diff --git a/buffer.c b/buffer.c index a34270b..a630efb 100644 --- a/buffer.c +++ b/buffer.c @@ -27,7 +27,7 @@ typedef struct Buffer_t { int refs; Stream_t *Next; Stream_t *Buffer; - + size_t size; /* size of read/write buffer */ int dirty; /* is the buffer dirty? */ @@ -152,10 +152,10 @@ static ssize_t buf_read(Stream_t *Stream, char *buf, mt_off_t start, size_t len) size_t offset; char *disk_ptr; ssize_t ret; - DeclareThis(Buffer_t); + DeclareThis(Buffer_t); if(!len) - return 0; + return 0; /*fprintf(stderr, "buf read %x %x %x\n", Stream, start, len);*/ switch(isInBuffer(This, start, &len)) { @@ -196,7 +196,7 @@ static ssize_t buf_write(Stream_t *Stream, char *buf, mt_off_t start, size_t len) { char *disk_ptr; - DeclareThis(Buffer_t); + DeclareThis(Buffer_t); size_t offset=0; if(!len) @@ -223,7 +223,7 @@ static ssize_t buf_write(Stream_t *Stream, char *buf, size_t readSize; ssize_t ret; size_t bytes_read; - + readSize = This->cylinderSize - (size_t)(This->current % (mt_off_t) This->cylinderSize); @@ -291,7 +291,7 @@ static ssize_t buf_write(Stream_t *Stream, char *buf, This->dirty_pos = ROUND_DOWN(offset, This->sectorSize); if(!This->dirty || offset + len > This->dirty_end) This->dirty_end = ROUND_UP(offset + len, This->sectorSize); - + if(This->dirty_end > This->cur_size) { fprintf(stderr, "Internal error, dirty end too big dirty_end=%x cur_size=%x len=%x offset=%d sectorSize=%x\n", diff --git a/buffer.h b/buffer.h index 98a82dc..401e8d5 100644 --- a/buffer.h +++ b/buffer.h @@ -20,8 +20,8 @@ #include "stream.h" -Stream_t *buf_init(Stream_t *Next, - size_t size, +Stream_t *buf_init(Stream_t *Next, + size_t size, size_t cylinderSize, size_t sectorSize); diff --git a/byte_dword.h b/byte_dword.h index 8d6d0f4..dd81708 100644 --- a/byte_dword.h +++ b/byte_dword.h @@ -22,17 +22,17 @@ static Dword byte2dword(Byte* val) { Dword l; l = (Dword)((val[0] << 24) + (val[1] << 16) + (val[2] << 8) + val[3]); - + return l; -} +} UNUSED(static int32_t byte2sdword(Byte* val)) { int32_t l; l = (int32_t)((val[0] << 24) + (val[1] << 16) + (val[2] << 8) + val[3]); - + return l; -} +} UNUSED(static Qword byte2qword(Byte* val)) @@ -47,7 +47,7 @@ UNUSED(static Qword byte2qword(Byte* val)) l = (l << 8) | val[6]; l = (l << 8) | val[7]; return l; -} +} static void dword2byte(Dword parm, Byte* rval) { diff --git a/charsetConv.c b/charsetConv.c index c3d03ae..50603e8 100644 --- a/charsetConv.c +++ b/charsetConv.c @@ -1,13 +1,13 @@ /* Copyright 2008,2009 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 + * 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. * @@ -61,7 +61,7 @@ static int try(const char *testCp) { size_t outbufLen = 2*sizeof(char); iconv_t test = 0; size_t i; - + for(i=0; i < sizeof(asciiTries) / sizeof(asciiTries[0]); i++) { test = iconv_open(asciiTries[i], testCp); if(test != (iconv_t) -1) @@ -88,7 +88,7 @@ static int try(const char *testCp) { static const char *getWcharCp(void) { unsigned int i; if(wcharCp != NULL) - return wcharCp; + return wcharCp; for(i=0; i< sizeof(wcharTries) / sizeof(wcharTries[0]); i++) { if(try(wcharTries[i])) return (wcharCp=wcharTries[i]); @@ -158,7 +158,7 @@ size_t dos_to_wchar(doscp_t *cp, const char *dos, wchar_t *wchar, size_t len) size_t in_len=len; size_t out_len=len*sizeof(wchar_t); wchar_t *dptr=wchar; - char *dos2 = (char *) dos; /* Magic to be able to call iconv with its + char *dos2 = (char *) dos; /* Magic to be able to call iconv with its buggy prototype */ r=iconv(cp->from, &dos2, &in_len, (char **)&dptr, &out_len); if(r == (size_t) -1) @@ -193,7 +193,7 @@ static size_t safe_iconv(iconv_t conv, const wchar_t *wchar, char *dest, if(out_len <= 0) break; - if(dptr) + if(dptr) *dptr++ = '_'; in_len -= sizeof(wchar_t); @@ -317,7 +317,7 @@ static inline size_t wcrtomb(char *s, wchar_t wc, mbstate_t *ps) return 1; } -static inline size_t mbrtowc(wchar_t *pwc, const char *s, +static inline size_t mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) { *pwc = *s; diff --git a/codepage.h b/codepage.h index 8775865..de5db7f 100644 --- a/codepage.h +++ b/codepage.h @@ -16,7 +16,7 @@ */ typedef struct Codepage_l { - int nr; + int nr; unsigned char tounix[128]; } Codepage_t; diff --git a/codepages.c b/codepages.c index 5c437e0..ecb99ee 100644 --- a/codepages.c +++ b/codepages.c @@ -53,7 +53,7 @@ Codepage_t codepages[]= { "ÓßÔÒõÕµþÞÚÙýÝÞ¯´" "­±_¾¶§÷¸°¨·¹³²__" }, - + { 852, "ÇüéâäucçlëÕõîZÄC" "ÉLlôöLlSsÖÜTtL×c" @@ -64,7 +64,7 @@ Codepage_t codepages[]= { "ÓßÔNnñSsRÚrUýÝt´" "­~.~~§÷¸°¨·¹uRr_" }, - + { 860, "ÇüéâãàåçêëèÍõìÃÂ" "ÉÀÈôõòÚùÌÕÜ¢£ÙPÓ" @@ -75,7 +75,7 @@ Codepage_t codepages[]= { "abgpSsµtftodøØ_N" "=±<>||÷~°··Vn²__" }, - + { 863, "ÇüéâÂà¶çêëèïî_À§" "ÉÈÊôËÏûù¤ÔÜ¢£ÙÛf" @@ -86,7 +86,7 @@ Codepage_t codepages[]= { "abgpSsµtftodøØ_N" "=±<>||÷~°··Vn²__" }, - + { 865, "ÇüéâäàåçêëèïîìÄÅ" "ÉæÆôöòûùÿÖÜø£ØPf" diff --git a/config.c b/config.c index c189513..bb13682 100644 --- a/config.c +++ b/config.c @@ -47,7 +47,7 @@ static unsigned int flag_mask; /* mask of currently set flags */ static unsigned int cur_devs; /* current number of defined devices */ static int cur_dev; /* device being filled in. If negative, none */ static int trusted=0; /* is the currently parsed device entry trusted? */ -static unsigned int nr_dev; /* number of devices that the current table can +static unsigned int nr_dev; /* number of devices that the current table can hold */ struct device *devices; /* the device table */ static int token_nr; /* number of tokens in line */ @@ -305,7 +305,7 @@ static int mtools_getline(void) syntax("line too long", 1); return 0; } - + static void skip_junk(int expect) { lastTokenLinenumber = linenumber; @@ -442,7 +442,7 @@ static void grow(void) } } } - + static void init_drive(void) { @@ -673,13 +673,13 @@ static void parse_old_device_line(char drive) long offset; int heads, sectors, tracks; - + /* finish any old drive */ finish_drive_clause(); /* purge out data of old configuration files */ purge(drive, file_nr); - + /* reserve slot */ append(); items = sscanf(token,"%c %s %i %i %i %i %li", @@ -713,7 +713,7 @@ static void parse_old_device_line(char drive) devices[cur_dev].sectors = 0; devices[cur_dev].heads = 0; } - + devices[cur_dev].drive = ch_canon_drv(devices[cur_dev].drive); maintain_default_drive(devices[cur_dev].drive); if (!(devices[cur_dev].name = strdup(name))) { @@ -745,7 +745,7 @@ static int parse_one(int privilege) syntax("drive letter expected", 0); if(action==1 || action==4) - /* replace existing drive */ + /* replace existing drive */ purge(token[0], file_nr); if(action==4) return 1; @@ -822,7 +822,7 @@ void read_config(void) char *envConfFile; static char conf_file[MAXPATHLEN+sizeof(CFG_FILE1)]; - + /* copy compiled-in devices */ file_nr = 0; cur_devs = nr_const_devices; diff --git a/devices.c b/devices.c index 0d2dd23..b26cd09 100644 --- a/devices.c +++ b/devices.c @@ -176,7 +176,7 @@ static inline int get_parameters(int fd, struct generic_floppy_struct *floppy) perror("FLOPPY_GET_GEOMETRY"); return(1); } - + return 0; } @@ -186,21 +186,21 @@ static inline int get_parameters(int fd, struct generic_floppy_struct *floppy) #define FD_SECTSIZE(floppy) floppy.fg.sector_size #define FD_SET_SECTSIZE(floppy,v) { floppy.fg.sector_size = v; } -static inline int set_parameters(int fd, struct generic_floppy_struct *floppy, +static inline int set_parameters(int fd, struct generic_floppy_struct *floppy, struct MT_STAT *buf) { if (ioctl(fd, FLOPPY_SET_GEOMETRY, &(floppy->fg)) != 0) { perror(""); return(1); } - + return 0; } #define INIT_GENERIC #endif #endif /* hpux */ - + #if (defined(OS_sinix) || defined(VENDOR_sni) || defined(SNI)) #define predefined_devices @@ -320,7 +320,7 @@ struct device devices[] = { }; #endif /* aix */ - + #ifdef OS_osf4 /* modified by Chris Samuel */ #define predefined_devices @@ -336,14 +336,14 @@ struct device devices[] = { #ifdef USING_NEW_VOLD char *alias_name = NULL; - + extern char *media_oldaliases(char *); extern char *media_findname(char *); char *getVoldName(struct device *dev, char *name) { char *rname; - + if(!SHOULD_USE_VOLD(dev)) return name; @@ -359,8 +359,8 @@ char *getVoldName(struct device *dev, char *name) } #endif if (rname == NULL) { - fprintf(stderr, - "No such volume or no media in device: %s.\n", + fprintf(stderr, + "No such volume or no media in device: %s.\n", name); exit(1); } @@ -420,7 +420,7 @@ static inline int get_parameters(int fd, struct generic_floppy_struct *floppy) #define FD_SECTSIZE(floppy) floppy.fdchar.fdc_sec_size #define FD_SET_SECTSIZE(floppy,v) { floppy.fdchar.fdc_sec_size = v; } -static inline int set_parameters(int fd, struct generic_floppy_struct *floppy, +static inline int set_parameters(int fd, struct generic_floppy_struct *floppy, struct MT_STAT *buf) { if (ioctl(fd, FDIOSCHAR, &(floppy->fdchar)) != 0) { @@ -496,7 +496,7 @@ struct device devices[] = { /* * Stuffing back the floppy parameters into the driver allows for gems * like 10 sector or single sided floppies from Atari ST systems. - * + * * Martin Schulz, Universite de Moncton, N.B., Canada, March 11, 1991. */ @@ -518,7 +518,7 @@ static inline int get_parameters(int fd, struct generic_floppy_struct *floppy) ioctl(fd, FDKEJECT, NULL); return(1); } - + if (ioctl(fd, FDKIOGCHAR, &( floppy->dkbuf)) != 0) { perror(""); ioctl(fd, FDKEJECT, NULL); @@ -534,7 +534,7 @@ static inline int get_parameters(int fd, struct generic_floppy_struct *floppy) #define FD_SECTSIZE(floppy) floppy.dkbuf.sec_size #define FD_SET_SECTSIZE(floppy,v) { floppy.dkbuf.sec_size = v; } -static inline int set_parameters(int fd, struct generic_floppy_struct *floppy, +static inline int set_parameters(int fd, struct generic_floppy_struct *floppy, struct MT_STAT *buf) { if (ioctl(fd, FDKIOSCHAR, &(floppy->dkbuf)) != 0) { @@ -542,7 +542,7 @@ static inline int set_parameters(int fd, struct generic_floppy_struct *floppy, perror(""); return(1); } - + if (ioctl(fd, ( unsigned int) DKIOCSPART, &(floppy->dkmap)) != 0) { ioctl(fd, FDKEJECT, NULL); perror(""); @@ -617,15 +617,15 @@ static __inline__ void print_message(RawRequest_t *raw_cmd,const char *message) fprintf(stderr," "); for (i=0; i< raw_cmd->cmd_count; i++) - fprintf(stderr,"%2.2x ", + fprintf(stderr,"%2.2x ", (int)raw_cmd->cmd[i] ); fprintf(stderr,"\n"); for (i=0; i< raw_cmd->reply_count; i++) fprintf(stderr,"%2.2x ", (int)raw_cmd->reply[i] ); fprintf(stderr,"\n"); - code = (raw_cmd->reply[0] <<16) + - (raw_cmd->reply[1] << 8) + + code = (raw_cmd->reply[0] <<16) + + (raw_cmd->reply[1] << 8) + raw_cmd->reply[2]; for(i=0; i<22; i++){ if ((code & (1 << i)) && error_msg[i]) @@ -647,7 +647,7 @@ int send_one_cmd(int fd, RawRequest_t *raw_cmd, const char *message) if (raw_cmd->reply_count < 7) { fprintf(stderr,"Short reply from FDC\n"); return -1; - } + } return 0; } @@ -679,10 +679,10 @@ int send_one_cmd(int fd, RawRequest_t *raw_cmd, const char *message) int analyze_one_reply(RawRequest_t *raw_cmd, int *bytes, int do_print) { - + if(raw_cmd->reply_count == 7) { int end; - + if (raw_cmd->reply[3] != raw_cmd->cmd[2]) { /* end of cylinder */ end = raw_cmd->cmd[6] + 1; @@ -694,7 +694,7 @@ int analyze_one_reply(RawRequest_t *raw_cmd, int *bytes, int do_print) /* FIXME: over/under run */ *bytes = *bytes << (7 + raw_cmd->cmd[5]); } else - *bytes = 0; + *bytes = 0; switch(raw_cmd->reply[0] & 0xc0){ case 0x40: @@ -726,7 +726,7 @@ int analyze_one_reply(RawRequest_t *raw_cmd, int *bytes, int do_print) return -1; default: break; - } + } #ifdef FD_RAW_MORE if(raw_cmd->flags & FD_RAW_MORE) return 1; @@ -748,7 +748,7 @@ struct device devices[] = { /* * Stuffing back the floppy parameters into the driver allows for gems * like 21 sector or single sided floppies from Atari ST systems. - * + * * Alain Knaff, Université Joseph Fourier, France, November 12, 1993. */ @@ -784,12 +784,12 @@ static __inline__ void set_ssize(struct floppy_struct *floppy, int value) #define SET_SSIZE set_ssize -static __inline__ int set_parameters(int fd, struct floppy_struct *floppy, +static __inline__ int set_parameters(int fd, struct floppy_struct *floppy, struct MT_STAT *buf) { if ( ( MINOR(buf->st_rdev ) & 0x7f ) > 3 ) return 1; - + return ioctl(fd, FDSETPRM, floppy); } @@ -847,7 +847,7 @@ static int get_block_geom(int fd, struct device *dev) { sec_size = get_sector_size(fd); if(sec_size < 0) return -1; - + dev->ssize = 0; while (dev->ssize < 0x7F && (128 << dev->ssize) < sec_size) dev->ssize++; @@ -905,7 +905,7 @@ struct device devices[] = { REMOTE }; #endif /* __FreeBSD__ */ - + /*** /jes -- for ALR 486 DX4/100 ***/ #if defined(OS_netbsd) || defined(OS_netbsdelf) #define predefined_devices @@ -958,7 +958,7 @@ int init_geom(int fd, struct device *dev, struct device *orig_dev, } if((dev->use_2m & 0x7f) || (dev->ssize & 0x7f)) return 1; - + SET_INT(gdbuf.params.cyls,dev->ntracks); SET_INT(gdbuf.params.heads,dev->nheads); SET_INT(gdbuf.params.psectrk,dev->nsect); @@ -1076,58 +1076,58 @@ int init_geom(int fd, struct device *dev, struct device *orig_dev, /** * Block device which *isn't* a floppy device */ - if (S_ISBLK(statbuf->st_mode) && + if (S_ISBLK(statbuf->st_mode) && major(statbuf->st_rdev) != BLOCK_MAJOR) { get_block_geom(fd, dev); return compare_geom(dev, orig_dev); } #endif - - /* + + /* * succeed if we don't have a floppy * this is the case for dosemu floppy image files for instance */ - if (!((S_ISBLK(statbuf->st_mode) && + if (!((S_ISBLK(statbuf->st_mode) && major(statbuf->st_rdev) == BLOCK_MAJOR) #ifdef CHAR_MAJOR - || (S_ISCHR(statbuf->st_mode) && - major(statbuf->st_rdev) == CHAR_MAJOR) + || (S_ISCHR(statbuf->st_mode) && + major(statbuf->st_rdev) == CHAR_MAJOR) #endif )) return compare_geom(dev, orig_dev); - + /* * We first try to get the current floppy parameters from the kernel. * This allows us to * 1. get the rate * 2. skip the parameter setting if the parameters are already o.k. */ - + if (get_parameters( fd, & floppy ) ) - /* + /* * autodetection failure. * This mostly occurs because of an absent or unformatted disks. * - * It might also occur because of bizarre formats (for example + * It might also occur because of bizarre formats (for example * rate 1 on a 3 1/2 disk). - * If this is the case, the user should do an explicit + * If this is the case, the user should do an explicit * setfdprm before calling mtools * - * Another cause might be pre-existing wrong parameters. The + * Another cause might be pre-existing wrong parameters. The * user should do an setfdprm -c to repair this situation. * * ...fail immediately... ( Theoretically, we could try to save - * the situation by trying out all rates, but it would be slow + * the situation by trying out all rates, but it would be slow * and awkward) */ return 1; - /* + /* * if we have already have the correct parameters, keep them. * the number of tracks doesn't need to match exactly, it may be bigger. - * the number of heads and sectors must match exactly, to avoid + * the number of heads and sectors must match exactly, to avoid * miscalculation of the location of a block on the disk */ change = 0; @@ -1136,13 +1136,13 @@ int init_geom(int fd, struct device *dev, struct device *orig_dev, change = 1; } else dev->sectors = (uint16_t) SECTORS(floppy); - + if(compare(dev->heads, HEADS(floppy))){ HEADS(floppy) = dev->heads; change = 1; } else dev->heads = (uint16_t) HEADS(floppy); - + if(compare(dev->tracks, TRACKS(floppy))){ TRACKS(floppy) = dev->tracks; change = 1; @@ -1155,7 +1155,7 @@ int init_geom(int fd, struct device *dev, struct device *orig_dev, change = 1; } else dev->use_2m = USE_2M(floppy); - + if( ! (dev->ssize & 0x80) ) dev->ssize = 0; if(compare(dev->ssize, SSIZE(floppy) + 128)){ @@ -1175,18 +1175,18 @@ int init_geom(int fd, struct device *dev, struct device *orig_dev, #ifdef SECTORS_PER_DISK SECTORS_PER_DISK(floppy) = dev->sectors * dev->heads * dev->tracks; #endif - + #ifdef STRETCH /* ... and the stretch */ - if ( dev->tracks > 41 ) + if ( dev->tracks > 41 ) STRETCH(floppy) = 0; else STRETCH(floppy) = 1; #endif - + return set_parameters( fd, &floppy, statbuf); } -#endif /* INIT_GENERIC */ +#endif /* INIT_GENERIC */ #ifdef INIT_NOOP int init_geom(int fd, struct device *dev, struct device *orig_dev, diff --git a/devices.h b/devices.h index 5107d0b..3bd55bf 100644 --- a/devices.h +++ b/devices.h @@ -29,7 +29,7 @@ #endif /* MINOR not defined */ #else - + #include /* get MAJOR/MINOR from Linux kernel */ #ifndef major #define major(x) MAJOR(x) @@ -91,14 +91,14 @@ UNUSED(static __inline__ void RR_SETHEAD(struct floppy_raw_cmd *request, uint8_t request->cmd[3] = head; } -UNUSED(static __inline__ void RR_SETSECTOR(struct floppy_raw_cmd *request, +UNUSED(static __inline__ void RR_SETSECTOR(struct floppy_raw_cmd *request, uint8_t sector)) { request->cmd[4] = sector; request->cmd[6] = sector-1; } -UNUSED(static __inline__ void RR_SETSIZECODE(struct floppy_raw_cmd *request, +UNUSED(static __inline__ void RR_SETSIZECODE(struct floppy_raw_cmd *request, uint8_t sizecode)) { request->cmd[5] = sizecode; @@ -113,7 +113,7 @@ static inline void RR_SETEND(struct floppy_raw_cmd *request, int end) } #endif -UNUSED(static __inline__ void RR_SETDIRECTION(struct floppy_raw_cmd *request, +UNUSED(static __inline__ void RR_SETDIRECTION(struct floppy_raw_cmd *request, int direction)) { if(direction == MT_READ) { @@ -126,7 +126,7 @@ UNUSED(static __inline__ void RR_SETDIRECTION(struct floppy_raw_cmd *request, } -UNUSED(static __inline__ void RR_SETDATA(struct floppy_raw_cmd *request, +UNUSED(static __inline__ void RR_SETDATA(struct floppy_raw_cmd *request, caddr_t data)) { request->data = data; @@ -169,11 +169,11 @@ UNUSED(static __inline__ int GET_DRIVE(int fd)) perror("stat"); return -1; } - + if (!S_ISBLK(statbuf.st_mode) || MAJOR(statbuf.st_rdev) != FLOPPY_MAJOR) return -1; - + return (int) MINOR( statbuf.st_rdev ); } diff --git a/dirCache.c b/dirCache.c index 5e24fff..8e6479f 100644 --- a/dirCache.c +++ b/dirCache.c @@ -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 = towupper((wint_t)*name); + c = towupper((wint_t)*name); hash ^= (c * (c+2)) ^ (i * (i+2)); hash &= 0xffffffff; i++; @@ -68,7 +68,7 @@ static unsigned int addBit(unsigned int *bitmap, bit = 1u << (hash % BITS_PER_INT); entry = (hash / BITS_PER_INT) % DC_BITMAP_SIZE; - + if(checkOnly) return bitmap[entry] & bit; else { @@ -87,7 +87,7 @@ static int _addHash(dirCache_t *cache, unsigned int hash, int checkOnly) static void addNameToHash(dirCache_t *cache, wchar_t *name) -{ +{ _addHash(cache, calcHash(name), 0); } @@ -118,7 +118,7 @@ int growDirCache(dirCache_t *cache, unsigned int slot) if( cache->nr_entries <= slot) { unsigned int i; - + cache->entries = realloc(cache->entries, (slot+1) * 2 * sizeof(dirCacheEntry_t *)); @@ -191,7 +191,7 @@ static int freeDirCacheRange(dirCache_t *cache, beginSlot++; continue; } - + /* Due to the way this is called, we _always_ de-allocate * starting from beginning... */ #ifdef HAVE_ASSERT_H @@ -201,7 +201,7 @@ static int freeDirCacheRange(dirCache_t *cache, if(clearEnd > endSlot) clearEnd = endSlot; clearBegin = beginSlot; - + for(i = clearBegin; i entries[i] = 0; @@ -275,7 +275,7 @@ dirCacheEntry_t *addUsedEntry(dirCache_t *cache, entry = allocDirCacheEntry(cache, beginSlot, endSlot, DCET_USED); if(!entry) return 0; - + entry->beginSlot = beginSlot; entry->endSlot = endSlot; if(longName) @@ -306,7 +306,7 @@ static void mergeFreeSlots(dirCache_t *cache, unsigned int slot) cache->entries[i] = previous; previous->endSlot = next->endSlot; previous->endMarkPos = next->endMarkPos; - free(next); + free(next); } } @@ -354,7 +354,7 @@ dirCacheEntry_t *lookupInDircache(dirCache_t *cache, unsigned int pos) { if(growDirCache(cache, pos+1) < 0) return 0; - return cache->entries[pos]; + return cache->entries[pos]; } void freeDirCache(Stream_t *Stream) diff --git a/dirCache.h b/dirCache.h index 04f9f3e..161c9a5 100644 --- a/dirCache.h +++ b/dirCache.h @@ -45,9 +45,9 @@ dirCacheEntry_t *addUsedEntry(dirCache_t *Stream, wchar_t *longName, wchar_t *shortName, struct directory *dir); void freeDirCache(Stream_t *Stream); -dirCacheEntry_t *addFreeEntry(dirCache_t *Stream, +dirCacheEntry_t *addFreeEntry(dirCache_t *Stream, unsigned int begin, unsigned int end); -dirCacheEntry_t *addFreeEndEntry(dirCache_t *Stream, +dirCacheEntry_t *addFreeEndEntry(dirCache_t *Stream, unsigned int begin, unsigned int end, int isAtEnd); dirCacheEntry_t *addEndEntry(dirCache_t *Stream, unsigned int pos); diff --git a/directory.c b/directory.c index 2ed7405..7625699 100644 --- a/directory.c +++ b/directory.c @@ -32,8 +32,8 @@ struct directory *dir_read(direntry_t *entry, int *error) { ssize_t n; *error = 0; - if((n=force_read(entry->Dir, (char *) (&entry->dir), - (mt_off_t) entry->entry * MDIR_SIZE, + if((n=force_read(entry->Dir, (char *) (&entry->dir), + (mt_off_t) entry->entry * MDIR_SIZE, MDIR_SIZE)) != MDIR_SIZE) { if (n < 0) { *error = -1; @@ -56,7 +56,7 @@ int dir_grow(Stream_t *Dir, int size) ssize_t ret; unsigned int buflen; char *buffer; - + if (!getfreeMinClusters(Dir, 1)) return -1; @@ -66,7 +66,7 @@ int dir_grow(Stream_t *Dir, int size) perror("dir_grow: malloc"); return -1; } - + memset((char *) buffer, '\0', buflen); ret = force_write(Dir, buffer, (mt_off_t) size * MDIR_SIZE, buflen); free(buffer); @@ -78,8 +78,8 @@ int dir_grow(Stream_t *Dir, int size) void low_level_dir_write(direntry_t *entry) { - force_write(entry->Dir, - (char *) (&entry->dir), + force_write(entry->Dir, + (char *) (&entry->dir), (mt_off_t) entry->entry * MDIR_SIZE, MDIR_SIZE); } diff --git a/direntry.c b/direntry.c index 3d79dc9..1dbb240 100644 --- a/direntry.c +++ b/direntry.c @@ -49,7 +49,7 @@ static size_t getPathLen(direntry_t *entry) while(1) { if(entry->entry == -3) /* rootDir */ return length + 3; - + length += 1 + wcslen(entry->name); entry = getDirentry(entry->Dir); } @@ -171,5 +171,5 @@ int isSubdirOf(Stream_t *inside, Stream_t *outside) return 0; /* look further up */ inside = getDirentry(inside)->Dir; - } + } } diff --git a/fat.c b/fat.c index 6a8ef5d..5054158 100644 --- a/fat.c +++ b/fat.c @@ -41,7 +41,7 @@ typedef struct FatMap_t { static __inline__ ssize_t readSector(Fs_t *This, char *buf, unsigned int off, size_t size) { - return READS(This->Next, buf, sectorsToBytes((Stream_t *)This, off), + return READS(This->Next, buf, sectorsToBytes((Stream_t *)This, off), size << This->sectorShift); } @@ -49,7 +49,7 @@ static __inline__ ssize_t readSector(Fs_t *This, char *buf, unsigned int off, static __inline__ ssize_t forceReadSector(Fs_t *This, char *buf, unsigned int off, size_t size) { - return force_read(This->Next, buf, sectorsToBytes((Stream_t *)This, off), + return force_read(This->Next, buf, sectorsToBytes((Stream_t *)This, off), size << This->sectorShift); } @@ -57,7 +57,7 @@ static __inline__ ssize_t forceReadSector(Fs_t *This, char *buf, static __inline__ ssize_t forceWriteSector(Fs_t *This, char *buf, unsigned int off, size_t size) { - return force_write(This->Next, buf, sectorsToBytes((Stream_t*)This, off), + return force_write(This->Next, buf, sectorsToBytes((Stream_t*)This, off), size << This->sectorShift); } @@ -95,7 +95,7 @@ static __inline__ int locate(Fs_t *Stream, uint32_t offset, static __inline__ ssize_t fatReadSector(Fs_t *This, unsigned int sector, - unsigned int slot, + unsigned int slot, unsigned int bit, unsigned int dupe, fatBitMask bitmap) { @@ -105,7 +105,7 @@ static __inline__ ssize_t fatReadSector(Fs_t *This, dupe = (dupe + This->primaryFat) % This->num_fat; fat_start = This->fat_start + This->fat_len * dupe; - + if(bitmap == 0) { nr_sectors = SECT_PER_ENTRY - bit%SECT_PER_ENTRY; } else { @@ -124,7 +124,7 @@ static __inline__ ssize_t fatReadSector(Fs_t *This, /* if we got less than one sector's worth, insist to get at * least one sector */ ret = forceReadSector(This, - (char *) (This->FatMap[slot].data + + (char *) (This->FatMap[slot].data + (bit << This->sectorShift)), fat_start+sector, 1); if(ret < (int) This->sector_size) @@ -151,7 +151,7 @@ static ssize_t fatWriteSector(Fs_t *This, fat_start = This->fat_start + This->fat_len * dupe; return forceWriteSector(This, - (char *) + (char *) (This->FatMap[slot].data + bit * This->sector_size), fat_start+sector, 1); } @@ -170,7 +170,7 @@ static unsigned char *loadSector(Fs_t *This, fprintf(stderr,"This should not happen\n"); fprintf(stderr, "fat_len = %d\n", This->fat_len); fprintf(stderr, "SECT_PER_ENTRY=%d\n", (int)SECT_PER_ENTRY); - fprintf(stderr, "sector = %d slot = %d bit=%d\n", + fprintf(stderr, "sector = %d slot = %d bit=%d\n", sector, slot, bit); fprintf(stderr, "left = %d",(int) ((This->fat_len+SECT_PER_ENTRY-1) / SECT_PER_ENTRY)); @@ -179,7 +179,7 @@ static unsigned char *loadSector(Fs_t *This, #endif if(!This->FatMap[slot].data) { /* allocate the storage space */ - This->FatMap[slot].data = + This->FatMap[slot].data = malloc(This->sector_size * SECT_PER_ENTRY); if(!This->FatMap[slot].data) return 0; @@ -244,7 +244,7 @@ static unsigned char *getAddress(Fs_t *Stream, if(sector == Stream->lastFatSectorNr && Stream->lastFatAccessMode >= mode) ret = Stream->lastFatSectorData; - if(!ret) { + if(!ret) { ret = loadSector(Stream, sector, mode, 0); if(!ret) return 0; @@ -260,7 +260,7 @@ static unsigned char *getAddress(Fs_t *Stream, static int readByte(Fs_t *Stream, unsigned int start) { unsigned char *address; - + address = getAddress(Stream, start, FAT_ACCESS_READ); if(!address) return -1; @@ -280,7 +280,7 @@ static int readByte(Fs_t *Stream, unsigned int start) * | n+1.5 | n+0.0 | n+0.5 | n+2.0 | n+2.5 | n+1.0 | * | FAT entry k | FAT entry k+1 | */ - + /* * Get and decode a FAT (file allocation table) entry. Returns the cluster * number on success or 1 on failure. @@ -291,7 +291,7 @@ static unsigned int fat12_decode(Fs_t *Stream, unsigned int num) unsigned int start = num * 3 / 2; int byte0 = readByte(Stream, start); int byte1 = readByte(Stream, start+1); - + if (num < 2 || byte0 < 0 || byte1 < 0 || num > Stream->num_clus+1) { fprintf(stderr,"[1] Bad address %d\n", num); return 1; @@ -361,8 +361,8 @@ static void fat16_encode(Fs_t *Stream, unsigned int num, unsigned int code) * manpage is "suitably aligned for any built-in type */ static unsigned int fast_fat16_decode(Fs_t *Stream, unsigned int num) { - unsigned short *address = - (unsigned short *) getAddress(Stream, num << 1, + unsigned short *address = + (unsigned short *) getAddress(Stream, num << 1, FAT_ACCESS_READ); if(!address) return 1; @@ -370,9 +370,9 @@ static unsigned int fast_fat16_decode(Fs_t *Stream, unsigned int num) } static void fast_fat16_encode(Fs_t *Stream, unsigned int num, unsigned int code) -{ - unsigned short *address = - (unsigned short *) getAddress(Stream, num << 1, +{ + unsigned short *address = + (unsigned short *) getAddress(Stream, num << 1, FAT_ACCESS_WRITE); if(code > UINT16_MAX) { fprintf(stderr, "FAT16 code %x too big\n", code); @@ -399,7 +399,7 @@ static unsigned int fat32_decode(Fs_t *Stream, unsigned int num) } static void fat32_encode(Fs_t *Stream, unsigned int num, unsigned int code) -{ +{ unsigned char *address = getAddress(Stream, num << 2, FAT_ACCESS_WRITE); set_dword(address,(code&FAT32_ADDR) | (_DWORD(address)&FAT32_HIGH)); } @@ -408,8 +408,8 @@ static void fat32_encode(Fs_t *Stream, unsigned int num, unsigned int code) #pragma GCC diagnostic ignored "-Wcast-align" static unsigned int fast_fat32_decode(Fs_t *Stream, unsigned int num) { - unsigned int *address = - (unsigned int *) getAddress(Stream, num << 2, + unsigned int *address = + (unsigned int *) getAddress(Stream, num << 2, FAT_ACCESS_READ); if(!address) return 1; @@ -417,9 +417,9 @@ static unsigned int fast_fat32_decode(Fs_t *Stream, unsigned int num) } static void fast_fat32_encode(Fs_t *Stream, unsigned int num, unsigned int code) -{ - unsigned int *address = - (unsigned int *) getAddress(Stream, num << 2, +{ + unsigned int *address = + (unsigned int *) getAddress(Stream, num << 2, FAT_ACCESS_WRITE); *address = (*address & FAT32_HIGH) | (code & FAT32_ADDR); } @@ -453,7 +453,7 @@ void fat_write(Fs_t *This) j += SECT_PER_ENTRY; continue; } - for(bit=0; + for(bit=0; bit < SECT_PER_ENTRY && jfat_len; bit++,j++) { if(!(This->FatMap[slot].dirty & (ONE << bit))) @@ -546,7 +546,7 @@ int zero_fat(Fs_t *Stream, uint8_t media_descriptor) } } } - + free(buf); Stream->FatMap = GetFatMap(Stream); if (Stream->FatMap == NULL) { @@ -592,7 +592,7 @@ static void set_fat32(Fs_t *This) This->fat_bits = 32; This->end_fat = 0xfffffff; This->last_fat = 0xffffff6; - + if(t[0] == 0x78 && t[1] == 0x56 && t[2] == 0x34 && t[3] == 0x12) { This->fat_decode = fast_fat32_decode; This->fat_encode = fast_fat32_encode; @@ -613,7 +613,7 @@ void set_fat(Fs_t *This) { static int check_fat(Fs_t *This) { - /* + /* * This is only a sanity check. For disks with really big FATs, * there is no point in checking the whole FAT. */ @@ -631,7 +631,7 @@ static int check_fat(Fs_t *This) /* we do not warn about too much sectors in FAT, which may * happen when a partition has been shrunk using FIPS, or on * other occurrences */ - + tocheck = This->num_clus; if (tocheck + 1 >= This->last_fat) { fprintf(stderr, "Too many clusters in FAT\n"); @@ -684,10 +684,10 @@ static int check_media_type(Fs_t *This, union bootsector *boot) return 0; if((address[0] != boot->boot.descr && boot->boot.descr >= 0xf0 && - ((address[0] != 0xf9 && address[0] != 0xf7) + ((address[0] != 0xf9 && address[0] != 0xf7) || boot->boot.descr != 0xf0)) || address[0] < 0xf0) { fprintf(stderr, - "Bad media types %02x/%02x, probably non-MSDOS disk\n", + "Bad media types %02x/%02x, probably non-MSDOS disk\n", address[0], boot->boot.descr); return -1; @@ -719,7 +719,7 @@ static int fat_32_read(Fs_t *This, union bootsector *boot) InfoSector_t *infoSector; infoSector = (InfoSector_t *) safe_malloc(size); if(forceReadSector(This, (char *)infoSector, - This->infoSectorLoc, 1) == + This->infoSectorLoc, 1) == (signed int) This->sector_size && _DWORD(infoSector->signature1) == INFOSECT_SIGNATURE1 && _DWORD(infoSector->signature2) == INFOSECT_SIGNATURE2) { @@ -728,7 +728,7 @@ static int fat_32_read(Fs_t *This, union bootsector *boot) } free(infoSector); } - + return(check_media_type(This, boot) || check_fat(This)); } @@ -755,7 +755,7 @@ static int old_fat_read(Fs_t *This, union bootsector *boot, int nodups) } /* - * Read the first sector of the FAT table into memory and initialize + * Read the first sector of the FAT table into memory and initialize * structures. */ int fat_read(Fs_t *This, union bootsector *boot, int nodups) @@ -878,7 +878,7 @@ uint32_t fat32RootCluster(Stream_t *Dir) { Stream_t *Stream = GetFs(Dir); DeclareThis(Fs_t); - + if(This->fat_bits == 32) return This->rootCluster; else @@ -909,7 +909,7 @@ mt_off_t getfree(Stream_t *Dir) } This->freeSpace = total; } - return (mt_off_t) sectorsToBytes((Stream_t*)This, + return (mt_off_t) sectorsToBytes((Stream_t*)This, This->freeSpace * This->cluster_size); } @@ -941,10 +941,10 @@ int getfreeMinClusters(Stream_t *Dir, size_t size) /* we start at the same place where we'll start later to actually * allocate the sectors. That way, the same sectors of the FAT, which - * are already loaded during getfreeMin will be able to be reused + * are already loaded during getfreeMin will be able to be reused * during get_next_free_cluster */ last = This->last; - + if ( last < 2 || last >= This->num_clus + 2) last = 1; for (i=last+1; i< This->num_clus+2; i++){ @@ -955,10 +955,10 @@ int getfreeMinClusters(Stream_t *Dir, size_t size) if (!r) total++; if(total >= size) - return 1; + return 1; } for(i=2; i < last+1; i++){ - unsigned int r = fatDecode(This, i); + unsigned int r = fatDecode(This, i); if(r == 1) { goto exit_0; } @@ -1011,11 +1011,11 @@ int fs_free(Stream_t *Stream) if(This->FatMap) { int i, nr_entries; - nr_entries = (This->fat_len + SECT_PER_ENTRY - 1) / + nr_entries = (This->fat_len + SECT_PER_ENTRY - 1) / SECT_PER_ENTRY; for(i=0; i< nr_entries; i++) if(This->FatMap[i].data) - free(This->FatMap[i].data); + free(This->FatMap[i].data); free(This->FatMap); } if(This->cp) diff --git a/fat_free.c b/fat_free.c index 8fb176c..f7c1d5b 100644 --- a/fat_free.c +++ b/fat_free.c @@ -69,4 +69,3 @@ int fatFreeWithDirentry(direntry_t *entry) { return fatFreeWithDir(entry->Dir, &entry->dir); } - diff --git a/file.c b/file.c index f7a631c..bad25e5 100644 --- a/file.c +++ b/file.c @@ -158,7 +158,7 @@ static unsigned int _countBlocks(Fs_t *This, unsigned int block) unsigned int rel, oldabs, oldrel; blocks = 0; - + oldabs = oldrel = rel = 0; while (block <= This->last_fat && block != 1 && block) { @@ -300,7 +300,7 @@ static int normal_map(File_t *This, uint32_t where, uint32_t *len, int mode, } RelCluNr = where / clus_size; - + if (RelCluNr >= This->PreviousRelCluNr){ CurCluNr = This->PreviousRelCluNr; AbsCluNr = This->PreviousAbsCluNr; @@ -324,7 +324,7 @@ static int normal_map(File_t *This, uint32_t where, uint32_t *len, int mode, AbsCluNr, NewCluNr); exit(1); } - if(CurCluNr == RelCluNr + NrClu) + if(CurCluNr == RelCluNr + NrClu) break; if (NewCluNr > Fs->last_fat && mode == MT_WRITE){ /* if at end, and writing, extend it */ @@ -352,7 +352,7 @@ static int normal_map(File_t *This, uint32_t where, uint32_t *len, int mode, } maximize(*len, (1 + CurCluNr - RelCluNr) * clus_size - offset); - + end = where + *len; if(batchmode && mode == MT_WRITE && @@ -387,11 +387,11 @@ static int root_map(File_t *This, uint32_t where, uint32_t *len, maximize(*len, Fs->dir_len * Fs->sector_size - where); if (*len == 0) return 0; - + *res = sectorsToBytes((Stream_t*)Fs, Fs->dir_start) + where; return 1; } - + static ssize_t read_file(Stream_t *Stream, char *buf, mt_off_t iwhere, size_t ilen) @@ -401,9 +401,9 @@ static ssize_t read_file(Stream_t *Stream, char *buf, mt_off_t iwhere, int err; uint32_t where = truncMtOffTo32u(iwhere); uint32_t len = truncSizeTo32u(ilen); - + Stream_t *Disk = This->Fs->Next; - + err = This->map(This, where, &len, MT_READ, &pos); if(err <= 0) return err; @@ -481,7 +481,7 @@ static __inline__ time_t conv_stamp(struct directory *dir) { struct timeval tv; struct timezone tz; - + gettimeofday(&tv, &tz); tzone = tz.tz_minuteswest * 60L; } @@ -621,7 +621,7 @@ static int comp(void *Stream, void *Stream2) static void init_hash(void) { static int is_initialised=0; - + if(!is_initialised){ make_ht(func1, func2, comp, 20, &filehash); is_initialised = 1; diff --git a/file_name.c b/file_name.c index d058849..4456492 100644 --- a/file_name.c +++ b/file_name.c @@ -30,7 +30,7 @@ char *unix_normalize (doscp_t *cp, char *ans, dos_name_t *dn, size_t ans_size) wchar_t wbuffer[13]; char *a; int j; - + for (a=buffer,j=0; (j<8) && (dn->base[j] > ' '); ++j,++a) *a = dn->base[j]; if(dn->ext[0] > ' ') { @@ -115,7 +115,7 @@ void dos_name(doscp_t *toDos, const char *name, int verbose UNUSEDP, name = _basename(name); if ((s = strrchr(name, '\\'))) name = s + 1; - + memset(dn, ' ', 11); /* skip leading dots and spaces */ diff --git a/file_read.c b/file_read.c index 60e336f..5345ae2 100644 --- a/file_read.c +++ b/file_read.c @@ -35,7 +35,7 @@ int file_read(FILE *fp, Stream_t *Source, int textmode, int stripmode) fprintf(stderr,"Couldn't open source file\n"); return -1; } - + pos = 0; while(1){ ret = Source->Class->read(Source, buffer, pos, 16384); diff --git a/filter.c b/filter.c index a5818e5..d598a2f 100644 --- a/filter.c +++ b/filter.c @@ -58,7 +58,7 @@ static ssize_t read_filter(Stream_t *Stream, char *buf, exit(1); } This->rw = F_READ; - + ret = READS(This->Next, buf, (mt_off_t) This->dospos, len); if ( ret < 0 ) return ret; @@ -90,7 +90,7 @@ static ssize_t write_filter(Stream_t *Stream, char *buf, mt_off_t iwhere, ssize_t ret; char buffer[1025]; char newchar; - + off_t where = truncBytes32(iwhere); if(This->unixpos == -1) @@ -100,7 +100,7 @@ static ssize_t write_filter(Stream_t *Stream, char *buf, mt_off_t iwhere, fprintf(stderr,"Bad offset\n"); exit(1); } - + if (This->rw == F_READ){ fprintf(stderr,"Change of transfer direction!\n"); exit(1); diff --git a/floppyd.c b/floppyd.c index 28a67e3..9575a17 100644 --- a/floppyd.c +++ b/floppyd.c @@ -23,7 +23,7 @@ * * udbz@rz.uni-karlsruhe.de * - * Large parts of the network code shamelessly stolen from + * Large parts of the network code shamelessly stolen from * transproxy by John Saunders * * Rewritten in C by Alain Knaff. Apparently C++ is still not as @@ -66,7 +66,7 @@ Client sends his protocol-version. If the version between server and client differ: bail out. - After that,we send our .Xauthority-file (a maximum of MAX_XAUTHORITY_LENGTH + After that,we send our .Xauthority-file (a maximum of MAX_XAUTHORITY_LENGTH Bytes long) to the server. The server then checks, if it already has a .Xauthority file. If so @@ -98,7 +98,7 @@ read the expected bytes from the socket stream. Don't know why this is necessary. Maybe the socket stream is nonblocking or something IT SHOULD NOT BE! - + */ @@ -116,11 +116,11 @@ void serve_client(int sock, const char *const*device_name, unsigned int n_dev, typedef struct io_buffer { Byte out_buffer[BUFFERED_IO_SIZE]; Byte in_buffer[BUFFERED_IO_SIZE]; - + size_t in_valid; size_t in_start; size_t out_valid; - + int handle; } *io_buffer; @@ -153,15 +153,15 @@ static void free_io_buffer(io_buffer buffer) { static size_t buf_read (io_buffer buf, Byte* buffer, size_t nbytes) { 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; ret = nbytes; } else { - if (buf->in_valid) - memcpy(buffer, buf->in_buffer+buf->in_start, + if (buf->in_valid) + memcpy(buffer, buf->in_buffer+buf->in_start, buf->in_valid); nbytes -= buf->in_valid; buffer += buf->in_valid; @@ -175,7 +175,7 @@ static size_t buf_read (io_buffer buf, Byte* buffer, size_t nbytes) { } buf->in_valid = buf->in_start = 0; } else { - ssize_t rval = read(buf->handle, buf->in_buffer, + ssize_t rval = read(buf->handle, buf->in_buffer, BUFFERED_IO_SIZE); if (rval >= 0) { if (rval < (ssize_t) nbytes) { @@ -251,16 +251,16 @@ static Dword read_dword(io_buffer fp) if (buf_read(fp, val, 4) < 4) { return 0xffffffff; } - + return byte2dword(val); } static void write_dword(io_buffer fp, Dword parm) { Byte val[4]; - + dword2byte(parm, val); - + buf_write(fp, val,4); } @@ -320,7 +320,7 @@ static char send_packet(Packet packet, io_buffer fp) fprintf(stderr, "%d ", packet->data[i]); } fprintf(stderr, "\n"); -#endif +#endif } return (packet->data != NULL); @@ -351,14 +351,14 @@ static char recv_packet(Packet packet, io_buffer fp, Dword maxlength) #if DEBUG fprintf(stderr, "*** read: %li\n", packet->len); #endif - + #if DEBUG fprintf(stderr, "recv_packet(): "); for (i = 0; i < packet->len; i++) { fprintf(stderr, "%d ", packet->data[i]); } fprintf(stderr, "\n"); -#endif +#endif return 1; } @@ -386,11 +386,11 @@ static void put_qword(Packet packet, int my_index, Qword val) { static Dword get_dword(Packet packet, int my_index) { return byte2dword(packet->data+my_index); -} +} static Qword get_qword(Packet packet, int my_index) { return byte2qword(packet->data+my_index); -} +} static Dword get_length(Packet packet) { return packet->len; @@ -409,7 +409,7 @@ static const char *dispName; static char XAUTHORITY[]="XAUTHORITY"; -static char do_auth(io_buffer sock, unsigned int *version) +static char do_auth(io_buffer sock, unsigned int *version) { int fd; Display* displ; @@ -434,7 +434,7 @@ static char do_auth(io_buffer sock, unsigned int *version) } *version = get_dword(proto_version, 0); - if (*version > FLOPPYD_PROTOCOL_VERSION || + if (*version > FLOPPYD_PROTOCOL_VERSION || *version < FLOPPYD_PROTOCOL_VERSION_OLD) { /* fail if client requests a newer version than us */ put_dword(reply, 0, AUTH_WRONGVERSION); @@ -695,7 +695,7 @@ static int bind_to_port(in_addr_t bind_ip, uint16_t bind_port) */ { int on = 1; - if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, + if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) { perror("setsockopt"); exit(1); @@ -731,7 +731,7 @@ static int bind_to_port(in_addr_t bind_ip, uint16_t bind_port) } static int sockethandle_now = -1; - + /* * Catch alarm signals and exit. */ @@ -770,7 +770,7 @@ static void server_main_loop(int sock, const char *const*device_name, */ len = sizeof(addr); while ((new_sock = accept(sock, (struct sockaddr *)&addr, &len)) < 0){} - + /* * Create a new process to handle the connection. */ @@ -781,7 +781,7 @@ static void server_main_loop(int sock, const char *const*device_name, * Under load conditions just ignore new connections. */ break; - + case 0: /* * Start the proxy work in the new socket. @@ -810,7 +810,7 @@ static void usage(char *prog, const char *opt, int ret) { fprintf(stderr, "%s: %s\n", prog, opt); } - fprintf(stderr, "usage: %s [-s port [-r user] [-b ipaddr]] devicename [Names of local host]\n", + fprintf(stderr, "usage: %s [-s port [-r user] [-b ipaddr]] devicename [Names of local host]\n", prog); fprintf(stderr, " -d Run as a server (default port 5703 + DISPLAY)\n"); fprintf(stderr, " -s port Run as a server bound to the specified port.\n"); @@ -828,7 +828,7 @@ static char *makeDisplayName(int dispNr) return strdup(result); } -int main (int argc, char** argv) +int main (int argc, char** argv) { int sockfd = 0; int arg; @@ -840,7 +840,7 @@ int main (int argc, char** argv) char* username = strdup("nobody"); int sock; - const char *const* device_name = NULL; + const char *const* device_name = NULL; const char *floppy0 = "/dev/fd0"; unsigned int n_dev; @@ -895,7 +895,7 @@ int main (int argc, char** argv) dispName = getenv("DISPLAY"); if(dispName==NULL && bind_port != 0) dispName=makeDisplayName((unsigned short)(bind_port - 5703)); - if(dispName==NULL) + if(dispName==NULL) dispName=":0"; if(bind_port == 0) { @@ -908,9 +908,9 @@ int main (int argc, char** argv) if(!run_as_server) { struct sockaddr_in addr; unsigned int len = sizeof(addr); - + /* try to find out port that we are connected to */ - if(getsockname(0, (struct sockaddr*) &addr, &len) >= 0 && + if(getsockname(0, (struct sockaddr*) &addr, &len) >= 0 && len == sizeof(addr)) { bind_port = ntohs(addr.sin_port); } @@ -937,7 +937,7 @@ int main (int argc, char** argv) * Start by binding to the port, the child inherits this socket. */ sock = bind_to_port(bind_ip, bind_port); - + /* * Start a server process. When DEBUG is defined, just run * in the foreground. @@ -951,7 +951,7 @@ int main (int argc, char** argv) case -1: perror("fork()"); exit(1); - + case 0: /* * Ignore some signals. @@ -965,14 +965,14 @@ int main (int argc, char** argv) signal(SIGCONT, SIG_IGN); signal(SIGPIPE, alarm_signal); /*signal(SIGALRM, alarm_signal);*/ - + /* * Drop back to an untrusted user. */ setgid(run_gid); initgroups(username, run_gid); setuid(run_uid); - + /* * Start a new session and group. */ @@ -994,7 +994,7 @@ int main (int argc, char** argv) server_main_loop(sock, device_name, n_dev); } - + /* * Parent exits at this stage. */ @@ -1066,13 +1066,13 @@ void serve_client(int sockhandle, const char *const*device_name, unsigned int version; int needSendReply=0; int rval=0; - + /* * Set the keepalive socket option to on. */ { int on = 1; - if(setsockopt(sockhandle, SOL_SOCKET, + if(setsockopt(sockhandle, SOL_SOCKET, SO_KEEPALIVE, (char *)&on, sizeof(on)) < 0) { perror("setsockopt"); exit(1); @@ -1089,12 +1089,12 @@ void serve_client(int sockhandle, const char *const*device_name, #endif sock = new_io_buffer(sockhandle); - + /* * Allow 60 seconds for any activity. */ alarm(60); - + version = 0; if (!do_auth(sock, &version)) { free_io_buffer(sock); @@ -1122,10 +1122,10 @@ void serve_client(int sockhandle, const char *const*device_name, /* old protocol */ readOnly = 0; devFd = open(device_name[0], O_RDWR|O_LARGEFILE); - + if (devFd < 0) { readOnly = 1; - devFd = open(device_name[0], + devFd = open(device_name[0], O_RDONLY|O_LARGEFILE); } if(devFd < 0) { @@ -1235,11 +1235,11 @@ void serve_client(int sockhandle, const char *const*device_name, fprintf(stderr, "SEEK:\n"); #endif - lseek(devFd, + lseek(devFd, get_dword(parm, 0), (int) get_dword(parm, 4)); - send_reply(devFd, - sock, + send_reply(devFd, + sock, (Dword) lseek(devFd, 0, SEEK_CUR)); break; case OP_SEEK64: @@ -1254,11 +1254,11 @@ void serve_client(int sockhandle, const char *const*device_name, #if DEBUG fprintf(stderr, "SEEK64:\n"); #endif - mt_lseek(devFd, + mt_lseek(devFd, (mt_off_t) get_qword(parm,0), (int) get_dword(parm,8)); - send_reply64(devFd, - sock, + send_reply64(devFd, + sock, mt_lseek(devFd, 0, SEEK_CUR)); break; case OP_FLUSH: @@ -1295,7 +1295,7 @@ void serve_client(int sockhandle, const char *const*device_name, alarm(0); } - + #if DEBUG fprintf(stderr, "Closing down...\n"); @@ -1320,10 +1320,10 @@ void serve_client(int sockhandle, const char *const*device_name, #else #include -int main(int argc, char **argv) +int main(int argc, char **argv) { puts("Floppyd support not included!"); return -1; } - + #endif diff --git a/floppyd_installtest.c b/floppyd_installtest.c index c5d5349..2a128c8 100644 --- a/floppyd_installtest.c +++ b/floppyd_installtest.c @@ -65,7 +65,7 @@ static int write_dword(int handle, Dword parm) /* ######################################################################## */ -static uint32_t authenticate_to_floppyd(char fullauth, int sock, char *display, +static uint32_t authenticate_to_floppyd(char fullauth, int sock, char *display, uint32_t protoversion) { uint32_t filelen=0; @@ -105,15 +105,15 @@ static uint32_t authenticate_to_floppyd(char fullauth, int sock, char *display, return errcode; } - protoversion = FLOPPYD_PROTOCOL_VERSION_OLD; + protoversion = FLOPPYD_PROTOCOL_VERSION_OLD; if(bytesRead >= 12) { protoversion = read_dword(sock); cap = read_dword(sock); } - + fprintf(stderr, "Protocol Version=%d\n", protoversion); if(protoversion >= FLOPPYD_PROTOCOL_VERSION) { - fprintf(stderr, "Capabilities:%s%s\n", + fprintf(stderr, "Capabilities:%s%s\n", (cap & FLOPPYD_CAP_EXPLICIT_OPEN) ? " ExplicitOpen" : "", (cap & FLOPPYD_CAP_LARGE_SEEK) ? " LargeFiles" : ""); } @@ -149,10 +149,10 @@ static int get_host_and_port(const char* name, char** hostname, char **display, p2 = p; if (*p) p++; *p2 = 0; - + *port = atou16(p); if (*port == 0) { - *port = FLOPPYD_DEFAULT_PORT; + *port = FLOPPYD_DEFAULT_PORT; } *display = strdup(newname); @@ -179,24 +179,24 @@ static int get_host_and_port(const char* name, char** hostname, char **display, * */ static in_addr_t getipaddress(char *ipaddr) { - + struct hostent *host; in_addr_t ip; - + if (((ip = inet_addr(ipaddr)) == INADDR_NONE) && (strcmp(ipaddr, "255.255.255.255") != 0)) { - + if ((host = gethostbyname(ipaddr)) != NULL) { memcpy(&ip, host->h_addr, sizeof(ip)); } - + endhostent(); } - + #ifdef DEBUG fprintf(stderr, "IP lookup %s -> 0x%08lx\n", ipaddr, ip); #endif - + return (ip); } @@ -205,25 +205,25 @@ static in_addr_t getipaddress(char *ipaddr) * */ static int connect_to_server(in_addr_t ip, uint16_t port) { - + struct sockaddr_in addr; int sock; - + /* * Allocate a socket. */ if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { return (-1); } - + /* * Set the address to connect to. */ - + addr.sin_family = AF_INET; addr.sin_port = htons(port); addr.sin_addr.s_addr = ip; - + /* * Connect our socket to the above address. */ @@ -236,15 +236,15 @@ static int connect_to_server(in_addr_t ip, uint16_t port) */ { int on = 1; - setsockopt(STDIN_FILENO, SOL_SOCKET, SO_KEEPALIVE, + setsockopt(STDIN_FILENO, SOL_SOCKET, SO_KEEPALIVE, (char *)&on, sizeof(on)); } - + return (sock); } -int main (int argc, char** argv) +int main (int argc, char** argv) { char* hostname; char* display; @@ -270,7 +270,7 @@ int main (int argc, char** argv) } rval = get_host_and_port(name, &hostname, &display, &port); - + if (!rval) return -1; sock = connect_to_server(getipaddress(hostname), port); @@ -281,7 +281,7 @@ int main (int argc, char** argv) hostname, port); return -1; } - + protoversion = FLOPPYD_PROTOCOL_VERSION; while(1) { reply = authenticate_to_floppyd(fullauth, sock, display, @@ -297,12 +297,12 @@ int main (int argc, char** argv) } if (reply != 0) { - fprintf(stderr, + fprintf(stderr, "Connection to floppyd failed:\n" "%s\n", AuthErrors[reply]); return -1; } - + free(hostname); free(display); diff --git a/floppyd_io.c b/floppyd_io.c index f347147..f78b17d 100644 --- a/floppyd_io.c +++ b/floppyd_io.c @@ -91,7 +91,7 @@ static unsigned int authenticate_to_floppyd(RemoteFile_t *floppyd, if(newlen < 1 || newlen > UINT16_MAX) return AUTH_AUTHFAILED; filelen = (uint16_t) newlen; - + /* Version negotiation */ dword2byte(4,buf); dword2byte(floppyd->version,buf+4); @@ -122,12 +122,12 @@ static unsigned int authenticate_to_floppyd(RemoteFile_t *floppyd, } errcode = read_dword(sock); - + return errcode; } -static ssize_t floppyd_reader(int fd, char* buffer, uint32_t len) +static ssize_t floppyd_reader(int fd, char* buffer, uint32_t len) { Dword errcode; Dword gotlen; @@ -171,7 +171,7 @@ static ssize_t floppyd_reader(int fd, char* buffer, uint32_t len) return (ssize_t) gotlen; } -static ssize_t floppyd_writer(int fd, char* buffer, uint32_t len) +static ssize_t floppyd_writer(int fd, char* buffer, uint32_t len) { int errcode; int32_t gotlen; @@ -189,7 +189,7 @@ static ssize_t floppyd_writer(int fd, char* buffer, uint32_t len) if(ret == -1 || (size_t) ret < len) return AUTH_IO_ERROR; cork(fd, 0); - + if (read_dword(fd) != 8) { errno = EIO; return -1; @@ -208,22 +208,22 @@ static ssize_t floppyd_writer(int fd, char* buffer, uint32_t len) return gotlen; } -static int floppyd_lseek(int fd, int32_t offset, int whence) +static int floppyd_lseek(int fd, int32_t offset, int whence) { int errcode; int gotlen; Byte buf[32]; - + dword2byte(1, buf); buf[4] = OP_SEEK; - + dword2byte(8, buf+5); sdword2byte(offset, buf+9); sdword2byte(whence, buf+13); - + if(write(fd, buf, 17) < 17) return AUTH_IO_ERROR; - + if (read_dword(fd) != 8) { errno = EIO; return -1; @@ -233,26 +233,26 @@ static int floppyd_lseek(int fd, int32_t offset, int whence) errcode = read_sdword(fd); errno = errcode; - + return gotlen; } -static mt_off_t floppyd_lseek64(int fd, mt_off_t offset, int whence) +static mt_off_t floppyd_lseek64(int fd, mt_off_t offset, int whence) { int errcode; struct SQwordRet gotlen; Byte buf[32]; - + dword2byte(1, buf); buf[4] = OP_SEEK64; - + dword2byte(12, buf+5); qword2byte((uint32_t)offset, buf+9); sdword2byte(whence, buf+17); - + if(write(fd, buf, 21) < 21) return AUTH_IO_ERROR; - + if (read_dword(fd) != 12) { errno = EIO; return -1; @@ -262,16 +262,16 @@ static mt_off_t floppyd_lseek64(int fd, mt_off_t offset, int whence) errcode = read_sdword(fd); errno = errcode; - + return gotlen.v; } -static int floppyd_open(RemoteFile_t *This, int mode) +static int floppyd_open(RemoteFile_t *This, int mode) { int errcode; int gotlen; Byte buf[16]; - + if(! (This->capabilities & FLOPPYD_CAP_EXPLICIT_OPEN) ) { /* floppyd has no "explicit seek" capabilities */ return 0; @@ -287,7 +287,7 @@ static int floppyd_open(RemoteFile_t *This, int mode) if(write(This->fd, buf, 13) < 13) return AUTH_IO_ERROR; - + if (read_dword(This->fd) != 8) { errno = EIO; return -1; @@ -297,7 +297,7 @@ static int floppyd_open(RemoteFile_t *This, int mode) errcode = read_sdword(This->fd); errno = errcode; - + return gotlen; } @@ -346,7 +346,7 @@ static ssize_t floppyd_io(Stream_t *Stream, char *buf, mt_off_t where, static ssize_t floppyd_read(Stream_t *Stream, char *buf, mt_off_t where, size_t len) -{ +{ return floppyd_io(Stream, buf, where, len, floppyd_reader); } @@ -397,10 +397,10 @@ static int floppyd_free(Stream_t *Stream) errno = EIO; return -1; } - + gotlen = read_sdword(This->fd); errcode = read_sdword(This->fd); - + errno = errcode; close(This->fd); @@ -433,7 +433,7 @@ static int floppyd_data(Stream_t *Stream, time_t *date, mt_size_t *size, /* ######################################################################## */ static Class_t FloppydFileClass = { - floppyd_read, + floppyd_read, floppyd_write, floppyd_flush, floppyd_free, @@ -459,8 +459,8 @@ static int get_host_and_port_and_drive(const char* name, char** hostname, p2 = p; if (*p) p++; *p2 = 0; - - *port = FLOPPYD_DEFAULT_PORT; + + *port = FLOPPYD_DEFAULT_PORT; if(*p >= '0' && *p <= '9') *port = strtou16(p, &p, 0); if(*p == '/') @@ -498,18 +498,18 @@ static in_addr_t getipaddress(char *ipaddr) if (((ip = inet_addr(ipaddr)) == INADDR_NONE) && (strcmp(ipaddr, "255.255.255.255") != 0)) { - + if ((host = gethostbyname(ipaddr)) != NULL) { memcpy(&ip, host->h_addr, sizeof(ip)); } - + endhostent(); } - + #ifdef DEBUG fprintf(stderr, "IP lookup %s -> 0x%08lx\n", ipaddr, ip); #endif - + return (ip); } @@ -518,25 +518,25 @@ static in_addr_t getipaddress(char *ipaddr) * */ static int connect_to_server(in_addr_t ip, uint16_t port) { - + struct sockaddr_in addr; int sock; - + /* * Allocate a socket. */ if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { return (-1); } - + /* * Set the address to connect to. */ - + addr.sin_family = AF_INET; addr.sin_port = htons(port); addr.sin_addr.s_addr = ip; - + /* * Connect our socket to the above address. */ @@ -549,17 +549,17 @@ static int connect_to_server(in_addr_t ip, uint16_t port) */ { int on = 1; - setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, + setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&on, sizeof(on)); } - + return (sock); } -static int ConnectToFloppyd(RemoteFile_t *floppyd, const char* name, +static int ConnectToFloppyd(RemoteFile_t *floppyd, const char* name, char *errmsg); -Stream_t *FloppydOpen(struct device *dev, +Stream_t *FloppydOpen(struct device *dev, const char *name, int mode, char *errmsg, mt_size_t *maxSize) { @@ -567,7 +567,7 @@ Stream_t *FloppydOpen(struct device *dev, if (!dev || !(dev->misc_flags & FLOPPYD_FLAG)) return NULL; - + This = New(RemoteFile_t); if (!This){ printOom(); @@ -602,24 +602,24 @@ Stream_t *FloppydOpen(struct device *dev, return (Stream_t *) This; } -static int ConnectToFloppyd(RemoteFile_t *floppyd, const char* name, - char *errmsg) +static int ConnectToFloppyd(RemoteFile_t *floppyd, const char* name, + char *errmsg) { char* hostname; char* display; uint16_t port; - int rval = get_host_and_port_and_drive(name, &hostname, &display, + int rval = get_host_and_port_and_drive(name, &hostname, &display, &port, &floppyd->drive); int sock; unsigned int reply; - + if (!rval) return -1; floppyd->version = FLOPPYD_PROTOCOL_VERSION; floppyd->capabilities = 0; while(1) { sock = connect_to_server(getipaddress(hostname), port); - + if (sock == -1) { #ifdef HAVE_SNPRINTF snprintf(errmsg, 200, @@ -632,7 +632,7 @@ static int ConnectToFloppyd(RemoteFile_t *floppyd, const char* name, #endif return -1; } - + reply = authenticate_to_floppyd(floppyd, sock, display); if(floppyd->version == FLOPPYD_PROTOCOL_VERSION_OLD) break; @@ -645,7 +645,7 @@ static int ConnectToFloppyd(RemoteFile_t *floppyd, const char* name, } if (reply != 0) { - fprintf(stderr, + fprintf(stderr, "Permission denied, authentication failed!\n" "%s\n", AuthErrors[reply]); return -1; diff --git a/floppyd_io.h b/floppyd_io.h index f2d511e..70a7552 100644 --- a/floppyd_io.h +++ b/floppyd_io.h @@ -30,7 +30,7 @@ typedef uint64_t Qword; #define DWORD_ERR ((Dword) -1) /*extern int ConnectToFloppyd(const char* name, Class_t** ioclass);*/ -Stream_t *FloppydOpen(struct device *dev, +Stream_t *FloppydOpen(struct device *dev, const char *name, int mode, char *errmsg, mt_size_t *maxSize); @@ -39,7 +39,7 @@ Stream_t *FloppydOpen(struct device *dev, #define FLOPPYD_PROTOCOL_VERSION_OLD 10 #define FLOPPYD_PROTOCOL_VERSION 11 -#define FLOPPYD_CAP_EXPLICIT_OPEN 1 /* explicit open. Useful for +#define FLOPPYD_CAP_EXPLICIT_OPEN 1 /* explicit open. Useful for * clean signalling of readonly disks */ #define FLOPPYD_CAP_LARGE_SEEK 2 /* large seeks */ @@ -69,13 +69,13 @@ enum AuthErrorsEnum { UNUSED(static inline void cork(int sockhandle, int on)) { #ifdef TCP_CORK - if(setsockopt(sockhandle, IPPROTO_TCP, + if(setsockopt(sockhandle, IPPROTO_TCP, TCP_CORK, (char *)&on, sizeof(on)) < 0) { perror("setsockopt cork"); } #else on = 1 ^ on; - if(setsockopt(sockhandle, IPPROTO_TCP, + if(setsockopt(sockhandle, IPPROTO_TCP, TCP_NODELAY, (char *)&on, sizeof(on)) < 0) { perror("setsockopt nodelay"); } diff --git a/force_io.c b/force_io.c index 10f9ba6..63b348d 100644 --- a/force_io.c +++ b/force_io.c @@ -18,7 +18,7 @@ * * written by: * - * Alain L. Knaff + * Alain L. Knaff * alain@knaff.lu * */ @@ -33,7 +33,7 @@ static ssize_t force_io(Stream_t *Stream, { ssize_t ret; int done=0; - + while(len){ ret = io(Stream, buf, start, len); if ( ret <= 0 ){ diff --git a/fsP.h b/fsP.h index 15cb773..10162e1 100644 --- a/fsP.h +++ b/fsP.h @@ -31,7 +31,7 @@ typedef struct Fs_t { int refs; Stream_t *Next; Stream_t *Buffer; - + int serialized; unsigned long serial_number; unsigned int cluster_size; diff --git a/hash.c b/hash.c index c049797..4e865cd 100644 --- a/hash.c +++ b/hash.c @@ -67,7 +67,7 @@ static int alloc_ht(T_HashTable *H, size_t size) H->entries = NewArray(size, T_HashTableEl); if (H->entries == NULL) return -1; /* out of memory error */ - + for(ii=0; ii < size; ii++) H->entries[ii] = &unallocated; return 0; @@ -80,7 +80,7 @@ int make_ht(T_HashFunc f1, T_HashFunc f2, T_ComparFunc c, size_t size, if (*H == NULL){ return -1; /* out of memory error */ } - + (*H)->f1 = f1; (*H)->f2 = f2; (*H)->compar = c; @@ -134,7 +134,7 @@ static int rehash(T_HashTable *H) size_t size,i; T_HashTableEl *oldentries; /* resize the table */ - + size = H->size; oldentries = H->entries; if(alloc_ht(H,((H->inuse+1)*4+H->fill)/5)) diff --git a/init.c b/init.c index f1532a0..2fb9e1a 100644 --- a/init.c +++ b/init.c @@ -47,7 +47,7 @@ static int read_boot(Stream_t *Stream, union bootsector * boot, size_t size) if (force_read(Stream, boot->characters, 0, size) != (ssize_t) size) return -1; - boot_sector_size = WORD(secsiz); + boot_sector_size = WORD(secsiz); if(boot_sector_size < sizeof(boot->bytes)) { /* zero rest of in-memory boot sector */ memset(boot->bytes+boot_sector_size, 0, @@ -126,7 +126,7 @@ static void boot_to_geom(struct device *dev, int media, dev->ssize = 2; /* allow for init_geom to change it */ dev->use_2m = 0x80; /* disable 2m mode to begin */ - if(media == 0xf0 || media >= 0x100){ + if(media == 0xf0 || media >= 0x100){ dev->heads = WORD(nheads); dev->sectors = WORD(nsect); tot_sectors = DWORD(bigsect); @@ -152,12 +152,12 @@ static void boot_to_geom(struct device *dev, int media, if(tot_sectors % sect_per_track) /* round size up */ dev->tracks++; - + BootP = WORD(ext.old.BootP); Infp0 = WORD(ext.old.Infp0); InfpX = WORD(ext.old.InfpX); InfTm = WORD(ext.old.InfTm); - + if(WORD(fatlen)) { labelBlock = &boot->boot.ext.old.labelBlock; } else { @@ -168,9 +168,9 @@ static void boot_to_geom(struct device *dev, int media, has_BPB4 && strncmp( boot->boot.banner,"2M", 2 ) == 0 && BootP < 512 && Infp0 < 512 && InfpX < 512 && InfTm < 512 && - BootP >= InfTm + 2 && InfTm >= InfpX && InfpX >= Infp0 && + BootP >= InfTm + 2 && InfTm >= InfpX && InfpX >= Infp0 && Infp0 >= 76 ){ - for (sum=0, j=63; j < BootP; j++) + for (sum=0, j=63; j < BootP; j++) sum += boot->bytes[j];/* checksum */ dev->ssize = boot->bytes[InfTm]; if (!sum && dev->ssize <= 7){ @@ -247,7 +247,7 @@ static Stream_t *try_device(struct device *dev, if(Stream == NULL) { if(geomFailure && (mode & O_ACCMODE) == O_RDONLY) { /* Our first attempt was to open read-only, - but this resulted in failure setting the + but this resulted in failure setting the geometry */ openMode = modeFlags | O_RDWR; continue; @@ -328,7 +328,7 @@ uint32_t calc_clus_start(Fs_t *Fs) { } /* Calculates number of clusters, and fills it in into Fs->num_clus - * Returns 0 if calculation could be performed, and -1 if less sectors than + * Returns 0 if calculation could be performed, and -1 if less sectors than * clus_start */ int calc_num_clus(Fs_t *Fs, uint32_t tot_sectors) @@ -363,7 +363,7 @@ Stream_t *find_device(char drive, int mode, struct device *out_dev, { char errmsg[200]; struct device *dev; - + sprintf(errmsg, "Drive '%c:' not supported", drive); /* open the device */ for (dev=devices; dev->name; dev++) { @@ -443,7 +443,7 @@ uint32_t parseFsParams( Fs_t *This, */ tot_sectors = WORD(psect); if(!tot_sectors) - tot_sectors = DWORD(bigsect); + tot_sectors = DWORD(bigsect); This->cluster_size = boot->boot.clsiz; This->fat_start = WORD(nrsvsect); @@ -469,7 +469,7 @@ uint32_t parseFsParams( Fs_t *This, /* Too few sectors */ return 0; set_fat(This); - + return tot_sectors; } @@ -518,7 +518,7 @@ Stream_t *fs_init(char drive, int mode, int *isRop) /* Error raised by parseFsParams */ return NULL; } - + if (tot_sectors >= (maxSize >> This->sectorShift)) { fprintf(stderr, "Big disks not supported on this architecture\n"); exit(1); diff --git a/lba.c b/lba.c index 777b617..aa514c5 100644 --- a/lba.c +++ b/lba.c @@ -46,7 +46,7 @@ int compute_lba_geom_from_tot_sectors(struct device *dev) dev->tracks = 40; dev->heads = 1; } else if(dev->tot_sectors <= 1080) { - /* double density 48tpi double sided or + /* double density 48tpi double sided or 96 tpi single sided */ if(dev->heads == 1) @@ -56,7 +56,7 @@ int compute_lba_geom_from_tot_sectors(struct device *dev) dev->heads = 2; } } else { - /* double density 96tpi double sided, + /* double density 96tpi double sided, * high density, extra density */ dev->tracks = 80; dev->heads = 2; @@ -65,11 +65,11 @@ int compute_lba_geom_from_tot_sectors(struct device *dev) (uint16_t) dev->tot_sectors / dev->heads / dev->tracks; } - + /* Heads or sectors not known => fill them in both... */ if(!dev->sectors || !dev->heads) { dev->sectors = 63; - + if (dev->tot_sectors < 16*dev->sectors*1024) dev->heads = 16; else if (dev->tot_sectors < 32*dev->sectors*1024) diff --git a/llong.c b/llong.c index 782224d..0ae8912 100644 --- a/llong.c +++ b/llong.c @@ -127,7 +127,7 @@ int mt_lseek(int fd, mt_off_t where, int whence) if(llseek(fd, where, whence) >= 0) return 0; else - return -1; + return -1; #else if (lseek(fd, (off_t) where, whence) >= 0) return 0; diff --git a/lockdev.c b/lockdev.c index e8d4e83..20423c7 100644 --- a/lockdev.c +++ b/lockdev.c @@ -29,7 +29,7 @@ #if (defined(HAVE_FLOCK) && defined (LOCK_EX) && (defined(LOCK_NB) || defined(ALRM))) - + # ifdef ALRM # define USE_FLOCK_W # else @@ -45,7 +45,7 @@ # else # define USE_LOCKF # endif - + #else /* LOCKF */ #if (defined(F_SETLK) && defined(F_WRLCK)) @@ -88,7 +88,7 @@ int lock_dev(int fd, int mode, struct device *dev) #ifdef USE_FLOCK ret = flock(fd, (mode ? LOCK_EX : LOCK_SH)|LOCK_NB); #endif - + #ifdef USE_FLOCK_W ret = flock(fd, (mode ? LOCK_EX : LOCK_SH)); #endif @@ -103,7 +103,7 @@ int lock_dev(int fd, int mode, struct device *dev) else ret = 0; #endif - + #if (defined(USE_SETLK) || defined(USE_SETLK_W)) { struct flock flk; @@ -119,7 +119,7 @@ int lock_dev(int fd, int mode, struct device *dev) # endif } #endif - + #if defined(USE_FLOCK_W) || defined(USE_LOCKF_W) || defined (USE_SETLK_W) /* Cancel the alarm */ sigaction(SIGALRM, &old_alrm_action, NULL); @@ -133,7 +133,7 @@ int lock_dev(int fd, int mode, struct device *dev) return 1; } #endif - + if( #ifdef EWOULDBLOCK (errno != EWOULDBLOCK) diff --git a/mainloop.c b/mainloop.c index 4d222ec..4a0f004 100644 --- a/mainloop.c +++ b/mainloop.c @@ -85,7 +85,7 @@ static const char *fix_mcwd(char *ans) return ans; } -int unix_dir_loop(Stream_t *Stream, MainParam_t *mp); +int unix_dir_loop(Stream_t *Stream, MainParam_t *mp); int unix_loop(Stream_t *Stream UNUSEDP, MainParam_t *mp, char *arg, int follow_dir_link); @@ -142,7 +142,7 @@ int unix_loop(Stream_t *Stream UNUSEDP, MainParam_t *mp, fprintf(stderr, "skipping directory symlink %s\n", arg); - return 0; + return 0; } #endif if(! (mp->lookupflags & ACCEPT_DIR)) @@ -168,7 +168,7 @@ int isSpecial(const char *name) return 1; if(!strcmp(name,"..")) return 1; - return 0; + return 0; } #ifdef HAVE_WCHAR_H @@ -180,7 +180,7 @@ int isSpecialW(const wchar_t *name) return 1; if(!wcscmp(name,L"..")) return 1; - return 0; + return 0; } #endif @@ -247,7 +247,7 @@ static int handle_leaf(direntry_t *direntry, MainParam_t *mp, } static int _dos_loop(Stream_t *Dir, MainParam_t *mp, const char *filename) -{ +{ Stream_t *MyFile=0; direntry_t entry; int ret; @@ -338,8 +338,8 @@ static int recurs_dos_loop(MainParam_t *mp, const char *filename0, doing_mcwd = !!filename1; ptr = strchr(filename0, '/'); - if(!ptr) { - length = strlen(filename0); + if(!ptr) { + length = strlen(filename0); ptr = filename1; filename1 = 0; } else { @@ -354,7 +354,7 @@ static int recurs_dos_loop(MainParam_t *mp, const char *filename0, mp->targetName = 0; return ret; } - + if(!strcmp(filename0, ".") || !filename0[0]) { return handle_leaf(getDirentry(mp->File), mp, lookupState); @@ -366,7 +366,7 @@ static int recurs_dos_loop(MainParam_t *mp, const char *filename0, } lookupflags = mp->lookupflags; - + if(lookupState) { lookupState->filename = filename0; if(lookupState->nbContainers + lookupState->nbDirs > 0){ @@ -431,7 +431,7 @@ static int common_dos_loop(MainParam_t *mp, const char *pathname, int ret; mp->loop = _dos_loop; - + drive='\0'; cwd = ""; if(*pathname && pathname[1] == ':') { @@ -507,7 +507,7 @@ static int dos_target_lookup(MainParam_t *mp, const char *arg) default: /* too much */ fprintf(stderr, "Ambiguous %s\n", arg); - return ERROR_ONE; + return ERROR_ONE; } } @@ -565,7 +565,7 @@ int main_loop(MainParam_t *mp, char **argv, int argc) { int i; int ret, Bret; - + Bret = 0; if(argc != 1 && mp->targetName) { @@ -590,7 +590,7 @@ int main_loop(MainParam_t *mp, char **argv, int argc) ret = unix_loop(0, mp, argv[i], 1); else ret = dos_loop(mp, argv[i]); - + if (! (ret & (GOT_ONE | ERROR_ONE)) ) { /* one argument was unmatched */ fprintf(stderr, "%s: File \"%s\" not found\n", diff --git a/mainloop.h b/mainloop.h index f872e4b..c611233 100644 --- a/mainloop.h +++ b/mainloop.h @@ -24,13 +24,13 @@ 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 + 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, + int (*loop)(Stream_t *Dir, struct MainParam_t *mp, const char *filename); int (*dirCallback)(direntry_t *, struct MainParam_t *); int (*callback)(direntry_t *, struct MainParam_t *); @@ -44,9 +44,9 @@ typedef struct MainParam_t { int fast_quit; /* for commands manipulating multiple files, quit * as soon as even _one_ file has a problem */ - bounded_string shortname; /* where to put the short name of the + bounded_string shortname; /* where to put the short name of the * matched file */ - bounded_string longname; /* where to put the long name of the + bounded_string longname; /* where to put the long name of the * matched file */ /* out parameters */ Stream_t *File; diff --git a/match.c b/match.c index 8ba3b50..3fcc505 100644 --- a/match.c +++ b/match.c @@ -47,7 +47,7 @@ static int is_in_range(wchar_t ch, const wchar_t **p, int *reverse) { /* Malformed pattern, range not closed */ return 0; if(*(++(*p)) == '-') { - last = *(++(*p)); + last = *(++(*p)); if(last==']') { /* Last "-" in range designates itself */ if(ch == first || ch == '-') diff --git a/mattrib.c b/mattrib.c index 5e939d0..0fa3e10 100644 --- a/mattrib.c +++ b/mattrib.c @@ -109,7 +109,7 @@ static int concise_view_attrib(direntry_t *entry, MainParam_t *mp) if(IS_ARCHIVE(entry)) putchar('A'); if(IS_DIR(entry)) - putchar('D'); + putchar('D'); if(IS_SYSTEM(entry)) putchar('S'); if(IS_HIDDEN(entry)) @@ -134,9 +134,9 @@ static int recursive_attrib(direntry_t *entry, MainParam_t *mp) static void usage(int ret) NORETURN; static void usage(int ret) { - fprintf(stderr, "Mtools version %s, dated %s\n", + fprintf(stderr, "Mtools version %s, dated %s\n", mversion, mdate); - fprintf(stderr, + fprintf(stderr, "Usage: %s [-p] [-a|+a] [-h|+h] [-r|+r] [-s|+s] msdosfile [msdosfiles...]\n", progname); exit(ret); diff --git a/mbadblocks.c b/mbadblocks.c index 5e9d50c..56e9004 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 = atoui(optarg); + startSector = atoui(optarg); break; case 'E': - endSector = atoui(optarg); + endSector = atoui(optarg); break; case 'w': writeMode = 1; @@ -190,7 +190,7 @@ void mbadblocks(int argc, char **argv, int type UNUSEDP) } for(i=0; i < Fs->clus_start; i++ ){ ssize_t r; - r = READS(Fs->Next, in_buf, + r = READS(Fs->Next, in_buf, sectorsToBytes((Stream_t*)Fs, i), Fs->sector_size); if( r < 0 ){ perror("early error"); @@ -209,7 +209,7 @@ void mbadblocks(int argc, char **argv, int type UNUSEDP) if(startSector < 2) startSector = 2; - if(endSector > Fs->num_clus + 2 || endSector <= 0) + if(endSector > Fs->num_clus + 2 || endSector <= 0) endSector = Fs->num_clus + 2; if(filename) { @@ -249,7 +249,7 @@ void mbadblocks(int argc, char **argv, int type UNUSEDP) if(got_signal) break; progress(i, Fs->num_clus); - ret |= scan(Fs, dev, i, badClus, + ret |= scan(Fs, dev, i, badClus, pat_buf + in_len * (i % N_PATTERN), 1); } @@ -264,7 +264,7 @@ void mbadblocks(int argc, char **argv, int type UNUSEDP) if(got_signal) break; progress(i, Fs->num_clus); - ret |= scan(Fs, dev, i, badClus, + ret |= scan(Fs, dev, i, badClus, pat_buf + in_len * (i % N_PATTERN), 0); } diff --git a/mcat.c b/mcat.c index e2934cd..65c3496 100644 --- a/mcat.c +++ b/mcat.c @@ -27,9 +27,9 @@ #include "open_image.h" static void usage(void) NORETURN; -static void usage(void) +static void usage(void) { - fprintf(stderr, "Mtools version %s, dated %s\n", + fprintf(stderr, "Mtools version %s, dated %s\n", mversion, mdate); fprintf(stderr, "Usage: mcat [-V] [-w] device\n"); fprintf(stderr, " -w write on device else read\n"); @@ -84,15 +84,15 @@ void mcat(int argc, char **argv, int type UNUSEDP) usage(); - if (!argv[optindex][0] || argv[optindex][1] != ':' + if (!argv[optindex][0] || argv[optindex][1] != ':' || argv[optindex][2]) { usage(); } drive = ch_toupper(argv[optindex][0]); - /* check out a drive whose letter and parameters match */ - sprintf(errmsg, "Drive '%c:' not supported", drive); + /* check out a drive whose letter and parameters match */ + sprintf(errmsg, "Drive '%c:' not supported", drive); Stream = NULL; for (dev=devices; dev->name; dev++) { FREE(&Stream); @@ -112,7 +112,7 @@ void mcat(int argc, char **argv, int type UNUSEDP) break; } - /* print error msg if needed */ + /* print error msg if needed */ if ( dev->drive == 0 ){ FREE(&Stream); fprintf(stderr,"%s\n",errmsg); @@ -127,7 +127,7 @@ void mcat(int argc, char **argv, int type UNUSEDP) size *= 512; while ((len = fread(buf, 1, bufLen(BUF_SIZE, size, address), - stdin)) > 0) { + stdin)) > 0) { ssize_t r = WRITES(Stream, buf, address, len); fprintf(stderr, "Wrote to %d\n", (int) address); if(r < 0) diff --git a/mcd.c b/mcd.c index a11909b..b1f167d 100644 --- a/mcd.c +++ b/mcd.c @@ -32,7 +32,7 @@ static int mcd_callback(direntry_t *entry, MainParam_t *mp UNUSEDP) fprintf(stderr,"mcd: Can't open mcwd .file for writing\n"); return ERROR_ONE; } - + fprintPwd(fp, entry,0); fprintf(fp, "\n"); fclose(fp); @@ -46,7 +46,7 @@ void mcd(int argc, char **argv, int type UNUSEDP) struct MainParam_t mp; if (argc > 2) { - fprintf(stderr, "Mtools version %s, dated %s\n", + fprintf(stderr, "Mtools version %s, dated %s\n", mversion, mdate); fprintf(stderr, "Usage: %s: [-V] msdosdirectory\n", argv[0]); exit(1); @@ -58,6 +58,6 @@ void mcd(int argc, char **argv, int type UNUSEDP) if (argc == 1) { printf("%s\n", mp.mcwd); exit(0); - } else + } else exit(main_loop(&mp, argv + 1, 1)); } diff --git a/mclasserase.c b/mclasserase.c index 565c588..08e33a7 100644 --- a/mclasserase.c +++ b/mclasserase.c @@ -72,7 +72,7 @@ static void usage(int ret) * * @param drive the drive to erase * @param debug 1: stop after each erase cycle, 0: normal mode - * + * * @returns n.a. * */ @@ -86,11 +86,11 @@ static void do_mclasserase(char drive,int debug) char name[EXPAND_BUF]; Stream_t *Stream; struct label_blk_t *labelBlock; - + FILE * fDevice; /* Stores device's file descriptor */ - + char cCardType[12]; - + char drivel[3]; /* Stores the drive letter */ @@ -110,12 +110,12 @@ static void do_mclasserase(char drive,int debug) odat[0]=0xff; odat[1]=0x00; odat[2]=0xff; - + if (debug == 1) printf("cycles: %i, odats: %i,%i,%i\n",CYCLES,odat[0],odat[1],odat[2]); - - + + /* Reading parameters from card. Exit with -1 if failed. */ if(! (Stream = find_device(drive, O_RDONLY, &dev, &boot, @@ -135,7 +135,7 @@ static void do_mclasserase(char drive,int debug) /* we use only FAT12/16 ...*/ labelBlock = &boot.boot.ext.old.labelBlock; - + /* store card type */ sprintf(cCardType, "%11.11s", labelBlock->label); @@ -144,20 +144,20 @@ static void do_mclasserase(char drive,int debug) printf("Using Device: %s\n",name); printf("Card-Type detected: %s\n",cCardType); } - + /* Forming cat command to overwrite the medias content. */ sprintf( drivel, "%c:", ch_tolower(drive) ); #if 0 media_sectors = dev.tracks * dev.sectors; - sector_size = WORD(secsiz) * dev.heads; - + sector_size = WORD(secsiz) * dev.heads; + printf(mcat); printf("\n%d\n", media_sectors); printf("%d\n", sector_size); #endif - + /* * Overwrite device */ @@ -169,7 +169,7 @@ static void do_mclasserase(char drive,int debug) } fDevice = fopen(name,"ab+"); - + if (fDevice == 0) { perror("Error opening device"); @@ -186,13 +186,13 @@ static void do_mclasserase(char drive,int debug) } /* iTotalErase = 0; */ - + /* * overwrite the whole device */ while ((feof(fDevice)==0) && (ferror(fDevice)==0)) { - + fputc(odat[i],fDevice); icount++; @@ -200,41 +200,41 @@ static void do_mclasserase(char drive,int debug) { /* flush device every 32KB of data...*/ fflush( fDevice ); - + iTotalErase += icount; if (debug == 1) { - printf("."); + printf("."); fflush( stdout ); } icount=0; } } - + if (debug==1) { printf("\nPress to continue\n"); printf("Press and to abort\n"); - + if(scanf("%c",dummy) < 1) printf("Input error\n"); fflush( stdin ); - + if (strcmp(dummy,"x") == 0) { printf("exiting.\n"); exit(0); } } - + fclose(fDevice); } - + /* * Format device using shell script - */ + */ if (debug == 0) { /* redirect STDERR and STDOUT to the black hole... */ @@ -243,22 +243,22 @@ static void do_mclasserase(char drive,int debug) if (dup2(open("/dev/null", O_WRONLY), STDOUT_FILENO) != STDOUT_FILENO) printf("Error with dup2() stdout\n"); } - + if (debug == 1) printf("Calling amuFormat.sh with args: %s,%s\n",cCardType,drivel); - + execlp("amuFormat.sh","",cCardType,drivel,NULL); /* we never come back...(we shouldn't come back ...) */ exit(-1); - + } /* * Total Erase of Data on a Disk. After using mclasserase there won't * be ANY bits of old files on the disk.
- * + * * @author stefan feuz
* thomas locher
* stefan.feuz@ruag.com @@ -270,7 +270,7 @@ static void do_mclasserase(char drive,int debug) * @param type generated automatically by operating systems * * @param -d stop after each erase cycle, for testing purposes - * + * * @returns int 0 if all is well done
* int -1 if there is something wrong * @@ -309,16 +309,16 @@ void mclasserase(int argc, char **argv, int type UNUSEDP) { switch (c) { - + case 'd': - + printf("=============\n"); printf("Debug Mode...\n"); printf("=============\n"); debug = 1; break; case 'p': - printf("option -p not implemented yet\n"); + printf("option -p not implemented yet\n"); break; case 'h': usage(0); @@ -344,9 +344,9 @@ void mclasserase(int argc, char **argv, int type UNUSEDP) } #ifdef DEBUG printf("mclasserase: found drive %c\n", drive); -#endif +#endif /* remove all data on drive, you never come back if drive does * not exist */ - + do_mclasserase(drive,debug); } diff --git a/mcopy.c b/mcopy.c index 8145118..d230f2b 100644 --- a/mcopy.c +++ b/mcopy.c @@ -40,7 +40,7 @@ static void set_mtime(const char *target, time_t mtime) { if (target && strcmp(target, "-") && mtime != 0L) { #ifdef HAVE_UTIMES - struct timeval tv[2]; + struct timeval tv[2]; tv[0].tv_sec = mtime; tv[0].tv_usec = 0; tv[1].tv_sec = mtime; @@ -130,7 +130,7 @@ static int _unix_write(MainParam_t *mp, int needfilter, const char *unixFile) if(!S_ISREG(stbuf.st_mode)) { fprintf(stderr,"\"%s\" is not a regular file\n", unixFile); - + return ERROR_ONE; } sFd = get_fd(File); @@ -147,7 +147,7 @@ static int _unix_write(MainParam_t *mp, int needfilter, const char *unixFile) unixFile)) { return ERROR_ONE; } - + } } @@ -156,7 +156,7 @@ static int _unix_write(MainParam_t *mp, int needfilter, const char *unixFile) mpPrintFilename(stderr,mp); fprintf(stderr,"\n"); } - + if(got_signal) { return ERROR_ONE; } @@ -221,7 +221,7 @@ static int unix_copydir(direntry_t *entry, MainParam_t *mp) if (!arg->recursive && mp->basenameHasWildcard) return 0; - File->Class->get_data(File, &mtime, 0, 0, 0); + File->Class->get_data(File, &mtime, 0, 0, 0); if (!arg->preserveTime) mtime = 0L; if(!arg->type && arg->verbose) { @@ -248,11 +248,11 @@ static int unix_copydir(direntry_t *entry, MainParam_t *mp) ret = mp->loop(File, &newArg.mp, "*"); set_mtime(unixFile, mtime); free(unixFile); - return ret | GOT_ONE; + return ret | GOT_ONE; } else { perror("mkdir"); - fprintf(stderr, - "Failure to make directory %s\n", + fprintf(stderr, + "Failure to make directory %s\n", unixFile); free(unixFile); return ERROR_ONE; @@ -322,7 +322,7 @@ static int writeit(struct dos_name_t *dosname, /* will it fit? */ if (!getfreeMinBytes(arg->mp.targetDir, filesize)) return -1; - + /* preserve mod time? */ if (arg->preserveTime) now = date; @@ -460,9 +460,9 @@ static int dos_copydir(direntry_t *entry, MainParam_t *mp) /* maybe the directory already exist. Use it */ newArg.mp.targetDir = subDir(mp->targetDir, targetName); if(!newArg.mp.targetDir) - newArg.mp.targetDir = createDir(mp->targetDir, + newArg.mp.targetDir = createDir(mp->targetDir, targetName, - &arg->ch, arg->attr, + &arg->ch, arg->attr, now); } else newArg.mp.targetDir = mp->targetDir; @@ -495,7 +495,7 @@ static void usage(int ret) fprintf(stderr, "Usage: %s [-spatnmQVBT] [-D clash_option] sourcefile targetfile\n", progname); fprintf(stderr, - " %s [-spatnmQVBT] [-D clash_option] sourcefile [sourcefiles...] targetdirectory\n", + " %s [-spatnmQVBT] [-D clash_option] sourcefile [sourcefiles...] targetdirectory\n", progname); exit(ret); } @@ -505,7 +505,7 @@ void mcopy(int argc, char **argv, int mtype) { Arg_t arg; int c, fastquit; - + /* get command line options */ @@ -597,7 +597,7 @@ void mcopy(int argc, char **argv, int mtype) arg.mp.unixTarget = strdup(""); arg.mp.callback = dos_to_unix; arg.mp.dirCallback = unix_copydir; - arg.mp.unixcallback = unix_to_unix; + arg.mp.unixcallback = unix_to_unix; } else { const char *target; if (argc - optind == 1) { diff --git a/mdel.c b/mdel.c index e650d71..4f0de7b 100644 --- a/mdel.c +++ b/mdel.c @@ -80,7 +80,7 @@ static int del_entry(direntry_t *entry, MainParam_t *mp) progname, tmp)) return ERROR_ONE; } - if (fatFreeWithDirentry(entry)) + if (fatFreeWithDirentry(entry)) return ERROR_ONE; wipeEntry(entry); @@ -95,14 +95,14 @@ static int del_file(direntry_t *entry, MainParam_t *mp) Arg_t *arg = (Arg_t *) mp->arg; MainParam_t sonmp; int ret; - int r; + int r; sonmp = *mp; sonmp.arg = mp->arg; r = 0; if (IS_DIR(entry)){ - /* a directory */ + /* a directory */ SubDir = OpenFileByDirentry(entry); initializeDirentry(&subEntry, SubDir); ret = 0; @@ -143,9 +143,9 @@ static int del_file(direntry_t *entry, MainParam_t *mp) static void usage(int ret) NORETURN; static void usage(int ret) { - fprintf(stderr, + fprintf(stderr, "Mtools version %s, dated %s\n", mversion, mdate); - fprintf(stderr, + fprintf(stderr, "Usage: %s [-v] msdosfile [msdosfiles...]\n", progname); exit(ret); } @@ -205,6 +205,6 @@ void mdel(int argc, char **argv, int deltype) if(l > 1 && argv[i][b+l-1] == '/') argv[i][b+l-1] = '\0'; } - + exit(main_loop(&mp, argv + optind, argc - optind)); } diff --git a/mdir.c b/mdir.c index 68821f9..0edfca4 100644 --- a/mdir.c +++ b/mdir.c @@ -48,14 +48,14 @@ static Stream_t *currentDir; static int filesInDir; /* files in current dir */ static int filesOnDrive; /* files on drive */ - + static int dirsOnDrive; /* number of listed directories on this drive */ static int debug = 0; /* debug mode */ static mt_size_t bytesInDir; static mt_size_t bytesOnDrive; -static Stream_t *RootDir; +static Stream_t *RootDir; static char mdir_shortname[4*12+1]; @@ -105,7 +105,7 @@ static __inline__ void print_time(struct directory *dir) { char am_pm; int hour = DOS_HOUR(dir); - + if(!mtools_twenty_four_hour_clock) { am_pm = (hour >= 12) ? 'p' : 'a'; if (hour > 12) @@ -135,7 +135,7 @@ static const char *dotted_num(mt_size_t num, size_t width, char **buf) if (*buf == NULL) return ""; - + /* Create the number in maximum width; make sure that the string * length is not exceeded (in %6ld, the result can be longer than 6!) */ @@ -154,7 +154,7 @@ static const char *dotted_num(mt_size_t num, size_t width, char **buf) srcp[0] = ' '; else break; - + len = strlen(*buf); srcp = (*buf)+len; dstp = (*buf)+len+1; @@ -172,7 +172,7 @@ static const char *dotted_num(mt_size_t num, size_t width, char **buf) if (dstp + 3 < (*buf) + len) /* use spaces instead of dots: they please both * Americans and Europeans */ - dstp[3] = ' '; + dstp[3] = ' '; srcp += 3; dstp += 4; } @@ -192,7 +192,7 @@ static __inline__ int print_volume_label(Stream_t *Dir, char drive) RootDir = OpenRoot(Stream); if(concise) return 0; - + /* find the volume label */ initializeDirentry(&entry, RootDir); @@ -212,7 +212,7 @@ static __inline__ int print_volume_label(Stream_t *Dir, char drive) drive, shortname); if(This->serialized) printf("\n Volume Serial Number is %04lX-%04lX", - (This->serial_number >> 16) & 0xffff, + (This->serial_number >> 16) & 0xffff, This->serial_number & 0xffff); return 0; } @@ -222,7 +222,7 @@ static void printSummary(int files, mt_size_t bytes) { if(!filesInDir) printf("No files\n"); - else { + else { char *s1 = NULL; printf(" %3d file", files); if(files == 1) @@ -280,10 +280,10 @@ static int enterDrive(Stream_t *Dir, char drive) int r; if(currentDrive == drive) return 0; /* still the same */ - + leaveDrive(0); currentDrive = drive; - + r = print_volume_label(Dir, drive); if (r) return r; @@ -307,7 +307,7 @@ static void leaveDirectory(int haveError) free(dynDirPath); if(wide) putchar('\n'); - + if(!concise) printSummary(filesInDir, bytesInDir); } @@ -373,21 +373,21 @@ static int list_file(direntry_t *entry, MainParam_t *mp UNUSEDP) return ERROR_ONE; if (wide) { if(filesInDir % 5) - putchar(' '); + putchar(' '); else putchar('\n'); } - + if(IS_DIR(entry)){ size = 0; } else size = FILE_SIZE(&entry->dir); - + Case = entry->dir.Case; - if(!(Case & (BASECASE | EXTCASE)) && + if(!(Case & (BASECASE | EXTCASE)) && mtools_ignore_short_case) Case |= BASECASE | EXTCASE; - + cp = GET_DOSCONVERT(entry->Dir); dos_to_wchar(cp, entry->dir.ext, ext, 3); if(Case & EXTCASE){ @@ -412,13 +412,13 @@ static int list_file(direntry_t *entry, MainParam_t *mp UNUSEDP) (int) (15 - 2 - strlen(mdir_shortname)), ""); else printf("%-15s", mdir_shortname); - } else if(!concise) { + } 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); - if (name[0] == ' ') + if (name[0] == ' ') printf(" "); else if(mtools_dotted_dir) printf("%-12s ", mdir_shortname); @@ -436,7 +436,7 @@ static int list_file(direntry_t *entry, MainParam_t *mp UNUSEDP) if(debug) printf(" %s %d ", tmpBasename, START(&entry->dir)); - + if(*mdir_longname) printf(" %s", mdir_longname); printf("\n"); @@ -601,7 +601,7 @@ void mdir(int argc, char **argv, int type UNUSEDP) if (testmode) { mp.lookupflags = ACCEPT_DIR | NO_DOTS; mp.dirCallback = test_directory; - } else + } else #endif if(recursive) { mp.lookupflags = ACCEPT_DIR | DO_OPEN_DIRS | NO_DOTS; diff --git a/mdoctorfat.c b/mdoctorfat.c index c8d290b..8ff3893 100644 --- a/mdoctorfat.c +++ b/mdoctorfat.c @@ -45,16 +45,16 @@ static int dos_doctorfat(direntry_t *entry, MainParam_t *mp) { Fs_t *Fs = getFs(mp->File); Arg_t *arg=(Arg_t *) mp->arg; - + if(!arg->markbad && entry->entry != -3) { /* if not root directory, change it */ set_word(entry->dir.start, arg->fat & 0xffff); set_word(entry->dir.startHi, arg->fat >> 16); if(arg->setsize) set_dword(entry->dir.size, arg->size); - dir_write(entry); + dir_write(entry); } - arg->Fs = Fs; + arg->Fs = Fs; return GOT_ONE; } @@ -84,7 +84,7 @@ void mdoctorfat(int argc, char **argv, int mtype UNUSEDP) char *number, *eptr; int i; unsigned int offset; - + /* get command line options */ init_clash_handling(& arg.ch); @@ -129,10 +129,10 @@ void mdoctorfat(int argc, char **argv, int mtype UNUSEDP) /* only 1 file to copy... */ init_mp(&arg.mp); arg.mp.arg = (void *) &arg; - + arg.mp.callback = dos_doctorfat; arg.mp.unixcallback = unix_doctorfat; - + arg.mp.lookupflags = ACCEPT_PLAIN | ACCEPT_DIR | DO_OPEN; arg.mp.openflags = O_RDWR; arg.fat = strtoui(argv[optind+1], 0, 0) + offset; diff --git a/mdu.c b/mdu.c index b6a7523..b17f46d 100644 --- a/mdu.c +++ b/mdu.c @@ -69,7 +69,7 @@ static int dir_mdu(direntry_t *entry, MainParam_t *mp) Arg_t *parentArg = (Arg_t *) (mp->arg); Arg_t arg; int ret; - + arg = *parentArg; arg.mp.arg = (void *) &arg; arg.parent = parentArg; diff --git a/mformat.c b/mformat.c index 932134b..4cd7600 100644 --- a/mformat.c +++ b/mformat.c @@ -264,7 +264,7 @@ static int calc_fat_len(Fs_t *Fs, uint32_t tot_sectors) if(tot_sectors < clus_start) return -2; rem_sect = tot_sectors - clus_start; - + /* Cheat a little bit to address the _really_ common case of odd number of remaining sectors while both nfat and cluster size are even... */ @@ -297,7 +297,7 @@ static int calc_fat_len(Fs_t *Fs, uint32_t tot_sectors) Fs->num_fat * fat_nybbles; if(fat_nybbles == 3) { - /* We need to do this test here, or multiplying rem_sect with + /* We need to do this test here, or multiplying rem_sect with * fat_nybbles might overflow */ if(rem_sect > 256 * FAT12) return 1; @@ -319,7 +319,7 @@ static int calc_fat_len(Fs_t *Fs, uint32_t tot_sectors) numerator -= denominator; corr++; } - + #ifdef DEBUG fprintf(stderr, "Numerator=%lu denominator=%lu\n", numerator, denominator); @@ -330,7 +330,7 @@ static int calc_fat_len(Fs_t *Fs, uint32_t tot_sectors) } /* Is there enough space in the FAT for the descriptors for all clusters. - * This only works if we assume that it is already clear that Fs->num_clus is + * This only works if we assume that it is already clear that Fs->num_clus is * less than FAT32, or else it might overflow */ static inline bool clusters_fit_into_fat(Fs_t *Fs) { return ((Fs->num_clus+2) * (Fs->fat_bits/4) - 1) / (Fs->sector_size*2) < @@ -360,7 +360,7 @@ static void check_fs_params_and_set_fat(Fs_t *Fs, uint32_t tot_sectors) assert(tot_sectors >= Fs->clus_start + Fs->num_clus * Fs->cluster_size); assert(tot_sectors <= - Fs->clus_start + Fs->num_clus * Fs->cluster_size + + Fs->clus_start + Fs->num_clus * Fs->cluster_size + Fs->cluster_size - 1); /* Fat must be big enough for all clusters */ @@ -382,7 +382,7 @@ static void fat32_specific_init(Fs_t *Fs) { else Fs->backupBoot=6; } - + if(Fs->fat_start < 3) { fprintf(stderr, "For FAT 32, reserved sectors need to be at least 3\n"); @@ -406,11 +406,11 @@ static void fat32_specific_init(Fs_t *Fs) { * may_change_fat_len try_cluster_size may change (compute) FAT length * may_change_root_size try_cluster_size may increase root directory size * to make everything fit - * may_pad if there are (slightly) too many clusters, + * may_pad if there are (slightly) too many clusters, * try_cluster_size may artificially inflate number of * boot sectors, fat length or root_size to take up * space in order to reduce number clusters below limit - * + * * Return values * -2 Too few sectors to contain even the header (reserved sectors, minimal * FAT and root directory) @@ -421,9 +421,9 @@ static void fat32_specific_init(Fs_t *Fs) { * size. Caller should either increase cluster size or FAT size, and * try again * 2 Fat length is set, and there are too many clusters to fit into - * that Fat length. Caller should either increase cluster size, or + * that Fat length. Caller should either increase cluster size, or * decrease FAT size, and try again - * + * */ static int try_cluster_size(Fs_t *Fs, uint32_t tot_sectors, @@ -459,7 +459,7 @@ static int try_cluster_size(Fs_t *Fs, Fs->fat_bits, Fs->cluster_size, may_pad ? " may_pad" : ""); } - + if(may_change_fat_len) { int fit=calc_fat_len(Fs, tot_sectors); if(fit != 0) @@ -489,7 +489,7 @@ static int try_cluster_size(Fs_t *Fs, if(Fs->num_clus < maxClus) break; - if(!may_pad) + if(!may_pad) return 1; /* "Pad" fat by artifically adding sectors to boot sectors, @@ -550,7 +550,7 @@ static int try_cluster_size(Fs_t *Fs, Fs->dir_len += dir_grow; /* If padding once failed, no point in keeping on retrying */ - may_pad=false; + may_pad=false; } #ifdef HAVE_ASSERT_H /* number of clusters must be within allowable range for fat @@ -611,7 +611,7 @@ int calc_fs_parameters(struct device *dev, bool fat32, *descr = 0xf0; Fs->fat_bits = abs(dev->fat_bits); - if(Fs->fat_bits == 0) + if(Fs->fat_bits == 0) /* If fat_bits not specified by device, start with a 12-bit * FAT, unless 32 bit specified on command line */ Fs->fat_bits = fat32 ? 32 : 12; @@ -664,13 +664,13 @@ int calc_fs_parameters(struct device *dev, bool fat32, /* FAT32 cluster sizes for disks with 512 block size according to Microsoft specification fatgen103.doc: - + ... - 8 GB cluster_size = 8 8 GB - 16 GB cluster_size = 16 16 GB - 32 GB cluster_size = 32 32 GB - 2 TB cluster_size = 64 - + Below calculation is generalized and does not depend on 512 block size. */ @@ -686,7 +686,7 @@ int calc_fs_parameters(struct device *dev, bool fat32, may_change_fat_len, may_change_root_size, may_pad); - + if(getenv("MTOOLS_DEBUG_FAT")) { fprintf(stderr, " fit=%d\n", fit); } @@ -790,7 +790,7 @@ int calc_fs_parameters(struct device *dev, bool fat32, void initFsForFormat(Fs_t *Fs) { memset(Fs, 0, sizeof(*Fs)); - + Fs->Class = &FsClass; Fs->refs = 1; @@ -943,7 +943,7 @@ void mformat(int argc, char **argv, int dummy UNUSEDP) uint16_t fsVersion; uint8_t mediaDesc=0; bool haveMediaDesc=false; - + mt_size_t maxSize; int Atari = 0; /* should we add an Atari-style serial number ? */ @@ -1320,7 +1320,7 @@ void mformat(int argc, char **argv, int dummy UNUSEDP) if(bootSector) { int fd; ssize_t ret; - + fd = open(bootSector, O_RDONLY | O_BINARY | O_LARGEFILE); if(fd < 0) { perror("open boot sector"); diff --git a/minfo.c b/minfo.c index 9181bce..56d0b9c 100644 --- a/minfo.c +++ b/minfo.c @@ -29,9 +29,9 @@ static void usage(int ret) NORETURN; static void usage(int ret) { - fprintf(stderr, + fprintf(stderr, "Mtools version %s, dated %s\n", mversion, mdate); - fprintf(stderr, + fprintf(stderr, "Usage: %s [-v] drive\n", progname); exit(ret); } @@ -45,7 +45,7 @@ static void displayInfosector(Stream_t *Stream, union bootsector *boot) return; infosec = (InfoSector_t *) safe_malloc(WORD(secsiz)); - force_read(Stream, (char *) infosec, + force_read(Stream, (char *) infosec, (mt_off_t) WORD(secsiz) * WORD(ext.fat32.infoSector), WORD(secsiz)); printf("\nInfosector:\n"); @@ -73,7 +73,7 @@ static void displayBPB(Stream_t *Stream, union bootsector *boot) { printf("cluster size: %d sectors\n", boot->boot.clsiz); printf("reserved (boot) sectors: %d\n", WORD(nrsvsect)); printf("fats: %d\n", boot->boot.nfat); - printf("max available root directory slots: %d\n", + printf("max available root directory slots: %d\n", WORD(dirents)); printf("small size: %d sectors\n", WORD(psect)); printf("media descriptor byte: 0x%x\n", boot->boot.descr); @@ -91,20 +91,20 @@ static void displayBPB(Stream_t *Stream, union bootsector *boot) { } if(has_BPB4) { - printf("physical drive id: 0x%x\n", + printf("physical drive id: 0x%x\n", labelBlock->physdrive); - printf("reserved=0x%x\n", + printf("reserved=0x%x\n", labelBlock->reserved); - printf("dos4=0x%x\n", + printf("dos4=0x%x\n", labelBlock->dos4); - printf("serial number: %08X\n", + printf("serial number: %08X\n", _DWORD(labelBlock->serial)); - printf("disk label=\"%11.11s\"\n", + printf("disk label=\"%11.11s\"\n", labelBlock->label); - printf("disk type=\"%8.8s\"\n", + printf("disk type=\"%8.8s\"\n", labelBlock->fat_type); } - + if(!WORD(fatlen)){ printf("Big fatlen=%u\n", DWORD(ext.fat32.bigFat)); @@ -148,7 +148,7 @@ static void print_mformat_commandline(const char *imgFile, struct device used_dev; uint8_t tryMedia; int bad; - + sect_per_track = dev->sectors * dev->heads; if(sect_per_track == 0) return; @@ -234,7 +234,7 @@ static void print_mformat_commandline(const char *imgFile, #endif if((media & 0xff) != (tryMedia & 0xff)) printf("-m %d ", (media & 0xff)); - + if(actual.fat_bits == 32) { if(actual.backupBoot != tryFs.backupBoot) printf("-K %d ", actual.backupBoot); @@ -261,7 +261,7 @@ void minfo(int argc, char **argv, int type UNUSEDP) int have_drive = 0; int ex=0; char *imgFile=NULL; - + if(helpFlag(argc, argv)) usage(0); while ((c = getopt(argc, argv, "i:vh")) != EOF) { @@ -295,7 +295,7 @@ void minfo(int argc, char **argv, int type UNUSEDP) } have_drive = 1; - if(! (Stream = find_device(drive, O_RDONLY, &dev, &boot, + if(! (Stream = find_device(drive, O_RDONLY, &dev, &boot, name, &media, 0, NULL))) { fprintf(stderr, "Could not open drive %c:\n", drive); ex=1; @@ -304,7 +304,7 @@ void minfo(int argc, char **argv, int type UNUSEDP) haveBPB = media >= 0x100; media = media & 0xff; - + printf("device information:\n"); printf("===================\n"); printf("filename=\"%s\"\n", name); @@ -315,7 +315,7 @@ void minfo(int argc, char **argv, int type UNUSEDP) print_mformat_commandline(imgFile, drive, &dev, &boot, media, haveBPB); - + if(haveBPB || verbose) displayBPB(Stream, &boot); @@ -326,7 +326,7 @@ void minfo(int argc, char **argv, int type UNUSEDP) printf("\n"); size = WORD_S(secsiz); - + buf = (unsigned char *) malloc(size); if(!buf) { fprintf(stderr, "Out of memory error\n"); diff --git a/misc.c b/misc.c index 546e82e..46427a2 100644 --- a/misc.c +++ b/misc.c @@ -36,29 +36,29 @@ char *get_homedir(void) uid_t uid; char *homedir; char *username; - - homedir = getenv ("HOME"); - /* - * first we call getlogin. - * There might be several accounts sharing one uid + + homedir = getenv ("HOME"); + /* + * first we call getlogin. + * There might be several accounts sharing one uid */ if ( homedir ) return homedir; - + pw = 0; - + username = getenv("LOGNAME"); if ( !username ) username = getlogin(); if ( username ) pw = getpwnam( username); - + if ( pw == 0 ){ /* if we can't getlogin, look up the pwent by uid */ uid = geteuid(); pw = getpwuid(uid); } - + /* we might still get no entry */ if ( pw ) return pw->pw_dir; @@ -100,7 +100,7 @@ FILE *open_mcwd(const char *mode) struct MT_STAT sbuf; char file[MAXPATHLEN+1]; time_t now; - + get_mcwd_file_name(file); if (*mode == 'r'){ if (MT_STAT(file, &sbuf) < 0) @@ -117,10 +117,10 @@ FILE *open_mcwd(const char *mode) return NULL; } } - + return fopen(file, mode); } - + void *safe_malloc(size_t size) @@ -141,10 +141,10 @@ void print_sector(const char *message, unsigned char *data, int size) int row; printf("%s:\n", message); - + for(row = 0; row * 16 < size; row++){ printf("%03x ", row * 16); - for(col = 0; col < 16; col++) + for(col = 0; col < 16; col++) printf("%02x ", data [row*16+col]); for(col = 0; col < 16; col++) { if(isprint(data [row*16+col])) @@ -193,7 +193,7 @@ time_t getTimeNow(time_t *now) } } } - + if(!haveTime) { time(&sharedNow); haveTime = 1; diff --git a/missFuncs.c b/missFuncs.c index 271fe0b..c774bd7 100644 --- a/missFuncs.c +++ b/missFuncs.c @@ -123,7 +123,7 @@ char * strchr (const char* s, int c) { if (!s) return NULL; while (*s && *s != c) s++; - if (*s) + if (*s) return (char*) s; else return NULL; @@ -133,7 +133,7 @@ char * strchr (const char* s, int c) #ifndef HAVE_STRRCHR -char * strrchr (const char* s1, int c) +char * strrchr (const char* s1, int c) { char* s = (char*) s1; char* start = (char*) s; @@ -175,7 +175,7 @@ char *strpbrk(const char *string, const char *brkset) static int getdigit(char a, int max) { int dig; - + if(a < '0') return -1; if(a <= '9') { @@ -412,7 +412,7 @@ static exitCallback_t *callback = 0; int atexit(void (*function) (void)) { exitCallback_t *newCallback; - + newCallback = New(exitCallback_t); if(!newCallback) { printOom(); diff --git a/mk_direntry.c b/mk_direntry.c index 2ea4793..da1c105 100644 --- a/mk_direntry.c +++ b/mk_direntry.c @@ -36,7 +36,7 @@ /** * Converts input to shortname * @param un unix name (in Unix charset) - * + * * @return 1 if name had to be mangled */ static __inline__ int convert_to_shortname(doscp_t *cp, ClashHandling_t *ch, @@ -70,7 +70,7 @@ static __inline__ int ask_rename(doscp_t *cp, ClashHandling_t *ch, { int mangled; - /* TODO: Would be nice to suggest "autorenamed" version of name, press + /* TODO: Would be nice to suggest "autorenamed" version of name, press * to get it. */ #if 0 @@ -92,7 +92,7 @@ static __inline__ int ask_rename(doscp_t *cp, ClashHandling_t *ch, if (isprimary) strcpy(longname, tname); else - mangled = convert_to_shortname(cp, + mangled = convert_to_shortname(cp, ch, tname, shortname); } while (mangled & 1); return 1; @@ -107,7 +107,7 @@ static __inline__ int ask_rename(doscp_t *cp, ClashHandling_t *ch, static __inline__ clash_action ask_namematch(doscp_t *cp, dos_name_t *dosname, char *longname, - int isprimary, + int isprimary, ClashHandling_t *ch, int no_overwrite, int reason) @@ -178,7 +178,7 @@ static __inline__ clash_action ask_namematch(doscp_t *cp, fflush(opentty(1)); if (mtools_raw_tty) { int rep; - rep = fgetc(opentty(1)); + rep = fgetc(opentty(1)); fputs("\n", stderr); if(rep == EOF) ans[0] = 'q'; @@ -336,7 +336,7 @@ static int is_reserved(char *ans, int islong) ((islong && !ans[4]) || (!islong && !strncmp(ans+4," ",4)))) return 1; - + return 0; } @@ -388,18 +388,18 @@ static __inline__ clash_action get_slots(Stream_t *Dir, ch->use_longname)) { case -1: return NAMEMATCH_ERROR; - + case 0: return NAMEMATCH_SKIP; /* Single-file error error or skip request */ - + case 5: return NAMEMATCH_GREW; /* Grew directory, try again */ - + case 6: return NAMEMATCH_SUCCESS; /* Success */ - } + } match_pos = -2; if (ssp->longmatch > -1) { /* Primary Long Name Match */ @@ -407,7 +407,7 @@ static __inline__ clash_action get_slots(Stream_t *Dir, fprintf(stderr, "Got longmatch=%d for name %s.\n", longmatch, longname); -#endif +#endif match_pos = ssp->longmatch; isprimary = 1; } else if ((ch->use_longname & 1) && (ssp->shortmatch != -1)) { @@ -443,7 +443,7 @@ static __inline__ clash_action get_slots(Stream_t *Dir, } ret = process_namematch(cp, dosname, longname, isprimary, ch, no_overwrite, reason); - + if (ret == NAMEMATCH_OVERWRITE && match_pos > -1){ if((entry.dir.attr & 0x5) && (ask_confirmation("file is read only, overwrite anyway (y/n) ? "))) @@ -451,7 +451,7 @@ static __inline__ clash_action get_slots(Stream_t *Dir, /* Free up the file to be overwritten */ if(fatFreeWithDirentry(&entry)) return NAMEMATCH_ERROR; - + #if 0 if(isprimary && match_pos - ssp->match_free + 1 >= ssp->size_needed){ @@ -591,7 +591,7 @@ static int _mwrite_one(Stream_t *Dir, case NAMEMATCH_ERROR: return -1; /* Non-file-specific error, * quit */ - + case NAMEMATCH_SKIP: return -1; /* Skip file (user request or * error) */ @@ -617,7 +617,7 @@ static int _mwrite_one(Stream_t *Dir, return -1; } expanded = 1; - + if (dir_grow(Dir, scan.max_entry)) return -1; continue; diff --git a/mkmanifest.c b/mkmanifest.c index ccbf86d..d950669 100644 --- a/mkmanifest.c +++ b/mkmanifest.c @@ -59,7 +59,7 @@ int main(int argc, char **argv) static char *dos_name2(const char *name) { - static const char *dev[9] = {"con", "aux", "com1", "com2", "lpt1", + static const char *dev[9] = {"con", "aux", "com1", "com2", "lpt1", "prn", "lpt2", "lpt3", "nul"}; char *s; char *ext,*temp; @@ -87,7 +87,7 @@ static char *dos_name2(const char *name) else { /* if name is a device */ for (i=0; i<9; i++) { - if (!strcasecmp(temp, dev[i])) + if (!strcasecmp(temp, dev[i])) *temp = 'x'; } /* name too long? */ @@ -101,7 +101,7 @@ static char *dos_name2(const char *name) *s = 'x'; while (ext && (s = strpbrk(ext, "^+=/[]:',?*\\<>|\". "))) - *s = 'x'; + *s = 'x'; strncpy(ans, temp, 12); ans[12] = '\0'; } diff --git a/mlabel.c b/mlabel.c index c908cb6..380e781 100644 --- a/mlabel.c +++ b/mlabel.c @@ -208,12 +208,12 @@ void mlabel(int argc, char **argv, int type UNUSEDP) fprintf(stderr, "Both clear and new label specified\n"); FREE(&RootDir); exit(1); - } + } RootDir = open_root_dir(drive, isRop ? 0 : O_RDWR, isRop); if(isRo) { show = 1; interactive = 0; - } + } if(!RootDir) { fprintf(stderr, "%s: Cannot initialize drive\n", argv[0]); exit(1); @@ -241,7 +241,7 @@ void mlabel(int argc, char **argv, int type UNUSEDP) /* ask for new label */ if(interactive){ - saved_sig_state ss; + saved_sig_state ss; newLabel = longname; allow_interrupts(&ss); fprintf(stderr,"Enter the new volume label : "); @@ -314,7 +314,7 @@ void mlabel(int argc, char **argv, int type UNUSEDP) if((set_serial != SER_NONE) & have_boot) { if(have_boot && boot.boot.descr >= 0xf0 && has_BPB4) { - set_dword(labelBlock->serial, serial); + set_dword(labelBlock->serial, serial); need_write_boot = 1; } } @@ -324,7 +324,7 @@ void mlabel(int argc, char **argv, int type UNUSEDP) /* If this is fat 32, write backup boot sector too */ if(!WORD_S(fatlen)) { int backupBoot = WORD_S(ext.fat32.backupBoot); - force_write(Fs, (char *)&boot, + force_write(Fs, (char *)&boot, backupBoot * WORD_S(secsiz), sizeof(boot)); } diff --git a/mmd.c b/mmd.c index e44d58b..b8f74fe 100644 --- a/mmd.c +++ b/mmd.c @@ -64,12 +64,12 @@ static int makeit(dos_name_t *dosname, Stream_t *Target; CreateArg_t *arg = (CreateArg_t *) arg0; uint32_t fat; - direntry_t subEntry; + direntry_t subEntry; /* will it fit? At least one cluster must be free */ if (!getfreeMinClusters(targetEntry->Dir, 1)) return -1; - + mk_entry(dosname, ATTR_DIR, 1, 0, arg->mtime, &targetEntry->dir); Target = OpenFileByDirentry(targetEntry); if(!Target){ @@ -148,7 +148,7 @@ static int createDirCallback(direntry_t *entry UNUSEDP, MainParam_t *mp) FREE(&ret); return GOT_ONE; } - + } void mmd(int argc, char **argv, int type UNUSEDP) NORETURN; diff --git a/mmount.c b/mmount.c index aee0330..7f86987 100644 --- a/mmount.c +++ b/mmount.c @@ -18,7 +18,7 @@ * * written by: * - * Alain L. Knaff + * Alain L. Knaff * alain@knaff.lu * */ @@ -43,7 +43,7 @@ void mmount(int argc, char **argv, int type UNUSEDP) int media; union bootsector boot; Stream_t *Stream; - + if (argc<2 || !argv[1][0] || argv[1][1] != ':' || argv[1][2]){ fprintf(stderr,"Usage: %s -V drive:\n", argv[0]); exit(1); @@ -59,7 +59,7 @@ void mmount(int argc, char **argv, int type UNUSEDP) if ( dev.partition ) { char part_name[4]; sprintf(part_name, "%d", dev.partition %1000); - strcat(name, part_name); + strcat(name, part_name); } /* and finally mount it */ @@ -79,7 +79,7 @@ void mmount(int argc, char **argv, int type UNUSEDP) exit(1); default: while ( wait(&status) != pid ); - } + } if ( WEXITSTATUS(status) == 0 ) exit(0); argv[0] = strdup("mount"); diff --git a/mmove.c b/mmove.c index df67a2a..def0d0f 100644 --- a/mmove.c +++ b/mmove.c @@ -65,7 +65,7 @@ static int renameit(dos_name_t *dosname, /* get old direntry. It is important that we do this * on the actual direntry which is stored in the file, * and not on a copy, because we will modify it, and the - * modification should be visible at file + * modification should be visible at file * de-allocation time */ movedEntry = getDirentry(arg->mp.File); if(movedEntry->Dir != targetEntry->Dir) { @@ -73,7 +73,7 @@ static int renameit(dos_name_t *dosname, direntry_t subEntry; Stream_t *oldDir; /* we have a directory here. Change its parent link */ - + initializeDirentry(&subEntry, arg->mp.File); switch(vfat_lookup(&subEntry, "..", 2, ACCEPT_DIR, @@ -101,7 +101,7 @@ static int renameit(dos_name_t *dosname, } wipeEntry(movedEntry); - + /* free the old parent, allocate the new one. */ oldDir = movedEntry->Dir; *movedEntry = *targetEntry; @@ -174,7 +174,7 @@ static int rename_directory(direntry_t *entry, MainParam_t *mp) ret = rename_file(entry, mp); if(ret & ERROR_ONE) return ret; - + return ret; } @@ -220,7 +220,7 @@ static void usage(int ret) fprintf(stderr, "Usage: %s [-vV] [-D clash_option] file targetfile\n", progname); fprintf(stderr, - " %s [-vV] [-D clash_option] file [files...] target_directory\n", + " %s [-vV] [-D clash_option] file [files...] target_directory\n", progname); exit(ret); } @@ -270,7 +270,7 @@ void mmove(int argc, char **argv, int oldsyntax) if (argc - optind < 2) usage(1); - init_mp(&arg.mp); + init_mp(&arg.mp); arg.mp.arg = (void *) &arg; arg.mp.openflags = O_RDWR; diff --git a/mpartition.c b/mpartition.c index 71e6532..30f3ad4 100644 --- a/mpartition.c +++ b/mpartition.c @@ -85,7 +85,7 @@ void setBeginEnd(struct partition *partTable, exit(1); } sectors=(uint8_t) isectors; - + set_offset(&partTable->start, begin, heads, sectors); set_offset(&partTable->end, end-1, heads, sectors); set_dword(partTable->start_sect, begin); @@ -305,7 +305,7 @@ void mpartition(int argc, char **argv, int dummy UNUSEDP) char errmsg[2100]; char *bootSector=0; struct partition *tpartition; - + argtracks = 0; argheads = 0; argsectors = 0; @@ -433,7 +433,7 @@ void mpartition(int argc, char **argv, int dummy UNUSEDP) #ifdef USING_NEW_VOLD strcpy(name, getVoldName(dev, name)); #endif - Stream = OpenImage(&used_dev, dev, name, mode, errmsg, + Stream = OpenImage(&used_dev, dev, name, mode, errmsg, open2flags | SKIP_PARTITION | ALWAYS_GET_GEOMETRY, mode, NULL, NULL, NULL); @@ -448,7 +448,7 @@ void mpartition(int argc, char **argv, int dummy UNUSEDP) } tot_sectors = used_dev.tot_sectors; - + /* read the partition table */ if (READS(Stream, (char *) buf, 0, 512) != 512 && !initialize){ #ifdef HAVE_SNPRINTF @@ -602,7 +602,7 @@ void mpartition(int argc, char **argv, int dummy UNUSEDP) fprintf(stderr, "Begin larger than end\n"); exit(1); } - + /* Check whether new partition doesn't overlap with * any of those already in place */ if((overlap=findOverlap(partTable, 4, begin, end))) { diff --git a/msdos.h b/msdos.h index 3b64ed8..8aed16b 100644 --- a/msdos.h +++ b/msdos.h @@ -202,11 +202,11 @@ union bootsector { #define OFFSET(x) (((char *) (boot->x)) - ((char *)(boot->jump))) /* max FAT12/FAT16 sizes, according to - + https://staff.washington.edu/dittrich/misc/fatgen103.pdf https://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/fatgen103.doc - interestingly enough, another Microsoft document + interestingly enough, another Microsoft document [http://support.microsoft.com/default.aspx?scid=kb%3ben-us%3b67321] gives different values, but the first seems to be more sure about itself, so we believe that one ;-) diff --git a/mshortname.c b/mshortname.c index 495cef5..1e3aa96 100644 --- a/mshortname.c +++ b/mshortname.c @@ -34,9 +34,9 @@ static int print_short_name(direntry_t *entry, MainParam_t *mp UNUSEDP) static void usage(int ret) NORETURN; static void usage(int ret) { - fprintf(stderr, "Mtools version %s, dated %s\n", + fprintf(stderr, "Mtools version %s, dated %s\n", mversion, mdate); - fprintf(stderr, + fprintf(stderr, "Usage: %s msdosfile [msdosfiles...]\n", progname); exit(ret); diff --git a/mshowfat.c b/mshowfat.c index b04c6e6..d4919c4 100644 --- a/mshowfat.c +++ b/mshowfat.c @@ -72,7 +72,7 @@ void mshowfat(int argc, char **argv, int mtype UNUSEDP) { Arg_t arg; int c, ret; - + /* get command line options */ if(helpFlag(argc, argv)) usage(0); diff --git a/mtools.c b/mtools.c index ffac8bb..272558e 100644 --- a/mtools.c +++ b/mtools.c @@ -78,10 +78,10 @@ int main(int argc,char **argv) /*#define PRIV_TEST*/ #ifdef PRIV_TEST - { + { int euid; char command[100]; - + printf("INIT: %d %d\n", getuid(), geteuid()); drop_privs(); printf("DROP: %d %d\n", getuid(), geteuid()); @@ -105,7 +105,7 @@ int main(int argc,char **argv) #ifdef __EMX__ _wildcard(&argc,&argv); -#endif +#endif /* check whether the compiler lays out structures in a sane way */ @@ -132,7 +132,7 @@ int main(int argc,char **argv) ** Mainly done for the BeOS, which doesn't support links yet. */ - if(argc >= 3 && + if(argc >= 3 && !strcmp(argv[1], "-c") && !strcmp(name, "mtools")) { argc-=2; @@ -143,9 +143,9 @@ int main(int argc,char **argv) /* print the version */ - if(argc >= 2 && + if(argc >= 2 && (strcmp(argv[1], "-V") == 0 || strcmp(argv[1], "--version") ==0)) { - printf("%s (GNU mtools) %s\n", + printf("%s (GNU mtools) %s\n", name, mversion); printf("configured with the following options: "); #ifdef USE_XDF diff --git a/mtools.h b/mtools.h index f6e159e..abd86df 100644 --- a/mtools.h +++ b/mtools.h @@ -24,7 +24,7 @@ typedef struct dos_name_t dos_name_t; #define MAXPATHLEN 1024 #include extern int lockf(int, int, off_t); /* SCO has no proper include file for lockf */ -#endif +#endif #define SCSI_FLAG 0x001u #define PRIV_FLAG 0x002u @@ -84,7 +84,7 @@ typedef struct device { * of a track) */ uint32_t sector_size; /* Non-default sector size */ - + const char *cfg_filename; /* used for debugging purposes */ } device_t; @@ -92,7 +92,7 @@ struct OldDos_t { unsigned int tracks; uint16_t sectors; uint16_t heads; - + uint16_t dir_len; unsigned int cluster_size; unsigned int fat_len; @@ -141,7 +141,7 @@ extern const char *short_illegals, *long_illegals; #define minimize(target, min) do { \ if(target < min) \ target = min; \ -} while(0) +} while(0) #ifdef OS_linux int get_sector_size(int fd); @@ -154,7 +154,7 @@ int readwrite_sectors(int fd, /* file descriptor */ int rate, int seektrack, int track, int head, int sector, int size, /* address */ - char *data, + char *data, int bytes, int direction, int retries); @@ -241,10 +241,10 @@ UNUSED(static __inline__ size_t ptrdiff (const char *end, const char *begin)) Stream_t *GetFs(Stream_t *Fs); -void label_name_uc(doscp_t *cp, const char *filename, int verbose, +void label_name_uc(doscp_t *cp, const char *filename, int verbose, int *mangled, dos_name_t *ans); -void label_name_pc(doscp_t *cp, const char *filename, int verbose, +void label_name_pc(doscp_t *cp, const char *filename, int verbose, int *mangled, dos_name_t *ans); /* environmental variables */ @@ -335,7 +335,7 @@ char *getVoldName(struct device *dev, char *name); Stream_t *OpenDir(const char *filename); -/* int unix_dir_loop(Stream_t *Stream, MainParam_t *mp); +/* int unix_dir_loop(Stream_t *Stream, MainParam_t *mp); int unix_loop(MainParam_t *mp, char *arg); */ struct dirCache_t **getDirCacheP(Stream_t *Stream); diff --git a/mtoolsDirentry.h b/mtoolsDirentry.h index d2281c1..4c3960b 100644 --- a/mtoolsDirentry.h +++ b/mtoolsDirentry.h @@ -21,15 +21,15 @@ typedef struct direntry_t { struct Stream_t *Dir; - /* struct direntry_t *parent; parent level */ + /* struct direntry_t *parent; parent level */ int entry; /* slot in parent directory */ /* Negative values have the following meanings: -1 not initialized -2 entry searched for, but not found -3 root directory */ - struct directory dir; /* descriptor in parent directory (random if + struct directory dir; /* descriptor in parent directory (random if * root)*/ - wchar_t name[MAX_VNAMELEN+1]; /* name in its parent directory, or + wchar_t name[MAX_VNAMELEN+1]; /* name in its parent directory, or * NULL if root */ int beginSlot; /* begin and end slot, for delete */ int endSlot; @@ -75,7 +75,7 @@ int lookupForInsert(Stream_t *Dir, direntry_t *direntry, struct dos_name_t *dosname, char *longname, - struct scan_state *ssp, + struct scan_state *ssp, int ignore_entry, int source_entry, int pessimisticShortRename, diff --git a/mzip.c b/mzip.c index b685acd..41f9b08 100644 --- a/mzip.c +++ b/mzip.c @@ -55,8 +55,8 @@ #endif -static int zip_cmd(int priv, int fd, unsigned char cdb[6], uint8_t clen, - scsi_io_mode_t mode, void *data, uint32_t len, +static int zip_cmd(int priv, int fd, unsigned char cdb[6], uint8_t clen, + scsi_io_mode_t mode, void *data, uint32_t len, void *extra_data) { int r; @@ -79,14 +79,14 @@ static int test_mounted ( char *dev ) * Now check if any partition of this device is already mounted (this * includes checking if the device is mounted under a different name). */ - + if (MT_STAT (dev, &st_dev)) { fprintf (stderr, "%s: stat(%s) failed: %s.\n", progname, dev, strerror (errno)); exit(1); } - - if (!S_ISBLK (st_dev.st_mode)) /* not a block device, cannot + + if (!S_ISBLK (st_dev.st_mode)) /* not a block device, cannot * be mounted */ return 0; @@ -99,7 +99,7 @@ static int test_mounted ( char *dev ) progname, _PATH_MOUNTED); exit(1); } - + while ( ( mnt = getmntent (mtab) ) ) { if (!mnt->mnt_fsname @@ -120,7 +120,7 @@ static int test_mounted ( char *dev ) if (MT_STAT (mnt->mnt_fsname, &st_mnt)) { continue; } - + if (S_ISBLK (st_mnt.st_mode)) { #ifdef OS_linux /* on Linux, warn also if the device is on the same @@ -128,10 +128,10 @@ static int test_mounted ( char *dev ) if (MAJOR(st_mnt.st_rdev) == MAJOR(st_dev.st_rdev) && MINOR(st_mnt.st_rdev) >= MINOR(st_dev.st_rdev) && MINOR(st_mnt.st_rdev) <= MINOR(st_dev.st_rdev)+15){ - fprintf (stderr, - "Device %s%d is mounted on %s.\n", - dev, - MINOR(st_mnt.st_rdev) - + fprintf (stderr, + "Device %s%d is mounted on %s.\n", + dev, + MINOR(st_mnt.st_rdev) - MINOR(st_dev.st_rdev), mnt->mnt_dir); #else @@ -154,10 +154,10 @@ static int test_mounted ( char *dev ) static void usage(int ret) NORETURN; static void usage(int ret) { - fprintf(stderr, - "Mtools version %s, dated %s\n", + fprintf(stderr, + "Mtools version %s, dated %s\n", mversion, mdate); - fprintf(stderr, + fprintf(stderr, "Usage: %s [-V] [-q] [-e] [-u] [-r|-w|-p|-x] [drive:]\n" "\t-q print status\n" "\t-e eject disk\n" @@ -166,7 +166,7 @@ static void usage(int ret) "\t-w not write-protected (read-write)\n" "\t-p password write protected\n" "\t-x password protected\n" - "\t-u unprotect till disk ejecting\n", + "\t-u unprotect till disk ejecting\n", progname); exit(ret); } @@ -181,8 +181,8 @@ static uint8_t get_zip_status(int priv, int fd, void *extra_data) { unsigned char status[128]; unsigned char cdb[6] = { 0x06, 0, 0x02, 0, sizeof status, 0 }; - - if (zip_cmd(priv, fd, cdb, 6, SCSI_IO_READ, + + if (zip_cmd(priv, fd, cdb, 6, SCSI_IO_READ, status, sizeof status, extra_data) == -1) { perror("status: "); exit(1); @@ -191,7 +191,7 @@ static uint8_t get_zip_status(int priv, int fd, void *extra_data) } -static int short_command(int priv, int fd, uint8_t cmd1, uint8_t cmd2, +static int short_command(int priv, int fd, uint8_t cmd1, uint8_t cmd2, uint8_t cmd3, const char *data, void *extra_data) { uint8_t cdb[6] = { 0, 0, 0, 0, 0, 0 }; @@ -200,16 +200,16 @@ static int short_command(int priv, int fd, uint8_t cmd1, uint8_t cmd2, cdb[1] = cmd2; cdb[4] = cmd3; - return zip_cmd(priv, fd, cdb, 6, SCSI_IO_WRITE, + return zip_cmd(priv, fd, cdb, 6, SCSI_IO_WRITE, (char *) data, data ? (uint32_t) strlen(data) : 0, extra_data); } -static int iomega_command(int priv, int fd, uint8_t mode, const char *data, +static int iomega_command(int priv, int fd, uint8_t mode, const char *data, void *extra_data) { - return short_command(priv, fd, + return short_command(priv, fd, SCSI_IOMEGA, mode, /* Do we really need strlen(data) in here? */ data ? (uint8_t) strlen(data) : 0, @@ -246,7 +246,7 @@ void mzip(int argc, char **argv, int type UNUSEDP) request |= ZIP_MODE_CHANGE; \ newMode = x; \ break; - + /* get command line options */ if(helpFlag(argc, argv)) usage(0); @@ -257,7 +257,7 @@ void mzip(int argc, char **argv, int type UNUSEDP) break; case 'f': if (get_real_uid()) { - fprintf(stderr, + fprintf(stderr, "Only root can use force. Sorry.\n"); exit(1); } @@ -284,19 +284,19 @@ void mzip(int argc, char **argv, int type UNUSEDP) usage(0); default: /* unrecognized */ usage(1); - + } } - + if (request == ZIP_NIX) request = ZIP_STATUS; /* default action */ - if (argc - optind > 1 || + if (argc - optind > 1 || (argc - optind == 1 && (!argv[optind][0] || argv[optind][1] != ':'))) usage(1); - + drive = ch_toupper(argc - optind == 1 ? argv[argc - 1][0] : ':'); - + for (dev = devices; dev->name; dev++) { unsigned char cdb[6] = { 0, 0, 0, 0, 0, 0 }; struct { @@ -314,13 +314,13 @@ void mzip(int argc, char **argv, int type UNUSEDP) reserved2[40]; } inq_data; - if (dev->drive != drive) + if (dev->drive != drive) continue; expand(dev->name, name); if ((request & (ZIP_MODE_CHANGE | ZIP_EJECT)) && !(request & ZIP_FORCE) && test_mounted(name)) { - fprintf(stderr, + fprintf(stderr, "Can\'t change status of/eject mounted device\n"); exit(1); } @@ -339,8 +339,8 @@ void mzip(int argc, char **argv, int type UNUSEDP) /* need readonly, else we can't * open the drive on Solaris if - * write-protected */ - if (fd == -1) + * write-protected */ + if (fd == -1) continue; closeExec(fd); @@ -352,12 +352,12 @@ void mzip(int argc, char **argv, int type UNUSEDP) cdb[0] = SCSI_INQUIRY; cdb[4] = sizeof inq_data; - if (zip_cmd(IS_PRIVILEGED(dev), fd, cdb, 6, SCSI_IO_READ, + if (zip_cmd(IS_PRIVILEGED(dev), fd, cdb, 6, SCSI_IO_READ, &inq_data, sizeof inq_data, extra_data) != 0) { close(fd); continue; } - + #ifdef DEBUG fprintf(stderr, "device: %s\n\tvendor: %.8s\n\tproduct: %.16s\n" "\trevision: %.4s\n", name, inq_data.vendor, @@ -381,10 +381,10 @@ void mzip(int argc, char **argv, int type UNUSEDP) /* debugging */ fprintf(stderr,"Skipping drive with vendor='"); - fwrite(inq_data.vendor,1, sizeof(inq_data.vendor), + fwrite(inq_data.vendor,1, sizeof(inq_data.vendor), stderr); fprintf(stderr,"' product='"); - fwrite(inq_data.product,1, sizeof(inq_data.product), + fwrite(inq_data.product,1, sizeof(inq_data.product), stderr); fprintf(stderr,"'\n"); /* end debugging */ @@ -433,34 +433,34 @@ void mzip(int argc, char **argv, int type UNUSEDP) char *s; passwd = "APlaceForYourStuff"; if ((s = strchr(passwd, '\n'))) *s = '\0'; /* chomp */ - iomega_command(IS_PRIVILEGED(dev), fd, unlockMode, + iomega_command(IS_PRIVILEGED(dev), fd, unlockMode, passwd, extra_data); } - - if ((get_zip_status(IS_PRIVILEGED(dev), fd, extra_data) & + + if ((get_zip_status(IS_PRIVILEGED(dev), fd, extra_data) & unlockMask) == 1) { /* unlock first */ char *s; passwd = getpass("Password: "); if ((s = strchr(passwd, '\n'))) *s = '\0'; /* chomp */ - if((ret=iomega_command(IS_PRIVILEGED(dev), fd, - unlockMode, passwd, + if((ret=iomega_command(IS_PRIVILEGED(dev), fd, + unlockMode, passwd, extra_data))){ if (ret == -1) perror("passwd: "); else fprintf(stderr, "wrong password\n"); exit(1); } - if((get_zip_status(IS_PRIVILEGED(dev), - fd, extra_data) & + if((get_zip_status(IS_PRIVILEGED(dev), + fd, extra_data) & unlockMask) == 1) { fprintf(stderr, "wrong password\n"); exit(1); } } - + if (newMode & 0x1) { char first_try[_PASSWORD_LEN+1]; - + passwd = getpass("Enter new password:"); strncpy(first_try, passwd,_PASSWORD_LEN); passwd = getpass("Re-type new password:"); @@ -477,7 +477,7 @@ void mzip(int argc, char **argv, int type UNUSEDP) if(newMode == ZIP_UNLOCK_TIL_EJECT) newMode |= oldMode; - if((ret=iomega_command(IS_PRIVILEGED(dev), fd, + if((ret=iomega_command(IS_PRIVILEGED(dev), fd, newMode, passwd, extra_data))){ if (ret == -1) perror("set passwd: "); else fprintf(stderr, "password not changed\n"); @@ -489,16 +489,16 @@ void mzip(int argc, char **argv, int type UNUSEDP) status has changed */ #endif } - + if (request & ZIP_STATUS) { const char *unlocked; if(oldMode & 8) unlocked = " and unlocked until eject"; else - unlocked = ""; + unlocked = ""; switch (oldMode & ~8) { - case ZIP_RW: + case ZIP_RW: printf("Drive '%c:' is not write-protected\n", drive); break; @@ -506,49 +506,49 @@ void mzip(int argc, char **argv, int type UNUSEDP) printf("Drive '%c:' is write-protected%s\n", drive, unlocked); break; - case ZIP_RO_PW: - printf("Drive '%c:' is password write-protected%s\n", + case ZIP_RO_PW: + printf("Drive '%c:' is password write-protected%s\n", drive, unlocked); break; - case ZIP_PW: - printf("Drive '%c:' is password protected%s\n", + case ZIP_PW: + printf("Drive '%c:' is password protected%s\n", drive, unlocked); break; - default: + default: printf("Unknown protection mode %d of drive '%c:'\n", oldMode, drive); - break; - } + break; + } } - + if (request & ZIP_EJECT) { if(request & ZIP_FORCE) - if(door_command(IS_PRIVILEGED(dev), fd, + if(door_command(IS_PRIVILEGED(dev), fd, SCSI_ALLOW_MEDIUM_REMOVAL, 0, extra_data) < 0) { perror("door unlock: "); exit(1); } - if(door_command(IS_PRIVILEGED(dev), fd, + if(door_command(IS_PRIVILEGED(dev), fd, SCSI_START_STOP, 1, extra_data) < 0) { perror("stop motor: "); exit(1); } - if(door_command(IS_PRIVILEGED(dev), fd, + if(door_command(IS_PRIVILEGED(dev), fd, SCSI_START_STOP, 2, extra_data) < 0) { perror("eject: "); exit(1); } - if(door_command(IS_PRIVILEGED(dev), fd, + if(door_command(IS_PRIVILEGED(dev), fd, SCSI_START_STOP, 2, extra_data) < 0) { perror("second eject: "); exit(1); } } - + close(fd); exit(0); } diff --git a/nameclash.h b/nameclash.h index 25674dc..5f3bdc6 100644 --- a/nameclash.h +++ b/nameclash.h @@ -37,7 +37,7 @@ typedef enum clash_action { typedef struct ClashHandling_t { clash_action action[2]; clash_action namematch_default[2]; - + int nowarn; /* Don't ask, just do default action if name collision*/ int got_slots; int mod_time; @@ -49,10 +49,10 @@ typedef struct ClashHandling_t { int use_longname; int ignore_entry; int source; /* to prevent the source from overwriting itself */ - int source_entry; /* to account for the space freed up by the original + int source_entry; /* to account for the space freed up by the original * name */ void (*name_converter)(doscp_t *cp, - const char *filename, int verbose, + const char *filename, int verbose, int *mangled, dos_name_t *ans); int is_label; } ClashHandling_t; diff --git a/offset.c b/offset.c index 076c50b..dedf098 100644 --- a/offset.c +++ b/offset.c @@ -34,14 +34,14 @@ typedef struct Offset_t { static ssize_t offset_read(Stream_t *Stream, char *buf, mt_off_t start, size_t len) { - DeclareThis(Offset_t); + DeclareThis(Offset_t); return READS(This->Next, buf, start+This->offset, len); } static ssize_t offset_write(Stream_t *Stream, char *buf, mt_off_t start, size_t len) { - DeclareThis(Offset_t); + DeclareThis(Offset_t); return WRITES(This->Next, buf, start+This->offset, len); } @@ -79,7 +79,7 @@ Stream_t *OpenOffset(Stream_t *Next, struct device *dev, off_t offset, sprintf(errmsg,"init: Big disks not supported"); goto exit_0; } - + *maxSize -= (mt_size_t) This->offset; } diff --git a/open_image.c b/open_image.c index 4201431..b3e3f3a 100644 --- a/open_image.c +++ b/open_image.c @@ -122,7 +122,7 @@ Stream_t *OpenImage(struct device *out_dev, struct device *dev, goto exit_0; Stream = Swap; } - + if((flags & ALWAYS_GET_GEOMETRY) && compute_lba_geom_from_tot_sectors(out_dev) < 0) goto exit_0; @@ -134,7 +134,7 @@ Stream_t *OpenImage(struct device *out_dev, struct device *dev, goto exit_0; Stream = Partition; } - + return Stream; exit_0: FREE(&Stream); diff --git a/partition.c b/partition.c index 9d8c0df..6c8d3c8 100644 --- a/partition.c +++ b/partition.c @@ -32,7 +32,7 @@ typedef struct Partition_t { uint32_t size; /* size, in sectors */ uint8_t pos; - + uint8_t sectors; uint8_t heads; uint16_t cyclinders; @@ -150,7 +150,7 @@ static ssize_t partition_read(Stream_t *Stream, char *buf, static ssize_t partition_write(Stream_t *Stream, char *buf, mt_off_t start, size_t len) { - DeclareThis(Partition_t); + DeclareThis(Partition_t); limit_size(This, start, &len); return WRITES(This->Next, buf, start+This->offset, len); } @@ -171,7 +171,7 @@ static int partition_data(Stream_t *Stream, time_t *date, mt_size_t *size, } -static int partition_geom(Stream_t *Stream, struct device *dev, +static int partition_geom(Stream_t *Stream, struct device *dev, UNUSEDP struct device *orig_dev) { DeclareThis(Partition_t); @@ -204,8 +204,8 @@ Stream_t *OpenPartition(Stream_t *Next, struct device *dev, struct partition *partition; if(!dev || (dev->partition > 4) || (dev->partition <= 0)) { - fprintf(stderr, - "Invalid partition %d (must be between 1 and 4), ignoring it\n", + fprintf(stderr, + "Invalid partition %d (must be between 1 and 4), ignoring it\n", dev->partition); return NULL; } @@ -220,7 +220,7 @@ Stream_t *OpenPartition(Stream_t *Next, struct device *dev, This->refs = 1; This->Next = Next; - + /* read the first sector, or part of it */ if (force_read(This->Next, (char*) buf, 0, 512) != 512) goto exit_0; @@ -239,7 +239,7 @@ Stream_t *OpenPartition(Stream_t *Next, struct device *dev, dev->partition); goto exit_0; } - + partOff = BEGIN(partition); if (maxSize) { if (partOff > *maxSize >> 9) { diff --git a/plain_io.c b/plain_io.c index efb1951..f4c1bac 100644 --- a/plain_io.c +++ b/plain_io.c @@ -18,7 +18,7 @@ * * written by: * - * Alain L. Knaff + * Alain L. Knaff * alain@knaff.lu * */ @@ -81,7 +81,7 @@ static ssize_t file_io(Stream_t *Stream, char *buf, mt_off_t where, size_t len, ret = io(This->fd, buf, len); #ifdef OS_hpux - if (ret == -1 && + if (ret == -1 && errno == EINVAL && /* if we got EINVAL */ len > MAX_SCSI_LEN) { This->size_limited = 1; @@ -98,7 +98,7 @@ static ssize_t file_io(Stream_t *Stream, char *buf, mt_off_t where, size_t len, This->lastwhere = where + ret; return ret; } - + static ssize_t file_read(Stream_t *Stream, char *buf, @@ -158,7 +158,7 @@ static int init_geom_with_reg(int fd, struct device *dev, } } -static int file_geom(Stream_t *Stream, struct device *dev, +static int file_geom(Stream_t *Stream, struct device *dev, struct device *orig_dev) { int ret; @@ -217,7 +217,7 @@ static int file_discard(Stream_t *Stream) } static Class_t SimpleFileClass = { - file_read, + file_read, file_write, file_flush, file_free, @@ -246,7 +246,7 @@ int LockDevice(int fd, struct device *dev, #else sprintf(errmsg, "plain floppy: device \"%s\" busy (%s):", - (dev && strlen(dev->name) < 50) ? + (dev && strlen(dev->name) < 50) ? dev->name : "unknown", strerror(errno)); #endif @@ -265,7 +265,7 @@ int LockDevice(int fd, struct device *dev, } Stream_t *SimpleFileOpen(struct device *dev, struct device *orig_dev, - const char *name, int mode, char *errmsg, + const char *name, int mode, char *errmsg, int mode2, int locked, mt_size_t *maxSize) { return SimpleFileOpenWithLm(dev, orig_dev, name, mode, errmsg, mode2, locked, mode, maxSize, @@ -273,7 +273,7 @@ Stream_t *SimpleFileOpen(struct device *dev, struct device *orig_dev, } Stream_t *SimpleFileOpenWithLm(struct device *dev, struct device *orig_dev, - const char *name, int mode, char *errmsg, + const char *name, int mode, char *errmsg, int mode2, int locked, int lockMode, mt_size_t *maxSize, int *geomFailure) { @@ -309,10 +309,10 @@ APIRET rc; Free(This); if(errmsg) #ifdef HAVE_SNPRINTF - snprintf(errmsg,199,"Can't stat -: %s", - strerror(errno)); + snprintf(errmsg,199,"Can't stat -: %s", + strerror(errno)); #else - sprintf(errmsg,"Can't stat -: %s", + sprintf(errmsg,"Can't stat -: %s", strerror(errno)); #endif return NULL; @@ -321,7 +321,7 @@ APIRET rc; return (Stream_t *) This; } - + if(dev) { if(!(mode2 & NO_PRIV)) This->privileged = IS_PRIVILEGED(dev); @@ -360,13 +360,13 @@ APIRET rc; } else #endif { - This->fd = open(name, mode | O_LARGEFILE | O_BINARY, + This->fd = open(name, mode | O_LARGEFILE | O_BINARY, IS_NOLOCK(dev)?0444:0666); } if(IS_PRIVILEGED(dev) && !(mode2 & NO_PRIV)) drop_privs(); - + if (This->fd < 0) { if(errmsg) { #ifdef HAVE_SNPRINTF @@ -393,14 +393,14 @@ APIRET rc; ) { if(errmsg) { #ifdef HAVE_SNPRINTF - snprintf(errmsg,199,"Can't stat %s: %s", + snprintf(errmsg,199,"Can't stat %s: %s", name, strerror(errno)); #else if(strlen(name) > 50) { - sprintf(errmsg,"Can't stat file: %s", + sprintf(errmsg,"Can't stat file: %s", strerror(errno)); } else { - sprintf(errmsg,"Can't stat %s: %s", + sprintf(errmsg,"Can't stat %s: %s", name, strerror(errno)); } #endif @@ -410,7 +410,7 @@ APIRET rc; if(LockDevice(This->fd, dev, locked, lockMode, errmsg) < 0) goto exit_0; - + /* set default parameters, if needed */ if (dev){ errno=0; diff --git a/precmd.c b/precmd.c index d31aa01..7660237 100644 --- a/precmd.c +++ b/precmd.c @@ -28,7 +28,7 @@ void precmd(struct device *dev) if(!dev || !dev->precmd) return; - + switch((pid=fork())){ case -1: perror("Could not fork"); @@ -42,4 +42,4 @@ void precmd(struct device *dev) } #endif } - + diff --git a/privileges.c b/privileges.c index 71de4c1..b055003 100644 --- a/privileges.c +++ b/privileges.c @@ -200,7 +200,7 @@ void init_privs(void) #endif #endif } - + drop_privs(); print_privs("after init, real should be 0, effective should not "); } diff --git a/read_dword.h b/read_dword.h index 0803bd8..499fd1d 100644 --- a/read_dword.h +++ b/read_dword.h @@ -18,10 +18,10 @@ * along with Mtools. If not, see . */ -static Dword read_dword(int handle) +static Dword read_dword(int handle) { Byte val[4]; - + if(read(handle, (char *)val, 4) < 4) return (Dword) -1; @@ -31,7 +31,7 @@ static Dword read_dword(int handle) UNUSED(static int32_t read_sdword(int handle)) { Byte val[4]; - + if(read(handle, (char *)val, 4) < 4) return (int32_t) -1; @@ -44,7 +44,7 @@ UNUSED(static struct SQwordRet read_sqword(int handle) ) { Byte val[8]; struct SQwordRet ret; - + if(read(handle, (char *)val, 8) < 8) { ret.err=-1; } else { diff --git a/remap.c b/remap.c index d8fb85d..6256b25 100644 --- a/remap.c +++ b/remap.c @@ -67,7 +67,7 @@ static enum map_type_t remap(Remap_t *This, mt_off_t *start, size_t *len) { static ssize_t remap_read(Stream_t *Stream, char *buf, mt_off_t start, size_t len) { - DeclareThis(Remap_t); + DeclareThis(Remap_t); if(remap(This, &start, &len)==DATA) return READS(This->Next, buf, start, len); else { @@ -79,7 +79,7 @@ static ssize_t remap_read(Stream_t *Stream, char *buf, static ssize_t remap_write(Stream_t *Stream, char *buf, mt_off_t start, size_t len) { - DeclareThis(Remap_t); + DeclareThis(Remap_t); if(remap(This, &start, &len)==DATA) return WRITES(This->Next, buf, start, len); else { @@ -159,7 +159,7 @@ static int process_map(Remap_t *This, const char *ptr, sprintf(errmsg, "Bad number %s\n", ptr); return -1; } - + if(type == POS) { orig = (mt_off_t)len; continue; @@ -177,7 +177,7 @@ static int process_map(Remap_t *This, const char *ptr, if(type != ZERO) { orig+=len; } - + } This->net_offset = orig-remapped; return count; @@ -188,7 +188,7 @@ Stream_t *Remap(Stream_t *Next, struct device *dev, char *errmsg) { Remap_t *This; int nrItems=0; const char *map = dev->data_map; - + This = New(Remap_t); if (!This){ printOom(); @@ -198,14 +198,14 @@ Stream_t *Remap(Stream_t *Next, struct device *dev, char *errmsg) { This->Class = &RemapClass; This->refs = 1; This->Next = Next; - + /* First count number of items */ nrItems=process_map(This, map, 1, errmsg); if(nrItems < 0) { free(This); return NULL; } - + This->map = calloc((size_t)nrItems+1, sizeof(struct map)); if(!This->map) { printOom(); @@ -216,7 +216,7 @@ Stream_t *Remap(Stream_t *Next, struct device *dev, char *errmsg) { if(adjust_tot_sectors(dev, This->net_offset, errmsg) < 0) goto exit_1; - + This->mapSize=nrItems-1; return (Stream_t *) This; exit_1: diff --git a/scsi.c b/scsi.c index 796e42f..114eb8c 100644 --- a/scsi.c +++ b/scsi.c @@ -104,7 +104,7 @@ int scsi_cmd(int fd, unsigned char *cdb, uint8_t cmdlen, scsi_io_mode_t mode, { #if defined OS_hpux struct sctl_io sctl_io; - + memset(&sctl_io, 0, sizeof sctl_io); /* clear reserved fields */ memcpy(sctl_io.cdb, cdb, cmdlen); /* copy command */ sctl_io.cdb_length = cmdlen; /* command length */ @@ -116,7 +116,7 @@ int scsi_cmd(int fd, unsigned char *cdb, uint8_t cmdlen, scsi_io_mode_t mode, sctl_io.data_length = len; sctl_io.data = data; break; - case SCSI_IO_WRITE: + case SCSI_IO_WRITE: sctl_io.flags = 0; sctl_io.data_length = data ? len : 0; sctl_io.data = len ? data : 0; @@ -129,7 +129,7 @@ int scsi_cmd(int fd, unsigned char *cdb, uint8_t cmdlen, scsi_io_mode_t mode, } return sctl_io.cdb_status; - + #elif defined OS_sunos || defined OS_solaris struct uscsi_cmd uscsi_cmd; memset(&uscsi_cmd, 0, sizeof uscsi_cmd); @@ -138,7 +138,7 @@ int scsi_cmd(int fd, unsigned char *cdb, uint8_t cmdlen, scsi_io_mode_t mode, #ifdef OS_solaris uscsi_cmd.uscsi_timeout = 20; /* msec? */ #endif /* solaris */ - + uscsi_cmd.uscsi_buflen = (u_int)len; uscsi_cmd.uscsi_bufaddr = data; @@ -158,13 +158,13 @@ int scsi_cmd(int fd, unsigned char *cdb, uint8_t cmdlen, scsi_io_mode_t mode, if(uscsi_cmd.uscsi_status) { errno = 0; - fprintf(stderr,"scsi status=%x\n", + fprintf(stderr,"scsi status=%x\n", (unsigned short)uscsi_cmd.uscsi_status); return -1; } - + return 0; - + #elif defined OS_linux struct sg_io_hdr my_scsi_cmd; @@ -191,7 +191,7 @@ int scsi_cmd(int fd, unsigned char *cdb, uint8_t cmdlen, scsi_io_mode_t mode, perror("scsi_io"); return -1; } - + return my_scsi_cmd.status & STATUS_MASK; #elif (defined _SCO_DS) && (defined SCSIUSERCMD) @@ -227,7 +227,7 @@ int scsi_cmd(int fd, unsigned char *cdb, uint8_t cmdlen, scsi_io_mode_t mode, case SCSI_IO_WRITE: my_scsi_cmd.ds_flags = DSRQ_WRITE|DSRQ_SENSE; break; - } + } my_scsi_cmd.ds_time = 10000; my_scsi_cmd.ds_link = 0; my_scsi_cmd.ds_synch =0; @@ -239,11 +239,11 @@ int scsi_cmd(int fd, unsigned char *cdb, uint8_t cmdlen, scsi_io_mode_t mode, if(my_scsi_cmd.ds_status) { errno = 0; - fprintf(stderr,"scsi status=%x\n", + fprintf(stderr,"scsi status=%x\n", (unsigned short)my_scsi_cmd.ds_status); return -1; } - + return 0; #elif (defined OS_freebsd) && (__FreeBSD__ >= 2) #define MSG_SIMPLE_Q_TAG 0x20 /* O/O */ @@ -278,7 +278,7 @@ int scsi_cmd(int fd, unsigned char *cdb, uint8_t cmdlen, scsi_io_mode_t mode, 96, cmdlen, 5000); - + if (cam_send_ccb(cam_dev, ccb) < 0 || (ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { return -1; @@ -310,7 +310,7 @@ int scsi_cmd(int fd, unsigned char *cdb, uint8_t cmdlen, scsi_io_mode_t mode, if (sc.retsts) { errno = EIO; - fprintf(stderr, "SCSI command failed, retsts %d\n", + fprintf(stderr, "SCSI command failed, retsts %d\n", sc.retsts); return -1; } diff --git a/scsi_io.c b/scsi_io.c index 6451211..89a816d 100644 --- a/scsi_io.c +++ b/scsi_io.c @@ -18,7 +18,7 @@ * * written by: * - * Alain L. Knaff + * Alain L. Knaff * alain@knaff.lu * */ @@ -40,15 +40,15 @@ typedef struct ScsiDevice_t { int refs; Stream_t *Next; Stream_t *Buffer; - + int fd; int privileged; - + uint32_t scsi_sector_size; mt_size_t device_size; uint32_t tot_sectors; void *extra_data; /* extra system dependent information for scsi. - On some platforms, filled in by scsi_open, and to + On some platforms, filled in by scsi_open, and to be supplied to scsi_cmd */ } ScsiDevice_t; @@ -77,7 +77,7 @@ static int scsi_init(ScsiDevice_t *This) memset(cdb, 0, sizeof cdb); memset(buf,0, sizeof(buf)); cdb[0]=SCSI_READ_CAPACITY; - if (scsi_cmd(fd, (unsigned char *)cdb, + if (scsi_cmd(fd, (unsigned char *)cdb, sizeof(cdb), SCSI_IO_READ, buf, sizeof(buf), This->extra_data)==0) { @@ -88,7 +88,7 @@ static int scsi_init(ScsiDevice_t *This) (unsigned)buf[3]; if(This->tot_sectors < UINT32_MAX) This->tot_sectors++; - + This->scsi_sector_size= ((unsigned)buf[5]<<16)| ((unsigned)buf[6]<<8)| @@ -139,7 +139,7 @@ static ssize_t scsi_io(Stream_t *Stream, char *buf, * equal to the requested size! */ while (nsect*This->scsi_sector_size>len) --nsect; - if(!nsect) { + if(!nsect) { fprintf(stderr,"Scsi buffer too small\n"); exit(1); } @@ -157,10 +157,10 @@ static ssize_t scsi_io(Stream_t *Stream, char *buf, max = scsi_max_length(); - + if (nsect > max) nsect=max; - + /* set up SCSI READ/WRITE command */ memset(cdb, 0, sizeof cdb); @@ -204,7 +204,7 @@ static ssize_t scsi_io(Stream_t *Stream, char *buf, cdb[4] = (unsigned char) nsect; cdb[5] = 0; } - + if(This->privileged) reclaim_privs(); @@ -265,7 +265,7 @@ static int scsi_get_data(Stream_t *Stream, time_t *date, mt_size_t *size, static Class_t ScsiDeviceClass = { - scsi_read, + scsi_read, scsi_write, 0, 0, @@ -276,8 +276,8 @@ static Class_t ScsiDeviceClass = { 0 /* discard */ }; -Stream_t *OpenScsi(struct device *dev, - const char *name, int mode, char *errmsg, +Stream_t *OpenScsi(struct device *dev, + const char *name, int mode, char *errmsg, int mode2, int locked, int lockMode, mt_size_t *maxSize) { @@ -294,7 +294,7 @@ Stream_t *OpenScsi(struct device *dev, memset((void*)This, 0, sizeof(ScsiDevice_t)); This->scsi_sector_size = 512; This->Class = &ScsiDeviceClass; - + if(dev) { if(!(mode2 & NO_PRIV)) This->privileged = IS_PRIVILEGED(dev); @@ -312,7 +312,7 @@ Stream_t *OpenScsi(struct device *dev, if(IS_PRIVILEGED(dev) && !(mode2 & NO_PRIV)) drop_privs(); - + if (This->fd < 0) { if(errmsg) { #ifdef HAVE_SNPRINTF diff --git a/scsi_io.h b/scsi_io.h index 23655fd..65f76c9 100644 --- a/scsi_io.h +++ b/scsi_io.h @@ -1,5 +1,5 @@ -Stream_t *OpenScsi(struct device *dev, - const char *name, int mode, char *errmsg, +Stream_t *OpenScsi(struct device *dev, + const char *name, int mode, char *errmsg, int mode2, int locked, int lockMode, mt_size_t *maxSize); diff --git a/stream.c b/stream.c index fcd59ac..4fc29ad 100644 --- a/stream.c +++ b/stream.c @@ -106,7 +106,7 @@ int adjust_tot_sectors(struct device *dev, mt_off_t offset, char *errmsg) if(!dev->tot_sectors) /* tot_sectors not set, do nothing */ return 0; - + mt_off_t offs_sectors = offset / (dev->sector_size ? dev->sector_size : 512); if(offs_sectors > 0 && dev->tot_sectors < offs_sectors) { diff --git a/streamcache.c b/streamcache.c index b0a8c4a..be50248 100644 --- a/streamcache.c +++ b/streamcache.c @@ -61,7 +61,7 @@ Stream_t *open_root_dir(char drive, int flags, int *isRop) init_streamcache(); drive = (char)toupper(drive); - + /* open the drive */ if(fss[(unsigned char)drive]) Fs = fss[(unsigned char)drive]; diff --git a/sysincludes.h b/sysincludes.h index 989b1cc..958ac61 100644 --- a/sysincludes.h +++ b/sysincludes.h @@ -53,7 +53,7 @@ #endif -/* On AIX, we have to prefer strings.h, as string.h lacks a prototype +/* On AIX, we have to prefer strings.h, as string.h lacks a prototype * for strcasecmp. On most other architectures, it's string.h which seems * to be more complete */ #if (defined OS_aix && defined HAVE_STRINGS_H) @@ -167,7 +167,7 @@ typedef unsigned char _Bool; # define false 0 # define true 1 # define __bool_true_false_are_defined 1 -#endif +#endif #ifdef HAVE_INTTYPES_H # include @@ -483,7 +483,7 @@ char *strerror(int errno); #endif #ifndef HAVE_ATEXIT -int atexit(void (*function)(void)); +int atexit(void (*function)(void)); #ifndef HAVE_ON_EXIT void myexit(int code) NORETURN; @@ -538,7 +538,7 @@ void _stripexe(char *filename); #ifndef __STDC__ # ifndef signed # define signed /**/ -# endif +# endif #endif /* !__STDC__ */ diff --git a/tty.c b/tty.c index 3babeb3..a085104 100644 --- a/tty.c +++ b/tty.c @@ -20,7 +20,7 @@ #include "mtools.h" static FILE *tty=NULL; -static int notty=0; +static int notty=0; static int ttyfd=-1; #ifdef USE_RAWTERM int mtools_raw_tty = 1; @@ -95,7 +95,7 @@ static void tty_time_out(int dummy UNUSEDP) int exit_code; signal(SIGALRM, SIG_IGN); if(tty && need_tty_reset) - restore_tty (&in_orig); + restore_tty (&in_orig); #ifdef future if (fail_on_timeout) exit_code=SHFAIL; @@ -118,7 +118,7 @@ static void tty_time_out(int dummy UNUSEDP) } static void cleanup_tty(void) -{ +{ if(tty && need_tty_reset) { restore_tty (&in_orig); setup_signal(); @@ -143,7 +143,7 @@ static void set_raw_tty(int mode) setup_signal(); signal (SIGALRM, tty_time_out); - + /* Change STDIN settings to raw */ gtty (STDIN, &in_raw); @@ -153,7 +153,7 @@ static void set_raw_tty(int mode) #else in_raw.c_lflag &= ~0u ^ ICANON; in_raw.c_cc[VMIN]=1; - in_raw.c_cc[VTIME]=0; + in_raw.c_cc[VTIME]=0; #endif stty (STDIN, &in_raw); } else { diff --git a/unixdir.c b/unixdir.c index 7e32d98..600c6d3 100644 --- a/unixdir.c +++ b/unixdir.c @@ -66,7 +66,7 @@ static int dir_free(Stream_t *Stream) return 0; } -static Class_t DirClass = { +static Class_t DirClass = { 0, /* read */ 0, /* write */ 0, /* flush */ @@ -82,8 +82,8 @@ static Class_t DirClass = { #define FCHDIR_MODE #endif -int unix_dir_loop(Stream_t *Stream, MainParam_t *mp); -int unix_loop(Stream_t *Stream, MainParam_t *mp, char *arg, +int unix_dir_loop(Stream_t *Stream, MainParam_t *mp); +int unix_loop(Stream_t *Stream, MainParam_t *mp, char *arg, int follow_dir_link); int unix_dir_loop(Stream_t *Stream, MainParam_t *mp) @@ -109,7 +109,7 @@ int unix_dir_loop(Stream_t *Stream, MainParam_t *mp) if(isSpecial(entry->d_name)) continue; #ifndef FCHDIR_MODE - newName = malloc(strlen(This->pathname) + 1 + + newName = malloc(strlen(This->pathname) + 1 + strlen(entry->d_name) + 1); if(!newName) { ret = ERROR_ONE; @@ -139,7 +139,7 @@ Stream_t *OpenDir(const char *filename) Dir_t *This; This = New(Dir_t); - + This->Class = &DirClass; This->Next = 0; This->refs = 1; diff --git a/vfat.c b/vfat.c index 4e32052..1761e14 100644 --- a/vfat.c +++ b/vfat.c @@ -43,7 +43,7 @@ static void autorename(char *name, unsigned int seqnum=0, maxseq=0; char tmp; char *p; - + #ifdef DEBUG printf("In autorename for name=%s.\n", name); #endif @@ -155,7 +155,7 @@ void clear_vfat(struct vfat_state *v) * and adding in each character, from left to right, padding both * the name and extension to maximum length with spaces and skipping * the "." (hence always summing exactly 11 characters). - * + * * This exact algorithm is required in order to remain compatible * with Microsoft Windows-95 and Microsoft Windows NT 3.5. * Thanks to Jeffrey Richter of Microsoft Systems Journal for @@ -197,7 +197,7 @@ static __inline__ void check_vfat(struct vfat_state *v, struct directory *dir) if (v->sum != sum_shortname(&dn)) return; - + if( (v->status & ((1<subentries) - 1)) != (1<subentries) - 1) return; /* missing entries */ @@ -284,9 +284,9 @@ int write_vfat(Stream_t *Dir, dos_name_t *shortname, char *longname, num_vses = (uint8_t)((wlen + VSE_NAMELEN - 1)/VSE_NAMELEN); for (vse_id = num_vses; vse_id; --vse_id) { int end = 0; - + c = wlongname + (vse_id - 1) * VSE_NAMELEN; - + c += unicode_write(c, vse->text1, VSE1SIZE, &end); c += unicode_write(c, vse->text2, VSE2SIZE, &end); c += unicode_write(c, vse->text3, VSE3SIZE, &end); @@ -297,7 +297,7 @@ int write_vfat(Stream_t *Dir, dos_name_t *shortname, char *longname, longname, vse_id, longname + (vse_id-1) * VSE_NAMELEN, start + num_vses - vse_id, start + num_vses); #endif - + entry.entry = start + num_vses - vse_id; low_level_dir_write(&entry); } @@ -348,15 +348,15 @@ void dir_write(direntry_t *entry) * The following function translates a series of vfat_subentries into * data suitable for a dircache entry */ -static __inline__ void parse_vses(direntry_t *entry, +static __inline__ void parse_vses(direntry_t *entry, struct vfat_state *v) { struct vfat_subentry *vse; unsigned char id, last_flag; wchar_t *c; - + vse = (struct vfat_subentry *) &entry->dir; - + id = vse->id & VSE_MASK; last_flag = (vse->id & VSE_LAST); if (id > MAX_VFAT_SUBENTRIES) { @@ -364,7 +364,7 @@ static __inline__ void parse_vses(direntry_t *entry, id, entry->entry); return; } - + /* 950819: This code enforced finding the VSEs in order. Well, Win95 * likes to write them in *reverse* order for some bizarre reason! So * we pretty much have to tolerate them coming in any possible order. @@ -384,17 +384,17 @@ static __inline__ void parse_vses(direntry_t *entry, clear_vfat(v); v->sum = vse->sum; } - + #ifdef DEBUG if(v->status & (1 << (id-1))) fprintf(stderr, "parse_vses: duplicate VSE %d\n", vse->id); #endif - + v->status |= 1 << (id-1); if(last_flag) v->subentries = id; - + #ifdef DEBUG if (id > v->subentries) /* simple test to detect entries preceding @@ -411,7 +411,7 @@ static __inline__ void parse_vses(direntry_t *entry, #ifdef DEBUG printf("Read VSE %d at %d, subentries=%d, = (%13ls).\n", id,entry->entry,v->subentries,&(v->name[VSE_NAMELEN * (id-1)])); -#endif +#endif if (last_flag) *c = '\0'; /* Null terminate long name */ } @@ -447,7 +447,7 @@ static dirCacheEntry_t *vfat_lookup_loop_common(doscp_t *cp, endmarkSeen); return addEndEntry(cache, direntry->entry); } - + if (endmarkSeen || direntry->dir.name[0] == ENDMARK){ /* the end of the directory */ if(lookForFreeSpace) { @@ -463,11 +463,11 @@ static dirCacheEntry_t *vfat_lookup_loop_common(doscp_t *cp, /* the main entry */ break; } - + /* If we get here, it's a short name FAT entry, maybe erased. * thus we should make sure that the vfat structure will be * cleared before the next loop run */ - + /* deleted file */ if (direntry->dir.name[0] == DELMARK) { return addFreeEntry(cache, initpos, @@ -843,7 +843,7 @@ int lookupForInsert(Stream_t *Dir, return 6; /* Success */ /* Need more room. Can we grow the directory? */ - if(!isRootDir(Dir)) + if(!isRootDir(Dir)) return 5; /* OK, try to grow the directory */ fprintf(stderr, "No directory slots\n"); diff --git a/xdf_io.c b/xdf_io.c index 3d7b69b..27577bf 100644 --- a/xdf_io.c +++ b/xdf_io.c @@ -72,7 +72,7 @@ static struct { typedef struct { unsigned char begin; /* where it begins */ - unsigned char end; + unsigned char end; unsigned char sector; unsigned char sizecode; @@ -92,10 +92,10 @@ typedef struct Xdf_t { int fd; char *buffer; - + bool track_valid; uint8_t current_track; - + sector_map_t *map; uint32_t track_size; @@ -142,7 +142,7 @@ static int analyze_reply(RawRequest_t *raw_cmd, int do_print) } } } - + static int send_cmd(int fd, RawRequest_t *raw_cmd, int nr, @@ -150,7 +150,7 @@ static int send_cmd(int fd, RawRequest_t *raw_cmd, int nr, { int j; int ret=-1; - + if(!nr) return 0; for (j=0; j< retries; j++){ @@ -185,7 +185,7 @@ static int add_to_request(Xdf_t *This, unsigned char ptr, { #if 0 if(direction == MT_WRITE) { - printf("writing %d: %u %d %d %d [%02x]\n", + printf("writing %d: %u %d %d %d [%02x]\n", ptr, This->current_track, REC.head, REC.sector, REC.sizecode, *(This->buffer + ptr * This->sector_size)); @@ -193,14 +193,14 @@ static int add_to_request(Xdf_t *This, unsigned char ptr, printf(" load %d.%u\n", This->current_track, ptr); #endif if(REC.phantom) { - if(direction== MT_READ) + if(direction== MT_READ) memset(This->buffer + ptr * This->sector_size, 0, 128u << REC.sizecode); return 0; } - + if(*nr && - RR_SIZECODE(request+(*nr)-1) == REC.sizecode && + RR_SIZECODE(request+(*nr)-1) == REC.sizecode && compactify->head == REC.head && compactify->ptr + 1 == ptr && compactify->sector +1 == REC.sector) { @@ -212,7 +212,7 @@ static int add_to_request(Xdf_t *This, unsigned char ptr, RR_SETDRIVE(request+(*nr), This->drive); RR_SETRATE(request+(*nr), This->rate); RR_SETTRACK(request+(*nr), This->current_track); - RR_SETPTRACK(request+(*nr), + RR_SETPTRACK(request+(*nr), This->current_track << This->stretch); RR_SETHEAD(request+(*nr), REC.head); RR_SETSECTOR(request+(*nr), REC.sector); @@ -257,7 +257,7 @@ static __inline__ int try_flush_dirty(Xdf_t *This) if(!This->track_valid) return 0; - + nr = 0; for(ptr=0; ptr < This->last_sector; ptr=REC.end) if(REC.dirty) @@ -285,11 +285,11 @@ static __inline__ int try_flush_dirty(Xdf_t *This) static int flush_dirty(Xdf_t *This) -{ +{ int ret; while((ret = try_flush_dirty(This))) { - if(ret < 0) + if(ret < 0) return ret; } return 0; @@ -305,7 +305,7 @@ static ssize_t load_data(Xdf_t *This, off_t ibegin, off_t iend, Compactify_t compactify; unsigned char begin, end; adjust_bounds(This, ibegin, iend, &begin, &end); - + ptr = begin; nr = 0; for(ptr=REC.begin; ptr < end ; ptr = REC.end) @@ -333,9 +333,9 @@ static void mark_dirty(Xdf_t *This, off_t ibegin, off_t iend) { int ptr; unsigned char begin, end; - + adjust_bounds(This, ibegin, iend, &begin, &end); - + ptr = begin; for(ptr=REC.begin; ptr < end ; ptr = REC.end) { REC.valid = 1; @@ -349,7 +349,7 @@ static ssize_t load_bounds(Xdf_t *This, off_t begin, off_t end) { unsigned char lbegin, lend; - adjust_bounds(This, begin, end, &lbegin, &lend); + adjust_bounds(This, begin, end, &lbegin, &lend); if(begin != BEGIN(lbegin) * This->sector_size && end != BEGIN(lend) * This->sector_size && @@ -379,12 +379,12 @@ static void fill_boot(Xdf_t *This) REC.head = 0; REC.sector = 129; REC.phantom = 0; - + REC.begin = ptr; REC.end = ptr+1; - + REC.sizecode = 2; - + REC.valid = 0; REC.dirty = 0; This->last_sector=1; @@ -427,10 +427,10 @@ static int decompose(Xdf_t *This, mt_off_t iwhere, size_t len, sector_map_t *map; uint8_t lbegin, lend; uint32_t track_size = This->track_size * 1024; - + mt_off_t track = iwhere / track_size; uint32_t where = iwhere % track_size; - + *begin = where; if(where + len > track_size) *end = track_size; @@ -456,11 +456,11 @@ static int decompose(Xdf_t *This, mt_off_t iwhere, size_t len, for( ; ptr < lend ; ptr++) { REC.begin = lbegin; REC.end = lend; - + REC.head = map->head; REC.sector = map->size + 128; REC.sizecode = map->size; - + REC.valid = 0; REC.dirty = 0; REC.phantom = 0; @@ -476,9 +476,9 @@ static int decompose(Xdf_t *This, mt_off_t iwhere, size_t len, for(ptr=boot; ptr < 2 * This->track_size; ptr++) { REC.begin = ptr; REC.end = ptr+1; - + REC.sizecode = 2; - + REC.valid = 0; REC.dirty = 0; } @@ -491,7 +491,7 @@ static int decompose(Xdf_t *This, mt_off_t iwhere, size_t len, /* root dir */ ptr=fill_t0(This, ptr, This->RootDirSize, §or, &head); - + /* "bad sectors" at the beginning of the fs */ ptr=fill_phantoms(This, ptr, 5); @@ -511,7 +511,7 @@ static int decompose(Xdf_t *This, mt_off_t iwhere, size_t len, static ssize_t xdf_read(Stream_t *Stream, char *buf, mt_off_t where, size_t len) -{ +{ uint32_t begin, end; ssize_t ret; DeclareThis(Xdf_t); @@ -528,7 +528,7 @@ static ssize_t xdf_read(Stream_t *Stream, char *buf, } static ssize_t xdf_write(Stream_t *Stream, char *buf, mt_off_t where, size_t len) -{ +{ uint32_t begin, end; ssize_t len2; DeclareThis(Xdf_t); @@ -554,7 +554,7 @@ static int xdf_flush(Stream_t *Stream) { DeclareThis(Xdf_t); - return flush_dirty(This); + return flush_dirty(This); } static int xdf_free(Stream_t *Stream) @@ -577,7 +577,7 @@ static int check_geom(Xdf_t *This, struct device *dev) compare(dev->sectors, 46) && compare(dev->sectors, 48)) return 1; - + /* check against contradictory info from configuration file */ if(compare(dev->heads, 2)) return 1; @@ -603,7 +603,7 @@ static void set_geom(Xdf_t *This, struct device *dev) dev->tracks = 80; } -static int config_geom(Stream_t *Stream UNUSEDP, struct device *dev, +static int config_geom(Stream_t *Stream UNUSEDP, struct device *dev, struct device *orig_dev UNUSEDP) { DeclareThis(Xdf_t); @@ -614,11 +614,11 @@ static int config_geom(Stream_t *Stream UNUSEDP, struct device *dev, } static Class_t XdfClass = { - xdf_read, - xdf_write, - xdf_flush, - xdf_free, - config_geom, + xdf_read, + xdf_write, + xdf_flush, + xdf_free, + config_geom, 0, /* get_data */ 0, /* pre-allocate */ 0, /* get_dosConvert */ @@ -633,7 +633,7 @@ Stream_t *XdfOpen(struct device *dev, const char *name, union bootsector *boot; unsigned int type; uint16_t fatSize; - + if(dev && ((!SHOULD_USE_XDF(dev) && !getenv("MTOOLS_USE_XDF")) || check_geom(NULL, dev))) return NULL; @@ -678,10 +678,10 @@ Stream_t *XdfOpen(struct device *dev, const char *name, /* lock the device on writes */ if (lock_dev(This->fd, mode == O_RDWR, dev)) { #ifdef HAVE_SNPRINTF - snprintf(errmsg,199,"xdf floppy: device \"%s\" busy:", + snprintf(errmsg,199,"xdf floppy: device \"%s\" busy:", dev->name); #else - sprintf(errmsg,"xdf floppy: device \"%s\" busy:", + sprintf(errmsg,"xdf floppy: device \"%s\" busy:", dev->name); #endif goto exit_3;