diff options
Diffstat (limited to 'fs/ufs/truncate.c')
-rw-r--r-- | fs/ufs/truncate.c | 72 |
1 files changed, 16 insertions, 56 deletions
diff --git a/fs/ufs/truncate.c b/fs/ufs/truncate.c index 61d2e35012a4..02e86291ef8a 100644 --- a/fs/ufs/truncate.c +++ b/fs/ufs/truncate.c | |||
@@ -29,6 +29,11 @@ | |||
29 | * Idea from Pierre del Perugia <delperug@gla.ecoledoc.ibp.fr> | 29 | * Idea from Pierre del Perugia <delperug@gla.ecoledoc.ibp.fr> |
30 | */ | 30 | */ |
31 | 31 | ||
32 | /* | ||
33 | * Modified to avoid infinite loop on 2006 by | ||
34 | * Evgeniy Dushistov <dushistov@mail.ru> | ||
35 | */ | ||
36 | |||
32 | #include <linux/errno.h> | 37 | #include <linux/errno.h> |
33 | #include <linux/fs.h> | 38 | #include <linux/fs.h> |
34 | #include <linux/ufs_fs.h> | 39 | #include <linux/ufs_fs.h> |
@@ -65,19 +70,16 @@ | |||
65 | #define DIRECT_BLOCK ((inode->i_size + uspi->s_bsize - 1) >> uspi->s_bshift) | 70 | #define DIRECT_BLOCK ((inode->i_size + uspi->s_bsize - 1) >> uspi->s_bshift) |
66 | #define DIRECT_FRAGMENT ((inode->i_size + uspi->s_fsize - 1) >> uspi->s_fshift) | 71 | #define DIRECT_FRAGMENT ((inode->i_size + uspi->s_fsize - 1) >> uspi->s_fshift) |
67 | 72 | ||
68 | #define DATA_BUFFER_USED(bh) \ | ||
69 | (atomic_read(&bh->b_count)>1 || buffer_locked(bh)) | ||
70 | 73 | ||
71 | static int ufs_trunc_direct (struct inode * inode) | 74 | static int ufs_trunc_direct (struct inode * inode) |
72 | { | 75 | { |
73 | struct ufs_inode_info *ufsi = UFS_I(inode); | 76 | struct ufs_inode_info *ufsi = UFS_I(inode); |
74 | struct super_block * sb; | 77 | struct super_block * sb; |
75 | struct ufs_sb_private_info * uspi; | 78 | struct ufs_sb_private_info * uspi; |
76 | struct buffer_head * bh; | ||
77 | __fs32 * p; | 79 | __fs32 * p; |
78 | unsigned frag1, frag2, frag3, frag4, block1, block2; | 80 | unsigned frag1, frag2, frag3, frag4, block1, block2; |
79 | unsigned frag_to_free, free_count; | 81 | unsigned frag_to_free, free_count; |
80 | unsigned i, j, tmp; | 82 | unsigned i, tmp; |
81 | int retry; | 83 | int retry; |
82 | 84 | ||
83 | UFSD(("ENTER\n")) | 85 | UFSD(("ENTER\n")) |
@@ -117,15 +119,7 @@ static int ufs_trunc_direct (struct inode * inode) | |||
117 | ufs_panic (sb, "ufs_trunc_direct", "internal error"); | 119 | ufs_panic (sb, "ufs_trunc_direct", "internal error"); |
118 | frag1 = ufs_fragnum (frag1); | 120 | frag1 = ufs_fragnum (frag1); |
119 | frag2 = ufs_fragnum (frag2); | 121 | frag2 = ufs_fragnum (frag2); |
120 | for (j = frag1; j < frag2; j++) { | 122 | |
121 | bh = sb_find_get_block (sb, tmp + j); | ||
122 | if ((bh && DATA_BUFFER_USED(bh)) || tmp != fs32_to_cpu(sb, *p)) { | ||
123 | retry = 1; | ||
124 | brelse (bh); | ||
125 | goto next1; | ||
126 | } | ||
127 | bforget (bh); | ||
128 | } | ||
129 | inode->i_blocks -= (frag2-frag1) << uspi->s_nspfshift; | 123 | inode->i_blocks -= (frag2-frag1) << uspi->s_nspfshift; |
130 | mark_inode_dirty(inode); | 124 | mark_inode_dirty(inode); |
131 | ufs_free_fragments (inode, tmp + frag1, frag2 - frag1); | 125 | ufs_free_fragments (inode, tmp + frag1, frag2 - frag1); |
@@ -140,15 +134,7 @@ next1: | |||
140 | tmp = fs32_to_cpu(sb, *p); | 134 | tmp = fs32_to_cpu(sb, *p); |
141 | if (!tmp) | 135 | if (!tmp) |
142 | continue; | 136 | continue; |
143 | for (j = 0; j < uspi->s_fpb; j++) { | 137 | |
144 | bh = sb_find_get_block(sb, tmp + j); | ||
145 | if ((bh && DATA_BUFFER_USED(bh)) || tmp != fs32_to_cpu(sb, *p)) { | ||
146 | retry = 1; | ||
147 | brelse (bh); | ||
148 | goto next2; | ||
149 | } | ||
150 | bforget (bh); | ||
151 | } | ||
152 | *p = 0; | 138 | *p = 0; |
153 | inode->i_blocks -= uspi->s_nspb; | 139 | inode->i_blocks -= uspi->s_nspb; |
154 | mark_inode_dirty(inode); | 140 | mark_inode_dirty(inode); |
@@ -162,7 +148,6 @@ next1: | |||
162 | frag_to_free = tmp; | 148 | frag_to_free = tmp; |
163 | free_count = uspi->s_fpb; | 149 | free_count = uspi->s_fpb; |
164 | } | 150 | } |
165 | next2:; | ||
166 | } | 151 | } |
167 | 152 | ||
168 | if (free_count > 0) | 153 | if (free_count > 0) |
@@ -179,15 +164,7 @@ next2:; | |||
179 | if (!tmp ) | 164 | if (!tmp ) |
180 | ufs_panic(sb, "ufs_truncate_direct", "internal error"); | 165 | ufs_panic(sb, "ufs_truncate_direct", "internal error"); |
181 | frag4 = ufs_fragnum (frag4); | 166 | frag4 = ufs_fragnum (frag4); |
182 | for (j = 0; j < frag4; j++) { | 167 | |
183 | bh = sb_find_get_block (sb, tmp + j); | ||
184 | if ((bh && DATA_BUFFER_USED(bh)) || tmp != fs32_to_cpu(sb, *p)) { | ||
185 | retry = 1; | ||
186 | brelse (bh); | ||
187 | goto next1; | ||
188 | } | ||
189 | bforget (bh); | ||
190 | } | ||
191 | *p = 0; | 168 | *p = 0; |
192 | inode->i_blocks -= frag4 << uspi->s_nspfshift; | 169 | inode->i_blocks -= frag4 << uspi->s_nspfshift; |
193 | mark_inode_dirty(inode); | 170 | mark_inode_dirty(inode); |
@@ -204,9 +181,8 @@ static int ufs_trunc_indirect (struct inode * inode, unsigned offset, __fs32 *p) | |||
204 | struct super_block * sb; | 181 | struct super_block * sb; |
205 | struct ufs_sb_private_info * uspi; | 182 | struct ufs_sb_private_info * uspi; |
206 | struct ufs_buffer_head * ind_ubh; | 183 | struct ufs_buffer_head * ind_ubh; |
207 | struct buffer_head * bh; | ||
208 | __fs32 * ind; | 184 | __fs32 * ind; |
209 | unsigned indirect_block, i, j, tmp; | 185 | unsigned indirect_block, i, tmp; |
210 | unsigned frag_to_free, free_count; | 186 | unsigned frag_to_free, free_count; |
211 | int retry; | 187 | int retry; |
212 | 188 | ||
@@ -238,15 +214,7 @@ static int ufs_trunc_indirect (struct inode * inode, unsigned offset, __fs32 *p) | |||
238 | tmp = fs32_to_cpu(sb, *ind); | 214 | tmp = fs32_to_cpu(sb, *ind); |
239 | if (!tmp) | 215 | if (!tmp) |
240 | continue; | 216 | continue; |
241 | for (j = 0; j < uspi->s_fpb; j++) { | 217 | |
242 | bh = sb_find_get_block(sb, tmp + j); | ||
243 | if ((bh && DATA_BUFFER_USED(bh)) || tmp != fs32_to_cpu(sb, *ind)) { | ||
244 | retry = 1; | ||
245 | brelse (bh); | ||
246 | goto next; | ||
247 | } | ||
248 | bforget (bh); | ||
249 | } | ||
250 | *ind = 0; | 218 | *ind = 0; |
251 | ubh_mark_buffer_dirty(ind_ubh); | 219 | ubh_mark_buffer_dirty(ind_ubh); |
252 | if (free_count == 0) { | 220 | if (free_count == 0) { |
@@ -261,7 +229,6 @@ static int ufs_trunc_indirect (struct inode * inode, unsigned offset, __fs32 *p) | |||
261 | } | 229 | } |
262 | inode->i_blocks -= uspi->s_nspb; | 230 | inode->i_blocks -= uspi->s_nspb; |
263 | mark_inode_dirty(inode); | 231 | mark_inode_dirty(inode); |
264 | next:; | ||
265 | } | 232 | } |
266 | 233 | ||
267 | if (free_count > 0) { | 234 | if (free_count > 0) { |
@@ -430,9 +397,7 @@ void ufs_truncate (struct inode * inode) | |||
430 | struct ufs_inode_info *ufsi = UFS_I(inode); | 397 | struct ufs_inode_info *ufsi = UFS_I(inode); |
431 | struct super_block * sb; | 398 | struct super_block * sb; |
432 | struct ufs_sb_private_info * uspi; | 399 | struct ufs_sb_private_info * uspi; |
433 | struct buffer_head * bh; | 400 | int retry; |
434 | unsigned offset; | ||
435 | int err, retry; | ||
436 | 401 | ||
437 | UFSD(("ENTER\n")) | 402 | UFSD(("ENTER\n")) |
438 | sb = inode->i_sb; | 403 | sb = inode->i_sb; |
@@ -442,6 +407,9 @@ void ufs_truncate (struct inode * inode) | |||
442 | return; | 407 | return; |
443 | if (IS_APPEND(inode) || IS_IMMUTABLE(inode)) | 408 | if (IS_APPEND(inode) || IS_IMMUTABLE(inode)) |
444 | return; | 409 | return; |
410 | |||
411 | block_truncate_page(inode->i_mapping, inode->i_size, ufs_getfrag_block); | ||
412 | |||
445 | lock_kernel(); | 413 | lock_kernel(); |
446 | while (1) { | 414 | while (1) { |
447 | retry = ufs_trunc_direct(inode); | 415 | retry = ufs_trunc_direct(inode); |
@@ -457,15 +425,7 @@ void ufs_truncate (struct inode * inode) | |||
457 | blk_run_address_space(inode->i_mapping); | 425 | blk_run_address_space(inode->i_mapping); |
458 | yield(); | 426 | yield(); |
459 | } | 427 | } |
460 | offset = inode->i_size & uspi->s_fshift; | 428 | |
461 | if (offset) { | ||
462 | bh = ufs_bread (inode, inode->i_size >> uspi->s_fshift, 0, &err); | ||
463 | if (bh) { | ||
464 | memset (bh->b_data + offset, 0, uspi->s_fsize - offset); | ||
465 | mark_buffer_dirty (bh); | ||
466 | brelse (bh); | ||
467 | } | ||
468 | } | ||
469 | inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC; | 429 | inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC; |
470 | ufsi->i_lastfrag = DIRECT_FRAGMENT; | 430 | ufsi->i_lastfrag = DIRECT_FRAGMENT; |
471 | unlock_kernel(); | 431 | unlock_kernel(); |