Skip to contentSkip to conversation

FAT32: "Superfloppy" format and other fixes

PATCH New Wolfgang Denk 2 participants 13 messages Jul 19, 2010 – Aug 1, 2010 VFAT/FAT/msdos filesystem

lore
Share & tools
lore
#0 lore raw

cover FAT32: "Superfloppy" format and other fixes

"Superfloppy" format (in U-Boot called PBR) did not work for FAT32 due to several errors; some errors appaeared only in certain configurations (like directories with more than 128 entries, etc.). These patches are supposed to fix these issues.

Wolfgang Denk (5):
usb_storage.c: initialize device type
FAT32: fix support for superfloppy-format (PBR)
FAT32: fix broken root directory handling. usb_storage.c: change progress output in debug() message fs/fat: Big code cleanup.

 common/cmd_fat.c     |  210 ++--------
 common/usb_storage.c |    9 +-
 disk/part_dos.c      |    4 +-
 disk/part_dos.h      |    3 +-
 fs/fat/fat.c         | 1143 ++++++++++++++++++++++++++++----------------------
 fs/fat/file.c        |   14 +-
 include/fat.h        |   63 ++--
 7 files changed, 717 insertions(+), 729 deletions(-)

Best regards,

Wolfgang Denk

Signature · 7 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
Misquotation is, in fact, the pride and privilege of the  learned.  A
widely-read  man  never  quotes  accurately,  for  the rather obvious
reason that he has read too widely.
                - Hesketh Pearson _Common Misquotations_ introduction
#1 lore raw

PATCH 1/5 usb_storage.c: initialize device type

The device type was left uninitialized which caused later tests against DEV_TYPE_UNKNOWN to fail. In the result, "usb part" would attempt to print information about non-existent devices like this:

=> usb part
print_part of 0

Partition Map for USB device 0 -- Partition Type: DOS

Partition Start Sector Num Sectors Type
1 0 2031616 f8

print_part of 1
## Unknown partition table

print_part of 2
## Unknown partition table

print_part of 3
## Unknown partition table

print_part of 4
## Unknown partition table
=>

By initializing the type as DEV_TYPE_UNKNOWN we avoid all the "Unknown partition table" messages.

[Note: the "print_part of ?" messages is left over debug code that will be removed in another patch.]

---
 common/usb_storage.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
common/usb_storage.c +2 -1
index 4fc01a2..9f31265 100644
@@ -224,10 +224,11 @@ int usb_stor_scan(int mode)
 
 	for (i = 0; i < USB_MAX_STOR_DEV; i++) {
 		memset(&usb_dev_desc[i], 0, sizeof(block_dev_desc_t));
-		usb_dev_desc[i].target = 0xff;
 		usb_dev_desc[i].if_type = IF_TYPE_USB;
 		usb_dev_desc[i].dev = i;
 		usb_dev_desc[i].part_type = PART_TYPE_UNKNOWN;
+		usb_dev_desc[i].target = 0xff;
+		usb_dev_desc[i].type = DEV_TYPE_UNKNOWN;
 		usb_dev_desc[i].block_read = usb_stor_read;
 		usb_dev_desc[i].block_write = usb_stor_write;
 	}
Signature · 1 line
1.6.2.5
author Applied
#2 lore raw

PATCH 1/5 usb_storage.c: initialize device type

Dear Wolfgang Denk,

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

The device type was left uninitialized which caused later tests against DEV_TYPE_UNKNOWN to fail. In the result, "usb part" would attempt to print information about non-existent devices like this:

=> usb part
print_part of 0

Partition Map for USB device 0 -- Partition Type: DOS

Partition Start Sector Num Sectors Type
1 0 2031616 f8

print_part of 1
## Unknown partition table

print_part of 2
## Unknown partition table

print_part of 3
## Unknown partition table

print_part of 4
## Unknown partition table
=>

By initializing the type as DEV_TYPE_UNKNOWN we avoid all the "Unknown partition table" messages.

[Note: the "print_part of ?" messages is left over debug code that will be removed in another patch.]

