memfs: memfs-main.c

This commit is contained in:
Bill Zissimopoulos 2016-04-08 20:29:43 -07:00
parent 9f6bbe4a63
commit 2c7ce4a3da
5 changed files with 28 additions and 8 deletions

View File

@ -19,6 +19,9 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "winfsp-tests", "testing\win
EndProjectSection EndProjectSection
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "memfs", "testing\memfs.vcxproj", "{AA7190E8-877F-4827-8CDD-E0D85F83C8C1}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "memfs", "testing\memfs.vcxproj", "{AA7190E8-877F-4827-8CDD-E0D85F83C8C1}"
ProjectSection(ProjectDependencies) = postProject
{C85C26BA-8C22-4D30-83DA-46C3548E6332} = {C85C26BA-8C22-4D30-83DA-46C3548E6332}
EndProjectSection
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution

View File

@ -54,14 +54,14 @@ static void usage(void)
"options:\n" "options:\n"
" -t FileInfoTimeout\n" " -t FileInfoTimeout\n"
" -n MaxFileNodes\n" " -n MaxFileNodes\n"
" -s MaxFileSize\n"; " -s MaxFileSize\n"
" -u \\\\Volume\\Prefix\n";
warn(usage, PROGNAME); warn(usage, PROGNAME);
exit(2); exit(2);
} }
static inline static ULONG argtol(wchar_t **argp, ULONG deflt)
ULONG argtol(wchar_t **argp, ULONG deflt)
{ {
if (0 == argp[0]) if (0 == argp[0])
usage(); usage();
@ -71,6 +71,14 @@ ULONG argtol(wchar_t **argp, ULONG deflt)
return 0 != ul ? ul : deflt; return 0 != ul ? ul : deflt;
} }
static wchar_t *argtos(wchar_t **argp)
{
if (0 == argp[0])
usage();
return argp[0];
}
static HANDLE MainEvent; static HANDLE MainEvent;
static BOOL WINAPI ConsoleCtrlHandler(DWORD CtrlType) static BOOL WINAPI ConsoleCtrlHandler(DWORD CtrlType)
@ -89,6 +97,7 @@ int wmain(int argc, wchar_t **argv)
ULONG MaxFileNodes = 1024; ULONG MaxFileNodes = 1024;
ULONG MaxFileSize = 1024 * 1024; ULONG MaxFileSize = 1024 * 1024;
PWSTR MountPoint = 0; PWSTR MountPoint = 0;
PWSTR VolumePrefix = 0;
for (argp = argv + 1; 0 != argp[0]; argp++) for (argp = argv + 1; 0 != argp[0]; argp++)
{ {
@ -105,6 +114,10 @@ int wmain(int argc, wchar_t **argv)
case L't': case L't':
FileInfoTimeout = argtol(++argp, FileInfoTimeout); FileInfoTimeout = argtol(++argp, FileInfoTimeout);
break; break;
case L'v':
VolumePrefix = argtos(++argp);
Flags = MemfsNet;
break;
default: default:
usage(); usage();
break; break;
@ -119,7 +132,7 @@ int wmain(int argc, wchar_t **argv)
if (0 == MainEvent) if (0 == MainEvent)
fail("error: cannot create MainEvent"); fail("error: cannot create MainEvent");
Result = MemfsCreate(Flags, FileInfoTimeout, MaxFileNodes, MaxFileSize, &Memfs); Result = MemfsCreate(Flags, FileInfoTimeout, MaxFileNodes, MaxFileSize, VolumePrefix, &Memfs);
if (!NT_SUCCESS(Result)) if (!NT_SUCCESS(Result))
fail("error: cannot create MEMFS"); fail("error: cannot create MEMFS");
Result = MemfsStart(Memfs); Result = MemfsStart(Memfs);
@ -129,8 +142,8 @@ int wmain(int argc, wchar_t **argv)
if (!NT_SUCCESS(Result)) if (!NT_SUCCESS(Result))
fail("error: cannot mount MEMFS"); fail("error: cannot mount MEMFS");
warn("%s -t %ld -n %ld -s %ld %s", warn("%s -t %ld -n %ld -s %ld -v %s %s",
PROGNAME, FileInfoTimeout, MaxFileNodes, MaxFileSize, MountPoint); PROGNAME, FileInfoTimeout, MaxFileNodes, MaxFileSize, VolumePrefix, MountPoint);
SetConsoleCtrlHandler(ConsoleCtrlHandler, TRUE); SetConsoleCtrlHandler(ConsoleCtrlHandler, TRUE);
if (WAIT_OBJECT_0 != WaitForSingleObject(MainEvent, INFINITE)) if (WAIT_OBJECT_0 != WaitForSingleObject(MainEvent, INFINITE))
fail("error: cannot wait on MainEvent"); fail("error: cannot wait on MainEvent");

View File

@ -838,6 +838,7 @@ static VOID MemfsLeaveOperation(FSP_FILE_SYSTEM *FileSystem,
NTSTATUS MemfsCreate(ULONG Flags, ULONG FileInfoTimeout, NTSTATUS MemfsCreate(ULONG Flags, ULONG FileInfoTimeout,
ULONG MaxFileNodes, ULONG MaxFileSize, ULONG MaxFileNodes, ULONG MaxFileSize,
PWSTR VolumePrefix,
MEMFS **PMemfs) MEMFS **PMemfs)
{ {
NTSTATUS Result; NTSTATUS Result;
@ -877,7 +878,8 @@ NTSTATUS MemfsCreate(ULONG Flags, ULONG FileInfoTimeout,
VolumeParams.CasePreservedNames = 1; VolumeParams.CasePreservedNames = 1;
VolumeParams.UnicodeOnDisk = 1; VolumeParams.UnicodeOnDisk = 1;
VolumeParams.PersistentAcls = 1; VolumeParams.PersistentAcls = 1;
wcscpy_s(VolumeParams.Prefix, sizeof VolumeParams.Prefix / sizeof(WCHAR), L"\\memfs\\share"); if (0 != VolumePrefix)
wcscpy_s(VolumeParams.Prefix, sizeof VolumeParams.Prefix / sizeof(WCHAR), VolumePrefix);
Result = FspFileSystemCreate(DevicePath, &VolumeParams, &MemfsInterface, &Memfs->FileSystem); Result = FspFileSystemCreate(DevicePath, &VolumeParams, &MemfsInterface, &Memfs->FileSystem);
if (!NT_SUCCESS(Result)) if (!NT_SUCCESS(Result))

View File

@ -23,6 +23,7 @@ enum
NTSTATUS MemfsCreate(ULONG Flags, ULONG FileInfoTimeout, NTSTATUS MemfsCreate(ULONG Flags, ULONG FileInfoTimeout,
ULONG MaxFileNodes, ULONG MaxFileSize, ULONG MaxFileNodes, ULONG MaxFileSize,
PWSTR VolumePrefix,
MEMFS **PMemfs); MEMFS **PMemfs);
VOID MemfsDelete(MEMFS *Memfs); VOID MemfsDelete(MEMFS *Memfs);
NTSTATUS MemfsStart(MEMFS *Memfs); NTSTATUS MemfsStart(MEMFS *Memfs);

View File

@ -14,7 +14,8 @@ void *memfs_start_ex(ULONG Flags, ULONG FileInfoTimeout)
MEMFS *Memfs; MEMFS *Memfs;
NTSTATUS Result; NTSTATUS Result;
Result = MemfsCreate(Flags, FileInfoTimeout, 1024, 1024 * 1024, &Memfs); Result = MemfsCreate(Flags, FileInfoTimeout, 1024, 1024 * 1024,
MemfsNet == Flags ? L"\\memfs\\share" : 0, &Memfs);
ASSERT(NT_SUCCESS(Result)); ASSERT(NT_SUCCESS(Result));
ASSERT(0 != Memfs); ASSERT(0 != Memfs);