squashfs.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * volume_id - reads filesystem label and uuid
  3. *
  4. * Copyright (C) 2012 S-G Bergh <sgb@systemasis.org>
  5. *
  6. * Licensed under GPLv2, see file LICENSE in this source tree.
  7. */
  8. //kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_SQUASHFS) += squashfs.o
  9. //config:
  10. //config:config FEATURE_VOLUMEID_SQUASHFS
  11. //config: bool "SquashFS filesystem"
  12. //config: default y
  13. //config: depends on VOLUMEID && FEATURE_BLKID_TYPE
  14. //config: help
  15. //config: Squashfs is a compressed read-only filesystem for Linux. Squashfs is
  16. //config: intended for general read-only filesystem use and in constrained block
  17. //config: device/memory systems (e.g. embedded systems) where low overhead is
  18. //config: needed.
  19. //config:
  20. #include "volume_id_internal.h"
  21. struct squashfs_superblock {
  22. uint32_t magic;
  23. /*
  24. uint32_t dummy[6];
  25. uint16_t major;
  26. uint16_t minor;
  27. */
  28. } PACKED;
  29. int FAST_FUNC volume_id_probe_squashfs(struct volume_id *id /*,uint64_t off*/)
  30. {
  31. #define off ((uint64_t)0)
  32. struct squashfs_superblock *sb;
  33. dbg("SquashFS: probing at offset 0x%llx", (unsigned long long) off);
  34. sb = volume_id_get_buffer(id, off, 0x200);
  35. if (!sb)
  36. return -1;
  37. // Old SquashFS (pre 4.0) can be both big and little endian, so test for both.
  38. // Likewise, it is commonly used in firwmare with some non-standard signatures.
  39. #define pack(a,b,c,d) ( (uint32_t)((a * 256 + b) * 256 + c) * 256 + d )
  40. #define SIG1 pack('s','q','s','h')
  41. #define SIG2 pack('h','s','q','s')
  42. #define SIG3 pack('s','h','s','q')
  43. #define SIG4 pack('q','s','h','s')
  44. if (sb->magic == SIG1
  45. || sb->magic == SIG2
  46. || sb->magic == SIG3
  47. || sb->magic == SIG4
  48. ) {
  49. IF_FEATURE_BLKID_TYPE(id->type = "squashfs";)
  50. return 0;
  51. }
  52. return -1;
  53. }