^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * symlink.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 1999 Al Smith
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Portions derived from work (c) 1995,1996 Christian Vogelgsang.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "efs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) static int efs_symlink_readpage(struct file *file, struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) char *link = page_address(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) struct buffer_head * bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) struct inode * inode = page->mapping->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) efs_block_t size = inode->i_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) err = -ENAMETOOLONG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) if (size > 2 * EFS_BLOCKSIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) /* read first 512 bytes of link target */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) bh = sb_bread(inode->i_sb, efs_bmap(inode, 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) if (!bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) memcpy(link, bh->b_data, (size > EFS_BLOCKSIZE) ? EFS_BLOCKSIZE : size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) if (size > EFS_BLOCKSIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) bh = sb_bread(inode->i_sb, efs_bmap(inode, 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) if (!bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) memcpy(link + EFS_BLOCKSIZE, bh->b_data, size - EFS_BLOCKSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) link[size] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) SetPageUptodate(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) SetPageError(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) const struct address_space_operations efs_symlink_aops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) .readpage = efs_symlink_readpage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) };