diff --git a/Doxyfile b/Doxyfile index e17b135..54fac8e 100644 --- a/Doxyfile +++ b/Doxyfile @@ -524,7 +524,7 @@ TIMESTAMP = NO # normally produced when WARNINGS is set to YES. # The default value is: NO. -EXTRACT_ALL = YES +EXTRACT_ALL = NO # If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will # be included in the documentation. @@ -949,7 +949,7 @@ WARN_LOGFILE = # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING # Note: If this tag is empty the current directory is searched. -INPUT = lib src module win32 +INPUT = libcrypto liblzp libstpdfs include module win32 # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses diff --git a/Makefile.am b/Makefile.am index fce50ec..bfe20d1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = lib tools tests +SUBDIRS = lib libcrypto liblzp tools if BUILD_FUSE SUBDIRS += fuse diff --git a/configure.ac b/configure.ac index 1c73a5b..e9bb9ea 100644 --- a/configure.ac +++ b/configure.ac @@ -44,8 +44,12 @@ AC_CHECK_FUNCS(m4_normalize([ AC_CONFIG_FILES([Makefile lib/Makefile + libcrypto/Makefile + libcrypto/tests/Makefile + liblzp/Makefile + liblzp/tests/Makefile + libstpdfs/Makefile tools/Makefile - tests/Makefile linux/Makefile fuse/Makefile]) diff --git a/include/stupidfs.h b/include/stupidfs.h index bbc0734..b5d8b54 100644 --- a/include/stupidfs.h +++ b/include/stupidfs.h @@ -22,6 +22,8 @@ # 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_SB_BLOCK 1 + # define STPDFS_SB_MAGIC 0x44505453 /**< Superblock magic number */ # define STPDFS_SB_REV STPDFS_SB_REV_1 /**< current revision */ # define STPDFS_SB_REV_1 1 diff --git a/lib/Makefile.am b/lib/Makefile.am index 0ce3799..4917d2b 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -4,7 +4,4 @@ libstpdfs_a_SOURCES = block.c \ inode.c \ dir.c \ data.c \ - superblock.c \ - compression/lzp.c \ - crypto/hchacha.c \ - crypto/xchacha.c \ No newline at end of file + superblock.c \ No newline at end of file diff --git a/libcrypto/Makefile.am b/libcrypto/Makefile.am new file mode 100644 index 0000000..77f1315 --- /dev/null +++ b/libcrypto/Makefile.am @@ -0,0 +1,5 @@ +SUBDIRS = tests + +noinst_LIBRARIES = libcrypto.a +AM_CFLAGS = -I$(top_srcdir) +libcrypto_a_SOURCES = hchacha.c xchacha.c \ No newline at end of file diff --git a/lib/crypto/chacha.h b/libcrypto/chacha.h similarity index 91% rename from lib/crypto/chacha.h rename to libcrypto/chacha.h index 490a1d6..76dd55a 100644 --- a/lib/crypto/chacha.h +++ b/libcrypto/chacha.h @@ -1,5 +1,8 @@ -#ifndef STPDFS_CRYPTO_CHACHA_H -# define STPDFS_CRYPTO_CHACHA_H 1 +/** + * \file chacha.h + */ +#ifndef CHACHA_H +# define CHACHA_H 1 # include # include @@ -38,4 +41,4 @@ void xchacha12(uint8_t *out, uint8_t key[CHACHA_KEY_BYTES], uint8_t nonce[24], uint8_t *in, size_t inlen); -#endif /* STPDFS_CRYPTO_CHACHA_H */ \ No newline at end of file +#endif /* CHACHA_H */ \ No newline at end of file diff --git a/lib/crypto/hchacha.c b/libcrypto/hchacha.c similarity index 100% rename from lib/crypto/hchacha.c rename to libcrypto/hchacha.c diff --git a/libcrypto/tests/Makefile.am b/libcrypto/tests/Makefile.am new file mode 100644 index 0000000..3c8e705 --- /dev/null +++ b/libcrypto/tests/Makefile.am @@ -0,0 +1,9 @@ +TESTS = test_hchacha test_xchacha +check_PROGRAMS = test_hchacha test_xchacha + +AM_CFLAGS = -I../ +LDADD = -lcmocka ../libcrypto.a + +test_hchacha_SOURCES = test_hchacha.c + +test_xchacha_SOURCES = test_xchacha.c \ No newline at end of file diff --git a/tests/test_hchacha.c b/libcrypto/tests/test_hchacha.c similarity index 97% rename from tests/test_hchacha.c rename to libcrypto/tests/test_hchacha.c index 100d5fb..15053f5 100644 --- a/tests/test_hchacha.c +++ b/libcrypto/tests/test_hchacha.c @@ -4,7 +4,7 @@ #include #include -#include +#include "chacha.h" /* test from https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-xchacha-03#section-2.2 */ diff --git a/tests/test_xchacha.c b/libcrypto/tests/test_xchacha.c similarity index 99% rename from tests/test_xchacha.c rename to libcrypto/tests/test_xchacha.c index 528b56e..8fdbe36 100644 --- a/tests/test_xchacha.c +++ b/libcrypto/tests/test_xchacha.c @@ -5,7 +5,7 @@ #include #include -#include +#include "chacha.h" void xchacha(uint8_t *out, uint8_t key[CHACHA_KEY_BYTES], uint8_t nonce[24], uint8_t *in, size_t inlen, int round); diff --git a/lib/crypto/xchacha.c b/libcrypto/xchacha.c similarity index 100% rename from lib/crypto/xchacha.c rename to libcrypto/xchacha.c diff --git a/liblzp/Makefile.am b/liblzp/Makefile.am new file mode 100644 index 0000000..a1a1ef9 --- /dev/null +++ b/liblzp/Makefile.am @@ -0,0 +1,4 @@ +SUBDIRS = tests + +noinst_LIBRARIES = liblzp.a +liblzp_a_SOURCES = lzp.c \ No newline at end of file diff --git a/lib/compression/lzp.c b/liblzp/lzp.c similarity index 100% rename from lib/compression/lzp.c rename to liblzp/lzp.c diff --git a/lib/compression/lzp.h b/liblzp/lzp.h similarity index 66% rename from lib/compression/lzp.h rename to liblzp/lzp.h index a0d9a0a..0d3525b 100644 --- a/lib/compression/lzp.h +++ b/liblzp/lzp.h @@ -1,5 +1,8 @@ -#ifndef STPDFS_COMPRESSION_LZP_H -# define STPDFS_COMPRESSION_LZP_H 1 +/** + * \file lzp.h + */ +#ifndef LZP_H +# define LZP_H 1 # include # include @@ -7,4 +10,4 @@ void lzp_compress(uint8_t *out, size_t *outsz, const uint8_t *in, size_t insz); void lzp_decompress(uint8_t *out, size_t *outsz, const uint8_t *in, size_t insz); -#endif /* STPDF_COMPRESSION_LZP_H */ \ No newline at end of file +#endif /* LZP_H */ \ No newline at end of file diff --git a/liblzp/tests/Makefile.am b/liblzp/tests/Makefile.am new file mode 100644 index 0000000..7a3ec8f --- /dev/null +++ b/liblzp/tests/Makefile.am @@ -0,0 +1,9 @@ +AM_CPPFLAGS = -I$(srcdir)/.. + +TESTS = test_lzp +check_PROGRAMS = test_lzp + +LDADD = -lcmocka ../liblzp.a + +test_lzp_SOURCES = test_lzp.c + diff --git a/tests/test_lzp.c b/liblzp/tests/test_lzp.c similarity index 100% rename from tests/test_lzp.c rename to liblzp/tests/test_lzp.c diff --git a/libstpdfs/Makefile.am b/libstpdfs/Makefile.am new file mode 100644 index 0000000..3557c22 --- /dev/null +++ b/libstpdfs/Makefile.am @@ -0,0 +1,2 @@ +noinst_LIBRARIES = libstpdfs.a +liblzp_a_SOURCES = super.c bio.c inode.c file.c dir.c \ No newline at end of file diff --git a/libstpdfs/bio.c b/libstpdfs/bio.c new file mode 100644 index 0000000..45be0c2 --- /dev/null +++ b/libstpdfs/bio.c @@ -0,0 +1,89 @@ +/** + * file: block.c + */ + +#include +#include +#include +#include +#include +#include + +size_t +stpdfs_write(int fd, uint32_t blocknum, void *data, size_t size) +{ + uint8_t buffer[STPDFS_BLOCK_SIZE]; + + if (size > STPDFS_BLOCK_SIZE) return (-1); + + lseek(fd, blocknum * STPDFS_BLOCK_SIZE, SEEK_SET); + if (size > 0) + { + memcpy(buffer, data, size); + return (write(fd, buffer, STPDFS_BLOCK_SIZE)); + } + + return (write(fd, data, size)); +} + +size_t +stpdfs_read(int fd, uint32_t blocknum, void *data, size_t size) +{ + lseek(fd, blocknum * STPDFS_BLOCK_SIZE, SEEK_SET); + + return (read(fd, data, size)); +} + +uint32_t +stpdfs_alloc_block(int fd, struct stpdfs_sb *sb) +{ + uint32_t blocknum; + struct stpdfs_free freelist; + + sb->state = STPDFS_DIRTY; /* mark state dirty */ +redo: + sb->freelist.nfree--; + blocknum = sb->freelist.free[sb->freelist.nfree]; + if (sb->freelist.nfree == 0 && blocknum != 0) + { + stpdfs_read(fd, blocknum, &freelist, sizeof(struct stpdfs_free)); + memcpy(sb->freelist.free, &freelist, sizeof(uint32_t) * 100); + sb->freelist.nfree = freelist.nfree; + goto redo; + } + + sb->time = time(NULL); + + return (blocknum); +} + +int +stpdfs_free_block(int fd, struct stpdfs_sb *sb, uint32_t blocknum) +{ + struct stpdfs_free copy; + + if (blocknum == 0 || blocknum >= sb->fsize) + { + return (-1); + } + + sb->state = STPDFS_DIRTY; /* mark state dirty */ + + if (sb->freelist.nfree == 100) + { + memcpy(©, sb->freelist.free, sizeof(uint32_t) * 100); + copy.nfree = sb->freelist.nfree; + + stpdfs_write(fd, blocknum, ©, sizeof(struct stpdfs_free)); + + sb->freelist.nfree = 1; + sb->freelist.free[0] = blocknum; + } + else + { + sb->freelist.free[sb->freelist.nfree++] = blocknum; + } + + sb->time = time(NULL); + return (0); +} \ No newline at end of file diff --git a/libstpdfs/dir.c b/libstpdfs/dir.c new file mode 100644 index 0000000..e69de29 diff --git a/libstpdfs/file.c b/libstpdfs/file.c new file mode 100644 index 0000000..e69de29 diff --git a/libstpdfs/inode.c b/libstpdfs/inode.c new file mode 100644 index 0000000..bb0c51a --- /dev/null +++ b/libstpdfs/inode.c @@ -0,0 +1,13 @@ +#include + +struct inode * +stpdfs_inode_get(struct stpdfs_sb *sb, uint32_t ino) +{ + return (NULL); +} + +struct stpdfs_dirent * +stpdfs_lookup(struct stpdfs_inode *dir, struct stpdfs_dirent *dentry, int flags) +{ + return (NULL); +} \ No newline at end of file diff --git a/libstpdfs/stpdfs.h b/libstpdfs/stpdfs.h new file mode 100644 index 0000000..cce4fe0 --- /dev/null +++ b/libstpdfs/stpdfs.h @@ -0,0 +1,18 @@ +/** + * \file stpdfs.h + */ +#ifndef STPDFS_H +# define STPDFS_H 1 + +# include + +struct stpdfs_super_info { + struct stpdfs_sb sb; + int fd; +}; + +int stpdfs_read_super(struct stpdfs_super_info *sbi, int fd); +int stpdfs_super_validate(struct stpdfs_sb *sb); +int stpdfs_kill_super(struct stpdfs_super_info *sbi); + +#endif /* !STPDFS_H */ \ No newline at end of file diff --git a/libstpdfs/super.c b/libstpdfs/super.c new file mode 100644 index 0000000..e60031a --- /dev/null +++ b/libstpdfs/super.c @@ -0,0 +1,27 @@ +#include + +int +stpdfs_super_validate(struct stpdfs_sb *sb) +{ + if (sb->magic != STPDFS_SB_MAGIC) + { + return (-1); + } + + if (sb->revision != STPDFS_SB_REV) + { + return (-1); + } + + if (sb->fsize == 0 || sb->isize == 0) + { + return (-1); + } + + if (sb->isize > sb->fsize) + { + return (-1); + } + + return (0); +} \ No newline at end of file diff --git a/tests/Makefile.am b/tests/Makefile.am deleted file mode 100644 index 3d9aeb7..0000000 --- a/tests/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ -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 - -LDADD = -lcmocka ../lib/libstpdfs.a - -test_lzp_SOURCES = test_lzp.c - - -test_hchacha_SOURCES = test_hchacha.c - -test_xchacha_SOURCES = test_xchacha.c \ No newline at end of file