Home | History | Annotate | Line # | Download | only in hfs
hfs.h revision 1.6
      1 /*	$NetBSD: hfs.h,v 1.6 2007/08/08 09:21:34 pooka Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2005, 2007 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Yevgeny Binder and Dieter Baron.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #ifndef _FS_HFS_HFS_H_
     33 #define _FS_HFS_HFS_H_
     34 
     35 #include <sys/vnode.h>
     36 #include <sys/mount.h>
     37 
     38 #include <miscfs/genfs/genfs_node.h>
     39 
     40 /* XXX remove before release */
     41 /*#define HFS_DEBUG*/
     42 
     43 #ifdef HFS_DEBUG
     44 	#if defined(_KERNEL) && !defined(_LKM)
     45 		#include "opt_ddb.h"
     46 	#endif /* defined(_KERNEL_) && !defined(_LKM) */
     47 #endif /* HFS_DEBUG */
     48 
     49 #include <fs/hfs/libhfs.h>
     50 
     51 /* XXX: make these mount options */
     52 #define HFS_DEFAULT_UID	0
     53 #define HFS_DEFAULT_GID	0
     54 #define HFS_DEFAULT_DIR_MODE	0755
     55 #define HFS_DEFAULT_FILE_MODE	0755
     56 
     57 struct hfs_args {
     58 	char *fspec;		/* block special device to mount */
     59 };
     60 
     61 struct hfsmount {
     62 	struct mount *hm_mountp;	/* filesystem vfs structure */
     63 	dev_t hm_dev;				/* device mounted */
     64 	struct vnode *hm_devvp;		/* block device mounted vnode */
     65 	hfs_volume hm_vol;			/* essential volume information */
     66 };
     67 
     68 struct hfsnode {
     69 	struct genfs_node h_gnode;
     70 	LIST_ENTRY(hfsnode) h_hash;/* hash chain */
     71 	struct vnode *h_vnode;		/* vnode associated with this hnode */
     72 	struct hfsmount *h_hmp;	/* mount point associated with this hnode */
     73 	struct vnode *h_devvp;		/* vnode for block I/O */
     74 	dev_t	h_dev;				/* device associated with this hnode */
     75 
     76 	union {
     77 		hfs_file_record_t		file;
     78 		hfs_folder_record_t	folder;
     79 		struct {
     80 			int16_t			rec_type;
     81 			uint16_t		flags;
     82 			uint32_t		valence;
     83 			hfs_cnid_t		cnid;
     84 		}; /* convenience for accessing common record info */
     85 	} h_rec; /* catalog record for this hnode */
     86 
     87 	/*
     88 	 * We cache this vnode's parent CNID here upon vnode creation (i.e., during
     89 	 * hfs_vop_vget()) for quick access without needing to search the catalog.
     90 	 * Note, however, that this value must also be updated whenever this file
     91 	 * is moved.
     92 	 */
     93 	hfs_cnid_t		h_parent;
     94 
     95 	uint8_t h_fork;
     96 
     97 	long	dummy;	/* FOR DEVELOPMENT ONLY */
     98 };
     99 
    100 typedef struct {
    101 	struct vnode* devvp; /* vnode for device I/O */
    102 	size_t devblksz; /* device block size (NOT HFS+ allocation block size)*/
    103 } hfs_libcb_data; /* custom data used in hfs_volume.cbdata */
    104 
    105 typedef struct {
    106 	kauth_cred_t cred;
    107 	struct lwp *l;
    108 	struct vnode *devvp;
    109 } hfs_libcb_argsopen;
    110 
    111 typedef struct {
    112 	struct lwp *l;
    113 } hfs_libcb_argsclose;
    114 
    115 typedef struct {
    116 	kauth_cred_t cred;
    117 	struct lwp *l;
    118 } hfs_libcb_argsread;
    119 
    120 #ifdef _KERNEL
    121 
    122 MALLOC_DECLARE(M_HFSMNT);	/* defined in hfs_vfsops.c */
    123 
    124 /*
    125  * Convenience macros
    126  */
    127 
    128 /* Convert mount ptr to hfsmount ptr. */
    129 #define VFSTOHFS(mp)    ((struct hfsmount *)((mp)->mnt_data))
    130 
    131 /* Convert between vnode ptrs and hfsnode ptrs. */
    132 #define VTOH(vp)    ((struct hfsnode *)(vp)->v_data)
    133 #define	HTOV(hp)	((hp)->h_vnode)
    134 
    135 /* Get volume's allocation block size given a vnode ptr */
    136 #define HFS_BLOCKSIZE(vp)    (VTOH(vp)->h_hmp->hm_vol.vh.block_size)
    137 
    138 
    139 /* Convert special device major/minor */
    140 #define HFS_CONVERT_RDEV(x)	makedev((x)>>24, (x)&0xffffff)
    141 
    142 /*
    143  * Global variables
    144  */
    145 
    146 extern const struct vnodeopv_desc hfs_vnodeop_opv_desc;
    147 extern const struct vnodeopv_desc hfs_specop_opv_desc;
    148 extern const struct vnodeopv_desc hfs_fifoop_opv_desc;
    149 extern int (**hfs_specop_p) (void *);
    150 extern int (**hfs_fifoop_p) (void *);
    151 
    152 
    153 /*
    154  * Function prototypes
    155  */
    156 
    157 /* hfs_nhash.c */
    158 void hfs_nhashinit (void);
    159 void hfs_nhashdone (void);
    160 struct vnode *hfs_nhashget (dev_t, hfs_cnid_t, uint8_t, int);
    161 void hfs_nhashinsert (struct hfsnode *);
    162 void hfs_nhashremove (struct hfsnode *);
    163 
    164 /* hfs_subr.c */
    165 void hfs_vinit (struct mount *, int (**)(void *), int (**)(void *),
    166 		 struct vnode **);
    167 int hfs_pread(struct vnode*, void*, size_t, uint64_t, uint64_t, kauth_cred_t);
    168 char* hfs_unicode_to_ascii(const unichar_t*, uint8_t, char*);
    169 unichar_t* hfs_ascii_to_unicode(const char*, uint8_t, unichar_t*);
    170 
    171 void hfs_time_to_timespec(uint32_t, struct timespec *);
    172 enum vtype hfs_catalog_keyed_record_vtype(const hfs_catalog_keyed_record_t *);
    173 
    174 void hfs_libcb_error(const char*, const char*, int, va_list);
    175 void* hfs_libcb_malloc(size_t, hfs_callback_args*);
    176 void* hfs_libcb_realloc(void*, size_t, hfs_callback_args*);
    177 void hfs_libcb_free(void*, hfs_callback_args*);
    178 int hfs_libcb_opendev(hfs_volume*, const char*, hfs_callback_args*);
    179 void hfs_libcb_closedev(hfs_volume*, hfs_callback_args*);
    180 int hfs_libcb_read(hfs_volume*, void*, uint64_t, uint64_t,
    181 	hfs_callback_args*);
    182 
    183 uint16_t be16tohp(void**);
    184 uint32_t be32tohp(void**);
    185 uint64_t be64tohp(void**);
    186 
    187 
    188 /* hfs_vfsops.c */
    189 VFS_PROTOS(hfs);
    190 
    191 int hfs_mountfs (struct vnode *, struct mount *, struct lwp *, const char *);
    192 int hfs_vget_internal(struct mount *, ino_t, uint8_t, struct vnode **);
    193 
    194 /* hfs_vnops.c */
    195 extern int (**hfs_vnodeop_p) (void *);
    196 
    197 #endif /* _KERNEL */
    198 
    199 #endif /* !_FS_HFS_HFS_H_ */
    200