summaryrefslogtreecommitdiffstats
path: root/misc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-21 04:59:33 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-21 04:59:33 +0000
commit73193347133e750faf27f88fd3ab31ce43aff062 (patch)
treee28a6d9512d1787b1fcbe9167188c9d134bf51d9 /misc
parentAdding upstream version 1.47.0. (diff)
downloade2fsprogs-73193347133e750faf27f88fd3ab31ce43aff062.tar.xz
e2fsprogs-73193347133e750faf27f88fd3ab31ce43aff062.zip
Adding upstream version 1.47.1.upstream/1.47.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'misc')
-rw-r--r--misc/Android.bp7
-rw-r--r--misc/Makefile.in20
-rw-r--r--misc/create_inode.c73
-rw-r--r--misc/create_inode.h10
-rw-r--r--misc/create_inode_libarchive.c704
-rw-r--r--misc/create_inode_libarchive.h10
-rw-r--r--misc/dumpe2fs.c12
-rw-r--r--misc/e2freefrag.c4
-rw-r--r--misc/e2fuzz.c1
-rw-r--r--misc/e2image.c8
-rw-r--r--misc/e2undo.c6
-rw-r--r--misc/e4crypt.c2
-rw-r--r--misc/e4defrag.c5
-rw-r--r--misc/ext4.5.in1
-rw-r--r--misc/findsuper.c9
-rw-r--r--misc/fsck.c1
-rw-r--r--misc/fuse2fs.c99
-rw-r--r--misc/lsattr.1.in4
-rw-r--r--misc/mke2fs.8.in25
-rw-r--r--misc/mke2fs.c72
-rw-r--r--misc/mklost+found.8.in6
-rw-r--r--misc/tune2fs.c43
22 files changed, 998 insertions, 124 deletions
diff --git a/misc/Android.bp b/misc/Android.bp
index 0656bf4..4edac23 100644
--- a/misc/Android.bp
+++ b/misc/Android.bp
@@ -18,6 +18,7 @@ cc_library {
name: "libext2_misc",
host_supported: true,
recovery_available: true,
+ vendor_available: true,
defaults: ["e2fsprogs-defaults"],
target: {
@@ -58,6 +59,7 @@ cc_defaults {
cc_binary {
name: "mke2fs",
host_supported: true,
+ vendor_available: true,
defaults: ["mke2fs_defaults"],
target: {
host: {
@@ -126,7 +128,7 @@ cc_binary {
symlinks: ["mkfs.ext4.microdroid"],
},
},
- installable: false,
+ no_full_install: true,
stem: "mke2fs",
visibility: ["//packages/modules/Virtualization/microdroid"],
}
@@ -191,9 +193,8 @@ cc_library_static {
//########################################################################
// Build badblocks
-cc_binary {
+cc_binary_host {
name: "badblocks",
- host_supported: true,
defaults: ["e2fsprogs-defaults"],
srcs: ["badblocks.c"],
diff --git a/misc/Makefile.in b/misc/Makefile.in
index e5420bb..8769620 100644
--- a/misc/Makefile.in
+++ b/misc/Makefile.in
@@ -56,7 +56,7 @@ LPROGS= @E2INITRD_PROG@
TUNE2FS_OBJS= tune2fs.o util.o journal.o recovery.o revoke.o
MKLPF_OBJS= mklost+found.o
MKE2FS_OBJS= mke2fs.o util.o default_profile.o mk_hugefiles.o \
- create_inode.o
+ create_inode.o create_inode_libarchive.o
CHATTR_OBJS= chattr.o
LSATTR_OBJS= lsattr.o
UUIDGEN_OBJS= uuidgen.o
@@ -80,7 +80,8 @@ PROFILED_MKLPF_OBJS= profiled/mklost+found.o
PROFILED_MKE2FS_OBJS= profiled/mke2fs.o profiled/util.o \
profiled/default_profile.o \
profiled/mk_hugefiles.o \
- profiled/create_inode.o
+ profiled/create_inode.o \
+ profiled/create_inode_libarchive.o
PROFILED_CHATTR_OBJS= profiled/chattr.o
PROFILED_LSATTR_OBJS= profiled/lsattr.o
PROFILED_UUIDGEN_OBJS= profiled/uuidgen.o
@@ -106,6 +107,7 @@ SRCS= $(srcdir)/tune2fs.c $(srcdir)/mklost+found.c $(srcdir)/mke2fs.c $(srcdir)/
$(srcdir)/filefrag.c $(srcdir)/base_device.c \
$(srcdir)/ismounted.c $(srcdir)/e2undo.c \
$(srcdir)/e2freefrag.c $(srcdir)/create_inode.c \
+ $(srcdir)/create_inode_libarchive.c \
$(srcdir)/fuse2fs.c $(srcdir)/e2fuzz.c \
$(srcdir)/check_fuzzer.c \
$(srcdir)/../debugfs/journal.c $(srcdir)/../e2fsck/revoke.c \
@@ -281,7 +283,7 @@ mke2fs: $(MKE2FS_OBJS) $(DEPLIBS) $(LIBE2P) $(DEPLIBBLKID) $(DEPLIBUUID) \
$(E) " LD $@"
$(Q) $(CC) $(ALL_LDFLAGS) -o mke2fs $(MKE2FS_OBJS) $(LIBS) $(LIBBLKID) \
$(LIBUUID) $(LIBEXT2FS) $(LIBE2P) $(LIBINTL) \
- $(SYSLIBS) $(LIBMAGIC)
+ $(SYSLIBS) $(LIBMAGIC) $(LIBARCHIVE)
mke2fs.static: $(MKE2FS_OBJS) $(STATIC_DEPLIBS) $(STATIC_LIBE2P) $(DEPSTATIC_LIBUUID) \
$(DEPSTATIC_LIBBLKID)
@@ -289,7 +291,7 @@ mke2fs.static: $(MKE2FS_OBJS) $(STATIC_DEPLIBS) $(STATIC_LIBE2P) $(DEPSTATIC_LIB
$(Q) $(CC) $(LDFLAGS_STATIC) -o mke2fs.static $(MKE2FS_OBJS) \
$(STATIC_LIBS) $(STATIC_LIBE2P) \
$(STATIC_LIBBLKID) $(STATIC_LIBUUID) $(LIBINTL) $(SYSLIBS) \
- $(LIBMAGIC)
+ $(LIBMAGIC) $(LIBARCHIVE)
mke2fs.profiled: $(MKE2FS_OBJS) $(PROFILED_DEPLIBS) \
$(PROFILED_LIBE2P) $(PROFILED_DEPLIBBLKID) $(PROFILED_DEPLIBUUID)
@@ -856,6 +858,16 @@ create_inode.o: $(srcdir)/create_inode.c $(top_builddir)/lib/config.h \
$(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/hashmap.h \
$(top_srcdir)/lib/ext2fs/bitops.h $(top_srcdir)/lib/ext2fs/fiemap.h \
$(srcdir)/create_inode.h $(top_srcdir)/lib/e2p/e2p.h \
+ $(top_srcdir)/lib/support/nls-enable.h $(srcdir)/create_inode_libarchive.h
+create_inode_libarchive.o: $(srcdir)/create_inode_libarchive.c \
+ $(top_builddir)/lib/config.h $(top_builddir)/lib/dirpaths.h \
+ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/create_inode.h \
+ $(top_srcdir)/lib/et/com_err.h $(top_srcdir)/lib/e2p/e2p.h \
+ $(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_srcdir)/lib/ext2fs/ext2fs.h \
+ $(top_srcdir)/lib/ext2fs/ext3_extents.h $(top_srcdir)/lib/ext2fs/ext2_io.h \
+ $(top_builddir)/lib/ext2fs/ext2_err.h \
+ $(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/hashmap.h \
+ $(top_srcdir)/lib/ext2fs/bitops.h $(srcdir)/create_inode_libarchive.h \
$(top_srcdir)/lib/support/nls-enable.h
fuse2fs.o: $(srcdir)/fuse2fs.c $(top_builddir)/lib/config.h \
$(top_builddir)/lib/dirpaths.h $(top_srcdir)/lib/ext2fs/ext2fs.h \
diff --git a/misc/create_inode.c b/misc/create_inode.c
index a3a34cd..4e292a2 100644
--- a/misc/create_inode.c
+++ b/misc/create_inode.c
@@ -9,7 +9,6 @@
* %End-Header%
*/
-#define _FILE_OFFSET_BITS 64
#define _LARGEFILE64_SOURCE 1
#define _GNU_SOURCE 1
@@ -39,6 +38,8 @@
#include "create_inode.h"
#include "support/nls-enable.h"
+#include "create_inode_libarchive.h"
+
/* 64KiB is the minimum blksize to best minimize system call overhead. */
#define COPY_FILE_BUFLEN 65536
@@ -69,7 +70,7 @@ static int ext2_file_type(unsigned int mode)
}
/* Link an inode number to a directory */
-static errcode_t add_link(ext2_filsys fs, ext2_ino_t parent_ino,
+errcode_t add_link(ext2_filsys fs, ext2_ino_t parent_ino,
ext2_ino_t ino, const char *name)
{
struct ext2_inode inode;
@@ -107,9 +108,16 @@ static errcode_t add_link(ext2_filsys fs, ext2_ino_t parent_ino,
return retval;
}
+static time_t clamped_time(ext2_filsys fs, time_t t)
+{
+ if ((fs->flags2 & EXT2_FLAG2_USE_FAKE_TIME) && t > fs->now)
+ return fs->now;
+ return t;
+}
+
/* Set the uid, gid, mode and time for the inode */
-static errcode_t set_inode_extra(ext2_filsys fs, ext2_ino_t ino,
- struct stat *st)
+errcode_t set_inode_extra(ext2_filsys fs, ext2_ino_t ino,
+ const struct stat *st)
{
errcode_t retval;
struct ext2_inode inode;
@@ -125,9 +133,9 @@ static errcode_t set_inode_extra(ext2_filsys fs, ext2_ino_t ino,
inode.i_gid = st->st_gid;
ext2fs_set_i_gid_high(inode, st->st_gid >> 16);
inode.i_mode = (LINUX_S_IFMT & inode.i_mode) | (~S_IFMT & st->st_mode);
- inode.i_atime = st->st_atime;
- inode.i_mtime = st->st_mtime;
- inode.i_ctime = st->st_ctime;
+ ext2fs_inode_xtime_set(&inode, i_atime, clamped_time(fs, st->st_atime));
+ ext2fs_inode_xtime_set(&inode, i_ctime, clamped_time(fs, st->st_ctime));
+ ext2fs_inode_xtime_set(&inode, i_mtime, clamped_time(fs, st->st_mtime));
retval = ext2fs_write_inode(fs, ino, &inode);
if (retval)
@@ -256,6 +264,7 @@ errcode_t do_mknod_internal(ext2_filsys fs, ext2_ino_t cwd, const char *name,
struct ext2_inode inode;
unsigned long devmajor, devminor, mode;
int filetype;
+ time_t now;
switch(st_mode & S_IFMT) {
case S_IFCHR:
@@ -309,8 +318,10 @@ errcode_t do_mknod_internal(ext2_filsys fs, ext2_ino_t cwd, const char *name,
ext2fs_inode_alloc_stats2(fs, ino, +1, 0);
memset(&inode, 0, sizeof(inode));
inode.i_mode = mode;
- inode.i_atime = inode.i_ctime = inode.i_mtime =
- fs->now ? fs->now : time(0);
+ now = fs->now ? fs->now : time(0);
+ ext2fs_inode_xtime_set(&inode, i_atime, now);
+ ext2fs_inode_xtime_set(&inode, i_ctime, now);
+ ext2fs_inode_xtime_set(&inode, i_mtime, now);
if (filetype != S_IFIFO) {
devmajor = major(st_rdev);
@@ -631,6 +642,7 @@ errcode_t do_write_internal(ext2_filsys fs, ext2_ino_t cwd, const char *src,
errcode_t retval;
struct ext2_inode inode;
char *cp;
+ time_t now;
fd = ext2fs_open_file(src, O_RDONLY, 0);
if (fd < 0) {
@@ -684,8 +696,10 @@ errcode_t do_write_internal(ext2_filsys fs, ext2_ino_t cwd, const char *src,
ext2fs_inode_alloc_stats2(fs, newfile, +1, 0);
memset(&inode, 0, sizeof(inode));
inode.i_mode = (statbuf.st_mode & ~S_IFMT) | LINUX_S_IFREG;
- inode.i_atime = inode.i_ctime = inode.i_mtime =
- fs->now ? fs->now : time(0);
+ now = fs->now ? fs->now : time(0);
+ ext2fs_inode_xtime_set(&inode, i_atime, now);
+ ext2fs_inode_xtime_set(&inode, i_ctime, now);
+ ext2fs_inode_xtime_set(&inode, i_mtime, now);
inode.i_links_count = 1;
retval = ext2fs_inode_size_set(fs, &inode, statbuf.st_size);
if (retval)
@@ -720,12 +734,6 @@ out:
return retval;
}
-struct file_info {
- char *path;
- size_t path_len;
- size_t path_max_len;
-};
-
static errcode_t path_append(struct file_info *target, const char *file)
{
if (strlen(file) + target->path_len + 1 > target->path_max_len) {
@@ -1044,7 +1052,7 @@ out:
}
errcode_t populate_fs2(ext2_filsys fs, ext2_ino_t parent_ino,
- const char *source_dir, ext2_ino_t root,
+ const char *source, ext2_ino_t root,
struct fs_ops_callbacks *fs_callbacks)
{
struct file_info file_info;
@@ -1069,14 +1077,35 @@ errcode_t populate_fs2(ext2_filsys fs, ext2_ino_t parent_ino,
file_info.path_max_len = 255;
file_info.path = calloc(file_info.path_max_len, 1);
- retval = set_inode_xattr(fs, root, source_dir);
+ /* interpret input as tarball either if it's "-" (stdin) or if it's
+ * a regular file (or a symlink pointing to a regular file)
+ */
+ if (strcmp(source, "-") == 0) {
+ retval = __populate_fs_from_tar(fs, parent_ino, NULL, root, &hdlinks,
+ &file_info, fs_callbacks);
+ goto out;
+ }
+
+ struct stat st;
+ if (stat(source, &st)) {
+ retval = errno;
+ com_err(__func__, retval, _("while calling stat"));
+ return retval;
+ }
+ if (S_ISREG(st.st_mode)) {
+ retval = __populate_fs_from_tar(fs, parent_ino, source, root, &hdlinks,
+ &file_info, fs_callbacks);
+ goto out;
+ }
+
+ retval = set_inode_xattr(fs, root, source);
if (retval) {
com_err(__func__, retval,
_("while copying xattrs on root directory"));
goto out;
}
- retval = __populate_fs(fs, parent_ino, source_dir, root, &hdlinks,
+ retval = __populate_fs(fs, parent_ino, source, root, &hdlinks,
&file_info, fs_callbacks);
out:
@@ -1086,7 +1115,7 @@ out:
}
errcode_t populate_fs(ext2_filsys fs, ext2_ino_t parent_ino,
- const char *source_dir, ext2_ino_t root)
+ const char *source, ext2_ino_t root)
{
- return populate_fs2(fs, parent_ino, source_dir, root, NULL);
+ return populate_fs2(fs, parent_ino, source, root, NULL);
}
diff --git a/misc/create_inode.h b/misc/create_inode.h
index b5eeb42..c75d685 100644
--- a/misc/create_inode.h
+++ b/misc/create_inode.h
@@ -22,6 +22,12 @@ struct hdlinks_s
struct hdlink_s *hdl;
};
+struct file_info {
+ char *path;
+ size_t path_len;
+ size_t path_max_len;
+};
+
#define HDLINK_CNT (4)
struct fs_ops_callbacks {
@@ -53,5 +59,9 @@ extern errcode_t do_mkdir_internal(ext2_filsys fs, ext2_ino_t cwd,
extern errcode_t do_write_internal(ext2_filsys fs, ext2_ino_t cwd,
const char *src, const char *dest,
ext2_ino_t root);
+extern errcode_t add_link(ext2_filsys fs, ext2_ino_t parent_ino,
+ ext2_ino_t ino, const char *name);
+extern errcode_t set_inode_extra(ext2_filsys fs, ext2_ino_t ino,
+ const struct stat *st);
#endif /* _CREATE_INODE_H */
diff --git a/misc/create_inode_libarchive.c b/misc/create_inode_libarchive.c
new file mode 100644
index 0000000..8705eb1
--- /dev/null
+++ b/misc/create_inode_libarchive.c
@@ -0,0 +1,704 @@
+/*
+ * create_inode_libarchive.c --- create an inode from libarchive input
+ *
+ * Copyright (C) 2023 Johannes Schauer Marin Rodrigues <josch@debian.org>
+ *
+ * %Begin-Header%
+ * This file may be redistributed under the terms of the GNU library
+ * General Public License, version 2.
+ * %End-Header%
+ */
+
+#define _LARGEFILE64_SOURCE 1
+#define _GNU_SOURCE 1
+
+#include "config.h"
+#include <ext2fs/ext2_types.h>
+#include "create_inode.h"
+#include "create_inode_libarchive.h"
+#include "support/nls-enable.h"
+
+#ifdef HAVE_ARCHIVE_H
+
+/* 64KiB is the minimum blksize to best minimize system call overhead. */
+//#define COPY_FILE_BUFLEN 65536
+//#define COPY_FILE_BUFLEN 1048576
+#define COPY_FILE_BUFLEN 16777216
+
+#include <archive.h>
+#include <archive_entry.h>
+#include <libgen.h>
+#include <locale.h>
+
+static const char *(*dl_archive_entry_hardlink)(struct archive_entry *);
+static const char *(*dl_archive_entry_pathname)(struct archive_entry *);
+static const struct stat *(*dl_archive_entry_stat)(struct archive_entry *);
+static const char *(*dl_archive_entry_symlink)(struct archive_entry *);
+static int (*dl_archive_entry_xattr_count)(struct archive_entry *);
+static int (*dl_archive_entry_xattr_next)(struct archive_entry *, const char **,
+ const void **, size_t *);
+static int (*dl_archive_entry_xattr_reset)(struct archive_entry *);
+static const char *(*dl_archive_error_string)(struct archive *);
+static int (*dl_archive_read_close)(struct archive *);
+static la_ssize_t (*dl_archive_read_data)(struct archive *, void *, size_t);
+static int (*dl_archive_read_free)(struct archive *);
+static struct archive *(*dl_archive_read_new)(void);
+static int (*dl_archive_read_next_header)(struct archive *,
+ struct archive_entry **);
+static int (*dl_archive_read_open_filename)(struct archive *,
+ const char *filename, size_t);
+static int (*dl_archive_read_support_filter_all)(struct archive *);
+static int (*dl_archive_read_support_format_all)(struct archive *);
+
+#ifdef CONFIG_DLOPEN_LIBARCHIVE
+#include <dlfcn.h>
+
+static void *libarchive_handle;
+
+#if defined(__FreeBSD__)
+#define LIBARCHIVE_SO "libarchive.so.7"
+#else
+#define LIBARCHIVE_SO "libarchive.so.13"
+#endif
+
+static int libarchive_available(void)
+{
+ if (!libarchive_handle) {
+ libarchive_handle = dlopen(LIBARCHIVE_SO, RTLD_NOW);
+ if (!libarchive_handle)
+ return 0;
+
+ dl_archive_entry_hardlink =
+ (const char *(*)(struct archive_entry *))dlsym(
+ libarchive_handle, "archive_entry_hardlink");
+ if (!dl_archive_entry_hardlink)
+ return 0;
+ dl_archive_entry_pathname =
+ (const char *(*)(struct archive_entry *))dlsym(
+ libarchive_handle, "archive_entry_pathname");
+ if (!dl_archive_entry_pathname)
+ return 0;
+ dl_archive_entry_stat =
+ (const struct stat *(*)(struct archive_entry *))dlsym(
+ libarchive_handle, "archive_entry_stat");
+ if (!dl_archive_entry_stat)
+ return 0;
+ dl_archive_entry_symlink =
+ (const char *(*)(struct archive_entry *))dlsym(
+ libarchive_handle, "archive_entry_symlink");
+ if (!dl_archive_entry_symlink)
+ return 0;
+ dl_archive_entry_xattr_count =
+ (int (*)(struct archive_entry *))dlsym(
+ libarchive_handle, "archive_entry_xattr_count");
+ if (!dl_archive_entry_xattr_count)
+ return 0;
+ dl_archive_entry_xattr_next = (int (*)(
+ struct archive_entry *, const char **, const void **,
+ size_t *))dlsym(libarchive_handle,
+ "archive_entry_xattr_next");
+ if (!dl_archive_entry_xattr_next)
+ return 0;
+ dl_archive_entry_xattr_reset =
+ (int (*)(struct archive_entry *))dlsym(
+ libarchive_handle, "archive_entry_xattr_reset");
+ if (!dl_archive_entry_xattr_reset)
+ return 0;
+ dl_archive_error_string =
+ (const char *(*)(struct archive *))dlsym(
+ libarchive_handle, "archive_error_string");
+ if (!dl_archive_error_string)
+ return 0;
+ dl_archive_read_close = (int (*)(struct archive *))dlsym(
+ libarchive_handle, "archive_read_close");
+ if (!dl_archive_read_close)
+ return 0;
+ dl_archive_read_data =
+ (la_ssize_t(*)(struct archive *, void *, size_t))dlsym(
+ libarchive_handle, "archive_read_data");
+ if (!dl_archive_read_data)
+ return 0;
+ dl_archive_read_free = (int (*)(struct archive *))dlsym(
+ libarchive_handle, "archive_read_free");
+ if (!dl_archive_read_free)
+ return 0;
+ dl_archive_read_new = (struct archive * (*)(void))
+ dlsym(libarchive_handle, "archive_read_new");
+ if (!dl_archive_read_new)
+ return 0;
+ dl_archive_read_next_header = (int (*)(struct archive *,
+ struct archive_entry **))
+ dlsym(libarchive_handle, "archive_read_next_header");
+ if (!dl_archive_read_next_header)
+ return 0;
+ dl_archive_read_open_filename =
+ (int (*)(struct archive *, const char *filename,
+ size_t))dlsym(libarchive_handle,
+ "archive_read_open_filename");
+ if (!dl_archive_read_open_filename)
+ return 0;
+ dl_archive_read_support_filter_all =
+ (int (*)(struct archive *))dlsym(
+ libarchive_handle,
+ "archive_read_support_filter_all");
+ if (!dl_archive_read_support_filter_all)
+ return 0;
+ dl_archive_read_support_format_all =
+ (int (*)(struct archive *))dlsym(
+ libarchive_handle,
+ "archive_read_support_format_all");
+ if (!dl_archive_read_support_format_all)
+ return 0;
+ }
+
+ return 1;
+}
+#else
+static int libarchive_available(void)
+{
+ dl_archive_entry_hardlink = archive_entry_hardlink;
+ dl_archive_entry_pathname = archive_entry_pathname;
+ dl_archive_entry_stat = archive_entry_stat;
+ dl_archive_entry_symlink = archive_entry_symlink;
+ dl_archive_entry_xattr_count = archive_entry_xattr_count;
+ dl_archive_entry_xattr_next = archive_entry_xattr_next;
+ dl_archive_entry_xattr_reset = archive_entry_xattr_reset;
+ dl_archive_error_string = archive_error_string;
+ dl_archive_read_close = archive_read_close;
+ dl_archive_read_data = archive_read_data;
+ dl_archive_read_free = archive_read_free;
+ dl_archive_read_new = archive_read_new;
+ dl_archive_read_next_header = archive_read_next_header;
+ dl_archive_read_open_filename = archive_read_open_filename;
+ dl_archive_read_support_filter_all = archive_read_support_filter_all;
+ dl_archive_read_support_format_all = archive_read_support_format_all;
+
+ return 1;
+}
+#endif
+
+static errcode_t __find_path(ext2_filsys fs, ext2_ino_t root, const char *name,
+ ext2_ino_t *inode)
+{
+ errcode_t retval = 0;
+ ext2_ino_t tmpino;
+ char *p, *n, *n2 = strdup(name);
+
+ if (n2 == NULL) {
+ retval = errno;
+ goto out;
+ }
+ n = n2;
+ *inode = root;
+ /* any number of leading slashes */
+ while (*n == '/')
+ n++;
+ while (*n) {
+ /* replace the next slash by a NULL, if any */
+ if ((p = strchr(n, '/')))
+ (*p) = 0;
+ /* find the inode of the next component */
+ retval = ext2fs_lookup(fs, *inode, n, strlen(n), 0, &tmpino);
+ if (retval)
+ goto out;
+ *inode = tmpino;
+ /* continue the search at the character after the slash */
+ if (p)
+ n = p + 1;
+ else
+ break;
+ }
+
+out:
+ free(n2);
+ return retval;
+}
+
+/* Rounds quantity up to a multiple of size. size should be a power of 2 */
+static inline unsigned int __round_up(unsigned int quantity, unsigned int size)
+{
+ return (quantity + (size - 1)) & ~(size - 1);
+}
+
+static int remove_inode(ext2_filsys fs, ext2_ino_t ino)
+{
+ errcode_t ret = 0;
+ struct ext2_inode_large inode;
+
+ memset(&inode, 0, sizeof(inode));
+ ret = ext2fs_read_inode_full(fs, ino, (struct ext2_inode *)&inode,
+ sizeof(inode));
+ if (ret)
+ goto out;
+
+ switch (inode.i_links_count) {
+ case 0:
+ return 0; /* XXX: already done? */
+ case 1:
+ inode.i_links_count--;
+ ext2fs_set_dtime(fs, EXT2_INODE(&inode));
+ break;
+ default:
+ inode.i_links_count--;
+ }
+
+ if (inode.i_links_count)
+ goto write_out;
+
+ /* Nobody holds this file; free its blocks! */
+ ret = ext2fs_free_ext_attr(fs, ino, &inode);
+ if (ret)
+ goto write_out;
+
+ if (ext2fs_inode_has_valid_blocks2(fs, (struct ext2_inode *)&inode)) {
+ ret = ext2fs_punch(fs, ino, (struct ext2_inode *)&inode, NULL,
+ 0, ~0ULL);
+ if (ret)
+ goto write_out;
+ }
+
+ ext2fs_inode_alloc_stats2(fs, ino, -1, LINUX_S_ISDIR(inode.i_mode));
+
+write_out:
+ ret = ext2fs_write_inode_full(fs, ino, (struct ext2_inode *)&inode,
+ sizeof(inode));
+ if (ret)
+ goto out;
+out:
+ return ret;
+}
+
+static errcode_t copy_file_chunk_tar(ext2_filsys fs, struct archive *archive,
+ ext2_file_t e2_file, off_t start,
+ off_t end, char *buf, char *zerobuf)
+{
+ off_t off, bpos;
+ ssize_t got, blen;
+ unsigned int written;
+ char *ptr;
+ errcode_t err = 0;
+
+ for (off = start; off < end; off += COPY_FILE_BUFLEN) {
+ got = dl_archive_read_data(archive, buf, COPY_FILE_BUFLEN);
+ if (got < 0) {
+ err = errno;
+ goto fail;
+ }
+ for (bpos = 0, ptr = buf; bpos < got; bpos += fs->blocksize) {
+ blen = fs->blocksize;
+ if (blen > got - bpos)
+ blen = got - bpos;
+ if (memcmp(ptr, zerobuf, blen) == 0) {
+ ptr += blen;
+ continue;
+ }
+ err = ext2fs_file_llseek(e2_file, off + bpos,
+ EXT2_SEEK_SET, NULL);
+ if (err)
+ goto fail;
+ while (blen > 0) {
+ err = ext2fs_file_write(e2_file, ptr, blen,
+ &written);
+ if (err)
+ goto fail;
+ if (written == 0) {
+ err = EIO;
+ goto fail;
+ }
+ blen -= written;
+ ptr += written;
+ }
+ }
+ }
+fail:
+ return err;
+}
+static errcode_t copy_file_tar(ext2_filsys fs, struct archive *archive,
+ const struct stat *statbuf, ext2_ino_t ino)
+{
+ ext2_file_t e2_file;
+ char *buf = NULL, *zerobuf = NULL;
+ errcode_t err, close_err;
+
+ err = ext2fs_file_open(fs, ino, EXT2_FILE_WRITE, &e2_file);
+ if (err)
+ return err;
+
+ err = ext2fs_get_mem(COPY_FILE_BUFLEN, &buf);
+ if (err)
+ goto out;
+
+ err = ext2fs_get_memzero(fs->blocksize, &zerobuf);
+ if (err)
+ goto out;
+
+ err = copy_file_chunk_tar(fs, archive, e2_file, 0, statbuf->st_size,
+ buf, zerobuf);
+out:
+ ext2fs_free_mem(&zerobuf);
+ ext2fs_free_mem(&buf);
+ close_err = ext2fs_file_close(e2_file);
+ if (err == 0)
+ err = close_err;
+ return err;
+}
+
+static errcode_t do_write_internal_tar(ext2_filsys fs, ext2_ino_t cwd,
+ struct archive *archive,
+ const char *dest,
+ const struct stat *statbuf)
+{
+ ext2_ino_t newfile;
+ errcode_t retval;
+ struct ext2_inode inode;
+
+ retval = ext2fs_new_inode(fs, cwd, 010755, 0, &newfile);
+ if (retval)
+ goto out;
+#ifdef DEBUGFS
+ printf("Allocated inode: %u\n", newfile);
+#endif
+ retval = ext2fs_link(fs, cwd, dest, newfile, EXT2_FT_REG_FILE);
+ if (retval == EXT2_ET_DIR_NO_SPACE) {
+ retval = ext2fs_expand_dir(fs, cwd);
+ if (retval)
+ goto out;
+ retval = ext2fs_link(fs, cwd, dest, newfile, EXT2_FT_REG_FILE);
+ }
+ if (retval)
+ goto out;
+ if (ext2fs_test_inode_bitmap2(fs->inode_map, newfile))
+ com_err(__func__, 0, "Warning: inode already set");
+ ext2fs_inode_alloc_stats2(fs, newfile, 1, 0);
+ memset(&inode, 0, sizeof(inode));
+ inode.i_mode = (statbuf->st_mode & ~S_IFMT) | LINUX_S_IFREG;
+ inode.i_atime = inode.i_ctime = inode.i_mtime = fs->now ? fs->now :
+ time(0);
+ inode.i_links_count = 1;
+ retval = ext2fs_inode_size_set(fs, &inode, statbuf->st_size);
+ if (retval)
+ goto out;
+ if (ext2fs_has_feature_inline_data(fs->super)) {
+ inode.i_flags |= EXT4_INLINE_DATA_FL;
+ } else if (ext2fs_has_feature_extents(fs->super)) {
+ ext2_extent_handle_t handle;
+
+ inode.i_flags &= ~EXT4_EXTENTS_FL;
+ retval = ext2fs_extent_open2(fs, newfile, &inode, &handle);
+ if (retval)
+ goto out;
+ ext2fs_extent_free(handle);
+ }
+
+ retval = ext2fs_write_new_inode(fs, newfile, &inode);
+ if (retval)
+ goto out;
+ if (inode.i_flags & EXT4_INLINE_DATA_FL) {
+ retval = ext2fs_inline_data_init(fs, newfile);
+ if (retval)
+ goto out;
+ }
+ if (LINUX_S_ISREG(inode.i_mode)) {
+ retval = copy_file_tar(fs, archive, statbuf, newfile);
+ if (retval)
+ goto out;
+ }
+out:
+ return retval;
+}
+
+static errcode_t set_inode_xattr_tar(ext2_filsys fs, ext2_ino_t ino,
+ struct archive_entry *entry)
+{
+ errcode_t retval, close_retval;
+ struct ext2_xattr_handle *handle;
+ ssize_t size;
+ const char *name;
+ const void *value;
+ size_t value_size;
+
+ if (no_copy_xattrs)
+ return 0;
+
+ size = dl_archive_entry_xattr_count(entry);
+ if (size == 0)
+ return 0;
+
+ retval = ext2fs_xattrs_open(fs, ino, &handle);
+ if (retval) {
+ if (retval == EXT2_ET_MISSING_EA_FEATURE)
+ return 0;
+ com_err(__func__, retval, _("while opening inode %u"), ino);
+ return retval;
+ }
+
+ retval = ext2fs_xattrs_read(handle);
+ if (retval) {
+ com_err(__func__, retval,
+ _("while reading xattrs for inode %u"), ino);
+ goto out;
+ }
+
+ dl_archive_entry_xattr_reset(entry);
+ while (dl_archive_entry_xattr_next(entry, &name, &value, &value_size) ==
+ ARCHIVE_OK) {
+ if (strcmp(name, "security.capability") != 0)
+ continue;
+
+ retval = ext2fs_xattr_set(handle, name, value, value_size);
+ if (retval) {
+ com_err(__func__, retval,
+ _("while writing attribute \"%s\" to inode %u"),
+ name, ino);
+ break;
+ }
+ }
+out:
+ close_retval = ext2fs_xattrs_close(&handle);
+ if (close_retval) {
+ com_err(__func__, retval, _("while closing inode %u"), ino);
+ retval = retval ? retval : close_retval;
+ }
+ return retval;
+}
+
+static errcode_t handle_entry(ext2_filsys fs, ext2_ino_t root_ino,
+ ext2_ino_t root, ext2_ino_t dirinode, char *name,
+ struct archive *a, struct archive_entry *entry,
+ const struct stat *st)
+{
+ errcode_t retval = 0;
+ char *ln_target;
+ ext2_ino_t tmpino;
+
+ switch (st->st_mode & S_IFMT) {
+ case S_IFCHR:
+ case S_IFBLK:
+ case S_IFIFO:
+ case S_IFSOCK:
+ retval = do_mknod_internal(fs, dirinode, name, st->st_mode,
+ st->st_rdev);
+ if (retval) {
+ com_err(__func__, retval,
+ _("while creating special file "
+ "\"%s\""),
+ name);
+ return 1;
+ }
+ break;
+ case S_IFLNK:
+ ln_target = calloc(
+ 1, __round_up(strlen(dl_archive_entry_symlink(entry)),
+ 1024));
+ strcpy(ln_target, dl_archive_entry_symlink(entry));
+ retval = do_symlink_internal(fs, dirinode, name, ln_target,
+ root);
+ free(ln_target);
+ if (retval) {
+ com_err(__func__, retval,
+ _("while writing symlink\"%s\""), name);
+ return 1;
+ }
+ break;
+ case S_IFREG:
+ retval = do_write_internal_tar(fs, dirinode, a, name, st);
+ if (retval) {
+ com_err(__func__, retval,
+ _("while writing file \"%s\""), name);
+ return 1;
+ }
+ break;
+ case S_IFDIR:
+ retval = do_mkdir_internal(fs, dirinode, name, root);
+ if (retval) {
+ com_err(__func__, retval, _("while making dir \"%s\""),
+ name);
+ return 1;
+ }
+ break;
+ default:
+ if (dl_archive_entry_hardlink(entry) != NULL) {
+ if ((retval = __find_path(
+ fs, root_ino,
+ dl_archive_entry_hardlink(entry),
+ &tmpino))) {
+ com_err(__func__, retval,
+ _("cannot find hardlink destination \"%s\" "
+ "to create \"%s\""),
+ dl_archive_entry_hardlink(entry), name);
+ return 1;
+ }
+ retval = add_link(fs, dirinode, tmpino, name);
+ if (retval) {
+ com_err(__func__, retval, "while linking %s",
+ name);
+ return 1;
+ }
+ } else {
+ com_err(__func__, 0, _("ignoring entry \"%s\""),
+ dl_archive_entry_pathname(entry));
+ }
+ }
+ return 0;
+}
+#endif
+
+errcode_t __populate_fs_from_tar(ext2_filsys fs, ext2_ino_t root_ino,
+ const char *source_tar, ext2_ino_t root,
+ struct hdlinks_s *hdlinks EXT2FS_ATTR((unused)),
+ struct file_info *target,
+ struct fs_ops_callbacks *fs_callbacks)
+{
+#ifndef HAVE_ARCHIVE_H
+ com_err(__func__, 0,
+ _("you need to compile e2fsprogs with libarchive to "
+ "be able to process tarballs"));
+ return 1;
+#else
+ char *path2, *path3, *dir, *name;
+ unsigned int dir_exists;
+ struct archive *a;
+ struct archive_entry *entry;
+ errcode_t retval = 0;
+ locale_t archive_locale;
+ locale_t old_locale;
+ ext2_ino_t dirinode, tmpino;
+ const struct stat *st;
+
+ if (!libarchive_available()) {
+ com_err(__func__, 0,
+ _("you need libarchive to be able to process tarballs"));
+ return 1;
+ }
+
+ archive_locale = newlocale(LC_CTYPE_MASK, "", (locale_t)0);
+ old_locale = uselocale(archive_locale);
+ a = dl_archive_read_new();
+ if (a == NULL) {
+ retval = 1;
+ com_err(__func__, retval, _("while creating archive reader"));
+ goto out;
+ }
+ if (dl_archive_read_support_filter_all(a) != ARCHIVE_OK) {
+ retval = 1;
+ com_err(__func__, retval, _("while enabling decompression"));
+ goto out;
+ }
+ if (dl_archive_read_support_format_all(a) != ARCHIVE_OK) {
+ retval = 1;
+ com_err(__func__, retval, _("while enabling reader formats"));
+ goto out;
+ }
+
+ if ((retval = dl_archive_read_open_filename(a, source_tar, 4096))) {
+ com_err(__func__, retval, _("while opening \"%s\""),
+ dl_archive_error_string(a));
+ goto out;
+ }
+
+ for (;;) {
+ retval = dl_archive_read_next_header(a, &entry);
+ if (retval == ARCHIVE_EOF) {
+ retval = 0;
+ break;
+ }
+ if (retval != ARCHIVE_OK) {
+ com_err(__func__, retval,
+ _("cannot read archive header: \"%s\""),
+ dl_archive_error_string(a));
+ goto out;
+ }
+ path2 = strdup(dl_archive_entry_pathname(entry));
+ path3 = strdup(dl_archive_entry_pathname(entry));
+ name = basename(path2);
+ dir = dirname(path3);
+ if ((retval = __find_path(fs, root_ino, dir, &dirinode))) {
+ com_err(__func__, retval,
+ _("cannot find directory \"%s\" to create \"%s\""),
+ dir, name);
+ goto out;
+ }
+
+ /*
+ * Did we already create this file as the result of a repeated entry
+ * in the tarball? Delete the existing one (except if it is a
+ * directory) so that it can be re-created by handle_entry().
+ */
+ dir_exists = 0;
+ st = dl_archive_entry_stat(entry);
+ retval = ext2fs_namei(fs, root, dirinode, name, &tmpino);
+ if (!retval) {
+ if ((st->st_mode & S_IFMT) == S_IFDIR) {
+ dir_exists = 1;
+ } else {
+ retval = ext2fs_unlink(fs, dirinode, name,
+ tmpino, 0);
+ if (retval) {
+ com_err(__func__, retval,
+ _("failed to unlink \"%s/%s\""),
+ dir, name);
+ goto out;
+ }
+ retval = remove_inode(fs, tmpino);
+ if (retval) {
+ com_err(__func__, retval,
+ _("failed to remove inode of \"%s/%s\""),
+ dir, name);
+ goto out;
+ }
+ }
+ }
+
+ /*
+ * Create files, directories, symlinks etc referenced by this archive
+ * entry unless this is an already existing directory
+ */
+ if (!dir_exists) {
+ retval = handle_entry(fs, root_ino, root, dirinode,
+ name, a, entry, st);
+ if (retval)
+ goto out;
+ retval =
+ ext2fs_namei(fs, root, dirinode, name, &tmpino);
+ if (retval) {
+ com_err(__func__, retval,
+ _("while looking up \"%s\""), name);
+ goto out;
+ }
+ }
+
+ /* set uid, gid, mode and time for the new (or re-created) inode */
+ retval = set_inode_extra(fs, tmpino, st);
+ if (retval) {
+ com_err(__func__, retval,
+ _("while setting inode for \"%s\""), name);
+ goto out;
+ }
+
+ retval = set_inode_xattr_tar(fs, tmpino, entry);
+ if (retval) {
+ com_err(__func__, retval,
+ _("while setting xattrs for \"%s\""), name);
+ goto out;
+ }
+
+ if (fs_callbacks && fs_callbacks->end_create_new_inode) {
+ retval = fs_callbacks->end_create_new_inode(
+ fs, target->path, name, dirinode, root,
+ st->st_mode & S_IFMT);
+ if (retval)
+ goto out;
+ }
+
+ free(path2);
+ free(path3);
+ }
+
+out:
+ dl_archive_read_close(a);
+ dl_archive_read_free(a);
+ uselocale(old_locale);
+ freelocale(archive_locale);
+ return retval;
+#endif
+}
diff --git a/misc/create_inode_libarchive.h b/misc/create_inode_libarchive.h
new file mode 100644
index 0000000..78c454e
--- /dev/null
+++ b/misc/create_inode_libarchive.h
@@ -0,0 +1,10 @@
+#ifndef _CREATE_INODE_LIBARCHIVE_H
+#define _CREATE_INODE_LIBARCHIVE_H
+
+errcode_t __populate_fs_from_tar(ext2_filsys fs, ext2_ino_t root_ino,
+ const char *source_tar, ext2_ino_t root,
+ struct hdlinks_s *hdlinks,
+ struct file_info *target,
+ struct fs_ops_callbacks *fs_callbacks);
+
+#endif /* _CREATE_INODE_LIBARCHIVE_H */
diff --git a/misc/dumpe2fs.c b/misc/dumpe2fs.c
index 7c080ed..d2d57fb 100644
--- a/misc/dumpe2fs.c
+++ b/misc/dumpe2fs.c
@@ -84,8 +84,7 @@ static void print_free(unsigned long group, char * bitmap,
unsigned long num, unsigned long offset, int ratio)
{
int p = 0;
- unsigned long i;
- unsigned long j;
+ unsigned long i, j;
offset /= ratio;
offset += group * num;
@@ -95,13 +94,14 @@ static void print_free(unsigned long group, char * bitmap,
if (p)
printf (", ");
print_number((i + offset) * ratio);
- for (j = i; j < num && !in_use (bitmap, j); j++)
+ for (j = i + 1; j < num && !in_use(bitmap, j); j++)
;
- if (--j != i) {
+ if (j != i + 1 || ratio > 1) {
fputc('-', stdout);
- print_number((j + offset) * ratio);
- i = j;
+ print_number(((j - 1 + offset) * ratio) +
+ ratio - 1);
}
+ i = j;
p = 1;
}
}
diff --git a/misc/e2freefrag.c b/misc/e2freefrag.c
index 49b6346..63a3d43 100644
--- a/misc/e2freefrag.c
+++ b/misc/e2freefrag.c
@@ -38,7 +38,7 @@ extern int optind;
#include "e2freefrag.h"
#if defined(HAVE_EXT2_IOCTLS) && !defined(DEBUGFS)
-# ifdef HAVE_LINUX_FSMAP_H
+# if defined(HAVE_LINUX_FSMAP_H) && defined(HAVE_FSMAP_SIZEOF)
# include <linux/fsmap.h>
# endif
# include "fsmap.h"
@@ -377,7 +377,7 @@ static void open_device(char *device_name, ext2_filsys *fs)
#ifdef DEBUGFS
#include "debugfs.h"
-void do_freefrag(int argc, char **argv, int sci_idx EXT2FS_ATTR((unused)),
+void do_freefrag(int argc, ss_argv_t argv, int sci_idx EXT2FS_ATTR((unused)),
void *infop EXT2FS_ATTR((unused)))
#else
int main(int argc, char *argv[])
diff --git a/misc/e2fuzz.c b/misc/e2fuzz.c
index 0ceece9..9f60bcf 100644
--- a/misc/e2fuzz.c
+++ b/misc/e2fuzz.c
@@ -9,7 +9,6 @@
* %End-Header%
*/
#define _XOPEN_SOURCE 600
-#define _FILE_OFFSET_BITS 64
#define _LARGEFILE64_SOURCE 1
#define _GNU_SOURCE 1
diff --git a/misc/e2image.c b/misc/e2image.c
index 1ae0300..a926724 100644
--- a/misc/e2image.c
+++ b/misc/e2image.c
@@ -239,6 +239,7 @@ static void write_image_file(ext2_filsys fs, int fd)
struct ext2_image_hdr hdr;
struct stat st;
errcode_t retval;
+ time_t now = time(0);
write_header(fd, NULL, sizeof(struct ext2_image_hdr), fs->blocksize);
memset(&hdr, 0, sizeof(struct ext2_image_hdr));
@@ -292,7 +293,12 @@ static void write_image_file(ext2_filsys fs, int fd)
}
memcpy(hdr.fs_uuid, fs->super->s_uuid, sizeof(hdr.fs_uuid));
- hdr.image_time = ext2fs_cpu_to_le32(time(0));
+ hdr.image_time_lo = ext2fs_cpu_to_le32(now & 0xFFFFFFFF);
+#if (SIZEOF_TIME_T > 4)
+ hdr.image_time_hi = ext2fs_cpu_to_le32(now >> 32);
+#else
+ hdr.image_time_hi = 0;
+#endif
write_header(fd, &hdr, sizeof(struct ext2_image_hdr), fs->blocksize);
}
diff --git a/misc/e2undo.c b/misc/e2undo.c
index bc78fb2..4cbf888 100644
--- a/misc/e2undo.c
+++ b/misc/e2undo.c
@@ -154,9 +154,11 @@ static void print_undo_mismatch(struct ext2_super_block *fs_super,
if (memcmp(fs_super->s_uuid, undo_super->s_uuid,
sizeof(fs_super->s_uuid)))
printf("%s", _("UUID does not match.\n"));
- if (fs_super->s_mtime != undo_super->s_mtime)
+ if (ext2fs_get_tstamp(fs_super, s_mtime) !=
+ ext2fs_get_tstamp(undo_super, s_mtime))
printf("%s", _("Last mount time does not match.\n"));
- if (fs_super->s_wtime != undo_super->s_wtime)
+ if (ext2fs_get_tstamp(fs_super, s_wtime) !=
+ ext2fs_get_tstamp(undo_super, s_wtime))
printf("%s", _("Last write time does not match.\n"));
if (fs_super->s_kbytes_written != undo_super->s_kbytes_written)
printf("%s", _("Lifetime write counter does not match.\n"));
diff --git a/misc/e4crypt.c b/misc/e4crypt.c
index 67d25d8..af90704 100644
--- a/misc/e4crypt.c
+++ b/misc/e4crypt.c
@@ -144,7 +144,7 @@ static void validate_paths(int argc, char *argv[], int path_start_index)
if (ret < 0)
goto invalid;
if (!S_ISDIR(st.st_mode)) {
- fprintf(stderr, "%s is not a directory\n", argv[x]);
+ errno = ENOTDIR;
goto invalid;
}
}
diff --git a/misc/e4defrag.c b/misc/e4defrag.c
index e3011d7..5bfa6ff 100644
--- a/misc/e4defrag.c
+++ b/misc/e4defrag.c
@@ -1206,9 +1206,8 @@ static int file_statistic(const char *file, const struct stat64 *buf,
if (mode_flag & DETAIL) {
/* Print statistic info */
- sprintf(msg_buffer, "[%u/%u]%.*s",
- defraged_file_count, total_count,
- PATH_MAX, file);
+ snprintf(msg_buffer, sizeof(msg_buffer), "[%u/%u]%.*s",
+ defraged_file_count, total_count, PATH_MAX, file);
if (current_uid == ROOT_UID) {
if (strlen(msg_buffer) > 40)
printf("\033[79;0H\033[K%s\n"
diff --git a/misc/ext4.5.in b/misc/ext4.5.in
index c835a34..6fb67eb 100644
--- a/misc/ext4.5.in
+++ b/misc/ext4.5.in
@@ -1,3 +1,4 @@
+'\" t
.\" -*- nroff -*-
.\" Copyright 1993, 1994, 1995 by Theodore Ts'o. All Rights Reserved.
.\" This file may be copied under the terms of the GNU Public License.
diff --git a/misc/findsuper.c b/misc/findsuper.c
index 7e78c1f..8f275ea 100644
--- a/misc/findsuper.c
+++ b/misc/findsuper.c
@@ -81,8 +81,6 @@
*
*/
-#define _FILE_OFFSET_BITS 64
-
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
@@ -230,10 +228,9 @@ int main(int argc, char *argv[])
WHY("free_inodes_count > inodes_count (%u > %u)\n",
ext2.s_free_inodes_count, ext2.s_inodes_count);
- if (ext2.s_mkfs_time != 0)
- tm = ext2.s_mkfs_time;
- else
- tm = ext2.s_mtime;
+ tm = ext2fs_get_tstamp(ext2, s_mkfs_time);
+ if (tm == 0)
+ tm = ext2fs_get_tstamp(ext2, s_mtime);
s = ctime(&tm);
s[24] = 0;
bsize = 1 << (ext2.s_log_block_size + 10);
diff --git a/misc/fsck.c b/misc/fsck.c
index 1769a10..64d0e7c 100644
--- a/misc/fsck.c
+++ b/misc/fsck.c
@@ -806,6 +806,7 @@ static void compile_fs_type(char *fs_type, struct fs_type_compile *cmp)
if ((negate && !cmp->negate) ||
(!negate && cmp->negate)) {
fputs(_(fs_type_syntax_error), stderr);
+ free(list);
exit(EXIT_USAGE);
}
}
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 0dc77ea..56a0d54 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -8,8 +8,6 @@
* License.
* %End-Header%
*/
-#define _FILE_OFFSET_BITS 64
-#define FUSE_USE_VERSION 29
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
@@ -19,12 +17,9 @@
# include <linux/fs.h>
# include <linux/falloc.h>
# include <linux/xattr.h>
-# define FUSE_PLATFORM_OPTS ",big_writes"
# ifdef HAVE_SYS_ACL_H
# define TRANSLATE_LINUX_ACLS
# endif
-#else
-# define FUSE_PLATFORM_OPTS ""
#endif
#ifdef TRANSLATE_LINUX_ACLS
# include <sys/acl.h>
@@ -35,6 +30,15 @@
#include <inttypes.h>
#include "ext2fs/ext2fs.h"
#include "ext2fs/ext2_fs.h"
+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
+# define FUSE_PLATFORM_OPTS ""
+#else
+# ifdef __linux__
+# define FUSE_PLATFORM_OPTS ",use_ino,big_writes"
+# else
+# define FUSE_PLATFORM_OPTS ",use_ino"
+# endif
+#endif
#include "../version.h"
@@ -728,7 +732,11 @@ static void op_destroy(void *p EXT2FS_ATTR((unused)))
}
}
-static void *op_init(struct fuse_conn_info *conn)
+static void *op_init(struct fuse_conn_info *conn
+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
+ , struct fuse_config *cfg EXT2FS_ATTR((unused))
+#endif
+ )
{
struct fuse_context *ctxt = fuse_get_context();
struct fuse2fs *ff = (struct fuse2fs *)ctxt->private_data;
@@ -746,7 +754,7 @@ static void *op_init(struct fuse_conn_info *conn)
#endif
if (fs->flags & EXT2_FLAG_RW) {
fs->super->s_mnt_count++;
- fs->super->s_mtime = time(NULL);
+ ext2fs_set_tstamp(fs->super, s_mtime, time(NULL));
fs->super->s_state &= ~EXT2_VALID_FS;
ext2fs_mark_super_dirty(fs);
err = ext2fs_flush2(fs, 0);
@@ -798,7 +806,11 @@ static int stat_inode(ext2_filsys fs, ext2_ino_t ino, struct stat *statbuf)
return ret;
}
-static int op_getattr(const char *path, struct stat *statbuf)
+static int op_getattr(const char *path, struct stat *statbuf
+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
+ , struct fuse_file_info *fi EXT2FS_ATTR((unused))
+#endif
+ )
{
struct fuse_context *ctxt = fuse_get_context();
struct fuse2fs *ff = (struct fuse2fs *)ctxt->private_data;
@@ -1129,7 +1141,7 @@ static int op_mkdir(const char *path, mode_t mode)
ext2fs_set_i_uid_high(inode, ctxt->uid >> 16);
inode.i_gid = ctxt->gid;
ext2fs_set_i_gid_high(inode, ctxt->gid >> 16);
- inode.i_mode = LINUX_S_IFDIR | (mode & ~(S_ISUID | fs->umask)) |
+ inode.i_mode = LINUX_S_IFDIR | (mode & ~S_ISUID) |
parent_sgid;
inode.i_generation = ff->next_generation++;
@@ -1230,7 +1242,7 @@ static int remove_inode(struct fuse2fs *ff, ext2_ino_t ino)
return 0; /* XXX: already done? */
case 1:
inode.i_links_count--;
- inode.i_dtime = fs->now ? fs->now : time(0);
+ ext2fs_set_dtime(fs, EXT2_INODE(&inode));
break;
default:
inode.i_links_count--;
@@ -1542,7 +1554,11 @@ static int update_dotdot_helper(ext2_ino_t dir EXT2FS_ATTR((unused)),
return 0;
}
-static int op_rename(const char *from, const char *to)
+static int op_rename(const char *from, const char *to
+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
+ , unsigned int flags EXT2FS_ATTR((unused))
+#endif
+ )
{
struct fuse_context *ctxt = fuse_get_context();
struct fuse2fs *ff = (struct fuse2fs *)ctxt->private_data;
@@ -1871,7 +1887,11 @@ out:
return ret;
}
-static int op_chmod(const char *path, mode_t mode)
+static int op_chmod(const char *path, mode_t mode
+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
+ , struct fuse_file_info *fi EXT2FS_ATTR((unused))
+#endif
+ )
{
struct fuse_context *ctxt = fuse_get_context();
struct fuse2fs *ff = (struct fuse2fs *)ctxt->private_data;
@@ -1930,7 +1950,11 @@ out:
return ret;
}
-static int op_chown(const char *path, uid_t owner, gid_t group)
+static int op_chown(const char *path, uid_t owner, gid_t group
+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
+ , struct fuse_file_info *fi EXT2FS_ATTR((unused))
+#endif
+ )
{
struct fuse_context *ctxt = fuse_get_context();
struct fuse2fs *ff = (struct fuse2fs *)ctxt->private_data;
@@ -2000,7 +2024,11 @@ out:
return ret;
}
-static int op_truncate(const char *path, off_t len)
+static int op_truncate(const char *path, off_t len
+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
+ , struct fuse_file_info *fi EXT2FS_ATTR((unused))
+#endif
+ )
{
struct fuse_context *ctxt = fuse_get_context();
struct fuse2fs *ff = (struct fuse2fs *)ctxt->private_data;
@@ -2753,7 +2781,11 @@ static int op_readdir_iter(ext2_ino_t dir EXT2FS_ATTR((unused)),
memcpy(namebuf, dirent->name, dirent->name_len & 0xFF);
namebuf[dirent->name_len & 0xFF] = 0;
- ret = i->func(i->buf, namebuf, NULL, 0);
+ ret = i->func(i->buf, namebuf, NULL, 0
+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
+ , 0
+#endif
+ );
if (ret)
return DIRENT_ABORT;
@@ -2763,7 +2795,11 @@ static int op_readdir_iter(ext2_ino_t dir EXT2FS_ATTR((unused)),
static int op_readdir(const char *path EXT2FS_ATTR((unused)),
void *buf, fuse_fill_dir_t fill_func,
off_t offset EXT2FS_ATTR((unused)),
- struct fuse_file_info *fp)
+ struct fuse_file_info *fp
+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
+ , enum fuse_readdir_flags flags EXT2FS_ATTR((unused))
+#endif
+ )
{
struct fuse_context *ctxt = fuse_get_context();
struct fuse2fs *ff = (struct fuse2fs *)ctxt->private_data;
@@ -2951,6 +2987,7 @@ out:
return ret;
}
+#if FUSE_VERSION < FUSE_MAKE_VERSION(3, 0)
static int op_ftruncate(const char *path EXT2FS_ATTR((unused)),
off_t len, struct fuse_file_info *fp)
{
@@ -3024,8 +3061,13 @@ static int op_fgetattr(const char *path EXT2FS_ATTR((unused)),
return ret;
}
+#endif /* FUSE_VERSION < FUSE_MAKE_VERSION(3, 0) */
-static int op_utimens(const char *path, const struct timespec ctv[2])
+static int op_utimens(const char *path, const struct timespec ctv[2]
+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
+ , struct fuse_file_info *fi EXT2FS_ATTR((unused))
+#endif
+ )
{
struct fuse_context *ctxt = fuse_get_context();
struct fuse2fs *ff = (struct fuse2fs *)ctxt->private_data;
@@ -3259,7 +3301,12 @@ static int ioctl_fitrim(ext2_filsys fs, struct fuse2fs_file_handle *fh,
#endif /* FITRIM */
#if FUSE_VERSION >= FUSE_MAKE_VERSION(2, 8)
-static int op_ioctl(const char *path EXT2FS_ATTR((unused)), int cmd,
+static int op_ioctl(const char *path EXT2FS_ATTR((unused)),
+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
+ unsigned int cmd,
+#else
+ int cmd,
+#endif
void *arg EXT2FS_ATTR((unused)),
struct fuse_file_info *fp,
unsigned int flags EXT2FS_ATTR((unused)), void *data)
@@ -3603,10 +3650,12 @@ static struct fuse_operations fs_ops = {
.fsyncdir = op_fsync,
.access = op_access,
.create = op_create,
+#if FUSE_VERSION < FUSE_MAKE_VERSION(3, 0)
.ftruncate = op_ftruncate,
.fgetattr = op_fgetattr,
+#endif
.utimens = op_utimens,
-#if FUSE_VERSION >= FUSE_MAKE_VERSION(2, 9)
+#if (FUSE_VERSION >= FUSE_MAKE_VERSION(2, 9)) && (FUSE_VERSION < FUSE_MAKE_VERSION(3, 0))
# if defined(UTIME_NOW) || defined(UTIME_OMIT)
.flag_utime_omit_ok = 1,
# endif
@@ -3618,10 +3667,14 @@ static struct fuse_operations fs_ops = {
#endif
#if FUSE_VERSION >= FUSE_MAKE_VERSION(2, 8)
.ioctl = op_ioctl,
+#if FUSE_VERSION < FUSE_MAKE_VERSION(3, 0)
.flag_nullpath_ok = 1,
#endif
+#endif
#if FUSE_VERSION >= FUSE_MAKE_VERSION(2, 9)
+#if FUSE_VERSION < FUSE_MAKE_VERSION(3, 0)
.flag_nopath = 1,
+#endif
# ifdef SUPPORT_FALLOCATE
.fallocate = op_fallocate,
# endif
@@ -3860,7 +3913,7 @@ int main(int argc, char *argv[])
get_random_bytes(&fctx.next_generation, sizeof(unsigned int));
/* Set up default fuse parameters */
- snprintf(extra_args, BUFSIZ, "-okernel_cache,subtype=ext4,use_ino,"
+ snprintf(extra_args, BUFSIZ, "-okernel_cache,subtype=ext4,"
"fsname=%s,attr_timeout=0" FUSE_PLATFORM_OPTS,
fctx.device);
if (fctx.no_default_opts == 0)
@@ -3984,14 +4037,14 @@ no_translation:
/* Make a note in the error log */
get_now(&now);
- fs->super->s_last_error_time = now.tv_sec;
+ ext2fs_set_tstamp(fs->super, s_last_error_time, now.tv_sec);
fs->super->s_last_error_ino = ino;
fs->super->s_last_error_line = line;
fs->super->s_last_error_block = err; /* Yeah... */
strncpy((char *)fs->super->s_last_error_func, file,
sizeof(fs->super->s_last_error_func));
- if (fs->super->s_first_error_time == 0) {
- fs->super->s_first_error_time = now.tv_sec;
+ if (ext2fs_get_tstamp(fs->super, s_first_error_time) == 0) {
+ ext2fs_set_tstamp(fs->super, s_first_error_time, now.tv_sec);
fs->super->s_first_error_ino = ino;
fs->super->s_first_error_line = line;
fs->super->s_first_error_block = err;
diff --git a/misc/lsattr.1.in b/misc/lsattr.1.in
index 4d02a95..9884a4d 100644
--- a/misc/lsattr.1.in
+++ b/misc/lsattr.1.in
@@ -1,7 +1,7 @@
.\" -*- nroff -*-
.TH LSATTR 1 "@E2FSPROGS_MONTH@ @E2FSPROGS_YEAR@" "E2fsprogs version @E2FSPROGS_VERSION@"
.SH NAME
-lsattr \- list file attributes on a Linux second extended file system
+lsattr \- list ext2/ext3/ext4 file attributes
.SH SYNOPSIS
.B lsattr
[
@@ -12,7 +12,7 @@ lsattr \- list file attributes on a Linux second extended file system
]
.SH DESCRIPTION
.B lsattr
-lists the file attributes on a second extended file system. See
+lists the file attributes on an ext2/ext3/ext4 file system. See
.BR chattr (1)
for a description of the attributes and what they mean.
.SH OPTIONS
diff --git a/misc/mke2fs.8.in b/misc/mke2fs.8.in
index 30f97bb..c12b607 100644
--- a/misc/mke2fs.8.in
+++ b/misc/mke2fs.8.in
@@ -23,7 +23,7 @@ mke2fs \- create an ext2/ext3/ext4 file system
]
[
.B \-d
-.I root-directory
+.I root-directory|tarball
]
[
.B \-D
@@ -232,16 +232,18 @@ test is used instead of a fast read-only test.
.TP
.B \-C " cluster-size"
Specify the size of cluster in bytes for file systems using the bigalloc
-feature. Valid cluster-size values are from 2048 to 256M bytes per
-cluster. This can only be specified if the bigalloc feature is
-enabled. (See the
+feature. Valid cluster-size values range from 2 to 32768 times the
+filesystem blocksize and must be a power of 2. The cluster-size can
+only be specified if the bigalloc feature is enabled. (See the
.B ext4 (5)
man page for more details about bigalloc.) The default cluster size if
bigalloc is enabled is 16 times the block size.
.TP
-.BI \-d " root-directory"
-Copy the contents of the given directory into the root directory of the
-file system.
+.BI \-d " root-directory|tarball"
+Copy the contents of the given directory or tarball into the root directory of the
+file system. Tarball input is only available if mke2fs was compiled with
+libarchive support enabled and if the libarchive shared library is available
+at run-time. The special value "-" will read a tarball from standard input.
.TP
.B \-D
Use direct I/O when writing to the disk. This avoids mke2fs dirtying a
@@ -406,6 +408,11 @@ The \fBroot_owner=\fR option allows explicitly specifying these values,
and avoid side-effects for users that do not expect the contents of the
file system to change based on the user running \fBmke2fs\fR.
.TP
+.BI root_perms [=permissions]
+Specify the root directory permissions in octal format. If no permissions
+are specified then the root directory permissions would be set in accordance with
+the default filesystem umask.
+.TP
.B test_fs
Set a flag in the file system superblock indicating that it may be
mounted using experimental kernel code, such as the ext4dev file system.
@@ -508,8 +515,8 @@ The default inode size is controlled by the
file. In the
.B mke2fs.conf
file shipped with e2fsprogs, the default inode size is 256 bytes for
-most file systems, except for small file systems where the inode size
-will be 128 bytes.
+all file systems, except for the GNU Hurd since it only supports
+128-byte inodes.
.TP
.B \-j
Create the file system with an ext3 journal. If the
diff --git a/misc/mke2fs.c b/misc/mke2fs.c
index 4a9c1b0..58ade9d 100644
--- a/misc/mke2fs.c
+++ b/misc/mke2fs.c
@@ -90,6 +90,7 @@ static int force;
static int noaction;
static int num_backups = 2; /* number of backup bg's for sparse_super2 */
static uid_t root_uid;
+static mode_t root_perms = (mode_t)-1;
static gid_t root_gid;
int journal_size;
int journal_flags;
@@ -117,7 +118,7 @@ static char *mount_dir;
char *journal_device;
static int sync_kludge; /* Set using the MKE2FS_SYNC env. option */
char **fs_types;
-const char *src_root_dir; /* Copy files from the specified directory */
+const char *src_root; /* Copy files from the specified directory or tarball */
static char *undo_file;
static int android_sparse_file; /* -E android_sparse */
@@ -134,7 +135,7 @@ static void usage(void)
"[-C cluster-size]\n\t[-i bytes-per-inode] [-I inode-size] "
"[-J journal-options]\n"
"\t[-G flex-group-size] [-N number-of-inodes] "
- "[-d root-directory]\n"
+ "[-d root-directory|tarball]\n"
"\t[-m reserved-blocks-percentage] [-o creator-os]\n"
"\t[-g blocks-per-group] [-L volume-label] "
"[-M last-mounted-directory]\n\t[-O feature[,...]] "
@@ -415,9 +416,9 @@ static errcode_t packed_allocate_tables(ext2_filsys fs)
static void write_inode_tables(ext2_filsys fs, int lazy_flag, int itable_zeroed)
{
errcode_t retval;
- blk64_t blk;
+ blk64_t start = 0;
dgrp_t i;
- int num;
+ int len = 0;
struct ext2fs_numeric_progress_struct progress;
ext2fs_numeric_progress_init(fs, &progress,
@@ -425,10 +426,10 @@ static void write_inode_tables(ext2_filsys fs, int lazy_flag, int itable_zeroed)
fs->group_desc_count);
for (i = 0; i < fs->group_desc_count; i++) {
- ext2fs_numeric_progress_update(fs, &progress, i);
+ blk64_t blk = ext2fs_inode_table_loc(fs, i);
+ int num = fs->inode_blocks_per_group;
- blk = ext2fs_inode_table_loc(fs, i);
- num = fs->inode_blocks_per_group;
+ ext2fs_numeric_progress_update(fs, &progress, i);
if (lazy_flag)
num = ext2fs_div_ceil((fs->super->s_inodes_per_group -
@@ -441,14 +442,26 @@ static void write_inode_tables(ext2_filsys fs, int lazy_flag, int itable_zeroed)
ext2fs_group_desc_csum_set(fs, i);
}
if (!itable_zeroed) {
- retval = ext2fs_zero_blocks2(fs, blk, num, &blk, &num);
+ if (len == 0) {
+ start = blk;
+ len = num;
+ continue;
+ }
+ /* 'len' must not overflow 2^31 blocks for ext2fs_zero_blocks2() */
+ if (start + len == blk && len + num >= len) {
+ len += num;
+ continue;
+ }
+ retval = ext2fs_zero_blocks2(fs, start, len, &start, &len);
if (retval) {
fprintf(stderr, _("\nCould not write %d "
"blocks in inode table starting at %llu: %s\n"),
- num, (unsigned long long) blk,
+ len, (unsigned long long) start,
error_message(retval));
exit(1);
}
+ start = blk;
+ len = num;
}
if (sync_kludge) {
if (sync_kludge == 1)
@@ -457,6 +470,18 @@ static void write_inode_tables(ext2_filsys fs, int lazy_flag, int itable_zeroed)
io_channel_flush(fs->io);
}
}
+ if (len) {
+ retval = ext2fs_zero_blocks2(fs, start, len, &start, &len);
+ if (retval) {
+ fprintf(stderr, _("\nCould not write %d "
+ "blocks in inode table starting at %llu: %s\n"),
+ len, (unsigned long long) start,
+ error_message(retval));
+ exit(1);
+ }
+ if (sync_kludge)
+ io_channel_flush(fs->io);
+ }
ext2fs_numeric_progress_close(fs, &progress,
_("done \n"));
@@ -469,6 +494,7 @@ static void create_root_dir(ext2_filsys fs)
{
errcode_t retval;
struct ext2_inode inode;
+ int need_inode_change;
retval = ext2fs_mkdir(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, 0);
if (retval) {
@@ -476,19 +502,30 @@ static void create_root_dir(ext2_filsys fs)
_("while creating root dir"));
exit(1);
}
- if (root_uid != 0 || root_gid != 0) {
+
+ need_inode_change = (int)(root_uid != 0 || root_gid != 0 || root_perms != (mode_t)-1);
+
+ if (need_inode_change) {
retval = ext2fs_read_inode(fs, EXT2_ROOT_INO, &inode);
if (retval) {
com_err("ext2fs_read_inode", retval, "%s",
_("while reading root inode"));
exit(1);
}
+ }
+ if (root_uid != 0 || root_gid != 0) {
inode.i_uid = root_uid;
ext2fs_set_i_uid_high(inode, root_uid >> 16);
inode.i_gid = root_gid;
ext2fs_set_i_gid_high(inode, root_gid >> 16);
+ }
+
+ if (root_perms != (mode_t)-1) {
+ inode.i_mode = LINUX_S_IFDIR | root_perms;
+ }
+ if (need_inode_change) {
retval = ext2fs_write_new_inode(fs, EXT2_ROOT_INO, &inode);
if (retval) {
com_err("ext2fs_write_inode", retval, "%s",
@@ -1048,6 +1085,10 @@ static void parse_extended_opts(struct ext2_super_block *param,
root_uid = getuid();
root_gid = getgid();
}
+ } else if (!strcmp(token, "root_perms")) {
+ if (arg) {
+ root_perms = strtoul(arg, &p, 8);
+ }
} else if (!strcmp(token, "discard")) {
discard = 1;
} else if (!strcmp(token, "nodiscard")) {
@@ -1132,6 +1173,7 @@ static void parse_extended_opts(struct ext2_super_block *param,
"\tlazy_itable_init=<0 to disable, 1 to enable>\n"
"\tlazy_journal_init=<0 to disable, 1 to enable>\n"
"\troot_owner=<uid of root dir>:<gid of root dir>\n"
+ "\troot_perms=<octal root directory permissions>\n"
"\ttest_fs\n"
"\tdiscard\n"
"\tnodiscard\n"
@@ -1712,7 +1754,7 @@ profile_error:
}
break;
case 'd':
- src_root_dir = optarg;
+ src_root = optarg;
break;
case 'D':
direct_io = 1;
@@ -3522,7 +3564,7 @@ no_journal:
fs->super->s_mmp_update_interval);
}
- overhead += fs->super->s_first_data_block;
+ overhead += EXT2FS_NUM_B2C(fs, fs->super->s_first_data_block);
if (!super_only)
fs->super->s_overhead_clusters = overhead;
@@ -3551,12 +3593,12 @@ no_journal:
retval = mk_hugefiles(fs, device_name);
if (retval)
com_err(program_name, retval, "while creating huge files");
- /* Copy files from the specified directory */
- if (src_root_dir) {
+ /* Copy files from the specified directory or tarball */
+ if (src_root) {
if (!quiet)
printf("%s", _("Copying files into the device: "));
- retval = populate_fs(fs, EXT2_ROOT_INO, src_root_dir,
+ retval = populate_fs(fs, EXT2_ROOT_INO, src_root,
EXT2_ROOT_INO);
if (retval) {
com_err(program_name, retval, "%s",
diff --git a/misc/mklost+found.8.in b/misc/mklost+found.8.in
index d338239..59b7e76 100644
--- a/misc/mklost+found.8.in
+++ b/misc/mklost+found.8.in
@@ -4,15 +4,15 @@
.\"
.TH MKLOST+FOUND 8 "@E2FSPROGS_MONTH@ @E2FSPROGS_YEAR@" "E2fsprogs version @E2FSPROGS_VERSION@"
.SH NAME
-mklost+found \- create a lost+found directory on a mounted Linux
-second extended file system
+mklost+found \- create a lost+found directory on a mounted
+ext2/ext3/ext4 file system
.SH SYNOPSIS
.B mklost+found
.SH DESCRIPTION
.B mklost+found
is used to create a
.I lost+found
-directory in the current working directory on a Linux second extended
+directory in the current working directory on an ext2/ext3/ext4
file system. There is normally a
.I lost+found
directory in the root directory of each file system.
diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index 458f7cf..6de40e9 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -51,11 +51,15 @@ extern int optind;
#include <unistd.h>
#include <sys/types.h>
#include <libgen.h>
-#include <limits.h>
+#include <limits.h> /* for PATH_MAX */
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
+#ifndef PATH_MAX
+#define PATH_MAX 4096
+#endif
+
#include "ext2fs/ext2_fs.h"
#include "ext2fs/ext2fs.h"
#include "ext2fs/kernel-jbd.h"
@@ -466,7 +470,8 @@ static int check_fsck_needed(ext2_filsys fs, const char *prompt)
/* Refuse to modify anything but a freshly checked valid filesystem. */
if (!(fs->super->s_state & EXT2_VALID_FS) ||
(fs->super->s_state & EXT2_ERROR_FS) ||
- (fs->super->s_lastcheck < fs->super->s_mtime)) {
+ (ext2fs_get_tstamp(fs->super, s_lastcheck) <
+ ext2fs_get_tstamp(fs->super, s_mtime))) {
puts(_(fsck_explain));
puts(_(please_fsck));
if (mount_flags & EXT2_MF_READONLY)
@@ -520,7 +525,8 @@ static void convert_64bit(ext2_filsys fs, int direction)
if (!fsck_requested &&
((fs->super->s_state & EXT2_ERROR_FS) ||
!(fs->super->s_state & EXT2_VALID_FS) ||
- fs->super->s_lastcheck < fs->super->s_mtime))
+ ext2fs_get_tstamp(fs->super, s_lastcheck) <
+ ext2fs_get_tstamp(fs->super, s_mtime)))
request_fsck_afterwards(fs);
if (fsck_requested)
fprintf(stderr, _("After running e2fsck, please run `resize2fs %s %s"),
@@ -3091,29 +3097,24 @@ static int handle_fslabel(int setlabel)
errcode_t ret;
int mnt_flags, fd;
char label[FSLABEL_MAX];
- int maxlen = FSLABEL_MAX - 1;
+ unsigned int maxlen = FSLABEL_MAX - 1;
char mntpt[PATH_MAX + 1];
ret = ext2fs_check_mount_point(device_name, &mnt_flags,
mntpt, sizeof(mntpt));
- if (ret) {
- com_err(device_name, ret, _("while checking mount status"));
- return 1;
- }
+ if (ret)
+ return -1;
+
if (!(mnt_flags & EXT2_MF_MOUNTED) ||
(setlabel && (mnt_flags & EXT2_MF_READONLY)))
return -1;
- if (!mntpt[0]) {
- fprintf(stderr,_("Unknown mount point for %s\n"), device_name);
- return 1;
- }
+ if (!mntpt[0])
+ return -1;
fd = open(mntpt, O_RDONLY);
- if (fd < 0) {
- com_err(mntpt, errno, _("while opening mount point"));
- return 1;
- }
+ if (fd < 0)
+ return -1;
/* Get fs label */
if (!setlabel) {
@@ -3444,7 +3445,7 @@ _("Warning: The journal is dirty. You may wish to replay the journal like:\n\n"
goto closefs;
}
if (T_flag) {
- sb->s_lastcheck = last_check_time;
+ ext2fs_set_tstamp(sb, s_lastcheck, last_check_time);
ext2fs_mark_super_dirty(fs);
printf(_("Setting time filesystem last checked to %s\n"),
ctime(&last_check_time));
@@ -3520,9 +3521,9 @@ _("Warning: The journal is dirty. You may wish to replay the journal like:\n\n"
}
if (Q_flag) {
- if (mount_flags & EXT2_MF_MOUNTED) {
+ if (mount_flags & (EXT2_MF_BUSY | EXT2_MF_MOUNTED)) {
fputs(_("The quota feature may only be changed when "
- "the filesystem is unmounted.\n"), stderr);
+ "the filesystem is unmounted and not in use.\n"), stderr);
rc = 1;
goto closefs;
}
@@ -3673,10 +3674,10 @@ _("Warning: The journal is dirty. You may wish to replay the journal like:\n\n"
}
if (I_flag) {
- if (mount_flags & EXT2_MF_MOUNTED) {
+ if (mount_flags & (EXT2_MF_BUSY | EXT2_MF_MOUNTED)) {
fputs(_("The inode size may only be "
"changed when the filesystem is "
- "unmounted.\n"), stderr);
+ "unmounted and not in use.\n"), stderr);
rc = 1;
goto closefs;
}