Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 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 | |
| 14 | static int affs_symlink_readpage(struct file *file, struct page *page) |
| 15 | { |
| 16 | struct buffer_head *bh; |
| 17 | struct inode *inode = page->mapping->host; |
Al Viro | 21fc61c | 2015-11-17 01:07:57 -0500 | [diff] [blame] | 18 | char *link = page_address(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | struct slink_front *lf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | int i, j; |
| 21 | char c; |
| 22 | char lc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
Al Viro | 6b25539 | 2015-11-17 10:20:54 -0500 | [diff] [blame] | 24 | pr_debug("get_link(ino=%lu)\n", inode->i_ino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | bh = affs_bread(inode->i_sb, inode->i_ino); |
| 27 | if (!bh) |
| 28 | goto fail; |
| 29 | i = 0; |
| 30 | j = 0; |
| 31 | lf = (struct slink_front *)bh->b_data; |
| 32 | lc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | if (strchr(lf->symname,':')) { /* Handle assign or volume name */ |
Al Viro | 2933392 | 2010-01-24 00:04:07 -0500 | [diff] [blame] | 35 | struct affs_sb_info *sbi = AFFS_SB(inode->i_sb); |
| 36 | char *pf; |
| 37 | spin_lock(&sbi->symlink_lock); |
| 38 | pf = sbi->s_prefix ? sbi->s_prefix : "/"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | while (i < 1023 && (c = pf[i])) |
| 40 | link[i++] = c; |
Al Viro | 2933392 | 2010-01-24 00:04:07 -0500 | [diff] [blame] | 41 | spin_unlock(&sbi->symlink_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | while (i < 1023 && lf->symname[j] != ':') |
| 43 | link[i++] = lf->symname[j++]; |
| 44 | if (i < 1023) |
| 45 | link[i++] = '/'; |
| 46 | j++; |
| 47 | lc = '/'; |
| 48 | } |
| 49 | while (i < 1023 && (c = lf->symname[j])) { |
| 50 | if (c == '/' && lc == '/' && i < 1020) { /* parent dir */ |
| 51 | link[i++] = '.'; |
| 52 | link[i++] = '.'; |
| 53 | } |
| 54 | link[i++] = c; |
| 55 | lc = c; |
| 56 | j++; |
| 57 | } |
| 58 | link[i] = '\0'; |
| 59 | affs_brelse(bh); |
| 60 | SetPageUptodate(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | unlock_page(page); |
| 62 | return 0; |
| 63 | fail: |
| 64 | SetPageError(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | unlock_page(page); |
Fabian Frederick | 196a4f8 | 2015-06-30 14:58:01 -0700 | [diff] [blame] | 66 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Christoph Hellwig | f5e54d6 | 2006-06-28 04:26:44 -0700 | [diff] [blame] | 69 | const struct address_space_operations affs_symlink_aops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | .readpage = affs_symlink_readpage, |
| 71 | }; |
| 72 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 73 | const struct inode_operations affs_symlink_inode_operations = { |
Al Viro | 6b25539 | 2015-11-17 10:20:54 -0500 | [diff] [blame] | 74 | .get_link = page_get_link, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | .setattr = affs_notify_change, |
| 76 | }; |