fdisk: fix struct padding for amd64 (from erik quanstros fdisk-64-bit-table patch)

small little patch to help fdisk work properly on 64-bit machines.
sizeof(Table) is 4 bytes too big.
This commit is contained in:
cinap_lenrek 2013-10-16 04:34:58 +02:00
parent 0f994b1b09
commit 87e187b09c

View file

@ -246,6 +246,8 @@ enum {
Toffset = 446, /* offset of partition table in sector */ Toffset = 446, /* offset of partition table in sector */
Magic0 = 0x55, Magic0 = 0x55,
Magic1 = 0xAA, Magic1 = 0xAA,
Tablesize = NTentry*sizeof(Tentry) + 2,
}; };
struct Table { struct Table {
@ -454,7 +456,7 @@ recover(Edit *edit)
err = 0; err = 0;
for(i=0; i<nrtab; i++) for(i=0; i<nrtab; i++)
if(diskwrite(edit->disk, &rtab[i].table, sizeof(Table), rtab[i].lba, Toffset) < 0) if(diskwrite(edit->disk, &rtab[i].table, Tablesize, rtab[i].lba, Toffset) < 0)
err = 1; err = 1;
if(err) { if(err) {
fprint(2, "warning: some writes failed during restoration of old partition tables\n"); fprint(2, "warning: some writes failed during restoration of old partition tables\n");
@ -499,7 +501,7 @@ rdpart(Edit *edit, uvlong xbase, uvlong ebrstart, int ebrtype)
if(xbase == 0) if(xbase == 0)
xbase = ebrstart; xbase = ebrstart;
diskread(edit->disk, &table, sizeof table, ebrstart, Toffset); diskread(edit->disk, &table, Tablesize, ebrstart, Toffset);
addrecover(table, ebrstart); addrecover(table, ebrstart);
if(table.magic[0] != Magic0 || table.magic[1] != Magic1) if(table.magic[0] != Magic0 || table.magic[1] != Magic1)
return; return;
@ -533,7 +535,7 @@ findmbr(Edit *edit)
{ {
Table table; Table table;
diskread(edit->disk, &table, sizeof(Table), 0, Toffset); diskread(edit->disk, &table, Tablesize, 0, Toffset);
if(table.magic[0] != Magic0 || table.magic[1] != Magic1) if(table.magic[0] != Magic0 || table.magic[1] != Magic1)
sysfatal("did not find master boot record"); sysfatal("did not find master boot record");
} }
@ -1022,14 +1024,14 @@ wrextend(Edit *edit, int i, vlong xbase, vlong startlba, vlong *endlba)
Finish: Finish:
if(startlba < *endlba){ if(startlba < *endlba){
disk = edit->disk; disk = edit->disk;
diskread(disk, &table, sizeof table, startlba, Toffset); diskread(disk, &table, Tablesize, startlba, Toffset);
tp = table.entry; tp = table.entry;
ep = tp+NTentry; ep = tp+NTentry;
for(; tp<ep; tp++) for(; tp<ep; tp++)
memset(tp, 0, sizeof *tp); memset(tp, 0, sizeof *tp);
table.magic[0] = Magic0; table.magic[0] = Magic0;
table.magic[1] = Magic1; table.magic[1] = Magic1;
if(diskwrite(edit->disk, &table, sizeof table, startlba, Toffset) < 0) if(diskwrite(edit->disk, &table, Tablesize, startlba, Toffset) < 0)
recover(edit); recover(edit);
} }
return i; return i;
@ -1041,7 +1043,7 @@ wrextend(Edit *edit, int i, vlong xbase, vlong startlba, vlong *endlba)
} }
disk = edit->disk; disk = edit->disk;
diskread(disk, &table, sizeof table, startlba, Toffset); diskread(disk, &table, Tablesize, startlba, Toffset);
tp = table.entry; tp = table.entry;
ep = tp+NTentry; ep = tp+NTentry;
@ -1077,7 +1079,7 @@ wrextend(Edit *edit, int i, vlong xbase, vlong startlba, vlong *endlba)
table.magic[0] = Magic0; table.magic[0] = Magic0;
table.magic[1] = Magic1; table.magic[1] = Magic1;
if(diskwrite(edit->disk, &table, sizeof table, startlba, Toffset) < 0) if(diskwrite(edit->disk, &table, Tablesize, startlba, Toffset) < 0)
recover(edit); recover(edit);
return ni; return ni;
} }
@ -1094,7 +1096,7 @@ wrpart(Edit *edit)
disk = edit->disk; disk = edit->disk;
diskread(disk, &table, sizeof table, 0, Toffset); diskread(disk, &table, Tablesize, 0, Toffset);
tp = table.entry; tp = table.entry;
ep = tp+NTentry; ep = tp+NTentry;
@ -1119,7 +1121,7 @@ wrpart(Edit *edit)
if(i != edit->npart) if(i != edit->npart)
sysfatal("cannot happen #1"); sysfatal("cannot happen #1");
if(diskwrite(disk, &table, sizeof table, 0, Toffset) < 0) if(diskwrite(disk, &table, Tablesize, 0, Toffset) < 0)
recover(edit); recover(edit);
/* bring parts up to date */ /* bring parts up to date */