#define DONT_NEED_WAIT
#include "sysincludes.h"
-#include "msdos.h"
#include "mtools.h"
-#include "mainloop.h"
#include "fsP.h"
#include "file.h"
#include "plain_io.h"
void setBeginEnd(struct partition *partTable,
uint32_t begin, uint32_t end,
uint16_t iheads, uint16_t isectors,
- int activate, uint8_t type, int fat_bits)
+ int activate, uint8_t type, unsigned int fat_bits)
{
uint8_t heads, sectors;
exit(1);
}
sectors=(uint8_t) isectors;
-
+
set_offset(&partTable->start, begin, heads, sectors);
set_offset(&partTable->end, end-1, heads, sectors);
set_dword(partTable->start_sect, begin);
exit(ret);
}
-static void checkTotalSectors(unsigned long tot_sectors) {
- if(tot_sectors > UINT32_MAX) {
- fprintf(stderr, "Too many total sectors %ld\n",
- tot_sectors);
- exit(1);
- }
-}
-
void mpartition(int argc, char **argv, int dummy UNUSEDP) NORETURN;
void mpartition(int argc, char **argv, int dummy UNUSEDP)
{
char errmsg[2100];
char *bootSector=0;
struct partition *tpartition;
-
+
argtracks = 0;
argheads = 0;
argsectors = 0;
break;
case 'l':
size_set = 1;
- length = strtoui(optarg, &endptr, 0);
+ length = parseSize(optarg);
break;
default:
#ifdef USING_NEW_VOLD
strcpy(name, getVoldName(dev, name));
#endif
- Stream = OpenImage(&used_dev, dev, name, mode, errmsg,
+ Stream = OpenImage(&used_dev, dev, name, mode, errmsg,
open2flags | SKIP_PARTITION | ALWAYS_GET_GEOMETRY,
mode, NULL, NULL, NULL);
}
tot_sectors = used_dev.tot_sectors;
-
+
/* read the partition table */
- if (READS(Stream, (char *) buf, 0, 512) != 512 && !initialize){
+ if (PREADS(Stream, (char *) buf, 0, 512) != 512 && !initialize){
#ifdef HAVE_SNPRINTF
snprintf(errmsg, sizeof(errmsg)-1,
"Error reading from '%s', wrong parameters?",
if(!used_dev.sectors && !used_dev.heads) {
if(tot_sectors) {
- checkTotalSectors(tot_sectors);
setsize0((uint32_t)tot_sectors,&dummy2,&used_dev.heads,
&used_dev.sectors);
} else {
if(create) {
unsigned int overlap;
if(!end_set && !size_set && tot_sectors) {
- checkTotalSectors(tot_sectors);
- end = (uint32_t) tot_sectors -
- (uint32_t) tot_sectors % sec_per_cyl;
+ end = tot_sectors - tot_sectors % sec_per_cyl;
end_set = 1;
}
fprintf(stderr, "Begin larger than end\n");
exit(1);
}
-
+
/* Check whether new partition doesn't overlap with
* any of those already in place */
if((overlap=findOverlap(partTable, 4, begin, end))) {
setBeginEnd(tpartition, begin, end,
used_dev.heads, used_dev.sectors,
!has_activated, type,
- dev->fat_bits);
+ abs(dev->fat_bits));
}
if(activate) {
printf("The following command will recreate the partition for drive %c:\n",
drive);
used_dev.tracks =
- (_DWORD(tpartition->nr_sects) +
+ (DWORD(tpartition->nr_sects) +
(BEGIN(tpartition) % sec_per_cyl)) /
sec_per_cyl;
printf("mpartition -c -b %d -l %d -t %d -h %d -s %d -b %u %c:\n",
/* write data back to the disk */
if(verbose>=2)
print_sector("Writing sector", buf, 512);
- if (WRITES(Stream, (char *) buf, 0, 512) != 512) {
+ if (PWRITES(Stream, (char *) buf, 0, 512) != 512) {
fprintf(stderr,"Error writing partition table");
exit(1);
}