namei.c (e219aafe50fd546b8686582ddbafd24c3c2eda04) namei.c (fceef393a538134f03b778c5d2519e670269342f)
1/*
2 * fs/f2fs/namei.c
3 *
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as

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

310
311 if (IS_DIRSYNC(dir))
312 f2fs_sync_fs(sbi->sb, 1);
313fail:
314 trace_f2fs_unlink_exit(inode, err);
315 return err;
316}
317
1/*
2 * fs/f2fs/namei.c
3 *
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as

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

310
311 if (IS_DIRSYNC(dir))
312 f2fs_sync_fs(sbi->sb, 1);
313fail:
314 trace_f2fs_unlink_exit(inode, err);
315 return err;
316}
317
318static const char *f2fs_follow_link(struct dentry *dentry, void **cookie)
318static const char *f2fs_get_link(struct dentry *dentry,
319 struct inode *inode,
320 struct delayed_call *done)
319{
321{
320 const char *link = page_follow_link_light(dentry, cookie);
322 const char *link = page_get_link(dentry, inode, done);
321 if (!IS_ERR(link) && !*link) {
322 /* this is broken symlink case */
323 if (!IS_ERR(link) && !*link) {
324 /* this is broken symlink case */
323 page_put_link(NULL, *cookie);
325 do_delayed_call(done);
326 clear_delayed_call(done);
324 link = ERR_PTR(-ENOENT);
325 }
326 return link;
327}
328
329static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
330 const char *symname)
331{

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

346 inode = f2fs_new_inode(dir, S_IFLNK | S_IRWXUGO);
347 if (IS_ERR(inode))
348 return PTR_ERR(inode);
349
350 if (f2fs_encrypted_inode(inode))
351 inode->i_op = &f2fs_encrypted_symlink_inode_operations;
352 else
353 inode->i_op = &f2fs_symlink_inode_operations;
327 link = ERR_PTR(-ENOENT);
328 }
329 return link;
330}
331
332static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
333 const char *symname)
334{

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

349 inode = f2fs_new_inode(dir, S_IFLNK | S_IRWXUGO);
350 if (IS_ERR(inode))
351 return PTR_ERR(inode);
352
353 if (f2fs_encrypted_inode(inode))
354 inode->i_op = &f2fs_encrypted_symlink_inode_operations;
355 else
356 inode->i_op = &f2fs_symlink_inode_operations;
357 inode_nohighmem(inode);
354 inode->i_mapping->a_ops = &f2fs_dblock_aops;
355
356 f2fs_lock_op(sbi);
357 err = f2fs_add_link(dentry, inode);
358 if (err)
359 goto out;
360 f2fs_unlock_op(sbi);
361 alloc_nid_done(sbi, inode->i_ino);

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

918 /*
919 * VFS has already handled the new dentry existence case,
920 * here, we just deal with "RENAME_NOREPLACE" as regular rename.
921 */
922 return f2fs_rename(old_dir, old_dentry, new_dir, new_dentry, flags);
923}
924
925#ifdef CONFIG_F2FS_FS_ENCRYPTION
358 inode->i_mapping->a_ops = &f2fs_dblock_aops;
359
360 f2fs_lock_op(sbi);
361 err = f2fs_add_link(dentry, inode);
362 if (err)
363 goto out;
364 f2fs_unlock_op(sbi);
365 alloc_nid_done(sbi, inode->i_ino);

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

