/*****************************************************************************/ /* * partpmodules.c -- pcimodules like utility for parallel port devices * * Written by Adam J. Richter. * * Copyright (C) 2000 Yggdrasil Computing, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * */ /*****************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include #define _GNU_SOURCE #include #include #define OPT_STRING "c:d:h" static struct option long_options[] = { {"check", required_argument, NULL, 'c'}, {"device", required_argument, NULL, 'd'}, {"help", no_argument, NULL, 'h'}, { 0, 0, NULL, 0} }; #define MODDIR "/lib/modules" #define PARPTMAP "modules.parptmap" #define LINELENGTH 8000 static void match_id_string(char *id) { struct utsname utsname; char filename[MAXPATHLEN]; FILE *parptmap_file; char line[LINELENGTH]; unsigned int driver_data; char name[LINELENGTH]; regex_t compiled; char regexp_string[200]; if (uname(&utsname) < 0) { perror("uname"); exit(1); } sprintf(filename, "%s/%s/%s", MODDIR, utsname.release, PARPTMAP); if ((parptmap_file = fopen(filename, "r")) == NULL) { perror(filename); exit(1); } while(fgets(line, LINELENGTH, parptmap_file) != NULL) { if (line[0] == '#') continue; if (sscanf(line, "%s %s\n", name, regexp_string) != 2) { fprintf (stderr, "modules.parptmap unparsable line: %s.\n", line); continue; } regcomp(&compiled, regexp_string, 0); if (regexec(&compiled, id, 0, NULL, 0) == 0) { printf("%s\n", name); } } fclose(parptmap_file); } int main (int argc, char **argv) { int opt_index = 0; int opt; char *device = NULL; match_id_string(argv[1]); return 0; while ((opt = getopt_long(argc, argv, OPT_STRING, long_options, &opt_index)) != -1) { switch(opt) { case 'd': device = optarg; break; case 'h': printf ("Usage: usbmodules [--help] [--device //proc/bus/usb/NNN/NNN] [--check module]\n" " Lists kernel modules corresponding to USB devices currently plugged\n" " into the computer.\n"); return 0; default: fprintf(stderr, "Unknown argument character \"%c\".\n", opt); return 1; } } if (device == NULL) { fprintf (stderr, "You must specify a device with something like:\n" "\tusbmodules --device /proc/bus/usb/001/009\n"); return 1; } /* STUB: do it. */ return 0; }