summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.in8
-rw-r--r--NEWS32
-rw-r--r--buffer.c2
-rw-r--r--byte_dword.h2
-rw-r--r--charsetConv.c22
-rw-r--r--config.c65
-rw-r--r--config.h.in3
-rwxr-xr-xconfigure4
-rw-r--r--configure.in4
-rw-r--r--copyfile.c10
-rw-r--r--debian/changelog9
-rw-r--r--devices.h10
-rw-r--r--dirCache.c18
-rw-r--r--direntry.c31
-rw-r--r--expand.c6
-rw-r--r--fat_size_calculation.tex6
-rw-r--r--file.c16
-rw-r--r--file_name.c40
-rw-r--r--file_name.h11
-rw-r--r--floppyd.12
-rw-r--r--floppyd.c164
-rw-r--r--floppyd_installtest.12
-rw-r--r--floppyd_installtest.c32
-rw-r--r--floppyd_io.c74
-rw-r--r--floppyd_io.h24
-rw-r--r--hash.c59
-rw-r--r--htable.h11
-rw-r--r--mainloop.c19
-rw-r--r--mainloop.h13
-rw-r--r--mattrib.12
-rw-r--r--mattrib.c2
-rw-r--r--mbadblocks.12
-rw-r--r--mbadblocks.c8
-rw-r--r--mcat.12
-rw-r--r--mcd.12
-rw-r--r--mclasserase.12
-rw-r--r--mclasserase.c2
-rw-r--r--mcomp.12
-rw-r--r--mcopy.12
-rw-r--r--mcopy.c2
-rw-r--r--mdel.12
-rw-r--r--mdel.c8
-rw-r--r--mdeltree.12
-rw-r--r--mdir.12
-rw-r--r--mdir.c36
-rw-r--r--mdoctorfat.c18
-rw-r--r--mdu.12
-rw-r--r--mformat.14
-rw-r--r--mformat.c132
-rw-r--r--minfo.12
-rw-r--r--minfo.c2
-rw-r--r--misc.c2
-rw-r--r--missFuncs.c2
-rw-r--r--mk_direntry.c3
-rw-r--r--mkmanifest.12
-rw-r--r--mkmanifest.c1
-rw-r--r--mlabel.12
-rw-r--r--mlabel.c12
-rw-r--r--mmd.12
-rw-r--r--mmd.c2
-rw-r--r--mmount.12
-rw-r--r--mmove.12
-rw-r--r--mmove.c8
-rw-r--r--mpartition.12
-rw-r--r--mpartition.c23
-rw-r--r--mrd.12
-rw-r--r--mren.12
-rw-r--r--msdos.h8
-rw-r--r--mshortname.12
-rw-r--r--mshowfat.12
-rw-r--r--mtools.110
-rw-r--r--mtools.54
-rw-r--r--mtools.h60
-rw-r--r--mtools.info58
-rw-r--r--mtools.spec7
-rw-r--r--mtools.texi2
-rw-r--r--mtools.tmpl.110
-rw-r--r--mtools.tmpl.54
-rw-r--r--mtoolsDirentry.h5
-rw-r--r--mtoolstest.12
-rw-r--r--mtype.12
-rw-r--r--mzip.12
-rw-r--r--mzip.c4
-rw-r--r--patchlevel.c6
-rw-r--r--plain_io.c4
-rw-r--r--privileges.c4
-rw-r--r--read_dword.h2
-rw-r--r--strtonum.c84
-rw-r--r--sysincludes.h29
-rw-r--r--version.texi4
-rw-r--r--vfat.c16
-rw-r--r--xdf_io.c9
-rw-r--r--xdf_io.h6
93 files changed, 825 insertions, 527 deletions
diff --git a/Makefile.in b/Makefile.in
index 7ea3384..616d59f 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -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 \
@@ -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 \
@@ -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
diff --git a/NEWS b/NEWS
index df9d0f8..4215884 100644
--- a/NEWS
+++ b/NEWS
@@ -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)
@@ -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
@@ -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)
@@ -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?)
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -979,7 +985,7 @@ v19960429
v19960427
more spelling fixes.
v19960426
- Speling fixes
+ Spelling fixes
v19960424
Mmount arg parsing bug fix
v19960422
diff --git a/buffer.c b/buffer.c
index f6334d5..e129ac4 100644
--- a/buffer.c
+++ b/buffer.c
@@ -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;
diff --git a/byte_dword.h b/byte_dword.h
index c7963ea..c3c3b97 100644
--- a/byte_dword.h
+++ b/byte_dword.h
@@ -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;
}
diff --git a/charsetConv.c b/charsetConv.c
index f2dece3..8734be5 100644
--- a/charsetConv.c
+++ b/charsetConv.c
@@ -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
@@ -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);
@@ -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
@@ -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
@@ -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;
diff --git a/config.c b/config.c
index dacb796..265d494 100644
--- a/config.c
+++ b/config.c
@@ -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;
@@ -75,7 +75,9 @@ typedef struct switches_l {
enum {
T_INT,
T_STRING,
- T_UINT
+ T_UINT,
+ T_UINT8,
+ T_UINT16
} type;
} switches_t;
@@ -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",
@@ -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 },
@@ -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;
}
@@ -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;
@@ -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)
@@ -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();
@@ -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:
@@ -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;
}
diff --git a/config.h.in b/config.h.in
index 665b2ca..1e293ca 100644
--- a/config.h.in
+++ b/config.h.in
@@ -135,6 +135,9 @@
/* Define to 1 if you have the <netinet/in.h> header file. */
#undef HAVE_NETINET_IN_H
+/* Define to 1 if you have the <netinet/tcp.h> header file. */
+#undef HAVE_NETINET_TCP_H
+
/* Define when the compiler supports OFFSET_T type */
#undef HAVE_OFFSET_T
diff --git a/configure b/configure
index 88da67c..47ac5b5 100755
--- a/configure
+++ b/configure
@@ -1350,7 +1350,7 @@ Optional Features:
--enable-xdf support for OS/2 extended density format disks
--enable-vold compatibility with Solaris' vold
--enable-new-vold compatibility with Solaris' vold, new version
- --enable-debug debuging messages
+ --enable-debug debugging messages
--enable-raw-term raw terminal (readkey behaviour, default)
--enable-floppyd floppy daemon support
@@ -4535,7 +4535,7 @@ fi
for ac_header in getopt.h sys/stat.h stdlib.h unistd.h linux/unistd.h \
libc.h fcntl.h limits.h sys/file.h sys/ioctl.h sys/time.h strings.h string.h \
sys/param.h memory.h malloc.h io.h signal.h sys/signal.h utime.h sgtty.h \
-sys/floppy.h mntent.h sys/sysmacros.h netinet/in.h assert.h \
+sys/floppy.h mntent.h sys/sysmacros.h netinet/in.h netinet/tcp.h assert.h \
iconv.h wctype.h wchar.h locale.h linux/fs.h
do :
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
diff --git a/configure.in b/configure.in
index f0a856f..d9632f4 100644
--- a/configure.in
+++ b/configure.in
@@ -67,7 +67,7 @@ fi])
dnl Check for configuration options
dnl Debugging
AC_ARG_ENABLE(debug,
-[ --enable-debug debuging messages],
+[ --enable-debug debugging messages],
[if test x$enableval = xyes; then
AC_DEFINE([DEBUG],1,[Define for debugging messages])
fi])
@@ -95,7 +95,7 @@ AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(getopt.h sys/stat.h stdlib.h unistd.h linux/unistd.h \
libc.h fcntl.h limits.h sys/file.h sys/ioctl.h sys/time.h strings.h string.h \
sys/param.h memory.h malloc.h io.h signal.h sys/signal.h utime.h sgtty.h \
-sys/floppy.h mntent.h sys/sysmacros.h netinet/in.h assert.h \
+sys/floppy.h mntent.h sys/sysmacros.h netinet/in.h netinet/tcp.h assert.h \
iconv.h wctype.h wchar.h locale.h linux/fs.h)
AC_CHECK_HEADERS(termio.h sys/termio.h, [break])
AC_CHECK_HEADERS(termios.h sys/termios.h, [break])
diff --git a/copyfile.c b/copyfile.c
index 282c649..ad5b3d0 100644
--- a/copyfile.c
+++ b/copyfile.c
@@ -28,7 +28,8 @@ int copyfile(Stream_t *Source, Stream_t *Target)
{
char buffer[8*16384];
mt_off_t pos;
- int ret, retw;
+ int ret;
+ ssize_t retw;
/* size_t len;*/
mt_size_t mt_len;
@@ -56,13 +57,14 @@ int copyfile(Stream_t *Source, Stream_t *Target)
return -1;
if (ret == 0)
break;
- if ((retw = force_write(Target, buffer, (mt_off_t) pos, ret)) != ret){
+ if ((retw = force_write(Target, buffer,
+ (mt_off_t) pos, (size_t) ret)) != ret){
if(retw < 0 )
perror("write in copy");
else
fprintf(stderr,
- "Short write %d instead of %d\n", retw,
- ret);
+ "Short write %lu instead of %d\n",
+ (unsigned long) retw, ret);
if(errno == ENOSPC)
got_signal = 1;
return ret;
diff --git a/debian/changelog b/debian/changelog
index bd4256c..06ea894 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+mtools (4.0.23) stable; urgency=low
+ * 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
+
+ -- Alain Knaff <alain@knaff.lu> Sun, 9 Dec 2018 23:26:50 +0100
mtools (4.0.22) stable; urgency=low
* Fixed -f flag for mformat (size is KBytes, rather than sectors)
* Fixed toupper/tolower usage (unsigned char rather than plain signed)
@@ -80,7 +87,7 @@ mtools (4.0.16) stable; urgency=low
mtools (4.0.15) stable; urgency=low
* 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
-- Alain Knaff <alain@knaff.lu> Sun, 17 Oct 2010 19:42:46 +0200
diff --git a/devices.h b/devices.h
index 1d0e236..7ca2feb 100644
--- a/devices.h
+++ b/devices.h
@@ -61,7 +61,7 @@ UNUSED(static __inline__ void RR_INIT(struct floppy_raw_cmd *request))
request->reply_count = 0;
}
-UNUSED(static __inline__ void RR_SETRATE(struct floppy_raw_cmd *request, int rate))
+UNUSED(static __inline__ void RR_SETRATE(struct floppy_raw_cmd *request, uint8_t rate))
{
request->rate = rate;
}
@@ -71,7 +71,7 @@ UNUSED(static __inline__ void RR_SETDRIVE(struct floppy_raw_cmd *request,int dri
request->cmd[1] = (request->cmd[1] & ~3) | (drive & 3);
}
-UNUSED(static __inline__ void RR_SETTRACK(struct floppy_raw_cmd *request,int track))
+UNUSED(static __inline__ void RR_SETTRACK(struct floppy_raw_cmd *request,uint8_t track))
{
request->cmd[2] = track;
}
@@ -82,7 +82,7 @@ UNUSED(static __inline__ void RR_SETPTRACK(struct floppy_raw_cmd *request,
request->track = track;
}
-UNUSED(static __inline__ void RR_SETHEAD(struct floppy_raw_cmd *request, int head))
+UNUSED(static __inline__ void RR_SETHEAD(struct floppy_raw_cmd *request, uint8_t head))
{
if(head)
request->cmd[1] |= 4;
@@ -92,14 +92,14 @@ UNUSED(static __inline__ void RR_SETHEAD(struct floppy_raw_cmd *request, int hea
}
UNUSED(static __inline__ void RR_SETSECTOR(struct floppy_raw_cmd *request,
- int sector))
+ uint8_t sector))
{
request->cmd[4] = sector;
request->cmd[6] = sector-1;
}
UNUSED(static __inline__ void RR_SETSIZECODE(struct floppy_raw_cmd *request,
- int sizecode))
+ uint8_t sizecode))
{
request->cmd[5] = sizecode;
request->cmd[6]++;
diff --git a/dirCache.c b/dirCache.c
index 00a3d39..5c9dc12 100644
--- a/dirCache.c
+++ b/dirCache.c
@@ -34,8 +34,8 @@ static __inline__ uint32_t rol(uint32_t arg, int shift)
static uint32_t calcHash(wchar_t *name)
{
uint32_t hash;
- int i;
- wchar_t c;
+ unsigned int i;
+ wint_t c;
hash = 0;
i = 0;
@@ -46,7 +46,7 @@ static uint32_t calcHash(wchar_t *name)
* prime with 32, which makes sure that
* successive letters cannot cover each
* other easily */
- c = (wchar_t)towupper((wint_t)*name);
+ c = towupper((wint_t)*name);
hash ^= (c * (c+2)) ^ (i * (i+2));
hash &= 0xffffffff;
i++, name++;
@@ -151,9 +151,9 @@ dirCache_t *allocDirCache(Stream_t *Stream, unsigned int slot)
return 0;
}
(*dcp)->nr_entries = (slot+1) * 2;
- memset( (*dcp)->bm0, 0, DC_BITMAP_SIZE);
- memset( (*dcp)->bm1, 0, DC_BITMAP_SIZE);
- memset( (*dcp)->bm2, 0, DC_BITMAP_SIZE);
+ memset( (*dcp)->bm0, 0, sizeof((*dcp)->bm0));
+ memset( (*dcp)->bm1, 0, sizeof((*dcp)->bm1));
+ memset( (*dcp)->bm2, 0, sizeof((*dcp)->bm1));
(*dcp)->nrHashed = 0;
} else
if(growDirCache(*dcp, slot) < 0)
@@ -217,7 +217,7 @@ static int freeDirCacheRange(dirCache_t *cache,
free(entry->shortName);
free(entry);
if(needWriteEnd) {
- return beginSlot;
+ return (int) beginSlot;
}
}
@@ -227,7 +227,7 @@ static int freeDirCacheRange(dirCache_t *cache,
}
static dirCacheEntry_t *allocDirCacheEntry(dirCache_t *cache,
- int beginSlot,
+ unsigned int beginSlot,
unsigned int endSlot,
dirCacheEntryType_t type)
{
@@ -330,7 +330,7 @@ dirCacheEntry_t *addFreeEndEntry(dirCache_t *cache,
return 0;
entry = allocDirCacheEntry(cache, beginSlot, endSlot, DCET_FREE);
if(isAtEnd)
- entry->endMarkPos = beginSlot;
+ entry->endMarkPos = (int) beginSlot;
mergeFreeSlots(cache, beginSlot);
mergeFreeSlots(cache, endSlot);
return cache->entries[beginSlot];
diff --git a/direntry.c b/direntry.c
index 4723b33..3d79dc9 100644
--- a/direntry.c
+++ b/direntry.c
@@ -42,9 +42,9 @@ direntry_t *getParent(direntry_t *entry)
}
-static int getPathLen(direntry_t *entry)
+static size_t getPathLen(direntry_t *entry)
{
- int length=0;
+ size_t length=0;
while(1) {
if(entry->entry == -3) /* rootDir */
@@ -55,19 +55,26 @@ static int getPathLen(direntry_t *entry)
}
}
-static char *sprintPwd(direntry_t *entry, char *ptr)
+static char *sprintPwd(direntry_t *entry, char *ptr, size_t *len_available)
{
if(entry->entry == -3) {
*ptr++ = getDrive(entry->Dir);
*ptr++ = ':';
*ptr++ = '/';
+ (*len_available) -= 3;
} else {
- ptr = sprintPwd(getDirentry(entry->Dir), ptr);
- if(ptr[-1] != '/')
+ size_t bytes_converted;
+ ptr = sprintPwd(getDirentry(entry->Dir), ptr, len_available);
+ if(ptr[-1] != '/') {
*ptr++ = '/';
- ptr += wchar_to_native(entry->name, ptr, MAX_VNAMELEN);
+ (*len_available)--;
+ }
+ bytes_converted = wchar_to_native(entry->name, ptr,
+ MAX_VNAMELEN, *len_available);
+ ptr += bytes_converted;
+ (*len_available) -= bytes_converted;
}
- return ptr;
+ return ptr;
}
@@ -96,7 +103,7 @@ static void _fprintPwd(FILE *f, direntry_t *entry, int recurs, int escape)
}
} else {
char tmp[4*MAX_VNAMELEN+1];
- wchar_to_native(entry->name,tmp,MAX_VNAMELEN);
+ WCHAR_TO_NATIVE(entry->name,tmp,MAX_VNAMELEN);
fprintf(f, "/%s", tmp);
}
}
@@ -140,15 +147,17 @@ void fprintShortPwd(FILE *f, direntry_t *entry)
char *getPwd(direntry_t *entry)
{
- int size;
+ size_t size;
char *ret;
char *end;
+ size_t buf_size;
size = getPathLen(entry);
- ret = malloc(size*4+1);
+ buf_size = size*4+1;
+ ret = malloc(buf_size);
if(!ret)
return 0;
- end = sprintPwd(entry, ret);
+ end = sprintPwd(entry, ret, &buf_size);
*end = '\0';
return ret;
}
diff --git a/expand.c b/expand.c
index fc3a08d..ccad8c4 100644
--- a/expand.c
+++ b/expand.c
@@ -22,12 +22,12 @@
#include "mtools.h"
#ifndef OS_mingw32msvc
-int safePopenOut(const char **command, char *output, int len)
+ssize_t safePopenOut(const char **command, char *output, size_t len)
{
int pipefd[2];
pid_t pid;
int status;
- int last;
+ ssize_t last;
if(pipe(pipefd)) {
return -2;
@@ -65,7 +65,7 @@ int safePopenOut(const char **command, char *output, int len)
const char *expand(const char *input, char *ans)
{
#ifndef OS_mingw32msvc
- int last;
+ ssize_t last;
char buf[256];
const char *command[] = { "/bin/sh", "sh", "-c", 0, 0 };
diff --git a/fat_size_calculation.tex b/fat_size_calculation.tex
index 6737cca..f5189a3 100644
--- a/fat_size_calculation.tex
+++ b/fat_size_calculation.tex
@@ -27,7 +27,7 @@
This small document explains the formula used by {\tt mformat.c} to
figure out fat size and number of clusters. Due to the way that
filesystem parameters are stored in the boot sector, we can afford to
-have a FAT that is larger than need to be to accomodate the clusters
+have a FAT that is larger than need to be to accommodate the clusters
present on disk, but under no circumstances can we have one that is
too small.
@@ -146,7 +146,7 @@ space for one more cluster (i.e. not enough space for data + FAT, but
enough for data alone). This situation, combined with a situation
where the last FAT sector was flush full could have lead to a
situation where $numClus$ would become too large for the FAT to
-accomodate. I think this is clearer with an example:
+accommodate. I think this is clearer with an example:
\begin{itemize}
\item $remSect=4127$, $clusSiz=1$, $nfats=1$
\item (Non rounded down) $numClus={(4127+2)*(1024) \over 1032} -
@@ -163,7 +163,7 @@ needed number of FAT sectors to 17, nicely solving this problem.
The downside of counting the fractional part however is that we quite
often waste a sector in the really common situation where both $nfats$
and $clusSiz$ are even, while $remSect$ is odd. An easy way to address
-this is to substract one from $remSect$ before application of the
+this is to subtract one from $remSect$ before application of the
formula, if this case is detected. Such operation carries no risk, as
the odd final sector cannot be used to make a full cluster.
diff --git a/file.c b/file.c
index 8ed9350..6ae7555 100644
--- a/file.c
+++ b/file.c
@@ -46,7 +46,7 @@ typedef struct File_t {
/* Relative position of previous cluster */
unsigned int PreviousRelCluNr;
direntry_t direntry;
- int hint;
+ size_t hint;
struct dirCache_t *dcp;
unsigned int loopDetectRel;
@@ -82,7 +82,7 @@ direntry_t *getDirentry(Stream_t *Stream)
static int recalcPreallocSize(File_t *This)
{
size_t currentClusters, neededClusters;
- int clus_size;
+ unsigned int clus_size;
int neededPrealloc;
Fs_t *Fs = This->Fs;
int r;
@@ -146,7 +146,7 @@ static unsigned int _countBlocks(Fs_t *This, unsigned int block)
block = fatDecode(This, block);
rel++;
if(_loopDetect(&oldrel, rel, &oldabs, block) < 0)
- block = -1;
+ block = 1;
}
return blocks;
}
@@ -175,7 +175,7 @@ void printFat(Stream_t *Stream)
{
File_t *This = getUnbufferedFile(Stream);
unsigned long n;
- int rel;
+ unsigned int rel;
unsigned long begin, end;
int first;
@@ -244,14 +244,14 @@ void printFatWithOffset(Stream_t *Stream, off_t offset) {
static int normal_map(File_t *This, off_t where, size_t *len, int mode,
mt_off_t *res)
{
- int offset;
+ unsigned int offset;
size_t end;
int NrClu; /* number of clusters to read */
unsigned int RelCluNr;
unsigned int CurCluNr;
unsigned int NewCluNr;
unsigned int AbsCluNr;
- int clus_size;
+ unsigned int clus_size;
Fs_t *Fs = This->Fs;
*res = 0;
@@ -562,14 +562,14 @@ static unsigned int getAbsCluNr(File_t *This)
return 1;
}
-static unsigned int func1(void *Stream)
+static size_t func1(void *Stream)
{
DeclareThis(File_t);
return getAbsCluNr(This) ^ (long) This->Fs;
}
-static unsigned int func2(void *Stream)
+static size_t func2(void *Stream)
{
DeclareThis(File_t);
diff --git a/file_name.c b/file_name.c
index caef196..8dac0aa 100644
--- a/file_name.c
+++ b/file_name.c
@@ -24,7 +24,7 @@
#include "file_name.h"
/* Write a DOS name + extension into a legal unix-style name. */
-char *unix_normalize (doscp_t *cp, char *ans, dos_name_t *dn)
+char *unix_normalize (doscp_t *cp, char *ans, dos_name_t *dn, size_t ans_size)
{
char buffer[13];
wchar_t wbuffer[13];
@@ -40,7 +40,7 @@ char *unix_normalize (doscp_t *cp, char *ans, dos_name_t *dn)
}
*a++ = '\0';
dos_to_wchar(cp, buffer, wbuffer, 13);
- wchar_to_native(wbuffer, ans, 13);
+ wchar_to_native(wbuffer, ans, 13, ans_size);
return ans;
}
@@ -50,12 +50,12 @@ typedef enum Case_l {
LOWER
} Case_t;
-static void TranslateToDos(doscp_t *toDos, const char *in, char *out, int count,
- char *end, Case_t *Case, int *mangled)
+static void TranslateToDos(doscp_t *toDos, const char *in, char *out,
+ size_t count, char *end, Case_t *Case, int *mangled)
{
wchar_t buffer[12];
wchar_t *s=buffer;
- wchar_t *t=buffer;
+ size_t t_idx = 0;
/* first convert to wchar, so we get to use towupper etc. */
native_to_wchar(in, buffer, count, end, mangled);
@@ -69,27 +69,27 @@ static void TranslateToDos(doscp_t *toDos, const char *in, char *out, int count,
continue;
}
- if (iswcntrl(*s)) {
+ if (iswcntrl((wint_t)*s)) {
/* "control" characters */
*mangled |= 3;
- *t = '_';
- } else if (iswlower(*s)) {
- *t = towupper(*s);
+ buffer[t_idx] = '_';
+ } else if (iswlower((wint_t)*s)) {
+ buffer[t_idx] = ch_towupper(*s);
if(*Case == UPPER && !mtools_no_vfat)
*mangled |= 1;
else
*Case = LOWER;
- } else if (iswupper(*s)) {
- *t = *s;
+ } else if (iswupper((wint_t)*s)) {
+ buffer[t_idx] = *s;
if(*Case == LOWER && !mtools_no_vfat)
*mangled |= 1;
else
*Case = UPPER;
} else
- *t = *s;
- t++;
+ buffer[t_idx] = *s;
+ t_idx++;
}
- wchar_to_dos(toDos, buffer, out, t - buffer, mangled);
+ wchar_to_dos(toDos, buffer, out, t_idx, mangled);
}
/* dos_name
@@ -102,7 +102,7 @@ void dos_name(doscp_t *toDos, const char *name, int verbose UNUSEDP,
int *mangled, dos_name_t *dn)
{
char *s, *ext;
- register int i;
+ size_t i;
Case_t BaseCase, ExtCase = UPPER;
*mangled = 0;
@@ -206,10 +206,14 @@ int unicode_write(wchar_t *in, struct unicode_char *out, int num, int *end_p)
for (j=0; j<num; ++j) {
if (*end_p)
/* Fill with 0xff */
- out->uchar = out->lchar = (char) 0xff;
+ out->uchar = out->lchar = 0xff;
else {
- out->uchar = *in >> 8;
- out->lchar = *in;
+ /* TODO / FIXME : handle case where wchat has more
+ * than 2 bytes (i.e. bytes 2 or 3 are set.
+ * ==> generate surrogate pairs?
+ */
+ out->uchar = (*in & 0xffff) >> 8;
+ out->lchar = *in & 0xff;
if (! *in) {
*end_p = VSE_LAST;
}
diff --git a/file_name.h b/file_name.h
index 132a391..cc7039a 100644
--- a/file_name.h
+++ b/file_name.h
@@ -26,8 +26,8 @@
* MYFILE TXT
*/
struct dos_name_t {
- char base[8];
- char ext[3];
+ char base[8] NONULLTERM;
+ char ext[3] NONULLTERM;
char sentinel;
};
@@ -37,7 +37,12 @@ void wchar_to_dos(doscp_t *toDos, wchar_t *wchar, char *dos, size_t len, int *ma
doscp_t *cp_open(int codepage);
void cp_close(doscp_t *cp);
-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);
+
+#define WCHAR_TO_NATIVE(wchar,native,len) \
+ wchar_to_native((wchar),(native),(len),sizeof(native))
+
int native_to_wchar(const char *native, wchar_t *wchar, size_t len,
const char *end, int *mangled);
diff --git a/floppyd.1 b/floppyd.1
index 83d156d..69706c9 100644
--- a/floppyd.1
+++ b/floppyd.1
@@ -1,5 +1,5 @@
'\" t
-.TH floppyd 1 "02Dec18" mtools-4.0.22
+.TH floppyd 1 "10Dec18" mtools-4.0.23
.SH Name
floppyd - floppy daemon for remote access to floppy drive
'\" t
diff --git a/floppyd.c b/floppyd.c
index 26a380e..cfe3d3f 100644
--- a/floppyd.c
+++ b/floppyd.c
@@ -101,9 +101,6 @@
*/
-typedef unsigned char Byte;
-typedef unsigned long Dword;
-typedef mt_off_t Qword;
#define MAX_XAUTHORITY_LENGTH 3000
#define MAX_DATA_REQUEST 3000000
@@ -111,7 +108,8 @@ typedef mt_off_t Qword;
unsigned int mtools_lock_timeout=30;
-void serve_client(int sock, char **device_name, int n_dev, int close_stderr);
+void serve_client(int sock, char **device_name, unsigned int n_dev,
+ int close_stderr);
#ifdef USE_FLOPPYD_BUFFERED_IO
@@ -119,9 +117,9 @@ typedef struct io_buffer {
Byte out_buffer[BUFFERED_IO_SIZE];
Byte in_buffer[BUFFERED_IO_SIZE];
- unsigned long in_valid;
- long in_start;
- long out_valid;
+ size_t in_valid;
+ size_t in_start;
+ size_t out_valid;
int handle;
} *io_buffer;
@@ -154,13 +152,13 @@ static void free_io_buffer(io_buffer buffer) {
static size_t buf_read (io_buffer buf, Byte* buffer, size_t nbytes) {
- ssize_t rval;
+ size_t ret;
if (nbytes <= buf->in_valid) {
memcpy(buffer, buf->in_buffer+buf->in_start, nbytes);
buf->in_valid -= nbytes;
buf->in_start += nbytes;
- rval = nbytes;
+ ret = nbytes;
} else {
if (buf->in_valid)
memcpy(buffer, buf->in_buffer+buf->in_start,
@@ -168,41 +166,48 @@ static size_t buf_read (io_buffer buf, Byte* buffer, size_t nbytes) {
nbytes -= buf->in_valid;
buffer += buf->in_valid;
if (nbytes > BUFFERED_IO_SIZE) {
- rval = read(buf->handle, buffer, nbytes);
+ ssize_t rval = read(buf->handle, buffer, nbytes);
if (rval >= 0) {
- rval += buf->in_valid;
+ ret = (size_t) rval + buf->in_valid;
+ } else {
+ perror("read error");
+ exit(1);
}
buf->in_valid = buf->in_start = 0;
} else {
- rval = read(buf->handle, buf->in_buffer,
- BUFFERED_IO_SIZE);
+ ssize_t rval = read(buf->handle, buf->in_buffer,
+ BUFFERED_IO_SIZE);
if (rval >= 0) {
if (rval < (ssize_t) nbytes) {
- memcpy(buffer, buf->in_buffer, rval);
- rval += buf->in_valid;
+ memcpy(buffer, buf->in_buffer,
+ (size_t) rval);
+ ret = (size_t) rval + buf->in_valid;
buf->in_valid = buf->in_start = 0;
} else {
size_t a;
memcpy(buffer, buf->in_buffer, nbytes);
buf->in_start = nbytes;
a = buf->in_valid;
- buf->in_valid = rval-nbytes;
- rval = a + nbytes;
+ buf->in_valid = (size_t) rval-nbytes;
+ ret = a + nbytes;
}
+ } else {
+ perror("read error");
+ exit(1);
}
}
}
- return rval;
+ return ret;
}
-static size_t buf_write(io_buffer buf, void* buffer, size_t nbytes) {
+static ssize_t buf_write(io_buffer buf, void* buffer, size_t nbytes) {
if (buf->out_valid + nbytes > BUFFERED_IO_SIZE) {
flush(buf);
return write(buf->handle, buffer, nbytes);
}
memcpy(buf->out_buffer+buf->out_valid, buffer, nbytes);
buf->out_valid += nbytes;
- return nbytes;
+ return (ssize_t) nbytes;
}
@@ -220,7 +225,7 @@ size_t buf_read (io_buffer handle, Byte* buffer, size_t nbytes) {
return (read(handle, buffer, nbytes));
}
-size_t buf_write(io_buffer handle, void* buffer, size_t nbytes) {
+ssize_t buf_write(io_buffer handle, void* buffer, size_t nbytes) {
return (write(handle, buffer, nbytes));
}
@@ -287,7 +292,7 @@ static void kill_packet(Packet packet)
packet->alloc_size = 0;
}
-static void make_new(Packet packet, unsigned long l)
+static void make_new(Packet packet, Dword l)
{
if (l < packet->alloc_size) {
packet->len = l;
@@ -324,7 +329,7 @@ static char send_packet(Packet packet, io_buffer fp)
static char recv_packet(Packet packet, io_buffer fp, Dword maxlength)
{
Dword start;
- int l;
+ size_t l;
Dword length = read_dword(fp);
#if DEBUG
fprintf(stderr, "recv_packet(): Size: %li\n", length);
@@ -357,13 +362,17 @@ static char recv_packet(Packet packet, io_buffer fp, Dword maxlength)
return 1;
}
-static void read_packet(Packet packet, int fd, int length) {
+static ssize_t read_packet(Packet packet, int fd, Dword length) {
make_new(packet, length);
- packet->len = read(fd, packet->data, packet->len);
+ ssize_t ret = read(fd, packet->data, packet->len);
+ if(ret < 0)
+ return ret;
+ packet->len = (Dword) ret;
+ return 0;
}
static int write_packet(Packet packet, int fd) {
- return (write(fd, packet->data, packet->len));
+ return (int)write(fd, packet->data, packet->len);
}
static void put_dword(Packet packet, int my_index, Dword val) {
@@ -386,7 +395,7 @@ static Dword get_length(Packet packet) {
return packet->len;
}
-static int eat(char **ptr, int *len, unsigned char c) {
+static int eat(unsigned char **ptr, size_t *len, unsigned char c) {
/* remove length + size code + terminating 0 */
if (*len < c + 3)
return -1;
@@ -399,17 +408,17 @@ static const char *dispName;
static char XAUTHORITY[]="XAUTHORITY";
-static char do_auth(io_buffer sock, int *version)
+static char do_auth(io_buffer sock, unsigned int *version)
{
int fd;
Display* displ;
Packet proto_version = newPacket();
Packet mit_cookie;
- char *ptr;
- int len;
+ unsigned char *ptr;
+ size_t len;
char authFile[41]="/tmp/floppyd.XXXXXX";
- char template[4096];
+ unsigned char template[4096];
Packet reply = newPacket();
@@ -487,20 +496,20 @@ static char do_auth(io_buffer sock, int *version)
*ptr++ = 1;
*ptr++ = 0;
*ptr++ = 0;
- gethostname(ptr+1, 4088);
- len = strlen(ptr+1);
- *ptr++ = len;
+ gethostname((char*)ptr+1, 4088);
+ len = strlen((char*)ptr+1);
+ *ptr++ = (unsigned char) len;
ptr += len;
*ptr++ = 0;
*ptr++ = 1;
*ptr++ = '0'; /* Display number */
*ptr++ = '\0';
- if(write(fd, template, len+8) < len + 8) {
+ if(write(fd, template, len+8) < (ssize_t) (len + 8)) {
close(fd);
return 0;
}
- ptr = (char *)mit_cookie->data;
+ ptr = mit_cookie->data;
len = mit_cookie->len;
if (eat(&ptr,&len,1) || /* the "type" */
@@ -514,7 +523,7 @@ static char do_auth(io_buffer sock, int *version)
return 0;
}
- if(write(fd, ptr, len) < len) {
+ if(write(fd, ptr, len) < (ssize_t) len) {
close(fd);
return 0;
}
@@ -542,11 +551,11 @@ static char do_auth(io_buffer sock, int *version)
/*
* Return the port number, in network order, of the specified service.
*/
-static short getportnum(char *portnum)
+static uint16_t getportnum(char *portnum)
{
- char *digits = portnum;
+ char *digits = portnum;
struct servent *serv;
- short port;
+ uint16_t port;
for (port = 0; isdigit(*digits); ++digits)
{
@@ -561,7 +570,7 @@ static short getportnum(char *portnum)
}
else
{
- port = -1;
+ port = 0;
}
endservent();
}
@@ -576,10 +585,10 @@ static short getportnum(char *portnum)
/*
* Return the IP address of the specified host.
*/
-static IPaddr_t getipaddress(char *ipaddr)
+static in_addr_t getipaddress(char *ipaddr)
{
struct hostent *host;
- IPaddr_t ip;
+ in_addr_t ip;
if (((ip = inet_addr(ipaddr)) == INADDR_NONE)
&&
@@ -666,7 +675,7 @@ static uid_t getgroupid(uid_t uid)
/*
* Bind to the specified ip and port.
*/
-static int bind_to_port(IPaddr_t bind_ip, short bind_port)
+static int bind_to_port(in_addr_t bind_ip, uint16_t bind_port)
{
struct sockaddr_in addr;
int sock;
@@ -740,8 +749,10 @@ static void alarm_signal(int a UNUSEDP)
/*
* This is the main loop when running as a server.
*/
-static void server_main_loop(int sock, char **device_name, int n_dev) NORETURN;
-static void server_main_loop(int sock, char **device_name, int n_dev)
+static void server_main_loop(int sock, char **device_name,
+ unsigned int n_dev) NORETURN;
+static void server_main_loop(int sock, char **device_name,
+ unsigned int n_dev)
{
struct sockaddr_in addr;
unsigned int len;
@@ -821,8 +832,8 @@ int main (int argc, char** argv)
int sockfd = 0;
int arg;
int run_as_server = 0;
- IPaddr_t bind_ip = INADDR_ANY;
- unsigned short bind_port = 0;
+ in_addr_t bind_ip = INADDR_ANY;
+ uint16_t bind_port = 0;
uid_t run_uid = 65535;
gid_t run_gid = 65535;
char* username = strdup("nobody");
@@ -830,7 +841,7 @@ int main (int argc, char** argv)
char **device_name = NULL;
const char *floppy0 = "/dev/fd0";
- int n_dev;
+ unsigned int n_dev;
/*
@@ -958,7 +969,7 @@ int main (int argc, char** argv)
* Drop back to an untrusted user.
*/
setgid(run_gid);
- initgroups(username, -1);
+ initgroups(username, run_gid);
setuid(run_uid);
/*
@@ -979,7 +990,8 @@ int main (int argc, char** argv)
/*
* Handle the server main loop.
*/
- server_main_loop(sock, device_name, n_dev);
+ server_main_loop(sock, device_name,
+ n_dev);
}
/*
@@ -1005,7 +1017,7 @@ int main (int argc, char** argv)
return 0;
}
-static void send_reply(int rval, io_buffer sock, int len) {
+static void send_reply(int rval, io_buffer sock, Dword len) {
Packet reply = newPacket();
make_new(reply, 8);
@@ -1013,7 +1025,7 @@ static void send_reply(int rval, io_buffer sock, int len) {
if (rval == -1) {
put_dword(reply, 4, 0);
} else {
- put_dword(reply, 4, errno);
+ put_dword(reply, 4, (Dword) errno);
}
send_packet(reply, sock);
destroyPacket(reply);
@@ -1027,7 +1039,7 @@ static void send_reply64(int rval, io_buffer sock, mt_off_t len) {
if (rval == -1) {
put_dword(reply, 8, 0);
} else {
- put_dword(reply, 8, errno);
+ put_dword(reply, 8, (Dword) errno);
}
send_packet(reply, sock);
destroyPacket(reply);
@@ -1041,7 +1053,7 @@ static void cleanup(int x UNUSEDP) {
#include "lockdev.h"
-void serve_client(int sockhandle, char **device_name, int n_dev,
+void serve_client(int sockhandle, char **device_name, unsigned int n_dev,
int close_stderr) {
Packet opcode;
Packet parm;
@@ -1050,7 +1062,7 @@ void serve_client(int sockhandle, char **device_name, int n_dev,
int devFd;
io_buffer sock;
int stopLoop;
- int version;
+ unsigned int version;
int needSendReply=0;
int rval=0;
@@ -1064,7 +1076,7 @@ void serve_client(int sockhandle, char **device_name, int n_dev,
perror("setsockopt");
exit(1);
}
-
+
}
@@ -1116,7 +1128,7 @@ void serve_client(int sockhandle, char **device_name, int n_dev,
O_RDONLY|O_LARGEFILE);
}
if(devFd < 0) {
- send_reply(0, sock, devFd);
+ send_reply(0, sock, devFd >= 0 ? 0 : DWORD_ERR);
stopLoop = 1;
}
lock_dev(devFd, !readOnly, NULL);
@@ -1124,7 +1136,7 @@ void serve_client(int sockhandle, char **device_name, int n_dev,
while(!stopLoop) {
- int dev_nr = 0;
+ uint32_t dev_nr = 0;
/*
* Allow 60 seconds for any activity.
*/
@@ -1136,7 +1148,7 @@ void serve_client(int sockhandle, char **device_name, int n_dev,
/* if(opcode->data[0] != OP_CLOSE)*/
recv_packet(parm, sock, MAX_DATA_REQUEST);
-
+ cork(sock->handle, 1);
switch(opcode->data[0]) {
case OP_OPRO:
if(get_length(parm) >= 4)
@@ -1144,7 +1156,7 @@ void serve_client(int sockhandle, char **device_name, int n_dev,
else
dev_nr = 0;
if(dev_nr >= n_dev) {
- send_reply(0, sock, -1);
+ send_reply(0, sock, DWORD_ERR);
break;
}
@@ -1154,10 +1166,11 @@ void serve_client(int sockhandle, char **device_name, int n_dev,
fprintf(stderr, "Device opened\n");
#endif
if(devFd >= 0 && lock_dev(devFd, 0, NULL)) {
- send_reply(0, sock, -1);
+ send_reply(0, sock, DWORD_ERR);
break;
}
- send_reply(0, sock, devFd);
+ send_reply(0, sock,
+ devFd >= 0 ? 0 : DWORD_ERR);
readOnly = 1;
break;
case OP_OPRW:
@@ -1166,24 +1179,30 @@ void serve_client(int sockhandle, char **device_name, int n_dev,
else
dev_nr = 0;
if(dev_nr >= n_dev) {
- send_reply(0, sock, -1);
+ send_reply(0, sock, DWORD_ERR);
break;
}
devFd = open(device_name[dev_nr], O_RDWR);
if(devFd >= 0 && lock_dev(devFd, 1, NULL)) {
- send_reply(0, sock, -1);
+ send_reply(0, sock, DWORD_ERR);
break;
}
- send_reply(0, sock, devFd);
+ send_reply(0, sock,
+ devFd >= 0 ? 0 : DWORD_ERR);
readOnly = 0;
break;
case OP_READ:
#if DEBUG
fprintf(stderr, "READ:\n");
#endif
- read_packet(parm, devFd, get_dword(parm, 0));
- send_reply(devFd, sock, get_length(parm));
- send_packet(parm, sock);
+ if(read_packet(parm, devFd,
+ get_dword(parm, 0)) < 0)
+ send_reply(devFd, sock, DWORD_ERR);
+ else {
+ send_reply(devFd, sock,
+ get_length(parm));
+ send_packet(parm, sock);
+ }
break;
case OP_WRITE:
#if DEBUG
@@ -1206,7 +1225,7 @@ void serve_client(int sockhandle, char **device_name, int n_dev,
get_dword(parm, 0), get_dword(parm, 4));
send_reply(devFd,
sock,
- lseek(devFd, 0, SEEK_CUR));
+ (Dword) lseek(devFd, 0, SEEK_CUR));
break;
case OP_SEEK64:
if(sizeof(mt_off_t) < 8) {
@@ -1214,7 +1233,7 @@ void serve_client(int sockhandle, char **device_name, int n_dev,
fprintf(stderr, "64 bit requested where not available!\n");
#endif
errno = EINVAL;
- send_reply(devFd, sock, -1);
+ send_reply(devFd, sock, DWORD_ERR);
break;
}
#if DEBUG
@@ -1252,9 +1271,10 @@ void serve_client(int sockhandle, char **device_name, int n_dev,
fprintf(stderr, "Invalid Opcode!\n");
#endif
errno = EINVAL;
- send_reply(devFd, sock, -1);
+ send_reply(devFd, sock, DWORD_ERR);
break;
}
+ cork(sock->handle, 0);
kill_packet(parm);
alarm(0);
}
diff --git a/floppyd_installtest.1 b/floppyd_installtest.1
index 92d0373..885f2e3 100644
--- a/floppyd_installtest.1
+++ b/floppyd_installtest.1
@@ -1,5 +1,5 @@
'\" t
-.TH floppyd_installtest 1 "02Dec18" mtools-4.0.22
+.TH floppyd_installtest 1 "10Dec18" mtools-4.0.23
.SH Name
floppyd_installtest - tests whether floppyd is installed and running
'\" t
diff --git a/floppyd_installtest.c b/floppyd_installtest.c
index ec84b48..98043c8 100644
--- a/floppyd_installtest.c
+++ b/floppyd_installtest.c
@@ -41,10 +41,6 @@
/* ######################################################################## */
-typedef unsigned char Byte;
-typedef unsigned long Dword;
-typedef mt_off_t Qword;
-
static const char* AuthErrors[] = {
"Auth success!",
"Auth failed: Packet oversized!",
@@ -70,16 +66,16 @@ static int write_dword(int handle, Dword parm)
/* ######################################################################## */
-static int authenticate_to_floppyd(char fullauth, int sock, char *display,
- int protoversion)
+static uint32_t authenticate_to_floppyd(char fullauth, int sock, char *display,
+ uint32_t protoversion)
{
- off_t filelen=0;
+ size_t filelen=0;
Byte buf[16];
const char *command[] = { "xauth", "xauth", "extract", "-", 0, 0 };
char *xcookie = NULL;
Dword errcode;
- int bytesRead;
- int cap=0;
+ uint32_t bytesRead;
+ uint32_t cap=0;
if (fullauth) {
command[4] = display;
@@ -125,7 +121,7 @@ static int authenticate_to_floppyd(char fullauth, int sock, char *display,
if (fullauth) {
dword2byte(filelen, (Byte *) xcookie);
- if(write(sock, xcookie, filelen+4) < filelen+4)
+ if(write(sock, xcookie, filelen+4) < (ssize_t)(filelen+4))
return AUTH_IO_ERROR;
if (read_dword(sock) != 4) {
@@ -143,7 +139,7 @@ static int authenticate_to_floppyd(char fullauth, int sock, char *display,
/* ######################################################################## */
static int get_host_and_port(const char* name, char** hostname, char **display,
- short* port)
+ uint16_t* port)
{
char* newname = strdup(name);
char* p;
@@ -155,7 +151,7 @@ static int get_host_and_port(const char* name, char** hostname, char **display,
if (*p) p++;
*p2 = 0;
- *port = atoi(p);
+ *port = atou16(p);
if (*port == 0) {
*port = FLOPPYD_DEFAULT_PORT;
}
@@ -182,11 +178,11 @@ static int get_host_and_port(const char* name, char** hostname, char **display,
/*
* * Return the IP address of the specified host.
* */
-static IPaddr_t getipaddress(char *ipaddr)
+static in_addr_t getipaddress(char *ipaddr)
{
struct hostent *host;
- IPaddr_t ip;
+ in_addr_t ip;
if (((ip = inet_addr(ipaddr)) == INADDR_NONE) &&
(strcmp(ipaddr, "255.255.255.255") != 0)) {
@@ -208,7 +204,7 @@ static IPaddr_t getipaddress(char *ipaddr)
/*
* * Connect to the floppyd server.
* */
-static int connect_to_server(IPaddr_t ip, short port)
+static int connect_to_server(in_addr_t ip, uint16_t port)
{
struct sockaddr_in addr;
@@ -254,11 +250,11 @@ int main (int argc, char** argv)
char* hostname;
char* display;
char* name;
- short port;
+ uint16_t port;
int sock;
- int reply;
+ uint32_t reply;
int rval;
- int protoversion;
+ uint32_t protoversion;
char fullauth = 0;
Byte opcode = OP_CLOSE;
diff --git a/floppyd_io.c b/floppyd_io.c
index 25bdaea..d243bc4 100644
--- a/floppyd_io.c
+++ b/floppyd_io.c
@@ -38,10 +38,6 @@
/* ######################################################################## */
-typedef unsigned char Byte;
-typedef unsigned long Dword;
-typedef mt_off_t Qword;
-
static const char* AuthErrors[] = {
"Auth success",
"Auth failed: Packet oversized",
@@ -62,8 +58,8 @@ typedef struct RemoteFile_t {
mt_off_t offset;
mt_off_t lastwhere;
mt_off_t size;
- int version;
- int capabilities;
+ unsigned int version;
+ unsigned int capabilities;
int drive;
} RemoteFile_t;
@@ -74,9 +70,11 @@ typedef struct RemoteFile_t {
/* ######################################################################## */
-static int authenticate_to_floppyd(RemoteFile_t *floppyd, int sock, char *display)
+static unsigned int authenticate_to_floppyd(RemoteFile_t *floppyd,
+ int sock, char *display)
{
- off_t filelen;
+ size_t filelen;
+ ssize_t newlen;
Byte buf[16];
const char *command[] = { "xauth", "xauth", "extract", "-", 0, 0 };
char *xcookie;
@@ -89,17 +87,18 @@ static int authenticate_to_floppyd(RemoteFile_t *floppyd, int sock, char *displa
filelen += 100;
xcookie = (char *) safe_malloc(filelen+4);
- filelen = safePopenOut(command, xcookie+4, filelen);
- if(filelen < 1)
+ newlen = safePopenOut(command, xcookie+4, filelen);
+ if(newlen < 1)
return AUTH_AUTHFAILED;
-
+ filelen = (size_t) newlen;
+
/* Version negotiation */
dword2byte(4,buf);
dword2byte(floppyd->version,buf+4);
if(write(sock, buf, 8) < 8)
return AUTH_IO_ERROR;
- if ( (l = read_dword(sock)) < 4) {
+ if ( (l = (int) read_dword(sock)) < 4) {
return AUTH_WRONGVERSION;
}
@@ -115,7 +114,7 @@ static int authenticate_to_floppyd(RemoteFile_t *floppyd, int sock, char *displa
floppyd->capabilities = read_dword(sock);
dword2byte(filelen, (Byte *)xcookie);
- if(write(sock, xcookie, filelen+4) < filelen + 4)
+ if(write(sock, xcookie, filelen+4) < ((ssize_t) (filelen + 4)))
return AUTH_IO_ERROR;
if (read_dword(sock) != 4) {
@@ -128,11 +127,10 @@ static int authenticate_to_floppyd(RemoteFile_t *floppyd, int sock, char *displa
}
-static int floppyd_reader(int fd, char* buffer, int len)
+static int floppyd_reader(int fd, char* buffer, size_t len)
{
Dword errcode;
Dword gotlen;
- int l;
Byte buf[16];
dword2byte(1, buf);
@@ -151,17 +149,21 @@ static int floppyd_reader(int fd, char* buffer, int len)
errcode = read_dword(fd);
if (gotlen != (Dword) -1) {
+ size_t l;
unsigned int start;
if (read_dword(fd) != gotlen) {
errno = EIO;
return -1;
}
for (start = 0, l = 0; start < gotlen; start += l) {
- l = read(fd, buffer+start, gotlen-start);
- if (l == 0) {
+ ssize_t ret = read(fd, buffer+start, gotlen-start);
+ if( ret < 0)
+ return -1;
+ if (ret == 0) {
errno = EIO;
return -1;
}
+ l = (size_t) ret;
}
} else {
errno = errcode;
@@ -169,7 +171,7 @@ static int floppyd_reader(int fd, char* buffer, int len)
return gotlen;
}
-static int floppyd_writer(int fd, char* buffer, int len)
+static int floppyd_writer(int fd, char* buffer, size_t len)
{
Dword errcode;
Dword gotlen;
@@ -179,10 +181,12 @@ static int floppyd_writer(int fd, char* buffer, int len)
buf[4] = OP_WRITE;
dword2byte(len, buf+5);
+ cork(fd, 1);
if(write(fd, buf, 9) < 9)
return AUTH_IO_ERROR;
if(write(fd, buffer, len) < len)
return AUTH_IO_ERROR;
+ cork(fd, 0);
if (read_dword(fd) != 8) {
errno = EIO;
@@ -298,10 +302,10 @@ static int floppyd_open(RemoteFile_t *This, int mode)
/* ######################################################################## */
-typedef int (*iofn) (int, char *, int);
+typedef int (*iofn) (int, char *, size_t);
-static int floppyd_io(Stream_t *Stream, char *buf, mt_off_t where, int len,
- iofn io)
+static int floppyd_io(Stream_t *Stream, char *buf, mt_off_t where, size_t len,
+ iofn io)
{
DeclareThis(RemoteFile_t);
int ret;
@@ -335,12 +339,12 @@ static int floppyd_io(Stream_t *Stream, char *buf, mt_off_t where, int len,
static int floppyd_read(Stream_t *Stream, char *buf, mt_off_t where, size_t len)
{
- return floppyd_io(Stream, buf, where, len, (iofn) floppyd_reader);
+ return floppyd_io(Stream, buf, where, len, floppyd_reader);
}
static int floppyd_write(Stream_t *Stream, char *buf, mt_off_t where, size_t len)
{
- return floppyd_io(Stream, buf, where, len, (iofn) floppyd_writer);
+ return floppyd_io(Stream, buf, where, len, floppyd_writer);
}
static int floppyd_flush(Stream_t *Stream)
@@ -370,8 +374,8 @@ static int floppyd_flush(Stream_t *Stream)
static int floppyd_free(Stream_t *Stream)
{
Byte buf[16];
- int gotlen;
- int errcode;
+ unsigned int gotlen;
+ unsigned int errcode;
DeclareThis(RemoteFile_t);
if (This->fd > 2) {
@@ -402,7 +406,7 @@ static int floppyd_geom(Stream_t *Stream, struct device *dev,
int media, union bootsector *boot)
{
size_t tot_sectors;
- int sect_per_track;
+ unsigned int sect_per_track;
DeclareThis(RemoteFile_t);
dev->ssize = 2; /* allow for init_geom to change it */
@@ -462,7 +466,8 @@ static Class_t FloppydFileClass = {
/* ######################################################################## */
static int get_host_and_port_and_drive(const char* name, char** hostname,
- char **display, short* port, int *drive)
+ char **display, uint16_t* port,
+ int *drive)
{
char* newname = strdup(name);
char* p;
@@ -476,12 +481,12 @@ static int get_host_and_port_and_drive(const char* name, char** hostname,
*port = FLOPPYD_DEFAULT_PORT;
if(*p >= '0' && *p <= '9')
- *port = strtoul(p, &p, 0);
+ *port = strtou16(p, &p, 0);
if(*p == '/')
p++;
*drive = 0;
if(*p >= '0' && *p <= '9')
- *drive = strtoul(p, &p, 0);
+ *drive = strtoi(p, &p, 0);
*display = strdup(newname);
@@ -505,11 +510,10 @@ static int get_host_and_port_and_drive(const char* name, char** hostname,
/*
* * Return the IP address of the specified host.
* */
-static IPaddr_t getipaddress(char *ipaddr)
+static in_addr_t getipaddress(char *ipaddr)
{
-
struct hostent *host;
- IPaddr_t ip;
+ in_addr_t ip;
if (((ip = inet_addr(ipaddr)) == INADDR_NONE) &&
(strcmp(ipaddr, "255.255.255.255") != 0)) {
@@ -531,7 +535,7 @@ static IPaddr_t getipaddress(char *ipaddr)
/*
* * Connect to the floppyd server.
* */
-static int connect_to_server(IPaddr_t ip, short port)
+static int connect_to_server(in_addr_t ip, uint16_t port)
{
struct sockaddr_in addr;
@@ -622,11 +626,11 @@ static int ConnectToFloppyd(RemoteFile_t *floppyd, const char* name,
{
char* hostname;
char* display;
- short port;
+ uint16_t port;
int rval = get_host_and_port_and_drive(name, &hostname, &display,
&port, &floppyd->drive);
int sock;
- int reply;
+ unsigned int reply;
if (!rval) return -1;
diff --git a/floppyd_io.h b/floppyd_io.h
index d767ea8..58f763f 100644
--- a/floppyd_io.h
+++ b/floppyd_io.h
@@ -23,6 +23,12 @@
#include "stream.h"
+typedef uint8_t Byte;
+typedef uint32_t Dword;
+typedef uint64_t Qword;
+
+#define DWORD_ERR ((Dword) -1)
+
/*extern int ConnectToFloppyd(const char* name, Class_t** ioclass);*/
Stream_t *FloppydOpen(struct device *dev,
char *name, int mode, char *errmsg,
@@ -59,7 +65,23 @@ enum AuthErrorsEnum {
AUTH_IO_ERROR
};
-typedef unsigned long IPaddr_t;
+
+UNUSED(static inline void cork(int sockhandle, int on))
+{
+#ifdef TCP_CORK
+ if(setsockopt(sockhandle, IPPROTO_TCP,
+ TCP_CORK, (char *)&on, sizeof(on)) < 0) {
+ perror("setsockopt cork");
+ }
+#else
+ on = 1 ^ on;
+ if(setsockopt(sockhandle, IPPROTO_TCP,
+ TCP_NODELAY, (char *)&on, sizeof(on)) < 0) {
+ perror("setsockopt nodelay");
+ }
+#endif
+}
+
#endif
#endif
diff --git a/hash.c b/hash.c
index 36fb591..3f526aa 100644
--- a/hash.c
+++ b/hash.c
@@ -24,23 +24,25 @@
struct hashtable {
T_HashFunc f1,f2;
T_ComparFunc compar;
- int size; /* actual size of the array */
- int fill; /* number of deleted or in use slots */
- int inuse; /* number of slots in use */
- int max; /* maximal number of elements to keep efficient */
+ size_t size; /* actual size of the array */
+ size_t fill; /* number of deleted or in use slots */
+ size_t inuse; /* number of slots in use */
+ size_t max; /* maximal number of elements to keep efficient */
T_HashTableEl *entries;
};
-static int sizes[]={5, 11, 23, 47, 97, 197, 397, 797, 1597, 3203, 6421, 12853,
- 25717, 51437, 102877, 205759, 411527, 823117, 1646237,
- 3292489, 6584983, 13169977, 26339969, 52679969, 105359939,
- 210719881, 421439783, 842879579, 1685759167, 0 };
+static size_t sizes[]=
+ { 5, 11, 23, 47, 97, 197, 397, 797, 1597, 3203, 6421, 12853,
+ 25717, 51437, 102877, 205759, 411527, 823117, 1646237,
+ 3292489, 6584983, 13169977, 26339969, 52679969, 105359939,
+ 210719881, 421439783, 842879579, 1685759167, 0 };
static int deleted=0;
static int unallocated=0;
-static int alloc_ht(T_HashTable *H, int size)
+static int alloc_ht(T_HashTable *H, size_t size)
{
int i;
+ size_t ii;
for(i=0; sizes[i]; i++)
if (sizes[i] > size*4 )
@@ -66,12 +68,12 @@ static int alloc_ht(T_HashTable *H, int size)
if (H->entries == NULL)
return -1; /* out of memory error */
- for(i=0; i < size; i++)
- H->entries[i] = &unallocated;
+ for(ii=0; ii < size; ii++)
+ H->entries[ii] = &unallocated;
return 0;
}
-int make_ht(T_HashFunc f1, T_HashFunc f2, T_ComparFunc c, int size,
+int make_ht(T_HashFunc f1, T_HashFunc f2, T_ComparFunc c, size_t size,
T_HashTable **H)
{
*H = New(T_HashTable);
@@ -90,7 +92,7 @@ int make_ht(T_HashFunc f1, T_HashFunc f2, T_ComparFunc c, int size,
int free_ht(T_HashTable *H, T_HashFunc entry_free)
{
- int i;
+ size_t i;
if(entry_free)
for(i=0; i< H->size; i++)
if (H->entries[i] != &unallocated &&
@@ -102,16 +104,17 @@ int free_ht(T_HashTable *H, T_HashFunc entry_free)
}
/* add into hash table without checking for repeats */
-static int _hash_add(T_HashTable *H,T_HashTableEl *E, int *hint)
+static int _hash_add(T_HashTable *H,T_HashTableEl *E, size_t *hint)
{
- int f2, pos, ctr;
+ size_t f2, pos;
+ int ctr;
pos = H->f1(E) % H->size;
- f2 = -1;
+ f2 = (size_t) -1;
ctr = 0;
while(H->entries[pos] != &unallocated &&
H->entries[pos] != &deleted){
- if (f2 == -1)
+ if (f2 == (size_t) -1)
f2 = H->f2(E) % (H->size - 1);
pos = (pos+f2+1) % H->size;
ctr++;
@@ -128,7 +131,7 @@ static int _hash_add(T_HashTable *H,T_HashTableEl *E, int *hint)
static int rehash(T_HashTable *H)
{
- int size,i;
+ size_t size,i;
T_HashTableEl *oldentries;
/* resize the table */
@@ -145,7 +148,7 @@ static int rehash(T_HashTable *H)
return 0;
}
-int hash_add(T_HashTable *H, T_HashTableEl *E, int *hint)
+int hash_add(T_HashTable *H, T_HashTableEl *E, size_t *hint)
{
if (H->fill >= H->max)
rehash(H);
@@ -157,29 +160,29 @@ int hash_add(T_HashTable *H, T_HashTableEl *E, int *hint)
/* add into hash table without checking for repeats */
static int _hash_lookup(T_HashTable *H,T_HashTableEl *E, T_HashTableEl **E2,
- int *hint, int isIdentity)
+ size_t *hint, int isIdentity)
{
- int f2, pos, upos, ttl;
+ size_t f2, pos, upos, ttl;
pos = H->f1(E) % H->size;
ttl = H->size;
- f2 = -1;
- upos = -1;
+ f2 = (size_t) -1;
+ upos = (size_t) -1;
while(ttl &&
H->entries[pos] != &unallocated &&
(H->entries[pos] == &deleted ||
((isIdentity || H->compar(H->entries[pos], E) != 0) &&
(!isIdentity || H->entries[pos] != E)))){
- if (f2 == -1)
+ if (f2 == (size_t) -1)
f2 = H->f2(E) % (H->size - 1);
- if (upos == -1 && H->entries[pos] == &deleted)
+ if (upos == (size_t) -1 && H->entries[pos] == &deleted)
upos = pos;
pos = (pos+f2+1) % H->size;
ttl--;
}
if(H->entries[pos] == &unallocated || !ttl)
return -1;
- if (upos != -1){
+ if (upos != (size_t) -1){
H->entries[upos] = H->entries[pos];
H->entries[pos] = &deleted;
pos = upos;
@@ -192,13 +195,13 @@ static int _hash_lookup(T_HashTable *H,T_HashTableEl *E, T_HashTableEl **E2,
int hash_lookup(T_HashTable *H,T_HashTableEl *E, T_HashTableEl **E2,
- int *hint)
+ size_t *hint)
{
return _hash_lookup(H, E, E2, hint, 0);
}
/* add into hash table without checking for repeats */
-int hash_remove(T_HashTable *H,T_HashTableEl *E, int hint)
+int hash_remove(T_HashTable *H,T_HashTableEl *E, size_t hint)
{
T_HashTableEl *E2;
diff --git a/htable.h b/htable.h
index 576a2b7..0754e14 100644
--- a/htable.h
+++ b/htable.h
@@ -19,14 +19,15 @@
typedef struct hashtable T_HashTable;
typedef void *T_HashTableEl;
-typedef unsigned int (*T_HashFunc)(void *);
+typedef size_t (*T_HashFunc)(void *);
typedef int (*T_ComparFunc)(void *, void *);
-int make_ht(T_HashFunc f1, T_HashFunc f2, T_ComparFunc c, int size, T_HashTable **H);
-int hash_add(T_HashTable *H, T_HashTableEl *E, int *hint);
-int hash_remove(T_HashTable *H, T_HashTableEl *E, int hint);
+int make_ht(T_HashFunc f1, T_HashFunc f2, T_ComparFunc c, size_t size,
+ T_HashTable **H);
+int hash_add(T_HashTable *H, T_HashTableEl *E, size_t *hint);
+int hash_remove(T_HashTable *H, T_HashTableEl *E, size_t hint);
int hash_lookup(T_HashTable *H, T_HashTableEl *E, T_HashTableEl **E2,
- int *hint);
+ size_t *hint);
int free_ht(T_HashTable *H, T_HashFunc entry_free);
diff --git a/mainloop.c b/mainloop.c
index e3d422b..cfd91bf 100644
--- a/mainloop.c
+++ b/mainloop.c
@@ -54,7 +54,7 @@ static const char *fix_mcwd(char *ans)
/* drive letter present? */
s = buf;
if (buf[0] && buf[1] == ':') {
- strncpy(ans, buf, 2);
+ memcpy(ans, buf, 2);
ans[2] = '\0';
s = &buf[2];
} else {
@@ -223,7 +223,7 @@ static int handle_leaf(direntry_t *direntry, MainParam_t *mp,
return 0;
case 1: /* we have already a directory */
FREE(&lookupState->Dir);
- fprintf(stderr,"Ambigous\n");
+ fprintf(stderr,"Ambiguous\n");
return STOP_NOW | ERROR_ONE;
default:
return STOP_NOW | ERROR_ONE;
@@ -258,8 +258,9 @@ static int _dos_loop(Stream_t *Dir, MainParam_t *mp, const char *filename)
initializeDirentry(&entry, Dir);
while(!got_signal &&
(r=vfat_lookup(&entry, filename, -1,
- mp->lookupflags, mp->shortname,
- mp->longname)) == 0 ){
+ mp->lookupflags,
+ mp->shortname.data, mp->shortname.len,
+ mp->longname.data, mp->longname.len)) == 0 ){
mp->File = NULL;
if(!checkForDot(mp->lookupflags,entry.name)) {
MyFile = 0;
@@ -390,7 +391,8 @@ static int recurs_dos_loop(MainParam_t *mp, const char *filename0,
!got_signal &&
(r=vfat_lookup(&entry, filename0, length,
lookupflags | NO_MSG,
- mp->shortname, mp->longname)) == 0 ){
+ mp->shortname.data, mp->shortname.len,
+ mp->longname.data, mp->longname.len)) == 0 ){
if(checkForDot(lookupflags, entry.name))
/* while following the path, ignore the
* special entries if they were not
@@ -504,7 +506,7 @@ static int dos_target_lookup(MainParam_t *mp, const char *arg)
return ret;
default:
/* too much */
- fprintf(stderr, "Ambigous %s\n", arg);
+ fprintf(stderr, "Ambiguous %s\n", arg);
return ERROR_ONE;
}
}
@@ -602,7 +604,8 @@ void init_mp(MainParam_t *mp)
mp->unixTarget = 0;
mp->dirCallback = dispatchToFile;
mp->unixcallback = NULL;
- mp->shortname = mp->longname = 0;
+ mp->shortname.data = mp->longname.data = 0;
+ mp->shortname.len = mp->longname.len = 0;
mp->File = 0;
mp->fast_quit = 0;
}
@@ -611,7 +614,7 @@ const char *mpGetBasename(MainParam_t *mp)
{
if(mp->direntry) {
wchar_to_native(mp->direntry->name, mp->targetBuffer,
- MAX_VNAMELEN+1);
+ MAX_VNAMELEN+1, sizeof(mp->targetBuffer));
return mp->targetBuffer;
} else
return _basename(mp->unixSourceName);
diff --git a/mainloop.h b/mainloop.h
index 940c853..a2ff666 100644
--- a/mainloop.h
+++ b/mainloop.h
@@ -22,6 +22,12 @@
#include "vfat.h"
#include "mtoolsDirentry.h"
+typedef struct bounded_string {
+ char *data; /* storage of converted string, including final null byte */
+ size_t len; /* max length of converted string, including final null
+ * byte */
+} bounded_string;
+
typedef struct MainParam_t {
/* stuff needing to be initialised by the caller */
int (*loop)(Stream_t *Dir, struct MainParam_t *mp,
@@ -38,9 +44,10 @@ typedef struct MainParam_t {
int fast_quit; /* for commands manipulating multiple files, quit
* as soon as even _one_ file has a problem */
- char *shortname; /* where to put the short name of the matched file */
- char *longname; /* where to put the long name of the matched file */
-
+ bounded_string shortname; /* where to put the short name of the
+ * matched file */
+ bounded_string longname; /* where to put the long name of the
+ * matched file */
/* out parameters */
Stream_t *File;
diff --git a/mattrib.1 b/mattrib.1
index 42513b4..9a8dbae 100644
--- a/mattrib.1
+++ b/mattrib.1
@@ -1,5 +1,5 @@
'\" t
-.TH mattrib 1 "02Dec18" mtools-4.0.22
+.TH mattrib 1 "10Dec18" mtools-4.0.23
.SH Name
mattrib - change MSDOS file attribute flags
'\" t
diff --git a/mattrib.c b/mattrib.c
index 1fd0eb2..c684e76 100644
--- a/mattrib.c
+++ b/mattrib.c
@@ -25,7 +25,7 @@
#include "mainloop.h"
typedef struct Arg_t {
- char add;
+ unsigned char add;
unsigned char remove;
struct MainParam_t mp;
int recursive;
diff --git a/mbadblocks.1 b/mbadblocks.1
index 6c4942d..8aa1cc6 100644
--- a/mbadblocks.1
+++ b/mbadblocks.1
@@ -1,5 +1,5 @@
'\" t
-.TH mbadblocks 1 "02Dec18" mtools-4.0.22
+.TH mbadblocks 1 "10Dec18" mtools-4.0.23
.SH Name
mbadblocks - tests a floppy disk, and marks the bad blocks in the FAT
'\" t
diff --git a/mbadblocks.c b/mbadblocks.c
index 6d2cf3b..37b4207 100644
--- a/mbadblocks.c
+++ b/mbadblocks.c
@@ -140,10 +140,10 @@ void mbadblocks(int argc, char **argv, int type UNUSEDP)
sectorMode = 1;
break;
case 'S':
- startSector = atol(optarg);
+ startSector = atoui(optarg);
break;
case 'E':
- endSector = atol(optarg);
+ endSector = atoui(optarg);
break;
case 'w':
writeMode = 1;
@@ -183,7 +183,7 @@ void mbadblocks(int argc, char **argv, int type UNUSEDP)
ret = 1;
goto exit_0;
}
- srandom(time(NULL));
+ init_random();
for(i=0; i < in_len * N_PATTERN; i++) {
pat_buf[i] = random();
}
@@ -222,7 +222,7 @@ void mbadblocks(int argc, char **argv, int type UNUSEDP)
}
while(fgets(line, sizeof(line), f)) {
char *ptr = line + strspn(line, " \t");
- long offset = strtoul(ptr, 0, 0);
+ long offset = strtol(ptr, 0, 0);
if(sectorMode)
offset = (offset-Fs->clus_start)/Fs->cluster_size + 2;
if(offset < 2) {
diff --git a/mcat.1 b/mcat.1
index a563508..f217593 100644
--- a/mcat.1
+++ b/mcat.1
@@ -1,5 +1,5 @@
'\" t
-.TH mcat 1 "02Dec18" mtools-4.0.22
+.TH mcat 1 "10Dec18" mtools-4.0.23
.SH Name
mcat - dump raw disk image
'\" t
diff --git a/mcd.1 b/mcd.1
index 89cc6de..1da5630 100644
--- a/mcd.1
+++ b/mcd.1
@@ -1,5 +1,5 @@
'\" t
-.TH mcd 1 "02Dec18" mtools-4.0.22
+.TH mcd 1 "10Dec18" mtools-4.0.23
.SH Name
mcd - change MSDOS directory
'\" t
diff --git a/mclasserase.1 b/mclasserase.1
index 01b16e6..1b30eed 100644
--- a/mclasserase.1
+++ b/mclasserase.1
@@ -1,5 +1,5 @@
'\" t
-.TH mclasserase 1 "02Dec18" mtools-4.0.22
+.TH mclasserase 1 "10Dec18" mtools-4.0.23
.SH Name
mclasserase - erase memory cards
'\" t
diff --git a/mclasserase.c b/mclasserase.c
index f99dd65..8e71e3b 100644
--- a/mclasserase.c
+++ b/mclasserase.c
@@ -256,7 +256,7 @@ static void do_mclasserase(char drive,int debug)
/**
- * Total Erase of Data on a Disk. After using mclasserase there wont
+ * Total Erase of Data on a Disk. After using mclasserase there won't
* be ANY bits of old files on the disk.<br>
* </b>
* @author stefan feuz<br>
diff --git a/mcomp.1 b/mcomp.1
index 1bf8417..a6719af 100644
--- a/mcomp.1
+++ b/mcomp.1
@@ -21,7 +21,7 @@ mcomp \- Compares two files using mtools
.SH DESCRIPTION
.B mcomp
compares two files, the first one must be on a floppy disk so it can
-be accesed via \fBmtools\fR.
+be accessed via \fBmtools\fR.
It is not strictly necessary on Debian GNU/Linux, because the diffutils
\fBcmp\fR(1) program provides the same capability after copying the
file locally with
diff --git a/mcopy.1 b/mcopy.1
index 8fbd038..7c15bbe 100644
--- a/mcopy.1
+++ b/mcopy.1
@@ -1,5 +1,5 @@
'\" t
-.TH mcopy 1 "02Dec18" mtools-4.0.22
+.TH mcopy 1 "10Dec18" mtools-4.0.23
.SH Name
mcopy - copy MSDOS files to/from Unix
'\" t
diff --git a/mcopy.c b/mcopy.c
index c25132f..c9a8900 100644
--- a/mcopy.c
+++ b/mcopy.c
@@ -392,7 +392,7 @@ static Stream_t *subDir(Stream_t *parent, const char *filename)
direntry_t entry;
initializeDirentry(&entry, parent);
- switch(vfat_lookup(&entry, filename, -1, ACCEPT_DIR, 0, 0)) {
+ switch(vfat_lookup(&entry, filename, -1, ACCEPT_DIR, 0, 0, 0, 0)) {
case 0:
return OpenFileByDirentry(&entry);
case -1:
diff --git a/mdel.1 b/mdel.1
index d75a909..feea139 100644
--- a/mdel.1
+++ b/mdel.1
@@ -1,5 +1,5 @@
'\" t
-.TH mdel 1 "02Dec18" mtools-4.0.22
+.TH mdel 1 "10Dec18" mtools-4.0.23
.SH Name
mdel - delete an MSDOS file
'\" t
diff --git a/mdel.c b/mdel.c
index 82ef2cb..e650d71 100644
--- a/mdel.c
+++ b/mdel.c
@@ -75,7 +75,7 @@ static int del_entry(direntry_t *entry, MainParam_t *mp)
if (entry->dir.attr & (ATTR_READONLY | ATTR_SYSTEM)) {
char tmp[4*MAX_VNAMELEN+1];
- wchar_to_native(entry->name,tmp,MAX_VNAMELEN);
+ WCHAR_TO_NATIVE(entry->name,tmp,MAX_VNAMELEN);
if (ask_confirmation("%s: \"%s\" is read only, erase anyway (y/n) ? ",
progname, tmp))
return ERROR_ONE;
@@ -108,7 +108,8 @@ static int del_file(direntry_t *entry, MainParam_t *mp)
ret = 0;
while((r=vfat_lookup(&subEntry, "*", 1,
ACCEPT_DIR | ACCEPT_PLAIN,
- shortname, NULL)) == 0 ){
+ shortname, sizeof(shortname),
+ NULL, 0)) == 0 ){
if(shortname[0] != DELMARK &&
shortname[0] &&
shortname[0] != '.' ){
@@ -195,8 +196,7 @@ void mdel(int argc, char **argv, int deltype)
}
mp.lookupflags |= NO_DOTS;
for(i=optind;i<argc;i++) {
- int b;
- size_t l;
+ size_t b, l;
if(argv[i][0] && argv[i][1] == ':')
b = 2;
else
diff --git a/mdeltree.1 b/mdeltree.1
index 87eb876..12851aa 100644
--- a/mdeltree.1
+++ b/mdeltree.1
@@ -1,5 +1,5 @@
'\" t
-.TH mdeltree 1 "02Dec18" mtools-4.0.22
+.TH mdeltree 1 "10Dec18" mtools-4.0.23
.SH Name
mdeltree - recursively delete an MSDOS directory and its contents
'\" t
diff --git a/mdir.1 b/mdir.1
index 8be73e8..043e7f5 100644
--- a/mdir.1
+++ b/mdir.1
@@ -1,5 +1,5 @@
'\" t
-.TH mdir 1 "02Dec18" mtools-4.0.22
+.TH mdir 1 "10Dec18" mtools-4.0.23
.SH Name
mdir - display an MSDOS directory
'\" t
diff --git a/mdir.c b/mdir.c
index 8190dfa..788ef5a 100644
--- a/mdir.c
+++ b/mdir.c
@@ -58,8 +58,8 @@ static mt_size_t bytesOnDrive;
static Stream_t *RootDir;
-static char global_shortname[4*12+1];
-static char global_longname[4*MAX_VNAMELEN+1];
+static char mdir_shortname[4*12+1];
+static char mdir_longname[4*MAX_VNAMELEN+1];
/*
@@ -197,7 +197,8 @@ static __inline__ int print_volume_label(Stream_t *Dir, char drive)
initializeDirentry(&entry, RootDir);
if((r=vfat_lookup(&entry, 0, 0, ACCEPT_LABEL | MATCH_ANY,
- shortname, longname)) ) {
+ shortname, sizeof(shortname),
+ longname, sizeof(longname))) ) {
if (r == -2) {
/* I/O Error */
return -1;
@@ -390,7 +391,7 @@ static int list_file(direntry_t *entry, MainParam_t *mp UNUSEDP)
dos_to_wchar(cp, entry->dir.ext, ext, 3);
if(Case & EXTCASE){
for(i=0; i<3;i++)
- ext[i] = towlower(ext[i]);
+ ext[i] = ch_towlower(ext[i]);
}
ext[3] = '\0';
if (entry->dir.name[0] == '\x05') {
@@ -401,25 +402,25 @@ static int list_file(direntry_t *entry, MainParam_t *mp UNUSEDP)
}
if(Case & BASECASE){
for(i=0; i<8;i++)
- name[i] = towlower(name[i]);
+ name[i] = ch_towlower(name[i]);
}
name[8]='\0';
if(wide){
if(IS_DIR(entry))
- printf("[%s]%*s", global_shortname,
- (int) (15 - 2 - strlen(global_shortname)), "");
+ printf("[%s]%*s", mdir_shortname,
+ (int) (15 - 2 - strlen(mdir_shortname)), "");
else
- printf("%-15s", global_shortname);
+ printf("%-15s", mdir_shortname);
} else if(!concise) {
char tmpBasename[4*8+1];
char tmpExt[4*3+1];
- wchar_to_native(name,tmpBasename,8);
- wchar_to_native(ext,tmpExt,3);
+ WCHAR_TO_NATIVE(name,tmpBasename,8);
+ WCHAR_TO_NATIVE(ext,tmpExt,3);
if (name[0] == ' ')
printf(" ");
else if(mtools_dotted_dir)
- printf("%-12s ", global_shortname);
+ printf("%-12s ", mdir_shortname);
else
printf("%s %s ", tmpBasename, tmpExt);
/* is a subdirectory */
@@ -435,12 +436,13 @@ static int list_file(direntry_t *entry, MainParam_t *mp UNUSEDP)
if(debug)
printf(" %s %d ", tmpBasename, START(&entry->dir));
- if(*global_longname)
- printf(" %s", global_longname);
+ if(*mdir_longname)
+ printf(" %s", mdir_longname);
printf("\n");
} else {
char tmp[4*MAX_VNAMELEN+1];
- wchar_to_native(entry->name,tmp,MAX_VNAMELEN);
+ wchar_to_native(entry->name,tmp,
+ MAX_VNAMELEN, sizeof(tmp));
printf("%s/%s", dirPath, tmp);
if(IS_DIR(entry))
@@ -608,8 +610,10 @@ void mdir(int argc, char **argv, int type UNUSEDP)
mp.dirCallback = list_non_recurs_directory;
mp.callback = list_file;
}
- mp.longname = global_longname;
- mp.shortname = global_shortname;
+ mp.longname.data = mdir_longname;
+ mp.longname.len = sizeof(mdir_longname);
+ mp.shortname.data = mdir_shortname;
+ mp.shortname.len = sizeof(mdir_shortname);
ret=main_loop(&mp, argv + optind, argc - optind);
leaveDirectory(ret);
leaveDrive(ret);
diff --git a/mdoctorfat.c b/mdoctorfat.c
index 174c3b9..3649b2b 100644
--- a/mdoctorfat.c
+++ b/mdoctorfat.c
@@ -34,7 +34,7 @@ typedef struct Arg_t {
MainParam_t mp;
ClashHandling_t ch;
Stream_t *sourcefile;
- unsigned long fat;
+ uint32_t fat;
int markbad;
int setsize;
unsigned long size;
@@ -79,10 +79,11 @@ void mdoctorfat(int argc, char **argv, int mtype UNUSEDP)
{
Arg_t arg;
int c, ret;
- long address, begin, end;
+ unsigned int address;
+ unsigned int begin, end;
char *number, *eptr;
- int i, j;
- long offset;
+ int i;
+ unsigned int offset;
/* get command line options */
@@ -105,7 +106,7 @@ void mdoctorfat(int argc, char **argv, int mtype UNUSEDP)
arg.markbad = 1;
break;
case 'o':
- offset = strtoul(optarg,0,0);
+ offset = strtoui(optarg,0,0);
break;
case 's':
arg.setsize=1;
@@ -131,20 +132,21 @@ void mdoctorfat(int argc, char **argv, int mtype UNUSEDP)
arg.mp.lookupflags = ACCEPT_PLAIN | ACCEPT_DIR | DO_OPEN;
arg.mp.openflags = O_RDWR;
- arg.fat = strtoul(argv[optind+1], 0, 0) + offset;
+ arg.fat = strtoui(argv[optind+1], 0, 0) + offset;
ret=main_loop(&arg.mp, argv + optind, 1);
if(ret)
exit(ret);
address = 0;
for(i=optind+1; i < argc; i++) {
+ unsigned int j;
number = argv[i];
if (*number == '<') {
number++;
}
- begin = strtoul(number, &eptr, 0);
+ begin = strtoui(number, &eptr, 0);
if (eptr && *eptr == '-') {
number = eptr+1;
- end = strtoul(number, &eptr, 0);
+ end = strtoui(number, &eptr, 0);
} else {
end = begin;
}
diff --git a/mdu.1 b/mdu.1
index a0f09ab..785fb89 100644
--- a/mdu.1
+++ b/mdu.1
@@ -1,5 +1,5 @@
'\" t
-.TH mdu 1 "02Dec18" mtools-4.0.22
+.TH mdu 1 "10Dec18" mtools-4.0.23
.SH Name
mdu - display the amount of space occupied by an MSDOS directory
'\" t
diff --git a/mformat.1 b/mformat.1
index ccfc296..5074361 100644
--- a/mformat.1
+++ b/mformat.1
@@ -1,5 +1,5 @@
'\" t
-.TH mformat 1 "02Dec18" mtools-4.0.22
+.TH mformat 1 "10Dec18" mtools-4.0.23
.SH Name
mformat - add an MSDOS filesystem to a low-level formatted floppy disk
'\" t
@@ -218,7 +218,7 @@ stored (only relevant on FAT32).
\&\fR\&\f(CWR\fR\
Sets the number of reserved sectors for this filesystem. This must be
at least 1 for non-FAT32 disks, and at least 3 for FAT disks (in order
-to accomodate the boot sector, the info sector and the backup boot
+to accommodate the boot sector, the info sector and the backup boot
sector).
.TP
\&\fR\&\f(CWm\fR\
diff --git a/mformat.c b/mformat.c
index 7aecd2d..b3c6098 100644
--- a/mformat.c
+++ b/mformat.c
@@ -55,14 +55,12 @@
static int init_geometry_boot(union bootsector *boot, struct device *dev,
- int sectors0, int rate_0, int rate_any,
- unsigned long *tot_sectors, int keepBoot)
+ uint8_t sectors0,
+ uint8_t rate_0, uint8_t rate_any,
+ unsigned long *tot_sectors, int keepBoot)
{
- int i;
int nb_renum;
int sector2;
- int size2;
- int j;
int sum;
set_word(boot->boot.nsect, dev->sectors);
@@ -72,16 +70,22 @@ static int init_geometry_boot(union bootsector *boot, struct device *dev,
assert(*tot_sectors != 0);
#endif
- if (*tot_sectors < 0x10000){
- set_word(boot->boot.psect, *tot_sectors);
+ if (*tot_sectors <= UINT16_MAX){
+ set_word(boot->boot.psect, (uint16_t) *tot_sectors);
set_dword(boot->boot.bigsect, 0);
- } else {
+ } else if(*tot_sectors <= UINT32_MAX){
set_word(boot->boot.psect, 0);
- set_dword(boot->boot.bigsect, *tot_sectors);
+ set_dword(boot->boot.bigsect, (uint32_t) *tot_sectors);
+ } else {
+ fprintf(stderr, "Too many sectors %ld\n", *tot_sectors);
+ exit(1);
}
if (dev->use_2m & 0x7f){
int bootOffset;
+ uint8_t j;
+ uint8_t size2;
+ uint16_t i;
strncpy(boot->boot.banner, "2M-STV04", 8);
boot->boot.ext.old.res_2m = 0;
boot->boot.ext.old.fmt_2mf = 6;
@@ -285,9 +289,9 @@ static __inline__ void format_root(Fs_t *Fs, char *label, union bootsector *boot
{
Stream_t *RootDir;
char *buf;
- int i;
+ unsigned int i;
struct ClashHandling_t ch;
- int dirlen;
+ unsigned int dirlen;
init_clash_handling(&ch);
ch.name_converter = label_name_uc;
@@ -361,7 +365,7 @@ static void calc_fat_size(Fs_t *Fs, unsigned long tot_sectors)
unsigned long real_rem_sect;
unsigned long numerator;
unsigned long denominator;
- int fat_nybbles;
+ unsigned int fat_nybbles;
unsigned int slack;
int printGrowMsg=1; /* Should we print "growing FAT" messages ?*/
@@ -587,7 +591,10 @@ static void calc_cluster_size(struct Fs_t *Fs, unsigned long tot_sectors,
}
-static int old_dos_size_to_geom(size_t size, int *cyls, int *heads, int *sects)
+static int old_dos_size_to_geom(size_t size,
+ unsigned int *cyls,
+ unsigned short *heads,
+ unsigned short *sects)
{
struct OldDos_t *params = getOldDosBySize(size);
if(params != NULL) {
@@ -663,6 +670,7 @@ static void calc_fs_parameters(struct device *dev, unsigned long tot_sectors,
static void calc_fs_parameters_32(unsigned long tot_sectors,
struct Fs_t *Fs, union bootsector *boot)
{
+ unsigned long num_clus;
if(DWORD(nhs))
boot->boot.descr = 0xf8;
else
@@ -671,12 +679,13 @@ static void calc_fs_parameters_32(unsigned long tot_sectors,
if(!Fs->cluster_size)
calc_cluster_size(Fs, tot_sectors, 32);
Fs->dir_len = 0;
- Fs->num_clus = tot_sectors / Fs->cluster_size;
+ num_clus = tot_sectors / Fs->cluster_size;
/* Maximal number of clusters on FAT32 is 0xffffff6 */
- if (Fs->num_clus > 0xffffff6) {
+ if (num_clus > 0xffffff6) {
fprintf(stderr, "Too many clusters\n");
exit(1);
}
+ Fs->num_clus = (unsigned int) num_clus;
set_fat32(Fs);
calc_fat_size(Fs, tot_sectors);
set_word(boot->boot.fatlen, 0);
@@ -726,9 +735,9 @@ static int get_block_geom(int fd, struct device *dev, char *errmsg) {
struct hd_geometry geom;
int sec_size;
long size;
- int heads=dev->heads;
- int sectors=dev->sectors;
- int sect_per_track;
+ uint16_t heads=dev->heads;
+ uint16_t sectors=dev->sectors;
+ unsigned int sect_per_track;
if (ioctl(fd, HDIO_GETGEO, &geom) < 0) {
sprintf(errmsg, "Could not get geometry of device (%s)",
@@ -757,11 +766,11 @@ static int get_block_geom(int fd, struct device *dev, char *errmsg) {
sect_per_track = heads * sectors;
if(!dev->hidden) {
- int hidden;
+ unsigned long hidden;
hidden = geom.start % sect_per_track;
if(hidden && hidden != sectors) {
sprintf(errmsg,
- "Hidden (%d) does not match sectors (%d)\n",
+ "Hidden (%ld) does not match sectors (%d)\n",
hidden, sectors);
return -1;
}
@@ -856,7 +865,7 @@ static int get_lba_geom(Stream_t *Direct, unsigned long tot_sectors, struct devi
return -1;
}
- dev->tracks = tracks;
+ dev->tracks = (uint32_t) tracks;
return 0;
}
@@ -866,13 +875,14 @@ void mformat(int argc, char **argv, int dummy UNUSEDP)
{
int r; /* generic return value */
Fs_t Fs;
- int hs, hs_set;
- int arguse_2m = 0;
- int sectors0=18; /* number of sectors on track 0 */
+ unsigned int hs;
+ int hs_set;
+ unsigned int arguse_2m = 0;
+ uint8_t sectors0=18; /* number of sectors on track 0 */
int create = 0;
- int rate_0, rate_any;
+ uint8_t rate_0, rate_any;
int mangled;
- int argssize=0; /* sector size */
+ uint8_t argssize=0; /* sector size */
int msize=0;
int fat32 = 0;
struct label_blk_t *labelBlock;
@@ -888,7 +898,8 @@ void mformat(int argc, char **argv, int dummy UNUSEDP)
int c;
int keepBoot = 0;
struct device used_dev;
- int argtracks, argheads, argsectors;
+ unsigned int argtracks;
+ uint16_t argheads, argsectors;
unsigned long tot_sectors=0;
int blocksize;
@@ -898,9 +909,9 @@ void mformat(int argc, char **argv, int dummy UNUSEDP)
dos_name_t shortlabel;
struct device *dev;
- char errmsg[200];
+ char errmsg[2100];
- unsigned long serial;
+ uint32_t serial;
int serial_set;
int fsVersion;
int mediaDesc=-1;
@@ -931,14 +942,14 @@ void mformat(int argc, char **argv, int dummy UNUSEDP)
Fs.refs = 1;
Fs.dir_len = 0;
if(getenv("MTOOLS_DIR_LEN")) {
- Fs.dir_len = atoi(getenv("MTOOLS_DIR_LEN"));
+ Fs.dir_len = atoui(getenv("MTOOLS_DIR_LEN"));
if(Fs.dir_len <= 0)
Fs.dir_len=0;
}
Fs.fat_len = 0;
Fs.num_fat = 2;
if(getenv("MTOOLS_NFATS")) {
- Fs.num_fat = atoi(getenv("MTOOLS_NFATS"));
+ Fs.num_fat = atoui(getenv("MTOOLS_NFATS"));
if(Fs.num_fat <= 0)
Fs.num_fat=2;
}
@@ -971,7 +982,7 @@ void mformat(int argc, char **argv, int dummy UNUSEDP)
argtracks = 40;
break;
case 'f':
- r=old_dos_size_to_geom(atoi(optarg),
+ r=old_dos_size_to_geom(atoul(optarg),
&argtracks, &argheads,
&argsectors);
if(r) {
@@ -981,16 +992,16 @@ void mformat(int argc, char **argv, int dummy UNUSEDP)
}
break;
case 't':
- argtracks = atoi(optarg);
+ argtracks = atou16(optarg);
break;
case 'T':
- tot_sectors = atoi(optarg);
+ tot_sectors = atoui(optarg);
break;
case 'n': /*non-standard*/
case 's':
- argsectors = atoi(optarg);
+ argsectors = atou16(optarg);
break;
case 'l': /* non-standard */
@@ -1017,7 +1028,7 @@ void mformat(int argc, char **argv, int dummy UNUSEDP)
case 'S':
- argssize = atoi(optarg) | 0x80;
+ argssize = atou8(optarg) | 0x80;
if(argssize < 0x80)
usage(1);
if(argssize >= 0x87) {
@@ -1034,17 +1045,17 @@ void mformat(int argc, char **argv, int dummy UNUSEDP)
case '2':
arguse_2m = 0xff;
- sectors0 = atoi(optarg);
+ sectors0 = atou8(optarg);
break;
case '3':
arguse_2m = 0x80;
break;
case '0': /* rate on track 0 */
- rate_0 = atoi(optarg);
+ rate_0 = atou8(optarg);
break;
case 'A': /* rate on other tracks */
- rate_any = atoi(optarg);
+ rate_any = atou8(optarg);
break;
case 'M':
@@ -1059,7 +1070,7 @@ void mformat(int argc, char **argv, int dummy UNUSEDP)
break;
case 'N':
- serial = strtoul(optarg,&endptr,16);
+ serial = strtou32(optarg,&endptr,16);
serial_set = 1;
break;
case 'a': /* Atari style serial number */
@@ -1071,23 +1082,23 @@ void mformat(int argc, char **argv, int dummy UNUSEDP)
break;
case 'H':
- hs = atoi(optarg);
+ hs = atoui(optarg);
hs_set = 1;
break;
case 'I':
- fsVersion = strtoul(optarg,&endptr,0);
+ fsVersion = strtoi(optarg,&endptr,0);
break;
case 'c':
- Fs.cluster_size = atoi(optarg);
+ Fs.cluster_size = atoui(optarg);
break;
case 'r':
- Fs.dir_len = strtoul(optarg,&endptr,0);
+ Fs.dir_len = strtoui(optarg,&endptr,0);
break;
case 'L':
- Fs.fat_len = strtoul(optarg,&endptr,0);
+ Fs.fat_len = strtoui(optarg,&endptr,0);
break;
@@ -1098,7 +1109,7 @@ void mformat(int argc, char **argv, int dummy UNUSEDP)
keepBoot = 1;
break;
case 'K':
- backupBoot = atoi(optarg);
+ backupBoot = atoui(optarg);
backupBootSet=1;
if(backupBoot < 2) {
fprintf(stderr, "Backupboot must be greater than 2\n");
@@ -1106,18 +1117,18 @@ void mformat(int argc, char **argv, int dummy UNUSEDP)
}
break;
case 'R':
- resvSects = atoi(optarg);
+ resvSects = atoui(optarg);
break;
case 'h':
- argheads = atoi(optarg);
+ argheads = atou16(optarg);
break;
case 'd':
- Fs.num_fat = atoi(optarg);
+ Fs.num_fat = atoui(optarg);
break;
case 'm':
- mediaDesc = strtoul(optarg,&endptr,0);
+ mediaDesc = strtoi(optarg,&endptr,0);
if(*endptr)
- mediaDesc = strtoul(optarg,&endptr,16);
+ mediaDesc = strtoi(optarg,&endptr,16);
break;
default:
usage(1);
@@ -1283,9 +1294,15 @@ void mformat(int argc, char **argv, int dummy UNUSEDP)
if (!create &&
READS(Fs.Direct, &boot.characters, 0, Fs.sector_size) !=
(signed int) Fs.sector_size) {
+#ifdef HAVE_SNPRINTF
+ snprintf(errmsg, sizeof(errmsg)-1,
+ "Error reading from '%s', wrong parameters?",
+ name);
+#else
sprintf(errmsg,
"Error reading from '%s', wrong parameters?",
name);
+#endif
continue;
}
break;
@@ -1441,14 +1458,15 @@ void mformat(int argc, char **argv, int dummy UNUSEDP)
labelBlock->dos4 = 0x29;
if (!serial_set || Atari)
- srandom(time (0));
+ init_random();
if (!serial_set)
- serial=random();
+ serial=(uint32_t) random();
set_dword(labelBlock->serial, serial);
label_name_pc(GET_DOSCONVERT((Stream_t *)&Fs),
label[0] ? label : "NO NAME ", 0,
&mangled, &shortlabel);
- strncpy(labelBlock->label, shortlabel.base, 11);
+ strncpy(labelBlock->label, shortlabel.base, 8);
+ strncpy(labelBlock->label+8, shortlabel.ext, 3);
sprintf(labelBlock->fat_type, "FAT%2.2d ", Fs.fat_bits);
labelBlock->fat_type[7] = ' ';
@@ -1465,9 +1483,9 @@ void mformat(int argc, char **argv, int dummy UNUSEDP)
}
if(Atari) {
boot.boot.banner[4] = 0;
- boot.boot.banner[5] = random();
- boot.boot.banner[6] = random();
- boot.boot.banner[7] = random();
+ boot.boot.banner[5] = (char) random();
+ boot.boot.banner[6] = (char) random();
+ boot.boot.banner[7] = (char) random();
}
if(!keepBoot)
diff --git a/minfo.1 b/minfo.1
index a3cd019..a09eb7b 100644
--- a/minfo.1
+++ b/minfo.1
@@ -1,5 +1,5 @@
'\" t
-.TH minfo 1 "02Dec18" mtools-4.0.22
+.TH minfo 1 "10Dec18" mtools-4.0.23
.SH Name
minfo - print the parameters of a MSDOS filesystem
'\" t
diff --git a/minfo.c b/minfo.c
index fceb7e5..05c4e9d 100644
--- a/minfo.c
+++ b/minfo.c
@@ -184,7 +184,7 @@ void minfo(int argc, char **argv, int type UNUSEDP)
sect_per_track = dev.sectors * dev.heads;
if(sect_per_track != 0) {
- int hidden;
+ unsigned int hidden;
unsigned long tot_sectors;
int tracks_match=0;
printf("mformat command line: mformat ");
diff --git a/misc.c b/misc.c
index 9f83649..a119cfe 100644
--- a/misc.c
+++ b/misc.c
@@ -242,7 +242,7 @@ void myfree(void *ptr)
{
int *size = ((int *) ptr)-1;
total -= *size;
- fprintf(stderr, "freeing %d bytes at %p total alloced=%d\n",
+ fprintf(stderr, "freeing %d bytes at %p total allocated=%d\n",
*size, ptr, total);
free(size);
}
diff --git a/missFuncs.c b/missFuncs.c
index e760336..271fe0b 100644
--- a/missFuncs.c
+++ b/missFuncs.c
@@ -269,7 +269,7 @@ size_t strspn(const char *s, const char *accept)
#endif /* HAVE_STRSPN */
#ifndef HAVE_STRCSPN
-/* Return the length of the maximum inital segment of S
+/* Return the length of the maximum initial segment of S
which contains no characters from REJECT. */
size_t strcspn (const char *s, const char *reject)
{
diff --git a/mk_direntry.c b/mk_direntry.c
index 858e5af..37015ea 100644
--- a/mk_direntry.c
+++ b/mk_direntry.c
@@ -156,7 +156,8 @@ static __inline__ clash_action ask_namematch(doscp_t *cp,
}
if (!isprimary)
- name = unix_normalize(cp, name_buffer, dosname);
+ name = unix_normalize(cp, name_buffer,
+ dosname, sizeof(*dosname));
else
name = longname;
diff --git a/mkmanifest.1 b/mkmanifest.1
index b0bae8b..00d54c2 100644
--- a/mkmanifest.1
+++ b/mkmanifest.1
@@ -1,5 +1,5 @@
'\" t
-.TH mkmanifest 1 "02Dec18" mtools-4.0.22
+.TH mkmanifest 1 "10Dec18" mtools-4.0.23
.SH Name
mkmanifest - makes list of file names and their DOS 8+3 equivalent
'\" t
diff --git a/mkmanifest.c b/mkmanifest.c
index 2582fb4..1ccf37f 100644
--- a/mkmanifest.c
+++ b/mkmanifest.c
@@ -103,6 +103,7 @@ static char *dos_name2(const char *name)
while (ext && (s = strpbrk(ext, "^+=/[]:',?*\\<>|\". ")))
*s = 'x';
strncpy(ans, temp, 12);
+ ans[12] = '\0';
}
if (ext && *ext) {
strcat(ans, ".");
diff --git a/mlabel.1 b/mlabel.1
index 0382658..a16a84a 100644
--- a/mlabel.1
+++ b/mlabel.1
@@ -1,5 +1,5 @@
'\" t
-.TH mlabel 1 "02Dec18" mtools-4.0.22
+.TH mlabel 1 "10Dec18" mtools-4.0.23
.SH Name
mlabel - make an MSDOS volume label
'\" t
diff --git a/mlabel.c b/mlabel.c
index 43ce31b..f37645c 100644
--- a/mlabel.c
+++ b/mlabel.c
@@ -51,7 +51,7 @@ static void _label_name(doscp_t *cp, const char *filename, int verbose UNUSEDP,
if(isupper(wbuffer[i]))
have_upper = 1;
if(!preserve_case)
- wbuffer[i] = towupper(wbuffer[i]);
+ wbuffer[i] = ch_towupper(wbuffer[i]);
if(
#ifdef HAVE_WCHAR_H
wcschr(L"^+=/[]:,?*\\<>|\".", wbuffer[i])
@@ -119,7 +119,7 @@ void mlabel(int argc, char **argv, int type UNUSEDP)
int c;
int mangled;
enum { SER_NONE, SER_RANDOM, SER_SET } set_serial = SER_NONE;
- long serial = 0;
+ unsigned long serial = 0;
int need_write_boot = 0;
int have_boot = 0;
char *eptr;
@@ -158,7 +158,7 @@ void mlabel(int argc, char **argv, int type UNUSEDP)
break;
case 'n':
set_serial = SER_RANDOM;
- srandom(time (0));
+ init_random();
serial=random();
break;
case 'N':
@@ -219,7 +219,8 @@ void mlabel(int argc, char **argv, int type UNUSEDP)
initializeDirentry(&entry, RootDir);
r=vfat_lookup(&entry, 0, 0, ACCEPT_LABEL | MATCH_ANY,
- shortname, longname);
+ shortname, sizeof(shortname),
+ longname, sizeof(longname));
if (r == -2) {
FREE(&RootDir);
exit(1);
@@ -302,7 +303,8 @@ void mlabel(int argc, char **argv, int type UNUSEDP)
label_name_pc(cp, shrtLabel, verbose, &mangled, &dosname);
if(have_boot && boot.boot.descr >= 0xf0 && has_BPB4) {
- strncpy(labelBlock->label, dosname.base, 11);
+ strncpy(labelBlock->label, dosname.base, 8);
+ strncpy(labelBlock->label+8, dosname.ext, 3);
need_write_boot = 1;
}
diff --git a/mmd.1 b/mmd.1
index 3b0c0f9..03d8b5e 100644
--- a/mmd.1
+++ b/mmd.1
@@ -1,5 +1,5 @@
'\" t
-.TH mmd 1 "02Dec18" mtools-4.0.22
+.TH mmd 1 "10Dec18" mtools-4.0.23
.SH Name
mmd - make an MSDOS subdirectory
'\" t
diff --git a/mmd.c b/mmd.c
index a7cf916..c6b34eb 100644
--- a/mmd.c
+++ b/mmd.c
@@ -172,7 +172,7 @@ void mmd(int argc, char **argv, int type UNUSEDP)
case '?':
usage(1);
case 'o':
- handle_clash_options(&arg.ch, c);
+ handle_clash_options(&arg.ch, (char) c);
break;
case 'D':
if(handle_clash_options(&arg.ch, *optarg))
diff --git a/mmount.1 b/mmount.1
index 0501729..b32e69f 100644
--- a/mmount.1
+++ b/mmount.1
@@ -1,5 +1,5 @@
'\" t
-.TH mmount 1 "02Dec18" mtools-4.0.22
+.TH mmount 1 "10Dec18" mtools-4.0.23
.SH Name
mmount - mount an MSDOS disk
'\" t
diff --git a/mmove.1 b/mmove.1
index 646abd4..8b8ab9e 100644
--- a/mmove.1
+++ b/mmove.1
@@ -1,5 +1,5 @@
'\" t
-.TH mmove 1 "02Dec18" mtools-4.0.22
+.TH mmove 1 "10Dec18" mtools-4.0.23
.SH Name
mmove - move or rename an MSDOS file or subdirectory
'\" t
diff --git a/mmove.c b/mmove.c
index 41af44b..d9221cf 100644
--- a/mmove.c
+++ b/mmove.c
@@ -77,7 +77,7 @@ static int renameit(dos_name_t *dosname,
initializeDirentry(&subEntry, arg->mp.File);
switch(vfat_lookup(&subEntry, "..", 2, ACCEPT_DIR,
- NULL, NULL)) {
+ NULL, 0, NULL, 0)) {
case -1:
fprintf(stderr,
" Directory has no parent entry\n");
@@ -312,10 +312,12 @@ void mmove(int argc, char **argv, int oldsyntax)
}
- arg.mp.longname = longname;
+ arg.mp.longname.data = longname;
+ arg.mp.longname.len = sizeof(longname);
longname[0]='\0';
- arg.mp.shortname = shortname;
+ arg.mp.shortname.data = shortname;
+ arg.mp.shortname.len = sizeof(shortname);
shortname[0]='\0';
exit(main_loop(&arg.mp, argv + optind, argc - optind - 1));
diff --git a/mpartition.1 b/mpartition.1
index cd8f546..cf6f377 100644
--- a/mpartition.1
+++ b/mpartition.1
@@ -1,5 +1,5 @@
'\" t
-.TH mpartition 1 "02Dec18" mtools-4.0.22
+.TH mpartition 1 "10Dec18" mtools-4.0.23
.SH Name
mpartition - partition an MSDOS hard disk
'\" t
diff --git a/mpartition.c b/mpartition.c
index 4aa8297..4d20ef0 100644
--- a/mpartition.c
+++ b/mpartition.c
@@ -252,8 +252,8 @@ int consistencyCheck(struct partition *partTable, int doprint, int verbose,
* accommodated. This algorithm does not use physical geometry.
*/
-static int setsize(unsigned long capacity,unsigned int *cyls,unsigned int *hds,
- unsigned int *secs) {
+static int setsize(unsigned long capacity,unsigned int *cyls,
+ uint16_t *hds, uint16_t *secs) {
unsigned int rv = 0;
unsigned long heads, sectors, cylinders, temp;
@@ -282,7 +282,7 @@ static int setsize(unsigned long capacity,unsigned int *cyls,unsigned int *hds,
}
static void setsize0(unsigned long capacity,unsigned int *cyls,
- unsigned int *hds, unsigned int *secs)
+ uint16_t *hds, uint16_t *secs)
{
int r;
@@ -358,7 +358,7 @@ void mpartition(int argc, char **argv, int dummy UNUSEDP)
unsigned char buf[512];
struct partition *partTable=(struct partition *)(buf+ 0x1ae);
struct device *dev;
- char errmsg[200];
+ char errmsg[2100];
char *bootSector=0;
argtracks = 0;
@@ -411,7 +411,7 @@ void mpartition(int argc, char **argv, int dummy UNUSEDP)
/* could be abused to "manually" create
* extended partitions */
open2flags |= NO_PRIV;
- type = strtoul(optarg,0,0);
+ type = strtoi(optarg,0,0);
break;
case 't':
@@ -440,16 +440,16 @@ void mpartition(int argc, char **argv, int dummy UNUSEDP)
* extending beyond the actual size of the
* device */
open2flags |= NO_PRIV;
- tot_sectors = strtoul(optarg,0,0);
+ tot_sectors = strtoui(optarg,0,0);
sizetest = 1;
break;
case 'b':
begin_set = 1;
- begin = strtoul(optarg, NULL, 10);
+ begin = strtoui(optarg, NULL, 10);
break;
case 'l':
size_set = 1;
- length = strtoul(optarg, NULL, 10);
+ length = strtoui(optarg, NULL, 10);
break;
default:
@@ -499,7 +499,8 @@ void mpartition(int argc, char **argv, int dummy UNUSEDP)
if (!Stream) {
#ifdef HAVE_SNPRINTF
- snprintf(errmsg,199,"init: open: %s", strerror(errno));
+ snprintf(errmsg,sizeof(errmsg)-1,
+ "init: open: %s", strerror(errno));
#else
sprintf(errmsg,"init: open: %s", strerror(errno));
#endif
@@ -537,7 +538,7 @@ void mpartition(int argc, char **argv, int dummy UNUSEDP)
/* read the partition table */
if (READS(Stream, (char *) buf, 0, 512) != 512 && !initialize){
#ifdef HAVE_SNPRINTF
- snprintf(errmsg, 199,
+ snprintf(errmsg, sizeof(errmsg)-1,
"Error reading from '%s', wrong parameters?",
name);
#else
@@ -653,7 +654,7 @@ void mpartition(int argc, char **argv, int dummy UNUSEDP)
if(!used_dev.sectors && !used_dev.heads) {
if(tot_sectors)
setsize0(tot_sectors,&dummy2,&used_dev.heads,
- &used_dev.sectors);
+ &used_dev.sectors);
else {
used_dev.heads = 64;
used_dev.sectors = 32;
diff --git a/mrd.1 b/mrd.1
index 51e2870..6c6ec53 100644
--- a/mrd.1
+++ b/mrd.1
@@ -1,5 +1,5 @@
'\" t
-.TH mrd 1 "02Dec18" mtools-4.0.22
+.TH mrd 1 "10Dec18" mtools-4.0.23
.SH Name
mrd - remove an MSDOS subdirectory
'\" t
diff --git a/mren.1 b/mren.1
index c8acb02..d5c9b89 100644
--- a/mren.1
+++ b/mren.1
@@ -1,5 +1,5 @@
'\" t
-.TH mren 1 "02Dec18" mtools-4.0.22
+.TH mren 1 "10Dec18" mtools-4.0.23
.SH Name
mren - rename an existing MSDOS file
'\" t
diff --git a/msdos.h b/msdos.h
index 39df870..192228b 100644
--- a/msdos.h
+++ b/msdos.h
@@ -33,8 +33,8 @@
#define NEW 1
#define OLD 0
-#define _WORD(x) ((unsigned short)((unsigned char)(x)[0] + (((unsigned char)(x)[1]) << 8)))
-#define _DWORD(x) ((unsigned int)(_WORD(x) + (_WORD((x)+2) << 16)))
+#define _WORD(x) ((uint16_t)((unsigned char)(x)[0] + (((unsigned char)(x)[1]) << 8)))
+#define _DWORD(x) ((uint32_t)(_WORD(x) + (_WORD((x)+2) << 16)))
#define DELMARK ((char) 0xe5)
#define ENDMARK ((char) 0x00)
@@ -67,7 +67,7 @@ struct directory {
#define STARTHI(dir) (_WORD((dir)->startHi))
/* ASSUMPTION: long is at least 32 bits */
-UNUSED(static __inline__ void set_dword(unsigned char *data, unsigned long value))
+UNUSED(static __inline__ void set_dword(unsigned char *data, uint32_t value))
{
data[3] = (value >> 24) & 0xff;
data[2] = (value >> 16) & 0xff;
@@ -164,7 +164,7 @@ typedef struct oldboot_t {
struct bootsector_s {
unsigned char jump[3]; /* 0 Jump to boot code */
- char banner[8]; /* 3 OEM name & version */
+ char banner[8] NONULLTERM; /* 3 OEM name & version */
unsigned char secsiz[2]; /* 11 Bytes per sector hopefully 512 */
unsigned char clsiz; /* 13 Cluster size in sectors */
unsigned char nrsvsect[2]; /* 14 Number of reserved (boot) sectors */
diff --git a/mshortname.1 b/mshortname.1
index 909bec3..00e65d3 100644
--- a/mshortname.1
+++ b/mshortname.1
@@ -1,5 +1,5 @@
'\" t
-.TH mshortname 1 "02Dec18" mtools-4.0.22
+.TH mshortname 1 "10Dec18" mtools-4.0.23
.SH Name
mshortname - shows short name of a file
'\" t
diff --git a/mshowfat.1 b/mshowfat.1
index 437fb51..36405e4 100644
--- a/mshowfat.1
+++ b/mshowfat.1
@@ -1,5 +1,5 @@
'\" t
-.TH mshowfat 1 "02Dec18" mtools-4.0.22
+.TH mshowfat 1 "10Dec18" mtools-4.0.23
.SH Name
mshowfat - shows FAT clusters allocated to file
'\" t
diff --git a/mtools.1 b/mtools.1
index c11e24c..78cdd89 100644
--- a/mtools.1
+++ b/mtools.1
@@ -1,5 +1,5 @@
'\" t
-.TH mtools 1 "02Dec18" mtools-4.0.22
+.TH mtools 1 "10Dec18" mtools-4.0.23
.SH Name
mtools - utilities to access DOS disks in Unix.
'\" t
@@ -36,10 +36,10 @@ Mtools can be found at the following places (and their mirrors):
.nf
.ft 3
.in +0.3i
-http://ftp.gnu.org/gnu/mtools/mtools-4.0.22.tar.gz
-http://mtools.linux.lu/mtools-4.0.22.tar.gz
-ftp://www.tux.org/pub/knaff/mtools/mtools-4.0.22.tar.gz
-ftp://ibiblio.unc.edu/pub/Linux/utils/disk-management/mtools-4.0.22.tar.gz
+http://ftp.gnu.org/gnu/mtools/mtools-4.0.23.tar.gz
+http://mtools.linux.lu/mtools-4.0.23.tar.gz
+ftp://www.tux.org/pub/knaff/mtools/mtools-4.0.23.tar.gz
+ftp://ibiblio.unc.edu/pub/Linux/utils/disk-management/mtools-4.0.23.tar.gz
.fi
.in -0.3i
.ft R
diff --git a/mtools.5 b/mtools.5
index ab20052..bfc611a 100644
--- a/mtools.5
+++ b/mtools.5
@@ -1,5 +1,5 @@
'\" t
-.TH mtools 5 "02Dec18" MTOOLS MTOOLS
+.TH mtools 5 "10Dec18" MTOOLS MTOOLS
.SH Name
mtools.conf - mtools configuration files
'\" t
@@ -13,7 +13,7 @@ mtools.conf - mtools configuration files
.tr \(if`
.tr \(pd"
-.ds St Mtools\ 4.0.22
+.ds St Mtools\ 4.0.23
.PP
.SH Description
.PP
diff --git a/mtools.h b/mtools.h
index 5eeb620..8e0eff8 100644
--- a/mtools.h
+++ b/mtools.h
@@ -47,15 +47,15 @@ extern int lockf(int, int, off_t); /* SCO has no proper include file for lockf
typedef struct device {
const char *name; /* full path to device */
- char drive; /* the drive letter */
- int fat_bits; /* FAT encoding scheme */
+ char drive; /* the drive letter */
+ int fat_bits; /* FAT encoding scheme */
- unsigned int mode; /* any special open() flags */
+ int mode; /* any special open() flags */
unsigned int tracks; /* tracks */
- unsigned int heads; /* heads */
- unsigned int sectors; /* sectors */
+ uint16_t heads; /* heads */
+ uint16_t sectors; /* sectors */
unsigned int hidden; /* number of hidden sectors. Used for
- * mformatting partitioned devices */
+ * mformatting partitioned devices */
off_t offset; /* skip this many bytes */
@@ -64,31 +64,31 @@ typedef struct device {
unsigned int misc_flags;
/* Linux only stuff */
- unsigned int ssize;
+ uint8_t ssize;
unsigned int use_2m;
char *precmd; /* command to be executed before opening
- * the drive */
+ * the drive */
/* internal variables */
int file_nr; /* used during parsing */
- unsigned int blocksize; /* size of disk block in bytes */
+ unsigned int blocksize; /* size of disk block in bytes */
- int codepage; /* codepage for shortname encoding */
+ int codepage; /* codepage for shortname encoding */
const char *cfg_filename; /* used for debugging purposes */
} device_t;
struct OldDos_t {
unsigned int tracks;
- unsigned int sectors;
- unsigned int heads;
+ uint16_t sectors;
+ uint16_t heads;
unsigned int dir_len;
unsigned int cluster_size;
unsigned int fat_len;
- int media;
+ uint8_t media;
};
extern struct OldDos_t *getOldDosBySize(size_t size);
@@ -158,7 +158,8 @@ int readwrite_sectors(int fd, /* file descriptor */
int lock_dev(int fd, int mode, struct device *dev);
-char *unix_normalize (doscp_t *cp, char *ans, struct dos_name_t *dn);
+char *unix_normalize (doscp_t *cp, char *ans, struct dos_name_t *dn,
+ size_t ans_size);
void dos_name(doscp_t *cp, const char *filename, int verbose, int *mangled,
struct dos_name_t *);
struct directory *mk_entry(const dos_name_t *filename, unsigned char attr,
@@ -219,6 +220,22 @@ UNUSED(static __inline__ char ch_tolower(char ch))
return (char) tolower( (unsigned char) ch);
}
+UNUSED(static __inline__ wchar_t ch_towupper(wchar_t ch))
+{
+ return (wchar_t) towupper( (wint_t) ch);
+}
+
+UNUSED(static __inline__ wchar_t ch_towlower(wchar_t ch))
+{
+ return (wchar_t) towlower( (wint_t) ch);
+}
+
+UNUSED(static __inline__ void init_random(void))
+{
+ srandom((unsigned int)time (0));
+}
+
+
Stream_t *GetFs(Stream_t *Fs);
void label_name_uc(doscp_t *cp, const char *filename, int verbose,
@@ -237,7 +254,7 @@ extern unsigned int mtools_dotted_dir;
extern unsigned int mtools_lock_timeout;
extern unsigned int mtools_twenty_four_hour_clock;
extern const char *mtools_date_string;
-extern unsigned int mtools_rate_0, mtools_rate_any;
+extern uint8_t mtools_rate_0, mtools_rate_any;
extern unsigned int mtools_default_codepage;
extern int mtools_raw_tty;
@@ -247,6 +264,17 @@ char get_default_drive(void);
void set_cmd_line_image(char *img);
void read_config(void);
off_t str_to_offset(char *str);
+unsigned int strtoui(const char *nptr, char **endptr, int base);
+unsigned int atoui(const char *nptr);
+int strtoi(const char *nptr, char **endptr, int base);
+unsigned long atoul(const char *nptr);
+uint8_t strtou8(const char *nptr, char **endptr, int base);
+uint8_t atou8(const char *str);
+uint16_t strtou16(const char *nptr, char **endptr, int base);
+uint16_t atou16(const char *str);
+uint32_t strtou32(const char *nptr, char **endptr, int base);
+uint32_t atou32(const char *str);
+
extern struct device *devices;
extern struct device const_devices[];
extern const unsigned int nr_const_devices;
@@ -321,7 +349,7 @@ FILE *open_mcwd(const char *mode);
void unlink_mcwd(void);
#ifndef OS_mingw32msvc
-int safePopenOut(const char **command, char *output, int len);
+ssize_t safePopenOut(const char **command, char *output, size_t len);
#endif
#define ROUND_DOWN(value, grain) ((value) - (value) % (grain))
diff --git a/mtools.info b/mtools.info
index 0505f16..76c945e 100644
--- a/mtools.info
+++ b/mtools.info
@@ -1,6 +1,6 @@
This is mtools.info, produced by makeinfo version 6.3 from mtools.texi.
-This manual is for Mtools (version 4.0.22, December 2018), which is a
+This manual is for Mtools (version 4.0.23, December 2018), which is a
collection of tools to allow Unix systems to manipulate MS-DOS files.
Copyright (C) 2007, 2009 Free Software Foundation, Inc. Copyright
@@ -41,7 +41,7 @@ preliminary mounting or initialization (assuming the default
'/etc/mtools.conf' works on your machine). With mtools, one can change
floppies too without unmounting and mounting.
- This manual is for Mtools (version 4.0.22, December 2018), which is a
+ This manual is for Mtools (version 4.0.23, December 2018), which is a
collection of tools to allow Unix systems to manipulate MS-DOS files.
Copyright (C) 2007, 2009 Free Software Foundation, Inc. Copyright
@@ -75,10 +75,10 @@ File: mtools.info, Node: Location, Next: Common features, Prev: Top, Up: Top
*********************
Mtools can be found at the following places (and their mirrors):
- http://ftp.gnu.org/gnu/mtools/mtools-4.0.22.tar.gz
- http://mtools.linux.lu/mtools-4.0.22.tar.gz
- ftp://www.tux.org/pub/knaff/mtools/mtools-4.0.22.tar.gz
- ftp://ibiblio.unc.edu/pub/Linux/utils/disk-management/mtools-4.0.22.tar.gz
+ http://ftp.gnu.org/gnu/mtools/mtools-4.0.23.tar.gz
+ http://mtools.linux.lu/mtools-4.0.23.tar.gz
+ ftp://www.tux.org/pub/knaff/mtools/mtools-4.0.23.tar.gz
+ ftp://ibiblio.unc.edu/pub/Linux/utils/disk-management/mtools-4.0.23.tar.gz
Before reporting a bug, make sure that it has not yet been fixed in
the Alpha patches which can be found at:
@@ -1681,8 +1681,8 @@ has a different meaning.
'R'
Sets the number of reserved sectors for this filesystem. This must
be at least 1 for non-FAT32 disks, and at least 3 for FAT disks (in
- order to accomodate the boot sector, the info sector and the backup
- boot sector).
+ order to accommodate the boot sector, the info sector and the
+ backup boot sector).
'm'
Use a non-standard media descriptor byte for this disk. The media
@@ -2726,26 +2726,26 @@ Node: mdeltree58860
Node: mdir59279
Node: mdu60555
Node: mformat61061
-Node: mkmanifest69571
-Node: minfo71545
-Node: mlabel72115
-Node: mmd73268
-Node: mmount73617
-Node: mmove74216
-Node: mpartition75023
-Node: mrd80536
-Node: mren80894
-Node: mshortname81643
-Node: mshowfat81973
-Node: mtoolstest82382
-Node: mtype82954
-Node: mzip83805
-Ref: mzip-Footnote-185830
-Ref: mzip-Footnote-285911
-Node: Compiling mtools86198
-Node: Porting mtools87297
-Node: Command Index93201
-Node: Variable Index93329
-Node: Concept Index95152
+Node: mkmanifest69572
+Node: minfo71546
+Node: mlabel72116
+Node: mmd73269
+Node: mmount73618
+Node: mmove74217
+Node: mpartition75024
+Node: mrd80537
+Node: mren80895
+Node: mshortname81644
+Node: mshowfat81974
+Node: mtoolstest82383
+Node: mtype82955
+Node: mzip83806
+Ref: mzip-Footnote-185831
+Ref: mzip-Footnote-285912
+Node: Compiling mtools86199
+Node: Porting mtools87298
+Node: Command Index93202
+Node: Variable Index93330
+Node: Concept Index95153

End Tag Table
diff --git a/mtools.spec b/mtools.spec
index 2d6a238..df41d6a 100644
--- a/mtools.spec
+++ b/mtools.spec
@@ -1,7 +1,7 @@
%define _binary_payload w9.gzdio
Name: mtools
Summary: mtools, read/write/list/format DOS disks under Unix
-Version: 4.0.22
+Version: 4.0.23
Release: 1
License: GPLv3+
Group: Utilities/System
@@ -135,6 +135,11 @@ if [ -f %{_bindir}/install-info ] ; then
fi
%changelog
+* Sun Dec 09 2018 Alain Knaff <alain@knaff.lu>
+- 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
* Sun Dec 02 2018 Alain Knaff <alain@knaff.lu>
- Fixed -f flag for mformat (size is KBytes, rather than sectors)
- Fixed toupper/tolower usage (unsigned char rather than plain signed)
diff --git a/mtools.texi b/mtools.texi
index 27dff44..c20c289 100644
--- a/mtools.texi
+++ b/mtools.texi
@@ -1917,7 +1917,7 @@ stored (only relevant on FAT32).
@item R
Sets the number of reserved sectors for this filesystem. This must be
at least 1 for non-FAT32 disks, and at least 3 for FAT disks (in order
-to accomodate the boot sector, the info sector and the backup boot
+to accommodate the boot sector, the info sector and the backup boot
sector).
@item m
diff --git a/mtools.tmpl.1 b/mtools.tmpl.1
index a227862..262aaf7 100644
--- a/mtools.tmpl.1
+++ b/mtools.tmpl.1
@@ -1,5 +1,5 @@
'\" t
-.TH mtools 1 "02Dec18" mtools-4.0.22
+.TH mtools 1 "10Dec18" mtools-4.0.23
.SH Name
mtools - utilities to access DOS disks in Unix.
'\" t
@@ -36,10 +36,10 @@ Mtools can be found at the following places (and their mirrors):
.nf
.ft 3
.in +0.3i
-http://ftp.gnu.org/gnu/mtools/mtools-4.0.22.tar.gz
-http://mtools.linux.lu/mtools-4.0.22.tar.gz
-ftp://www.tux.org/pub/knaff/mtools/mtools-4.0.22.tar.gz
-ftp://ibiblio.unc.edu/pub/Linux/utils/disk-management/mtools-4.0.22.tar.gz
+http://ftp.gnu.org/gnu/mtools/mtools-4.0.23.tar.gz
+http://mtools.linux.lu/mtools-4.0.23.tar.gz
+ftp://www.tux.org/pub/knaff/mtools/mtools-4.0.23.tar.gz
+ftp://ibiblio.unc.edu/pub/Linux/utils/disk-management/mtools-4.0.23.tar.gz
.fi
.in -0.3i
.ft R
diff --git a/mtools.tmpl.5 b/mtools.tmpl.5
index 56d7548..ec40596 100644
--- a/mtools.tmpl.5
+++ b/mtools.tmpl.5
@@ -1,5 +1,5 @@
'\" t
-.TH mtools 5 "02Dec18" MTOOLS MTOOLS
+.TH mtools 5 "10Dec18" MTOOLS MTOOLS
.SH Name
mtools.conf - mtools configuration files
'\" t
@@ -13,7 +13,7 @@ mtools.conf - mtools configuration files
.tr \(if`
.tr \(pd"
-.ds St Mtools\ 4.0.22
+.ds St Mtools\ 4.0.23
.PP
.SH Description
.PP
diff --git a/mtoolsDirentry.h b/mtoolsDirentry.h
index 2f7eccc..2ad0c29 100644
--- a/mtoolsDirentry.h
+++ b/mtoolsDirentry.h
@@ -33,8 +33,9 @@ typedef struct direntry_t {
#include "stream.h"
-int vfat_lookup(direntry_t *entry, const char *filename, int length,
- int flags, char *shortname, char *longname);
+int vfat_lookup(direntry_t *entry, const char *filename, int length, int flags,
+ char *shortname, size_t shortname_len,
+ char *longname, size_t longname_len);
struct directory *dir_read(direntry_t *entry, int *error);
diff --git a/mtoolstest.1 b/mtoolstest.1
index 8c2b4bf..8d96999 100644
--- a/mtoolstest.1
+++ b/mtoolstest.1
@@ -1,5 +1,5 @@
'\" t
-.TH mtoolstest 1 "02Dec18" mtools-4.0.22
+.TH mtoolstest 1 "10Dec18" mtools-4.0.23
.SH Name
mtoolstest - tests and displays the configuration
'\" t
diff --git a/mtype.1 b/mtype.1
index 30aa0c1..1fa6fce 100644
--- a/mtype.1
+++ b/mtype.1
@@ -1,5 +1,5 @@
'\" t
-.TH mtype 1 "02Dec18" mtools-4.0.22
+.TH mtype 1 "10Dec18" mtools-4.0.23
.SH Name
mtype - display contents of an MSDOS file
'\" t
diff --git a/mzip.1 b/mzip.1
index ea7311f..9a090f0 100644
--- a/mzip.1
+++ b/mzip.1
@@ -1,5 +1,5 @@
'\" t
-.TH mzip 1 "02Dec18" mtools-4.0.22
+.TH mzip 1 "10Dec18" mtools-4.0.23
.SH Name
mzip - change protection mode and eject disk on Zip/Jaz drive
'\" t
diff --git a/mzip.c b/mzip.c
index b5c43b2..8721910 100644
--- a/mzip.c
+++ b/mzip.c
@@ -459,14 +459,14 @@ void mzip(int argc, char **argv, int type UNUSEDP)
}
if (newMode & 0x1) {
- char first_try[_PASSWORD_LEN];
+ char first_try[_PASSWORD_LEN+1];
passwd = getpass("Enter new password:");
strncpy(first_try, passwd,_PASSWORD_LEN);
passwd = getpass("Re-type new password:");
if(strncmp(first_try, passwd, _PASSWORD_LEN)) {
fprintf(stderr,
- "You mispelled it. Password not set.\n");
+ "You misspelled it. Password not set.\n");
exit(1);
}
} else {
diff --git a/patchlevel.c b/patchlevel.c
index aecdab7..bd7c322 100644
--- a/patchlevel.c
+++ b/patchlevel.c
@@ -18,10 +18,10 @@
#include "sysincludes.h"
#include "msdos.h"
-const char *mversion="4.0.22";
+const char *mversion="4.0.23";
/* Multiple releases on same day should be marked with (b), (cd), (d) after
* date string below */
-const char *mdate = "December 2nd, 2018";
+const char *mdate = "December 9th, 2018";
-const char *mformat_banner = "MTOO4022";
+const char *mformat_banner = "MTOO4023";
diff --git a/plain_io.c b/plain_io.c
index 7554cd2..5404ba3 100644
--- a/plain_io.c
+++ b/plain_io.c
@@ -51,7 +51,7 @@ typedef struct SimpleFile_t {
int size_limited;
#endif
int scsi_sector_size;
- void *extra_data; /* extra system dependant information for scsi */
+ void *extra_data; /* extra system dependent information for scsi */
int swap; /* do the word swapping */
} SimpleFile_t;
@@ -386,7 +386,7 @@ static int scsi_io(Stream_t *Stream, char *buf,
if (firstblock > 0x1fffff || nsect > 0xff) {
/* I suspect that the ZIP drive also understands Group 1
* commands. If that is indeed true, we may chose Group 1
- * more agressively in the future */
+ * more aggressively in the future */
cdb[0] |= SCSI_GROUP1;
clen=10; /* SCSI Group 1 cmd */
diff --git a/privileges.c b/privileges.c
index 88f385f..71de4c1 100644
--- a/privileges.c
+++ b/privileges.c
@@ -82,7 +82,7 @@ static uid_t ruid, euid;
*/
-/* group id handling is lots easyer, as long as we don't use group 0.
+/* group id handling is lots easier, as long as we don't use group 0.
* If you want to use group id's, create a *new* group mtools or
* floppy. Chgrp any devices that you only want to be accessible to
* mtools to this group, and give them the appropriate privs. Make
@@ -134,7 +134,7 @@ void destroy_privs(void)
setuid(ruid); /* this should be enough to get rid of the three
* ids */
seteuid(ruid); /* for good measure... just in case we came
- * accross a system which implemented sane
+ * across a system which implemented sane
* semantics instead of POSIXly broken
* semantics for setuid */
#else
diff --git a/read_dword.h b/read_dword.h
index 7812c90..e7150c0 100644
--- a/read_dword.h
+++ b/read_dword.h
@@ -23,7 +23,7 @@ static Dword read_dword(int handle)
Byte val[4];
if(read(handle, (char *)val, 4) < 4)
- return -1;
+ return (Dword) -1;
return byte2dword(val);
}
diff --git a/strtonum.c b/strtonum.c
new file mode 100644
index 0000000..d5a5601
--- /dev/null
+++ b/strtonum.c
@@ -0,0 +1,84 @@
+/* Copyright 2018 Alain Knaff.
+ * This file is part of mtools.
+ *
+ * Mtools is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Mtools is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mtools. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+#include "sysincludes.h"
+#include "mtools.h"
+
+unsigned int strtoui(const char *nptr, char **endptr, int base) {
+ unsigned long l = strtoul(nptr, endptr, base);
+ if(l > UINT_MAX) {
+ fprintf(stderr, "%lu too large\n", l);
+ exit(1);
+ }
+ return (unsigned int) l;
+}
+
+unsigned int atoui(const char *str) {
+ return strtoui(str, 0, 0);
+}
+
+int strtoi(const char *nptr, char **endptr, int base) {
+ long l = strtol(nptr, endptr, base);
+ if(l > INT_MAX || l < INT_MIN) {
+ fprintf(stderr, "%lu out ob bounds\n", l);
+ exit(1);
+ }
+ return (int) l;
+}
+
+unsigned long atoul(const char *str) {
+ return strtoul(str, 0, 0);
+}
+
+uint8_t strtou8(const char *nptr, char **endptr, int base) {
+ unsigned long l = strtoul(nptr, endptr, base);
+ if(l > UINT8_MAX) {
+ fprintf(stderr, "%lu too large\n", l);
+ exit(1);
+ }
+ return (uint8_t) l;
+}
+
+uint8_t atou8(const char *str) {
+ return strtou8(str, 0, 0);
+}
+
+uint16_t strtou16(const char *nptr, char **endptr, int base) {
+ unsigned long l = strtoul(nptr, endptr, base);
+ if(l > UINT16_MAX) {
+ fprintf(stderr, "%lu too large\n", l);
+ exit(1);
+ }
+ return (uint16_t) l;
+}
+
+uint16_t atou16(const char *str) {
+ return strtou16(str, 0, 0);
+}
+
+uint32_t strtou32(const char *nptr, char **endptr, int base) {
+ unsigned long l = strtoul(nptr, endptr, base);
+ if(l > UINT32_MAX) {
+ fprintf(stderr, "%lu too large\n", l);
+ exit(1);
+ }
+ return (uint32_t) l;
+}
+
+uint32_t atou32(const char *str) {
+ return strtou32(str, 0, 0);
+}
diff --git a/sysincludes.h b/sysincludes.h
index b683231..056218e 100644
--- a/sysincludes.h
+++ b/sysincludes.h
@@ -35,7 +35,7 @@
/***********************************************************************/
/* */
-/* OS dependancies which cannot be covered by the autoconfigure script */
+/* OS dependencies which cannot be covered by the autoconfigure script */
/* */
/***********************************************************************/
@@ -93,7 +93,7 @@ typedef void *caddr_t;
/***********************************************************************/
/* */
-/* Compiler dependancies */
+/* Compiler dependencies */
/* */
/***********************************************************************/
@@ -105,18 +105,29 @@ typedef void *caddr_t;
/* gcc 2.6.3 doesn't have "unused" */ /* mool */
# define UNUSED(x) x __attribute__ ((unused));x
# define UNUSEDP __attribute__ ((unused))
-# else
-# define UNUSED(x) x
-# define UNUSEDP /* */
# endif
# define NORETURN __attribute__ ((noreturn))
-#else
+# if __GNUC__ >= 8
+# define NONULLTERM __attribute__ ((nonstring))
+# endif
+#endif
+
+#ifndef UNUSED
# define UNUSED(x) x
-# define UNUSEDP /* */
+# define UNUSEDP /* */
+#endif
+
+#ifndef PACKED
# define PACKED /* */
+#endif
+
+#ifndef NORETURN
# define NORETURN /* */
#endif
+#ifndef NONULLTERM
+# define NONULLTERM /* */
+#endif
/***********************************************************************/
/* */
@@ -347,6 +358,10 @@ extern int errno;
#include <netinet/in.h>
#endif
+#ifdef HAVE_NETINET_TCP_H
+#include <netinet/tcp.h>
+#endif
+
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
diff --git a/version.texi b/version.texi
index e002dc7..972a00a 100644
--- a/version.texi
+++ b/version.texi
@@ -1,3 +1,3 @@
-@set EDITION 4.0.22
-@set VERSION 4.0.22
+@set EDITION 4.0.23
+@set VERSION 4.0.23
@set UPDATED December 2018
diff --git a/vfat.c b/vfat.c
index d23ab6c..3ca0fa3 100644
--- a/vfat.c
+++ b/vfat.c
@@ -576,7 +576,7 @@ static result_t checkNameForMatch(struct direntry_t *direntry,
if(IS_DIR(direntry) && !(flags & ACCEPT_DIR)) {
if(!(flags & (ACCEPT_LABEL|MATCH_ANY|NO_MSG))) {
char tmp[4*13+1];
- wchar_to_native(dce->shortName,tmp,13);
+ WCHAR_TO_NATIVE(dce->shortName,tmp,13);
fprintf(stderr, "Skipping \"%s\", is a directory\n",
tmp);
}
@@ -587,7 +587,7 @@ static result_t checkNameForMatch(struct direntry_t *direntry,
!(flags & ACCEPT_PLAIN)) {
if(!(flags & (ACCEPT_LABEL|MATCH_ANY|NO_MSG))) {
char tmp[4*13+1];
- wchar_to_native(dce->shortName,tmp,13);
+ WCHAR_TO_NATIVE(dce->shortName,tmp,13);
fprintf(stderr,
"Skipping \"%s\", is not a directory\n",
tmp);
@@ -606,7 +606,8 @@ static result_t checkNameForMatch(struct direntry_t *direntry,
*/
int vfat_lookup(direntry_t *direntry, const char *filename, int length,
- int flags, char *shortname, char *longname)
+ int flags, char *shortname, size_t shortname_size,
+ char *longname, size_t longname_size)
{
dirCacheEntry_t *dce;
result_t result;
@@ -649,13 +650,14 @@ int vfat_lookup(direntry_t *direntry, const char *filename, int length,
if(result == RES_MATCH){
if(longname){
if(dce->longName)
- wchar_to_native(dce->longName,
- longname, MAX_VNAMELEN);
+ wchar_to_native(dce->longName, longname,
+ MAX_VNAMELEN, longname_size);
else
*longname ='\0';
}
if(shortname)
- wchar_to_native(dce->shortName, shortname, 12);
+ wchar_to_native(dce->shortName, shortname,
+ 12, shortname_size);
direntry->beginSlot = dce->beginSlot;
direntry->endSlot = dce->endSlot-1;
return 0; /* file found */
@@ -804,7 +806,7 @@ int lookupForInsert(Stream_t *Dir,
/* long match is a reason for
* immediate stop */
direntry->beginSlot = dce->beginSlot;
- direntry->endSlot = dce->endSlot-1;
+ direntry->endSlot = dce->endSlot - 1;
return 1;
}
diff --git a/xdf_io.c b/xdf_io.c
index 411a843..db02414 100644
--- a/xdf_io.c
+++ b/xdf_io.c
@@ -100,8 +100,8 @@ typedef struct Xdf_t {
int track_size;
int track0_size;
int sector_size;
- int FatSize;
- int RootDirSize;
+ unsigned int FatSize;
+ unsigned int RootDirSize;
TrackMap_t *track_map;
unsigned char last_sector;
@@ -370,7 +370,8 @@ static int load_bounds(Xdf_t *This, off_t begin, off_t end)
}
-static int fill_t0(Xdf_t *This, int ptr, int size, int *sector, int *head)
+static int fill_t0(Xdf_t *This, int ptr, unsigned int size,
+ int *sector, int *head)
{
int n;
@@ -388,7 +389,7 @@ static int fill_t0(Xdf_t *This, int ptr, int size, int *sector, int *head)
}
-static int fill_phantoms(Xdf_t *This, int ptr, int size)
+static int fill_phantoms(Xdf_t *This, int ptr, unsigned int size)
{
int n;
diff --git a/xdf_io.h b/xdf_io.h
index db5d52c..ac45a37 100644
--- a/xdf_io.h
+++ b/xdf_io.h
@@ -22,9 +22,9 @@
#include "stream.h"
struct xdf_info {
- int FatSize;
- int RootDirSize;
- int BadSectors;
+ unsigned int FatSize;
+ unsigned int RootDirSize;
+ unsigned int BadSectors;
};
Stream_t *XdfOpen(struct device *dev, char *name,