lakitu:Adding e2fsprogs to the overlay-lakitu

cherry-pick the upstream change to package
(retry_reading_superblock_on_open_when_checksum_is_bad)
BUG=b/151453112
TEST=emerge-lakitu e2fsprogs

Change-Id: I70f67f24bb30f6d9dacf9cac8687a98c921bc8bb
diff --git a/overlay-lakitu/profiles/base/package.mask b/overlay-lakitu/profiles/base/package.mask
index b168123..1ad4d4a 100644
--- a/overlay-lakitu/profiles/base/package.mask
+++ b/overlay-lakitu/profiles/base/package.mask
@@ -1,5 +1,7 @@
 # Mask audit from portage-stable
 sys-process/audit::portage-stable
 sys-apps/shadow::portage-stable
+# Mask e2fsprogs from portage-stable
+sys-fs/e2fsprogs::portage-stable
 # Mask audit from chromiumos-overlay
 sys-process/audit::chromiumos
diff --git a/overlay-lakitu/sys-fs/e2fsprogs/Manifest b/overlay-lakitu/sys-fs/e2fsprogs/Manifest
new file mode 100644
index 0000000..f31a0f8
--- /dev/null
+++ b/overlay-lakitu/sys-fs/e2fsprogs/Manifest
@@ -0,0 +1,2 @@
+DIST e2fsprogs-1.42.9-mint-r1.patch.xz 9012 BLAKE2B ae6421587c3cca2f9b26805c5f8d236d3fecde78cc7df3776ae9c23c7f254d7240e06507568fdd2154a16113c47609a8143535ab9cb2925426d3c578d077ce26 SHA512 591a7c80d65082eebcdc455028be6ade05c9aae96c94f654106be0facef330a8875dae82891e6e3ad2b48dece2b4e1c1940dbc47cd3eba3e6eea3b5ddba9a8fc
+DIST e2fsprogs-1.45.5.tar.xz 5569796 BLAKE2B cf9633caa6c00afa51408364d0c0a1515a9989ad1582fb485a300fd71bf61ec56b57dbb26f152609eaf2d63bfb04fe1e3f271085c26aa0c832c1f467960e6480 SHA512 d1a8611b525742387061f390fb24825dfa175997cc7db05decea913fcc7b97a95a3e787091f2920d4a7d4eb1d813568af734a1610229ead09bcbf9f3e262e4ce
diff --git a/overlay-lakitu/sys-fs/e2fsprogs/e2fsprogs-1.45.5-r1.ebuild b/overlay-lakitu/sys-fs/e2fsprogs/e2fsprogs-1.45.5-r1.ebuild
new file mode 120000
index 0000000..824ebdb
--- /dev/null
+++ b/overlay-lakitu/sys-fs/e2fsprogs/e2fsprogs-1.45.5-r1.ebuild
@@ -0,0 +1 @@
+e2fsprogs-1.45.5.ebuild
\ No newline at end of file
diff --git a/overlay-lakitu/sys-fs/e2fsprogs/e2fsprogs-1.45.5.ebuild b/overlay-lakitu/sys-fs/e2fsprogs/e2fsprogs-1.45.5.ebuild
new file mode 100644
index 0000000..a274644
--- /dev/null
+++ b/overlay-lakitu/sys-fs/e2fsprogs/e2fsprogs-1.45.5.ebuild
@@ -0,0 +1,146 @@
+# Copyright 1999-2020 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=7
+
+inherit flag-o-matic systemd toolchain-funcs udev usr-ldscript
+
+DESCRIPTION="Standard EXT2/EXT3/EXT4 filesystem utilities"
+HOMEPAGE="http://e2fsprogs.sourceforge.net/"
+SRC_URI="mirror://sourceforge/e2fsprogs/${P}.tar.xz
+	https://www.kernel.org/pub/linux/kernel/people/tytso/e2fsprogs/v${PV}/${P}.tar.xz
+	elibc_mintlib? ( mirror://gentoo/${PN}-1.42.9-mint-r1.patch.xz )"
+
+LICENSE="GPL-2 BSD"
+SLOT="0"
+KEYWORDS="*"
+IUSE="cron fuse nls static-libs elibc_FreeBSD"
+
+RDEPEND="~sys-libs/${PN}-libs-${PV}
+	>=sys-apps/util-linux-2.16
+	cron? ( sys-fs/lvm2[-device-mapper-only(-)] )
+	fuse? ( sys-fs/fuse:0 )
+	nls? ( virtual/libintl )"
+DEPEND="${RDEPEND}"
+BDEPEND="
+	nls? ( sys-devel/gettext )
+	virtual/pkgconfig
+	sys-apps/texinfo
+"
+
+PATCHES=(
+	"${FILESDIR}"/${PN}-1.40-fbsd.patch
+	"${FILESDIR}"/${PN}-1.42.13-fix-build-cflags.patch #516854
+	# cherry picked the change b/151453112 to fix the issue where resize partition
+	# service fails and partition doesn't grow - will be removed after next e2fsprogs release.
+	"${FILESDIR}"/retry_reading_superblock_on_open_when_checksum_is_bad.patch
+
+	# Upstream patches (can usually removed with next version bump)
+)
+
+src_prepare() {
+	if [[ ${CHOST} == *-mint* ]] ; then
+		PATCHES+=( "${WORKDIR}"/${PN}-1.42.9-mint-r1.patch )
+	fi
+
+	default
+
+	cp doc/RelNotes/v${PV}.txt ChangeLog || die "Failed to copy Release Notes"
+
+	# Get rid of doc -- we don't use them. This also prevents a sandbox
+	# violation due to mktexfmt invocation
+	rm -r doc || die "Failed to remove doc dir"
+
+	# blargh ... trick e2fsprogs into using e2fsprogs-libs
+	sed -i -r \
+		-e 's:@LIBINTL@:@LTLIBINTL@:' \
+		-e '/^(STATIC_)?LIB(COM_ERR|SS)/s:[$][(]LIB[)]/lib([^@]*)@(STATIC_)?LIB_EXT@:-l\1:' \
+		-e '/^DEP(STATIC_)?LIB(COM_ERR|SS)/s:=.*:=:' \
+		MCONFIG.in || die "muck libs" #122368
+	sed -i -r \
+		-e '/^LIB_SUBDIRS/s:lib/(et|ss)::g' \
+		Makefile.in || die "remove subdirs"
+	ln -s $(which mk_cmds) lib/ss/ || die
+
+	# Avoid rebuild
+	echo '#include_next <ss/ss_err.h>' > lib/ss/ss_err.h
+}
+
+src_configure() {
+	# Keep the package from doing silly things #261411
+	export VARTEXFONTS="${T}/fonts"
+
+	# needs open64() prototypes and friends
+	append-cppflags -D_GNU_SOURCE
+
+	local myeconfargs=(
+		--with-root-prefix="${EPREFIX}"
+		$(use_with cron crond-dir "${EPREFIX}/etc/cron.d")
+		--with-systemd-unit-dir="$(systemd_get_systemunitdir)"
+		--with-udev-rules-dir="${EPREFIX}$(get_udevdir)/rules.d"
+		--enable-symlink-install
+		--enable-elf-shlibs
+		$(tc-has-tls || echo --disable-tls)
+		--without-included-gettext
+		$(use_enable fuse fuse2fs)
+		$(use_enable nls)
+		--disable-libblkid
+		--disable-libuuid
+		--disable-fsck
+		--disable-uuidd
+	)
+	ac_cv_path_LDCONFIG=: econf "${myeconfargs[@]}"
+
+	if [[ ${CHOST} != *-uclibc ]] && grep -qs 'USE_INCLUDED_LIBINTL.*yes' config.{log,status} ; then
+		eerror "INTL sanity check failed, aborting build."
+		eerror "Please post your ${S}/config.log file as an"
+		eerror "attachment to https://bugs.gentoo.org/show_bug.cgi?id=81096"
+		die "Preventing included intl cruft from building"
+	fi
+}
+
+src_compile() {
+	emake V=1 COMPILE_ET=compile_et MK_CMDS=mk_cmds
+
+	# Build the FreeBSD helper
+	if use elibc_FreeBSD ; then
+		cp "${FILESDIR}"/fsck_ext2fs.c .
+		emake V=1 fsck_ext2fs
+	fi
+}
+
+src_install() {
+	# need to set root_libdir= manually as any --libdir options in the
+	# econf above (i.e. multilib) will screw up the default #276465
+	emake \
+		STRIP=: \
+		root_libdir="${EPREFIX}/usr/$(get_libdir)" \
+		DESTDIR="${D}" \
+		install
+
+	einstalldocs
+
+	insinto /etc
+	doins "${FILESDIR}"/e2fsck.conf
+
+	# Move shared libraries to /lib/, install static libraries to
+	# /usr/lib/, and install linker scripts to /usr/lib/.
+	gen_usr_ldscript -a e2p ext2fs
+
+	# configure doesn't have an option to disable static libs :/
+	if ! use static-libs ; then
+		find "${ED}" -name '*.a' -delete || die
+	fi
+
+	if use elibc_FreeBSD ; then
+		# Install helpers for us
+		into /
+		dosbin "${S}"/fsck_ext2fs
+		doman "${FILESDIR}"/fsck_ext2fs.8
+
+		# filefrag is linux only
+		rm \
+			"${ED}"/usr/sbin/filefrag \
+			"${ED}"/usr/share/man/man8/filefrag.8 || die
+	fi
+}
diff --git a/overlay-lakitu/sys-fs/e2fsprogs/files/e2fsck.conf b/overlay-lakitu/sys-fs/e2fsprogs/files/e2fsck.conf
new file mode 100644
index 0000000..401cec4
--- /dev/null
+++ b/overlay-lakitu/sys-fs/e2fsprogs/files/e2fsck.conf
@@ -0,0 +1,6 @@
+# See the e2fsck.conf man page for more info
+
+[options]
+
+# allow fsck to run sanely at any point in time #142850
+buggy_init_scripts = yes
diff --git a/overlay-lakitu/sys-fs/e2fsprogs/files/e2fsprogs-1.40-fbsd.patch b/overlay-lakitu/sys-fs/e2fsprogs/files/e2fsprogs-1.40-fbsd.patch
new file mode 100644
index 0000000..7d09196
--- /dev/null
+++ b/overlay-lakitu/sys-fs/e2fsprogs/files/e2fsprogs-1.40-fbsd.patch
@@ -0,0 +1,11 @@
+--- a/lib/ext2fs/ext2_fs.h
++++ b/lib/ext2fs/ext2_fs.h
+@@ -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/overlay-lakitu/sys-fs/e2fsprogs/files/e2fsprogs-1.42.13-fix-build-cflags.patch b/overlay-lakitu/sys-fs/e2fsprogs/files/e2fsprogs-1.42.13-fix-build-cflags.patch
new file mode 100644
index 0000000..dcab9a3
--- /dev/null
+++ b/overlay-lakitu/sys-fs/e2fsprogs/files/e2fsprogs-1.42.13-fix-build-cflags.patch
@@ -0,0 +1,13 @@
+https://bugs.gentoo.org/516854
+
+--- e2fsprogs-1.42.13/configure
++++ e2fsprogs-1.42.13/configure
+@@ -1315,6 +1315,8 @@
+ if test $cross_compiling = no; then
+    BUILD_CFLAGS="$CFLAGS $CPPFLAGS $INCLUDES -DHAVE_CONFIG_H"
+    BUILD_LDFLAGS="$LDFLAGS"
++else
++   BUILD_CFLAGS="$INCLUDES"
+ fi
+ 
+ 
diff --git a/overlay-lakitu/sys-fs/e2fsprogs/files/fsck_ext2fs.8 b/overlay-lakitu/sys-fs/e2fsprogs/files/fsck_ext2fs.8
new file mode 100644
index 0000000..aa31cf1
--- /dev/null
+++ b/overlay-lakitu/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.3 2006/07/02 11:45:21 emma 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/overlay-lakitu/sys-fs/e2fsprogs/files/fsck_ext2fs.c b/overlay-lakitu/sys-fs/e2fsprogs/files/fsck_ext2fs.c
new file mode 100644
index 0000000..f5e3e5e
--- /dev/null
+++ b/overlay-lakitu/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.6 2006/07/02 11:37:49 emma 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);
+}
diff --git a/overlay-lakitu/sys-fs/e2fsprogs/files/retry_reading_superblock_on_open_when_checksum_is_bad.patch b/overlay-lakitu/sys-fs/e2fsprogs/files/retry_reading_superblock_on_open_when_checksum_is_bad.patch
new file mode 100644
index 0000000..8ad6bbe
--- /dev/null
+++ b/overlay-lakitu/sys-fs/e2fsprogs/files/retry_reading_superblock_on_open_when_checksum_is_bad.patch
@@ -0,0 +1,32 @@
+
+--- a/lib/ext2fs/openfs.c
++++ b/lib/ext2fs/openfs.c
+@@ -134,6 +134,7 @@ errcode_t ext2fs_open2(const char *name, const char *io_options,
+ 	int		j;
+ #endif
+ 	char		*time_env;
++	int		csum_retries = 0;
+ 
+ 	EXT2_CHECK_MAGIC(manager, EXT2_ET_MAGIC_IO_MANAGER);
+ 
+@@ -221,6 +222,7 @@ errcode_t ext2fs_open2(const char *name, const char *io_options,
+ 		if (retval)
+ 			goto cleanup;
+ 	}
++retry:
+ 	retval = io_channel_read_blk(fs->io, superblock, -SUPERBLOCK_SIZE,
+ 				     fs->super);
+ 	if (retval)
+@@ -232,8 +234,11 @@ errcode_t ext2fs_open2(const char *name, const char *io_options,
+ 		retval = 0;
+ 		if (!ext2fs_verify_csum_type(fs, fs->super))
+ 			retval = EXT2_ET_UNKNOWN_CSUM;
+-		if (!ext2fs_superblock_csum_verify(fs, fs->super))
++		if (!ext2fs_superblock_csum_verify(fs, fs->super)) {
++			if (csum_retries++ < 3)
++				goto retry;
+ 			retval = EXT2_ET_SB_CSUM_INVALID;
++		}
+ 	}
+ 
+ #ifdef WORDS_BIGENDIAN
diff --git a/overlay-lakitu/sys-fs/e2fsprogs/metadata.xml b/overlay-lakitu/sys-fs/e2fsprogs/metadata.xml
new file mode 100644
index 0000000..fd22991
--- /dev/null
+++ b/overlay-lakitu/sys-fs/e2fsprogs/metadata.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+<maintainer type="project">
+	<email>base-system@gentoo.org</email>
+	<name>Gentoo Base System</name>
+</maintainer>
+<use>
+	<flag name="cron">Install e2scrub_all cron script</flag>
+	<flag name='fuse'>Build fuse2fs, a FUSE file system client for ext2/ext3/ext4 file systems</flag>
+</use>
+<upstream>
+	<remote-id type="cpe">cpe:/a:e2fsprogs_project:e2fsprogs</remote-id>
+	<remote-id type="sourceforge">e2fsprogs</remote-id>
+</upstream>
+</pkgmetadata>