1 diff -urN linux.old/fs/partitions/check.c linux.dev/fs/partitions/check.c
2 --- linux.old/fs/partitions/check.c 2006-05-31 02:31:44.000000000 +0200
3 +++ linux.dev/fs/partitions/check.c 2006-06-15 01:27:17.000000000 +0200
13 * Probe partition formats with tables at disk address 0
14 * that also have an ADFS boot block at 0xdc0.
16 +#ifdef CONFIG_OPENWRT_PARTITION
19 #ifdef CONFIG_ACORN_PARTITION_ICS
22 diff -urN linux.old/fs/partitions/Kconfig linux.dev/fs/partitions/Kconfig
23 --- linux.old/fs/partitions/Kconfig 2006-05-31 02:31:44.000000000 +0200
24 +++ linux.dev/fs/partitions/Kconfig 2006-06-15 01:27:17.000000000 +0200
29 +config OPENWRT_PARTITION
30 + bool "OpenWrt partition support" if PARTITION_ADVANCED
33 + Support the custom OpenWrt partition map
35 config ACORN_PARTITION
36 bool "Acorn partition support" if PARTITION_ADVANCED
37 default y if ARCH_ACORN
38 diff -urN linux.old/fs/partitions/Makefile linux.dev/fs/partitions/Makefile
39 --- linux.old/fs/partitions/Makefile 2006-05-31 02:31:44.000000000 +0200
40 +++ linux.dev/fs/partitions/Makefile 2006-06-15 01:27:17.000000000 +0200
42 obj-$(CONFIG_MAC_PARTITION) += mac.o
43 obj-$(CONFIG_LDM_PARTITION) += ldm.o
44 obj-$(CONFIG_MSDOS_PARTITION) += msdos.o
45 +obj-$(CONFIG_OPENWRT_PARTITION) += openwrt.o
46 obj-$(CONFIG_OSF_PARTITION) += osf.o
47 obj-$(CONFIG_SGI_PARTITION) += sgi.o
48 obj-$(CONFIG_SUN_PARTITION) += sun.o
49 diff -urN linux.old/fs/partitions/openwrt.c linux.dev/fs/partitions/openwrt.c
50 --- linux.old/fs/partitions/openwrt.c 1970-01-01 01:00:00.000000000 +0100
51 +++ linux.dev/fs/partitions/openwrt.c 2006-06-15 01:27:17.000000000 +0200
54 + * fs/partitions/openwrt.c
56 + * Code extracted from drivers/block/genhd.c
57 + * and fs/partitions/msdos.c
59 + * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
60 + * Copyright (C) 1991-1998 Linus Torvalds
62 + * Thanks to Branko Lankester, lankeste@fwi.uva.nl, who found a bug
63 + * in the early extended-partition checks and added DM partitions
65 + * Support for DiskManager v6.0x added by Mark Lord,
66 + * with information provided by OnTrack. This now works for linux fdisk
67 + * and LILO, as well as loadlin and bootln. Note that disks other than
68 + * /dev/hda *must* have a "DOS" type 0x51 partition in the first slot (hda1).
70 + * More flexible handling of extended partitions - aeb, 950831
72 + * Check partition table on IDE disks for common CHS translations
74 + * Re-organised Feb 1998 Russell King
77 +#include <linux/config.h>
83 + * Many architectures don't like unaligned accesses, while
84 + * the nr_sects and start_sect partition table entries are
85 + * at a 2 (mod 4) address.
87 +#include <asm/unaligned.h>
89 +#define SYS_IND(p) (get_unaligned(&p->sys_ind))
90 +#define NR_SECTS(p) ({ __typeof__(p->nr_sects) __a = \
91 + get_unaligned(&p->nr_sects); \
95 +#define START_SECT(p) ({ __typeof__(p->start_sect) __a = \
96 + get_unaligned(&p->start_sect); \
100 +static inline int is_extended_partition(struct partition *p)
102 + return (SYS_IND(p) == DOS_EXTENDED_PARTITION ||
103 + SYS_IND(p) == WIN98_EXTENDED_PARTITION ||
104 + SYS_IND(p) == LINUX_EXTENDED_PARTITION);
107 +#define MSDOS_LABEL_MAGIC1 0x55
108 +#define MSDOS_LABEL_MAGIC2 0xAA
111 +msdos_magic_present(unsigned char *p)
113 + return (p[0] == MSDOS_LABEL_MAGIC1 && p[1] == MSDOS_LABEL_MAGIC2);
117 +openwrt_magic_present(unsigned char *p)
119 + return (p[0] == 'O' &&
126 + * Create devices for each logical partition in an extended partition.
127 + * The logical partitions form a linked list, with each entry being
128 + * a partition table with two entries. The first entry
129 + * is the real data partition (with a start relative to the partition
130 + * table start). The second is a pointer to the next logical partition
131 + * (with a start relative to the entire extended partition).
132 + * We do not create a Linux partition for the partition tables, but
133 + * only for the actual data partitions.
137 +parse_extended(struct parsed_partitions *state, struct block_device *bdev,
138 + u32 first_sector, u32 first_size)
140 + struct partition *p;
142 + unsigned char *data;
143 + u32 this_sector, this_size;
144 + int sector_size = bdev_hardsect_size(bdev) / 512;
145 + int loopct = 0; /* number of links followed
146 + without finding a data partition */
149 + this_sector = first_sector;
150 + this_size = first_size;
153 + if (++loopct > 100)
155 + if (state->next == state->limit)
157 + data = read_dev_sector(bdev, this_sector, §);
161 + if (!msdos_magic_present(data + 510))
164 + p = (struct partition *) (data + 0x1be);
167 + * Usually, the first entry is the real data partition,
168 + * the 2nd entry is the next extended partition, or empty,
169 + * and the 3rd and 4th entries are unused.
170 + * However, DRDOS sometimes has the extended partition as
171 + * the first entry (when the data partition is empty),
172 + * and OS/2 seems to use all four entries.
176 + * First process the data partition(s)
178 + for (i=0; i<4; i++, p++) {
179 + u32 offs, size, next;
180 + if (!NR_SECTS(p) || is_extended_partition(p))
183 + /* Check the 3rd and 4th entries -
184 + these sometimes contain random garbage */
185 + offs = START_SECT(p)*sector_size;
186 + size = NR_SECTS(p)*sector_size;
187 + next = this_sector + offs;
189 + if (offs + size > this_size)
191 + if (next < first_sector)
193 + if (next + size > first_sector + first_size)
197 + put_partition(state, state->next, next, size);
198 + if (SYS_IND(p) == LINUX_RAID_PARTITION)
199 + state->parts[state->next].flags = 1;
201 + if (++state->next == state->limit)
205 + * Next, process the (first) extended partition, if present.
206 + * (So far, there seems to be no reason to make
207 + * parse_extended() recursive and allow a tree
208 + * of extended partitions.)
209 + * It should be a link to the next logical partition.
212 + for (i=0; i<4; i++, p++)
213 + if (NR_SECTS(p) && is_extended_partition(p))
216 + goto done; /* nothing left to do */
218 + this_sector = first_sector + START_SECT(p) * sector_size;
219 + this_size = NR_SECTS(p) * sector_size;
220 + put_dev_sector(sect);
223 + put_dev_sector(sect);
227 +int openwrt_partition(struct parsed_partitions *state, struct block_device *bdev)
229 + int sector_size = bdev_hardsect_size(bdev) / 512;
231 + unsigned char *data;
232 + struct partition *p;
234 + u32 last_block = 0;
238 + data = read_dev_sector(bdev, 0, §);
241 + if (!openwrt_magic_present(data)) {
242 + printk("No OpenWrt partition table detected\n");
243 + put_dev_sector(sect);
248 + * Now that the 55aa signature is present, this is probably
249 + * either the boot sector of a FAT filesystem or a DOS-type
250 + * partition table. Reject this in case the boot indicator
251 + * is not 0 or 0x80.
253 + p = (struct partition *) (data + 0x1be);
254 + for (slot = 1; slot <= 4; slot++, p++) {
255 + if (p->boot_ind != 0 && p->boot_ind != 0x80) {
256 + put_dev_sector(sect);
261 + p = (struct partition *) (data + 0x1be);
264 + * Look for partitions in two passes:
265 + * First find the primary and DOS-type extended partitions.
269 + for (slot = 1 ; slot <= 4 ; slot++, p++) {
270 + u32 start = START_SECT(p)*sector_size;
271 + size = NR_SECTS(p)*sector_size;
273 + if (firstfree > slot)
278 + if (is_extended_partition(p)) {
279 + /* prevent someone doing mkfs or mkswap on an
280 + extended partition, but leave room for LILO */
281 + last_block = start + size;
282 + put_partition(state, slot, start, size == 1 ? 1 : 2);
284 + parse_extended(state, bdev, start, size);
288 + if ((start + size) > get_capacity(bdev->bd_disk))
289 + size = get_capacity(bdev->bd_disk) - start;
290 + last_block = start + size;
291 + put_partition(state, slot, start, size);
293 + if (last_block + 1024 < (size = get_capacity(bdev->bd_disk)))
294 + put_partition(state, firstfree, last_block, size - last_block);
298 + put_dev_sector(sect);
302 diff -urN linux.old/fs/partitions/openwrt.h linux.dev/fs/partitions/openwrt.h
303 --- linux.old/fs/partitions/openwrt.h 1970-01-01 01:00:00.000000000 +0100
304 +++ linux.dev/fs/partitions/openwrt.h 2006-06-15 01:27:17.000000000 +0200
307 + * fs/partitions/openwrt.h
310 +int openwrt_partition(struct parsed_partitions *state, struct block_device *bdev);