aboutsummaryrefslogtreecommitdiff
path: root/libdiskfs/readonly.c
diff options
context:
space:
mode:
Diffstat (limited to 'libdiskfs/readonly.c')
-rw-r--r--libdiskfs/readonly.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/libdiskfs/readonly.c b/libdiskfs/readonly.c
index 18ade09a..02f583c8 100644
--- a/libdiskfs/readonly.c
+++ b/libdiskfs/readonly.c
@@ -1,6 +1,6 @@
/* Change to/from read-only
- Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 1997, 1999 Free Software Foundation, Inc.
Written by Miles Bader <miles@gnu.ai.mit.edu>
@@ -21,21 +21,34 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <fcntl.h>
+#include <error.h>
#include "priv.h"
int _diskfs_diskdirty;
+int diskfs_readonly = 0;
+int diskfs_hard_readonly = 0;
int
diskfs_check_readonly ()
{
+ error_t err;
+
if (diskfs_readonly)
return 1;
else
{
if (!_diskfs_diskdirty)
{
- diskfs_set_hypermetadata (1, 0);
+ err = diskfs_set_hypermetadata (1, 0);
+ if (err)
+ {
+ error (0, 0,
+ "%s: MEDIA NOT WRITABLE; switching to READ-ONLY",
+ diskfs_disk_name ?: "-");
+ diskfs_hard_readonly = diskfs_readonly = 1;
+ return 1;
+ }
_diskfs_diskdirty = 1;
}
return 0;
@@ -51,6 +64,9 @@ diskfs_set_readonly (int readonly)
{
error_t err = 0;
+ if (diskfs_hard_readonly)
+ return readonly ? 0 : EROFS;
+
if (readonly != diskfs_readonly)
{
err = ports_inhibit_class_rpcs (diskfs_protid_class);
@@ -60,15 +76,13 @@ diskfs_set_readonly (int readonly)
{
error_t peropen_writable (void *pi)
{
- if (((struct port_info *)pi)->class == diskfs_protid_class
- && (((struct protid *)pi)->po->openstat & O_WRITE))
- return EBUSY;
- else
- return 0;
+ struct protid *const cred = pi;
+ return (cred->po->openstat & O_WRITE) ? EBUSY : 0;
}
/* Any writable open files? */
- err = ports_bucket_iterate (diskfs_port_bucket, peropen_writable);
+ err = ports_class_iterate (diskfs_protid_class,
+ peropen_writable);
/* Any writable pagers? */
if (!err && (diskfs_max_user_pager_prot () & VM_PROT_WRITE))