erofs-utils: lib: track packed inode position explicitly
Subsystems (2)
PATCH 1/5 erofs-utils: lib: track packed inode position explicitly
Track the packed inode position in memory instead of querying the file offset. Use positional writes for fragment data and seek explicitly before the sendfile fallback.
Factor out __erofs_io_pwrite() and fix its short-write handling.
--- include/erofs/io.h | 2 +- lib/fragments.c | 44 +++++++++++++++++++++----------------------- lib/io.c | 29 ++++++++++++++--------------- 3 files changed, 36 insertions(+), 39 deletions(-)
include/erofs/io.h +1 -1
@@ -68,7 +68,7 @@ struct erofs_vfile { }; }; -ssize_t __erofs_io_write (int fd,const void *buf,size_t len); +ssize_t __erofs_io_pwrite (int fd,const void *buf,size_t len,u64 pos);int __erofs_0write (int fd,size_t len);int erofs_io_fstat (struct erofs_vfile *vf,struct stat *buf);
lib/fragments.c +21 -23
118 lines not on this page · raw message
lib/io.c +14 -15
@@ -26,7 +26,7 @@#define EROFS_MODNAME "erofs_io"#include "erofs/print.h" -ssize_t __erofs_io_write (int fd,const void *buf,size_t len) +static ssize_t __erofs_io_write (int fd,const void *buf,size_t len) {ssize_t ret, written =0 ;
@@ -61,24 +61,12 @@ int erofs_io_fstat(struct erofs_vfile *vf, struct stat *buf)return fstat (vf->fd, buf); } -ssize_t erofs_io_pwrite (struct erofs_vfile *vf,const void *buf, -u64 pos,size_t len) +ssize_t __erofs_io_pwrite (int fd,const void *buf,size_t len,u64 pos) {ssize_t ret, written =0 ; -if (__erofs_unlikely (cfg.c_dry_run)) -return 0 ; - -if (vf->ops) -return vf->ops->pwrite (vf, buf, pos, len); - - pos += vf->offset; do { -#ifdef HAVE_PWRITE64 - ret = pwrite64(vf->fd, buf, len, (off64_t)pos); -#else - ret = pwrite(vf->fd, buf, len, (off_t)pos); -#endif + ret = pwrite(fd, buf, len - written, (off_t)pos); if (ret <= 0) { if (!ret) break;
@@ -96,6 +84,17 @@ ssize_t erofs_io_pwrite(struct erofs_vfile *vf, const void *buf,return written; } +ssize_t erofs_io_pwrite (struct erofs_vfile *vf,const void *buf, +u64 pos,size_t len) +{ +if (__erofs_unlikely (cfg.c_dry_run)) +return 0 ; + +if (vf->ops) +return vf->ops->pwrite (vf, buf, pos, len); +return __erofs_io_pwrite (vf->fd, buf, len, pos + vf->offset); +} +ssize_t erofs_io_pwritev (struct erofs_vfile *vf,const struct iovec *iov,int iovcnt,u64 pos) {
Signature · 1 line
2.54.0 (Apple Git-157)
PATCH 2/5 erofs-utils: lib: use positional reads for single-threaded compression
Use explicit offsets when reading compression input. Skip segment-level fragment matching for the single-threaded context, which handles it before compression.
--- lib/compress.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)
lib/compress.c +15 -13
@@ -65,6 +65,8 @@ struct z_erofs_compress_ictx { /* inode context */#endif }; +static struct z_erofs_compress_ictx g_ictx; +struct z_erofs_compress_sctx {/* segment context */ union {struct list_head extents;
@@ -1345,16 +1347,18 @@ int z_erofs_compress_segment(struct z_erofs_compress_sctx *ctx,struct erofs_vfile *vf = ictx->vf;int ret; -DBG_BUGON (offset !=-1 && frag && inode->fragment_size); -if (offset !=-1 && frag && !inode->fragment_size && - params->fragdedupe !=EROFS_FRAGDEDUPE_OFF ) { - ret =erofs_fragment_findmatch (inode, vf, ictx->fpos, - ictx->tofh); -if (ret <0 ) -return ret; -if (inode->fragment_size > ctx->remaining) - inode->fragment_size = ctx->remaining; - ctx->remaining -= inode->fragment_size; +if (ictx != &g_ictx && offset !=-1 && frag) { +DBG_BUGON (inode->fragment_size); +if (!inode->fragment_size && + params->fragdedupe !=EROFS_FRAGDEDUPE_OFF ) { + ret =erofs_fragment_findmatch (inode, vf, ictx->fpos, + ictx->tofh); +if (ret <0 ) +return ret; +if (inode->fragment_size > ctx->remaining) + inode->fragment_size = ctx->remaining; + ctx->remaining -= inode->fragment_size; + } } ctx->pstart = pstart;
@@ -1579,8 +1583,6 @@ out:return err <0 ?ERR_PTR (err) : metabuf; } -static struct z_erofs_compress_ictx g_ictx; -#ifdef EROFS_MT_ENABLED void *z_erofs_mt_wq_tls_alloc (struct erofs_workqueue *wq,void *ptr) {
@@ -2169,7 +2171,7 @@ int erofs_write_compressed_file(struct z_erofs_compress_ictx *ictx) };init_list_head (&sctx.extents); - ret =z_erofs_compress_segment (&sctx,-1 , pstart); + ret =z_erofs_compress_segment (&sctx,0 , pstart);if (ret) goto err_free_idata;
Signature · 1 line
2.54.0 (Apple Git-157)
PATCH 3/5 erofs-utils: lib: fix S3 and OCI portability
In reply to Gao XiangReplace strptime() and strcasestr() with portable timestamp parsing and curl_strnequal() for the upcoming Windows builds.
Pass libcurl compiler flags to both test programs for static linking, and build both when S3 and OCI are enabled.
--- lib/Makefile.am | 9 +++++---- lib/remotes/oci.c | 7 +++++-- lib/remotes/s3.c | 28 ++++++++++++++++++++++------ 3 files changed, 32 insertions(+), 12 deletions(-)
lib/Makefile.am +5 -4
@@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0+ OR MIT noinst_LTLIBRARIES = liberofs.la +noinst_PROGRAMS = noinst_HEADERS = $(top_srcdir)/include/erofs_fs.h \ $(top_srcdir)/include/erofs/block_list.h \ $(top_srcdir)/include/erofs/config.h \
@@ -98,15 +99,15 @@ liberofs_la_CFLAGS += ${json_c_CFLAGS} liberofs_la_SOURCES += gzran.c if ENABLE_S3 -noinst_PROGRAMS = s3erofs_test +noinst_PROGRAMS += s3erofs_test s3erofs_test_SOURCES = remotes/s3.c -s3erofs_test_CFLAGS = -Wall -I$(top_srcdir)/include ${libxml2_CFLAGS} ${openssl_CFLAGS} -DTEST +s3erofs_test_CFLAGS = -Wall -I$(top_srcdir)/include ${libcurl_CFLAGS} ${libxml2_CFLAGS} ${openssl_CFLAGS} -DTEST s3erofs_test_LDADD = liberofs.la $(LIBEROFS_LIBS) endif if ENABLE_OCI -noinst_PROGRAMS = ocierofs_test +noinst_PROGRAMS += ocierofs_test ocierofs_test_SOURCES = remotes/oci.c -ocierofs_test_CFLAGS = -Wall -I$(top_srcdir)/include ${json_c_CFLAGS} -DTEST +ocierofs_test_CFLAGS = -Wall -I$(top_srcdir)/include ${libcurl_CFLAGS} ${json_c_CFLAGS} -DTEST ocierofs_test_LDADD = liberofs.la $(LIBEROFS_LIBS) endif
lib/remotes/oci.c +5 -2
@@ -360,8 +360,11 @@ static int ocierofs_extract_www_auth_info(const char *resp_data,if (!resp_data)return -EINVAL ; - www_auth =strcasestr (resp_data,"www-authenticate:" ); -if (!www_auth) +for (www_auth = (char *)resp_data; *www_auth; ++www_auth) +if (curl_strnequal (www_auth,"www-authenticate:" , +sizeof ("www-authenticate:" ) -1 )) +break ; +if (!*www_auth)return -ENOENT ; line_end =strchr (www_auth,'\n' );
lib/remotes/s3.c +22 -6
@@ -5,6 +5,7 @@* Created by Yifan Zhao <[email protected]> */ #define _GNU_SOURCE +#include "erofs/internal.h" #include <stdio.h> #include <stdlib.h> #include <ctype.h>
@@ -12,7 +13,6 @@#include <curl/curl.h> #include <libxml/parser.h> #include <openssl/hmac.h> -#include "erofs/internal.h" #include "erofs/print.h" #include "erofs/inode.h" #include "../liberofs_chunk.h"
@@ -689,6 +689,25 @@ struct s3erofs_object_iterator {bool is_truncated; }; +static char *s3erofs_parse_timestamp (const char *str,struct tm *tm) +{ +int len =0 ; + +memset (tm,0 ,sizeof (*tm)); +if (sscanf (str,"%4d-%2d-%2dT%2d:%2d:%2d%n" , + &tm->tm_year, &tm->tm_mon, &tm->tm_mday, + &tm->tm_hour, &tm->tm_min, &tm->tm_sec, &len) !=6 || + tm->tm_year <0 || tm->tm_mon <1 || tm->tm_mon >12 || + tm->tm_mday <1 || tm->tm_mday >31 || + tm->tm_hour <0 || tm->tm_hour >23 || + tm->tm_min <0 || tm->tm_min >59 || + tm->tm_sec <0 || tm->tm_sec >60 ) +return NULL ; + tm->tm_year -=1900 ; + --tm->tm_mon; +return (char *)str + len; +} +static int s3erofs_parse_list_objects_one (xmlNodePtr node,struct s3erofs_object_info *info) {
@@ -705,7 +724,7 @@ static int s3erofs_parse_list_objects_one(xmlNodePtr node,struct tm tm;char *end; - end =strptime ((char *)str,"%Y-%m-%dT%H:%M:%S" , &tm); + end =s3erofs_parse_timestamp ((char *)str, &tm);if (!end || (*end !='.' && *end !='Z' && *end !='\0' )) {xmlFree (str);return -EIO ;
@@ -717,10 +736,7 @@ static int s3erofs_parse_list_objects_one(xmlNodePtr node,return -EIO ; } } -/* -* Not set by strptime(); tells mktime() to determine -* whether daylight saving time is in effect -*/ +/* Let mktime() determine whether DST is in effect. */ tm.tm_isdst =-1 ; info->mtime =mktime (&tm); }
Signature · 1 line
2.54.0 (Apple Git-157)
PATCH 4/5 erofs-utils: add native Windows support
In reply to Gao XiangAdd an OS abstraction layer for file metadata, positional I/O and temporary files, with Win32 implementations for MinGW builds. Keep POSIX interfaces for other hosts, including Cygwin.
Add an Alpine-based Docker target for x86-64 Windows builds using MSYS2 static libraries, with compression, S3 and OCI support.
--- Dockerfile | 67 ++++++- configure.ac | 22 ++- fsck/Makefile.am | 2 + fsck/main.c | 23 +-- include/erofs/defs.h | 7 +- include/erofs/err.h | 2 +- include/erofs/inode.h | 2 +- include/erofs/io.h | 8 +- include/erofs/os.h | 60 +++++++ include/erofs/tar.h | 2 +- include/erofs/windows_compat.h | 159 +++++++++++++++++ lib/Makefile.am | 11 ++ lib/blobchunk.c | 2 +- lib/config.c | 5 + lib/diskbuf.c | 24 ++- lib/fragments.c | 27 ++- lib/global.c | 4 + lib/inode.c | 47 +++-- lib/io.c | 41 ++--- lib/liberofs_private.h | 2 - lib/metabox.c | 2 +- lib/namei.c | 2 +- lib/rebuild.c | 6 +- lib/remotes/docker_config.c | 4 +- lib/remotes/oci.c | 11 +- lib/remotes/s3.c | 12 +- lib/super.c | 2 +- lib/tar.c | 8 +- lib/uuid.c | 5 + lib/windows_compat.c | 308 +++++++++++++++++++++++++++++++++ lib/xattr.c | 7 +- mkfs/main.c | 24 +-- scripts/msys2-ucrt64.sha256 | 17 ++ 33 files changed, 800 insertions(+), 125 deletions(-) create mode 100644 include/erofs/os.h create mode 100644 include/erofs/windows_compat.h create mode 100644 lib/windows_compat.c create mode 100644 scripts/msys2-ucrt64.sha256
Dockerfile +65 -2
@@ -1,4 +1,8 @@ -# Build fully static erofs-utils binaries +# Build static erofs-utils binaries: +# docker build --target linux --output type=local,dest=output/linux . +# docker build --target windows --output type=local,dest=output/windows . + +ARG MINGW_BUILD_PLATFORM=linux/amd64 FROM alpine:3.24.1 AS builder
@@ -46,5 +50,64 @@ RUN ./autogen.sh && \ --with-uuid && \ make -j"$(nproc)" V=1 LDFLAGS="-all-static" && make install -FROM scratch +# Cross-compile x86-64 Windows binaries with static third-party libraries. +# Alpine packages the MinGW toolchain for x86-64 build hosts. +FROM --platform=${MINGW_BUILD_PLATFORM} alpine:3.24.1 AS windows-builder + +RUN apk add --no-cache \ + build-base autoconf automake libtool pkgconf git \ + ca-certificates curl tar zstd mingw-w64-gcc + +ENV MINGW_TARGET=x86_64-w64-mingw32 MINGW_PREFIX=/ucrt64 +ENV CC=${MINGW_TARGET}-gcc \ + AR=${MINGW_TARGET}-ar \ + RANLIB=${MINGW_TARGET}-ranlib \ + WINDRES=${MINGW_TARGET}-windres + +# Use MSYS2 UCRT64 archives with Alpine's UCRT-based MinGW toolchain. +# curl-winssl uses the Windows certificate store for HTTPS. +ARG MSYS2_MIRROR=https://repo.msys2.org/mingw/ucrt64 +WORKDIR /deps +COPY scripts/msys2-ucrt64.sha256 . +RUN while read -r checksum package; do \ + curl -fLsS -o "$package" "${MSYS2_MIRROR}/$package" && \ + echo "$checksum $package" | sha256sum -c - && \ + tar --zstd -xf "$package" -C / ucrt64 || exit 1; \ + done < msys2-ucrt64.sha256 && \ + find ${MINGW_PREFIX}/lib -name '*.dll.a' -delete + +# Keep native pkg-config metadata out of cross checks. +ENV PKG_CONFIG_LIBDIR=${MINGW_PREFIX}/lib/pkgconfig PKG_CONFIG_PATH="" + +WORKDIR /build +COPY . . +RUN ./autogen.sh && mkdir build-windows && cd build-windows && \ + PKG_CONFIG="pkg-config --static" \ + CPPFLAGS="-I${MINGW_PREFIX}/include -I${MINGW_PREFIX}/include/tre" \ + LDFLAGS="-static -L${MINGW_PREFIX}/lib" \ + LIBS="-lintl -liconv" \ + ../configure --host=${MINGW_TARGET} --prefix=/output \ + --enable-static --disable-shared --enable-multithreading \ + --enable-lz4 --enable-lzma --with-zlib --with-libzstd \ + --without-uuid --without-selinux \ + --enable-s3 --enable-oci \ + --with-libcurl --with-openssl --with-libxml2 --with-json-c \ + --without-libnl3 && \ + make -j"$(nproc)" V=1 LDFLAGS="-all-static -L${MINGW_PREFIX}/lib" && \ + make install-strip && \ + for binary in /output/bin/*.exe; do \ + ${MINGW_TARGET}-objdump -p "$binary" > /tmp/imports.txt && \ + awk '/DLL Name:/ { \ + name = tolower($3); \ + if (name !~ /^(kernel32|advapi32|msvcrt|ucrtbase|bcrypt|crypt32|secur32|ws2_32|iphlpapi|wldap32|user32|gdi32|api-ms-win-crt-[a-z0-9-]+)\.dll$/) { \ + print "Unexpected DLL dependency: " $3; failed = 1 \ + } \ + } END { exit failed }' /tmp/imports.txt || exit 1; \ + done + +FROM scratch AS windows +COPY --from=windows-builder /output . + +# Keep the existing Linux output as the default target. +FROM scratch AS linux COPY --from=builder /build/output .
configure.ac +18 -4
@@ -13,22 +13,34 @@ AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_AUX_DIR(config) AC_CANONICAL_TARGET +AC_CANONICAL_HOST build_linux=no -case "${target_os}" in +build_windows=no +case "${host_os}" in linux*) build_linux=yes ;; + mingw*) + build_windows=yes + ;; esac # OS-specific treatment AM_CONDITIONAL([OS_LINUX], [test "$build_linux" = "yes"]) +AM_CONDITIONAL([OS_WINDOWS], [test "$build_windows" = "yes"]) AM_INIT_AUTOMAKE([foreign subdir-objects -Wall]) +# Enable LFS (e.g. 64-bit off_t) before compiler and feature checks. +CPPFLAGS="$CPPFLAGS -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" + # Checks for programs. AM_PROG_AR AC_PROG_CC +AS_CASE([$host_os], [mingw*], [ + CPPFLAGS="$CPPFLAGS -D__USE_MINGW_ANSI_STDIO=1" +]) AC_PROG_INSTALL LT_INIT
@@ -242,6 +254,7 @@ AC_CHECK_HEADERS(m4_flatten([ linux/types.h linux/xattr.h limits.h + regex.h stddef.h stdint.h stdlib.h
@@ -278,6 +291,10 @@ AC_CHECK_DECL(memrchr,[AC_DEFINE(HAVE_MEMRCHR, 1, #include <string.h>]) # Checks for library functions. +AC_SEARCH_LIBS([regcomp], [gnurx regex], [], [ + AC_CHECK_LIB([tre], [tre_regcomp], [], + [AC_MSG_ERROR([POSIX regex support is required (e.g. libgnurx or TRE on Windows)])]) +]) AC_CHECK_FUNCS(m4_flatten([ backtrace copy_file_range
@@ -787,9 +804,6 @@ AS_IF([test "x$enable_s3" != "xno"], [ AC_MSG_ERROR([S3 disabled: missing libcurl, openssl, or libxml2])]) ], [have_s3="no"]) -# Enable 64-bit off_t -CFLAGS+=" -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" - # Configure fuzzing mode AS_IF([test "x$enable_fuzzing" != "xyes"], [], [ CC_CHECK_CFLAGS(["-fsanitize=address,fuzzer-no-link"], [
fsck/Makefile.am +2 -0
@@ -8,6 +8,7 @@ fsck_erofs_SOURCES = main.c fsck_erofs_CFLAGS = -Wall -I$(top_srcdir)/include ${openssl_CFLAGS} fsck_erofs_LDADD = $(top_builddir)/lib/liberofs.la $(LIBEROFS_LIBS) +if !OS_WINDOWS if ENABLE_FUZZING noinst_PROGRAMS = fuzz_erofsfsck fuzz_erofsfsck_SOURCES = main.c
@@ -15,3 +16,4 @@ fuzz_erofsfsck_CFLAGS = -Wall -I$(top_srcdir)/include -DFUZZING ${openssl_CFLAGS fuzz_erofsfsck_LDFLAGS = -fsanitize=address,fuzzer fuzz_erofsfsck_LDADD = $(top_builddir)/lib/liberofs.la $(LIBEROFS_LIBS) endif +endif
fsck/main.c +12 -11
@@ -333,7 +333,7 @@ static void erofsfsck_set_attributes(struct erofs_inode *inode, char *path)erofs_warn ("failed to set times: %s" , path);if (fsckcfg.preserve_owner) { - ret =lchown (path, inode->i_uid, inode->i_gid); + ret =erofs_os_lchown (path, inode->i_uid, inode->i_gid);if (ret <0 )erofs_warn ("failed to change ownership: %s" , path); }
@@ -683,8 +683,8 @@ static inline int erofs_extract_dir(struct erofs_inode *inode)* write/execute permission. These are fixed up later in * erofsfsck_set_attributes(). */ -if (mkdir (fsckcfg.extract_path,0700 ) <0 ) { -struct stat st; +if (erofs_os_mkdir (fsckcfg.extract_path,0700 ) <0 ) { +erofs_os_stat_t st;if (errno !=EEXIST ) { erofs_err("failed to create directory: %s (%s)",
@@ -692,7 +692,7 @@ static inline int erofs_extract_dir(struct erofs_inode *inode)return -errno; } -if (lstat (fsckcfg.extract_path, &st) || +if (erofs_os_lstat (fsckcfg.extract_path, &st) || !S_ISDIR (st.st_mode)) {erofs_err ("path is not a directory: %s" , fsckcfg.extract_path);
@@ -827,9 +827,9 @@ static inline int erofs_extract_file(struct erofs_inode *inode)erofs_dbg ("extract file to path: %s" , fsckcfg.extract_path); again: - fd =open (fsckcfg.extract_path, -O_WRONLY |O_CREAT |O_NOFOLLOW | - (fsckcfg.overwrite ?O_TRUNC :O_EXCL ),0700 ); + fd =erofs_os_open (fsckcfg.extract_path, +O_WRONLY |O_CREAT |O_NOFOLLOW | + (fsckcfg.overwrite ?O_TRUNC :O_EXCL ),0700 );if (fd <0 ) {if (fsckcfg.overwrite && tryagain) {if (errno ==EISDIR ) {
@@ -898,7 +898,7 @@ static inline int erofs_extract_symlink(struct erofs_inode *inode) buf[inode->i_size] ='\0' ; again: -if (symlink (buf, fsckcfg.extract_path) <0 ) { +if (erofs_os_symlink (buf, fsckcfg.extract_path) <0 ) {if (errno ==EEXIST && fsckcfg.overwrite && tryagain) {erofs_warn ("try to forcely remove file %s" , fsckcfg.extract_path);
@@ -934,7 +934,8 @@ static int erofs_extract_special(struct erofs_inode *inode)return ret; again: -if (mknod (fsckcfg.extract_path, inode->i_mode, inode->u.i_rdev) <0 ) { +if (erofs_os_mknod (fsckcfg.extract_path, inode->i_mode, + inode->u.i_rdev) <0 ) {if (errno ==EEXIST && fsckcfg.overwrite && tryagain) {erofs_warn ("try to forcely remove file %s" , fsckcfg.extract_path);
@@ -1023,7 +1024,7 @@ verify: oldpath =erofsfsck_hardlink_find (inode->nid);if (oldpath) { -if (link (oldpath, fsckcfg.extract_path) ==-1 ) { +if (erofs_os_link (oldpath, fsckcfg.extract_path) ==-1 ) {erofs_err ("failed to extract hard link: %s (%s)" , fsckcfg.extract_path,strerror (errno));return -errno;
@@ -1139,7 +1140,7 @@ int main(int argc, char *argv[]) fsckcfg.extract_path =NULL ; fsckcfg.extract_pos =0 ; fsckcfg.umask =umask (0 ); - fsckcfg.superuser =geteuid () ==0 ; + fsckcfg.superuser =erofs_os_geteuid () ==0 ; fsckcfg.corrupted = false; fsckcfg.print_comp_ratio = false; fsckcfg.check_decomp = false;
include/erofs/defs.h +5 -2
@@ -24,6 +24,8 @@ extern "C"#include <config.h> #endif +#include "os.h" +#ifdef HAVE_ENDIAN_H #include <endian.h> #else
@@ -361,8 +363,9 @@ unsigned long __roundup_pow_of_two(unsigned long n)#define __always_inline inline#endif -#ifdef HAVE_STRUCT_STAT_ST_ATIM -/* Linux */ +#if defined(HAVE_STRUCT_STAT_ST_ATIM ) || \ + (defined(_WIN32) && !defined(__CYGWIN__)) +/* Linux and native Windows */ #define ST_ATIM_NSEC (stbuf) ((stbuf)->st_atim.tv_nsec)#define ST_CTIM_NSEC (stbuf) ((stbuf)->st_ctim.tv_nsec)#define ST_MTIM_NSEC (stbuf) ((stbuf)->st_mtim.tv_nsec)
include/erofs/err.h +1 -1
@@ -35,7 +35,7 @@ static inline const char *erofs_strerror(int err)static inline void *ERR_PTR (long error) { -return (void *)error; +return (void *)(intptr_t )error; }static inline int IS_ERR (const void *ptr)
include/erofs/inode.h +1 -1
@@ -41,7 +41,7 @@ int erofs_allocate_inode_bh_data(struct erofs_inode *inode, erofs_blk_t nblocks, int device_id);bool erofs_dentry_is_wht (struct erofs_sb_info *sbi,struct erofs_dentry *d);int __erofs_fill_inode (struct erofs_importer *im,struct erofs_inode *inode, -struct stat *st,const char *path); +erofs_os_stat_t *st,const char *path);struct erofs_inode *erofs_new_inode (struct erofs_sb_info *sbi);int erofs_importer_load_tree (struct erofs_importer *im,bool rebuild,bool incremental);
include/erofs/io.h +5 -3
@@ -17,8 +17,10 @@ extern "C"#endif #include <unistd.h> #include <sys/stat.h> -#include <sys/uio.h> #include "defs.h" +#if defined(HAVE_SYS_UIO_H ) || !defined(_WIN32) +#include <sys/uio.h> +#endif #ifndef O_BINARY #define O_BINARY 0
@@ -48,7 +50,7 @@ struct erofs_vfops {ssize_t (*read)(struct erofs_vfile *vf,void *buf,size_t len);ssize_t (*write)(struct erofs_vfile *vf,void *buf,size_t len);off_t (*lseek)(struct erofs_vfile *vf,u64 offset,int whence); -int (*fstat)(struct erofs_vfile *vf,struct stat *buf); +int (*fstat)(struct erofs_vfile *vf,erofs_os_stat_t *buf);ssize_t (*sendfile)(struct erofs_vfile *vout,struct erofs_vfile *vin,off_t *pos,size_t count); int (*xcopy)(struct erofs_vfile *vout, off_t pos,
@@ -71,7 +73,7 @@ struct erofs_vfile {ssize_t __erofs_io_pwrite (int fd,const void *buf,size_t len,u64 pos);int __erofs_0write (int fd,size_t len); -int erofs_io_fstat (struct erofs_vfile *vf,struct stat *buf); +int erofs_io_fstat (struct erofs_vfile *vf,erofs_os_stat_t *buf);ssize_t erofs_io_pwrite (struct erofs_vfile *vf,const void *buf,u64 pos,size_t len);ssize_t erofs_io_pwritev (struct erofs_vfile *vf,const struct iovec *iov,int iovcnt,u64 pos);
include/erofs/os.h new file +60 -0
60 lines not on this page · raw message
include/erofs/tar.h +1 -1
@@ -12,7 +12,7 @@ extern "C"#include "internal.h" struct erofs_pax_header { -struct stat st; +erofs_os_stat_t st;struct list_head xattrs;bool use_mtime;bool use_size;
include/erofs/windows_compat.h new file +159 -0
159 lines not on this page · raw message
lib/Makefile.am +11 -0
@@ -13,12 +13,14 @@ noinst_HEADERS = $(top_srcdir)/include/erofs_fs.h \ $(top_srcdir)/include/erofs/inode.h \ $(top_srcdir)/include/erofs/internal.h \ $(top_srcdir)/include/erofs/io.h \ + $(top_srcdir)/include/erofs/os.h \ $(top_srcdir)/include/erofs/list.h \ $(top_srcdir)/include/erofs/print.h \ $(top_srcdir)/include/erofs/bitops.h \ $(top_srcdir)/include/erofs/tar.h \ $(top_srcdir)/include/erofs/trace.h \ $(top_srcdir)/include/erofs/xattr.h \ + $(top_srcdir)/include/erofs/windows_compat.h \ $(top_srcdir)/include/erofs/compress_hints.h \ $(top_srcdir)/include/erofs/importer.h \ $(top_srcdir)/lib/liberofs_base64.h \
@@ -49,6 +51,15 @@ liberofs_la_SOURCES = config.c io.c cache.c super.c inode.c xattr.c exclude.c \ liberofs_la_CFLAGS = -Wall ${libuuid_CFLAGS} -I$(top_srcdir)/include liberofs_la_LIBADD = $(LIBEROFS_LIBS) +if OS_WINDOWS +liberofs_la_SOURCES += windows_compat.c +liberofs_la_LIBADD += -lbcrypt +check_PROGRAMS = windows_compat_test +TESTS = windows_compat_test$(EXEEXT) +windows_compat_test_SOURCES = windows_compat_test.c windows_compat.c +windows_compat_test_CPPFLAGS = -I$(top_srcdir)/include +windows_compat_test_LDADD = -lbcrypt +endif if ENABLE_LZ4 liberofs_la_CFLAGS += ${liblz4_CFLAGS} liberofs_la_SOURCES += compressor_lz4.c
lib/blobchunk.c +1 -1
@@ -602,7 +602,7 @@ int erofs_blob_init_device(struct erofs_sb_info *sbi, int device_id)if (!vf)return -ENOMEM ; - fd =open (sbi->devs[device_id -1 ].src_path, + fd =erofs_os_open (sbi->devs[device_id -1 ].src_path,O_WRONLY |O_CREAT |O_TRUNC |O_BINARY ,0666 );if (fd <0 ) { ret = -errno;
lib/config.c +5 -0
@@ -179,6 +179,11 @@ unsigned int erofs_get_available_processors(void) {#if defined(HAVE_UNISTD_H ) && defined(HAVE_SYSCONF )return sysconf (_SC_NPROCESSORS_ONLN); +#elif defined(_WIN32) +SYSTEM_INFO info; + +GetSystemInfo (&info); +return info.dwNumberOfProcessors;#else return 0 ;#endif
lib/diskbuf.c +17 -7
@@ -66,7 +66,8 @@ void erofs_diskbuf_close(struct erofs_diskbuf *db) db->sp =NULL ; } -int erofs_tmpfile (void ) +#if !defined(_WIN32) || defined(__CYGWIN__) +int erofs_os_tmpfile (void ) {#define TRAILER "tmp.XXXXXXXXXX"char buf[PATH_MAX ];
@@ -86,6 +87,7 @@ int erofs_tmpfile(void) (void )fchmod (fd,0666 & ~u); return fd; } +#endif int erofs_diskbuf_init (unsigned int nstrms) {
@@ -98,9 +100,14 @@ int erofs_diskbuf_init(unsigned int nstrms) dbufstrm = strm;for (; strm < dbufstrm + nstrms; ++strm) { -struct stat st; - -/* try to use the devfd for regfiles on stream 0 */ +erofs_os_stat_t st; + +/* +* Try to use the devfd for regfiles on stream 0. Skip Windows, +* where extending a non-sparse file can allocate the entire +* 2 TiB scratch range. +*/ +#ifndef _WIN32if (strm == dbufstrm && !g_sbi.bdev.ops) { strm->devpos =1ULL <<40 ;if (!ftruncate (g_sbi.bdev.fd, strm->devpos <<1 )) {
@@ -108,16 +115,19 @@ int erofs_diskbuf_init(unsigned int nstrms) goto setupone; } } +#endif strm->devpos =0 ; - strm->fd =erofs_tmpfile (); + strm->fd =erofs_os_tmpfile ();if (strm->fd <0 )return -ENOSPC ; +#ifndef _WIN32 setupone: +#endif strm->tailoffset =0 ;erofs_atomic_set (&strm->count,1 ); -if (fstat (strm->fd, &st)) +if (erofs_os_fstat (strm->fd, &st))return -errno; - strm->alignsize =max_t (u32, st.st_blksize,getpagesize ()); + strm->alignsize =max_t (u32, st.st_blksize,erofs_os_getpagesize ()); }return 0 ; }
lib/fragments.c +18 -9
@@ -11,7 +11,10 @@#endif #include <stdlib.h> #include <unistd.h> +#include <config.h> +#ifdef HAVE_SYS_MMAN_H #include <sys/mman.h> +#endif #include "erofs/err.h" #include "erofs/inode.h" #include "erofs/print.h"
@@ -108,7 +111,7 @@ static erofs_off_t erofs_fragment_longmatch(struct erofs_inode *inode,break ;if (!inmem) { -if (pread (epi->fd, buf[1 ], sz, pos - sz) != sz) +if (erofs_os_pread (epi->fd, buf[1 ], sz, pos - sz) != sz)break ;if (memcmp (buf[0 ], buf[1 ], sz))break ;
@@ -240,7 +243,7 @@ int erofs_pack_file_from_fd(struct erofs_inode *inode, {struct erofs_packed_inode *epi = inode->sbi->packedinode;s64 offset, rc, sz; -char *memblock; +char *memblock =NULL ;bool onheap = false;if (__erofs_unlikely (!inode->i_size))
@@ -248,12 +251,15 @@ int erofs_pack_file_from_fd(struct erofs_inode *inode, offset = epi->pos; -if (vf->ops) - memblock =NULL ; -else +#ifdef HAVE_SYS_MMAN_H +if (!vf->ops) { memblock =mmap (NULL , inode->i_size,PROT_READ ,MAP_SHARED , vf->fd, fpos); -if (memblock ==MAP_FAILED || !memblock) { +if (memblock ==MAP_FAILED ) + memblock =NULL ; + } +#endif +if (!memblock) {erofs_off_t remaining = inode->i_size;struct erofs_vfile vout = { .fd = epi->fd };bool noseek = vf->ops && !vf->ops->pread;
@@ -285,7 +291,8 @@ int erofs_pack_file_from_fd(struct erofs_inode *inode, } onheap = true; - rc =pread (epi->fd, memblock, sz, offset + inode->i_size - sz); + rc =erofs_os_pread (epi->fd, memblock, sz, + offset + inode->i_size - sz);if (rc != sz) {if (rc >=0 ) {DBG_BUGON (1 );
@@ -308,8 +315,10 @@ int erofs_pack_file_from_fd(struct erofs_inode *inode, out:if (onheap)free (memblock); +#ifdef HAVE_SYS_MMAN_H else if (memblock) munmap(memblock, inode->i_size); +#endif return rc; }
@@ -452,7 +461,7 @@ int erofs_packedfile_init(struct erofs_sb_info *sbi, bool fragments_mkfs) } } - epi->fd =erofs_tmpfile (); + epi->fd =erofs_os_tmpfile ();if (epi->fd <0 ) { err = epi->fd; goto err_out;
@@ -635,7 +644,7 @@ int erofs_packedfile_read(struct erofs_sb_info *sbi,if (!uptodate)continue ; - err =pread (epi->fd, buf, len, pos); + err =erofs_os_pread (epi->fd, buf, len, pos);if (err <0 )break ;if (err == len) {
lib/global.c +4 -0
@@ -24,6 +24,10 @@ int liberofs_global_init(void)erofs_mutex_lock (&erofs_global_mutex);erofs_init_configure (); +#ifdef _WIN32 +_setmode (STDIN_FILENO ,O_BINARY ); +_setmode (STDOUT_FILENO ,O_BINARY ); +#endif #ifdef S3EROFS_ENABLED xmlInitParser ();#endif
lib/inode.c +28 -19
152 lines not on this page · raw message
lib/io.c +16 -25
126 lines not on this page · raw message
lib/liberofs_private.h +0 -2
@@ -23,5 +23,3 @@ static inline void *memrchr(const void *s, int c, size_t n) return NULL; }#endif - -int erofs_tmpfile (void );
lib/metabox.c +1 -1
@@ -26,7 +26,7 @@ static int erofs_metamgr_init(struct erofs_sb_info *sbi, {int ret; - ret =erofs_tmpfile (); + ret =erofs_os_tmpfile ();if (ret <0 )return ret;
lib/namei.c +1 -1
@@ -19,7 +19,7 @@ static dev_t erofs_new_decode_dev(u32 dev)const unsigned int major = (dev &0xfff00 ) >>8 ;const unsigned int minor = (dev &0xff ) | ((dev >>12 ) &0xfff00 ); -return makedev (major, minor); +return erofs_os_makedev (major, minor); }int erofs_read_inode_from_disk (struct erofs_inode *vi)
lib/rebuild.c +3 -3
@@ -313,8 +313,8 @@ static int erofs_rebuild_update_inode(struct erofs_sb_info *dst_sb,case S_IFIFO :case S_IFSOCK : inode->i_size =0 ; -erofs_dbg ("\tdev: %d %d" ,major (inode->u.i_rdev), -minor (inode->u.i_rdev)); +erofs_dbg ("\tdev: %d %d" ,erofs_os_major (inode->u.i_rdev), +erofs_os_minor (inode->u.i_rdev)); inode->u.i_rdev =erofs_new_encode_dev (inode->u.i_rdev);break ;case S_IFDIR :
@@ -577,7 +577,7 @@ static int erofs_rebuild_basedir_dirent_iter(struct erofs_dir_context *ctx)if (ctx->dot_dotdot)return 0 ; - dname =strndup (ctx->dname, ctx->de_namelen); + dname =erofs_os_strndup (ctx->dname, ctx->de_namelen);if (!dname)return -ENOMEM ; d = erofs_rebuild_get_dentry(mergedir, dname, false,
lib/remotes/docker_config.c +2 -2
@@ -62,11 +62,11 @@ static char *docker_config_path(void)static char *read_file_to_string (const char *path) {FILE *fp; -struct stat st; +erofs_os_stat_t st;char *buf;size_t nread; -if (stat (path, &st) <0 ) +if (erofs_os_stat (path, &st) <0 )return NULL ;if (st.st_size <=0 || st.st_size > (1 <<22 ))
lib/remotes/oci.c +6 -5
@@ -314,7 +314,7 @@ static int ocierofs_parse_auth_header(const char *auth_header,continue ; len = param_end - param_start; - value =strndup (param_start, len); + value =erofs_os_strndup (param_start, len);if (!value) { ret = -ENOMEM ; goto out;
@@ -891,7 +891,8 @@ static int ocierofs_process_tar_stream(struct erofs_importer *importer, int fd, }while (!ret);if (decoder ==EROFS_IOS_DECODER_GZRAN ) { - zinfo_fd =open (config->zinfo_path,O_WRONLY |O_CREAT |O_TRUNC ,0644 ); + zinfo_fd =erofs_os_open (config->zinfo_path, +O_WRONLY |O_CREAT |O_TRUNC ,0644 );if (zinfo_fd <0 ) { ret = -errno; }else {
@@ -1065,7 +1066,7 @@ static int ocierofs_parse_ref(struct ocierofs_ctx *ctx, const char *ref_str)/* a dot or colon before the slash indicating a registry */ if ((dot && dot < slash) || (colon && colon < slash)) { len = slash - ref_str; - tmp =strndup (ref_str, len); + tmp =erofs_os_strndup (ref_str, len);if (!tmp)return -ENOMEM ;free (ctx->registry);
@@ -1081,7 +1082,7 @@ static int ocierofs_parse_ref(struct ocierofs_ctx *ctx, const char *ref_str) colon =strchr (repo_part,':' );if (colon) { len = colon - repo_part; - tmp =strndup (repo_part, len); + tmp =erofs_os_strndup (repo_part, len); }else { tmp =strdup (repo_part); }
@@ -1259,7 +1260,7 @@ static int ocierofs_extract_layer(struct ocierofs_ctx *ctx, stream = (struct ocierofs_stream ) { .digest = digest, - .blobfd =erofs_tmpfile (), + .blobfd =erofs_os_tmpfile (), };if (stream.blobfd <0 ) {erofs_err ("failed to create temporary file for %s" , digest);
lib/remotes/s3.c +6 -6
@@ -56,7 +56,7 @@ static const char *s3erofs_parse_host(const char *endpoint, const char **schema) }else { host = split +sizeof ("://" ) -1 ;if (schema) { - *schema =strndup (endpoint, host - endpoint); + *schema =erofs_os_strndup (endpoint, host - endpoint);if (!*schema)return ERR_PTR (-ENOMEM ); }
@@ -962,7 +962,7 @@ s3erofs_create_object_iterator(struct erofs_s3 *s3, const char *path, ret = -EINVAL ; goto err; } - iter->bucket =strndup (path, prefix - path); + iter->bucket =erofs_os_strndup (path, prefix - path); iter->prefix =strdup (prefix); }
@@ -1127,7 +1127,7 @@ int s3erofs_build_trees(struct erofs_importer *im, struct erofs_s3 *s3,struct s3erofs_object_info *obj;struct erofs_dentry *d;struct erofs_inode *inode; -struct stat st; +erofs_os_stat_t st;char *trimmed;bool dumb;int ret;
@@ -1431,17 +1431,17 @@ err_free:int s3erofs_parse_s3fs_passwd (const char *filepath,char *ak,char *sk) {char buf[S3_ACCESS_KEY_LEN +S3_SECRET_KEY_LEN +3 ]; -struct stat st; +erofs_os_stat_t st;int fd, n, ret;char *colon; - fd =open (filepath,O_RDONLY ); + fd =erofs_os_open (filepath,O_RDONLY );if (fd <0 ) {erofs_err ("failed to open passwd_file %s" , filepath);return -errno; } - ret =fstat (fd, &st); + ret =erofs_os_fstat (fd, &st);if (ret) { ret = -errno; goto err;
lib/super.c +1 -1
@@ -500,7 +500,7 @@ int erofs_mkfs_format_fs(struct erofs_sb_info *sbi, unsigned int blkszbits,int erofs_mkfs_load_fs (struct erofs_sb_info *sbi,unsigned int dsunit) {union { -struct stat st; +erofs_os_stat_t st;erofs_blk_t startblk; } u;struct erofs_bufmgr *bmgr;
lib/tar.c +4 -4
@@ -759,7 +759,7 @@ static int tarerofs_write_file_data(struct erofs_inode *inode, nread = -EIO ;break ; } -if (pwrite (fd, buf, nread, off) != nread) { +if (erofs_os_pwrite (fd, buf, nread, off) != nread) { nread = -EIO ;break ; }
@@ -779,7 +779,7 @@ int tarerofs_parse_tar(struct erofs_importer *im, struct erofs_tarfile *tar)struct erofs_inode *root = im->root;bool whout, opq, e = false;char _path[PATH_MAX +1 ], *path = _path +1 ; -struct stat st; +erofs_os_stat_t st;mode_t mode;erofs_off_t tar_offset, dataoff;
@@ -1044,10 +1044,10 @@ out_eot: goto out; } - st.st_rdev =makedev (major, minor); + st.st_rdev =erofs_os_makedev (major, minor); }else if (th->typeflag =='1' || th->typeflag =='2' ) {if (!eh.link) - eh.link =strndup (th->linkname,sizeof (th->linkname)); + eh.link =erofs_os_strndup (th->linkname,sizeof (th->linkname)); }/* EROFS metadata index referring to the original tar data */
lib/uuid.c +5 -0
@@ -20,8 +20,10 @@#else #define _GNU_SOURCE#include <unistd.h> +#ifdef __linux__#include <sys/syscall.h> #endif +#endif /* Flags to be used, will be modified if kernel does not support them */ static unsigned int erofs_grnd_flag =
@@ -43,6 +45,9 @@ static int s_getrandom(void *out, unsigned size, bool insecure)#if defined(HAVE_SYS_RANDOM_H ) && defined(HAVE_GETRANDOM ) r =getrandom (out, size, flags); +#elif defined(_WIN32) + (void )flags; + r =erofs_win_random (out, size);#elif defined(__linux__) && defined(__NR_getrandom) r = (ssize_t )syscall (__NR_getrandom, out, size, flags);#else
lib/windows_compat.c new file +308 -0
308 lines not on this page · raw message
lib/xattr.c +4 -3
@@ -792,7 +792,7 @@ static int erofs_count_all_xattrs_from_path(struct erofs_sb_info *sbi, {int ret;DIR *_dir; -struct stat st; +erofs_os_stat_t st; _dir =opendir (path);if (!_dir) {
@@ -826,7 +826,7 @@ static int erofs_count_all_xattrs_from_path(struct erofs_sb_info *sbi, goto fail; } - ret =lstat (buf, &st); + ret =erofs_os_lstat (buf, &st);if (ret) { ret = -errno; goto fail;
@@ -1207,7 +1207,8 @@ static int erofs_init_inode_xattrs(struct erofs_inode *vi) ih = it.kaddr; vi->xattr_shared_count = ih->h_shared_count; - vi->xattr_shared_xattrs =malloc (vi->xattr_shared_count *sizeof (uint)); + vi->xattr_shared_xattrs =malloc (vi->xattr_shared_count * +sizeof (*vi->xattr_shared_xattrs));if (!vi->xattr_shared_xattrs) {erofs_put_metabuf (&it.buf);return -ENOMEM ;
mkfs/main.c +13 -11
@@ -657,7 +657,7 @@ static int mkfs_parse_s3_cfg(char *cfg_str) p =strchr (cfg_str,',' );if (p) { - s3cfg.endpoint =strndup (cfg_str, p - cfg_str); + s3cfg.endpoint =erofs_os_strndup (cfg_str, p - cfg_str); }else { s3cfg.endpoint =strdup (cfg_str);return 0 ;
@@ -698,7 +698,7 @@ static int mkfs_parse_s3_cfg(char *cfg_str) }else if ((p =strstr (opt,"region=" ))) { p +=strlen ("region=" ); opt =strchr (cfg_str,',' ); - s3cfg.region = opt ?strndup (p, opt - p) :strdup (p); + s3cfg.region = opt ?erofs_os_strndup (p, opt - p) :strdup (p); }else {erofs_err ("invalid --s3 option %s" , opt);return -EINVAL ;
@@ -742,7 +742,7 @@ static int erofs_mkfs_strtoll(const char *nptr, char **endptr,static int erofs_mkfs_strtol (const char *nptr,char **endptr,long *res,int base) { -long long res_ll; +long long res_ll =0 ;int ret; ret =erofs_mkfs_strtoll (nptr, endptr, &res_ll, base);
@@ -966,20 +966,20 @@ static void erofs_rebuild_cleanup(void)static int mkfs_parse_sources (int argc,char *argv[],int optind) { -struct stat st; +erofs_os_stat_t st;int err, fd;char *s;switch (source_mode) {case EROFS_MKFS_SOURCE_LOCALDIR : - err =lstat ((s = argv[optind++]), &st); + err =erofs_os_lstat ((s = argv[optind++]), &st);if (err) {erofs_err ("failed to stat %s: %s" , s,erofs_strerror (-errno));return -ENOENT ; }if (S_ISDIR (st.st_mode)) { - cfg.c_src_path =realpath (s,NULL ); + cfg.c_src_path =erofs_os_realpath (s,NULL );if (!cfg.c_src_path) {erofs_err ("failed to parse source directory: %s" ,erofs_strerror (-errno));
@@ -997,7 +997,7 @@ static int mkfs_parse_sources(int argc, char *argv[], int optind) cfg.c_src_path =strdup (argv[optind++]);if (!cfg.c_src_path)return -ENOMEM ; - fd =open (cfg.c_src_path,O_RDONLY ); + fd =erofs_os_open (cfg.c_src_path,O_RDONLY );if (fd <0 ) {erofs_err ("failed to open tar file: %s" , cfg.c_src_path);return -errno;
@@ -1008,8 +1008,8 @@ static int mkfs_parse_sources(int argc, char *argv[], int optind)return err;if (erofstar.dumpfile) { - fd =open (erofstar.dumpfile, -O_WRONLY |O_CREAT |O_TRUNC ,0644 ); + fd =erofs_os_open (erofstar.dumpfile, +O_WRONLY |O_CREAT |O_TRUNC ,0644 );if (fd <0 ) {erofs_err ("failed to open dumpfile: %s" , erofstar.dumpfile);
@@ -1624,7 +1624,8 @@ static void erofs_mkfs_default_options(struct erofs_importer_params *params) cfg.c_mt_workers =erofs_get_available_processors (); cfg.c_mkfs_segment_size =16ULL *1024 *1024 ;#endif - mkfs_blkszbits =ilog2 (min_t (u32,getpagesize (),EROFS_MAX_BLOCK_SIZE )); + mkfs_blkszbits =ilog2 (min_t (u32,erofs_os_getpagesize (), +EROFS_MAX_BLOCK_SIZE )); params->pclusterblks_max =1U ; params->pclusterblks_def =1U ; g_sbi.feature_incompat =0 ;
@@ -2091,7 +2092,8 @@ exit:struct erofs_vfile vf;int fd; - fd =open (mkfs_aws_zinfo_file,O_WRONLY |O_CREAT |O_TRUNC ,0644 ); + fd =erofs_os_open (mkfs_aws_zinfo_file, +O_WRONLY |O_CREAT |O_TRUNC ,0644 );if (fd <0 ) { err = -errno; }else {
scripts/msys2-ucrt64.sha256 new file +17 -0
@@ -0,0 +1,17 @@ +e3257d4303fc0aca4c64f702d4c8cd766a321351c5e61927631c30bfdf2e7536 mingw-w64-ucrt-x86_64-brotli-1.2.1-1-any.pkg.tar.zst +a95c349e1a838a825d4c6723c0fc497ae62d7ca9fe68b517552fd80afa5cd5f1 mingw-w64-ucrt-x86_64-c-ares-1.34.9-1-any.pkg.tar.zst +d96afb79b32b3831f98929762a2b2eb4177e6859db0b348e10551893f755de76 mingw-w64-ucrt-x86_64-curl-winssl-8.23.0-1-any.pkg.tar.zst +ba693dda4ac375af76ce481ff3a6e7481286546cc7dc6d56c7021dae34084157 mingw-w64-ucrt-x86_64-gettext-runtime-1.0-1-any.pkg.tar.zst +e209dfd2e0955a9ab22bf394b13d477b2d24ae2660327e3981651efd464be0d5 mingw-w64-ucrt-x86_64-json-c-0.19-2-any.pkg.tar.zst +9a500f38c2b91808741c62fae746b3e9110b33a1ecf5c30fa0c66dbedddf7e16 mingw-w64-ucrt-x86_64-libiconv-1.19-1-any.pkg.tar.zst +d5f4b5e9d99ff7b2a986d1dc0c73da2bcd93ba68462be7b1debbd6ef76371f57 mingw-w64-ucrt-x86_64-libidn2-2.3.8-4-any.pkg.tar.zst +d96e0bb50ac3f8b6e44a39ea8de8d186f7b08f6938b0676eb69a7ba1f127bcf4 mingw-w64-ucrt-x86_64-libpsl-0.21.5-3-any.pkg.tar.zst +26710b6978533c38b60a33762e99128bd74f8520896bb9486656e4aa741bbe5b mingw-w64-ucrt-x86_64-libssh2-wincng-1.11.1-2-any.pkg.tar.zst +d50f22545c50d7c0cd584474bba83f0c7a2cd8aab1aed1ad6c1f9c6452f3c4fc mingw-w64-ucrt-x86_64-libtre-0.9.0-2-any.pkg.tar.zst +e784273da19bbdcc91cbb510b5e27c3ac021b026140734eefcce5ccbd878bd97 mingw-w64-ucrt-x86_64-libunistring-1.4.2-1-any.pkg.tar.zst +e774c85139c004ce9b4085474d6b3450526c718d2e8c555a87e47adc11f376b1 mingw-w64-ucrt-x86_64-libxml2-2.15.4-3-any.pkg.tar.zst +00a807df81a4b7e82445178b8625962ed592cf1f0a08a8e04c8b9338c4362638 mingw-w64-ucrt-x86_64-lz4-1.10.0-1-any.pkg.tar.zst +773e021ebad83f14b5c103db467411e8ff064663e1c7e7f730e2be72f4117064 mingw-w64-ucrt-x86_64-openssl-3.6.5-1-any.pkg.tar.zst +a9d771f816d8c0c5bde152ffb27a687ede91079b8e77e5b8297efa3b5a835934 mingw-w64-ucrt-x86_64-xz-5.8.4-1-any.pkg.tar.zst +130e6ef04c654fc2150a177600aa5ed0035087665a893479d2c85ba7485d5704 mingw-w64-ucrt-x86_64-zlib-1.3.2-3-any.pkg.tar.zst +dbdb8427280046a2b41697780aa4c52983b708082b0da4755951dc3bea96ca89 mingw-w64-ucrt-x86_64-zstd-1.5.7-2-any.pkg.tar.zst
Signature · 1 line
2.54.0 (Apple Git-157)
PATCH 5/5 erofs-utils: lib: reject seeks on Windows pipes
In reply to Gao XiangThe Windows CRT can report successful seeks on pipes without advancing the read position. This makes TAR input appear seekable and corrupts parsing when skipped data is not consumed.
Adapt erofs_os_lseek() to return ESPIPE for Windows pipes and use it throughout the library and tools. This keeps pipe input on the read-and-discard path.
--- fsck/main.c | 2 +- include/erofs/os.h | 1 + include/erofs/windows_compat.h | 1 + lib/blobchunk.c | 6 +++--- lib/fragments.c | 2 +- lib/inode.c | 8 ++++---- lib/io.c | 4 ++-- lib/remotes/oci.c | 2 +- lib/tar.c | 4 ++-- lib/windows_compat.c | 14 ++++++++++++++ lib/xattr.c | 4 ++-- 11 files changed, 32 insertions(+), 16 deletions(-)
fsck/main.c +1 -1
@@ -571,7 +571,7 @@ static int erofs_verify_inode_data(struct erofs_inode *inode, int outfd, } }if (outfd >=0 ) { -if (lseek (outfd, map.m_llen,SEEK_CUR ) <0 ) { +if (erofs_os_lseek (outfd, map.m_llen,SEEK_CUR ) <0 ) { ret = -errno; goto out; }
include/erofs/os.h +1 -0
@@ -33,6 +33,7 @@ typedef struct stat erofs_os_stat_t;#define erofs_os_fstat fstat#define erofs_os_open open#define erofs_os_link link +#define erofs_os_lseek lseek#define erofs_os_pread pread#define erofs_os_pwrite pwrite#define erofs_os_realpath realpath
include/erofs/windows_compat.h +1 -0
@@ -82,6 +82,7 @@ int erofs_os_lstat(const char *path, erofs_os_stat_t *st);int erofs_os_fstat (int fd,erofs_os_stat_t *st);int erofs_os_open (const char *path,int flags, ...);int erofs_os_link (const char *oldpath,const char *newpath); +off_t erofs_os_lseek (int fd,off_t offset,int whence);ssize_t erofs_os_pread (int fd,void *buf,size_t len,off_t offset);ssize_t erofs_os_pwrite (int fd,const void *buf,size_t len,off_t offset);char *erofs_os_realpath (const char *path,char *resolved);
lib/blobchunk.c +3 -3
@@ -336,7 +336,7 @@ int erofs_blob_write_chunked_file(struct erofs_inode *inode, int fd,ssize_t ret;/* if the file is fully sparsed, use one big chunk instead */ -if (lseek (fd, startoff,SEEK_DATA ) <0 && errno ==ENXIO ) { +if (erofs_os_lseek (fd, startoff,SEEK_DATA ) <0 && errno ==ENXIO ) { chunkbits =ilog2 (inode->i_size -1 ) +1 ;if (chunkbits < sbi->blkszbits) chunkbits = sbi->blkszbits;
@@ -369,14 +369,14 @@ int erofs_blob_write_chunked_file(struct erofs_inode *inode, int fd, interval_start =0 ;for (pos =0 ; pos < inode->i_size; pos += len) { -off_t offset =lseek (fd, pos + startoff,SEEK_DATA ); +off_t offset =erofs_os_lseek (fd, pos + startoff,SEEK_DATA );if (offset >=0 && offset < startoff + inode->i_size) { offset -= startoff;if (offset != (offset & ~(chunksize -1 ))) { offset &= ~(chunksize -1 ); -if (lseek (fd, offset + startoff,SEEK_SET ) != +if (erofs_os_lseek (fd, offset + startoff,SEEK_SET ) != startoff + offset) { ret = -EIO ; goto err;
lib/fragments.c +1 -1
@@ -266,7 +266,7 @@ int erofs_pack_file_from_fd(struct erofs_inode *inode,off_t pos = fpos; memblock =NULL ; - rc =lseek (epi->fd, offset,SEEK_SET ); + rc =erofs_os_lseek (epi->fd, offset,SEEK_SET );if (rc <0 ) { rc = -errno; goto out;
lib/inode.c +4 -4
@@ -1525,7 +1525,7 @@ static int erofs_mkfs_job_write_file(const struct erofs_mkfs_btctx *btctx,int ret;if (inode->datasource ==EROFS_INODE_DATA_SOURCE_DISKBUF && -lseek (ctx->fd, ctx->fpos,SEEK_SET ) <0 ) { +erofs_os_lseek (ctx->fd, ctx->fpos,SEEK_SET ) <0 ) { ret = -errno; goto out; }
@@ -1534,7 +1534,7 @@ static int erofs_mkfs_job_write_file(const struct erofs_mkfs_btctx *btctx, ret =erofs_write_compressed_file (ctx->ictx);if (ret !=EROFS_RETVAL_FALLBACK ) goto out; -if (lseek (ctx->fd, ctx->fpos,SEEK_SET ) <0 ) { +if (erofs_os_lseek (ctx->fd, ctx->fpos,SEEK_SET ) <0 ) { ret = -errno; goto out; }
@@ -2393,7 +2393,7 @@ struct erofs_inode *erofs_mkfs_build_special_from_fd(struct erofs_importer *im,void *ictx;int ret; - ret =lseek (fd,0 ,SEEK_SET ); + ret =erofs_os_lseek (fd,0 ,SEEK_SET );if (ret <0 )return ERR_PTR (-errno);
@@ -2432,7 +2432,7 @@ struct erofs_inode *erofs_mkfs_build_special_from_fd(struct erofs_importer *im,if (ret !=EROFS_RETVAL_FALLBACK )return ERR_PTR (ret); - ret =lseek (fd,0 ,SEEK_SET ); + ret =erofs_os_lseek (fd,0 ,SEEK_SET );if (ret <0 )return ERR_PTR (-errno); }
lib/io.c +2 -2
@@ -567,7 +567,7 @@ off_t erofs_io_lseek(struct erofs_vfile *vf, u64 offset, int whence)if (vf->ops)return vf->ops->lseek (vf, offset, whence); - ret =lseek (vf->fd, offset, whence); + ret =erofs_os_lseek (vf->fd, offset, whence);return ret <0 ? -errno : ret; }
@@ -643,7 +643,7 @@ int erofs_io_xcopy(struct erofs_vfile *vout, off_t pos,#endif #if defined(HAVE_SYS_SENDFILE_H ) && defined(HAVE_SENDFILE )if (len && !noseek) { - ret =lseek (vout->fd, pos,SEEK_SET ); + ret =erofs_os_lseek (vout->fd, pos,SEEK_SET );if (ret == pos) { ret =sendfile (vout->fd, vin->fd,NULL , len);if (ret >0 ) {
lib/remotes/oci.c +1 -1
@@ -1271,7 +1271,7 @@ static int ocierofs_extract_layer(struct ocierofs_ctx *ctx,if (ret) goto out; -if (lseek (stream.blobfd,0 ,SEEK_SET ) <0 ) { +if (erofs_os_lseek (stream.blobfd,0 ,SEEK_SET ) <0 ) {erofs_err ("failed to seek to beginning of temp file: %s" ,strerror (errno)); ret = -errno;
lib/tar.c +2 -2
@@ -123,13 +123,13 @@ int erofs_iostream_open(struct erofs_iostream *ios, int fd, int decoder)return PTR_ERR (ios->gb); }else { ios->vf.fd = fd; - fsz =lseek (fd,0 ,SEEK_END ); + fsz =erofs_os_lseek (fd,0 ,SEEK_END );if (fsz <=0 ) { ios->feof = !fsz; ios->sz =0 ; }else { ios->sz = fsz; -if (lseek (fd,0 ,SEEK_SET )) +if (erofs_os_lseek (fd,0 ,SEEK_SET ))return -EIO ;#ifdef HAVE_POSIX_FADVISE if (posix_fadvise (fd,0 ,0 ,POSIX_FADV_SEQUENTIAL ))
lib/windows_compat.c +14 -0
@@ -186,6 +186,20 @@ int erofs_os_link(const char *oldpath, const char *newpath)return -1 ; } +off_t erofs_os_lseek (int fd,off_t offset,int whence) +{ +HANDLE h = (HANDLE )_get_osfhandle (fd); + +if (h ==INVALID_HANDLE_VALUE ) +return -1 ; +/* The CRT can report a successful seek on a pipe without moving it. */ +if (GetFileType (h) ==FILE_TYPE_PIPE ) { + errno =ESPIPE ; +return -1 ; + } +return _lseeki64 (fd, offset, whence); +} +static ssize_t erofs_win_pio (int fd,void *buf,size_t len,off_t offset,int writing) {
lib/xattr.c +2 -2
@@ -899,7 +899,7 @@ int erofs_xattr_flush_name_prefixes(struct erofs_importer *im, bool plain)erofs_sb_set_fragments (sbi); _vf = (struct erofs_vfile ){ .fd =erofs_packedfile (sbi) }; vf = &_vf; - offset =lseek (vf->fd,0 ,SEEK_CUR ); + offset =erofs_os_lseek (vf->fd,0 ,SEEK_CUR );if (offset <0 )return -errno; bmgr =NULL ;
@@ -960,7 +960,7 @@ int erofs_xattr_flush_name_prefixes(struct erofs_importer *im, bool plain)erofs_bdrop (bh, false); }else {DBG_BUGON (bmgr); -if (lseek (vf->fd, offset,SEEK_SET ) <0 ) +if (erofs_os_lseek (vf->fd, offset,SEEK_SET ) <0 )return -errno; }erofs_sb_set_xattr_prefixes (sbi);
Signature · 1 line
2.54.0 (Apple Git-157)
Quoted 32 lines · Gao Xiang
Track the packed inode position in memory instead of querying the file offset. Use positional writes for fragment data and seek explicitly before the sendfile fallback.
Factor out
__erofs_io_pwrite()and fix its short-write handling.Assisted-by ChatGPT:gpt-6.1-solSigned-off-by Gao Xiang <[email protected]>--- include/erofs/io.h | 2 +- lib/fragments.c | 44 +++++++++++++++++++++----------------------- lib/io.c | 29 ++++++++++++++--------------- 3 files changed, 36 insertions(+), 39 deletions(-)include/erofs/io.h +1
-1@@ -68,7 +68,7 @@ struct erofs_vfile { }; }; -ssize_t __erofs_io_write (int fd,const void *buf,size_t len); +ssize_t __erofs_io_pwrite (int fd,const void *buf,size_t len,u64 pos);int __erofs_0write (int fd,size_t len);int erofs_io_fstat (struct erofs_vfile *vf,struct stat *buf);lib/fragments.c +0
-0
lib/fragments.c struct erofs_packed_inode { · line 52
Quoted 4 lines
lib/fragments.c +1
-0@@ -49,6 +49,7 @@ struct erofs_packed_inode {unsigned long *uptodate;erofs_mutex_t mutex;u64 uptodate_bits; +erofs_off_t pos;
erofs_xattr_flush_name_prefixes() also manipulates the packed inode's fd offset.
if (bh) {
bh->op = &erofs_drop_directly_bhops;
err = erofs_bh_balloon(bh, offset - start);
if (err < 0)
return err;
bh->op = &erofs_drop_directly_bhops;
erofs_bdrop(bh, false);
} else {
DBG_BUGON(bmgr);
if (lseek(vf->fd, offset, SEEK_SET) < 0) // maybe a packedinode return -errno;
}
Introducing a separate pos field would leave the two out of sync; how should this be handled?
Thanks,
Yifan Zhao
Quoted 181 lines
lib/fragments.c +20
-23};const char *erofs_frags_packedname ="packed_file" ;@@ -245,9 +246,7 @@ int erofs_pack_file_from_fd(struct erofs_inode *inode,if (__erofs_unlikely (!inode->i_size))return 0 ; - offset =lseek (epi->fd,0 ,SEEK_CUR ); -if (offset <0 ) -return -errno; + offset = epi->pos;if (vf->ops) memblock =NULL ;@@ -260,20 +259,24 @@ int erofs_pack_file_from_fd(struct erofs_inode *inode,bool noseek = vf->ops && !vf->ops->pread;off_t pos = fpos; + memblock =NULL ; + rc =lseek (epi->fd, offset,SEEK_SET ); +if (rc <0 ) { + rc = -errno; + goto out; + }do { sz =min_t (u64, remaining,UINT_MAX ); rc =erofs_io_sendfile (&vout, vf, noseek ?NULL : &pos, sz); -if (rc <=0 ) -break ; +if (rc <=0 ) { +if (!rc) + rc = -EIO ; + goto out; + } remaining -= rc; }while (remaining); -if (remaining && rc >=0 ) { - rc = -EIO ; - goto out; - } - sz =min_t (u64, inode->i_size,EROFS_FRAGMENT_INMEM_SZ_MAX ); memblock =malloc (sz);if (!memblock) {@@ -291,7 +294,7 @@ int erofs_pack_file_from_fd(struct erofs_inode *inode, goto out; } }else { - rc =__erofs_io_write (epi->fd, memblock, inode->i_size); + rc =__erofs_io_pwrite (epi->fd, memblock, inode->i_size, offset);if (rc != inode->i_size) {if (rc >=0 ) rc = -EIO ;@@ -299,6 +302,7 @@ int erofs_pack_file_from_fd(struct erofs_inode *inode, } } + epi->pos = offset + inode->i_size; rc =erofs_fragment_pack (inode, memblock, offset, inode->i_size, tofh, onheap); out:@@ -332,17 +336,16 @@ int erofs_fragment_commit(struct erofs_inode *inode, u32 tofh)return 0 ; } - offset =lseek (epi->fd,0 ,SEEK_CUR ); -if (offset <0 ) -return -errno; + offset = epi->pos; - ret =write (epi->fd, fi->data, fi->length); + ret =__erofs_io_pwrite (epi->fd, fi->data, fi->length, offset);if (ret != fi->length) {if (ret <0 )return -errno;return -EIO ; } offset += fi->length; + epi->pos = offset;if (!list_empty (&fi->list)) {struct erofs_fragment_bucket *bk = &epi->bks[FRAGMENT_HASH (tofh)];@@ -380,7 +383,7 @@ int erofs_flush_packed_inode(struct erofs_importer *im)if (!epi || !erofs_sb_has_fragments (sbi))return 0 ; -if (lseek (epi->fd,0 ,SEEK_CUR ) <=0 ) +if (!epi->pos)return 0 ;erofs_update_progressinfo ("Processing packed data ..." );@@ -460,7 +463,6 @@ int erofs_packedfile_init(struct erofs_sb_info *sbi, bool fragments_mkfs) .sbi = sbi, .nid = sbi->packed_nid, }; -s64 offset; err =erofs_read_inode_from_disk (&ei);if (err) {@@ -469,11 +471,7 @@ int erofs_packedfile_init(struct erofs_sb_info *sbi, bool fragments_mkfs) goto err_out; } - offset =lseek (epi->fd, ei.i_size,SEEK_SET ); -if (offset <0 ) { - err = -errno; - goto err_out; - } + epi->pos = ei.i_size; epi->uptodate_bits =round_up (BLK_ROUND_UP (sbi, ei.i_size),sizeof (epi->uptodate) *8 ); epi->uptodate =calloc (1 , epi->uptodate_bits >>3 );@@ -548,7 +546,7 @@ static void *erofs_packedfile_preload(struct erofs_inode *pi,if (err) goto err_out; - err =pwrite (epi->fd, buffer, map->m_llen, map->m_la); + err =__erofs_io_pwrite (epi->fd, buffer, map->m_llen, map->m_la);if (err <0 ) { err = -errno;if (err == -ENOSPC ) {lib/io.c +14
-15@@ -26,7 +26,7 @@#define EROFS_MODNAME "erofs_io"#include "erofs/print.h" -ssize_t __erofs_io_write (int fd,const void *buf,size_t len) +static ssize_t __erofs_io_write (int fd,const void *buf,size_t len) {ssize_t ret, written =0 ;@@ -61,24 +61,12 @@ int erofs_io_fstat(struct erofs_vfile *vf, struct stat *buf)return fstat (vf->fd, buf); } -ssize_t erofs_io_pwrite (struct erofs_vfile *vf,const void *buf, -u64 pos,size_t len) +ssize_t __erofs_io_pwrite (int fd,const void *buf,size_t len,u64 pos) {ssize_t ret, written =0 ; -if (__erofs_unlikely (cfg.c_dry_run)) -return 0 ; - -if (vf->ops) -return vf->ops->pwrite (vf, buf, pos, len); - - pos += vf->offset; do { -#ifdef HAVE_PWRITE64 - ret = pwrite64(vf->fd, buf, len, (off64_t)pos); -#else - ret = pwrite(vf->fd, buf, len, (off_t)pos); -#endif + ret = pwrite(fd, buf, len - written, (off_t)pos); if (ret <= 0) { if (!ret) break;@@ -96,6 +84,17 @@ ssize_t erofs_io_pwrite(struct erofs_vfile *vf, const void *buf,return written; } +ssize_t erofs_io_pwrite (struct erofs_vfile *vf,const void *buf, +u64 pos,size_t len) +{ +if (__erofs_unlikely (cfg.c_dry_run)) +return 0 ; + +if (vf->ops) +return vf->ops->pwrite (vf, buf, pos, len); +return __erofs_io_pwrite (vf->fd, buf, len, pos + vf->offset); +} +ssize_t erofs_io_pwritev (struct erofs_vfile *vf,const struct iovec *iov,int iovcnt,u64 pos) {