Blame view
block/partitions/check.c
4.19 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
/* * fs/partitions/check.c * * Code extracted from drivers/block/genhd.c * Copyright (C) 1991-1998 Linus Torvalds * Re-organised Feb 1998 Russell King * * We now have independent partition support from the * block drivers, which allows all the partition code to * be grouped in one location, and it to be mostly self * contained. * * Added needed MAJORS for new pairs, {hdi,hdj}, {hdk,hdl} */ |
5a0e3ad6a include cleanup: ... |
15 |
#include <linux/slab.h> |
ac2e5327a block/partitions:... |
16 |
#include <linux/vmalloc.h> |
1da177e4c Linux-2.6.12-rc2 |
17 |
#include <linux/ctype.h> |
6f2576af5 Enhanced partitio... |
18 |
#include <linux/genhd.h> |
1da177e4c Linux-2.6.12-rc2 |
19 20 |
#include "check.h" |
1da177e4c Linux-2.6.12-rc2 |
21 22 23 24 25 26 27 28 29 30 31 32 33 |
#include "acorn.h" #include "amiga.h" #include "atari.h" #include "ldm.h" #include "mac.h" #include "msdos.h" #include "osf.h" #include "sgi.h" #include "sun.h" #include "ibm.h" #include "ultrix.h" #include "efi.h" |
0e6e1db4a [PATCH] partition... |
34 |
#include "karma.h" |
19d0e8ce8 partition: add su... |
35 |
#include "sysv68.h" |
bab55417b block: support em... |
36 |
#include "cmdline.h" |
1da177e4c Linux-2.6.12-rc2 |
37 |
|
1da177e4c Linux-2.6.12-rc2 |
38 |
int warn_no_part = 1; /*This is ugly: should make genhd removable media aware*/ |
1493bf217 block: use struct... |
39 |
static int (*check_part[])(struct parsed_partitions *) = { |
1da177e4c Linux-2.6.12-rc2 |
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
/* * Probe partition formats with tables at disk address 0 * that also have an ADFS boot block at 0xdc0. */ #ifdef CONFIG_ACORN_PARTITION_ICS adfspart_check_ICS, #endif #ifdef CONFIG_ACORN_PARTITION_POWERTEC adfspart_check_POWERTEC, #endif #ifdef CONFIG_ACORN_PARTITION_EESOX adfspart_check_EESOX, #endif /* * Now move on to formats that only have partition info at * disk address 0xdc0. Since these may also have stale * PC/BIOS partition tables, they need to come before * the msdos entry. */ #ifdef CONFIG_ACORN_PARTITION_CUMANA adfspart_check_CUMANA, #endif #ifdef CONFIG_ACORN_PARTITION_ADFS adfspart_check_ADFS, #endif |
bab55417b block: support em... |
66 67 68 |
#ifdef CONFIG_CMDLINE_PARTITION cmdline_partition, #endif |
1da177e4c Linux-2.6.12-rc2 |
69 70 71 72 73 74 75 76 77 |
#ifdef CONFIG_EFI_PARTITION efi_partition, /* this must come before msdos */ #endif #ifdef CONFIG_SGI_PARTITION sgi_partition, #endif #ifdef CONFIG_LDM_PARTITION ldm_partition, /* this must come before msdos */ #endif |
1da177e4c Linux-2.6.12-rc2 |
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
#ifdef CONFIG_MSDOS_PARTITION msdos_partition, #endif #ifdef CONFIG_OSF_PARTITION osf_partition, #endif #ifdef CONFIG_SUN_PARTITION sun_partition, #endif #ifdef CONFIG_AMIGA_PARTITION amiga_partition, #endif #ifdef CONFIG_ATARI_PARTITION atari_partition, #endif #ifdef CONFIG_MAC_PARTITION mac_partition, #endif #ifdef CONFIG_ULTRIX_PARTITION ultrix_partition, #endif #ifdef CONFIG_IBM_PARTITION ibm_partition, #endif |
0e6e1db4a [PATCH] partition... |
102 103 104 |
#ifdef CONFIG_KARMA_PARTITION karma_partition, #endif |
19d0e8ce8 partition: add su... |
105 106 107 |
#ifdef CONFIG_SYSV68_PARTITION sysv68_partition, #endif |
1da177e4c Linux-2.6.12-rc2 |
108 109 |
NULL }; |
1da177e4c Linux-2.6.12-rc2 |
110 |
|
ac2e5327a block/partitions:... |
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
static struct parsed_partitions *allocate_partitions(struct gendisk *hd) { struct parsed_partitions *state; int nr; state = kzalloc(sizeof(*state), GFP_KERNEL); if (!state) return NULL; nr = disk_max_parts(hd); state->parts = vzalloc(nr * sizeof(state->parts[0])); if (!state->parts) { kfree(state); return NULL; } state->limit = nr; return state; } void free_partitions(struct parsed_partitions *state) { vfree(state->parts); kfree(state); } |
94ea4158f separate partitio... |
137 |
struct parsed_partitions * |
1da177e4c Linux-2.6.12-rc2 |
138 139 140 |
check_partition(struct gendisk *hd, struct block_device *bdev) { struct parsed_partitions *state; |
57881dd9d [PATCH] Fix check... |
141 |
int i, res, err; |
1da177e4c Linux-2.6.12-rc2 |
142 |
|
ac2e5327a block/partitions:... |
143 |
state = allocate_partitions(hd); |
1da177e4c Linux-2.6.12-rc2 |
144 145 |
if (!state) return NULL; |
9c867fbe0 partitions: fix s... |
146 147 |
state->pp_buf = (char *)__get_free_page(GFP_KERNEL); if (!state->pp_buf) { |
ac2e5327a block/partitions:... |
148 |
free_partitions(state); |
9c867fbe0 partitions: fix s... |
149 150 151 |
return NULL; } state->pp_buf[0] = '\0'; |
1da177e4c Linux-2.6.12-rc2 |
152 |
|
1493bf217 block: use struct... |
153 |
state->bdev = bdev; |
a29641883 [PATCH] devfs: Re... |
154 |
disk_name(hd, 0, state->name); |
9c867fbe0 partitions: fix s... |
155 |
snprintf(state->pp_buf, PAGE_SIZE, " %s:", state->name); |
a29641883 [PATCH] devfs: Re... |
156 |
if (isdigit(state->name[strlen(state->name)-1])) |
1da177e4c Linux-2.6.12-rc2 |
157 |
sprintf(state->name, "p"); |
a29641883 [PATCH] devfs: Re... |
158 |
|
57881dd9d [PATCH] Fix check... |
159 |
i = res = err = 0; |
1da177e4c Linux-2.6.12-rc2 |
160 |
while (!res && check_part[i]) { |
ac2e5327a block/partitions:... |
161 |
memset(state->parts, 0, state->limit * sizeof(state->parts[0])); |
1493bf217 block: use struct... |
162 |
res = check_part[i++](state); |
57881dd9d [PATCH] Fix check... |
163 164 165 166 167 168 169 |
if (res < 0) { /* We have hit an I/O error which we don't report now. * But record it, and let the others do their job. */ err = res; res = 0; } |
1da177e4c Linux-2.6.12-rc2 |
170 |
} |
9c867fbe0 partitions: fix s... |
171 172 173 174 |
if (res > 0) { printk(KERN_INFO "%s", state->pp_buf); free_page((unsigned long)state->pp_buf); |
1da177e4c Linux-2.6.12-rc2 |
175 |
return state; |
9c867fbe0 partitions: fix s... |
176 |
} |
b403a98e2 block: improve au... |
177 178 |
if (state->access_beyond_eod) err = -ENOSPC; |
9bebff6ca [PATCH] check_par... |
179 |
if (err) |
57881dd9d [PATCH] Fix check... |
180 181 |
/* The partition is unrecognized. So report I/O errors if there were any */ res = err; |
bb5c3cdda block: Remove ann... |
182 183 184 185 186 187 188 |
if (res) { if (warn_no_part) strlcat(state->pp_buf, " unable to read partition table ", PAGE_SIZE); printk(KERN_INFO "%s", state->pp_buf); } |
9c867fbe0 partitions: fix s... |
189 190 |
free_page((unsigned long)state->pp_buf); |
ac2e5327a block/partitions:... |
191 |
free_partitions(state); |
5127d002f [PATCH] fix resca... |
192 |
return ERR_PTR(res); |
1da177e4c Linux-2.6.12-rc2 |
193 |
} |