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