]> git.ipfire.org Git - thirdparty/systemd.git/blame - udev/udev.h
use no_argument, required_argument, optional_argument in longopts
[thirdparty/systemd.git] / udev / udev.h
CommitLineData
f0083e3d 1/*
f0083e3d 2 * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
4f4b12c2 3 * Copyright (C) 2003-2008 Kay Sievers <kay.sievers@vrfy.org>
f0083e3d 4 *
55e9959b
KS
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.
f0083e3d 9 *
55e9959b
KS
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.
14 *
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/>.
f0083e3d
GKH
17 */
18
c81b35c0
KS
19#ifndef _UDEV_H_
20#define _UDEV_H_
f0083e3d 21
c1ab0461 22#include <sys/types.h>
c076a2bd 23#include <sys/param.h>
1aa1e248 24
dbd16d26 25#include "udev_sysdeps.h"
7d563a17
KS
26#define LIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE 1
27#include "lib/libudev.h"
28#include "lib/libudev-private.h"
e345e267 29#include "list.h"
f0083e3d 30
c1987051 31#define ALLOWED_CHARS "#+-.:=@_"
2f2c4fa4 32#define ALLOWED_CHARS_FILE ALLOWED_CHARS "/"
c1987051 33#define ALLOWED_CHARS_INPUT ALLOWED_CHARS_FILE " $%?,"
2f2c4fa4 34
03b24b71 35#define DEFAULT_PARTITIONS_COUNT 15
bf50425b 36#define UDEV_EVENT_TIMEOUT 180
6d564166 37
d59f11e1
KS
38/* linux/include/linux/kobject.h */
39#define UEVENT_BUFFER_SIZE 2048
40#define UEVENT_NUM_ENVP 32
41
42#define UDEV_CTRL_SOCK_PATH "@" UDEV_PREFIX "/org/kernel/udev/udevd"
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
e8d569b4
KS
50struct udev_rules;
51
1aa1e248 52struct sysfs_device {
03b24b71 53 struct list_head node; /* for device cache */
34f55103 54 struct sysfs_device *parent; /* already cached parent*/
17fcfb59
KS
55 char devpath[UTIL_PATH_SIZE];
56 char subsystem[UTIL_NAME_SIZE];
57 char kernel[UTIL_NAME_SIZE]; /* device instance name */
58 char kernel_number[UTIL_NAME_SIZE];
59 char driver[UTIL_NAME_SIZE];
5ef42682
KS
60};
61
5840bc63 62struct udevice {
7d563a17
KS
63 struct udev *udev;
64
1aa1e248 65 /* device event */
03b24b71 66 struct sysfs_device *dev; /* points to dev_local by default */
1aa1e248 67 struct sysfs_device dev_local;
03b24b71 68 struct sysfs_device *dev_parent; /* current parent device used for matching */
17fcfb59 69 char action[UTIL_NAME_SIZE];
a2f2270e 70 char *devpath_old;
2af003fe 71
1aa1e248 72 /* node */
17fcfb59 73 char name[UTIL_PATH_SIZE];
e48fc108 74 struct list_head symlink_list;
c974742b 75 int symlink_final;
17fcfb59 76 char owner[UTIL_NAME_SIZE];
c974742b 77 int owner_final;
17fcfb59 78 char group[UTIL_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;
17fcfb59 88 char tmp_node[UTIL_PATH_SIZE];
50e5de03 89 int partitions;
821d0ec8 90 int ignore_device;
7efa217d 91 int ignore_remove;
17fcfb59 92 char program_result[UTIL_PATH_SIZE];
2dbb47f8 93 int link_priority;
bf50425b 94 int event_timeout;
7a947ce5 95 int test_run;
5840bc63
GKH
96};
97
7d563a17
KS
98static inline void logging_init(const char *program_name)
99{
100 openlog(program_name, LOG_PID | LOG_CONS, LOG_DAEMON);
101}
102
103static inline void logging_msg(struct udev *udev, int priority,
104 const char *file, int line, const char *fn,
105 const char *format, va_list args)
106{
107 vsyslog(priority, format, args);
108}
109
110static inline void logging_close(void)
111{
112 closelog();
113}
1aa1e248
KS
114
115/* udev_device.c */
7d563a17
KS
116extern struct udevice *udev_device_init(struct udev *udev);
117extern void udev_device_cleanup(struct udevice *udevice);
118extern dev_t udev_device_get_devt(struct udevice *udevice);
1aa1e248 119
d46f37fd 120/* udev_device_event.c */
7d563a17 121extern int udev_device_event(struct udev_rules *rules, struct udevice *udevice);
d46f37fd 122
1aa1e248 123/* udev_sysfs.c */
1aa1e248
KS
124extern int sysfs_init(void);
125extern void sysfs_cleanup(void);
7d563a17
KS
126extern void sysfs_device_set_values(struct udev *udev,
127 struct sysfs_device *dev, const char *devpath,
254efc14 128 const char *subsystem, const char *driver);
7d563a17
KS
129extern struct sysfs_device *sysfs_device_get(struct udev *udev, const char *devpath);
130extern struct sysfs_device *sysfs_device_get_parent(struct udev *udev, struct sysfs_device *dev);
131extern struct sysfs_device *sysfs_device_get_parent_with_subsystem(struct udev *udev, struct sysfs_device *dev, const char *subsystem);
132extern char *sysfs_attr_get_value(struct udev *udev, const char *devpath, const char *attr_name);
7d563a17 133extern int sysfs_lookup_devpath_by_subsys_id(struct udev *udev, char *devpath, size_t len, const char *subsystem, const char *id);
1aa1e248 134
a4d5ca64 135/* udev_node.c */
7d563a17
KS
136extern int udev_node_mknod(struct udevice *udevice, const char *file, dev_t devt, mode_t mode, uid_t uid, gid_t gid);
137extern void udev_node_update_symlinks(struct udevice *udevice, struct udevice *udev_old);
138extern int udev_node_add(struct udevice *udevice);
139extern int udev_node_remove(struct udevice *udevice);
a507a015 140
1aa1e248 141/* udev_db.c */
7d563a17
KS
142extern int udev_db_add_device(struct udevice *udevice);
143extern int udev_db_delete_device(struct udevice *udevice);
144extern int udev_db_rename(struct udev *udev, const char *devpath_old, const char *devpath);
145extern int udev_db_get_device(struct udevice *udevice, const char *devpath);
146extern int udev_db_get_devices_by_name(struct udev *udev, const char *name, struct list_head *name_list);
fc55cf68 147
1aa1e248
KS
148/* udev_utils.c */
149struct name_entry {
150 struct list_head node;
17fcfb59 151 char name[UTIL_PATH_SIZE];
4110664d 152 unsigned int ignore_error:1;
1aa1e248 153};
7d563a17
KS
154extern struct name_entry *name_list_add(struct udev *udev, struct list_head *name_list, const char *name, int sort);
155extern struct name_entry *name_list_key_add(struct udev *udev, struct list_head *name_list, const char *key, const char *value);
156extern int name_list_key_remove(struct udev *udev, struct list_head *name_list, const char *key);
157extern void name_list_cleanup(struct udev *udev, struct list_head *name_list);
158extern int add_matching_files(struct udev *udev, struct list_head *name_list, const char *dirname, const char *suffix);
159extern uid_t lookup_user(struct udev *udev, const char *user);
160extern gid_t lookup_group(struct udev *udev, const char *group);
1aa1e248 161
1aa1e248 162/* udev_utils_file.c */
7d563a17
KS
163extern int create_path(struct udev *udev, const char *path);
164extern int delete_path(struct udev *udev, const char *path);
165extern int unlink_secure(struct udev *udev, const char *filename);
1aa1e248
KS
166extern int file_map(const char *filename, char **buf, size_t *bufsize);
167extern void file_unmap(void *buf, size_t bufsize);
1aa1e248
KS
168extern size_t buf_get_line(const char *buf, size_t buflen, size_t cur);
169
32bf8399 170/* udevadm commands */
7d563a17
KS
171extern int udevadm_monitor(struct udev *udev, int argc, char *argv[]);
172extern int udevadm_info(struct udev *udev, int argc, char *argv[]);
173extern int udevadm_control(struct udev *udev, int argc, char *argv[]);
174extern int udevadm_trigger(struct udev *udev, int argc, char *argv[]);
175extern int udevadm_settle(struct udev *udev, int argc, char *argv[]);
176extern int udevadm_test(struct udev *udev, int argc, char *argv[]);
225cb03b 177
f0083e3d 178#endif