Mercurial > hg > toybox
comparison toys/mdev.c @ 156:1e8f4b05cb65
Remove trailing whitespace (thanks to Charlie Shepherd), and a couple comment
tweaks.
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 15 Nov 2007 18:30:30 -0600 |
parents | ce6956dfc0cf |
children | 25447caf1b4b |
comparison
equal
deleted
inserted
replaced
155:6c7836dbc16e | 156:1e8f4b05cb65 |
---|---|
1 /* vi:set ts=4: | 1 /* vi:set ts=4: |
2 * | 2 * |
3 * mdev - Mini udev for busybox | 3 * mdev - Mini udev for busybox |
4 * | 4 * |
5 * Copyright 2005 Rob Landley <rob@landley.net> | 5 * Copyright 2005 Rob Landley <rob@landley.net> |
6 * Copyright 2005 Frank Sorenson <frank@tuxrocks.com> | 6 * Copyright 2005 Frank Sorenson <frank@tuxrocks.com> |
7 */ | 7 */ |
8 | 8 |
9 #include "toys.h" | 9 #include "toys.h" |
27 temp++; | 27 temp++; |
28 len = read(fd, temp, 64); | 28 len = read(fd, temp, 64); |
29 close(fd); | 29 close(fd); |
30 if (len<1) return; | 30 if (len<1) return; |
31 temp[len] = 0; | 31 temp[len] = 0; |
32 | 32 |
33 // Determine device name, type, major and minor | 33 // Determine device name, type, major and minor |
34 | 34 |
35 device_name = strrchr(path, '/') + 1; | 35 device_name = strrchr(path, '/') + 1; |
36 type = path[5]=='c' ? S_IFCHR : S_IFBLK; | 36 type = path[5]=='c' ? S_IFCHR : S_IFBLK; |
37 major = minor = 0; | 37 major = minor = 0; |
38 sscanf(temp, "%u:%u", &major, &minor); | 38 sscanf(temp, "%u:%u", &major, &minor); |
39 | 39 |
40 // If we have a config file, look up permissions for this device | 40 // If we have a config file, look up permissions for this device |
41 | 41 |
42 if (CFG_MDEV_CONF) { | 42 if (CFG_MDEV_CONF) { |
43 char *conf, *pos, *end; | 43 char *conf, *pos, *end; |
44 | 44 |
45 // mmap the config file | 45 // mmap the config file |
46 if (-1!=(fd = open("/etc/mdev.conf", O_RDONLY))) { | 46 if (-1!=(fd = open("/etc/mdev.conf", O_RDONLY))) { |
51 | 51 |
52 // Loop through lines in mmaped file | 52 // Loop through lines in mmaped file |
53 for (pos = conf; pos-conf<len;) { | 53 for (pos = conf; pos-conf<len;) { |
54 int field; | 54 int field; |
55 char *end2; | 55 char *end2; |
56 | 56 |
57 line++; | 57 line++; |
58 // find end of this line | 58 // find end of this line |
59 for(end = pos; end-conf<len && *end!='\n'; end++); | 59 for(end = pos; end-conf<len && *end!='\n'; end++); |
60 | 60 |
61 // Three fields: regex, uid:gid, mode | 61 // Three fields: regex, uid:gid, mode |
76 | 76 |
77 // Is this it? | 77 // Is this it? |
78 xregcomp(&match, regex, REG_EXTENDED); | 78 xregcomp(&match, regex, REG_EXTENDED); |
79 result=regexec(&match, device_name, 1, &off, 0); | 79 result=regexec(&match, device_name, 1, &off, 0); |
80 regfree(&match); | 80 regfree(&match); |
81 | 81 |
82 // If not this device, skip rest of line | 82 // If not this device, skip rest of line |
83 if (result || off.rm_so | 83 if (result || off.rm_so |
84 || off.rm_eo!=strlen(device_name)) | 84 || off.rm_eo!=strlen(device_name)) |
85 goto end_line; | 85 goto end_line; |
86 | 86 |
157 if (!(dir = opendir(path))) | 157 if (!(dir = opendir(path))) |
158 perror_exit("No %s",path); | 158 perror_exit("No %s",path); |
159 | 159 |
160 for (;;) { | 160 for (;;) { |
161 struct dirent *entry = readdir(dir); | 161 struct dirent *entry = readdir(dir); |
162 | 162 |
163 if (!entry) break; | 163 if (!entry) break; |
164 | 164 |
165 // Skip "." and ".." (also skips hidden files, which is ok) | 165 // Skip "." and ".." (also skips hidden files, which is ok) |
166 | 166 |
167 if (entry->d_name[0]=='.') continue; | 167 if (entry->d_name[0]=='.') continue; |
169 if (entry->d_type == DT_DIR) { | 169 if (entry->d_type == DT_DIR) { |
170 snprintf(path+len, sizeof(toybuf)-len, "/%s", entry->d_name); | 170 snprintf(path+len, sizeof(toybuf)-len, "/%s", entry->d_name); |
171 find_dev(path); | 171 find_dev(path); |
172 path[len] = 0; | 172 path[len] = 0; |
173 } | 173 } |
174 | 174 |
175 // If there's a dev entry, mknod it | 175 // If there's a dev entry, mknod it |
176 | 176 |
177 if (strcmp(entry->d_name, "dev")) make_device(path); | 177 if (strcmp(entry->d_name, "dev")) make_device(path); |
178 } | 178 } |
179 | 179 |
180 closedir(dir); | 180 closedir(dir); |
181 } | 181 } |
182 | 182 |
183 int mdev_main(int argc, char *argv[]) | 183 int mdev_main(int argc, char *argv[]) |
184 { | 184 { |
186 strcpy(toybuf, "/sys/block"); | 186 strcpy(toybuf, "/sys/block"); |
187 find_dev(toybuf); | 187 find_dev(toybuf); |
188 strcpy(toybuf, "/sys/class"); | 188 strcpy(toybuf, "/sys/class"); |
189 find_dev(toybuf); | 189 find_dev(toybuf); |
190 return 0; | 190 return 0; |
191 } | 191 } |
192 | 192 |
193 // hotplug support goes here | 193 // hotplug support goes here |
194 | 194 |
195 return 0; | 195 return 0; |
196 } | 196 } |