chiark / gitweb /
1dd55f6a23e23e7b5914b511b02d246925561e17
[elogind.git] / udev / udev.h
1 /*
2  * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
3  * Copyright (C) 2003-2006 Kay Sievers <kay.sievers@vrfy.org>
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.,
16  *      51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  *
18  */
19
20 #ifndef _UDEV_H_
21 #define _UDEV_H_
22
23 #include "config.h"
24
25 #include <sys/types.h>
26 #include <sys/param.h>
27
28 #include "list.h"
29 #include "udev_sysdeps.h"
30 #define LIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE 1
31 #include "lib/libudev.h"
32 #include "lib/libudev-private.h"
33
34 #define COMMENT_CHARACTER                       '#'
35 #define LINE_SIZE                               512
36 #define PATH_SIZE                               512
37 #define NAME_SIZE                               256
38 #define VALUE_SIZE                              128
39
40 #define ALLOWED_CHARS                           "#+-.:=@_"
41 #define ALLOWED_CHARS_FILE                      ALLOWED_CHARS "/"
42 #define ALLOWED_CHARS_INPUT                     ALLOWED_CHARS_FILE " $%?,"
43
44 #define DEFAULT_PARTITIONS_COUNT                15
45 #define UDEV_EVENT_TIMEOUT                      180
46
47 #define UDEV_MAX(a,b) ((a) > (b) ? (a) : (b))
48
49 /* pipes */
50 #define READ_END                                0
51 #define WRITE_END                               1
52
53 struct udev_rules;
54
55 struct sysfs_device {
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, module */
60         char kernel[NAME_SIZE];                 /* device instance name */
61         char kernel_number[NAME_SIZE];
62         char driver[NAME_SIZE];                 /* device driver name */
63 };
64
65 struct udevice {
66         struct udev *udev;
67
68         /* device event */
69         struct sysfs_device *dev;               /* points to dev_local by default */
70         struct sysfs_device dev_local;
71         struct sysfs_device *dev_parent;        /* current parent device used for matching */
72         char action[NAME_SIZE];
73         char *devpath_old;
74
75         /* node */
76         char name[PATH_SIZE];
77         struct list_head symlink_list;
78         int symlink_final;
79         char owner[NAME_SIZE];
80         int owner_final;
81         char group[NAME_SIZE];
82         int group_final;
83         mode_t mode;
84         int mode_final;
85         dev_t devt;
86
87         /* event processing */
88         struct list_head run_list;
89         int run_final;
90         struct list_head env_list;
91         char tmp_node[PATH_SIZE];
92         int partitions;
93         int ignore_device;
94         int ignore_remove;
95         char program_result[PATH_SIZE];
96         int link_priority;
97         int event_timeout;
98         int test_run;
99 };
100
101 static inline void logging_init(const char *program_name)
102 {
103         openlog(program_name, LOG_PID | LOG_CONS, LOG_DAEMON);
104 }
105
106 static inline void logging_msg(struct udev *udev, int priority,
107                           const char *file, int line, const char *fn,
108                           const char *format, va_list args)
109 {
110         vsyslog(priority, format, args);
111 }
112
113 static inline void logging_close(void)
114 {
115         closelog();
116 }
117
118 /* udev_device.c */
119 extern struct udevice *udev_device_init(struct udev *udev);
120 extern void udev_device_cleanup(struct udevice *udevice);
121 extern dev_t udev_device_get_devt(struct udevice *udevice);
122
123 /* udev_device_event.c */
124 extern int udev_device_event(struct udev_rules *rules, struct udevice *udevice);
125
126 /* udev_sysfs.c */
127 extern int sysfs_init(void);
128 extern void sysfs_cleanup(void);
129 extern void sysfs_device_set_values(struct udev *udev,
130                                     struct sysfs_device *dev, const char *devpath,
131                                     const char *subsystem, const char *driver);
132 extern struct sysfs_device *sysfs_device_get(struct udev *udev, const char *devpath);
133 extern struct sysfs_device *sysfs_device_get_parent(struct udev *udev, struct sysfs_device *dev);
134 extern struct sysfs_device *sysfs_device_get_parent_with_subsystem(struct udev *udev, struct sysfs_device *dev, const char *subsystem);
135 extern char *sysfs_attr_get_value(struct udev *udev, const char *devpath, const char *attr_name);
136 extern int sysfs_resolve_link(struct udev *udev, char *path, size_t size);
137 extern int sysfs_lookup_devpath_by_subsys_id(struct udev *udev, char *devpath, size_t len, const char *subsystem, const char *id);
138
139 /* udev_node.c */
140 extern int udev_node_mknod(struct udevice *udevice, const char *file, dev_t devt, mode_t mode, uid_t uid, gid_t gid);
141 extern void udev_node_update_symlinks(struct udevice *udevice, struct udevice *udev_old);
142 extern int udev_node_add(struct udevice *udevice);
143 extern int udev_node_remove(struct udevice *udevice);
144
145 /* udev_db.c */
146 extern int udev_db_add_device(struct udevice *udevice);
147 extern int udev_db_delete_device(struct udevice *udevice);
148 extern int udev_db_rename(struct udev *udev, const char *devpath_old, const char *devpath);
149 extern int udev_db_get_device(struct udevice *udevice, const char *devpath);
150 extern int udev_db_get_devices_by_name(struct udev *udev, const char *name, struct list_head *name_list);
151 extern int udev_db_get_all_entries(struct udev *udevconst, struct list_head *name_list);
152
153 /* udev_utils.c */
154 struct name_entry {
155         struct list_head node;
156         char name[PATH_SIZE];
157         unsigned int ignore_error:1;
158 };
159
160 extern int log_priority(const char *priority);
161 extern struct name_entry *name_list_add(struct udev *udev, struct list_head *name_list, const char *name, int sort);
162 extern struct name_entry *name_list_key_add(struct udev *udev, struct list_head *name_list, const char *key, const char *value);
163 extern int name_list_key_remove(struct udev *udev, struct list_head *name_list, const char *key);
164 extern void name_list_cleanup(struct udev *udev, struct list_head *name_list);
165 extern int add_matching_files(struct udev *udev, struct list_head *name_list, const char *dirname, const char *suffix);
166 extern uid_t lookup_user(struct udev *udev, const char *user);
167 extern gid_t lookup_group(struct udev *udev, const char *group);
168
169 /* udev_utils_string.c */
170 extern int string_is_true(const char *str);
171 extern void remove_trailing_chars(char *path, char c);
172 extern size_t path_encode(char *s, size_t len);
173 extern size_t path_decode(char *s);
174 extern int utf8_encoded_valid_unichar(const char *str);
175 extern int replace_chars(char *str, const char *white);
176
177 /* udev_utils_file.c */
178 extern int create_path(struct udev *udev, const char *path);
179 extern int delete_path(struct udev *udev, const char *path);
180 extern int unlink_secure(struct udev *udev, const char *filename);
181 extern int file_map(const char *filename, char **buf, size_t *bufsize);
182 extern void file_unmap(void *buf, size_t bufsize);
183 extern size_t buf_get_line(const char *buf, size_t buflen, size_t cur);
184
185 /* udevadm commands */
186 extern int udevadm_monitor(struct udev *udev, int argc, char *argv[]);
187 extern int udevadm_info(struct udev *udev, int argc, char *argv[]);
188 extern int udevadm_control(struct udev *udev, int argc, char *argv[]);
189 extern int udevadm_trigger(struct udev *udev, int argc, char *argv[]);
190 extern int udevadm_settle(struct udev *udev, int argc, char *argv[]);
191 extern int udevadm_test(struct udev *udev, int argc, char *argv[]);
192
193 /* udev_ctrl - daemon runtime setup */
194 struct udev_ctrl;
195 extern struct udev_ctrl *udev_ctrl_new_from_socket(struct udev *udev, const char *socket_path);
196 extern void udev_ctrl_unref(struct udev_ctrl *uctrl);
197 extern int udev_ctrl_set_log_level(struct udev_ctrl *uctrl, int priority);
198 extern int udev_ctrl_stop_exec_queue(struct udev_ctrl *uctrl);
199 extern int udev_ctrl_start_exec_queue(struct udev_ctrl *uctrl);
200 extern int udev_ctrl_reload_rules(struct udev_ctrl *uctrl);
201 extern int udev_ctrl_set_env(struct udev_ctrl *uctrl, const char *key);
202 extern int udev_ctrl_set_max_childs(struct udev_ctrl *uctrl, int count);
203 extern int udev_ctrl_set_max_childs_running(struct udev_ctrl *uctrl, int count);
204
205 #endif