Remove building with NOCRYPTO option
[minix3.git] / lib / libpuffs / pnode.c
blob81441eb0980c98176b4c12cb5d8fa54dfb11f8be
1 /* $NetBSD: pnode.c,v 1.13 2012/08/16 09:25:43 manu 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 #include <sys/cdefs.h>
29 #if !defined(lint)
30 __RCSID("$NetBSD: pnode.c,v 1.13 2012/08/16 09:25:43 manu Exp $");
31 #endif /* !lint */
33 #include <sys/types.h>
35 #include <assert.h>
36 #include <puffs.h>
37 #include <stdlib.h>
38 #include <stdio.h>
39 #include <string.h>
41 #include "puffs_priv.h"
44 * Well, you're probably wondering why this isn't optimized.
45 * The reason is simple: my available time is not optimized for
46 * size ... so please be patient ;)
48 struct puffs_node *
49 puffs_pn_new(struct puffs_usermount *pu, void *privdata)
51 struct puffs_node *pn;
53 pn = calloc(1, sizeof(struct puffs_node));
54 if (pn == NULL)
55 return NULL;
57 pn->pn_data = privdata;
58 pn->pn_mnt = pu;
59 puffs_vattr_null(&pn->pn_va);
61 LIST_INSERT_HEAD(&pu->pu_pnodelst, pn, pn_entries);
63 pu->pu_flags |= PUFFS_FLAG_PNCOOKIE;
65 return pn;
68 void
69 puffs_pn_remove(struct puffs_node *pn)
72 LIST_REMOVE(pn, pn_entries);
73 pn->pn_flags |= PUFFS_NODE_REMOVED;
74 #if defined(__minix)
75 if (pn->pn_count != 0) {
76 struct puffs_usermount *pu = pn->pn_mnt;
77 assert(pu != NULL);
79 /* XXX FS removes this pn from the list to prevent further
80 * lookups from finding node after remove/rm/rename op.
81 * But VFS still uses it, i.e. pnode is still open, and
82 * will put it later. Keep it in separate list to do reclaim
83 * in fs_put().
85 LIST_INSERT_HEAD(&pu->pu_pnode_removed_lst, pn, pn_entries);
87 #endif /* defined(__minix) */
90 void
91 puffs_pn_put(struct puffs_node *pn)
93 struct puffs_usermount *pu = pn->pn_mnt;
95 pu->pu_pathfree(pu, &pn->pn_po);
96 if ((pn->pn_flags & PUFFS_NODE_REMOVED) == 0)
97 LIST_REMOVE(pn, pn_entries);
98 free(pn);
101 /* walk list, rv can be used either to halt or to return a value */
102 void *
103 puffs_pn_nodewalk(struct puffs_usermount *pu, puffs_nodewalk_fn fn, void *arg)
105 struct puffs_node *pn_cur, *pn_next;
106 void *rv;
108 pn_cur = LIST_FIRST(&pu->pu_pnodelst);
109 while (pn_cur) {
110 pn_next = LIST_NEXT(pn_cur, pn_entries);
111 rv = fn(pu, pn_cur, arg);
112 if (rv)
113 return rv;
114 pn_cur = pn_next;
117 return NULL;
120 struct vattr *
121 puffs_pn_getvap(struct puffs_node *pn)
124 return &pn->pn_va;
127 void *
128 puffs_pn_getpriv(struct puffs_node *pn)
131 return pn->pn_data;
134 void
135 puffs_pn_setpriv(struct puffs_node *pn, void *priv)
138 pn->pn_data = priv;
141 struct puffs_pathobj *
142 puffs_pn_getpo(struct puffs_node *pn)
145 return &pn->pn_po;
148 struct puffs_usermount *
149 puffs_pn_getmnt(struct puffs_node *pn)
152 return pn->pn_mnt;
155 /* convenience / shortcut */
156 void *
157 puffs_pn_getmntspecific(struct puffs_node *pn)
160 return pn->pn_mnt->pu_privdata;
164 * newnode parameters
166 void
167 puffs_newinfo_setcookie(struct puffs_newinfo *pni, puffs_cookie_t cookie)
170 *pni->pni_cookie = cookie;
173 void
174 puffs_newinfo_setvtype(struct puffs_newinfo *pni, enum vtype vt)
177 *pni->pni_vtype = vt;
180 void
181 puffs_newinfo_setsize(struct puffs_newinfo *pni, voff_t size)
184 *pni->pni_size = size;
187 void
188 puffs_newinfo_setrdev(struct puffs_newinfo *pni, dev_t rdev)
191 *pni->pni_rdev = rdev;
194 void
195 puffs_newinfo_setva(struct puffs_newinfo *pni, struct vattr *va)
198 (void)memcpy(pni->pni_va, va, sizeof(struct vattr));
201 void
202 puffs_newinfo_setvattl(struct puffs_newinfo *pni, struct timespec *va_ttl)
205 pni->pni_va_ttl->tv_sec = va_ttl->tv_sec;
206 pni->pni_va_ttl->tv_nsec = va_ttl->tv_nsec;
209 void
210 puffs_newinfo_setcnttl(struct puffs_newinfo *pni, struct timespec *cn_ttl)
213 pni->pni_cn_ttl->tv_sec = cn_ttl->tv_sec;
214 pni->pni_cn_ttl->tv_nsec = cn_ttl->tv_nsec;