6 * Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>
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.
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.
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.
31 #include "libsysfs/sysfs/libsysfs.h"
33 #include "udev_sysfs.h"
34 #include "udev_utils.h"
35 #include "udev_version.h"
36 #include "udev_rules.h"
41 void log_message (int priority, const char *format, ...)
45 if (priority > udev_log_priority)
48 va_start(args, format);
49 vprintf(format, args);
51 if (format[strlen(format)-1] != '\n')
56 int main(int argc, char *argv[], char *envp[])
58 struct udev_rules rules;
59 struct sysfs_class_device *class_dev;
64 char *subsystem = NULL;
66 info("version %s", UDEV_VERSION);
68 /* initialize our configuration */
70 if (udev_log_priority < LOG_INFO)
71 udev_log_priority = LOG_INFO;
74 info("Usage: udevtest <devpath> <subsystem>");
78 /* remove sysfs_path if given */
79 if (strncmp(argv[1], sysfs_path, strlen(sysfs_path)) == 0)
80 devpath = &argv[1][strlen(sysfs_path)] ;
82 if (argv[1][0] != '/') {
83 /* prepend '/' if missing */
84 snprintf(temp, sizeof(temp), "/%s", argv[1]);
85 temp[sizeof(temp)-1] = '\0';
91 setenv("DEVPATH", devpath, 1);
92 setenv("SUBSYSTEM", subsystem, 1);
93 setenv("ACTION", "add", 1);
94 info("looking at device '%s' from subsystem '%s'", devpath, subsystem);
96 /* initialize the naming deamon */
97 udev_rules_init(&rules, 0);
99 /* fill in values and test_run flag*/
100 udev_init_device(&udev, devpath, subsystem, "add");
102 /* open the device */
103 snprintf(path, sizeof(path), "%s%s", sysfs_path, udev.devpath);
104 path[sizeof(path)-1] = '\0';
105 class_dev = sysfs_open_class_device_path(path);
106 if (class_dev == NULL) {
107 info("sysfs_open_class_device_path failed");
110 info("opened class_dev->name='%s'", class_dev->name);
112 if (udev.type == DEV_BLOCK || udev.type == DEV_CLASS)
113 udev.devt = get_devt(class_dev);
115 /* simulate node creation with test flag */
117 if (udev.type == DEV_NET || udev.devt) {
118 udev_rules_get_name(&rules, &udev, class_dev);
119 udev_add_device(&udev, class_dev);
121 info("only char and block devices with a dev-file are supported by this test program");
122 sysfs_close_class_device(class_dev);