source: mainline/uspace/lib/ext2/libext2.h@ c00e729

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since c00e729 was c00e729, checked in by Martin Sucha <sucha14@…>, 14 years ago

Support for some more superblock fields and displaying in ext2info

  • Property mode set to 100644
File size: 4.3 KB
Line 
1/*
2 * Copyright (c) 2011 Martin Sucha
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libext2
30 * @{
31 */
32/**
33 * @file
34 */
35
36#ifndef LIBEXT2_LIBEXT2_H_
37#define LIBEXT2_LIBEXT2_H_
38
39#include <byteorder.h>
40#include <libblock.h>
41
42typedef struct ext2_superblock {
43 uint8_t unused[20];
44 uint32_t first_block; // Block containing the superblock (either 0 or 1)
45 uint32_t block_size_log2; // log_2(block_size)
46 int32_t fragment_size_log2; // log_2(fragment size)
47 uint32_t blocks_per_group; // Number of blocks in one block group
48 uint32_t fragments_per_group; // Number of fragments per block group
49 uint32_t inodes_per_group; // Number of inodes per block group
50 uint8_t unused2[12];
51 uint16_t magic; // Magic value
52 uint16_t state; // State (mounted/unmounted)
53 uint16_t rev_minor; // Minor revision level
54 uint8_t unused3[12];
55 uint32_t creator_os;
56 uint32_t rev_major; // Major revision level
57 uint8_t unused4[8];
58
59 // Following is for ext2 revision 1 only
60 uint32_t first_inode;
61 uint16_t inode_size;
62 uint8_t unused5[14];
63 uint8_t uuid[16]; // UUID TODO: Create a library for UUIDs
64 uint8_t volume_name[16];
65
66// TODO: add __attribute__((aligned(...)) for better performance?
67// (it is necessary to ensure the superblock is correctly aligned then
68// though)
69} __attribute__ ((packed)) ext2_superblock_t;
70
71
72typedef struct ext2_filesystem {
73 devmap_handle_t device;
74 ext2_superblock_t * superblock;
75} ext2_filesystem_t;
76
77#define EXT2_SUPERBLOCK_MAGIC 0xEF53
78#define EXT2_SUPERBLOCK_SIZE 1024
79#define EXT2_SUPERBLOCK_OFFSET 1024
80#define EXT2_SUPERBLOCK_LAST_BYTE (EXT2_SUPERBLOCK_OFFSET + \
81 EXT2_SUPERBLOCK_SIZE -1)
82// allow maximum this block size
83#define EXT2_MAX_BLOCK_SIZE 8096
84#define EXT2_REV0_FIRST_INODE 11
85#define EXT2_REV0_INODE_SIZE 128
86
87inline uint16_t ext2_superblock_get_magic(ext2_superblock_t *);
88inline uint32_t ext2_superblock_get_first_block(ext2_superblock_t *);
89inline uint32_t ext2_superblock_get_block_size_log2(ext2_superblock_t *);
90inline uint32_t ext2_superblock_get_block_size(ext2_superblock_t *);
91inline int32_t ext2_superblock_get_fragment_size_log2(ext2_superblock_t *);
92inline uint32_t ext2_superblock_get_fragment_size(ext2_superblock_t *);
93inline uint32_t ext2_superblock_get_blocks_per_group(ext2_superblock_t *);
94inline uint32_t ext2_superblock_get_fragments_per_group(ext2_superblock_t *);
95inline uint16_t ext2_superblock_get_state(ext2_superblock_t *);
96inline uint16_t ext2_superblock_get_rev_minor(ext2_superblock_t *);
97inline uint32_t ext2_superblock_get_rev_major(ext2_superblock_t *);
98inline uint32_t ext2_superblock_get_creator_os(ext2_superblock_t *);
99inline uint32_t ext2_superblock_get_first_inode(ext2_superblock_t *);
100inline uint16_t ext2_superblock_get_inode_size(ext2_superblock_t *);
101
102extern int ext2_superblock_read_direct(devmap_handle_t, ext2_superblock_t **);
103
104extern int ext2_filesystem_init(ext2_filesystem_t *, devmap_handle_t);
105extern void ext2_filesystem_fini(ext2_filesystem_t *);
106
107#endif
108
109/** @}
110 */
Note: See TracBrowser for help on using the repository browser.