[Kernel] Add support for XFileEndOfFileInformation.
This commit is contained in:
@@ -88,6 +88,9 @@ class FileHandle {
|
||||
virtual bool Write(size_t file_offset, const void* buffer,
|
||||
size_t buffer_length, size_t* out_bytes_written) = 0;
|
||||
|
||||
// Set length of the file in bytes.
|
||||
virtual bool SetLength(size_t length) = 0;
|
||||
|
||||
// Flushes any pending write buffers to the underlying filesystem.
|
||||
virtual void Flush() = 0;
|
||||
|
||||
|
||||
@@ -99,6 +99,9 @@ class PosixFileHandle : public FileHandle {
|
||||
*out_bytes_written = out;
|
||||
return out >= 0 ? true : false;
|
||||
}
|
||||
bool SetLength(size_t length) override {
|
||||
return ftruncate(handle_, length) >= 0 ? true : false;
|
||||
}
|
||||
void Flush() override { fsync(handle_); }
|
||||
|
||||
private:
|
||||
|
||||
@@ -115,6 +115,17 @@ class Win32FileHandle : public FileHandle {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
bool SetLength(size_t length) {
|
||||
LARGE_INTEGER position;
|
||||
position.QuadPart = length;
|
||||
if (!SetFilePointerEx(handle_, position, nullptr, SEEK_SET)) {
|
||||
return false;
|
||||
}
|
||||
if (!SetEndOfFile(handle_)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
void Flush() override { FlushFileBuffers(handle_); }
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user