diff options
author | Miles Bader <miles@gnu.org> | 1996-06-19 18:20:01 +0000 |
---|---|---|
committer | Miles Bader <miles@gnu.org> | 1996-06-19 18:20:01 +0000 |
commit | 3de53c55206b65efc39ed02a06a0de9b51d9dc91 (patch) | |
tree | 096883475c605ce95aa4693f208d4572777067f4 | |
parent | b375f5b6259fab36e8ad582c864fbba74ba9af75 (diff) |
Initial revision
-rw-r--r-- | libshouldbeinlibc/fsysops.c | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/libshouldbeinlibc/fsysops.c b/libshouldbeinlibc/fsysops.c new file mode 100644 index 00000000..4e282f0b --- /dev/null +++ b/libshouldbeinlibc/fsysops.c @@ -0,0 +1,94 @@ +/* Some handy utility routines for fsys control ports + + Copyright (C) 1996 Free Software Foundation, Inc. + + Written by Miles Bader <miles@gnu.ai.mit.edu> + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + The GNU Hurd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#include <errno.h> +#include <argz.h> +#include <mach.h> +#include <hurd/fsys.h> + +/* Make FSYS readonly or writable. */ +error_t +fsys_set_readonly (fsys_t fsys, int readonly) +{ + error_t err; + char *opts = readonly ? "--readonly" : "--writable"; + size_t opts_len = strlen (opts) + 1; + err = fsys_set_options (fsys, opts, opts_len, 0); + if (err == EINVAL) + err = EOPNOTSUPP; + return err; +} + +/* Ask FSYS whether it's readonly, returning the result in READONLY; we don't + really have a good method for this, other than asking for it's options and + looking for `--readonly' or `--writable'. If we see neither, return + EOPNOTSUPP. */ +error_t +fsys_get_readonly (fsys_t fsys, int *readonly) +{ + error_t err; + char _opts[200], *opts = _opts; + size_t opts_len = sizeof opts; + + err = fsys_get_options (fsys, &opts, &opts_len); + if (! err) + { + char *opt; + int ok = 0; + + for (opt = opts + ; !ok && opt && opt < opts + opts_len + ; opt = argz_next (opts, opts_len, opt)) + if (strcasecmp (opt, "--readonly") == 0) + { + *readonly = 1; + ok = 1; + } + else if (strcasecmp (opt, "--writable") == 0) + { + *readonly = 0; + ok = 1; + } + + if (! ok) + err = EOPNOTSUPP; /* So far as we know... */ + + if (opts != _opts) + /* Free out-of-line memory returned by fsys_get_options. */ + vm_deallocate (mach_task_self (), (vm_address_t)opts, opts_len); + } + + return err; +} + +/* Tell FSYS to remount itself. */ +error_t +fsys_remount (fsys_t fsys, int readonly) +{ + error_t err; + char *opts = "--remount"; + size_t opts_len = strlen (opts) + 1; + err = fsys_set_options (fsys, opts, opts_len, 0); + if (err == EINVAL) + err = EOPNOTSUPP; + return err; +} |