diff options
Diffstat (limited to 'mtools.h')
-rw-r--r-- | mtools.h | 144 |
1 files changed, 29 insertions, 115 deletions
@@ -17,88 +17,16 @@ * along with Mtools. If not, see <http://www.gnu.org/licenses/>. */ #include "msdos.h" - +#include "llong.h" typedef struct dos_name_t dos_name_t; #if defined(OS_sco3) #define MAXPATHLEN 1024 #include <signal.h> extern int lockf(int, int, off_t); /* SCO has no proper include file for lockf */ -#endif - -#define SCSI_FLAG 0x001u -#define PRIV_FLAG 0x002u -#define NOLOCK_FLAG 0x004u -#define USE_XDF_FLAG 0x008u -#define MFORMAT_ONLY_FLAG 0x010u -#define VOLD_FLAG 0x020u -#define FLOPPYD_FLAG 0x040u -#define FILTER_FLAG 0x080u -#define SWAP_FLAG 0x100u - -#define IS_SCSI(x) ((x) && ((x)->misc_flags & SCSI_FLAG)) -#define IS_PRIVILEGED(x) ((x) && ((x)->misc_flags & PRIV_FLAG)) -#define IS_NOLOCK(x) ((x) && ((x)->misc_flags & NOLOCK_FLAG)) -#define IS_MFORMAT_ONLY(x) ((x) && ((x)->misc_flags & MFORMAT_ONLY_FLAG)) -#define SHOULD_USE_VOLD(x) ((x)&& ((x)->misc_flags & VOLD_FLAG)) -#define SHOULD_USE_XDF(x) ((x)&& ((x)->misc_flags & USE_XDF_FLAG)) -#define DO_SWAP(x) ((x) && ((x)->misc_flags & SWAP_FLAG)) - -typedef struct device { - const char *name; /* full path to device */ - - char drive; /* the drive letter */ - int fat_bits; /* FAT encoding scheme */ - - int mode; /* any special open() flags */ - unsigned int tracks; /* tracks */ - uint16_t heads; /* heads */ - uint16_t sectors; /* sectors */ - unsigned int hidden; /* number of hidden sectors. Used for - * mformatting partitioned devices */ - - off_t offset; /* skip this many bytes */ - - unsigned int partition; - - unsigned int misc_flags; - - /* Linux only stuff */ - uint8_t ssize; - unsigned int use_2m; - - char *precmd; /* command to be executed before opening - * the drive */ - - /* internal variables */ - int file_nr; /* used during parsing */ - unsigned int blocksize; /* size of disk block in bytes */ - - int codepage; /* codepage for shortname encoding */ - - const char *cfg_filename; /* used for debugging purposes */ -} device_t; - -struct OldDos_t { - unsigned int tracks; - uint16_t sectors; - uint16_t heads; - - unsigned int dir_len; - unsigned int cluster_size; - unsigned int fat_len; - - uint8_t media; -}; - -extern struct OldDos_t *getOldDosBySize(size_t size); -extern struct OldDos_t *getOldDosByMedia(int media); -extern struct OldDos_t *getOldDosByParams(unsigned int tracks, - unsigned int heads, - unsigned int sectors, - unsigned int dir_len, - unsigned int cluster_size); -int setDeviceFromOldDos(int media, struct device *dev); +#endif + + #ifndef OS_linux @@ -120,72 +48,62 @@ extern const char *short_illegals, *long_illegals; } \ } while(0) -#define smaximize(target, max) do { \ - if(max < 0) { \ - if(target > 0) \ - target = 0; \ - } else if(target > max) { \ - target = max; \ - } \ -} while(0) - #define sizemaximize(target, max) do { \ if(max < 0) { \ if(target > 0) \ target = 0; \ } else if(target > (size_t) max) { \ - target = max; \ + target = (size_t) max; \ } \ } while(0) #define minimize(target, min) do { \ if(target < min) \ target = min; \ -} while(0) +} while(0) -int init_geom(int fd, struct device *dev, struct device *orig_dev, - struct MT_STAT *statbuf); +#ifdef OS_linux +int get_sector_size(int fd); +#endif int readwrite_sectors(int fd, /* file descriptor */ int *drive, int rate, int seektrack, int track, int head, int sector, int size, /* address */ - char *data, + char *data, int bytes, int direction, int retries); -int lock_dev(int fd, int mode, struct device *dev); - char *unix_normalize (doscp_t *cp, char *ans, struct dos_name_t *dn, size_t ans_size); void dos_name(doscp_t *cp, const char *filename, int verbose, int *mangled, struct dos_name_t *); struct directory *mk_entry(const dos_name_t *filename, unsigned char attr, - unsigned int fat, size_t size, time_t date, + unsigned int fat, uint32_t size, time_t date, struct directory *ndir); struct directory *mk_entry_from_base(const char *base, unsigned char attr, - unsigned int fat, size_t size, time_t date, + unsigned int fat, uint32_t size, time_t date, struct directory *ndir); -int copyfile(Stream_t *Source, Stream_t *Target); -int getfreeMinClusters(Stream_t *Stream, size_t ref); +mt_off_t copyfile(Stream_t *Source, Stream_t *Target); +int getfreeMinClusters(Stream_t *Stream, uint32_t ref); FILE *opentty(int mode); int is_dir(Stream_t *Dir, char *path); -void bufferize(Stream_t **Dir); int dir_grow(Stream_t *Dir, int size); int match(const wchar_t *, const wchar_t *, wchar_t *, int, int); wchar_t *unix_name(doscp_t *fromDos, - const char *base, const char *ext, char Case, + const char *base, const char *ext, uint8_t Case, wchar_t *answer); void *safe_malloc(size_t size); -Stream_t *open_filter(Stream_t *Next,int convertCharset); +Stream_t *open_dos2unix(Stream_t *Next,int convertCharset); +Stream_t *open_unix2dos(Stream_t *Next,int convertCharset); extern int got_signal; /* int do_gotsignal(char *, int); @@ -204,11 +122,7 @@ void restore_interrupts(saved_sig_state *ss); #define SET_INT(target, source) \ if(source)target=source - -UNUSED(static __inline__ int compare (long ref, long testee)) -{ - return (ref && ref != testee); -} +#define compare(ref,testee) ((ref) && (ref) != (testee)) UNUSED(static __inline__ char ch_toupper(char ch)) { @@ -235,13 +149,17 @@ UNUSED(static __inline__ void init_random(void)) srandom((unsigned int)time (0)); } +UNUSED(static __inline__ size_t ptrdiff (const char *end, const char *begin)) +{ + return (size_t) (end-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 */ @@ -264,7 +182,10 @@ char get_default_drive(void); void set_cmd_line_image(char *img); void check_number_parse_errno(char c, const char *optarg, char *endptr); void read_config(void); +off_t str_to_offset_with_end(const char *str, char **endp); +mt_off_t str_to_off_with_end(const char *str, char **endp); off_t str_to_offset(char *str); +uint32_t parseSize(char *sizeStr); unsigned int strtoui(const char *nptr, char **endptr, int base); unsigned int atoui(const char *nptr); #ifndef HAVE_STRTOI @@ -278,20 +199,15 @@ uint16_t atou16(const char *str); uint32_t strtou32(const char *nptr, char **endptr, int base); uint32_t atou32(const char *str); -extern struct device *devices; -extern struct device const_devices[]; -extern const unsigned int nr_const_devices; - #define New(type) ((type*)(calloc(1,sizeof(type)))) #define Grow(adr,n,type) ((type*)(realloc((char *)adr,n*sizeof(type)))) -#define Free(adr) (free((char *)adr)); +#define Free(adr) (free((char *)adr)) #define NewArray(size,type) ((type*)(calloc((size),sizeof(type)))) void mattrib(int argc, char **argv, int type); void mbadblocks(int argc, char **argv, int type); void mcat(int argc, char **argv, int type); void mcd(int argc, char **argv, int type); -void mclasserase(int argc, char **argv, int type); void mcopy(int argc, char **argv, int type); void mdel(int argc, char **argv, int type); void mdir(int argc, char **argv, int type); @@ -319,8 +235,6 @@ void closeExec(int fd); extern const char *progname; -void precmd(struct device *dev); - void print_sector(const char *message, unsigned char *data, int size); time_t getTimeNow(time_t *now); @@ -330,7 +244,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); |