ref: 6459fcff761a53c534f48106deee25a230022ad3
parent: 4c64c5023f8250a3d5b816f53223f30b6b8aa8cf
author: cinap_lenrek <cinap_lenrek@gmx.de>
date: Tue May 8 12:30:18 EDT 2012
disk/format, 9boot: fix alignment issues
--- a/sys/src/boot/pc/fat.c
+++ b/sys/src/boot/pc/fat.c
@@ -16,6 +16,7 @@
typedef struct File File;
typedef struct Dir Dir;
typedef struct Pbs Pbs;
+typedef struct Pbs32 Pbs32;
typedef struct Fat Fat;
struct Fat
@@ -75,36 +76,32 @@
uchar nheads[2];
uchar nhidden[4];
uchar bigvolsize[4];
- union
- {- struct
- {- uchar driveno;
- uchar reserved0;
- uchar bootsig;
- uchar volid[4];
- uchar label[11];
- uchar type[8];
- };
- struct
- {- uchar fatsize[4];
- uchar flags[2];
- uchar ver[2];
- uchar rootclust[4];
- uchar fsinfo[2];
- uchar bootbak[2];
- uchar reserved0[12];
- uchar driveno;
- uchar reserved1;
- uchar bootsig;
- uchar volid[4];
- uchar label[11];
- uchar type[8];
- } fat32;
- };
+ uchar driveno;
+ uchar reserved0;
+ uchar bootsig;
+ uchar volid[4];
+ uchar label[11];
+ uchar type[8];
};
+struct Pbs32
+{+ uchar common[36];
+ uchar fatsize[4];
+ uchar flags[2];
+ uchar ver[2];
+ uchar rootclust[4];
+ uchar fsinfo[2];
+ uchar bootbak[2];
+ uchar reserved0[12];
+ uchar driveno;
+ uchar reserved1;
+ uchar bootsig;
+ uchar volid[4];
+ uchar label[11];
+ uchar type[8];
+};
+
int readsect(ulong drive, ulong lba, void *buf);
void
@@ -278,7 +275,7 @@
if(GETSHORT(p->sectsize) != Sectsz)
return -1;
- if(memcmp(p->type, "FAT", 3) && memcmp(p->fat32.type, "FAT", 3))
+ if(memcmp(p->type, "FAT", 3) && memcmp(((Pbs32*)buf)->type, "FAT", 3))
return -1;
/* load values from fat */
@@ -285,7 +282,7 @@
ver = 0;
fatsize = GETSHORT(p->fatsize);
if(fatsize == 0){- fatsize = GETLONG(p->fat32.fatsize);
+ fatsize = GETLONG(((Pbs32*)buf)->fatsize);
ver = Fat32;
}
volsize = GETSHORT(p->volsize);
@@ -310,7 +307,7 @@
fat->dirstart = fat->fatlba + fatsize * p->nfats;
if(ver == Fat32){fat->datalba = fat->dirstart;
- fat->dirstart = GETLONG(p->fat32.rootclust);
+ fat->dirstart = GETLONG(((Pbs32*)buf)->rootclust);
fat->eofmark = 0xffffff7;
}else{fat->datalba = fat->dirstart + dirsize;
--- a/sys/src/cmd/disk/format.c
+++ b/sys/src/cmd/disk/format.c
@@ -45,33 +45,33 @@
uchar nheads[2];
uchar nhidden[4];
uchar bigvolsize[4];
- union {- struct {- uchar driveno;
- uchar reserved0;
- uchar bootsig;
- uchar volid[4];
- uchar label[11];
- uchar type[8];
- };
- struct {- uchar fatsize[4];
- uchar flags[2];
- uchar ver[2];
- uchar rootclust[4];
- uchar fsinfo[2];
- uchar bootbak[2];
- uchar reserved0[12];
- uchar driveno;
- uchar reserved1;
- uchar bootsig;
- uchar volid[4];
- uchar label[11];
- uchar type[8];
- } fat32;
- };
+ uchar driveno;
+ uchar reserved0;
+ uchar bootsig;
+ uchar volid[4];
+ uchar label[11];
+ uchar type[8];
};
+typedef struct Dosboot32 Dosboot32;
+struct Dosboot32
+{+ uchar common[36];
+ uchar fatsize[4];
+ uchar flags[2];
+ uchar ver[2];
+ uchar rootclust[4];
+ uchar fsinfo[2];
+ uchar bootbak[2];
+ uchar reserved0[12];
+ uchar driveno;
+ uchar reserved1;
+ uchar bootsig;
+ uchar volid[4];
+ uchar label[11];
+ uchar type[8];
+};
+
#define PUTSHORT(p, v) { (p)[1] = (v)>>8; (p)[0] = (v); } #define PUTLONG(p, v) { PUTSHORT((p), (v)); PUTSHORT((p)+2, (v)>>16); }#define GETSHORT(p) (((p)[1]<<8)|(p)[0])
@@ -604,12 +604,15 @@
sprint(r, "FAT%d ", fatbits);
if(fatbits == 32){- PUTLONG(b->fat32.fatsize, fatsecs);
- PUTLONG(b->fat32.rootclust, 2);
- b->fat32.bootsig = 0x29;
- b->fat32.driveno = (t->media == 0xF8) ? getdriveno(disk) : 0;
- memmove(b->fat32.label, label, sizeof(b->fat32.label));
- memmove(b->fat32.type, r, sizeof(b->fat32.type));
+ Dosboot32 *bb;
+
+ bb = (Dosboot32*)buf;
+ PUTLONG(bb->fatsize, fatsecs);
+ PUTLONG(bb->rootclust, 2);
+ bb->bootsig = 0x29;
+ bb->driveno = (t->media == 0xF8) ? getdriveno(disk) : 0;
+ memmove(bb->label, label, sizeof(bb->label));
+ memmove(bb->type, r, sizeof(bb->type));
} else {b->bootsig = 0x29;
b->driveno = (t->media == 0xF8) ? getdriveno(disk) : 0;
--
⑨