aboutsummaryrefslogtreecommitdiff
path: root/sbin/mdconfig/mdconfig.c
diff options
context:
space:
mode:
authorChristian S.J. Peron <csjp@FreeBSD.org>2005-08-30 16:45:32 +0000
committerChristian S.J. Peron <csjp@FreeBSD.org>2005-08-30 16:45:32 +0000
commitc313f09bfbaba40cc7a85d11f10dbb70f68621cd (patch)
treeb251e55ac474f77eefb48fcdf41ef195b4edd9dd /sbin/mdconfig/mdconfig.c
parente0aec6825599217702d01a21908261c5a48a0503 (diff)
downloadsrc-c313f09bfbaba40cc7a85d11f10dbb70f68621cd.tar.gz
src-c313f09bfbaba40cc7a85d11f10dbb70f68621cd.zip
When using files as backing stores for devices, and the user has requested the
device be created read+write, check to see if the backing store is read only through the use of the access(2) system call. If this check fails returning EACCES, EPERM or EROFS then gracefully downgrade the access to read only. Also print a warning message to stderr, informing the user that the access mode they requested is not available. This behavior used to be handled by md(4) but was changed in revision 1.154 Discussed with: pjd, phk, Dario Freni <saturnero at freesbie dot org> Reviewed by: phk
Notes
Notes: svn path=/head/; revision=149638
Diffstat (limited to 'sbin/mdconfig/mdconfig.c')
-rw-r--r--sbin/mdconfig/mdconfig.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/sbin/mdconfig/mdconfig.c b/sbin/mdconfig/mdconfig.c
index 02f128763c21..e3ca148d7fa9 100644
--- a/sbin/mdconfig/mdconfig.c
+++ b/sbin/mdconfig/mdconfig.c
@@ -12,6 +12,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <inttypes.h>
@@ -233,6 +234,16 @@ main(int argc, char **argv)
if (cmdline == 2 && mdio.md_type == MD_VNODE)
if (mdio.md_file[0] == '\0')
errx(1, "must specify -f for -t vnode");
+ if (mdio.md_type == MD_VNODE &&
+ (mdio.md_options & MD_READONLY) == 0) {
+ if (access(mdio.md_file, W_OK) < 0 &&
+ (errno == EACCES || errno == EPERM || errno == EROFS)) {
+ fprintf(stderr,
+ "WARNING: opening backing store: %s readonly\n",
+ mdio.md_file);
+ mdio.md_options |= MD_READONLY;
+ }
+ }
if (action == LIST) {
if (mdio.md_options & MD_AUTOUNIT)
list(fd);