1.1 --- a/libfsserver/lib/files/ext2_file_operations.cc Fri Jul 30 00:20:35 2021 +0200
1.2 +++ b/libfsserver/lib/files/ext2_file_operations.cc Fri Jul 30 00:45:24 2021 +0200
1.3 @@ -34,6 +34,8 @@
1.4 if (!path_is_leafname(filename))
1.5 return -L4_EINVAL;
1.6
1.7 + std::lock_guard<std::mutex> guard(_lock);
1.8 +
1.9 struct ext2_inode inode_parent;
1.10 errcode_t retval = ext2fs_read_inode(_fs, ino_parent, &inode_parent);
1.11
1.12 @@ -56,6 +58,8 @@
1.13 long Ext2FileOperations::find_file(const char *path, ext2_ino_t *ino,
1.14 const char **remaining)
1.15 {
1.16 + std::lock_guard<std::mutex> guard(_lock);
1.17 +
1.18 *remaining = path;
1.19 errcode_t retval = image_find_path(_fs, remaining, ino);
1.20
1.21 @@ -71,6 +75,8 @@
1.22
1.23 void Ext2FileOperations::close_file(ext2_file_t file)
1.24 {
1.25 + std::lock_guard<std::mutex> guard(_lock);
1.26 +
1.27 ext2fs_file_flush(file);
1.28 ext2fs_file_close(file);
1.29 }
1.30 @@ -79,6 +85,8 @@
1.31
1.32 long Ext2FileOperations::open_file(ext2_ino_t ino, ext2_file_t *file)
1.33 {
1.34 + std::lock_guard<std::mutex> guard(_lock);
1.35 +
1.36 errcode_t retval = ext2fs_file_open(_fs, ino, EXT2_FILE_WRITE, file);
1.37
1.38 // NOTE: Map error conditions.
1.39 @@ -93,6 +101,8 @@
1.40
1.41 offset_t Ext2FileOperations::get_size(ext2_file_t file)
1.42 {
1.43 + std::lock_guard<std::mutex> guard(_lock);
1.44 +
1.45 return ext2fs_file_get_size(file);
1.46 }
1.47
1.48 @@ -100,6 +110,8 @@
1.49
1.50 void Ext2FileOperations::set_size(ext2_file_t file, offset_t size)
1.51 {
1.52 + std::lock_guard<std::mutex> guard(_lock);
1.53 +
1.54 ext2fs_file_set_size(file, size);
1.55 }
1.56
1.57 @@ -107,6 +119,8 @@
1.58
1.59 offset_t Ext2FileOperations::read_file(ext2_file_t file, offset_t filepos, void *addr, offset_t size)
1.60 {
1.61 + std::lock_guard<std::mutex> guard(_lock);
1.62 +
1.63 unsigned int nread;
1.64
1.65 ext2fs_file_llseek(file, filepos, SEEK_SET, NULL);
1.66 @@ -119,6 +133,8 @@
1.67
1.68 void Ext2FileOperations::write_file(ext2_file_t file, offset_t filepos, const void *addr, offset_t size)
1.69 {
1.70 + std::lock_guard<std::mutex> guard(_lock);
1.71 +
1.72 ext2fs_file_llseek(file, filepos, SEEK_SET, NULL);
1.73 ext2fs_file_write(file, addr, size, NULL);
1.74 }