xref: /nrf52832-nimble/rt-thread/components/dfs/include/dfs_file.h (revision 104654410c56c573564690304ae786df310c91fc)
1 /*
2  * Copyright (c) 2006-2018, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2005-01-26     Bernard      The first version.
9  */
10 
11 #ifndef __DFS_FILE_H__
12 #define __DFS_FILE_H__
13 
14 #include <dfs.h>
15 #include <dfs_fs.h>
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 struct rt_pollreq;
22 
23 struct dfs_file_ops
24 {
25     int (*open)     (struct dfs_fd *fd);
26     int (*close)    (struct dfs_fd *fd);
27     int (*ioctl)    (struct dfs_fd *fd, int cmd, void *args);
28     int (*read)     (struct dfs_fd *fd, void *buf, size_t count);
29     int (*write)    (struct dfs_fd *fd, const void *buf, size_t count);
30     int (*flush)    (struct dfs_fd *fd);
31     int (*lseek)    (struct dfs_fd *fd, off_t offset);
32     int (*getdents) (struct dfs_fd *fd, struct dirent *dirp, uint32_t count);
33 
34     int (*poll)     (struct dfs_fd *fd, struct rt_pollreq *req);
35 };
36 
37 /* file descriptor */
38 #define DFS_FD_MAGIC     0xfdfd
39 struct dfs_fd
40 {
41     uint16_t magic;              /* file descriptor magic number */
42     uint16_t type;               /* Type (regular or socket) */
43 
44     char *path;                  /* Name (below mount point) */
45     int ref_count;               /* Descriptor reference count */
46 
47     struct dfs_filesystem *fs;
48     const struct dfs_file_ops *fops;
49 
50     uint32_t flags;              /* Descriptor flags */
51     size_t   size;               /* Size in bytes */
52     off_t    pos;                /* Current file position */
53 
54     void *data;                  /* Specific file system data */
55 };
56 
57 int dfs_file_open(struct dfs_fd *fd, const char *path, int flags);
58 int dfs_file_close(struct dfs_fd *fd);
59 int dfs_file_ioctl(struct dfs_fd *fd, int cmd, void *args);
60 int dfs_file_read(struct dfs_fd *fd, void *buf, size_t len);
61 int dfs_file_getdents(struct dfs_fd *fd, struct dirent *dirp, size_t nbytes);
62 int dfs_file_unlink(const char *path);
63 int dfs_file_write(struct dfs_fd *fd, const void *buf, size_t len);
64 int dfs_file_flush(struct dfs_fd *fd);
65 int dfs_file_lseek(struct dfs_fd *fd, off_t offset);
66 
67 int dfs_file_stat(const char *path, struct stat *buf);
68 int dfs_file_rename(const char *oldpath, const char *newpath);
69 
70 #ifdef __cplusplus
71 }
72 #endif
73 
74 #endif
75