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/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
, int wait
);
32 static int minix_statfs(struct super_block
*sb
, struct statfs
*buf
);
33 static int minix_remount (struct super_block
* sb
, int * flags
, char * data
);
35 static void minix_delete_inode(struct inode
*inode
)
40 minix_truncate(inode
);
41 minix_free_inode(inode
);
46 static void minix_commit_super(struct super_block
* sb
)
48 mark_buffer_dirty(sb
->u
.minix_sb
.s_sbh
);
52 static void minix_write_super(struct super_block
* sb
)
54 struct minix_super_block
* ms
;
56 if (!(sb
->s_flags
& MS_RDONLY
)) {
57 ms
= sb
->u
.minix_sb
.s_ms
;
59 if (ms
->s_state
& MINIX_VALID_FS
)
60 ms
->s_state
&= ~MINIX_VALID_FS
;
61 minix_commit_super(sb
);
67 static void minix_put_super(struct super_block
*sb
)
71 if (!(sb
->s_flags
& MS_RDONLY
)) {
72 sb
->u
.minix_sb
.s_ms
->s_state
= sb
->u
.minix_sb
.s_mount_state
;
73 mark_buffer_dirty(sb
->u
.minix_sb
.s_sbh
);
75 for (i
= 0; i
< sb
->u
.minix_sb
.s_imap_blocks
; i
++)
76 brelse(sb
->u
.minix_sb
.s_imap
[i
]);
77 for (i
= 0; i
< sb
->u
.minix_sb
.s_zmap_blocks
; i
++)
78 brelse(sb
->u
.minix_sb
.s_zmap
[i
]);
79 brelse (sb
->u
.minix_sb
.s_sbh
);
80 kfree(sb
->u
.minix_sb
.s_imap
);
85 static struct super_operations minix_sops
= {
86 read_inode
: minix_read_inode
,
87 write_inode
: minix_write_inode
,
88 delete_inode
: minix_delete_inode
,
89 put_super
: minix_put_super
,
90 write_super
: minix_write_super
,
92 remount_fs
: minix_remount
,
95 static int minix_remount (struct super_block
* sb
, int * flags
, char * data
)
97 struct minix_super_block
* ms
;
99 ms
= sb
->u
.minix_sb
.s_ms
;
100 if ((*flags
& MS_RDONLY
) == (sb
->s_flags
& MS_RDONLY
))
102 if (*flags
& MS_RDONLY
) {
103 if (ms
->s_state
& MINIX_VALID_FS
||
104 !(sb
->u
.minix_sb
.s_mount_state
& MINIX_VALID_FS
))
106 /* Mounting a rw partition read-only. */
107 ms
->s_state
= sb
->u
.minix_sb
.s_mount_state
;
108 mark_buffer_dirty(sb
->u
.minix_sb
.s_sbh
);
110 minix_commit_super(sb
);
113 /* Mount a partition which is read-only, read-write. */
114 sb
->u
.minix_sb
.s_mount_state
= ms
->s_state
;
115 ms
->s_state
&= ~MINIX_VALID_FS
;
116 mark_buffer_dirty(sb
->u
.minix_sb
.s_sbh
);
119 if (!(sb
->u
.minix_sb
.s_mount_state
& MINIX_VALID_FS
))
120 printk ("MINIX-fs warning: remounting unchecked fs, "
121 "running fsck is recommended.\n");
122 else if ((sb
->u
.minix_sb
.s_mount_state
& MINIX_ERROR_FS
))
123 printk ("MINIX-fs warning: remounting fs with errors, "
124 "running fsck is recommended.\n");
130 * Check the root directory of the filesystem to make sure
131 * it really _is_ a Minix filesystem, and to check the size
132 * of the directory entry.
134 static const char * minix_checkroot(struct super_block
*s
, struct inode
*dir
)
136 struct buffer_head
*bh
;
137 struct minix_dir_entry
*de
;
141 if (!S_ISDIR(dir
->i_mode
))
142 return "root directory is not a directory";
144 bh
= minix_bread(dir
, 0, 0);
146 return "unable to read root directory";
148 de
= (struct minix_dir_entry
*) bh
->b_data
;
149 errmsg
= "bad root directory '.' entry";
150 dirsize
= BLOCK_SIZE
;
151 if (de
->inode
== MINIX_ROOT_INO
&& strcmp(de
->name
, ".") == 0) {
152 errmsg
= "bad root directory '..' entry";
156 while ((dirsize
<<= 1) < BLOCK_SIZE
) {
157 de
= (struct minix_dir_entry
*) (bh
->b_data
+ dirsize
);
158 if (de
->inode
!= MINIX_ROOT_INO
)
160 if (strcmp(de
->name
, ".."))
162 s
->u
.minix_sb
.s_dirsize
= dirsize
;
163 s
->u
.minix_sb
.s_namelen
= dirsize
- 2;
171 static struct super_block
*minix_read_super(struct super_block
*s
, void *data
,
174 struct buffer_head
*bh
;
175 struct buffer_head
**map
;
176 struct minix_super_block
*ms
;
178 kdev_t dev
= s
->s_dev
;
180 struct inode
*root_inode
;
183 /* N.B. These should be compile-time tests.
184 Unfortunately that is impossible. */
185 if (32 != sizeof (struct minix_inode
))
186 panic("bad V1 i-node size");
187 if (64 != sizeof(struct minix2_inode
))
188 panic("bad V2 i-node size");
190 hblock
= get_hardblocksize(dev
);
191 if (hblock
&& hblock
> BLOCK_SIZE
)
194 set_blocksize(dev
, BLOCK_SIZE
);
195 if (!(bh
= bread(dev
,1,BLOCK_SIZE
)))
198 ms
= (struct minix_super_block
*) bh
->b_data
;
199 s
->u
.minix_sb
.s_ms
= ms
;
200 s
->u
.minix_sb
.s_sbh
= bh
;
201 s
->u
.minix_sb
.s_mount_state
= ms
->s_state
;
202 s
->s_blocksize
= BLOCK_SIZE
;
203 s
->s_blocksize_bits
= BLOCK_SIZE_BITS
;
204 s
->u
.minix_sb
.s_ninodes
= ms
->s_ninodes
;
205 s
->u
.minix_sb
.s_nzones
= ms
->s_nzones
;
206 s
->u
.minix_sb
.s_imap_blocks
= ms
->s_imap_blocks
;
207 s
->u
.minix_sb
.s_zmap_blocks
= ms
->s_zmap_blocks
;
208 s
->u
.minix_sb
.s_firstdatazone
= ms
->s_firstdatazone
;
209 s
->u
.minix_sb
.s_log_zone_size
= ms
->s_log_zone_size
;
210 s
->u
.minix_sb
.s_max_size
= ms
->s_max_size
;
211 s
->s_magic
= ms
->s_magic
;
212 if (s
->s_magic
== MINIX_SUPER_MAGIC
) {
213 s
->u
.minix_sb
.s_version
= MINIX_V1
;
214 s
->u
.minix_sb
.s_dirsize
= 16;
215 s
->u
.minix_sb
.s_namelen
= 14;
216 s
->u
.minix_sb
.s_link_max
= MINIX_LINK_MAX
;
217 } else if (s
->s_magic
== MINIX_SUPER_MAGIC2
) {
218 s
->u
.minix_sb
.s_version
= MINIX_V1
;
219 s
->u
.minix_sb
.s_dirsize
= 32;
220 s
->u
.minix_sb
.s_namelen
= 30;
221 s
->u
.minix_sb
.s_link_max
= MINIX_LINK_MAX
;
222 } else if (s
->s_magic
== MINIX2_SUPER_MAGIC
) {
223 s
->u
.minix_sb
.s_version
= MINIX_V2
;
224 s
->u
.minix_sb
.s_nzones
= ms
->s_zones
;
225 s
->u
.minix_sb
.s_dirsize
= 16;
226 s
->u
.minix_sb
.s_namelen
= 14;
227 s
->u
.minix_sb
.s_link_max
= MINIX2_LINK_MAX
;
228 } else if (s
->s_magic
== MINIX2_SUPER_MAGIC2
) {
229 s
->u
.minix_sb
.s_version
= MINIX_V2
;
230 s
->u
.minix_sb
.s_nzones
= ms
->s_zones
;
231 s
->u
.minix_sb
.s_dirsize
= 32;
232 s
->u
.minix_sb
.s_namelen
= 30;
233 s
->u
.minix_sb
.s_link_max
= MINIX2_LINK_MAX
;
238 * Allocate the buffer map to keep the superblock small.
240 i
= (s
->u
.minix_sb
.s_imap_blocks
+ s
->u
.minix_sb
.s_zmap_blocks
) * sizeof(bh
);
241 map
= kmalloc(i
, GFP_KERNEL
);
245 s
->u
.minix_sb
.s_imap
= &map
[0];
246 s
->u
.minix_sb
.s_zmap
= &map
[s
->u
.minix_sb
.s_imap_blocks
];
249 for (i
=0 ; i
< s
->u
.minix_sb
.s_imap_blocks
; i
++) {
250 if (!(s
->u
.minix_sb
.s_imap
[i
]=bread(dev
,block
,BLOCK_SIZE
)))
254 for (i
=0 ; i
< s
->u
.minix_sb
.s_zmap_blocks
; i
++) {
255 if (!(s
->u
.minix_sb
.s_zmap
[i
]=bread(dev
,block
,BLOCK_SIZE
)))
260 minix_set_bit(0,s
->u
.minix_sb
.s_imap
[0]->b_data
);
261 minix_set_bit(0,s
->u
.minix_sb
.s_zmap
[0]->b_data
);
262 /* set up enough so that it can read an inode */
263 s
->s_op
= &minix_sops
;
264 root_inode
= iget(s
, MINIX_ROOT_INO
);
268 * Check the fs before we get the root dentry ...
270 errmsg
= minix_checkroot(s
, root_inode
);
274 s
->s_root
= d_alloc_root(root_inode
);
278 s
->s_root
->d_op
= &minix_dentry_operations
;
280 if (!(s
->s_flags
& MS_RDONLY
)) {
281 ms
->s_state
&= ~MINIX_VALID_FS
;
282 mark_buffer_dirty(bh
);
285 if (!(s
->u
.minix_sb
.s_mount_state
& MINIX_VALID_FS
))
286 printk ("MINIX-fs: mounting unchecked file system, "
287 "running fsck is recommended.\n");
288 else if (s
->u
.minix_sb
.s_mount_state
& MINIX_ERROR_FS
)
289 printk ("MINIX-fs: mounting file system with errors, "
290 "running fsck is recommended.\n");
295 printk("MINIX-fs: %s\n", errmsg
);
302 printk("MINIX-fs: get root inode failed\n");
306 printk("MINIX-fs: bad superblock or unable to read bitmaps\n");
308 for (i
= 0; i
< s
->u
.minix_sb
.s_imap_blocks
; i
++)
309 brelse(s
->u
.minix_sb
.s_imap
[i
]);
310 for (i
= 0; i
< s
->u
.minix_sb
.s_zmap_blocks
; i
++)
311 brelse(s
->u
.minix_sb
.s_zmap
[i
]);
312 kfree(s
->u
.minix_sb
.s_imap
);
317 printk ("MINIX-fs: can't allocate map\n");
322 printk("VFS: Can't find a Minix or Minix V2 filesystem on device "
323 "%s.\n", kdevname(dev
));
329 printk("MINIX-fs: blocksize too small for device.\n");
333 printk("MINIX-fs: unable to read superblock\n");
338 static int minix_statfs(struct super_block
*sb
, struct statfs
*buf
)
340 buf
->f_type
= sb
->s_magic
;
341 buf
->f_bsize
= sb
->s_blocksize
;
342 buf
->f_blocks
= (sb
->u
.minix_sb
.s_nzones
- sb
->u
.minix_sb
.s_firstdatazone
) << sb
->u
.minix_sb
.s_log_zone_size
;
343 buf
->f_bfree
= minix_count_free_blocks(sb
);
344 buf
->f_bavail
= buf
->f_bfree
;
345 buf
->f_files
= sb
->u
.minix_sb
.s_ninodes
;
346 buf
->f_ffree
= minix_count_free_inodes(sb
);
347 buf
->f_namelen
= sb
->u
.minix_sb
.s_namelen
;
352 * The minix V1 fs bmap functions.
354 #define V1_inode_bmap(inode,nr) (((unsigned short *)(inode)->u.minix_i.u.i1_data)[(nr)])
356 static int V1_block_bmap(struct buffer_head
* bh
, int nr
)
362 tmp
= ((unsigned short *) bh
->b_data
)[nr
];
367 static int V1_minix_block_map(struct inode
* inode
, long block
)
374 printk("minix_bmap: block<0");
377 if (block
>= (inode
->i_sb
->u
.minix_sb
.s_max_size
/BLOCK_SIZE
)) {
378 printk("minix_bmap: block>big");
382 ret
= V1_inode_bmap(inode
,block
);
387 i
= V1_inode_bmap(inode
,7);
390 ret
= V1_block_bmap(bread(inode
->i_dev
, i
,
395 i
= V1_inode_bmap(inode
,8);
398 i
= V1_block_bmap(bread(inode
->i_dev
,i
,BLOCK_SIZE
),block
>>9);
401 ret
= V1_block_bmap(bread(inode
->i_dev
, i
, BLOCK_SIZE
),
409 * The minix V2 fs bmap functions.
411 #define V2_inode_bmap(inode,nr) (((unsigned int *)(inode)->u.minix_i.u.i2_data)[(nr)])
412 static int V2_block_bmap(struct buffer_head
* bh
, int nr
)
418 tmp
= ((unsigned int *) bh
->b_data
)[nr
];
423 static int V2_minix_block_map(struct inode
* inode
, int block
)
430 printk("minix_bmap: block<0");
433 if (block
>= (inode
->i_sb
->u
.minix_sb
.s_max_size
/BLOCK_SIZE
)) {
434 printk("minix_bmap: block>big");
438 ret
= V2_inode_bmap(inode
,block
);
443 i
= V2_inode_bmap(inode
, 7);
446 ret
= V2_block_bmap(bread(inode
->i_dev
, i
,
451 if (block
< (256 * 256)) {
452 i
= V2_inode_bmap(inode
, 8);
455 i
= V2_block_bmap(bread(inode
->i_dev
, i
, BLOCK_SIZE
),
459 ret
= V2_block_bmap(bread(inode
->i_dev
, i
, BLOCK_SIZE
),
463 block
-= (256 * 256);
464 i
= V2_inode_bmap(inode
, 9);
467 i
= V2_block_bmap(bread(inode
->i_dev
, i
, BLOCK_SIZE
),
471 i
= V2_block_bmap(bread(inode
->i_dev
, i
, BLOCK_SIZE
),
475 ret
= V2_block_bmap(bread(inode
->i_dev
, i
, BLOCK_SIZE
),
483 * The minix V1 fs getblk functions.
485 static struct buffer_head
* V1_inode_getblk(struct inode
* inode
, int nr
,
486 int new_block
, int *err
,
487 int metadata
, int *phys
, int *new)
491 struct buffer_head
* result
;
493 p
= inode
->u
.minix_i
.u
.i1_data
+ nr
;
498 result
= getblk(inode
->i_dev
, tmp
, BLOCK_SIZE
);
509 tmp
= minix_new_block(inode
);
515 result
= getblk(inode
->i_dev
, tmp
, BLOCK_SIZE
);
517 minix_free_block(inode
, tmp
);
521 memset(result
->b_data
, 0, BLOCK_SIZE
);
522 mark_buffer_uptodate(result
, 1);
523 mark_buffer_dirty(result
);
527 * Nobody is allowed to change block allocation
528 * state from under us:
531 minix_free_block(inode
, tmp
);
541 inode
->i_ctime
= CURRENT_TIME
;
542 mark_inode_dirty(inode
);
546 static struct buffer_head
* V1_block_getblk(struct inode
* inode
,
547 struct buffer_head
* bh
, int nr
, int new_block
, int *err
,
548 int metadata
, int *phys
, int *new)
552 struct buffer_head
* result
;
557 if (!buffer_uptodate(bh
)) {
558 ll_rw_block(READ
, 1, &bh
);
560 if (!buffer_uptodate(bh
))
563 p
= nr
+ (unsigned short *) bh
->b_data
;
568 result
= getblk(bh
->b_dev
, tmp
, BLOCK_SIZE
);
579 tmp
= minix_new_block(inode
);
583 result
= getblk(bh
->b_dev
, tmp
, BLOCK_SIZE
);
585 minix_free_block(inode
, tmp
);
589 memset(result
->b_data
, 0, BLOCK_SIZE
);
590 mark_buffer_uptodate(result
, 1);
591 mark_buffer_dirty(result
);
597 minix_free_block(inode
, tmp
);
603 mark_buffer_dirty(bh
);
610 static int V1_get_block(struct inode
* inode
, long block
,
611 struct buffer_head
*bh_result
, int create
)
613 int ret
, err
, new, phys
, ptr
;
614 struct buffer_head
*bh
;
617 phys
= V1_minix_block_map(inode
, block
);
619 bh_result
->b_dev
= inode
->i_dev
;
620 bh_result
->b_blocknr
= phys
;
621 bh_result
->b_state
|= (1UL << BH_Mapped
);
634 if (block
>= inode
->i_sb
->u
.minix_sb
.s_max_size
/BLOCK_SIZE
)
640 * ok, these macros clean the logic up a bit and make
641 * it much more readable:
643 #define GET_INODE_DATABLOCK(x) \
644 V1_inode_getblk(inode, x, block, &err, 0, &phys, &new)
645 #define GET_INODE_PTR(x) \
646 V1_inode_getblk(inode, x, block, &err, 1, NULL, NULL)
647 #define GET_INDIRECT_DATABLOCK(x) \
648 V1_block_getblk(inode, bh, x, block, &err, 0, &phys, &new)
649 #define GET_INDIRECT_PTR(x) \
650 V1_block_getblk(inode, bh, x, block, &err, 1, NULL, NULL)
653 bh
= GET_INODE_DATABLOCK(ptr
);
658 bh
= GET_INODE_PTR(7);
662 bh
= GET_INODE_PTR(8);
663 bh
= GET_INDIRECT_PTR((ptr
>> 9) & 511);
665 bh
= GET_INDIRECT_DATABLOCK(ptr
& 511);
667 #undef GET_INODE_DATABLOCK
669 #undef GET_INDIRECT_DATABLOCK
670 #undef GET_INDIRECT_PTR
675 bh_result
->b_dev
= inode
->i_dev
;
676 bh_result
->b_blocknr
= phys
;
677 bh_result
->b_state
|= (1UL << BH_Mapped
);
679 bh_result
->b_state
|= (1UL << BH_New
);
685 printk("minix_getblk: block<0");
689 printk("minix_getblk: block>big");
694 * The minix V2 fs getblk functions.
696 static struct buffer_head
* V2_inode_getblk(struct inode
* inode
, int nr
,
697 int new_block
, int *err
,
698 int metadata
, int *phys
, int *new)
702 struct buffer_head
* result
;
704 p
= (unsigned int *) inode
->u
.minix_i
.u
.i2_data
+ nr
;
709 result
= getblk(inode
->i_dev
, tmp
, BLOCK_SIZE
);
720 tmp
= minix_new_block(inode
);
726 result
= getblk(inode
->i_dev
, tmp
, BLOCK_SIZE
);
728 minix_free_block(inode
, tmp
);
732 memset(result
->b_data
, 0, BLOCK_SIZE
);
733 mark_buffer_uptodate(result
, 1);
734 mark_buffer_dirty(result
);
738 * Nobody is allowed to change block allocation
739 * state from under us:
742 minix_free_block(inode
, tmp
);
752 inode
->i_ctime
= CURRENT_TIME
;
753 mark_inode_dirty(inode
);
757 static struct buffer_head
* V2_block_getblk(struct inode
* inode
,
758 struct buffer_head
* bh
, int nr
, int new_block
, int *err
,
759 int metadata
, int *phys
, int *new)
763 struct buffer_head
* result
;
768 if (!buffer_uptodate(bh
)) {
769 ll_rw_block(READ
, 1, &bh
);
771 if (!buffer_uptodate(bh
))
774 p
= nr
+ (unsigned int *) bh
->b_data
;
779 result
= getblk(bh
->b_dev
, tmp
, BLOCK_SIZE
);
790 tmp
= minix_new_block(inode
);
794 result
= getblk(bh
->b_dev
, tmp
, BLOCK_SIZE
);
796 minix_free_block(inode
, tmp
);
800 memset(result
->b_data
, 0, BLOCK_SIZE
);
801 mark_buffer_uptodate(result
, 1);
802 mark_buffer_dirty(result
);
808 minix_free_block(inode
, tmp
);
814 mark_buffer_dirty(bh
);
821 static int V2_get_block(struct inode
* inode
, long block
,
822 struct buffer_head
*bh_result
, int create
)
824 int ret
, err
, new, phys
, ptr
;
825 struct buffer_head
* bh
;
828 phys
= V2_minix_block_map(inode
, block
);
830 bh_result
->b_dev
= inode
->i_dev
;
831 bh_result
->b_blocknr
= phys
;
832 bh_result
->b_state
|= (1UL << BH_Mapped
);
845 if (block
>= inode
->i_sb
->u
.minix_sb
.s_max_size
/BLOCK_SIZE
)
851 * ok, these macros clean the logic up a bit and make
852 * it much more readable:
854 #define GET_INODE_DATABLOCK(x) \
855 V2_inode_getblk(inode, x, block, &err, 0, &phys, &new)
856 #define GET_INODE_PTR(x) \
857 V2_inode_getblk(inode, x, block, &err, 1, NULL, NULL)
858 #define GET_INDIRECT_DATABLOCK(x) \
859 V2_block_getblk(inode, bh, x, block, &err, 0, &phys, &new)
860 #define GET_INDIRECT_PTR(x) \
861 V2_block_getblk(inode, bh, x, block, &err, 1, NULL, NULL)
864 bh
= GET_INODE_DATABLOCK(ptr
);
869 bh
= GET_INODE_PTR(7);
874 bh
= GET_INODE_PTR(8);
878 bh
= GET_INODE_PTR(9);
879 bh
= GET_INDIRECT_PTR((ptr
>> 16) & 255);
881 bh
= GET_INDIRECT_PTR((ptr
>> 8) & 255);
883 bh
= GET_INDIRECT_DATABLOCK(ptr
& 255);
885 #undef GET_INODE_DATABLOCK
887 #undef GET_INDIRECT_DATABLOCK
888 #undef GET_INDIRECT_PTR
893 bh_result
->b_dev
= inode
->i_dev
;
894 bh_result
->b_blocknr
= phys
;
895 bh_result
->b_state
|= (1UL << BH_Mapped
);
897 bh_result
->b_state
|= (1UL << BH_New
);
903 printk("minix_getblk: block<0");
907 printk("minix_getblk: block>big");
911 static int minix_get_block(struct inode
*inode
, long block
,
912 struct buffer_head
*bh_result
, int create
)
914 if (INODE_VERSION(inode
) == MINIX_V1
)
915 return V1_get_block(inode
, block
, bh_result
, create
);
917 return V2_get_block(inode
, block
, bh_result
, create
);
921 * the global minix fs getblk function.
923 struct buffer_head
*minix_getblk(struct inode
*inode
, int block
, int create
)
925 struct buffer_head dummy
;
929 dummy
.b_blocknr
= -1000;
930 error
= minix_get_block(inode
, block
, &dummy
, create
);
931 if (!error
&& buffer_mapped(&dummy
)) {
932 struct buffer_head
*bh
;
933 bh
= getblk(dummy
.b_dev
, dummy
.b_blocknr
, BLOCK_SIZE
);
934 if (buffer_new(&dummy
)) {
935 memset(bh
->b_data
, 0, BLOCK_SIZE
);
936 mark_buffer_uptodate(bh
, 1);
937 mark_buffer_dirty(bh
);
944 struct buffer_head
* minix_bread(struct inode
* inode
, int block
, int create
)
946 struct buffer_head
* bh
;
948 bh
= minix_getblk(inode
, block
, create
);
949 if (!bh
|| buffer_uptodate(bh
))
951 ll_rw_block(READ
, 1, &bh
);
953 if (buffer_uptodate(bh
))
959 static int minix_writepage(struct file
*file
, struct page
*page
)
961 return block_write_full_page(page
,minix_get_block
);
963 static int minix_readpage(struct file
*file
, struct page
*page
)
965 return block_read_full_page(page
,minix_get_block
);
967 static int minix_prepare_write(struct file
*file
, struct page
*page
, unsigned from
, unsigned to
)
969 return block_prepare_write(page
,from
,to
,minix_get_block
);
971 static int minix_bmap(struct address_space
*mapping
, long block
)
973 return generic_block_bmap(mapping
,block
,minix_get_block
);
975 struct address_space_operations minix_aops
= {
976 readpage
: minix_readpage
,
977 writepage
: minix_writepage
,
978 sync_page
: block_sync_page
,
979 prepare_write
: minix_prepare_write
,
980 commit_write
: generic_commit_write
,
985 * The minix V1 function to read an inode.
987 static void V1_minix_read_inode(struct inode
* inode
)
989 struct buffer_head
* bh
;
990 struct minix_inode
* raw_inode
;
995 if (!ino
|| ino
> inode
->i_sb
->u
.minix_sb
.s_ninodes
) {
996 printk("Bad inode number on dev %s"
997 ": %d is out of range\n",
998 kdevname(inode
->i_dev
), ino
);
1001 block
= 2 + inode
->i_sb
->u
.minix_sb
.s_imap_blocks
+
1002 inode
->i_sb
->u
.minix_sb
.s_zmap_blocks
+
1003 (ino
-1)/MINIX_INODES_PER_BLOCK
;
1004 if (!(bh
=bread(inode
->i_dev
,block
, BLOCK_SIZE
))) {
1005 printk("Major problem: unable to read inode from dev "
1006 "%s\n", kdevname(inode
->i_dev
));
1009 raw_inode
= ((struct minix_inode
*) bh
->b_data
) +
1010 (ino
-1)%MINIX_INODES_PER_BLOCK
;
1011 inode
->i_mode
= raw_inode
->i_mode
;
1012 inode
->i_uid
= (uid_t
)raw_inode
->i_uid
;
1013 inode
->i_gid
= (gid_t
)raw_inode
->i_gid
;
1014 inode
->i_nlink
= raw_inode
->i_nlinks
;
1015 inode
->i_size
= raw_inode
->i_size
;
1016 inode
->i_mtime
= inode
->i_atime
= inode
->i_ctime
= raw_inode
->i_time
;
1017 inode
->i_blocks
= inode
->i_blksize
= 0;
1018 for (block
= 0; block
< 9; block
++)
1019 inode
->u
.minix_i
.u
.i1_data
[block
] = raw_inode
->i_zone
[block
];
1020 if (S_ISREG(inode
->i_mode
)) {
1021 inode
->i_op
= &minix_file_inode_operations
;
1022 inode
->i_fop
= &minix_file_operations
;
1023 inode
->i_mapping
->a_ops
= &minix_aops
;
1024 } else if (S_ISDIR(inode
->i_mode
)) {
1025 inode
->i_op
= &minix_dir_inode_operations
;
1026 inode
->i_fop
= &minix_dir_operations
;
1027 } else if (S_ISLNK(inode
->i_mode
)) {
1028 inode
->i_op
= &page_symlink_inode_operations
;
1029 inode
->i_mapping
->a_ops
= &minix_aops
;
1031 init_special_inode(inode
, inode
->i_mode
, raw_inode
->i_zone
[0]);
1036 * The minix V2 function to read an inode.
1038 static void V2_minix_read_inode(struct inode
* inode
)
1040 struct buffer_head
* bh
;
1041 struct minix2_inode
* raw_inode
;
1046 if (!ino
|| ino
> inode
->i_sb
->u
.minix_sb
.s_ninodes
) {
1047 printk("Bad inode number on dev %s"
1048 ": %d is out of range\n",
1049 kdevname(inode
->i_dev
), ino
);
1052 block
= 2 + inode
->i_sb
->u
.minix_sb
.s_imap_blocks
+
1053 inode
->i_sb
->u
.minix_sb
.s_zmap_blocks
+
1054 (ino
-1)/MINIX2_INODES_PER_BLOCK
;
1055 if (!(bh
=bread(inode
->i_dev
,block
, BLOCK_SIZE
))) {
1056 printk("Major problem: unable to read inode from dev "
1057 "%s\n", kdevname(inode
->i_dev
));
1060 raw_inode
= ((struct minix2_inode
*) bh
->b_data
) +
1061 (ino
-1)%MINIX2_INODES_PER_BLOCK
;
1062 inode
->i_mode
= raw_inode
->i_mode
;
1063 inode
->i_uid
= (uid_t
)raw_inode
->i_uid
;
1064 inode
->i_gid
= (gid_t
)raw_inode
->i_gid
;
1065 inode
->i_nlink
= raw_inode
->i_nlinks
;
1066 inode
->i_size
= raw_inode
->i_size
;
1067 inode
->i_mtime
= raw_inode
->i_mtime
;
1068 inode
->i_atime
= raw_inode
->i_atime
;
1069 inode
->i_ctime
= raw_inode
->i_ctime
;
1070 inode
->i_blocks
= inode
->i_blksize
= 0;
1071 for (block
= 0; block
< 10; block
++)
1072 inode
->u
.minix_i
.u
.i2_data
[block
] = raw_inode
->i_zone
[block
];
1073 if (S_ISREG(inode
->i_mode
)) {
1074 inode
->i_op
= &minix_file_inode_operations
;
1075 inode
->i_fop
= &minix_file_operations
;
1076 inode
->i_mapping
->a_ops
= &minix_aops
;
1077 } else if (S_ISDIR(inode
->i_mode
)) {
1078 inode
->i_op
= &minix_dir_inode_operations
;
1079 inode
->i_fop
= &minix_dir_operations
;
1080 } else if (S_ISLNK(inode
->i_mode
)) {
1081 inode
->i_op
= &page_symlink_inode_operations
;
1082 inode
->i_mapping
->a_ops
= &minix_aops
;
1084 init_special_inode(inode
, inode
->i_mode
, raw_inode
->i_zone
[0]);
1089 * The global function to read an inode.
1091 static void minix_read_inode(struct inode
* inode
)
1093 if (INODE_VERSION(inode
) == MINIX_V1
)
1094 V1_minix_read_inode(inode
);
1096 V2_minix_read_inode(inode
);
1100 * The minix V1 function to synchronize an inode.
1102 static struct buffer_head
* V1_minix_update_inode(struct inode
* inode
)
1104 struct buffer_head
* bh
;
1105 struct minix_inode
* raw_inode
;
1109 if (!ino
|| ino
> inode
->i_sb
->u
.minix_sb
.s_ninodes
) {
1110 printk("Bad inode number on dev %s"
1111 ": %d is out of range\n",
1112 kdevname(inode
->i_dev
), ino
);
1115 block
= 2 + inode
->i_sb
->u
.minix_sb
.s_imap_blocks
+ inode
->i_sb
->u
.minix_sb
.s_zmap_blocks
+
1116 (ino
-1)/MINIX_INODES_PER_BLOCK
;
1117 if (!(bh
=bread(inode
->i_dev
, block
, BLOCK_SIZE
))) {
1118 printk("unable to read i-node block\n");
1121 raw_inode
= ((struct minix_inode
*)bh
->b_data
) +
1122 (ino
-1)%MINIX_INODES_PER_BLOCK
;
1123 raw_inode
->i_mode
= inode
->i_mode
;
1124 raw_inode
->i_uid
= fs_high2lowuid(inode
->i_uid
);
1125 raw_inode
->i_gid
= fs_high2lowgid(inode
->i_gid
);
1126 raw_inode
->i_nlinks
= inode
->i_nlink
;
1127 raw_inode
->i_size
= inode
->i_size
;
1128 raw_inode
->i_time
= inode
->i_mtime
;
1129 if (S_ISCHR(inode
->i_mode
) || S_ISBLK(inode
->i_mode
))
1130 raw_inode
->i_zone
[0] = kdev_t_to_nr(inode
->i_rdev
);
1131 else for (block
= 0; block
< 9; block
++)
1132 raw_inode
->i_zone
[block
] = inode
->u
.minix_i
.u
.i1_data
[block
];
1133 mark_buffer_dirty(bh
);
1138 * The minix V2 function to synchronize an inode.
1140 static struct buffer_head
* V2_minix_update_inode(struct inode
* inode
)
1142 struct buffer_head
* bh
;
1143 struct minix2_inode
* raw_inode
;
1147 if (!ino
|| ino
> inode
->i_sb
->u
.minix_sb
.s_ninodes
) {
1148 printk("Bad inode number on dev %s"
1149 ": %d is out of range\n",
1150 kdevname(inode
->i_dev
), ino
);
1153 block
= 2 + inode
->i_sb
->u
.minix_sb
.s_imap_blocks
+ inode
->i_sb
->u
.minix_sb
.s_zmap_blocks
+
1154 (ino
-1)/MINIX2_INODES_PER_BLOCK
;
1155 if (!(bh
=bread(inode
->i_dev
, block
, BLOCK_SIZE
))) {
1156 printk("unable to read i-node block\n");
1159 raw_inode
= ((struct minix2_inode
*)bh
->b_data
) +
1160 (ino
-1)%MINIX2_INODES_PER_BLOCK
;
1161 raw_inode
->i_mode
= inode
->i_mode
;
1162 raw_inode
->i_uid
= fs_high2lowuid(inode
->i_uid
);
1163 raw_inode
->i_gid
= fs_high2lowgid(inode
->i_gid
);
1164 raw_inode
->i_nlinks
= inode
->i_nlink
;
1165 raw_inode
->i_size
= inode
->i_size
;
1166 raw_inode
->i_mtime
= inode
->i_mtime
;
1167 raw_inode
->i_atime
= inode
->i_atime
;
1168 raw_inode
->i_ctime
= inode
->i_ctime
;
1169 if (S_ISCHR(inode
->i_mode
) || S_ISBLK(inode
->i_mode
))
1170 raw_inode
->i_zone
[0] = kdev_t_to_nr(inode
->i_rdev
);
1171 else for (block
= 0; block
< 10; block
++)
1172 raw_inode
->i_zone
[block
] = inode
->u
.minix_i
.u
.i2_data
[block
];
1173 mark_buffer_dirty(bh
);
1177 static struct buffer_head
*minix_update_inode(struct inode
*inode
)
1179 if (INODE_VERSION(inode
) == MINIX_V1
)
1180 return V1_minix_update_inode(inode
);
1182 return V2_minix_update_inode(inode
);
1185 static void minix_write_inode(struct inode
* inode
, int wait
)
1187 struct buffer_head
*bh
;
1190 bh
= minix_update_inode(inode
);
1195 int minix_sync_inode(struct inode
* inode
)
1198 struct buffer_head
*bh
;
1200 bh
= minix_update_inode(inode
);
1201 if (bh
&& buffer_dirty(bh
))
1203 ll_rw_block(WRITE
, 1, &bh
);
1205 if (buffer_req(bh
) && !buffer_uptodate(bh
))
1207 printk ("IO error syncing minix inode ["
1209 kdevname(inode
->i_dev
), inode
->i_ino
);
1219 static DECLARE_FSTYPE_DEV(minix_fs_type
,"minix",minix_read_super
);
1221 static int __init
init_minix_fs(void)
1223 return register_filesystem(&minix_fs_type
);
1226 static void __exit
exit_minix_fs(void)
1228 unregister_filesystem(&minix_fs_type
);
1233 module_init(init_minix_fs
)
1234 module_exit(exit_minix_fs
)