summaryrefslogtreecommitdiffstats
path: root/kernel/fs/udf/symlink.c
diff options
context:
space:
mode:
authorYunhong Jiang <yunhong.jiang@intel.com>2015-08-04 12:17:53 -0700
committerYunhong Jiang <yunhong.jiang@intel.com>2015-08-04 15:44:42 -0700
commit9ca8dbcc65cfc63d6f5ef3312a33184e1d726e00 (patch)
tree1c9cafbcd35f783a87880a10f85d1a060db1a563 /kernel/fs/udf/symlink.c
parent98260f3884f4a202f9ca5eabed40b1354c489b29 (diff)
Add the rt linux 4.1.3-rt3 as base
Import the rt linux 4.1.3-rt3 as OPNFV kvm base. It's from git://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-rt-devel.git linux-4.1.y-rt and the base is: commit 0917f823c59692d751951bf5ea699a2d1e2f26a2 Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Date: Sat Jul 25 12:13:34 2015 +0200 Prepare v4.1.3-rt3 Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> We lose all the git history this way and it's not good. We should apply another opnfv project repo in future. Change-Id: I87543d81c9df70d99c5001fbdf646b202c19f423 Signed-off-by: Yunhong Jiang <yunhong.jiang@intel.com>
Diffstat (limited to 'kernel/fs/udf/symlink.c')
-rw-r--r--kernel/fs/udf/symlink.c159
1 files changed, 159 insertions, 0 deletions
diff --git a/kernel/fs/udf/symlink.c b/kernel/fs/udf/symlink.c
new file mode 100644
index 000000000..8dfbc4025
--- /dev/null
+++ b/kernel/fs/udf/symlink.c
@@ -0,0 +1,159 @@
+/*
+ * symlink.c
+ *
+ * PURPOSE
+ * Symlink handling routines for the OSTA-UDF(tm) filesystem.
+ *
+ * COPYRIGHT
+ * This file is distributed under the terms of the GNU General Public
+ * License (GPL). Copies of the GPL can be obtained from:
+ * ftp://prep.ai.mit.edu/pub/gnu/GPL
+ * Each contributing author retains all rights to their own work.
+ *
+ * (C) 1998-2001 Ben Fennema
+ * (C) 1999 Stelias Computing Inc
+ *
+ * HISTORY
+ *
+ * 04/16/99 blf Created.
+ *
+ */
+
+#include "udfdecl.h"
+#include <linux/uaccess.h>
+#include <linux/errno.h>
+#include <linux/fs.h>
+#include <linux/time.h>
+#include <linux/mm.h>
+#include <linux/stat.h>
+#include <linux/pagemap.h>
+#include "udf_i.h"
+
+static int udf_pc_to_char(struct super_block *sb, unsigned char *from,
+ int fromlen, unsigned char *to, int tolen)
+{
+ struct pathComponent *pc;
+ int elen = 0;
+ int comp_len;
+ unsigned char *p = to;
+
+ /* Reserve one byte for terminating \0 */
+ tolen--;
+ while (elen < fromlen) {
+ pc = (struct pathComponent *)(from + elen);
+ elen += sizeof(struct pathComponent);
+ switch (pc->componentType) {
+ case 1:
+ /*
+ * Symlink points to some place which should be agreed
+ * upon between originator and receiver of the media. Ignore.
+ */
+ if (pc->lengthComponentIdent > 0) {
+ elen += pc->lengthComponentIdent;
+ break;
+ }
+ /* Fall through */
+ case 2:
+ if (tolen == 0)
+ return -ENAMETOOLONG;
+ p = to;
+ *p++ = '/';
+ tolen--;
+ break;
+ case 3:
+ if (tolen < 3)
+ return -ENAMETOOLONG;
+ memcpy(p, "../", 3);
+ p += 3;
+ tolen -= 3;
+ break;
+ case 4:
+ if (tolen < 2)
+ return -ENAMETOOLONG;
+ memcpy(p, "./", 2);
+ p += 2;
+ tolen -= 2;
+ /* that would be . - just ignore */
+ break;
+ case 5:
+ elen += pc->lengthComponentIdent;
+ if (elen > fromlen)
+ return -EIO;
+ comp_len = udf_get_filename(sb, pc->componentIdent,
+ pc->lengthComponentIdent,
+ p, tolen);
+ p += comp_len;
+ tolen -= comp_len;
+ if (tolen == 0)
+ return -ENAMETOOLONG;
+ *p++ = '/';
+ tolen--;
+ break;
+ }
+ }
+ if (p > to + 1)
+ p[-1] = '\0';
+ else
+ p[0] = '\0';
+ return 0;
+}
+
+static int udf_symlink_filler(struct file *file, struct page *page)
+{
+ struct inode *inode = page->mapping->host;
+ struct buffer_head *bh = NULL;
+ unsigned char *symlink;
+ int err;
+ unsigned char *p = kmap(page);
+ struct udf_inode_info *iinfo;
+ uint32_t pos;
+
+ /* We don't support symlinks longer than one block */
+ if (inode->i_size > inode->i_sb->s_blocksize) {
+ err = -ENAMETOOLONG;
+ goto out_unmap;
+ }
+
+ iinfo = UDF_I(inode);
+ pos = udf_block_map(inode, 0);
+
+ down_read(&iinfo->i_data_sem);
+ if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
+ symlink = iinfo->i_ext.i_data + iinfo->i_lenEAttr;
+ } else {
+ bh = sb_bread(inode->i_sb, pos);
+
+ if (!bh) {
+ err = -EIO;
+ goto out_unlock_inode;
+ }
+
+ symlink = bh->b_data;
+ }
+
+ err = udf_pc_to_char(inode->i_sb, symlink, inode->i_size, p, PAGE_SIZE);
+ brelse(bh);
+ if (err)
+ goto out_unlock_inode;
+
+ up_read(&iinfo->i_data_sem);
+ SetPageUptodate(page);
+ kunmap(page);
+ unlock_page(page);
+ return 0;
+
+out_unlock_inode:
+ up_read(&iinfo->i_data_sem);
+ SetPageError(page);
+out_unmap:
+ kunmap(page);
+ unlock_page(page);
+ return err;
+}
+
+/*
+ * symlinks can't do much...
+ */
+const struct address_space_operations udf_symlink_aops = {
+ .readpage = udf_symlink_filler,
+};