Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * symlink.c
0004  *
0005  * Copyright (c) 1999 Al Smith
0006  *
0007  * Portions derived from work (c) 1995,1996 Christian Vogelgsang.
0008  */
0009 
0010 #include <linux/string.h>
0011 #include <linux/pagemap.h>
0012 #include <linux/buffer_head.h>
0013 #include "efs.h"
0014 
0015 static int efs_symlink_read_folio(struct file *file, struct folio *folio)
0016 {
0017     struct page *page = &folio->page;
0018     char *link = page_address(page);
0019     struct buffer_head * bh;
0020     struct inode * inode = page->mapping->host;
0021     efs_block_t size = inode->i_size;
0022     int err;
0023   
0024     err = -ENAMETOOLONG;
0025     if (size > 2 * EFS_BLOCKSIZE)
0026         goto fail;
0027   
0028     /* read first 512 bytes of link target */
0029     err = -EIO;
0030     bh = sb_bread(inode->i_sb, efs_bmap(inode, 0));
0031     if (!bh)
0032         goto fail;
0033     memcpy(link, bh->b_data, (size > EFS_BLOCKSIZE) ? EFS_BLOCKSIZE : size);
0034     brelse(bh);
0035     if (size > EFS_BLOCKSIZE) {
0036         bh = sb_bread(inode->i_sb, efs_bmap(inode, 1));
0037         if (!bh)
0038             goto fail;
0039         memcpy(link + EFS_BLOCKSIZE, bh->b_data, size - EFS_BLOCKSIZE);
0040         brelse(bh);
0041     }
0042     link[size] = '\0';
0043     SetPageUptodate(page);
0044     unlock_page(page);
0045     return 0;
0046 fail:
0047     SetPageError(page);
0048     unlock_page(page);
0049     return err;
0050 }
0051 
0052 const struct address_space_operations efs_symlink_aops = {
0053     .read_folio = efs_symlink_read_folio
0054 };