xref: /openbmc/linux/fs/ocfs2/symlink.c (revision 360823a09426347ea8f232b0b0b5156d0aed0302)
1fa60ce2cSMasahiro Yamada /*
2ccd979bdSMark Fasheh  *  linux/cluster/ssi/cfs/symlink.c
3ccd979bdSMark Fasheh  *
4ccd979bdSMark Fasheh  *	This program is free software; you can redistribute it and/or
5ccd979bdSMark Fasheh  *	modify it under the terms of the GNU General Public License as
6ccd979bdSMark Fasheh  *	published by the Free Software Foundation; either version 2 of
7ccd979bdSMark Fasheh  *	the License, or (at your option) any later version.
8ccd979bdSMark Fasheh  *
9ccd979bdSMark Fasheh  *	This program is distributed in the hope that it will be useful,
10ccd979bdSMark Fasheh  *	but WITHOUT ANY WARRANTY; without even the implied warranty of
11ccd979bdSMark Fasheh  *	MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE
12ccd979bdSMark Fasheh  *	or NON INFRINGEMENT.  See the GNU General Public License for more
13ccd979bdSMark Fasheh  *	details.
14ccd979bdSMark Fasheh  *
15ccd979bdSMark Fasheh  * 	You should have received a copy of the GNU General Public License
16ccd979bdSMark Fasheh  * 	along with this program; if not, write to the Free Software
17ccd979bdSMark Fasheh  * 	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18ccd979bdSMark Fasheh  *
19ccd979bdSMark Fasheh  *	Questions/Comments/Bugfixes to ssic-linux-devel@lists.sourceforge.net
20ccd979bdSMark Fasheh  *
21ccd979bdSMark Fasheh  *  Copyright (C) 1992  Rick Sladkey
22ccd979bdSMark Fasheh  *
23ccd979bdSMark Fasheh  *  Optimization changes Copyright (C) 1994 Florian La Roche
24ccd979bdSMark Fasheh  *
25ccd979bdSMark Fasheh  *  Jun 7 1999, cache symlink lookups in the page cache.  -DaveM
26ccd979bdSMark Fasheh  *
27ccd979bdSMark Fasheh  *  Portions Copyright (C) 2001 Compaq Computer Corporation
28ccd979bdSMark Fasheh  *
29ccd979bdSMark Fasheh  *  ocfs2 symlink handling code.
30ccd979bdSMark Fasheh  *
31ccd979bdSMark Fasheh  *  Copyright (C) 2004, 2005 Oracle.
32ccd979bdSMark Fasheh  *
33ccd979bdSMark Fasheh  */
34ccd979bdSMark Fasheh 
35ccd979bdSMark Fasheh #include <linux/fs.h>
36ccd979bdSMark Fasheh #include <linux/types.h>
37ccd979bdSMark Fasheh #include <linux/slab.h>
38ccd979bdSMark Fasheh #include <linux/pagemap.h>
39a731d12dSJoel Becker #include <linux/namei.h>
40ccd979bdSMark Fasheh 
41ccd979bdSMark Fasheh #include <cluster/masklog.h>
42ccd979bdSMark Fasheh 
43ccd979bdSMark Fasheh #include "ocfs2.h"
44ccd979bdSMark Fasheh 
45ccd979bdSMark Fasheh #include "alloc.h"
46ccd979bdSMark Fasheh #include "file.h"
47ccd979bdSMark Fasheh #include "inode.h"
48ccd979bdSMark Fasheh #include "journal.h"
49ccd979bdSMark Fasheh #include "symlink.h"
50cf1d6c76STiger Yang #include "xattr.h"
51ccd979bdSMark Fasheh 
52ccd979bdSMark Fasheh #include "buffer_head_io.h"
53ccd979bdSMark Fasheh 
54ccd979bdSMark Fasheh 
ocfs2_fast_symlink_read_folio(struct file * f,struct folio * folio)55bb9263fcSMatthew Wilcox (Oracle) static int ocfs2_fast_symlink_read_folio(struct file *f, struct folio *folio)
56ccd979bdSMark Fasheh {
57bb9263fcSMatthew Wilcox (Oracle) 	struct page *page = &folio->page;
58ea022dfbSAl Viro 	struct inode *inode = page->mapping->host;
5930b9c9e6SSunil Mushran 	struct buffer_head *bh = NULL;
60ea022dfbSAl Viro 	int status = ocfs2_read_inode_block(inode, &bh);
61ccd979bdSMark Fasheh 	struct ocfs2_dinode *fe;
62ea022dfbSAl Viro 	const char *link;
63ea022dfbSAl Viro 	void *kaddr;
64ea022dfbSAl Viro 	size_t len;
65ccd979bdSMark Fasheh 
66ccd979bdSMark Fasheh 	if (status < 0) {
67ccd979bdSMark Fasheh 		mlog_errno(status);
68*b6833b38SMatthew Wilcox (Oracle) 		goto out;
69ccd979bdSMark Fasheh 	}
70ccd979bdSMark Fasheh 
71ea022dfbSAl Viro 	fe = (struct ocfs2_dinode *) bh->b_data;
72ccd979bdSMark Fasheh 	link = (char *) fe->id2.i_symlink;
73ea022dfbSAl Viro 	/* will be less than a page size */
74ea022dfbSAl Viro 	len = strnlen(link, ocfs2_fast_symlink_chars(inode->i_sb));
75ea022dfbSAl Viro 	kaddr = kmap_atomic(page);
76ea022dfbSAl Viro 	memcpy(kaddr, link, len + 1);
77ea022dfbSAl Viro 	kunmap_atomic(kaddr);
78ea022dfbSAl Viro 	SetPageUptodate(page);
79*b6833b38SMatthew Wilcox (Oracle) out:
80ea022dfbSAl Viro 	unlock_page(page);
81ccd979bdSMark Fasheh 	brelse(bh);
82*b6833b38SMatthew Wilcox (Oracle) 	return status;
83ccd979bdSMark Fasheh }
84ccd979bdSMark Fasheh 
85ea022dfbSAl Viro const struct address_space_operations ocfs2_fast_symlink_aops = {
86bb9263fcSMatthew Wilcox (Oracle) 	.read_folio		= ocfs2_fast_symlink_read_folio,
87ea022dfbSAl Viro };
88ccd979bdSMark Fasheh 
8992e1d5beSArjan van de Ven const struct inode_operations ocfs2_symlink_inode_operations = {
906b255391SAl Viro 	.get_link	= page_get_link,
91ccd979bdSMark Fasheh 	.getattr	= ocfs2_getattr,
92bc535809SSunil Mushran 	.setattr	= ocfs2_setattr,
93cf1d6c76STiger Yang 	.listxattr	= ocfs2_listxattr,
9486239d59STristan Ye 	.fiemap		= ocfs2_fiemap,
95ccd979bdSMark Fasheh };
96