Skip to content

Commit

Permalink
lsblk: rename blkdev_cxt to lsblk_device
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
karelzak committed Dec 7, 2018
1 parent 8229ed2 commit fed34a1
Show file tree
Hide file tree
Showing 4 changed files with 278 additions and 278 deletions.
34 changes: 17 additions & 17 deletions misc-utils/lsblk-mnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 */
Expand All @@ -100,18 +100,18 @@ 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;
}
}
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)
Expand Down
50 changes: 25 additions & 25 deletions misc-utils/lsblk-properties.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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;
}

Expand Down
Loading

0 comments on commit fed34a1

Please sign in to comment.