chiark / gitweb /
200d7e83692808c89c2e93f0dec7bc17c42b6c13
[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                               128
35 #define VALUE_SIZE                              128
36
37 #define DEFAULT_PARTITIONS_COUNT                15
38 #define UDEV_ALARM_TIMEOUT                      180
39
40 #define UDEV_MAX(a,b) ((a) > (b) ? (a) : (b))
41
42 /* pipes */
43 #define READ_END                                0
44 #define WRITE_END                               1
45
46 #define DB_DIR                                  ".udev/db"
47
48 struct udev_rules;
49
50 struct sysfs_device {
51         struct list_head node;                  /* for device cache */
52         struct sysfs_device *parent;            /* already cached parent*/
53         char devpath[PATH_SIZE];
54         char subsystem[NAME_SIZE];              /* $class, $bus, drivers, module */
55         char kernel[NAME_SIZE];                 /* device instance name */
56         char kernel_number[NAME_SIZE];
57         char driver[NAME_SIZE];                 /* device driver name */
58 };
59
60 struct udevice {
61         /* device event */
62         struct sysfs_device *dev;               /* points to dev_local by default */
63         struct sysfs_device dev_local;
64         struct sysfs_device *dev_parent;        /* current parent device used for matching */
65         char action[NAME_SIZE];
66
67         /* node */
68         char name[PATH_SIZE];
69         struct list_head symlink_list;
70         int symlink_final;
71         char owner[NAME_SIZE];
72         int owner_final;
73         char group[NAME_SIZE];
74         int group_final;
75         mode_t mode;
76         int mode_final;
77         dev_t devt;
78
79         /* event processing */
80         struct list_head run_list;
81         int run_final;
82         struct list_head env_list;
83         char tmp_node[PATH_SIZE];
84         int partitions;
85         int ignore_device;
86         int ignore_remove;
87         char program_result[PATH_SIZE];
88         int test_run;
89 };
90
91 /* udev_config.c */
92 extern char udev_root[PATH_SIZE];
93 extern char udev_config_filename[PATH_SIZE];
94 extern char udev_rules_dir[PATH_SIZE];
95 extern int udev_log_priority;
96 extern int udev_run;
97 extern void udev_config_init(void);
98
99 /* udev_device.c */
100 extern struct udevice *udev_device_init(void);
101 extern void udev_device_cleanup(struct udevice *udev);
102 extern int udev_device_event(struct udev_rules *rules, struct udevice *udev);
103 extern dev_t udev_device_get_devt(struct udevice *udev);
104
105 /* udev_sysfs.c */
106 extern char sysfs_path[PATH_SIZE];
107 extern int sysfs_init(void);
108 extern void sysfs_cleanup(void);
109 extern void sysfs_device_set_values(struct sysfs_device *dev, const char *devpath,
110                                     const char *subsystem, const char *driver);
111 extern struct sysfs_device *sysfs_device_get(const char *devpath);
112 extern struct sysfs_device *sysfs_device_get_parent(struct sysfs_device *dev);
113 extern struct sysfs_device *sysfs_device_get_parent_with_subsystem(struct sysfs_device *dev, const char *subsystem);
114 extern char *sysfs_attr_get_value(const char *devpath, const char *attr_name);
115 extern int sysfs_resolve_link(char *path, size_t size);
116
117 /* udev_node.c */
118 extern int udev_node_mknod(struct udevice *udev, const char *file, dev_t devt, mode_t mode, uid_t uid, gid_t gid);
119 extern int udev_node_add(struct udevice *udev, struct udevice *udev_old);
120 extern void udev_node_remove_symlinks(struct udevice *udev);
121 extern int udev_node_remove(struct udevice *udev);
122
123 /* udev_db.c */
124 extern int udev_db_add_device(struct udevice *dev);
125 extern int udev_db_delete_device(struct udevice *dev);
126 extern int udev_db_get_device(struct udevice *udev, const char *devpath);
127 extern int udev_db_lookup_name(const char *name, char *devpath, size_t len);
128 extern int udev_db_get_all_entries(struct list_head *name_list);
129
130 /* udev_utils.c */
131 struct name_entry {
132         struct list_head node;
133         char name[PATH_SIZE];
134 };
135 extern int log_priority(const char *priority);
136 extern char *name_list_add(struct list_head *name_list, const char *name, int sort);
137 extern char *name_list_key_add(struct list_head *name_list, const char *key, const char *value);
138 extern void name_list_cleanup(struct list_head *name_list);
139 extern int add_matching_files(struct list_head *name_list, const char *dirname, const char *suffix);
140 extern uid_t lookup_user(const char *user);
141 extern gid_t lookup_group(const char *group);
142
143 /* udev_utils_string.c */
144 extern int string_is_true(const char *str);
145 extern void remove_trailing_chars(char *path, char c);
146 extern size_t path_encode(char *s, size_t len);
147 extern size_t path_decode(char *s);
148 extern int utf8_encoded_valid_unichar(const char *str);
149 extern int replace_untrusted_chars(char *str);
150
151 /* udev_utils_file.c */
152 extern int create_path(const char *path);
153 extern int delete_path(const char *path);
154 extern int file_map(const char *filename, char **buf, size_t *bufsize);
155 extern void file_unmap(void *buf, size_t bufsize);
156 extern int unlink_secure(const char *filename);
157 extern size_t buf_get_line(const char *buf, size_t buflen, size_t cur);
158
159 /* udev_utils_run.c */
160 extern int pass_env_to_socket(const char *name, const char *devpath, const char *action);
161 extern int run_program(const char *command, const char *subsystem,
162                        char *result, size_t ressize, size_t *reslen, int log);
163
164 #endif