Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / lib / libpuffs / flush.c
blob0f9858c88d602c74d28fd82d99962e15cac75558
1 /* $NetBSD: flush.c,v 1.15 2007/12/05 18:55:19 pooka Exp $ */
3 /*
4 * Copyright (c) 2007 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: flush.c,v 1.15 2007/12/05 18:55:19 pooka Exp $");
31 #endif /* !lint */
34 * Flushing / invalidation routines
37 #include <sys/types.h>
39 #include <assert.h>
40 #include <err.h>
41 #include <errno.h>
42 #include <puffs.h>
43 #include <stdio.h>
44 #include <unistd.h>
46 #include "puffs_priv.h"
48 #if 0
49 int
50 puffs_inval_namecache_node(struct puffs_usermount *pu, puffs_cookie_t cookie,
51 const char *name)
54 return EOPNOTSUPP;
56 #endif
58 static int
59 doflush(struct puffs_usermount *pu, puffs_cookie_t cookie, int op,
60 off_t start, off_t end)
62 struct puffs_framebuf *pb;
63 struct puffs_flush *pf;
64 size_t winlen;
65 int rv;
67 pb = puffs_framebuf_make();
68 if (pb == NULL)
69 return ENOMEM;
71 winlen = sizeof(struct puffs_flush);
72 if ((rv = puffs_framebuf_getwindow(pb, 0, (void *)&pf, &winlen)) == -1)
73 goto out;
74 assert(winlen == sizeof(struct puffs_flush));
76 pf->pf_req.preq_buflen = sizeof(struct puffs_flush);
77 pf->pf_req.preq_opclass = PUFFSOP_FLUSH;
78 pf->pf_req.preq_id = puffs__nextreq(pu);
80 pf->pf_op = op;
81 pf->pf_cookie = cookie;
82 pf->pf_start = start;
83 pf->pf_end = end;
85 rv = puffs_framev_enqueue_cc(puffs_cc_getcc(pu),
86 puffs_getselectable(pu), pb, 0);
88 out:
89 puffs_framebuf_destroy(pb);
90 return rv;
93 int
94 puffs_inval_namecache_dir(struct puffs_usermount *pu, puffs_cookie_t cookie)
97 return doflush(pu, cookie, PUFFS_INVAL_NAMECACHE_DIR, 0, 0);
101 puffs_inval_namecache_all(struct puffs_usermount *pu)
104 return doflush(pu, NULL, PUFFS_INVAL_NAMECACHE_ALL, 0, 0);
108 puffs_inval_pagecache_node(struct puffs_usermount *pu, puffs_cookie_t cookie)
111 return doflush(pu, cookie, PUFFS_INVAL_PAGECACHE_NODE_RANGE, 0, 0);
115 puffs_inval_pagecache_node_range(struct puffs_usermount *pu,
116 puffs_cookie_t cookie, off_t start, off_t end)
119 return doflush(pu, cookie, PUFFS_INVAL_PAGECACHE_NODE_RANGE, start,end);
123 puffs_flush_pagecache_node(struct puffs_usermount *pu, puffs_cookie_t cookie)
126 return doflush(pu, cookie, PUFFS_FLUSH_PAGECACHE_NODE_RANGE, 0, 0);
130 puffs_flush_pagecache_node_range(struct puffs_usermount *pu,
131 puffs_cookie_t cookie, off_t start, off_t end)
134 return doflush(pu, cookie, PUFFS_FLUSH_PAGECACHE_NODE_RANGE, start,end);