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) 1999 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: super.ori,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
#include <fs/sysmacro.h>
45
#include <fs/util.h>
46
#include <fs/major.h>
47
#include <fs/fsinit.h>
48
#include <fs/bdev.h>
49
#include <fs/fsind.h>
50
#include <fs/mount.h>
51
#include <fs/assert.h>
52
 
53
#include "mutex.h"
54
#include "fs.h"
55
#include "super.h"
56
 
57
#define MAXSUPERBLOCKS 8
58
static __fs_mutex_t mutex;
59
static __fs_mutex_t mutexsb;
60
static struct super_block sbs[MAXSUPERBLOCKS];
61
 
62
static struct super_block *root_superblock=NULL;
63
 
64
int super_init(void)
65
{
66
  int i;
67
 
68
  __fs_mutex_init(&mutex);
69
  __fs_mutex_init(&mutexsb);
70
 
71
  for (i=0;i<MAXSUPERBLOCKS;i++) {
72
    memset(sbs+i,0,sizeof(struct super_block));
73
    mount_std_parms(sbs[i].sb_mopts);
74
    sbs[i].sb_busycount=0;
75
    sbs[i].sb_used=0;
76
    sbs[i].sb_blocked=0;
77
  }
78
 
79
  return 0;
80
}
81
 
82
struct super_block *super_getblock(void)
83
{
84
  struct super_block *ptr=NULL;
85
  int i;
86
 
87
  __fs_mutex_lock(&mutexsb);
88
  for (i=0;i<MAXSUPERBLOCKS;i++)
89
    if (!sbs[i].sb_used) {
90
      sbs[i].sb_used=1;
91
      sbs[i].sb_blocked=1;
92
      sbs[i].sb_busycount=0;
93
      ptr=sbs+i;
94
      break;
95
    }
96
  __fs_mutex_unlock(&mutexsb);
97
 
98
  return ptr;
99
}
100
 
101
void super_freeblock(struct super_block *ptr)
102
{
103
  __fs_mutex_lock(&mutexsb);
104
  assert(ptr->sb_used==1);
105
  assert(ptr->sb_blocked==1);
106
  assert(ptr->sb_busycount==0);
107
  ptr->sb_used=0;
108
  __fs_mutex_unlock(&mutexsb);
109
}
110
 
111
void super_enumdevice(int(*func)(__dev_t))
112
{
113
  int i;
114
  //__fs_mutex_lock(&mutexsb);
115
  for (i=0;i<MAXSUPERBLOCKS;i++)
116
    if (!sbs[i].sb_used) {
117
      sbs[i].sb_used=1;
118
      (*func)(sbs[i].sb_dev);
119
    }
120
  //__fs_mutex_unlock(&mutexsb);
121
}
122
 
123
/* --- */
124
 
125
struct super_block *get_root_superblock(void)
126
{
127
  assert(root_superblock!=NULL);
128
  return root_superblock;
129
}
130
 
131
void set_root_superblock(struct super_block *sb)
132
{
133
  assert(root_superblock==NULL);
134
  root_superblock=sb;
135
}
136
 
137
/* --- */
138
 
139
int super_incbusy(struct super_block *sb)
140
{
141
  int ret=-1;
142
 
143
  assert(sb>=sbs&&sb<sbs+MAXSUPERBLOCKS);
144
 
145
  __fs_mutex_lock(&mutex);
146
 
147
  if (sb->sb_blocked==0) {
148
    ret=0;
149
    sb->sb_busycount++;
150
  }
151
 
152
  __fs_mutex_unlock(&mutex);
153
 
154
  return ret;
155
}
156
 
157
void super_decbusy(struct super_block *sb)
158
{
159
  assert(sb>=sbs&&sb<sbs+MAXSUPERBLOCKS);
160
 
161
  __fs_mutex_lock(&mutex);
162
 
163
  assert(sb->sb_busycount>0);
164
  assert(sb->sb_blocked==0);
165
 
166
  sb->sb_busycount--;
167
 
168
  __fs_mutex_unlock(&mutex);
169
}
170
 
171
struct super_block *super_aquire(__dev_t dev)
172
{
173
  struct super_block *ptr=NULL;
174
  int i;
175
 
176
  __fs_mutex_lock(&mutex);
177
 
178
  for (i=0;i<MAXSUPERBLOCKS;i++) {
179
    if (sbs[i].sb_used==1&&sbs[i].sb_dev==dev) {
180
      if (sbs[i].sb_blocked==1||sbs[i].sb_busycount!=0) break;
181
      sbs[i].sb_blocked=1;
182
      ptr=sbs+i;
183
      break;
184
    }
185
  }
186
  __fs_mutex_unlock(&mutex);
187
  return ptr;
188
}
189
 
190
void super_release(struct super_block *sb)
191
{
192
  assert(sb>=sbs&&sb<sbs+MAXSUPERBLOCKS);
193
  __fs_mutex_lock(&mutex);
194
  assert(sb->sb_used==1&&sb->sb_blocked==1);
195
  sb->sb_blocked=0;
196
  __fs_mutex_unlock(&mutex);
197
}