1 | /* |
2 | Copyright (c) 2012, Broadcom Europe Ltd |
3 | All rights reserved. |
4 | |
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the following conditions are met: |
7 | * Redistributions of source code must retain the above copyright |
8 | notice, this list of conditions and the following disclaimer. |
9 | * Redistributions in binary form must reproduce the above copyright |
10 | notice, this list of conditions and the following disclaimer in the |
11 | documentation and/or other materials provided with the distribution. |
12 | * Neither the name of the copyright holder nor the |
13 | names of its contributors may be used to endorse or promote products |
14 | derived from this software without specific prior written permission. |
15 | |
16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY |
20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ |
27 | |
28 | #ifndef VC_VCHI_VCFILESYS_H_ |
29 | #define VC_VCHI_VCFILESYS_H_ |
30 | |
31 | #include "vchost_platform_config.h" |
32 | #include "vcfilesys_defs.h" |
33 | #include "vc_fileservice_defs.h" |
34 | #include "interface/vchi/vchi.h" |
35 | |
36 | #ifndef _DIRENT_H // This should really be in a dirent.h header to avoid conflicts |
37 | typedef struct DIR_tag DIR; |
38 | #endif // ifndef _DIRENT_H |
39 | |
40 | typedef struct { |
41 | int64_t st_size; /* total size, in bytes (off_t)*/ |
42 | uint32_t st_modtime; /* time of last modification (time_t)*/ |
43 | } FSTAT_T; |
44 | |
45 | |
46 | VCHPRE_ int VCHPOST_ vc_vchi_filesys_init (VCHI_INSTANCE_T initialise_instance, VCHI_CONNECTION_T **connections, uint32_t num_connections ); |
47 | |
48 | // Stop it to prevent the functions from trying to use it. |
49 | VCHPRE_ void VCHPOST_ vc_filesys_stop(void); |
50 | |
51 | // Return the service number (-1 if not running). |
52 | VCHPRE_ int VCHPOST_ vc_filesys_inum(void); |
53 | |
54 | // Low level file system functions equivalent to close(), lseek(), open(), read() and write() |
55 | VCHPRE_ int VCHPOST_ vc_filesys_close(int fildes); |
56 | |
57 | VCHPRE_ long VCHPOST_ vc_filesys_lseek(int fildes, long offset, int whence); |
58 | |
59 | VCHPRE_ int64_t VCHPOST_ vc_filesys_lseek64(int fildes, int64_t offset, int whence); |
60 | |
61 | VCHPRE_ int VCHPOST_ vc_filesys_open(const char *path, int vc_oflag); |
62 | |
63 | VCHPRE_ int VCHPOST_ vc_filesys_read(int fildes, void *buf, unsigned int nbyte); |
64 | |
65 | VCHPRE_ int VCHPOST_ vc_filesys_write(int fildes, const void *buf, unsigned int nbyte); |
66 | |
67 | VCHPRE_ int VCHPOST_ vc_filesys_mount(const char *device, const char *mountpoint, const char *options); |
68 | VCHPRE_ int VCHPOST_ vc_filesys_umount(const char *mountpoint); |
69 | |
70 | |
71 | // Ends a directory listing iteration |
72 | VCHPRE_ int VCHPOST_ vc_filesys_closedir(void *dhandle); |
73 | |
74 | // Formats the drive that contains the given path |
75 | VCHPRE_ int VCHPOST_ vc_filesys_format(const char *path); |
76 | |
77 | // Returns the amount of free space on the drive that contains the given path |
78 | VCHPRE_ int VCHPOST_ vc_filesys_freespace(const char *path); |
79 | VCHPRE_ int64_t VCHPOST_ vc_filesys_freespace64(const char *path); |
80 | |
81 | // Gets the attributes of the named file |
82 | VCHPRE_ int VCHPOST_ vc_filesys_get_attr(const char *path, fattributes_t *attr); |
83 | |
84 | // Get the file stat info struct for the specified file. |
85 | VCHPRE_ int VCHPOST_ vc_filesys_fstat(int filedes, FSTAT_T *buf); |
86 | |
87 | // Creates a new directory |
88 | VCHPRE_ int VCHPOST_ vc_filesys_mkdir(const char *path); |
89 | |
90 | // Starts a directory listing iteration |
91 | VCHPRE_ void * VCHPOST_ vc_filesys_opendir(const char *dirname); |
92 | |
93 | // Directory listing iterator |
94 | VCHPRE_ struct dirent * VCHPOST_ vc_filesys_readdir_r(void *dhandle, struct dirent *result); |
95 | |
96 | // Get the sum of the filesizes, and the number of files under the specified directory path. |
97 | VCHPRE_ int64_t VCHPOST_ vc_filesys_dirsize(const char *path, uint32_t *num_files, uint32_t *num_dirs); |
98 | |
99 | // Deletes a file or (empty) directory |
100 | VCHPRE_ int VCHPOST_ vc_filesys_remove(const char *path); |
101 | |
102 | // Renames a file, provided the new name is on the same file system as the old |
103 | VCHPRE_ int VCHPOST_ vc_filesys_rename(const char *oldfile, const char *newfile); |
104 | |
105 | // Resets the co-processor side file system |
106 | VCHPRE_ int VCHPOST_ vc_filesys_reset(void); |
107 | |
108 | // Sets the attributes of the named file |
109 | VCHPRE_ int VCHPOST_ vc_filesys_set_attr(const char *path, fattributes_t attr); |
110 | |
111 | // Truncates a file at its current position |
112 | VCHPRE_ int VCHPOST_ vc_filesys_setend(int fildes); |
113 | |
114 | // Returns the size of a file in bytes. |
115 | VCHPRE_ int VCHPOST_ vc_filesys_size(const char *path); |
116 | |
117 | // Checks whether there are any messages in the incoming message fifo and responds to any such messages |
118 | VCHPRE_ int VCHPOST_ vc_filesys_poll_message_fifo(void); |
119 | |
120 | // Return the event used to wait for reads. |
121 | VCHPRE_ void * VCHPOST_ vc_filesys_read_event(void); |
122 | |
123 | // Sends a command for VC01 to reset the file system |
124 | VCHPRE_ void VCHPOST_ vc_filesys_sendreset(void); |
125 | |
126 | // Return the error code of the last file system error |
127 | VCHPRE_ int VCHPOST_ vc_filesys_errno(void); |
128 | |
129 | // Invalidates any cluster chains in the FAT that are not referenced in any directory structures |
130 | VCHPRE_ void VCHPOST_ vc_filesys_scandisk(const char *path); |
131 | |
132 | // Checks whether or not a FAT filesystem is corrupt or not. If fix_errors is TRUE behaves exactly as vc_filesys_scandisk. |
133 | VCHPRE_ int VCHPOST_ vc_filesys_chkdsk(const char *path, int fix_errors); |
134 | |
135 | // Return whether a disk is writeable or not. |
136 | VCHPRE_ int VCHPOST_ vc_filesys_diskwritable(const char *path); |
137 | |
138 | // Return file system type of a disk. |
139 | VCHPRE_ int VCHPOST_ vc_filesys_fstype(const char *path); |
140 | |
141 | // Returns the toatl amount of space on the drive that contains the given path |
142 | VCHPRE_ int VCHPOST_ vc_filesys_totalspace(const char *path); |
143 | VCHPRE_ int64_t VCHPOST_ vc_filesys_totalspace64(const char *path); |
144 | |
145 | // Open disk for block level access |
146 | VCHPRE_ int VCHPOST_ vc_filesys_open_disk_raw(const char *path); |
147 | |
148 | // Close disk from block level access mode |
149 | VCHPRE_ int VCHPOST_ vc_filesys_close_disk_raw(const char *path); |
150 | |
151 | // Open disk for normal access |
152 | VCHPRE_ int VCHPOST_ vc_filesys_open_disk(const char *path); |
153 | |
154 | // Close disk for normal access |
155 | VCHPRE_ int VCHPOST_ vc_filesys_close_disk(const char *path); |
156 | |
157 | // Return number of sectors. |
158 | VCHPRE_ int VCHPOST_ vc_filesys_numsectors(const char *path); |
159 | VCHPRE_ int64_t VCHPOST_ vc_filesys_numsectors64(const char *path); |
160 | |
161 | // Read/Write sectors |
162 | VCHPRE_ int VCHPOST_ vc_filesys_read_sectors(const char *path, uint32_t sector_num, char *sectors, uint32_t num_sectors, uint32_t *sectors_read); |
163 | VCHPRE_ int VCHPOST_ vc_filesys_write_sectors(const char *path, uint32_t sector_num, char *sectors, uint32_t num_sectors, uint32_t *sectors_written); |
164 | |
165 | // Begin reading sectors from VideoCore. |
166 | VCHPRE_ int VCHPOST_ vc_filesys_read_sectors_begin(const char *path, uint32_t sector, uint32_t count); |
167 | |
168 | // Read the next sector. |
169 | VCHPRE_ int VCHPOST_ vc_filesys_read_sector(char *buf); |
170 | |
171 | // End streaming sectors. |
172 | VCHPRE_ int VCHPOST_ vc_filesys_read_sectors_end(uint32_t *sectors_read); |
173 | |
174 | // Begin writing sectors from VideoCore. |
175 | VCHPRE_ int VCHPOST_ vc_filesys_write_sectors_begin(const char *path, uint32_t sector, uint32_t count); |
176 | |
177 | // Write the next sector. |
178 | VCHPRE_ int VCHPOST_ vc_filesys_write_sector(const char *buf); |
179 | |
180 | // End streaming sectors. |
181 | VCHPRE_ int VCHPOST_ vc_filesys_write_sectors_end(uint32_t *sectors_written); |
182 | |
183 | #endif //VCFILESYS_H_ |
184 | |
185 | |