~ubuntu-branches/ubuntu/trusty/hfsprogs/trusty-proposed

« back to all changes in this revision

Viewing changes to debian/patches/0002-Add-exclude-Darwin-specific-code.patch

  • Committer: Package Import Robot
  • Author(s): Rogério Brito
  • Date: 2013-10-24 01:20:15 UTC
  • Revision ID: package-import@ubuntu.com-20131024012015-qsncxmr4cielybvz
Tags: 332.25-11
* debian/control: Remove DMUA flag.
* debian/rules: Override rules for which we don't have makefiles.
  (Closes: #724195)
* debian/patches:
  + Change the headers to be friendlier with gbp pq.
  + Remove unreferenced patches in series file.
  + Coalesce all patches touching man pages into one.
  + Regenerate everything from patch-queue branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
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).
 
7
---
 
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
 
31
 
 
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
 
36
@@ -26,7 +26,11 @@
 
37
 #include <stdlib.h>
 
38
 #include <sys/mman.h>
 
39
 #include <sys/stat.h>
 
40
+#if LINUX
 
41
+#include "missing.h"
 
42
+#else
 
43
 #include <sys/types.h>
 
44
+#endif /* __LINUX__ */
 
45
 #include <sys/uio.h>
 
46
 #include <unistd.h>
 
47
 #include <string.h>
 
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,
 
53
                                                                 UInt16                                  version,
 
54
                                                                 BTreeInfoRec                   *info )
 
