Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

Commit

Permalink
add projection handlers to test programs
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisd8088 committed Feb 12, 2019
1 parent ab4ed50 commit 76946dd
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 22 deletions.
20 changes: 17 additions & 3 deletions t/test_projfs_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
see <http://www.gnu.org/licenses/>.
*/

#include <errno.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>

#include "test_common.h"

static int test_handle_event(struct projfs_event *event, const char *desc,
int perm)
int proj, int perm)
{
unsigned int opt_flags, ret_flags;
const char *retfile;
Expand All @@ -44,6 +45,13 @@ static int test_handle_event(struct projfs_event *event, const char *desc,
event->pid);
}

if (proj) {
if ((event->mask & ~PROJFS_ONDIR) != PROJFS_CREATE_SELF) {
fprintf(stderr, "unknown projection flags\n");
ret = -EINVAL;
}
}

if ((ret_flags & TEST_VAL_SET) == TEST_VAL_UNSET)
ret = perm ? PROJFS_ALLOW : 0;
else if(!perm && ret > 0)
Expand All @@ -52,14 +60,19 @@ static int test_handle_event(struct projfs_event *event, const char *desc,
return ret;
}

static int test_proj_event(struct projfs_event *event)
{
return test_handle_event(event, "projection request", 1, 0);
}

static int test_notify_event(struct projfs_event *event)
{
return test_handle_event(event, "event notification", 0);
return test_handle_event(event, "event notification", 0, 0);
}

static int test_perm_event(struct projfs_event *event)
{
return test_handle_event(event, "permission request", 1);
return test_handle_event(event, "permission request", 0, 1);
}

int main(int argc, char *const argv[])
Expand All @@ -72,6 +85,7 @@ int main(int argc, char *const argv[])
(TEST_OPT_RETVAL | TEST_OPT_RETFILE),
&lower_path, &mount_path);

handlers.handle_proj_event = &test_proj_event;
handlers.handle_notify_event = &test_notify_event;
handlers.handle_perm_event = &test_perm_event;

Expand Down
67 changes: 48 additions & 19 deletions t/test_vfsapi_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,9 @@

#include "test_common.h"

static PrjFS_Result TestNotifyOperation(
_In_ unsigned long commandId,
_In_ const char* relativePath,
_In_ unsigned char providerId[PrjFS_PlaceholderIdLength],
_In_ unsigned char contentId[PrjFS_PlaceholderIdLength],
_In_ int triggeringProcessId,
_In_ const char* triggeringProcessName,
_In_ bool isDirectory,
_In_ PrjFS_NotificationType notificationType,
_In_ const char* destinationRelativePath
)
static int test_handle_event(const char *desc, const char *path,
int pid, const char *procname,
int isdir, int type, int proj)
{
unsigned int opt_flags, ret_flags;
const char *retfile;
Expand All @@ -49,23 +41,59 @@ static PrjFS_Result TestNotifyOperation(

if ((opt_flags & TEST_OPT_RETFILE) == TEST_OPT_NONE ||
(ret_flags & TEST_FILE_EXIST) != TEST_FILE_NONE) {
printf(" TestNotifyOperation for %s: %d, %s, %hhd, 0x%08X\n",
relativePath,
triggeringProcessId, triggeringProcessName,
isDirectory, notificationType);
printf(" Test%s for %s: %d, %s, %hhd, 0x%08X\n",
desc, path, pid, procname, isdir, type);
}

(void)commandId; // prevent compiler warnings
(void)providerId;
(void)contentId;
(void)destinationRelativePath;
if (proj) {
if (!isdir) {
fprintf(stderr, "unsupported file projection\n");
ret = PrjFS_Result_Invalid;
}
}

if ((ret_flags & TEST_VAL_SET) == TEST_VAL_UNSET)
ret = PrjFS_Result_Success;

return ret;
}

static PrjFS_Result TestEnumerateDirectory(
_In_ unsigned long commandId,
_In_ const char* relativePath,
_In_ int triggeringProcessId,
_In_ const char* triggeringProcessName
)
{
(void)commandId; // prevent compiler warnings

return test_handle_event("EnumerateDirectory", relativePath,
triggeringProcessId, triggeringProcessName,
1, 0, 1);
}

static PrjFS_Result TestNotifyOperation(
_In_ unsigned long commandId,
_In_ const char* relativePath,
_In_ unsigned char providerId[PrjFS_PlaceholderIdLength],
_In_ unsigned char contentId[PrjFS_PlaceholderIdLength],
_In_ int triggeringProcessId,
_In_ const char* triggeringProcessName,
_In_ bool isDirectory,
_In_ PrjFS_NotificationType notificationType,
_In_ const char* destinationRelativePath
)
{
(void)commandId; // prevent compiler warnings
(void)providerId;
(void)contentId;
(void)destinationRelativePath;

return test_handle_event("NotifyOperation", relativePath,
triggeringProcessId, triggeringProcessName,
isDirectory, notificationType, 0);
}

int main(int argc, char *const argv[])
{
const char *lower_path, *mount_path;
Expand All @@ -78,6 +106,7 @@ int main(int argc, char *const argv[])
&lower_path, &mount_path);

memset(&callbacks, 0, sizeof(PrjFS_Callbacks));
callbacks.EnumerateDirectory = TestEnumerateDirectory;
callbacks.NotifyOperation = TestNotifyOperation;

test_start_vfsapi_mount(lower_path, mount_path, callbacks,
Expand Down

0 comments on commit 76946dd

Please sign in to comment.