Subversion Repositories shark

Rev

Rev 2 | Rev 33 | Go to most recent revision | Details | Compare with Previous | 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: fs.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 file contains the registration functions for filesystems mudules and the blocking functions
46
 used internally for filesystem primitive calls.
47
 ***/
48
 
49
#ifndef __FS_H__
50
#define __FS_H__
51
 
52
#include <fs/types.h>
53
#include <fs/mount.h>
54
 
55
#include "mutex.h"
56
#include "semaph.h"
57
 
58
struct super_block;
59
 
60
/*+
61
 This structure is used to inform the file system manager that a new
62
 filesystem is ready to bind data on some device:
63
 
64
 name
65
   It's the name of the filesystem; can be any string.
66
 fs_flags
67
   I don't remember what it is
68
 fs_ind
69
   It's a unique identifier for the filesystem; it is taken from the
70
   PC IBM hard disk architecture
71
 read_super
72
   It's the main entry point to the fileystem: the mount function call
73
   this routine to perform the initial binding between a disk device and
74
   a filesystem; the struct super_block it is the only thing that
75
   the filesystem manager required to perform a disk operation.
76
 
77
 +*/
78
struct file_system_type {
79
  /*+ filesystem name +*/
80
  const char *name;
81
  /*+ filesystem flags +*/
82
  int        fs_flags;
83
  /*+ filesystem indicator +*/
84
  __uint8_t  fs_ind;
85
 
86
  /*+ filesystem read_super function +*/
87
  struct super_block *(*read_super)(__dev_t device, __uint8_t fs_ind,
88
                                    struct mount_opts *options);
89
};
90
 
91
 
92
int filesystem_register(struct file_system_type *ptr);
93
struct file_system_type *filesystem_find_byid(__uint8_t fs_ind);
94
 
95
int mount_device(__dev_t device, __uint8_t fs_ind, char *pathname,
96
                 struct mount_opts *opts);
97
 
98
int umount_device(__dev_t device);
99
 
100
/*
101
 *
102
 *
103
 *
104
 */
105
 
106
/* define this if you want to debug the synchronization functions */
107
#define FS_DEBUGSYNC KERN_DEBUG
108
#undef FS_DEBUGSYNC
109
 
110
#ifdef FS_DEBUGSYNC
111
#define _printk0(fmt,args...) cprintf(fmt,##args)
112
#else
113
#define _printk0(fmt,args...)
114
#endif
115
 
116
/*+ state of the fs: 0 can accept syscalls - 1 abort all syscalls +*/
117
extern int              fssysstate;
118
/*+ number of syscalls in progress +*/
119
extern long             fssyscounter;
120
/*+ mutex to update the above two variables +*/
121
extern __fs_fastmutex_t fssysmutex;
122
/*+ syncronization semaphore to change fssysstate +*/
123
extern __fs_sem_t       fssyssync;
124
/*+ number of task waiting for fs +*/
125
extern long             fssysinitcounter;
126
/*+ syncronization semaphore to change fssysstate from -1 to 0 +*/
127
extern __fs_sem_t       fssysinit;
128
 
129
/*+ prolog for all syscalls +*/
130
static __inline__ int __call_to_fs(void)
131
{
132
  __fs_fastmutex_lock(&fssysmutex);
133
  if (fssysstate!=0) {
134
    __fs_fastmutex_unlock(&fssysmutex);
135
    return -1;
136
  }
137
  fssyscounter++;
138
  __fs_fastmutex_unlock(&fssysmutex);
139
  return 0;
140
}
141
 
142
#define call_to_fs() { if (__call_to_fs()) return -ENOENT; }
143
 
144
/*+ release temporally a syscall (very dangerous) +*/
145
static __inline__ void release_sys_call(void)
146
{
147
  __fs_fastmutex_lock(&fssysmutex);
148
  fssyscounter--;
149
  __fs_fastmutex_unlock(&fssysmutex);
150
}
151
 
152
/*+ reaquire a syscall (MUST be tested the return value for abort) +*/
153
static __inline__ int reacquire_sys_call(void)
154
{
155
  int ret=0;
156
  __fs_fastmutex_lock(&fssysmutex);
157
  if (fssysstate==1) ret=-1;
158
  else fssyscounter++;
159
  __fs_fastmutex_unlock(&fssysmutex);
160
  return ret;
161
}
162
 
163
/*+ epilog for all syscalls +*/
164
static __inline__ int __return_from_fs(int code)
165
{
166
  __fs_fastmutex_lock(&fssysmutex);
167
  fssyscounter--;
168
  if (fssysstate==1) {
169
    if (fssyscounter==0) {
170
      __fs_fastmutex_unlock(&fssysmutex);
171
      __fs_sem_signal(&fssyssync);
172
      return (code);
173
    }
174
  }
175
  __fs_fastmutex_unlock(&fssysmutex);
176
  return (code);
177
}
178
 
179
#define return_from_fs(code) return __return_from_fs(code)
180
 
181
#define fs_test_cancellation(code) \
182
{  \
183
  if (proc_table[exec_shadow].control & KILL_ENABLED && \
184
      proc_table[exec_shadow].control & KILL_REQUEST ) { \
185
    __return_from_fs(0); \
186
    task_testcancel(); \
187
    return (code); \
188
  } \
189
}
190
 
191
/*+ called only one time when the system is ready +*/
192
static __inline__ void permit_all_fs_calls(void)
193
{
194
  _printk0("<pfscall>");
195
  __fs_fastmutex_lock(&fssysmutex);
196
  fssysstate=0;
197
  if (fssysinitcounter>0) {
198
    __fs_fastmutex_unlock(&fssysmutex);
199
    _printk0("<pfscall:%li>",fssysinitcounter);
200
    while (fssysinitcounter-->0)
201
      __fs_sem_signal(&fssysinit);
202
    return;
203
  }
204
  __fs_fastmutex_unlock(&fssysmutex);
205
}
206
 
207
#define SHUTDOWNTIMEOUT 6000000
208
#define SHUTDOWNSLICE    250000
209
#define SHUTDOWNCOUNTER (SHUTDOWNTIMEOUT/SHUTDOWNSLICE)
210
 
211
/*+ called only one during shutdown to disable syscalls +*/
212
static __inline__ void block_all_fs_calls(void)    
213
{
214
  _printk0("<bfscall>");
215
  __fs_fastmutex_lock(&fssysmutex);
216
  fssysstate=1;
217
  if (fssyscounter>0) {
218
    _printk0("<bfscallfor%li>",fssyscounter);
219
    __fs_fastmutex_unlock(&fssysmutex);
220
    _printk0("<bfscallwait>");
221
 
222
#ifdef SHUTDOWNTIMEOUT
223
    {
224
      int counter;
225
      counter=0;
226
      while (counter<SHUTDOWNCOUNTER&&__fs_sem_trywait(&fssyssync)) {
227
        counter++;
228
        task_delay(SHUTDOWNSLICE);
229
      }
230
      if (counter>=SHUTDOWNCOUNTER) {
231
        printk(KERN_NOTICE "filesystem shutdown timeout... aborting!");
232
        sys_abort(371);
233
      }
234
    }
235
#else
236
    __fs_sem_wait(&fssyssync);
237
#endif
238
 
239
    _printk0("<bfscallresum>");
240
  } else {
241
    __fs_fastmutex_unlock(&fssysmutex);
242
  }
243
}
244
 
245
 
246
#endif