Merge tag 'v3.10.103' into update
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / fs / ubifs / file.c
index 14374530784c683f36a15e52b64d792578a8ec07..4a624c01a2e2ea6f9a4e65c2fc3d934b5ae8b10d 100644 (file)
@@ -54,6 +54,7 @@
 #include <linux/mount.h>
 #include <linux/namei.h>
 #include <linux/slab.h>
+#include <linux/migrate.h>
 
 static int read_block(struct inode *inode, void *addr, unsigned int block,
                      struct ubifs_data_node *dn)
@@ -79,6 +80,10 @@ static int read_block(struct inode *inode, void *addr, unsigned int block,
                goto dump;
 
        dlen = le32_to_cpu(dn->ch.len) - UBIFS_DATA_NODE_SZ;
+
+       if (UBIFS_COMPR_LZ4K ==  le16_to_cpu(dn->compr_type))
+         out_len = len; //Jack modify for lz4k decompress      
+       else
        out_len = UBIFS_BLOCK_SIZE;
        err = ubifs_decompress(&dn->data, dlen, addr, &out_len,
                               le16_to_cpu(dn->compr_type));
@@ -648,6 +653,10 @@ static int populate_page(struct ubifs_info *c, struct page *page,
                                goto out_err;
 
                        dlen = le32_to_cpu(dn->ch.len) - UBIFS_DATA_NODE_SZ;
+                       
+                       if (UBIFS_COMPR_LZ4K ==  le16_to_cpu(dn->compr_type))                           
+                         out_len = len; //Jack modify for lz4k decompress      
+                       else
                        out_len = UBIFS_BLOCK_SIZE;
                        err = ubifs_decompress(&dn->data, dlen, addr, &out_len,
                                               le16_to_cpu(dn->compr_type));
@@ -1422,6 +1431,26 @@ static int ubifs_set_page_dirty(struct page *page)
        return ret;
 }
 
+#ifdef CONFIG_MIGRATION
+static int ubifs_migrate_page(struct address_space *mapping,
+               struct page *newpage, struct page *page, enum migrate_mode mode)
+{
+       int rc;
+
+       rc = migrate_page_move_mapping(mapping, newpage, page, NULL, mode);
+       if (rc != MIGRATEPAGE_SUCCESS)
+               return rc;
+
+       if (PagePrivate(page)) {
+               ClearPagePrivate(page);
+               SetPagePrivate(newpage);
+       }
+
+       migrate_page_copy(newpage, page);
+       return MIGRATEPAGE_SUCCESS;
+}
+#endif
+
 static int ubifs_releasepage(struct page *page, gfp_t unused_gfp_flags)
 {
        /*
@@ -1524,8 +1553,7 @@ static int ubifs_vm_page_mkwrite(struct vm_area_struct *vma,
        }
 
        wait_for_stable_page(page);
-       unlock_page(page);
-       return 0;
+       return VM_FAULT_LOCKED;
 
 out_unlock:
        unlock_page(page);
@@ -1552,6 +1580,31 @@ static int ubifs_file_mmap(struct file *file, struct vm_area_struct *vma)
        return 0;
 }
 
+//MTK add for cts
+long ubifs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
+{
+       int err;
+       struct inode *inode = file->f_mapping->host;
+       struct ubifs_info *c = inode->i_sb->s_fs_info;
+       struct iattr newattrs;
+
+       loff_t new_len = offset + len;
+       if (len < 0 || offset < 0)
+               return -EINVAL;
+
+       if(new_len < inode->i_size)
+               return -EINVAL;
+       
+       newattrs.ia_size = new_len;
+        newattrs.ia_valid = ATTR_SIZE | ATTR_MTIME|ATTR_CTIME;
+       newattrs.ia_file = file;
+       newattrs.ia_valid |= ATTR_FILE;
+
+       
+       err = do_setattr(c, inode, &newattrs);
+       return err;
+}
+
 const struct address_space_operations ubifs_file_address_operations = {
        .readpage       = ubifs_readpage,
        .writepage      = ubifs_writepage,
@@ -1559,6 +1612,9 @@ const struct address_space_operations ubifs_file_address_operations = {
        .write_end      = ubifs_write_end,
        .invalidatepage = ubifs_invalidatepage,
        .set_page_dirty = ubifs_set_page_dirty,
+#ifdef CONFIG_MIGRATION
+       .migratepage    = ubifs_migrate_page,
+#endif
        .releasepage    = ubifs_releasepage,
 };
 
@@ -1576,6 +1632,10 @@ const struct inode_operations ubifs_symlink_inode_operations = {
        .follow_link = ubifs_follow_link,
        .setattr     = ubifs_setattr,
        .getattr     = ubifs_getattr,
+       .setxattr    = ubifs_setxattr,
+       .getxattr    = ubifs_getxattr,
+       .listxattr   = ubifs_listxattr,
+       .removexattr = ubifs_removexattr,
 };
 
 const struct file_operations ubifs_file_operations = {
@@ -1592,4 +1652,5 @@ const struct file_operations ubifs_file_operations = {
 #ifdef CONFIG_COMPAT
        .compat_ioctl   = ubifs_compat_ioctl,
 #endif
+        .fallocate      = ubifs_fallocate,
 };