From 96cecadbe7aab4b17634cf522fccbae9ba6982ac Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Thu, 15 Nov 2012 09:35:07 +0545 Subject: Add refcount_read to util.inc Add refcount_read so other code can easily find out how many things have the file system mounted. --- etc/inc/util.inc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/etc/inc/util.inc b/etc/inc/util.inc index 94e8553..9961b4b 100644 --- a/etc/inc/util.inc +++ b/etc/inc/util.inc @@ -248,6 +248,19 @@ function refcount_unreference($reference) { return $shm_data; } +function refcount_read($reference) { + /* This function just reads the current value of the refcount for information. */ + /* There is no need for locking. */ + $shmid = @shmop_open($reference, "a", 0, 0); + if (!$shmid) { + log_error(gettext("Could not open shared memory for read {$reference}")); + return -1; + } + $shm_data = @shmop_read($shmid, 0, 10); + @shmop_close($shmid); + return $shm_data; +} + function is_module_loaded($module_name) { $running = `/sbin/kldstat | grep {$module_name} | /usr/bin/grep -v grep | /usr/bin/wc -l`; if (intval($running) >= 1) -- cgit v1.1 From 41cc7a540236f73c34c10f4df3cb008e1abc3e8b Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Thu, 15 Nov 2012 09:45:25 +0545 Subject: Enhance reporting read-write setting If the user has already selected Current Read/Write Status to be Read-Write, then they also choose Permanent Read/Write the mount refcount becomes 2. Then if they turn off Permanent Read/Write the setting is saved, but the refcount goes back to 1. This results in the file system still being mounted Read-Write. This would be unexpected behaviour IMO - a user who came back some days later to turn off Permanent Read-Write would expect the file system to switch back to Read-Only in real time, as well as changing back the config setting. This corrects the above behaviour. I also added display of the refcount if it is more than 1. If for some reason multiple other things leave the file system mounted then this can be immediately seen on the GUI. Note: The "Switch to Read-Only" button only decrements the refcount by 1 each time. So if the refcount is >1 the user has to press a few times to get the count back to zero and the file system read-only. I think this is reasonable behaviour. --- usr/local/www/diag_nanobsd.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/usr/local/www/diag_nanobsd.php b/usr/local/www/diag_nanobsd.php index 353f9ba..c88aa1b 100755 --- a/usr/local/www/diag_nanobsd.php +++ b/usr/local/www/diag_nanobsd.php @@ -118,7 +118,9 @@ if ($_POST['changero']) { if ($_POST['setrw']) { if (isset($_POST['nanobsd_force_rw'])) { - conf_mount_rw(); + if (!is_writable("/")) { + conf_mount_rw(); + } $config['system']['nanobsd_force_rw'] = true; } else { unset($config['system']['nanobsd_force_rw']); @@ -181,7 +183,13 @@ if ($savemsg)
"; } else { -- cgit v1.1