• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /asus-wl-520gu-7.0.1.45/src/linux/linux/fs/ext2/

Lines Matching refs:inode

2  *  linux/fs/ext2/inode.c
11 * linux/fs/minix/inode.c
39 static int ext2_update_inode(struct inode * inode, int do_sync);
44 void ext2_put_inode (struct inode * inode)
46 ext2_discard_prealloc (inode);
52 void ext2_delete_inode (struct inode * inode)
56 if (is_bad_inode(inode) ||
57 inode->i_ino == EXT2_ACL_IDX_INO ||
58 inode->i_ino == EXT2_ACL_DATA_INO)
60 inode->u.ext2_i.i_dtime = CURRENT_TIME;
61 mark_inode_dirty(inode);
62 ext2_update_inode(inode, IS_SYNC(inode));
63 inode->i_size = 0;
64 if (inode->i_blocks)
65 ext2_truncate (inode);
66 ext2_free_inode (inode);
72 clear_inode(inode); /* We must guarantee clearing of inode... */
75 void ext2_discard_prealloc (struct inode * inode)
80 if (inode->u.ext2_i.i_prealloc_count) {
81 unsigned short total = inode->u.ext2_i.i_prealloc_count;
82 unsigned long block = inode->u.ext2_i.i_prealloc_block;
83 inode->u.ext2_i.i_prealloc_count = 0;
84 inode->u.ext2_i.i_prealloc_block = 0;
86 ext2_free_blocks (inode, block, total);
92 static int ext2_alloc_block (struct inode * inode, unsigned long goal, int *err)
102 if (inode->u.ext2_i.i_prealloc_count &&
103 (goal == inode->u.ext2_i.i_prealloc_block ||
104 goal + 1 == inode->u.ext2_i.i_prealloc_block))
106 result = inode->u.ext2_i.i_prealloc_block++;
107 inode->u.ext2_i.i_prealloc_count--;
112 ext2_discard_prealloc (inode);
115 if (S_ISREG(inode->i_mode))
116 result = ext2_new_block (inode, goal,
117 &inode->u.ext2_i.i_prealloc_count,
118 &inode->u.ext2_i.i_prealloc_block, err);
120 result = ext2_new_block (inode, goal, 0, 0, err);
123 result = ext2_new_block (inode, goal, 0, 0, err);
149 * @inode: inode in question (we are only interested in its superblock)
154 * for UNIX filesystems - tree of pointers anchored in the inode, with
163 * inode->i_sb).
176 static int ext2_block_to_path(struct inode *inode, long i_block, int offsets[4])
178 int ptrs = EXT2_ADDR_PER_BLOCK(inode->i_sb);
179 int ptrs_bits = EXT2_ADDR_PER_BLOCK_BITS(inode->i_sb);
186 ext2_warning (inode->i_sb, "ext2_block_to_path", "block < 0");
202 ext2_warning (inode->i_sb, "ext2_block_to_path", "block > big");
209 * @inode: inode in question
211 * @offsets: offsets of pointers in inode/indirect blocks
220 * number (it points into struct inode for i==0 and into the bh->b_data
236 static Indirect *ext2_get_branch(struct inode *inode,
242 struct super_block *sb = inode->i_sb;
248 add_chain (chain, NULL, inode->u.ext2_i.i_data + *offsets);
276 * @inode: owner
284 * + if pointer will live in inode - allocate in the same cylinder group.
288 static inline unsigned long ext2_find_near(struct inode *inode, Indirect *ind)
290 u32 *start = ind->bh ? (u32*) ind->bh->b_data : inode->u.ext2_i.i_data;
303 * It is going to be refered from inode itself? OK, just put it into
306 return (inode->u.ext2_i.i_block_group *
307 EXT2_BLOCKS_PER_GROUP(inode->i_sb)) +
308 le32_to_cpu(inode->i_sb->u.ext2_sb.s_es->s_first_data_block);
313 * @inode: owner
324 static inline int ext2_find_goal(struct inode *inode,
331 if (block == inode->u.ext2_i.i_next_alloc_block + 1) {
332 inode->u.ext2_i.i_next_alloc_block++;
333 inode->u.ext2_i.i_next_alloc_goal++;
342 if (block == inode->u.ext2_i.i_next_alloc_block)
343 *goal = inode->u.ext2_i.i_next_alloc_goal;
345 *goal = ext2_find_near(inode, partial);
354 * @inode: owner
362 * inode. It stores the information about that chain in the branch[], in
377 static int ext2_alloc_branch(struct inode *inode,
383 int blocksize = inode->i_sb->s_blocksize;
387 int parent = ext2_alloc_block(inode, goal, &err);
393 int nr = ext2_alloc_block(inode, parent, &err);
401 bh = sb_getblk(inode->i_sb, parent);
409 mark_buffer_dirty_inode(bh, inode);
410 /* We used to sync bh here if IS_SYNC(inode).
414 if (S_ISDIR(inode->i_mode) && IS_SYNC(inode)) {
427 ext2_free_blocks(inode, le32_to_cpu(branch[i].key), 1);
432 * ext2_splice_branch - splice the allocated branch onto inode.
433 * @inode: owner
442 * inode (->i_blocks, etc.). In case of success we end up with the full
448 static inline int ext2_splice_branch(struct inode *inode,
466 inode->u.ext2_i.i_next_alloc_block = block;
467 inode->u.ext2_i.i_next_alloc_goal = le32_to_cpu(where[num-1].key);
473 inode->i_ctime = CURRENT_TIME;
477 mark_buffer_dirty_inode(where->bh, inode);
478 if (S_ISDIR(inode->i_mode) && IS_SYNC(inode)) {
484 mark_inode_dirty(inode);
491 ext2_free_blocks(inode, le32_to_cpu(where[i].key), 1);
505 * reachable from inode.
508 static int ext2_get_block(struct inode *inode, long iblock, struct buffer_head *bh_result, int create)
516 int depth = ext2_block_to_path(inode, iblock, offsets);
523 partial = ext2_get_branch(inode, depth, offsets, chain, &err);
528 bh_result->b_dev = inode->i_dev;
556 if (ext2_find_goal(inode, iblock, chain, partial, &goal) < 0)
560 err = ext2_alloc_branch(inode, left, goal,
565 if (ext2_splice_branch(inode, iblock, chain, partial, left) < 0)
595 static int ext2_direct_IO(int rw, struct inode * inode, struct kiobuf * iobuf, unsigned long blocknr, int blocksize)
597 return generic_direct_IO(rw, inode, iobuf, blocknr, blocksize, ext2_get_block);
624 * @inode: inode in question
652 * c) free the subtrees growing from the inode past the @chain[0].p
656 static Indirect *ext2_find_shared(struct inode *inode,
668 partial = ext2_get_branch(inode, k, offsets, chain, &err);
684 * of branch is all ours and does not grow immediately from the inode
706 * @inode: inode we are dealing with
711 * stored as little-endian 32-bit) and updating @inode->i_blocks
714 static inline void ext2_free_data(struct inode *inode, u32 *p, u32 *q)
729 mark_inode_dirty(inode);
730 ext2_free_blocks (inode, block_to_free, count);
738 mark_inode_dirty(inode);
739 ext2_free_blocks (inode, block_to_free, count);
745 * @inode: inode we are dealing with
751 * stored as little-endian 32-bit) and updating @inode->i_blocks
754 static void ext2_free_branches(struct inode *inode, u32 *p, u32 *q, int depth)
760 int addr_per_block = EXT2_ADDR_PER_BLOCK(inode->i_sb);
766 bh = sb_bread(inode->i_sb, nr);
772 ext2_error(inode->i_sb, "ext2_free_branches",
773 "Read failure, inode=%ld, block=%ld",
774 inode->i_ino, nr);
777 ext2_free_branches(inode,
782 ext2_free_blocks(inode, nr, 1);
783 mark_inode_dirty(inode);
786 ext2_free_data(inode, p, q);
789 void ext2_truncate (struct inode * inode)
791 u32 *i_data = inode->u.ext2_i.i_data;
792 int addr_per_block = EXT2_ADDR_PER_BLOCK(inode->i_sb);
801 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
802 S_ISLNK(inode->i_mode)))
804 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
807 ext2_discard_prealloc(inode);
809 blocksize = inode->i_sb->s_blocksize;
810 iblock = (inode->i_size + blocksize-1)
811 >> EXT2_BLOCK_SIZE_BITS(inode->i_sb);
813 block_truncate_page(inode->i_mapping, inode->i_size, ext2_get_block);
815 n = ext2_block_to_path(inode, iblock, offsets);
820 ext2_free_data(inode, i_data+offsets[0],
825 partial = ext2_find_shared(inode, n, offsets, chain, &nr);
829 mark_inode_dirty(inode);
831 mark_buffer_dirty_inode(partial->bh, inode);
832 ext2_free_branches(inode, &nr, &nr+1, (chain+n-1) - partial);
836 ext2_free_branches(inode,
840 mark_buffer_dirty_inode(partial->bh, inode);
851 mark_inode_dirty(inode);
852 ext2_free_branches(inode, &nr, &nr+1, 1);
858 mark_inode_dirty(inode);
859 ext2_free_branches(inode, &nr, &nr+1, 2);
865 mark_inode_dirty(inode);
866 ext2_free_branches(inode, &nr, &nr+1, 3);
871 inode->i_mtime = inode->i_ctime = CURRENT_TIME;
872 if (IS_SYNC(inode)) {
873 fsync_inode_buffers(inode);
874 ext2_sync_inode (inode);
876 mark_inode_dirty(inode);
880 void ext2_read_inode (struct inode * inode)
891 if ((inode->i_ino != EXT2_ROOT_INO && inode->i_ino != EXT2_ACL_IDX_INO &&
892 inode->i_ino != EXT2_ACL_DATA_INO &&
893 inode->i_ino < EXT2_FIRST_INO(inode->i_sb)) ||
894 inode->i_ino > le32_to_cpu(inode->i_sb->u.ext2_sb.s_es->s_inodes_count)) {
895 ext2_error (inode->i_sb, "ext2_read_inode",
896 "bad inode number: %lu", inode->i_ino);
899 block_group = (inode->i_ino - 1) / EXT2_INODES_PER_GROUP(inode->i_sb);
900 if (block_group >= inode->i_sb->u.ext2_sb.s_groups_count) {
901 ext2_error (inode->i_sb, "ext2_read_inode",
905 group_desc = block_group >> EXT2_DESC_PER_BLOCK_BITS(inode->i_sb);
906 desc = block_group & (EXT2_DESC_PER_BLOCK(inode->i_sb) - 1);
907 bh = inode->i_sb->u.ext2_sb.s_group_desc[group_desc];
909 ext2_error (inode->i_sb, "ext2_read_inode",
916 * Figure out the offset within the block group inode table
918 offset = ((inode->i_ino - 1) % EXT2_INODES_PER_GROUP(inode->i_sb)) *
919 EXT2_INODE_SIZE(inode->i_sb);
921 (offset >> EXT2_BLOCK_SIZE_BITS(inode->i_sb));
922 if (!(bh = sb_bread(inode->i_sb, block))) {
923 ext2_error (inode->i_sb, "ext2_read_inode",
924 "unable to read inode block - "
925 "inode=%lu, block=%lu", inode->i_ino, block);
928 offset &= (EXT2_BLOCK_SIZE(inode->i_sb) - 1);
931 inode->i_mode = le16_to_cpu(raw_inode->i_mode);
932 inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
933 inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
934 if(!(test_opt (inode->i_sb, NO_UID32))) {
935 inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
936 inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
938 inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
939 inode->i_size = le32_to_cpu(raw_inode->i_size);
940 inode->i_atime = le32_to_cpu(raw_inode->i_atime);
941 inode->i_ctime = le32_to_cpu(raw_inode->i_ctime);
942 inode->i_mtime = le32_to_cpu(raw_inode->i_mtime);
943 inode->u.ext2_i.i_dtime = le32_to_cpu(raw_inode->i_dtime);
944 /* We now have enough fields to check if the inode was active or not.
949 if (inode->i_nlink == 0 && (inode->i_mode == 0 || inode->u.ext2_i.i_dtime)) {
950 /* this inode is deleted */
954 inode->i_blksize = PAGE_SIZE; /* This is the optimal IO size (for stat), not the fs block size */
955 inode->i_blocks = le32_to_cpu(raw_inode->i_blocks);
956 inode->i_version = ++event;
957 inode->u.ext2_i.i_flags = le32_to_cpu(raw_inode->i_flags);
958 inode->u.ext2_i.i_faddr = le32_to_cpu(raw_inode->i_faddr);
959 inode->u.ext2_i.i_frag_no = raw_inode->i_frag;
960 inode->u.ext2_i.i_frag_size = raw_inode->i_fsize;
961 inode->u.ext2_i.i_file_acl = le32_to_cpu(raw_inode->i_file_acl);
962 if (S_ISREG(inode->i_mode))
963 inode->i_size |= ((__u64)le32_to_cpu(raw_inode->i_size_high)) << 32;
965 inode->u.ext2_i.i_dir_acl = le32_to_cpu(raw_inode->i_dir_acl);
966 inode->i_generation = le32_to_cpu(raw_inode->i_generation);
967 inode->u.ext2_i.i_prealloc_count = 0;
968 inode->u.ext2_i.i_block_group = block_group;
971 * NOTE! The in-memory inode i_data array is in little-endian order
975 inode->u.ext2_i.i_data[block] = raw_inode->i_block[block];
977 if (inode->i_ino == EXT2_ACL_IDX_INO ||
978 inode->i_ino == EXT2_ACL_DATA_INO)
980 else if (S_ISREG(inode->i_mode)) {
981 inode->i_op = &ext2_file_inode_operations;
982 inode->i_fop = &ext2_file_operations;
983 inode->i_mapping->a_ops = &ext2_aops;
984 } else if (S_ISDIR(inode->i_mode)) {
985 inode->i_op = &ext2_dir_inode_operations;
986 inode->i_fop = &ext2_dir_operations;
987 inode->i_mapping->a_ops = &ext2_aops;
988 } else if (S_ISLNK(inode->i_mode)) {
989 if (!inode->i_blocks)
990 inode->i_op = &ext2_fast_symlink_inode_operations;
992 inode->i_op = &page_symlink_inode_operations;
993 inode->i_mapping->a_ops = &ext2_aops;
996 init_special_inode(inode, inode->i_mode,
999 inode->i_attr_flags = 0;
1000 if (inode->u.ext2_i.i_flags & EXT2_SYNC_FL) {
1001 inode->i_attr_flags |= ATTR_FLAG_SYNCRONOUS;
1002 inode->i_flags |= S_SYNC;
1004 if (inode->u.ext2_i.i_flags & EXT2_APPEND_FL) {
1005 inode->i_attr_flags |= ATTR_FLAG_APPEND;
1006 inode->i_flags |= S_APPEND;
1008 if (inode->u.ext2_i.i_flags & EXT2_IMMUTABLE_FL) {
1009 inode->i_attr_flags |= ATTR_FLAG_IMMUTABLE;
1010 inode->i_flags |= S_IMMUTABLE;
1012 if (inode->u.ext2_i.i_flags & EXT2_NOATIME_FL) {
1013 inode->i_attr_flags |= ATTR_FLAG_NOATIME;
1014 inode->i_flags |= S_NOATIME;
1019 make_bad_inode(inode);
1023 static int ext2_update_inode(struct inode * inode, int do_sync)
1035 if ((inode->i_ino != EXT2_ROOT_INO &&
1036 inode->i_ino < EXT2_FIRST_INO(inode->i_sb)) ||
1037 inode->i_ino > le32_to_cpu(inode->i_sb->u.ext2_sb.s_es->s_inodes_count)) {
1038 ext2_error (inode->i_sb, "ext2_write_inode",
1039 "bad inode number: %lu", inode->i_ino);
1042 block_group = (inode->i_ino - 1) / EXT2_INODES_PER_GROUP(inode->i_sb);
1043 if (block_group >= inode->i_sb->u.ext2_sb.s_groups_count) {
1044 ext2_error (inode->i_sb, "ext2_write_inode",
1048 group_desc = block_group >> EXT2_DESC_PER_BLOCK_BITS(inode->i_sb);
1049 desc = block_group & (EXT2_DESC_PER_BLOCK(inode->i_sb) - 1);
1050 bh = inode->i_sb->u.ext2_sb.s_group_desc[group_desc];
1052 ext2_error (inode->i_sb, "ext2_write_inode",
1058 * Figure out the offset within the block group inode table
1060 offset = ((inode->i_ino - 1) % EXT2_INODES_PER_GROUP(inode->i_sb)) *
1061 EXT2_INODE_SIZE(inode->i_sb);
1063 (offset >> EXT2_BLOCK_SIZE_BITS(inode->i_sb));
1064 if (!(bh = sb_bread(inode->i_sb, block))) {
1065 ext2_error (inode->i_sb, "ext2_write_inode",
1066 "unable to read inode block - "
1067 "inode=%lu, block=%lu", inode->i_ino, block);
1070 offset &= EXT2_BLOCK_SIZE(inode->i_sb) - 1;
1073 raw_inode->i_mode = cpu_to_le16(inode->i_mode);
1074 if(!(test_opt(inode->i_sb, NO_UID32))) {
1075 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
1076 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
1081 if(!inode->u.ext2_i.i_dtime) {
1082 raw_inode->i_uid_high = cpu_to_le16(high_16_bits(inode->i_uid));
1083 raw_inode->i_gid_high = cpu_to_le16(high_16_bits(inode->i_gid));
1089 raw_inode->i_uid_low = cpu_to_le16(fs_high2lowuid(inode->i_uid));
1090 raw_inode->i_gid_low = cpu_to_le16(fs_high2lowgid(inode->i_gid));
1094 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
1095 raw_inode->i_size = cpu_to_le32(inode->i_size);
1096 raw_inode->i_atime = cpu_to_le32(inode->i_atime);
1097 raw_inode->i_ctime = cpu_to_le32(inode->i_ctime);
1098 raw_inode->i_mtime = cpu_to_le32(inode->i_mtime);
1099 raw_inode->i_blocks = cpu_to_le32(inode->i_blocks);
1100 raw_inode->i_dtime = cpu_to_le32(inode->u.ext2_i.i_dtime);
1101 raw_inode->i_flags = cpu_to_le32(inode->u.ext2_i.i_flags);
1102 raw_inode->i_faddr = cpu_to_le32(inode->u.ext2_i.i_faddr);
1103 raw_inode->i_frag = inode->u.ext2_i.i_frag_no;
1104 raw_inode->i_fsize = inode->u.ext2_i.i_frag_size;
1105 raw_inode->i_file_acl = cpu_to_le32(inode->u.ext2_i.i_file_acl);
1106 if (!S_ISREG(inode->i_mode))
1107 raw_inode->i_dir_acl = cpu_to_le32(inode->u.ext2_i.i_dir_acl);
1109 raw_inode->i_size_high = cpu_to_le32(inode->i_size >> 32);
1110 if (inode->i_size > 0x7fffffffULL) {
1111 struct super_block *sb = inode->i_sb;
1129 raw_inode->i_generation = cpu_to_le32(inode->i_generation);
1130 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
1131 raw_inode->i_block[0] = cpu_to_le32(kdev_t_to_nr(inode->i_rdev));
1133 raw_inode->i_block[block] = inode->u.ext2_i.i_data[block];
1139 printk ("IO error syncing ext2 inode ["
1141 bdevname(inode->i_dev), inode->i_ino);
1149 void ext2_write_inode (struct inode * inode, int wait)
1152 ext2_update_inode (inode, wait);
1156 int ext2_sync_inode (struct inode *inode)
1158 return ext2_update_inode (inode, 1);