0001-Add-OSX-support.patch 62 KB

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