fat: Prepare API change for files greater than 2GB

Change the internal FAT functions to use loff_t for offsets.

Signed-off-by: Suriyan Ramasami <suriyan.r@gmail.com>
Acked-by: Simon Glass <sjg@chromium.org>
[trini: Fix fs/fat/fat.c for min3 updates]
Signed-off-by: Tom Rini <trini@ti.com>
master
Suriyan Ramasami 10 years ago committed by Tom Rini
parent 64553717bb
commit 1ad0b98a06
  1. 3
      board/esd/common/auto_update.c
  2. 9
      common/cmd_fat.c
  3. 4
      common/env_fat.c
  4. 135
      fs/fat/fat.c
  5. 61
      fs/fat/fat_write.c
  6. 3
      fs/fat/file.c
  7. 13
      include/fat.h

@ -31,9 +31,6 @@ extern int N_AU_IMAGES;
#define MAX_LOADSZ 0x1c00000 #define MAX_LOADSZ 0x1c00000
/* externals */ /* externals */
extern int fat_register_device(block_dev_desc_t *, int);
extern int file_fat_detectfs(void);
extern long file_fat_read(const char *, void *, unsigned long);
long do_fat_read (const char *filename, void *buffer, long do_fat_read (const char *filename, void *buffer,
unsigned long maxsize, int dols); unsigned long maxsize, int dols);

@ -100,7 +100,8 @@ U_BOOT_CMD(
static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag, static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag,
int argc, char * const argv[]) int argc, char * const argv[])
{ {
long size; loff_t size;
int ret;
unsigned long addr; unsigned long addr;
unsigned long count; unsigned long count;
block_dev_desc_t *dev_desc = NULL; block_dev_desc_t *dev_desc = NULL;
@ -127,15 +128,15 @@ static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag,
count = simple_strtoul(argv[5], NULL, 16); count = simple_strtoul(argv[5], NULL, 16);
buf = map_sysmem(addr, count); buf = map_sysmem(addr, count);
size = file_fat_write(argv[4], buf, count); ret = file_fat_write(argv[4], buf, 0, count, &size);
unmap_sysmem(buf); unmap_sysmem(buf);
if (size == -1) { if (ret < 0) {
printf("\n** Unable to write \"%s\" from %s %d:%d **\n", printf("\n** Unable to write \"%s\" from %s %d:%d **\n",
argv[4], argv[1], dev, part); argv[4], argv[1], dev, part);
return 1; return 1;
} }
printf("%ld bytes written\n", size); printf("%llu bytes written\n", size);
return 0; return 0;
} }

