super.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * super.c
  3. *
  4. * Copyright (C) 2001-2002 Will Dyson <will_dyson@pobox.com>
  5. *
  6. * Licensed under the GNU GPL. See the file COPYING for details.
  7. *
  8. */
  9. #include <linux/fs.h>
  10. #include <asm/page.h> /* for PAGE_SIZE */
  11. #include "befs.h"
  12. #include "super.h"
  13. /*
  14. * befs_load_sb -- Read from disk and properly byteswap all the fields
  15. * of the befs superblock
  16. */
  17. int
  18. befs_load_sb(struct super_block *sb, befs_super_block *disk_sb)
  19. {
  20. struct befs_sb_info *befs_sb = BEFS_SB(sb);
  21. /* Check the byte order of the filesystem */
  22. if (disk_sb->fs_byte_order == BEFS_BYTEORDER_NATIVE_LE)
  23. befs_sb->byte_order = BEFS_BYTESEX_LE;
  24. else if (disk_sb->fs_byte_order == BEFS_BYTEORDER_NATIVE_BE)
  25. befs_sb->byte_order = BEFS_BYTESEX_BE;
  26. befs_sb->magic1 = fs32_to_cpu(sb, disk_sb->magic1);
  27. befs_sb->magic2 = fs32_to_cpu(sb, disk_sb->magic2);
  28. befs_sb->magic3 = fs32_to_cpu(sb, disk_sb->magic3);
  29. befs_sb->block_size = fs32_to_cpu(sb, disk_sb->block_size);
  30. befs_sb->block_shift = fs32_to_cpu(sb, disk_sb->block_shift);
  31. befs_sb->num_blocks = fs64_to_cpu(sb, disk_sb->num_blocks);
  32. befs_sb->used_blocks = fs64_to_cpu(sb, disk_sb->used_blocks);
  33. befs_sb->inode_size = fs32_to_cpu(sb, disk_sb->inode_size);
  34. befs_sb->blocks_per_ag = fs32_to_cpu(sb, disk_sb->blocks_per_ag);
  35. befs_sb->ag_shift = fs32_to_cpu(sb, disk_sb->ag_shift);
  36. befs_sb->num_ags = fs32_to_cpu(sb, disk_sb->num_ags);
  37. befs_sb->flags = fs32_to_cpu(sb, disk_sb->flags);
  38. befs_sb->log_blocks = fsrun_to_cpu(sb, disk_sb->log_blocks);
  39. befs_sb->log_start = fs64_to_cpu(sb, disk_sb->log_start);
  40. befs_sb->log_end = fs64_to_cpu(sb, disk_sb->log_end);
  41. befs_sb->root_dir = fsrun_to_cpu(sb, disk_sb->root_dir);
  42. befs_sb->indices = fsrun_to_cpu(sb, disk_sb->indices);
  43. befs_sb->nls = NULL;
  44. return BEFS_OK;
  45. }
  46. int
  47. befs_check_sb(struct super_block *sb)
  48. {
  49. struct befs_sb_info *befs_sb = BEFS_SB(sb);
  50. /* Check magic headers of super block */
  51. if ((befs_sb->magic1 != BEFS_SUPER_MAGIC1)
  52. || (befs_sb->magic2 != BEFS_SUPER_MAGIC2)
  53. || (befs_sb->magic3 != BEFS_SUPER_MAGIC3)) {
  54. befs_error(sb, "invalid magic header");
  55. return BEFS_ERR;
  56. }
  57. /*
  58. * Check blocksize of BEFS.
  59. *
  60. * Blocksize of BEFS is 1024, 2048, 4096 or 8192.
  61. */
  62. if ((befs_sb->block_size != 1024)
  63. && (befs_sb->block_size != 2048)
  64. && (befs_sb->block_size != 4096)
  65. && (befs_sb->block_size != 8192)) {
  66. befs_error(sb, "invalid blocksize: %u", befs_sb->block_size);
  67. return BEFS_ERR;
  68. }
  69. if (befs_sb->block_size > PAGE_SIZE) {
  70. befs_error(sb, "blocksize(%u) cannot be larger "
  71. "than system pagesize(%lu)", befs_sb->block_size,
  72. PAGE_SIZE);
  73. return BEFS_ERR;
  74. }
  75. /*
  76. * block_shift and block_size encode the same information
  77. * in different ways as a consistency check.
  78. */
  79. if ((1 << befs_sb->block_shift) != befs_sb->block_size) {
  80. befs_error(sb, "block_shift disagrees with block_size. "
  81. "Corruption likely.");
  82. return BEFS_ERR;
  83. }
  84. /* ag_shift also encodes the same information as blocks_per_ag in a
  85. * different way, non-fatal consistency check
  86. */
  87. if ((1 << befs_sb->ag_shift) != befs_sb->blocks_per_ag)
  88. befs_error(sb, "ag_shift disagrees with blocks_per_ag.");
  89. if (befs_sb->log_start != befs_sb->log_end ||
  90. befs_sb->flags == BEFS_DIRTY) {
  91. befs_error(sb, "Filesystem not clean! There are blocks in the "
  92. "journal. You must boot into BeOS and mount this "
  93. "volume to make it clean.");
  94. return BEFS_ERR;
  95. }
  96. return BEFS_OK;
  97. }