3
0

nilfs.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. //kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_NILFS) += nilfs.o
  22. //config:
  23. //config:config FEATURE_VOLUMEID_NILFS
  24. //config: bool "nilfs filesystem"
  25. //config: default y
  26. //config: depends on VOLUMEID
  27. //config: help
  28. //config: NILFS is a New Implementation of a Log-Structured File System (LFS)
  29. //config: that supports continuous snapshots. This provides features like
  30. //config: versioning of the entire filesystem, restoration of files that
  31. //config: were deleted a few minutes ago. NILFS keeps consistency like
  32. //config: conventional LFS, so it provides quick recovery after system crashes.
  33. //config:
  34. //config: The possible use of NILFS includes versioning, tamper detection,
  35. //config: SOX compliance logging, and so forth. It can serve as an alternative
  36. //config: filesystem for Linux desktop environment, or as a basis of advanced
  37. //config: storage appliances.
  38. //config:
  39. #include "volume_id_internal.h"
  40. #define NILFS_UUID_SIZE 16
  41. #define NILFS_LABEL_SIZE 80
  42. #define NILFS_SB1_OFFSET 0x400
  43. #define NILFS_SB2_OFFSET 0x1000
  44. #define NILFS_MAGIC 0x3434
  45. struct nilfs2_super_block {
  46. /* 0x00 */ uint32_t s_rev_level; // Major revision level.
  47. /* 0x04 */ uint16_t s_minor_rev_level; // Minor revision level.
  48. /* 0x06 */ uint16_t s_magic; // Magic signature.
  49. /* 0x08 */ uint16_t s_bytes;
  50. /* 0x0A */ uint16_t s_flags;
  51. /* 0x0C */ uint32_t s_crc_seed;
  52. /* 0x10 */ uint32_t s_sum;
  53. /* 0x14 */ uint32_t s_log_block_size;
  54. /* 0x18 */ uint64_t s_nsegments;
  55. /* 0x20 */ uint64_t s_dev_size; // Block device size in bytes.
  56. /* 0x28 */ uint64_t s_first_data_block;
  57. /* 0x30 */ uint32_t s_blocks_per_segment;
  58. /* 0x34 */ uint32_t s_r_segments_percentage;
  59. /* 0x38 */ uint64_t s_last_cno;
  60. /* 0x40 */ uint64_t s_last_pseg;
  61. /* 0x48 */ uint64_t s_last_seq;
  62. /* 0x50 */ uint64_t s_free_blocks_count;
  63. /* 0x58 */ uint64_t s_ctime;
  64. /* 0x60 */ uint64_t s_mtime;
  65. /* 0x68 */ uint64_t s_wtime;
  66. /* 0x70 */ uint16_t s_mnt_count;
  67. /* 0x72 */ uint16_t s_max_mnt_count;
  68. /* 0x74 */ uint16_t s_state;
  69. /* 0x76 */ uint16_t s_errors;
  70. /* 0x78 */ uint64_t s_lastcheck;
  71. /* 0x80 */ uint32_t s_checkinterval;
  72. /* 0x84 */ uint32_t s_creator_os;
  73. /* 0x88 */ uint16_t s_def_resuid;
  74. /* 0x8A */ uint16_t s_def_resgid;
  75. /* 0x8C */ uint32_t s_first_ino;
  76. /* 0x90 */ uint16_t s_inode_size;
  77. /* 0x92 */ uint16_t s_dat_entry_size;
  78. /* 0x94 */ uint16_t s_checkpoint_size;
  79. /* 0x96 */ uint16_t s_segment_usage_size;
  80. /* 0x98 */ uint8_t s_uuid[NILFS_UUID_SIZE]; // 128-bit UUID for volume.
  81. /* 0xA8 */ uint8_t s_volume_name[NILFS_LABEL_SIZE]; // Volume label.
  82. /* 0xF8 */ // ...
  83. } PACKED;
  84. int FAST_FUNC volume_id_probe_nilfs(struct volume_id *id /*,uint64_t off*/)
  85. {
  86. struct nilfs2_super_block *sb;
  87. // Primary super block
  88. dbg("nilfs: probing at offset 0x%x", NILFS_SB1_OFFSET);
  89. sb = volume_id_get_buffer(id, NILFS_SB1_OFFSET, sizeof(*sb));
  90. if (sb == NULL)
  91. return -1;
  92. if (sb->s_magic != NILFS_MAGIC)
  93. return -1;
  94. // The secondary superblock is not always used, so ignore it for now.
  95. // When used it is at 4K from the end of the partition (sb->s_dev_size - NILFS_SB2_OFFSET).
  96. volume_id_set_label_string(id, sb->s_volume_name, NILFS_LABEL_SIZE < VOLUME_ID_LABEL_SIZE ?
  97. NILFS_LABEL_SIZE : VOLUME_ID_LABEL_SIZE);
  98. volume_id_set_uuid(id, sb->s_uuid, UUID_DCE);
  99. if (sb->s_rev_level == 2)
  100. IF_FEATURE_BLKID_TYPE(id->type = "nilfs2");
  101. return 0;
  102. }