Skip to content

Commit

Permalink
file_vault: re-enable support for 32-bit platforms
Browse files Browse the repository at this point in the history
Ref #5148
  • Loading branch information
m-stein committed Mar 27, 2024
1 parent 4c42f80 commit ab50b9d
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 45 deletions.
2 changes: 1 addition & 1 deletion repos/gems/run/tresor_tester.run
Expand Up @@ -47,7 +47,7 @@ proc block_io_vfs_ram_mb { } {
return [expr 8 * $bench_mb]
}
# when benchmarks turned off
return 10
return 36
}

proc jent_avail { } {
Expand Down
38 changes: 19 additions & 19 deletions repos/gems/src/app/file_vault/main.cc
Expand Up @@ -628,22 +628,22 @@ class File_vault::Main
}
}

static Number_of_blocks _tresor_tree_num_leaves(size_t payload_size);
static Number_of_blocks _tresor_tree_num_leaves(uint64_t payload_size);


static size_t _tree_nr_of_blocks(size_t nr_of_lvls,
static uint64_t _tree_nr_of_blocks(size_t nr_of_lvls,
size_t nr_of_children,
size_t nr_of_leafs);
uint64_t nr_of_leafs);

size_t _tresor_size() const;
uint64_t _tresor_size() const;

static size_t _tresor_nr_of_blocks(size_t nr_of_superblocks,
static uint64_t _tresor_nr_of_blocks(size_t nr_of_superblocks,
size_t nr_of_vbd_lvls,
size_t nr_of_vbd_children,
size_t nr_of_vbd_leafs,
uint64_t nr_of_vbd_leafs,
size_t nr_of_ft_lvls,
size_t nr_of_ft_children,
size_t nr_of_ft_leafs);
uint64_t nr_of_ft_leafs);

template <size_t N>
static bool listing_file_starts_with(Xml_node const &fs_query_listing,
Expand Down Expand Up @@ -2361,7 +2361,7 @@ void File_vault::Main::wakeup_local_service()
}


