symlink.c 1.2 KB

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