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 static int ufs_block_to_path(struct inode *inode, sector_t i_block, sector_t offsets[4])
46 struct ufs_sb_private_info *uspi = UFS_SB(inode->i_sb)->s_uspi;
47 int ptrs = uspi->s_apb;
48 int ptrs_bits = uspi->s_apbshift;
49 const long direct_blocks = UFS_NDADDR,
50 indirect_blocks = ptrs,
51 double_blocks = (1 << (ptrs_bits * 2));
55 UFSD("ptrs=uspi->s_apb = %d,double_blocks=%ld \n",ptrs,double_blocks);
57 ufs_warning(inode->i_sb, "ufs_block_to_path", "block < 0");
58 } else if (i_block < direct_blocks) {
59 offsets[n++] = i_block;
60 } else if ((i_block -= direct_blocks) < indirect_blocks) {
61 offsets[n++] = UFS_IND_BLOCK;
62 offsets[n++] = i_block;
63 } else if ((i_block -= indirect_blocks) < double_blocks) {
64 offsets[n++] = UFS_DIND_BLOCK;
65 offsets[n++] = i_block >> ptrs_bits;
66 offsets[n++] = i_block & (ptrs - 1);
67 } else if (((i_block -= double_blocks) >> (ptrs_bits * 2)) < ptrs) {
68 offsets[n++] = UFS_TIND_BLOCK;
69 offsets[n++] = i_block >> (ptrs_bits * 2);
70 offsets[n++] = (i_block >> ptrs_bits) & (ptrs - 1);
71 offsets[n++] = i_block & (ptrs - 1);
73 ufs_warning(inode->i_sb, "ufs_block_to_path", "block > big");
79 * Returns the location of the fragment from
80 * the begining of the filesystem.
83 u64 ufs_frag_map(struct inode *inode, sector_t frag)
85 struct ufs_inode_info *ufsi = UFS_I(inode);
86 struct super_block *sb = inode->i_sb;
87 struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
88 u64 mask = (u64) uspi->s_apbmask>>uspi->s_fpbshift;
89 int shift = uspi->s_apbshift-uspi->s_fpbshift;
90 sector_t offsets[4], *p;
91 int depth = ufs_block_to_path(inode, frag >> uspi->s_fpbshift, offsets);
95 unsigned flags = UFS_SB(sb)->s_flags;
98 UFSD(": frag = %llu depth = %d\n", (unsigned long long)frag, depth);
99 UFSD(": uspi->s_fpbshift = %d ,uspi->s_apbmask = %x, mask=%llx\n",uspi->s_fpbshift,uspi->s_apbmask,mask);
107 if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2)
110 block = ufsi->i_u1.i_data[*p++];
114 struct buffer_head *bh;
117 bh = sb_bread(sb, uspi->s_sbbase + fs32_to_cpu(sb, block)+(n>>shift));
120 block = ((__fs32 *) bh->b_data)[n & mask];
125 ret = (u64) (uspi->s_sbbase + fs32_to_cpu(sb, block) + (frag & uspi->s_fpbmask));
128 u2_block = ufsi->i_u1.u2_i_data[*p++];
134 struct buffer_head *bh;
138 temp = (u64)(uspi->s_sbbase) + fs64_to_cpu(sb, u2_block);
139 bh = sb_bread(sb, temp +(u64) (n>>shift));
142 u2_block = ((__fs64 *)bh->b_data)[n & mask];
147 temp = (u64)uspi->s_sbbase + fs64_to_cpu(sb, u2_block);
148 ret = temp + (u64) (frag & uspi->s_fpbmask);
155 static void ufs_clear_frag(struct inode *inode, struct buffer_head *bh)
158 memset(bh->b_data, 0, inode->i_sb->s_blocksize);
159 set_buffer_uptodate(bh);
160 mark_buffer_dirty(bh);
163 sync_dirty_buffer(bh);
166 static struct buffer_head *
167 ufs_clear_frags(struct inode *inode, sector_t beg,
170 struct buffer_head *res, *bh;
171 sector_t end = beg + n;
173 res = sb_getblk(inode->i_sb, beg);
174 ufs_clear_frag(inode, res);
175 for (++beg; beg < end; ++beg) {
176 bh = sb_getblk(inode->i_sb, beg);
177 ufs_clear_frag(inode, bh);
184 * ufs_inode_getfrag() - allocate new fragment(s)
185 * @inode - pointer to inode
186 * @fragment - number of `fragment' which hold pointer
187 * to new allocated fragment(s)
188 * @new_fragment - number of new allocated fragment(s)
189 * @required - how many fragment(s) we require
190 * @err - we set it if something wrong
191 * @phys - pointer to where we save physical number of new allocated fragments,
192 * NULL if we allocate not data(indirect blocks for example).
193 * @new - we set it if we allocate new block
194 * @locked_page - for ufs_new_fragments()
196 static struct buffer_head *
197 ufs_inode_getfrag(struct inode *inode, unsigned int fragment,
198 sector_t new_fragment, unsigned int required, int *err,
199 long *phys, int *new, struct page *locked_page)
201 struct ufs_inode_info *ufsi = UFS_I(inode);
202 struct super_block *sb = inode->i_sb;
203 struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
204 struct buffer_head * result;
205 unsigned block, blockoff, lastfrag, lastblock, lastblockoff;
209 UFSD("ENTER, ino %lu, fragment %u, new_fragment %llu, required %u, "
210 "metadata %d\n", inode->i_ino, fragment,
211 (unsigned long long)new_fragment, required, !phys);
213 /* TODO : to be done for write support
214 if ( (flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2)
218 block = ufs_fragstoblks (fragment);
219 blockoff = ufs_fragnum (fragment);
220 p = ufsi->i_u1.i_data + block;
224 tmp = fs32_to_cpu(sb, *p);
225 lastfrag = ufsi->i_lastfrag;
226 if (tmp && fragment < lastfrag) {
228 result = sb_getblk(sb, uspi->s_sbbase + tmp + blockoff);
229 if (tmp == fs32_to_cpu(sb, *p)) {
230 UFSD("EXIT, result %u\n", tmp + blockoff);
236 *phys = tmp + blockoff;
241 lastblock = ufs_fragstoblks (lastfrag);
242 lastblockoff = ufs_fragnum (lastfrag);
244 * We will extend file into new block beyond last allocated block
246 if (lastblock < block) {
248 * We must reallocate last allocated block
251 p2 = ufsi->i_u1.i_data + lastblock;
252 tmp = ufs_new_fragments (inode, p2, lastfrag,
253 fs32_to_cpu(sb, *p2), uspi->s_fpb - lastblockoff,
256 if (lastfrag != ufsi->i_lastfrag)
261 lastfrag = ufsi->i_lastfrag;
264 goal = fs32_to_cpu(sb, ufsi->i_u1.i_data[lastblock]) + uspi->s_fpb;
265 tmp = ufs_new_fragments (inode, p, fragment - blockoff,
266 goal, required + blockoff,
270 * We will extend last allocated block
272 else if (lastblock == block) {
273 tmp = ufs_new_fragments(inode, p, fragment - (blockoff - lastblockoff),
274 fs32_to_cpu(sb, *p), required + (blockoff - lastblockoff),
278 * We will allocate new block before last allocated block
280 else /* (lastblock > block) */ {
281 if (lastblock && (tmp = fs32_to_cpu(sb, ufsi->i_u1.i_data[lastblock-1])))
282 goal = tmp + uspi->s_fpb;
283 tmp = ufs_new_fragments(inode, p, fragment - blockoff,
284 goal, uspi->s_fpb, err, locked_page);
287 if ((!blockoff && *p) ||
288 (blockoff && lastfrag != ufsi->i_lastfrag))
295 result = ufs_clear_frags(inode, tmp + blockoff, required);
297 *phys = tmp + blockoff;
303 inode->i_ctime = CURRENT_TIME_SEC;
305 ufs_sync_inode (inode);
306 mark_inode_dirty(inode);
307 UFSD("EXIT, result %u\n", tmp + blockoff);
310 /* This part : To be implemented ....
311 Required only for writing, not required for READ-ONLY.
314 u2_block = ufs_fragstoblks(fragment);
315 u2_blockoff = ufs_fragnum(fragment);
316 p = ufsi->i_u1.u2_i_data + block;
320 tmp = fs32_to_cpu(sb, *p);
321 lastfrag = ufsi->i_lastfrag;
327 * ufs_inode_getblock() - allocate new block
328 * @inode - pointer to inode
329 * @bh - pointer to block which hold "pointer" to new allocated block
330 * @fragment - number of `fragment' which hold pointer
331 * to new allocated block
332 * @new_fragment - number of new allocated fragment
333 * (block will hold this fragment and also uspi->s_fpb-1)
334 * @err - see ufs_inode_getfrag()
335 * @phys - see ufs_inode_getfrag()
336 * @new - see ufs_inode_getfrag()
337 * @locked_page - see ufs_inode_getfrag()
339 static struct buffer_head *
340 ufs_inode_getblock(struct inode *inode, struct buffer_head *bh,
341 unsigned int fragment, sector_t new_fragment, int *err,
342 long *phys, int *new, struct page *locked_page)
344 struct super_block *sb = inode->i_sb;
345 struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
346 struct buffer_head * result;
347 unsigned tmp, goal, block, blockoff;
350 block = ufs_fragstoblks (fragment);
351 blockoff = ufs_fragnum (fragment);
353 UFSD("ENTER, ino %lu, fragment %u, new_fragment %llu, metadata %d\n",
354 inode->i_ino, fragment, (unsigned long long)new_fragment, !phys);
359 if (!buffer_uptodate(bh)) {
360 ll_rw_block (READ, 1, &bh);
362 if (!buffer_uptodate(bh))
366 p = (__fs32 *) bh->b_data + block;
368 tmp = fs32_to_cpu(sb, *p);
371 result = sb_getblk(sb, uspi->s_sbbase + tmp + blockoff);
372 if (tmp == fs32_to_cpu(sb, *p))
377 *phys = tmp + blockoff;
382 if (block && (tmp = fs32_to_cpu(sb, ((__fs32*)bh->b_data)[block-1]) + uspi->s_fpb))
383 goal = tmp + uspi->s_fpb;
385 goal = bh->b_blocknr + uspi->s_fpb;
386 tmp = ufs_new_fragments(inode, p, ufs_blknum(new_fragment), goal,
387 uspi->s_fpb, err, locked_page);
389 if (fs32_to_cpu(sb, *p))
396 result = ufs_clear_frags(inode, tmp + blockoff, uspi->s_fpb);
398 *phys = tmp + blockoff;
402 mark_buffer_dirty(bh);
404 sync_dirty_buffer(bh);
405 inode->i_ctime = CURRENT_TIME_SEC;
406 mark_inode_dirty(inode);
407 UFSD("result %u\n", tmp + blockoff);
415 * ufs_getfrag_bloc() - `get_block_t' function, interface between UFS and
416 * readpage, writepage and so on
419 int ufs_getfrag_block(struct inode *inode, sector_t fragment, struct buffer_head *bh_result, int create)
421 struct super_block * sb = inode->i_sb;
422 struct ufs_sb_private_info * uspi = UFS_SB(sb)->s_uspi;
423 struct buffer_head * bh;
425 unsigned long ptr,phys;
429 phys64 = ufs_frag_map(inode, fragment);
430 UFSD("phys64 = %llu \n",phys64);
432 map_bh(bh_result, sb, phys64);
436 /* This code entered only while writing ....? */
445 UFSD("ENTER, ino %lu, fragment %llu\n", inode->i_ino, (unsigned long long)fragment);
449 ((UFS_NDADDR + uspi->s_apb + uspi->s_2apb + uspi->s_3apb)
450 << uspi->s_fpbshift))
457 * ok, these macros clean the logic up a bit and make
458 * it much more readable:
460 #define GET_INODE_DATABLOCK(x) \
461 ufs_inode_getfrag(inode, x, fragment, 1, &err, &phys, &new, bh_result->b_page)
462 #define GET_INODE_PTR(x) \
463 ufs_inode_getfrag(inode, x, fragment, uspi->s_fpb, &err, NULL, NULL, bh_result->b_page)
464 #define GET_INDIRECT_DATABLOCK(x) \
465 ufs_inode_getblock(inode, bh, x, fragment, \
466 &err, &phys, &new, bh_result->b_page);
467 #define GET_INDIRECT_PTR(x) \
468 ufs_inode_getblock(inode, bh, x, fragment, \
469 &err, NULL, NULL, bh_result->b_page);
471 if (ptr < UFS_NDIR_FRAGMENT) {
472 bh = GET_INODE_DATABLOCK(ptr);
475 ptr -= UFS_NDIR_FRAGMENT;
476 if (ptr < (1 << (uspi->s_apbshift + uspi->s_fpbshift))) {
477 bh = GET_INODE_PTR(UFS_IND_FRAGMENT + (ptr >> uspi->s_apbshift));
480 ptr -= 1 << (uspi->s_apbshift + uspi->s_fpbshift);
481 if (ptr < (1 << (uspi->s_2apbshift + uspi->s_fpbshift))) {
482 bh = GET_INODE_PTR(UFS_DIND_FRAGMENT + (ptr >> uspi->s_2apbshift));
485 ptr -= 1 << (uspi->s_2apbshift + uspi->s_fpbshift);
486 bh = GET_INODE_PTR(UFS_TIND_FRAGMENT + (ptr >> uspi->s_3apbshift));
487 bh = GET_INDIRECT_PTR((ptr >> uspi->s_2apbshift) & uspi->s_apbmask);
489 bh = GET_INDIRECT_PTR((ptr >> uspi->s_apbshift) & uspi->s_apbmask);
491 bh = GET_INDIRECT_DATABLOCK(ptr & uspi->s_apbmask);
493 #undef GET_INODE_DATABLOCK
495 #undef GET_INDIRECT_DATABLOCK
496 #undef GET_INDIRECT_PTR
502 set_buffer_new(bh_result);
503 map_bh(bh_result, sb, phys);
509 ufs_warning(sb, "ufs_get_block", "block < 0");
513 ufs_warning(sb, "ufs_get_block", "block > big");
517 struct buffer_head *ufs_getfrag(struct inode *inode, unsigned int fragment,
518 int create, int *err)
520 struct buffer_head dummy;
524 dummy.b_blocknr = -1000;
525 error = ufs_getfrag_block(inode, fragment, &dummy, create);
527 if (!error && buffer_mapped(&dummy)) {
528 struct buffer_head *bh;
529 bh = sb_getblk(inode->i_sb, dummy.b_blocknr);
530 if (buffer_new(&dummy)) {
531 memset(bh->b_data, 0, inode->i_sb->s_blocksize);
532 set_buffer_uptodate(bh);
533 mark_buffer_dirty(bh);
540 struct buffer_head * ufs_bread (struct inode * inode, unsigned fragment,
541 int create, int * err)
543 struct buffer_head * bh;
545 UFSD("ENTER, ino %lu, fragment %u\n", inode->i_ino, fragment);
546 bh = ufs_getfrag (inode, fragment, create, err);
547 if (!bh || buffer_uptodate(bh))
549 ll_rw_block (READ, 1, &bh);
551 if (buffer_uptodate(bh))
558 static int ufs_writepage(struct page *page, struct writeback_control *wbc)
560 return block_write_full_page(page,ufs_getfrag_block,wbc);
562 static int ufs_readpage(struct file *file, struct page *page)
564 return block_read_full_page(page,ufs_getfrag_block);
566 static int ufs_prepare_write(struct file *file, struct page *page, unsigned from, unsigned to)
568 return block_prepare_write(page,from,to,ufs_getfrag_block);
570 static sector_t ufs_bmap(struct address_space *mapping, sector_t block)
572 return generic_block_bmap(mapping,block,ufs_getfrag_block);
574 struct address_space_operations ufs_aops = {
575 .readpage = ufs_readpage,
576 .writepage = ufs_writepage,
577 .sync_page = block_sync_page,
578 .prepare_write = ufs_prepare_write,
579 .commit_write = generic_commit_write,
583 static void ufs_set_inode_ops(struct inode *inode)
585 if (S_ISREG(inode->i_mode)) {
586 inode->i_op = &ufs_file_inode_operations;
587 inode->i_fop = &ufs_file_operations;
588 inode->i_mapping->a_ops = &ufs_aops;
589 } else if (S_ISDIR(inode->i_mode)) {
590 inode->i_op = &ufs_dir_inode_operations;
591 inode->i_fop = &ufs_dir_operations;
592 inode->i_mapping->a_ops = &ufs_aops;
593 } else if (S_ISLNK(inode->i_mode)) {
594 if (!inode->i_blocks)
595 inode->i_op = &ufs_fast_symlink_inode_operations;
597 inode->i_op = &page_symlink_inode_operations;
598 inode->i_mapping->a_ops = &ufs_aops;
601 init_special_inode(inode, inode->i_mode,
602 ufs_get_inode_dev(inode->i_sb, UFS_I(inode)));
605 void ufs_read_inode (struct inode * inode)
607 struct ufs_inode_info *ufsi = UFS_I(inode);
608 struct super_block * sb;
609 struct ufs_sb_private_info * uspi;
610 struct ufs_inode * ufs_inode;
611 struct ufs2_inode *ufs2_inode;
612 struct buffer_head * bh;
617 UFSD("ENTER, ino %lu\n", inode->i_ino);
620 uspi = UFS_SB(sb)->s_uspi;
621 flags = UFS_SB(sb)->s_flags;
623 if (inode->i_ino < UFS_ROOTINO ||
624 inode->i_ino > (uspi->s_ncg * uspi->s_ipg)) {
625 ufs_warning (sb, "ufs_read_inode", "bad inode number (%lu)\n", inode->i_ino);
629 bh = sb_bread(sb, uspi->s_sbbase + ufs_inotofsba(inode->i_ino));
631 ufs_warning (sb, "ufs_read_inode", "unable to read inode %lu\n", inode->i_ino);
634 if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2)
637 ufs_inode = (struct ufs_inode *) (bh->b_data + sizeof(struct ufs_inode) * ufs_inotofsbo(inode->i_ino));
640 * Copy data to the in-core inode.
642 inode->i_mode = mode = fs16_to_cpu(sb, ufs_inode->ui_mode);
643 inode->i_nlink = fs16_to_cpu(sb, ufs_inode->ui_nlink);
644 if (inode->i_nlink == 0)
645 ufs_error (sb, "ufs_read_inode", "inode %lu has zero nlink\n", inode->i_ino);
648 * Linux now has 32-bit uid and gid, so we can support EFT.
650 inode->i_uid = ufs_get_inode_uid(sb, ufs_inode);
651 inode->i_gid = ufs_get_inode_gid(sb, ufs_inode);
653 inode->i_size = fs64_to_cpu(sb, ufs_inode->ui_size);
654 inode->i_atime.tv_sec = fs32_to_cpu(sb, ufs_inode->ui_atime.tv_sec);
655 inode->i_ctime.tv_sec = fs32_to_cpu(sb, ufs_inode->ui_ctime.tv_sec);
656 inode->i_mtime.tv_sec = fs32_to_cpu(sb, ufs_inode->ui_mtime.tv_sec);
657 inode->i_mtime.tv_nsec = 0;
658 inode->i_atime.tv_nsec = 0;
659 inode->i_ctime.tv_nsec = 0;
660 inode->i_blocks = fs32_to_cpu(sb, ufs_inode->ui_blocks);
661 inode->i_blksize = PAGE_SIZE; /* This is the optimal IO size (for stat) */
663 ufsi->i_flags = fs32_to_cpu(sb, ufs_inode->ui_flags);
664 ufsi->i_gen = fs32_to_cpu(sb, ufs_inode->ui_gen);
665 ufsi->i_shadow = fs32_to_cpu(sb, ufs_inode->ui_u3.ui_sun.ui_shadow);
666 ufsi->i_oeftflag = fs32_to_cpu(sb, ufs_inode->ui_u3.ui_sun.ui_oeftflag);
667 ufsi->i_lastfrag = (inode->i_size + uspi->s_fsize - 1) >> uspi->s_fshift;
668 ufsi->i_dir_start_lookup = 0;
670 if (S_ISCHR(mode) || S_ISBLK(mode) || inode->i_blocks) {
671 for (i = 0; i < (UFS_NDADDR + UFS_NINDIR); i++)
672 ufsi->i_u1.i_data[i] = ufs_inode->ui_u2.ui_addr.ui_db[i];
674 for (i = 0; i < (UFS_NDADDR + UFS_NINDIR) * 4; i++)
675 ufsi->i_u1.i_symlink[i] = ufs_inode->ui_u2.ui_symlink[i];
679 ufs_set_inode_ops(inode);
687 make_bad_inode(inode);
691 UFSD("Reading ufs2 inode, ino %lu\n", inode->i_ino);
693 ufs2_inode = (struct ufs2_inode *)(bh->b_data + sizeof(struct ufs2_inode) * ufs_inotofsbo(inode->i_ino));
696 * Copy data to the in-core inode.
698 inode->i_mode = mode = fs16_to_cpu(sb, ufs2_inode->ui_mode);
699 inode->i_nlink = fs16_to_cpu(sb, ufs2_inode->ui_nlink);
700 if (inode->i_nlink == 0)
701 ufs_error (sb, "ufs_read_inode", "inode %lu has zero nlink\n", inode->i_ino);
704 * Linux now has 32-bit uid and gid, so we can support EFT.
706 inode->i_uid = fs32_to_cpu(sb, ufs2_inode->ui_uid);
707 inode->i_gid = fs32_to_cpu(sb, ufs2_inode->ui_gid);
709 inode->i_size = fs64_to_cpu(sb, ufs2_inode->ui_size);
710 inode->i_atime.tv_sec = fs32_to_cpu(sb, ufs2_inode->ui_atime.tv_sec);
711 inode->i_ctime.tv_sec = fs32_to_cpu(sb, ufs2_inode->ui_ctime.tv_sec);
712 inode->i_mtime.tv_sec = fs32_to_cpu(sb, ufs2_inode->ui_mtime.tv_sec);
713 inode->i_mtime.tv_nsec = 0;
714 inode->i_atime.tv_nsec = 0;
715 inode->i_ctime.tv_nsec = 0;
716 inode->i_blocks = fs64_to_cpu(sb, ufs2_inode->ui_blocks);
717 inode->i_blksize = PAGE_SIZE; /*This is the optimal IO size(for stat)*/
720 ufsi->i_flags = fs32_to_cpu(sb, ufs2_inode->ui_flags);
721 ufsi->i_gen = fs32_to_cpu(sb, ufs2_inode->ui_gen);
723 ufsi->i_shadow = fs32_to_cpu(sb, ufs_inode->ui_u3.ui_sun.ui_shadow);
724 ufsi->i_oeftflag = fs32_to_cpu(sb, ufs_inode->ui_u3.ui_sun.ui_oeftflag);
726 ufsi->i_lastfrag= (inode->i_size + uspi->s_fsize- 1) >> uspi->s_fshift;
728 if (S_ISCHR(mode) || S_ISBLK(mode) || inode->i_blocks) {
729 for (i = 0; i < (UFS_NDADDR + UFS_NINDIR); i++)
730 ufsi->i_u1.u2_i_data[i] =
731 ufs2_inode->ui_u2.ui_addr.ui_db[i];
734 for (i = 0; i < (UFS_NDADDR + UFS_NINDIR) * 4; i++)
735 ufsi->i_u1.i_symlink[i] = ufs2_inode->ui_u2.ui_symlink[i];
739 ufs_set_inode_ops(inode);
747 static int ufs_update_inode(struct inode * inode, int do_sync)
749 struct ufs_inode_info *ufsi = UFS_I(inode);
750 struct super_block * sb;
751 struct ufs_sb_private_info * uspi;
752 struct buffer_head * bh;
753 struct ufs_inode * ufs_inode;
757 UFSD("ENTER, ino %lu\n", inode->i_ino);
760 uspi = UFS_SB(sb)->s_uspi;
761 flags = UFS_SB(sb)->s_flags;
763 if (inode->i_ino < UFS_ROOTINO ||
764 inode->i_ino > (uspi->s_ncg * uspi->s_ipg)) {
765 ufs_warning (sb, "ufs_read_inode", "bad inode number (%lu)\n", inode->i_ino);
769 bh = sb_bread(sb, ufs_inotofsba(inode->i_ino));
771 ufs_warning (sb, "ufs_read_inode", "unable to read inode %lu\n", inode->i_ino);
774 ufs_inode = (struct ufs_inode *) (bh->b_data + ufs_inotofsbo(inode->i_ino) * sizeof(struct ufs_inode));
776 ufs_inode->ui_mode = cpu_to_fs16(sb, inode->i_mode);
777 ufs_inode->ui_nlink = cpu_to_fs16(sb, inode->i_nlink);
779 ufs_set_inode_uid(sb, ufs_inode, inode->i_uid);
780 ufs_set_inode_gid(sb, ufs_inode, inode->i_gid);
782 ufs_inode->ui_size = cpu_to_fs64(sb, inode->i_size);
783 ufs_inode->ui_atime.tv_sec = cpu_to_fs32(sb, inode->i_atime.tv_sec);
784 ufs_inode->ui_atime.tv_usec = 0;
785 ufs_inode->ui_ctime.tv_sec = cpu_to_fs32(sb, inode->i_ctime.tv_sec);
786 ufs_inode->ui_ctime.tv_usec = 0;
787 ufs_inode->ui_mtime.tv_sec = cpu_to_fs32(sb, inode->i_mtime.tv_sec);
788 ufs_inode->ui_mtime.tv_usec = 0;
789 ufs_inode->ui_blocks = cpu_to_fs32(sb, inode->i_blocks);
790 ufs_inode->ui_flags = cpu_to_fs32(sb, ufsi->i_flags);
791 ufs_inode->ui_gen = cpu_to_fs32(sb, ufsi->i_gen);
793 if ((flags & UFS_UID_MASK) == UFS_UID_EFT) {
794 ufs_inode->ui_u3.ui_sun.ui_shadow = cpu_to_fs32(sb, ufsi->i_shadow);
795 ufs_inode->ui_u3.ui_sun.ui_oeftflag = cpu_to_fs32(sb, ufsi->i_oeftflag);
798 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
799 /* ufs_inode->ui_u2.ui_addr.ui_db[0] = cpu_to_fs32(sb, inode->i_rdev); */
800 ufs_inode->ui_u2.ui_addr.ui_db[0] = ufsi->i_u1.i_data[0];
801 } else if (inode->i_blocks) {
802 for (i = 0; i < (UFS_NDADDR + UFS_NINDIR); i++)
803 ufs_inode->ui_u2.ui_addr.ui_db[i] = ufsi->i_u1.i_data[i];
806 for (i = 0; i < (UFS_NDADDR + UFS_NINDIR) * 4; i++)
807 ufs_inode->ui_u2.ui_symlink[i] = ufsi->i_u1.i_symlink[i];
811 memset (ufs_inode, 0, sizeof(struct ufs_inode));
813 mark_buffer_dirty(bh);
815 sync_dirty_buffer(bh);
822 int ufs_write_inode (struct inode * inode, int wait)
826 ret = ufs_update_inode (inode, wait);
831 int ufs_sync_inode (struct inode *inode)
833 return ufs_update_inode (inode, 1);
836 void ufs_delete_inode (struct inode * inode)
838 truncate_inode_pages(&inode->i_data, 0);
839 /*UFS_I(inode)->i_dtime = CURRENT_TIME;*/
841 mark_inode_dirty(inode);
842 ufs_update_inode(inode, IS_SYNC(inode));
845 ufs_truncate (inode);
846 ufs_free_inode (inode);