symlink.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 = kmap(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. kunmap(page);
  39. unlock_page(page);
  40. return 0;
  41. fail:
  42. SetPageError(page);
  43. kunmap(page);
  44. unlock_page(page);
  45. return err;
  46. }
  47. const struct address_space_operations efs_symlink_aops = {
  48. .readpage = efs_symlink_readpage
  49. };