Beispiel #1
0
int get_partition_info_efi(block_dev_desc_t * dev_desc, int part,
				disk_partition_t * info)
{
	ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz);
	gpt_entry *gpt_pte = NULL;

	/* "part" argument must be at least 1 */
	if (!dev_desc || !info || part < 1) {
		printf("%s: Invalid Argument(s)\n", __func__);
		return -1;
	}

	/* This function validates AND fills in the GPT header and PTE */
	if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA,
			gpt_head, &gpt_pte) != 1) {
		printf("%s: *** ERROR: Invalid GPT ***\n", __func__);
		if (is_gpt_valid(dev_desc, (dev_desc->lba - 1),
				 gpt_head, &gpt_pte) != 1) {
			printf("%s: *** ERROR: Invalid Backup GPT ***\n",
			       __func__);
			return -1;
		} else {
			printf("%s: ***        Using Backup GPT ***\n",
			       __func__);
		}
	}

	if (part > le32_to_cpu(gpt_head->num_partition_entries) ||
	    !is_pte_valid(&gpt_pte[part - 1])) {
		debug("%s: *** ERROR: Invalid partition number %d ***\n",
			__func__, part);
		free(gpt_pte);
		return -1;
	}

	/* The 'lbaint_t' casting may limit the maximum disk size to 2 TB */
	info->start = (lbaint_t)le64_to_cpu(gpt_pte[part - 1].starting_lba);
	/* The ending LBA is inclusive, to calculate size, add 1 to it */
	info->size = (lbaint_t)le64_to_cpu(gpt_pte[part - 1].ending_lba) + 1
		     - info->start;
	info->blksz = dev_desc->blksz;

	sprintf((char *)info->name, "%s",
			print_efiname(&gpt_pte[part - 1]));
	sprintf((char *)info->type, "U-Boot");
	info->bootable = is_bootable(&gpt_pte[part - 1]);
#ifdef CONFIG_PARTITION_UUIDS
	uuid_bin_to_str(gpt_pte[part - 1].unique_partition_guid.b, info->uuid,
			UUID_STR_FORMAT_GUID);
#endif

	debug("%s: start 0x" LBAF ", size 0x" LBAF ", name %s\n", __func__,
	      info->start, info->size, info->name);

	/* Remember to free pte */
	free(gpt_pte);
	return 0;
}
Beispiel #2
0
static void print_one_part(dos_partition_t *p, lbaint_t ext_part_sector,
			   int part_num, unsigned int disksig)
{
    lbaint_t lba_start = ext_part_sector + le32_to_uint32(p->start4);
    lbaint_t lba_size  = le32_to_uint32(p->size4);

    printf("%3d\t%-10llu\t%-10llu\t%08x-%02x\t%02x%s%s\n", part_num, lba_start, lba_size, disksig, part_num, p->sys_ind, 
           (is_extended(p->sys_ind) ? " Extd" : ""), (is_bootable(p) ? " Boot" : ""));
}
Beispiel #3
0
static Menu *
add_boot_volume_menu(Directory *bootVolume)
{
    Menu *menu = new(nothrow) Menu(CHOICE_MENU, "Select Boot Volume");
    MenuItem *item;
    void *cookie;
    int32 count = 0;

    if (gRoot->Open(&cookie, O_RDONLY) == B_OK) {
        Directory *volume;
        while (gRoot->GetNextNode(cookie, (Node **)&volume) == B_OK) {
            // only list bootable volumes
            if (!is_bootable(volume))
                continue;

            char name[B_FILE_NAME_LENGTH];
            if (volume->GetName(name, sizeof(name)) == B_OK) {
                menu->AddItem(item = new(nothrow) MenuItem(name));
                item->SetTarget(user_menu_boot_volume);
                item->SetData(volume);

                if (volume == bootVolume) {
                    item->SetMarked(true);
                    item->Select(true);
                }

                count++;
            }
        }
        gRoot->Close(cookie);
    }

    if (count == 0) {
        // no boot volume found yet
        menu->AddItem(item = new(nothrow) MenuItem("<No boot volume found>"));
        item->SetType(MENU_ITEM_NO_CHOICE);
        item->SetEnabled(false);
    }

    menu->AddSeparatorItem();

    menu->AddItem(item = new(nothrow) MenuItem("Rescan volumes"));
    item->SetHelpText("Please insert a Antares CD-ROM or attach a USB disk - "
                      "depending on your system, you can then boot from them.");
    item->SetType(MENU_ITEM_NO_CHOICE);
    if (count == 0)
        item->Select(true);

    menu->AddItem(item = new(nothrow) MenuItem("Return to main menu"));
    item->SetType(MENU_ITEM_NO_CHOICE);

    if (gKernelArgs.boot_volume.GetBool(BOOT_VOLUME_BOOTED_FROM_IMAGE, false))
        menu->SetChoiceText("CD-ROM or hard drive");

    return menu;
}
Beispiel #4
0
void handle_request(int fd, struct link *link, bool check_bootable)
{
	memset(link->buf, 0, sizeof(link->buf));
	memset(&link->src, 0, sizeof(link->src));

	ssize_t size = read_request(fd,
		&link->src, link->buf, sizeof(link->buf));

	if (size <= 0) {
		return;
	}

	if (!check_frame(&link->src, link)) {
		return;
	}

	if ((size_t) size < sizeof(struct ether_arp)) {
		XLOG_WARNING("request to short");
		return;
	}

	struct ether_arp *arp_req = (struct ether_arp *)link->buf;
	if (!check_request(arp_req, &link->src)) {
		return;
	}

	struct in_addr ip;
	memset(&ip, 0, sizeof(in_addr_t));
	int ret = resolve((struct ether_addr*)&arp_req->arp_tha, &ip);
	if (ret != 0) {
		return;
	}

	XLOG_DEBUG("found address: %s", inet_ntoa(ip));
	if (check_bootable == true && !is_bootable(ip)) {
		return;
	}

	create_reply(arp_req, &ip, link);
	dispatcher_flags(&link->handler, POLLOUT);
}
Beispiel #5
0
/*  Print a partition that is relative to its Extended partition table
 */
