2 * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
3 * Copyright (C) 2003-2008 Kay Sievers <kay.sievers@vrfy.org>
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.
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.
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/>.
22 #include <sys/types.h>
23 #include <sys/param.h>
25 #include "udev-sysdeps.h"
26 #include "lib/libudev.h"
27 #include "lib/libudev-private.h"
30 #define ALLOWED_CHARS "#+-.:=@_"
31 #define ALLOWED_CHARS_FILE ALLOWED_CHARS "/"
32 #define ALLOWED_CHARS_INPUT ALLOWED_CHARS_FILE " $%?,"
34 #define DEFAULT_PARTITIONS_COUNT 15
35 #define UDEV_EVENT_TIMEOUT 180
37 /* linux/include/linux/kobject.h */
38 #define UEVENT_BUFFER_SIZE 2048
39 #define UEVENT_NUM_ENVP 32
41 #define UDEV_CTRL_SOCK_PATH "@" UDEV_PREFIX "/org/kernel/udev/udevd"
43 #define UDEV_MAX(a,b) ((a) > (b) ? (a) : (b))
51 static inline void logging_init(const char *program_name)
53 openlog(program_name, LOG_PID | LOG_CONS, LOG_DAEMON);
56 static inline void logging_msg(struct udev *udev, int priority,
57 const char *file, int line, const char *fn,
58 const char *format, va_list args)
60 vsyslog(priority, format, args);
63 static inline void logging_close(void)
71 struct udev_device *dev;
72 struct udev_device *dev_parent;
77 char tmp_node[UTIL_PATH_SIZE];
78 char program_result[UTIL_PATH_SIZE];
81 char name[UTIL_PATH_SIZE];
83 char owner[UTIL_NAME_SIZE];
84 char group[UTIL_NAME_SIZE];
85 struct udev_list_node run_list;
89 struct list_head node;
94 extern struct udev_event *udev_event_new(struct udev_device *dev);
95 extern void udev_event_unref(struct udev_event *event);
96 extern int udev_event_run(struct udev_event *event, struct udev_rules *rules);
99 extern int udev_node_mknod(struct udev_device *dev, const char *file, dev_t devnum, mode_t mode, uid_t uid, gid_t gid);
100 extern int udev_node_add(struct udev_device *dev, mode_t mode, const char *owner, const char *group, int test);
101 extern int udev_node_remove(struct udev_device *dev, int test);
102 extern void udev_node_update_old_links(struct udev_device *dev, struct udev_device *dev_old, int test);
105 extern int create_path(struct udev *udev, const char *path);
106 extern int delete_path(struct udev *udev, const char *path);
107 extern int unlink_secure(struct udev *udev, const char *filename);
108 extern uid_t lookup_user(struct udev *udev, const char *user);
109 extern gid_t lookup_group(struct udev *udev, const char *group);
111 /* udev_utils_file.c */
112 extern int file_map(const char *filename, char **buf, size_t *bufsize);
113 extern void file_unmap(void *buf, size_t bufsize);
114 extern size_t buf_get_line(const char *buf, size_t buflen, size_t cur);
118 static inline void selinux_init(struct udev *udev) {}
119 static inline void selinux_exit(struct udev *udev) {}
120 static inline void udev_selinux_lsetfilecon(struct udev *udev, const char *file, unsigned int mode) {}
121 static inline void udev_selinux_setfscreatecon(struct udev *udev, const char *file, unsigned int mode) {}
122 static inline void udev_selinux_resetfscreatecon(struct udev *udev) {}
124 extern void selinux_init(struct udev *udev);
125 extern void selinux_exit(struct udev *udev);
126 extern void udev_selinux_lsetfilecon(struct udev *udev, const char *file, unsigned int mode);
127 extern void udev_selinux_setfscreatecon(struct udev *udev, const char *file, unsigned int mode);
128 extern void udev_selinux_resetfscreatecon(struct udev *udev);
131 /* udevadm commands */
132 extern int udevadm_monitor(struct udev *udev, int argc, char *argv[]);
133 extern int udevadm_info(struct udev *udev, int argc, char *argv[]);
134 extern int udevadm_control(struct udev *udev, int argc, char *argv[]);
135 extern int udevadm_trigger(struct udev *udev, int argc, char *argv[]);
136 extern int udevadm_settle(struct udev *udev, int argc, char *argv[]);
137 extern int udevadm_test(struct udev *udev, int argc, char *argv[]);