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
This commit is contained in:
Christian S.J. Peron 2005-08-30 16:45:32 +00:00
parent e0aec68255
commit c313f09bfb
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=149638

View File

@ -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);