@ -41,6 +41,7 @@ int saveenv(void)
disk_partition_t info; disk_partition_t info;
int dev, part; int dev, part;
int err; int err;
loff_t size;
err = env_export(&env_new); err = env_export(&env_new);
if (err) if (err)
@ -59,7 +60,8 @@ int saveenv(void)
return 1; return 1;
} }
err = file_fat_write(FAT_ENV_FILE, (void *)&env_new, sizeof(env_t)); err = file_fat_write(FAT_ENV_FILE, (void *)&env_new, 0, sizeof(env_t),
&size);
if (err == -1) { if (err == -1) {
printf("\n** Unable to write \"%s\" from %s%d:%d **\n", printf("\n** Unable to write \"%s\" from %s%d:%d **\n",
FAT_ENV_FILE, FAT_ENV_INTERFACE, dev, part); FAT_ENV_FILE, FAT_ENV_INTERFACE, dev, part);

@ -317,32 +317,32 @@ get_cluster(fsdata *mydata, __u32 clustnum, __u8 *buffer, unsigned long size)
/* /*
* Read at most 'maxsize' bytes from 'pos' in the file associated with 'dentptr' * Read at most 'maxsize' bytes from 'pos' in the file associated with 'dentptr'
* into 'buffer'. * into 'buffer'.
* Return the number of bytes read or -1 on fatal errors. * Update the number of bytes read in *gotsize or return -1 on fatal errors.
*/ */
__u8 get_contents_vfatname_block[MAX_CLUSTSIZE] __u8 get_contents_vfatname_block[MAX_CLUSTSIZE]
__aligned(ARCH_DMA_MINALIGN); __aligned(ARCH_DMA_MINALIGN);
static long static int get_contents(fsdata *mydata, dir_entry *dentptr, loff_t pos,
get_contents(fsdata *mydata, dir_entry *dentptr, unsigned long pos, __u8 *buffer, loff_t maxsize, loff_t *gotsize)
__u8 *buffer, unsigned long maxsize)
{ {
unsigned long filesize = FAT2CPU32(dentptr->size), gotsize = 0; loff_t filesize = FAT2CPU32(dentptr->size);
unsigned int bytesperclust = mydata->clust_size * mydata->sect_size; unsigned int bytesperclust = mydata->clust_size * mydata->sect_size;
__u32 curclust = START(dentptr); __u32 curclust = START(dentptr);
__u32 endclust, newclust; __u32 endclust, newclust;
unsigned long actsize; loff_t actsize;
debug("Filesize: %ld bytes\n", filesize); *gotsize = 0;
debug("Filesize: %llu bytes\n", filesize);
if (pos >= filesize) { if (pos >= filesize) {
debug("Read position past EOF: %lu\n", pos); debug("Read position past EOF: %llu\n", pos);
return gotsize; return 0;
} }
if (maxsize > 0 && filesize > pos + maxsize) if (maxsize > 0 && filesize > pos + maxsize)
filesize = pos + maxsize; filesize = pos + maxsize;
debug("%ld bytes\n", filesize); debug("%llu bytes\n", filesize);
actsize = bytesperclust; actsize = bytesperclust;
@ -352,7 +352,7 @@ get_contents(fsdata *mydata, dir_entry *dentptr, unsigned long pos,
if (CHECK_CLUST(curclust, mydata->fatsize)) { if (CHECK_CLUST(curclust, mydata->fatsize)) {
debug("curclust: 0x%x\n", curclust); debug("curclust: 0x%x\n", curclust);
debug("Invalid FAT entry\n"); debug("Invalid FAT entry\n");
return gotsize; return 0;
} }
actsize += bytesperclust; actsize += bytesperclust;
} }
@ -364,7 +364,7 @@ get_contents(fsdata *mydata, dir_entry *dentptr, unsigned long pos,
/* align to beginning of next cluster if any */ /* align to beginning of next cluster if any */
if (pos) { if (pos) {
actsize = min(filesize, (unsigned long)bytesperclust); actsize = min(filesize, (loff_t)bytesperclust);
if (get_cluster(mydata, curclust, get_contents_vfatname_block, if (get_cluster(mydata, curclust, get_contents_vfatname_block,
(int)actsize) != 0) { (int)actsize) != 0) {
printf("Error reading cluster\n"); printf("Error reading cluster\n");
@ -373,16 +373,16 @@ get_contents(fsdata *mydata, dir_entry *dentptr, unsigned long pos,
filesize -= actsize; filesize -= actsize;
actsize -= pos; actsize -= pos;
memcpy(buffer, get_contents_vfatname_block + pos, actsize); memcpy(buffer, get_contents_vfatname_block + pos, actsize);
gotsize += actsize; *gotsize += actsize;
if (!filesize) if (!filesize)
return gotsize; return 0;
buffer += actsize; buffer += actsize;
curclust = get_fatent(mydata, curclust); curclust = get_fatent(mydata, curclust);
if (CHECK_CLUST(curclust, mydata->fatsize)) { if (CHECK_CLUST(curclust, mydata->fatsize)) {
debug("curclust: 0x%x\n", curclust); debug("curclust: 0x%x\n", curclust);
debug("Invalid FAT entry\n"); debug("Invalid FAT entry\n");
return gotsize; return 0;
} }
} }
@ -398,7 +398,7 @@ get_contents(fsdata *mydata, dir_entry *dentptr, unsigned long pos,
if (CHECK_CLUST(newclust, mydata->fatsize)) { if (CHECK_CLUST(newclust, mydata->fatsize)) {
debug("curclust: 0x%x\n", newclust); debug("curclust: 0x%x\n", newclust);
debug("Invalid FAT entry\n"); debug("Invalid FAT entry\n");
return gotsize; return 0;
} }
endclust = newclust; endclust = newclust;
actsize += bytesperclust; actsize += bytesperclust;
@ -410,14 +410,14 @@ get_contents(fsdata *mydata, dir_entry *dentptr, unsigned long pos,
printf("Error reading cluster\n"); printf("Error reading cluster\n");
return -1; return -1;
} }
gotsize += actsize; *gotsize += actsize;
return gotsize; return 0;
getit: getit:
if (get_cluster(mydata, curclust, buffer, (int)actsize) != 0) { if (get_cluster(mydata, curclust, buffer, (int)actsize) != 0) {
printf("Error reading cluster\n"); printf("Error reading cluster\n");
return -1; return -1;
} }
gotsize += (int)actsize; *gotsize += (int)actsize;
filesize -= actsize; filesize -= actsize;
buffer += actsize; buffer += actsize;
@ -425,7 +425,7 @@ getit:
if (CHECK_CLUST(curclust, mydata->fatsize)) { if (CHECK_CLUST(curclust, mydata->fatsize)) {
debug("curclust: 0x%x\n", curclust); debug("curclust: 0x%x\n", curclust);
printf("Invalid FAT entry\n"); printf("Invalid FAT entry\n");
return gotsize; return 0;
} }
actsize = bytesperclust; actsize = bytesperclust;
endclust = curclust; endclust = curclust;
@ -633,8 +633,8 @@ static dir_entry *get_dentfromdir(fsdata *mydata, int startsect,
} }
if (doit) { if (doit) {
if (dirc == ' ') { if (dirc == ' ') {
printf(" %8ld %s%c\n", printf(" %8u %s%c\n",
(long)FAT2CPU32(dentptr->size), FAT2CPU32(dentptr->size),
l_name, l_name,
dirc); dirc);
} else { } else {
@ -690,8 +690,8 @@ static dir_entry *get_dentfromdir(fsdata *mydata, int startsect,
if (doit) { if (doit) {
if (dirc == ' ') { if (dirc == ' ') {
printf(" %8ld %s%c\n", printf(" %8u %s%c\n",
(long)FAT2CPU32(dentptr->size), FAT2CPU32(dentptr->size),
s_name, dirc); s_name, dirc);
} else { } else {
printf(" %s%c\n", printf(" %s%c\n",
@ -806,9 +806,8 @@ exit:
__u8 do_fat_read_at_block[MAX_CLUSTSIZE] __u8 do_fat_read_at_block[MAX_CLUSTSIZE]
__aligned(ARCH_DMA_MINALIGN); __aligned(ARCH_DMA_MINALIGN);
long int do_fat_read_at(const char *filename, loff_t pos, void *buffer,
do_fat_read_at(const char *filename, unsigned long pos, void *buffer, loff_t maxsize, int dols, int dogetsize, loff_t *size)
unsigned long maxsize, int dols, int dogetsize)
{ {
char fnamecopy[2048]; char fnamecopy[2048];
boot_sector bs; boot_sector bs;
@ -821,7 +820,7 @@ do_fat_read_at(const char *filename, unsigned long pos, void *buffer,
__u32 cursect; __u32 cursect;
int idx, isdir = 0; int idx, isdir = 0;
int files = 0, dirs = 0; int files = 0, dirs = 0;
long ret = -1; int ret = -1;
int firsttime; int firsttime;
__u32 root_cluster = 0; __u32 root_cluster = 0;
int rootdir_size = 0; int rootdir_size = 0;
@ -974,8 +973,8 @@ do_fat_read_at(const char *filename, unsigned long pos, void *buffer,
} }
if (doit) { if (doit) {
if (dirc == ' ') { if (dirc == ' ') {
printf(" %8ld %s%c\n", printf(" %8u %s%c\n",
(long)FAT2CPU32(dentptr->size), FAT2CPU32(dentptr->size),
l_name, l_name,
dirc); dirc);
} else { } else {
@ -1032,8 +1031,8 @@ do_fat_read_at(const char *filename, unsigned long pos, void *buffer,
} }
if (doit) { if (doit) {
if (dirc == ' ') { if (dirc == ' ') {
printf(" %8ld %s%c\n", printf(" %8u %s%c\n",
(long)FAT2CPU32(dentptr->size), FAT2CPU32(dentptr->size),
s_name, dirc); s_name, dirc);
} else { } else {
printf(" %s%c\n", printf(" %s%c\n",
@ -1102,7 +1101,7 @@ do_fat_read_at(const char *filename, unsigned long pos, void *buffer,
if (dols == LS_ROOT) { if (dols == LS_ROOT) {
printf("\n%d file(s), %d dir(s)\n\n", printf("\n%d file(s), %d dir(s)\n\n",
files, dirs); files, dirs);
ret = 0; *size = 0;
} }
goto exit; goto exit;
} }
@ -1141,7 +1140,7 @@ rootdir_done:
if (get_dentfromdir(mydata, startsect, subname, dentptr, if (get_dentfromdir(mydata, startsect, subname, dentptr,
isdir ? 0 : dols) == NULL) { isdir ? 0 : dols) == NULL) {
if (dols && !isdir) if (dols && !isdir)
ret = 0; *size = 0;
goto exit; goto exit;
} }
@ -1152,21 +1151,23 @@ rootdir_done:
subname = nextname; subname = nextname;
} }
if (dogetsize) if (dogetsize) {
ret = FAT2CPU32(dentptr->size); *size = FAT2CPU32(dentptr->size);
else ret = 0;
ret = get_contents(mydata, dentptr, pos, buffer, maxsize); } else {
debug("Size: %d, got: %ld\n", FAT2CPU32(dentptr->size), ret); ret = get_contents(mydata, dentptr, pos, buffer, maxsize, size);
}
debug("Size: %u, got: %llu\n", FAT2CPU32(dentptr->size), *size);
exit: exit:
free(mydata->fatbuf); free(mydata->fatbuf);
return ret; return ret;
} }
long int do_fat_read(const char *filename, void *buffer, loff_t maxsize, int dols,
do_fat_read(const char *filename, void *buffer, unsigned long maxsize, int dols) loff_t *actread)
{ {
return do_fat_read_at(filename, 0, buffer, maxsize, dols, 0); return do_fat_read_at(filename, 0, buffer, maxsize, dols, 0, actread);
} }
int file_fat_detectfs(void) int file_fat_detectfs(void)
@ -1233,44 +1234,64 @@ int file_fat_detectfs(void)
int file_fat_ls(const char *dir) int file_fat_ls(const char *dir)
{ {
return do_fat_read(dir, NULL, 0, LS_YES); loff_t size;
return do_fat_read(dir, NULL, 0, LS_YES, &size);
} }
int fat_exists(const char *filename) int fat_exists(const char *filename)
{ {
int sz; int ret;
sz = do_fat_read_at(filename, 0, NULL, 0, LS_NO, 1); loff_t size;
return sz >= 0;
ret = do_fat_read_at(filename, 0, NULL, 0, LS_NO, 1, &size);
return ret == 0;
} }
int fat_size(const char *filename) int fat_size(const char *filename)
{ {
return do_fat_read_at(filename, 0, NULL, 0, LS_NO, 1); loff_t size;
int ret;
ret = do_fat_read_at(filename, 0, NULL, 0, LS_NO, 1, &size);
if (ret)
return ret;
else
return size;
} }
long file_fat_read_at(const char *filename, unsigned long pos, void *buffer, int file_fat_read_at(const char *filename, loff_t pos, void *buffer,
unsigned long maxsize) loff_t maxsize, loff_t *actread)
{ {
printf("reading %s\n", filename); printf("reading %s\n", filename);
return do_fat_read_at(filename, pos, buffer, maxsize, LS_NO, 0); return do_fat_read_at(filename, pos, buffer, maxsize, LS_NO, 0,
actread);
} }
long file_fat_read(const char *filename, void *buffer, unsigned long maxsize) int file_fat_read(const char *filename, void *buffer, int maxsize)
{ {
return file_fat_read_at(filename, 0, buffer, maxsize); loff_t actread;
int ret;
ret = file_fat_read_at(filename, 0, buffer, maxsize, &actread);
if (ret)
return ret;
else
return actread;
} }
int fat_read_file(const char *filename, void *buf, int offset, int len) int fat_read_file(const char *filename, void *buf, int offset, int len)
{ {
int len_read; int ret;
loff_t actread;
len_read = file_fat_read_at(filename, offset, buf, len); ret = file_fat_read_at(filename, offset, buf, len, &actread);
if (len_read == -1) { if (ret) {
printf("** Unable to read file %s **\n", filename); printf("** Unable to read file %s **\n", filename);
return -1; return ret;
} }
return len_read; return actread;
} }
void fat_close(void) void fat_close(void)

@ -660,24 +660,26 @@ static int clear_fatent(fsdata *mydata, __u32 entry)
/* /*
* Write at most 'maxsize' bytes from 'buffer' into * Write at most 'maxsize' bytes from 'buffer' into
* the file associated with 'dentptr' * the file associated with 'dentptr'
* Return the number of bytes read or -1 on fatal errors. * Update the number of bytes written in *gotsize and return 0
* or return -1 on fatal errors.
*/ */
static int static int
set_contents(fsdata *mydata, dir_entry *dentptr, __u8 *buffer, set_contents(fsdata *mydata, dir_entry *dentptr, __u8 *buffer,
unsigned long maxsize) loff_t maxsize, loff_t *gotsize)
{ {
unsigned long filesize = FAT2CPU32(dentptr->size), gotsize = 0; loff_t filesize = FAT2CPU32(dentptr->size);
unsigned int bytesperclust = mydata->clust_size * mydata->sect_size; unsigned int bytesperclust = mydata->clust_size * mydata->sect_size;
__u32 curclust = START(dentptr); __u32 curclust = START(dentptr);
__u32 endclust = 0, newclust = 0; __u32 endclust = 0, newclust = 0;
unsigned long actsize; loff_t actsize;
debug("Filesize: %ld bytes\n", filesize); *gotsize = 0;
debug("Filesize: %llu bytes\n", filesize);
if (maxsize > 0 && filesize > maxsize) if (maxsize > 0 && filesize > maxsize)
filesize = maxsize; filesize = maxsize;
debug("%ld bytes\n", filesize); debug("%llu bytes\n", filesize);
actsize = bytesperclust; actsize = bytesperclust;
endclust = curclust; endclust = curclust;
@ -692,7 +694,7 @@ set_contents(fsdata *mydata, dir_entry *dentptr, __u8 *buffer,
if (CHECK_CLUST(newclust, mydata->fatsize)) { if (CHECK_CLUST(newclust, mydata->fatsize)) {
debug("curclust: 0x%x\n", newclust); debug("curclust: 0x%x\n", newclust);
debug("Invalid FAT entry\n"); debug("Invalid FAT entry\n");
return gotsize; return 0;
} }
endclust = newclust; endclust = newclust;
actsize += bytesperclust; actsize += bytesperclust;
@ -706,7 +708,7 @@ set_contents(fsdata *mydata, dir_entry *dentptr, __u8 *buffer,
} }
/* set remaining bytes */ /* set remaining bytes */
gotsize += (int)actsize; *gotsize += actsize;
filesize -= actsize; filesize -= actsize;
buffer += actsize; buffer += actsize;
actsize = filesize; actsize = filesize;
@ -715,7 +717,7 @@ set_contents(fsdata *mydata, dir_entry *dentptr, __u8 *buffer,
debug("error: writing cluster\n"); debug("error: writing cluster\n");
return -1; return -1;
} }
gotsize += actsize; *gotsize += actsize;
/* Mark end of file in FAT */ /* Mark end of file in FAT */
if (mydata->fatsize == 16) if (mydata->fatsize == 16)
@ -724,20 +726,20 @@ set_contents(fsdata *mydata, dir_entry *dentptr, __u8 *buffer,
newclust = 0xfffffff; newclust = 0xfffffff;
set_fatent_value(mydata, endclust, newclust); set_fatent_value(mydata, endclust, newclust);
return gotsize; return 0;
getit: getit:
if (set_cluster(mydata, curclust, buffer, (int)actsize) != 0) { if (set_cluster(mydata, curclust, buffer, (int)actsize) != 0) {
debug("error: writing cluster\n"); debug("error: writing cluster\n");
return -1; return -1;
} }
gotsize += (int)actsize; *gotsize += actsize;
filesize -= actsize; filesize -= actsize;
buffer += actsize; buffer += actsize;
if (CHECK_CLUST(curclust, mydata->fatsize)) { if (CHECK_CLUST(curclust, mydata->fatsize)) {
debug("curclust: 0x%x\n", curclust); debug("curclust: 0x%x\n", curclust);
debug("Invalid FAT entry\n"); debug("Invalid FAT entry\n");
return gotsize; return 0;
} }
actsize = bytesperclust; actsize = bytesperclust;
curclust = endclust = newclust; curclust = endclust = newclust;
@ -766,7 +768,7 @@ static void fill_dentry(fsdata *mydata, dir_entry *dentptr,
* exceed the size of the block device * exceed the size of the block device
* Return -1 when overflow occurs, otherwise return 0 * Return -1 when overflow occurs, otherwise return 0
*/ */
static int check_overflow(fsdata *mydata, __u32 clustnum, unsigned long size) static int check_overflow(fsdata *mydata, __u32 clustnum, loff_t size)
{ {
__u32 startsect, sect_num; __u32 startsect, sect_num;
@ -923,8 +925,8 @@ static dir_entry *find_directory_entry(fsdata *mydata, int startsect,
return NULL; return NULL;
} }
static int do_fat_write(const char *filename, void *buffer, static int do_fat_write(const char *filename, void *buffer, loff_t size,
unsigned long size) loff_t *actwrite)
{ {
dir_entry *dentptr, *retdent; dir_entry *dentptr, *retdent;
__u32 startsect; __u32 startsect;
@ -936,8 +938,8 @@ static int do_fat_write(const char *filename, void *buffer,
int cursect; int cursect;
int ret = -1, name_len; int ret = -1, name_len;
char l_filename[VFAT_MAXLEN_BYTES]; char l_filename[VFAT_MAXLEN_BYTES];
int write_size = size;
*actwrite = size;
dir_curclust = 0; dir_curclust = 0;
if (read_bootsectandvi(&bs, &volinfo, &mydata->fatsize)) { if (read_bootsectandvi(&bs, &volinfo, &mydata->fatsize)) {
@ -1015,7 +1017,7 @@ static int do_fat_write(const char *filename, void *buffer,
ret = check_overflow(mydata, start_cluster, size); ret = check_overflow(mydata, start_cluster, size);
if (ret) { if (ret) {
printf("Error: %ld overflow\n", size); printf("Error: %llu overflow\n", size);
goto exit; goto exit;
} }
@ -1025,13 +1027,12 @@ static int do_fat_write(const char *filename, void *buffer,
goto exit; goto exit;
} }
ret = set_contents(mydata, retdent, buffer, size); ret = set_contents(mydata, retdent, buffer, size, actwrite);
if (ret < 0) { if (ret < 0) {
printf("Error: writing contents\n"); printf("Error: writing contents\n");
goto exit; goto exit;
} }
write_size = ret; debug("attempt to write 0x%llx bytes\n", *actwrite);
debug("attempt to write 0x%x bytes\n", write_size);
/* Flush fat buffer */ /* Flush fat buffer */
ret = flush_fat_buffer(mydata); ret = flush_fat_buffer(mydata);
@ -1061,7 +1062,7 @@ static int do_fat_write(const char *filename, void *buffer,
ret = check_overflow(mydata, start_cluster, size); ret = check_overflow(mydata, start_cluster, size);
if (ret) { if (ret) {
printf("Error: %ld overflow\n", size); printf("Error: %llu overflow\n", size);
goto exit; goto exit;
} }
@ -1069,13 +1070,13 @@ static int do_fat_write(const char *filename, void *buffer,
fill_dentry(mydata, empty_dentptr, filename, fill_dentry(mydata, empty_dentptr, filename,
start_cluster, size, 0x20); start_cluster, size, 0x20);
ret = set_contents(mydata, empty_dentptr, buffer, size); ret = set_contents(mydata, empty_dentptr, buffer, size,
actwrite);
if (ret < 0) { if (ret < 0) {
printf("Error: writing contents\n"); printf("Error: writing contents\n");
goto exit; goto exit;
} }
write_size = ret; debug("attempt to write 0x%llx bytes\n", *actwrite);
debug("attempt to write 0x%x bytes\n", write_size);
/* Flush fat buffer */ /* Flush fat buffer */
ret = flush_fat_buffer(mydata); ret = flush_fat_buffer(mydata);
@ -1096,11 +1097,17 @@ static int do_fat_write(const char *filename, void *buffer,
exit: exit:
free(mydata->fatbuf); free(mydata->fatbuf);
return ret < 0 ? ret : write_size; return ret;
} }
int file_fat_write(const char *filename, void *buffer, unsigned long maxsize) int file_fat_write(const char *filename, void *buffer, loff_t offset,
loff_t maxsize, loff_t *actwrite)
{ {
if (offset != 0) {
printf("Error: non zero offset is currently not suported.\n");
return -1;
}
printf("writing %s\n", filename); printf("writing %s\n", filename);
return do_fat_write(filename, buffer, maxsize); return do_fat_write(filename, buffer, maxsize, actwrite);
} }

@ -162,8 +162,7 @@ file_ls(const char *dir)
return filesystems[current_filesystem].ls(arg); return filesystems[current_filesystem].ls(arg);
} }
long int file_read(const char *filename, void *buffer, int maxsize)
file_read(const char *filename, void *buffer, unsigned long maxsize)
{ {
char fullpath[1024]; char fullpath[1024];
const char *arg; const char *arg;

@ -178,8 +178,8 @@ typedef struct {
typedef int (file_detectfs_func)(void); typedef int (file_detectfs_func)(void);
typedef int (file_ls_func)(const char *dir); typedef int (file_ls_func)(const char *dir);
typedef long (file_read_func)(const char *filename, void *buffer, typedef int (file_read_func)(const char *filename, void *buffer,
unsigned long maxsize); int maxsize);
struct filesystem { struct filesystem {
file_detectfs_func *detect; file_detectfs_func *detect;
@ -199,14 +199,15 @@ int file_fat_detectfs(void);
int file_fat_ls(const char *dir); int file_fat_ls(const char *dir);
int fat_exists(const char *filename); int fat_exists(const char *filename);
int fat_size(const char *filename); int fat_size(const char *filename);
long file_fat_read_at(const char *filename, unsigned long pos, void *buffer, int file_fat_read_at(const char *filename, loff_t pos, void *buffer,
unsigned long maxsize); loff_t maxsize, loff_t *actread);
long file_fat_read(const char *filename, void *buffer, unsigned long maxsize); int file_fat_read(const char *filename, void *buffer, int maxsize);
const char *file_getfsname(int idx); const char *file_getfsname(int idx);
int fat_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info); int fat_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info);
int fat_register_device(block_dev_desc_t *dev_desc, int part_no); int fat_register_device(block_dev_desc_t *dev_desc, int part_no);
int file_fat_write(const char *filename, void *buffer, unsigned long maxsize); int file_fat_write(const char *filename, void *buf, loff_t offset, loff_t len,
loff_t *actwrite);
int fat_read_file(const char *filename, void *buf, int offset, int len); int fat_read_file(const char *filename, void *buf, int offset, int len);
void fat_close(void); void fat_close(void);
#endif /* _FAT_H_ */ #endif /* _FAT_H_ */

Loading…
Cancel
Save