Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2 | /* |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3 | * linux/fs/ext4/symlink.c |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 4 | * |
| 5 | * Only fast symlinks left here - the rest is done by generic code. AV, 1999 |
| 6 | * |
| 7 | * Copyright (C) 1992, 1993, 1994, 1995 |
| 8 | * Remy Card (card@masi.ibp.fr) |
| 9 | * Laboratoire MASI - Institut Blaise Pascal |
| 10 | * Universite Pierre et Marie Curie (Paris VI) |
| 11 | * |
| 12 | * from |
| 13 | * |
| 14 | * linux/fs/minix/symlink.c |
| 15 | * |
| 16 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 17 | * |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 18 | * ext4 symlink handling code |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include <linux/fs.h> |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 22 | #include <linux/namei.h> |
Christoph Hellwig | 3dcf545 | 2008-04-29 18:13:32 -0400 | [diff] [blame] | 23 | #include "ext4.h" |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 24 | #include "xattr.h" |
| 25 | |
Al Viro | 6b25539 | 2015-11-17 10:20:54 -0500 | [diff] [blame] | 26 | static const char *ext4_encrypted_get_link(struct dentry *dentry, |
Al Viro | fceef39 | 2015-12-29 15:58:39 -0500 | [diff] [blame] | 27 | struct inode *inode, |
| 28 | struct delayed_call *done) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 29 | { |
Theodore Ts'o | f348c25 | 2015-04-16 01:55:00 -0400 | [diff] [blame] | 30 | struct page *cpage = NULL; |
Eric Biggers | 6a9269c | 2018-01-11 22:10:40 -0500 | [diff] [blame^] | 31 | const void *caddr; |
| 32 | unsigned int max_size; |
| 33 | const char *paddr; |
Theodore Ts'o | f348c25 | 2015-04-16 01:55:00 -0400 | [diff] [blame] | 34 | |
Al Viro | 6b25539 | 2015-11-17 10:20:54 -0500 | [diff] [blame] | 35 | if (!dentry) |
| 36 | return ERR_PTR(-ECHILD); |
| 37 | |
Theodore Ts'o | f348c25 | 2015-04-16 01:55:00 -0400 | [diff] [blame] | 38 | if (ext4_inode_is_fast_symlink(inode)) { |
Eric Biggers | 6a9269c | 2018-01-11 22:10:40 -0500 | [diff] [blame^] | 39 | caddr = EXT4_I(inode)->i_data; |
Linus Torvalds | 9ec3a64 | 2015-04-26 15:48:49 -0700 | [diff] [blame] | 40 | max_size = sizeof(EXT4_I(inode)->i_data); |
Theodore Ts'o | f348c25 | 2015-04-16 01:55:00 -0400 | [diff] [blame] | 41 | } else { |
| 42 | cpage = read_mapping_page(inode->i_mapping, 0, NULL); |
Theodore Ts'o | b7236e2 | 2015-05-18 13:17:47 -0400 | [diff] [blame] | 43 | if (IS_ERR(cpage)) |
Al Viro | 680baac | 2015-05-02 13:32:22 -0400 | [diff] [blame] | 44 | return ERR_CAST(cpage); |
Al Viro | 21fc61c | 2015-11-17 01:07:57 -0500 | [diff] [blame] | 45 | caddr = page_address(cpage); |
Eric Biggers | 6a9269c | 2018-01-11 22:10:40 -0500 | [diff] [blame^] | 46 | max_size = inode->i_sb->s_blocksize; |
Theodore Ts'o | f348c25 | 2015-04-16 01:55:00 -0400 | [diff] [blame] | 47 | } |
| 48 | |
Eric Biggers | 6a9269c | 2018-01-11 22:10:40 -0500 | [diff] [blame^] | 49 | paddr = fscrypt_get_symlink(inode, caddr, max_size, done); |
Al Viro | 21fc61c | 2015-11-17 01:07:57 -0500 | [diff] [blame] | 50 | if (cpage) |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 51 | put_page(cpage); |
Al Viro | fceef39 | 2015-12-29 15:58:39 -0500 | [diff] [blame] | 52 | return paddr; |
Theodore Ts'o | f348c25 | 2015-04-16 01:55:00 -0400 | [diff] [blame] | 53 | } |
| 54 | |
Al Viro | a7a67e8 | 2015-04-27 17:51:30 -0400 | [diff] [blame] | 55 | const struct inode_operations ext4_encrypted_symlink_inode_operations = { |
Al Viro | 6b25539 | 2015-11-17 10:20:54 -0500 | [diff] [blame] | 56 | .get_link = ext4_encrypted_get_link, |
Al Viro | a7a67e8 | 2015-04-27 17:51:30 -0400 | [diff] [blame] | 57 | .setattr = ext4_setattr, |
David Howells | 99652ea | 2017-03-31 18:31:56 +0100 | [diff] [blame] | 58 | .getattr = ext4_getattr, |
Al Viro | a7a67e8 | 2015-04-27 17:51:30 -0400 | [diff] [blame] | 59 | .listxattr = ext4_listxattr, |
Al Viro | a7a67e8 | 2015-04-27 17:51:30 -0400 | [diff] [blame] | 60 | }; |
Theodore Ts'o | f348c25 | 2015-04-16 01:55:00 -0400 | [diff] [blame] | 61 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 62 | const struct inode_operations ext4_symlink_inode_operations = { |
Al Viro | 6b25539 | 2015-11-17 10:20:54 -0500 | [diff] [blame] | 63 | .get_link = page_get_link, |
Dmitry Monakhov | 256a453 | 2010-05-16 02:00:00 -0400 | [diff] [blame] | 64 | .setattr = ext4_setattr, |
David Howells | 99652ea | 2017-03-31 18:31:56 +0100 | [diff] [blame] | 65 | .getattr = ext4_getattr, |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 66 | .listxattr = ext4_listxattr, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 67 | }; |
| 68 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 69 | const struct inode_operations ext4_fast_symlink_inode_operations = { |
Al Viro | 6b25539 | 2015-11-17 10:20:54 -0500 | [diff] [blame] | 70 | .get_link = simple_get_link, |
Dmitry Monakhov | 256a453 | 2010-05-16 02:00:00 -0400 | [diff] [blame] | 71 | .setattr = ext4_setattr, |
David Howells | 99652ea | 2017-03-31 18:31:56 +0100 | [diff] [blame] | 72 | .getattr = ext4_getattr, |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 73 | .listxattr = ext4_listxattr, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 74 | }; |