udev.h revision 225cb03bd851adc6d269b13bdf2b1bfded2b96b9
ee9c9500ab13c1093fc3feaf2aa5a0d330d0bfadKay Sievers/*
b3ae710c251d0ce5cf2cef63208e325497b5e323Zbigniew Jędrzejewski-Szmek * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
b3ae710c251d0ce5cf2cef63208e325497b5e323Zbigniew Jędrzejewski-Szmek * Copyright (C) 2003-2006 Kay Sievers <kay.sievers@vrfy.org>
19aadacf92ad86967ffb678e37b2ff9e83cb9480Jan Engelhardt *
cff452c7e974db5053cdbd0d7bbbab2e3b4c91b9Kay Sievers * This program is free software; you can redistribute it and/or modify it
cff452c7e974db5053cdbd0d7bbbab2e3b4c91b9Kay Sievers * under the terms of the GNU General Public License as published by the
cff452c7e974db5053cdbd0d7bbbab2e3b4c91b9Kay Sievers * Free Software Foundation version 2 of the License.
cff452c7e974db5053cdbd0d7bbbab2e3b4c91b9Kay Sievers *
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers * This program is distributed in the hope that it will be useful, but
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers * WITHOUT ANY WARRANTY; without even the implied warranty of
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers * General Public License for more details.
a40593a0d0d740efa387e35411e1e456a6c5aba7Lennart Poettering *
20ffc4c4a9226b0e45cc02ad9c0108981626c0bbKay Sievers * You should have received a copy of the GNU General Public License along
04ac799283f517672a5424e7c5bf066cfa4ca020Zbigniew Jędrzejewski-Szmek * with this program; if not, write to the Free Software Foundation, Inc.,
04ac799283f517672a5424e7c5bf066cfa4ca020Zbigniew Jędrzejewski-Szmek * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
04ac799283f517672a5424e7c5bf066cfa4ca020Zbigniew Jędrzejewski-Szmek *
04ac799283f517672a5424e7c5bf066cfa4ca020Zbigniew Jędrzejewski-Szmek */
d8160f21fd295b451cee9679aa281fedf1cb8e8cZbigniew Jędrzejewski-Szmek
d8160f21fd295b451cee9679aa281fedf1cb8e8cZbigniew Jędrzejewski-Szmek#ifndef _UDEV_H_
374c356979ba7222fa7e09005824fe6996b0e91eDavid Herrmann#define _UDEV_H_
374c356979ba7222fa7e09005824fe6996b0e91eDavid Herrmann
374c356979ba7222fa7e09005824fe6996b0e91eDavid Herrmann#include <sys/types.h>
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering#include <sys/param.h>
7b4da18c1717f811bae67ea3d39290495857c03eLennart Poettering
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering#include "list.h"
466784c8710e5cb0e0b86a16506d992d7ec5b619Kay Sievers#include "logging.h"
55d32caf94d8df547ca763be52b0c35bb6388606Lennart Poettering#include "udev_sysdeps.h"
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering#include "udev_version.h"
bafb15bab99887d1b6b8a35136531bac6c3876a6Lennart Poettering
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering#define COMMENT_CHARACTER '#'
bafb15bab99887d1b6b8a35136531bac6c3876a6Lennart Poettering#define LINE_SIZE 512
eb124a97fb72d076014253b1acde69d428f15ecfLennart Poettering#define PATH_SIZE 512
154ff088d371bee5651eaa2bc9bde8a34c185656Lennart Poettering#define NAME_SIZE 256
a2b135e3d8d5dfa103a87e304ed8a91b01fdbb02Lennart Poettering#define VALUE_SIZE 128
a2b135e3d8d5dfa103a87e304ed8a91b01fdbb02Lennart Poettering
a2b135e3d8d5dfa103a87e304ed8a91b01fdbb02Lennart Poettering#define ALLOWED_CHARS "#+-.:=@_"
a2b135e3d8d5dfa103a87e304ed8a91b01fdbb02Lennart Poettering#define ALLOWED_CHARS_FILE ALLOWED_CHARS "/"
b107b705cc97d3033e37c44229deb37b5aa31df5Lennart Poettering#define ALLOWED_CHARS_INPUT ALLOWED_CHARS_FILE " $%?,"
b107b705cc97d3033e37c44229deb37b5aa31df5Lennart Poettering
edb2935c5c5b95c42b8679086f60da5eafad74cbLennart Poettering#define DEFAULT_PARTITIONS_COUNT 15
edb2935c5c5b95c42b8679086f60da5eafad74cbLennart Poettering#define UDEV_ALARM_TIMEOUT 180
769918ecd30c0f7ee6e87b9aa6226d956bd2f530Lennart Poettering
769918ecd30c0f7ee6e87b9aa6226d956bd2f530Lennart Poettering#define UDEV_MAX(a,b) ((a) > (b) ? (a) : (b))
769918ecd30c0f7ee6e87b9aa6226d956bd2f530Lennart Poettering
769918ecd30c0f7ee6e87b9aa6226d956bd2f530Lennart Poettering/* pipes */
6a3f892a23db71544d0439355f96c44350dafa8fLennart Poettering#define READ_END 0
2a781fc9bd33982c81e5ff75974a442a33d4f167Lennart Poettering#define WRITE_END 1
2a781fc9bd33982c81e5ff75974a442a33d4f167Lennart Poettering
6a3f892a23db71544d0439355f96c44350dafa8fLennart Poettering#define DB_DIR ".udev/db"
6a3f892a23db71544d0439355f96c44350dafa8fLennart Poettering#define DB_NAME_INDEX_DIR ".udev/names"
efc141b8ffbfa1e449da40ce27fccaa81428f779Lennart Poettering#define RULES_DYN_DIR ".udev/rules.d"
efc141b8ffbfa1e449da40ce27fccaa81428f779Lennart Poettering
efc141b8ffbfa1e449da40ce27fccaa81428f779Lennart Poetteringstruct udev_rules;
efc141b8ffbfa1e449da40ce27fccaa81428f779Lennart Poettering
efc141b8ffbfa1e449da40ce27fccaa81428f779Lennart Poetteringstruct sysfs_device {
726a6e963056a7238a512cfe6ce612af2c2d1419Lennart Poettering struct list_head node; /* for device cache */
7ba4fedb8048182fb765bd6ae5aa1e548389bef3Lennart Poettering struct sysfs_device *parent; /* already cached parent*/
23fae27185ddde98706faac0f45d77b11ecd66e6Lennart Poettering char devpath[PATH_SIZE];
23fae27185ddde98706faac0f45d77b11ecd66e6Lennart Poettering char subsystem[NAME_SIZE]; /* $class, $bus, drivers, module */
650264033f2f98f6319513958d94d59078654af8Lennart Poettering char kernel[NAME_SIZE]; /* device instance name */
650264033f2f98f6319513958d94d59078654af8Lennart Poettering char kernel_number[NAME_SIZE];
650264033f2f98f6319513958d94d59078654af8Lennart Poettering char driver[NAME_SIZE]; /* device driver name */
650264033f2f98f6319513958d94d59078654af8Lennart Poettering};
650264033f2f98f6319513958d94d59078654af8Lennart Poettering
650264033f2f98f6319513958d94d59078654af8Lennart Poetteringstruct udevice {
650264033f2f98f6319513958d94d59078654af8Lennart Poettering /* device event */
650264033f2f98f6319513958d94d59078654af8Lennart Poettering struct sysfs_device *dev; /* points to dev_local by default */
650264033f2f98f6319513958d94d59078654af8Lennart Poettering struct sysfs_device dev_local;
650264033f2f98f6319513958d94d59078654af8Lennart Poettering struct sysfs_device *dev_parent; /* current parent device used for matching */
650264033f2f98f6319513958d94d59078654af8Lennart Poettering char action[NAME_SIZE];
f8901862b2b030921b3d5aba4157044ceab16451Lennart Poettering char *devpath_old;
eda8f06755bd98c4639293c26b856c225f0d1fe1Lennart Poettering
eda8f06755bd98c4639293c26b856c225f0d1fe1Lennart Poettering /* node */
d4fdc205a4610965cee46408dbd046c922e7620cLennart Poettering char name[PATH_SIZE];
d4fdc205a4610965cee46408dbd046c922e7620cLennart Poettering struct list_head symlink_list;
d4fdc205a4610965cee46408dbd046c922e7620cLennart Poettering int symlink_final;
4c63a53ac5190dc8b837c15daefec5772de66bdcLennart Poettering char owner[NAME_SIZE];
4c63a53ac5190dc8b837c15daefec5772de66bdcLennart Poettering int owner_final;
7bb2954901b2e568efaf67254e480032e0958cadLennart Poettering char group[NAME_SIZE];
af1082b04a3d45a9b1d796b4271f44e87e307026Lennart Poettering int group_final;
af1082b04a3d45a9b1d796b4271f44e87e307026Lennart Poettering mode_t mode;
af1082b04a3d45a9b1d796b4271f44e87e307026Lennart Poettering int mode_final;
af1082b04a3d45a9b1d796b4271f44e87e307026Lennart Poettering dev_t devt;
488ad3b32a7e2b5b1380abf4a15e5f65fa65f3feLennart Poettering
488ad3b32a7e2b5b1380abf4a15e5f65fa65f3feLennart Poettering /* event processing */
488ad3b32a7e2b5b1380abf4a15e5f65fa65f3feLennart Poettering struct list_head run_list;
488ad3b32a7e2b5b1380abf4a15e5f65fa65f3feLennart Poettering int run_final;
488ad3b32a7e2b5b1380abf4a15e5f65fa65f3feLennart Poettering struct list_head env_list;
488ad3b32a7e2b5b1380abf4a15e5f65fa65f3feLennart Poettering char tmp_node[PATH_SIZE];
47c94a96df29080f8b3a97e7362df4e9c6ba3265Lennart Poettering int partitions;
47c94a96df29080f8b3a97e7362df4e9c6ba3265Lennart Poettering int ignore_device;
09ecd746c9d6581664873674c2188f8c93ed7780Lennart Poettering int ignore_remove;
09ecd746c9d6581664873674c2188f8c93ed7780Lennart Poettering char program_result[PATH_SIZE];
09ecd746c9d6581664873674c2188f8c93ed7780Lennart Poettering int link_priority;
09ecd746c9d6581664873674c2188f8c93ed7780Lennart Poettering int test_run;
09ecd746c9d6581664873674c2188f8c93ed7780Lennart Poettering};
09ecd746c9d6581664873674c2188f8c93ed7780Lennart Poettering
09ecd746c9d6581664873674c2188f8c93ed7780Lennart Poettering/* udev_config.c */
ef417cfd2211ae017a38b9796c6db29130133e63Zbigniew Jędrzejewski-Szmekextern char udev_root[PATH_SIZE];
ef417cfd2211ae017a38b9796c6db29130133e63Zbigniew Jędrzejewski-Szmekextern char udev_config_filename[PATH_SIZE];
3333d748facc15f49935b6b793490ba0824976e6Zbigniew Jędrzejewski-Szmekextern char udev_rules_dir[PATH_SIZE];
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poetteringextern int udev_log_priority;
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poetteringextern int udev_run;
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poetteringextern void udev_config_init(void);
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering/* udev_device.c */
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poetteringextern struct udevice *udev_device_init(struct udevice *udev);
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poetteringextern void udev_device_cleanup(struct udevice *udev);
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poetteringextern int udev_device_event(struct udev_rules *rules, struct udevice *udev);
0bee65f0622c4faa8ac8ae771cc0c8a936dfa284Lennart Poetteringextern dev_t udev_device_get_devt(struct udevice *udev);
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering/* udev_sysfs.c */
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poetteringextern char sysfs_path[PATH_SIZE];
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poetteringextern int sysfs_init(void);
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poetteringextern void sysfs_cleanup(void);
47c94a96df29080f8b3a97e7362df4e9c6ba3265Lennart Poetteringextern void sysfs_device_set_values(struct sysfs_device *dev, const char *devpath,
47c94a96df29080f8b3a97e7362df4e9c6ba3265Lennart Poettering const char *subsystem, const char *driver);
718db96199eb307751264e4163555662c9a389faLennart Poetteringextern struct sysfs_device *sysfs_device_get(const char *devpath);
718db96199eb307751264e4163555662c9a389faLennart Poetteringextern struct sysfs_device *sysfs_device_get_parent(struct sysfs_device *dev);
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poetteringextern struct sysfs_device *sysfs_device_get_parent_with_subsystem(struct sysfs_device *dev, const char *subsystem);
718db96199eb307751264e4163555662c9a389faLennart Poetteringextern char *sysfs_attr_get_value(const char *devpath, const char *attr_name);
718db96199eb307751264e4163555662c9a389faLennart Poetteringextern int sysfs_resolve_link(char *path, size_t size);
718db96199eb307751264e4163555662c9a389faLennart Poetteringextern int sysfs_lookup_devpath_by_subsys_id(char *devpath, size_t len, const char *subsystem, const char *id);
966204e010ed432a1d7a0481d41a326d8ec7b0c8Lennart Poettering
966204e010ed432a1d7a0481d41a326d8ec7b0c8Lennart Poettering/* udev_node.c */
94676f3e9352cbf1f72e0a512ee0d2ed83ff676dLennart Poetteringextern int udev_node_mknod(struct udevice *udev, const char *file, dev_t devt, mode_t mode, uid_t uid, gid_t gid);
6fd4d0209827e5c3e52fa8c7144852f550f8f95cLennart Poetteringextern void udev_node_update_symlinks(struct udevice *udev, struct udevice *udev_old);
ced4d06784dbb19666688947901961f949f2aa6dLennart Poetteringextern int udev_node_add(struct udevice *udev);
ced4d06784dbb19666688947901961f949f2aa6dLennart Poetteringextern int udev_node_remove(struct udevice *udev);
af1082b04a3d45a9b1d796b4271f44e87e307026Lennart Poettering
416446221d905b6815175dc4d525d27f8ae43d1bLennart Poettering/* udev_db.c */
416446221d905b6815175dc4d525d27f8ae43d1bLennart Poetteringextern int udev_db_add_device(struct udevice *dev);
416446221d905b6815175dc4d525d27f8ae43d1bLennart Poetteringextern int udev_db_delete_device(struct udevice *dev);
7f79cd7109a60810140a045cc725291fc5515264Lennart Poetteringextern int udev_db_rename(const char *devpath_old, const char *devpath);
0aafd43d235982510d1c40564079f7bcec0c7c19Lennart Poetteringextern int udev_db_get_device(struct udevice *udev, const char *devpath);
19aadacf92ad86967ffb678e37b2ff9e83cb9480Jan Engelhardtextern int udev_db_get_devices_by_name(const char *name, struct list_head *name_list);
19aadacf92ad86967ffb678e37b2ff9e83cb9480Jan Engelhardtextern int udev_db_get_all_entries(struct list_head *name_list);
df5f6971e6e15b4632884916c71daa076c8bae96Lennart Poettering
df5f6971e6e15b4632884916c71daa076c8bae96Lennart Poettering/* udev_utils.c */
fcba531ed4c6e6f8f21d8ca4e3a56e3162b1c578Lennart Poetteringstruct name_entry {
fcba531ed4c6e6f8f21d8ca4e3a56e3162b1c578Lennart Poettering struct list_head node;
8b8f259170e35b93e6c6d1757cb8b835bbdaa40cZbigniew Jędrzejewski-Szmek char name[PATH_SIZE];
8b8f259170e35b93e6c6d1757cb8b835bbdaa40cZbigniew Jędrzejewski-Szmek unsigned int ignore_error:1;
e10e429f2dcbb586215e65f62847f40c7d8b5956David Herrmann};
e1b7e7ec9b34ae6ae54a4c8084395cbf2bfe9960Lennart Poettering
6aaa8c2f783cd1b3ac27c5ce40625d032e7e3d71Zbigniew Jędrzejewski-Szmekextern int log_priority(const char *priority);
c3bb87dbab8b79bb9253407cb5b7f3e6fe8db395Lennart Poetteringextern struct name_entry *name_list_add(struct list_head *name_list, const char *name, int sort);
e1b7e7ec9b34ae6ae54a4c8084395cbf2bfe9960Lennart Poetteringextern struct name_entry *name_list_key_add(struct list_head *name_list, const char *key, const char *value);
18d4e7c26e7806ac363d19989df7144d5058ce41Lennart Poetteringextern int name_list_key_remove(struct list_head *name_list, const char *key);
bdeeb6b543a2a2d0a494f17b85f1498859cdfc2fLennart Poetteringextern void name_list_cleanup(struct list_head *name_list);
bdeeb6b543a2a2d0a494f17b85f1498859cdfc2fLennart Poetteringextern int add_matching_files(struct list_head *name_list, const char *dirname, const char *suffix);
bdeeb6b543a2a2d0a494f17b85f1498859cdfc2fLennart Poetteringextern uid_t lookup_user(const char *user);
bdeeb6b543a2a2d0a494f17b85f1498859cdfc2fLennart Poetteringextern gid_t lookup_group(const char *group);
9444b1f20e311f073864d81e913bd4f32fe95cfdLennart Poettering
69af45035913e7119cffd94c542bd3039600e45dZbigniew Jędrzejewski-Szmek/* udev_utils_string.c */
9444b1f20e311f073864d81e913bd4f32fe95cfdLennart Poetteringextern int string_is_true(const char *str);
466784c8710e5cb0e0b86a16506d992d7ec5b619Kay Sieversextern void remove_trailing_chars(char *path, char c);
466784c8710e5cb0e0b86a16506d992d7ec5b619Kay Sieversextern size_t path_encode(char *s, size_t len);
9444b1f20e311f073864d81e913bd4f32fe95cfdLennart Poetteringextern size_t path_decode(char *s);
4e09014daf8f98584b3f15e64e93bed232e70a6bLennart Poetteringextern int utf8_encoded_valid_unichar(const char *str);
4e09014daf8f98584b3f15e64e93bed232e70a6bLennart Poetteringextern int replace_chars(char *str, const char *white);
4e09014daf8f98584b3f15e64e93bed232e70a6bLennart Poettering
6bb648a16ae4a682ad4784412af706d2e6a3e4daTom Gundersen/* udev_utils_file.c */
eb01ba5de14859d7a94835ab9299de40132d549aLennart Poetteringextern int create_path(const char *path);
7973ca1927e1f3bac9438f3529458c9ff868905dLennart Poetteringextern int delete_path(const char *path);
7973ca1927e1f3bac9438f3529458c9ff868905dLennart Poetteringextern int file_map(const char *filename, char **buf, size_t *bufsize);
7973ca1927e1f3bac9438f3529458c9ff868905dLennart Poetteringextern void file_unmap(void *buf, size_t bufsize);
7973ca1927e1f3bac9438f3529458c9ff868905dLennart Poetteringextern int unlink_secure(const char *filename);
7973ca1927e1f3bac9438f3529458c9ff868905dLennart Poetteringextern size_t buf_get_line(const char *buf, size_t buflen, size_t cur);
7973ca1927e1f3bac9438f3529458c9ff868905dLennart Poettering
7973ca1927e1f3bac9438f3529458c9ff868905dLennart Poettering/* udev commands */
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poetteringextern int udevmonitor(int argc, char *argv[], char *envp[]);
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poetteringextern int udevinfo(int argc, char *argv[], char *envp[]);
80caea6cc72ebd311a311b1527cc6b87201c13bfLennart Poetteringextern int udevcontrol(int argc, char *argv[], char *envp[]);
ab9716c2489f9141ed13ec22dbb216b3e6fbd6b5Lennart Poetteringextern int udevtrigger(int argc, char *argv[], char *envp[]);
df98a87ba389bdfc0359beedf47557411f3af434Lennart Poetteringextern int udevsettle(int argc, char *argv[], char *envp[]);
df98a87ba389bdfc0359beedf47557411f3af434Lennart Poetteringextern int udevtest(int argc, char *argv[], char *envp[]);
df98a87ba389bdfc0359beedf47557411f3af434Lennart Poettering
df98a87ba389bdfc0359beedf47557411f3af434Lennart Poettering#endif
bee7e928990fd8a0c5909c2022a2b9eede557c81Lennart Poettering