* [U-Boot] [PATCH] FAT on non standard sector size devices
@ 2008-11-12 10:09 Igor Luri
2008-11-12 11:25 ` Remy Bohmer
0 siblings, 1 reply; 10+ messages in thread
From: Igor Luri @ 2008-11-12 10:09 UTC (permalink / raw)
To: u-boot
Hi all!
There are USB devices with sector size different than 512 bytes. In
fact, I have one with 2048 bytes per sector:
scsi0 : SCSI emulation for USB Mass Storage devices
Vendor: ChipsBnk Model: Flash Disk Rev: 4.00
Type: Direct-Access ANSI SCSI revision: 02
Attached scsi removable disk sda at scsi0, channel 0, id 0, lun 0
SCSI device sda: 129124 2048-byte hdwr sectors (264 MB)
sda: Write Protect is off
Partition check:
sda: sda1 sda2 sda3 sda4
U-boot FAT filesystem code supposes that sector size is always 512
bytes, consecuently fatload and fatls commands ends up with a
segmentation fault.
Attached patches adds FAT support on devices with sector size up to 8192
bytes.
I have only tested on our custom board with u-boot 1.1.6 version. I
would aprpeciate if someone could test this patch on latest version.
Thanks.
Signed-off-by: Igor Luri <iluri@aotek.es>
--
Igor Luri
R&D Software Department
Fagor Aotek S. Coop.
P. O. Box 144
E-20500 Mondrag?n-Arrasate
Tel. ++34 943 71 92 00
++34 943 71 92 01 (Ext. 44268)
Fax. ++34 943 79 92 03
www.aotek.es
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Add-support-for-non-standard-sector-size-devices.patch
Type: application/mbox
Size: 6252 bytes
Desc: not available
Url : http://lists.denx.de/pipermail/u-boot/attachments/20081112/a684ed52/attachment-0002.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-Add-support-for-non-standard-sector-size-devices.patch
Type: application/mbox
Size: 2053 bytes
Desc: not available
Url : http://lists.denx.de/pipermail/u-boot/attachments/20081112/a684ed52/attachment-0003.bin
^ permalink raw reply [flat|nested] 10+ messages in thread
* [U-Boot] [PATCH] FAT on non standard sector size devices
2008-11-12 10:09 Igor Luri
@ 2008-11-12 11:25 ` Remy Bohmer
0 siblings, 0 replies; 10+ messages in thread
From: Remy Bohmer @ 2008-11-12 11:25 UTC (permalink / raw)
To: u-boot
Hello Igor,
2008/11/12 Igor Luri <iluri@aotek.es>:
> Hi all!
>
> There are USB devices with sector size different than 512 bytes. In
> fact, I have one with 2048 bytes per sector:
>
> scsi0 : SCSI emulation for USB Mass Storage devices
> Vendor: ChipsBnk Model: Flash Disk Rev: 4.00
> Type: Direct-Access ANSI SCSI revision: 02
> Attached scsi removable disk sda at scsi0, channel 0, id 0, lun 0
> SCSI device sda: 129124 2048-byte hdwr sectors (264 MB)
> sda: Write Protect is off
> Partition check:
> sda: sda1 sda2 sda3 sda4
>
> U-boot FAT filesystem code supposes that sector size is always 512
> bytes, consecuently fatload and fatls commands ends up with a
> segmentation fault.
>
> Attached patches adds FAT support on devices with sector size up to 8192
> bytes.
Please only sent patches inline, see http://lwn.net/Articles/139918/
for more info
> I have only tested on our custom board with u-boot 1.1.6 version. I
> would aprpeciate if someone could test this patch on latest version.
I just looked at it (not tested it yet), and I have some comments:
> - unsigned char buffer[SECTOR_SIZE];
> + unsigned char buffer[8192];
> disk_partition_t info;
Why hardcode this size to 8192, cant it be malloced somehow?
Is there a check that detects if the size is getting bigger than 8192
to prevent segfaults?
> if (!dev_desc->block_read)
> @@ -184,7 +185,7 @@ static void get_name (dir_entry *dirent, char *s_name)
> if (*s_name == DELETED_FLAG)
> *s_name = '\0';
> else if (*s_name == aRING)
> - *s_name = '?';
> + *s_name = '???';
Some weird characters here... Is this change what you want?
Kind Regards,
Remy
^ permalink raw reply [flat|nested] 10+ messages in thread
* [U-Boot] [PATCH] FAT on non standard sector size devices
[not found] <1226492854.5686.8.camel@txema-desktop>
@ 2008-11-12 13:21 ` Igor Luri
0 siblings, 0 replies; 10+ messages in thread
From: Igor Luri @ 2008-11-12 13:21 UTC (permalink / raw)
To: u-boot
> Please only sent patches inline, see http://lwn.net/Articles/139918/
Sorry.
> Why hardcode this size to 8192, cant it be malloced somehow?
> Is there a check that detects if the size is getting bigger than 8192
> to prevent segfaults?
>
In read_bootsectandvi function already isn't known device sector size, so I define quite large sector size of 8 Kbyte.
It can be malloced if I get the sector size of the device from block_dev_desc_t. I am going to double check it, and if
it works, I'll send the definitive patch.
> Some weird characters here... Is this change what you want?
Sorry, I don't know how I have changed thouse caracters, I will correct this too.
Thanks.
--
Igor Luri
R&D Software Department
Fagor Aotek S. Coop.
P. O. Box 144
E-20500 Mondrag?n-Arrasate
Tel. ++34 943 71 92 00
++34 943 71 92 01 (Ext. 44268)
Fax. ++34 943 79 92 03
www.aotek.es
^ permalink raw reply [flat|nested] 10+ messages in thread
* [U-Boot] [PATCH] FAT on non standard sector size devices
@ 2008-11-12 16:30 Igor Luri
2008-11-12 19:21 ` Remy Bohmer
2008-11-12 22:01 ` Wolfgang Denk
0 siblings, 2 replies; 10+ messages in thread
From: Igor Luri @ 2008-11-12 16:30 UTC (permalink / raw)
To: u-boot
Hi all!
I have done some changes sugested by Remy Bohme and finally the
following patch adds FAT support on devices of ANY sector size.
I have only tested on our custom board with u-boot 1.1.6 version. I
would appreciate if someone could test this patch on latest version.
Thanks.
Signed-off-by: Igor Luri <iluri@aotek.es>
diff --git a/include/fat.h b/include/fat.h
index 59de3fb..dad2e3d 100644
--- a/include/fat.h
+++ b/include/fat.h
@@ -31,20 +31,12 @@
#define CONFIG_SUPPORT_VFAT
-#define SECTOR_SIZE FS_BLOCK_SIZE
-
-#define FS_BLOCK_SIZE 512
-
-#if FS_BLOCK_SIZE != SECTOR_SIZE
-#error FS_BLOCK_SIZE != SECTOR_SIZE - This code needs to be fixed!
-#endif
-
#define MAX_CLUSTSIZE 65536
-#define DIRENTSPERBLOCK (FS_BLOCK_SIZE/sizeof(dir_entry))
-#define DIRENTSPERCLUST
((mydata->clust_size*SECTOR_SIZE)/sizeof(dir_entry))
+#define DIRENTSPERBLOCK (mydata->sector_size/sizeof(dir_entry))
+#define DIRENTSPERCLUST
((mydata->clust_size*mydata->sector_size)/sizeof(dir_entry))
#define FATBUFBLOCKS 6
-#define FATBUFSIZE (FS_BLOCK_SIZE*FATBUFBLOCKS)
+#define FATBUFSIZE (mydata->sector_size*FATBUFBLOCKS)
#define FAT12BUFSIZE ((FATBUFSIZE*2)/3)
#define FAT16BUFSIZE (FATBUFSIZE/2)
#define FAT32BUFSIZE (FATBUFSIZE/4)
@@ -182,8 +174,9 @@ typedef struct dir_slot {
* (see FAT32 accesses)
*/
typedef struct {
- __u8 fatbuf[FATBUFSIZE]; /* Current FAT buffer */
+ __u8 *fatbuf; /* Current FAT buffer */
int fatsize; /* Size of FAT in bits */
+ __u16 sector_size; /* Sector size */
__u16 fatlength; /* Length of FAT in sectors */
__u16 fat_sect; /* Starting sector of the FAT */
__u16 rootdir_sect; /* Start sector of root directory */
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index 2f0bd8c..c24f009 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -30,6 +30,7 @@
#include <fat.h>
#include <asm/byteorder.h>
#include <part.h>
+#include <malloc.h>
/*
* Convert a string to lowercase.
@@ -67,12 +68,17 @@ int disk_read (__u32 startblock, __u32 getsize, __u8
* bufptr)
int
fat_register_device(block_dev_desc_t *dev_desc, int part_no)
{
- unsigned char buffer[SECTOR_SIZE];
+ unsigned char *buffer;
disk_partition_t info;
if (!dev_desc->block_read)
return -1;
- cur_dev = dev_desc;
+ cur_dev=dev_desc;
+
+ buffer = malloc (cur_dev->blksz);
+ if(buffer == NULL)
+ return(-1);
+
/* check if we have a MBR (on floppies we have only a PBR) */
if (dev_desc->block_read (dev_desc->dev, 0, 1, (ulong *) buffer) != 1)
{
printf ("** Can't read from device %d **\n", dev_desc->dev);
@@ -118,6 +124,7 @@ fat_register_device(block_dev_desc_t *dev_desc, int
part_no)
cur_part = 1;
}
#endif
+ free(buffer);
return 0;
}
@@ -220,12 +227,12 @@ get_fatent(fsdata *mydata, __u32 entry)
/* Read a new block of FAT entries into the cache. */
if (bufnum != mydata->fatbufnum) {
- int getsize = FATBUFSIZE/FS_BLOCK_SIZE;
+ int getsize = FATBUFSIZE/mydata->sector_size;
__u8 *bufptr = mydata->fatbuf;
__u32 fatlength = mydata->fatlength;
__u32 startblock = bufnum * FATBUFBLOCKS;
- fatlength *= SECTOR_SIZE; /* We want it in bytes now */
+ fatlength *= mydata->sector_size; /* We want it in bytes now */
startblock += mydata->fat_sect; /* Offset from start of disk */
if (getsize > fatlength) getsize = fatlength;
@@ -300,20 +307,25 @@ get_cluster(fsdata *mydata, __u32 clustnum, __u8
*buffer, unsigned long size)
}
FAT_DPRINT("gc - clustnum: %d, startsect: %d\n", clustnum, startsect);
- if (disk_read(startsect, size/FS_BLOCK_SIZE , buffer) < 0) {
+ if (disk_read(startsect, size/mydata->sector_size , buffer) < 0) {
FAT_DPRINT("Error reading data\n");
return -1;
}
- if(size % FS_BLOCK_SIZE) {
- __u8 tmpbuf[FS_BLOCK_SIZE];
- idx= size/FS_BLOCK_SIZE;
+ if(size % mydata->sector_size) {
+ __u8 * tmpbuf;
+
+ tmpbuf = (__u8*) malloc(mydata->sector_size);
+ if(tmpbuf == NULL)
+ return(-1);
+ idx= size/mydata->sector_size;
if (disk_read(startsect + idx, 1, tmpbuf) < 0) {
FAT_DPRINT("Error reading data\n");
return -1;
}
- buffer += idx*FS_BLOCK_SIZE;
+ buffer += idx*mydata->sector_size;
- memcpy(buffer, tmpbuf, size % FS_BLOCK_SIZE);
+ memcpy(buffer, tmpbuf, size % mydata->sector_size);
+ free(tmpbuf);
return 0;
}
@@ -331,7 +343,7 @@ get_contents(fsdata *mydata, dir_entry *dentptr,
__u8 *buffer,
unsigned long maxsize)
{
unsigned long filesize = FAT2CPU32(dentptr->size), gotsize = 0;
- unsigned int bytesperclust = mydata->clust_size * SECTOR_SIZE;
+ unsigned int bytesperclust = mydata->clust_size * mydata->sector_size;
__u32 curclust = START(dentptr);
__u32 endclust, newclust;
unsigned long actsize;
@@ -440,7 +452,7 @@ get_vfatname(fsdata *mydata, int curclust, __u8
*cluster,
{
dir_entry *realdent;
dir_slot *slotptr = (dir_slot*) retdent;
- __u8 *nextclust = cluster + mydata->clust_size * SECTOR_SIZE;
+ __u8 *nextclust = cluster + mydata->clust_size *
mydata->sector_size;
__u8 counter = (slotptr->id & ~LAST_LONG_ENTRY_MASK) & 0xff;
int idx = 0;
@@ -463,7 +475,7 @@ get_vfatname(fsdata *mydata, int curclust, __u8
*cluster,
return -1;
}
if (get_cluster(mydata, curclust, get_vfatname_block,
- mydata->clust_size * SECTOR_SIZE) != 0) {
+ mydata->clust_size * mydata->sector_size) != 0) {
FAT_DPRINT("Error: reading directory block\n");
return -1;
}
@@ -534,7 +546,7 @@ static dir_entry *get_dentfromdir (fsdata * mydata,
int startsect,
int i;
if (get_cluster (mydata, curclust, get_dentfromdir_block,
- mydata->clust_size * SECTOR_SIZE) != 0) {
+ mydata->clust_size * mydata->sector_size) != 0) {
FAT_DPRINT ("Error: reading directory block\n");
return NULL;
}
@@ -667,9 +679,16 @@ static dir_entry *get_dentfromdir (fsdata * mydata,
int startsect,
static int
read_bootsectandvi(boot_sector *bs, volume_info *volinfo, int *fatsize)
{
- __u8 block[FS_BLOCK_SIZE];
+ __u8 *block;
volume_info *vistart;
+ if(cur_dev == NULL)
+ return(-1);
+
+ block = (__u8 *)malloc (cur_dev->blksz);
+ if(block == NULL)
+ return(-1);
+
if (disk_read(0, 1, block) < 0) {
FAT_DPRINT("Error: reading block\n");
return -1;
@@ -680,6 +699,7 @@ read_bootsectandvi(boot_sector *bs, volume_info
*volinfo, int *fatsize)
bs->fat_length = FAT2CPU16(bs->fat_length);
bs->secs_track = FAT2CPU16(bs->secs_track);
bs->heads = FAT2CPU16(bs->heads);
+ *(__u16 *)bs->sector_size = FAT2CPU16(*(__u16 *)bs->sector_size);
#if 0 /* UNUSED */
bs->hidden = FAT2CPU32(bs->hidden);
#endif
@@ -704,7 +724,7 @@ read_bootsectandvi(boot_sector *bs, volume_info
*volinfo, int *fatsize)
/* Terminate fs_type string. Writing past the end of vistart
is ok - it's just the buffer. */
vistart->fs_type[8] = '\0';
-
+ free(block);
if (*fatsize == 32) {
if (compare_sign(FAT32_SIGN, vistart->fs_type) == 0) {
return 0;
@@ -757,6 +777,7 @@ do_fat_read (const char *filename, void *buffer,
unsigned long maxsize,
mydata->fatlength = bs.fat_length;
}
mydata->fat_sect = bs.reserved;
+ mydata->sector_size = *(__u16 *)bs.sector_size;
cursect = mydata->rootdir_sect
= mydata->fat_sect + mydata->fatlength * bs.fats;
mydata->clust_size = bs.cluster_size;
@@ -766,17 +787,20 @@ do_fat_read (const char *filename, void *buffer,
unsigned long maxsize,
- (mydata->clust_size * 2);
} else {
rootdir_size = ((bs.dir_entries[1] * (int) 256 + bs.dir_entries[0])
- * sizeof (dir_entry)) / SECTOR_SIZE;
+ * sizeof (dir_entry)) / mydata->sector_size;
mydata->data_begin = mydata->rootdir_sect + rootdir_size
- (mydata->clust_size * 2);
}
mydata->fatbufnum = -1;
+ mydata->fatbuf = (__u8 *) malloc (FATBUFSIZE);
+ if(mydata->fatbuf == NULL)
+ return(-1);
FAT_DPRINT ("FAT%d, fatlength: %d\n", mydata->fatsize,
mydata->fatlength);
FAT_DPRINT ("Rootdir begins at sector: %d, offset: %x, size: %d\n"
"Data begins at: %d\n",
- mydata->rootdir_sect, mydata->rootdir_sect * SECTOR_SIZE,
+ mydata->rootdir_sect, mydata->rootdir_sect * mydata->sector_size,
rootdir_size, mydata->data_begin);
FAT_DPRINT ("Cluster size: %d\n", mydata->clust_size);
@@ -787,8 +811,10 @@ do_fat_read (const char *filename, void *buffer,
unsigned long maxsize,
strcpy (fnamecopy, filename);
downcase (fnamecopy);
if (*fnamecopy == '\0') {
- if (!dols)
- return -1;
+ if (!dols) {
+ free(mydata->fatbuf);
+ return -1;
+ }
dols = LS_ROOT;
} else if ((idx = dirdelim (fnamecopy)) >= 0) {
isdir = 1;
@@ -806,6 +832,7 @@ do_fat_read (const char *filename, void *buffer,
unsigned long maxsize,
if (disk_read (cursect, mydata->clust_size, do_fat_read_block) < 0) {
FAT_DPRINT ("Error: reading rootdir block\n");
+ free(mydata->fatbuf);
return -1;
}
dentptr = (dir_entry *) do_fat_read_block;
@@ -856,6 +883,7 @@ do_fat_read (const char *filename, void *buffer,
unsigned long maxsize,
continue;
}
} else if (dentptr->name[0] == 0) {
+ free(mydata->fatbuf);
FAT_DPRINT ("RootDentname == NULL - %d\n", i);
if (dols == LS_ROOT) {
printf ("\n%d file(s), %d dir(s)\n\n", files, dirs);
@@ -906,9 +934,10 @@ do_fat_read (const char *filename, void *buffer,
unsigned long maxsize,
dentptr++;
continue;
}
- if (isdir && !(dentptr->attr & ATTR_DIR))
+ if (isdir && !(dentptr->attr & ATTR_DIR)) {
+ free(mydata->fatbuf);
return -1;
-
+ }
FAT_DPRINT ("RootName: %s", s_name);
FAT_DPRINT (", start: 0x%x", START (dentptr));
FAT_DPRINT (", size: 0x%x %s\n",
@@ -949,20 +978,23 @@ do_fat_read (const char *filename, void *buffer,
unsigned long maxsize,
if (get_dentfromdir (mydata, startsect, subname, dentptr,
isdir ? 0 : dols) == NULL) {
+ free(mydata->fatbuf);
if (dols && !isdir)
return 0;
return -1;
}
if (idx >= 0) {
- if (!(dentptr->attr & ATTR_DIR))
- return -1;
+ if (!(dentptr->attr & ATTR_DIR)) {
+ free(mydata->fatbuf);
+ return -1;
+ }
subname = nextname;
}
}
ret = get_contents (mydata, dentptr, buffer, maxsize);
FAT_DPRINT ("Size: %d, got: %ld\n", FAT2CPU32 (dentptr->size),
ret);
-
+ free(mydata->fatbuf);
return ret;
}
--
Igor Luri
R&D Software Department
Fagor Aotek S. Coop.
P. O. Box 144
E-20500 Mondrag?n-Arrasate
Tel. ++34 943 71 92 00
++34 943 71 92 01 (Ext. 44268)
Fax. ++34 943 79 92 03
www.aotek.es
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [U-Boot] [PATCH] FAT on non standard sector size devices
2008-11-12 16:30 Igor Luri
@ 2008-11-12 19:21 ` Remy Bohmer
2008-11-12 22:01 ` Wolfgang Denk
1 sibling, 0 replies; 10+ messages in thread
From: Remy Bohmer @ 2008-11-12 19:21 UTC (permalink / raw)
To: u-boot
Hello Luri,
2008/11/12 Igor Luri <iluri@aotek.es>:
> Hi all!
>
> I have done some changes sugested by Remy Bohme and finally the
> following patch adds FAT support on devices of ANY sector size.
>
> I have only tested on our custom board with u-boot 1.1.6 version. I
> would appreciate if someone could test this patch on latest version.
I will try to find a gap tomorrow to test it on mainline.
I will keep you informed!
Kind Regards,
Remy
>
> Thanks.
>
> Signed-off-by: Igor Luri <iluri@aotek.es>
>
> diff --git a/include/fat.h b/include/fat.h
> index 59de3fb..dad2e3d 100644
> --- a/include/fat.h
> +++ b/include/fat.h
> @@ -31,20 +31,12 @@
>
> #define CONFIG_SUPPORT_VFAT
>
> -#define SECTOR_SIZE FS_BLOCK_SIZE
> -
> -#define FS_BLOCK_SIZE 512
> -
> -#if FS_BLOCK_SIZE != SECTOR_SIZE
> -#error FS_BLOCK_SIZE != SECTOR_SIZE - This code needs to be fixed!
> -#endif
> -
> #define MAX_CLUSTSIZE 65536
> -#define DIRENTSPERBLOCK (FS_BLOCK_SIZE/sizeof(dir_entry))
> -#define DIRENTSPERCLUST
> ((mydata->clust_size*SECTOR_SIZE)/sizeof(dir_entry))
> +#define DIRENTSPERBLOCK (mydata->sector_size/sizeof(dir_entry))
> +#define DIRENTSPERCLUST
> ((mydata->clust_size*mydata->sector_size)/sizeof(dir_entry))
>
> #define FATBUFBLOCKS 6
> -#define FATBUFSIZE (FS_BLOCK_SIZE*FATBUFBLOCKS)
> +#define FATBUFSIZE (mydata->sector_size*FATBUFBLOCKS)
> #define FAT12BUFSIZE ((FATBUFSIZE*2)/3)
> #define FAT16BUFSIZE (FATBUFSIZE/2)
> #define FAT32BUFSIZE (FATBUFSIZE/4)
> @@ -182,8 +174,9 @@ typedef struct dir_slot {
> * (see FAT32 accesses)
> */
> typedef struct {
> - __u8 fatbuf[FATBUFSIZE]; /* Current FAT buffer */
> + __u8 *fatbuf; /* Current FAT buffer */
> int fatsize; /* Size of FAT in bits */
> + __u16 sector_size; /* Sector size */
> __u16 fatlength; /* Length of FAT in sectors */
> __u16 fat_sect; /* Starting sector of the FAT */
> __u16 rootdir_sect; /* Start sector of root directory */
>
>
> diff --git a/fs/fat/fat.c b/fs/fat/fat.c
> index 2f0bd8c..c24f009 100644
> --- a/fs/fat/fat.c
> +++ b/fs/fat/fat.c
> @@ -30,6 +30,7 @@
> #include <fat.h>
> #include <asm/byteorder.h>
> #include <part.h>
> +#include <malloc.h>
>
> /*
> * Convert a string to lowercase.
> @@ -67,12 +68,17 @@ int disk_read (__u32 startblock, __u32 getsize, __u8
> * bufptr)
> int
> fat_register_device(block_dev_desc_t *dev_desc, int part_no)
> {
> - unsigned char buffer[SECTOR_SIZE];
> + unsigned char *buffer;
> disk_partition_t info;
>
> if (!dev_desc->block_read)
> return -1;
> - cur_dev = dev_desc;
> + cur_dev=dev_desc;
> +
> + buffer = malloc (cur_dev->blksz);
> + if(buffer == NULL)
> + return(-1);
> +
> /* check if we have a MBR (on floppies we have only a PBR) */
> if (dev_desc->block_read (dev_desc->dev, 0, 1, (ulong *) buffer) != 1)
> {
> printf ("** Can't read from device %d **\n", dev_desc->dev);
> @@ -118,6 +124,7 @@ fat_register_device(block_dev_desc_t *dev_desc, int
> part_no)
> cur_part = 1;
> }
> #endif
> + free(buffer);
> return 0;
> }
>
> @@ -220,12 +227,12 @@ get_fatent(fsdata *mydata, __u32 entry)
>
> /* Read a new block of FAT entries into the cache. */
> if (bufnum != mydata->fatbufnum) {
> - int getsize = FATBUFSIZE/FS_BLOCK_SIZE;
> + int getsize = FATBUFSIZE/mydata->sector_size;
> __u8 *bufptr = mydata->fatbuf;
> __u32 fatlength = mydata->fatlength;
> __u32 startblock = bufnum * FATBUFBLOCKS;
>
> - fatlength *= SECTOR_SIZE; /* We want it in bytes now */
> + fatlength *= mydata->sector_size; /* We want it in bytes now */
> startblock += mydata->fat_sect; /* Offset from start of disk */
>
> if (getsize > fatlength) getsize = fatlength;
> @@ -300,20 +307,25 @@ get_cluster(fsdata *mydata, __u32 clustnum, __u8
> *buffer, unsigned long size)
> }
>
> FAT_DPRINT("gc - clustnum: %d, startsect: %d\n", clustnum, startsect);
> - if (disk_read(startsect, size/FS_BLOCK_SIZE , buffer) < 0) {
> + if (disk_read(startsect, size/mydata->sector_size , buffer) < 0) {
> FAT_DPRINT("Error reading data\n");
> return -1;
> }
> - if(size % FS_BLOCK_SIZE) {
> - __u8 tmpbuf[FS_BLOCK_SIZE];
> - idx= size/FS_BLOCK_SIZE;
> + if(size % mydata->sector_size) {
> + __u8 * tmpbuf;
> +
> + tmpbuf = (__u8*) malloc(mydata->sector_size);
> + if(tmpbuf == NULL)
> + return(-1);
> + idx= size/mydata->sector_size;
> if (disk_read(startsect + idx, 1, tmpbuf) < 0) {
> FAT_DPRINT("Error reading data\n");
> return -1;
> }
> - buffer += idx*FS_BLOCK_SIZE;
> + buffer += idx*mydata->sector_size;
>
> - memcpy(buffer, tmpbuf, size % FS_BLOCK_SIZE);
> + memcpy(buffer, tmpbuf, size % mydata->sector_size);
> + free(tmpbuf);
> return 0;
> }
>
> @@ -331,7 +343,7 @@ get_contents(fsdata *mydata, dir_entry *dentptr,
> __u8 *buffer,
> unsigned long maxsize)
> {
> unsigned long filesize = FAT2CPU32(dentptr->size), gotsize = 0;
> - unsigned int bytesperclust = mydata->clust_size * SECTOR_SIZE;
> + unsigned int bytesperclust = mydata->clust_size * mydata->sector_size;
> __u32 curclust = START(dentptr);
> __u32 endclust, newclust;
> unsigned long actsize;
> @@ -440,7 +452,7 @@ get_vfatname(fsdata *mydata, int curclust, __u8
> *cluster,
> {
> dir_entry *realdent;
> dir_slot *slotptr = (dir_slot*) retdent;
> - __u8 *nextclust = cluster + mydata->clust_size * SECTOR_SIZE;
> + __u8 *nextclust = cluster + mydata->clust_size *
> mydata->sector_size;
> __u8 counter = (slotptr->id & ~LAST_LONG_ENTRY_MASK) & 0xff;
> int idx = 0;
>
> @@ -463,7 +475,7 @@ get_vfatname(fsdata *mydata, int curclust, __u8
> *cluster,
> return -1;
> }
> if (get_cluster(mydata, curclust, get_vfatname_block,
> - mydata->clust_size * SECTOR_SIZE) != 0) {
> + mydata->clust_size * mydata->sector_size) != 0) {
> FAT_DPRINT("Error: reading directory block\n");
> return -1;
> }
> @@ -534,7 +546,7 @@ static dir_entry *get_dentfromdir (fsdata * mydata,
> int startsect,
> int i;
>
> if (get_cluster (mydata, curclust, get_dentfromdir_block,
> - mydata->clust_size * SECTOR_SIZE) != 0) {
> + mydata->clust_size * mydata->sector_size) != 0) {
> FAT_DPRINT ("Error: reading directory block\n");
> return NULL;
> }
> @@ -667,9 +679,16 @@ static dir_entry *get_dentfromdir (fsdata * mydata,
> int startsect,
> static int
> read_bootsectandvi(boot_sector *bs, volume_info *volinfo, int *fatsize)
> {
> - __u8 block[FS_BLOCK_SIZE];
> + __u8 *block;
> volume_info *vistart;
>
> + if(cur_dev == NULL)
> + return(-1);
> +
> + block = (__u8 *)malloc (cur_dev->blksz);
> + if(block == NULL)
> + return(-1);
> +
> if (disk_read(0, 1, block) < 0) {
> FAT_DPRINT("Error: reading block\n");
> return -1;
> @@ -680,6 +699,7 @@ read_bootsectandvi(boot_sector *bs, volume_info
> *volinfo, int *fatsize)
> bs->fat_length = FAT2CPU16(bs->fat_length);
> bs->secs_track = FAT2CPU16(bs->secs_track);
> bs->heads = FAT2CPU16(bs->heads);
> + *(__u16 *)bs->sector_size = FAT2CPU16(*(__u16 *)bs->sector_size);
> #if 0 /* UNUSED */
> bs->hidden = FAT2CPU32(bs->hidden);
> #endif
> @@ -704,7 +724,7 @@ read_bootsectandvi(boot_sector *bs, volume_info
> *volinfo, int *fatsize)
> /* Terminate fs_type string. Writing past the end of vistart
> is ok - it's just the buffer. */
> vistart->fs_type[8] = '\0';
> -
> + free(block);
> if (*fatsize == 32) {
> if (compare_sign(FAT32_SIGN, vistart->fs_type) == 0) {
> return 0;
> @@ -757,6 +777,7 @@ do_fat_read (const char *filename, void *buffer,
> unsigned long maxsize,
> mydata->fatlength = bs.fat_length;
> }
> mydata->fat_sect = bs.reserved;
> + mydata->sector_size = *(__u16 *)bs.sector_size;
> cursect = mydata->rootdir_sect
> = mydata->fat_sect + mydata->fatlength * bs.fats;
> mydata->clust_size = bs.cluster_size;
> @@ -766,17 +787,20 @@ do_fat_read (const char *filename, void *buffer,
> unsigned long maxsize,
> - (mydata->clust_size * 2);
> } else {
> rootdir_size = ((bs.dir_entries[1] * (int) 256 + bs.dir_entries[0])
> - * sizeof (dir_entry)) / SECTOR_SIZE;
> + * sizeof (dir_entry)) / mydata->sector_size;
> mydata->data_begin = mydata->rootdir_sect + rootdir_size
> - (mydata->clust_size * 2);
> }
> mydata->fatbufnum = -1;
> + mydata->fatbuf = (__u8 *) malloc (FATBUFSIZE);
> + if(mydata->fatbuf == NULL)
> + return(-1);
>
> FAT_DPRINT ("FAT%d, fatlength: %d\n", mydata->fatsize,
> mydata->fatlength);
> FAT_DPRINT ("Rootdir begins at sector: %d, offset: %x, size: %d\n"
> "Data begins at: %d\n",
> - mydata->rootdir_sect, mydata->rootdir_sect * SECTOR_SIZE,
> + mydata->rootdir_sect, mydata->rootdir_sect * mydata->sector_size,
> rootdir_size, mydata->data_begin);
> FAT_DPRINT ("Cluster size: %d\n", mydata->clust_size);
>
> @@ -787,8 +811,10 @@ do_fat_read (const char *filename, void *buffer,
> unsigned long maxsize,
> strcpy (fnamecopy, filename);
> downcase (fnamecopy);
> if (*fnamecopy == '\0') {
> - if (!dols)
> - return -1;
> + if (!dols) {
> + free(mydata->fatbuf);
> + return -1;
> + }
> dols = LS_ROOT;
> } else if ((idx = dirdelim (fnamecopy)) >= 0) {
> isdir = 1;
> @@ -806,6 +832,7 @@ do_fat_read (const char *filename, void *buffer,
> unsigned long maxsize,
>
> if (disk_read (cursect, mydata->clust_size, do_fat_read_block) < 0) {
> FAT_DPRINT ("Error: reading rootdir block\n");
> + free(mydata->fatbuf);
> return -1;
> }
> dentptr = (dir_entry *) do_fat_read_block;
> @@ -856,6 +883,7 @@ do_fat_read (const char *filename, void *buffer,
> unsigned long maxsize,
> continue;
> }
> } else if (dentptr->name[0] == 0) {
> + free(mydata->fatbuf);
> FAT_DPRINT ("RootDentname == NULL - %d\n", i);
> if (dols == LS_ROOT) {
> printf ("\n%d file(s), %d dir(s)\n\n", files, dirs);
> @@ -906,9 +934,10 @@ do_fat_read (const char *filename, void *buffer,
> unsigned long maxsize,
> dentptr++;
> continue;
> }
> - if (isdir && !(dentptr->attr & ATTR_DIR))
> + if (isdir && !(dentptr->attr & ATTR_DIR)) {
> + free(mydata->fatbuf);
> return -1;
> -
> + }
> FAT_DPRINT ("RootName: %s", s_name);
> FAT_DPRINT (", start: 0x%x", START (dentptr));
> FAT_DPRINT (", size: 0x%x %s\n",
> @@ -949,20 +978,23 @@ do_fat_read (const char *filename, void *buffer,
> unsigned long maxsize,
>
> if (get_dentfromdir (mydata, startsect, subname, dentptr,
> isdir ? 0 : dols) == NULL) {
> + free(mydata->fatbuf);
> if (dols && !isdir)
> return 0;
> return -1;
> }
>
> if (idx >= 0) {
> - if (!(dentptr->attr & ATTR_DIR))
> - return -1;
> + if (!(dentptr->attr & ATTR_DIR)) {
> + free(mydata->fatbuf);
> + return -1;
> + }
> subname = nextname;
> }
> }
> ret = get_contents (mydata, dentptr, buffer, maxsize);
> FAT_DPRINT ("Size: %d, got: %ld\n", FAT2CPU32 (dentptr->size),
> ret);
> -
> + free(mydata->fatbuf);
> return ret;
> }
>
>
>
>
>
> --
> Igor Luri
> R&D Software Department
> Fagor Aotek S. Coop.
> P. O. Box 144
> E-20500 Mondrag?n-Arrasate
> Tel. ++34 943 71 92 00
> ++34 943 71 92 01 (Ext. 44268)
> Fax. ++34 943 79 92 03
> www.aotek.es
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [U-Boot] [PATCH] FAT on non standard sector size devices
2008-11-12 16:30 Igor Luri
2008-11-12 19:21 ` Remy Bohmer
@ 2008-11-12 22:01 ` Wolfgang Denk
1 sibling, 0 replies; 10+ messages in thread
From: Wolfgang Denk @ 2008-11-12 22:01 UTC (permalink / raw)
To: u-boot
Dear Igor Luri,
In message <1226507458.6038.70.camel@ilurilinux> you wrote:
> SGkgYWxsIQoKSSBoYXZlIGRvbmUgc29tZSBjaGFuZ2VzIHN1Z2VzdGVkIGJ5IFJlbXkgQm9obWUg
> YW5kIGZpbmFsbHkgdGhlCmZvbGxvd2luZyBwYXRjaCBhZGRzIEZBVCBzdXBwb3J0IG9uIGRldmlj
> ZXMgb2YgQU5ZIHNlY3RvciBzaXplLgoKSSBoYXZlIG9ubHkgdGVzdGVkIG9uIG91ciBjdXN0b20g
> Ym9hcmQgd2l0aCB1LWJvb3QgMS4xLjYgdmVyc2lvbi4gSQp3b3VsZCBhcHByZWNpYXRlIGlmIHNv
> bWVvbmUgY291bGQgdGVzdCB0aGlzIHBhdGNoIG9uIGxhdGVzdCB2ZXJzaW9uLgoKVGhhbmtzLgoK
> U2lnbmVkLW9mZi1ieTogSWdvciBMdXJpIDxpbHVyaUBhb3Rlay5lcz4KCmRpZmYgLS1naXQgYS9p
> bmNsdWRlL2ZhdC5oIGIvaW5jbHVkZS9mYXQuaAppbmRleCA1OWRlM2ZiLi5kYWQyZTNkIDEwMDY0
> NAotLS0gYS9pbmNsdWRlL2ZhdC5oCisrKyBiL2luY2x1ZGUvZmF0LmgKQEAgLTMxLDIwICszMSwx
> MiBAQAogCiAjZGVmaW5lIENPTkZJR19TVVBQT1JUX1ZGQVQKIAotI2RlZmluZSBTRUNUT1JfU0la
> RSBGU19CTE9DS19TSVpFCi0KLSNkZWZpbmUgRlNfQkxPQ0tfU0laRSA1MTIKLQotI2lmIEZTX0JM
> T0NLX1NJWkUgIT0gU0VDVE9SX1NJWkUKLSNlcnJvciBGU19CTE9DS19TSVpFICE9IFNFQ1RPUl9T
> SVpFIC0gVGhpcyBjb2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iAJfQogICAgIH0K
> ICAgICByZXQgPSBnZXRfY29udGVudHMgKG15ZGF0YSwgZGVudHB0ciwgYnVmZmVyLCBtYXhzaXpl
> KTsKICAgICBGQVRfRFBSSU5UICgiU2l6ZTogJWQsIGdvdDogJWxkXG4iLCBGQVQyQ1BVMzIgKGRl
> bnRwdHItPnNpemUpLApyZXQpOwotCisgICAgZnJlZShteWRhdGEtPmZhdGJ1Zik7CiAgICAgcmV0
> dXJuIHJldDsKIH0KIAoKCgoKLS0gCklnb3IgTHVyaQpSJkQgU29mdHdhcmUgRGVwYXJ0bWVudApG
> YWdvciBBb3RlayBTLiBDb29wLgpQLiBPLiBCb3ggMTQ0CkUtMjA1MDAgTW9uZHJhZ8Ozbi1BcnJh
> c2F0ZQpUZWwuICAgICsrMzQgOTQzIDcxIDkyIDAwIAogICAgICAgICsrMzQgOTQzIDcxIDkyIDAx
> IChFeHQuIDQ0MjY4KQpGYXguICAgICsrMzQgOTQzIDc5IDkyIDAzCnd3dy5hb3Rlay5lcwpfX19f
> X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fXwpVLUJvb3QgbWFpbGlu
> ZyBsaXN0ClUtQm9vdEBsaXN0cy5kZW54LmRlCmh0dHA6Ly9saXN0cy5kZW54LmRlL21haWxtYW4v
> bGlzdGluZm8vdS1ib290Cg==
>
Please do not send base 64 encoded messages.
Please do not send HTML messages.
Please send plain text only.
Message unreadable, ignored. Sorry.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [U-Boot] [PATCH] FAT on non standard sector size devices
@ 2008-11-17 8:19 Igor Luri
2008-11-17 12:30 ` Jerry Van Baren
0 siblings, 1 reply; 10+ messages in thread
From: Igor Luri @ 2008-11-17 8:19 UTC (permalink / raw)
To: u-boot
Dear Remy Bohme,
Sorry, but I don't have experience in email encoding. I have changed
Evolution's preferences to use ISO-8859-15 intead of UTF-8 caracter
encoding. If this change does not correct the problem, any help would be
apretiated.
Thanks.
Signed-off-by: Igor Luri <iluri@aotek.es>
diff --git a/include/fat.h b/include/fat.h
index 59de3fb..dad2e3d 100644
--- a/include/fat.h
+++ b/include/fat.h
@@ -31,20 +31,12 @@
#define CONFIG_SUPPORT_VFAT
-#define SECTOR_SIZE FS_BLOCK_SIZE
-
-#define FS_BLOCK_SIZE 512
-
-#if FS_BLOCK_SIZE != SECTOR_SIZE
-#error FS_BLOCK_SIZE != SECTOR_SIZE - This code needs to be fixed!
-#endif
-
#define MAX_CLUSTSIZE 65536
-#define DIRENTSPERBLOCK (FS_BLOCK_SIZE/sizeof(dir_entry))
-#define DIRENTSPERCLUST
((mydata->clust_size*SECTOR_SIZE)/sizeof(dir_entry))
+#define DIRENTSPERBLOCK (mydata->sector_size/sizeof(dir_entry))
+#define DIRENTSPERCLUST
((mydata->clust_size*mydata->sector_size)/sizeof(dir_entry))
#define FATBUFBLOCKS 6
-#define FATBUFSIZE (FS_BLOCK_SIZE*FATBUFBLOCKS)
+#define FATBUFSIZE (mydata->sector_size*FATBUFBLOCKS)
#define FAT12BUFSIZE ((FATBUFSIZE*2)/3)
#define FAT16BUFSIZE (FATBUFSIZE/2)
#define FAT32BUFSIZE (FATBUFSIZE/4)
@@ -182,8 +174,9 @@ typedef struct dir_slot {
* (see FAT32 accesses)
*/
typedef struct {
- __u8 fatbuf[FATBUFSIZE]; /* Current FAT buffer */
+ __u8 *fatbuf; /* Current FAT buffer */
int fatsize; /* Size of FAT in bits */
+ __u16 sector_size; /* Sector size */
__u16 fatlength; /* Length of FAT in sectors */
__u16 fat_sect; /* Starting sector of the FAT */
__u16 rootdir_sect; /* Start sector of root directory */
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index 2f0bd8c..c24f009 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -30,6 +30,7 @@
#include <fat.h>
#include <asm/byteorder.h>
#include <part.h>
+#include <malloc.h>
/*
* Convert a string to lowercase.
@@ -67,12 +68,17 @@ int disk_read (__u32 startblock, __u32 getsize, __u8
* bufptr)
int
fat_register_device(block_dev_desc_t *dev_desc, int part_no)
{
- unsigned char buffer[SECTOR_SIZE];
+ unsigned char *buffer;
disk_partition_t info;
if (!dev_desc->block_read)
return -1;
- cur_dev = dev_desc;
+ cur_dev=dev_desc;
+
+ buffer = malloc (cur_dev->blksz);
+ if(buffer == NULL)
+ return(-1);
+
/* check if we have a MBR (on floppies we have only a PBR) */
if (dev_desc->block_read (dev_desc->dev, 0, 1, (ulong *)
buffer) != 1)
{
printf ("** Can't read from device %d **\n",
dev_desc->dev);
@@ -118,6 +124,7 @@ fat_register_device(block_dev_desc_t *dev_desc, int
part_no)
cur_part = 1;
}
#endif
+ free(buffer);
return 0;
}
@@ -220,12 +227,12 @@ get_fatent(fsdata *mydata, __u32 entry)
/* Read a new block of FAT entries into the cache. */
if (bufnum != mydata->fatbufnum) {
- int getsize = FATBUFSIZE/FS_BLOCK_SIZE;
+ int getsize = FATBUFSIZE/mydata->sector_size;
__u8 *bufptr = mydata->fatbuf;
__u32 fatlength = mydata->fatlength;
__u32 startblock = bufnum * FATBUFBLOCKS;
- fatlength *= SECTOR_SIZE; /* We want it in bytes
now */
+ fatlength *= mydata->sector_size; /* We want it in
bytes now */
startblock += mydata->fat_sect; /* Offset from start of
disk */
if (getsize > fatlength) getsize = fatlength;
@@ -300,20 +307,25 @@ get_cluster(fsdata *mydata, __u32 clustnum, __u8
*buffer, unsigned long size)
}
FAT_DPRINT("gc - clustnum: %d, startsect: %d\n", clustnum,
startsect);
- if (disk_read(startsect, size/FS_BLOCK_SIZE , buffer) < 0) {
+ if (disk_read(startsect, size/mydata->sector_size , buffer) < 0)
{
FAT_DPRINT("Error reading data\n");
return -1;
}
- if(size % FS_BLOCK_SIZE) {
- __u8 tmpbuf[FS_BLOCK_SIZE];
- idx= size/FS_BLOCK_SIZE;
+ if(size % mydata->sector_size) {
+ __u8 * tmpbuf;
+
+ tmpbuf = (__u8*) malloc(mydata->sector_size);
+ if(tmpbuf == NULL)
+ return(-1);
+ idx= size/mydata->sector_size;
if (disk_read(startsect + idx, 1, tmpbuf) < 0) {
FAT_DPRINT("Error reading data\n");
return -1;
}
- buffer += idx*FS_BLOCK_SIZE;
+ buffer += idx*mydata->sector_size;
- memcpy(buffer, tmpbuf, size % FS_BLOCK_SIZE);
+ memcpy(buffer, tmpbuf, size % mydata->sector_size);
+ free(tmpbuf);
return 0;
}
@@ -331,7 +343,7 @@ get_contents(fsdata *mydata, dir_entry *dentptr,
__u8 *buffer,
unsigned long maxsize)
{
unsigned long filesize = FAT2CPU32(dentptr->size), gotsize = 0;
- unsigned int bytesperclust = mydata->clust_size * SECTOR_SIZE;
+ unsigned int bytesperclust = mydata->clust_size *
mydata->sector_size;
__u32 curclust = START(dentptr);
__u32 endclust, newclust;
unsigned long actsize;
@@ -440,7 +452,7 @@ get_vfatname(fsdata *mydata, int curclust, __u8
*cluster,
{
dir_entry *realdent;
dir_slot *slotptr = (dir_slot*) retdent;
- __u8 *nextclust = cluster + mydata->clust_size *
SECTOR_SIZE;
+ __u8 *nextclust = cluster + mydata->clust_size *
mydata->sector_size;
__u8 counter = (slotptr->id & ~LAST_LONG_ENTRY_MASK) &
0xff;
int idx = 0;
@@ -463,7 +475,7 @@ get_vfatname(fsdata *mydata, int curclust, __u8
*cluster,
return -1;
}
if (get_cluster(mydata, curclust, get_vfatname_block,
- mydata->clust_size * SECTOR_SIZE) != 0)
{
+ mydata->clust_size *
mydata->sector_size) != 0) {
FAT_DPRINT("Error: reading directory block\n");
return -1;
}
@@ -534,7 +546,7 @@ static dir_entry *get_dentfromdir (fsdata * mydata,
int startsect,
int i;
if (get_cluster (mydata, curclust, get_dentfromdir_block,
- mydata->clust_size * SECTOR_SIZE) != 0) {
+ mydata->clust_size * mydata->sector_size) != 0)
{
FAT_DPRINT ("Error: reading directory block\n");
return NULL;
}
@@ -667,9 +679,16 @@ static dir_entry *get_dentfromdir (fsdata * mydata,
int startsect,
static int
read_bootsectandvi(boot_sector *bs, volume_info *volinfo, int *fatsize)
{
- __u8 block[FS_BLOCK_SIZE];
+ __u8 *block;
volume_info *vistart;
+ if(cur_dev == NULL)
+ return(-1);
+
+ block = (__u8 *)malloc (cur_dev->blksz);
+ if(block == NULL)
+ return(-1);
+
if (disk_read(0, 1, block) < 0) {
FAT_DPRINT("Error: reading block\n");
return -1;
@@ -680,6 +699,7 @@ read_bootsectandvi(boot_sector *bs, volume_info
*volinfo, int *fatsize)
bs->fat_length = FAT2CPU16(bs->fat_length);
bs->secs_track = FAT2CPU16(bs->secs_track);
bs->heads = FAT2CPU16(bs->heads);
+ *(__u16 *)bs->sector_size = FAT2CPU16(*(__u16
*)bs->sector_size);
#if 0 /* UNUSED */
bs->hidden = FAT2CPU32(bs->hidden);
#endif
@@ -704,7 +724,7 @@ read_bootsectandvi(boot_sector *bs, volume_info
*volinfo, int *fatsize)
/* Terminate fs_type string. Writing past the end of vistart
is ok - it's just the buffer. */
vistart->fs_type[8] = '\0';
-
+ free(block);
if (*fatsize == 32) {
if (compare_sign(FAT32_SIGN, vistart->fs_type) == 0) {
return 0;
@@ -757,6 +777,7 @@ do_fat_read (const char *filename, void *buffer,
unsigned long maxsize,
mydata->fatlength = bs.fat_length;
}
mydata->fat_sect = bs.reserved;
+ mydata->sector_size = *(__u16 *)bs.sector_size;
cursect = mydata->rootdir_sect
= mydata->fat_sect + mydata->fatlength * bs.fats;
mydata->clust_size = bs.cluster_size;
@@ -766,17 +787,20 @@ do_fat_read (const char *filename, void *buffer,
unsigned long maxsize,
- (mydata->clust_size * 2);
} else {
rootdir_size = ((bs.dir_entries[1] * (int) 256 +
bs.dir_entries[0])
- * sizeof (dir_entry)) / SECTOR_SIZE;
+ * sizeof (dir_entry)) / mydata->sector_size;
mydata->data_begin = mydata->rootdir_sect + rootdir_size
- (mydata->clust_size * 2);
}
mydata->fatbufnum = -1;
+ mydata->fatbuf = (__u8 *) malloc (FATBUFSIZE);
+ if(mydata->fatbuf == NULL)
+ return(-1);
FAT_DPRINT ("FAT%d, fatlength: %d\n", mydata->fatsize,
mydata->fatlength);
FAT_DPRINT ("Rootdir begins at sector: %d, offset: %x, size: %d\n"
"Data begins at: %d\n",
- mydata->rootdir_sect, mydata->rootdir_sect *
SECTOR_SIZE,
+ mydata->rootdir_sect, mydata->rootdir_sect *
mydata->sector_size,
rootdir_size, mydata->data_begin);
FAT_DPRINT ("Cluster size: %d\n", mydata->clust_size);
@@ -787,8 +811,10 @@ do_fat_read (const char *filename, void *buffer,
unsigned long maxsize,
strcpy (fnamecopy, filename);
downcase (fnamecopy);
if (*fnamecopy == '\0') {
- if (!dols)
- return -1;
+ if (!dols) {
+ free(mydata->fatbuf);
+ return -1;
+ }
dols = LS_ROOT;
} else if ((idx = dirdelim (fnamecopy)) >= 0) {
isdir = 1;
@@ -806,6 +832,7 @@ do_fat_read (const char *filename, void *buffer,
unsigned long maxsize,
if (disk_read (cursect, mydata->clust_size, do_fat_read_block) <
0) {
FAT_DPRINT ("Error: reading rootdir block\n");
+ free(mydata->fatbuf);
return -1;
}
dentptr = (dir_entry *) do_fat_read_block;
@@ -856,6 +883,7 @@ do_fat_read (const char *filename, void *buffer,
unsigned long maxsize,
continue;
}
} else if (dentptr->name[0] == 0) {
+ free(mydata->fatbuf);
FAT_DPRINT ("RootDentname == NULL - %d\n", i);
if (dols == LS_ROOT) {
printf ("\n%d file(s), %d dir(s)\n\n", files, dirs);
@@ -906,9 +934,10 @@ do_fat_read (const char *filename, void *buffer,
unsigned long maxsize,
dentptr++;
continue;
}
- if (isdir && !(dentptr->attr & ATTR_DIR))
+ if (isdir && !(dentptr->attr & ATTR_DIR)) {
+ free(mydata->fatbuf);
return -1;
-
+ }
FAT_DPRINT ("RootName: %s", s_name);
FAT_DPRINT (", start: 0x%x", START (dentptr));
FAT_DPRINT (", size: 0x%x %s\n",
@@ -949,20 +978,23 @@ do_fat_read (const char *filename, void *buffer,
unsigned long maxsize,
if (get_dentfromdir (mydata, startsect, subname, dentptr,
isdir ? 0 : dols) == NULL) {
+ free(mydata->fatbuf);
if (dols && !isdir)
return 0;
return -1;
}
if (idx >= 0) {
- if (!(dentptr->attr & ATTR_DIR))
- return -1;
+ if (!(dentptr->attr & ATTR_DIR)) {
+ free(mydata->fatbuf);
+ return -1;
+ }
subname = nextname;
}
}
ret = get_contents (mydata, dentptr, buffer, maxsize);
FAT_DPRINT ("Size: %d, got: %ld\n", FAT2CPU32 (dentptr->size),
ret);
-
+ free(mydata->fatbuf);
return ret;
}
--
Igor Luri
R&D Software Department
Fagor Aotek S. Coop.
P. O. Box 144
E-20500 Mondrag?n-Arrasate
Tel. ++34 943 71 92 00
++34 943 71 92 01 (Ext. 44268)
Fax. ++34 943 79 92 03
www.aotek.es
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [U-Boot] [PATCH] FAT on non standard sector size devices
2008-11-17 8:19 [U-Boot] [PATCH] FAT on non standard sector size devices Igor Luri
@ 2008-11-17 12:30 ` Jerry Van Baren
2008-11-17 13:34 ` Igor Luri
0 siblings, 1 reply; 10+ messages in thread
From: Jerry Van Baren @ 2008-11-17 12:30 UTC (permalink / raw)
To: u-boot
Igor Luri wrote:
> Dear Remy Bohme,
>
> Sorry, but I don't have experience in email encoding. I have changed
> Evolution's preferences to use ISO-8859-15 intead of UTF-8 caracter
> encoding. If this change does not correct the problem, any help would be
> apretiated.
>
> Thanks.
Hi Igor,
Your patch is linewrapped. Try the hints for using Evolution found in
the linux kernel tree under Documentation/email-clients.txt:
<http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/email-clients.txt;h=a618efab7b156658be70b29c1a6a9b9c4093e0f5;hb=HEAD#l69>
gvb
^ permalink raw reply [flat|nested] 10+ messages in thread
* [U-Boot] [PATCH] FAT on non standard sector size devices
2008-11-17 12:30 ` Jerry Van Baren
@ 2008-11-17 13:34 ` Igor Luri
2008-11-17 19:49 ` Remy Bohmer
0 siblings, 1 reply; 10+ messages in thread
From: Igor Luri @ 2008-11-17 13:34 UTC (permalink / raw)
To: u-boot
OK, thanks for your help.
I have followed the hints found on the document suggested and I think this time is going to work the patch, I have sended myself and it works.
Signed-off-by: Igor Luri <iluri@aotek.es>
--- ./Escritorio/Descargas/fat.h 2008-11-10 15:50:57.000000000 +0100
+++ git/u-boot/include/fat.h 2008-11-12 16:59:42.000000000 +0100
@@ -31,20 +31,12 @@
#define CONFIG_SUPPORT_VFAT
-#define SECTOR_SIZE FS_BLOCK_SIZE
-
-#define FS_BLOCK_SIZE 512
-
-#if FS_BLOCK_SIZE != SECTOR_SIZE
-#error FS_BLOCK_SIZE != SECTOR_SIZE - This code needs to be fixed!
-#endif
-
#define MAX_CLUSTSIZE 65536
-#define DIRENTSPERBLOCK (FS_BLOCK_SIZE/sizeof(dir_entry))
-#define DIRENTSPERCLUST ((mydata->clust_size*SECTOR_SIZE)/sizeof(dir_entry))
+#define DIRENTSPERBLOCK (mydata->sector_size/sizeof(dir_entry))
+#define DIRENTSPERCLUST ((mydata->clust_size*mydata->sector_size)/sizeof(dir_entry))
#define FATBUFBLOCKS 6
-#define FATBUFSIZE (FS_BLOCK_SIZE*FATBUFBLOCKS)
+#define FATBUFSIZE (mydata->sector_size*FATBUFBLOCKS)
#define FAT12BUFSIZE ((FATBUFSIZE*2)/3)
#define FAT16BUFSIZE (FATBUFSIZE/2)
#define FAT32BUFSIZE (FATBUFSIZE/4)
@@ -182,8 +174,9 @@
* (see FAT32 accesses)
*/
typedef struct {
- __u8 fatbuf[FATBUFSIZE]; /* Current FAT buffer */
+ __u8 *fatbuf; /* Current FAT buffer */
int fatsize; /* Size of FAT in bits */
+ __u16 sector_size; /* Sector size */
__u16 fatlength; /* Length of FAT in sectors */
__u16 fat_sect; /* Starting sector of the FAT */
__u16 rootdir_sect; /* Start sector of root directory */
--- ./Escritorio/Descargas/fat.c 2008-11-07 17:10:22.000000000 +0100
+++ git/u-boot/fs/fat/fat.c 2008-11-12 17:14:25.000000000 +0100
@@ -30,6 +30,7 @@
#include <fat.h>
#include <asm/byteorder.h>
#include <part.h>
+#include <malloc.h>
/*
* Convert a string to lowercase.
@@ -67,12 +68,17 @@
int
fat_register_device(block_dev_desc_t *dev_desc, int part_no)
{
- unsigned char buffer[SECTOR_SIZE];
+ unsigned char *buffer;
disk_partition_t info;
if (!dev_desc->block_read)
return -1;
- cur_dev = dev_desc;
+ cur_dev=dev_desc;
+
+ buffer = malloc (cur_dev->blksz);
+ if(buffer == NULL)
+ return(-1);
+
/* check if we have a MBR (on floppies we have only a PBR) */
if (dev_desc->block_read (dev_desc->dev, 0, 1, (ulong *) buffer) != 1) {
printf ("** Can't read from device %d **\n", dev_desc->dev);
@@ -118,6 +124,7 @@
cur_part = 1;
}
#endif
+ free(buffer);
return 0;
}
@@ -220,12 +227,12 @@
/* Read a new block of FAT entries into the cache. */
if (bufnum != mydata->fatbufnum) {
- int getsize = FATBUFSIZE/FS_BLOCK_SIZE;
+ int getsize = FATBUFSIZE/mydata->sector_size;
__u8 *bufptr = mydata->fatbuf;
__u32 fatlength = mydata->fatlength;
__u32 startblock = bufnum * FATBUFBLOCKS;
- fatlength *= SECTOR_SIZE; /* We want it in bytes now */
+ fatlength *= mydata->sector_size; /* We want it in bytes now */
startblock += mydata->fat_sect; /* Offset from start of disk */
if (getsize > fatlength) getsize = fatlength;
@@ -300,20 +307,25 @@
}
FAT_DPRINT("gc - clustnum: %d, startsect: %d\n", clustnum, startsect);
- if (disk_read(startsect, size/FS_BLOCK_SIZE , buffer) < 0) {
+ if (disk_read(startsect, size/mydata->sector_size , buffer) < 0) {
FAT_DPRINT("Error reading data\n");
return -1;
}
- if(size % FS_BLOCK_SIZE) {
- __u8 tmpbuf[FS_BLOCK_SIZE];
- idx= size/FS_BLOCK_SIZE;
+ if(size % mydata->sector_size) {
+ __u8 * tmpbuf;
+
+ tmpbuf = (__u8*) malloc(mydata->sector_size);
+ if(tmpbuf == NULL)
+ return(-1);
+ idx= size/mydata->sector_size;
if (disk_read(startsect + idx, 1, tmpbuf) < 0) {
FAT_DPRINT("Error reading data\n");
return -1;
}
- buffer += idx*FS_BLOCK_SIZE;
+ buffer += idx*mydata->sector_size;
- memcpy(buffer, tmpbuf, size % FS_BLOCK_SIZE);
+ memcpy(buffer, tmpbuf, size % mydata->sector_size);
+ free(tmpbuf);
return 0;
}
@@ -331,7 +343,7 @@
unsigned long maxsize)
{
unsigned long filesize = FAT2CPU32(dentptr->size), gotsize = 0;
- unsigned int bytesperclust = mydata->clust_size * SECTOR_SIZE;
+ unsigned int bytesperclust = mydata->clust_size * mydata->sector_size;
__u32 curclust = START(dentptr);
__u32 endclust, newclust;
unsigned long actsize;
@@ -440,7 +452,7 @@
{
dir_entry *realdent;
dir_slot *slotptr = (dir_slot*) retdent;
- __u8 *nextclust = cluster + mydata->clust_size * SECTOR_SIZE;
+ __u8 *nextclust = cluster + mydata->clust_size * mydata->sector_size;
__u8 counter = (slotptr->id & ~LAST_LONG_ENTRY_MASK) & 0xff;
int idx = 0;
@@ -463,7 +475,7 @@
return -1;
}
if (get_cluster(mydata, curclust, get_vfatname_block,
- mydata->clust_size * SECTOR_SIZE) != 0) {
+ mydata->clust_size * mydata->sector_size) != 0) {
FAT_DPRINT("Error: reading directory block\n");
return -1;
}
@@ -534,7 +546,7 @@
int i;
if (get_cluster (mydata, curclust, get_dentfromdir_block,
- mydata->clust_size * SECTOR_SIZE) != 0) {
+ mydata->clust_size * mydata->sector_size) != 0) {
FAT_DPRINT ("Error: reading directory block\n");
return NULL;
}
@@ -667,9 +679,16 @@
static int
read_bootsectandvi(boot_sector *bs, volume_info *volinfo, int *fatsize)
{
- __u8 block[FS_BLOCK_SIZE];
+ __u8 *block;
volume_info *vistart;
+ if(cur_dev == NULL)
+ return(-1);
+
+ block = (__u8 *)malloc (cur_dev->blksz);
+ if(block == NULL)
+ return(-1);
+
if (disk_read(0, 1, block) < 0) {
FAT_DPRINT("Error: reading block\n");
return -1;
@@ -680,6 +699,7 @@
bs->fat_length = FAT2CPU16(bs->fat_length);
bs->secs_track = FAT2CPU16(bs->secs_track);
bs->heads = FAT2CPU16(bs->heads);
+ *(__u16 *)bs->sector_size = FAT2CPU16(*(__u16 *)bs->sector_size);
#if 0 /* UNUSED */
bs->hidden = FAT2CPU32(bs->hidden);
#endif
@@ -704,7 +724,7 @@
/* Terminate fs_type string. Writing past the end of vistart
is ok - it's just the buffer. */
vistart->fs_type[8] = '\0';
-
+ free(block);
if (*fatsize == 32) {
if (compare_sign(FAT32_SIGN, vistart->fs_type) == 0) {
return 0;
@@ -757,6 +777,7 @@
mydata->fatlength = bs.fat_length;
}
mydata->fat_sect = bs.reserved;
+ mydata->sector_size = *(__u16 *)bs.sector_size;
cursect = mydata->rootdir_sect
= mydata->fat_sect + mydata->fatlength * bs.fats;
mydata->clust_size = bs.cluster_size;
@@ -766,17 +787,20 @@
- (mydata->clust_size * 2);
} else {
rootdir_size = ((bs.dir_entries[1] * (int) 256 + bs.dir_entries[0])
- * sizeof (dir_entry)) / SECTOR_SIZE;
+ * sizeof (dir_entry)) / mydata->sector_size;
mydata->data_begin = mydata->rootdir_sect + rootdir_size
- (mydata->clust_size * 2);
}
mydata->fatbufnum = -1;
+ mydata->fatbuf = (__u8 *) malloc (FATBUFSIZE);
+ if(mydata->fatbuf == NULL)
+ return(-1);
FAT_DPRINT ("FAT%d, fatlength: %d\n", mydata->fatsize,
mydata->fatlength);
FAT_DPRINT ("Rootdir begins at sector: %d, offset: %x, size: %d\n"
"Data begins at: %d\n",
- mydata->rootdir_sect, mydata->rootdir_sect * SECTOR_SIZE,
+ mydata->rootdir_sect, mydata->rootdir_sect * mydata->sector_size,
rootdir_size, mydata->data_begin);
FAT_DPRINT ("Cluster size: %d\n", mydata->clust_size);
@@ -787,8 +811,10 @@
strcpy (fnamecopy, filename);
downcase (fnamecopy);
if (*fnamecopy == '\0') {
- if (!dols)
- return -1;
+ if (!dols) {
+ free(mydata->fatbuf);
+ return -1;
+ }
dols = LS_ROOT;
} else if ((idx = dirdelim (fnamecopy)) >= 0) {
isdir = 1;
@@ -806,6 +832,7 @@
if (disk_read (cursect, mydata->clust_size, do_fat_read_block) < 0) {
FAT_DPRINT ("Error: reading rootdir block\n");
+ free(mydata->fatbuf);
return -1;
}
dentptr = (dir_entry *) do_fat_read_block;
@@ -856,6 +883,7 @@
continue;
}
} else if (dentptr->name[0] == 0) {
+ free(mydata->fatbuf);
FAT_DPRINT ("RootDentname == NULL - %d\n", i);
if (dols == LS_ROOT) {
printf ("\n%d file(s), %d dir(s)\n\n", files, dirs);
@@ -906,9 +934,10 @@
dentptr++;
continue;
}
- if (isdir && !(dentptr->attr & ATTR_DIR))
+ if (isdir && !(dentptr->attr & ATTR_DIR)) {
+ free(mydata->fatbuf);
return -1;
-
+ }
FAT_DPRINT ("RootName: %s", s_name);
FAT_DPRINT (", start: 0x%x", START (dentptr));
FAT_DPRINT (", size: 0x%x %s\n",
@@ -949,20 +978,23 @@
if (get_dentfromdir (mydata, startsect, subname, dentptr,
isdir ? 0 : dols) == NULL) {
+ free(mydata->fatbuf);
if (dols && !isdir)
return 0;
return -1;
}
if (idx >= 0) {
- if (!(dentptr->attr & ATTR_DIR))
- return -1;
+ if (!(dentptr->attr & ATTR_DIR)) {
+ free(mydata->fatbuf);
+ return -1;
+ }
subname = nextname;
}
}
ret = get_contents (mydata, dentptr, buffer, maxsize);
FAT_DPRINT ("Size: %d, got: %ld\n", FAT2CPU32 (dentptr->size), ret);
-
+ free(mydata->fatbuf);
return ret;
}
El lun, 17-11-2008 a las 07:30 -0500, Jerry Van Baren escribi?:
> Igor Luri wrote:
> > Dear Remy Bohme,
> >
> > Sorry, but I don't have experience in email encoding. I have changed
> > Evolution's preferences to use ISO-8859-15 intead of UTF-8 caracter
> > encoding. If this change does not correct the problem, any help would be
> > apretiated.
> >
> > Thanks.
>
> Hi Igor,
>
> Your patch is linewrapped. Try the hints for using Evolution found in
> the linux kernel tree under Documentation/email-clients.txt:
> <http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/email-clients.txt;h=a618efab7b156658be70b29c1a6a9b9c4093e0f5;hb=HEAD#l69>
>
> gvb
>
--
Igor Luri
R&D Software Department
Fagor Aotek S. Coop.
P. O. Box 144
E-20500 Mondrag?n-Arrasate
Tel. ++34 943 71 92 00
++34 943 71 92 01 (Ext. 44268)
Fax. ++34 943 79 92 03
www.aotek.es
^ permalink raw reply [flat|nested] 10+ messages in thread
* [U-Boot] [PATCH] FAT on non standard sector size devices
2008-11-17 13:34 ` Igor Luri
@ 2008-11-17 19:49 ` Remy Bohmer
0 siblings, 0 replies; 10+ messages in thread
From: Remy Bohmer @ 2008-11-17 19:49 UTC (permalink / raw)
To: u-boot
Hello Igor,
2008/11/17 Igor Luri <iluri@aotek.es>:
> OK, thanks for your help.
>
> I have followed the hints found on the document suggested and I think this time is going to work the patch, I have sended myself and it works.
For the next time, if you stuck on using Evolution (for example due to
exchange mailservers, or proxy problems etc):
* You can also generate a Berkely mail message via 'quilt mail' and
output to a file
* Import this mail file in the _outbox_ of Evolution... (1 file can
contain a couple of messages at once)
* Finally press the send button... Works flawlessly ;-)
Kind Regards,
Remy
> Signed-off-by: Igor Luri <iluri@aotek.es>
>
> --- ./Escritorio/Descargas/fat.h 2008-11-10 15:50:57.000000000 +0100
> +++ git/u-boot/include/fat.h 2008-11-12 16:59:42.000000000 +0100
> @@ -31,20 +31,12 @@
>
> #define CONFIG_SUPPORT_VFAT
>
> -#define SECTOR_SIZE FS_BLOCK_SIZE
> -
> -#define FS_BLOCK_SIZE 512
> -
> -#if FS_BLOCK_SIZE != SECTOR_SIZE
> -#error FS_BLOCK_SIZE != SECTOR_SIZE - This code needs to be fixed!
> -#endif
> -
> #define MAX_CLUSTSIZE 65536
> -#define DIRENTSPERBLOCK (FS_BLOCK_SIZE/sizeof(dir_entry))
> -#define DIRENTSPERCLUST ((mydata->clust_size*SECTOR_SIZE)/sizeof(dir_entry))
> +#define DIRENTSPERBLOCK (mydata->sector_size/sizeof(dir_entry))
> +#define DIRENTSPERCLUST ((mydata->clust_size*mydata->sector_size)/sizeof(dir_entry))
>
> #define FATBUFBLOCKS 6
> -#define FATBUFSIZE (FS_BLOCK_SIZE*FATBUFBLOCKS)
> +#define FATBUFSIZE (mydata->sector_size*FATBUFBLOCKS)
> #define FAT12BUFSIZE ((FATBUFSIZE*2)/3)
> #define FAT16BUFSIZE (FATBUFSIZE/2)
> #define FAT32BUFSIZE (FATBUFSIZE/4)
> @@ -182,8 +174,9 @@
> * (see FAT32 accesses)
> */
> typedef struct {
> - __u8 fatbuf[FATBUFSIZE]; /* Current FAT buffer */
> + __u8 *fatbuf; /* Current FAT buffer */
> int fatsize; /* Size of FAT in bits */
> + __u16 sector_size; /* Sector size */
> __u16 fatlength; /* Length of FAT in sectors */
> __u16 fat_sect; /* Starting sector of the FAT */
> __u16 rootdir_sect; /* Start sector of root directory */
> --- ./Escritorio/Descargas/fat.c 2008-11-07 17:10:22.000000000 +0100
> +++ git/u-boot/fs/fat/fat.c 2008-11-12 17:14:25.000000000 +0100
> @@ -30,6 +30,7 @@
> #include <fat.h>
> #include <asm/byteorder.h>
> #include <part.h>
> +#include <malloc.h>
>
> /*
> * Convert a string to lowercase.
> @@ -67,12 +68,17 @@
> int
> fat_register_device(block_dev_desc_t *dev_desc, int part_no)
> {
> - unsigned char buffer[SECTOR_SIZE];
> + unsigned char *buffer;
> disk_partition_t info;
>
> if (!dev_desc->block_read)
> return -1;
> - cur_dev = dev_desc;
> + cur_dev=dev_desc;
> +
> + buffer = malloc (cur_dev->blksz);
> + if(buffer == NULL)
> + return(-1);
> +
> /* check if we have a MBR (on floppies we have only a PBR) */
> if (dev_desc->block_read (dev_desc->dev, 0, 1, (ulong *) buffer) != 1) {
> printf ("** Can't read from device %d **\n", dev_desc->dev);
> @@ -118,6 +124,7 @@
> cur_part = 1;
> }
> #endif
> + free(buffer);
> return 0;
> }
>
> @@ -220,12 +227,12 @@
>
> /* Read a new block of FAT entries into the cache. */
> if (bufnum != mydata->fatbufnum) {
> - int getsize = FATBUFSIZE/FS_BLOCK_SIZE;
> + int getsize = FATBUFSIZE/mydata->sector_size;
> __u8 *bufptr = mydata->fatbuf;
> __u32 fatlength = mydata->fatlength;
> __u32 startblock = bufnum * FATBUFBLOCKS;
>
> - fatlength *= SECTOR_SIZE; /* We want it in bytes now */
> + fatlength *= mydata->sector_size; /* We want it in bytes now */
> startblock += mydata->fat_sect; /* Offset from start of disk */
>
> if (getsize > fatlength) getsize = fatlength;
> @@ -300,20 +307,25 @@
> }
>
> FAT_DPRINT("gc - clustnum: %d, startsect: %d\n", clustnum, startsect);
> - if (disk_read(startsect, size/FS_BLOCK_SIZE , buffer) < 0) {
> + if (disk_read(startsect, size/mydata->sector_size , buffer) < 0) {
> FAT_DPRINT("Error reading data\n");
> return -1;
> }
> - if(size % FS_BLOCK_SIZE) {
> - __u8 tmpbuf[FS_BLOCK_SIZE];
> - idx= size/FS_BLOCK_SIZE;
> + if(size % mydata->sector_size) {
> + __u8 * tmpbuf;
> +
> + tmpbuf = (__u8*) malloc(mydata->sector_size);
> + if(tmpbuf == NULL)
> + return(-1);
> + idx= size/mydata->sector_size;
> if (disk_read(startsect + idx, 1, tmpbuf) < 0) {
> FAT_DPRINT("Error reading data\n");
> return -1;
> }
> - buffer += idx*FS_BLOCK_SIZE;
> + buffer += idx*mydata->sector_size;
>
> - memcpy(buffer, tmpbuf, size % FS_BLOCK_SIZE);
> + memcpy(buffer, tmpbuf, size % mydata->sector_size);
> + free(tmpbuf);
> return 0;
> }
>
> @@ -331,7 +343,7 @@
> unsigned long maxsize)
> {
> unsigned long filesize = FAT2CPU32(dentptr->size), gotsize = 0;
> - unsigned int bytesperclust = mydata->clust_size * SECTOR_SIZE;
> + unsigned int bytesperclust = mydata->clust_size * mydata->sector_size;
> __u32 curclust = START(dentptr);
> __u32 endclust, newclust;
> unsigned long actsize;
> @@ -440,7 +452,7 @@
> {
> dir_entry *realdent;
> dir_slot *slotptr = (dir_slot*) retdent;
> - __u8 *nextclust = cluster + mydata->clust_size * SECTOR_SIZE;
> + __u8 *nextclust = cluster + mydata->clust_size * mydata->sector_size;
> __u8 counter = (slotptr->id & ~LAST_LONG_ENTRY_MASK) & 0xff;
> int idx = 0;
>
> @@ -463,7 +475,7 @@
> return -1;
> }
> if (get_cluster(mydata, curclust, get_vfatname_block,
> - mydata->clust_size * SECTOR_SIZE) != 0) {
> + mydata->clust_size * mydata->sector_size) != 0) {
> FAT_DPRINT("Error: reading directory block\n");
> return -1;
> }
> @@ -534,7 +546,7 @@
> int i;
>
> if (get_cluster (mydata, curclust, get_dentfromdir_block,
> - mydata->clust_size * SECTOR_SIZE) != 0) {
> + mydata->clust_size * mydata->sector_size) != 0) {
> FAT_DPRINT ("Error: reading directory block\n");
> return NULL;
> }
> @@ -667,9 +679,16 @@
> static int
> read_bootsectandvi(boot_sector *bs, volume_info *volinfo, int *fatsize)
> {
> - __u8 block[FS_BLOCK_SIZE];
> + __u8 *block;
> volume_info *vistart;
>
> + if(cur_dev == NULL)
> + return(-1);
> +
> + block = (__u8 *)malloc (cur_dev->blksz);
> + if(block == NULL)
> + return(-1);
> +
> if (disk_read(0, 1, block) < 0) {
> FAT_DPRINT("Error: reading block\n");
> return -1;
> @@ -680,6 +699,7 @@
> bs->fat_length = FAT2CPU16(bs->fat_length);
> bs->secs_track = FAT2CPU16(bs->secs_track);
> bs->heads = FAT2CPU16(bs->heads);
> + *(__u16 *)bs->sector_size = FAT2CPU16(*(__u16 *)bs->sector_size);
> #if 0 /* UNUSED */
> bs->hidden = FAT2CPU32(bs->hidden);
> #endif
> @@ -704,7 +724,7 @@
> /* Terminate fs_type string. Writing past the end of vistart
> is ok - it's just the buffer. */
> vistart->fs_type[8] = '\0';
> -
> + free(block);
> if (*fatsize == 32) {
> if (compare_sign(FAT32_SIGN, vistart->fs_type) == 0) {
> return 0;
> @@ -757,6 +777,7 @@
> mydata->fatlength = bs.fat_length;
> }
> mydata->fat_sect = bs.reserved;
> + mydata->sector_size = *(__u16 *)bs.sector_size;
> cursect = mydata->rootdir_sect
> = mydata->fat_sect + mydata->fatlength * bs.fats;
> mydata->clust_size = bs.cluster_size;
> @@ -766,17 +787,20 @@
> - (mydata->clust_size * 2);
> } else {
> rootdir_size = ((bs.dir_entries[1] * (int) 256 + bs.dir_entries[0])
> - * sizeof (dir_entry)) / SECTOR_SIZE;
> + * sizeof (dir_entry)) / mydata->sector_size;
> mydata->data_begin = mydata->rootdir_sect + rootdir_size
> - (mydata->clust_size * 2);
> }
> mydata->fatbufnum = -1;
> + mydata->fatbuf = (__u8 *) malloc (FATBUFSIZE);
> + if(mydata->fatbuf == NULL)
> + return(-1);
>
> FAT_DPRINT ("FAT%d, fatlength: %d\n", mydata->fatsize,
> mydata->fatlength);
> FAT_DPRINT ("Rootdir begins at sector: %d, offset: %x, size: %d\n"
> "Data begins at: %d\n",
> - mydata->rootdir_sect, mydata->rootdir_sect * SECTOR_SIZE,
> + mydata->rootdir_sect, mydata->rootdir_sect * mydata->sector_size,
> rootdir_size, mydata->data_begin);
> FAT_DPRINT ("Cluster size: %d\n", mydata->clust_size);
>
> @@ -787,8 +811,10 @@
> strcpy (fnamecopy, filename);
> downcase (fnamecopy);
> if (*fnamecopy == '\0') {
> - if (!dols)
> - return -1;
> + if (!dols) {
> + free(mydata->fatbuf);
> + return -1;
> + }
> dols = LS_ROOT;
> } else if ((idx = dirdelim (fnamecopy)) >= 0) {
> isdir = 1;
> @@ -806,6 +832,7 @@
>
> if (disk_read (cursect, mydata->clust_size, do_fat_read_block) < 0) {
> FAT_DPRINT ("Error: reading rootdir block\n");
> + free(mydata->fatbuf);
> return -1;
> }
> dentptr = (dir_entry *) do_fat_read_block;
> @@ -856,6 +883,7 @@
> continue;
> }
> } else if (dentptr->name[0] == 0) {
> + free(mydata->fatbuf);
> FAT_DPRINT ("RootDentname == NULL - %d\n", i);
> if (dols == LS_ROOT) {
> printf ("\n%d file(s), %d dir(s)\n\n", files, dirs);
> @@ -906,9 +934,10 @@
> dentptr++;
> continue;
> }
> - if (isdir && !(dentptr->attr & ATTR_DIR))
> + if (isdir && !(dentptr->attr & ATTR_DIR)) {
> + free(mydata->fatbuf);
> return -1;
> -
> + }
> FAT_DPRINT ("RootName: %s", s_name);
> FAT_DPRINT (", start: 0x%x", START (dentptr));
> FAT_DPRINT (", size: 0x%x %s\n",
> @@ -949,20 +978,23 @@
>
> if (get_dentfromdir (mydata, startsect, subname, dentptr,
> isdir ? 0 : dols) == NULL) {
> + free(mydata->fatbuf);
> if (dols && !isdir)
> return 0;
> return -1;
> }
>
> if (idx >= 0) {
> - if (!(dentptr->attr & ATTR_DIR))
> - return -1;
> + if (!(dentptr->attr & ATTR_DIR)) {
> + free(mydata->fatbuf);
> + return -1;
> + }
> subname = nextname;
> }
> }
> ret = get_contents (mydata, dentptr, buffer, maxsize);
> FAT_DPRINT ("Size: %d, got: %ld\n", FAT2CPU32 (dentptr->size), ret);
> -
> + free(mydata->fatbuf);
> return ret;
> }
>
>
>
>
> El lun, 17-11-2008 a las 07:30 -0500, Jerry Van Baren escribi?:
>> Igor Luri wrote:
>> > Dear Remy Bohme,
>> >
>> > Sorry, but I don't have experience in email encoding. I have changed
>> > Evolution's preferences to use ISO-8859-15 intead of UTF-8 caracter
>> > encoding. If this change does not correct the problem, any help would be
>> > apretiated.
>> >
>> > Thanks.
>>
>> Hi Igor,
>>
>> Your patch is linewrapped. Try the hints for using Evolution found in
>> the linux kernel tree under Documentation/email-clients.txt:
>> <http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/email-clients.txt;h=a618efab7b156658be70b29c1a6a9b9c4093e0f5;hb=HEAD#l69>
>>
>> gvb
>>
> --
> Igor Luri
> R&D Software Department
> Fagor Aotek S. Coop.
> P. O. Box 144
> E-20500 Mondrag?n-Arrasate
> Tel. ++34 943 71 92 00
> ++34 943 71 92 01 (Ext. 44268)
> Fax. ++34 943 79 92 03
> www.aotek.es
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot
>
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2008-11-17 19:49 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-17 8:19 [U-Boot] [PATCH] FAT on non standard sector size devices Igor Luri
2008-11-17 12:30 ` Jerry Van Baren
2008-11-17 13:34 ` Igor Luri
2008-11-17 19:49 ` Remy Bohmer
-- strict thread matches above, loose matches on Subject: below --
2008-11-12 16:30 Igor Luri
2008-11-12 19:21 ` Remy Bohmer
2008-11-12 22:01 ` Wolfgang Denk
[not found] <1226492854.5686.8.camel@txema-desktop>
2008-11-12 13:21 ` Igor Luri
2008-11-12 10:09 Igor Luri
2008-11-12 11:25 ` Remy Bohmer
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.