core: fix "sector size" confusion syslinux-4.00-pre45
authorH. Peter Anvin <hpa@linux.intel.com>
Fri, 14 May 2010 22:22:00 +0000 (15:22 -0700)
committerH. Peter Anvin <hpa@linux.intel.com>
Fri, 14 May 2010 22:22:00 +0000 (15:22 -0700)
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@linux.intel.com>
core/comboot.inc
core/diskfs.inc
core/extern.inc
core/fs/fs.c
core/fs/iso9660/iso9660.c
core/getc.inc
core/isolinux.asm
core/pxelinux.asm
core/runkernel.inc

index 9255f8a..b714dd4 100644 (file)
@@ -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
index b8d0376..9f18c76 100644 (file)
@@ -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
index 6110db0..64edea6 100644 (file)
        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
index 792da02..3ae12ec 100644 (file)
@@ -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;
 }
index 4c568bf..d695e43 100644 (file)
@@ -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;
 }
index efe60de..33656b4 100644 (file)
@@ -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
index d2ba81d..8060767 100644 (file)
@@ -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
index 204b09c..0b87e73 100644 (file)
@@ -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
index bf67b11..25b073f 100644 (file)
@@ -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