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_read_folio(struct file *file, struct folio *folio)
  14. {
  15. struct page *page = &folio->page;
  16. char *link = page_address(page);
  17. struct buffer_head * bh;
  18. struct inode * inode = page->mapping->host;
  19. efs_block_t size = inode->i_size;
  20. int err;
  21. err = -ENAMETOOLONG;
  22. if (size > 2 * EFS_BLOCKSIZE)
  23. goto fail;
  24. /* read first 512 bytes of link target */
  25. err = -EIO;
  26. bh = sb_bread(inode->i_sb, efs_bmap(inode, 0));
  27. if (!bh)
  28. goto fail;
  29. memcpy(link, bh->b_data, (size > EFS_BLOCKSIZE) ? EFS_BLOCKSIZE : size);
  30. brelse(bh);
  31. if (size > EFS_BLOCKSIZE) {
  32. bh = sb_bread(inode->i_sb, efs_bmap(inode, 1));
  33. if (!bh)
  34. goto fail;
  35. memcpy(link + EFS_BLOCKSIZE, bh->b_data, size - EFS_BLOCKSIZE);
  36. brelse(bh);
  37. }
  38. link[size] = '\0';
  39. SetPageUptodate(page);
  40. unlock_page(page);
  41. return 0;
  42. fail:
  43. SetPageError(page);
  44. unlock_page(page);
  45. return err;
  46. }
  47. const struct address_space_operations efs_symlink_aops = {
  48. .read_folio = efs_symlink_read_folio
  49. };