refactor: reorganize source (wip)
This commit is contained in:
parent
ae2abce732
commit
b06aba1da8
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -38,4 +38,5 @@ test_base64
|
|||
*.trs
|
||||
stpdfs-fuse
|
||||
test_hchacha
|
||||
test_xchacha
|
||||
test_xchacha
|
||||
tools.stpd
|
|
@ -1,4 +1,4 @@
|
|||
AM_CFLAGS = $(FUSE_CFLAGS) -I$(top_srcdir)/lib -I$(top_srcdir)
|
||||
AM_CFLAGS = $(FUSE_CFLAGS) -I$(top_srcdir)/lib -I$(top_srcdir)/include -I$(top_srcdir)
|
||||
LDADD = $(FUSE_LIBS) ../lib/libstpdfs.a
|
||||
|
||||
bin_PROGRAMS = stpdfs-fuse
|
||||
|
|
|
@ -1,66 +1,35 @@
|
|||
/**
|
||||
* \file stupidfs.h
|
||||
*
|
||||
* StupidFS
|
||||
* StupidFS Filesystem
|
||||
*
|
||||
* ```
|
||||
* ┌──────────┬───────────┬──────┬───┬──────┬────┬───┬────┐
|
||||
* │Boot block│Super block│Inodes│...│Inodes│Data│...│Data│
|
||||
* └──────────┴───────────┴──────┴───┴──────┴────┴───┴────┘
|
||||
* ```
|
||||
*/
|
||||
#ifndef STPDFS_H
|
||||
# define STPDFS_H 1
|
||||
#ifndef STUPIDFS_H
|
||||
# define STUPIDFS_H 1
|
||||
|
||||
# ifndef __KERNEL__
|
||||
# include <stdint.h>
|
||||
# include <stddef.h>
|
||||
# endif
|
||||
|
||||
# define STPDFS_SB_MAGIC 0x44505453
|
||||
# define STPDFS_SB_REV STPDFS_SB_REV_1
|
||||
# define STPDFS_SB_REV_1 1
|
||||
|
||||
# define STPDFS_INO_ROOTDIR 1
|
||||
|
||||
# define STPDFS_BLOCK_SIZE 512
|
||||
|
||||
# define STPDFS_NAME_MAX 28
|
||||
|
||||
# define STPDFS_BLOCK_SIZE 512 /**< StupidFS block size */
|
||||
# define STPDFS_INODES_PER_BLOCK (STPDFS_BLOCK_SIZE / (sizeof(struct stpdfs_inode)))
|
||||
# define STPDFS_ZONES_PER_BLOCK (STPDFS_BLOCK_SIZE / sizeof(uint32_t))
|
||||
# define STPDFS_DIRENT_PER_BLOCK (STPDFS_BLOCK_SIZE / (sizeof(struct stpdfs_dirent)))
|
||||
# define STPDFS_NDIR 7
|
||||
# define STPDFS_ROOT_INO 1
|
||||
|
||||
# define STPDFS_INO_FLAG_ALOC (1 << 15)
|
||||
# define STPDFS_INO_FLAG_LZP (1 << 1)
|
||||
# define STPDFS_INO_FLAG_ENC (1 << 2)
|
||||
# define STPDFS_SB_MAGIC 0x44505453 /**< Superblock magic number */
|
||||
# define STPDFS_SB_REV STPDFS_SB_REV_1 /**< current revision */
|
||||
# define STPDFS_SB_REV_1 1
|
||||
|
||||
# define STPDFS_S_IFMT 0xF000
|
||||
# define STPDFS_S_IFSOCK 0xA000
|
||||
# define STPDFS_S_IFLNK 0xC000
|
||||
# define STPDFS_S_IFREG 0x8000
|
||||
# define STPDFS_S_IFBLK 0x6000
|
||||
# define STPDFS_S_IFDIR 0x4000
|
||||
# define STPDFS_BADINO 0 /**< StupidFS bad inode number */
|
||||
# define STPDFS_ROOTINO 1 /**< StupidFS root inode number */
|
||||
|
||||
# define STPDFS_S_ISUID 0x0800
|
||||
# define STPDFS_S_ISGID 0x0400
|
||||
# define STPDFS_S_ISVTX 0x0200
|
||||
|
||||
# define STPDFS_S_IRWXU 0x01C0
|
||||
# define STPDFS_S_IRUSR 0x0100
|
||||
# define STPDFS_S_IWUSR 0x0080
|
||||
# define STPDFS_S_IXUSR 0x0040
|
||||
|
||||
# define STPDFS_S_IRWXG 0x0038
|
||||
# define STPDFS_S_IRGRP 0x0020
|
||||
# define STPDFS_S_IWGRP 0x0010
|
||||
# define STPDFS_S_IXGRP 0x0008
|
||||
|
||||
# define STPDFS_S_IRWXO 0x0007
|
||||
# define STPDFS_S_IROTH 0x0004
|
||||
# define STPDFS_S_IWOTH 0x0002
|
||||
# define STPDFS_S_IXOTH 0x0001
|
||||
# define STPDFS_NAME_MAX 28 /**< Max filename length */
|
||||
|
||||
/**
|
||||
* \brief free block list
|
||||
|
@ -89,8 +58,8 @@
|
|||
* ```
|
||||
*/
|
||||
struct stpdfs_free {
|
||||
uint32_t free[100];
|
||||
uint8_t nfree;
|
||||
uint32_t free[100]; /**< List of free block (0-99), index 0 point to next freelist */
|
||||
uint8_t nfree; /**< index */
|
||||
} __attribute__((packed));
|
||||
|
||||
enum stpdfs_state {
|
||||
|
@ -104,36 +73,100 @@ enum stpdfs_state {
|
|||
*/
|
||||
struct stpdfs_sb {
|
||||
uint32_t magic; /**< MUST be \ref STPDFS_SB_MAGIC */
|
||||
uint32_t isize; /**< size in block of the I list */
|
||||
uint32_t fsize; /**< size in block of the entire volume */
|
||||
uint32_t isize; /**< Size in block of the I list */
|
||||
uint32_t fsize; /**< Size in block of the entire volume */
|
||||
struct stpdfs_free freelist; /**< \see stpdfs_free */
|
||||
uint8_t revision; /**< MUST be \ref STPDFS_SB_REV */
|
||||
uint16_t state; /**< \see stpdfs_state */
|
||||
uint64_t time; /**< last time the superblock was modified */
|
||||
uint64_t time; /**< Last time the superblock was modified */
|
||||
} __attribute__((packed));
|
||||
|
||||
#define STPDFS_SB_SIZE sizeof(struct stpdfs_sb)
|
||||
|
||||
/**
|
||||
* \brief StupidFS I-node
|
||||
*
|
||||
* ```
|
||||
* ┌────────┐
|
||||
* │ │
|
||||
* ┌───────►│ │
|
||||
* │ │ │
|
||||
* ┌──────┐ Direct│ └────────┘
|
||||
* │zone 0├───────┘
|
||||
* ├──────┤
|
||||
* │... │
|
||||
* ├──────┤ ┌────────┐ ┌────────┐
|
||||
* │zone 6│ │ ├─────►│ │
|
||||
* ├──────┤ Indirect │ │ │ │
|
||||
* │zone 7├─────────►│ │ │ │
|
||||
* ├──────┤ └────────┘ └────────┘
|
||||
* │zone 8├───────┐
|
||||
* ├──────┤ │Double indirect┌────────┐ ┌────────┐ ┌────────┐
|
||||
* │zone 9│ └──────────────►│ ├───►│ ├───►│ │
|
||||
* └──┬───┘ │ │ │ │ │ │
|
||||
* │ │ │ │ │ │ │
|
||||
* │ └────────┘ └────────┘ └────────┘
|
||||
* │ Triple indirect ┌────────┐
|
||||
* └────────────────►│ │ ┌────────┐ ┌────────┐ ┌────────┐
|
||||
* │ ├───►│ │ │ │ │ │
|
||||
* │ │ │ ├─────►│ ├─────►│ │
|
||||
* └────────┘ │ │ │ │ │ │
|
||||
* └────────┘ └────────┘ └────────┘
|
||||
* ```
|
||||
*/
|
||||
struct stpdfs_inode {
|
||||
uint16_t mode; /**< file mode */
|
||||
uint16_t nlink; /**< link count */
|
||||
uint16_t uid; /**< owner user id */
|
||||
uint16_t gid; /**< group id */
|
||||
uint16_t flags;
|
||||
uint32_t size;
|
||||
uint16_t mode; /**< File mode */
|
||||
uint16_t nlink; /**< Link count */
|
||||
uint16_t uid; /**< Owner user id */
|
||||
uint16_t gid; /**< Group id */
|
||||
uint16_t flags; /** File flags */
|
||||
uint32_t size; /** Data size in byte */
|
||||
uint32_t zones[10];
|
||||
uint64_t actime;
|
||||
uint64_t modtime;
|
||||
uint64_t actime; /**< Access time */
|
||||
uint64_t modtime; /**< Modification time */
|
||||
} __attribute__((packed));
|
||||
#define STPDFS_INODE_SIZE sizeof(struct inode)
|
||||
|
||||
# define STPDFS_NDIR 7 /**< Number of direct block */
|
||||
|
||||
# define STPDFS_INO_FLAG_ALOC (1 << 15)
|
||||
# define STPDFS_INO_FLAG_LZP (1 << 1)
|
||||
# define STPDFS_INO_FLAG_ENC (1 << 2)
|
||||
|
||||
|
||||
# define STPDFS_S_IFMT 0xF000
|
||||
# define STPDFS_S_IFSOCK 0xA000
|
||||
# define STPDFS_S_IFLNK 0xC000
|
||||
# define STPDFS_S_IFREG 0x8000
|
||||
# define STPDFS_S_IFBLK 0x6000
|
||||
# define STPDFS_S_IFDIR 0x4000
|
||||
|
||||
# define STPDFS_S_ISUID 0x0800
|
||||
# define STPDFS_S_ISGID 0x0400
|
||||
# define STPDFS_S_ISVTX 0x0200
|
||||
|
||||
# define STPDFS_S_IRWXU 0x01C0
|
||||
# define STPDFS_S_IRUSR 0x0100
|
||||
# define STPDFS_S_IWUSR 0x0080
|
||||
# define STPDFS_S_IXUSR 0x0040
|
||||
|
||||
# define STPDFS_S_IRWXG 0x0038
|
||||
# define STPDFS_S_IRGRP 0x0020
|
||||
# define STPDFS_S_IWGRP 0x0010
|
||||
# define STPDFS_S_IXGRP 0x0008
|
||||
|
||||
# define STPDFS_S_IRWXO 0x0007
|
||||
# define STPDFS_S_IROTH 0x0004
|
||||
# define STPDFS_S_IWOTH 0x0002
|
||||
# define STPDFS_S_IXOTH 0x0001
|
||||
|
||||
/**
|
||||
* \brief StupidFS directory entry
|
||||
*/
|
||||
struct stpdfs_dirent {
|
||||
uint32_t inode;
|
||||
char filename[STPDFS_NAME_MAX];
|
||||
uint32_t inode; /**< inode containing file */
|
||||
char filename[STPDFS_NAME_MAX]; /** null terminated file name (\see STPDFS_NAME_MAX) */
|
||||
};
|
||||
#define STPDFS_DIRENT_SIZE sizeof(struct stpdfs_dirent)
|
||||
|
||||
#endif /* !STPDFS_H */
|
||||
#endif /* !STPIDFS_H */
|
|
@ -1,4 +1,5 @@
|
|||
noinst_LIBRARIES = libstpdfs.a
|
||||
AM_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/lib -I$(top_srcdir)
|
||||
libstpdfs_a_SOURCES = block.c \
|
||||
inode.c \
|
||||
dir.c \
|
||||
|
|
126
lib/stpdfs.h
126
lib/stpdfs.h
|
@ -11,134 +11,10 @@
|
|||
#ifndef STPDFS_H
|
||||
# define STPDFS_H 1
|
||||
|
||||
# include <stupidfs.h>
|
||||
# include <stdint.h>
|
||||
# include <stddef.h>
|
||||
|
||||
# define STPDFS_SB_MAGIC 0x44505453
|
||||
# define STPDFS_SB_REV STPDFS_SB_REV_1
|
||||
# define STPDFS_SB_REV_1 1
|
||||
|
||||
# define STPDFS_INO_ROOTDIR 1
|
||||
|
||||
# define STPDFS_BLOCK_SIZE_BITS 9
|
||||
# define STPDFS_BLOCK_SIZE (1 << STPDFS_BLOCK_SIZE_BITS)
|
||||
|
||||
# define STPDFS_NAME_MAX 28
|
||||
|
||||
# define STPDFS_INODES_PER_BLOCK (STPDFS_BLOCK_SIZE / (sizeof(struct stpdfs_inode)))
|
||||
# define STPDFS_ZONES_PER_BLOCK (STPDFS_BLOCK_SIZE / sizeof(uint32_t))
|
||||
# define STPDFS_DIRENT_PER_BLOCK (STPDFS_BLOCK_SIZE / (sizeof(struct stpdfs_dirent)))
|
||||
# define STPDFS_NDIR 7
|
||||
# define STPDFS_ROOT_INO 1
|
||||
|
||||
# define STPDFS_INO_FLAG_ALOC (1 << 15)
|
||||
# define STPDFS_INO_FLAG_LARGE (1 << 0)
|
||||
# define STPDFS_INO_FLAG_LZP (1 << 1)
|
||||
# define STPDFS_INO_FLAG_ENC (1 << 2)
|
||||
|
||||
# define STPDFS_S_IFMT 0xF000
|
||||
# define STPDFS_S_IFSOCK 0xA000
|
||||
# define STPDFS_S_IFLNK 0xC000
|
||||
# define STPDFS_S_IFREG 0x8000
|
||||
# define STPDFS_S_IFBLK 0x6000
|
||||
# define STPDFS_S_IFDIR 0x4000
|
||||
|
||||
# define STPDFS_S_ISUID 0x0800
|
||||
# define STPDFS_S_ISGID 0x0400
|
||||
# define STPDFS_S_ISVTX 0x0200
|
||||
|
||||
# define STPDFS_S_IRWXU 0x01C0
|
||||
# define STPDFS_S_IRUSR 0x0100
|
||||
# define STPDFS_S_IWUSR 0x0080
|
||||
# define STPDFS_S_IXUSR 0x0040
|
||||
|
||||
# define STPDFS_S_IRWXG 0x0038
|
||||
# define STPDFS_S_IRGRP 0x0020
|
||||
# define STPDFS_S_IWGRP 0x0010
|
||||
# define STPDFS_S_IXGRP 0x0008
|
||||
|
||||
# define STPDFS_S_IRWXO 0x0007
|
||||
# define STPDFS_S_IROTH 0x0004
|
||||
# define STPDFS_S_IWOTH 0x0002
|
||||
# define STPDFS_S_IXOTH 0x0001
|
||||
|
||||
typedef uint32_t zone_t; /**< zone number */
|
||||
typedef uint32_t block_t; /**< block number */
|
||||
|
||||
/**
|
||||
* \brief free block list
|
||||
* ```
|
||||
* ┌──────────┐
|
||||
* │ block 99 │
|
||||
* ├──────────┤
|
||||
* │ block 98 │
|
||||
* ├──────────┤
|
||||
* │ ... │
|
||||
* ├──────────┤
|
||||
* │ block 2 │
|
||||
* ├──────────┤
|
||||
* │ block 1 │
|
||||
* ├──────────┤ ┌──────────┐
|
||||
* │ block 0 ├───►│ block 99 │
|
||||
* └──────────┘ ├──────────┤
|
||||
* │ ... │
|
||||
* ├──────────┤ ┌──────────┐
|
||||
* │ block 0 ├──►│ block 99 │
|
||||
* └──────────┘ ├──────────┤
|
||||
* │ ... │
|
||||
* ├──────────┤
|
||||
* │ block 0 │
|
||||
* └──────────┘
|
||||
* ```
|
||||
*/
|
||||
struct stpdfs_free {
|
||||
block_t free[100];
|
||||
uint8_t nfree;
|
||||
} __attribute__((packed));
|
||||
|
||||
enum stpdfs_state {
|
||||
STPDFS_CLEANLY_UNMOUNTED = 0,
|
||||
STPDFS_ERROR = 1,
|
||||
STPDFS_DIRTY = 1,
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief StupidFS Superblock
|
||||
*/
|
||||
struct stpdfs_sb {
|
||||
uint32_t magic; /**< MUST be \ref STPDFS_SB_MAGIC */
|
||||
uint32_t isize; /**< size in block of the I list */
|
||||
uint32_t fsize; /**< size in block of the entire volume */
|
||||
struct stpdfs_free freelist; /**< \see stpdfs_free */
|
||||
uint8_t revision; /**< MUST be \ref STPDFS_SB_REV */
|
||||
uint16_t state; /**< \see stpdfs_state */
|
||||
uint64_t time; /**< last time the superblock was modified */
|
||||
} __attribute__((packed));
|
||||
|
||||
#define STPDFS_SB_SIZE sizeof(struct stpdfs_sb)
|
||||
|
||||
/**
|
||||
* \brief StupidFS I-node
|
||||
*/
|
||||
struct stpdfs_inode {
|
||||
uint16_t mode; /**< file mode */
|
||||
uint16_t nlink; /**< link count */
|
||||
uint16_t uid; /**< owner user id */
|
||||
uint16_t gid; /**< group id */
|
||||
uint16_t flags;
|
||||
uint32_t size;
|
||||
zone_t zones[10];
|
||||
uint64_t actime;
|
||||
uint64_t modtime;
|
||||
} __attribute__((packed));
|
||||
|
||||
#define STPDFS_INODE_SIZE sizeof(struct inode)
|
||||
|
||||
struct stpdfs_dirent {
|
||||
uint32_t inode;
|
||||
char filename[STPDFS_NAME_MAX];
|
||||
};
|
||||
|
||||
/*
|
||||
* API
|
||||
*/
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
AM_CPPFLAGS = -I$(top_srcdir)/lib
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/lib -I$(top_srcdir)/include
|
||||
|
||||
TESTS = test_lzp test_hchacha test_xchacha
|
||||
check_PROGRAMS = test_lzp test_hchacha test_xchacha
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
AM_CFLAGS = -I$(top_srcdir)/lib -I$(top_srcdir)
|
||||
AM_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/lib -I$(top_srcdir)
|
||||
LDADD = ../lib/libstpdfs.a
|
||||
|
||||
bin_PROGRAMS = mkfs.stpd tools.stpd
|
||||
|
|
|
@ -2,12 +2,13 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <stpdfs.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <stupidfs.h>
|
||||
#include <stpdfs.h>
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
@ -146,20 +147,20 @@ mkfs()
|
|||
|
||||
/* create root dir */
|
||||
stpdfs_read(fd, 2, &inds, sizeof(struct stpdfs_inode) * STPDFS_INODES_PER_BLOCK);
|
||||
inds[STPDFS_INO_ROOTDIR].modtime = time(NULL);
|
||||
inds[STPDFS_INO_ROOTDIR].actime = time(NULL);
|
||||
inds[STPDFS_INO_ROOTDIR].size = sizeof(struct stpdfs_dirent) * 2;
|
||||
inds[STPDFS_INO_ROOTDIR].flags = STPDFS_INO_FLAG_ALOC;
|
||||
inds[STPDFS_INO_ROOTDIR].mode = STPDFS_S_IFDIR | STPDFS_S_IRUSR | STPDFS_S_IWUSR | STPDFS_S_IXUSR | STPDFS_S_IRGRP | STPDFS_S_IXGRP | STPDFS_S_IXOTH;
|
||||
inds[STPDFS_INO_ROOTDIR].zones[0] = stpdfs_alloc_block(fd, &super);
|
||||
inds[STPDFS_INO_ROOTDIR].size = sizeof(struct stpdfs_dirent) * 2;
|
||||
stpdfs_read(fd, inds[STPDFS_INO_ROOTDIR].zones[0], rootdirent, sizeof(struct stpdfs_dirent) * 2);
|
||||
inds[STPDFS_ROOTINO].modtime = time(NULL);
|
||||
inds[STPDFS_ROOTINO].actime = time(NULL);
|
||||
inds[STPDFS_ROOTINO].size = sizeof(struct stpdfs_dirent) * 2;
|
||||
inds[STPDFS_ROOTINO].flags = STPDFS_INO_FLAG_ALOC;
|
||||
inds[STPDFS_ROOTINO].mode = STPDFS_S_IFDIR | STPDFS_S_IRUSR | STPDFS_S_IWUSR | STPDFS_S_IXUSR | STPDFS_S_IRGRP | STPDFS_S_IXGRP | STPDFS_S_IXOTH;
|
||||
inds[STPDFS_ROOTINO].zones[0] = stpdfs_alloc_block(fd, &super);
|
||||
inds[STPDFS_ROOTINO].size = sizeof(struct stpdfs_dirent) * 2;
|
||||
stpdfs_read(fd, inds[STPDFS_ROOTINO].zones[0], rootdirent, sizeof(struct stpdfs_dirent) * 2);
|
||||
strcpy(rootdirent[0].filename, ".");
|
||||
rootdirent[1].inode = 1;
|
||||
strcpy(rootdirent[1].filename, "..");
|
||||
rootdirent[1].inode = 1;
|
||||
inds[STPDFS_INO_ROOTDIR].nlink += 2;
|
||||
stpdfs_write(fd, inds[STPDFS_INO_ROOTDIR].zones[0], rootdirent, sizeof(struct stpdfs_dirent) * 2);
|
||||
inds[STPDFS_ROOTINO].nlink += 2;
|
||||
stpdfs_write(fd, inds[STPDFS_ROOTINO].zones[0], rootdirent, sizeof(struct stpdfs_dirent) * 2);
|
||||
stpdfs_write(fd, 2, &inds, sizeof(struct stpdfs_inode) * STPDFS_INODES_PER_BLOCK);
|
||||
|
||||
/* write super block */
|
||||
|
|
BIN
tools/tools.stpd
BIN
tools/tools.stpd
Binary file not shown.
Loading…
Reference in a new issue