X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/c910b4d9d2451126ae3917b931cd4390c11e1d52..2dced7af2b695f87fe26496a3e73c219b7880cbc:/bsd/hfs/hfs.h diff --git a/bsd/hfs/hfs.h b/bsd/hfs/hfs.h index f3c12bb41..b19e23208 100644 --- a/bsd/hfs/hfs.h +++ b/bsd/hfs/hfs.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2007 Apple Inc. All rights reserved. + * Copyright (c) 2000-2015 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * @@ -29,12 +29,22 @@ #ifndef __HFS__ #define __HFS__ +/* If set to 1, enables the code to allocate blocks from the start + * of the disk instead of the nextAllocation for sparse devices like + * sparse disk images or sparsebundle images. The free extent cache + * for such volumes is also maintained based on the start block instead + * of number of contiguous allocation blocks. These devices prefer + * allocation of blocks near the start of the disk to avoid the + * increasing the image size, but it can also result in file fragmentation. + */ #define HFS_SPARSE_DEV 1 -#ifdef DEBUG +#if DEBUG #define HFS_CHECK_LOCK_ORDER 1 #endif +#define HFS_TMPDBG 0 + #include #ifdef KERNEL @@ -46,6 +56,8 @@ #include #include #include +#include +#include #include @@ -57,6 +69,14 @@ #include #include #include +#include + +#if CONFIG_PROTECT +/* Forward declare the cprotect struct */ +struct cprotect; + + +#endif /* * Just reported via MIG interface. @@ -90,6 +110,9 @@ extern struct timezone gTimeZone; /* How many free extents to cache per volume */ #define kMaxFreeExtents 10 +/* The maximum time hfs locks can be held while performing hfs statistics gathering */ +#define HFS_FSINFO_MAX_LOCKHELD_TIME 20 * 1000000ULL /* at most 20 milliseconds. */ + /* * HFS_MINFREE gives the minimum acceptable percentage * of file system blocks which may be free (but this @@ -99,6 +122,7 @@ extern struct timezone gTimeZone; */ #define HFS_MINFREE 1 #define HFS_MAXRESERVE ((u_int64_t)(250*1024*1024)) +#define HFS_BT_MAXRESERVE ((u_int64_t)(10*1024*1024)) /* * The system distinguishes between the desirable low-disk @@ -107,15 +131,19 @@ extern struct timezone gTimeZone; * volume size, all capped at a certain fixed level */ -#define HFS_ROOTLOWDISKTRIGGERFRACTION 5 -#define HFS_ROOTLOWDISKTRIGGERLEVEL ((u_int64_t)(250*1024*1024)) -#define HFS_ROOTLOWDISKSHUTOFFFRACTION 6 -#define HFS_ROOTLOWDISKSHUTOFFLEVEL ((u_int64_t)(375*1024*1024)) - -#define HFS_LOWDISKTRIGGERFRACTION 1 -#define HFS_LOWDISKTRIGGERLEVEL ((u_int64_t)(50*1024*1024)) -#define HFS_LOWDISKSHUTOFFFRACTION 2 -#define HFS_LOWDISKSHUTOFFLEVEL ((u_int64_t)(75*1024*1024)) +#define HFS_ROOTVERYLOWDISKTRIGGERFRACTION 5 +#define HFS_ROOTVERYLOWDISKTRIGGERLEVEL ((u_int64_t)(512*1024*1024)) +#define HFS_ROOTLOWDISKTRIGGERFRACTION 10 +#define HFS_ROOTLOWDISKTRIGGERLEVEL ((u_int64_t)(1024*1024*1024)) +#define HFS_ROOTLOWDISKSHUTOFFFRACTION 11 +#define HFS_ROOTLOWDISKSHUTOFFLEVEL ((u_int64_t)(1024*1024*1024 + 250*1024*1024)) + +#define HFS_VERYLOWDISKTRIGGERFRACTION 1 +#define HFS_VERYLOWDISKTRIGGERLEVEL ((u_int64_t)(100*1024*1024)) +#define HFS_LOWDISKTRIGGERFRACTION 2 +#define HFS_LOWDISKTRIGGERLEVEL ((u_int64_t)(150*1024*1024)) +#define HFS_LOWDISKSHUTOFFFRACTION 3 +#define HFS_LOWDISKSHUTOFFLEVEL ((u_int64_t)(200*1024*1024)) /* Internal Data structures*/ @@ -125,8 +153,20 @@ typedef struct hfsmount { /* Physical Description */ u_int32_t hfs_logical_block_size; /* Logical block size of the disk as reported by ioctl(DKIOCGETBLOCKSIZE), always a multiple of 512 */ - daddr64_t hfs_logical_block_count; /* Number of logical blocks on the disk */ - daddr64_t hfs_alt_id_sector; /* location of alternate VH/MDB */ + daddr64_t hfs_logical_block_count; /* Number of logical blocks on the disk, as reported by ioctl(DKIOCGETBLOCKCOUNT) */ + u_int64_t hfs_logical_bytes; /* Number of bytes on the disk device this HFS is mounted on (blockcount * blocksize) */ + /* + * Regarding the two AVH sector fields below: + * Under normal circumstances, the filesystem's notion of the "right" location for the AVH is such that + * the partition and filesystem's are in sync. However, during a filesystem resize, HFS proactively + * writes a new AVH at the end of the filesystem, assuming that the partition will be resized accordingly. + * + * However, it is not technically a corruption if the partition size is never modified. As a result, we need + * to keep two copies of the AVH around "just in case" the partition size is not modified. + */ + daddr64_t hfs_partition_avh_sector; /* location of Alt VH w.r.t partition size */ + daddr64_t hfs_fs_avh_sector; /* location of Alt VH w.r.t filesystem size */ + u_int32_t hfs_physical_block_size; /* Physical block size of the disk as reported by ioctl(DKIOCGETPHYSICALBLOCKSIZE) */ u_int32_t hfs_log_per_phys; /* Number of logical blocks per physical block size */ @@ -152,14 +192,17 @@ typedef struct hfsmount { gid_t hfs_gid; /* gid to set as owner of the files */ mode_t hfs_dir_mask; /* mask to and with directory protection bits */ mode_t hfs_file_mask; /* mask to and with file protection bits */ - u_long hfs_encoding; /* Default encoding for non hfs+ volumes */ + u_int32_t hfs_encoding; /* Default encoding for non hfs+ volumes */ /* Persistent fields (on disk, dynamic) */ time_t hfs_mtime; /* file system last modification time */ u_int32_t hfs_filecount; /* number of files in file system */ u_int32_t hfs_dircount; /* number of directories in file system */ - u_int32_t freeBlocks; /* free allocation blocks */ + u_int32_t freeBlocks; /* free allocation blocks */ + u_int32_t reclaimBlocks; /* number of blocks we are reclaiming during resize */ + u_int32_t tentativeBlocks; /* tentative allocation blocks -- see note below */ u_int32_t nextAllocation; /* start of next allocation search */ + u_int32_t sparseAllocation; /* start of allocations for sparse devices */ u_int32_t vcbNxtCNID; /* next unused catalog node ID - protected by catalog lock */ u_int32_t vcbWrCnt; /* file system write count */ u_int64_t encodingsBitmap; /* in-use encodings */ @@ -168,11 +211,18 @@ typedef struct hfsmount { /* Persistent fields (on disk, static) */ u_int16_t vcbSigWord; - int16_t vcbFlags; /* Runtime flag to indicate if volume is dirty/clean */ + + // Volume will be inconsistent if header is not flushed + bool hfs_header_dirty; + + // Volume header is dirty, but won't be inconsistent if not flushed + bool hfs_header_minor_change; + u_int32_t vcbAtrb; u_int32_t vcbJinfoBlock; - time_t hfs_itime; /* file system creation time */ - time_t hfs_btime; /* file system last backup time */ + u_int32_t localCreateDate;/* volume create time from volume header (For HFS+, value is in local time) */ + time_t hfs_itime; /* file system creation time (creation date of the root folder) */ + time_t hfs_btime; /* file system last backup time */ u_int32_t blockSize; /* size of allocation blocks */ u_int32_t totalBlocks; /* total allocation blocks */ u_int32_t allocLimit; /* Do not allocate this block or beyond */ @@ -197,11 +247,19 @@ typedef struct hfsmount { /* cache of largest known free extents */ u_int32_t vcbFreeExtCnt; HFSPlusExtentDescriptor vcbFreeExt[kMaxFreeExtents]; + lck_spin_t vcbFreeExtLock; + + /* Summary Table */ + u_int8_t *hfs_summary_table; /* Each bit is 1 vcbVBMIOSize of bitmap, byte indexed */ + u_int32_t hfs_summary_size; /* number of BITS in summary table defined above (not bytes!) */ + u_int32_t hfs_summary_bytes; /* number of BYTES in summary table */ + u_int32_t scan_var; /* For initializing the summary table */ + + u_int32_t reserveBlocks; /* free block reserve */ u_int32_t loanedBlocks; /* blocks on loan for delayed allocations */ - - u_int32_t localCreateDate; /* creation times for HFS+ volumes are in local time */ + u_int32_t lockedBlocks; /* blocks reserved and locked */ /* * HFS+ Private system directories (two). Any access @@ -219,17 +277,19 @@ typedef struct hfsmount { struct quotafile hfs_qfiles[MAXQUOTAS]; /* quota files */ /* Journaling variables: */ - void *jnl; // the journal for this volume (if one exists) + struct journal *jnl; // the journal for this volume (if one exists) struct vnode *jvp; // device where the journal lives (may be equal to devvp) u_int32_t jnl_start; // start block of the journal file (so we don't delete it) u_int32_t jnl_size; u_int32_t hfs_jnlfileid; u_int32_t hfs_jnlinfoblkid; - lck_rw_t hfs_global_lock; - u_int32_t hfs_global_lock_nesting; - + lck_rw_t hfs_global_lock; + thread_t hfs_global_lockowner; + u_int32_t hfs_transaction_nesting; + /* Notification variables: */ - unsigned long hfs_notification_conditions; + u_int32_t hfs_notification_conditions; + u_int32_t hfs_freespace_notify_dangerlimit; u_int32_t hfs_freespace_notify_warninglimit; u_int32_t hfs_freespace_notify_desiredlevel; @@ -242,7 +302,11 @@ typedef struct hfsmount { u_int32_t hfs_metazone_end; u_int32_t hfs_hotfile_start; u_int32_t hfs_hotfile_end; + u_int32_t hfs_min_alloc_start; + u_int32_t hfs_freed_block_count; + u_int64_t hfs_cs_hotfile_size; // in bytes int hfs_hotfile_freeblks; + int hfs_hotfile_blk_adjust; int hfs_hotfile_maxblks; int hfs_overflow_maxblks; int hfs_catalog_maxblks; @@ -253,31 +317,118 @@ typedef struct hfsmount { time_t hfc_timebase; /* recording period start time */ time_t hfc_timeout; /* recording period stop time */ void * hfc_recdata; /* recording data (opaque) */ - int hfc_maxfiles; /* maximum files to track */ + uint32_t hfc_maxfiles; /* maximum files to track */ struct vnode * hfc_filevp; -#ifdef HFS_SPARSE_DEV +#if HFS_SPARSE_DEV /* Sparse device variables: */ struct vnode * hfs_backingfs_rootvp; u_int32_t hfs_last_backingstatfs; - int hfs_sparsebandblks; + u_int32_t hfs_sparsebandblks; + u_int64_t hfs_backingfs_maxblocks; #endif size_t hfs_max_inline_attrsize; lck_mtx_t hfs_mutex; /* protects access to hfsmount data */ - void *hfs_freezing_proc; /* who froze the fs */ - void *hfs_downgrading_proc; /* process who's downgrading to rdonly */ - lck_rw_t hfs_insync; /* protects sync/freeze interaction */ + + uint32_t hfs_syncers; // Count of the number of syncers running + enum { + HFS_THAWED, + HFS_WANT_TO_FREEZE, // This state stops hfs_sync from starting + HFS_FREEZING, // We're in this state whilst we're flushing + HFS_FROZEN // Everything gets blocked in hfs_lock_global + } hfs_freeze_state; + union { + /* + * When we're freezing (HFS_FREEZING) but not yet + * frozen (HFS_FROZEN), we record the freezing thread + * so that we stop other threads from taking locks, + * but allow the freezing thread. + */ + const struct thread *hfs_freezing_thread; + /* + * Once we have frozen (HFS_FROZEN), we record the + * process so that if it dies, we can automatically + * unfreeze. + */ + proc_t hfs_freezing_proc; + }; + + thread_t hfs_downgrading_thread; /* thread who's downgrading to rdonly */ /* Resize variables: */ - u_int32_t hfs_resize_filesmoved; - u_int32_t hfs_resize_totalfiles; + u_int32_t hfs_resize_blocksmoved; + u_int32_t hfs_resize_totalblocks; + u_int32_t hfs_resize_progress; +#if CONFIG_PROTECT + /* Data Protection fields */ + cpx_t hfs_resize_cpx; + u_int16_t hfs_running_cp_major_vers; + uint32_t default_cp_class; /* default effective class value */ + uint64_t cproot_flags; + uint8_t cp_crypto_generation; + uint8_t hfs_cp_lock_state; /* per-mount device lock state info */ +#if HFS_TMPDBG +#if !SECURE_KERNEL + boolean_t hfs_cp_verbose; +#endif +#endif + +#endif + + /* Per mount cnode hash variables: */ + lck_mtx_t hfs_chash_mutex; /* protects access to cnode hash table */ + u_long hfs_cnodehash; /* size of cnode hash table - 1 */ + LIST_HEAD(cnodehashhead, cnode) *hfs_cnodehashtbl; /* base of cnode hash */ + + /* Per mount fileid hash variables (protected by catalog lock!) */ + u_long hfs_idhash; /* size of cnid/fileid hash table -1 */ + LIST_HEAD(idhashhead, cat_preflightid) *hfs_idhashtbl; /* base of ID hash */ + + // Records the oldest outstanding sync request + struct timeval hfs_sync_req_oldest; + + // Records whether a sync has been queued or is in progress + boolean_t hfs_sync_incomplete; + + thread_call_t hfs_syncer; // removeable devices get sync'ed by this guy + + /* Records the syncer thread so that we can avoid the syncer + queing more syncs. */ + thread_t hfs_syncer_thread; + + // Not currently used except for debugging purposes + uint32_t hfs_active_threads; + + enum { + // These are indices into the array below + + // Tentative ranges can be claimed back at any time + HFS_TENTATIVE_BLOCKS = 0, + + // Locked ranges cannot be claimed back, but the allocation + // won't have been written to disk yet + HFS_LOCKED_BLOCKS = 1, + }; + // These lists are not sorted like a range list usually is + struct rl_head hfs_reserved_ranges[2]; } hfsmount_t; +/* + * HFS_META_DELAY is a duration (in usecs) used for triggering the + * hfs_syncer() routine. We will back off if writes are in + * progress, but... + * HFS_MAX_META_DELAY is the maximum time we will allow the + * syncer to be delayed. + */ +enum { + HFS_META_DELAY = 100 * 1000, // 0.1 secs + HFS_MAX_META_DELAY = 5000 * 1000 // 5 secs +}; + typedef hfsmount_t ExtendedVCB; /* Aliases for legacy (Mac OS 9) field names */ -#define vcbCrDate hfs_itime #define vcbLsMod hfs_mtime #define vcbVolBkUp hfs_btime #define extentsRefNum hfs_extents_vp @@ -286,28 +437,40 @@ typedef hfsmount_t ExtendedVCB; #define vcbFilCnt hfs_filecount #define vcbDirCnt hfs_dircount -/* Inline functions to set/reset vcbFlags. Upper 8 bits indicate if the volume - * header/VCB is clean/dirty --- if set, volume header is dirty, and - * if clear, volume header is clean. This value is checked to determine - * if the in-memory copy of volume header should be flushed to the disk - * or not. - */ -/* Set runtime flag to indicate that volume is dirty */ -static __inline__ void MarkVCBDirty(ExtendedVCB *vcb) +static inline void MarkVCBDirty(hfsmount_t *hfsmp) { - vcb->vcbFlags |= 0xFF00; + hfsmp->hfs_header_dirty = true; +} + +static inline void MarkVCBClean(hfsmount_t *hfsmp) +{ + hfsmp->hfs_header_dirty = false; + hfsmp->hfs_header_minor_change = false; +} + +static inline bool IsVCBDirty(ExtendedVCB *vcb) +{ + return vcb->hfs_header_minor_change || vcb->hfs_header_dirty; } -/* Clear runtime flag to indicate that volume is dirty */ -static __inline__ void MarkVCBClean(ExtendedVCB *vcb) +// Header is changed but won't be inconsistent if we don't write it +static inline void hfs_note_header_minor_change(hfsmount_t *hfsmp) { - vcb->vcbFlags &= 0x00FF; + hfsmp->hfs_header_minor_change = true; } -/* Check runtime flag to determine if the volume is dirty or not */ -static __inline__ Boolean IsVCBDirty(ExtendedVCB *vcb) +// Must header be flushed for volume to be consistent? +static inline bool hfs_header_needs_flushing(hfsmount_t *hfsmp) { - return (vcb->vcbFlags & 0xFF00 ? true : false); + return (hfsmp->hfs_header_dirty + || ISSET(hfsmp->hfs_catalog_cp->c_flag, C_MODIFIED) + || ISSET(hfsmp->hfs_extents_cp->c_flag, C_MODIFIED) + || (hfsmp->hfs_attribute_cp + && ISSET(hfsmp->hfs_attribute_cp->c_flag, C_MODIFIED)) + || (hfsmp->hfs_allocation_cp + && ISSET(hfsmp->hfs_allocation_cp->c_flag, C_MODIFIED)) + || (hfsmp->hfs_startup_cp + && ISSET(hfsmp->hfs_startup_cp->c_flag, C_MODIFIED))); } /* @@ -318,6 +481,8 @@ static __inline__ Boolean IsVCBDirty(ExtendedVCB *vcb) */ enum privdirtype {FILE_HARDLINKS, DIR_HARDLINKS}; +#define HFS_ALLOCATOR_SCAN_INFLIGHT 0x0001 /* scan started */ +#define HFS_ALLOCATOR_SCAN_COMPLETED 0x0002 /* initial scan was completed */ /* HFS mount point flags */ #define HFS_READ_ONLY 0x00001 @@ -336,6 +501,7 @@ enum privdirtype {FILE_HARDLINKS, DIR_HARDLINKS}; #define HFS_CREATING_BTREE 0x02000 /* When set, do not update nextAllocation in the mount structure */ #define HFS_SKIP_UPDATE_NEXT_ALLOCATION 0x04000 +/* When set, the file system supports extent-based extended attributes */ #define HFS_XATTR_EXTENTS 0x08000 #define HFS_FOLDERCOUNT 0x10000 /* When set, the file system exists on a virtual device, like disk image */ @@ -343,9 +509,18 @@ enum privdirtype {FILE_HARDLINKS, DIR_HARDLINKS}; /* When set, we're in hfs_changefs, so hfs_sync should do nothing. */ #define HFS_IN_CHANGEFS 0x40000 /* When set, we are in process of downgrading or have downgraded to read-only, - * so hfs_start_transaction should return EROFS. */ + * so hfs_start_transaction should return EROFS. + */ #define HFS_RDONLY_DOWNGRADE 0x80000 - +#define HFS_DID_CONTIG_SCAN 0x100000 +#define HFS_UNMAP 0x200000 +#define HFS_SSD 0x400000 +#define HFS_SUMMARY_TABLE 0x800000 +#define HFS_CS 0x1000000 +#define HFS_CS_METADATA_PIN 0x2000000 +#define HFS_CS_HOTFILE_PIN 0x4000000 /* cooperative fusion (enables a hotfile variant) */ +#define HFS_FEATURE_BARRIER 0x8000000 /* device supports barrier-only flush */ +#define HFS_CS_SWAPFILE_PIN 0x10000000 /* Macro to update next allocation block in the HFS mount structure. If * the HFS_SKIP_UPDATE_NEXT_ALLOCATION is set, do not update @@ -357,21 +532,6 @@ enum privdirtype {FILE_HARDLINKS, DIR_HARDLINKS}; hfsmp->nextAllocation = new_nextAllocation; \ } \ -#define HFS_MOUNT_LOCK(hfsmp, metadata) \ - { \ - if ((metadata) && 1) \ - lck_mtx_lock(&(hfsmp)->hfs_mutex); \ - } \ - -#define HFS_MOUNT_UNLOCK(hfsmp, metadata) \ - { \ - if ((metadata) && 1) \ - lck_mtx_unlock(&(hfsmp)->hfs_mutex); \ - } \ - -#define hfs_global_exclusive_lock_acquire(hfsmp) lck_rw_lock_exclusive(&(hfsmp)->hfs_global_lock) -#define hfs_global_exclusive_lock_release(hfsmp) lck_rw_unlock_exclusive(&(hfsmp)->hfs_global_lock) - /* Macro for incrementing and decrementing the folder count in a cnode * attribute only if the HFS_FOLDERCOUNT bit is set in the mount flags * and kHFSHasFolderCount bit is set in the cnode flags. Currently these @@ -415,7 +575,7 @@ typedef struct filefork FCB; ((sizeof(struct dirent) - (NAME_MAX+1)) + (((namlen)+1 + 3) &~ 3)) #define EXT_DIRENT_LEN(namlen) \ - ((sizeof(struct direntry) + (namlen) - (MAXPATHLEN-1) + 3) & ~3) + ((sizeof(struct direntry) + (namlen) - (MAXPATHLEN-1) + 7) & ~7) enum { kHFSPlusMaxFileNameBytes = kHFSPlusMaxFileNameChars * 3 }; @@ -450,9 +610,6 @@ enum { kHFSPlusMaxFileNameBytes = kHFSPlusMaxFileNameChars * 3 }; #define FCBTOVCB(FCB) FCBTOHFS(FCB) -#define HFS_KNOTE(vp, hint) KNOTE(&VTOC(vp)->c_knotes, (hint)) - - #define E_NONE 0 #define kHFSBlockSize 512 @@ -473,12 +630,10 @@ enum { kHFSPlusMaxFileNameBytes = kHFSPlusMaxFileNameChars * 3 }; /* * HFS specific fcntl()'s */ -#define HFS_BULKACCESS (FCNTL_FS_SPECIFIC_BASE + 0x00001) -#define HFS_GET_MOUNT_TIME (FCNTL_FS_SPECIFIC_BASE + 0x00002) -#define HFS_GET_LAST_MTIME (FCNTL_FS_SPECIFIC_BASE + 0x00003) #define HFS_GET_BOOT_INFO (FCNTL_FS_SPECIFIC_BASE + 0x00004) #define HFS_SET_BOOT_INFO (FCNTL_FS_SPECIFIC_BASE + 0x00005) -#define HFS_EXT_BULKACCESS (FCNTL_FS_SPECIFIC_BASE + 0x00006) +/* See HFSIOC_EXT_BULKACCESS and friends for HFS specific fsctls*/ + /* @@ -488,20 +643,46 @@ enum { kHFSPlusMaxFileNameBytes = kHFSPlusMaxFileNameChars * 3 }; */ #define MAC_GMT_FACTOR 2082844800UL +static inline __attribute__((const)) +off_t hfs_blk_to_bytes(uint32_t blk, uint32_t blk_size) +{ + return (off_t)blk * blk_size; // Avoid the overflow +} + +/* + * For now, we use EIO to indicate consistency issues. It is safe to + * return or assign an error value to HFS_EINCONSISTENT but it is + * *not* safe to compare against it because EIO can be generated for + * other reasons. We take advantage of the fact that == has + * left-to-right associativity and so any uses of: + * + * if (error == HFS_EINCONSISTENT) + * + * will produce a compiler warning: "comparison between pointer and + * integer". + * + * Note that not everwhere is consistent with the use of + * HFS_EINCONSISTENT. Some places return EINVAL, EIO directly or + * other error codes. + */ +#define HFS_EINCONSISTENT (void *)0 == (void *)0 ? EIO : EIO /***************************************************************************** FUNCTION PROTOTYPES ******************************************************************************/ - /***************************************************************************** hfs_vnop_xxx functions from different files ******************************************************************************/ int hfs_vnop_readdirattr(struct vnop_readdirattr_args *); /* in hfs_attrlist.c */ +int hfs_vnop_getattrlistbulk(struct vnop_getattrlistbulk_args *); /* in hfs_attrlist.c */ int hfs_vnop_inactive(struct vnop_inactive_args *); /* in hfs_cnode.c */ int hfs_vnop_reclaim(struct vnop_reclaim_args *); /* in hfs_cnode.c */ +int hfs_set_backingstore (struct vnode *vp, int val); /* in hfs_cnode.c */ +int hfs_is_backingstore (struct vnode *vp, int *val); /* in hfs_cnode.c */ + int hfs_vnop_link(struct vnop_link_args *); /* in hfs_link.c */ int hfs_vnop_lookup(struct vnop_lookup_args *); /* in hfs_lookup.c */ @@ -520,6 +701,7 @@ int hfs_vnop_bwrite(struct vnop_bwrite_args *); /* in hfs_readwrite.c */ int hfs_vnop_blktooff(struct vnop_blktooff_args *); /* in hfs_readwrite.c */ int hfs_vnop_offtoblk(struct vnop_offtoblk_args *); /* in hfs_readwrite.c */ int hfs_vnop_blockmap(struct vnop_blockmap_args *); /* in hfs_readwrite.c */ +errno_t hfs_flush_invalid_ranges(vnode_t vp); /* in hfs_readwrite.c */ int hfs_vnop_getxattr(struct vnop_getxattr_args *); /* in hfs_xattr.c */ int hfs_vnop_setxattr(struct vnop_setxattr_args *); /* in hfs_xattr.c */ @@ -555,11 +737,12 @@ void hfs_setencodingbias(u_int32_t bias); ******************************************************************************/ void hfs_converterinit(void); +int hfs_relconverter (u_int32_t encoding); + int hfs_getconverter(u_int32_t encoding, hfs_to_unicode_func_t *get_unicode, unicode_to_hfs_func_t *get_hfsname); -int hfs_relconverter(u_int32_t encoding); - +#if CONFIG_HFS_STD int hfs_to_utf8(ExtendedVCB *vcb, const Str31 hfs_str, ByteCount maxDstLen, ByteCount *actualDstLen, unsigned char* dstStr); @@ -574,7 +757,7 @@ int utf8_to_mac_roman(ByteCount srcLen, const unsigned char* srcStr, Str31 dstSt int mac_roman_to_unicode(const Str31 hfs_str, UniChar *uni_str, u_int32_t maxCharLen, u_int32_t *usedCharLen); int unicode_to_hfs(ExtendedVCB *vcb, ByteCount srcLen, u_int16_t* srcStr, Str31 dstStr, int retry); - +#endif /***************************************************************************** Functions from hfs_notifications.c @@ -587,21 +770,49 @@ void hfs_generate_volume_notifications(struct hfsmount *hfsmp); ******************************************************************************/ extern int hfs_relocate(struct vnode *, u_int32_t, kauth_cred_t, struct proc *); -extern int hfs_truncate(struct vnode *, off_t, int, int, vfs_context_t); +/* flags for hfs_pin_block_range() and hfs_pin_vnode() */ +#define HFS_PIN_IT 0x0001 +#define HFS_UNPIN_IT 0x0002 +#define HFS_TEMP_PIN 0x0004 +#define HFS_EVICT_PIN 0x0008 +#define HFS_DATALESS_PIN 0x0010 -extern int hfs_bmap(struct vnode *, daddr_t, struct vnode **, daddr64_t *, unsigned int *); +// +// pin/un-pin an explicit range of blocks to the "fast" (usually ssd) device +// +int hfs_pin_block_range(struct hfsmount *hfsmp, int pin_state, uint32_t start_block, uint32_t nblocks, vfs_context_t ctx); -extern int hfs_fsync(struct vnode *, int, int, struct proc *); +// +// pin/un-pin all the extents belonging to a vnode. +// also, if it is non-null, "num_blocks_pinned" returns the number of blocks pin/unpinned by the function +// +int hfs_pin_vnode(struct hfsmount *hfsmp, struct vnode *vp, int pin_state, uint32_t *num_blocks_pinned, vfs_context_t ctx); -extern int hfs_access(struct vnode *, mode_t, kauth_cred_t, struct proc *); -extern int hfs_removeallattr(struct hfsmount *hfsmp, u_int32_t fileid); +int hfs_pin_overflow_extents (struct hfsmount *hfsmp, uint32_t fileid, uint8_t forktype, uint32_t *pinned); + -extern int hfs_set_volxattr(struct hfsmount *hfsmp, unsigned int xattrtype, int state); +/* Flags for HFS truncate */ +#define HFS_TRUNCATE_SKIPTIMES 0x00000002 /* implied by skipupdate; it is a subset */ + -extern void hfs_check_volxattr(struct hfsmount *hfsmp, unsigned int xattrtype); +extern int hfs_truncate(struct vnode *, off_t, int, int, vfs_context_t); + +extern int hfs_release_storage (struct hfsmount *hfsmp, struct filefork *datafork, + struct filefork *rsrcfork, u_int32_t fileid); -extern int hfs_isallocated(struct hfsmount *, u_long, u_long); +extern int hfs_prepare_release_storage (struct hfsmount *hfsmp, struct vnode *vp); + +extern int hfs_bmap(struct vnode *, daddr_t, struct vnode **, daddr64_t *, unsigned int *); + +extern errno_t hfs_ubc_setsize(vnode_t vp, off_t len, bool have_cnode_lock); + + +/***************************************************************************** + Functions from hfs_resize.c +******************************************************************************/ +int hfs_extendfs(struct hfsmount *hfsmp, u_int64_t newsize, vfs_context_t context); +int hfs_truncatefs(struct hfsmount *hfsmp, u_int64_t newsize, vfs_context_t context); /***************************************************************************** @@ -612,15 +823,20 @@ int hfs_mountroot(mount_t mp, vnode_t rvp, vfs_context_t context); /* used as a callback by the journaling code */ extern void hfs_sync_metadata(void *arg); -extern int hfs_vget(struct hfsmount *, cnid_t, struct vnode **, int); +extern int hfs_vget(struct hfsmount *, cnid_t, struct vnode **, int, int); extern void hfs_setencodingbits(struct hfsmount *hfsmp, u_int32_t encoding); enum volop {VOL_UPDATE, VOL_MKDIR, VOL_RMDIR, VOL_MKFILE, VOL_RMFILE}; extern int hfs_volupdate(struct hfsmount *hfsmp, enum volop op, int inroot); -int hfs_flushvolumeheader(struct hfsmount *hfsmp, int waitfor, int altflush); -#define HFS_ALTFLUSH 1 +enum { + HFS_FVH_WAIT = 0x0001, + HFS_FVH_WRITE_ALT = 0x0002, + HFS_FVH_FLUSH_IF_DIRTY = 0x0004, +}; +typedef uint32_t hfs_flush_volume_header_options_t; +int hfs_flushvolumeheader(struct hfsmount *hfsmp, hfs_flush_volume_header_options_t); extern int hfs_extendfs(struct hfsmount *, u_int64_t, vfs_context_t); extern int hfs_truncatefs(struct hfsmount *, u_int64_t, vfs_context_t); @@ -629,27 +845,66 @@ extern int hfs_resize_progress(struct hfsmount *, u_int32_t *); /* If a runtime corruption is detected, mark the volume inconsistent * bit in the volume attributes. */ -void hfs_mark_volume_inconsistent(struct hfsmount *hfsmp); + +typedef enum { + HFS_INCONSISTENCY_DETECTED, + + // Used when unable to rollback an operation that failed + HFS_ROLLBACK_FAILED, + + // Used when the latter part of an operation failed, but we chose not to roll back + HFS_OP_INCOMPLETE, + + // Used when someone told us to force an fsck on next mount + HFS_FSCK_FORCED, +} hfs_inconsistency_reason_t; + +void hfs_mark_inconsistent(struct hfsmount *hfsmp, + hfs_inconsistency_reason_t reason); + +void hfs_scan_blocks (struct hfsmount *hfsmp); /***************************************************************************** Functions from hfs_vfsutils.c ******************************************************************************/ -unsigned long BestBlockSizeFit(unsigned long allocationBlockSize, - unsigned long blockSizeLimit, - unsigned long baseMultiple); +u_int32_t BestBlockSizeFit(u_int32_t allocationBlockSize, + u_int32_t blockSizeLimit, + u_int32_t baseMultiple); +#if CONFIG_HFS_STD OSErr hfs_MountHFSVolume(struct hfsmount *hfsmp, HFSMasterDirectoryBlock *mdb, struct proc *p); +#endif OSErr hfs_MountHFSPlusVolume(struct hfsmount *hfsmp, HFSPlusVolumeHeader *vhp, off_t embeddedOffset, u_int64_t disksize, struct proc *p, void *args, kauth_cred_t cred); +OSErr hfs_ValidateHFSPlusVolumeHeader(struct hfsmount *hfsmp, HFSPlusVolumeHeader *vhp); + extern int hfsUnmount(struct hfsmount *hfsmp, struct proc *p); -extern int overflow_extents(struct filefork *fp); +extern bool overflow_extents(struct filefork *fp); extern int hfs_owner_rights(struct hfsmount *hfsmp, uid_t cnode_uid, kauth_cred_t cred, struct proc *p, int invokesuperuserstatus); +extern int check_for_tracked_file(struct vnode *vp, time_t ctime, uint64_t op_type, void *arg); +extern int check_for_dataless_file(struct vnode *vp, uint64_t op_type); +extern int hfs_generate_document_id(struct hfsmount *hfsmp, uint32_t *docid); +extern void hfs_pin_fs_metadata(struct hfsmount *hfsmp); + +/* Return information about number of metadata blocks for volume */ +extern int hfs_getinfo_metadata_blocks(struct hfsmount *hfsmp, struct hfsinfo_metadata *hinfo); + +/* + * Journal lock function prototypes + */ +int hfs_lock_global (struct hfsmount *hfsmp, enum hfs_locktype locktype); +void hfs_unlock_global (struct hfsmount *hfsmp); + +/* HFS mount lock/unlock prototypes */ +void hfs_lock_mount (struct hfsmount *hfsmp); +void hfs_unlock_mount (struct hfsmount *hfsmp); + /* HFS System file locking */ #define SFL_CATALOG 0x0001 @@ -657,12 +912,10 @@ extern int hfs_owner_rights(struct hfsmount *hfsmp, uid_t cnode_uid, kauth_cred_ #define SFL_BITMAP 0x0004 #define SFL_ATTRIBUTE 0x0008 #define SFL_STARTUP 0x0010 -#define SFL_VALIDMASK (SFL_CATALOG | SFL_EXTENTS | SFL_BITMAP | SFL_ATTRIBUTE | SFL_STARTUP) - -extern int hfs_systemfile_lock(struct hfsmount *, int, enum hfslocktype); -extern void hfs_systemfile_unlock(struct hfsmount *, int); +#define SFL_VM_PRIV 0x0020 +#define SFL_VALIDMASK (SFL_CATALOG | SFL_EXTENTS | SFL_BITMAP | SFL_ATTRIBUTE | SFL_STARTUP | SFL_VM_PRIV) -extern u_long GetFileInfo(ExtendedVCB *vcb, u_int32_t dirid, const char *name, +extern u_int32_t GetFileInfo(ExtendedVCB *vcb, u_int32_t dirid, const char *name, struct cat_attr *fattr, struct cat_fork *forkinfo); extern void hfs_remove_orphans(struct hfsmount *); @@ -673,6 +926,8 @@ extern u_int32_t hfs_freeblks(struct hfsmount * hfsmp, int wantreserve); short MacToVFSError(OSErr err); +void hfs_metadatazone_init(struct hfsmount *hfsmp, int disable); + /* HFS directory hint functions. */ extern directoryhint_t * hfs_getdirhint(struct cnode *, int, int); extern void hfs_reldirhint(struct cnode *, directoryhint_t *); @@ -689,6 +944,35 @@ extern int hfs_virtualmetafile(struct cnode *); extern int hfs_start_transaction(struct hfsmount *hfsmp); extern int hfs_end_transaction(struct hfsmount *hfsmp); +extern void hfs_journal_lock(struct hfsmount *hfsmp); +extern void hfs_journal_unlock(struct hfsmount *hfsmp); +extern void hfs_syncer_lock(struct hfsmount *hfsmp); +extern void hfs_syncer_unlock(struct hfsmount *hfsmp); +extern void hfs_syncer_wait(struct hfsmount *hfsmp); +extern void hfs_syncer_wakeup(struct hfsmount *hfsmp); +extern void hfs_syncer_queue(thread_call_t syncer); +extern void hfs_sync_ejectable(struct hfsmount *hfsmp); + +typedef enum hfs_flush_mode { + HFS_FLUSH_JOURNAL, // Flush journal + HFS_FLUSH_JOURNAL_META, // Flush journal and metadata blocks + HFS_FLUSH_FULL, // Flush journal and does a cache flush + HFS_FLUSH_CACHE, // Flush track cache to media + HFS_FLUSH_BARRIER, // Barrier-only flush to ensure write order + HFS_FLUSH_JOURNAL_BARRIER // Flush journal with barrier +} hfs_flush_mode_t; + +extern errno_t hfs_flush(struct hfsmount *hfsmp, hfs_flush_mode_t mode); + +extern void hfs_trim_callback(void *arg, uint32_t extent_count, const dk_extent_t *extents); + +/* Erase unused Catalog nodes due to . */ +extern int hfs_erase_unused_nodes(struct hfsmount *hfsmp); + +extern uint64_t hfs_usecs_to_deadline(uint64_t usecs); + +extern int hfs_freeze(struct hfsmount *hfsmp); +extern int hfs_thaw(struct hfsmount *hfsmp, const struct proc *process); /***************************************************************************** @@ -707,18 +991,56 @@ extern int hfs_btsync(struct vnode *vp, int sync_transaction); extern void replace_desc(struct cnode *cp, struct cat_desc *cdp); extern int hfs_vgetrsrc(struct hfsmount *hfsmp, struct vnode *vp, - struct vnode **rvpp, int can_drop_lock); + struct vnode **rvpp); -extern int hfs_update(struct vnode *, int); +typedef enum { + // Push all modifications to disk (including minor ones) + HFS_UPDATE_FORCE = 0x01, +} hfs_update_options_t; +extern int hfs_update(struct vnode *, int options); + +typedef enum hfs_sync_mode { + HFS_FSYNC, + HFS_FSYNC_FULL, + HFS_FSYNC_BARRIER +} hfs_fsync_mode_t; + +extern int hfs_fsync(struct vnode *, int, hfs_fsync_mode_t, struct proc *); + +const struct cat_fork * +hfs_prepare_fork_for_update(filefork_t *ff, + const struct cat_fork *cf, + struct cat_fork *cf_buf, + uint32_t block_size); /***************************************************************************** Functions from hfs_xattr.c ******************************************************************************/ + +/* + * Maximum extended attribute size supported for all extended attributes except + * resource fork and finder info. + */ +#define HFS_XATTR_MAXSIZE INT32_MAX + +/* Number of bits used to represent maximum extended attribute size */ +#define HFS_XATTR_SIZE_BITS 31 + int hfs_attrkeycompare(HFSPlusAttrKey *searchKey, HFSPlusAttrKey *trialKey); int hfs_buildattrkey(u_int32_t fileID, const char *attrname, HFSPlusAttrKey *key); void hfs_xattr_init(struct hfsmount * hfsmp); int file_attribute_exist(struct hfsmount *hfsmp, uint32_t fileID); +int init_attrdata_vnode(struct hfsmount *hfsmp); +int hfs_xattr_read(vnode_t vp, const char *name, void *data, size_t *size); +int hfs_getxattr_internal(cnode_t *, struct vnop_getxattr_args *, + struct hfsmount *, u_int32_t); +int hfs_xattr_write(vnode_t vp, const char *name, const void *data, size_t size); +int hfs_setxattr_internal(struct cnode *, const void *, size_t, + struct vnop_setxattr_args *, struct hfsmount *, u_int32_t); +extern int hfs_removeallattr(struct hfsmount *hfsmp, u_int32_t fileid, + bool *open_transaction); +extern int hfs_set_volxattr(struct hfsmount *hfsmp, unsigned int xattrtype, int state); @@ -728,17 +1050,36 @@ int file_attribute_exist(struct hfsmount *hfsmp, uint32_t fileID); extern int hfs_unlink(struct hfsmount *hfsmp, struct vnode *dvp, struct vnode *vp, struct componentname *cnp, int skip_reserve); -extern int hfs_lookuplink(struct hfsmount *hfsmp, cnid_t linkfileid, +extern int hfs_lookup_siblinglinks(struct hfsmount *hfsmp, cnid_t linkfileid, cnid_t *prevlinkid, cnid_t *nextlinkid); +extern int hfs_lookup_lastlink(struct hfsmount *hfsmp, cnid_t linkfileid, + cnid_t *nextlinkid, struct cat_desc *cdesc); extern void hfs_privatedir_init(struct hfsmount *, enum privdirtype); extern void hfs_savelinkorigin(cnode_t *cp, cnid_t parentcnid); extern void hfs_relorigins(struct cnode *cp); extern void hfs_relorigin(struct cnode *cp, cnid_t parentcnid); extern int hfs_haslinkorigin(cnode_t *cp); -extern cnid_t hfs_currentparent(cnode_t *cp); +extern cnid_t hfs_currentparent(cnode_t *cp, bool have_lock); extern cnid_t hfs_currentcnid(cnode_t *cp); +errno_t hfs_first_link(hfsmount_t *hfsmp, cnode_t *cp, cnid_t *link_id); + + +/***************************************************************************** + Functions from VolumeAllocation.c + ******************************************************************************/ +extern int hfs_isallocated(struct hfsmount *hfsmp, u_int32_t startingBlock, u_int32_t numBlocks); +extern int hfs_count_allocated(struct hfsmount *hfsmp, u_int32_t startBlock, + u_int32_t numBlocks, u_int32_t *alloc_count); + +extern int hfs_isrbtree_active (struct hfsmount *hfsmp); + +/***************************************************************************** + Functions from hfs_fsinfo.c + ******************************************************************************/ +extern errno_t hfs_get_fsinfo(struct hfsmount *hfsmp, void *a_data); +extern void hfs_fsinfo_data_add(struct hfs_fsinfo_data *fsinfo, uint64_t entry); #endif /* __APPLE_API_PRIVATE */ #endif /* KERNEL */