fs: fat: write returns error code instead of -1

It would be good that FAT write function return error code instead of
just returning -1 as fat_read_file() does.
This patch attempts to address this issue although it is 'best effort
(or estimate)' for now.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
lime2-spi
AKASHI Takahiro 6 years ago committed by Alexander Graf
parent 25bb9dab14
commit f1149cea16
  1. 19
      fs/fat/fat_write.c

@ -956,7 +956,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size,
if (read_bootsectandvi(&bs, &volinfo, &mydata->fatsize)) { if (read_bootsectandvi(&bs, &volinfo, &mydata->fatsize)) {
debug("error: reading boot sector\n"); debug("error: reading boot sector\n");
return -1; return -EIO;
} }
total_sector = bs.total_sect; total_sector = bs.total_sect;
@ -997,7 +997,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size,
mydata->fatbuf = memalign(ARCH_DMA_MINALIGN, FATBUFSIZE); mydata->fatbuf = memalign(ARCH_DMA_MINALIGN, FATBUFSIZE);
if (mydata->fatbuf == NULL) { if (mydata->fatbuf == NULL) {
debug("Error: allocating memory\n"); debug("Error: allocating memory\n");
return -1; return -ENOMEM;
} }
if (disk_read(cursect, if (disk_read(cursect,
@ -1005,6 +1005,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size,
(mydata->clust_size) : (mydata->clust_size) :
PREFETCH_BLOCKS, do_fat_read_at_block) < 0) { PREFETCH_BLOCKS, do_fat_read_at_block) < 0) {
debug("Error: reading rootdir block\n"); debug("Error: reading rootdir block\n");
ret = -EIO;
goto exit; goto exit;
} }
dentptr = (dir_entry *) do_fat_read_at_block; dentptr = (dir_entry *) do_fat_read_at_block;
@ -1029,6 +1030,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size,
size); size);
if (ret) { if (ret) {
printf("Error: %llu overflow\n", size); printf("Error: %llu overflow\n", size);
ret = -ENOSPC;
goto exit; goto exit;
} }
} }
@ -1036,6 +1038,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size,
ret = clear_fatent(mydata, start_cluster); ret = clear_fatent(mydata, start_cluster);
if (ret) { if (ret) {
printf("Error: clearing FAT entries\n"); printf("Error: clearing FAT entries\n");
ret = -EIO;
goto exit; goto exit;
} }
@ -1045,12 +1048,14 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size,
ret = start_cluster = find_empty_cluster(mydata); ret = start_cluster = find_empty_cluster(mydata);
if (ret < 0) { if (ret < 0) {
printf("Error: finding empty cluster\n"); printf("Error: finding empty cluster\n");
ret = -ENOSPC;
goto exit; goto exit;
} }
ret = check_overflow(mydata, start_cluster, size); ret = check_overflow(mydata, start_cluster, size);
if (ret) { if (ret) {
printf("Error: %llu overflow\n", size); printf("Error: %llu overflow\n", size);
ret = -ENOSPC;
goto exit; goto exit;
} }
@ -1065,12 +1070,14 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size,
ret = start_cluster = find_empty_cluster(mydata); ret = start_cluster = find_empty_cluster(mydata);
if (ret < 0) { if (ret < 0) {
printf("Error: finding empty cluster\n"); printf("Error: finding empty cluster\n");
ret = -ENOSPC;
goto exit; goto exit;
} }
ret = check_overflow(mydata, start_cluster, size); ret = check_overflow(mydata, start_cluster, size);
if (ret) { if (ret) {
printf("Error: %llu overflow\n", size); printf("Error: %llu overflow\n", size);
ret = -ENOSPC;
goto exit; goto exit;
} }
} else { } else {
@ -1087,6 +1094,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size,
ret = set_contents(mydata, retdent, buffer, size, actwrite); ret = set_contents(mydata, retdent, buffer, size, actwrite);
if (ret < 0) { if (ret < 0) {
printf("Error: writing contents\n"); printf("Error: writing contents\n");
ret = -EIO;
goto exit; goto exit;
} }
debug("attempt to write 0x%llx bytes\n", *actwrite); debug("attempt to write 0x%llx bytes\n", *actwrite);
@ -1095,14 +1103,17 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size,
ret = flush_dirty_fat_buffer(mydata); ret = flush_dirty_fat_buffer(mydata);
if (ret) { if (ret) {
printf("Error: flush fat buffer\n"); printf("Error: flush fat buffer\n");
ret = -EIO;
goto exit; goto exit;
} }
/* Write directory table to device */ /* Write directory table to device */
ret = set_cluster(mydata, dir_curclust, get_dentfromdir_block, ret = set_cluster(mydata, dir_curclust, get_dentfromdir_block,
mydata->clust_size * mydata->sect_size); mydata->clust_size * mydata->sect_size);
if (ret) if (ret) {
printf("Error: writing directory entry\n"); printf("Error: writing directory entry\n");
ret = -EIO;
}
exit: exit:
free(mydata->fatbuf); free(mydata->fatbuf);
@ -1114,7 +1125,7 @@ int file_fat_write(const char *filename, void *buffer, loff_t offset,
{ {
if (offset != 0) { if (offset != 0) {
printf("Error: non zero offset is currently not supported.\n"); printf("Error: non zero offset is currently not supported.\n");
return -1; return -EINVAL;
} }
printf("writing %s\n", filename); printf("writing %s\n", filename);

Loading…
Cancel
Save