1 | #ifndef MTOOLS_MTOOLS_H
|
---|
2 | #define MTOOLS_MTOOLS_H
|
---|
3 |
|
---|
4 | #include "msdos.h"
|
---|
5 |
|
---|
6 | #if defined(OS_sco3)
|
---|
7 | #define MAXPATHLEN 1024
|
---|
8 | #include <signal.h>
|
---|
9 | extern int lockf(int, int, off_t); /* SCO has no proper include file for lockf */
|
---|
10 | #endif
|
---|
11 |
|
---|
12 | #define SCSI_FLAG 1
|
---|
13 | #define PRIV_FLAG 2
|
---|
14 | #define NOLOCK_FLAG 4
|
---|
15 | #define USE_XDF_FLAG 8
|
---|
16 | #define MFORMAT_ONLY_FLAG 16
|
---|
17 | #define VOLD_FLAG 32
|
---|
18 | #define FLOPPYD_FLAG 64
|
---|
19 | #define FILTER_FLAG 128
|
---|
20 |
|
---|
21 | #define IS_SCSI(x) ((x) && ((x)->misc_flags & SCSI_FLAG))
|
---|
22 | #define IS_PRIVILEGED(x) ((x) && ((x)->misc_flags & PRIV_FLAG))
|
---|
23 | #define IS_NOLOCK(x) ((x) && ((x)->misc_flags & NOLOCK_FLAG))
|
---|
24 | #define IS_MFORMAT_ONLY(x) ((x) && ((x)->misc_flags & MFORMAT_ONLY_FLAG))
|
---|
25 | #define SHOULD_USE_VOLD(x) ((x)&& ((x)->misc_flags & VOLD_FLAG))
|
---|
26 | #define SHOULD_USE_XDF(x) ((x)&& ((x)->misc_flags & USE_XDF_FLAG))
|
---|
27 |
|
---|
28 | typedef struct device {
|
---|
29 | const char *name; /* full path to device */
|
---|
30 |
|
---|
31 | char *drive; /* the drive letter / device name */
|
---|
32 | int fat_bits; /* FAT encoding scheme */
|
---|
33 |
|
---|
34 | unsigned int mode; /* any special open() flags */
|
---|
35 | unsigned int tracks; /* tracks */
|
---|
36 | unsigned int heads; /* heads */
|
---|
37 | unsigned int sectors; /* sectors */
|
---|
38 | unsigned int hidden; /* number of hidden sectors. Used for
|
---|
39 | * mformatting partitioned devices */
|
---|
40 |
|
---|
41 | off_t offset; /* skip this many bytes */
|
---|
42 |
|
---|
43 | unsigned int partition;
|
---|
44 |
|
---|
45 | unsigned int misc_flags;
|
---|
46 |
|
---|
47 | /* Linux only stuff */
|
---|
48 | unsigned int ssize;
|
---|
49 | unsigned int use_2m;
|
---|
50 |
|
---|
51 | char *precmd; /* command to be executed before opening
|
---|
52 | * the drive */
|
---|
53 |
|
---|
54 | /* internal variables */
|
---|
55 | int file_nr; /* used during parsing */
|
---|
56 | int blocksize; /* size of disk block in bytes */
|
---|
57 |
|
---|
58 | const char *cfg_filename; /* used for debugging purposes */
|
---|
59 | } device_t;
|
---|
60 |
|
---|
61 |
|
---|
62 | #ifndef OS_linux
|
---|
63 | #define BOOTSIZE 512
|
---|
64 | #else
|
---|
65 | #define BOOTSIZE 256
|
---|
66 | #endif
|
---|
67 |
|
---|
68 | #include "stream.h"
|
---|
69 |
|
---|
70 |
|
---|
71 | extern const char *short_illegals, *long_illegals;
|
---|
72 |
|
---|
73 | #define maximize(target, max) do { \
|
---|
74 | if(max < 0) { \
|
---|
75 | if(target > 0) \
|
---|
76 | target = 0; \
|
---|
77 | } else if(target > max) { \
|
---|
78 | target = max; \
|
---|
79 | } \
|
---|
80 | } while(0)
|
---|
81 |
|
---|
82 | #define minimize(target, min) do { \
|
---|
83 | if(target < min) \
|
---|
84 | target = min; \
|
---|
85 | } while(0)
|
---|
86 |
|
---|
87 | int init_geom(int fd, struct device *dev, struct device *orig_dev,
|
---|
88 | struct stat *stat);
|
---|
89 |
|
---|
90 | int readwrite_sectors(int fd, /* file descriptor */
|
---|
91 | int *drive,
|
---|
92 | int rate,
|
---|
93 | int seektrack,
|
---|
94 | int track, int head, int sector, int size, /* address */
|
---|
95 | char *data,
|
---|
96 | int bytes,
|
---|
97 | int direction,
|
---|
98 | int retries);
|
---|
99 |
|
---|
100 | int lock_dev(int fd, int mode, struct device *dev);
|
---|
101 |
|
---|
102 | char *unix_normalize (char *ans, char *name, char *ext);
|
---|
103 | char *dos_name(char *filename, int verbose, int *mangled, char *buffer);
|
---|
104 | struct directory *mk_entry(const char *filename, char attr,
|
---|
105 | unsigned int fat, size_t size, time_t date,
|
---|
106 | struct directory *ndir);
|
---|
107 | int copyfile(Stream_t *Source, Stream_t *Target);
|
---|
108 | int getfreeMinClusters(Stream_t *Stream, size_t ref);
|
---|
109 |
|
---|
110 | FILE *opentty(int mode);
|
---|
111 |
|
---|
112 | int is_dir(Stream_t *Dir, char *path);
|
---|
113 | void bufferize(Stream_t **Dir);
|
---|
114 |
|
---|
115 | int dir_grow(Stream_t *Dir, int size);
|
---|
116 | int match(const char *, const char *, char *, int, int);
|
---|
117 |
|
---|
118 | char *unix_name(char *name, char *ext, char Case, char *answer);
|
---|
119 | void *safe_malloc(size_t size);
|
---|
120 | Stream_t *open_filter(Stream_t *Next);
|
---|
121 |
|
---|
122 | extern int got_signal;
|
---|
123 | /* int do_gotsignal(char *, int);
|
---|
124 | #define got_signal do_gotsignal(__FILE__, __LINE__) */
|
---|
125 |
|
---|
126 | void setup_signal(void);
|
---|
127 |
|
---|
128 |
|
---|
129 | #define SET_INT(target, source) \
|
---|
130 | if(source)target=source
|
---|
131 |
|
---|
132 |
|
---|
133 | UNUSED(static inline int compare (long ref, long testee))
|
---|
134 | {
|
---|
135 | return (ref && ref != testee);
|
---|
136 | }
|
---|
137 |
|
---|
138 | Stream_t *GetFs(Stream_t *Fs);
|
---|
139 |
|
---|
140 | char *label_name(char *filename, int verbose,
|
---|
141 | int *mangled, char *ans);
|
---|
142 |
|
---|
143 | /* environmental variables */
|
---|
144 | extern unsigned int mtools_skip_check;
|
---|
145 | extern unsigned int mtools_fat_compatibility;
|
---|
146 | extern unsigned int mtools_ignore_short_case;
|
---|
147 | extern unsigned int mtools_no_vfat;
|
---|
148 | extern unsigned int mtools_numeric_tail;
|
---|
149 | extern unsigned int mtools_dotted_dir;
|
---|
150 | extern unsigned int mtools_twenty_four_hour_clock;
|
---|
151 | extern char *mtools_date_string;
|
---|
152 | extern unsigned int mtools_rate_0, mtools_rate_any;
|
---|
153 | extern int mtools_raw_tty;
|
---|
154 |
|
---|
155 | extern int batchmode;
|
---|
156 |
|
---|
157 | void read_config(void);
|
---|
158 | extern struct device *devices;
|
---|
159 | extern struct device const_devices[];
|
---|
160 | extern const int nr_const_devices;
|
---|
161 |
|
---|
162 | #define New(type) ((type*)(malloc(sizeof(type))))
|
---|
163 | #define Grow(adr,n,type) ((type*)(realloc((char *)adr,n*sizeof(type))))
|
---|
164 | #define Free(adr) (free((char *)adr));
|
---|
165 | #define NewArray(size,type) ((type*)(calloc((size),sizeof(type))))
|
---|
166 |
|
---|
167 | void mattrib(int argc, char **argv, int type);
|
---|
168 | void mbadblocks(int argc, char **argv, int type);
|
---|
169 | void mcat(int argc, char **argv, int type);
|
---|
170 | void mcd(int argc, char **argv, int type);
|
---|
171 | void mcopy(int argc, char **argv, int type);
|
---|
172 | void mdel(int argc, char **argv, int type);
|
---|
173 | void mdir(int argc, char **argv, int type);
|
---|
174 | void mdoctorfat(int argc, char **argv, int type);
|
---|
175 | void mdu(int argc, char **argv, int type);
|
---|
176 | void mformat(int argc, char **argv, int type);
|
---|
177 | void minfo(int argc, char **argv, int type);
|
---|
178 | void mlabel(int argc, char **argv, int type);
|
---|
179 | void mmd(int argc, char **argv, int type);
|
---|
180 | void mmount(int argc, char **argv, int type);
|
---|
181 | void mmove(int argc, char **argv, int type);
|
---|
182 | void mpartition(int argc, char **argv, int type);
|
---|
183 | void mshowfat(int argc, char **argv, int mtype);
|
---|
184 | void mtoolstest(int argc, char **argv, int type);
|
---|
185 | void mzip(int argc, char **argv, int type);
|
---|
186 |
|
---|
187 | extern int noPrivileges;
|
---|
188 | void init_privs(void);
|
---|
189 | void reclaim_privs(void);
|
---|
190 | void drop_privs(void);
|
---|
191 | void destroy_privs(void);
|
---|
192 | uid_t get_real_uid(void);
|
---|
193 | void closeExec(int fd);
|
---|
194 |
|
---|
195 | extern const char *progname;
|
---|
196 |
|
---|
197 | void precmd(struct device *dev);
|
---|
198 |
|
---|
199 | void print_sector(char *message, unsigned char *data, int size);
|
---|
200 | time_t getTimeNow(time_t *now);
|
---|
201 |
|
---|
202 | #ifdef USING_NEW_VOLD
|
---|
203 | char *getVoldName(struct device *dev, char *name);
|
---|
204 | #endif
|
---|
205 |
|
---|
206 |
|
---|
207 | Stream_t *OpenDir(Stream_t *Parent, const char *filename);
|
---|
208 | /* int unix_dir_loop(Stream_t *Stream, MainParam_t *mp);
|
---|
209 | int unix_loop(MainParam_t *mp, char *arg); */
|
---|
210 |
|
---|
211 | struct dirCache_t **getDirCacheP(Stream_t *Stream);
|
---|
212 | int isRootDir(Stream_t *Stream);
|
---|
213 | unsigned int getStart(Stream_t *Dir, struct directory *dir);
|
---|
214 | unsigned int countBlocks(Stream_t *Dir, unsigned int block);
|
---|
215 | char *getDrive(Stream_t *Stream);
|
---|
216 |
|
---|
217 |
|
---|
218 | void printOom(void);
|
---|
219 | int ask_confirmation(const char *, const char *, const char *);
|
---|
220 | char *get_homedir(void);
|
---|
221 | #define EXPAND_BUF 2048
|
---|
222 | const char *expand(const char *, char *);
|
---|
223 | const char *fix_mcwd(char *);
|
---|
224 | FILE *open_mcwd(const char *mode);
|
---|
225 | void unlink_mcwd(void);
|
---|
226 | char *skip_drive(const char *path);
|
---|
227 | char *get_drive(const char *path, const char *def);
|
---|
228 |
|
---|
229 | int safePopenOut(char **command, char *output, int len);
|
---|
230 |
|
---|
231 | #define ROUND_DOWN(value, grain) ((value) - (value) % (grain))
|
---|
232 | #define ROUND_UP(value, grain) ROUND_DOWN((value) + (grain)-1, (grain))
|
---|
233 |
|
---|
234 | #endif
|
---|