1 Index: linux-2.6.27.21-0.1/fs/ext4/ialloc.c
2 ===================================================================
3 --- linux-2.6.27.21-0.1.orig/fs/ext4/ialloc.c
4 +++ linux-2.6.27.21-0.1/fs/ext4/ialloc.c
5 @@ -721,12 +721,15 @@ struct inode *ext4_new_inode(handle_t *h
6 return ERR_PTR(-EPERM);
10 + if (sbi->s_max_dir_size > 0 && i_size_read(dir) >= sbi->s_max_dir_size)
11 + return ERR_PTR(-EFBIG);
13 inode = new_inode(sb);
15 return ERR_PTR(-ENOMEM);
22 Index: linux-2.6.27.21-0.1/fs/ext4/super.c
23 ===================================================================
24 --- linux-2.6.27.21-0.1.orig/fs/ext4/super.c
25 +++ linux-2.6.27.21-0.1/fs/ext4/super.c
27 #include <asm/uaccess.h>
28 #include <linux/kthread.h>
29 #include <linux/utsname.h>
30 +#include <linux/proc_fs.h>
33 #include "ext4_jbd2.h"
34 @@ -71,6 +72,8 @@ static void ext4_write_super(struct supe
35 static void ext4_write_super_lockfs(struct super_block *sb);
38 +struct proc_dir_entry *proc_root_ext4;
40 ext4_fsblk_t ext4_block_bitmap(struct super_block *sb,
41 struct ext4_group_desc *bg)
43 @@ -602,6 +605,9 @@ static void ext4_put_super(struct super_
46 kthread_stop(sbi->s_mmp_tsk);
48 + remove_proc_entry(EXT4_MAX_DIR_SIZE_NAME, sbi->s_proc);
53 @@ -2287,6 +2293,46 @@ static unsigned long ext4_get_stripe_siz
57 +static int ext4_max_dir_size_read(char *page, char **start, off_t off,
58 + int count, int *eof, void *data)
60 + struct ext4_sb_info *sbi = data;
67 + len = sprintf(page, "%lu\n", sbi->s_max_dir_size);
72 +static int ext4_max_dir_size_write(struct file *file, const char *buffer,
73 + unsigned long count, void *data)
75 + struct ext4_sb_info *sbi = data;
77 + unsigned long value;
80 + if (count >= sizeof(str)) {
81 + printk(KERN_ERR "EXT4-fs: %s string too long, max %u bytes\n",
82 + EXT4_MAX_DIR_SIZE_NAME, (int)sizeof(str));
86 + if (copy_from_user(str, buffer, count))
89 + value = simple_strtol(str, &end, 0);
93 + sbi->s_max_dir_size = value;
97 static int ext4_fill_super(struct super_block *sb, void *data, int silent)
98 __releases(kernel_lock)
99 __acquires(kernel_lock)
100 @@ -2311,6 +2357,7 @@ static int ext4_fill_super(struct super_
101 int needs_recovery, has_huge_files;
104 + struct proc_dir_entry *proc;
107 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
108 @@ -2881,6 +2928,22 @@ static int ext4_fill_super(struct super_
109 test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA ? "ordered":
112 + sbi->s_max_dir_size = EXT4_DEFAULT_MAX_DIR_SIZE;
113 + proc = create_proc_entry(EXT4_MAX_DIR_SIZE_NAME,
114 + S_IFREG | S_IRUGO | S_IWUSR, sbi->s_proc);
115 + if (proc == NULL) {
116 + printk(KERN_ERR "EXT4-fs: unable to create %s\n",
117 + EXT4_MAX_DIR_SIZE_NAME);
118 + remove_proc_entry(EXT4_MAX_DIR_SIZE_NAME, sbi->s_proc);
119 + remove_proc_entry(sbi->s_proc->name, proc_root_ext4);
120 + sbi->s_proc = NULL;
122 + goto failed_mount4;
125 + proc->read_proc = ext4_max_dir_size_read;
126 + proc->write_proc = ext4_max_dir_size_write;
131 @@ -3254,7 +3317,6 @@ static void ext4_commit_super(struct sup
137 * Have we just finished recovery? If so, and if we are mounting (or
138 * remounting) the filesystem readonly, then we will end up with a
139 Index: linux-2.6.27.21-0.1/fs/ext4/ext4_sb.h
140 ===================================================================
141 --- linux-2.6.27.21-0.1.orig/fs/ext4/ext4_sb.h
142 +++ linux-2.6.27.21-0.1/fs/ext4/ext4_sb.h
143 @@ -120,6 +120,7 @@ struct ext4_sb_info {
144 /* where last allocation was done - for stream allocation */
145 unsigned long s_mb_last_group;
146 unsigned long s_mb_last_start;
147 + unsigned long s_max_dir_size;
149 /* history to debug policy */
150 struct ext4_mb_history *s_mb_history;
151 Index: linux-2.6.27.21-0.1/fs/ext4/ext4.h
152 ===================================================================
153 --- linux-2.6.27.21-0.1.orig/fs/ext4/ext4.h
154 +++ linux-2.6.27.21-0.1/fs/ext4/ext4.h
155 @@ -1017,6 +1017,14 @@ struct mmp_struct {
157 #define EXT4_MMP_MIN_CHECK_INTERVAL 5
159 +extern struct proc_dir_entry *proc_root_ext4;
162 + * max directory size tunable
164 +#define EXT4_DEFAULT_MAX_DIR_SIZE 0
165 +#define EXT4_MAX_DIR_SIZE_NAME "max_dir_size"
168 * Function prototypes
170 Index: linux-2.6.27.21-0.1/fs/ext4/mballoc.c
171 ===================================================================
172 --- linux-2.6.27.21-0.1.orig/fs/ext4/mballoc.c
173 +++ linux-2.6.27.21-0.1/fs/ext4/mballoc.c
174 @@ -2943,6 +2943,7 @@ err_out:
175 remove_proc_entry(EXT4_MB_MIN_TO_SCAN_NAME, sbi->s_proc);
176 remove_proc_entry(EXT4_MB_MAX_TO_SCAN_NAME, sbi->s_proc);
177 remove_proc_entry(EXT4_MB_STATS_NAME, sbi->s_proc);
178 + remove_proc_entry(EXT4_MAX_DIR_SIZE_NAME, sbi->s_proc);
182 @@ -2963,6 +2964,7 @@ static int ext4_mb_destroy_per_dev_proc(
183 remove_proc_entry(EXT4_MB_MIN_TO_SCAN_NAME, sbi->s_proc);
184 remove_proc_entry(EXT4_MB_MAX_TO_SCAN_NAME, sbi->s_proc);
185 remove_proc_entry(EXT4_MB_STATS_NAME, sbi->s_proc);
186 + remove_proc_entry(EXT4_MAX_DIR_SIZE_NAME, sbi->s_proc);