[syslinux] Patch: Add io.c functions, and vfat library

Ram Yalamanchili ramyinc at gmail.com
Thu Apr 5 01:04:18 PDT 2007


This is a continuation to the library creation effort for syslinux.

I added the necessary ops required to read partitions and sectors off
the disk. I'm using it with my com32 module. I did change the
interface for read_disk a bit, so it takes a disk_info argument. This
way I can maintain multiple instances of read handlers, for example if
I'm reading and comparing stuff from two different partitions, etc.

There was some discussion on whether the FAT library, should be in
com32/lib, but its quite helpful for me since I can hook my own
read_handler for any partition on any disk, and use libfat to read
files off it. Here is an example:


typedef struct filedesc {
   diskinfo* disk_info;
   part_entry* partition;
} filedesc;

static filedesc rFd;

static int fat_disk_read_handle(intptr_t fdp, void* buf, size_t nbyte,
libfat_sector_t sector)
{
   filedesc* fd = (filedesc*) fdp;
   int num_sectors = nbyte / LIBFAT_SECTOR_SIZE;
   int status;

   sector += fd->partition->start_lba;
   status = syslinux_read_disk(fd->disk_info, buf, sector, num_sectors);

   return (status) ? 0 : nbyte;
}

and in some function like main():

   /* Get the disk geometry (not needed for MBR) */
   if ( syslinux_get_disk_params(drive, &disk_info) ) {
      error("Cannot get disk parameters\n");
      goto error;
   }

   /* Get MBR */
   if ( syslinux_read_disk(&disk_info, mbr, 0, 1) ) {
      error("Cannot read Master Boot Record\n");
      goto error;
   }

   /* Get 1st partition info */
   bank1_part_info = PARTITION_ENTRY(mbr, bank1);
   if (bank1_part_info->ostype != PART_TYPE_FAT16) {
      error("Warning: Bank 1 is of wrong type");
   }

   /* Get 2nd partition info */
   bank2_part_info = PARTITION_ENTRY(mbr, bank2);
   if (bank2_part_info->ostype != PART_TYPE_FAT16) {
      error("Warning: Bank 2 is of wrong type");
   }

   rFd.disk_info = &disk_info;
   rFd.partition = bank1_part_info;

   fat_fs = libfat_open(fat_disk_read_handle, (intptr_t) &rFd);
   bootcfg_cluster = libfat_searchdir(fat_fs, 0, "BOOT    CFG", NULL);
   if (bootcfg_cluster <= 0) {
      error("No boot config file found");
   }

   bootcfg_sector = libfat_clustertosector(fat_fs, bootcfg_cluster) +
rFd.partition->start_lba;
   if (!syslinux_read_disk(&disk_info, sectorbuf, bootcfg_sector, 1)) {
      printf("boot.cfg: %s\n", sectorbuf);
   }

I will change chain.c to use the library functions, but kinda busy
with other stuff at the moment. I'll do it next week hopefully.

thanks.

--
Ram

(patch is attached, not sure if attachments work though!)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: io_fat_lib_syslinux_3.50p4
Type: application/octet-stream
Size: 29029 bytes
Desc: not available
URL: <http://www.zytor.com/pipermail/syslinux/attachments/20070405/c946d6c6/attachment.obj>


More information about the Syslinux mailing list