blob: 69b03dbb792f7a080abc70f5d45ff4bf50d458b9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/fs/affs/symlink.c
3 *
4 * 1995 Hans-Joachim Widmaier - Modified for affs.
5 *
6 * Copyright (C) 1991, 1992 Linus Torvalds
7 *
8 * affs symlink handling code
9 */
10
11#include "affs.h"
12
13static int affs_symlink_readpage(struct file *file, struct page *page)
14{
15 struct buffer_head *bh;
16 struct inode *inode = page->mapping->host;
Al Viro21fc61c2015-11-17 01:07:57 -050017 char *link = page_address(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 struct slink_front *lf;
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 int i, j;
20 char c;
21 char lc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Al Viro6b255392015-11-17 10:20:54 -050023 pr_debug("get_link(ino=%lu)\n", inode->i_ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 bh = affs_bread(inode->i_sb, inode->i_ino);
26 if (!bh)
27 goto fail;
28 i = 0;
29 j = 0;
30 lf = (struct slink_front *)bh->b_data;
31 lc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
33 if (strchr(lf->symname,':')) { /* Handle assign or volume name */
Al Viro29333922010-01-24 00:04:07 -050034 struct affs_sb_info *sbi = AFFS_SB(inode->i_sb);
35 char *pf;
36 spin_lock(&sbi->symlink_lock);
37 pf = sbi->s_prefix ? sbi->s_prefix : "/";
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 while (i < 1023 && (c = pf[i]))
39 link[i++] = c;
Al Viro29333922010-01-24 00:04:07 -050040 spin_unlock(&sbi->symlink_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 while (i < 1023 && lf->symname[j] != ':')
42 link[i++] = lf->symname[j++];
43 if (i < 1023)
44 link[i++] = '/';
45 j++;
46 lc = '/';
47 }
48 while (i < 1023 && (c = lf->symname[j])) {
49 if (c == '/' && lc == '/' && i < 1020) { /* parent dir */
50 link[i++] = '.';
51 link[i++] = '.';
52 }
53 link[i++] = c;
54 lc = c;
55 j++;
56 }
57 link[i] = '\0';
58 affs_brelse(bh);
59 SetPageUptodate(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 unlock_page(page);
61 return 0;
62fail:
63 SetPageError(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 unlock_page(page);
Fabian Frederick196a4f82015-06-30 14:58:01 -070065 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066}
67
Christoph Hellwigf5e54d62006-06-28 04:26:44 -070068const struct address_space_operations affs_symlink_aops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 .readpage = affs_symlink_readpage,
70};
71
Arjan van de Ven754661f2007-02-12 00:55:38 -080072const struct inode_operations affs_symlink_inode_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 .readlink = generic_readlink,
Al Viro6b255392015-11-17 10:20:54 -050074 .get_link = page_get_link,
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 .setattr = affs_notify_change,
76};