# HG changeset patch # User Paul Boddie # Date 1627598724 -7200 # Node ID efaffd8182eeb054b64cb9f7a0e8b77c8ff5e1ec # Parent 40729d5e6af2937595431f604721e50a56b7bbf6 Introduced locking around filesystem operations. diff -r 40729d5e6af2 -r efaffd8182ee libfsserver/include/fsserver/ext2_file_operations.h --- a/libfsserver/include/fsserver/ext2_file_operations.h Fri Jul 30 00:20:35 2021 +0200 +++ b/libfsserver/include/fsserver/ext2_file_operations.h Fri Jul 30 00:45:24 2021 +0200 @@ -21,6 +21,8 @@ #pragma once +#include + #include #include @@ -33,6 +35,7 @@ class Ext2FileOperations { protected: + std::mutex _lock; ext2_filsys _fs; public: diff -r 40729d5e6af2 -r efaffd8182ee libfsserver/lib/files/ext2_file_operations.cc --- a/libfsserver/lib/files/ext2_file_operations.cc Fri Jul 30 00:20:35 2021 +0200 +++ b/libfsserver/lib/files/ext2_file_operations.cc Fri Jul 30 00:45:24 2021 +0200 @@ -34,6 +34,8 @@ if (!path_is_leafname(filename)) return -L4_EINVAL; + std::lock_guard guard(_lock); + struct ext2_inode inode_parent; errcode_t retval = ext2fs_read_inode(_fs, ino_parent, &inode_parent); @@ -56,6 +58,8 @@ long Ext2FileOperations::find_file(const char *path, ext2_ino_t *ino, const char **remaining) { + std::lock_guard guard(_lock); + *remaining = path; errcode_t retval = image_find_path(_fs, remaining, ino); @@ -71,6 +75,8 @@ void Ext2FileOperations::close_file(ext2_file_t file) { + std::lock_guard guard(_lock); + ext2fs_file_flush(file); ext2fs_file_close(file); } @@ -79,6 +85,8 @@ long Ext2FileOperations::open_file(ext2_ino_t ino, ext2_file_t *file) { + std::lock_guard guard(_lock); + errcode_t retval = ext2fs_file_open(_fs, ino, EXT2_FILE_WRITE, file); // NOTE: Map error conditions. @@ -93,6 +101,8 @@ offset_t Ext2FileOperations::get_size(ext2_file_t file) { + std::lock_guard guard(_lock); + return ext2fs_file_get_size(file); } @@ -100,6 +110,8 @@ void Ext2FileOperations::set_size(ext2_file_t file, offset_t size) { + std::lock_guard guard(_lock); + ext2fs_file_set_size(file, size); } @@ -107,6 +119,8 @@ offset_t Ext2FileOperations::read_file(ext2_file_t file, offset_t filepos, void *addr, offset_t size) { + std::lock_guard guard(_lock); + unsigned int nread; ext2fs_file_llseek(file, filepos, SEEK_SET, NULL); @@ -119,6 +133,8 @@ void Ext2FileOperations::write_file(ext2_file_t file, offset_t filepos, const void *addr, offset_t size) { + std::lock_guard guard(_lock); + ext2fs_file_llseek(file, filepos, SEEK_SET, NULL); ext2fs_file_write(file, addr, size, NULL); }