2 * linux/fs/sysv/inode.c
5 * Copyright (C) 1991, 1992 Linus Torvalds
8 * Copyright (C) 1992 Doug Evans
11 * Copyright (C) 1993 Pascal Haible, Bruno Haible
14 * Copyright (C) 1993 Paul B. Monday
17 * Copyright (C) 1993 Bruno Haible
19 * This file contains code for allocating/freeing inodes and for read/writing
23 #include <linux/sched.h>
24 #include <linux/kernel.h>
26 #include <linux/sysv_fs.h>
27 #include <linux/stat.h>
28 #include <linux/string.h>
29 #include <linux/locks.h>
31 #include <asm/segment.h>
33 void _coh_wait_on_inode (struct inode
* inode
)
35 struct wait_queue wait
= { current
, NULL
};
37 add_wait_queue(&inode
->u
.sysv_i
.i_wait
, &wait
);
39 current
->state
= TASK_UNINTERRUPTIBLE
;
40 if (inode
->u
.sysv_i
.i_lock
) {
44 remove_wait_queue(&inode
->u
.sysv_i
.i_wait
, &wait
);
45 current
->state
= TASK_RUNNING
;
48 void sysv_put_inode(struct inode
*inode
)
54 sysv_free_inode(inode
);
58 static struct super_operations sysv_sops
= {
69 /* The following functions try to recognize specific filesystems.
71 * - Xenix FS by its magic number.
72 * - SystemV FS by its magic number.
73 * - Coherent FS by its funny fname/fpack field.
74 * We discriminate among SystemV4 and SystemV2 FS by the assumption that
75 * the time stamp is not < 01-01-1980.
78 static void detected_bs512 (struct super_block
*sb
)
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);
99 static void detected_bs1024 (struct super_block
*sb
)
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);
120 static const char* detect_xenix (struct super_block
*sb
, struct buffer_head
*bh
)
122 struct xenix_super_block
* sbd
;
124 sbd
= (struct xenix_super_block
*) bh
->b_data
;
125 if (sbd
->s_magic
!= 0x2b5544)
127 sb
->sv_type
= FSTYPE_XENIX
;
129 sb
->sv_kludge_symlinks
= 1;
131 sb
->sv_link_max
= XENIX_LINK_MAX
;
132 sb
->sv_fic_size
= XENIX_NICINOD
;
133 sb
->sv_flc_size
= XENIX_NICFREE
;
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
;
156 static const char* detect_sysv4 (struct super_block
*sb
, struct buffer_head
*bh
)
158 struct sysv4_super_block
* sbd
;
160 sbd
= (struct sysv4_super_block
*) (bh
->b_data
+ BLOCK_SIZE
/2);
161 if (sbd
->s_magic
!= 0xfd187e20)
163 if (sbd
->s_time
< 315532800) /* this is likely to happen on SystemV2 FS */
165 sb
->sv_type
= FSTYPE_SYSV4
;
167 sb
->sv_kludge_symlinks
= 0; /* ?? */
169 sb
->sv_link_max
= SYSV_LINK_MAX
;
170 sb
->sv_fic_size
= SYSV_NICINOD
;
171 sb
->sv_flc_size
= SYSV_NICFREE
;
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
;
194 static const char* detect_sysv2 (struct super_block
*sb
, struct buffer_head
*bh
)
196 struct sysv2_super_block
* sbd
;
198 sbd
= (struct sysv2_super_block
*) (bh
->b_data
+ BLOCK_SIZE
/2);
199 if (sbd
->s_magic
!= 0xfd187e20)
201 if (sbd
->s_time
< 315532800) /* this is likely to happen on SystemV4 FS */
203 sb
->sv_type
= FSTYPE_SYSV2
;
205 sb
->sv_kludge_symlinks
= 0; /* ?? */
207 sb
->sv_link_max
= SYSV_LINK_MAX
;
208 sb
->sv_fic_size
= SYSV_NICINOD
;
209 sb
->sv_flc_size
= SYSV_NICFREE
;
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
;
229 return "SystemV Release 2";
232 static const char* detect_coherent (struct super_block
*sb
, struct buffer_head
*bh
)
234 struct coh_super_block
* sbd
;
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)))
240 sb
->sv_type
= FSTYPE_COH
;
242 sb
->sv_kludge_symlinks
= 1;
244 sb
->sv_link_max
= COH_LINK_MAX
;
245 sb
->sv_fic_size
= COH_NICINOD
;
246 sb
->sv_flc_size
= COH_NICFREE
;
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
;
265 struct super_block
*sysv_read_super(struct super_block
*sb
,void *data
,
268 struct buffer_head
*bh
;
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");
282 sb
->s_blocksize
= BLOCK_SIZE
; /* anything else not supported by the block device drivers */
283 sb
->s_blocksize_bits
= BLOCK_SIZE_BITS
;
285 /* Try to read Xenix superblock */
286 if ((bh
= bread(dev
, 1, BLOCK_SIZE
)) != NULL
) {
287 if ((found
= detect_xenix(sb
,bh
)) != NULL
)
291 if ((bh
= bread(dev
, 0, BLOCK_SIZE
)) != NULL
) {
292 /* Try to recognize SystemV superblock */
293 if ((found
= detect_sysv4(sb
,bh
)) != NULL
)
295 if ((found
= detect_sysv2(sb
,bh
)) != NULL
)
297 /* Try to recognize Coherent superblock */
298 if ((found
= detect_coherent(sb
,bh
)) != NULL
)
302 /* Try to recognize SystemV2 superblock */
303 /* Offset by 1 track, i.e. most probably 9, 15, or 18 kilobytes. */
304 { static int offsets
[] = { 9, 15, 18, };
306 for (i
= 0; i
< sizeof(offsets
)/sizeof(offsets
[0]); i
++)
307 if ((bh
= bread(dev
, offsets
[i
], BLOCK_SIZE
)) != NULL
) {
308 /* Try to recognize SystemV superblock */
309 if ((found
= detect_sysv2(sb
,bh
)) != NULL
) {
310 sb
->sv_block_base
= offsets
[i
];
319 printk("VFS: unable to read Xenix/SystemV/Coherent superblock on device %d/%d\n",MAJOR(dev
),MINOR(dev
));
323 sb
->sv_ninodes
= (sb
->sv_firstdatazone
- sb
->sv_firstinodezone
) << sb
->sv_inodes_per_block_bits
;
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 /* set up enough so that it can read an inode */
329 sb
->s_op
= &sysv_sops
;
330 sb
->s_mounted
= iget(sb
,SYSV_ROOT_INO
);
332 if (!sb
->s_mounted
) {
335 printk("SysV FS: get root inode failed\n");
338 sb
->s_dirt
= 1; /* brelse(bh); occurs when the disk is unmounted. */
342 /* This is only called on sync() and umount(), when s_dirt=1. */
343 void sysv_write_super (struct super_block
*sb
)
346 if (sb
->sv_bh
->b_dirt
) {
347 /* If we are going to write out the super block,
348 then attach current time stamp. */
349 unsigned long time
= CURRENT_TIME
;
351 time
= to_coh_ulong(time
);
352 *sb
->sv_sb_time
= time
;
358 void sysv_put_super(struct super_block
*sb
)
360 /* we can assume sysv_write_super() has already been called */
367 void sysv_statfs(struct super_block
*sb
, struct statfs
*buf
)
371 put_fs_long(sb
->s_magic
, &buf
->f_type
); /* type of filesystem */
372 put_fs_long(sb
->sv_block_size
, &buf
->f_bsize
); /* block size */
373 put_fs_long(sb
->sv_ndatazones
, &buf
->f_blocks
); /* total data blocks in file system */
374 tmp
= sysv_count_free_blocks(sb
);
375 put_fs_long(tmp
, &buf
->f_bfree
); /* free blocks in fs */
376 put_fs_long(tmp
, &buf
->f_bavail
); /* free blocks available to non-superuser */
377 put_fs_long(sb
->sv_ninodes
, &buf
->f_files
); /* total file nodes in file system */
378 put_fs_long(sysv_count_free_inodes(sb
), &buf
->f_ffree
); /* free file nodes in fs */
379 put_fs_long(SYSV_NAMELEN
, &buf
->f_namelen
);
380 /* Don't know what value to put in buf->f_fsid */ /* file system id */
384 /* bmap support for running executables and shared libraries.
385 Used only if block_size = BLOCK_SIZE. */
387 #define IND_PER_BLOCK (BLOCK_SIZE / sizeof(sysv_zone_t))
389 static inline int inode_bmap(struct super_block
* sb
, struct inode
* inode
, int nr
)
391 int tmp
= inode
->u
.sysv_i
.i_data
[nr
];
394 return tmp
+ sb
->sv_block_base
;
397 static int block_bmap(struct super_block
* sb
, struct buffer_head
* bh
, int nr
, int convert
)
403 tmp
= ((sysv_zone_t
*) bh
->b_data
) [nr
];
405 tmp
= from_coh_ulong(tmp
);
409 return tmp
+ sb
->sv_block_base
;
412 int sysv_bmap(struct inode
* inode
,int block_nr
)
414 unsigned int block
= block_nr
;
415 struct super_block
* sb
= inode
->i_sb
;
418 struct buffer_head
* bh
;
421 return inode_bmap(sb
,inode
,block
);
423 convert
= sb
->sv_convert
;
424 if (block
< IND_PER_BLOCK
) {
425 i
= inode_bmap(sb
,inode
,10);
428 bh
= bread(inode
->i_dev
,i
,BLOCK_SIZE
);
429 return block_bmap(sb
,bh
,block
,convert
);
431 block
-= IND_PER_BLOCK
;
432 if (block
< IND_PER_BLOCK
*IND_PER_BLOCK
) {
433 i
= inode_bmap(sb
,inode
,11);
436 bh
= bread(inode
->i_dev
,i
,BLOCK_SIZE
);
437 i
= block_bmap(sb
,bh
,block
/IND_PER_BLOCK
,convert
);
440 bh
= bread(inode
->i_dev
,i
,BLOCK_SIZE
);
441 return block_bmap(sb
,bh
,block
%IND_PER_BLOCK
,convert
);
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);
448 bh
= bread(inode
->i_dev
,i
,BLOCK_SIZE
);
449 i
= block_bmap(sb
,bh
,block
/(IND_PER_BLOCK
*IND_PER_BLOCK
),convert
);
452 bh
= bread(inode
->i_dev
,i
,BLOCK_SIZE
);
453 i
= block_bmap(sb
,bh
,(block
/IND_PER_BLOCK
)%IND_PER_BLOCK
,convert
);
456 bh
= bread(inode
->i_dev
,i
,BLOCK_SIZE
);
457 return block_bmap(sb
,bh
,block
%IND_PER_BLOCK
,convert
);
460 printk("sysv_bmap: block<0");
463 printk("sysv_bmap: block>big");
467 /* End of bmap support. */
470 /* Access selected blocks of regular files (or directories) */
472 static struct buffer_head
* inode_getblk(struct inode
* inode
, int nr
, int create
, char * *start
)
474 struct super_block
*sb
;
477 struct buffer_head
* result
;
480 p
= inode
->u
.sysv_i
.i_data
+ nr
;
484 result
= getblk(inode
->i_dev
, (tmp
>> sb
->sv_block_size_ratio_bits
) + sb
->sv_block_base
, BLOCK_SIZE
);
486 *start
= result
->b_data
+ ((tmp
& sb
->sv_block_size_ratio_1
) << sb
->sv_block_size_bits
);
494 tmp
= sysv_new_block(sb
);
497 result
= getblk(inode
->i_dev
, (tmp
>> sb
->sv_block_size_ratio_bits
) + sb
->sv_block_base
, BLOCK_SIZE
);
499 sysv_free_block(sb
,tmp
);
504 inode
->i_ctime
= CURRENT_TIME
;
506 *start
= result
->b_data
+ ((tmp
& sb
->sv_block_size_ratio_1
) << sb
->sv_block_size_bits
);
510 static struct buffer_head
* block_getblk(struct inode
* inode
,
511 struct buffer_head
* bh
, int nr
, int create
, char * *start
)
513 struct super_block
*sb
;
514 unsigned long tmp
, block
;
516 struct buffer_head
* result
;
520 if (!bh
->b_uptodate
) {
521 ll_rw_block(READ
, 1, &bh
);
523 if (!bh
->b_uptodate
) {
529 p
= nr
+ (sysv_zone_t
*) *start
;
533 block
= from_coh_ulong(block
);
535 result
= getblk(bh
->b_dev
, (block
>> sb
->sv_block_size_ratio_bits
) + sb
->sv_block_base
, BLOCK_SIZE
);
538 *start
= result
->b_data
+ ((block
& sb
->sv_block_size_ratio_1
) << sb
->sv_block_size_bits
);
548 block
= sysv_new_block(sb
);
553 result
= getblk(bh
->b_dev
, (block
>> sb
->sv_block_size_ratio_bits
) + sb
->sv_block_base
, BLOCK_SIZE
);
555 sysv_free_block(sb
,block
);
559 *p
= (sb
->sv_convert
? to_coh_ulong(block
) : block
);
562 *start
= result
->b_data
+ ((block
& sb
->sv_block_size_ratio_1
) << sb
->sv_block_size_bits
);
566 struct buffer_head
* sysv_getblk(struct inode
* inode
, unsigned int block
,
567 int create
, char * *start
)
569 struct super_block
* sb
= inode
->i_sb
;
570 struct buffer_head
* bh
;
573 return inode_getblk(inode
,block
,create
,start
);
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
);
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
);
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
);
593 printk("sysv_getblk: block<0");
596 printk("sysv_getblk: block>big");
600 struct buffer_head
* sysv_file_bread(struct inode
* inode
, int block
, int create
, char * *start
)
602 struct buffer_head
* bh
;
604 bh
= sysv_getblk(inode
,block
,create
,start
);
605 if (!bh
|| bh
->b_uptodate
)
607 ll_rw_block(READ
, 1, &bh
);
616 static inline unsigned long read3byte (char * p
)
618 return (unsigned long)(*(unsigned short *)p
)
619 | (unsigned long)(*(unsigned char *)(p
+2)) << 16;
622 static inline void write3byte (char * p
, unsigned long val
)
624 *(unsigned short *)p
= (unsigned short) val
;
625 *(unsigned char *)(p
+2) = val
>> 16;
628 static inline unsigned long coh_read3byte (char * p
)
630 return (unsigned long)(*(unsigned char *)p
) << 16
631 | (unsigned long)(*(unsigned short *)(p
+1));
634 static inline void coh_write3byte (char * p
, unsigned long val
)
636 *(unsigned char *)p
= val
>> 16;
637 *(unsigned short *)(p
+1) = (unsigned short) val
;
640 void sysv_read_inode(struct inode
* inode
)
642 struct super_block
* sb
= inode
->i_sb
;
643 struct buffer_head
* bh
;
645 struct sysv_inode
* raw_inode
;
646 unsigned int block
, ino
;
652 if (!ino
|| ino
> sb
->sv_ninodes
) {
653 printk("Bad inode number on dev 0x%04x: %d is out of range\n",
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",
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 /* SystemV FS: kludge permissions if ino==SYSV_ROOT_INO ?? */
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
);
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
;
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
;
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
]);
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
]);
696 if (S_ISREG(inode
->i_mode
))
697 if (sb
->sv_block_size_ratio_bits
== 0) /* block_size == BLOCK_SIZE ? */
698 inode
->i_op
= &sysv_file_inode_operations_with_bmap
;
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
))
713 /* To avoid inconsistencies between inodes in memory and inodes on disk. */
714 extern int sysv_notify_change(int flags
, struct inode
*inode
)
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
;
725 static struct buffer_head
* sysv_update_inode(struct inode
* inode
)
727 struct super_block
* sb
= inode
->i_sb
;
728 struct buffer_head
* bh
;
730 struct sysv_inode
* raw_inode
;
731 unsigned int ino
, block
;
735 if (!ino
|| ino
> sb
->sv_ninodes
) {
736 printk("Bad inode number on dev 0x%04x: %d is out of range\n",
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");
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
);
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
;
766 if (S_ISCHR(inode
->i_mode
) || S_ISBLK(inode
->i_mode
))
767 raw_inode
->i_a
.i_rdev
= inode
->i_rdev
; /* write 2 or 3 bytes ?? */
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
]);
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
]);
780 void sysv_write_inode(struct inode
* inode
)
782 struct buffer_head
*bh
;
783 bh
= sysv_update_inode(inode
);
787 int sysv_sync_inode(struct inode
* inode
)
790 struct buffer_head
*bh
;
792 bh
= sysv_update_inode(inode
);
793 if (bh
&& bh
->b_dirt
) {
794 ll_rw_block(WRITE
, 1, &bh
);
796 if (bh
->b_req
&& !bh
->b_uptodate
)
798 printk ("IO error syncing sysv inode [%04x:%08lx]\n",
799 inode
->i_dev
, inode
->i_ino
);