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_block_base = 0;
232 sb->sv_firstinodezone = 2;
233 sb->sv_firstdatazone = sbd->s_isize;
234 sb->sv_nzones = sbd->s_fsize;
235 sb->sv_ndatazones = sb->sv_nzones - sb->sv_firstdatazone;
236 return sb;
237 }
238
239 static const char* detect_sysv2 (struct super_block *sb, struct buffer_head *bh)
240 {
241 struct sysv2_super_block * sbd;
242
243 sbd = (struct sysv2_super_block *) (bh->b_data + BLOCK_SIZE/2);
244 if (sbd->s_magic != 0xfd187e20)
245 return NULL;
246 if (sbd->s_time < 315532800)
247 return NULL;
248 switch (sbd->s_type) {
249 case 1: detected_bs512(sb); break;
250 case 2: detected_bs1024(sb); break;
251 default: return NULL;
252 }
253 sb->sv_type = FSTYPE_SYSV2;
254 return "SystemV Release 2";
255 }
256 static struct super_block * detected_sysv2 (struct super_block *sb, struct buffer_head *bh)
257 {
258 struct sysv2_super_block * sbd;
259
260 if (sb->sv_block_size == BLOCK_SIZE)
261 sbd = (struct sysv2_super_block *) (bh->b_data + BLOCK_SIZE/2);
262 else {
263 sbd = (struct sysv2_super_block *) bh->b_data;
264
265 if (sbd->s_magic != 0xfd187e20)
266 return NULL;
267 if (sbd->s_time < 315532800)
268 return NULL;
269 }
270
271 sb->sv_convert = 0;
272 sb->sv_kludge_symlinks = 0;
273 sb->sv_truncate = 1;
274 sb->sv_link_max = SYSV_LINK_MAX;
275 sb->sv_fic_size = SYSV_NICINOD;
276 sb->sv_flc_size = SYSV_NICFREE;
277 sb->sv_bh1 = bh;
278 sb->sv_bh2 = bh;
279 sb->sv_sbd1 = (char *) sbd;
280 sb->sv_sbd2 = (char *) sbd;
281 sb->sv_sb_fic_count = &sbd->s_ninode;
282 sb->sv_sb_fic_inodes = &sbd->s_inode[0];
283 sb->sv_sb_total_free_inodes = &sbd->s_tinode;
284 sb->sv_sb_flc_count = &sbd->s_nfree;
285 sb->sv_sb_flc_blocks = &sbd->s_free[0];
286 sb->sv_sb_total_free_blocks = &sbd->s_tfree;
287 sb->sv_sb_time = &sbd->s_time;
288 sb->sv_block_base = 0;
289 sb->sv_firstinodezone = 2;
290 sb->sv_firstdatazone = sbd->s_isize;
291 sb->sv_nzones = sbd->s_fsize;
292 sb->sv_ndatazones = sb->sv_nzones - sb->sv_firstdatazone;
293 return sb;
294 }
295
296 static const char* detect_coherent (struct super_block *sb, struct buffer_head *bh)
297 {
298 struct coh_super_block * sbd;
299
300 sbd = (struct coh_super_block *) (bh->b_data + BLOCK_SIZE/2);
301 if ((memcmp(sbd->s_fname,"noname",6) && memcmp(sbd->s_fname,"xxxxx ",6))
302 || (memcmp(sbd->s_fpack,"nopack",6) && memcmp(sbd->s_fpack,"xxxxx\n",6)))
303 return NULL;
304 detected_bs512(sb);
305 sb->sv_type = FSTYPE_COH;
306 return "Coherent";
307 }
308 static struct super_block * detected_coherent (struct super_block *sb, struct buffer_head *bh)
309 {
310 struct coh_super_block * sbd;
311
312 sbd = (struct coh_super_block *) bh->b_data;
313
314 if ((memcmp(sbd->s_fname,"noname",6) && memcmp(sbd->s_fname,"xxxxx ",6))
315 || (memcmp(sbd->s_fpack,"nopack",6) && memcmp(sbd->s_fpack,"xxxxx\n",6)))
316 return NULL;
317
318 sb->sv_convert = 1;
319 sb->sv_kludge_symlinks = 1;
320 sb->sv_truncate = 1;
321 sb->sv_link_max = COH_LINK_MAX;
322 sb->sv_fic_size = COH_NICINOD;
323 sb->sv_flc_size = COH_NICFREE;
324 sb->sv_bh1 = bh;
325 sb->sv_bh2 = bh;
326 sb->sv_sbd1 = (char *) sbd;
327 sb->sv_sbd2 = (char *) sbd;
328 sb->sv_sb_fic_count = &sbd->s_ninode;
329 sb->sv_sb_fic_inodes = &sbd->s_inode[0];
330 sb->sv_sb_total_free_inodes = &sbd->s_tinode;
331 sb->sv_sb_flc_count = &sbd->s_nfree;
332 sb->sv_sb_flc_blocks = &sbd->s_free[0];
333 sb->sv_sb_total_free_blocks = &sbd->s_tfree;
334 sb->sv_sb_time = &sbd->s_time;
335 sb->sv_block_base = 0;
336 sb->sv_firstinodezone = 2;
337 sb->sv_firstdatazone = sbd->s_isize;
338 sb->sv_nzones = from_coh_ulong(sbd->s_fsize);
339 sb->sv_ndatazones = sb->sv_nzones - sb->sv_firstdatazone;
340 return sb;
341 }
342
343 struct super_block *sysv_read_super(struct super_block *sb,void *data,
344 int silent)
345 {
346 struct buffer_head *bh;
347 const char *found;
348 int dev = sb->s_dev;
349
350 if (1024 != sizeof (struct xenix_super_block))
351 panic("Xenix FS: bad super-block size");
352 if ((512 != sizeof (struct sysv4_super_block))
353 || (512 != sizeof (struct sysv2_super_block)))
354 panic("SystemV FS: bad super-block size");
355 if (500 != sizeof (struct coh_super_block))
356 panic("Coherent FS: bad super-block size");
357 if (64 != sizeof (struct sysv_inode))
358 panic("sysv fs: bad i-node size");
359 MOD_INC_USE_COUNT;
360 lock_super(sb);
361 set_blocksize(dev,BLOCK_SIZE);
362
363
364 if ((bh = bread(dev, 1, BLOCK_SIZE)) != NULL) {
365 if ((found = detect_xenix(sb,bh)) != NULL)
366 goto ok;
367 brelse(bh);
368 }
369 if ((bh = bread(dev, 0, BLOCK_SIZE)) != NULL) {
370
371 if ((found = detect_sysv4(sb,bh)) != NULL)
372 goto ok;
373 if ((found = detect_sysv2(sb,bh)) != NULL)
374 goto ok;
375
376 if ((found = detect_coherent(sb,bh)) != NULL)
377 goto ok;
378 brelse(bh);
379 }
380
381
382 { static int offsets[] = { 9, 15, 18, };
383 int i;
384 for (i = 0; i < sizeof(offsets)/sizeof(offsets[0]); i++)
385 if ((bh = bread(dev, offsets[i], BLOCK_SIZE)) != NULL) {
386
387 if ((found = detect_sysv4(sb,bh)) != NULL) {
388 sb->sv_block_base = offsets[i] << sb->sv_block_size_ratio_bits;
389 goto ok;
390 }
391 if ((found = detect_sysv2(sb,bh)) != NULL) {
392 sb->sv_block_base = offsets[i] << sb->sv_block_size_ratio_bits;
393 goto ok;
394 }
395 brelse(bh);
396 }
397 }
398 sb->s_dev=0;
399 unlock_super(sb);
400 if (!silent)
401 printk("VFS: unable to read Xenix/SystemV/Coherent superblock on device %d/%d\n",MAJOR(dev),MINOR(dev));
402 failed:
403 MOD_DEC_USE_COUNT;
404 return NULL;
405
406 ok:
407 if (sb->sv_block_size == BLOCK_SIZE) {
408 switch (sb->sv_type) {
409 case FSTYPE_XENIX:
410 if (!detected_xenix(sb,bh,bh))
411 goto bad_superblock;
412 break;
413 case FSTYPE_SYSV4:
414 if (!detected_sysv4(sb,bh))
415 goto bad_superblock;
416 break;
417 case FSTYPE_SYSV2:
418 if (!detected_sysv2(sb,bh))
419 goto bad_superblock;
420 break;
421 default:
422 bad_superblock:
423 brelse(bh);
424 sb->s_dev = 0;
425 unlock_super(sb);
426 printk("SysV FS: cannot read superblock in 1024 byte mode\n");
427 goto failed;
428 }
429 } else {
430
431
432 struct buffer_head *bh1, *bh2;
433 unsigned long blocknr = bh->b_blocknr << sb->sv_block_size_ratio_bits;
434
435 brelse(bh);
436 set_blocksize(dev,sb->sv_block_size);
437 bh1 = NULL; bh2 = NULL;
438 switch (sb->sv_type) {
439 case FSTYPE_XENIX:
440 if ((bh1 = bread(dev, blocknr, sb->sv_block_size)) == NULL)
441 goto bad_superblock2;
442 if ((bh2 = bread(dev, blocknr+1, sb->sv_block_size)) == NULL)
443 goto bad_superblock2;
444 if (!detected_xenix(sb,bh1,bh2))
445 goto bad_superblock2;
446 break;
447 case FSTYPE_SYSV4:
448 if ((bh2 = bread(dev, blocknr+1, sb->sv_block_size)) == NULL)
449 goto bad_superblock2;
450 if (!detected_sysv4(sb,bh2))
451 goto bad_superblock2;
452 break;
453 case FSTYPE_SYSV2:
454 if ((bh2 = bread(dev, blocknr+1, sb->sv_block_size)) == NULL)
455 goto bad_superblock2;
456 if (!detected_sysv2(sb,bh2))
457 goto bad_superblock2;
458 break;
459 case FSTYPE_COH:
460 if ((bh2 = bread(dev, blocknr+1, sb->sv_block_size)) == NULL)
461 goto bad_superblock2;
462 if (!detected_coherent(sb,bh2))
463 goto bad_superblock2;
464 break;
465 default:
466 bad_superblock2:
467 brelse(bh1);
468 brelse(bh2);
469 set_blocksize(sb->s_dev,BLOCK_SIZE);
470 sb->s_dev = 0;
471 unlock_super(sb);
472 printk("SysV FS: cannot read superblock in 512 byte mode\n");
473 goto failed;
474 }
475 }
476 sb->sv_ninodes = (sb->sv_firstdatazone - sb->sv_firstinodezone) << sb->sv_inodes_per_block_bits;
477 if (!silent)
478 printk("VFS: Found a %s FS (block size = %d) on device %d/%d\n",found,sb->sv_block_size,MAJOR(dev),MINOR(dev));
479 sb->s_magic = SYSV_MAGIC_BASE + sb->sv_type;
480
481 sb->s_blocksize = sb->sv_block_size;
482 sb->s_blocksize_bits = sb->sv_block_size_bits;
483
484 sb->s_dev = dev;
485 sb->s_op = &sysv_sops;
486 sb->s_mounted = iget(sb,SYSV_ROOT_INO);
487 unlock_super(sb);
488 if (!sb->s_mounted) {
489 printk("SysV FS: get root inode failed\n");
490 sysv_put_super(sb);
491 return NULL;
492 }
493 sb->s_dirt = 1;
494
495
496 return sb;
497 }
498
499
500 void sysv_write_super (struct super_block *sb)
501 {
502 lock_super(sb);
503 if (sb->sv_bh1->b_dirt || sb->sv_bh2->b_dirt) {
504
505
506 unsigned long time = CURRENT_TIME;
507 if (sb->sv_convert)
508 time = to_coh_ulong(time);
509 *sb->sv_sb_time = time;
510 mark_buffer_dirty(sb->sv_bh2, 1);
511 }
512 sb->s_dirt = 0;
513 unlock_super(sb);
514 }
515
516 void sysv_put_super(struct super_block *sb)
517 {
518
519 lock_super(sb);
520 brelse(sb->sv_bh1);
521 if (sb->sv_bh1 != sb->sv_bh2) brelse(sb->sv_bh2);
522
523 if (sb->s_blocksize != BLOCK_SIZE)
524 set_blocksize(sb->s_dev,BLOCK_SIZE);
525 sb->s_dev = 0;
526 unlock_super(sb);
527 MOD_DEC_USE_COUNT;
528 }
529
530 void sysv_statfs(struct super_block *sb, struct statfs *buf)
531 {
532 long tmp;
533
534 put_fs_long(sb->s_magic, &buf->f_type);
535 put_fs_long(sb->sv_block_size, &buf->f_bsize);
536 put_fs_long(sb->sv_ndatazones, &buf->f_blocks);
537 tmp = sysv_count_free_blocks(sb);
538 put_fs_long(tmp, &buf->f_bfree);
539 put_fs_long(tmp, &buf->f_bavail);
540 put_fs_long(sb->sv_ninodes, &buf->f_files);
541 put_fs_long(sysv_count_free_inodes(sb), &buf->f_ffree);
542 put_fs_long(SYSV_NAMELEN, &buf->f_namelen);
543
544 }
545
546
547
548
549 static inline int inode_bmap(struct super_block * sb, struct inode * inode, int nr)
550 {
551 int tmp = inode->u.sysv_i.i_data[nr];
552 if (!tmp)
553 return 0;
554 return tmp + sb->sv_block_base;
555 }
556
557 static int block_bmap(struct super_block * sb, struct buffer_head * bh, int nr, int convert)
558 {
559 int tmp;
560
561 if (!bh)
562 return 0;
563 tmp = ((sysv_zone_t *) bh->b_data) [nr];
564 if (convert)
565 tmp = from_coh_ulong(tmp);
566 brelse(bh);
567 if (!tmp)
568 return 0;
569 return tmp + sb->sv_block_base;
570 }
571
572 int sysv_bmap(struct inode * inode,int block_nr)
573 {
574 unsigned int block = block_nr;
575 struct super_block * sb = inode->i_sb;
576 int convert;
577 int i;
578 struct buffer_head * bh;
579
580 if (block < 10)
581 return inode_bmap(sb,inode,block);
582 block -= 10;
583 convert = sb->sv_convert;
584 if (block < sb->sv_ind_per_block) {
585 i = inode_bmap(sb,inode,10);
586 if (!i)
587 return 0;
588 bh = bread(inode->i_dev,i,sb->sv_block_size);
589 return block_bmap(sb, bh, block, convert);
590 }
591 block -= sb->sv_ind_per_block;
592 if (block < sb->sv_ind_per_block_2) {
593 i = inode_bmap(sb,inode,11);
594 if (!i)
595 return 0;
596 bh = bread(inode->i_dev,i,sb->sv_block_size);
597 i = block_bmap(sb, bh, block >> sb->sv_ind_per_block_bits, convert);
598 if (!i)
599 return 0;
600 bh = bread(inode->i_dev,i,sb->sv_block_size);
601 return block_bmap(sb, bh, block & sb->sv_ind_per_block_1, convert);
602 }
603 block -= sb->sv_ind_per_block_2;
604 if (block < sb->sv_ind_per_block_3) {
605 i = inode_bmap(sb,inode,12);
606 if (!i)
607 return 0;
608 bh = bread(inode->i_dev,i,sb->sv_block_size);
609 i = block_bmap(sb, bh, block >> sb->sv_ind_per_block_2_bits, convert);
610 if (!i)
611 return 0;
612 bh = bread(inode->i_dev,i,sb->sv_block_size);
613 i = block_bmap(sb, bh, (block >> sb->sv_ind_per_block_bits) & sb->sv_ind_per_block_1,convert);
614 if (!i)
615 return 0;
616 bh = bread(inode->i_dev,i,sb->sv_block_size);
617 return block_bmap(sb, bh, block & sb->sv_ind_per_block_1, convert);
618 }
619 if ((int)block<0) {
620 printk("sysv_bmap: block<0");
621 return 0;
622 }
623 printk("sysv_bmap: block>big");
624 return 0;
625 }
626
627
628
629
630
631
632 static struct buffer_head * inode_getblk(struct inode * inode, int nr, int create)
633 {
634 struct super_block *sb;
635 unsigned long tmp;
636 unsigned long *p;
637 struct buffer_head * result;
638
639 sb = inode->i_sb;
640 p = inode->u.sysv_i.i_data + nr;
641 repeat:
642 tmp = *p;
643 if (tmp) {
644 result = sv_getblk(sb, inode->i_dev, tmp);
645 if (tmp == *p)
646 return result;
647 brelse(result);
648 goto repeat;
649 }
650 if (!create)
651 return NULL;
652 tmp = sysv_new_block(sb);
653 if (!tmp)
654 return NULL;
655 result = sv_getblk(sb, inode->i_dev, tmp);
656 if (*p) {
657 sysv_free_block(sb,tmp);
658 brelse(result);
659 goto repeat;
660 }
661 *p = tmp;
662 inode->i_ctime = CURRENT_TIME;
663 inode->i_dirt = 1;
664 return result;
665 }
666
667 static struct buffer_head * block_getblk(struct inode * inode,
668 struct buffer_head * bh, int nr, int create)
669 {
670 struct super_block *sb;
671 unsigned long tmp, block;
672 sysv_zone_t *p;
673 struct buffer_head * result;
674
675 if (!bh)
676 return NULL;
677 if (!bh->b_uptodate) {
678 ll_rw_block(READ, 1, &bh);
679 wait_on_buffer(bh);
680 if (!bh->b_uptodate) {
681 brelse(bh);
682 return NULL;
683 }
684 }
685 sb = inode->i_sb;
686 p = nr + (sysv_zone_t *) bh->b_data;
687 repeat:
688 block = tmp = *p;
689 if (sb->sv_convert)
690 block = from_coh_ulong(block);
691 if (tmp) {
692 result = sv_getblk(sb, bh->b_dev, block);
693 if (tmp == *p) {
694 brelse(bh);
695 return result;
696 }
697 brelse(result);
698 goto repeat;
699 }
700 if (!create) {
701 brelse(bh);
702 return NULL;
703 }
704 block = sysv_new_block(sb);
705 if (!block) {
706 brelse(bh);
707 return NULL;
708 }
709 result = sv_getblk(sb, bh->b_dev, block);
710 if (*p) {
711 sysv_free_block(sb,block);
712 brelse(result);
713 goto repeat;
714 }
715 *p = (sb->sv_convert ? to_coh_ulong(block) : block);
716 mark_buffer_dirty(bh, 1);
717 brelse(bh);
718 return result;
719 }
720
721 struct buffer_head * sysv_getblk(struct inode * inode, unsigned int block, int create)
722 {
723 struct super_block * sb = inode->i_sb;
724 struct buffer_head * bh;
725
726 if (block < 10)
727 return inode_getblk(inode,block,create);
728 block -= 10;
729 if (block < sb->sv_ind_per_block) {
730 bh = inode_getblk(inode,10,create);
731 return block_getblk(inode, bh, block, create);
732 }
733 block -= sb->sv_ind_per_block;
734 if (block < sb->sv_ind_per_block_2) {
735 bh = inode_getblk(inode,11,create);
736 bh = block_getblk(inode, bh, block >> sb->sv_ind_per_block_bits, create);
737 return block_getblk(inode, bh, block & sb->sv_ind_per_block_1, create);
738 }
739 block -= sb->sv_ind_per_block_2;
740 if (block < sb->sv_ind_per_block_3) {
741 bh = inode_getblk(inode,12,create);
742 bh = block_getblk(inode, bh, block >> sb->sv_ind_per_block_2_bits, create);
743 bh = block_getblk(inode, bh, (block >> sb->sv_ind_per_block_bits) & sb->sv_ind_per_block_1, create);
744 return block_getblk(inode, bh, block & sb->sv_ind_per_block_1, create);
745 }
746 if ((int)block<0) {
747 printk("sysv_getblk: block<0");
748 return NULL;
749 }
750 printk("sysv_getblk: block>big");
751 return NULL;
752 }
753
754 struct buffer_head * sysv_file_bread(struct inode * inode, int block, int create)
755 {
756 struct buffer_head * bh;
757
758 bh = sysv_getblk(inode,block,create);
759 if (!bh || bh->b_uptodate)
760 return bh;
761 ll_rw_block(READ, 1, &bh);
762 wait_on_buffer(bh);
763 if (bh->b_uptodate)
764 return bh;
765 brelse(bh);
766 return NULL;
767 }
768
769
770 static inline unsigned long read3byte (char * p)
771 {
772 return (unsigned long)(*(unsigned short *)p)
773 | (unsigned long)(*(unsigned char *)(p+2)) << 16;
774 }
775
776 static inline void write3byte (char * p, unsigned long val)
777 {
778 *(unsigned short *)p = (unsigned short) val;
779 *(unsigned char *)(p+2) = val >> 16;
780 }
781
782 static inline unsigned long coh_read3byte (char * p)
783 {
784 return (unsigned long)(*(unsigned char *)p) << 16
785 | (unsigned long)(*(unsigned short *)(p+1));
786 }
787
788 static inline void coh_write3byte (char * p, unsigned long val)
789 {
790 *(unsigned char *)p = val >> 16;
791 *(unsigned short *)(p+1) = (unsigned short) val;
792 }
793
794 void sysv_read_inode(struct inode * inode)
795 {
796 struct super_block * sb = inode->i_sb;
797 struct buffer_head * bh;
798 struct sysv_inode * raw_inode;
799 unsigned int block, ino;
800 umode_t mode;
801
802 ino = inode->i_ino;
803 inode->i_op = NULL;
804 inode->i_mode = 0;
805 if (!ino || ino > sb->sv_ninodes) {
806 printk("Bad inode number on dev 0x%04x: %d is out of range\n",
807 inode->i_dev, ino);
808 return;
809 }
810 block = sb->sv_firstinodezone + ((ino-1) >> sb->sv_inodes_per_block_bits);
811 if (!(bh = sv_bread(sb,inode->i_dev,block))) {
812 printk("Major problem: unable to read inode from dev 0x%04x\n",
813 inode->i_dev);
814 return;
815 }
816 raw_inode = (struct sysv_inode *) bh->b_data + ((ino-1) & sb->sv_inodes_per_block_1);
817 mode = raw_inode->i_mode;
818 if (sb->sv_kludge_symlinks)
819 mode = from_coh_imode(mode);
820
821 inode->i_mode = mode;
822 inode->i_uid = raw_inode->i_uid;
823 inode->i_gid = raw_inode->i_gid;
824 inode->i_nlink = raw_inode->i_nlink;
825 if (sb->sv_convert) {
826 inode->i_size = from_coh_ulong(raw_inode->i_size);
827 inode->i_atime = from_coh_ulong(raw_inode->i_atime);
828 inode->i_mtime = from_coh_ulong(raw_inode->i_mtime);
829 inode->i_ctime = from_coh_ulong(raw_inode->i_ctime);
830 } else {
831 inode->i_size = raw_inode->i_size;
832 inode->i_atime = raw_inode->i_atime;
833 inode->i_mtime = raw_inode->i_mtime;
834 inode->i_ctime = raw_inode->i_ctime;
835 }
836 inode->i_blocks = inode->i_blksize = 0;
837 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
838 inode->i_rdev = raw_inode->i_a.i_rdev;
839 else
840 if (sb->sv_convert)
841 for (block = 0; block < 10+1+1+1; block++)
842 inode->u.sysv_i.i_data[block] =
843 coh_read3byte(&raw_inode->i_a.i_addb[3*block]);
844 else
845 for (block = 0; block < 10+1+1+1; block++)
846 inode->u.sysv_i.i_data[block] =
847 read3byte(&raw_inode->i_a.i_addb[3*block]);
848 brelse(bh);
849 if (S_ISREG(inode->i_mode))
850 inode->i_op = &sysv_file_inode_operations;
851 else if (S_ISDIR(inode->i_mode))
852 inode->i_op = &sysv_dir_inode_operations;
853 else if (S_ISLNK(inode->i_mode))
854 inode->i_op = &sysv_symlink_inode_operations;
855 else if (S_ISCHR(inode->i_mode))
856 inode->i_op = &chrdev_inode_operations;
857 else if (S_ISBLK(inode->i_mode))
858 inode->i_op = &blkdev_inode_operations;
859 else if (S_ISFIFO(inode->i_mode))
860 init_fifo(inode);
861 }
862
863
864 extern int sysv_notify_change(struct inode *inode, struct iattr *attr)
865 {
866 int error;
867
868 if ((error = inode_change_ok(inode, attr)) != 0)
869 return error;
870
871 if (attr->ia_valid & ATTR_MODE)
872 if (inode->i_sb->sv_kludge_symlinks)
873 if (attr->ia_mode == COH_KLUDGE_SYMLINK_MODE)
874 attr->ia_mode = COH_KLUDGE_NOT_SYMLINK;
875
876 inode_setattr(inode, attr);
877
878 return 0;
879 }
880
881 static struct buffer_head * sysv_update_inode(struct inode * inode)
882 {
883 struct super_block * sb = inode->i_sb;
884 struct buffer_head * bh;
885 struct sysv_inode * raw_inode;
886 unsigned int ino, block;
887 umode_t mode;
888
889 ino = inode->i_ino;
890 if (!ino || ino > sb->sv_ninodes) {
891 printk("Bad inode number on dev 0x%04x: %d is out of range\n",
892 inode->i_dev, ino);
893 inode->i_dirt = 0;
894 return 0;
895 }
896 block = sb->sv_firstinodezone + ((ino-1) >> sb->sv_inodes_per_block_bits);
897 if (!(bh = sv_bread(sb,inode->i_dev,block))) {
898 printk("unable to read i-node block\n");
899 inode->i_dirt = 0;
900 return 0;
901 }
902 raw_inode = (struct sysv_inode *) bh->b_data + ((ino-1) & sb->sv_inodes_per_block_1);
903 mode = inode->i_mode;
904 if (sb->sv_kludge_symlinks)
905 mode = to_coh_imode(mode);
906 raw_inode->i_mode = mode;
907 raw_inode->i_uid = inode->i_uid;
908 raw_inode->i_gid = inode->i_gid;
909 raw_inode->i_nlink = inode->i_nlink;
910 if (sb->sv_convert) {
911 raw_inode->i_size = to_coh_ulong(inode->i_size);
912 raw_inode->i_atime = to_coh_ulong(inode->i_atime);
913 raw_inode->i_mtime = to_coh_ulong(inode->i_mtime);
914 raw_inode->i_ctime = to_coh_ulong(inode->i_ctime);
915 } else {
916 raw_inode->i_size = inode->i_size;
917 raw_inode->i_atime = inode->i_atime;
918 raw_inode->i_mtime = inode->i_mtime;
919 raw_inode->i_ctime = inode->i_ctime;
920 }
921 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
922 raw_inode->i_a.i_rdev = inode->i_rdev;
923 else
924 if (sb->sv_convert)
925 for (block = 0; block < 10+1+1+1; block++)
926 coh_write3byte(&raw_inode->i_a.i_addb[3*block],inode->u.sysv_i.i_data[block]);
927 else
928 for (block = 0; block < 10+1+1+1; block++)
929 write3byte(&raw_inode->i_a.i_addb[3*block],inode->u.sysv_i.i_data[block]);
930 inode->i_dirt=0;
931 mark_buffer_dirty(bh, 1);
932 return bh;
933 }
934
935 void sysv_write_inode(struct inode * inode)
936 {
937 struct buffer_head *bh;
938 bh = sysv_update_inode(inode);
939 brelse(bh);
940 }
941
942 int sysv_sync_inode(struct inode * inode)
943 {
944 int err = 0;
945 struct buffer_head *bh;
946
947 bh = sysv_update_inode(inode);
948 if (bh && bh->b_dirt) {
949 ll_rw_block(WRITE, 1, &bh);
950 wait_on_buffer(bh);
951 if (bh->b_req && !bh->b_uptodate)
952 {
953 printk ("IO error syncing sysv inode [%04x:%08lx]\n",
954 inode->i_dev, inode->i_ino);
955 err = -1;
956 }
957 }
958 else if (!bh)
959 err = -1;
960 brelse (bh);
961 return err;
962 }
963
964 #ifdef MODULE
965
966
967
968 char kernel_version[] = UTS_RELEASE;
969
970 static struct file_system_type sysv_fs_type[3] = {
971 {sysv_read_super, "xenix", 1, NULL},
972 {sysv_read_super, "sysv", 1, NULL},
973 {sysv_read_super, "coherent", 1, NULL}
974 };
975
976 int init_module(void)
977 {
978 int i;
979
980 for (i = 0; i < 3; i++)
981 register_filesystem(&sysv_fs_type[i]);
982
983 return 0;
984 }
985
986 void cleanup_module(void)
987 {
988 int i;
989
990 if (MOD_IN_USE) {
991 printk("SysV FS cannot be removed, currently in use\n");
992 return;
993 }
994
995 for (i = 0; i < 3; i++)
996 unregister_filesystem(&sysv_fs_type[i]);
997 }
998
999 #endif