chiark / gitweb /
918398b7930aa7bc59ef5a6602ed4b197cc97d60
[elogind.git] / udev / lib / libudev-device.c
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
20 #include "config.h"
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <stddef.h>
25 #include <unistd.h>
26 #include <errno.h>
27 #include <string.h>
28 #include <dirent.h>
29 #include <fcntl.h>
30 #include <sys/stat.h>
31
32 #include "libudev.h"
33 #include "libudev-private.h"
34
35 struct udev_device {
36         int refcount;
37         struct udev *udev;
38         struct udev_device *parent_device;
39         char *syspath;
40         const char *devpath;
41         const char *sysname;
42         char *devname;
43         char *subsystem;
44         struct list_head link_list;
45         struct list_head env_list;
46         char *action;
47         char *driver;
48         char *devpath_old;
49         char *physdevpath;
50         int timeout;
51         dev_t devnum;
52         unsigned long long int seqnum;
53         int num_fake_partitions;
54         int devlink_priority;
55         int ignore_remove;
56         struct list_head attr_list;
57 };
58
59 static size_t devpath_to_db_path(struct udev *udev, const char *devpath, char *filename, size_t len)
60 {
61         size_t start;
62
63         /* translate to location of db file */
64         util_strlcpy(filename, udev_get_dev_path(udev), len);
65         start = util_strlcat(filename, "/.udev/db/", len);
66         util_strlcat(filename, devpath, len);
67         return util_path_encode(&filename[start], len - start);
68 }
69
70 static int device_read_db(struct udev_device *udev_device)
71 {
72         struct stat stats;
73         char filename[UTIL_PATH_SIZE];
74         char line[UTIL_LINE_SIZE];
75         FILE *f;
76         int rc = 0;
77
78         devpath_to_db_path(udev_device->udev, udev_device->devpath, filename, sizeof(filename));
79
80         if (lstat(filename, &stats) != 0) {
81                 info(udev_device->udev, "no db file to read %s: %s\n", filename, strerror(errno));
82                 return -1;
83         }
84         if ((stats.st_mode & S_IFMT) == S_IFLNK) {
85                 char target[UTIL_PATH_SIZE];
86                 int target_len;
87
88                 info(udev_device->udev, "found a symlink as db file\n");
89                 target_len = readlink(filename, target, sizeof(target));
90                 if (target_len > 0)
91                         target[target_len] = '\0';
92                 else {
93                         info(udev_device->udev, "error reading db link %s: %s\n", filename, strerror(errno));
94                         return -1;
95                 }
96                 dbg(udev_device->udev, "db link points to '%s'\n", target);
97                 if (asprintf(&udev_device->devname, "%s/%s", udev_get_dev_path(udev_device->udev), target) < 0)
98                         return -ENOMEM;
99                 return 0;
100         }
101
102         f = fopen(filename, "r");
103         if (f == NULL) {
104                 info(udev_device->udev, "error reading db file %s: %s\n", filename, strerror(errno));
105                 return -1;
106         }
107         while (fgets(line, sizeof(line), f)) {
108                 ssize_t len;
109                 const char *val;
110                 unsigned int maj, min;
111
112                 len = strlen(line);
113                 if (len < 4)
114                         break;
115                 line[len-1] = '\0';
116                 val = &line[2];
117
118                 switch(line[0]) {
119                 case 'N':
120                         asprintf(&udev_device->devname, "%s/%s", udev_get_dev_path(udev_device->udev), val);
121                         break;
122                 case 'M':
123                         sscanf(val, "%u:%u", &maj, &min);
124                         device_set_devnum(udev_device, makedev(maj, min));
125                         break;
126                 case 'S':
127                         util_strlcpy(filename, udev_get_dev_path(udev_device->udev), sizeof(filename));
128                         util_strlcat(filename, "/", sizeof(filename));
129                         util_strlcat(filename, val, sizeof(filename));
130                         device_add_devlink(udev_device, filename);
131                         break;
132                 case 'L':
133                         device_set_devlink_priority(udev_device, atoi(val));
134                         break;
135                 case 'T':
136                         device_set_timeout(udev_device,  atoi(val));
137                         break;
138                 case 'A':
139                         device_set_num_fake_partitions(udev_device, atoi(val));
140                         break;
141                 case 'R':
142                         device_set_ignore_remove(udev_device, atoi(val));
143                         break;
144                 case 'E':
145                         device_add_property_from_string(udev_device, val);
146                         break;
147                 }
148         }
149         fclose(f);
150
151         return rc;
152 }
153
154 struct udev_device *device_init(struct udev *udev)
155 {
156         struct udev_device *udev_device;
157
158         if (udev == NULL)
159                 return NULL;
160
161         udev_device = malloc(sizeof(struct udev_device));
162         if (udev_device == NULL)
163                 return NULL;
164         memset(udev_device, 0x00, sizeof(struct udev_device));
165         udev_device->refcount = 1;
166         udev_device->udev = udev;
167         INIT_LIST_HEAD(&udev_device->link_list);
168         INIT_LIST_HEAD(&udev_device->env_list);
169         INIT_LIST_HEAD(&udev_device->attr_list);
170         info(udev_device->udev, "udev_device: %p created\n", udev_device);
171         return udev_device;
172 }
173
174 /**
175  * udev_device_new_from_devpath:
176  * @udev: udev library context
177  * @devpath: sys device path
178  *
179  * Create new udev device, and fill in information from the sysfs
180  * device and the udev database entry. The devpath must not contain
181  * the sysfs mount path, and must contain a leading '/'.
182  *
183  * The initial refcount is 1, and needs to be decremented to
184  * release the ressources of the udev device.
185  *
186  * Returns: a new udev device, or #NULL, if it does not exist
187  **/
188 struct udev_device *udev_device_new_from_devpath(struct udev *udev, const char *devpath)
189 {
190         char path[UTIL_PATH_SIZE];
191         struct stat statbuf;
192         struct udev_device *udev_device;
193
194         if (udev == NULL)
195                 return NULL;
196         if (devpath == NULL)
197                 return NULL;
198
199         util_strlcpy(path, udev_get_sys_path(udev), sizeof(path));
200         util_strlcat(path, devpath, sizeof(path));
201         util_strlcat(path, "/uevent", sizeof(path));
202         if (stat(path, &statbuf) != 0) {
203                 info(udev, "not a device :%s\n", devpath);
204                 return NULL;
205         }
206
207         udev_device = device_init(udev);
208         if (udev_device == NULL)
209                 return NULL;
210
211         /* resolve possible symlink to real path */
212         util_strlcpy(path, devpath, sizeof(path));
213         util_resolve_sys_link(udev, path, sizeof(path));
214         device_set_devpath(udev_device, path);
215         info(udev, "device %p has devpath '%s'\n", udev_device, udev_device_get_devpath(udev_device));
216
217         if (device_read_db(udev_device) >= 0)
218                 info(udev, "device %p filled with udev database data\n", udev_device);
219         return udev_device;
220 }
221
222 static struct udev_device *device_new_from_parent(struct udev_device *udev_device)
223 {
224         struct udev_device *udev_device_parent = NULL;
225         char path[UTIL_PATH_SIZE];
226         char *pos;
227
228         if (udev_device == NULL)
229                 return NULL;
230
231         util_strlcpy(path, udev_device_get_devpath(udev_device), sizeof(path));
232         while (1) {
233                 pos = strrchr(path, '/');
234                 if (pos == path || pos == NULL)
235                         break;
236                 pos[0] = '\0';
237                 udev_device_parent = udev_device_new_from_devpath(udev_device->udev, path);
238                 if (udev_device_parent != NULL)
239                         return udev_device_parent;
240         }
241
242         /* follow "device" link in deprecated sysfs /sys/class/ layout */
243         if (strncmp(udev_device->devpath, "/class/", 7) == 0) {
244                 util_strlcpy(path, udev_device->devpath, sizeof(path));
245                 util_strlcat(path, "/device", sizeof(path));
246                 if (util_resolve_sys_link(udev_device->udev, path, sizeof(path)) == 0) {
247                         udev_device_parent = udev_device_new_from_devpath(udev_device->udev, path);
248                         if (udev_device_parent != NULL)
249                                 return udev_device_parent;
250                 }
251         }
252         return NULL;
253 }
254
255 struct udev_device *udev_device_get_parent(struct udev_device *udev_device)
256 {
257         if (udev_device->parent_device != NULL) {
258                 info(udev_device->udev, "returning existing parent %p\n", udev_device->parent_device);
259                 return udev_device->parent_device;
260         }
261         udev_device->parent_device = device_new_from_parent(udev_device);
262         return udev_device->parent_device;
263 }
264
265 /**
266  * udev_device_get_udev:
267  * @udev_device: udev device
268  *
269  * Retrieve the udev library context the device was created with.
270  *
271  * Returns: the udev library context
272  **/
273 struct udev *udev_device_get_udev(struct udev_device *udev_device)
274 {
275         if (udev_device == NULL)
276                 return NULL;
277         return udev_device->udev;
278 }
279
280 /**
281  * udev_device_ref:
282  * @udev_device: udev device
283  *
284  * Take a reference of a udev device.
285  *
286  * Returns: the passed udev device
287  **/
288 struct udev_device *udev_device_ref(struct udev_device *udev_device)
289 {
290         if (udev_device == NULL)
291                 return NULL;
292         udev_device->refcount++;
293         return udev_device;
294 }
295
296 /**
297  * udev_device_unref:
298  * @udev_device: udev device
299  *
300  * Drop a reference of a udev device. If the refcount reaches zero,
301  * the ressources of the device will be released.
302  *
303  **/
304 void udev_device_unref(struct udev_device *udev_device)
305 {
306         if (udev_device == NULL)
307                 return;
308         udev_device->refcount--;
309         if (udev_device->refcount > 0)
310                 return;
311         if (udev_device->parent_device != NULL)
312                 udev_device_unref(udev_device->parent_device);
313         free(udev_device->syspath);
314         free(udev_device->devname);
315         free(udev_device->subsystem);
316         util_name_list_cleanup(udev_device->udev, &udev_device->link_list);
317         util_name_list_cleanup(udev_device->udev, &udev_device->env_list);
318         free(udev_device->action);
319         free(udev_device->driver);
320         free(udev_device->devpath_old);
321         free(udev_device->physdevpath);
322         util_name_list_cleanup(udev_device->udev, &udev_device->attr_list);
323         info(udev_device->udev, "udev_device: %p released\n", udev_device);
324         free(udev_device);
325 }
326
327 /**
328  * udev_device_get_devpath:
329  * @udev_device: udev device
330  *
331  * Retrieve the kernel devpath value of the udev device. The path
332  * does not contain the sys mount point, and starts with a '/'.
333  *
334  * Returns: the devpath of the udev device
335  **/
336 const char *udev_device_get_devpath(struct udev_device *udev_device)
337 {
338         if (udev_device == NULL)
339                 return NULL;
340         return udev_device->devpath;
341 }
342
343 /**
344  * udev_device_get_syspath:
345  * @udev_device: udev device
346  *
347  * Retrieve the sys path of the udev device. The path is an
348  * absolute path and starts with the sys mount point.
349  *
350  * Returns: the sys path of the udev device
351  **/
352 const char *udev_device_get_syspath(struct udev_device *udev_device)
353 {
354         if (udev_device == NULL)
355                 return NULL;
356         return udev_device->syspath;
357 }
358
359 const char *udev_device_get_sysname(struct udev_device *udev_device)
360 {
361         if (udev_device == NULL)
362                 return NULL;
363         return udev_device->sysname;
364 }
365
366 /**
367  * udev_device_get_devname:
368  * @udev_device: udev device
369  *
370  * Retrieve the device node file name belonging to the udev device.
371  * The path is an absolute path, and starts with the device directory.
372  *
373  * Returns: the device node file name of the udev device, or #NULL if no device node exists
374  **/
375 const char *udev_device_get_devname(struct udev_device *udev_device)
376 {
377         if (udev_device == NULL)
378                 return NULL;
379         return udev_device->devname;
380 }
381
382 /**
383  * udev_device_get_subsystem:
384  * @udev_device: udev device
385  *
386  * Retrieve the subsystem string of the udev device. The string does not
387  * contain any "/".
388  *
389  * Returns: the subsystem name of the udev device, or #NULL if it can not be determined
390  **/
391 const char *udev_device_get_subsystem(struct udev_device *udev_device)
392 {
393         char subsystem[UTIL_NAME_SIZE];
394
395         if (udev_device == NULL)
396                 return NULL;
397         if (udev_device->subsystem != NULL)
398                 return udev_device->subsystem;
399
400         /* read "subsytem" link */
401         if (util_get_sys_subsystem(udev_device->udev, udev_device->devpath, subsystem, sizeof(subsystem)) == 0) {
402                 udev_device->subsystem = strdup(subsystem);
403                 return udev_device->subsystem;
404         }
405
406         /* implicit names */
407         if (strncmp(udev_device->devpath, "/module/", 8) == 0) {
408                 udev_device->subsystem = strdup("module");
409                 return udev_device->subsystem;
410         }
411         if (strstr(udev_device->devpath, "/drivers/") != NULL) {
412                 udev_device->subsystem = strdup("drivers");
413                 return udev_device->subsystem;
414         }
415         if (strncmp(udev_device->devpath, "/subsystem/", 11) == 0 ||
416             strncmp(udev_device->devpath, "/class/", 7) == 0 ||
417             strncmp(udev_device->devpath, "/bus/", 5) == 0) {
418                 udev_device->subsystem = strdup("subsystem");
419                 return udev_device->subsystem;
420         }
421         return NULL;
422 }
423
424 /**
425  * udev_device_get_devlinks:
426  * @udev_device: udev device
427  * @cb: function to be called for every device link found
428  * @data: data to be passed to the function
429  *
430  * Retrieve the device links pointing to the device file of the
431  * udev device. For every device link, the passed function will be
432  * called with the device link string.
433  * The path is an absolute path, and starts with the device directory.
434  * If the function returns 1, remaning device links will be ignored.
435  *
436  * Returns: the number of device links passed to the caller, or a negative value on error
437  **/
438 int udev_device_get_devlinks(struct udev_device *udev_device,
439                               int (*cb)(struct udev_device *udev_device, const char *value, void *data),
440                               void *data)
441 {
442         struct util_name_entry *name_loop;
443         int count = 0;
444
445         if (udev_device == NULL)
446                 return -1;
447         list_for_each_entry(name_loop, &udev_device->link_list, node) {
448                 count++;
449                 if (cb(udev_device, name_loop->name, data) != 0)
450                         break;
451         }
452         return count;
453 }
454
455 /**
456  * udev_device_get_properties:
457  * @udev_device: udev device
458  * @cb: function to be called for every property found
459  * @data: data to be passed to the function
460  *
461  * Retrieve the property key/value pairs belonging to the
462  * udev device. For every key/value pair, the passed function will be
463  * called. If the function returns 1, remaning properties will be
464  * ignored.
465  *
466  * Returns: the number of properties passed to the caller, or a negative value on error
467  **/
468 int udev_device_get_properties(struct udev_device *udev_device,
469                                 int (*cb)(struct udev_device *udev_device, const char *key, const char *value, void *data),
470                                 void *data)
471 {
472         struct util_name_entry *name_loop;
473         int count = 0;
474
475         if (udev_device == NULL)
476                 return -1;
477         list_for_each_entry(name_loop, &udev_device->env_list, node) {
478                 count++;
479                 if (cb(udev_device, name_loop->name, name_loop->value, data) != 0)
480                         break;
481         }
482         return count;
483 }
484
485 const char *udev_device_get_driver(struct udev_device *udev_device)
486 {
487         char driver[UTIL_NAME_SIZE];
488
489         if (udev_device == NULL)
490                 return NULL;
491         if (udev_device->driver != NULL)
492                 return udev_device->driver;
493         if (util_get_sys_driver(udev_device->udev, udev_device->devpath, driver, sizeof(driver)) < 2)
494                 return NULL;
495         udev_device->driver = strdup(driver);
496         return udev_device->driver;
497 }
498
499 dev_t udev_device_get_devnum(struct udev_device *udev_device)
500 {
501         if (udev_device == NULL)
502                 return makedev(0, 0);
503         return udev_device->devnum;
504 }
505
506 const char *udev_device_get_action(struct udev_device *udev_device)
507 {
508         if (udev_device == NULL)
509                 return NULL;
510         return udev_device->action;
511 }
512
513 unsigned long long int udev_device_get_seqnum(struct udev_device *udev_device)
514 {
515         if (udev_device == NULL)
516                 return 0;
517         return udev_device->seqnum;
518 }
519
520 const char *udev_device_get_attr_value(struct udev_device *udev_device, const char *attr)
521 {
522         struct util_name_entry *name_loop;
523         char path[UTIL_PATH_SIZE];
524         char value[UTIL_NAME_SIZE];
525         struct stat statbuf;
526         int fd;
527         ssize_t size;
528         const char *val = NULL;
529
530         /* look for possibly already cached result */
531         list_for_each_entry(name_loop, &udev_device->attr_list, node) {
532                 if (strcmp(name_loop->name, attr) == 0) {
533                         info(udev_device->udev, "'%s' in cache '%s'\n", attr, name_loop->value);
534                         return name_loop->value;
535                 }
536         }
537
538         util_strlcpy(path, udev_device_get_syspath(udev_device), sizeof(path));
539         util_strlcat(path, "/", sizeof(path));
540         util_strlcat(path, attr, sizeof(path));
541
542         if (lstat(path, &statbuf) != 0) {
543                 info(udev_device->udev, "stat '%s' failed: %s\n", path, strerror(errno));
544                 goto out;
545         }
546
547         if (S_ISLNK(statbuf.st_mode)) {
548                 /* links return the last element of the target path */
549                 char target[UTIL_NAME_SIZE];
550                 int len;
551                 char *pos;
552
553                 len = readlink(path, target, sizeof(target));
554                 if (len > 0) {
555                         target[len] = '\0';
556                         pos = strrchr(target, '/');
557                         if (pos != NULL) {
558                                 pos = &pos[1];
559                                 info(udev_device->udev, "cache '%s' with link value '%s'\n", attr, pos);
560                                 val = util_name_list_add(udev_device->udev, &udev_device->attr_list, attr, pos, 0)->value;
561                         }
562                 }
563                 goto out;
564         }
565
566         /* skip directories */
567         if (S_ISDIR(statbuf.st_mode))
568                 goto out;
569
570         /* skip non-readable files */
571         if ((statbuf.st_mode & S_IRUSR) == 0)
572                 goto out;
573
574         /* read attribute value */
575         fd = open(path, O_RDONLY);
576         if (fd < 0) {
577                 info(udev_device->udev, "attribute '%s' can not be opened\n", path);
578                 goto out;
579         }
580         size = read(fd, value, sizeof(value));
581         close(fd);
582         if (size < 0)
583                 goto out;
584         if (size == sizeof(value))
585                 goto out;
586
587         /* got a valid value, store it in cache and return it */
588         value[size] = '\0';
589         util_remove_trailing_chars(value, '\n');
590         info(udev_device->udev, "'%s' has attribute value '%s'\n", path, value);
591         val = util_name_list_add(udev_device->udev, &udev_device->attr_list, attr, value, 0)->value;
592 out:
593         return val;
594 }
595 int device_set_devpath(struct udev_device *udev_device, const char *devpath)
596 {
597         if (asprintf(&udev_device->syspath, "%s%s", udev_get_sys_path(udev_device->udev), devpath) < 0)
598                 return -ENOMEM;
599         udev_device->devpath = &udev_device->syspath[strlen(udev_get_sys_path(udev_device->udev))];
600         udev_device->sysname = strrchr(udev_device->syspath, '/');
601         if (udev_device->sysname != NULL)
602                 udev_device->sysname = &udev_device->sysname[1];
603         return 0;
604 }
605
606 int device_set_subsystem(struct udev_device *udev_device, const char *subsystem)
607 {
608         udev_device->subsystem = strdup(subsystem);
609         if (udev_device->subsystem == NULL)
610                 return -1;
611         return 0;
612 }
613
614 int device_set_devname(struct udev_device *udev_device, const char *devname)
615 {
616         udev_device->devname = strdup(devname);
617         if (udev_device->devname == NULL)
618                 return -ENOMEM;
619         return 0;
620 }
621
622 int device_add_devlink(struct udev_device *udev_device, const char *devlink)
623 {
624         if (util_name_list_add(udev_device->udev, &udev_device->link_list, devlink, NULL, 0) == NULL)
625                 return -ENOMEM;
626         return 0;
627 }
628
629 int device_add_property(struct udev_device *udev_device, const char *key, const char *value)
630 {
631         if (util_name_list_add(udev_device->udev, &udev_device->env_list, key, value, 0) == NULL)
632                 return -ENOMEM;
633         return 0;
634 }
635
636 int device_add_property_from_string(struct udev_device *udev_device, const char *property)
637 {
638         char name[UTIL_PATH_SIZE];
639         char *val;
640
641         strncpy(name, property, sizeof(name));
642         val = strchr(name, '=');
643         if (val == NULL)
644                 return -1;
645         val[0] = '\0';
646         val = &val[1];
647         if (val[0] == '\0')
648                 val = NULL;
649         device_add_property(udev_device, name, val);
650         return 0;
651 }
652
653 int device_set_action(struct udev_device *udev_device, const char *action)
654 {
655         udev_device->action = strdup(action);
656         if (udev_device->action == NULL)
657                 return -ENOMEM;
658         return 0;
659 }
660
661 int device_set_driver(struct udev_device *udev_device, const char *driver)
662 {
663         udev_device->driver = strdup(driver);
664         if (udev_device->driver == NULL)
665                 return -ENOMEM;
666         return 0;
667 }
668
669 const char *device_get_devpath_old(struct udev_device *udev_device)
670 {
671         if (udev_device == NULL)
672                 return NULL;
673         return udev_device->devpath_old;
674 }
675
676 int device_set_devpath_old(struct udev_device *udev_device, const char *devpath_old)
677 {
678         udev_device->devpath_old = strdup(devpath_old);
679         if (udev_device->devpath_old == NULL)
680                 return -ENOMEM;
681         return 0;
682 }
683
684 const char *device_get_physdevpath(struct udev_device *udev_device)
685 {
686         if (udev_device == NULL)
687                 return NULL;
688         return udev_device->physdevpath;
689 }
690
691 int device_set_physdevpath(struct udev_device *udev_device, const char *physdevpath)
692 {
693         udev_device->physdevpath = strdup(physdevpath);
694         if (udev_device->physdevpath == NULL)
695                 return -ENOMEM;
696         return 0;
697 }
698
699 int device_get_timeout(struct udev_device *udev_device)
700 {
701         if (udev_device == NULL)
702                 return -1;
703         return udev_device->timeout;
704 }
705
706 int device_set_timeout(struct udev_device *udev_device, int timeout)
707 {
708         udev_device->timeout = timeout;
709         return 0;
710 }
711
712 int device_set_seqnum(struct udev_device *udev_device, unsigned long long int seqnum)
713 {
714         udev_device->seqnum = seqnum;
715         return 0;
716 }
717
718 int device_set_devnum(struct udev_device *udev_device, dev_t devnum)
719 {
720         udev_device->devnum = devnum;
721         return 0;
722 }
723
724 int device_get_num_fake_partitions(struct udev_device *udev_device)
725 {
726         if (udev_device == NULL)
727                 return -1;
728         return udev_device->num_fake_partitions;
729 }
730
731 int device_set_num_fake_partitions(struct udev_device *udev_device, int num)
732 {
733         udev_device->num_fake_partitions = num;
734         return 0;
735 }
736
737 int device_get_devlink_priority(struct udev_device *udev_device)
738 {
739         if (udev_device == NULL)
740                 return -1;
741         return udev_device->devlink_priority;
742 }
743
744 int device_set_devlink_priority(struct udev_device *udev_device, int prio)
745 {
746          udev_device->devlink_priority = prio;
747         return 0;
748 }
749
750 int device_get_ignore_remove(struct udev_device *udev_device)
751 {
752         if (udev_device == NULL)
753                 return -1;
754         return udev_device->ignore_remove;
755 }
756
757 int device_set_ignore_remove(struct udev_device *udev_device, int ignore)
758 {
759         udev_device->ignore_remove = ignore;
760         return 0;
761 }
762