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
5
Modify some of the files so that they can be compiled without the
6
Apple owned frameworks in a Debian system (and possibly others).
8
fsck_hfs.tproj/cache.c | 4 ++
9
fsck_hfs.tproj/dfalib/BTree.c | 2 +
10
fsck_hfs.tproj/dfalib/BlockCache.c | 3 +
11
fsck_hfs.tproj/dfalib/SBTree.c | 2 +
12
fsck_hfs.tproj/dfalib/SDevice.c | 92 ++++++++++++++++++++---------
13
fsck_hfs.tproj/dfalib/SKeyCompare.c | 2 +
14
fsck_hfs.tproj/dfalib/SRepair.c | 2 +
15
fsck_hfs.tproj/dfalib/SRuntime.h | 7 ++-
16
fsck_hfs.tproj/dfalib/SUtils.c | 5 +-
17
fsck_hfs.tproj/dfalib/SVerify2.c | 7 +++
18
fsck_hfs.tproj/dfalib/Scavenger.h | 11 +++-
19
fsck_hfs.tproj/dfalib/hfs_endian.c | 4 ++
20
fsck_hfs.tproj/dfalib/hfs_endian.h | 7 ++-
21
fsck_hfs.tproj/fsck_hfs.c | 61 +++++++++++++++----
22
fsck_hfs.tproj/utilities.c | 8 ++-
23
include/missing.h | 115 ++++++++++++++++++++++++++++++++++++
24
newfs_hfs.tproj/hfs_endian.c | 5 ++
25
newfs_hfs.tproj/hfs_endian.h | 5 ++
26
newfs_hfs.tproj/makehfs.c | 72 ++++++++++++++++------
27
newfs_hfs.tproj/newfs_hfs.c | 74 ++++++++++++++++++++---
28
newfs_hfs.tproj/newfs_hfs.h | 26 ++++----
29
21 files changed, 429 insertions(+), 85 deletions(-)
30
create mode 100644 include/missing.h
32
diff --git a/fsck_hfs.tproj/cache.c b/fsck_hfs.tproj/cache.c
33
index be46195..527088a 100644
34
--- a/fsck_hfs.tproj/cache.c
35
+++ b/fsck_hfs.tproj/cache.c
43
#include <sys/types.h>
44
+#endif /* __LINUX__ */
48
diff --git a/fsck_hfs.tproj/dfalib/BTree.c b/fsck_hfs.tproj/dfalib/BTree.c
49
index edd8301..7ad9fe0 100644
50
--- a/fsck_hfs.tproj/dfalib/BTree.c
51
+++ b/fsck_hfs.tproj/dfalib/BTree.c
52
@@ -1705,7 +1705,9 @@ OSStatus BTGetInformation (SFCB *filePtr,
57
#pragma unused (version)
60
BTreeControlBlockPtr btreePtr;
62
diff --git a/fsck_hfs.tproj/dfalib/BlockCache.c b/fsck_hfs.tproj/dfalib/BlockCache.c
63
index 1bb952f..e3a28a2 100644
64
--- a/fsck_hfs.tproj/dfalib/BlockCache.c
65
+++ b/fsck_hfs.tproj/dfalib/BlockCache.c
67
* @APPLE_LICENSE_HEADER_END@
74
#include "Scavenger.h"
76
diff --git a/fsck_hfs.tproj/dfalib/SBTree.c b/fsck_hfs.tproj/dfalib/SBTree.c
77
index 2fbcd1d..cd81b13 100644
78
--- a/fsck_hfs.tproj/dfalib/SBTree.c
79
+++ b/fsck_hfs.tproj/dfalib/SBTree.c
80
@@ -322,7 +322,9 @@ ErrorExit:
82
SetEndOfForkProc ( SFCB *filePtr, FSSize minEOF, FSSize maxEOF )
85
#pragma unused (maxEOF)
89
UInt32 actualSectorsAdded;
90
diff --git a/fsck_hfs.tproj/dfalib/SDevice.c b/fsck_hfs.tproj/dfalib/SDevice.c
91
index bf6f61c..9a46023 100644
92
--- a/fsck_hfs.tproj/dfalib/SDevice.c
93
+++ b/fsck_hfs.tproj/dfalib/SDevice.c
95
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
97
* @APPLE_LICENSE_HEADER_START@
100
* "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
101
* Reserved. This file contains Original Code and/or Modifications of
102
* Original Code as defined in and that are subject to the Apple Public
104
* except in compliance with the License. Please obtain a copy of the
105
* License at http://www.apple.com/publicsource and read it before using
109
* The Original Code and all software distributed under the License are
110
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
111
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
113
* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
114
* License for the specific language governing rights and limitations
115
* under the License."
118
* @APPLE_LICENSE_HEADER_END@
120
#include "SRuntime.h"
124
#include <sys/ioctl.h>
128
+#include <sys/stat.h>
130
#include <IOKit/storage/IOMediaBSDClient.h>
142
OSErr GetDeviceSize(int driveRefNum, UInt64 *numBlocks, UInt32 *blockSize)
145
UInt64 devBlockCount = 0;
146
int devBlockSize = 0;
150
+ devBlockSize = 512;
153
+#define BLKGETSIZE _IO(0x12,96)
155
+#ifndef BLKGETSIZE64
156
+#define BLKGETSIZE64 _IOR(0x12,114,size_t)
158
+ if (fstat(driveRefNum, &stbuf) < 0){
159
+ printf("Error: %s\n", strerror(errno));
163
+ if (S_ISREG(stbuf.st_mode)) {
164
+ devBlockCount = stbuf.st_size / 512;
166
+ else if (S_ISBLK(stbuf.st_mode)) {
167
+ unsigned long size;
169
+ if (!ioctl(driveRefNum, BLKGETSIZE64, &size64))
170
+ devBlockCount = size64 / 512;
171
+ else if (!ioctl(driveRefNum, BLKGETSIZE, &size))
172
+ devBlockCount = size;
174
+ printf("Error: %s\n", strerror(errno));
180
+ printf("Device is not a block device");
184
if (ioctl(driveRefNum, DKIOCGETBLOCKCOUNT, &devBlockCount) < 0) {
185
printf("ioctl(DKIOCGETBLOCKCOUNT) for fd %d: %s\n", driveRefNum, strerror(errno));
190
if (ioctl(driveRefNum, DKIOCGETBLOCKSIZE, &devBlockSize) < 0) {
191
printf("ioctl(DKIOCGETBLOCKSIZE) for fd %d: %s\n", driveRefNum, strerror(errno));
196
if (devBlockSize != 512) {
197
*numBlocks = (devBlockCount * (UInt64)devBlockSize) / 512;
198
@@ -70,24 +108,24 @@ OSErr GetDeviceSize(int driveRefNum, UInt64 *numBlocks, UInt32 *blockSize)
200
/* return format list status code */
204
/* reference number of .SONY driver */
205
kSonyRefNum = 0xfffb,
208
/* values returned by DriveStatus in DrvSts.twoSideFmt */
211
kSingleSidedSize = 800, /* 400K */
212
kDoubleSidedSize = 1600, /* 800K */
215
/* values in DrvQEl.qType */
220
/* more than enough formatListRecords */
221
kMaxFormatListRecs = 16
226
FormatListRec formatListRecords[kMaxFormatListRecs];
228
@@ -95,22 +133,22 @@ OSErr GetDeviceSize(int driveRefNum, UInt64 *numBlocks, UInt32 *blockSize)
230
unsigned long blocks = 0;
234
/* Attempt to get the drive's format list. */
235
/* (see the Technical Note "What Your Sony Drives For You") */
238
pb.cntrlParam.ioVRefNum = driveQElementPtr->dQDrive;
239
pb.cntrlParam.ioCRefNum = driveQElementPtr->dQRefNum;
240
pb.cntrlParam.csCode = kFmtLstCode;
241
pb.cntrlParam.csParam[0] = kMaxFormatListRecs;
242
*(long *)&pb.cntrlParam.csParam[1] = (long)&formatListRecords[0];
245
result = PBStatusSync(&pb);
248
if ( result == noErr )
250
/* The drive supports ReturnFormatList status call. */
253
/* Get the current disk's size. */
254
for( formatListRecIndex = 0;
255
formatListRecIndex < pb.cntrlParam.csParam[0];
256
@@ -131,7 +169,7 @@ OSErr GetDeviceSize(int driveRefNum, UInt64 *numBlocks, UInt32 *blockSize)
257
else if ( driveQElementPtr->dQRefNum == (short)kSonyRefNum )
259
/* The drive is a non-SuperDrive floppy which only supports 400K and 800K disks */
262
result = DriveStatus(driveQElementPtr->dQDrive, &status);
263
if ( result == noErr )
265
@@ -140,11 +178,11 @@ OSErr GetDeviceSize(int driveRefNum, UInt64 *numBlocks, UInt32 *blockSize)
267
blocks = kSingleSidedSize;
272
blocks = kDoubleSidedSize;
276
default: // This should never happen
279
@@ -155,20 +193,20 @@ OSErr GetDeviceSize(int driveRefNum, UInt64 *numBlocks, UInt32 *blockSize)
281
/* The drive is not a floppy and it doesn't support ReturnFormatList */
282
/* so use the dQDrvSz field(s) */
285
result = noErr; /* reset result */
288
switch ( driveQElementPtr->qType )
291
blocks = driveQElementPtr->dQDrvSz;
296
blocks = ((unsigned long)driveQElementPtr->dQDrvSz2 << 16) +
297
driveQElementPtr->dQDrvSz;
301
default: // This should never happen
304
@@ -177,7 +215,7 @@ OSErr GetDeviceSize(int driveRefNum, UInt64 *numBlocks, UInt32 *blockSize)
313
@@ -188,7 +226,7 @@ OSErr DeviceRead(int device, int drive, void* buffer, SInt64 offset, UInt32 reqB
321
seek_off = lseek(device, offset, SEEK_SET);
322
diff --git a/fsck_hfs.tproj/dfalib/SKeyCompare.c b/fsck_hfs.tproj/dfalib/SKeyCompare.c
323
index 46e145f..18d99c5 100644
324
--- a/fsck_hfs.tproj/dfalib/SKeyCompare.c
325
+++ b/fsck_hfs.tproj/dfalib/SKeyCompare.c
326
@@ -454,7 +454,9 @@ SInt32 CompareExtentKeysPlus( const HFSPlusExtentKey *searchKey, const HFSPlusEx
327
* The name portion of the key is compared using a 16-bit binary comparison.
328
* This is called from the b-tree code.
334
CompareAttributeKeys(const AttributeKey *searchKey, const AttributeKey *trialKey)
336
diff --git a/fsck_hfs.tproj/dfalib/SRepair.c b/fsck_hfs.tproj/dfalib/SRepair.c
337
index 01c1a10..8eb759c 100644
338
--- a/fsck_hfs.tproj/dfalib/SRepair.c
339
+++ b/fsck_hfs.tproj/dfalib/SRepair.c
340
@@ -1617,7 +1617,9 @@ Output:
342
static OSErr FixWrapperExtents( SGlobPtr GPtr, RepairOrderPtr p )
349
HFSMasterDirectoryBlock *mdb;
350
diff --git a/fsck_hfs.tproj/dfalib/SRuntime.h b/fsck_hfs.tproj/dfalib/SRuntime.h
351
index 646917b..770e3ef 100644
352
--- a/fsck_hfs.tproj/dfalib/SRuntime.h
353
+++ b/fsck_hfs.tproj/dfalib/SRuntime.h
360
+#include "missing.h"
362
#include <sys/types.h>
367
@@ -91,10 +94,12 @@ typedef const unsigned char * ConstStr255Param;
369
typedef u_int32_t HFSCatalogNodeID;
380
diff --git a/fsck_hfs.tproj/dfalib/SUtils.c b/fsck_hfs.tproj/dfalib/SUtils.c
381
index 72035f0..6e9253e 100644
382
--- a/fsck_hfs.tproj/dfalib/SUtils.c
383
+++ b/fsck_hfs.tproj/dfalib/SUtils.c
384
@@ -380,7 +380,8 @@ void InvalidateCalculatedVolumeBitMap( SGlobPtr GPtr )
385
// GPtr->realVCB Real in-memory vcb
386
//------------------------------------------------------------------------------
391
OSErr GetVolumeFeatures( SGlobPtr GPtr )
394
@@ -418,7 +419,7 @@ OSErr GetVolumeFeatures( SGlobPtr GPtr )
402
/*-------------------------------------------------------------------------------
403
diff --git a/fsck_hfs.tproj/dfalib/SVerify2.c b/fsck_hfs.tproj/dfalib/SVerify2.c
404
index 6a47935..c68f3d8 100644
405
--- a/fsck_hfs.tproj/dfalib/SVerify2.c
406
+++ b/fsck_hfs.tproj/dfalib/SVerify2.c
410
#include <sys/ioctl.h>
412
#include <sys/disk.h>
416
#include "BTreePrivate.h"
417
@@ -1354,8 +1356,13 @@ OSErr CompareVolumeHeader( SGlobPtr GPtr, HFSPlusVolumeHeader *volumeHeader )
418
* clump size for read-only media is irrelevant we skip the clump size
419
* check to avoid non useful warnings.
426
ioctl( GPtr->DrvNum, DKIOCISWRITABLE, &isWriteable );
428
if ( isWriteable != 0 &&
429
volumeHeader->catalogFile.clumpSize != vcb->vcbCatalogFile->fcbClumpSize ) {
430
PrintError(GPtr, E_InvalidClumpSize, 0);
431
diff --git a/fsck_hfs.tproj/dfalib/Scavenger.h b/fsck_hfs.tproj/dfalib/Scavenger.h
432
index cf53970..edb3a80 100644
433
--- a/fsck_hfs.tproj/dfalib/Scavenger.h
434
+++ b/fsck_hfs.tproj/dfalib/Scavenger.h
436
#include "../fsck_debug.h"
440
+#define XATTR_MAXNAMELEN 127
443
#include <sys/xattr.h>
445
#include <sys/kauth.h>
446
-#include <sys/errno.h>
447
#include <sys/syslimits.h>
449
+#include <sys/errno.h>
453
@@ -1465,4 +1470,8 @@ extern int AllocateContigBitmapBits (SVCB *vcb, UInt32 numBlocks, UInt32 *actua
458
+#undef XATTR_MAXNAMELEN
461
#endif /* __SCAVENGER__ */
462
diff --git a/fsck_hfs.tproj/dfalib/hfs_endian.c b/fsck_hfs.tproj/dfalib/hfs_endian.c
463
index 7fa5385..69500c1 100755
464
--- a/fsck_hfs.tproj/dfalib/hfs_endian.c
465
+++ b/fsck_hfs.tproj/dfalib/hfs_endian.c
467
#include <sys/types.h>
468
#include <sys/stat.h>
471
+#include "missing.h"
473
#include <architecture/byte_order.h>
475
#include <hfs/hfs_format.h>
477
#include "Scavenger.h"
478
diff --git a/fsck_hfs.tproj/dfalib/hfs_endian.h b/fsck_hfs.tproj/dfalib/hfs_endian.h
479
index 52d0c3a..0763d9d 100755
480
--- a/fsck_hfs.tproj/dfalib/hfs_endian.h
481
+++ b/fsck_hfs.tproj/dfalib/hfs_endian.h
484
* This file prototypes endian swapping routines for the HFS/HFS Plus
488
#include <hfs/hfs_format.h>
491
+#include <byteswap.h>
493
#include <architecture/byte_order.h>
495
#include "SRuntime.h"
497
/*********************/
498
diff --git a/fsck_hfs.tproj/fsck_hfs.c b/fsck_hfs.tproj/fsck_hfs.c
499
index 90532fd..f1a18bd 100644
500
--- a/fsck_hfs.tproj/fsck_hfs.c
501
+++ b/fsck_hfs.tproj/fsck_hfs.c
503
#include <sys/types.h>
504
#include <sys/stat.h>
505
#include <sys/param.h>
507
#include <sys/ucred.h>
509
#include <sys/mount.h>
510
#include <sys/ioctl.h>
512
#include <sys/disk.h>
515
#include <hfs/hfs_mount.h>
517
@@ -195,8 +199,12 @@ main(argc, argv)
519
debug = 0; /* debugging is for command line only */
524
if (signal(SIGINT, SIG_IGN) != SIG_IGN)
525
(void)signal(SIGINT, catch);
529
(void) fprintf(stderr, "%s: missing special-device\n", progname);
530
@@ -218,7 +226,9 @@ checkfilesys(char * filesys)
531
int chkLev, repLev, logLev;
532
int blockDevice_fd, canWrite;
533
char *unraw, *mntonname;
535
struct statfs *fsinfo;
537
int fs_fd=-1; // fd to the root-dir of the fs we're checking (only w/lfag == 1)
540
@@ -227,7 +237,9 @@ checkfilesys(char * filesys)
549
result = getmntinfo(&fsinfo, MNT_NOWAIT);
551
@@ -257,10 +269,10 @@ checkfilesys(char * filesys)
561
if (setup( filesys, &blockDevice_fd, &canWrite ) == 0) {
563
pfatal("CAN'T CHECK FILE SYSTEM.");
564
@@ -278,7 +290,7 @@ checkfilesys(char * filesys)
565
repLev = kMajorRepairs;
566
logLev = kVerboseLog;
570
repLev = kMajorRepairs;
573
@@ -298,16 +310,16 @@ checkfilesys(char * filesys)
576
repLev = kNeverRepair;
579
if ( rebuildCatalogBtree ) {
580
chkLev = kPartialCheck;
581
repLev = kForceRepairs; // this will force rebuild of catalog B-Tree file
586
* go check HFS volume...
588
- result = CheckHFS( fsreadfd, fswritefd, chkLev, repLev, logLev,
589
+ result = CheckHFS( fsreadfd, fswritefd, chkLev, repLev, logLev,
590
guiControl, lostAndFoundMode, canWrite, &fsmodified );
593
@@ -330,6 +342,9 @@ checkfilesys(char * filesys)
600
struct statfs stfs_buf;
602
* Check to see if root is mounted read-write.
603
@@ -339,19 +354,25 @@ checkfilesys(char * filesys)
606
ckfini(flags & MNT_RDONLY);
610
/* XXX free any allocated memory here */
612
if (hotroot && fsmodified) {
614
struct hfs_mount_args args;
617
* We modified the root. Do a mount update on
618
* it, unless it is read-write, so we can continue.
621
printf("\n***** FILE SYSTEM WAS MODIFIED *****\n");
622
- if (flags & MNT_RDONLY) {
626
+ if (flags & MNT_RDONLY) {
627
bzero(&args, sizeof(args));
628
flags |= MNT_UPDATE | MNT_RELOAD;
629
if (mount("hfs", "/", flags, &args) == 0) {
630
@@ -359,6 +380,7 @@ checkfilesys(char * filesys)
631
goto ExitThisRoutine;
636
printf("\n***** REBOOT NOW *****\n");
638
@@ -367,7 +389,7 @@ checkfilesys(char * filesys)
641
result = (result == 0) ? 0 : EEXIT;
646
fcntl(fs_fd, F_THAW_FS, NULL);
647
@@ -401,16 +423,18 @@ setup( char *dev, int *blockDevice_fdPtr, int *canWritePtr )
649
*blockDevice_fdPtr = -1;
653
if (stat(dev, &statb) < 0) {
654
printf("Can't stat %s: %s\n", dev, strerror(errno));
658
if ((statb.st_mode & S_IFMT) != S_IFCHR) {
659
pfatal("%s is not a character device", dev);
660
if (reply("CONTINUE") == 0)
664
if ((fsreadfd = open(dev, O_RDONLY)) < 0) {
665
printf("Can't open %s: %s\n", dev, strerror(errno));
667
@@ -419,7 +443,7 @@ setup( char *dev, int *blockDevice_fdPtr, int *canWritePtr )
668
/* attempt to get write access to the block device and if not check if volume is */
669
/* mounted read-only. */
670
getWriteAccess( dev, blockDevice_fdPtr, canWritePtr );
673
if (preen == 0 && !guiControl)
674
printf("** %s", dev);
675
if (nflag || (fswritefd = open(dev, O_WRONLY)) < 0) {
676
@@ -433,10 +457,14 @@ setup( char *dev, int *blockDevice_fdPtr, int *canWritePtr )
679
/* Get device block size to initialize cache */
681
+ devBlockSize = 512;
683
if (ioctl(fsreadfd, DKIOCGETBLOCKSIZE, &devBlockSize) < 0) {
684
pfatal ("Can't get device block size\n");
689
/* calculate the cache block size and total blocks */
690
if (CalculateCacheSize(userCacheSize, &cacheBlockSize, &cacheTotalBlocks, debug) != 0) {
691
@@ -463,11 +491,15 @@ setup( char *dev, int *blockDevice_fdPtr, int *canWritePtr )
693
static void getWriteAccess( char *dev, int *blockDevice_fdPtr, int *canWritePtr )
702
struct statfs * myBufPtr;
707
@@ -490,6 +522,9 @@ static void getWriteAccess( char *dev, int *blockDevice_fdPtr, int *canWritePtr
710
// get count of mounts then get the info for each
714
myMountsCount = getfsstat( NULL, 0, MNT_NOWAIT );
715
if ( myMountsCount < 0 )
716
goto ExitThisRoutine;
717
@@ -513,8 +548,8 @@ static void getWriteAccess( char *dev, int *blockDevice_fdPtr, int *canWritePtr
721
- *canWritePtr = 1; // single user will get us here, f_mntfromname is not /dev/diskXXXX
724
+ *canWritePtr = 1; // single user will get us here, f_mntfromname is not /dev/diskXXXX
728
diff --git a/fsck_hfs.tproj/utilities.c b/fsck_hfs.tproj/utilities.c
729
index ee41bef..8e1cd77 100644
730
--- a/fsck_hfs.tproj/utilities.c
731
+++ b/fsck_hfs.tproj/utilities.c
732
@@ -183,12 +183,14 @@ retry:
733
printf("Can't stat %s\n", raw);
737
if ((stchar.st_mode & S_IFMT) == S_IFCHR) {
740
printf("%s is not a character device\n", raw);
744
} else if ((stblock.st_mode & S_IFMT) == S_IFCHR && !retried) {
745
newname = unrawname(newname);
747
@@ -214,7 +216,11 @@ rawname(char *name)
749
(void)strcpy(rawbuf, name);
751
- (void)strcat(rawbuf, "/r");
753
+ (void)strcat(rawbuf, "/");
755
+ (void)strcat(rawbuf,"/r");
757
(void)strcat(rawbuf, &dp[1]);
760
diff --git a/include/missing.h b/include/missing.h
762
index 0000000..0a859c4
764
+++ b/include/missing.h
770
+#include <byteswap.h>
774
+#include <bsd/string.h>
776
+#define MAXBSIZE (256 * 4096)
789
+#define UInt8 uint8_t
792
+#define u_int8_t UInt8
795
+#define SInt8 int8_t
800
+#define UInt16 uint16_t
803
+#define u_int16_t UInt16
806
+#define SInt16 int16_t
811
+#define UInt32 uint32_t
814
+#define u_int32_t UInt32
817
+#define SInt32 int32_t
822
+#define UInt64 uint64_t
825
+#define u_int64_t UInt64
828
+#define SInt64 int64_t
831
+#define UniChar u_int16_t
832
+#define Boolean u_int8_t
834
+#define UF_NODUMP 0x00000001
837
+#define NAME_MAX 255
839
+/* Byteswap stuff */
840
+#define NXSwapHostLongToBig(x) cpu_to_be64(x)
841
+#define NXSwapBigShortToHost(x) be16_to_cpu(x)
842
+#define OSSwapBigToHostInt16(x) be16_to_cpu(x)
843
+#define NXSwapBigLongToHost(x) be32_to_cpu(x)
844
+#define OSSwapBigToHostInt32(x) be32_to_cpu(x)
845
+#define NXSwapBigLongLongToHost(x) be64_to_cpu(x)
846
+#define OSSwapBigToHostInt64(x) be64_to_cpu(x)
848
+#if __BYTE_ORDER == __LITTLE_ENDIAN
849
+/* Big Endian Swaps */
851
+#define be16_to_cpu(x) bswap_16(x)
854
+#define be32_to_cpu(x) bswap_32(x)
857
+#define be64_to_cpu(x) bswap_64(x)
860
+#define cpu_to_be64(x) bswap_64(x)
862
+#elif __BYTE_ORDER == __BIG_ENDIAN
863
+/* Big endian doesn't swap */
865
+#define be16_to_cpu(x) (x)
868
+#define be32_to_cpu(x) (x)
871
+#define be64_to_cpu(x) (x)
874
+#define cpu_to_be64(x) (x)
878
+#define KAUTH_FILESEC_XATTR "com.apple.system.Security"
881
diff --git a/newfs_hfs.tproj/hfs_endian.c b/newfs_hfs.tproj/hfs_endian.c
882
index 117b7f8..fdf7353 100644
883
--- a/newfs_hfs.tproj/hfs_endian.c
884
+++ b/newfs_hfs.tproj/hfs_endian.c
886
#include <sys/types.h>
887
#include <sys/stat.h>
890
+#include "missing.h"
892
#include <architecture/byte_order.h>
895
#include <hfs/hfs_format.h>
897
#include "hfs_endian.h"
898
diff --git a/newfs_hfs.tproj/hfs_endian.h b/newfs_hfs.tproj/hfs_endian.h
899
index 8d9d01d..5c7ff57 100644
900
--- a/newfs_hfs.tproj/hfs_endian.h
901
+++ b/newfs_hfs.tproj/hfs_endian.h
905
#include <hfs/hfs_format.h>
908
+#include <byteswap.h>
910
#include <architecture/byte_order.h>
913
/*********************/
914
/* BIG ENDIAN Macros */
915
diff --git a/newfs_hfs.tproj/makehfs.c b/newfs_hfs.tproj/makehfs.c
916
index 085222f..7609779 100644
917
--- a/newfs_hfs.tproj/makehfs.c
918
+++ b/newfs_hfs.tproj/makehfs.c
920
#include <sys/param.h>
921
#include <sys/types.h>
922
#include <sys/time.h>
925
+#include "missing.h"
927
#include <sys/errno.h>
928
#include <sys/stat.h>
929
#include <sys/sysctl.h>
931
#include <sys/vmmeter.h>
938
#include <openssl/sha.h>
941
#include <architecture/byte_order.h>
943
#include <CoreFoundation/CFString.h>
944
#include <CoreFoundation/CFStringEncodingExt.h>
946
extern Boolean _CFStringGetFileSystemRepresentation(CFStringRef string, UInt8 *buffer, CFIndex maxBufLen);
950
#include <hfs/hfs_format.h>
951
#include <hfs/hfs_mount.h>
952
@@ -129,7 +136,9 @@ static UInt32 Largest __P((UInt32 a, UInt32 b, UInt32 c, UInt32 d ));
953
static void MarkBitInAllocationBuffer __P((HFSPlusVolumeHeader *header,
954
UInt32 allocationBlock, void* sectorBuffer, UInt32 *sector));
957
static UInt32 GetDefaultEncoding();
960
static UInt32 UTCToLocal __P((UInt32 utcTime));
962
@@ -158,11 +167,14 @@ void SETOFFSET (void *buffer, UInt16 btNodeSize, SInt16 recOffset, SInt16 vecOff
964
#define ROUNDUP(x, u) (((x) % (u) == 0) ? (x) : ((x)/(u) + 1) * (u))
966
-#define ENCODING_TO_BIT(e) \
968
+#define ENCODING_TO_BIT(e) (e)
970
+#define ENCODING_TO_BIT(e)
972
((e) == kCFStringEncodingMacUkrainian ? 48 : \
973
((e) == kCFStringEncodingMacFarsi ? 49 : 0)))
979
@@ -528,6 +540,7 @@ InitMDB(hfsparams_t *defaults, UInt32 driveBlocks, HFS_MDB *mdbp)
980
* Map UTF-8 input into a Mac encoding.
981
* On conversion errors "untitled" is used as a fallback.
985
UniChar unibuf[kHFSMaxVolumeNameChars];
987
@@ -553,7 +566,11 @@ InitMDB(hfsparams_t *defaults, UInt32 driveBlocks, HFS_MDB *mdbp)
988
bcopy(&mdbp->drVN[1], defaults->volumeName, mdbp->drVN[0]);
989
defaults->volumeName[mdbp->drVN[0]] = '\0';
992
/* Save the encoding hint in the Finder Info (field 4). */
993
+ mdbp->drVN[0] = strlen(defaults->volumeName);
994
+ bcopy(defaults->volumeName,&mdbp->drVN[1],mdbp->drVN[0]);
996
mdbp->drFndrInfo[4] = SET_HFS_TEXT_ENCODING(defaults->encodingHint);
998
mdbp->drWrCnt = kWriteSeqNum;
999
@@ -1100,9 +1117,11 @@ InitCatalogRoot_HFSPlus(const hfsparams_t *dp, const HFSPlusVolumeHeader *header
1002
UInt32 unicodeBytes;
1004
UInt8 canonicalName[256];
1010
nodeSize = dp->catalogNodeSize;
1011
@@ -1122,7 +1141,9 @@ InitCatalogRoot_HFSPlus(const hfsparams_t *dp, const HFSPlusVolumeHeader *header
1012
* First record is always the root directory...
1014
ckp = (HFSPlusCatalogKey *)((UInt8 *)buffer + offset);
1017
+ ConvertUTF8toUnicode(dp->volumeName, sizeof(ckp->nodeName.unicode), ckp->nodeName.unicode, &ckp->nodeName.length);
1019
/* Use CFString functions to get a HFSPlus Canonical name */
1020
cfstr = CFStringCreateWithCString(kCFAllocatorDefault, (char *)dp->volumeName, kCFStringEncodingUTF8);
1021
cfOK = _CFStringGetFileSystemRepresentation(cfstr, canonicalName, sizeof(canonicalName));
1022
@@ -1139,6 +1160,7 @@ InitCatalogRoot_HFSPlus(const hfsparams_t *dp, const HFSPlusVolumeHeader *header
1023
dp->volumeName, kDefaultVolumeNameStr);
1027
ckp->nodeName.length = SWAP_BE16 (ckp->nodeName.length);
1029
unicodeBytes = sizeof(UniChar) * SWAP_BE16 (ckp->nodeName.length);
1030
@@ -1821,15 +1843,15 @@ WriteBuffer(const DriveInfo *driveInfo, UInt64 startingSector, UInt32 byteCount,
1033
if ((byteCount % driveInfo->sectorSize) != 0)
1034
- errx(1, "WriteBuffer: byte count %ld is not sector size multiple", byteCount);
1035
+ errx(1, "WriteBuffer: byte count %i is not sector size multiple", byteCount);
1037
sector = driveInfo->sectorOffset + startingSector;
1039
if (lseek(driveInfo->fd, sector * driveInfo->sectorSize, SEEK_SET) < 0)
1040
- err(1, "seek (sector %qd)", sector);
1041
+ err(1, "seek (sector %lld)", sector);
1043
if (write(driveInfo->fd, buffer, byteCount) != byteCount)
1044
- err(1, "write (sector %qd, %ld bytes)", sector, byteCount);
1045
+ err(1, "write (sector %lld, %i bytes)", sector, byteCount);
1049
@@ -1913,7 +1935,7 @@ DivideAndRoundUp(UInt32 numerator, UInt32 denominator)
1055
#define __kCFUserEncodingFileName ("/.CFUserTextEncoding")
1058
@@ -1939,7 +1961,7 @@ GetDefaultEncoding()
1066
ConvertUTF8toUnicode(const UInt8* source, UInt32 bufsize, UniChar* unibuf,
1067
@@ -2006,6 +2028,9 @@ ConvertUTF8toUnicode(const UInt8* source, UInt32 bufsize, UniChar* unibuf,
1069
getencodinghint(unsigned char *name)
1075
size_t buflen = sizeof(int);
1077
@@ -2023,7 +2048,8 @@ getencodinghint(unsigned char *name)
1080
hint = GetDefaultEncoding();
1087
@@ -2034,12 +2060,14 @@ void GenerateVolumeUUID(VolumeUUID *newVolumeID) {
1088
unsigned char digest[20];
1093
- char sysctlstring[128];
1095
double sysloadavg[3];
1099
+ char sysctlstring[128];
1100
struct vmtotal sysvmtotal;
1104
/* Initialize the SHA-1 context for processing: */
1105
@@ -2052,52 +2080,58 @@ void GenerateVolumeUUID(VolumeUUID *newVolumeID) {
1106
SHA1_Update(&context, &uptime, sizeof(uptime));
1108
/* The kernel's boot time: */
1111
mib[1] = KERN_BOOTTIME;
1112
datalen = sizeof(sysdata);
1113
sysctl(mib, 2, &sysdata, &datalen, NULL, 0);
1114
SHA1_Update(&context, &sysdata, datalen);
1117
/* The system's host id: */
1120
mib[1] = KERN_HOSTID;
1121
datalen = sizeof(sysdata);
1122
sysctl(mib, 2, &sysdata, &datalen, NULL, 0);
1123
SHA1_Update(&context, &sysdata, datalen);
1126
/* The system's host name: */
1129
mib[1] = KERN_HOSTNAME;
1130
datalen = sizeof(sysctlstring);
1131
sysctl(mib, 2, sysctlstring, &datalen, NULL, 0);
1132
SHA1_Update(&context, sysctlstring, datalen);
1135
/* The running kernel's OS release string: */
1138
mib[1] = KERN_OSRELEASE;
1139
datalen = sizeof(sysctlstring);
1140
sysctl(mib, 2, sysctlstring, &datalen, NULL, 0);
1141
SHA1_Update(&context, sysctlstring, datalen);
1144
/* The running kernel's version string: */
1147
mib[1] = KERN_VERSION;
1148
datalen = sizeof(sysctlstring);
1149
sysctl(mib, 2, sysctlstring, &datalen, NULL, 0);
1150
SHA1_Update(&context, sysctlstring, datalen);
1153
/* The system's load average: */
1154
datalen = sizeof(sysloadavg);
1155
getloadavg(sysloadavg, 3);
1156
SHA1_Update(&context, &sysloadavg, datalen);
1158
/* The system's VM statistics: */
1162
datalen = sizeof(sysvmtotal);
1163
sysctl(mib, 2, &sysvmtotal, &datalen, NULL, 0);
1164
SHA1_Update(&context, &sysvmtotal, datalen);
1167
/* The current GMT (26 ASCII characters): */
1169
strncpy(randomInputBuffer, asctime(gmtime(&now)), 26); /* "Mon Mar 27 13:46:26 2000" */
1170
diff --git a/newfs_hfs.tproj/newfs_hfs.c b/newfs_hfs.tproj/newfs_hfs.c
1171
index c4176a9..bf2ed21 100644
1172
--- a/newfs_hfs.tproj/newfs_hfs.c
1173
+++ b/newfs_hfs.tproj/newfs_hfs.c
1175
#include <sys/mount.h>
1176
#include <sys/param.h>
1177
#include <sys/stat.h>
1183
#include <IOKit/storage/IOMediaBSDClient.h>
1186
#include <hfs/hfs_format.h>
1187
#include "newfs_hfs.h"
1188
@@ -73,7 +78,9 @@ static void usage __P((void));
1191
char gVolumeName[kHFSPlusMaxFileNameChars + 1] = {kDefaultVolumeNameStr};
1193
char rawdevice[MAXPATHLEN];
1195
char blkdevice[MAXPATHLEN];
1196
UInt32 gBlockSize = 0;
1197
UInt32 gNextCNID = kHFSFirstUserCatalogNodeID;
1198
@@ -158,8 +165,10 @@ main(argc, argv)
1208
if ((progname = strrchr(*argv, '/')))
1209
@@ -260,16 +269,19 @@ main(argc, argv)
1218
- if (gPartitionSize != 0) {
1224
+ if (gPartitionSize != 0) {
1232
+ (void) sprintf(blkdevice, "%s", argv[0]);
1235
cp = strrchr(special, '/');
1237
@@ -278,6 +290,7 @@ main(argc, argv)
1239
(void) sprintf(rawdevice, "%sr%s", _PATH_DEV, special);
1240
(void) sprintf(blkdevice, "%s%s", _PATH_DEV, special);
1244
if (forceHFS && gJournaled) {
1245
@@ -301,6 +314,9 @@ main(argc, argv)
1247
* Check if target device is aready mounted
1252
n = getmntinfo(&mp, MNT_NOWAIT);
1254
fatal("%s: getmntinfo: %s", blkdevice, strerror(errno));
1255
@@ -310,15 +326,20 @@ main(argc, argv)
1256
fatal("%s is mounted on %s", blkdevice, mp->f_mntonname);
1262
- if (hfs_newfs(rawdevice, forceHFS, true) < 0) {
1263
+ if (hfs_newfs(blkdevice, forceHFS, true) < 0) {
1267
/* On ENXIO error use the block device (to get de-blocking) */
1268
if (errno == ENXIO) {
1269
if (hfs_newfs(blkdevice, forceHFS, false) < 0)
1277
@@ -506,7 +527,9 @@ hfs_newfs(char *device, int forceHFS, int isRaw)
1280
hfsparams_t defaults = {0};
1282
u_int64_t maxSectorsPerIO;
1285
if (gPartitionSize) {
1286
dip.sectorSize = kBytesPerSector;
1287
@@ -526,6 +549,34 @@ hfs_newfs(char *device, int forceHFS, int isRaw)
1289
if (fstat( fso, &stbuf) < 0)
1290
fatal("%s: %s", device, strerror(errno));
1292
+ dip.sectorSize = 512;
1293
+ dip.sectorsPerIO = 256;
1295
+# ifndef BLKGETSIZE
1296
+# define BLKGETSIZE _IO(0x12,96)
1299
+# ifndef BLKGETSIZE64
1300
+# define BLKGETSIZE64 _IOR(0x12,114,size_t)
1303
+ if (S_ISREG(stbuf.st_mode)) {
1304
+ dip.totalSectors = stbuf.st_size / 512;
1306
+ else if (S_ISBLK(stbuf.st_mode)) {
1307
+ unsigned long size;
1309
+ if (!ioctl(fso, BLKGETSIZE64, &size64))
1310
+ dip.totalSectors = size64 / 512;
1311
+ else if (!ioctl(fso, BLKGETSIZE, &size))
1312
+ dip.totalSectors = size;
1314
+ fatal("%s: %s", device, strerror(errno));
1317
+ fatal("%s: is not a block device", device);
1320
if (ioctl(fso, DKIOCGETBLOCKCOUNT, &dip.totalSectors) < 0)
1321
fatal("%s: %s", device, strerror(errno));
1322
@@ -537,11 +588,14 @@ hfs_newfs(char *device, int forceHFS, int isRaw)
1323
dip.sectorsPerIO = (128 * 1024) / dip.sectorSize; /* use 128K as default */
1325
dip.sectorsPerIO = MIN(maxSectorsPerIO, (1024 * 1024) / dip.sectorSize);
1329
* The make_hfs code currentlydoes 512 byte sized I/O.
1330
* If the sector size is bigger than 512, start over
1331
* using the block device (to get de-blocking).
1334
if (dip.sectorSize != kBytesPerSector) {
1337
@@ -556,7 +610,9 @@ hfs_newfs(char *device, int forceHFS, int isRaw)
1338
dip.sectorSize = kBytesPerSector;
1344
dip.sectorOffset = 0;
1347
diff --git a/newfs_hfs.tproj/newfs_hfs.h b/newfs_hfs.tproj/newfs_hfs.h
1348
index 968ff10..5680a34 100644
1349
--- a/newfs_hfs.tproj/newfs_hfs.h
1350
+++ b/newfs_hfs.tproj/newfs_hfs.h
1353
* @APPLE_LICENSE_HEADER_END@
1358
+#include "missing.h"
1360
#include <CoreFoundation/CFBase.h>
1364
* Mac OS Finder flags
1365
@@ -122,33 +126,33 @@ enum {
1366
#define kDTDF_FileID 16
1367
#define kDTDF_Name "Desktop DF"
1368
#define kDTDF_Chars 10
1369
-#define kDTDF_Type 'DTFL'
1370
-#define kDTDF_Creator 'DMGR'
1371
+#define kDTDF_Type 0x4454464C /* 'DTFL' */
1372
+#define kDTDF_Creator 0x444D4752 /* 'DMGR' */
1374
#define kDTDB_FileID 17
1375
#define kDTDB_Name "Desktop DB"
1376
#define kDTDB_Chars 10
1377
-#define kDTDB_Type 'BTFL'
1378
-#define kDTDB_Creator 'DMGR'
1379
+#define kDTDB_Type 0x4254464C /* 'BTFL' */
1380
+#define kDTDB_Creator 0x444D4752 /* 'DMGR' */
1381
#define kDTDB_Size 1024
1383
#define kReadMe_FileID 18
1384
#define kReadMe_Name "ReadMe"
1385
#define kReadMe_Chars 6
1386
-#define kReadMe_Type 'ttro'
1387
-#define kReadMe_Creator 'ttxt'
1388
+#define kReadMe_Type 0x7474726F /* 'ttro' */
1389
+#define kReadMe_Creator 0x74747974 /* 'ttxt' */
1391
#define kFinder_FileID 19
1392
#define kFinder_Name "Finder"
1393
#define kFinder_Chars 6
1394
-#define kFinder_Type 'FNDR'
1395
-#define kFinder_Creator 'MACS'
1396
+#define kFinder_Type 0x464E4452 /* 'FNDR' */
1397
+#define kFinder_Creator 0x4D414353 /* 'MACS' */
1399
#define kSystem_FileID 20
1400
#define kSystem_Name "System"
1401
#define kSystem_Chars 6
1402
-#define kSystem_Type 'zsys'
1403
-#define kSystem_Creator 'MACS'
1404
+#define kSystem_Type 0x7A737973 /* 'zsys' */
1405
+#define kSystem_Creator 0x4D414353 /* 'MACS' */