Exemplo n.º 1
0
int mac_partition(struct parsed_partitions *state)
{
	Sector sect;
	unsigned char *data;
	int slot, blocks_in_map;
	unsigned secsize;
#ifdef CONFIG_PPC_PMAC
	int found_root = 0;
	int found_root_goodness = 0;
#endif
	struct mac_partition *part;
	struct mac_driver_desc *md;

	/*                                                          */
	md = read_part_sector(state, 0, &sect);
	if (!md)
		return -1;
	if (be16_to_cpu(md->signature) != MAC_DRIVER_MAGIC) {
		put_dev_sector(sect);
		return 0;
	}
	secsize = be16_to_cpu(md->block_size);
	put_dev_sector(sect);
	data = read_part_sector(state, secsize/512, &sect);
	if (!data)
		return -1;
	part = (struct mac_partition *) (data + secsize%512);
	if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC) {
		put_dev_sector(sect);
		return 0;		/*                  */
	}
	blocks_in_map = be32_to_cpu(part->map_count);
	if (blocks_in_map < 0 || blocks_in_map >= DISK_MAX_PARTS) {
		put_dev_sector(sect);
		return 0;
	}
	strlcat(state->pp_buf, " [mac]", PAGE_SIZE);
	for (slot = 1; slot <= blocks_in_map; ++slot) {
		int pos = slot * secsize;
		put_dev_sector(sect);
		data = read_part_sector(state, pos/512, &sect);
		if (!data)
			return -1;
		part = (struct mac_partition *) (data + pos%512);
		if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC)
			break;
		put_partition(state, slot,
			be32_to_cpu(part->start_block) * (secsize/512),
			be32_to_cpu(part->block_count) * (secsize/512));

		if (!strnicmp(part->type, "Linux_RAID", 10))
			state->parts[slot].flags = ADDPART_FLAG_RAID;
#ifdef CONFIG_PPC_PMAC
		/*
                                                      
                                                        
   */
		if (machine_is(powermac)) {
			int goodness = 0;

			mac_fix_string(part->processor, 16);
			mac_fix_string(part->name, 32);
			mac_fix_string(part->type, 32);					
		    
			if ((be32_to_cpu(part->status) & MAC_STATUS_BOOTABLE)
			    && strcasecmp(part->processor, "powerpc") == 0)
				goodness++;

			if (strcasecmp(part->type, "Apple_UNIX_SVR2") == 0
			    || (strnicmp(part->type, "Linux", 5) == 0
			        && strcasecmp(part->type, "Linux_swap") != 0)) {
				int i, l;

				goodness++;
				l = strlen(part->name);
				if (strcmp(part->name, "/") == 0)
					goodness++;
				for (i = 0; i <= l - 4; ++i) {
					if (strnicmp(part->name + i, "root",
						     4) == 0) {
						goodness += 2;
						break;
					}
				}
				if (strnicmp(part->name, "swap", 4) == 0)
					goodness--;
			}

			if (goodness > found_root_goodness) {
				found_root = slot;
				found_root_goodness = goodness;
			}
		}
#endif /*                 */
	}
#ifdef CONFIG_PPC_PMAC
	if (found_root_goodness)
		note_bootable_part(state->bdev->bd_dev, found_root,
				   found_root_goodness);
