From c313f09bfbaba40cc7a85d11f10dbb70f68621cd Mon Sep 17 00:00:00 2001 From: "Christian S.J. Peron" Date: Tue, 30 Aug 2005 16:45:32 +0000 Subject: [PATCH] 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 Reviewed by: phk --- sbin/mdconfig/mdconfig.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sbin/mdconfig/mdconfig.c b/sbin/mdconfig/mdconfig.c index 02f128763c2..e3ca148d7fa 100644 --- a/sbin/mdconfig/mdconfig.c +++ b/sbin/mdconfig/mdconfig.c @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -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);