2009-07-03 06:48:23 +08:00
|
|
|
/*
|
2010-07-19 00:15:53 +08:00
|
|
|
* File : dfs_fs.h
|
|
|
|
* This file is part of Device File System in RT-Thread RTOS
|
|
|
|
* COPYRIGHT (C) 2004-2010, RT-Thread Development Team
|
|
|
|
*
|
|
|
|
* The license and distribution terms for this file may be
|
|
|
|
* found in the file LICENSE in this distribution or at
|
|
|
|
* http://www.rt-thread.org/license/LICENSE.
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2005-02-22 Bernard The first version.
|
|
|
|
*/
|
2009-07-03 06:48:23 +08:00
|
|
|
#ifndef __DFS_FS_H__
|
|
|
|
#define __DFS_FS_H__
|
|
|
|
|
|
|
|
#include <dfs_def.h>
|
|
|
|
|
|
|
|
/* Pre-declaration */
|
|
|
|
struct dfs_filesystem;
|
|
|
|
struct dfs_fd;
|
|
|
|
|
|
|
|
/* File system operations struct */
|
|
|
|
struct dfs_filesystem_operation
|
|
|
|
{
|
2010-07-19 00:15:53 +08:00
|
|
|
char *name;
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2010-07-19 00:15:53 +08:00
|
|
|
/* mount and unmount file system */
|
2010-04-22 17:33:25 +08:00
|
|
|
int (*mount) (struct dfs_filesystem* fs, unsigned long rwflag, const void* data);
|
2009-07-03 06:48:23 +08:00
|
|
|
int (*unmount) (struct dfs_filesystem* fs);
|
|
|
|
|
2010-07-19 00:15:53 +08:00
|
|
|
/* make a file system */
|
|
|
|
int (*mkfs) (const char* device_name);
|
2010-10-19 16:18:24 +08:00
|
|
|
int (*statfs) (struct dfs_filesystem* fs, struct statfs *buf);
|
2010-07-19 00:15:53 +08:00
|
|
|
|
|
|
|
int (*open) (struct dfs_fd* fd);
|
2009-07-03 06:48:23 +08:00
|
|
|
int (*close) (struct dfs_fd* fd);
|
|
|
|
int (*ioctl) (struct dfs_fd* fd, int cmd, void *args);
|
2010-07-19 00:15:53 +08:00
|
|
|
int (*read) (struct dfs_fd* fd, void* buf, rt_size_t count);
|
2009-07-03 06:48:23 +08:00
|
|
|
int (*write) (struct dfs_fd* fd, const void* buf, rt_size_t count);
|
2010-07-19 00:15:53 +08:00
|
|
|
int (*flush) (struct dfs_fd* fd);
|
2009-07-03 06:48:23 +08:00
|
|
|
int (*lseek) (struct dfs_fd* fd, rt_off_t offset);
|
2010-10-19 16:18:24 +08:00
|
|
|
int (*getdents) (struct dfs_fd* fd, struct dirent* dirp, rt_uint32_t count);
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
int (*unlink) (struct dfs_filesystem* fs, const char* pathname);
|
2010-10-19 16:18:24 +08:00
|
|
|
int (*stat) (struct dfs_filesystem* fs, const char* filename, struct stat* buf);
|
2009-07-03 06:48:23 +08:00
|
|
|
int (*rename) (struct dfs_filesystem* fs, const char* oldpath, const char* newpath);
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Mounted file system */
|
|
|
|
struct dfs_filesystem
|
|
|
|
{
|
2010-07-19 00:15:53 +08:00
|
|
|
rt_device_t dev_id; /* Attached device */
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2010-07-19 00:15:53 +08:00
|
|
|
char* path; /* File system mount point */
|
|
|
|
const struct dfs_filesystem_operation* ops; /* Operations for file system type */
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2010-07-19 00:15:53 +08:00
|
|
|
void *data; /* Specific file system data */
|
2009-07-03 06:48:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* file system partition table */
|
|
|
|
struct dfs_partition
|
|
|
|
{
|
|
|
|
rt_uint8_t type; /* file system type */
|
|
|
|
rt_off_t offset; /* partition start offset */
|
|
|
|
rt_size_t size; /* partition size */
|
|
|
|
rt_sem_t lock;
|
|
|
|
};
|
|
|
|
|
2010-07-19 00:15:53 +08:00
|
|
|
int dfs_register(const struct dfs_filesystem_operation* ops);
|
2009-07-03 06:48:23 +08:00
|
|
|
struct dfs_filesystem* dfs_filesystem_lookup(const char *path);
|
|
|
|
rt_err_t dfs_filesystem_get_partition(struct dfs_partition* part, rt_uint8_t* buf, rt_uint32_t pindex);
|
|
|
|
|
|
|
|
int dfs_mount(const char* device_name, const char* path,
|
|
|
|
const char* filesystemtype, rt_uint32_t rwflag, const
|
|
|
|
void* data);
|
|
|
|
int dfs_unmount(const char *specialfile);
|
|
|
|
|
|
|
|
/* extern variable */
|
2010-07-19 00:15:53 +08:00
|
|
|
extern const struct dfs_filesystem_operation* filesystem_operation_table[];
|
2009-07-03 06:48:23 +08:00
|
|
|
extern struct dfs_filesystem filesystem_table[];
|
|
|
|
|
|
|
|
extern char working_directory[];
|
2009-10-26 07:24:51 +08:00
|
|
|
|
|
|
|
void dfs_lock(void);
|
|
|
|
void dfs_unlock(void);
|
2010-10-19 16:18:24 +08:00
|
|
|
int dfs_statfs(const char* path, struct statfs* buffer);
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
#endif
|