dfs_fs.h 2.8 KB
Newer Older
1
/*
2 3 4 5 6 7 8 9 10 11 12 13
 * 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.
 */
14 15 16 17 18 19 20 21 22 23 24 25
#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
{
26
	char *name;
27

28
	/* mount and unmount file system */
29
	int (*mount)	(struct dfs_filesystem* fs, unsigned long rwflag, const void* data);
30 31
	int (*unmount)	(struct dfs_filesystem* fs);

32 33
	/* make a file system */
	int (*mkfs)     (const char* device_name);
34
	int (*statfs)   (struct dfs_filesystem* fs, struct statfs *buf);
35 36

	int (*open)		(struct dfs_fd* fd);
37 38
	int (*close)	(struct dfs_fd* fd);
	int (*ioctl)	(struct dfs_fd* fd, int cmd, void *args);
39
	int (*read)		(struct dfs_fd* fd, void* buf, rt_size_t count);
40
	int (*write)	(struct dfs_fd* fd, const void* buf, rt_size_t count);
41
	int (*flush)    (struct dfs_fd* fd);
42
	int (*lseek)	(struct dfs_fd* fd, rt_off_t offset);
43
	int (*getdents)	(struct dfs_fd* fd, struct dirent* dirp, rt_uint32_t count);
44 45

	int (*unlink)	(struct dfs_filesystem* fs, const char* pathname);
46
	int (*stat)		(struct dfs_filesystem* fs, const char* filename, struct stat* buf);
47 48 49 50 51 52
	int (*rename)	(struct dfs_filesystem* fs, const char* oldpath, const char* newpath);
};

/* Mounted file system */
struct dfs_filesystem
{
53
	rt_device_t dev_id;		/* Attached device */
54

55 56
	char* path;				/* File system mount point */
	const struct dfs_filesystem_operation* ops;	/* Operations for file system type */
57

58
	void *data;				/* Specific file system data */
59 60 61 62 63 64 65 66 67 68 69
};

/* 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;	
};

70
int dfs_register(const struct dfs_filesystem_operation* ops);
71 72 73 74 75 76 77 78 79
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 */
80
extern const struct dfs_filesystem_operation* filesystem_operation_table[];
81 82 83
extern struct dfs_filesystem filesystem_table[];

extern char working_directory[];
84 85 86

void dfs_lock(void);
void dfs_unlock(void);
87
int dfs_statfs(const char* path, struct statfs* buffer);
88 89

#endif