vfs: implement seek
This commit is contained in:
parent
fbc70ddf7b
commit
40d94feff4
3 changed files with 26 additions and 9 deletions
|
|
@ -406,11 +406,6 @@ int ext2_read_file(struct fs *vfs, struct file *file, void *buf, size_t offset,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ext2_seek_file(struct fs *vfs, struct file *file, size_t offset)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct fs *ext2_init_fs(struct block_device *bdev)
|
struct fs *ext2_init_fs(struct block_device *bdev)
|
||||||
{
|
{
|
||||||
struct ext2fs *extfs = kmalloc(sizeof(*extfs), ALLOC_KERN);
|
struct ext2fs *extfs = kmalloc(sizeof(*extfs), ALLOC_KERN);
|
||||||
|
|
@ -455,7 +450,6 @@ struct fs *ext2_init_fs(struct block_device *bdev)
|
||||||
.close = ext2_close_file,
|
.close = ext2_close_file,
|
||||||
.read = ext2_read_file,
|
.read = ext2_read_file,
|
||||||
.write = ext2_write_file,
|
.write = ext2_write_file,
|
||||||
.seek = ext2_seek_file,
|
|
||||||
.readdir = ext2_readdir,
|
.readdir = ext2_readdir,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
25
fs/vfs.c
25
fs/vfs.c
|
|
@ -28,7 +28,7 @@ int read(int fd, void *buf, size_t count)
|
||||||
|
|
||||||
struct file_descriptor *fdesc = (struct file_descriptor *)fdnode->value;
|
struct file_descriptor *fdesc = (struct file_descriptor *)fdnode->value;
|
||||||
|
|
||||||
if(fdesc->file.type == VFS_FILE_DIR)
|
if (fdesc->file.type == VFS_FILE_DIR)
|
||||||
return -EISDIR;
|
return -EISDIR;
|
||||||
|
|
||||||
if (fdesc->file.type != VFS_FILE_FILE)
|
if (fdesc->file.type != VFS_FILE_FILE)
|
||||||
|
|
@ -95,7 +95,28 @@ int close(int fd)
|
||||||
|
|
||||||
int seek(int fd, size_t offset, int whence)
|
int seek(int fd, size_t offset, int whence)
|
||||||
{
|
{
|
||||||
return 0;
|
struct rbnode *fdnode = rbt_search(kfd, fd);
|
||||||
|
|
||||||
|
if (!fdnode)
|
||||||
|
return -EBADF;
|
||||||
|
|
||||||
|
struct file_descriptor *fdesc = (struct file_descriptor *)fdnode->value;
|
||||||
|
|
||||||
|
switch (whence) {
|
||||||
|
case SEEK_SET:
|
||||||
|
fdesc->pos = offset;
|
||||||
|
break;
|
||||||
|
case SEEK_CUR:
|
||||||
|
fdesc->pos += offset;
|
||||||
|
break;
|
||||||
|
case SEEK_END:
|
||||||
|
fdesc->pos = fdesc->file.size + offset;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fdesc->pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
DIR *opendir(const char *name)
|
DIR *opendir(const char *name)
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,9 @@
|
||||||
#define VFS_FILE_SOCK 0x0006
|
#define VFS_FILE_SOCK 0x0006
|
||||||
#define VFS_FILE_SYMLINK 0x0007
|
#define VFS_FILE_SYMLINK 0x0007
|
||||||
|
|
||||||
|
#define SEEK_SET 0
|
||||||
|
#define SEEK_CUR 1
|
||||||
|
#define SEEK_END 2
|
||||||
|
|
||||||
struct inode {
|
struct inode {
|
||||||
uint16_t mode;
|
uint16_t mode;
|
||||||
|
|
@ -88,7 +91,6 @@ struct fs_ops {
|
||||||
int (*write)(struct fs *fs, struct file *file, void *buf, size_t offset, size_t size);
|
int (*write)(struct fs *fs, struct file *file, void *buf, size_t offset, size_t size);
|
||||||
int (*open)(struct fs *fs, struct file *file, const char *path);
|
int (*open)(struct fs *fs, struct file *file, const char *path);
|
||||||
int (*close)(struct fs *fs, struct file *file);
|
int (*close)(struct fs *fs, struct file *file);
|
||||||
int (*seek)(struct fs *fs, struct file *file, size_t offset);
|
|
||||||
int (*readdir)(struct fs *fs, uint32_t ino, struct dirent **dir);
|
int (*readdir)(struct fs *fs, uint32_t ino, struct dirent **dir);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue