>From d9cbfa3398fe9e6269cc76429220d1fc1990b474 Mon Sep 17 00:00:00 2001 From: Alan Jenkins Date: Fri, 12 Oct 2018 11:11:13 +0100 Subject: [PATCH] vfs: tiny sample programs for open_tree() and move_mount() A couple of utility commands for fd-based mounts. They were useful to reproduce three different issues, in the original implementation of the system calls. Also add .gitignore for all the vfs samples. Signed-off-by: Alan Jenkins --- samples/vfs/.gitignore | 4 +++ samples/vfs/Makefile | 4 +++ samples/vfs/move_mount.c | 42 ++++++++++++++++++++++ samples/vfs/open_tree_clone.c | 65 +++++++++++++++++++++++++++++++++++ 4 files changed, 115 insertions(+) create mode 100644 samples/vfs/.gitignore create mode 100644 samples/vfs/move_mount.c create mode 100644 samples/vfs/open_tree_clone.c diff --git a/samples/vfs/.gitignore b/samples/vfs/.gitignore new file mode 100644 index 000000000000..242ed23f90d2 --- /dev/null +++ b/samples/vfs/.gitignore @@ -0,0 +1,4 @@ +open_tree_clone +move_mount +test-fsmount +test-statx diff --git a/samples/vfs/Makefile b/samples/vfs/Makefile index 4ac9690fb3c4..3a5bb48d21a0 100644 --- a/samples/vfs/Makefile +++ b/samples/vfs/Makefile @@ -1,10 +1,14 @@ # List of programs to build hostprogs-$(CONFIG_SAMPLE_VFS) := \ + open_tree_clone \ + move_mount \ test-fsmount \ test-statx # Tell kbuild to always build the programs always := $(hostprogs-y) +HOSTCFLAGS_open_tree_clone.o += -I$(objtree)/usr/include +HOSTCFLAGS_move_mount.o += -I$(objtree)/usr/include HOSTCFLAGS_test-fsmount.o += -I$(objtree)/usr/include HOSTCFLAGS_test-statx.o += -I$(objtree)/usr/include diff --git a/samples/vfs/move_mount.c b/samples/vfs/move_mount.c new file mode 100644 index 000000000000..2cc9d876078a --- /dev/null +++ b/samples/vfs/move_mount.c @@ -0,0 +1,42 @@ +/* fd-based mount utility. + * + * Copyright (C) 2018 Alan Jenkins (alan.christopher.jenkins@gmail.com). + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public Licence + * as published by the Free Software Foundation; either version + * 2 of the Licence, or (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include + +static inline int move_mount(int from_dfd, const char *from_pathname, + int to_dfd, const char *to_pathname, + unsigned int flags) +{ + return syscall(__NR_move_mount, + from_dfd, from_pathname, + to_dfd, to_pathname, flags); +} + +int main(int argc, char *argv[]) +{ + if (argc != 1) { + fprintf(stderr, "Usage: move_mount 3 +#include +#include +#include +#include +#include +#include +#include + +#ifndef AT_RECURSIVE +#define AT_RECURSIVE 0x8000 +#endif + +#define E(x) do { if ((x) == -1) { perror(#x); exit(1); } } while(0) + +static inline int open_tree(int dfd, const char *pathname, unsigned flags) +{ + return syscall(__NR_open_tree, dfd, pathname, flags); +} + +int main(int argc, char *argv[]) +{ + int fd_number; + char **command; + int mfd; + + if (argc < 3 || !isdigit(argv[1][0])) { + fprintf(stderr, "Usage: 3