btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / bin / bfs_tools / lib / Disk.h
blob19d9ea69a8601a844c6ce887861d6f7fd74e5630
1 #ifndef DISK_H
2 #define DISK_H
3 /* Disk - handles BFS superblock, disk access etc.
4 **
5 ** Copyright (c) 2001-2003 pinc Software. All Rights Reserved.
6 ** Released under the terms of the MIT license.
7 */
10 #include <BufferIO.h>
11 #include <File.h>
12 #include <Path.h>
14 #include <string.h>
16 #include "Bitmap.h"
17 #include "bfs.h"
18 #include "Cache.h"
21 class Disk;
23 class BlockRunCache : public Cache<block_run>
25 public:
26 BlockRunCache(Disk *disk);
27 // ~BlockRunCache();
29 virtual Cacheable *NewCacheable(block_run run);
31 protected:
32 Disk *fDisk;
36 class Disk : public BPositionIO
38 public:
39 Disk(const char *device, bool rawMode = false, off_t start = 0, off_t stop = -1);
40 virtual ~Disk();
42 status_t InitCheck();
43 const BPath &Path() const { return fPath; }
45 off_t Size() const { return fSize; }
46 off_t NumBlocks() const { return fSuperBlock.num_blocks; }
47 uint32 BlockSize() const { return fSuperBlock.block_size; }
48 uint32 BlockShift() const { return fSuperBlock.block_shift; }
49 uint32 AllocationGroups() const { return fSuperBlock.num_ags; }
50 uint32 AllocationGroupShift() const { return fSuperBlock.ag_shift; }
51 uint32 BitmapSize() const { return fBitmap.Size(); }
52 off_t LogSize() const;
54 disk_super_block *SuperBlock() { return &fSuperBlock; }
55 block_run Root() const { return fSuperBlock.root_dir; }
56 block_run Indices() const { return fSuperBlock.indices; }
57 block_run Log() const { return fSuperBlock.log_blocks; }
58 Bitmap *BlockBitmap() { return &fBitmap; }
60 const char *Name() const { return fSuperBlock.name; }
61 void SetName(const char *name) { strcpy(fSuperBlock.name,name); }
63 off_t ToOffset(block_run run) const { return ToBlock(run) << fSuperBlock.block_shift; }
64 off_t ToBlock(block_run run) const { return ((((off_t)run.allocation_group) << fSuperBlock.ag_shift) | (off_t)run.start); }
65 block_run ToBlockRun(off_t start,int16 length = 1) const;
67 uint8 *ReadBlockRun(block_run run);
69 status_t ScanForSuperBlock(off_t start = 0,off_t stop = -1);
70 status_t ValidateSuperBlock();
71 status_t RecreateSuperBlock();
73 status_t DumpBootBlockToFile();
75 // BPositionIO methods
76 virtual ssize_t Read(void *buffer, size_t size);
77 virtual ssize_t Write(const void *buffer, size_t size);
79 virtual ssize_t ReadAt(off_t pos, void *buffer, size_t size);
80 virtual ssize_t WriteAt(off_t pos, const void *buffer, size_t size);
82 virtual off_t Seek(off_t position, uint32 seek_mode);
83 virtual off_t Position() const;
85 virtual status_t SetSize(off_t size);
87 protected:
88 status_t GetNextSpecialInode(char *,off_t *,off_t,bool);
89 void SaveInode(bfs_inode *,bool *,bfs_inode *,bool *,bfs_inode *);
90 status_t ScanForIndexAndRoot(bfs_inode *,bfs_inode *);
91 status_t DetermineBlockSize();
92 status_t ValidateSuperBlock(disk_super_block &superBlock);
94 status_t LoadBootBlock();
96 protected:
97 BFile fFile;
98 BBufferIO* fBufferedFile;
99 BPath fPath;
100 off_t fRawDiskOffset;
101 off_t fSize;
102 disk_super_block fSuperBlock;
103 Bitmap fBitmap;
105 block_run fValidBlockRun;
106 off_t fValidOffset;
107 off_t fLogStart;
109 BlockRunCache fCache;
111 bool fRawMode;
114 #endif /* DISK_H */