diff --git a/src/add-ons/kernel/file_systems/btrfs/Volume.h b/src/add-ons/kernel/file_systems/btrfs/Volume.h index a5ca3d2628..75765a69bb 100644 --- a/src/add-ons/kernel/file_systems/btrfs/Volume.h +++ b/src/add-ons/kernel/file_systems/btrfs/Volume.h @@ -59,6 +59,8 @@ public: btrfs_super_block& SuperBlock() { return fSuperBlock; } + mutex& GetLock() { return fLock; } + status_t LoadSuperBlock(); status_t WriteSuperBlock(); diff --git a/src/add-ons/kernel/file_systems/btrfs/btrfs.h b/src/add-ons/kernel/file_systems/btrfs/btrfs.h index 0851452a8e..042ed265cf 100644 --- a/src/add-ons/kernel/file_systems/btrfs/btrfs.h +++ b/src/add-ons/kernel/file_systems/btrfs/btrfs.h @@ -20,6 +20,7 @@ typedef uint64 fsblock_t; // filesystem block number #define BTRFS_NUM_ROOT_BACKUPS 4 +#define BTRFS_CSUM_SIZE 32 struct btrfs_backup_roots { uint64 root; @@ -218,7 +219,7 @@ struct btrfs_device { struct btrfs_super_block { - uint8 checksum[32]; + uint8 checksum[BTRFS_CSUM_SIZE]; uuid_t fsid; uint64 blocknum; uint64 flags; diff --git a/src/add-ons/kernel/file_systems/btrfs/kernel_interface.cpp b/src/add-ons/kernel/file_systems/btrfs/kernel_interface.cpp index 3670dc6676..4bb2d855b2 100644 --- a/src/add-ons/kernel/file_systems/btrfs/kernel_interface.cpp +++ b/src/add-ons/kernel/file_systems/btrfs/kernel_interface.cpp @@ -175,6 +175,33 @@ btrfs_read_fs_info(fs_volume* _volume, struct fs_info* info) } +static status_t +btrfs_write_fs_info(fs_volume* _volume, const struct fs_info* info, uint32 mask) +{ + Volume* volume = (Volume*)_volume->private_volume; + if (volume->IsReadOnly()) + return B_READ_ONLY_DEVICE; + + if (mask & ~FS_WFITE_FSINFO_NAME != 0) + return B_NOT_SUPPORTED; + + MutexLocker locker(volume->GetLock()); + status_t status = B_BAD_VALUE; + + if (mask & FS_WRITE_FSINFO_NAME) { + btrfs_super_block& superBlock = volume->SuperBlock(); + + strncpy(superBlock.label, info->volume_name, + sizeof(superBlock.label) - 1); + superBlock.label[sizeof(superBlock.label) - 1] = '\0'; + + status = volume->WriteSuperBlock(); + } + + return status; +} + + // #pragma mark - @@ -1119,7 +1146,7 @@ btrfs_std_ops(int32 op, ...) fs_volume_ops gBtrfsVolumeOps = { &btrfs_unmount, &btrfs_read_fs_info, - NULL, // write_fs_info() + &btrfs_write_fs_info, NULL, // fs_sync, &btrfs_get_vnode, };