lsblk: rename blkdev_cxt to lsblk_device

The patch does not change code logic and semantic -- just rename.

* set_cxt() to set_device()
* struct blkdev_cxt to lsblk_device

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2018-10-09 12:46:28 +02:00
parent 8229ed2f5c
commit fed34a1e63
4 changed files with 278 additions and 278 deletions

View File

@ -42,16 +42,16 @@ static int is_active_swap(const char *filename)
return mnt_table_find_srcpath(swaps, filename, MNT_ITER_BACKWARD) != NULL;
}
char *lsblk_device_get_mountpoint(struct blkdev_cxt *cxt)
char *lsblk_device_get_mountpoint(struct lsblk_device *dev)
{
struct libmnt_fs *fs;
const char *fsroot;
assert(cxt);
assert(cxt->filename);
assert(dev);
assert(dev->filename);
if (cxt->is_mounted || cxt->is_swap)
return cxt->mountpoint;
if (dev->is_mounted || dev->is_swap)
return dev->mountpoint;
if (!mtab) {
mtab = mnt_new_table();
@ -75,17 +75,17 @@ char *lsblk_device_get_mountpoint(struct blkdev_cxt *cxt)
/* Note that maj:min in /proc/self/mountinfo does not have to match with
* devno as returned by stat(), so we have to try devname too
*/
fs = mnt_table_find_devno(mtab, makedev(cxt->maj, cxt->min), MNT_ITER_BACKWARD);
fs = mnt_table_find_devno(mtab, makedev(dev->maj, dev->min), MNT_ITER_BACKWARD);
if (!fs)
fs = mnt_table_find_srcpath(mtab, cxt->filename, MNT_ITER_BACKWARD);
fs = mnt_table_find_srcpath(mtab, dev->filename, MNT_ITER_BACKWARD);
if (!fs) {
if (is_active_swap(cxt->filename)) {
cxt->mountpoint = xstrdup("[SWAP]");
cxt->is_swap = 1;
if (is_active_swap(dev->filename)) {
dev->mountpoint = xstrdup("[SWAP]");
dev->is_swap = 1;
} else
cxt->mountpoint = NULL;
dev->mountpoint = NULL;
return cxt->mountpoint;
return dev->mountpoint;
}
/* found */
@ -100,7 +100,7 @@ char *lsblk_device_get_mountpoint(struct blkdev_cxt *cxt)
while (mnt_table_next_fs(mtab, itr, &rfs) == 0) {
fsroot = mnt_fs_get_root(rfs);
if ((!fsroot || strcmp(fsroot, "/") == 0)
&& mnt_fs_match_source(rfs, cxt->filename, mntcache)) {
&& mnt_fs_match_source(rfs, dev->filename, mntcache)) {
fs = rfs;
break;
}
@ -108,10 +108,10 @@ char *lsblk_device_get_mountpoint(struct blkdev_cxt *cxt)
mnt_free_iter(itr);
}
DBG(DEV, ul_debugobj(cxt, "mountpoint: %s", mnt_fs_get_target(fs)));
cxt->mountpoint = xstrdup(mnt_fs_get_target(fs));
cxt->is_mounted = 1;
return cxt->mountpoint;
DBG(DEV, ul_debugobj(dev, "mountpoint: %s", mnt_fs_get_target(fs)));
dev->mountpoint = xstrdup(mnt_fs_get_target(fs));
dev->is_mounted = 1;
return dev->mountpoint;
}
void lsblk_mnt_init(void)

View File

@ -36,18 +36,18 @@ void lsblk_device_free_properties(struct lsblk_devprop *p)
}
#ifndef HAVE_LIBUDEV
static struct lsblk_devprop *get_properties_by_udev(struct blkdev_cxt *cxt
static struct lsblk_devprop *get_properties_by_udev(struct lsblk_device *dev
__attribute__((__unused__)))
{
return NULL;
}
#else
static struct lsblk_devprop *get_properties_by_udev(struct blkdev_cxt *cxt)
static struct lsblk_devprop *get_properties_by_udev(struct lsblk_device *ld)
{
struct udev_device *dev;
if (cxt->udev_requested)
return cxt->properties;
if (ld->udev_requested)
return ld->properties;
if (lsblk->sysroot)
goto done;
@ -56,14 +56,14 @@ static struct lsblk_devprop *get_properties_by_udev(struct blkdev_cxt *cxt)
if (!udev)
goto done;
dev = udev_device_new_from_subsystem_sysname(udev, "block", cxt->name);
dev = udev_device_new_from_subsystem_sysname(udev, "block", ld->name);
if (dev) {
const char *data;
struct lsblk_devprop *prop;
if (cxt->properties)
lsblk_device_free_properties(cxt->properties);
prop = cxt->properties = xcalloc(1, sizeof(*cxt->properties));
if (ld->properties)
lsblk_device_free_properties(ld->properties);
prop = ld->properties = xcalloc(1, sizeof(*ld->properties));
if ((data = udev_device_get_property_value(dev, "ID_FS_LABEL_ENC"))) {
prop->label = xstrdup(data);
@ -102,28 +102,28 @@ static struct lsblk_devprop *get_properties_by_udev(struct blkdev_cxt *cxt)
prop->model = xstrdup(data);
udev_device_unref(dev);
DBG(DEV, ul_debugobj(cxt, "%s: found udev properties", cxt->name));
DBG(DEV, ul_debugobj(ld, "%s: found udev properties", ld->name));
}
done:
cxt->udev_requested = 1;
return cxt->properties;
ld->udev_requested = 1;
return ld->properties;
}
#endif /* HAVE_LIBUDEV */
static struct lsblk_devprop *get_properties_by_blkid(struct blkdev_cxt *cxt)
static struct lsblk_devprop *get_properties_by_blkid(struct lsblk_device *dev)
{
blkid_probe pr = NULL;
if (cxt->blkid_requested)
return cxt->properties;
if (dev->blkid_requested)
return dev->properties;
if (!cxt->size)
if (!dev->size)
goto done;
if (getuid() != 0)
goto done;; /* no permissions to read from the device */
pr = blkid_new_probe_from_filename(cxt->filename);
pr = blkid_new_probe_from_filename(dev->filename);
if (!pr)
goto done;
@ -138,9 +138,9 @@ static struct lsblk_devprop *get_properties_by_blkid(struct blkdev_cxt *cxt)
const char *data = NULL;
struct lsblk_devprop *prop;
if (cxt->properties)
lsblk_device_free_properties(cxt->properties);
prop = cxt->properties = xcalloc(1, sizeof(*cxt->properties));
if (dev->properties)
lsblk_device_free_properties(dev->properties);
prop = dev->properties = xcalloc(1, sizeof(*dev->properties));
if (!blkid_probe_lookup_value(pr, "TYPE", &data, NULL))
prop->fstype = xstrdup(data);
@ -161,22 +161,22 @@ static struct lsblk_devprop *get_properties_by_blkid(struct blkdev_cxt *cxt)
if (!blkid_probe_lookup_value(pr, "PART_ENTRY_FLAGS", &data, NULL))
prop->partflags = xstrdup(data);
DBG(DEV, ul_debugobj(cxt, "%s: found blkid properties", cxt->name));
DBG(DEV, ul_debugobj(dev, "%s: found blkid properties", dev->name));
}
done:
blkid_free_probe(pr);
cxt->blkid_requested = 1;
return cxt->properties;
dev->blkid_requested = 1;
return dev->properties;
}
struct lsblk_devprop *lsblk_device_get_properties(struct blkdev_cxt *cxt)
struct lsblk_devprop *lsblk_device_get_properties(struct lsblk_device *dev)
{
struct lsblk_devprop *p = get_properties_by_udev(cxt);
struct lsblk_devprop *p = get_properties_by_udev(dev);
if (!p)
p = get_properties_by_blkid(cxt);
p = get_properties_by_blkid(dev);
return p;
}

File diff suppressed because it is too large Load Diff

View File

@ -64,8 +64,8 @@ struct lsblk_devprop {
char *model; /* disk model */
};
struct blkdev_cxt {
struct blkdev_cxt *parent;
struct lsblk_device {
struct lsblk_device *parent;
struct lsblk_devprop *properties;
struct libscols_line *scols_line;
@ -102,11 +102,11 @@ struct blkdev_cxt {
extern void lsblk_mnt_init(void);
extern void lsblk_mnt_deinit(void);
extern char *lsblk_device_get_mountpoint(struct blkdev_cxt *cxt);
extern char *lsblk_device_get_mountpoint(struct lsblk_device *dev);
/* lsblk-properties.c */
extern void lsblk_device_free_properties(struct lsblk_devprop *p);
extern struct lsblk_devprop *lsblk_device_get_properties(struct blkdev_cxt *cxt);
extern struct lsblk_devprop *lsblk_device_get_properties(struct lsblk_device *dev);
extern void lsblk_properties_deinit(void);
#endif /* UTIL_LINUX_LSBLK_H */