File 0006-hfs-Combined-patch-to-add-Linux-support.patch of Package hfsplus-tools
From 9117af75316a4685f7a598e6b57201f942862f05 Mon Sep 17 00:00:00 2001
From: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Date: Thu, 22 Jun 2023 21:33:20 +0200
Subject: [PATCH 6/7] hfs: Combined patch to add Linux support
---
fsck_hfs/cache.c | 4 +
fsck_hfs/dfalib/BTree.c | 2 +
fsck_hfs/dfalib/BlockCache.c | 3 +
fsck_hfs/dfalib/SBTree.c | 2 +
fsck_hfs/dfalib/SControl.c | 7 ++
fsck_hfs/dfalib/SDevice.c | 11 +--
fsck_hfs/dfalib/SKeyCompare.c | 2 +
fsck_hfs/dfalib/SRepair.c | 2 +
fsck_hfs/dfalib/SRuntime.h | 11 ++-
fsck_hfs/dfalib/SUtils.c | 5 +-
fsck_hfs/dfalib/SVerify1.c | 14 ++-
fsck_hfs/dfalib/SVerify2.c | 2 +
fsck_hfs/dfalib/Scavenger.h | 8 +-
fsck_hfs/dfalib/VolumeBitmapCheck.c | 20 +++++
fsck_hfs/dfalib/fsck_journal.c | 7 ++
fsck_hfs/dfalib/hfs_endian.c | 4 +
fsck_hfs/dfalib/hfs_endian.h | 2 +
fsck_hfs/dfalib/uuid.c | 4 +
fsck_hfs/fsck_debug.h | 4 +
fsck_hfs/fsck_hfs.c | 85 +++++++++++++++---
fsck_hfs/fsck_hfs.h | 3 +
fsck_hfs/fsck_messages.c | 13 +++
fsck_hfs/fsck_messages.h | 4 +
fsck_hfs/utilities.c | 30 ++++++-
include/hfs | 1 +
include/missing.h | 128 ++++++++++++++++++++++++++++
include/sys/appleapiopts.h | 56 ++++++++++++
newfs_hfs/hfs_endian.c | 5 ++
newfs_hfs/hfs_endian.h | 5 ++
newfs_hfs/makehfs.c | 76 +++++++++++++----
newfs_hfs/newfs_hfs.c | 33 ++++++-
newfs_hfs/newfs_hfs.h | 8 +-
32 files changed, 512 insertions(+), 49 deletions(-)
create mode 120000 include/hfs
create mode 100644 include/missing.h
create mode 100644 include/sys/appleapiopts.h
diff --git a/fsck_hfs/cache.c b/fsck_hfs/cache.c
index 26c8a4a..5875b66 100644
--- a/fsck_hfs/cache.c
+++ b/fsck_hfs/cache.c
@@ -27,7 +27,11 @@
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/stat.h>
+#if LINUX
+#include "missing.h"
+#else
#include <sys/types.h>
+#endif /* __LINUX__ */
#include <sys/uio.h>
#include <unistd.h>
#include <string.h>
diff --git a/fsck_hfs/dfalib/BTree.c b/fsck_hfs/dfalib/BTree.c
index 4bb1f9e..4574c2b 100644
--- a/fsck_hfs/dfalib/BTree.c
+++ b/fsck_hfs/dfalib/BTree.c
@@ -1709,7 +1709,9 @@ OSStatus BTGetInformation (SFCB *filePtr,
UInt16 version,
BTreeInfoRec *info )
{
+#if !LINUX
#pragma unused (version)
+#endif
BTreeControlBlockPtr btreePtr;
diff --git a/fsck_hfs/dfalib/BlockCache.c b/fsck_hfs/dfalib/BlockCache.c
index 132139e..4b6cc27 100644
--- a/fsck_hfs/dfalib/BlockCache.c
+++ b/fsck_hfs/dfalib/BlockCache.c
@@ -21,6 +21,9 @@
* @APPLE_LICENSE_HEADER_END@
*/
+#if LINUX
+#include "missing.h"
+#endif
#include "SRuntime.h"
#include "Scavenger.h"
#include "../cache.h"
diff --git a/fsck_hfs/dfalib/SBTree.c b/fsck_hfs/dfalib/SBTree.c
index e2bb56d..c74620f 100644
--- a/fsck_hfs/dfalib/SBTree.c
+++ b/fsck_hfs/dfalib/SBTree.c
@@ -321,7 +321,9 @@ ErrorExit:
OSStatus
SetEndOfForkProc ( SFCB *filePtr, FSSize minEOF, FSSize maxEOF )
{
+#if !LINUX
#pragma unused (maxEOF)
+#endif
OSStatus result;
UInt32 actualSectorsAdded;
diff --git a/fsck_hfs/dfalib/SControl.c b/fsck_hfs/dfalib/SControl.c
index bf6946e..614758d 100644
--- a/fsck_hfs/dfalib/SControl.c
+++ b/fsck_hfs/dfalib/SControl.c
@@ -34,6 +34,7 @@
#define SHOW_ELAPSED_TIMES 0
+#include "missing.h"
#if SHOW_ELAPSED_TIMES
#include <sys/time.h>
@@ -48,6 +49,10 @@
#define CONFIG_HFS_TRIM 1
#endif
+#if LINUX
+#include <bsd/string.h>
+#endif
+
#define DisplayTimeRemaining 0
/* Variable containing diskdev_cmds tag number and date/time when the binary was built.
@@ -59,7 +64,9 @@
*
* TODO: Get this building properly within Xcode, without need for the version.pl script!
*/
+#if !LINUX
extern const unsigned char fsck_hfsVersionString[];
+#endif
int gGUIControl;
extern char lflag;
diff --git a/fsck_hfs/dfalib/SDevice.c b/fsck_hfs/dfalib/SDevice.c
index 67dab52..358d3fb 100644
--- a/fsck_hfs/dfalib/SDevice.c
+++ b/fsck_hfs/dfalib/SDevice.c
@@ -28,18 +28,18 @@
#include <unistd.h>
#include <errno.h>
#include <sys/ioctl.h>
-
+#if LINUX
+#include <fcntl.h>
+#include <sys/stat.h>
+#else
#include <IOKit/storage/IOMediaBSDClient.h>
-
+#endif /* LINUX */
#else
-
#include <Files.h>
#include <Device.h>
#include <Disks.h>
-
#endif
-
OSErr GetDeviceSize(int driveRefNum, UInt64 *numBlocks, UInt32 *blockSize)
{
#if BSD
@@ -55,6 +55,7 @@ OSErr GetDeviceSize(int driveRefNum, UInt64 *numBlocks, UInt32 *blockSize)
if (debug) plog("ioctl(DKIOCGETBLOCKSIZE) for fd %d: %s\n", driveRefNum, strerror(errno));
return (-1);
}
+#endif /* BSD */
if (devBlockSize != 512) {
*numBlocks = (devBlockCount * (UInt64)devBlockSize) / 512;
diff --git a/fsck_hfs/dfalib/SKeyCompare.c b/fsck_hfs/dfalib/SKeyCompare.c
index 5b2816d..f0412f9 100644
--- a/fsck_hfs/dfalib/SKeyCompare.c
+++ b/fsck_hfs/dfalib/SKeyCompare.c
@@ -453,7 +453,9 @@ SInt32 CompareExtentKeysPlus( const HFSPlusExtentKey *searchKey, const HFSPlusEx
* The name portion of the key is compared using a 16-bit binary comparison.
* This is called from the b-tree code.
*/
+#if !LINUX
__private_extern__
+#endif
SInt32
CompareAttributeKeys(const AttributeKey *searchKey, const AttributeKey *trialKey)
{
diff --git a/fsck_hfs/dfalib/SRepair.c b/fsck_hfs/dfalib/SRepair.c
index 65cc03a..f3323cc 100644
--- a/fsck_hfs/dfalib/SRepair.c
+++ b/fsck_hfs/dfalib/SRepair.c
@@ -2581,7 +2581,9 @@ Output:
static OSErr FixWrapperExtents( SGlobPtr GPtr, RepairOrderPtr p )
{
+#if !LINUX
#pragma unused (p)
+#endif
OSErr err;
HFSMasterDirectoryBlock *mdb;
diff --git a/fsck_hfs/dfalib/SRuntime.h b/fsck_hfs/dfalib/SRuntime.h
index 005a4da..222b3b2 100644
--- a/fsck_hfs/dfalib/SRuntime.h
+++ b/fsck_hfs/dfalib/SRuntime.h
@@ -26,8 +26,11 @@
#define __SRUNTIME__
#if BSD
-
+#if LINUX
+#include "missing.h"
+#else
#include <sys/types.h>
+#endif
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
@@ -60,7 +63,7 @@ typedef char * Ptr;
typedef Ptr * Handle;
typedef u_int8_t Byte;
typedef size_t Size;
-typedef unsigned char Boolean;
+//typedef unsigned char Boolean;
typedef u_int32_t ItemCount;
typedef u_int32_t ByteCount;
typedef u_int32_t OptionBits;
@@ -71,7 +74,7 @@ typedef int32_t OSStatus;
typedef u_int32_t OSType;
typedef u_int32_t ResType;
-typedef u_int16_t UniChar;
+//typedef u_int16_t UniChar;
typedef u_int32_t UniCharCount;
typedef UniChar * UniCharArrayPtr;
typedef const UniChar * ConstUniCharArrayPtr;
@@ -89,10 +92,12 @@ typedef const unsigned char * ConstStr255Param;
typedef u_int32_t HFSCatalogNodeID;
+#if !LINUX
enum {
false = 0,
true = 1
};
+#endif
/* OS error codes */
enum {
diff --git a/fsck_hfs/dfalib/SUtils.c b/fsck_hfs/dfalib/SUtils.c
index a5567b5..997d46e 100644
--- a/fsck_hfs/dfalib/SUtils.c
+++ b/fsck_hfs/dfalib/SUtils.c
@@ -471,7 +471,8 @@ void InvalidateCalculatedVolumeBitMap( SGlobPtr GPtr )
// GPtr->realVCB Real in-memory vcb
//------------------------------------------------------------------------------
-#if !BSD
+#if BSD
+#if !LINUX
OSErr GetVolumeFeatures( SGlobPtr GPtr )
{
OSErr err;
@@ -509,7 +510,7 @@ OSErr GetVolumeFeatures( SGlobPtr GPtr )
return( noErr );
}
#endif
-
+#endif
/*-------------------------------------------------------------------------------
diff --git a/fsck_hfs/dfalib/SVerify1.c b/fsck_hfs/dfalib/SVerify1.c
index 5ed40df..548d863 100644
--- a/fsck_hfs/dfalib/SVerify1.c
+++ b/fsck_hfs/dfalib/SVerify1.c
@@ -40,7 +40,11 @@
#include <fcntl.h>
#include <limits.h>
+#if !LINUX
#include <libkern/OSByteOrder.h>
+#else
+#define XATTR_MAXNAMELEN 127
+#endif
#define SW16(x) OSSwapBigToHostInt16(x)
#define SW32(x) OSSwapBigToHostInt32(x)
#define SW64(x) OSSwapBigToHostInt64(x)
@@ -355,6 +359,9 @@ IsJournalEmpty(SGlobPtr GPtr, fsckJournalInfo_t *jp)
char **namePtr = jp ? &jp->name : NULL;
if (debug)
plog("External Journal device\n");
+#if LINUX
+ goto out;
+#endif
jfd = OpenDeviceByUUID(&jib.ext_jnl_uuid, namePtr);
}
if (jfd == -1) {
@@ -3575,6 +3582,7 @@ static int RecordBadExtent(SGlobPtr GPtr, UInt32 fileID, UInt8 forkType,
/*
* Build a catalog node thread key.
*/
+#if !LINUX
__unused static void
buildthreadkey(UInt32 parentID, CatalogKey *key)
{
@@ -3582,7 +3590,7 @@ buildthreadkey(UInt32 parentID, CatalogKey *key)
key->hfsPlus.parentID = parentID;
key->hfsPlus.nodeName.length = 0;
}
-
+#endif
static void
printpath(SGlobPtr GPtr, UInt32 fileID)
@@ -4478,6 +4486,9 @@ static int CompareExtentFileID(const void *first, const void *second)
//int journal_replay(SGlobPtr gptr)
int journal_replay(const char *block_device)
{
+#if LINUX
+ return 0;
+#else
int retval = 0;
struct vfsconf vfc;
int mib[4];
@@ -4509,5 +4520,6 @@ int journal_replay(const char *block_device)
out:
return retval;
+#endif
}
diff --git a/fsck_hfs/dfalib/SVerify2.c b/fsck_hfs/dfalib/SVerify2.c
index 1249cf7..7fea077 100644
--- a/fsck_hfs/dfalib/SVerify2.c
+++ b/fsck_hfs/dfalib/SVerify2.c
@@ -31,7 +31,9 @@
*/
#include <sys/ioctl.h>
+#if !LINUX
#include <sys/disk.h>
+#endif
#include "BTree.h"
#include "BTreePrivate.h"
diff --git a/fsck_hfs/dfalib/Scavenger.h b/fsck_hfs/dfalib/Scavenger.h
index 7b8768f..a77cc65 100644
--- a/fsck_hfs/dfalib/Scavenger.h
+++ b/fsck_hfs/dfalib/Scavenger.h
@@ -41,12 +41,18 @@
#include <assert.h>
#include <sys/xattr.h>
+#if !LINUX
#include <sys/acl.h>
#include <sys/kauth.h>
-#include <sys/errno.h>
#include <sys/syslimits.h>
+#endif
+#include <sys/errno.h>
#include <sys/param.h>
+#if !LINUX
#include <sys/sysctl.h>
+#else
+#include <linux/sysctl.h>
+#endif
#include <sys/mount.h>
#include <hfs/hfs_mount.h>
diff --git a/fsck_hfs/dfalib/VolumeBitmapCheck.c b/fsck_hfs/dfalib/VolumeBitmapCheck.c
index dde1d92..92dfe2e 100644
--- a/fsck_hfs/dfalib/VolumeBitmapCheck.c
+++ b/fsck_hfs/dfalib/VolumeBitmapCheck.c
@@ -31,9 +31,15 @@
#include "Scavenger.h"
+#if !LINUX
#include <sys/disk.h>
+#endif
+#if !LINUX
#include <bitstring.h>
+#else
+#include <bsd/bitstring.h>
+#endif
#define bit_dealloc(p) free(p)
@@ -1080,18 +1086,23 @@ int AllocateContigBitmapBits (SVCB *vcb, UInt32 numBlocks, UInt32 *actualStartBl
return error;
}
+#if !LINUX
enum { kMaxTrimExtents = 256 };
dk_extent_t gTrimExtents[kMaxTrimExtents];
dk_unmap_t gTrimData;
+#endif
static void TrimInit(void)
{
+#if !LINUX
bzero(&gTrimData, sizeof(gTrimData));
gTrimData.extents = gTrimExtents;
+#endif
}
static void TrimFlush(void)
{
+#if !LINUX
int err;
if (gTrimData.extentsCount == 0)
@@ -1106,10 +1117,12 @@ static void TrimFlush(void)
DPRINTF(d_error|d_trim, "TrimFlush: error %d\n", errno);
}
gTrimData.extentsCount = 0;
+#endif
}
static void TrimExtent(SGlobPtr g, UInt32 startBlock, UInt32 blockCount)
{
+#if !LINUX
UInt64 offset;
UInt64 length;
@@ -1126,6 +1139,7 @@ static void TrimExtent(SGlobPtr g, UInt32 startBlock, UInt32 blockCount)
gTrimExtents[gTrimData.extentsCount].length = length;
if (++gTrimData.extentsCount == kMaxTrimExtents)
TrimFlush();
+#endif
}
/* Function: TrimFreeBlocks
@@ -1140,6 +1154,7 @@ static void TrimExtent(SGlobPtr g, UInt32 startBlock, UInt32 blockCount)
*/
void TrimFreeBlocks(SGlobPtr g)
{
+#if !LINUX
UInt32 *buffer;
UInt32 bit;
UInt32 wordWithinSegment;
@@ -1237,6 +1252,7 @@ void TrimFreeBlocks(SGlobPtr g)
TrimFlush();
DPRINTF(d_info|d_trim, "Trimmed %u allocation blocks.\n", totalTrimmed);
+#endif
}
/* Function: IsTrimSupported
@@ -1250,6 +1266,9 @@ void TrimFreeBlocks(SGlobPtr g)
*/
int IsTrimSupported(void)
{
+#if LINUX
+ return 0;
+#else
int err;
uint32_t features = 0;
@@ -1261,6 +1280,7 @@ int IsTrimSupported(void)
}
return features & DK_FEATURE_UNMAP;
+#endif
}
/*
diff --git a/fsck_hfs/dfalib/fsck_journal.c b/fsck_hfs/dfalib/fsck_journal.c
index 4ea2e53..4d5acc3 100644
--- a/fsck_hfs/dfalib/fsck_journal.c
+++ b/fsck_hfs/dfalib/fsck_journal.c
@@ -40,7 +40,14 @@
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
+
+#if !LINUX
#include <sys/disk.h>
+#else
+#include <linux/fs.h>
+#include "missing.h"
+#endif
+
#include <sys/param.h>
#include "../fsck_hfs.h"
diff --git a/fsck_hfs/dfalib/hfs_endian.c b/fsck_hfs/dfalib/hfs_endian.c
index 38fe64c..a1f92c9 100755
--- a/fsck_hfs/dfalib/hfs_endian.c
+++ b/fsck_hfs/dfalib/hfs_endian.c
@@ -32,7 +32,11 @@
#include <sys/types.h>
#include <sys/stat.h>
+#if !LINUX
#include <libkern/OSByteOrder.h>
+#else
+#include "missing.h"
+#endif
#include <hfs/hfs_format.h>
#include "Scavenger.h"
diff --git a/fsck_hfs/dfalib/hfs_endian.h b/fsck_hfs/dfalib/hfs_endian.h
index 923d7fd..aa642c5 100755
--- a/fsck_hfs/dfalib/hfs_endian.h
+++ b/fsck_hfs/dfalib/hfs_endian.h
@@ -30,7 +30,9 @@
* volume format.
*/
#include <hfs/hfs_format.h>
+#if !LINUX
#include <libkern/OSByteOrder.h>
+#endif
#include "SRuntime.h"
/*********************/
diff --git a/fsck_hfs/dfalib/uuid.c b/fsck_hfs/dfalib/uuid.c
index 4dea401..89feb4e 100644
--- a/fsck_hfs/dfalib/uuid.c
+++ b/fsck_hfs/dfalib/uuid.c
@@ -1,12 +1,16 @@
#include <fcntl.h>
+#if !LINUX
#include <util.h>
+#endif
#include <unistd.h>
#include <string.h>
#include <sys/mount.h>
#include <uuid/uuid.h>
+#if !LINUX
#include <IOKit/IOBSD.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/storage/IOMedia.h>
+#endif
extern char debug;
extern void plog(const char *, ...);
diff --git a/fsck_hfs/fsck_debug.h b/fsck_hfs/fsck_debug.h
index 3078c2d..c46f0b7 100644
--- a/fsck_hfs/fsck_debug.h
+++ b/fsck_hfs/fsck_debug.h
@@ -23,6 +23,10 @@
#ifndef __FSCK_DEBUG__
#define __FSCK_DEBUG__
+#if LINUX
+#include <bsd/bsd.h>
+#endif
+
#include <sys/types.h>
enum debug_message_type {
diff --git a/fsck_hfs/fsck_hfs.c b/fsck_hfs/fsck_hfs.c
index 49259b4..34b79de 100644
--- a/fsck_hfs/fsck_hfs.c
+++ b/fsck_hfs/fsck_hfs.c
@@ -23,16 +23,26 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/param.h>
+#if !LINUX
#include <sys/ucred.h>
+#endif
#include <sys/mount.h>
#include <sys/ioctl.h>
+#if !LINUX
#include <sys/disk.h>
#include <sys/sysctl.h>
-#include <err.h>
#include <setjmp.h>
+#endif
+
+#include <err.h>
#include <hfs/hfs_mount.h>
+#if LINUX
+#include <mntent.h>
+#include <linux/fs.h>
+#endif
+
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
@@ -42,7 +52,9 @@
#include <ctype.h>
#include <signal.h>
+#if !LINUX
#include <TargetConditionals.h>
+#endif
#include "fsck_hfs.h"
#include "fsck_msgnums.h"
@@ -234,6 +246,7 @@ main(argc, argv)
yflag = 0;
break;
+ case 'a':
case 'p':
preen++;
break;
@@ -279,12 +292,14 @@ main(argc, argv)
}
break;
}
-
+ case 'v':
+ fprintf(stderr, "%s: version %s\n", progname, VERSION);
+ exit(0);
+ break;
case 'y':
yflag++;
nflag = 0;
break;
-
case 'u':
case '?':
default:
@@ -303,10 +318,12 @@ main(argc, argv)
if (guiControl)
debug = 0; /* debugging is for command line only */
-
+#if LINUX
+// FIXME
+#else
if (signal(SIGINT, SIG_IGN) != SIG_IGN)
(void)signal(SIGINT, catch);
-
+#endif
if (argc < 1) {
(void) fplog(stderr, "%s: missing special-device\n", progname);
usage();
@@ -341,7 +358,12 @@ mountpoint(const char *cdev)
char *unraw = NULL;
int result;
int i;
-
+
+#if LINUX
+ FILE *fp = fopen("/proc/self/mounts", "r");
+ struct mntent *mntent;
+#endif
+
if (detonator_run)
return NULL;
@@ -351,6 +373,14 @@ mountpoint(const char *cdev)
if (unraw == NULL)
goto done;
+#if LINUX
+ while ((mntent = getmntent(fp))) {
+ if (strcmp(unraw, mntent->mnt_fsname) == 0) {
+ retval = strdup(mntent->mnt_dir);
+ break;
+ }
+ }
+#else
result = getmntinfo(&fsinfo, MNT_NOWAIT);
for (i = 0; i < result; i++) {
@@ -359,6 +389,7 @@ mountpoint(const char *cdev)
break;
}
}
+#endif
done:
if (unraw)
@@ -397,6 +428,9 @@ checkfilesys(char * filesys)
mntonname = strdup("/");
}
+#if LINUX
+ // FIXME
+#else
if (lflag && !detonator_run) {
struct stat fs_stat;
@@ -460,7 +494,7 @@ checkfilesys(char * filesys)
}
}
}
-
+#endif
if (debug && preen)
pwarn("starting\n");
@@ -575,6 +609,9 @@ checkfilesys(char * filesys)
}
}
} else {
+#if LINUX
+ // FIXME
+#else
struct statfs stfs_buf;
/*
@@ -585,8 +622,8 @@ checkfilesys(char * filesys)
else
flags = 0;
ckfini(flags & MNT_RDONLY);
+#endif
}
-
/* XXX free any allocated memory here */
if (hotmount && fsmodified) {
@@ -597,6 +634,9 @@ checkfilesys(char * filesys)
*/
if (!preen)
fsckPrint(context, fsckVolumeModified);
+#if LINUX
+ // FIXME
+#else
if (flags & MNT_RDONLY) {
bzero(&args, sizeof(args));
flags |= MNT_UPDATE | MNT_RELOAD;
@@ -611,6 +651,7 @@ checkfilesys(char * filesys)
fprintf(stderr, "update/reload mount for %s failed: %s\n", mntonname, strerror(errno));
}
}
+#endif
if (!preen)
plog("\n***** REBOOT NOW *****\n");
sync();
@@ -662,11 +703,13 @@ setup( char *dev, int *canWritePtr )
plog("Can't stat %s: %s\n", dev, strerror(errno));
return (0);
}
+#if !LINUX
if ((statb.st_mode & S_IFMT) != S_IFCHR) {
pfatal("%s is not a character device", dev);
if (reply("CONTINUE") == 0)
return (0);
}
+#endif
/* Always attempt to replay the journal */
if (!nflag && !quick) {
// We know we have a character device by now.
@@ -684,7 +727,11 @@ setup( char *dev, int *canWritePtr )
if (nflag == 0 && quick == 0) {
getWriteAccess( dev, canWritePtr );
}
-
+
+#if LINUX
+#define O_EXLOCK 0
+#endif
+
if (nflag || quick || (fswritefd = open(dev, O_RDWR | (hotmount ? 0 : O_EXLOCK))) < 0) {
fswritefd = -1;
if (preen) {
@@ -767,6 +814,7 @@ setup( char *dev, int *canWritePtr )
size_t dsize = sizeof(memSize);
int rv;
+#if !LINUX
rv = sysctlbyname("hw.memsize", &memSize, &dsize, NULL, 0);
if (rv == -1) {
(void)fplog(stderr, "sysctlbyname failed, not auto-setting cache size\n");
@@ -786,6 +834,7 @@ setup( char *dev, int *canWritePtr )
}
reqCacheSize = memSize / d;
}
+#endif
}
CalculateCacheSizes(reqCacheSize, &cacheBlockSize, &cacheTotalBlocks, debug);
@@ -812,11 +861,15 @@ setup( char *dev, int *canWritePtr )
static void getWriteAccess( char *dev, int *canWritePtr )
{
+#if !LINUX
int i;
int myMountsCount;
+#endif
void * myPtr;
char * myCharPtr;
+#if !LINUX
struct statfs * myBufPtr;
+#endif
void * myNamePtr;
int blockDevice_fd = -1;
@@ -840,6 +893,9 @@ static void getWriteAccess( char *dev, int *canWritePtr )
}
// get count of mounts then get the info for each
+#if LINUX
+ // FIXME
+#else
myMountsCount = getfsstat( NULL, 0, MNT_NOWAIT );
if ( myMountsCount < 0 )
goto ExitThisRoutine;
@@ -863,8 +919,8 @@ static void getWriteAccess( char *dev, int *canWritePtr )
}
myBufPtr++;
}
+#endif
*canWritePtr = 1; // single user will get us here, f_mntfromname is not /dev/diskXXXX
-
ExitThisRoutine:
if ( myPtr != NULL )
free( myPtr );
@@ -902,6 +958,7 @@ usage()
(void) fplog(stderr, " r = rebuild catalog btree \n");
(void) fplog(stderr, " S = Scan disk for bad blocks\n");
(void) fplog(stderr, " u = usage \n");
+ (void) fplog(stderr, " v = version\n");
(void) fplog(stderr, " y = assume a yes response \n");
exit(1);
@@ -943,12 +1000,14 @@ ScanDisk(int fd)
size_t bufSize = 1024 * 1024;
ssize_t nread;
off_t curPos = 0;
+#if !LINUX
void (*oldhandler)(int);
+#endif
uint32_t numErrors = 0;
uint32_t maxErrors = 40; // Something more variable?
-
+#if !LINUX
oldhandler = signal(SIGINFO, &siginfo);
-
+#endif
#define PRSTAT \
do { \
if (diskSize) { \
@@ -1049,7 +1108,9 @@ loop:
done:
if (buffer)
free(buffer);
+#if !LINUX
signal(SIGINFO, oldhandler);
+#endif
return;
}
diff --git a/fsck_hfs/fsck_hfs.h b/fsck_hfs/fsck_hfs.h
index 2630226..f6ef309 100644
--- a/fsck_hfs/fsck_hfs.h
+++ b/fsck_hfs/fsck_hfs.h
@@ -23,6 +23,9 @@
#include "cache.h"
+#if LINUX
+#include <bsd/bsd.h>
+#endif
const extern char *cdevname; /* name of device being checked */
extern char *progname;
diff --git a/fsck_hfs/fsck_messages.c b/fsck_hfs/fsck_messages.c
index b4bbb2c..34bcd84 100644
--- a/fsck_hfs/fsck_messages.c
+++ b/fsck_hfs/fsck_messages.c
@@ -21,6 +21,7 @@
* @APPLE_LICENSE_HEADER_END@
*/
+#define _GNU_SOURCE
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
@@ -29,6 +30,9 @@
#include <string.h>
#include <assert.h>
#include <sys/param.h>
+#if LINUX
+#include <bsd/stdio.h>
+#endif
#include "fsck_messages.h"
#include "fsck_keys.h"
@@ -531,11 +535,20 @@ doit:
break;
}
if (rv == -1) {
+#if LINUX
+ char resp[80];
+#else
char *resp = NULL;
+#endif
size_t len;
count++;
+#if LINUX
+ fgets (resp, 80, stdin);
+ len = strlen(resp);
+#else
resp = fgetln(stdin, &len);
+#endif
if (resp == NULL || len == 0) {
if (count > 10) {
// Only ask so many times...
diff --git a/fsck_hfs/fsck_messages.h b/fsck_hfs/fsck_messages.h
index d05ca48..83a0577 100644
--- a/fsck_hfs/fsck_messages.h
+++ b/fsck_hfs/fsck_messages.h
@@ -22,6 +22,10 @@
*/
#include <stdio.h>
+#if LINUX
+#include <bsd/bsd.h>
+#endif
+
#ifndef _FSCK_MESSAGES_H
#define _FSCK_MESSAGES_H
diff --git a/fsck_hfs/utilities.c b/fsck_hfs/utilities.c
index cb1c117..f8020c7 100644
--- a/fsck_hfs/utilities.c
+++ b/fsck_hfs/utilities.c
@@ -56,7 +56,14 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/errno.h>
+#if LINUX
+#include <limits.h>
+#include <signal.h>
+#include <bsd/stdio.h>
+#include <bsd/string.h>
+#else
#include <sys/syslimits.h>
+#endif
#include <pwd.h>
#include <ctype.h>
@@ -65,7 +72,9 @@
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
+#if !LINUX
#include <sys/sysctl.h>
+#endif
#include <fcntl.h>
#include "fsck_hfs.h"
@@ -194,12 +203,14 @@ retry:
plog("Can't stat %s\n", raw);
return (origname);
}
+#if !LINUX
if ((stchar.st_mode & S_IFMT) == S_IFCHR) {
return (raw);
} else {
plog("%s is not a character device\n", raw);
return (origname);
}
+#endif
} else if ((stblock.st_mode & S_IFMT) == S_IFCHR && !retried) {
newname = unrawname(newname);
retried++;
@@ -225,7 +236,11 @@ rawname(char *name)
*dp = 0;
(void)strlcpy(rawbuf, name, sizeof(rawbuf));
*dp = '/';
+#if LINUX
+ (void)strlcat(rawbuf, "/", sizeof(rawbuf));
+#else
(void)strlcat(rawbuf, "/r", sizeof(rawbuf));
+#endif
(void)strlcat(rawbuf, &dp[1], sizeof(rawbuf));
return (rawbuf);
@@ -1008,6 +1023,19 @@ fplog(FILE *stream, const char *fmt, ...)
#define kProgressToggle "kern.progressmeterenable"
#define kProgress "kern.progressmeter"
+#if LINUX
+void start_progress()
+{
+}
+
+void draw_progress(int pct)
+{
+}
+
+void end_progress()
+{
+}
+#else
void
start_progress(void)
{
@@ -1045,4 +1073,4 @@ end_progress(void)
warn("sysctl(%s) failed", kProgressToggle);
}
}
-
+#endif
diff --git a/include/hfs b/include/hfs
new file mode 120000
index 0000000..c73d9e1
--- /dev/null
+++ b/include/hfs
@@ -0,0 +1 @@
+../core
\ No newline at end of file
diff --git a/include/missing.h b/include/missing.h
new file mode 100644
index 0000000..e25a584
--- /dev/null
+++ b/include/missing.h
@@ -0,0 +1,128 @@
+#ifndef _MISSING_H_
+#define _MISSING_H_
+
+#include <endian.h>
+#include <byteswap.h>
+#include <errno.h>
+#include <stdint.h>
+
+typedef char uuid_string_t[37];
+#define __APPLE_API_PRIVATE
+#define __APPLE_API_UNSTABLE
+
+#define fsck_hfsVersionString "627.40.1"
+
+#define UF_IMMUTABLE 0x00000002
+#define XATTR_MAXNAMELEN 127
+#define MAXBSIZE (256 * 4096)
+
+#ifndef true
+#define true 1
+#endif
+#ifndef false
+#define false 0
+#endif
+
+/* Mac types */
+
+/* 8 Bit */
+#ifndef UInt8
+#define UInt8 uint8_t
+#endif
+#ifndef u_int8_t
+#define u_int8_t UInt8
+#endif
+#ifndef SInt8
+#define SInt8 int8_t
+#endif
+
+/* 16 Bit */
+#ifndef UInt16
+#define UInt16 uint16_t
+#endif
+#ifndef u_int16_t
+#define u_int16_t UInt16
+#endif
+#ifndef SInt16
+#define SInt16 int16_t
+#endif
+
+/* 32 Bit */
+#ifndef UInt32
+#define UInt32 uint32_t
+#endif
+#ifndef u_int32_t
+#define u_int32_t UInt32
+#endif
+#ifndef SInt32
+#define SInt32 int32_t
+#endif
+
+/* 64 Bit */
+#ifndef UInt64
+#define UInt64 uint64_t
+#endif
+#ifndef u_int64_t
+#define u_int64_t UInt64
+#endif
+#ifndef SInt64
+#define SInt64 int64_t
+#endif
+
+#define UniChar u_int16_t
+#define Boolean u_int8_t
+
+#define UF_NODUMP 0x00000001
+
+/* syslimits.h */
+#define NAME_MAX 255
+
+/* Byteswap stuff */
+#define OSSwapHostLongToBig(x) cpu_to_be64(x)
+#define OSSwapBigShortToHost(x) be16_to_cpu(x)
+#define OSSwapBigToHostInt16(x) be16_to_cpu(x)
+#define OSSwapBigLongToHost(x) be32_to_cpu(x)
+#define OSSwapBigToHostInt32(x) be32_to_cpu(x)
+#define OSSwapBigLongLongToHost(x) be64_to_cpu(x)
+#define OSSwapBigToHostInt64(x) be64_to_cpu(x)
+#define OSSwapHostToBigInt32(x) cpu_to_be32(x)
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+/* Big Endian Swaps */
+#ifndef be16_to_cpu
+#define be16_to_cpu(x) bswap_16(x)
+#endif
+#ifndef be32_to_cpu
+#define be32_to_cpu(x) bswap_32(x)
+#endif
+#ifndef cpu_to_be32
+#define cpu_to_be32(x) bswap_32(x)
+#endif
+#ifndef be64_to_cpu
+#define be64_to_cpu(x) bswap_64(x)
+#endif
+#ifndef cpu_to_be64
+#define cpu_to_be64(x) bswap_64(x)
+#endif
+#elif __BYTE_ORDER == __BIG_ENDIAN
+/* Big endian doesn't swap */
+#ifndef be16_to_cpu
+#define be16_to_cpu(x) (x)
+#endif
+#ifndef be32_to_cpu
+#define be32_to_cpu(x) (x)
+#endif
+#ifndef cpu_to_be32
+#define cpu_to_be32(x) (x)
+#endif
+#ifndef be64_to_cpu
+#define be64_to_cpu(x) (x)
+#endif
+#ifndef cpu_to_be64
+#define cpu_to_be64(x) (x)
+#endif
+#endif
+
+#define KAUTH_FILESEC_XATTR "com.apple.system.Security"
+
+#endif
diff --git a/include/sys/appleapiopts.h b/include/sys/appleapiopts.h
new file mode 100644
index 0000000..2ecde9d
--- /dev/null
+++ b/include/sys/appleapiopts.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#ifndef __SYS_APPLEAPIOPTS_H__
+#define __SYS_APPLEAPIOPTS_H__
+
+
+#ifndef __APPLE_API_STANDARD
+#define __APPLE_API_STANDARD
+#endif /* __APPLE_API_STANDARD */
+
+#ifndef __APPLE_API_STABLE
+#define __APPLE_API_STABLE
+#endif /* __APPLE_API_STABLE */
+
+#ifndef __APPLE_API_STRICT_CONFORMANCE
+
+#ifndef __APPLE_API_EVOLVING
+#define __APPLE_API_EVOLVING
+#endif /* __APPLE_API_EVOLVING */
+
+#ifndef __APPLE_API_UNSTABLE
+#define __APPLE_API_UNSTABLE
+#endif /* __APPLE_API_UNSTABLE */
+
+#ifndef __APPLE_API_PRIVATE
+#define __APPLE_API_PRIVATE
+#endif /* __APPLE_API_PRIVATE */
+
+#ifndef __APPLE_API_OBSOLETE
+#define __APPLE_API_OBSOLETE
+#endif /* __APPLE_API_OBSOLETE */
+
+#endif /* __APPLE_API_STRICT_CONFORMANCE */
+
+#endif /* __SYS_APPLEAPIOPTS_H__ */
+
diff --git a/newfs_hfs/hfs_endian.c b/newfs_hfs/hfs_endian.c
index 1370737..d324d18 100644
--- a/newfs_hfs/hfs_endian.c
+++ b/newfs_hfs/hfs_endian.c
@@ -31,7 +31,12 @@
#include <sys/types.h>
#include <sys/stat.h>
+#if LINUX
+#include "missing.h"
+#else
#include <libkern/OSByteOrder.h>
+#endif
+
#include <hfs/hfs_format.h>
#include "hfs_endian.h"
diff --git a/newfs_hfs/hfs_endian.h b/newfs_hfs/hfs_endian.h
index 9c3962b..abbf530 100644
--- a/newfs_hfs/hfs_endian.h
+++ b/newfs_hfs/hfs_endian.h
@@ -30,7 +30,12 @@
* volume format.
*/
#include <hfs/hfs_format.h>
+#if LINUX
+#include <endian.h>
+#include <byteswap.h>
+#else
#include <libkern/OSByteOrder.h>
+#endif
/*********************/
/* BIG ENDIAN Macros */
diff --git a/newfs_hfs/makehfs.c b/newfs_hfs/makehfs.c
index a97c89e..feee374 100644
--- a/newfs_hfs/makehfs.c
+++ b/newfs_hfs/makehfs.c
@@ -32,11 +32,22 @@
#include <sys/param.h>
#include <sys/types.h>
#include <sys/time.h>
+#if LINUX
+#include <time.h>
+#include "missing.h"
+#endif
#include <err.h>
#include <sys/errno.h>
#include <sys/stat.h>
+#if !LINUX
#include <sys/sysctl.h>
+#else
+#include <linux/sysctl.h>
+#endif
+
+#if !LINUX
#include <sys/vmmeter.h>
+#endif
#include <err.h>
#include <errno.h>
@@ -47,11 +58,11 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+#if !LINUX
#include <wipefs.h>
+#endif
-#include <TargetConditionals.h>
-
-#if TARGET_OS_IPHONE
+#if TARGET_OS_IPHONE || LINUX
// CoreServices is not available, so...
@@ -86,6 +97,7 @@ enum {
* with OpenSSL, so we don't have to change the code.
*/
#define COMMON_DIGEST_FOR_OPENSSL
+#if !LINUX
#include <CommonCrypto/CommonDigest.h>
#include <libkern/OSByteOrder.h>
@@ -98,7 +110,9 @@ enum {
#include <TargetConditionals.h>
extern Boolean _CFStringGetFileSystemRepresentation(CFStringRef string, UInt8 *buffer, CFIndex maxBufLen);
-
+#else
+#include <sha.h>
+#endif
#include <hfs/hfs_format.h>
#include <hfs/hfs_mount.h>
@@ -169,7 +183,9 @@ static void WriteBuffer __P((const DriveInfo *driveInfo, UInt64 startingSector,
UInt64 byteCount, const void *buffer));
static UInt32 Largest __P((UInt32 a, UInt32 b, UInt32 c, UInt32 d ));
+#if !LINUX
static UInt32 GetDefaultEncoding();
+#endif
static UInt32 UTCToLocal __P((UInt32 utcTime));
@@ -194,6 +210,9 @@ void SETOFFSET (void *buffer, UInt16 btNodeSize, SInt16 recOffset, SInt16 vecOff
#define ROUNDUP(x, u) (((x) % (u) == 0) ? (x) : ((x)/(u) + 1) * (u))
+#if LINUX
+#define ENCODING_TO_BIT(e) (e)
+#else
#if TARGET_OS_IPHONE
#define ENCODING_TO_BIT(e) \
((e) < 48 ? (e) : 0)
@@ -213,6 +232,7 @@ struct cp_root_xattr {
u_int8_t reserved3[16];
} __attribute__((aligned(2), packed));
#endif
+#endif
/*
* Create a series of (sequential!) extents for the
@@ -322,6 +342,7 @@ createExtents(HFSPlusForkData *file,
return;
}
+#if !LINUX
/*
* wipefs() in -lutil knows about multiple filesystem formats.
* This replaces the code:
@@ -343,7 +364,7 @@ dowipefs(int fd)
wipefs_free(&handle);
return err;
}
-
+#endif
/*
* make_hfsplus
@@ -368,13 +389,14 @@ make_hfsplus(const DriveInfo *driveInfo, hfsparams_t *defaults)
HFSPlusVolumeHeader *header = NULL;
UInt64 sector;
+#if !LINUX
/* Use wipefs() API to clear old metadata from the device.
* This should be done before we start writing anything on the
* device as wipefs will internally call ioctl(DKIOCDISCARD) on the
* entire device.
*/
(void) dowipefs(driveInfo->fd);
-
+#endif
/* --- Create an HFS Plus header: */
header = (HFSPlusVolumeHeader*)malloc((size_t)kBytesPerSector);
@@ -1146,7 +1168,8 @@ WriteExtentsFile(const DriveInfo *driveInfo, UInt64 startingSector,
offset += nodeBitsInHeader/8;
SETOFFSET(buffer, nodeSize, offset, 4);
-
+
+#if !LINUX
if (NEWFS_HFS_DEBUG && numOverflowExtents) {
void *node2 = (uint8_t*)buffer + nodeSize;
size_t i;
@@ -1180,6 +1203,7 @@ WriteExtentsFile(const DriveInfo *driveInfo, UInt64 startingSector,
}
SETOFFSET(node2, nodeSize, offset, numOverflowExtents + 1);
}
+#endif
*bytesUsed = (SWAP_BE32 (bthp->totalNodes) - SWAP_BE32 (bthp->freeNodes) - *mapNodes) * nodeSize;
@@ -1371,7 +1395,7 @@ WriteAttributesFile(const DriveInfo *driveInfo, UInt64 startingSector,
WriteBuffer(driveInfo, startingSector, *bytesUsed, buffer);
}
-#if !TARGET_OS_IPHONE
+#if !TARGET_OS_IPHONE && !LINUX
static int
get_dev_uuid(const char *disk_name, char *dev_uuid_str, int dev_uuid_len)
{
@@ -1622,9 +1646,11 @@ InitCatalogRoot_HFSPlus(const hfsparams_t *dp, const HFSPlusVolumeHeader *header
UInt16 nodeSize;
SInt16 offset;
size_t unicodeBytes;
+#if !LINUX
UInt8 canonicalName[kHFSPlusMaxFileNameBytes]; // UTF8 character may convert to three bytes, plus a NUL
CFStringRef cfstr;
Boolean cfOK;
+#endif
int index = 0;
nodeSize = dp->catalogNodeSize;
@@ -1644,7 +1670,9 @@ InitCatalogRoot_HFSPlus(const hfsparams_t *dp, const HFSPlusVolumeHeader *header
* First record is always the root directory...
*/
ckp = (HFSPlusCatalogKey *)((UInt8 *)buffer + offset);
-
+#if LINUX
+ ConvertUTF8toUnicode(dp->volumeName, sizeof(ckp->nodeName.unicode), ckp->nodeName.unicode, &ckp->nodeName.length);
+#else
/* Use CFString functions to get a HFSPlus Canonical name */
cfstr = CFStringCreateWithCString(kCFAllocatorDefault, (char *)dp->volumeName, kCFStringEncodingUTF8);
cfOK = _CFStringGetFileSystemRepresentation(cfstr, canonicalName, sizeof(canonicalName));
@@ -1661,6 +1689,7 @@ InitCatalogRoot_HFSPlus(const hfsparams_t *dp, const HFSPlusVolumeHeader *header
dp->volumeName, kDefaultVolumeNameStr);
}
CFRelease(cfstr);
+#endif
ckp->nodeName.length = SWAP_BE16 (ckp->nodeName.length);
unicodeBytes = sizeof(UniChar) * SWAP_BE16 (ckp->nodeName.length);
@@ -1672,9 +1701,12 @@ InitCatalogRoot_HFSPlus(const hfsparams_t *dp, const HFSPlusVolumeHeader *header
cdp = (HFSPlusCatalogFolder *)((UInt8 *)buffer + offset);
cdp->recordType = SWAP_BE16 (kHFSPlusFolderRecord);
/* folder count is only supported on HFSX volumes */
+#if !LINUX
+ // FIXME
if (dp->flags & kMakeCaseSensitive) {
cdp->flags = SWAP_BE16 (kHFSHasFolderCountMask);
}
+#endif
cdp->valence = SWAP_BE32 (dp->journaledHFS ? 2 : 0);
cdp->folderID = SWAP_BE32 (kHFSRootFolderID);
cdp->createDate = SWAP_BE32 (dp->createDate);
@@ -2080,12 +2112,14 @@ void GenerateVolumeUUID(VolumeUUID *newVolumeID) {
unsigned char digest[20];
time_t now;
clock_t uptime;
- int mib[2];
- int sysdata;
- char sysctlstring[128];
size_t datalen;
double sysloadavg[3];
+#if !LINUX
+ int sysdata;
+ int mib[2];
+ char sysctlstring[128];
struct vmtotal sysvmtotal;
+#endif
do {
/* Initialize the SHA-1 context for processing: */
@@ -2098,52 +2132,58 @@ void GenerateVolumeUUID(VolumeUUID *newVolumeID) {
SHA1_Update(&context, &uptime, sizeof(uptime));
/* The kernel's boot time: */
+#if !LINUX
mib[0] = CTL_KERN;
mib[1] = KERN_BOOTTIME;
datalen = sizeof(sysdata);
sysctl(mib, 2, &sysdata, &datalen, NULL, 0);
SHA1_Update(&context, &sysdata, datalen);
-
+#endif
/* The system's host id: */
+#if !LINUX
mib[0] = CTL_KERN;
mib[1] = KERN_HOSTID;
datalen = sizeof(sysdata);
sysctl(mib, 2, &sysdata, &datalen, NULL, 0);
SHA1_Update(&context, &sysdata, datalen);
-
+#endif
/* The system's host name: */
+#if !LINUX
mib[0] = CTL_KERN;
mib[1] = KERN_HOSTNAME;
datalen = sizeof(sysctlstring);
sysctl(mib, 2, sysctlstring, &datalen, NULL, 0);
SHA1_Update(&context, sysctlstring, datalen);
-
+#endif
/* The running kernel's OS release string: */
+#if !LINUX
mib[0] = CTL_KERN;
mib[1] = KERN_OSRELEASE;
datalen = sizeof(sysctlstring);
sysctl(mib, 2, sysctlstring, &datalen, NULL, 0);
SHA1_Update(&context, sysctlstring, datalen);
-
+#endif
/* The running kernel's version string: */
+#if !LINUX
mib[0] = CTL_KERN;
mib[1] = KERN_VERSION;
datalen = sizeof(sysctlstring);
sysctl(mib, 2, sysctlstring, &datalen, NULL, 0);
SHA1_Update(&context, sysctlstring, datalen);
-
+#endif
/* The system's load average: */
datalen = sizeof(sysloadavg);
getloadavg(sysloadavg, 3);
SHA1_Update(&context, &sysloadavg, datalen);
/* The system's VM statistics: */
+#if !LINUX
mib[0] = CTL_VM;
mib[1] = VM_METER;
datalen = sizeof(sysvmtotal);
sysctl(mib, 2, &sysvmtotal, &datalen, NULL, 0);
SHA1_Update(&context, &sysvmtotal, datalen);
-
+#endif
/* The current GMT (26 ASCII characters): */
time(&now);
strncpy(randomInputBuffer, asctime(gmtime(&now)), 26); /* "Mon Mar 27 13:46:26 2000" */
diff --git a/newfs_hfs/newfs_hfs.c b/newfs_hfs/newfs_hfs.c
index e9f07a9..7d7c3d6 100644
--- a/newfs_hfs/newfs_hfs.c
+++ b/newfs_hfs/newfs_hfs.c
@@ -39,8 +39,17 @@
#include <sys/mount.h>
#include <sys/param.h>
#include <sys/stat.h>
+#if LINUX
+#include <time.h>
+#endif
+#if !LINUX
#include <IOKit/storage/IOMediaBSDClient.h>
+#endif
+
+#if LINUX
+#include "missing.h"
+#endif
#include <hfs/hfs_format.h>
#include "newfs_hfs.h"
@@ -202,8 +211,10 @@ main(argc, argv)
extern char *optarg;
extern int optind;
int ch;
+#if !LINUX
char *cp, *special;
struct statfs *mp;
+#endif
int n;
if ((progname = strrchr(*argv, '/')))
@@ -360,6 +371,9 @@ main(argc, argv)
if (argc != 1)
usage();
+#if LINUX
+ (void) sprintf(blkdevice, "%s", argv[0]);
+#else
special = argv[0];
cp = strrchr(special, '/');
if (cp != 0)
@@ -368,12 +382,16 @@ main(argc, argv)
special++;
(void) snprintf(rawdevice, sizeof(rawdevice), "%sr%s", _PATH_DEV, special);
(void) snprintf(blkdevice, sizeof(blkdevice), "%s%s", _PATH_DEV, special);
+#endif
}
if (gPartitionSize == 0) {
/*
* Check if target device is aready mounted
*/
+#if LINUX
+ //FIXME
+#else
n = getmntinfo(&mp, MNT_NOWAIT);
if (n == 0)
fatal("%s: getmntinfo: %s", blkdevice, strerror(errno));
@@ -383,10 +401,14 @@ main(argc, argv)
fatal("%s is mounted on %s", blkdevice, mp->f_mntonname);
++mp;
}
+#endif
}
-
- if (hfs_newfs(rawdevice) < 0) {
+ if (hfs_newfs(blkdevice) < 0) {
+#if LINUX
+ err(1, "cannot create filesystem on %s", blkdevice);
+#else
err(1, "cannot create filesystem on %s", rawdevice);
+#endif
}
exit(0);
@@ -863,8 +885,10 @@ hfs_newfs(char *device)
int fso = -1;
int retval = 0;
hfsparams_t defaults = {0};
+#if !LINUX
UInt64 maxPhysPerIO = 0;
-
+#endif
+
if (gPartitionSize) {
dip.sectorSize = kBytesPerSector;
dip.physTotalSectors = dip.totalSectors = gPartitionSize / kBytesPerSector;
@@ -881,8 +905,9 @@ hfs_newfs(char *device)
}
dip.fd = fso;
+#if !LINUX
fcntl(fso, F_NOCACHE, 1);
-
+#endif
if (fso < 0)
fatal("%s: %s", device, strerror(errno));
diff --git a/newfs_hfs/newfs_hfs.h b/newfs_hfs/newfs_hfs.h
index d336282..599d6fc 100644
--- a/newfs_hfs/newfs_hfs.h
+++ b/newfs_hfs/newfs_hfs.h
@@ -20,8 +20,12 @@
*
* @APPLE_LICENSE_HEADER_END@
*/
-
-#include <CoreFoundation/CFBase.h>
+
+#if !LINUX
+#include <CoreFoundation/CFBase.h>*/
+#else
+#include <bsd/bsd.h>
+#endif
enum {
kMinHFSPlusVolumeSize = (512 * 1024),
--
2.41.0