1 // Copyright 2017 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // This file includes necessary methods for checking the consistency
6 // of a MinFS filesystem.
7 
8 #pragma once
9 
10 #include <inttypes.h>
11 
12 #include <minfs/bcache.h>
13 #include <minfs/format.h>
14 #include <fbl/array.h>
15 #include <fbl/unique_ptr.h>
16 #include <fbl/vector.h>
17 #include <fs/trace.h>
18 
19 namespace minfs {
20 
21 // Validate header information about the filesystem backed by |bc|.
22 zx_status_t CheckSuperblock(const Superblock* info, Bcache* bc);
23 
24 // Run fsck on an unmounted filesystem backed by |bc|.
25 //
26 // Invokes CheckSuperblock, but also verifies inode and block usage.
27 zx_status_t Fsck(fbl::unique_ptr<Bcache> bc);
28 
29 #ifndef __Fuchsia__
30 // Run fsck on a sparse minfs partition
31 // |start| indicates where the minfs partition starts within the file (in bytes)
32 // |end| indicates the end of the minfs partition (in bytes)
33 // |extent_lengths| contains the length (in bytes) of each minfs extent: currently this includes
34 // the superblock, inode bitmap, block bitmap, inode table, and data blocks.
35 zx_status_t SparseFsck(fbl::unique_fd fd, off_t start, off_t end,
36                        const fbl::Vector<size_t>& extent_lengths);
37 #endif
38 } // namespace minfs
39