chiark / gitweb /
udevd: use udev_list_node
[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 <sys/types.h>
23 #include <sys/param.h>
24
25 #include "udev-sysdeps.h"
26 #include "lib/libudev.h"
27 #include "lib/libudev-private.h"
28
29 #define ALLOWED_CHARS                           "#+-.:=@_"
30 #define ALLOWED_CHARS_FILE                      ALLOWED_CHARS "/"
31 #define ALLOWED_CHARS_INPUT                     ALLOWED_CHARS_FILE " $%?,"
32
33 #define DEFAULT_PARTITIONS_COUNT                15
34 #define UDEV_EVENT_TIMEOUT                      180
35
36 /* linux/include/linux/kobject.h */
37 #define UEVENT_BUFFER_SIZE                      2048
38 #define UEVENT_NUM_ENVP                         32
39
40 #define UDEV_CTRL_SOCK_PATH                     "@" UDEV_PREFIX "/org/kernel/udev/udevd"
41
42 #define UDEV_MAX(a,b) ((a) > (b) ? (a) : (b))
43
44 /* pipes */
45 #define READ_END                                0
46 #define WRITE_END                               1
47
48 struct udev_rules;
49
50 static inline void logging_init(const char *program_name)
51 {
52         openlog(program_name, LOG_PID | LOG_CONS, LOG_DAEMON);
53 }
54
55 static inline void logging_msg(struct udev *udev, int priority,
56                           const char *file, int line, const char *fn,
57                           const char *format, va_list args)
58 {
59         vsyslog(priority, format, args);
60 }
61
62 static inline void logging_close(void)
63 {
64         closelog();
65 }
66
67 /* udev-event.c */
68 struct udev_event {
69         struct udev *udev;
70         struct udev_device *dev;
71         struct udev_device *dev_parent;
72         int devlink_final;
73         int owner_final;
74         int group_final;
75         int mode_final;
76         char tmp_node[UTIL_PATH_SIZE];
77         char program_result[UTIL_PATH_SIZE];
78         int run_final;
79
80         char name[UTIL_PATH_SIZE];
81         mode_t mode;
82         char owner[UTIL_NAME_SIZE];
83         char group[UTIL_NAME_SIZE];
84         struct udev_list_node run_list;
85         int ignore_device;
86         int test;
87
88         struct udev_list_node node;
89         pid_t pid;
90         int exitstatus;
91         time_t queue_time;
92 };
93 extern struct udev_event *udev_event_new(struct udev_device *dev);
94 extern void udev_event_unref(struct udev_event *event);
95 extern int udev_event_run(struct udev_event *event, struct udev_rules *rules);
96
97 /* udev-node.c */
98 extern int udev_node_mknod(struct udev_device *dev, const char *file, dev_t devnum, mode_t mode, uid_t uid, gid_t gid);
99 extern int udev_node_add(struct udev_device *dev, mode_t mode, const char *owner, const char *group, int test);
100 extern int udev_node_remove(struct udev_device *dev, int test);
101 extern void udev_node_update_old_links(struct udev_device *dev, struct udev_device *dev_old, int test);
102
103 /* udev-util.c */
104 extern int create_path(struct udev *udev, const char *path);
105 extern int delete_path(struct udev *udev, const char *path);
106 extern int unlink_secure(struct udev *udev, const char *filename);
107 extern uid_t lookup_user(struct udev *udev, const char *user);
108 extern gid_t lookup_group(struct udev *udev, const char *group);
109
110 /* udev_utils_file.c */
111 extern int file_map(const char *filename, char **buf, size_t *bufsize);
112 extern void file_unmap(void *buf, size_t bufsize);
113 extern size_t buf_get_line(const char *buf, size_t buflen, size_t cur);
114
115 /* udev-selinux.c */
116 #ifndef USE_SELINUX
117 static inline void selinux_init(struct udev *udev) {}
118 static inline void selinux_exit(struct udev *udev) {}
119 static inline void udev_selinux_lsetfilecon(struct udev *udev, const char *file, unsigned int mode) {}
120 static inline void udev_selinux_setfscreatecon(struct udev *udev, const char *file, unsigned int mode) {}
121 static inline void udev_selinux_resetfscreatecon(struct udev *udev) {}
122 #else
123 extern void selinux_init(struct udev *udev);
124 extern void selinux_exit(struct udev *udev);
125 extern void udev_selinux_lsetfilecon(struct udev *udev, const char *file, unsigned int mode);
126 extern void udev_selinux_setfscreatecon(struct udev *udev, const char *file, unsigned int mode);
127 extern void udev_selinux_resetfscreatecon(struct udev *udev);
128 #endif
129
130 /* udevadm commands */
131 extern int udevadm_monitor(struct udev *udev, int argc, char *argv[]);
132 extern int udevadm_info(struct udev *udev, int argc, char *argv[]);
133 extern int udevadm_control(struct udev *udev, int argc, char *argv[]);
134 extern int udevadm_trigger(struct udev *udev, int argc, char *argv[]);
135 extern int udevadm_settle(struct udev *udev, int argc, char *argv[]);
136 extern int udevadm_test(struct udev *udev, int argc, char *argv[]);
137 #endif