922 /*
923 * VFS has already handled the new dentry existence case,
924 * here, we just deal with "RENAME_NOREPLACE" as regular rename.
925 */
926 return f2fs_rename(old_dir, old_dentry, new_dir, new_dentry, flags);
927}
928
929#ifdef CONFIG_F2FS_FS_ENCRYPTION
926static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void **cookie)
930static const char *f2fs_encrypted_get_link(struct dentry *dentry,
931 struct inode *inode,
932 struct delayed_call *done)
927{
928 struct page *cpage = NULL;
929 char *caddr, *paddr = NULL;
930 struct f2fs_str cstr;
931 struct f2fs_str pstr = FSTR_INIT(NULL, 0);
933{
934 struct page *cpage = NULL;
935 char *caddr, *paddr = NULL;
936 struct f2fs_str cstr;
937 struct f2fs_str pstr = FSTR_INIT(NULL, 0);
932 struct inode *inode = d_inode(dentry);
933 struct f2fs_encrypted_symlink_data *sd;
934 loff_t size = min_t(loff_t, i_size_read(inode), PAGE_SIZE - 1);
935 u32 max_size = inode->i_sb->s_blocksize;
936 int res;
937
938 struct f2fs_encrypted_symlink_data *sd;
939 loff_t size = min_t(loff_t, i_size_read(inode), PAGE_SIZE - 1);
940 u32 max_size = inode->i_sb->s_blocksize;
941 int res;
942
943 if (!dentry)
944 return ERR_PTR(-ECHILD);
945
938 res = f2fs_get_encryption_info(inode);
939 if (res)
940 return ERR_PTR(res);
941
942 cpage = read_mapping_page(inode->i_mapping, 0, NULL);
943 if (IS_ERR(cpage))
944 return ERR_CAST(cpage);
946 res = f2fs_get_encryption_info(inode);
947 if (res)
948 return ERR_PTR(res);
949
950 cpage = read_mapping_page(inode->i_mapping, 0, NULL);
951 if (IS_ERR(cpage))
952 return ERR_CAST(cpage);
945 caddr = kmap(cpage);
953 caddr = page_address(cpage);
946 caddr[size] = 0;
947
948 /* Symlink is encrypted */
949 sd = (struct f2fs_encrypted_symlink_data *)caddr;
950 cstr.len = le16_to_cpu(sd->len);
951 cstr.name = kmalloc(cstr.len, GFP_NOFS);
952 if (!cstr.name) {
953 res = -ENOMEM;

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

977
978 kfree(cstr.name);
979
980 paddr = pstr.name;
981
982 /* Null-terminate the name */
983 paddr[res] = '\0';
984
954 caddr[size] = 0;
955
956 /* Symlink is encrypted */
957 sd = (struct f2fs_encrypted_symlink_data *)caddr;
958 cstr.len = le16_to_cpu(sd->len);
959 cstr.name = kmalloc(cstr.len, GFP_NOFS);
960 if (!cstr.name) {
961 res = -ENOMEM;

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

985
986 kfree(cstr.name);
987
988 paddr = pstr.name;
989
990 /* Null-terminate the name */
991 paddr[res] = '\0';
992
985 kunmap(cpage);
986 page_cache_release(cpage);
993 page_cache_release(cpage);
987 return *cookie = paddr;
994 set_delayed_call(done, kfree_link, paddr);
995 return paddr;
988errout:
989 kfree(cstr.name);
990 f2fs_fname_crypto_free_buffer(&pstr);
996errout:
997 kfree(cstr.name);
998 f2fs_fname_crypto_free_buffer(&pstr);
991 kunmap(cpage);
992 page_cache_release(cpage);
993 return ERR_PTR(res);
994}
995
996const struct inode_operations f2fs_encrypted_symlink_inode_operations = {
997 .readlink = generic_readlink,
999 page_cache_release(cpage);
1000 return ERR_PTR(res);
1001}
1002
1003const struct inode_operations f2fs_encrypted_symlink_inode_operations = {
1004 .readlink = generic_readlink,
998 .follow_link = f2fs_encrypted_follow_link,
999 .put_link = kfree_put_link,
1005 .get_link = f2fs_encrypted_get_link,
1000 .getattr = f2fs_getattr,
1001 .setattr = f2fs_setattr,
1002 .setxattr = generic_setxattr,
1003 .getxattr = generic_getxattr,
1004 .listxattr = f2fs_listxattr,
1005 .removexattr = generic_removexattr,
1006};
1007#endif

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

1026 .getxattr = generic_getxattr,
1027 .listxattr = f2fs_listxattr,
1028 .removexattr = generic_removexattr,
1029#endif
1030};
1031
1032const struct inode_operations f2fs_symlink_inode_operations = {
1033 .readlink = generic_readlink,
1006 .getattr = f2fs_getattr,
1007 .setattr = f2fs_setattr,
1008 .setxattr = generic_setxattr,
1009 .getxattr = generic_getxattr,
1010 .listxattr = f2fs_listxattr,
1011 .removexattr = generic_removexattr,
1012};
1013#endif

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

1032 .getxattr = generic_getxattr,
1033 .listxattr = f2fs_listxattr,
1034 .removexattr = generic_removexattr,
1035#endif
1036};
1037
1038const struct inode_operations f2fs_symlink_inode_operations = {
1039 .readlink = generic_readlink,
1034 .follow_link = f2fs_follow_link,
1035 .put_link = page_put_link,
1040 .get_link = f2fs_get_link,
1036 .getattr = f2fs_getattr,
1037 .setattr = f2fs_setattr,
1038#ifdef CONFIG_F2FS_FS_XATTR
1039 .setxattr = generic_setxattr,
1040 .getxattr = generic_getxattr,
1041 .listxattr = f2fs_listxattr,
1042 .removexattr = generic_removexattr,
1043#endif

--- 14 unchanged lines hidden ---
1041 .getattr = f2fs_getattr,
1042 .setattr = f2fs_setattr,
1043#ifdef CONFIG_F2FS_FS_XATTR
1044 .setxattr = generic_setxattr,
1045 .getxattr = generic_getxattr,
1046 .listxattr = f2fs_listxattr,
1047 .removexattr = generic_removexattr,
1048#endif

--- 14 unchanged lines hidden ---