Implement fs::file::get_id()

File descripor ID with 2 provided ways to compare between them:
1. is_mirror_of():
 Test if identical:
  For example: when LHS writes one byte to a file at X offset, RHS file be able to read that exact byte at X offset)

2. is_coherent_with():
 Test if both files point to the same file:
  For example: if a file descriptor pointing to the complete file exists and is being truncated to 0 bytes from non-
  -zero size state: this has to affect both RHS and LHS files.
This commit is contained in:
Eladash 2021-09-21 16:17:45 +03:00 committed by Elad Ashkenazi
parent e27e6c0b2d
commit eecadab387
4 changed files with 152 additions and 0 deletions

View file

@ -84,6 +84,16 @@ namespace fs
usz iov_len;
};
struct file_id
{
std::string type;
std::vector<u8> data;
explicit operator bool() const;
bool is_mirror_of(const file_id&) const;
bool is_coherent_with(const file_id&) const;
};
// File handle base
struct file_base
{
@ -98,6 +108,7 @@ namespace fs
virtual u64 seek(s64 offset, seek_mode whence) = 0;
virtual u64 size() = 0;
virtual native_handle get_handle();
virtual file_id get_id();
virtual u64 write_gather(const iovec_clone* buffers, u64 buf_count);
};
@ -505,6 +516,9 @@ namespace fs
// Get native handle if available
native_handle get_handle() const;
// Get file ID information (custom ID)
file_id get_id() const;
// Gathered write
u64 write_gather(const iovec_clone* buffers, u64 buf_count,
u32 line = __builtin_LINE(),