1.1 --- a/libfsserver/include/fsserver/ext2_file_operations.h Fri Jul 30 00:20:35 2021 +0200
1.2 +++ b/libfsserver/include/fsserver/ext2_file_operations.h Fri Jul 30 00:45:24 2021 +0200
1.3 @@ -21,6 +21,8 @@
1.4
1.5 #pragma once
1.6
1.7 +#include <mutex>
1.8 +
1.9 #include <ext2fs/ext2fs.h>
1.10
1.11 #include <systypes/base.h>
1.12 @@ -33,6 +35,7 @@
1.13 class Ext2FileOperations
1.14 {
1.15 protected:
1.16 + std::mutex _lock;
1.17 ext2_filsys _fs;
1.18
1.19 public:
2.1 --- a/libfsserver/lib/files/ext2_file_operations.cc Fri Jul 30 00:20:35 2021 +0200
2.2 +++ b/libfsserver/lib/files/ext2_file_operations.cc Fri Jul 30 00:45:24 2021 +0200
2.3 @@ -34,6 +34,8 @@
2.4 if (!path_is_leafname(filename))
2.5 return -L4_EINVAL;
2.6
2.7 + std::lock_guard<std::mutex> guard(_lock);
2.8 +
2.9 struct ext2_inode inode_parent;
2.10 errcode_t retval = ext2fs_read_inode(_fs, ino_parent, &inode_parent);
2.11
2.12 @@ -56,6 +58,8 @@
2.13 long Ext2FileOperations::find_file(const char *path, ext2_ino_t *ino,
2.14 const char **remaining)
2.15 {
2.16 + std::lock_guard<std::mutex> guard(_lock);
2.17 +
2.18 *remaining = path;
2.19 errcode_t retval = image_find_path(_fs, remaining, ino);
2.20
2.21 @@ -71,6 +75,8 @@
2.22
2.23 void Ext2FileOperations::close_file(ext2_file_t file)
2.24 {
2.25 + std::lock_guard<std::mutex> guard(_lock);
2.26 +
2.27 ext2fs_file_flush(file);
2.28 ext2fs_file_close(file);
2.29 }
2.30 @@ -79,6 +85,8 @@
2.31
2.32 long Ext2FileOperations::open_file(ext2_ino_t ino, ext2_file_t *file)
2.33 {
2.34 + std::lock_guard<std::mutex> guard(_lock);
2.35 +
2.36 errcode_t retval = ext2fs_file_open(_fs, ino, EXT2_FILE_WRITE, file);
2.37
2.38 // NOTE: Map error conditions.
2.39 @@ -93,6 +101,8 @@
2.40
2.41 offset_t Ext2FileOperations::get_size(ext2_file_t file)
2.42 {
2.43 + std::lock_guard<std::mutex> guard(_lock);
2.44 +
2.45 return ext2fs_file_get_size(file);
2.46 }
2.47
2.48 @@ -100,6 +110,8 @@
2.49
2.50 void Ext2FileOperations::set_size(ext2_file_t file, offset_t size)
2.51 {
2.52 + std::lock_guard<std::mutex> guard(_lock);
2.53 +
2.54 ext2fs_file_set_size(file, size);
2.55 }
2.56
2.57 @@ -107,6 +119,8 @@
2.58
2.59 offset_t Ext2FileOperations::read_file(ext2_file_t file, offset_t filepos, void *addr, offset_t size)
2.60 {
2.61 + std::lock_guard<std::mutex> guard(_lock);
2.62 +
2.63 unsigned int nread;
2.64
2.65 ext2fs_file_llseek(file, filepos, SEEK_SET, NULL);
2.66 @@ -119,6 +133,8 @@
2.67
2.68 void Ext2FileOperations::write_file(ext2_file_t file, offset_t filepos, const void *addr, offset_t size)
2.69 {
2.70 + std::lock_guard<std::mutex> guard(_lock);
2.71 +
2.72 ext2fs_file_llseek(file, filepos, SEEK_SET, NULL);
2.73 ext2fs_file_write(file, addr, size, NULL);
2.74 }