static int get_partition_info_extended (block_dev_desc_t *dev_desc,
				 lbaint_t ext_part_sector,
				 lbaint_t relative, int part_num,
				 int which_part, disk_partition_t *info,
				 unsigned int disksig)
{
    unsigned char buffer[DOS_PART_DEFAULT_SECTOR];
    dos_partition_t *pt;
    int i;
    int dos_type;

    if (dev_desc->block_read(dev_desc, ext_part_sector, 1, buffer) != 1)
    {
        printf("** Can't read partition table on %d:" LBAFU " **\n", dev_desc->dev, ext_part_sector);
        return -1;
    }
    if (buffer[DOS_PART_MAGIC_OFFSET] != 0x55 || buffer[DOS_PART_MAGIC_OFFSET + 1] != 0xaa)
    {
        printf ("bad MBR sector signature 0x%02x%02x\n", buffer[DOS_PART_MAGIC_OFFSET], buffer[DOS_PART_MAGIC_OFFSET + 1]);
        return -1;
    }

    // disksig is "Disk identifier" shown in "sudo fdisk -l"
    if (!ext_part_sector)
        disksig = le32_to_uint32(&buffer[DOS_PART_DISKSIG_OFFSET]);

    /* Print all primary/logical partitions */
    pt = (dos_partition_t *) (buffer + DOS_PART_TBL_OFFSET);
    for (i = 0; i < 4; i++, pt++)
    {
        /*
         * fdisk does not show the extended partitions that are not in the MBR
         */
        if (((pt->boot_ind & ~0x80) == 0) && (pt->sys_ind != 0) && (part_num == which_part) && (is_extended(pt->sys_ind) == 0))
        {
            info->blksz = DOS_PART_DEFAULT_SECTOR;
            info->start = (lbaint_t)(ext_part_sector + le32_to_uint32(pt->start4));
            info->size  = (lbaint_t)le32_to_uint32(pt->size4);
            switch(dev_desc->if_type)
            {
                case IF_TYPE_IDE:
                case IF_TYPE_SATA:
                case IF_TYPE_ATAPI:
                    sprintf ((char *)info->name, "hd%c%d", 'a' + dev_desc->dev, part_num);
                    break;
                case IF_TYPE_SCSI:
                    sprintf ((char *)info->name, "sd%c%d", 'a' + dev_desc->dev, part_num);
                    break;
                case IF_TYPE_USB:
                    sprintf ((char *)info->name, "usbd%c%d", 'a' + dev_desc->dev, part_num);
                    break;
                case IF_TYPE_DOC:
                    sprintf ((char *)info->name, "docd%c%d", 'a' + dev_desc->dev, part_num);
                    break;
                default:
                    sprintf ((char *)info->name, "xx%c%d", 'a' + dev_desc->dev, part_num);
                    break;
                }
                /* sprintf(info->type, "%d, pt->sys_ind); */
                strcpy((char *)info->type, "U-Boot");
                info->bootable = is_bootable(pt);
                sprintf(info->uuid, "%08x-%02x", disksig, part_num);
                return 0;
        }

        /* Reverse engr the fdisk part# assignment rule! */
        if ((ext_part_sector == 0) || (pt->sys_ind != 0 && !is_extended (pt->sys_ind)) )
        {
            part_num++;
        }
    }

    /* Follows the extended partitions */
    pt = (dos_partition_t *) (buffer + DOS_PART_TBL_OFFSET);
    for (i = 0; i < 4; i++, pt++)
    {
        if (is_extended (pt->sys_ind))
        {
            lbaint_t lba_start = le32_to_uint32(pt->start4) + relative;

            return get_partition_info_extended (dev_desc, lba_start, ext_part_sector == 0 ? lba_start : relative, part_num, which_part, info, disksig);
        }
    }

    /* Check for DOS PBR if no partition is found */
    dos_type = test_block_type(buffer);

    if (dos_type == DOS_PBR)
    {
        info->start = 0;
        info->size = dev_desc->lba;
        info->blksz = DOS_PART_DEFAULT_SECTOR;
        info->bootable = 0;
        strcpy((char *)info->type, "U-Boot");

        info->uuid[0] = 0;

        return 0;
    }

    return -1;
}
Beispiel #6
0
/*  Print a partition that is relative to its Extended partition table
 */
