aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile5
-rw-r--r--ldlinux.c83
-rw-r--r--main.c4
3 files changed, 53 insertions, 39 deletions
diff --git a/Makefile b/Makefile
index 63b72cc..097a2c4 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,10 @@
+all:extlinux syslinux
+
+
extlinux:cache.h disklab.h ext2_fs.h
gcc -g cache.c main.c disklab.c extlinux.c -o extlinux
syslinux:cache.h disklab.h fat_fs.h
gcc -g main.c cache.c disklab.c ldlinux.c -o syslinux
clean:
- (rm -f *~ *.o) \ No newline at end of file
+ (rm -f *~ *.o syslinux) \ No newline at end of file
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 */
diff --git a/main.c b/main.c
index 9d1cb3c..2c1be74 100644
--- a/main.c
+++ b/main.c
@@ -116,7 +116,7 @@ int main(int argc, char *argv[])
init_fs(&sb);
- file = (struct open_file_t *)ext2_open(filename);
+ file = (struct open_file_t *)open_file(filename);
if ( ! file ) {
printf("open file error: file %s not found ....\n", filename);
close(fd);
@@ -128,7 +128,7 @@ int main(int argc, char *argv[])
* going well.
*/
do {
- bytes_read = ext2_read(file, buf, 1024, &have_more);
+ bytes_read = read_file(file, buf, 1024, &have_more);
printf("--------read %d bytes-------\n", bytes_read);
printf("----------------\n");
print_hex(buf, bytes_read);