tools/llvm: Do not build with symbols
[minix3.git] / lib / libpuffs / inode.c
blob629ea8dcaf1eb1ab699b129c588424ea6f2c4573
1 /*
2 * Created (MFS based):
3 * June 2011 (Evgeniy Ivanov)
4 */
6 #include "fs.h"
7 #include <string.h>
8 #include <assert.h>
9 #include <minix/vfsif.h>
11 #include "puffs.h"
12 #include "puffs_priv.h"
15 void release_node(struct puffs_usermount *pu, struct puffs_node *pn)
17 assert(pn->pn_count == 0);
19 /* Required if puffs_node_reclaim() decides to leave node in the list */
20 pn->pn_mountpoint = FALSE;
22 if (pu->pu_ops.puffs_node_reclaim) {
23 if (global_pu->pu_ops.puffs_node_reclaim(global_pu, pn) != 0)
24 lpuffs_debug("Warning: reclaim failed\n");
25 } else {
26 puffs_pn_put(pn);
31 /*===========================================================================*
32 * fs_putnode *
33 *===========================================================================*/
34 int fs_putnode(void)
36 /* Find the pnode specified by the request message and decrease its counter.
37 * Release unused pnode.
39 struct puffs_node *pn;
40 int count = fs_m_in.m_vfs_fs_putnode.count;
41 ino_t inum = fs_m_in.m_vfs_fs_putnode.inode;
43 if ((pn = puffs_pn_nodewalk(global_pu, 0, &inum)) == NULL) {
44 /* XXX Probably removed from the list, see puffs_pn_remove() */
45 struct puffs_node *pn_cur, *pn_next;
46 pn_cur = LIST_FIRST(&global_pu->pu_pnode_removed_lst);
47 while (pn_cur) {
48 pn_next = LIST_NEXT(pn_cur, pn_entries);
49 if (pn_cur->pn_va.va_fileid == inum) {
50 pn = pn_cur;
51 break;
53 pn_cur = pn_next;
57 if (pn == NULL) {
58 lpuffs_debug("%s:%d putnode: pnode #%ld dev: %d not found\n", __FILE__,
59 __LINE__, inum, fs_dev);
60 panic("fs_putnode failed");
63 if (count <= 0) {
64 lpuffs_debug("%s:%d putnode: bad value for count: %d\n", __FILE__,
65 __LINE__, count);
66 panic("fs_putnode failed");
67 } else if (pn->pn_count == 0) {
68 /* FUSE fs might store in the list pnodes, which we hasn't
69 * open, this means we got put request for file,
70 * which wasn't opened by VFS.
72 lpuffs_debug("%s:%d putnode: pn_count already zero\n", __FILE__,
73 __LINE__);
74 panic("fs_putnode failed");
75 } else if (count > pn->pn_count) {
76 struct puffs_node *pn_cur, *pn_next;
77 struct puffs_usermount *pu = global_pu;
78 ino_t ino = pn->pn_va.va_fileid;
80 pn_cur = LIST_FIRST(&pu->pu_pnodelst);
81 lpuffs_debug("inum count path polen hash\n");
82 while (pn_cur) {
83 pn_next = LIST_NEXT(pn_cur, pn_entries);
84 if (pn_cur->pn_va.va_fileid == ino) {
85 lpuffs_debug("%ld: %d %s %u %u\n", ino, pn_cur->pn_count,
86 pn_cur->pn_po.po_path,
87 pn_cur->pn_po.po_len,
88 pn_cur->pn_po.po_hash);
90 pn_cur = pn_next;
92 lpuffs_debug("%s:%d putnode: count too high: %d > %d\n", __FILE__,
93 __LINE__, count, pn->pn_count);
94 panic("fs_putnode failed");
97 pn->pn_count -= count;
99 if (pn->pn_count == 0)
100 release_node(global_pu, pn);
102 return(OK);