diff options
author | Kay Sievers <kay.sievers@vrfy.org> | 2007-05-21 16:08:01 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2008-01-24 23:40:36 -0500 |
commit | edfaa7c36574f1bf09c65ad602412db9da5f96bf (patch) | |
tree | d591b80ff9229e4845e41d68e2f4c5aadb017027 /init/do_mounts.c | |
parent | 09f82ea92822a7bbb7e816508abbda47ed54a77f (diff) |
Driver core: convert block from raw kobjects to core devices
This moves the block devices to /sys/class/block. It will create a
flat list of all block devices, with the disks and partitions in one
directory. For compatibility /sys/block is created and contains symlinks
to the disks.
/sys/class/block
|-- sda -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda
|-- sda1 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1
|-- sda10 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda10
|-- sda5 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5
|-- sda6 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda6
|-- sda7 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda7
|-- sda8 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda8
|-- sda9 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda9
`-- sr0 -> ../../devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0/block/sr0
/sys/block/
|-- sda -> ../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda
`-- sr0 -> ../devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0/block/sr0
Signed-off-by: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'init/do_mounts.c')
-rw-r--r-- | init/do_mounts.c | 108 |
1 files changed, 8 insertions, 100 deletions
diff --git a/init/do_mounts.c b/init/do_mounts.c index 4efa1e5385e3..2ae5b8462399 100644 --- a/init/do_mounts.c +++ b/init/do_mounts.c | |||
@@ -55,69 +55,6 @@ static int __init readwrite(char *str) | |||
55 | __setup("ro", readonly); | 55 | __setup("ro", readonly); |
56 | __setup("rw", readwrite); | 56 | __setup("rw", readwrite); |
57 | 57 | ||
58 | static dev_t try_name(char *name, int part) | ||
59 | { | ||
60 | char path[64]; | ||
61 | char buf[32]; | ||
62 | int range; | ||
63 | dev_t res; | ||
64 | char *s; | ||
65 | int len; | ||
66 | int fd; | ||
67 | unsigned int maj, min; | ||
68 | |||
69 | /* read device number from .../dev */ | ||
70 | |||
71 | sprintf(path, "/sys/block/%s/dev", name); | ||
72 | fd = sys_open(path, 0, 0); | ||
73 | if (fd < 0) | ||
74 | goto fail; | ||
75 | len = sys_read(fd, buf, 32); | ||
76 | sys_close(fd); | ||
77 | if (len <= 0 || len == 32 || buf[len - 1] != '\n') | ||
78 | goto fail; | ||
79 | buf[len - 1] = '\0'; | ||
80 | if (sscanf(buf, "%u:%u", &maj, &min) == 2) { | ||
81 | /* | ||
82 | * Try the %u:%u format -- see print_dev_t() | ||
83 | */ | ||
84 | res = MKDEV(maj, min); | ||
85 | if (maj != MAJOR(res) || min != MINOR(res)) | ||
86 | goto fail; | ||
87 | } else { | ||
88 | /* | ||
89 | * Nope. Try old-style "0321" | ||
90 | */ | ||
91 | res = new_decode_dev(simple_strtoul(buf, &s, 16)); | ||
92 | if (*s) | ||
93 | goto fail; | ||
94 | } | ||
95 | |||
96 | /* if it's there and we are not looking for a partition - that's it */ | ||
97 | if (!part) | ||
98 | return res; | ||
99 | |||
100 | /* otherwise read range from .../range */ | ||
101 | sprintf(path, "/sys/block/%s/range", name); | ||
102 | fd = sys_open(path, 0, 0); | ||
103 | if (fd < 0) | ||
104 | goto fail; | ||
105 | len = sys_read(fd, buf, 32); | ||
106 | sys_close(fd); | ||
107 | if (len <= 0 || len == 32 || buf[len - 1] != '\n') | ||
108 | goto fail; | ||
109 | buf[len - 1] = '\0'; | ||
110 | range = simple_strtoul(buf, &s, 10); | ||
111 | if (*s) | ||
112 | goto fail; | ||
113 | |||
114 | /* if partition is within range - we got it */ | ||
115 | if (part < range) | ||
116 | return res + part; | ||
117 | fail: | ||
118 | return 0; | ||
119 | } | ||
120 | |||
121 | /* | 58 | /* |
122 | * Convert a name into device number. We accept the following variants: | 59 | * Convert a name into device number. We accept the following variants: |
123 | * | 60 | * |
@@ -129,12 +66,10 @@ fail: | |||
129 | * 5) /dev/<disk_name>p<decimal> - same as the above, that form is | 66 | * 5) /dev/<disk_name>p<decimal> - same as the above, that form is |
130 | * used when disk name of partitioned disk ends on a digit. | 67 | * used when disk name of partitioned disk ends on a digit. |
131 | * | 68 | * |
132 | * If name doesn't have fall into the categories above, we return 0. | 69 | * If name doesn't have fall into the categories above, we return (0,0). |
133 | * Sysfs is used to check if something is a disk name - it has | 70 | * block_class is used to check if something is a disk name. If the disk |
134 | * all known disks under bus/block/devices. If the disk name | 71 | * name contains slashes, the device name has them replaced with |
135 | * contains slashes, name of sysfs node has them replaced with | 72 | * bangs. |
136 | * bangs. try_name() does the actual checks, assuming that sysfs | ||
137 | * is mounted on rootfs /sys. | ||
138 | */ | 73 | */ |
139 | 74 | ||
140 | dev_t name_to_dev_t(char *name) | 75 | dev_t name_to_dev_t(char *name) |
@@ -142,13 +77,6 @@ dev_t name_to_dev_t(char *name) | |||
142 | char s[32]; | 77 | char s[32]; |
143 | char *p; | 78 | char *p; |
144 | dev_t res = 0; | 79 | dev_t res = 0; |
145 | int part; | ||
146 | |||
147 | #ifdef CONFIG_SYSFS | ||
148 | int mkdir_err = sys_mkdir("/sys", 0700); | ||
149 | if (sys_mount("sysfs", "/sys", "sysfs", 0, NULL) < 0) | ||
150 | goto out; | ||
151 | #endif | ||
152 | 80 | ||
153 | if (strncmp(name, "/dev/", 5) != 0) { | 81 | if (strncmp(name, "/dev/", 5) != 0) { |
154 | unsigned maj, min; | 82 | unsigned maj, min; |
@@ -164,6 +92,7 @@ dev_t name_to_dev_t(char *name) | |||
164 | } | 92 | } |
165 | goto done; | 93 | goto done; |
166 | } | 94 | } |
95 | |||
167 | name += 5; | 96 | name += 5; |
168 | res = Root_NFS; | 97 | res = Root_NFS; |
169 | if (strcmp(name, "nfs") == 0) | 98 | if (strcmp(name, "nfs") == 0) |
@@ -178,35 +107,14 @@ dev_t name_to_dev_t(char *name) | |||
178 | for (p = s; *p; p++) | 107 | for (p = s; *p; p++) |
179 | if (*p == '/') | 108 | if (*p == '/') |
180 | *p = '!'; | 109 | *p = '!'; |
181 | res = try_name(s, 0); | 110 | res = blk_lookup_devt(s); |
182 | if (res) | 111 | if (res) |
183 | goto done; | 112 | goto done; |
184 | 113 | ||
185 | while (p > s && isdigit(p[-1])) | 114 | fail: |
186 | p--; | 115 | return 0; |
187 | if (p == s || !*p || *p == '0') | ||
188 | goto fail; | ||
189 | part = simple_strtoul(p, NULL, 10); | ||
190 | *p = '\0'; | ||
191 | res = try_name(s, part); | ||
192 | if (res) | ||
193 | goto done; | ||
194 | |||
195 | if (p < s + 2 || !isdigit(p[-2]) || p[-1] != 'p') | ||
196 | goto fail; | ||
197 | p[-1] = '\0'; | ||
198 | res = try_name(s, part); | ||
199 | done: | 116 | done: |
200 | #ifdef CONFIG_SYSFS | ||
201 | sys_umount("/sys", 0); | ||
202 | out: | ||
203 | if (!mkdir_err) | ||
204 | sys_rmdir("/sys"); | ||
205 | #endif | ||
206 | return res; | 117 | return res; |
207 | fail: | ||
208 | res = 0; | ||
209 | goto done; | ||
210 | } | 118 | } |
211 | 119 | ||
212 | static int __init root_dev_setup(char *line) | 120 | static int __init root_dev_setup(char *line) |