diff options
author | Andrew Morton <akpm@digeo.com> | 2003-01-05 03:50:42 -0800 |
---|---|---|
committer | Linus Torvalds <torvalds@home.transmeta.com> | 2003-01-05 03:50:42 -0800 |
commit | 07ce6ac053470671cbc2b22d78e19d3fbeef32ad (patch) | |
tree | 8e1a0a80500b5ee4d7993da300e36add21c4f1cd /init | |
parent | 0d5f0a37701076e152323c221151874665c48852 (diff) | |
download | history-07ce6ac053470671cbc2b22d78e19d3fbeef32ad.tar.gz |
[PATCH] devfs mount-time readdir fix and cleanup
Patch from Adam J. Richter <adam@yggdrasil.com> and
Milton Miller <miltonm@bga.com>
There's some init-time code which is supposed to read a devfs directory by
expanding the bufer until the whole directory fits. But the logic is wrong
and it only works if the whole directory fits into 512 bytes.
So fix that up, and also clean up some coding in there, and rationalise the
duplicated definition of linux_dirent64.
Diffstat (limited to 'init')
-rw-r--r-- | init/do_mounts.c | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/init/do_mounts.c b/init/do_mounts.c index d660505010096a..316e29d758d3bf 100644 --- a/init/do_mounts.c +++ b/init/do_mounts.c @@ -13,6 +13,7 @@ #include <linux/suspend.h> #include <linux/root_dev.h> #include <linux/mount.h> +#include <linux/dirent.h> #include <linux/security.h> #include <linux/nfs_fs.h> @@ -324,22 +325,32 @@ static int __init mount_nfs_root(void) #endif #ifdef CONFIG_DEVFS_FS + +/* + * If the dir will fit in *buf, return its length. If it won't fit, return + * zero. Return -ve on error. + */ static int __init do_read_dir(int fd, void *buf, int len) { long bytes, n; char *p = buf; lseek(fd, 0, 0); - for (bytes = 0, p = buf; bytes < len; bytes += n, p+=n) { - n = sys_getdents64(fd, p, len - bytes); + for (bytes = 0; bytes < len; bytes += n) { + n = sys_getdents64(fd, p + bytes, len - bytes); if (n < 0) - return -1; + return n; if (n == 0) return bytes; } return 0; } +/* + * Try to read all of a directory. Returns the contents at *p, which + * is kmalloced memory. Returns the number of bytes read at *len. Returns + * NULL on error. + */ static void * __init read_dir(char *path, int *len) { int size; @@ -349,7 +360,7 @@ static void * __init read_dir(char *path, int *len) if (fd < 0) return NULL; - for (size = 1<<9; size < (1<<18); size <<= 1) { + for (size = 1 << 9; size <= (1 << MAX_ORDER); size <<= 1) { void *p = kmalloc(size, GFP_KERNEL); int n; if (!p) @@ -361,6 +372,8 @@ static void * __init read_dir(char *path, int *len) return p; } kfree(p); + if (n == -EINVAL) + continue; /* Try a larger buffer */ if (n < 0) break; } @@ -369,14 +382,6 @@ static void * __init read_dir(char *path, int *len) } #endif -struct linux_dirent64 { - u64 d_ino; - s64 d_off; - unsigned short d_reclen; - unsigned char d_type; - char d_name[0]; -}; - static int __init find_in_devfs(char *path, dev_t dev) { #ifdef CONFIG_DEVFS_FS |