Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Implement link(2) in rumphijack. Add a couple trivial test ...
details: https://anonhg.NetBSD.org/src/rev/8025153da526
branches: trunk
changeset: 780700:8025153da526
user: riastradh <riastradh%NetBSD.org@localhost>
date: Sat Aug 04 03:56:47 2012 +0000
description:
Implement link(2) in rumphijack. Add a couple trivial test cases.
diffstat:
lib/librumphijack/hijack.c | 35 ++++++++++++++++++++++++++---------
tests/lib/librumphijack/t_vfs.sh | 35 ++++++++++++++++++++++++++++++++---
2 files changed, 58 insertions(+), 12 deletions(-)
diffs (167 lines):
diff -r 3c013772d511 -r 8025153da526 lib/librumphijack/hijack.c
--- a/lib/librumphijack/hijack.c Sat Aug 04 03:55:43 2012 +0000
+++ b/lib/librumphijack/hijack.c Sat Aug 04 03:56:47 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: hijack.c,v 1.94 2012/06/29 13:20:25 yamt Exp $ */
+/* $NetBSD: hijack.c,v 1.95 2012/08/04 03:56:47 riastradh Exp $ */
/*-
* Copyright (c) 2011 Antti Kantee. All Rights Reserved.
@@ -29,7 +29,7 @@
#undef _FORTIFY_SOURCE
#include <sys/cdefs.h>
-__RCSID("$NetBSD: hijack.c,v 1.94 2012/06/29 13:20:25 yamt Exp $");
+__RCSID("$NetBSD: hijack.c,v 1.95 2012/08/04 03:56:47 riastradh Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -86,7 +86,7 @@
DUALCALL_LSEEK,
DUALCALL_GETDENTS,
DUALCALL_UNLINK, DUALCALL_SYMLINK, DUALCALL_READLINK,
- DUALCALL_RENAME,
+ DUALCALL_LINK, DUALCALL_RENAME,
DUALCALL_MKDIR, DUALCALL_RMDIR,
DUALCALL_UTIMES, DUALCALL_LUTIMES, DUALCALL_FUTIMES,
DUALCALL_TRUNCATE, DUALCALL_FTRUNCATE,
@@ -227,6 +227,7 @@
{ DUALCALL_UNLINK, "unlink", RSYS_NAME(UNLINK) },
{ DUALCALL_SYMLINK, "symlink", RSYS_NAME(SYMLINK) },
{ DUALCALL_READLINK, "readlink", RSYS_NAME(READLINK) },
+ { DUALCALL_LINK, "link", RSYS_NAME(LINK) },
{ DUALCALL_RENAME, "rename", RSYS_NAME(RENAME) },
{ DUALCALL_MKDIR, "mkdir", RSYS_NAME(MKDIR) },
{ DUALCALL_RMDIR, "rmdir", RSYS_NAME(RMDIR) },
@@ -1080,10 +1081,12 @@
return rv;
}
-int
-rename(const char *from, const char *to)
+static int
+moveish(const char *from, const char *to,
+ int (*rump_op)(const char *, const char *),
+ int (*host_op)(const char *, const char *))
{
- int (*op_rename)(const char *, const char *);
+ int (*op)(const char *, const char *);
enum pathtype ptf, ptt;
if ((ptf = path_isrump(from)) != PATH_HOST) {
@@ -1096,17 +1099,31 @@
from = path_host2rump(from);
if (ptt == PATH_RUMP)
to = path_host2rump(to);
- op_rename = GETSYSCALL(rump, RENAME);
+ op = rump_op;
} else {
if (path_isrump(to) != PATH_HOST) {
errno = EXDEV;
return -1;
}
- op_rename = GETSYSCALL(host, RENAME);
+ op = host_op;
}
- return op_rename(from, to);
+ return op(from, to);
+}
+
+int
+link(const char *from, const char *to)
+{
+ return moveish(from, to,
+ GETSYSCALL(rump, LINK), GETSYSCALL(host, LINK));
+}
+
+int
+rename(const char *from, const char *to)
+{
+ return moveish(from, to,
+ GETSYSCALL(rump, RENAME), GETSYSCALL(host, RENAME));
}
int __socket30(int, int, int);
diff -r 3c013772d511 -r 8025153da526 tests/lib/librumphijack/t_vfs.sh
--- a/tests/lib/librumphijack/t_vfs.sh Sat Aug 04 03:55:43 2012 +0000
+++ b/tests/lib/librumphijack/t_vfs.sh Sat Aug 04 03:56:47 2012 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_vfs.sh,v 1.5 2011/12/01 21:54:10 christos Exp $
+# $NetBSD: t_vfs.sh,v 1.6 2012/08/04 03:56:47 riastradh Exp $
#
# Copyright (c) 2011 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -90,6 +90,7 @@
test_case paxcopy
test_case cpcopy
test_case mv_nox
+test_case ln_nox
#
# use rumphijack to cp/pax stuff onto an image, unmount it, remount it
@@ -121,10 +122,10 @@
# which is not supported by rumpfs)
#
-# stat default format sans changetime and filename
-statstr='%d %i %Sp %l %Su %Sg %r %z \"%Sa\" \"%Sm\" \"%SB\" %k %b %#Xf'
mv_nox()
{
+ # stat default format sans changetime and filename
+ statstr='%d %i %Sp %l %Su %Sg %r %z \"%Sa\" \"%Sm\" \"%SB\" %k %b %#Xf'
atf_check -s exit:0 touch /rump/mnt/filename
atf_check -s exit:0 -o save:stat.out \
@@ -135,7 +136,24 @@
stat -f "${statstr}" /rump/mnt/dir/same
}
+ln_nox()
+{
+ # Omit st_nlink too, since it will increase.
+ statstr='%d %i %Sp %Su %Sg %r %z \"%Sa\" \"%Sm\" \"%SB\" %k %b %#Xf'
+
+ atf_check -s exit:0 touch /rump/mnt/filename
+ atf_check -s exit:0 -o save:stat.out \
+ stat -f "${statstr}" /rump/mnt/filename
+ atf_check -s exit:0 mkdir /rump/mnt/dir
+ atf_check -s exit:0 ln /rump/mnt/filename /rump/mnt/dir/same
+ atf_check -s exit:0 -o file:stat.out \
+ stat -f "${statstr}" /rump/mnt/filename
+ atf_check -s exit:0 -o file:stat.out \
+ stat -f "${statstr}" /rump/mnt/dir/same
+}
+
simpletest mv_x
+simpletest ln_x
simpletest runonprefix
simpletest blanket
simpletest doubleblanket
@@ -152,6 +170,15 @@
atf_check -s exit:0 diff -ru ${thedir}.2 /rump/${thedir}
}
+#
+# Fail to make a cross-kernel hard link.
+#
+ln_x()
+{
+ atf_check -s exit:0 touch ./loser
+ atf_check -s not-exit:0 -e ignore ln ./loser /rump/.
+}
+
runonprefix()
{
atf_check -s exit:0 -o ignore stat /rump/dev
@@ -187,7 +214,9 @@
atf_add_test_case paxcopy
atf_add_test_case cpcopy
atf_add_test_case mv_x
+ atf_add_test_case ln_x
atf_add_test_case mv_nox
+ atf_add_test_case ln_nox
atf_add_test_case runonprefix
atf_add_test_case blanket
atf_add_test_case doubleblanket
Home |
Main Index |
Thread Index |
Old Index