#endif

	put_dev_sector(sect);
	strlcat(state->pp_buf, "\n", PAGE_SIZE);
	return 1;
}
Exemplo n.º 2
0
int mac_partition(struct gendisk *hd, kdev_t dev, unsigned long fsec, int first_part_minor)
{
	struct buffer_head *bh;
	int blk, blocks_in_map;
	int dev_bsize, dev_pos, pos;
	unsigned secsize;
#ifdef CONFIG_PPC
	int found_root = 0;
	int found_root_goodness = 0;
#endif
	struct mac_partition *part;
	struct mac_driver_desc *md;

	dev_bsize = get_ptable_blocksize(dev);
	dev_pos = 0;
	/* Get 0th block and look at the first partition map entry. */
	if ((bh = bread(dev, 0, dev_bsize)) == 0) {
	    printk("%s: error reading partition table\n",
		   kdevname(dev));
	    return -1;
	}
	md = (struct mac_driver_desc *) bh->b_data;
	if (be16_to_cpu(md->signature) != MAC_DRIVER_MAGIC) {
		brelse(bh);
		return 0;
	}
	secsize = be16_to_cpu(md->block_size);
	if (secsize >= dev_bsize) {
		brelse(bh);
		dev_pos = secsize;
		if ((bh = bread(dev, secsize/dev_bsize, dev_bsize)) == 0) {
			printk("%s: error reading partition table\n",
			       kdevname(dev));
			return -1;
		}
	}
	part = (struct mac_partition *) (bh->b_data + secsize - dev_pos);
	if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC) {
		brelse(bh);
		return 0;		/* not a MacOS disk */
	}
	blocks_in_map = be32_to_cpu(part->map_count);
	for (blk = 1; blk <= blocks_in_map; ++blk) {
		pos = blk * secsize;
		if (pos >= dev_pos + dev_bsize) {
			brelse(bh);
			dev_pos = pos;
			if ((bh = bread(dev, pos/dev_bsize, dev_bsize)) == 0) {
				printk("%s: error reading partition table\n",
				       kdevname(dev));
				return -1;
			}
		}
		part = (struct mac_partition *) (bh->b_data + pos - dev_pos);
		if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC)
			break;
		blocks_in_map = be32_to_cpu(part->map_count);
		add_gd_partition(hd, first_part_minor,
			fsec + be32_to_cpu(part->start_block) * (secsize/512),
			be32_to_cpu(part->block_count) * (secsize/512), 0);

#ifdef CONFIG_PPC
		/*
		 * If this is the first bootable partition, tell the
		 * setup code, in case it wants to make this the root.
		 */
		if (_machine == _MACH_Pmac) {
			int goodness = 0;
		    
			if ((be32_to_cpu(part->status) & MAC_STATUS_BOOTABLE)
			    && strcasecmp(part->processor, "powerpc") == 0)
				goodness++;

			if (strcasecmp(part->type, "Apple_UNIX_SVR2") == 0) {
				goodness++;
				if ((strcmp(part->name, "/") == 0) ||
				    (strstr(part->name, "root") != 0)) {
					goodness++;
				}
				if (strncmp(part->name, "swap", 4) == 0)
					goodness--;
			}

			if (goodness > found_root_goodness) {
				found_root = blk;
				found_root_goodness = goodness;
			}
		}
#endif /* CONFIG_PPC */

		++first_part_minor;
	}
#ifdef CONFIG_PPC
	if (found_root_goodness)
		note_bootable_part(dev, found_root);
#endif
	brelse(bh);
	printk("\n");
	return 1;
}
Exemplo n.º 3
0
int mac_partition(struct parsed_partitions *state, struct block_device *bdev)
{
    int slot = 1;
    Sector sect;
    unsigned char *data;
    int blk, blocks_in_map;
    unsigned secsize;
#ifdef CONFIG_PPC_PMAC
    int found_root = 0;
    int found_root_goodness = 0;
#endif
    struct mac_partition *part;
    struct tivo_bigpartition *bigpart;
    struct mac_driver_desc *md;
#ifdef CONFIG_TIVO
    int tivo_only = 0;
#endif

    /* Get 0th block and look at the first partition map entry. */
    md = (struct mac_driver_desc *) read_dev_sector(bdev, 0, &sect);
    if (!md)
        return -1;
#ifdef CONFIG_TIVO
    switch(be16_to_cpu(md->signature)) {
    case MAC_DRIVER_MAGIC:
        secsize = be16_to_cpu(md->block_size);
        put_dev_sector(sect);
        data = read_dev_sector(bdev, secsize/512, &sect);
        if (!data)
            return -1;
        part = (struct mac_partition *)(data + secsize % 512);
        break;
    case TIVO_BOOT_MAGIC:
        tivo_only = 0;
        secsize = 512;
        data = read_dev_sector(bdev, 1, &sect);
        if (!data)
            return -1;
        part = (struct mac_partition *)data;
        break;
    default:
        put_dev_sector(sect);
        printk("block 0 has signature %x rather than %x or %x\n",
               be16_to_cpu(md->signature), MAC_DRIVER_MAGIC,
               TIVO_BOOT_MAGIC);
        return 0;
    }
#else
    if (be16_to_cpu(md->signature) != MAC_DRIVER_MAGIC) {
        put_dev_sector(sect);
        return 0;
    }
    secsize = be16_to_cpu(md->block_size);
    put_dev_sector(sect);
    data = read_dev_sector(bdev, secsize/512, &sect);
    if (!data)
        return -1;
    part = (struct mac_partition *) (data + secsize%512);
#endif
    if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC) {
        put_dev_sector(sect);
        return 0;		/* not a MacOS disk */
    }
