1N/A/* disk_io.c - implement abstract BIOS disk input and output */ 1N/A * GRUB -- GRand Unified Bootloader 1N/A * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc. 1N/A * This program is free software; you can redistribute it and/or modify 1N/A * it under the terms of the GNU General Public License as published by 1N/A * the Free Software Foundation; either version 2 of the License, or 1N/A * (at your option) any later version. 1N/A * This program is distributed in the hope that it will be useful, 1N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of 1N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1N/A * GNU General Public License for more details. 1N/A * You should have received a copy of the GNU General Public License 1N/A * along with this program; if not, write to the Free Software 1N/A * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 1N/A/* instrumentation variables */ 1N/A /* TFTP should come first because others don't handle net device. */ 1N/A /* XX FFS should come last as it's superblock is commonly crossing tracks 1N/A on floppies from track 1 to 2, while others only use 1. */ 1N/A/* These have the same format as "boot_drive" and "install_partition", but 1N/A are meant to be working values. */ 1N/A/* The register ESI should contain the address of the partition to be 1N/A used for loading a chain-loader when chain-loading the loader. */ 1N/A * Global variables describing details of the filesystem 1N/A/* FIXME: BSD evil hack */ 1N/A/* filesystem type */ 1N/A#
endif /* NO_BLOCK_FILES */ 1N/A/* these are the translated numbers for the open partition */ 1N/A/* ZFS root filesystem for booting */ 1N/A/* disk buffer parameters */ 1N/A/* filesystem common variables */ 1N/Astatic inline unsigned long 1N/A asm volatile (
"bsfl %1,%0" 1N/A * Check track buffer. If it isn't valid or it is from the 1N/A * wrong disk, then reset the disk geometry. 1N/A /* Eliminate a buffer overflow. */ 1N/A /* Get the first sector of track. */ 1N/A * If there's more than one read in this entire loop, then 1N/A * only make the earlier reads for the portion needed. This 1N/A * saves filling the buffer with data that won't be used! 1N/A * If there was an error, try to load only the 1N/A * required sector(s) rather than failing completely. 1N/A /* This is a EZD disk map sector 0 to sector 1 */ 1N/A /* We already read the sector 1, copy it to sector 0 */ 1N/A * Instrumentation to tell which sectors were read and used. 1N/A * Check partition boundaries 1N/A * Get the read to the beginning of a partition. 1N/A#
endif /* !STAGE1_5 */ 1N/A * Call RAWREAD, which is very similar, but: 1N/A * -- It takes an extra parameter, the drive number. 1N/A * -- It requires that "sector" is relative to the beginning 1N/A * -- It doesn't handle offsets of more than 511 bytes into the 1N/A /* Clear the cache. */ 1N/A /* If the grub shell is running under Linux and the user wants to 1N/A embed a Stage 1.5 into a partition instead of a MBR, use system 1N/A calls directly instead of biosdisk, because of the bug in 1N/A#
endif /* GRUB_UTIL && __linux__ */ 1N/A#
endif /* ! STAGE1_5 */ 1N/A/* Turn on the active flag for the partition SAVED_PARTITION in the 1N/A drive SAVED_DRIVE. If an error occurs, return zero, otherwise return 1N/A /* If the partition is not a primary partition, the active flag is 1N/A meaningless. (XXX: Really?) */ 1N/A /* Read the MBR in the scratch space. */ 1N/A /* If the partition is an extended partition, setting the active 1N/A flag violates the specification by IBM. */ 1N/A /* Check if the active flag is disabled. */ 1N/A /* Clear all the active flags in this table. */ 1N/A for (i = 0; i <
4; i++)
1N/A /* Write back the MBR. */ 1N/A /* If the drive is not a hard disk drive, you shouldn't call this 1N/A function. (XXX: Should I just ignore this error?) */ 1N/A /* The drive must be a hard disk. */ 1N/A /* The partition must be a PC slice. */ 1N/A /* Look for the partition. */ 1N/A /* Write back the MBR to the disk. */ 1N/A#
endif /* STAGE1_5 */ 1N/A/* Get the information on next partition on the drive DRIVE. 1N/A The caller must not modify the contents of the arguments when 1N/A iterating this function. The partition representation in GRUB will 1N/A be stored in *PARTITION. Likewise, the partition type in *TYPE, the 1N/A start sector in *START, the length in *LEN, the offset of the 1N/A partition table in *OFFSET, the entry number in the table in *ENTRY, 1N/A the offset of the extended partition in *EXT_OFFSET. 1N/A BUF is used to store a MBR, the boot sector of a partition, or 1N/A a BSD label sector, and it must be at least 512 bytes length. 1N/A When calling this function first, *PARTITION must be initialized to 1N/A 0xFFFFFF. The return value is zero if fails, otherwise non-zero. */ 1N/A /* Forward declarations. */ 1N/A /* Get next BSD partition in current PC slice. */ 1N/A /* If this is the first time... */ 1N/A /* Check if the BSD label is within current PC slice. */ 1N/A /* Read the BSD label. */ 1N/A /* Check if it is valid. */ 1N/A /* Search next valid BSD partition. */ 1N/A /* Note that *TYPE and *PARTITION were set 1N/A for current PC slice. */ 1N/A#
endif /* ! STAGE1_5 */ 1N/A /* Get next Solaris partition in current PC slice. */ 1N/A /* If this is the first time... */ 1N/A /* Check if the Solaris label is within current PC slice. */ 1N/A /* Read the Solaris label. */ 1N/A /* Check if it is valid. */ 1N/A /* Search next valid Solaris partition. */ 1N/A /* SOL_PART_START is relative to fdisk partition */ 1N/A /* Get next PC slice. Be careful of that this function may return 1N/A an empty PC slice (i.e. a partition whose type is zero) as well. */ 1N/A /* If this is the first time... */ 1N/A /* Read the MBR or the boot sector of the extended partition. */ 1N/A /* Check if it is valid. */ 1N/A /* Increase the entry number. */ 1N/A /* If this is out of current partition table... */ 1N/A /* Search the first extended partition in current table. */ 1N/A /* Found. Set the new offset and the entry number, 1N/A and restart this function. */ 1N/A /* The calculation of a PC slice number is complicated, because of 1N/A the rather odd definition of extended partitions. Even worse, 1N/A there is no guarantee that this is consistent with every 1N/A operating systems. Uggh. */ 1N/A /* Start the body of this function. */ 1N/A /* check for Solaris partition */ 1N/A /* If previous partition is a BSD partition or a PC slice which 1N/A contains BSD partitions... */ 1N/A /* Get next BSD partition, if any. */ 1N/A /* If the destination partition is a BSD partition and current 1N/A BSD partition has any error, abort the operation. */ 1N/A /* Ignore the error. */ 1N/A/* Open a partition. */ 1N/A /* For simplicity. */ 1N/A /* Make sure that buf_geom is valid. */ 1N/A /* If this is the whole disk, return here. */ 1N/A /* Initialize CURRENT_PARTITION for next_partition. */ 1N/A#
endif /* ! STAGE1_5 */ 1N/A /* If this is a valid partition... */ 1N/A /* Display partition information. */ 1N/A#
endif /* ! STAGE1_5 */ 1N/A /* Check if this is the destination partition. */ 1N/A#
endif /* ! STAGE1_5 */ 1N/A/* XX used for device completion in 'set_device' and 'print_completions' */ 1N/A#
endif /* ! STAGE1_5 */ 1N/A /* In Stage 1.5, the first 4 bytes of FILENAME has a device number. */ 1N/A /* If DRIVE is disabled, use SAVED_DRIVE instead. */ 1N/A /* The `partition' part must always have a valid number. */ 1N/A#
else /* ! STAGE1_5 */ 1N/A /* user has given '(' only, let disk_choice handle what disks we have */ 1N/A#
endif /* SUPPORT_NETBOOT */ 1N/A /* user has given '([fhn]', check for resp. add 'd' and 1N/A let disk_choice handle what disks we have */ 1N/A#
endif /* SUPPORT_NETBOOT */ 1N/A /* Either an absolute PC, BSD, or Solaris partition. */ 1N/A#
endif /* ! STAGE1_5 */ 1N/A * This performs a "mount" on the current device, both drive and partition 1N/A /* Copy the boot partition information to 0x7be-0x7fd for chain-loading. */ 1N/A /* Need only the partition table. 1N/A XXX: We cannot use grub_memmove because BOOT_PART_TABLE 1N/A (0x07be) is less than 0x1000. */ 1N/A /* Set the active flag of the booted partition. */ 1N/A for (i = 0; i <
4; i++)
1N/A * Set BSD boot device. 1N/A /* FIXME: extremely evil hack!!! */ 1N/A#
endif /* STAGE1_5 */ 1N/A#
endif /* ! NO_BLOCK_FILES */ 1N/A#
else /* ! STAGE1_5 */ 1N/A#
endif /* ! NO_BLOCK_FILES */ 1N/A /* allow for the error case of "no filesystem" after the partition 1N/A is found. This makes block files work fine on no filesystem */ 1N/A#
endif /* ! NO_BLOCK_FILES */ 1N/A#
endif /* ! STAGE1_5 */ 1N/A * This prints the filesystem type or gives relevant information. 1N/A#
endif /* STAGE1_5 */ 1N/A/* If DO_COMPLETION is true, just print NAME. Otherwise save the unique 1N/A part into UNIQUE_STRING. */ 1N/A /* If NAME is "." or "..", do not count it. */ 1N/A /* mismatch, strip it. */ 1N/A * This lists the possible completions of a device string, filename, or 1N/A * any sane combination of the two. 1N/A /* Print the completions of builtin commands. */ 1N/A /* If *BUILTIN cannot be run in the command-line, skip it. */ 1N/A /* disk completions */ 1N/A#
endif /* SUPPORT_NETBOOT */ 1N/A for (i = (
ptr && (*(
ptr-
1) ==
'd' && *(
ptr-
2) ==
'h') ?
1:0);
1N/A for (j = 0; j <
8; j++)
1N/A#
endif /* SUPPORT_NETBOOT */ 1N/A /* partition completions */ 1N/A /* filename completions */ 1N/A /* Check if the file UNIQUE_STRING is a directory. */ 1N/A /* Restore the original unique value. */ 1N/A#
endif /* STAGE1_5 */ 1N/A * This is the generic file open function. 1N/A#
endif /* NO_DECOMPRESSION */ 1N/A set it to zero before returning if opening a file! */ 1N/A#
endif /* NO_BLOCK_FILES */ 1N/A /* This accounts for partial filesystem implementations. */ 1N/A /* since we use the same filesystem buffer, mark it to 1N/A#
else /* NO_DECOMPRESSION */ 1N/A#
endif /* NO_DECOMPRESSION */ 1N/A#
else /* NO_BLOCK_FILES */ 1N/A#
endif /* NO_BLOCK_FILES */ 1N/A /* set "dir" function to open a file */ 1N/A#
else /* NO_DECOMPRESSION */ 1N/A#
endif /* NO_DECOMPRESSION */ 1N/A /* Make sure "filepos" is a sane value */ 1N/A /* Make sure "len" is a sane value */ 1N/A /* if target file position is past the end of 1N/A there is an error */ 1N/A#
endif /* NO_DECOMPRESSION */ 1N/A /* we may need to look for the right block in the list(s) */ 1N/A /* run BLK_CUR_FILEPOS up to filepos */ 1N/A /* read current block and put it in the right place in memory */ 1N/A#
endif /* NO_BLOCK_FILES */ 1N/A/* Reposition a file offset. */ 1N/A#
endif /* NO_DECOMPRESSION */ 1N/A /* set "dir" function to list completions */ 1N/A#
endif /* STAGE1_5 */ 1N/A#
endif /* NO_BLOCK_FILES */