]> git.ipfire.org Git - thirdparty/systemd.git/blame - udev/lib/libudev-device.c
do not use the new work-in-progress parser rule matcher
[thirdparty/systemd.git] / udev / lib / libudev-device.c
CommitLineData
eb1f0e66
KS
1/*
2 * libudev - interface to udev device information
3 *
4 * Copyright (C) 2008 Kay Sievers <kay.sievers@vrfy.org>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
eb1f0e66
KS
20#include <stdio.h>
21#include <stdlib.h>
22#include <stddef.h>
23#include <unistd.h>
24#include <errno.h>
25#include <string.h>
26#include <dirent.h>
93b0f384 27#include <fcntl.h>
517814e7 28#include <ctype.h>
eb1f0e66
KS
29#include <sys/stat.h>
30
31#include "libudev.h"
32#include "libudev-private.h"
eb1f0e66 33
11d543c1
KS
34struct udev_device {
35 int refcount;
36 struct udev *udev;
b2d9e4f2 37 struct udev_device *parent_device;
31f4b036 38 int parent_set;
11d543c1 39 char *syspath;
4ad3a37f 40 const char *devpath;
517814e7
KS
41 char *sysname;
42 const char *sysnum;
99214844 43 char *devnode;
11d543c1 44 char *subsystem;
5c5cad79 45 int subsystem_set;
517814e7 46 struct udev_list_node devlinks_list;
bd85566c 47 int devlinks_uptodate;
8cd2e972 48 struct udev_list_node properties_list;
979ff016
KS
49 char *envp[128];
50 int envp_uptodate;
51 char *driver;
5c5cad79 52 int driver_set;
979ff016 53 dev_t devnum;
c4f5f942 54 char *action;
99214844 55 int event_timeout;
c4f5f942
KS
56 char *devpath_old;
57 char *physdevpath;
58 int timeout;
6bd1c78a
KS
59 unsigned long long int seqnum;
60 int num_fake_partitions;
e88a82b5 61 int devlink_priority;
6bd1c78a 62 int ignore_remove;
69239210 63 struct udev_list_node sysattr_list;
99214844 64 int info_loaded;
11d543c1
KS
65};
66
9a997ecf 67static size_t devpath_to_db_path(struct udev *udev, const char *devpath, char *filename, size_t len)
e88a82b5
KS
68{
69 size_t start;
70
71 /* translate to location of db file */
9a997ecf 72 util_strlcpy(filename, udev_get_dev_path(udev), len);
3eb46ec6 73 start = util_strlcat(filename, "/.udev/db/", len);
9a997ecf 74 util_strlcat(filename, devpath, len);
7a01f11a 75 return util_path_encode(&filename[start], len - start);
e88a82b5
KS
76}
77
aa8734ff 78int udev_device_read_db(struct udev_device *udev_device)
e88a82b5
KS
79{
80 struct stat stats;
3eb46ec6
KS
81 char filename[UTIL_PATH_SIZE];
82 char line[UTIL_LINE_SIZE];
e88a82b5 83 FILE *f;
e88a82b5 84
9a997ecf 85 devpath_to_db_path(udev_device->udev, udev_device->devpath, filename, sizeof(filename));
e88a82b5
KS
86
87 if (lstat(filename, &stats) != 0) {
659353f5 88 info(udev_device->udev, "no db file to read %s: %m\n", filename);
e88a82b5
KS
89 return -1;
90 }
91 if ((stats.st_mode & S_IFMT) == S_IFLNK) {
3eb46ec6 92 char target[UTIL_PATH_SIZE];
517814e7 93 char devnode[UTIL_PATH_SIZE];
e88a82b5 94 int target_len;
1e75cda3 95 char *next;
e88a82b5 96
e88a82b5
KS
97 target_len = readlink(filename, target, sizeof(target));
98 if (target_len > 0)
99 target[target_len] = '\0';
100 else {
659353f5 101 info(udev_device->udev, "error reading db link %s: %m\n", filename);
e88a82b5
KS
102 return -1;
103 }
1e75cda3
KS
104
105 next = strchr(target, ' ');
106 if (next != NULL) {
107 next[0] = '\0';
108 next = &next[1];
109 }
517814e7
KS
110 util_strlcpy(devnode, udev_get_dev_path(udev_device->udev), sizeof(devnode));
111 util_strlcat(devnode, "/", sizeof(devnode));
112 util_strlcat(devnode, target, sizeof(devnode));
113 udev_device_set_devnode(udev_device, devnode);
1e75cda3 114 while (next != NULL) {
517814e7 115 char devlink[UTIL_PATH_SIZE];
1e75cda3
KS
116 const char *lnk;
117
118 lnk = next;
119 next = strchr(next, ' ');
120 if (next != NULL) {
121 next[0] = '\0';
122 next = &next[1];
123 }
517814e7
KS
124 util_strlcpy(devlink, udev_get_dev_path(udev_device->udev), sizeof(devlink));
125 util_strlcat(devlink, "/", sizeof(devlink));
126 util_strlcat(devlink, lnk, sizeof(devlink));
127 udev_device_add_devlink(udev_device, devlink);
1e75cda3 128 }
99214844 129 info(udev_device->udev, "device %p filled with db symlink data '%s'\n", udev_device, udev_device->devnode);
e88a82b5
KS
130 return 0;
131 }
132
133 f = fopen(filename, "r");
134 if (f == NULL) {
659353f5 135 info(udev_device->udev, "error reading db file %s: %m\n", filename);
e88a82b5
KS
136 return -1;
137 }
138 while (fgets(line, sizeof(line), f)) {
139 ssize_t len;
140 const char *val;
e88a82b5
KS
141
142 len = strlen(line);
143 if (len < 4)
144 break;
145 line[len-1] = '\0';
146 val = &line[2];
e88a82b5
KS
147 switch(line[0]) {
148 case 'N':
517814e7
KS
149 util_strlcpy(filename, udev_get_dev_path(udev_device->udev), sizeof(filename));
150 util_strlcat(filename, "/", sizeof(filename));
151 util_strlcat(filename, val, sizeof(filename));
152 udev_device_set_devnode(udev_device, filename);
e88a82b5 153 break;
e88a82b5 154 case 'S':
3eb46ec6
KS
155 util_strlcpy(filename, udev_get_dev_path(udev_device->udev), sizeof(filename));
156 util_strlcat(filename, "/", sizeof(filename));
157 util_strlcat(filename, val, sizeof(filename));
8cd2e972 158 udev_device_add_devlink(udev_device, filename);
e88a82b5
KS
159 break;
160 case 'L':
8cd2e972 161 udev_device_set_devlink_priority(udev_device, atoi(val));
e88a82b5
KS
162 break;
163 case 'T':
8cd2e972 164 udev_device_set_event_timeout(udev_device, atoi(val));
e88a82b5
KS
165 break;
166 case 'A':
8cd2e972 167 udev_device_set_num_fake_partitions(udev_device, atoi(val));
e88a82b5
KS
168 break;
169 case 'R':
8cd2e972 170 udev_device_set_ignore_remove(udev_device, atoi(val));
e88a82b5
KS
171 break;
172 case 'E':
8cd2e972 173 udev_device_add_property_from_string(udev_device, val);
e88a82b5
KS
174 break;
175 }
176 }
177 fclose(f);
178
cd42b50d 179 info(udev_device->udev, "device %p filled with db file data\n", udev_device);
04f5d75f 180 return 0;
e88a82b5
KS
181}
182
bd85566c 183int udev_device_read_uevent_file(struct udev_device *udev_device)
99214844
KS
184{
185 char filename[UTIL_PATH_SIZE];
186 FILE *f;
187 char line[UTIL_LINE_SIZE];
188 int maj = 0;
189 int min = 0;
190
191 util_strlcpy(filename, udev_device->syspath, sizeof(filename));
192 util_strlcat(filename, "/uevent", sizeof(filename));
193 f = fopen(filename, "r");
194 if (f == NULL)
195 return -1;
196
197 while (fgets(line, sizeof(line), f)) {
198 char *pos;
199
200 pos = strchr(line, '\n');
201 if (pos == NULL)
202 continue;
203 pos[0] = '\0';
204
205 if (strncmp(line, "MAJOR=", 6) == 0)
206 maj = strtoull(&line[6], NULL, 10);
207 else if (strncmp(line, "MINOR=", 6) == 0)
208 min = strtoull(&line[6], NULL, 10);
209
8cd2e972 210 udev_device_add_property_from_string(udev_device, line);
99214844
KS
211 }
212
213 udev_device->devnum = makedev(maj, min);
214
215 fclose(f);
216 return 0;
217}
218
219static void device_load_info(struct udev_device *device)
220{
517814e7 221 device->info_loaded = 1;
bd85566c 222 udev_device_read_uevent_file(device);
aa8734ff 223 udev_device_read_db(device);
99214844
KS
224}
225
8cd2e972 226void udev_device_set_info_loaded(struct udev_device *device)
99214844
KS
227{
228 device->info_loaded = 1;
229}
230
e0083e8e 231struct udev_device *device_new(struct udev *udev)
eb1f0e66
KS
232{
233 struct udev_device *udev_device;
ebacd6ec 234 struct udev_list_entry *list_entry;
eb1f0e66 235
ba6929f6
KS
236 if (udev == NULL)
237 return NULL;
238
eb1f0e66
KS
239 udev_device = malloc(sizeof(struct udev_device));
240 if (udev_device == NULL)
241 return NULL;
242 memset(udev_device, 0x00, sizeof(struct udev_device));
243 udev_device->refcount = 1;
244 udev_device->udev = udev;
517814e7 245 udev_list_init(&udev_device->devlinks_list);
8cd2e972 246 udev_list_init(&udev_device->properties_list);
69239210 247 udev_list_init(&udev_device->sysattr_list);
979ff016 248 udev_device->event_timeout = -1;
ebacd6ec
KS
249 /* copy global properties */
250 udev_list_entry_foreach(list_entry, udev_get_properties_list_entry(udev))
251 udev_device_add_property(udev_device,
252 udev_list_entry_get_name(list_entry),
253 udev_list_entry_get_value(list_entry));
7d563a17 254 info(udev_device->udev, "udev_device: %p created\n", udev_device);
eb1f0e66
KS
255 return udev_device;
256}
257
258/**
8753fadf 259 * udev_device_new_from_syspath:
eb1f0e66 260 * @udev: udev library context
8753fadf 261 * @syspath: sys device path including sys directory
eb1f0e66 262 *
8753fadf
KS
263 * Create new udev device, and fill in information from the sys
264 * device and the udev database entry. The sypath is the absolute
265 * path to the device, including the sys mount point.
eb1f0e66
KS
266 *
267 * The initial refcount is 1, and needs to be decremented to
268 * release the ressources of the udev device.
269 *
270 * Returns: a new udev device, or #NULL, if it does not exist
271 **/
8753fadf 272struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath)
eb1f0e66 273{
b95f8a76
KS
274 size_t len;
275 const char *subdir;
3eb46ec6 276 char path[UTIL_PATH_SIZE];
62b9dfb6 277 char *pos;
eb1f0e66
KS
278 struct stat statbuf;
279 struct udev_device *udev_device;
eb1f0e66 280
ba6929f6
KS
281 if (udev == NULL)
282 return NULL;
8753fadf 283 if (syspath == NULL)
ba6929f6
KS
284 return NULL;
285
b95f8a76
KS
286 /* path starts in sys */
287 len = strlen(udev_get_sys_path(udev));
288 if (strncmp(syspath, udev_get_sys_path(udev), len) != 0) {
289 info(udev, "not in sys :%s\n", syspath);
eb1f0e66 290 return NULL;
4ad3a37f 291 }
eb1f0e66 292
b95f8a76
KS
293 /* path is not a root directory */
294 subdir = &syspath[len+1];
295 pos = strrchr(subdir, '/');
296 if (pos == NULL || pos < &subdir[2]) {
bc8184ed 297 info(udev, "not a subdir :%s\n", syspath);
eb1f0e66 298 return NULL;
b95f8a76 299 }
eb1f0e66 300
ba6929f6 301 /* resolve possible symlink to real path */
8753fadf 302 util_strlcpy(path, syspath, sizeof(path));
b21b95d7 303 util_resolve_sys_link(udev, path, sizeof(path));
b95f8a76 304
62b9dfb6
KS
305 /* try to resolve the silly block layout if needed */
306 if (strncmp(&path[len], "/block/", 7) == 0) {
307 char block[UTIL_PATH_SIZE];
308 char part[UTIL_PATH_SIZE];
309
310 util_strlcpy(block, path, sizeof(block));
311 pos = strrchr(block, '/');
312 if (pos == NULL)
313 return NULL;
314 util_strlcpy(part, pos, sizeof(part));
315 pos[0] = '\0';
316 if (util_resolve_sys_link(udev, block, sizeof(block)) == 0) {
317 util_strlcpy(path, block, sizeof(path));
318 util_strlcat(path, part, sizeof(path));
319 }
320 }
321
b95f8a76
KS
322 /* path exists in sys */
323 if (strncmp(&syspath[len], "/devices/", 9) == 0 ||
324 strncmp(&syspath[len], "/class/", 7) == 0 ||
325 strncmp(&syspath[len], "/block/", 7) == 0) {
326 char file[UTIL_PATH_SIZE];
327
328 /* all "devices" require a "uevent" file */
329 util_strlcpy(file, path, sizeof(file));
330 util_strlcat(file, "/uevent", sizeof(file));
331 if (stat(file, &statbuf) != 0) {
332 info(udev, "not a device: %s\n", syspath);
333 return NULL;
334 }
335 } else {
336 /* everything else just needs to be a directory */
337 if (stat(path, &statbuf) != 0 || !S_ISDIR(statbuf.st_mode)) {
338 info(udev, "directory not found: %s\n", syspath);
339 return NULL;
340 }
341 }
342
e0083e8e 343 udev_device = device_new(udev);
b95f8a76
KS
344 if (udev_device == NULL)
345 return NULL;
346
8cd2e972 347 udev_device_set_syspath(udev_device, path);
7d563a17 348 info(udev, "device %p has devpath '%s'\n", udev_device, udev_device_get_devpath(udev_device));
eb1f0e66 349
eb1f0e66
KS
350 return udev_device;
351}
352
4c9dff47
KS
353struct udev_device *udev_device_new_from_devnum(struct udev *udev, char type, dev_t devnum)
354{
355 char path[UTIL_PATH_SIZE];
03198b93 356 const char *type_str;
438d4c3c 357 struct udev_enumerate *udev_enumerate;
0de33a61 358 struct udev_list_entry *list_entry;
bf7ad0ea 359 struct udev_device *device = NULL;
03198b93
KS
360
361 if (type == 'b')
362 type_str = "block";
363 else if (type == 'c')
364 type_str = "char";
365 else
366 return NULL;
4c9dff47 367
b95f8a76 368 /* /sys/dev/{block,char}/<maj>:<min> link */
03198b93
KS
369 snprintf(path, sizeof(path), "%s/dev/%s/%u:%u", udev_get_sys_path(udev),
370 type_str, major(devnum), minor(devnum));
bf7ad0ea
KS
371 if (util_resolve_sys_link(udev, path, sizeof(path)) == 0)
372 return udev_device_new_from_syspath(udev, path);
4c9dff47 373
438d4c3c
KS
374 udev_enumerate = udev_enumerate_new(udev);
375 if (udev_enumerate == NULL)
376 return NULL;
377
bc8184ed
KS
378 /* fallback to search sys devices for the major/minor */
379 if (type == 'b')
c97f839e 380 udev_enumerate_add_match_subsystem(udev_enumerate, "block");
bc8184ed 381 else if (type == 'c')
c97f839e
KS
382 udev_enumerate_add_nomatch_subsystem(udev_enumerate, "block");
383 udev_enumerate_scan_devices(udev_enumerate);
438d4c3c 384 udev_list_entry_foreach(list_entry, udev_enumerate_get_list_entry(udev_enumerate)) {
bf7ad0ea
KS
385 struct udev_device *device_loop;
386
0de33a61 387 device_loop = udev_device_new_from_syspath(udev, udev_list_entry_get_name(list_entry));
bf7ad0ea
KS
388 if (device_loop != NULL) {
389 if (udev_device_get_devnum(device_loop) == devnum) {
c97f839e 390 if (type == 'b' && strcmp(udev_device_get_subsystem(device_loop), "block") != 0)
bc8184ed 391 continue;
c97f839e 392 if (type == 'c' && strcmp(udev_device_get_subsystem(device_loop), "block") == 0)
bc8184ed 393 continue;
bf7ad0ea
KS
394 device = device_loop;
395 break;
396 }
397 udev_device_unref(device_loop);
398 }
bf7ad0ea 399 }
438d4c3c 400 udev_enumerate_unref(udev_enumerate);
bf7ad0ea 401 return device;
4c9dff47
KS
402}
403
90d80c2e
KS
404struct udev_device *udev_device_new_from_subsystem_sysname(struct udev *udev, const char *subsystem, const char *sysname)
405{
406 size_t sys_path_len;
407 char path_full[UTIL_PATH_SIZE];
408 char *path;
409 struct stat statbuf;
410
411 sys_path_len = util_strlcpy(path_full, udev_get_sys_path(udev), sizeof(path_full));
412 path = &path_full[sys_path_len];
413
414 if (strcmp(subsystem, "subsystem") == 0) {
415 util_strlcpy(path, "/subsystem/", sizeof(path_full) - sys_path_len);
416 util_strlcat(path, sysname, sizeof(path_full) - sys_path_len);
417 if (stat(path_full, &statbuf) == 0)
418 goto found;
419
420 util_strlcpy(path, "/bus/", sizeof(path_full) - sys_path_len);
421 util_strlcat(path, sysname, sizeof(path_full) - sys_path_len);
422 if (stat(path_full, &statbuf) == 0)
423 goto found;
424
425 util_strlcpy(path, "/class/", sizeof(path_full) - sys_path_len);
426 util_strlcat(path, sysname, sizeof(path_full) - sys_path_len);
427 if (stat(path_full, &statbuf) == 0)
428 goto found;
429 goto out;
430 }
431
432 if (strcmp(subsystem, "module") == 0) {
433 util_strlcpy(path, "/module/", sizeof(path_full) - sys_path_len);
434 util_strlcat(path, sysname, sizeof(path_full) - sys_path_len);
435 if (stat(path_full, &statbuf) == 0)
436 goto found;
437 goto out;
438 }
439
440 if (strcmp(subsystem, "drivers") == 0) {
441 char subsys[UTIL_NAME_SIZE];
442 char *driver;
443
444 util_strlcpy(subsys, sysname, sizeof(subsys));
445 driver = strchr(subsys, ':');
446 if (driver != NULL) {
447 driver[0] = '\0';
448 driver = &driver[1];
449 util_strlcpy(path, "/subsystem/", sizeof(path_full) - sys_path_len);
450 util_strlcat(path, subsys, sizeof(path_full) - sys_path_len);
451 util_strlcat(path, "/drivers/", sizeof(path_full) - sys_path_len);
452 util_strlcat(path, driver, sizeof(path_full) - sys_path_len);
453 if (stat(path_full, &statbuf) == 0)
454 goto found;
455
456 util_strlcpy(path, "/bus/", sizeof(path_full) - sys_path_len);
457 util_strlcat(path, subsys, sizeof(path_full) - sys_path_len);
458 util_strlcat(path, "/drivers/", sizeof(path_full) - sys_path_len);
459 util_strlcat(path, driver, sizeof(path_full) - sys_path_len);
460 if (stat(path_full, &statbuf) == 0)
461 goto found;
462 }
463 goto out;
464 }
465
466 util_strlcpy(path, "/subsystem/", sizeof(path_full) - sys_path_len);
467 util_strlcat(path, subsystem, sizeof(path_full) - sys_path_len);
468 util_strlcat(path, "/devices/", sizeof(path_full) - sys_path_len);
469 util_strlcat(path, sysname, sizeof(path_full) - sys_path_len);
470 if (stat(path_full, &statbuf) == 0)
471 goto found;
472
473 util_strlcpy(path, "/bus/", sizeof(path_full) - sys_path_len);
474 util_strlcat(path, subsystem, sizeof(path_full) - sys_path_len);
475 util_strlcat(path, "/devices/", sizeof(path_full) - sys_path_len);
476 util_strlcat(path, sysname, sizeof(path_full) - sys_path_len);
477 if (stat(path_full, &statbuf) == 0)
478 goto found;
479
480 util_strlcpy(path, "/class/", sizeof(path_full) - sys_path_len);
481 util_strlcat(path, subsystem, sizeof(path_full) - sys_path_len);
482 util_strlcat(path, "/", sizeof(path_full) - sys_path_len);
483 util_strlcat(path, sysname, sizeof(path_full) - sys_path_len);
484 if (stat(path_full, &statbuf) == 0)
485 goto found;
486out:
487 return NULL;
488found:
489 return udev_device_new_from_syspath(udev, path_full);
490}
491
b2d9e4f2 492static struct udev_device *device_new_from_parent(struct udev_device *udev_device)
4ad3a37f
KS
493{
494 struct udev_device *udev_device_parent = NULL;
495 char path[UTIL_PATH_SIZE];
b95f8a76 496 const char *subdir;
4ad3a37f 497
b95f8a76
KS
498 /* follow "device" link in deprecated sys layout */
499 if (strncmp(udev_device->devpath, "/class/", 7) == 0 ||
500 strncmp(udev_device->devpath, "/block/", 7) == 0) {
501 util_strlcpy(path, udev_device->syspath, sizeof(path));
502 util_strlcat(path, "/device", sizeof(path));
503 if (util_resolve_sys_link(udev_device->udev, path, sizeof(path)) == 0)
504 udev_device_parent = udev_device_new_from_syspath(udev_device->udev, path);
505 return udev_device_parent;
506 }
4ad3a37f 507
8753fadf 508 util_strlcpy(path, udev_device->syspath, sizeof(path));
b95f8a76 509 subdir = &path[strlen(udev_get_sys_path(udev_device->udev))+1];
4ad3a37f 510 while (1) {
b95f8a76
KS
511 char *pos;
512
513 pos = strrchr(subdir, '/');
514 if (pos == NULL || pos < &subdir[2])
4ad3a37f
KS
515 break;
516 pos[0] = '\0';
8753fadf 517 udev_device_parent = udev_device_new_from_syspath(udev_device->udev, path);
4ad3a37f 518 if (udev_device_parent != NULL)
0518da3b
KS
519 return udev_device_parent;
520 }
0518da3b 521 return NULL;
4ad3a37f
KS
522}
523
b2d9e4f2
KS
524struct udev_device *udev_device_get_parent(struct udev_device *udev_device)
525{
b95f8a76
KS
526 if (udev_device == NULL)
527 return NULL;
31f4b036
KS
528 if (!udev_device->parent_set) {
529 udev_device->parent_set = 1;
530 udev_device->parent_device = device_new_from_parent(udev_device);
0518da3b 531 }
31f4b036
KS
532 if (udev_device->parent_device != NULL)
533 info(udev_device->udev, "returning existing parent %p\n", udev_device->parent_device);
b2d9e4f2
KS
534 return udev_device->parent_device;
535}
536
98f10a9e
KS
537struct udev_device *udev_device_get_parent_with_subsystem(struct udev_device *udev_device, const char *subsystem)
538{
539 struct udev_device *parent;
540
541 parent = udev_device_get_parent(udev_device);
542 while (parent != NULL) {
543 const char *parent_subsystem;
544
545 parent_subsystem = udev_device_get_subsystem(parent);
546 if (parent_subsystem != NULL && strcmp(parent_subsystem, subsystem) == 0)
547 break;
548 parent = udev_device_get_parent(parent);
549 }
550 return parent;
551}
552
eb1f0e66
KS
553/**
554 * udev_device_get_udev:
7d8787b3 555 * @udev_device: udev device
eb1f0e66
KS
556 *
557 * Retrieve the udev library context the device was created with.
558 *
559 * Returns: the udev library context
560 **/
561struct udev *udev_device_get_udev(struct udev_device *udev_device)
562{
ba6929f6
KS
563 if (udev_device == NULL)
564 return NULL;
eb1f0e66
KS
565 return udev_device->udev;
566}
567
568/**
569 * udev_device_ref:
570 * @udev_device: udev device
571 *
572 * Take a reference of a udev device.
573 *
574 * Returns: the passed udev device
575 **/
576struct udev_device *udev_device_ref(struct udev_device *udev_device)
577{
ba6929f6
KS
578 if (udev_device == NULL)
579 return NULL;
eb1f0e66
KS
580 udev_device->refcount++;
581 return udev_device;
582}
583
584/**
585 * udev_device_unref:
586 * @udev_device: udev device
587 *
588 * Drop a reference of a udev device. If the refcount reaches zero,
589 * the ressources of the device will be released.
590 *
591 **/
592void udev_device_unref(struct udev_device *udev_device)
593{
979ff016
KS
594 unsigned int i;
595
ba6929f6
KS
596 if (udev_device == NULL)
597 return;
eb1f0e66
KS
598 udev_device->refcount--;
599 if (udev_device->refcount > 0)
600 return;
b2d9e4f2
KS
601 if (udev_device->parent_device != NULL)
602 udev_device_unref(udev_device->parent_device);
11d543c1 603 free(udev_device->syspath);
517814e7 604 free(udev_device->sysname);
99214844 605 free(udev_device->devnode);
ba6929f6 606 free(udev_device->subsystem);
eb8837e1
KS
607 udev_list_cleanup_entries(udev_device->udev, &udev_device->devlinks_list);
608 udev_list_cleanup_entries(udev_device->udev, &udev_device->properties_list);
1c7047ea
KS
609 free(udev_device->action);
610 free(udev_device->driver);
611 free(udev_device->devpath_old);
612 free(udev_device->physdevpath);
69239210 613 udev_list_cleanup_entries(udev_device->udev, &udev_device->sysattr_list);
979ff016
KS
614 for (i = 0; i < ARRAY_SIZE(udev_device->envp) && udev_device->envp[i] != NULL; i++)
615 free(udev_device->envp[i]);
7d563a17 616 info(udev_device->udev, "udev_device: %p released\n", udev_device);
eb1f0e66
KS
617 free(udev_device);
618}
619
620/**
621 * udev_device_get_devpath:
622 * @udev_device: udev device
623 *
11d543c1
KS
624 * Retrieve the kernel devpath value of the udev device. The path
625 * does not contain the sys mount point, and starts with a '/'.
eb1f0e66 626 *
11d543c1 627 * Returns: the devpath of the udev device
eb1f0e66
KS
628 **/
629const char *udev_device_get_devpath(struct udev_device *udev_device)
630{
ba6929f6
KS
631 if (udev_device == NULL)
632 return NULL;
633 return udev_device->devpath;
eb1f0e66
KS
634}
635
11d543c1
KS
636/**
637 * udev_device_get_syspath:
638 * @udev_device: udev device
639 *
640 * Retrieve the sys path of the udev device. The path is an
641 * absolute path and starts with the sys mount point.
642 *
643 * Returns: the sys path of the udev device
644 **/
645const char *udev_device_get_syspath(struct udev_device *udev_device)
646{
647 if (udev_device == NULL)
648 return NULL;
649 return udev_device->syspath;
650}
651
4ad3a37f
KS
652const char *udev_device_get_sysname(struct udev_device *udev_device)
653{
654 if (udev_device == NULL)
655 return NULL;
656 return udev_device->sysname;
657}
658
517814e7
KS
659const char *udev_device_get_sysnum(struct udev_device *udev_device)
660{
661 if (udev_device == NULL)
662 return NULL;
663 return udev_device->sysnum;
664}
665
eb1f0e66 666/**
fb762bb9 667 * udev_device_get_devnode:
eb1f0e66
KS
668 * @udev_device: udev device
669 *
670 * Retrieve the device node file name belonging to the udev device.
ba6929f6 671 * The path is an absolute path, and starts with the device directory.
eb1f0e66
KS
672 *
673 * Returns: the device node file name of the udev device, or #NULL if no device node exists
674 **/
fb762bb9 675const char *udev_device_get_devnode(struct udev_device *udev_device)
eb1f0e66 676{
ba6929f6 677 if (udev_device == NULL)
eb1f0e66 678 return NULL;
99214844
KS
679 if (!udev_device->info_loaded)
680 device_load_info(udev_device);
681 return udev_device->devnode;
eb1f0e66
KS
682}
683
684/**
685 * udev_device_get_subsystem:
686 * @udev_device: udev device
687 *
688 * Retrieve the subsystem string of the udev device. The string does not
689 * contain any "/".
690 *
691 * Returns: the subsystem name of the udev device, or #NULL if it can not be determined
692 **/
693const char *udev_device_get_subsystem(struct udev_device *udev_device)
694{
17fcfb59 695 char subsystem[UTIL_NAME_SIZE];
ba6929f6
KS
696
697 if (udev_device == NULL)
698 return NULL;
5c5cad79
KS
699 if (!udev_device->subsystem_set) {
700 udev_device->subsystem_set = 1;
701 /* read "subsytem" link */
702 if (util_get_sys_subsystem(udev_device->udev, udev_device->syspath, subsystem, sizeof(subsystem)) > 0) {
703 udev_device_set_subsystem(udev_device, subsystem);
704 return udev_device->subsystem;
705 }
706 /* implicit names */
707 if (strncmp(udev_device->devpath, "/module/", 8) == 0) {
708 udev_device_set_subsystem(udev_device, "module");
709 return udev_device->subsystem;
710 }
711 if (strstr(udev_device->devpath, "/drivers/") != NULL) {
712 udev_device_set_subsystem(udev_device, "drivers");
713 return udev_device->subsystem;
714 }
715 if (strncmp(udev_device->devpath, "/subsystem/", 11) == 0 ||
716 strncmp(udev_device->devpath, "/class/", 7) == 0 ||
717 strncmp(udev_device->devpath, "/bus/", 5) == 0) {
718 udev_device_set_subsystem(udev_device, "subsystem");
719 return udev_device->subsystem;
720 }
0518da3b 721 }
5c5cad79 722 return udev_device->subsystem;
eb1f0e66
KS
723}
724
725/**
0de33a61 726 * udev_device_get_devlinks_list_entry:
eb1f0e66 727 * @udev_device: udev device
eb1f0e66 728 *
bf7ad0ea
KS
729 * Retrieve the list of device links pointing to the device file of
730 * the udev device. The next list entry can be retrieved with
e345e267 731 * udev_list_entry_next(), which returns #NULL if no more entries exist.
bf7ad0ea 732 * The devlink path can be retrieved from the list entry by
e345e267 733 * udev_list_entry_get_name(). The path is an absolute path, and starts with
bf7ad0ea 734 * the device directory.
eb1f0e66 735 *
bf7ad0ea 736 * Returns: the first entry of the device node link list
eb1f0e66 737 **/
0de33a61 738struct udev_list_entry *udev_device_get_devlinks_list_entry(struct udev_device *udev_device)
eb1f0e66 739{
99214844
KS
740 if (udev_device == NULL)
741 return NULL;
742 if (!udev_device->info_loaded)
743 device_load_info(udev_device);
517814e7 744 return udev_list_get_entry(&udev_device->devlinks_list);
eb1f0e66
KS
745}
746
979ff016
KS
747void udev_device_cleanup_devlinks_list(struct udev_device *udev_device)
748{
bd85566c 749 udev_device->devlinks_uptodate = 0;
eb8837e1 750 udev_list_cleanup_entries(udev_device->udev, &udev_device->devlinks_list);
979ff016
KS
751}
752
eb1f0e66 753/**
0de33a61 754 * udev_device_get_properties_list_entry:
eb1f0e66 755 * @udev_device: udev device
eb1f0e66 756 *
bf7ad0ea 757 * Retrieve the list of key/value device properties of the udev
e345e267 758 * device. The next list entry can be retrieved with udev_list_entry_next(),
bf7ad0ea
KS
759 * which returns #NULL if no more entries exist. The property name
760 * can be retrieved from the list entry by udev_list_get_name(),
761 * the property value by udev_list_get_value().
eb1f0e66 762 *
bf7ad0ea 763 * Returns: the first entry of the property list
eb1f0e66 764 **/
0de33a61 765struct udev_list_entry *udev_device_get_properties_list_entry(struct udev_device *udev_device)
eb1f0e66 766{
99214844
KS
767 if (udev_device == NULL)
768 return NULL;
769 if (!udev_device->info_loaded)
770 device_load_info(udev_device);
bd85566c
KS
771 if (!udev_device->devlinks_uptodate) {
772 char symlinks[UTIL_PATH_SIZE];
773 struct udev_list_entry *list_entry;
774
775 udev_device->devlinks_uptodate = 1;
776 list_entry = udev_device_get_devlinks_list_entry(udev_device);
777 if (list_entry != NULL) {
778 util_strlcpy(symlinks, udev_list_entry_get_name(list_entry), sizeof(symlinks));
779 udev_list_entry_foreach(list_entry, udev_list_entry_get_next(list_entry)) {
780 util_strlcat(symlinks, " ", sizeof(symlinks));
781 util_strlcat(symlinks, udev_list_entry_get_name(list_entry), sizeof(symlinks));
782 }
783 udev_device_add_property(udev_device, "DEVLINKS", symlinks);
784 }
785 }
8cd2e972 786 return udev_list_get_entry(&udev_device->properties_list);
eb1f0e66 787}
11d543c1 788
c4f5f942
KS
789const char *udev_device_get_driver(struct udev_device *udev_device)
790{
17fcfb59 791 char driver[UTIL_NAME_SIZE];
95d90c4f 792
c4f5f942
KS
793 if (udev_device == NULL)
794 return NULL;
5c5cad79
KS
795 if (!udev_device->driver_set) {
796 udev_device->driver_set = 1;
797 if (util_get_sys_driver(udev_device->udev, udev_device->syspath, driver, sizeof(driver)) > 0)
798 udev_device->driver = strdup(driver);
799 }
c4f5f942
KS
800 return udev_device->driver;
801}
802
803dev_t udev_device_get_devnum(struct udev_device *udev_device)
804{
805 if (udev_device == NULL)
806 return makedev(0, 0);
99214844
KS
807 if (!udev_device->info_loaded)
808 device_load_info(udev_device);
c4f5f942
KS
809 return udev_device->devnum;
810}
811
812const char *udev_device_get_action(struct udev_device *udev_device)
813{
814 if (udev_device == NULL)
815 return NULL;
816 return udev_device->action;
817}
818
37372bbc
KS
819unsigned long long int udev_device_get_seqnum(struct udev_device *udev_device)
820{
821 if (udev_device == NULL)
822 return 0;
823 return udev_device->seqnum;
824}
825
69239210 826const char *udev_device_get_sysattr_value(struct udev_device *udev_device, const char *sysattr)
93b0f384 827{
0de33a61 828 struct udev_list_entry *list_entry;
93b0f384
KS
829 char path[UTIL_PATH_SIZE];
830 char value[UTIL_NAME_SIZE];
831 struct stat statbuf;
832 int fd;
833 ssize_t size;
834 const char *val = NULL;
835
517814e7
KS
836 if (udev_device == NULL)
837 return NULL;
69239210 838 if (sysattr == NULL)
517814e7
KS
839 return NULL;
840
0518da3b 841 /* look for possibly already cached result */
69239210
KS
842 udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_device->sysattr_list)) {
843 if (strcmp(udev_list_entry_get_name(list_entry), sysattr) == 0) {
517814e7 844 info(udev_device->udev, "got '%s' (%s) from cache\n",
69239210 845 sysattr, udev_list_entry_get_value(list_entry));
0de33a61 846 return udev_list_entry_get_value(list_entry);
0518da3b
KS
847 }
848 }
849
93b0f384
KS
850 util_strlcpy(path, udev_device_get_syspath(udev_device), sizeof(path));
851 util_strlcat(path, "/", sizeof(path));
69239210 852 util_strlcat(path, sysattr, sizeof(path));
93b0f384
KS
853
854 if (lstat(path, &statbuf) != 0) {
5c5cad79 855 info(udev_device->udev, "no attribute '%s', keep negative entry\n", path);
69239210 856 udev_list_entry_add(udev_device->udev, &udev_device->sysattr_list, sysattr, NULL, 0, 0);
93b0f384
KS
857 goto out;
858 }
859
860 if (S_ISLNK(statbuf.st_mode)) {
861 /* links return the last element of the target path */
862 char target[UTIL_NAME_SIZE];
863 int len;
864 char *pos;
865
866 len = readlink(path, target, sizeof(target));
867 if (len > 0) {
868 target[len] = '\0';
869 pos = strrchr(target, '/');
870 if (pos != NULL) {
871 pos = &pos[1];
69239210
KS
872 info(udev_device->udev, "cache '%s' with link value '%s'\n", sysattr, pos);
873 list_entry = udev_list_entry_add(udev_device->udev, &udev_device->sysattr_list, sysattr, pos, 0, 0);
0de33a61 874 val = udev_list_entry_get_value(list_entry);
93b0f384
KS
875 }
876 }
877 goto out;
878 }
879
880 /* skip directories */
881 if (S_ISDIR(statbuf.st_mode))
882 goto out;
883
884 /* skip non-readable files */
885 if ((statbuf.st_mode & S_IRUSR) == 0)
886 goto out;
887
888 /* read attribute value */
889 fd = open(path, O_RDONLY);
890 if (fd < 0) {
891 info(udev_device->udev, "attribute '%s' can not be opened\n", path);
892 goto out;
893 }
894 size = read(fd, value, sizeof(value));
895 close(fd);
896 if (size < 0)
897 goto out;
898 if (size == sizeof(value))
899 goto out;
900
0518da3b 901 /* got a valid value, store it in cache and return it */
93b0f384
KS
902 value[size] = '\0';
903 util_remove_trailing_chars(value, '\n');
904 info(udev_device->udev, "'%s' has attribute value '%s'\n", path, value);
69239210 905 list_entry = udev_list_entry_add(udev_device->udev, &udev_device->sysattr_list, sysattr, value, 0, 0);
0de33a61 906 val = udev_list_entry_get_value(list_entry);
93b0f384
KS
907out:
908 return val;
909}
517814e7 910
8cd2e972 911int udev_device_set_syspath(struct udev_device *udev_device, const char *syspath)
11d543c1 912{
8753fadf 913 const char *pos;
517814e7 914 size_t len;
8753fadf 915
8cd2e972 916 free(udev_device->syspath);
8753fadf
KS
917 udev_device->syspath = strdup(syspath);
918 if (udev_device->syspath == NULL)
11d543c1
KS
919 return -ENOMEM;
920 udev_device->devpath = &udev_device->syspath[strlen(udev_get_sys_path(udev_device->udev))];
9a997ecf 921 udev_device_add_property(udev_device, "DEVPATH", udev_device->devpath);
517814e7 922
8753fadf
KS
923 pos = strrchr(udev_device->syspath, '/');
924 if (pos == NULL)
925 return -EINVAL;
517814e7
KS
926 udev_device->sysname = strdup(&pos[1]);
927 if (udev_device->sysname == NULL)
928 return -ENOMEM;
929
930 /* some devices have '!' in their name, change that to '/' */
931 len = 0;
932 while (udev_device->sysname[len] != '\0') {
933 if (udev_device->sysname[len] == '!')
934 udev_device->sysname[len] = '/';
935 len++;
936 }
937
938 /* trailing number */
babcf3cb 939 while (len > 0 && isdigit(udev_device->sysname[--len]))
517814e7 940 udev_device->sysnum = &udev_device->sysname[len];
babcf3cb
AJ
941
942 /* sysname is completely numeric */
943 if (len == 0)
944 udev_device->sysnum = NULL;
945
11d543c1
KS
946 return 0;
947}
948
8cd2e972 949int udev_device_set_subsystem(struct udev_device *udev_device, const char *subsystem)
11d543c1 950{
979ff016 951 free(udev_device->subsystem);
11d543c1
KS
952 udev_device->subsystem = strdup(subsystem);
953 if (udev_device->subsystem == NULL)
9a997ecf 954 return -ENOMEM;
5c5cad79 955 udev_device->subsystem_set = 1;
9a997ecf 956 udev_device_add_property(udev_device, "SUBSYSTEM", udev_device->subsystem);
11d543c1
KS
957 return 0;
958}
959
8cd2e972 960int udev_device_set_devnode(struct udev_device *udev_device, const char *devnode)
11d543c1 961{
517814e7 962 free(udev_device->devnode);
99214844 963 udev_device->devnode = strdup(devnode);
bd85566c
KS
964 if (devnode == NULL)
965 return 0;
99214844 966 if (udev_device->devnode == NULL)
11d543c1 967 return -ENOMEM;
979ff016 968 udev_device_add_property(udev_device, "DEVNAME", udev_device->devnode);
11d543c1
KS
969 return 0;
970}
971
8cd2e972 972int udev_device_add_devlink(struct udev_device *udev_device, const char *devlink)
11d543c1 973{
bd85566c 974 udev_device->devlinks_uptodate = 0;
517814e7 975 if (udev_list_entry_add(udev_device->udev, &udev_device->devlinks_list, devlink, NULL, 1, 0) == NULL)
11d543c1
KS
976 return -ENOMEM;
977 return 0;
978}
979
517814e7 980struct udev_list_entry *udev_device_add_property(struct udev_device *udev_device, const char *key, const char *value)
11d543c1 981{
979ff016 982 udev_device->envp_uptodate = 0;
ebacd6ec
KS
983 if (value == NULL) {
984 struct udev_list_entry *list_entry;
985
986 list_entry = udev_device_get_properties_list_entry(udev_device);
987 list_entry = udev_list_entry_get_by_name(list_entry, key);
988 if (list_entry != NULL)
989 udev_list_entry_remove(list_entry);
990 return NULL;
991 }
517814e7 992 return udev_list_entry_add(udev_device->udev, &udev_device->properties_list, key, value, 1, 0);
11d543c1 993}
c4f5f942 994
517814e7 995struct udev_list_entry *udev_device_add_property_from_string(struct udev_device *udev_device, const char *property)
0518da3b
KS
996{
997 char name[UTIL_PATH_SIZE];
998 char *val;
999
1000 strncpy(name, property, sizeof(name));
1001 val = strchr(name, '=');
1002 if (val == NULL)
517814e7 1003 return NULL;
0518da3b
KS
1004 val[0] = '\0';
1005 val = &val[1];
1006 if (val[0] == '\0')
1007 val = NULL;
517814e7 1008 return udev_device_add_property(udev_device, name, val);
0518da3b
KS
1009}
1010
979ff016
KS
1011char **udev_device_get_properties_envp(struct udev_device *udev_device)
1012{
1013 if (!udev_device->envp_uptodate) {
1014 unsigned int i;
1015 struct udev_list_entry *list_entry;
1016
1017 for (i = 0; i < ARRAY_SIZE(udev_device->envp) && udev_device->envp[i] != NULL; i++)
1018 free(udev_device->envp[i]);
1019 i = 0;
1020 udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(udev_device)) {
1021 asprintf(&udev_device->envp[i++], "%s=%s",
1022 udev_list_entry_get_name(list_entry),
1023 udev_list_entry_get_value(list_entry));
1024 if (i+1 >= ARRAY_SIZE(udev_device->envp))
1025 break;
1026 }
1027 udev_device->envp[i] = NULL;
1028 info(udev_device->udev, "constructed envp from %u properties\n", i);
1029 udev_device->envp_uptodate = 1;
1030 }
1031 return udev_device->envp;
1032}
1033
8cd2e972 1034int udev_device_set_action(struct udev_device *udev_device, const char *action)
c4f5f942 1035{
517814e7 1036 free(udev_device->action);
c4f5f942
KS
1037 udev_device->action = strdup(action);
1038 if (udev_device->action == NULL)
1039 return -ENOMEM;
31f4b036 1040 udev_device_add_property(udev_device, "ACTION", udev_device->action);
c4f5f942
KS
1041 return 0;
1042}
1043
8cd2e972 1044int udev_device_set_driver(struct udev_device *udev_device, const char *driver)
c4f5f942 1045{
979ff016 1046 free(udev_device->driver);
c4f5f942
KS
1047 udev_device->driver = strdup(driver);
1048 if (udev_device->driver == NULL)
1049 return -ENOMEM;
5c5cad79 1050 udev_device->driver_set = 1;
31f4b036 1051 udev_device_add_property(udev_device, "DRIVER", udev_device->driver);
c4f5f942
KS
1052 return 0;
1053}
1054
8cd2e972 1055const char *udev_device_get_devpath_old(struct udev_device *udev_device)
c4f5f942 1056{
c4f5f942
KS
1057 return udev_device->devpath_old;
1058}
1059
8cd2e972 1060int udev_device_set_devpath_old(struct udev_device *udev_device, const char *devpath_old)
c4f5f942
KS
1061{
1062 udev_device->devpath_old = strdup(devpath_old);
1063 if (udev_device->devpath_old == NULL)
1064 return -ENOMEM;
31f4b036 1065 udev_device_add_property(udev_device, "DEVPATH_OLD", udev_device->devpath_old);
c4f5f942
KS
1066 return 0;
1067}
1068
8cd2e972 1069const char *udev_device_get_physdevpath(struct udev_device *udev_device)
c4f5f942 1070{
c4f5f942
KS
1071 return udev_device->physdevpath;
1072}
1073
8cd2e972 1074int udev_device_set_physdevpath(struct udev_device *udev_device, const char *physdevpath)
c4f5f942
KS
1075{
1076 udev_device->physdevpath = strdup(physdevpath);
1077 if (udev_device->physdevpath == NULL)
1078 return -ENOMEM;
1079 return 0;
1080}
1081
8cd2e972 1082int udev_device_get_timeout(struct udev_device *udev_device)
c4f5f942 1083{
c4f5f942
KS
1084 return udev_device->timeout;
1085}
1086
8cd2e972 1087int udev_device_set_timeout(struct udev_device *udev_device, int timeout)
c4f5f942
KS
1088{
1089 udev_device->timeout = timeout;
1090 return 0;
1091}
8cd2e972 1092int udev_device_get_event_timeout(struct udev_device *udev_device)
99214844
KS
1093{
1094 if (!udev_device->info_loaded)
1095 device_load_info(udev_device);
1096 return udev_device->event_timeout;
1097}
1098
8cd2e972 1099int udev_device_set_event_timeout(struct udev_device *udev_device, int event_timeout)
99214844
KS
1100{
1101 udev_device->event_timeout = event_timeout;
1102 return 0;
1103}
c4f5f942 1104
8cd2e972 1105int udev_device_set_seqnum(struct udev_device *udev_device, unsigned long long int seqnum)
37372bbc 1106{
31f4b036
KS
1107 char num[32];
1108
37372bbc 1109 udev_device->seqnum = seqnum;
31f4b036
KS
1110 snprintf(num, sizeof(num), "%llu", seqnum);
1111 udev_device_add_property(udev_device, "SEQNUM", num);
37372bbc
KS
1112 return 0;
1113}
1114
8cd2e972 1115int udev_device_set_devnum(struct udev_device *udev_device, dev_t devnum)
c4f5f942 1116{
31f4b036
KS
1117 char num[32];
1118
c4f5f942 1119 udev_device->devnum = devnum;
31f4b036
KS
1120
1121 snprintf(num, sizeof(num), "%u", major(devnum));
1122 udev_device_add_property(udev_device, "MAJOR", num);
1123 snprintf(num, sizeof(num), "%u", minor(devnum));
1124 udev_device_add_property(udev_device, "MINOR", num);
c4f5f942
KS
1125 return 0;
1126}
6bd1c78a 1127
8cd2e972 1128int udev_device_get_num_fake_partitions(struct udev_device *udev_device)
6bd1c78a 1129{
99214844
KS
1130 if (!udev_device->info_loaded)
1131 device_load_info(udev_device);
6bd1c78a
KS
1132 return udev_device->num_fake_partitions;
1133}
1134
8cd2e972 1135int udev_device_set_num_fake_partitions(struct udev_device *udev_device, int num)
6bd1c78a
KS
1136{
1137 udev_device->num_fake_partitions = num;
e88a82b5 1138 return 0;
6bd1c78a
KS
1139}
1140
8cd2e972 1141int udev_device_get_devlink_priority(struct udev_device *udev_device)
6bd1c78a 1142{
99214844
KS
1143 if (!udev_device->info_loaded)
1144 device_load_info(udev_device);
e88a82b5 1145 return udev_device->devlink_priority;
6bd1c78a
KS
1146}
1147
8cd2e972 1148int udev_device_set_devlink_priority(struct udev_device *udev_device, int prio)
6bd1c78a 1149{
e88a82b5
KS
1150 udev_device->devlink_priority = prio;
1151 return 0;
6bd1c78a
KS
1152}
1153
8cd2e972 1154int udev_device_get_ignore_remove(struct udev_device *udev_device)
6bd1c78a 1155{
99214844
KS
1156 if (!udev_device->info_loaded)
1157 device_load_info(udev_device);
6bd1c78a
KS
1158 return udev_device->ignore_remove;
1159}
1160
8cd2e972 1161int udev_device_set_ignore_remove(struct udev_device *udev_device, int ignore)
6bd1c78a 1162{
e88a82b5
KS
1163 udev_device->ignore_remove = ignore;
1164 return 0;
6bd1c78a 1165}