3
0

nilfs.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * volume_id - reads filesystem label and uuid
  3. *
  4. * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
  5. * Copyright (C) 2012 S-G Bergh <sgb@systemasis.org>
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. //config:config FEATURE_VOLUMEID_NILFS
  22. //config: bool "nilfs filesystem"
  23. //config: default y
  24. //config: depends on VOLUMEID
  25. //config: help
  26. //config: NILFS is a New Implementation of a Log-Structured File System (LFS)
  27. //config: that supports continuous snapshots. This provides features like
  28. //config: versioning of the entire filesystem, restoration of files that
  29. //config: were deleted a few minutes ago. NILFS keeps consistency like
  30. //config: conventional LFS, so it provides quick recovery after system crashes.
  31. //config:
  32. //config: The possible use of NILFS includes versioning, tamper detection,
  33. //config: SOX compliance logging, and so forth. It can serve as an alternative
  34. //config: filesystem for Linux desktop environment, or as a basis of advanced
  35. //config: storage appliances.
  36. //kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_NILFS) += nilfs.o
  37. #include "volume_id_internal.h"
  38. #define NILFS_UUID_SIZE 16
  39. #define NILFS_LABEL_SIZE 80
  40. #define NILFS_SB1_OFFSET 0x400
  41. #define NILFS_SB2_OFFSET 0x1000
  42. #define NILFS_MAGIC 0x3434
  43. struct nilfs2_super_block {
  44. /* 0x00 */ uint32_t s_rev_level; // Major revision level.
  45. /* 0x04 */ uint16_t s_minor_rev_level; // Minor revision level.
  46. /* 0x06 */ uint16_t s_magic; // Magic signature.
  47. /* 0x08 */ uint16_t s_bytes;
  48. /* 0x0A */ uint16_t s_flags;
  49. /* 0x0C */ uint32_t s_crc_seed;
  50. /* 0x10 */ uint32_t s_sum;
  51. /* 0x14 */ uint32_t s_log_block_size;
  52. /* 0x18 */ uint64_t s_nsegments;
  53. /* 0x20 */ uint64_t s_dev_size; // Block device size in bytes.
  54. /* 0x28 */ uint64_t s_first_data_block;
  55. /* 0x30 */ uint32_t s_blocks_per_segment;
  56. /* 0x34 */ uint32_t s_r_segments_percentage;
  57. /* 0x38 */ uint64_t s_last_cno;
  58. /* 0x40 */ uint64_t s_last_pseg;
  59. /* 0x48 */ uint64_t s_last_seq;
  60. /* 0x50 */ uint64_t s_free_blocks_count;
  61. /* 0x58 */ uint64_t s_ctime;
  62. /* 0x60 */ uint64_t s_mtime;
  63. /* 0x68 */ uint64_t s_wtime;
  64. /* 0x70 */ uint16_t s_mnt_count;
  65. /* 0x72 */ uint16_t s_max_mnt_count;
  66. /* 0x74 */ uint16_t s_state;
  67. /* 0x76 */ uint16_t s_errors;
  68. /* 0x78 */ uint64_t s_lastcheck;
  69. /* 0x80 */ uint32_t s_checkinterval;
  70. /* 0x84 */ uint32_t s_creator_os;
  71. /* 0x88 */ uint16_t s_def_resuid;
  72. /* 0x8A */ uint16_t s_def_resgid;
  73. /* 0x8C */ uint32_t s_first_ino;
  74. /* 0x90 */ uint16_t s_inode_size;
  75. /* 0x92 */ uint16_t s_dat_entry_size;
  76. /* 0x94 */ uint16_t s_checkpoint_size;
  77. /* 0x96 */ uint16_t s_segment_usage_size;
  78. /* 0x98 */ uint8_t s_uuid[NILFS_UUID_SIZE]; // 128-bit UUID for volume.
  79. /* 0xA8 */ uint8_t s_volume_name[NILFS_LABEL_SIZE]; // Volume label.
  80. /* 0xF8 */ // ...
  81. } PACKED;
  82. int FAST_FUNC volume_id_probe_nilfs(struct volume_id *id /*,uint64_t off*/)
  83. {
  84. struct nilfs2_super_block *sb;
  85. // Primary super block
  86. dbg("nilfs: probing at offset 0x%x", NILFS_SB1_OFFSET);
  87. sb = volume_id_get_buffer(id, NILFS_SB1_OFFSET, sizeof(*sb));
  88. if (sb == NULL)
  89. return -1;
  90. if (sb->s_magic != NILFS_MAGIC)
  91. return -1;
  92. // The secondary superblock is not always used, so ignore it for now.
  93. // When used it is at 4K from the end of the partition (sb->s_dev_size - NILFS_SB2_OFFSET).
  94. volume_id_set_label_string(id, sb->s_volume_name, NILFS_LABEL_SIZE < VOLUME_ID_LABEL_SIZE ?
  95. NILFS_LABEL_SIZE : VOLUME_ID_LABEL_SIZE);
  96. volume_id_set_uuid(id, sb->s_uuid, UUID_DCE);
  97. if (sb->s_rev_level == 2)
  98. IF_FEATURE_BLKID_TYPE(id->type = "nilfs2");
  99. return 0;
  100. }