Skip to content

Commit

Permalink
Import files from mtools-4.0.23
Browse files Browse the repository at this point in the history
  • Loading branch information
hamishcoleman committed Dec 10, 2018
1 parent 30447c2 commit 1062dca
Show file tree
Hide file tree
Showing 94 changed files with 3,547 additions and 498 deletions.
8 changes: 4 additions & 4 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ mpartition.1 mpartition.c mrd.1 \
mren.1 msdos.h mshortname.1 mshowfat.1 mtoolstest.1 mtools.1 mtools.5 mtools.c \
mtools.conf mtools.h mtype.1 nameclash.h patchlevel.c \
plain_io.c plain_io.h precmd.c privileges.c scripts signal.c stream.c stream.h \
streamcache.c streamcache.h subdir.c sysincludes.h unixdir.c todo \
streamcache.c streamcache.h subdir.c strtonum.c sysincludes.h unixdir.c todo \
vfat.c vfat.h xdf_io.c xdf_io.h

OBJS1 = buffer.o charsetConv.o codepages.o config.o copyfile.o \
Expand All @@ -113,13 +113,13 @@ mdel.o mdir.o mdoctorfat.o mdu.o \
mformat.o minfo.o misc.o missFuncs.o mk_direntry.o mlabel.o mmd.o mmount.o \
mmove.o mpartition.o mshortname.o mshowfat.o mzip.o mtools.o old_dos.o \
patchlevel.o plain_io.o precmd.o privileges.o scsi.o signal.o stream.o \
streamcache.o subdir.o unixdir.o tty.o vfat.o xdf_io.o
streamcache.o subdir.o unixdir.o tty.o vfat.o xdf_io.o strtonum.o

OBJS2 = missFuncs.o mkmanifest.o misc.o patchlevel.o

OBJS3 = floppyd.o llong.o lockdev.o

OBJS4 = floppyd_installtest.o misc.o expand.o privileges.o
OBJS4 = floppyd_installtest.o misc.o expand.o privileges.o strtonum.o

SRCS = buffer.c codepages.c config.c copyfile.c devices.c \
dirCache.c directory.c direntry.c expand.c fat.c fat_free.c file.c file_name.c \
Expand Down Expand Up @@ -329,7 +329,7 @@ depend: $(SRCS)

check:
echo No self tests included
# check target needed even if empty, in order to make life easyer for
# check target needed even if empty, in order to make life easier for
# automatic tools to install GNU soft


