summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/dosfstools
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/dosfstools')
-rw-r--r--meta/recipes-devtools/dosfstools/dosfstools/0001-fsck.fat-Adhere-to-the-fsck-exit-codes.patch214
-rw-r--r--meta/recipes-devtools/dosfstools/dosfstools/0002-manpages-Document-fsck.fat-new-exit-codes.patch46
-rw-r--r--meta/recipes-devtools/dosfstools/dosfstools_4.2.bb7
3 files changed, 264 insertions, 3 deletions
diff --git a/meta/recipes-devtools/dosfstools/dosfstools/0001-fsck.fat-Adhere-to-the-fsck-exit-codes.patch b/meta/recipes-devtools/dosfstools/dosfstools/0001-fsck.fat-Adhere-to-the-fsck-exit-codes.patch
new file mode 100644
index 0000000000..3d2ce48723
--- /dev/null
+++ b/meta/recipes-devtools/dosfstools/dosfstools/0001-fsck.fat-Adhere-to-the-fsck-exit-codes.patch
@@ -0,0 +1,214 @@
1From 9d165145b9f9c20a56e111360fbc2003c2b28cba Mon Sep 17 00:00:00 2001
2From: Ricardo Simoes <ricardo.simoes@pt.bosch.com>
3Date: Thu, 26 Jun 2025 08:14:29 +0100
4Subject: [PATCH] fsck.fat: Adhere to the fsck exit codes
5
6fsck.fat is used as a filesystem-specific checker for the `fsck`. This
7also causes `fsck` to return the same exit-codes given by `fsck.fat`.
8
9In most cases this is already the case. One exception to that comes when
10checking a read-only filesystem. In that case `fsck.fat` will return 6,
11which for `fsck` means "Fiesystem errors left uncorrected" and "System
12should reboot". When a more proper response would be to return 8,
13"Operational Error".
14
15This commit solves that problem by introducing a new header file which
16standardizes the exit codes used by `fsck.fat`.
17
18Signed-off-by: Ricardo Ungerer <ungerer.ricardo@gmail.com>
19
20Upstream-Status: Inactive-Upstream [lastcommit: 2023, lastrelease: 2021]
21Upstream-Status: Submitted [https://github.com/dosfstools/dosfstools/pull/217]
22---
23 src/Makefile.am | 4 ++--
24 src/common.c | 8 ++++----
25 src/exit_codes.h | 15 +++++++++++++++
26 src/fsck.fat.c | 23 ++++++++++++-----------
27 src/io.c | 3 ++-
28 5 files changed, 35 insertions(+), 18 deletions(-)
29 create mode 100644 src/exit_codes.h
30
31diff --git a/src/Makefile.am b/src/Makefile.am
32index a389046..48f00dd 100644
33--- a/src/Makefile.am
34+++ b/src/Makefile.am
35@@ -23,7 +23,7 @@ EXTRA_DIST = blkdev/README
36
37 charconv_common_sources = charconv.c charconv.h
38 charconv_common_ldadd = $(LIBICONV)
39-fscklabel_common_sources = boot.c boot.h common.c common.h \
40+fscklabel_common_sources = boot.c boot.h common.c common.h exit_codes.h \
41 fat.c fat.h io.c io.h msdos_fs.h \
42 $(charconv_common_sources) \
43 fsck.fat.h endian_compat.h
44@@ -38,7 +38,7 @@ devinfo_common_sources = device_info.c device_info.h \
45 blkdev/blkdev.c blkdev/blkdev.h \
46 blkdev/linux_version.c blkdev/linux_version.h
47 mkfs_fat_SOURCES = mkfs.fat.c msdos_fs.h common.c common.h endian_compat.h \
48- $(charconv_common_sources) $(devinfo_common_sources)
49+ exit_codes.h $(charconv_common_sources) $(devinfo_common_sources)
50 mkfs_fat_CPPFLAGS = -I$(srcdir)/blkdev
51 mkfs_fat_CFLAGS = $(AM_CFLAGS)
52 mkfs_fat_LDADD = $(charconv_common_ldadd)
53diff --git a/src/common.c b/src/common.c
54index 4f1afcb..089d4b3 100644
55--- a/src/common.c
56+++ b/src/common.c
57@@ -38,7 +38,7 @@
58
59 #include "common.h"
60 #include "charconv.h"
61-
62+#include "exit_codes.h"
63
64 int interactive;
65 int write_immed;
66@@ -62,7 +62,7 @@ void die(const char *msg, ...)
67 vfprintf(stderr, msg, args);
68 va_end(args);
69 fprintf(stderr, "\n");
70- exit(1);
71+ exit(OPERATIONAL_ERROR);
72 }
73
74 void pdie(const char *msg, ...)
75@@ -205,7 +205,7 @@ int get_choice(int noninteractive_result, const char *noninteractive_msg,
76 } while (choice == '\n'); /* filter out enter presses */
77
78 if (choice == EOF)
79- exit(1);
80+ exit(USAGE_OR_SYNTAX_ERROR);
81
82 printf("%c\n", choice);
83
84@@ -235,7 +235,7 @@ int get_choice(int noninteractive_result, const char *noninteractive_msg,
85 inhibit_quit_choice = 0;
86
87 if (quit_choice == 1)
88- exit(0);
89+ exit(NO_ERRORS);
90 }
91 }
92
93diff --git a/src/exit_codes.h b/src/exit_codes.h
94new file mode 100644
95index 0000000..f67d22e
96--- /dev/null
97+++ b/src/exit_codes.h
98@@ -0,0 +1,15 @@
99+#ifndef _EXIT_CODES_H
100+#define _EXIT_CODES_H
101+
102+/* Codes as defined by fsck.
103+ For more information, see fsck manpage. */
104+#define NO_ERRORS 0
105+#define FS_ERRORS_CORRECTED 1
106+#define SYSTEM_SHOULD_BE_REBOOTED 2
107+#define FS_ERRORS_LEFT_UNCORRECTED 4
108+#define OPERATIONAL_ERROR 8
109+#define USAGE_OR_SYNTAX_ERROR 16
110+#define CHECKING_CANCELED_BY_USER 32
111+#define SHARED_LIB_ERROR 128
112+
113+#endif
114diff --git a/src/fsck.fat.c b/src/fsck.fat.c
115index 8b02b57..42e3ab4 100644
116--- a/src/fsck.fat.c
117+++ b/src/fsck.fat.c
118@@ -46,6 +46,7 @@
119 #include "file.h"
120 #include "check.h"
121 #include "charconv.h"
122+#include "exit_codes.h"
123
124 int rw = 0, list = 0, test = 0, verbose = 0;
125 long fat_table = 0;
126@@ -147,10 +148,10 @@ int main(int argc, char **argv)
127 codepage = strtol(optarg, &tmp, 10);
128 if (!*optarg || isspace(*optarg) || *tmp || errno || codepage < 0 || codepage > INT_MAX) {
129 fprintf(stderr, "Invalid codepage : %s\n", optarg);
130- usage(argv[0], 2);
131+ usage(argv[0], USAGE_OR_SYNTAX_ERROR);
132 }
133 if (!set_dos_codepage(codepage))
134- usage(argv[0], 2);
135+ usage(argv[0], USAGE_OR_SYNTAX_ERROR);
136 break;
137 case 'd':
138 file_add(optarg, fdt_drop);
139@@ -163,7 +164,7 @@ int main(int argc, char **argv)
140 fat_table = strtol(optarg, &tmp, 10);
141 if (!*optarg || isspace(*optarg) || *tmp || errno || fat_table < 0 || fat_table > 255) {
142 fprintf(stderr, "Invalid FAT table : %s\n", optarg);
143- usage(argv[0], 2);
144+ usage(argv[0], USAGE_OR_SYNTAX_ERROR);
145 }
146 break;
147 case 'l':
148@@ -202,31 +203,31 @@ int main(int argc, char **argv)
149 atari_format = 1;
150 } else {
151 fprintf(stderr, "Unknown variant: %s\n", optarg);
152- usage(argv[0], 2);
153+ usage(argv[0], USAGE_OR_SYNTAX_ERROR);
154 }
155 break;
156 case 'w':
157 write_immed = 1;
158 break;
159 case OPT_HELP:
160- usage(argv[0], 0);
161+ usage(argv[0], EXIT_SUCCESS);
162 break;
163 case '?':
164- usage(argv[0], 2);
165+ usage(argv[0], USAGE_OR_SYNTAX_ERROR);
166 break;
167 default:
168 fprintf(stderr,
169 "Internal error: getopt_long() returned unexpected value %d\n", c);
170- exit(3);
171+ exit(OPERATIONAL_ERROR);
172 }
173 if (!set_dos_codepage(-1)) /* set default codepage if none was given in command line */
174- exit(2);
175+ exit(OPERATIONAL_ERROR);
176 if ((test || write_immed) && !rw) {
177 fprintf(stderr, "-t and -w can not be used in read only mode\n");
178- exit(2);
179+ exit(USAGE_OR_SYNTAX_ERROR);
180 }
181 if (optind != argc - 1)
182- usage(argv[0], 2);
183+ usage(argv[0], USAGE_OR_SYNTAX_ERROR);
184
185 printf("fsck.fat " VERSION " (" VERSION_DATE ")\n");
186 fs_open(argv[optind], rw);
187@@ -285,5 +286,5 @@ exit:
188 n_files, (unsigned long)fs.data_clusters - free_clusters,
189 (unsigned long)fs.data_clusters);
190
191- return fs_close(rw) ? 1 : 0;
192+ return fs_close(rw) ? FS_ERRORS_CORRECTED : NO_ERRORS;
193 }
194diff --git a/src/io.c b/src/io.c
195index 8c0c3b2..8bd1ae5 100644
196--- a/src/io.c
197+++ b/src/io.c
198@@ -44,6 +44,7 @@
199 #include "fsck.fat.h"
200 #include "common.h"
201 #include "io.h"
202+#include "exit_codes.h"
203
204 typedef struct _change {
205 void *data;
206@@ -60,7 +61,7 @@ void fs_open(const char *path, int rw)
207 {
208 if ((fd = open(path, rw ? O_RDWR : O_RDONLY)) < 0) {
209 perror("open");
210- exit(6);
211+ exit(OPERATIONAL_ERROR);
212 }
213 changes = last = NULL;
214 did_change = 0;
diff --git a/meta/recipes-devtools/dosfstools/dosfstools/0002-manpages-Document-fsck.fat-new-exit-codes.patch b/meta/recipes-devtools/dosfstools/dosfstools/0002-manpages-Document-fsck.fat-new-exit-codes.patch
new file mode 100644
index 0000000000..29bba7b093
--- /dev/null
+++ b/meta/recipes-devtools/dosfstools/dosfstools/0002-manpages-Document-fsck.fat-new-exit-codes.patch
@@ -0,0 +1,46 @@
1From 8d703216d2ea3247092a08adb0c37b38eb77ccc7 Mon Sep 17 00:00:00 2001
2From: Ricardo Ungerer <ungerer.ricardo@gmail.com>
3Date: Wed, 21 May 2025 07:18:15 +0100
4Subject: [PATCH 2/3] manpages: Document fsck.fat new exit codes
5
6Signed-off-by: Ricardo Ungerer <ungerer.ricardo@gmail.com>
7
8Upstream-Status: Inactive-Upstream [lastcommit: 2023, lastrelease: 2021]
9Upstream-Status: Submitted [https://github.com/dosfstools/dosfstools/pull/217]
10---
11 manpages/fsck.fat.8.in | 18 +++++++++++++-----
12 1 file changed, 13 insertions(+), 5 deletions(-)
13
14diff --git a/manpages/fsck.fat.8.in b/manpages/fsck.fat.8.in
15index 824a83d..557aa4c 100644
16--- a/manpages/fsck.fat.8.in
17+++ b/manpages/fsck.fat.8.in
18@@ -222,13 +222,21 @@ Display help message describing usage and options then exit.
19 .\" ----------------------------------------------------------------------------
20 .SH "EXIT STATUS"
21 .IP "0" 4
22-No recoverable errors have been detected.
23+No errors
24 .IP "1" 4
25-Recoverable errors have been detected or \fBfsck.fat\fP has discovered an
26-internal inconsistency.
27+Filesystem errors corrected
28 .IP "2" 4
29-Usage error.
30-\fBfsck.fat\fP did not access the filesystem.
31+System should be rebooted
32+.IP "4" 4
33+Filesystem errors left uncorrected
34+.IP "8" 4
35+Operational error
36+.IP "16" 4
37+Usage or syntax error
38+.IP "32" 4
39+Checking canceled by user request
40+.IP "128" 4
41+Shared-library error
42 .\" ----------------------------------------------------------------------------
43 .SH FILES
44 .IP "\fIfsck0000.rec\fP, \fIfsck0001.rec\fP, ..." 4
45--
462.25.1
diff --git a/meta/recipes-devtools/dosfstools/dosfstools_4.2.bb b/meta/recipes-devtools/dosfstools/dosfstools_4.2.bb
index 175fa265ef..86fb68f664 100644
--- a/meta/recipes-devtools/dosfstools/dosfstools_4.2.bb
+++ b/meta/recipes-devtools/dosfstools/dosfstools_4.2.bb
@@ -10,11 +10,12 @@ LICENSE = "GPL-3.0-only"
10LIC_FILES_CHKSUM = "file://COPYING;md5=d32239bcb673463ab874e80d47fae504" 10LIC_FILES_CHKSUM = "file://COPYING;md5=d32239bcb673463ab874e80d47fae504"
11 11
12SRC_URI = "${GITHUB_BASE_URI}/download/v${PV}/${BP}.tar.gz \ 12SRC_URI = "${GITHUB_BASE_URI}/download/v${PV}/${BP}.tar.gz \
13 " 13 file://source-date-epoch.patch \
14 file://0001-fsck.fat-Adhere-to-the-fsck-exit-codes.patch \
15 file://0002-manpages-Document-fsck.fat-new-exit-codes.patch \
16 "
14SRC_URI[sha256sum] = "64926eebf90092dca21b14259a5301b7b98e7b1943e8a201c7d726084809b527" 17SRC_URI[sha256sum] = "64926eebf90092dca21b14259a5301b7b98e7b1943e8a201c7d726084809b527"
15 18
16SRC_URI += "file://source-date-epoch.patch"
17
18inherit autotools gettext pkgconfig update-alternatives github-releases 19inherit autotools gettext pkgconfig update-alternatives github-releases
19 20
20EXTRA_OECONF = "--enable-compat-symlinks --without-iconv" 21EXTRA_OECONF = "--enable-compat-symlinks --without-iconv"