Sync usage with man page.
[netbsd-mini2440.git] / share / examples / puffs / dtfs / dtfs.h
blob1e2430b680ed4cb980f65631ce72558ff1e22092
1 /* $NetBSD: dtfs.h,v 1.20 2007/07/27 08:29:10 pooka Exp $ */
3 /*
4 * Copyright (c) 2006 Antti Kantee. All Rights Reserved.
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.
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.
28 #ifndef DTFS_H_
29 #define DTFS_H_
31 #include <sys/types.h>
33 #include <puffs.h>
35 PUFFSOP_PROTOS(dtfs);
36 int dtfs_domount(struct puffs_usermount *, const char *);
38 #define DTFS_BLOCKSHIFT (12)
39 #define DTFS_BLOCKSIZE (1<<DTFS_BLOCKSHIFT)
41 #define ROUNDUP(a,b) ((a) & ((b)-1))
42 #define BLOCKNUM(a,b) (((a) & ~((1<<(b))-1)) >> (b))
44 struct dtfs_fid;
45 struct dtfs_mount {
46 ino_t dtm_nextfileid; /* running number for file id */
48 size_t dtm_fsizes; /* sum of file sizes in bytes */
49 fsfilcnt_t dtm_nfiles; /* number of files */
51 LIST_HEAD(, dtfs_poll) dtm_pollent;
52 int dtm_needwakeup;
53 vm_prot_t dtm_allowprot;
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
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;
85 LIST_ENTRY(dtfs_dirent) dfd_entries;
88 struct dtfs_fid {
89 struct puffs_node *dfid_addr;
91 /* best^Wsome-effort extra sanity check */
92 ino_t dfid_fileid;
93 u_long dfid_gen;
95 #define DTFS_FIDSIZE (sizeof(struct dtfs_fid))
97 struct dtfs_poll {
98 struct puffs_cc *dp_pcc;
99 LIST_ENTRY(dtfs_poll) dp_entries;
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);
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);
115 void dtfs_adddent(struct puffs_node *, struct dtfs_dirent *);
116 void dtfs_removedent(struct puffs_node *, struct dtfs_dirent *);
118 void dtfs_baseattrs(struct vattr *, enum vtype, ino_t);
119 void dtfs_updatetimes(struct puffs_node *, int, int, int);
122 #define DTFS_CTOF(a) ((struct dtfs_file *)(((struct puffs_node *)a)->pn_data))
123 #define DTFS_PTOF(a) ((struct dtfs_file *)(a->pn_data))
125 #endif /* DTFS_H_ */