chore: all still wip
This commit is contained in:
parent
9dcde5fa89
commit
75b8c8af48
|
@ -134,9 +134,8 @@ struct inode {
|
|||
\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 \\
|
||||
STPDFS\_INODE\_LZP & 1 << 0 & if set data are compressed \\
|
||||
STPDFS\_INODE\_ENC & 1 << 1 & if set data are encrypted \\
|
||||
\hline
|
||||
\end{tabular}
|
||||
\end{center}
|
||||
|
|
|
@ -109,6 +109,7 @@ fuse_stpdfs_getattr(const char *path, struct stat *stbuf,
|
|||
stbuf->st_mode = inode.mode;
|
||||
stbuf->st_gid = inode.gid;
|
||||
stbuf->st_uid = inode.uid;
|
||||
stbuf->st_nlink = inode.nlink;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
/**
|
||||
* file: block.c
|
||||
*/
|
||||
|
||||
#include "stpdfs.h"
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
|
80
lib/data.c
80
lib/data.c
|
@ -1,16 +1,82 @@
|
|||
#include "stpdfs.h"
|
||||
#include <string.h>
|
||||
|
||||
int
|
||||
stpdfs_add_data(int fd, struct stpdfs_sb *sb, struct stpdfs_inode *inode, uint8_t *buffer, size_t size)
|
||||
static void
|
||||
write_indirect(int fd, struct stpdfs_sb *sb, struct stpdfs_inode *inode, size_t zone, uint8_t *buffer, size_t size)
|
||||
{
|
||||
size_t idx;
|
||||
size_t max_zone;
|
||||
|
||||
if (size > STPDFS_BLOCK_SIZE)
|
||||
}
|
||||
|
||||
static void
|
||||
write_zone(int fd, struct stpdfs_sb *sb, struct stpdfs_inode *inode, size_t zone, uint8_t *buffer, size_t size)
|
||||
{
|
||||
uint32_t zones[128];
|
||||
|
||||
if (zone < 7)
|
||||
{
|
||||
for (idx = 0; idx < size / STPDFS_BLOCK_SIZE; idx++)
|
||||
if (inode->zones[zone] == 0)
|
||||
{
|
||||
stpdfs_add_data(fd, sb, inode, buffer, 512 * idx);
|
||||
inode->zones[zone] = stpdfs_alloc_block(fd, sb);
|
||||
}
|
||||
stpdfs_write(fd, inode->zones[zone], buffer, size);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (zone < 135)
|
||||
{
|
||||
if (inode->zones[7] == 0)
|
||||
{
|
||||
inode->zones[7] = stpdfs_alloc_block(fd, sb);
|
||||
memset(zones, 0, 512);
|
||||
stpdfs_write(fd, inode->zones[7], zones, 512);
|
||||
}
|
||||
|
||||
stpdfs_read(fd, inode->zones[7], zones, 512);
|
||||
if (zones[zone - 7] == 0)
|
||||
{
|
||||
zones[zone - 7] = stpdfs_alloc_block(fd, sb);
|
||||
stpdfs_write(fd, inode->zones[7], zones, 512);
|
||||
}
|
||||
|
||||
stpdfs_write(fd, zones[zone - 7], buffer, size);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (zone < 16519)
|
||||
{
|
||||
if (inode->zones[8] == 0)
|
||||
{
|
||||
inode->zones[8] = stpdfs_alloc_block(fd, sb);
|
||||
memset(zones, 0, 512);
|
||||
stpdfs_write(fd, inode->zones[7], zones, 512);
|
||||
}
|
||||
stpdfs_read(fd, inode->zones[8], zones, 512);
|
||||
|
||||
if (zones[(zone - 135) / 128] == 0)
|
||||
{
|
||||
zones[(zone - 135) / 128] = stpdfs_alloc_block(fd, sb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
stpdfs_write_data(int fd, struct stpdfs_sb *sb, struct stpdfs_inode *inode, uint8_t *buffer, size_t size)
|
||||
{
|
||||
size_t idx;
|
||||
uint32_t zonenum;
|
||||
size_t max_zone;
|
||||
|
||||
for (idx = 0; idx < size; idx += STPDFS_BLOCK_SIZE)
|
||||
{
|
||||
max_zone = idx / STPDFS_BLOCK_SIZE;
|
||||
for (zonenum = 0; zonenum < max_zone; zonenum++)
|
||||
{
|
||||
write_zone(fd, sb, inode, zonenum, buffer + idx, ((idx + 1) * 512) > size ? size % 512 : 512);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return (0)
|
||||
}
|
||||
|
|
24
lib/stpdfs.h
24
lib/stpdfs.h
|
@ -13,7 +13,7 @@
|
|||
# define STPDFS_BLOCK_SIZE_BITS 9
|
||||
# define STPDFS_BLOCK_SIZE (1 << STPDFS_BLOCK_SIZE_BITS)
|
||||
|
||||
# define STPDFS_NAME_MAX 28
|
||||
# define STPDFS_NAME_MAX 255
|
||||
|
||||
# define STPDFS_INODES_PER_BLOCK (STPDFS_BLOCK_SIZE / (sizeof(struct stpdfs_inode)))
|
||||
# define STPDFS_DIRENT_PER_BLOCK (STPDFS_BLOCK_SIZE / (sizeof(struct stpdfs_dirent)))
|
||||
|
@ -32,6 +32,12 @@
|
|||
# define STPDFS_S_IFBLK 0x6000
|
||||
# define STPDFS_S_IFDIR 0x4000
|
||||
|
||||
typedef uint32_t zone_t; /**< zone number */
|
||||
typedef uint32_t block_t; /**< block number */
|
||||
|
||||
/**
|
||||
* \brief free block list
|
||||
*/
|
||||
struct stpdfs_free {
|
||||
uint32_t free[100];
|
||||
uint8_t nfree;
|
||||
|
@ -88,7 +94,23 @@ struct stpdfs_dirent {
|
|||
size_t stpdfs_write(int fd, uint32_t blocknum, void *data, size_t size);
|
||||
size_t stpdfs_read(int fd, uint32_t blocknum, void *data, size_t size);
|
||||
|
||||
|
||||
/**
|
||||
* mark block as available for new allocation.
|
||||
*
|
||||
* \param fd file descriptor.
|
||||
* \param sb pointer to \ref stpdfs_sb.
|
||||
* \param blocknum block to free
|
||||
*/
|
||||
uint32_t stpdfs_alloc_block(int fd, struct stpdfs_sb *sb);
|
||||
|
||||
/**
|
||||
* find a free block.
|
||||
*
|
||||
* \param fd file descriptor.
|
||||
* \param sb pointer to \ref stpdfs_sb.
|
||||
* \return block number or 0 if no block found.
|
||||
*/
|
||||
int stpdfs_free_block(int fd, struct stpdfs_sb *sb, uint32_t blocknum);
|
||||
|
||||
/* superblock.c */
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
AM_CFLAGS = -I$(top_srcdir)/lib -I$(top_srcdir)
|
||||
LDADD = ../lib/libstpdfs.a
|
||||
|
||||
bin_PROGRAMS = mkfs.stpd
|
||||
bin_PROGRAMS = mkfs.stpd tools.stpd
|
||||
|
||||
mkfs_stpd_SOURCES = mkfs/main.c
|
||||
|
||||
man_MANS = mkfs/mkfs.stpd.8
|
||||
tools_stpd_SOURCES = tools/main.c
|
||||
|
||||
man_MANS = mkfs/mkfs.stpd.8 tools/tools.stpd.8
|
5
tools/tools/main.c
Normal file
5
tools/tools/main.c
Normal file
|
@ -0,0 +1,5 @@
|
|||
int
|
||||
main(void)
|
||||
{
|
||||
return (0);
|
||||
}
|
0
tools/tools/tools.stpd.8
Normal file
0
tools/tools/tools.stpd.8
Normal file
Loading…
Reference in a new issue