2 * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
3 * Copyright (C) 2003-2008 Kay Sievers <kay.sievers@vrfy.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include <sys/types.h>
23 #include <sys/param.h>
25 #include "udev_sysdeps.h"
26 #define LIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE 1
27 #include "lib/libudev.h"
28 #include "lib/libudev-private.h"
31 #define ALLOWED_CHARS "#+-.:=@_"
32 #define ALLOWED_CHARS_FILE ALLOWED_CHARS "/"
33 #define ALLOWED_CHARS_INPUT ALLOWED_CHARS_FILE " $%?,"
35 #define DEFAULT_PARTITIONS_COUNT 15
36 #define UDEV_EVENT_TIMEOUT 180
38 /* linux/include/linux/kobject.h */
39 #define UEVENT_BUFFER_SIZE 2048
40 #define UEVENT_NUM_ENVP 32
42 #define UDEV_CTRL_SOCK_PATH "@" UDEV_PREFIX "/org/kernel/udev/udevd"
44 #define UDEV_MAX(a,b) ((a) > (b) ? (a) : (b))
53 struct list_head node; /* for device cache */
54 struct sysfs_device *parent; /* already cached parent*/
55 char devpath[UTIL_PATH_SIZE];
56 char subsystem[UTIL_NAME_SIZE];
57 char kernel[UTIL_NAME_SIZE]; /* device instance name */
58 char kernel_number[UTIL_NAME_SIZE];
59 char driver[UTIL_NAME_SIZE];
66 struct sysfs_device *dev; /* points to dev_local by default */
67 struct sysfs_device dev_local;
68 struct sysfs_device *dev_parent; /* current parent device used for matching */
69 char action[UTIL_NAME_SIZE];
73 char name[UTIL_PATH_SIZE];
74 struct list_head symlink_list;
76 char owner[UTIL_NAME_SIZE];
78 char group[UTIL_NAME_SIZE];
84 /* event processing */
85 struct list_head run_list;
87 struct list_head env_list;
88 char tmp_node[UTIL_PATH_SIZE];
92 char program_result[UTIL_PATH_SIZE];
98 static inline void logging_init(const char *program_name)
100 openlog(program_name, LOG_PID | LOG_CONS, LOG_DAEMON);
103 static inline void logging_msg(struct udev *udev, int priority,
104 const char *file, int line, const char *fn,
105 const char *format, va_list args)
107 vsyslog(priority, format, args);
110 static inline void logging_close(void)
116 extern struct udevice *udev_device_init(struct udev *udev);
117 extern void udev_device_cleanup(struct udevice *udevice);
118 extern dev_t udev_device_get_devt(struct udevice *udevice);
120 /* udev_device_event.c */
121 extern int udev_device_event(struct udev_rules *rules, struct udevice *udevice);
124 extern int sysfs_init(void);
125 extern void sysfs_cleanup(void);
126 extern void sysfs_device_set_values(struct udev *udev,
127 struct sysfs_device *dev, const char *devpath,
128 const char *subsystem, const char *driver);
129 extern struct sysfs_device *sysfs_device_get(struct udev *udev, const char *devpath);
130 extern struct sysfs_device *sysfs_device_get_parent(struct udev *udev, struct sysfs_device *dev);
131 extern struct sysfs_device *sysfs_device_get_parent_with_subsystem(struct udev *udev, struct sysfs_device *dev, const char *subsystem);
132 extern char *sysfs_attr_get_value(struct udev *udev, const char *devpath, const char *attr_name);
133 extern int sysfs_lookup_devpath_by_subsys_id(struct udev *udev, char *devpath, size_t len, const char *subsystem, const char *id);
136 extern int udev_node_mknod(struct udevice *udevice, const char *file, dev_t devt, mode_t mode, uid_t uid, gid_t gid);
137 extern void udev_node_update_symlinks(struct udevice *udevice, struct udevice *udev_old);
138 extern int udev_node_add(struct udevice *udevice);
139 extern int udev_node_remove(struct udevice *udevice);
142 extern int udev_db_add_device(struct udevice *udevice);
143 extern int udev_db_delete_device(struct udevice *udevice);
144 extern int udev_db_rename(struct udev *udev, const char *devpath_old, const char *devpath);
145 extern int udev_db_get_device(struct udevice *udevice, const char *devpath);
146 extern int udev_db_get_devices_by_name(struct udev *udev, const char *name, struct list_head *name_list);
150 struct list_head node;
151 char name[UTIL_PATH_SIZE];
152 unsigned int ignore_error:1;
154 extern struct name_entry *name_list_add(struct udev *udev, struct list_head *name_list, const char *name, int sort);
155 extern struct name_entry *name_list_key_add(struct udev *udev, struct list_head *name_list, const char *key, const char *value);
156 extern int name_list_key_remove(struct udev *udev, struct list_head *name_list, const char *key);
157 extern void name_list_cleanup(struct udev *udev, struct list_head *name_list);
158 extern int add_matching_files(struct udev *udev, struct list_head *name_list, const char *dirname, const char *suffix);
159 extern uid_t lookup_user(struct udev *udev, const char *user);
160 extern gid_t lookup_group(struct udev *udev, const char *group);
162 /* udev_utils_file.c */
163 extern int create_path(struct udev *udev, const char *path);
164 extern int delete_path(struct udev *udev, const char *path);
165 extern int unlink_secure(struct udev *udev, const char *filename);
166 extern int file_map(const char *filename, char **buf, size_t *bufsize);
167 extern void file_unmap(void *buf, size_t bufsize);
168 extern size_t buf_get_line(const char *buf, size_t buflen, size_t cur);
170 /* udevadm commands */
171 extern int udevadm_monitor(struct udev *udev, int argc, char *argv[]);
172 extern int udevadm_info(struct udev *udev, int argc, char *argv[]);
173 extern int udevadm_control(struct udev *udev, int argc, char *argv[]);
174 extern int udevadm_trigger(struct udev *udev, int argc, char *argv[]);
175 extern int udevadm_settle(struct udev *udev, int argc, char *argv[]);
176 extern int udevadm_test(struct udev *udev, int argc, char *argv[]);