]>
Commit | Line | Data |
---|---|---|
f0083e3d | 1 | /* |
f0083e3d | 2 | * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com> |
27b77df4 | 3 | * Copyright (C) 2003-2006 Kay Sievers <kay.sievers@vrfy.org> |
f0083e3d GKH |
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., | |
27b77df4 | 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
f0083e3d GKH |
17 | * |
18 | */ | |
19 | ||
c81b35c0 KS |
20 | #ifndef _UDEV_H_ |
21 | #define _UDEV_H_ | |
f0083e3d | 22 | |
c1ab0461 | 23 | #include <sys/types.h> |
c076a2bd | 24 | #include <sys/param.h> |
1aa1e248 | 25 | |
9ed47a9f | 26 | #include "list.h" |
1aa1e248 | 27 | #include "logging.h" |
dbd16d26 | 28 | #include "udev_sysdeps.h" |
1aa1e248 | 29 | #include "udev_version.h" |
f0083e3d | 30 | |
03b24b71 | 31 | #define COMMENT_CHARACTER '#' |
03b24b71 | 32 | #define LINE_SIZE 512 |
989e0811 | 33 | #define PATH_SIZE 512 |
05610c08 | 34 | #define NAME_SIZE 256 |
03b24b71 | 35 | #define VALUE_SIZE 128 |
e964c2c0 | 36 | |
2f2c4fa4 KS |
37 | #define ALLOWED_CHARS "#+-.:=@_%" |
38 | #define ALLOWED_CHARS_FILE ALLOWED_CHARS "/" | |
39 | #define ALLOWED_CHARS_INPUT ALLOWED_CHARS " $/?," | |
40 | ||
03b24b71 KS |
41 | #define DEFAULT_PARTITIONS_COUNT 15 |
42 | #define UDEV_ALARM_TIMEOUT 180 | |
6d564166 | 43 | |
1aa1e248 KS |
44 | #define UDEV_MAX(a,b) ((a) > (b) ? (a) : (b)) |
45 | ||
46 | /* pipes */ | |
03b24b71 KS |
47 | #define READ_END 0 |
48 | #define WRITE_END 1 | |
1aa1e248 | 49 | |
03b24b71 | 50 | #define DB_DIR ".udev/db" |
fbda4bab | 51 | #define DB_NAME_INDEX_DIR ".udev/names" |
fc55cf68 | 52 | |
e8d569b4 KS |
53 | struct udev_rules; |
54 | ||
1aa1e248 | 55 | struct sysfs_device { |
03b24b71 | 56 | struct list_head node; /* for device cache */ |
34f55103 | 57 | struct sysfs_device *parent; /* already cached parent*/ |
1aa1e248 | 58 | char devpath[PATH_SIZE]; |
95776dc6 KS |
59 | char subsystem[NAME_SIZE]; /* $class, $bus, drivers, module */ |
60 | char kernel[NAME_SIZE]; /* device instance name */ | |
1aa1e248 | 61 | char kernel_number[NAME_SIZE]; |
03b24b71 | 62 | char driver[NAME_SIZE]; /* device driver name */ |
5ef42682 KS |
63 | }; |
64 | ||
5840bc63 | 65 | struct udevice { |
1aa1e248 | 66 | /* device event */ |
03b24b71 | 67 | struct sysfs_device *dev; /* points to dev_local by default */ |
1aa1e248 | 68 | struct sysfs_device dev_local; |
03b24b71 | 69 | struct sysfs_device *dev_parent; /* current parent device used for matching */ |
821d0ec8 | 70 | char action[NAME_SIZE]; |
2af003fe | 71 | |
1aa1e248 | 72 | /* node */ |
63f61c5c | 73 | char name[PATH_SIZE]; |
e48fc108 | 74 | struct list_head symlink_list; |
c974742b | 75 | int symlink_final; |
989e0811 | 76 | char owner[NAME_SIZE]; |
c974742b | 77 | int owner_final; |
989e0811 | 78 | char group[NAME_SIZE]; |
c974742b | 79 | int group_final; |
2af003fe | 80 | mode_t mode; |
c974742b | 81 | int mode_final; |
7e720bd4 | 82 | dev_t devt; |
1aa1e248 KS |
83 | |
84 | /* event processing */ | |
821d0ec8 | 85 | struct list_head run_list; |
c974742b | 86 | int run_final; |
b8476286 | 87 | struct list_head env_list; |
63f61c5c | 88 | char tmp_node[PATH_SIZE]; |
50e5de03 | 89 | int partitions; |
821d0ec8 | 90 | int ignore_device; |
7efa217d | 91 | int ignore_remove; |
63f61c5c | 92 | char program_result[PATH_SIZE]; |
2dbb47f8 | 93 | int link_priority; |
7a947ce5 | 94 | int test_run; |
5840bc63 GKH |
95 | }; |
96 | ||
1aa1e248 KS |
97 | /* udev_config.c */ |
98 | extern char udev_root[PATH_SIZE]; | |
99 | extern char udev_config_filename[PATH_SIZE]; | |
9dd0c257 | 100 | extern char udev_rules_dir[PATH_SIZE]; |
1aa1e248 KS |
101 | extern int udev_log_priority; |
102 | extern int udev_run; | |
103 | extern void udev_config_init(void); | |
104 | ||
105 | /* udev_device.c */ | |
31de3a2b | 106 | extern struct udevice *udev_device_init(struct udevice *udev); |
1aa1e248 KS |
107 | extern void udev_device_cleanup(struct udevice *udev); |
108 | extern int udev_device_event(struct udev_rules *rules, struct udevice *udev); | |
109 | extern dev_t udev_device_get_devt(struct udevice *udev); | |
110 | ||
111 | /* udev_sysfs.c */ | |
112 | extern char sysfs_path[PATH_SIZE]; | |
113 | extern int sysfs_init(void); | |
114 | extern void sysfs_cleanup(void); | |
254efc14 KS |
115 | extern void sysfs_device_set_values(struct sysfs_device *dev, const char *devpath, |
116 | const char *subsystem, const char *driver); | |
1aa1e248 KS |
117 | extern struct sysfs_device *sysfs_device_get(const char *devpath); |
118 | extern struct sysfs_device *sysfs_device_get_parent(struct sysfs_device *dev); | |
6ecd4d1e | 119 | extern struct sysfs_device *sysfs_device_get_parent_with_subsystem(struct sysfs_device *dev, const char *subsystem); |
1aa1e248 | 120 | extern char *sysfs_attr_get_value(const char *devpath, const char *attr_name); |
82c60ce5 | 121 | extern int sysfs_resolve_link(char *path, size_t size); |
1aa1e248 | 122 | |
a4d5ca64 KS |
123 | /* udev_node.c */ |
124 | extern int udev_node_mknod(struct udevice *udev, const char *file, dev_t devt, mode_t mode, uid_t uid, gid_t gid); | |
24f0605c KS |
125 | extern void udev_node_update_symlinks(struct udevice *udev, struct udevice *udev_old); |
126 | extern int udev_node_add(struct udevice *udev); | |
a4d5ca64 | 127 | extern int udev_node_remove(struct udevice *udev); |
a507a015 | 128 | |
1aa1e248 | 129 | /* udev_db.c */ |
fc55cf68 KS |
130 | extern int udev_db_add_device(struct udevice *dev); |
131 | extern int udev_db_delete_device(struct udevice *dev); | |
132 | extern int udev_db_get_device(struct udevice *udev, const char *devpath); | |
31de3a2b | 133 | extern int udev_db_get_devices_by_name(const char *name, struct list_head *name_list); |
fc55cf68 KS |
134 | extern int udev_db_get_all_entries(struct list_head *name_list); |
135 | ||
1aa1e248 KS |
136 | /* udev_utils.c */ |
137 | struct name_entry { | |
138 | struct list_head node; | |
139 | char name[PATH_SIZE]; | |
140 | }; | |
141 | extern int log_priority(const char *priority); | |
7ba2d2e6 KS |
142 | extern char *name_list_add(struct list_head *name_list, const char *name, int sort); |
143 | extern char *name_list_key_add(struct list_head *name_list, const char *key, const char *value); | |
db6e59df | 144 | extern int name_list_key_remove(struct list_head *name_list, const char *key); |
1aa1e248 KS |
145 | extern void name_list_cleanup(struct list_head *name_list); |
146 | extern int add_matching_files(struct list_head *name_list, const char *dirname, const char *suffix); | |
3a020a85 KS |
147 | extern uid_t lookup_user(const char *user); |
148 | extern gid_t lookup_group(const char *group); | |
1aa1e248 KS |
149 | |
150 | /* udev_utils_string.c */ | |
1aa1e248 KS |
151 | extern int string_is_true(const char *str); |
152 | extern void remove_trailing_chars(char *path, char c); | |
9c6ad9fb KS |
153 | extern size_t path_encode(char *s, size_t len); |
154 | extern size_t path_decode(char *s); | |
1aa1e248 | 155 | extern int utf8_encoded_valid_unichar(const char *str); |
2f2c4fa4 | 156 | extern int replace_chars(char *str, const char *white); |
1aa1e248 KS |
157 | |
158 | /* udev_utils_file.c */ | |
159 | extern int create_path(const char *path); | |
160 | extern int delete_path(const char *path); | |
161 | extern int file_map(const char *filename, char **buf, size_t *bufsize); | |
162 | extern void file_unmap(void *buf, size_t bufsize); | |
163 | extern int unlink_secure(const char *filename); | |
164 | extern size_t buf_get_line(const char *buf, size_t buflen, size_t cur); | |
165 | ||
166 | /* udev_utils_run.c */ | |
167 | extern int pass_env_to_socket(const char *name, const char *devpath, const char *action); | |
168 | extern int run_program(const char *command, const char *subsystem, | |
169 | char *result, size_t ressize, size_t *reslen, int log); | |
c056c514 | 170 | |
f0083e3d | 171 | #endif |