Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
Cygwin target add fuse.erofs
Browse files Browse the repository at this point in the history
  • Loading branch information
affggh committed Jul 16, 2023
1 parent 2666199 commit b3b28c2
Show file tree
Hide file tree
Showing 15 changed files with 2,117 additions and 0 deletions.
49 changes: 49 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ else
ext =
endif

ifeq ($(shell uname -m | tr -d "\n"), x86_64)
arch = x64
else
ifeq ($(shell uname -m | tr -d "\n"), i686)
arch = x86
else
arch = unknow
endif
endif

EROFS_DEF_DEFINES = \
-Wall \
-Werror \
Expand Down Expand Up @@ -44,6 +54,11 @@ endif
ifeq ($(shell uname -s | cut -d "-" -f 1), CYGWIN_NT)
EROFS_DEF_REMOVE = -DHAVE_LINUX_TYPES_H -DHAVE_FALLOCATE
EROFS_DEF_DEFINES += -Wno-address-of-temporary
ifeq ($(shell uname -o | tr -d "\n"), Cygwin)
ifeq ($(shell [ -d "winfsp" ] && echo "true"), true)
EROFS_DEF_DEFINES += -DCYGFUSE -Wno-missing-braces
endif
endif
override EROFS_DEF_DEFINES := $(filter-out $(EROFS_DEF_REMOVE),$(EROFS_DEF_DEFINES))
LDFLAGS += -liconv
endif
Expand Down Expand Up @@ -72,6 +87,12 @@ INCLUDES = \
-I./libcutils/include \
-I./extract/extract/include

ifeq ($(shell uname -o | tr -d "\n"), Cygwin)
ifeq ($(shell [ -d "winfsp" ] && echo "true"), true)
INCLUDES += -I./winfsp/$(arch)/usr/include/fuse
endif
endif

liberofs_src = $(shell find lib -name \*.c)
liberofs_obj = $(patsubst %.c,obj/%.o,$(liberofs_src))

Expand All @@ -84,6 +105,9 @@ fsck_obj = $(patsubst %.c,obj/%.o,$(fsck_src))
dump_src = $(shell find dump -name \*.c)
dump_obj = $(patsubst %.c,obj/%.o,$(dump_src))

fuse_src = $(shell find fuse -name \*.c)
fuse_obj = $(patsubst %.c,obj/%.o,$(fuse_src))

# Addon extract.erofs
ifeq ($(shell [ -d "extract" ] && echo "true"), true)
extract_src = $(shell find extract/extract -name \*.cpp)
Expand All @@ -109,10 +133,23 @@ all_bin_prefix = \
ifeq ($(shell [ -d "extract" ] && echo "true"), true)
all_bin_prefix += extract
endif

ifeq ($(shell uname -o | tr -d "\n"), Cygwin)

ifeq ($(shell [ -d "winfsp" ] && echo "true"), true)
all_bin_prefix += fuse
endif

all_bin = $(patsubst %,bin/%.erofs$(ext),$(all_bin_prefix))
ifeq ($(shell uname -s | cut -d "-" -f 1), CYGWIN_NT)
all_bin += bin/cygwin1.dll
endif
ifeq ($(shell [ -d "winfsp" ] && echo "true"), true)
all_bin+= bin/cygfuse-2.8.dll
endif

endif

strip_bin = $(filter-out %.dll,$(all_bin))

.PHONY: all
Expand Down Expand Up @@ -213,6 +250,18 @@ bin/extract.erofs$(ext): $(extract_obj) $(all_lib)
@echo -e "\tLD\t $@"
@$(LD) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)

# No nesseary to build fuse but cygwin provide cygfuse we can still use this
bin/fuse.erofs$(ext): $(fuse_obj) $(all_lib)
@mkdir -p `dirname $@`
@echo -e "\tLD\t $@"
@$(LD) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) winfsp/$(arch)/usr/lib/libfuse-2.8.dll.a

# cygfuse-2.8.dll is for fuse.erofs
bin/cygfuse-2.8.dll:
@mkdir -p `dirname $@`
@echo -e "\tCOPY \t$@"
@$(CP) winfsp/$(arch)/usr/$@ $@

