Re: [Yaffs] Kenrel 2.6.28-rc8 removes prepare_write/commit_w…

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Marcel Ziswiler
Date:  
To: yaffs
Subject: Re: [Yaffs] Kenrel 2.6.28-rc8 removes prepare_write/commit_write...
Peter Barada <peterb <at> logicpd.com> writes:
> Does anyone have a patch to get the latest CVS YAFFS to work with 2.6.28-rc8?


Sure, how about something like that?

diff -Naur yaffs2.orig/yaffs_fs.c yaffs2/yaffs_fs.c
--- yaffs2.orig/yaffs_fs.c    2009-01-18 22:50:37.000000000 +0100
+++ yaffs2/yaffs_fs.c    2009-01-19 22:17:52.000000000 +0100
@@ -218,10 +218,19 @@
 #else
 static int yaffs_writepage(struct page *page);
 #endif
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27))
+static int yaffs_write_begin(struct file *f, struct address_space *mapping,
+                 loff_t pos, unsigned len, unsigned flags,
+                 struct page **pagep, void **fsdata);
+static int yaffs_write_end(struct file *f, struct address_space *mapping,
+               loff_t pos, unsigned len, unsigned copied,
+               struct page *pg, void *fsdata);
+#else
 static int yaffs_prepare_write(struct file *f, struct page *pg,
                    unsigned offset, unsigned to);
 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset,
                   unsigned to);
+#endif


 static int yaffs_readlink(struct dentry *dentry, char __user * buffer,
               int buflen);
@@ -234,8 +243,13 @@
 static struct address_space_operations yaffs_file_address_operations = {
     .readpage = yaffs_readpage,
     .writepage = yaffs_writepage,
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27))
+    .write_begin = yaffs_write_begin,
+    .write_end = yaffs_write_end,
+#else
     .prepare_write = yaffs_prepare_write,
     .commit_write = yaffs_commit_write,
+#endif
 };


 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,22))
@@ -701,32 +715,67 @@
     return (nWritten == nBytes) ? 0 : -ENOSPC;
 }


+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27))
+static int yaffs_write_begin(struct file *f, struct address_space *mapping,
+                 loff_t pos, unsigned len, unsigned flags,
+                 struct page **pagep, void **fsdata)
+{
+    struct page *pg;
+    pgoff_t index = pos >> PAGE_CACHE_SHIFT;
+    uint32_t offset = pos & (PAGE_CACHE_SIZE - 1);
+    uint32_t to = offset + len;
+#else
 static int yaffs_prepare_write(struct file *f, struct page *pg,
                    unsigned offset, unsigned to)
 {
+#endif
+    int ret = 0;


     T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_prepair_write\n"));
-    if (!Page_Uptodate(pg) && (offset || to < PAGE_CACHE_SIZE))
-        return yaffs_readpage_nolock(f, pg);
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27))
+    pg = __grab_cache_page(mapping, index);
+    if (!pg)
+        return -ENOMEM;
+    *pagep = pg;
+#endif


-    return 0;
+    if (!Page_Uptodate(pg) && (offset || to < PAGE_CACHE_SIZE)) {
+        ret = yaffs_readpage_nolock(f, pg);
+    }
+
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27))
+    if (ret) {
+        unlock_page(pg);
+        page_cache_release(pg);
+    }
+#endif


+    return ret;
 }


+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27))
+static int yaffs_write_end(struct file *f, struct address_space *mapping,
+               loff_t pos, unsigned len, unsigned copied,
+               struct page *pg, void *fsdata)
+{
+    unsigned offset = pos & (PAGE_CACHE_SIZE - 1);
+    unsigned to = offset + copied;
+#else
 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset,
                   unsigned to)
 {
-
+#endif
     void *addr, *kva;
-    
+#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,27))
     loff_t pos = (((loff_t) pg->index) << PAGE_CACHE_SHIFT) + offset;
+#endif
     int nBytes = to - offset;
     int nWritten;


     unsigned spos = pos;
     unsigned saddr = (unsigned)addr;

    
-    kva=kmap(pg);
+    kva = kmap(pg);
     addr = kva + offset;


     T(YAFFS_TRACE_OS,
@@ -752,8 +801,12 @@
       (KERN_DEBUG "yaffs_commit_write returning %d\n",
        nWritten == nBytes ? 0 : nWritten));


-    return nWritten == nBytes ? 0 : nWritten;
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27))
+    unlock_page(pg);
+    page_cache_release(pg);
+#endif


+    return nWritten == nBytes ? 0 : nWritten;
 }


static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object * obj)