55
 {
 
56
+#if !LINUX
 
57
 #pragma unused (version)
 
58
+#endif
 
59
 
 
60
        BTreeControlBlockPtr    btreePtr;
 
61
 
 
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
 
66
@@ -20,6 +20,9 @@
 
67
  * @APPLE_LICENSE_HEADER_END@
 
68
  */
 
69
 
 
70
+#if LINUX
 
71
+#include "missing.h"
 
72
+#endif
 
73
 #include "SRuntime.h"
 
74
 #include "Scavenger.h"
 
75
 #include "../cache.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:
 
81
 OSStatus
 
82
 SetEndOfForkProc ( SFCB *filePtr, FSSize minEOF, FSSize maxEOF )
 
83
 {
 
84
+#if !LINUX
 
85
 #pragma unused (maxEOF)
 
86
+#endif
 
87
 
 
88
        OSStatus        result;
 
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
 
94
@@ -2,7 +2,7 @@
 
95
  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
 
96
  *
 
97
  * @APPLE_LICENSE_HEADER_START@
 
98
- * 
 
99
+ *
 
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
 
103
@@ -10,7 +10,7 @@
 
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
 
106
  * this file.
 
107
- * 
 
108
+ *
 
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,
 
112
@@ -18,7 +18,7 @@
 
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."
 
116
- * 
 
117
+ *
 
118
  * @APPLE_LICENSE_HEADER_END@
 
119
  */
 
120
 #include "SRuntime.h"
 
121
@@ -28,33 +28,71 @@
 
122
 #include <unistd.h>
 
123
 #include <errno.h>
 
124
 #include <sys/ioctl.h>
 
125
-
 
126
+#if LINUX
 
127
+#include <fcntl.h>
 
128
+#include <sys/stat.h>
 
129
+#else
 
130
 #include <IOKit/storage/IOMediaBSDClient.h>
 
131
-
 
132
+#endif /* LINUX */
 
133
 #else
 
134
-
 
135
 #include <Files.h>
 
136
 #include <Device.h>
 
137
 #include <Disks.h>
 
138
 
 
139
 #endif
 
140
 
 
141
-
 
142
 OSErr GetDeviceSize(int driveRefNum, UInt64 *numBlocks, UInt32 *blockSize)
 
143
 {
 
144
 #if BSD
 
145
        UInt64 devBlockCount = 0;
 
146
        int devBlockSize = 0;
 
147
+#if LINUX
 
148
+       struct stat stbuf;
 
149
+
 
150
+       devBlockSize = 512;
 
151
 
 
152
+#ifndef BLKGETSIZE
 
153
+#define BLKGETSIZE              _IO(0x12,96)
 
154
+#endif
 
155
+#ifndef BLKGETSIZE64
 
156
+#define BLKGETSIZE64            _IOR(0x12,114,size_t)
 
157
+#endif
 
158
+       if (fstat(driveRefNum, &stbuf) < 0){
 
159
+               printf("Error: %s\n", strerror(errno));
 
160
+               return(-1);
 
161
+       }
 
162
+
 
163
+        if (S_ISREG(stbuf.st_mode)) {
 
164
+                devBlockCount = stbuf.st_size / 512;
 
165
+        }
 
166
+        else if (S_ISBLK(stbuf.st_mode)) {
 
167
+                unsigned long size;
 
168
+                u_int64_t size64;
 
169
+                if (!ioctl(driveRefNum, BLKGETSIZE64, &size64))
 
170
+                        devBlockCount = size64 / 512;
 
171
+                else if (!ioctl(driveRefNum, BLKGETSIZE, &size))
 
172
+                        devBlockCount = size;
 
173
+                else{
 
174
+                        printf("Error: %s\n", strerror(errno));
 
175
+                       return(-1);
 
176
+               }
 
177
+
 
178
+        }
 
179
+        else{
 
180
+                printf("Device is not a block device");
 
181
+               return(-1);
 
182
+       }
 
183
+#elif BSD
 
184
        if (ioctl(driveRefNum, DKIOCGETBLOCKCOUNT, &devBlockCount) < 0) {
 
185
                printf("ioctl(DKIOCGETBLOCKCOUNT) for fd %d: %s\n", driveRefNum, strerror(errno));
 
186
                return (-1);
 
187
        }
 
188
-       
 
189
+
 
190
        if (ioctl(driveRefNum, DKIOCGETBLOCKSIZE, &devBlockSize) < 0) {
 
191
                printf("ioctl(DKIOCGETBLOCKSIZE) for fd %d: %s\n", driveRefNum, strerror(errno));
 
192
                return (-1);
 
193
        }
 
194
+#endif /* BSD */
 
195
 
 
196
        if (devBlockSize != 512) {
 
197
                *numBlocks = (devBlockCount * (UInt64)devBlockSize) / 512;
 
198
@@ -70,24 +108,24 @@ OSErr GetDeviceSize(int driveRefNum, UInt64 *numBlocks, UInt32 *blockSize)
 
199
        {
 
200
                /* return format list status code */
 
201
                kFmtLstCode = 6,
 
202
-               
 
203
+
 
204
                /* reference number of .SONY driver */
 
205
                kSonyRefNum = 0xfffb,
 
206
-               
 
207
+
 
208
                /* values returned by DriveStatus in DrvSts.twoSideFmt */
 
209
                kSingleSided = 0,
 
210
                kDoubleSided = -1,
 
211
                kSingleSidedSize = 800,         /* 400K */
 
212
                kDoubleSidedSize = 1600,        /* 800K */
 
213
-               
 
214
+
 
215
                /* values in DrvQEl.qType */
 
216
                kWordDrvSiz = 0,
 
217
                kLongDrvSiz = 1,
 
218
-               
 
219
+
 
220
                /* more than enough formatListRecords */
 
221
                kMaxFormatListRecs = 16
 
222
        };
 
223
-       
 
224
+
 
225
        ParamBlockRec   pb;
 
226
        FormatListRec   formatListRecords[kMaxFormatListRecs];
 
227
        DrvSts                  status;
 
228
@@ -95,22 +133,22 @@ OSErr GetDeviceSize(int driveRefNum, UInt64 *numBlocks, UInt32 *blockSize)
 
229
        OSErr                   result;
 
230
        unsigned long   blocks                  = 0;
 
231
 
 
232
-       
 
233
+
 
234
        /* Attempt to get the drive's format list. */
 
235
        /* (see the Technical Note "What Your Sony Drives For You") */
 
236
-       
 
237
+
 
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];
 
243
-       
 
244
+
 
245
        result = PBStatusSync(&pb);
 
246
-       
 
247
+
 
248
        if ( result == noErr )
 
249
        {
 
250
                /* The drive supports ReturnFormatList status call. */
 
251
-               
 
252
+
 
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 )
 
258
        {
 
259
                /* The drive is a non-SuperDrive floppy which only supports 400K and 800K disks */
 
260
-               
 
261
+
 
262
                result = DriveStatus(driveQElementPtr->dQDrive, &status);
 
263
                if ( result == noErr )
 
264
                {
 
265
@@ -140,11 +178,11 @@ OSErr GetDeviceSize(int driveRefNum, UInt64 *numBlocks, UInt32 *blockSize)
 
266
                                case kSingleSided:
 
267
                                        blocks = kSingleSidedSize;
 
268
                                        break;
 
269
-                                       
 
270
+
 
271
                                case kDoubleSided:
 
272
                                        blocks = kDoubleSidedSize;
 
273
                                        break;
 
274
-                                       
 
275
+
 
276
                                default:                //      This should never happen
 
277
                                        result = paramErr;
 
278
                                        break;
 
279
@@ -155,20 +193,20 @@ OSErr GetDeviceSize(int driveRefNum, UInt64 *numBlocks, UInt32 *blockSize)
 
280
        {
 
281
                /* The drive is not a floppy and it doesn't support ReturnFormatList */
 
282
                /* so use the dQDrvSz field(s) */
 
283
-               
 
284
+
 
285
                result = noErr; /* reset result */
 
286
-               
 
287
+
 
288
                switch ( driveQElementPtr->qType )
 
289
                {
 
290
                        case kWordDrvSiz:
 
291
                                blocks = driveQElementPtr->dQDrvSz;
 
292
                                break;
 
293
-                               
 
294
+
 
295
                        case kLongDrvSiz:
 
296
                                blocks = ((unsigned long)driveQElementPtr->dQDrvSz2 << 16) +
 
297
                                                 driveQElementPtr->dQDrvSz;
 
298
                                break;
 
299
-                               
 
300
+
 
301
                        default:                //      This should never happen
 
302
                                result = paramErr;
 
303
                                break;
 
304
@@ -177,7 +215,7 @@ OSErr GetDeviceSize(int driveRefNum, UInt64 *numBlocks, UInt32 *blockSize)
 
305
 
 
306
        *numBlocks = blocks;
 
307
        *blockSize = 512;
 
308
-       
 
309
+
 
310
        return( result );
 
311
 #endif
 
312
 }
 
313
@@ -188,7 +226,7 @@ OSErr DeviceRead(int device, int drive, void* buffer, SInt64 offset, UInt32 reqB
 
314
 #if BSD
 
315
        off_t seek_off;
 
316
        ssize_t nbytes;
 
317
-       
 
318
+
 
319
        *actBytes = 0;
 
320
 
 
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.
 
329
  */
 
330
+#if !LINUX
 
331
 __private_extern__
 
332
+#endif
 
333
 SInt32
 
334
 CompareAttributeKeys(const AttributeKey *searchKey, const AttributeKey *trialKey)
 
335
 {
 
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:
 
341
 
 
342
 static OSErr   FixWrapperExtents( SGlobPtr GPtr, RepairOrderPtr p )
 
343
 {
 
344
+#if !LINUX
 
345
 #pragma unused (p)
 
346
+#endif
 
347
 
 
348
        OSErr                                           err;
 
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
 
354
@@ -27,8 +27,11 @@
 
355
 #define __SRUNTIME__
 
356
 
 
357
 #if BSD
 
358
-
 
359
+#if LINUX
 
360
+#include "missing.h"
 
361
+#else
 
362
 #include <sys/types.h>
 
363
+#endif
 
364
 #include <stdlib.h>
 
365
 #include <string.h>
 
366
 #include <stdio.h>
 
367
@@ -91,10 +94,12 @@ typedef const unsigned char *       ConstStr255Param;
 
368
 
 
369
 typedef u_int32_t      HFSCatalogNodeID;
 
370
 
 
371
+#if !LINUX
 
372
 enum {
 
373
        false           = 0,
 
374
        true            = 1
 
375
 };
 
376
+#endif
 
377
 
 
378
 /* OS error codes */
 
379
 enum {
 
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
 //------------------------------------------------------------------------------
 
387
 
 
388
-#if !BSD       
 
389
+#if BSD
 
390
+#if !LINUX
 
391
 OSErr GetVolumeFeatures( SGlobPtr GPtr )
 
392
 {
 
393
        OSErr                                   err;
 
394
@@ -418,7 +419,7 @@ OSErr GetVolumeFeatures( SGlobPtr GPtr )
 
395
        return( noErr );
 
396
 }
 
397
 #endif
 
398
-
 
399
+#endif
 
400
 
 
401
 
 
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
 
407
@@ -32,7 +32,9 @@
 
408
 */
 
409
 
 
410
 #include <sys/ioctl.h>
 
411
+#if !LINUX
 
412
 #include <sys/disk.h>
 
413
+#endif
 
414
 
 
415
 #include "BTree.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. 
 
420
         */
 
421
+#if LINUX
 
422
+       // FIXME
 
423
+       isWriteable = 1;
 
424
+#else
 
425
        isWriteable = 0;
 
426
        ioctl( GPtr->DrvNum, DKIOCISWRITABLE, &isWriteable );
 
427
+#endif
 
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
 
435
@@ -37,11 +37,16 @@
 
436
 #include "../fsck_debug.h"
 
437
 
 
438
 #include <assert.h>
 
439
+#if LINUX
 
440
+#define XATTR_MAXNAMELEN 127
 
441
+#include <limits.h>
 
442
+#else
 
443
 #include <sys/xattr.h>
 
444
 #include <sys/acl.h>
 
445
 #include <sys/kauth.h>
 
446
-#include <sys/errno.h>
 
447
 #include <sys/syslimits.h>
 
448
+#endif
 
449
+#include <sys/errno.h>
 
450
 
 
451
 #ifdef __cplusplus
 
452
 extern "C" {
 
453
@@ -1465,4 +1470,8 @@ extern int        AllocateContigBitmapBits (SVCB *vcb, UInt32 numBlocks, UInt32 *actua
 
454
 };
 
455
 #endif
 
456
 
 
457
+/* #if LINUX
 
458
+#undef XATTR_MAXNAMELEN
 
459
+#endif */
 
460
+
 
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
 
466
@@ -31,7 +31,11 @@
 
467
 #include <sys/types.h>
 
468
 #include <sys/stat.h>
 
469
 
 
470
+#if LINUX
 
471
+#include "missing.h"
 
472
+#else
 
473
 #include <architecture/byte_order.h>
 
474
+#endif
 
475
 #include <hfs/hfs_format.h>
 
476
 
 
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
 
482
@@ -27,9 +27,14 @@
 
483
  *
 
484
  * This file prototypes endian swapping routines for the HFS/HFS Plus
 
485
  * volume format.
 
486
- */
 
487
+*/
 
488
 #include <hfs/hfs_format.h>
 
489
+#if LINUX
 
490
+#include <endian.h>
 
491
+#include <byteswap.h>
 
492
+#else
 
493
 #include <architecture/byte_order.h>
 
494
+#endif
 
495
 #include "SRuntime.h"
 
496
 
 
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
 
502
@@ -24,10 +24,14 @@
 
503
 #include <sys/types.h>
 
504
 #include <sys/stat.h>
 
505
 #include <sys/param.h>
 
506
+#if !LINUX
 
507
 #include <sys/ucred.h>
 
508
+#endif
 
509
 #include <sys/mount.h>
 
510
 #include <sys/ioctl.h>
 
511
+#if !LINUX
 
512
 #include <sys/disk.h>
 
513
+#endif
 
514
 
 
515
 #include <hfs/hfs_mount.h>
 
516
 
 
517
@@ -195,8 +199,12 @@ main(argc, argv)
 
518
        if (guiControl)
 
519
                debug = 0; /* debugging is for command line only */
 
520
 
 
521
+#if LINUX
 
522
+// FIXME
 
523
+#else
 
524
        if (signal(SIGINT, SIG_IGN) != SIG_IGN)
 
525
                (void)signal(SIGINT, catch);
 
526
+#endif
 
527
 
 
528
        if (argc < 1) {
 
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;
 
534
+#if !LINUX
 
535
        struct statfs *fsinfo;
 
536
+#endif
 
537
        int fs_fd=-1;  // fd to the root-dir of the fs we're checking (only w/lfag == 1)
 
538
 
 
539
        flags = 0;
 
540
@@ -227,7 +237,9 @@ checkfilesys(char * filesys)
 
541
        canWrite = 0;
 
542
        unraw = NULL;
 
543
        mntonname = NULL;
 
544
-
 
545
+#if LINUX
 
546
+       // FIXME
 
547
+#else
 
548
        if (lflag) {
 
549
                result = getmntinfo(&fsinfo, MNT_NOWAIT);
 
550
 
 
551
@@ -257,10 +269,10 @@ checkfilesys(char * filesys)
 
552
                    }
 
553
                }
 
554
        }
 
555
-
 
556
+#endif
 
557
        if (debug && preen)
 
558
                pwarn("starting\n");
 
559
-       
 
560
+
 
561
        if (setup( filesys, &blockDevice_fd, &canWrite ) == 0) {
 
562
                if (preen)
 
563
                        pfatal("CAN'T CHECK FILE SYSTEM.");
 
564
@@ -278,7 +290,7 @@ checkfilesys(char * filesys)
 
565
        repLev = kMajorRepairs;
 
566
        logLev = kVerboseLog;
 
567
 
 
568
-       if (yflag)      
 
569
+       if (yflag)
 
570
                repLev = kMajorRepairs;
 
571
 
 
572
        if (quick) {
 
573
@@ -298,16 +310,16 @@ checkfilesys(char * filesys)
 
574
 
 
575
        if (nflag)
 
576
                repLev = kNeverRepair;
 
577
-               
 
578
+
 
579
        if ( rebuildCatalogBtree ) {
 
580
                chkLev = kPartialCheck;
 
581
                repLev = kForceRepairs;  // this will force rebuild of catalog B-Tree file
 
582
        }
 
583
-               
 
584
+
 
585
        /*
 
586
         * go check HFS volume...
 
587
         */
 
588
-       result = CheckHFS(      fsreadfd, fswritefd, chkLev, repLev, logLev, 
 
589
+       result = CheckHFS(      fsreadfd, fswritefd, chkLev, repLev, logLev,
 
590
                                                guiControl, lostAndFoundMode, canWrite, &fsmodified );
 
591
        if (!hotroot) {
 
592
                ckfini(1);
 
593
@@ -330,6 +342,9 @@ checkfilesys(char * filesys)
 
594
                        }
 
595
                }
 
596
        } else {
 
597
+#if LINUX
 
598
+       // FIXME
 
599
+#else
 
600
                struct statfs stfs_buf;
 
601
                /*
 
602
                 * Check to see if root is mounted read-write.
 
603
@@ -339,19 +354,25 @@ checkfilesys(char * filesys)
 
604
                else
 
605
                        flags = 0;
 
606
                ckfini(flags & MNT_RDONLY);
 
607
+#endif
 
608
        }
 
609
 
 
610
        /* XXX free any allocated memory here */
 
611
 
 
612
        if (hotroot && fsmodified) {
 
613
+#if !LINUX
 
614
                struct hfs_mount_args args;
 
615
+#endif
 
616
                /*
 
617
                 * We modified the root.  Do a mount update on
 
618
                 * it, unless it is read-write, so we can continue.
 
619
                 */
 
620
                if (!preen)
 
621
                        printf("\n***** FILE SYSTEM WAS MODIFIED *****\n");
 
622
-               if (flags & MNT_RDONLY) {               
 
623
+#if LINUX
 
624
+               // FIXME
 
625
+#else
 
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;
 
632
                        }
 
633
                }
 
634
+#endif
 
635
                if (!preen)
 
636
                        printf("\n***** REBOOT NOW *****\n");
 
637
                sync();
 
638
@@ -367,7 +389,7 @@ checkfilesys(char * filesys)
 
639
        }
 
640
 
 
641
        result = (result == 0) ? 0 : EEXIT;
 
642
-       
 
643
+
 
644
 ExitThisRoutine:
 
645
        if (lflag) {
 
646
            fcntl(fs_fd, F_THAW_FS, NULL);
 
647
@@ -401,16 +423,18 @@ setup( char *dev, int *blockDevice_fdPtr, int *canWritePtr )
 
648
        fswritefd = -1;
 
649
        *blockDevice_fdPtr = -1;
 
650
        *canWritePtr = 0;
 
651
-       
 
652
+
 
653
        if (stat(dev, &statb) < 0) {
 
654
                printf("Can't stat %s: %s\n", dev, strerror(errno));
 
655
                return (0);
 
656
        }
 
657
+#if !LINUX
 
658
        if ((statb.st_mode & S_IFMT) != S_IFCHR) {
 
659
                pfatal("%s is not a character device", dev);
 
660
                if (reply("CONTINUE") == 0)
 
661
                        return (0);
 
662
        }
 
663
+#endif
 
664
        if ((fsreadfd = open(dev, O_RDONLY)) < 0) {
 
665
                printf("Can't open %s: %s\n", dev, strerror(errno));
 
666
                return (0);
 
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 );
 
671
-       
 
672
+
 
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 )
 
677
                printf("\n");
 
678
 
 
679
        /* Get device block size to initialize cache */
 
680
+#if LINUX
 
681
+       devBlockSize = 512;
 
682
+#else
 
683
        if (ioctl(fsreadfd, DKIOCGETBLOCKSIZE, &devBlockSize) < 0) {
 
684
                pfatal ("Can't get device block size\n");
 
685
                return (0);
 
686
        }
 
687
+#endif
 
688
 
 
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 )
 
692
 
 
693
 static void getWriteAccess( char *dev, int *blockDevice_fdPtr, int *canWritePtr )
 
694
 {
 
695
+#if !LINUX
 
696
        int                                     i;
 
697
        int                                     myMountsCount;
 
698
+#endif
 
699
        void *                          myPtr;
 
700
        char *                          myCharPtr;
 
701
+#if !LINUX
 
702
        struct statfs *         myBufPtr;
 
703
+#endif
 
704
        void *                          myNamePtr;
 
705
 
 
706
        myPtr = NULL;
 
707
@@ -490,6 +522,9 @@ static void getWriteAccess( char *dev, int *blockDevice_fdPtr, int *canWritePtr
 
708
        }
 
709
        
 
710
        // get count of mounts then get the info for each 
 
711
+#if LINUX
 
712
+       // FIXME
 
713
+#else
 
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
 
718
                }
 
719
                myBufPtr++;
 
720
        }
 
721
-       *canWritePtr = 1;  // single user will get us here, f_mntfromname is not /dev/diskXXXX 
 
722
-       
 
723
+#endif
 
724
+       *canWritePtr = 1;  // single user will get us here, f_mntfromname is not /dev/diskXXXX
 
725
 ExitThisRoutine:
 
726
        if ( myPtr != NULL )
 
727
                free( myPtr );
 
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);
 
734
                        return (origname);
 
735
                }
 
736
+#if !LINUX
 
737
                if ((stchar.st_mode & S_IFMT) == S_IFCHR) {
 
738
                        return (raw);
 
739
                } else {
 
740
                        printf("%s is not a character device\n", raw);
 
741
                        return (origname);
 
742
                }
 
743
+#endif
 
744
        } else if ((stblock.st_mode & S_IFMT) == S_IFCHR && !retried) {
 
745
                newname = unrawname(newname);
 
746
                retried++;
 
747
@@ -214,7 +216,11 @@ rawname(char *name)
 
748
        *dp = 0;
 
749
        (void)strcpy(rawbuf, name);
 
750
        *dp = '/';
 
751
-       (void)strcat(rawbuf, "/r");
 
752
+#if LINUX
 
753
+       (void)strcat(rawbuf, "/");
 
754
+#else
 
755
+       (void)strcat(rawbuf,"/r");
 
756
+#endif
 
757
        (void)strcat(rawbuf, &dp[1]);
 
758
 
 
759
        return (rawbuf);
 
760
diff --git a/include/missing.h b/include/missing.h
 
761
new file mode 100644
 
762
index 0000000..0a859c4
 
763
--- /dev/null
 
764
+++ b/include/missing.h
 
765
@@ -0,0 +1,115 @@
 
766
+#ifndef _MISSING_H_
 
767
+#define _MISSING_H_
 
768
+
 
769
+#include <endian.h>
 
770
+#include <byteswap.h>
 
771
+#include <errno.h>
 
772
+#include <stdint.h>
 
773
+#include <string.h>
 
774
+#include <bsd/string.h>
 
775
+
 
776
+#define MAXBSIZE               (256 * 4096)
 
777
+
 
778
+#ifndef true
 
779
+#define true                   1
 
780
+#endif
 
781
+#ifndef false
 
782
+#define false                  0
 
783
+#endif
 
784
+
 
785
+/* Mac types */
 
786
+
 
787
+/* 8 Bit */
 
788
+#ifndef UInt8
 
789
+#define UInt8                  uint8_t
 
790
+#endif
 
791
+#ifndef u_int8_t
 
792
+#define u_int8_t               UInt8
 
793
+#endif
 
794
+#ifndef SInt8
 
795
+#define SInt8                  int8_t
 
796
+#endif
 
797
+
 
798
+/* 16 Bit */
 
799
+#ifndef UInt16
 
800
+#define UInt16                 uint16_t
 
801
+#endif
 
802
+#ifndef u_int16_t
 
803
+#define u_int16_t              UInt16
 
804
+#endif
 
805
+#ifndef SInt16
 
806
+#define SInt16                 int16_t
 
807
+#endif
 
808
+
 
809
+/* 32 Bit */
 
810
+#ifndef UInt32
 
811
+#define UInt32                 uint32_t
 
812
+#endif
 
813
+#ifndef u_int32_t
 
814
+#define u_int32_t              UInt32
 
815
+#endif
 
816
+#ifndef SInt32
 
817
+#define SInt32                 int32_t
 
818
+#endif
 
819
+
 
820
+/* 64 Bit */
 
821
+#ifndef UInt64
 
822
+#define UInt64                 uint64_t
 
823
+#endif
 
824
+#ifndef u_int64_t
 
825
+#define u_int64_t              UInt64
 
826
+#endif
 
827
+#ifndef SInt64
 
828
+#define SInt64                 int64_t
 
829
+#endif
 
830
+
 
831
+#define UniChar                        u_int16_t
 
832
+#define Boolean                        u_int8_t
 
833
+
 
834
+#define UF_NODUMP      0x00000001
 
835
+
 
836
+/* syslimits.h */
 
837
+#define NAME_MAX       255
 
838
+
 
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)
 
847
+
 
848
+#if __BYTE_ORDER == __LITTLE_ENDIAN
 
849
+/* Big Endian Swaps */
 
850
+#ifndef be16_to_cpu
 
851
+#define be16_to_cpu(x) bswap_16(x)
 
852
+#endif
 
853
+#ifndef be32_to_cpu
 
854
+#define be32_to_cpu(x) bswap_32(x)
 
855
+#endif
 
856
+#ifndef be64_to_cpu
 
857
+#define be64_to_cpu(x) bswap_64(x)
 
858
+#endif
 
859
+#ifndef cpu_to_be64
 
860
+#define cpu_to_be64(x) bswap_64(x)
 
861
+#endif
 
862
+#elif __BYTE_ORDER == __BIG_ENDIAN
 
863
+/* Big endian doesn't swap */
 
864
+#ifndef be16_to_cpu
 
865
+#define be16_to_cpu(x) (x)
 
866
+#endif
 
867
+#ifndef be32_to_cpu
 
868
+#define be32_to_cpu(x) (x)
 
869
+#endif
 
870
+#ifndef be64_to_cpu
 
871
+#define be64_to_cpu(x) (x)
 
872
+#endif
 
873
+#ifndef cpu_to_be64
 
874
+#define cpu_to_be64(x)         (x)
 
875
+#endif
 
876
+#endif
 
877
+
 
878
+#define KAUTH_FILESEC_XATTR "com.apple.system.Security"
 
879
+
 
880
+#endif
 
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
 
885
@@ -30,7 +30,12 @@
 
886
 #include <sys/types.h>
 
887
 #include <sys/stat.h>
 
888
 
 
889
+#if LINUX
 
890
+#include "missing.h"
 
891
+#else
 
892
 #include <architecture/byte_order.h>
 
893
+#endif
 
894
+
 
895
 #include <hfs/hfs_format.h>
 
896
 
 
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
 
902
@@ -29,7 +29,12 @@
 
903
  * volume format.
 
904
  */
 
905
 #include <hfs/hfs_format.h>
 
906
+#if LINUX
 
907
+#include <endian.h>
 
908
+#include <byteswap.h>
 
909
+#else
 
910
 #include <architecture/byte_order.h>
 
911
+#endif
 
912
 
 
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
 
919
@@ -31,10 +31,16 @@
 
920
 #include <sys/param.h>
 
921
 #include <sys/types.h>
 
922
 #include <sys/time.h>
 
923
+#if LINUX
 
924
+#include <time.h>
 
925
+#include "missing.h"
 
926
+#endif
 
927
 #include <sys/errno.h>
 
928
 #include <sys/stat.h>
 
929
 #include <sys/sysctl.h>
 
930
+#if !LINUX
 
931
 #include <sys/vmmeter.h>
 
932
+#endif
 
933
 
 
934
 #include <err.h>
 
935
 #include <errno.h>
 
936
@@ -47,13 +53,14 @@
 
937
 
 
938
 #include <openssl/sha.h>
 
939
 
 
940
+#if !LINUX
 
941
 #include <architecture/byte_order.h>
 
942
 
 
943
 #include <CoreFoundation/CFString.h>
 
944
 #include <CoreFoundation/CFStringEncodingExt.h>
 
945
 
 
946
 extern Boolean _CFStringGetFileSystemRepresentation(CFStringRef string, UInt8 *buffer, CFIndex maxBufLen);
 
947
-
 
948
+#endif
 
949
 
 
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));
 
955
 
 
956
+#if !LINUX
 
957
 static UInt32 GetDefaultEncoding();
 
958
+#endif
 
959
 
 
960
 static UInt32 UTCToLocal __P((UInt32 utcTime));
 
961
 
 
962
@@ -158,11 +167,14 @@ void SETOFFSET (void *buffer, UInt16 btNodeSize, SInt16 recOffset, SInt16 vecOff
 
963
 
 
964
 #define ROUNDUP(x, u)  (((x) % (u) == 0) ? (x) : ((x)/(u) + 1) * (u))
 
965
 
 
966
-#define ENCODING_TO_BIT(e)                               \
 
967
+#if LINUX
 
968
+#define ENCODING_TO_BIT(e)       (e)
 
969
+#else
 
970
+#define ENCODING_TO_BIT(e)
 
971
           ((e) < 48 ? (e) :                              \
 
972
           ((e) == kCFStringEncodingMacUkrainian ? 48 :   \
 
973
           ((e) == kCFStringEncodingMacFarsi ? 49 : 0)))
 
974
-
 
975
+#endif
 
976
 /*
 
977
  * make_hfs
 
978
  *     
 
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.
 
982
         */
 
983
+#if !LINUX
 
984
        {
 
985
                UniChar unibuf[kHFSMaxVolumeNameChars];
 
986
                CFStringRef cfstr;
 
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';
 
990
        }
 
991
+#endif
 
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]);
 
995
+
 
996
        mdbp->drFndrInfo[4] = SET_HFS_TEXT_ENCODING(defaults->encodingHint);
 
997
 
 
998
        mdbp->drWrCnt = kWriteSeqNum;
 
999
@@ -1100,9 +1117,11 @@ InitCatalogRoot_HFSPlus(const hfsparams_t *dp, const HFSPlusVolumeHeader *header
 
1000
        UInt16                                  nodeSize;
 
1001
        SInt16                                  offset;
 
1002
        UInt32                                  unicodeBytes;
 
1003
+#if !LINUX
 
1004
        UInt8 canonicalName[256];
 
1005
        CFStringRef cfstr;
 
1006
        Boolean cfOK;
 
1007
+#endif
 
1008
        int index = 0;
 
1009
 
 
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...
 
1013
         */
 
1014
        ckp = (HFSPlusCatalogKey *)((UInt8 *)buffer + offset);
 
1015
-       
 
1016
+#if LINUX
 
1017
+       ConvertUTF8toUnicode(dp->volumeName, sizeof(ckp->nodeName.unicode), ckp->nodeName.unicode, &ckp->nodeName.length);
 
1018
+#else
 
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);
 
1024
        }
 
1025
        CFRelease(cfstr);
 
1026
+#endif
 
1027
        ckp->nodeName.length = SWAP_BE16 (ckp->nodeName.length);
 
1028
 
 
1029
        unicodeBytes = sizeof(UniChar) * SWAP_BE16 (ckp->nodeName.length);
 
1030
@@ -1821,15 +1843,15 @@ WriteBuffer(const DriveInfo *driveInfo, UInt64 startingSector, UInt32 byteCount,
 
1031
        off_t sector;
 
1032
 
 
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);
 
1036
 
 
1037
        sector = driveInfo->sectorOffset + startingSector;
 
1038
 
 
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);
 
1042
 
 
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);
 
