-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache.h
83 lines (63 loc) · 2.56 KB
/
cache.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* tarfs - A GNU tar filesystem for the Hurd.
Copyright (C) 2002, Ludovic Courtès <ludo@chbouib.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or * (at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA */
/*
* Nodes contents cache management.
*/
#ifndef __CACHE_H__
#define __CACHE_H__
#include <stdlib.h>
#include <error.h>
#include <hurd/netfs.h>
#include <hurd/store.h>
/* Size of a cache block. */
#define CACHE_BLOCK_SIZE_LOG2 10
#define CACHE_BLOCK_SIZE (1 << CACHE_BLOCK_SIZE_LOG2)
/* Cache data accessor */
#define CACHE_INFO(Node, Field) \
(NODE_INFO(Node)->cache. Field)
/* Nodes contents cache */
struct cache
{
/* Vector of cache blocks */
char **blocks;
/* Size of BLOCKS */
size_t size;
/* Lock of this cache */
struct mutex lock;
};
/* Initializes the cache backend. READ is the method that will be called
when data needs to be read from a node. */
extern void cache_init (error_t (* read) (struct node *node, off_t offset,
size_t howmuch,
size_t *actually_read, void *data));
/* Create a cache for node NODE. */
extern error_t cache_create (struct node *node);
/* Free NODE's cache. */
extern error_t cache_free (struct node *node);
/* Read at most AMOUNT bytes from NODE at OFFSET into BUF.
Returns the amount of data actually read in LEN. */
extern error_t cache_read (struct node *node, off_t offset,
size_t amount, void *buf, size_t *len);
/* Writes at most LEN bytes from NODE at OFFSET into BUF.
Returns the amount of data actually written in AMOUNT. */
extern error_t cache_write (struct node *node, off_t offset,
void *data, size_t len, size_t *amount);
/* Sets the size of NODE and reduce/grow its cache. */
extern error_t cache_set_size (struct node *node, size_t size);
/* Cache AMOUNT bytes of NODE. */
extern error_t cache_cache (struct node *node, size_t amount);
/* Returns non-zero if NODE is synchronized (ie. not cached). */
extern int cache_synced (struct node *node);
#endif /* cache.h */