mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-12-29 01:06:27 -05:00
File: Widen size/offset types for 64-bit filesystems.
This commit is contained in:
parent
f7bfde73b6
commit
ed791ac5bd
@ -35,7 +35,7 @@
|
||||
|
||||
class Writer {
|
||||
public:
|
||||
virtual File::Result<size_t> write(const void* const buffer, const size_t bytes) = 0;
|
||||
virtual File::Result<File::Size> write(const void* const buffer, const File::Size bytes) = 0;
|
||||
virtual ~Writer() = default;
|
||||
};
|
||||
|
||||
|
@ -64,7 +64,7 @@ File::~File() {
|
||||
f_close(&f);
|
||||
}
|
||||
|
||||
File::Result<size_t> File::read(void* const data, const size_t bytes_to_read) {
|
||||
File::Result<File::Size> File::read(void* const data, const Size bytes_to_read) {
|
||||
UINT bytes_read = 0;
|
||||
const auto result = f_read(&f, data, bytes_to_read, &bytes_read);
|
||||
if( result == FR_OK ) {
|
||||
@ -74,12 +74,12 @@ File::Result<size_t> File::read(void* const data, const size_t bytes_to_read) {
|
||||
}
|
||||
}
|
||||
|
||||
File::Result<size_t> File::write(const void* const data, const size_t bytes_to_write) {
|
||||
File::Result<File::Size> File::write(const void* const data, const Size bytes_to_write) {
|
||||
UINT bytes_written = 0;
|
||||
const auto result = f_write(&f, data, bytes_to_write, &bytes_written);
|
||||
if( result == FR_OK ) {
|
||||
if( bytes_to_write == bytes_written ) {
|
||||
return { static_cast<size_t>(bytes_written) };
|
||||
return { static_cast<File::Size>(bytes_written) };
|
||||
} else {
|
||||
return Error { FR_DISK_FULL };
|
||||
}
|
||||
@ -88,7 +88,7 @@ File::Result<size_t> File::write(const void* const data, const size_t bytes_to_w
|
||||
}
|
||||
}
|
||||
|
||||
File::Result<uint64_t> File::seek(const uint64_t new_position) {
|
||||
File::Result<File::Offset> File::seek(const Offset new_position) {
|
||||
/* NOTE: Returns *old* position, not new position */
|
||||
const auto old_position = f_tell(&f);
|
||||
const auto result = f_lseek(&f, new_position);
|
||||
@ -98,7 +98,7 @@ File::Result<uint64_t> File::seek(const uint64_t new_position) {
|
||||
if( f_tell(&f) != new_position ) {
|
||||
return { static_cast<Error>(FR_BAD_SEEK) };
|
||||
}
|
||||
return { static_cast<uint64_t>(old_position) };
|
||||
return { static_cast<File::Offset>(old_position) };
|
||||
}
|
||||
|
||||
Optional<File::Error> File::write_line(const std::string& s) {
|
||||
|
@ -136,6 +136,8 @@ std::filesystem::path next_filename_stem_matching_pattern(const std::filesystem:
|
||||
|
||||
class File {
|
||||
public:
|
||||
using Size = uint64_t;
|
||||
using Offset = uint64_t;
|
||||
using Error = std::filesystem::filesystem_error;
|
||||
|
||||
template<typename T>
|
||||
@ -200,13 +202,13 @@ public:
|
||||
Optional<Error> append(const std::filesystem::path& filename);
|
||||
Optional<Error> create(const std::filesystem::path& filename);
|
||||
|
||||
Result<size_t> read(void* const data, const size_t bytes_to_read);
|
||||
Result<size_t> write(const void* const data, const size_t bytes_to_write);
|
||||
Result<Size> read(void* const data, const Size bytes_to_read);
|
||||
Result<Size> write(const void* const data, const Size bytes_to_write);
|
||||
|
||||
Result<uint64_t> seek(const uint64_t new_position);
|
||||
Result<Offset> seek(const uint64_t Offset);
|
||||
|
||||
template<size_t N>
|
||||
Result<size_t> write(const std::array<uint8_t, N>& data) {
|
||||
Result<Size> write(const std::array<uint8_t, N>& data) {
|
||||
return write(data.data(), N);
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ public:
|
||||
return file.create(filename);
|
||||
}
|
||||
|
||||
File::Result<size_t> write(const void* const buffer, const size_t bytes) override {
|
||||
File::Result<File::Size> write(const void* const buffer, const File::Size bytes) override {
|
||||
auto write_result = file.write(buffer, bytes) ;
|
||||
if( write_result.is_ok() ) {
|
||||
bytes_written += write_result.value();
|
||||
|
@ -51,13 +51,13 @@ public:
|
||||
halrtcnt_t write_duration_min { 0 };
|
||||
halrtcnt_t write_duration_max { 0 };
|
||||
halrtcnt_t write_test_duration { 0 };
|
||||
size_t write_bytes { 0 };
|
||||
File::Size write_bytes { 0 };
|
||||
size_t write_count { 0 };
|
||||
|
||||
halrtcnt_t read_duration_min { 0 };
|
||||
halrtcnt_t read_duration_max { 0 };
|
||||
halrtcnt_t read_test_duration { 0 };
|
||||
size_t read_bytes { 0 };
|
||||
File::Size read_bytes { 0 };
|
||||
size_t read_count { 0 };
|
||||
};
|
||||
|
||||
@ -80,9 +80,9 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
static constexpr size_t write_size = 16384;
|
||||
static constexpr size_t bytes_to_write = 16 * 1024 * 1024;
|
||||
static constexpr size_t bytes_to_read = bytes_to_write;
|
||||
static constexpr File::Size write_size = 16384;
|
||||
static constexpr File::Size bytes_to_write = 16 * 1024 * 1024;
|
||||
static constexpr File::Size bytes_to_read = bytes_to_write;
|
||||
|
||||
static Thread* thread;
|
||||
volatile Result _result { Result::Incomplete };
|
||||
@ -365,7 +365,7 @@ static std::string format_ticks_as_ms(const halrtcnt_t value) {
|
||||
return format_3dot3_string(us);
|
||||
}
|
||||
|
||||
static std::string format_bytes_per_ticks_as_mib(const size_t bytes, const halrtcnt_t ticks) {
|
||||
static std::string format_bytes_per_ticks_as_mib(const File::Size bytes, const halrtcnt_t ticks) {
|
||||
const uint32_t bps = uint64_t(bytes) * halGetCounterFrequency() / ticks;
|
||||
const uint32_t kbps = bps / 1000U;
|
||||
return format_3dot3_string(kbps);
|
||||
|
Loading…
Reference in New Issue
Block a user