symlink.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. char *link = folio_address(folio);
  16. struct buffer_head *bh;
  17. struct inode *inode = folio->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. err = 0;
  39. fail:
  40. folio_end_read(folio, err == 0);
  41. return err;
  42. }
  43. const struct address_space_operations efs_symlink_aops = {
  44. .read_folio = efs_symlink_read_folio
  45. };