Mercurial > hg > toybox
comparison toys/mdev.c @ 580:4877cff01b25
dirtree logic cleanup: switch DIRTREE_NORECURSE and DIRTREE_NOSAVE to DIRTREE_RECURSE and DIRTREE_SAVE.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sun, 20 May 2012 15:00:19 -0500 |
parents | 2a757e592ff7 |
children |
comparison
equal
deleted
inserted
replaced
579:6a7d64f51b1b | 580:4877cff01b25 |
---|---|
33 matching devies. | 33 matching devies. |
34 */ | 34 */ |
35 | 35 |
36 #include "toys.h" | 36 #include "toys.h" |
37 #include "lib/xregcomp.h" | 37 #include "lib/xregcomp.h" |
38 | |
39 // todo, open() block devices to trigger partition scanning. | |
38 | 40 |
39 // mknod in /dev based on a path like "/sys/block/hda/hda1" | 41 // mknod in /dev based on a path like "/sys/block/hda/hda1" |
40 static void make_device(char *path) | 42 static void make_device(char *path) |
41 { | 43 { |
42 char *device_name, *s, *temp; | 44 char *device_name, *s, *temp; |
178 | 180 |
179 static int callback(struct dirtree *node) | 181 static int callback(struct dirtree *node) |
180 { | 182 { |
181 // Entries in /sys/class/block aren't char devices, so skip 'em. (We'll | 183 // Entries in /sys/class/block aren't char devices, so skip 'em. (We'll |
182 // get block devices out of /sys/block.) | 184 // get block devices out of /sys/block.) |
183 if(!strcmp(node->name, "block")) return DIRTREE_NOSAVE|DIRTREE_NORECURSE; | 185 if(!strcmp(node->name, "block")) return 0; |
184 | 186 |
185 // Does this directory have a "dev" entry in it? | 187 // Does this directory have a "dev" entry in it? |
186 // This is path based because the hotplug callbacks are | 188 // This is path based because the hotplug callbacks are |
187 if (S_ISDIR(node->st.st_mode) || S_ISLNK(node->st.st_mode)) { | 189 if (S_ISDIR(node->st.st_mode) || S_ISLNK(node->st.st_mode)) { |
188 int len=4; | 190 int len=4; |
192 free(dev); | 194 free(dev); |
193 } | 195 } |
194 | 196 |
195 // Circa 2.6.25 the entries more than 2 deep are all either redundant | 197 // Circa 2.6.25 the entries more than 2 deep are all either redundant |
196 // (mouse#, event#) or unnamed (every usb_* entry is called "device"). | 198 // (mouse#, event#) or unnamed (every usb_* entry is called "device"). |
197 if (node->parent && node->parent->parent) | 199 |
198 return DIRTREE_NOSAVE|DIRTREE_NORECURSE; | 200 return (node->parent && node->parent->parent) ? 0 : DIRTREE_RECURSE; |
199 return DIRTREE_NOSAVE; | |
200 } | 201 } |
201 | 202 |
202 void mdev_main(void) | 203 void mdev_main(void) |
203 { | 204 { |
204 // Handle -s | 205 // Handle -s |