decompressor_single.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (c) 2013
  3. * Phillip Lougher <phillip@squashfs.org.uk>
  4. *
  5. * This work is licensed under the terms of the GNU GPL, version 2. See
  6. * the COPYING file in the top-level directory.
  7. */
  8. #include <linux/types.h>
  9. #include <linux/mutex.h>
  10. #include <linux/slab.h>
  11. #include <linux/buffer_head.h>
  12. #include "squashfs_fs.h"
  13. #include "squashfs_fs_sb.h"
  14. #include "decompressor.h"
  15. #include "squashfs.h"
  16. /*
  17. * This file implements single-threaded decompression in the
  18. * decompressor framework
  19. */
  20. struct squashfs_stream {
  21. void *stream;
  22. struct mutex mutex;
  23. };
  24. void *squashfs_decompressor_create(struct squashfs_sb_info *msblk,
  25. void *comp_opts)
  26. {
  27. struct squashfs_stream *stream;
  28. int err = -ENOMEM;
  29. stream = kmalloc(sizeof(*stream), GFP_KERNEL);
  30. if (stream == NULL)
  31. goto out;
  32. stream->stream = msblk->decompressor->init(msblk, comp_opts);
  33. if (IS_ERR(stream->stream)) {
  34. err = PTR_ERR(stream->stream);
  35. goto out;
  36. }
  37. kfree(comp_opts);
  38. mutex_init(&stream->mutex);
  39. return stream;
  40. out:
  41. kfree(stream);
  42. return ERR_PTR(err);
  43. }
  44. void squashfs_decompressor_destroy(struct squashfs_sb_info *msblk)
  45. {
  46. struct squashfs_stream *stream = msblk->stream;
  47. if (stream) {
  48. msblk->decompressor->free(stream->stream);
  49. kfree(stream);
  50. }
  51. }
  52. int squashfs_decompress(struct squashfs_sb_info *msblk, struct buffer_head **bh,
  53. int b, int offset, int length, struct squashfs_page_actor *output)
  54. {
  55. int res;
  56. struct squashfs_stream *stream = msblk->stream;
  57. mutex_lock(&stream->mutex);
  58. res = msblk->decompressor->decompress(msblk, stream->stream, bh, b,
  59. offset, length, output);
  60. mutex_unlock(&stream->mutex);
  61. if (res < 0)
  62. ERROR("%s decompression failed, data probably corrupt\n",
  63. msblk->decompressor->name);
  64. return res;
  65. }
  66. int squashfs_max_decompressors(void)
  67. {
  68. return 1;
  69. }