]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - repair/init.c
xfsprogs: suggest "-d" option for repair of RO mount
[thirdparty/xfsprogs-dev.git] / repair / init.c
1 /*
2 * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include <libxfs.h>
20 #include "globals.h"
21 #include "agheader.h"
22 #include "protos.h"
23 #include "err_protos.h"
24 #include "pthread.h"
25 #include "avl.h"
26 #include "bmap.h"
27 #include "incore.h"
28 #include "prefetch.h"
29 #include <sys/resource.h>
30
31 static void
32 ts_create(void)
33 {
34 pthread_key_create(&dblkmap_key, NULL);
35 pthread_key_create(&ablkmap_key, NULL);
36 }
37
38 static void
39 increase_rlimit(void)
40 {
41 struct rlimit rl;
42
43 /* Increase limits */
44 if (getrlimit(RLIMIT_FSIZE, &rl) == -1) {
45 perror("getrlimit");
46 fprintf(stderr, _("getrlimit(RLIMIT_FSIZE) failed!\n"));
47 exit(1);
48 }
49 if (rl.rlim_cur != RLIM_INFINITY) {
50 rl.rlim_max = rl.rlim_cur = RLIM_INFINITY;
51 if (setrlimit(RLIMIT_FSIZE, &rl) == -1) {
52 perror("setrlimit");
53 fprintf(stderr,
54 _("setrlimit failed - current: %lld, max: %lld\n"),
55 (unsigned long long)rl.rlim_cur,
56 (unsigned long long)rl.rlim_max);
57 exit(1);
58 }
59 }
60 }
61
62 void
63 xfs_init(libxfs_init_t *args)
64 {
65 memset(args, 0, sizeof(libxfs_init_t));
66
67 if (isa_file) {
68 args->disfile = 1;
69 args->dname = fs_name;
70 args->volname = NULL;
71 } else {
72 args->disfile = 0;
73 args->volname = fs_name;
74 args->dname = NULL;
75 }
76
77 if (log_spec) { /* External log specified */
78 args->logname = log_name;
79 args->lisfile = (isa_file?1:0);
80 /* XXX assume data file also means log file */
81 /* REVISIT: Need to do fs sanity / log validity checking */
82 }
83
84 if (rt_spec) { /* RT device specified */
85 args->rtname = rt_name;
86 args->risfile = (isa_file?1:0);
87 /* XXX assume data file also means rt file */
88 }
89
90 args->usebuflock = do_prefetch;
91 args->setblksize = 0;
92 args->isdirect = LIBXFS_DIRECT;
93 if (no_modify)
94 args->isreadonly = (LIBXFS_ISREADONLY | LIBXFS_ISINACTIVE);
95 else if (dangerously)
96 args->isreadonly = (LIBXFS_ISINACTIVE | LIBXFS_DANGEROUSLY);
97 else
98 args->isreadonly = LIBXFS_EXCLUSIVELY;
99
100 if (!libxfs_init(args)) {
101 /* would -d be an option? */
102 if (!no_modify && !dangerously) {
103 args->isreadonly = (LIBXFS_ISINACTIVE |
104 LIBXFS_DANGEROUSLY);
105 if (libxfs_init(args))
106 fprintf(stderr,
107 _("Unmount or use the dangerous (-d) option to repair a read-only mounted filesystem\n"));
108 }
109 do_error(_("couldn't initialize XFS library\n"));
110 }
111
112 ts_create();
113 increase_rlimit();
114 pftrace_init();
115 }