2 * fs/partitions/atari.c
4 * Code extracted from drivers/block/genhd.c
6 * Copyright (C) 1991-1998 Linus Torvalds
7 * Re-organised Feb 1998 Russell King
11 #include <linux/genhd.h>
12 #include <linux/kernel.h>
13 #include <linux/major.h>
14 #include <linux/string.h>
15 #include <linux/blk.h>
16 #include <linux/ctype.h>
18 #include <asm/byteorder.h>
19 #include <asm/system.h>
24 /* ++guenther: this should be settable by the user ("make config")?.
28 /* check if a partition entry looks valid -- Atari format is assumed if at
29 least one of the primary entries is ok this way */
30 #define VALID_PARTITION(pi,hdsiz) \
32 isalnum((pi)->id[0]) && isalnum((pi)->id[1]) && isalnum((pi)->id[2]) && \
33 be32_to_cpu((pi)->st) <= (hdsiz) && \
34 be32_to_cpu((pi)->st) + be32_to_cpu((pi)->siz) <= (hdsiz))
36 int atari_partition (struct gendisk
*hd
, kdev_t dev
,
37 unsigned long first_sector
, int first_part_minor
)
39 int minor
= first_part_minor
, m_lim
= first_part_minor
+ hd
->max_p
;
40 struct buffer_head
*bh
;
41 struct rootsector
*rs
;
42 struct partition_info
*pi
;
46 int part_fmt
= 0; /* 0:unknown, 1:AHDI, 2:ICD/Supra */
49 bh
= bread (dev
, 0, get_ptable_blocksize(dev
));
51 printk (" unable to read block 0 (partition table)\n");
55 /* Verify this is an Atari rootsector: */
56 rs
= (struct rootsector
*) bh
->b_data
;
57 hd_size
= hd
->part
[minor
- 1].nr_sects
;
58 if (!VALID_PARTITION(&rs
->part
[0], hd_size
) &&
59 !VALID_PARTITION(&rs
->part
[1], hd_size
) &&
60 !VALID_PARTITION(&rs
->part
[2], hd_size
) &&
61 !VALID_PARTITION(&rs
->part
[3], hd_size
)) {
62 /* if there's no valid primary partition, assume that no Atari
63 format partition table (there's no reliable magic or the like
70 for (; pi
< &rs
->part
[4] && minor
< m_lim
; minor
++, pi
++)
73 /* active partition */
75 if (memcmp (pi
->id
, "XGM", 3) == 0)
76 /* extension partition */
78 struct rootsector
*xrs
;
79 struct buffer_head
*xbh
;
86 partsect
= extensect
= be32_to_cpu(pi
->st
);
89 xbh
= bread (dev
, partsect
/ 2, get_ptable_blocksize(dev
));
92 printk (" block %ld read failed\n", partsect
);
97 xrs
= (struct rootsector
*) &xbh
->b_data
[512];
99 xrs
= (struct rootsector
*) &xbh
->b_data
[0];
101 /* ++roman: sanity check: bit 0 of flg field must be set */
102 if (!(xrs
->part
[0].flg
& 1)) {
103 printk( "\nFirst sub-partition in extended partition is not valid!\n" );
107 add_gd_partition(hd
, minor
,
108 partsect
+ be32_to_cpu(xrs
->part
[0].st
),
109 be32_to_cpu(xrs
->part
[0].siz
));
111 if (!(xrs
->part
[1].flg
& 1)) {
112 /* end of linked partition list */
116 if (memcmp( xrs
->part
[1].id
, "XGM", 3 ) != 0) {
117 printk( "\nID of extended partition is not XGM!\n" );
122 partsect
= be32_to_cpu(xrs
->part
[1].st
) + extensect
;
125 if (minor
>= m_lim
) {
126 printk( "\nMaximum number of partitions reached!\n" );
134 /* we don't care about other id's */
135 add_gd_partition (hd
, minor
, be32_to_cpu(pi
->st
),
136 be32_to_cpu(pi
->siz
));
141 if ( part_fmt
!=1 ) /* no extended partitions -> test ICD-format */
143 pi
= &rs
->icdpart
[0];
144 /* sanity check: no ICD format if first partition invalid */
145 if (memcmp (pi
->id
, "GEM", 3) == 0 ||
146 memcmp (pi
->id
, "BGM", 3) == 0 ||
147 memcmp (pi
->id
, "LNX", 3) == 0 ||
148 memcmp (pi
->id
, "SWP", 3) == 0 ||
149 memcmp (pi
->id
, "RAW", 3) == 0 )
152 for (; pi
< &rs
->icdpart
[8] && minor
< m_lim
; minor
++, pi
++)
154 /* accept only GEM,BGM,RAW,LNX,SWP partitions */
156 (memcmp (pi
->id
, "GEM", 3) == 0 ||
157 memcmp (pi
->id
, "BGM", 3) == 0 ||
158 memcmp (pi
->id
, "LNX", 3) == 0 ||
159 memcmp (pi
->id
, "SWP", 3) == 0 ||
160 memcmp (pi
->id
, "RAW", 3) == 0) )
163 add_gd_partition (hd
, minor
, be32_to_cpu(pi
->st
),
164 be32_to_cpu(pi
->siz
));