Quoted 6 lines
---
 common/usb_storage.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

Applied.

Remy, I hope this is OK with you?

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
All your people must learn before you can reach for the stars.
	-- Kirk, "The Gamesters of Triskelion", stardate 3259.2
#3 lore raw

PATCH 1/5 usb_storage.c: initialize device type

Hi,

2010/7/24 Wolfgang Denk <[email protected]>:

Quoted 9 lines

Dear Wolfgang Denk,

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

The device type was left uninitialized which caused later tests against DEV_TYPE_UNKNOWN to fail. In the result, "usb part" would attempt to print information about non-existent devices like this:

Quoted 7 lines
Quoted 3 lines

---
?common/usb_storage.c | ? ?3 ++-
?1 files changed, 2 insertions(+), 1 deletions(-)

Applied.

Remy, I hope this is OK with you?

OK with me.
Thanks.

Remy

#4 lore raw

PATCH 2/5 FAT32: fix support for superfloppy-format (PBR)

In reply to Wolfgang Denk

"Superfloppy" format (in U-Boot called PBR) did not work for FAT32 as the file system type string is at a different location. Add support for FAT32.

---
 disk/part_dos.c |    4 +++-
 disk/part_dos.h |    3 ++-
 fs/fat/fat.c    |    4 +++-
 3 files changed, 8 insertions(+), 3 deletions(-)
disk/part_dos.c +3 -1
index 887b75e..2de1bb8 100644
@@ -77,8 +77,10 @@ static int test_block_type(unsigned char *buffer)
 	    (buffer[DOS_PART_MAGIC_OFFSET + 1] != 0xaa) ) {
 		return (-1);
 	} /* no DOS Signature at all */
-	if(strncmp((char *)&buffer[DOS_PBR_FSTYPE_OFFSET],"FAT",3)==0)
+	if (strncmp((char *)&buffer[DOS_PBR_FSTYPE_OFFSET],"FAT",3)==0 ||
+	    strncmp((char *)&buffer[DOS_PBR32_FSTYPE_OFFSET],"FAT32",5)==0) {
 		return DOS_PBR; /* is PBR */
+	}
 	return DOS_MBR;	    /* Is MBR */
 }
 
disk/part_dos.h +2 -1
index ac93f20..195a32c 100644
@@ -28,13 +28,14 @@
 #ifdef CONFIG_ISO_PARTITION
 /* Make the buffers bigger if ISO partition support is enabled -- CD-ROMS
    have 2048 byte blocks */
-#define DEFAULT_SECTOR_SIZE   2048
+#define DEFAULT_SECTOR_SIZE	2048
 #else
 #define DEFAULT_SECTOR_SIZE	512
 #endif
 #define DOS_PART_TBL_OFFSET	0x1be
 #define DOS_PART_MAGIC_OFFSET	0x1fe
 #define DOS_PBR_FSTYPE_OFFSET	0x36
+#define DOS_PBR32_FSTYPE_OFFSET	0x52
 #define DOS_PBR_MEDIA_TYPE_OFFSET	0x15
 #define DOS_MBR	0
 #define DOS_PBR	1
fs/fat/fat.c +3 -1
index 6b3a274..0b2febe 100644
@@ -50,6 +50,7 @@ static int cur_part = 1;
 #define DOS_PART_TBL_OFFSET	0x1be
 #define DOS_PART_MAGIC_OFFSET	0x1fe
 #define DOS_FS_TYPE_OFFSET	0x36
+#define DOS_FS32_TYPE_OFFSET	0x52
 
 int disk_read (__u32 startblock, __u32 getsize, __u8 * bufptr)
 {
@@ -94,7 +95,8 @@ 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;
-	} else if (!strncmp((char *)&buffer[DOS_FS_TYPE_OFFSET], "FAT", 3)) {
+	} 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 */
 		cur_part = 1;
 		part_offset = 0;
Signature · 1 line
1.6.2.5
author Applied
#5 lore raw

