]> git.saurik.com Git - apple/hfs.git/commitdiff
hfs-191.1.tar.gz mac-os-x-1073 mac-os-x-1074 mac-os-x-1075 v191.1
authorApple <opensource@apple.com>
Tue, 8 Nov 2011 23:05:59 +0000 (23:05 +0000)
committerApple <opensource@apple.com>
Tue, 8 Nov 2011 23:05:59 +0000 (23:05 +0000)
CopyHFSMeta/main.c

index 28aa38cac47719bda7f1f99ce74d6e0e83002fb3..235f0e809c9d8b90c6aa0d6a72bfbc0d10598967 100644 (file)
@@ -66,6 +66,44 @@ OpenDevice(const char *devname)
        if (stat(devname, &sb) == -1) {
                err(kBadExit, "cannot open device %s", devname);
        }
+       /*
+        * Attempt to flush the journal.  If it fails, we just warn, but don't abort.
+        */
+       if (getvfsbyname("hfs", &vfc) == 0) {
+               int rv;
+               int mib[4];
+               char block_device[MAXPATHLEN+1];
+               int jfd;
+
+               /*
+                * The journal replay code, sadly, requires a block device.
+                * So we need to go from the raw device to block device, if
+                * necessary.
+                */
+               if (strncmp(devname, "/dev/rdisk", 10) == 0) {
+                       snprintf(block_device, sizeof(block_device), "/dev/%s", devname+6);
+               } else {
+                       snprintf(block_device, sizeof(block_device), "%s", devname);
+               }
+               jfd = open(block_device, O_RDWR);
+               if (jfd == -1) {
+                       warn("Cannot open block device %s for read-write", block_device);
+               } else {
+                       mib[0] = CTL_VFS;
+                       mib[1] = vfc.vfc_typenum;
+                       mib[2] = HFS_REPLAY_JOURNAL;
+                       mib[3] = jfd;
+                       if (debug)
+                               fprintf(stderr, "about to replay journal\n");
+                       rv = sysctl(mib, 4, NULL, NULL, NULL, 0);
+                       if (rv == -1) {
+                               warn("cannot replay journal");
+                       }
+                       /* This is probably not necessary, but we couldn't prove it. */
+                       (void)fcntl(jfd, F_FULLFSYNC, 0);
+                       close(jfd);
+               }
+       }
        /*
         * We only allow a character device (e.g., /dev/rdisk1s2)
         * If we're given a non-character device, we'll try to turn
@@ -99,26 +137,6 @@ OpenDevice(const char *devname)
        if (ioctl(fd, DKIOCGETBLOCKCOUNT, &dev.blockCount) == -1) {
                err(kBadExit, "cannot get size of device %s", dev.devname);
        }
-       /*
-        * Attempt to flush the journal.  If it fails, we just warn, but don't abort.
-        */
-       if (getvfsbyname("hfs", &vfc) == 0) {
-               int rv;
-               int mib[4];
-
-               mib[0] = CTL_VFS;
-               mib[1] = vfc.vfc_typenum;
-               mib[2] = HFS_REPLAY_JOURNAL;
-               mib[3] = fd;
-               if (debug)
-                       fprintf(stderr, "about to replay journal\n");
-               rv = sysctl(mib, 4, NULL, NULL, NULL, 0);
-               if (rv == -1) {
-                       warn("cannot replay journal");
-               }
-               /* This is probably not necessary, but we couldn't prove it. */
-               (void)fcntl(fd, F_FULLFSYNC, 0);
-       }
 
        dev.size = dev.blockCount * dev.blockSize;
        dev.fd = fd;