2011-10-08 22:50:08 +08:00
|
|
|
/*
|
2012-12-26 09:12:13 +08:00
|
|
|
* File : dfs_file.h
|
2011-12-23 10:11:55 +08:00
|
|
|
* 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-12-23 10:11:55 +08:00
|
|
|
*
|
2013-06-26 22:30:40 +08:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2011-12-23 10:11:55 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2005-01-26 Bernard The first version.
|
|
|
|
*/
|
2011-10-08 22:50:08 +08:00
|
|
|
|
2012-12-26 09:12:13 +08:00
|
|
|
#ifndef __DFS_FILE_H__
|
|
|
|
#define __DFS_FILE_H__
|
2011-10-08 22:50:08 +08:00
|
|
|
|
|
|
|
#include <dfs.h>
|
|
|
|
#include <dfs_fs.h>
|
|
|
|
|
2017-10-15 22:44:53 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct rt_pollreq;
|
|
|
|
|
|
|
|
struct dfs_file_ops
|
|
|
|
{
|
|
|
|
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, size_t count);
|
|
|
|
int (*write) (struct dfs_fd *fd, const void *buf, size_t count);
|
|
|
|
int (*flush) (struct dfs_fd *fd);
|
|
|
|
int (*lseek) (struct dfs_fd *fd, off_t offset);
|
|
|
|
int (*getdents) (struct dfs_fd *fd, struct dirent *dirp, uint32_t count);
|
|
|
|
|
|
|
|
int (*poll) (struct dfs_fd *fd, struct rt_pollreq *req);
|
|
|
|
};
|
|
|
|
|
|
|
|
/* file descriptor */
|
|
|
|
#define DFS_FD_MAGIC 0xfdfd
|
|
|
|
struct dfs_fd
|
|
|
|
{
|
|
|
|
uint16_t magic; /* file descriptor magic number */
|
|
|
|
uint16_t type; /* Type (regular or socket) */
|
|
|
|
|
|
|
|
char *path; /* Name (below mount point) */
|
|
|
|
int ref_count; /* Descriptor reference count */
|
|
|
|
|
|
|
|
const struct dfs_file_ops *fops;
|
|
|
|
|
|
|
|
uint32_t flags; /* Descriptor flags */
|
|
|
|
size_t size; /* Size in bytes */
|
|
|
|
off_t pos; /* Current file position */
|
|
|
|
|
|
|
|
void *data; /* Specific file system data */
|
|
|
|
};
|
|
|
|
|
2011-12-23 10:11:55 +08:00
|
|
|
int dfs_file_open(struct dfs_fd *fd, const char *path, int flags);
|
|
|
|
int dfs_file_close(struct dfs_fd *fd);
|
|
|
|
int dfs_file_ioctl(struct dfs_fd *fd, int cmd, void *args);
|
2017-10-15 22:44:53 +08:00
|
|
|
int dfs_file_read(struct dfs_fd *fd, void *buf, size_t len);
|
|
|
|
int dfs_file_getdents(struct dfs_fd *fd, struct dirent *dirp, size_t nbytes);
|
2011-10-08 22:50:08 +08:00
|
|
|
int dfs_file_unlink(const char *path);
|
2017-10-15 22:44:53 +08:00
|
|
|
int dfs_file_write(struct dfs_fd *fd, const void *buf, size_t len);
|
2013-10-11 14:55:23 +08:00
|
|
|
int dfs_file_flush(struct dfs_fd *fd);
|
2017-10-15 22:44:53 +08:00
|
|
|
int dfs_file_lseek(struct dfs_fd *fd, off_t offset);
|
|
|
|
|
2011-10-08 22:50:08 +08:00
|
|
|
int dfs_file_stat(const char *path, struct stat *buf);
|
2011-12-23 10:11:55 +08:00
|
|
|
int dfs_file_rename(const char *oldpath, const char *newpath);
|
2011-10-08 22:50:08 +08:00
|
|
|
|
2017-10-15 22:44:53 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
2011-10-08 22:50:08 +08:00
|
|
|
#endif
|
|
|
|
|
2017-10-15 22:44:53 +08:00
|
|
|
#endif
|