static int get_partition_info_extended (block_dev_desc_t *dev_desc, int ext_part_sector,
				 int relative, int part_num,
				 int which_part, disk_partition_t *info,
				 unsigned int disksig)
{
	ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz);
	dos_partition_t *pt;
	int i;

	if (dev_desc->block_read (dev_desc->dev, ext_part_sector, 1, (ulong *) buffer) != 1) {
		printf ("** Can't read partition table on %d:%d **\n",
			dev_desc->dev, ext_part_sector);
		return -1;
	}
	if (buffer[DOS_PART_MAGIC_OFFSET] != 0x55 ||
		buffer[DOS_PART_MAGIC_OFFSET + 1] != 0xaa) {
		printf ("bad MBR sector signature 0x%02x%02x\n",
			buffer[DOS_PART_MAGIC_OFFSET],
			buffer[DOS_PART_MAGIC_OFFSET + 1]);
		return -1;
	}

#ifdef CONFIG_PARTITION_UUIDS
	if (!ext_part_sector)
		disksig = le32_to_int(&buffer[DOS_PART_DISKSIG_OFFSET]);
#endif

	/* Print all primary/logical partitions */
	pt = (dos_partition_t *) (buffer + DOS_PART_TBL_OFFSET);
	for (i = 0; i < 4; i++, pt++) {
		/*
		 * fdisk does not show the extended partitions that
		 * are not in the MBR
		 */
		if (((pt->boot_ind & ~0x80) == 0) &&
		    (pt->sys_ind != 0) &&
		    (part_num == which_part) &&
		    (is_extended(pt->sys_ind) == 0)) {
			info->blksz = 512;
			info->start = ext_part_sector + le32_to_int (pt->start4);
			info->size  = le32_to_int (pt->size4);
			switch(dev_desc->if_type) {
				case IF_TYPE_IDE:
				case IF_TYPE_SATA:
				case IF_TYPE_ATAPI:
					sprintf ((char *)info->name, "hd%c%d",
						'a' + dev_desc->dev, part_num);
					break;
				case IF_TYPE_SCSI:
					sprintf ((char *)info->name, "sd%c%d",
						'a' + dev_desc->dev, part_num);
					break;
				case IF_TYPE_USB:
					sprintf ((char *)info->name, "usbd%c%d",
						'a' + dev_desc->dev, part_num);
					break;
				case IF_TYPE_DOC:
					sprintf ((char *)info->name, "docd%c%d",
						'a' + dev_desc->dev, part_num);
					break;
				default:
					sprintf ((char *)info->name, "xx%c%d",
						'a' + dev_desc->dev, part_num);
					break;
			}
			/* sprintf(info->type, "%d, pt->sys_ind); */
			sprintf ((char *)info->type, "U-Boot");
			info->bootable = is_bootable(pt);
#ifdef CONFIG_PARTITION_UUIDS
			sprintf(info->uuid, "%08x-%02x", disksig, part_num);
#endif
			return 0;
		}

		/* Reverse engr the fdisk part# assignment rule! */
		if ((ext_part_sector == 0) ||
		    (pt->sys_ind != 0 && !is_extended (pt->sys_ind)) ) {
			part_num++;
		}
	}

	/* Follows the extended partitions */
	pt = (dos_partition_t *) (buffer + DOS_PART_TBL_OFFSET);
	for (i = 0; i < 4; i++, pt++) {
		if (is_extended (pt->sys_ind)) {
			int lba_start = le32_to_int (pt->start4) + relative;

			return get_partition_info_extended (dev_desc, lba_start,
				 ext_part_sector == 0 ? lba_start : relative,
				 part_num, which_part, info, disksig);
		}
	}
	return -1;
}
Beispiel #7
0
int guess_filesystem(int start_session)
{
    int ret = 0;

    read_super(start_session);

#undef _DEBUG
#ifdef _DEBUG
    /* buffer is defined */
    if (is_cdi())     printf("CD-I, ");
    if (is_cd_rtos()) printf("CD-RTOS, ");
    if (is_isofs())   printf("ISOFS, ");
    if (is_hs())      printf("HS, ");
    if (is_bridge())  printf("BRIDGE, ");
    if (is_xa())      printf("XA, ");
    if (is_cdtv())    printf("CDTV, ");
    puts("");
#endif

    /* filesystem */
    if (is_cdi() && is_cd_rtos() && !is_bridge() && !is_xa()) {
        return FS_INTERACTIVE;
    } else {	/* read sector 0 ONLY, when NO greenbook CD-I !!!! */

        read_super2(start_session);

#ifdef _DEBUG
	/* buffer2 is defined */
	if (is_photocd()) printf("PHOTO CD, ");
	if (is_hfs()) printf("HFS, ");
	if (is_ext2()) printf("EXT2 FS, ");
	puts("");
#endif
        if (is_hs())
	    ret |= FS_HIGH_SIERRA;
	else if (is_isofs()) {
	    if (is_cd_rtos() && is_bridge())
	        ret = FS_ISO_9660_INTERACTIVE;
	    else if (is_hfs())
	        ret = FS_ISO_HFS;
	    else
	        ret = FS_ISO_9660;
	    isofs_size = get_size();

	    read_super4(start_session);

#ifdef _DEBUG
	    /* buffer4 is defined */
	    if (is_bootable()) printf("BOOTABLE, ");
	    puts("");
#endif
	    if (is_bootable())
		ret |= BOOTABLE;

	    if (is_bridge() && is_xa() && is_isofs() && is_cd_rtos()) {
	        read_super5(start_session);

#ifdef _DEBUG
		/* buffer5 is defined */
		if (is_video_cdi()) printf("VIDEO-CDI, ");
		puts("");
#endif
		if (is_video_cdi())
		    ret |= VIDEOCDI;
	    }
	} else if (is_hfs())
	    ret |= FS_HFS;
	else if (is_ext2())
	    ret |= FS_EXT2;
	else {

	    read_super3(start_session);

#ifdef _DEBUG
	    /* buffer3 is defined */
	    if (is_ufs()) printf("UFS, ");
	    puts("");
#endif
	    if (is_ufs())
	        ret |= FS_UFS;
	    else
	        ret |= FS_UNKNOWN;
	}
    }
    /* other checks */
    if (is_xa())
        ret |= XA;
    if (is_photocd())
	ret |= PHOTO_CD;
    if (is_cdtv())
	ret |= CDTV;
    return ret;
}