]> git.saurik.com Git - apple/hfs.git/blob - core/hfs.h
f726cd31e1220ae448ed097921c7d6be200aece6
[apple/hfs.git] / core / hfs.h
1 /*
2 * Copyright (c) 2000-2015 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29 #ifndef __HFS__
30 #define __HFS__
31
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.
39 */
40 #define HFS_SPARSE_DEV 1
41
42 #if DEBUG
43 #define HFS_CHECK_LOCK_ORDER 1
44 #endif
45
46 #define HFS_TMPDBG 0
47
48 #include <sys/appleapiopts.h>
49
50 #ifdef KERNEL
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>
59 #include <sys/disk.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>
65
66 #include "../hfs_encodings/hfs_encodings.h"
67
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"
75
76 __BEGIN_DECLS
77
78 #if CONFIG_PROTECT
79 /* Forward declare the cprotect struct */
80 struct cprotect;
81 #endif
82
83 /*
84 * Just reported via MIG interface.
85 */
86 #define VERSION_STRING "hfs-2 (4-12-99)"
87
88 #define HFS_LINK_MAX 32767
89
90 #define HFS_MAX_DEFERED_ALLOC (1024*1024)
91
92 #define HFS_MAX_FILES (UINT32_MAX - kHFSFirstUserCatalogNodeID)
93
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)
98
99 enum { kMDBSize = 512 }; /* Size of I/O transfer to read entire MDB */
100
101 enum { kMasterDirectoryBlock = 2 }; /* MDB offset on disk in 512-byte blocks */
102 enum { kMDBOffset = kMasterDirectoryBlock * 512 }; /* MDB offset on disk in bytes */
103
104 #define kRootDirID kHFSRootFolderID
105
106
107 /* number of locked buffer caches to hold for b-tree meta data */
108 #define kMaxLockedMetaBuffers 32
109
110 extern struct timezone gTimeZone;
111
112
113 /* How many free extents to cache per volume */
114 #define kMaxFreeExtents 10
115
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)
119
120
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. */
123
124 /*
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.
130 */
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))
134
135 /*
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
140 */
141
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_ROOTLOWDISKSHUTOFFFRACTION 11
147 #define HFS_ROOTLOWDISKSHUTOFFLEVEL ((u_int64_t)(1024*1024*1024 + 250*1024*1024))
148
149 #define HFS_VERYLOWDISKTRIGGERFRACTION 1
150 #define HFS_VERYLOWDISKTRIGGERLEVEL ((u_int64_t)(100*1024*1024))
151 #define HFS_LOWDISKTRIGGERFRACTION 2
152 #define HFS_LOWDISKTRIGGERLEVEL ((u_int64_t)(150*1024*1024))
153 #define HFS_LOWDISKSHUTOFFFRACTION 3
154 #define HFS_LOWDISKSHUTOFFLEVEL ((u_int64_t)(200*1024*1024))
155
156 /* Internal Data structures*/
157
158 /* This structure describes the HFS specific mount structure data. */
159 typedef struct hfsmount {
160 u_int32_t hfs_flags; /* see below */
161
162 /* Physical Description */
163 u_int32_t hfs_logical_block_size; /* Logical block size of the disk as reported by ioctl(DKIOCGETBLOCKSIZE), always a multiple of 512 */
164 daddr64_t hfs_logical_block_count; /* Number of logical blocks on the disk, as reported by ioctl(DKIOCGETBLOCKCOUNT) */
165 u_int64_t hfs_logical_bytes; /* Number of bytes on the disk device this HFS is mounted on (blockcount * blocksize) */
166 /*
167 * Regarding the two AVH sector fields below:
168 * Under normal circumstances, the filesystem's notion of the "right" location for the AVH is such that
169 * the partition and filesystem's are in sync. However, during a filesystem resize, HFS proactively
170 * writes a new AVH at the end of the filesystem, assuming that the partition will be resized accordingly.
171 *
172 * However, it is not technically a corruption if the partition size is never modified. As a result, we need
173 * to keep two copies of the AVH around "just in case" the partition size is not modified.
174 */
175 daddr64_t hfs_partition_avh_sector; /* location of Alt VH w.r.t partition size */
176 daddr64_t hfs_fs_avh_sector; /* location of Alt VH w.r.t filesystem size */
177
178 u_int32_t hfs_physical_block_size; /* Physical block size of the disk as reported by ioctl(DKIOCGETPHYSICALBLOCKSIZE) */
179 u_int32_t hfs_log_per_phys; /* Number of logical blocks per physical block size */
180
181 /* Access to VFS and devices */
182 struct mount *hfs_mp; /* filesystem vfs structure */
183 struct vnode *hfs_devvp; /* block device mounted vnode */
184 struct vnode * hfs_extents_vp;
185 struct vnode * hfs_catalog_vp;
186 struct vnode * hfs_allocation_vp;
187 struct vnode * hfs_attribute_vp;
188 struct vnode * hfs_startup_vp;
189 struct vnode * hfs_attrdata_vp; /* pseudo file */
190 struct cnode * hfs_extents_cp;
191 struct cnode * hfs_catalog_cp;
192 struct cnode * hfs_allocation_cp;
193 struct cnode * hfs_attribute_cp;
194 struct cnode * hfs_startup_cp;
195 dev_t hfs_raw_dev; /* device mounted */
196 u_int32_t hfs_logBlockSize; /* Size of buffer cache buffer for I/O */
197
198 /* Default values for HFS standard and non-init access */
199 uid_t hfs_uid; /* uid to set as owner of the files */
200 gid_t hfs_gid; /* gid to set as owner of the files */
201 mode_t hfs_dir_mask; /* mask to and with directory protection bits */
202 mode_t hfs_file_mask; /* mask to and with file protection bits */
203 u_int32_t hfs_encoding; /* Default encoding for non hfs+ volumes */
204
205 /* Persistent fields (on disk, dynamic) */
206 time_t hfs_mtime; /* file system last modification time */
207 u_int32_t hfs_filecount; /* number of files in file system */
208 u_int32_t hfs_dircount; /* number of directories in file system */
209 u_int32_t freeBlocks; /* free allocation blocks */
210 u_int32_t reclaimBlocks; /* number of blocks we are reclaiming during resize */
211 u_int32_t tentativeBlocks; /* tentative allocation blocks -- see note below */
212 u_int32_t nextAllocation; /* start of next allocation search */
213 u_int32_t sparseAllocation; /* start of allocations for sparse devices */
214 u_int32_t vcbNxtCNID; /* next unused catalog node ID - protected by catalog lock */
215 u_int32_t vcbWrCnt; /* file system write count */
216 u_int64_t encodingsBitmap; /* in-use encodings */
217 u_int16_t vcbNmFls; /* HFS Only - root dir file count */
218 u_int16_t vcbNmRtDirs; /* HFS Only - root dir directory count */
219
220 /* Persistent fields (on disk, static) */
221 u_int16_t vcbSigWord;
222
223 // Volume will be inconsistent if header is not flushed
224 bool hfs_header_dirty;
225
226 // Volume header is dirty, but won't be inconsistent if not flushed
227 bool hfs_header_minor_change;
228
229 u_int32_t vcbAtrb;
230 u_int32_t vcbJinfoBlock;
231 u_int32_t localCreateDate;/* volume create time from volume header (For HFS+, value is in local time) */
232 time_t hfs_itime; /* file system creation time (creation date of the root folder) */
233 time_t hfs_btime; /* file system last backup time */
234 u_int32_t blockSize; /* size of allocation blocks */
235 u_int32_t totalBlocks; /* total allocation blocks */
236 u_int32_t allocLimit; /* Do not allocate this block or beyond */
237 /*
238 * NOTE: When resizing a volume to make it smaller, allocLimit is set to the allocation
239 * block number which will contain the new alternate volume header. At all other times,
240 * allocLimit is set to totalBlocks. The allocation code uses allocLimit instead of
241 * totalBlocks to limit which blocks may be allocated, so that during a resize, we don't
242 * put new content into the blocks we're trying to truncate away.
243 */
244 int32_t vcbClpSiz;
245 u_int32_t vcbFndrInfo[8];
246 int16_t vcbVBMSt; /* HFS only */
247 int16_t vcbAlBlSt; /* HFS only */
248
249 /* vcb stuff */
250 u_int8_t vcbVN[256]; /* volume name in UTF-8 */
251 u_int32_t volumeNameEncodingHint;
252 u_int32_t hfsPlusIOPosOffset; /* Disk block where HFS+ starts */
253 u_int32_t vcbVBMIOSize; /* volume bitmap I/O size */
254
255 /* cache of largest known free extents */
256 u_int32_t vcbFreeExtCnt;
257 HFSPlusExtentDescriptor vcbFreeExt[kMaxFreeExtents];
258 lck_spin_t vcbFreeExtLock;
259
260 /* Summary Table */
261 u_int8_t *hfs_summary_table; /* Each bit is 1 vcbVBMIOSize of bitmap, byte indexed */
262 u_int32_t hfs_summary_size; /* number of BITS in summary table defined above (not bytes!) */
263 u_int32_t hfs_summary_bytes; /* number of BYTES in summary table */
264
265 u_int32_t scan_var; /* For initializing the summary table */
266
267
268 u_int32_t reserveBlocks; /* free block reserve */
269 u_int32_t loanedBlocks; /* blocks on loan for delayed allocations */
270 u_int32_t lockedBlocks; /* blocks reserved and locked */
271
272 /*
273 * HFS+ Private system directories (two). Any access
274 * (besides looking at the cd_cnid) requires holding
275 * the Catalog File lock.
276 */
277 struct cat_desc hfs_private_desc[2];
278 struct cat_attr hfs_private_attr[2];
279
280 u_int32_t hfs_metadata_createdate;
281 #if CONFIG_HFS_STD
282 hfs_to_unicode_func_t hfs_get_unicode;
283 unicode_to_hfs_func_t hfs_get_hfsname;
284 #endif
285
286 /* Quota variables: */
287 struct quotafile hfs_qfiles[MAXQUOTAS]; /* quota files */
288
289 /* Journaling variables: */
290 struct journal *jnl; // the journal for this volume (if one exists)
291 struct vnode *jvp; // device where the journal lives (may be equal to devvp)
292 u_int32_t jnl_start; // start block of the journal file (so we don't delete it)
293 u_int32_t jnl_size;
294 u_int32_t hfs_jnlfileid;
295 u_int32_t hfs_jnlinfoblkid;
296 lck_rw_t hfs_global_lock;
297 thread_t hfs_global_lockowner;
298 u_int32_t hfs_transaction_nesting;
299
300 /*
301 * Notification variables
302 * See comments in hfs mount code for what the
303 * default levels are set to.
304 */
305 u_int32_t hfs_notification_conditions;
306 u_int32_t hfs_freespace_notify_dangerlimit;
307 u_int32_t hfs_freespace_notify_warninglimit;
308 u_int32_t hfs_freespace_notify_desiredlevel;
309
310 /* time mounted and last mounted mod time "snapshot" */
311 time_t hfs_mount_time;
312 time_t hfs_last_mounted_mtime;
313
314 /* Metadata allocation zone variables: */
315 u_int32_t hfs_metazone_start;
316 u_int32_t hfs_metazone_end;
317 u_int32_t hfs_hotfile_start;
318 u_int32_t hfs_hotfile_end;
319 u_int32_t hfs_min_alloc_start;
320 u_int32_t hfs_freed_block_count;
321 u_int64_t hfs_cs_hotfile_size; // in bytes
322 int hfs_hotfile_freeblks;
323 int hfs_hotfile_blk_adjust;
324 int hfs_hotfile_maxblks;
325 int hfs_overflow_maxblks;
326 int hfs_catalog_maxblks;
327
328 /* Hot File Clustering variables: */
329 lck_mtx_t hfc_mutex; /* serialize hot file stages */
330 enum hfc_stage hfc_stage; /* what are we up to... */
331 time_t hfc_timebase; /* recording period start time */
332 time_t hfc_timeout; /* recording period stop time */
333 struct hotfile_data *hfc_recdata;
334 struct hotfilelist *hfc_filelist;
335 uint32_t hfc_maxfiles; /* maximum files to track */
336 struct vnode * hfc_filevp;
337
338 /* defrag-on-open variables */
339 int hfs_defrag_nowait; //issue defrags now, regardless of whether or not we've gone past 3 min.
340 uint64_t hfs_defrag_max; //maximum file size we'll defragment on this mount
341
342 #if HFS_SPARSE_DEV
343 /* Sparse device variables: */
344 struct vnode * hfs_backingvp;
345 u_int32_t hfs_last_backingstatfs;
346 u_int32_t hfs_sparsebandblks;
347 u_int64_t hfs_backingfs_maxblocks;
348 #endif
349 size_t hfs_max_inline_attrsize;
350
351 lck_mtx_t hfs_mutex; /* protects access to hfsmount data */
352
353 uint32_t hfs_syncers; // Count of the number of syncers running
354 enum {
355 HFS_THAWED,
356 HFS_WANT_TO_FREEZE, // This state stops hfs_sync from starting
357 HFS_FREEZING, // We're in this state whilst we're flushing
358 HFS_FROZEN // Everything gets blocked in hfs_lock_global
359 } hfs_freeze_state;
360 union {
361 /*
362 * When we're freezing (HFS_FREEZING) but not yet
363 * frozen (HFS_FROZEN), we record the freezing thread
364 * so that we stop other threads from taking locks,
365 * but allow the freezing thread.
366 */
367 const struct thread *hfs_freezing_thread;
368 /*
369 * Once we have frozen (HFS_FROZEN), we record the
370 * process so that if it dies, we can automatically
371 * unfreeze.
372 */
373 proc_t hfs_freezing_proc;
374 };
375
376 thread_t hfs_downgrading_thread; /* thread who's downgrading to rdonly */
377
378 /* Resize variables: */
379 u_int32_t hfs_resize_blocksmoved;
380 u_int32_t hfs_resize_totalblocks;
381 u_int32_t hfs_resize_progress;
382 #if CONFIG_PROTECT
383 /* Data Protection fields */
384 cpx_t hfs_resize_cpx;
385 u_int16_t hfs_running_cp_major_vers;
386 uint32_t default_cp_class; /* default effective class value */
387 uint64_t cproot_flags;
388 uint8_t cp_crypto_generation;
389 cp_lock_state_t hfs_cp_lock_state; /* per-mount device lock state info */
390 #if HFS_CONFIG_KEY_ROLL
391 uint32_t hfs_auto_roll_min_key_os_version;
392 uint32_t hfs_auto_roll_max_key_os_version;
393 #endif
394 #if HFS_TMPDBG
395 #if !SECURE_KERNEL
396 boolean_t hfs_cp_verbose;
397 #endif
398 #endif
399
400 #endif
401
402 /* the full UUID of the volume, not the one stored in finderinfo */
403 uuid_t hfs_full_uuid;
404
405 /* Per mount cnode hash variables: */
406 lck_mtx_t hfs_chash_mutex; /* protects access to cnode hash table */
407 u_long hfs_cnodehash; /* size of cnode hash table - 1 */
408 LIST_HEAD(cnodehashhead, cnode) *hfs_cnodehashtbl; /* base of cnode hash */
409
410 /* Per mount fileid hash variables (protected by catalog lock!) */
411 u_long hfs_idhash; /* size of cnid/fileid hash table -1 */
412 LIST_HEAD(idhashhead, cat_preflightid) *hfs_idhashtbl; /* base of ID hash */
413
414 // Records the oldest outstanding sync request
415 struct timeval hfs_sync_req_oldest;
416
417 /* Records the syncer thread so that we can avoid the syncer
418 queing more syncs. */
419 thread_t hfs_syncer_thread;
420
421 // Not currently used except for debugging purposes
422 uint32_t hfs_active_threads;
423
424 enum {
425 // These are indices into the array below
426
427 // Tentative ranges can be claimed back at any time
428 HFS_TENTATIVE_BLOCKS = 0,
429
430 // Locked ranges cannot be claimed back, but the allocation
431 // won't have been written to disk yet
432 HFS_LOCKED_BLOCKS = 1,
433 };
434 // These lists are not sorted like a range list usually is
435 struct rl_head hfs_reserved_ranges[2];
436 } hfsmount_t;
437
438 /*
439 * HFS_META_DELAY is a duration (in usecs) used for triggering the
440 * hfs_syncer() routine. We will back off if writes are in
441 * progress, but...
442 * HFS_MAX_META_DELAY is the maximum time we will allow the
443 * syncer to be delayed.
444 */
445 enum {
446 HFS_META_DELAY = 100 * 1000, // 0.1 secs
447 HFS_MAX_META_DELAY = 5000 * 1000 // 5 secs
448 };
449
450 #define HFS_META_DELAY_TS \
451 (struct timespec){ 0, HFS_META_DELAY * NSEC_PER_USEC }
452
453 typedef hfsmount_t ExtendedVCB;
454
455 /* Aliases for legacy (Mac OS 9) field names */
456 #define vcbLsMod hfs_mtime
457 #define vcbVolBkUp hfs_btime
458 #define extentsRefNum hfs_extents_vp
459 #define catalogRefNum hfs_catalog_vp
460 #define allocationsRefNum hfs_allocation_vp
461 #define vcbFilCnt hfs_filecount
462 #define vcbDirCnt hfs_dircount
463
464 static inline void MarkVCBDirty(hfsmount_t *hfsmp)
465 {
466 hfsmp->hfs_header_dirty = true;
467 }
468
469 static inline void MarkVCBClean(hfsmount_t *hfsmp)
470 {
471 hfsmp->hfs_header_dirty = false;
472 hfsmp->hfs_header_minor_change = false;
473 }
474
475 static inline bool IsVCBDirty(ExtendedVCB *vcb)
476 {
477 return vcb->hfs_header_minor_change || vcb->hfs_header_dirty;
478 }
479
480 // Header is changed but won't be inconsistent if we don't write it
481 static inline void hfs_note_header_minor_change(hfsmount_t *hfsmp)
482 {
483 hfsmp->hfs_header_minor_change = true;
484 }
485
486 // Must header be flushed for volume to be consistent?
487 static inline bool hfs_header_needs_flushing(hfsmount_t *hfsmp)
488 {
489 return (hfsmp->hfs_header_dirty
490 || ISSET(hfsmp->hfs_catalog_cp->c_flag, C_MODIFIED)
491 || ISSET(hfsmp->hfs_extents_cp->c_flag, C_MODIFIED)
492 || (hfsmp->hfs_attribute_cp
493 && ISSET(hfsmp->hfs_attribute_cp->c_flag, C_MODIFIED))
494 || (hfsmp->hfs_allocation_cp
495 && ISSET(hfsmp->hfs_allocation_cp->c_flag, C_MODIFIED))
496 || (hfsmp->hfs_startup_cp
497 && ISSET(hfsmp->hfs_startup_cp->c_flag, C_MODIFIED)));
498 }
499
500 /*
501 * There are two private directories in HFS+.
502 *
503 * One contains inodes for files that are hardlinked or open/unlinked.
504 * The other contains inodes for directories that are hardlinked.
505 */
506 enum privdirtype {FILE_HARDLINKS, DIR_HARDLINKS};
507
508 #define HFS_ALLOCATOR_SCAN_INFLIGHT 0x0001 /* scan started */
509 #define HFS_ALLOCATOR_SCAN_COMPLETED 0x0002 /* initial scan was completed */
510
511 /* HFS mount point flags */
512 #define HFS_READ_ONLY 0x00001
513 #define HFS_UNKNOWN_PERMS 0x00002
514 #define HFS_WRITEABLE_MEDIA 0x00004
515 #define HFS_CLEANED_ORPHANS 0x00008
516 #define HFS_X 0x00010
517 #define HFS_CASE_SENSITIVE 0x00020
518 #define HFS_STANDARD 0x00040
519 #define HFS_METADATA_ZONE 0x00080
520 #define HFS_FRAGMENTED_FREESPACE 0x00100
521 #define HFS_NEED_JNL_RESET 0x00200
522 #define HFS_HAS_SPARSE_DEVICE 0x00400
523 #define HFS_RESIZE_IN_PROGRESS 0x00800
524 #define HFS_QUOTAS 0x01000
525 #define HFS_CREATING_BTREE 0x02000
526 /* When set, do not update nextAllocation in the mount structure */
527 #define HFS_SKIP_UPDATE_NEXT_ALLOCATION 0x04000
528 /* When set, the file system supports extent-based extended attributes */
529 #define HFS_XATTR_EXTENTS 0x08000
530 #define HFS_FOLDERCOUNT 0x10000
531 /* When set, the file system exists on a virtual device, like disk image */
532 #define HFS_VIRTUAL_DEVICE 0x20000
533 /* When set, we're in hfs_changefs, so hfs_sync should do nothing. */
534 #define HFS_IN_CHANGEFS 0x40000
535 /* When set, we are in process of downgrading or have downgraded to read-only,
536 * so hfs_start_transaction should return EROFS.
537 */
538 #define HFS_RDONLY_DOWNGRADE 0x80000
539 #define HFS_DID_CONTIG_SCAN 0x100000
540 #define HFS_UNMAP 0x200000
541 #define HFS_SSD 0x400000
542 #define HFS_SUMMARY_TABLE 0x800000
543 #define HFS_CS 0x1000000
544 #define HFS_CS_METADATA_PIN 0x2000000
545 #define HFS_CS_HOTFILE_PIN 0x4000000 /* cooperative fusion (enables a hotfile variant) */
546 #define HFS_FEATURE_BARRIER 0x8000000 /* device supports barrier-only flush */
547 #define HFS_CS_SWAPFILE_PIN 0x10000000
548 #define HFS_RUN_SYNCER 0x20000000
549
550 /* Macro to update next allocation block in the HFS mount structure. If
551 * the HFS_SKIP_UPDATE_NEXT_ALLOCATION is set, do not update
552 * nextAllocation block.
553 */
554 #define HFS_UPDATE_NEXT_ALLOCATION(hfsmp, new_nextAllocation) \
555 { \
556 if ((hfsmp->hfs_flags & HFS_SKIP_UPDATE_NEXT_ALLOCATION) == 0)\
557 hfsmp->nextAllocation = new_nextAllocation; \
558 } \
559
560 /* Macro for incrementing and decrementing the folder count in a cnode
561 * attribute only if the HFS_FOLDERCOUNT bit is set in the mount flags
562 * and kHFSHasFolderCount bit is set in the cnode flags. Currently these
563 * bits are only set for case sensitive HFS+ volumes.
564 */
565 #define INC_FOLDERCOUNT(hfsmp, cattr) \
566 if ((hfsmp->hfs_flags & HFS_FOLDERCOUNT) && \
567 (cattr.ca_recflags & kHFSHasFolderCountMask)) { \
568 cattr.ca_dircount++; \
569 } \
570
571 #define DEC_FOLDERCOUNT(hfsmp, cattr) \
572 if ((hfsmp->hfs_flags & HFS_FOLDERCOUNT) && \
573 (cattr.ca_recflags & kHFSHasFolderCountMask) && \
574 (cattr.ca_dircount > 0)) { \
575 cattr.ca_dircount--; \
576 } \
577
578 typedef struct filefork FCB;
579
580 /*
581 * Macros for creating item names for our special/private directories.
582 */
583 #define MAKE_INODE_NAME(name, size, linkno) \
584 (void) snprintf((name), size, "%s%d", HFS_INODE_PREFIX, (linkno))
585 #define HFS_INODE_PREFIX_LEN 5
586
587 #define MAKE_DIRINODE_NAME(name, size, linkno) \
588 (void) snprintf((name), size, "%s%d", HFS_DIRINODE_PREFIX, (linkno))
589 #define HFS_DIRINODE_PREFIX_LEN 4
590
591 #define MAKE_DELETED_NAME(NAME, size, FID) \
592 (void) snprintf((NAME), size, "%s%d", HFS_DELETE_PREFIX, (FID))
593 #define HFS_DELETE_PREFIX_LEN 4
594
595
596 #define HFS_AVERAGE_NAME_SIZE 22
597 #define AVERAGE_HFSDIRENTRY_SIZE (8+HFS_AVERAGE_NAME_SIZE+4)
598
599 #define STD_DIRENT_LEN(namlen) \
600 ((sizeof(struct dirent) - (NAME_MAX+1)) + (((namlen)+1 + 3) &~ 3))
601
602 #define EXT_DIRENT_LEN(namlen) \
603 ((sizeof(struct direntry) + (namlen) - (MAXPATHLEN-1) + 7) & ~7)
604
605
606 enum { kHFSPlusMaxFileNameBytes = kHFSPlusMaxFileNameChars * 3 };
607
608
609 /* macro to determine if hfs or hfsplus */
610 #define ISHFSPLUS(VCB) ((VCB)->vcbSigWord == kHFSPlusSigWord)
611 #define ISHFS(VCB) ((VCB)->vcbSigWord == kHFSSigWord)
612
613
614 /*
615 * Various ways to acquire a VFS mount point pointer:
616 */
617 #define VTOVFS(VP) vnode_mount((VP))
618 #define HFSTOVFS(HFSMP) ((HFSMP)->hfs_mp)
619 #define VCBTOVFS(VCB) HFSTOVFS(VCB)
620
621 /*
622 * Various ways to acquire an HFS mount point pointer:
623 */
624 #define VTOHFS(VP) ((struct hfsmount *)vfs_fsprivate(vnode_mount((VP))))
625 #define VFSTOHFS(MP) ((struct hfsmount *)vfs_fsprivate((MP)))
626 #define VCBTOHFS(VCB) (VCB)
627 #define FCBTOHFS(FCB) ((struct hfsmount *)vfs_fsprivate(vnode_mount((FCB)->ff_cp->c_vp)))
628
629 /*
630 * Various ways to acquire a VCB (legacy) pointer:
631 */
632 #define VTOVCB(VP) VTOHFS(VP)
633 #define VFSTOVCB(MP) VFSTOHFS(MP)
634 #define HFSTOVCB(HFSMP) (HFSMP)
635 #define FCBTOVCB(FCB) FCBTOHFS(FCB)
636
637
638 #define E_NONE 0
639 #define kHFSBlockSize 512
640
641 /*
642 * Macros for getting the MDB/VH sector and offset
643 */
644 #define HFS_PRI_SECTOR(blksize) (1024 / (blksize))
645 #define HFS_PRI_OFFSET(blksize) ((blksize) > 1024 ? 1024 : 0)
646
647 #define HFS_ALT_SECTOR(blksize, blkcnt) (((blkcnt) - 1) - (512 / (blksize)))
648 #define HFS_ALT_OFFSET(blksize) ((blksize) > 1024 ? (blksize) - 1024 : 0)
649
650 /* Convert the logical sector number to be aligned on physical block size boundary.
651 * We are assuming the partition is a multiple of physical block size.
652 */
653 #define HFS_PHYSBLK_ROUNDDOWN(sector_num, log_per_phys) ((sector_num / log_per_phys) * log_per_phys)
654
655 /*
656 * HFS specific fcntl()'s
657 */
658 #define HFS_GET_BOOT_INFO (FCNTL_FS_SPECIFIC_BASE + 0x00004)
659 #define HFS_SET_BOOT_INFO (FCNTL_FS_SPECIFIC_BASE + 0x00005)
660 /* See HFSIOC_EXT_BULKACCESS and friends for HFS specific fsctls*/
661
662
663
664 /*
665 * This is the straight GMT conversion constant:
666 * 00:00:00 January 1, 1970 - 00:00:00 January 1, 1904
667 * (3600 * 24 * ((365 * (1970 - 1904)) + (((1970 - 1904) / 4) + 1)))
668 */
669 #define MAC_GMT_FACTOR 2082844800UL
670
671 static inline __attribute__((const))
672 off_t hfs_blk_to_bytes(uint32_t blk, uint32_t blk_size)
673 {
674 return (off_t)blk * blk_size; // Avoid the overflow
675 }
676
677 /*
678 * For now, we use EIO to indicate consistency issues. It is safe to
679 * return or assign an error value to HFS_EINCONSISTENT but it is
680 * *not* safe to compare against it because EIO can be generated for
681 * other reasons. We take advantage of the fact that == has
682 * left-to-right associativity and so any uses of:
683 *
684 * if (error == HFS_EINCONSISTENT)
685 *
686 * will produce a compiler warning: "comparison between pointer and
687 * integer".
688 *
689 * Note that not everwhere is consistent with the use of
690 * HFS_EINCONSISTENT. Some places return EINVAL, EIO directly or
691 * other error codes.
692 */
693 #define HFS_EINCONSISTENT (void *)0 == (void *)0 ? EIO : EIO
694
695 #define HFS_ERESERVEDNAME -8
696
697 extern int (**hfs_specop_p)(void *);
698
699 /*****************************************************************************
700 FUNCTION PROTOTYPES
701 ******************************************************************************/
702
703 /*****************************************************************************
704 hfs_vnop_xxx functions from different files
705 ******************************************************************************/
706 int hfs_vnop_readdirattr(struct vnop_readdirattr_args *); /* in hfs_attrlist.c */
707 int hfs_vnop_getattrlistbulk(struct vnop_getattrlistbulk_args *); /* in hfs_attrlist.c */
708
709 int hfs_vnop_inactive(struct vnop_inactive_args *); /* in hfs_cnode.c */
710 int hfs_vnop_reclaim(struct vnop_reclaim_args *); /* in hfs_cnode.c */
711
712 int hfs_set_backingstore (struct vnode *vp, int val); /* in hfs_cnode.c */
713 int hfs_is_backingstore (struct vnode *vp, int *val); /* in hfs_cnode.c */
714
715 int hfs_vnop_link(struct vnop_link_args *); /* in hfs_link.c */
716
717 int hfs_vnop_lookup(struct vnop_lookup_args *); /* in hfs_lookup.c */
718
719 int hfs_vnop_search(struct vnop_searchfs_args *); /* in hfs_search.c */
720
721 int hfs_vnop_read(struct vnop_read_args *); /* in hfs_readwrite.c */
722 int hfs_vnop_write(struct vnop_write_args *); /* in hfs_readwrite.c */
723 int hfs_vnop_ioctl(struct vnop_ioctl_args *); /* in hfs_readwrite.c */
724 int hfs_vnop_select(struct vnop_select_args *); /* in hfs_readwrite.c */
725 int hfs_vnop_strategy(struct vnop_strategy_args *); /* in hfs_readwrite.c */
726 int hfs_vnop_allocate(struct vnop_allocate_args *); /* in hfs_readwrite.c */
727 int hfs_vnop_pagein(struct vnop_pagein_args *); /* in hfs_readwrite.c */
728 int hfs_vnop_pageout(struct vnop_pageout_args *); /* in hfs_readwrite.c */
729 int hfs_vnop_bwrite(struct vnop_bwrite_args *); /* in hfs_readwrite.c */
730 int hfs_vnop_blktooff(struct vnop_blktooff_args *); /* in hfs_readwrite.c */
731 int hfs_vnop_offtoblk(struct vnop_offtoblk_args *); /* in hfs_readwrite.c */
732 int hfs_vnop_blockmap(struct vnop_blockmap_args *); /* in hfs_readwrite.c */
733 errno_t hfs_flush_invalid_ranges(vnode_t vp); /* in hfs_readwrite.c */
734
735 int hfs_vnop_getxattr(struct vnop_getxattr_args *); /* in hfs_xattr.c */
736 int hfs_vnop_setxattr(struct vnop_setxattr_args *); /* in hfs_xattr.c */
737 int hfs_vnop_removexattr(struct vnop_removexattr_args *); /* in hfs_xattr.c */
738 int hfs_vnop_listxattr(struct vnop_listxattr_args *); /* in hfs_xattr.c */
739 #if NAMEDSTREAMS
740 extern int hfs_vnop_getnamedstream(struct vnop_getnamedstream_args*);
741 extern int hfs_vnop_makenamedstream(struct vnop_makenamedstream_args*);
742 extern int hfs_vnop_removenamedstream(struct vnop_removenamedstream_args*);
743 #endif
744
745
746 /*****************************************************************************
747 Functions from MacOSStubs.c
748 ******************************************************************************/
749 time_t to_bsd_time(u_int32_t hfs_time);
750
751 u_int32_t to_hfs_time(time_t bsd_time);
752
753
754 /*****************************************************************************
755 Functions from hfs_notifications.c
756 ******************************************************************************/
757 void hfs_generate_volume_notifications(struct hfsmount *hfsmp);
758
759
760 /*****************************************************************************
761 Functions from hfs_readwrite.c
762 ******************************************************************************/
763 extern int hfs_relocate(struct vnode *, u_int32_t, kauth_cred_t, struct proc *);
764
765 /* flags for hfs_pin_block_range() and hfs_pin_vnode() */
766 #define HFS_PIN_IT 0x0001
767 #define HFS_UNPIN_IT 0x0002
768 #define HFS_TEMP_PIN 0x0004
769 #define HFS_EVICT_PIN 0x0008
770 #define HFS_DATALESS_PIN 0x0010
771
772 //
773 // pin/un-pin an explicit range of blocks to the "fast" (usually ssd) device
774 //
775 int hfs_pin_block_range(struct hfsmount *hfsmp, int pin_state, uint32_t start_block, uint32_t nblocks);
776
777 //
778 // pin/un-pin all the extents belonging to a vnode.
779 // also, if it is non-null, "num_blocks_pinned" returns the number of blocks pin/unpinned by the function
780 //
781 int hfs_pin_vnode(struct hfsmount *hfsmp, struct vnode *vp, int pin_state, uint32_t *num_blocks_pinned);
782
783
784 int hfs_pin_overflow_extents (struct hfsmount *hfsmp, uint32_t fileid, uint8_t forktype, uint32_t *pinned);
785
786
787 /* Flags for HFS truncate */
788 #define HFS_TRUNCATE_SKIPTIMES 0x00000002 /* implied by skipupdate; it is a subset */
789
790
791 extern int hfs_truncate(struct vnode *, off_t, int, int, vfs_context_t);
792
793 extern int hfs_release_storage (struct hfsmount *hfsmp, struct filefork *datafork,
794 struct filefork *rsrcfork, u_int32_t fileid);
795
796 extern int hfs_prepare_release_storage (struct hfsmount *hfsmp, struct vnode *vp);
797
798 extern int hfs_bmap(struct vnode *, daddr_t, struct vnode **, daddr64_t *, unsigned int *);
799
800 extern errno_t hfs_ubc_setsize(vnode_t vp, off_t len, bool have_cnode_lock);
801
802
803 /*****************************************************************************
804 Functions from hfs_resize.c
805 ******************************************************************************/
806 int hfs_extendfs(struct hfsmount *hfsmp, u_int64_t newsize, vfs_context_t context);
807 int hfs_truncatefs(struct hfsmount *hfsmp, u_int64_t newsize, vfs_context_t context);
808
809
810 /*****************************************************************************
811 Functions from hfs_vfsops.c
812 ******************************************************************************/
813
814 extern void hfs_getvoluuid(struct hfsmount *hfsmp, uuid_t result);
815
816 /* used as a callback by the journaling code */
817 extern void hfs_sync_metadata(void *arg);
818
819 extern int hfs_vget(struct hfsmount *, cnid_t, struct vnode **, int, int);
820
821 extern void hfs_setencodingbits(struct hfsmount *hfsmp, u_int32_t encoding);
822
823 enum volop {VOL_UPDATE, VOL_MKDIR, VOL_RMDIR, VOL_MKFILE, VOL_RMFILE};
824 extern int hfs_volupdate(struct hfsmount *hfsmp, enum volop op, int inroot);
825
826 enum {
827 HFS_FVH_WAIT = 0x0001,
828 HFS_FVH_WRITE_ALT = 0x0002,
829 HFS_FVH_FLUSH_IF_DIRTY = 0x0004,
830 };
831 typedef uint32_t hfs_flush_volume_header_options_t;
832 int hfs_flushvolumeheader(struct hfsmount *hfsmp, hfs_flush_volume_header_options_t);
833
834 extern int hfs_extendfs(struct hfsmount *, u_int64_t, vfs_context_t);
835 extern int hfs_truncatefs(struct hfsmount *, u_int64_t, vfs_context_t);
836 extern int hfs_resize_progress(struct hfsmount *, u_int32_t *);
837
838 /* If a runtime corruption is detected, mark the volume inconsistent
839 * bit in the volume attributes.
840 */
841
842 typedef enum {
843 HFS_INCONSISTENCY_DETECTED,
844
845 // Used when unable to rollback an operation that failed
846 HFS_ROLLBACK_FAILED,
847
848 // Used when the latter part of an operation failed, but we chose not to roll back
849 HFS_OP_INCOMPLETE,
850
851 // Used when someone told us to force an fsck on next mount
852 HFS_FSCK_FORCED,
853 } hfs_inconsistency_reason_t;
854
855 void hfs_mark_inconsistent(struct hfsmount *hfsmp,
856 hfs_inconsistency_reason_t reason);
857
858 void hfs_scan_blocks (struct hfsmount *hfsmp);
859 int hfs_vfs_root(struct mount *mp, struct vnode **vpp, vfs_context_t context);
860
861 /*****************************************************************************
862 Functions from hfs_vfsutils.c
863 ******************************************************************************/
864 u_int32_t BestBlockSizeFit(u_int32_t allocationBlockSize,
865 u_int32_t blockSizeLimit,
866 u_int32_t baseMultiple);
867
868 #if CONFIG_HFS_STD
869 OSErr hfs_MountHFSVolume(struct hfsmount *hfsmp, HFSMasterDirectoryBlock *mdb,
870 struct proc *p);
871 #endif
872 OSErr hfs_MountHFSPlusVolume(struct hfsmount *hfsmp, HFSPlusVolumeHeader *vhp,
873 off_t embeddedOffset, u_int64_t disksize, struct proc *p, void *args, kauth_cred_t cred);
874
875 OSErr hfs_ValidateHFSPlusVolumeHeader(struct hfsmount *hfsmp, HFSPlusVolumeHeader *vhp);
876
877 extern int hfsUnmount(struct hfsmount *hfsmp, struct proc *p);
878
879 extern bool overflow_extents(struct filefork *fp);
880
881 extern int hfs_owner_rights(struct hfsmount *hfsmp, uid_t cnode_uid, kauth_cred_t cred,
882 struct proc *p, int invokesuperuserstatus);
883
884 extern int check_for_dataless_file(struct vnode *vp, uint64_t op_type);
885 extern int hfs_generate_document_id(struct hfsmount *hfsmp, uint32_t *docid);
886 extern void hfs_pin_fs_metadata(struct hfsmount *hfsmp);
887
888 /* Return information about number of metadata blocks for volume */
889 extern int hfs_getinfo_metadata_blocks(struct hfsmount *hfsmp, struct hfsinfo_metadata *hinfo);
890
891 /*
892 * Journal lock function prototypes
893 */
894 int hfs_lock_global (struct hfsmount *hfsmp, enum hfs_locktype locktype);
895 void hfs_unlock_global (struct hfsmount *hfsmp);
896
897 /* HFS mount lock/unlock prototypes */
898 void hfs_lock_mount (struct hfsmount *hfsmp);
899 void hfs_unlock_mount (struct hfsmount *hfsmp);
900
901
902 /* HFS System file locking */
903 #define SFL_CATALOG 0x0001
904 #define SFL_EXTENTS 0x0002
905 #define SFL_BITMAP 0x0004
906 #define SFL_ATTRIBUTE 0x0008
907 #define SFL_STARTUP 0x0010
908 #define SFL_VM_PRIV 0x0020
909 #define SFL_VALIDMASK (SFL_CATALOG | SFL_EXTENTS | SFL_BITMAP | SFL_ATTRIBUTE | SFL_STARTUP | SFL_VM_PRIV)
910
911 extern u_int32_t GetFileInfo(ExtendedVCB *vcb, u_int32_t dirid, const char *name,
912 struct cat_attr *fattr, struct cat_fork *forkinfo);
913
914 extern void hfs_remove_orphans(struct hfsmount *);
915
916 u_int32_t GetLogicalBlockSize(struct vnode *vp);
917
918 extern u_int32_t hfs_free_cnids(struct hfsmount * hfsmp);
919 extern u_int32_t hfs_freeblks(struct hfsmount * hfsmp, int wantreserve);
920
921 short MacToVFSError(OSErr err);
922
923 void hfs_metadatazone_init(struct hfsmount *hfsmp, int disable);
924
925 /* HFS directory hint functions. */
926 extern directoryhint_t * hfs_getdirhint(struct cnode *, int, int);
927 extern void hfs_reldirhint(struct cnode *, directoryhint_t *);
928 extern void hfs_reldirhints(struct cnode *, int);
929 extern void hfs_insertdirhint(struct cnode *, directoryhint_t *);
930
931 extern int hfs_namecmp(const u_int8_t *str1, size_t len1, const u_int8_t *str2, size_t len2);
932
933 extern int hfs_early_journal_init(struct hfsmount *hfsmp, HFSPlusVolumeHeader *vhp,
934 void *_args, off_t embeddedOffset, daddr64_t mdb_offset,
935 HFSMasterDirectoryBlock *mdbp, kauth_cred_t cred);
936
937 extern int hfs_virtualmetafile(struct cnode *);
938
939 extern int hfs_start_transaction(struct hfsmount *hfsmp);
940 extern int hfs_end_transaction(struct hfsmount *hfsmp);
941 extern void hfs_journal_lock(struct hfsmount *hfsmp);
942 extern void hfs_journal_unlock(struct hfsmount *hfsmp);
943 extern void hfs_syncer_lock(struct hfsmount *hfsmp);
944 extern void hfs_syncer_unlock(struct hfsmount *hfsmp);
945 extern void hfs_syncer_wait(struct hfsmount *hfsmp, struct timespec *ts);
946 extern void hfs_syncer_wakeup(struct hfsmount *hfsmp);
947 extern void hfs_syncer(void *arg, wait_result_t);
948 extern void hfs_sync_ejectable(struct hfsmount *hfsmp);
949
950 typedef enum hfs_flush_mode {
951 HFS_FLUSH_JOURNAL, // Flush journal
952 HFS_FLUSH_JOURNAL_META, // Flush journal and metadata blocks
953 HFS_FLUSH_FULL, // Flush journal and does a cache flush
954 HFS_FLUSH_CACHE, // Flush track cache to media
955 HFS_FLUSH_BARRIER, // Barrier-only flush to ensure write order
956 HFS_FLUSH_JOURNAL_BARRIER // Flush journal with barrier
957 } hfs_flush_mode_t;
958
959 extern errno_t hfs_flush(struct hfsmount *hfsmp, hfs_flush_mode_t mode);
960
961 extern void hfs_trim_callback(void *arg, uint32_t extent_count, const dk_extent_t *extents);
962
963 /* Erase unused Catalog nodes due to <rdar://problem/6947811>. */
964 extern int hfs_erase_unused_nodes(struct hfsmount *hfsmp);
965
966 extern uint64_t hfs_usecs_to_deadline(uint64_t usecs);
967
968 extern int hfs_freeze(struct hfsmount *hfsmp);
969 extern int hfs_thaw(struct hfsmount *hfsmp, const struct proc *process);
970
971 void hfs_close_jvp(hfsmount_t *hfsmp);
972
973 // Return a heap address suitable for logging or tracing
974 uintptr_t obfuscate_addr(void *addr);
975
976 #if CONFIG_HFS_STD
977 int hfs_to_utf8(ExtendedVCB *vcb, const Str31 hfs_str, ByteCount maxDstLen,
978 ByteCount *actualDstLen, unsigned char* dstStr);
979 int utf8_to_hfs(ExtendedVCB *vcb, ByteCount srcLen, const unsigned char* srcStr,
980 Str31 dstStr);
981 int unicode_to_hfs(ExtendedVCB *vcb, ByteCount srcLen, u_int16_t* srcStr, Str31 dstStr, int retry);
982 #endif
983
984 void *hfs_malloc(size_t size);
985 void hfs_free(void *ptr, size_t size);
986 void *hfs_mallocz(size_t size);
987
988 typedef enum {
989 HFS_CNODE_ZONE,
990 HFS_FILEFORK_ZONE,
991 HFS_DIRHINT_ZONE,
992 HFS_NUM_ZONES
993 } hfs_zone_kind_t;
994
995 typedef struct hfs_zone_entry {
996 hfs_zone_kind_t hze_kind;
997 size_t hze_elem_size;
998 const char * hze_name;
999 boolean_t hze_noencrypt;
1000 } hfs_zone_entry_t;
1001
1002 typedef struct hfs_zone {
1003 zone_t hz_zone;
1004 size_t hz_elem_size;
1005 } hfs_zone_t;
1006
1007 void hfs_init_zones(void);
1008 void *hfs_zalloc(hfs_zone_kind_t type);
1009 void hfs_zfree(void *ptr, hfs_zone_kind_t type);
1010
1011 void hfs_sysctl_register(void);
1012 void hfs_sysctl_unregister(void);
1013
1014 #if HFS_MALLOC_DEBUG
1015
1016 void hfs_alloc_trace_disable(void);
1017 void hfs_alloc_trace_enable(void);
1018 bool hfs_dump_allocations(void);
1019
1020 #endif // HFS_MALLOC_DEBUG
1021
1022 /*****************************************************************************
1023 Functions from hfs_vnops.c
1024 ******************************************************************************/
1025 int hfs_write_access(struct vnode *vp, kauth_cred_t cred, struct proc *p, Boolean considerFlags);
1026
1027 int hfs_chmod(struct vnode *vp, int mode, kauth_cred_t cred, struct proc *p);
1028
1029 int hfs_chown(struct vnode *vp, uid_t uid, gid_t gid, kauth_cred_t cred, struct proc *p);
1030
1031 int hfs_vnop_create(struct vnop_create_args *ap);
1032
1033 int hfs_vnop_remove(struct vnop_remove_args*);
1034
1035 #define kMaxSecsForFsync 5
1036 #define HFS_SYNCTRANS 1
1037 extern int hfs_btsync(struct vnode *vp, int sync_transaction);
1038
1039 extern void replace_desc(struct cnode *cp, struct cat_desc *cdp);
1040
1041 extern int hfs_vgetrsrc(struct hfsmount *hfsmp, struct vnode *vp,
1042 struct vnode **rvpp);
1043
1044 typedef enum {
1045 // Push all modifications to disk (including minor ones)
1046 HFS_UPDATE_FORCE = 0x01,
1047 } hfs_update_options_t;
1048
1049 extern int hfs_update(struct vnode *, int options);
1050
1051 typedef enum hfs_sync_mode {
1052 HFS_FSYNC,
1053 HFS_FSYNC_FULL,
1054 HFS_FSYNC_BARRIER
1055 } hfs_fsync_mode_t;
1056
1057 extern int hfs_fsync(struct vnode *, int, hfs_fsync_mode_t, struct proc *);
1058
1059 const struct cat_fork *
1060 hfs_prepare_fork_for_update(filefork_t *ff,
1061 const struct cat_fork *cf,
1062 struct cat_fork *cf_buf,
1063 uint32_t block_size);
1064
1065 struct decmpfs_cnode;
1066 struct decmpfs_cnode *hfs_lazy_init_decmpfs_cnode (struct cnode *cp);
1067
1068 /*****************************************************************************
1069 Functions from hfs_xattr.c
1070 ******************************************************************************/
1071
1072 /*
1073 * Maximum extended attribute size supported for all extended attributes except
1074 * resource fork and finder info.
1075 */
1076 #define HFS_XATTR_MAXSIZE INT32_MAX
1077
1078 /* Number of bits used to represent maximum extended attribute size */
1079 #define HFS_XATTR_SIZE_BITS 31
1080
1081 int hfs_attrkeycompare(HFSPlusAttrKey *searchKey, HFSPlusAttrKey *trialKey);
1082 int hfs_buildattrkey(u_int32_t fileID, const char *attrname, HFSPlusAttrKey *key);
1083 void hfs_xattr_init(struct hfsmount * hfsmp);
1084 int file_attribute_exist(struct hfsmount *hfsmp, uint32_t fileID);
1085 int init_attrdata_vnode(struct hfsmount *hfsmp);
1086 int hfs_xattr_read(vnode_t vp, const char *name, void *data, size_t *size);
1087 int hfs_getxattr_internal(cnode_t *, struct vnop_getxattr_args *,
1088 struct hfsmount *, u_int32_t);
1089 int hfs_xattr_write(vnode_t vp, const char *name, const void *data, size_t size);
1090 int hfs_setxattr_internal(struct cnode *, const void *, size_t,
1091 struct vnop_setxattr_args *, struct hfsmount *, u_int32_t);
1092 extern int hfs_removeallattr(struct hfsmount *hfsmp, u_int32_t fileid,
1093 bool *open_transaction);
1094 extern int hfs_set_volxattr(struct hfsmount *hfsmp, unsigned int xattrtype, int state);
1095
1096
1097
1098 /*****************************************************************************
1099 Functions from hfs_link.c
1100 ******************************************************************************/
1101
1102 extern int hfs_unlink(struct hfsmount *hfsmp, struct vnode *dvp, struct vnode *vp,
1103 struct componentname *cnp, int skip_reserve);
1104 extern int hfs_lookup_siblinglinks(struct hfsmount *hfsmp, cnid_t linkfileid,
1105 cnid_t *prevlinkid, cnid_t *nextlinkid);
1106 extern int hfs_lookup_lastlink(struct hfsmount *hfsmp, cnid_t linkfileid,
1107 cnid_t *nextlinkid, struct cat_desc *cdesc);
1108 extern void hfs_privatedir_init(struct hfsmount *, enum privdirtype);
1109
1110 extern void hfs_savelinkorigin(cnode_t *cp, cnid_t parentcnid);
1111 extern void hfs_relorigins(struct cnode *cp);
1112 extern void hfs_relorigin(struct cnode *cp, cnid_t parentcnid);
1113 extern int hfs_haslinkorigin(cnode_t *cp);
1114 extern cnid_t hfs_currentparent(cnode_t *cp, bool have_lock);
1115 extern cnid_t hfs_currentcnid(cnode_t *cp);
1116 errno_t hfs_first_link(hfsmount_t *hfsmp, cnode_t *cp, cnid_t *link_id);
1117
1118
1119 /*****************************************************************************
1120 Functions from VolumeAllocation.c
1121 ******************************************************************************/
1122 extern int hfs_isallocated(struct hfsmount *hfsmp, u_int32_t startingBlock, u_int32_t numBlocks);
1123
1124 extern int hfs_count_allocated(struct hfsmount *hfsmp, u_int32_t startBlock,
1125 u_int32_t numBlocks, u_int32_t *alloc_count);
1126
1127 extern int hfs_isrbtree_active (struct hfsmount *hfsmp);
1128
1129 /*****************************************************************************
1130 Functions from hfs_fsinfo.c
1131 ******************************************************************************/
1132 extern errno_t hfs_get_fsinfo(struct hfsmount *hfsmp, void *a_data);
1133 extern void hfs_fsinfo_data_add(struct hfs_fsinfo_data *fsinfo, uint64_t entry);
1134
1135 struct hfs_sysctl_chain {
1136 struct sysctl_oid *oid;
1137 struct hfs_sysctl_chain *next;
1138 };
1139
1140 extern struct hfs_sysctl_chain *sysctl_list;
1141
1142 SYSCTL_DECL(_vfs_generic_hfs);
1143
1144 #define HFS_SYSCTL(kind, parent, flags, name, ...) \
1145 SYSCTL_##kind(parent, flags, name, __VA_ARGS__) \
1146 struct hfs_sysctl_chain hfs_sysctl_##parent##_##name##_chain = { \
1147 .oid = &sysctl_##parent##_##name \
1148 }; \
1149 static __attribute__((__constructor__)) void \
1150 hfs_sysctl_register_##parent##_##name(void) { \
1151 hfs_sysctl_##parent##_##name##_chain.next = sysctl_list; \
1152 sysctl_list = &hfs_sysctl_##parent##_##name##_chain; \
1153 }
1154
1155 __END_DECLS
1156
1157 #undef assert
1158 #define assert Do_not_use_assert__Use_hfs_assert_instead
1159
1160 #endif /* __APPLE_API_PRIVATE */
1161 #endif /* KERNEL */
1162 #endif /* __HFS__ */