compress.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2019 HUAWEI, Inc.
  4. * https://www.huawei.com/
  5. */
  6. #ifndef __EROFS_FS_COMPRESS_H
  7. #define __EROFS_FS_COMPRESS_H
  8. #include "internal.h"
  9. struct z_erofs_decompress_req {
  10. struct super_block *sb;
  11. struct page **in, **out;
  12. unsigned int inpages, outpages;
  13. unsigned short pageofs_in, pageofs_out;
  14. unsigned int inputsize, outputsize;
  15. unsigned int alg; /* the algorithm for decompression */
  16. bool inplace_io, partial_decoding, fillgaps;
  17. gfp_t gfp; /* allocation flags for extra temporary buffers */
  18. };
  19. struct z_erofs_decompressor {
  20. int (*config)(struct super_block *sb, struct erofs_super_block *dsb,
  21. void *data, int size);
  22. const char *(*decompress)(struct z_erofs_decompress_req *rq,
  23. struct page **pagepool);
  24. int (*init)(void);
  25. void (*exit)(void);
  26. char *name;
  27. };
  28. #define Z_EROFS_SHORTLIVED_PAGE (-1UL << 2)
  29. #define Z_EROFS_PREALLOCATED_FOLIO ((void *)(-2UL << 2))
  30. /*
  31. * Currently, short-lived pages are pages directly from buddy system
  32. * with specific page->private (Z_EROFS_SHORTLIVED_PAGE).
  33. * In the future world of Memdescs, it should be type 0 (Misc) memory
  34. * which type can be checked with a new helper.
  35. */
  36. static inline bool z_erofs_is_shortlived_page(struct page *page)
  37. {
  38. return page->private == Z_EROFS_SHORTLIVED_PAGE;
  39. }
  40. static inline bool z_erofs_put_shortlivedpage(struct page **pagepool,
  41. struct page *page)
  42. {
  43. if (!z_erofs_is_shortlived_page(page))
  44. return false;
  45. erofs_pagepool_add(pagepool, page);
  46. return true;
  47. }
  48. extern const struct z_erofs_decompressor z_erofs_lzma_decomp;
  49. extern const struct z_erofs_decompressor z_erofs_deflate_decomp;
  50. extern const struct z_erofs_decompressor z_erofs_zstd_decomp;
  51. extern const struct z_erofs_decompressor *z_erofs_decomp[];
  52. struct z_erofs_stream_dctx {
  53. struct z_erofs_decompress_req *rq;
  54. int no, ni; /* the current {en,de}coded page # */
  55. unsigned int avail_out; /* remaining bytes in the decoded buffer */
  56. unsigned int inbuf_pos, inbuf_sz;
  57. /* current status of the encoded buffer */
  58. u8 *kin, *kout; /* buffer mapped pointers */
  59. void *bounce; /* bounce buffer for inplace I/Os */
  60. bool bounced; /* is the bounce buffer used now? */
  61. };
  62. const char *z_erofs_stream_switch_bufs(struct z_erofs_stream_dctx *dctx,
  63. void **dst, void **src, struct page **pgpl);
  64. const char *z_erofs_fixup_insize(struct z_erofs_decompress_req *rq,
  65. const char *padbuf, unsigned int padbufsize);
  66. int __init z_erofs_init_decompressor(void);
  67. void z_erofs_exit_decompressor(void);
  68. int z_erofs_crypto_decompress(struct z_erofs_decompress_req *rq,
  69. struct page **pgpl);
  70. int z_erofs_crypto_enable_engine(const char *name, int len);
  71. #ifdef CONFIG_EROFS_FS_ZIP_ACCEL
  72. void z_erofs_crypto_disable_all_engines(void);
  73. int z_erofs_crypto_show_engines(char *buf, int size, char sep);
  74. #else
  75. static inline void z_erofs_crypto_disable_all_engines(void) {}
  76. static inline int z_erofs_crypto_show_engines(char *buf, int size, char sep) { return 0; }
  77. #endif
  78. #endif