1 |
1628 |
jcastillo |
/*
|
2 |
|
|
* linux/fs/sysv/inode.c
|
3 |
|
|
*
|
4 |
|
|
* minix/inode.c
|
5 |
|
|
* Copyright (C) 1991, 1992 Linus Torvalds
|
6 |
|
|
*
|
7 |
|
|
* xenix/inode.c
|
8 |
|
|
* Copyright (C) 1992 Doug Evans
|
9 |
|
|
*
|
10 |
|
|
* coh/inode.c
|
11 |
|
|
* Copyright (C) 1993 Pascal Haible, Bruno Haible
|
12 |
|
|
*
|
13 |
|
|
* sysv/inode.c
|
14 |
|
|
* Copyright (C) 1993 Paul B. Monday
|
15 |
|
|
*
|
16 |
|
|
* sysv/inode.c
|
17 |
|
|
* Copyright (C) 1993 Bruno Haible
|
18 |
|
|
*
|
19 |
|
|
* This file contains code for allocating/freeing inodes and for read/writing
|
20 |
|
|
* the superblock.
|
21 |
|
|
*/
|
22 |
|
|
|
23 |
|
|
#include <linux/module.h>
|
24 |
|
|
|
25 |
|
|
#include <linux/sched.h>
|
26 |
|
|
#include <linux/kernel.h>
|
27 |
|
|
#include <linux/fs.h>
|
28 |
|
|
#include <linux/sysv_fs.h>
|
29 |
|
|
#include <linux/stat.h>
|
30 |
|
|
#include <linux/string.h>
|
31 |
|
|
#include <linux/locks.h>
|
32 |
|
|
|
33 |
|
|
#include <asm/segment.h>
|
34 |
|
|
|
35 |
|
|
void sysv_put_inode(struct inode *inode)
|
36 |
|
|
{
|
37 |
|
|
if (inode->i_nlink)
|
38 |
|
|
return;
|
39 |
|
|
inode->i_size = 0;
|
40 |
|
|
sysv_truncate(inode);
|
41 |
|
|
sysv_free_inode(inode);
|
42 |
|
|
}
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
static struct super_operations sysv_sops = {
|
46 |
|
|
sysv_read_inode,
|
47 |
|
|
sysv_notify_change,
|
48 |
|
|
sysv_write_inode,
|
49 |
|
|
sysv_put_inode,
|
50 |
|
|
sysv_put_super,
|
51 |
|
|
sysv_write_super,
|
52 |
|
|
sysv_statfs,
|
53 |
|
|
NULL
|
54 |
|
|
};
|
55 |
|
|
|
56 |
|
|
/* The following functions try to recognize specific filesystems.
|
57 |
|
|
* We recognize:
|
58 |
|
|
* - Xenix FS by its magic number.
|
59 |
|
|
* - SystemV FS by its magic number.
|
60 |
|
|
* - Coherent FS by its funny fname/fpack field.
|
61 |
|
|
* We discriminate among SystemV4 and SystemV2 FS by the assumption that
|
62 |
|
|
* the time stamp is not < 01-01-1980.
|
63 |
|
|
*/
|
64 |
|
|
|
65 |
|
|
static void detected_bs512 (struct super_block *sb)
|
66 |
|
|
{
|
67 |
|
|
sb->sv_block_size = 512;
|
68 |
|
|
sb->sv_block_size_1 = 512-1;
|
69 |
|
|
sb->sv_block_size_bits = 9;
|
70 |
|
|
sb->sv_block_size_ratio = 2;
|
71 |
|
|
sb->sv_block_size_ratio_bits = 1;
|
72 |
|
|
sb->sv_inodes_per_block = 512/64;
|
73 |
|
|
sb->sv_inodes_per_block_1 = 512/64-1;
|
74 |
|
|
sb->sv_inodes_per_block_bits = 9-6;
|
75 |
|
|
sb->sv_toobig_block = 10 +
|
76 |
|
|
(sb->sv_ind_per_block = 512/4) +
|
77 |
|
|
(sb->sv_ind_per_block_2 = (512/4)*(512/4)) +
|
78 |
|
|
(sb->sv_ind_per_block_3 = (512/4)*(512/4)*(512/4));
|
79 |
|
|
sb->sv_ind_per_block_1 = 512/4-1;
|
80 |
|
|
sb->sv_ind_per_block_2_1 = (512/4)*(512/4)-1;
|
81 |
|
|
sb->sv_ind_per_block_2_bits = 2 *
|
82 |
|
|
(sb->sv_ind_per_block_bits = 9-2);
|
83 |
|
|
sb->sv_ind_per_block_block_size_1 = (512/4)*512-1;
|
84 |
|
|
sb->sv_ind_per_block_block_size_bits = (9-2)+9;
|
85 |
|
|
sb->sv_ind_per_block_2_block_size_1 = (512/4)*(512/4)*512-1;
|
86 |
|
|
sb->sv_ind_per_block_2_block_size_bits = (9-2)+(9-2)+9;
|
87 |
|
|
sb->sv_ind0_size = 10 * 512;
|
88 |
|
|
sb->sv_ind1_size = (10 + (512/4))* 512;
|
89 |
|
|
sb->sv_ind2_size = (10 + (512/4) + (512/4)*(512/4)) * 512;
|
90 |
|
|
}
|
91 |
|
|
|
92 |
|
|
static void detected_bs1024 (struct super_block *sb)
|
93 |
|
|
{
|
94 |
|
|
sb->sv_block_size = 1024;
|
95 |
|
|
sb->sv_block_size_1 = 1024-1;
|
96 |
|
|
sb->sv_block_size_bits = 10;
|
97 |
|
|
sb->sv_block_size_ratio = 1;
|
98 |
|
|
sb->sv_block_size_ratio_bits = 0;
|
99 |
|
|
sb->sv_inodes_per_block = 1024/64;
|
100 |
|
|
sb->sv_inodes_per_block_1 = 1024/64-1;
|
101 |
|
|
sb->sv_inodes_per_block_bits = 10-6;
|
102 |
|
|
sb->sv_toobig_block = 10 +
|
103 |
|
|
(sb->sv_ind_per_block = 1024/4) +
|
104 |
|
|
(sb->sv_ind_per_block_2 = (1024/4)*(1024/4)) +
|
105 |
|
|
(sb->sv_ind_per_block_3 = (1024/4)*(1024/4)*(1024/4));
|
106 |
|
|
sb->sv_ind_per_block_1 = 1024/4-1;
|
107 |
|
|
sb->sv_ind_per_block_2_1 = (1024/4)*(1024/4)-1;
|
108 |
|
|
sb->sv_ind_per_block_2_bits = 2 *
|
109 |
|
|
(sb->sv_ind_per_block_bits = 10-2);
|
110 |
|
|
sb->sv_ind_per_block_block_size_1 = (1024/4)*1024-1;
|
111 |
|
|
sb->sv_ind_per_block_block_size_bits = (10-2)+10;
|
112 |
|
|
sb->sv_ind_per_block_2_block_size_1 = (1024/4)*(1024/4)*1024-1;
|
113 |
|
|
sb->sv_ind_per_block_2_block_size_bits = (10-2)+(10-2)+10;
|
114 |
|
|
sb->sv_ind0_size = 10 * 1024;
|
115 |
|
|
sb->sv_ind1_size = (10 + (1024/4))* 1024;
|
116 |
|
|
sb->sv_ind2_size = (10 + (1024/4) + (1024/4)*(1024/4)) * 1024;
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
static const char* detect_xenix (struct super_block *sb, struct buffer_head *bh)
|
120 |
|
|
{
|
121 |
|
|
struct xenix_super_block * sbd;
|
122 |
|
|
|
123 |
|
|
sbd = (struct xenix_super_block *) bh->b_data;
|
124 |
|
|
if (sbd->s_magic != 0x2b5544)
|
125 |
|
|
return NULL;
|
126 |
|
|
switch (sbd->s_type) {
|
127 |
|
|
case 1: detected_bs512(sb); break;
|
128 |
|
|
case 2: detected_bs1024(sb); break;
|
129 |
|
|
default: return NULL;
|
130 |
|
|
}
|
131 |
|
|
sb->sv_type = FSTYPE_XENIX;
|
132 |
|
|
return "Xenix";
|
133 |
|
|
}
|
134 |
|
|
static struct super_block * detected_xenix (struct super_block *sb, struct buffer_head *bh1, struct buffer_head *bh2)
|
135 |
|
|
{
|
136 |
|
|
struct xenix_super_block * sbd1;
|
137 |
|
|
struct xenix_super_block * sbd2;
|
138 |
|
|
|
139 |
|
|
if (sb->sv_block_size == BLOCK_SIZE)
|
140 |
|
|
/* block size = 1024, so bh1 = bh2 */
|
141 |
|
|
sbd1 = sbd2 = (struct xenix_super_block *) bh1->b_data;
|
142 |
|
|
else {
|
143 |
|
|
/* block size = 512, so bh1 != bh2 */
|
144 |
|
|
sbd1 = (struct xenix_super_block *) bh1->b_data;
|
145 |
|
|
sbd2 = (struct xenix_super_block *) (bh2->b_data - BLOCK_SIZE/2);
|
146 |
|
|
/* sanity check */
|
147 |
|
|
if (sbd2->s_magic != 0x2b5544)
|
148 |
|
|
return NULL;
|
149 |
|
|
}
|
150 |
|
|
|
151 |
|
|
sb->sv_convert = 0;
|
152 |
|
|
sb->sv_kludge_symlinks = 1;
|
153 |
|
|
sb->sv_truncate = 1;
|
154 |
|
|
sb->sv_link_max = XENIX_LINK_MAX;
|
155 |
|
|
sb->sv_fic_size = XENIX_NICINOD;
|
156 |
|
|
sb->sv_flc_size = XENIX_NICFREE;
|
157 |
|
|
sb->sv_bh1 = bh1;
|
158 |
|
|
sb->sv_bh2 = bh2;
|
159 |
|
|
sb->sv_sbd1 = (char *) sbd1;
|
160 |
|
|
sb->sv_sbd2 = (char *) sbd2;
|
161 |
|
|
sb->sv_sb_fic_count = &sbd1->s_ninode;
|
162 |
|
|
sb->sv_sb_fic_inodes = &sbd1->s_inode[0];
|
163 |
|
|
sb->sv_sb_total_free_inodes = &sbd2->s_tinode;
|
164 |
|
|
sb->sv_sb_flc_count = &sbd1->s_nfree;
|
165 |
|
|
sb->sv_sb_flc_blocks = &sbd1->s_free[0];
|
166 |
|
|
sb->sv_sb_total_free_blocks = &sbd2->s_tfree;
|
167 |
|
|
sb->sv_sb_time = &sbd2->s_time;
|
168 |
|
|
sb->sv_firstinodezone = 2;
|
169 |
|
|
sb->sv_firstdatazone = sbd1->s_isize;
|
170 |
|
|
sb->sv_nzones = sbd1->s_fsize;
|
171 |
|
|
sb->sv_ndatazones = sb->sv_nzones - sb->sv_firstdatazone;
|
172 |
|
|
return sb;
|
173 |
|
|
}
|
174 |
|
|
|
175 |
|
|
static const char* detect_sysv4 (struct super_block *sb, struct buffer_head *bh)
|
176 |
|
|
{
|
177 |
|
|
struct sysv4_super_block * sbd;
|
178 |
|
|
|
179 |
|
|
sbd = (struct sysv4_super_block *) (bh->b_data + BLOCK_SIZE/2);
|
180 |
|
|
if (sbd->s_magic != 0xfd187e20)
|
181 |
|
|
return NULL;
|
182 |
|
|
if (sbd->s_time < 315532800) /* this is likely to happen on SystemV2 FS */
|
183 |
|
|
return NULL;
|
184 |
|
|
switch (sbd->s_type) {
|
185 |
|
|
case 1: detected_bs512(sb); break;
|
186 |
|
|
case 2: detected_bs1024(sb); break;
|
187 |
|
|
default: return NULL;
|
188 |
|
|
}
|
189 |
|
|
sb->sv_type = FSTYPE_SYSV4;
|
190 |
|
|
return "SystemV";
|
191 |
|
|
}
|
192 |
|
|
static struct super_block * detected_sysv4 (struct super_block *sb, struct buffer_head *bh)
|
193 |
|
|
{
|
194 |
|
|
struct sysv4_super_block * sbd;
|
195 |
|
|
|
196 |
|
|
if (sb->sv_block_size == BLOCK_SIZE)
|
197 |
|
|
sbd = (struct sysv4_super_block *) (bh->b_data + BLOCK_SIZE/2);
|
198 |
|
|
else {
|
199 |
|
|
sbd = (struct sysv4_super_block *) bh->b_data;
|
200 |
|
|
/* sanity check */
|
201 |
|
|
if (sbd->s_magic != 0xfd187e20)
|
202 |
|
|
return NULL;
|
203 |
|
|
if (sbd->s_time < 315532800)
|
204 |
|
|
return NULL;
|
205 |
|
|
}
|
206 |
|
|
|
207 |
|
|
sb->sv_convert = 0;
|
208 |
|
|
sb->sv_kludge_symlinks = 0; /* ?? */
|
209 |
|
|
sb->sv_truncate = 1;
|
210 |
|
|
sb->sv_link_max = SYSV_LINK_MAX;
|
211 |
|
|
sb->sv_fic_size = SYSV_NICINOD;
|
212 |
|
|
sb->sv_flc_size = SYSV_NICFREE;
|
213 |
|
|
sb->sv_bh1 = bh;
|
214 |
|
|
sb->sv_bh2 = bh;
|
215 |
|
|
sb->sv_sbd1 = (char *) sbd;
|
216 |
|
|
sb->sv_sbd2 = (char *) sbd;
|
217 |
|
|
sb->sv_sb_fic_count = &sbd->s_ninode;
|
218 |
|
|
sb->sv_sb_fic_inodes = &sbd->s_inode[0];
|
219 |
|
|
sb->sv_sb_total_free_inodes = &sbd->s_tinode;
|
220 |
|
|
sb->sv_sb_flc_count = &sbd->s_nfree;
|
221 |
|
|
sb->sv_sb_flc_blocks = &sbd->s_free[0];
|
222 |
|
|
sb->sv_sb_total_free_blocks = &sbd->s_tfree;
|
223 |
|
|
sb->sv_sb_time = &sbd->s_time;
|
224 |
|
|
sb->sv_sb_state = &sbd->s_state;
|
225 |
|
|
sb->sv_firstinodezone = 2;
|
226 |
|
|
sb->sv_firstdatazone = sbd->s_isize;
|
227 |
|
|
sb->sv_nzones = sbd->s_fsize;
|
228 |
|
|
sb->sv_ndatazones = sb->sv_nzones - sb->sv_firstdatazone;
|
229 |
|
|
return sb;
|
230 |
|
|
}
|
231 |
|
|
|
232 |
|
|
static const char* detect_sysv2 (struct super_block *sb, struct buffer_head *bh)
|
233 |
|
|
{
|
234 |
|
|
struct sysv2_super_block * sbd;
|
235 |
|
|
|
236 |
|
|
sbd = (struct sysv2_super_block *) (bh->b_data + BLOCK_SIZE/2);
|
237 |
|
|
if (sbd->s_magic != 0xfd187e20)
|
238 |
|
|
return NULL;
|
239 |
|
|
if (sbd->s_time < 315532800) /* this is likely to happen on SystemV4 FS */
|
240 |
|
|
return NULL;
|
241 |
|
|
switch (sbd->s_type) {
|
242 |
|
|
case 1: detected_bs512(sb); break;
|
243 |
|
|
case 2: detected_bs1024(sb); break;
|
244 |
|
|
default: return NULL;
|
245 |
|
|
}
|
246 |
|
|
sb->sv_type = FSTYPE_SYSV2;
|
247 |
|
|
return "SystemV Release 2";
|
248 |
|
|
}
|
249 |
|
|
static struct super_block * detected_sysv2 (struct super_block *sb, struct buffer_head *bh)
|
250 |
|
|
{
|
251 |
|
|
struct sysv2_super_block * sbd;
|
252 |
|
|
|
253 |
|
|
if (sb->sv_block_size == BLOCK_SIZE)
|
254 |
|
|
sbd = (struct sysv2_super_block *) (bh->b_data + BLOCK_SIZE/2);
|
255 |
|
|
else {
|
256 |
|
|
sbd = (struct sysv2_super_block *) bh->b_data;
|
257 |
|
|
/* sanity check */
|
258 |
|
|
if (sbd->s_magic != 0xfd187e20)
|
259 |
|
|
return NULL;
|
260 |
|
|
if (sbd->s_time < 315532800)
|
261 |
|
|
return NULL;
|
262 |
|
|
}
|
263 |
|
|
|
264 |
|
|
sb->sv_convert = 0;
|
265 |
|
|
sb->sv_kludge_symlinks = 0; /* ?? */
|
266 |
|
|
sb->sv_truncate = 1;
|
267 |
|
|
sb->sv_link_max = SYSV_LINK_MAX;
|
268 |
|
|
sb->sv_fic_size = SYSV_NICINOD;
|
269 |
|
|
sb->sv_flc_size = SYSV_NICFREE;
|
270 |
|
|
sb->sv_bh1 = bh;
|
271 |
|
|
sb->sv_bh2 = bh;
|
272 |
|
|
sb->sv_sbd1 = (char *) sbd;
|
273 |
|
|
sb->sv_sbd2 = (char *) sbd;
|
274 |
|
|
sb->sv_sb_fic_count = &sbd->s_ninode;
|
275 |
|
|
sb->sv_sb_fic_inodes = &sbd->s_inode[0];
|
276 |
|
|
sb->sv_sb_total_free_inodes = &sbd->s_tinode;
|
277 |
|
|
sb->sv_sb_flc_count = &sbd->s_nfree;
|
278 |
|
|
sb->sv_sb_flc_blocks = &sbd->s_free[0];
|
279 |
|
|
sb->sv_sb_total_free_blocks = &sbd->s_tfree;
|
280 |
|
|
sb->sv_sb_time = &sbd->s_time;
|
281 |
|
|
sb->sv_sb_state = &sbd->s_state;
|
282 |
|
|
sb->sv_firstinodezone = 2;
|
283 |
|
|
sb->sv_firstdatazone = sbd->s_isize;
|
284 |
|
|
sb->sv_nzones = sbd->s_fsize;
|
285 |
|
|
sb->sv_ndatazones = sb->sv_nzones - sb->sv_firstdatazone;
|
286 |
|
|
return sb;
|
287 |
|
|
}
|
288 |
|
|
|
289 |
|
|
static const char* detect_coherent (struct super_block *sb, struct buffer_head *bh)
|
290 |
|
|
{
|
291 |
|
|
struct coh_super_block * sbd;
|
292 |
|
|
|
293 |
|
|
sbd = (struct coh_super_block *) (bh->b_data + BLOCK_SIZE/2);
|
294 |
|
|
if ((memcmp(sbd->s_fname,"noname",6) && memcmp(sbd->s_fname,"xxxxx ",6))
|
295 |
|
|
|| (memcmp(sbd->s_fpack,"nopack",6) && memcmp(sbd->s_fpack,"xxxxx\n",6)))
|
296 |
|
|
return NULL;
|
297 |
|
|
detected_bs512(sb);
|
298 |
|
|
sb->sv_type = FSTYPE_COH;
|
299 |
|
|
return "Coherent";
|
300 |
|
|
}
|
301 |
|
|
static struct super_block * detected_coherent (struct super_block *sb, struct buffer_head *bh)
|
302 |
|
|
{
|
303 |
|
|
struct coh_super_block * sbd;
|
304 |
|
|
|
305 |
|
|
sbd = (struct coh_super_block *) bh->b_data;
|
306 |
|
|
/* sanity check */
|
307 |
|
|
if ((memcmp(sbd->s_fname,"noname",6) && memcmp(sbd->s_fname,"xxxxx ",6))
|
308 |
|
|
|| (memcmp(sbd->s_fpack,"nopack",6) && memcmp(sbd->s_fpack,"xxxxx\n",6)))
|
309 |
|
|
return NULL;
|
310 |
|
|
|
311 |
|
|
sb->sv_convert = 1;
|
312 |
|
|
sb->sv_kludge_symlinks = 1;
|
313 |
|
|
sb->sv_truncate = 1;
|
314 |
|
|
sb->sv_link_max = COH_LINK_MAX;
|
315 |
|
|
sb->sv_fic_size = COH_NICINOD;
|
316 |
|
|
sb->sv_flc_size = COH_NICFREE;
|
317 |
|
|
sb->sv_bh1 = bh;
|
318 |
|
|
sb->sv_bh2 = bh;
|
319 |
|
|
sb->sv_sbd1 = (char *) sbd;
|
320 |
|
|
sb->sv_sbd2 = (char *) sbd;
|
321 |
|
|
sb->sv_sb_fic_count = &sbd->s_ninode;
|
322 |
|
|
sb->sv_sb_fic_inodes = &sbd->s_inode[0];
|
323 |
|
|
sb->sv_sb_total_free_inodes = &sbd->s_tinode;
|
324 |
|
|
sb->sv_sb_flc_count = &sbd->s_nfree;
|
325 |
|
|
sb->sv_sb_flc_blocks = &sbd->s_free[0];
|
326 |
|
|
sb->sv_sb_total_free_blocks = &sbd->s_tfree;
|
327 |
|
|
sb->sv_sb_time = &sbd->s_time;
|
328 |
|
|
sb->sv_firstinodezone = 2;
|
329 |
|
|
sb->sv_firstdatazone = sbd->s_isize;
|
330 |
|
|
sb->sv_nzones = from_coh_ulong(sbd->s_fsize);
|
331 |
|
|
sb->sv_ndatazones = sb->sv_nzones - sb->sv_firstdatazone;
|
332 |
|
|
return sb;
|
333 |
|
|
}
|
334 |
|
|
|
335 |
|
|
struct super_block *sysv_read_super(struct super_block *sb,void *data,
|
336 |
|
|
int silent)
|
337 |
|
|
{
|
338 |
|
|
struct buffer_head *bh;
|
339 |
|
|
const char *found;
|
340 |
|
|
kdev_t dev = sb->s_dev;
|
341 |
|
|
|
342 |
|
|
if (1024 != sizeof (struct xenix_super_block))
|
343 |
|
|
panic("Xenix FS: bad super-block size");
|
344 |
|
|
if ((512 != sizeof (struct sysv4_super_block))
|
345 |
|
|
|| (512 != sizeof (struct sysv2_super_block)))
|
346 |
|
|
panic("SystemV FS: bad super-block size");
|
347 |
|
|
if (500 != sizeof (struct coh_super_block))
|
348 |
|
|
panic("Coherent FS: bad super-block size");
|
349 |
|
|
if (64 != sizeof (struct sysv_inode))
|
350 |
|
|
panic("sysv fs: bad i-node size");
|
351 |
|
|
MOD_INC_USE_COUNT;
|
352 |
|
|
lock_super(sb);
|
353 |
|
|
set_blocksize(dev,BLOCK_SIZE);
|
354 |
|
|
sb->sv_block_base = 0;
|
355 |
|
|
|
356 |
|
|
/* Try to read Xenix superblock */
|
357 |
|
|
if ((bh = bread(dev, 1, BLOCK_SIZE)) != NULL) {
|
358 |
|
|
if ((found = detect_xenix(sb,bh)) != NULL)
|
359 |
|
|
goto ok;
|
360 |
|
|
brelse(bh);
|
361 |
|
|
}
|
362 |
|
|
if ((bh = bread(dev, 0, BLOCK_SIZE)) != NULL) {
|
363 |
|
|
/* Try to recognize SystemV superblock */
|
364 |
|
|
if ((found = detect_sysv4(sb,bh)) != NULL)
|
365 |
|
|
goto ok;
|
366 |
|
|
if ((found = detect_sysv2(sb,bh)) != NULL)
|
367 |
|
|
goto ok;
|
368 |
|
|
/* Try to recognize Coherent superblock */
|
369 |
|
|
if ((found = detect_coherent(sb,bh)) != NULL)
|
370 |
|
|
goto ok;
|
371 |
|
|
brelse(bh);
|
372 |
|
|
}
|
373 |
|
|
/* Try to recognize SystemV superblock */
|
374 |
|
|
/* Offset by 1 track, i.e. most probably 9, 15, or 18 kilobytes. */
|
375 |
|
|
{ static int offsets[] = { 9, 15, 18, };
|
376 |
|
|
int i;
|
377 |
|
|
for (i = 0; i < sizeof(offsets)/sizeof(offsets[0]); i++)
|
378 |
|
|
if ((bh = bread(dev, offsets[i], BLOCK_SIZE)) != NULL) {
|
379 |
|
|
/* Try to recognize SystemV superblock */
|
380 |
|
|
if ((found = detect_sysv4(sb,bh)) != NULL) {
|
381 |
|
|
sb->sv_block_base = offsets[i] << sb->sv_block_size_ratio_bits;
|
382 |
|
|
goto ok;
|
383 |
|
|
}
|
384 |
|
|
if ((found = detect_sysv2(sb,bh)) != NULL) {
|
385 |
|
|
sb->sv_block_base = offsets[i] << sb->sv_block_size_ratio_bits;
|
386 |
|
|
goto ok;
|
387 |
|
|
}
|
388 |
|
|
brelse(bh);
|
389 |
|
|
}
|
390 |
|
|
}
|
391 |
|
|
sb->s_dev = 0;
|
392 |
|
|
unlock_super(sb);
|
393 |
|
|
if (!silent)
|
394 |
|
|
printk("VFS: unable to read Xenix/SystemV/Coherent superblock on device "
|
395 |
|
|
"%s\n", kdevname(dev));
|
396 |
|
|
failed:
|
397 |
|
|
MOD_DEC_USE_COUNT;
|
398 |
|
|
return NULL;
|
399 |
|
|
|
400 |
|
|
ok:
|
401 |
|
|
if (sb->sv_block_size == BLOCK_SIZE) {
|
402 |
|
|
switch (sb->sv_type) {
|
403 |
|
|
case FSTYPE_XENIX:
|
404 |
|
|
if (!detected_xenix(sb,bh,bh))
|
405 |
|
|
goto bad_superblock;
|
406 |
|
|
break;
|
407 |
|
|
case FSTYPE_SYSV4:
|
408 |
|
|
if (!detected_sysv4(sb,bh))
|
409 |
|
|
goto bad_superblock;
|
410 |
|
|
break;
|
411 |
|
|
case FSTYPE_SYSV2:
|
412 |
|
|
if (!detected_sysv2(sb,bh))
|
413 |
|
|
goto bad_superblock;
|
414 |
|
|
break;
|
415 |
|
|
default:
|
416 |
|
|
bad_superblock:
|
417 |
|
|
brelse(bh);
|
418 |
|
|
sb->s_dev = 0;
|
419 |
|
|
unlock_super(sb);
|
420 |
|
|
printk("SysV FS: cannot read superblock in 1024 byte mode\n");
|
421 |
|
|
goto failed;
|
422 |
|
|
}
|
423 |
|
|
} else {
|
424 |
|
|
/* Switch to another block size. Unfortunately, we have to
|
425 |
|
|
release the 1 KB block bh and read it in two parts again. */
|
426 |
|
|
struct buffer_head *bh1, *bh2;
|
427 |
|
|
unsigned long blocknr = bh->b_blocknr << sb->sv_block_size_ratio_bits;
|
428 |
|
|
|
429 |
|
|
brelse(bh);
|
430 |
|
|
set_blocksize(dev,sb->sv_block_size);
|
431 |
|
|
bh1 = NULL; bh2 = NULL;
|
432 |
|
|
switch (sb->sv_type) {
|
433 |
|
|
case FSTYPE_XENIX:
|
434 |
|
|
if ((bh1 = bread(dev, blocknr, sb->sv_block_size)) == NULL)
|
435 |
|
|
goto bad_superblock2;
|
436 |
|
|
if ((bh2 = bread(dev, blocknr+1, sb->sv_block_size)) == NULL)
|
437 |
|
|
goto bad_superblock2;
|
438 |
|
|
if (!detected_xenix(sb,bh1,bh2))
|
439 |
|
|
goto bad_superblock2;
|
440 |
|
|
break;
|
441 |
|
|
case FSTYPE_SYSV4:
|
442 |
|
|
if ((bh2 = bread(dev, blocknr+1, sb->sv_block_size)) == NULL)
|
443 |
|
|
goto bad_superblock2;
|
444 |
|
|
if (!detected_sysv4(sb,bh2))
|
445 |
|
|
goto bad_superblock2;
|
446 |
|
|
break;
|
447 |
|
|
case FSTYPE_SYSV2:
|
448 |
|
|
if ((bh2 = bread(dev, blocknr+1, sb->sv_block_size)) == NULL)
|
449 |
|
|
goto bad_superblock2;
|
450 |
|
|
if (!detected_sysv2(sb,bh2))
|
451 |
|
|
goto bad_superblock2;
|
452 |
|
|
break;
|
453 |
|
|
case FSTYPE_COH:
|
454 |
|
|
if ((bh2 = bread(dev, blocknr+1, sb->sv_block_size)) == NULL)
|
455 |
|
|
goto bad_superblock2;
|
456 |
|
|
if (!detected_coherent(sb,bh2))
|
457 |
|
|
goto bad_superblock2;
|
458 |
|
|
break;
|
459 |
|
|
default:
|
460 |
|
|
bad_superblock2:
|
461 |
|
|
brelse(bh1);
|
462 |
|
|
brelse(bh2);
|
463 |
|
|
set_blocksize(sb->s_dev,BLOCK_SIZE);
|
464 |
|
|
sb->s_dev = 0;
|
465 |
|
|
unlock_super(sb);
|
466 |
|
|
printk("SysV FS: cannot read superblock in 512 byte mode\n");
|
467 |
|
|
goto failed;
|
468 |
|
|
}
|
469 |
|
|
}
|
470 |
|
|
sb->sv_ninodes = (sb->sv_firstdatazone - sb->sv_firstinodezone) << sb->sv_inodes_per_block_bits;
|
471 |
|
|
if (!silent)
|
472 |
|
|
printk("VFS: Found a %s FS (block size = %d) on device %s\n",
|
473 |
|
|
found, sb->sv_block_size, kdevname(dev));
|
474 |
|
|
sb->s_magic = SYSV_MAGIC_BASE + sb->sv_type;
|
475 |
|
|
/* The buffer code now supports block size 512 as well as 1024. */
|
476 |
|
|
sb->s_blocksize = sb->sv_block_size;
|
477 |
|
|
sb->s_blocksize_bits = sb->sv_block_size_bits;
|
478 |
|
|
/* set up enough so that it can read an inode */
|
479 |
|
|
sb->s_dev = dev;
|
480 |
|
|
sb->s_op = &sysv_sops;
|
481 |
|
|
sb->s_mounted = iget(sb,SYSV_ROOT_INO);
|
482 |
|
|
unlock_super(sb);
|
483 |
|
|
if (!sb->s_mounted) {
|
484 |
|
|
printk("SysV FS: get root inode failed\n");
|
485 |
|
|
sysv_put_super(sb);
|
486 |
|
|
return NULL;
|
487 |
|
|
}
|
488 |
|
|
sb->s_dirt = 1;
|
489 |
|
|
/* brelse(bh); resp. brelse(bh1); brelse(bh2);
|
490 |
|
|
occurs when the disk is unmounted. */
|
491 |
|
|
return sb;
|
492 |
|
|
}
|
493 |
|
|
|
494 |
|
|
/* This is only called on sync() and umount(), when s_dirt=1. */
|
495 |
|
|
void sysv_write_super (struct super_block *sb)
|
496 |
|
|
{
|
497 |
|
|
lock_super(sb);
|
498 |
|
|
if (buffer_dirty(sb->sv_bh1) || buffer_dirty(sb->sv_bh2)) {
|
499 |
|
|
/* If we are going to write out the super block,
|
500 |
|
|
then attach current time stamp.
|
501 |
|
|
But if the filesystem was marked clean, keep it clean. */
|
502 |
|
|
unsigned long time = CURRENT_TIME;
|
503 |
|
|
unsigned long old_time = *sb->sv_sb_time;
|
504 |
|
|
if (sb->sv_convert)
|
505 |
|
|
old_time = from_coh_ulong(old_time);
|
506 |
|
|
if (sb->sv_type == FSTYPE_SYSV4)
|
507 |
|
|
if (*sb->sv_sb_state == 0x7c269d38 - old_time)
|
508 |
|
|
*sb->sv_sb_state = 0x7c269d38 - time;
|
509 |
|
|
if (sb->sv_convert)
|
510 |
|
|
time = to_coh_ulong(time);
|
511 |
|
|
*sb->sv_sb_time = time;
|
512 |
|
|
mark_buffer_dirty(sb->sv_bh2, 1);
|
513 |
|
|
}
|
514 |
|
|
sb->s_dirt = 0;
|
515 |
|
|
unlock_super(sb);
|
516 |
|
|
}
|
517 |
|
|
|
518 |
|
|
void sysv_put_super(struct super_block *sb)
|
519 |
|
|
{
|
520 |
|
|
/* we can assume sysv_write_super() has already been called */
|
521 |
|
|
lock_super(sb);
|
522 |
|
|
brelse(sb->sv_bh1);
|
523 |
|
|
if (sb->sv_bh1 != sb->sv_bh2) brelse(sb->sv_bh2);
|
524 |
|
|
/* switch back to default block size */
|
525 |
|
|
if (sb->s_blocksize != BLOCK_SIZE)
|
526 |
|
|
set_blocksize(sb->s_dev,BLOCK_SIZE);
|
527 |
|
|
sb->s_dev = 0;
|
528 |
|
|
unlock_super(sb);
|
529 |
|
|
MOD_DEC_USE_COUNT;
|
530 |
|
|
}
|
531 |
|
|
|
532 |
|
|
void sysv_statfs(struct super_block *sb, struct statfs *buf, int bufsiz)
|
533 |
|
|
{
|
534 |
|
|
struct statfs tmp;
|
535 |
|
|
|
536 |
|
|
tmp.f_type = sb->s_magic; /* type of filesystem */
|
537 |
|
|
tmp.f_bsize = sb->sv_block_size; /* block size */
|
538 |
|
|
tmp.f_blocks = sb->sv_ndatazones; /* total data blocks in file system */
|
539 |
|
|
tmp.f_bfree = sysv_count_free_blocks(sb); /* free blocks in fs */
|
540 |
|
|
tmp.f_bavail = tmp.f_bfree; /* free blocks available to non-superuser */
|
541 |
|
|
tmp.f_files = sb->sv_ninodes; /* total file nodes in file system */
|
542 |
|
|
tmp.f_ffree = sysv_count_free_inodes(sb); /* free file nodes in fs */
|
543 |
|
|
tmp.f_namelen = SYSV_NAMELEN;
|
544 |
|
|
/* Don't know what value to put in tmp.f_fsid */ /* file system id */
|
545 |
|
|
memcpy_tofs(buf, &tmp, bufsiz);
|
546 |
|
|
}
|
547 |
|
|
|
548 |
|
|
|
549 |
|
|
/* bmap support for running executables and shared libraries. */
|
550 |
|
|
|
551 |
|
|
static inline int inode_bmap(struct super_block * sb, struct inode * inode, int nr)
|
552 |
|
|
{
|
553 |
|
|
int tmp = inode->u.sysv_i.i_data[nr];
|
554 |
|
|
if (!tmp)
|
555 |
|
|
return 0;
|
556 |
|
|
return tmp + sb->sv_block_base;
|
557 |
|
|
}
|
558 |
|
|
|
559 |
|
|
static int block_bmap(struct super_block * sb, struct buffer_head * bh, int nr, int convert)
|
560 |
|
|
{
|
561 |
|
|
int tmp;
|
562 |
|
|
|
563 |
|
|
if (!bh)
|
564 |
|
|
return 0;
|
565 |
|
|
tmp = ((sysv_zone_t *) bh->b_data) [nr];
|
566 |
|
|
if (convert)
|
567 |
|
|
tmp = from_coh_ulong(tmp);
|
568 |
|
|
brelse(bh);
|
569 |
|
|
if (!tmp)
|
570 |
|
|
return 0;
|
571 |
|
|
return tmp + sb->sv_block_base;
|
572 |
|
|
}
|
573 |
|
|
|
574 |
|
|
int sysv_bmap(struct inode * inode,int block_nr)
|
575 |
|
|
{
|
576 |
|
|
unsigned int block = block_nr;
|
577 |
|
|
struct super_block * sb = inode->i_sb;
|
578 |
|
|
int convert;
|
579 |
|
|
int i;
|
580 |
|
|
struct buffer_head * bh;
|
581 |
|
|
|
582 |
|
|
if (block < 10)
|
583 |
|
|
return inode_bmap(sb,inode,block);
|
584 |
|
|
block -= 10;
|
585 |
|
|
convert = sb->sv_convert;
|
586 |
|
|
if (block < sb->sv_ind_per_block) {
|
587 |
|
|
i = inode_bmap(sb,inode,10);
|
588 |
|
|
if (!i)
|
589 |
|
|
return 0;
|
590 |
|
|
bh = bread(inode->i_dev,i,sb->sv_block_size);
|
591 |
|
|
return block_bmap(sb, bh, block, convert);
|
592 |
|
|
}
|
593 |
|
|
block -= sb->sv_ind_per_block;
|
594 |
|
|
if (block < sb->sv_ind_per_block_2) {
|
595 |
|
|
i = inode_bmap(sb,inode,11);
|
596 |
|
|
if (!i)
|
597 |
|
|
return 0;
|
598 |
|
|
bh = bread(inode->i_dev,i,sb->sv_block_size);
|
599 |
|
|
i = block_bmap(sb, bh, block >> sb->sv_ind_per_block_bits, convert);
|
600 |
|
|
if (!i)
|
601 |
|
|
return 0;
|
602 |
|
|
bh = bread(inode->i_dev,i,sb->sv_block_size);
|
603 |
|
|
return block_bmap(sb, bh, block & sb->sv_ind_per_block_1, convert);
|
604 |
|
|
}
|
605 |
|
|
block -= sb->sv_ind_per_block_2;
|
606 |
|
|
if (block < sb->sv_ind_per_block_3) {
|
607 |
|
|
i = inode_bmap(sb,inode,12);
|
608 |
|
|
if (!i)
|
609 |
|
|
return 0;
|
610 |
|
|
bh = bread(inode->i_dev,i,sb->sv_block_size);
|
611 |
|
|
i = block_bmap(sb, bh, block >> sb->sv_ind_per_block_2_bits, convert);
|
612 |
|
|
if (!i)
|
613 |
|
|
return 0;
|
614 |
|
|
bh = bread(inode->i_dev,i,sb->sv_block_size);
|
615 |
|
|
i = block_bmap(sb, bh, (block >> sb->sv_ind_per_block_bits) & sb->sv_ind_per_block_1,convert);
|
616 |
|
|
if (!i)
|
617 |
|
|
return 0;
|
618 |
|
|
bh = bread(inode->i_dev,i,sb->sv_block_size);
|
619 |
|
|
return block_bmap(sb, bh, block & sb->sv_ind_per_block_1, convert);
|
620 |
|
|
}
|
621 |
|
|
if ((int)block<0) {
|
622 |
|
|
printk("sysv_bmap: block<0");
|
623 |
|
|
return 0;
|
624 |
|
|
}
|
625 |
|
|
printk("sysv_bmap: block>big");
|
626 |
|
|
return 0;
|
627 |
|
|
}
|
628 |
|
|
|
629 |
|
|
/* End of bmap support. */
|
630 |
|
|
|
631 |
|
|
|
632 |
|
|
/* Access selected blocks of regular files (or directories) */
|
633 |
|
|
|
634 |
|
|
static struct buffer_head * inode_getblk(struct inode * inode, int nr, int create)
|
635 |
|
|
{
|
636 |
|
|
struct super_block *sb;
|
637 |
|
|
unsigned long tmp;
|
638 |
|
|
unsigned long *p;
|
639 |
|
|
struct buffer_head * result;
|
640 |
|
|
|
641 |
|
|
sb = inode->i_sb;
|
642 |
|
|
p = inode->u.sysv_i.i_data + nr;
|
643 |
|
|
repeat:
|
644 |
|
|
tmp = *p;
|
645 |
|
|
if (tmp) {
|
646 |
|
|
result = sv_getblk(sb, inode->i_dev, tmp);
|
647 |
|
|
if (tmp == *p)
|
648 |
|
|
return result;
|
649 |
|
|
brelse(result);
|
650 |
|
|
goto repeat;
|
651 |
|
|
}
|
652 |
|
|
if (!create)
|
653 |
|
|
return NULL;
|
654 |
|
|
tmp = sysv_new_block(sb);
|
655 |
|
|
if (!tmp)
|
656 |
|
|
return NULL;
|
657 |
|
|
result = sv_getblk(sb, inode->i_dev, tmp);
|
658 |
|
|
if (*p) {
|
659 |
|
|
sysv_free_block(sb,tmp);
|
660 |
|
|
brelse(result);
|
661 |
|
|
goto repeat;
|
662 |
|
|
}
|
663 |
|
|
*p = tmp;
|
664 |
|
|
inode->i_ctime = CURRENT_TIME;
|
665 |
|
|
inode->i_dirt = 1;
|
666 |
|
|
return result;
|
667 |
|
|
}
|
668 |
|
|
|
669 |
|
|
static struct buffer_head * block_getblk(struct inode * inode,
|
670 |
|
|
struct buffer_head * bh, int nr, int create)
|
671 |
|
|
{
|
672 |
|
|
struct super_block *sb;
|
673 |
|
|
unsigned long tmp, block;
|
674 |
|
|
sysv_zone_t *p;
|
675 |
|
|
struct buffer_head * result;
|
676 |
|
|
|
677 |
|
|
if (!bh)
|
678 |
|
|
return NULL;
|
679 |
|
|
if (!buffer_uptodate(bh)) {
|
680 |
|
|
ll_rw_block(READ, 1, &bh);
|
681 |
|
|
wait_on_buffer(bh);
|
682 |
|
|
if (!buffer_uptodate(bh)) {
|
683 |
|
|
brelse(bh);
|
684 |
|
|
return NULL;
|
685 |
|
|
}
|
686 |
|
|
}
|
687 |
|
|
sb = inode->i_sb;
|
688 |
|
|
p = nr + (sysv_zone_t *) bh->b_data;
|
689 |
|
|
repeat:
|
690 |
|
|
block = tmp = *p;
|
691 |
|
|
if (sb->sv_convert)
|
692 |
|
|
block = from_coh_ulong(block);
|
693 |
|
|
if (tmp) {
|
694 |
|
|
result = sv_getblk(sb, bh->b_dev, block);
|
695 |
|
|
if (tmp == *p) {
|
696 |
|
|
brelse(bh);
|
697 |
|
|
return result;
|
698 |
|
|
}
|
699 |
|
|
brelse(result);
|
700 |
|
|
goto repeat;
|
701 |
|
|
}
|
702 |
|
|
if (!create) {
|
703 |
|
|
brelse(bh);
|
704 |
|
|
return NULL;
|
705 |
|
|
}
|
706 |
|
|
block = sysv_new_block(sb);
|
707 |
|
|
if (!block) {
|
708 |
|
|
brelse(bh);
|
709 |
|
|
return NULL;
|
710 |
|
|
}
|
711 |
|
|
result = sv_getblk(sb, bh->b_dev, block);
|
712 |
|
|
if (*p) {
|
713 |
|
|
sysv_free_block(sb,block);
|
714 |
|
|
brelse(result);
|
715 |
|
|
goto repeat;
|
716 |
|
|
}
|
717 |
|
|
*p = (sb->sv_convert ? to_coh_ulong(block) : block);
|
718 |
|
|
mark_buffer_dirty(bh, 1);
|
719 |
|
|
brelse(bh);
|
720 |
|
|
return result;
|
721 |
|
|
}
|
722 |
|
|
|
723 |
|
|
struct buffer_head * sysv_getblk(struct inode * inode, unsigned int block, int create)
|
724 |
|
|
{
|
725 |
|
|
struct super_block * sb = inode->i_sb;
|
726 |
|
|
struct buffer_head * bh;
|
727 |
|
|
|
728 |
|
|
if (block < 10)
|
729 |
|
|
return inode_getblk(inode,block,create);
|
730 |
|
|
block -= 10;
|
731 |
|
|
if (block < sb->sv_ind_per_block) {
|
732 |
|
|
bh = inode_getblk(inode,10,create);
|
733 |
|
|
return block_getblk(inode, bh, block, create);
|
734 |
|
|
}
|
735 |
|
|
block -= sb->sv_ind_per_block;
|
736 |
|
|
if (block < sb->sv_ind_per_block_2) {
|
737 |
|
|
bh = inode_getblk(inode,11,create);
|
738 |
|
|
bh = block_getblk(inode, bh, block >> sb->sv_ind_per_block_bits, create);
|
739 |
|
|
return block_getblk(inode, bh, block & sb->sv_ind_per_block_1, create);
|
740 |
|
|
}
|
741 |
|
|
block -= sb->sv_ind_per_block_2;
|
742 |
|
|
if (block < sb->sv_ind_per_block_3) {
|
743 |
|
|
bh = inode_getblk(inode,12,create);
|
744 |
|
|
bh = block_getblk(inode, bh, block >> sb->sv_ind_per_block_2_bits, create);
|
745 |
|
|
bh = block_getblk(inode, bh, (block >> sb->sv_ind_per_block_bits) & sb->sv_ind_per_block_1, create);
|
746 |
|
|
return block_getblk(inode, bh, block & sb->sv_ind_per_block_1, create);
|
747 |
|
|
}
|
748 |
|
|
if ((int)block<0) {
|
749 |
|
|
printk("sysv_getblk: block<0");
|
750 |
|
|
return NULL;
|
751 |
|
|
}
|
752 |
|
|
printk("sysv_getblk: block>big");
|
753 |
|
|
return NULL;
|
754 |
|
|
}
|
755 |
|
|
|
756 |
|
|
struct buffer_head * sysv_file_bread(struct inode * inode, int block, int create)
|
757 |
|
|
{
|
758 |
|
|
struct buffer_head * bh;
|
759 |
|
|
|
760 |
|
|
bh = sysv_getblk(inode,block,create);
|
761 |
|
|
if (!bh || buffer_uptodate(bh))
|
762 |
|
|
return bh;
|
763 |
|
|
ll_rw_block(READ, 1, &bh);
|
764 |
|
|
wait_on_buffer(bh);
|
765 |
|
|
if (buffer_uptodate(bh))
|
766 |
|
|
return bh;
|
767 |
|
|
brelse(bh);
|
768 |
|
|
return NULL;
|
769 |
|
|
}
|
770 |
|
|
|
771 |
|
|
|
772 |
|
|
static inline unsigned long read3byte (char * p)
|
773 |
|
|
{
|
774 |
|
|
return (unsigned long)(*(unsigned short *)p)
|
775 |
|
|
| (unsigned long)(*(unsigned char *)(p+2)) << 16;
|
776 |
|
|
}
|
777 |
|
|
|
778 |
|
|
static inline void write3byte (char * p, unsigned long val)
|
779 |
|
|
{
|
780 |
|
|
*(unsigned short *)p = (unsigned short) val;
|
781 |
|
|
*(unsigned char *)(p+2) = val >> 16;
|
782 |
|
|
}
|
783 |
|
|
|
784 |
|
|
static inline unsigned long coh_read3byte (char * p)
|
785 |
|
|
{
|
786 |
|
|
return (unsigned long)(*(unsigned char *)p) << 16
|
787 |
|
|
| (unsigned long)(*(unsigned short *)(p+1));
|
788 |
|
|
}
|
789 |
|
|
|
790 |
|
|
static inline void coh_write3byte (char * p, unsigned long val)
|
791 |
|
|
{
|
792 |
|
|
*(unsigned char *)p = val >> 16;
|
793 |
|
|
*(unsigned short *)(p+1) = (unsigned short) val;
|
794 |
|
|
}
|
795 |
|
|
|
796 |
|
|
void sysv_read_inode(struct inode * inode)
|
797 |
|
|
{
|
798 |
|
|
struct super_block * sb = inode->i_sb;
|
799 |
|
|
struct buffer_head * bh;
|
800 |
|
|
struct sysv_inode * raw_inode;
|
801 |
|
|
unsigned int block, ino;
|
802 |
|
|
umode_t mode;
|
803 |
|
|
|
804 |
|
|
ino = inode->i_ino;
|
805 |
|
|
inode->i_op = NULL;
|
806 |
|
|
inode->i_mode = 0;
|
807 |
|
|
if (!ino || ino > sb->sv_ninodes) {
|
808 |
|
|
printk("Bad inode number on dev %s"
|
809 |
|
|
": %d is out of range\n",
|
810 |
|
|
kdevname(inode->i_dev), ino);
|
811 |
|
|
return;
|
812 |
|
|
}
|
813 |
|
|
block = sb->sv_firstinodezone + ((ino-1) >> sb->sv_inodes_per_block_bits);
|
814 |
|
|
if (!(bh = sv_bread(sb,inode->i_dev,block))) {
|
815 |
|
|
printk("Major problem: unable to read inode from dev "
|
816 |
|
|
"%s\n",
|
817 |
|
|
kdevname(inode->i_dev));
|
818 |
|
|
return;
|
819 |
|
|
}
|
820 |
|
|
raw_inode = (struct sysv_inode *) bh->b_data + ((ino-1) & sb->sv_inodes_per_block_1);
|
821 |
|
|
mode = raw_inode->i_mode;
|
822 |
|
|
if (sb->sv_kludge_symlinks)
|
823 |
|
|
mode = from_coh_imode(mode);
|
824 |
|
|
/* SystemV FS: kludge permissions if ino==SYSV_ROOT_INO ?? */
|
825 |
|
|
inode->i_mode = mode;
|
826 |
|
|
inode->i_uid = raw_inode->i_uid;
|
827 |
|
|
inode->i_gid = raw_inode->i_gid;
|
828 |
|
|
inode->i_nlink = raw_inode->i_nlink;
|
829 |
|
|
if (sb->sv_convert) {
|
830 |
|
|
inode->i_size = from_coh_ulong(raw_inode->i_size);
|
831 |
|
|
inode->i_atime = from_coh_ulong(raw_inode->i_atime);
|
832 |
|
|
inode->i_mtime = from_coh_ulong(raw_inode->i_mtime);
|
833 |
|
|
inode->i_ctime = from_coh_ulong(raw_inode->i_ctime);
|
834 |
|
|
} else {
|
835 |
|
|
inode->i_size = raw_inode->i_size;
|
836 |
|
|
inode->i_atime = raw_inode->i_atime;
|
837 |
|
|
inode->i_mtime = raw_inode->i_mtime;
|
838 |
|
|
inode->i_ctime = raw_inode->i_ctime;
|
839 |
|
|
}
|
840 |
|
|
inode->i_blocks = inode->i_blksize = 0;
|
841 |
|
|
if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
|
842 |
|
|
inode->i_rdev = to_kdev_t(raw_inode->i_a.i_rdev);
|
843 |
|
|
else
|
844 |
|
|
if (sb->sv_convert)
|
845 |
|
|
for (block = 0; block < 10+1+1+1; block++)
|
846 |
|
|
inode->u.sysv_i.i_data[block] =
|
847 |
|
|
coh_read3byte(&raw_inode->i_a.i_addb[3*block]);
|
848 |
|
|
else
|
849 |
|
|
for (block = 0; block < 10+1+1+1; block++)
|
850 |
|
|
inode->u.sysv_i.i_data[block] =
|
851 |
|
|
read3byte(&raw_inode->i_a.i_addb[3*block]);
|
852 |
|
|
brelse(bh);
|
853 |
|
|
if (S_ISREG(inode->i_mode))
|
854 |
|
|
inode->i_op = &sysv_file_inode_operations;
|
855 |
|
|
else if (S_ISDIR(inode->i_mode))
|
856 |
|
|
inode->i_op = &sysv_dir_inode_operations;
|
857 |
|
|
else if (S_ISLNK(inode->i_mode))
|
858 |
|
|
inode->i_op = &sysv_symlink_inode_operations;
|
859 |
|
|
else if (S_ISCHR(inode->i_mode))
|
860 |
|
|
inode->i_op = &chrdev_inode_operations;
|
861 |
|
|
else if (S_ISBLK(inode->i_mode))
|
862 |
|
|
inode->i_op = &blkdev_inode_operations;
|
863 |
|
|
else if (S_ISFIFO(inode->i_mode))
|
864 |
|
|
init_fifo(inode);
|
865 |
|
|
}
|
866 |
|
|
|
867 |
|
|
/* To avoid inconsistencies between inodes in memory and inodes on disk. */
|
868 |
|
|
extern int sysv_notify_change(struct inode *inode, struct iattr *attr)
|
869 |
|
|
{
|
870 |
|
|
int error;
|
871 |
|
|
|
872 |
|
|
if ((error = inode_change_ok(inode, attr)) != 0)
|
873 |
|
|
return error;
|
874 |
|
|
|
875 |
|
|
if (attr->ia_valid & ATTR_MODE)
|
876 |
|
|
if (inode->i_sb->sv_kludge_symlinks)
|
877 |
|
|
if (attr->ia_mode == COH_KLUDGE_SYMLINK_MODE)
|
878 |
|
|
attr->ia_mode = COH_KLUDGE_NOT_SYMLINK;
|
879 |
|
|
|
880 |
|
|
inode_setattr(inode, attr);
|
881 |
|
|
|
882 |
|
|
return 0;
|
883 |
|
|
}
|
884 |
|
|
|
885 |
|
|
static struct buffer_head * sysv_update_inode(struct inode * inode)
|
886 |
|
|
{
|
887 |
|
|
struct super_block * sb = inode->i_sb;
|
888 |
|
|
struct buffer_head * bh;
|
889 |
|
|
struct sysv_inode * raw_inode;
|
890 |
|
|
unsigned int ino, block;
|
891 |
|
|
umode_t mode;
|
892 |
|
|
|
893 |
|
|
ino = inode->i_ino;
|
894 |
|
|
if (!ino || ino > sb->sv_ninodes) {
|
895 |
|
|
printk("Bad inode number on dev %s"
|
896 |
|
|
": %d is out of range\n",
|
897 |
|
|
kdevname(inode->i_dev), ino);
|
898 |
|
|
inode->i_dirt = 0;
|
899 |
|
|
return 0;
|
900 |
|
|
}
|
901 |
|
|
block = sb->sv_firstinodezone + ((ino-1) >> sb->sv_inodes_per_block_bits);
|
902 |
|
|
if (!(bh = sv_bread(sb,inode->i_dev,block))) {
|
903 |
|
|
printk("unable to read i-node block\n");
|
904 |
|
|
inode->i_dirt = 0;
|
905 |
|
|
return 0;
|
906 |
|
|
}
|
907 |
|
|
raw_inode = (struct sysv_inode *) bh->b_data + ((ino-1) & sb->sv_inodes_per_block_1);
|
908 |
|
|
mode = inode->i_mode;
|
909 |
|
|
if (sb->sv_kludge_symlinks)
|
910 |
|
|
mode = to_coh_imode(mode);
|
911 |
|
|
raw_inode->i_mode = mode;
|
912 |
|
|
raw_inode->i_uid = inode->i_uid;
|
913 |
|
|
raw_inode->i_gid = inode->i_gid;
|
914 |
|
|
raw_inode->i_nlink = inode->i_nlink;
|
915 |
|
|
if (sb->sv_convert) {
|
916 |
|
|
raw_inode->i_size = to_coh_ulong(inode->i_size);
|
917 |
|
|
raw_inode->i_atime = to_coh_ulong(inode->i_atime);
|
918 |
|
|
raw_inode->i_mtime = to_coh_ulong(inode->i_mtime);
|
919 |
|
|
raw_inode->i_ctime = to_coh_ulong(inode->i_ctime);
|
920 |
|
|
} else {
|
921 |
|
|
raw_inode->i_size = inode->i_size;
|
922 |
|
|
raw_inode->i_atime = inode->i_atime;
|
923 |
|
|
raw_inode->i_mtime = inode->i_mtime;
|
924 |
|
|
raw_inode->i_ctime = inode->i_ctime;
|
925 |
|
|
}
|
926 |
|
|
if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
|
927 |
|
|
raw_inode->i_a.i_rdev = kdev_t_to_nr(inode->i_rdev); /* write 2 or 3 bytes ?? */
|
928 |
|
|
else
|
929 |
|
|
if (sb->sv_convert)
|
930 |
|
|
for (block = 0; block < 10+1+1+1; block++)
|
931 |
|
|
coh_write3byte(&raw_inode->i_a.i_addb[3*block],inode->u.sysv_i.i_data[block]);
|
932 |
|
|
else
|
933 |
|
|
for (block = 0; block < 10+1+1+1; block++)
|
934 |
|
|
write3byte(&raw_inode->i_a.i_addb[3*block],inode->u.sysv_i.i_data[block]);
|
935 |
|
|
inode->i_dirt=0;
|
936 |
|
|
mark_buffer_dirty(bh, 1);
|
937 |
|
|
return bh;
|
938 |
|
|
}
|
939 |
|
|
|
940 |
|
|
void sysv_write_inode(struct inode * inode)
|
941 |
|
|
{
|
942 |
|
|
struct buffer_head *bh;
|
943 |
|
|
bh = sysv_update_inode(inode);
|
944 |
|
|
brelse(bh);
|
945 |
|
|
}
|
946 |
|
|
|
947 |
|
|
int sysv_sync_inode(struct inode * inode)
|
948 |
|
|
{
|
949 |
|
|
int err = 0;
|
950 |
|
|
struct buffer_head *bh;
|
951 |
|
|
|
952 |
|
|
bh = sysv_update_inode(inode);
|
953 |
|
|
if (bh && buffer_dirty(bh)) {
|
954 |
|
|
ll_rw_block(WRITE, 1, &bh);
|
955 |
|
|
wait_on_buffer(bh);
|
956 |
|
|
if (buffer_req(bh) && !buffer_uptodate(bh))
|
957 |
|
|
{
|
958 |
|
|
printk ("IO error syncing sysv inode ["
|
959 |
|
|
"%s:%08lx]\n",
|
960 |
|
|
kdevname(inode->i_dev), inode->i_ino);
|
961 |
|
|
err = -1;
|
962 |
|
|
}
|
963 |
|
|
}
|
964 |
|
|
else if (!bh)
|
965 |
|
|
err = -1;
|
966 |
|
|
brelse (bh);
|
967 |
|
|
return err;
|
968 |
|
|
}
|
969 |
|
|
|
970 |
|
|
/* Every kernel module contains stuff like this. */
|
971 |
|
|
|
972 |
|
|
static struct file_system_type sysv_fs_type[3] = {
|
973 |
|
|
{sysv_read_super, "xenix", 1, NULL},
|
974 |
|
|
{sysv_read_super, "sysv", 1, NULL},
|
975 |
|
|
{sysv_read_super, "coherent", 1, NULL}
|
976 |
|
|
};
|
977 |
|
|
|
978 |
|
|
int init_sysv_fs(void)
|
979 |
|
|
{
|
980 |
|
|
int i;
|
981 |
|
|
int ouch;
|
982 |
|
|
|
983 |
|
|
for (i = 0; i < 3; i++) {
|
984 |
|
|
if ((ouch = register_filesystem(&sysv_fs_type[i])) != 0)
|
985 |
|
|
return ouch;
|
986 |
|
|
}
|
987 |
|
|
return ouch;
|
988 |
|
|
}
|
989 |
|
|
|
990 |
|
|
#ifdef MODULE
|
991 |
|
|
int init_module(void)
|
992 |
|
|
{
|
993 |
|
|
int status;
|
994 |
|
|
|
995 |
|
|
if ((status = init_sysv_fs()) == 0)
|
996 |
|
|
register_symtab(0);
|
997 |
|
|
return status;
|
998 |
|
|
}
|
999 |
|
|
|
1000 |
|
|
void cleanup_module(void)
|
1001 |
|
|
{
|
1002 |
|
|
int i;
|
1003 |
|
|
|
1004 |
|
|
for (i = 0; i < 3; i++)
|
1005 |
|
|
/* No error message if this breaks... that's OK... */
|
1006 |
|
|
unregister_filesystem(&sysv_fs_type[i]);
|
1007 |
|
|
}
|
1008 |
|
|
|
1009 |
|
|
#endif
|