page_actor.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. void **page;
  12. int pages;
  13. int length;
  14. int next_page;
  15. };
  16. static inline struct squashfs_page_actor *squashfs_page_actor_init(void **page,
  17. int pages, int length)
  18. {
  19. struct squashfs_page_actor *actor = kmalloc(sizeof(*actor), GFP_KERNEL);
  20. if (actor == NULL)
  21. return NULL;
  22. actor->length = length ? : pages * PAGE_CACHE_SIZE;
  23. actor->page = page;
  24. actor->pages = pages;
  25. actor->next_page = 0;
  26. return actor;
  27. }
  28. static inline void *squashfs_first_page(struct squashfs_page_actor *actor)
  29. {
  30. actor->next_page = 1;
  31. return actor->page[0];
  32. }
  33. static inline void *squashfs_next_page(struct squashfs_page_actor *actor)
  34. {
  35. return actor->next_page == actor->pages ? NULL :
  36. actor->page[actor->next_page++];
  37. }
  38. static inline void squashfs_finish_page(struct squashfs_page_actor *actor)
  39. {
  40. /* empty */
  41. }
  42. #endif