feat(iso): add read function
This commit is contained in:
parent
04bbb27df6
commit
b2eb2df8e9
33
k/iso.c
33
k/iso.c
@ -49,7 +49,10 @@ int open(const char *pathname, int flags)
|
|||||||
|
|
||||||
// we found the file
|
// we found the file
|
||||||
if (!length)
|
if (!length)
|
||||||
return register_fd(curr->data_blk.le, curr->data_size.le);
|
{
|
||||||
|
return register_fd(curr->data_blk.le, curr->file_size.le,
|
||||||
|
(curr->type == ISO_FILE_ISDIR));
|
||||||
|
}
|
||||||
|
|
||||||
// iteration for one directory
|
// iteration for one directory
|
||||||
while (curr->dir_size != 0)
|
while (curr->dir_size != 0)
|
||||||
@ -72,6 +75,34 @@ int open(const char *pathname, int flags)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s64 read(int fd, void *buf, size_t count)
|
||||||
|
{
|
||||||
|
if (fd > MAX_FD)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
struct file_entry *f = &fd_table[fd];
|
||||||
|
if (!f->open)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
u32 nb_block = f->file_offset / ISO_BLOCK_SIZE;
|
||||||
|
char *content = read_block(f->lba + nb_block);
|
||||||
|
|
||||||
|
size_t i = 0;
|
||||||
|
for (; i < count && f->file_offset < f->file_size; ++i)
|
||||||
|
{
|
||||||
|
((char *)buf)[i] = content[f->file_offset];
|
||||||
|
++(f->file_offset);
|
||||||
|
|
||||||
|
if (f->file_offset / ISO_BLOCK_SIZE > nb_block)
|
||||||
|
{
|
||||||
|
++nb_block;
|
||||||
|
content = read_block(f->lba + nb_block);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
int close(int fd)
|
int close(int fd)
|
||||||
{
|
{
|
||||||
return destroy_fd(fd);
|
return destroy_fd(fd);
|
||||||
|
2
k/iso.h
2
k/iso.h
@ -6,5 +6,7 @@
|
|||||||
#define O_RDONLY 0
|
#define O_RDONLY 0
|
||||||
|
|
||||||
int open(const char *path, int flags);
|
int open(const char *path, int flags);
|
||||||
|
s64 read(int fd, void *buf, size_t count);
|
||||||
|
int close(int fd);
|
||||||
|
|
||||||
#endif /* !ISO_H */
|
#endif /* !ISO_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user