hfs.h revision 1.1 1 /* $NetBSD: hfs.h,v 1.1 2007/03/06 00:22:04 dillo 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_HFSP_HFSP_H_
33 #define _FS_HFSP_HFSP_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 HFSP_DEBUG*/
42
43 #ifdef HFSP_DEBUG
44 #if defined(_KERNEL) && !defined(_LKM)
45 #include "opt_ddb.h"
46 #endif /* defined(_KERNEL_) && !defined(_LKM) */
47 #endif /* HFSP_DEBUG */
48
49 #include <fs/hfsp/libhfsp.h>
50
51 /* XXX: make these mount options */
52 #define HFSP_DEFAULT_UID 0
53 #define HFSP_DEFAULT_GID 0
54 #define HFSP_DEFAULT_DIR_MODE 0755
55 #define HFSP_DEFAULT_FILE_MODE 0755
56
57 MALLOC_DECLARE(M_HFSPMNT); /* defined in hfsp_vfsops.c */
58
59 struct hfsp_args {
60 char *fspec; /* block special device to mount */
61 uint64_t offset; /*number of bytes to start of volume from start of device*/
62 };
63
64 struct hfspmount {
65 struct mount *hm_mountp; /* filesystem vfs structure */
66 dev_t hm_dev; /* device mounted */
67 struct vnode *hm_devvp; /* block device mounted vnode */
68 hfsp_volume hm_vol; /* essential volume information */
69 uint64_t offset; /* number of device bloks to start of volume from start of device*/
70 };
71
72 struct hfspnode {
73 struct genfs_node h_gnode;
74 LIST_ENTRY(hfspnode) h_hash;/* hash chain */
75 struct vnode *h_vnode; /* vnode associated with this hnode */
76 struct hfspmount *h_hmp; /* mount point associated with this hnode */
77 struct vnode *h_devvp; /* vnode for block I/O */
78 dev_t h_dev; /* device associated with this hnode */
79
80 union {
81 hfsp_file_record_t file;
82 hfsp_folder_record_t folder;
83 struct {
84 int16_t rec_type;
85 uint16_t flags;
86 uint32_t valence;
87 hfsp_cnid_t cnid;
88 }; /* convenience for accessing common record info */
89 } h_rec; /* catalog record for this hnode */
90
91 /*
92 * We cache this vnode's parent CNID here upon vnode creation (i.e., during
93 * hfsp_vop_vget()) for quick access without needing to search the catalog.
94 * Note, however, that this value must also be updated whenever this file
95 * is moved.
96 */
97 hfsp_cnid_t h_parent;
98
99 uint8_t h_fork;
100
101 long dummy; /* FOR DEVELOPMENT ONLY */
102 };
103
104 typedef struct {
105 uint64_t offset; /* offset to start of volume from start of device */
106 struct vnode* devvp; /* vnode for device I/O */
107 size_t devblksz; /* device block size (NOT HFS+ allocation block size)*/
108 } hfsp_libcb_data; /* custom data used in hfsp_volume.cbdata */
109
110 typedef struct {
111 kauth_cred_t cred;
112 struct lwp *l;
113 struct vnode *devvp;
114 } hfsp_libcb_argsopen;
115
116 typedef struct {
117 struct lwp *l;
118 } hfsp_libcb_argsclose;
119
120 typedef struct {
121 kauth_cred_t cred;
122 struct lwp *l;
123 } hfsp_libcb_argsread;
124
125 /*
126 * Convenience macros
127 */
128
129 /* Convert mount ptr to hfspmount ptr. */
130 #define VFSTOHFSP(mp) ((struct hfspmount *)((mp)->mnt_data))
131
132 /* Convert between vnode ptrs and hfsnode ptrs. */
133 #define VTOH(vp) ((struct hfspnode *)(vp)->v_data)
134 #define HTOV(hp) ((hp)->h_vnode)
135
136 /* Get volume's allocation block size given a vnode ptr */
137 #define HFSP_BLOCKSIZE(vp) (VTOH(vp)->h_hmp->hm_vol.vh.block_size)
138
139
140 /* Convert special device major/minor */
141 #define HFSP_CONVERT_RDEV(x) makedev((x)>>24, (x)&0xffffff)
142
143 /*
144 * Global variables
145 */
146
147 extern const struct vnodeopv_desc hfsp_vnodeop_opv_desc;
148 extern const struct vnodeopv_desc hfsp_specop_opv_desc;
149 extern const struct vnodeopv_desc hfsp_fifoop_opv_desc;
150 extern int (**hfsp_specop_p) (void *);
151 extern int (**hfsp_fifoop_p) (void *);
152
153
154 /*
155 * Function prototypes
156 */
157
158 /* hfsp_nhash.c */
159 void hfsp_nhashinit (void);
160 void hfsp_nhashdone (void);
161 struct vnode *hfsp_nhashget (dev_t, hfsp_cnid_t, uint8_t, int);
162 void hfsp_nhashinsert (struct hfspnode *);
163 void hfsp_nhashremove (struct hfspnode *);
164
165 /* hfsp_subr.c */
166 void hfsp_vinit (struct mount *, int (**)(void *), int (**)(void *),
167 struct vnode **);
168 int hfsp_pread(struct vnode*, void*, size_t, uint64_t, uint64_t, kauth_cred_t);
169 char* hfsp_unicode_to_ascii(const unichar_t*, uint8_t, char*);
170 unichar_t* hfsp_ascii_to_unicode(const char*, uint8_t, unichar_t*);
171
172 void hfsp_time_to_timespec(uint32_t, struct timespec *);
173 enum vtype hfsp_catalog_keyed_record_vtype(const hfsp_catalog_keyed_record_t *);
174
175 void hfsp_libcb_error(const char*, const char*, int, va_list);
176 void* hfsp_libcb_malloc(size_t, hfsp_callback_args*);
177 void* hfsp_libcb_realloc(void*, size_t, hfsp_callback_args*);
178 void hfsp_libcb_free(void*, hfsp_callback_args*);
179 int hfsp_libcb_opendev(hfsp_volume*, const char*, uint64_t,hfsp_callback_args*);
180 void hfsp_libcb_closedev(hfsp_volume*, hfsp_callback_args*);
181 int hfsp_libcb_read(hfsp_volume*, void*, uint64_t, uint64_t,
182 hfsp_callback_args*);
183
184 uint16_t be16tohp(void**);
185 uint32_t be32tohp(void**);
186 uint64_t be64tohp(void**);
187
188
189 /* hfsp_vfsops.c */
190 int hfsp_mount (struct mount *, const char *, void *, struct nameidata *,
191 struct lwp *);
192 int hfsp_mountfs (struct vnode *, struct mount *, struct lwp *,
193 const char *, uint64_t);
194 int hfsp_start (struct mount *, int, struct lwp *);
195 int hfsp_unmount (struct mount *, int, struct lwp *);
196 int hfsp_root (struct mount *, struct vnode **);
197 int hfsp_quotactl (struct mount *, int, uid_t, void *, struct lwp *);
198 int hfsp_statvfs (struct mount *, struct statvfs *, struct lwp *);
199 int hfsp_sync (struct mount *, int, kauth_cred_t , struct lwp *);
200 int hfsp_vget (struct mount *, ino_t, struct vnode **);
201 int hfsp_vget_internal(struct mount *, ino_t, uint8_t, struct vnode **);
202 int hfsp_fhtovp (struct mount *, struct fid *, struct vnode **);
203 int hfsp_vptofh (struct vnode *, struct fid *, size_t *);
204 void hfsp_init (void);
205 void hfsp_reinit (void);
206 void hfsp_done (void);
207 int hfsp_mountroot (void);
208 int hfsp_extattrctl (struct mount *, int, struct vnode *, int, const char *,
209 struct lwp *);
210
211 /* hfsp_vnops.c */
212 extern int (**hfsp_vnodeop_p) (void *);
213
214 #endif /* !_FS_HFSP_HFSP_H_ */
215