4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
22 #pragma ident "%Z%%M% %I% %E% SMI"
25 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
26 * Use is subject to license terms.
33 #include <sys/mount.h>
34 #include <sys/types.h>
39 #include <sys/mnttab.h>
42 #define MNTTYPE_TMPFS "tmpfs"
48 in_mnttab(char *mountp
)
54 if ((file
= fopen("/etc/mnttab", "r")) == NULL
)
56 while (getmntent(file
, &mntent
) == 0) {
57 if (mntent
.mnt_mountp
!= NULL
&&
58 strcmp(mntent
.mnt_mountp
, mountp
) == 0 &&
59 mntent
.mnt_fstype
!= NULL
&&
60 strcmp(mntent
.mnt_fstype
, MNTTYPE_TMPFS
) == 0) {
70 main(int argc
, char *argv
[])
72 /* mount information */
85 int mount_attempts
= 5;
87 char optbuf
[MAX_MNTOPT_STR
];
91 (void) setlocale(LC_ALL
, "");
93 #if !defined(TEXT_DOMAIN)
94 #define TEXT_DOMAIN "SYS_TEST"
96 (void) textdomain(TEXT_DOMAIN
);
98 myname
= strrchr(argv
[0], '/');
99 myname
= myname
? myname
+ 1 : argv
[0];
100 (void) snprintf(typename
, sizeof (typename
), "%s_%s",
101 MNTTYPE_TMPFS
, myname
);
105 while ((c
= getopt(argc
, argv
, "?o:VmOq")) != EOF
) {
120 (void) strncpy(optbuf
, optarg
, MAX_MNTOPT_STR
);
121 optbuf
[MAX_MNTOPT_STR
- 1] = '\0';
122 optsize
= strlen(optbuf
);
125 (void) fprintf(stderr
, "optsize:%d optbuf:%s\n",
134 if (verbose
&& !error
) {
137 (void) fprintf(stderr
, "%s", typename
);
138 for (optcnt
= 1; optcnt
< argc
; optcnt
++) {
139 optptr
= argv
[optcnt
];
141 (void) fprintf(stderr
, " %s", optptr
);
143 (void) fprintf(stderr
, "\n");
146 if (argc
- optind
!= 2 || error
) {
147 (void) fprintf(stderr
,
148 gettext("Usage: %s [-o size] swap mount_point\n"),
153 special
= argv
[optind
++];
154 mountp
= argv
[optind
++];
155 mflg
|= MS_OPTIONSTR
;
156 mflg
|= (nmflg
? MS_NOMNTTAB
: 0);
159 (void) fprintf(stderr
, "mount(%s, \"%s\", %d, %s",
160 special
, mountp
, mflg
, MNTTYPE_TMPFS
);
162 (void) fprintf(stderr
, ", \"%s\", %d)\n",
163 optbuf
, strlen(optbuf
));
165 (void) fprintf(stderr
, ")\n");
168 if ((saveoptbuf
= strdup(optbuf
)) == NULL
) {
169 (void) fprintf(stderr
, gettext("%s: out of memory\n"),
174 again
: if (mount(special
, mountp
, mflg
, MNTTYPE_TMPFS
, NULL
, 0,
175 optbuf
, MAX_MNTOPT_STR
)) {
176 if (errno
== EBUSY
&& !(mflg
& MS_OVERLAY
)) {
178 * Because of bug 6176743, any attempt to mount
179 * tmpfs filesystem could fail for reasons
180 * described in that bug. We're trying to detect
181 * that situation here by checking that the filesystem
182 * we're mounting is not in /etc/mnttab yet.
183 * When that bug is fixed, this code can be removed.
185 if (!in_mnttab(mountp
) && mount_attempts
-- > 0) {
186 (void) poll(NULL
, 0, 50);
189 (void) fprintf(stderr
, gettext(
190 "%s: %s is already mounted or %s is busy\n"),
191 myname
, mountp
, special
);
198 if (optsize
&& !qflg
)
199 cmp_requested_to_actual_options(saveoptbuf
, optbuf
,