blob: 31d6446dc16689eb7336a2a0addba9c0bffc46f1 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * linux/fs/affs/symlink.c
4 *
5 * 1995 Hans-Joachim Widmaier - Modified for affs.
6 *
7 * Copyright (C) 1991, 1992 Linus Torvalds
8 *
9 * affs symlink handling code
10 */
11
12#include "affs.h"
13
Matthew Wilcox (Oracle)1b6f3c82022-04-29 11:12:16 -040014static int affs_symlink_read_folio(struct file *file, struct folio *folio)
Linus Torvalds1da177e2005-04-16 15:20:36 -070015{
Matthew Wilcox (Oracle)1b6f3c82022-04-29 11:12:16 -040016 struct page *page = &folio->page;
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 struct buffer_head *bh;
18 struct inode *inode = page->mapping->host;
Al Viro21fc61c2015-11-17 01:07:57 -050019 char *link = page_address(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 struct slink_front *lf;
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 int i, j;
22 char c;
23 char lc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
Al Viro6b255392015-11-17 10:20:54 -050025 pr_debug("get_link(ino=%lu)\n", inode->i_ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 bh = affs_bread(inode->i_sb, inode->i_ino);
28 if (!bh)
29 goto fail;
30 i = 0;
31 j = 0;
32 lf = (struct slink_front *)bh->b_data;
33 lc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35 if (strchr(lf->symname,':')) { /* Handle assign or volume name */
Al Viro29333922010-01-24 00:04:07 -050036 struct affs_sb_info *sbi = AFFS_SB(inode->i_sb);
37 char *pf;
38 spin_lock(&sbi->symlink_lock);
39 pf = sbi->s_prefix ? sbi->s_prefix : "/";
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 while (i < 1023 && (c = pf[i]))
41 link[i++] = c;
Al Viro29333922010-01-24 00:04:07 -050042 spin_unlock(&sbi->symlink_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 while (i < 1023 && lf->symname[j] != ':')
44 link[i++] = lf->symname[j++];
45 if (i < 1023)
46 link[i++] = '/';
47 j++;
48 lc = '/';
49 }
50 while (i < 1023 && (c = lf->symname[j])) {
51 if (c == '/' && lc == '/' && i < 1020) { /* parent dir */
52 link[i++] = '.';
53 link[i++] = '.';
54 }
55 link[i++] = c;
56 lc = c;
57 j++;
58 }
59 link[i] = '\0';
60 affs_brelse(bh);
61 SetPageUptodate(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 unlock_page(page);
63 return 0;
64fail:
65 SetPageError(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 unlock_page(page);
Fabian Frederick196a4f82015-06-30 14:58:01 -070067 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068}
69
Christoph Hellwigf5e54d62006-06-28 04:26:44 -070070const struct address_space_operations affs_symlink_aops = {
Matthew Wilcox (Oracle)1b6f3c82022-04-29 11:12:16 -040071 .read_folio = affs_symlink_read_folio,
Linus Torvalds1da177e2005-04-16 15:20:36 -070072};
73
Arjan van de Ven754661f2007-02-12 00:55:38 -080074const struct inode_operations affs_symlink_inode_operations = {
Al Viro6b255392015-11-17 10:20:54 -050075 .get_link = page_get_link,
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 .setattr = affs_notify_change,
77};