# cygwin1.dll is needed
bin/cygwin1.dll:
@mkdir -p `dirname $@`
Expand Down
16 changes: 16 additions & 0 deletions winfsp/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cd "$(dirname "$0")"
case $(uname -m) in
x86_64)
tar -C/ -xaf x64/fuse-*.tar.xz
tar -C/ -xaf x64/fuse3-*.tar.xz
;;
i686)
tar -C/ -xaf x86/fuse-*.tar.xz
tar -C/ -xaf x86/fuse3-*.tar.xz
;;
*)
echo unsupported architecture 1>&2
exit 1
;;
esac
echo FUSE for Cygwin installed.
16 changes: 16 additions & 0 deletions winfsp/uninstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cd "$(dirname "$0")"
case $(uname -m) in
x86_64)
tar -taf x64/fuse-*.tar.xz | sed -e '/\/$/d' -e 's/.*/\/&/' | xargs rm -f
tar -taf x64/fuse3-*.tar.xz | sed -e '/\/$/d' -e 's/.*/\/&/' | xargs rm -f
;;
i686)
tar -taf x86/fuse-*.tar.xz | sed -e '/\/$/d' -e 's/.*/\/&/' | xargs rm -f
tar -taf x86/fuse3-*.tar.xz | sed -e '/\/$/d' -e 's/.*/\/&/' | xargs rm -f
;;
*)
echo unsupported architecture 1>&2
exit 1
;;
esac
echo FUSE for Cygwin uninstalled.
Binary file added winfsp/x64/usr/bin/cygfuse-2.8.dll
Binary file not shown.
261 changes: 261 additions & 0 deletions winfsp/x64/usr/include/fuse/fuse.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
/**
* @file fuse/fuse.h
* WinFsp FUSE compatible API.
*
* This file is derived from libfuse/include/fuse.h:
* FUSE: Filesystem in Userspace
* Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
*
* @copyright 2015-2019 Bill Zissimopoulos
*/
/*
* This file is part of WinFsp.
*
* You can redistribute it and/or modify it under the terms of the GNU
* General Public License version 3 as published by the Free Software
* Foundation.
*
* Licensees holding a valid commercial license may use this software
* in accordance with the commercial license agreement provided in
* conjunction with the software. The terms and conditions of any such
* commercial license agreement shall govern, supersede, and render
* ineffective any application of the GPLv3 license to this software,
* notwithstanding of any reference thereto in the software or
* associated repository.
*/

#ifndef FUSE_H_
#define FUSE_H_

#include "fuse_common.h"

