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