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.
30 #include "libsysfs/sysfs/libsysfs.h"
32 #include "udev_sysfs.h"
33 #include "udev_utils.h"
34 #include "udev_version.h"
40 void log_message (int level, const char *format, ...)
44 va_start(args, format);
45 vprintf(format, args);
47 if (format[strlen(format)-1] != '\n')
52 int main(int argc, char *argv[], char *envp[])
54 struct sysfs_class_device *class_dev;
56 char path[SYSFS_PATH_MAX];
59 char *subsystem = NULL;
61 info("version %s", UDEV_VERSION);
63 if (argc < 2 || argc > 3) {
64 info("Usage: udevtest <devpath> [subsystem]");
68 /* initialize our configuration */
71 /* remove sysfs_path if given */
72 if (strncmp(argv[1], sysfs_path, strlen(sysfs_path)) == 0) {
73 devpath = &argv[1][strlen(sysfs_path)] ;
76 if (argv[1][0] != '/') {
77 /* prepend '/' if missing */
78 strfieldcpy(temp, "/");
79 strfieldcat(temp, argv[1]);
85 info("looking at '%s'", devpath);
87 /* initialize the naming deamon */
93 /* fill in values and test_run flag*/
94 udev_init_device(&udev, devpath, subsystem);
96 /* skip subsystems without "dev", but handle net devices */
97 if (udev.type != 'n' && subsystem_expect_no_dev(udev.subsystem)) {
98 info("don't care about '%s' devices", udev.subsystem);
102 /* open the device */
103 snprintf(path, SYSFS_PATH_MAX, "%s%s", sysfs_path, udev.devpath);
104 class_dev = sysfs_open_class_device_path(path);
105 if (class_dev == NULL) {
106 info("sysfs_open_class_device_path failed");
110 info("opened class_dev->name='%s'", class_dev->name);
112 /* simulate node creation with test flag */
114 udev_add_device(&udev, class_dev);
116 sysfs_close_class_device(class_dev);