22 if ((inode->
mode & S_IFMT) != S_IFDIR)
26 size_t blocks_nr = inode->
size / bs;
29 char *buf =
kmalloc(bs, &M_BUFFER, 0);
36 for (
size_t i = 0; i < blocks_nr && err == -ENOENT; ++i) {
45 while ((
char *) d < (
char *) buf + bs && d->
size) {
64 switch (mode & S_IFMT) {
92 if ((dir->
mode & S_IFMT) != S_IFDIR)
95 struct ext2 *desc = dir->
p;
98 size_t length = strlen(name);
108 char *buf =
kmalloc(desc->
bs, &M_BUFFER, 0);
114 size_t bs = desc->
bs;
115 size_t blocks_nr = dir_inode.
size / bs;
119 for (block = 0; block < blocks_nr; ++block) {
126 while ((
char *) cur < (
char *) buf + bs && cur->size) {
128 if ((!cur->ino) && cur->size >=
size) {
134 if ((((cur->length +
sizeof(
struct ext2_dentry) + 3) & ~3) +
size) <= cur->size) {
139 cur = (
struct ext2_dentry *) ((
char *) cur + cur->size);
152 }
else if (flag == 2) {
154 size_t new_size = (cur->length +
sizeof(
struct ext2_dentry) + 3) & ~3;
158 next->
size = cur->size - new_size;
163 cur->size = new_size;
179 dir_inode.
size += bs;
int ext2_dentry_create(struct vnode *dir, const char *name, ino_t ino, mode_t mode)
Adds an entry to a directory.
int ext2_dentry_find(struct ext2 *desc, struct ext2_inode *inode, const char *name, ino_t *ino)
Finds the inode number of a name in a directory.
static uint8_t ext2_dentry_type(mode_t mode)
Returns the directory entry type of a file's mode.
#define EXT2_DENTRY_TYPE_SCKT
#define EXT2_DENTRY_TYPE_SLINK
#define EXT2_DENTRY_TYPE_BAD
#define EXT2_DENTRY_TYPE_RGL
#define EXT2_DENTRY_TYPE_BLK
#define EXT2_DENTRY_TYPE_FIFO
int ext2_inode_read(struct ext2 *desc, ino_t inode, struct ext2_inode *ref)
Reads an inode from the disk.
int ext2_inode_block_read(struct ext2 *desc, struct ext2_inode *inode, size_t idx, void *buf)
Reads a block of a file.
#define EXT2_DENTRY_TYPE_DIR
int ext2_inode_write(struct ext2 *desc, ino_t inode, struct ext2_inode *i)
Writes an inode to the disk.
#define EXT2_DENTRY_TYPE_CHR
int ext2_inode_block_write(struct ext2 *desc, struct ext2_inode *inode, uint32_t inode_nr, size_t idx, void *buf)
Writes a block of a file, allocating it and the indirect blocks above it if they don't exist yet.
void * kmalloc(size_t size, struct malloc_type *type, int flags)
Allocates memory for one of the kernel's structures.
void kfree(void *)
Frees an object that kmalloc() gave.
int memcmp(const void *a, const void *b, size_t n)
Compares n bytes.
void * memset(void *dst, int c, size_t n)
Sets n bytes to c.
void * memcpy(void *dst, const void *src, size_t n)
Copies n bytes; dst and src must not overlap.
A directory entry, as it is on the disk.
uint16_t size
entry total size
uint8_t name[0]
the name follows (not NUL-terminated)
uint8_t length
name length
An inode, as it is on the disk.
A mounted ext2 filesystem.
int filetype
directory entries have their file's type (EXT2_INCOMPAT_FILETYPE); without it, the byte is 0
A file in memory (a vnode): what its inode says, and the kernel's own state.
void * p
the filesystem's own data