#ifdef CONFIG_TIVO
    printk(" [%s]", (be16_to_cpu(md->signature) == TIVO_BOOT_MAGIC) ? "tivo" : "mac");
#else
    printk(" [mac]");
#endif
    blocks_in_map = be32_to_cpu(part->map_count);
    for (blk = 1; blk <= blocks_in_map; ++blk) {
        int pos = blk * secsize;
        put_dev_sector(sect);
        data = read_dev_sector(bdev, pos/512, &sect);
        if (!data)
            return -1;
        part = (struct mac_partition *) (data + pos%512);
        switch (be16_to_cpu(part->signature)) {
        case MAC_PARTITION_MAGIC:
#ifdef CONFIG_TIVO
            if (tivo_only && strncmp(part->type, "TiVo", 4) != 0) {
                continue;
            }
#endif
            put_partition(state, slot,
                          be32_to_cpu(part->start_block) * (secsize/512),
                          be32_to_cpu(part->block_count) * (secsize/512));

#ifdef CONFIG_TIVO
            /* Check for media partition */
            if (be32_to_cpu(part->status) & 0x100) {
                state->parts[slot].driver_flags = 1;
                printk("[M]");
            }
#endif

#ifdef CONFIG_PPC_PMAC
            /*
             * If this is the first bootable partition, tell the
             * setup code, in case it wants to make this the root.
             */
            if (machine_is(powermac)) {
                int goodness = 0;

                mac_fix_string(part->processor, 16);
                mac_fix_string(part->name, 32);
                mac_fix_string(part->type, 32);

                if ((be32_to_cpu(part->status) & MAC_STATUS_BOOTABLE)
                        && strcasecmp(part->processor, "powerpc") == 0)
                    goodness++;

                if (strcasecmp(part->type, "Apple_UNIX_SVR2") == 0
                        || (strnicmp(part->type, "Linux", 5) == 0
                            && strcasecmp(part->type, "Linux_swap") != 0)) {
                    int i, l;

                    goodness++;
                    l = strlen(part->name);
                    if (strcmp(part->name, "/") == 0)
                        goodness++;
                    for (i = 0; i <= l - 4; ++i) {
                        if (strnicmp(part->name + i, "root",
                                     4) == 0) {
                            goodness += 2;
                            break;
                        }
                    }
                    if (strnicmp(part->name, "swap", 4) == 0)
                        goodness--;
                }

                if (goodness > found_root_goodness) {
                    found_root = blk;
                    found_root_goodness = goodness;
                }
            }
#endif /* CONFIG_PPC_PMAC */

            ++slot;
            break;
#ifdef CONFIG_TIVO
        case TIVO_BIGPARTITION_MAGIC:
            bigpart = (struct tivo_bigpartition *) part;
            put_partition(state, slot,
                          be64_to_cpu(bigpart->start_block) * (secsize/512),
                          be64_to_cpu(bigpart->block_count) * (secsize/512));
            /* Show that we found the big-partition code */
            printk("!");
            /* Check for media partition */
            if (be32_to_cpu(bigpart->status) & 0x100) {
                state->parts[slot].driver_flags = 1;
                printk("[M]");
            }
            ++slot;
#endif
            break;
        default:
            break;
        }
    }
#ifdef CONFIG_PPC_PMAC
    if (found_root_goodness)
        note_bootable_part(bdev->bd_dev, found_root, found_root_goodness);
#endif

    put_dev_sector(sect);
    printk("\n");
    return 1;
}
Exemplo n.º 4
0
int mac_partition(struct parsed_partitions *state, struct block_device *bdev)
{
	Sector sect;
	unsigned char *data;
	int slot, blocks_in_map;
	unsigned secsize;
#ifdef CONFIG_PPC_PMAC
	int found_root = 0;
	int found_root_goodness = 0;
#endif
	struct mac_partition *part;
	struct mac_driver_desc *md;

	/* Get 0th block and look at the first partition map entry. */
	md = (struct mac_driver_desc *) read_dev_sector(bdev, 0, &sect);
	if (!md)
		return -1;
	if (be16_to_cpu(md->signature) != MAC_DRIVER_MAGIC) {
		put_dev_sector(sect);
		return 0;
	}
	secsize = be16_to_cpu(md->block_size);
	put_dev_sector(sect);
	data = read_dev_sector(bdev, secsize/512, &sect);
	if (!data)
		return -1;
	part = (struct mac_partition *) (data + secsize%512);
	if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC) {
		put_dev_sector(sect);
		return 0;		/* not a MacOS disk */
	}
	blocks_in_map = be32_to_cpu(part->map_count);
	if (blocks_in_map < 0 || blocks_in_map >= DISK_MAX_PARTS) {
                put_dev_sector(sect);
                return 0;
        }
        printk(" [mac]");
        for (slot = 1; slot <= blocks_in_map; ++slot) {
                int pos = slot * secsize;
		put_dev_sector(sect);
		data = read_dev_sector(bdev, pos/512, &sect);
		if (!data)
			return -1;
		part = (struct mac_partition *) (data + pos%512);
		if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC)
			break;
		put_partition(state, slot,
			be32_to_cpu(part->start_block) * (secsize/512),
			be32_to_cpu(part->block_count) * (secsize/512));

		if (!strnicmp(part->type, "Linux_RAID", 10))
			state->parts[slot].flags = 1;
