1 1.2 pooka /* $NetBSD: dtfs.h,v 1.2 2010/07/14 13:09:52 pooka Exp $ */ 2 1.1 pooka 3 1.1 pooka /* 4 1.1 pooka * Copyright (c) 2006 Antti Kantee. All Rights Reserved. 5 1.1 pooka * 6 1.1 pooka * Redistribution and use in source and binary forms, with or without 7 1.1 pooka * modification, are permitted provided that the following conditions 8 1.1 pooka * are met: 9 1.1 pooka * 1. Redistributions of source code must retain the above copyright 10 1.1 pooka * notice, this list of conditions and the following disclaimer. 11 1.1 pooka * 2. Redistributions in binary form must reproduce the above copyright 12 1.1 pooka * notice, this list of conditions and the following disclaimer in the 13 1.1 pooka * documentation and/or other materials provided with the distribution. 14 1.1 pooka * 15 1.1 pooka * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 16 1.1 pooka * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 1.1 pooka * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 1.1 pooka * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 1.1 pooka * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 1.1 pooka * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 1.1 pooka * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 1.1 pooka * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 1.1 pooka * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 1.1 pooka * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 1.1 pooka * SUCH DAMAGE. 26 1.1 pooka */ 27 1.1 pooka 28 1.1 pooka #ifndef DTFS_H_ 29 1.1 pooka #define DTFS_H_ 30 1.1 pooka 31 1.1 pooka #include <sys/types.h> 32 1.1 pooka 33 1.1 pooka #include <puffs.h> 34 1.1 pooka 35 1.1 pooka PUFFSOP_PROTOS(dtfs); 36 1.1 pooka int dtfs_domount(struct puffs_usermount *, const char *); 37 1.1 pooka 38 1.1 pooka #define DTFS_BLOCKSHIFT (12) 39 1.1 pooka #define DTFS_BLOCKSIZE (1<<DTFS_BLOCKSHIFT) 40 1.1 pooka 41 1.1 pooka #define ROUNDUP(a,b) ((a) & ((b)-1)) 42 1.1 pooka #define BLOCKNUM(a,b) (((a) & ~((1<<(b))-1)) >> (b)) 43 1.1 pooka 44 1.1 pooka struct dtfs_fid; 45 1.1 pooka struct dtfs_mount { 46 1.1 pooka ino_t dtm_nextfileid; /* running number for file id */ 47 1.1 pooka 48 1.1 pooka size_t dtm_fsizes; /* sum of file sizes in bytes */ 49 1.1 pooka fsfilcnt_t dtm_nfiles; /* number of files */ 50 1.1 pooka 51 1.1 pooka LIST_HEAD(, dtfs_poll) dtm_pollent; 52 1.1 pooka int dtm_needwakeup; 53 1.1 pooka vm_prot_t dtm_allowprot; 54 1.1 pooka }; 55 1.1 pooka 56 1.1 pooka struct dtfs_file { 57 1.1 pooka union { 58 1.1 pooka struct { 59 1.1 pooka uint8_t **blocks; 60 1.1 pooka size_t numblocks; 61 1.1 pooka size_t datalen; 62 1.1 pooka } reg; 63 1.1 pooka struct { 64 1.1 pooka struct puffs_node *dotdot; 65 1.1 pooka LIST_HEAD(, dtfs_dirent) dirents; 66 1.1 pooka } dir; 67 1.1 pooka struct { 68 1.1 pooka char *target; 69 1.1 pooka } link; 70 1.1 pooka } u; 71 1.1 pooka #define df_blocks u.reg.blocks 72 1.1 pooka #define df_numblocks u.reg.numblocks 73 1.1 pooka #define df_datalen u.reg.datalen 74 1.1 pooka #define df_dotdot u.dir.dotdot 75 1.1 pooka #define df_dirents u.dir.dirents 76 1.1 pooka #define df_linktarget u.link.target 77 1.1 pooka }; 78 1.1 pooka 79 1.1 pooka struct dtfs_dirent { 80 1.1 pooka struct puffs_node *dfd_node; 81 1.1 pooka struct puffs_node *dfd_parent; 82 1.1 pooka char *dfd_name; 83 1.1 pooka size_t dfd_namelen; 84 1.1 pooka 85 1.1 pooka LIST_ENTRY(dtfs_dirent) dfd_entries; 86 1.1 pooka }; 87 1.1 pooka 88 1.1 pooka struct dtfs_fid { 89 1.1 pooka struct puffs_node *dfid_addr; 90 1.1 pooka 91 1.1 pooka /* best^Wsome-effort extra sanity check */ 92 1.1 pooka ino_t dfid_fileid; 93 1.1 pooka u_long dfid_gen; 94 1.1 pooka }; 95 1.1 pooka #define DTFS_FIDSIZE (sizeof(struct dtfs_fid)) 96 1.1 pooka 97 1.1 pooka struct dtfs_poll { 98 1.1 pooka struct puffs_cc *dp_pcc; 99 1.1 pooka LIST_ENTRY(dtfs_poll) dp_entries; 100 1.1 pooka }; 101 1.1 pooka 102 1.1 pooka struct puffs_node * dtfs_genfile(struct puffs_node *, 103 1.1 pooka const struct puffs_cn *, enum vtype); 104 1.1 pooka struct dtfs_file * dtfs_newdir(void); 105 1.1 pooka struct dtfs_file * dtfs_newfile(void); 106 1.1 pooka struct dtfs_dirent * dtfs_dirgetnth(struct dtfs_file *, int); 107 1.1 pooka struct dtfs_dirent * dtfs_dirgetbyname(struct dtfs_file *, 108 1.1 pooka const char *, size_t); 109 1.1 pooka 110 1.1 pooka void dtfs_nukenode(struct puffs_node *, struct puffs_node *, 111 1.1 pooka const char *, size_t); 112 1.1 pooka void dtfs_freenode(struct puffs_node *); 113 1.1 pooka void dtfs_setsize(struct puffs_node *, off_t); 114 1.1 pooka 115 1.1 pooka void dtfs_adddent(struct puffs_node *, struct dtfs_dirent *); 116 1.1 pooka void dtfs_removedent(struct puffs_node *, struct dtfs_dirent *); 117 1.1 pooka 118 1.1 pooka void dtfs_baseattrs(struct vattr *, enum vtype, ino_t); 119 1.1 pooka void dtfs_updatetimes(struct puffs_node *, int, int, int); 120 1.1 pooka 121 1.2 pooka bool dtfs_isunder(struct puffs_node *, struct puffs_node *); 122 1.2 pooka 123 1.1 pooka 124 1.1 pooka #define DTFS_CTOF(a) ((struct dtfs_file *)(((struct puffs_node *)a)->pn_data)) 125 1.1 pooka #define DTFS_PTOF(a) ((struct dtfs_file *)(a->pn_data)) 126 1.1 pooka 127 1.1 pooka #endif /* DTFS_H_ */ 128