PATCH 2/5 FAT32: fix support for superfloppy-format (PBR)

Dear Wolfgang Denk,

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

"Superfloppy" format (in U-Boot called PBR) did not work for FAT32 as the file system type string is at a different location. Add support for FAT32.

---
 disk/part_dos.c |    4 +++-
 disk/part_dos.h |    3 ++-
 fs/fat/fat.c    |    4 +++-
 3 files changed, 8 insertions(+), 3 deletions(-)

Applied.

Best regards,

Wolfgang Denk

Signature · 6 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
The ideal situation is to have massive computing power right at home.
Something that dims the streetlights and shrinks the picture  on  the
neighbours' TVs when you boot it up.
#6 lore raw

PATCH 3/5 FAT32: fix broken root directory handling.

In reply to Wolfgang Denk

On FAT32, instead of fetching the cluster numbers from the FAT, the code assumed (incorrectly) that the clusters for the root directory were allocated contiguously. In the result, only the first cluster could be accessed. At the typical cluster size of 8 sectors this caused all accesses to files after the first 128 entries to fail - "fatls" would terminate after 128 files (usually displaying a bogus file name, occasionally even crashing the system), and "fatload" would fail to find any files that were not in the first directory cluster.

---
 fs/fat/fat.c |   60 ++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 50 insertions(+), 10 deletions(-)
fs/fat/fat.c +50 -10
index 0b2febe..413c687 100644
@@ -200,6 +200,9 @@ get_fatent(fsdata *mydata, __u32 entry)
 		return ret;
 	}
 
+	FAT_DPRINT("FAT%d: entry: 0x%04x = %d, offset: 0x%04x = %d\n",
+		mydata->fatsize, entry, entry, offset, offset);
+
 	/* Read a new block of FAT entries into the cache. */
 	if (bufnum != mydata->fatbufnum) {
 		int getsize = FATBUFSIZE/FS_BLOCK_SIZE;
@@ -259,7 +262,8 @@ get_fatent(fsdata *mydata, __u32 entry)
 	}
 	break;
 	}
-	FAT_DPRINT("ret: %d, offset: %d\n", ret, offset);
+	FAT_DPRINT("FAT%d: ret: %08x, offset: %04x\n",
+		mydata->fatsize, ret, offset);
 
 	return ret;
 }
