warn("Cannot read from device at offset %lld", start + total);
return -1;
}
- (void)pwrite(ctx->fd, (char*)buffer + total, amt, start + total);
- bp(amt);
- total += amt;
+ (void)pwrite(ctx->fd, (char*)buffer, nread, start + total);
+ bp(nread);
+ total += nread;
}
return 0;
}
errx(kBadExit, "device name `%s' does not fit pattern", devname);
}
// Only use an exclusive open if we're not debugging.
- fd = open(dev.devname, O_RDONLY | (debug ? 0 : O_EXLOCK));
+ fd = open(dev.devname, O_RDWR | (debug ? 0 : O_EXLOCK));
if (fd == -1) {
err(kBadExit, "cannot open raw device %s", dev.devname);
}
err(kBadExit, "cannot get size of device %s", dev.devname);
}
/*
- * Attempt to flush the buffer. This works even with a file descriptor
- * opened for read-only. If it fails, we just warn, but don't abort.
+ * Attempt to flush the journal. If it fails, we just warn, but don't abort.
*/
if (getvfsbyname("hfs", &vfc) == 0) {
int rv;
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;
<key>CFBundlePackageType</key>
<string>fs </string>
<key>CFBundleShortVersionString</key>
- <string>1.6.0</string>
+ <string>1.6.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<integer>128</integer>
<key>FSRepairArguments</key>
<string>-y</string>
+ <key>FSXMLOutputArgument</key>
+ <string>-x</string>
<key>FSRepairExecutable</key>
<string>../../../../../../sbin/fsck_hfs</string>
<key>FSVerificationArguments</key>
<integer>0</integer>
<key>FSRepairArguments</key>
<string>-y</string>
+ <key>FSXMLOutputArgument</key>
+ <string>-x</string>
<key>FSRepairExecutable</key>
<string>../../../../../../sbin/fsck_hfs</string>
<key>FSVerificationArguments</key>
<integer>1</integer>
<key>FSRepairArguments</key>
<string>-fy</string>
+ <key>FSXMLOutputArgument</key>
+ <string>-x</string>
<key>FSRepairExecutable</key>
<string>../../../../../../sbin/fsck_hfs</string>
<key>FSVerificationArguments</key>
<string>../../../../../../sbin/fsck_hfs</string>
<key>FSLiveVerificationArguments</key>
<string>-l</string>
+ <key>FSCoreStorageEncryptionName</key>
+ <string>Mac OS Extended (Journaled, Encrypted)</string>
+
</dict>
<key>Case-sensitive HFS+</key>
<dict>
<integer>2</integer>
<key>FSRepairArguments</key>
<string>-y</string>
+ <key>FSXMLOutputArgument</key>
+ <string>-x</string>
<key>FSRepairExecutable</key>
<string>../../../../../../sbin/fsck_hfs</string>
<key>FSVerificationArguments</key>
<integer>3</integer>
<key>FSRepairArguments</key>
<string>-fy</string>
+ <key>FSXMLOutputArgument</key>
+ <string>-x</string>
<key>FSRepairExecutable</key>
<string>../../../../../../sbin/fsck_hfs</string>
<key>FSVerificationArguments</key>
<string>../../../../../../sbin/fsck_hfs</string>
<key>FSLiveVerificationArguments</key>
<string>-l</string>
+ <key>FSCoreStorageEncryptionName</key>
+ <string>Mac OS Extended (Case-sensitive, Journaled, Encrypted)</string>
</dict>
</dict>
</dict>
<dict>
<key>FSName</key>
<string>Mac OS Extended (Journaled)</string>
+ <key>FSCoreStorageEncryptionName</key>
+ <string>Mac OS Extended (Journaled, Encrypted)</string>
+
</dict>
<key>Case-sensitive HFS+</key>
<dict>
<dict>
<key>FSName</key>
<string>Mac OS Extended (Case-sensitive, Journaled)</string>
+ <key>FSCoreStorageEncryptionName</key>
+ <string>Mac OS Extended (Case-sensitive, Journaled, Encrypted)</string>
+
</dict>
</dict>
</dict>
-#
-# Generated by the Apple Project Builder.
-#
-# NOTE: Do NOT change this file -- Project Builder maintains it.
-#
-# Put all of your customizations in files called Makefile.preamble
-# and Makefile.postamble (both optional), and Makefile will include them.
-#
+Project = hfs.util
+ProductType = tool
+Install_Dir = /System/Library/Filesystems/hfs.fs
-NAME = hfs.util
-
-PROJECTVERSION = 2.8
-PROJECT_TYPE = Tool
+MAN_DIR= $(DSTROOT)/usr/share/man/man8
+MANPAGES= hfs.util.8
CFILES = hfsutil_main.c hfsutil_jnl.c
-
-OTHERSRCS = Makefile.preamble Makefile Makefile.postamble\
- hfs_CD.fs.tiff hfs_CD.openfs.tiff hfs_FD.fs.tiff\
- hfs_FD.openfs.tiff hfs_HD.fs.tiff hfs_HD.openfs.tiff\
- hfs_RHD.fs.tiff hfs_RHD.openfs.tiff Info.plist\
+OTHERSRCS = \
+ hfs_CD.fs.tiff hfs_CD.openfs.tiff hfs_FD.fs.tiff \
+ hfs_FD.openfs.tiff hfs_HD.fs.tiff hfs_HD.openfs.tiff \
+ hfs_RHD.fs.tiff hfs_RHD.openfs.tiff Info.plist \
InfoPlist.strings PkgInfo version.plist hfs.util.8
+Extra_LD_Flags = -framework CoreFoundation
-MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles
-CODE_GEN_STYLE = DYNAMIC
-MAKEFILE = tool.make
-NEXTSTEP_INSTALLDIR = $(SYSTEM_LIBRARY_DIR)/Filesystems/hfs.fs
-LIBS =
-DEBUG_LIBS = $(LIBS)
-PROF_LIBS = $(LIBS)
-
-
-FRAMEWORKS = -framework CoreFoundation
-
-
-NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc
-WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc
-PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc
-NEXTSTEP_JAVA_COMPILER = /usr/bin/javac
-WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe
-PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac
-
-include $(MAKEFILEDIR)/platform.make
-
--include Makefile.preamble
-
-include $(MAKEFILEDIR)/$(MAKEFILE)
-
--include Makefile.postamble
+include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make
--include Makefile.dependencies
+after_install:
+ $(INSTALL_DIRECTORY) "$(DSTROOT)/$(Install_Dir)/Contents/Resources/English.lproj"
+ install -o root -m 644 Info.plist "$(DSTROOT)/$(Install_Dir)/Contents"
+ install -o root -m 644 PkgInfo "$(DSTROOT)/$(Install_Dir)/Contents"
+ install -o root -m 644 version.plist "$(DSTROOT)/$(Install_Dir)/Contents"
+ install -o root -m 644 InfoPlist.strings "$(DSTROOT)/$(Install_Dir)/Contents/Resources/English.lproj"
+++ /dev/null
-###############################################################################
-# Makefile.postamble
-# Copyright 1997, Apple Computer, Inc.
-#
-# Use this makefile, which is imported after all other makefiles, to
-# override attributes for a project's Makefile environment. This allows you
-# to take advantage of the environment set up by the other Makefiles.
-# You can also define custom rules at the end of this file.
-#
-###############################################################################
-#
-# These variables are exported by the standard makefiles and can be
-# used in any customizations you make. They are *outputs* of
-# the Makefiles and should be used, not set.
-#
-# PRODUCTS: products to install. All of these products will be placed in
-# the directory $(DSTROOT)$(INSTALLDIR)
-# GLOBAL_RESOURCE_DIR: The directory to which resources are copied.
-# LOCAL_RESOURCE_DIR: The directory to which localized resources are copied.
-# OFILE_DIR: Directory into which .o object files are generated.
-# DERIVED_SRC_DIR: Directory used for all other derived files
-#
-# ALL_CFLAGS: flags to pass when compiling .c files
-# ALL_MFLAGS: flags to pass when compiling .m files
-# ALL_CCFLAGS: flags to pass when compiling .cc, .cxx, and .C files
-# ALL_MMFLAGS: flags to pass when compiling .mm, .mxx, and .M files
-# ALL_PRECOMPFLAGS: flags to pass when precompiling .h files
-# ALL_LDFLAGS: flags to pass when linking object files
-# ALL_LIBTOOL_FLAGS: flags to pass when libtooling object files
-# ALL_PSWFLAGS: flags to pass when processing .psw and .pswm (pswrap) files
-# ALL_RPCFLAGS: flags to pass when processing .rpc (rpcgen) files
-# ALL_YFLAGS: flags to pass when processing .y (yacc) files
-# ALL_LFLAGS: flags to pass when processing .l (lex) files
-#
-# NAME: name of application, bundle, subproject, palette, etc.
-# LANGUAGE: langage in which the project is written (default "English")
-# LOCAL_RESOURCES: localized resources (e.g. nib's, images) of project
-# GLOBAL_RESOURCES: non-localized resources of project
-#
-# SRCROOT: base directory in which to place the new source files
-# SRCPATH: relative path from SRCROOT to present subdirectory
-#
-# INSTALLDIR: Directory the product will be installed into by 'install' target
-# PUBLIC_HDR_INSTALLDIR: where to install public headers. Don't forget
-# to prefix this with DSTROOT when you use it.
-# PRIVATE_HDR_INSTALLDIR: where to install private headers. Don't forget
-# to prefix this with DSTROOT when you use it.
-#
-# EXECUTABLE_EXT: Executable extension for the platform (i.e. .exe on Windows)
-#
-###############################################################################
-
-# Some compiler flags can be overridden here for certain build situations.
-#
-# WARNING_CFLAGS: flag used to set warning level (defaults to -Wmost)
-# DEBUG_SYMBOLS_CFLAGS: debug-symbol flag passed to all builds (defaults
-# to -g)
-# DEBUG_BUILD_CFLAGS: flags passed during debug builds (defaults to -DDEBUG)
-# OPTIMIZE_BUILD_CFLAGS: flags passed during optimized builds (defaults
-# to -O)
-# PROFILE_BUILD_CFLAGS: flags passed during profile builds (defaults
-# to -pg -DPROFILE)
-# LOCAL_DIR_INCLUDE_DIRECTIVE: flag used to add current directory to
-# the include path (defaults to -I.)
-# DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags
-# passed to ld/libtool (defaults to nothing)
-
-
-# Library and Framework projects only:
-# INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked
-# against the framework will run against the correct version even if
-# the current version of the framework changes. You may override this
-# to "" as an alternative to using the DYLD_LIBRARY_PATH during your
-# development cycle, but be sure to restore it before installing.
-
-
-# Ownership and permissions of files installed by 'install' target
-
-INSTALL_AS_USER = root
- # User/group ownership
-#INSTALL_AS_GROUP = wheel
- # (probably want to set both of these)
-#INSTALL_PERMISSIONS = 4555
- # If set, 'install' chmod's executable to this
-
-
-# Options to strip. Note: -S strips debugging symbols (executables can be stripped
-# down further with -x or, if they load no bundles, with no options at all).
-
-#STRIPFLAGS = -S
-
-
-#########################################################################
-# Put rules to extend the behavior of the standard Makefiles here. Include them in
-# the dependency tree via cvariables like AFTER_INSTALL in the Makefile.preamble.
-#
-# You should avoid redefining things like "install" or "app", as they are
-# owned by the top-level Makefile API and no context has been set up for where
-# derived files should go.
-#
-
-after_install:
- install -m 755 -o root -g wheel -d $(DSTROOT)/usr/share/man/man8
- install -m 644 -o root -g wheel -c hfs.util.8 $(DSTROOT)/usr/share/man/man8
-
-buildContentsDir:
- mkdir -p $(DSTROOT)$(INSTALLDIR)/Contents/Resources/English.lproj
- cp -pr Info.plist $(DSTROOT)$(INSTALLDIR)/Contents
- cp -pr PkgInfo $(DSTROOT)$(INSTALLDIR)/Contents
- cp -pr version.plist $(DSTROOT)$(INSTALLDIR)/Contents
- cp -pr InfoPlist.strings $(DSTROOT)$(INSTALLDIR)/Contents/Resources/English.lproj
- chown -Rf root:wheel $(DSTROOT)$(INSTALLDIR)/Contents
- find $(DSTROOT)$(INSTALLDIR)/Contents -type d -exec chmod 755 {} \;
- find $(DSTROOT)$(INSTALLDIR)/Contents -type f -exec chmod 644 {} \;
+++ /dev/null
-###############################################################################
-# Makefile.preamble
-# Copyright 1997, Apple Computer, Inc.
-#
-# Use this makefile for configuring the standard application makefiles
-# associated with ProjectBuilder. It is included before the main makefile.
-# In Makefile.preamble you set attributes for a project, so they are available
-# to the project's makefiles. In contrast, you typically write additional rules or
-# override built-in behavior in the Makefile.postamble.
-#
-# Each directory in a project tree (main project plus subprojects) should
-# have its own Makefile.preamble and Makefile.postamble.
-###############################################################################
-#
-# Before the main makefile is included for this project, you may set:
-#
-# MAKEFILEDIR: Directory in which to find $(MAKEFILE)
-# MAKEFILE: Top level mechanism Makefile (e.g., app.make, bundle.make)
-
-# Compiler/linker flags added to the defaults: The OTHER_* variables will be
-# inherited by all nested sub-projects, but the LOCAL_ versions of the same
-# variables will not. Put your -I, -D, -U, and -L flags in ProjectBuilder's
-# Build Attributes inspector if at all possible. To override the default flags
-# that get passed to ${CC} (e.g. change -O to -O2), see Makefile.postamble. The
-# variables below are *inputs* to the build process and distinct from the override
-# settings done (less often) in the Makefile.postamble.
-#
-# OTHER_CFLAGS, LOCAL_CFLAGS: additional flags to pass to the compiler
-# Note that $(OTHER_CFLAGS) and $(LOCAL_CFLAGS) are used for .h, ...c, .m,
-# .cc, .cxx, .C, and .M files. There is no need to respecify the
-# flags in OTHER_MFLAGS, etc.
-# OTHER_MFLAGS, LOCAL_MFLAGS: additional flags for .m files
-# OTHER_CCFLAGS, LOCAL_CCFLAGS: additional flags for .cc, .cxx, and ...C files
-# OTHER_MMFLAGS, LOCAL_MMFLAGS: additional flags for .mm and .M files
-# OTHER_PRECOMPFLAGS, LOCAL_PRECOMPFLAGS: additional flags used when
-# precompiling header files
-# OTHER_LDFLAGS, LOCAL_LDFLAGS: additional flags passed to ld and libtool
-# OTHER_PSWFLAGS, LOCAL_PSWFLAGS: additional flags passed to pswrap
-# OTHER_RPCFLAGS, LOCAL_RPCFLAGS: additional flags passed to rpcgen
-# OTHER_YFLAGS, LOCAL_YFLAGS: additional flags passed to yacc
-# OTHER_LFLAGS, LOCAL_LFLAGS: additional flags passed to lex
-
-# These variables provide hooks enabling you to add behavior at almost every
-# stage of the make:
-#
-# BEFORE_PREBUILD: targets to build before installing headers for a subproject
-# AFTER_PREBUILD: targets to build after installing headers for a subproject
-# BEFORE_BUILD_RECURSION: targets to make before building subprojects
-# BEFORE_BUILD: targets to make before a build, but after subprojects
-# AFTER_BUILD: targets to make after a build
-#
-# BEFORE_INSTALL: targets to build before installing the product
-# AFTER_INSTALL: targets to build after installing the product
-# BEFORE_POSTINSTALL: targets to build before postinstalling every subproject
-# AFTER_POSTINSTALL: targts to build after postinstalling every subproject
-#
-# BEFORE_INSTALLHDRS: targets to build before installing headers for a
-# subproject
-# AFTER_INSTALLHDRS: targets to build after installing headers for a subproject
-# BEFORE_INSTALLSRC: targets to build before installing source for a subproject
-# AFTER_INSTALLSRC: targets to build after installing source for a subproject
-#
-# BEFORE_DEPEND: targets to build before building dependencies for a
-# subproject
-# AFTER_DEPEND: targets to build after building dependencies for a
-# subproject
-#
-# AUTOMATIC_DEPENDENCY_INFO: if YES, then the dependency file is
-# updated every time the project is built. If NO, the dependency
-# file is only built when the depend target is invoked.
-
-# Framework-related variables:
-# FRAMEWORK_DLL_INSTALLDIR: On Windows platforms, this variable indicates
-# where to put the framework's DLL. This variable defaults to
-# $(INSTALLDIR)/../Executables
-
-# Library-related variables:
-# PUBLIC_HEADER_DIR: Determines where public exported header files
-# should be installed. Do not include $(DSTROOT) in this value --
-# it is prefixed automatically.
-# PRIVATE_HEADER_DIR: Determines where private exported header files
-# should be installed. Do not include $(DSTROOT) in this value --
-# it is prefixed automatically.
-# LIBRARY_STYLE: This may be either STATIC or DYNAMIC, and determines
-# whether the libraries produced are statically linked when they
-# are used or if they are dynamically loadable. <<default?>>
-# LIBRARY_DLL_INSTALLDIR: On Windows platforms, this variable indicates
-# where to put the library's DLL. This variable defaults to
-# $(INSTALLDIR)/../Executables
-#
-# INSTALL_AS_USER: owner of the intalled products (default root)
-# INSTALL_AS_GROUP: group of the installed products (default wheel)
-# INSTALL_PERMISSION: permissions of the installed product (default o+rX)
-#
-# OTHER_RECURSIVE_VARIABLES: The names of variables which you want to be
-# passed on the command line to recursive invocations of make. Note that
-# the values in OTHER_*FLAGS are inherited by subprojects automatically --
-# you do not have to (and shouldn't) add OTHER_*FLAGS to
-# OTHER_RECURSIVE_VARIABLES.
-
-# Additional headers to export beyond those in the PB.project:
-# OTHER_PUBLIC_HEADERS
-# OTHER_PROJECT_HEADERS
-# OTHER_PRIVATE_HEADERS
-
-# Additional files for the project's product: <<path relative to proj?>>
-# OTHER_RESOURCES: (non-localized) resources for this project
-# OTHER_OFILES: relocatables to be linked into this project
-# OTHER_LIBS: more libraries to link against
-# OTHER_PRODUCT_DEPENDS: other dependencies of this project
-# OTHER_SOURCEFILES: other source files maintained by .pre/postamble
-# OTHER_GARBAGE: additional files to be removed by `make clean'
-
-#OTHER_LIBS += -lkernload
-
-# Set this to YES if you don't want a final libtool call for a library/framework.
-# BUILD_OFILES_LIST_ONLY
-
-# To include a version string, project source must exist in a directory named
-# $(NAME).%d[.%d][.%d] and the following line must be uncommented.
-OTHER_GENERATED_OFILES = $(VERS_OFILE)
-
-# This definition will suppress stripping of debug symbols when an executable
-# is installed. By default it is YES.
-# STRIP_ON_INSTALL = NO
-
-AFTER_INSTALL += buildContentsDir
+++ /dev/null
-{
- DYNAMIC_CODE_GEN = YES;
- FILESTABLE = {
- BUNDLES = ();
- CLASSES = ();
- C_FILES = ();
- FRAMEWORKS = (CoreFoundation.framework);
- FRAMEWORKSEARCH = ();
- H_FILES = ();
- M_FILES = ();
- OTHER_LINKED = (hfsutil_main.c hfsutil_jnl.c);
- OTHER_SOURCES = (
- Makefile.preamble,
- Makefile,
- Makefile.postamble,
- hfs_CD.fs.tiff,
- hfs_CD.openfs.tiff,
- hfs_FD.fs.tiff,
- hfs_FD.openfs.tiff,
- hfs_HD.fs.tiff,
- hfs_HD.openfs.tiff,
- hfs_RHD.fs.tiff,
- hfs_RHD.openfs.tiff,
- Info.plist,
- InfoPlist.strings,
- PkgInfo,
- version.plist,
- hfs.util.8
- );
- PRECOMPILED_HEADERS = ();
- PROJECT_HEADERS = ();
- PUBLIC_HEADERS = ();
- SUBPROJECTS = ();
- TOOLS = ();
- };
- LANGUAGE = English;
- LOCALIZABLE_FILES = {};
- MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles";
- NEXTSTEP_BUILDTOOL = /bin/gnumake;
- NEXTSTEP_INSTALLDIR = "$(SYSTEM_LIBRARY_DIR)/Filesystems/hfs.fs";
- NEXTSTEP_JAVA_COMPILER = /usr/bin/javac;
- NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc;
- PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make;
- PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac";
- PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc";
- PROJECTNAME = hfs.util;
- PROJECTTYPE = Tool;
- PROJECTVERSION = 2.8;
- WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make;
- WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe";
- WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc";
-}
/*
- * Copyright (c) 1999-2008 Apple Inc. All rights reserved.
+ * Copyright (c) 1999-2009 Apple Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
buff = (char *)malloc(blksize);
if (pread(fd, buff, blksize, HFS_PRI_SECTOR(blksize)*blksize) != blksize) {
- fprintf(stderr, "failed to read volume header @ offset %d (%s)\n",
- HFS_PRI_SECTOR(blksize), strerror(errno));
- ret = -1;
- goto out;
+ fprintf(stderr, "failed to read volume header @ offset %d (%s)\n",
+ HFS_PRI_SECTOR(blksize), strerror(errno));
+ ret = -1;
+ goto out;
}
- mdbp = (HFSMasterDirectoryBlock *)buff;
- if ( (SWAP_BE16(mdbp->drSigWord) != kHFSSigWord)
- && (SWAP_BE16(mdbp->drSigWord) != kHFSPlusSigWord)
- && (SWAP_BE16(mdbp->drSigWord) != kHFSXSigWord)) {
- ret = -1;
- goto out;
- }
+ mdbp = (HFSMasterDirectoryBlock *)(buff + HFS_PRI_OFFSET(blksize));
+ if ( (SWAP_BE16(mdbp->drSigWord) != kHFSSigWord)
+ && (SWAP_BE16(mdbp->drSigWord) != kHFSPlusSigWord)
+ && (SWAP_BE16(mdbp->drSigWord) != kHFSXSigWord)) {
+ printf ("get_embedded_offset: invalid volume signature \n");
+ ret = -1;
+ goto out;
+ }
if ((SWAP_BE16(mdbp->drSigWord) == kHFSSigWord) && (SWAP_BE16(mdbp->drEmbedSigWord) != kHFSPlusSigWord)) {
ret = -1;
goto out;
}
- if (blksize == 512) {
- mdbp = (HFSMasterDirectoryBlock *)buff;
- } else {
- mdbp = (HFSMasterDirectoryBlock *)(buff + 1024);
+ mdbp = (HFSMasterDirectoryBlock *)(buff + HFS_PRI_OFFSET(blksize));
+
+ if ( (SWAP_BE16(mdbp->drSigWord) != kHFSSigWord)
+ && (SWAP_BE16(mdbp->drSigWord) != kHFSPlusSigWord)
+ && (SWAP_BE16(mdbp->drSigWord) != kHFSXSigWord)) {
+ ret = -1;
+ printf("get_journal_info: invalid volume signature\n");
+ goto out;
}
mdbp->drSigWord = SWAP_BE16(mdbp->drSigWord);
mdbp->drEmbedExtent.startBlock = SWAP_BE16(mdbp->drEmbedExtent.startBlock);
mdbp->drAlBlkSiz = SWAP_BE32(mdbp->drAlBlkSiz);
mdbp->drEmbedExtent.blockCount = SWAP_BE16(mdbp->drEmbedExtent.blockCount);
-
- // first check if it's even hfs at all...
- if ( mdbp->drSigWord != kHFSSigWord
- && mdbp->drSigWord != kHFSPlusSigWord
- && mdbp->drSigWord != kHFSXSigWord) {
- ret = -1;
- goto out;
- }
if ((mdbp->drSigWord == kHFSSigWord) && (mdbp->drEmbedSigWord != kHFSPlusSigWord)) {
// normal hfs can not ever be journaled
goto out;
}
- vhp = (HFSPlusVolumeHeader*) buff;
+ vhp = (HFSPlusVolumeHeader*) (buff + HFS_PRI_OFFSET(blksize));
+
+ mdbp = (HFSMasterDirectoryBlock *)vhp;
+ if ( (SWAP_BE16(mdbp->drSigWord) != kHFSSigWord)
+ && (SWAP_BE16(mdbp->drSigWord) != kHFSPlusSigWord)
+ && (SWAP_BE16(mdbp->drSigWord) != kHFSXSigWord)) {
+ ret = -1;
+
+ printf("get_journal_info: invalid embedded volume signature \n");
+ goto out;
+ }
+
} else /* pure HFS+ */ {
embeddedOffset = 0;
vhp = (HFSPlusVolumeHeader*) mdbp;
hdr_offset = HFS_PRI_SECTOR(blksize)*blksize;
if (pread(fd, buff, blksize, hdr_offset) != blksize) {
- fprintf(stderr, "failed to read volume header @ offset %lld (%s)\n",
- hdr_offset, strerror(errno));
- ret = -1;
- goto out;
+ fprintf(stderr, "RawDisableJournaling: failed to read volume header @ offset %lld (%s)\n",
+ hdr_offset, strerror(errno));
+ ret = -1;
+ goto out;
}
- // if we read in an empty bunch of junk at location zero, then
- // retry at offset 0x400 which is where the header normally is.
- if (*(int *)buff == 0 && hdr_offset == 0) {
- hdr_offset = 0x400;
- if (pread(fd, buff, blksize, hdr_offset) != blksize) {
- fprintf(stderr, "failed to read volume header @ offset %lld (%s)\n",
- hdr_offset, strerror(errno));
- ret = -1;
- goto out;
+ mdbp = (HFSMasterDirectoryBlock *)(buff + HFS_PRI_OFFSET(blksize));
+ if ( (SWAP_BE16(mdbp->drSigWord) != kHFSSigWord)
+ && (SWAP_BE16(mdbp->drSigWord) != kHFSPlusSigWord)
+ && (SWAP_BE16(mdbp->drSigWord) != kHFSXSigWord)) {
+ ret = -1;
+ printf("RawDisableJournaling: Invalid Volume Signature \n");
+ goto out;
}
- }
-
-
-
- mdbp = (HFSMasterDirectoryBlock *)buff;
+
if ((SWAP_BE16(mdbp->drSigWord) == kHFSSigWord) && (SWAP_BE16(mdbp->drEmbedSigWord) != kHFSPlusSigWord)) {
// normal hfs can not ever be journaled
fprintf(stderr, "disable_journaling: volume is only regular HFS, not HFS+\n");
/* Get the embedded Volume Header */
if (SWAP_BE16(mdbp->drEmbedSigWord) == kHFSPlusSigWord) {
- embeddedOffset = SWAP_BE16(mdbp->drAlBlSt) * 512;
- embeddedOffset += (u_int64_t)SWAP_BE16(mdbp->drEmbedExtent.startBlock) * (u_int64_t)SWAP_BE32(mdbp->drAlBlkSiz);
-
- /*
- * If the embedded volume doesn't start on a block
- * boundary, then switch the device to a 512-byte
- * block size so everything will line up on a block
- * boundary.
- */
- if ((embeddedOffset % blksize) != 0) {
- fprintf(stderr, "HFS Mount: embedded volume offset not"
- " a multiple of physical block size (%d);"
- " switching to 512\n", blksize);
+ embeddedOffset = SWAP_BE16(mdbp->drAlBlSt) * 512;
+ embeddedOffset += (u_int64_t)SWAP_BE16(mdbp->drEmbedExtent.startBlock) * (u_int64_t)SWAP_BE32(mdbp->drAlBlkSiz);
+
+ /*
+ * If the embedded volume doesn't start on a block
+ * boundary, then switch the device to a 512-byte
+ * block size so everything will line up on a block
+ * boundary.
+ */
+ if ((embeddedOffset % blksize) != 0) {
+ fprintf(stderr, "HFS Mount: embedded volume offset not"
+ " a multiple of physical block size (%d);"
+ " switching to 512\n", blksize);
+
+ blkcnt *= (blksize / 512);
+ blksize = 512;
+ }
+
+ disksize = (u_int64_t)SWAP_BE16(mdbp->drEmbedExtent.blockCount) * (u_int64_t)SWAP_BE32(mdbp->drAlBlkSiz);
+
+ mdb_offset = (embeddedOffset / blksize) + HFS_PRI_SECTOR(blksize);
+ hdr_offset = mdb_offset * blksize;
+ if (pread(fd, buff, blksize, hdr_offset) != blksize) {
+ fprintf(stderr, "failed to read the embedded vhp @ offset %d\n", mdb_offset * blksize);
+ ret = -1;
+ goto out;
+ }
+
+ vhp = (HFSPlusVolumeHeader*) (buff + HFS_PRI_OFFSET(blksize));
+
+ mdbp = (HFSMasterDirectoryBlock *)vhp;
+ if ( (SWAP_BE16(mdbp->drSigWord) != kHFSSigWord)
+ && (SWAP_BE16(mdbp->drSigWord) != kHFSPlusSigWord)
+ && (SWAP_BE16(mdbp->drSigWord) != kHFSXSigWord)) {
+ ret = -1;
+
+ printf("RawDisableJournaling: invalid embedded volume signature \n");
+ goto out;
+ }
- blkcnt *= (blksize / 512);
- blksize = 512;
- }
-
- disksize = (u_int64_t)SWAP_BE16(mdbp->drEmbedExtent.blockCount) * (u_int64_t)SWAP_BE32(mdbp->drAlBlkSiz);
-
- mdb_offset = (embeddedOffset / blksize) + HFS_PRI_SECTOR(blksize);
- hdr_offset = mdb_offset * blksize;
- if (pread(fd, buff, blksize, hdr_offset) != blksize) {
- fprintf(stderr, "failed to read the embedded vhp @ offset %d\n", mdb_offset * blksize);
- ret = -1;
- goto out;
- }
-
- vhp = (HFSPlusVolumeHeader*) buff;
} else /* pure HFS+ */ {
- embeddedOffset = 0;
- vhp = (HFSPlusVolumeHeader*) mdbp;
+ embeddedOffset = 0;
+ vhp = (HFSPlusVolumeHeader*) mdbp;
}
if ((SWAP_BE32(vhp->attributes) & kHFSVolumeJournaledMask) != 0) {
- unsigned int tmp = SWAP_BE32(vhp->attributes);
-
- tmp &= ~kHFSVolumeJournaledMask;
- vhp->attributes = SWAP_BE32(tmp);
- if ((tmp = pwrite(fd, buff, blksize, hdr_offset)) != blksize) {
- fprintf(stderr, "Update of super-block on %s failed! (%d != %d, %s)\n",
- devname, tmp, blksize, strerror(errno));
- } else {
- fprintf(stderr, "Turned off the journaling bit for %s\n", devname);
- }
+ unsigned int tmp = SWAP_BE32(vhp->attributes);
+
+ tmp &= ~kHFSVolumeJournaledMask;
+ vhp->attributes = SWAP_BE32(tmp);
+ if ((tmp = pwrite(fd, buff, blksize, hdr_offset)) != blksize) {
+ fprintf(stderr, "Update of super-block on %s failed! (%d != %d, %s)\n",
+ devname, tmp, blksize, strerror(errno));
+ } else {
+ fprintf(stderr, "Turned off the journaling bit for %s\n", devname);
+ }
} else {
- fprintf(stderr, "disable_journaling: %s is not journaled.\n", devname);
+ fprintf(stderr, "disable_journaling: %s is not journaled.\n", devname);
}
-
+
out:
if (buff)
goto out;
}
- if (blksize == 512) {
- mdbp = (HFSMasterDirectoryBlock *)buff;
- } else {
- mdbp = (HFSMasterDirectoryBlock *)(buff + 1024);
- }
+ mdbp = (HFSMasterDirectoryBlock *)(buff + HFS_PRI_OFFSET(blksize));
- // first check if it's even hfs at all...
- if ( SWAP_BE16(mdbp->drSigWord) != kHFSSigWord
- && SWAP_BE16(mdbp->drSigWord) != kHFSPlusSigWord
- && SWAP_BE16(mdbp->drSigWord) != kHFSXSigWord) {
- ret = -1;
- goto out;
+ if ( (SWAP_BE16(mdbp->drSigWord) != kHFSSigWord)
+ && (SWAP_BE16(mdbp->drSigWord) != kHFSPlusSigWord)
+ && (SWAP_BE16(mdbp->drSigWord) != kHFSXSigWord)) {
+ ret = -1;
+ printf ("SetJournalInFSState: Invalid Volume Signature \n");
+ goto out;
}
if ((SWAP_BE16(mdbp->drSigWord) == kHFSSigWord) && (SWAP_BE16(mdbp->drEmbedSigWord) != kHFSPlusSigWord)) {
goto out;
}
- vhp = (HFSPlusVolumeHeader*) buff;
+ vhp = (HFSPlusVolumeHeader*) (buff + HFS_PRI_OFFSET(blksize));
+
+ mdbp = (HFSMasterDirectoryBlock *)(vhp);
+ if ( (SWAP_BE16(mdbp->drSigWord) != kHFSSigWord)
+ && (SWAP_BE16(mdbp->drSigWord) != kHFSPlusSigWord)
+ && (SWAP_BE16(mdbp->drSigWord) != kHFSXSigWord)) {
+ ret = -1;
+ printf("SetJournalInFSState: Invalid Embedded Volume Signature \n");
+ goto out;
+ }
+
+
} else /* pure HFS+ */ {
embeddedOffset = 0;
vhp = (HFSPlusVolumeHeader*) mdbp;
/* ************************************ P R O T O T Y P E S *************************************** */
static void DoDisplayUsage( const char * argv[] );
-static int DoMount( char * theDeviceNamePtr, const char * theMountPointPtr, boolean_t isLocked, boolean_t isSetuid, boolean_t isDev );
+static int DoMount( char * theDeviceNamePtr, const char *rawName, const char * theMountPointPtr,
+ boolean_t isLocked, boolean_t isSetuid, boolean_t isDev );
static int DoProbe( char * rawDeviceNamePtr, char * blockDeviceNamePtr );
static int DoUnmount( const char * theMountPointPtr );
-static int DoGetUUIDKey( const char * theDeviceNamePtr );
+static int DoGetUUIDKey( const char * theDeviceNamePtr, const char *rawName );
static int DoChangeUUIDKey( const char * theDeviceNamePtr );
-static int DoAdopt( const char * theDeviceNamePtr );
-static int DoDisown( const char * theDeviceNamePtr );
+static int DoAdopt( const char * theDeviceNamePtr, const char *rawName);
+static int DoDisown( const char * theDeviceNamePtr, const char *rawName);
extern int DoMakeJournaled( const char * volNamePtr, int journalSize ); // XXXdbg
extern int DoUnJournal( const char * volNamePtr ); // XXXdbg
static int GetHFSMountPoint(const char *deviceNamePtr, char **pathPtr);
static int ReadHeaderBlock(int fd, void *bufptr, off_t *startOffset, VolumeUUID **finderInfoUUIDPtr);
-static int GetVolumeUUIDRaw(const char *deviceNamePtr, VolumeUUID *volumeUUIDPtr);
+static int GetVolumeUUIDRaw(const char *deviceNamePtr, const char *rawName, VolumeUUID *volumeUUIDPtr);
static int GetVolumeUUIDAttr(const char *path, VolumeUUID *volumeUUIDPtr);
-static int GetVolumeUUID(const char *deviceNamePtr, VolumeUUID *volumeUUIDPtr, boolean_t generate);
+static int GetVolumeUUID(const char *deviceNamePtr, const char *rawName, VolumeUUID *volumeUUIDPtr, boolean_t generate);
static int SetVolumeUUIDRaw(const char *deviceNamePtr, VolumeUUID *volumeUUIDPtr);
static int SetVolumeUUIDAttr(const char *path, VolumeUUID *volumeUUIDPtr);
static int SetVolumeUUID(const char *deviceNamePtr, VolumeUUID *volumeUUIDPtr);
case FSUC_MOUNT:
case FSUC_MOUNT_FORCE:
- result = DoMount(blockDeviceName, mountPointPtr, isLocked, isSetuid, isDev);
+ result = DoMount(blockDeviceName, rawDeviceName, mountPointPtr, isLocked, isSetuid, isDev);
break;
case FSUC_UNMOUNT:
result = DoUnmount( mountPointPtr );
break;
case FSUC_GETUUID:
- result = DoGetUUIDKey( blockDeviceName );
+ result = DoGetUUIDKey( blockDeviceName, rawDeviceName);
break;
case FSUC_SETUUID:
result = DoChangeUUIDKey( blockDeviceName );
break;
case FSUC_ADOPT:
- result = DoAdopt( blockDeviceName );
+ result = DoAdopt( blockDeviceName, rawDeviceName);
break;
case FSUC_DISOWN:
- result = DoDisown( blockDeviceName );
+ result = DoDisown( blockDeviceName, rawDeviceName );
break;
case FSUC_MKJNL:
returns FSUR_IO_SUCCESS everything is cool else one of several other FSUR_xyz error codes.
*********************************************************************** */
static int
-DoMount(char *deviceNamePtr, const char *mountPointPtr, boolean_t isLocked, boolean_t isSetuid, boolean_t isDev)
+DoMount(char *deviceNamePtr, const char *rawName, const char *mountPointPtr,
+ boolean_t isLocked, boolean_t isSetuid, boolean_t isDev)
{
int pid;
char *isLockedstr;
/* get the volume UUID to check if permissions should be used: */
targetVolumeStatus = 0;
- if (((result = GetVolumeUUID(deviceNamePtr, &targetVolumeUUID, FALSE)) != FSUR_IO_SUCCESS) ||
+ if (((result = GetVolumeUUID(deviceNamePtr, rawName, &targetVolumeUUID, FALSE)) != FSUR_IO_SUCCESS) ||
(targetVolumeUUID.v.high ==0) ||
(targetVolumeUUID.v.low == 0)) {
#if TRACE_HFS_UTIL
#endif
#if AUTO_ADOPT_FIXED
if (gIsEjectable == 0) {
- result = DoAdopt( deviceNamePtr );
+ result = DoAdopt( deviceNamePtr, rawName);
#if TRACE_HFS_UTIL
fprintf(stderr, "hfs.util: DoMount: Auto-adopting %s; result = %d.\n", deviceNamePtr, result);
#endif
#endif
#if AUTO_ENTER_FIXED
if (gIsEjectable == 0) {
- result = DoAdopt( deviceNamePtr );
+ result = DoAdopt( deviceNamePtr, rawName );
#if TRACE_HFS_UTIL
fprintf(stderr, "hfs.util: DoMount: Auto-adopting %s; result = %d.\n", deviceNamePtr, result);
#endif
returns FSUR_IO_SUCCESS or else one of the FSUR_xyz error codes.
*************************************************************************************************** */
static int
-DoGetUUIDKey( const char * theDeviceNamePtr ) {
+DoGetUUIDKey( const char * theDeviceNamePtr, const char *rawName) {
int result;
VolumeUUID targetVolumeUUID;
uuid_t uuid;
unsigned char rawUUID[8];
- if ((result = GetVolumeUUID(theDeviceNamePtr, &targetVolumeUUID, FALSE)) != FSUR_IO_SUCCESS) goto Err_Exit;
+ if ((result = GetVolumeUUID(theDeviceNamePtr, rawName, &targetVolumeUUID, FALSE)) != FSUR_IO_SUCCESS) goto Err_Exit;
((uint32_t *)rawUUID)[0] = OSSwapHostToBigInt32(targetVolumeUUID.v.high);
((uint32_t *)rawUUID)[1] = OSSwapHostToBigInt32(targetVolumeUUID.v.low);
returns FSUR_IO_SUCCESS or else one of the FSUR_xyz error codes.
*************************************************************************************************** */
static int
-DoAdopt( const char * theDeviceNamePtr ) {
+DoAdopt( const char * theDeviceNamePtr, const char *rawName) {
int result, closeresult;
VolumeUUID targetVolumeUUID;
VolumeStatusDBHandle vsdbhandle = NULL;
unsigned long targetVolumeStatus;
- if ((result = GetVolumeUUID(theDeviceNamePtr, &targetVolumeUUID, TRUE)) != FSUR_IO_SUCCESS) goto Err_Return;
+ if ((result = GetVolumeUUID(theDeviceNamePtr, rawName, &targetVolumeUUID, TRUE)) != FSUR_IO_SUCCESS) goto Err_Return;
if ((result = OpenVolumeStatusDB(&vsdbhandle)) != 0) goto Err_Exit;
if ((result = GetVolumeStatusDBEntry(vsdbhandle, &targetVolumeUUID, &targetVolumeStatus)) != 0) {
returns FSUR_IO_SUCCESS or else one of the FSUR_xyz error codes.
*************************************************************************************************** */
static int
-DoDisown( const char * theDeviceNamePtr ) {
+DoDisown( const char * theDeviceNamePtr, const char *rawName) {
int result, closeresult;
VolumeUUID targetVolumeUUID;
VolumeStatusDBHandle vsdbhandle = NULL;
unsigned long targetVolumeStatus;
- if ((result = GetVolumeUUID(theDeviceNamePtr, &targetVolumeUUID, TRUE)) != FSUR_IO_SUCCESS) goto Err_Return;
+ if ((result = GetVolumeUUID(theDeviceNamePtr, rawName, &targetVolumeUUID, TRUE)) != FSUR_IO_SUCCESS) goto Err_Return;
if ((result = OpenVolumeStatusDB(&vsdbhandle)) != 0) goto Err_Exit;
if ((result = GetVolumeStatusDBEntry(vsdbhandle, &targetVolumeUUID, &targetVolumeStatus)) != 0) {
Returns: FSUR_IO_SUCCESS, FSUR_IO_FAIL, FSUR_UNRECOGNIZED
*/
static int
-GetVolumeUUIDRaw(const char *deviceNamePtr, VolumeUUID *volumeUUIDPtr)
+GetVolumeUUIDRaw(const char *deviceNamePtr, const char *rawName, VolumeUUID *volumeUUIDPtr)
{
int fd = 0;
char * bufPtr;
off_t startOffset;
VolumeUUID *finderInfoUUIDPtr;
int result;
+ int error;
bufPtr = (char *)malloc(HFS_BLOCK_SIZE);
if ( ! bufPtr ) {
fd = open( deviceNamePtr, O_RDONLY, 0);
if (fd <= 0) {
+ error = errno;
#if TRACE_HFS_UTIL
- fprintf(stderr, "hfs.util: GetVolumeUUIDRaw: device open failed (errno = %d).\n", errno);
+ fprintf(stderr, "hfs.util: GetVolumeUUIDRaw: device (%s) open failed (errno = %d).\n", deviceNamePtr, errno);
#endif
- result = FSUR_IO_FAIL;
- goto Err_Exit;
+ if (error == EBUSY) {
+ /* If it was busy, then retry, this time using the raw device */
+ fd = open (rawName, O_RDONLY, 0);
+ if (fd <= 0) {
+#if TRACE_HFS_UTIL
+ fprintf(stderr, "hfs.util: GetVolumeUUIDRaw: device (%s) open failed (errno = %d).\n", rawName, errno);
+#endif
+ result = FSUR_IO_FAIL;
+ goto Err_Exit;
+ }
+ }
+ else {
+ result = FSUR_IO_FAIL;
+ goto Err_Exit;
+ }
}
/*
*/
static int
-GetVolumeUUID(const char *deviceNamePtr, VolumeUUID *volumeUUIDPtr, boolean_t generate)
+GetVolumeUUID(const char *deviceNamePtr, const char *rawName, VolumeUUID *volumeUUIDPtr, boolean_t generate)
{
int result;
char *path = NULL;
if (path)
result = GetVolumeUUIDAttr(path, volumeUUIDPtr);
else
- result = GetVolumeUUIDRaw(deviceNamePtr, volumeUUIDPtr);
+ result = GetVolumeUUIDRaw(deviceNamePtr, rawName, volumeUUIDPtr);
if (result != FSUR_IO_SUCCESS)
goto Err_Exit;
if ((OSSwapBigToHostInt16(k->nodeName.length) >
(sizeof(k->nodeName.unicode) / sizeof(k->nodeName.unicode[0]))) ||
- OSSwapBigToHostInt16(k->nodeName.length) < 0) {
+ OSSwapBigToHostInt16(k->nodeName.length) > 255) {
result = FSUR_IO_FAIL;
#if TRACE_HFS_UTIL
fprintf(stderr, "hfs.util: ERROR: k->nodeName.length is a bad size (%d)\n", OSSwapBigToHostInt16(k->nodeName.length));