71b8a956da1581db392b612409a28f68c8c91979
[openwrt/staging/chunkeey.git] / tools / dosfstools / patches / 0001-Add-OSX-support.patch
1 From 92e55f1d1404e823b0a5fd6d0ea0b962de247e31 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= <noltari@gmail.com>
3 Date: Wed, 25 Feb 2015 17:00:32 +0100
4 Subject: [PATCH] Add OSX support
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
10 ---
11 Makefile | 16 +-
12 src/boot.c | 1 +
13 src/common.h | 54 ++++-
14 src/file.c | 9 +-
15 src/file.h | 2 +
16 src/fsck.fat.h | 11 -
17 src/io.c | 4 +-
18 src/linux/fd.h | 383 ++++++++++++++++++++++++++++++
19 src/linux/fs.h | 206 ++++++++++++++++
20 src/linux/hdreg.h | 644 +++++++++++++++++++++++++++++++++++++++++++++++++++
21 src/linux/magic.h | 76 ++++++
22 src/linux/msdos_fs.h | 201 ++++++++++++++++
23 src/mkfs.fat.c | 32 ++-
24 13 files changed, 1603 insertions(+), 36 deletions(-)
25 create mode 100644 src/linux/fd.h
26 create mode 100644 src/linux/fs.h
27 create mode 100644 src/linux/hdreg.h
28 create mode 100644 src/linux/magic.h
29 create mode 100644 src/linux/msdos_fs.h
30
31 diff --git a/Makefile b/Makefile
32 index 3cbdb76..b86111d 100644
33 --- a/Makefile
34 +++ b/Makefile
35 @@ -27,10 +27,16 @@ SBINDIR = $(PREFIX)/sbin
36 DOCDIR = $(PREFIX)/share/doc
37 MANDIR = $(PREFIX)/share/man
38
39 +UNAME_S := $(shell uname -s)
40 +ifeq ($(UNAME_S),Darwin)
41 + CFLAGS += -D__osx__
42 + LDLIBS += -liconv
43 +endif
44 +
45 #OPTFLAGS = -O2 -fomit-frame-pointer -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
46 OPTFLAGS = -O2 -fomit-frame-pointer -D_GNU_SOURCE $(shell getconf LFS_CFLAGS)
47 #WARNFLAGS = -Wall -pedantic -std=c99
48 -WARNFLAGS = -Wall -Wextra -Wno-sign-compare -Wno-missing-field-initializers -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings
49 +WARNFLAGS = -Wall -Wextra -Wno-sign-compare -Wno-missing-field-initializers -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings -Wimplicit-function-declaration
50 DEBUGFLAGS = -g
51 CFLAGS += $(OPTFLAGS) $(WARNFLAGS) $(DEBUGFLAGS)
52
53 @@ -62,7 +68,8 @@ install-man:
54 for MANPAGE in manpages/en/*; \
55 do \
56 SECTION="8"; \
57 - install -D -m 0644 $${MANPAGE} $(DESTDIR)/$(MANDIR)/man$${SECTION}/$$(basename $${MANPAGE}); \
58 + mkdir -p $(DESTDIR)/$(MANDIR)/man$${SECTION}/; \
59 + install -m 0644 $${MANPAGE} $(DESTDIR)/$(MANDIR)/man$${SECTION}/$$(basename $${MANPAGE}); \
60 done
61
62 for LANGUAGE in $(LANGUAGES); \
63 @@ -70,7 +77,8 @@ install-man:
64 for MANPAGE in manpages/$${LANGUAGE}/*; \
65 do \
66 SECTION="8"; \
67 - install -D -m 0644 $${MANPAGE} $(DESTDIR)/$(MANDIR)/$${LANGUAGE}/man$${SECTION}/$$(basename $${MANPAGE} .$${LANGUAGE}.$${SECTION}).$${SECTION}; \
68 + mkdir -p $(DESTDIR)/$(MANDIR)/$${LANGUAGE}/man$${SECTION}/; \
69 + install -m 0644 $${MANPAGE} $(DESTDIR)/$(MANDIR)/$${LANGUAGE}/man$${SECTION}/$$(basename $${MANPAGE} .$${LANGUAGE}.$${SECTION}).$${SECTION}; \
70 done; \
71 done
72 install-symlinks: install-bin install-man
73 @@ -127,7 +135,7 @@ uninstall-man:
74 for MANPAGE in manpages/en/*; \
75 do \
76 SECTION="8"; \
77 - rm -f $(DESTDIR)/$(MANDIR}/man$${SECTION}/$$(basename $${MANPAGE} .en.$${SECTION}).$${SECTION}; \
78 + rm -f $(DESTDIR)/$(MANDIR)/man$${SECTION}/$$(basename $${MANPAGE} .en.$${SECTION}).$${SECTION}; \
79 done
80
81 for LANGUAGE in $(LANGUAGES); \
82 diff --git a/src/boot.c b/src/boot.c
83 index be7bfb7..0c8b273 100644
84 --- a/src/boot.c
85 +++ b/src/boot.c
86 @@ -31,6 +31,7 @@
87 #include <time.h>
88
89 #include "common.h"
90 +#include "linux/msdos_fs.h"
91 #include "fsck.fat.h"
92 #include "fat.h"
93 #include "io.h"
94 diff --git a/src/common.h b/src/common.h
95 index b127f63..e16c00c 100644
96 --- a/src/common.h
97 +++ b/src/common.h
98 @@ -20,11 +20,61 @@
99 can be found in /usr/share/common-licenses/GPL-3 file.
100 */
101
102 -#include <asm/types.h>
103 -
104 #ifndef _COMMON_H
105 #define _COMMON_H
106
107 +/* from linux/types.h */
108 +#if defined(__linux__)
109 + #include <linux/types.h>
110 +#elif defined(__osx__)
111 + #include <stdint.h>
112 +
113 + typedef uint8_t __u8;
114 + typedef uint16_t __u16;
115 + typedef uint32_t __u32;
116 + typedef uint64_t __u64;
117 +
118 + typedef int16_t __le16;
119 + typedef int32_t __le32;
120 +
121 + /* from linux stdio.h */
122 + #ifndef loff_t
123 + typedef long long loff_t;
124 + #endif /* loff_t */
125 +
126 + #ifndef off64_t
127 + #ifdef _LP64
128 + typedef off_t off64_t;
129 + #else
130 + typedef __longlong_t off64_t;
131 + #endif /* _LP64 */
132 + #endif /* off64_t */
133 +
134 + /* from endian.h */
135 + #if defined(__APPLE__) && defined(__MACH__)
136 + #include <libkern/OSByteOrder.h>
137 +
138 + #define htobe16(x) OSSwapHostToBigInt16(x)
139 + #define htole16(x) OSSwapHostToLittleInt16(x)
140 + #define be16toh(x) OSSwapBigToHostInt16(x)
141 + #define le16toh(x) OSSwapLittleToHostInt16(x)
142 +
143 + #define htobe32(x) OSSwapHostToBigInt32(x)
144 + #define htole32(x) OSSwapHostToLittleInt32(x)
145 + #define be32toh(x) OSSwapBigToHostInt32(x)
146 + #define le32toh(x) OSSwapLittleToHostInt32(x)
147 +
148 + #define htobe64(x) OSSwapHostToBigInt64(x)
149 + #define htole64(x) OSSwapHostToLittleInt64(x)
150 + #define be64toh(x) OSSwapBigToHostInt64(x)
151 + #define le64toh(x) OSSwapLittleToHostInt64(x)
152 +
153 + #ifndef lseek64
154 + #define lseek64 lseek
155 + #endif /* lseek64 */
156 + #endif /* __APPLE__ && __MACH__ */
157 +#endif
158 +
159 void die(const char *msg, ...) __attribute((noreturn));
160
161 /* Displays a prinf-style message and terminates the program. */
162 diff --git a/src/file.c b/src/file.c
163 index 30adcde..1c1a5f0 100644
164 --- a/src/file.c
165 +++ b/src/file.c
166 @@ -30,15 +30,8 @@
167 #include <ctype.h>
168 #include <unistd.h>
169
170 -#define _LINUX_STAT_H /* hack to avoid inclusion of <linux/stat.h> */
171 -#define _LINUX_STRING_H_ /* hack to avoid inclusion of <linux/string.h> */
172 -#define _LINUX_FS_H /* hack to avoid inclusion of <linux/fs.h> */
173 -
174 -#include <asm/types.h>
175 -
176 -#include <linux/msdos_fs.h>
177 -
178 #include "common.h"
179 +#include "linux/msdos_fs.h"
180 #include "file.h"
181 #include "charconv.h"
182
183 diff --git a/src/file.h b/src/file.h
184 index 3adfc96..f5dec16 100644
185 --- a/src/file.h
186 +++ b/src/file.h
187 @@ -23,6 +23,8 @@
188 #ifndef _FILE_H
189 #define _FILE_H
190
191 +#include "linux/msdos_fs.h"
192 +
193 typedef enum { fdt_none, fdt_drop, fdt_undelete } FD_TYPE;
194
195 typedef struct _fptr {
196 diff --git a/src/fsck.fat.h b/src/fsck.fat.h
197 index e5ade5b..274820a 100644
198 --- a/src/fsck.fat.h
199 +++ b/src/fsck.fat.h
200 @@ -28,19 +28,8 @@
201 #define _DOSFSCK_H
202
203 #include <fcntl.h>
204 -#include <sys/types.h>
205 -#define _LINUX_STAT_H /* hack to avoid inclusion of <linux/stat.h> */
206 -#define _LINUX_STRING_H_ /* hack to avoid inclusion of <linux/string.h> */
207 -#define _LINUX_FS_H /* hack to avoid inclusion of <linux/fs.h> */
208 -
209 -#include <asm/types.h>
210 -#include <asm/byteorder.h>
211 -
212 -#include <linux/msdos_fs.h>
213 -
214 #include <stddef.h>
215 #include <stdint.h>
216 -#include <endian.h>
217
218 #define VFAT_LN_ATTR (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME)
219
220 diff --git a/src/io.c b/src/io.c
221 index 3755ba5..fa96b62 100644
222 --- a/src/io.c
223 +++ b/src/io.c
224 @@ -40,10 +40,10 @@
225 #include <sys/ioctl.h>
226 #include <errno.h>
227 #include <fcntl.h>
228 -#include <linux/fd.h>
229
230 -#include "fsck.fat.h"
231 +#include "linux/fd.h"
232 #include "common.h"
233 +#include "fsck.fat.h"
234 #include "io.h"
235
236 typedef struct _change {
237 diff --git a/src/linux/fd.h b/src/linux/fd.h
238 new file mode 100644
239 index 0000000..ffe33a6
240 --- /dev/null
241 +++ b/src/linux/fd.h
242 @@ -0,0 +1,383 @@
243 +#ifndef _LINUX_FD_H
244 +#define _LINUX_FD_H
245 +
246 +#ifdef __linux__
247 +#include <linux/ioctl.h>
248 +#endif
249 +
250 +/* New file layout: Now the ioctl definitions immediately follow the
251 + * definitions of the structures that they use */
252 +
253 +/*
254 + * Geometry
255 + */
256 +struct floppy_struct {
257 + unsigned int size, /* nr of sectors total */
258 + sect, /* sectors per track */
259 + head, /* nr of heads */
260 + track, /* nr of tracks */
261 + stretch; /* bit 0 !=0 means double track steps */
262 + /* bit 1 != 0 means swap sides */
263 + /* bits 2..9 give the first sector */
264 + /* number (the LSB is flipped) */
265 +#define FD_STRETCH 1
266 +#define FD_SWAPSIDES 2
267 +#define FD_ZEROBASED 4
268 +#define FD_SECTBASEMASK 0x3FC
269 +#define FD_MKSECTBASE(s) (((s) ^ 1) << 2)
270 +#define FD_SECTBASE(floppy) ((((floppy)->stretch & FD_SECTBASEMASK) >> 2) ^ 1)
271 +
272 + unsigned char gap, /* gap1 size */
273 +
274 + rate, /* data rate. |= 0x40 for perpendicular */
275 +#define FD_2M 0x4
276 +#define FD_SIZECODEMASK 0x38
277 +#define FD_SIZECODE(floppy) (((((floppy)->rate&FD_SIZECODEMASK)>> 3)+ 2) %8)
278 +#define FD_SECTSIZE(floppy) ( (floppy)->rate & FD_2M ? \
279 + 512 : 128 << FD_SIZECODE(floppy) )
280 +#define FD_PERP 0x40
281 +
282 + spec1, /* stepping rate, head unload time */
283 + fmt_gap; /* gap2 size */
284 + const char * name; /* used only for predefined formats */
285 +};
286 +
287 +
288 +/* commands needing write access have 0x40 set */
289 +/* commands needing super user access have 0x80 set */
290 +
291 +#define FDCLRPRM _IO(2, 0x41)
292 +/* clear user-defined parameters */
293 +
294 +#define FDSETPRM _IOW(2, 0x42, struct floppy_struct)
295 +#define FDSETMEDIAPRM FDSETPRM
296 +/* set user-defined parameters for current media */
297 +
298 +#define FDDEFPRM _IOW(2, 0x43, struct floppy_struct)
299 +#define FDGETPRM _IOR(2, 0x04, struct floppy_struct)
300 +#define FDDEFMEDIAPRM FDDEFPRM
301 +#define FDGETMEDIAPRM FDGETPRM
302 +/* set/get disk parameters */
303 +
304 +
305 +#define FDMSGON _IO(2,0x45)
306 +#define FDMSGOFF _IO(2,0x46)
307 +/* issue/don't issue kernel messages on media type change */
308 +
309 +
310 +/*
311 + * Formatting (obsolete)
312 + */
313 +#define FD_FILL_BYTE 0xF6 /* format fill byte. */
314 +
315 +struct format_descr {
316 + unsigned int device,head,track;
317 +};
318 +
319 +#define FDFMTBEG _IO(2,0x47)
320 +/* begin formatting a disk */
321 +#define FDFMTTRK _IOW(2,0x48, struct format_descr)
322 +/* format the specified track */
323 +#define FDFMTEND _IO(2,0x49)
324 +/* end formatting a disk */
325 +
326 +
327 +/*
328 + * Error thresholds
329 + */
330 +struct floppy_max_errors {
331 + unsigned int
332 + abort, /* number of errors to be reached before aborting */
333 + read_track, /* maximal number of errors permitted to read an
334 + * entire track at once */
335 + reset, /* maximal number of errors before a reset is tried */
336 + recal, /* maximal number of errors before a recalibrate is
337 + * tried */
338 +
339 + /*
340 + * Threshold for reporting FDC errors to the console.
341 + * Setting this to zero may flood your screen when using
342 + * ultra cheap floppies ;-)
343 + */
344 + reporting;
345 +
346 +};
347 +
348 +#define FDSETEMSGTRESH _IO(2,0x4a)
349 +/* set fdc error reporting threshold */
350 +
351 +#define FDFLUSH _IO(2,0x4b)
352 +/* flush buffers for media; either for verifying media, or for
353 + * handling a media change without closing the file descriptor */
354 +
355 +#define FDSETMAXERRS _IOW(2, 0x4c, struct floppy_max_errors)
356 +#define FDGETMAXERRS _IOR(2, 0x0e, struct floppy_max_errors)
357 +/* set/get abortion and read_track threshold. See also floppy_drive_params
358 + * structure */
359 +
360 +
361 +typedef char floppy_drive_name[16];
362 +#define FDGETDRVTYP _IOR(2, 0x0f, floppy_drive_name)
363 +/* get drive type: 5 1/4 or 3 1/2 */
364 +
365 +
366 +/*
367 + * Drive parameters (user modifiable)
368 + */
369 +struct floppy_drive_params {
370 + signed char cmos; /* CMOS type */
371 +
372 + /* Spec2 is (HLD<<1 | ND), where HLD is head load time (1=2ms, 2=4 ms
373 + * etc) and ND is set means no DMA. Hardcoded to 6 (HLD=6ms, use DMA).
374 + */
375 + unsigned long max_dtr; /* Step rate, usec */
376 + unsigned long hlt; /* Head load/settle time, msec */
377 + unsigned long hut; /* Head unload time (remnant of
378 + * 8" drives) */
379 + unsigned long srt; /* Step rate, usec */
380 +
381 + unsigned long spinup; /* time needed for spinup (expressed
382 + * in jiffies) */
383 + unsigned long spindown; /* timeout needed for spindown */
384 + unsigned char spindown_offset; /* decides in which position the disk
385 + * will stop */
386 + unsigned char select_delay; /* delay to wait after select */
387 + unsigned char rps; /* rotations per second */
388 + unsigned char tracks; /* maximum number of tracks */
389 + unsigned long timeout; /* timeout for interrupt requests */
390 +
391 + unsigned char interleave_sect; /* if there are more sectors, use
392 + * interleave */
393 +
394 + struct floppy_max_errors max_errors;
395 +
396 + char flags; /* various flags, including ftd_msg */
397 +/*
398 + * Announce successful media type detection and media information loss after
399 + * disk changes.
400 + * Also used to enable/disable printing of overrun warnings.
401 + */
402 +
403 +#define FTD_MSG 0x10
404 +#define FD_BROKEN_DCL 0x20
405 +#define FD_DEBUG 0x02
406 +#define FD_SILENT_DCL_CLEAR 0x4
407 +#define FD_INVERTED_DCL 0x80 /* must be 0x80, because of hardware
408 + considerations */
409 +
410 + char read_track; /* use readtrack during probing? */
411 +
412 +/*
413 + * Auto-detection. Each drive type has eight formats which are
414 + * used in succession to try to read the disk. If the FDC cannot lock onto
415 + * the disk, the next format is tried. This uses the variable 'probing'.
416 + */
417 + short autodetect[8]; /* autodetected formats */
418 +
419 + int checkfreq; /* how often should the drive be checked for disk
420 + * changes */
421 + int native_format; /* native format of this drive */
422 +};
423 +
424 +enum {
425 + FD_NEED_TWADDLE_BIT, /* more magic */
426 + FD_VERIFY_BIT, /* inquire for write protection */
427 + FD_DISK_NEWCHANGE_BIT, /* change detected, and no action undertaken yet
428 + * to clear media change status */
429 + FD_UNUSED_BIT,
430 + FD_DISK_CHANGED_BIT, /* disk has been changed since last i/o */
431 + FD_DISK_WRITABLE_BIT /* disk is writable */
432 +};
433 +
434 +#define FDSETDRVPRM _IOW(2, 0x90, struct floppy_drive_params)
435 +#define FDGETDRVPRM _IOR(2, 0x11, struct floppy_drive_params)
436 +/* set/get drive parameters */
437 +
438 +
439 +/*
440 + * Current drive state (not directly modifiable by user, readonly)
441 + */
442 +struct floppy_drive_struct {
443 + unsigned long flags;
444 +/* values for these flags */
445 +#define FD_NEED_TWADDLE (1 << FD_NEED_TWADDLE_BIT)
446 +#define FD_VERIFY (1 << FD_VERIFY_BIT)
447 +#define FD_DISK_NEWCHANGE (1 << FD_DISK_NEWCHANGE_BIT)
448 +#define FD_DISK_CHANGED (1 << FD_DISK_CHANGED_BIT)
449 +#define FD_DISK_WRITABLE (1 << FD_DISK_WRITABLE_BIT)
450 +
451 + unsigned long spinup_date;
452 + unsigned long select_date;
453 + unsigned long first_read_date;
454 + short probed_format;
455 + short track; /* current track */
456 + short maxblock; /* id of highest block read */
457 + short maxtrack; /* id of highest half track read */
458 + int generation; /* how many diskchanges? */
459 +
460 +/*
461 + * (User-provided) media information is _not_ discarded after a media change
462 + * if the corresponding keep_data flag is non-zero. Positive values are
463 + * decremented after each probe.
464 + */
465 + int keep_data;
466 +
467 + /* Prevent "aliased" accesses. */
468 + int fd_ref;
469 + int fd_device;
470 + unsigned long last_checked; /* when was the drive last checked for a disk
471 + * change? */
472 +
473 + char *dmabuf;
474 + int bufblocks;
475 +};
476 +
477 +#define FDGETDRVSTAT _IOR(2, 0x12, struct floppy_drive_struct)
478 +#define FDPOLLDRVSTAT _IOR(2, 0x13, struct floppy_drive_struct)
479 +/* get drive state: GET returns the cached state, POLL polls for new state */
480 +
481 +
482 +/*
483 + * reset FDC
484 + */
485 +enum reset_mode {
486 + FD_RESET_IF_NEEDED, /* reset only if the reset flags is set */
487 + FD_RESET_IF_RAWCMD, /* obsolete */
488 + FD_RESET_ALWAYS /* reset always */
489 +};
490 +#define FDRESET _IO(2, 0x54)
491 +
492 +
493 +/*
494 + * FDC state
495 + */
496 +struct floppy_fdc_state {
497 + int spec1; /* spec1 value last used */
498 + int spec2; /* spec2 value last used */
499 + int dtr;
500 + unsigned char version; /* FDC version code */
501 + unsigned char dor;
502 + unsigned long address; /* io address */
503 + unsigned int rawcmd:2;
504 + unsigned int reset:1;
505 + unsigned int need_configure:1;
506 + unsigned int perp_mode:2;
507 + unsigned int has_fifo:1;
508 + unsigned int driver_version; /* version code for floppy driver */
509 +#define FD_DRIVER_VERSION 0x100
510 +/* user programs using the floppy API should use floppy_fdc_state to
511 + * get the version number of the floppy driver that they are running
512 + * on. If this version number is bigger than the one compiled into the
513 + * user program (the FD_DRIVER_VERSION define), it should be prepared
514 + * to bigger structures
515 + */
516 +
517 + unsigned char track[4];
518 + /* Position of the heads of the 4 units attached to this FDC,
519 + * as stored on the FDC. In the future, the position as stored
520 + * on the FDC might not agree with the actual physical
521 + * position of these drive heads. By allowing such
522 + * disagreement, it will be possible to reset the FDC without
523 + * incurring the expensive cost of repositioning all heads.
524 + * Right now, these positions are hard wired to 0. */
525 +
526 +};
527 +
528 +#define FDGETFDCSTAT _IOR(2, 0x15, struct floppy_fdc_state)
529 +
530 +
531 +/*
532 + * Asynchronous Write error tracking
533 + */
534 +struct floppy_write_errors {
535 + /* Write error logging.
536 + *
537 + * These fields can be cleared with the FDWERRORCLR ioctl.
538 + * Only writes that were attempted but failed due to a physical media
539 + * error are logged. write(2) calls that fail and return an error code
540 + * to the user process are not counted.
541 + */
542 +
543 + unsigned int write_errors; /* number of physical write errors
544 + * encountered */
545 +
546 + /* position of first and last write errors */
547 + unsigned long first_error_sector;
548 + int first_error_generation;
549 + unsigned long last_error_sector;
550 + int last_error_generation;
551 +
552 + unsigned int badness; /* highest retry count for a read or write
553 + * operation */
554 +};
555 +
556 +#define FDWERRORCLR _IO(2, 0x56)
557 +/* clear write error and badness information */
558 +#define FDWERRORGET _IOR(2, 0x17, struct floppy_write_errors)
559 +/* get write error and badness information */
560 +
561 +
562 +/*
563 + * Raw commands
564 + */
565 +/* new interface flag: now we can do them in batches */
566 +#define FDHAVEBATCHEDRAWCMD
567 +
568 +struct floppy_raw_cmd {
569 + unsigned int flags;
570 +#define FD_RAW_READ 1
571 +#define FD_RAW_WRITE 2
572 +#define FD_RAW_NO_MOTOR 4
573 +#define FD_RAW_DISK_CHANGE 4 /* out: disk change flag was set */
574 +#define FD_RAW_INTR 8 /* wait for an interrupt */
575 +#define FD_RAW_SPIN 0x10 /* spin up the disk for this command */
576 +#define FD_RAW_NO_MOTOR_AFTER 0x20 /* switch the motor off after command
577 + * completion */
578 +#define FD_RAW_NEED_DISK 0x40 /* this command needs a disk to be present */
579 +#define FD_RAW_NEED_SEEK 0x80 /* this command uses an implied seek (soft) */
580 +
581 +/* more "in" flags */
582 +#define FD_RAW_MORE 0x100 /* more records follow */
583 +#define FD_RAW_STOP_IF_FAILURE 0x200 /* stop if we encounter a failure */
584 +#define FD_RAW_STOP_IF_SUCCESS 0x400 /* stop if command successful */
585 +#define FD_RAW_SOFTFAILURE 0x800 /* consider the return value for failure
586 + * detection too */
587 +
588 +/* more "out" flags */
589 +#define FD_RAW_FAILURE 0x10000 /* command sent to fdc, fdc returned error */
590 +#define FD_RAW_HARDFAILURE 0x20000 /* fdc had to be reset, or timed out */
591 +
592 + void *data;
593 + char *kernel_data; /* location of data buffer in the kernel */
594 + struct floppy_raw_cmd *next; /* used for chaining of raw cmd's
595 + * within the kernel */
596 + long length; /* in: length of dma transfer. out: remaining bytes */
597 + long phys_length; /* physical length, if different from dma length */
598 + int buffer_length; /* length of allocated buffer */
599 +
600 + unsigned char rate;
601 + unsigned char cmd_count;
602 + unsigned char cmd[16];
603 + unsigned char reply_count;
604 + unsigned char reply[16];
605 + int track;
606 + int resultcode;
607 +
608 + int reserved1;
609 + int reserved2;
610 +};
611 +
612 +#define FDRAWCMD _IO(2, 0x58)
613 +/* send a raw command to the fdc. Structure size not included, because of
614 + * batches */
615 +
616 +#define FDTWADDLE _IO(2, 0x59)
617 +/* flicker motor-on bit before reading a sector. Experimental */
618 +
619 +
620 +#define FDEJECT _IO(2, 0x5a)
621 +/* eject the disk */
622 +
623 +
624 +
625 +#endif /* _LINUX_FD_H */
626 diff --git a/src/linux/fs.h b/src/linux/fs.h
627 new file mode 100644
628 index 0000000..8639ce5
629 --- /dev/null
630 +++ b/src/linux/fs.h
631 @@ -0,0 +1,206 @@
632 +#ifndef _LINUX_FS_H
633 +#define _LINUX_FS_H
634 +
635 +/*
636 + * This file has definitions for some important file table
637 + * structures etc.
638 + */
639 +
640 +#ifdef __linux__
641 +#include <linux/limits.h>
642 +#include <linux/ioctl.h>
643 +#include <linux/types.h>
644 +#endif
645 +
646 +/*
647 + * It's silly to have NR_OPEN bigger than NR_FILE, but you can change
648 + * the file limit at runtime and only root can increase the per-process
649 + * nr_file rlimit, so it's safe to set up a ridiculously high absolute
650 + * upper limit on files-per-process.
651 + *
652 + * Some programs (notably those using select()) may have to be
653 + * recompiled to take full advantage of the new limits..
654 + */
655 +
656 +/* Fixed constants first: */
657 +#undef NR_OPEN
658 +#define INR_OPEN_CUR 1024 /* Initial setting for nfile rlimits */
659 +#define INR_OPEN_MAX 4096 /* Hard limit for nfile rlimits */
660 +
661 +#define BLOCK_SIZE_BITS 10
662 +#define BLOCK_SIZE (1<<BLOCK_SIZE_BITS)
663 +
664 +#define SEEK_SET 0 /* seek relative to beginning of file */
665 +#define SEEK_CUR 1 /* seek relative to current file position */
666 +#define SEEK_END 2 /* seek relative to end of file */
667 +#define SEEK_DATA 3 /* seek to the next data */
668 +#define SEEK_HOLE 4 /* seek to the next hole */
669 +#define SEEK_MAX SEEK_HOLE
670 +
671 +struct fstrim_range {
672 + __u64 start;
673 + __u64 len;
674 + __u64 minlen;
675 +};
676 +
677 +/* And dynamically-tunable limits and defaults: */
678 +struct files_stat_struct {
679 + unsigned long nr_files; /* read only */
680 + unsigned long nr_free_files; /* read only */
681 + unsigned long max_files; /* tunable */
682 +};
683 +
684 +struct inodes_stat_t {
685 + long nr_inodes;
686 + long nr_unused;
687 + long dummy[5]; /* padding for sysctl ABI compatibility */
688 +};
689 +
690 +
691 +#define NR_FILE 8192 /* this can well be larger on a larger system */
692 +
693 +
694 +/*
695 + * These are the fs-independent mount-flags: up to 32 flags are supported
696 + */
697 +#define MS_RDONLY 1 /* Mount read-only */
698 +#define MS_NOSUID 2 /* Ignore suid and sgid bits */
699 +#define MS_NODEV 4 /* Disallow access to device special files */
700 +#define MS_NOEXEC 8 /* Disallow program execution */
701 +#define MS_SYNCHRONOUS 16 /* Writes are synced at once */
702 +#define MS_REMOUNT 32 /* Alter flags of a mounted FS */
703 +#define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */
704 +#define MS_DIRSYNC 128 /* Directory modifications are synchronous */
705 +#define MS_NOATIME 1024 /* Do not update access times. */
706 +#define MS_NODIRATIME 2048 /* Do not update directory access times */
707 +#define MS_BIND 4096
708 +#define MS_MOVE 8192
709 +#define MS_REC 16384
710 +#define MS_VERBOSE 32768 /* War is peace. Verbosity is silence.
711 + MS_VERBOSE is deprecated. */
712 +#define MS_SILENT 32768
713 +#define MS_POSIXACL (1<<16) /* VFS does not apply the umask */
714 +#define MS_UNBINDABLE (1<<17) /* change to unbindable */
715 +#define MS_PRIVATE (1<<18) /* change to private */
716 +#define MS_SLAVE (1<<19) /* change to slave */
717 +#define MS_SHARED (1<<20) /* change to shared */
718 +#define MS_RELATIME (1<<21) /* Update atime relative to mtime/ctime. */
719 +#define MS_KERNMOUNT (1<<22) /* this is a kern_mount call */
720 +#define MS_I_VERSION (1<<23) /* Update inode I_version field */
721 +#define MS_STRICTATIME (1<<24) /* Always perform atime updates */
722 +
723 +/* These sb flags are internal to the kernel */
724 +#define MS_NOSEC (1<<28)
725 +#define MS_BORN (1<<29)
726 +#define MS_ACTIVE (1<<30)
727 +#define MS_NOUSER (1<<31)
728 +
729 +/*
730 + * Superblock flags that can be altered by MS_REMOUNT
731 + */
732 +#define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_I_VERSION)
733 +
734 +/*
735 + * Old magic mount flag and mask
736 + */
737 +#define MS_MGC_VAL 0xC0ED0000
738 +#define MS_MGC_MSK 0xffff0000
739 +
740 +/* the read-only stuff doesn't really belong here, but any other place is
741 + probably as bad and I don't want to create yet another include file. */
742 +
743 +#define BLKROSET _IO(0x12,93) /* set device read-only (0 = read-write) */
744 +#define BLKROGET _IO(0x12,94) /* get read-only status (0 = read_write) */
745 +#define BLKRRPART _IO(0x12,95) /* re-read partition table */
746 +#define BLKGETSIZE _IO(0x12,96) /* return device size /512 (long *arg) */
747 +#define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */
748 +#define BLKRASET _IO(0x12,98) /* set read ahead for block device */
749 +#define BLKRAGET _IO(0x12,99) /* get current read ahead setting */
750 +#define BLKFRASET _IO(0x12,100)/* set filesystem (mm/filemap.c) read-ahead */
751 +#define BLKFRAGET _IO(0x12,101)/* get filesystem (mm/filemap.c) read-ahead */
752 +#define BLKSECTSET _IO(0x12,102)/* set max sectors per request (ll_rw_blk.c) */
753 +#define BLKSECTGET _IO(0x12,103)/* get max sectors per request (ll_rw_blk.c) */
754 +#define BLKSSZGET _IO(0x12,104)/* get block device sector size */
755 +#if 0
756 +#define BLKPG _IO(0x12,105)/* See blkpg.h */
757 +
758 +/* Some people are morons. Do not use sizeof! */
759 +
760 +#define BLKELVGET _IOR(0x12,106,size_t)/* elevator get */
761 +#define BLKELVSET _IOW(0x12,107,size_t)/* elevator set */
762 +/* This was here just to show that the number is taken -
763 + probably all these _IO(0x12,*) ioctls should be moved to blkpg.h. */
764 +#endif
765 +/* A jump here: 108-111 have been used for various private purposes. */
766 +#define BLKBSZGET _IOR(0x12,112,size_t)
767 +#define BLKBSZSET _IOW(0x12,113,size_t)
768 +#define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */
769 +#define BLKTRACESETUP _IOWR(0x12,115,struct blk_user_trace_setup)
770 +#define BLKTRACESTART _IO(0x12,116)
771 +#define BLKTRACESTOP _IO(0x12,117)
772 +#define BLKTRACETEARDOWN _IO(0x12,118)
773 +#define BLKDISCARD _IO(0x12,119)
774 +#define BLKIOMIN _IO(0x12,120)
775 +#define BLKIOOPT _IO(0x12,121)
776 +#define BLKALIGNOFF _IO(0x12,122)
777 +#define BLKPBSZGET _IO(0x12,123)
778 +#define BLKDISCARDZEROES _IO(0x12,124)
779 +#define BLKSECDISCARD _IO(0x12,125)
780 +#define BLKROTATIONAL _IO(0x12,126)
781 +#define BLKZEROOUT _IO(0x12,127)
782 +
783 +#define BMAP_IOCTL 1 /* obsolete - kept for compatibility */
784 +#define FIBMAP _IO(0x00,1) /* bmap access */
785 +#define FIGETBSZ _IO(0x00,2) /* get the block size used for bmap */
786 +#define FIFREEZE _IOWR('X', 119, int) /* Freeze */
787 +#define FITHAW _IOWR('X', 120, int) /* Thaw */
788 +#define FITRIM _IOWR('X', 121, struct fstrim_range) /* Trim */
789 +
790 +#define FS_IOC_GETFLAGS _IOR('f', 1, long)
791 +#define FS_IOC_SETFLAGS _IOW('f', 2, long)
792 +#define FS_IOC_GETVERSION _IOR('v', 1, long)
793 +#define FS_IOC_SETVERSION _IOW('v', 2, long)
794 +#define FS_IOC_FIEMAP _IOWR('f', 11, struct fiemap)
795 +#define FS_IOC32_GETFLAGS _IOR('f', 1, int)
796 +#define FS_IOC32_SETFLAGS _IOW('f', 2, int)
797 +#define FS_IOC32_GETVERSION _IOR('v', 1, int)
798 +#define FS_IOC32_SETVERSION _IOW('v', 2, int)
799 +
800 +/*
801 + * Inode flags (FS_IOC_GETFLAGS / FS_IOC_SETFLAGS)
802 + */
803 +#define FS_SECRM_FL 0x00000001 /* Secure deletion */
804 +#define FS_UNRM_FL 0x00000002 /* Undelete */
805 +#define FS_COMPR_FL 0x00000004 /* Compress file */
806 +#define FS_SYNC_FL 0x00000008 /* Synchronous updates */
807 +#define FS_IMMUTABLE_FL 0x00000010 /* Immutable file */
808 +#define FS_APPEND_FL 0x00000020 /* writes to file may only append */
809 +#define FS_NODUMP_FL 0x00000040 /* do not dump file */
810 +#define FS_NOATIME_FL 0x00000080 /* do not update atime */
811 +/* Reserved for compression usage... */
812 +#define FS_DIRTY_FL 0x00000100
813 +#define FS_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */
814 +#define FS_NOCOMP_FL 0x00000400 /* Don't compress */
815 +#define FS_ECOMPR_FL 0x00000800 /* Compression error */
816 +/* End compression flags --- maybe not all used */
817 +#define FS_BTREE_FL 0x00001000 /* btree format dir */
818 +#define FS_INDEX_FL 0x00001000 /* hash-indexed directory */
819 +#define FS_IMAGIC_FL 0x00002000 /* AFS directory */
820 +#define FS_JOURNAL_DATA_FL 0x00004000 /* Reserved for ext3 */
821 +#define FS_NOTAIL_FL 0x00008000 /* file tail should not be merged */
822 +#define FS_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */
823 +#define FS_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/
824 +#define FS_EXTENT_FL 0x00080000 /* Extents */
825 +#define FS_DIRECTIO_FL 0x00100000 /* Use direct i/o */
826 +#define FS_NOCOW_FL 0x00800000 /* Do not cow file */
827 +#define FS_RESERVED_FL 0x80000000 /* reserved for ext2 lib */
828 +
829 +#define FS_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */
830 +#define FS_FL_USER_MODIFIABLE 0x000380FF /* User modifiable flags */
831 +
832 +
833 +#define SYNC_FILE_RANGE_WAIT_BEFORE 1
834 +#define SYNC_FILE_RANGE_WRITE 2
835 +#define SYNC_FILE_RANGE_WAIT_AFTER 4
836 +
837 +#endif /* _LINUX_FS_H */
838 diff --git a/src/linux/hdreg.h b/src/linux/hdreg.h
839 new file mode 100644
840 index 0000000..5f23b03
841 --- /dev/null
842 +++ b/src/linux/hdreg.h
843 @@ -0,0 +1,644 @@
844 +#ifndef _LINUX_HDREG_H
845 +#define _LINUX_HDREG_H
846 +
847 +#ifdef __linux__
848 +#include <linux/types.h>
849 +#endif
850 +
851 +/*
852 + * Command Header sizes for IOCTL commands
853 + */
854 +
855 +#define HDIO_DRIVE_CMD_HDR_SIZE (4 * sizeof(__u8))
856 +#define HDIO_DRIVE_HOB_HDR_SIZE (8 * sizeof(__u8))
857 +#define HDIO_DRIVE_TASK_HDR_SIZE (8 * sizeof(__u8))
858 +
859 +#define IDE_DRIVE_TASK_NO_DATA 0
860 +#define IDE_DRIVE_TASK_INVALID -1
861 +#define IDE_DRIVE_TASK_SET_XFER 1
862 +#define IDE_DRIVE_TASK_IN 2
863 +#define IDE_DRIVE_TASK_OUT 3
864 +#define IDE_DRIVE_TASK_RAW_WRITE 4
865 +
866 +/*
867 + * Define standard taskfile in/out register
868 + */
869 +#define IDE_TASKFILE_STD_IN_FLAGS 0xFE
870 +#define IDE_HOB_STD_IN_FLAGS 0x3C
871 +#define IDE_TASKFILE_STD_OUT_FLAGS 0xFE
872 +#define IDE_HOB_STD_OUT_FLAGS 0x3C
873 +
874 +typedef unsigned char task_ioreg_t;
875 +typedef unsigned long sata_ioreg_t;
876 +
877 +typedef union ide_reg_valid_s {
878 + unsigned all : 16;
879 + struct {
880 + unsigned data : 1;
881 + unsigned error_feature : 1;
882 + unsigned sector : 1;
883 + unsigned nsector : 1;
884 + unsigned lcyl : 1;
885 + unsigned hcyl : 1;
886 + unsigned select : 1;
887 + unsigned status_command : 1;
888 +
889 + unsigned data_hob : 1;
890 + unsigned error_feature_hob : 1;
891 + unsigned sector_hob : 1;
892 + unsigned nsector_hob : 1;
893 + unsigned lcyl_hob : 1;
894 + unsigned hcyl_hob : 1;
895 + unsigned select_hob : 1;
896 + unsigned control_hob : 1;
897 + } b;
898 +} ide_reg_valid_t;
899 +
900 +typedef struct ide_task_request_s {
901 + __u8 io_ports[8];
902 + __u8 hob_ports[8]; /* bytes 6 and 7 are unused */
903 + ide_reg_valid_t out_flags;
904 + ide_reg_valid_t in_flags;
905 + int data_phase;
906 + int req_cmd;
907 + unsigned long out_size;
908 + unsigned long in_size;
909 +} ide_task_request_t;
910 +
911 +typedef struct ide_ioctl_request_s {
912 + ide_task_request_t *task_request;
913 + unsigned char *out_buffer;
914 + unsigned char *in_buffer;
915 +} ide_ioctl_request_t;
916 +
917 +struct hd_drive_cmd_hdr {
918 + __u8 command;
919 + __u8 sector_number;
920 + __u8 feature;
921 + __u8 sector_count;
922 +};
923 +
924 +typedef struct hd_drive_task_hdr {
925 + __u8 data;
926 + __u8 feature;
927 + __u8 sector_count;
928 + __u8 sector_number;
929 + __u8 low_cylinder;
930 + __u8 high_cylinder;
931 + __u8 device_head;
932 + __u8 command;
933 +} task_struct_t;
934 +
935 +typedef struct hd_drive_hob_hdr {
936 + __u8 data;
937 + __u8 feature;
938 + __u8 sector_count;
939 + __u8 sector_number;
940 + __u8 low_cylinder;
941 + __u8 high_cylinder;
942 + __u8 device_head;
943 + __u8 control;
944 +} hob_struct_t;
945 +
946 +#define TASKFILE_NO_DATA 0x0000
947 +
948 +#define TASKFILE_IN 0x0001
949 +#define TASKFILE_MULTI_IN 0x0002
950 +
951 +#define TASKFILE_OUT 0x0004
952 +#define TASKFILE_MULTI_OUT 0x0008
953 +#define TASKFILE_IN_OUT 0x0010
954 +
955 +#define TASKFILE_IN_DMA 0x0020
956 +#define TASKFILE_OUT_DMA 0x0040
957 +#define TASKFILE_IN_DMAQ 0x0080
958 +#define TASKFILE_OUT_DMAQ 0x0100
959 +
960 +#define TASKFILE_P_IN 0x0200
961 +#define TASKFILE_P_OUT 0x0400
962 +#define TASKFILE_P_IN_DMA 0x0800
963 +#define TASKFILE_P_OUT_DMA 0x1000
964 +#define TASKFILE_P_IN_DMAQ 0x2000
965 +#define TASKFILE_P_OUT_DMAQ 0x4000
966 +#define TASKFILE_48 0x8000
967 +#define TASKFILE_INVALID 0x7fff
968 +
969 +/* ATA/ATAPI Commands pre T13 Spec */
970 +#define WIN_NOP 0x00
971 +/*
972 + * 0x01->0x02 Reserved
973 + */
974 +#define CFA_REQ_EXT_ERROR_CODE 0x03 /* CFA Request Extended Error Code */
975 +/*
976 + * 0x04->0x07 Reserved
977 + */
978 +#define WIN_SRST 0x08 /* ATAPI soft reset command */
979 +#define WIN_DEVICE_RESET 0x08
980 +/*
981 + * 0x09->0x0F Reserved
982 + */
983 +#define WIN_RECAL 0x10
984 +#define WIN_RESTORE WIN_RECAL
985 +/*
986 + * 0x10->0x1F Reserved
987 + */
988 +#define WIN_READ 0x20 /* 28-Bit */
989 +#define WIN_READ_ONCE 0x21 /* 28-Bit without retries */
990 +#define WIN_READ_LONG 0x22 /* 28-Bit */
991 +#define WIN_READ_LONG_ONCE 0x23 /* 28-Bit without retries */
992 +#define WIN_READ_EXT 0x24 /* 48-Bit */
993 +#define WIN_READDMA_EXT 0x25 /* 48-Bit */
994 +#define WIN_READDMA_QUEUED_EXT 0x26 /* 48-Bit */
995 +#define WIN_READ_NATIVE_MAX_EXT 0x27 /* 48-Bit */
996 +/*
997 + * 0x28
998 + */
999 +#define WIN_MULTREAD_EXT 0x29 /* 48-Bit */
1000 +/*
1001 + * 0x2A->0x2F Reserved
1002 + */
1003 +#define WIN_WRITE 0x30 /* 28-Bit */
1004 +#define WIN_WRITE_ONCE 0x31 /* 28-Bit without retries */
1005 +#define WIN_WRITE_LONG 0x32 /* 28-Bit */
1006 +#define WIN_WRITE_LONG_ONCE 0x33 /* 28-Bit without retries */
1007 +#define WIN_WRITE_EXT 0x34 /* 48-Bit */
1008 +#define WIN_WRITEDMA_EXT 0x35 /* 48-Bit */
1009 +#define WIN_WRITEDMA_QUEUED_EXT 0x36 /* 48-Bit */
1010 +#define WIN_SET_MAX_EXT 0x37 /* 48-Bit */
1011 +#define CFA_WRITE_SECT_WO_ERASE 0x38 /* CFA Write Sectors without erase */
1012 +#define WIN_MULTWRITE_EXT 0x39 /* 48-Bit */
1013 +/*
1014 + * 0x3A->0x3B Reserved
1015 + */
1016 +#define WIN_WRITE_VERIFY 0x3C /* 28-Bit */
1017 +/*
1018 + * 0x3D->0x3F Reserved
1019 + */
1020 +#define WIN_VERIFY 0x40 /* 28-Bit - Read Verify Sectors */
1021 +#define WIN_VERIFY_ONCE 0x41 /* 28-Bit - without retries */
1022 +#define WIN_VERIFY_EXT 0x42 /* 48-Bit */
1023 +/*
1024 + * 0x43->0x4F Reserved
1025 + */
1026 +#define WIN_FORMAT 0x50
1027 +/*
1028 + * 0x51->0x5F Reserved
1029 + */
1030 +#define WIN_INIT 0x60
1031 +/*
1032 + * 0x61->0x5F Reserved
1033 + */
1034 +#define WIN_SEEK 0x70 /* 0x70-0x7F Reserved */
1035 +
1036 +#define CFA_TRANSLATE_SECTOR 0x87 /* CFA Translate Sector */
1037 +#define WIN_DIAGNOSE 0x90
1038 +#define WIN_SPECIFY 0x91 /* set drive geometry translation */
1039 +#define WIN_DOWNLOAD_MICROCODE 0x92
1040 +#define WIN_STANDBYNOW2 0x94
1041 +#define WIN_STANDBY2 0x96
1042 +#define WIN_SETIDLE2 0x97
1043 +#define WIN_CHECKPOWERMODE2 0x98
1044 +#define WIN_SLEEPNOW2 0x99
1045 +/*
1046 + * 0x9A VENDOR
1047 + */
1048 +#define WIN_PACKETCMD 0xA0 /* Send a packet command. */
1049 +#define WIN_PIDENTIFY 0xA1 /* identify ATAPI device */
1050 +#define WIN_QUEUED_SERVICE 0xA2
1051 +#define WIN_SMART 0xB0 /* self-monitoring and reporting */
1052 +#define CFA_ERASE_SECTORS 0xC0
1053 +#define WIN_MULTREAD 0xC4 /* read sectors using multiple mode*/
1054 +#define WIN_MULTWRITE 0xC5 /* write sectors using multiple mode */
1055 +#define WIN_SETMULT 0xC6 /* enable/disable multiple mode */
1056 +#define WIN_READDMA_QUEUED 0xC7 /* read sectors using Queued DMA transfers */
1057 +#define WIN_READDMA 0xC8 /* read sectors using DMA transfers */
1058 +#define WIN_READDMA_ONCE 0xC9 /* 28-Bit - without retries */
1059 +#define WIN_WRITEDMA 0xCA /* write sectors using DMA transfers */
1060 +#define WIN_WRITEDMA_ONCE 0xCB /* 28-Bit - without retries */
1061 +#define WIN_WRITEDMA_QUEUED 0xCC /* write sectors using Queued DMA transfers */
1062 +#define CFA_WRITE_MULTI_WO_ERASE 0xCD /* CFA Write multiple without erase */
1063 +#define WIN_GETMEDIASTATUS 0xDA
1064 +#define WIN_ACKMEDIACHANGE 0xDB /* ATA-1, ATA-2 vendor */
1065 +#define WIN_POSTBOOT 0xDC
1066 +#define WIN_PREBOOT 0xDD
1067 +#define WIN_DOORLOCK 0xDE /* lock door on removable drives */
1068 +#define WIN_DOORUNLOCK 0xDF /* unlock door on removable drives */
1069 +#define WIN_STANDBYNOW1 0xE0
1070 +#define WIN_IDLEIMMEDIATE 0xE1 /* force drive to become "ready" */
1071 +#define WIN_STANDBY 0xE2 /* Set device in Standby Mode */
1072 +#define WIN_SETIDLE1 0xE3
1073 +#define WIN_READ_BUFFER 0xE4 /* force read only 1 sector */
1074 +#define WIN_CHECKPOWERMODE1 0xE5
1075 +#define WIN_SLEEPNOW1 0xE6
1076 +#define WIN_FLUSH_CACHE 0xE7
1077 +#define WIN_WRITE_BUFFER 0xE8 /* force write only 1 sector */
1078 +#define WIN_WRITE_SAME 0xE9 /* read ata-2 to use */
1079 + /* SET_FEATURES 0x22 or 0xDD */
1080 +#define WIN_FLUSH_CACHE_EXT 0xEA /* 48-Bit */
1081 +#define WIN_IDENTIFY 0xEC /* ask drive to identify itself */
1082 +#define WIN_MEDIAEJECT 0xED
1083 +#define WIN_IDENTIFY_DMA 0xEE /* same as WIN_IDENTIFY, but DMA */
1084 +#define WIN_SETFEATURES 0xEF /* set special drive features */
1085 +#define EXABYTE_ENABLE_NEST 0xF0
1086 +#define WIN_SECURITY_SET_PASS 0xF1
1087 +#define WIN_SECURITY_UNLOCK 0xF2
1088 +#define WIN_SECURITY_ERASE_PREPARE 0xF3
1089 +#define WIN_SECURITY_ERASE_UNIT 0xF4
1090 +#define WIN_SECURITY_FREEZE_LOCK 0xF5
1091 +#define WIN_SECURITY_DISABLE 0xF6
1092 +#define WIN_READ_NATIVE_MAX 0xF8 /* return the native maximum address */
1093 +#define WIN_SET_MAX 0xF9
1094 +#define DISABLE_SEAGATE 0xFB
1095 +
1096 +/* WIN_SMART sub-commands */
1097 +
1098 +#define SMART_READ_VALUES 0xD0
1099 +#define SMART_READ_THRESHOLDS 0xD1
1100 +#define SMART_AUTOSAVE 0xD2
1101 +#define SMART_SAVE 0xD3
1102 +#define SMART_IMMEDIATE_OFFLINE 0xD4
1103 +#define SMART_READ_LOG_SECTOR 0xD5
1104 +#define SMART_WRITE_LOG_SECTOR 0xD6
1105 +#define SMART_WRITE_THRESHOLDS 0xD7
1106 +#define SMART_ENABLE 0xD8
1107 +#define SMART_DISABLE 0xD9
1108 +#define SMART_STATUS 0xDA
1109 +#define SMART_AUTO_OFFLINE 0xDB
1110 +
1111 +/* Password used in TF4 & TF5 executing SMART commands */
1112 +
1113 +#define SMART_LCYL_PASS 0x4F
1114 +#define SMART_HCYL_PASS 0xC2
1115 +
1116 +/* WIN_SETFEATURES sub-commands */
1117 +#define SETFEATURES_EN_8BIT 0x01 /* Enable 8-Bit Transfers */
1118 +#define SETFEATURES_EN_WCACHE 0x02 /* Enable write cache */
1119 +#define SETFEATURES_DIS_DEFECT 0x04 /* Disable Defect Management */
1120 +#define SETFEATURES_EN_APM 0x05 /* Enable advanced power management */
1121 +#define SETFEATURES_EN_SAME_R 0x22 /* for a region ATA-1 */
1122 +#define SETFEATURES_DIS_MSN 0x31 /* Disable Media Status Notification */
1123 +#define SETFEATURES_DIS_RETRY 0x33 /* Disable Retry */
1124 +#define SETFEATURES_EN_AAM 0x42 /* Enable Automatic Acoustic Management */
1125 +#define SETFEATURES_RW_LONG 0x44 /* Set Length of VS bytes */
1126 +#define SETFEATURES_SET_CACHE 0x54 /* Set Cache segments to SC Reg. Val */
1127 +#define SETFEATURES_DIS_RLA 0x55 /* Disable read look-ahead feature */
1128 +#define SETFEATURES_EN_RI 0x5D /* Enable release interrupt */
1129 +#define SETFEATURES_EN_SI 0x5E /* Enable SERVICE interrupt */
1130 +#define SETFEATURES_DIS_RPOD 0x66 /* Disable reverting to power on defaults */
1131 +#define SETFEATURES_DIS_ECC 0x77 /* Disable ECC byte count */
1132 +#define SETFEATURES_DIS_8BIT 0x81 /* Disable 8-Bit Transfers */
1133 +#define SETFEATURES_DIS_WCACHE 0x82 /* Disable write cache */
1134 +#define SETFEATURES_EN_DEFECT 0x84 /* Enable Defect Management */
1135 +#define SETFEATURES_DIS_APM 0x85 /* Disable advanced power management */
1136 +#define SETFEATURES_EN_ECC 0x88 /* Enable ECC byte count */
1137 +#define SETFEATURES_EN_MSN 0x95 /* Enable Media Status Notification */
1138 +#define SETFEATURES_EN_RETRY 0x99 /* Enable Retry */
1139 +#define SETFEATURES_EN_RLA 0xAA /* Enable read look-ahead feature */
1140 +#define SETFEATURES_PREFETCH 0xAB /* Sets drive prefetch value */
1141 +#define SETFEATURES_EN_REST 0xAC /* ATA-1 */
1142 +#define SETFEATURES_4B_RW_LONG 0xBB /* Set Length of 4 bytes */
1143 +#define SETFEATURES_DIS_AAM 0xC2 /* Disable Automatic Acoustic Management */
1144 +#define SETFEATURES_EN_RPOD 0xCC /* Enable reverting to power on defaults */
1145 +#define SETFEATURES_DIS_RI 0xDD /* Disable release interrupt ATAPI */
1146 +#define SETFEATURES_EN_SAME_M 0xDD /* for a entire device ATA-1 */
1147 +#define SETFEATURES_DIS_SI 0xDE /* Disable SERVICE interrupt ATAPI */
1148 +
1149 +/* WIN_SECURITY sub-commands */
1150 +
1151 +#define SECURITY_SET_PASSWORD 0xBA
1152 +#define SECURITY_UNLOCK 0xBB
1153 +#define SECURITY_ERASE_PREPARE 0xBC
1154 +#define SECURITY_ERASE_UNIT 0xBD
1155 +#define SECURITY_FREEZE_LOCK 0xBE
1156 +#define SECURITY_DISABLE_PASSWORD 0xBF
1157 +
1158 +struct hd_geometry {
1159 + unsigned char heads;
1160 + unsigned char sectors;
1161 + unsigned short cylinders;
1162 + unsigned long start;
1163 +};
1164 +
1165 +/* hd/ide ctl's that pass (arg) ptrs to user space are numbered 0x030n/0x031n */
1166 +#define HDIO_GETGEO 0x0301 /* get device geometry */
1167 +#define HDIO_GET_UNMASKINTR 0x0302 /* get current unmask setting */
1168 +#define HDIO_GET_MULTCOUNT 0x0304 /* get current IDE blockmode setting */
1169 +#define HDIO_GET_QDMA 0x0305 /* get use-qdma flag */
1170 +
1171 +#define HDIO_SET_XFER 0x0306 /* set transfer rate via proc */
1172 +
1173 +#define HDIO_OBSOLETE_IDENTITY 0x0307 /* OBSOLETE, DO NOT USE: returns 142 bytes */
1174 +#define HDIO_GET_KEEPSETTINGS 0x0308 /* get keep-settings-on-reset flag */
1175 +#define HDIO_GET_32BIT 0x0309 /* get current io_32bit setting */
1176 +#define HDIO_GET_NOWERR 0x030a /* get ignore-write-error flag */
1177 +#define HDIO_GET_DMA 0x030b /* get use-dma flag */
1178 +#define HDIO_GET_NICE 0x030c /* get nice flags */
1179 +#define HDIO_GET_IDENTITY 0x030d /* get IDE identification info */
1180 +#define HDIO_GET_WCACHE 0x030e /* get write cache mode on|off */
1181 +#define HDIO_GET_ACOUSTIC 0x030f /* get acoustic value */
1182 +#define HDIO_GET_ADDRESS 0x0310 /* */
1183 +
1184 +#define HDIO_GET_BUSSTATE 0x031a /* get the bus state of the hwif */
1185 +#define HDIO_TRISTATE_HWIF 0x031b /* execute a channel tristate */
1186 +#define HDIO_DRIVE_RESET 0x031c /* execute a device reset */
1187 +#define HDIO_DRIVE_TASKFILE 0x031d /* execute raw taskfile */
1188 +#define HDIO_DRIVE_TASK 0x031e /* execute task and special drive command */
1189 +#define HDIO_DRIVE_CMD 0x031f /* execute a special drive command */
1190 +#define HDIO_DRIVE_CMD_AEB HDIO_DRIVE_TASK
1191 +
1192 +/* hd/ide ctl's that pass (arg) non-ptr values are numbered 0x032n/0x033n */
1193 +#define HDIO_SET_MULTCOUNT 0x0321 /* change IDE blockmode */
1194 +#define HDIO_SET_UNMASKINTR 0x0322 /* permit other irqs during I/O */
1195 +#define HDIO_SET_KEEPSETTINGS 0x0323 /* keep ioctl settings on reset */
1196 +#define HDIO_SET_32BIT 0x0324 /* change io_32bit flags */
1197 +#define HDIO_SET_NOWERR 0x0325 /* change ignore-write-error flag */
1198 +#define HDIO_SET_DMA 0x0326 /* change use-dma flag */
1199 +#define HDIO_SET_PIO_MODE 0x0327 /* reconfig interface to new speed */
1200 +#define HDIO_SCAN_HWIF 0x0328 /* register and (re)scan interface */
1201 +#define HDIO_UNREGISTER_HWIF 0x032a /* unregister interface */
1202 +#define HDIO_SET_NICE 0x0329 /* set nice flags */
1203 +#define HDIO_SET_WCACHE 0x032b /* change write cache enable-disable */
1204 +#define HDIO_SET_ACOUSTIC 0x032c /* change acoustic behavior */
1205 +#define HDIO_SET_BUSSTATE 0x032d /* set the bus state of the hwif */
1206 +#define HDIO_SET_QDMA 0x032e /* change use-qdma flag */
1207 +#define HDIO_SET_ADDRESS 0x032f /* change lba addressing modes */
1208 +
1209 +/* bus states */
1210 +enum {
1211 + BUSSTATE_OFF = 0,
1212 + BUSSTATE_ON,
1213 + BUSSTATE_TRISTATE
1214 +};
1215 +
1216 +/* hd/ide ctl's that pass (arg) ptrs to user space are numbered 0x033n/0x033n */
1217 +/* 0x330 is reserved - used to be HDIO_GETGEO_BIG */
1218 +/* 0x331 is reserved - used to be HDIO_GETGEO_BIG_RAW */
1219 +/* 0x338 is reserved - used to be HDIO_SET_IDE_SCSI */
1220 +/* 0x339 is reserved - used to be HDIO_SET_SCSI_IDE */
1221 +
1222 +#define __NEW_HD_DRIVE_ID
1223 +
1224 +/*
1225 + * Structure returned by HDIO_GET_IDENTITY, as per ANSI NCITS ATA6 rev.1b spec.
1226 + *
1227 + * If you change something here, please remember to update fix_driveid() in
1228 + * ide/probe.c.
1229 + */
1230 +struct hd_driveid {
1231 + unsigned short config; /* lots of obsolete bit flags */
1232 + unsigned short cyls; /* Obsolete, "physical" cyls */
1233 + unsigned short reserved2; /* reserved (word 2) */
1234 + unsigned short heads; /* Obsolete, "physical" heads */
1235 + unsigned short track_bytes; /* unformatted bytes per track */
1236 + unsigned short sector_bytes; /* unformatted bytes per sector */
1237 + unsigned short sectors; /* Obsolete, "physical" sectors per track */
1238 + unsigned short vendor0; /* vendor unique */
1239 + unsigned short vendor1; /* vendor unique */
1240 + unsigned short vendor2; /* Retired vendor unique */
1241 + unsigned char serial_no[20]; /* 0 = not_specified */
1242 + unsigned short buf_type; /* Retired */
1243 + unsigned short buf_size; /* Retired, 512 byte increments
1244 + * 0 = not_specified
1245 + */
1246 + unsigned short ecc_bytes; /* for r/w long cmds; 0 = not_specified */
1247 + unsigned char fw_rev[8]; /* 0 = not_specified */
1248 + unsigned char model[40]; /* 0 = not_specified */
1249 + unsigned char max_multsect; /* 0=not_implemented */
1250 + unsigned char vendor3; /* vendor unique */
1251 + unsigned short dword_io; /* 0=not_implemented; 1=implemented */
1252 + unsigned char vendor4; /* vendor unique */
1253 + unsigned char capability; /* (upper byte of word 49)
1254 + * 3: IORDYsup
1255 + * 2: IORDYsw
1256 + * 1: LBA
1257 + * 0: DMA
1258 + */
1259 + unsigned short reserved50; /* reserved (word 50) */
1260 + unsigned char vendor5; /* Obsolete, vendor unique */
1261 + unsigned char tPIO; /* Obsolete, 0=slow, 1=medium, 2=fast */
1262 + unsigned char vendor6; /* Obsolete, vendor unique */
1263 + unsigned char tDMA; /* Obsolete, 0=slow, 1=medium, 2=fast */
1264 + unsigned short field_valid; /* (word 53)
1265 + * 2: ultra_ok word 88
1266 + * 1: eide_ok words 64-70
1267 + * 0: cur_ok words 54-58
1268 + */
1269 + unsigned short cur_cyls; /* Obsolete, logical cylinders */
1270 + unsigned short cur_heads; /* Obsolete, l heads */
1271 + unsigned short cur_sectors; /* Obsolete, l sectors per track */
1272 + unsigned short cur_capacity0; /* Obsolete, l total sectors on drive */
1273 + unsigned short cur_capacity1; /* Obsolete, (2 words, misaligned int) */
1274 + unsigned char multsect; /* current multiple sector count */
1275 + unsigned char multsect_valid; /* when (bit0==1) multsect is ok */
1276 + unsigned int lba_capacity; /* Obsolete, total number of sectors */
1277 + unsigned short dma_1word; /* Obsolete, single-word dma info */
1278 + unsigned short dma_mword; /* multiple-word dma info */
1279 + unsigned short eide_pio_modes; /* bits 0:mode3 1:mode4 */
1280 + unsigned short eide_dma_min; /* min mword dma cycle time (ns) */
1281 + unsigned short eide_dma_time; /* recommended mword dma cycle time (ns) */
1282 + unsigned short eide_pio; /* min cycle time (ns), no IORDY */
1283 + unsigned short eide_pio_iordy; /* min cycle time (ns), with IORDY */
1284 + unsigned short words69_70[2]; /* reserved words 69-70
1285 + * future command overlap and queuing
1286 + */
1287 + unsigned short words71_74[4]; /* reserved words 71-74
1288 + * for IDENTIFY PACKET DEVICE command
1289 + */
1290 + unsigned short queue_depth; /* (word 75)
1291 + * 15:5 reserved
1292 + * 4:0 Maximum queue depth -1
1293 + */
1294 + unsigned short words76_79[4]; /* reserved words 76-79 */
1295 + unsigned short major_rev_num; /* (word 80) */
1296 + unsigned short minor_rev_num; /* (word 81) */
1297 + unsigned short command_set_1; /* (word 82) supported
1298 + * 15: Obsolete
1299 + * 14: NOP command
1300 + * 13: READ_BUFFER
1301 + * 12: WRITE_BUFFER
1302 + * 11: Obsolete
1303 + * 10: Host Protected Area
1304 + * 9: DEVICE Reset
1305 + * 8: SERVICE Interrupt
1306 + * 7: Release Interrupt
1307 + * 6: look-ahead
1308 + * 5: write cache
1309 + * 4: PACKET Command
1310 + * 3: Power Management Feature Set
1311 + * 2: Removable Feature Set
1312 + * 1: Security Feature Set
1313 + * 0: SMART Feature Set
1314 + */
1315 + unsigned short command_set_2; /* (word 83)
1316 + * 15: Shall be ZERO
1317 + * 14: Shall be ONE
1318 + * 13: FLUSH CACHE EXT
1319 + * 12: FLUSH CACHE
1320 + * 11: Device Configuration Overlay
1321 + * 10: 48-bit Address Feature Set
1322 + * 9: Automatic Acoustic Management
1323 + * 8: SET MAX security
1324 + * 7: reserved 1407DT PARTIES
1325 + * 6: SetF sub-command Power-Up
1326 + * 5: Power-Up in Standby Feature Set
1327 + * 4: Removable Media Notification
1328 + * 3: APM Feature Set
1329 + * 2: CFA Feature Set
1330 + * 1: READ/WRITE DMA QUEUED
1331 + * 0: Download MicroCode
1332 + */
1333 + unsigned short cfsse; /* (word 84)
1334 + * cmd set-feature supported extensions
1335 + * 15: Shall be ZERO
1336 + * 14: Shall be ONE
1337 + * 13:6 reserved
1338 + * 5: General Purpose Logging
1339 + * 4: Streaming Feature Set
1340 + * 3: Media Card Pass Through
1341 + * 2: Media Serial Number Valid
1342 + * 1: SMART selt-test supported
1343 + * 0: SMART error logging
1344 + */
1345 + unsigned short cfs_enable_1; /* (word 85)
1346 + * command set-feature enabled
1347 + * 15: Obsolete
1348 + * 14: NOP command
1349 + * 13: READ_BUFFER
1350 + * 12: WRITE_BUFFER
1351 + * 11: Obsolete
1352 + * 10: Host Protected Area
1353 + * 9: DEVICE Reset
1354 + * 8: SERVICE Interrupt
1355 + * 7: Release Interrupt
1356 + * 6: look-ahead
1357 + * 5: write cache
1358 + * 4: PACKET Command
1359 + * 3: Power Management Feature Set
1360 + * 2: Removable Feature Set
1361 + * 1: Security Feature Set
1362 + * 0: SMART Feature Set
1363 + */
1364 + unsigned short cfs_enable_2; /* (word 86)
1365 + * command set-feature enabled
1366 + * 15: Shall be ZERO
1367 + * 14: Shall be ONE
1368 + * 13: FLUSH CACHE EXT
1369 + * 12: FLUSH CACHE
1370 + * 11: Device Configuration Overlay
1371 + * 10: 48-bit Address Feature Set
1372 + * 9: Automatic Acoustic Management
1373 + * 8: SET MAX security
1374 + * 7: reserved 1407DT PARTIES
1375 + * 6: SetF sub-command Power-Up
1376 + * 5: Power-Up in Standby Feature Set
1377 + * 4: Removable Media Notification
1378 + * 3: APM Feature Set
1379 + * 2: CFA Feature Set
1380 + * 1: READ/WRITE DMA QUEUED
1381 + * 0: Download MicroCode
1382 + */
1383 + unsigned short csf_default; /* (word 87)
1384 + * command set-feature default
1385 + * 15: Shall be ZERO
1386 + * 14: Shall be ONE
1387 + * 13:6 reserved
1388 + * 5: General Purpose Logging enabled
1389 + * 4: Valid CONFIGURE STREAM executed
1390 + * 3: Media Card Pass Through enabled
1391 + * 2: Media Serial Number Valid
1392 + * 1: SMART selt-test supported
1393 + * 0: SMART error logging
1394 + */
1395 + unsigned short dma_ultra; /* (word 88) */
1396 + unsigned short trseuc; /* time required for security erase */
1397 + unsigned short trsEuc; /* time required for enhanced erase */
1398 + unsigned short CurAPMvalues; /* current APM values */
1399 + unsigned short mprc; /* master password revision code */
1400 + unsigned short hw_config; /* hardware config (word 93)
1401 + * 15: Shall be ZERO
1402 + * 14: Shall be ONE
1403 + * 13:
1404 + * 12:
1405 + * 11:
1406 + * 10:
1407 + * 9:
1408 + * 8:
1409 + * 7:
1410 + * 6:
1411 + * 5:
1412 + * 4:
1413 + * 3:
1414 + * 2:
1415 + * 1:
1416 + * 0: Shall be ONE
1417 + */
1418 + unsigned short acoustic; /* (word 94)
1419 + * 15:8 Vendor's recommended value
1420 + * 7:0 current value
1421 + */
1422 + unsigned short msrqs; /* min stream request size */
1423 + unsigned short sxfert; /* stream transfer time */
1424 + unsigned short sal; /* stream access latency */
1425 + unsigned int spg; /* stream performance granularity */
1426 + unsigned long long lba_capacity_2;/* 48-bit total number of sectors */
1427 + unsigned short words104_125[22];/* reserved words 104-125 */
1428 + unsigned short last_lun; /* (word 126) */
1429 + unsigned short word127; /* (word 127) Feature Set
1430 + * Removable Media Notification
1431 + * 15:2 reserved
1432 + * 1:0 00 = not supported
1433 + * 01 = supported
1434 + * 10 = reserved
1435 + * 11 = reserved
1436 + */
1437 + unsigned short dlf; /* (word 128)
1438 + * device lock function
1439 + * 15:9 reserved
1440 + * 8 security level 1:max 0:high
1441 + * 7:6 reserved
1442 + * 5 enhanced erase
1443 + * 4 expire
1444 + * 3 frozen
1445 + * 2 locked
1446 + * 1 en/disabled
1447 + * 0 capability
1448 + */
1449 + unsigned short csfo; /* (word 129)
1450 + * current set features options
1451 + * 15:4 reserved
1452 + * 3: auto reassign
1453 + * 2: reverting
1454 + * 1: read-look-ahead
1455 + * 0: write cache
1456 + */
1457 + unsigned short words130_155[26];/* reserved vendor words 130-155 */
1458 + unsigned short word156; /* reserved vendor word 156 */
1459 + unsigned short words157_159[3];/* reserved vendor words 157-159 */
1460 + unsigned short cfa_power; /* (word 160) CFA Power Mode
1461 + * 15 word 160 supported
1462 + * 14 reserved
1463 + * 13
1464 + * 12
1465 + * 11:0
1466 + */
1467 + unsigned short words161_175[15];/* Reserved for CFA */
1468 + unsigned short words176_205[30];/* Current Media Serial Number */
1469 + unsigned short words206_254[49];/* reserved words 206-254 */
1470 + unsigned short integrity_word; /* (word 255)
1471 + * 15:8 Checksum
1472 + * 7:0 Signature
1473 + */
1474 +};
1475 +
1476 +/*
1477 + * IDE "nice" flags. These are used on a per drive basis to determine
1478 + * when to be nice and give more bandwidth to the other devices which
1479 + * share the same IDE bus.
1480 + */
1481 +#define IDE_NICE_DSC_OVERLAP (0) /* per the DSC overlap protocol */
1482 +#define IDE_NICE_ATAPI_OVERLAP (1) /* not supported yet */
1483 +#define IDE_NICE_1 (3) /* when probably won't affect us much */
1484 +#define IDE_NICE_0 (2) /* when sure that it won't affect us */
1485 +#define IDE_NICE_2 (4) /* when we know it's on our expense */
1486 +
1487 +#endif /* _LINUX_HDREG_H */
1488 diff --git a/src/linux/magic.h b/src/linux/magic.h
1489 new file mode 100644
1490 index 0000000..77c6031
1491 --- /dev/null
1492 +++ b/src/linux/magic.h
1493 @@ -0,0 +1,76 @@
1494 +#ifndef __LINUX_MAGIC_H__
1495 +#define __LINUX_MAGIC_H__
1496 +
1497 +#define ADFS_SUPER_MAGIC 0xadf5
1498 +#define AFFS_SUPER_MAGIC 0xadff
1499 +#define AFS_SUPER_MAGIC 0x5346414F
1500 +#define AUTOFS_SUPER_MAGIC 0x0187
1501 +#define CODA_SUPER_MAGIC 0x73757245
1502 +#define CRAMFS_MAGIC 0x28cd3d45 /* some random number */
1503 +#define CRAMFS_MAGIC_WEND 0x453dcd28 /* magic number with the wrong endianess */
1504 +#define DEBUGFS_MAGIC 0x64626720
1505 +#define SECURITYFS_MAGIC 0x73636673
1506 +#define SELINUX_MAGIC 0xf97cff8c
1507 +#define SMACK_MAGIC 0x43415d53 /* "SMAC" */
1508 +#define RAMFS_MAGIC 0x858458f6 /* some random number */
1509 +#define TMPFS_MAGIC 0x01021994
1510 +#define HUGETLBFS_MAGIC 0x958458f6 /* some random number */
1511 +#define SQUASHFS_MAGIC 0x73717368
1512 +#define ECRYPTFS_SUPER_MAGIC 0xf15f
1513 +#define EFS_SUPER_MAGIC 0x414A53
1514 +#define EXT2_SUPER_MAGIC 0xEF53
1515 +#define EXT3_SUPER_MAGIC 0xEF53
1516 +#define XENFS_SUPER_MAGIC 0xabba1974
1517 +#define EXT4_SUPER_MAGIC 0xEF53
1518 +#define BTRFS_SUPER_MAGIC 0x9123683E
1519 +#define NILFS_SUPER_MAGIC 0x3434
1520 +#define F2FS_SUPER_MAGIC 0xF2F52010
1521 +#define HPFS_SUPER_MAGIC 0xf995e849
1522 +#define ISOFS_SUPER_MAGIC 0x9660
1523 +#define JFFS2_SUPER_MAGIC 0x72b6
1524 +#define PSTOREFS_MAGIC 0x6165676C
1525 +#define EFIVARFS_MAGIC 0xde5e81e4
1526 +#define HOSTFS_SUPER_MAGIC 0x00c0ffee
1527 +
1528 +#define MINIX_SUPER_MAGIC 0x137F /* minix v1 fs, 14 char names */
1529 +#define MINIX_SUPER_MAGIC2 0x138F /* minix v1 fs, 30 char names */
1530 +#define MINIX2_SUPER_MAGIC 0x2468 /* minix v2 fs, 14 char names */
1531 +#define MINIX2_SUPER_MAGIC2 0x2478 /* minix v2 fs, 30 char names */
1532 +#define MINIX3_SUPER_MAGIC 0x4d5a /* minix v3 fs, 60 char names */
1533 +
1534 +#define MSDOS_SUPER_MAGIC 0x4d44 /* MD */
1535 +#define NCP_SUPER_MAGIC 0x564c /* Guess, what 0x564c is :-) */
1536 +#define NFS_SUPER_MAGIC 0x6969
1537 +#define OPENPROM_SUPER_MAGIC 0x9fa1
1538 +#define QNX4_SUPER_MAGIC 0x002f /* qnx4 fs detection */
1539 +#define QNX6_SUPER_MAGIC 0x68191122 /* qnx6 fs detection */
1540 +
1541 +#define REISERFS_SUPER_MAGIC 0x52654973 /* used by gcc */
1542 + /* used by file system utilities that
1543 + look at the superblock, etc. */
1544 +#define REISERFS_SUPER_MAGIC_STRING "ReIsErFs"
1545 +#define REISER2FS_SUPER_MAGIC_STRING "ReIsEr2Fs"
1546 +#define REISER2FS_JR_SUPER_MAGIC_STRING "ReIsEr3Fs"
1547 +
1548 +#define SMB_SUPER_MAGIC 0x517B
1549 +#define CGROUP_SUPER_MAGIC 0x27e0eb
1550 +
1551 +
1552 +#define STACK_END_MAGIC 0x57AC6E9D
1553 +
1554 +#define V9FS_MAGIC 0x01021997
1555 +
1556 +#define BDEVFS_MAGIC 0x62646576
1557 +#define BINFMTFS_MAGIC 0x42494e4d
1558 +#define DEVPTS_SUPER_MAGIC 0x1cd1
1559 +#define FUTEXFS_SUPER_MAGIC 0xBAD1DEA
1560 +#define PIPEFS_MAGIC 0x50495045
1561 +#define PROC_SUPER_MAGIC 0x9fa0
1562 +#define SOCKFS_MAGIC 0x534F434B
1563 +#define SYSFS_MAGIC 0x62656572
1564 +#define USBDEVICE_SUPER_MAGIC 0x9fa2
1565 +#define MTD_INODE_FS_MAGIC 0x11307854
1566 +#define ANON_INODE_FS_MAGIC 0x09041934
1567 +#define BTRFS_TEST_MAGIC 0x73727279
1568 +
1569 +#endif /* __LINUX_MAGIC_H__ */
1570 diff --git a/src/linux/msdos_fs.h b/src/linux/msdos_fs.h
1571 new file mode 100644
1572 index 0000000..635d905
1573 --- /dev/null
1574 +++ b/src/linux/msdos_fs.h
1575 @@ -0,0 +1,201 @@
1576 +#ifndef _LINUX_MSDOS_FS_H
1577 +#define _LINUX_MSDOS_FS_H
1578 +
1579 +#ifdef __linux__
1580 +#include <linux/types.h>
1581 +#include <asm/byteorder.h>
1582 +#endif
1583 +#include "magic.h"
1584 +
1585 +/*
1586 + * The MS-DOS filesystem constants/structures
1587 + */
1588 +
1589 +#define SECTOR_SIZE 512 /* sector size (bytes) */
1590 +#define SECTOR_BITS 9 /* log2(SECTOR_SIZE) */
1591 +#define MSDOS_DPB (MSDOS_DPS) /* dir entries per block */
1592 +#define MSDOS_DPB_BITS 4 /* log2(MSDOS_DPB) */
1593 +#define MSDOS_DPS (SECTOR_SIZE / sizeof(struct msdos_dir_entry))
1594 +#define MSDOS_DPS_BITS 4 /* log2(MSDOS_DPS) */
1595 +#define MSDOS_LONGNAME 256 /* maximum name length */
1596 +#define CF_LE_W(v) le16_to_cpu(v)
1597 +#define CF_LE_L(v) le32_to_cpu(v)
1598 +#define CT_LE_W(v) cpu_to_le16(v)
1599 +#define CT_LE_L(v) cpu_to_le32(v)
1600 +
1601 +#define MSDOS_ROOT_INO 1 /* The root inode number */
1602 +#define MSDOS_FSINFO_INO 2 /* Used for managing the FSINFO block */
1603 +
1604 +#define MSDOS_DIR_BITS 5 /* log2(sizeof(struct msdos_dir_entry)) */
1605 +
1606 +/* directory limit */
1607 +#define FAT_MAX_DIR_ENTRIES (65536)
1608 +#define FAT_MAX_DIR_SIZE (FAT_MAX_DIR_ENTRIES << MSDOS_DIR_BITS)
1609 +
1610 +#define ATTR_NONE 0 /* no attribute bits */
1611 +#define ATTR_RO 1 /* read-only */
1612 +#define ATTR_HIDDEN 2 /* hidden */
1613 +#define ATTR_SYS 4 /* system */
1614 +#define ATTR_VOLUME 8 /* volume label */
1615 +#define ATTR_DIR 16 /* directory */
1616 +#define ATTR_ARCH 32 /* archived */
1617 +
1618 +/* attribute bits that are copied "as is" */
1619 +#define ATTR_UNUSED (ATTR_VOLUME | ATTR_ARCH | ATTR_SYS | ATTR_HIDDEN)
1620 +/* bits that are used by the Windows 95/Windows NT extended FAT */
1621 +#define ATTR_EXT (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME)
1622 +
1623 +#define CASE_LOWER_BASE 8 /* base is lower case */
1624 +#define CASE_LOWER_EXT 16 /* extension is lower case */
1625 +
1626 +#define DELETED_FLAG 0xe5 /* marks file as deleted when in name[0] */
1627 +#define IS_FREE(n) (!*(n) || *(n) == DELETED_FLAG)
1628 +
1629 +#define FAT_LFN_LEN 255 /* maximum long name length */
1630 +#define MSDOS_NAME 11 /* maximum name length */
1631 +#define MSDOS_SLOTS 21 /* max # of slots for short and long names */
1632 +#define MSDOS_DOT ". " /* ".", padded to MSDOS_NAME chars */
1633 +#define MSDOS_DOTDOT ".. " /* "..", padded to MSDOS_NAME chars */
1634 +
1635 +#define FAT_FIRST_ENT(s, x) ((MSDOS_SB(s)->fat_bits == 32 ? 0x0FFFFF00 : \
1636 + MSDOS_SB(s)->fat_bits == 16 ? 0xFF00 : 0xF00) | (x))
1637 +
1638 +/* start of data cluster's entry (number of reserved clusters) */
1639 +#define FAT_START_ENT 2
1640 +
1641 +/* maximum number of clusters */
1642 +#define MAX_FAT12 0xFF4
1643 +#define MAX_FAT16 0xFFF4
1644 +#define MAX_FAT32 0x0FFFFFF6
1645 +#define MAX_FAT(s) (MSDOS_SB(s)->fat_bits == 32 ? MAX_FAT32 : \
1646 + MSDOS_SB(s)->fat_bits == 16 ? MAX_FAT16 : MAX_FAT12)
1647 +
1648 +/* bad cluster mark */
1649 +#define BAD_FAT12 0xFF7
1650 +#define BAD_FAT16 0xFFF7
1651 +#define BAD_FAT32 0x0FFFFFF7
1652 +
1653 +/* standard EOF */
1654 +#define EOF_FAT12 0xFFF
1655 +#define EOF_FAT16 0xFFFF
1656 +#define EOF_FAT32 0x0FFFFFFF
1657 +
1658 +#define FAT_ENT_FREE (0)
1659 +#define FAT_ENT_BAD (BAD_FAT32)
1660 +#define FAT_ENT_EOF (EOF_FAT32)
1661 +
1662 +#define FAT_FSINFO_SIG1 0x41615252
1663 +#define FAT_FSINFO_SIG2 0x61417272
1664 +#define IS_FSINFO(x) (le32_to_cpu((x)->signature1) == FAT_FSINFO_SIG1 \
1665 + && le32_to_cpu((x)->signature2) == FAT_FSINFO_SIG2)
1666 +
1667 +#define FAT_STATE_DIRTY 0x01
1668 +
1669 +struct __fat_dirent {
1670 + long d_ino;
1671 + long d_off;
1672 + unsigned short d_reclen;
1673 + char d_name[256]; /* We must not include limits.h! */
1674 +};
1675 +
1676 +/*
1677 + * ioctl commands
1678 + */
1679 +#define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct __fat_dirent[2])
1680 +#define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct __fat_dirent[2])
1681 +/* <linux/videotext.h> has used 0x72 ('r') in collision, so skip a few */
1682 +#define FAT_IOCTL_GET_ATTRIBUTES _IOR('r', 0x10, __u32)
1683 +#define FAT_IOCTL_SET_ATTRIBUTES _IOW('r', 0x11, __u32)
1684 +/*Android kernel has used 0x12, so we use 0x13*/
1685 +#define FAT_IOCTL_GET_VOLUME_ID _IOR('r', 0x13, __u32)
1686 +
1687 +struct fat_boot_sector {
1688 + __u8 ignored[3]; /* Boot strap short or near jump */
1689 + __u8 system_id[8]; /* Name - can be used to special case
1690 + partition manager volumes */
1691 + __u8 sector_size[2]; /* bytes per logical sector */
1692 + __u8 sec_per_clus; /* sectors/cluster */
1693 + __le16 reserved; /* reserved sectors */
1694 + __u8 fats; /* number of FATs */
1695 + __u8 dir_entries[2]; /* root directory entries */
1696 + __u8 sectors[2]; /* number of sectors */
1697 + __u8 media; /* media code */
1698 + __le16 fat_length; /* sectors/FAT */
1699 + __le16 secs_track; /* sectors per track */
1700 + __le16 heads; /* number of heads */
1701 + __le32 hidden; /* hidden sectors (unused) */
1702 + __le32 total_sect; /* number of sectors (if sectors == 0) */
1703 +
1704 + union {
1705 + struct {
1706 + /* Extended BPB Fields for FAT16 */
1707 + __u8 drive_number; /* Physical drive number */
1708 + __u8 state; /* undocumented, but used
1709 + for mount state. */
1710 + __u8 signature; /* extended boot signature */
1711 + __u8 vol_id[4]; /* volume ID */
1712 + __u8 vol_label[11]; /* volume label */
1713 + __u8 fs_type[8]; /* file system type */
1714 + /* other fiealds are not added here */
1715 + } fat16;
1716 +
1717 + struct {
1718 + /* only used by FAT32 */
1719 + __le32 length; /* sectors/FAT */
1720 + __le16 flags; /* bit 8: fat mirroring,
1721 + low 4: active fat */
1722 + __u8 version[2]; /* major, minor filesystem
1723 + version */
1724 + __le32 root_cluster; /* first cluster in
1725 + root directory */
1726 + __le16 info_sector; /* filesystem info sector */
1727 + __le16 backup_boot; /* backup boot sector */
1728 + __le16 reserved2[6]; /* Unused */
1729 + /* Extended BPB Fields for FAT32 */
1730 + __u8 drive_number; /* Physical drive number */
1731 + __u8 state; /* undocumented, but used
1732 + for mount state. */
1733 + __u8 signature; /* extended boot signature */
1734 + __u8 vol_id[4]; /* volume ID */
1735 + __u8 vol_label[11]; /* volume label */
1736 + __u8 fs_type[8]; /* file system type */
1737 + /* other fiealds are not added here */
1738 + } fat32;
1739 + };
1740 +};
1741 +
1742 +struct fat_boot_fsinfo {
1743 + __le32 signature1; /* 0x41615252L */
1744 + __le32 reserved1[120]; /* Nothing as far as I can tell */
1745 + __le32 signature2; /* 0x61417272L */
1746 + __le32 free_clusters; /* Free cluster count. -1 if unknown */
1747 + __le32 next_cluster; /* Most recently allocated cluster */
1748 + __le32 reserved2[4];
1749 +};
1750 +
1751 +struct msdos_dir_entry {
1752 + __u8 name[MSDOS_NAME];/* name and extension */
1753 + __u8 attr; /* attribute bits */
1754 + __u8 lcase; /* Case for base and extension */
1755 + __u8 ctime_cs; /* Creation time, centiseconds (0-199) */
1756 + __le16 ctime; /* Creation time */
1757 + __le16 cdate; /* Creation date */
1758 + __le16 adate; /* Last access date */
1759 + __le16 starthi; /* High 16 bits of cluster in FAT32 */
1760 + __le16 time,date,start;/* time, date and first cluster */
1761 + __le32 size; /* file size (in bytes) */
1762 +};
1763 +
1764 +/* Up to 13 characters of the name */
1765 +struct msdos_dir_slot {
1766 + __u8 id; /* sequence number for slot */
1767 + __u8 name0_4[10]; /* first 5 characters in name */
1768 + __u8 attr; /* attribute byte */
1769 + __u8 reserved; /* always 0 */
1770 + __u8 alias_checksum; /* checksum for 8.3 alias */
1771 + __u8 name5_10[12]; /* 6 more characters in name */
1772 + __le16 start; /* starting cluster number, 0 in long slots */
1773 + __u8 name11_12[4]; /* last 2 characters in name */
1774 +};
1775 +
1776 +#endif /* _LINUX_MSDOS_FS_H */
1777 diff --git a/src/mkfs.fat.c b/src/mkfs.fat.c
1778 index e6f9390..ebdfdb5 100644
1779 --- a/src/mkfs.fat.c
1780 +++ b/src/mkfs.fat.c
1781 @@ -47,12 +47,6 @@
1782 #include "version.h"
1783
1784 #include <fcntl.h>
1785 -#include <linux/hdreg.h>
1786 -#include <sys/mount.h>
1787 -#include <linux/fs.h>
1788 -#include <linux/fd.h>
1789 -#include <endian.h>
1790 -#include <mntent.h>
1791 #include <signal.h>
1792 #include <string.h>
1793 #include <stdio.h>
1794 @@ -60,15 +54,23 @@
1795 #include <sys/ioctl.h>
1796 #include <sys/stat.h>
1797 #include <sys/time.h>
1798 -#include <sys/types.h>
1799 #include <unistd.h>
1800 #include <time.h>
1801 #include <errno.h>
1802 #include <ctype.h>
1803 #include <stdint.h>
1804 -#include <endian.h>
1805
1806 -#include <asm/types.h>
1807 +#if defined(__linux__)
1808 + #include <mntent.h>
1809 +#elif defined(__osx__)
1810 + #include <fstab.h>
1811 + #include <sys/mount.h>
1812 +#endif
1813 +
1814 +#include "common.h"
1815 +#include "linux/fs.h"
1816 +#include "linux/fd.h"
1817 +#include "linux/hdreg.h"
1818
1819 /* In earlier versions, an own llseek() was used, but glibc lseek() is
1820 * sufficient (or even better :) for 64 bit offsets in the meantime */
1821 @@ -524,6 +526,7 @@ static uint64_t count_blocks(char *filename, int *remainder)
1822
1823 static void check_mount(char *device_name)
1824 {
1825 +#if defined(__linux__)
1826 FILE *f;
1827 struct mntent *mnt;
1828
1829 @@ -533,6 +536,17 @@ static void check_mount(char *device_name)
1830 if (strcmp(device_name, mnt->mnt_fsname) == 0)
1831 die("%s contains a mounted filesystem.");
1832 endmntent(f);
1833 +#elif defined(__osx__)
1834 + struct statfs* mounts;
1835 + int num_mounts = getmntinfo(&mounts, MNT_WAIT);
1836 + if (num_mounts < 0)
1837 + return;
1838 + for ( int i = 0; i < num_mounts; i++ )
1839 + {
1840 + if (strcmp(device_name, mounts[i].f_mntfromname) == 0)
1841 + die("%s contains a mounted filesystem.");
1842 + }
1843 +#endif
1844 }
1845
1846 /* Establish the geometry and media parameters for the device */
1847 --
1848 1.9.1
1849