15 static struct udev
*udev
;
18 void lsblk_device_free_properties(struct lsblk_devprop
*p
)
39 static struct lsblk_devprop
*get_properties_by_udev(struct blkdev_cxt
*cxt
40 __attribute__((__unused__
)))
45 static struct lsblk_devprop
*get_properties_by_udev(struct blkdev_cxt
*cxt
)
47 struct udev_device
*dev
;
49 if (cxt
->udev_requested
)
50 return cxt
->properties
;
55 udev
= udev_new(); /* global handler */
59 dev
= udev_device_new_from_subsystem_sysname(udev
, "block", cxt
->name
);
62 struct lsblk_devprop
*prop
;
65 lsblk_device_free_properties(cxt
->properties
);
66 prop
= cxt
->properties
= xcalloc(1, sizeof(*cxt
->properties
));
68 if ((data
= udev_device_get_property_value(dev
, "ID_FS_LABEL_ENC"))) {
69 prop
->label
= xstrdup(data
);
70 unhexmangle_string(prop
->label
);
72 if ((data
= udev_device_get_property_value(dev
, "ID_FS_UUID_ENC"))) {
73 prop
->uuid
= xstrdup(data
);
74 unhexmangle_string(prop
->uuid
);
76 if ((data
= udev_device_get_property_value(dev
, "ID_PART_TABLE_UUID")))
77 prop
->ptuuid
= xstrdup(data
);
78 if ((data
= udev_device_get_property_value(dev
, "ID_PART_TABLE_TYPE")))
79 prop
->pttype
= xstrdup(data
);
80 if ((data
= udev_device_get_property_value(dev
, "ID_PART_ENTRY_NAME"))) {
81 prop
->partlabel
= xstrdup(data
);
82 unhexmangle_string(prop
->partlabel
);
84 if ((data
= udev_device_get_property_value(dev
, "ID_FS_TYPE")))
85 prop
->fstype
= xstrdup(data
);
86 if ((data
= udev_device_get_property_value(dev
, "ID_PART_ENTRY_TYPE")))
87 prop
->parttype
= xstrdup(data
);
88 if ((data
= udev_device_get_property_value(dev
, "ID_PART_ENTRY_UUID")))
89 prop
->partuuid
= xstrdup(data
);
90 if ((data
= udev_device_get_property_value(dev
, "ID_PART_ENTRY_FLAGS")))
91 prop
->partflags
= xstrdup(data
);
93 data
= udev_device_get_property_value(dev
, "ID_WWN_WITH_EXTENSION");
95 data
= udev_device_get_property_value(dev
, "ID_WWN");
97 prop
->wwn
= xstrdup(data
);
99 if ((data
= udev_device_get_property_value(dev
, "ID_SERIAL_SHORT")))
100 prop
->serial
= xstrdup(data
);
101 if ((data
= udev_device_get_property_value(dev
, "ID_MODEL")))
102 prop
->model
= xstrdup(data
);
104 udev_device_unref(dev
);
105 DBG(DEV
, ul_debugobj(cxt
, "%s: found udev properties", cxt
->name
));
109 cxt
->udev_requested
= 1;
110 return cxt
->properties
;
112 #endif /* HAVE_LIBUDEV */
114 static struct lsblk_devprop
*get_properties_by_blkid(struct blkdev_cxt
*cxt
)
116 blkid_probe pr
= NULL
;
118 if (cxt
->blkid_requested
)
119 return cxt
->properties
;
124 goto done
;; /* no permissions to read from the device */
126 pr
= blkid_new_probe_from_filename(cxt
->filename
);
130 blkid_probe_enable_superblocks(pr
, 1);
131 blkid_probe_set_superblocks_flags(pr
, BLKID_SUBLKS_LABEL
|
134 blkid_probe_enable_partitions(pr
, 1);
135 blkid_probe_set_partitions_flags(pr
, BLKID_PARTS_ENTRY_DETAILS
);
137 if (!blkid_do_safeprobe(pr
)) {
138 const char *data
= NULL
;
139 struct lsblk_devprop
*prop
;
142 lsblk_device_free_properties(cxt
->properties
);
143 prop
= cxt
->properties
= xcalloc(1, sizeof(*cxt
->properties
));
145 if (!blkid_probe_lookup_value(pr
, "TYPE", &data
, NULL
))
146 prop
->fstype
= xstrdup(data
);
147 if (!blkid_probe_lookup_value(pr
, "UUID", &data
, NULL
))
148 prop
->uuid
= xstrdup(data
);
149 if (!blkid_probe_lookup_value(pr
, "PTUUID", &data
, NULL
))
150 prop
->ptuuid
= xstrdup(data
);
151 if (!blkid_probe_lookup_value(pr
, "PTTYPE", &data
, NULL
))
152 prop
->pttype
= xstrdup(data
);
153 if (!blkid_probe_lookup_value(pr
, "LABEL", &data
, NULL
))
154 prop
->label
= xstrdup(data
);
155 if (!blkid_probe_lookup_value(pr
, "PART_ENTRY_TYPE", &data
, NULL
))
156 prop
->parttype
= xstrdup(data
);
157 if (!blkid_probe_lookup_value(pr
, "PART_ENTRY_UUID", &data
, NULL
))
158 prop
->partuuid
= xstrdup(data
);
159 if (!blkid_probe_lookup_value(pr
, "PART_ENTRY_NAME", &data
, NULL
))
160 prop
->partlabel
= xstrdup(data
);
161 if (!blkid_probe_lookup_value(pr
, "PART_ENTRY_FLAGS", &data
, NULL
))
162 prop
->partflags
= xstrdup(data
);
164 DBG(DEV
, ul_debugobj(cxt
, "%s: found blkid properties", cxt
->name
));
168 blkid_free_probe(pr
);
170 cxt
->blkid_requested
= 1;
171 return cxt
->properties
;
174 struct lsblk_devprop
*lsblk_device_get_properties(struct blkdev_cxt
*cxt
)
176 struct lsblk_devprop
*p
= get_properties_by_udev(cxt
);
179 p
= get_properties_by_blkid(cxt
);
183 void lsblk_properties_deinit(void)