/*
 * fsbase.c: implementation of base filesystem object.
 */

#include <../source/TAL/objbase.h>
#include <../source/PAL/dataman.h>
#include <../source/vfs/iobase.h>
#include <../source/vfs/fsbase.h>
#include <../source/PAL/fsops.h>

#ifdef	CHECKED_BUILD
#define	VFS_MAGIC				0x524F4653	/* ROFS */
static char	*vfs_object			= "virtual FS";
#endif	/* CHECKED_BUILD */

V_LOCAL u32_t V_CALL
vfs_generic_destroy(vhandle_t handle)
{
	vfs_dev_p self=(vfs_dev_p)handle;
	if(--self->base.ref_count)
    	return self->base.ref_count;
	memFreeObject(self);
	return 0;
}

/*
 *	Default stub procedures.
 */
#include <../source/PAL/argsused.h>
V_LOCAL u32_t	V_CALL
vfs_get_inode_count_stub(struct vfs_dev_s *self)
{
	return 0;
}

#include <../source/PAL/argsused.h>
V_LOCAL vboolean	V_CALL
vfs_get_file_name_stub(struct vfs_dev_s *self,u32_t inode,char *name_ret)
{
	return false;
}

#include <../source/PAL/argsused.h>
V_LOCAL file_t	V_CALL
vfs_create_file_stub(struct vfs_dev_s *self,u32_t inode)
{
	/* self->base.ref_count++; */
	return NULL;
}

vfs_dev_p	V_CALL
vfsAlloc(u32_t size_of_object)
{
	vfs_dev_t *fs;
	if(size_of_object<sizeof(vfs_dev_t))
		size_of_object=sizeof(vfs_dev_t);
	ALLOC_OBJECT(fs,vfs_dev_t,size_of_object-sizeof(vfs_dev_t),VFS_MAGIC);
	fs->base.destroy=vfs_generic_destroy;
	fs->get_inode_count=vfs_get_inode_count_stub;
	fs->get_file_name=vfs_get_file_name_stub;
	fs->create_file=vfs_create_file_stub;
	return fs;
}

void	V_CALL
vfsDestroy(vhandle_t vfs_handle)
{
	libvCloseHandle(vfs_handle,"vfsDestroy",vfs_object,VFS_MAGIC);
}
