comparison toys/other/modinfo.c @ 933:a81921ce4930

Patch that assumes that the presence of the string ".ko" indicates use of a path to a module (*.ko.xz and similar included, but not supported).
author Isaac Dunham <idunham@lavabit.com>
date Sun, 23 Jun 2013 14:02:16 -0500
parents aff9fa1075eb
children d0ab54f62346
comparison
equal deleted inserted replaced
932:58b5263d63bf 933:a81921ce4930
36 if (TT.field) xprintf("%s", value); 36 if (TT.field) xprintf("%s", value);
37 else xprintf("%s:%*s%s", field, 15 - len, "", value); 37 else xprintf("%s:%*s%s", field, 15 - len, "", value);
38 xputc((toys.optflags & FLAG_0) ? 0 : '\n'); 38 xputc((toys.optflags & FLAG_0) ? 0 : '\n');
39 } 39 }
40 40
41 static void modinfo_file(struct dirtree *dir) 41 static int modinfo_file(struct dirtree *dir)
42 { 42 {
43 int fd, len, i; 43 int fd, len, i;
44 char *buf, *pos, *full_name; 44 char *buf, *pos, *full_name;
45 45
46 full_name = dirtree_path(dir, NULL); 46 full_name = dirtree_path(dir, NULL);
47 output_field("filename", full_name); 47 output_field("filename", full_name);
48 fd = xopen(full_name, O_RDONLY); 48 fd = xopen(full_name, O_RDONLY);
49 free(full_name); 49 free(full_name);
50 50
51 len = fdlength(fd); 51 len = fdlength(fd);
52 if (!(buf = mmap(0, len, PROT_READ, MAP_SHARED, fd, 0))) 52 if (!(buf = mmap(0, len, PROT_READ, MAP_SHARED, fd, 0))) {
53 perror_exit("mmap %s", full_name); 53 perror_msg("mmap %s", full_name);
54 return 1;
55 }
54 56
55 for (pos = buf; pos < buf+len; pos++) { 57 for (pos = buf; pos < buf+len; pos++) {
56 if (*pos) continue; 58 if (*pos) continue;
57 59
58 for (i = 0; i < sizeof(modinfo_tags) / sizeof(*modinfo_tags); i++) { 60 for (i = 0; i < sizeof(modinfo_tags) / sizeof(*modinfo_tags); i++) {
64 } 66 }
65 } 67 }
66 68
67 munmap(buf, len); 69 munmap(buf, len);
68 close(fd); 70 close(fd);
71 return 0;
69 } 72 }
70 73
71 static int check_module(struct dirtree *new) 74 static int check_module(struct dirtree *new)
72 { 75 {
73 if (S_ISREG(new->st.st_mode)) { 76 if (S_ISREG(new->st.st_mode)) {
97 100
98 if (uname(&uts) < 0) perror_exit("bad uname"); 101 if (uname(&uts) < 0) perror_exit("bad uname");
99 sprintf(toybuf, "/lib/modules/%s", uts.release); 102 sprintf(toybuf, "/lib/modules/%s", uts.release);
100 103
101 for(TT.mod = 0; TT.mod<toys.optc; TT.mod++) { 104 for(TT.mod = 0; TT.mod<toys.optc; TT.mod++) {
102 dirtree_read(toybuf, check_module); 105 if (strstr(toys.optargs[TT.mod], ".ko")) {
106 dirtree_read(toys.optargs[TT.mod], modinfo_file);
107 } else {
108 dirtree_read(toybuf, check_module);
109 }
103 } 110 }
104 } 111 }