udev.h revision bd284db142c1d3fb6e2a709678c8828c12c52466
b7ff1e47da4653d2ff1ec7b489e6067fed29d8c5Lennart Poettering/*
b7ff1e47da4653d2ff1ec7b489e6067fed29d8c5Lennart Poettering * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
c904f64d84db8c4eebedf210ba10893f19ba05edLennart Poettering * Copyright (C) 2003-2008 Kay Sievers <kay.sievers@vrfy.org>
c904f64d84db8c4eebedf210ba10893f19ba05edLennart Poettering *
7d640cdf66a7c032c871ccfe0ee4ad56f7e3869bLennart Poettering * This program is free software: you can redistribute it and/or modify
62170515a17d0771aa38c8e7711a7a60c8d14d2fLennart Poettering * it under the terms of the GNU General Public License as published by
f80781eaf9f927d7b4d5e66116e3f3a4242e6fa1Lennart Poettering * the Free Software Foundation, either version 2 of the License, or
f80781eaf9f927d7b4d5e66116e3f3a4242e6fa1Lennart Poettering * (at your option) any later version.
f80781eaf9f927d7b4d5e66116e3f3a4242e6fa1Lennart Poettering *
222ae6a8d7e27dd36552cb9574e63cbdfdf2d264Lennart Poettering * This program is distributed in the hope that it will be useful,
222ae6a8d7e27dd36552cb9574e63cbdfdf2d264Lennart Poettering * but WITHOUT ANY WARRANTY; without even the implied warranty of
c904f64d84db8c4eebedf210ba10893f19ba05edLennart Poettering * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c904f64d84db8c4eebedf210ba10893f19ba05edLennart Poettering * GNU General Public License for more details.
099663ff8c117303af369a4d412dafed0c5614c2Lennart Poettering *
cebe0d41e4d5b3fdd9d521116cc029bcb819c90dLennart Poettering * You should have received a copy of the GNU General Public License
099663ff8c117303af369a4d412dafed0c5614c2Lennart Poettering * along with this program. If not, see <http://www.gnu.org/licenses/>.
099663ff8c117303af369a4d412dafed0c5614c2Lennart Poettering */
a49408ec64063023524b964064d393c1fce36e4aKay Sievers
b925e72633bf98438f56a140520e07ec8c959e46Lennart Poettering#ifndef _UDEV_H_
b9a2a36b519ccd79c4198e7dda4e657d597a14adLennart Poettering#define _UDEV_H_
619c2581a2aee8a148caa3b5bec1487fe1a868c6Kay Sievers
619c2581a2aee8a148caa3b5bec1487fe1a868c6Kay Sievers#include <sys/types.h>
b9a2a36b519ccd79c4198e7dda4e657d597a14adLennart Poettering#include <sys/param.h>
90a5f6e42a7422b6033be5d0fe2bf48ea6b91b98Lennart Poettering
90a5f6e42a7422b6033be5d0fe2bf48ea6b91b98Lennart Poettering#include "udev-sysdeps.h"
3d3961f26770b2949a30a72457e1660969bc17b8Lennart Poettering#include "lib/libudev.h"
3d3961f26770b2949a30a72457e1660969bc17b8Lennart Poettering#include "lib/libudev-private.h"
3d3961f26770b2949a30a72457e1660969bc17b8Lennart Poettering
3d3961f26770b2949a30a72457e1660969bc17b8Lennart Poettering#define DEFAULT_FAKE_PARTITIONS_COUNT 15
3d3961f26770b2949a30a72457e1660969bc17b8Lennart Poettering#define UDEV_EVENT_TIMEOUT 180
3d3961f26770b2949a30a72457e1660969bc17b8Lennart Poettering
3d3961f26770b2949a30a72457e1660969bc17b8Lennart Poettering#define UDEV_CTRL_SOCK_PATH "@" UDEV_PREFIX "/org/kernel/udev/udevd"
3d3961f26770b2949a30a72457e1660969bc17b8Lennart Poettering
3d3961f26770b2949a30a72457e1660969bc17b8Lennart Poettering#define UDEV_MAX(a,b) ((a) > (b) ? (a) : (b))
73090dc815390f4fca4e3ed8a7e1d3806605daaaLennart Poettering#define READ_END 0
73090dc815390f4fca4e3ed8a7e1d3806605daaaLennart Poettering#define WRITE_END 1
73090dc815390f4fca4e3ed8a7e1d3806605daaaLennart Poettering
73090dc815390f4fca4e3ed8a7e1d3806605daaaLennart Poetteringstatic inline void logging_init(const char *program_name)
222ae6a8d7e27dd36552cb9574e63cbdfdf2d264Lennart Poettering{
7d76f312889d54dcfe6fdde6eb055e890e7a615bLennart Poettering openlog(program_name, LOG_PID | LOG_CONS, LOG_DAEMON);
73090dc815390f4fca4e3ed8a7e1d3806605daaaLennart Poettering}
73090dc815390f4fca4e3ed8a7e1d3806605daaaLennart Poettering
73090dc815390f4fca4e3ed8a7e1d3806605daaaLennart Poetteringstatic inline void logging_msg(struct udev *udev, int priority,
73090dc815390f4fca4e3ed8a7e1d3806605daaaLennart Poettering const char *file, int line, const char *fn,
3d3961f26770b2949a30a72457e1660969bc17b8Lennart Poettering const char *format, va_list args)
3d3961f26770b2949a30a72457e1660969bc17b8Lennart Poettering{
ba1a55152c50dfbcd3d4a64353b95f4a2f37985eLennart Poettering vsyslog(priority, format, args);
18a5d7fffbcaea5ebd721df5f4938e8a347a2d3bLennart Poettering}
abf96c874cd644cf6c66da95d376aa330382376eLennart Poettering
abf96c874cd644cf6c66da95d376aa330382376eLennart Poetteringstatic inline void logging_close(void)
68c7d001f4117f0c3d0a4582e32cbb03ae5fac57Lennart Poettering{
68c7d001f4117f0c3d0a4582e32cbb03ae5fac57Lennart Poettering closelog();
68c7d001f4117f0c3d0a4582e32cbb03ae5fac57Lennart Poettering}
73090dc815390f4fca4e3ed8a7e1d3806605daaaLennart Poettering
3d3961f26770b2949a30a72457e1660969bc17b8Lennart Poetteringstruct udev_event {
68c7d001f4117f0c3d0a4582e32cbb03ae5fac57Lennart Poettering struct udev_list_node node;
73090dc815390f4fca4e3ed8a7e1d3806605daaaLennart Poettering struct udev *udev;
73090dc815390f4fca4e3ed8a7e1d3806605daaaLennart Poettering struct udev_device *dev;
3d57c6ab801f4437f12948e29589e3d00c3ad9dbLennart Poettering struct udev_device *dev_parent;
3d57c6ab801f4437f12948e29589e3d00c3ad9dbLennart Poettering char *name;
9d8677dad260d7dc20146f8affe3d376daff7c19Lennart Poettering char *tmp_node;
9d8677dad260d7dc20146f8affe3d376daff7c19Lennart Poettering char *program_result;
9d8677dad260d7dc20146f8affe3d376daff7c19Lennart Poettering mode_t mode;
9d8677dad260d7dc20146f8affe3d376daff7c19Lennart Poettering uid_t uid;
cca4aeeead1985f503d175eb1fcad9ed66f2e25dLennart Poettering gid_t gid;
cca4aeeead1985f503d175eb1fcad9ed66f2e25dLennart Poettering struct udev_list_node run_list;
16b879e3eeb25f7b0d517682a4e8b62f39c149f2Kay Sievers pid_t pid;
16b879e3eeb25f7b0d517682a4e8b62f39c149f2Kay Sievers int exitstatus;
16b879e3eeb25f7b0d517682a4e8b62f39c149f2Kay Sievers time_t queue_time;
b9a2a36b519ccd79c4198e7dda4e657d597a14adLennart Poettering unsigned long long int delaying_seqnum;
b9a2a36b519ccd79c4198e7dda4e657d597a14adLennart Poettering unsigned int group_final:1;
ba1a55152c50dfbcd3d4a64353b95f4a2f37985eLennart Poettering unsigned int owner_final:1;
9408a2d295a312a5472345090e28e0502570494bLennart Poettering unsigned int mode_final:1;
68c7d001f4117f0c3d0a4582e32cbb03ae5fac57Lennart Poettering unsigned int name_final:1;
68c7d001f4117f0c3d0a4582e32cbb03ae5fac57Lennart Poettering unsigned int devlink_final:1;
ba1a55152c50dfbcd3d4a64353b95f4a2f37985eLennart Poettering unsigned int run_final:1;
9408a2d295a312a5472345090e28e0502570494bLennart Poettering unsigned int ignore_device:1;
d7cc2987a50e62af6b806f1f56f526cf219a0d97Lennart Poettering unsigned int inotify_watch:1;
d7cc2987a50e62af6b806f1f56f526cf219a0d97Lennart Poettering unsigned int trace:1;
d7cc2987a50e62af6b806f1f56f526cf219a0d97Lennart Poettering};
3f7a8c4e9f1d3ce48919e24eb2c9d56dd6fd88d8Kay Sievers
3f7a8c4e9f1d3ce48919e24eb2c9d56dd6fd88d8Kay Sieversstruct udev_watch {
619c2581a2aee8a148caa3b5bec1487fe1a868c6Kay Sievers struct udev_list_node node;
b9a2a36b519ccd79c4198e7dda4e657d597a14adLennart Poettering int handle;
619c2581a2aee8a148caa3b5bec1487fe1a868c6Kay Sievers char *name;
619c2581a2aee8a148caa3b5bec1487fe1a868c6Kay Sievers};
619c2581a2aee8a148caa3b5bec1487fe1a868c6Kay Sievers
619c2581a2aee8a148caa3b5bec1487fe1a868c6Kay Sievers/* udev-rules.c */
619c2581a2aee8a148caa3b5bec1487fe1a868c6Kay Sieversstruct udev_rules;
619c2581a2aee8a148caa3b5bec1487fe1a868c6Kay Sieversextern struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names);
619c2581a2aee8a148caa3b5bec1487fe1a868c6Kay Sieversextern void udev_rules_unref(struct udev_rules *rules);
619c2581a2aee8a148caa3b5bec1487fe1a868c6Kay Sieversextern int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event);
3f7a8c4e9f1d3ce48919e24eb2c9d56dd6fd88d8Kay Sievers
f9276855a1d270b6c3f857cdaf2c4b49920c2228Lennart Poettering/* udev-event.c */
f9276855a1d270b6c3f857cdaf2c4b49920c2228Lennart Poetteringextern struct udev_event *udev_event_new(struct udev_device *dev);
260abb780a135e4cae8c10715c7e85675efc345aLennart Poetteringextern void udev_event_unref(struct udev_event *event);
260abb780a135e4cae8c10715c7e85675efc345aLennart Poetteringextern int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules);
260abb780a135e4cae8c10715c7e85675efc345aLennart Poetteringextern int udev_event_execute_run(struct udev_event *event);
260abb780a135e4cae8c10715c7e85675efc345aLennart Poetteringextern void udev_event_apply_format(struct udev_event *event, char *string, size_t maxsize);
260abb780a135e4cae8c10715c7e85675efc345aLennart Poetteringextern int udev_event_apply_subsys_kernel(struct udev_event *event, const char *string,
260abb780a135e4cae8c10715c7e85675efc345aLennart Poettering char *result, size_t maxsize, int read_value);
260abb780a135e4cae8c10715c7e85675efc345aLennart Poettering
2791a8f8dc8764a9247cdba3562bd4c04010f144Lennart Poettering/* udev-watch.c */
7d9e57d2cf671f7173324942e0eb9de0d030c505Kay Sieversextern int inotify_fd;
3f7a8c4e9f1d3ce48919e24eb2c9d56dd6fd88d8Kay Sieversextern void udev_watch_init(struct udev *udev);
7d9e57d2cf671f7173324942e0eb9de0d030c505Kay Sieversextern void udev_watch_restore(struct udev *udev);
7d9e57d2cf671f7173324942e0eb9de0d030c505Kay Sieversextern void udev_watch_begin(struct udev *udev, struct udev_device *dev);
7d9e57d2cf671f7173324942e0eb9de0d030c505Kay Sieversextern void udev_watch_clear(struct udev *udev, struct udev_device *dev);
7d9e57d2cf671f7173324942e0eb9de0d030c505Kay Sieversextern void udev_watch_end(struct udev *udev, int wd);
7d9e57d2cf671f7173324942e0eb9de0d030c505Kay Sieversextern const char *udev_watch_lookup(struct udev *udev, int wd);
7d9e57d2cf671f7173324942e0eb9de0d030c505Kay Sievers
7d9e57d2cf671f7173324942e0eb9de0d030c505Kay Sievers/* udev-node.c */
7d9e57d2cf671f7173324942e0eb9de0d030c505Kay Sieversextern int udev_node_mknod(struct udev_device *dev, const char *file, dev_t devnum, mode_t mode, uid_t uid, gid_t gid);
7d9e57d2cf671f7173324942e0eb9de0d030c505Kay Sieversextern int udev_node_add(struct udev_device *dev, mode_t mode, uid_t uid, gid_t gid);
3f7a8c4e9f1d3ce48919e24eb2c9d56dd6fd88d8Kay Sieversextern int udev_node_remove(struct udev_device *dev);
2791a8f8dc8764a9247cdba3562bd4c04010f144Lennart Poetteringextern void udev_node_update_old_links(struct udev_device *dev, struct udev_device *dev_old);
a49408ec64063023524b964064d393c1fce36e4aKay Sievers
a49408ec64063023524b964064d393c1fce36e4aKay Sievers/* udev-util.c */
a49408ec64063023524b964064d393c1fce36e4aKay Sieversextern int util_create_path(struct udev *udev, const char *path);
a49408ec64063023524b964064d393c1fce36e4aKay Sieversextern int util_delete_path(struct udev *udev, const char *path);
a8f11321c209830a35edd0357e8def5d4437d854Lennart Poetteringextern int util_unlink_secure(struct udev *udev, const char *filename);
a8f11321c209830a35edd0357e8def5d4437d854Lennart Poetteringextern uid_t util_lookup_user(struct udev *udev, const char *user);
e85138e67761beeb15967150109734b04862ae05Lennart Poetteringextern gid_t util_lookup_group(struct udev *udev, const char *group);
e85138e67761beeb15967150109734b04862ae05Lennart Poetteringextern int util_run_program(struct udev *udev, const char *command, char **envp,
81253930180bac6b6fb372a9c7bea724bd795c86Lennart Poettering char *result, size_t ressize, size_t *reslen);
7fc7012b8b54bdd6610d32649d4ee9c938a4843dLennart Poetteringextern int util_resolve_subsys_kernel(struct udev *udev, const char *string,
430c18ed7f576fd9041b0a02e7c4210bdd020a25Lennart Poettering char *result, size_t maxsize, int read_value);
1a6f4df6c9437ed631080b7e006f666326063d36Lennart Poettering
1a6f4df6c9437ed631080b7e006f666326063d36Lennart Poettering/* udev-selinux.c */
1a6f4df6c9437ed631080b7e006f666326063d36Lennart Poettering#ifndef USE_SELINUX
a49408ec64063023524b964064d393c1fce36e4aKay Sieversstatic inline void udev_selinux_init(struct udev *udev) {}
3db48a7850d9ceb8e81ec4ad410520c05c008763Lennart Poetteringstatic inline void udev_selinux_exit(struct udev *udev) {}
3db48a7850d9ceb8e81ec4ad410520c05c008763Lennart Poetteringstatic inline void udev_selinux_lsetfilecon(struct udev *udev, const char *file, unsigned int mode) {}
3db48a7850d9ceb8e81ec4ad410520c05c008763Lennart Poetteringstatic inline void udev_selinux_setfscreatecon(struct udev *udev, const char *file, unsigned int mode) {}
2e0d98fa87a4e399763c8235abe56be4f8ac7fb8Lennart Poetteringstatic inline void udev_selinux_resetfscreatecon(struct udev *udev) {}
2e0d98fa87a4e399763c8235abe56be4f8ac7fb8Lennart Poettering#else
62170515a17d0771aa38c8e7711a7a60c8d14d2fLennart Poetteringextern void udev_selinux_init(struct udev *udev);
a49408ec64063023524b964064d393c1fce36e4aKay Sieversextern void udev_selinux_exit(struct udev *udev);
62170515a17d0771aa38c8e7711a7a60c8d14d2fLennart Poetteringextern void udev_selinux_lsetfilecon(struct udev *udev, const char *file, unsigned int mode);
b5c6cf87342bedeb67fbbc4f3f512af1603a461cLennart Poetteringextern void udev_selinux_setfscreatecon(struct udev *udev, const char *file, unsigned int mode);
b5c6cf87342bedeb67fbbc4f3f512af1603a461cLennart Poetteringextern void udev_selinux_resetfscreatecon(struct udev *udev);
3185a36b05d53757a412f847d8c510978b9b00f0Lennart Poettering#endif
7d9e57d2cf671f7173324942e0eb9de0d030c505Kay Sievers
3185a36b05d53757a412f847d8c510978b9b00f0Lennart Poettering/* udevadm commands */
b8bb3e8f346468e61dcc7a6aba5e7ac9c623d964Lennart Poetteringextern int udevadm_monitor(struct udev *udev, int argc, char *argv[]);
b8bb3e8f346468e61dcc7a6aba5e7ac9c623d964Lennart Poetteringextern int udevadm_info(struct udev *udev, int argc, char *argv[]);
f959c5e63a9080cbff42ac4160154f8a6b508e7aLennart Poetteringextern int udevadm_control(struct udev *udev, int argc, char *argv[]);
b9a2a36b519ccd79c4198e7dda4e657d597a14adLennart Poetteringextern int udevadm_trigger(struct udev *udev, int argc, char *argv[]);
7f6d613516020bf390d8de25bbbb2551ea8dade0Lennart Poetteringextern int udevadm_settle(struct udev *udev, int argc, char *argv[]);
c32e0c40f7e706e3ebcd101187d5ced96f083491Lennart Poetteringextern int udevadm_test(struct udev *udev, int argc, char *argv[]);
c32e0c40f7e706e3ebcd101187d5ced96f083491Lennart Poettering#endif
47ae6e6760301ecae086e984b0b23f2db9663b28Lennart Poettering