#ifdef __cplusplus
extern "C" {
#endif

struct fuse;

typedef int (*fuse_fill_dir_t)(void *buf, const char *name,
const struct fuse_stat *stbuf, fuse_off_t off);
typedef struct fuse_dirhandle *fuse_dirh_t;
typedef int (*fuse_dirfil_t)(fuse_dirh_t h, const char *name,
int type, fuse_ino_t ino);

struct fuse_operations
{
/* S - supported by WinFsp */
/* S */ int (*getattr)(const char *path, struct fuse_stat *stbuf);
/* S */ int (*getdir)(const char *path, fuse_dirh_t h, fuse_dirfil_t filler);
/* S */ int (*readlink)(const char *path, char *buf, size_t size);
/* S */ int (*mknod)(const char *path, fuse_mode_t mode, fuse_dev_t dev);
/* S */ int (*mkdir)(const char *path, fuse_mode_t mode);
/* S */ int (*unlink)(const char *path);
/* S */ int (*rmdir)(const char *path);
/* S */ int (*symlink)(const char *dstpath, const char *srcpath);
/* S */ int (*rename)(const char *oldpath, const char *newpath);
/* _ */ int (*link)(const char *srcpath, const char *dstpath);
/* S */ int (*chmod)(const char *path, fuse_mode_t mode);
/* S */ int (*chown)(const char *path, fuse_uid_t uid, fuse_gid_t gid);
/* S */ int (*truncate)(const char *path, fuse_off_t size);
/* S */ int (*utime)(const char *path, struct fuse_utimbuf *timbuf);
/* S */ int (*open)(const char *path, struct fuse_file_info *fi);
/* S */ int (*read)(const char *path, char *buf, size_t size, fuse_off_t off,
struct fuse_file_info *fi);
/* S */ int (*write)(const char *path, const char *buf, size_t size, fuse_off_t off,
struct fuse_file_info *fi);
/* S */ int (*statfs)(const char *path, struct fuse_statvfs *stbuf);
/* S */ int (*flush)(const char *path, struct fuse_file_info *fi);
/* S */ int (*release)(const char *path, struct fuse_file_info *fi);
/* S */ int (*fsync)(const char *path, int datasync, struct fuse_file_info *fi);
/* S */ int (*setxattr)(const char *path, const char *name, const char *value, size_t size,
int flags);
/* S */ int (*getxattr)(const char *path, const char *name, char *value, size_t size);
/* S */ int (*listxattr)(const char *path, char *namebuf, size_t size);
/* S */ int (*removexattr)(const char *path, const char *name);
/* S */ int (*opendir)(const char *path, struct fuse_file_info *fi);
/* S */ int (*readdir)(const char *path, void *buf, fuse_fill_dir_t filler, fuse_off_t off,
struct fuse_file_info *fi);
/* S */ int (*releasedir)(const char *path, struct fuse_file_info *fi);
/* S */ int (*fsyncdir)(const char *path, int datasync, struct fuse_file_info *fi);
/* S */ void *(*init)(struct fuse_conn_info *conn);
/* S */ void (*destroy)(void *data);
/* _ */ int (*access)(const char *path, int mask);
/* S */ int (*create)(const char *path, fuse_mode_t mode, struct fuse_file_info *fi);
/* S */ int (*ftruncate)(const char *path, fuse_off_t off, struct fuse_file_info *fi);
/* S */ int (*fgetattr)(const char *path, struct fuse_stat *stbuf, struct fuse_file_info *fi);
/* _ */ int (*lock)(const char *path,
struct fuse_file_info *fi, int cmd, struct fuse_flock *lock);
/* S */ int (*utimens)(const char *path, const struct fuse_timespec tv[2]);
/* _ */ int (*bmap)(const char *path, size_t blocksize, uint64_t *idx);
/* _ */ unsigned int flag_nullpath_ok:1;
/* _ */ unsigned int flag_nopath:1;
/* _ */ unsigned int flag_utime_omit_ok:1;
/* _ */ unsigned int flag_reserved:29;
/* S */ int (*ioctl)(const char *path, int cmd, void *arg, struct fuse_file_info *fi,
unsigned int flags, void *data);
/* _ */ int (*poll)(const char *path, struct fuse_file_info *fi,
struct fuse_pollhandle *ph, unsigned *reventsp);
/* FUSE 2.9 */
/* _ */ int (*write_buf)(const char *path,
struct fuse_bufvec *buf, fuse_off_t off, struct fuse_file_info *fi);
/* _ */ int (*read_buf)(const char *path,
struct fuse_bufvec **bufp, size_t size, fuse_off_t off, struct fuse_file_info *fi);
/* _ */ int (*flock)(const char *path, struct fuse_file_info *, int op);
/* _ */ int (*fallocate)(const char *path, int mode, fuse_off_t off, fuse_off_t len,
struct fuse_file_info *fi);
/* OSXFUSE */
/* _ */ int (*reserved00)();
/* _ */ int (*reserved01)();
/* _ */ int (*reserved02)();
/* _ */ int (*statfs_x)(const char *path, struct fuse_statfs *stbuf);
/* _ */ int (*setvolname)(const char *volname);
/* _ */ int (*exchange)(const char *oldpath, const char *newpath, unsigned long flags);
/* _ */ int (*getxtimes)(const char *path,
struct fuse_timespec *bkuptime, struct fuse_timespec *crtime);
/* _ */ int (*setbkuptime)(const char *path, const struct fuse_timespec *tv);
/* S */ int (*setchgtime)(const char *path, const struct fuse_timespec *tv);
/* S */ int (*setcrtime)(const char *path, const struct fuse_timespec *tv);
/* S */ int (*chflags)(const char *path, uint32_t flags);
/* _ */ int (*setattr_x)(const char *path, struct fuse_setattr_x *attr);
/* _ */ int (*fsetattr_x)(const char *path, struct fuse_setattr_x *attr,
struct fuse_file_info *fi);
};

struct fuse_context
{
struct fuse *fuse;
fuse_uid_t uid;
fuse_gid_t gid;
fuse_pid_t pid;
void *private_data;
fuse_mode_t umask;
};

#define fuse_main(argc, argv, ops, data)\
fuse_main_real(argc, argv, ops, sizeof *(ops), data)

FSP_FUSE_API int FSP_FUSE_API_NAME(fsp_fuse_main_real)(struct fsp_fuse_env *env,
int argc, char *argv[],
const struct fuse_operations *ops, size_t opsize, void *data);
FSP_FUSE_API int FSP_FUSE_API_NAME(fsp_fuse_is_lib_option)(struct fsp_fuse_env *env,
const char *opt);
FSP_FUSE_API struct fuse *FSP_FUSE_API_NAME(fsp_fuse_new)(struct fsp_fuse_env *env,
struct fuse_chan *ch, struct fuse_args *args,
const struct fuse_operations *ops, size_t opsize, void *data);
FSP_FUSE_API void FSP_FUSE_API_NAME(fsp_fuse_destroy)(struct fsp_fuse_env *env,
struct fuse *f);
FSP_FUSE_API int FSP_FUSE_API_NAME(fsp_fuse_loop)(struct fsp_fuse_env *env,
struct fuse *f);
FSP_FUSE_API int FSP_FUSE_API_NAME(fsp_fuse_loop_mt)(struct fsp_fuse_env *env,
struct fuse *f);
FSP_FUSE_API void FSP_FUSE_API_NAME(fsp_fuse_exit)(struct fsp_fuse_env *env,
struct fuse *f);
FSP_FUSE_API int FSP_FUSE_API_NAME(fsp_fuse_exited)(struct fsp_fuse_env *env,
struct fuse *f);
FSP_FUSE_API struct fuse_context *FSP_FUSE_API_NAME(fsp_fuse_get_context)(struct fsp_fuse_env *env);

FSP_FUSE_SYM(
int fuse_main_real(int argc, char *argv[],
const struct fuse_operations *ops, size_t opsize, void *data),
{
return FSP_FUSE_API_CALL(fsp_fuse_main_real)
(fsp_fuse_env(), argc, argv, ops, opsize, data);
})

FSP_FUSE_SYM(
int fuse_is_lib_option(const char *opt),
{
return FSP_FUSE_API_CALL(fsp_fuse_is_lib_option)
(fsp_fuse_env(), opt);
})

FSP_FUSE_SYM(
struct fuse *fuse_new(struct fuse_chan *ch, struct fuse_args *args,
const struct fuse_operations *ops, size_t opsize, void *data),
{
return FSP_FUSE_API_CALL(fsp_fuse_new)
(fsp_fuse_env(), ch, args, ops, opsize, data);
})

FSP_FUSE_SYM(
void fuse_destroy(struct fuse *f),
{
FSP_FUSE_API_CALL(fsp_fuse_destroy)
(fsp_fuse_env(), f);
})

FSP_FUSE_SYM(
int fuse_loop(struct fuse *f),
{
return FSP_FUSE_API_CALL(fsp_fuse_loop)
(fsp_fuse_env(), f);
})

FSP_FUSE_SYM(
int fuse_loop_mt(struct fuse *f),
{
return FSP_FUSE_API_CALL(fsp_fuse_loop_mt)
(fsp_fuse_env(), f);
})

FSP_FUSE_SYM(
void fuse_exit(struct fuse *f),
{
FSP_FUSE_API_CALL(fsp_fuse_exit)
(fsp_fuse_env(), f);
})

FSP_FUSE_SYM(
int fuse_exited(struct fuse *f),
{
return FSP_FUSE_API_CALL(fsp_fuse_exited)
(fsp_fuse_env(), f);
})

FSP_FUSE_SYM(
struct fuse_context *fuse_get_context(void),
{
return FSP_FUSE_API_CALL(fsp_fuse_get_context)
(fsp_fuse_env());
})

FSP_FUSE_SYM(
int fuse_getgroups(int size, fuse_gid_t list[]),
{
(void)size;
(void)list;
return -ENOSYS;
})

FSP_FUSE_SYM(
int fuse_interrupted(void),
{
return 0;
})

FSP_FUSE_SYM(
int fuse_invalidate(struct fuse *f, const char *path),
{
(void)f;
(void)path;
return -EINVAL;
})

FSP_FUSE_SYM(
int fuse_notify_poll(struct fuse_pollhandle *ph),
{
(void)ph;
return 0;
})

FSP_FUSE_SYM(
struct fuse_session *fuse_get_session(struct fuse *f),
{
return (struct fuse_session *)f;
})

#ifdef __cplusplus
}
#endif

#endif
Loading

0 comments on commit b3b28c2

Please sign in to comment.