#include "boot.h"
#include "pathfs.h"
#include "unixdev.h"
#include "compat_linux.h"
__compactcall int
pathfs_open(const char *path, struct open_file *fd)
{
if (strcmp(fd->f_dev->dv_name, "path"))
return EINVAL;
(void) ulseek((int)fd->f_devdata, 0L, SEEK_SET);
return 0;
}
__compactcall int
pathfs_read(struct open_file *fd, void *vbuf, size_t nbyte, size_t *resid)
{
char *buf = vbuf;
size_t off = 0;
ssize_t rsz;
while (off < nbyte) {
rsz = uread((int)fd->f_devdata, buf + off, nbyte - off);
if (rsz < 0)
return errno;
if (rsz == 0)
break;
off += rsz;
}
*resid -= off;
return 0;
}
__compactcall int
pathfs_write(struct open_file *fd, void *vbuf, size_t size, size_t *resid)
{
return EROFS;
}
__compactcall off_t
pathfs_seek(struct open_file *fd, off_t offset, int whence)
{
return ulseek((int)fd->f_devdata, offset, whence);
}
__compactcall int
pathfs_close(struct open_file *fd)
{
return 0;
}
__compactcall int
pathfs_stat(struct open_file *fd, struct stat *sb)
{
struct linux_stat lsb;
int rv;
rv = ufstat((int)fd->f_devdata, &lsb);
if (rv < 0)
return errno;
sb->st_ino = lsb.lst_ino;
sb->st_mode = lsb.lst_mode;
sb->st_nlink = lsb.lst_nlink;
sb->st_uid = lsb.lst_uid;
sb->st_gid = lsb.lst_gid;
sb->st_size = lsb.lst_size;
sb->st_blksize = lsb.lst_blksize;
sb->st_blocks = lsb.lst_blocks;
sb->st_atime = lsb.lst_atime;
sb->st_mtime = lsb.lst_mtime;
sb->st_ctime = lsb.lst_ctime;
return 0;
}
__compactcall void
pathfs_ls(struct open_file *f, const char *pattern)
{
printf("Currently ls command is unsupported by pathfs.\n");
}