]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - repair/init.c
xfs_repair: don't flag log_incompat inconsistencies as corruptions
[thirdparty/xfsprogs-dev.git] / repair / init.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
5 */
6
7 #include "libxfs.h"
8 #include "globals.h"
9 #include "agheader.h"
10 #include "protos.h"
11 #include "err_protos.h"
12 #include "pthread.h"
13 #include "avl.h"
14 #include "bmap.h"
15 #include "incore.h"
16 #include "prefetch.h"
17 #include "libfrog/crc32cselftest.h"
18 #include <sys/resource.h>
19
20 static void
21 ts_create(void)
22 {
23 pthread_key_create(&dblkmap_key, NULL);
24 pthread_key_create(&ablkmap_key, NULL);
25 }
26
27 static void
28 increase_rlimit(void)
29 {
30 struct rlimit rl;
31
32 /* Increase limits */
33 if (getrlimit(RLIMIT_FSIZE, &rl) == -1) {
34 perror("getrlimit");
35 fprintf(stderr, _("getrlimit(RLIMIT_FSIZE) failed!\n"));
36 exit(1);
37 }
38 if (rl.rlim_cur != RLIM_INFINITY) {
39 rl.rlim_max = rl.rlim_cur = RLIM_INFINITY;
40 if (setrlimit(RLIMIT_FSIZE, &rl) == -1) {
41 perror("setrlimit");
42 fprintf(stderr,
43 _("setrlimit failed - current: %lld, max: %lld\n"),
44 (unsigned long long)rl.rlim_cur,
45 (unsigned long long)rl.rlim_max);
46 exit(1);
47 }
48 }
49 }
50
51 void
52 xfs_init(libxfs_init_t *args)
53 {
54 memset(args, 0, sizeof(libxfs_init_t));
55
56 if (isa_file) {
57 args->disfile = 1;
58 args->dname = fs_name;
59 args->volname = NULL;
60 } else {
61 args->disfile = 0;
62 args->volname = fs_name;
63 args->dname = NULL;
64 }
65
66 if (log_spec) { /* External log specified */
67 args->logname = log_name;
68 args->lisfile = (isa_file?1:0);
69 /* XXX assume data file also means log file */
70 /* REVISIT: Need to do fs sanity / log validity checking */
71 }
72
73 if (rt_spec) { /* RT device specified */
74 args->rtname = rt_name;
75 args->risfile = (isa_file?1:0);
76 /* XXX assume data file also means rt file */
77 }
78
79 args->usebuflock = do_prefetch;
80 args->setblksize = 0;
81 args->isdirect = LIBXFS_DIRECT;
82 if (no_modify)
83 args->isreadonly = (LIBXFS_ISREADONLY | LIBXFS_ISINACTIVE);
84 else if (dangerously)
85 args->isreadonly = (LIBXFS_ISINACTIVE | LIBXFS_DANGEROUSLY);
86 else
87 args->isreadonly = LIBXFS_EXCLUSIVELY;
88
89 if (!libxfs_init(args)) {
90 /* would -d be an option? */
91 if (!no_modify && !dangerously) {
92 args->isreadonly = (LIBXFS_ISINACTIVE |
93 LIBXFS_DANGEROUSLY);
94 if (libxfs_init(args))
95 fprintf(stderr,
96 _("Unmount or use the dangerous (-d) option to repair a read-only mounted filesystem\n"));
97 }
98 do_error(_("couldn't initialize XFS library\n"));
99 }
100
101 ts_create();
102 increase_rlimit();
103 pftrace_init();
104
105 if (crc32c_test(CRC32CTEST_QUIET) != 0)
106 do_error(
107 _("crc32c self-test failed, will not examine filesystem.\n"));
108 }