]> git.saurik.com Git - apple/xnu.git/blame - bsd/hfs/hfs.h
xnu-1486.2.11.tar.gz
[apple/xnu.git] / bsd / hfs / hfs.h
CommitLineData
1c79356b 1/*
b0d623f7 2 * Copyright (c) 2000-2009 Apple Inc. All rights reserved.
5d5c5d0d 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
A
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.
8f6c56a5 14 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b 27 */
1c79356b
A
28
29#ifndef __HFS__
30#define __HFS__
31
55e303ae
A
32#define HFS_SPARSE_DEV 1
33
b0d623f7 34#if DEBUG
2d21ac55
A
35#define HFS_CHECK_LOCK_ORDER 1
36#endif
37
9bccf70c
A
38#include <sys/appleapiopts.h>
39
40#ifdef KERNEL
41#ifdef __APPLE_API_PRIVATE
1c79356b 42#include <sys/param.h>
1c79356b 43#include <sys/queue.h>
9bccf70c 44#include <sys/mount.h>
9bccf70c
A
45#include <sys/vnode.h>
46#include <sys/quota.h>
1c79356b 47#include <sys/dirent.h>
55e303ae 48#include <sys/event.h>
e2fac8b1 49#include <kern/thread_call.h>
1c79356b 50
91447636
A
51#include <kern/locks.h>
52
b4c24cb9
A
53#include <vfs/vfs_journal.h>
54
1c79356b 55#include <hfs/hfs_format.h>
9bccf70c
A
56#include <hfs/hfs_catalog.h>
57#include <hfs/hfs_cnode.h>
1c79356b
A
58#include <hfs/hfs_macos_defs.h>
59#include <hfs/hfs_encodings.h>
55e303ae 60#include <hfs/hfs_hotfiles.h>
1c79356b 61
1c79356b
A
62/*
63 * Just reported via MIG interface.
64 */
65#define VERSION_STRING "hfs-2 (4-12-99)"
66
67#define HFS_LINK_MAX 32767
68
9bccf70c
A
69#define HFS_MAX_DEFERED_ALLOC (1024*1024)
70
2d21ac55 71// 400 megs is a "big" file (i.e. one that when deleted
55e303ae 72// would touch enough data that we should break it into
2d21ac55 73// multiple separate transactions)
0c530ab8 74#define HFS_BIGFILE_SIZE (400LL * 1024LL * 1024LL)
55e303ae 75
1c79356b
A
76
77enum { kMDBSize = 512 }; /* Size of I/O transfer to read entire MDB */
78
79enum { kMasterDirectoryBlock = 2 }; /* MDB offset on disk in 512-byte blocks */
80enum { kMDBOffset = kMasterDirectoryBlock * 512 }; /* MDB offset on disk in bytes */
81
91447636 82#define kRootDirID kHFSRootFolderID
1c79356b 83
1c79356b 84
0b4e3aa0
A
85/* number of locked buffer caches to hold for b-tree meta data */
86#define kMaxLockedMetaBuffers 32
1c79356b 87
1c79356b
A
88extern struct timezone gTimeZone;
89
1c79356b 90
0b4e3aa0
A
91/* How many free extents to cache per volume */
92#define kMaxFreeExtents 10
93
9bccf70c
A
94/*
95 * HFS_MINFREE gives the minimum acceptable percentage
96 * of file system blocks which may be free (but this
97 * minimum will never exceed HFS_MAXRESERVE bytes). If
98 * the free block count drops below this level only the
99 * superuser may continue to allocate blocks.
100 */
101#define HFS_MINFREE 1
55e303ae
A
102#define HFS_MAXRESERVE ((u_int64_t)(250*1024*1024))
103
104/*
105 * The system distinguishes between the desirable low-disk
106 * notifiaction levels for root volumes and non-root volumes.
107 * The various thresholds are computed as a fraction of the
108 * volume size, all capped at a certain fixed level
109 */
110
b0d623f7
A
111#define HFS_ROOTVERYLOWDISKTRIGGERFRACTION 5
112#define HFS_ROOTVERYLOWDISKTRIGGERLEVEL ((u_int64_t)(125*1024*1024))
113#define HFS_ROOTLOWDISKTRIGGERFRACTION 10
55e303ae 114#define HFS_ROOTLOWDISKTRIGGERLEVEL ((u_int64_t)(250*1024*1024))
b0d623f7 115#define HFS_ROOTLOWDISKSHUTOFFFRACTION 11
55e303ae
A
116#define HFS_ROOTLOWDISKSHUTOFFLEVEL ((u_int64_t)(375*1024*1024))
117
b0d623f7
A
118#define HFS_VERYLOWDISKTRIGGERFRACTION 1
119#define HFS_VERYLOWDISKTRIGGERLEVEL ((u_int64_t)(100*1024*1024))
120#define HFS_LOWDISKTRIGGERFRACTION 2
121#define HFS_LOWDISKTRIGGERLEVEL ((u_int64_t)(150*1024*1024))
122#define HFS_LOWDISKSHUTOFFFRACTION 3
123#define HFS_LOWDISKSHUTOFFLEVEL ((u_int64_t)(200*1024*1024))
9bccf70c 124
1c79356b
A
125/* Internal Data structures*/
126
1c79356b
A
127/* This structure describes the HFS specific mount structure data. */
128typedef struct hfsmount {
91447636
A
129 u_int32_t hfs_flags; /* see below */
130
1c79356b 131 /* Physical Description */
593a1d5f
A
132 u_int32_t hfs_logical_block_size; /* Logical block size of the disk as reported by ioctl(DKIOCGETBLOCKSIZE), always a multiple of 512 */
133 daddr64_t hfs_logical_block_count; /* Number of logical blocks on the disk */
134 daddr64_t hfs_alt_id_sector; /* location of alternate VH/MDB */
135 u_int32_t hfs_physical_block_size; /* Physical block size of the disk as reported by ioctl(DKIOCGETPHYSICALBLOCKSIZE) */
136 u_int32_t hfs_log_per_phys; /* Number of logical blocks per physical block size */
1c79356b
A
137
138 /* Access to VFS and devices */
139 struct mount *hfs_mp; /* filesystem vfs structure */
140 struct vnode *hfs_devvp; /* block device mounted vnode */
91447636
A
141 struct vnode * hfs_extents_vp;
142 struct vnode * hfs_catalog_vp;
143 struct vnode * hfs_allocation_vp;
144 struct vnode * hfs_attribute_vp;
2d21ac55
A
145 struct vnode * hfs_startup_vp;
146 struct vnode * hfs_attrdata_vp; /* pseudo file */
147 struct cnode * hfs_extents_cp;
148 struct cnode * hfs_catalog_cp;
149 struct cnode * hfs_allocation_cp;
150 struct cnode * hfs_attribute_cp;
151 struct cnode * hfs_startup_cp;
91447636
A
152 dev_t hfs_raw_dev; /* device mounted */
153 u_int32_t hfs_logBlockSize; /* Size of buffer cache buffer for I/O */
1c79356b
A
154
155 /* Default values for HFS standard and non-init access */
91447636
A
156 uid_t hfs_uid; /* uid to set as owner of the files */
157 gid_t hfs_gid; /* gid to set as owner of the files */
158 mode_t hfs_dir_mask; /* mask to and with directory protection bits */
159 mode_t hfs_file_mask; /* mask to and with file protection bits */
b0d623f7 160 u_int32_t hfs_encoding; /* Default encoding for non hfs+ volumes */
91447636
A
161
162 /* Persistent fields (on disk, dynamic) */
163 time_t hfs_mtime; /* file system last modification time */
164 u_int32_t hfs_filecount; /* number of files in file system */
165 u_int32_t hfs_dircount; /* number of directories in file system */
166 u_int32_t freeBlocks; /* free allocation blocks */
167 u_int32_t nextAllocation; /* start of next allocation search */
b0d623f7 168 u_int32_t sparseAllocation; /* start of allocations for sparse devices */
2d21ac55 169 u_int32_t vcbNxtCNID; /* next unused catalog node ID - protected by catalog lock */
91447636
A
170 u_int32_t vcbWrCnt; /* file system write count */
171 u_int64_t encodingsBitmap; /* in-use encodings */
172 u_int16_t vcbNmFls; /* HFS Only - root dir file count */
173 u_int16_t vcbNmRtDirs; /* HFS Only - root dir directory count */
174
175 /* Persistent fields (on disk, static) */
176 u_int16_t vcbSigWord;
2d21ac55 177 int16_t vcbFlags; /* Runtime flag to indicate if volume is dirty/clean */
91447636
A
178 u_int32_t vcbAtrb;
179 u_int32_t vcbJinfoBlock;
180 time_t hfs_itime; /* file system creation time */
181 time_t hfs_btime; /* file system last backup time */
182 u_int32_t blockSize; /* size of allocation blocks */
183 u_int32_t totalBlocks; /* total allocation blocks */
2d21ac55
A
184 u_int32_t allocLimit; /* Do not allocate this block or beyond */
185 /*
186 * NOTE: When resizing a volume to make it smaller, allocLimit is set to the allocation
187 * block number which will contain the new alternate volume header. At all other times,
188 * allocLimit is set to totalBlocks. The allocation code uses allocLimit instead of
189 * totalBlocks to limit which blocks may be allocated, so that during a resize, we don't
190 * put new content into the blocks we're trying to truncate away.
191 */
91447636
A
192 int32_t vcbClpSiz;
193 u_int32_t vcbFndrInfo[8];
194 int16_t vcbVBMSt; /* HFS only */
195 int16_t vcbAlBlSt; /* HFS only */
196
197 /* vcb stuff */
198 u_int8_t vcbVN[256]; /* volume name in UTF-8 */
199 u_int32_t volumeNameEncodingHint;
200 u_int32_t hfsPlusIOPosOffset; /* Disk block where HFS+ starts */
201 u_int32_t vcbVBMIOSize; /* volume bitmap I/O size */
202
203 /* cache of largest known free extents */
204 u_int32_t vcbFreeExtCnt;
205 HFSPlusExtentDescriptor vcbFreeExt[kMaxFreeExtents];
206
207 u_int32_t reserveBlocks; /* free block reserve */
208 u_int32_t loanedBlocks; /* blocks on loan for delayed allocations */
209
210 u_int32_t localCreateDate; /* creation times for HFS+ volumes are in local time */
2d21ac55
A
211
212 /*
213 * HFS+ Private system directories (two). Any access
214 * (besides looking at the cd_cnid) requires holding
215 * the Catalog File lock.
216 */
217 struct cat_desc hfs_private_desc[2];
218 struct cat_attr hfs_private_attr[2];
219
1c79356b
A
220 u_int32_t hfs_metadata_createdate;
221 hfs_to_unicode_func_t hfs_get_unicode;
222 unicode_to_hfs_func_t hfs_get_hfsname;
9bccf70c 223
55e303ae 224 /* Quota variables: */
9bccf70c 225 struct quotafile hfs_qfiles[MAXQUOTAS]; /* quota files */
b4c24cb9 226
55e303ae 227 /* Journaling variables: */
b4c24cb9
A
228 void *jnl; // the journal for this volume (if one exists)
229 struct vnode *jvp; // device where the journal lives (may be equal to devvp)
230 u_int32_t jnl_start; // start block of the journal file (so we don't delete it)
55e303ae 231 u_int32_t jnl_size;
b4c24cb9
A
232 u_int32_t hfs_jnlfileid;
233 u_int32_t hfs_jnlinfoblkid;
91447636
A
234 lck_rw_t hfs_global_lock;
235 u_int32_t hfs_global_lock_nesting;
55e303ae
A
236
237 /* Notification variables: */
b0d623f7
A
238 u_int32_t hfs_notification_conditions;
239 u_int32_t hfs_freespace_notify_dangerlimit;
55e303ae
A
240 u_int32_t hfs_freespace_notify_warninglimit;
241 u_int32_t hfs_freespace_notify_desiredlevel;
242
91447636
A
243 /* time mounted and last mounted mod time "snapshot" */
244 time_t hfs_mount_time;
245 time_t hfs_last_mounted_mtime;
246
55e303ae
A
247 /* Metadata allocation zone variables: */
248 u_int32_t hfs_metazone_start;
249 u_int32_t hfs_metazone_end;
250 u_int32_t hfs_hotfile_start;
251 u_int32_t hfs_hotfile_end;
b0d623f7
A
252 u_int32_t hfs_min_alloc_start;
253 u_int32_t hfs_freed_block_count;
55e303ae
A
254 int hfs_hotfile_freeblks;
255 int hfs_hotfile_maxblks;
256 int hfs_overflow_maxblks;
257 int hfs_catalog_maxblks;
258
259 /* Hot File Clustering variables: */
91447636 260 lck_mtx_t hfc_mutex; /* serialize hot file stages */
55e303ae
A
261 enum hfc_stage hfc_stage; /* what are we up to... */
262 time_t hfc_timebase; /* recording period start time */
263 time_t hfc_timeout; /* recording period stop time */
264 void * hfc_recdata; /* recording data (opaque) */
265 int hfc_maxfiles; /* maximum files to track */
266 struct vnode * hfc_filevp;
267
268#ifdef HFS_SPARSE_DEV
269 /* Sparse device variables: */
270 struct vnode * hfs_backingfs_rootvp;
2d21ac55 271 u_int32_t hfs_last_backingstatfs;
55e303ae 272 int hfs_sparsebandblks;
b0d623f7 273 u_int64_t hfs_backingfs_maxblocks;
55e303ae 274#endif
91447636
A
275 size_t hfs_max_inline_attrsize;
276
277 lck_mtx_t hfs_mutex; /* protects access to hfsmount data */
278 void *hfs_freezing_proc; /* who froze the fs */
c910b4d9 279 void *hfs_downgrading_proc; /* process who's downgrading to rdonly */
3a60a9f5 280 lck_rw_t hfs_insync; /* protects sync/freeze interaction */
0c530ab8
A
281
282 /* Resize variables: */
283 u_int32_t hfs_resize_filesmoved;
284 u_int32_t hfs_resize_totalfiles;
e2fac8b1 285
b0d623f7
A
286 /* Per mount cnode hash variables: */
287 lck_mtx_t hfs_chash_mutex; /* protects access to cnode hash table */
288 u_long hfs_cnodehash; /* size of cnode hash table - 1 */
289 LIST_HEAD(cnodehashhead, cnode) *hfs_cnodehashtbl; /* base of cnode hash */
290
291
e2fac8b1
A
292 /*
293 * About the sync counters:
294 * hfs_sync_scheduled keeps track whether a timer was scheduled but we
295 * haven't started processing the callback (i.e. we
296 * haven't begun the flush). This will be non-zero
297 * even if the callback has been invoked, before we
298 * start the flush.
299 * hfs_sync_incomplete keeps track of the number of callbacks that have
300 * not completed yet (including callbacks not yet
301 * invoked). We cannot safely unmount until this
302 * drops to zero.
303 *
304 * In both cases, we use counters, not flags, so that we can avoid
305 * taking locks.
306 */
307 int32_t hfs_sync_scheduled;
308 int32_t hfs_sync_incomplete;
309 u_int64_t hfs_last_sync_request_time;
310 u_int64_t hfs_last_sync_time;
b0d623f7
A
311 u_int32_t hfs_active_threads;
312 u_int64_t hfs_max_pending_io;
313
e2fac8b1
A
314 thread_call_t hfs_syncer; // removeable devices get sync'ed by this guy
315
1c79356b
A
316} hfsmount_t;
317
e2fac8b1
A
318#define HFS_META_DELAY (100)
319#define HFS_MILLISEC_SCALE (1000*1000)
320
91447636
A
321typedef hfsmount_t ExtendedVCB;
322
2d21ac55 323/* Aliases for legacy (Mac OS 9) field names */
91447636
A
324#define vcbCrDate hfs_itime
325#define vcbLsMod hfs_mtime
326#define vcbVolBkUp hfs_btime
327#define extentsRefNum hfs_extents_vp
328#define catalogRefNum hfs_catalog_vp
329#define allocationsRefNum hfs_allocation_vp
330#define vcbFilCnt hfs_filecount
331#define vcbDirCnt hfs_dircount
332
2d21ac55
A
333/* Inline functions to set/reset vcbFlags. Upper 8 bits indicate if the volume
334 * header/VCB is clean/dirty --- if set, volume header is dirty, and
335 * if clear, volume header is clean. This value is checked to determine
336 * if the in-memory copy of volume header should be flushed to the disk
337 * or not.
338 */
339/* Set runtime flag to indicate that volume is dirty */
340static __inline__ void MarkVCBDirty(ExtendedVCB *vcb)
341{
342 vcb->vcbFlags |= 0xFF00;
343}
344
345/* Clear runtime flag to indicate that volume is dirty */
346static __inline__ void MarkVCBClean(ExtendedVCB *vcb)
347{
348 vcb->vcbFlags &= 0x00FF;
349}
350
351/* Check runtime flag to determine if the volume is dirty or not */
352static __inline__ Boolean IsVCBDirty(ExtendedVCB *vcb)
353{
354 return (vcb->vcbFlags & 0xFF00 ? true : false);
355}
55e303ae 356
2d21ac55
A
357/*
358 * There are two private directories in HFS+.
359 *
360 * One contains inodes for files that are hardlinked or open/unlinked.
361 * The other contains inodes for directories that are hardlinked.
362 */
363enum privdirtype {FILE_HARDLINKS, DIR_HARDLINKS};
55e303ae 364
1c79356b 365
2d21ac55
A
366/* HFS mount point flags */
367#define HFS_READ_ONLY 0x00001
368#define HFS_UNKNOWN_PERMS 0x00002
369#define HFS_WRITEABLE_MEDIA 0x00004
370#define HFS_CLEANED_ORPHANS 0x00008
371#define HFS_X 0x00010
372#define HFS_CASE_SENSITIVE 0x00020
373#define HFS_STANDARD 0x00040
374#define HFS_METADATA_ZONE 0x00080
375#define HFS_FRAGMENTED_FREESPACE 0x00100
376#define HFS_NEED_JNL_RESET 0x00200
377#define HFS_HAS_SPARSE_DEVICE 0x00400
378#define HFS_RESIZE_IN_PROGRESS 0x00800
379#define HFS_QUOTAS 0x01000
380#define HFS_CREATING_BTREE 0x02000
381/* When set, do not update nextAllocation in the mount structure */
382#define HFS_SKIP_UPDATE_NEXT_ALLOCATION 0x04000
383#define HFS_XATTR_EXTENTS 0x08000
384#define HFS_FOLDERCOUNT 0x10000
385/* When set, the file system exists on a virtual device, like disk image */
386#define HFS_VIRTUAL_DEVICE 0x20000
593a1d5f
A
387/* When set, we're in hfs_changefs, so hfs_sync should do nothing. */
388#define HFS_IN_CHANGEFS 0x40000
c910b4d9 389/* When set, we are in process of downgrading or have downgraded to read-only,
b0d623f7
A
390 * so hfs_start_transaction should return EROFS.
391 */
c910b4d9 392#define HFS_RDONLY_DOWNGRADE 0x80000
b0d623f7 393#define HFS_DID_CONTIG_SCAN 0x100000
2d21ac55
A
394
395
396/* Macro to update next allocation block in the HFS mount structure. If
397 * the HFS_SKIP_UPDATE_NEXT_ALLOCATION is set, do not update
398 * nextAllocation block.
399 */
400#define HFS_UPDATE_NEXT_ALLOCATION(hfsmp, new_nextAllocation) \
401 { \
402 if ((hfsmp->hfs_flags & HFS_SKIP_UPDATE_NEXT_ALLOCATION) == 0)\
403 hfsmp->nextAllocation = new_nextAllocation; \
404 } \
405
91447636
A
406#define HFS_MOUNT_LOCK(hfsmp, metadata) \
407 { \
408 if ((metadata) && 1) \
409 lck_mtx_lock(&(hfsmp)->hfs_mutex); \
410 } \
411
412#define HFS_MOUNT_UNLOCK(hfsmp, metadata) \
413 { \
414 if ((metadata) && 1) \
415 lck_mtx_unlock(&(hfsmp)->hfs_mutex); \
416 } \
417
418#define hfs_global_exclusive_lock_acquire(hfsmp) lck_rw_lock_exclusive(&(hfsmp)->hfs_global_lock)
2d21ac55 419#define hfs_global_exclusive_lock_release(hfsmp) lck_rw_unlock_exclusive(&(hfsmp)->hfs_global_lock)
1c79356b 420
2d21ac55
A
421/* Macro for incrementing and decrementing the folder count in a cnode
422 * attribute only if the HFS_FOLDERCOUNT bit is set in the mount flags
423 * and kHFSHasFolderCount bit is set in the cnode flags. Currently these
424 * bits are only set for case sensitive HFS+ volumes.
425 */
426#define INC_FOLDERCOUNT(hfsmp, cattr) \
427 if ((hfsmp->hfs_flags & HFS_FOLDERCOUNT) && \
428 (cattr.ca_recflags & kHFSHasFolderCountMask)) { \
429 cattr.ca_dircount++; \
430 } \
431
432#define DEC_FOLDERCOUNT(hfsmp, cattr) \
433 if ((hfsmp->hfs_flags & HFS_FOLDERCOUNT) && \
434 (cattr.ca_recflags & kHFSHasFolderCountMask) && \
435 (cattr.ca_dircount > 0)) { \
436 cattr.ca_dircount--; \
437 } \
1c79356b 438
9bccf70c 439typedef struct filefork FCB;
1c79356b 440
2d21ac55
A
441/*
442 * Macros for creating item names for our special/private directories.
443 */
444#define MAKE_INODE_NAME(name, size, linkno) \
445 (void) snprintf((name), size, "%s%d", HFS_INODE_PREFIX, (linkno))
446#define HFS_INODE_PREFIX_LEN 5
1c79356b 447
2d21ac55
A
448#define MAKE_DIRINODE_NAME(name, size, linkno) \
449 (void) snprintf((name), size, "%s%d", HFS_DIRINODE_PREFIX, (linkno))
450#define HFS_DIRINODE_PREFIX_LEN 4
1c79356b 451
2d21ac55
A
452#define MAKE_DELETED_NAME(NAME, size, FID) \
453 (void) snprintf((NAME), size, "%s%d", HFS_DELETE_PREFIX, (FID))
454#define HFS_DELETE_PREFIX_LEN 4
1c79356b 455
1c79356b 456
9bccf70c
A
457#define HFS_AVERAGE_NAME_SIZE 22
458#define AVERAGE_HFSDIRENTRY_SIZE (8+HFS_AVERAGE_NAME_SIZE+4)
1c79356b 459
91447636
A
460#define STD_DIRENT_LEN(namlen) \
461 ((sizeof(struct dirent) - (NAME_MAX+1)) + (((namlen)+1 + 3) &~ 3))
1c79356b 462
91447636
A
463#define EXT_DIRENT_LEN(namlen) \
464 ((sizeof(struct direntry) + (namlen) - (MAXPATHLEN-1) + 3) & ~3)
1c79356b 465
1c79356b
A
466
467enum { kHFSPlusMaxFileNameBytes = kHFSPlusMaxFileNameChars * 3 };
468
1c79356b
A
469
470/* macro to determine if hfs or hfsplus */
471#define ISHFSPLUS(VCB) ((VCB)->vcbSigWord == kHFSPlusSigWord)
472#define ISHFS(VCB) ((VCB)->vcbSigWord == kHFSSigWord)
473
474
1c79356b
A
475/*
476 * Various ways to acquire a VFS mount point pointer:
477 */
91447636 478#define VTOVFS(VP) vnode_mount((VP))
1c79356b 479#define HFSTOVFS(HFSMP) ((HFSMP)->hfs_mp)
91447636 480#define VCBTOVFS(VCB) HFSTOVFS(VCB)
1c79356b
A
481
482/*
483 * Various ways to acquire an HFS mount point pointer:
484 */
91447636
A
485#define VTOHFS(VP) ((struct hfsmount *)vfs_fsprivate(vnode_mount((VP))))
486#define VFSTOHFS(MP) ((struct hfsmount *)vfs_fsprivate((MP)))
487#define VCBTOHFS(VCB) (VCB)
488#define FCBTOHFS(FCB) ((struct hfsmount *)vfs_fsprivate(vnode_mount((FCB)->ff_cp->c_vp)))
1c79356b
A
489
490/*
91447636 491 * Various ways to acquire a VCB (legacy) pointer:
1c79356b 492 */
91447636
A
493#define VTOVCB(VP) VTOHFS(VP)
494#define VFSTOVCB(MP) VFSTOHFS(MP)
495#define HFSTOVCB(HFSMP) (HFSMP)
496#define FCBTOVCB(FCB) FCBTOHFS(FCB)
1c79356b
A
497
498
499#define E_NONE 0
500#define kHFSBlockSize 512
1c79356b 501
9bccf70c
A
502/*
503 * Macros for getting the MDB/VH sector and offset
504 */
505#define HFS_PRI_SECTOR(blksize) (1024 / (blksize))
506#define HFS_PRI_OFFSET(blksize) ((blksize) > 1024 ? 1024 : 0)
d52fe63f
A
507
508#define HFS_ALT_SECTOR(blksize, blkcnt) (((blkcnt) - 1) - (512 / (blksize)))
509#define HFS_ALT_OFFSET(blksize) ((blksize) > 1024 ? (blksize) - 1024 : 0)
510
593a1d5f
A
511/* Convert the logical sector number to be aligned on physical block size boundary.
512 * We are assuming the partition is a multiple of physical block size.
513 */
514#define HFS_PHYSBLK_ROUNDDOWN(sector_num, log_per_phys) ((sector_num / log_per_phys) * log_per_phys)
91447636
A
515
516/*
517 * HFS specific fcntl()'s
518 */
519#define HFS_BULKACCESS (FCNTL_FS_SPECIFIC_BASE + 0x00001)
520#define HFS_GET_MOUNT_TIME (FCNTL_FS_SPECIFIC_BASE + 0x00002)
521#define HFS_GET_LAST_MTIME (FCNTL_FS_SPECIFIC_BASE + 0x00003)
522#define HFS_GET_BOOT_INFO (FCNTL_FS_SPECIFIC_BASE + 0x00004)
523#define HFS_SET_BOOT_INFO (FCNTL_FS_SPECIFIC_BASE + 0x00005)
2d21ac55 524#define HFS_EXT_BULKACCESS (FCNTL_FS_SPECIFIC_BASE + 0x00006)
91447636
A
525
526
1c79356b
A
527/*
528 * This is the straight GMT conversion constant:
529 * 00:00:00 January 1, 1970 - 00:00:00 January 1, 1904
530 * (3600 * 24 * ((365 * (1970 - 1904)) + (((1970 - 1904) / 4) + 1)))
531 */
532#define MAC_GMT_FACTOR 2082844800UL
533
1c79356b 534
2d21ac55
A
535/*****************************************************************************
536 FUNCTION PROTOTYPES
537******************************************************************************/
1c79356b 538
1c79356b 539
2d21ac55
A
540/*****************************************************************************
541 hfs_vnop_xxx functions from different files
542******************************************************************************/
543int hfs_vnop_readdirattr(struct vnop_readdirattr_args *); /* in hfs_attrlist.c */
1c79356b 544
2d21ac55
A
545int hfs_vnop_inactive(struct vnop_inactive_args *); /* in hfs_cnode.c */
546int hfs_vnop_reclaim(struct vnop_reclaim_args *); /* in hfs_cnode.c */
9bccf70c 547
2d21ac55 548int hfs_vnop_link(struct vnop_link_args *); /* in hfs_link.c */
9bccf70c 549
2d21ac55 550int hfs_vnop_lookup(struct vnop_lookup_args *); /* in hfs_lookup.c */
b4c24cb9 551
2d21ac55 552int hfs_vnop_search(struct vnop_searchfs_args *); /* in hfs_search.c */
1c79356b 553
2d21ac55
A
554int hfs_vnop_read(struct vnop_read_args *); /* in hfs_readwrite.c */
555int hfs_vnop_write(struct vnop_write_args *); /* in hfs_readwrite.c */
556int hfs_vnop_ioctl(struct vnop_ioctl_args *); /* in hfs_readwrite.c */
557int hfs_vnop_select(struct vnop_select_args *); /* in hfs_readwrite.c */
558int hfs_vnop_strategy(struct vnop_strategy_args *); /* in hfs_readwrite.c */
559int hfs_vnop_allocate(struct vnop_allocate_args *); /* in hfs_readwrite.c */
560int hfs_vnop_pagein(struct vnop_pagein_args *); /* in hfs_readwrite.c */
561int hfs_vnop_pageout(struct vnop_pageout_args *); /* in hfs_readwrite.c */
562int hfs_vnop_bwrite(struct vnop_bwrite_args *); /* in hfs_readwrite.c */
563int hfs_vnop_blktooff(struct vnop_blktooff_args *); /* in hfs_readwrite.c */
564int hfs_vnop_offtoblk(struct vnop_offtoblk_args *); /* in hfs_readwrite.c */
565int hfs_vnop_blockmap(struct vnop_blockmap_args *); /* in hfs_readwrite.c */
1c79356b 566
2d21ac55
A
567int hfs_vnop_getxattr(struct vnop_getxattr_args *); /* in hfs_xattr.c */
568int hfs_vnop_setxattr(struct vnop_setxattr_args *); /* in hfs_xattr.c */
569int hfs_vnop_removexattr(struct vnop_removexattr_args *); /* in hfs_xattr.c */
570int hfs_vnop_listxattr(struct vnop_listxattr_args *); /* in hfs_xattr.c */
571#if NAMEDSTREAMS
572extern int hfs_vnop_getnamedstream(struct vnop_getnamedstream_args*);
573extern int hfs_vnop_makenamedstream(struct vnop_makenamedstream_args*);
574extern int hfs_vnop_removenamedstream(struct vnop_removenamedstream_args*);
575#endif
9bccf70c 576
1c79356b 577
2d21ac55
A
578/*****************************************************************************
579 Functions from MacOSStubs.c
580******************************************************************************/
581time_t to_bsd_time(u_int32_t hfs_time);
9bccf70c 582
2d21ac55 583u_int32_t to_hfs_time(time_t bsd_time);
1c79356b 584
1c79356b 585
2d21ac55
A
586/*****************************************************************************
587 Functions from hfs_encodinghint.c
588******************************************************************************/
589u_int32_t hfs_pickencoding(const u_int16_t *src, int len);
9bccf70c 590
2d21ac55 591u_int32_t hfs_getencodingbias(void);
1c79356b 592
2d21ac55 593void hfs_setencodingbias(u_int32_t bias);
b4c24cb9 594
2d21ac55
A
595
596/*****************************************************************************
597 Functions from hfs_encodings.c
598******************************************************************************/
599void hfs_converterinit(void);
1c79356b
A
600
601int hfs_getconverter(u_int32_t encoding, hfs_to_unicode_func_t *get_unicode,
602 unicode_to_hfs_func_t *get_hfsname);
603
604int hfs_relconverter(u_int32_t encoding);
605
2d21ac55 606int hfs_to_utf8(ExtendedVCB *vcb, const Str31 hfs_str, ByteCount maxDstLen,
1c79356b
A
607 ByteCount *actualDstLen, unsigned char* dstStr);
608
609int utf8_to_hfs(ExtendedVCB *vcb, ByteCount srcLen, const unsigned char* srcStr,
610 Str31 dstStr);
611
2d21ac55 612int mac_roman_to_utf8(const Str31 hfs_str, ByteCount maxDstLen, ByteCount *actualDstLen,
1c79356b
A
613 unsigned char* dstStr);
614
615int utf8_to_mac_roman(ByteCount srcLen, const unsigned char* srcStr, Str31 dstStr);
616
2d21ac55 617int mac_roman_to_unicode(const Str31 hfs_str, UniChar *uni_str, u_int32_t maxCharLen, u_int32_t *usedCharLen);
0b4e3aa0 618
2d21ac55 619int unicode_to_hfs(ExtendedVCB *vcb, ByteCount srcLen, u_int16_t* srcStr, Str31 dstStr, int retry);
9bccf70c 620
9bccf70c 621
2d21ac55
A
622/*****************************************************************************
623 Functions from hfs_notifications.c
624******************************************************************************/
625void hfs_generate_volume_notifications(struct hfsmount *hfsmp);
9bccf70c
A
626
627
2d21ac55
A
628/*****************************************************************************
629 Functions from hfs_readwrite.c
630******************************************************************************/
631extern int hfs_relocate(struct vnode *, u_int32_t, kauth_cred_t, struct proc *);
9bccf70c 632
b0d623f7 633extern int hfs_truncate(struct vnode *, off_t, int, int, int, vfs_context_t);
d7e50217 634
2d21ac55 635extern int hfs_bmap(struct vnode *, daddr_t, struct vnode **, daddr64_t *, unsigned int *);
55e303ae 636
2d21ac55 637extern int hfs_fsync(struct vnode *, int, int, struct proc *);
55e303ae 638
2d21ac55 639extern int hfs_access(struct vnode *, mode_t, kauth_cred_t, struct proc *);
91447636 640
2d21ac55 641extern int hfs_removeallattr(struct hfsmount *hfsmp, u_int32_t fileid);
91447636 642
2d21ac55 643extern int hfs_set_volxattr(struct hfsmount *hfsmp, unsigned int xattrtype, int state);
91447636 644
2d21ac55 645extern void hfs_check_volxattr(struct hfsmount *hfsmp, unsigned int xattrtype);
91447636 646
b0d623f7 647extern int hfs_isallocated(struct hfsmount *, u_int32_t, u_int32_t);
91447636 648
91447636 649
2d21ac55
A
650/*****************************************************************************
651 Functions from hfs_vfsops.c
652******************************************************************************/
653int hfs_mountroot(mount_t mp, vnode_t rvp, vfs_context_t context);
91447636 654
2d21ac55
A
655/* used as a callback by the journaling code */
656extern void hfs_sync_metadata(void *arg);
91447636 657
2d21ac55 658extern int hfs_vget(struct hfsmount *, cnid_t, struct vnode **, int);
91447636 659
2d21ac55 660extern void hfs_setencodingbits(struct hfsmount *hfsmp, u_int32_t encoding);
91447636 661
2d21ac55
A
662enum volop {VOL_UPDATE, VOL_MKDIR, VOL_RMDIR, VOL_MKFILE, VOL_RMFILE};
663extern int hfs_volupdate(struct hfsmount *hfsmp, enum volop op, int inroot);
664
665int hfs_flushvolumeheader(struct hfsmount *hfsmp, int waitfor, int altflush);
666#define HFS_ALTFLUSH 1
91447636
A
667
668extern int hfs_extendfs(struct hfsmount *, u_int64_t, vfs_context_t);
669extern int hfs_truncatefs(struct hfsmount *, u_int64_t, vfs_context_t);
0c530ab8 670extern int hfs_resize_progress(struct hfsmount *, u_int32_t *);
91447636 671
2d21ac55
A
672/* If a runtime corruption is detected, mark the volume inconsistent
673 * bit in the volume attributes.
674 */
675void hfs_mark_volume_inconsistent(struct hfsmount *hfsmp);
676
677/*****************************************************************************
678 Functions from hfs_vfsutils.c
679******************************************************************************/
b0d623f7
A
680u_int32_t BestBlockSizeFit(u_int32_t allocationBlockSize,
681 u_int32_t blockSizeLimit,
682 u_int32_t baseMultiple);
2d21ac55
A
683
684OSErr hfs_MountHFSVolume(struct hfsmount *hfsmp, HFSMasterDirectoryBlock *mdb,
685 struct proc *p);
686OSErr hfs_MountHFSPlusVolume(struct hfsmount *hfsmp, HFSPlusVolumeHeader *vhp,
687 off_t embeddedOffset, u_int64_t disksize, struct proc *p, void *args, kauth_cred_t cred);
688
689extern int hfsUnmount(struct hfsmount *hfsmp, struct proc *p);
690
691extern int overflow_extents(struct filefork *fp);
692
693extern int hfs_owner_rights(struct hfsmount *hfsmp, uid_t cnode_uid, kauth_cred_t cred,
694 struct proc *p, int invokesuperuserstatus);
91447636
A
695
696
697/* HFS System file locking */
698#define SFL_CATALOG 0x0001
699#define SFL_EXTENTS 0x0002
700#define SFL_BITMAP 0x0004
701#define SFL_ATTRIBUTE 0x0008
2d21ac55
A
702#define SFL_STARTUP 0x0010
703#define SFL_VALIDMASK (SFL_CATALOG | SFL_EXTENTS | SFL_BITMAP | SFL_ATTRIBUTE | SFL_STARTUP)
91447636
A
704
705extern int hfs_systemfile_lock(struct hfsmount *, int, enum hfslocktype);
706extern void hfs_systemfile_unlock(struct hfsmount *, int);
d7e50217 707
b0d623f7 708extern u_int32_t GetFileInfo(ExtendedVCB *vcb, u_int32_t dirid, const char *name,
2d21ac55
A
709 struct cat_attr *fattr, struct cat_fork *forkinfo);
710
711extern void hfs_remove_orphans(struct hfsmount *);
712
713u_int32_t GetLogicalBlockSize(struct vnode *vp);
714
715extern u_int32_t hfs_freeblks(struct hfsmount * hfsmp, int wantreserve);
716
717short MacToVFSError(OSErr err);
718
719/* HFS directory hint functions. */
720extern directoryhint_t * hfs_getdirhint(struct cnode *, int, int);
721extern void hfs_reldirhint(struct cnode *, directoryhint_t *);
722extern void hfs_reldirhints(struct cnode *, int);
723extern void hfs_insertdirhint(struct cnode *, directoryhint_t *);
724
725extern int hfs_namecmp(const u_int8_t *str1, size_t len1, const u_int8_t *str2, size_t len2);
726
727extern int hfs_early_journal_init(struct hfsmount *hfsmp, HFSPlusVolumeHeader *vhp,
728 void *_args, off_t embeddedOffset, daddr64_t mdb_offset,
729 HFSMasterDirectoryBlock *mdbp, kauth_cred_t cred);
730
731extern int hfs_virtualmetafile(struct cnode *);
732
733extern int hfs_start_transaction(struct hfsmount *hfsmp);
734extern int hfs_end_transaction(struct hfsmount *hfsmp);
b0d623f7 735extern int hfs_journal_flush(struct hfsmount *hfsmp);
e2fac8b1 736extern void hfs_sync_ejectable(struct hfsmount *hfsmp);
2d21ac55 737
b0d623f7
A
738/* Erase unused Catalog nodes due to <rdar://problem/6947811>. */
739extern int hfs_erase_unused_nodes(struct hfsmount *hfsmp);
740
2d21ac55
A
741
742/*****************************************************************************
743 Functions from hfs_vnops.c
744******************************************************************************/
745int hfs_write_access(struct vnode *vp, kauth_cred_t cred, struct proc *p, Boolean considerFlags);
746
747int hfs_chmod(struct vnode *vp, int mode, kauth_cred_t cred, struct proc *p);
748
749int hfs_chown(struct vnode *vp, uid_t uid, gid_t gid, kauth_cred_t cred, struct proc *p);
750
751#define kMaxSecsForFsync 5
752#define HFS_SYNCTRANS 1
753extern int hfs_btsync(struct vnode *vp, int sync_transaction);
754
755extern void replace_desc(struct cnode *cp, struct cat_desc *cdp);
756
757extern int hfs_vgetrsrc(struct hfsmount *hfsmp, struct vnode *vp,
758 struct vnode **rvpp, int can_drop_lock);
759
760extern int hfs_update(struct vnode *, int);
761
762
763/*****************************************************************************
764 Functions from hfs_xattr.c
765******************************************************************************/
766int hfs_attrkeycompare(HFSPlusAttrKey *searchKey, HFSPlusAttrKey *trialKey);
767int hfs_buildattrkey(u_int32_t fileID, const char *attrname, HFSPlusAttrKey *key);
768void hfs_xattr_init(struct hfsmount * hfsmp);
769int file_attribute_exist(struct hfsmount *hfsmp, uint32_t fileID);
770
771
772
773/*****************************************************************************
774 Functions from hfs_link.c
775******************************************************************************/
776
777extern int hfs_unlink(struct hfsmount *hfsmp, struct vnode *dvp, struct vnode *vp,
778 struct componentname *cnp, int skip_reserve);
779extern int hfs_lookuplink(struct hfsmount *hfsmp, cnid_t linkfileid,
780 cnid_t *prevlinkid, cnid_t *nextlinkid);
781extern void hfs_privatedir_init(struct hfsmount *, enum privdirtype);
782
783extern void hfs_savelinkorigin(cnode_t *cp, cnid_t parentcnid);
784extern void hfs_relorigins(struct cnode *cp);
785extern void hfs_relorigin(struct cnode *cp, cnid_t parentcnid);
786extern int hfs_haslinkorigin(cnode_t *cp);
787extern cnid_t hfs_currentparent(cnode_t *cp);
788extern cnid_t hfs_currentcnid(cnode_t *cp);
789
790
9bccf70c
A
791#endif /* __APPLE_API_PRIVATE */
792#endif /* KERNEL */
1c79356b 793#endif /* __HFS__ */