Home | History | Annotate | Line # | Download | only in libpuffs
flush.c revision 1.12
      1 /*	$NetBSD: flush.c,v 1.12 2007/10/11 19:41:14 pooka Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2007  Antti Kantee.  All Rights Reserved.
      5  *
      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.
     14  *
     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.
     26  */
     27 
     28 #include <sys/cdefs.h>
     29 #if !defined(lint)
     30 __RCSID("$NetBSD: flush.c,v 1.12 2007/10/11 19:41:14 pooka Exp $");
     31 #endif /* !lint */
     32 
     33 /*
     34  * Flushing / invalidation routines
     35  */
     36 
     37 #include <sys/types.h>
     38 
     39 #include <assert.h>
     40 #include <err.h>
     41 #include <errno.h>
     42 #include <puffs.h>
     43 #include <stdio.h>
     44 #include <unistd.h>
     45 
     46 #include "puffs_priv.h"
     47 
     48 #if 0
     49 int
     50 puffs_inval_namecache_node(struct puffs_usermount *pu, void *cookie,
     51 	const char *name)
     52 {
     53 
     54 	return EOPNOTSUPP;
     55 }
     56 #endif
     57 
     58 static int
     59 doflush(struct puffs_usermount *pu, void *cookie, int op,
     60 	off_t start, off_t end)
     61 {
     62 	struct puffs_flush pf;
     63 	ssize_t n;
     64 
     65 	pf.pf_frhdr.pfr_len = sizeof(struct puffs_flush);
     66 	pf.pf_frhdr.pfr_type = PUFFSOP_FLUSH;
     67 
     68 	pf.pf_op = op;
     69 	pf.pf_cookie = cookie;
     70 	pf.pf_start = start;
     71 	pf.pf_end = end;
     72 
     73 	n = write(pu->pu_fd, &pf, sizeof(struct puffs_flush));
     74 
     75 	/* XXX */
     76 	assert(n == sizeof(struct puffs_flush));
     77 	return 0;
     78 }
     79 
     80 int
     81 puffs_inval_namecache_dir(struct puffs_usermount *pu, void *cookie)
     82 {
     83 
     84 	return doflush(pu, cookie, PUFFS_INVAL_NAMECACHE_DIR, 0, 0);
     85 }
     86 
     87 int
     88 puffs_inval_namecache_all(struct puffs_usermount *pu)
     89 {
     90 
     91 	return doflush(pu, NULL, PUFFS_INVAL_NAMECACHE_ALL, 0, 0);
     92 }
     93 
     94 int
     95 puffs_inval_pagecache_node(struct puffs_usermount *pu, void *cookie)
     96 {
     97 
     98 	return doflush(pu, cookie, PUFFS_INVAL_PAGECACHE_NODE_RANGE, 0, 0);
     99 }
    100 
    101 int
    102 puffs_inval_pagecache_node_range(struct puffs_usermount *pu, void *cookie,
    103 	off_t start, off_t end)
    104 {
    105 
    106 	return doflush(pu, cookie, PUFFS_INVAL_PAGECACHE_NODE_RANGE, start,end);
    107 }
    108 
    109 int
    110 puffs_flush_pagecache_node(struct puffs_usermount *pu, void *cookie)
    111 {
    112 
    113 	return doflush(pu, cookie, PUFFS_FLUSH_PAGECACHE_NODE_RANGE, 0, 0);
    114 }
    115 
    116 int
    117 puffs_flush_pagecache_node_range(struct puffs_usermount *pu, void *cookie,
    118 	off_t start, off_t end)
    119 {
    120 
    121 	return doflush(pu, cookie, PUFFS_FLUSH_PAGECACHE_NODE_RANGE, start,end);
    122 }
    123