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 lsblk_device
*dev
40 __attribute__((__unused__
)))
45 static struct lsblk_devprop
*get_properties_by_udev(struct lsblk_device
*ld
)
47 struct udev_device
*dev
;
49 if (ld
->udev_requested
)
50 return ld
->properties
;
55 udev
= udev_new(); /* global handler */
59 dev
= udev_device_new_from_subsystem_sysname(udev
, "block", ld
->name
);
62 struct lsblk_devprop
*prop
;
65 lsblk_device_free_properties(ld
->properties
);
66 prop
= ld
->properties
= xcalloc(1, sizeof(*ld
->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 data
= udev_device_get_property_value(dev
, "ID_SCSI_SERIAL");
101 data
= udev_device_get_property_value(dev
, "ID_SERIAL_SHORT");
103 prop
->serial
= xstrdup(data
);
105 if ((data
= udev_device_get_property_value(dev
, "ID_MODEL")))
106 prop
->model
= xstrdup(data
);
108 udev_device_unref(dev
);
109 DBG(DEV
, ul_debugobj(ld
, "%s: found udev properties", ld
->name
));
113 ld
->udev_requested
= 1;
114 return ld
->properties
;
116 #endif /* HAVE_LIBUDEV */
118 static struct lsblk_devprop
*get_properties_by_blkid(struct lsblk_device
*dev
)
120 blkid_probe pr
= NULL
;
122 if (dev
->blkid_requested
)
123 return dev
->properties
;
128 goto done
;; /* no permissions to read from the device */
130 pr
= blkid_new_probe_from_filename(dev
->filename
);
134 blkid_probe_enable_superblocks(pr
, 1);
135 blkid_probe_set_superblocks_flags(pr
, BLKID_SUBLKS_LABEL
|
138 blkid_probe_enable_partitions(pr
, 1);
139 blkid_probe_set_partitions_flags(pr
, BLKID_PARTS_ENTRY_DETAILS
);
141 if (!blkid_do_safeprobe(pr
)) {
142 const char *data
= NULL
;
143 struct lsblk_devprop
*prop
;
146 lsblk_device_free_properties(dev
->properties
);
147 prop
= dev
->properties
= xcalloc(1, sizeof(*dev
->properties
));
149 if (!blkid_probe_lookup_value(pr
, "TYPE", &data
, NULL
))
150 prop
->fstype
= xstrdup(data
);
151 if (!blkid_probe_lookup_value(pr
, "UUID", &data
, NULL
))
152 prop
->uuid
= xstrdup(data
);
153 if (!blkid_probe_lookup_value(pr
, "PTUUID", &data
, NULL
))
154 prop
->ptuuid
= xstrdup(data
);
155 if (!blkid_probe_lookup_value(pr
, "PTTYPE", &data
, NULL
))
156 prop
->pttype
= xstrdup(data
);
157 if (!blkid_probe_lookup_value(pr
, "LABEL", &data
, NULL
))
158 prop
->label
= xstrdup(data
);
159 if (!blkid_probe_lookup_value(pr
, "PART_ENTRY_TYPE", &data
, NULL
))
160 prop
->parttype
= xstrdup(data
);
161 if (!blkid_probe_lookup_value(pr
, "PART_ENTRY_UUID", &data
, NULL
))
162 prop
->partuuid
= xstrdup(data
);
163 if (!blkid_probe_lookup_value(pr
, "PART_ENTRY_NAME", &data
, NULL
))
164 prop
->partlabel
= xstrdup(data
);
165 if (!blkid_probe_lookup_value(pr
, "PART_ENTRY_FLAGS", &data
, NULL
))
166 prop
->partflags
= xstrdup(data
);
168 DBG(DEV
, ul_debugobj(dev
, "%s: found blkid properties", dev
->name
));
172 blkid_free_probe(pr
);
174 dev
->blkid_requested
= 1;
175 return dev
->properties
;
178 struct lsblk_devprop
*lsblk_device_get_properties(struct lsblk_device
*dev
)
180 struct lsblk_devprop
*p
= get_properties_by_udev(dev
);
183 p
= get_properties_by_blkid(dev
);
187 void lsblk_properties_deinit(void)