74 lines
1.5 KiB
C
74 lines
1.5 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
#ifndef _INODE_H_
|
|
#define _INODE_H_
|
|
|
|
#include <kernel/types.h>
|
|
|
|
#include <lib/list.h>
|
|
#include <lib/rwlock.h>
|
|
|
|
typedef struct _inode inode_t;
|
|
typedef struct _dirent dirent_t;
|
|
typedef struct _fs fs_t;
|
|
|
|
struct inode_ops {
|
|
ssize_t (*read)(inode_t *inode, char *buf, size_t size, size_t offset);
|
|
ssize_t (*write)(inode_t *inode, const char *buf, size_t size, size_t offset);
|
|
|
|
int (*link)(inode_t *parent_dir, inode_t *child, const char *name, dirent_t **out);
|
|
int (*unlink)(inode_t *parent_dir, const char *name);
|
|
ssize_t (*get_dents)(inode_t *parent, dirent_t **dents);
|
|
};
|
|
|
|
struct _inode {
|
|
u64 mode;
|
|
u64 ino_num;
|
|
u64 file_size;
|
|
|
|
u64 flags;
|
|
|
|
void *data;
|
|
|
|
u64 refcount;
|
|
rwlock_t rwlock;
|
|
|
|
list_t dirents;
|
|
|
|
struct inode_ops i_ops;
|
|
};
|
|
|
|
struct _dirent {
|
|
fs_t *fs;
|
|
inode_t *inode;
|
|
dirent_t *parent;
|
|
|
|
u64 ino_num;
|
|
|
|
size_t rec_len;
|
|
size_t name_len;
|
|
|
|
u64 flags;
|
|
u64 type;
|
|
spinlock_t lock;
|
|
|
|
u64 refcount;
|
|
|
|
char *name;
|
|
};
|
|
|
|
dirent_t *dirent_create(const char *name);
|
|
dirent_t *dirent_dup(dirent_t *src);
|
|
void dirent_free(dirent_t *dirent);
|
|
void dirent_inc_ref(dirent_t *dent);
|
|
void dirent_dec_ref(dirent_t *dent);
|
|
|
|
int dirent_lookup(dirent_t *dir, const char *name, dirent_t **out);
|
|
int dirent_lookup_locked(dirent_t *dir, const char *name, dirent_t **out);
|
|
int dirent_populate_children(dirent_t *dir);
|
|
inode_t *inode_create(void);
|
|
void inode_free(inode_t *inode);
|
|
void inode_inc_ref(inode_t *inode);
|
|
void inode_dec_ref(inode_t *inode);
|
|
void inode_init(void);
|
|
|
|
#endif /* _INODE_H_ */
|