summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoy Marples <uberlord@gentoo.org>2007-09-15 08:54:26 +0000
committerRoy Marples <uberlord@gentoo.org>2007-09-15 08:54:26 +0000
commit840285b032d45d8f0657fcf94e24da403fc70779 (patch)
tree81de2f812f747b5fe2ecbbd897b5d8bf8d04a0dc /sys-fs/e2fsprogs
parentfix #192289 (diff)
downloadhistorical-840285b032d45d8f0657fcf94e24da403fc70779.tar.gz
historical-840285b032d45d8f0657fcf94e24da403fc70779.tar.bz2
historical-840285b032d45d8f0657fcf94e24da403fc70779.zip
Add the fsck_ext2fs helper and man page for FreeBSD and add a patch for 1.40.2 to work on FreeBSD.
Package-Manager: portage-2.1.3.9
Diffstat (limited to 'sys-fs/e2fsprogs')
-rw-r--r--sys-fs/e2fsprogs/ChangeLog8
-rw-r--r--sys-fs/e2fsprogs/Manifest38
-rw-r--r--sys-fs/e2fsprogs/e2fsprogs-1.40.2.ebuild31
-rw-r--r--sys-fs/e2fsprogs/files/e2fsprogs-1.40-fbsd.patch21
-rw-r--r--sys-fs/e2fsprogs/files/fsck_ext2fs.896
-rw-r--r--sys-fs/e2fsprogs/files/fsck_ext2fs.c147
6 files changed, 315 insertions, 26 deletions
diff --git a/sys-fs/e2fsprogs/ChangeLog b/sys-fs/e2fsprogs/ChangeLog
index ba8bcab81515..da05700f0b44 100644
--- a/sys-fs/e2fsprogs/ChangeLog
+++ b/sys-fs/e2fsprogs/ChangeLog
@@ -1,6 +1,12 @@
# ChangeLog for sys-fs/e2fsprogs
# Copyright 1999-2007 Gentoo Foundation; Distributed under the GPL v2
-# $Header: /var/cvsroot/gentoo-x86/sys-fs/e2fsprogs/ChangeLog,v 1.110 2007/07/14 17:19:03 vapier Exp $
+# $Header: /var/cvsroot/gentoo-x86/sys-fs/e2fsprogs/ChangeLog,v 1.111 2007/09/15 08:54:25 uberlord Exp $
+
+ 15 Sep 2007; Roy Marples <uberlord@gentoo.org> +files/fsck_ext2fs.8,
+ +files/e2fsprogs-1.40-fbsd.patch, +files/fsck_ext2fs.c,
+ e2fsprogs-1.40.2.ebuild:
+ Add the fsck_ext2fs helper and man page for FreeBSD and add a patch for
+ 1.40.2 to work on FreeBSD.
*e2fsprogs-1.40.2 (14 Jul 2007)
diff --git a/sys-fs/e2fsprogs/Manifest b/sys-fs/e2fsprogs/Manifest
index d362c5936751..a7500928cd4b 100644
--- a/sys-fs/e2fsprogs/Manifest
+++ b/sys-fs/e2fsprogs/Manifest
@@ -1,6 +1,3 @@
------BEGIN PGP SIGNED MESSAGE-----
-Hash: SHA1
-
AUX e2fsprogs-1.32-mk_cmds-cosmetic.patch 316 RMD160 42dae53c318fb52b39c8e1d357974111bf8712bf SHA1 2515d77050072bcd1ae7defa90f32fb101ac01c5 SHA256 182da8741b852fdaf2d17a485da0451ec0c665adb83327b29b3372e2e43f712a
MD5 1a896f2697b055d4b8b4139c3482ac9e files/e2fsprogs-1.32-mk_cmds-cosmetic.patch 316
RMD160 42dae53c318fb52b39c8e1d357974111bf8712bf files/e2fsprogs-1.32-mk_cmds-cosmetic.patch 316
@@ -41,10 +38,22 @@ AUX e2fsprogs-1.39-util-strptime.patch 178 RMD160 04d8e04d5e04f9a927a76b36a072c5
MD5 1fafebe6571f92773e2773deef654d16 files/e2fsprogs-1.39-util-strptime.patch 178
RMD160 04d8e04d5e04f9a927a76b36a072c50fb80eae84 files/e2fsprogs-1.39-util-strptime.patch 178
SHA256 fa300c80bbd679967ff74c361b63a9610f911b0916eff38fd491b797c0ff99c5 files/e2fsprogs-1.39-util-strptime.patch 178
+AUX e2fsprogs-1.40-fbsd.patch 646 RMD160 c0cf25c094ecad52464716f4031d9d43a1496ce1 SHA1 b6b1140b5877fafe4b03e0b7215f6fa62899055e SHA256 9320846955a3f258d888af0181bb0ee74d32cd3cc6ab8bcb31531447479bb72f
+MD5 cc8abe69b45243ddd16a9ef3912734be files/e2fsprogs-1.40-fbsd.patch 646
+RMD160 c0cf25c094ecad52464716f4031d9d43a1496ce1 files/e2fsprogs-1.40-fbsd.patch 646
+SHA256 9320846955a3f258d888af0181bb0ee74d32cd3cc6ab8bcb31531447479bb72f files/e2fsprogs-1.40-fbsd.patch 646
AUX e2fsprogs-1.40-libintl.patch 395 RMD160 dc4216ba03bc4e530b499198838f5c5625d7f245 SHA1 59c50cc94f27537bc7e93094b919faf82b6512b7 SHA256 fb56042fde8e1cb0a22e3c76c3381ba39449ee151c95d437a267c5188dfdd6b1
MD5 2b3e72dc3791ae92ec98b5c937f88942 files/e2fsprogs-1.40-libintl.patch 395
RMD160 dc4216ba03bc4e530b499198838f5c5625d7f245 files/e2fsprogs-1.40-libintl.patch 395
SHA256 fb56042fde8e1cb0a22e3c76c3381ba39449ee151c95d437a267c5188dfdd6b1 files/e2fsprogs-1.40-libintl.patch 395
+AUX fsck_ext2fs.8 3806 RMD160 193e4e01508ad363c28c8d5feb124f65d59a76eb SHA1 dff54a3149f8d6187f6481c428d4b980c3abfb97 SHA256 fc1155e67f17aebc8762d75a25d25511a1463be3da05baf7a322d0b5f91938e0
+MD5 a689cd9a4217895c01c91c9e697f8416 files/fsck_ext2fs.8 3806
+RMD160 193e4e01508ad363c28c8d5feb124f65d59a76eb files/fsck_ext2fs.8 3806
+SHA256 fc1155e67f17aebc8762d75a25d25511a1463be3da05baf7a322d0b5f91938e0 files/fsck_ext2fs.8 3806
+AUX fsck_ext2fs.c 2797 RMD160 b5a58058b90876d11286ffb12de75bdbf6a064e3 SHA1 c0027c5e031b87dd8a5d50a3a256ac7637e59fd3 SHA256 a7c3614e76c89ab7882191c14a469789d4b5b54f3c61c5888e5bd72840816e22
+MD5 5afe4af9fb6c7069c01e66e282fec576 files/fsck_ext2fs.c 2797
+RMD160 b5a58058b90876d11286ffb12de75bdbf6a064e3 files/fsck_ext2fs.c 2797
+SHA256 a7c3614e76c89ab7882191c14a469789d4b5b54f3c61c5888e5bd72840816e22 files/fsck_ext2fs.c 2797
DIST e2fsprogs-1.39.tar.gz 3695111 RMD160 67e77a7cbf0e719fa8b5a8ac6285b334e1c3481b SHA1 c2dad0c9bd76701eafe3804e2a7d072aa198f046 SHA256 dc2033447e69a1612881151f6f163e8a3b80e51d16f5e8b3576f3f8ccb325ea3
DIST e2fsprogs-1.40.1.tar.gz 3957193 RMD160 5b468a143ac73da34601ad2d2f358e60091b4f08 SHA1 86e4d29accdd2a5d439940bd5c0551cfcbe875b7 SHA256 5db8bd0d4af126a112e784d40f81187a1d111d36e7b86a6ef993806a6ee02d39
DIST e2fsprogs-1.40.2.tar.gz 3965919 RMD160 6e4ec42d50fa6f0762b5c4f58c09a0fa71a9af79 SHA1 65519d66bd15550d0bcd32ec72481ff0dbe737e2 SHA256 8bbdfd8866b60edec27fee58611d98ef841892c4e2cd0f0dacf194f20a716a63
@@ -62,18 +71,18 @@ EBUILD e2fsprogs-1.40.1.ebuild 3584 RMD160 bed78e0da855c8fb36f6a7e8a91e73c28327a
MD5 8c13b4ab7a190d040dd5402aa79b34f5 e2fsprogs-1.40.1.ebuild 3584
RMD160 bed78e0da855c8fb36f6a7e8a91e73c28327ab75 e2fsprogs-1.40.1.ebuild 3584
SHA256 f273f0dafcf092c546856519d02e78e2d4e164921352231c15836f533f778b67 e2fsprogs-1.40.1.ebuild 3584
-EBUILD e2fsprogs-1.40.2.ebuild 3584 RMD160 56d9cb0ca03357e92f8441d7e7d1a8ba00501ba6 SHA1 4a9b194d50082dc81f07d21f0a11f6f301b7f0fc SHA256 4d71537f6d42bca6e54b930832d439e64271480a0d5c8b3b73424cc0d965cc30
-MD5 e46b3a53115165a216a68e69cd1d4d6a e2fsprogs-1.40.2.ebuild 3584
-RMD160 56d9cb0ca03357e92f8441d7e7d1a8ba00501ba6 e2fsprogs-1.40.2.ebuild 3584
-SHA256 4d71537f6d42bca6e54b930832d439e64271480a0d5c8b3b73424cc0d965cc30 e2fsprogs-1.40.2.ebuild 3584
+EBUILD e2fsprogs-1.40.2.ebuild 3973 RMD160 3e48c9d123cb5b15050a5322ec839ffcdb6dc2a3 SHA1 47a1e4aaef7f7258d1b8c5b9a167ed68f4e4d089 SHA256 9f714fbbc1a70117ad002de8926bf171f67ed5ffede53bf889c85cf09eaa24fb
+MD5 e809b207b836867744344a8fa99df150 e2fsprogs-1.40.2.ebuild 3973
+RMD160 3e48c9d123cb5b15050a5322ec839ffcdb6dc2a3 e2fsprogs-1.40.2.ebuild 3973
+SHA256 9f714fbbc1a70117ad002de8926bf171f67ed5ffede53bf889c85cf09eaa24fb e2fsprogs-1.40.2.ebuild 3973
EBUILD e2fsprogs-1.40.ebuild 3755 RMD160 4f4be7e00db70e664bcd2decd8bca753c1986846 SHA1 21a478adcb58d2c8d08a7851f39369eaaa03bf27 SHA256 4d29aba74951e171b0c80037181a6f178288190db8bd892aea61876d7105b30a
MD5 b55a92cff12ba7d74ecc90caaec63aa3 e2fsprogs-1.40.ebuild 3755
RMD160 4f4be7e00db70e664bcd2decd8bca753c1986846 e2fsprogs-1.40.ebuild 3755
SHA256 4d29aba74951e171b0c80037181a6f178288190db8bd892aea61876d7105b30a e2fsprogs-1.40.ebuild 3755
-MISC ChangeLog 17819 RMD160 9073dcb2f55e6add6e28e92f4eeb72a8a8949f96 SHA1 8c53365dd9ba878b88eb6b7fed15ebdc7a471c8c SHA256 0524b9538b583eca04b3d31db05fd264fbe0db896886a56e8ec91e3f8ec1fc2a
-MD5 41fbeade092c4e637d9e7ce4eddc7bcb ChangeLog 17819
-RMD160 9073dcb2f55e6add6e28e92f4eeb72a8a8949f96 ChangeLog 17819
-SHA256 0524b9538b583eca04b3d31db05fd264fbe0db896886a56e8ec91e3f8ec1fc2a ChangeLog 17819
+MISC ChangeLog 18081 RMD160 047f161984f594db257cc7e940cd98a16d566f18 SHA1 5f74e50f4063e4c0fbcdf15846947c1e128102d1 SHA256 954cde43c0e3b5c4dfec3cac293f2ab9bfa2f18464237aead3ad77520f7bfe35
+MD5 2c5525c71f0e07b05d952ce5d80252be ChangeLog 18081
+RMD160 047f161984f594db257cc7e940cd98a16d566f18 ChangeLog 18081
+SHA256 954cde43c0e3b5c4dfec3cac293f2ab9bfa2f18464237aead3ad77520f7bfe35 ChangeLog 18081
MISC metadata.xml 164 RMD160 f43cbec30b7074319087c9acffdb9354b17b0db3 SHA1 9c213f5803676c56439df3716be07d6692588856 SHA256 f5f2891f2a4791cd31350bb2bb572131ad7235cd0eeb124c9912c187ac10ce92
MD5 9a09f8d531c582e78977dbfd96edc1f2 metadata.xml 164
RMD160 f43cbec30b7074319087c9acffdb9354b17b0db3 metadata.xml 164
@@ -93,10 +102,3 @@ SHA256 34fc9d99ddb2ac1455d1eb05a649862baa502d24becbd4d952389d34498b1fe9 files/di
MD5 4dfbb4dfcdb81f785ddc91f3307408ed files/digest-e2fsprogs-1.40.2 253
RMD160 e4d75313507a8be6e01cfffe25055b77f885bc86 files/digest-e2fsprogs-1.40.2 253
SHA256 68110f35f1b48f57c5da0f660ab454bc56debab94691022394ab4722f698b992 files/digest-e2fsprogs-1.40.2 253
------BEGIN PGP SIGNATURE-----
-Version: GnuPG v2.0.5 (GNU/Linux)
-
-iD8DBQFGmQWmp/wUKkr7RBoRAhozAKCUNf06kNVIGK+8A/LKIeXK718n1gCfeuYY
-/jNu7/VtswVZTBj9vYwRZlw=
-=KMzC
------END PGP SIGNATURE-----
diff --git a/sys-fs/e2fsprogs/e2fsprogs-1.40.2.ebuild b/sys-fs/e2fsprogs/e2fsprogs-1.40.2.ebuild
index eaf2f9fdcb55..7fcbda07b4a8 100644
--- a/sys-fs/e2fsprogs/e2fsprogs-1.40.2.ebuild
+++ b/sys-fs/e2fsprogs/e2fsprogs-1.40.2.ebuild
@@ -1,6 +1,6 @@
# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/sys-fs/e2fsprogs/e2fsprogs-1.40.2.ebuild,v 1.1 2007/07/14 17:19:03 vapier Exp $
+# $Header: /var/cvsroot/gentoo-x86/sys-fs/e2fsprogs/e2fsprogs-1.40.2.ebuild,v 1.2 2007/09/15 08:54:25 uberlord Exp $
inherit eutils flag-o-matic toolchain-funcs
@@ -10,7 +10,7 @@ SRC_URI="mirror://sourceforge/e2fsprogs/${P}.tar.gz"
LICENSE="GPL-2 BSD"
SLOT="0"
-KEYWORDS="~alpha ~amd64 ~arm ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86"
+KEYWORDS="~alpha ~amd64 ~arm ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~x86-fbsd"
IUSE="nls static"
RDEPEND="~sys-libs/com_err-${PV}
@@ -31,6 +31,9 @@ src_unpack() {
epatch "${FILESDIR}"/e2fsprogs-1.39-makefile.patch
epatch "${FILESDIR}"/${PN}-1.40-libintl.patch #122368
+ # Fix compile on FreeBSD
+ epatch "${FILESDIR}"/${PN}-1.40-fbsd.patch
+
# kernel headers use the same defines as e2fsprogs and can cause issues #48829
sed -i \
-e 's:CONFIG_JBD_DEBUG:__CONFIG_JBD_DEBUG__E2FS:g' \
@@ -58,9 +61,9 @@ src_unpack() {
src_compile() {
# Keep the package from doing silly things
- export LDCONFIG=/bin/true
+ export LDCONFIG=:
export CC=$(tc-getCC)
- export STRIP=/bin/true
+ export STRIP=:
econf \
--bindir=/bin \
@@ -80,6 +83,11 @@ src_compile() {
fi
# Parallel make sometimes fails
emake -j1 COMPILE_ET=compile_et || die
+
+ # Build the FreeBSD helper
+ if use elibc_FreeBSD ; then
+ ${CC} "${FILESDIR}"/fsck_ext2fs.c -o fsck_ext2fs || die
+ fi
}
src_install() {
@@ -104,8 +112,17 @@ src_install() {
dosbin "${D}"/sbin/mklost+found
rm -f "${D}"/sbin/mklost+found
- # these manpages are already provided by FreeBSD libc
- use elibc_FreeBSD && \
- rm -f "${D}"/usr/share/man/man3/{uuid,uuid_compare}.3 \
+ if use elibc_FreeBSD ; then
+ # Install helpers for us
+ dosbin "${S}"/fsck_ext2fs
+ doman "${FILESDIR}"/fsck_ext2fs.8
+
+ # these manpages are already provided by FreeBSD libc
+ # and filefrag is linux only
+ rm -f \
+ "${D}"/sbin/filefrag
+ "${D}"/usr/share/man/man8/filefrag.8
+ "${D}"/usr/share/man/man3/{uuid,uuid_compare}.3 \
"${D}"/usr/share/man/man1/uuidgen.1
+ fi
}
diff --git a/sys-fs/e2fsprogs/files/e2fsprogs-1.40-fbsd.patch b/sys-fs/e2fsprogs/files/e2fsprogs-1.40-fbsd.patch
new file mode 100644
index 000000000000..616a638ef32c
--- /dev/null
+++ b/sys-fs/e2fsprogs/files/e2fsprogs-1.40-fbsd.patch
@@ -0,0 +1,21 @@
+--- a/lib/ext2fs/tdb.c.orig Thu Apr 5 02:43:05 2007
++++ b/lib/ext2fs/tdb.c Sat Jun 30 16:13:15 2007
+@@ -36,7 +36,6 @@
+ #define HAVE_UTIME_H
+ #define HAVE_UTIME
+ #endif
+-#define _XOPEN_SOURCE 500
+
+ #include <unistd.h>
+ #include <stdio.h>
+--- a/lib/ext2fs/ext2_fs.h.orig Sat Jun 30 16:36:37 2007
++++ b/lib/ext2fs/ext2_fs.h Sat Jun 30 16:36:43 2007
+@@ -414,7 +414,7 @@
+
+ #define i_size_high i_dir_acl
+
+-#if defined(__KERNEL__) || defined(__linux__)
++#if defined(__KERNEL__) || defined(__linux__) || defined(__FreeBSD__)
+ #define i_reserved1 osd1.linux1.l_i_reserved1
+ #define i_frag osd2.linux2.l_i_frag
+ #define i_fsize osd2.linux2.l_i_fsize
diff --git a/sys-fs/e2fsprogs/files/fsck_ext2fs.8 b/sys-fs/e2fsprogs/files/fsck_ext2fs.8
new file mode 100644
index 000000000000..ee40b26b58e0
--- /dev/null
+++ b/sys-fs/e2fsprogs/files/fsck_ext2fs.8
@@ -0,0 +1,96 @@
+.TH fsck_ext2fs 8 2006-07-02 "Matthias Andree" "FreeBSD Ports"
+.\"
+.\" fsck_ext2fs.8 - manual page for fsck_ext2fs wrapper
+.\"
+.\" (C) Copyright 2006 by Matthias Andree <matthias.andree@gmx.de>
+.\"
+.\" License: This file may be redistributed in accordance with the terms
+.\" of the GNU General Public License v2.
+.\"
+.\" Upstream $Id: fsck_ext2fs.8,v 1.1 2007/09/15 08:54:26 uberlord Exp $
+.\" $FreeBSD: ports/sysutils/e2fsprogs/files/fsck_ext2fs.8,v 1.1 2006/07/04 15:47:51 leeym Exp $
+.\"
+.SH NAME
+.B fsck_ext2fs
+\- compatibility wrapper for e2fsck
+.SH SYNOPSIS
+.P
+.B fsck_ext2fs
+[\fB\-Fpfnyv\fR] [\fB\-b\fR \fIblock\fR]
+.SH DESCRIPTION
+.P
+\fBfsck_ext2fs\fR maps the traditional FreeBSD \fBfsck_ffs\fR options to
+options with the same functionality for \fBe2fsck,\fR runs \fBe2fsck\fR
+and then maps its exit status to values that FreeBSD understands.
+\fBe2fsck\fR is a utility to check and repair ext2 and ext3 file
+systems.
+
+.SH OPTIONS
+.IP \fB\-F\fR
+(check foreground mode required) Immediately exits with status 1 to tell
+\fBfsck\fR that ext2fs cannot be checked in the background. \fBfsck\fR
+usually runs \fBfsck_*\fR programs twice, first with \fB\-F\fR to find
+out if they can do background checking, then either immediately without
+\fB\-F\fR for foreground checking or deferred in the background with
+\fB\-B\fR.
+.IP \fB\-p\fR
+(preen mode) This option suppresses adding the \fB\-f\fR option (unless
+\fB\-f\fR is also given) and adds the \fB\-p\fR option to the
+\fBe2fsck\fR command line. This causes \fBe2fsck\fR to automatically fix
+any filesystem problems that can safely be fixed without operator
+intervention. Without this option given, \fBe2fsck\fR will be run with
+the \fB\-f\fR option to force a check, since interactive scan and repair
+mode is the default on FreeBSD, but not on Linux where \fBe2fsck\fR
+comes from.
+.IP \fB\-f\fR
+(force check) This option forces the check of a clean file system while
+preening and is passed to \fBe2fsck\fR verbatim.
+.IP \fB\-n\fR
+("no" mode) This option causes the file system to be opened in read-only
+mode and assume "no" as answer to all questions. This is the only way to
+safely run \fBfsck\fR on a mounted ext2 or ext3 file system. This option
+is passed to \fBe2fsck\fR verbatim.
+.IP \fB\-y\fR
+("yes" mode) This option is passed verbatim to \fBe2fsck\fR and causes
+it to assume "yes" as answer to all questions. This allows the
+non-interactive use of e2fsck but is rather aggressive. Use with care.
+.IP \fB\-v\fR
+(verbose output) This option is passed verbatim to \fBe2fsck\fR and
+causes it to verbosely report its progress.
+.IP "\fB\-b\fR \fIblock\fR"
+(use alternate super block) This option is passed verbatim to
+\fBe2fsck\fR and selects an alternate super block, for use when the
+primary super block has been damaged. Please see the \fBe2fsck\fR(8)
+manual page for details.
+
+.SH EXIT STATUS
+If errors remain after \fBe2fsck\fR, an invalid option or too many
+options have been specified, \fBe2fsck\fR was killed with a signal or
+the \fIfork\fB system call failed, \fBfsck_ext2fs\fR exits with status
+EXIT_FAILURE (usually 1). If \fBe2fsck\fR cannot be started, exits with
+status 127. If the file system is clean after \fBe2fsck\fR operation,
+exits with status EXIT_SUCCESS (0).
+
+.SH NOTES
+.P
+This utility is merely meant as an adaptor so that \fBe2fsck\fR can be
+run during the boot process, it does not support all options that
+\fBe2fsck\fR offers. If you need one of its advanced options, please run
+\fBe2fsck\fR directly.
+
+.SH FILES
+.TP
+.I /sbin/e2fsck
+is the location of the \fBe2fsck\fR program to run.
+
+.SH AUTHOR
+.P
+Matthias Andree <matthias.andree@gmx.de> wrote the program and this
+manual page.
+.SH CONFORMING TO
+The FreeBSD 6.1 command line interface for \fBfsck_ufs\fR(8).
+.SH SEE ALSO
+.BR fsck (8),
+.BR e2fsck (8)
+and
+.BR fsck_ufs (8).
diff --git a/sys-fs/e2fsprogs/files/fsck_ext2fs.c b/sys-fs/e2fsprogs/files/fsck_ext2fs.c
new file mode 100644
index 000000000000..0b6a74ee0aab
--- /dev/null
+++ b/sys-fs/e2fsprogs/files/fsck_ext2fs.c
@@ -0,0 +1,147 @@
+/*
+ * fsck_ext2fs - wrapper for e2fsck on FreeBSD
+ * Copyright (C) 2004,2006 Matthias Andree <matthias.andree@gmx.de>
+ * redistributable in accordance with the
+ * GNU General Public License v2
+ *
+ * $FreeBSD: ports/sysutils/e2fsprogs/files/fsck_ext2fs.c,v 1.5 2006/07/04 15:47:51 leeym Exp $
+ *
+ * Upstream: $Id: fsck_ext2fs.c,v 1.1 2007/09/15 08:54:26 uberlord Exp $
+ *
+ * format: gindent -kr
+ */
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/wait.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <errno.h>
+
+__attribute__ ((noreturn))
+static int die(const char *tag)
+{
+ perror(tag);
+ exit(EXIT_FAILURE);
+}
+
+int main(int argc, char **argv)
+{
+ int ch, i = 1, force = 0, status, verbose = 0, t;
+ long block = 0;
+ enum { normal, preen, yes, no } mode = normal;
+ char *cmd[256];
+ pid_t pid;
+
+ cmd[0] = "/sbin/e2fsck";
+ while ((ch = getopt(argc, argv, "BFpfnyb:v")) != -1) {
+ switch (ch) {
+ case 'p':
+ mode = preen;
+ break;
+ case 'f':
+ force = 1;
+ break;
+ case 'n':
+ mode = no;
+ break;
+ case 'y':
+ mode = yes;
+ break;
+ case 'b':
+ block = atol(optarg);
+ break;
+ case 'v':
+ verbose++;
+ break;
+ case 'F':
+ /* e2fsck does not support background checking,
+ * hence exit with nonzero status to force
+ * the foreground check. */
+ exit(1);
+ case 'B':
+ default:
+ fprintf(stderr, "%s: unknown option -%c\n",
+ argv[0], optopt);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (force)
+ cmd[i++] = "-f";
+
+ switch (mode) {
+ case normal:
+ /* FreeBSD needs -f to force a check only in context
+ * with -p -- so map normal to force to match
+ * expectations */
+ if (!force)
+ cmd[i++] = "-f";
+ break;
+ case yes:
+ cmd[i++] = "-y";
+ break;
+ case no:
+ cmd[i++] = "-n";
+ break;
+ case preen:
+ cmd[i++] = "-p";
+ break;
+ }
+
+ if (block) {
+ static char b[30];
+
+ sprintf(b, "-b %ld", block);
+ cmd[i++] = b;
+ }
+
+ /* silently limit verbose to 15 so we don't overflow the cmd array */
+ if (verbose > 15)
+ verbose = 15;
+
+ for (t = verbose; t > 1; t--)
+ cmd[i++] = "-v";
+
+ while (optind < argc) {
+ cmd[i++] = argv[optind++];
+ /* sanity check so we don't overflow the cmd buffer */
+ if (i+1 == sizeof(cmd)/sizeof(cmd[0])) {
+ errno = E2BIG;
+ die(argv[0]);
+ }
+ }
+
+ cmd[i++] = 0;
+
+ if (verbose) {
+ for (i=0; cmd[i]; i++)
+ fputs(cmd[i], stderr),
+ fputc(' ', stderr);
+ fputc('\n', stderr);
+ }
+
+ pid = fork();
+ switch (pid) {
+ case -1:
+ /* error */
+ die("fork");
+ break;
+ case 0:
+ /* child */
+ (void) execv(cmd[0], cmd);
+ perror("execve");
+ _exit(127);
+ default:
+ /* parent */
+ if (pid != waitpid(pid, &status, 0))
+ die("waitpid");
+ if (WIFSIGNALED(status)
+ || (WIFEXITED(status) && WEXITSTATUS(status) >= 4))
+ exit(EXIT_FAILURE);
+ }
+ exit(EXIT_SUCCESS);
+}