generic-2.6: add yaffs fs fixes for 2.6.28
[openwrt/staging/chunkeey.git] / target / linux / generic-2.6 / patches-2.6.28 / 514-yaffs_2.6.28_fixes.patch
1 --- a/fs/yaffs2/yaffs_fs.c
2 +++ b/fs/yaffs2/yaffs_fs.c
3 @@ -207,10 +207,20 @@ static int yaffs_writepage(struct page *
4 #else
5 static int yaffs_writepage(struct page *page);
6 #endif
7 +
8 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28))
9 +static int yaffs_write_begin(struct file *f, struct address_space *mapping,
10 + loff_t pos, unsigned len, unsigned flags,
11 + struct page **pagep, void **fsdata);
12 +static int yaffs_write_end(struct file *f, struct address_space *mapping,
13 + loff_t pos, unsigned len, unsigned copied,
14 + struct page *pg, void *fsdata);
15 +#else
16 static int yaffs_prepare_write(struct file *f, struct page *pg,
17 unsigned offset, unsigned to);
18 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset,
19 unsigned to);
20 +#endif
21
22 static int yaffs_readlink(struct dentry *dentry, char __user * buffer,
23 int buflen);
24 @@ -223,8 +233,13 @@ static int yaffs_follow_link(struct dent
25 static struct address_space_operations yaffs_file_address_operations = {
26 .readpage = yaffs_readpage,
27 .writepage = yaffs_writepage,
28 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28))
29 + .write_begin = yaffs_write_begin,
30 + .write_end = yaffs_write_end,
31 +#else
32 .prepare_write = yaffs_prepare_write,
33 .commit_write = yaffs_commit_write,
34 +#endif
35 };
36
37 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,22))
38 @@ -687,6 +702,74 @@ static int yaffs_writepage(struct page *
39 return (nWritten == nBytes) ? 0 : -ENOSPC;
40 }
41
42 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28))
43 +static int yaffs_write_begin(struct file *f, struct address_space *mapping,
44 + loff_t pos, unsigned len, unsigned flags,
45 + struct page **pagep, void **fsdata)
46 +{
47 + struct page *pg;
48 + pgoff_t index = pos >> PAGE_CACHE_SHIFT;
49 + int ret = 0;
50 +
51 + pg = __grab_cache_page(mapping, index);
52 + if (!pg)
53 + return -ENOMEM;
54 +
55 + *pagep = pg;
56 +
57 + T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_write_begin\n"));
58 + if (!Page_Uptodate(pg)) {
59 + ret = yaffs_readpage_nolock(f, pg);
60 + if (ret)
61 + goto err_unlock;
62 + }
63 +
64 + T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_write_begin\n"));
65 + return 0;
66 +
67 + err_unlock:
68 + unlock_page(pg);
69 + page_cache_release(pg);
70 + return ret;
71 +}
72 +
73 +static int yaffs_write_end(struct file *f, struct address_space *mapping,
74 + loff_t pos, unsigned len, unsigned copied,
75 + struct page *pg, void *fsdata)
76 +{
77 + void *addr = page_address(pg) + (pos & (PAGE_CACHE_SIZE - 1));
78 + loff_t pos2;
79 + int nBytes = copied;
80 + int nWritten;
81 +
82 + T(YAFFS_TRACE_OS,
83 + (KERN_DEBUG "yaffs_write_end addr %x pos %x nBytes %d\n", (unsigned)addr,
84 + (unsigned)pos, nBytes));
85 +
86 + pos2 = pos;
87 + nWritten = yaffs_file_write(f, addr, nBytes, &pos2);
88 +
89 + if (nWritten != nBytes) {
90 + T(YAFFS_TRACE_OS,
91 + (KERN_DEBUG
92 + "yaffs_write_end not same size nWritten %d nBytes %d\n",
93 + nWritten, nBytes));
94 + SetPageError(pg);
95 + ClearPageUptodate(pg);
96 + } else {
97 + SetPageUptodate(pg);
98 + }
99 +
100 + T(YAFFS_TRACE_OS,
101 + (KERN_DEBUG "yaffs_write_end returning %d\n",
102 + nWritten == nBytes ? nWritten : 0));
103 +
104 + unlock_page(pg);
105 + page_cache_release(pg);
106 +
107 + return (nWritten == nBytes) ? nWritten : 0;
108 +}
109 +#else
110 static int yaffs_prepare_write(struct file *f, struct page *pg,
111 unsigned offset, unsigned to)
112 {
113 @@ -735,6 +818,7 @@ static int yaffs_commit_write(struct fil
114 return nWritten == nBytes ? 0 : nWritten;
115
116 }
117 +#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)) */
118
119 static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object * obj)
120 {