fix: linux build

This commit is contained in:
d0p1 🏳️‍⚧️ 2024-08-24 07:30:18 +02:00
parent b11c2454d3
commit 5861542ef8
5 changed files with 37 additions and 47 deletions

1
.gitignore vendored
View file

@ -46,3 +46,4 @@ config.sub
hdd hdd
config.h config.h
*.guess *.guess
inspect.stpd

View file

@ -1,5 +1,5 @@
AM_CFLAGS = $(FUSE_CFLAGS) -I$(top_srcdir)/lib -I$(top_srcdir)/include -I$(top_srcdir) AM_CFLAGS = $(FUSE_CFLAGS) -I$(top_srcdir)/lib -I$(top_srcdir)/include -I$(top_srcdir)
LDADD = $(FUSE_LIBS) ../lib/libstpdfs.a LDADD = $(FUSE_LIBS) ../libfs/libfs.a
bin_PROGRAMS = stpdfs-fuse bin_PROGRAMS = stpdfs-fuse

View file

@ -1,4 +1,3 @@
#include "stpdfs.h"
#include <fcntl.h> #include <fcntl.h>
#include <stdlib.h> #include <stdlib.h>
#include <stddef.h> #include <stddef.h>
@ -6,6 +5,7 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include <libfs/fs.h>
#define FUSE_USE_VERSION 31 #define FUSE_USE_VERSION 31
#include <fuse.h> #include <fuse.h>
@ -38,6 +38,8 @@ static struct options {
int show_version; int show_version;
} options; } options;
static struct fs_super super;
#define OPTION(t, p) { t, offsetof(struct options, p), 1 } #define OPTION(t, p) { t, offsetof(struct options, p), 1 }
static const struct fuse_opt option_spec[] = { static const struct fuse_opt option_spec[] = {
@ -54,62 +56,43 @@ static void *
fuse_stpdfs_init(struct fuse_conn_info *conn, fuse_stpdfs_init(struct fuse_conn_info *conn,
struct fuse_config *config) struct fuse_config *config)
{ {
struct stpdfs_sb sb; if (fs_super_open(&super, options.filename) != 0)
(void)conn;
(void)config;
fd = open(options.filename, O_RDWR);
if (fd < 0)
{ {
perror(options.filename);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
stpdfs_read(fd, 1, &sb, sizeof(struct stpdfs_sb));
return (NULL); return (NULL);
} }
static void static void
fuse_stpdfs_destroy(void *data) fuse_stpdfs_destroy(void *data)
{ {
struct stpdfs_sb sb; fs_super_kill(&super);
stpdfs_read(fd, 1, &sb, sizeof(struct stpdfs_sb)),
sb.state = STPDFS_CLEANLY_UNMOUNTED;
sb.time = time(NULL);
stpdfs_write(fd, 1, &sb, sizeof(struct stpdfs_sb));
close(fd);
} }
static int static int
fuse_stpdfs_getattr(const char *path, struct stat *stbuf, fuse_stpdfs_getattr(const char *path, struct stat *stbuf,
struct fuse_file_info *fi) struct fuse_file_info *fi)
{ {
struct stpdfs_inode inodes[STPDFS_INODES_PER_BLOCK]; struct fs_inode *ip;
struct stpdfs_inode inode;
size_t idx;
uint32_t ino;
char *p = strtok(path, "/"); ip = fs_inode_get(&super, STPDFS_ROOTINO);
stpdfs_read(fd, 2, &inodes, sizeof(struct stpdfs_inode) * STPDFS_INODES_PER_BLOCK); if (ip == NULL)
inode = inodes[1];
if (p != NULL)
{ {
// todo return (-1);
} }
stbuf->st_atim.tv_sec = inode.actime; if (ip->valid == 0)
stbuf->st_mtim.tv_sec = inode.modtime; {
stbuf->st_size = inode.size; fs_inode_read(ip);
stbuf->st_mode = inode.mode; }
stbuf->st_gid = inode.gid;
stbuf->st_uid = inode.uid; stbuf->st_atim.tv_sec = ip->inode.actime;
stbuf->st_nlink = inode.nlink; stbuf->st_mtim.tv_sec = ip->inode.modtime;
stbuf->st_size = ip->inode.size;
stbuf->st_mode = ip->inode.mode;
stbuf->st_gid = ip->inode.gid;
stbuf->st_uid = ip->inode.uid;
stbuf->st_nlink = ip->inode.nlink;
return (0); return (0);
} }

View file

@ -40,8 +40,11 @@ int
fs_super_open(struct fs_super *super, const char *fname) fs_super_open(struct fs_super *super, const char *fname)
{ {
struct fs_buffer *buff; struct fs_buffer *buff;
#ifdef _WIN32
super->fd = open(fname, O_RDWR | O_BINARY); super->fd = open(fname, O_RDWR | O_BINARY);
#else
super->fd = open(fname, O_RDWR);
#endif
if (super->fd < 0) if (super->fd < 0)
{ {
perror(fname); perror(fname);

View file

@ -80,8 +80,11 @@ create_create_super(struct fs_super *super)
perror(device); perror(device);
return (-1); return (-1);
} }
#ifdef _WIN32
super->fd = open(device, O_RDWR | O_BINARY); super->fd = open(device, O_RDWR | O_BINARY);
#else
super->fd = open(device, O_RDWR);
#endif
if (super->fd < 0) if (super->fd < 0)
{ {
perror(device); perror(device);