Masahiro Yamada | fa60ce2 | 2021-05-06 18:06:44 -0700 | [diff] [blame] | 1 | /* |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2 | * linux/cluster/ssi/cfs/symlink.c |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License as |
| 6 | * published by the Free Software Foundation; either version 2 of |
| 7 | * the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE |
| 12 | * or NON INFRINGEMENT. See the GNU General Public License for more |
| 13 | * details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 18 | * |
| 19 | * Questions/Comments/Bugfixes to ssic-linux-devel@lists.sourceforge.net |
| 20 | * |
| 21 | * Copyright (C) 1992 Rick Sladkey |
| 22 | * |
| 23 | * Optimization changes Copyright (C) 1994 Florian La Roche |
| 24 | * |
| 25 | * Jun 7 1999, cache symlink lookups in the page cache. -DaveM |
| 26 | * |
| 27 | * Portions Copyright (C) 2001 Compaq Computer Corporation |
| 28 | * |
| 29 | * ocfs2 symlink handling code. |
| 30 | * |
| 31 | * Copyright (C) 2004, 2005 Oracle. |
| 32 | * |
| 33 | */ |
| 34 | |
| 35 | #include <linux/fs.h> |
| 36 | #include <linux/types.h> |
| 37 | #include <linux/slab.h> |
| 38 | #include <linux/pagemap.h> |
Joel Becker | a731d12 | 2009-04-06 16:43:42 -0700 | [diff] [blame] | 39 | #include <linux/namei.h> |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 40 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 41 | #include <cluster/masklog.h> |
| 42 | |
| 43 | #include "ocfs2.h" |
| 44 | |
| 45 | #include "alloc.h" |
| 46 | #include "file.h" |
| 47 | #include "inode.h" |
| 48 | #include "journal.h" |
| 49 | #include "symlink.h" |
Tiger Yang | cf1d6c7 | 2008-08-18 17:11:00 +0800 | [diff] [blame] | 50 | #include "xattr.h" |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 51 | |
| 52 | #include "buffer_head_io.h" |
| 53 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 54 | |
Al Viro | ea022dfb | 2012-05-03 10:14:29 -0400 | [diff] [blame] | 55 | static int ocfs2_fast_symlink_readpage(struct file *unused, struct page *page) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 56 | { |
Al Viro | ea022dfb | 2012-05-03 10:14:29 -0400 | [diff] [blame] | 57 | struct inode *inode = page->mapping->host; |
Sunil Mushran | 30b9c9e | 2012-08-03 17:36:17 +0100 | [diff] [blame] | 58 | struct buffer_head *bh = NULL; |
Al Viro | ea022dfb | 2012-05-03 10:14:29 -0400 | [diff] [blame] | 59 | int status = ocfs2_read_inode_block(inode, &bh); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 60 | struct ocfs2_dinode *fe; |
Al Viro | ea022dfb | 2012-05-03 10:14:29 -0400 | [diff] [blame] | 61 | const char *link; |
| 62 | void *kaddr; |
| 63 | size_t len; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 64 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 65 | if (status < 0) { |
| 66 | mlog_errno(status); |
Al Viro | ea022dfb | 2012-05-03 10:14:29 -0400 | [diff] [blame] | 67 | return status; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 68 | } |
| 69 | |
Al Viro | ea022dfb | 2012-05-03 10:14:29 -0400 | [diff] [blame] | 70 | fe = (struct ocfs2_dinode *) bh->b_data; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 71 | link = (char *) fe->id2.i_symlink; |
Al Viro | ea022dfb | 2012-05-03 10:14:29 -0400 | [diff] [blame] | 72 | /* will be less than a page size */ |
| 73 | len = strnlen(link, ocfs2_fast_symlink_chars(inode->i_sb)); |
| 74 | kaddr = kmap_atomic(page); |
| 75 | memcpy(kaddr, link, len + 1); |
| 76 | kunmap_atomic(kaddr); |
| 77 | SetPageUptodate(page); |
| 78 | unlock_page(page); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 79 | brelse(bh); |
Al Viro | ea022dfb | 2012-05-03 10:14:29 -0400 | [diff] [blame] | 80 | return 0; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 81 | } |
| 82 | |
Al Viro | ea022dfb | 2012-05-03 10:14:29 -0400 | [diff] [blame] | 83 | const struct address_space_operations ocfs2_fast_symlink_aops = { |
| 84 | .readpage = ocfs2_fast_symlink_readpage, |
| 85 | }; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 86 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 87 | const struct inode_operations ocfs2_symlink_inode_operations = { |
Al Viro | 6b25539 | 2015-11-17 10:20:54 -0500 | [diff] [blame] | 88 | .get_link = page_get_link, |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 89 | .getattr = ocfs2_getattr, |
Sunil Mushran | bc53580 | 2008-04-18 10:23:53 -0700 | [diff] [blame] | 90 | .setattr = ocfs2_setattr, |
Tiger Yang | cf1d6c7 | 2008-08-18 17:11:00 +0800 | [diff] [blame] | 91 | .listxattr = ocfs2_listxattr, |
Tristan Ye | 86239d5 | 2009-12-22 09:11:58 +0800 | [diff] [blame] | 92 | .fiemap = ocfs2_fiemap, |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 93 | }; |