Expand Down
32 changes: 19 additions & 13 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v4_0_23
- Address lots of compiler warnings (assignments between different types)
- Network speedup fixes for floppyd (TCP_CORK)
- Typo fixes
- Explicitly pass available target buffer size for character
set conversions
v4_0_22
- Fixed -f flag for mformat (size is KBytes, rather than sectors)
- Fixed toupper/tolower usage (unsigned char rather than plain signed)
Expand Down Expand Up @@ -73,7 +79,7 @@ v4_0_16
Fixed typo in initialization of FAT32 info sector
v4_0_15
Added missing -i option to mshortname
Splitted .deb package into mtools and floppyd in order to
Split .deb package into mtools and floppyd in order to
match Ubuntu
v4_0_14
New mshortname command
Expand Down Expand Up @@ -170,7 +176,7 @@ v20070305
v20060626
Merged Redhat/Fedora patches
v20060531
#ifdef linux-dependant code in mformat.c
#ifdef linux-dependent code in mformat.c
v20060525
Fix gcc4 warnings
Fix reading of boot sector (block size)
Expand Down Expand Up @@ -210,7 +216,7 @@ v20040228
v20030718
Fix rootskip and rate of XDF disks
v20030705
Fix inverted IS_MFORMAT_ONLY conditon in plain_io.c
Fix inverted IS_MFORMAT_ONLY condition in plain_io.c
v20030609
Moved putc after variable description (anybody knows about a -W
flag so that gcc warns about these?)
Expand Down Expand Up @@ -264,7 +270,7 @@ v20021102
v20020125
Fixes for cygwin
Fixes in buffer.c for oddly sized image files
Mformat.c fixes to avoid makeing images which would not be
Mformat.c fixes to avoid making images which would not be
readable in windows.
v20010908
Warn for invalid partition numbers
Expand Down Expand Up @@ -521,7 +527,7 @@ v19971215
Jacked up performance, and corrected signal handling bugs. Also
corrected various "Disk full bugs"
v19971212
Fixed "Bad address" errors which occured when running mdu on empty
Fixed "Bad address" errors which occurred when running mdu on empty
files. When copying recursively, do not barf if a directory
already exist at the target. Mcopy operates silently by default.
v19971212
Expand Down Expand Up @@ -550,7 +556,7 @@ v19971129
Pre-3.9. Redid the mainloop logic, and got rid of lots of cruft
in subdir.c and parse.c. It is now possible to put wildcards in
the directory part of the filename. Design also became simpler,
making it easyer to maintain this part in the future.
making it easier to maintain this part in the future.
Added a -u flag to mzip to temporarily unprotect a disk
Added a test to mzip to prevent manipulation of mounted disks
Added support for partitioned devices in mmount
Expand Down Expand Up @@ -590,7 +596,7 @@ v19970812
Guard against corrupted "next free block" pointer in a FAT32
InfoBlock
v19970715
Use root priviliges during scsi_init
Use root privileges during scsi_init
v19970714
Fixed close-on-exec bug.
v19970714
Expand Down Expand Up @@ -665,11 +671,11 @@ v19970426
v19970423
Prefer termios.h on Ultrix
v19970422
Renamed missing_functions to missFuncs in order to accomodate
Renamed missing_functions to missFuncs in order to accommodate
operating systems with file name size limits.
v19970420
Autoextend size for images that are too small. Moved BSD
dependant #ifdef's after the inclusion of sys/param.h, as it
dependent #ifdef's after the inclusion of sys/param.h, as it
is there where BSD is defined (sigh!)
v19970419
Insist on the fact that mzip's -f flag only makes sense if
Expand Down Expand Up @@ -878,7 +884,7 @@ v19961211
v19961210
Added warning about running mtools with root privs.
v19961209
Fixed unitialized variable in fat.c and added example for Sun
Fixed uninitialized variable in fat.c and added example for Sun
mtools.conf
v19961209
Fixed comment in scripts/tgz
Expand All @@ -895,7 +901,7 @@ v19961202
Test first for tzset in autoconfigure (Solaris)
v19961202
Segment fault due to change of buffer size fixed
E-mail adress fixed
E-mail address fixed
v19961117
Lots of portability fixes.
v19961012
Expand Down Expand Up @@ -935,7 +941,7 @@ v19960609
Beginning of ED and 5 1/4 HD XDF support (doesn't work yet for
ED)
v19960528
Make vold and "raw" floppy drive accesible simultaneously on
Make vold and "raw" floppy drive accessible simultaneously on
Solaris by calling one A: and the other B:
Add missing mbadblock LINK in Makefile.in
v19960527
Expand Down Expand Up @@ -979,7 +985,7 @@ v19960429
v19960427
more spelling fixes.
v19960426
Speling fixes
Spelling fixes
v19960424
Mmount arg parsing bug fix
v19960422
Expand Down
2 changes: 1 addition & 1 deletion buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ typedef struct Buffer_t {

size_t sectorSize; /* sector size: all operations happen
* in multiples of this */
size_t cylinderSize; /* cylinder size: preferred alignemnt,
size_t cylinderSize; /* cylinder size: preferred alignment,
* but for efficiency, less data may be read */
int ever_dirty; /* was the buffer ever dirty? */
size_t dirty_pos;
Expand Down
2 changes: 1 addition & 1 deletion byte_dword.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
static Dword byte2dword(Byte* val)
{
Dword l;
l = (val[0] << 24) + (val[1] << 16) + (val[2] << 8) + val[3];
l = (Dword)((val[0] << 24) + (val[1] << 16) + (val[2] << 8) + val[3]);

return l;
}
Expand Down
22 changes: 13 additions & 9 deletions charsetConv.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,16 @@ int dos_to_wchar(doscp_t *cp, const char *dos, wchar_t *wchar, size_t len)
* mangled will be set if there has been an untranslatable character.
*/
static int safe_iconv(iconv_t conv, const wchar_t *wchar, char *dest,
size_t len, int *mangled)
size_t in_len, size_t out_len, int *mangled)
{
int r;
unsigned int i;
size_t in_len=len*sizeof(wchar_t);
size_t out_len=len;
char *dptr = dest;
size_t len;

while(in_len > 0) {
in_len=in_len*sizeof(wchar_t);

while(in_len > 0 && out_len > 0) {
r=iconv(conv, (char**)&wchar, &in_len, &dptr, &out_len);
if(r >= 0 || errno != EILSEQ) {
/* everything transformed, or error that is _not_ a bad
Expand All @@ -190,7 +191,9 @@ static int safe_iconv(iconv_t conv, const wchar_t *wchar, char *dest,
}
*mangled |= 1;

if(dptr)
if(out_len <= 0)
break;
if(dptr)
*dptr++ = '_';
in_len -= sizeof(wchar_t);

Expand All @@ -215,7 +218,7 @@ static int safe_iconv(iconv_t conv, const wchar_t *wchar, char *dest,
void wchar_to_dos(doscp_t *cp,
wchar_t *wchar, char *dos, size_t len, int *mangled)
{
safe_iconv(cp->to, wchar, dos, len, mangled);
safe_iconv(cp->to, wchar, dos, len, len, mangled);
}

#else
Expand Down Expand Up @@ -361,14 +364,15 @@ static void initialize_to_native(void)
* Convert wchar string to native, converting at most len wchar characters
* Returns number of generated native characters
*/
int wchar_to_native(const wchar_t *wchar, char *native, size_t len)
int wchar_to_native(const wchar_t *wchar, char *native, size_t len,
size_t out_len)
{
#ifdef HAVE_ICONV_H
int mangled;
int r;
initialize_to_native();
len = wcsnlen(wchar,len);
r=safe_iconv(to_native, wchar, native, len*4, &mangled);
r=safe_iconv(to_native, wchar, native, len, out_len, &mangled);
native[r]='\0';
return r;
#else
Expand Down Expand Up @@ -407,7 +411,7 @@ int native_to_wchar(const char *native, wchar_t *wchar, size_t len,
int r = mbrtowc(wchar+i, native, len, &ps);
if(r < 0) {
/* Unconvertible character. Just pretend it's Latin1
encoded (if valid Latin1 character) or substitue
encoded (if valid Latin1 character) or substitute
with an underscore if not
*/
char c = *native;
Expand Down
65 changes: 50 additions & 15 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ static char default_drive='\0'; /* default drive */
unsigned int mtools_skip_check=0;
unsigned int mtools_fat_compatibility=0;
unsigned int mtools_ignore_short_case=0;
unsigned int mtools_rate_0=0;
unsigned int mtools_rate_any=0;
uint8_t mtools_rate_0=0;
uint8_t mtools_rate_any=0;
unsigned int mtools_no_vfat=0;
unsigned int mtools_numeric_tail=1;
unsigned int mtools_dotted_dir=0;
Expand All @@ -75,7 +75,9 @@ typedef struct switches_l {
enum {
T_INT,
T_STRING,
T_UINT
T_UINT,
T_UINT8,
T_UINT16
} type;
} switches_t;

Expand All @@ -84,8 +86,8 @@ static switches_t global_switches[] = {
{ "MTOOLS_FAT_COMPATIBILITY", (caddr_t) & mtools_fat_compatibility, T_UINT },
{ "MTOOLS_SKIP_CHECK", (caddr_t) & mtools_skip_check, T_UINT },
{ "MTOOLS_NO_VFAT", (caddr_t) & mtools_no_vfat, T_UINT },
{ "MTOOLS_RATE_0", (caddr_t) &mtools_rate_0, T_UINT },
{ "MTOOLS_RATE_ANY", (caddr_t) &mtools_rate_any, T_UINT },
{ "MTOOLS_RATE_0", (caddr_t) &mtools_rate_0, T_UINT8 },
{ "MTOOLS_RATE_ANY", (caddr_t) &mtools_rate_any, T_UINT8 },
{ "MTOOLS_NAME_NUMERIC_TAIL", (caddr_t) &mtools_numeric_tail, T_UINT },
{ "MTOOLS_DOTTED_DIR", (caddr_t) &mtools_dotted_dir, T_UINT },
{ "MTOOLS_TWENTY_FOUR_HOUR_CLOCK",
Expand Down Expand Up @@ -168,8 +170,8 @@ static switches_t dswitches[]= {
{ "MODE", OFFS(mode), T_UINT },
{ "TRACKS", OFFS(tracks), T_UINT },
{ "CYLINDERS", OFFS(tracks), T_UINT },
{ "HEADS", OFFS(heads), T_UINT },
{ "SECTORS", OFFS(sectors), T_UINT },
{ "HEADS", OFFS(heads), T_UINT16 },
{ "SECTORS", OFFS(sectors), T_UINT16 },
{ "HIDDEN", OFFS(hidden), T_UINT },
{ "PRECMD", OFFS(precmd), T_STRING },
{ "BLOCKSIZE", OFFS(blocksize), T_UINT },
Expand Down Expand Up @@ -221,6 +223,12 @@ static void get_env_conf(void)
if(global_switches[i].type == T_UINT)
* ((unsigned int *)global_switches[i].address) =
(unsigned int) strtoul(s,0,0);
if(global_switches[i].type == T_UINT8)
* ((uint8_t *)global_switches[i].address) =
(uint8_t) strtou8(s,0,0);
if(global_switches[i].type == T_UINT16)
* ((uint16_t *)global_switches[i].address) =
(uint16_t) strtou8(s,0,0);
else if (global_switches[i].type == T_STRING)
* ((char **)global_switches[i].address) = s;
}
Expand Down Expand Up @@ -306,16 +314,18 @@ static char *get_string(void)
return str;
}

static unsigned int get_unumber(void)
static unsigned long get_unumber(unsigned long max)
{
char *last;
unsigned int n;
unsigned long n;

skip_junk(1);
last = pos;
n=(unsigned int) strtoul(pos, &pos, 0);
n=strtoul(pos, &pos, 0);
if(last == pos)
syntax("numeral expected", 0);
if(n > max)
syntax("number too big", 0);
pos++;
token_nr++;
return n;
Expand Down Expand Up @@ -434,8 +444,14 @@ static int set_var(struct switches_l *switches, int nr,
expect_char('=');
if(switches[i].type == T_UINT)
* ((unsigned int *)((long)switches[i].address+base_address)) =
get_unumber();
if(switches[i].type == T_INT)
(unsigned int) get_unumber(UINT_MAX);
else if(switches[i].type == T_UINT8)
* ((uint8_t *)((long)switches[i].address+base_address)) =
(uint8_t) get_unumber(UINT8_MAX);
else if(switches[i].type == T_UINT16)
* ((uint16_t *)((long)switches[i].address+base_address)) =
(uint16_t) get_unumber(UINT16_MAX);
else if(switches[i].type == T_INT)
* ((int *)((long)switches[i].address+base_address)) =
get_number();
else if (switches[i].type == T_STRING)
Expand Down Expand Up @@ -546,12 +562,27 @@ void set_cmd_line_image(char *img) {
}
}

static uint16_t tou16(int in, const char *comment) {
if(in > UINT16_MAX) {
fprintf(stderr, "Number of %s %d too big\n", comment, in);
exit(1);
}
if(in < 0) {
fprintf(stderr, "Number of %s %d negative\n", comment, in);
exit(1);
}
return (uint16_t) in;

}

static void parse_old_device_line(char drive)
{
char name[MAXPATHLEN];
int items;
long offset;

int heads, sectors;

/* finish any old drive */
finish_drive_clause();

Expand All @@ -560,10 +591,13 @@ static void parse_old_device_line(char drive)

/* reserve slot */
append();
items = sscanf(token,"%c %s %i %ui %ui %ui %li",
items = sscanf(token,"%c %s %i %i %i %i %li",
&devices[cur_dev].drive,name,&devices[cur_dev].fat_bits,
&devices[cur_dev].tracks,&devices[cur_dev].heads,
&devices[cur_dev].sectors, &offset);
&devices[cur_dev].tracks,&heads,
&sectors, &offset);
devices[cur_dev].heads = tou16(heads, "heads");
devices[cur_dev].sectors = tou16(sectors, "sectors");

devices[cur_dev].offset = (off_t) offset;
switch(items){
case 2:
Expand Down Expand Up @@ -596,6 +630,7 @@ static void parse_old_device_line(char drive)
printOom();
exit(1);
}
devices[cur_dev].misc_flags |= MFORMAT_ONLY_FLAG;
finish_drive_clause();
pos=0;
}
Expand Down
Loading

0 comments on commit 1062dca

Please sign in to comment.