Commit 51924607 authored by Alexander Viro's avatar Alexander Viro Committed by Christoph Hellwig

[PATCH] removal of root_dev_names[]

 - name_to_kdev_t() turned into name_to_dev_t(), callers updated.
 - table of names is gone, we use driverfs instead.

 - root name is converted to dev_t only at prepare_namespace() time - we
   use to do it in setup and we need it after driver initialization.  So
   setup only stores the root name and leaves the work to
   prepare_namespace().

 - disk names for rd and cm206 changed to match the old behaviour of
   root= parser: ramdisks have ram<n> in ->disk_name now (instead of
   rd<n>) and cm206 - cm206cd (instead of cm206).
parent 82b3980b
...@@ -432,7 +432,7 @@ static int __init rd_init (void) ...@@ -432,7 +432,7 @@ static int __init rd_init (void)
disk->first_minor = i; disk->first_minor = i;
disk->fops = &rd_bd_op; disk->fops = &rd_bd_op;
disk->queue = &rd_queue; disk->queue = &rd_queue;
sprintf(disk->disk_name, "rd%d", i); sprintf(disk->disk_name, "ram%d", i);
set_capacity(disk, rd_size * 2); set_capacity(disk, rd_size * 2);
} }
devfs_handle = devfs_mk_dir (NULL, "rd", NULL); devfs_handle = devfs_mk_dir (NULL, "rd", NULL);
......
...@@ -1497,7 +1497,7 @@ int __init cm206_init(void) ...@@ -1497,7 +1497,7 @@ int __init cm206_init(void)
goto out_disk; goto out_disk;
disk->major = MAJOR_NR; disk->major = MAJOR_NR;
disk->first_minor = 0; disk->first_minor = 0;
sprintf(disk->disk_name, "cm206"); sprintf(disk->disk_name, "cm206cd");
disk->fops = &cm206_bdops; disk->fops = &cm206_bdops;
disk->flags = GENHD_FL_CD; disk->flags = GENHD_FL_CD;
cm206_gendisk = disk; cm206_gendisk = disk;
......
...@@ -3287,13 +3287,13 @@ static int __init md_setup(char *str) ...@@ -3287,13 +3287,13 @@ static int __init md_setup(char *str)
return 1; return 1;
} }
extern kdev_t name_to_kdev_t(char *line) __init; extern dev_t name_to_dev_t(char *line) __init;
void __init md_setup_drive(void) void __init md_setup_drive(void)
{ {
int minor, i; int minor, i;
kdev_t dev; dev_t dev;
mddev_t*mddev; mddev_t*mddev;
kdev_t devices[MD_SB_DISKS+1]; dev_t devices[MD_SB_DISKS+1];
for (minor = 0; minor < MAX_MD_DEVS; minor++) { for (minor = 0; minor < MAX_MD_DEVS; minor++) {
int err = 0; int err = 0;
...@@ -3312,16 +3312,17 @@ void __init md_setup_drive(void) ...@@ -3312,16 +3312,17 @@ void __init md_setup_drive(void)
if (p) if (p)
*p++ = 0; *p++ = 0;
dev = name_to_kdev_t(devname); dev = name_to_dev_t(devname);
handle = devfs_get_handle(NULL, devname, major(dev), minor(dev), handle = devfs_get_handle(NULL, devname,
DEVFS_SPECIAL_BLK, 1); MAJOR(dev), MINOR(dev),
DEVFS_SPECIAL_BLK, 1);
if (handle != 0) { if (handle != 0) {
unsigned major, minor; unsigned major, minor;
devfs_get_maj_min(handle, &major, &minor); devfs_get_maj_min(handle, &major, &minor);
dev = mk_kdev(major, minor); dev = MKDEV(major, minor);
devfs_put(handle); devfs_put(handle);
} }
if (kdev_none(dev)) { if (!dev) {
printk(KERN_WARNING "md: Unknown device name: %s\n", devname); printk(KERN_WARNING "md: Unknown device name: %s\n", devname);
break; break;
} }
...@@ -3331,7 +3332,7 @@ void __init md_setup_drive(void) ...@@ -3331,7 +3332,7 @@ void __init md_setup_drive(void)
devname = p; devname = p;
} }
devices[i] = to_kdev_t(0); devices[i] = 0;
if (!md_setup_args.device_set[minor]) if (!md_setup_args.device_set[minor])
continue; continue;
...@@ -3375,13 +3376,13 @@ void __init md_setup_drive(void) ...@@ -3375,13 +3376,13 @@ void __init md_setup_drive(void)
err = set_array_info(mddev, &ainfo); err = set_array_info(mddev, &ainfo);
for (i = 0; !err && i <= MD_SB_DISKS; i++) { for (i = 0; !err && i <= MD_SB_DISKS; i++) {
dev = devices[i]; dev = devices[i];
if (kdev_none(dev)) if (!dev)
break; break;
dinfo.number = i; dinfo.number = i;
dinfo.raid_disk = i; dinfo.raid_disk = i;
dinfo.state = (1<<MD_DISK_ACTIVE)|(1<<MD_DISK_SYNC); dinfo.state = (1<<MD_DISK_ACTIVE)|(1<<MD_DISK_SYNC);
dinfo.major = major(dev); dinfo.major = MAJOR(dev);
dinfo.minor = minor(dev); dinfo.minor = MINOR(dev);
mddev->raid_disks++; mddev->raid_disks++;
err = add_new_disk (mddev, &dinfo); err = add_new_disk (mddev, &dinfo);
} }
...@@ -3389,10 +3390,10 @@ void __init md_setup_drive(void) ...@@ -3389,10 +3390,10 @@ void __init md_setup_drive(void)
/* persistent */ /* persistent */
for (i = 0; i <= MD_SB_DISKS; i++) { for (i = 0; i <= MD_SB_DISKS; i++) {
dev = devices[i]; dev = devices[i];
if (kdev_none(dev)) if (!dev)
break; break;
dinfo.major = major(dev); dinfo.major = MAJOR(dev);
dinfo.minor = minor(dev); dinfo.minor = MINOR(dev);
add_new_disk (mddev, &dinfo); add_new_disk (mddev, &dinfo);
} }
} }
......
...@@ -1044,7 +1044,7 @@ static int __init calc_erase_regions(struct mtd_erase_region_info *info, size_t ...@@ -1044,7 +1044,7 @@ static int __init calc_erase_regions(struct mtd_erase_region_info *info, size_t
} }
extern kdev_t name_to_kdev_t(char *line) __init; extern dev_t name_to_dev_t(char *line) __init;
/* Startup */ /* Startup */
static int __init init_blkmtd(void) static int __init init_blkmtd(void)
...@@ -1059,7 +1059,7 @@ static int __init init_blkmtd(void) ...@@ -1059,7 +1059,7 @@ static int __init init_blkmtd(void)
loff_t size; loff_t size;
int readonly = 0; int readonly = 0;
int erase_size = CONFIG_MTD_BLKDEV_ERASESIZE; int erase_size = CONFIG_MTD_BLKDEV_ERASESIZE;
kdev_t rdev; dev_t rdev;
struct block_device *bdev; struct block_device *bdev;
int err; int err;
int mode; int mode;
...@@ -1107,17 +1107,17 @@ static int __init init_blkmtd(void) ...@@ -1107,17 +1107,17 @@ static int __init init_blkmtd(void)
filp_close(file, NULL); filp_close(file, NULL);
return 1; return 1;
} }
rdev = inode->i_rdev; rdev = inode->i_bdev->bd_dev;
filp_close(file, NULL); filp_close(file, NULL);
#else #else
rdev = name_to_kdev_t(device); rdev = name_to_dev_t(device);
#endif #endif
maj = major(rdev); maj = MAJOR(rdev);
min = minor(rdev); min = MINOR(rdev);
DEBUG(1, "blkmtd: found a block device major = %d, minor = %d\n", maj, min); DEBUG(1, "blkmtd: found a block device major = %d, minor = %d\n", maj, min);
if(kdev_none(rdev)) { if(!rdev) {
printk("blkmtd: bad block device: `%s'\n", device); printk("blkmtd: bad block device: `%s'\n", device);
return 1; return 1;
} }
......
...@@ -27,6 +27,7 @@ extern int get_filesystem_list(char * buf); ...@@ -27,6 +27,7 @@ extern int get_filesystem_list(char * buf);
extern asmlinkage long sys_mount(char *dev_name, char *dir_name, char *type, extern asmlinkage long sys_mount(char *dev_name, char *dir_name, char *type,
unsigned long flags, void *data); unsigned long flags, void *data);
extern asmlinkage long sys_mkdir(const char *name, int mode); extern asmlinkage long sys_mkdir(const char *name, int mode);
extern asmlinkage long sys_rmdir(const char *name);
extern asmlinkage long sys_chdir(const char *name); extern asmlinkage long sys_chdir(const char *name);
extern asmlinkage long sys_fchdir(int fd); extern asmlinkage long sys_fchdir(int fd);
extern asmlinkage long sys_chroot(const char *name); extern asmlinkage long sys_chroot(const char *name);
...@@ -55,6 +56,7 @@ int __initdata rd_doload; /* 1 = load RAM disk, 0 = don't load */ ...@@ -55,6 +56,7 @@ int __initdata rd_doload; /* 1 = load RAM disk, 0 = don't load */
int root_mountflags = MS_RDONLY | MS_VERBOSE; int root_mountflags = MS_RDONLY | MS_VERBOSE;
static char root_device_name[64]; static char root_device_name[64];
static char saved_root_name[64];
/* this is initialized in init/main.c */ /* this is initialized in init/main.c */
dev_t ROOT_DEV; dev_t ROOT_DEV;
...@@ -87,169 +89,135 @@ static int __init readwrite(char *str) ...@@ -87,169 +89,135 @@ static int __init readwrite(char *str)
__setup("ro", readonly); __setup("ro", readonly);
__setup("rw", readwrite); __setup("rw", readwrite);
static struct dev_name_struct { static __init dev_t try_name(char *name, int part)
const char *name; {
const int num; char path[64];
} root_dev_names[] __initdata = { char buf[32];
{ "nfs", 0x00ff }, int range;
{ "hda", 0x0300 }, dev_t res;
{ "hdb", 0x0340 }, char *s;
{ "loop", 0x0700 }, int len;
{ "hdc", 0x1600 }, int fd;
{ "hdd", 0x1640 },
{ "hde", 0x2100 }, /* read device number from .../dev */
{ "hdf", 0x2140 },
{ "hdg", 0x2200 }, sprintf(path, "/sys/bus/block/devices/%s/dev", name);
{ "hdh", 0x2240 }, fd = open(path, 0, 0);
{ "hdi", 0x3800 }, if (fd < 0)
{ "hdj", 0x3840 }, goto fail;
{ "hdk", 0x3900 }, len = read(fd, buf, 32);
{ "hdl", 0x3940 }, close(fd);
{ "hdm", 0x5800 }, if (len <= 0 || len == 32 || buf[len - 1] != '\n')
{ "hdn", 0x5840 }, goto fail;
{ "hdo", 0x5900 }, buf[len - 1] = '\0';
{ "hdp", 0x5940 }, res = (dev_t) simple_strtoul(buf, &s, 16);
{ "hdq", 0x5A00 }, if (*s)
{ "hdr", 0x5A40 }, goto fail;
{ "hds", 0x5B00 },
{ "hdt", 0x5B40 }, /* if it's there and we are not looking for a partition - that's it */
{ "sda", 0x0800 }, if (!part)
{ "sdb", 0x0810 }, return res;
{ "sdc", 0x0820 },
{ "sdd", 0x0830 }, /* otherwise read range from .../range */
{ "sde", 0x0840 }, sprintf(path, "/sys/bus/block/devices/%s/range", name);
{ "sdf", 0x0850 }, fd = open(path, 0, 0);
{ "sdg", 0x0860 }, if (fd < 0)
{ "sdh", 0x0870 }, goto fail;
{ "sdi", 0x0880 }, len = read(fd, buf, 32);
{ "sdj", 0x0890 }, close(fd);
{ "sdk", 0x08a0 }, if (len <= 0 || len == 32 || buf[len - 1] != '\n')
{ "sdl", 0x08b0 }, goto fail;
{ "sdm", 0x08c0 }, buf[len - 1] = '\0';
{ "sdn", 0x08d0 }, range = simple_strtoul(buf, &s, 10);
{ "sdo", 0x08e0 }, if (*s)
{ "sdp", 0x08f0 }, goto fail;
{ "ada", 0x1c00 },
{ "adb", 0x1c10 }, /* if partition is within range - we got it */
{ "adc", 0x1c20 }, if (part < range)
{ "add", 0x1c30 }, return res + part;
{ "ade", 0x1c40 }, fail:
{ "fd", 0x0200 }, return (dev_t) 0;
{ "md", 0x0900 }, }
{ "xda", 0x0d00 },
{ "xdb", 0x0d40 }, /*
{ "ram", 0x0100 }, * Convert a name into device number. We accept the following variants:
{ "scd", 0x0b00 }, *
{ "mcd", 0x1700 }, * 1) device number in hexadecimal represents itself
{ "cdu535", 0x1800 }, * 2) /dev/nfs represents Root_NFS (0xff)
{ "sonycd", 0x1800 }, * 3) /dev/<disk_name> represents the device number of disk
{ "aztcd", 0x1d00 }, * 4) /dev/<disk_name><decimal> represents the device number
{ "cm206cd", 0x2000 }, * of partition - device number of disk plus the partition number
{ "gscd", 0x1000 }, * 5) /dev/<disk_name>p<decimal> - same as the above, that form is
{ "sbpcd", 0x1900 }, * used when disk name of partitioned disk ends on a digit.
{ "eda", 0x2400 }, *
{ "edb", 0x2440 }, * If name doesn't have fall into the categories above, we return 0.
{ "pda", 0x2d00 }, * Driverfs is used to check if something is a disk name - it has
{ "pdb", 0x2d10 }, * all known disks under bus/block/devices. If the disk name
{ "pdc", 0x2d20 }, * contains slashes, name of driverfs node has them replaced with
{ "pdd", 0x2d30 }, * dots. try_name() does the actual checks, assuming that driverfs
{ "pcd", 0x2e00 }, * is mounted on rootfs /sys.
{ "pf", 0x2f00 }, */
{ "apblock", APBLOCK_MAJOR << 8},
{ "ddv", DDV_MAJOR << 8}, __init dev_t name_to_dev_t(char *name)
{ "jsfd", JSFD_MAJOR << 8}, {
#if defined(CONFIG_ARCH_S390) char s[32];
{ "dasda", (DASD_MAJOR << MINORBITS) }, char *p;
{ "dasdb", (DASD_MAJOR << MINORBITS) + (1 << 2) }, dev_t res = 0;
{ "dasdc", (DASD_MAJOR << MINORBITS) + (2 << 2) }, int part;
{ "dasdd", (DASD_MAJOR << MINORBITS) + (3 << 2) },
{ "dasde", (DASD_MAJOR << MINORBITS) + (4 << 2) }, sys_mkdir("/sys", 0700);
{ "dasdf", (DASD_MAJOR << MINORBITS) + (5 << 2) }, if (sys_mount("driverfs", "/sys", "driverfs", 0, NULL) < 0)
{ "dasdg", (DASD_MAJOR << MINORBITS) + (6 << 2) }, goto out;
{ "dasdh", (DASD_MAJOR << MINORBITS) + (7 << 2) },
#endif if (strncmp(name, "/dev/", 5) != 0) {
#if defined(CONFIG_BLK_CPQ_DA) || defined(CONFIG_BLK_CPQ_DA_MODULE) res = (dev_t) simple_strtoul(name, &p, 16);
{ "ida/c0d0p",0x4800 }, if (*p)
{ "ida/c0d1p",0x4810 }, goto fail;
{ "ida/c0d2p",0x4820 }, goto done;
{ "ida/c0d3p",0x4830 },
{ "ida/c0d4p",0x4840 },
{ "ida/c0d5p",0x4850 },
{ "ida/c0d6p",0x4860 },
{ "ida/c0d7p",0x4870 },
{ "ida/c0d8p",0x4880 },
{ "ida/c0d9p",0x4890 },
{ "ida/c0d10p",0x48A0 },
{ "ida/c0d11p",0x48B0 },
{ "ida/c0d12p",0x48C0 },
{ "ida/c0d13p",0x48D0 },
{ "ida/c0d14p",0x48E0 },
{ "ida/c0d15p",0x48F0 },
#endif
#if defined(CONFIG_BLK_CPQ_CISS_DA) || defined(CONFIG_BLK_CPQ_CISS_DA_MODULE)
{ "cciss/c0d0p",0x6800 },
{ "cciss/c0d1p",0x6810 },
{ "cciss/c0d2p",0x6820 },
{ "cciss/c0d3p",0x6830 },
{ "cciss/c0d4p",0x6840 },
{ "cciss/c0d5p",0x6850 },
{ "cciss/c0d6p",0x6860 },
{ "cciss/c0d7p",0x6870 },
{ "cciss/c0d8p",0x6880 },
{ "cciss/c0d9p",0x6890 },
{ "cciss/c0d10p",0x68A0 },
{ "cciss/c0d11p",0x68B0 },
{ "cciss/c0d12p",0x68C0 },
{ "cciss/c0d13p",0x68D0 },
{ "cciss/c0d14p",0x68E0 },
{ "cciss/c0d15p",0x68F0 },
#endif
{ "nftla", 0x5d00 },
{ "nftlb", 0x5d10 },
{ "nftlc", 0x5d20 },
{ "nftld", 0x5d30 },
{ "ftla", 0x2c00 },
{ "ftlb", 0x2c08 },
{ "ftlc", 0x2c10 },
{ "ftld", 0x2c18 },
{ "mtdblock", 0x1f00 },
{ NULL, 0 }
};
kdev_t __init name_to_kdev_t(char *line)
{
int base = 0;
if (strncmp(line,"/dev/",5) == 0) {
struct dev_name_struct *dev = root_dev_names;
line += 5;
do {
int len = strlen(dev->name);
if (strncmp(line,dev->name,len) == 0) {
line += len;
base = dev->num;
break;
}
dev++;
} while (dev->name);
} }
return to_kdev_t(base + simple_strtoul(line,NULL,base?10:16)); name += 5;
res = Root_NFS;
if (strcmp(name, "nfs") == 0)
goto done;
if (strlen(name) > 31)
goto fail;
strcpy(s, name);
for (p = s; *p; p++)
if (*p == '/')
*p = '.';
res = try_name(s, 0);
if (res)
goto done;
while (p > s && isdigit(p[-1]))
p--;
if (p == s || !*p || *p == '0')
goto fail;
part = simple_strtoul(p, NULL, 10);
*p = '\0';
res = try_name(s, part);
if (res)
goto done;
if (p < s + 2 || !isdigit(p[-2]) || p[-1] != 'p')
goto fail;
p[-1] = '\0';
res = try_name(s, part);
done:
sys_umount("/sys", 0);
out:
sys_rmdir("/sys");
return res;
fail:
res = (dev_t) 0;
goto done;
} }
static int __init root_dev_setup(char *line) static int __init root_dev_setup(char *line)
{ {
int i; strncpy(saved_root_name, line, 64);
char ch; saved_root_name[63] = '\0';
ROOT_DEV = kdev_t_to_nr(name_to_kdev_t(line));
memset (root_device_name, 0, sizeof root_device_name);
if (strncmp (line, "/dev/", 5) == 0) line += 5;
for (i = 0; i < sizeof root_device_name - 1; ++i)
{
ch = line[i];
if ( isspace (ch) || (ch == ',') || (ch == '\0') ) break;
root_device_name[i] = ch;
}
return 1; return 1;
} }
...@@ -768,6 +736,13 @@ static int __init initrd_load(void) ...@@ -768,6 +736,13 @@ static int __init initrd_load(void)
void prepare_namespace(void) void prepare_namespace(void)
{ {
int is_floppy = MAJOR(ROOT_DEV) == FLOPPY_MAJOR; int is_floppy = MAJOR(ROOT_DEV) == FLOPPY_MAJOR;
if (saved_root_name[0]) {
char *p = saved_root_name;
ROOT_DEV = name_to_dev_t(p);
if (strncmp(p, "/dev/", 5) == 0)
p += 5;
strcpy(root_device_name, p);
}
#ifdef CONFIG_BLK_DEV_INITRD #ifdef CONFIG_BLK_DEV_INITRD
if (!initrd_start) if (!initrd_start)
mount_initrd = 0; mount_initrd = 0;
......
...@@ -1047,7 +1047,7 @@ static int bdev_write_page(struct block_device *bdev, long pos, void *buf) ...@@ -1047,7 +1047,7 @@ static int bdev_write_page(struct block_device *bdev, long pos, void *buf)
return 0; return 0;
} }
extern kdev_t __init name_to_kdev_t(const char *line); extern dev_t __init name_to_dev_t(const char *line);
static int __read_suspend_image(struct block_device *bdev, union diskpage *cur, int noresume) static int __read_suspend_image(struct block_device *bdev, union diskpage *cur, int noresume)
{ {
...@@ -1143,7 +1143,7 @@ static int read_suspend_image(const char * specialfile, int noresume) ...@@ -1143,7 +1143,7 @@ static int read_suspend_image(const char * specialfile, int noresume)
unsigned long scratch_page = 0; unsigned long scratch_page = 0;
int error; int error;
resume_device = name_to_kdev_t(specialfile); resume_device = to_kdev_t(name_to_dev_t(specialfile));
scratch_page = get_zeroed_page(GFP_ATOMIC); scratch_page = get_zeroed_page(GFP_ATOMIC);
cur = (void *) scratch_page; cur = (void *) scratch_page;
if (cur) { if (cur) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment