Adds explicit check for VFS create alignment

This commit is contained in:
Vladislav Belov
2026-09-10 16:39:14 +02:00
parent 4ae50fd4a4
commit 571047a64a
4 changed files with 10 additions and 4 deletions
@@ -22,6 +22,7 @@
#include "lib/self_test.h"
#include "lib/allocators/shared_ptr.h"
#include "lib/file/file_system.h"
#include "lib/file/vfs/vfs.h"
#include "lib/os_path.h"
@@ -80,7 +81,8 @@ public:
createRealDir(TEST_FOLDER / "cache" / "some_folder");
createRealDir(TEST_FOLDER / "some_mod" / "cache" / "some_mod");
std::shared_ptr<u8> buf(new u8(1));
std::shared_ptr<u8> buf;
TS_ASSERT_OK(AllocateAligned(buf, 1, maxSectorSize));
g_VFS->Mount(L"", TEST_FOLDER / "some_mod" / "", 0, 0);
+4 -1
View File
@@ -22,6 +22,7 @@
#include "lib/self_test.h"
#include "lib/allocators/shared_ptr.h"
#include "lib/file/file_system.h"
#include "lib/file/vfs/vfs.h"
#include "lib/file/vfs/vfs_path.h"
@@ -76,7 +77,9 @@ public:
void test_getPathnames()
{
std::shared_ptr<u8> nodata(new u8);
std::shared_ptr<u8> nodata;
TS_ASSERT_OK(AllocateAligned(nodata, 1, maxSectorSize));
g_VFS->CreateFile("test_file.txt", {nodata.get(), 0});
g_VFS->CreateFile("test_file2.txt", {nodata.get(), 0});
g_VFS->CreateFile("test_file3.txt", {nodata.get(), 0});
+2
View File
@@ -145,6 +145,8 @@ public:
WARN_RETURN_STATUS_IF_ERR(st);
ENSURE(IsAligned(fileContents.data(), maxSectorSize));
const PRealDirectory& realDirectory = directory->AssociatedDirectory();
const OsPath name = pathname.Filename();
RETURN_STATUS_IF_ERR(realDirectory->Store(name, fileContents));
+1 -2
View File
@@ -145,8 +145,7 @@ struct IVFS
/**
* Create a file with the given contents.
* @param pathname
* @param fileContents
* @param size [bytes] of the contents, will match that of the file.
* @param fileContents the pointer must be aligned to maxSectorSize
* @return Status.
**/
virtual Status CreateFile(const VfsPath& pathname, std::span<const u8> fileContents) = 0;