Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
/*
2
 * Project: HARTIK (HA-rd R-eal TI-me K-ernel)
3
 *
4
 * Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
5
 *               Gerardo Lamastra <gerardo@sssup.it>
6
 *
7
 * Authors     : Massimiliano Giorgi <massy@hartik.sssup.it>
8
 * (see authors.txt for full list of hartik's authors)
9
 *
10
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
11
 *
12
 * http://www.sssup.it
13
 * http://retis.sssup.it
14
 * http://hartik.sssup.it
15
 */
16
 
17
/*
18
 * Copyright (C) 2000 Massimiliano Giorgi
19
 *
20
 * This program is free software; you can redistribute it and/or modify
21
 * it under the terms of the GNU General Public License as published by
22
 * the Free Software Foundation; either version 2 of the License, or
23
 * (at your option) any later version.
24
 *
25
 * This program is distributed in the hope that it will be useful,
26
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
 * GNU General Public License for more details.
29
 *
30
 * You should have received a copy of the GNU General Public License
31
 * along with this program; if not, write to the Free Software
32
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
33
 *
34
 */
35
 
36
/*
37
 * CVS :        $Id: dcache.h,v 1.1.1.1 2002-03-29 14:12:50 pj Exp $
38
 *
39
 * File:        $File$
40
 * Revision:    $Revision: 1.1.1.1 $
41
 * Last update: $Date: 2002-03-29 14:12:50 $
42
 */
43
 
44
/***
45
 This is the caching module: all the I/O requestes of filesystems MUST pass throught this to
46
 read/write on disks.
47
 ***/
48
 
49
#ifndef __DCACHE_H__
50
#define __DCACHE_H__
51
 
52
#include <fs/types.h>
53
#include <fs/magic.h>
54
#include <fs/bdev.h>
55
 
56
#include "semaph.h"
57
#include "rwlock.h"
58
 
59
#define MAXSECTORSIZE 512
60
 
61
typedef struct TAGdcache {
62
 
63
  DECLARE_MAGIC(magic);
64
 
65
  /*+ index of previous cache entry (if used) +*/
66
  int        prev;
67
  /*+ index of next cache entry +*/
68
  int        next;
69
  /*+ hash value +*/
70
  int        hash;
71
 
72
 
73
  /*+ device of this entry +*/
74
  __dev_t    device;
75
  /*+ logical sector of this entry +*/
76
  __blkcnt_t lsector;
77
  /*+ sector buffer +*/
78
  __uint8_t  buffer[MAXSECTORSIZE];
79
 
80
 
81
 
82
  /*+ how many threads are using this entry? +*/
83
  /* -1: unused and free 0: unused >0: used by 'used' thread */
84
  int        used;
85
  /*+ system tyme of last release +*/
86
  __time_t   time;
87
 
88
 
89
  /*+ number of threads waiting for 'ready' field +*/
90
  int        numblocked;
91
  /*+ all 'numblocked' threads wait on this semaphore +*/
92
  __fs_sem_t sync;
93
  /*+ for error syncronization [see __purge_dcache()] +*/
94
  __fs_sem_t esync;
95
 
96
 
97
  /*+ reading/writing mutex object [see rwlock.c module] +*/
98
  __rwlock_t rwlock;
99
 
100
 
101
  /* flags */
102
 
103
  /*+ the buffer has been modified +*/
104
  __uint32_t dirty:1;
105
  /*+ the buffer is ready +*/
106
  __uint32_t ready:1;
107
  /*+ request for error syncronization [see __purge_dcache()] +*/
108
  __uint32_t esyncreq:1;
109
  /*+ if set a write throught cache policy for this entry is not honoured +*/
110
  __uint32_t skipwt:1;
111
 
112
} dcache_t;
113
 
114
int dcache_init(void);
115
int dcache_end(int flag);
116
 
117
dcache_t *dcache_lock(__dev_t dev, __blkcnt_t lsector);
118
void dcache_unlock(dcache_t *);
119
dcache_t *dcache_acquire(__dev_t dev, __blkcnt_t lsector);
120
void dcache_release(dcache_t *);
121
 
122
void dcache_dirty(dcache_t *d);
123
 
124
static __inline__ void dcache_skipwt(dcache_t *d)
125
{
126
  d->skipwt=1;
127
}
128
 
129
int  dcache_flush(void);
130
int dcache_purgedevice(__dev_t device, int cont);
131
 
132
/* -- */
133
 
134
#define DCACHE_OK    BDEV_OK
135
#define DCACHE_FAIL  BDEV_FAIL
136
#define DCACHE_ERR   BDEV_ERROR
137
 
138
extern __inline__ int dcache_lockdevice(__dev_t device)
139
{
140
  return bdev_trylock(device);
141
}
142
 
143
extern __inline__ int dcache_unlockdevice(__dev_t device)
144
{
145
  return bdev_tryunlock(device);
146
}
147
 
148
 
149
#endif
150
 
151