Sven-Göran Bergh | c5a9fa2 | 2012-09-02 15:34:39 +0200 | [diff] [blame] | 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 | |
Sven-Göran Bergh | 3b45801 | 2013-07-31 15:45:20 +0200 | [diff] [blame^] | 22 | //kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_NILFS) += nilfs.o |
| 23 | |
Sven-Göran Bergh | c5a9fa2 | 2012-09-02 15:34:39 +0200 | [diff] [blame] | 24 | #include "volume_id_internal.h" |
| 25 | |
| 26 | #define NILFS_UUID_SIZE 16 |
| 27 | #define NILFS_LABEL_SIZE 80 |
| 28 | #define NILFS_SB1_OFFSET 0x400 |
| 29 | #define NILFS_SB2_OFFSET 0x1000 |
| 30 | #define NILFS_MAGIC 0x3434 |
| 31 | |
| 32 | struct nilfs2_super_block { |
| 33 | /* 0x00 */ uint32_t s_rev_level; // Major revision level. |
| 34 | /* 0x04 */ uint16_t s_minor_rev_level; // Minor revision level. |
| 35 | /* 0x06 */ uint16_t s_magic; // Magic signature. |
| 36 | /* 0x08 */ uint16_t s_bytes; |
| 37 | /* 0x0A */ uint16_t s_flags; |
| 38 | /* 0x0C */ uint32_t s_crc_seed; |
| 39 | /* 0x10 */ uint32_t s_sum; |
| 40 | /* 0x14 */ uint32_t s_log_block_size; |
| 41 | /* 0x18 */ uint64_t s_nsegments; |
| 42 | /* 0x20 */ uint64_t s_dev_size; // Block device size in bytes. |
| 43 | /* 0x28 */ uint64_t s_first_data_block; |
| 44 | /* 0x30 */ uint32_t s_blocks_per_segment; |
| 45 | /* 0x34 */ uint32_t s_r_segments_percentage; |
| 46 | /* 0x38 */ uint64_t s_last_cno; |
| 47 | /* 0x40 */ uint64_t s_last_pseg; |
| 48 | /* 0x48 */ uint64_t s_last_seq; |
| 49 | /* 0x50 */ uint64_t s_free_blocks_count; |
| 50 | /* 0x58 */ uint64_t s_ctime; |
| 51 | /* 0x60 */ uint64_t s_mtime; |
| 52 | /* 0x68 */ uint64_t s_wtime; |
| 53 | /* 0x70 */ uint16_t s_mnt_count; |
| 54 | /* 0x72 */ uint16_t s_max_mnt_count; |
| 55 | /* 0x74 */ uint16_t s_state; |
| 56 | /* 0x76 */ uint16_t s_errors; |
| 57 | /* 0x78 */ uint64_t s_lastcheck; |
| 58 | /* 0x80 */ uint32_t s_checkinterval; |
| 59 | /* 0x84 */ uint32_t s_creator_os; |
| 60 | /* 0x88 */ uint16_t s_def_resuid; |
| 61 | /* 0x8A */ uint16_t s_def_resgid; |
| 62 | /* 0x8C */ uint32_t s_first_ino; |
| 63 | /* 0x90 */ uint16_t s_inode_size; |
| 64 | /* 0x92 */ uint16_t s_dat_entry_size; |
| 65 | /* 0x94 */ uint16_t s_checkpoint_size; |
| 66 | /* 0x96 */ uint16_t s_segment_usage_size; |
| 67 | /* 0x98 */ uint8_t s_uuid[NILFS_UUID_SIZE]; // 128-bit UUID for volume. |
| 68 | /* 0xA8 */ uint8_t s_volume_name[NILFS_LABEL_SIZE]; // Volume label. |
| 69 | /* 0xF8 */ // ... |
| 70 | } PACKED; |
| 71 | |
| 72 | int FAST_FUNC volume_id_probe_nilfs(struct volume_id *id /*,uint64_t off*/) |
| 73 | { |
| 74 | struct nilfs2_super_block *sb; |
| 75 | |
| 76 | // Primary super block |
| 77 | dbg("nilfs: probing at offset 0x%x", NILFS_SB1_OFFSET); |
| 78 | |
| 79 | sb = volume_id_get_buffer(id, NILFS_SB1_OFFSET, sizeof(*sb)); |
| 80 | |
| 81 | if (sb == NULL) |
| 82 | return -1; |
| 83 | |
| 84 | if (sb->s_magic != NILFS_MAGIC) |
| 85 | return -1; |
| 86 | |
| 87 | // The secondary superblock is not always used, so ignore it for now. |
| 88 | // When used it is at 4K from the end of the partition (sb->s_dev_size - NILFS_SB2_OFFSET). |
| 89 | |
| 90 | volume_id_set_label_string(id, sb->s_volume_name, NILFS_LABEL_SIZE < VOLUME_ID_LABEL_SIZE ? |
Denys Vlasenko | 60cb48c | 2013-01-14 15:57:44 +0100 | [diff] [blame] | 91 | NILFS_LABEL_SIZE : VOLUME_ID_LABEL_SIZE); |
Sven-Göran Bergh | c5a9fa2 | 2012-09-02 15:34:39 +0200 | [diff] [blame] | 92 | volume_id_set_uuid(id, sb->s_uuid, UUID_DCE); |
| 93 | |
| 94 | if (sb->s_rev_level == 2) |
| 95 | IF_FEATURE_BLKID_TYPE(id->type = "nilfs2"); |
| 96 | |
| 97 | return 0; |
| 98 | } |