aboutsummaryrefslogtreecommitdiffstats
path: root/isolinux.c
diff options
context:
space:
mode:
authorLiu Aleaxander <Aleaxander@gmail.com>2009-05-24 15:15:07 +0800
committerLiu Aleaxander <Aleaxander@gmail.com>2009-05-24 15:15:07 +0800
commit60ec7dc442d580970c5e72bb972fb5f770160cf4 (patch)
treef3d2bf9285343c8444d2726abac65baa5edf8cbe /isolinux.c
parent03fa5dd9baef4e78c011092ffae1b321c9a3e77e (diff)
downloaddevel-60ec7dc442d580970c5e72bb972fb5f770160cf4.tar.gz
devel-60ec7dc442d580970c5e72bb972fb5f770160cf4.tar.xz
devel-60ec7dc442d580970c5e72bb972fb5f770160cf4.zip
make isolinux do the work
well, for now, we can read a file from a iso image. we also create a iso_main.c file for isolinux 'cause isolinux do not use the cache, and the block size is 2k instead of 512B
Diffstat (limited to 'isolinux.c')
-rw-r--r--isolinux.c145
1 files changed, 97 insertions, 48 deletions
diff --git a/isolinux.c b/isolinux.c
index 9eb7332..12540f9 100644
--- a/isolinux.c
+++ b/isolinux.c
@@ -1,5 +1,10 @@
#include "iso_fs.h"
-#include "cache.h"
+
+
+/*
+ * I also find that we don't use cache here any more
+ */
+//#include "cache.h"
/*
* well, we defined the getlinsec() function here
@@ -49,17 +54,20 @@ struct dir_t {
+struct open_file_t Files[MAX_OPEN];
+
+struct dir_t RootDir;
+struct dir_t CurrentDir;
#define trackbufsize 8192
char trackbuf[trackbufsize] = {0,};
+__u16 BufSafe = trackbufsize >> SECTOR_SHIFT;
+__u16 BufSafeBytes = trackbufsize;
char ISOFileName[64]; /* ISO filename canonicalizatin buffer */
char *ISOFileNameEnd = &ISOFileName[64];
-struct dir_t RootDir;
-struct dir_t CurrentDir;
-
__u32 FirstSecSum; /* checksum of bytes 64-2048 */
__u32 ImageDwords; /* isolinux.bin size, dwords */
__u32 InitStack; /* Initial stack pointer (SS:SP) */
@@ -131,13 +139,20 @@ void close_file(struct open_file_t *file)
file->file_sector = 0;
}
-
+extern int fd;
void getlinsec(char *buf, int sector, int sector_cnt)
{
int bytes_read;
+#if 1 /* Debug message */
+ printf("/**************************************************\n");
+ printf("You are reading stores at sector --0x%x--0x%x\n",
+ sector, sector + sector_cnt -1);
+ printf("**************************************************/\n");
+#endif
+
if ( lseek(fd, sector*SECTOR_SIZE, SEEK_SET) < 0 ) {
- printf("seek file ext2.img error ....\n");
+ printf("seek file iso.img error ....\n");
return;
}
@@ -175,7 +190,7 @@ void mangle_name(char *dst, char *src)
while ( *src > ' ' ) {
if ( *src == '/' ) {
while ( *src == '/' ) {
- cx --;
+ i --;
src ++;
}
*dst++ = '/';
@@ -183,7 +198,7 @@ void mangle_name(char *dst, char *src)
}
*dst++ = *src ++;
- cx --;
+ i --;
}
@@ -195,11 +210,11 @@ void mangle_name(char *dst, char *src)
break;
dst --;
- cx ++;
+ i ++;
}
- cx ++;
- for (; cx > 0; cx -- )
+ i ++;
+ for (; i > 0; i -- )
*dst++ = '\0';
}
@@ -224,18 +239,19 @@ int iso_compare_names(char *de_name, __u32 len, char *file_name)
char *p = ISOFileName;
char c1, c2;
- while ( len && *de_name && (*de_name != ';') && (p < ISOFileNameEnd - 1) ) {
+ int i = len;
+
+ while ( i && *de_name && (*de_name != ';') && (p < ISOFileNameEnd - 1) ) {
*p++ = *de_name++;
- len --;
+ i --;
}
- while ( 1 ) {
+ /* Remove terminal dots */
+ while ( *(p-1) == '.' ) {
if ( p <= ISOFileName )
break;
-
- if ( *(p-1) == '.' ) /* Remove terminal dots */
- p --;
+ p --;
}
*p = '\0';
@@ -243,7 +259,7 @@ int iso_compare_names(char *de_name, __u32 len, char *file_name)
p = ISOFileName;
- do {
+ while ( len ) {
c1 = *p++;
c2 = *file_name++;
@@ -255,9 +271,12 @@ int iso_compare_names(char *de_name, __u32 len, char *file_name)
c1 |= 0x20;
c2 |= 0x20; /* convert to lower case */
- }while ( c1 == c2 );
+ if ( c1 != c2 )
+ return 0;
+ len --;
+ }
- return 0;
+ return 1;
}
@@ -276,7 +295,7 @@ __u32 getfssec(char *buf, struct open_file_t *file, __u32 sectors, int *have_mor
{
__u32 bytes_read = sectors << SECTOR_SHIFT;
- if ( sectros > file->file_left )
+ if ( sectors > file->file_left )
sectors = file->file_left;
getlinsec(buf, file->file_sector, sectors);
@@ -316,9 +335,16 @@ int do_search_dir(struct dir_t *dir, char *name, void **res)
{
struct open_file_t *file;
struct iso_dir_entry *de;
+ struct iso_dir_entry *tmpde;
+
__u32 offset = 0; /* let's start it with the start */
__u32 file_pos = 0;
+
+ char *de_name;
+ int de_len;
+ int de_name_len;
+ int have_more;
file = allocate_file();
if ( !file )
@@ -341,16 +367,10 @@ int do_search_dir(struct dir_t *dir, char *name, void **res)
de = (struct iso_dir_entry *) (trackbuf + offset);
- de_len = iso_dir->length;
+ de_len = de->length;
if ( de_len == 0) {
- file_pos = (file_pos+SECTOR_SIZE) & ~(SECTOR_SIZE-1);
- file->file_sector ++;
- if ( !have_more )
- return 0;
- getfssec(trackbuf, file, BufSafe, &have_more);
- offset = 0;
-
+ offset = file_pos = (file_pos+SECTOR_SIZE) & ~(SECTOR_SIZE-1);
continue;
}
@@ -362,12 +382,12 @@ int do_search_dir(struct dir_t *dir, char *name, void **res)
int slop = trackbufsize - offset + de_len;
memcpy(tmpde, de, slop);
offset &= trackbufsize - 1;
- file->sector ++;
+ file->file_sector ++;
if ( offset ) {
if ( !have_more )
return 0;
getfssec(trackbuf, file, BufSafe, &have_more);
- memcpy((void*) tmp + slop, trackbuf, offset);
+ memcpy((void*)tmpde + slop, trackbuf, offset);
}
de = tmpde;
}
@@ -378,14 +398,15 @@ int do_search_dir(struct dir_t *dir, char *name, void **res)
}
de_name_len = de->name_len;
- if ( iso_compare_names(de->name, name, de_name_len) )
+ de_name = (char *)((void *)de + 0x21);
+ if ( iso_compare_names(de_name, de_name_len, name) )
break; /* we found it */
file_pos += de_len;
}
- if ( *(filename+de_name) && (*(name+de_name) != '/' ) ) {
+ if ( *(name+de_name_len) && (*(name+de_name_len) != '/' ) ) {
*res = NULL;
return 0;
}
@@ -393,7 +414,7 @@ int do_search_dir(struct dir_t *dir, char *name, void **res)
if ( de->flags & 0x02 ) {
/* it's a directory */
- dir = CurrentDir;
+ dir = &CurrentDir;
dir->dir_lba = *(__u32 *)de->extent;
dir->dir_len = *(__u32 *)de->size;
@@ -444,12 +465,13 @@ struct open_file_t *searchdir(char *filename)
struct iso_dir_entry *de;
void *res;
-
+ int ret;
int flag = 0;
- dir = CurrentDir;
+
+ dir = &CurrentDir;
if ( *filename == '/' ) {
- dir = RootDir;
+ dir = &RootDir;
filename ++;
}
@@ -457,7 +479,7 @@ struct open_file_t *searchdir(char *filename)
ret = do_search_dir(dir, filename, &res);
if ( ret == 1 )
- dir = (struct dir_t *) res;
+ dir = (struct dir_t *)res;
else if ( ret == 2 )
break;
else
@@ -487,22 +509,47 @@ struct open_file_t *searchdir(char *filename)
}
}
+
+
+
+struct open_file_t *open_file(char *filename)
+{
+ return searchdir(filename);
+}
+
+
+__u32 read_file(struct open_file_t *file, char *buf, int size, int *have_more)
+{
+ __u32 sectors = ( size + SECTOR_SIZE - 1 ) >> SECTOR_SHIFT;
+
+ return getfssec(buf, file, sectors, have_more);
+}
+
+
+char *boot_dir = "/boot/isolinux";
+char *isolinux_dir = "/isolinux";
+
+int bi_pvd = 16;
void init_fs()
{
-
+ char CurrentDirName[64];
+ char *iso_dir;
+
+ struct open_file_t *file;
+ int len;
getlinsec(trackbuf, bi_pvd, 1);
- CurrentDir->dir_lba = RootDir->dir_lba = *(__u32 *)(trackbuf + 156 + 2);
+ CurrentDir.dir_lba = RootDir.dir_lba = *(__u32 *)(trackbuf + 156 + 2);
#ifdef DEBUG
- printf("Root directory at LBA = 0x%x\n", RootDir->dir_lba);
+ printf("Root directory at LBA = 0x%x\n", RootDir.dir_lba);
#endif
- CurrentDir->dir_len = RootDir->dir_len = *(__u32*)(trackbuf + 156 + 10);
- CurrentDir->dir_clust = RootDir->dir_clust = (RootDir->dir_len + SECTOR_SIZE - 1) >> SECTOR_SHIFT;
+ CurrentDir.dir_len = RootDir.dir_len = *(__u32*)(trackbuf + 156 + 10);
+ CurrentDir.dir_clust = RootDir.dir_clust = (RootDir.dir_len + SECTOR_SIZE - 1) >> SECTOR_SHIFT;
/*
@@ -528,15 +575,17 @@ void init_fs()
CurrentDirName[len] = '/';
CurrentDirName[len+1] = '\0';
- CurrentDir->dir_len = file->file_bytesleft;
- CurrentDir->dir_clust = file->file_left;
- CurrentDir->dir_lba = file->file_sector;
+ CurrentDir.dir_len = file->file_bytesleft;
+ CurrentDir.dir_clust = file->file_left;
+ CurrentDir.dir_lba = file->file_sector;
close_file(file);
#ifdef DEBUG
- printf("isolinux directory at LBA = %0x%x\n", CurrentDirName->dir_lba);
+ printf("isolinux directory at LBA = %0x%x\n", CurrentDir.dir_lba);
#endif
+
+ return;
no_isolinux_dir:
- ;
+ printf("No isolinux directory found\n");
}