/*-
* Copyright (c) 2005, 2007 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Yevgeny Binder, Dieter Baron, and Pelle Johansson.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#if 0
#pragma mark -
#pragma mark Custom Types
#endif
typedef struct {
hfs_volume_header_t vh; /* volume header */
hfs_header_record_t chr; /* catalog file header node record*/
hfs_header_record_t ehr; /* extent overflow file header node record*/
uint8_t catkeysizefieldsize; /* size of catalog file key_len field in
* bytes (1 or 2); always 2 for HFS+ */
uint8_t extkeysizefieldsize; /* size of extent file key_len field in
* bytes (1 or 2); always 2 for HFS+ */
hfs_unistr255_t name; /* volume name */
/* pointer to catalog file key comparison function */
int (*keycmp) (const void*, const void*);
int journaled; /* 1 if volume is journaled, else 0 */
hfs_journal_info_t jib; /* journal info block */
hfs_journal_header_t jh; /* journal header */
uint64_t offset; /* offset, in bytes, of HFS+ volume */
int readonly; /* 0 if mounted r/w, 1 if mounted r/o */
void* cbdata; /* application-specific data; allocated, defined and
* used (if desired) by the program, usually within
* callback routines */
} hfs_volume;
typedef union {
/* for leaf nodes */
int16_t type; /* type of record: folder, file, or thread */
hfs_folder_record_t folder;
hfs_file_record_t file;
hfs_thread_record_t thread;
/* for pointer nodes */
/* (using this large union for just one tiny field is not memory-efficient,
* so change this if it becomes problematic) */
uint32_t child; /* node number of this node's child node */
} hfs_catalog_keyed_record_t;
/*
* These arguments are passed among libhfs without any inspection. This struct
* is accepted by all public functions of libhfs, and passed to each callback.
* An application dereferences each pointer to its own specific struct of
* arguments. Callbacks must be prepared to deal with NULL values for any of
* these fields (by providing default values to be used in lieu of that
* argument). However, a NULL pointer to this struct is an error.
*
* It was decided to make one unified argument structure, rather than many
* separate, operand-specific structures, because, when this structure is passed
* to a public function (e.g., hfslib_open_volume()), the function may make
* several calls (and subcalls) to various facilities, e.g., read(), malloc(),
* and free(), all of which require their own particular arguments. The
* facilities to be used are quite impractical to foreshadow, so the application
* takes care of all possible calls at once. This also reinforces the idea that
* a public call is an umbrella to a set of system calls, and all of these calls
* must be passed arguments which do not change within the context of this
* umbrella. (E.g., if a public function makes two calls to read(), one call
* should not be passed a uid of root and the other passed a uid of daemon.)
*/
typedef struct {
/* The 'error' function does not take an argument. All others do. */
int hfslib_compare_catalog_keys_cf(const void*, const void*);
int hfslib_compare_catalog_keys_bc(const void*, const void*);
int hfslib_compare_extent_keys(const void*, const void*);