This source file includes following definitions.
- _coh_wait_on_inode
- sysv_put_inode
- detected_bs512
- detected_bs1024
- detect_xenix
- detect_sysv4
- detect_sysv2
- detect_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
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 void _coh_wait_on_inode (struct inode * inode)
34 {
35 struct wait_queue wait = { current, NULL };
36
37 add_wait_queue(&inode->u.sysv_i.i_wait, &wait);
38 repeat:
39 current->state = TASK_UNINTERRUPTIBLE;
40 if (inode->u.sysv_i.i_lock) {
41 schedule();
42 goto repeat;
43 }
44 remove_wait_queue(&inode->u.sysv_i.i_wait, &wait);
45 current->state = TASK_RUNNING;
46 }
47
48 void sysv_put_inode(struct inode *inode)
49 {
50 if (inode->i_nlink)
51 return;
52 inode->i_size = 0;
53 sysv_truncate(inode);
54 sysv_free_inode(inode);
55 }
56
57
58 static struct super_operations sysv_sops = {
59 sysv_read_inode,
60 sysv_notify_change,
61 sysv_write_inode,
62 sysv_put_inode,
63 sysv_put_super,
64 sysv_write_super,
65 sysv_statfs,
66 NULL
67 };
68
69
70
71
72
73
74
75
76
77
78 static void detected_bs512 (struct super_block *sb)
79 {
80 sb->sv_block_size = 512;
81 sb->sv_block_size_1 = 512-1;
82 sb->sv_block_size_bits = 9;
83 sb->sv_block_size_ratio = 2;
84 sb->sv_block_size_ratio_1 = 2-1;
85 sb->sv_block_size_ratio_bits = 1;
86 sb->sv_inodes_per_block = 512/64;
87 sb->sv_inodes_per_block_1 = 512/64-1;
88 sb->sv_inodes_per_block_bits = 9-6;
89 sb->sv_toobig_block = 10 +
90 (sb->sv_ind_per_block = 512/4) +
91 (sb->sv_ind_per_block_2 = (512/4)*(512/4)) +
92 (sb->sv_ind_per_block_3 = (512/4)*(512/4)*(512/4));
93 sb->sv_ind_per_block_1 = 512/4-1;
94 sb->sv_ind_per_block_2_1 = (512/4)*(512/4)-1;
95 sb->sv_ind_per_block_2_bits = 2 *
96 (sb->sv_ind_per_block_bits = 9-2);
97 }
98
99 static void detected_bs1024 (struct super_block *sb)
100 {
101 sb->sv_block_size = 1024;
102 sb->sv_block_size_1 = 1024-1;
103 sb->sv_block_size_bits = 10;
104 sb->sv_block_size_ratio = 1;
105 sb->sv_block_size_ratio_1 = 1-1;
106 sb->sv_block_size_ratio_bits = 0;
107 sb->sv_inodes_per_block = 1024/64;
108 sb->sv_inodes_per_block_1 = 1024/64-1;
109 sb->sv_inodes_per_block_bits = 10-6;
110 sb->sv_toobig_block = 10 +
111 (sb->sv_ind_per_block = 1024/4) +
112 (sb->sv_ind_per_block_2 = (1024/4)*(1024/4)) +
113 (sb->sv_ind_per_block_3 = (1024/4)*(1024/4)*(1024/4));
114 sb->sv_ind_per_block_1 = 1024/4-1;
115 sb->sv_ind_per_block_2_1 = (1024/4)*(1024/4)-1;
116 sb->sv_ind_per_block_2_bits = 2 *
117 (sb->sv_ind_per_block_bits = 10-2);
118 }
119
120 static const char* detect_xenix (struct super_block *sb, struct buffer_head *bh)
121 {
122 struct xenix_super_block * sbd;
123
124 sbd = (struct xenix_super_block *) bh->b_data;
125 if (sbd->s_magic != 0x2b5544)
126 return NULL;
127 sb->sv_type = FSTYPE_XENIX;
128 sb->sv_convert = 0;
129 sb->sv_kludge_symlinks = 1;
130 sb->sv_truncate = 1;
131 sb->sv_link_max = XENIX_LINK_MAX;
132 sb->sv_fic_size = XENIX_NICINOD;
133 sb->sv_flc_size = XENIX_NICFREE;
134 sb->sv_bh = bh;
135 sb->sv_sbd = (char *) sbd;
136 sb->sv_sb_fic_count = &sbd->s_ninode;
137 sb->sv_sb_fic_inodes = &sbd->s_inode[0];
138 sb->sv_sb_total_free_inodes = &sbd->s_tinode;
139 sb->sv_sb_flc_count = &sbd->s_nfree;
140 sb->sv_sb_flc_blocks = &sbd->s_free[0];
141 sb->sv_sb_total_free_blocks = &sbd->s_tfree;
142 sb->sv_sb_time = &sbd->s_time;
143 sb->sv_block_base = 0;
144 sb->sv_firstinodezone = 2;
145 sb->sv_firstdatazone = sbd->s_isize;
146 sb->sv_nzones = sbd->s_fsize;
147 sb->sv_ndatazones = sb->sv_nzones - sb->sv_firstdatazone;
148 switch (sbd->s_type) {
149 case 1: detected_bs512(sb); break;
150 case 2: detected_bs1024(sb); break;
151 default: return NULL;
152 }
153 return "Xenix";
154 }
155
156 static const char* detect_sysv4 (struct super_block *sb, struct buffer_head *bh)
157 {
158 struct sysv4_super_block * sbd;
159
160 sbd = (struct sysv4_super_block *) (bh->b_data + BLOCK_SIZE/2);
161 if (sbd->s_magic != 0xfd187e20)
162 return NULL;
163 if (sbd->s_time < 315532800)
164 return NULL;
165 sb->sv_type = FSTYPE_SYSV4;
166 sb->sv_convert = 0;
167 sb->sv_kludge_symlinks = 0;
168 sb->sv_truncate = 1;
169 sb->sv_link_max = SYSV_LINK_MAX;
170 sb->sv_fic_size = SYSV_NICINOD;
171 sb->sv_flc_size = SYSV_NICFREE;
172 sb->sv_bh = bh;
173 sb->sv_sbd = (char *) sbd;
174 sb->sv_sb_fic_count = &sbd->s_ninode;
175 sb->sv_sb_fic_inodes = &sbd->s_inode[0];
176 sb->sv_sb_total_free_inodes = &sbd->s_tinode;
177 sb->sv_sb_flc_count = &sbd->s_nfree;
178 sb->sv_sb_flc_blocks = &sbd->s_free[0];
179 sb->sv_sb_total_free_blocks = &sbd->s_tfree;
180 sb->sv_sb_time = &sbd->s_time;
181 sb->sv_block_base = 0;
182 sb->sv_firstinodezone = 2;
183 sb->sv_firstdatazone = sbd->s_isize;
184 sb->sv_nzones = sbd->s_fsize;
185 sb->sv_ndatazones = sb->sv_nzones - sb->sv_firstdatazone;
186 switch (sbd->s_type) {
187 case 1: detected_bs512(sb); break;
188 case 2: detected_bs1024(sb); break;
189 default: return NULL;
190 }
191 return "SystemV";
192 }
193
194 static const char* detect_sysv2 (struct super_block *sb, struct buffer_head *bh)
195 {
196 struct sysv2_super_block * sbd;
197
198 sbd = (struct sysv2_super_block *) (bh->b_data + BLOCK_SIZE/2);
199 if (sbd->s_magic != 0xfd187e20)
200 return NULL;
201 if (sbd->s_time < 315532800)
202 return NULL;
203 sb->sv_type = FSTYPE_SYSV2;
204 sb->sv_convert = 0;
205 sb->sv_kludge_symlinks = 0;
206 sb->sv_truncate = 1;
207 sb->sv_link_max = SYSV_LINK_MAX;
208 sb->sv_fic_size = SYSV_NICINOD;
209 sb->sv_flc_size = SYSV_NICFREE;
210 sb->sv_bh = bh;
211 sb->sv_sbd = (char *) sbd;
212 sb->sv_sb_fic_count = &sbd->s_ninode;
213 sb->sv_sb_fic_inodes = &sbd->s_inode[0];
214 sb->sv_sb_total_free_inodes = &sbd->s_tinode;
215 sb->sv_sb_flc_count = &sbd->s_nfree;
216 sb->sv_sb_flc_blocks = &sbd->s_free[0];
217 sb->sv_sb_total_free_blocks = &sbd->s_tfree;
218 sb->sv_sb_time = &sbd->s_time;
219 sb->sv_block_base = 0;
220 sb->sv_firstinodezone = 2;
221 sb->sv_firstdatazone = sbd->s_isize;
222 sb->sv_nzones = sbd->s_fsize;
223 sb->sv_ndatazones = sb->sv_nzones - sb->sv_firstdatazone;
224 switch (sbd->s_type) {
225 case 1: detected_bs512(sb); break;
226 case 2: detected_bs1024(sb); break;
227 default: return NULL;
228 }
229 return "SystemV Release 2";
230 }
231
232 static const char* detect_coherent (struct super_block *sb, struct buffer_head *bh)
233 {
234 struct coh_super_block * sbd;
235
236 sbd = (struct coh_super_block *) (bh->b_data + BLOCK_SIZE/2);
237 if ((memcmp(sbd->s_fname,"noname",6) && memcmp(sbd->s_fname,"xxxxx ",6))
238 || (memcmp(sbd->s_fpack,"nopack",6) && memcmp(sbd->s_fpack,"xxxxx\n",6)))
239 return NULL;
240 sb->sv_type = FSTYPE_COH;
241 sb->sv_convert = 1;
242 sb->sv_kludge_symlinks = 1;
243 sb->sv_truncate = 1;
244 sb->sv_link_max = COH_LINK_MAX;
245 sb->sv_fic_size = COH_NICINOD;
246 sb->sv_flc_size = COH_NICFREE;
247 sb->sv_bh = bh;
248 sb->sv_sbd = (char *) sbd;
249 sb->sv_sb_fic_count = &sbd->s_ninode;
250 sb->sv_sb_fic_inodes = &sbd->s_inode[0];
251 sb->sv_sb_total_free_inodes = &sbd->s_tinode;
252 sb->sv_sb_flc_count = &sbd->s_nfree;
253 sb->sv_sb_flc_blocks = &sbd->s_free[0];
254 sb->sv_sb_total_free_blocks = &sbd->s_tfree;
255 sb->sv_sb_time = &sbd->s_time;
256 sb->sv_block_base = 0;
257 sb->sv_firstinodezone = 2;
258 sb->sv_firstdatazone = sbd->s_isize;
259 sb->sv_nzones = from_coh_ulong(sbd->s_fsize);
260 sb->sv_ndatazones = sb->sv_nzones - sb->sv_firstdatazone;
261 detected_bs512(sb);
262 return "Coherent";
263 }
264
265 struct super_block *sysv_read_super(struct super_block *sb,void *data,
266 int silent)
267 {
268 struct buffer_head *bh;
269 const char *found;
270 int dev = sb->s_dev;
271
272 if (1024 != sizeof (struct xenix_super_block))
273 panic("Xenix FS: bad super-block size");
274 if ((512 != sizeof (struct sysv4_super_block))
275 || (512 != sizeof (struct sysv2_super_block)))
276 panic("SystemV FS: bad super-block size");
277 if (500 != sizeof (struct coh_super_block))
278 panic("Coherent FS: bad super-block size");
279 if (64 != sizeof (struct sysv_inode))
280 panic("sysv fs: bad i-node size");
281 lock_super(sb);
282 sb->s_blocksize = BLOCK_SIZE;
283 sb->s_blocksize_bits = BLOCK_SIZE_BITS;
284
285
286 if ((bh = bread(dev, 1, BLOCK_SIZE)) != NULL) {
287 if ((found = detect_xenix(sb,bh)) != NULL)
288 goto ok;
289 brelse(bh);
290 }
291 if ((bh = bread(dev, 0, BLOCK_SIZE)) != NULL) {
292
293 if ((found = detect_sysv4(sb,bh)) != NULL)
294 goto ok;
295 if ((found = detect_sysv2(sb,bh)) != NULL)
296 goto ok;
297
298 if ((found = detect_coherent(sb,bh)) != NULL)
299 goto ok;
300 brelse(bh);
301 }
302
303
304 { static int offsets[] = { 9, 15, 18, };
305 int i;
306 for (i = 0; i < sizeof(offsets)/sizeof(offsets[0]); i++)
307 if ((bh = bread(dev, offsets[i], BLOCK_SIZE)) != NULL) {
308
309 if ((found = detect_sysv2(sb,bh)) != NULL) {
310 sb->sv_block_base = offsets[i];
311 goto ok;
312 }
313 brelse(bh);
314 }
315 }
316 sb->s_dev=0;
317 unlock_super(sb);
318 if (!silent)
319 printk("VFS: unable to read Xenix/SystemV/Coherent superblock\n");
320 return NULL;
321
322 ok:
323 sb->sv_ninodes = (sb->sv_firstdatazone - sb->sv_firstinodezone) << sb->sv_inodes_per_block_bits;
324 if (!silent)
325 printk("VFS: Found a %s FS (block size = %d) on device %d/%d\n",found,sb->sv_block_size,MAJOR(dev),MINOR(dev));
326 sb->s_magic = SYSV_MAGIC_BASE + sb->sv_type;
327
328 sb->s_dev = dev;
329 sb->s_op = &sysv_sops;
330 sb->s_mounted = iget(sb,SYSV_ROOT_INO);
331 unlock_super(sb);
332 if (!sb->s_mounted) {
333 brelse(bh);
334 sb->s_dev = 0;
335 printk("SysV FS: get root inode failed\n");
336 return NULL;
337 }
338 sb->s_dirt = 1;
339 return sb;
340 }
341
342
343 void sysv_write_super (struct super_block *sb)
344 {
345 lock_super(sb);
346 if (sb->sv_bh->b_dirt) {
347
348
349 unsigned long time = CURRENT_TIME;
350 if (sb->sv_convert)
351 time = to_coh_ulong(time);
352 *sb->sv_sb_time = time;
353 }
354 sb->s_dirt = 0;
355 unlock_super(sb);
356 }
357
358 void sysv_put_super(struct super_block *sb)
359 {
360
361 lock_super(sb);
362 brelse(sb->sv_bh);
363 sb->s_dev = 0;
364 unlock_super(sb);
365 }
366
367 void sysv_statfs(struct super_block *sb, struct statfs *buf)
368 {
369 long tmp;
370
371 put_fs_long(sb->s_magic, &buf->f_type);
372 put_fs_long(sb->sv_block_size, &buf->f_bsize);
373 put_fs_long(sb->sv_ndatazones, &buf->f_blocks);
374 tmp = sysv_count_free_blocks(sb);
375 put_fs_long(tmp, &buf->f_bfree);
376 put_fs_long(tmp, &buf->f_bavail);
377 put_fs_long(sb->sv_ninodes, &buf->f_files);
378 put_fs_long(sysv_count_free_inodes(sb), &buf->f_ffree);
379 put_fs_long(SYSV_NAMELEN, &buf->f_namelen);
380
381 }
382
383
384
385
386
387 #define IND_PER_BLOCK (BLOCK_SIZE / sizeof(sysv_zone_t))
388
389 static inline int inode_bmap(struct super_block * sb, struct inode * inode, int nr)
390 {
391 int tmp = inode->u.sysv_i.i_data[nr];
392 if (!tmp)
393 return 0;
394 return tmp + sb->sv_block_base;
395 }
396
397 static int block_bmap(struct super_block * sb, struct buffer_head * bh, int nr, int convert)
398 {
399 int tmp;
400
401 if (!bh)
402 return 0;
403 tmp = ((sysv_zone_t *) bh->b_data) [nr];
404 if (convert)
405 tmp = from_coh_ulong(tmp);
406 brelse(bh);
407 if (!tmp)
408 return 0;
409 return tmp + sb->sv_block_base;
410 }
411
412 int sysv_bmap(struct inode * inode,int block_nr)
413 {
414 unsigned int block = block_nr;
415 struct super_block * sb = inode->i_sb;
416 int convert;
417 int i;
418 struct buffer_head * bh;
419
420 if (block < 10)
421 return inode_bmap(sb,inode,block);
422 block -= 10;
423 convert = sb->sv_convert;
424 if (block < IND_PER_BLOCK) {
425 i = inode_bmap(sb,inode,10);
426 if (!i)
427 return 0;
428 bh = bread(inode->i_dev,i,BLOCK_SIZE);
429 return block_bmap(sb,bh,block,convert);
430 }
431 block -= IND_PER_BLOCK;
432 if (block < IND_PER_BLOCK*IND_PER_BLOCK) {
433 i = inode_bmap(sb,inode,11);
434 if (!i)
435 return 0;
436 bh = bread(inode->i_dev,i,BLOCK_SIZE);
437 i = block_bmap(sb,bh,block/IND_PER_BLOCK,convert);
438 if (!i)
439 return 0;
440 bh = bread(inode->i_dev,i,BLOCK_SIZE);
441 return block_bmap(sb,bh,block%IND_PER_BLOCK,convert);
442 }
443 block -= IND_PER_BLOCK*IND_PER_BLOCK;
444 if (block < IND_PER_BLOCK*IND_PER_BLOCK*IND_PER_BLOCK) {
445 i = inode_bmap(sb,inode,12);
446 if (!i)
447 return 0;
448 bh = bread(inode->i_dev,i,BLOCK_SIZE);
449 i = block_bmap(sb,bh,block/(IND_PER_BLOCK*IND_PER_BLOCK),convert);
450 if (!i)
451 return 0;
452 bh = bread(inode->i_dev,i,BLOCK_SIZE);
453 i = block_bmap(sb,bh,(block/IND_PER_BLOCK)%IND_PER_BLOCK,convert);
454 if (!i)
455 return 0;
456 bh = bread(inode->i_dev,i,BLOCK_SIZE);
457 return block_bmap(sb,bh,block%IND_PER_BLOCK,convert);
458 }
459 if ((int)block<0) {
460 printk("sysv_bmap: block<0");
461 return 0;
462 }
463 printk("sysv_bmap: block>big");
464 return 0;
465 }
466
467
468
469
470
471
472 static struct buffer_head * inode_getblk(struct inode * inode, int nr, int create, char * *start)
473 {
474 struct super_block *sb;
475 unsigned long tmp;
476 unsigned long *p;
477 struct buffer_head * result;
478
479 sb = inode->i_sb;
480 p = inode->u.sysv_i.i_data + nr;
481 repeat:
482 tmp = *p;
483 if (tmp) {
484 result = getblk(inode->i_dev, (tmp >> sb->sv_block_size_ratio_bits) + sb->sv_block_base, BLOCK_SIZE);
485 if (tmp == *p) {
486 *start = result->b_data + ((tmp & sb->sv_block_size_ratio_1) << sb->sv_block_size_bits);
487 return result;
488 }
489 brelse(result);
490 goto repeat;
491 }
492 if (!create)
493 return NULL;
494 tmp = sysv_new_block(sb);
495 if (!tmp)
496 return NULL;
497 result = getblk(inode->i_dev, (tmp >> sb->sv_block_size_ratio_bits) + sb->sv_block_base, BLOCK_SIZE);
498 if (*p) {
499 sysv_free_block(sb,tmp);
500 brelse(result);
501 goto repeat;
502 }
503 *p = tmp;
504 inode->i_ctime = CURRENT_TIME;
505 inode->i_dirt = 1;
506 *start = result->b_data + ((tmp & sb->sv_block_size_ratio_1) << sb->sv_block_size_bits);
507 return result;
508 }
509
510 static struct buffer_head * block_getblk(struct inode * inode,
511 struct buffer_head * bh, int nr, int create, char * *start)
512 {
513 struct super_block *sb;
514 unsigned long tmp, block;
515 sysv_zone_t *p;
516 struct buffer_head * result;
517
518 if (!bh)
519 return NULL;
520 if (!bh->b_uptodate) {
521 ll_rw_block(READ, 1, &bh);
522 wait_on_buffer(bh);
523 if (!bh->b_uptodate) {
524 brelse(bh);
525 return NULL;
526 }
527 }
528 sb = inode->i_sb;
529 p = nr + (sysv_zone_t *) *start;
530 repeat:
531 block = tmp = *p;
532 if (sb->sv_convert)
533 block = from_coh_ulong(block);
534 if (tmp) {
535 result = getblk(bh->b_dev, (block >> sb->sv_block_size_ratio_bits) + sb->sv_block_base, BLOCK_SIZE);
536 if (tmp == *p) {
537 brelse(bh);
538 *start = result->b_data + ((block & sb->sv_block_size_ratio_1) << sb->sv_block_size_bits);
539 return result;
540 }
541 brelse(result);
542 goto repeat;
543 }
544 if (!create) {
545 brelse(bh);
546 return NULL;
547 }
548 block = sysv_new_block(sb);
549 if (!block) {
550 brelse(bh);
551 return NULL;
552 }
553 result = getblk(bh->b_dev, (block >> sb->sv_block_size_ratio_bits) + sb->sv_block_base, BLOCK_SIZE);
554 if (*p) {
555 sysv_free_block(sb,block);
556 brelse(result);
557 goto repeat;
558 }
559 *p = (sb->sv_convert ? to_coh_ulong(block) : block);
560 bh->b_dirt = 1;
561 brelse(bh);
562 *start = result->b_data + ((block & sb->sv_block_size_ratio_1) << sb->sv_block_size_bits);
563 return result;
564 }
565
566 struct buffer_head * sysv_getblk(struct inode * inode, unsigned int block,
567 int create, char * *start)
568 {
569 struct super_block * sb = inode->i_sb;
570 struct buffer_head * bh;
571
572 if (block < 10)
573 return inode_getblk(inode,block,create,start);
574 block -= 10;
575 if (block < sb->sv_ind_per_block) {
576 bh = inode_getblk(inode,10,create,start);
577 return block_getblk(inode, bh, block, create, start);
578 }
579 block -= sb->sv_ind_per_block;
580 if (block < sb->sv_ind_per_block_2) {
581 bh = inode_getblk(inode,11,create,start);
582 bh = block_getblk(inode, bh, block >> sb->sv_ind_per_block_bits, create, start);
583 return block_getblk(inode, bh, block & sb->sv_ind_per_block_1, create, start);
584 }
585 block -= sb->sv_ind_per_block_2;
586 if (block < sb->sv_ind_per_block_3) {
587 bh = inode_getblk(inode,12,create,start);
588 bh = block_getblk(inode, bh, block >> sb->sv_ind_per_block_2_bits, create, start);
589 bh = block_getblk(inode, bh, (block >> sb->sv_ind_per_block_bits) & sb->sv_ind_per_block_1, create, start);
590 return block_getblk(inode, bh, block & sb->sv_ind_per_block_1, create, start);
591 }
592 if ((int)block<0) {
593 printk("sysv_getblk: block<0");
594 return NULL;
595 }
596 printk("sysv_getblk: block>big");
597 return NULL;
598 }
599
600 struct buffer_head * sysv_file_bread(struct inode * inode, int block, int create, char * *start)
601 {
602 struct buffer_head * bh;
603
604 bh = sysv_getblk(inode,block,create,start);
605 if (!bh || bh->b_uptodate)
606 return bh;
607 ll_rw_block(READ, 1, &bh);
608 wait_on_buffer(bh);
609 if (bh->b_uptodate)
610 return bh;
611 brelse(bh);
612 return NULL;
613 }
614
615
616 static inline unsigned long read3byte (char * p)
617 {
618 return (unsigned long)(*(unsigned short *)p)
619 | (unsigned long)(*(unsigned char *)(p+2)) << 16;
620 }
621
622 static inline void write3byte (char * p, unsigned long val)
623 {
624 *(unsigned short *)p = (unsigned short) val;
625 *(unsigned char *)(p+2) = val >> 16;
626 }
627
628 static inline unsigned long coh_read3byte (char * p)
629 {
630 return (unsigned long)(*(unsigned char *)p) << 16
631 | (unsigned long)(*(unsigned short *)(p+1));
632 }
633
634 static inline void coh_write3byte (char * p, unsigned long val)
635 {
636 *(unsigned char *)p = val >> 16;
637 *(unsigned short *)(p+1) = (unsigned short) val;
638 }
639
640 void sysv_read_inode(struct inode * inode)
641 {
642 struct super_block * sb = inode->i_sb;
643 struct buffer_head * bh;
644 char * bh_data;
645 struct sysv_inode * raw_inode;
646 unsigned int block, ino;
647 umode_t mode;
648
649 ino = inode->i_ino;
650 inode->i_op = NULL;
651 inode->i_mode = 0;
652 if (!ino || ino > sb->sv_ninodes) {
653 printk("Bad inode number on dev 0x%04x: %d is out of range\n",
654 inode->i_dev, ino);
655 return;
656 }
657 block = sb->sv_firstinodezone + ((ino-1) >> sb->sv_inodes_per_block_bits);
658 if (!(bh=sysv_bread(sb,inode->i_dev,block,&bh_data))) {
659 printk("Major problem: unable to read inode from dev 0x%04x\n",
660 inode->i_dev);
661 return;
662 }
663 raw_inode = (struct sysv_inode *) bh_data + ((ino-1) & sb->sv_inodes_per_block_1);
664 mode = raw_inode->i_mode;
665 if (sb->sv_kludge_symlinks)
666 mode = from_coh_imode(mode);
667
668 inode->i_mode = mode;
669 inode->i_uid = raw_inode->i_uid;
670 inode->i_gid = raw_inode->i_gid;
671 inode->i_nlink = raw_inode->i_nlink;
672 if (sb->sv_convert) {
673 inode->i_size = from_coh_ulong(raw_inode->i_size);
674 inode->i_atime = from_coh_ulong(raw_inode->i_atime);
675 inode->i_mtime = from_coh_ulong(raw_inode->i_mtime);
676 inode->i_ctime = from_coh_ulong(raw_inode->i_ctime);
677 } else {
678 inode->i_size = raw_inode->i_size;
679 inode->i_atime = raw_inode->i_atime;
680 inode->i_mtime = raw_inode->i_mtime;
681 inode->i_ctime = raw_inode->i_ctime;
682 }
683 inode->i_blocks = inode->i_blksize = 0;
684 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
685 inode->i_rdev = raw_inode->i_a.i_rdev;
686 else
687 if (sb->sv_convert)
688 for (block = 0; block < 10+1+1+1; block++)
689 inode->u.sysv_i.i_data[block] =
690 coh_read3byte(&raw_inode->i_a.i_addb[3*block]);
691 else
692 for (block = 0; block < 10+1+1+1; block++)
693 inode->u.sysv_i.i_data[block] =
694 read3byte(&raw_inode->i_a.i_addb[3*block]);
695 brelse(bh);
696 if (S_ISREG(inode->i_mode))
697 if (sb->sv_block_size_ratio_bits == 0)
698 inode->i_op = &sysv_file_inode_operations_with_bmap;
699 else
700 inode->i_op = &sysv_file_inode_operations;
701 else if (S_ISDIR(inode->i_mode))
702 inode->i_op = &sysv_dir_inode_operations;
703 else if (S_ISLNK(inode->i_mode))
704 inode->i_op = &sysv_symlink_inode_operations;
705 else if (S_ISCHR(inode->i_mode))
706 inode->i_op = &chrdev_inode_operations;
707 else if (S_ISBLK(inode->i_mode))
708 inode->i_op = &blkdev_inode_operations;
709 else if (S_ISFIFO(inode->i_mode))
710 init_fifo(inode);
711 }
712
713
714 extern int sysv_notify_change(int flags, struct inode *inode)
715 {
716 if (flags & NOTIFY_MODE)
717 if (inode->i_sb->sv_kludge_symlinks)
718 if (inode->i_mode == COH_KLUDGE_SYMLINK_MODE) {
719 inode->i_mode = COH_KLUDGE_NOT_SYMLINK;
720 inode->i_dirt = 1;
721 }
722 return 0;
723 }
724
725 static struct buffer_head * sysv_update_inode(struct inode * inode)
726 {
727 struct super_block * sb = inode->i_sb;
728 struct buffer_head * bh;
729 char * bh_data;
730 struct sysv_inode * raw_inode;
731 unsigned int ino, block;
732 umode_t mode;
733
734 ino = inode->i_ino;
735 if (!ino || ino > sb->sv_ninodes) {
736 printk("Bad inode number on dev 0x%04x: %d is out of range\n",
737 inode->i_dev, ino);
738 inode->i_dirt = 0;
739 return 0;
740 }
741 block = sb->sv_firstinodezone + ((ino-1) >> sb->sv_inodes_per_block_bits);
742 if (!(bh = sysv_bread(sb,inode->i_dev,block,&bh_data))) {
743 printk("unable to read i-node block\n");
744 inode->i_dirt = 0;
745 return 0;
746 }
747 raw_inode = (struct sysv_inode *) bh_data + ((ino-1) & sb->sv_inodes_per_block_1);
748 mode = inode->i_mode;
749 if (sb->sv_kludge_symlinks)
750 mode = to_coh_imode(mode);
751 raw_inode->i_mode = mode;
752 raw_inode->i_uid = inode->i_uid;
753 raw_inode->i_gid = inode->i_gid;
754 raw_inode->i_nlink = inode->i_nlink;
755 if (sb->sv_convert) {
756 raw_inode->i_size = to_coh_ulong(inode->i_size);
757 raw_inode->i_atime = to_coh_ulong(inode->i_atime);
758 raw_inode->i_mtime = to_coh_ulong(inode->i_mtime);
759 raw_inode->i_ctime = to_coh_ulong(inode->i_ctime);
760 } else {
761 raw_inode->i_size = inode->i_size;
762 raw_inode->i_atime = inode->i_atime;
763 raw_inode->i_mtime = inode->i_mtime;
764 raw_inode->i_ctime = inode->i_ctime;
765 }
766 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
767 raw_inode->i_a.i_rdev = inode->i_rdev;
768 else
769 if (sb->sv_convert)
770 for (block = 0; block < 10+1+1+1; block++)
771 coh_write3byte(&raw_inode->i_a.i_addb[3*block],inode->u.sysv_i.i_data[block]);
772 else
773 for (block = 0; block < 10+1+1+1; block++)
774 write3byte(&raw_inode->i_a.i_addb[3*block],inode->u.sysv_i.i_data[block]);
775 inode->i_dirt=0;
776 bh->b_dirt=1;
777 return bh;
778 }
779
780 void sysv_write_inode(struct inode * inode)
781 {
782 struct buffer_head *bh;
783 bh = sysv_update_inode(inode);
784 brelse(bh);
785 }
786
787 int sysv_sync_inode(struct inode * inode)
788 {
789 int err = 0;
790 struct buffer_head *bh;
791
792 bh = sysv_update_inode(inode);
793 if (bh && bh->b_dirt) {
794 ll_rw_block(WRITE, 1, &bh);
795 wait_on_buffer(bh);
796 if (bh->b_req && !bh->b_uptodate)
797 {
798 printk ("IO error syncing sysv inode [%04x:%08lx]\n",
799 inode->i_dev, inode->i_ino);
800 err = -1;
801 }
802 }
803 else if (!bh)
804 err = -1;
805 brelse (bh);
806 return err;
807 }
808