]>
git.saurik.com Git - apple/hfs.git/blob - fsck_hfs/fsck_hfs.c
2 * Copyright (c) 1999-2000, 2002-2008 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
23 #include <sys/types.h>
25 #include <sys/param.h>
26 #include <sys/ucred.h>
27 #include <sys/mount.h>
28 #include <sys/ioctl.h>
30 #include <sys/sysctl.h>
33 #include <hfs/hfs_mount.h>
44 #include <TargetConditionals.h>
47 #include "fsck_msgnums.h"
48 #include "fsck_hfs_msgnums.h"
50 #include "fsck_debug.h"
51 #include "dfalib/CheckHFS.h"
54 * These definitions are duplicated from xnu's hfs_readwrite.c, and could live
55 * in a shared header file if desired. On the other hand, the freeze and thaw
56 * commands are not really supposed to be public.
59 #define F_FREEZE_FS 53 /* "freeze" all fs operations */
60 #define F_THAW_FS 54 /* "thaw" all fs operations */
63 /* Global Variables for front end */
64 const char *cdevname
; /* name of device being checked */
66 char lflag
; /* live fsck */
67 char nflag
; /* assume a no response */
68 char yflag
; /* assume a yes response */
69 char preen
; /* just fix normal inconsistencies */
70 char force
; /* force fsck even if clean (preen only) */
71 char quick
; /* quick check returns clean, dirty, or failure */
72 char debug
; /* output debugging info */
73 char disable_journal
; /* If debug, and set, do not simulate journal replay */
74 char scanflag
; /* Scan entire disk for bad blocks */
75 #if !TARGET_OS_EMBEDDED
81 char hotroot
; /* checking root device */
82 char hotmount
; /* checking read-only mounted device */
83 char guiControl
; /* this app should output info for gui control */
84 char xmlControl
; /* Output XML (plist) messages -- implies guiControl as well */
85 char rebuildBTree
; /* Rebuild requested btree files */
86 int rebuildOptions
; /* Options to indicate which btree should be rebuilt */
87 char modeSetting
; /* set the mode when creating "lost+found" directory */
88 char errorOnExit
= 0; /* Exit on first error */
89 int upgrading
; /* upgrading format */
90 int lostAndFoundMode
= 0; /* octal mode used when creating "lost+found" directory */
91 uint64_t reqCacheSize
; /* Cache size requested by the caller (may be specified by the user via -c) */
93 int fsmodified
; /* 1 => write done to file system */
94 int fsreadfd
; /* file descriptor for reading file system */
95 int fswritefd
; /* file descriptor for writing file system */
99 * Variables used to map physical block numbers to file paths
101 enum { BLOCK_LIST_INCREMENT
= 512 };
102 int gBlkListEntries
= 0;
103 u_int64_t
*gBlockList
= NULL
;
104 int gFoundBlockEntries
= 0;
105 struct found_blocks
*gFoundBlocksList
= NULL
;
106 long gBlockSize
= 512;
107 static void ScanDisk(int);
108 static int getblocklist(const char *filepath
);
111 static int checkfilesys
__P((char * filesys
));
112 static int setup
__P(( char *dev
, int *canWritePtr
));
113 static void usage
__P((void));
114 static void getWriteAccess
__P(( char *dev
, int *canWritePtr
));
115 extern char *unrawname
__P((char *name
));
128 if ((progname
= strrchr(*argv
, '/')))
133 while ((ch
= getopt(argc
, argv
, "b:B:c:D:e:Edfglm:npqrR:SuyxJ")) != EOF
) {
136 gBlockSize
= atoi(optarg
);
137 if ((gBlockSize
< 512) || (gBlockSize
& (gBlockSize
-1))) {
138 (void) fprintf(stderr
, "%s invalid block size %d\n",
139 progname
, gBlockSize
);
147 getblocklist(optarg
);
150 /* Cache size to use in fsck_hfs */
151 reqCacheSize
= strtoull(optarg
, &lastChar
, 0);
153 switch (tolower(*lastChar
)) {
155 reqCacheSize
*= 1024ULL;
158 reqCacheSize
*= 1024ULL;
161 reqCacheSize
*= 1024ULL;
178 /* Input value should be in hex example: -D 0x5 */
179 cur_debug_level
= strtoul(optarg
, NULL
, 0);
180 if (cur_debug_level
== 0) {
181 (void) fplog (stderr
, "%s: invalid debug development argument. Assuming zero\n", progname
);
187 if (strcasecmp(optarg
, "embedded") == 0)
189 else if (strcasecmp(optarg
, "desktop") == 0)
195 /* Exit on first error, after logging it */
220 lostAndFoundMode
= strtol( optarg
, NULL
, 8 );
221 if ( lostAndFoundMode
== 0 )
223 (void) fplog(stderr
, "%s: invalid mode argument \n", progname
);
242 // rebuild catalog btree
244 rebuildOptions
|= REBUILD_CATALOG
;
253 // rebuild attribute btree
255 rebuildOptions
|= REBUILD_ATTRIBUTE
;
259 // rebuild catalog btree
261 rebuildOptions
|= REBUILD_CATALOG
;
265 // rebuild extents overflow btree
267 rebuildOptions
|= REBUILD_EXTENTS
;
271 fprintf(stderr
, "%s: unknown btree rebuild code `%c' (%#x)\n", progname
, *cp
, *cp
);
294 if (debug
== 0 && disable_journal
!= 0)
297 if (gBlkListEntries
!= 0 && gBlockSize
== 0)
301 debug
= 0; /* debugging is for command line only */
303 if (signal(SIGINT
, SIG_IGN
) != SIG_IGN
)
304 (void)signal(SIGINT
, catch);
307 (void) fplog(stderr
, "%s: missing special-device\n", progname
);
313 ret
|= checkfilesys(blockcheck(*argv
++));
318 int fs_fd
=-1; // fd to the root-dir of the fs we're checking (only w/lfag == 1)
324 fcntl(fs_fd
, F_THAW_FS
, NULL
);
331 mountpoint(const char *cdev
)
334 struct statfs
*fsinfo
;
339 unraw
= strdup(cdev
);
345 result
= getmntinfo(&fsinfo
, MNT_NOWAIT
);
347 for (i
= 0; i
< result
; i
++) {
348 if (strcmp(unraw
, fsinfo
[i
].f_mntfromname
) == 0) {
349 retval
= strdup(fsinfo
[i
].f_mntonname
);
362 checkfilesys(char * filesys
)
366 int chkLev
, repLev
, logLev
;
368 char *mntonname
= NULL
;
369 fsck_ctx_t context
= NULL
;
373 hotmount
= hotroot
; // hotroot will be 1 or 0 by this time
376 // initialize the printing/logging without actually printing anything
377 // DO NOT DELETE THIS or else you can deadlock during a live fsck
378 // when something is printed and we try to create the log file.
382 context
= fsckCreate();
384 mntonname
= mountpoint(cdevname
);
388 mntonname
= strdup("/");
395 * Ensure that, if we're doing a live verify, that we're not trying
396 * to do input or output to the same device. This would cause a deadlock.
399 if (stat(cdevname
, &fs_stat
) != -1 &&
400 (((fs_stat
.st_mode
& S_IFMT
) == S_IFCHR
) ||
401 ((fs_stat
.st_mode
& S_IFMT
) == S_IFBLK
))) {
404 if (fstat(fileno(stdin
), &io_stat
) != -1 &&
405 (fs_stat
.st_rdev
== io_stat
.st_dev
)) {
406 plog("ERROR: input redirected from target volume for live verify.\n");
409 if (fstat(fileno(stdout
), &io_stat
) != -1 &&
410 (fs_stat
.st_rdev
== io_stat
.st_dev
)) {
411 plog("ERROR: output redirected to target volume for live verify.\n");
414 if (fstat(fileno(stderr
), &io_stat
) != -1 &&
415 (fs_stat
.st_rdev
== io_stat
.st_dev
)) {
416 plog("ERROR: error output redirected to target volume for live verify.\n");
424 * If the device is mounted somewhere, then we need to make sure that it's
425 * a read-only device, or that a live-verify has been requested.
427 if (mntonname
!= NULL
) {
428 struct statfs stfs_buf
;
430 if (statfs(mntonname
, &stfs_buf
) == 0) {
432 // Need to try to freeze it
433 fs_fd
= open(mntonname
, O_RDONLY
);
435 plog("ERROR: could not open %s to freeze the volume.\n", mntonname
);
440 if (fcntl(fs_fd
, F_FREEZE_FS
, NULL
) != 0) {
442 plog("ERROR: could not freeze volume (%s)\n", strerror(errno
));
445 } else if (stfs_buf
.f_flags
& MNT_RDONLY
) {
454 if (setup( filesys
, &canWrite
) == 0) {
456 pfatal("CAN'T CHECK FILE SYSTEM.");
458 goto ExitThisRoutine
;
462 if (hotroot
&& !guiControl
)
463 plog("** Root file system\n");
466 /* start with defaults for dfa back-end */
467 chkLev
= kAlwaysCheck
;
468 repLev
= kMajorRepairs
;
469 logLev
= kVerboseLog
;
472 repLev
= kMajorRepairs
;
475 chkLev
= kNeverCheck
;
476 repLev
= kNeverRepair
;
479 chkLev
= kForceCheck
;
482 repLev
= kMinorRepairs
;
483 chkLev
= force
? kAlwaysCheck
: kDirtyCheck
;
490 repLev
= kNeverRepair
;
492 if ( rebuildBTree
) {
493 chkLev
= kPartialCheck
;
494 repLev
= kForceRepairs
; // this will force rebuild of B-Tree file
497 fsckSetVerbosity(context
, logLev
);
498 /* All of fsck_hfs' output should go thorugh logstring */
499 fsckSetOutput(context
, NULL
);
500 /* Setup writer that will output to standard out */
501 fsckSetWriter(context
, &outstring
);
502 /* Setup logger that will write to log file */
503 fsckSetLogger(context
, &logstring
);
506 fsckSetOutputStyle(context
, fsckOutputXML
);
508 fsckSetOutputStyle(context
, fsckOutputGUI
);
510 fsckSetOutputStyle(context
, fsckOutputTraditional
);
513 if (errorOnExit
&& nflag
) {
514 chkLev
= kMajorCheck
;
518 * go check HFS volume...
521 if (rebuildOptions
&& canWrite
== 0) {
522 plog("BTree rebuild requested but writing disabled\n");
524 goto ExitThisRoutine
;
527 if (gBlockList
!= NULL
&& scanflag
!= 0) {
528 plog("Cannot scan for bad blocks and ask for listed blocks to file mapping\n");
530 goto ExitThisRoutine
;
533 plog("Scanning entire disk for bad blocks\n");
537 result
= CheckHFS( filesys
, fsreadfd
, fswritefd
, chkLev
, repLev
, context
,
538 lostAndFoundMode
, canWrite
, &fsmodified
,
539 lflag
, rebuildOptions
);
541 plog("\tCheckHFS returned %d, fsmodified = %d\n", result
, fsmodified
);
547 pwarn("QUICKCHECK ONLY; FILESYSTEM CLEAN\n");
549 goto ExitThisRoutine
;
550 } else if (result
== R_Dirty
) {
551 pwarn("QUICKCHECK ONLY; FILESYSTEM DIRTY\n");
553 goto ExitThisRoutine
;
554 } else if (result
== R_BadSig
) {
555 pwarn("QUICKCHECK ONLY; NO HFS SIGNATURE FOUND\n");
557 goto ExitThisRoutine
;
560 goto ExitThisRoutine
;
564 struct statfs stfs_buf
;
567 * Check to see if root is mounted read-write.
569 if (statfs(mntonname
, &stfs_buf
) == 0)
570 flags
= stfs_buf
.f_flags
;
573 ckfini(flags
& MNT_RDONLY
);
576 /* XXX free any allocated memory here */
578 if (hotmount
&& fsmodified
) {
579 struct hfs_mount_args args
;
581 * We modified the root. Do a mount update on
582 * it, unless it is read-write, so we can continue.
585 fsckPrint(context
, fsckVolumeModified
);
586 if (flags
& MNT_RDONLY
) {
587 bzero(&args
, sizeof(args
));
588 flags
|= MNT_UPDATE
| MNT_RELOAD
;
590 fprintf(stderr
, "doing update / reload mount for %s now\n", mntonname
);
591 if (mount("hfs", mntonname
, flags
, &args
) == 0) {
594 goto ExitThisRoutine
;
597 fprintf(stderr
, "update/reload mount for %s failed: %s\n", mntonname
, strerror(errno
));
601 plog("\n***** REBOOT NOW *****\n");
603 result
= FIXEDROOTEXIT
;
604 goto ExitThisRoutine
;
607 if (result
!= 0 && result
!= MAJOREXIT
)
613 fcntl(fs_fd
, F_THAW_FS
, NULL
);
622 fsckDestroy(context
);
629 * Setup for I/O to device
630 * Return 1 if successful, 0 if unsuccessful.
631 * canWrite - 1 if we can safely write to the raw device or 0 if not.
634 setup( char *dev
, int *canWritePtr
)
638 uint32_t cacheBlockSize
;
639 uint32_t cacheTotalBlocks
;
645 if (stat(dev
, &statb
) < 0) {
646 plog("Can't stat %s: %s\n", dev
, strerror(errno
));
649 if ((statb
.st_mode
& S_IFMT
) != S_IFCHR
) {
650 pfatal("%s is not a character device", dev
);
651 if (reply("CONTINUE") == 0)
654 /* Always attempt to replay the journal */
655 if (!nflag
&& !quick
) {
656 // We know we have a character device by now.
657 if (strncmp(dev
, "/dev/rdisk", 10) == 0) {
658 char block_device
[MAXPATHLEN
+1];
660 snprintf(block_device
, sizeof(block_device
), "/dev/%s", dev
+ 6);
661 rv
= journal_replay(block_device
);
663 plog("journal_replay(%s) returned %d\n", block_device
, rv
);
666 /* attempt to get write access to the block device and if not check if volume is */
667 /* mounted read-only. */
668 if (nflag
== 0 && quick
== 0) {
669 getWriteAccess( dev
, canWritePtr
);
672 if (nflag
|| quick
|| (fswritefd
= open(dev
, O_RDWR
| (hotmount
? 0 : O_EXLOCK
))) < 0) {
675 pfatal("** %s (NO WRITE ACCESS)\n", dev
);
679 if (preen
== 0 && !guiControl
) {
680 if (nflag
|| quick
|| fswritefd
== -1) {
681 plog("** %s (NO WRITE)\n", dev
);
683 plog("** %s\n", dev
);
687 if (fswritefd
== -1) {
688 if ((fsreadfd
= open(dev
, O_RDONLY
)) < 0) {
689 plog("Can't open %s: %s\n", dev
, strerror(errno
));
693 fsreadfd
= dup(fswritefd
);
695 plog("Can't dup fd for reading on %s: %s\n", dev
, strerror(errno
));
702 /* Get device block size to initialize cache */
703 if (ioctl(fsreadfd
, DKIOCGETBLOCKSIZE
, &devBlockSize
) < 0) {
704 pfatal ("Can't get device block size\n");
709 * Calculate the cache block size and total blocks.
711 * If a quick check was requested, we'll only be checking to see if
712 * the volume was cleanly unmounted or journalled, so we won't need
713 * a lot of cache. Since lots of quick checks can be run in parallel
714 * when a new disk with several partitions comes on line, let's avoid
715 * the memory usage when we don't need it.
717 if (reqCacheSize
== 0 && quick
== 0) {
719 * Auto-pick the cache size. The cache code will deal with minimum
720 * maximum values, so we just need to find out the size of memory, and
721 * how much of it we'll use.
723 * If we're looking at the root device, and it's not a live verify (lflag),
724 * then we will use half of physical memory; otherwise, we'll use an eigth.
728 size_t dsize
= sizeof(memSize
);
731 rv
= sysctlbyname("hw.memsize", &memSize
, &dsize
, NULL
, 0);
733 (void)fplog(stderr
, "sysctlbyname failed, not auto-setting cache size\n");
735 int d
= (hotroot
&& !lflag
) ? 2 : 8;
737 dsize
= sizeof(safeMode
);
738 rv
= sysctlbyname("kern.safeboot", &safeMode
, &dsize
, NULL
, 0);
739 if (rv
!= -1 && safeMode
!= 0 && hotroot
&& !lflag
) {
740 #define kMaxSafeModeMem ((size_t)2 * 1024 * 1024 * 1024) /* 2Gbytes, means cache will max out at 1gbyte */
742 (void)fplog(stderr
, "Safe mode and single-user, setting memsize to a maximum of 2gbytes\n");
744 memSize
= (memSize
< kMaxSafeModeMem
) ? memSize
: kMaxSafeModeMem
;
746 reqCacheSize
= memSize
/ d
;
750 CalculateCacheSizes(reqCacheSize
, &cacheBlockSize
, &cacheTotalBlocks
, debug
);
752 preTouchMem
= (hotroot
!= 0) && (lflag
!= 0);
753 /* Initialize the cache */
754 if (CacheInit (&fscache
, fsreadfd
, fswritefd
, devBlockSize
,
755 cacheBlockSize
, cacheTotalBlocks
, CacheHashSize
, preTouchMem
) != EOK
) {
756 pfatal("Can't initialize disk cache\n");
764 // This routine will attempt to open the block device with write access for the target
765 // volume in order to block others from mounting the volume with write access while we
766 // check / repair it. If we cannot get write access then we check to see if the volume
767 // has been mounted read-only. If it is read-only then we should be OK to write to
768 // the raw device. Note that this does not protect use from someone upgrading the mount
769 // from read-only to read-write.
771 static void getWriteAccess( char *dev
, int *canWritePtr
)
777 struct statfs
* myBufPtr
;
779 int blockDevice_fd
= -1;
782 myNamePtr
= malloc( strlen(dev
) + 2 );
783 if ( myNamePtr
== NULL
)
786 strcpy( (char *)myNamePtr
, dev
);
787 if ( (myCharPtr
= strrchr( (char *)myNamePtr
, '/' )) != 0 ) {
788 if ( myCharPtr
[1] == 'r' ) {
789 memmove(&myCharPtr
[1], &myCharPtr
[2], strlen(&myCharPtr
[2]) + 1);
790 blockDevice_fd
= open( (char *)myNamePtr
, O_WRONLY
| (hotmount
? 0 : O_EXLOCK
) );
794 if ( blockDevice_fd
> 0 ) {
795 // we got write access to the block device so we can safely write to raw device
797 goto ExitThisRoutine
;
800 // get count of mounts then get the info for each
801 myMountsCount
= getfsstat( NULL
, 0, MNT_NOWAIT
);
802 if ( myMountsCount
< 0 )
803 goto ExitThisRoutine
;
805 myPtr
= (void *) malloc( sizeof(struct statfs
) * myMountsCount
);
807 goto ExitThisRoutine
;
808 myMountsCount
= getfsstat( myPtr
,
809 (int)(sizeof(struct statfs
) * myMountsCount
),
811 if ( myMountsCount
< 0 )
812 goto ExitThisRoutine
;
814 myBufPtr
= (struct statfs
*) myPtr
;
815 for ( i
= 0; i
< myMountsCount
; i
++ )
817 if ( strcmp( myBufPtr
->f_mntfromname
, myNamePtr
) == 0 ) {
818 if ( myBufPtr
->f_flags
& MNT_RDONLY
)
820 goto ExitThisRoutine
;
824 *canWritePtr
= 1; // single user will get us here, f_mntfromname is not /dev/diskXXXX
830 if ( myNamePtr
!= NULL
)
833 if (blockDevice_fd
!= -1) {
834 close(blockDevice_fd
);
839 } /* getWriteAccess */
845 (void) fplog(stderr
, "usage: %s [-b [size] B [path] c [size] e [mode] ESdfglx m [mode] npqruy] special-device\n", progname
);
846 (void) fplog(stderr
, " b size = size of physical blocks (in bytes) for -B option\n");
847 (void) fplog(stderr
, " B path = file containing physical block numbers to map to paths\n");
848 (void) fplog(stderr
, " c size = cache size (ex. 512m, 1g)\n");
849 (void) fplog(stderr
, " e mode = emulate 'embedded' or 'desktop'\n");
850 (void) fplog(stderr
, " E = exit on first major error\n");
851 (void) fplog(stderr
, " d = output debugging info\n");
852 (void) fplog(stderr
, " f = force fsck even if clean (preen only) \n");
853 (void) fplog(stderr
, " g = GUI output mode\n");
854 (void) fplog(stderr
, " x = XML output mode\n");
855 (void) fplog(stderr
, " l = live fsck (lock down and test-only)\n");
856 (void) fplog(stderr
, " m arg = octal mode used when creating lost+found directory \n");
857 (void) fplog(stderr
, " n = assume a no response \n");
858 (void) fplog(stderr
, " p = just fix normal inconsistencies \n");
859 (void) fplog(stderr
, " q = quick check returns clean, dirty, or failure \n");
860 (void) fplog(stderr
, " r = rebuild catalog btree \n");
861 (void) fplog(stderr
, " S = Scan disk for bad blocks\n");
862 (void) fplog(stderr
, " u = usage \n");
863 (void) fplog(stderr
, " y = assume a yes response \n");
870 AddBlockToList(long long block
)
873 if ((gBlkListEntries
% BLOCK_LIST_INCREMENT
) == 0) {
876 // gBlkListEntries += BLOCK_LIST_INCREMENT;
877 tmp
= realloc(gBlockList
, (gBlkListEntries
+ BLOCK_LIST_INCREMENT
) * sizeof(u_int64_t
));
879 pfatal("Can't allocate memory for block list (%llu entries).\n", gBlkListEntries
);
881 gBlockList
= (u_int64_t
*)tmp
;
883 gBlockList
[gBlkListEntries
++] = block
;
887 static int printStatus
;
897 uint32_t devBlockSize
= 512;
898 uint64_t devBlockTotal
;
900 uint8_t *buffer
= NULL
;
901 size_t bufSize
= 1024 * 1024;
904 void (*oldhandler
)(int);
905 uint32_t numErrors
= 0;
906 uint32_t maxErrors
= 40; // Something more variable?
908 oldhandler
= signal(SIGINFO
, &siginfo
);
913 fprintf(stderr, "Scanning offset %lld of %lld (%d%%)\n", \
914 curPos, diskSize, (int)((curPos * 100) / diskSize)); \
916 fprintf(stderr, "Scanning offset %lld\n", curPos); \
921 if (ioctl(fd
, DKIOCGETBLOCKSIZE
, &devBlockSize
) == -1) {
925 if (ioctl(fd
, DKIOCGETBLOCKCOUNT
, &devBlockTotal
) == -1) {
928 diskSize
= devBlockTotal
* devBlockSize
;
930 while (buffer
== NULL
&& bufSize
>= devBlockSize
) {
931 buffer
= malloc(bufSize
);
932 if (buffer
== NULL
) {
936 if (buffer
== NULL
) {
937 pfatal("Cannot allocate buffer for disk scan.\n");
945 while ((nread
= pread(fd
, buffer
, bufSize
, curPos
)) == bufSize
) {
953 /* We're done with the disk */
958 /* Try reading devBlockSize blocks */
960 for (total
= 0; total
< bufSize
; total
+= devBlockSize
) {
961 nread
= pread(fd
, buffer
, devBlockSize
, curPos
+ total
);
965 fprintf(stderr
, "Bad block at offset %lld\n", curPos
+ total
);
966 AddBlockToList((curPos
+ total
) / gBlockSize
);
967 if (++numErrors
> maxErrors
) {
969 fprintf(stderr
, "Got %u errors, maxing out so stopping scan\n", numErrors
);
974 pfatal("Got a non I/O error reading disk at offset %llu: %s\n",
975 curPos
+ total
, strerror(errno
));
976 // Hey, pfatal wasn't fatal!
977 // But that seems to work out for us for some reason.
981 /* End of disk, somehow. */
984 if (nread
!= devBlockSize
) {
985 pwarn("During disk scan, did not get block size (%zd) read, got %zd instead. Skipping rest of this block.\n", (size_t)devBlockSize
, nread
);
991 } else if (errno
== EINTR
) {
994 pfatal("Got a non I/O error reading disk at offset %llu: %s\n", curPos
, strerror(errno
));
998 if (nread
< bufSize
) {
999 if ((nread
% devBlockSize
) == 0) {
1002 curPos
= curPos
+ (((nread
% devBlockSize
) + 1) * devBlockSize
);
1010 signal(SIGINFO
, oldhandler
);
1016 getblocklist(const char *filepath
)
1020 size_t blockListCount
; /* Number of elements allocated to gBlockList array */
1022 blockListCount
= BLOCK_LIST_INCREMENT
;
1023 gBlockList
= (u_int64_t
*) malloc(blockListCount
* sizeof(u_int64_t
));
1024 if (gBlockList
== NULL
)
1025 pfatal("Can't allocate memory for block list.\n");
1027 // printf("getblocklist: processing blocklist %s...\n", filepath);
1029 if ((file
= fopen(filepath
, "r")) == NULL
)
1030 pfatal("Can't open %s\n", filepath
);
1032 while (fscanf(file
, "%lli", &block
) > 0) {
1033 AddBlockToList(block
);
1036 (void) fclose(file
);
1038 printf("%d blocks to match:\n", gBlkListEntries
);