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