aboutsummaryrefslogtreecommitdiffstats
path: root/x-loader/fs/fat
diff options
context:
space:
mode:
Diffstat (limited to 'x-loader/fs/fat')
-rw-r--r--x-loader/fs/fat/Makefile15
-rw-r--r--x-loader/fs/fat/fat.c32
2 files changed, 27 insertions, 20 deletions
diff --git a/x-loader/fs/fat/Makefile b/x-loader/fs/fat/Makefile
index e462757..2fa428c 100644
--- a/x-loader/fs/fat/Makefile
+++ b/x-loader/fs/fat/Makefile
@@ -19,28 +19,27 @@
# MA 02111-1307 USA
#
-TOPDIR=../../
-
include $(TOPDIR)/config.mk
-LIB = libfat.a
+LIB = $(obj)libfat.a
AOBJS =
COBJS = fat.o file.o
-OBJS = $(AOBJS) $(COBJS)
+SRCS := $(AOBJS:.o=.S) $(COBJS:.o=.c)
+OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS))
all: $(LIB) $(AOBJS)
-$(LIB): .depend $(OBJS)
+$(LIB): $(obj).depend $(OBJS)
$(AR) crv $@ $(OBJS)
#########################################################################
-.depend: Makefile $(AOBJS:.o=.S) $(COBJS:.o=.c)
- $(CC) -M $(CFLAGS) $(AOBJS:.o=.S) $(COBJS:.o=.c) > $@
+# defines $(obj).depend target
+include $(SRCTREE)/rules.mk
-sinclude .depend
+sinclude $(obj).depend
#########################################################################
diff --git a/x-loader/fs/fat/fat.c b/x-loader/fs/fat/fat.c
index 0e91556..44ecb4a 100644
--- a/x-loader/fs/fat/fat.c
+++ b/x-loader/fs/fat/fat.c
@@ -145,13 +145,11 @@ fat_register_device(block_dev_desc_t *dev_desc, int part_no)
return -1;
}
#else
- /* FIXME we need to determine the start block of the
- * partition where the DOS FS resides. This can be done
- * by using the get_partition_info routine. For this
- * purpose the libpart must be included.
- */
- part_offset=63;
- //part_offset=0;
+ part_offset = buffer[DOS_PART_TBL_OFFSET+8] |
+ buffer[DOS_PART_TBL_OFFSET+9] <<8 |
+ buffer[DOS_PART_TBL_OFFSET+10]<<16 |
+ buffer[DOS_PART_TBL_OFFSET+11]<<24;
+
cur_part = 1;
#endif
}
@@ -386,7 +384,7 @@ get_contents(fsdata *mydata, dir_entry *dentptr, __u8 *buffer,
newclust = get_fatent(mydata, endclust);
if((newclust -1)!=endclust)
goto getit;
- if (newclust <= 0x0001 || newclust >= 0xfff0) {
+ if (newclust <= 0x0001 || newclust >= 0xfffff0) {
FAT_DPRINT("curclust: 0x%x\n", newclust);
FAT_DPRINT("Invalid FAT entry\n");
return gotsize;
@@ -421,7 +419,7 @@ getit:
filesize -= actsize;
buffer += actsize;
curclust = get_fatent(mydata, endclust);
- if (curclust <= 0x0001 || curclust >= 0xfff0) {
+ if (curclust <= 0x0001 || curclust >= 0xfffff0) {
FAT_DPRINT("curclust: 0x%x\n", curclust);
FAT_ERROR("Invalid FAT entry\n");
return gotsize;
@@ -582,7 +580,7 @@ static dir_entry *get_dentfromdir (fsdata * mydata, int startsect,
return retdent;
}
curclust = get_fatent (mydata, curclust);
- if (curclust <= 0x0001 || curclust >= 0xfff0) {
+ if (curclust <= 0x0001 || curclust >= 0xfffff0) {
FAT_DPRINT ("curclust: 0x%x\n", curclust);
FAT_ERROR ("Invalid FAT entry\n");
return NULL;
@@ -681,7 +679,7 @@ do_fat_read(const char *filename, void *buffer, unsigned long maxsize,
dir_entry *dentptr;
__u16 prevcksum = 0xffff;
char *subname = "";
- int rootdir_size, cursect;
+ int rootdir_size, cursect, curclus;
int idx, isdir = 0;
int files = 0, dirs = 0;
long ret = 0;
@@ -699,6 +697,7 @@ do_fat_read(const char *filename, void *buffer, unsigned long maxsize,
mydata->fat_sect = bs.reserved;
cursect = mydata->rootdir_sect
= mydata->fat_sect + mydata->fatlength * bs.fats;
+ curclus = bs.root_cluster; // For FAT32 only
mydata->clust_size = bs.cluster_size;
if (mydata->fatsize == 32) {
rootdir_size = mydata->clust_size;
@@ -820,7 +819,16 @@ do_fat_read(const char *filename, void *buffer, unsigned long maxsize,
goto rootdir_done; /* We got a match */
}
- cursect++;
+
+ if (mydata->fatsize != 32)
+ cursect++;
+ else {
+ // FAT32 does not guarantee contiguous root directory
+ curclus = get_fatent (mydata, curclus);
+ cursect = (curclus * mydata->clust_size) + mydata->data_begin;
+
+ FAT_DPRINT ("root clus %d sector %d\n", curclus, cursect);
+ }
}
rootdir_done: