ext2: implement file writing

there is much room for improvement in the traversal of indirectly linked
blocks
This commit is contained in:
Michael Shaw 2023-10-21 12:54:35 -04:00
commit f8d84c7780
6 changed files with 423 additions and 31 deletions

View file

@ -8,6 +8,7 @@
#define EBADF 4
#define ENOTDIR 5
#define EISDIR 6
#define ENOSPC 7
const char *strerror(int errnum);

View file

@ -144,6 +144,8 @@ struct ext2fs {
struct ext2_superblock sb;
struct block_device *bdev;
uint32_t bgdt_blockno;
uint32_t bgdt_num_blocks;
struct ext2_group_desc *bgdt;
uint32_t indir_block_size;
@ -153,10 +155,4 @@ struct ext2fs {
struct fs *ext2_init_fs(struct block_device *bdev);
/* Filesystem block sizes are not equal to block device block sizes */
int ext2_read_block(struct ext2fs *fs, void *buf, size_t block);
int ext2_write_block(struct ext2fs *fs, void *buf, size_t block);
int ext2_read_inode(struct ext2fs *fs, struct ext2_inode *out, uint32_t inode);
int ext2_read_inode(struct ext2fs *fs, struct ext2_inode *in, uint32_t inode);
#endif /* _EXT2_H_ */

View file

@ -47,6 +47,10 @@ struct inode {
uint32_t file_acl;
uint32_t dir_acl;
uint32_t faddr;
uint64_t af_size;
uint16_t frag_number;
uint16_t frag_size;
} PACKED; /* PACKED to allow for memcpy */
struct dirent {
@ -105,7 +109,7 @@ struct fs {
};
void vfs_init(const char *rootfs);
int write(int fd, const void *buf, size_t count);
int write(int fd, void *buf, size_t count);
int read(int fd, void *buf, size_t count);
int open(const char *pathname, int flags);
int close(int fd);