Number_of_blocks Main::_tresor_tree_num_leaves(size_t payload_size)
Number_of_blocks Main::_tresor_tree_num_leaves(uint64_t payload_size)
{
Number_of_blocks nr_of_leaves { payload_size / TRESOR_BLOCK_SIZE };
if (payload_size % TRESOR_BLOCK_SIZE) {
Expand Down Expand Up @@ -2673,12 +2673,12 @@ void File_vault::Main::_generate_sandbox_config(Xml_generator &xml) const
}


size_t Main::_tree_nr_of_blocks(size_t nr_of_lvls,
uint64_t Main::_tree_nr_of_blocks(size_t nr_of_lvls,
size_t nr_of_children,
size_t nr_of_leafs)
uint64_t nr_of_leafs)
{
size_t nr_of_blks { 0 };
size_t nr_of_last_lvl_blks { nr_of_leafs };
uint64_t nr_of_blks { 0 };
uint64_t nr_of_last_lvl_blks { nr_of_leafs };
for (size_t lvl_idx { 0 }; lvl_idx < nr_of_lvls; lvl_idx++) {
nr_of_blks += nr_of_last_lvl_blks;
if (nr_of_last_lvl_blks % nr_of_children) {
Expand All @@ -2691,7 +2691,7 @@ size_t Main::_tree_nr_of_blocks(size_t nr_of_lvls,
}


size_t Main::_tresor_size() const
uint64_t Main::_tresor_size() const
{
return
_tresor_nr_of_blocks(
Expand All @@ -2706,21 +2706,21 @@ size_t Main::_tresor_size() const
}


size_t Main::_tresor_nr_of_blocks(size_t nr_of_superblocks,
uint64_t Main::_tresor_nr_of_blocks(size_t nr_of_superblocks,
size_t nr_of_vbd_lvls,
size_t nr_of_vbd_children,
size_t nr_of_vbd_leafs,
uint64_t nr_of_vbd_leafs,
size_t nr_of_ft_lvls,
size_t nr_of_ft_children,
size_t nr_of_ft_leafs)
uint64_t nr_of_ft_leafs)
{
size_t const nr_of_vbd_blks {
uint64_t const nr_of_vbd_blks {
_tree_nr_of_blocks(
nr_of_vbd_lvls,
nr_of_vbd_children,
nr_of_vbd_leafs) };

size_t const nr_of_ft_blks {
uint64_t const nr_of_ft_blks {
_tree_nr_of_blocks(
nr_of_ft_lvls,
nr_of_ft_children,
Expand All @@ -2741,7 +2741,7 @@ size_t Main::_tresor_nr_of_blocks(size_t nr_of_superblocks,
* nr_of_mt_children,
* nr_of_mt_leafs) };
*/
size_t const nr_of_mt_blks { nr_of_ft_blks };
uint64_t const nr_of_mt_blks { nr_of_ft_blks };

return
nr_of_superblocks +
Expand Down
2 changes: 1 addition & 1 deletion repos/gems/src/app/file_vault/sandbox.h
Expand Up @@ -470,7 +470,7 @@ namespace File_vault {
void gen_truncate_file_start_node(Xml_generator &xml,
Child_state const &child,
char const *path,
size_t size)
uint64_t size)
{
child.gen_start_node(xml, [&] () {

Expand Down
4 changes: 2 additions & 2 deletions repos/gems/src/app/tresor_tester/main.cc
Expand Up @@ -147,7 +147,7 @@ class Tresor_tester::Benchmark : Noncopyable

if (_num_virt_blks_read) {

size_t const bytes_read { _num_virt_blks_read * Tresor::BLOCK_SIZE };
uint64_t const bytes_read { _num_virt_blks_read * Tresor::BLOCK_SIZE };
double const mibyte_read { (double)bytes_read / (double)(1024 * 1024) };
double const mibyte_per_sec_read {
(double)bytes_read / (double)passed_time_sec / (double)(1024 * 1024) };
Expand All @@ -157,7 +157,7 @@ class Tresor_tester::Benchmark : Noncopyable
}
if (_num_virt_blks_written) {

size_t bytes_written { _num_virt_blks_written * Tresor::BLOCK_SIZE };
uint64_t bytes_written { _num_virt_blks_written * Tresor::BLOCK_SIZE };
double const mibyte_written { (double)bytes_written / (double)(1024 * 1024) };
double const mibyte_per_sec_written {
(double)bytes_written / (double)passed_time_sec / (double)(1024 * 1024) };
Expand Down
4 changes: 2 additions & 2 deletions repos/gems/src/lib/tresor/include/tresor/crypto.h
Expand Up @@ -98,7 +98,7 @@ class Tresor::Crypto::Encrypt : Noncopyable

Request_helper<Encrypt, State> _helper;
Attr const _attr;
off_t _offset { };
uint64_t _offset { };
Constructible<File<State> > _file { };

public:
Expand Down Expand Up @@ -132,7 +132,7 @@ class Tresor::Crypto::Decrypt : Noncopyable

Request_helper<Decrypt, State> _helper;
Attr const _attr;
off_t _offset { };
uint64_t _offset { };
Constructible<File<State> > _file { };

public:
Expand Down
2 changes: 1 addition & 1 deletion repos/gems/src/lib/tresor/include/tresor/file.h
Expand Up @@ -60,7 +60,7 @@ class Tresor::File
HOST_STATE &_host_state;
State _state { IDLE };
Vfs::Vfs_handle &_handle;
Vfs::file_size _num_processed_bytes { 0 };
size_t _num_processed_bytes { 0 };

/*
* Noncopyable
Expand Down
22 changes: 11 additions & 11 deletions repos/gems/src/lib/vfs/tresor/splitter.h
Expand Up @@ -55,7 +55,7 @@ struct Tresor::Splitter : Noncopyable

Request_helper<Read, State> _helper;
Attr const _attr;
addr_t _curr_off { };
uint64_t _curr_off { };
addr_t _curr_buf_addr { };
Block _blk { };
Generation _gen { };
Expand Down Expand Up @@ -88,16 +88,16 @@ struct Tresor::Splitter : Noncopyable
addr_t _curr_buf_off() const
{
ASSERT(_curr_off >= _attr.in_off && _curr_off <= _attr.in_off + _attr.in_buf_num_bytes);
return _curr_off - _attr.in_off;
return (addr_t)(_curr_off - _attr.in_off);
}

addr_t _num_remaining_bytes() const
{
ASSERT(_curr_off >= _attr.in_off && _curr_off <= _attr.in_off + _attr.in_buf_num_bytes);
return _attr.in_off + _attr.in_buf_num_bytes - _curr_off;
return _attr.in_buf_num_bytes - (size_t)(_curr_off - _attr.in_off);
}

void _advance_curr_off(size_t advance, bool &progress)
void _advance_curr_off(uint64_t advance, bool &progress)
{
_curr_off += advance;
if (!_num_remaining_bytes()) {
Expand Down Expand Up @@ -133,7 +133,7 @@ struct Tresor::Splitter : Noncopyable
case READ_FIRST_VBA: progress |= _execute_read(READ_FIRST_VBA_SUCCEEDED, attr); break;
case READ_FIRST_VBA_SUCCEEDED:
{
size_t num_outside_bytes { _curr_off % BLOCK_SIZE };
size_t num_outside_bytes { (size_t)(_curr_off % BLOCK_SIZE) };
size_t num_inside_bytes { min(_num_remaining_bytes(), BLOCK_SIZE - num_outside_bytes) };
memcpy(_attr.in_buf_start, (void *)((addr_t)&_blk + num_outside_bytes), num_inside_bytes);
_advance_curr_off(num_inside_bytes, progress);
Expand Down Expand Up @@ -201,7 +201,7 @@ struct Tresor::Splitter : Noncopyable

Request_helper<Write, State> _helper;
Attr const _attr;
addr_t _curr_off { };
uint64_t _curr_off { };
addr_t _curr_buf_addr { };
Block _blk { };
Generation _gen { };
Expand All @@ -213,13 +213,13 @@ struct Tresor::Splitter : Noncopyable
addr_t _curr_buf_off() const
{
ASSERT(_curr_off >= _attr.in_off && _curr_off <= _attr.in_off + _attr.in_buf_num_bytes);
return _curr_off - _attr.in_off;
return (addr_t)(_curr_off - _attr.in_off);
}

addr_t _num_remaining_bytes() const
{
ASSERT(_curr_off >= _attr.in_off && _curr_off <= _attr.in_off + _attr.in_buf_num_bytes);
return _attr.in_off + _attr.in_buf_num_bytes - _curr_off;
return _attr.in_buf_num_bytes - (size_t)(_curr_off - _attr.in_off);
}

void _generate_sb_control_request(State target_state, bool &progress)
Expand All @@ -239,7 +239,7 @@ struct Tresor::Splitter : Noncopyable
progress = true;
}

void _advance_curr_off(size_t advance, bool &progress)
void _advance_curr_off(uint64_t advance, bool &progress)
{
_curr_off += advance;
if (!_num_remaining_bytes()) {
Expand Down Expand Up @@ -299,7 +299,7 @@ struct Tresor::Splitter : Noncopyable
case READ_FIRST_VBA: progress |= _execute_read(READ_FIRST_VBA_SUCCEEDED, attr); break;
case READ_FIRST_VBA_SUCCEEDED:
{
size_t num_outside_bytes { _curr_off % BLOCK_SIZE };
size_t num_outside_bytes { (size_t)(_curr_off % BLOCK_SIZE) };
size_t num_inside_bytes { min(_num_remaining_bytes(), BLOCK_SIZE - num_outside_bytes) };
memcpy((void *)((addr_t)&_blk + num_outside_bytes), _attr.in_buf_start, num_inside_bytes);
_curr_buf_addr = (addr_t)&_blk;
Expand All @@ -309,7 +309,7 @@ struct Tresor::Splitter : Noncopyable
case WRITE_FIRST_VBA: progress |= _execute_write(WRITE_FIRST_VBA_SUCCEEDED, attr); break;
case WRITE_FIRST_VBA_SUCCEEDED:
{
size_t num_outside_bytes { _curr_off % BLOCK_SIZE };
size_t num_outside_bytes { (size_t)(_curr_off % BLOCK_SIZE) };
size_t num_inside_bytes { min(_num_remaining_bytes(), BLOCK_SIZE - num_outside_bytes) };
_advance_curr_off(num_inside_bytes, progress);
break;
Expand Down
16 changes: 8 additions & 8 deletions repos/gems/src/lib/vfs/tresor/vfs.cc
Expand Up @@ -84,26 +84,26 @@ class Vfs_tresor::Data_operation : private Noncopyable
State _state { INIT };
bool const _verbose;
Generation _generation { };
addr_t _seek { };
Vfs::file_size _seek { };
bool _success { };
Constructible<Byte_range_ptr> _dst { };
Constructible<Const_byte_range_ptr> _src { };
Constructible<Splitter::Write> _write { };
Constructible<Splitter::Read> _read { };
Constructible<Superblock_control::Synchronize> _sync { };

bool _range_violation(Superblock_control &sb_control, addr_t start, size_t num_bytes) const
bool _range_violation(Superblock_control &sb_control, uint64_t start, uint64_t num_bytes) const
{
addr_t last_byte = num_bytes ? start - 1 + num_bytes : start;
addr_t last_file_byte = (sb_control.max_vba() * BLOCK_SIZE) + (BLOCK_SIZE - 1);
uint64_t last_byte = num_bytes ? start - 1 + num_bytes : start;
uint64_t last_file_byte = (sb_control.max_vba() * BLOCK_SIZE) + (BLOCK_SIZE - 1);
return last_byte > last_file_byte;
}

public:

Data_operation(bool verbose) : _verbose(verbose) { }

Result write(addr_t seek, Const_byte_range_ptr const &src)
Result write(Vfs::file_size seek, Const_byte_range_ptr const &src)
{
switch (_state) {
case INIT:
Expand All @@ -129,7 +129,7 @@ class Vfs_tresor::Data_operation : private Noncopyable
ASSERT_NEVER_REACHED;
}

Result read(addr_t seek, Byte_range_ptr const &dst)
Result read(Vfs::file_size seek, Byte_range_ptr const &dst)
{
switch (_state) {
case INIT:
Expand Down Expand Up @@ -742,7 +742,7 @@ class Vfs_tresor::Plugin : private Noncopyable, private Client_data_interface, p

void _wakeup_back_end_services() { _vfs_env.io().commit(); }

size_t _data_file_size() const { return (_sb_control.max_vba() + 1) * BLOCK_SIZE; }
Vfs::file_size _data_file_size() const { return (_sb_control.max_vba() + 1) * BLOCK_SIZE; }

/********************************
** Crypto_key_files_interface **
Expand Down Expand Up @@ -984,7 +984,7 @@ class Vfs_tresor::Data_file_system : private Noncopyable, public Single_file_sys
Stat_result stat(char const *path, Stat &out) override
{
Stat_result result = STAT_ERR_NO_ENTRY;
_plugin.with_data_file_size([&] (size_t size) {
_plugin.with_data_file_size([&] (Vfs::file_size size) {
result = Single_file_system::stat(path, out);
out.size = size;
});
Expand Down

0 comments on commit ab50b9d

Please sign in to comment.