2011-10-08 22:50:08 +08:00
|
|
|
/*
|
|
|
|
* File : dfs_fs.h
|
|
|
|
* This file is part of Device File System in RT-Thread RTOS
|
2012-12-26 09:12:13 +08:00
|
|
|
* COPYRIGHT (C) 2004-2012, RT-Thread Development Team
|
2011-10-08 22:50:08 +08:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2011-12-23 10:11:55 +08:00
|
|
|
|
2011-10-08 22:50:08 +08:00
|
|
|
#ifndef __DFS_FS_H__
|
|
|
|
#define __DFS_FS_H__
|
|
|
|
|
|
|
|
#include <dfs_def.h>
|
|
|
|
|
2012-12-26 09:12:13 +08:00
|
|
|
#define DFS_FS_FLAG_DEFAULT 0x00 /* default flag */
|
|
|
|
#define DFS_FS_FLAG_FULLPATH 0x01 /* set full path to underlaying file system */
|
2012-01-01 21:37:21 +08:00
|
|
|
|
2011-10-08 22:50:08 +08:00
|
|
|
/* Pre-declaration */
|
|
|
|
struct dfs_filesystem;
|
|
|
|
struct dfs_fd;
|
|
|
|
|
|
|
|
/* File system operations struct */
|
|
|
|
struct dfs_filesystem_operation
|
|
|
|
{
|
2012-12-26 09:12:13 +08:00
|
|
|
char *name;
|
|
|
|
rt_uint32_t flags; /* flags for file system operations */
|
|
|
|
|
|
|
|
/* mount and unmount file system */
|
|
|
|
int (*mount) (struct dfs_filesystem *fs, unsigned long rwflag, const void *data);
|
|
|
|
int (*unmount) (struct dfs_filesystem *fs);
|
|
|
|
|
|
|
|
/* make a file system */
|
2013-01-08 18:58:45 +08:00
|
|
|
int (*mkfs) (rt_device_t devid);
|
2012-12-26 09:12:13 +08:00
|
|
|
int (*statfs) (struct dfs_filesystem *fs, struct statfs *buf);
|
|
|
|
|
|
|
|
int (*open) (struct dfs_fd *fd);
|
|
|
|
int (*close) (struct dfs_fd *fd);
|
|
|
|
int (*ioctl) (struct dfs_fd *fd, int cmd, void *args);
|
|
|
|
int (*read) (struct dfs_fd *fd, void *buf, rt_size_t count);
|
|
|
|
int (*write) (struct dfs_fd *fd, const void *buf, rt_size_t count);
|
|
|
|
int (*flush) (struct dfs_fd *fd);
|
|
|
|
int (*lseek) (struct dfs_fd *fd, rt_off_t offset);
|
|
|
|
int (*getdents) (struct dfs_fd *fd, struct dirent *dirp, rt_uint32_t count);
|
|
|
|
|
|
|
|
int (*unlink) (struct dfs_filesystem *fs, const char *pathname);
|
|
|
|
int (*stat) (struct dfs_filesystem *fs, const char *filename, struct stat *buf);
|
|
|
|
int (*rename) (struct dfs_filesystem *fs, const char *oldpath, const char *newpath);
|
2011-10-08 22:50:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Mounted file system */
|
|
|
|
struct dfs_filesystem
|
|
|
|
{
|
2012-12-26 09:12:13 +08:00
|
|
|
rt_device_t dev_id; /* Attached device */
|
2011-10-08 22:50:08 +08:00
|
|
|
|
2012-12-26 09:12:13 +08:00
|
|
|
char *path; /* File system mount point */
|
|
|
|
const struct dfs_filesystem_operation *ops; /* Operations for file system type */
|
2011-10-08 22:50:08 +08:00
|
|
|
|
2012-12-26 09:12:13 +08:00
|
|
|
void *data; /* Specific file system data */
|
2011-10-08 22:50:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* file system partition table */
|
|
|
|
struct dfs_partition
|
|
|
|
{
|
2012-12-26 09:12:13 +08:00
|
|
|
rt_uint8_t type; /* file system type */
|
|
|
|
rt_off_t offset; /* partition start offset */
|
|
|
|
rt_size_t size; /* partition size */
|
|
|
|
rt_sem_t lock;
|
2011-10-08 22:50:08 +08:00
|
|
|
};
|
|
|
|
|
2011-12-23 10:11:55 +08:00
|
|
|
int dfs_register(const struct dfs_filesystem_operation *ops);
|
|
|
|
struct dfs_filesystem *dfs_filesystem_lookup(const char *path);
|
2012-12-26 09:12:13 +08:00
|
|
|
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);
|
2011-10-08 22:50:08 +08:00
|
|
|
int dfs_unmount(const char *specialfile);
|
|
|
|
|
|
|
|
/* extern variable */
|
2011-12-23 10:11:55 +08:00
|
|
|
extern const struct dfs_filesystem_operation *filesystem_operation_table[];
|
2011-10-08 22:50:08 +08:00
|
|
|
extern struct dfs_filesystem filesystem_table[];
|
|
|
|
|
|
|
|
extern char working_directory[];
|
|
|
|
|
|
|
|
void dfs_lock(void);
|
|
|
|
void dfs_unlock(void);
|
2013-05-17 20:03:24 +08:00
|
|
|
int dfs_mkfs(const char *fs_name, const char *device_name);
|
2011-12-23 10:11:55 +08:00
|
|
|
int dfs_statfs(const char *path, struct statfs *buffer);
|
2011-10-08 22:50:08 +08:00
|
|
|
|
|
|
|
#endif
|