]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blobdiff - lib/ext2fs/blknum.c
Merge branch 'maint' into next
[thirdparty/e2fsprogs.git] / lib / ext2fs / blknum.c
index ead23281987ebc3aa1232afd4e4f5c9d674ee416..93b64ceda51d1debf6c9ab2c160e475be05c2447 100644 (file)
@@ -523,3 +523,31 @@ void ext2fs_file_acl_block_set(ext2_filsys fs, struct ext2_inode *inode,
                inode->osd2.linux2.l_i_file_acl_high = (__u64) blk >> 32;
 }
 
+/*
+ * Set the size of the inode
+ */
+errcode_t ext2fs_inode_size_set(ext2_filsys fs, struct ext2_inode *inode,
+                               ext2_off64_t size)
+{
+       /* Only regular files get to be larger than 4GB */
+       if (!LINUX_S_ISREG(inode->i_mode) && (size >> 32))
+               return EXT2_ET_FILE_TOO_BIG;
+
+       /* If we're writing a large file, set the large_file flag */
+       if (LINUX_S_ISREG(inode->i_mode) &&
+           ext2fs_needs_large_file_feature(size) &&
+           (!EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
+                                        EXT2_FEATURE_RO_COMPAT_LARGE_FILE) ||
+            fs->super->s_rev_level == EXT2_GOOD_OLD_REV)) {
+               fs->super->s_feature_ro_compat |=
+                                       EXT2_FEATURE_RO_COMPAT_LARGE_FILE;
+               ext2fs_update_dynamic_rev(fs);
+               ext2fs_mark_super_dirty(fs);
+       }
+
+       inode->i_size = size & 0xffffffff;
+       inode->i_size_high = (size >> 32);
+
+       return 0;
+}
+