2
* mount_attrs.c - NILFS mount attribute functions for libmount version
4
* Copyright (C) 2011 Nippon Telegraph and Telephone Corporation.
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public
8
* License as published by the Free Software Foundation; either
9
* version 2 of the License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* General Public License for more details.
16
* You should have received a copy of the GNU General Public
17
* License along with this program; if not, write to the
18
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
* Boston, MA 021110-1307, USA.
21
* Written by Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
26
#endif /* HAVE_CONFIG_H */
29
#include <sys/types.h>
30
#endif /* HAVE_SYS_TYPES_H */
36
#endif /* HAVE_STDLIB_H */
40
#endif /* HAVE_STRING_H */
42
#if HAVE_LIBMOUNT_LIBMOUNT_H
43
#include <libmount/libmount.h>
44
#endif /* HAVE_LIBMOUNT_H */
51
#include "mount.nilfs2.h"
52
#include "mount_attrs.h"
53
#include "cleaner_exec.h" /* PIDOPT_NAME */
56
extern char *progname;
58
void nilfs_mount_attrs_init(struct nilfs_mount_attrs *mattrs)
60
memset(mattrs, 0, sizeof(*mattrs));
61
mattrs->pp = ULONG_MAX; /* no protection period */
64
int nilfs_mount_attrs_parse(struct nilfs_mount_attrs *mattrs,
65
const char *optstr, char **found, char **rest,
68
char *name, *val, *str, *p, *endptr, *prev = NULL;
82
while (!mnt_optstr_next_option(&p, &name, &namesz, &val, &valsz)) {
83
if (!strncmp(name, PPOPT_NAME, namesz)) {
84
if (!val || valsz == 0)
87
mattrs->pp = strtoul(val, &endptr, 10);
88
if (endptr != val + valsz)
91
} else if (!strncmp(name, NOGCOPT_NAME, namesz)) {
97
} else if (!strncmp(name, PIDOPT_NAME, namesz)) {
98
if (!val || valsz == 0 || !mtab)
101
mattrs->gcpid = strtoul(val, &endptr, 10);
102
if (endptr != val + valsz)
105
} else if (!strncmp(name, NOATTR_NAME, namesz)) {
117
res = mnt_optstr_append_option(rest, prev, NULL);
126
res = mnt_optstr_append_option(found, name, val);
133
res = mnt_optstr_append_option(rest, prev, NULL);
142
error(_("%s: invalid options (%s)."), progname, optstr);
159
void nilfs_mount_attrs_update(struct nilfs_mount_attrs *old_attrs,
160
struct nilfs_mount_attrs *new_attrs,
161
struct libmnt_context *cxt)
163
struct libmnt_fs *fs;
165
if (!new_attrs && !old_attrs)
168
fs = mnt_context_get_fs(cxt);
169
mnt_fs_set_attributes(fs, NULL);
173
if (new_attrs->nogc) {
174
mnt_fs_append_attributes(fs, NOGCOPT_NAME);
175
} else if (new_attrs->gcpid) {
178
snprintf(abuf, sizeof(abuf), PIDOPT_NAME "=%lu",
179
(unsigned long)new_attrs->gcpid);
180
mnt_fs_append_attributes(fs, abuf);
181
if (new_attrs->pp != ULONG_MAX) {
182
snprintf(abuf, sizeof(abuf), PPOPT_NAME "=%lu",
184
mnt_fs_append_attributes(fs, abuf);
186
} else if (old_attrs) {
188
* The following dummy attribute is required to handle
189
* removal of attributes on remount.
191
mnt_fs_set_attributes(fs, NOATTR_NAME);