[syslinux:pathbased] core: fix "sector size" confusion

syslinux-bot for H. Peter Anvin hpa at linux.intel.com
Fri May 14 15:24:15 PDT 2010


Commit-ID:  4f2568ba84172915df94995df4ad358d2f09cc0e
Gitweb:     http://syslinux.zytor.com/commit/4f2568ba84172915df94995df4ad358d2f09cc0e
Author:     H. Peter Anvin <hpa at linux.intel.com>
AuthorDate: Fri, 14 May 2010 15:22:00 -0700
Committer:  H. Peter Anvin <hpa at linux.intel.com>
CommitDate: Fri, 14 May 2010 15:22:00 -0700

core: fix "sector size" confusion

Fix the case where the "sector size" used by the pm filesystem driver
isn't the same thing as the SECTOR_SIZE/SECTOR_SHIFT macros used in
the assembly code.  This is a per-device property, and in the
particular case of isolinux hybrid, they are not even currently the
same (for all others, they are the same for now, but not necessarily
in the future.)

Signed-off-by: H. Peter Anvin <hpa at linux.intel.com>


---
 core/comboot.inc          |    8 ++++----
 core/diskfs.inc           |    9 ---------
 core/extern.inc           |    4 +++-
 core/fs/fs.c              |   35 ++++++++++++++++++++++++++++++++++-
 core/fs/iso9660/iso9660.c |    4 ++--
 core/getc.inc             |    5 ++---
 core/isolinux.asm         |   19 -------------------
 core/pxelinux.asm         |   11 -----------
 core/runkernel.inc        |    4 ++--
 9 files changed, 47 insertions(+), 52 deletions(-)

diff --git a/core/comboot.inc b/core/comboot.inc
index 9255f8a..b714dd4 100644
--- a/core/comboot.inc
+++ b/core/comboot.inc
@@ -124,9 +124,8 @@ is_comboot_image:
 		; Now actually load the file...
 		pop si			; File handle
 		mov bx,100h		; Load at <seg>:0100h
-		mov cx,10000h >> SECTOR_SHIFT
-					; Absolute maximum # of sectors
-		pm_call getfssec
+		mov cx,0FF00h		; Maximum number of bytes
+		pm_call getfsbytes
 		cmp ecx,65536-256-2	; Maximum size
 		ja comboot_too_large
 
@@ -586,7 +585,8 @@ comapi_derinfo:
 %else
 		; Physical medium...
 
-		mov P_CL,SECTOR_SHIFT
+		mov al,[SectorShift]
+		mov P_CL,al
 		mov al,[DriveNumber]
 		mov P_DL,al
 		mov P_FS,cs
diff --git a/core/diskfs.inc b/core/diskfs.inc
index b8d0376..9f18c76 100644
--- a/core/diskfs.inc
+++ b/core/diskfs.inc
@@ -171,12 +171,3 @@ exten_table_end:
 %ifdef debug				; This code for debugging only
 debug_magic	dw 0D00Dh		; Debug code sentinel
 %endif
-
-		alignz 4
-BufSafe		dw trackbufsize/SECTOR_SIZE	; Clusters we can load into trackbuf
-BufSafeBytes	dw trackbufsize		; = how many bytes?
-%ifndef DEPEND
-%if ( trackbufsize % SECTOR_SIZE ) != 0
-%error trackbufsize must be a multiple of SECTOR_SIZE
-%endif
-%endif
diff --git a/core/extern.inc b/core/extern.inc
index 6110db0..64edea6 100644
--- a/core/extern.inc
+++ b/core/extern.inc
@@ -10,8 +10,10 @@
 	extern rllpack, rllunpack
 
 	; fs.c
-	extern fs_init, pm_searchdir, getfssec, pm_mangle_name, load_config
+	extern fs_init, pm_searchdir, getfssec, getfsbytes
+	extern pm_mangle_name, load_config
         extern pm_open_file, pm_close_file
+	extern SectorSize, SectorShift
 
 	; chdir.c
 	extern pm_realpath
diff --git a/core/fs/fs.c b/core/fs/fs.c
index 792da02..3ae12ec 100644
--- a/core/fs/fs.c
+++ b/core/fs/fs.c
@@ -117,6 +117,35 @@ void getfssec(com32sys_t *regs)
     regs->ecx.l = bytes_read;
 }
 
+void getfsbytes(com32sys_t *regs)
+{
+    int sectors;
+    bool have_more;
+    uint32_t bytes_read;
+    char *buf;
+    struct file *file;
+    uint16_t handle;
+
+    handle = regs->esi.w[0];
+    file = handle_to_file(handle);
+
+    sectors = regs->ecx.w[0] >> SECTOR_SHIFT(file->fs);
+
+    buf = MK_PTR(regs->es, regs->ebx.w[0]);
+    bytes_read = file->fs->fs_ops->getfssec(file, buf, sectors, &have_more);
+
+    /*
+     * If we reach EOF, the filesystem driver will have already closed
+     * the underlying file... this really should be cleaner.
+     */
+    if (!have_more) {
+	_close_file(file);
+        regs->esi.w[0] = 0;
+    }
+
+    regs->ecx.l = bytes_read;
+}
+
 size_t pmapi_read_file(uint16_t *handle, void *buf, size_t sectors)
 {
     bool have_more;
@@ -353,8 +382,9 @@ void pm_close_file(com32sys_t *regs)
  *    invoke the fs-specific init function;
  *    initialize the cache if we need one;
  *    finally, get the current inode for relative path looking.
- *
  */
+__bss16 uint16_t SectorSize, SectorShift;
+
 void fs_init(com32sys_t *regs)
 {
     static struct fs_info fs;	/* The actual filesystem buffer */
@@ -411,4 +441,7 @@ void fs_init(com32sys_t *regs)
 	fs.root = fs.fs_ops->iget_root(&fs);
 	fs.cwd = get_inode(fs.root);
     }
+
+    SectorShift = fs.sector_shift;
+    SectorSize  = fs.sector_size;
 }
