You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1407 lines
36 KiB

  1. From: =?UTF-8?q?Rog=C3=A9rio=20Brito?= <rbrito@ime.usp.br>
  2. Date: Thu, 24 Oct 2013 01:11:21 -0200
  3. Subject: Add/exclude Darwin-specific code
  4. Modify some of the files so that they can be compiled without the
  5. Apple owned frameworks in a Debian system (and possibly others).
  6. ---
  7. fsck_hfs.tproj/cache.c | 4 ++
  8. fsck_hfs.tproj/dfalib/BTree.c | 2 +
  9. fsck_hfs.tproj/dfalib/BlockCache.c | 3 +
  10. fsck_hfs.tproj/dfalib/SBTree.c | 2 +
  11. fsck_hfs.tproj/dfalib/SDevice.c | 92 ++++++++++++++++++++---------
  12. fsck_hfs.tproj/dfalib/SKeyCompare.c | 2 +
  13. fsck_hfs.tproj/dfalib/SRepair.c | 2 +
  14. fsck_hfs.tproj/dfalib/SRuntime.h | 7 ++-
  15. fsck_hfs.tproj/dfalib/SUtils.c | 5 +-
  16. fsck_hfs.tproj/dfalib/SVerify2.c | 7 +++
  17. fsck_hfs.tproj/dfalib/Scavenger.h | 11 +++-
  18. fsck_hfs.tproj/dfalib/hfs_endian.c | 4 ++
  19. fsck_hfs.tproj/dfalib/hfs_endian.h | 7 ++-
  20. fsck_hfs.tproj/fsck_hfs.c | 61 +++++++++++++++----
  21. fsck_hfs.tproj/utilities.c | 8 ++-
  22. include/missing.h | 115 ++++++++++++++++++++++++++++++++++++
  23. newfs_hfs.tproj/hfs_endian.c | 5 ++
  24. newfs_hfs.tproj/hfs_endian.h | 5 ++
  25. newfs_hfs.tproj/makehfs.c | 72 ++++++++++++++++------
  26. newfs_hfs.tproj/newfs_hfs.c | 74 ++++++++++++++++++++---
  27. newfs_hfs.tproj/newfs_hfs.h | 26 ++++----
  28. 21 files changed, 429 insertions(+), 85 deletions(-)
  29. create mode 100644 include/missing.h
  30. diff --git a/fsck_hfs.tproj/cache.c b/fsck_hfs.tproj/cache.c
  31. index be46195..527088a 100644
  32. --- a/fsck_hfs.tproj/cache.c
  33. +++ b/fsck_hfs.tproj/cache.c
  34. @@ -26,7 +26,11 @@
  35. #include <stdlib.h>
  36. #include <sys/mman.h>
  37. #include <sys/stat.h>
  38. +#if LINUX
  39. +#include "missing.h"
  40. +#else
  41. #include <sys/types.h>
  42. +#endif /* __LINUX__ */
  43. #include <sys/uio.h>
  44. #include <unistd.h>
  45. #include <string.h>
  46. diff --git a/fsck_hfs.tproj/dfalib/BTree.c b/fsck_hfs.tproj/dfalib/BTree.c
  47. index edd8301..7ad9fe0 100644
  48. --- a/fsck_hfs.tproj/dfalib/BTree.c
  49. +++ b/fsck_hfs.tproj/dfalib/BTree.c
  50. @@ -1705,7 +1705,9 @@ OSStatus BTGetInformation (SFCB *filePtr,
  51. UInt16 version,
  52. BTreeInfoRec *info )
  53. {
  54. +#if !LINUX
  55. #pragma unused (version)
  56. +#endif
  57. BTreeControlBlockPtr btreePtr;
  58. diff --git a/fsck_hfs.tproj/dfalib/BlockCache.c b/fsck_hfs.tproj/dfalib/BlockCache.c
  59. index 1bb952f..e3a28a2 100644
  60. --- a/fsck_hfs.tproj/dfalib/BlockCache.c
  61. +++ b/fsck_hfs.tproj/dfalib/BlockCache.c
  62. @@ -20,6 +20,9 @@
  63. * @APPLE_LICENSE_HEADER_END@
  64. */
  65. +#if LINUX
  66. +#include "missing.h"
  67. +#endif
  68. #include "SRuntime.h"
  69. #include "Scavenger.h"
  70. #include "../cache.h"
  71. diff --git a/fsck_hfs.tproj/dfalib/SBTree.c b/fsck_hfs.tproj/dfalib/SBTree.c
  72. index 2fbcd1d..cd81b13 100644
  73. --- a/fsck_hfs.tproj/dfalib/SBTree.c
  74. +++ b/fsck_hfs.tproj/dfalib/SBTree.c
  75. @@ -322,7 +322,9 @@ ErrorExit:
  76. OSStatus
  77. SetEndOfForkProc ( SFCB *filePtr, FSSize minEOF, FSSize maxEOF )
  78. {
  79. +#if !LINUX
  80. #pragma unused (maxEOF)
  81. +#endif
  82. OSStatus result;
  83. UInt32 actualSectorsAdded;
  84. diff --git a/fsck_hfs.tproj/dfalib/SDevice.c b/fsck_hfs.tproj/dfalib/SDevice.c
  85. index bf6f61c..9a46023 100644
  86. --- a/fsck_hfs.tproj/dfalib/SDevice.c
  87. +++ b/fsck_hfs.tproj/dfalib/SDevice.c
  88. @@ -2,7 +2,7 @@
  89. * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
  90. *
  91. * @APPLE_LICENSE_HEADER_START@
  92. - *
  93. + *
  94. * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
  95. * Reserved. This file contains Original Code and/or Modifications of
  96. * Original Code as defined in and that are subject to the Apple Public
  97. @@ -10,7 +10,7 @@
  98. * except in compliance with the License. Please obtain a copy of the
  99. * License at http://www.apple.com/publicsource and read it before using
  100. * this file.
  101. - *
  102. + *
  103. * The Original Code and all software distributed under the License are
  104. * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  105. * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  106. @@ -18,7 +18,7 @@
  107. * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
  108. * License for the specific language governing rights and limitations
  109. * under the License."
  110. - *
  111. + *
  112. * @APPLE_LICENSE_HEADER_END@
  113. */
  114. #include "SRuntime.h"
  115. @@ -28,33 +28,71 @@
  116. #include <unistd.h>
  117. #include <errno.h>
  118. #include <sys/ioctl.h>
  119. -
  120. +#if LINUX
  121. +#include <fcntl.h>
  122. +#include <sys/stat.h>
  123. +#else
  124. #include <IOKit/storage/IOMediaBSDClient.h>
  125. -
  126. +#endif /* LINUX */
  127. #else
  128. -
  129. #include <Files.h>
  130. #include <Device.h>
  131. #include <Disks.h>
  132. #endif
  133. -
  134. OSErr GetDeviceSize(int driveRefNum, UInt64 *numBlocks, UInt32 *blockSize)
  135. {
  136. #if BSD
  137. UInt64 devBlockCount = 0;
  138. int devBlockSize = 0;
  139. +#if LINUX
  140. + struct stat stbuf;
  141. +
  142. + devBlockSize = 512;
  143. +#ifndef BLKGETSIZE
  144. +#define BLKGETSIZE _IO(0x12,96)
  145. +#endif
  146. +#ifndef BLKGETSIZE64
  147. +#define BLKGETSIZE64 _IOR(0x12,114,size_t)
  148. +#endif
  149. + if (fstat(driveRefNum, &stbuf) < 0){
  150. + printf("Error: %s\n", strerror(errno));
  151. + return(-1);
  152. + }
  153. +
  154. + if (S_ISREG(stbuf.st_mode)) {
  155. + devBlockCount = stbuf.st_size / 512;
  156. + }
  157. + else if (S_ISBLK(stbuf.st_mode)) {
  158. + unsigned long size;
  159. + u_int64_t size64;
  160. + if (!ioctl(driveRefNum, BLKGETSIZE64, &size64))
  161. + devBlockCount = size64 / 512;
  162. + else if (!ioctl(driveRefNum, BLKGETSIZE, &size))
  163. + devBlockCount = size;
  164. + else{
  165. + printf("Error: %s\n", strerror(errno));
  166. + return(-1);
  167. + }
  168. +
  169. + }
  170. + else{
  171. + printf("Device is not a block device");
  172. + return(-1);
  173. + }
  174. +#elif BSD
  175. if (ioctl(driveRefNum, DKIOCGETBLOCKCOUNT, &devBlockCount) < 0) {
  176. printf("ioctl(DKIOCGETBLOCKCOUNT) for fd %d: %s\n", driveRefNum, strerror(errno));
  177. return (-1);
  178. }
  179. -
  180. +
  181. if (ioctl(driveRefNum, DKIOCGETBLOCKSIZE, &devBlockSize) < 0) {
  182. printf("ioctl(DKIOCGETBLOCKSIZE) for fd %d: %s\n", driveRefNum, strerror(errno));
  183. return (-1);
  184. }
  185. +#endif /* BSD */
  186. if (devBlockSize != 512) {
  187. *numBlocks = (devBlockCount * (UInt64)devBlockSize) / 512;
  188. @@ -70,24 +108,24 @@ OSErr GetDeviceSize(int driveRefNum, UInt64 *numBlocks, UInt32 *blockSize)
  189. {
  190. /* return format list status code */
  191. kFmtLstCode = 6,
  192. -
  193. +
  194. /* reference number of .SONY driver */
  195. kSonyRefNum = 0xfffb,
  196. -
  197. +
  198. /* values returned by DriveStatus in DrvSts.twoSideFmt */
  199. kSingleSided = 0,
  200. kDoubleSided = -1,
  201. kSingleSidedSize = 800, /* 400K */
  202. kDoubleSidedSize = 1600, /* 800K */
  203. -
  204. +
  205. /* values in DrvQEl.qType */
  206. kWordDrvSiz = 0,
  207. kLongDrvSiz = 1,
  208. -
  209. +
  210. /* more than enough formatListRecords */
  211. kMaxFormatListRecs = 16
  212. };
  213. -
  214. +
  215. ParamBlockRec pb;
  216. FormatListRec formatListRecords[kMaxFormatListRecs];
  217. DrvSts status;
  218. @@ -95,22 +133,22 @@ OSErr GetDeviceSize(int driveRefNum, UInt64 *numBlocks, UInt32 *blockSize)
  219. OSErr result;
  220. unsigned long blocks = 0;
  221. -
  222. +
  223. /* Attempt to get the drive's format list. */
  224. /* (see the Technical Note "What Your Sony Drives For You") */
  225. -
  226. +
  227. pb.cntrlParam.ioVRefNum = driveQElementPtr->dQDrive;
  228. pb.cntrlParam.ioCRefNum = driveQElementPtr->dQRefNum;
  229. pb.cntrlParam.csCode = kFmtLstCode;
  230. pb.cntrlParam.csParam[0] = kMaxFormatListRecs;
  231. *(long *)&pb.cntrlParam.csParam[1] = (long)&formatListRecords[0];
  232. -
  233. +
  234. result = PBStatusSync(&pb);
  235. -
  236. +
  237. if ( result == noErr )
  238. {
  239. /* The drive supports ReturnFormatList status call. */
  240. -
  241. +
  242. /* Get the current disk's size. */
  243. for( formatListRecIndex = 0;
  244. formatListRecIndex < pb.cntrlParam.csParam[0];
  245. @@ -131,7 +169,7 @@ OSErr GetDeviceSize(int driveRefNum, UInt64 *numBlocks, UInt32 *blockSize)
  246. else if ( driveQElementPtr->dQRefNum == (short)kSonyRefNum )
  247. {
  248. /* The drive is a non-SuperDrive floppy which only supports 400K and 800K disks */
  249. -
  250. +
  251. result = DriveStatus(driveQElementPtr->dQDrive, &status);
  252. if ( result == noErr )
  253. {
  254. @@ -140,11 +178,11 @@ OSErr GetDeviceSize(int driveRefNum, UInt64 *numBlocks, UInt32 *blockSize)
  255. case kSingleSided:
  256. blocks = kSingleSidedSize;
  257. break;
  258. -
  259. +
  260. case kDoubleSided:
  261. blocks = kDoubleSidedSize;
  262. break;
  263. -
  264. +
  265. default: // This should never happen
  266. result = paramErr;
  267. break;
  268. @@ -155,20 +193,20 @@ OSErr GetDeviceSize(int driveRefNum, UInt64 *numBlocks, UInt32 *blockSize)
  269. {
  270. /* The drive is not a floppy and it doesn't support ReturnFormatList */
  271. /* so use the dQDrvSz field(s) */
  272. -
  273. +
  274. result = noErr; /* reset result */
  275. -
  276. +
  277. switch ( driveQElementPtr->qType )
  278. {
  279. case kWordDrvSiz:
  280. blocks = driveQElementPtr->dQDrvSz;
  281. break;
  282. -
  283. +
  284. case kLongDrvSiz:
  285. blocks = ((unsigned long)driveQElementPtr->dQDrvSz2 << 16) +
  286. driveQElementPtr->dQDrvSz;
  287. break;
  288. -
  289. +
  290. default: // This should never happen
  291. result = paramErr;
  292. break;
  293. @@ -177,7 +215,7 @@ OSErr GetDeviceSize(int driveRefNum, UInt64 *numBlocks, UInt32 *blockSize)
  294. *numBlocks = blocks;
  295. *blockSize = 512;
  296. -
  297. +
  298. return( result );
  299. #endif
  300. }
  301. @@ -188,7 +226,7 @@ OSErr DeviceRead(int device, int drive, void* buffer, SInt64 offset, UInt32 reqB
  302. #if BSD
  303. off_t seek_off;
  304. ssize_t nbytes;
  305. -
  306. +
  307. *actBytes = 0;
  308. seek_off = lseek(device, offset, SEEK_SET);
  309. diff --git a/fsck_hfs.tproj/dfalib/SKeyCompare.c b/fsck_hfs.tproj/dfalib/SKeyCompare.c
  310. index 46e145f..18d99c5 100644
  311. --- a/fsck_hfs.tproj/dfalib/SKeyCompare.c
  312. +++ b/fsck_hfs.tproj/dfalib/SKeyCompare.c
  313. @@ -454,7 +454,9 @@ SInt32 CompareExtentKeysPlus( const HFSPlusExtentKey *searchKey, const HFSPlusEx
  314. * The name portion of the key is compared using a 16-bit binary comparison.
  315. * This is called from the b-tree code.
  316. */
  317. +#if !LINUX
  318. __private_extern__
  319. +#endif
  320. SInt32
  321. CompareAttributeKeys(const AttributeKey *searchKey, const AttributeKey *trialKey)
  322. {
  323. diff --git a/fsck_hfs.tproj/dfalib/SRepair.c b/fsck_hfs.tproj/dfalib/SRepair.c
  324. index 01c1a10..8eb759c 100644
  325. --- a/fsck_hfs.tproj/dfalib/SRepair.c
  326. +++ b/fsck_hfs.tproj/dfalib/SRepair.c
  327. @@ -1617,7 +1617,9 @@ Output:
  328. static OSErr FixWrapperExtents( SGlobPtr GPtr, RepairOrderPtr p )
  329. {
  330. +#if !LINUX
  331. #pragma unused (p)
  332. +#endif
  333. OSErr err;
  334. HFSMasterDirectoryBlock *mdb;
  335. diff --git a/fsck_hfs.tproj/dfalib/SRuntime.h b/fsck_hfs.tproj/dfalib/SRuntime.h
  336. index 646917b..770e3ef 100644
  337. --- a/fsck_hfs.tproj/dfalib/SRuntime.h
  338. +++ b/fsck_hfs.tproj/dfalib/SRuntime.h
  339. @@ -27,8 +27,11 @@
  340. #define __SRUNTIME__
  341. #if BSD
  342. -
  343. +#if LINUX
  344. +#include "missing.h"
  345. +#else
  346. #include <sys/types.h>
  347. +#endif
  348. #include <stdlib.h>
  349. #include <string.h>
  350. #include <stdio.h>
  351. @@ -91,10 +94,12 @@ typedef const unsigned char * ConstStr255Param;
  352. typedef u_int32_t HFSCatalogNodeID;
  353. +#if !LINUX
  354. enum {
  355. false = 0,
  356. true = 1
  357. };
  358. +#endif
  359. /* OS error codes */
  360. enum {
  361. diff --git a/fsck_hfs.tproj/dfalib/SUtils.c b/fsck_hfs.tproj/dfalib/SUtils.c
  362. index 72035f0..6e9253e 100644
  363. --- a/fsck_hfs.tproj/dfalib/SUtils.c
  364. +++ b/fsck_hfs.tproj/dfalib/SUtils.c
  365. @@ -380,7 +380,8 @@ void InvalidateCalculatedVolumeBitMap( SGlobPtr GPtr )
  366. // GPtr->realVCB Real in-memory vcb
  367. //------------------------------------------------------------------------------
  368. -#if !BSD
  369. +#if BSD
  370. +#if !LINUX
  371. OSErr GetVolumeFeatures( SGlobPtr GPtr )
  372. {
  373. OSErr err;
  374. @@ -418,7 +419,7 @@ OSErr GetVolumeFeatures( SGlobPtr GPtr )
  375. return( noErr );
  376. }
  377. #endif
  378. -
  379. +#endif
  380. /*-------------------------------------------------------------------------------
  381. diff --git a/fsck_hfs.tproj/dfalib/SVerify2.c b/fsck_hfs.tproj/dfalib/SVerify2.c
  382. index 6a47935..c68f3d8 100644
  383. --- a/fsck_hfs.tproj/dfalib/SVerify2.c
  384. +++ b/fsck_hfs.tproj/dfalib/SVerify2.c
  385. @@ -32,7 +32,9 @@
  386. */
  387. #include <sys/ioctl.h>
  388. +#if !LINUX
  389. #include <sys/disk.h>
  390. +#endif
  391. #include "BTree.h"
  392. #include "BTreePrivate.h"
  393. @@ -1354,8 +1356,13 @@ OSErr CompareVolumeHeader( SGlobPtr GPtr, HFSPlusVolumeHeader *volumeHeader )
  394. * clump size for read-only media is irrelevant we skip the clump size
  395. * check to avoid non useful warnings.
  396. */
  397. +#if LINUX
  398. + // FIXME
  399. + isWriteable = 1;
  400. +#else
  401. isWriteable = 0;
  402. ioctl( GPtr->DrvNum, DKIOCISWRITABLE, &isWriteable );
  403. +#endif
  404. if ( isWriteable != 0 &&
  405. volumeHeader->catalogFile.clumpSize != vcb->vcbCatalogFile->fcbClumpSize ) {
  406. PrintError(GPtr, E_InvalidClumpSize, 0);
  407. diff --git a/fsck_hfs.tproj/dfalib/Scavenger.h b/fsck_hfs.tproj/dfalib/Scavenger.h
  408. index cf53970..edb3a80 100644
  409. --- a/fsck_hfs.tproj/dfalib/Scavenger.h
  410. +++ b/fsck_hfs.tproj/dfalib/Scavenger.h
  411. @@ -37,11 +37,16 @@
  412. #include "../fsck_debug.h"
  413. #include <assert.h>
  414. +#if LINUX
  415. +#define XATTR_MAXNAMELEN 127
  416. +#include <limits.h>
  417. +#else
  418. #include <sys/xattr.h>
  419. #include <sys/acl.h>
  420. #include <sys/kauth.h>
  421. -#include <sys/errno.h>
  422. #include <sys/syslimits.h>
  423. +#endif
  424. +#include <sys/errno.h>
  425. #ifdef __cplusplus
  426. extern "C" {
  427. @@ -1465,4 +1470,8 @@ extern int AllocateContigBitmapBits (SVCB *vcb, UInt32 numBlocks, UInt32 *actua
  428. };
  429. #endif
  430. +/* #if LINUX
  431. +#undef XATTR_MAXNAMELEN
  432. +#endif */
  433. +
  434. #endif /* __SCAVENGER__ */
  435. diff --git a/fsck_hfs.tproj/dfalib/hfs_endian.c b/fsck_hfs.tproj/dfalib/hfs_endian.c
  436. index 7fa5385..69500c1 100755
  437. --- a/fsck_hfs.tproj/dfalib/hfs_endian.c
  438. +++ b/fsck_hfs.tproj/dfalib/hfs_endian.c
  439. @@ -31,7 +31,11 @@
  440. #include <sys/types.h>
  441. #include <sys/stat.h>
  442. +#if LINUX
  443. +#include "missing.h"
  444. +#else
  445. #include <architecture/byte_order.h>
  446. +#endif
  447. #include <hfs/hfs_format.h>
  448. #include "Scavenger.h"
  449. diff --git a/fsck_hfs.tproj/dfalib/hfs_endian.h b/fsck_hfs.tproj/dfalib/hfs_endian.h
  450. index 52d0c3a..0763d9d 100755
  451. --- a/fsck_hfs.tproj/dfalib/hfs_endian.h
  452. +++ b/fsck_hfs.tproj/dfalib/hfs_endian.h
  453. @@ -27,9 +27,14 @@
  454. *
  455. * This file prototypes endian swapping routines for the HFS/HFS Plus
  456. * volume format.
  457. - */
  458. +*/
  459. #include <hfs/hfs_format.h>
  460. +#if LINUX
  461. +#include <endian.h>
  462. +#include <byteswap.h>
  463. +#else
  464. #include <architecture/byte_order.h>
  465. +#endif
  466. #include "SRuntime.h"
  467. /*********************/
  468. diff --git a/fsck_hfs.tproj/fsck_hfs.c b/fsck_hfs.tproj/fsck_hfs.c
  469. index 90532fd..f1a18bd 100644
  470. --- a/fsck_hfs.tproj/fsck_hfs.c
  471. +++ b/fsck_hfs.tproj/fsck_hfs.c
  472. @@ -24,10 +24,14 @@
  473. #include <sys/types.h>
  474. #include <sys/stat.h>
  475. #include <sys/param.h>
  476. +#if !LINUX
  477. #include <sys/ucred.h>
  478. +#endif
  479. #include <sys/mount.h>
  480. #include <sys/ioctl.h>
  481. +#if !LINUX
  482. #include <sys/disk.h>
  483. +#endif
  484. #include <hfs/hfs_mount.h>
  485. @@ -195,8 +199,12 @@ main(argc, argv)
  486. if (guiControl)
  487. debug = 0; /* debugging is for command line only */
  488. +#if LINUX
  489. +// FIXME
  490. +#else
  491. if (signal(SIGINT, SIG_IGN) != SIG_IGN)
  492. (void)signal(SIGINT, catch);
  493. +#endif
  494. if (argc < 1) {
  495. (void) fprintf(stderr, "%s: missing special-device\n", progname);
  496. @@ -218,7 +226,9 @@ checkfilesys(char * filesys)
  497. int chkLev, repLev, logLev;
  498. int blockDevice_fd, canWrite;
  499. char *unraw, *mntonname;
  500. +#if !LINUX
  501. struct statfs *fsinfo;
  502. +#endif
  503. int fs_fd=-1; // fd to the root-dir of the fs we're checking (only w/lfag == 1)
  504. flags = 0;
  505. @@ -227,7 +237,9 @@ checkfilesys(char * filesys)
  506. canWrite = 0;
  507. unraw = NULL;
  508. mntonname = NULL;
  509. -
  510. +#if LINUX
  511. + // FIXME
  512. +#else
  513. if (lflag) {
  514. result = getmntinfo(&fsinfo, MNT_NOWAIT);
  515. @@ -257,10 +269,10 @@ checkfilesys(char * filesys)
  516. }
  517. }
  518. }
  519. -
  520. +#endif
  521. if (debug && preen)
  522. pwarn("starting\n");
  523. -
  524. +
  525. if (setup( filesys, &blockDevice_fd, &canWrite ) == 0) {
  526. if (preen)
  527. pfatal("CAN'T CHECK FILE SYSTEM.");
  528. @@ -278,7 +290,7 @@ checkfilesys(char * filesys)
  529. repLev = kMajorRepairs;
  530. logLev = kVerboseLog;
  531. - if (yflag)
  532. + if (yflag)
  533. repLev = kMajorRepairs;
  534. if (quick) {
  535. @@ -298,16 +310,16 @@ checkfilesys(char * filesys)
  536. if (nflag)
  537. repLev = kNeverRepair;
  538. -
  539. +
  540. if ( rebuildCatalogBtree ) {
  541. chkLev = kPartialCheck;
  542. repLev = kForceRepairs; // this will force rebuild of catalog B-Tree file
  543. }
  544. -
  545. +
  546. /*
  547. * go check HFS volume...
  548. */
  549. - result = CheckHFS( fsreadfd, fswritefd, chkLev, repLev, logLev,
  550. + result = CheckHFS( fsreadfd, fswritefd, chkLev, repLev, logLev,
  551. guiControl, lostAndFoundMode, canWrite, &fsmodified );
  552. if (!hotroot) {
  553. ckfini(1);
  554. @@ -330,6 +342,9 @@ checkfilesys(char * filesys)
  555. }
  556. }
  557. } else {
  558. +#if LINUX
  559. + // FIXME
  560. +#else
  561. struct statfs stfs_buf;
  562. /*
  563. * Check to see if root is mounted read-write.
  564. @@ -339,19 +354,25 @@ checkfilesys(char * filesys)
  565. else
  566. flags = 0;
  567. ckfini(flags & MNT_RDONLY);
  568. +#endif
  569. }
  570. /* XXX free any allocated memory here */
  571. if (hotroot && fsmodified) {
  572. +#if !LINUX
  573. struct hfs_mount_args args;
  574. +#endif
  575. /*
  576. * We modified the root. Do a mount update on
  577. * it, unless it is read-write, so we can continue.
  578. */
  579. if (!preen)
  580. printf("\n***** FILE SYSTEM WAS MODIFIED *****\n");
  581. - if (flags & MNT_RDONLY) {
  582. +#if LINUX
  583. + // FIXME
  584. +#else
  585. + if (flags & MNT_RDONLY) {
  586. bzero(&args, sizeof(args));
  587. flags |= MNT_UPDATE | MNT_RELOAD;
  588. if (mount("hfs", "/", flags, &args) == 0) {
  589. @@ -359,6 +380,7 @@ checkfilesys(char * filesys)
  590. goto ExitThisRoutine;
  591. }
  592. }
  593. +#endif
  594. if (!preen)
  595. printf("\n***** REBOOT NOW *****\n");
  596. sync();
  597. @@ -367,7 +389,7 @@ checkfilesys(char * filesys)
  598. }
  599. result = (result == 0) ? 0 : EEXIT;
  600. -
  601. +
  602. ExitThisRoutine:
  603. if (lflag) {
  604. fcntl(fs_fd, F_THAW_FS, NULL);
  605. @@ -401,16 +423,18 @@ setup( char *dev, int *blockDevice_fdPtr, int *canWritePtr )
  606. fswritefd = -1;
  607. *blockDevice_fdPtr = -1;
  608. *canWritePtr = 0;
  609. -
  610. +
  611. if (stat(dev, &statb) < 0) {
  612. printf("Can't stat %s: %s\n", dev, strerror(errno));
  613. return (0);
  614. }
  615. +#if !LINUX
  616. if ((statb.st_mode & S_IFMT) != S_IFCHR) {
  617. pfatal("%s is not a character device", dev);
  618. if (reply("CONTINUE") == 0)
  619. return (0);
  620. }
  621. +#endif
  622. if ((fsreadfd = open(dev, O_RDONLY)) < 0) {
  623. printf("Can't open %s: %s\n", dev, strerror(errno));
  624. return (0);
  625. @@ -419,7 +443,7 @@ setup( char *dev, int *blockDevice_fdPtr, int *canWritePtr )
  626. /* attempt to get write access to the block device and if not check if volume is */
  627. /* mounted read-only. */
  628. getWriteAccess( dev, blockDevice_fdPtr, canWritePtr );
  629. -
  630. +
  631. if (preen == 0 && !guiControl)
  632. printf("** %s", dev);
  633. if (nflag || (fswritefd = open(dev, O_WRONLY)) < 0) {
  634. @@ -433,10 +457,14 @@ setup( char *dev, int *blockDevice_fdPtr, int *canWritePtr )
  635. printf("\n");
  636. /* Get device block size to initialize cache */
  637. +#if LINUX
  638. + devBlockSize = 512;
  639. +#else
  640. if (ioctl(fsreadfd, DKIOCGETBLOCKSIZE, &devBlockSize) < 0) {
  641. pfatal ("Can't get device block size\n");
  642. return (0);
  643. }
  644. +#endif
  645. /* calculate the cache block size and total blocks */
  646. if (CalculateCacheSize(userCacheSize, &cacheBlockSize, &cacheTotalBlocks, debug) != 0) {
  647. @@ -463,11 +491,15 @@ setup( char *dev, int *blockDevice_fdPtr, int *canWritePtr )
  648. static void getWriteAccess( char *dev, int *blockDevice_fdPtr, int *canWritePtr )
  649. {
  650. +#if !LINUX
  651. int i;
  652. int myMountsCount;
  653. +#endif
  654. void * myPtr;
  655. char * myCharPtr;
  656. +#if !LINUX
  657. struct statfs * myBufPtr;
  658. +#endif
  659. void * myNamePtr;
  660. myPtr = NULL;
  661. @@ -490,6 +522,9 @@ static void getWriteAccess( char *dev, int *blockDevice_fdPtr, int *canWritePtr
  662. }
  663. // get count of mounts then get the info for each
  664. +#if LINUX
  665. + // FIXME
  666. +#else
  667. myMountsCount = getfsstat( NULL, 0, MNT_NOWAIT );
  668. if ( myMountsCount < 0 )
  669. goto ExitThisRoutine;
  670. @@ -513,8 +548,8 @@ static void getWriteAccess( char *dev, int *blockDevice_fdPtr, int *canWritePtr
  671. }
  672. myBufPtr++;
  673. }
  674. - *canWritePtr = 1; // single user will get us here, f_mntfromname is not /dev/diskXXXX
  675. -
  676. +#endif
  677. + *canWritePtr = 1; // single user will get us here, f_mntfromname is not /dev/diskXXXX
  678. ExitThisRoutine:
  679. if ( myPtr != NULL )
  680. free( myPtr );
  681. diff --git a/fsck_hfs.tproj/utilities.c b/fsck_hfs.tproj/utilities.c
  682. index ee41bef..8e1cd77 100644
  683. --- a/fsck_hfs.tproj/utilities.c
  684. +++ b/fsck_hfs.tproj/utilities.c
  685. @@ -183,12 +183,14 @@ retry:
  686. printf("Can't stat %s\n", raw);
  687. return (origname);
  688. }
  689. +#if !LINUX
  690. if ((stchar.st_mode & S_IFMT) == S_IFCHR) {
  691. return (raw);
  692. } else {
  693. printf("%s is not a character device\n", raw);
  694. return (origname);
  695. }
  696. +#endif
  697. } else if ((stblock.st_mode & S_IFMT) == S_IFCHR && !retried) {
  698. newname = unrawname(newname);
  699. retried++;
  700. @@ -214,7 +216,11 @@ rawname(char *name)
  701. *dp = 0;
  702. (void)strcpy(rawbuf, name);
  703. *dp = '/';
  704. - (void)strcat(rawbuf, "/r");
  705. +#if LINUX
  706. + (void)strcat(rawbuf, "/");
  707. +#else
  708. + (void)strcat(rawbuf,"/r");
  709. +#endif
  710. (void)strcat(rawbuf, &dp[1]);
  711. return (rawbuf);
  712. diff --git a/include/missing.h b/include/missing.h
  713. new file mode 100644
  714. index 0000000..0a859c4
  715. --- /dev/null
  716. +++ b/include/missing.h
  717. @@ -0,0 +1,114 @@
  718. +#ifndef _MISSING_H_
  719. +#define _MISSING_H_
  720. +
  721. +#include <endian.h>
  722. +#include <byteswap.h>
  723. +#include <errno.h>
  724. +#include <stdint.h>
  725. +#include <string.h>
  726. +
  727. +#define MAXBSIZE (256 * 4096)
  728. +
  729. +#ifndef true
  730. +#define true 1
  731. +#endif
  732. +#ifndef false
  733. +#define false 0
  734. +#endif
  735. +
  736. +/* Mac types */
  737. +
  738. +/* 8 Bit */
  739. +#ifndef UInt8
  740. +#define UInt8 uint8_t
  741. +#endif
  742. +#ifndef u_int8_t
  743. +#define u_int8_t UInt8
  744. +#endif
  745. +#ifndef SInt8
  746. +#define SInt8 int8_t
  747. +#endif
  748. +
  749. +/* 16 Bit */
  750. +#ifndef UInt16
  751. +#define UInt16 uint16_t
  752. +#endif
  753. +#ifndef u_int16_t
  754. +#define u_int16_t UInt16
  755. +#endif
  756. +#ifndef SInt16
  757. +#define SInt16 int16_t
  758. +#endif
  759. +
  760. +/* 32 Bit */
  761. +#ifndef UInt32
  762. +#define UInt32 uint32_t
  763. +#endif
  764. +#ifndef u_int32_t
  765. +#define u_int32_t UInt32
  766. +#endif
  767. +#ifndef SInt32
  768. +#define SInt32 int32_t
  769. +#endif
  770. +
  771. +/* 64 Bit */
  772. +#ifndef UInt64
  773. +#define UInt64 uint64_t
  774. +#endif
  775. +#ifndef u_int64_t
  776. +#define u_int64_t UInt64
  777. +#endif
  778. +#ifndef SInt64
  779. +#define SInt64 int64_t
  780. +#endif
  781. +
  782. +#define UniChar u_int16_t
  783. +#define Boolean u_int8_t
  784. +
  785. +#define UF_NODUMP 0x00000001
  786. +
  787. +/* syslimits.h */
  788. +#define NAME_MAX 255
  789. +
  790. +/* Byteswap stuff */
  791. +#define NXSwapHostLongToBig(x) cpu_to_be64(x)
  792. +#define NXSwapBigShortToHost(x) be16_to_cpu(x)
  793. +#define OSSwapBigToHostInt16(x) be16_to_cpu(x)
  794. +#define NXSwapBigLongToHost(x) be32_to_cpu(x)
  795. +#define OSSwapBigToHostInt32(x) be32_to_cpu(x)
  796. +#define NXSwapBigLongLongToHost(x) be64_to_cpu(x)
  797. +#define OSSwapBigToHostInt64(x) be64_to_cpu(x)
  798. +
  799. +#if __BYTE_ORDER == __LITTLE_ENDIAN
  800. +/* Big Endian Swaps */
  801. +#ifndef be16_to_cpu
  802. +#define be16_to_cpu(x) bswap_16(x)
  803. +#endif
  804. +#ifndef be32_to_cpu
  805. +#define be32_to_cpu(x) bswap_32(x)
  806. +#endif
  807. +#ifndef be64_to_cpu
  808. +#define be64_to_cpu(x) bswap_64(x)
  809. +#endif
  810. +#ifndef cpu_to_be64
  811. +#define cpu_to_be64(x) bswap_64(x)
  812. +#endif
  813. +#elif __BYTE_ORDER == __BIG_ENDIAN
  814. +/* Big endian doesn't swap */
  815. +#ifndef be16_to_cpu
  816. +#define be16_to_cpu(x) (x)
  817. +#endif
  818. +#ifndef be32_to_cpu
  819. +#define be32_to_cpu(x) (x)
  820. +#endif
  821. +#ifndef be64_to_cpu
  822. +#define be64_to_cpu(x) (x)
  823. +#endif
  824. +#ifndef cpu_to_be64
  825. +#define cpu_to_be64(x) (x)
  826. +#endif
  827. +#endif
  828. +
  829. +#define KAUTH_FILESEC_XATTR "com.apple.system.Security"
  830. +
  831. +#endif
  832. diff --git a/newfs_hfs.tproj/hfs_endian.c b/newfs_hfs.tproj/hfs_endian.c
  833. index 117b7f8..fdf7353 100644
  834. --- a/newfs_hfs.tproj/hfs_endian.c
  835. +++ b/newfs_hfs.tproj/hfs_endian.c
  836. @@ -30,7 +30,12 @@
  837. #include <sys/types.h>
  838. #include <sys/stat.h>
  839. +#if LINUX
  840. +#include "missing.h"
  841. +#else
  842. #include <architecture/byte_order.h>
  843. +#endif
  844. +
  845. #include <hfs/hfs_format.h>
  846. #include "hfs_endian.h"
  847. diff --git a/newfs_hfs.tproj/hfs_endian.h b/newfs_hfs.tproj/hfs_endian.h
  848. index 8d9d01d..5c7ff57 100644
  849. --- a/newfs_hfs.tproj/hfs_endian.h
  850. +++ b/newfs_hfs.tproj/hfs_endian.h
  851. @@ -29,7 +29,12 @@
  852. * volume format.
  853. */
  854. #include <hfs/hfs_format.h>
  855. +#if LINUX
  856. +#include <endian.h>
  857. +#include <byteswap.h>
  858. +#else
  859. #include <architecture/byte_order.h>
  860. +#endif
  861. /*********************/
  862. /* BIG ENDIAN Macros */
  863. diff --git a/newfs_hfs.tproj/makehfs.c b/newfs_hfs.tproj/makehfs.c
  864. index 085222f..7609779 100644
  865. --- a/newfs_hfs.tproj/makehfs.c
  866. +++ b/newfs_hfs.tproj/makehfs.c
  867. @@ -31,10 +31,16 @@
  868. #include <sys/param.h>
  869. #include <sys/types.h>
  870. #include <sys/time.h>
  871. +#if LINUX
  872. +#include <time.h>
  873. +#include "missing.h"
  874. +#endif
  875. #include <sys/errno.h>
  876. #include <sys/stat.h>
  877. #include <sys/sysctl.h>
  878. +#if !LINUX
  879. #include <sys/vmmeter.h>
  880. +#endif
  881. #include <err.h>
  882. #include <errno.h>
  883. @@ -47,13 +53,14 @@
  884. #include <openssl/sha.h>
  885. +#if !LINUX
  886. #include <architecture/byte_order.h>
  887. #include <CoreFoundation/CFString.h>
  888. #include <CoreFoundation/CFStringEncodingExt.h>
  889. extern Boolean _CFStringGetFileSystemRepresentation(CFStringRef string, UInt8 *buffer, CFIndex maxBufLen);
  890. -
  891. +#endif
  892. #include <hfs/hfs_format.h>
  893. #include <hfs/hfs_mount.h>
  894. @@ -129,7 +136,9 @@ static UInt32 Largest __P((UInt32 a, UInt32 b, UInt32 c, UInt32 d ));
  895. static void MarkBitInAllocationBuffer __P((HFSPlusVolumeHeader *header,
  896. UInt32 allocationBlock, void* sectorBuffer, UInt32 *sector));
  897. +#if !LINUX
  898. static UInt32 GetDefaultEncoding();
  899. +#endif
  900. static UInt32 UTCToLocal __P((UInt32 utcTime));
  901. @@ -158,11 +167,14 @@ void SETOFFSET (void *buffer, UInt16 btNodeSize, SInt16 recOffset, SInt16 vecOff
  902. #define ROUNDUP(x, u) (((x) % (u) == 0) ? (x) : ((x)/(u) + 1) * (u))
  903. -#define ENCODING_TO_BIT(e) \
  904. +#if LINUX
  905. +#define ENCODING_TO_BIT(e) (e)
  906. +#else
  907. +#define ENCODING_TO_BIT(e)
  908. ((e) < 48 ? (e) : \
  909. ((e) == kCFStringEncodingMacUkrainian ? 48 : \
  910. ((e) == kCFStringEncodingMacFarsi ? 49 : 0)))
  911. -
  912. +#endif
  913. /*
  914. * make_hfs
  915. *
  916. @@ -528,6 +540,7 @@ InitMDB(hfsparams_t *defaults, UInt32 driveBlocks, HFS_MDB *mdbp)
  917. * Map UTF-8 input into a Mac encoding.
  918. * On conversion errors "untitled" is used as a fallback.
  919. */
  920. +#if !LINUX
  921. {
  922. UniChar unibuf[kHFSMaxVolumeNameChars];
  923. CFStringRef cfstr;
  924. @@ -553,7 +566,11 @@ InitMDB(hfsparams_t *defaults, UInt32 driveBlocks, HFS_MDB *mdbp)
  925. bcopy(&mdbp->drVN[1], defaults->volumeName, mdbp->drVN[0]);
  926. defaults->volumeName[mdbp->drVN[0]] = '\0';
  927. }
  928. +#endif
  929. /* Save the encoding hint in the Finder Info (field 4). */
  930. + mdbp->drVN[0] = strlen(defaults->volumeName);
  931. + bcopy(defaults->volumeName,&mdbp->drVN[1],mdbp->drVN[0]);
  932. +
  933. mdbp->drFndrInfo[4] = SET_HFS_TEXT_ENCODING(defaults->encodingHint);
  934. mdbp->drWrCnt = kWriteSeqNum;
  935. @@ -1100,9 +1117,11 @@ InitCatalogRoot_HFSPlus(const hfsparams_t *dp, const HFSPlusVolumeHeader *header
  936. UInt16 nodeSize;
  937. SInt16 offset;
  938. UInt32 unicodeBytes;
  939. +#if !LINUX
  940. UInt8 canonicalName[256];
  941. CFStringRef cfstr;
  942. Boolean cfOK;
  943. +#endif
  944. int index = 0;
  945. nodeSize = dp->catalogNodeSize;
  946. @@ -1122,7 +1141,9 @@ InitCatalogRoot_HFSPlus(const hfsparams_t *dp, const HFSPlusVolumeHeader *header
  947. * First record is always the root directory...
  948. */
  949. ckp = (HFSPlusCatalogKey *)((UInt8 *)buffer + offset);
  950. -
  951. +#if LINUX
  952. + ConvertUTF8toUnicode(dp->volumeName, sizeof(ckp->nodeName.unicode), ckp->nodeName.unicode, &ckp->nodeName.length);
  953. +#else
  954. /* Use CFString functions to get a HFSPlus Canonical name */
  955. cfstr = CFStringCreateWithCString(kCFAllocatorDefault, (char *)dp->volumeName, kCFStringEncodingUTF8);
  956. cfOK = _CFStringGetFileSystemRepresentation(cfstr, canonicalName, sizeof(canonicalName));
  957. @@ -1139,6 +1160,7 @@ InitCatalogRoot_HFSPlus(const hfsparams_t *dp, const HFSPlusVolumeHeader *header
  958. dp->volumeName, kDefaultVolumeNameStr);
  959. }
  960. CFRelease(cfstr);
  961. +#endif
  962. ckp->nodeName.length = SWAP_BE16 (ckp->nodeName.length);
  963. unicodeBytes = sizeof(UniChar) * SWAP_BE16 (ckp->nodeName.length);
  964. @@ -1821,15 +1843,15 @@ WriteBuffer(const DriveInfo *driveInfo, UInt64 startingSector, UInt32 byteCount,
  965. off_t sector;
  966. if ((byteCount % driveInfo->sectorSize) != 0)
  967. - errx(1, "WriteBuffer: byte count %ld is not sector size multiple", byteCount);
  968. + errx(1, "WriteBuffer: byte count %i is not sector size multiple", byteCount);
  969. sector = driveInfo->sectorOffset + startingSector;
  970. if (lseek(driveInfo->fd, sector * driveInfo->sectorSize, SEEK_SET) < 0)
  971. - err(1, "seek (sector %qd)", sector);
  972. + err(1, "seek (sector %lld)", sector);
  973. if (write(driveInfo->fd, buffer, byteCount) != byteCount)
  974. - err(1, "write (sector %qd, %ld bytes)", sector, byteCount);
  975. + err(1, "write (sector %lld, %i bytes)", sector, byteCount);
  976. }
  977. @@ -1913,7 +1935,7 @@ DivideAndRoundUp(UInt32 numerator, UInt32 denominator)
  978. return quotient;
  979. }
  980. -
  981. +#if !LINUX
  982. #define __kCFUserEncodingFileName ("/.CFUserTextEncoding")
  983. static UInt32
  984. @@ -1939,7 +1961,7 @@ GetDefaultEncoding()
  985. }
  986. return 0;
  987. }
  988. -
  989. +#endif
  990. static int
  991. ConvertUTF8toUnicode(const UInt8* source, UInt32 bufsize, UniChar* unibuf,
  992. @@ -2006,6 +2028,9 @@ ConvertUTF8toUnicode(const UInt8* source, UInt32 bufsize, UniChar* unibuf,
  993. static int
  994. getencodinghint(unsigned char *name)
  995. {
  996. +#if LINUX
  997. + return(0);
  998. +#else
  999. int mib[3];
  1000. size_t buflen = sizeof(int);
  1001. struct vfsconf vfc;
  1002. @@ -2023,7 +2048,8 @@ getencodinghint(unsigned char *name)
  1003. return (hint);
  1004. error:
  1005. hint = GetDefaultEncoding();
  1006. - return (hint);
  1007. + return (0);
  1008. +#endif
  1009. }
  1010. @@ -2034,12 +2060,14 @@ void GenerateVolumeUUID(VolumeUUID *newVolumeID) {
  1011. unsigned char digest[20];
  1012. time_t now;
  1013. clock_t uptime;
  1014. - int mib[2];
  1015. - int sysdata;
  1016. - char sysctlstring[128];
  1017. size_t datalen;
  1018. double sysloadavg[3];
  1019. +#if !LINUX
  1020. + int sysdata;
  1021. + int mib[2];
  1022. + char sysctlstring[128];
  1023. struct vmtotal sysvmtotal;
  1024. +#endif
  1025. do {
  1026. /* Initialize the SHA-1 context for processing: */
  1027. @@ -2052,52 +2080,58 @@ void GenerateVolumeUUID(VolumeUUID *newVolumeID) {
  1028. SHA1_Update(&context, &uptime, sizeof(uptime));
  1029. /* The kernel's boot time: */
  1030. +#if !LINUX
  1031. mib[0] = CTL_KERN;
  1032. mib[1] = KERN_BOOTTIME;
  1033. datalen = sizeof(sysdata);
  1034. sysctl(mib, 2, &sysdata, &datalen, NULL, 0);
  1035. SHA1_Update(&context, &sysdata, datalen);
  1036. -
  1037. +#endif
  1038. /* The system's host id: */
  1039. +#if !LINUX
  1040. mib[0] = CTL_KERN;
  1041. mib[1] = KERN_HOSTID;
  1042. datalen = sizeof(sysdata);
  1043. sysctl(mib, 2, &sysdata, &datalen, NULL, 0);
  1044. SHA1_Update(&context, &sysdata, datalen);
  1045. -
  1046. +#endif
  1047. /* The system's host name: */
  1048. +#if !LINUX
  1049. mib[0] = CTL_KERN;
  1050. mib[1] = KERN_HOSTNAME;
  1051. datalen = sizeof(sysctlstring);
  1052. sysctl(mib, 2, sysctlstring, &datalen, NULL, 0);
  1053. SHA1_Update(&context, sysctlstring, datalen);
  1054. -
  1055. +#endif
  1056. /* The running kernel's OS release string: */
  1057. +#if !LINUX
  1058. mib[0] = CTL_KERN;
  1059. mib[1] = KERN_OSRELEASE;
  1060. datalen = sizeof(sysctlstring);
  1061. sysctl(mib, 2, sysctlstring, &datalen, NULL, 0);
  1062. SHA1_Update(&context, sysctlstring, datalen);
  1063. -
  1064. +#endif
  1065. /* The running kernel's version string: */
  1066. +#if !LINUX
  1067. mib[0] = CTL_KERN;
  1068. mib[1] = KERN_VERSION;
  1069. datalen = sizeof(sysctlstring);
  1070. sysctl(mib, 2, sysctlstring, &datalen, NULL, 0);
  1071. SHA1_Update(&context, sysctlstring, datalen);
  1072. -
  1073. +#endif
  1074. /* The system's load average: */
  1075. datalen = sizeof(sysloadavg);
  1076. getloadavg(sysloadavg, 3);
  1077. SHA1_Update(&context, &sysloadavg, datalen);
  1078. /* The system's VM statistics: */
  1079. +#if !LINUX
  1080. mib[0] = CTL_VM;
  1081. mib[1] = VM_METER;
  1082. datalen = sizeof(sysvmtotal);
  1083. sysctl(mib, 2, &sysvmtotal, &datalen, NULL, 0);
  1084. SHA1_Update(&context, &sysvmtotal, datalen);
  1085. -
  1086. +#endif
  1087. /* The current GMT (26 ASCII characters): */
  1088. time(&now);
  1089. strncpy(randomInputBuffer, asctime(gmtime(&now)), 26); /* "Mon Mar 27 13:46:26 2000" */
  1090. diff --git a/newfs_hfs.tproj/newfs_hfs.c b/newfs_hfs.tproj/newfs_hfs.c
  1091. index c4176a9..bf2ed21 100644
  1092. --- a/newfs_hfs.tproj/newfs_hfs.c
  1093. +++ b/newfs_hfs.tproj/newfs_hfs.c
  1094. @@ -38,8 +38,13 @@
  1095. #include <sys/mount.h>
  1096. #include <sys/param.h>
  1097. #include <sys/stat.h>
  1098. +#if LINUX
  1099. +#include <time.h>
  1100. +#endif
  1101. +#if !LINUX
  1102. #include <IOKit/storage/IOMediaBSDClient.h>
  1103. +#endif
  1104. #include <hfs/hfs_format.h>
  1105. #include "newfs_hfs.h"
  1106. @@ -73,7 +78,9 @@ static void usage __P((void));
  1107. char *progname;
  1108. char gVolumeName[kHFSPlusMaxFileNameChars + 1] = {kDefaultVolumeNameStr};
  1109. +#if !LINUX
  1110. char rawdevice[MAXPATHLEN];
  1111. +#endif
  1112. char blkdevice[MAXPATHLEN];
  1113. UInt32 gBlockSize = 0;
  1114. UInt32 gNextCNID = kHFSFirstUserCatalogNodeID;
  1115. @@ -158,8 +165,10 @@ main(argc, argv)
  1116. extern int optind;
  1117. int ch;
  1118. int forceHFS;
  1119. +#if !LINUX
  1120. char *cp, *special;
  1121. struct statfs *mp;
  1122. +#endif
  1123. int n;
  1124. if ((progname = strrchr(*argv, '/')))
  1125. @@ -260,16 +269,19 @@ main(argc, argv)
  1126. usage();
  1127. }
  1128. - argc -= optind;
  1129. - argv += optind;
  1130. + argc -= optind;
  1131. + argv += optind;
  1132. - if (gPartitionSize != 0) {
  1133. - if (argc != 0)
  1134. - usage();
  1135. - } else {
  1136. - if (argc != 1)
  1137. - usage();
  1138. + if (gPartitionSize != 0) {
  1139. + if (argc != 0)
  1140. + usage();
  1141. + } else {
  1142. + if (argc != 1)
  1143. + usage();
  1144. +#if LINUX
  1145. + (void) sprintf(blkdevice, "%s", argv[0]);
  1146. +#else
  1147. special = argv[0];
  1148. cp = strrchr(special, '/');
  1149. if (cp != 0)
  1150. @@ -278,6 +290,7 @@ main(argc, argv)
  1151. special++;
  1152. (void) sprintf(rawdevice, "%sr%s", _PATH_DEV, special);
  1153. (void) sprintf(blkdevice, "%s%s", _PATH_DEV, special);
  1154. +#endif
  1155. }
  1156. if (forceHFS && gJournaled) {
  1157. @@ -301,6 +314,9 @@ main(argc, argv)
  1158. /*
  1159. * Check if target device is aready mounted
  1160. */
  1161. +#if LINUX
  1162. + // FIXME
  1163. +#else
  1164. n = getmntinfo(&mp, MNT_NOWAIT);
  1165. if (n == 0)
  1166. fatal("%s: getmntinfo: %s", blkdevice, strerror(errno));
  1167. @@ -310,15 +326,20 @@ main(argc, argv)
  1168. fatal("%s is mounted on %s", blkdevice, mp->f_mntonname);
  1169. ++mp;
  1170. }
  1171. +#endif
  1172. }
  1173. - if (hfs_newfs(rawdevice, forceHFS, true) < 0) {
  1174. + if (hfs_newfs(blkdevice, forceHFS, true) < 0) {
  1175. +#if LINUX
  1176. + err(1, NULL);
  1177. +#else
  1178. /* On ENXIO error use the block device (to get de-blocking) */
  1179. if (errno == ENXIO) {
  1180. if (hfs_newfs(blkdevice, forceHFS, false) < 0)
  1181. err(1, NULL);
  1182. } else
  1183. err(1, NULL);
  1184. +#endif
  1185. }
  1186. exit(0);
  1187. @@ -506,7 +527,9 @@ hfs_newfs(char *device, int forceHFS, int isRaw)
  1188. int fso = 0;
  1189. int retval = 0;
  1190. hfsparams_t defaults = {0};
  1191. +#if !LINUX
  1192. u_int64_t maxSectorsPerIO;
  1193. +#endif
  1194. if (gPartitionSize) {
  1195. dip.sectorSize = kBytesPerSector;
  1196. @@ -526,6 +549,34 @@ hfs_newfs(char *device, int forceHFS, int isRaw)
  1197. if (fstat( fso, &stbuf) < 0)
  1198. fatal("%s: %s", device, strerror(errno));
  1199. +#if LINUX
  1200. + dip.sectorSize = 512;
  1201. + dip.sectorsPerIO = 256;
  1202. +
  1203. +# ifndef BLKGETSIZE
  1204. +# define BLKGETSIZE _IO(0x12,96)
  1205. +# endif
  1206. +
  1207. +# ifndef BLKGETSIZE64
  1208. +# define BLKGETSIZE64 _IOR(0x12,114,size_t)
  1209. +# endif
  1210. +
  1211. + if (S_ISREG(stbuf.st_mode)) {
  1212. + dip.totalSectors = stbuf.st_size / 512;
  1213. + }
  1214. + else if (S_ISBLK(stbuf.st_mode)) {
  1215. + unsigned long size;
  1216. + u_int64_t size64;
  1217. + if (!ioctl(fso, BLKGETSIZE64, &size64))
  1218. + dip.totalSectors = size64 / 512;
  1219. + else if (!ioctl(fso, BLKGETSIZE, &size))
  1220. + dip.totalSectors = size;
  1221. + else
  1222. + fatal("%s: %s", device, strerror(errno));
  1223. + }
  1224. + else
  1225. + fatal("%s: is not a block device", device);
  1226. +#else
  1227. if (ioctl(fso, DKIOCGETBLOCKCOUNT, &dip.totalSectors) < 0)
  1228. fatal("%s: %s", device, strerror(errno));
  1229. @@ -537,11 +588,14 @@ hfs_newfs(char *device, int forceHFS, int isRaw)
  1230. dip.sectorsPerIO = (128 * 1024) / dip.sectorSize; /* use 128K as default */
  1231. else
  1232. dip.sectorsPerIO = MIN(maxSectorsPerIO, (1024 * 1024) / dip.sectorSize);
  1233. +#endif
  1234. +
  1235. /*
  1236. * The make_hfs code currentlydoes 512 byte sized I/O.
  1237. * If the sector size is bigger than 512, start over
  1238. * using the block device (to get de-blocking).
  1239. */
  1240. +#if !LINUX
  1241. if (dip.sectorSize != kBytesPerSector) {
  1242. if (isRaw) {
  1243. close(fso);
  1244. @@ -556,7 +610,9 @@ hfs_newfs(char *device, int forceHFS, int isRaw)
  1245. dip.sectorSize = kBytesPerSector;
  1246. }
  1247. }
  1248. +#endif
  1249. }
  1250. +
  1251. dip.sectorOffset = 0;
  1252. time(&createtime);
  1253. diff --git a/newfs_hfs.tproj/newfs_hfs.h b/newfs_hfs.tproj/newfs_hfs.h
  1254. index 968ff10..5680a34 100644
  1255. --- a/newfs_hfs.tproj/newfs_hfs.h
  1256. +++ b/newfs_hfs.tproj/newfs_hfs.h
  1257. @@ -19,8 +19,12 @@
  1258. *
  1259. * @APPLE_LICENSE_HEADER_END@
  1260. */
  1261. -
  1262. +
  1263. +#if LINUX
  1264. +#include "missing.h"
  1265. +#else
  1266. #include <CoreFoundation/CFBase.h>
  1267. +#endif
  1268. /*
  1269. * Mac OS Finder flags
  1270. @@ -122,33 +126,33 @@ enum {
  1271. #define kDTDF_FileID 16
  1272. #define kDTDF_Name "Desktop DF"
  1273. #define kDTDF_Chars 10
  1274. -#define kDTDF_Type 'DTFL'
  1275. -#define kDTDF_Creator 'DMGR'
  1276. +#define kDTDF_Type 0x4454464C /* 'DTFL' */
  1277. +#define kDTDF_Creator 0x444D4752 /* 'DMGR' */
  1278. #define kDTDB_FileID 17
  1279. #define kDTDB_Name "Desktop DB"
  1280. #define kDTDB_Chars 10
  1281. -#define kDTDB_Type 'BTFL'
  1282. -#define kDTDB_Creator 'DMGR'
  1283. +#define kDTDB_Type 0x4254464C /* 'BTFL' */
  1284. +#define kDTDB_Creator 0x444D4752 /* 'DMGR' */
  1285. #define kDTDB_Size 1024
  1286. #define kReadMe_FileID 18
  1287. #define kReadMe_Name "ReadMe"
  1288. #define kReadMe_Chars 6
  1289. -#define kReadMe_Type 'ttro'
  1290. -#define kReadMe_Creator 'ttxt'
  1291. +#define kReadMe_Type 0x7474726F /* 'ttro' */
  1292. +#define kReadMe_Creator 0x74747974 /* 'ttxt' */
  1293. #define kFinder_FileID 19
  1294. #define kFinder_Name "Finder"
  1295. #define kFinder_Chars 6
  1296. -#define kFinder_Type 'FNDR'
  1297. -#define kFinder_Creator 'MACS'
  1298. +#define kFinder_Type 0x464E4452 /* 'FNDR' */
  1299. +#define kFinder_Creator 0x4D414353 /* 'MACS' */
  1300. #define kSystem_FileID 20
  1301. #define kSystem_Name "System"
  1302. #define kSystem_Chars 6
  1303. -#define kSystem_Type 'zsys'
  1304. -#define kSystem_Creator 'MACS'
  1305. +#define kSystem_Type 0x7A737973 /* 'zsys' */
  1306. +#define kSystem_Creator 0x4D414353 /* 'MACS' */