mirror of
https://github.com/opnsense/src.git
synced 2026-06-08 16:22:46 -04:00
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:
parent
e0aec68255
commit
c313f09bfb
1 changed files with 11 additions and 0 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue