chiark / gitweb /
release 125
[elogind.git] / 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 <sys/types.h>
24 #include <sys/param.h>
25
26 #include "list.h"
27 #include "logging.h"
28 #include "udev_sysdeps.h"
29 #include "udev_version.h"
30
31 #define COMMENT_CHARACTER                       '#'
32 #define LINE_SIZE                               512
33 #define PATH_SIZE                               512
34 #define NAME_SIZE                               256
35 #define VALUE_SIZE                              128
36
37 #define ALLOWED_CHARS                           "#+-.:=@_"
38 #define ALLOWED_CHARS_FILE                      ALLOWED_CHARS "/"
39 #define ALLOWED_CHARS_INPUT                     ALLOWED_CHARS_FILE " $%?,"
40
41 #define DEFAULT_PARTITIONS_COUNT                15
42 #define UDEV_EVENT_TIMEOUT                      180
43
44 #define UDEV_MAX(a,b) ((a) > (b) ? (a) : (b))
45
46 /* pipes */
47 #define READ_END                                0
48 #define WRITE_END                               1
49
50 #define UDEV_ROOT                               "/dev"
51 #define DB_DIR                                  ".udev/db"
52 #define DB_NAME_INDEX_DIR                       ".udev/names"
53 #define RULES_LIB_DIR                           "/lib/udev/rules.d"
54 #define RULES_DYN_DIR                           ".udev/rules.d"
55 #define RULES_ETC_DIR                           "/etc/udev/rules.d"
56
57 struct udev_rules;
58
59 struct sysfs_device {
60         struct list_head node;                  /* for device cache */
61         struct sysfs_device *parent;            /* already cached parent*/
62         char devpath[PATH_SIZE];
63         char subsystem[NAME_SIZE];              /* $class, $bus, drivers, module */
64         char kernel[NAME_SIZE];                 /* device instance name */
65         char kernel_number[NAME_SIZE];
66         char driver[NAME_SIZE];                 /* device driver name */
67 };
68
69 struct udevice {
70         /* device event */
71         struct sysfs_device *dev;               /* points to dev_local by default */
72         struct sysfs_device dev_local;
73         struct sysfs_device *dev_parent;        /* current parent device used for matching */
74         char action[NAME_SIZE];
75         char *devpath_old;
76
77         /* node */
78         char name[PATH_SIZE];
79         struct list_head symlink_list;
80         int symlink_final;
81         char owner[NAME_SIZE];
82         int owner_final;
83         char group[NAME_SIZE];
84         int group_final;
85         mode_t mode;
86         int mode_final;
87         dev_t devt;
88
89         /* event processing */
90         struct list_head run_list;
91         int run_final;
92         struct list_head env_list;
93         char tmp_node[PATH_SIZE];
94         int partitions;
95         int ignore_device;
96         int ignore_remove;
97         char program_result[PATH_SIZE];
98         int link_priority;
99         int event_timeout;
100         int test_run;
101 };
102
103 /* udev_config.c */
104 extern char udev_root[PATH_SIZE];
105 extern char udev_config_filename[PATH_SIZE];
106 extern char udev_rules_dir[PATH_SIZE];
107 extern int udev_log_priority;
108 extern int udev_run;
109 extern void udev_config_init(void);
110
111 /* udev_device.c */
112 extern struct udevice *udev_device_init(struct udevice *udev);
113 extern void udev_device_cleanup(struct udevice *udev);
114 extern int udev_device_event(struct udev_rules *rules, struct udevice *udev);
115 extern dev_t udev_device_get_devt(struct udevice *udev);
116
117 /* udev_sysfs.c */
118 extern char sysfs_path[PATH_SIZE];
119 extern int sysfs_init(void);
120 extern void sysfs_cleanup(void);
121 extern void sysfs_device_set_values(struct sysfs_device *dev, const char *devpath,
122                                     const char *subsystem, const char *driver);
123 extern struct sysfs_device *sysfs_device_get(const char *devpath);
124 extern struct sysfs_device *sysfs_device_get_parent(struct sysfs_device *dev);
125 extern struct sysfs_device *sysfs_device_get_parent_with_subsystem(struct sysfs_device *dev, const char *subsystem);
126 extern char *sysfs_attr_get_value(const char *devpath, const char *attr_name);
127 extern int sysfs_resolve_link(char *path, size_t size);
128 extern int sysfs_lookup_devpath_by_subsys_id(char *devpath, size_t len, const char *subsystem, const char *id);
129
130 /* udev_node.c */
131 extern int udev_node_mknod(struct udevice *udev, const char *file, dev_t devt, mode_t mode, uid_t uid, gid_t gid);
132 extern void udev_node_update_symlinks(struct udevice *udev, struct udevice *udev_old);
133 extern int udev_node_add(struct udevice *udev);
134 extern int udev_node_remove(struct udevice *udev);
135
136 /* udev_db.c */
137 extern int udev_db_add_device(struct udevice *dev);
138 extern int udev_db_delete_device(struct udevice *dev);
139 extern int udev_db_rename(const char *devpath_old, const char *devpath);
140 extern int udev_db_get_device(struct udevice *udev, const char *devpath);
141 extern int udev_db_get_devices_by_name(const char *name, struct list_head *name_list);
142 extern int udev_db_get_all_entries(struct list_head *name_list);
143
144 /* udev_utils.c */
145 struct name_entry {
146         struct list_head node;
147         char name[PATH_SIZE];
148         unsigned int ignore_error:1;
149 };
150
151 extern int log_priority(const char *priority);
152 extern struct name_entry *name_list_add(struct list_head *name_list, const char *name, int sort);
153 extern struct name_entry *name_list_key_add(struct list_head *name_list, const char *key, const char *value);
154 extern int name_list_key_remove(struct list_head *name_list, const char *key);
155 extern void name_list_cleanup(struct list_head *name_list);
156 extern int add_matching_files(struct list_head *name_list, const char *dirname, const char *suffix);
157 extern uid_t lookup_user(const char *user);
158 extern gid_t lookup_group(const char *group);
159
160 /* udev_utils_string.c */
161 extern int string_is_true(const char *str);
162 extern void remove_trailing_chars(char *path, char c);
163 extern size_t path_encode(char *s, size_t len);
164 extern size_t path_decode(char *s);
165 extern int utf8_encoded_valid_unichar(const char *str);
166 extern int replace_chars(char *str, const char *white);
167
168 /* udev_utils_file.c */
169 extern int create_path(const char *path);
170 extern int delete_path(const char *path);
171 extern int file_map(const char *filename, char **buf, size_t *bufsize);
172 extern void file_unmap(void *buf, size_t bufsize);
173 extern int unlink_secure(const char *filename);
174 extern size_t buf_get_line(const char *buf, size_t buflen, size_t cur);
175
176 /* udev commands */
177 extern int udevmonitor(int argc, char *argv[], char *envp[]);
178 extern int udevinfo(int argc, char *argv[], char *envp[]);
179 extern int udevcontrol(int argc, char *argv[], char *envp[]);
180 extern int udevtrigger(int argc, char *argv[], char *envp[]);
181 extern int udevsettle(int argc, char *argv[], char *envp[]);
182 extern int udevtest(int argc, char *argv[], char *envp[]);
183
184 #endif