1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
/* Parse standard run-time options
Copyright (C) 1995, 1996 Free Software Foundation, Inc.
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 "priv.h"
static const struct argp_option
std_runtime_options[] =
{
{"remount", 'u', 0, 0, "Flush any meta-data cached in core"},
{0, 0}
};
struct parse_hook
{
int readonly, sync, sync_interval, remount;
};
/* Implement the options in H, and free H. */
static error_t
set_opts (struct parse_hook *h)
{
error_t err = 0;
/* Do things in this order: remount, change readonly, change-sync; always
do the remount while the disk is readonly, even if only temporarily. */
if (h->remount)
{
/* We can only remount while readonly. */
err = diskfs_set_readonly (1);
if (!err)
err = diskfs_remount ();
}
if (h->readonly != diskfs_readonly)
if (err)
diskfs_set_readonly (h->readonly); /* keep the old error. */
else
err = diskfs_set_readonly (h->readonly);
/* Change sync mode. */
if (h->sync)
{
diskfs_synchronous = 1;
diskfs_set_sync_interval (0); /* Don't waste time syncing. */
}
else
{
diskfs_synchronous = 0;
if (h->sync_interval >= 0)
diskfs_set_sync_interval (h->sync_interval);
}
free (h);
return err;
}
/* Parse diskfs standard runtime options. */
static error_t
parse_opt (int opt, char *arg, struct argp_state *state)
{
struct parse_hook *h = state->hook;
switch (opt)
{
case 'r': h->readonly = 1; break;
case 'w': h->readonly = 0; break;
case 'u': h->remount = 1; break;
case 'n': h->sync_interval = 0; h->sync = 0; break;
case 's':
if (arg)
h->sync_interval = atoi (arg);
else
h->sync = 1;
break;
case ARGP_KEY_INIT:
h = state->hook = malloc (sizeof (struct parse_hook));
if (! h)
return ENOMEM;
h->readonly = diskfs_readonly;
h->sync = diskfs_synchronous;
h->sync_interval = -1;
h->remount = 0;
break;
case ARGP_KEY_ERROR:
free (h); break;
case ARGP_KEY_SUCCESS:
return set_opts (h);
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
static const struct argp common_argp = { diskfs_common_options, parse_opt };
static const struct argp *parents[] = { &common_argp, 0 };
const struct argp diskfs_std_runtime_argp =
{
std_runtime_options, parse_opt, 0, 0, parents
};
|