errcode_t ext2fs_rewrite_to_io(ext2_filsys fs, io_channel new_io);
/* orphan.c */
+#define EXT4_MAX_ORPHAN_FILE_SIZE 8 << 20
+#define EXT4_DEFAULT_ORPHAN_FILE_SIZE 2 << 20
extern errcode_t ext2fs_create_orphan_file(ext2_filsys fs, blk_t num_blocks);
extern errcode_t ext2fs_truncate_orphan_file(ext2_filsys fs);
extern e2_blkcnt_t ext2fs_default_orphan_file_blocks(ext2_filsys fs);
memset(zerobuf, 0, fs->blocksize);
ob_tail = ext2fs_orphan_block_tail(fs, buf);
ob_tail->ob_magic = ext2fs_cpu_to_le32(EXT4_ORPHAN_BLOCK_MAGIC);
+ if (num_blocks * fs->blocksize > EXT4_MAX_ORPHAN_FILE_SIZE)
+ num_blocks = EXT4_MAX_ORPHAN_FILE_SIZE / fs->blocksize;
oi.num_blocks = num_blocks;
oi.alloc_blocks = 0;
oi.last_blk = 0;
/*
* Find reasonable size for orphan file. We choose orphan file size to be
- * between 32 and 512 filesystem blocks and not more than 1/4096 of the
- * filesystem unless it is really small.
+ * between 32 filesystem blocks and EXT4_DEFAULT_ORPHAN_FILE_SIZE, and not
+ * more than 1/fs->blocksize of the filesystem unless it is really small.
*/
e2_blkcnt_t ext2fs_default_orphan_file_blocks(ext2_filsys fs)
{
__u64 num_blocks = ext2fs_blocks_count(fs->super);
- e2_blkcnt_t blks = 512;
+ e2_blkcnt_t blks = EXT4_DEFAULT_ORPHAN_FILE_SIZE / fs->blocksize;
if (num_blocks < 128 * 1024)
blks = 32;
- else if (num_blocks < 2 * 1024 * 1024)
- blks = num_blocks / 4096;
+ else if (num_blocks < EXT4_DEFAULT_ORPHAN_FILE_SIZE)
+ blks = num_blocks / fs->blocksize;
return (blks + EXT2FS_CLUSTER_MASK(fs)) & ~EXT2FS_CLUSTER_MASK(fs);
}