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.

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