2 * Copyright 2008, Haiku, Inc.
3 * Distributed under the terms of the MIT License.
6 * François Revol <revol@free.fr>
10 #include "CachedBlock.h"
17 #include <util/kernel_cpp.h>
20 using namespace FATFS
;
23 CachedBlock::CachedBlock(Volume
&volume
)
32 CachedBlock::CachedBlock(Volume
&volume
, off_t block
)
42 CachedBlock::~CachedBlock()
49 CachedBlock::SetTo(off_t block
)
51 status_t error
= SetTo(block
, READ
);
52 return error
== B_OK
? fBlock
: NULL
;
57 CachedBlock::SetTo(off_t blockNumber
, uint32 flags
)
60 fBlock
= (uint8
*)malloc(BlockSize());
65 if (blockNumber
!= fBlockNumber
)
68 fBlockNumber
= blockNumber
;
70 status_t error
= B_OK
;
72 if ((flags
& READ
) != 0) {
73 if ((flags
& FORCE
) != 0) {
74 ssize_t bytesRead
= read_pos(fVolume
.Device(),
75 fBlockNumber
<< BlockShift(), fBlock
, BlockSize());
78 else if (bytesRead
< (ssize_t
)BlockSize())
81 } else if ((flags
& CLEAR
) != 0)
82 memset(fBlock
, 0, BlockSize());
97 ssize_t written
= write_pos(fVolume
.Device(), fBlockNumber
<< BlockShift(),
101 if (written
!= (ssize_t
)BlockSize())