diff --git a/core/fs/iso9660/iso9660.c b/core/fs/iso9660/iso9660.c
index 4c568bf..d695e43 100644
--- a/core/fs/iso9660/iso9660.c
+++ b/core/fs/iso9660/iso9660.c
@@ -206,8 +206,8 @@ static struct inode *iso_get_inode(struct fs_info *fs,
     inode->blocks = (inode->size + BLOCK_SIZE(fs) - 1) >> BLOCK_SHIFT(fs);
 
     /* We have a single extent for all data */
-    inode->next_extent.pstart = de->extent_le << blktosec;
-    inode->next_extent.len = inode->blocks << blktosec;
+    inode->next_extent.pstart = (sector_t)de->extent_le << blktosec;
+    inode->next_extent.len    = (sector_t)inode->blocks << blktosec;
 
     return inode;
 }
diff --git a/core/getc.inc b/core/getc.inc
index efe60de..33656b4 100644
--- a/core/getc.inc
+++ b/core/getc.inc
@@ -23,7 +23,6 @@ MAX_GETC_LG2	equ 4			; Max number of file nesting
 MAX_GETC	equ (1 << MAX_GETC_LG2)
 bytes_per_getc_lg2	equ 16-MAX_GETC_LG2
 bytes_per_getc		equ (1 << bytes_per_getc_lg2)
-secs_per_getc	equ bytes_per_getc/SECTOR_SIZE
 MAX_UNGET	equ 9			; Max bytes that can be pushed back
 
 		struc getc_file
@@ -135,8 +134,8 @@ getc:
 		and si,si
 		mov [di+gc_bufbytes],si	; In case SI == 0
 		jz .empty
-		mov cx,bytes_per_getc >> SECTOR_SHIFT
-		pm_call getfssec
+		mov cx,bytes_per_getc
+		pm_call getfsbytes
 		mov [di+gc_bufbytes],cx
 		mov [di+gc_file],si
 		jcxz .empty
diff --git a/core/isolinux.asm b/core/isolinux.asm
index d2ba81d..8060767 100644
--- a/core/isolinux.asm
+++ b/core/isolinux.asm
@@ -1379,22 +1379,3 @@ img_table:
 		db 80-1			; Max cylinder
 		db 36			; Max sector
 		db 2-1			; Max head
-
-;
-; Misc initialized (data) variables
-;
-
-;
-; Variables that are uninitialized in SYSLINUX but initialized here
-;
-; **** ISOLINUX:: We may have to make this flexible, based on what the
-; **** BIOS expects our "sector size" to be.
-;
-		alignz 4
-BufSafe		dw trackbufsize/SECTOR_SIZE	; Clusters we can load into trackbuf
-BufSafeBytes	dw trackbufsize		; = how many bytes?
-%ifndef DEPEND
-%if ( trackbufsize % SECTOR_SIZE ) != 0
-%error trackbufsize must be a multiple of SECTOR_SIZE
-%endif
-%endif
diff --git a/core/pxelinux.asm b/core/pxelinux.asm
index 204b09c..0b87e73 100644
--- a/core/pxelinux.asm
+++ b/core/pxelinux.asm
@@ -534,14 +534,3 @@ KeepPXE		db 0			; Should PXE be kept around?
 		alignz 4
                 global MyIP
 MyIP		dd 0			; My IP address 
-;
-; Variables that are uninitialized in SYSLINUX but initialized here
-;
-		alignz 4
-BufSafe		dw trackbufsize/TFTP_BLOCKSIZE	; Clusters we can load into trackbuf
-BufSafeBytes	dw trackbufsize		; = how many bytes?
-%ifndef DEPEND
-%if ( trackbufsize % TFTP_BLOCKSIZE ) != 0
-%error trackbufsize must be a multiple of TFTP_BLOCKSIZE
-%endif
-%endif
diff --git a/core/runkernel.inc b/core/runkernel.inc
index bf67b11..25b073f 100644
--- a/core/runkernel.inc
+++ b/core/runkernel.inc
@@ -55,10 +55,10 @@ is_linux_kernel:
 ; work since we might have funny stuff up near the end of memory).
 ;
 		call abort_check		; Check for abort key
-		mov cx,8000h >> SECTOR_SHIFT	; Half a moby (32K)
+		mov cx,8000h			; Half a moby (32K)
 		xor bx,bx
                 pop si                          ; <A> file pointer
-		pm_call getfssec
+		pm_call getfsbytes
 		cmp cx,1024
 		jb kernel_corrupt
                 cmp word [es:bs_bootsign],0AA55h



More information about the Syslinux-commits mailing list