4 * Return the "base device" given a particular device; this is used to
5 * assure that we only fsck one partition on a particular drive at any
6 * one time. Otherwise, the disk heads will be seeking all over the
7 * place. If the base device can not be determined, return NULL.
9 * The base_device() function returns an allocated string which must
12 * Written by Theodore Ts'o, <tytso@mit.edu>
14 * Copyright (C) 2000 Theodore Ts'o.
17 * This file may be redistributed under the terms of the GNU Public
29 #ifdef CONFIG_FEATURE_DEVFS
31 * Required for the uber-silly devfs /dev/ide/host1/bus2/target3/lun3
34 static const char *devfs_hier[] = {
35 "host", "bus", "target", "lun", 0
39 char *base_device(const char *device)
42 #ifdef CONFIG_FEATURE_DEVFS
43 const char **hier, *disk;
47 cp = str = bb_xstrdup(device);
49 /* Skip over /dev/; if it's not present, give up. */
50 if (strncmp(cp, "/dev/", 5) != 0)
54 #if 0 /* this is for old stuff no one uses anymore ? */
55 /* Skip over /dev/dsk/... */
56 if (strncmp(cp, "dsk/", 4) == 0)
61 * For md devices, we treat them all as if they were all
62 * on one disk, since we don't know how to parallelize them.
64 if (cp[0] == 'm' && cp[1] == 'd') {
69 /* Handle DAC 960 devices */
70 if (strncmp(cp, "rd/", 3) == 0) {
72 if (cp[0] != 'c' || cp[2] != 'd' ||
73 !isdigit(cp[1]) || !isdigit(cp[3]))
79 /* Now let's handle /dev/hd* and /dev/sd* devices.... */
80 if ((cp[0] == 'h' || cp[0] == 's') && (cp[1] == 'd')) {
82 /* If there's a single number after /dev/hd, skip it */
85 /* What follows must be an alpha char, or give up */
92 #ifdef CONFIG_FEATURE_DEVFS
93 /* Now let's handle devfs (ugh) names */
95 if (strncmp(cp, "ide/", 4) == 0)
97 if (strncmp(cp, "scsi/", 5) == 0)
102 * Now we proceed down the expected devfs hierarchy.
103 * i.e., .../host1/bus2/target3/lun4/...
104 * If we don't find the expected token, followed by
105 * some number of digits at each level, abort.
107 for (hier = devfs_hier; *hier; hier++) {
109 if (strncmp(cp, *hier, len) != 0)
112 while (*cp != '/' && *cp != 0) {
123 /* Now handle devfs /dev/disc or /dev/disk names */
125 if (strncmp(cp, "discs/", 6) == 0)
127 else if (strncmp(cp, "disks/", 6) == 0)
131 if (strncmp(cp, disk, 4) != 0)
134 while (*cp != '/' && *cp != 0) {