diff options
author | Karel Zak | 2011-05-16 17:20:55 +0200 |
---|---|---|
committer | Karel Zak | 2011-05-16 20:22:52 +0200 |
commit | d8a84552fb6539eaa2c15882d434e3845d758014 (patch) | |
tree | 40ffda4b41c0eb21a5142a14b373f3e74643a5f4 /shlibs/blkid/src/devname.c | |
parent | lsblk: use generic sysfs functions (diff) | |
download | kernel-qcow2-util-linux-d8a84552fb6539eaa2c15882d434e3845d758014.tar.gz kernel-qcow2-util-linux-d8a84552fb6539eaa2c15882d434e3845d758014.tar.xz kernel-qcow2-util-linux-d8a84552fb6539eaa2c15882d434e3845d758014.zip |
libblkid: use stuff from sysfs.h and at.h
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'shlibs/blkid/src/devname.c')
-rw-r--r-- | shlibs/blkid/src/devname.c | 40 |
1 files changed, 13 insertions, 27 deletions
diff --git a/shlibs/blkid/src/devname.c b/shlibs/blkid/src/devname.c index 68e392350..81eac9aa3 100644 --- a/shlibs/blkid/src/devname.c +++ b/shlibs/blkid/src/devname.c @@ -38,6 +38,8 @@ #include "canonicalize.h" /* $(top_srcdir)/include */ #include "pathnames.h" +#include "sysfs.h" +#include "at.h" /* * Find a dev struct in the cache by device name, if available. @@ -400,7 +402,7 @@ ubi_probe_all(blkid_cache cache, int only_if_new) continue; if (!strcmp(name, "ubi_ctrl")) continue; - if (blkid_fstatat(dir, *dirname, name, &st, 0)) + if (fstat_at(dirfd(dir), *dirname, name, &st, 0)) continue; dev = st.st_rdev; @@ -543,7 +545,6 @@ static int probe_all_removable(blkid_cache cache) { DIR *dir; struct dirent *d; - char buf[PATH_MAX]; if (!cache) return -BLKID_ERR_PARAM; @@ -553,7 +554,9 @@ static int probe_all_removable(blkid_cache cache) return -BLKID_ERR_PROC; while((d = readdir(dir))) { - int fd, rc, ma, mi; + struct sysfs_cxt sysfs; + int removable; + dev_t devno; #ifdef _DIRENT_HAVE_D_TYPE if (d->d_type != DT_UNKNOWN && d->d_type != DT_LNK) @@ -564,33 +567,16 @@ static int probe_all_removable(blkid_cache cache) ((d->d_name[1] == '.') && (d->d_name[2] == 0)))) continue; - snprintf(buf, sizeof(buf), "%s/removable", d->d_name); - fd = blkid_openat(dir, _PATH_SYS_BLOCK, buf, O_RDONLY); - if (fd < 0) + devno = sysfs_devname_to_devno(d->d_name, NULL); + if (!devno) continue; - rc = read(fd, buf, 1); - close(fd); + sysfs_init(&sysfs, devno, NULL); + removable = sysfs_read_int(&sysfs, "removable"); + sysfs_deinit(&sysfs); - if (rc != 1 || *buf != '1') - continue; /* not removable device */ - - /* get devno */ - snprintf(buf, sizeof(buf), "%s/dev", d->d_name); - fd = blkid_openat(dir, _PATH_SYS_BLOCK, buf, O_RDONLY); - if (fd < 0) - continue; - - rc = read(fd, buf, sizeof(buf)); - close(fd); - - if (rc < 3) - continue; /* M:N */ - buf[rc] = '\0'; - if (sscanf(buf, "%d:%d", &ma, &mi) != 2) - continue; - - probe_one(cache, d->d_name, makedev(ma, mi), 0, 0, 1); + if (removable) + probe_one(cache, d->d_name, devno, 0, 0, 1); } closedir(dir); |