Inherit owner, group and mode of the mount directory so that mounting a
tmpfs over, e.g., /tmp, is trivial.
This commit is contained in:
parent
b453f6ca4f
commit
847bd3696d
@ -1,4 +1,4 @@
|
||||
.\" $NetBSD: mount_tmpfs.8,v 1.3 2005/09/23 15:36:16 jmmv Exp $
|
||||
.\" $NetBSD: mount_tmpfs.8,v 1.4 2005/09/25 08:08:12 jmmv Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2005 The NetBSD Foundation, Inc.
|
||||
.\" All rights reserved.
|
||||
@ -35,7 +35,7 @@
|
||||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd September 10, 2005
|
||||
.Dd September 25, 2005
|
||||
.Dt MOUNT_TMPFS 8
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -58,14 +58,18 @@ command attaches an instance of the efficient memory file system to the
|
||||
global file system namespace.
|
||||
The directory specified by
|
||||
.Ar mount_point
|
||||
is converted to an absolute path before use.
|
||||
is converted to an absolute path before use and its attributes (owner,
|
||||
group and mode) are inherited unless explicitly overriden by the options
|
||||
described below.
|
||||
.Pp
|
||||
The following options are supported:
|
||||
.Bl -tag -width XoXoptions
|
||||
.It Fl g Ar group
|
||||
Specifies the group name or GID of the root inode of the file system.
|
||||
Defaults to the mount point's GID.
|
||||
.It Fl m Ar mode
|
||||
Specifies the mode (in octal notation) of the root inode of the file system.
|
||||
Defaults to the mount point's mode.
|
||||
.It Fl n Ar nodes
|
||||
Specifies the maximum number of nodes available to the file system.
|
||||
.It Fl o Ar options
|
||||
@ -83,6 +87,7 @@ Note that four megabytes are always reserved for the system and cannot
|
||||
be assigned to the file system.
|
||||
.It Fl u Ar user
|
||||
Specifies the user name or UID of the root inode of the file system.
|
||||
Defaults to the mount point's UID.
|
||||
.El
|
||||
.Pp
|
||||
Every option that accepts a numerical value as its argument can take a
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: mount_tmpfs.c,v 1.3 2005/09/23 15:36:16 jmmv Exp $ */
|
||||
/* $NetBSD: mount_tmpfs.c,v 1.4 2005/09/25 08:08:12 jmmv Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2005 The NetBSD Foundation, Inc.
|
||||
@ -39,11 +39,12 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: mount_tmpfs.c,v 1.3 2005/09/23 15:36:16 jmmv Exp $");
|
||||
__RCSID("$NetBSD: mount_tmpfs.c,v 1.4 2005/09/25 08:08:12 jmmv Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <fs/tmpfs/tmpfs.h>
|
||||
|
||||
@ -53,6 +54,7 @@ __RCSID("$NetBSD: mount_tmpfs.c,v 1.3 2005/09/23 15:36:16 jmmv Exp $");
|
||||
#include <grp.h>
|
||||
#include <mntopts.h>
|
||||
#include <pwd.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -80,10 +82,15 @@ int
|
||||
mount_tmpfs(int argc, char *argv[])
|
||||
{
|
||||
char canon_dir[MAXPATHLEN];
|
||||
bool gidset, modeset, uidset;
|
||||
int ch, mntflags;
|
||||
gid_t gid;
|
||||
uid_t uid;
|
||||
mode_t mode;
|
||||
off_t offtmp;
|
||||
mntoptparse_t mo;
|
||||
struct tmpfs_args args;
|
||||
struct stat sb;
|
||||
|
||||
setprogname(argv[0]);
|
||||
|
||||
@ -91,28 +98,31 @@ mount_tmpfs(int argc, char *argv[])
|
||||
args.ta_version = TMPFS_ARGS_VERSION;
|
||||
args.ta_size_max = 0;
|
||||
args.ta_nodes_max = 0;
|
||||
args.ta_root_uid = getuid();
|
||||
args.ta_root_gid = getgid();
|
||||
args.ta_root_mode = 0755;
|
||||
mntflags = 0;
|
||||
|
||||
gidset = false; gid = 0;
|
||||
uidset = false; uid = 0;
|
||||
modeset = false; mode = 0;
|
||||
|
||||
optind = optreset = 1;
|
||||
while ((ch = getopt(argc, argv, "g:m:n:o:s:u:")) != -1 ) {
|
||||
switch (ch) {
|
||||
case 'g':
|
||||
if (!dehumanize_group(optarg, &args.ta_root_gid)) {
|
||||
if (!dehumanize_group(optarg, &gid)) {
|
||||
errx(EXIT_FAILURE, "failed to parse group "
|
||||
"'%s'", optarg);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
gidset = true;
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
if (!dehumanize_mode(optarg, &args.ta_root_mode)) {
|
||||
if (!dehumanize_mode(optarg, &mode)) {
|
||||
errx(EXIT_FAILURE, "failed to parse mode "
|
||||
"'%s'", optarg);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
modeset = true;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
@ -139,11 +149,12 @@ mount_tmpfs(int argc, char *argv[])
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
if (!dehumanize_user(optarg, &args.ta_root_uid)) {
|
||||
if (!dehumanize_user(optarg, &uid)) {
|
||||
errx(EXIT_FAILURE, "failed to parse user "
|
||||
"'%s'", optarg);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
uidset = true;
|
||||
break;
|
||||
|
||||
case '?':
|
||||
@ -170,6 +181,14 @@ mount_tmpfs(int argc, char *argv[])
|
||||
warnx("using \"%s\" instead", canon_dir);
|
||||
}
|
||||
|
||||
if (stat(canon_dir, &sb) == -1) {
|
||||
err(EXIT_FAILURE, "cannot stat");
|
||||
/* NOTREACHED */
|
||||
}
|
||||
args.ta_root_uid = uidset ? uid : sb.st_uid;
|
||||
args.ta_root_gid = gidset ? gid : sb.st_gid;
|
||||
args.ta_root_mode = modeset ? mode : sb.st_mode;
|
||||
|
||||
if (mount(MOUNT_TMPFS, canon_dir, mntflags, &args)) {
|
||||
err(EXIT_FAILURE, "tmpfs on %s", canon_dir);
|
||||
/* NOTREACHED */
|
||||
|
Loading…
Reference in New Issue
Block a user