1 /*
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 [email protected]
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>
39 #include <linux/namei.h>
40 
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"
50 #include "xattr.h"
51 
52 #include "buffer_head_io.h"
53 
54 
ocfs2_fast_symlink_read_folio(struct file * f,struct folio * folio)55 static int ocfs2_fast_symlink_read_folio(struct file *f, struct folio *folio)
56 {
57 	struct inode *inode = folio->mapping->host;
58 	struct buffer_head *bh = NULL;
59 	int status = ocfs2_read_inode_block(inode, &bh);
60 	struct ocfs2_dinode *fe;
61 	const char *link;
62 	size_t len;
63 
64 	if (status < 0) {
65 		mlog_errno(status);
66 		goto out;
67 	}
68 
69 	fe = (struct ocfs2_dinode *) bh->b_data;
70 	link = (char *) fe->id2.i_symlink;
71 	/* will be less than a page size */
72 	len = strnlen(link, ocfs2_fast_symlink_chars(inode->i_sb));
73 	memcpy_to_folio(folio, 0, link, len + 1);
74 out:
75 	folio_end_read(folio, status == 0);
76 	brelse(bh);
77 	return status;
78 }
79 
80 const struct address_space_operations ocfs2_fast_symlink_aops = {
81 	.read_folio		= ocfs2_fast_symlink_read_folio,
82 };
83 
84 const struct inode_operations ocfs2_symlink_inode_operations = {
85 	.get_link	= page_get_link,
86 	.getattr	= ocfs2_getattr,
87 	.setattr	= ocfs2_setattr,
88 	.listxattr	= ocfs2_listxattr,
89 	.fiemap		= ocfs2_fiemap,
90 };
91