| 1 | /*
|
|---|
| 2 | * Copyright (c) 2011 Martin Sucha
|
|---|
| 3 | * Copyright (c) 2010 Jiri Svoboda
|
|---|
| 4 | * All rights reserved.
|
|---|
| 5 | *
|
|---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 7 | * modification, are permitted provided that the following conditions
|
|---|
| 8 | * are met:
|
|---|
| 9 | *
|
|---|
| 10 | * - Redistributions of source code must retain the above copyright
|
|---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 14 | * documentation and/or other materials provided with the distribution.
|
|---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 16 | * derived from this software without specific prior written permission.
|
|---|
| 17 | *
|
|---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 28 | */
|
|---|
| 29 |
|
|---|
| 30 | /** @addtogroup fs
|
|---|
| 31 | * @{
|
|---|
| 32 | */
|
|---|
| 33 |
|
|---|
| 34 | /**
|
|---|
| 35 | * @file ext2info.c
|
|---|
| 36 | * @brief Tool for displaying information about ext2 filesystem
|
|---|
| 37 | *
|
|---|
| 38 | */
|
|---|
| 39 |
|
|---|
| 40 | #include <stdio.h>
|
|---|
| 41 | #include <stdlib.h>
|
|---|
| 42 | #include <libblock.h>
|
|---|
| 43 | #include <mem.h>
|
|---|
| 44 | #include <devmap.h>
|
|---|
| 45 | #include <byteorder.h>
|
|---|
| 46 | #include <sys/types.h>
|
|---|
| 47 | #include <sys/typefmt.h>
|
|---|
| 48 | #include <inttypes.h>
|
|---|
| 49 | #include <errno.h>
|
|---|
| 50 | #include <libext2.h>
|
|---|
| 51 |
|
|---|
| 52 | #define NAME "ext2info"
|
|---|
| 53 |
|
|---|
| 54 | static void syntax_print(void);
|
|---|
| 55 |
|
|---|
| 56 | int main(int argc, char **argv)
|
|---|
| 57 | {
|
|---|
| 58 |
|
|---|
| 59 | int rc;
|
|---|
| 60 | char *dev_path;
|
|---|
| 61 | devmap_handle_t handle;
|
|---|
| 62 | ext2_superblock_t *superblock;
|
|---|
| 63 |
|
|---|
| 64 | uint16_t magic;
|
|---|
| 65 |
|
|---|
| 66 | if (argc < 2) {
|
|---|
| 67 | printf(NAME ": Error, argument missing.\n");
|
|---|
| 68 | syntax_print();
|
|---|
| 69 | return 1;
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | --argc; ++argv;
|
|---|
| 73 |
|
|---|
| 74 | if (argc != 1) {
|
|---|
| 75 | printf(NAME ": Error, unexpected argument.\n");
|
|---|
| 76 | syntax_print();
|
|---|
| 77 | return 1;
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | dev_path = *argv;
|
|---|
| 81 |
|
|---|
| 82 | rc = devmap_device_get_handle(dev_path, &handle, 0);
|
|---|
| 83 | if (rc != EOK) {
|
|---|
| 84 | printf(NAME ": Error resolving device `%s'.\n", dev_path);
|
|---|
| 85 | return 2;
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | rc = block_init(handle, 2048);
|
|---|
| 89 | if (rc != EOK) {
|
|---|
| 90 | printf(NAME ": Error initializing libblock.\n");
|
|---|
| 91 | return 2;
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | rc = ext2_superblock_read_direct(handle, &superblock);
|
|---|
| 95 | if (rc != EOK) {
|
|---|
| 96 | printf(NAME ": Error reading superblock.\n");
|
|---|
| 97 | return 3;
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | printf("Superblock:\n");
|
|---|
| 101 | magic = ext2_superblock_get_magic(superblock);
|
|---|
| 102 | if (magic == EXT2_SUPERBLOCK_MAGIC) {
|
|---|
| 103 | printf(" Magic value: %X (correct)\n", magic);
|
|---|
| 104 | }
|
|---|
| 105 | else {
|
|---|
| 106 | printf(" Magic value: %X (incorrect)\n", magic);
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 | free(superblock);
|
|---|
| 111 |
|
|---|
| 112 | block_fini(handle);
|
|---|
| 113 |
|
|---|
| 114 | return 0;
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 | static void syntax_print(void)
|
|---|
| 119 | {
|
|---|
| 120 | printf("syntax: blkdump [--offset <num_blocks>] [--count <num_blocks>] <device_name>\n");
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | /**
|
|---|
| 124 | * @}
|
|---|
| 125 | */
|
|---|