|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24:
25: /* @(#)hfs.h 3.0
26: *
27: * (c) 1997-1999 Apple Computer, Inc. All Rights Reserved
28: * (c) 1990, 1992 NeXT Computer, Inc. All Rights Reserved
29: *
30: * hfs.h -- constants, structures, function declarations. etc.
31: * for Macintosh file system vfs.
32: *
33: * HISTORY
34: * 13-Jan-1999 Don Brady Add ATTR_CMN_SCRIPT to HFS_ATTR_CMN_LOOKUPMASK (radar #2296613).
35: * 20-Nov-1998 Don Brady Remove UFSToHFSStr and HFSToUFSStr prototypes (obsolete).
36: * Move filename entry from FCB to hfsfilemeta, hfsdirentry
37: * names are now 255 byte long.
38: * 10-Nov-1998 Pat Dirks Added MAXLOGBLOCKSIZE and MAXLOGBLOCKSIZEBLOCKS and RELEASE_BUFFER flag.
39: * Added hfsLogicalBlockTableEntry and h_logicalblocktable field in struct hfsnode.
40: * 4-Sep-1998 Pat Dirks Added hfs_log_block_size to hfsmount struct [again] and BestBlockSizeFit routine.
41: * 31-aug-1998 Don Brady Add UL to MAC_GMT_FACTOR constant.
42: * 04-jun-1998 Don Brady Add hfsMoveRename prototype to replace hfsMove and hfsRename.
43: * Add VRELE and VPUT macros to catch bad ref counts.
44: * 28-May-1998 Pat Dirks Move internal 'struct searchinfo' def'n here from attr.h
45: * 03-may-1998 Brent Knight Add gTimeZone.
46: * 23-apr-1998 Don Brady Add File type and creator for symbolic links.
47: * 22-apr-1998 Don Brady Removed kMetaFile.
48: * 21-apr-1998 Don Brady Add to_bsd_time and to_hfs_time prototypes.
49: * 20-apr-1998 Don Brady Remove course-grained hfs metadata locking.
50: * 15-apr-1998 Don Brady Add hasOverflowExtents and hfs_metafilelocking prototypes. Add kSysFile constant.
51: * 14-apr-1998 Deric Horn Added searchinfo_t, definition of search criteria used by searchfs.
52: * 9-apr-1998 Don Brady Added hfs_flushMDB and hfs_flushvolumeheader prototypes.
53: * 8-apr-1998 Don Brady Add MAKE_VREFNUM macro.
54: * 26-mar-1998 Don Brady Removed CloseBTreeFile and OpenBtreeFile prototypes.
55: *
56: * 12-nov-1997 scott
57: * Added changes for HFSPlus
58: */
59:
60: #ifndef __HFS__
61: #define __HFS__
62:
63: #include <sys/types.h>
64: #include <sys/ucred.h> /* mount.h needs this */
65: #include <sys/mount.h>
66: #include <sys/malloc.h>
67: #include <mach/machine/vm_types.h>
68: #include <sys/vnode.h>
69: #include <sys/namei.h>
70: #include <sys/attr.h>
71: #include <sys/syslimits.h>
72: #include <mach/vm_param.h> /* For PAGE_SIZE */
73: #include <sys/dir.h> /* For MAXNAMLEN */
74:
75: #include <libkern/libkern.h>
76: #include <kern/queue.h>
77: #include <kern/kalloc.h>
78: #include <mach/machine/simple_lock.h>
79: #include <mach/mach_types.h>
80:
81: #ifndef __FILEMGRINTERNAL__
82: #include "hfscommon/headers/FileMgrInternal.h"
83: #endif
84:
85: #ifndef __BTREESINTERNAL__
86: #include "hfscommon/headers/BTreesInternal.h"
87: #endif
88:
89: #if KERNEL_PRIVATE
90: #include <kern/thread.h>
91: #define GET_CURRENT_THREAD current_thread()
92: #else
93: extern thread_t current_thread_EXTERNAL();
94: #define GET_CURRENT_THREAD current_thread_EXTERNAL();
95: #endif
96:
97: #if KERNEL_PRIVATE
98: #define CURRENT_PROC current_proc()
99: #else
100: extern struct proc * current_proc_EXTERNAL();
101: #define CURRENT_PROC current_proc_EXTERNAL()
102: #endif
103:
104: struct uio; // This is more effective than #include <sys/uio.h> in case KERNEL is undefined...
105: struct hfslockf; // For advisory locking
106:
107: /*
108: * Just reported via MIG interface.
109: */
110: #define VERSION_STRING "hfs-1 (1-nov-97)"
111:
112: /*
113: * fork strings.
114: */
115: #define kDataForkNameStr "data"
116: #define kRsrcForkNameStr "rsrc"
117:
118: /*
119: * Set to force READ_ONLY.
120: */
121: #define FORCE_READONLY 0
122:
123: enum { kMDBSize = 512 }; /* Size of I/O transfer to read entire MDB */
124:
125: enum { kMasterDirectoryBlock = 2 }; /* MDB offset on disk in 512-byte blocks */
126: enum { kMDBOffset = kMasterDirectoryBlock * 512 }; /* MDB offset on disk in bytes */
127:
128: enum {
129: kUnknownID = 0,
130: kRootParID = 1,
131: kRootDirID = 2
132: };
133:
134: enum {
135: kDirCmplx = 1,
136: kDataFork = 2,
137: kRsrcFork = 3,
138: kSysFile = 4
139: };
140:
141:
142: /*
143: * File type and creator for symbolic links
144: */
145: enum {
146: kSymLinkFileType = 0x736C6E6B, /* 'slnk' */
147: kSymLinkCreator = 0x72686170 /* 'rhap' */
148: };
149:
150:
151: #define MAXLOGBLOCKSIZE PAGE_SIZE
152: #define MAXLOGBLOCKSIZEBLOCKS (MAXLOGBLOCKSIZE/512)
153: /* NOTE: Special support will be needed for LOGBLOCKMAPENTRIES > kHFSPlusExtentDensity (=8) */
154: #define LOGBLOCKMAPENTRIES 8
155:
156: #define BUFFERPTRLISTSIZE 25
157:
158: extern Ptr gBufferAddress[BUFFERPTRLISTSIZE];
159: extern struct buf *gBufferHeaderPtr[BUFFERPTRLISTSIZE];
160: extern int gBufferListIndex;
161: extern simple_lock_data_t gBufferPtrListLock;
162:
163: extern struct timezone gTimeZone;
164:
165: /* Flag values for bexpand: */
166: #define RELEASE_BUFFER 0x00000001
167:
168:
169: /*
170: * NOTE: The code relies on being able to cast an ExtendedVCB* to a vfsVCB* in order
171: * to gain access to the mount point pointer from a pointer
172: * to an ExtendedVCB. DO NOT INSERT OTHER FIELDS BEFORE THE vcb FIELD!!
173: *
174: * vcbFlags, vcbLsMod, vcbFilCnt, vcbDirCnt, vcbNxtCNID, etc
175: * are locked by the hfs_lock simple lock.
176: */
177: typedef struct vfsVCB {
178: ExtendedVCB vcb_vcb;
179: struct hfsmount *vcb_hfsmp; /* Pointer to hfsmount structure */
180: } vfsVCB_t;
181:
182: typedef struct hfsmount {
183: u_char hfs_mountpoint[MAXPATHLEN+1];
184: u_long hfs_mount_flags;
185: Boolean hfs_fs_clean; /* Whether contents have been flushed in clean state */
186: Boolean hfs_fs_ronly; /* Whether this was mounted as read-initially */
187:
188: /* Physical Description */
189: u_long hfs_phys_block_count; /* Num of PHYSICAL blocks of volume */
190: u_long hfs_phys_block_size; /* Always a multiple of 512 */
191:
192: /* Access to VFS and devices */
193: struct mount *hfs_mp; /* filesystem vfs structure */
194: struct vnode *hfs_devvp; /* block device mounted vnode */
195: dev_t hfs_raw_dev; /* device mounted */
196: struct hfsnode *hfs_rootDirectory;
197: unsigned long hfs_log_block_size; /* Size of buffer cache buffer for I/O */
198:
199: /* Default values for HFS standard and non-init access */
200: uid_t hfs_uid; /* uid to set as owner of the files */
201: gid_t hfs_gid; /* gid to set as owner of the files */
202: mode_t hfs_dir_mask; /* mask to and with directory protection bits */
203: mode_t hfs_file_mask; /* mask to and with file protection bits */
204: u_long hfs_encoding; /* Defualt encoding for non hfs+ volumes */
205:
206: /* HFS Specific */
207: struct vfsVCB hfs_vcb;
208: } hfsmount_t;
209:
210:
211: /*****************************************************************************
212: *
213: * hfsnode structure
214: *
215: *
216: * m_closeable is an indication of whether the file can be closed at
217: * any time. This flag is implemented to help indicate whether
218: * its OK to close a file which is being deleted or renamed onto
219: * and also as a consistency check because we don't actually close the
220: * file in hfs_close, but rather wait for hfs_inactive. This flag
221: * is set TRUE when the vnode is created, and only set FALSE by
222: * hfs_open.
223: *
224: * m_valid is used to indicate when a vnode no longer references a
225: * file etc. It is set to 0 when an active vnode is removed
226: * or a file is renamed onto an active vnode.
227: *
228: * To uniquely identify an entity for the HFS file system, we need
229: * the volume descriptor, the parent directory id, and the name.
230: *
231: *****************************************************************************/
232:
233: #define MAXHFSVNODELEN 31
234: typedef u_char FileNameStr[MAXHFSVNODELEN+1];
235:
236: /*
237: * NOTE: The code relies on being able to cast an FCB* to a vfsFCB* in order
238: * to gain access to the extended FCB and the vnode pointer from a pointer
239: * to an HFS FCB. DO NOT INSERT OTHER FIELDS BEFORE THE fcb FIELD!!
240: */
241: typedef struct vfsFCB {
242: FCB fcb_fcb; /* File Control Block */
243: ExtendedFCB fcb_extFCB;
244: struct vnode *fcb_vp; /* pointer to start of container vnode */
245: } vfsFCB;
246:
247:
248: typedef struct hfsfilemeta {
249: struct lock__bsd__ h_fmetalock; /* file meta lock. */
250: struct vnode *h_fork; /* vnode for first fork. */
251: u_int16_t h_usecount; /* Amount of users accessing this record XXX SER Should be deprecated*/
252: u_int32_t h_logBlockSize; /* Size of a block for reading/writing */
253: u_int16_t h_physBlkPerLogBlk; /* Amount of phys sectory per logical block */
254: u_int16_t h_mode; /* IFMT, permissions; see below. */
255: u_int32_t h_pflags; /* Permission flags (NODUMP, IMMUTABLE, APPEND etc.) */
256: u_int32_t h_uid; /* File owner. */
257: u_int32_t h_gid; /* File group. */
258: dev_t h_rdev; /* Special device info for this node */
259: u_int32_t h_nodeflags; /* flags, see below */
260: u_int32_t h_crtime; /* UNIX-format creation date in secs. */
261: u_int32_t h_atime; /* UNIX-format access date in secs. */
262: u_int32_t h_mtime; /* UNIX-format mod date in seconds */
263: u_int32_t h_ctime; /* UNIX-format status change date */
264: u_int32_t h_butime; /* UNIX-format last backup date in secs. */
265: u_long h_hint; /* Catalog hint for use on Close */
266: u_long h_dirID; /* Parent Directory ID */
267: u_short h_namelen; /* Length of name string */
268: char * h_namePtr; /* Points the name of the file */
269: FileNameStr h_fileName; /* CName of file */
270: } hfsfilemeta;
271:
272:
273: struct hfsLogicalBlockTableEntry {
274: u_long logicalBlockCount;
275: off_t extentLength;
276: };
277:
278:
279: typedef struct hfsnode {
280: LIST_ENTRY(hfsnode) h_hash; /* links on valid and free lists */
281: struct lock__bsd__ h_lock; /* node lock. */
282: struct hfslockf *h_lockf; /* Head of byte-level lock list. */
283: struct vnode *h_vp; /* vnode associated with this inode. */
284: struct vnode *h_devvp; /* vnode for block I/O. */
285: struct vnode *h_relative; /* vnode for complex parent, or to default fork */
286: struct vnode *h_sibling; /* vnode for sibling, if is a fork. */
287: dev_t h_dev; /* Device associated with the inode. */
288: u_long h_nodeID; /* specific id of this node */
289: UInt8 h_type; /* Type of info: dir, cmplx, data, rsrc */
290: off_t h_size; /* Total physical size of object */
291: struct hfsLogicalBlockTableEntry h_logicalblocktable[LOGBLOCKMAPENTRIES];
292: off_t h_optimizedblocksizelimit; /* End of range covered by h_logicalblocktable */
293: daddr_t h_uniformblocksizestart; /* First LBN in fixed-size log. block range */
294: int32_t h_lastfsync; /* Last time that this was fsynced (used for meta data) */
295: vfsFCB *h_xfcb; /* Ptr to fcb data, if this is a fork */
296: hfsfilemeta *h_meta; /* Ptr to complex (or file meta) data */
297: u_int32_t h_valid; /* is the vnode reference valid */
298: } hfsnode_t;
299: typedef struct hfsnode *hfsnodeptr;
300:
301:
302: /*
303: * Macros for quick access to fields buried in the fcb inside an hfs node:
304: */
305: #define H_FILEID(HP) ((HP)->h_nodeID)
306: #define H_FORKTYPE(HP) ((HP)->h_type)
307: #define H_DIRID(HP) ((HP)->h_meta->h_dirID)
308: #define H_NAME(HP) ((HP)->h_meta->h_namePtr)
309: #define H_HINT(HP) ((HP)->h_meta->h_hint)
310:
311: /* These flags are kept in flags. */
312: #define IN_ACCESS 0x0001 /* Access time update request. */
313: #define IN_CHANGE 0x0002 /* Change time update request. */
314: #define IN_UPDATE 0x0004 /* Modification time update request. */
315: #define IN_MODIFIED 0x0008 /* Node has been modified. */
316: #define IN_RENAME 0x0010 /* Node is being renamed. */
317: #define IN_SHLOCK 0x0020 /* File has shared lock. */
318: #define IN_EXLOCK 0x0040 /* File has exclusive lock. */
319: #define IN_UNSETACCESS 0x0200 /* File has unset access. */
320: #define IN_LONGNAME 0x0400 /* File has unset access. */
321:
322: /* File permissions.stored in mode */
323: #define IEXEC 0000100 /* Executable. */
324: #define IWRITE 0000200 /* Writeable. */
325: #define IREAD 0000400 /* Readable. */
326: #define ISVTX 0001000 /* Sticky bit. */
327: #define ISGID 0002000 /* Set-gid. */
328: #define ISUID 0004000 /* Set-uid. */
329:
330: /* File types. */
331: #define IFMT 0170000 /* Mask of file type. */
332: #define IFIFO 0010000 /* Named pipe (fifo). */
333: #define IFCHR 0020000 /* Character device. */
334: #define IFDIR 0040000 /* Directory file. */
335: #define IFBLK 0060000 /* Block device. */
336: #define IFREG 0100000 /* Regular file. */
337: #define IFLNK 0120000 /* Symbolic link. */
338: #define IFSOCK 0140000 /* UNIX domain socket. */
339: #define IFWHT 0160000 /* Whiteout. */
340:
341: /* Value to make sure vnode is real and defined */
342: #define HFS_VNODE_MAGIC 0x4846532b /* 'HFS+' */
343:
344:
345: /*
346: * Write check macro
347: */
348: #define WRITE_CK(VNODE, FUNC_NAME) { \
349: if ((VNODE)->v_mount->mnt_flag & MNT_RDONLY) { \
350: DBG_ERR(("%s: ATTEMPT TO WRITE A READONLY VOLUME\n", \
351: FUNC_NAME)); \
352: return(EROFS); \
353: } \
354: }
355:
356:
357: /*
358: * hfsmount locking and unlocking.
359: *
360: * mvl_lock_flags
361: */
362: #define MVL_LOCKED 0x00000001 /* debug only */
363:
364: #if DIAGNOSTIC
365: #define MVL_LOCK(mvip) { \
366: (simple_lock(&(mvip)->mvl_lock)); \
367: (mvip)->mvl_flags |= MVL_LOCKED; \
368: }
369:
370: #define MVL_UNLOCK(mvip) { \
371: if(((mvip)->mvl_flags & MVL_LOCKED) == 0) { \
372: panic("MVL_UNLOCK - hfsnode not locked"); \
373: } \
374: (simple_unlock(&(mvip)->mvl_lock)); \
375: (mvip)->mvl_flags &= ~MVL_LOCKED; \
376: }
377: #else /* DIAGNOSTIC */
378: #define MVL_LOCK(mvip) (simple_lock(&(mvip)->mvl_lock))
379: #define MVL_UNLOCK(mvip) (simple_unlock(&(mvip)->mvl_lock))
380: #endif /* DIAGNOSTIC */
381:
382:
383: /* structure to hold a directory entry, patterned after struct dirent */
384: typedef struct hfsdirentry {
385: u_int32_t fileno; /* unique file number */
386: u_int16_t reclen; /* length of this structure */
387: u_int8_t type; /* dirent file type */
388: u_int8_t namelen; /* len of filename */
389: char name[NAME_MAX+1]; /* filename */
390: } hfsdirentry;
391:
392: /* structure to hold a catalog record information */
393: /* Of everything you wanted to know about a catalog entry, file and directory */
394: typedef struct hfsCatalogInfo {
395: CatalogNodeData nodeData;
396: FSSpec spec; /* filename */
397: UInt32 hint;
398: } hfsCatalogInfo;
399:
400: // structure definition of the searchfs system trap for the search criterea.
401: struct directoryInfoSpec
402: {
403: u_long numFiles;
404: };
405:
406: struct fileInfoSpec
407: {
408: off_t dataLogicalLength;
409: off_t dataPhysicalLength;
410: off_t resourceLogicalLength;
411: off_t resourcePhysicalLength;
412: };
413:
414: struct searchinfospec
415: {
416: u_char name[512];
417: u_long nameLength;
418: char attributes; // see IM:Files 2-100
419: u_long parentDirID;
420: struct timespec creationDate;
421: struct timespec modificationDate;
422: struct timespec lastBackupDate;
423: u_long finderInfo[8];
424: struct fileInfoSpec f;
425: struct directoryInfoSpec d;
426: };
427: typedef struct searchinfospec searchinfospec_t;
428:
429: #define HFSTIMES(hp, t1, t2) { \
430: if ((hp)->h_meta->h_nodeflags & (IN_ACCESS | IN_CHANGE | IN_UPDATE)) { \
431: (hp)->h_meta->h_nodeflags |= IN_MODIFIED; \
432: if ((hp)->h_meta->h_nodeflags & IN_ACCESS) { \
433: (hp)->h_meta->h_atime = (t1)->tv_sec; \
434: }; \
435: if ((hp)->h_meta->h_nodeflags & IN_UPDATE) { \
436: (hp)->h_meta->h_mtime = (t2)->tv_sec; \
437: } \
438: if ((hp)->h_meta->h_nodeflags & IN_CHANGE) { \
439: (hp)->h_meta->h_ctime = time.tv_sec; \
440: }; \
441: (hp)->h_meta->h_nodeflags &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE); \
442: } \
443: }
444:
445: /*
446: * Various ways to acquire a VNode pointer:
447: */
448: #define HTOV(HP) ((HP)->h_vp)
449: #define FCBTOV(FCB) (((vfsFCB *)(FCB))->fcb_vp)
450:
451: /*
452: * Various ways to acquire an HFS Node pointer:
453: */
454: #define VTOH(VP) ((struct hfsnode *)((VP)->v_data))
455: #define FCBTOH(FCB) ((struct hfsnode *)(((vfsFCB *)(FCB))->fcb_vp->v_data))
456:
457: /*
458: * Various ways to acquire an FCB pointer:
459: */
460: #define VTOFCB(VP) (&(((struct hfsnode *)((VP)->v_data))->h_xfcb->fcb_fcb))
461: #define HTOFCB(HP) (&(HP)->h_xfcb->fcb_fcb)
462:
463: /*
464: * Various ways to acquire a VFS mount point pointer:
465: */
466: #define VTOVFS(VP) ((VP)->v_mount)
467: #define HTOVFS(HP) ((HP)->h_vp->v_mount)
468: #define FCBTOVFS(FCB) (((vfsFCB *)(FCB))->fcb_vp->v_mount)
469: #define HFSTOVFS(HFSMP) ((HFSMP)->hfs_mp)
470: #define VCBTOVFS(VCB) (((struct vfsVCB *)(VCB))->vcb_hfsmp->hfs_mp)
471:
472: /*
473: * Various ways to acquire an HFS mount point pointer:
474: */
475: #define VTOHFS(VP) ((struct hfsmount *)((VP)->v_mount->mnt_data))
476: #define HTOHFS(HP) ((struct hfsmount *)(HP)->h_vp->v_mount->mnt_data)
477: #define FCBTOHFS(FCB) ((struct hfsmount *)(((vfsFCB *)(FCB))->fcb_vp->v_mount->mnt_data))
478: #define VFSTOHFS(MP) ((struct hfsmount *)(MP)->mnt_data)
479: #define VCBTOHFS(VCB) (((struct vfsVCB *)(VCB))->vcb_hfsmp)
480:
481: /*
482: * Various ways to acquire a VCB pointer:
483: */
484: #define VTOVCB(VP) (&(((struct hfsmount *)((VP)->v_mount->mnt_data))->hfs_vcb.vcb_vcb))
485: #define HTOVCB(HP) (&(((struct hfsmount *)((HP)->h_vp->v_mount->mnt_data))->hfs_vcb.vcb_vcb))
486: #define FCBTOVCB(FCB) (&(((struct hfsmount *)(((vfsFCB *)(FCB))->fcb_vp->v_mount->mnt_data))->hfs_vcb.vcb_vcb))
487: #define VFSTOVCB(MP) (&(((struct hfsmount *)(MP)->mnt_data)->hfs_vcb.vcb_vcb))
488: #define HFSTOVCB(HFSMP) (&(HFSMP)->hfs_vcb.vcb_vcb)
489:
490: /*
491: * Lock for HFS file metadata
492: */
493: #define HFSFILEMETA_LOCK_EXCLUSIVE(HP, P) \
494: lockmgr(&(HP)->h_meta->h_fmetalock, LK_EXCLUSIVE, (simple_lock_t) 0, P)
495:
496: #define HFSFILEMETA_LOCK_SHARED(HP, P) \
497: lockmgr(&(HP)->h_meta->h_fmetalock, LK_SHARED, (simple_lock_t) 0, P)
498:
499: #define HFSFILEMETA_UNLOCK(HP, P) \
500: lockmgr(&(HP)->h_meta->h_fmetalock, LK_RELEASE, (simple_lock_t) 0, P)
501:
502: #define E_NONE 0
503: #define kHFSBlockSize 512
504: #define kHFSBlockShift 9 /* 2^9 = 512 */
505:
506: #define IOBLKNOFORBLK(STARTINGBLOCK, BLOCKSIZEINBYTES) ((daddr_t)((STARTINGBLOCK) / ((BLOCKSIZEINBYTES) >> 9)))
507: #define IOBLKCNTFORBLK(STARTINGBLOCK, BYTESTOTRANSFER, BLOCKSIZEINBYTES) \
508: ((int)(IOBLKNOFORBYTE(((STARTINGBLOCK) * 512) + (BYTESTOTRANSFER) - 1, (BLOCKSIZEINBYTES)) - \
509: IOBLKNOFORBLK((STARTINGBLOCK), (BLOCKSIZEINBYTES)) + 1))
510: #define IOBYTECCNTFORBLK(STARTINGBLOCK, BYTESTOTRANSFER, BLOCKSIZEINBYTES) \
511: (IOBLKCNTFORBLK((STARTINGBLOCK),(BYTESTOTRANSFER),(BLOCKSIZEINBYTES)) * (BLOCKSIZEINBYTES))
512: #define IOBYTEOFFSETFORBLK(STARTINGBLOCK, BLOCKSIZEINBYTES) \
513: (((STARTINGBLOCK) * 512) - \
514: (IOBLKNOFORBLK((STARTINGBLOCK), (BLOCKSIZEINBYTES)) * (BLOCKSIZEINBYTES)))
515:
516: #define IOBLKNOFORBYTE(STARTINGBYTE, BLOCKSIZEINBYTES) ((daddr_t)((STARTINGBYTE) / (BLOCKSIZEINBYTES)))
517: #define IOBLKCNTFORBYTE(STARTINGBYTE, BYTESTOTRANSFER, BLOCKSIZEINBYTES) \
518: ((int)(IOBLKNOFORBYTE((STARTINGBYTE) + (BYTESTOTRANSFER) - 1, (BLOCKSIZEINBYTES)) - \
519: IOBLKNOFORBYTE((STARTINGBYTE), (BLOCKSIZEINBYTES)) + 1))
520: #define IOBYTECNTFORBYTE(STARTINGBYTE, BYTESTOTRANSFER, BLOCKSIZEINBYTES) \
521: (IOBLKCNTFORBYTE((STARTINGBYTE),(BYTESTOTRANSFER),(BLOCKSIZEINBYTES)) * (BLOCKSIZEINBYTES))
522: #define IOBYTEOFFSETFORBYTE(STARTINGBYTE, BLOCKSIZEINBYTES) ((STARTINGBYTE) - (IOBLKNOFORBYTE((STARTINGBYTE), (BLOCKSIZEINBYTES)) * (BLOCKSIZEINBYTES)))
523:
524: #define MAKE_VREFNUM(x) ((int32_t)((x) & 0xffff))
525: /*
526: * This is the straight GMT conversion constant:
527: * 00:00:00 January 1, 1970 - 00:00:00 January 1, 1904
528: * (3600 * 24 * ((365 * (1970 - 1904)) + (((1970 - 1904) / 4) + 1)))
529: */
530: #define MAC_GMT_FACTOR 2082844800UL
531:
532: #define HFS_ATTR_CMN_LOOKUPMASK (ATTR_CMN_SCRIPT | ATTR_CMN_FNDRINFO | ATTR_CMN_NAMEDATTRCOUNT | ATTR_CMN_NAMEDATTRLIST)
533: #define HFS_ATTR_DIR_LOOKUPMASK (ATTR_DIR_LINKCOUNT | ATTR_DIR_ENTRYCOUNT)
534: #define HFS_ATTR_FILE_LOOKUPMASK (ATTR_FILE_LINKCOUNT | ATTR_FILE_TOTALSIZE | ATTR_FILE_ALLOCSIZE | \
535: ATTR_FILE_DATALENGTH | ATTR_FILE_DATAALLOCSIZE | ATTR_FILE_DATAEXTENTS | \
536: ATTR_FILE_RSRCLENGTH | ATTR_FILE_RSRCALLOCSIZE | ATTR_FILE_RSRCEXTENTS)
537:
538: #define VPUT(vp) if (((vp)->v_usecount > 0) && (*((volatile int *)(&(vp)->v_interlock))==0)) vput((vp)); else panic("hfs: vput bad ref cnt (%d)!", (vp)->v_usecount)
539: #define VRELE(vp) if (((vp)->v_usecount > 0) && (*((volatile int *)(&(vp)->v_interlock))==0)) vrele((vp)); else panic("hfs: vrele bad ref cnt (%d)!", (vp)->v_usecount)
540:
541: u_int32_t to_bsd_time(u_int32_t hfs_time);
542: u_int32_t to_hfs_time(u_int32_t bsd_time);
543:
544: struct vnode *hfs_vhashget(dev_t dev, UInt32 dirID, UInt8 forkType);
545: void hfs_vhashins(struct hfsnode *hp);
546: void hfs_vhashinslocked(struct hfsnode *hp);
547: void hfs_vhashrem(struct hfsnode *hp);
548:
549: short hfs_flushfiles(struct mount *mp, unsigned short flags);
550: short hfs_flushMDB(struct hfsmount *hfsmp, int waitfor);
551: short hfs_flushvolumeheader(struct hfsmount *hfsmp, int waitfor);
552:
553: short hfsLookup (ExtendedVCB *vcb, UInt32 dirID, char *name, short len, UInt32 hint, hfsCatalogInfo *catInfo);
554: short hfsMoveRename (ExtendedVCB *vcb, UInt32 oldDirID, char *oldName, UInt32 newDirID, char *newName, UInt32 *hint);
555: short hfsCreate (ExtendedVCB *vcb, UInt32 dirID, char *name, int mode);
556: short hfsCreateFileID (ExtendedVCB *vcb, UInt32 parentDirID, StringPtr name, UInt32 catalogHint, UInt32 *fileIDPtr);
557: short hfsGet (ExtendedVCB *vcb, hfsCatalogInfo *catInfo, UInt8 forkType, struct vnode *dvp, struct vnode **vpp);
558: short hfsDelete (ExtendedVCB *vcb, UInt32 parentDirID, StringPtr name, short isfile, UInt32 catalogHint);
559: short hfsUnmount(struct hfsmount *hfsmp, struct proc *p);
560:
561: extern int hfs_metafilelocking(struct hfsmount *hfsmp, u_long fileID, u_int flags, struct proc *p);
562: extern int hasOverflowExtents(struct hfsnode *hp);
563:
564: short MacToVFSError(OSErr err);
565: void MapFileOffset(struct hfsnode *hp, off_t filePosition, daddr_t *logBlockNumber, long *blockSize, long *blockOffset);
566: long LogicalBlockSize(struct hfsnode *hp, daddr_t logicalBlockNumber);
567: void UpdateBlockMappingTable(struct hfsnode *hp);
568: void CopyVNodeToCatalogNode (struct vnode *vp, struct CatalogNodeData *nodeData);
569: void CopyCatalogToHFSNode(struct hfsCatalogInfo *catalogInfo, struct hfsnode *hp);
570: int bexpand(struct buf *bp, int newsize, struct buf **nbpp, long flags);
571:
572: short make_dir_entry(struct FCB **fileptr, char *name, UInt32 fileID);
573:
574: int AttributeBlockSize(struct attrlist *attrlist);
575: void PackCommonAttributeBlock(struct attrlist *alist,
576: struct vnode *vp,
577: struct hfsCatalogInfo *catInfo,
578: void **attrbufptrptr,
579: void **varbufptrptr);
580: void PackVolAttributeBlock(struct attrlist *alist,
581: struct vnode *vp,
582: struct hfsCatalogInfo *catInfo,
583: void **attrbufptrptr,
584: void **varbufptrptr);
585: void PackFileDirAttributeBlock(struct attrlist *alist,
586: struct vnode *vp,
587: struct hfsCatalogInfo *catInfo,
588: void **attrbufptrptr,
589: void **varbufptrptr);
590: void PackForkAttributeBlock(struct attrlist *alist,
591: struct vnode *vp,
592: struct hfsCatalogInfo *catInfo,
593: void **attrbufptrptr,
594: void **varbufptrptr);
595: void PackAttributeBlock(struct attrlist *alist,
596: struct vnode *vp,
597: struct hfsCatalogInfo *catInfo,
598: void **attrbufptrptr,
599: void **varbufptrptr);
600: void PackCatalogInfoAttributeBlock (struct attrlist *alist,
601: struct vnode * root_vp,
602: struct hfsCatalogInfo *catInfo,
603: void **attrbufptrptr,
604: void **varbufptrptr);
605: void UnpackCommonAttributeBlock(struct attrlist *alist,
606: struct vnode *vp,
607: struct hfsCatalogInfo *catInfo,
608: void **attrbufptrptr,
609: void **varbufptrptr);
610: void UnpackAttributeBlock(struct attrlist *alist,
611: struct vnode *vp,
612: struct hfsCatalogInfo *catInfo,
613: void **attrbufptrptr,
614: void **varbufptrptr);
615: unsigned long BestBlockSizeFit(unsigned long allocationBlockSize,
616: unsigned long blockSizeLimit,
617: unsigned long baseMultiple);
618:
619: OSErr hfs_MountHFSVolume(struct hfsmount *hfsmp, HFSMasterDirectoryBlock *mdb, struct proc *p);
620: OSErr hfs_MountHFSPlusVolume(struct hfsmount *hfsmp, HFSPlusVolumeHeader *vhp, u_long embBlkOffset, struct proc *p);
621: OSStatus GetInitializedVNode(struct hfsmount *hfsmp, struct vnode **tmpvnode );
622:
623: /* B-tree I/O callbacks (in hfs_btreio.c) */
624: extern OSStatus GetBTreeBlock(FileReference fileRefNum, UInt32 blockNum, GetBlockOptions options, BlockDescriptor *block);
625: extern OSStatus ReleaseBTreeBlock(FileReference fileRefNum, BlockDescPtr blockPtr, ReleaseBlockOptions options);
626: extern OSStatus SetBTreeBlockSize(FileReference fileRefNum, ByteCount blockSize, ItemCount minBlockCount);
627: extern OSStatus ExtendBTreeFile(FileReference fileRefNum, FSSize minEOF, FSSize maxEOF);
628:
629: #endif /* __HFS__ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.