Lines Matching refs:inode
43 static int __ext2_write_inode(struct inode *inode, int do_sync);
48 static inline int ext2_inode_is_fast_symlink(struct inode *inode) in ext2_inode_is_fast_symlink() argument
50 int ea_blocks = EXT2_I(inode)->i_file_acl ? in ext2_inode_is_fast_symlink()
51 (inode->i_sb->s_blocksize >> 9) : 0; in ext2_inode_is_fast_symlink()
53 return (S_ISLNK(inode->i_mode) && in ext2_inode_is_fast_symlink()
54 inode->i_blocks - ea_blocks == 0); in ext2_inode_is_fast_symlink()
57 static void ext2_truncate_blocks(struct inode *inode, loff_t offset);
61 struct inode *inode = mapping->host; in ext2_write_failed() local
63 if (to > inode->i_size) { in ext2_write_failed()
64 truncate_pagecache(inode, inode->i_size); in ext2_write_failed()
65 ext2_truncate_blocks(inode, inode->i_size); in ext2_write_failed()
72 void ext2_evict_inode(struct inode * inode) in ext2_evict_inode() argument
77 if (!inode->i_nlink && !is_bad_inode(inode)) { in ext2_evict_inode()
79 dquot_initialize(inode); in ext2_evict_inode()
81 dquot_drop(inode); in ext2_evict_inode()
84 truncate_inode_pages_final(&inode->i_data); in ext2_evict_inode()
87 sb_start_intwrite(inode->i_sb); in ext2_evict_inode()
89 EXT2_I(inode)->i_dtime = ktime_get_real_seconds(); in ext2_evict_inode()
90 mark_inode_dirty(inode); in ext2_evict_inode()
91 __ext2_write_inode(inode, inode_needs_sync(inode)); in ext2_evict_inode()
93 inode->i_size = 0; in ext2_evict_inode()
94 if (inode->i_blocks) in ext2_evict_inode()
95 ext2_truncate_blocks(inode, 0); in ext2_evict_inode()
96 ext2_xattr_delete_inode(inode); in ext2_evict_inode()
99 invalidate_inode_buffers(inode); in ext2_evict_inode()
100 clear_inode(inode); in ext2_evict_inode()
102 ext2_discard_reservation(inode); in ext2_evict_inode()
103 rsv = EXT2_I(inode)->i_block_alloc_info; in ext2_evict_inode()
104 EXT2_I(inode)->i_block_alloc_info = NULL; in ext2_evict_inode()
109 ext2_free_inode(inode); in ext2_evict_inode()
110 sb_end_intwrite(inode->i_sb); in ext2_evict_inode()
163 static int ext2_block_to_path(struct inode *inode, in ext2_block_to_path() argument
166 int ptrs = EXT2_ADDR_PER_BLOCK(inode->i_sb); in ext2_block_to_path()
167 int ptrs_bits = EXT2_ADDR_PER_BLOCK_BITS(inode->i_sb); in ext2_block_to_path()
175 ext2_msg(inode->i_sb, KERN_WARNING, in ext2_block_to_path()
196 ext2_msg(inode->i_sb, KERN_WARNING, in ext2_block_to_path()
234 static Indirect *ext2_get_branch(struct inode *inode, in ext2_get_branch() argument
240 struct super_block *sb = inode->i_sb; in ext2_get_branch()
246 add_chain (chain, NULL, EXT2_I(inode)->i_data + *offsets); in ext2_get_branch()
253 read_lock(&EXT2_I(inode)->i_meta_lock); in ext2_get_branch()
257 read_unlock(&EXT2_I(inode)->i_meta_lock); in ext2_get_branch()
264 read_unlock(&EXT2_I(inode)->i_meta_lock); in ext2_get_branch()
294 static ext2_fsblk_t ext2_find_near(struct inode *inode, Indirect *ind) in ext2_find_near() argument
296 struct ext2_inode_info *ei = EXT2_I(inode); in ext2_find_near()
315 bg_start = ext2_group_first_block_no(inode->i_sb, ei->i_block_group); in ext2_find_near()
317 (EXT2_BLOCKS_PER_GROUP(inode->i_sb) / 16); in ext2_find_near()
330 static inline ext2_fsblk_t ext2_find_goal(struct inode *inode, long block, in ext2_find_goal() argument
335 block_i = EXT2_I(inode)->i_block_alloc_info; in ext2_find_goal()
346 return ext2_find_near(inode, partial); in ext2_find_goal()
395 static int ext2_alloc_blocks(struct inode *inode, in ext2_alloc_blocks() argument
418 current_block = ext2_new_blocks(inode,goal,&count,err); in ext2_alloc_blocks()
442 ext2_free_blocks(inode, new_blocks[i], 1); in ext2_alloc_blocks()
444 mark_inode_dirty(inode); in ext2_alloc_blocks()
475 static int ext2_alloc_branch(struct inode *inode, in ext2_alloc_branch() argument
479 int blocksize = inode->i_sb->s_blocksize; in ext2_alloc_branch()
487 num = ext2_alloc_blocks(inode, goal, indirect_blks, in ext2_alloc_branch()
502 bh = sb_getblk(inode->i_sb, new_blocks[n-1]); in ext2_alloc_branch()
525 mark_buffer_dirty_inode(bh, inode); in ext2_alloc_branch()
530 if (S_ISDIR(inode->i_mode) && IS_DIRSYNC(inode)) in ext2_alloc_branch()
540 ext2_free_blocks(inode, new_blocks[i], 1); in ext2_alloc_branch()
541 ext2_free_blocks(inode, new_blocks[i], num); in ext2_alloc_branch()
557 static void ext2_splice_branch(struct inode *inode, in ext2_splice_branch() argument
564 block_i = EXT2_I(inode)->i_block_alloc_info; in ext2_splice_branch()
596 mark_buffer_dirty_inode(where->bh, inode); in ext2_splice_branch()
598 inode->i_ctime = current_time(inode); in ext2_splice_branch()
599 mark_inode_dirty(inode); in ext2_splice_branch()
620 static int ext2_get_blocks(struct inode *inode, in ext2_get_blocks() argument
633 struct ext2_inode_info *ei = EXT2_I(inode); in ext2_get_blocks()
639 depth = ext2_block_to_path(inode,iblock,offsets,&blocks_to_boundary); in ext2_get_blocks()
644 partial = ext2_get_branch(inode, depth, offsets, chain, &err); in ext2_get_blocks()
697 partial = ext2_get_branch(inode, depth, offsets, chain, &err); in ext2_get_blocks()
714 if (S_ISREG(inode->i_mode) && (!ei->i_block_alloc_info)) in ext2_get_blocks()
715 ext2_init_block_alloc_info(inode); in ext2_get_blocks()
717 goal = ext2_find_goal(inode, iblock, partial); in ext2_get_blocks()
730 err = ext2_alloc_branch(inode, indirect_blks, &count, goal, in ext2_get_blocks()
738 if (IS_DAX(inode)) { in ext2_get_blocks()
743 clean_bdev_aliases(inode->i_sb->s_bdev, in ext2_get_blocks()
751 err = sb_issue_zeroout(inode->i_sb, in ext2_get_blocks()
761 ext2_splice_branch(inode, iblock, partial, indirect_blks, count); in ext2_get_blocks()
779 int ext2_get_block(struct inode *inode, sector_t iblock, in ext2_get_block() argument
782 unsigned max_blocks = bh_result->b_size >> inode->i_blkbits; in ext2_get_block()
787 ret = ext2_get_blocks(inode, iblock, max_blocks, &bno, &new, &boundary, in ext2_get_block()
792 map_bh(bh_result, inode->i_sb, bno); in ext2_get_block()
793 bh_result->b_size = (ret << inode->i_blkbits); in ext2_get_block()
803 static int ext2_iomap_begin(struct inode *inode, loff_t offset, loff_t length, in ext2_iomap_begin() argument
806 unsigned int blkbits = inode->i_blkbits; in ext2_iomap_begin()
809 struct ext2_sb_info *sbi = EXT2_SB(inode->i_sb); in ext2_iomap_begin()
814 ret = ext2_get_blocks(inode, first_block, max_blocks, in ext2_iomap_begin()
820 iomap->bdev = inode->i_sb->s_bdev; in ext2_iomap_begin()
841 ext2_iomap_end(struct inode *inode, loff_t offset, loff_t length, in ext2_iomap_end() argument
847 ext2_write_failed(inode->i_mapping, offset + length); in ext2_iomap_end()
860 int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, in ext2_fiemap() argument
863 return generic_block_fiemap(inode, fieinfo, start, len, in ext2_fiemap()
938 struct inode *inode = mapping->host; in ext2_direct_IO() local
943 ret = blockdev_direct_IO(iocb, inode, iter, ext2_get_block); in ext2_direct_IO()
1044 static Indirect *ext2_find_shared(struct inode *inode, in ext2_find_shared() argument
1056 partial = ext2_get_branch(inode, k, offsets, chain, &err); in ext2_find_shared()
1063 write_lock(&EXT2_I(inode)->i_meta_lock); in ext2_find_shared()
1065 write_unlock(&EXT2_I(inode)->i_meta_lock); in ext2_find_shared()
1082 write_unlock(&EXT2_I(inode)->i_meta_lock); in ext2_find_shared()
1103 static inline void ext2_free_data(struct inode *inode, __le32 *p, __le32 *q) in ext2_free_data() argument
1118 ext2_free_blocks (inode, block_to_free, count); in ext2_free_data()
1119 mark_inode_dirty(inode); in ext2_free_data()
1127 ext2_free_blocks (inode, block_to_free, count); in ext2_free_data()
1128 mark_inode_dirty(inode); in ext2_free_data()
1143 static void ext2_free_branches(struct inode *inode, __le32 *p, __le32 *q, int depth) in ext2_free_branches() argument
1149 int addr_per_block = EXT2_ADDR_PER_BLOCK(inode->i_sb); in ext2_free_branches()
1155 bh = sb_bread(inode->i_sb, nr); in ext2_free_branches()
1161 ext2_error(inode->i_sb, "ext2_free_branches", in ext2_free_branches()
1163 inode->i_ino, nr); in ext2_free_branches()
1166 ext2_free_branches(inode, in ext2_free_branches()
1171 ext2_free_blocks(inode, nr, 1); in ext2_free_branches()
1172 mark_inode_dirty(inode); in ext2_free_branches()
1175 ext2_free_data(inode, p, q); in ext2_free_branches()
1179 static void __ext2_truncate_blocks(struct inode *inode, loff_t offset) in __ext2_truncate_blocks() argument
1181 __le32 *i_data = EXT2_I(inode)->i_data; in __ext2_truncate_blocks()
1182 struct ext2_inode_info *ei = EXT2_I(inode); in __ext2_truncate_blocks()
1183 int addr_per_block = EXT2_ADDR_PER_BLOCK(inode->i_sb); in __ext2_truncate_blocks()
1191 blocksize = inode->i_sb->s_blocksize; in __ext2_truncate_blocks()
1192 iblock = (offset + blocksize-1) >> EXT2_BLOCK_SIZE_BITS(inode->i_sb); in __ext2_truncate_blocks()
1198 n = ext2_block_to_path(inode, iblock, offsets, NULL); in __ext2_truncate_blocks()
1209 ext2_free_data(inode, i_data+offsets[0], in __ext2_truncate_blocks()
1214 partial = ext2_find_shared(inode, n, offsets, chain, &nr); in __ext2_truncate_blocks()
1218 mark_inode_dirty(inode); in __ext2_truncate_blocks()
1220 mark_buffer_dirty_inode(partial->bh, inode); in __ext2_truncate_blocks()
1221 ext2_free_branches(inode, &nr, &nr+1, (chain+n-1) - partial); in __ext2_truncate_blocks()
1225 ext2_free_branches(inode, in __ext2_truncate_blocks()
1229 mark_buffer_dirty_inode(partial->bh, inode); in __ext2_truncate_blocks()
1240 mark_inode_dirty(inode); in __ext2_truncate_blocks()
1241 ext2_free_branches(inode, &nr, &nr+1, 1); in __ext2_truncate_blocks()
1248 mark_inode_dirty(inode); in __ext2_truncate_blocks()
1249 ext2_free_branches(inode, &nr, &nr+1, 2); in __ext2_truncate_blocks()
1256 mark_inode_dirty(inode); in __ext2_truncate_blocks()
1257 ext2_free_branches(inode, &nr, &nr+1, 3); in __ext2_truncate_blocks()
1263 ext2_discard_reservation(inode); in __ext2_truncate_blocks()
1268 static void ext2_truncate_blocks(struct inode *inode, loff_t offset) in ext2_truncate_blocks() argument
1270 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || in ext2_truncate_blocks()
1271 S_ISLNK(inode->i_mode))) in ext2_truncate_blocks()
1273 if (ext2_inode_is_fast_symlink(inode)) in ext2_truncate_blocks()
1276 dax_sem_down_write(EXT2_I(inode)); in ext2_truncate_blocks()
1277 __ext2_truncate_blocks(inode, offset); in ext2_truncate_blocks()
1278 dax_sem_up_write(EXT2_I(inode)); in ext2_truncate_blocks()
1281 static int ext2_setsize(struct inode *inode, loff_t newsize) in ext2_setsize() argument
1285 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || in ext2_setsize()
1286 S_ISLNK(inode->i_mode))) in ext2_setsize()
1288 if (ext2_inode_is_fast_symlink(inode)) in ext2_setsize()
1290 if (IS_APPEND(inode) || IS_IMMUTABLE(inode)) in ext2_setsize()
1293 inode_dio_wait(inode); in ext2_setsize()
1295 if (IS_DAX(inode)) { in ext2_setsize()
1296 error = iomap_zero_range(inode, newsize, in ext2_setsize()
1299 } else if (test_opt(inode->i_sb, NOBH)) in ext2_setsize()
1300 error = nobh_truncate_page(inode->i_mapping, in ext2_setsize()
1303 error = block_truncate_page(inode->i_mapping, in ext2_setsize()
1308 dax_sem_down_write(EXT2_I(inode)); in ext2_setsize()
1309 truncate_setsize(inode, newsize); in ext2_setsize()
1310 __ext2_truncate_blocks(inode, newsize); in ext2_setsize()
1311 dax_sem_up_write(EXT2_I(inode)); in ext2_setsize()
1313 inode->i_mtime = inode->i_ctime = current_time(inode); in ext2_setsize()
1314 if (inode_needs_sync(inode)) { in ext2_setsize()
1315 sync_mapping_buffers(inode->i_mapping); in ext2_setsize()
1316 sync_inode_metadata(inode, 1); in ext2_setsize()
1318 mark_inode_dirty(inode); in ext2_setsize()
1367 void ext2_set_inode_flags(struct inode *inode) in ext2_set_inode_flags() argument
1369 unsigned int flags = EXT2_I(inode)->i_flags; in ext2_set_inode_flags()
1371 inode->i_flags &= ~(S_SYNC | S_APPEND | S_IMMUTABLE | S_NOATIME | in ext2_set_inode_flags()
1374 inode->i_flags |= S_SYNC; in ext2_set_inode_flags()
1376 inode->i_flags |= S_APPEND; in ext2_set_inode_flags()
1378 inode->i_flags |= S_IMMUTABLE; in ext2_set_inode_flags()
1380 inode->i_flags |= S_NOATIME; in ext2_set_inode_flags()
1382 inode->i_flags |= S_DIRSYNC; in ext2_set_inode_flags()
1383 if (test_opt(inode->i_sb, DAX) && S_ISREG(inode->i_mode)) in ext2_set_inode_flags()
1384 inode->i_flags |= S_DAX; in ext2_set_inode_flags()
1387 void ext2_set_file_ops(struct inode *inode) in ext2_set_file_ops() argument
1389 inode->i_op = &ext2_file_inode_operations; in ext2_set_file_ops()
1390 inode->i_fop = &ext2_file_operations; in ext2_set_file_ops()
1391 if (IS_DAX(inode)) in ext2_set_file_ops()
1392 inode->i_mapping->a_ops = &ext2_dax_aops; in ext2_set_file_ops()
1393 else if (test_opt(inode->i_sb, NOBH)) in ext2_set_file_ops()
1394 inode->i_mapping->a_ops = &ext2_nobh_aops; in ext2_set_file_ops()
1396 inode->i_mapping->a_ops = &ext2_aops; in ext2_set_file_ops()
1399 struct inode *ext2_iget (struct super_block *sb, unsigned long ino) in ext2_iget()
1404 struct inode *inode; in ext2_iget() local
1410 inode = iget_locked(sb, ino); in ext2_iget()
1411 if (!inode) in ext2_iget()
1413 if (!(inode->i_state & I_NEW)) in ext2_iget()
1414 return inode; in ext2_iget()
1416 ei = EXT2_I(inode); in ext2_iget()
1419 raw_inode = ext2_get_inode(inode->i_sb, ino, &bh); in ext2_iget()
1425 inode->i_mode = le16_to_cpu(raw_inode->i_mode); in ext2_iget()
1428 if (!(test_opt (inode->i_sb, NO_UID32))) { in ext2_iget()
1432 i_uid_write(inode, i_uid); in ext2_iget()
1433 i_gid_write(inode, i_gid); in ext2_iget()
1434 set_nlink(inode, le16_to_cpu(raw_inode->i_links_count)); in ext2_iget()
1435 inode->i_size = le32_to_cpu(raw_inode->i_size); in ext2_iget()
1436 inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime); in ext2_iget()
1437 inode->i_ctime.tv_sec = (signed)le32_to_cpu(raw_inode->i_ctime); in ext2_iget()
1438 inode->i_mtime.tv_sec = (signed)le32_to_cpu(raw_inode->i_mtime); in ext2_iget()
1439 inode->i_atime.tv_nsec = inode->i_mtime.tv_nsec = inode->i_ctime.tv_nsec = 0; in ext2_iget()
1446 if (inode->i_nlink == 0 && (inode->i_mode == 0 || ei->i_dtime)) { in ext2_iget()
1451 inode->i_blocks = le32_to_cpu(raw_inode->i_blocks); in ext2_iget()
1453 ext2_set_inode_flags(inode); in ext2_iget()
1468 if (S_ISREG(inode->i_mode)) in ext2_iget()
1469 inode->i_size |= ((__u64)le32_to_cpu(raw_inode->i_size_high)) << 32; in ext2_iget()
1472 if (i_size_read(inode) < 0) { in ext2_iget()
1477 inode->i_generation = le32_to_cpu(raw_inode->i_generation); in ext2_iget()
1479 ei->i_block_group = (ino - 1) / EXT2_INODES_PER_GROUP(inode->i_sb); in ext2_iget()
1489 if (S_ISREG(inode->i_mode)) { in ext2_iget()
1490 ext2_set_file_ops(inode); in ext2_iget()
1491 } else if (S_ISDIR(inode->i_mode)) { in ext2_iget()
1492 inode->i_op = &ext2_dir_inode_operations; in ext2_iget()
1493 inode->i_fop = &ext2_dir_operations; in ext2_iget()
1494 if (test_opt(inode->i_sb, NOBH)) in ext2_iget()
1495 inode->i_mapping->a_ops = &ext2_nobh_aops; in ext2_iget()
1497 inode->i_mapping->a_ops = &ext2_aops; in ext2_iget()
1498 } else if (S_ISLNK(inode->i_mode)) { in ext2_iget()
1499 if (ext2_inode_is_fast_symlink(inode)) { in ext2_iget()
1500 inode->i_link = (char *)ei->i_data; in ext2_iget()
1501 inode->i_op = &ext2_fast_symlink_inode_operations; in ext2_iget()
1502 nd_terminate_link(ei->i_data, inode->i_size, in ext2_iget()
1505 inode->i_op = &ext2_symlink_inode_operations; in ext2_iget()
1506 inode_nohighmem(inode); in ext2_iget()
1507 if (test_opt(inode->i_sb, NOBH)) in ext2_iget()
1508 inode->i_mapping->a_ops = &ext2_nobh_aops; in ext2_iget()
1510 inode->i_mapping->a_ops = &ext2_aops; in ext2_iget()
1513 inode->i_op = &ext2_special_inode_operations; in ext2_iget()
1515 init_special_inode(inode, inode->i_mode, in ext2_iget()
1518 init_special_inode(inode, inode->i_mode, in ext2_iget()
1522 unlock_new_inode(inode); in ext2_iget()
1523 return inode; in ext2_iget()
1527 iget_failed(inode); in ext2_iget()
1531 static int __ext2_write_inode(struct inode *inode, int do_sync) in __ext2_write_inode() argument
1533 struct ext2_inode_info *ei = EXT2_I(inode); in __ext2_write_inode()
1534 struct super_block *sb = inode->i_sb; in __ext2_write_inode()
1535 ino_t ino = inode->i_ino; in __ext2_write_inode()
1536 uid_t uid = i_uid_read(inode); in __ext2_write_inode()
1537 gid_t gid = i_gid_read(inode); in __ext2_write_inode()
1551 raw_inode->i_mode = cpu_to_le16(inode->i_mode); in __ext2_write_inode()
1572 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink); in __ext2_write_inode()
1573 raw_inode->i_size = cpu_to_le32(inode->i_size); in __ext2_write_inode()
1574 raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec); in __ext2_write_inode()
1575 raw_inode->i_ctime = cpu_to_le32(inode->i_ctime.tv_sec); in __ext2_write_inode()
1576 raw_inode->i_mtime = cpu_to_le32(inode->i_mtime.tv_sec); in __ext2_write_inode()
1578 raw_inode->i_blocks = cpu_to_le32(inode->i_blocks); in __ext2_write_inode()
1585 if (!S_ISREG(inode->i_mode)) in __ext2_write_inode()
1588 raw_inode->i_size_high = cpu_to_le32(inode->i_size >> 32); in __ext2_write_inode()
1589 if (inode->i_size > 0x7fffffffULL) { in __ext2_write_inode()
1607 raw_inode->i_generation = cpu_to_le32(inode->i_generation); in __ext2_write_inode()
1608 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) { in __ext2_write_inode()
1609 if (old_valid_dev(inode->i_rdev)) { in __ext2_write_inode()
1611 cpu_to_le32(old_encode_dev(inode->i_rdev)); in __ext2_write_inode()
1616 cpu_to_le32(new_encode_dev(inode->i_rdev)); in __ext2_write_inode()
1635 int ext2_write_inode(struct inode *inode, struct writeback_control *wbc) in ext2_write_inode() argument
1637 return __ext2_write_inode(inode, wbc->sync_mode == WB_SYNC_ALL); in ext2_write_inode()
1643 struct inode *inode = d_inode(path->dentry); in ext2_getattr() local
1644 struct ext2_inode_info *ei = EXT2_I(inode); in ext2_getattr()
1662 generic_fillattr(inode, stat); in ext2_getattr()
1668 struct inode *inode = d_inode(dentry); in ext2_setattr() local
1675 if (is_quota_modification(inode, iattr)) { in ext2_setattr()
1676 error = dquot_initialize(inode); in ext2_setattr()
1680 if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) || in ext2_setattr()
1681 (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) { in ext2_setattr()
1682 error = dquot_transfer(inode, iattr); in ext2_setattr()
1686 if (iattr->ia_valid & ATTR_SIZE && iattr->ia_size != inode->i_size) { in ext2_setattr()
1687 error = ext2_setsize(inode, iattr->ia_size); in ext2_setattr()
1691 setattr_copy(inode, iattr); in ext2_setattr()
1693 error = posix_acl_chmod(inode, inode->i_mode); in ext2_setattr()
1694 mark_inode_dirty(inode); in ext2_setattr()