5 * Daniel Pirkl <daniel.pirkl@email.cz>
6 * Charles University, Faculty of Mathematics and Physics
10 * linux/fs/ext2/inode.c
12 * Copyright (C) 1992, 1993, 1994, 1995
13 * Remy Card (card@masi.ibp.fr)
14 * Laboratoire MASI - Institut Blaise Pascal
15 * Universite Pierre et Marie Curie (Paris VI)
19 * linux/fs/minix/inode.c
21 * Copyright (C) 1991, 1992 Linus Torvalds
23 * Goal-directed block allocation by Stephen Tweedie (sct@dcs.ed.ac.uk), 1993
24 * Big-endian to little-endian byte-swapping/bitmaps by
25 * David S. Miller (davem@caip.rutgers.edu), 1995
28 #include <asm/uaccess.h>
29 #include <asm/system.h>
31 #include <linux/errno.h>
33 #include <linux/ufs_fs.h>
34 #include <linux/time.h>
35 #include <linux/stat.h>
36 #include <linux/string.h>
38 #include <linux/smp_lock.h>
39 #include <linux/buffer_head.h>
44 #undef UFS_INODE_DEBUG
45 #undef UFS_INODE_DEBUG_MORE
47 #ifdef UFS_INODE_DEBUG
48 #define UFSD(x) printk("(%s, %d), %s: ", __FILE__, __LINE__, __FUNCTION__); printk x;
53 static int ufs_block_to_path(struct inode
*inode
, sector_t i_block
, sector_t offsets
[4])
55 struct ufs_sb_private_info
*uspi
= UFS_SB(inode
->i_sb
)->s_uspi
;
56 int ptrs
= uspi
->s_apb
;
57 int ptrs_bits
= uspi
->s_apbshift
;
58 const long direct_blocks
= UFS_NDADDR
,
59 indirect_blocks
= ptrs
,
60 double_blocks
= (1 << (ptrs_bits
* 2));
64 UFSD(("ptrs=uspi->s_apb = %d,double_blocks=%d \n",ptrs
,double_blocks
));
66 ufs_warning(inode
->i_sb
, "ufs_block_to_path", "block < 0");
67 } else if (i_block
< direct_blocks
) {
68 offsets
[n
++] = i_block
;
69 } else if ((i_block
-= direct_blocks
) < indirect_blocks
) {
70 offsets
[n
++] = UFS_IND_BLOCK
;
71 offsets
[n
++] = i_block
;
72 } else if ((i_block
-= indirect_blocks
) < double_blocks
) {
73 offsets
[n
++] = UFS_DIND_BLOCK
;
74 offsets
[n
++] = i_block
>> ptrs_bits
;
75 offsets
[n
++] = i_block
& (ptrs
- 1);
76 } else if (((i_block
-= double_blocks
) >> (ptrs_bits
* 2)) < ptrs
) {
77 offsets
[n
++] = UFS_TIND_BLOCK
;
78 offsets
[n
++] = i_block
>> (ptrs_bits
* 2);
79 offsets
[n
++] = (i_block
>> ptrs_bits
) & (ptrs
- 1);
80 offsets
[n
++] = i_block
& (ptrs
- 1);
82 ufs_warning(inode
->i_sb
, "ufs_block_to_path", "block > big");
88 * Returns the location of the fragment from
89 * the begining of the filesystem.
92 u64
ufs_frag_map(struct inode
*inode
, sector_t frag
)
94 struct ufs_inode_info
*ufsi
= UFS_I(inode
);
95 struct super_block
*sb
= inode
->i_sb
;
96 struct ufs_sb_private_info
*uspi
= UFS_SB(sb
)->s_uspi
;
97 u64 mask
= (u64
) uspi
->s_apbmask
>>uspi
->s_fpbshift
;
98 int shift
= uspi
->s_apbshift
-uspi
->s_fpbshift
;
99 sector_t offsets
[4], *p
;
100 int depth
= ufs_block_to_path(inode
, frag
>> uspi
->s_fpbshift
, offsets
);
103 __fs64 u2_block
= 0L;
104 unsigned flags
= UFS_SB(sb
)->s_flags
;
107 UFSD((": frag = %lu depth = %d\n",frag
,depth
));
108 UFSD((": uspi->s_fpbshift = %d ,uspi->s_apbmask = %x, mask=%llx\n",uspi
->s_fpbshift
,uspi
->s_apbmask
,mask
));
116 if ((flags
& UFS_TYPE_MASK
) == UFS_TYPE_UFS2
)
119 block
= ufsi
->i_u1
.i_data
[*p
++];
123 struct buffer_head
*bh
;
126 bh
= sb_bread(sb
, uspi
->s_sbbase
+ fs32_to_cpu(sb
, block
)+(n
>>shift
));
129 block
= ((__fs32
*) bh
->b_data
)[n
& mask
];
134 ret
= (u64
) (uspi
->s_sbbase
+ fs32_to_cpu(sb
, block
) + (frag
& uspi
->s_fpbmask
));
137 u2_block
= ufsi
->i_u1
.u2_i_data
[*p
++];
143 struct buffer_head
*bh
;
147 temp
= (u64
)(uspi
->s_sbbase
) + fs64_to_cpu(sb
, u2_block
);
148 bh
= sb_bread(sb
, temp
+(u64
) (n
>>shift
));
151 u2_block
= ((__fs64
*)bh
->b_data
)[n
& mask
];
156 temp
= (u64
)uspi
->s_sbbase
+ fs64_to_cpu(sb
, u2_block
);
157 ret
= temp
+ (u64
) (frag
& uspi
->s_fpbmask
);
164 static struct buffer_head
* ufs_inode_getfrag (struct inode
*inode
,
165 unsigned int fragment
, unsigned int new_fragment
,
166 unsigned int required
, int *err
, int metadata
, long *phys
, int *new)
168 struct ufs_inode_info
*ufsi
= UFS_I(inode
);
169 struct super_block
* sb
;
170 struct ufs_sb_private_info
* uspi
;
171 struct buffer_head
* result
;
172 unsigned block
, blockoff
, lastfrag
, lastblock
, lastblockoff
;
177 UFSD(("ENTER, ino %lu, fragment %u, new_fragment %u, required %u\n",
178 inode
->i_ino
, fragment
, new_fragment
, required
))
181 uspi
= UFS_SB(sb
)->s_uspi
;
183 flags
= UFS_SB(sb
)->s_flags
;
184 /* TODO : to be done for write support
185 if ( (flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2)
189 block
= ufs_fragstoblks (fragment
);
190 blockoff
= ufs_fragnum (fragment
);
191 p
= ufsi
->i_u1
.i_data
+ block
;
195 tmp
= fs32_to_cpu(sb
, *p
);
196 lastfrag
= ufsi
->i_lastfrag
;
197 if (tmp
&& fragment
< lastfrag
) {
199 result
= sb_getblk(sb
, uspi
->s_sbbase
+ tmp
+ blockoff
);
200 if (tmp
== fs32_to_cpu(sb
, *p
)) {
201 UFSD(("EXIT, result %u\n", tmp
+ blockoff
))
212 lastblock
= ufs_fragstoblks (lastfrag
);
213 lastblockoff
= ufs_fragnum (lastfrag
);
215 * We will extend file into new block beyond last allocated block
217 if (lastblock
< block
) {
219 * We must reallocate last allocated block
222 p2
= ufsi
->i_u1
.i_data
+ lastblock
;
223 tmp
= ufs_new_fragments (inode
, p2
, lastfrag
,
224 fs32_to_cpu(sb
, *p2
), uspi
->s_fpb
- lastblockoff
, err
);
226 if (lastfrag
!= ufsi
->i_lastfrag
)
231 lastfrag
= ufsi
->i_lastfrag
;
234 goal
= fs32_to_cpu(sb
, ufsi
->i_u1
.i_data
[lastblock
]) + uspi
->s_fpb
;
235 tmp
= ufs_new_fragments (inode
, p
, fragment
- blockoff
,
236 goal
, required
+ blockoff
, err
);
239 * We will extend last allocated block
241 else if (lastblock
== block
) {
242 tmp
= ufs_new_fragments (inode
, p
, fragment
- (blockoff
- lastblockoff
),
243 fs32_to_cpu(sb
, *p
), required
+ (blockoff
- lastblockoff
), err
);
246 * We will allocate new block before last allocated block
248 else /* (lastblock > block) */ {
249 if (lastblock
&& (tmp
= fs32_to_cpu(sb
, ufsi
->i_u1
.i_data
[lastblock
-1])))
250 goal
= tmp
+ uspi
->s_fpb
;
251 tmp
= ufs_new_fragments (inode
, p
, fragment
- blockoff
,
252 goal
, uspi
->s_fpb
, err
);
255 if ((!blockoff
&& *p
) ||
256 (blockoff
&& lastfrag
!= ufsi
->i_lastfrag
))
262 /* The nullification of framgents done in ufs/balloc.c is
263 * something I don't have the stomache to move into here right
267 result
= sb_getblk(inode
->i_sb
, tmp
+ blockoff
);
275 inode
->i_ctime
= CURRENT_TIME_SEC
;
277 ufs_sync_inode (inode
);
278 mark_inode_dirty(inode
);
279 UFSD(("EXIT, result %u\n", tmp
+ blockoff
))
282 /* This part : To be implemented ....
283 Required only for writing, not required for READ-ONLY.
286 u2_block = ufs_fragstoblks(fragment);
287 u2_blockoff = ufs_fragnum(fragment);
288 p = ufsi->i_u1.u2_i_data + block;
292 tmp = fs32_to_cpu(sb, *p);
293 lastfrag = ufsi->i_lastfrag;
298 static struct buffer_head
* ufs_block_getfrag (struct inode
*inode
,
299 struct buffer_head
*bh
, unsigned int fragment
, unsigned int new_fragment
,
300 unsigned int blocksize
, int * err
, int metadata
, long *phys
, int *new)
302 struct super_block
* sb
;
303 struct ufs_sb_private_info
* uspi
;
304 struct buffer_head
* result
;
305 unsigned tmp
, goal
, block
, blockoff
;
309 uspi
= UFS_SB(sb
)->s_uspi
;
310 block
= ufs_fragstoblks (fragment
);
311 blockoff
= ufs_fragnum (fragment
);
313 UFSD(("ENTER, ino %lu, fragment %u, new_fragment %u\n", inode
->i_ino
, fragment
, new_fragment
))
318 if (!buffer_uptodate(bh
)) {
319 ll_rw_block (READ
, 1, &bh
);
321 if (!buffer_uptodate(bh
))
325 p
= (__fs32
*) bh
->b_data
+ block
;
327 tmp
= fs32_to_cpu(sb
, *p
);
330 result
= sb_getblk(sb
, uspi
->s_sbbase
+ tmp
+ blockoff
);
331 if (tmp
== fs32_to_cpu(sb
, *p
))
341 if (block
&& (tmp
= fs32_to_cpu(sb
, ((__fs32
*)bh
->b_data
)[block
-1]) + uspi
->s_fpb
))
342 goal
= tmp
+ uspi
->s_fpb
;
344 goal
= bh
->b_blocknr
+ uspi
->s_fpb
;
345 tmp
= ufs_new_fragments (inode
, p
, ufs_blknum(new_fragment
), goal
, uspi
->s_fpb
, err
);
347 if (fs32_to_cpu(sb
, *p
))
352 /* The nullification of framgents done in ufs/balloc.c is
353 * something I don't have the stomache to move into here right
357 result
= sb_getblk(sb
, tmp
+ blockoff
);
363 mark_buffer_dirty(bh
);
365 sync_dirty_buffer(bh
);
366 inode
->i_ctime
= CURRENT_TIME_SEC
;
367 mark_inode_dirty(inode
);
370 UFSD(("EXIT, result %u\n", tmp
+ blockoff
))
375 * This function gets the block which contains the fragment.
378 static int ufs_getfrag_block (struct inode
*inode
, sector_t fragment
, struct buffer_head
*bh_result
, int create
)
380 struct super_block
* sb
= inode
->i_sb
;
381 struct ufs_sb_private_info
* uspi
= UFS_SB(sb
)->s_uspi
;
382 struct buffer_head
* bh
;
384 unsigned long ptr
,phys
;
388 phys64
= ufs_frag_map(inode
, fragment
);
389 UFSD(("phys64 = %lu \n",phys64
));
391 map_bh(bh_result
, sb
, phys64
);
395 /* This code entered only while writing ....? */
404 UFSD(("ENTER, ino %lu, fragment %u\n", inode
->i_ino
, fragment
))
408 ((UFS_NDADDR
+ uspi
->s_apb
+ uspi
->s_2apb
+ uspi
->s_3apb
)
409 << uspi
->s_fpbshift
))
416 * ok, these macros clean the logic up a bit and make
417 * it much more readable:
419 #define GET_INODE_DATABLOCK(x) \
420 ufs_inode_getfrag(inode, x, fragment, 1, &err, 0, &phys, &new)
421 #define GET_INODE_PTR(x) \
422 ufs_inode_getfrag(inode, x, fragment, uspi->s_fpb, &err, 1, NULL, NULL)
423 #define GET_INDIRECT_DATABLOCK(x) \
424 ufs_block_getfrag(inode, bh, x, fragment, sb->s_blocksize, \
425 &err, 0, &phys, &new);
426 #define GET_INDIRECT_PTR(x) \
427 ufs_block_getfrag(inode, bh, x, fragment, sb->s_blocksize, \
428 &err, 1, NULL, NULL);
430 if (ptr
< UFS_NDIR_FRAGMENT
) {
431 bh
= GET_INODE_DATABLOCK(ptr
);
434 ptr
-= UFS_NDIR_FRAGMENT
;
435 if (ptr
< (1 << (uspi
->s_apbshift
+ uspi
->s_fpbshift
))) {
436 bh
= GET_INODE_PTR(UFS_IND_FRAGMENT
+ (ptr
>> uspi
->s_apbshift
));
439 ptr
-= 1 << (uspi
->s_apbshift
+ uspi
->s_fpbshift
);
440 if (ptr
< (1 << (uspi
->s_2apbshift
+ uspi
->s_fpbshift
))) {
441 bh
= GET_INODE_PTR(UFS_DIND_FRAGMENT
+ (ptr
>> uspi
->s_2apbshift
));
444 ptr
-= 1 << (uspi
->s_2apbshift
+ uspi
->s_fpbshift
);
445 bh
= GET_INODE_PTR(UFS_TIND_FRAGMENT
+ (ptr
>> uspi
->s_3apbshift
));
446 bh
= GET_INDIRECT_PTR((ptr
>> uspi
->s_2apbshift
) & uspi
->s_apbmask
);
448 bh
= GET_INDIRECT_PTR((ptr
>> uspi
->s_apbshift
) & uspi
->s_apbmask
);
450 bh
= GET_INDIRECT_DATABLOCK(ptr
& uspi
->s_apbmask
);
452 #undef GET_INODE_DATABLOCK
454 #undef GET_INDIRECT_DATABLOCK
455 #undef GET_INDIRECT_PTR
461 set_buffer_new(bh_result
);
462 map_bh(bh_result
, sb
, phys
);
468 ufs_warning(sb
, "ufs_get_block", "block < 0");
472 ufs_warning(sb
, "ufs_get_block", "block > big");
476 struct buffer_head
*ufs_getfrag(struct inode
*inode
, unsigned int fragment
,
477 int create
, int *err
)
479 struct buffer_head dummy
;
483 dummy
.b_blocknr
= -1000;
484 error
= ufs_getfrag_block(inode
, fragment
, &dummy
, create
);
486 if (!error
&& buffer_mapped(&dummy
)) {
487 struct buffer_head
*bh
;
488 bh
= sb_getblk(inode
->i_sb
, dummy
.b_blocknr
);
489 if (buffer_new(&dummy
)) {
490 memset(bh
->b_data
, 0, inode
->i_sb
->s_blocksize
);
491 set_buffer_uptodate(bh
);
492 mark_buffer_dirty(bh
);
499 struct buffer_head
* ufs_bread (struct inode
* inode
, unsigned fragment
,
500 int create
, int * err
)
502 struct buffer_head
* bh
;
504 UFSD(("ENTER, ino %lu, fragment %u\n", inode
->i_ino
, fragment
))
505 bh
= ufs_getfrag (inode
, fragment
, create
, err
);
506 if (!bh
|| buffer_uptodate(bh
))
508 ll_rw_block (READ
, 1, &bh
);
510 if (buffer_uptodate(bh
))
517 static int ufs_writepage(struct page
*page
, struct writeback_control
*wbc
)
519 return block_write_full_page(page
,ufs_getfrag_block
,wbc
);
521 static int ufs_readpage(struct file
*file
, struct page
*page
)
523 return block_read_full_page(page
,ufs_getfrag_block
);
525 static int ufs_prepare_write(struct file
*file
, struct page
*page
, unsigned from
, unsigned to
)
527 return block_prepare_write(page
,from
,to
,ufs_getfrag_block
);
529 static sector_t
ufs_bmap(struct address_space
*mapping
, sector_t block
)
531 return generic_block_bmap(mapping
,block
,ufs_getfrag_block
);
533 struct address_space_operations ufs_aops
= {
534 .readpage
= ufs_readpage
,
535 .writepage
= ufs_writepage
,
536 .sync_page
= block_sync_page
,
537 .prepare_write
= ufs_prepare_write
,
538 .commit_write
= generic_commit_write
,
542 void ufs_read_inode (struct inode
* inode
)
544 struct ufs_inode_info
*ufsi
= UFS_I(inode
);
545 struct super_block
* sb
;
546 struct ufs_sb_private_info
* uspi
;
547 struct ufs_inode
* ufs_inode
;
548 struct ufs2_inode
*ufs2_inode
;
549 struct buffer_head
* bh
;
554 UFSD(("ENTER, ino %lu\n", inode
->i_ino
))
557 uspi
= UFS_SB(sb
)->s_uspi
;
558 flags
= UFS_SB(sb
)->s_flags
;
560 if (inode
->i_ino
< UFS_ROOTINO
||
561 inode
->i_ino
> (uspi
->s_ncg
* uspi
->s_ipg
)) {
562 ufs_warning (sb
, "ufs_read_inode", "bad inode number (%lu)\n", inode
->i_ino
);
566 bh
= sb_bread(sb
, uspi
->s_sbbase
+ ufs_inotofsba(inode
->i_ino
));
568 ufs_warning (sb
, "ufs_read_inode", "unable to read inode %lu\n", inode
->i_ino
);
571 if ((flags
& UFS_TYPE_MASK
) == UFS_TYPE_UFS2
)
574 ufs_inode
= (struct ufs_inode
*) (bh
->b_data
+ sizeof(struct ufs_inode
) * ufs_inotofsbo(inode
->i_ino
));
577 * Copy data to the in-core inode.
579 inode
->i_mode
= mode
= fs16_to_cpu(sb
, ufs_inode
->ui_mode
);
580 inode
->i_nlink
= fs16_to_cpu(sb
, ufs_inode
->ui_nlink
);
581 if (inode
->i_nlink
== 0)
582 ufs_error (sb
, "ufs_read_inode", "inode %lu has zero nlink\n", inode
->i_ino
);
585 * Linux now has 32-bit uid and gid, so we can support EFT.
587 inode
->i_uid
= ufs_get_inode_uid(sb
, ufs_inode
);
588 inode
->i_gid
= ufs_get_inode_gid(sb
, ufs_inode
);
590 inode
->i_size
= fs64_to_cpu(sb
, ufs_inode
->ui_size
);
591 inode
->i_atime
.tv_sec
= fs32_to_cpu(sb
, ufs_inode
->ui_atime
.tv_sec
);
592 inode
->i_ctime
.tv_sec
= fs32_to_cpu(sb
, ufs_inode
->ui_ctime
.tv_sec
);
593 inode
->i_mtime
.tv_sec
= fs32_to_cpu(sb
, ufs_inode
->ui_mtime
.tv_sec
);
594 inode
->i_mtime
.tv_nsec
= 0;
595 inode
->i_atime
.tv_nsec
= 0;
596 inode
->i_ctime
.tv_nsec
= 0;
597 inode
->i_blocks
= fs32_to_cpu(sb
, ufs_inode
->ui_blocks
);
598 inode
->i_blksize
= PAGE_SIZE
; /* This is the optimal IO size (for stat) */
600 ufsi
->i_flags
= fs32_to_cpu(sb
, ufs_inode
->ui_flags
);
601 ufsi
->i_gen
= fs32_to_cpu(sb
, ufs_inode
->ui_gen
);
602 ufsi
->i_shadow
= fs32_to_cpu(sb
, ufs_inode
->ui_u3
.ui_sun
.ui_shadow
);
603 ufsi
->i_oeftflag
= fs32_to_cpu(sb
, ufs_inode
->ui_u3
.ui_sun
.ui_oeftflag
);
604 ufsi
->i_lastfrag
= (inode
->i_size
+ uspi
->s_fsize
- 1) >> uspi
->s_fshift
;
606 if (S_ISCHR(mode
) || S_ISBLK(mode
) || inode
->i_blocks
) {
607 for (i
= 0; i
< (UFS_NDADDR
+ UFS_NINDIR
); i
++)
608 ufsi
->i_u1
.i_data
[i
] = ufs_inode
->ui_u2
.ui_addr
.ui_db
[i
];
611 for (i
= 0; i
< (UFS_NDADDR
+ UFS_NINDIR
) * 4; i
++)
612 ufsi
->i_u1
.i_symlink
[i
] = ufs_inode
->ui_u2
.ui_symlink
[i
];
616 if (S_ISREG(inode
->i_mode
)) {
617 inode
->i_op
= &ufs_file_inode_operations
;
618 inode
->i_fop
= &ufs_file_operations
;
619 inode
->i_mapping
->a_ops
= &ufs_aops
;
620 } else if (S_ISDIR(inode
->i_mode
)) {
621 inode
->i_op
= &ufs_dir_inode_operations
;
622 inode
->i_fop
= &ufs_dir_operations
;
623 } else if (S_ISLNK(inode
->i_mode
)) {
624 if (!inode
->i_blocks
)
625 inode
->i_op
= &ufs_fast_symlink_inode_operations
;
627 inode
->i_op
= &page_symlink_inode_operations
;
628 inode
->i_mapping
->a_ops
= &ufs_aops
;
631 init_special_inode(inode
, inode
->i_mode
,
632 ufs_get_inode_dev(sb
, ufsi
));
640 make_bad_inode(inode
);
644 UFSD(("Reading ufs2 inode, ino %lu\n", inode
->i_ino
))
646 ufs2_inode
= (struct ufs2_inode
*)(bh
->b_data
+ sizeof(struct ufs2_inode
) * ufs_inotofsbo(inode
->i_ino
));
649 * Copy data to the in-core inode.
651 inode
->i_mode
= mode
= fs16_to_cpu(sb
, ufs2_inode
->ui_mode
);
652 inode
->i_nlink
= fs16_to_cpu(sb
, ufs2_inode
->ui_nlink
);
653 if (inode
->i_nlink
== 0)
654 ufs_error (sb
, "ufs_read_inode", "inode %lu has zero nlink\n", inode
->i_ino
);
657 * Linux now has 32-bit uid and gid, so we can support EFT.
659 inode
->i_uid
= fs32_to_cpu(sb
, ufs2_inode
->ui_uid
);
660 inode
->i_gid
= fs32_to_cpu(sb
, ufs2_inode
->ui_gid
);
662 inode
->i_size
= fs64_to_cpu(sb
, ufs2_inode
->ui_size
);
663 inode
->i_atime
.tv_sec
= fs32_to_cpu(sb
, ufs2_inode
->ui_atime
.tv_sec
);
664 inode
->i_ctime
.tv_sec
= fs32_to_cpu(sb
, ufs2_inode
->ui_ctime
.tv_sec
);
665 inode
->i_mtime
.tv_sec
= fs32_to_cpu(sb
, ufs2_inode
->ui_mtime
.tv_sec
);
666 inode
->i_mtime
.tv_nsec
= 0;
667 inode
->i_atime
.tv_nsec
= 0;
668 inode
->i_ctime
.tv_nsec
= 0;
669 inode
->i_blocks
= fs64_to_cpu(sb
, ufs2_inode
->ui_blocks
);
670 inode
->i_blksize
= PAGE_SIZE
; /*This is the optimal IO size(for stat)*/
673 ufsi
->i_flags
= fs32_to_cpu(sb
, ufs2_inode
->ui_flags
);
674 ufsi
->i_gen
= fs32_to_cpu(sb
, ufs2_inode
->ui_gen
);
676 ufsi->i_shadow = fs32_to_cpu(sb, ufs_inode->ui_u3.ui_sun.ui_shadow);
677 ufsi->i_oeftflag = fs32_to_cpu(sb, ufs_inode->ui_u3.ui_sun.ui_oeftflag);
679 ufsi
->i_lastfrag
= (inode
->i_size
+ uspi
->s_fsize
- 1) >> uspi
->s_fshift
;
681 if (S_ISCHR(mode
) || S_ISBLK(mode
) || inode
->i_blocks
) {
682 for (i
= 0; i
< (UFS_NDADDR
+ UFS_NINDIR
); i
++)
683 ufsi
->i_u1
.u2_i_data
[i
] =
684 ufs2_inode
->ui_u2
.ui_addr
.ui_db
[i
];
687 for (i
= 0; i
< (UFS_NDADDR
+ UFS_NINDIR
) * 4; i
++)
688 ufsi
->i_u1
.i_symlink
[i
] = ufs2_inode
->ui_u2
.ui_symlink
[i
];
692 if (S_ISREG(inode
->i_mode
)) {
693 inode
->i_op
= &ufs_file_inode_operations
;
694 inode
->i_fop
= &ufs_file_operations
;
695 inode
->i_mapping
->a_ops
= &ufs_aops
;
696 } else if (S_ISDIR(inode
->i_mode
)) {
697 inode
->i_op
= &ufs_dir_inode_operations
;
698 inode
->i_fop
= &ufs_dir_operations
;
699 } else if (S_ISLNK(inode
->i_mode
)) {
700 if (!inode
->i_blocks
)
701 inode
->i_op
= &ufs_fast_symlink_inode_operations
;
703 inode
->i_op
= &page_symlink_inode_operations
;
704 inode
->i_mapping
->a_ops
= &ufs_aops
;
706 } else /* TODO : here ...*/
707 init_special_inode(inode
, inode
->i_mode
,
708 ufs_get_inode_dev(sb
, ufsi
));
716 static int ufs_update_inode(struct inode
* inode
, int do_sync
)
718 struct ufs_inode_info
*ufsi
= UFS_I(inode
);
719 struct super_block
* sb
;
720 struct ufs_sb_private_info
* uspi
;
721 struct buffer_head
* bh
;
722 struct ufs_inode
* ufs_inode
;
726 UFSD(("ENTER, ino %lu\n", inode
->i_ino
))
729 uspi
= UFS_SB(sb
)->s_uspi
;
730 flags
= UFS_SB(sb
)->s_flags
;
732 if (inode
->i_ino
< UFS_ROOTINO
||
733 inode
->i_ino
> (uspi
->s_ncg
* uspi
->s_ipg
)) {
734 ufs_warning (sb
, "ufs_read_inode", "bad inode number (%lu)\n", inode
->i_ino
);
738 bh
= sb_bread(sb
, ufs_inotofsba(inode
->i_ino
));
740 ufs_warning (sb
, "ufs_read_inode", "unable to read inode %lu\n", inode
->i_ino
);
743 ufs_inode
= (struct ufs_inode
*) (bh
->b_data
+ ufs_inotofsbo(inode
->i_ino
) * sizeof(struct ufs_inode
));
745 ufs_inode
->ui_mode
= cpu_to_fs16(sb
, inode
->i_mode
);
746 ufs_inode
->ui_nlink
= cpu_to_fs16(sb
, inode
->i_nlink
);
748 ufs_set_inode_uid(sb
, ufs_inode
, inode
->i_uid
);
749 ufs_set_inode_gid(sb
, ufs_inode
, inode
->i_gid
);
751 ufs_inode
->ui_size
= cpu_to_fs64(sb
, inode
->i_size
);
752 ufs_inode
->ui_atime
.tv_sec
= cpu_to_fs32(sb
, inode
->i_atime
.tv_sec
);
753 ufs_inode
->ui_atime
.tv_usec
= 0;
754 ufs_inode
->ui_ctime
.tv_sec
= cpu_to_fs32(sb
, inode
->i_ctime
.tv_sec
);
755 ufs_inode
->ui_ctime
.tv_usec
= 0;
756 ufs_inode
->ui_mtime
.tv_sec
= cpu_to_fs32(sb
, inode
->i_mtime
.tv_sec
);
757 ufs_inode
->ui_mtime
.tv_usec
= 0;
758 ufs_inode
->ui_blocks
= cpu_to_fs32(sb
, inode
->i_blocks
);
759 ufs_inode
->ui_flags
= cpu_to_fs32(sb
, ufsi
->i_flags
);
760 ufs_inode
->ui_gen
= cpu_to_fs32(sb
, ufsi
->i_gen
);
762 if ((flags
& UFS_UID_MASK
) == UFS_UID_EFT
) {
763 ufs_inode
->ui_u3
.ui_sun
.ui_shadow
= cpu_to_fs32(sb
, ufsi
->i_shadow
);
764 ufs_inode
->ui_u3
.ui_sun
.ui_oeftflag
= cpu_to_fs32(sb
, ufsi
->i_oeftflag
);
767 if (S_ISCHR(inode
->i_mode
) || S_ISBLK(inode
->i_mode
)) {
768 /* ufs_inode->ui_u2.ui_addr.ui_db[0] = cpu_to_fs32(sb, inode->i_rdev); */
769 ufs_inode
->ui_u2
.ui_addr
.ui_db
[0] = ufsi
->i_u1
.i_data
[0];
770 } else if (inode
->i_blocks
) {
771 for (i
= 0; i
< (UFS_NDADDR
+ UFS_NINDIR
); i
++)
772 ufs_inode
->ui_u2
.ui_addr
.ui_db
[i
] = ufsi
->i_u1
.i_data
[i
];
775 for (i
= 0; i
< (UFS_NDADDR
+ UFS_NINDIR
) * 4; i
++)
776 ufs_inode
->ui_u2
.ui_symlink
[i
] = ufsi
->i_u1
.i_symlink
[i
];
780 memset (ufs_inode
, 0, sizeof(struct ufs_inode
));
782 mark_buffer_dirty(bh
);
784 sync_dirty_buffer(bh
);
791 int ufs_write_inode (struct inode
* inode
, int wait
)
795 ret
= ufs_update_inode (inode
, wait
);
800 int ufs_sync_inode (struct inode
*inode
)
802 return ufs_update_inode (inode
, 1);
805 void ufs_delete_inode (struct inode
* inode
)
807 /*UFS_I(inode)->i_dtime = CURRENT_TIME;*/
809 mark_inode_dirty(inode
);
810 ufs_update_inode(inode
, IS_SYNC(inode
));
813 ufs_truncate (inode
);
814 ufs_free_inode (inode
);