source: trunk/minix/commands/i386/mtools-3.9.7/mtools.h@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 6.5 KB
Line 
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>
9extern 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
28typedef 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
71extern 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
87int init_geom(int fd, struct device *dev, struct device *orig_dev,
88 struct stat *stat);
89
90int 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
100int lock_dev(int fd, int mode, struct device *dev);
101
102char *unix_normalize (char *ans, char *name, char *ext);
103char *dos_name(char *filename, int verbose, int *mangled, char *buffer);
104struct directory *mk_entry(const char *filename, char attr,
105 unsigned int fat, size_t size, time_t date,
106 struct directory *ndir);
107int copyfile(Stream_t *Source, Stream_t *Target);
108int getfreeMinClusters(Stream_t *Stream, size_t ref);
109
110FILE *opentty(int mode);
111
112int is_dir(Stream_t *Dir, char *path);
113void bufferize(Stream_t **Dir);
114
115int dir_grow(Stream_t *Dir, int size);
116int match(const char *, const char *, char *, int, int);
117
118char *unix_name(char *name, char *ext, char Case, char *answer);
119void *safe_malloc(size_t size);
120Stream_t *open_filter(Stream_t *Next);
121
122extern int got_signal;
123/* int do_gotsignal(char *, int);
124#define got_signal do_gotsignal(__FILE__, __LINE__) */
125
126void setup_signal(void);
127
128
129#define SET_INT(target, source) \
130if(source)target=source
131
132
133UNUSED(static inline int compare (long ref, long testee))
134{
135 return (ref && ref != testee);
136}
137
138Stream_t *GetFs(Stream_t *Fs);
139
140char *label_name(char *filename, int verbose,
141 int *mangled, char *ans);
142
143/* environmental variables */
144extern unsigned int mtools_skip_check;
145extern unsigned int mtools_fat_compatibility;
146extern unsigned int mtools_ignore_short_case;
147extern unsigned int mtools_no_vfat;
148extern unsigned int mtools_numeric_tail;
149extern unsigned int mtools_dotted_dir;
150extern unsigned int mtools_twenty_four_hour_clock;
151extern char *mtools_date_string;
152extern unsigned int mtools_rate_0, mtools_rate_any;
153extern int mtools_raw_tty;
154
155extern int batchmode;
156
157void read_config(void);
158extern struct device *devices;
159extern struct device const_devices[];
160extern 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
167void mattrib(int argc, char **argv, int type);
168void mbadblocks(int argc, char **argv, int type);
169void mcat(int argc, char **argv, int type);
170void mcd(int argc, char **argv, int type);
171void mcopy(int argc, char **argv, int type);
172void mdel(int argc, char **argv, int type);
173void mdir(int argc, char **argv, int type);
174void mdoctorfat(int argc, char **argv, int type);
175void mdu(int argc, char **argv, int type);
176void mformat(int argc, char **argv, int type);
177void minfo(int argc, char **argv, int type);
178void mlabel(int argc, char **argv, int type);
179void mmd(int argc, char **argv, int type);
180void mmount(int argc, char **argv, int type);
181void mmove(int argc, char **argv, int type);
182void mpartition(int argc, char **argv, int type);
183void mshowfat(int argc, char **argv, int mtype);
184void mtoolstest(int argc, char **argv, int type);
185void mzip(int argc, char **argv, int type);
186
187extern int noPrivileges;
188void init_privs(void);
189void reclaim_privs(void);
190void drop_privs(void);
191void destroy_privs(void);
192uid_t get_real_uid(void);
193void closeExec(int fd);
194
195extern const char *progname;
196
197void precmd(struct device *dev);
198
199void print_sector(char *message, unsigned char *data, int size);
200time_t getTimeNow(time_t *now);
201
202#ifdef USING_NEW_VOLD
203char *getVoldName(struct device *dev, char *name);
204#endif
205
206
207Stream_t *OpenDir(Stream_t *Parent, const char *filename);
208/* int unix_dir_loop(Stream_t *Stream, MainParam_t *mp);
209int unix_loop(MainParam_t *mp, char *arg); */
210
211struct dirCache_t **getDirCacheP(Stream_t *Stream);
212int isRootDir(Stream_t *Stream);
213unsigned int getStart(Stream_t *Dir, struct directory *dir);
214unsigned int countBlocks(Stream_t *Dir, unsigned int block);
215char *getDrive(Stream_t *Stream);
216
217
218void printOom(void);
219int ask_confirmation(const char *, const char *, const char *);
220char *get_homedir(void);
221#define EXPAND_BUF 2048
222const char *expand(const char *, char *);
223const char *fix_mcwd(char *);
224FILE *open_mcwd(const char *mode);
225void unlink_mcwd(void);
226char *skip_drive(const char *path);
227char *get_drive(const char *path, const char *def);
228
229int 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
Note: See TracBrowser for help on using the repository browser.