Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fdc7d5ce5c | |||
| be701fdd0b | |||
| 171ea49050 |
10 changed files with 57 additions and 17 deletions
|
|
@ -16,7 +16,7 @@ static ssize_t read(inode_t *inode, char *buf, size_t size, size_t offset)
|
||||||
return -ENOSYS;
|
return -ENOSYS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t write(inode_t *inode, char *buf, size_t size, size_t offset)
|
static ssize_t write(inode_t *inode, const char *buf, size_t size, size_t offset)
|
||||||
{
|
{
|
||||||
return -ENOSYS;
|
return -ENOSYS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ static ssize_t i_read_chr(inode_t *inode, char *buf, size_t size, size_t offset)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t i_write_chr(inode_t *inode, char *buf, size_t size, size_t offset)
|
static ssize_t i_write_chr(inode_t *inode, const char *buf, size_t size, size_t offset)
|
||||||
{
|
{
|
||||||
for (size_t i = offset; i < size + offset; i++)
|
for (size_t i = offset; i < size + offset; i++)
|
||||||
tty_putchar(inode->data, buf[offset + i]);
|
tty_putchar(inode->data, buf[offset + i]);
|
||||||
|
|
@ -31,7 +31,7 @@ static ssize_t i_read_blk(inode_t *inode, char *buf, size_t n_blocks, size_t off
|
||||||
return block_read(inode->data, buf, offset, n_blocks);
|
return block_read(inode->data, buf, offset, n_blocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t i_write_blk(inode_t *inode, char *buf, size_t n_blocks, size_t offset)
|
static ssize_t i_write_blk(inode_t *inode, const char *buf, size_t n_blocks, size_t offset)
|
||||||
{
|
{
|
||||||
return block_write(inode->data, buf, offset, n_blocks);
|
return block_write(inode->data, buf, offset, n_blocks);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ static ssize_t read(inode_t *inode, char *buf, size_t size, size_t offset)
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t write(inode_t *inode, char *buf, size_t size, size_t offset)
|
static ssize_t write(inode_t *inode, const char *buf, size_t size, size_t offset)
|
||||||
{
|
{
|
||||||
size_t new_size = size + offset;
|
size_t new_size = size + offset;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,24 +6,64 @@
|
||||||
#include <lib/errno.h>
|
#include <lib/errno.h>
|
||||||
#include <lib/string.h>
|
#include <lib/string.h>
|
||||||
|
|
||||||
|
static struct file *check_fd(int fd)
|
||||||
|
{
|
||||||
|
struct proc *proc = get_cur_proc();
|
||||||
|
|
||||||
|
if (fd >= proc->fd_array_size)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
struct file *f = proc->fdt + fd;
|
||||||
|
if (!f->dirent)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
static ssize_t do_read(dirent_t *dirent, void *buf, size_t nbyte, off_t offset)
|
||||||
|
{
|
||||||
|
return vfs_read(dirent->inode, buf, nbyte, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
static ssize_t do_write(dirent_t *dirent, const void *buf, size_t nbyte, off_t offset)
|
||||||
|
{
|
||||||
|
return vfs_write(dirent->inode, buf, nbyte, offset);
|
||||||
|
}
|
||||||
|
|
||||||
static ssize_t sys_pread(int fd, void *buf, size_t nbyte, off_t offset)
|
static ssize_t sys_pread(int fd, void *buf, size_t nbyte, off_t offset)
|
||||||
{
|
{
|
||||||
return -ENOSYS;
|
struct file *f = check_fd(fd);
|
||||||
|
if (!f)
|
||||||
|
return -EBADF;
|
||||||
|
|
||||||
|
return do_read(f->dirent, buf, nbyte, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t sys_read(int fd, void *buf, size_t nbyte)
|
static ssize_t sys_read(int fd, void *buf, size_t nbyte)
|
||||||
{
|
{
|
||||||
return -ENOSYS;
|
struct file *f = check_fd(fd);
|
||||||
|
if (!f)
|
||||||
|
return -EBADF;
|
||||||
|
|
||||||
|
return do_read(f->dirent, buf, nbyte, f->offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t sys_pwrite(int fd, const void *buf, size_t nbyte, off_t offset)
|
static ssize_t sys_pwrite(int fd, const void *buf, size_t nbyte, off_t offset)
|
||||||
{
|
{
|
||||||
return -ENOSYS;
|
struct file *f = check_fd(fd);
|
||||||
|
if (!f)
|
||||||
|
return -EBADF;
|
||||||
|
|
||||||
|
return do_write(f->dirent, buf, nbyte, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t sys_write(int fd, const void *buf, size_t nbyte)
|
static ssize_t sys_write(int fd, const void *buf, size_t nbyte)
|
||||||
{
|
{
|
||||||
return -ENOSYS;
|
struct file *f = check_fd(fd);
|
||||||
|
if (!f)
|
||||||
|
return -EBADF;
|
||||||
|
|
||||||
|
return do_write(f->dirent, buf, nbyte, f->offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sys_open(const char *path, int flags)
|
static int sys_open(const char *path, int flags)
|
||||||
|
|
|
||||||
|
|
@ -199,7 +199,7 @@ int vfs_readdir(dirent_t *dir, struct dir_context *ctx, dirent_t **out)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t vfs_write(inode_t *ino, char *buf, size_t size, size_t offset)
|
ssize_t vfs_write(inode_t *ino, const char *buf, size_t size, size_t offset)
|
||||||
{
|
{
|
||||||
if (!ino)
|
if (!ino)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ typedef struct _fs fs_t;
|
||||||
|
|
||||||
struct inode_ops {
|
struct inode_ops {
|
||||||
ssize_t (*read)(inode_t *inode, char *buf, size_t size, size_t offset);
|
ssize_t (*read)(inode_t *inode, char *buf, size_t size, size_t offset);
|
||||||
ssize_t (*write)(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 (*link)(inode_t *parent_dir, inode_t *child, const char *name, dirent_t **out);
|
||||||
int (*unlink)(inode_t *parent_dir, const char *name);
|
int (*unlink)(inode_t *parent_dir, const char *name);
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,7 @@ fs_t *vfs_get_root(void);
|
||||||
struct mount *vfs_get_root_mount(void);
|
struct mount *vfs_get_root_mount(void);
|
||||||
struct mount *mount_find_child(struct mount *parent, dirent_t *dent);
|
struct mount *mount_find_child(struct mount *parent, dirent_t *dent);
|
||||||
|
|
||||||
ssize_t vfs_write(inode_t *ino, char *buf, size_t size, size_t offset);
|
ssize_t vfs_write(inode_t *ino, const char *buf, size_t size, size_t offset);
|
||||||
ssize_t vfs_read(inode_t *ino, char *buf, size_t size, size_t offset);
|
ssize_t vfs_read(inode_t *ino, char *buf, size_t size, size_t offset);
|
||||||
|
|
||||||
#endif /* _VFS_H_ */
|
#endif /* _VFS_H_ */
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ struct block_device {
|
||||||
};
|
};
|
||||||
|
|
||||||
ssize_t block_read(struct block_device *dev, char *buf, size_t offset, size_t n_blocks);
|
ssize_t block_read(struct block_device *dev, char *buf, size_t offset, size_t n_blocks);
|
||||||
ssize_t block_write(struct block_device *dev, char *buf, size_t offset, size_t n_blocks);
|
ssize_t block_write(struct block_device *dev, const char *buf, size_t offset, size_t n_blocks);
|
||||||
|
|
||||||
int block_check_partitions(struct block_device *bdev);
|
int block_check_partitions(struct block_device *bdev);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,6 @@
|
||||||
|
|
||||||
#include <kernel/types.h>
|
#include <kernel/types.h>
|
||||||
|
|
||||||
void cache_flush_range(void *addr, size_t len);
|
void cache_flush_range(const void *addr, size_t len);
|
||||||
|
|
||||||
#endif /* _CACHE_H */
|
#endif /* _CACHE_H */
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ ssize_t block_read(struct block_device *dev, char *buf, size_t offset, size_t n_
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t block_write(struct block_device *dev, char *buf, size_t offset, size_t n_blocks)
|
ssize_t block_write(struct block_device *dev, const char *buf, size_t offset, size_t n_blocks)
|
||||||
{
|
{
|
||||||
while (dev->part_of) {
|
while (dev->part_of) {
|
||||||
offset += dev->lba_start;
|
offset += dev->lba_start;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue