aboutsummaryrefslogtreecommitdiffstats
path: root/ldlinux.c
diff options
context:
space:
mode:
authorLiu Aleaxander <Aleaxander@gmail.com>2009-05-19 16:09:37 +0800
committerLiu Aleaxander <Aleaxander@gmail.com>2009-05-19 16:09:37 +0800
commit88a72896dc32cc4a2a79b962af6b21ec5d442333 (patch)
treeb6869030be29b105edc4c5053de29c8f5fb1588a /ldlinux.c
parentd79c1c9fc74b867b2a060f909b62cc7c1b7dfdac (diff)
downloaddevel-88a72896dc32cc4a2a79b962af6b21ec5d442333.tar.gz
devel-88a72896dc32cc4a2a79b962af6b21ec5d442333.tar.xz
devel-88a72896dc32cc4a2a79b962af6b21ec5d442333.zip
Finally, It can do some work.
yeah, It can compile correctly, but somehow with some bugs, like it can correctly open the /ldlinux.sys file. So I need do more debug tomorrow. What's make me happy is that it can handle long file name:), so it can work somehow.
Diffstat (limited to 'ldlinux.c')
-rw-r--r--ldlinux.c83
1 files changed, 47 insertions, 36 deletions
diff --git a/ldlinux.c b/ldlinux.c
index 9203283..8e697fb 100644
--- a/ldlinux.c
+++ b/ldlinux.c
@@ -47,6 +47,8 @@ __u8 ClustByteShift; /* Shift count for bytes/cluster */
/* for SYSLINUX, the block size equal to the sector size */
__u32 blk_size = 1 << SECTOR_SHIFT;
+/* used for long name dir entry */
+char *NameStart;
int NameLen;
@@ -174,7 +176,7 @@ __u32 nextcluster(__u32 clust_num)
case FAT12:
fat_sector = (clust_num + clust_num / 2) >> SECTOR_SHIFT;
cs = getfatsector(fat_sector);
- next_cluster = ((__u16 *)cs->data)[clust_num];
+ next_cluster = *(__u16 *)(cs->data + (clust_num*3/2) % 512);
if ( clust_num & 0x0001 )
next_cluster >>= 4; /* cluster number is ODD */
else
@@ -231,7 +233,7 @@ __u32 nextsector(__u32 sector)
}
- data_sector -= DataArea;
+ data_sector = sector - DataArea;
if ( !data_sector & ClustMask ) /* in a cluster */
return (++sector);
@@ -250,7 +252,7 @@ __u32 nextsector(__u32 sector)
/**
- * __getfssec_edx:
+ * __getfssec:
*
* get multiple sectors from a file
*
@@ -263,7 +265,7 @@ __u32 nextsector(__u32 sector)
* @param: sectors
*
*/
-void __getfssec(char *buf, __u32 curr_sector, __u32 sectors, int *have_more)
+void __getfssec(char *buf, __u32 curr_sector, __u32 sectors)
{
__u32 frag_start , next_sector;
__u32 con_sec_cnt;
@@ -280,17 +282,25 @@ void __getfssec(char *buf, __u32 curr_sector, __u32 sectors, int *have_more)
if ( sectors == 0 )
break;
- next_sector = nextsector(curr_sector, have_more);
- if ( ! *have_more )
+ next_sector = nextsector(curr_sector);
+ if ( !next_sector )
break;
}while( next_sector == (++curr_sector) );
-
+
+#if 1 /* Debug message */
+ printf("/**************************************************\n");
+ printf("You are reading stores at sector --0x%x--0x%x\n",
+ frag_start, frag_start + con_sec_cnt -1);
+ printf("**************************************************/\n");
+#endif
/* do read */
getlinsec(buf, frag_start, con_sec_cnt);
buf += con_sec_cnt << 9;/* adjust buffer pointer */
-
- curr_sector --; /* this is the last sector actually read */
+
+ if ( !sectors )
+ break;
+ //curr_sector --; /* this is the last sector actually read */
curr_sector = next_sector = nextsector(curr_sector);
}while( sectors );
@@ -314,26 +324,27 @@ void __getfssec(char *buf, __u32 curr_sector, __u32 sectors, int *have_more)
*/
__u32 getfssec(char *buf, struct open_file_t *file, __u32 sectors, int *have_more)
{
- __u32 bytes_read;
+ __u32 bytes_read = sectors << SECTOR_SHIFT;
if ( sectors > file->file_left )
sectors = file->file_left;
- bytes_read = sectors << SECTOR_SHIFT;
-
- file->file_left -= sectors;
- __getfssec_edx(buf, file->file_sector, sectors);
+
+ __getfssec(buf, file->file_sector, sectors);
if ( bytes_read >= file->file_bytesleft ) {
bytes_read = file->file_bytesleft;
file->file_bytesleft = 0;
*have_more = 0;
-
close_file(file);
+
} else {
file->file_bytesleft -= bytes_read;
*have_more = 1;
}
+ file->file_left -= sectors;
+ file->file_sector += sectors;
+
return bytes_read;
}
@@ -342,7 +353,7 @@ __u32 getfssec(char *buf, struct open_file_t *file, __u32 sectors, int *have_mor
-char *NameStart;
+
/**
@@ -444,13 +455,13 @@ void long_entry_name(struct fat_long_name_entry *dir)
}
-__u8 get_checksum(char *entry_name)
+__u8 get_checksum(char *dir_name)
{
int i;
__u8 sum=0;
for (i=11; i; i--)
- sum = ((sum & 1) << 7) + (sum >> 1) + *entry_name++;
+ sum = ((sum & 1) << 7) + (sum >> 1) + *dir_name++;
return sum;
}
@@ -459,7 +470,7 @@ __u32 first_sector(struct fat_dir_entry *dir)
__u32 first_clust, sector;
first_clust = (dir->first_cluster_high << 16) + dir->first_cluster_low;
- sector = (first_clust - 2) << ClustShift + DataArea;
+ sector = ((first_clust - 2) << ClustShift) + DataArea;
return sector;
}
@@ -487,7 +498,7 @@ __u32 first_sector(struct fat_dir_entry *dir)
* @out: dh, clobbered.
*
*/
-struct open_file_t* search_dos_dir(char *MangleBuf, __u32 dir_sector,
+struct open_file_t* search_dos_dir(char *MangleBuf, __u32 dir_sector, \
__u32 *file_len, __u8 *attr)
{
struct open_file_t* file;
@@ -528,7 +539,7 @@ struct open_file_t* search_dos_dir(char *MangleBuf, __u32 dir_sector,
/* scan all the entries in a sector */
do {
- if ( *(char *)dir == 0 )
+ if ( dir->name[0] == 0 )
return NULL; /* Hit directory high water mark */
if ( dir->attr == 0x0f ) {
@@ -577,7 +588,7 @@ struct open_file_t* search_dos_dir(char *MangleBuf, __u32 dir_sector,
* the match is only valid if the checksum matchs.
*/
checksum = get_checksum(dir->name);
- if ( checksum = VFATCsum )
+ if ( checksum == VFATCsum )
goto found; /* got a match on long name */
} else {
@@ -594,7 +605,7 @@ struct open_file_t* search_dos_dir(char *MangleBuf, __u32 dir_sector,
}while ( --entries );
- dir_sector = nextsector(dir_sector, &have_more);
+ dir_sector = nextsector(dir_sector);
}while ( dir_sector ); /* scan another secotr */
@@ -621,9 +632,10 @@ __u32 CurrentDir = 0;
* @return: return the file structure on successful, or NULL.
*
*/
-struct open_file_t* searchdir(char *filename, __u32 *file_len)
+struct open_file_t* searchdir(char *filename)
{
__u32 dir_sector, prev_dir;
+ __u32 file_len;
__u8 attr;
char *p;
@@ -648,16 +660,16 @@ struct open_file_t* searchdir(char *filename, __u32 *file_len)
prev_dir = dir_sector;
mangle_dos_name(MangleBuf, filename);
- file = search_dos_dir(MangleBuf, dir_sector, file_len, &attr);
+ file = search_dos_dir(MangleBuf, dir_sector, &file_len, &attr);
if ( !file ) {
- *file_len = 0;
+ file_len = 0;
return NULL;
}
if ( *p != '/' ) /* we got a file */
break;
- if ( attr & 0x10 ) /* subdirectory */
+ if ( (attr & 0x10) == 0 ) /* subdirectory */
return NULL;
dir_sector = file->file_sector;
@@ -669,8 +681,8 @@ struct open_file_t* searchdir(char *filename, __u32 *file_len)
if ( (attr & 0x18) || (file_len == 0) )
return NULL;
- file->file_bytesleft = *file_len;
- file->file_left = ( *file_len + SECTOR_SIZE -1 ) >> SECTOR_SHIFT;
+ file->file_bytesleft = file_len;
+ file->file_left = ( file_len + SECTOR_SIZE -1 ) >> SECTOR_SHIFT;
return file;
}
@@ -779,10 +791,10 @@ struct open_file_t * readdir(struct open_file_t* dir_file, char* filename,
entries_left --;
if ( !entries_left ) {
- sector = next_sector(sector, &have_more);
+ sector = nextsector(sector);
if ( !sector )
goto fail;
- cs = (struct cache_struct *)get_cache_sector(sector);
+ cs = (struct cache_struct *)get_cache_block(sector);
dir = (struct fat_dir_entry *)cs->data;
}
}
@@ -790,7 +802,7 @@ struct open_file_t * readdir(struct open_file_t* dir_file, char* filename,
/* finally , we get what we want */
entries_left --;
if ( !entries_left ) {
- sector = next_sector(sector, &have_more);
+ sector = nextsector(sector);
if ( !sector )
goto fail;
}
@@ -813,9 +825,8 @@ struct open_file_t * readdir(struct open_file_t* dir_file, char* filename,
struct open_file_t* open_file(char *filename)
{
struct open_file_t *file;
- int file_len;
-
- file = searchdir(filename, &file_len);
+
+ file = searchdir(filename);
/* if we failed, we also will get a NULL value */
return file;
@@ -830,7 +841,7 @@ __u32 read_file(struct open_file_t *file, char *buf, int size, int *have_more)
void bsr(__u8 *res, int num)
{
- *res = 2;
+ *res = 0;
}
/* init. the fs meta data */