# HG changeset patch # User Rob Landley # Date 1210571547 18000 # Node ID b4077be6c7463b34ceb403950cd76403df362c94 # Parent 620a2eab6b8241ef67a1cbbda3bd331b35e628c5 Update mdev to work around the newest sysfs api breakage in the 2.6.25 kernel. (Yeah, I know sysfs hasn't actually got an API, but I like to pretend...) diff -r 620a2eab6b82 -r b4077be6c746 lib/dirtree.c --- a/lib/dirtree.c Sun May 04 19:44:39 2008 -0500 +++ b/lib/dirtree.c Mon May 12 00:52:27 2008 -0500 @@ -58,6 +58,7 @@ if (!(dir = opendir(path))) perror_msg("No %s", path); else for (;;) { + int norecurse = 0; struct dirent *entry = readdir(dir); if (!entry) { closedir(dir); @@ -74,8 +75,9 @@ *ddt = dirtree_add_node(path); if (!*ddt) continue; (*ddt)->parent = parent; - if (callback) callback(path, *ddt); - if (entry->d_type == DT_DIR) + (*ddt)->depth = parent ? parent->depth + 1 : 1; + if (callback) norecurse = callback(path, *ddt); + if (!norecurse && entry->d_type == DT_DIR) (*ddt)->child = dirtree_read(path, *ddt, callback); if (callback) free(*ddt); else ddt = &((*ddt)->next); diff -r 620a2eab6b82 -r b4077be6c746 lib/lib.c --- a/lib/lib.c Sun May 04 19:44:39 2008 -0500 +++ b/lib/lib.c Mon May 12 00:52:27 2008 -0500 @@ -326,6 +326,11 @@ return path; } +void xchdir(char *path) +{ + if (chdir(path)) error_exit("chdir '%s'"); +} + // Ensure entire path exists. // If mode != -1 set permissions on newly created dirs. // Requires that path string be writable (for temporary null terminators). diff -r 620a2eab6b82 -r b4077be6c746 lib/lib.h --- a/lib/lib.h Sun May 04 19:44:39 2008 -0500 +++ b/lib/lib.h Mon May 12 00:52:27 2008 -0500 @@ -36,6 +36,7 @@ struct dirtree { struct dirtree *next, *child, *parent; struct stat st; + int depth; char name[]; }; @@ -75,6 +76,7 @@ char *xgetcwd(void); void xstat(char *path, struct stat *st); char *xabspath(char *path); +void xchdir(char *path); void xmkpath(char *path, int mode); struct string_list *find_in_path(char *path, char *filename); void utoa_to_buf(unsigned n, char *buf, unsigned buflen); diff -r 620a2eab6b82 -r b4077be6c746 toys/mdev.c --- a/toys/mdev.c Sun May 04 19:44:39 2008 -0500 +++ b/toys/mdev.c Mon May 12 00:52:27 2008 -0500 @@ -2,7 +2,7 @@ * * mdev - Mini udev for busybox * - * Copyright 2005, 2007 Rob Landley + * Copyright 2005, 2008 Rob Landley * Copyright 2005 Frank Sorenson * * Not in SUSv3. @@ -11,7 +11,7 @@ config MDEV bool "mdev" - default n + default y help usage: mdev [-s] @@ -21,7 +21,7 @@ config MDEV_CONF bool "Configuration file for mdev" - default n + default y depends on MDEV help The mdev config file (/etc/mdev.conf) contains lines that look like: @@ -47,8 +47,7 @@ // Try to read major/minor string - temp = path+strlen(path); - strcpy(temp, "/dev"); + temp = strrchr(path, '/'); fd = open(path, O_RDONLY); *temp=0; temp++; @@ -172,49 +171,43 @@ if (CFG_MDEV_CONF) chown(temp, uid, gid); } -// Recursive search of /sys/block or /sys/class. path must be a writeable -// buffer of size PATH_MAX containing the directory string to start at. - -static void find_dev(char *path) +static int callback(char *path, struct dirtree *node) { - DIR *dir; - int len=strlen(path); - - if (!(dir = opendir(path))) - perror_exit("No %s",path); - - for (;;) { - struct dirent *entry = readdir(dir); + // Entries in /sys/class/block aren't char devices, so skip 'em. (We'll + // get block devices out of /sys/block.) + if(!strcmp(node->name, "block")) return 1; - if (!entry) break; - - // Skip "." and ".." (also skips hidden files, which is ok) - - if (entry->d_name[0]=='.') continue; - - if (entry->d_type == DT_DIR) { - snprintf(path+len, sizeof(toybuf)-len, "/%s", entry->d_name); - find_dev(path); - path[len] = 0; - } - - // If there's a dev entry, mknod it - - if (strcmp(entry->d_name, "dev")) make_device(path); + // Does this directory have a "dev" entry in it? + if (S_ISDIR(node->st.st_mode) || S_ISLNK(node->st.st_mode)) { + char *dest = path+strlen(path); + strcpy(dest, "/dev"); + if (!access(path, R_OK)) make_device(path); + *dest = 0; } - closedir(dir); + // Circa 2.6.25 the entries more than 2 deep are all either redundant + // (mouse#, event#) or unnamed (every usb_* entry is called "device"). + return node->depth>1; } void mdev_main(void) { + // Handle -s + if (toys.optflags) { - strcpy(toybuf, "/sys/block"); - find_dev(toybuf); + xchdir("/sys/class"); strcpy(toybuf, "/sys/class"); - find_dev(toybuf); - return; + dirtree_read(toybuf, NULL, callback); + strcpy(toybuf+5, "block"); + dirtree_read(toybuf, NULL, callback); } +// if (toys.optflags) { +// strcpy(toybuf, "/sys/block"); +// find_dev(toybuf); +// strcpy(toybuf, "/sys/class"); +// find_dev(toybuf); +// return; +// } // hotplug support goes here } diff -r 620a2eab6b82 -r b4077be6c746 toys/toysh.c --- a/toys/toysh.c Sun May 04 19:44:39 2008 -0500 +++ b/toys/toysh.c Mon May 12 00:52:27 2008 -0500 @@ -349,7 +349,7 @@ void cd_main(void) { char *dest = *toys.optargs ? *toys.optargs : getenv("HOME"); - if (chdir(dest)) error_exit("chdir %s",dest); + xchdir(dest); } void exit_main(void)