Home | History | Annotate | Line # | Download | only in hfs
hfs.h revision 1.1
      1  1.1  dillo /*	$NetBSD: hfs.h,v 1.1 2007/03/06 00:22:04 dillo Exp $	*/
      2  1.1  dillo 
      3  1.1  dillo /*-
      4  1.1  dillo  * Copyright (c) 2005, 2007 The NetBSD Foundation, Inc.
      5  1.1  dillo  * All rights reserved.
      6  1.1  dillo  *
      7  1.1  dillo  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  dillo  * by Yevgeny Binder and Dieter Baron.
      9  1.1  dillo  *
     10  1.1  dillo  * Redistribution and use in source and binary forms, with or without
     11  1.1  dillo  * modification, are permitted provided that the following conditions
     12  1.1  dillo  * are met:
     13  1.1  dillo  * 1. Redistributions of source code must retain the above copyright
     14  1.1  dillo  *    notice, this list of conditions and the following disclaimer.
     15  1.1  dillo  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  dillo  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  dillo  *    documentation and/or other materials provided with the distribution.
     18  1.1  dillo  *
     19  1.1  dillo  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1  dillo  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1  dillo  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1  dillo  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1  dillo  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1  dillo  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1  dillo  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1  dillo  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1  dillo  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1  dillo  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1  dillo  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1  dillo  */
     31  1.1  dillo 
     32  1.1  dillo #ifndef _FS_HFSP_HFSP_H_
     33  1.1  dillo #define _FS_HFSP_HFSP_H_
     34  1.1  dillo 
     35  1.1  dillo #include <sys/vnode.h>
     36  1.1  dillo #include <sys/mount.h>
     37  1.1  dillo 
     38  1.1  dillo #include <miscfs/genfs/genfs_node.h>
     39  1.1  dillo 
     40  1.1  dillo /* XXX remove before release */
     41  1.1  dillo /*#define HFSP_DEBUG*/
     42  1.1  dillo 
     43  1.1  dillo #ifdef HFSP_DEBUG
     44  1.1  dillo 	#if defined(_KERNEL) && !defined(_LKM)
     45  1.1  dillo 		#include "opt_ddb.h"
     46  1.1  dillo 	#endif /* defined(_KERNEL_) && !defined(_LKM) */
     47  1.1  dillo #endif /* HFSP_DEBUG */
     48  1.1  dillo 
     49  1.1  dillo #include <fs/hfsp/libhfsp.h>
     50  1.1  dillo 
     51  1.1  dillo /* XXX: make these mount options */
     52  1.1  dillo #define HFSP_DEFAULT_UID	0
     53  1.1  dillo #define HFSP_DEFAULT_GID	0
     54  1.1  dillo #define HFSP_DEFAULT_DIR_MODE	0755
     55  1.1  dillo #define HFSP_DEFAULT_FILE_MODE	0755
     56  1.1  dillo 
     57  1.1  dillo MALLOC_DECLARE(M_HFSPMNT);	/* defined in hfsp_vfsops.c */
     58  1.1  dillo 
     59  1.1  dillo struct hfsp_args {
     60  1.1  dillo 	char *fspec;		/* block special device to mount */
     61  1.1  dillo 	uint64_t offset; /*number of bytes to start of volume from start of device*/
     62  1.1  dillo };
     63  1.1  dillo 
     64  1.1  dillo struct hfspmount {
     65  1.1  dillo 	struct mount *hm_mountp;	/* filesystem vfs structure */
     66  1.1  dillo 	dev_t hm_dev;				/* device mounted */
     67  1.1  dillo 	struct vnode *hm_devvp;		/* block device mounted vnode */
     68  1.1  dillo 	hfsp_volume hm_vol;			/* essential volume information */
     69  1.1  dillo 	uint64_t offset;		/* number of device bloks to start of volume from start of device*/
     70  1.1  dillo };
     71  1.1  dillo 
     72  1.1  dillo struct hfspnode {
     73  1.1  dillo 	struct genfs_node h_gnode;
     74  1.1  dillo 	LIST_ENTRY(hfspnode) h_hash;/* hash chain */
     75  1.1  dillo 	struct vnode *h_vnode;		/* vnode associated with this hnode */
     76  1.1  dillo 	struct hfspmount *h_hmp;	/* mount point associated with this hnode */
     77  1.1  dillo 	struct vnode *h_devvp;		/* vnode for block I/O */
     78  1.1  dillo 	dev_t	h_dev;				/* device associated with this hnode */
     79  1.1  dillo 
     80  1.1  dillo 	union {
     81  1.1  dillo 		hfsp_file_record_t		file;
     82  1.1  dillo 		hfsp_folder_record_t	folder;
     83  1.1  dillo 		struct {
     84  1.1  dillo 			int16_t			rec_type;
     85  1.1  dillo 			uint16_t		flags;
     86  1.1  dillo 			uint32_t		valence;
     87  1.1  dillo 			hfsp_cnid_t		cnid;
     88  1.1  dillo 		}; /* convenience for accessing common record info */
     89  1.1  dillo 	} h_rec; /* catalog record for this hnode */
     90  1.1  dillo 
     91  1.1  dillo 	/*
     92  1.1  dillo 	 * We cache this vnode's parent CNID here upon vnode creation (i.e., during
     93  1.1  dillo 	 * hfsp_vop_vget()) for quick access without needing to search the catalog.
     94  1.1  dillo 	 * Note, however, that this value must also be updated whenever this file
     95  1.1  dillo 	 * is moved.
     96  1.1  dillo 	 */
     97  1.1  dillo 	hfsp_cnid_t		h_parent;
     98  1.1  dillo 
     99  1.1  dillo 	uint8_t h_fork;
    100  1.1  dillo 
    101  1.1  dillo 	long	dummy;	/* FOR DEVELOPMENT ONLY */
    102  1.1  dillo };
    103  1.1  dillo 
    104  1.1  dillo typedef struct {
    105  1.1  dillo 	uint64_t offset; /* offset to start of volume from start of device */
    106  1.1  dillo 	struct vnode* devvp; /* vnode for device I/O */
    107  1.1  dillo 	size_t devblksz; /* device block size (NOT HFS+ allocation block size)*/
    108  1.1  dillo } hfsp_libcb_data; /* custom data used in hfsp_volume.cbdata */
    109  1.1  dillo 
    110  1.1  dillo typedef struct {
    111  1.1  dillo 	kauth_cred_t cred;
    112  1.1  dillo 	struct lwp *l;
    113  1.1  dillo 	struct vnode *devvp;
    114  1.1  dillo } hfsp_libcb_argsopen;
    115  1.1  dillo 
    116  1.1  dillo typedef struct {
    117  1.1  dillo 	struct lwp *l;
    118  1.1  dillo } hfsp_libcb_argsclose;
    119  1.1  dillo 
    120  1.1  dillo typedef struct {
    121  1.1  dillo 	kauth_cred_t cred;
    122  1.1  dillo 	struct lwp *l;
    123  1.1  dillo } hfsp_libcb_argsread;
    124  1.1  dillo 
    125  1.1  dillo /*
    126  1.1  dillo  * Convenience macros
    127  1.1  dillo  */
    128  1.1  dillo 
    129  1.1  dillo /* Convert mount ptr to hfspmount ptr. */
    130  1.1  dillo #define VFSTOHFSP(mp)    ((struct hfspmount *)((mp)->mnt_data))
    131  1.1  dillo 
    132  1.1  dillo /* Convert between vnode ptrs and hfsnode ptrs. */
    133  1.1  dillo #define VTOH(vp)    ((struct hfspnode *)(vp)->v_data)
    134  1.1  dillo #define	HTOV(hp)	((hp)->h_vnode)
    135  1.1  dillo 
    136  1.1  dillo /* Get volume's allocation block size given a vnode ptr */
    137  1.1  dillo #define HFSP_BLOCKSIZE(vp)    (VTOH(vp)->h_hmp->hm_vol.vh.block_size)
    138  1.1  dillo 
    139  1.1  dillo 
    140  1.1  dillo /* Convert special device major/minor */
    141  1.1  dillo #define HFSP_CONVERT_RDEV(x)	makedev((x)>>24, (x)&0xffffff)
    142  1.1  dillo 
    143  1.1  dillo /*
    144  1.1  dillo  * Global variables
    145  1.1  dillo  */
    146  1.1  dillo 
    147  1.1  dillo extern const struct vnodeopv_desc hfsp_vnodeop_opv_desc;
    148  1.1  dillo extern const struct vnodeopv_desc hfsp_specop_opv_desc;
    149  1.1  dillo extern const struct vnodeopv_desc hfsp_fifoop_opv_desc;
    150  1.1  dillo extern int (**hfsp_specop_p) (void *);
    151  1.1  dillo extern int (**hfsp_fifoop_p) (void *);
    152  1.1  dillo 
    153  1.1  dillo 
    154  1.1  dillo /*
    155  1.1  dillo  * Function prototypes
    156  1.1  dillo  */
    157  1.1  dillo 
    158  1.1  dillo /* hfsp_nhash.c */
    159  1.1  dillo void hfsp_nhashinit (void);
    160  1.1  dillo void hfsp_nhashdone (void);
    161  1.1  dillo struct vnode *hfsp_nhashget (dev_t, hfsp_cnid_t, uint8_t, int);
    162  1.1  dillo void hfsp_nhashinsert (struct hfspnode *);
    163  1.1  dillo void hfsp_nhashremove (struct hfspnode *);
    164  1.1  dillo 
    165  1.1  dillo /* hfsp_subr.c */
    166  1.1  dillo void hfsp_vinit (struct mount *, int (**)(void *), int (**)(void *),
    167  1.1  dillo 		 struct vnode **);
    168  1.1  dillo int hfsp_pread(struct vnode*, void*, size_t, uint64_t, uint64_t, kauth_cred_t);
    169  1.1  dillo char* hfsp_unicode_to_ascii(const unichar_t*, uint8_t, char*);
    170  1.1  dillo unichar_t* hfsp_ascii_to_unicode(const char*, uint8_t, unichar_t*);
    171  1.1  dillo 
    172  1.1  dillo void hfsp_time_to_timespec(uint32_t, struct timespec *);
    173  1.1  dillo enum vtype hfsp_catalog_keyed_record_vtype(const hfsp_catalog_keyed_record_t *);
    174  1.1  dillo 
    175  1.1  dillo void hfsp_libcb_error(const char*, const char*, int, va_list);
    176  1.1  dillo void* hfsp_libcb_malloc(size_t, hfsp_callback_args*);
    177  1.1  dillo void* hfsp_libcb_realloc(void*, size_t, hfsp_callback_args*);
    178  1.1  dillo void hfsp_libcb_free(void*, hfsp_callback_args*);
    179  1.1  dillo int hfsp_libcb_opendev(hfsp_volume*, const char*, uint64_t,hfsp_callback_args*);
    180  1.1  dillo void hfsp_libcb_closedev(hfsp_volume*, hfsp_callback_args*);
    181  1.1  dillo int hfsp_libcb_read(hfsp_volume*, void*, uint64_t, uint64_t,
    182  1.1  dillo 	hfsp_callback_args*);
    183  1.1  dillo 
    184  1.1  dillo uint16_t be16tohp(void**);
    185  1.1  dillo uint32_t be32tohp(void**);
    186  1.1  dillo uint64_t be64tohp(void**);
    187  1.1  dillo 
    188  1.1  dillo 
    189  1.1  dillo /* hfsp_vfsops.c */
    190  1.1  dillo int hfsp_mount (struct mount *, const char *, void *, struct nameidata *,
    191  1.1  dillo 	struct lwp *);
    192  1.1  dillo int hfsp_mountfs (struct vnode *, struct mount *, struct lwp *,
    193  1.1  dillo 	const char *, uint64_t);
    194  1.1  dillo int hfsp_start (struct mount *, int, struct lwp *);
    195  1.1  dillo int hfsp_unmount (struct mount *, int, struct lwp *);
    196  1.1  dillo int hfsp_root (struct mount *, struct vnode **);
    197  1.1  dillo int hfsp_quotactl (struct mount *, int, uid_t, void *, struct lwp *);
    198  1.1  dillo int hfsp_statvfs (struct mount *, struct statvfs *, struct lwp *);
    199  1.1  dillo int hfsp_sync (struct mount *, int, kauth_cred_t , struct lwp *);
    200  1.1  dillo int hfsp_vget (struct mount *, ino_t, struct vnode **);
    201  1.1  dillo int hfsp_vget_internal(struct mount *, ino_t, uint8_t, struct vnode **);
    202  1.1  dillo int hfsp_fhtovp (struct mount *, struct fid *, struct vnode **);
    203  1.1  dillo int hfsp_vptofh (struct vnode *, struct fid *, size_t *);
    204  1.1  dillo void hfsp_init (void);
    205  1.1  dillo void hfsp_reinit (void);
    206  1.1  dillo void hfsp_done (void);
    207  1.1  dillo int hfsp_mountroot (void);
    208  1.1  dillo int hfsp_extattrctl (struct mount *, int, struct vnode *, int, const char *,
    209  1.1  dillo 		     struct lwp *);
    210  1.1  dillo 
    211  1.1  dillo /* hfsp_vnops.c */
    212  1.1  dillo extern int (**hfsp_vnodeop_p) (void *);
    213  1.1  dillo 
    214  1.1  dillo #endif /* !_FS_HFSP_HFSP_H_ */
    215