14
static int matching_device (struct udev_device *device, const char *path);
16
static void alarm_handler (int signum);
24
const char * rootdelay;
27
struct udev_monitor *udev_monitor;
29
struct udev_device * udev_device = NULL;
32
fprintf (stderr, "Usage: %s DEVICE\n", argv[0]);
38
rootdelay = getenv ("ROOTDELAY");
40
timeout = atoi (rootdelay) ?: 30;
45
signal (SIGALRM, alarm_handler);
48
/* Connect to the udev monitor first; if we stat() first, the
49
* event might happen between the stat() and the time we actually
53
udev_monitor = udev_monitor_new_from_netlink (udev, "udev");
55
udev_monitor_filter_add_match_subsystem_devtype (udev_monitor, "block", NULL);
56
udev_monitor_enable_receiving (udev_monitor);
58
/* Check whether or not the device already exists */
59
if ((stat (devpath, &devstat) == 0)
60
&& S_ISBLK (devstat.st_mode)) {
61
struct udev_queue * udev_queue;
62
struct udev_list_entry *queue_entry;
64
/* Make sure that the device is not currently queued */
65
udev_queue = udev_queue_new (udev);
67
for (queue_entry = udev_queue_get_queued_list_entry (udev_queue);
69
queue_entry = udev_list_entry_get_next (queue_entry)) {
72
syspath = udev_list_entry_get_name (queue_entry);
73
udev_device = udev_device_new_from_syspath (udev, syspath);
75
/* If the device exists, we wait for it to leave
79
&& matching_device (udev_device, devpath)) {
81
unsigned long long seqnum;
83
sscanf (udev_list_entry_get_value (queue_entry),
87
time.tv_nsec = 100000000;
89
while (! udev_queue_get_seqnum_is_finished (udev_queue, seqnum))
90
nanosleep (&time, NULL);
94
udev_device_unref (udev_device);
97
udev_queue_unref (udev_queue);
99
/* If the device exists but isn't queued, look it up in the
100
* udevdb by major/minor number (since udev must have created
104
udev_device = udev_device_new_from_devnum (udev, 'b', devstat.st_rdev);
107
while ((udev_device = udev_monitor_receive_device (udev_monitor)) != NULL) {
108
if (matching_device (udev_device, devpath))
111
udev_device_unref (udev_device);
119
type = udev_device_get_property_value (udev_device, "ID_FS_TYPE");
121
printf ("%s\n", udev_device_get_property_value (udev_device, "ID_FS_TYPE"));
122
udev_device_unref (udev_device);
124
udev_device_unref (udev_device);
130
udev_monitor_unref (udev_monitor);
133
exit (udev_device ? 0 : 1);
138
matching_device (struct udev_device *device,
141
const char * fs_type;
142
struct udev_list_entry *devlinks_entry;
144
fs_type = udev_device_get_property_value (device, "ID_FS_TYPE");
149
if (! strcmp (path, udev_device_get_devnode (device)))
153
if (! strncmp (path, "UUID=", 5)) {
156
uuid = udev_device_get_property_value (device, "ID_FS_UUID");
157
if (uuid && (! strcmp (path + 5, uuid)))
162
if (! strncmp (path, "LABEL=", 6)) {
165
label = udev_device_get_property_value (device, "ID_FS_LABEL");
166
if (label && (! strcmp (path + 6, label)))
170
/* Match by symlink */
171
for (devlinks_entry = udev_device_get_devlinks_list_entry (device);
172
devlinks_entry != NULL;
173
devlinks_entry = udev_list_entry_get_next (devlinks_entry))
174
if (! strcmp (path, udev_list_entry_get_name (devlinks_entry)))
182
alarm_handler (int signum)