symlink.c 1.1 KB

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