#ifdef CONFIG_PPC_PMAC
		/*
		 * If this is the first bootable partition, tell the
		 * setup code, in case it wants to make this the root.
		 */
		if (machine_is(powermac)) {
			int goodness = 0;

			mac_fix_string(part->processor, 16);
			mac_fix_string(part->name, 32);
			mac_fix_string(part->type, 32);					
		    
			if ((be32_to_cpu(part->status) & MAC_STATUS_BOOTABLE)
			    && strcasecmp(part->processor, "powerpc") == 0)
				goodness++;

			if (strcasecmp(part->type, "Apple_UNIX_SVR2") == 0
			    || (strnicmp(part->type, "Linux", 5) == 0
			        && strcasecmp(part->type, "Linux_swap") != 0)) {
				int i, l;

				goodness++;
				l = strlen(part->name);
				if (strcmp(part->name, "/") == 0)
					goodness++;
				for (i = 0; i <= l - 4; ++i) {
					if (strnicmp(part->name + i, "root",
						     4) == 0) {
						goodness += 2;
						break;
					}
				}
				if (strnicmp(part->name, "swap", 4) == 0)
					goodness--;
			}

			if (goodness > found_root_goodness) {
				found_root = slot;
				found_root_goodness = goodness;
			}
		}
#endif /* CONFIG_PPC_PMAC */
	}
#ifdef CONFIG_PPC_PMAC
	if (found_root_goodness)
		note_bootable_part(bdev->bd_dev, found_root, found_root_goodness);
#endif

	put_dev_sector(sect);
	printk("\n");
	return 1;
}
Exemplo n.º 5
0
int mac_partition(struct parsed_partitions *state)
{
	Sector sect;
	unsigned char *data;
	int slot, blocks_in_map;
	unsigned secsize;
#ifdef CONFIG_PPC_PMAC
	int found_root = 0;
	int found_root_goodness = 0;
#endif
#ifdef CONFIG_TIVO_DISKPARTITION
	int num_parts=-1; // count number of valid tivo partitions
#endif	
	struct mac_partition *part;
	struct mac_driver_desc *md;

	/* Get 0th block and look at the first partition map entry. */
	md = read_part_sector(state, 0, &sect);
	if (!md)
		return -1;
#ifdef CONFIG_TIVO_DISKPARTITION
	switch(md->signature) {
		case MAC_DRIVER_MAGIC:
			secsize = md->block_size;
			put_dev_sector(sect);
			data = read_part_sector(state, secsize/512, &sect);
			if (!data) 
				return -1;
			part = (struct mac_partition *)(data + secsize % 512);
			break;
		case TIVO_BOOT_MAGIC:
			secsize = 512;
			data = read_part_sector(state, 1, &sect);
			if (!data) 
				return -1;
			part = (struct mac_partition *)data;
			break;
		default:
			put_dev_sector(sect);
			printk("block 0 has signature %x rather than %x or %x\n",
				md->signature, MAC_DRIVER_MAGIC,
				TIVO_BOOT_MAGIC);
			return 0;
	}
    if (part->signature != MAC_PARTITION_MAGIC) {
        put_dev_sector(sect);
        return 0;       /* not a MacOS disk */
    }
    blocks_in_map = part->map_count;
#else
	if (be16_to_cpu(md->signature) != MAC_DRIVER_MAGIC) {
		put_dev_sector(sect);
		return 0;
	}
	secsize = be16_to_cpu(md->block_size);
	put_dev_sector(sect);
	data = read_part_sector(state, secsize/512, &sect);
	if (!data)
		return -1;
	part = (struct mac_partition *) (data + secsize%512);
	if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC) {
		put_dev_sector(sect);
		return 0;		/* not a MacOS disk */
	}
	blocks_in_map = be32_to_cpu(part->map_count);
