page_actor.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef PAGE_ACTOR_H
  2. #define PAGE_ACTOR_H
  3. /*
  4. * Copyright (c) 2013
  5. * Phillip Lougher <phillip@squashfs.org.uk>
  6. *
  7. * This work is licensed under the terms of the GNU GPL, version 2. See
  8. * the COPYING file in the top-level directory.
  9. */
  10. struct squashfs_page_actor {
  11. struct page **page;
  12. void *pageaddr;
  13. int pages;
  14. int length;
  15. int next_page;
  16. void (*release_pages)(struct page **, int, int);
  17. };
  18. extern struct squashfs_page_actor *squashfs_page_actor_init(struct page **,
  19. int, int, void (*)(struct page **, int, int));
  20. extern void squashfs_page_actor_free(struct squashfs_page_actor *, int);
  21. extern void squashfs_actor_to_buf(struct squashfs_page_actor *, void *, int);
  22. extern void squashfs_buf_to_actor(void *, struct squashfs_page_actor *, int);
  23. extern void squashfs_bh_to_actor(struct buffer_head **, int,
  24. struct squashfs_page_actor *, int, int, int);
  25. extern void squashfs_bh_to_buf(struct buffer_head **, int, void *, int, int,
  26. int);
  27. /*
  28. * Calling code should avoid sleeping between calls to squashfs_first_page()
  29. * and squashfs_finish_page().
  30. */
  31. static inline void *squashfs_first_page(struct squashfs_page_actor *actor)
  32. {
  33. actor->next_page = 1;
  34. return actor->pageaddr = actor->page[0] ? kmap_atomic(actor->page[0])
  35. : NULL;
  36. }
  37. static inline void *squashfs_next_page(struct squashfs_page_actor *actor)
  38. {
  39. if (!IS_ERR_OR_NULL(actor->pageaddr))
  40. kunmap_atomic(actor->pageaddr);
  41. if (actor->next_page == actor->pages)
  42. return actor->pageaddr = ERR_PTR(-ENODATA);
  43. actor->pageaddr = actor->page[actor->next_page] ?
  44. kmap_atomic(actor->page[actor->next_page]) : NULL;
  45. ++actor->next_page;
  46. return actor->pageaddr;
  47. }
  48. static inline void squashfs_finish_page(struct squashfs_page_actor *actor)
  49. {
  50. if (!IS_ERR_OR_NULL(actor->pageaddr))
  51. kunmap_atomic(actor->pageaddr);
  52. }
  53. extern struct page **alloc_page_array(int, int);
  54. extern void free_page_array(struct page **, int);
  55. #endif