aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4/ialloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ext4/ialloc.c')
-rw-r--r--fs/ext4/ialloc.c230
1 files changed, 115 insertions, 115 deletions
diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
index e45dbd651736..4b92066ca08f 100644
--- a/fs/ext4/ialloc.c
+++ b/fs/ext4/ialloc.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/fs/ext3/ialloc.c 2 * linux/fs/ext4/ialloc.c
3 * 3 *
4 * Copyright (C) 1992, 1993, 1994, 1995 4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr) 5 * Remy Card (card@masi.ibp.fr)
@@ -15,8 +15,8 @@
15#include <linux/time.h> 15#include <linux/time.h>
16#include <linux/fs.h> 16#include <linux/fs.h>
17#include <linux/jbd.h> 17#include <linux/jbd.h>
18#include <linux/ext3_fs.h> 18#include <linux/ext4_fs.h>
19#include <linux/ext3_jbd.h> 19#include <linux/ext4_jbd.h>
20#include <linux/stat.h> 20#include <linux/stat.h>
21#include <linux/string.h> 21#include <linux/string.h>
22#include <linux/quotaops.h> 22#include <linux/quotaops.h>
@@ -53,16 +53,16 @@
53static struct buffer_head * 53static struct buffer_head *
54read_inode_bitmap(struct super_block * sb, unsigned long block_group) 54read_inode_bitmap(struct super_block * sb, unsigned long block_group)
55{ 55{
56 struct ext3_group_desc *desc; 56 struct ext4_group_desc *desc;
57 struct buffer_head *bh = NULL; 57 struct buffer_head *bh = NULL;
58 58
59 desc = ext3_get_group_desc(sb, block_group, NULL); 59 desc = ext4_get_group_desc(sb, block_group, NULL);
60 if (!desc) 60 if (!desc)
61 goto error_out; 61 goto error_out;
62 62
63 bh = sb_bread(sb, le32_to_cpu(desc->bg_inode_bitmap)); 63 bh = sb_bread(sb, le32_to_cpu(desc->bg_inode_bitmap));
64 if (!bh) 64 if (!bh)
65 ext3_error(sb, "read_inode_bitmap", 65 ext4_error(sb, "read_inode_bitmap",
66 "Cannot read inode bitmap - " 66 "Cannot read inode bitmap - "
67 "block_group = %lu, inode_bitmap = %u", 67 "block_group = %lu, inode_bitmap = %u",
68 block_group, le32_to_cpu(desc->bg_inode_bitmap)); 68 block_group, le32_to_cpu(desc->bg_inode_bitmap));
@@ -86,7 +86,7 @@ error_out:
86 * though), and then we'd have two inodes sharing the 86 * though), and then we'd have two inodes sharing the
87 * same inode number and space on the harddisk. 87 * same inode number and space on the harddisk.
88 */ 88 */
89void ext3_free_inode (handle_t *handle, struct inode * inode) 89void ext4_free_inode (handle_t *handle, struct inode * inode)
90{ 90{
91 struct super_block * sb = inode->i_sb; 91 struct super_block * sb = inode->i_sb;
92 int is_directory; 92 int is_directory;
@@ -95,36 +95,36 @@ void ext3_free_inode (handle_t *handle, struct inode * inode)
95 struct buffer_head *bh2; 95 struct buffer_head *bh2;
96 unsigned long block_group; 96 unsigned long block_group;
97 unsigned long bit; 97 unsigned long bit;
98 struct ext3_group_desc * gdp; 98 struct ext4_group_desc * gdp;
99 struct ext3_super_block * es; 99 struct ext4_super_block * es;
100 struct ext3_sb_info *sbi; 100 struct ext4_sb_info *sbi;
101 int fatal = 0, err; 101 int fatal = 0, err;
102 102
103 if (atomic_read(&inode->i_count) > 1) { 103 if (atomic_read(&inode->i_count) > 1) {
104 printk ("ext3_free_inode: inode has count=%d\n", 104 printk ("ext4_free_inode: inode has count=%d\n",
105 atomic_read(&inode->i_count)); 105 atomic_read(&inode->i_count));
106 return; 106 return;
107 } 107 }
108 if (inode->i_nlink) { 108 if (inode->i_nlink) {
109 printk ("ext3_free_inode: inode has nlink=%d\n", 109 printk ("ext4_free_inode: inode has nlink=%d\n",
110 inode->i_nlink); 110 inode->i_nlink);
111 return; 111 return;
112 } 112 }
113 if (!sb) { 113 if (!sb) {
114 printk("ext3_free_inode: inode on nonexistent device\n"); 114 printk("ext4_free_inode: inode on nonexistent device\n");
115 return; 115 return;
116 } 116 }
117 sbi = EXT3_SB(sb); 117 sbi = EXT4_SB(sb);
118 118
119 ino = inode->i_ino; 119 ino = inode->i_ino;
120 ext3_debug ("freeing inode %lu\n", ino); 120 ext4_debug ("freeing inode %lu\n", ino);
121 121
122 /* 122 /*
123 * Note: we must free any quota before locking the superblock, 123 * Note: we must free any quota before locking the superblock,
124 * as writing the quota to disk may need the lock as well. 124 * as writing the quota to disk may need the lock as well.
125 */ 125 */
126 DQUOT_INIT(inode); 126 DQUOT_INIT(inode);
127 ext3_xattr_delete_inode(handle, inode); 127 ext4_xattr_delete_inode(handle, inode);
128 DQUOT_FREE_INODE(inode); 128 DQUOT_FREE_INODE(inode);
129 DQUOT_DROP(inode); 129 DQUOT_DROP(inode);
130 130
@@ -133,33 +133,33 @@ void ext3_free_inode (handle_t *handle, struct inode * inode)
133 /* Do this BEFORE marking the inode not in use or returning an error */ 133 /* Do this BEFORE marking the inode not in use or returning an error */
134 clear_inode (inode); 134 clear_inode (inode);
135 135
136 es = EXT3_SB(sb)->s_es; 136 es = EXT4_SB(sb)->s_es;
137 if (ino < EXT3_FIRST_INO(sb) || ino > le32_to_cpu(es->s_inodes_count)) { 137 if (ino < EXT4_FIRST_INO(sb) || ino > le32_to_cpu(es->s_inodes_count)) {
138 ext3_error (sb, "ext3_free_inode", 138 ext4_error (sb, "ext4_free_inode",
139 "reserved or nonexistent inode %lu", ino); 139 "reserved or nonexistent inode %lu", ino);
140 goto error_return; 140 goto error_return;
141 } 141 }
142 block_group = (ino - 1) / EXT3_INODES_PER_GROUP(sb); 142 block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb);
143 bit = (ino - 1) % EXT3_INODES_PER_GROUP(sb); 143 bit = (ino - 1) % EXT4_INODES_PER_GROUP(sb);
144 bitmap_bh = read_inode_bitmap(sb, block_group); 144 bitmap_bh = read_inode_bitmap(sb, block_group);
145 if (!bitmap_bh) 145 if (!bitmap_bh)
146 goto error_return; 146 goto error_return;
147 147
148 BUFFER_TRACE(bitmap_bh, "get_write_access"); 148 BUFFER_TRACE(bitmap_bh, "get_write_access");
149 fatal = ext3_journal_get_write_access(handle, bitmap_bh); 149 fatal = ext4_journal_get_write_access(handle, bitmap_bh);
150 if (fatal) 150 if (fatal)
151 goto error_return; 151 goto error_return;
152 152
153 /* Ok, now we can actually update the inode bitmaps.. */ 153 /* Ok, now we can actually update the inode bitmaps.. */
154 if (!ext3_clear_bit_atomic(sb_bgl_lock(sbi, block_group), 154 if (!ext4_clear_bit_atomic(sb_bgl_lock(sbi, block_group),
155 bit, bitmap_bh->b_data)) 155 bit, bitmap_bh->b_data))
156 ext3_error (sb, "ext3_free_inode", 156 ext4_error (sb, "ext4_free_inode",
157 "bit already cleared for inode %lu", ino); 157 "bit already cleared for inode %lu", ino);
158 else { 158 else {
159 gdp = ext3_get_group_desc (sb, block_group, &bh2); 159 gdp = ext4_get_group_desc (sb, block_group, &bh2);
160 160
161 BUFFER_TRACE(bh2, "get_write_access"); 161 BUFFER_TRACE(bh2, "get_write_access");
162 fatal = ext3_journal_get_write_access(handle, bh2); 162 fatal = ext4_journal_get_write_access(handle, bh2);
163 if (fatal) goto error_return; 163 if (fatal) goto error_return;
164 164
165 if (gdp) { 165 if (gdp) {
@@ -175,18 +175,18 @@ void ext3_free_inode (handle_t *handle, struct inode * inode)
175 percpu_counter_dec(&sbi->s_dirs_counter); 175 percpu_counter_dec(&sbi->s_dirs_counter);
176 176
177 } 177 }
178 BUFFER_TRACE(bh2, "call ext3_journal_dirty_metadata"); 178 BUFFER_TRACE(bh2, "call ext4_journal_dirty_metadata");
179 err = ext3_journal_dirty_metadata(handle, bh2); 179 err = ext4_journal_dirty_metadata(handle, bh2);
180 if (!fatal) fatal = err; 180 if (!fatal) fatal = err;
181 } 181 }
182 BUFFER_TRACE(bitmap_bh, "call ext3_journal_dirty_metadata"); 182 BUFFER_TRACE(bitmap_bh, "call ext4_journal_dirty_metadata");
183 err = ext3_journal_dirty_metadata(handle, bitmap_bh); 183 err = ext4_journal_dirty_metadata(handle, bitmap_bh);
184 if (!fatal) 184 if (!fatal)
185 fatal = err; 185 fatal = err;
186 sb->s_dirt = 1; 186 sb->s_dirt = 1;
187error_return: 187error_return:
188 brelse(bitmap_bh); 188 brelse(bitmap_bh);
189 ext3_std_error(sb, fatal); 189 ext4_std_error(sb, fatal);
190} 190}
191 191
192/* 192/*
@@ -201,17 +201,17 @@ error_return:
201 */ 201 */
202static int find_group_dir(struct super_block *sb, struct inode *parent) 202static int find_group_dir(struct super_block *sb, struct inode *parent)
203{ 203{
204 int ngroups = EXT3_SB(sb)->s_groups_count; 204 int ngroups = EXT4_SB(sb)->s_groups_count;
205 unsigned int freei, avefreei; 205 unsigned int freei, avefreei;
206 struct ext3_group_desc *desc, *best_desc = NULL; 206 struct ext4_group_desc *desc, *best_desc = NULL;
207 struct buffer_head *bh; 207 struct buffer_head *bh;
208 int group, best_group = -1; 208 int group, best_group = -1;
209 209
210 freei = percpu_counter_read_positive(&EXT3_SB(sb)->s_freeinodes_counter); 210 freei = percpu_counter_read_positive(&EXT4_SB(sb)->s_freeinodes_counter);
211 avefreei = freei / ngroups; 211 avefreei = freei / ngroups;
212 212
213 for (group = 0; group < ngroups; group++) { 213 for (group = 0; group < ngroups; group++) {
214 desc = ext3_get_group_desc (sb, group, &bh); 214 desc = ext4_get_group_desc (sb, group, &bh);
215 if (!desc || !desc->bg_free_inodes_count) 215 if (!desc || !desc->bg_free_inodes_count)
216 continue; 216 continue;
217 if (le16_to_cpu(desc->bg_free_inodes_count) < avefreei) 217 if (le16_to_cpu(desc->bg_free_inodes_count) < avefreei)
@@ -256,19 +256,19 @@ static int find_group_dir(struct super_block *sb, struct inode *parent)
256 256
257static int find_group_orlov(struct super_block *sb, struct inode *parent) 257static int find_group_orlov(struct super_block *sb, struct inode *parent)
258{ 258{
259 int parent_group = EXT3_I(parent)->i_block_group; 259 int parent_group = EXT4_I(parent)->i_block_group;
260 struct ext3_sb_info *sbi = EXT3_SB(sb); 260 struct ext4_sb_info *sbi = EXT4_SB(sb);
261 struct ext3_super_block *es = sbi->s_es; 261 struct ext4_super_block *es = sbi->s_es;
262 int ngroups = sbi->s_groups_count; 262 int ngroups = sbi->s_groups_count;
263 int inodes_per_group = EXT3_INODES_PER_GROUP(sb); 263 int inodes_per_group = EXT4_INODES_PER_GROUP(sb);
264 unsigned int freei, avefreei; 264 unsigned int freei, avefreei;
265 ext3_fsblk_t freeb, avefreeb; 265 ext4_fsblk_t freeb, avefreeb;
266 ext3_fsblk_t blocks_per_dir; 266 ext4_fsblk_t blocks_per_dir;
267 unsigned int ndirs; 267 unsigned int ndirs;
268 int max_debt, max_dirs, min_inodes; 268 int max_debt, max_dirs, min_inodes;
269 ext3_grpblk_t min_blocks; 269 ext4_grpblk_t min_blocks;
270 int group = -1, i; 270 int group = -1, i;
271 struct ext3_group_desc *desc; 271 struct ext4_group_desc *desc;
272 struct buffer_head *bh; 272 struct buffer_head *bh;
273 273
274 freei = percpu_counter_read_positive(&sbi->s_freeinodes_counter); 274 freei = percpu_counter_read_positive(&sbi->s_freeinodes_counter);
@@ -278,7 +278,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
278 ndirs = percpu_counter_read_positive(&sbi->s_dirs_counter); 278 ndirs = percpu_counter_read_positive(&sbi->s_dirs_counter);
279 279
280 if ((parent == sb->s_root->d_inode) || 280 if ((parent == sb->s_root->d_inode) ||
281 (EXT3_I(parent)->i_flags & EXT3_TOPDIR_FL)) { 281 (EXT4_I(parent)->i_flags & EXT4_TOPDIR_FL)) {
282 int best_ndir = inodes_per_group; 282 int best_ndir = inodes_per_group;
283 int best_group = -1; 283 int best_group = -1;
284 284
@@ -286,7 +286,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
286 parent_group = (unsigned)group % ngroups; 286 parent_group = (unsigned)group % ngroups;
287 for (i = 0; i < ngroups; i++) { 287 for (i = 0; i < ngroups; i++) {
288 group = (parent_group + i) % ngroups; 288 group = (parent_group + i) % ngroups;
289 desc = ext3_get_group_desc (sb, group, &bh); 289 desc = ext4_get_group_desc (sb, group, &bh);
290 if (!desc || !desc->bg_free_inodes_count) 290 if (!desc || !desc->bg_free_inodes_count)
291 continue; 291 continue;
292 if (le16_to_cpu(desc->bg_used_dirs_count) >= best_ndir) 292 if (le16_to_cpu(desc->bg_used_dirs_count) >= best_ndir)
@@ -307,9 +307,9 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
307 307
308 max_dirs = ndirs / ngroups + inodes_per_group / 16; 308 max_dirs = ndirs / ngroups + inodes_per_group / 16;
309 min_inodes = avefreei - inodes_per_group / 4; 309 min_inodes = avefreei - inodes_per_group / 4;
310 min_blocks = avefreeb - EXT3_BLOCKS_PER_GROUP(sb) / 4; 310 min_blocks = avefreeb - EXT4_BLOCKS_PER_GROUP(sb) / 4;
311 311
312 max_debt = EXT3_BLOCKS_PER_GROUP(sb) / max(blocks_per_dir, (ext3_fsblk_t)BLOCK_COST); 312 max_debt = EXT4_BLOCKS_PER_GROUP(sb) / max(blocks_per_dir, (ext4_fsblk_t)BLOCK_COST);
313 if (max_debt * INODE_COST > inodes_per_group) 313 if (max_debt * INODE_COST > inodes_per_group)
314 max_debt = inodes_per_group / INODE_COST; 314 max_debt = inodes_per_group / INODE_COST;
315 if (max_debt > 255) 315 if (max_debt > 255)
@@ -319,7 +319,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
319 319
320 for (i = 0; i < ngroups; i++) { 320 for (i = 0; i < ngroups; i++) {
321 group = (parent_group + i) % ngroups; 321 group = (parent_group + i) % ngroups;
322 desc = ext3_get_group_desc (sb, group, &bh); 322 desc = ext4_get_group_desc (sb, group, &bh);
323 if (!desc || !desc->bg_free_inodes_count) 323 if (!desc || !desc->bg_free_inodes_count)
324 continue; 324 continue;
325 if (le16_to_cpu(desc->bg_used_dirs_count) >= max_dirs) 325 if (le16_to_cpu(desc->bg_used_dirs_count) >= max_dirs)
@@ -334,7 +334,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
334fallback: 334fallback:
335 for (i = 0; i < ngroups; i++) { 335 for (i = 0; i < ngroups; i++) {
336 group = (parent_group + i) % ngroups; 336 group = (parent_group + i) % ngroups;
337 desc = ext3_get_group_desc (sb, group, &bh); 337 desc = ext4_get_group_desc (sb, group, &bh);
338 if (!desc || !desc->bg_free_inodes_count) 338 if (!desc || !desc->bg_free_inodes_count)
339 continue; 339 continue;
340 if (le16_to_cpu(desc->bg_free_inodes_count) >= avefreei) 340 if (le16_to_cpu(desc->bg_free_inodes_count) >= avefreei)
@@ -355,9 +355,9 @@ fallback:
355 355
356static int find_group_other(struct super_block *sb, struct inode *parent) 356static int find_group_other(struct super_block *sb, struct inode *parent)
357{ 357{
358 int parent_group = EXT3_I(parent)->i_block_group; 358 int parent_group = EXT4_I(parent)->i_block_group;
359 int ngroups = EXT3_SB(sb)->s_groups_count; 359 int ngroups = EXT4_SB(sb)->s_groups_count;
360 struct ext3_group_desc *desc; 360 struct ext4_group_desc *desc;
361 struct buffer_head *bh; 361 struct buffer_head *bh;
362 int group, i; 362 int group, i;
363 363
@@ -365,7 +365,7 @@ static int find_group_other(struct super_block *sb, struct inode *parent)
365 * Try to place the inode in its parent directory 365 * Try to place the inode in its parent directory
366 */ 366 */
367 group = parent_group; 367 group = parent_group;
368 desc = ext3_get_group_desc (sb, group, &bh); 368 desc = ext4_get_group_desc (sb, group, &bh);
369 if (desc && le16_to_cpu(desc->bg_free_inodes_count) && 369 if (desc && le16_to_cpu(desc->bg_free_inodes_count) &&
370 le16_to_cpu(desc->bg_free_blocks_count)) 370 le16_to_cpu(desc->bg_free_blocks_count))
371 return group; 371 return group;
@@ -389,7 +389,7 @@ static int find_group_other(struct super_block *sb, struct inode *parent)
389 group += i; 389 group += i;
390 if (group >= ngroups) 390 if (group >= ngroups)
391 group -= ngroups; 391 group -= ngroups;
392 desc = ext3_get_group_desc (sb, group, &bh); 392 desc = ext4_get_group_desc (sb, group, &bh);
393 if (desc && le16_to_cpu(desc->bg_free_inodes_count) && 393 if (desc && le16_to_cpu(desc->bg_free_inodes_count) &&
394 le16_to_cpu(desc->bg_free_blocks_count)) 394 le16_to_cpu(desc->bg_free_blocks_count))
395 return group; 395 return group;
@@ -403,7 +403,7 @@ static int find_group_other(struct super_block *sb, struct inode *parent)
403 for (i = 0; i < ngroups; i++) { 403 for (i = 0; i < ngroups; i++) {
404 if (++group >= ngroups) 404 if (++group >= ngroups)
405 group = 0; 405 group = 0;
406 desc = ext3_get_group_desc (sb, group, &bh); 406 desc = ext4_get_group_desc (sb, group, &bh);
407 if (desc && le16_to_cpu(desc->bg_free_inodes_count)) 407 if (desc && le16_to_cpu(desc->bg_free_inodes_count))
408 return group; 408 return group;
409 } 409 }
@@ -421,7 +421,7 @@ static int find_group_other(struct super_block *sb, struct inode *parent)
421 * For other inodes, search forward from the parent directory's block 421 * For other inodes, search forward from the parent directory's block
422 * group to find a free inode. 422 * group to find a free inode.
423 */ 423 */
424struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode) 424struct inode *ext4_new_inode(handle_t *handle, struct inode * dir, int mode)
425{ 425{
426 struct super_block *sb; 426 struct super_block *sb;
427 struct buffer_head *bitmap_bh = NULL; 427 struct buffer_head *bitmap_bh = NULL;
@@ -429,10 +429,10 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode)
429 int group; 429 int group;
430 unsigned long ino = 0; 430 unsigned long ino = 0;
431 struct inode * inode; 431 struct inode * inode;
432 struct ext3_group_desc * gdp = NULL; 432 struct ext4_group_desc * gdp = NULL;
433 struct ext3_super_block * es; 433 struct ext4_super_block * es;
434 struct ext3_inode_info *ei; 434 struct ext4_inode_info *ei;
435 struct ext3_sb_info *sbi; 435 struct ext4_sb_info *sbi;
436 int err = 0; 436 int err = 0;
437 struct inode *ret; 437 struct inode *ret;
438 int i; 438 int i;
@@ -445,9 +445,9 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode)
445 inode = new_inode(sb); 445 inode = new_inode(sb);
446 if (!inode) 446 if (!inode)
447 return ERR_PTR(-ENOMEM); 447 return ERR_PTR(-ENOMEM);
448 ei = EXT3_I(inode); 448 ei = EXT4_I(inode);
449 449
450 sbi = EXT3_SB(sb); 450 sbi = EXT4_SB(sb);
451 es = sbi->s_es; 451 es = sbi->s_es;
452 if (S_ISDIR(mode)) { 452 if (S_ISDIR(mode)) {
453 if (test_opt (sb, OLDALLOC)) 453 if (test_opt (sb, OLDALLOC))
@@ -464,7 +464,7 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode)
464 for (i = 0; i < sbi->s_groups_count; i++) { 464 for (i = 0; i < sbi->s_groups_count; i++) {
465 err = -EIO; 465 err = -EIO;
466 466
467 gdp = ext3_get_group_desc(sb, group, &bh2); 467 gdp = ext4_get_group_desc(sb, group, &bh2);
468 if (!gdp) 468 if (!gdp)
469 goto fail; 469 goto fail;
470 470
@@ -476,21 +476,21 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode)
476 ino = 0; 476 ino = 0;
477 477
478repeat_in_this_group: 478repeat_in_this_group:
479 ino = ext3_find_next_zero_bit((unsigned long *) 479 ino = ext4_find_next_zero_bit((unsigned long *)
480 bitmap_bh->b_data, EXT3_INODES_PER_GROUP(sb), ino); 480 bitmap_bh->b_data, EXT4_INODES_PER_GROUP(sb), ino);
481 if (ino < EXT3_INODES_PER_GROUP(sb)) { 481 if (ino < EXT4_INODES_PER_GROUP(sb)) {
482 482
483 BUFFER_TRACE(bitmap_bh, "get_write_access"); 483 BUFFER_TRACE(bitmap_bh, "get_write_access");
484 err = ext3_journal_get_write_access(handle, bitmap_bh); 484 err = ext4_journal_get_write_access(handle, bitmap_bh);
485 if (err) 485 if (err)
486 goto fail; 486 goto fail;
487 487
488 if (!ext3_set_bit_atomic(sb_bgl_lock(sbi, group), 488 if (!ext4_set_bit_atomic(sb_bgl_lock(sbi, group),
489 ino, bitmap_bh->b_data)) { 489 ino, bitmap_bh->b_data)) {
490 /* we won it */ 490 /* we won it */
491 BUFFER_TRACE(bitmap_bh, 491 BUFFER_TRACE(bitmap_bh,
492 "call ext3_journal_dirty_metadata"); 492 "call ext4_journal_dirty_metadata");
493 err = ext3_journal_dirty_metadata(handle, 493 err = ext4_journal_dirty_metadata(handle,
494 bitmap_bh); 494 bitmap_bh);
495 if (err) 495 if (err)
496 goto fail; 496 goto fail;
@@ -499,7 +499,7 @@ repeat_in_this_group:
499 /* we lost it */ 499 /* we lost it */
500 journal_release_buffer(handle, bitmap_bh); 500 journal_release_buffer(handle, bitmap_bh);
501 501
502 if (++ino < EXT3_INODES_PER_GROUP(sb)) 502 if (++ino < EXT4_INODES_PER_GROUP(sb))
503 goto repeat_in_this_group; 503 goto repeat_in_this_group;
504 } 504 }
505 505
@@ -517,9 +517,9 @@ repeat_in_this_group:
517 goto out; 517 goto out;
518 518
519got: 519got:
520 ino += group * EXT3_INODES_PER_GROUP(sb) + 1; 520 ino += group * EXT4_INODES_PER_GROUP(sb) + 1;
521 if (ino < EXT3_FIRST_INO(sb) || ino > le32_to_cpu(es->s_inodes_count)) { 521 if (ino < EXT4_FIRST_INO(sb) || ino > le32_to_cpu(es->s_inodes_count)) {
522 ext3_error (sb, "ext3_new_inode", 522 ext4_error (sb, "ext4_new_inode",
523 "reserved inode or inode > inodes count - " 523 "reserved inode or inode > inodes count - "
524 "block_group = %d, inode=%lu", group, ino); 524 "block_group = %d, inode=%lu", group, ino);
525 err = -EIO; 525 err = -EIO;
@@ -527,7 +527,7 @@ got:
527 } 527 }
528 528
529 BUFFER_TRACE(bh2, "get_write_access"); 529 BUFFER_TRACE(bh2, "get_write_access");
530 err = ext3_journal_get_write_access(handle, bh2); 530 err = ext4_journal_get_write_access(handle, bh2);
531 if (err) goto fail; 531 if (err) goto fail;
532 spin_lock(sb_bgl_lock(sbi, group)); 532 spin_lock(sb_bgl_lock(sbi, group));
533 gdp->bg_free_inodes_count = 533 gdp->bg_free_inodes_count =
@@ -537,8 +537,8 @@ got:
537 cpu_to_le16(le16_to_cpu(gdp->bg_used_dirs_count) + 1); 537 cpu_to_le16(le16_to_cpu(gdp->bg_used_dirs_count) + 1);
538 } 538 }
539 spin_unlock(sb_bgl_lock(sbi, group)); 539 spin_unlock(sb_bgl_lock(sbi, group));
540 BUFFER_TRACE(bh2, "call ext3_journal_dirty_metadata"); 540 BUFFER_TRACE(bh2, "call ext4_journal_dirty_metadata");
541 err = ext3_journal_dirty_metadata(handle, bh2); 541 err = ext4_journal_dirty_metadata(handle, bh2);
542 if (err) goto fail; 542 if (err) goto fail;
543 543
544 percpu_counter_dec(&sbi->s_freeinodes_counter); 544 percpu_counter_dec(&sbi->s_freeinodes_counter);
@@ -566,13 +566,13 @@ got:
566 ei->i_dir_start_lookup = 0; 566 ei->i_dir_start_lookup = 0;
567 ei->i_disksize = 0; 567 ei->i_disksize = 0;
568 568
569 ei->i_flags = EXT3_I(dir)->i_flags & ~EXT3_INDEX_FL; 569 ei->i_flags = EXT4_I(dir)->i_flags & ~EXT4_INDEX_FL;
570 if (S_ISLNK(mode)) 570 if (S_ISLNK(mode))
571 ei->i_flags &= ~(EXT3_IMMUTABLE_FL|EXT3_APPEND_FL); 571 ei->i_flags &= ~(EXT4_IMMUTABLE_FL|EXT4_APPEND_FL);
572 /* dirsync only applies to directories */ 572 /* dirsync only applies to directories */
573 if (!S_ISDIR(mode)) 573 if (!S_ISDIR(mode))
574 ei->i_flags &= ~EXT3_DIRSYNC_FL; 574 ei->i_flags &= ~EXT4_DIRSYNC_FL;
575#ifdef EXT3_FRAGMENTS 575#ifdef EXT4_FRAGMENTS
576 ei->i_faddr = 0; 576 ei->i_faddr = 0;
577 ei->i_frag_no = 0; 577 ei->i_frag_no = 0;
578 ei->i_frag_size = 0; 578 ei->i_frag_size = 0;
@@ -583,7 +583,7 @@ got:
583 ei->i_block_alloc_info = NULL; 583 ei->i_block_alloc_info = NULL;
584 ei->i_block_group = group; 584 ei->i_block_group = group;
585 585
586 ext3_set_inode_flags(inode); 586 ext4_set_inode_flags(inode);
587 if (IS_DIRSYNC(inode)) 587 if (IS_DIRSYNC(inode))
588 handle->h_sync = 1; 588 handle->h_sync = 1;
589 insert_inode_hash(inode); 589 insert_inode_hash(inode);
@@ -591,10 +591,10 @@ got:
591 inode->i_generation = sbi->s_next_generation++; 591 inode->i_generation = sbi->s_next_generation++;
592 spin_unlock(&sbi->s_next_gen_lock); 592 spin_unlock(&sbi->s_next_gen_lock);
593 593
594 ei->i_state = EXT3_STATE_NEW; 594 ei->i_state = EXT4_STATE_NEW;
595 ei->i_extra_isize = 595 ei->i_extra_isize =
596 (EXT3_INODE_SIZE(inode->i_sb) > EXT3_GOOD_OLD_INODE_SIZE) ? 596 (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE) ?
597 sizeof(struct ext3_inode) - EXT3_GOOD_OLD_INODE_SIZE : 0; 597 sizeof(struct ext4_inode) - EXT4_GOOD_OLD_INODE_SIZE : 0;
598 598
599 ret = inode; 599 ret = inode;
600 if(DQUOT_ALLOC_INODE(inode)) { 600 if(DQUOT_ALLOC_INODE(inode)) {
@@ -602,24 +602,24 @@ got:
602 goto fail_drop; 602 goto fail_drop;
603 } 603 }
604 604
605 err = ext3_init_acl(handle, inode, dir); 605 err = ext4_init_acl(handle, inode, dir);
606 if (err) 606 if (err)
607 goto fail_free_drop; 607 goto fail_free_drop;
608 608
609 err = ext3_init_security(handle,inode, dir); 609 err = ext4_init_security(handle,inode, dir);
610 if (err) 610 if (err)
611 goto fail_free_drop; 611 goto fail_free_drop;
612 612
613 err = ext3_mark_inode_dirty(handle, inode); 613 err = ext4_mark_inode_dirty(handle, inode);
614 if (err) { 614 if (err) {
615 ext3_std_error(sb, err); 615 ext4_std_error(sb, err);
616 goto fail_free_drop; 616 goto fail_free_drop;
617 } 617 }
618 618
619 ext3_debug("allocating inode %lu\n", inode->i_ino); 619 ext4_debug("allocating inode %lu\n", inode->i_ino);
620 goto really_out; 620 goto really_out;
621fail: 621fail:
622 ext3_std_error(sb, err); 622 ext4_std_error(sb, err);
623out: 623out:
624 iput(inode); 624 iput(inode);
625 ret = ERR_PTR(err); 625 ret = ERR_PTR(err);
@@ -640,9 +640,9 @@ fail_drop:
640} 640}
641 641
642/* Verify that we are loading a valid orphan from disk */ 642/* Verify that we are loading a valid orphan from disk */
643struct inode *ext3_orphan_get(struct super_block *sb, unsigned long ino) 643struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
644{ 644{
645 unsigned long max_ino = le32_to_cpu(EXT3_SB(sb)->s_es->s_inodes_count); 645 unsigned long max_ino = le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count);
646 unsigned long block_group; 646 unsigned long block_group;
647 int bit; 647 int bit;
648 struct buffer_head *bitmap_bh = NULL; 648 struct buffer_head *bitmap_bh = NULL;
@@ -650,16 +650,16 @@ struct inode *ext3_orphan_get(struct super_block *sb, unsigned long ino)
650 650
651 /* Error cases - e2fsck has already cleaned up for us */ 651 /* Error cases - e2fsck has already cleaned up for us */
652 if (ino > max_ino) { 652 if (ino > max_ino) {
653 ext3_warning(sb, __FUNCTION__, 653 ext4_warning(sb, __FUNCTION__,
654 "bad orphan ino %lu! e2fsck was run?", ino); 654 "bad orphan ino %lu! e2fsck was run?", ino);
655 goto out; 655 goto out;
656 } 656 }
657 657
658 block_group = (ino - 1) / EXT3_INODES_PER_GROUP(sb); 658 block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb);
659 bit = (ino - 1) % EXT3_INODES_PER_GROUP(sb); 659 bit = (ino - 1) % EXT4_INODES_PER_GROUP(sb);
660 bitmap_bh = read_inode_bitmap(sb, block_group); 660 bitmap_bh = read_inode_bitmap(sb, block_group);
661 if (!bitmap_bh) { 661 if (!bitmap_bh) {
662 ext3_warning(sb, __FUNCTION__, 662 ext4_warning(sb, __FUNCTION__,
663 "inode bitmap error for orphan %lu", ino); 663 "inode bitmap error for orphan %lu", ino);
664 goto out; 664 goto out;
665 } 665 }
@@ -668,14 +668,14 @@ struct inode *ext3_orphan_get(struct super_block *sb, unsigned long ino)
668 * is a valid orphan (no e2fsck run on fs). Orphans also include 668 * is a valid orphan (no e2fsck run on fs). Orphans also include
669 * inodes that were being truncated, so we can't check i_nlink==0. 669 * inodes that were being truncated, so we can't check i_nlink==0.
670 */ 670 */
671 if (!ext3_test_bit(bit, bitmap_bh->b_data) || 671 if (!ext4_test_bit(bit, bitmap_bh->b_data) ||
672 !(inode = iget(sb, ino)) || is_bad_inode(inode) || 672 !(inode = iget(sb, ino)) || is_bad_inode(inode) ||
673 NEXT_ORPHAN(inode) > max_ino) { 673 NEXT_ORPHAN(inode) > max_ino) {
674 ext3_warning(sb, __FUNCTION__, 674 ext4_warning(sb, __FUNCTION__,
675 "bad orphan inode %lu! e2fsck was run?", ino); 675 "bad orphan inode %lu! e2fsck was run?", ino);
676 printk(KERN_NOTICE "ext3_test_bit(bit=%d, block=%llu) = %d\n", 676 printk(KERN_NOTICE "ext4_test_bit(bit=%d, block=%llu) = %d\n",
677 bit, (unsigned long long)bitmap_bh->b_blocknr, 677 bit, (unsigned long long)bitmap_bh->b_blocknr,
678 ext3_test_bit(bit, bitmap_bh->b_data)); 678 ext4_test_bit(bit, bitmap_bh->b_data));
679 printk(KERN_NOTICE "inode=%p\n", inode); 679 printk(KERN_NOTICE "inode=%p\n", inode);
680 if (inode) { 680 if (inode) {
681 printk(KERN_NOTICE "is_bad_inode(inode)=%d\n", 681 printk(KERN_NOTICE "is_bad_inode(inode)=%d\n",
@@ -695,22 +695,22 @@ out:
695 return inode; 695 return inode;
696} 696}
697 697
698unsigned long ext3_count_free_inodes (struct super_block * sb) 698unsigned long ext4_count_free_inodes (struct super_block * sb)
699{ 699{
700 unsigned long desc_count; 700 unsigned long desc_count;
701 struct ext3_group_desc *gdp; 701 struct ext4_group_desc *gdp;
702 int i; 702 int i;
703#ifdef EXT3FS_DEBUG 703#ifdef EXT4FS_DEBUG
704 struct ext3_super_block *es; 704 struct ext4_super_block *es;
705 unsigned long bitmap_count, x; 705 unsigned long bitmap_count, x;
706 struct buffer_head *bitmap_bh = NULL; 706 struct buffer_head *bitmap_bh = NULL;
707 707
708 es = EXT3_SB(sb)->s_es; 708 es = EXT4_SB(sb)->s_es;
709 desc_count = 0; 709 desc_count = 0;
710 bitmap_count = 0; 710 bitmap_count = 0;
711 gdp = NULL; 711 gdp = NULL;
712 for (i = 0; i < EXT3_SB(sb)->s_groups_count; i++) { 712 for (i = 0; i < EXT4_SB(sb)->s_groups_count; i++) {
713 gdp = ext3_get_group_desc (sb, i, NULL); 713 gdp = ext4_get_group_desc (sb, i, NULL);
714 if (!gdp) 714 if (!gdp)
715 continue; 715 continue;
716 desc_count += le16_to_cpu(gdp->bg_free_inodes_count); 716 desc_count += le16_to_cpu(gdp->bg_free_inodes_count);
@@ -719,19 +719,19 @@ unsigned long ext3_count_free_inodes (struct super_block * sb)
719 if (!bitmap_bh) 719 if (!bitmap_bh)
720 continue; 720 continue;
721 721
722 x = ext3_count_free(bitmap_bh, EXT3_INODES_PER_GROUP(sb) / 8); 722 x = ext4_count_free(bitmap_bh, EXT4_INODES_PER_GROUP(sb) / 8);
723 printk("group %d: stored = %d, counted = %lu\n", 723 printk("group %d: stored = %d, counted = %lu\n",
724 i, le16_to_cpu(gdp->bg_free_inodes_count), x); 724 i, le16_to_cpu(gdp->bg_free_inodes_count), x);
725 bitmap_count += x; 725 bitmap_count += x;
726 } 726 }
727 brelse(bitmap_bh); 727 brelse(bitmap_bh);
728 printk("ext3_count_free_inodes: stored = %u, computed = %lu, %lu\n", 728 printk("ext4_count_free_inodes: stored = %u, computed = %lu, %lu\n",
729 le32_to_cpu(es->s_free_inodes_count), desc_count, bitmap_count); 729 le32_to_cpu(es->s_free_inodes_count), desc_count, bitmap_count);
730 return desc_count; 730 return desc_count;
731#else 731#else
732 desc_count = 0; 732 desc_count = 0;
733 for (i = 0; i < EXT3_SB(sb)->s_groups_count; i++) { 733 for (i = 0; i < EXT4_SB(sb)->s_groups_count; i++) {
734 gdp = ext3_get_group_desc (sb, i, NULL); 734 gdp = ext4_get_group_desc (sb, i, NULL);
735 if (!gdp) 735 if (!gdp)
736 continue; 736 continue;
737 desc_count += le16_to_cpu(gdp->bg_free_inodes_count); 737 desc_count += le16_to_cpu(gdp->bg_free_inodes_count);
@@ -742,13 +742,13 @@ unsigned long ext3_count_free_inodes (struct super_block * sb)
742} 742}
743 743
744/* Called at mount-time, super-block is locked */ 744/* Called at mount-time, super-block is locked */
745unsigned long ext3_count_dirs (struct super_block * sb) 745unsigned long ext4_count_dirs (struct super_block * sb)
746{ 746{
747 unsigned long count = 0; 747 unsigned long count = 0;
748 int i; 748 int i;
749 749
750 for (i = 0; i < EXT3_SB(sb)->s_groups_count; i++) { 750 for (i = 0; i < EXT4_SB(sb)->s_groups_count; i++) {
751 struct ext3_group_desc *gdp = ext3_get_group_desc (sb, i, NULL); 751 struct ext4_group_desc *gdp = ext4_get_group_desc (sb, i, NULL);
752 if (!gdp) 752 if (!gdp)
753 continue; 753 continue;
754 count += le16_to_cpu(gdp->bg_used_dirs_count); 754 count += le16_to_cpu(gdp->bg_used_dirs_count);