; 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
%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
%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
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
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;
* 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 */
fs.root = fs.fs_ops->iget_root(&fs);
fs.cwd = get_inode(fs.root);
}
+
+ SectorShift = fs.sector_shift;
+ SectorSize = fs.sector_size;
}
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;
}
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
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
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
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
; 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