doc: wip
This commit is contained in:
parent
de26533871
commit
9dcde5fa89
|
@ -62,6 +62,8 @@
|
|||
|
||||
\mainmatter
|
||||
|
||||
\chapter{File, file system, and memory size limits}
|
||||
|
||||
\chapter{Magic Numbers}
|
||||
|
||||
\begin{center}
|
||||
|
@ -70,15 +72,32 @@
|
|||
\textbf{Flag} & \textbf{Hexadecimal} & \textbf{ASCII} & \textbf{Data structure} \\
|
||||
\hline
|
||||
STPDFS\_SB\_MAGIC & 0x44505453 & STPD & Superblock \\
|
||||
STDFS\_BLOCK\_SIZE & 512 & & Block size\\
|
||||
\hline
|
||||
\end{tabular}
|
||||
\end{center}
|
||||
|
||||
\chapter{Structures}
|
||||
|
||||
\section{Superblocks}
|
||||
\section{Superblock}
|
||||
|
||||
\subsection{free list}
|
||||
|
||||
\begin{lstlisting}[language=C]
|
||||
struct stpdfs_free {
|
||||
uint32_t free[100];
|
||||
uint8_t nfree;
|
||||
};
|
||||
\end{lstlisting}
|
||||
|
||||
\subsection{superblock}
|
||||
|
||||
\begin{lstlisting}[language=C]
|
||||
|
||||
#define STPDFS_SB_MAGIC 0x44505453
|
||||
#define STPDFS_REV STPDFS_REV_1
|
||||
#define STPDFS_REV_1 0x1
|
||||
|
||||
struct stpdfs_sb {
|
||||
uint32_t magic;
|
||||
uint32_t isize;
|
||||
|
@ -86,7 +105,7 @@ struct stpdfs_sb {
|
|||
uint32_t free[100];
|
||||
uint8_t nfree;
|
||||
uint8_t revision;
|
||||
uint8_t state;
|
||||
uint16_t state;
|
||||
uint64_t time;
|
||||
};
|
||||
\end{lstlisting}
|
||||
|
@ -106,6 +125,46 @@ struct inode {
|
|||
uint64_t modtime;
|
||||
};
|
||||
\end{lstlisting}
|
||||
|
||||
\subsection{flags}
|
||||
|
||||
\begin{center}
|
||||
\begin{tabular}{ |c|c|c|c| }
|
||||
\hline
|
||||
\textbf{flags} & \textbf{value} & \textbf{Description} \\
|
||||
\hline
|
||||
STPDFS\_INODE\_ALLOCATED & 1 << 15 & if set inode is allocated \\
|
||||
STPDFS\_INODE\_LARGE\_FILE & 1 << 0 & \\
|
||||
STPDFS\_INODE\_LZP & 1 << 1 & if set data are compressed \\
|
||||
STPDFS\_INODE\_ENC & 1 << 2 & if set data are encrypted \\
|
||||
\hline
|
||||
\end{tabular}
|
||||
\end{center}
|
||||
|
||||
\begin{center}
|
||||
\begin{tabular}{ |c|c| }
|
||||
zone 0-6 & direct \\
|
||||
zone 7 & indirect \\
|
||||
zone 8 & double indirect \\
|
||||
zone 9 & triple indirect \\
|
||||
\end{tabular}
|
||||
\end{center}
|
||||
|
||||
\subsection{mode}
|
||||
|
||||
\begin{center}
|
||||
\begin{tabular}{ |c|c|c|c| }
|
||||
\hline
|
||||
\textbf{mode} & \textbf{value} & \textbf{Description} \\
|
||||
STPDFS\_S\_IFSOCK & 0xA000 & \\
|
||||
STPDFS\_S\_IFLNK & 0xC000 & \\
|
||||
STPDFS\_S\_IFREG & 0x8000 & \\
|
||||
STPDFS\_S\_IFBLK & 0x6000 & \\
|
||||
STPDFS\_S\_IFDIR & 0x4000 & \\
|
||||
\hline
|
||||
\end{tabular}
|
||||
\end{center}
|
||||
|
||||
\appendix
|
||||
|
||||
\end{document}
|
|
@ -1,5 +1,7 @@
|
|||
noinst_LIBRARIES = libstpdfs.a
|
||||
libstpdfs_a_SOURCES = block.c \
|
||||
inode.c \
|
||||
dir.c
|
||||
superblock.c \
|
||||
compression/lzp.c \
|
||||
crypto/hchacha.c \
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
# define STPDFS_CRYPTO_CHACHA_H 1
|
||||
|
||||
# include <stdint.h>
|
||||
# include <stddef.h>
|
||||
|
||||
# define CHACHA_CONST1 "expa"
|
||||
# define CHACHA_CONST2 "nd 3"
|
||||
|
|
16
lib/data.c
Normal file
16
lib/data.c
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include "stpdfs.h"
|
||||
|
||||
int
|
||||
stpdfs_add_data(int fd, struct stpdfs_sb *sb, struct stpdfs_inode *inode, uint8_t *buffer, size_t size)
|
||||
{
|
||||
size_t idx;
|
||||
size_t max_zone;
|
||||
|
||||
if (size > STPDFS_BLOCK_SIZE)
|
||||
{
|
||||
for (idx = 0; idx < size / STPDFS_BLOCK_SIZE; idx++)
|
||||
{
|
||||
stpdfs_add_data(fd, sb, inode, buffer, 512 * idx);
|
||||
}
|
||||
}
|
||||
}
|
63
lib/dir.c
Normal file
63
lib/dir.c
Normal file
|
@ -0,0 +1,63 @@
|
|||
#include "stpdfs.h"
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int
|
||||
stpdfs_dir_add_entry(int fd, uint8_t inonum, const char *name, uint32_t target)
|
||||
{
|
||||
struct stpdfs_inode inode;
|
||||
struct stpdfs_dirent dirent[STPDFS_DIRENT_PER_BLOCK];
|
||||
struct stpdfs_sb sb;
|
||||
size_t max_zone;
|
||||
size_t zone;
|
||||
uint32_t blocknum;
|
||||
|
||||
stpdfs_read_superblock(fd, &sb);
|
||||
stpdfs_read_inode(fd, inonum, &inode);
|
||||
if (!(inode.mode & STPDFS_S_IFDIR))
|
||||
{
|
||||
return (-1);
|
||||
}
|
||||
|
||||
max_zone = (inode.size + sizeof(struct stpdfs_dirent)) / STPDFS_DIRENT_PER_BLOCK;
|
||||
zone = max_zone;
|
||||
|
||||
if (max_zone > 2113671)
|
||||
{
|
||||
|
||||
}
|
||||
if (max_zone > 16519)
|
||||
{
|
||||
|
||||
}
|
||||
else if (max_zone > 135)
|
||||
{
|
||||
|
||||
}
|
||||
else if (max_zone > 7)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
if (inode.zones[max_zone] == 0)
|
||||
{
|
||||
inode.zones[max_zone] = stpdfs_alloc_block(fd, &sb);
|
||||
}
|
||||
|
||||
blocknum = inode.zones[max_zone];
|
||||
}
|
||||
|
||||
stpdfs_read(fd, blocknum, &dirent, sizeof(struct stpdfs_dirent) * STPDFS_DIRENT_PER_BLOCK);
|
||||
dirent[inode.size % STPDFS_DIRENT_PER_BLOCK].inode = target;
|
||||
memcpy(dirent[inode.size % STPDFS_DIRENT_PER_BLOCK].filename, name, STPDFS_NAME_MAX);
|
||||
stpdfs_write(fd, blocknum, &dirent, sizeof(struct stpdfs_dirent) * STPDFS_DIRENT_PER_BLOCK);
|
||||
|
||||
inode.size += sizeof(struct stpdfs_dirent);
|
||||
|
||||
stpdfs_write_inode(fd, inonum, &inode);
|
||||
|
||||
stpdfs_write(fd, 1, &sb, sizeof(struct stpdfs_sb));
|
||||
|
||||
return (0);
|
||||
}
|
18
lib/inode.c
18
lib/inode.c
|
@ -9,14 +9,28 @@ stpdfs_locate_inode(uint32_t inode)
|
|||
}
|
||||
|
||||
int
|
||||
stpdfs_read_inode()
|
||||
stpdfs_read_inode(int fd, uint32_t inodenum, struct stpdfs_inode *ino)
|
||||
{
|
||||
struct stpdfs_inode inodes[STPDFS_INODES_PER_BLOCK];
|
||||
|
||||
stpdfs_read(fd, 2 + inodenum / STPDFS_INODES_PER_BLOCK, (uint8_t *)&inodes, sizeof(struct stpdfs_inode) * STPDFS_INODES_PER_BLOCK);
|
||||
|
||||
memcpy(ino, &inodes[inodenum % STPDFS_INODES_PER_BLOCK], sizeof(struct stpdfs_inode));
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
stpdfs_write_inode()
|
||||
stpdfs_write_inode(int fd, uint32_t inodenum, const struct stpdfs_inode *inode)
|
||||
{
|
||||
struct stpdfs_inode inodes[STPDFS_INODES_PER_BLOCK];
|
||||
|
||||
stpdfs_read(fd, 2 + inodenum / STPDFS_INODES_PER_BLOCK, (uint8_t *)&inodes, sizeof(struct stpdfs_inode) * STPDFS_INODES_PER_BLOCK);
|
||||
|
||||
memcpy(&inodes[inodenum % STPDFS_INODES_PER_BLOCK], inode, sizeof(struct stpdfs_inode));
|
||||
|
||||
stpdfs_write(fd, 2 + inodenum / STPDFS_INODES_PER_BLOCK, (uint8_t *)&inodes, sizeof(struct stpdfs_inode) * STPDFS_INODES_PER_BLOCK);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
# define STPDFS_NAME_MAX 28
|
||||
|
||||
# define STPDFS_INODES_PER_BLOCK (STPDFS_BLOCK_SIZE / (sizeof(struct stpdfs_inode)))
|
||||
# define STPDFS_DIRENT_PER_BLOCK (STPDFS_BLOCK_SIZE / (sizeof(struct stpdfs_dirent)))
|
||||
|
||||
# define STPDFS_ROOT_INO 1
|
||||
|
||||
|
@ -96,5 +97,7 @@ int stpdfs_read_superblock(int fd, struct stpdfs_sb *sb);
|
|||
|
||||
/* inode.c */
|
||||
uint32_t stpdfd_alloc_inode(int fd, struct stpdfs_sb *sb);
|
||||
int stpdfs_read_inode(int fd, uint32_t inodenum, struct stpdfs_inode *ino);
|
||||
int stpdfs_write_inode(int fd, uint32_t inodenum, const struct stpdfs_inode *inode);
|
||||
|
||||
#endif /* !STPDFS_H */
|
Loading…
Reference in a new issue