dll: fuse: ensure compatibility between winfsp and cygwin stat, etc. definitions

This commit is contained in:
Bill Zissimopoulos 2016-06-02 14:07:29 -07:00
parent 6910b67982
commit 190e2320c0
4 changed files with 59 additions and 156 deletions

View File

@ -54,7 +54,7 @@ struct fuse_operations
int (*chmod)(const char *path, fuse_mode_t mode);
int (*chown)(const char *path, fuse_uid_t uid, fuse_gid_t gid);
int (*truncate)(const char *path, fuse_off_t size);
int (*utime)(const char *path, struct utimbuf *timbuf);
int (*utime)(const char *path, struct fuse_utimbuf *timbuf);
int (*open)(const char *path, struct fuse_file_info *fi);
int (*read)(const char *path, char *buf, size_t size, fuse_off_t off,
struct fuse_file_info *fi);
@ -81,7 +81,7 @@ struct fuse_operations
int (*ftruncate)(const char *path, fuse_off_t off, struct fuse_file_info *fi);
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 flock *lock);
int (*utimens)(const char *path, const struct timespec tv[2]);
int (*utimens)(const char *path, const struct fuse_timespec tv[2]);
int (*bmap)(const char *path, size_t blocksize, uint64_t *idx);
int (*ioctl)(const char *path, int cmd, void *arg, struct fuse_file_info *fi,
unsigned int flags, void *data);

View File

