Skip to content

Commit

Permalink
No more write at the end of file for resizing
Browse files Browse the repository at this point in the history
May solve the delay problem of copying large files on Windows
  • Loading branch information
netheril96 committed Nov 14, 2017
1 parent 51171d5 commit 351cb13
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 19 deletions.
5 changes: 3 additions & 2 deletions sources/btree_dir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,9 @@ bool BtreeDirectory::validate_node(const BtreeNode* n, int depth)
return false;
if (!std::is_sorted(n->entries().begin(), n->entries().end()))
return false;
if (n->parent_page_number() != INVALID_PAGE && (n->entries().size() < BTREE_MAX_NUM_ENTRIES / 2
|| n->entries().size() > BTREE_MAX_NUM_ENTRIES))
if (n->parent_page_number() != INVALID_PAGE
&& (n->entries().size() < BTREE_MAX_NUM_ENTRIES / 2
|| n->entries().size() > BTREE_MAX_NUM_ENTRIES))
return false;
if (!n->is_leaf())
{
Expand Down
4 changes: 1 addition & 3 deletions sources/btree_dir.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ const int BTREE_MAX_DEPTH = 32;
const int BTREE_MAX_NUM_ENTRIES = 13;

static_assert(BTREE_MAX_NUM_ENTRIES * (Directory::MAX_FILENAME_LENGTH + 1 + ID_LENGTH + 4)
+ (BTREE_MAX_NUM_ENTRIES + 1) * 4
+ 4
+ 4
+ (BTREE_MAX_NUM_ENTRIES + 1) * 4 + 4 + 4
<= BLOCK_SIZE,
"A btree node may not fit in a single block");

Expand Down
6 changes: 3 additions & 3 deletions sources/file_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ class FileTableIOVersion1 : public FileTableIO
first_level_dir = securefs::hexify(id.data(), FIRST_LEVEL);
second_level_dir
= first_level_dir + '/' + securefs::hexify(id.data() + FIRST_LEVEL, SECOND_LEVEL);
full_filename
= second_level_dir + '/' + securefs::hexify(id.data() + FIRST_LEVEL + SECOND_LEVEL,
id.size() - FIRST_LEVEL - SECOND_LEVEL);
full_filename = second_level_dir + '/'
+ securefs::hexify(id.data() + FIRST_LEVEL + SECOND_LEVEL,
id.size() - FIRST_LEVEL - SECOND_LEVEL);
meta_filename = full_filename + ".meta";
}

Expand Down
2 changes: 1 addition & 1 deletion sources/operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ namespace operations
struct fuse_stat st;
memset(&st, 0, sizeof(st));
auto actions = [&st, filler, fs, buffer](
const std::string& name, const id_type&, int type) -> bool {
const std::string& name, const id_type&, int type) -> bool {
st.st_mode = FileBase::mode_for_type(type);
bool success = filler(buffer, name.c_str(), &st, 0) == 0;
if (!success)
Expand Down
16 changes: 7 additions & 9 deletions sources/streams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,6 @@ void BlockBasedStream::unchecked_resize(length_type current_size, length_type ne
else
{
zero_fill(current_size, old_block_num * m_block_size + m_block_size);
// No need to encrypt zeros in the middle
zero_fill(new_block_num * m_block_size, new_size);
}
}
adjust_logical_size(new_size);
Expand Down Expand Up @@ -445,17 +443,17 @@ namespace internal
throw MessageVerificationException(id(), block_number * m_block_size);
}

public:
bool is_sparse() const noexcept override
void adjust_logical_size(length_type length) override
{
return m_stream->is_sparse() && m_metastream.is_sparse();
CryptStream::adjust_logical_size(length);
auto block_num = (length + this->m_block_size - 1) / this->m_block_size;
m_metastream.resize(meta_position_for_iv(block_num));
}

void resize(length_type new_size) override
public:
bool is_sparse() const noexcept override
{
CryptStream::resize(new_size);
auto num_blocks = (new_size + m_block_size - 1) / m_block_size;
m_metastream.resize(meta_position_for_iv(num_blocks));
return m_stream->is_sparse() && m_metastream.is_sparse();
}

void flush() override
Expand Down
3 changes: 2 additions & 1 deletion sources/streams.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,11 @@ class CryptStream : public BlockBasedStream
decrypt(offset_type block_number, const void* input, void* output, length_type length)
= 0;

void adjust_logical_size(length_type length) override { m_stream->resize(length); }

private:
length_type read_block(offset_type block_number, void* output) override;
void write_block(offset_type block_number, const void* input, length_type length) override;
void adjust_logical_size(length_type length) override { m_stream->resize(length); }

public:
explicit CryptStream(std::shared_ptr<StreamBase> stream, length_type block_size)
Expand Down

0 comments on commit 351cb13

Please sign in to comment.