Read-only bind mounts are currently not supported by standard kernels,
but it appears that they eventually will be.
The included patch converts local read-only NFS mounts to read-only
bind mounts. Comments are welcome. It compiles and even appears to
work -- well, at least 'mount' shows the resulting bind mounts as
'ro', so the rest is up to the kernel.
(Are there other options that one might want to honour for bind
mounts?)
Thorild Sel�n
Datorf�reningen Update / Update Computer Club, Uppsala, SE
diff -Naur autofs-4.1.3/modules/mount_bind.c
autofs-4.1.3-bindro/modules/mount_bind.c
--- autofs-4.1.3/modules/mount_bind.c 2004-05-10 14:44:30.000000000 +0200
+++ autofs-4.1.3-bindro/modules/mount_bind.c 2004-11-13 21:51:22.000000000
+0100
@@ -106,6 +106,9 @@
while (--i > 0 && fullpath[i] == '/')
fullpath[i] = '\0';
+ if (options == NULL || *options == '\0')
+ options = "defaults";
+
if (bind_works) {
int status;
@@ -121,11 +124,14 @@
return 0;
}
- debug(MODPREFIX "calling mount --bind %s %s", what, fullpath);
+ debug(MODPREFIX
+ "calling mount --bind " SLOPPY " -o %s %s %s",
+ options, what, fullpath);
wait_for_lock();
err = spawnl(LOG_NOTICE, MOUNTED_LOCK,
PATH_MOUNT, PATH_MOUNT, "--bind",
+ SLOPPYOPT "-o", options,
what, fullpath, NULL);
unlink(AUTOFS_LOCK);
diff -Naur autofs-4.1.3/modules/mount_nfs.c
autofs-4.1.3-bindro/modules/mount_nfs.c
--- autofs-4.1.3/modules/mount_nfs.c 2004-05-18 14:20:08.000000000 +0200
+++ autofs-4.1.3-bindro/modules/mount_nfs.c 2004-11-13 23:23:27.000000000
+0100
@@ -333,6 +333,7 @@
char *nfsoptions = NULL;
int local, err;
int nosymlink = 0;
+ int ro = 0; /* Set if mount bind should be read-only */
debug(MODPREFIX " root=%s name=%s what=%s, fstype=%s, options=%s",
root, name, what, fstype, options);
@@ -387,14 +388,18 @@
if (strncmp("nosymlink", cp, end - cp + 1) == 0)
nosymlink = 1;
else {
+ /* Check for options that also make sense
+ with bind mounts */
+ if (strncmp("ro", cp, end - cp + 1) == 0)
+ ro = 1;
/* and jump over trailing white space */
memcpy(nfsp, cp, comma - cp + 1);
nfsp += comma - cp + 1;
}
}
- debug(MODPREFIX "nfs options=\"%s\", nosymlink=%d",
- nfsoptions, nosymlink);
+ debug(MODPREFIX "nfs options=\"%s\", nosymlink=%d, ro=%d",
+ nfsoptions, nosymlink, ro);
}
local = 0;
@@ -426,10 +431,13 @@
if (local) {
/* Local host -- do a "bind" */
+ const char *bind_options = ro ? "ro" : "";
+
debug(MODPREFIX "%s is local, doing bind", name);
return mount_bind->mount_mount(root, name, name_len,
- whatstr, "bind", NULL, mount_bind->context);
+ whatstr, "bind", bind_options,
+ mount_bind->context);
} else {
/* Not a local host - do an NFS mount */
int status;
_______________________________________________
autofs mailing list
[EMAIL PROTECTED]
http://linux.kernel.org/mailman/listinfo/autofs