@ -41,9 +41,9 @@ extern "C" {
* are not even native.
*
* For this reason we will define our own fuse_* types which represent the
* types as the WinFsp DLL expects to see them. When the file is included
* by FUSE clients in different environments we will translate between their
* understanding of the types and ours.
* types as the WinFsp DLL expects to see them. We will define these types
* to be compatible with the equivalent Cygwin types as we want WinFsp-FUSE
* to be usable from Cygwin.
*/
#if defined(_WIN64) || defined(_WIN32)
@ -52,22 +52,45 @@ typedef uint32_t fuse_uid_t;
typedef uint32_t fuse_gid_t;
typedef int32_t fuse_pid_t;
typedef uint64_t fuse_dev_t;
typedef uint32_t fuse_dev_t;
typedef uint64_t fuse_ino_t;
typedef uint32_t fuse_mode_t;
typedef uint32_t fuse_nlink_t;
typedef uint16_t fuse_nlink_t;
typedef int64_t fuse_off_t;
#if defined(_WIN64)
typedef uint64_t fuse_fsblkcnt_t;
typedef uint64_t fuse_fsfilcnt_t;
typedef int64_t fuse_blksize_t;
#else
typedef uint32_t fuse_fsblkcnt_t;
typedef uint32_t fuse_fsfilcnt_t;
#endif
typedef int32_t fuse_blksize_t;
typedef int64_t fuse_blkcnt_t;
#if defined(_WIN64)
struct fuse_utimbuf
{
int64_t actime;
int64_t modtime;
};
struct fuse_timespec
{
time_t tv_sec;
int tv_nsec;
int64_t tv_sec;
int64_t tv_nsec;
};
#else
struct fuse_utimbuf
{
int32_t actime;
int32_t modtime;
};
struct fuse_timespec
{
int32_t tv_sec;
int32_t tv_nsec;
};
#endif
struct fuse_stat
{
@ -87,6 +110,7 @@ struct fuse_stat
struct fuse_timespec st_birthtim;
};
#if defined(_WIN64)
struct fuse_statvfs
{
uint64_t f_bsize;
@ -101,6 +125,22 @@ struct fuse_statvfs
uint64_t f_flag;
uint64_t f_namemax;
};
#else
struct fuse_statvfs
{
uint32_t f_bsize;
uint32_t f_frsize;
fuse_fsblkcnt_t f_blocks;
fuse_fsblkcnt_t f_bfree;
fuse_fsblkcnt_t f_bavail;
fuse_fsfilcnt_t f_files;
fuse_fsfilcnt_t f_ffree;
fuse_fsfilcnt_t f_favail;
uint32_t f_fsid;
uint32_t f_flag;
uint32_t f_namemax;
};
#endif
#if defined(WINFSP_DLL_INTERNAL)
#define FSP_FUSE_ENV_INIT \
@ -145,6 +185,7 @@ struct fuse_statvfs
#define fuse_blksize_t blksize_t
#define fuse_blkcnt_t blkcnt_t
#define fuse_utimbuf utimbuf
#define fuse_timespec timespec
#define fuse_stat stat

View File

@ -244,42 +244,31 @@ static NTSTATUS fsp_fuse_svcstart(FSP_SERVICE *Service, ULONG argc, PWSTR *argv)
f->fsinit = TRUE;
if (0 != f->ops.statfs)
{
union
{
struct cyg_statvfs cygbuf;
struct fuse_statvfs fspbuf;
} buf;
struct fuse_statvfs fspbuf;
struct fuse_statvfs stbuf;
int err;
err = f->ops.statfs("/", (void *)&buf);
err = f->ops.statfs("/", &stbuf);
if (0 != err)
goto fail;
fsp_fuse_get_statvfs_buf(f->env, &buf, &fspbuf);
if (0 == f->VolumeParams.SectorSize)
f->VolumeParams.SectorSize = (UINT16)fspbuf.f_bsize;
f->VolumeParams.SectorSize = (UINT16)stbuf.f_bsize;
if (0 == f->VolumeParams.MaxComponentLength)
f->VolumeParams.MaxComponentLength = (UINT16)fspbuf.f_namemax;
f->VolumeParams.MaxComponentLength = (UINT16)stbuf.f_namemax;
}
if (0 != f->ops.getattr)
{
union
{
struct cyg_stat cygbuf;
struct fuse_stat fspbuf;
} buf;
struct fuse_stat fspbuf;
struct fuse_stat stbuf;
int err;
err = f->ops.getattr("/", (void *)&buf);
err = f->ops.getattr("/", (void *)&stbuf);
if (0 != err)
goto fail;
fsp_fuse_get_stat_buf(f->env, &buf, &fspbuf);
if (0 == f->VolumeParams.VolumeCreationTime)
f->VolumeParams.VolumeCreationTime =
Int32x32To64(fspbuf.st_birthtim.tv_sec, 10000000) + 116444736000000000;
Int32x32To64(stbuf.st_birthtim.tv_sec, 10000000) + 116444736000000000 +
stbuf.st_birthtim.tv_nsec / 100;
}
/* the FSD does not currently limit these VolumeParams fields; do so here! */

View File

@ -24,133 +24,6 @@
#define FSP_FUSE_LIBRARY_NAME LIBRARY_NAME "-FUSE"
#if defined(_WIN64)
struct cyg_timespec
{
int64_t tv_sec;
int64_t tv_nsec;
};
#else
struct cyg_timespec
{
int32_t tv_sec;
int32_t tv_nsec;
};
#endif
struct cyg_stat
{
uint32_t st_dev;
uint64_t st_ino;
uint32_t st_mode;
uint16_t st_nlink;
uint32_t st_uid;
uint32_t st_gid;
uint32_t st_rdev;
int64_t st_size;
struct cyg_timespec st_atim;
struct cyg_timespec st_mtim;
struct cyg_timespec st_ctim;
int32_t st_blksize;
int64_t st_blocks;
struct cyg_timespec st_birthtim;
};
#if defined(_WIN64)
struct cyg_statvfs
{
uint64_t f_bsize;
uint64_t f_frsize;
uint64_t f_blocks;
uint64_t f_bfree;
uint64_t f_bavail;
uint64_t f_files;
uint64_t f_ffree;
uint64_t f_favail;
uint64_t f_fsid;
uint64_t f_flag;
uint64_t f_namemax;
};
#else
struct cyg_statvfs
{
uint32_t f_bsize;
uint32_t f_frsize;
uint32_t f_blocks;
uint32_t f_bfree;
uint32_t f_bavail;
uint32_t f_files;
uint32_t f_ffree;
uint32_t f_favail;
uint32_t f_fsid;
uint32_t f_flag;
uint32_t f_namemax;
};
#endif
static inline void fsp_fuse_get_stat_buf(
struct fsp_fuse_env *env,
const void *buf, struct fuse_stat *fspbuf)
{
switch (env->environment)
{
case 'C':
{
const struct cyg_stat *cygbuf = buf;
fspbuf->st_dev = cygbuf->st_dev;
fspbuf->st_ino = cygbuf->st_ino;
fspbuf->st_mode = cygbuf->st_mode;
fspbuf->st_nlink = cygbuf->st_nlink;
fspbuf->st_uid = cygbuf->st_uid;
fspbuf->st_gid = cygbuf->st_gid;
fspbuf->st_rdev = cygbuf->st_rdev;
fspbuf->st_size = cygbuf->st_size;
fspbuf->st_atim.tv_sec = cygbuf->st_atim.tv_sec;
fspbuf->st_atim.tv_nsec = (int)cygbuf->st_atim.tv_nsec;
fspbuf->st_mtim.tv_sec = cygbuf->st_mtim.tv_sec;
fspbuf->st_mtim.tv_nsec = (int)cygbuf->st_mtim.tv_nsec;
fspbuf->st_ctim.tv_sec = cygbuf->st_ctim.tv_sec;
fspbuf->st_ctim.tv_nsec = (int)cygbuf->st_ctim.tv_nsec;
fspbuf->st_blksize = cygbuf->st_blksize;
fspbuf->st_blocks = cygbuf->st_blocks;
fspbuf->st_birthtim.tv_sec = cygbuf->st_birthtim.tv_sec;
fspbuf->st_birthtim.tv_nsec = (int)cygbuf->st_birthtim.tv_nsec;
}
break;
default:
memcpy(fspbuf, buf, sizeof *fspbuf);
break;
}
}
static inline void fsp_fuse_get_statvfs_buf(
struct fsp_fuse_env *env,
const void *buf, struct fuse_statvfs *fspbuf)
{
switch (env->environment)
{
case 'C':
{
const struct cyg_statvfs *cygbuf = buf;
fspbuf->f_bsize = cygbuf->f_bsize;
fspbuf->f_frsize = cygbuf->f_frsize;
fspbuf->f_blocks = cygbuf->f_blocks;
fspbuf->f_bfree = cygbuf->f_bfree;
fspbuf->f_bavail = cygbuf->f_bavail;
fspbuf->f_files = cygbuf->f_files;
fspbuf->f_ffree = cygbuf->f_ffree;
fspbuf->f_favail = cygbuf->f_favail;
fspbuf->f_fsid = cygbuf->f_fsid;
fspbuf->f_flag = cygbuf->f_flag;
fspbuf->f_namemax = cygbuf->f_namemax;
}
break;
default:
memcpy(fspbuf, buf, sizeof *fspbuf);
break;
}
}
struct fuse
{
struct fsp_fuse_env *env;