]> git.ipfire.org Git - thirdparty/systemd.git/blame - udev.h
rename config "filename" to "dir"
[thirdparty/systemd.git] / udev.h
CommitLineData
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
KS
31#define COMMENT_CHARACTER '#'
32#define PATH_TO_NAME_CHAR '@'
33#define LINE_SIZE 512
989e0811 34#define PATH_SIZE 512
03b24b71 35#define NAME_SIZE 128
03b24b71 36#define VALUE_SIZE 128
e964c2c0 37
03b24b71
KS
38#define DEFAULT_PARTITIONS_COUNT 15
39#define UDEV_ALARM_TIMEOUT 180
6d564166 40
1aa1e248
KS
41#define UDEV_MAX(a,b) ((a) > (b) ? (a) : (b))
42
43/* pipes */
03b24b71
KS
44#define READ_END 0
45#define WRITE_END 1
1aa1e248 46
03b24b71 47#define DB_DIR ".udev/db"
fc55cf68 48
e8d569b4
KS
49struct udev_rules;
50
1aa1e248 51struct sysfs_device {
03b24b71 52 struct list_head node; /* for device cache */
34f55103 53 struct sysfs_device *parent; /* already cached parent*/
1aa1e248 54 char devpath[PATH_SIZE];
95776dc6
KS
55 char subsystem[NAME_SIZE]; /* $class, $bus, drivers, module */
56 char kernel[NAME_SIZE]; /* device instance name */
1aa1e248 57 char kernel_number[NAME_SIZE];
03b24b71 58 char driver[NAME_SIZE]; /* device driver name */
5ef42682
KS
59};
60
5840bc63 61struct udevice {
1aa1e248 62 /* device event */
03b24b71 63 struct sysfs_device *dev; /* points to dev_local by default */
1aa1e248 64 struct sysfs_device dev_local;
03b24b71 65 struct sysfs_device *dev_parent; /* current parent device used for matching */
821d0ec8 66 char action[NAME_SIZE];
2af003fe 67
1aa1e248 68 /* node */
63f61c5c 69 char name[PATH_SIZE];
e48fc108 70 struct list_head symlink_list;
c974742b 71 int symlink_final;
989e0811 72 char owner[NAME_SIZE];
c974742b 73 int owner_final;
989e0811 74 char group[NAME_SIZE];
c974742b 75 int group_final;
2af003fe 76 mode_t mode;
c974742b 77 int mode_final;
7e720bd4 78 dev_t devt;
1aa1e248
KS
79
80 /* event processing */
821d0ec8 81 struct list_head run_list;
c974742b 82 int run_final;
b8476286 83 struct list_head env_list;
63f61c5c 84 char tmp_node[PATH_SIZE];
50e5de03 85 int partitions;
821d0ec8 86 int ignore_device;
7efa217d 87 int ignore_remove;
63f61c5c 88 char program_result[PATH_SIZE];
7a947ce5 89 int test_run;
5840bc63
GKH
90};
91
1aa1e248
KS
92/* udev_config.c */
93extern char udev_root[PATH_SIZE];
94extern char udev_config_filename[PATH_SIZE];
9dd0c257 95extern char udev_rules_dir[PATH_SIZE];
1aa1e248
KS
96extern int udev_log_priority;
97extern int udev_run;
98extern void udev_config_init(void);
99
100/* udev_device.c */
101extern struct udevice *udev_device_init(void);
102extern void udev_device_cleanup(struct udevice *udev);
103extern int udev_device_event(struct udev_rules *rules, struct udevice *udev);
104extern dev_t udev_device_get_devt(struct udevice *udev);
105
106/* udev_sysfs.c */
107extern char sysfs_path[PATH_SIZE];
108extern int sysfs_init(void);
109extern void sysfs_cleanup(void);
254efc14
KS
110extern void sysfs_device_set_values(struct sysfs_device *dev, const char *devpath,
111 const char *subsystem, const char *driver);
1aa1e248
KS
112extern struct sysfs_device *sysfs_device_get(const char *devpath);
113extern struct sysfs_device *sysfs_device_get_parent(struct sysfs_device *dev);
6ecd4d1e 114extern struct sysfs_device *sysfs_device_get_parent_with_subsystem(struct sysfs_device *dev, const char *subsystem);
1aa1e248 115extern char *sysfs_attr_get_value(const char *devpath, const char *attr_name);
82c60ce5 116extern int sysfs_resolve_link(char *path, size_t size);
1aa1e248 117
a4d5ca64
KS
118/* udev_node.c */
119extern int udev_node_mknod(struct udevice *udev, const char *file, dev_t devt, mode_t mode, uid_t uid, gid_t gid);
ff9a488d
KS
120extern int udev_node_add(struct udevice *udev, struct udevice *udev_old);
121extern void udev_node_remove_symlinks(struct udevice *udev);
a4d5ca64 122extern int udev_node_remove(struct udevice *udev);
a507a015 123
1aa1e248 124/* udev_db.c */
fc55cf68
KS
125extern int udev_db_add_device(struct udevice *dev);
126extern int udev_db_delete_device(struct udevice *dev);
127extern int udev_db_get_device(struct udevice *udev, const char *devpath);
128extern int udev_db_lookup_name(const char *name, char *devpath, size_t len);
129extern int udev_db_get_all_entries(struct list_head *name_list);
130
1aa1e248
KS
131/* udev_utils.c */
132struct name_entry {
133 struct list_head node;
134 char name[PATH_SIZE];
135};
136extern int log_priority(const char *priority);
7ba2d2e6
KS
137extern char *name_list_add(struct list_head *name_list, const char *name, int sort);
138extern char *name_list_key_add(struct list_head *name_list, const char *key, const char *value);
1aa1e248
KS
139extern void name_list_cleanup(struct list_head *name_list);
140extern int add_matching_files(struct list_head *name_list, const char *dirname, const char *suffix);
3a020a85
KS
141extern uid_t lookup_user(const char *user);
142extern gid_t lookup_group(const char *group);
1aa1e248
KS
143
144/* udev_utils_string.c */
1aa1e248
KS
145extern int string_is_true(const char *str);
146extern void remove_trailing_chars(char *path, char c);
147extern int utf8_encoded_valid_unichar(const char *str);
148extern int replace_untrusted_chars(char *str);
149
150/* udev_utils_file.c */
151extern int create_path(const char *path);
152extern int delete_path(const char *path);
153extern int file_map(const char *filename, char **buf, size_t *bufsize);
154extern void file_unmap(void *buf, size_t bufsize);
155extern int unlink_secure(const char *filename);
156extern size_t buf_get_line(const char *buf, size_t buflen, size_t cur);
157
158/* udev_utils_run.c */
159extern int pass_env_to_socket(const char *name, const char *devpath, const char *action);
160extern int run_program(const char *command, const char *subsystem,
161 char *result, size_t ressize, size_t *reslen, int log);
c056c514 162
f0083e3d 163#endif