aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiu Aleaxander <Aleaxander@gmail.com>2009-05-20 09:58:21 +0800
committerLiu Aleaxander <Aleaxander@gmail.com>2009-05-20 09:58:21 +0800
commit7eb2956a115575912207c6c667e9e8af14ea949a (patch)
tree21eedff6e008af64bb5f5e98ade3c33a3893a61a
parentd168f4e85ebc67c2a68b661d0ec3e62b344ab1b3 (diff)
downloaddevel-7eb2956a115575912207c6c667e9e8af14ea949a.tar.gz
devel-7eb2956a115575912207c6c667e9e8af14ea949a.tar.xz
devel-7eb2956a115575912207c6c667e9e8af14ea949a.zip
Make it work on a FAT16 or FAT32 filesystem
Now, it works on FAT12/16/32 filesystem.
-rw-r--r--README9
-rw-r--r--ldlinux.c23
2 files changed, 25 insertions, 7 deletions
diff --git a/README b/README
index f17b494..11060d3 100644
--- a/README
+++ b/README
@@ -4,6 +4,15 @@
************************************************************************/
+README verion 0.7
+=================
+
+Finally, I have tested it with FAT16 and FAT32; after the debug, it works
+well too. But one thing is really wierd. MS detects the FAT filesystem type
+by the clust number instead of other things that make more sense. So fourcing
+to format a small disk with FAT32 or FAT12 is not a good thing. If you're
+under *NIX, just type mkfs.msdos xxx.img; it works:)
+
README version 0.6
==================
diff --git a/ldlinux.c b/ldlinux.c
index 4e4f776..1bc8e74 100644
--- a/ldlinux.c
+++ b/ldlinux.c
@@ -27,7 +27,7 @@
#define ROOT_DIR_WORD 0x002f
enum fat_type{ FAT12, FAT16, FAT32 };
-__u8 FATType;
+__u8 FATType = 0;
/* generic information about FAT fs */
@@ -170,10 +170,11 @@ __u32 nextcluster(__u32 clust_num)
{
__u32 next_cluster;
__u32 fat_sector;
+ __u32 offset;
struct cache_struct *cs;
+
#if FATType == FAT12
- int offset;
int lo, hi;
#endif
@@ -205,17 +206,19 @@ __u32 nextcluster(__u32 clust_num)
break;
case FAT16:
- fat_sector = clust_num >> (SECTOR_SHIFT - 2);
+ fat_sector = clust_num >> (SECTOR_SHIFT - 1);
+ offset = clust_num & ( (1 << (SECTOR_SHIFT-1)) -1);
cs = getfatsector(fat_sector);
- next_cluster = ((__u16 *)cs->data)[clust_num];
+ next_cluster = ((__u16 *)cs->data)[offset];
if ( next_cluster > 0xfff0 )
goto fail;
break;
case FAT32:
fat_sector = clust_num >> (SECTOR_SHIFT - 2);
+ offset = clust_num & ( (1 << (SECTOR_SHIFT-2)) -1);
cs = getfatsector(fat_sector);
- next_cluster = ((__u32 *)cs->data)[clust_num] & 0x0fffffff;
+ next_cluster = ((__u32 *)cs->data)[offset] & 0x0fffffff;
if ( next_cluster > 0x0ffffff0 )
goto fail;
break;
@@ -253,7 +256,7 @@ __u32 nextsector(__u32 sector)
data_sector = sector - DataArea;
- if ( !data_sector & ClustMask ) /* in a cluster */
+ if ( (data_sector+1) & ClustMask ) /* in a cluster */
return (++sector);
/* got a new cluster */
@@ -863,7 +866,13 @@ __u32 read_file(struct open_file_t *file, char *buf, int size, int *have_more)
void bsr(__u8 *res, int num)
{
- *res = 0;
+ int i = 0;
+
+ while (num >>= 1) {
+ i ++;
+ }
+
+ *res = i;
}
/* init. the fs meta data */