?? mkboot.c
字號:
{ printErr ("ctrl is out of range (0-%d).\n", ATA_MAX_CTRLS -1); free (dosVolBootSec); free (lbaSectorOne); return (ERROR); } if ((UINT)drive >= ATA_MAX_DRIVES) { printErr ("drive is out of range(0-%d).\n", ATA_MAX_DRIVES -1); free (dosVolBootSec); free (lbaSectorOne); return (ERROR); } /* * ATA disks formatted via Windows always have partitions. * ATA disks formatted via vxWorks may have partitions or * they may have the dosFs volume start on LBA sector one * without any partition. * * If the dosFs volume starts on LBA sector one, then * the VXDOS, or VXEXT strings will be present there. * * If the partition table (Master Boot Record) resides * on LBA sector one, these strings will not be present. * * MSDOS compatible hard discs always have FDISK style * partitions. For those we must find the bootable partition * sector and modify the dosFs volumes boot sector therein. * The master boot record, the initial partition table, * is always found on LBA sector one on MSDOS hard discs. * * Note that the partition should have a FAT12 or FAT16 * dosFs volume formatted upon it. FAT32 will not work. */ ataRaw.cylinder = 0; ataRaw.head = 0; ataRaw.sector = 1; ataRaw.pBuf = lbaSectorOne; ataRaw.nSecs = 1; ataRaw.direction = 0; ataRawio (ctrl, drive, &ataRaw); pSys = &lbaSectorOne[DOS_BOOT_SYS_ID]; pPart = (DOS_PART_TBL *)&lbaSectorOne[DOS_BOOT_PART_TBL]; if ((strncmp(pSys, VXDOS, strlen(VXDOS)) != 0) && (strncmp(pSys, VXEXT, strlen(VXEXT)) != 0)) { for (ix = 0; ix < 4; ix++) { /* * Note that we are supporting partitions * that could have FAT32 filesystems upon them. * vxLd 1.x will ONLY work on FAT12 and FAT16 * filesystem, it will NOT work on FAT32, * but we should still accept the partition types. * Note that dosFsVolFormat can force FAT type. */ if (pPart->dospt_status == PART_IS_BOOTABLE) if ((pPart->dospt_type == PART_TYPE_DOS12 ) || (pPart->dospt_type == PART_TYPE_DOS3 ) || (pPart->dospt_type == PART_TYPE_DOS4 ) || (pPart->dospt_type == PART_TYPE_DOS32 ) || (pPart->dospt_type == PART_TYPE_DOS32X) || (pPart->dospt_type == PART_TYPE_WIN95_D4)) { found = TRUE; break; } pPart++; } if (!found) { printErr ("Can't find the primary DOS partition.\n"); free (dosVolBootSec); free (lbaSectorOne); return (ERROR); } ataRaw.cylinder = (pPart->dospt_startSec & 0xf0) >> 4; ataRaw.head = pPart->dospt_startHead; ataRaw.sector = pPart->dospt_startSec & 0x0f; ataRaw.pBuf = dosVolBootSec; ataRawio (ctrl, drive, &ataRaw); /* read the boot sector */ offset = pPart->dospt_absSec; if (strncmp((char *)&dosVolBootSec[3], VXEXT, strlen(VXEXT)) == 0) { useLongNames = TRUE; } if (vxsysDebug) printErr ("UseLongNames is %s\n", (useLongNames) ? "TRUE":"FALSE"); } else /* disk is formatted with vxWorks without partition */ { if (strncmp(pSys, VXEXT, strlen(VXEXT)) == 0) { useLongNames = TRUE; } if (vxsysDebug) printErr ("UseLongNames is %s\n", (useLongNames) ? "TRUE":"FALSE"); ataRaw.cylinder = 0; /* read the dosFs volume boot sector */ ataRaw.head = 0; ataRaw.sector = 1; ataRaw.pBuf = dosVolBootSec; ataRaw.nSecs = 1; ataRaw.direction = 0; ataRawio (ctrl, drive, &ataRaw); } /* * Below, we attempt to avoid corrupting a FAT32 image. * For FAT32, the 16bit sectors per FAT field (at offset * 0x16 in a MSDOS FAT volumes boot record) will allways * be zero. For FAT12, FAT16 it is always non-zero. * We will not continue if this offset is zero. */ if ((UINT16) (0x0000) == (UINT16)(dosVolBootSec [0x16])) { printErr ("\nThis appears to be a FAT32 volume.\n"); printErr ("Sectors per FAT, offset 0x16 in the volumes " "boot record is zero.\n"); printErr ("mkbootAta supports only FAT16 or FAT12.\n"); printErr ("dosFsVolFormat can force a FAT type.\n"); free (dosVolBootSec); free (lbaSectorOne); return (ERROR); } if (vxsysBootsec) { dosVolBootSec[0] = 0xeb; /* modify the boot sector */ dosVolBootSec[1] = 0x3c; dosVolBootSec[2] = 0x90; bcopy (bootStrap, (char *)&dosVolBootSec[0x3e], sizeof (bootStrap)); ataRaw.direction = 1; /* write the boot sector */ ataRawio (ctrl, drive, &ataRaw); } if ((pBlkDev = ataDevCreate (ctrl, drive, 0, offset)) == NULL) { printErr ("Error during fdDevCreate: %x\n", errnoGet ()); free (dosVolBootSec); free (lbaSectorOne); return (ERROR); } break;#ifdef INCLUDE_TFFS case VXSYS_TFFS: if ((UINT)drive >= TFFS_MAX_DRIVES) { printErr ("drive is out of range (0-%d).\n", TFFS_MAX_DRIVES-1); free (dosVolBootSec); free (lbaSectorOne); return (ERROR); } /* mount the TFFS */ if ((pBlkDev = tffsDevCreate (drive, removable)) == NULL) { printErr ("Error during fdDevCreate: %x\n", errnoGet ()); free (dosVolBootSec); free (lbaSectorOne); return (ERROR); } /* read the partition table */ tffsRawio (drive, TFFS_ABS_READ, 0, 1, (int)&lbaSectorOne); offset = 0; pSys = &lbaSectorOne[DOS_BOOT_SYS_ID]; pPart = (DOS_PART_TBL *)&lbaSectorOne[DOS_BOOT_PART_TBL]; if ((strncmp(pSys, VXDOS, strlen(VXDOS)) != 0) && (strncmp(pSys, VXEXT, strlen(VXEXT)) != 0)) { for (ix = 0; ix < 4; ix++) { if (pPart->dospt_status == PART_IS_BOOTABLE) if ((pPart->dospt_type == PART_TYPE_DOS12 ) || (pPart->dospt_type == PART_TYPE_DOS3 ) || (pPart->dospt_type == PART_TYPE_DOS4 ) || (pPart->dospt_type == PART_TYPE_DOS32 ) || (pPart->dospt_type == PART_TYPE_DOS32X) || (pPart->dospt_type == PART_TYPE_WIN95_D4)) { found = TRUE; break; } pPart++; } if (found) offset = pPart->dospt_absSec; } /* read the boot sector */ tffsRawio (drive, TFFS_ABS_READ, offset, 1, (int)&dosVolBootSec); if (strncmp((char *)&dosVolBootSec[3], VXEXT, strlen(VXEXT)) == 0) { useLongNames = TRUE; } if (vxsysDebug) printErr ("UseLongNames is %s\n", (useLongNames) ? "TRUE":"FALSE"); /* * Below, we attempt to avoid corrupting a FAT32 image. * For FAT32, the 16bit sectors per FAT field (at offset * 0x16 in a MSDOS FAT volumes boot record) will allways * be zero. For FAT12, FAT16 it is always non-zero. * We will not continue if this offset is zero. */ if ((UINT16)(0x0000) == (UINT16)(dosVolBootSec [0x16])) { printErr ("\nThis appears to be a FAT32 volume.\n"); printErr ("Sectors per FAT, offset 0x16 in the volumes " "boot record is zero.\n"); printErr ("mkbootTffs supports only FAT16 or FAT12.\n"); printErr ("dosFsVolFormat can force a FAT type.\n"); free (dosVolBootSec); free (lbaSectorOne); return (ERROR); } if (vxsysBootsec) { dosVolBootSec[0] = 0xeb; /* modify the boot sector */ dosVolBootSec[1] = 0x3c; dosVolBootSec[2] = 0x90; bcopy (bootStrap, (char *)&dosVolBootSec[0x3e], sizeof (bootStrap)); /* write the boot sector */ tffsRawio (drive, TFFS_ABS_WRITE, offset, 1, (int)&dosVolBootSec); } break;#endif /*INCLUDE_TFFS */ default: printErr ("unknown device (0-1).\n"); free (dosVolBootSec); free (lbaSectorOne); return (ERROR); } if (vxsysBootrom) { /* read the header to get a text-size and a data-size */ if ((inFd = open (in, O_RDONLY, 0644)) == ERROR) { printErr ("Can't open \"%s\"\n", in); free (dosVolBootSec); free (lbaSectorOne); return (ERROR); } if ((read (inFd, (char *)&hdr, sizeof(hdr))) == ERROR) { printErr ("Error during read header: %x\n", errnoGet ()); free (dosVolBootSec); free (lbaSectorOne); return (ERROR); } if (vxsysDebug) printErr ("text=0x%x data=0x%x\n", hdr.a_text, hdr.a_data); /* check the magic number to find out if it is a.out or binary */ if ((hdr.a_magic & AOUT_MAGIC_MASK) == AOUT_MAGIC) /* a.out */ { bytes = hdr.a_text + hdr.a_data; } else /* binary */ { bytes = ROM_SIZE; close (inFd); if ((inFd = open (in, O_RDONLY, 0644)) == ERROR) { printErr ("Can't open \"%s\"\n", in); free (dosVolBootSec); free (lbaSectorOne); return (ERROR); } } if (NULL == dosFsVolDescGet(VXSYS_DOSDEV, (u_char **)&pSys)) { if ((dosFsDevInit (VXSYS_DOSDEV, pBlkDev, NULL)) == NULL) { printErr ("Error during dosFsDevInit: %x\n", errnoGet ()); free (dosVolBootSec); free (lbaSectorOne); return (ERROR); } } if (useLongNames == FALSE) { if ((outFd = open (VXSYS_FILE, O_CREAT | O_RDWR, 0644)) == ERROR) { close (inFd); printErr ("Can't open \"%s\"\n", VXSYS_FILE); free (dosVolBootSec); free (lbaSectorOne); return (ERROR); } } else /* useLongNames file name */ { if ((outFd = open (VXSYS_FILE_VXEXT, O_CREAT | O_RDWR, 0644)) == ERROR) { close (inFd); printErr ("Can't open \"%s\"\n", VXSYS_FILE); free (dosVolBootSec); free (lbaSectorOne); return (ERROR); } } if (ioctl (outFd, FIOCONTIG, bytes) == ERROR) { printErr ("Error during ioctl FIOCONTIG: %x\n", errnoGet ()); free (dosVolBootSec); free (lbaSectorOne); return (ERROR); } /* read text and data, write them to the diskette */ for (ix = 0; ix < bytes; ix += MAX_SECTOR_SIZE) { if (read (inFd, dosVolBootSec, MAX_SECTOR_SIZE) == ERROR) { printErr ("Error during read file: %x\n", errnoGet ()); free (dosVolBootSec); free (lbaSectorOne); return (ERROR); } if (write (outFd, dosVolBootSec, MAX_SECTOR_SIZE) == ERROR) { printErr ("Error during write fd: %x\n", errnoGet ()); free (dosVolBootSec); free (lbaSectorOne); return (ERROR); } } free (dosVolBootSec); free (lbaSectorOne); iosDevDelete (iosDevFind (VXSYS_DOSDEV,&pSys)); close (inFd); close (outFd); } return (OK); }
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -