symlink.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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/efs_fs.h>
  10. #include <linux/pagemap.h>
  11. #include <linux/buffer_head.h>
  12. #include <linux/smp_lock.h>
  13. static int efs_symlink_readpage(struct file *file, struct page *page)
  14. {
  15. char *link = kmap(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_notlocked;
  23. lock_kernel();
  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. unlock_kernel();
  40. SetPageUptodate(page);
  41. kunmap(page);
  42. unlock_page(page);
  43. return 0;
  44. fail:
  45. unlock_kernel();
  46. fail_notlocked:
  47. SetPageError(page);
  48. kunmap(page);
  49. unlock_page(page);
  50. return err;
  51. }
  52. const struct address_space_operations efs_symlink_aops = {
  53. .readpage = efs_symlink_readpage
  54. };