patch-2.1.19 linux/drivers/block/genhd.c
Next file: linux/drivers/char/tty_ioctl.c
Previous file: linux/arch/sparc64/prom/tree.c
Back to the patch index
Back to the overall index
- Lines: 146
- Date:
Mon Dec 30 12:06:22 1996
- Orig file:
v2.1.18/linux/drivers/block/genhd.c
- Orig date:
Sun Nov 10 20:12:09 1996
diff -u --recursive --new-file v2.1.18/linux/drivers/block/genhd.c linux/drivers/block/genhd.c
@@ -37,10 +37,16 @@
*/
#include <asm/unaligned.h>
-#define SYS_IND(p) get_unaligned(&p->sys_ind)
-#define NR_SECTS(p) get_unaligned(&p->nr_sects)
-#define START_SECT(p) get_unaligned(&p->start_sect)
-
+#define SYS_IND(p) (get_unaligned(&p->sys_ind))
+#define NR_SECTS(p) ({ __typeof__(p->nr_sects) __a = \
+ get_unaligned(&p->nr_sects); \
+ le32_to_cpu(__a); \
+ })
+
+#define START_SECT(p) ({ __typeof__(p->start_sect) __a = \
+ get_unaligned(&p->start_sect); \
+ le32_to_cpu(__a); \
+ })
struct gendisk *gendisk_head = NULL;
@@ -115,6 +121,8 @@
* only for the actual data partitions.
*/
+#define MSDOS_LABEL_MAGIC 0xAA55
+
static void extended_partition(struct gendisk *hd, kdev_t dev)
{
struct buffer_head *bh;
@@ -138,7 +146,7 @@
*/
bh->b_state = 0;
- if (*(unsigned short *) (bh->b_data+510) != 0xAA55)
+ if (le16_to_cpu(*(unsigned short *) (bh->b_data+510)) != MSDOS_LABEL_MAGIC)
goto done;
p = (struct partition *) (0x1BE + bh->b_data);
@@ -263,7 +271,7 @@
#ifdef CONFIG_BLK_DEV_IDE
check_table:
#endif
- if (*(unsigned short *) (0x1fe + data) != 0xAA55) {
+ if (le16_to_cpu(*(unsigned short *) (0x1fe + data)) != MSDOS_LABEL_MAGIC) {
brelse(bh);
return 0;
}
@@ -275,7 +283,7 @@
* Look for various forms of IDE disk geometry translation
*/
extern int ide_xlate_1024(kdev_t, int, const char *);
- unsigned int sig = *(unsigned short *)(data + 2);
+ unsigned int sig = le16_to_cpu(*(unsigned short *)(data + 2));
if (SYS_IND(p) == EZD_PARTITION) {
/*
* The remainder of the disk must be accessed using
@@ -305,12 +313,10 @@
brelse(bh);
goto read_mbr; /* start over with new MBR */
}
- } else if (sig <= 0x1ae && *(unsigned short *)(data + sig) == 0x55AA
- && (1 & *(unsigned char *)(data + sig + 2)) )
- {
- /*
- * DM6 signature in MBR, courtesy of OnTrack
- */
+ } else if (sig <= 0x1ae &&
+ le16_to_cpu(*(unsigned short *)(data + sig)) == 0x55AA &&
+ (1 & *(unsigned char *)(data + sig + 2))) {
+ /* DM6 signature in MBR, courtesy of OnTrack */
(void) ide_xlate_1024 (dev, 0, " [DM6:MBR]");
} else if (SYS_IND(p) == DM6_AUX1PARTITION || SYS_IND(p) == DM6_AUX3PARTITION) {
/*
@@ -373,7 +379,7 @@
/*
* Check for old-style Disk Manager partition table
*/
- if (*(unsigned short *) (data+0xfc) == 0x55AA) {
+ if (le16_to_cpu(*(unsigned short *) (data+0xfc)) == MSDOS_LABEL_MAGIC) {
p = (struct partition *) (0x1be + data);
for (i = 4 ; i < 16 ; i++, current_minor++) {
p--;
@@ -492,20 +498,8 @@
unsigned short csum; /* Label xor'd checksum */
} * label;
struct sun_partition *p;
- int other_endian;
unsigned long spc;
#define SUN_LABEL_MAGIC 0xDABE
-#define SUN_LABEL_MAGIC_SWAPPED 0xBEDA
-/* No need to optimize these macros since they are called only when reading
- * the partition table. This occurs only at each disk change. */
-#define SWAP16(x) (other_endian ? (((__u16)(x) & 0xFF) << 8) \
- | (((__u16)(x) & 0xFF00) >> 8) \
- : (__u16)(x))
-#define SWAP32(x) (other_endian ? (((__u32)(x) & 0xFF) << 24) \
- | (((__u32)(x) & 0xFF00) << 8) \
- | (((__u32)(x) & 0xFF0000) >> 8) \
- | (((__u32)(x) & 0xFF000000) >> 24) \
- : (__u32)(x))
if(!(bh = bread(dev, 0, 1024))) {
printk("Dev %s: unable to read partition table\n",
@@ -514,13 +508,12 @@
}
label = (struct sun_disklabel *) bh->b_data;
p = label->partitions;
- if (label->magic != SUN_LABEL_MAGIC && label->magic != SUN_LABEL_MAGIC_SWAPPED) {
+ if (be16_to_cpu(label->magic) != SUN_LABEL_MAGIC) {
printk("Dev %s Sun disklabel: bad magic %04x\n",
- kdevname(dev), label->magic);
+ kdevname(dev), be16_to_cpu(label->magic));
brelse(bh);
return 0;
}
- other_endian = (label->magic == SUN_LABEL_MAGIC_SWAPPED);
/* Look at the checksum */
ush = ((unsigned short *) (label+1)) - 1;
for(csum = 0; ush >= ((unsigned short *) label);)
@@ -532,22 +525,20 @@
return 0;
}
/* All Sun disks have 8 partition entries */
- spc = SWAP16(label->ntrks) * SWAP16(label->nsect);
+ spc = be16_to_cpu(label->ntrks) * be16_to_cpu(label->nsect);
for(i=0; i < 8; i++, p++) {
unsigned long st_sector;
/* We register all partitions, even if zero size, so that
* the minor numbers end up ok as per SunOS interpretation.
*/
- st_sector = first_sector + SWAP32(p->start_cylinder) * spc;
- add_partition(hd, current_minor, st_sector, SWAP32(p->num_sectors));
+ st_sector = first_sector + be32_to_cpu(p->start_cylinder) * spc;
+ add_partition(hd, current_minor, st_sector, be32_to_cpu(p->num_sectors));
current_minor++;
}
printk("\n");
brelse(bh);
return 1;
-#undef SWAP16
-#undef SWAP32
}
#endif /* CONFIG_SUN_PARTITION */
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov