aboutsummaryrefslogtreecommitdiffstats
path: root/fs/jffs2/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/jffs2/file.c')
-rw-r--r--fs/jffs2/file.c78
1 files changed, 34 insertions, 44 deletions
diff --git a/fs/jffs2/file.c b/fs/jffs2/file.c
index 1506673c087..61e6723535b 100644
--- a/fs/jffs2/file.c
+++ b/fs/jffs2/file.c
@@ -10,8 +10,6 @@
10 * 10 *
11 */ 11 */
12 12
13#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14
15#include <linux/kernel.h> 13#include <linux/kernel.h>
16#include <linux/fs.h> 14#include <linux/fs.h>
17#include <linux/time.h> 15#include <linux/time.h>
@@ -87,8 +85,7 @@ static int jffs2_do_readpage_nolock (struct inode *inode, struct page *pg)
87 unsigned char *pg_buf; 85 unsigned char *pg_buf;
88 int ret; 86 int ret;
89 87
90 jffs2_dbg(2, "%s(): ino #%lu, page at offset 0x%lx\n", 88 D2(printk(KERN_DEBUG "jffs2_do_readpage_nolock(): ino #%lu, page at offset 0x%lx\n", inode->i_ino, pg->index << PAGE_CACHE_SHIFT));
91 __func__, inode->i_ino, pg->index << PAGE_CACHE_SHIFT);
92 89
93 BUG_ON(!PageLocked(pg)); 90 BUG_ON(!PageLocked(pg));
94 91
@@ -108,7 +105,7 @@ static int jffs2_do_readpage_nolock (struct inode *inode, struct page *pg)
108 flush_dcache_page(pg); 105 flush_dcache_page(pg);
109 kunmap(pg); 106 kunmap(pg);
110 107
111 jffs2_dbg(2, "readpage finished\n"); 108 D2(printk(KERN_DEBUG "readpage finished\n"));
112 return ret; 109 return ret;
113} 110}
114 111
@@ -138,39 +135,33 @@ static int jffs2_write_begin(struct file *filp, struct address_space *mapping,
138 struct page *pg; 135 struct page *pg;
139 struct inode *inode = mapping->host; 136 struct inode *inode = mapping->host;
140 struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode); 137 struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
141 struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
142 struct jffs2_raw_inode ri;
143 uint32_t alloc_len = 0;
144 pgoff_t index = pos >> PAGE_CACHE_SHIFT; 138 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
145 uint32_t pageofs = index << PAGE_CACHE_SHIFT; 139 uint32_t pageofs = index << PAGE_CACHE_SHIFT;
146 int ret = 0; 140 int ret = 0;
147 141
148 jffs2_dbg(1, "%s()\n", __func__);
149
150 if (pageofs > inode->i_size) {
151 ret = jffs2_reserve_space(c, sizeof(ri), &alloc_len,
152 ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
153 if (ret)
154 return ret;
155 }
156
157 mutex_lock(&f->sem);
158 pg = grab_cache_page_write_begin(mapping, index, flags); 142 pg = grab_cache_page_write_begin(mapping, index, flags);
159 if (!pg) { 143 if (!pg)
160 if (alloc_len)
161 jffs2_complete_reservation(c);
162 mutex_unlock(&f->sem);
163 return -ENOMEM; 144 return -ENOMEM;
164 }
165 *pagep = pg; 145 *pagep = pg;
166 146
167 if (alloc_len) { 147 D1(printk(KERN_DEBUG "jffs2_write_begin()\n"));
148
149 if (pageofs > inode->i_size) {
168 /* Make new hole frag from old EOF to new page */ 150 /* Make new hole frag from old EOF to new page */
151 struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
152 struct jffs2_raw_inode ri;
169 struct jffs2_full_dnode *fn; 153 struct jffs2_full_dnode *fn;
154 uint32_t alloc_len;
170 155
171 jffs2_dbg(1, "Writing new hole frag 0x%x-0x%x between current EOF and new page\n", 156 D1(printk(KERN_DEBUG "Writing new hole frag 0x%x-0x%x between current EOF and new page\n",
172 (unsigned int)inode->i_size, pageofs); 157 (unsigned int)inode->i_size, pageofs));
158
159 ret = jffs2_reserve_space(c, sizeof(ri), &alloc_len,
160 ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
161 if (ret)
162 goto out_page;
173 163
164 mutex_lock(&f->sem);
174 memset(&ri, 0, sizeof(ri)); 165 memset(&ri, 0, sizeof(ri));
175 166
176 ri.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); 167 ri.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
@@ -181,8 +172,8 @@ static int jffs2_write_begin(struct file *filp, struct address_space *mapping,
181 ri.ino = cpu_to_je32(f->inocache->ino); 172 ri.ino = cpu_to_je32(f->inocache->ino);
182 ri.version = cpu_to_je32(++f->highest_version); 173 ri.version = cpu_to_je32(++f->highest_version);
183 ri.mode = cpu_to_jemode(inode->i_mode); 174 ri.mode = cpu_to_jemode(inode->i_mode);
184 ri.uid = cpu_to_je16(i_uid_read(inode)); 175 ri.uid = cpu_to_je16(inode->i_uid);
185 ri.gid = cpu_to_je16(i_gid_read(inode)); 176 ri.gid = cpu_to_je16(inode->i_gid);
186 ri.isize = cpu_to_je32(max((uint32_t)inode->i_size, pageofs)); 177 ri.isize = cpu_to_je32(max((uint32_t)inode->i_size, pageofs));
187 ri.atime = ri.ctime = ri.mtime = cpu_to_je32(get_seconds()); 178 ri.atime = ri.ctime = ri.mtime = cpu_to_je32(get_seconds());
188 ri.offset = cpu_to_je32(inode->i_size); 179 ri.offset = cpu_to_je32(inode->i_size);
@@ -197,6 +188,7 @@ static int jffs2_write_begin(struct file *filp, struct address_space *mapping,
197 if (IS_ERR(fn)) { 188 if (IS_ERR(fn)) {
198 ret = PTR_ERR(fn); 189 ret = PTR_ERR(fn);
199 jffs2_complete_reservation(c); 190 jffs2_complete_reservation(c);
191 mutex_unlock(&f->sem);
200 goto out_page; 192 goto out_page;
201 } 193 }
202 ret = jffs2_add_full_dnode_to_inode(c, f, fn); 194 ret = jffs2_add_full_dnode_to_inode(c, f, fn);
@@ -206,15 +198,16 @@ static int jffs2_write_begin(struct file *filp, struct address_space *mapping,
206 f->metadata = NULL; 198 f->metadata = NULL;
207 } 199 }
208 if (ret) { 200 if (ret) {
209 jffs2_dbg(1, "Eep. add_full_dnode_to_inode() failed in write_begin, returned %d\n", 201 D1(printk(KERN_DEBUG "Eep. add_full_dnode_to_inode() failed in write_begin, returned %d\n", ret));
210 ret);
211 jffs2_mark_node_obsolete(c, fn->raw); 202 jffs2_mark_node_obsolete(c, fn->raw);
212 jffs2_free_full_dnode(fn); 203 jffs2_free_full_dnode(fn);
213 jffs2_complete_reservation(c); 204 jffs2_complete_reservation(c);
205 mutex_unlock(&f->sem);
214 goto out_page; 206 goto out_page;
215 } 207 }
216 jffs2_complete_reservation(c); 208 jffs2_complete_reservation(c);
217 inode->i_size = pageofs; 209 inode->i_size = pageofs;
210 mutex_unlock(&f->sem);
218 } 211 }
219 212
220 /* 213 /*
@@ -223,18 +216,18 @@ static int jffs2_write_begin(struct file *filp, struct address_space *mapping,
223 * case of a short-copy. 216 * case of a short-copy.
224 */ 217 */
225 if (!PageUptodate(pg)) { 218 if (!PageUptodate(pg)) {
219 mutex_lock(&f->sem);
226 ret = jffs2_do_readpage_nolock(inode, pg); 220 ret = jffs2_do_readpage_nolock(inode, pg);
221 mutex_unlock(&f->sem);
227 if (ret) 222 if (ret)
228 goto out_page; 223 goto out_page;
229 } 224 }
230 mutex_unlock(&f->sem); 225 D1(printk(KERN_DEBUG "end write_begin(). pg->flags %lx\n", pg->flags));
231 jffs2_dbg(1, "end write_begin(). pg->flags %lx\n", pg->flags);
232 return ret; 226 return ret;
233 227
234out_page: 228out_page:
235 unlock_page(pg); 229 unlock_page(pg);
236 page_cache_release(pg); 230 page_cache_release(pg);
237 mutex_unlock(&f->sem);
238 return ret; 231 return ret;
239} 232}
240 233
@@ -255,9 +248,8 @@ static int jffs2_write_end(struct file *filp, struct address_space *mapping,
255 int ret = 0; 248 int ret = 0;
256 uint32_t writtenlen = 0; 249 uint32_t writtenlen = 0;
257 250
258 jffs2_dbg(1, "%s(): ino #%lu, page at 0x%lx, range %d-%d, flags %lx\n", 251 D1(printk(KERN_DEBUG "jffs2_write_end(): ino #%lu, page at 0x%lx, range %d-%d, flags %lx\n",
259 __func__, inode->i_ino, pg->index << PAGE_CACHE_SHIFT, 252 inode->i_ino, pg->index << PAGE_CACHE_SHIFT, start, end, pg->flags));
260 start, end, pg->flags);
261 253
262 /* We need to avoid deadlock with page_cache_read() in 254 /* We need to avoid deadlock with page_cache_read() in
263 jffs2_garbage_collect_pass(). So the page must be 255 jffs2_garbage_collect_pass(). So the page must be
@@ -276,8 +268,7 @@ static int jffs2_write_end(struct file *filp, struct address_space *mapping,
276 ri = jffs2_alloc_raw_inode(); 268 ri = jffs2_alloc_raw_inode();
277 269
278 if (!ri) { 270 if (!ri) {
279 jffs2_dbg(1, "%s(): Allocation of raw inode failed\n", 271 D1(printk(KERN_DEBUG "jffs2_write_end(): Allocation of raw inode failed\n"));
280 __func__);
281 unlock_page(pg); 272 unlock_page(pg);
282 page_cache_release(pg); 273 page_cache_release(pg);
283 return -ENOMEM; 274 return -ENOMEM;
@@ -286,8 +277,8 @@ static int jffs2_write_end(struct file *filp, struct address_space *mapping,
286 /* Set the fields that the generic jffs2_write_inode_range() code can't find */ 277 /* Set the fields that the generic jffs2_write_inode_range() code can't find */
287 ri->ino = cpu_to_je32(inode->i_ino); 278 ri->ino = cpu_to_je32(inode->i_ino);
288 ri->mode = cpu_to_jemode(inode->i_mode); 279 ri->mode = cpu_to_jemode(inode->i_mode);
289 ri->uid = cpu_to_je16(i_uid_read(inode)); 280 ri->uid = cpu_to_je16(inode->i_uid);
290 ri->gid = cpu_to_je16(i_gid_read(inode)); 281 ri->gid = cpu_to_je16(inode->i_gid);
291 ri->isize = cpu_to_je32((uint32_t)inode->i_size); 282 ri->isize = cpu_to_je32((uint32_t)inode->i_size);
292 ri->atime = ri->ctime = ri->mtime = cpu_to_je32(get_seconds()); 283 ri->atime = ri->ctime = ri->mtime = cpu_to_je32(get_seconds());
293 284
@@ -324,14 +315,13 @@ static int jffs2_write_end(struct file *filp, struct address_space *mapping,
324 /* generic_file_write has written more to the page cache than we've 315 /* generic_file_write has written more to the page cache than we've
325 actually written to the medium. Mark the page !Uptodate so that 316 actually written to the medium. Mark the page !Uptodate so that
326 it gets reread */ 317 it gets reread */
327 jffs2_dbg(1, "%s(): Not all bytes written. Marking page !uptodate\n", 318 D1(printk(KERN_DEBUG "jffs2_write_end(): Not all bytes written. Marking page !uptodate\n"));
328 __func__);
329 SetPageError(pg); 319 SetPageError(pg);
330 ClearPageUptodate(pg); 320 ClearPageUptodate(pg);
331 } 321 }
332 322
333 jffs2_dbg(1, "%s() returning %d\n", 323 D1(printk(KERN_DEBUG "jffs2_write_end() returning %d\n",
334 __func__, writtenlen > 0 ? writtenlen : ret); 324 writtenlen > 0 ? writtenlen : ret));
335 unlock_page(pg); 325 unlock_page(pg);
336 page_cache_release(pg); 326 page_cache_release(pg);
337 return writtenlen > 0 ? writtenlen : ret; 327 return writtenlen > 0 ? writtenlen : ret;