chiark / gitweb /
[PATCH] no error on enoent
[elogind.git] / udev.h
1 /*
2  * udev.h
3  *
4  * Userspace devfs
5  *
6  * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
7  *
8  *      This program is free software; you can redistribute it and/or modify it
9  *      under the terms of the GNU General Public License as published by the
10  *      Free Software Foundation version 2 of the License.
11  * 
12  *      This program is distributed in the hope that it will be useful, but
13  *      WITHOUT ANY WARRANTY; without even the implied warranty of
14  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  *      General Public License for more details.
16  * 
17  *      You should have received a copy of the GNU General Public License along
18  *      with this program; if not, write to the Free Software Foundation, Inc.,
19  *      675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  */
22
23 #ifndef UDEV_H
24 #define UDEV_H
25
26 #include <stdlib.h>
27 #include <string.h>
28 #include <sysfs/libsysfs.h>
29 #include <stddef.h>
30 #include <sys/param.h>
31
32 #define COMMENT_CHARACTER               '#'
33
34 #define NAME_SIZE       100
35 #define OWNER_SIZE      30
36 #define GROUP_SIZE      30
37 #define MODE_SIZE       8
38
39 #define ACTION_SIZE     30
40 #define DEVPATH_SIZE    255
41 #define SUBSYSTEM_SIZE  30
42
43 /* length of public data */
44 #define UDEVICE_LEN (offsetof(struct udevice, bus_id))
45
46 struct udevice {
47         char name[NAME_SIZE];
48         char owner[OWNER_SIZE];
49         char group[GROUP_SIZE];
50         char type;
51         int major;
52         int minor;
53         unsigned int mode;      /* not mode_t due to conflicting definitions in different libcs */
54         char symlink[NAME_SIZE];
55         int partitions;
56
57         /* private data that help us in building strings */
58         char bus_id[SYSFS_NAME_LEN];
59         char program_result[NAME_SIZE];
60         char kernel_number[NAME_SIZE];
61         char kernel_name[NAME_SIZE];
62 };
63
64 #define strfieldcpy(to, from) \
65 do { \
66         to[sizeof(to)-1] = '\0'; \
67         strncpy(to, from, sizeof(to)-1); \
68 } while (0)
69
70 #define strfieldcat(to, from) \
71 do { \
72         to[sizeof(to)-1] = '\0'; \
73         strncat(to, from, sizeof(to) - strlen(to)-1); \
74 } while (0)
75
76 #define strnfieldcpy(to, from, maxsize) \
77 do { \
78         to[maxsize-1] = '\0'; \
79         strncpy(to, from, maxsize-1); \
80 } while (0)
81
82 #define strnfieldcat(to, from, maxsize) \
83 do { \
84         to[maxsize-1] = '\0'; \
85         strncat(to, from, maxsize - strlen(to)-1); \
86 } while (0)
87
88 #define strintcat(to, i) \
89 do { \
90         to[sizeof(to)-1] = '\0'; \
91         snprintf((to) + strlen(to), sizeof(to) - strlen(to)-1, "%u", i); \
92 } while (0)
93
94 #define strnintcat(to, i, maxsize) \
95 do { \
96         to[maxsize-1] = '\0'; \
97         snprintf((to) + strlen(to), maxsize - strlen(to)-1, "%u", i); \
98 } while (0)
99
100 static inline char *get_action(void)
101 {
102         char *action;
103
104         action = getenv("ACTION");
105         if (action != NULL && strlen(action) > ACTION_SIZE)
106                 action[ACTION_SIZE-1] = '\0';
107
108         return action;
109 }
110
111 static inline char *get_devpath(void)
112 {
113         char *devpath;
114
115         devpath = getenv("DEVPATH");
116         if (devpath != NULL && strlen(devpath) > DEVPATH_SIZE)
117                 devpath[DEVPATH_SIZE-1] = '\0';
118
119         return devpath;
120 }
121
122 static inline char *get_seqnum(void)
123 {
124         char *seqnum;
125
126         seqnum = getenv("SEQNUM");
127
128         return seqnum;
129 }
130
131 static inline char *get_subsystem(char *subsystem)
132 {
133         if (subsystem != NULL && strlen(subsystem) > SUBSYSTEM_SIZE)
134                 subsystem[SUBSYSTEM_SIZE-1] = '\0';
135
136         return subsystem;
137 }
138
139 extern int udev_add_device(char *path, char *subsystem, int fake);
140 extern int udev_remove_device(char *path, char *subsystem);
141 extern void udev_init_config(void);
142 extern int parse_get_pair(char **orig_string, char **left, char **right);
143
144 extern char **main_argv;
145 extern char **main_envp;
146 extern char sysfs_path[SYSFS_PATH_MAX];
147 extern char udev_root[PATH_MAX];
148 extern char udev_db_filename[PATH_MAX+NAME_MAX];
149 extern char udev_permissions_filename[PATH_MAX+NAME_MAX];
150 extern char udev_config_filename[PATH_MAX+NAME_MAX];
151 extern char udev_rules_filename[PATH_MAX+NAME_MAX];
152 extern char default_mode_str[MODE_SIZE];
153 extern char default_owner_str[OWNER_SIZE];
154 extern char default_group_str[GROUP_SIZE];
155 extern int udev_log;
156 extern int udev_sleep;
157
158 #endif