0002-Add-exclude-Darwin-specific-code.patch (36824B)
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,114 @@ 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 + 775 +#define MAXBSIZE (256 * 4096) 776 + 777 +#ifndef true 778 +#define true 1 779 +#endif 780 +#ifndef false 781 +#define false 0 782 +#endif 783 + 784 +/* Mac types */ 785 + 786 +/* 8 Bit */ 787 +#ifndef UInt8 788 +#define UInt8 uint8_t 789 +#endif 790 +#ifndef u_int8_t 791 +#define u_int8_t UInt8 792 +#endif 793 +#ifndef SInt8 794 +#define SInt8 int8_t 795 +#endif 796 + 797 +/* 16 Bit */ 798 +#ifndef UInt16 799 +#define UInt16 uint16_t 800 +#endif 801 +#ifndef u_int16_t 802 +#define u_int16_t UInt16 803 +#endif 804 +#ifndef SInt16 805 +#define SInt16 int16_t 806 +#endif 807 + 808 +/* 32 Bit */ 809 +#ifndef UInt32 810 +#define UInt32 uint32_t 811 +#endif 812 +#ifndef u_int32_t 813 +#define u_int32_t UInt32 814 +#endif 815 +#ifndef SInt32 816 +#define SInt32 int32_t 817 +#endif 818 + 819 +/* 64 Bit */ 820 +#ifndef UInt64 821 +#define UInt64 uint64_t 822 +#endif 823 +#ifndef u_int64_t 824 +#define u_int64_t UInt64 825 +#endif 826 +#ifndef SInt64 827 +#define SInt64 int64_t 828 +#endif 829 + 830 +#define UniChar u_int16_t 831 +#define Boolean u_int8_t 832 + 833 +#define UF_NODUMP 0x00000001 834 + 835 +/* syslimits.h */ 836 +#define NAME_MAX 255 837 + 838 +/* Byteswap stuff */ 839 +#define NXSwapHostLongToBig(x) cpu_to_be64(x) 840 +#define NXSwapBigShortToHost(x) be16_to_cpu(x) 841 +#define OSSwapBigToHostInt16(x) be16_to_cpu(x) 842 +#define NXSwapBigLongToHost(x) be32_to_cpu(x) 843 +#define OSSwapBigToHostInt32(x) be32_to_cpu(x) 844 +#define NXSwapBigLongLongToHost(x) be64_to_cpu(x) 845 +#define OSSwapBigToHostInt64(x) be64_to_cpu(x) 846 + 847 +#if __BYTE_ORDER == __LITTLE_ENDIAN 848 +/* Big Endian Swaps */ 849 +#ifndef be16_to_cpu 850 +#define be16_to_cpu(x) bswap_16(x) 851 +#endif 852 +#ifndef be32_to_cpu 853 +#define be32_to_cpu(x) bswap_32(x) 854 +#endif 855 +#ifndef be64_to_cpu 856 +#define be64_to_cpu(x) bswap_64(x) 857 +#endif 858 +#ifndef cpu_to_be64 859 +#define cpu_to_be64(x) bswap_64(x) 860 +#endif 861 +#elif __BYTE_ORDER == __BIG_ENDIAN 862 +/* Big endian doesn't swap */ 863 +#ifndef be16_to_cpu 864 +#define be16_to_cpu(x) (x) 865 +#endif 866 +#ifndef be32_to_cpu 867 +#define be32_to_cpu(x) (x) 868 +#endif 869 +#ifndef be64_to_cpu 870 +#define be64_to_cpu(x) (x) 871 +#endif 872 +#ifndef cpu_to_be64 873 +#define cpu_to_be64(x) (x) 874 +#endif 875 +#endif 876 + 877 +#define KAUTH_FILESEC_XATTR "com.apple.system.Security" 878 + 879 +#endif 880 diff --git a/newfs_hfs.tproj/hfs_endian.c b/newfs_hfs.tproj/hfs_endian.c 881 index 117b7f8..fdf7353 100644 882 --- a/newfs_hfs.tproj/hfs_endian.c 883 +++ b/newfs_hfs.tproj/hfs_endian.c 884 @@ -30,7 +30,12 @@ 885 #include <sys/types.h> 886 #include <sys/stat.h> 887 888 +#if LINUX 889 +#include "missing.h" 890 +#else 891 #include <architecture/byte_order.h> 892 +#endif 893 + 894 #include <hfs/hfs_format.h> 895 896 #include "hfs_endian.h" 897 diff --git a/newfs_hfs.tproj/hfs_endian.h b/newfs_hfs.tproj/hfs_endian.h 898 index 8d9d01d..5c7ff57 100644 899 --- a/newfs_hfs.tproj/hfs_endian.h 900 +++ b/newfs_hfs.tproj/hfs_endian.h 901 @@ -29,7 +29,12 @@ 902 * volume format. 903 */ 904 #include <hfs/hfs_format.h> 905 +#if LINUX 906 +#include <endian.h> 907 +#include <byteswap.h> 908 +#else 909 #include <architecture/byte_order.h> 910 +#endif 911 912 /*********************/ 913 /* BIG ENDIAN Macros */ 914 diff --git a/newfs_hfs.tproj/makehfs.c b/newfs_hfs.tproj/makehfs.c 915 index 085222f..7609779 100644 916 --- a/newfs_hfs.tproj/makehfs.c 917 +++ b/newfs_hfs.tproj/makehfs.c 918 @@ -31,10 +31,16 @@ 919 #include <sys/param.h> 920 #include <sys/types.h> 921 #include <sys/time.h> 922 +#if LINUX 923 +#include <time.h> 924 +#include "missing.h" 925 +#endif 926 #include <sys/errno.h> 927 #include <sys/stat.h> 928 #include <sys/sysctl.h> 929 +#if !LINUX 930 #include <sys/vmmeter.h> 931 +#endif 932 933 #include <err.h> 934 #include <errno.h> 935 @@ -47,13 +53,14 @@ 936 937 #include <openssl/sha.h> 938 939 +#if !LINUX 940 #include <architecture/byte_order.h> 941 942 #include <CoreFoundation/CFString.h> 943 #include <CoreFoundation/CFStringEncodingExt.h> 944 945 extern Boolean _CFStringGetFileSystemRepresentation(CFStringRef string, UInt8 *buffer, CFIndex maxBufLen); 946 - 947 +#endif 948 949 #include <hfs/hfs_format.h> 950 #include <hfs/hfs_mount.h> 951 @@ -129,7 +136,9 @@ static UInt32 Largest __P((UInt32 a, UInt32 b, UInt32 c, UInt32 d )); 952 static void MarkBitInAllocationBuffer __P((HFSPlusVolumeHeader *header, 953 UInt32 allocationBlock, void* sectorBuffer, UInt32 *sector)); 954 955 +#if !LINUX 956 static UInt32 GetDefaultEncoding(); 957 +#endif 958 959 static UInt32 UTCToLocal __P((UInt32 utcTime)); 960 961 @@ -158,11 +167,14 @@ void SETOFFSET (void *buffer, UInt16 btNodeSize, SInt16 recOffset, SInt16 vecOff 962 963 #define ROUNDUP(x, u) (((x) % (u) == 0) ? (x) : ((x)/(u) + 1) * (u)) 964 965 -#define ENCODING_TO_BIT(e) \ 966 +#if LINUX 967 +#define ENCODING_TO_BIT(e) (e) 968 +#else 969 +#define ENCODING_TO_BIT(e) 970 ((e) < 48 ? (e) : \ 971 ((e) == kCFStringEncodingMacUkrainian ? 48 : \ 972 ((e) == kCFStringEncodingMacFarsi ? 49 : 0))) 973 - 974 +#endif 975 /* 976 * make_hfs 977 * 978 @@ -528,6 +540,7 @@ InitMDB(hfsparams_t *defaults, UInt32 driveBlocks, HFS_MDB *mdbp) 979 * Map UTF-8 input into a Mac encoding. 980 * On conversion errors "untitled" is used as a fallback. 981 */ 982 +#if !LINUX 983 { 984 UniChar unibuf[kHFSMaxVolumeNameChars]; 985 CFStringRef cfstr; 986 @@ -553,7 +566,11 @@ InitMDB(hfsparams_t *defaults, UInt32 driveBlocks, HFS_MDB *mdbp) 987 bcopy(&mdbp->drVN[1], defaults->volumeName, mdbp->drVN[0]); 988 defaults->volumeName[mdbp->drVN[0]] = '\0'; 989 } 990 +#endif 991 /* Save the encoding hint in the Finder Info (field 4). */ 992 + mdbp->drVN[0] = strlen(defaults->volumeName); 993 + bcopy(defaults->volumeName,&mdbp->drVN[1],mdbp->drVN[0]); 994 + 995 mdbp->drFndrInfo[4] = SET_HFS_TEXT_ENCODING(defaults->encodingHint); 996 997 mdbp->drWrCnt = kWriteSeqNum; 998 @@ -1100,9 +1117,11 @@ InitCatalogRoot_HFSPlus(const hfsparams_t *dp, const HFSPlusVolumeHeader *header 999 UInt16 nodeSize; 1000 SInt16 offset; 1001 UInt32 unicodeBytes; 1002 +#if !LINUX 1003 UInt8 canonicalName[256]; 1004 CFStringRef cfstr; 1005 Boolean cfOK; 1006 +#endif 1007 int index = 0; 1008 1009 nodeSize = dp->catalogNodeSize; 1010 @@ -1122,7 +1141,9 @@ InitCatalogRoot_HFSPlus(const hfsparams_t *dp, const HFSPlusVolumeHeader *header 1011 * First record is always the root directory... 1012 */ 1013 ckp = (HFSPlusCatalogKey *)((UInt8 *)buffer + offset); 1014 - 1015 +#if LINUX 1016 + ConvertUTF8toUnicode(dp->volumeName, sizeof(ckp->nodeName.unicode), ckp->nodeName.unicode, &ckp->nodeName.length); 1017 +#else 1018 /* Use CFString functions to get a HFSPlus Canonical name */ 1019 cfstr = CFStringCreateWithCString(kCFAllocatorDefault, (char *)dp->volumeName, kCFStringEncodingUTF8); 1020 cfOK = _CFStringGetFileSystemRepresentation(cfstr, canonicalName, sizeof(canonicalName)); 1021 @@ -1139,6 +1160,7 @@ InitCatalogRoot_HFSPlus(const hfsparams_t *dp, const HFSPlusVolumeHeader *header 1022 dp->volumeName, kDefaultVolumeNameStr); 1023 } 1024 CFRelease(cfstr); 1025 +#endif 1026 ckp->nodeName.length = SWAP_BE16 (ckp->nodeName.length); 1027 1028 unicodeBytes = sizeof(UniChar) * SWAP_BE16 (ckp->nodeName.length); 1029 @@ -1821,15 +1843,15 @@ WriteBuffer(const DriveInfo *driveInfo, UInt64 startingSector, UInt32 byteCount, 1030 off_t sector; 1031 1032 if ((byteCount % driveInfo->sectorSize) != 0) 1033 - errx(1, "WriteBuffer: byte count %ld is not sector size multiple", byteCount); 1034 + errx(1, "WriteBuffer: byte count %i is not sector size multiple", byteCount); 1035 1036 sector = driveInfo->sectorOffset + startingSector; 1037 1038 if (lseek(driveInfo->fd, sector * driveInfo->sectorSize, SEEK_SET) < 0) 1039 - err(1, "seek (sector %qd)", sector); 1040 + err(1, "seek (sector %lld)", sector); 1041 1042 if (write(driveInfo->fd, buffer, byteCount) != byteCount) 1043 - err(1, "write (sector %qd, %ld bytes)", sector, byteCount); 1044 + err(1, "write (sector %lld, %i bytes)", sector, byteCount); 1045 } 1046 1047 1048 @@ -1913,7 +1935,7 @@ DivideAndRoundUp(UInt32 numerator, UInt32 denominator) 1049 return quotient; 1050 } 1051 1052 - 1053 +#if !LINUX 1054 #define __kCFUserEncodingFileName ("/.CFUserTextEncoding") 1055 1056 static UInt32 1057 @@ -1939,7 +1961,7 @@ GetDefaultEncoding() 1058 } 1059 return 0; 1060 } 1061 - 1062 +#endif 1063 1064 static int 1065 ConvertUTF8toUnicode(const UInt8* source, UInt32 bufsize, UniChar* unibuf, 1066 @@ -2006,6 +2028,9 @@ ConvertUTF8toUnicode(const UInt8* source, UInt32 bufsize, UniChar* unibuf, 1067 static int 1068 getencodinghint(unsigned char *name) 1069 { 1070 +#if LINUX 1071 + return(0); 1072 +#else 1073 int mib[3]; 1074 size_t buflen = sizeof(int); 1075 struct vfsconf vfc; 1076 @@ -2023,7 +2048,8 @@ getencodinghint(unsigned char *name) 1077 return (hint); 1078 error: 1079 hint = GetDefaultEncoding(); 1080 - return (hint); 1081 + return (0); 1082 +#endif 1083 } 1084 1085 1086 @@ -2034,12 +2060,14 @@ void GenerateVolumeUUID(VolumeUUID *newVolumeID) { 1087 unsigned char digest[20]; 1088 time_t now; 1089 clock_t uptime; 1090 - int mib[2]; 1091 - int sysdata; 1092 - char sysctlstring[128]; 1093 size_t datalen; 1094 double sysloadavg[3]; 1095 +#if !LINUX 1096 + int sysdata; 1097 + int mib[2]; 1098 + char sysctlstring[128]; 1099 struct vmtotal sysvmtotal; 1100 +#endif 1101 1102 do { 1103 /* Initialize the SHA-1 context for processing: */ 1104 @@ -2052,52 +2080,58 @@ void GenerateVolumeUUID(VolumeUUID *newVolumeID) { 1105 SHA1_Update(&context, &uptime, sizeof(uptime)); 1106 1107 /* The kernel's boot time: */ 1108 +#if !LINUX 1109 mib[0] = CTL_KERN; 1110 mib[1] = KERN_BOOTTIME; 1111 datalen = sizeof(sysdata); 1112 sysctl(mib, 2, &sysdata, &datalen, NULL, 0); 1113 SHA1_Update(&context, &sysdata, datalen); 1114 - 1115 +#endif 1116 /* The system's host id: */ 1117 +#if !LINUX 1118 mib[0] = CTL_KERN; 1119 mib[1] = KERN_HOSTID; 1120 datalen = sizeof(sysdata); 1121 sysctl(mib, 2, &sysdata, &datalen, NULL, 0); 1122 SHA1_Update(&context, &sysdata, datalen); 1123 - 1124 +#endif 1125 /* The system's host name: */ 1126 +#if !LINUX 1127 mib[0] = CTL_KERN; 1128 mib[1] = KERN_HOSTNAME; 1129 datalen = sizeof(sysctlstring); 1130 sysctl(mib, 2, sysctlstring, &datalen, NULL, 0); 1131 SHA1_Update(&context, sysctlstring, datalen); 1132 - 1133 +#endif 1134 /* The running kernel's OS release string: */ 1135 +#if !LINUX 1136 mib[0] = CTL_KERN; 1137 mib[1] = KERN_OSRELEASE; 1138 datalen = sizeof(sysctlstring); 1139 sysctl(mib, 2, sysctlstring, &datalen, NULL, 0); 1140 SHA1_Update(&context, sysctlstring, datalen); 1141 - 1142 +#endif 1143 /* The running kernel's version string: */ 1144 +#if !LINUX 1145 mib[0] = CTL_KERN; 1146 mib[1] = KERN_VERSION; 1147 datalen = sizeof(sysctlstring); 1148 sysctl(mib, 2, sysctlstring, &datalen, NULL, 0); 1149 SHA1_Update(&context, sysctlstring, datalen); 1150 - 1151 +#endif 1152 /* The system's load average: */ 1153 datalen = sizeof(sysloadavg); 1154 getloadavg(sysloadavg, 3); 1155 SHA1_Update(&context, &sysloadavg, datalen); 1156 1157 /* The system's VM statistics: */ 1158 +#if !LINUX 1159 mib[0] = CTL_VM; 1160 mib[1] = VM_METER; 1161 datalen = sizeof(sysvmtotal); 1162 sysctl(mib, 2, &sysvmtotal, &datalen, NULL, 0); 1163 SHA1_Update(&context, &sysvmtotal, datalen); 1164 - 1165 +#endif 1166 /* The current GMT (26 ASCII characters): */ 1167 time(&now); 1168 strncpy(randomInputBuffer, asctime(gmtime(&now)), 26); /* "Mon Mar 27 13:46:26 2000" */ 1169 diff --git a/newfs_hfs.tproj/newfs_hfs.c b/newfs_hfs.tproj/newfs_hfs.c 1170 index c4176a9..bf2ed21 100644 1171 --- a/newfs_hfs.tproj/newfs_hfs.c 1172 +++ b/newfs_hfs.tproj/newfs_hfs.c 1173 @@ -38,8 +38,13 @@ 1174 #include <sys/mount.h> 1175 #include <sys/param.h> 1176 #include <sys/stat.h> 1177 +#if LINUX 1178 +#include <time.h> 1179 +#endif 1180 1181 +#if !LINUX 1182 #include <IOKit/storage/IOMediaBSDClient.h> 1183 +#endif 1184 1185 #include <hfs/hfs_format.h> 1186 #include "newfs_hfs.h" 1187 @@ -73,7 +78,9 @@ static void usage __P((void)); 1188 1189 char *progname; 1190 char gVolumeName[kHFSPlusMaxFileNameChars + 1] = {kDefaultVolumeNameStr}; 1191 +#if !LINUX 1192 char rawdevice[MAXPATHLEN]; 1193 +#endif 1194 char blkdevice[MAXPATHLEN]; 1195 UInt32 gBlockSize = 0; 1196 UInt32 gNextCNID = kHFSFirstUserCatalogNodeID; 1197 @@ -158,8 +165,10 @@ main(argc, argv) 1198 extern int optind; 1199 int ch; 1200 int forceHFS; 1201 +#if !LINUX 1202 char *cp, *special; 1203 struct statfs *mp; 1204 +#endif 1205 int n; 1206 1207 if ((progname = strrchr(*argv, '/'))) 1208 @@ -260,16 +269,19 @@ main(argc, argv) 1209 usage(); 1210 } 1211 1212 - argc -= optind; 1213 - argv += optind; 1214 + argc -= optind; 1215 + argv += optind; 1216 1217 - if (gPartitionSize != 0) { 1218 - if (argc != 0) 1219 - usage(); 1220 - } else { 1221 - if (argc != 1) 1222 - usage(); 1223 + if (gPartitionSize != 0) { 1224 + if (argc != 0) 1225 + usage(); 1226 + } else { 1227 + if (argc != 1) 1228 + usage(); 1229 1230 +#if LINUX 1231 + (void) sprintf(blkdevice, "%s", argv[0]); 1232 +#else 1233 special = argv[0]; 1234 cp = strrchr(special, '/'); 1235 if (cp != 0) 1236 @@ -278,6 +290,7 @@ main(argc, argv) 1237 special++; 1238 (void) sprintf(rawdevice, "%sr%s", _PATH_DEV, special); 1239 (void) sprintf(blkdevice, "%s%s", _PATH_DEV, special); 1240 +#endif 1241 } 1242 1243 if (forceHFS && gJournaled) { 1244 @@ -301,6 +314,9 @@ main(argc, argv) 1245 /* 1246 * Check if target device is aready mounted 1247 */ 1248 +#if LINUX 1249 + // FIXME 1250 +#else 1251 n = getmntinfo(&mp, MNT_NOWAIT); 1252 if (n == 0) 1253 fatal("%s: getmntinfo: %s", blkdevice, strerror(errno)); 1254 @@ -310,15 +326,20 @@ main(argc, argv) 1255 fatal("%s is mounted on %s", blkdevice, mp->f_mntonname); 1256 ++mp; 1257 } 1258 +#endif 1259 } 1260 1261 - if (hfs_newfs(rawdevice, forceHFS, true) < 0) { 1262 + if (hfs_newfs(blkdevice, forceHFS, true) < 0) { 1263 +#if LINUX 1264 + err(1, NULL); 1265 +#else 1266 /* On ENXIO error use the block device (to get de-blocking) */ 1267 if (errno == ENXIO) { 1268 if (hfs_newfs(blkdevice, forceHFS, false) < 0) 1269 err(1, NULL); 1270 } else 1271 err(1, NULL); 1272 +#endif 1273 } 1274 1275 exit(0); 1276 @@ -506,7 +527,9 @@ hfs_newfs(char *device, int forceHFS, int isRaw) 1277 int fso = 0; 1278 int retval = 0; 1279 hfsparams_t defaults = {0}; 1280 +#if !LINUX 1281 u_int64_t maxSectorsPerIO; 1282 +#endif 1283 1284 if (gPartitionSize) { 1285 dip.sectorSize = kBytesPerSector; 1286 @@ -526,6 +549,34 @@ hfs_newfs(char *device, int forceHFS, int isRaw) 1287 1288 if (fstat( fso, &stbuf) < 0) 1289 fatal("%s: %s", device, strerror(errno)); 1290 +#if LINUX 1291 + dip.sectorSize = 512; 1292 + dip.sectorsPerIO = 256; 1293 + 1294 +# ifndef BLKGETSIZE 1295 +# define BLKGETSIZE _IO(0x12,96) 1296 +# endif 1297 + 1298 +# ifndef BLKGETSIZE64 1299 +# define BLKGETSIZE64 _IOR(0x12,114,size_t) 1300 +# endif 1301 + 1302 + if (S_ISREG(stbuf.st_mode)) { 1303 + dip.totalSectors = stbuf.st_size / 512; 1304 + } 1305 + else if (S_ISBLK(stbuf.st_mode)) { 1306 + unsigned long size; 1307 + u_int64_t size64; 1308 + if (!ioctl(fso, BLKGETSIZE64, &size64)) 1309 + dip.totalSectors = size64 / 512; 1310 + else if (!ioctl(fso, BLKGETSIZE, &size)) 1311 + dip.totalSectors = size; 1312 + else 1313 + fatal("%s: %s", device, strerror(errno)); 1314 + } 1315 + else 1316 + fatal("%s: is not a block device", device); 1317 +#else 1318 1319 if (ioctl(fso, DKIOCGETBLOCKCOUNT, &dip.totalSectors) < 0) 1320 fatal("%s: %s", device, strerror(errno)); 1321 @@ -537,11 +588,14 @@ hfs_newfs(char *device, int forceHFS, int isRaw) 1322 dip.sectorsPerIO = (128 * 1024) / dip.sectorSize; /* use 128K as default */ 1323 else 1324 dip.sectorsPerIO = MIN(maxSectorsPerIO, (1024 * 1024) / dip.sectorSize); 1325 +#endif 1326 + 1327 /* 1328 * The make_hfs code currentlydoes 512 byte sized I/O. 1329 * If the sector size is bigger than 512, start over 1330 * using the block device (to get de-blocking). 1331 */ 1332 +#if !LINUX 1333 if (dip.sectorSize != kBytesPerSector) { 1334 if (isRaw) { 1335 close(fso); 1336 @@ -556,7 +610,9 @@ hfs_newfs(char *device, int forceHFS, int isRaw) 1337 dip.sectorSize = kBytesPerSector; 1338 } 1339 } 1340 +#endif 1341 } 1342 + 1343 dip.sectorOffset = 0; 1344 time(&createtime); 1345 1346 diff --git a/newfs_hfs.tproj/newfs_hfs.h b/newfs_hfs.tproj/newfs_hfs.h 1347 index 968ff10..5680a34 100644 1348 --- a/newfs_hfs.tproj/newfs_hfs.h 1349 +++ b/newfs_hfs.tproj/newfs_hfs.h 1350 @@ -19,8 +19,12 @@ 1351 * 1352 * @APPLE_LICENSE_HEADER_END@ 1353 */ 1354 - 1355 + 1356 +#if LINUX 1357 +#include "missing.h" 1358 +#else 1359 #include <CoreFoundation/CFBase.h> 1360 +#endif 1361 1362 /* 1363 * Mac OS Finder flags 1364 @@ -122,33 +126,33 @@ enum { 1365 #define kDTDF_FileID 16 1366 #define kDTDF_Name "Desktop DF" 1367 #define kDTDF_Chars 10 1368 -#define kDTDF_Type 'DTFL' 1369 -#define kDTDF_Creator 'DMGR' 1370 +#define kDTDF_Type 0x4454464C /* 'DTFL' */ 1371 +#define kDTDF_Creator 0x444D4752 /* 'DMGR' */ 1372 1373 #define kDTDB_FileID 17 1374 #define kDTDB_Name "Desktop DB" 1375 #define kDTDB_Chars 10 1376 -#define kDTDB_Type 'BTFL' 1377 -#define kDTDB_Creator 'DMGR' 1378 +#define kDTDB_Type 0x4254464C /* 'BTFL' */ 1379 +#define kDTDB_Creator 0x444D4752 /* 'DMGR' */ 1380 #define kDTDB_Size 1024 1381 1382 #define kReadMe_FileID 18 1383 #define kReadMe_Name "ReadMe" 1384 #define kReadMe_Chars 6 1385 -#define kReadMe_Type 'ttro' 1386 -#define kReadMe_Creator 'ttxt' 1387 +#define kReadMe_Type 0x7474726F /* 'ttro' */ 1388 +#define kReadMe_Creator 0x74747974 /* 'ttxt' */ 1389 1390 #define kFinder_FileID 19 1391 #define kFinder_Name "Finder" 1392 #define kFinder_Chars 6 1393 -#define kFinder_Type 'FNDR' 1394 -#define kFinder_Creator 'MACS' 1395 +#define kFinder_Type 0x464E4452 /* 'FNDR' */ 1396 +#define kFinder_Creator 0x4D414353 /* 'MACS' */ 1397 1398 #define kSystem_FileID 20 1399 #define kSystem_Name "System" 1400 #define kSystem_Chars 6 1401 -#define kSystem_Type 'zsys' 1402 -#define kSystem_Creator 'MACS' 1403 +#define kSystem_Type 0x7A737973 /* 'zsys' */ 1404 +#define kSystem_Creator 0x4D414353 /* 'MACS' */ 1405 1406 1407