#endif

	if (blocks_in_map < 0 || blocks_in_map >= DISK_MAX_PARTS) {
		put_dev_sector(sect);
		return 0;
	}
#ifdef CONFIG_TIVO_DISKPARTITION
	if (md->signature == TIVO_BOOT_MAGIC)
	{
		strlcat(state->pp_buf," [tivo]", PAGE_SIZE);
		num_parts=0;  
	}
	else
#endif
	strlcat(state->pp_buf, " [mac]", PAGE_SIZE);
	for (slot = 1; slot <= blocks_in_map; ++slot) {
		int pos = slot * secsize;
		put_dev_sector(sect);
		data = read_part_sector(state, pos/512, &sect);
		if (!data)
			return -1;
		part = (struct mac_partition *) (data + pos%512);
#ifdef CONFIG_TIVO_DISKPARTITION        
		if (part->signature == TIVO_BIGPARTITION_MAGIC) {
			struct tivo_bigpartition *bigpart = (void *) part;
			put_partition(state, slot,
				bigpart->start_block * (secsize/512),
				bigpart->block_count * (secsize/512));
			/* Show that we found the big-partition code */
			strlcat(state->pp_buf,"!",PAGE_SIZE);
			/* Check for media partition */
			if (bigpart->status & 0x100) {
				state->parts[slot].driver_flags = 1;
				strlcat(state->pp_buf,"[M]",PAGE_SIZE);
			}
		} else
		{
			if (part->signature != MAC_PARTITION_MAGIC)
				break;
			put_partition(state, slot,
				part->start_block * (secsize/512),
				part->block_count * (secsize/512));

			/* Check for media partition */
			if (part->status & 0x100) {
				state->parts[slot].driver_flags = 1;
				strlcat(state->pp_buf,"[M]",PAGE_SIZE);
			}
		}	
		if (num_parts >= 0) num_parts++;

#else
		if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC)
			break;
		put_partition(state, slot,
			be32_to_cpu(part->start_block) * (secsize/512),
			be32_to_cpu(part->block_count) * (secsize/512));

		if (!strnicmp(part->type, "Linux_RAID", 10))
			state->parts[slot].flags = ADDPART_FLAG_RAID;
#endif

#ifdef CONFIG_PPC_PMAC
		/*
		 * If this is the first bootable partition, tell the
		 * setup code, in case it wants to make this the root.
		 */
		if (machine_is(powermac)) {
			int goodness = 0;

			mac_fix_string(part->processor, 16);
			mac_fix_string(part->name, 32);
			mac_fix_string(part->type, 32);					
		    
			if ((be32_to_cpu(part->status) & MAC_STATUS_BOOTABLE)
			    && strcasecmp(part->processor, "powerpc") == 0)
				goodness++;

			if (strcasecmp(part->type, "Apple_UNIX_SVR2") == 0
			    || (strnicmp(part->type, "Linux", 5) == 0
			        && strcasecmp(part->type, "Linux_swap") != 0)) {
				int i, l;

				goodness++;
				l = strlen(part->name);
				if (strcmp(part->name, "/") == 0)
					goodness++;
				for (i = 0; i <= l - 4; ++i) {
					if (strnicmp(part->name + i, "root",
						     4) == 0) {
						goodness += 2;
						break;
					}
				}
				if (strnicmp(part->name, "swap", 4) == 0)
					goodness--;
			}

			if (goodness > found_root_goodness) {
				found_root = slot;
				found_root_goodness = goodness;
			}
		}
#endif /* CONFIG_PPC_PMAC */
	}
#ifdef CONFIG_PPC_PMAC
	if (found_root_goodness)
		note_bootable_part(state->bdev->bd_dev, found_root,
				   found_root_goodness);
#endif

	put_dev_sector(sect);
#ifdef CONFIG_TIVO_DISKPARTITION	
	if (num_parts == 14)
	{
		// We found a TiVo signature plus exactly 14 partitions
		strlcat(state->pp_buf, " :)", PAGE_SIZE);
		state->bdev->bd_disk->tivo=1; // tell sysfs 
	}
#endif		
	strlcat(state->pp_buf, "\n", PAGE_SIZE);
	return 1;
}