1 /*
2 * get_device.c
3 *
4 * Utility to get details of a given device
5 *
6 * Copyright (C) IBM Corp. 2003-2005
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 #include <stdio.h>
24 #include <stdlib.h>
25
26 #include "libsysfs.h"
27
print_usage(void)28 static void print_usage(void)
29 {
30 fprintf(stdout, "Usage: get_device [bus] [device]\n");
31 }
32
main(int argc,char * argv[])33 int main(int argc, char *argv[])
34 {
35 struct sysfs_device *device = NULL;
36
37 if (argc != 3) {
38 print_usage();
39 return 1;
40 }
41
42 device = sysfs_open_device(argv[1], argv[2]);
43 if (device == NULL) {
44 fprintf(stdout, "Device \"%s\" not found on bus \"%s\"\n",
45 argv[2], argv[1]);
46 return 1;
47 }
48 fprintf(stdout, "device is on bus %s, using driver %s\n",
49 device->bus, device->driver_name);
50
51 struct sysfs_device *parent = sysfs_get_device_parent(device);
52 if (parent)
53 fprintf(stdout, "parent is %s\n", parent->name);
54 else
55 fprintf(stdout, "no parent\n");
56 return 0;
57 }
58
59