summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorBenoît Thébaudeau <benoit@wsystem.com>2015-09-28 15:45:31 +0200
committerTom Rini <trini@konsulko.com>2015-10-11 17:12:08 -0400
commite876be4b5ccb661d68b5b83330e134ace339316c (patch)
tree628caa9eded5b61649f6fa2e99e56acecb76ed31 /fs
parent5e1a860e6cd6d42d9ae16c9d9abbde46514da46d (diff)
downloadu-boot-imx-e876be4b5ccb661d68b5b83330e134ace339316c.zip
u-boot-imx-e876be4b5ccb661d68b5b83330e134ace339316c.tar.gz
u-boot-imx-e876be4b5ccb661d68b5b83330e134ace339316c.tar.bz2
fs/fat/fat_write: Factor out duplicate code
Signed-off-by: Benoît Thébaudeau <benoit@wsystem.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/fat/fat_write.c68
1 files changed, 20 insertions, 48 deletions
diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
index 2399844..2d032ee 100644
--- a/fs/fat/fat_write.c
+++ b/fs/fat/fat_write.c
@@ -1028,10 +1028,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size,
if (retdent) {
/* Update file size and start_cluster in a directory entry */
retdent->size = cpu_to_le32(size);
- start_cluster = FAT2CPU16(retdent->start);
- if (mydata->fatsize == 32)
- start_cluster |=
- (FAT2CPU16(retdent->starthi) << 16);
+ start_cluster = START(retdent);
ret = check_overflow(mydata, start_cluster, size);
if (ret) {
@@ -1044,29 +1041,6 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size,
printf("Error: clearing FAT entries\n");
goto exit;
}
-
- ret = set_contents(mydata, retdent, buffer, size, actwrite);
- if (ret < 0) {
- printf("Error: writing contents\n");
- goto exit;
- }
- debug("attempt to write 0x%llx bytes\n", *actwrite);
-
- /* Flush fat buffer */
- ret = flush_fat_buffer(mydata);
- if (ret) {
- printf("Error: flush fat buffer\n");
- goto exit;
- }
-
- /* Write directory table to device */
- ret = set_cluster(mydata, dir_curclust,
- get_dentfromdir_block,
- mydata->clust_size * mydata->sect_size);
- if (ret) {
- printf("Error: writing directory entry\n");
- goto exit;
- }
} else {
/* Set short name to set alias checksum field in dir_slot */
set_name(empty_dentptr, filename);
@@ -1088,31 +1062,29 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size,
fill_dentry(mydata, empty_dentptr, filename,
start_cluster, size, 0x20);
- ret = set_contents(mydata, empty_dentptr, buffer, size,
- actwrite);
- if (ret < 0) {
- printf("Error: writing contents\n");
- goto exit;
- }
- debug("attempt to write 0x%llx bytes\n", *actwrite);
+ retdent = empty_dentptr;
+ }
- /* Flush fat buffer */
- ret = flush_fat_buffer(mydata);
- if (ret) {
- printf("Error: flush fat buffer\n");
- goto exit;
- }
+ ret = set_contents(mydata, retdent, buffer, size, actwrite);
+ if (ret < 0) {
+ printf("Error: writing contents\n");
+ goto exit;
+ }
+ debug("attempt to write 0x%llx bytes\n", *actwrite);
- /* Write directory table to device */
- ret = set_cluster(mydata, dir_curclust,
- get_dentfromdir_block,
- mydata->clust_size * mydata->sect_size);
- if (ret) {
- printf("Error: writing directory entry\n");
- goto exit;
- }
+ /* Flush fat buffer */
+ ret = flush_fat_buffer(mydata);
+ if (ret) {
+ printf("Error: flush fat buffer\n");
+ goto exit;
}
+ /* Write directory table to device */
+ ret = set_cluster(mydata, dir_curclust, get_dentfromdir_block,
+ mydata->clust_size * mydata->sect_size);
+ if (ret)
+ printf("Error: writing directory entry\n");
+
exit:
free(mydata->fatbuf);
return ret;