file.c (4fc67fbe52d7c34dfd3e03a1a79f3e078904bba2) file.c (182ec4eee397543101a6db8906ed88727d3f7e53)
1/*
2 * JFFS2 -- Journalling Flash File System, Version 2.
3 *
4 * Copyright (C) 2001-2003 Red Hat, Inc.
5 *
6 * Created by David Woodhouse <dwmw2@infradead.org>
7 *
8 * For licensing information, see the file 'LICENCE' in this directory.

--- 20 unchanged lines hidden (view full) ---

29
30int jffs2_fsync(struct file *filp, struct dentry *dentry, int datasync)
31{
32 struct inode *inode = dentry->d_inode;
33 struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
34
35 /* Trigger GC to flush any pending writes for this inode */
36 jffs2_flush_wbuf_gc(c, inode->i_ino);
1/*
2 * JFFS2 -- Journalling Flash File System, Version 2.
3 *
4 * Copyright (C) 2001-2003 Red Hat, Inc.
5 *
6 * Created by David Woodhouse <dwmw2@infradead.org>
7 *
8 * For licensing information, see the file 'LICENCE' in this directory.

--- 20 unchanged lines hidden (view full) ---

29
30int jffs2_fsync(struct file *filp, struct dentry *dentry, int datasync)
31{
32 struct inode *inode = dentry->d_inode;
33 struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
34
35 /* Trigger GC to flush any pending writes for this inode */
36 jffs2_flush_wbuf_gc(c, inode->i_ino);
37
38 return 0;
37
38 return 0;
39}
40
41struct file_operations jffs2_file_operations =
42{
43 .llseek = generic_file_llseek,
44 .open = generic_file_open,
45 .read = generic_file_read,
46 .write = generic_file_write,

--- 55 unchanged lines hidden (view full) ---

102 return ret;
103}
104
105
106static int jffs2_readpage (struct file *filp, struct page *pg)
107{
108 struct jffs2_inode_info *f = JFFS2_INODE_INFO(pg->mapping->host);
109 int ret;
39}
40
41struct file_operations jffs2_file_operations =
42{
43 .llseek = generic_file_llseek,
44 .open = generic_file_open,
45 .read = generic_file_read,
46 .write = generic_file_write,

--- 55 unchanged lines hidden (view full) ---

102 return ret;
103}
104
105
106static int jffs2_readpage (struct file *filp, struct page *pg)
107{
108 struct jffs2_inode_info *f = JFFS2_INODE_INFO(pg->mapping->host);
109 int ret;
110
110
111 down(&f->sem);
112 ret = jffs2_do_readpage_unlock(pg->mapping->host, pg);
113 up(&f->sem);
114 return ret;
115}
116
117static int jffs2_prepare_write (struct file *filp, struct page *pg,
118 unsigned start, unsigned end)

--- 6 unchanged lines hidden (view full) ---

125 D1(printk(KERN_DEBUG "jffs2_prepare_write()\n"));
126
127 if (pageofs > inode->i_size) {
128 /* Make new hole frag from old EOF to new page */
129 struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
130 struct jffs2_raw_inode ri;
131 struct jffs2_full_dnode *fn;
132 uint32_t phys_ofs, alloc_len;
111 down(&f->sem);
112 ret = jffs2_do_readpage_unlock(pg->mapping->host, pg);
113 up(&f->sem);
114 return ret;
115}
116
117static int jffs2_prepare_write (struct file *filp, struct page *pg,
118 unsigned start, unsigned end)

--- 6 unchanged lines hidden (view full) ---

