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>
23 #include <linux/highuid.h>
25 #include <asm/system.h>
26 #include <asm/uaccess.h>
27 #include <asm/bitops.h>
29 #include <linux/minix_fs.h>
31 static void minix_read_inode(struct inode
* inode
);
32 static void minix_write_inode(struct inode
* inode
);
33 static int minix_statfs(struct super_block
*sb
, struct statfs
*buf
, int bufsiz
);
34 static int minix_remount (struct super_block
* sb
, int * flags
, char * data
);
36 static void minix_delete_inode(struct inode
*inode
)
41 minix_truncate(inode
);
42 minix_free_inode(inode
);
47 static void minix_commit_super(struct super_block
* sb
)
49 mark_buffer_dirty(sb
->u
.minix_sb
.s_sbh
, 1);
53 static void minix_write_super(struct super_block
* sb
)
55 struct minix_super_block
* ms
;
57 if (!(sb
->s_flags
& MS_RDONLY
)) {
58 ms
= sb
->u
.minix_sb
.s_ms
;
60 if (ms
->s_state
& MINIX_VALID_FS
)
61 ms
->s_state
&= ~MINIX_VALID_FS
;
62 minix_commit_super(sb
);
68 static void minix_put_super(struct super_block
*sb
)
72 if (!(sb
->s_flags
& MS_RDONLY
)) {
73 sb
->u
.minix_sb
.s_ms
->s_state
= sb
->u
.minix_sb
.s_mount_state
;
74 mark_buffer_dirty(sb
->u
.minix_sb
.s_sbh
, 1);
76 for (i
= 0; i
< sb
->u
.minix_sb
.s_imap_blocks
; i
++)
77 brelse(sb
->u
.minix_sb
.s_imap
[i
]);
78 for (i
= 0; i
< sb
->u
.minix_sb
.s_zmap_blocks
; i
++)
79 brelse(sb
->u
.minix_sb
.s_zmap
[i
]);
80 brelse (sb
->u
.minix_sb
.s_sbh
);
81 kfree(sb
->u
.minix_sb
.s_imap
);
87 static struct super_operations minix_sops
= {
88 read_inode
: minix_read_inode
,
89 write_inode
: minix_write_inode
,
90 delete_inode
: minix_delete_inode
,
91 put_super
: minix_put_super
,
92 write_super
: minix_write_super
,
94 remount_fs
: minix_remount
,
97 static int minix_remount (struct super_block
* sb
, int * flags
, char * data
)
99 struct minix_super_block
* ms
;
101 ms
= sb
->u
.minix_sb
.s_ms
;
102 if ((*flags
& MS_RDONLY
) == (sb
->s_flags
& MS_RDONLY
))
104 if (*flags
& MS_RDONLY
) {
105 if (ms
->s_state
& MINIX_VALID_FS
||
106 !(sb
->u
.minix_sb
.s_mount_state
& MINIX_VALID_FS
))
108 /* Mounting a rw partition read-only. */
109 ms
->s_state
= sb
->u
.minix_sb
.s_mount_state
;
110 mark_buffer_dirty(sb
->u
.minix_sb
.s_sbh
, 1);
112 minix_commit_super(sb
);
115 /* Mount a partition which is read-only, read-write. */
116 sb
->u
.minix_sb
.s_mount_state
= ms
->s_state
;
117 ms
->s_state
&= ~MINIX_VALID_FS
;
118 mark_buffer_dirty(sb
->u
.minix_sb
.s_sbh
, 1);
121 if (!(sb
->u
.minix_sb
.s_mount_state
& MINIX_VALID_FS
))
122 printk ("MINIX-fs warning: remounting unchecked fs, "
123 "running fsck is recommended.\n");
124 else if ((sb
->u
.minix_sb
.s_mount_state
& MINIX_ERROR_FS
))
125 printk ("MINIX-fs warning: remounting fs with errors, "
126 "running fsck is recommended.\n");
132 * Check the root directory of the filesystem to make sure
133 * it really _is_ a Minix filesystem, and to check the size
134 * of the directory entry.
136 static const char * minix_checkroot(struct super_block
*s
, struct inode
*dir
)
138 struct buffer_head
*bh
;
139 struct minix_dir_entry
*de
;
143 if (!S_ISDIR(dir
->i_mode
))
144 return "root directory is not a directory";
146 bh
= minix_bread(dir
, 0, 0);
148 return "unable to read root directory";
150 de
= (struct minix_dir_entry
*) bh
->b_data
;
151 errmsg
= "bad root directory '.' entry";
152 dirsize
= BLOCK_SIZE
;
153 if (de
->inode
== MINIX_ROOT_INO
&& strcmp(de
->name
, ".") == 0) {
154 errmsg
= "bad root directory '..' entry";
158 while ((dirsize
<<= 1) < BLOCK_SIZE
) {
159 de
= (struct minix_dir_entry
*) (bh
->b_data
+ dirsize
);
160 if (de
->inode
!= MINIX_ROOT_INO
)
162 if (strcmp(de
->name
, ".."))
164 s
->u
.minix_sb
.s_dirsize
= dirsize
;
165 s
->u
.minix_sb
.s_namelen
= dirsize
- 2;
173 static struct super_block
*minix_read_super(struct super_block
*s
, void *data
,
176 struct buffer_head
*bh
;
177 struct buffer_head
**map
;
178 struct minix_super_block
*ms
;
180 kdev_t dev
= s
->s_dev
;
182 struct inode
*root_inode
;
185 /* N.B. These should be compile-time tests.
186 Unfortunately that is impossible. */
187 if (32 != sizeof (struct minix_inode
))
188 panic("bad V1 i-node size");
189 if (64 != sizeof(struct minix2_inode
))
190 panic("bad V2 i-node size");
194 hblock
= get_hardblocksize(dev
);
195 if (hblock
&& hblock
> BLOCK_SIZE
)
199 set_blocksize(dev
, BLOCK_SIZE
);
200 if (!(bh
= bread(dev
,1,BLOCK_SIZE
)))
203 ms
= (struct minix_super_block
*) bh
->b_data
;
204 s
->u
.minix_sb
.s_ms
= ms
;
205 s
->u
.minix_sb
.s_sbh
= bh
;
206 s
->u
.minix_sb
.s_mount_state
= ms
->s_state
;
207 s
->s_blocksize
= BLOCK_SIZE
;
208 s
->s_blocksize_bits
= BLOCK_SIZE_BITS
;
209 s
->u
.minix_sb
.s_ninodes
= ms
->s_ninodes
;
210 s
->u
.minix_sb
.s_nzones
= ms
->s_nzones
;
211 s
->u
.minix_sb
.s_imap_blocks
= ms
->s_imap_blocks
;
212 s
->u
.minix_sb
.s_zmap_blocks
= ms
->s_zmap_blocks
;
213 s
->u
.minix_sb
.s_firstdatazone
= ms
->s_firstdatazone
;
214 s
->u
.minix_sb
.s_log_zone_size
= ms
->s_log_zone_size
;
215 s
->u
.minix_sb
.s_max_size
= ms
->s_max_size
;
216 s
->s_magic
= ms
->s_magic
;
217 if (s
->s_magic
== MINIX_SUPER_MAGIC
) {
218 s
->u
.minix_sb
.s_version
= MINIX_V1
;
219 s
->u
.minix_sb
.s_dirsize
= 16;
220 s
->u
.minix_sb
.s_namelen
= 14;
221 s
->u
.minix_sb
.s_link_max
= MINIX_LINK_MAX
;
222 } else if (s
->s_magic
== MINIX_SUPER_MAGIC2
) {
223 s
->u
.minix_sb
.s_version
= MINIX_V1
;
224 s
->u
.minix_sb
.s_dirsize
= 32;
225 s
->u
.minix_sb
.s_namelen
= 30;
226 s
->u
.minix_sb
.s_link_max
= MINIX_LINK_MAX
;
227 } else if (s
->s_magic
== MINIX2_SUPER_MAGIC
) {
228 s
->u
.minix_sb
.s_version
= MINIX_V2
;
229 s
->u
.minix_sb
.s_nzones
= ms
->s_zones
;
230 s
->u
.minix_sb
.s_dirsize
= 16;
231 s
->u
.minix_sb
.s_namelen
= 14;
232 s
->u
.minix_sb
.s_link_max
= MINIX2_LINK_MAX
;
233 } else if (s
->s_magic
== MINIX2_SUPER_MAGIC2
) {
234 s
->u
.minix_sb
.s_version
= MINIX_V2
;
235 s
->u
.minix_sb
.s_nzones
= ms
->s_zones
;
236 s
->u
.minix_sb
.s_dirsize
= 32;
237 s
->u
.minix_sb
.s_namelen
= 30;
238 s
->u
.minix_sb
.s_link_max
= MINIX2_LINK_MAX
;
243 * Allocate the buffer map to keep the superblock small.
245 i
= (s
->u
.minix_sb
.s_imap_blocks
+ s
->u
.minix_sb
.s_zmap_blocks
) * sizeof(bh
);
246 map
= kmalloc(i
, GFP_KERNEL
);
250 s
->u
.minix_sb
.s_imap
= &map
[0];
251 s
->u
.minix_sb
.s_zmap
= &map
[s
->u
.minix_sb
.s_imap_blocks
];
254 for (i
=0 ; i
< s
->u
.minix_sb
.s_imap_blocks
; i
++) {
255 if (!(s
->u
.minix_sb
.s_imap
[i
]=bread(dev
,block
,BLOCK_SIZE
)))
259 for (i
=0 ; i
< s
->u
.minix_sb
.s_zmap_blocks
; i
++) {
260 if (!(s
->u
.minix_sb
.s_zmap
[i
]=bread(dev
,block
,BLOCK_SIZE
)))
265 minix_set_bit(0,s
->u
.minix_sb
.s_imap
[0]->b_data
);
266 minix_set_bit(0,s
->u
.minix_sb
.s_zmap
[0]->b_data
);
267 /* set up enough so that it can read an inode */
268 s
->s_op
= &minix_sops
;
269 root_inode
= iget(s
, MINIX_ROOT_INO
);
273 * Check the fs before we get the root dentry ...
275 errmsg
= minix_checkroot(s
, root_inode
);
279 s
->s_root
= d_alloc_root(root_inode
);
283 s
->s_root
->d_op
= &minix_dentry_operations
;
285 if (!(s
->s_flags
& MS_RDONLY
)) {
286 ms
->s_state
&= ~MINIX_VALID_FS
;
287 mark_buffer_dirty(bh
, 1);
291 if (!(s
->u
.minix_sb
.s_mount_state
& MINIX_VALID_FS
))
292 printk ("MINIX-fs: mounting unchecked file system, "
293 "running fsck is recommended.\n");
294 else if (s
->u
.minix_sb
.s_mount_state
& MINIX_ERROR_FS
)
295 printk ("MINIX-fs: mounting file system with errors, "
296 "running fsck is recommended.\n");
301 printk("MINIX-fs: %s\n", errmsg
);
308 printk("MINIX-fs: get root inode failed\n");
312 printk("MINIX-fs: bad superblock or unable to read bitmaps\n");
314 for (i
= 0; i
< s
->u
.minix_sb
.s_imap_blocks
; i
++)
315 brelse(s
->u
.minix_sb
.s_imap
[i
]);
316 for (i
= 0; i
< s
->u
.minix_sb
.s_zmap_blocks
; i
++)
317 brelse(s
->u
.minix_sb
.s_zmap
[i
]);
318 kfree(s
->u
.minix_sb
.s_imap
);
323 printk ("MINIX-fs: can't allocate map\n");
328 printk("VFS: Can't find a Minix or Minix V2 filesystem on device "
329 "%s.\n", kdevname(dev
));
335 printk("MINIX-fs: blocksize too small for device.\n");
339 printk("MINIX-fs: unable to read superblock\n");
348 static int minix_statfs(struct super_block
*sb
, struct statfs
*buf
, int bufsiz
)
352 tmp
.f_type
= sb
->s_magic
;
353 tmp
.f_bsize
= sb
->s_blocksize
;
354 tmp
.f_blocks
= (sb
->u
.minix_sb
.s_nzones
- sb
->u
.minix_sb
.s_firstdatazone
) << sb
->u
.minix_sb
.s_log_zone_size
;
355 tmp
.f_bfree
= minix_count_free_blocks(sb
);
356 tmp
.f_bavail
= tmp
.f_bfree
;
357 tmp
.f_files
= sb
->u
.minix_sb
.s_ninodes
;
358 tmp
.f_ffree
= minix_count_free_inodes(sb
);
359 tmp
.f_namelen
= sb
->u
.minix_sb
.s_namelen
;
360 return copy_to_user(buf
, &tmp
, bufsiz
) ? -EFAULT
: 0;
364 * The minix V1 fs bmap functions.
366 #define V1_inode_bmap(inode,nr) (((unsigned short *)(inode)->u.minix_i.u.i1_data)[(nr)])
368 static int V1_block_bmap(struct buffer_head
* bh
, int nr
)
374 tmp
= ((unsigned short *) bh
->b_data
)[nr
];
379 static int V1_minix_block_map(struct inode
* inode
, long block
)
386 printk("minix_bmap: block<0");
389 if (block
>= (inode
->i_sb
->u
.minix_sb
.s_max_size
/BLOCK_SIZE
)) {
390 printk("minix_bmap: block>big");
394 ret
= V1_inode_bmap(inode
,block
);
399 i
= V1_inode_bmap(inode
,7);
402 ret
= V1_block_bmap(bread(inode
->i_dev
, i
,
407 i
= V1_inode_bmap(inode
,8);
410 i
= V1_block_bmap(bread(inode
->i_dev
,i
,BLOCK_SIZE
),block
>>9);
413 ret
= V1_block_bmap(bread(inode
->i_dev
, i
, BLOCK_SIZE
),
421 * The minix V2 fs bmap functions.
423 #define V2_inode_bmap(inode,nr) (((unsigned int *)(inode)->u.minix_i.u.i2_data)[(nr)])
424 static int V2_block_bmap(struct buffer_head
* bh
, int nr
)
430 tmp
= ((unsigned int *) bh
->b_data
)[nr
];
435 static int V2_minix_block_map(struct inode
* inode
, int block
)
442 printk("minix_bmap: block<0");
445 if (block
>= (inode
->i_sb
->u
.minix_sb
.s_max_size
/BLOCK_SIZE
)) {
446 printk("minix_bmap: block>big");
450 ret
= V2_inode_bmap(inode
,block
);
455 i
= V2_inode_bmap(inode
, 7);
458 ret
= V2_block_bmap(bread(inode
->i_dev
, i
,
463 if (block
< (256 * 256)) {
464 i
= V2_inode_bmap(inode
, 8);
467 i
= V2_block_bmap(bread(inode
->i_dev
, i
, BLOCK_SIZE
),
471 ret
= V2_block_bmap(bread(inode
->i_dev
, i
, BLOCK_SIZE
),
475 block
-= (256 * 256);
476 i
= V2_inode_bmap(inode
, 9);
479 i
= V2_block_bmap(bread(inode
->i_dev
, i
, BLOCK_SIZE
),
483 i
= V2_block_bmap(bread(inode
->i_dev
, i
, BLOCK_SIZE
),
487 ret
= V2_block_bmap(bread(inode
->i_dev
, i
, BLOCK_SIZE
),
495 * The minix V1 fs getblk functions.
497 static struct buffer_head
* V1_inode_getblk(struct inode
* inode
, int nr
,
498 int new_block
, int *err
,
499 int metadata
, int *phys
, int *new)
503 struct buffer_head
* result
;
505 p
= inode
->u
.minix_i
.u
.i1_data
+ nr
;
510 result
= getblk(inode
->i_dev
, tmp
, BLOCK_SIZE
);
522 /* Check file limits.. */
524 unsigned long limit
= current
->rlim
[RLIMIT_FSIZE
].rlim_cur
;
525 if (limit
< RLIM_INFINITY
) {
526 limit
>>= BLOCK_SIZE_BITS
;
527 if (new_block
>= limit
) {
528 send_sig(SIGXFSZ
, current
, 0);
535 tmp
= minix_new_block(inode
);
541 result
= getblk(inode
->i_dev
, tmp
, BLOCK_SIZE
);
543 minix_free_block(inode
, tmp
);
547 memset(result
->b_data
, 0, BLOCK_SIZE
);
548 mark_buffer_uptodate(result
, 1);
549 mark_buffer_dirty(result
, 1);
553 * Nobody is allowed to change block allocation
554 * state from under us:
557 minix_free_block(inode
, tmp
);
567 inode
->i_ctime
= CURRENT_TIME
;
568 mark_inode_dirty(inode
);
572 static struct buffer_head
* V1_block_getblk(struct inode
* inode
,
573 struct buffer_head
* bh
, int nr
, int new_block
, int *err
,
574 int metadata
, int *phys
, int *new)
578 struct buffer_head
* result
;
584 if (!buffer_uptodate(bh
)) {
585 ll_rw_block(READ
, 1, &bh
);
587 if (!buffer_uptodate(bh
))
590 p
= nr
+ (unsigned short *) bh
->b_data
;
595 result
= getblk(bh
->b_dev
, tmp
, BLOCK_SIZE
);
607 limit
= current
->rlim
[RLIMIT_FSIZE
].rlim_cur
;
608 if (limit
< RLIM_INFINITY
) {
609 limit
>>= BLOCK_SIZE_BITS
;
610 if (new_block
>= limit
) {
611 send_sig(SIGXFSZ
, current
, 0);
616 tmp
= minix_new_block(inode
);
620 result
= getblk(bh
->b_dev
, tmp
, BLOCK_SIZE
);
622 minix_free_block(inode
, tmp
);
626 memset(result
->b_data
, 0, BLOCK_SIZE
);
627 mark_buffer_uptodate(result
, 1);
628 mark_buffer_dirty(result
, 1);
634 minix_free_block(inode
, tmp
);
640 mark_buffer_dirty(bh
, 1);
647 static int V1_get_block(struct inode
* inode
, long block
,
648 struct buffer_head
*bh_result
, int create
)
650 int ret
, err
, new, phys
, ptr
;
651 struct buffer_head
*bh
;
654 phys
= V1_minix_block_map(inode
, block
);
656 bh_result
->b_dev
= inode
->i_dev
;
657 bh_result
->b_blocknr
= phys
;
658 bh_result
->b_state
|= (1UL << BH_Mapped
);
671 if (block
>= inode
->i_sb
->u
.minix_sb
.s_max_size
/BLOCK_SIZE
)
677 * ok, these macros clean the logic up a bit and make
678 * it much more readable:
680 #define GET_INODE_DATABLOCK(x) \
681 V1_inode_getblk(inode, x, block, &err, 0, &phys, &new)
682 #define GET_INODE_PTR(x) \
683 V1_inode_getblk(inode, x, block, &err, 1, NULL, NULL)
684 #define GET_INDIRECT_DATABLOCK(x) \
685 V1_block_getblk(inode, bh, x, block, &err, 0, &phys, &new)
686 #define GET_INDIRECT_PTR(x) \
687 V1_block_getblk(inode, bh, x, block, &err, 1, NULL, NULL)
690 bh
= GET_INODE_DATABLOCK(ptr
);
695 bh
= GET_INODE_PTR(7);
699 bh
= GET_INODE_PTR(8);
700 bh
= GET_INDIRECT_PTR((ptr
>> 9) & 511);
702 bh
= GET_INDIRECT_DATABLOCK(ptr
& 511);
704 #undef GET_INODE_DATABLOCK
706 #undef GET_INDIRECT_DATABLOCK
707 #undef GET_INDIRECT_PTR
712 bh_result
->b_dev
= inode
->i_dev
;
713 bh_result
->b_blocknr
= phys
;
714 bh_result
->b_state
|= (1UL << BH_Mapped
);
716 bh_result
->b_state
|= (1UL << BH_New
);
722 printk("minix_getblk: block<0");
726 printk("minix_getblk: block>big");
731 * The minix V2 fs getblk functions.
733 static struct buffer_head
* V2_inode_getblk(struct inode
* inode
, int nr
,
734 int new_block
, int *err
,
735 int metadata
, int *phys
, int *new)
739 struct buffer_head
* result
;
741 p
= (unsigned int *) inode
->u
.minix_i
.u
.i2_data
+ nr
;
746 result
= getblk(inode
->i_dev
, tmp
, BLOCK_SIZE
);
758 /* Check file limits.. */
760 unsigned long limit
= current
->rlim
[RLIMIT_FSIZE
].rlim_cur
;
761 if (limit
< RLIM_INFINITY
) {
762 limit
>>= BLOCK_SIZE_BITS
;
763 if (new_block
>= limit
) {
764 send_sig(SIGXFSZ
, current
, 0);
771 tmp
= minix_new_block(inode
);
777 result
= getblk(inode
->i_dev
, tmp
, BLOCK_SIZE
);
779 minix_free_block(inode
, tmp
);
783 memset(result
->b_data
, 0, BLOCK_SIZE
);
784 mark_buffer_uptodate(result
, 1);
785 mark_buffer_dirty(result
, 1);
789 * Nobody is allowed to change block allocation
790 * state from under us:
793 minix_free_block(inode
, tmp
);
803 inode
->i_ctime
= CURRENT_TIME
;
804 mark_inode_dirty(inode
);
808 static struct buffer_head
* V2_block_getblk(struct inode
* inode
,
809 struct buffer_head
* bh
, int nr
, int new_block
, int *err
,
810 int metadata
, int *phys
, int *new)
814 struct buffer_head
* result
;
820 if (!buffer_uptodate(bh
)) {
821 ll_rw_block(READ
, 1, &bh
);
823 if (!buffer_uptodate(bh
))
826 p
= nr
+ (unsigned int *) bh
->b_data
;
831 result
= getblk(bh
->b_dev
, tmp
, BLOCK_SIZE
);
843 limit
= current
->rlim
[RLIMIT_FSIZE
].rlim_cur
;
844 if (limit
< RLIM_INFINITY
) {
845 limit
>>= BLOCK_SIZE_BITS
;
846 if (new_block
>= limit
) {
847 send_sig(SIGXFSZ
, current
, 0);
852 tmp
= minix_new_block(inode
);
856 result
= getblk(bh
->b_dev
, tmp
, BLOCK_SIZE
);
858 minix_free_block(inode
, tmp
);
862 memset(result
->b_data
, 0, BLOCK_SIZE
);
863 mark_buffer_uptodate(result
, 1);
864 mark_buffer_dirty(result
, 1);
870 minix_free_block(inode
, tmp
);
876 mark_buffer_dirty(bh
, 1);
883 static int V2_get_block(struct inode
* inode
, long block
,
884 struct buffer_head
*bh_result
, int create
)
886 int ret
, err
, new, phys
, ptr
;
887 struct buffer_head
* bh
;
890 phys
= V2_minix_block_map(inode
, block
);
892 bh_result
->b_dev
= inode
->i_dev
;
893 bh_result
->b_blocknr
= phys
;
894 bh_result
->b_state
|= (1UL << BH_Mapped
);
907 if (block
>= inode
->i_sb
->u
.minix_sb
.s_max_size
/BLOCK_SIZE
)
913 * ok, these macros clean the logic up a bit and make
914 * it much more readable:
916 #define GET_INODE_DATABLOCK(x) \
917 V2_inode_getblk(inode, x, block, &err, 0, &phys, &new)
918 #define GET_INODE_PTR(x) \
919 V2_inode_getblk(inode, x, block, &err, 1, NULL, NULL)
920 #define GET_INDIRECT_DATABLOCK(x) \
921 V2_block_getblk(inode, bh, x, block, &err, 0, &phys, &new)
922 #define GET_INDIRECT_PTR(x) \
923 V2_block_getblk(inode, bh, x, block, &err, 1, NULL, NULL)
926 bh
= GET_INODE_DATABLOCK(ptr
);
931 bh
= GET_INODE_PTR(7);
936 bh
= GET_INODE_PTR(8);
940 bh
= GET_INODE_PTR(9);
941 bh
= GET_INDIRECT_PTR((ptr
>> 16) & 255);
943 bh
= GET_INDIRECT_PTR((ptr
>> 8) & 255);
945 bh
= GET_INDIRECT_DATABLOCK(ptr
& 255);
947 #undef GET_INODE_DATABLOCK
949 #undef GET_INDIRECT_DATABLOCK
950 #undef GET_INDIRECT_PTR
955 bh_result
->b_dev
= inode
->i_dev
;
956 bh_result
->b_blocknr
= phys
;
957 bh_result
->b_state
|= (1UL << BH_Mapped
);
959 bh_result
->b_state
|= (1UL << BH_New
);
965 printk("minix_getblk: block<0");
969 printk("minix_getblk: block>big");
973 static int minix_get_block(struct inode
*inode
, long block
,
974 struct buffer_head
*bh_result
, int create
)
976 if (INODE_VERSION(inode
) == MINIX_V1
)
977 return V1_get_block(inode
, block
, bh_result
, create
);
979 return V2_get_block(inode
, block
, bh_result
, create
);
983 * the global minix fs getblk function.
985 struct buffer_head
*minix_getblk(struct inode
*inode
, int block
, int create
)
987 struct buffer_head dummy
;
991 dummy
.b_blocknr
= -1000;
992 error
= minix_get_block(inode
, block
, &dummy
, create
);
993 if (!error
&& buffer_mapped(&dummy
)) {
994 struct buffer_head
*bh
;
995 bh
= getblk(dummy
.b_dev
, dummy
.b_blocknr
, BLOCK_SIZE
);
996 if (buffer_new(&dummy
)) {
997 memset(bh
->b_data
, 0, BLOCK_SIZE
);
998 mark_buffer_uptodate(bh
, 1);
999 mark_buffer_dirty(bh
, 1);
1006 struct buffer_head
* minix_bread(struct inode
* inode
, int block
, int create
)
1008 struct buffer_head
* bh
;
1010 bh
= minix_getblk(inode
, block
, create
);
1011 if (!bh
|| buffer_uptodate(bh
))
1013 ll_rw_block(READ
, 1, &bh
);
1015 if (buffer_uptodate(bh
))
1021 static int minix_writepage(struct dentry
*dentry
, struct page
*page
)
1023 return block_write_full_page(page
,minix_get_block
);
1025 static int minix_readpage(struct dentry
*dentry
, struct page
*page
)
1027 return block_read_full_page(page
,minix_get_block
);
1029 static int minix_prepare_write(struct page
*page
, unsigned from
, unsigned to
)
1031 return block_prepare_write(page
,from
,to
,minix_get_block
);
1033 static int minix_bmap(struct address_space
*mapping
, long block
)
1035 return generic_block_bmap(mapping
,block
,minix_get_block
);
1037 struct address_space_operations minix_aops
= {
1038 readpage
: minix_readpage
,
1039 writepage
: minix_writepage
,
1040 prepare_write
: minix_prepare_write
,
1041 commit_write
: generic_commit_write
,
1046 * The minix V1 function to read an inode.
1048 static void V1_minix_read_inode(struct inode
* inode
)
1050 struct buffer_head
* bh
;
1051 struct minix_inode
* raw_inode
;
1056 if (!ino
|| ino
> inode
->i_sb
->u
.minix_sb
.s_ninodes
) {
1057 printk("Bad inode number on dev %s"
1058 ": %d is out of range\n",
1059 kdevname(inode
->i_dev
), ino
);
1062 block
= 2 + inode
->i_sb
->u
.minix_sb
.s_imap_blocks
+
1063 inode
->i_sb
->u
.minix_sb
.s_zmap_blocks
+
1064 (ino
-1)/MINIX_INODES_PER_BLOCK
;
1065 if (!(bh
=bread(inode
->i_dev
,block
, BLOCK_SIZE
))) {
1066 printk("Major problem: unable to read inode from dev "
1067 "%s\n", kdevname(inode
->i_dev
));
1070 raw_inode
= ((struct minix_inode
*) bh
->b_data
) +
1071 (ino
-1)%MINIX_INODES_PER_BLOCK
;
1072 inode
->i_mode
= raw_inode
->i_mode
;
1073 inode
->i_uid
= (uid_t
)raw_inode
->i_uid
;
1074 inode
->i_gid
= (gid_t
)raw_inode
->i_gid
;
1075 inode
->i_nlink
= raw_inode
->i_nlinks
;
1076 inode
->i_size
= raw_inode
->i_size
;
1077 inode
->i_mtime
= inode
->i_atime
= inode
->i_ctime
= raw_inode
->i_time
;
1078 inode
->i_blocks
= inode
->i_blksize
= 0;
1079 for (block
= 0; block
< 9; block
++)
1080 inode
->u
.minix_i
.u
.i1_data
[block
] = raw_inode
->i_zone
[block
];
1081 if (S_ISREG(inode
->i_mode
)) {
1082 inode
->i_op
= &minix_file_inode_operations
;
1083 inode
->i_fop
= &minix_file_operations
;
1084 inode
->i_mapping
->a_ops
= &minix_aops
;
1085 } else if (S_ISDIR(inode
->i_mode
)) {
1086 inode
->i_op
= &minix_dir_inode_operations
;
1087 inode
->i_fop
= &minix_dir_operations
;
1088 } else if (S_ISLNK(inode
->i_mode
)) {
1089 inode
->i_op
= &page_symlink_inode_operations
;
1090 inode
->i_mapping
->a_ops
= &minix_aops
;
1092 init_special_inode(inode
, inode
->i_mode
, raw_inode
->i_zone
[0]);
1097 * The minix V2 function to read an inode.
1099 static void V2_minix_read_inode(struct inode
* inode
)
1101 struct buffer_head
* bh
;
1102 struct minix2_inode
* raw_inode
;
1107 if (!ino
|| ino
> inode
->i_sb
->u
.minix_sb
.s_ninodes
) {
1108 printk("Bad inode number on dev %s"
1109 ": %d is out of range\n",
1110 kdevname(inode
->i_dev
), ino
);
1113 block
= 2 + inode
->i_sb
->u
.minix_sb
.s_imap_blocks
+
1114 inode
->i_sb
->u
.minix_sb
.s_zmap_blocks
+
1115 (ino
-1)/MINIX2_INODES_PER_BLOCK
;
1116 if (!(bh
=bread(inode
->i_dev
,block
, BLOCK_SIZE
))) {
1117 printk("Major problem: unable to read inode from dev "
1118 "%s\n", kdevname(inode
->i_dev
));
1121 raw_inode
= ((struct minix2_inode
*) bh
->b_data
) +
1122 (ino
-1)%MINIX2_INODES_PER_BLOCK
;
1123 inode
->i_mode
= raw_inode
->i_mode
;
1124 inode
->i_uid
= (uid_t
)raw_inode
->i_uid
;
1125 inode
->i_gid
= (gid_t
)raw_inode
->i_gid
;
1126 inode
->i_nlink
= raw_inode
->i_nlinks
;
1127 inode
->i_size
= raw_inode
->i_size
;
1128 inode
->i_mtime
= raw_inode
->i_mtime
;
1129 inode
->i_atime
= raw_inode
->i_atime
;
1130 inode
->i_ctime
= raw_inode
->i_ctime
;
1131 inode
->i_blocks
= inode
->i_blksize
= 0;
1132 for (block
= 0; block
< 10; block
++)
1133 inode
->u
.minix_i
.u
.i2_data
[block
] = raw_inode
->i_zone
[block
];
1134 if (S_ISREG(inode
->i_mode
)) {
1135 inode
->i_op
= &minix_file_inode_operations
;
1136 inode
->i_fop
= &minix_file_operations
;
1137 inode
->i_mapping
->a_ops
= &minix_aops
;
1138 } else if (S_ISDIR(inode
->i_mode
)) {
1139 inode
->i_op
= &minix_dir_inode_operations
;
1140 inode
->i_fop
= &minix_dir_operations
;
1141 } else if (S_ISLNK(inode
->i_mode
)) {
1142 inode
->i_op
= &page_symlink_inode_operations
;
1143 inode
->i_mapping
->a_ops
= &minix_aops
;
1145 init_special_inode(inode
, inode
->i_mode
, raw_inode
->i_zone
[0]);
1150 * The global function to read an inode.
1152 static void minix_read_inode(struct inode
* inode
)
1154 if (INODE_VERSION(inode
) == MINIX_V1
)
1155 V1_minix_read_inode(inode
);
1157 V2_minix_read_inode(inode
);
1161 * The minix V1 function to synchronize an inode.
1163 static struct buffer_head
* V1_minix_update_inode(struct inode
* inode
)
1165 struct buffer_head
* bh
;
1166 struct minix_inode
* raw_inode
;
1170 if (!ino
|| ino
> inode
->i_sb
->u
.minix_sb
.s_ninodes
) {
1171 printk("Bad inode number on dev %s"
1172 ": %d is out of range\n",
1173 kdevname(inode
->i_dev
), ino
);
1176 block
= 2 + inode
->i_sb
->u
.minix_sb
.s_imap_blocks
+ inode
->i_sb
->u
.minix_sb
.s_zmap_blocks
+
1177 (ino
-1)/MINIX_INODES_PER_BLOCK
;
1178 if (!(bh
=bread(inode
->i_dev
, block
, BLOCK_SIZE
))) {
1179 printk("unable to read i-node block\n");
1182 raw_inode
= ((struct minix_inode
*)bh
->b_data
) +
1183 (ino
-1)%MINIX_INODES_PER_BLOCK
;
1184 raw_inode
->i_mode
= inode
->i_mode
;
1185 raw_inode
->i_uid
= fs_high2lowuid(inode
->i_uid
);
1186 raw_inode
->i_gid
= fs_high2lowgid(inode
->i_gid
);
1187 raw_inode
->i_nlinks
= inode
->i_nlink
;
1188 raw_inode
->i_size
= inode
->i_size
;
1189 raw_inode
->i_time
= inode
->i_mtime
;
1190 if (S_ISCHR(inode
->i_mode
) || S_ISBLK(inode
->i_mode
))
1191 raw_inode
->i_zone
[0] = kdev_t_to_nr(inode
->i_rdev
);
1192 else for (block
= 0; block
< 9; block
++)
1193 raw_inode
->i_zone
[block
] = inode
->u
.minix_i
.u
.i1_data
[block
];
1194 mark_buffer_dirty(bh
, 1);
1199 * The minix V2 function to synchronize an inode.
1201 static struct buffer_head
* V2_minix_update_inode(struct inode
* inode
)
1203 struct buffer_head
* bh
;
1204 struct minix2_inode
* raw_inode
;
1208 if (!ino
|| ino
> inode
->i_sb
->u
.minix_sb
.s_ninodes
) {
1209 printk("Bad inode number on dev %s"
1210 ": %d is out of range\n",
1211 kdevname(inode
->i_dev
), ino
);
1214 block
= 2 + inode
->i_sb
->u
.minix_sb
.s_imap_blocks
+ inode
->i_sb
->u
.minix_sb
.s_zmap_blocks
+
1215 (ino
-1)/MINIX2_INODES_PER_BLOCK
;
1216 if (!(bh
=bread(inode
->i_dev
, block
, BLOCK_SIZE
))) {
1217 printk("unable to read i-node block\n");
1220 raw_inode
= ((struct minix2_inode
*)bh
->b_data
) +
1221 (ino
-1)%MINIX2_INODES_PER_BLOCK
;
1222 raw_inode
->i_mode
= inode
->i_mode
;
1223 raw_inode
->i_uid
= fs_high2lowuid(inode
->i_uid
);
1224 raw_inode
->i_gid
= fs_high2lowgid(inode
->i_gid
);
1225 raw_inode
->i_nlinks
= inode
->i_nlink
;
1226 raw_inode
->i_size
= inode
->i_size
;
1227 raw_inode
->i_mtime
= inode
->i_mtime
;
1228 raw_inode
->i_atime
= inode
->i_atime
;
1229 raw_inode
->i_ctime
= inode
->i_ctime
;
1230 if (S_ISCHR(inode
->i_mode
) || S_ISBLK(inode
->i_mode
))
1231 raw_inode
->i_zone
[0] = kdev_t_to_nr(inode
->i_rdev
);
1232 else for (block
= 0; block
< 10; block
++)
1233 raw_inode
->i_zone
[block
] = inode
->u
.minix_i
.u
.i2_data
[block
];
1234 mark_buffer_dirty(bh
, 1);
1238 static struct buffer_head
*minix_update_inode(struct inode
*inode
)
1240 if (INODE_VERSION(inode
) == MINIX_V1
)
1241 return V1_minix_update_inode(inode
);
1243 return V2_minix_update_inode(inode
);
1246 static void minix_write_inode(struct inode
* inode
)
1248 struct buffer_head
*bh
;
1251 bh
= minix_update_inode(inode
);
1256 int minix_sync_inode(struct inode
* inode
)
1259 struct buffer_head
*bh
;
1261 bh
= minix_update_inode(inode
);
1262 if (bh
&& buffer_dirty(bh
))
1264 ll_rw_block(WRITE
, 1, &bh
);
1266 if (buffer_req(bh
) && !buffer_uptodate(bh
))
1268 printk ("IO error syncing minix inode ["
1270 kdevname(inode
->i_dev
), inode
->i_ino
);
1280 static struct file_system_type minix_fs_type
= {
1287 int __init
init_minix_fs(void)
1289 return register_filesystem(&minix_fs_type
);
1295 int init_module(void)
1297 return init_minix_fs();
1300 void cleanup_module(void)
1302 unregister_filesystem(&minix_fs_type
);