chiark / gitweb /
make SYSFS{} usable for all devices
[elogind.git] / udev_rules.h
1 /*
2  * udev_rules.h
3  *
4  * Userspace devfs
5  *
6  * Copyright (C) 2003,2004 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_RULES_H
24 #define UDEV_RULES_H
25
26 #include "libsysfs/sysfs/libsysfs.h"
27 #include "udev.h"
28 #include "list.h"
29
30 #define PAIRS_MAX               5
31 #define RULEFILE_SUFFIX         ".rules"
32
33 enum key_operation {
34         KEY_OP_UNSET,
35         KEY_OP_MATCH,
36         KEY_OP_NOMATCH,
37         KEY_OP_ADD,
38         KEY_OP_ASSIGN,
39         KEY_OP_ASSIGN_FINAL,
40 };
41
42 struct key {
43         enum key_operation operation;
44         size_t val_off;
45 };
46
47 struct key_pair {
48         struct key key;
49         size_t key_name_off;
50 };
51
52 struct key_pairs {
53         int count;
54         struct key_pair keys[PAIRS_MAX];
55 };
56
57 enum import_type {
58         IMPORT_UNSET,
59         IMPORT_PROGRAM,
60         IMPORT_FILE,
61         IMPORT_PARENT,
62 };
63
64 struct udev_rule {
65         struct key label;
66         struct key goto_label;
67         struct key kernel_name;
68         struct key subsystem;
69         struct key action;
70         struct key devpath;
71         struct key bus;
72         struct key id;
73         struct key driver;
74         struct key program;
75         struct key result;
76         struct key modalias;
77         struct key import;
78         enum import_type import_type;
79         struct key wait_for_sysfs;
80         struct key_pairs sysfs;
81         struct key_pairs env;
82
83         struct key name;
84         struct key symlink;
85         struct key run;
86         struct key owner;
87         struct key group;
88         enum key_operation mode_operation;
89         mode_t mode;
90
91         unsigned int partitions;
92         unsigned int last_rule:1,
93                      ignore_device:1,
94                      ignore_remove:1;
95
96         size_t bufsize;
97         char buf[];
98 };
99
100 struct udev_rules {
101         char *buf;
102         size_t bufsize;
103         size_t current;
104         int mapped;
105         int resolve_names;
106 };
107
108 extern int udev_rules_init(struct udev_rules *rules, int resolve_names);
109 extern void udev_rules_close(struct udev_rules *rules);
110
111 extern void udev_rules_iter_init(struct udev_rules *rules);
112 extern struct udev_rule *udev_rules_iter_next(struct udev_rules *rules);
113 extern struct udev_rule *udev_rules_iter_label(struct udev_rules *rules, const char *label);
114
115 extern int udev_rules_get_name(struct udev_rules *rules, struct udevice *udev,
116                                struct sysfs_class_device *class_dev);
117 extern int udev_rules_get_run(struct udev_rules *rules, struct udevice *udev,
118                               struct sysfs_class_device *class_dev, struct sysfs_device *sysfs_dev);
119
120 #endif