chiark / gitweb /
remove 'static' from local variable
[elogind.git] / udev.h
1 /*
2  * udev.h
3  *
4  * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
5  * Copyright (C) 2003-2005 Kay Sievers <kay.sievers@vrfy.org>
6  *
7  *      This program is free software; you can redistribute it and/or modify it
8  *      under the terms of the GNU General Public License as published by the
9  *      Free Software Foundation version 2 of the License.
10  * 
11  *      This program is distributed in the hope that it will be useful, but
12  *      WITHOUT ANY WARRANTY; without even the implied warranty of
13  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  *      General Public License for more details.
15  * 
16  *      You should have received a copy of the GNU General Public License along
17  *      with this program; if not, write to the Free Software Foundation, Inc.,
18  *      675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */
21
22 #ifndef _UDEV_H_
23 #define _UDEV_H_
24
25 #include <sys/types.h>
26 #include <sys/param.h>
27
28 #include "list.h"
29 #include "logging.h"
30 #include "udev_libc_wrapper.h"
31 #include "udev_version.h"
32
33 #define COMMENT_CHARACTER                       '#'
34 #define PATH_TO_NAME_CHAR                       '@'
35 #define LINE_SIZE                               512
36 #define PATH_SIZE                               512
37 #define NAME_SIZE                               128
38 #define VALUE_SIZE                              128
39
40 #define DEFAULT_PARTITIONS_COUNT                15
41 #define UDEV_ALARM_TIMEOUT                      180
42
43 #define UDEV_MAX(a,b) ((a) > (b) ? (a) : (b))
44
45 /* pipes */
46 #define READ_END                                0
47 #define WRITE_END                               1
48
49 #define DB_DIR                                  ".udev/db"
50
51 struct udev_rules;
52
53 struct sysfs_device {
54         struct list_head node;                  /* for device cache */
55         struct sysfs_device *parent;            /* already cached parent*/
56         char devpath[PATH_SIZE];
57         char subsystem[NAME_SIZE];              /* $class/$bus/"drivers" */
58         char kernel_name[NAME_SIZE];            /* device instance name */
59         char kernel_number[NAME_SIZE];
60         char driver[NAME_SIZE];                 /* device driver name */
61 };
62
63 struct udevice {
64         /* device event */
65         struct sysfs_device *dev;               /* points to dev_local by default */
66         struct sysfs_device dev_local;
67         struct sysfs_device *dev_parent;        /* current parent device used for matching */
68         char action[NAME_SIZE];
69
70         /* node */
71         char name[PATH_SIZE];
72         struct list_head symlink_list;
73         int symlink_final;
74         char owner[NAME_SIZE];
75         int owner_final;
76         char group[NAME_SIZE];
77         int group_final;
78         mode_t mode;
79         int mode_final;
80         dev_t devt;
81
82         /* event processing */
83         struct list_head run_list;
84         int run_final;
85         struct list_head env_list;
86         char tmp_node[PATH_SIZE];
87         int partitions;
88         int ignore_device;
89         int ignore_remove;
90         char program_result[PATH_SIZE];
91         int test_run;
92 };
93
94 /* udev_config.c */
95 extern char udev_root[PATH_SIZE];
96 extern char udev_config_filename[PATH_SIZE];
97 extern char udev_rules_filename[PATH_SIZE];
98 extern int udev_log_priority;
99 extern int udev_run;
100 extern void udev_config_init(void);
101
102 /* udev_device.c */
103 extern struct udevice *udev_device_init(void);
104 extern void udev_device_cleanup(struct udevice *udev);
105 extern int udev_device_event(struct udev_rules *rules, struct udevice *udev);
106 extern dev_t udev_device_get_devt(struct udevice *udev);
107
108 /* udev_sysfs.c */
109 extern char sysfs_path[PATH_SIZE];
110 extern int sysfs_init(void);
111 extern void sysfs_cleanup(void);
112 extern void sysfs_device_set_values(struct sysfs_device *dev, const char *devpath, const char *subsystem);
113 extern struct sysfs_device *sysfs_device_get(const char *devpath);
114 extern struct sysfs_device *sysfs_device_get_parent(struct sysfs_device *dev);
115 extern struct sysfs_device *sysfs_device_get_parent_with_subsystem(struct sysfs_device *dev, const char *subsystem);
116 extern char *sysfs_attr_get_value(const char *devpath, const char *attr_name);
117
118 /* udev_node.c */
119 extern int udev_node_mknod(struct udevice *udev, const char *file, dev_t devt, mode_t mode, uid_t uid, gid_t gid);
120 extern int udev_node_add(struct udevice *udev, struct udevice *udev_old);
121 extern void udev_node_remove_symlinks(struct udevice *udev);
122 extern int udev_node_remove(struct udevice *udev);
123
124 /* udev_db.c */
125 extern int udev_db_add_device(struct udevice *dev);
126 extern int udev_db_delete_device(struct udevice *dev);
127 extern int udev_db_get_device(struct udevice *udev, const char *devpath);
128 extern int udev_db_lookup_name(const char *name, char *devpath, size_t len);
129 extern int udev_db_get_all_entries(struct list_head *name_list);
130
131 /* udev_utils.c */
132 struct name_entry {
133         struct list_head node;
134         char name[PATH_SIZE];
135 };
136 extern int log_priority(const char *priority);
137 extern char *name_list_add(struct list_head *name_list, const char *name, int sort);
138 extern char *name_list_key_add(struct list_head *name_list, const char *key, const char *value);
139 extern void name_list_cleanup(struct list_head *name_list);
140 extern int add_matching_files(struct list_head *name_list, const char *dirname, const char *suffix);
141
142 /* udev_utils_string.c */
143 extern int strcmp_pattern(const char *p, const char *s);
144 extern int string_is_true(const char *str);
145 extern void remove_trailing_chars(char *path, char c);
146 extern int utf8_encoded_valid_unichar(const char *str);
147 extern int replace_untrusted_chars(char *str);
148
149 /* udev_utils_file.c */
150 extern int create_path(const char *path);
151 extern int delete_path(const char *path);
152 extern int file_map(const char *filename, char **buf, size_t *bufsize);
153 extern void file_unmap(void *buf, size_t bufsize);
154 extern int unlink_secure(const char *filename);
155 extern size_t buf_get_line(const char *buf, size_t buflen, size_t cur);
156
157 /* udev_utils_run.c */
158 extern int pass_env_to_socket(const char *name, const char *devpath, const char *action);
159 extern int run_program(const char *command, const char *subsystem,
160                        char *result, size_t ressize, size_t *reslen, int log);
161
162 #endif