--- partition.h.orig 2009-03-01 00:04:01.000000000 +0100 +++ partition.h 2018-08-16 23:46:33.636671725 +0200 @@ -45,5 +45,6 @@ int consistencyCheck(struct partition *p unsigned int *j, struct device *used_dev, int target_partition); -void setBeginEnd(struct partition *partTable, int begin, int end, - int heads, int sector, int activate, int type); +void setBeginEnd(struct partition *partTable, unsigned int begin, unsigned int end, + unsigned int heads, unsigned int sector, int activate, int type, + int fat_bits); --- mpartition.c.orig 2011-06-29 22:10:51.000000000 +0200 +++ mpartition.c 2018-08-17 00:06:08.603854536 +0200 @@ -70,8 +70,9 @@ static void set_offset(hsc *h, int offse h->cyl = cyl & 0xff; } -void setBeginEnd(struct partition *partTable, int begin, int end, - int heads, int sectors, int activate, int type) +void setBeginEnd(struct partition *partTable, unsigned int begin, unsigned int end, + unsigned int heads, unsigned int sectors, int activate, int type, + int fat_bits) { set_offset(&partTable->start, begin, heads, sectors); set_offset(&partTable->end, end-1, heads, sectors); @@ -82,12 +83,16 @@ void setBeginEnd(struct partition *partT else partTable->boot_ind = 0; if(!type) { - if(end-begin < 4096) - type = 1; /* DOS 12-bit FAT */ - else if(end-begin<32*2048) - type = 4; /* DOS 16-bit FAT, <32M */ + if ((fat_bits == 12 || (fat_bits == 0 && end-begin+1 < 4096)) && end+1 < 65536) + type = 0x01; /* DOS FAT12, CHS */ + else if ((fat_bits == 16 || fat_bits == 0) && end+1 < 65536) + type = 0x04; /* DOS FAT16, CHS */ + else if (fat_bits != 32 && end+1 < sectors * heads * 1024) + type = 0x06; /* DOS BIG FAT16 or FAT12, CHS */ + else if (fat_bits != 32) + type = 0x0E; /* Win95 BIG FAT16, LBA */ else - type = 6; /* DOS 16-bit FAT >= 32M */ + type = 0x0C; /* Win95 FAT32, LBA */ } partTable->sys_ind = type; } @@ -286,7 +291,7 @@ void mpartition(int argc, char **argv, i int verbose = 0; int create = 0; int force = 0; - int length = 0; + unsigned int length = 0; int do_remove = 0; int initialize = 0; unsigned int tot_sectors=0; @@ -298,8 +303,8 @@ void mpartition(int argc, char **argv, i int activate = 0; int has_activated = 0; int inconsistency=0; - int begin=0; - int end=0; + unsigned int begin=0; + unsigned int end=0; int sizetest=0; int dirty = 0; int open2flags = NO_OFFSET; @@ -399,11 +404,11 @@ void mpartition(int argc, char **argv, i break; case 'b': begin_set = 1; - begin = atoi(optarg); + begin = strtoul(optarg, NULL, 10); break; case 'l': size_set = 1; - length = atoi(optarg); + length = strtoul(optarg, NULL, 10); break; default: @@ -656,7 +661,7 @@ void mpartition(int argc, char **argv, i setBeginEnd(&partTable[dev->partition], begin, end, used_dev.heads, used_dev.sectors, - !has_activated, type); + !has_activated, type, 0); } if(activate) { --- mformat.c.orig 2013-01-08 23:14:21.000000000 +0100 +++ mformat.c 2018-08-17 00:07:46.753309584 +0200 @@ -1214,17 +1214,8 @@ void mformat(int argc, char **argv, int keepBoot = 1; close(fd); } - if(!keepBoot && !(used_dev.use_2m & 0x7f)) { + if(!keepBoot && !(used_dev.use_2m & 0x7f)) memset(boot.characters, '\0', Fs.sector_size); - if(Fs.sector_size == 512 && !used_dev.partition) { - /* install fake partition table pointing to itself */ - struct partition *partTable=(struct partition *) - (&boot.bytes[0x1ae]); - setBeginEnd(&partTable[1], 0, - used_dev.heads * used_dev.sectors * used_dev.tracks, - used_dev.heads, used_dev.sectors, 1, 0); - } - } set_dword(boot.boot.nhs, used_dev.hidden); Fs.Next = buf_init(Fs.Direct, @@ -1243,6 +1234,17 @@ void mformat(int argc, char **argv, int used_dev.fat_bits = comp_fat_bits(&Fs,used_dev.fat_bits, tot_sectors, fat32); + if(!keepBoot && !(used_dev.use_2m & 0x7f)) { + if(!used_dev.partition) { + /* install fake partition table pointing to itself */ + struct partition *partTable=(struct partition *) + (&boot.bytes[0x1ae]); + setBeginEnd(&partTable[1], 0, + used_dev.heads * used_dev.sectors * used_dev.tracks, + used_dev.heads, used_dev.sectors, 1, 0, used_dev.fat_bits); + } + } + if(used_dev.fat_bits == 32) { Fs.primaryFat = 0; Fs.writeAllFats = 1;