4 * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
5 * Copyright (C) 2003-2005 Kay Sievers <kay.sievers@vrfy.org>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation version 2 of the License.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <sys/types.h>
26 #include <sys/param.h>
30 #include "udev_libc_wrapper.h"
31 #include "udev_version.h"
33 #define COMMENT_CHARACTER '#'
34 #define PATH_TO_NAME_CHAR '@'
39 #define SEQNUM_SIZE 32
40 #define VALUE_SIZE 128
42 #define DEFAULT_PARTITIONS_COUNT 15
43 #define UDEV_ALARM_TIMEOUT 180
45 #define UDEV_MAX(a,b) ((a) > (b) ? (a) : (b))
51 #define DB_DIR ".udev/db"
56 struct list_head node; /* for device cache */
57 struct sysfs_device *parent; /* already cached parent*/
58 char devpath[PATH_SIZE];
59 char subsystem[NAME_SIZE]; /* $class/$bus/"drivers" */
60 char kernel_name[NAME_SIZE]; /* device instance name */
61 char kernel_number[NAME_SIZE];
62 char driver[NAME_SIZE]; /* device driver name */
67 struct sysfs_device *dev; /* points to dev_local by default */
68 struct sysfs_device dev_local;
69 struct sysfs_device *dev_parent; /* current parent device used for matching */
70 char action[NAME_SIZE];
74 struct list_head symlink_list;
76 char owner[USER_SIZE];
78 char group[USER_SIZE];
84 /* event processing */
85 struct list_head run_list;
87 struct list_head env_list;
88 char tmp_node[PATH_SIZE];
92 char program_result[PATH_SIZE];
97 extern char udev_root[PATH_SIZE];
98 extern char udev_config_filename[PATH_SIZE];
99 extern char udev_rules_filename[PATH_SIZE];
100 extern int udev_log_priority;
102 extern void udev_config_init(void);
105 extern struct udevice *udev_device_init(void);
106 extern void udev_device_cleanup(struct udevice *udev);
107 extern int udev_device_event(struct udev_rules *rules, struct udevice *udev);
108 extern dev_t udev_device_get_devt(struct udevice *udev);
111 extern char sysfs_path[PATH_SIZE];
112 extern int sysfs_init(void);
113 extern void sysfs_cleanup(void);
114 extern void sysfs_device_set_values(struct sysfs_device *dev, const char *devpath, const char *subsystem);
115 extern struct sysfs_device *sysfs_device_get(const char *devpath);
116 extern struct sysfs_device *sysfs_device_get_parent(struct sysfs_device *dev);
117 extern struct sysfs_device *sysfs_device_get_parent_with_subsystem(struct sysfs_device *dev, const char *subsystem);
118 extern char *sysfs_attr_get_value(const char *devpath, const char *attr_name);
121 extern int udev_make_node(struct udevice *udev, const char *file, dev_t devt, mode_t mode, uid_t uid, gid_t gid);
122 extern int udev_add_device(struct udevice *udev);
125 extern int udev_remove_device(struct udevice *udev);
128 extern int udev_db_add_device(struct udevice *dev);
129 extern int udev_db_delete_device(struct udevice *dev);
130 extern int udev_db_get_device(struct udevice *udev, const char *devpath);
131 extern int udev_db_lookup_name(const char *name, char *devpath, size_t len);
132 extern int udev_db_get_all_entries(struct list_head *name_list);
136 struct list_head node;
137 char name[PATH_SIZE];
139 extern int log_priority(const char *priority);
140 extern int name_list_add(struct list_head *name_list, const char *name, int sort);
141 extern int name_list_key_add(struct list_head *name_list, const char *key, const char *value);
142 extern void name_list_cleanup(struct list_head *name_list);
143 extern int add_matching_files(struct list_head *name_list, const char *dirname, const char *suffix);
145 /* udev_utils_string.c */
146 extern int strcmp_pattern(const char *p, const char *s);
147 extern int string_is_true(const char *str);
148 extern void remove_trailing_chars(char *path, char c);
149 extern int utf8_encoded_valid_unichar(const char *str);
150 extern int replace_untrusted_chars(char *str);
152 /* udev_utils_file.c */
153 extern int create_path(const char *path);
154 extern int delete_path(const char *path);
155 extern int file_map(const char *filename, char **buf, size_t *bufsize);
156 extern void file_unmap(void *buf, size_t bufsize);
157 extern int unlink_secure(const char *filename);
158 extern size_t buf_get_line(const char *buf, size_t buflen, size_t cur);
160 /* udev_utils_run.c */
161 extern int pass_env_to_socket(const char *name, const char *devpath, const char *action);
162 extern int run_program(const char *command, const char *subsystem,
163 char *result, size_t ressize, size_t *reslen, int log);