fat: reading directories (with long names) and files works now (tested with FAT12)
[meinos.git] / apps / fat / file.c
blob77b78a9726c3a33545cd3340d8dfa83c98d055df
1 /*
2 * fat - A FAT* CDI driver
4 * Copyright (C) 2008 Janosch Gräf
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 3 of the License, or (at your option)
9 * any later version.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, see <http://www.gnu.org/licenses/>.
20 #include <stdint.h>
22 #include "fat_cdi.h"
23 #include "cluster.h"
25 #include "cdi/fs.h"
27 /**
28 * Reads from file
29 * @param stream CDI FS stream
30 * @param start Offset in flie
31 * @param size How many bytes to read
32 * @param buffer Buffer to store data in
33 * @return How many bytes read
35 size_t fat_fs_file_read(struct cdi_fs_stream *stream,uint64_t start,size_t size,void *buffer) {
36 debug("fat_fs_file_read(0x%x,0x%x,0x%x,0x%x)\n",stream,start,size,buffer);
37 struct fat_fs_res *res = (struct fat_fs_res*)stream->res;
39 if (start>res->filesize) return 0;
40 if (start+size>res->filesize) size = res->filesize-start;
42 fat_cluster_read(res->fs,res->clusters,start,size,buffer);
43 return size;