* [U-Boot] [PATCH] FAT: fix some issues in FAT write support code
@ 2011-12-15 13:12 Anatolij Gustschin
2011-12-16 7:47 ` Donggeun Kim
2011-12-20 22:18 ` Wolfgang Denk
0 siblings, 2 replies; 3+ messages in thread
From: Anatolij Gustschin @ 2011-12-15 13:12 UTC (permalink / raw)
To: u-boot
Writing a file to the FAT partition didn't work while a
test using a CF card. The test was done on mpc5200 based
board (powerpc). There is a number of problems in FAT
write code:
Compiler warning:
fat_write.c: In function 'file_fat_write':
fat_write.c:326: warning: 'counter' may be used uninitialized
in this function
fat_write.c:326: note: 'counter' was declared here
'l_filename' string is not terminated, so a file name
with garbage at the end is used as a file name as shown
by debug code.
Return value of set_contents() is not checked properly
so actually a file won't be written at all (as checked
using 'fatls' after a write attempt with 'fatwrite'
command).
do_fat_write() doesn't return the number of written bytes
if no error happened. However the return value of this
function is used to show the number of written bytes
in do_fat_fswrite().
The patch adds some debug code and fixes above mentioned
problems and also fixes a typo in error output.
NOTE: after a successful write to the FAT partition (under
U-Boot) the partition was checked under Linux using fsck.
The partition needed fixing FATs:
-bash-3.2# fsck -a /dev/sda1
fsck 1.39 (29-May-2006)
dosfsck 2.11, 12 Mar 2005, FAT32, LFN
FATs differ but appear to be intact. Using first FAT.
Performing changes.
Signed-off-by: Anatolij Gustschin <agust@denx.de>
Cc: Donggeun Kim <dg77.kim@samsung.com>
Cc: Aaron Williams <Aaron.Williams@cavium.com>
---
fs/fat/fat_write.c | 19 ++++++++++++++-----
1 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
index 4f1772f..3542b0b 100644
--- a/fs/fat/fat_write.c
+++ b/fs/fat/fat_write.c
@@ -323,7 +323,7 @@ static void
fill_dir_slot(fsdata *mydata, dir_entry **dentptr, const char *l_name)
{
dir_slot *slotptr = (dir_slot *)get_vfatname_block;
- __u8 counter, checksum;
+ __u8 counter = 0, checksum;
int idx = 0, ret;
char s_name[16];
@@ -926,6 +926,7 @@ static int do_fat_write(const char *filename, void *buffer,
int cursect;
int root_cluster, ret = -1, name_len;
char l_filename[VFAT_MAXLEN_BYTES];
+ int write_size = size;
dir_curclust = 0;
@@ -985,7 +986,11 @@ static int do_fat_write(const char *filename, void *buffer,
dentptr = (dir_entry *) do_fat_read_block;
name_len = strlen(filename);
+ if (name_len >= VFAT_MAXLEN_BYTES)
+ name_len = VFAT_MAXLEN_BYTES - 1;
+
memcpy(l_filename, filename, name_len);
+ l_filename[name_len] = 0; /* terminate the string */
downcase(l_filename);
startsect = mydata->rootdir_sect;
@@ -1012,10 +1017,12 @@ static int do_fat_write(const char *filename, void *buffer,
}
ret = set_contents(mydata, retdent, buffer, size);
- if (ret) {
+ if (ret < 0) {
printf("Error: writing contents\n");
goto exit;
}
+ write_size = ret;
+ debug("attempt to write 0x%x bytes\n", write_size);
/* Flush fat buffer */
ret = flush_fat_buffer(mydata);
@@ -1029,7 +1036,7 @@ static int do_fat_write(const char *filename, void *buffer,
get_dentfromdir_block,
mydata->clust_size * mydata->sect_size);
if (ret) {
- printf("Error: wrinting directory entry\n");
+ printf("Error: writing directory entry\n");
goto exit;
}
} else {
@@ -1056,10 +1063,12 @@ static int do_fat_write(const char *filename, void *buffer,
start_cluster, size, 0x20);
ret = set_contents(mydata, empty_dentptr, buffer, size);
- if (ret) {
+ if (ret < 0) {
printf("Error: writing contents\n");
goto exit;
}
+ write_size = ret;
+ debug("attempt to write 0x%x bytes\n", write_size);
/* Flush fat buffer */
ret = flush_fat_buffer(mydata);
@@ -1080,7 +1089,7 @@ static int do_fat_write(const char *filename, void *buffer,
exit:
free(mydata->fatbuf);
- return ret;
+ return ret < 0 ? ret : write_size;
}
int file_fat_write(const char *filename, void *buffer, unsigned long maxsize)
--
1.7.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [U-Boot] [PATCH] FAT: fix some issues in FAT write support code
2011-12-15 13:12 [U-Boot] [PATCH] FAT: fix some issues in FAT write support code Anatolij Gustschin
@ 2011-12-16 7:47 ` Donggeun Kim
2011-12-20 22:18 ` Wolfgang Denk
1 sibling, 0 replies; 3+ messages in thread
From: Donggeun Kim @ 2011-12-16 7:47 UTC (permalink / raw)
To: u-boot
On 2011? 12? 15? 22:12, Anatolij Gustschin wrote:
> Writing a file to the FAT partition didn't work while a
> test using a CF card. The test was done on mpc5200 based
> board (powerpc). There is a number of problems in FAT
> write code:
>
> Compiler warning:
> fat_write.c: In function 'file_fat_write':
> fat_write.c:326: warning: 'counter' may be used uninitialized
> in this function
> fat_write.c:326: note: 'counter' was declared here
>
> 'l_filename' string is not terminated, so a file name
> with garbage at the end is used as a file name as shown
> by debug code.
>
> Return value of set_contents() is not checked properly
> so actually a file won't be written at all (as checked
> using 'fatls' after a write attempt with 'fatwrite'
> command).
>
> do_fat_write() doesn't return the number of written bytes
> if no error happened. However the return value of this
> function is used to show the number of written bytes
> in do_fat_fswrite().
>
> The patch adds some debug code and fixes above mentioned
> problems and also fixes a typo in error output.
>
> NOTE: after a successful write to the FAT partition (under
> U-Boot) the partition was checked under Linux using fsck.
> The partition needed fixing FATs:
> -bash-3.2# fsck -a /dev/sda1
> fsck 1.39 (29-May-2006)
> dosfsck 2.11, 12 Mar 2005, FAT32, LFN
> FATs differ but appear to be intact. Using first FAT.
> Performing changes.
>
> Signed-off-by: Anatolij Gustschin <agust@denx.de>
> Cc: Donggeun Kim <dg77.kim@samsung.com>
> Cc: Aaron Williams <Aaron.Williams@cavium.com>
Acked-by: Donggeun Kim <dg77.kim@samsung.com>
Thanks.
-Donggeun
^ permalink raw reply [flat|nested] 3+ messages in thread
* [U-Boot] [PATCH] FAT: fix some issues in FAT write support code
2011-12-15 13:12 [U-Boot] [PATCH] FAT: fix some issues in FAT write support code Anatolij Gustschin
2011-12-16 7:47 ` Donggeun Kim
@ 2011-12-20 22:18 ` Wolfgang Denk
1 sibling, 0 replies; 3+ messages in thread
From: Wolfgang Denk @ 2011-12-20 22:18 UTC (permalink / raw)
To: u-boot
Dear Anatolij Gustschin,
In message <1323954734-26775-1-git-send-email-agust@denx.de> you wrote:
> Writing a file to the FAT partition didn't work while a
> test using a CF card. The test was done on mpc5200 based
> board (powerpc). There is a number of problems in FAT
> write code:
>
> Compiler warning:
> fat_write.c: In function 'file_fat_write':
> fat_write.c:326: warning: 'counter' may be used uninitialized
> in this function
> fat_write.c:326: note: 'counter' was declared here
>
> 'l_filename' string is not terminated, so a file name
> with garbage at the end is used as a file name as shown
> by debug code.
>
> Return value of set_contents() is not checked properly
> so actually a file won't be written at all (as checked
> using 'fatls' after a write attempt with 'fatwrite'
> command).
>
> do_fat_write() doesn't return the number of written bytes
> if no error happened. However the return value of this
> function is used to show the number of written bytes
> in do_fat_fswrite().
>
> The patch adds some debug code and fixes above mentioned
> problems and also fixes a typo in error output.
>
> NOTE: after a successful write to the FAT partition (under
> U-Boot) the partition was checked under Linux using fsck.
> The partition needed fixing FATs:
> -bash-3.2# fsck -a /dev/sda1
> fsck 1.39 (29-May-2006)
> dosfsck 2.11, 12 Mar 2005, FAT32, LFN
> FATs differ but appear to be intact. Using first FAT.
> Performing changes.
>
> Signed-off-by: Anatolij Gustschin <agust@denx.de>
> Cc: Donggeun Kim <dg77.kim@samsung.com>
> Cc: Aaron Williams <Aaron.Williams@cavium.com>
> ---
> fs/fat/fat_write.c | 19 ++++++++++++++-----
> 1 files changed, 14 insertions(+), 5 deletions(-)
Applied, thanks.
Best regards,
Wolfgang Denk
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Emotions are alien to me. I'm a scientist.
-- Spock, "This Side of Paradise", stardate 3417.3
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-12-20 22:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-15 13:12 [U-Boot] [PATCH] FAT: fix some issues in FAT write support code Anatolij Gustschin
2011-12-16 7:47 ` Donggeun Kim
2011-12-20 22:18 ` Wolfgang Denk
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox