/**
 * fs_stub.h: TOYX stub filesystem.
 * Eric Cronin <ecronin@cis.upenn.edu>
 * $Id: fs_stub.h 36 2006-10-12 22:04:57Z ecronin $
 *
 * This provides a stub implementation of the f_*() TOYX calls which
 * pass through to the Linux filesystem (chroot()'d to the directory
 * passed to mount().  Please see below for implementation-dependent
 * features.
 *
 * The goal of this stub is to allow the required user-land tools such
 * as ls, rm, mkdir, rmdir, cd, cat, more, wc, etc. to be built and
 * tested before your FAT filesystem is stable.  It is not perfect in
 * this regard, as some filesystem-specific details must be expressed
 * in the form of structures and flags passed to these calls.
 * However, our hope is that by using this implementation you can get
 * a leg up.
 * 
 * Things that may need changing:
 *
 *  - recursive mounts are disallowed
 *  - global errno error numbers are used
 *  - struct f_stat is empty in the stub implementation
 *  - type and flags of f_mode_t
 *  - type F_DIR is just a Linux DIR
 *  - struct f_dirent is minimal
 */

#ifndef __fs_stub_h__
#define __fs_stub_h__

#include <sys/types.h>
#include <dirent.h>

/**
 * Filesystem-specific information about a file.
 */
struct f_stat {
  char empty;
};

/** Directory Pointer */
typedef DIR F_DIR;

/**
 * Directory entry for a file.
 */
struct f_dirent {
  char d_name[256];         /**< filename */
};

/** Permissions for a file/directory */
typedef unsigned int f_mode_t;

/** Flags for f_mode_t */
#define F_S_IRWXU S_IRWXU     /**< mask for file owner permissions */
#define F_S_IRUSR S_IRUSR     /**< owner has read permission */
#define F_S_IWUSR S_IWUSR     /**< owner has write permission */
#define F_S_IXUSR S_IXUSR     /**< owner has execute permission */

/** Flags for f_open() */
#define F_O_ACCMODE O_ACCMODE
#define F_O_RDONLY O_RDONLY
#define F_O_WRONLY O_WRONLY
#define F_O_RDWR O_RDWR
#define F_O_CREAT O_CREAT
#define F_O_EXCL O_EXCL
#define F_O_TRUNC O_TRUNC
#define F_O_APPEND O_APPEND


int f_open(const char *pathname, int flags, f_mode_t mode);

int f_read(int fd, void *buf, size_t count);

int f_write(int fd, const void *buf, size_t count);

int f_close(int fd);

off_t f_lseek(int fd, off_t offset);

int f_stat(const char *pathname, struct f_stat *buf);

int f_chmod(const char *pathname, f_mode_t mode);

int f_unlink(const char *pathname);

F_DIR *f_opendir(const char *pathname);

struct f_dirent *f_readdir(F_DIR *dir);

int f_closedir(F_DIR *dir);

int f_mkdir(const char *pathname, f_mode_t mode);

int f_rmdir(const char *pathname);

int f_mount(const char *source, const char *target);

int f_umount(const char *target);

#endif
