3 /* Disk - handles BFS superblock, disk access etc.
5 ** Copyright (c) 2001-2003 pinc Software. All Rights Reserved.
6 ** Released under the terms of the MIT license.
23 class BlockRunCache
: public Cache
<block_run
>
26 BlockRunCache(Disk
*disk
);
29 virtual Cacheable
*NewCacheable(block_run run
);
36 class Disk
: public BPositionIO
39 Disk(const char *device
, bool rawMode
= false, off_t start
= 0, off_t stop
= -1);
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
);
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();
98 BBufferIO
* fBufferedFile
;
100 off_t fRawDiskOffset
;
102 disk_super_block fSuperBlock
;
105 block_run fValidBlockRun
;
109 BlockRunCache fCache
;