chiark / gitweb /
55814cee0e7974e8c3f44780859a6aec6db44078
[elogind.git] / udev / udev.h
1 /*
2  * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
3  * Copyright (C) 2003-2008 Kay Sievers <kay.sievers@vrfy.org>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #ifndef _UDEV_H_
20 #define _UDEV_H_
21
22 #include "config.h"
23
24 #include <sys/types.h>
25 #include <sys/param.h>
26
27 #include "udev_sysdeps.h"
28 #define LIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE 1
29 #include "lib/libudev.h"
30 #include "lib/libudev-private.h"
31 #include "lib/list.h"
32
33 #define ALLOWED_CHARS                           "#+-.:=@_"
34 #define ALLOWED_CHARS_FILE                      ALLOWED_CHARS "/"
35 #define ALLOWED_CHARS_INPUT                     ALLOWED_CHARS_FILE " $%?,"
36
37 #define DEFAULT_PARTITIONS_COUNT                15
38 #define UDEV_EVENT_TIMEOUT                      180
39
40 /* linux/include/linux/kobject.h */
41 #define UEVENT_BUFFER_SIZE                      2048
42 #define UEVENT_NUM_ENVP                         32
43
44 #define UDEV_CTRL_SOCK_PATH                     "@" UDEV_PREFIX "/org/kernel/udev/udevd"
45
46 #define UDEV_MAX(a,b) ((a) > (b) ? (a) : (b))
47
48 /* pipes */
49 #define READ_END                                0
50 #define WRITE_END                               1
51
52 struct udev_rules;
53
54 struct sysfs_device {
55         struct list_head node;                  /* for device cache */
56         struct sysfs_device *parent;            /* already cached parent*/
57         char devpath[UTIL_PATH_SIZE];
58         char subsystem[UTIL_NAME_SIZE];
59         char kernel[UTIL_NAME_SIZE];            /* device instance name */
60         char kernel_number[UTIL_NAME_SIZE];
61         char driver[UTIL_NAME_SIZE];
62 };
63
64 struct udevice {
65         struct udev *udev;
66
67         /* device event */
68         struct sysfs_device *dev;               /* points to dev_local by default */
69         struct sysfs_device dev_local;
70         struct sysfs_device *dev_parent;        /* current parent device used for matching */
71         char action[UTIL_NAME_SIZE];
72         char *devpath_old;
73
74         /* node */
75         char name[UTIL_PATH_SIZE];
76         struct list_head symlink_list;
77         int symlink_final;
78         char owner[UTIL_NAME_SIZE];
79         int owner_final;
80         char group[UTIL_NAME_SIZE];
81         int group_final;
82         mode_t mode;
83         int mode_final;
84         dev_t devt;
85
86         /* event processing */
87         struct list_head run_list;
88         int run_final;
89         struct list_head env_list;
90         char tmp_node[UTIL_PATH_SIZE];
91         int partitions;
92         int ignore_device;
93         int ignore_remove;
94         char program_result[UTIL_PATH_SIZE];
95         int link_priority;
96         int event_timeout;
97         int test_run;
98 };
99
100 static inline void logging_init(const char *program_name)
101 {
102         openlog(program_name, LOG_PID | LOG_CONS, LOG_DAEMON);
103 }
104
105 static inline void logging_msg(struct udev *udev, int priority,
106                           const char *file, int line, const char *fn,
107                           const char *format, va_list args)
108 {
109         vsyslog(priority, format, args);
110 }
111
112 static inline void logging_close(void)
113 {
114         closelog();
115 }
116
117 /* udev_device.c */
118 extern struct udevice *udev_device_init(struct udev *udev);
119 extern void udev_device_cleanup(struct udevice *udevice);
120 extern dev_t udev_device_get_devt(struct udevice *udevice);
121
122 /* udev_device_event.c */
123 extern int udev_device_event(struct udev_rules *rules, struct udevice *udevice);
124
125 /* udev_sysfs.c */
126 extern int sysfs_init(void);
127 extern void sysfs_cleanup(void);
128 extern void sysfs_device_set_values(struct udev *udev,
129                                     struct sysfs_device *dev, const char *devpath,
130                                     const char *subsystem, const char *driver);
131 extern struct sysfs_device *sysfs_device_get(struct udev *udev, const char *devpath);
132 extern struct sysfs_device *sysfs_device_get_parent(struct udev *udev, struct sysfs_device *dev);
133 extern struct sysfs_device *sysfs_device_get_parent_with_subsystem(struct udev *udev, struct sysfs_device *dev, const char *subsystem);
134 extern char *sysfs_attr_get_value(struct udev *udev, const char *devpath, const char *attr_name);
135 extern int sysfs_lookup_devpath_by_subsys_id(struct udev *udev, char *devpath, size_t len, const char *subsystem, const char *id);
136
137 /* udev_node.c */
138 extern int udev_node_mknod(struct udevice *udevice, const char *file, dev_t devt, mode_t mode, uid_t uid, gid_t gid);
139 extern void udev_node_update_symlinks(struct udevice *udevice, struct udevice *udev_old);
140 extern int udev_node_add(struct udevice *udevice);
141 extern int udev_node_remove(struct udevice *udevice);
142
143 /* udev_db.c */
144 extern int udev_db_add_device(struct udevice *udevice);
145 extern int udev_db_delete_device(struct udevice *udevice);
146 extern int udev_db_rename(struct udev *udev, const char *devpath_old, const char *devpath);
147 extern int udev_db_get_device(struct udevice *udevice, const char *devpath);
148 extern int udev_db_get_devices_by_name(struct udev *udev, const char *name, struct list_head *name_list);
149
150 /* udev_utils.c */
151 struct name_entry {
152         struct list_head node;
153         char name[UTIL_PATH_SIZE];
154         unsigned int ignore_error:1;
155 };
156 extern struct name_entry *name_list_add(struct udev *udev, struct list_head *name_list, const char *name, int sort);
157 extern struct name_entry *name_list_key_add(struct udev *udev, struct list_head *name_list, const char *key, const char *value);
158 extern int name_list_key_remove(struct udev *udev, struct list_head *name_list, const char *key);
159 extern void name_list_cleanup(struct udev *udev, struct list_head *name_list);
160 extern int add_matching_files(struct udev *udev, struct list_head *name_list, const char *dirname, const char *suffix);
161 extern uid_t lookup_user(struct udev *udev, const char *user);
162 extern gid_t lookup_group(struct udev *udev, const char *group);
163
164 /* udev_utils_file.c */
165 extern int create_path(struct udev *udev, const char *path);
166 extern int delete_path(struct udev *udev, const char *path);
167 extern int unlink_secure(struct udev *udev, const char *filename);
168 extern int file_map(const char *filename, char **buf, size_t *bufsize);
169 extern void file_unmap(void *buf, size_t bufsize);
170 extern size_t buf_get_line(const char *buf, size_t buflen, size_t cur);
171
172 /* udevadm commands */
173 extern int udevadm_monitor(struct udev *udev, int argc, char *argv[]);
174 extern int udevadm_info(struct udev *udev, int argc, char *argv[]);
175 extern int udevadm_control(struct udev *udev, int argc, char *argv[]);
176 extern int udevadm_trigger(struct udev *udev, int argc, char *argv[]);
177 extern int udevadm_settle(struct udev *udev, int argc, char *argv[]);
178 extern int udevadm_test(struct udev *udev, int argc, char *argv[]);
179
180 #endif