2 * Copyright (c) 2000-2020 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 /* If set to 1, enables the code to allocate blocks from the start
33 * of the disk instead of the nextAllocation for sparse devices like
34 * sparse disk images or sparsebundle images. The free extent cache
35 * for such volumes is also maintained based on the start block instead
36 * of number of contiguous allocation blocks. These devices prefer
37 * allocation of blocks near the start of the disk to avoid the
38 * increasing the image size, but it can also result in file fragmentation.
40 #define HFS_SPARSE_DEV 1
43 #define HFS_CHECK_LOCK_ORDER 1
48 #include <sys/appleapiopts.h>
51 #ifdef __APPLE_API_PRIVATE
52 #include <sys/param.h>
53 #include <sys/queue.h>
54 #include <sys/mount.h>
55 #include <sys/vnode.h>
56 #include <sys/quota.h>
57 #include <sys/dirent.h>
58 #include <sys/event.h>
60 #include <kern/thread_call.h>
61 #include <kern/locks.h>
62 #include <vm/vm_kern.h>
63 #include <sys/sysctl.h>
64 #include <uuid/uuid.h>
66 #include "../hfs_encodings/hfs_encodings.h"
68 #include "hfs_journal.h"
69 #include "hfs_format.h"
70 #include "hfs_catalog.h"
71 #include "hfs_cnode.h"
72 #include "hfs_macos_defs.h"
73 #include "hfs_hotfiles.h"
74 #include "hfs_fsctl.h"
79 /* Forward declare the cprotect struct */
84 * Just reported via MIG interface.
86 #define VERSION_STRING "hfs-2 (4-12-99)"
88 #define HFS_LINK_MAX 32767
90 #define HFS_MAX_DEFERED_ALLOC (1024*1024)
92 #define HFS_MAX_FILES (UINT32_MAX - kHFSFirstUserCatalogNodeID)
94 // 400 megs is a "big" file (i.e. one that when deleted
95 // would touch enough data that we should break it into
96 // multiple separate transactions)
97 #define HFS_BIGFILE_SIZE (400LL * 1024LL * 1024LL)
99 enum { kMDBSize
= 512 }; /* Size of I/O transfer to read entire MDB */
101 enum { kMasterDirectoryBlock
= 2 }; /* MDB offset on disk in 512-byte blocks */
102 enum { kMDBOffset
= kMasterDirectoryBlock
* 512 }; /* MDB offset on disk in bytes */
104 #define kRootDirID kHFSRootFolderID
107 /* number of locked buffer caches to hold for b-tree meta data */
108 #define kMaxLockedMetaBuffers 32
110 extern struct timezone gTimeZone
;
113 /* How many free extents to cache per volume */
114 #define kMaxFreeExtents 10
116 /* Maximum file size that we're willing to defrag on open */
117 #define HFS_MAX_DEFRAG_SIZE 104857600 // 100 * 1024 * 1024 (100MB)
118 #define HFS_INITIAL_DEFRAG_SIZE 20971520 // 20 * 1024 * 1024 (20MB)
121 /* The maximum time hfs locks can be held while performing hfs statistics gathering */
122 #define HFS_FSINFO_MAX_LOCKHELD_TIME 20 * 1000000ULL /* at most 20 milliseconds. */
125 * HFS_MINFREE gives the minimum acceptable percentage
126 * of file system blocks which may be free (but this
127 * minimum will never exceed HFS_MAXRESERVE bytes). If
128 * the free block count drops below this level only the
129 * superuser may continue to allocate blocks.
131 #define HFS_MINFREE 1
132 #define HFS_MAXRESERVE ((u_int64_t)(250*1024*1024))
133 #define HFS_BT_MAXRESERVE ((u_int64_t)(10*1024*1024))
136 * The system distinguishes between the desirable low-disk
137 * notifiaction levels for root volumes and non-root volumes.
138 * The various thresholds are computed as a fraction of the
139 * volume size, all capped at a certain fixed level
142 #define HFS_ROOTVERYLOWDISKTRIGGERFRACTION 5
143 #define HFS_ROOTVERYLOWDISKTRIGGERLEVEL ((u_int64_t)(512*1024*1024))
144 #define HFS_ROOTLOWDISKTRIGGERFRACTION 10
145 #define HFS_ROOTLOWDISKTRIGGERLEVEL ((u_int64_t)(1024*1024*1024))
146 #define HFS_ROOTNEARLOWDISKTRIGGERFRACTION 10.5
147 #define HFS_ROOTNEARLOWDISKTRIGGERLEVEL ((u_int64_t)(1024*1024*1024 + 100*1024*1024))
148 #define HFS_ROOTLOWDISKSHUTOFFFRACTION 11
149 #define HFS_ROOTLOWDISKSHUTOFFLEVEL ((u_int64_t)(1024*1024*1024 + 250*1024*1024))
151 #define HFS_VERYLOWDISKTRIGGERFRACTION 1
152 #define HFS_VERYLOWDISKTRIGGERLEVEL ((u_int64_t)(150*1024*1024))
153 #define HFS_LOWDISKTRIGGERFRACTION 2
154 #define HFS_LOWDISKTRIGGERLEVEL ((u_int64_t)(500*1024*1024))
155 #define HFS_NEARLOWDISKTRIGGERFRACTION 10
156 #define HFS_NEARLOWDISKTRIGGERLEVEL ((uint64_t)(1024*1024*1024))
157 #define HFS_LOWDISKSHUTOFFFRACTION 12
158 #define HFS_LOWDISKSHUTOFFLEVEL ((u_int64_t)(1024*1024*1024 + 200*1024*1024))
160 /* Internal Data structures*/
162 #define NEW_XATTR TARGET_CPU_ARM64
166 // number of concurrent xattr IOs permitted
167 #define XATTR_NUM_FEXTS 64u
168 // bitmap size, in 64bit words, used to track concurrent xattr IOs
169 #define XATTR_BM_SIZE ((XATTR_NUM_FEXTS) / (NBBY * sizeof(uint64_t)))
172 * State for all stream based xattr IO on a volume.
174 * Fixed size thread local storage for use across the IO stack.
178 * A spin lock used to access both the free file extent bitmap, `free_bm',
179 * and the xattr file extents themselves, `xattr_fexts'.
181 * This bitmap represents the unused indices of `xattr_fexts'. The name is
182 * somewhat backwards: set bits (with a value of one) denote *used* indices.
184 * These are references to xattr file extents used as thread local storage to
185 * communicate from top level xattr IO functions, through the cluster layer,
186 * down into lower level IO functions (hfs_vnop_blockmap()).
187 * Each index which contains a non-NULL fext should have its corresponding
188 * bit within `free_bm' set. Though the reverse is not strictly true: a bit
189 * within the bitmap may be set before the corresponding fext is. This is
190 * the case when memory for a file extent reference is preallocated before
191 * the value of the file extent is available.
192 * This is an array of pointers rather than an array of file extents because:
193 * - it avoids both copying a full fext into and out from the array
194 * - it prints more nicely in lldb
198 uint64_t free_bm
[XATTR_BM_SIZE
];
199 const HFSPlusExtentDescriptor
*xattr_fexts
[XATTR_NUM_FEXTS
];
204 /* This structure describes the HFS specific mount structure data. */
205 typedef struct hfsmount
{
206 u_int32_t hfs_flags
; /* see below */
208 /* Physical Description */
209 u_int32_t hfs_logical_block_size
; /* Logical block size of the disk as reported by ioctl(DKIOCGETBLOCKSIZE), always a multiple of 512 */
210 daddr64_t hfs_logical_block_count
; /* Number of logical blocks on the disk, as reported by ioctl(DKIOCGETBLOCKCOUNT) */
211 u_int64_t hfs_logical_bytes
; /* Number of bytes on the disk device this HFS is mounted on (blockcount * blocksize) */
213 * Regarding the two AVH sector fields below:
214 * Under normal circumstances, the filesystem's notion of the "right" location for the AVH is such that
215 * the partition and filesystem's are in sync. However, during a filesystem resize, HFS proactively
216 * writes a new AVH at the end of the filesystem, assuming that the partition will be resized accordingly.
218 * However, it is not technically a corruption if the partition size is never modified. As a result, we need
219 * to keep two copies of the AVH around "just in case" the partition size is not modified.
221 daddr64_t hfs_partition_avh_sector
; /* location of Alt VH w.r.t partition size */
222 daddr64_t hfs_fs_avh_sector
; /* location of Alt VH w.r.t filesystem size */
224 u_int32_t hfs_physical_block_size
; /* Physical block size of the disk as reported by ioctl(DKIOCGETPHYSICALBLOCKSIZE) */
225 u_int32_t hfs_log_per_phys
; /* Number of logical blocks per physical block size */
227 /* Access to VFS and devices */
228 struct mount
*hfs_mp
; /* filesystem vfs structure */
229 struct vnode
*hfs_devvp
; /* block device mounted vnode */
230 struct vnode
* hfs_extents_vp
;
231 struct vnode
* hfs_catalog_vp
;
232 struct vnode
* hfs_allocation_vp
;
233 struct vnode
* hfs_attribute_vp
;
234 struct vnode
* hfs_startup_vp
;
235 struct vnode
* hfs_attrdata_vp
; /* pseudo file */
237 xattr_io_info_t hfs_xattr_io
; /* Note, this is a big structure ~(64 * 8 bytes) */
239 struct cnode
* hfs_extents_cp
;
240 struct cnode
* hfs_catalog_cp
;
241 struct cnode
* hfs_allocation_cp
;
242 struct cnode
* hfs_attribute_cp
;
243 struct cnode
* hfs_startup_cp
;
244 dev_t hfs_raw_dev
; /* device mounted */
245 u_int32_t hfs_logBlockSize
; /* Size of buffer cache buffer for I/O */
247 /* Default values for HFS standard and non-init access */
248 uid_t hfs_uid
; /* uid to set as owner of the files */
249 gid_t hfs_gid
; /* gid to set as owner of the files */
250 mode_t hfs_dir_mask
; /* mask to and with directory protection bits */
251 mode_t hfs_file_mask
; /* mask to and with file protection bits */
252 u_int32_t hfs_encoding
; /* Default encoding for non hfs+ volumes */
254 /* Persistent fields (on disk, dynamic) */
255 time_t hfs_mtime
; /* file system last modification time */
256 u_int32_t hfs_filecount
; /* number of files in file system */
257 u_int32_t hfs_dircount
; /* number of directories in file system */
258 u_int32_t freeBlocks
; /* free allocation blocks */
259 u_int32_t reclaimBlocks
; /* number of blocks we are reclaiming during resize */
260 u_int32_t tentativeBlocks
; /* tentative allocation blocks -- see note below */
261 u_int32_t nextAllocation
; /* start of next allocation search */
262 u_int32_t sparseAllocation
; /* start of allocations for sparse devices */
263 u_int32_t vcbNxtCNID
; /* next unused catalog node ID - protected by catalog lock */
264 u_int32_t vcbWrCnt
; /* file system write count */
265 u_int64_t encodingsBitmap
; /* in-use encodings */
266 u_int16_t vcbNmFls
; /* HFS Only - root dir file count */
267 u_int16_t vcbNmRtDirs
; /* HFS Only - root dir directory count */
269 /* Persistent fields (on disk, static) */
270 u_int16_t vcbSigWord
;
272 // Volume will be inconsistent if header is not flushed
273 bool hfs_header_dirty
;
275 // Volume header is dirty, but won't be inconsistent if not flushed
276 bool hfs_header_minor_change
;
279 u_int32_t vcbJinfoBlock
;
280 u_int32_t localCreateDate
;/* volume create time from volume header (For HFS+, value is in local time) */
281 time_t hfs_itime
; /* file system creation time (creation date of the root folder) */
282 time_t hfs_btime
; /* file system last backup time */
283 u_int32_t blockSize
; /* size of allocation blocks */
284 u_int32_t totalBlocks
; /* total allocation blocks */
285 u_int32_t allocLimit
; /* Do not allocate this block or beyond */
287 * NOTE: When resizing a volume to make it smaller, allocLimit is set to the allocation
288 * block number which will contain the new alternate volume header. At all other times,
289 * allocLimit is set to totalBlocks. The allocation code uses allocLimit instead of
290 * totalBlocks to limit which blocks may be allocated, so that during a resize, we don't
291 * put new content into the blocks we're trying to truncate away.
294 u_int32_t vcbFndrInfo
[8];
295 int16_t vcbVBMSt
; /* HFS only */
296 int16_t vcbAlBlSt
; /* HFS only */
299 u_int8_t vcbVN
[256]; /* volume name in UTF-8 */
300 u_int32_t volumeNameEncodingHint
;
301 u_int32_t hfsPlusIOPosOffset
; /* Disk block where HFS+ starts */
302 u_int32_t vcbVBMIOSize
; /* volume bitmap I/O size */
304 /* cache of largest known free extents */
305 u_int32_t vcbFreeExtCnt
;
306 HFSPlusExtentDescriptor vcbFreeExt
[kMaxFreeExtents
];
307 lck_spin_t vcbFreeExtLock
;
310 u_int8_t
*hfs_summary_table
; /* Each bit is 1 vcbVBMIOSize of bitmap, byte indexed */
311 u_int32_t hfs_summary_size
; /* number of BITS in summary table defined above (not bytes!) */
312 u_int32_t hfs_summary_bytes
; /* number of BYTES in summary table */
314 u_int32_t scan_var
; /* For initializing the summary table */
317 u_int32_t reserveBlocks
; /* free block reserve */
318 u_int32_t loanedBlocks
; /* blocks on loan for delayed allocations */
319 u_int32_t lockedBlocks
; /* blocks reserved and locked */
322 * HFS+ Private system directories (two). Any access
323 * (besides looking at the cd_cnid) requires holding
324 * the Catalog File lock.
326 struct cat_desc hfs_private_desc
[2];
327 struct cat_attr hfs_private_attr
[2];
329 u_int32_t hfs_metadata_createdate
;
331 hfs_to_unicode_func_t hfs_get_unicode
;
332 unicode_to_hfs_func_t hfs_get_hfsname
;
335 /* Quota variables: */
336 struct quotafile hfs_qfiles
[MAXQUOTAS
]; /* quota files */
338 /* Journaling variables: */
339 struct journal
*jnl
; // the journal for this volume (if one exists)
340 struct vnode
*jvp
; // device where the journal lives (may be equal to devvp)
341 u_int32_t jnl_start
; // start block of the journal file (so we don't delete it)
343 u_int32_t hfs_jnlfileid
;
344 u_int32_t hfs_jnlinfoblkid
;
345 lck_rw_t hfs_global_lock
;
346 thread_t hfs_global_lockowner
;
347 u_int32_t hfs_transaction_nesting
;
350 * Notification variables
351 * See comments in hfs mount code for what the
352 * default levels are set to.
354 u_int32_t hfs_notification_conditions
;
355 u_int32_t hfs_freespace_notify_dangerlimit
;
356 u_int32_t hfs_freespace_notify_warninglimit
;
357 u_int32_t hfs_freespace_notify_nearwarninglimit
;
358 u_int32_t hfs_freespace_notify_desiredlevel
;
360 /* time mounted and last mounted mod time "snapshot" */
361 time_t hfs_mount_time
;
362 time_t hfs_last_mounted_mtime
;
364 /* Metadata allocation zone variables: */
365 u_int32_t hfs_metazone_start
;
366 u_int32_t hfs_metazone_end
;
367 u_int32_t hfs_hotfile_start
;
368 u_int32_t hfs_hotfile_end
;
369 u_int32_t hfs_min_alloc_start
;
370 u_int32_t hfs_freed_block_count
;
371 u_int64_t hfs_cs_hotfile_size
; // in bytes
372 int hfs_hotfile_freeblks
;
373 int hfs_hotfile_blk_adjust
; // since we pass this to OSAddAtomic, this needs to be 4-byte aligned
374 int hfs_hotfile_maxblks
;
375 int hfs_overflow_maxblks
;
376 int hfs_catalog_maxblks
;
378 /* Hot File Clustering variables: */
379 lck_mtx_t hfc_mutex
; /* serialize hot file stages */
380 enum hfc_stage hfc_stage
; /* what are we up to... */
381 time_t hfc_timebase
; /* recording period start time */
382 time_t hfc_timeout
; /* recording period stop time */
383 struct hotfile_data
*hfc_recdata
;
384 struct hotfilelist
*hfc_filelist
;
385 uint32_t hfc_maxfiles
; /* maximum files to track */
386 struct vnode
* hfc_filevp
;
388 /* defrag-on-open variables */
389 int hfs_defrag_nowait
; //issue defrags now, regardless of whether or not we've gone past 3 min.
390 uint64_t hfs_defrag_max
; //maximum file size we'll defragment on this mount
393 /* Sparse device variables: */
394 struct vnode
* hfs_backingvp
;
395 u_int32_t hfs_last_backingstatfs
;
396 u_int32_t hfs_sparsebandblks
;
397 u_int64_t hfs_backingfs_maxblocks
;
399 size_t hfs_max_inline_attrsize
;
401 lck_mtx_t hfs_mutex
; /* protects access to hfsmount data */
403 uint32_t hfs_syncers
; // Count of the number of syncers running
406 HFS_WANT_TO_FREEZE
, // This state stops hfs_sync from starting
407 HFS_FREEZING
, // We're in this state whilst we're flushing
408 HFS_FROZEN
// Everything gets blocked in hfs_lock_global
412 * When we're freezing (HFS_FREEZING) but not yet
413 * frozen (HFS_FROZEN), we record the freezing thread
414 * so that we stop other threads from taking locks,
415 * but allow the freezing thread.
417 const struct thread
*hfs_freezing_thread
;
419 * Once we have frozen (HFS_FROZEN), we record the
420 * process so that if it dies, we can automatically
423 proc_t hfs_freezing_proc
;
426 thread_t hfs_downgrading_thread
; /* thread who's downgrading to rdonly */
428 /* Resize variables: */
429 u_int32_t hfs_resize_blocksmoved
;
430 u_int32_t hfs_resize_totalblocks
;
431 u_int32_t hfs_resize_progress
;
433 /* Data Protection fields */
434 cpx_t hfs_resize_cpx
;
435 u_int16_t hfs_running_cp_major_vers
;
436 uint32_t default_cp_class
; /* default effective class value */
437 uint64_t cproot_flags
;
438 uint8_t cp_crypto_generation
;
439 cp_lock_state_t hfs_cp_lock_state
; /* per-mount device lock state info */
440 #if HFS_CONFIG_KEY_ROLL
441 uint32_t hfs_auto_roll_min_key_os_version
;
442 uint32_t hfs_auto_roll_max_key_os_version
;
446 boolean_t hfs_cp_verbose
;
452 /* the full UUID of the volume, not the one stored in finderinfo */
453 uuid_t hfs_full_uuid
;
455 /* Per mount cnode hash variables: */
456 lck_mtx_t hfs_chash_mutex
; /* protects access to cnode hash table */
457 u_long hfs_cnodehash
; /* size of cnode hash table - 1 */
458 LIST_HEAD(cnodehashhead
, cnode
) *hfs_cnodehashtbl
; /* base of cnode hash */
460 /* Per mount fileid hash variables (protected by catalog lock!) */
461 u_long hfs_idhash
; /* size of cnid/fileid hash table -1 */
462 LIST_HEAD(idhashhead
, cat_preflightid
) *hfs_idhashtbl
; /* base of ID hash */
464 // Records the oldest outstanding sync request
465 struct timeval hfs_sync_req_oldest
;
467 /* Records the syncer thread so that we can avoid the syncer
468 queing more syncs. */
469 thread_t hfs_syncer_thread
;
471 // Not currently used except for debugging purposes
472 // Since we pass this to OSAddAtomic, this needs to be 4-byte aligned.
473 uint32_t hfs_active_threads
;
476 // These are indices into the array below
478 // Tentative ranges can be claimed back at any time
479 HFS_TENTATIVE_BLOCKS
= 0,
481 // Locked ranges cannot be claimed back, but the allocation
482 // won't have been written to disk yet
483 HFS_LOCKED_BLOCKS
= 1,
485 // These lists are not sorted like a range list usually is
486 struct rl_head hfs_reserved_ranges
[2];
490 * HFS_META_DELAY is a duration (in usecs) used for triggering the
491 * hfs_syncer() routine. We will back off if writes are in
493 * HFS_MAX_META_DELAY is the maximum time we will allow the
494 * syncer to be delayed.
497 HFS_META_DELAY
= 100 * 1000, // 0.1 secs
498 HFS_MAX_META_DELAY
= 5000 * 1000 // 5 secs
501 #define HFS_META_DELAY_TS \
502 (struct timespec){ 0, HFS_META_DELAY * NSEC_PER_USEC }
504 typedef hfsmount_t ExtendedVCB
;
506 /* Aliases for legacy (Mac OS 9) field names */
507 #define vcbLsMod hfs_mtime
508 #define vcbVolBkUp hfs_btime
509 #define extentsRefNum hfs_extents_vp
510 #define catalogRefNum hfs_catalog_vp
511 #define allocationsRefNum hfs_allocation_vp
512 #define vcbFilCnt hfs_filecount
513 #define vcbDirCnt hfs_dircount
515 static inline void MarkVCBDirty(hfsmount_t
*hfsmp
)
517 hfsmp
->hfs_header_dirty
= true;
520 static inline void MarkVCBClean(hfsmount_t
*hfsmp
)
522 hfsmp
->hfs_header_dirty
= false;
523 hfsmp
->hfs_header_minor_change
= false;
526 static inline bool IsVCBDirty(ExtendedVCB
*vcb
)
528 return vcb
->hfs_header_minor_change
|| vcb
->hfs_header_dirty
;
531 // Header is changed but won't be inconsistent if we don't write it
532 static inline void hfs_note_header_minor_change(hfsmount_t
*hfsmp
)
534 hfsmp
->hfs_header_minor_change
= true;
537 // Must header be flushed for volume to be consistent?
538 static inline bool hfs_header_needs_flushing(hfsmount_t
*hfsmp
)
540 return (hfsmp
->hfs_header_dirty
541 || ISSET(hfsmp
->hfs_catalog_cp
->c_flag
, C_MODIFIED
)
542 || ISSET(hfsmp
->hfs_extents_cp
->c_flag
, C_MODIFIED
)
543 || (hfsmp
->hfs_attribute_cp
544 && ISSET(hfsmp
->hfs_attribute_cp
->c_flag
, C_MODIFIED
))
545 || (hfsmp
->hfs_allocation_cp
546 && ISSET(hfsmp
->hfs_allocation_cp
->c_flag
, C_MODIFIED
))
547 || (hfsmp
->hfs_startup_cp
548 && ISSET(hfsmp
->hfs_startup_cp
->c_flag
, C_MODIFIED
)));
552 * There are two private directories in HFS+.
554 * One contains inodes for files that are hardlinked or open/unlinked.
555 * The other contains inodes for directories that are hardlinked.
557 enum privdirtype
{FILE_HARDLINKS
, DIR_HARDLINKS
};
559 #define HFS_ALLOCATOR_SCAN_INFLIGHT 0x0001 /* scan started */
560 #define HFS_ALLOCATOR_SCAN_COMPLETED 0x0002 /* initial scan was completed */
562 /* HFS mount point flags */
563 #define HFS_READ_ONLY 0x00001
564 #define HFS_UNKNOWN_PERMS 0x00002
565 #define HFS_WRITEABLE_MEDIA 0x00004
566 #define HFS_CLEANED_ORPHANS 0x00008
567 #define HFS_X 0x00010
568 #define HFS_CASE_SENSITIVE 0x00020
569 #define HFS_STANDARD 0x00040
570 #define HFS_METADATA_ZONE 0x00080
571 #define HFS_FRAGMENTED_FREESPACE 0x00100
572 #define HFS_NEED_JNL_RESET 0x00200
573 #define HFS_HAS_SPARSE_DEVICE 0x00400
574 #define HFS_RESIZE_IN_PROGRESS 0x00800
575 #define HFS_QUOTAS 0x01000
576 #define HFS_CREATING_BTREE 0x02000
577 /* When set, do not update nextAllocation in the mount structure */
578 #define HFS_SKIP_UPDATE_NEXT_ALLOCATION 0x04000
579 /* When set, the file system supports extent-based extended attributes */
580 #define HFS_XATTR_EXTENTS 0x08000
581 #define HFS_FOLDERCOUNT 0x10000
582 /* When set, the file system exists on a virtual device, like disk image */
583 #define HFS_VIRTUAL_DEVICE 0x20000
584 /* When set, we're in hfs_changefs, so hfs_sync should do nothing. */
585 #define HFS_IN_CHANGEFS 0x40000
586 /* When set, we are in process of downgrading or have downgraded to read-only,
587 * so hfs_start_transaction should return EROFS.
589 #define HFS_RDONLY_DOWNGRADE 0x80000
590 #define HFS_DID_CONTIG_SCAN 0x100000
591 #define HFS_UNMAP 0x200000
592 #define HFS_SSD 0x400000
593 #define HFS_SUMMARY_TABLE 0x800000
594 #define HFS_CS 0x1000000
595 #define HFS_CS_METADATA_PIN 0x2000000
596 #define HFS_CS_HOTFILE_PIN 0x4000000 /* cooperative fusion (enables a hotfile variant) */
597 #define HFS_FEATURE_BARRIER 0x8000000 /* device supports barrier-only flush */
598 #define HFS_CS_SWAPFILE_PIN 0x10000000
599 #define HFS_RUN_SYNCER 0x20000000
601 /* Macro to update next allocation block in the HFS mount structure. If
602 * the HFS_SKIP_UPDATE_NEXT_ALLOCATION is set, do not update
603 * nextAllocation block.
605 #define HFS_UPDATE_NEXT_ALLOCATION(hfsmp, new_nextAllocation) \
607 if ((hfsmp->hfs_flags & HFS_SKIP_UPDATE_NEXT_ALLOCATION) == 0)\
608 hfsmp->nextAllocation = new_nextAllocation; \
611 /* Macro for incrementing and decrementing the folder count in a cnode
612 * attribute only if the HFS_FOLDERCOUNT bit is set in the mount flags
613 * and kHFSHasFolderCount bit is set in the cnode flags. Currently these
614 * bits are only set for case sensitive HFS+ volumes.
616 #define INC_FOLDERCOUNT(hfsmp, cattr) \
617 if ((hfsmp->hfs_flags & HFS_FOLDERCOUNT) && \
618 (cattr.ca_recflags & kHFSHasFolderCountMask)) { \
619 cattr.ca_dircount++; \
622 #define DEC_FOLDERCOUNT(hfsmp, cattr) \
623 if ((hfsmp->hfs_flags & HFS_FOLDERCOUNT) && \
624 (cattr.ca_recflags & kHFSHasFolderCountMask) && \
625 (cattr.ca_dircount > 0)) { \
626 cattr.ca_dircount--; \
629 typedef struct filefork FCB;
632 * Macros for creating item names for our special/private directories.
634 #define MAKE_INODE_NAME(name, size, linkno) \
635 (void) snprintf((name), size, "%s%d", HFS_INODE_PREFIX, (linkno))
636 #define HFS_INODE_PREFIX_LEN 5
638 #define MAKE_DIRINODE_NAME(name, size, linkno) \
639 (void) snprintf((name), size, "%s%d", HFS_DIRINODE_PREFIX, (linkno))
640 #define HFS_DIRINODE_PREFIX_LEN 4
642 #define MAKE_DELETED_NAME(NAME, size, FID) \
643 (void) snprintf((NAME), size, "%s%d", HFS_DELETE_PREFIX, (FID))
644 #define HFS_DELETE_PREFIX_LEN 4
647 #define HFS_AVERAGE_NAME_SIZE 22
648 #define AVERAGE_HFSDIRENTRY_SIZE (8+HFS_AVERAGE_NAME_SIZE+4)
650 #define STD_DIRENT_LEN(namlen) \
651 ((sizeof(struct dirent) - (NAME_MAX+1)) + (((namlen)+1 + 3) &~ 3))
653 #define EXT_DIRENT_LEN(namlen) \
654 ((sizeof(struct direntry) + (namlen) - (MAXPATHLEN-1) + 7) & ~7)
657 enum { kHFSPlusMaxFileNameBytes
= kHFSPlusMaxFileNameChars
* 3 };
660 /* macro to determine if hfs or hfsplus */
661 #define ISHFSPLUS(VCB) ((VCB)->vcbSigWord == kHFSPlusSigWord)
662 #define ISHFS(VCB) ((VCB)->vcbSigWord == kHFSSigWord)
666 * Various ways to acquire a VFS mount point pointer:
668 #define VTOVFS(VP) vnode_mount((VP))
669 #define HFSTOVFS(HFSMP) ((HFSMP)->hfs_mp)
670 #define VCBTOVFS(VCB) HFSTOVFS(VCB)
673 * Various ways to acquire an HFS mount point pointer:
675 #define VTOHFS(VP) ((struct hfsmount *)vfs_fsprivate(vnode_mount((VP))))
676 #define VFSTOHFS(MP) ((struct hfsmount *)vfs_fsprivate((MP)))
677 #define VCBTOHFS(VCB) (VCB)
678 #define FCBTOHFS(FCB) ((struct hfsmount *)vfs_fsprivate(vnode_mount((FCB)->ff_cp->c_vp)))
681 * Various ways to acquire a VCB (legacy) pointer:
683 #define VTOVCB(VP) VTOHFS(VP)
684 #define VFSTOVCB(MP) VFSTOHFS(MP)
685 #define HFSTOVCB(HFSMP) (HFSMP)
686 #define FCBTOVCB(FCB) FCBTOHFS(FCB)
690 #define kHFSBlockSize 512
693 * Macros for getting the MDB/VH sector and offset
695 #define HFS_PRI_SECTOR(blksize) (1024 / (blksize))
696 #define HFS_PRI_OFFSET(blksize) ((blksize) > 1024 ? 1024 : 0)
698 #define HFS_ALT_SECTOR(blksize, blkcnt) (((blkcnt) - 1) - (512 / (blksize)))
699 #define HFS_ALT_OFFSET(blksize) ((blksize) > 1024 ? (blksize) - 1024 : 0)
701 /* Convert the logical sector number to be aligned on physical block size boundary.
702 * We are assuming the partition is a multiple of physical block size.
704 #define HFS_PHYSBLK_ROUNDDOWN(sector_num, log_per_phys) ((sector_num / log_per_phys) * log_per_phys)
707 * HFS specific fcntl()'s
709 #define HFS_GET_BOOT_INFO (FCNTL_FS_SPECIFIC_BASE + 0x00004)
710 #define HFS_SET_BOOT_INFO (FCNTL_FS_SPECIFIC_BASE + 0x00005)
711 /* See HFSIOC_EXT_BULKACCESS and friends for HFS specific fsctls*/
716 * This is the straight GMT conversion constant:
717 * 00:00:00 January 1, 1970 - 00:00:00 January 1, 1904
718 * (3600 * 24 * ((365 * (1970 - 1904)) + (((1970 - 1904) / 4) + 1)))
720 #define MAC_GMT_FACTOR 2082844800UL
722 static inline __attribute__((const))
723 off_t
hfs_blk_to_bytes(uint32_t blk
, uint32_t blk_size
)
725 return (off_t
)blk
* blk_size
; // Avoid the overflow
729 * For now, we use EIO to indicate consistency issues. It is safe to
730 * return or assign an error value to HFS_EINCONSISTENT but it is
731 * *not* safe to compare against it because EIO can be generated for
732 * other reasons. We take advantage of the fact that == has
733 * left-to-right associativity and so any uses of:
735 * if (error == HFS_EINCONSISTENT)
737 * will produce a compiler warning: "comparison between pointer and
740 * Note that not everwhere is consistent with the use of
741 * HFS_EINCONSISTENT. Some places return EINVAL, EIO directly or
744 #define HFS_EINCONSISTENT (void *)0 == (void *)0 ? EIO : EIO
746 #define HFS_ERESERVEDNAME -8
748 extern int (**hfs_specop_p
)(void *);
750 /*****************************************************************************
752 ******************************************************************************/
754 /*****************************************************************************
755 hfs_vnop_xxx functions from different files
756 ******************************************************************************/
757 int hfs_vnop_readdirattr(struct vnop_readdirattr_args
*); /* in hfs_attrlist.c */
758 int hfs_vnop_getattrlistbulk(struct vnop_getattrlistbulk_args
*); /* in hfs_attrlist.c */
760 int hfs_vnop_inactive(struct vnop_inactive_args
*); /* in hfs_cnode.c */
761 int hfs_vnop_reclaim(struct vnop_reclaim_args
*); /* in hfs_cnode.c */
763 int hfs_set_backingstore (struct vnode
*vp
, int val
); /* in hfs_cnode.c */
764 int hfs_is_backingstore (struct vnode
*vp
, int *val
); /* in hfs_cnode.c */
766 int hfs_vnop_link(struct vnop_link_args
*); /* in hfs_link.c */
768 int hfs_vnop_lookup(struct vnop_lookup_args
*); /* in hfs_lookup.c */
770 int hfs_vnop_search(struct vnop_searchfs_args
*); /* in hfs_search.c */
772 int hfs_vnop_read(struct vnop_read_args
*); /* in hfs_readwrite.c */
773 int hfs_vnop_write(struct vnop_write_args
*); /* in hfs_readwrite.c */
774 int hfs_vnop_ioctl(struct vnop_ioctl_args
*); /* in hfs_readwrite.c */
775 int hfs_vnop_select(struct vnop_select_args
*); /* in hfs_readwrite.c */
776 int hfs_vnop_strategy(struct vnop_strategy_args
*); /* in hfs_readwrite.c */
777 int hfs_vnop_allocate(struct vnop_allocate_args
*); /* in hfs_readwrite.c */
778 int hfs_vnop_pagein(struct vnop_pagein_args
*); /* in hfs_readwrite.c */
779 int hfs_vnop_pageout(struct vnop_pageout_args
*); /* in hfs_readwrite.c */
780 int hfs_vnop_bwrite(struct vnop_bwrite_args
*); /* in hfs_readwrite.c */
781 int hfs_vnop_blktooff(struct vnop_blktooff_args
*); /* in hfs_readwrite.c */
782 int hfs_vnop_offtoblk(struct vnop_offtoblk_args
*); /* in hfs_readwrite.c */
783 int hfs_vnop_blockmap(struct vnop_blockmap_args
*); /* in hfs_readwrite.c */
784 errno_t
hfs_flush_invalid_ranges(vnode_t vp
); /* in hfs_readwrite.c */
786 int hfs_vnop_getxattr(struct vnop_getxattr_args
*); /* in hfs_xattr.c */
787 int hfs_vnop_setxattr(struct vnop_setxattr_args
*); /* in hfs_xattr.c */
788 int hfs_vnop_removexattr(struct vnop_removexattr_args
*); /* in hfs_xattr.c */
789 int hfs_vnop_listxattr(struct vnop_listxattr_args
*); /* in hfs_xattr.c */
791 extern int hfs_vnop_getnamedstream(struct vnop_getnamedstream_args
*);
792 extern int hfs_vnop_makenamedstream(struct vnop_makenamedstream_args
*);
793 extern int hfs_vnop_removenamedstream(struct vnop_removenamedstream_args
*);
797 /*****************************************************************************
798 Functions from MacOSStubs.c
799 ******************************************************************************/
800 time_t to_bsd_time(u_int32_t hfs_time
);
802 u_int32_t
to_hfs_time(time_t bsd_time
);
805 /*****************************************************************************
806 Functions from hfs_notifications.c
807 ******************************************************************************/
808 void hfs_generate_volume_notifications(struct hfsmount
*hfsmp
);
811 /*****************************************************************************
812 Functions from hfs_readwrite.c
813 ******************************************************************************/
814 extern int hfs_relocate(struct vnode
*, u_int32_t
, kauth_cred_t
, struct proc
*);
816 /* flags for hfs_pin_block_range() and hfs_pin_vnode() */
817 #define HFS_PIN_IT 0x0001
818 #define HFS_UNPIN_IT 0x0002
819 #define HFS_TEMP_PIN 0x0004
820 #define HFS_EVICT_PIN 0x0008
821 #define HFS_DATALESS_PIN 0x0010
824 // pin/un-pin an explicit range of blocks to the "fast" (usually ssd) device
826 int hfs_pin_block_range(struct hfsmount
*hfsmp
, int pin_state
, uint32_t start_block
, uint32_t nblocks
);
829 // pin/un-pin all the extents belonging to a vnode.
830 // also, if it is non-null, "num_blocks_pinned" returns the number of blocks pin/unpinned by the function
832 int hfs_pin_vnode(struct hfsmount
*hfsmp
, struct vnode
*vp
, int pin_state
, uint32_t *num_blocks_pinned
);
835 int hfs_pin_overflow_extents (struct hfsmount
*hfsmp
, uint32_t fileid
, uint8_t forktype
, uint32_t *pinned
);
838 /* Flags for HFS truncate */
839 #define HFS_TRUNCATE_SKIPTIMES 0x00000002 /* implied by skipupdate; it is a subset */
842 extern int hfs_truncate(struct vnode
*, off_t
, int, int, vfs_context_t
);
844 extern int hfs_release_storage (struct hfsmount
*hfsmp
, struct filefork
*datafork
,
845 struct filefork
*rsrcfork
, u_int32_t fileid
);
847 extern int hfs_prepare_release_storage (struct hfsmount
*hfsmp
, struct vnode
*vp
);
849 extern int hfs_bmap(struct vnode
*, daddr_t
, struct vnode
**, daddr64_t
*, unsigned int *);
851 extern errno_t
hfs_ubc_setsize(vnode_t vp
, off_t len
, bool have_cnode_lock
);
854 /*****************************************************************************
855 Functions from hfs_resize.c
856 ******************************************************************************/
857 int hfs_extendfs(struct hfsmount
*hfsmp
, u_int64_t newsize
, vfs_context_t context
);
858 int hfs_truncatefs(struct hfsmount
*hfsmp
, u_int64_t newsize
, vfs_context_t context
);
861 /*****************************************************************************
862 Functions from hfs_vfsops.c
863 ******************************************************************************/
865 extern void hfs_getvoluuid(struct hfsmount
*hfsmp
, uuid_t result
);
867 /* used as a callback by the journaling code */
868 extern void hfs_sync_metadata(void *arg
);
870 extern int hfs_vget(struct hfsmount
*, cnid_t
, struct vnode
**, int, int);
872 extern void hfs_setencodingbits(struct hfsmount
*hfsmp
, u_int32_t encoding
);
874 enum volop
{VOL_UPDATE
, VOL_MKDIR
, VOL_RMDIR
, VOL_MKFILE
, VOL_RMFILE
};
875 extern int hfs_volupdate(struct hfsmount
*hfsmp
, enum volop op
, int inroot
);
878 HFS_FVH_WAIT
= 0x0001,
879 HFS_FVH_WRITE_ALT
= 0x0002,
880 HFS_FVH_FLUSH_IF_DIRTY
= 0x0004,
882 typedef uint32_t hfs_flush_volume_header_options_t
;
883 int hfs_flushvolumeheader(struct hfsmount
*hfsmp
, hfs_flush_volume_header_options_t
);
885 extern int hfs_extendfs(struct hfsmount
*, u_int64_t
, vfs_context_t
);
886 extern int hfs_truncatefs(struct hfsmount
*, u_int64_t
, vfs_context_t
);
887 extern int hfs_resize_progress(struct hfsmount
*, u_int32_t
*);
889 /* If a runtime corruption is detected, mark the volume inconsistent
890 * bit in the volume attributes.
894 HFS_INCONSISTENCY_DETECTED
,
896 // Used when unable to rollback an operation that failed
899 // Used when the latter part of an operation failed, but we chose not to roll back
902 // Used when someone told us to force an fsck on next mount
904 } hfs_inconsistency_reason_t
;
906 void hfs_mark_inconsistent(struct hfsmount
*hfsmp
,
907 hfs_inconsistency_reason_t reason
);
909 void hfs_scan_blocks (struct hfsmount
*hfsmp
);
910 int hfs_vfs_root(struct mount
*mp
, struct vnode
**vpp
, vfs_context_t context
);
912 /*****************************************************************************
913 Functions from hfs_vfsutils.c
914 ******************************************************************************/
915 u_int32_t
BestBlockSizeFit(u_int32_t allocationBlockSize
,
916 u_int32_t blockSizeLimit
,
917 u_int32_t baseMultiple
);
920 OSErr
hfs_MountHFSVolume(struct hfsmount
*hfsmp
, HFSMasterDirectoryBlock
*mdb
,
923 OSErr
hfs_MountHFSPlusVolume(struct hfsmount
*hfsmp
, HFSPlusVolumeHeader
*vhp
,
924 off_t embeddedOffset
, u_int64_t disksize
, struct proc
*p
, void *args
, kauth_cred_t cred
);
926 OSErr
hfs_ValidateHFSPlusVolumeHeader(struct hfsmount
*hfsmp
, HFSPlusVolumeHeader
*vhp
);
928 extern int hfsUnmount(struct hfsmount
*hfsmp
, struct proc
*p
);
930 extern bool overflow_extents(struct filefork
*fp
);
932 extern int hfs_owner_rights(struct hfsmount
*hfsmp
, uid_t cnode_uid
, kauth_cred_t cred
,
933 struct proc
*p
, int invokesuperuserstatus
);
935 extern int check_for_dataless_file(struct vnode
*vp
, uint64_t op_type
);
936 extern int hfs_generate_document_id(struct hfsmount
*hfsmp
, uint32_t *docid
);
937 extern void hfs_pin_fs_metadata(struct hfsmount
*hfsmp
);
939 /* Return information about number of metadata blocks for volume */
940 extern int hfs_getinfo_metadata_blocks(struct hfsmount
*hfsmp
, struct hfsinfo_metadata
*hinfo
);
943 * Journal lock function prototypes
945 int hfs_lock_global (struct hfsmount
*hfsmp
, enum hfs_locktype locktype
);
946 void hfs_unlock_global (struct hfsmount
*hfsmp
);
948 /* HFS mount lock/unlock prototypes */
949 void hfs_lock_mount (struct hfsmount
*hfsmp
);
950 void hfs_unlock_mount (struct hfsmount
*hfsmp
);
953 /* HFS System file locking */
954 #define SFL_CATALOG 0x0001
955 #define SFL_EXTENTS 0x0002
956 #define SFL_BITMAP 0x0004
957 #define SFL_ATTRIBUTE 0x0008
958 #define SFL_STARTUP 0x0010
959 #define SFL_VM_PRIV 0x0020
960 #define SFL_VALIDMASK (SFL_CATALOG | SFL_EXTENTS | SFL_BITMAP | SFL_ATTRIBUTE | SFL_STARTUP | SFL_VM_PRIV)
962 extern u_int32_t
GetFileInfo(ExtendedVCB
*vcb
, u_int32_t dirid
, const char *name
,
963 struct cat_attr
*fattr
, struct cat_fork
*forkinfo
);
965 extern void hfs_remove_orphans(struct hfsmount
*);
967 u_int32_t
GetLogicalBlockSize(struct vnode
*vp
);
969 extern u_int32_t
hfs_free_cnids(struct hfsmount
* hfsmp
);
970 extern u_int32_t
hfs_freeblks(struct hfsmount
* hfsmp
, int wantreserve
);
972 short MacToVFSError(OSErr err
);
974 void hfs_metadatazone_init(struct hfsmount
*hfsmp
, int disable
);
976 /* HFS directory hint functions. */
977 extern directoryhint_t
* hfs_getdirhint(struct cnode
*, int, int);
978 extern void hfs_reldirhint(struct cnode
*, directoryhint_t
*);
979 extern void hfs_reldirhints(struct cnode
*, int);
980 extern void hfs_insertdirhint(struct cnode
*, directoryhint_t
*);
982 extern int hfs_namecmp(const u_int8_t
*str1
, size_t len1
, const u_int8_t
*str2
, size_t len2
);
984 extern int hfs_early_journal_init(struct hfsmount
*hfsmp
, HFSPlusVolumeHeader
*vhp
,
985 void *_args
, off_t embeddedOffset
, daddr64_t mdb_offset
,
986 HFSMasterDirectoryBlock
*mdbp
, kauth_cred_t cred
);
988 extern int hfs_virtualmetafile(struct cnode
*);
990 extern int hfs_start_transaction(struct hfsmount
*hfsmp
);
991 extern int hfs_end_transaction(struct hfsmount
*hfsmp
);
992 extern void hfs_journal_lock(struct hfsmount
*hfsmp
);
993 extern void hfs_journal_unlock(struct hfsmount
*hfsmp
);
994 extern void hfs_syncer_lock(struct hfsmount
*hfsmp
);
995 extern void hfs_syncer_unlock(struct hfsmount
*hfsmp
);
996 extern void hfs_syncer_wait(struct hfsmount
*hfsmp
, struct timespec
*ts
);
997 extern void hfs_syncer_wakeup(struct hfsmount
*hfsmp
);
998 extern void hfs_syncer(void *arg
, wait_result_t
);
999 extern void hfs_sync_ejectable(struct hfsmount
*hfsmp
);
1001 typedef enum hfs_flush_mode
{
1002 HFS_FLUSH_JOURNAL
, // Flush journal
1003 HFS_FLUSH_JOURNAL_META
, // Flush journal and metadata blocks
1004 HFS_FLUSH_FULL
, // Flush journal and does a cache flush
1005 HFS_FLUSH_CACHE
, // Flush track cache to media
1006 HFS_FLUSH_BARRIER
, // Barrier-only flush to ensure write order
1007 HFS_FLUSH_JOURNAL_BARRIER
// Flush journal with barrier
1010 extern errno_t
hfs_flush(struct hfsmount
*hfsmp
, hfs_flush_mode_t mode
);
1012 extern void hfs_trim_callback(void *arg
, uint32_t extent_count
, const dk_extent_t
*extents
);
1014 /* Erase unused Catalog nodes due to <rdar://problem/6947811>. */
1015 extern int hfs_erase_unused_nodes(struct hfsmount
*hfsmp
);
1017 extern uint64_t hfs_usecs_to_deadline(uint64_t usecs
);
1019 extern int hfs_freeze(struct hfsmount
*hfsmp
);
1020 extern int hfs_thaw(struct hfsmount
*hfsmp
, const struct proc
*process
);
1022 void hfs_close_jvp(hfsmount_t
*hfsmp
);
1024 // Return a heap address suitable for logging or tracing
1025 uintptr_t obfuscate_addr(void *addr
);
1028 int hfs_to_utf8(ExtendedVCB
*vcb
, const Str31 hfs_str
, ByteCount maxDstLen
,
1029 ByteCount
*actualDstLen
, unsigned char* dstStr
);
1030 int utf8_to_hfs(ExtendedVCB
*vcb
, ByteCount srcLen
, const unsigned char* srcStr
,
1032 int unicode_to_hfs(ExtendedVCB
*vcb
, ByteCount srcLen
, u_int16_t
* srcStr
, Str31 dstStr
, int retry
);
1035 void *hfs_malloc(size_t size
);
1036 void hfs_free(void *ptr
, size_t size
);
1037 void *hfs_mallocz(size_t size
);
1046 typedef struct hfs_zone_entry
{
1047 hfs_zone_kind_t hze_kind
;
1048 size_t hze_elem_size
;
1049 const char * hze_name
;
1052 typedef struct hfs_zone
{
1054 size_t hz_elem_size
;
1057 void hfs_init_zones(void);
1058 void *hfs_zalloc(hfs_zone_kind_t type
);
1059 void hfs_zfree(void *ptr
, hfs_zone_kind_t type
);
1061 void hfs_sysctl_register(void);
1062 void hfs_sysctl_unregister(void);
1064 #if HFS_MALLOC_DEBUG
1066 void hfs_alloc_trace_disable(void);
1067 void hfs_alloc_trace_enable(void);
1068 bool hfs_dump_allocations(void);
1070 #endif // HFS_MALLOC_DEBUG
1072 /*****************************************************************************
1073 Functions from hfs_vnops.c
1074 ******************************************************************************/
1075 int hfs_write_access(struct vnode
*vp
, kauth_cred_t cred
, struct proc
*p
, Boolean considerFlags
);
1077 int hfs_chmod(struct vnode
*vp
, int mode
, kauth_cred_t cred
, struct proc
*p
);
1079 int hfs_chown(struct vnode
*vp
, uid_t uid
, gid_t gid
, kauth_cred_t cred
, struct proc
*p
);
1081 int hfs_vnop_create(struct vnop_create_args
*ap
);
1083 int hfs_vnop_remove(struct vnop_remove_args
*);
1085 #define kMaxSecsForFsync 5
1086 #define HFS_SYNCTRANS 1
1087 extern int hfs_btsync(struct vnode
*vp
, int sync_transaction
);
1089 extern void replace_desc(struct cnode
*cp
, struct cat_desc
*cdp
);
1091 extern int hfs_vgetrsrc(struct hfsmount
*hfsmp
, struct vnode
*vp
,
1092 struct vnode
**rvpp
);
1095 // Push all modifications to disk (including minor ones)
1096 HFS_UPDATE_FORCE
= 0x01,
1097 } hfs_update_options_t
;
1099 extern int hfs_update(struct vnode
*, int options
);
1101 typedef enum hfs_sync_mode
{
1107 extern int hfs_fsync(struct vnode
*, int, hfs_fsync_mode_t
, struct proc
*);
1109 const struct cat_fork
*
1110 hfs_prepare_fork_for_update(filefork_t
*ff
,
1111 const struct cat_fork
*cf
,
1112 struct cat_fork
*cf_buf
,
1113 uint32_t block_size
);
1115 struct decmpfs_cnode
;
1116 struct decmpfs_cnode
*hfs_lazy_init_decmpfs_cnode (struct cnode
*cp
);
1118 /*****************************************************************************
1119 Functions from hfs_xattr.c
1120 ******************************************************************************/
1123 * Maximum extended attribute size supported for all extended attributes except
1124 * resource fork and finder info.
1126 #define HFS_XATTR_MAXSIZE INT32_MAX
1128 /* Number of bits used to represent maximum extended attribute size */
1129 #define HFS_XATTR_SIZE_BITS 31
1131 int hfs_attrkeycompare(HFSPlusAttrKey
*searchKey
, HFSPlusAttrKey
*trialKey
);
1132 int hfs_buildattrkey(u_int32_t fileID
, const char *attrname
, HFSPlusAttrKey
*key
);
1133 void hfs_xattr_init(struct hfsmount
* hfsmp
);
1134 int file_attribute_exist(struct hfsmount
*hfsmp
, uint32_t fileID
);
1135 int init_attrdata_vnode(struct hfsmount
*hfsmp
);
1136 int hfs_xattr_read(vnode_t vp
, const char *name
, void *data
, size_t *size
);
1137 int hfs_getxattr_internal(cnode_t
*, struct vnop_getxattr_args
*,
1138 struct hfsmount
*, u_int32_t
);
1139 int hfs_xattr_write(vnode_t vp
, const char *name
, const void *data
, size_t size
);
1140 int hfs_setxattr_internal(struct cnode
*, const void *, size_t,
1141 struct vnop_setxattr_args
*, struct hfsmount
*, u_int32_t
);
1142 extern int hfs_removeallattr(struct hfsmount
*hfsmp
, u_int32_t fileid
,
1143 bool *open_transaction
);
1145 int hfs_removexattr_by_id (struct hfsmount
*hfsmp
, uint32_t fileid
, const char *xattr_name
);
1147 extern int hfs_set_volxattr(struct hfsmount
*hfsmp
, unsigned int xattrtype
, int state
);
1151 /*****************************************************************************
1152 Functions from hfs_link.c
1153 ******************************************************************************/
1155 extern int hfs_unlink(struct hfsmount
*hfsmp
, struct vnode
*dvp
, struct vnode
*vp
,
1156 struct componentname
*cnp
, int skip_reserve
);
1157 extern int hfs_lookup_siblinglinks(struct hfsmount
*hfsmp
, cnid_t linkfileid
,
1158 cnid_t
*prevlinkid
, cnid_t
*nextlinkid
);
1159 extern int hfs_lookup_lastlink(struct hfsmount
*hfsmp
, cnid_t linkfileid
,
1160 cnid_t
*nextlinkid
, struct cat_desc
*cdesc
);
1161 extern void hfs_privatedir_init(struct hfsmount
*, enum privdirtype
);
1163 extern void hfs_savelinkorigin(cnode_t
*cp
, cnid_t parentcnid
);
1164 extern void hfs_relorigins(struct cnode
*cp
);
1165 extern void hfs_relorigin(struct cnode
*cp
, cnid_t parentcnid
);
1166 extern int hfs_haslinkorigin(cnode_t
*cp
);
1167 extern cnid_t
hfs_currentparent(cnode_t
*cp
, bool have_lock
);
1168 extern cnid_t
hfs_currentcnid(cnode_t
*cp
);
1169 errno_t
hfs_first_link(hfsmount_t
*hfsmp
, cnode_t
*cp
, cnid_t
*link_id
);
1172 /*****************************************************************************
1173 Functions from VolumeAllocation.c
1174 ******************************************************************************/
1175 extern int hfs_isallocated(struct hfsmount
*hfsmp
, u_int32_t startingBlock
, u_int32_t numBlocks
);
1177 extern int hfs_count_allocated(struct hfsmount
*hfsmp
, u_int32_t startBlock
,
1178 u_int32_t numBlocks
, u_int32_t
*alloc_count
);
1180 extern int hfs_isrbtree_active (struct hfsmount
*hfsmp
);
1182 /*****************************************************************************
1183 Functions from hfs_fsinfo.c
1184 ******************************************************************************/
1185 extern errno_t
hfs_get_fsinfo(struct hfsmount
*hfsmp
, void *a_data
);
1186 extern void hfs_fsinfo_data_add(struct hfs_fsinfo_data
*fsinfo
, uint64_t entry
);
1189 bool hfs_xattr_fext_find(xattr_io_info_t
*info
, uint32_t fs_bsize
,
1190 uint64_t off
, HFSPlusExtentDescriptor
*out
, uint64_t *off_out
);
1193 struct hfs_sysctl_chain
{
1194 struct sysctl_oid
*oid
;
1195 struct hfs_sysctl_chain
*next
;
1198 extern struct hfs_sysctl_chain
*sysctl_list
;
1200 SYSCTL_DECL(_vfs_generic_hfs
);
1202 #define HFS_SYSCTL(kind, parent, flags, name, ...) \
1203 SYSCTL_##kind(parent, flags, name, __VA_ARGS__); \
1204 struct hfs_sysctl_chain hfs_sysctl_##parent##_##name##_chain = { \
1205 .oid = &sysctl_##parent##_##name \
1207 static __attribute__((__constructor__)) void \
1208 hfs_sysctl_register_##parent##_##name(void) { \
1209 hfs_sysctl_##parent##_##name##_chain.next = sysctl_list; \
1210 sysctl_list = &hfs_sysctl_##parent##_##name##_chain; \
1216 #define assert Do_not_use_assert__Use_hfs_assert_instead
1218 #endif /* __APPLE_API_PRIVATE */
1220 #endif /* __HFS__ */