1046
 }
 
1047
 
 
1048
 
 
1049
@@ -1913,7 +1935,7 @@ DivideAndRoundUp(UInt32 numerator, UInt32 denominator)
 
1050
        return quotient;
 
1051
 }
 
1052
 
 
1053
-
 
1054
+#if !LINUX
 
1055
 #define __kCFUserEncodingFileName ("/.CFUserTextEncoding")
 
1056
 
 
1057
 static UInt32
 
1058
@@ -1939,7 +1961,7 @@ GetDefaultEncoding()
 
1059
     }
 
1060
     return 0;
 
1061
 }
 
1062
-
 
1063
+#endif
 
1064
 
 
1065
 static int
 
1066
 ConvertUTF8toUnicode(const UInt8* source, UInt32 bufsize, UniChar* unibuf,
 
1067
@@ -2006,6 +2028,9 @@ ConvertUTF8toUnicode(const UInt8* source, UInt32 bufsize, UniChar* unibuf,
 
1068
 static int
 
1069
 getencodinghint(unsigned char *name)
 
1070
 {
 
1071
+#if LINUX
 
1072
+       return(0);
 
1073
+#else
 
1074
         int mib[3];
 
1075
         size_t buflen = sizeof(int);
 
1076
         struct vfsconf vfc;
 
1077
@@ -2023,7 +2048,8 @@ getencodinghint(unsigned char *name)
 
1078
        return (hint);
 
1079
 error:
 
1080
        hint = GetDefaultEncoding();
 
1081
-       return (hint);
 
1082
+       return (0);
 
1083
+#endif
 
1084
 }
 
1085
 
 
1086
 
 
1087
@@ -2034,12 +2060,14 @@ void GenerateVolumeUUID(VolumeUUID *newVolumeID) {
 
1088
        unsigned char digest[20];
 
1089
        time_t now;
 
1090
        clock_t uptime;
 
1091
-       int mib[2];
 
1092
-       int sysdata;
 
1093
-       char sysctlstring[128];
 
1094
        size_t datalen;
 
1095
        double sysloadavg[3];
 
1096
+#if !LINUX
 
1097
+       int sysdata;
 
1098
+       int mib[2];
 
1099
+       char sysctlstring[128];
 
1100
        struct vmtotal sysvmtotal;
 
1101
+#endif
 
1102
        
 
1103
        do {
 
1104
                /* Initialize the SHA-1 context for processing: */
 
1105
@@ -2052,52 +2080,58 @@ void GenerateVolumeUUID(VolumeUUID *newVolumeID) {
 
1106
                SHA1_Update(&context, &uptime, sizeof(uptime));
 
1107
                
 
1108
                /* The kernel's boot time: */
 
1109
+#if !LINUX
 
1110
                mib[0] = CTL_KERN;
 
1111
                mib[1] = KERN_BOOTTIME;
 
1112
                datalen = sizeof(sysdata);
 
1113
                sysctl(mib, 2, &sysdata, &datalen, NULL, 0);
 
1114
                SHA1_Update(&context, &sysdata, datalen);
 
1115
-               
 
1116
+#endif
 
1117
                /* The system's host id: */
 
1118
+#if !LINUX
 
1119
                mib[0] = CTL_KERN;
 
1120
                mib[1] = KERN_HOSTID;
 
1121
                datalen = sizeof(sysdata);
 
1122
                sysctl(mib, 2, &sysdata, &datalen, NULL, 0);
 
1123
                SHA1_Update(&context, &sysdata, datalen);
 
1124
-
 
1125
+#endif
 
1126
                /* The system's host name: */
 
1127
+#if !LINUX
 
1128
                mib[0] = CTL_KERN;
 
1129
                mib[1] = KERN_HOSTNAME;
 
1130
                datalen = sizeof(sysctlstring);
 
1131
                sysctl(mib, 2, sysctlstring, &datalen, NULL, 0);
 
1132
                SHA1_Update(&context, sysctlstring, datalen);
 
1133
-
 
1134
+#endif
 
1135
                /* The running kernel's OS release string: */
 
1136
+#if !LINUX
 
1137
                mib[0] = CTL_KERN;
 
1138
                mib[1] = KERN_OSRELEASE;
 
1139
                datalen = sizeof(sysctlstring);
 
1140
                sysctl(mib, 2, sysctlstring, &datalen, NULL, 0);
 
1141
                SHA1_Update(&context, sysctlstring, datalen);
 
1142
-
 
1143
+#endif
 
1144
                /* The running kernel's version string: */
 
1145
+#if !LINUX
 
1146
                mib[0] = CTL_KERN;
 
1147
                mib[1] = KERN_VERSION;
 
1148
                datalen = sizeof(sysctlstring);
 
1149
                sysctl(mib, 2, sysctlstring, &datalen, NULL, 0);
 
1150
                SHA1_Update(&context, sysctlstring, datalen);
 
1151
-
 
1152
+#endif
 
1153
                /* The system's load average: */
 
1154
                datalen = sizeof(sysloadavg);
 
1155
                getloadavg(sysloadavg, 3);
 
1156
                SHA1_Update(&context, &sysloadavg, datalen);
 
1157
 
 
1158
                /* The system's VM statistics: */
 
1159
+#if !LINUX
 
1160
                mib[0] = CTL_VM;
 
1161
                mib[1] = VM_METER;
 
1162
                datalen = sizeof(sysvmtotal);
 
1163
                sysctl(mib, 2, &sysvmtotal, &datalen, NULL, 0);
 
1164
                SHA1_Update(&context, &sysvmtotal, datalen);
 
1165
-
 
1166
+#endif
 
1167
                /* The current GMT (26 ASCII characters): */
 
1168
                time(&now);
 
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
 
1174
@@ -38,8 +38,13 @@
 
1175
 #include <sys/mount.h>
 
1176
 #include <sys/param.h>
 
1177
 #include <sys/stat.h>
 
1178
+#if LINUX
 
1179
+#include <time.h>
 
1180
+#endif
 
1181
 
 
1182
+#if !LINUX
 
1183
 #include <IOKit/storage/IOMediaBSDClient.h>
 
1184
+#endif
 
1185
 
 
1186
 #include <hfs/hfs_format.h>
 
1187
 #include "newfs_hfs.h"
 
1188
@@ -73,7 +78,9 @@ static void usage __P((void));
 
1189
 
 
1190
 char   *progname;
 
1191
 char   gVolumeName[kHFSPlusMaxFileNameChars + 1] = {kDefaultVolumeNameStr};
 
1192
+#if !LINUX
 
1193
 char   rawdevice[MAXPATHLEN];
 
1194
+#endif
 
1195
 char   blkdevice[MAXPATHLEN];
 
1196
 UInt32 gBlockSize = 0;
 
1197
 UInt32 gNextCNID = kHFSFirstUserCatalogNodeID;
 
1198
@@ -158,8 +165,10 @@ main(argc, argv)
 
1199
        extern int optind;
 
1200
        int ch;
 
1201
        int forceHFS;
 
1202
+#if !LINUX
 
1203
        char *cp, *special;
 
1204
        struct statfs *mp;
 
1205
+#endif
 
1206
        int n;
 
1207
        
 
1208
        if ((progname = strrchr(*argv, '/')))
 
1209
@@ -260,16 +269,19 @@ main(argc, argv)
 
1210
                        usage();
 
1211
                }
 
1212
 
 
1213
-       argc -= optind;
 
1214
-       argv += optind;
 
1215
+               argc -= optind;
 
1216
+               argv += optind;
 
1217
 
 
1218
-       if (gPartitionSize != 0) {
 
1219
-               if (argc != 0)
 
1220
-                       usage();
 
1221
-       } else {
 
1222
-               if (argc != 1)
 
1223
-                       usage();
 
1224
+               if (gPartitionSize != 0) {
 
1225
+                       if (argc != 0)
 
1226
+                               usage();
 
1227
+               } else {
 
1228
+                       if (argc != 1)
 
1229
+                               usage();
 
1230
 
 
1231
+#if LINUX
 
1232
+               (void) sprintf(blkdevice, "%s", argv[0]);
 
1233
+#else
 
1234
                special = argv[0];
 
1235
                cp = strrchr(special, '/');
 
1236
                if (cp != 0)
 
1237
@@ -278,6 +290,7 @@ main(argc, argv)
 
1238
                        special++;
 
1239
                (void) sprintf(rawdevice, "%sr%s", _PATH_DEV, special);
 
1240
                (void) sprintf(blkdevice, "%s%s", _PATH_DEV, special);
 
1241
+#endif
 
1242
        }
 
1243
 
 
1244
        if (forceHFS && gJournaled) {
 
1245
@@ -301,6 +314,9 @@ main(argc, argv)
 
1246
                /*
 
1247
                 * Check if target device is aready mounted
 
1248
                 */
 
1249
+#if LINUX
 
1250
+       // FIXME
 
1251
+#else
 
1252
                n = getmntinfo(&mp, MNT_NOWAIT);
 
1253
                if (n == 0)
 
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);
 
1257
                        ++mp;
 
1258
                }
 
1259
+#endif
 
1260
        }
 
1261
 
 
1262
-       if (hfs_newfs(rawdevice, forceHFS, true) < 0) {
 
1263
+       if (hfs_newfs(blkdevice, forceHFS, true) < 0) {
 
1264
+#if LINUX
 
1265
+               err(1, NULL);
 
1266
+#else
 
1267
                /* On ENXIO error use the block device (to get de-blocking) */
 
1268
                if (errno == ENXIO) {
 
1269
                        if (hfs_newfs(blkdevice, forceHFS, false) < 0)
 
1270
                                err(1, NULL);
 
1271
                } else
 
1272
                        err(1, NULL);
 
1273
+#endif
 
1274
        }
 
1275
 
 
1276
        exit(0);
 
1277
@@ -506,7 +527,9 @@ hfs_newfs(char *device, int forceHFS, int isRaw)
 
1278
        int fso = 0;
 
1279
        int retval = 0;
 
1280
        hfsparams_t defaults = {0};
 
1281
+#if !LINUX
 
1282
        u_int64_t maxSectorsPerIO;
 
1283
+#endif
 
1284
 
 
1285
        if (gPartitionSize) {
 
1286
                        dip.sectorSize = kBytesPerSector;
 
1287
@@ -526,6 +549,34 @@ hfs_newfs(char *device, int forceHFS, int isRaw)
 
1288
        
 
1289
                if (fstat( fso, &stbuf) < 0)
 
1290
                        fatal("%s: %s", device, strerror(errno));
 
1291
+#if LINUX
 
1292
+               dip.sectorSize = 512;
 
1293
+               dip.sectorsPerIO = 256;
 
1294
+
 
1295
+#      ifndef  BLKGETSIZE
 
1296
+#      define  BLKGETSIZE              _IO(0x12,96)
 
1297
+#      endif
 
1298
+
 
1299
+#      ifndef  BLKGETSIZE64
 
1300
+#      define BLKGETSIZE64             _IOR(0x12,114,size_t)
 
1301
+#      endif
 
1302
+
 
1303
+               if (S_ISREG(stbuf.st_mode)) {
 
1304
+                       dip.totalSectors = stbuf.st_size / 512;
 
1305
+               }
 
1306
+               else if (S_ISBLK(stbuf.st_mode)) {
 
1307
+                       unsigned long size;
 
1308
+                       u_int64_t size64;
 
1309
+                       if (!ioctl(fso, BLKGETSIZE64, &size64))
 
1310
+                               dip.totalSectors = size64 / 512;
 
1311
+                       else if (!ioctl(fso, BLKGETSIZE, &size))
 
1312
+                               dip.totalSectors = size;
 
1313
+                       else
 
1314
+                               fatal("%s: %s", device, strerror(errno));
 
1315
+               }
 
1316
+               else
 
1317
+                       fatal("%s: is not a block device", device);
 
1318
+#else
 
1319
        
 
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 */
 
1324
                else
 
1325
                        dip.sectorsPerIO = MIN(maxSectorsPerIO, (1024 * 1024) / dip.sectorSize);
 
1326
+#endif
 
1327
+
 
1328
                /*
 
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).
 
1332
                 */       
 
1333
+#if !LINUX
 
1334
                if (dip.sectorSize != kBytesPerSector) {
 
1335
                        if (isRaw) {
 
1336
                                close(fso);
 
1337
@@ -556,7 +610,9 @@ hfs_newfs(char *device, int forceHFS, int isRaw)
 
1338
                                dip.sectorSize = kBytesPerSector;
 
1339
                        }
 
1340
                }
 
1341
+#endif
 
1342
        }
 
1343
+
 
1344
        dip.sectorOffset = 0;
 
1345
        time(&createtime);
 
1346
 
 
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
 
1351
@@ -19,8 +19,12 @@
 
1352
  * 
 
1353
  * @APPLE_LICENSE_HEADER_END@
 
1354
  */
 
1355
 
1356
+
 
1357
+#if LINUX
 
1358
+#include "missing.h"
 
1359
+#else
 
1360
 #include <CoreFoundation/CFBase.h>
 
1361
+#endif
 
1362
 
 
1363
 /*
 
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' */
 
1373
 
 
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
 
1382
 
 
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' */
 
1390
 
 
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' */
 
1398
 
 
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' */
 
1406
 
 
1407
 
 
1408