custom message type for VM_INFO
[minix3.git] / lib / libpuffs / pnode.c
blobb8283091539c85f56a33b2961da05cf770fca8e7
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"
42 #if defined(__minix)
43 #include <minix/type.h>
44 #include "proto.h"
45 #endif /* defined(__minix) */
48 * Well, you're probably wondering why this isn't optimized.
49 * The reason is simple: my available time is not optimized for
50 * size ... so please be patient ;)
52 struct puffs_node *
53 puffs_pn_new(struct puffs_usermount *pu, void *privdata)
55 struct puffs_node *pn;
57 pn = calloc(1, sizeof(struct puffs_node));
58 if (pn == NULL)
59 return NULL;
61 pn->pn_data = privdata;
62 pn->pn_mnt = pu;
63 puffs_vattr_null(&pn->pn_va);
65 LIST_INSERT_HEAD(&pu->pu_pnodelst, pn, pn_entries);
67 pu->pu_flags |= PUFFS_FLAG_PNCOOKIE;
69 return pn;
72 void
73 puffs_pn_remove(struct puffs_node *pn)
75 struct puffs_usermount *pu = pn->pn_mnt;
76 assert(pu != NULL);
78 LIST_REMOVE(pn, pn_entries);
79 pn->pn_flags |= PUFFS_NODE_REMOVED;
80 if (pn->pn_count != 0) {
81 /* XXX FS removes this pn from the list to prevent further
82 * lookups from finding node after remove/rm/rename op.
83 * But VFS still uses it, i.e. pnode is still open, and
84 * will put it later. Keep it in separate list to do reclaim
85 * in fs_put().
87 LIST_INSERT_HEAD(&pu->pu_pnode_removed_lst, pn, pn_entries);
91 void
92 puffs_pn_put(struct puffs_node *pn)
94 struct puffs_usermount *pu = pn->pn_mnt;
96 pu->pu_pathfree(pu, &pn->pn_po);
97 if ((pn->pn_flags & PUFFS_NODE_REMOVED) == 0)
98 LIST_REMOVE(pn, pn_entries);
99 free(pn);
102 /* walk list, rv can be used either to halt or to return a value
103 * XXX (MINIX note): if fn is 0, then arg is ino_t and we search
104 * node with ino_t. TODO: modify docs.
106 void *
107 puffs_pn_nodewalk(struct puffs_usermount *pu, puffs_nodewalk_fn fn, void *arg)
109 struct puffs_node *pn_cur, *pn_next;
110 void *rv;
112 pn_cur = LIST_FIRST(&pu->pu_pnodelst);
113 while (pn_cur) {
114 pn_next = LIST_NEXT(pn_cur, pn_entries);
115 if (fn) {
116 rv = fn(pu, pn_cur, arg);
117 if (rv)
118 return rv;
119 } else {
120 if (pn_cur->pn_va.va_fileid == *((ino_t*) arg))
121 return pn_cur;
123 pn_cur = pn_next;
126 return NULL;
129 struct vattr *
130 puffs_pn_getvap(struct puffs_node *pn)
133 return &pn->pn_va;
136 void *
137 puffs_pn_getpriv(struct puffs_node *pn)
140 return pn->pn_data;
143 void
144 puffs_pn_setpriv(struct puffs_node *pn, void *priv)
147 pn->pn_data = priv;
150 struct puffs_pathobj *
151 puffs_pn_getpo(struct puffs_node *pn)
154 return &pn->pn_po;
157 struct puffs_usermount *
158 puffs_pn_getmnt(struct puffs_node *pn)
161 return pn->pn_mnt;
164 /* convenience / shortcut */
165 void *
166 puffs_pn_getmntspecific(struct puffs_node *pn)
169 return pn->pn_mnt->pu_privdata;
173 * newnode parameters
175 void
176 puffs_newinfo_setcookie(struct puffs_newinfo *pni, puffs_cookie_t cookie)
179 *pni->pni_cookie = cookie;
182 void
183 puffs_newinfo_setvtype(struct puffs_newinfo *pni, enum vtype vt)
186 *pni->pni_vtype = vt;
189 void
190 puffs_newinfo_setsize(struct puffs_newinfo *pni, voff_t size)
193 *pni->pni_size = size;
196 void
197 puffs_newinfo_setrdev(struct puffs_newinfo *pni, dev_t rdev)
200 *pni->pni_rdev = rdev;
203 void
204 puffs_newinfo_setva(struct puffs_newinfo *pni, struct vattr *va)
207 (void)memcpy(pni->pni_va, va, sizeof(struct vattr));
210 void
211 puffs_newinfo_setvattl(struct puffs_newinfo *pni, struct timespec *va_ttl)
214 pni->pni_va_ttl->tv_sec = va_ttl->tv_sec;
215 pni->pni_va_ttl->tv_nsec = va_ttl->tv_nsec;
218 void
219 puffs_newinfo_setcnttl(struct puffs_newinfo *pni, struct timespec *cn_ttl)
222 pni->pni_cn_ttl->tv_sec = cn_ttl->tv_sec;
223 pni->pni_cn_ttl->tv_nsec = cn_ttl->tv_nsec;