Skip to contentSkip to conversation

FAT: Add FAT write feature

PATCH RESEND Superseded Donggeun Kim 2 participants 2 messages Oct 7, 2011 – Oct 21, 2011 VFAT/FAT/msdos filesystem

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 FAT: Add FAT write feature

In some cases, saving data in RAM as a file with FAT format is required. This patch allows the file to be written in FAT formatted partition.

The usage is similar with reading a file.
First, fat_register_device function is called before file_fat_write function in order to set target partition.
Then, file_fat_write function is invoked with desired file name, start ram address for writing data, and file size.

---
 fs/fat/Makefile    |    1 +
 fs/fat/fat.c       |    2 +
 fs/fat/fat_write.c | 1091 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/fat.h      |    3 +
 4 files changed, 1097 insertions(+), 0 deletions(-)
 create mode 100644 fs/fat/fat_write.c
fs/fat/Makefile +1 -0
index 93b6f07..9635d36 100644
@@ -25,6 +25,7 @@ LIB	= $(obj)libfat.o
 
 AOBJS	=
 COBJS-$(CONFIG_CMD_FAT)	:= fat.o
+COBJS-$(CONFIG_FAT_WRITE):= fat_write.o
 
 ifndef CONFIG_SPL_BUILD
 COBJS-$(CONFIG_CMD_FAT)	+= file.o
fs/fat/fat.c +2 -0
index 756ac64..7cf173c 100644
@@ -46,6 +46,7 @@ static void downcase (char *str)
 static block_dev_desc_t *cur_dev = NULL;
 
 static unsigned long part_offset = 0;
+static unsigned long part_size;
 
 static int cur_part = 1;
 
@@ -99,6 +100,7 @@ int fat_register_device (block_dev_desc_t * dev_desc, int part_no)
 	if (!get_partition_info(dev_desc, part_no, &info)) {
 		part_offset = info.start;
 		cur_part = part_no;
+		part_size = info.size;
 	} else if ((strncmp((char *)&buffer[DOS_FS_TYPE_OFFSET], "FAT", 3) == 0) ||
 		   (strncmp((char *)&buffer[DOS_FS32_TYPE_OFFSET], "FAT32", 5) == 0)) {
 		/* ok, we assume we are on a PBR only */
fs/fat/fat_write.c new file +1091 -0

1,091 lines not on this page · raw message

include/fat.h +3 -0
index 15dbf10..4c92442 100644
@@ -99,6 +99,8 @@
 #endif
 
 #define TOLOWER(c)	if((c) >= 'A' && (c) <= 'Z'){(c)+=('a' - 'A');}
+#define TOUPPER(c)	if ((c) >= 'a' && (c) <= 'z') \
+				(c) -= ('a' - 'A');
 #define START(dent)	(FAT2CPU16((dent)->start) \
 			+ (mydata->fatsize != 32 ? 0 : \
 			  (FAT2CPU16((dent)->starthi) << 16)))
@@ -210,4 +212,5 @@ long file_fat_read(const char *filename, void *buffer, unsigned long maxsize);
 const char *file_getfsname(int idx);
 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);
 #endif /* _FAT_H_ */
Signature · 1 line
1.7.4.1
#1 lore raw

PATCH RESEND 1/1 FAT: Add FAT write feature

Dear Donggeun Kim,

Quoted 24 lines · In message <[email protected]> you wrote:

In some cases, saving data in RAM as a file with FAT format is required. This patch allows the file to be written in FAT formatted partition.

The usage is similar with reading a file.
First, fat_register_device function is called before file_fat_write function in order to set target partition.
Then, file_fat_write function is invoked with desired file name, start ram address for writing data, and file size.

---
 fs/fat/Makefile    |    1 +
 fs/fat/fat.c       |    2 +
 fs/fat/fat_write.c | 1091 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/fat.h      |    3 +
 4 files changed, 1097 insertions(+), 0 deletions(-)
 create mode 100644 fs/fat/fat_write.c
fs/fat/Makefile +0 -0
index 93b6f07..9635d36 100644

fs/fat/Makefile LIB = $(obj)libfat.o · line 28

Quoted 4 lines
fs/fat/Makefile +1 -0
@@ -25,6 +25,7 @@ LIB	= $(obj)libfat.o
 
 AOBJS	=
 COBJS-$(CONFIG_CMD_FAT)	:= fat.o
+COBJS-$(CONFIG_FAT_WRITE):= fat_write.o

Can ypu please document this new CONFIG_FAT_WRITE option in the README? Thanks.

Best regards,

Wolfgang Denk

Signature · 5 lines
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
"A complex system that works is invariably found to have evolved from
a simple system that worked."             - John Gall, _Systemantics_