]>
Commit | Line | Data |
---|---|---|
f0083e3d | 1 | /* |
f0083e3d | 2 | * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com> |
4f4b12c2 | 3 | * Copyright (C) 2003-2008 Kay Sievers <kay.sievers@vrfy.org> |
f0083e3d GKH |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU General Public License as published by the | |
7 | * Free Software Foundation version 2 of the License. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, but | |
10 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | * General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License along | |
15 | * with this program; if not, write to the Free Software Foundation, Inc., | |
27b77df4 | 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
f0083e3d GKH |
17 | * |
18 | */ | |
19 | ||
c81b35c0 KS |
20 | #ifndef _UDEV_H_ |
21 | #define _UDEV_H_ | |
f0083e3d | 22 | |
7d563a17 KS |
23 | #include "config.h" |
24 | ||
c1ab0461 | 25 | #include <sys/types.h> |
c076a2bd | 26 | #include <sys/param.h> |
1aa1e248 | 27 | |
9ed47a9f | 28 | #include "list.h" |
dbd16d26 | 29 | #include "udev_sysdeps.h" |
7d563a17 KS |
30 | #define LIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE 1 |
31 | #include "lib/libudev.h" | |
32 | #include "lib/libudev-private.h" | |
f0083e3d | 33 | |
03b24b71 | 34 | #define COMMENT_CHARACTER '#' |
03b24b71 | 35 | #define LINE_SIZE 512 |
989e0811 | 36 | #define PATH_SIZE 512 |
05610c08 | 37 | #define NAME_SIZE 256 |
03b24b71 | 38 | #define VALUE_SIZE 128 |
e964c2c0 | 39 | |
c1987051 | 40 | #define ALLOWED_CHARS "#+-.:=@_" |
2f2c4fa4 | 41 | #define ALLOWED_CHARS_FILE ALLOWED_CHARS "/" |
c1987051 | 42 | #define ALLOWED_CHARS_INPUT ALLOWED_CHARS_FILE " $%?," |
2f2c4fa4 | 43 | |
03b24b71 | 44 | #define DEFAULT_PARTITIONS_COUNT 15 |
bf50425b | 45 | #define UDEV_EVENT_TIMEOUT 180 |
6d564166 | 46 | |
d59f11e1 KS |
47 | /* linux/include/linux/kobject.h */ |
48 | #define UEVENT_BUFFER_SIZE 2048 | |
49 | #define UEVENT_NUM_ENVP 32 | |
50 | ||
51 | #define UDEV_CTRL_SOCK_PATH "@" UDEV_PREFIX "/org/kernel/udev/udevd" | |
52 | ||
1aa1e248 KS |
53 | #define UDEV_MAX(a,b) ((a) > (b) ? (a) : (b)) |
54 | ||
55 | /* pipes */ | |
03b24b71 KS |
56 | #define READ_END 0 |
57 | #define WRITE_END 1 | |
1aa1e248 | 58 | |
e8d569b4 KS |
59 | struct udev_rules; |
60 | ||
1aa1e248 | 61 | struct sysfs_device { |
03b24b71 | 62 | struct list_head node; /* for device cache */ |
34f55103 | 63 | struct sysfs_device *parent; /* already cached parent*/ |
1aa1e248 | 64 | char devpath[PATH_SIZE]; |
95776dc6 KS |
65 | char subsystem[NAME_SIZE]; /* $class, $bus, drivers, module */ |
66 | char kernel[NAME_SIZE]; /* device instance name */ | |
1aa1e248 | 67 | char kernel_number[NAME_SIZE]; |
03b24b71 | 68 | char driver[NAME_SIZE]; /* device driver name */ |
5ef42682 KS |
69 | }; |
70 | ||
5840bc63 | 71 | struct udevice { |
7d563a17 KS |
72 | struct udev *udev; |
73 | ||
1aa1e248 | 74 | /* device event */ |
03b24b71 | 75 | struct sysfs_device *dev; /* points to dev_local by default */ |
1aa1e248 | 76 | struct sysfs_device dev_local; |
03b24b71 | 77 | struct sysfs_device *dev_parent; /* current parent device used for matching */ |
821d0ec8 | 78 | char action[NAME_SIZE]; |
a2f2270e | 79 | char *devpath_old; |
2af003fe | 80 | |
1aa1e248 | 81 | /* node */ |
63f61c5c | 82 | char name[PATH_SIZE]; |
e48fc108 | 83 | struct list_head symlink_list; |
c974742b | 84 | int symlink_final; |
989e0811 | 85 | char owner[NAME_SIZE]; |
c974742b | 86 | int owner_final; |
989e0811 | 87 | char group[NAME_SIZE]; |
c974742b | 88 | int group_final; |
2af003fe | 89 | mode_t mode; |
c974742b | 90 | int mode_final; |
7e720bd4 | 91 | dev_t devt; |
1aa1e248 KS |
92 | |
93 | /* event processing */ | |
821d0ec8 | 94 | struct list_head run_list; |
c974742b | 95 | int run_final; |
b8476286 | 96 | struct list_head env_list; |
63f61c5c | 97 | char tmp_node[PATH_SIZE]; |
50e5de03 | 98 | int partitions; |
821d0ec8 | 99 | int ignore_device; |
7efa217d | 100 | int ignore_remove; |
63f61c5c | 101 | char program_result[PATH_SIZE]; |
2dbb47f8 | 102 | int link_priority; |
bf50425b | 103 | int event_timeout; |
7a947ce5 | 104 | int test_run; |
5840bc63 GKH |
105 | }; |
106 | ||
7d563a17 KS |
107 | static inline void logging_init(const char *program_name) |
108 | { | |
109 | openlog(program_name, LOG_PID | LOG_CONS, LOG_DAEMON); | |
110 | } | |
111 | ||
112 | static inline void logging_msg(struct udev *udev, int priority, | |
113 | const char *file, int line, const char *fn, | |
114 | const char *format, va_list args) | |
115 | { | |
116 | vsyslog(priority, format, args); | |
117 | } | |
118 | ||
119 | static inline void logging_close(void) | |
120 | { | |
121 | closelog(); | |
122 | } | |
1aa1e248 KS |
123 | |
124 | /* udev_device.c */ | |
7d563a17 KS |
125 | extern struct udevice *udev_device_init(struct udev *udev); |
126 | extern void udev_device_cleanup(struct udevice *udevice); | |
127 | extern dev_t udev_device_get_devt(struct udevice *udevice); | |
1aa1e248 | 128 | |
d46f37fd | 129 | /* udev_device_event.c */ |
7d563a17 | 130 | extern int udev_device_event(struct udev_rules *rules, struct udevice *udevice); |
d46f37fd | 131 | |
1aa1e248 | 132 | /* udev_sysfs.c */ |
1aa1e248 KS |
133 | extern int sysfs_init(void); |
134 | extern void sysfs_cleanup(void); | |
7d563a17 KS |
135 | extern void sysfs_device_set_values(struct udev *udev, |
136 | struct sysfs_device *dev, const char *devpath, | |
254efc14 | 137 | const char *subsystem, const char *driver); |
7d563a17 KS |
138 | extern struct sysfs_device *sysfs_device_get(struct udev *udev, const char *devpath); |
139 | extern struct sysfs_device *sysfs_device_get_parent(struct udev *udev, struct sysfs_device *dev); | |
140 | extern struct sysfs_device *sysfs_device_get_parent_with_subsystem(struct udev *udev, struct sysfs_device *dev, const char *subsystem); | |
141 | extern char *sysfs_attr_get_value(struct udev *udev, const char *devpath, const char *attr_name); | |
142 | extern int sysfs_resolve_link(struct udev *udev, char *path, size_t size); | |
143 | extern int sysfs_lookup_devpath_by_subsys_id(struct udev *udev, char *devpath, size_t len, const char *subsystem, const char *id); | |
1aa1e248 | 144 | |
a4d5ca64 | 145 | /* udev_node.c */ |
7d563a17 KS |
146 | extern int udev_node_mknod(struct udevice *udevice, const char *file, dev_t devt, mode_t mode, uid_t uid, gid_t gid); |
147 | extern void udev_node_update_symlinks(struct udevice *udevice, struct udevice *udev_old); | |
148 | extern int udev_node_add(struct udevice *udevice); | |
149 | extern int udev_node_remove(struct udevice *udevice); | |
a507a015 | 150 | |
1aa1e248 | 151 | /* udev_db.c */ |
7d563a17 KS |
152 | extern int udev_db_add_device(struct udevice *udevice); |
153 | extern int udev_db_delete_device(struct udevice *udevice); | |
154 | extern int udev_db_rename(struct udev *udev, const char *devpath_old, const char *devpath); | |
155 | extern int udev_db_get_device(struct udevice *udevice, const char *devpath); | |
156 | extern int udev_db_get_devices_by_name(struct udev *udev, const char *name, struct list_head *name_list); | |
157 | extern int udev_db_get_all_entries(struct udev *udevconst, struct list_head *name_list); | |
fc55cf68 | 158 | |
1aa1e248 KS |
159 | /* udev_utils.c */ |
160 | struct name_entry { | |
161 | struct list_head node; | |
162 | char name[PATH_SIZE]; | |
4110664d | 163 | unsigned int ignore_error:1; |
1aa1e248 | 164 | }; |
4110664d | 165 | |
1aa1e248 | 166 | extern int log_priority(const char *priority); |
7d563a17 KS |
167 | extern struct name_entry *name_list_add(struct udev *udev, struct list_head *name_list, const char *name, int sort); |
168 | extern struct name_entry *name_list_key_add(struct udev *udev, struct list_head *name_list, const char *key, const char *value); | |
169 | extern int name_list_key_remove(struct udev *udev, struct list_head *name_list, const char *key); | |
170 | extern void name_list_cleanup(struct udev *udev, struct list_head *name_list); | |
171 | extern int add_matching_files(struct udev *udev, struct list_head *name_list, const char *dirname, const char *suffix); | |
172 | extern uid_t lookup_user(struct udev *udev, const char *user); | |
173 | extern gid_t lookup_group(struct udev *udev, const char *group); | |
1aa1e248 KS |
174 | |
175 | /* udev_utils_string.c */ | |
1aa1e248 KS |
176 | extern int string_is_true(const char *str); |
177 | extern void remove_trailing_chars(char *path, char c); | |
9c6ad9fb KS |
178 | extern size_t path_encode(char *s, size_t len); |
179 | extern size_t path_decode(char *s); | |
1aa1e248 | 180 | extern int utf8_encoded_valid_unichar(const char *str); |
2f2c4fa4 | 181 | extern int replace_chars(char *str, const char *white); |
1aa1e248 KS |
182 | |
183 | /* udev_utils_file.c */ | |
7d563a17 KS |
184 | extern int create_path(struct udev *udev, const char *path); |
185 | extern int delete_path(struct udev *udev, const char *path); | |
186 | extern int unlink_secure(struct udev *udev, const char *filename); | |
1aa1e248 KS |
187 | extern int file_map(const char *filename, char **buf, size_t *bufsize); |
188 | extern void file_unmap(void *buf, size_t bufsize); | |
1aa1e248 KS |
189 | extern size_t buf_get_line(const char *buf, size_t buflen, size_t cur); |
190 | ||
32bf8399 | 191 | /* udevadm commands */ |
7d563a17 KS |
192 | extern int udevadm_monitor(struct udev *udev, int argc, char *argv[]); |
193 | extern int udevadm_info(struct udev *udev, int argc, char *argv[]); | |
194 | extern int udevadm_control(struct udev *udev, int argc, char *argv[]); | |
195 | extern int udevadm_trigger(struct udev *udev, int argc, char *argv[]); | |
196 | extern int udevadm_settle(struct udev *udev, int argc, char *argv[]); | |
197 | extern int udevadm_test(struct udev *udev, int argc, char *argv[]); | |
225cb03b | 198 | |
f0083e3d | 199 | #endif |