1/*
2	Copyright 1999-2001, Be Incorporated.   All Rights Reserved.
3	This file may be used under the terms of the Be Sample Code License.
4*/
5
6#ifndef USERLAND_FS_BEOS_FS_CACHE_PRIV_H
7#define USERLAND_FS_BEOS_FS_CACHE_PRIV_H
8
9#include "lock.h"
10
11#ifndef _IMPEXP_KERNEL
12#define _IMPEXP_KERNEL
13#endif
14
15typedef struct hash_ent {
16	int              dev;
17	off_t            bnum;
18	off_t            hash_val;
19	void            *data;
20	struct hash_ent *next;
21} hash_ent;
22
23
24typedef struct hash_table {
25    hash_ent **table;
26    int        max;
27    int        mask;          /* == max - 1 */
28    int        num_elements;
29} hash_table;
30
31
32#define HT_DEFAULT_MAX   128
33
34
35typedef struct cache_ent {
36	int               dev;
37	off_t             block_num;
38	int               bsize;
39	volatile int      flags;
40
41	void             *data;
42	void             *clone;         /* copy of data by set_block_info() */
43	int               lock;
44
45	void            (*func)(off_t bnum, size_t num_blocks, void *arg);
46	off_t             logged_bnum;
47	void             *arg;
48
49	struct cache_ent *next,          /* points toward mru end of list */
50	                 *prev;          /* points toward lru end of list */
51
52} cache_ent;
53
54#define CE_NORMAL    0x0000     /* a nice clean pristine page */
55#define CE_DIRTY     0x0002     /* needs to be written to disk */
56#define CE_BUSY      0x0004     /* this block has i/o happening, don't touch it */
57
58
59typedef struct cache_ent_list {
60	cache_ent *lru;              /* tail of the list */
61	cache_ent *mru;              /* head of the list */
62} cache_ent_list;
63
64
65typedef struct block_cache {
66	struct beos_lock lock;
67	int			 	flags;
68    int				cur_blocks;
69	int				max_blocks;
70	hash_table		ht;
71
72	cache_ent_list	normal,       /* list of "normal" blocks (clean & dirty) */
73					locked;       /* list of clean and locked blocks */
74} block_cache;
75
76#if 0   /* XXXdbg -- need to deal with write through caches */
77#define DC_WRITE_THROUGH    0x0001  /* cache is write-through (for floppies) */
78#endif
79
80#define ALLOW_WRITES  1
81#define NO_WRITES     0
82
83#endif /* USERLAND_FS_BEOS_FS_CACHE_PRIV_H */
84