Compare commits
2 commits
b11c2454d3
...
8ad9864c38
Author | SHA1 | Date | |
---|---|---|---|
d0p1 🏳️⚧️ | 8ad9864c38 | ||
d0p1 🏳️⚧️ | 5861542ef8 |
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -46,3 +46,4 @@ config.sub
|
|||
hdd
|
||||
config.h
|
||||
*.guess
|
||||
inspect.stpd
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
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
|
||||
|
||||
|
|
67
fuse/main.c
67
fuse/main.c
|
@ -1,4 +1,3 @@
|
|||
#include "stpdfs.h"
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
|
@ -6,6 +5,7 @@
|
|||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <libfs/fs.h>
|
||||
|
||||
#define FUSE_USE_VERSION 31
|
||||
#include <fuse.h>
|
||||
|
@ -38,6 +38,8 @@ static struct options {
|
|||
int show_version;
|
||||
} options;
|
||||
|
||||
static struct fs_super super;
|
||||
|
||||
#define OPTION(t, p) { t, offsetof(struct options, p), 1 }
|
||||
|
||||
static const struct fuse_opt option_spec[] = {
|
||||
|
@ -54,62 +56,43 @@ static void *
|
|||
fuse_stpdfs_init(struct fuse_conn_info *conn,
|
||||
struct fuse_config *config)
|
||||
{
|
||||
struct stpdfs_sb sb;
|
||||
|
||||
(void)conn;
|
||||
(void)config;
|
||||
|
||||
fd = open(options.filename, O_RDWR);
|
||||
if (fd < 0)
|
||||
{
|
||||
perror(options.filename);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
stpdfs_read(fd, 1, &sb, sizeof(struct stpdfs_sb));
|
||||
|
||||
if (fs_super_open(&super, options.filename) != 0)
|
||||
{
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
fuse_stpdfs_destroy(void *data)
|
||||
{
|
||||
struct stpdfs_sb sb;
|
||||
|
||||
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);
|
||||
fs_super_kill(&super);
|
||||
}
|
||||
|
||||
static int
|
||||
fuse_stpdfs_getattr(const char *path, struct stat *stbuf,
|
||||
struct fuse_file_info *fi)
|
||||
{
|
||||
struct stpdfs_inode inodes[STPDFS_INODES_PER_BLOCK];
|
||||
struct stpdfs_inode inode;
|
||||
size_t idx;
|
||||
uint32_t ino;
|
||||
struct fs_inode *ip;
|
||||
|
||||
char *p = strtok(path, "/");
|
||||
stpdfs_read(fd, 2, &inodes, sizeof(struct stpdfs_inode) * STPDFS_INODES_PER_BLOCK);
|
||||
inode = inodes[1];
|
||||
ip = fs_inode_get(&super, STPDFS_ROOTINO);
|
||||
if (ip == NULL)
|
||||
{
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (p != NULL)
|
||||
{
|
||||
// todo
|
||||
}
|
||||
if (ip->valid == 0)
|
||||
{
|
||||
fs_inode_read(ip);
|
||||
}
|
||||
|
||||
stbuf->st_atim.tv_sec = inode.actime;
|
||||
stbuf->st_mtim.tv_sec = inode.modtime;
|
||||
stbuf->st_size = inode.size;
|
||||
stbuf->st_mode = inode.mode;
|
||||
stbuf->st_gid = inode.gid;
|
||||
stbuf->st_uid = inode.uid;
|
||||
stbuf->st_nlink = inode.nlink;
|
||||
stbuf->st_atim.tv_sec = ip->inode.actime;
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
68
libfs/dir.c
68
libfs/dir.c
|
@ -65,7 +65,73 @@ fs_dir_link(struct fs_inode *dp, const char *name, uint32_t inum)
|
|||
{
|
||||
return (-1);
|
||||
}
|
||||
fs_inode_update(dp);
|
||||
|
||||
ip = fs_inode_get(dp->super, inum);
|
||||
if (ip->valid == 0)
|
||||
{
|
||||
fs_inode_read(ip);
|
||||
}
|
||||
ip->inode.nlink += 1;
|
||||
|
||||
fs_inode_update(ip);
|
||||
fs_inode_release(ip);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
fs_dir_unlink(struct fs_inode *dp, const char *name)
|
||||
{
|
||||
int offset;
|
||||
struct fs_inode *ip;
|
||||
struct stpdfs_dirent dirent;
|
||||
|
||||
ip = fs_dir_lookup(dp, name, 0);
|
||||
if (ip == NULL)
|
||||
{
|
||||
return (-1);
|
||||
}
|
||||
|
||||
ip->inode.nlink -= 1;
|
||||
|
||||
fs_inode_update(ip);
|
||||
fs_inode_release(ip);
|
||||
|
||||
for (offset = 0; offset < dp->inode.size; offset += STPDFS_DIRENT_SIZE)
|
||||
{
|
||||
fs_read(dp, (uint8_t *)&dirent, offset, STPDFS_DIRENT_SIZE);
|
||||
if (strncmp(dirent.filename, name, STPDFS_NAME_MAX) == 0)
|
||||
{
|
||||
memset(dirent.filename, 0, STPDFS_NAME_MAX);
|
||||
dirent.inode = 0;
|
||||
fs_write(dp, (uint8_t *)&dirent, offset, STPDFS_DIRENT_SIZE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
fs_mkdir(struct fs_inode *dp, const char *name)
|
||||
{
|
||||
struct fs_inode *ndp;
|
||||
|
||||
if (!(dp->inode.mode & STPDFS_S_IFDIR))
|
||||
{
|
||||
return (-1);
|
||||
}
|
||||
|
||||
ndp = fs_inode_alloc(dp->super);
|
||||
if (ndp == NULL)
|
||||
{
|
||||
return (-1);
|
||||
}
|
||||
|
||||
ndp->inode.mode |= STPDFS_S_IFDIR;
|
||||
|
||||
fs_dir_link(ndp, ".", ndp->inum);
|
||||
fs_dir_link(ndp, "..", dp->inum);
|
||||
|
||||
fs_dir_link(dp, name, ndp->inum);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
|
|
@ -5,12 +5,13 @@
|
|||
# include "inode.h"
|
||||
|
||||
struct fs_dir {
|
||||
char name[STPDFS_NAME_MAX];
|
||||
uint32_t inum;
|
||||
|
||||
|
||||
struct fs_inode *dp;
|
||||
int offset;
|
||||
};
|
||||
|
||||
struct fs_inode *fs_dir_lookup(struct fs_inode *dp, const char *name, size_t *offset);
|
||||
int fs_dir_link(struct fs_inode *dp, const char *name, uint32_t inum);
|
||||
int fs_dir_unlink(struct fs_inode *dp, const char *name);
|
||||
int fs_mkdir(struct fs_inode *dp, const char *name);
|
||||
|
||||
#endif /* !FS_DIR_H */
|
|
@ -71,7 +71,7 @@ fs_inode_read(struct fs_inode *ip)
|
|||
buff = fs_bio_bread(ip->super->fd, IBLOCK(ip->inum));
|
||||
if (buff == NULL) return (NULL);
|
||||
|
||||
dinode = (struct stpdfs_inode *)buff->data + ip->inum % STPDFS_INODES_PER_BLOCK;;
|
||||
dinode = (struct stpdfs_inode *)buff->data + ip->inum % STPDFS_INODES_PER_BLOCK;
|
||||
memcpy(&ip->inode, dinode, sizeof(struct stpdfs_inode));
|
||||
|
||||
fs_bio_brelse(buff);
|
||||
|
|
|
@ -40,8 +40,11 @@ int
|
|||
fs_super_open(struct fs_super *super, const char *fname)
|
||||
{
|
||||
struct fs_buffer *buff;
|
||||
|
||||
#ifdef _WIN32
|
||||
super->fd = open(fname, O_RDWR | O_BINARY);
|
||||
#else
|
||||
super->fd = open(fname, O_RDWR);
|
||||
#endif
|
||||
if (super->fd < 0)
|
||||
{
|
||||
perror(fname);
|
||||
|
|
|
@ -34,7 +34,6 @@ static struct option long_options[] = {
|
|||
};
|
||||
#endif /* HAVE_STRUCT_OPTION */
|
||||
|
||||
|
||||
static int
|
||||
inspect(void)
|
||||
{
|
||||
|
|
|
@ -11,11 +11,11 @@
|
|||
LF equ 0xA
|
||||
|
||||
struc inode
|
||||
.mode: resb 1
|
||||
.nlink: resb 1
|
||||
.uid: resb 1
|
||||
.gid: resb 1
|
||||
.flags: resb 1
|
||||
.mode: resw 1
|
||||
.nlink: resw 1
|
||||
.uid: resw 1
|
||||
.gid: resw 1
|
||||
.flags: resw 1
|
||||
.size: resd 1
|
||||
.zones: resd 10
|
||||
.actime: resq 1
|
||||
|
@ -75,7 +75,7 @@ start:
|
|||
jc .reset_disk
|
||||
|
||||
; read superblock
|
||||
mov ax, DISK_BUFFER/10
|
||||
mov ax, DISK_BUFFER
|
||||
mov es, ax
|
||||
|
||||
; load two sector in memory
|
||||
|
@ -92,29 +92,46 @@ start:
|
|||
; inode 0 bad
|
||||
; inode 1 root dir
|
||||
; inode 2 is loader, let's keep things easy
|
||||
mov ax, word [DISK_BUFFER + 34 * 2 + inode.flags]
|
||||
mov ax, word [DISK_BUFFER + 512 + 0x46 * 2 + inode.flags]
|
||||
and ax, INODE_ALLOCATED
|
||||
jz .err_no_loader
|
||||
|
||||
mov dword eax, [DISK_BUFFER + 34 * 2 + inode.size] ; size
|
||||
mov dword eax, [DISK_BUFFER + 512 + 0x46 * 2 + inode.size] ; size
|
||||
mov dword [uFsize], eax
|
||||
|
||||
xor ecx, ecx
|
||||
.read_loop:
|
||||
xchg bx, bx
|
||||
|
||||
xor ecx, ecx
|
||||
xor edx, edx
|
||||
mov eax, DISK_BUFFER + 0x46 * 2 + inode.zone ; first zone
|
||||
.read_loop:
|
||||
cmp dword ecx, [uFsize]
|
||||
jg .all_read
|
||||
|
||||
|
||||
.zone_loop:
|
||||
cmp edx, 7
|
||||
jb .zone_direct
|
||||
|
||||
.zone_triple:
|
||||
|
||||
.zone_double:
|
||||
|
||||
.zone_indirect:
|
||||
|
||||
.zone_direct:
|
||||
mov eax, edx
|
||||
shr eax, 2
|
||||
add eax, DISK_BUFFER + 0x46 + 2 + inode.zone
|
||||
|
||||
|
||||
inc edx
|
||||
.end_zone:
|
||||
add ecx, BLOCK_SIZE
|
||||
jmp .read_loop
|
||||
.all_read:
|
||||
|
||||
mov eax, DISK_BUFFER + 34 * 2 + 14 ; first zone
|
||||
|
||||
mov ax, LOADER_BASE/10
|
||||
mov es, ax
|
||||
|
||||
jmp 0x0:LOADER_BASE
|
||||
|
||||
.err_no_loader:
|
||||
mov si, szErrorNoLoader
|
||||
call bios_print
|
||||
|
@ -150,10 +167,11 @@ disk_read_sectors:
|
|||
mov word [disk_packet.segment], es
|
||||
mov word [disk_packet.offset], bx
|
||||
mov dword [disk_packet.lba], eax
|
||||
mov si, [disk_packet]
|
||||
mov si, disk_packet
|
||||
mov dl, [bpb.drive_num]
|
||||
mov ah, 0x42
|
||||
int 0x13
|
||||
jc start.err_lba
|
||||
ret
|
||||
|
||||
disk_packet:
|
||||
|
|
|
@ -80,8 +80,11 @@ create_create_super(struct fs_super *super)
|
|||
perror(device);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
super->fd = open(device, O_RDWR | O_BINARY);
|
||||
#else
|
||||
super->fd = open(device, O_RDWR);
|
||||
#endif
|
||||
if (super->fd < 0)
|
||||
{
|
||||
perror(device);
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
#include "libfs/dir.h"
|
||||
#include "libfs/fs.h"
|
||||
#include "libfs/inode.h"
|
||||
#include "libfs/super.h"
|
||||
#include "stupidfs.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
|
@ -16,6 +11,8 @@
|
|||
#ifdef HAVE_GETOPT_H
|
||||
# include <getopt.h>
|
||||
#endif /* HAVE_GETOPT_H */
|
||||
# include <stupidfs.h>
|
||||
# include "libfs/fs.h"
|
||||
|
||||
#ifdef HAVE_STRUCT_OPTION
|
||||
static struct option long_options[] = {
|
||||
|
@ -75,6 +72,7 @@ do_copy(void)
|
|||
ip->inode.gid = st.st_gid;
|
||||
ip->inode.modtime = st.st_mtime;
|
||||
ip->inode.actime = st.st_atime;
|
||||
ip->inode.flags = STPDFS_INO_FLAG_ALOC;
|
||||
|
||||
fs_inode_update(ip);
|
||||
|
||||
|
@ -151,7 +149,11 @@ copy(int argc, char **argv)
|
|||
|
||||
if (dest == NULL)
|
||||
{
|
||||
dest = src;
|
||||
#ifdef HAVE_LIBGEN_H
|
||||
dest = basename(src);
|
||||
#else
|
||||
dest = src;
|
||||
#endif
|
||||
}
|
||||
|
||||
return (do_copy());
|
||||
|
|
Loading…
Reference in a new issue