125 D1(printk(KERN_DEBUG "jffs2_prepare_write()\n"));
126
127 if (pageofs > inode->i_size) {
128 /* Make new hole frag from old EOF to new page */
129 struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
130 struct jffs2_raw_inode ri;
131 struct jffs2_full_dnode *fn;
132 uint32_t phys_ofs, alloc_len;
133
133
134 D1(printk(KERN_DEBUG "Writing new hole frag 0x%x-0x%x between current EOF and new page\n",
135 (unsigned int)inode->i_size, pageofs));
136
137 ret = jffs2_reserve_space(c, sizeof(ri), &phys_ofs, &alloc_len,
138 ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
139 if (ret)
140 return ret;
141

--- 13 unchanged lines hidden (view full) ---

155 ri.isize = cpu_to_je32(max((uint32_t)inode->i_size, pageofs));
156 ri.atime = ri.ctime = ri.mtime = cpu_to_je32(get_seconds());
157 ri.offset = cpu_to_je32(inode->i_size);
158 ri.dsize = cpu_to_je32(pageofs - inode->i_size);
159 ri.csize = cpu_to_je32(0);
160 ri.compr = JFFS2_COMPR_ZERO;
161 ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8));
162 ri.data_crc = cpu_to_je32(0);
134 D1(printk(KERN_DEBUG "Writing new hole frag 0x%x-0x%x between current EOF and new page\n",
135 (unsigned int)inode->i_size, pageofs));
136
137 ret = jffs2_reserve_space(c, sizeof(ri), &phys_ofs, &alloc_len,
138 ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
139 if (ret)
140 return ret;
141

--- 13 unchanged lines hidden (view full) ---

155 ri.isize = cpu_to_je32(max((uint32_t)inode->i_size, pageofs));
156 ri.atime = ri.ctime = ri.mtime = cpu_to_je32(get_seconds());
157 ri.offset = cpu_to_je32(inode->i_size);
158 ri.dsize = cpu_to_je32(pageofs - inode->i_size);
159 ri.csize = cpu_to_je32(0);
160 ri.compr = JFFS2_COMPR_ZERO;
161 ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8));
162 ri.data_crc = cpu_to_je32(0);
163
163
164 fn = jffs2_write_dnode(c, f, &ri, NULL, 0, phys_ofs, ALLOC_NORMAL);
165
166 if (IS_ERR(fn)) {
167 ret = PTR_ERR(fn);
168 jffs2_complete_reservation(c);
169 up(&f->sem);
170 return ret;
171 }

--- 10 unchanged lines hidden (view full) ---

182 jffs2_complete_reservation(c);
183 up(&f->sem);
184 return ret;
185 }
186 jffs2_complete_reservation(c);
187 inode->i_size = pageofs;
188 up(&f->sem);
189 }
164 fn = jffs2_write_dnode(c, f, &ri, NULL, 0, phys_ofs, ALLOC_NORMAL);
165
166 if (IS_ERR(fn)) {
167 ret = PTR_ERR(fn);
168 jffs2_complete_reservation(c);
169 up(&f->sem);
170 return ret;
171 }

--- 10 unchanged lines hidden (view full) ---

182 jffs2_complete_reservation(c);
183 up(&f->sem);
184 return ret;
185 }
186 jffs2_complete_reservation(c);
187 inode->i_size = pageofs;
188 up(&f->sem);
189 }
190
190
191 /* Read in the page if it wasn't already present, unless it's a whole page */
192 if (!PageUptodate(pg) && (start || end < PAGE_CACHE_SIZE)) {
193 down(&f->sem);
194 ret = jffs2_do_readpage_nolock(inode, pg);
195 up(&f->sem);
196 }
197 D1(printk(KERN_DEBUG "end prepare_write(). pg->flags %lx\n", pg->flags));
198 return ret;

--- 14 unchanged lines hidden (view full) ---

