page_actor.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #ifndef CONFIG_SQUASHFS_FILE_DIRECT
  11. struct squashfs_page_actor {
  12. void **page;
  13. int pages;
  14. int length;
  15. int next_page;
  16. };
  17. static inline struct squashfs_page_actor *squashfs_page_actor_init(void **page,
  18. int pages, int length)
  19. {
  20. struct squashfs_page_actor *actor = kmalloc(sizeof(*actor), GFP_KERNEL);
  21. if (actor == NULL)
  22. return NULL;
  23. actor->length = length ? : pages * PAGE_CACHE_SIZE;
  24. actor->page = page;
  25. actor->pages = pages;
  26. actor->next_page = 0;
  27. return actor;
  28. }
  29. static inline void *squashfs_first_page(struct squashfs_page_actor *actor)
  30. {
  31. actor->next_page = 1;
  32. return actor->page[0];
  33. }
  34. static inline void *squashfs_next_page(struct squashfs_page_actor *actor)
  35. {
  36. return actor->next_page == actor->pages ? NULL :
  37. actor->page[actor->next_page++];
  38. }
  39. static inline void squashfs_finish_page(struct squashfs_page_actor *actor)
  40. {
  41. /* empty */
  42. }
  43. #else
  44. struct squashfs_page_actor {
  45. union {
  46. void **buffer;
  47. struct page **page;
  48. };
  49. void *pageaddr;
  50. void *(*squashfs_first_page)(struct squashfs_page_actor *);
  51. void *(*squashfs_next_page)(struct squashfs_page_actor *);
  52. void (*squashfs_finish_page)(struct squashfs_page_actor *);
  53. int pages;
  54. int length;
  55. int next_page;
  56. };
  57. extern struct squashfs_page_actor *squashfs_page_actor_init(void **, int, int);
  58. extern struct squashfs_page_actor *squashfs_page_actor_init_special(struct page
  59. **, int, int);
  60. static inline void *squashfs_first_page(struct squashfs_page_actor *actor)
  61. {
  62. return actor->squashfs_first_page(actor);
  63. }
  64. static inline void *squashfs_next_page(struct squashfs_page_actor *actor)
  65. {
  66. return actor->squashfs_next_page(actor);
  67. }
  68. static inline void squashfs_finish_page(struct squashfs_page_actor *actor)
  69. {
  70. actor->squashfs_finish_page(actor);
  71. }
  72. #endif
  73. #endif