1/* $NetBSD: adosfs.h,v 1.10 2009/03/14 14:46:09 dsl Exp $ */ 2 3/* 4 * Copyright (c) 1994 Christian E. Hopps 5 * Copyright (c) 1996 Matthias Scheler 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by Christian E. Hopps. 19 * 4. The name of the author may not be used to endorse or promote products 20 * derived from this software without specific prior written permission 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34#ifndef _ADOSFS_ADOSFS_H_ 35#define _ADOSFS_ADOSFS_H_ 36/* 37 * Arguments to mount amigados filesystems. 38 */ 39struct adosfs_args { 40 char *fspec; /* blocks special holding the fs to mount */ 41 struct export_args30 _pad1; /* compat with old userland tools */ 42 uid_t uid; /* uid that owns adosfs files */ 43 gid_t gid; /* gid that owns adosfs files */ 44 mode_t mask; /* mask to be applied for adosfs perms */ 45}; 46 47#ifdef _KERNEL 48#include <sys/mallocvar.h> 49#include <miscfs/genfs/genfs_node.h> 50 51MALLOC_DECLARE(M_ANODE); 52 53/* 54 * Amigados datestamp. (from 1/1/1978 00:00:00 local) 55 */ 56struct datestamp { 57 u_int32_t days; 58 u_int32_t mins; 59 u_int32_t ticks; /* 20000 * (ticks % 50) = useconds */ 60 /* ticks / 50 = seconds */ 61}; 62 63enum anode_type { AROOT, ADIR, AFILE, ALDIR, ALFILE, ASLINK }; 64 65/* Maximum file/directory name */ 66#define ADMAXNAMELEN 30 67 68/* 69 * similar to inode's, we use to represent: 70 * the root dir, reg dirs, reg files and extension blocks 71 * note the ``tab'' is a hash table for r/d, and a data block 72 * table for f/e. it is always ANODETABSZ(ap) bytes in size. 73 */ 74struct anode { 75 struct genfs_node gnode; 76 LIST_ENTRY(anode) link; 77 enum anode_type type; 78 char name[ADMAXNAMELEN+1]; /* (r/d/f) name for object */ 79 struct datestamp mtimev; /* (r) volume modified */ 80 struct datestamp created; /* (r) volume created */ 81 struct datestamp mtime; /* (r/d/f) last modified */ 82 struct adosfsmount *amp; /* owner file system */ 83 struct vnode *vp; /* owner vnode */ 84 u_long fsize; /* (f) size of file in bytes */ 85 u_long block; /* block num */ 86 u_long pblock; /* (d/f/e) parent block */ 87 u_long hashf; /* (d/f) hash forward */ 88 u_long extb; /* (f/e) extension block number */ 89 u_long linkto; /* (hd/hf) header this link points at */ 90 u_long linknext; /* (d/f/hd/hf) next link (or head) in chain */ 91 u_long lastlindblk; /* (f/hf) last logical indirect block */ 92 u_long lastindblk; /* (f/hf) last indirect block read */ 93 u_long *tab; /* (r/d) hash table */ 94 int *tabi; /* (r/d) table info */ 95 int ntabent; /* (r/d) number of entries in table */ 96 int nwords; /* size of blocks in long words */ 97 int adprot; /* (d/f) amigados protection bits */ 98 uid_t uid; /* (d/f) uid of directory/file */ 99 gid_t gid; /* (d/f) gid of directory/file */ 100 int flags; /* misc flags */ 101 char *slinkto; /* name of file or dir */ 102}; 103#define VTOA(vp) ((struct anode *)(vp)->v_data) 104#define ATOV(ap) ((ap)->vp) 105#define ANODETABSZ(ap) (((ap)->nwords - 56) * sizeof(long)) 106#define ANODETABENT(ap) ((ap)->nwords - 56) 107#define ANODENDATBLKENT(ap) ((ap)->nwords - 56) 108 109/* 110 * mount data 111 */ 112#define ANODEHASHSZ (512) 113 114struct adosfsmount { 115 LIST_HEAD(anodechain, anode) anodetab[ANODEHASHSZ]; 116 struct mount *mp; /* owner mount */ 117 u_int32_t dostype; /* type of volume */ 118 u_long rootb; /* root block number */ 119 u_long secsperblk; /* sectors per block */ 120 u_long bsize; /* size of blocks */ 121 u_long nwords; /* size of blocks in long words */ 122 u_long dbsize; /* data bytes per block */ 123 uid_t uid; /* uid of mounting user */ 124 gid_t gid; /* gid of mounting user */ 125 u_long mask; /* mode mask */ 126 struct vnode *devvp; /* blk device mounted on */ 127 struct vnode *rootvp; /* out root vnode */ 128 u_long *bitmap; /* allocation bitmap */ 129 u_long numblks; /* number of usable blocks */ 130 u_long freeblks; /* number of free blocks */ 131}; 132 133#define VFSTOADOSFS(mp) ((struct adosfsmount *)(mp)->mnt_data) 134 135#define IS_FFS(amp) ((amp)->dostype & 1) 136#define IS_INTER(amp) (((amp)->dostype & 7) > 1) 137 138/* 139 * AmigaDOS block stuff. 140 */ 141#define BBOFF (0) 142 143#define BPT_SHORT ((u_int32_t)2) 144#define BPT_DATA ((u_int32_t)8) 145#define BPT_LIST ((u_int32_t)16) 146 147#define BST_RDIR ((u_int32_t)1) 148#define BST_UDIR ((u_int32_t)2) 149#define BST_SLINK ((u_int32_t)3) 150#define BST_LDIR ((u_int32_t)4) 151#define BST_FILE ((u_int32_t)-3) 152#define BST_LFILE ((u_int32_t)-4) 153 154#define OFS_DATA_OFFSET (24) 155 156extern struct pool adosfs_node_pool; 157 158/* 159 * utility protos 160 */ 161#if BYTE_ORDER != BIG_ENDIAN 162u_int32_t adoswordn(struct buf *, int); 163#else 164#define adoswordn(bp,wn) (*((u_int32_t *)(bp)->b_data + (wn))) 165#endif 166 167u_int32_t adoscksum(struct buf *, int); 168int adoscaseequ(const u_char *, const u_char *, int, int); 169int adoshash(const u_char *, int, int, int); 170int adunixprot(int); 171int adosfs_getblktype(struct adosfsmount *, struct buf *); 172 173struct vnode *adosfs_ahashget(struct mount *, ino_t); 174void adosfs_ainshash(struct adosfsmount *, struct anode *); 175void adosfs_aremhash(struct anode *); 176 177int adosfs_lookup(void *); 178 179extern int (**adosfs_vnodeop_p)(void *); 180 181/* Should print a vnode or the vnode-op's arguments? */ 182#define advopprint(p) /* XXX */ 183 184#endif /* _KERNEL */ 185#endif /* _ADOSFS_ADOSFS_H_ */ 186