2 * linux/fs/minix/inode.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
6 * Copyright (C) 1996 Gertjan van Wingerde (gertjan@cs.vu.nl)
9 * Modified for 680x0 by Andreas Schwab
12 #include <linux/module.h>
14 #include <linux/sched.h>
15 #include <linux/kernel.h>
17 #include <linux/malloc.h>
18 #include <linux/string.h>
19 #include <linux/stat.h>
20 #include <linux/locks.h>
21 #include <linux/init.h>
22 #include <linux/smp_lock.h>
24 #include <asm/system.h>
25 #include <asm/uaccess.h>
26 #include <asm/bitops.h>
28 #include <linux/minix_fs.h>
30 static void minix_read_inode(struct inode
* inode
);
31 static void minix_write_inode(struct inode
* inode
);
32 static int minix_statfs(struct super_block
*sb
, struct statfs
*buf
, int bufsiz
);
33 static int minix_remount (struct super_block
* sb
, int * flags
, char * data
);
35 static void minix_delete_inode(struct inode
*inode
)
38 minix_truncate(inode
);
39 minix_free_inode(inode
);
42 static void minix_commit_super(struct super_block
* sb
)
44 mark_buffer_dirty(sb
->u
.minix_sb
.s_sbh
, 1);
48 static void minix_write_super(struct super_block
* sb
)
50 struct minix_super_block
* ms
;
52 if (!(sb
->s_flags
& MS_RDONLY
)) {
53 ms
= sb
->u
.minix_sb
.s_ms
;
55 if (ms
->s_state
& MINIX_VALID_FS
)
56 ms
->s_state
&= ~MINIX_VALID_FS
;
57 minix_commit_super(sb
);
63 static void minix_put_super(struct super_block
*sb
)
67 if (!(sb
->s_flags
& MS_RDONLY
)) {
68 sb
->u
.minix_sb
.s_ms
->s_state
= sb
->u
.minix_sb
.s_mount_state
;
69 mark_buffer_dirty(sb
->u
.minix_sb
.s_sbh
, 1);
71 for (i
= 0; i
< sb
->u
.minix_sb
.s_imap_blocks
; i
++)
72 brelse(sb
->u
.minix_sb
.s_imap
[i
]);
73 for (i
= 0; i
< sb
->u
.minix_sb
.s_zmap_blocks
; i
++)
74 brelse(sb
->u
.minix_sb
.s_zmap
[i
]);
75 brelse (sb
->u
.minix_sb
.s_sbh
);
76 kfree(sb
->u
.minix_sb
.s_imap
);
82 static struct super_operations minix_sops
= {
87 NULL
, /* notify_change */
94 static int minix_remount (struct super_block
* sb
, int * flags
, char * data
)
96 struct minix_super_block
* ms
;
98 ms
= sb
->u
.minix_sb
.s_ms
;
99 if ((*flags
& MS_RDONLY
) == (sb
->s_flags
& MS_RDONLY
))
101 if (*flags
& MS_RDONLY
) {
102 if (ms
->s_state
& MINIX_VALID_FS
||
103 !(sb
->u
.minix_sb
.s_mount_state
& MINIX_VALID_FS
))
105 /* Mounting a rw partition read-only. */
106 ms
->s_state
= sb
->u
.minix_sb
.s_mount_state
;
107 mark_buffer_dirty(sb
->u
.minix_sb
.s_sbh
, 1);
109 minix_commit_super(sb
);
112 /* Mount a partition which is read-only, read-write. */
113 sb
->u
.minix_sb
.s_mount_state
= ms
->s_state
;
114 ms
->s_state
&= ~MINIX_VALID_FS
;
115 mark_buffer_dirty(sb
->u
.minix_sb
.s_sbh
, 1);
118 if (!(sb
->u
.minix_sb
.s_mount_state
& MINIX_VALID_FS
))
119 printk ("MINIX-fs warning: remounting unchecked fs, "
120 "running fsck is recommended.\n");
121 else if ((sb
->u
.minix_sb
.s_mount_state
& MINIX_ERROR_FS
))
122 printk ("MINIX-fs warning: remounting fs with errors, "
123 "running fsck is recommended.\n");
129 * Check the root directory of the filesystem to make sure
130 * it really _is_ a Minix filesystem, and to check the size
131 * of the directory entry.
133 static const char * minix_checkroot(struct super_block
*s
, struct inode
*dir
)
135 struct buffer_head
*bh
;
136 struct minix_dir_entry
*de
;
140 if (!S_ISDIR(dir
->i_mode
))
141 return "root directory is not a directory";
143 bh
= minix_bread(dir
, 0, 0);
145 return "unable to read root directory";
147 de
= (struct minix_dir_entry
*) bh
->b_data
;
148 errmsg
= "bad root directory '.' entry";
149 dirsize
= BLOCK_SIZE
;
150 if (de
->inode
== MINIX_ROOT_INO
&& strcmp(de
->name
, ".") == 0) {
151 errmsg
= "bad root directory '..' entry";
155 while ((dirsize
<<= 1) < BLOCK_SIZE
) {
156 de
= (struct minix_dir_entry
*) (bh
->b_data
+ dirsize
);
157 if (de
->inode
!= MINIX_ROOT_INO
)
159 if (strcmp(de
->name
, ".."))
161 s
->u
.minix_sb
.s_dirsize
= dirsize
;
162 s
->u
.minix_sb
.s_namelen
= dirsize
- 2;
170 static struct super_block
*minix_read_super(struct super_block
*s
, void *data
,
173 struct buffer_head
*bh
;
174 struct buffer_head
**map
;
175 struct minix_super_block
*ms
;
177 kdev_t dev
= s
->s_dev
;
179 struct inode
*root_inode
;
181 /* N.B. These should be compile-time tests.
182 Unfortunately that is impossible. */
183 if (32 != sizeof (struct minix_inode
))
184 panic("bad V1 i-node size");
185 if (64 != sizeof(struct minix2_inode
))
186 panic("bad V2 i-node size");
190 set_blocksize(dev
, BLOCK_SIZE
);
191 if (!(bh
= bread(dev
,1,BLOCK_SIZE
)))
194 ms
= (struct minix_super_block
*) bh
->b_data
;
195 s
->u
.minix_sb
.s_ms
= ms
;
196 s
->u
.minix_sb
.s_sbh
= bh
;
197 s
->u
.minix_sb
.s_mount_state
= ms
->s_state
;
198 s
->s_blocksize
= BLOCK_SIZE
;
199 s
->s_blocksize_bits
= BLOCK_SIZE_BITS
;
200 s
->u
.minix_sb
.s_ninodes
= ms
->s_ninodes
;
201 s
->u
.minix_sb
.s_nzones
= ms
->s_nzones
;
202 s
->u
.minix_sb
.s_imap_blocks
= ms
->s_imap_blocks
;
203 s
->u
.minix_sb
.s_zmap_blocks
= ms
->s_zmap_blocks
;
204 s
->u
.minix_sb
.s_firstdatazone
= ms
->s_firstdatazone
;
205 s
->u
.minix_sb
.s_log_zone_size
= ms
->s_log_zone_size
;
206 s
->u
.minix_sb
.s_max_size
= ms
->s_max_size
;
207 s
->s_magic
= ms
->s_magic
;
208 if (s
->s_magic
== MINIX_SUPER_MAGIC
) {
209 s
->u
.minix_sb
.s_version
= MINIX_V1
;
210 s
->u
.minix_sb
.s_dirsize
= 16;
211 s
->u
.minix_sb
.s_namelen
= 14;
212 s
->u
.minix_sb
.s_link_max
= MINIX_LINK_MAX
;
213 } else if (s
->s_magic
== MINIX_SUPER_MAGIC2
) {
214 s
->u
.minix_sb
.s_version
= MINIX_V1
;
215 s
->u
.minix_sb
.s_dirsize
= 32;
216 s
->u
.minix_sb
.s_namelen
= 30;
217 s
->u
.minix_sb
.s_link_max
= MINIX_LINK_MAX
;
218 } else if (s
->s_magic
== MINIX2_SUPER_MAGIC
) {
219 s
->u
.minix_sb
.s_version
= MINIX_V2
;
220 s
->u
.minix_sb
.s_nzones
= ms
->s_zones
;
221 s
->u
.minix_sb
.s_dirsize
= 16;
222 s
->u
.minix_sb
.s_namelen
= 14;
223 s
->u
.minix_sb
.s_link_max
= MINIX2_LINK_MAX
;
224 } else if (s
->s_magic
== MINIX2_SUPER_MAGIC2
) {
225 s
->u
.minix_sb
.s_version
= MINIX_V2
;
226 s
->u
.minix_sb
.s_nzones
= ms
->s_zones
;
227 s
->u
.minix_sb
.s_dirsize
= 32;
228 s
->u
.minix_sb
.s_namelen
= 30;
229 s
->u
.minix_sb
.s_link_max
= MINIX2_LINK_MAX
;
234 * Allocate the buffer map to keep the superblock small.
236 i
= (s
->u
.minix_sb
.s_imap_blocks
+ s
->u
.minix_sb
.s_zmap_blocks
) * sizeof(bh
);
237 map
= kmalloc(i
, GFP_KERNEL
);
241 s
->u
.minix_sb
.s_imap
= &map
[0];
242 s
->u
.minix_sb
.s_zmap
= &map
[s
->u
.minix_sb
.s_imap_blocks
];
245 for (i
=0 ; i
< s
->u
.minix_sb
.s_imap_blocks
; i
++) {
246 if (!(s
->u
.minix_sb
.s_imap
[i
]=bread(dev
,block
,BLOCK_SIZE
)))
250 for (i
=0 ; i
< s
->u
.minix_sb
.s_zmap_blocks
; i
++) {
251 if (!(s
->u
.minix_sb
.s_zmap
[i
]=bread(dev
,block
,BLOCK_SIZE
)))
256 minix_set_bit(0,s
->u
.minix_sb
.s_imap
[0]->b_data
);
257 minix_set_bit(0,s
->u
.minix_sb
.s_zmap
[0]->b_data
);
258 /* set up enough so that it can read an inode */
259 s
->s_op
= &minix_sops
;
260 root_inode
= iget(s
, MINIX_ROOT_INO
);
264 * Check the fs before we get the root dentry ...
266 errmsg
= minix_checkroot(s
, root_inode
);
270 s
->s_root
= d_alloc_root(root_inode
);
274 s
->s_root
->d_op
= &minix_dentry_operations
;
276 if (!(s
->s_flags
& MS_RDONLY
)) {
277 ms
->s_state
&= ~MINIX_VALID_FS
;
278 mark_buffer_dirty(bh
, 1);
282 if (!(s
->u
.minix_sb
.s_mount_state
& MINIX_VALID_FS
))
283 printk ("MINIX-fs: mounting unchecked file system, "
284 "running fsck is recommended.\n");
285 else if (s
->u
.minix_sb
.s_mount_state
& MINIX_ERROR_FS
)
286 printk ("MINIX-fs: mounting file system with errors, "
287 "running fsck is recommended.\n");
292 printk("MINIX-fs: %s\n", errmsg
);
299 printk("MINIX-fs: get root inode failed\n");
303 printk("MINIX-fs: bad superblock or unable to read bitmaps\n");
305 for (i
= 0; i
< s
->u
.minix_sb
.s_imap_blocks
; i
++)
306 brelse(s
->u
.minix_sb
.s_imap
[i
]);
307 for (i
= 0; i
< s
->u
.minix_sb
.s_zmap_blocks
; i
++)
308 brelse(s
->u
.minix_sb
.s_zmap
[i
]);
309 kfree(s
->u
.minix_sb
.s_imap
);
314 printk ("MINIX-fs: can't allocate map\n");
319 printk("VFS: Can't find a Minix or Minix V2 filesystem on device "
320 "%s.\n", kdevname(dev
));
326 printk("MINIX-fs: unable to read superblock\n");
334 static int minix_statfs(struct super_block
*sb
, struct statfs
*buf
, int bufsiz
)
338 tmp
.f_type
= sb
->s_magic
;
339 tmp
.f_bsize
= sb
->s_blocksize
;
340 tmp
.f_blocks
= (sb
->u
.minix_sb
.s_nzones
- sb
->u
.minix_sb
.s_firstdatazone
) << sb
->u
.minix_sb
.s_log_zone_size
;
341 tmp
.f_bfree
= minix_count_free_blocks(sb
);
342 tmp
.f_bavail
= tmp
.f_bfree
;
343 tmp
.f_files
= sb
->u
.minix_sb
.s_ninodes
;
344 tmp
.f_ffree
= minix_count_free_inodes(sb
);
345 tmp
.f_namelen
= sb
->u
.minix_sb
.s_namelen
;
346 return copy_to_user(buf
, &tmp
, bufsiz
) ? -EFAULT
: 0;
350 * The minix V1 fs bmap functions.
352 #define V1_inode_bmap(inode,nr) (((unsigned short *)(inode)->u.minix_i.u.i1_data)[(nr)])
354 static int V1_block_bmap(struct buffer_head
* bh
, int nr
)
360 tmp
= ((unsigned short *) bh
->b_data
)[nr
];
365 static int V1_minix_block_map(struct inode
* inode
, long block
)
372 printk("minix_bmap: block<0");
375 if (block
>= (inode
->i_sb
->u
.minix_sb
.s_max_size
/BLOCK_SIZE
)) {
376 printk("minix_bmap: block>big");
380 ret
= V1_inode_bmap(inode
,block
);
385 i
= V1_inode_bmap(inode
,7);
388 ret
= V1_block_bmap(bread(inode
->i_dev
, i
,
393 i
= V1_inode_bmap(inode
,8);
396 i
= V1_block_bmap(bread(inode
->i_dev
,i
,BLOCK_SIZE
),block
>>9);
399 ret
= V1_block_bmap(bread(inode
->i_dev
, i
, BLOCK_SIZE
),
407 * The minix V2 fs bmap functions.
409 #define V2_inode_bmap(inode,nr) (((unsigned int *)(inode)->u.minix_i.u.i2_data)[(nr)])
410 static int V2_block_bmap(struct buffer_head
* bh
, int nr
)
416 tmp
= ((unsigned int *) bh
->b_data
)[nr
];
421 static int V2_minix_block_map(struct inode
* inode
, int block
)
428 printk("minix_bmap: block<0");
431 if (block
>= (inode
->i_sb
->u
.minix_sb
.s_max_size
/BLOCK_SIZE
)) {
432 printk("minix_bmap: block>big");
436 ret
= V2_inode_bmap(inode
,block
);
441 i
= V2_inode_bmap(inode
, 7);
444 ret
= V2_block_bmap(bread(inode
->i_dev
, i
,
449 if (block
< (256 * 256)) {
450 i
= V2_inode_bmap(inode
, 8);
453 i
= V2_block_bmap(bread(inode
->i_dev
, i
, BLOCK_SIZE
),
457 ret
= V2_block_bmap(bread(inode
->i_dev
, i
, BLOCK_SIZE
),
461 block
-= (256 * 256);
462 i
= V2_inode_bmap(inode
, 9);
465 i
= V2_block_bmap(bread(inode
->i_dev
, i
, BLOCK_SIZE
),
469 i
= V2_block_bmap(bread(inode
->i_dev
, i
, BLOCK_SIZE
),
473 ret
= V2_block_bmap(bread(inode
->i_dev
, i
, BLOCK_SIZE
),
481 * The minix V1 fs getblk functions.
483 static struct buffer_head
* V1_inode_getblk(struct inode
* inode
, int nr
,
484 int new_block
, int *err
,
485 int metadata
, int *phys
, int *new)
489 struct buffer_head
* result
;
491 p
= inode
->u
.minix_i
.u
.i1_data
+ nr
;
496 result
= getblk(inode
->i_dev
, tmp
, BLOCK_SIZE
);
508 /* Check file limits.. */
510 unsigned long limit
= current
->rlim
[RLIMIT_FSIZE
].rlim_cur
;
511 if (limit
< RLIM_INFINITY
) {
512 limit
>>= BLOCK_SIZE_BITS
;
513 if (new_block
>= limit
) {
514 send_sig(SIGXFSZ
, current
, 0);
521 tmp
= minix_new_block(inode
);
527 result
= getblk(inode
->i_dev
, tmp
, BLOCK_SIZE
);
529 minix_free_block(inode
, tmp
);
533 memset(result
->b_data
, 0, BLOCK_SIZE
);
534 mark_buffer_uptodate(result
, 1);
535 mark_buffer_dirty(result
, 1);
539 * Nobody is allowed to change block allocation
540 * state from under us:
543 minix_free_block(inode
, tmp
);
553 inode
->i_ctime
= CURRENT_TIME
;
554 mark_inode_dirty(inode
);
558 static struct buffer_head
* V1_block_getblk(struct inode
* inode
,
559 struct buffer_head
* bh
, int nr
, int new_block
, int *err
,
560 int metadata
, int *phys
, int *new)
564 struct buffer_head
* result
;
570 if (!buffer_uptodate(bh
)) {
571 ll_rw_block(READ
, 1, &bh
);
573 if (!buffer_uptodate(bh
))
576 p
= nr
+ (unsigned short *) bh
->b_data
;
581 result
= getblk(bh
->b_dev
, tmp
, BLOCK_SIZE
);
593 limit
= current
->rlim
[RLIMIT_FSIZE
].rlim_cur
;
594 if (limit
< RLIM_INFINITY
) {
595 limit
>>= BLOCK_SIZE_BITS
;
596 if (new_block
>= limit
) {
597 send_sig(SIGXFSZ
, current
, 0);
602 tmp
= minix_new_block(inode
);
606 result
= getblk(bh
->b_dev
, tmp
, BLOCK_SIZE
);
608 minix_free_block(inode
, tmp
);
612 memset(result
->b_data
, 0, BLOCK_SIZE
);
613 mark_buffer_uptodate(result
, 1);
614 mark_buffer_dirty(result
, 1);
620 minix_free_block(inode
, tmp
);
626 mark_buffer_dirty(bh
, 1);
633 static int V1_get_block(struct inode
* inode
, long block
,
634 struct buffer_head
*bh_result
, int create
)
636 int ret
, err
, new, phys
, ptr
;
637 struct buffer_head
*bh
;
640 phys
= V1_minix_block_map(inode
, block
);
642 bh_result
->b_dev
= inode
->i_dev
;
643 bh_result
->b_blocknr
= phys
;
644 bh_result
->b_state
|= (1UL << BH_Mapped
);
657 if (block
>= inode
->i_sb
->u
.minix_sb
.s_max_size
/BLOCK_SIZE
)
663 * ok, these macros clean the logic up a bit and make
664 * it much more readable:
666 #define GET_INODE_DATABLOCK(x) \
667 V1_inode_getblk(inode, x, block, &err, 0, &phys, &new)
668 #define GET_INODE_PTR(x) \
669 V1_inode_getblk(inode, x, block, &err, 1, NULL, NULL)
670 #define GET_INDIRECT_DATABLOCK(x) \
671 V1_block_getblk(inode, bh, x, block, &err, 0, &phys, &new)
672 #define GET_INDIRECT_PTR(x) \
673 V1_block_getblk(inode, bh, x, block, &err, 1, NULL, NULL)
676 bh
= GET_INODE_DATABLOCK(ptr
);
681 bh
= GET_INODE_PTR(7);
685 bh
= GET_INODE_PTR(8);
686 bh
= GET_INDIRECT_PTR((ptr
>> 9) & 511);
688 bh
= GET_INDIRECT_DATABLOCK(ptr
& 511);
690 #undef GET_INODE_DATABLOCK
692 #undef GET_INDIRECT_DATABLOCK
693 #undef GET_INDIRECT_PTR
698 bh_result
->b_dev
= inode
->i_dev
;
699 bh_result
->b_blocknr
= phys
;
700 bh_result
->b_state
|= (1UL << BH_Mapped
);
702 bh_result
->b_state
|= (1UL << BH_New
);
708 printk("minix_getblk: block<0");
712 printk("minix_getblk: block>big");
717 * The minix V2 fs getblk functions.
719 static struct buffer_head
* V2_inode_getblk(struct inode
* inode
, int nr
,
720 int new_block
, int *err
,
721 int metadata
, int *phys
, int *new)
725 struct buffer_head
* result
;
727 p
= (unsigned int *) inode
->u
.minix_i
.u
.i2_data
+ nr
;
732 result
= getblk(inode
->i_dev
, tmp
, BLOCK_SIZE
);
744 /* Check file limits.. */
746 unsigned long limit
= current
->rlim
[RLIMIT_FSIZE
].rlim_cur
;
747 if (limit
< RLIM_INFINITY
) {
748 limit
>>= BLOCK_SIZE_BITS
;
749 if (new_block
>= limit
) {
750 send_sig(SIGXFSZ
, current
, 0);
757 tmp
= minix_new_block(inode
);
763 result
= getblk(inode
->i_dev
, tmp
, BLOCK_SIZE
);
765 minix_free_block(inode
, tmp
);
769 memset(result
->b_data
, 0, BLOCK_SIZE
);
770 mark_buffer_uptodate(result
, 1);
771 mark_buffer_dirty(result
, 1);
775 * Nobody is allowed to change block allocation
776 * state from under us:
779 minix_free_block(inode
, tmp
);
789 inode
->i_ctime
= CURRENT_TIME
;
790 mark_inode_dirty(inode
);
794 static struct buffer_head
* V2_block_getblk(struct inode
* inode
,
795 struct buffer_head
* bh
, int nr
, int new_block
, int *err
,
796 int metadata
, int *phys
, int *new)
800 struct buffer_head
* result
;
806 if (!buffer_uptodate(bh
)) {
807 ll_rw_block(READ
, 1, &bh
);
809 if (!buffer_uptodate(bh
))
812 p
= nr
+ (unsigned int *) bh
->b_data
;
817 result
= getblk(bh
->b_dev
, tmp
, BLOCK_SIZE
);
829 limit
= current
->rlim
[RLIMIT_FSIZE
].rlim_cur
;
830 if (limit
< RLIM_INFINITY
) {
831 limit
>>= BLOCK_SIZE_BITS
;
832 if (new_block
>= limit
) {
833 send_sig(SIGXFSZ
, current
, 0);
838 tmp
= minix_new_block(inode
);
842 result
= getblk(bh
->b_dev
, tmp
, BLOCK_SIZE
);
844 minix_free_block(inode
, tmp
);
848 memset(result
->b_data
, 0, BLOCK_SIZE
);
849 mark_buffer_uptodate(result
, 1);
850 mark_buffer_dirty(result
, 1);
856 minix_free_block(inode
, tmp
);
862 mark_buffer_dirty(bh
, 1);
869 static int V2_get_block(struct inode
* inode
, long block
,
870 struct buffer_head
*bh_result
, int create
)
872 int ret
, err
, new, phys
, ptr
;
873 struct buffer_head
* bh
;
876 phys
= V2_minix_block_map(inode
, block
);
878 bh_result
->b_dev
= inode
->i_dev
;
879 bh_result
->b_blocknr
= phys
;
880 bh_result
->b_state
|= (1UL << BH_Mapped
);
893 if (block
>= inode
->i_sb
->u
.minix_sb
.s_max_size
/BLOCK_SIZE
)
899 * ok, these macros clean the logic up a bit and make
900 * it much more readable:
902 #define GET_INODE_DATABLOCK(x) \
903 V2_inode_getblk(inode, x, block, &err, 0, &phys, &new)
904 #define GET_INODE_PTR(x) \
905 V2_inode_getblk(inode, x, block, &err, 1, NULL, NULL)
906 #define GET_INDIRECT_DATABLOCK(x) \
907 V2_block_getblk(inode, bh, x, block, &err, 0, &phys, &new)
908 #define GET_INDIRECT_PTR(x) \
909 V2_block_getblk(inode, bh, x, block, &err, 1, NULL, NULL)
912 bh
= GET_INODE_DATABLOCK(ptr
);
917 bh
= GET_INODE_PTR(7);
922 bh
= GET_INODE_PTR(8);
926 bh
= GET_INODE_PTR(9);
927 bh
= GET_INDIRECT_PTR((ptr
>> 16) & 255);
929 bh
= GET_INDIRECT_PTR((ptr
>> 8) & 255);
931 bh
= GET_INDIRECT_DATABLOCK(ptr
& 255);
933 #undef GET_INODE_DATABLOCK
935 #undef GET_INDIRECT_DATABLOCK
936 #undef GET_INDIRECT_PTR
941 bh_result
->b_dev
= inode
->i_dev
;
942 bh_result
->b_blocknr
= phys
;
943 bh_result
->b_state
|= (1UL << BH_Mapped
);
945 bh_result
->b_state
|= (1UL << BH_New
);
951 printk("minix_getblk: block<0");
955 printk("minix_getblk: block>big");
959 int minix_get_block(struct inode
*inode
, long block
,
960 struct buffer_head
*bh_result
, int create
)
962 if (INODE_VERSION(inode
) == MINIX_V1
)
963 return V1_get_block(inode
, block
, bh_result
, create
);
965 return V2_get_block(inode
, block
, bh_result
, create
);
969 * the global minix fs getblk function.
971 struct buffer_head
*minix_getblk(struct inode
*inode
, int block
, int create
)
973 struct buffer_head dummy
;
977 dummy
.b_blocknr
= -1000;
978 error
= minix_get_block(inode
, block
, &dummy
, create
);
979 if (!error
&& buffer_mapped(&dummy
)) {
980 struct buffer_head
*bh
;
981 bh
= getblk(dummy
.b_dev
, dummy
.b_blocknr
, BLOCK_SIZE
);
982 if (buffer_new(&dummy
)) {
983 memset(bh
->b_data
, 0, BLOCK_SIZE
);
984 mark_buffer_uptodate(bh
, 1);
985 mark_buffer_dirty(bh
, 1);
992 struct buffer_head
* minix_bread(struct inode
* inode
, int block
, int create
)
994 struct buffer_head
* bh
;
996 bh
= minix_getblk(inode
, block
, create
);
997 if (!bh
|| buffer_uptodate(bh
))
999 ll_rw_block(READ
, 1, &bh
);
1001 if (buffer_uptodate(bh
))
1008 * The minix V1 function to read an inode.
1010 static void V1_minix_read_inode(struct inode
* inode
)
1012 struct buffer_head
* bh
;
1013 struct minix_inode
* raw_inode
;
1019 if (!ino
|| ino
> inode
->i_sb
->u
.minix_sb
.s_ninodes
) {
1020 printk("Bad inode number on dev %s"
1021 ": %d is out of range\n",
1022 kdevname(inode
->i_dev
), ino
);
1025 block
= 2 + inode
->i_sb
->u
.minix_sb
.s_imap_blocks
+
1026 inode
->i_sb
->u
.minix_sb
.s_zmap_blocks
+
1027 (ino
-1)/MINIX_INODES_PER_BLOCK
;
1028 if (!(bh
=bread(inode
->i_dev
,block
, BLOCK_SIZE
))) {
1029 printk("Major problem: unable to read inode from dev "
1030 "%s\n", kdevname(inode
->i_dev
));
1033 raw_inode
= ((struct minix_inode
*) bh
->b_data
) +
1034 (ino
-1)%MINIX_INODES_PER_BLOCK
;
1035 inode
->i_mode
= raw_inode
->i_mode
;
1036 inode
->i_uid
= raw_inode
->i_uid
;
1037 inode
->i_gid
= raw_inode
->i_gid
;
1038 inode
->i_nlink
= raw_inode
->i_nlinks
;
1039 inode
->i_size
= raw_inode
->i_size
;
1040 inode
->i_mtime
= inode
->i_atime
= inode
->i_ctime
= raw_inode
->i_time
;
1041 inode
->i_blocks
= inode
->i_blksize
= 0;
1042 for (block
= 0; block
< 9; block
++)
1043 inode
->u
.minix_i
.u
.i1_data
[block
] = raw_inode
->i_zone
[block
];
1044 if (S_ISREG(inode
->i_mode
))
1045 inode
->i_op
= &minix_file_inode_operations
;
1046 else if (S_ISDIR(inode
->i_mode
))
1047 inode
->i_op
= &minix_dir_inode_operations
;
1048 else if (S_ISLNK(inode
->i_mode
))
1049 inode
->i_op
= &minix_symlink_inode_operations
;
1051 init_special_inode(inode
, inode
->i_mode
, raw_inode
->i_zone
[0]);
1056 * The minix V2 function to read an inode.
1058 static void V2_minix_read_inode(struct inode
* inode
)
1060 struct buffer_head
* bh
;
1061 struct minix2_inode
* raw_inode
;
1067 if (!ino
|| ino
> inode
->i_sb
->u
.minix_sb
.s_ninodes
) {
1068 printk("Bad inode number on dev %s"
1069 ": %d is out of range\n",
1070 kdevname(inode
->i_dev
), ino
);
1073 block
= 2 + inode
->i_sb
->u
.minix_sb
.s_imap_blocks
+
1074 inode
->i_sb
->u
.minix_sb
.s_zmap_blocks
+
1075 (ino
-1)/MINIX2_INODES_PER_BLOCK
;
1076 if (!(bh
=bread(inode
->i_dev
,block
, BLOCK_SIZE
))) {
1077 printk("Major problem: unable to read inode from dev "
1078 "%s\n", kdevname(inode
->i_dev
));
1081 raw_inode
= ((struct minix2_inode
*) bh
->b_data
) +
1082 (ino
-1)%MINIX2_INODES_PER_BLOCK
;
1083 inode
->i_mode
= raw_inode
->i_mode
;
1084 inode
->i_uid
= raw_inode
->i_uid
;
1085 inode
->i_gid
= raw_inode
->i_gid
;
1086 inode
->i_nlink
= raw_inode
->i_nlinks
;
1087 inode
->i_size
= raw_inode
->i_size
;
1088 inode
->i_mtime
= raw_inode
->i_mtime
;
1089 inode
->i_atime
= raw_inode
->i_atime
;
1090 inode
->i_ctime
= raw_inode
->i_ctime
;
1091 inode
->i_blocks
= inode
->i_blksize
= 0;
1092 for (block
= 0; block
< 10; block
++)
1093 inode
->u
.minix_i
.u
.i2_data
[block
] = raw_inode
->i_zone
[block
];
1094 if (S_ISREG(inode
->i_mode
))
1095 inode
->i_op
= &minix_file_inode_operations
;
1096 else if (S_ISDIR(inode
->i_mode
))
1097 inode
->i_op
= &minix_dir_inode_operations
;
1098 else if (S_ISLNK(inode
->i_mode
))
1099 inode
->i_op
= &minix_symlink_inode_operations
;
1101 init_special_inode(inode
, inode
->i_mode
, raw_inode
->i_zone
[0]);
1106 * The global function to read an inode.
1108 static void minix_read_inode(struct inode
* inode
)
1110 if (INODE_VERSION(inode
) == MINIX_V1
)
1111 V1_minix_read_inode(inode
);
1113 V2_minix_read_inode(inode
);
1117 * The minix V1 function to synchronize an inode.
1119 static struct buffer_head
* V1_minix_update_inode(struct inode
* inode
)
1121 struct buffer_head
* bh
;
1122 struct minix_inode
* raw_inode
;
1126 if (!ino
|| ino
> inode
->i_sb
->u
.minix_sb
.s_ninodes
) {
1127 printk("Bad inode number on dev %s"
1128 ": %d is out of range\n",
1129 kdevname(inode
->i_dev
), ino
);
1132 block
= 2 + inode
->i_sb
->u
.minix_sb
.s_imap_blocks
+ inode
->i_sb
->u
.minix_sb
.s_zmap_blocks
+
1133 (ino
-1)/MINIX_INODES_PER_BLOCK
;
1134 if (!(bh
=bread(inode
->i_dev
, block
, BLOCK_SIZE
))) {
1135 printk("unable to read i-node block\n");
1138 raw_inode
= ((struct minix_inode
*)bh
->b_data
) +
1139 (ino
-1)%MINIX_INODES_PER_BLOCK
;
1140 raw_inode
->i_mode
= inode
->i_mode
;
1141 raw_inode
->i_uid
= inode
->i_uid
;
1142 raw_inode
->i_gid
= inode
->i_gid
;
1143 raw_inode
->i_nlinks
= inode
->i_nlink
;
1144 raw_inode
->i_size
= inode
->i_size
;
1145 raw_inode
->i_time
= inode
->i_mtime
;
1146 if (S_ISCHR(inode
->i_mode
) || S_ISBLK(inode
->i_mode
))
1147 raw_inode
->i_zone
[0] = kdev_t_to_nr(inode
->i_rdev
);
1148 else for (block
= 0; block
< 9; block
++)
1149 raw_inode
->i_zone
[block
] = inode
->u
.minix_i
.u
.i1_data
[block
];
1150 mark_buffer_dirty(bh
, 1);
1155 * The minix V2 function to synchronize an inode.
1157 static struct buffer_head
* V2_minix_update_inode(struct inode
* inode
)
1159 struct buffer_head
* bh
;
1160 struct minix2_inode
* raw_inode
;
1164 if (!ino
|| ino
> inode
->i_sb
->u
.minix_sb
.s_ninodes
) {
1165 printk("Bad inode number on dev %s"
1166 ": %d is out of range\n",
1167 kdevname(inode
->i_dev
), ino
);
1170 block
= 2 + inode
->i_sb
->u
.minix_sb
.s_imap_blocks
+ inode
->i_sb
->u
.minix_sb
.s_zmap_blocks
+
1171 (ino
-1)/MINIX2_INODES_PER_BLOCK
;
1172 if (!(bh
=bread(inode
->i_dev
, block
, BLOCK_SIZE
))) {
1173 printk("unable to read i-node block\n");
1176 raw_inode
= ((struct minix2_inode
*)bh
->b_data
) +
1177 (ino
-1)%MINIX2_INODES_PER_BLOCK
;
1178 raw_inode
->i_mode
= inode
->i_mode
;
1179 raw_inode
->i_uid
= inode
->i_uid
;
1180 raw_inode
->i_gid
= inode
->i_gid
;
1181 raw_inode
->i_nlinks
= inode
->i_nlink
;
1182 raw_inode
->i_size
= inode
->i_size
;
1183 raw_inode
->i_mtime
= inode
->i_mtime
;
1184 raw_inode
->i_atime
= inode
->i_atime
;
1185 raw_inode
->i_ctime
= inode
->i_ctime
;
1186 if (S_ISCHR(inode
->i_mode
) || S_ISBLK(inode
->i_mode
))
1187 raw_inode
->i_zone
[0] = kdev_t_to_nr(inode
->i_rdev
);
1188 else for (block
= 0; block
< 10; block
++)
1189 raw_inode
->i_zone
[block
] = inode
->u
.minix_i
.u
.i2_data
[block
];
1190 mark_buffer_dirty(bh
, 1);
1194 static struct buffer_head
*minix_update_inode(struct inode
*inode
)
1196 if (INODE_VERSION(inode
) == MINIX_V1
)
1197 return V1_minix_update_inode(inode
);
1199 return V2_minix_update_inode(inode
);
1202 static void minix_write_inode(struct inode
* inode
)
1204 struct buffer_head
*bh
;
1206 bh
= minix_update_inode(inode
);
1210 int minix_sync_inode(struct inode
* inode
)
1213 struct buffer_head
*bh
;
1215 bh
= minix_update_inode(inode
);
1216 if (bh
&& buffer_dirty(bh
))
1218 ll_rw_block(WRITE
, 1, &bh
);
1220 if (buffer_req(bh
) && !buffer_uptodate(bh
))
1222 printk ("IO error syncing minix inode ["
1224 kdevname(inode
->i_dev
), inode
->i_ino
);
1234 static struct file_system_type minix_fs_type
= {
1241 int __init
init_minix_fs(void)
1243 return register_filesystem(&minix_fs_type
);
1249 int init_module(void)
1251 return init_minix_fs();
1254 void cleanup_module(void)
1256 unregister_filesystem(&minix_fs_type
);