aboutsummaryrefslogtreecommitdiff
path: root/ubifs-utils/fsck.ubifs/fsck.ubifs.h
blob: 762745f982cc90cf7a84fb572775286f47fe5cb0 (plain)
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
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (C) 2024, Huawei Technologies Co, Ltd.
 *
 * Authors: Zhihao Cheng <chengzhihao1@huawei.com>
 */

#ifndef __FSCK_UBIFS_H__
#define __FSCK_UBIFS_H__

/* Exit codes used by fsck-type programs */
#define FSCK_OK			0	/* No errors */
#define FSCK_NONDESTRUCT	1	/* File system errors corrected */
#define FSCK_REBOOT		2	/* System should be rebooted */
#define FSCK_UNCORRECTED	4	/* File system errors left uncorrected */
#define FSCK_ERROR		8	/* Operational error */
#define FSCK_USAGE		16	/* Usage or syntax error */
#define FSCK_CANCELED		32	/* Aborted with a signal or ^C */
#define FSCK_LIBRARY		128	/* Shared library error */

/*
 * There are 6 working modes for fsck:
 * NORMAL_MODE:	Check the filesystem, ask user whether or not to fix the
 *		problem as long as inconsistent data is found during checking.
 * SAFE_MODE:	Check and safely repair the filesystem, if there are any
 *		data dropping operations needed by fixing, fsck will fail.
 * DANGER_MODE0:Check and repair the filesystem according to TNC, data dropping
 *              will be reported. If TNC/master/log is corrupted, fsck will fail.
 * DANGER_MODE1:Check and forcedly repair the filesystem according to TNC,
 *		turns to @REBUILD_MODE mode automatically if TNC/master/log is
 *		corrupted.
 * REBUILD_MODE:Scan entire UBI volume to find all nodes, and rebuild the
 *		filesystem, always make fsck success.
 * CHECK_MODE:	Make no changes to the filesystem, only check the filesystem.
 */
enum { NORMAL_MODE = 0, SAFE_MODE, DANGER_MODE0,
       DANGER_MODE1, REBUILD_MODE, CHECK_MODE };

/**
 * struct ubifs_fsck_info - UBIFS fsck information.
 * @mode: working mode
 * @failure_reason: reasons for failed operations
 * @lpt_status: the status of lpt, could be: %0(OK), %FR_LPT_CORRUPTED or
 *		%FR_LPT_INCORRECT
 */
struct ubifs_fsck_info {
	int mode;
	unsigned int failure_reason;
	unsigned int lpt_status;
};

#define FSCK(c) ((struct ubifs_fsck_info*)c->private)

static inline const char *mode_name(const struct ubifs_info *c)
{
	if (!c->private)
		return "";

	switch (FSCK(c)->mode) {
	case NORMAL_MODE:
		return ",normal mode";
	case SAFE_MODE:
		return ",safe mode";
	case DANGER_MODE0:
		return ",danger mode";
	case DANGER_MODE1:
		return ",danger + rebuild mode";
	case REBUILD_MODE:
		return ",rebuild mode";
	case CHECK_MODE:
		return ",check mode";
	default:
		return "";
	}
}

#define log_out(c, fmt, ...)						\
	printf("%s[%d] (%s%s): " fmt "\n", c->program_name ? : "noprog",\
	       getpid(), c->dev_name ? : "-", mode_name(c),		\
	       ##__VA_ARGS__)

#define log_err(c, err, fmt, ...) do {					\
	printf("%s[%d][ERROR] (%s%s): %s: " fmt,			\
	       c->program_name ? : "noprog", getpid(),			\
	       c->dev_name ? : "-", mode_name(c),			\
	       __FUNCTION__, ##__VA_ARGS__);				\
	if (err)							\
		printf(" - %s", strerror(err));				\
	printf("\n");							\
} while (0)

/* Exit code for fsck program. */
extern int exit_code;

/* problem.c */
bool fix_problem(const struct ubifs_info *c, int problem_type);

#endif