"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "mformat.c" between
mtools-4.0.35.tar.bz2 and mtools-4.0.36.tar.bz2

About: Mtools is a collection of utilities to access MS-DOS disks from Unix without mounting them.

mformat.c  (mtools-4.0.35.tar.bz2):mformat.c  (mtools-4.0.36.tar.bz2)
skipping to change at line 206 skipping to change at line 206
memset(buf, '\0', Fs->sector_size); memset(buf, '\0', Fs->sector_size);
if(Fs->fat_bits == 32) { if(Fs->fat_bits == 32) {
/* on a FAT32 system, we only write one sector, /* on a FAT32 system, we only write one sector,
* as the directory can be extended at will...*/ * as the directory can be extended at will...*/
dirlen = Fs->cluster_size; dirlen = Fs->cluster_size;
fatAllocate(Fs, Fs->rootCluster, Fs->end_fat); fatAllocate(Fs, Fs->rootCluster, Fs->end_fat);
} else } else
dirlen = Fs->dir_len; dirlen = Fs->dir_len;
for (i = 0; i < dirlen; i++) for (i = 0; i < dirlen; i++)
WRITES(RootDir, buf, sectorsToBytes(Fs, i), PWRITES(RootDir, buf, sectorsToBytes(Fs, i),
Fs->sector_size); Fs->sector_size);
ch.ignore_entry = 1; ch.ignore_entry = 1;
if(label[0]) if(label[0])
mwrite_one(RootDir,label, 0, labelit, NULL,&ch); mwrite_one(RootDir,label, 0, labelit, NULL,&ch);
FREE(&RootDir); FREE(&RootDir);
if(Fs->fat_bits == 32) if(Fs->fat_bits == 32)
set_word(boot->boot.dirents, 0); set_word(boot->boot.dirents, 0);
else else
set_word(boot->boot.dirents, set_word(boot->boot.dirents,
skipping to change at line 781 skipping to change at line 781
} }
check_fs_params_and_set_fat(Fs, tot_sectors); check_fs_params_and_set_fat(Fs, tot_sectors);
if(Fs->fat_bits == 32) if(Fs->fat_bits == 32)
fat32_specific_init(Fs); fat32_specific_init(Fs);
return 0; return 0;
} }
void initFsForFormat(Fs_t *Fs) void initFsForFormat(Fs_t *Fs)
{ {
memset(Fs, 0, sizeof(*Fs)); memset(Fs, 0, sizeof(*Fs));
init_head(&Fs->head, &FsClass, NULL);
Fs->Class = &FsClass;
Fs->refs = 1;
Fs->cluster_size = 0; Fs->cluster_size = 0;
Fs->dir_len = 0; Fs->dir_len = 0;
Fs->fat_len = 0; Fs->fat_len = 0;
Fs->num_fat = 2; Fs->num_fat = 2;
Fs->backupBoot = 0; Fs->backupBoot = 0;
} }
void setFsSectorSize(Fs_t *Fs, struct device *dev, uint16_t msize) { void setFsSectorSize(Fs_t *Fs, struct device *dev, uint16_t msize) {
unsigned int j; unsigned int j;
skipping to change at line 824 skipping to change at line 822
struct OldDos_t *params = getOldDosBySize(size); struct OldDos_t *params = getOldDosBySize(size);
if(params != NULL) { if(params != NULL) {
*cyls = params->tracks; *cyls = params->tracks;
*heads = params->heads; *heads = params->heads;
*sects = params->sectors; *sects = params->sectors;
return 0; return 0;
} else } else
return 1; return 1;
} }
static void checkOverflow(uint32_t tot_sectors, int bits) {
if(tot_sectors > UINT32_MAX >> bits) {
fprintf(stderr, "Too many sectors\n");
exit(1);
}
}
static uint32_t parseSize(char *sizeStr) {
char *eptr;
uint32_t tot_sectors = strtou32(sizeStr, &eptr, 10);
if(eptr == optarg) {
fprintf(stderr, "Bad size %s\n", sizeStr);
exit(1);
}
switch(toupper(*eptr)) {
case 'T':
checkOverflow(tot_sectors, 10);
tot_sectors *= 1024;
/* FALL THROUGH */
case 'G':
checkOverflow(tot_sectors, 10);
tot_sectors *= 1024;
/* FALL THROUGH */
case 'M':
checkOverflow(tot_sectors, 10);
tot_sectors *= 1024;
/* FALL THROUGH */
case 'K':
checkOverflow(tot_sectors, 1);
tot_sectors *= 2;
eptr++;
break;
case '\0':
/* By default, assume sectors */
break;
}
if(*eptr) {
fprintf(stderr, "Bad suffix %s\n", eptr);
exit(1);
}
return tot_sectors;
}
static void usage(int ret) NORETURN; static void usage(int ret) NORETURN;
static void usage(int ret) static void usage(int ret)
{ {
fprintf(stderr, fprintf(stderr,
"Mtools version %s, dated %s\n", mversion, mdate); "Mtools version %s, dated %s\n", mversion, mdate);
fprintf(stderr, fprintf(stderr,
"Usage: %s [-V] [-t tracks] [-h heads] [-n sectors] " "Usage: %s [-V] [-t tracks] [-h heads] [-n sectors] "
"[-v label] [-1] [-4] [-8] [-f size] " "[-v label] [-1] [-4] [-8] [-f size] "
"[-N serialnumber] " "[-N serialnumber] "
"[-k] [-B bootsector] [-r root_dir_len] [-L fat_len] " "[-k] [-B bootsector] [-r root_dir_len] [-L fat_len] "
skipping to change at line 1181 skipping to change at line 1136
#ifdef USE_XDF #ifdef USE_XDF
if(create && format_xdf) { if(create && format_xdf) {
fprintf(stderr,"Create and XDF can't be used together\n"); fprintf(stderr,"Create and XDF can't be used together\n");
exit(1); exit(1);
} }
#endif #endif
/* check out a drive whose letter and parameters match */ /* check out a drive whose letter and parameters match */
sprintf(errmsg, "Drive '%c:' not supported", drive); sprintf(errmsg, "Drive '%c:' not supported", drive);
Fs->Direct = NULL;
blocksize = 0; blocksize = 0;
for(dev=devices;dev->drive;dev++) { for(dev=devices;dev->drive;dev++) {
FREE(&(Fs->Direct)); FREE(&(Fs->head.Next));
/* drive letter */ /* drive letter */
if (dev->drive != drive) if (dev->drive != drive)
continue; continue;
used_dev = *dev; used_dev = *dev;
SET_INT(used_dev.tracks, argtracks); SET_INT(used_dev.tracks, argtracks);
SET_INT(used_dev.heads, argheads); SET_INT(used_dev.heads, argheads);
SET_INT(used_dev.sectors, argsectors); SET_INT(used_dev.sectors, argsectors);
SET_INT(used_dev.use_2m, arguse_2m); SET_INT(used_dev.use_2m, arguse_2m);
SET_INT(used_dev.ssize, argssize); SET_INT(used_dev.ssize, argssize);
skipping to change at line 1210 skipping to change at line 1164
strcpy(name, getVoldName(dev, name)); strcpy(name, getVoldName(dev, name));
#endif #endif
#ifdef USE_XDF #ifdef USE_XDF
if(format_xdf) if(format_xdf)
used_dev.misc_flags |= USE_XDF_FLAG; used_dev.misc_flags |= USE_XDF_FLAG;
info.FatSize=0; info.FatSize=0;
#endif #endif
if(tot_sectors) if(tot_sectors)
used_dev.tot_sectors = tot_sectors; used_dev.tot_sectors = tot_sectors;
Fs->Direct = OpenImage(&used_dev, dev, name, Fs->head.Next = OpenImage(&used_dev, dev, name,
O_RDWR|create, errmsg, O_RDWR|create, errmsg,
ALWAYS_GET_GEOMETRY, ALWAYS_GET_GEOMETRY,
O_RDWR, O_RDWR,
&maxSize, NULL, &maxSize, NULL,
#ifdef USE_XDF #ifdef USE_XDF
&info &info
#else #else
NULL NULL
#endif #endif
); );
#ifdef USE_XDF #ifdef USE_XDF
if(Fs->Direct && info.FatSize) { if(Fs->head.Next && info.FatSize) {
if(!Fs->fat_len) if(!Fs->fat_len)
Fs->fat_len = info.FatSize; Fs->fat_len = info.FatSize;
if(!Fs->dir_len) if(!Fs->dir_len)
Fs->dir_len = info.RootDirSize; Fs->dir_len = info.RootDirSize;
} }
#endif #endif
if (!Fs->Direct) if (!Fs->head.Next)
continue; continue;
if(tot_sectors) if(tot_sectors)
used_dev.tot_sectors = tot_sectors; used_dev.tot_sectors = tot_sectors;
setFsSectorSize(Fs, &used_dev, msize); setFsSectorSize(Fs, &used_dev, msize);
if(!used_dev.blocksize || used_dev.blocksize < Fs->sector_size) if(!used_dev.blocksize || used_dev.blocksize < Fs->sector_size)
blocksize = Fs->sector_size; blocksize = Fs->sector_size;
else else
blocksize = used_dev.blocksize; blocksize = used_dev.blocksize;
if(blocksize > MAX_SECTOR) if(blocksize > MAX_SECTOR)
blocksize = MAX_SECTOR; blocksize = MAX_SECTOR;
if(chs_to_totsectors(&used_dev, errmsg) < 0 || if(chs_to_totsectors(&used_dev, errmsg) < 0 ||
check_if_sectors_fit(dev->tot_sectors, maxSize, blocksize, check_if_sectors_fit(dev->tot_sectors, maxSize, blocksize,
errmsg) < 0) { errmsg) < 0) {
FREE(&Fs->Direct); FREE(&Fs->head.Next);
continue; continue;
} }
if(!tot_sectors) if(!tot_sectors)
tot_sectors = used_dev.tot_sectors; tot_sectors = used_dev.tot_sectors;
/* do a "test" read */ /* do a "test" read */
if (!create && if (!create &&
READS(Fs->Direct, &boot.characters, 0, Fs->sector_size) != PREADS(Fs->head.Next,
&boot.characters, 0, Fs->sector_size) !=
(signed int) Fs->sector_size) { (signed int) Fs->sector_size) {
#ifdef HAVE_SNPRINTF #ifdef HAVE_SNPRINTF
snprintf(errmsg, sizeof(errmsg)-1, snprintf(errmsg, sizeof(errmsg)-1,
"Error reading from '%s', wrong parameters?", "Error reading from '%s', wrong parameters?",
name); name);
#else #else
sprintf(errmsg, sprintf(errmsg,
"Error reading from '%s', wrong parameters?", "Error reading from '%s', wrong parameters?",
name); name);
#endif #endif
FREE(&Fs->Direct); FREE(&Fs->head.Next);
continue; continue;
} }
break; break;
} }
/* print error msg if needed */ /* print error msg if needed */
if ( dev->drive == 0 ){ if ( dev->drive == 0 ){
FREE(&Fs->Direct); FREE(&Fs->head.Next);
fprintf(stderr,"%s: %s\n", argv[0],errmsg); fprintf(stderr,"%s: %s\n", argv[0],errmsg);
exit(1); exit(1);
} }
if(tot_sectors == 0) { if(tot_sectors == 0) {
fprintf(stderr, "Number of sectors not known\n"); fprintf(stderr, "Number of sectors not known\n");
exit(1); exit(1);
} }
/* create the image file if needed */ /* create the image file if needed */
if (create) { if (create) {
WRITES(Fs->Direct, &boot.characters, PWRITES(Fs->head.Next, &boot.characters,
sectorsToBytes(Fs, tot_sectors-1), sectorsToBytes(Fs, tot_sectors-1),
Fs->sector_size); Fs->sector_size);
} }
/* the boot sector */ /* the boot sector */
if(bootSector) { if(bootSector) {
int fd; int fd;
ssize_t ret; ssize_t ret;
fd = open(bootSector, O_RDONLY | O_BINARY | O_LARGEFILE); fd = open(bootSector, O_RDONLY | O_BINARY | O_LARGEFILE);
if(fd < 0) { if(fd < 0) {
perror("open boot sector"); perror("open boot sector");
skipping to change at line 1316 skipping to change at line 1271
if(ret < 0 || (size_t) ret < blocksize) { if(ret < 0 || (size_t) ret < blocksize) {
perror("short read on boot sector"); perror("short read on boot sector");
exit(1); exit(1);
} }
keepBoot = 1; keepBoot = 1;
close(fd); close(fd);
} }
if(!keepBoot && !(used_dev.use_2m & 0x7f)) if(!keepBoot && !(used_dev.use_2m & 0x7f))
memset(boot.characters, '\0', Fs->sector_size); memset(boot.characters, '\0', Fs->sector_size);
Fs->Next = buf_init(Fs->Direct, Fs->head.Next = buf_init(Fs->head.Next,
blocksize * used_dev.heads * used_dev.sectors, blocksize * used_dev.heads * used_dev.sectors,
blocksize * used_dev.heads * used_dev.sectors, blocksize * used_dev.heads * used_dev.sectors,
blocksize); blocksize);
Fs->Buffer = 0;
boot.boot.nfat = Fs->num_fat; boot.boot.nfat = Fs->num_fat;
if(!keepBoot) if(!keepBoot)
set_word(&boot.bytes[510], 0xaa55); set_word(&boot.bytes[510], 0xaa55);
/* Initialize the remaining parameters */ /* Initialize the remaining parameters */
set_word(boot.boot.nsect, used_dev.sectors); set_word(boot.boot.nsect, used_dev.sectors);
set_word(boot.boot.nheads, used_dev.heads); set_word(boot.boot.nheads, used_dev.heads);
switch(calc_fs_parameters(&used_dev, fat32, tot_sectors, Fs, switch(calc_fs_parameters(&used_dev, fat32, tot_sectors, Fs,
skipping to change at line 1465 skipping to change at line 1419
#ifdef USE_XDF #ifdef USE_XDF
if(used_dev.misc_flags & USE_XDF_FLAG) if(used_dev.misc_flags & USE_XDF_FLAG)
for(i=0; for(i=0;
i < (info.BadSectors+Fs->cluster_size-1)/Fs->cluster_size; i < (info.BadSectors+Fs->cluster_size-1)/Fs->cluster_size;
i++) i++)
fatEncode(Fs, i+2, 0xfff7); fatEncode(Fs, i+2, 0xfff7);
#endif #endif
format_root(Fs, label, &boot); format_root(Fs, label, &boot);
if(WRITES((Stream_t *)Fs, boot.characters, 0, Fs->sector_size) < 0) { if(PWRITES((Stream_t *)Fs, boot.characters, 0, Fs->sector_size) < 0) {
fprintf(stderr, "Error writing boot sector\n"); fprintf(stderr, "Error writing boot sector\n");
exit(1); exit(1);
} }
if(Fs->fat_bits == 32 && WORD_S(ext.fat32.backupBoot) != MAX16) { if(Fs->fat_bits == 32 && WORD_S(ext.fat32.backupBoot) != MAX16) {
if(WRITES((Stream_t *)Fs, boot.characters, if(PWRITES((Stream_t *)Fs, boot.characters,
sectorsToBytes(Fs, WORD_S(ext.fat32.backupBoot)), sectorsToBytes(Fs, WORD_S(ext.fat32.backupBoot)),
Fs->sector_size) < 0) { Fs->sector_size) < 0) {
fprintf(stderr, "Error writing backup boot sector\n"); fprintf(stderr, "Error writing backup boot sector\n");
exit(1); exit(1);
} }
} }
FREE((Stream_t **)&Fs); FREE((Stream_t **)&Fs);
#ifdef USE_XDF #ifdef USE_XDF
if(format_xdf && isatty(0) && !getenv("MTOOLS_USE_XDF")) if(format_xdf && isatty(0) && !getenv("MTOOLS_USE_XDF"))
fprintf(stderr, fprintf(stderr,
"Note:\n" "Note:\n"
 End of changes. 19 change blocks. 
76 lines changed or deleted 30 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)