2 fat - A FAT* CDI driver
3 Copyright (C) 2008 Janosch Gräf <janosch.graef@gmx.net>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
28 * @param stream CDI FS stream
29 * @param start Offset in flie
30 * @param size How many bytes to read
31 * @param buffer Buffer to store data in
32 * @return How many bytes read
34 size_t fat_fs_file_read(struct cdi_fs_stream
*stream
,uint64_t start
,size_t size
,void *buffer
) {
35 debug("fat_fs_file_read(0x%x,0x%x,0x%x,0x%x)\n",stream
,start
,size
,buffer
);
36 struct fat_fs_res
*res
= (struct fat_fs_res
*)stream
->res
;
38 if (start
>res
->filesize
) return 0;
39 if (start
+size
>res
->filesize
) size
= res
->filesize
-start
;
41 fat_cluster_read(res
->fs
,res
->clusters
,start
,size
,buffer
);
47 * @param stream CDI FS stream
48 * @param start Offset in flie
49 * @param size How many bytes to write
50 * @param buffer Data to write to file
51 * @return How many bytes read
53 size_t fat_fs_file_write(struct cdi_fs_stream
*stream
,uint64_t start
,size_t size
,const void *buffer
) {
54 debug("fat_fs_file_write(0x%x,0x%x,0x%x,0x%x)\n",stream
,start
,size
,buffer
);
55 struct fat_fs_res
*res
= (struct fat_fs_res
*)stream
->res
;
57 if (stream
->fs
->read_only
) return 0;
59 if (start
+size
>res
->filesize
) {
61 //fat_fs_file_truncate(stream,start+size);
65 fat_cluster_write(res
->fs
,res
->clusters
,start
,size
,buffer
);