@@ -322,7 +326,7 @@ get_contents(fsdata *mydata, dir_entry *dentptr, __u8 *buffer,
 
 	if (maxsize > 0 && filesize > maxsize) filesize = maxsize;
 
-	FAT_DPRINT("Reading: %ld bytes\n", filesize);
+	FAT_DPRINT("%ld bytes\n", filesize);
 
 	actsize=bytesperclust;
 	endclust=curclust;
@@ -718,16 +722,19 @@ do_fat_read (const char *filename, void *buffer, unsigned long maxsize,
     dir_entry *dentptr;
     __u16 prevcksum = 0xffff;
     char *subname = "";
-    int rootdir_size, cursect;
+    int cursect;
     int idx, isdir = 0;
     int files = 0, dirs = 0;
     long ret = 0;
     int firsttime;
+    int root_cluster;
+    int j;
 
     if (read_bootsectandvi (&bs, &volinfo, &mydata->fatsize)) {
 	FAT_DPRINT ("Error: reading boot sector\n");
 	return -1;
     }
+	root_cluster = bs.root_cluster;
     if (mydata->fatsize == 32) {
 	mydata->fatlength = bs.fat32_length;
     } else {
@@ -738,10 +745,11 @@ do_fat_read (const char *filename, void *buffer, unsigned long maxsize,
 	    = mydata->fat_sect + mydata->fatlength * bs.fats;
     mydata->clust_size = bs.cluster_size;
     if (mydata->fatsize == 32) {
-	rootdir_size = mydata->clust_size;
-	mydata->data_begin = mydata->rootdir_sect   /* + rootdir_size */
+	mydata->data_begin = mydata->rootdir_sect
 		- (mydata->clust_size * 2);
     } else {
+	int rootdir_size;
+
 	rootdir_size = ((bs.dir_entries[1] * (int) 256 + bs.dir_entries[0])
 			* sizeof (dir_entry)) / SECTOR_SIZE;
 	mydata->data_begin = mydata->rootdir_sect + rootdir_size
@@ -749,12 +757,19 @@ do_fat_read (const char *filename, void *buffer, unsigned long maxsize,
     }
     mydata->fatbufnum = -1;
 
-    FAT_DPRINT ("FAT%d, fatlength: %d\n", mydata->fatsize,
+#ifdef CONFIG_SUPPORT_VFAT
+    FAT_DPRINT ("VFAT Support enabled\n");
+#endif
+    FAT_DPRINT ("FAT%d, fat_sect: %d, fatlength: %d\n",
+		mydata->fatsize,
+		mydata->fat_sect,
 		mydata->fatlength);
-    FAT_DPRINT ("Rootdir begins at sector: %d, offset: %x, size: %d\n"
+    FAT_DPRINT ("Rootdir begins at cluster: %d, sector: %d, offset: %x\n"
 		"Data begins at: %d\n",
-		mydata->rootdir_sect, mydata->rootdir_sect * SECTOR_SIZE,
-		rootdir_size, mydata->data_begin);
+		root_cluster,
+		mydata->rootdir_sect,
+		mydata->rootdir_sect * SECTOR_SIZE,
+		mydata->data_begin);
     FAT_DPRINT ("Cluster size: %d\n", mydata->clust_size);
 
     /* "cwd" is always the root... */
@@ -778,9 +793,12 @@ do_fat_read (const char *filename, void *buffer, unsigned long maxsize,
 	isdir = 1;
     }
 
+    j=0;
     while (1) {
 	int i;
 
+	FAT_DPRINT ("FAT read sect=%d, clust_size=%d, DIRENTSPERBLOCK=%d\n",
+		cursect, mydata->clust_size, DIRENTSPERBLOCK);
 	if (disk_read (cursect, mydata->clust_size, do_fat_read_block) < 0) {
 	    FAT_DPRINT ("Error: reading rootdir block\n");
 	    return -1;
@@ -893,7 +911,29 @@ do_fat_read (const char *filename, void *buffer, unsigned long maxsize,
 
 	    goto rootdir_done;  /* We got a match */
 	}
-	cursect++;
+	FAT_DPRINT ("END LOOP: j=%d   clust_size=%d\n", j, mydata->clust_size);
+
+	/*
+	 * On FAT32 we must fetch the FAT entries for the next
+	 * root directory clusters when a cluster has been
+	 * completely processed.
+	 */
+	if ((mydata->fatsize == 32) && (++j == mydata->clust_size)) {
+		int nxtsect;
+		int cur_clust, nxt_clust;
+
+		cur_clust = (cursect - mydata->data_begin) / mydata->clust_size;
+		nxt_clust = get_fatent(mydata, root_cluster);
+		nxtsect = mydata->data_begin + (nxt_clust * mydata->clust_size);
+		FAT_DPRINT ("END LOOP: sect=%d, clust=%d, root_clust=%d, n_sect=%d, n_clust=%d\n",
+			cursect, cur_clust, root_cluster, nxtsect, nxt_clust);
+		root_cluster = nxt_clust;
+
+		cursect = nxtsect;
+		j = 0;
+	} else {
+		cursect++;
+	}
     }
   rootdir_done:
 
Signature · 1 line
1.6.2.5
author Applied
#7 lore raw

PATCH 3/5 FAT32: fix broken root directory handling.

Dear Wolfgang Denk,

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

On FAT32, instead of fetching the cluster numbers from the FAT, the code assumed (incorrectly) that the clusters for the root directory were allocated contiguously. In the result, only the first cluster could be accessed. At the typical cluster size of 8 sectors this caused all accesses to files after the first 128 entries to fail - "fatls" would terminate after 128 files (usually displaying a bogus file name, occasionally even crashing the system), and "fatload" would fail to find any files that were not in the first directory cluster.

Quoted 4 lines
---
 fs/fat/fat.c |   60 ++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 50 insertions(+), 10 deletions(-)

Applied.

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
The first thing we do is kill all the lawyers.
(Shakespeare. II Henry VI, Act IV, scene ii)
#8 lore raw

PATCH 4/5 usb_storage.c: change progress output in debug() message

In reply to Wolfgang Denk

The dots printed by common/usb_storage.c as progress meter corrupt the output for example of "fatls usb" commands like this:

=> fatls usb 0
. <<==== here

       29   file.001
       29   file.002
       29   file.003
       29   file.004
       29   file.005
       29   file.006
       29   file.007
       29   file.008
       29   file.009
       29   file.010
       29   file.011
       29   file.012
       29   file.013
       29   file.014
       29   file.015
       29   file.016
.			<<==== here
       29   file.017
       29   file.018
       29   file.019

...

Turn the progress output into a debug message.

---
 common/usb_storage.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
common/usb_storage.c +3 -3
index 9f31265..76949b8 100644
@@ -181,7 +181,7 @@ block_dev_desc_t *usb_stor_get_dev(int index)
 
 void usb_show_progress(void)
 {
-	printf(".");
+	debug(".");
 }
 
 /*******************************************************************************
@@ -1081,7 +1081,7 @@ retry_it:
 
 	usb_disable_asynch(0); /* asynch transfer allowed */
 	if (blkcnt >= USB_MAX_READ_BLK)
-		printf("\n");
+		debug("\n");
 	return blkcnt;
 }
 
@@ -1161,7 +1161,7 @@ retry_it:
 
 	usb_disable_asynch(0); /* asynch transfer allowed */
 	if (blkcnt >= USB_MAX_WRITE_BLK)
-		printf("\n");
+		debug("\n");
 	return blkcnt;
 
 }
Signature · 1 line
1.6.2.5
author Applied
#9 lore raw

PATCH 4/5 usb_storage.c: change progress output in debug() message

Dear Wolfgang Denk,

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

The dots printed by common/usb_storage.c as progress meter corrupt the output for example of "fatls usb" commands like this:

=> fatls usb 0
. <<==== here

       29   file.001
       29   file.002
       29   file.003
       29   file.004
       29   file.005
       29   file.006
       29   file.007
       29   file.008
       29   file.009
       29   file.010
       29   file.011
       29   file.012
       29   file.013
       29   file.014
       29   file.015
       29   file.016
.			<<==== here
       29   file.017
       29   file.018
       29   file.019

...

Quoted 7 lines

Turn the progress output into a debug message.

---
 common/usb_storage.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

Applied.

Remy, I hope this is OK with you?

Best regards,

Wolfgang Denk

Signature · 4 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
Brain off-line, please wait.
#10 lore raw

PATCH 4/5 usb_storage.c: change progress output in debug() message

Hi Wolfgang,

Quoted 11 lines
Quoted 7 lines

Turn the progress output into a debug message.

---
?common/usb_storage.c | ? ?6 +++---
?1 files changed, 3 insertions(+), 3 deletions(-)

Applied.

Remy, I hope this is OK with you?

Fine with me.
Thanks.

Remy

#11 lore raw

PATCH 5/5 fs/fat: Big code cleanup.

In reply to Wolfgang Denk

- reformat
- throw out macros like FAT_DPRINT and FAT_DPRINT
- remove dead code

---
 common/cmd_fat.c |  210 ++--------
 fs/fat/fat.c     | 1167 +++++++++++++++++++++++++++++-------------------------
 fs/fat/file.c    |   14 +-
 include/fat.h    |   63 ++--
 4 files changed, 698 insertions(+), 756 deletions(-)
common/cmd_fat.c +38 -172
index ede7308..0220494 100644
@@ -45,39 +45,43 @@ int do_fat_fsload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	char *ep;
 
 	if (argc < 5) {
-		printf ("usage: fatload <interface> <dev[:part]> <addr> <filename> [bytes]\n");
+		printf( "usage: fatload <interface> <dev[:part]> "
+			"<addr> <filename> [bytes]\n");
 		return 1;
 	}
-	dev = (int)simple_strtoul (argv[2], &ep, 16);
-	dev_desc=get_dev(argv[1],dev);
-	if (dev_desc==NULL) {
-		puts ("\n** Invalid boot device **\n");
+
+	dev = (int)simple_strtoul(argv[2], &ep, 16);
+	dev_desc = get_dev(argv[1],dev);
+	if (dev_desc == NULL) {
+		puts("\n** Invalid boot device **\n");
 		return 1;
 	}
 	if (*ep) {
 		if (*ep != ':') {
-			puts ("\n** Invalid boot device, use `dev[:part]' **\n");
+			puts("\n** Invalid boot device, use `dev[:part]' **\n");
 			return 1;
 		}
 		part = (int)simple_strtoul(++ep, NULL, 16);
 	}
 	if (fat_register_device(dev_desc,part)!=0) {
-		printf ("\n** Unable to use %s %d:%d for fatload **\n",argv[1],dev,part);
+		printf("\n** Unable to use %s %d:%d for fatload **\n",
+			argv[1], dev, part);
 		return 1;
 	}
-	offset = simple_strtoul (argv[3], NULL, 16);
+	offset = simple_strtoul(argv[3], NULL, 16);
 	if (argc == 6)
-		count = simple_strtoul (argv[5], NULL, 16);
+		count = simple_strtoul(argv[5], NULL, 16);
 	else
 		count = 0;
-	size = file_fat_read (argv[4], (unsigned char *) offset, count);
+	size = file_fat_read(argv[4], (unsigned char *)offset, count);
 
 	if(size==-1) {
-		printf("\n** Unable to read \"%s\" from %s %d:%d **\n",argv[4],argv[1],dev,part);
+		printf("\n** Unable to read \"%s\" from %s %d:%d **\n",
+			argv[4], argv[1], dev, part);
 		return 1;
 	}
 
-	printf ("\n%ld bytes read\n", size);
+	printf("\n%ld bytes read\n", size);
 
 	sprintf(buf, "%lX", size);
 	setenv("filesize", buf);
@@ -104,34 +108,35 @@ int do_fat_ls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	block_dev_desc_t *dev_desc=NULL;
 
 	if (argc < 3) {
-		printf ("usage: fatls <interface> <dev[:part]> [directory]\n");
-		return (0);
+		printf("usage: fatls <interface> <dev[:part]> [directory]\n");
+		return 0;
 	}
-	dev = (int)simple_strtoul (argv[2], &ep, 16);
-	dev_desc=get_dev(argv[1],dev);
-	if (dev_desc==NULL) {
-		puts ("\n** Invalid boot device **\n");
+	dev = (int)simple_strtoul(argv[2], &ep, 16);
+	dev_desc = get_dev(argv[1],dev);
+	if (dev_desc == NULL) {
+		puts("\n** Invalid boot device **\n");
 		return 1;
 	}
 	if (*ep) {
 		if (*ep != ':') {
-			puts ("\n** Invalid boot device, use `dev[:part]' **\n");
+			puts("\n** Invalid boot device, use `dev[:part]' **\n");
 			return 1;
 		}
 		part = (int)simple_strtoul(++ep, NULL, 16);
 	}
 	if (fat_register_device(dev_desc,part)!=0) {
-		printf ("\n** Unable to use %s %d:%d for fatls **\n",argv[1],dev,part);
+		printf("\n** Unable to use %s %d:%d for fatls **\n",
+			argv[1], dev, part);
 		return 1;
 	}
 	if (argc == 4)
-		ret = file_fat_ls (argv[3]);
+		ret = file_fat_ls(argv[3]);
 	else
-		ret = file_fat_ls (filename);
+		ret = file_fat_ls(filename);
 
 	if(ret!=0)
 		printf("No Fat FS detected\n");
-	return (ret);
+	return ret;
 }
 
 U_BOOT_CMD(
@@ -149,27 +154,28 @@ int do_fat_fsinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	block_dev_desc_t *dev_desc=NULL;
 
 	if (argc < 2) {
-		printf ("usage: fatinfo <interface> <dev[:part]>\n");
-		return (0);
+		printf("usage: fatinfo <interface> <dev[:part]>\n");
+		return 0;
 	}
-	dev = (int)simple_strtoul (argv[2], &ep, 16);
-	dev_desc=get_dev(argv[1],dev);
-	if (dev_desc==NULL) {
-		puts ("\n** Invalid boot device **\n");
+	dev = (int)simple_strtoul(argv[2], &ep, 16);
+	dev_desc = get_dev(argv[1],dev);
+	if (dev_desc == NULL) {
+		puts("\n** Invalid boot device **\n");
 		return 1;
 	}
 	if (*ep) {
 		if (*ep != ':') {
-			puts ("\n** Invalid boot device, use `dev[:part]' **\n");
+			puts("\n** Invalid boot device, use `dev[:part]' **\n");
 			return 1;
 		}
 		part = (int)simple_strtoul(++ep, NULL, 16);
 	}
 	if (fat_register_device(dev_desc,part)!=0) {
-		printf ("\n** Unable to use %s %d:%d for fatinfo **\n",argv[1],dev,part);
+		printf("\n** Unable to use %s %d:%d for fatinfo **\n",
+			argv[1], dev, part);
 		return 1;
 	}
-	return (file_fat_detectfs ());
+	return file_fat_detectfs();
 }
 
 U_BOOT_CMD(
@@ -178,143 +184,3 @@ U_BOOT_CMD(
 	"<interface> <dev[:part]>\n"
 	"    - print information about filesystem from 'dev' on 'interface'"
 );
-
-#ifdef NOT_IMPLEMENTED_YET
-/* find first device whose first partition is a DOS filesystem */
-int find_fat_partition (void)
-{
-	int i, j;
-	block_dev_desc_t *dev_desc;
-	unsigned char *part_table;
-	unsigned char buffer[ATA_BLOCKSIZE];
-
-	for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; i++) {
-		dev_desc = ide_get_dev (i);
-		if (!dev_desc) {
-			debug ("couldn't get ide device!\n");
-			return (-1);
-		}
-		if (dev_desc->part_type == PART_TYPE_DOS) {
-			if (dev_desc->
-				block_read (dev_desc->dev, 0, 1, (ulong *) buffer) != 1) {
-				debug ("can't perform block_read!\n");
-				return (-1);
-			}
-			part_table = &buffer[0x1be];	/* start with partition #4 */
-			for (j = 0; j < 4; j++) {
-				if ((part_table[4] == 1 ||	/* 12-bit FAT */
-				     part_table[4] == 4 ||	/* 16-bit FAT */
-				     part_table[4] == 6) &&	/* > 32Meg part */
-				    part_table[0] == 0x80) {	/* bootable? */
-					curr_dev = i;
-					part_offset = part_table[11];
-					part_offset <<= 8;
-					part_offset |= part_table[10];
-					part_offset <<= 8;
-					part_offset |= part_table[9];
-					part_offset <<= 8;
-					part_offset |= part_table[8];
-					debug ("found partition start@%ld\n", part_offset);
-					return (0);
-				}
-				part_table += 16;
-			}
-		}
-	}
-
-	debug ("no valid devices found!\n");
-	return (-1);
-}
-
-int
-do_fat_dump (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char * const argv[])
-{
-	__u8 block[1024];
-	int ret;
-	int bknum;
-
-	ret = 0;
-
-	if (argc != 2) {
-		printf ("needs an argument!\n");
-		return (0);
-	}
-
-	bknum = simple_strtoul (argv[1], NULL, 10);
-
-	if (disk_read (0, bknum, block) != 0) {
-		printf ("Error: reading block\n");
-		return -1;
-	}
-	printf ("FAT dump: %d\n", bknum);
-	hexdump (512, block);
-
-	return (ret);
-}
-
-int disk_read (__u32 startblock, __u32 getsize, __u8 *bufptr)
-{
-	ulong tot;
-	block_dev_desc_t *dev_desc;
-
-	if (curr_dev < 0) {
-		if (find_fat_partition () != 0)
-			return (-1);
-	}
-
-	dev_desc = ide_get_dev (curr_dev);
-	if (!dev_desc) {
-		debug ("couldn't get ide device\n");
-		return (-1);
-	}
-
-	tot = dev_desc->block_read (0, startblock + part_offset,
-				    getsize, (ulong *) bufptr);
-
-	/* should we do this here?
-	   flush_cache ((ulong)buf, cnt*ide_dev_desc[device].blksz);
-	 */
-
-	if (tot == getsize)
-		return (0);
-
-	debug ("unable to read from device!\n");
-
-	return (-1);
-}
-
-
-static int isprint (unsigned char ch)
-{
-	if (ch >= 32 && ch < 127)
-		return (1);
-
-	return (0);
-}
-
-
-void hexdump (int cnt, unsigned char *data)
-{
-	int i;
-	int run;
-	int offset;
-
-	offset = 0;
-	while (cnt) {
-		printf ("%04X : ", offset);
-		if (cnt >= 16)
-			run = 16;
-		else
-			run = cnt;
-		cnt -= run;
-		for (i = 0; i < run; i++)
-			printf ("%02X ", (unsigned int) data[i]);
-		printf (": ");
-		for (i = 0; i < run; i++)
-			printf ("%c", isprint (data[i]) ? data[i] : '.');
-		printf ("\n");
-		data = &data[16];
-		offset += run;
-	}
-}
-#endif	/* NOT_IMPLEMENTED_YET */
fs/fat/fat.c +626 -541

1,582 lines not on this page · raw message

fs/fat/file.c +5 -9
index e870734..59c5d37 100644
@@ -48,12 +48,12 @@ char file_cwd[CWD_LEN+1] = "/";
 const char *
 file_getfsname(int idx)
 {
-	if (idx < 0 || idx >= NUM_FILESYS) return NULL;
+	if (idx < 0 || idx >= NUM_FILESYS)
+		return NULL;
 
 	return filesystems[idx].name;
 }
 
-
 static void
 pathcpy(char *dest, const char *src)
 {
@@ -72,15 +72,14 @@ pathcpy(char *dest, const char *src)
 			return;
 		}
 		++dest;
-		if (ISDIRDELIM(*src)) {
+
+		if (ISDIRDELIM(*src))
 			while (ISDIRDELIM(*src)) src++;
-		} else {
+		else
 			src++;
-		}
 	} while (1);
 }
 
-
 int
 file_cd(const char *path)
 {
@@ -141,7 +140,6 @@ file_cd(const char *path)
 	return 0;
 }
 
-
 int
 file_detectfs(void)
 {
@@ -160,7 +158,6 @@ file_detectfs(void)
 	return current_filesystem;
 }
 
-
 int
 file_ls(const char *dir)
 {
@@ -181,7 +178,6 @@ file_ls(const char *dir)
 	return filesystems[current_filesystem].ls(arg);
 }
 
-
 long
 file_read(const char *filename, void *buffer, unsigned long maxsize)
 {
include/fat.h +29 -34

100 lines not on this page · raw message

Signature · 1 line
1.6.2.5
author Applied
#12 lore raw

PATCH 5/5 fs/fat: Big code cleanup.

Dear Wolfgang Denk,

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

- reformat
- throw out macros like FAT_DPRINT and FAT_DPRINT
- remove dead code

---
 common/cmd_fat.c |  210 ++--------
 fs/fat/fat.c     | 1167 +++++++++++++++++++++++++++++-------------------------
 fs/fat/file.c    |   14 +-
 include/fat.h    |   63 ++--
 4 files changed, 698 insertions(+), 756 deletions(-)

Applied.

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
"We don't have to protect the environment -- the Second Coming is  at
hand."                                                   - James Watt