2006-04-26 16:39:16 +00:00
|
|
|
#include "openbios/config.h"
|
2010-03-14 14:21:02 +00:00
|
|
|
#include "kernel/kernel.h"
|
2006-04-26 16:39:16 +00:00
|
|
|
#include "libc/diskio.h"
|
|
|
|
|
#include "loadfs.h"
|
|
|
|
|
|
|
|
|
|
static int load_fd=-1;
|
|
|
|
|
|
|
|
|
|
int file_open(const char *filename)
|
|
|
|
|
{
|
|
|
|
|
load_fd=open_io(filename);
|
2006-05-22 10:33:31 +00:00
|
|
|
if(load_fd >= 0)
|
|
|
|
|
seek_io(load_fd, 0);
|
2006-04-26 16:39:16 +00:00
|
|
|
return load_fd>-1;
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-05 19:40:05 +00:00
|
|
|
void file_close(void)
|
|
|
|
|
{
|
2008-07-07 18:35:51 +00:00
|
|
|
if(load_fd==-1)
|
2006-06-05 19:40:05 +00:00
|
|
|
return;
|
2008-12-11 20:30:53 +00:00
|
|
|
|
2006-06-05 19:40:05 +00:00
|
|
|
close_io(load_fd);
|
|
|
|
|
load_fd=-1;
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-26 16:39:16 +00:00
|
|
|
int lfile_read(void *buf, unsigned long len)
|
|
|
|
|
{
|
2006-05-22 10:33:31 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
|
|
if (load_fd >= 0)
|
|
|
|
|
ret=read_io(load_fd, buf, len);
|
2006-04-26 16:39:16 +00:00
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int file_seek(unsigned long offset)
|
|
|
|
|
{
|
2006-05-22 10:33:31 +00:00
|
|
|
if (load_fd >= 0)
|
|
|
|
|
return seek_io(load_fd, offset);
|
|
|
|
|
else
|
|
|
|
|
return -1;
|
2006-04-26 16:39:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned long file_size(void)
|
|
|
|
|
{
|
|
|
|
|
llong fpos, fsize;
|
2008-12-11 20:30:53 +00:00
|
|
|
|
2006-05-22 10:33:31 +00:00
|
|
|
if (load_fd < 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2006-04-26 16:39:16 +00:00
|
|
|
/* save current position */
|
|
|
|
|
fpos=tell(load_fd);
|
|
|
|
|
|
|
|
|
|
/* go to end of file and get position */
|
|
|
|
|
seek_io(load_fd, -1);
|
|
|
|
|
fsize=tell(load_fd);
|
2008-12-11 20:30:53 +00:00
|
|
|
|
2006-04-26 16:39:16 +00:00
|
|
|
/* go back to old position */
|
|
|
|
|
seek_io(load_fd, 0);
|
|
|
|
|
seek_io(load_fd, fpos);
|
2008-12-11 20:30:53 +00:00
|
|
|
|
2006-04-26 16:39:16 +00:00
|
|
|
return fsize;
|
|
|
|
|
}
|