213 uint32_t writtenlen = 0;
214
215 D1(printk(KERN_DEBUG "jffs2_commit_write(): ino #%lu, page at 0x%lx, range %d-%d, flags %lx\n",
216 inode->i_ino, pg->index << PAGE_CACHE_SHIFT, start, end, pg->flags));
217
218 if (!start && end == PAGE_CACHE_SIZE) {
219 /* We need to avoid deadlock with page_cache_read() in
220 jffs2_garbage_collect_pass(). So we have to mark the
191 /* Read in the page if it wasn't already present, unless it's a whole page */
192 if (!PageUptodate(pg) && (start || end < PAGE_CACHE_SIZE)) {
193 down(&f->sem);
194 ret = jffs2_do_readpage_nolock(inode, pg);
195 up(&f->sem);
196 }
197 D1(printk(KERN_DEBUG "end prepare_write(). pg->flags %lx\n", pg->flags));
198 return ret;

--- 14 unchanged lines hidden (view full) ---

213 uint32_t writtenlen = 0;
214
215 D1(printk(KERN_DEBUG "jffs2_commit_write(): ino #%lu, page at 0x%lx, range %d-%d, flags %lx\n",
216 inode->i_ino, pg->index << PAGE_CACHE_SHIFT, start, end, pg->flags));
217
218 if (!start && end == PAGE_CACHE_SIZE) {
219 /* We need to avoid deadlock with page_cache_read() in
220 jffs2_garbage_collect_pass(). So we have to mark the
221 page up to date, to prevent page_cache_read() from
221 page up to date, to prevent page_cache_read() from
222 trying to re-lock it. */
223 SetPageUptodate(pg);
224 }
225
226 ri = jffs2_alloc_raw_inode();
227
228 if (!ri) {
229 D1(printk(KERN_DEBUG "jffs2_commit_write(): Allocation of raw inode failed\n"));

--- 17 unchanged lines hidden (view full) ---

247 end - aligned_start, &writtenlen);
248
249 kunmap(pg);
250
251 if (ret) {
252 /* There was an error writing. */
253 SetPageError(pg);
254 }
222 trying to re-lock it. */
223 SetPageUptodate(pg);
224 }
225
226 ri = jffs2_alloc_raw_inode();
227
228 if (!ri) {
229 D1(printk(KERN_DEBUG "jffs2_commit_write(): Allocation of raw inode failed\n"));

--- 17 unchanged lines hidden (view full) ---

247 end - aligned_start, &writtenlen);
248
249 kunmap(pg);
250
251 if (ret) {
252 /* There was an error writing. */
253 SetPageError(pg);
254 }
255
255
256 /* Adjust writtenlen for the padding we did, so we don't confuse our caller */
257 if (writtenlen < (start&3))
258 writtenlen = 0;
259 else
260 writtenlen -= (start&3);
261
262 if (writtenlen) {
263 if (inode->i_size < (pg->index << PAGE_CACHE_SHIFT) + start + writtenlen) {
264 inode->i_size = (pg->index << PAGE_CACHE_SHIFT) + start + writtenlen;
265 inode->i_blocks = (inode->i_size + 511) >> 9;
256 /* Adjust writtenlen for the padding we did, so we don't confuse our caller */
257 if (writtenlen < (start&3))
258 writtenlen = 0;
259 else
260 writtenlen -= (start&3);
261
262 if (writtenlen) {
263 if (inode->i_size < (pg->index << PAGE_CACHE_SHIFT) + start + writtenlen) {
264 inode->i_size = (pg->index << PAGE_CACHE_SHIFT) + start + writtenlen;
265 inode->i_blocks = (inode->i_size + 511) >> 9;
266
266
267 inode->i_ctime = inode->i_mtime = ITIME(je32_to_cpu(ri->ctime));
268 }
269 }
270
271 jffs2_free_raw_inode(ri);
272
273 if (start+writtenlen < end) {
274 /* generic_file_write has written more to the page cache than we've
267 inode->i_ctime = inode->i_mtime = ITIME(je32_to_cpu(ri->ctime));
268 }
269 }
270
271 jffs2_free_raw_inode(ri);
272
273 if (start+writtenlen < end) {
274 /* generic_file_write has written more to the page cache than we've
275 actually written to the medium. Mark the page !Uptodate so that
275 actually written to the medium. Mark the page !Uptodate so that
276 it gets reread */
277 D1(printk(KERN_DEBUG "jffs2_commit_write(): Not all bytes written. Marking page !uptodate\n"));
278 SetPageError(pg);
279 ClearPageUptodate(pg);
280 }
281
282 D1(printk(KERN_DEBUG "jffs2_commit_write() returning %d\n",start+writtenlen==end?0:ret));
283 return start+writtenlen==end?0:ret;
284}
276 it gets reread */
277 D1(printk(KERN_DEBUG "jffs2_commit_write(): Not all bytes written. Marking page !uptodate\n"));
278 SetPageError(pg);
279 ClearPageUptodate(pg);
280 }
281
282 D1(printk(KERN_DEBUG "jffs2_commit_write() returning %d\n",start+writtenlen==end?0:ret));
283 return start+writtenlen==end?0:ret;
284}