2 * Copyright (c) 2000-2007 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 #define HFS_SPARSE_DEV 1
35 #define HFS_CHECK_LOCK_ORDER 1
38 #include <sys/appleapiopts.h>
41 #ifdef __APPLE_API_PRIVATE
42 #include <sys/param.h>
43 #include <sys/queue.h>
44 #include <sys/mount.h>
45 #include <sys/vnode.h>
46 #include <sys/quota.h>
47 #include <sys/dirent.h>
48 #include <sys/event.h>
50 #include <kern/locks.h>
52 #include <vfs/vfs_journal.h>
54 #include <hfs/hfs_format.h>
55 #include <hfs/hfs_catalog.h>
56 #include <hfs/hfs_cnode.h>
57 #include <hfs/hfs_macos_defs.h>
58 #include <hfs/hfs_encodings.h>
59 #include <hfs/hfs_hotfiles.h>
62 * Just reported via MIG interface.
64 #define VERSION_STRING "hfs-2 (4-12-99)"
66 #define HFS_LINK_MAX 32767
68 #define HFS_MAX_DEFERED_ALLOC (1024*1024)
70 // 400 megs is a "big" file (i.e. one that when deleted
71 // would touch enough data that we should break it into
72 // multiple separate transactions)
73 #define HFS_BIGFILE_SIZE (400LL * 1024LL * 1024LL)
76 enum { kMDBSize
= 512 }; /* Size of I/O transfer to read entire MDB */
78 enum { kMasterDirectoryBlock
= 2 }; /* MDB offset on disk in 512-byte blocks */
79 enum { kMDBOffset
= kMasterDirectoryBlock
* 512 }; /* MDB offset on disk in bytes */
81 #define kRootDirID kHFSRootFolderID
84 /* number of locked buffer caches to hold for b-tree meta data */
85 #define kMaxLockedMetaBuffers 32
87 extern struct timezone gTimeZone
;
90 /* How many free extents to cache per volume */
91 #define kMaxFreeExtents 10
94 * HFS_MINFREE gives the minimum acceptable percentage
95 * of file system blocks which may be free (but this
96 * minimum will never exceed HFS_MAXRESERVE bytes). If
97 * the free block count drops below this level only the
98 * superuser may continue to allocate blocks.
100 #define HFS_MINFREE 1
101 #define HFS_MAXRESERVE ((u_int64_t)(250*1024*1024))
104 * The system distinguishes between the desirable low-disk
105 * notifiaction levels for root volumes and non-root volumes.
106 * The various thresholds are computed as a fraction of the
107 * volume size, all capped at a certain fixed level
110 #define HFS_ROOTLOWDISKTRIGGERFRACTION 5
111 #define HFS_ROOTLOWDISKTRIGGERLEVEL ((u_int64_t)(250*1024*1024))
112 #define HFS_ROOTLOWDISKSHUTOFFFRACTION 6
113 #define HFS_ROOTLOWDISKSHUTOFFLEVEL ((u_int64_t)(375*1024*1024))
115 #define HFS_LOWDISKTRIGGERFRACTION 1
116 #define HFS_LOWDISKTRIGGERLEVEL ((u_int64_t)(50*1024*1024))
117 #define HFS_LOWDISKSHUTOFFFRACTION 2
118 #define HFS_LOWDISKSHUTOFFLEVEL ((u_int64_t)(75*1024*1024))
120 /* Internal Data structures*/
122 /* This structure describes the HFS specific mount structure data. */
123 typedef struct hfsmount
{
124 u_int32_t hfs_flags
; /* see below */
126 /* Physical Description */
127 u_long hfs_phys_block_size
; /* Always a multiple of 512 */
128 daddr64_t hfs_phys_block_count
; /* Num of PHYSICAL blocks of volume */
129 daddr64_t hfs_alt_id_sector
; /* location of alternate VH/MDB */
131 /* Access to VFS and devices */
132 struct mount
*hfs_mp
; /* filesystem vfs structure */
133 struct vnode
*hfs_devvp
; /* block device mounted vnode */
134 struct vnode
* hfs_extents_vp
;
135 struct vnode
* hfs_catalog_vp
;
136 struct vnode
* hfs_allocation_vp
;
137 struct vnode
* hfs_attribute_vp
;
138 struct vnode
* hfs_startup_vp
;
139 struct vnode
* hfs_attrdata_vp
; /* pseudo file */
140 struct cnode
* hfs_extents_cp
;
141 struct cnode
* hfs_catalog_cp
;
142 struct cnode
* hfs_allocation_cp
;
143 struct cnode
* hfs_attribute_cp
;
144 struct cnode
* hfs_startup_cp
;
145 dev_t hfs_raw_dev
; /* device mounted */
146 u_int32_t hfs_logBlockSize
; /* Size of buffer cache buffer for I/O */
148 /* Default values for HFS standard and non-init access */
149 uid_t hfs_uid
; /* uid to set as owner of the files */
150 gid_t hfs_gid
; /* gid to set as owner of the files */
151 mode_t hfs_dir_mask
; /* mask to and with directory protection bits */
152 mode_t hfs_file_mask
; /* mask to and with file protection bits */
153 u_long hfs_encoding
; /* Default encoding for non hfs+ volumes */
155 /* Persistent fields (on disk, dynamic) */
156 time_t hfs_mtime
; /* file system last modification time */
157 u_int32_t hfs_filecount
; /* number of files in file system */
158 u_int32_t hfs_dircount
; /* number of directories in file system */
159 u_int32_t freeBlocks
; /* free allocation blocks */
160 u_int32_t nextAllocation
; /* start of next allocation search */
161 u_int32_t vcbNxtCNID
; /* next unused catalog node ID - protected by catalog lock */
162 u_int32_t vcbWrCnt
; /* file system write count */
163 u_int64_t encodingsBitmap
; /* in-use encodings */
164 u_int16_t vcbNmFls
; /* HFS Only - root dir file count */
165 u_int16_t vcbNmRtDirs
; /* HFS Only - root dir directory count */
167 /* Persistent fields (on disk, static) */
168 u_int16_t vcbSigWord
;
169 int16_t vcbFlags
; /* Runtime flag to indicate if volume is dirty/clean */
171 u_int32_t vcbJinfoBlock
;
172 time_t hfs_itime
; /* file system creation time */
173 time_t hfs_btime
; /* file system last backup time */
174 u_int32_t blockSize
; /* size of allocation blocks */
175 u_int32_t totalBlocks
; /* total allocation blocks */
176 u_int32_t allocLimit
; /* Do not allocate this block or beyond */
178 * NOTE: When resizing a volume to make it smaller, allocLimit is set to the allocation
179 * block number which will contain the new alternate volume header. At all other times,
180 * allocLimit is set to totalBlocks. The allocation code uses allocLimit instead of
181 * totalBlocks to limit which blocks may be allocated, so that during a resize, we don't
182 * put new content into the blocks we're trying to truncate away.
185 u_int32_t vcbFndrInfo
[8];
186 int16_t vcbVBMSt
; /* HFS only */
187 int16_t vcbAlBlSt
; /* HFS only */
190 u_int8_t vcbVN
[256]; /* volume name in UTF-8 */
191 u_int32_t volumeNameEncodingHint
;
192 u_int32_t hfsPlusIOPosOffset
; /* Disk block where HFS+ starts */
193 u_int32_t vcbVBMIOSize
; /* volume bitmap I/O size */
195 /* cache of largest known free extents */
196 u_int32_t vcbFreeExtCnt
;
197 HFSPlusExtentDescriptor vcbFreeExt
[kMaxFreeExtents
];
199 u_int32_t reserveBlocks
; /* free block reserve */
200 u_int32_t loanedBlocks
; /* blocks on loan for delayed allocations */
202 u_int32_t localCreateDate
; /* creation times for HFS+ volumes are in local time */
205 * HFS+ Private system directories (two). Any access
206 * (besides looking at the cd_cnid) requires holding
207 * the Catalog File lock.
209 struct cat_desc hfs_private_desc
[2];
210 struct cat_attr hfs_private_attr
[2];
212 u_int32_t hfs_metadata_createdate
;
213 hfs_to_unicode_func_t hfs_get_unicode
;
214 unicode_to_hfs_func_t hfs_get_hfsname
;
216 /* Quota variables: */
217 struct quotafile hfs_qfiles
[MAXQUOTAS
]; /* quota files */
219 /* Journaling variables: */
220 void *jnl
; // the journal for this volume (if one exists)
221 struct vnode
*jvp
; // device where the journal lives (may be equal to devvp)
222 u_int32_t jnl_start
; // start block of the journal file (so we don't delete it)
224 u_int32_t hfs_jnlfileid
;
225 u_int32_t hfs_jnlinfoblkid
;
226 lck_rw_t hfs_global_lock
;
227 u_int32_t hfs_global_lock_nesting
;
229 /* Notification variables: */
230 unsigned long hfs_notification_conditions
;
231 u_int32_t hfs_freespace_notify_warninglimit
;
232 u_int32_t hfs_freespace_notify_desiredlevel
;
234 /* time mounted and last mounted mod time "snapshot" */
235 time_t hfs_mount_time
;
236 time_t hfs_last_mounted_mtime
;
238 /* Metadata allocation zone variables: */
239 u_int32_t hfs_metazone_start
;
240 u_int32_t hfs_metazone_end
;
241 u_int32_t hfs_hotfile_start
;
242 u_int32_t hfs_hotfile_end
;
243 int hfs_hotfile_freeblks
;
244 int hfs_hotfile_maxblks
;
245 int hfs_overflow_maxblks
;
246 int hfs_catalog_maxblks
;
248 /* Hot File Clustering variables: */
249 lck_mtx_t hfc_mutex
; /* serialize hot file stages */
250 enum hfc_stage hfc_stage
; /* what are we up to... */
251 time_t hfc_timebase
; /* recording period start time */
252 time_t hfc_timeout
; /* recording period stop time */
253 void * hfc_recdata
; /* recording data (opaque) */
254 int hfc_maxfiles
; /* maximum files to track */
255 struct vnode
* hfc_filevp
;
257 #ifdef HFS_SPARSE_DEV
258 /* Sparse device variables: */
259 struct vnode
* hfs_backingfs_rootvp
;
260 u_int32_t hfs_last_backingstatfs
;
261 int hfs_sparsebandblks
;
263 size_t hfs_max_inline_attrsize
;
265 lck_mtx_t hfs_mutex
; /* protects access to hfsmount data */
266 void *hfs_freezing_proc
; /* who froze the fs */
267 lck_rw_t hfs_insync
; /* protects sync/freeze interaction */
269 /* Resize variables: */
270 u_int32_t hfs_resize_filesmoved
;
271 u_int32_t hfs_resize_totalfiles
;
274 typedef hfsmount_t ExtendedVCB
;
276 /* Aliases for legacy (Mac OS 9) field names */
277 #define vcbCrDate hfs_itime
278 #define vcbLsMod hfs_mtime
279 #define vcbVolBkUp hfs_btime
280 #define extentsRefNum hfs_extents_vp
281 #define catalogRefNum hfs_catalog_vp
282 #define allocationsRefNum hfs_allocation_vp
283 #define vcbFilCnt hfs_filecount
284 #define vcbDirCnt hfs_dircount
286 /* Inline functions to set/reset vcbFlags. Upper 8 bits indicate if the volume
287 * header/VCB is clean/dirty --- if set, volume header is dirty, and
288 * if clear, volume header is clean. This value is checked to determine
289 * if the in-memory copy of volume header should be flushed to the disk
292 /* Set runtime flag to indicate that volume is dirty */
293 static __inline__
void MarkVCBDirty(ExtendedVCB
*vcb
)
295 vcb
->vcbFlags
|= 0xFF00;
298 /* Clear runtime flag to indicate that volume is dirty */
299 static __inline__
void MarkVCBClean(ExtendedVCB
*vcb
)
301 vcb
->vcbFlags
&= 0x00FF;
304 /* Check runtime flag to determine if the volume is dirty or not */
305 static __inline__ Boolean
IsVCBDirty(ExtendedVCB
*vcb
)
307 return (vcb
->vcbFlags
& 0xFF00 ? true : false);
311 * There are two private directories in HFS+.
313 * One contains inodes for files that are hardlinked or open/unlinked.
314 * The other contains inodes for directories that are hardlinked.
316 enum privdirtype
{FILE_HARDLINKS
, DIR_HARDLINKS
};
319 /* HFS mount point flags */
320 #define HFS_READ_ONLY 0x00001
321 #define HFS_UNKNOWN_PERMS 0x00002
322 #define HFS_WRITEABLE_MEDIA 0x00004
323 #define HFS_CLEANED_ORPHANS 0x00008
324 #define HFS_X 0x00010
325 #define HFS_CASE_SENSITIVE 0x00020
326 #define HFS_STANDARD 0x00040
327 #define HFS_METADATA_ZONE 0x00080
328 #define HFS_FRAGMENTED_FREESPACE 0x00100
329 #define HFS_NEED_JNL_RESET 0x00200
330 #define HFS_HAS_SPARSE_DEVICE 0x00400
331 #define HFS_RESIZE_IN_PROGRESS 0x00800
332 #define HFS_QUOTAS 0x01000
333 #define HFS_CREATING_BTREE 0x02000
334 /* When set, do not update nextAllocation in the mount structure */
335 #define HFS_SKIP_UPDATE_NEXT_ALLOCATION 0x04000
336 #define HFS_XATTR_EXTENTS 0x08000
337 #define HFS_FOLDERCOUNT 0x10000
338 /* When set, the file system exists on a virtual device, like disk image */
339 #define HFS_VIRTUAL_DEVICE 0x20000
342 /* Macro to update next allocation block in the HFS mount structure. If
343 * the HFS_SKIP_UPDATE_NEXT_ALLOCATION is set, do not update
344 * nextAllocation block.
346 #define HFS_UPDATE_NEXT_ALLOCATION(hfsmp, new_nextAllocation) \
348 if ((hfsmp->hfs_flags & HFS_SKIP_UPDATE_NEXT_ALLOCATION) == 0)\
349 hfsmp->nextAllocation = new_nextAllocation; \
352 #define HFS_MOUNT_LOCK(hfsmp, metadata) \
354 if ((metadata) && 1) \
355 lck_mtx_lock(&(hfsmp)->hfs_mutex); \
358 #define HFS_MOUNT_UNLOCK(hfsmp, metadata) \
360 if ((metadata) && 1) \
361 lck_mtx_unlock(&(hfsmp)->hfs_mutex); \
364 #define hfs_global_exclusive_lock_acquire(hfsmp) lck_rw_lock_exclusive(&(hfsmp)->hfs_global_lock)
365 #define hfs_global_exclusive_lock_release(hfsmp) lck_rw_unlock_exclusive(&(hfsmp)->hfs_global_lock)
367 /* Macro for incrementing and decrementing the folder count in a cnode
368 * attribute only if the HFS_FOLDERCOUNT bit is set in the mount flags
369 * and kHFSHasFolderCount bit is set in the cnode flags. Currently these
370 * bits are only set for case sensitive HFS+ volumes.
372 #define INC_FOLDERCOUNT(hfsmp, cattr) \
373 if ((hfsmp->hfs_flags & HFS_FOLDERCOUNT) && \
374 (cattr.ca_recflags & kHFSHasFolderCountMask)) { \
375 cattr.ca_dircount++; \
378 #define DEC_FOLDERCOUNT(hfsmp, cattr) \
379 if ((hfsmp->hfs_flags & HFS_FOLDERCOUNT) && \
380 (cattr.ca_recflags & kHFSHasFolderCountMask) && \
381 (cattr.ca_dircount > 0)) { \
382 cattr.ca_dircount--; \
385 typedef struct filefork FCB;
388 * Macros for creating item names for our special/private directories.
390 #define MAKE_INODE_NAME(name, size, linkno) \
391 (void) snprintf((name), size, "%s%d", HFS_INODE_PREFIX, (linkno))
392 #define HFS_INODE_PREFIX_LEN 5
394 #define MAKE_DIRINODE_NAME(name, size, linkno) \
395 (void) snprintf((name), size, "%s%d", HFS_DIRINODE_PREFIX, (linkno))
396 #define HFS_DIRINODE_PREFIX_LEN 4
398 #define MAKE_DELETED_NAME(NAME, size, FID) \
399 (void) snprintf((NAME), size, "%s%d", HFS_DELETE_PREFIX, (FID))
400 #define HFS_DELETE_PREFIX_LEN 4
403 #define HFS_AVERAGE_NAME_SIZE 22
404 #define AVERAGE_HFSDIRENTRY_SIZE (8+HFS_AVERAGE_NAME_SIZE+4)
406 #define STD_DIRENT_LEN(namlen) \
407 ((sizeof(struct dirent) - (NAME_MAX+1)) + (((namlen)+1 + 3) &~ 3))
409 #define EXT_DIRENT_LEN(namlen) \
410 ((sizeof(struct direntry) + (namlen) - (MAXPATHLEN-1) + 3) & ~3)
413 enum { kHFSPlusMaxFileNameBytes
= kHFSPlusMaxFileNameChars
* 3 };
416 /* macro to determine if hfs or hfsplus */
417 #define ISHFSPLUS(VCB) ((VCB)->vcbSigWord == kHFSPlusSigWord)
418 #define ISHFS(VCB) ((VCB)->vcbSigWord == kHFSSigWord)
422 * Various ways to acquire a VFS mount point pointer:
424 #define VTOVFS(VP) vnode_mount((VP))
425 #define HFSTOVFS(HFSMP) ((HFSMP)->hfs_mp)
426 #define VCBTOVFS(VCB) HFSTOVFS(VCB)
429 * Various ways to acquire an HFS mount point pointer:
431 #define VTOHFS(VP) ((struct hfsmount *)vfs_fsprivate(vnode_mount((VP))))
432 #define VFSTOHFS(MP) ((struct hfsmount *)vfs_fsprivate((MP)))
433 #define VCBTOHFS(VCB) (VCB)
434 #define FCBTOHFS(FCB) ((struct hfsmount *)vfs_fsprivate(vnode_mount((FCB)->ff_cp->c_vp)))
437 * Various ways to acquire a VCB (legacy) pointer:
439 #define VTOVCB(VP) VTOHFS(VP)
440 #define VFSTOVCB(MP) VFSTOHFS(MP)
441 #define HFSTOVCB(HFSMP) (HFSMP)
442 #define FCBTOVCB(FCB) FCBTOHFS(FCB)
445 #define HFS_KNOTE(vp, hint) KNOTE(&VTOC(vp)->c_knotes, (hint))
449 #define kHFSBlockSize 512
452 * Macros for getting the MDB/VH sector and offset
454 #define HFS_PRI_SECTOR(blksize) (1024 / (blksize))
455 #define HFS_PRI_OFFSET(blksize) ((blksize) > 1024 ? 1024 : 0)
457 #define HFS_ALT_SECTOR(blksize, blkcnt) (((blkcnt) - 1) - (512 / (blksize)))
458 #define HFS_ALT_OFFSET(blksize) ((blksize) > 1024 ? (blksize) - 1024 : 0)
462 * HFS specific fcntl()'s
464 #define HFS_BULKACCESS (FCNTL_FS_SPECIFIC_BASE + 0x00001)
465 #define HFS_GET_MOUNT_TIME (FCNTL_FS_SPECIFIC_BASE + 0x00002)
466 #define HFS_GET_LAST_MTIME (FCNTL_FS_SPECIFIC_BASE + 0x00003)
467 #define HFS_GET_BOOT_INFO (FCNTL_FS_SPECIFIC_BASE + 0x00004)
468 #define HFS_SET_BOOT_INFO (FCNTL_FS_SPECIFIC_BASE + 0x00005)
469 #define HFS_EXT_BULKACCESS (FCNTL_FS_SPECIFIC_BASE + 0x00006)
473 * This is the straight GMT conversion constant:
474 * 00:00:00 January 1, 1970 - 00:00:00 January 1, 1904
475 * (3600 * 24 * ((365 * (1970 - 1904)) + (((1970 - 1904) / 4) + 1)))
477 #define MAC_GMT_FACTOR 2082844800UL
480 /*****************************************************************************
482 ******************************************************************************/
485 /*****************************************************************************
486 hfs_vnop_xxx functions from different files
487 ******************************************************************************/
488 int hfs_vnop_readdirattr(struct vnop_readdirattr_args
*); /* in hfs_attrlist.c */
490 int hfs_vnop_inactive(struct vnop_inactive_args
*); /* in hfs_cnode.c */
491 int hfs_vnop_reclaim(struct vnop_reclaim_args
*); /* in hfs_cnode.c */
493 int hfs_vnop_link(struct vnop_link_args
*); /* in hfs_link.c */
495 int hfs_vnop_lookup(struct vnop_lookup_args
*); /* in hfs_lookup.c */
497 int hfs_vnop_search(struct vnop_searchfs_args
*); /* in hfs_search.c */
499 int hfs_vnop_read(struct vnop_read_args
*); /* in hfs_readwrite.c */
500 int hfs_vnop_write(struct vnop_write_args
*); /* in hfs_readwrite.c */
501 int hfs_vnop_ioctl(struct vnop_ioctl_args
*); /* in hfs_readwrite.c */
502 int hfs_vnop_select(struct vnop_select_args
*); /* in hfs_readwrite.c */
503 int hfs_vnop_strategy(struct vnop_strategy_args
*); /* in hfs_readwrite.c */
504 int hfs_vnop_allocate(struct vnop_allocate_args
*); /* in hfs_readwrite.c */
505 int hfs_vnop_pagein(struct vnop_pagein_args
*); /* in hfs_readwrite.c */
506 int hfs_vnop_pageout(struct vnop_pageout_args
*); /* in hfs_readwrite.c */
507 int hfs_vnop_bwrite(struct vnop_bwrite_args
*); /* in hfs_readwrite.c */
508 int hfs_vnop_blktooff(struct vnop_blktooff_args
*); /* in hfs_readwrite.c */
509 int hfs_vnop_offtoblk(struct vnop_offtoblk_args
*); /* in hfs_readwrite.c */
510 int hfs_vnop_blockmap(struct vnop_blockmap_args
*); /* in hfs_readwrite.c */
512 int hfs_vnop_getxattr(struct vnop_getxattr_args
*); /* in hfs_xattr.c */
513 int hfs_vnop_setxattr(struct vnop_setxattr_args
*); /* in hfs_xattr.c */
514 int hfs_vnop_removexattr(struct vnop_removexattr_args
*); /* in hfs_xattr.c */
515 int hfs_vnop_listxattr(struct vnop_listxattr_args
*); /* in hfs_xattr.c */
517 extern int hfs_vnop_getnamedstream(struct vnop_getnamedstream_args
*);
518 extern int hfs_vnop_makenamedstream(struct vnop_makenamedstream_args
*);
519 extern int hfs_vnop_removenamedstream(struct vnop_removenamedstream_args
*);
523 /*****************************************************************************
524 Functions from MacOSStubs.c
525 ******************************************************************************/
526 time_t to_bsd_time(u_int32_t hfs_time
);
528 u_int32_t
to_hfs_time(time_t bsd_time
);
531 /*****************************************************************************
532 Functions from hfs_encodinghint.c
533 ******************************************************************************/
534 u_int32_t
hfs_pickencoding(const u_int16_t
*src
, int len
);
536 u_int32_t
hfs_getencodingbias(void);
538 void hfs_setencodingbias(u_int32_t bias
);
541 /*****************************************************************************
542 Functions from hfs_encodings.c
543 ******************************************************************************/
544 void hfs_converterinit(void);
546 int hfs_getconverter(u_int32_t encoding
, hfs_to_unicode_func_t
*get_unicode
,
547 unicode_to_hfs_func_t
*get_hfsname
);
549 int hfs_relconverter(u_int32_t encoding
);
551 int hfs_to_utf8(ExtendedVCB
*vcb
, const Str31 hfs_str
, ByteCount maxDstLen
,
552 ByteCount
*actualDstLen
, unsigned char* dstStr
);
554 int utf8_to_hfs(ExtendedVCB
*vcb
, ByteCount srcLen
, const unsigned char* srcStr
,
557 int mac_roman_to_utf8(const Str31 hfs_str
, ByteCount maxDstLen
, ByteCount
*actualDstLen
,
558 unsigned char* dstStr
);
560 int utf8_to_mac_roman(ByteCount srcLen
, const unsigned char* srcStr
, Str31 dstStr
);
562 int mac_roman_to_unicode(const Str31 hfs_str
, UniChar
*uni_str
, u_int32_t maxCharLen
, u_int32_t
*usedCharLen
);
564 int unicode_to_hfs(ExtendedVCB
*vcb
, ByteCount srcLen
, u_int16_t
* srcStr
, Str31 dstStr
, int retry
);
567 /*****************************************************************************
568 Functions from hfs_notifications.c
569 ******************************************************************************/
570 void hfs_generate_volume_notifications(struct hfsmount
*hfsmp
);
573 /*****************************************************************************
574 Functions from hfs_readwrite.c
575 ******************************************************************************/
576 extern int hfs_relocate(struct vnode
*, u_int32_t
, kauth_cred_t
, struct proc
*);
578 extern int hfs_truncate(struct vnode
*, off_t
, int, int, vfs_context_t
);
580 extern int hfs_bmap(struct vnode
*, daddr_t
, struct vnode
**, daddr64_t
*, unsigned int *);
582 extern int hfs_fsync(struct vnode
*, int, int, struct proc
*);
584 extern int hfs_access(struct vnode
*, mode_t
, kauth_cred_t
, struct proc
*);
586 extern int hfs_removeallattr(struct hfsmount
*hfsmp
, u_int32_t fileid
);
588 extern int hfs_set_volxattr(struct hfsmount
*hfsmp
, unsigned int xattrtype
, int state
);
590 extern void hfs_check_volxattr(struct hfsmount
*hfsmp
, unsigned int xattrtype
);
592 extern int hfs_isallocated(struct hfsmount
*, u_long
, u_long
);
595 /*****************************************************************************
596 Functions from hfs_vfsops.c
597 ******************************************************************************/
598 int hfs_mountroot(mount_t mp
, vnode_t rvp
, vfs_context_t context
);
600 /* used as a callback by the journaling code */
601 extern void hfs_sync_metadata(void *arg
);
603 extern int hfs_vget(struct hfsmount
*, cnid_t
, struct vnode
**, int);
605 extern void hfs_setencodingbits(struct hfsmount
*hfsmp
, u_int32_t encoding
);
607 enum volop
{VOL_UPDATE
, VOL_MKDIR
, VOL_RMDIR
, VOL_MKFILE
, VOL_RMFILE
};
608 extern int hfs_volupdate(struct hfsmount
*hfsmp
, enum volop op
, int inroot
);
610 int hfs_flushvolumeheader(struct hfsmount
*hfsmp
, int waitfor
, int altflush
);
611 #define HFS_ALTFLUSH 1
613 extern int hfs_extendfs(struct hfsmount
*, u_int64_t
, vfs_context_t
);
614 extern int hfs_truncatefs(struct hfsmount
*, u_int64_t
, vfs_context_t
);
615 extern int hfs_resize_progress(struct hfsmount
*, u_int32_t
*);
617 /* If a runtime corruption is detected, mark the volume inconsistent
618 * bit in the volume attributes.
620 void hfs_mark_volume_inconsistent(struct hfsmount
*hfsmp
);
622 /*****************************************************************************
623 Functions from hfs_vfsutils.c
624 ******************************************************************************/
625 unsigned long BestBlockSizeFit(unsigned long allocationBlockSize
,
626 unsigned long blockSizeLimit
,
627 unsigned long baseMultiple
);
629 OSErr
hfs_MountHFSVolume(struct hfsmount
*hfsmp
, HFSMasterDirectoryBlock
*mdb
,
631 OSErr
hfs_MountHFSPlusVolume(struct hfsmount
*hfsmp
, HFSPlusVolumeHeader
*vhp
,
632 off_t embeddedOffset
, u_int64_t disksize
, struct proc
*p
, void *args
, kauth_cred_t cred
);
634 extern int hfsUnmount(struct hfsmount
*hfsmp
, struct proc
*p
);
636 extern int overflow_extents(struct filefork
*fp
);
638 extern int hfs_owner_rights(struct hfsmount
*hfsmp
, uid_t cnode_uid
, kauth_cred_t cred
,
639 struct proc
*p
, int invokesuperuserstatus
);
642 /* HFS System file locking */
643 #define SFL_CATALOG 0x0001
644 #define SFL_EXTENTS 0x0002
645 #define SFL_BITMAP 0x0004
646 #define SFL_ATTRIBUTE 0x0008
647 #define SFL_STARTUP 0x0010
648 #define SFL_VALIDMASK (SFL_CATALOG | SFL_EXTENTS | SFL_BITMAP | SFL_ATTRIBUTE | SFL_STARTUP)
650 extern int hfs_systemfile_lock(struct hfsmount
*, int, enum hfslocktype
);
651 extern void hfs_systemfile_unlock(struct hfsmount
*, int);
653 extern u_long
GetFileInfo(ExtendedVCB
*vcb
, u_int32_t dirid
, const char *name
,
654 struct cat_attr
*fattr
, struct cat_fork
*forkinfo
);
656 extern void hfs_remove_orphans(struct hfsmount
*);
658 u_int32_t
GetLogicalBlockSize(struct vnode
*vp
);
660 extern u_int32_t
hfs_freeblks(struct hfsmount
* hfsmp
, int wantreserve
);
662 short MacToVFSError(OSErr err
);
664 /* HFS directory hint functions. */
665 extern directoryhint_t
* hfs_getdirhint(struct cnode
*, int, int);
666 extern void hfs_reldirhint(struct cnode
*, directoryhint_t
*);
667 extern void hfs_reldirhints(struct cnode
*, int);
668 extern void hfs_insertdirhint(struct cnode
*, directoryhint_t
*);
670 extern int hfs_namecmp(const u_int8_t
*str1
, size_t len1
, const u_int8_t
*str2
, size_t len2
);
672 extern int hfs_early_journal_init(struct hfsmount
*hfsmp
, HFSPlusVolumeHeader
*vhp
,
673 void *_args
, off_t embeddedOffset
, daddr64_t mdb_offset
,
674 HFSMasterDirectoryBlock
*mdbp
, kauth_cred_t cred
);
676 extern int hfs_virtualmetafile(struct cnode
*);
678 extern int hfs_start_transaction(struct hfsmount
*hfsmp
);
679 extern int hfs_end_transaction(struct hfsmount
*hfsmp
);
682 /*****************************************************************************
683 Functions from hfs_vnops.c
684 ******************************************************************************/
685 int hfs_write_access(struct vnode
*vp
, kauth_cred_t cred
, struct proc
*p
, Boolean considerFlags
);
687 int hfs_chmod(struct vnode
*vp
, int mode
, kauth_cred_t cred
, struct proc
*p
);
689 int hfs_chown(struct vnode
*vp
, uid_t uid
, gid_t gid
, kauth_cred_t cred
, struct proc
*p
);
691 #define kMaxSecsForFsync 5
692 #define HFS_SYNCTRANS 1
693 extern int hfs_btsync(struct vnode
*vp
, int sync_transaction
);
695 extern void replace_desc(struct cnode
*cp
, struct cat_desc
*cdp
);
697 extern int hfs_vgetrsrc(struct hfsmount
*hfsmp
, struct vnode
*vp
,
698 struct vnode
**rvpp
, int can_drop_lock
);
700 extern int hfs_update(struct vnode
*, int);
703 /*****************************************************************************
704 Functions from hfs_xattr.c
705 ******************************************************************************/
706 int hfs_attrkeycompare(HFSPlusAttrKey
*searchKey
, HFSPlusAttrKey
*trialKey
);
707 int hfs_buildattrkey(u_int32_t fileID
, const char *attrname
, HFSPlusAttrKey
*key
);
708 void hfs_xattr_init(struct hfsmount
* hfsmp
);
709 int file_attribute_exist(struct hfsmount
*hfsmp
, uint32_t fileID
);
713 /*****************************************************************************
714 Functions from hfs_link.c
715 ******************************************************************************/
717 extern int hfs_unlink(struct hfsmount
*hfsmp
, struct vnode
*dvp
, struct vnode
*vp
,
718 struct componentname
*cnp
, int skip_reserve
);
719 extern int hfs_lookuplink(struct hfsmount
*hfsmp
, cnid_t linkfileid
,
720 cnid_t
*prevlinkid
, cnid_t
*nextlinkid
);
721 extern void hfs_privatedir_init(struct hfsmount
*, enum privdirtype
);
723 extern void hfs_savelinkorigin(cnode_t
*cp
, cnid_t parentcnid
);
724 extern void hfs_relorigins(struct cnode
*cp
);
725 extern void hfs_relorigin(struct cnode
*cp
, cnid_t parentcnid
);
726 extern int hfs_haslinkorigin(cnode_t
*cp
);
727 extern cnid_t
hfs_currentparent(cnode_t
*cp
);
728 extern cnid_t
hfs_currentcnid(cnode_t
*cp
);
731 #endif /* __APPLE_API_PRIVATE */