blob: d4ce3af418a019986b41279b38e576b440c8768b [file] [log] [blame]
Dave Kleikampac27a0e2006-10-11 01:20:50 -07001/*
Mingming Cao617ba132006-10-11 01:20:53 -07002 * linux/fs/ext4/symlink.c
Dave Kleikampac27a0e2006-10-11 01:20:50 -07003 *
4 * Only fast symlinks left here - the rest is done by generic code. AV, 1999
5 *
6 * Copyright (C) 1992, 1993, 1994, 1995
7 * Remy Card (card@masi.ibp.fr)
8 * Laboratoire MASI - Institut Blaise Pascal
9 * Universite Pierre et Marie Curie (Paris VI)
10 *
11 * from
12 *
13 * linux/fs/minix/symlink.c
14 *
15 * Copyright (C) 1991, 1992 Linus Torvalds
16 *
Mingming Cao617ba132006-10-11 01:20:53 -070017 * ext4 symlink handling code
Dave Kleikampac27a0e2006-10-11 01:20:50 -070018 */
19
20#include <linux/fs.h>
Dave Kleikampac27a0e2006-10-11 01:20:50 -070021#include <linux/namei.h>
Christoph Hellwig3dcf5452008-04-29 18:13:32 -040022#include "ext4.h"
Dave Kleikampac27a0e2006-10-11 01:20:50 -070023#include "xattr.h"
24
Al Viro6b255392015-11-17 10:20:54 -050025static const char *ext4_encrypted_get_link(struct dentry *dentry,
Al Virofceef392015-12-29 15:58:39 -050026 struct inode *inode,
27 struct delayed_call *done)
Dave Kleikampac27a0e2006-10-11 01:20:50 -070028{
Theodore Ts'of348c252015-04-16 01:55:00 -040029 struct page *cpage = NULL;
Jaegeuk Kimd9197652018-01-05 10:44:52 -080030 const void *caddr;
31 unsigned int max_size;
32 const char *paddr;
Theodore Ts'of348c252015-04-16 01:55:00 -040033
Al Viro6b255392015-11-17 10:20:54 -050034 if (!dentry)
35 return ERR_PTR(-ECHILD);
36
Theodore Ts'of348c252015-04-16 01:55:00 -040037 if (ext4_inode_is_fast_symlink(inode)) {
Jaegeuk Kimd9197652018-01-05 10:44:52 -080038 caddr = EXT4_I(inode)->i_data;
Linus Torvalds9ec3a642015-04-26 15:48:49 -070039 max_size = sizeof(EXT4_I(inode)->i_data);
Theodore Ts'of348c252015-04-16 01:55:00 -040040 } else {
41 cpage = read_mapping_page(inode->i_mapping, 0, NULL);
Theodore Ts'ob7236e22015-05-18 13:17:47 -040042 if (IS_ERR(cpage))
Al Viro680baac2015-05-02 13:32:22 -040043 return ERR_CAST(cpage);
Al Viro21fc61c2015-11-17 01:07:57 -050044 caddr = page_address(cpage);
Jaegeuk Kimd9197652018-01-05 10:44:52 -080045 max_size = inode->i_sb->s_blocksize;
Theodore Ts'of348c252015-04-16 01:55:00 -040046 }
47
Jaegeuk Kimd9197652018-01-05 10:44:52 -080048 paddr = fscrypt_get_symlink(inode, caddr, max_size, done);
Al Viro21fc61c2015-11-17 01:07:57 -050049 if (cpage)
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +030050 put_page(cpage);
Al Virofceef392015-12-29 15:58:39 -050051 return paddr;
Theodore Ts'of348c252015-04-16 01:55:00 -040052}
53
Al Viroa7a67e82015-04-27 17:51:30 -040054const struct inode_operations ext4_encrypted_symlink_inode_operations = {
55 .readlink = generic_readlink,
Al Viro6b255392015-11-17 10:20:54 -050056 .get_link = ext4_encrypted_get_link,
Al Viroa7a67e82015-04-27 17:51:30 -040057 .setattr = ext4_setattr,
Al Viroa7a67e82015-04-27 17:51:30 -040058 .listxattr = ext4_listxattr,
Al Viroa7a67e82015-04-27 17:51:30 -040059};
Theodore Ts'of348c252015-04-16 01:55:00 -040060
Arjan van de Ven754661f2007-02-12 00:55:38 -080061const struct inode_operations ext4_symlink_inode_operations = {
Dave Kleikampac27a0e2006-10-11 01:20:50 -070062 .readlink = generic_readlink,
Al Viro6b255392015-11-17 10:20:54 -050063 .get_link = page_get_link,
Dmitry Monakhov256a4532010-05-16 02:00:00 -040064 .setattr = ext4_setattr,
Mingming Cao617ba132006-10-11 01:20:53 -070065 .listxattr = ext4_listxattr,
Dave Kleikampac27a0e2006-10-11 01:20:50 -070066};
67
Arjan van de Ven754661f2007-02-12 00:55:38 -080068const struct inode_operations ext4_fast_symlink_inode_operations = {
Dave Kleikampac27a0e2006-10-11 01:20:50 -070069 .readlink = generic_readlink,
Al Viro6b255392015-11-17 10:20:54 -050070 .get_link = simple_get_link,
Dmitry Monakhov256a4532010-05-16 02:00:00 -040071 .setattr = ext4_setattr,
Mingming Cao617ba132006-10-11 01:20:53 -070072 .listxattr = ext4_listxattr,
Dave Kleikampac27a0e2006-10-11 01:20:50 -070073};