static int simple_mmc_get_disk_info(struct mbr_part_info *mpi, unsigned char *name)
{
    int i = 0;
    char* no_partition_name = "n/a";
    struct disk_part_iter piter;
    struct hd_struct *part;
    struct msdc_host *host;
    struct gendisk *disk;
    struct __mmc_blk_data *md;

    if(!name || !mpi)
        return -EINVAL;

    /* emmc always in slot0 */
    host = msdc_get_host(MSDC_EMMC,MSDC_BOOT_EN,0);
    BUG_ON(!host);
    BUG_ON(!host->mmc);
    BUG_ON(!host->mmc->card);

    md = mmc_get_drvdata(host->mmc->card);
    BUG_ON(!md);
    BUG_ON(!md->disk);

    disk = md->disk;

    /* use this way to find partition info is to avoid handle addr transfer in scatter file
     * and 64bit address calculate */
    disk_part_iter_init(&piter, disk, 0);
    while ((part = disk_part_iter_next(&piter))){
        for (i = 0; i < PART_NUM; i++) {
			if ((PartInfo[i].partition_idx != 0)
				&& (PartInfo[i].partition_idx == part->partno)) {
#if DEBUG_MMC_IOCTL
				pr_debug("part_name = %s    name = %s\n", PartInfo[i].name, name);
#endif
				if (!strncmp(PartInfo[i].name, name, PARTITION_NAME_LENGTH)) {
					mpi->start_sector = part->start_sect;
					mpi->nr_sects = part->nr_sects;
					mpi->part_no = part->partno;
					if (i < PART_NUM) {
						mpi->part_name = PartInfo[i].name;
					} else {
						mpi->part_name = no_partition_name;
					}

					disk_part_iter_exit(&piter);
					return 0;
				}

				break;
			}
		}
	}
	disk_part_iter_exit(&piter);

	return 1;
}
int mt65xx_mmc_change_disk_info(unsigned int px, unsigned int addr, unsigned int size)
{
#ifdef MTK_EMMC_SUPPORT

    struct disk_part_iter piter;
	struct hd_struct *part;
	struct msdc_host *host;
	struct gendisk *disk;
    struct __mmc_blk_data *md;
    int i;
    /* emmc always in slot0 */
	host = msdc_get_host(MSDC_EMMC,MSDC_BOOT_EN,0);
	BUG_ON(!host);
	BUG_ON(!host->mmc);
	BUG_ON(!host->mmc->card);

	md = mmc_get_drvdata(host->mmc->card);
	BUG_ON(!md);
	BUG_ON(!md->disk);
	disk = md->disk;
    disk_part_iter_init(&piter, disk, 0);

	for(i=0;i<PART_NUM;i++){
		if((PartInfo[i].partition_idx == px)&&((!strncmp(PartInfo[i].name,"usrdata",7))||(!strncmp(PartInfo[i].name,"sec_ro",6))||(!strncmp(PartInfo[i].name,"android",7))||(!strncmp(PartInfo[i].name,"cache",5)))){
			printk("update %s,need reduce 1MB in block device\n",PartInfo[i].name);
			size -= (0x100000)/512;
		}
	}
    while ((part = disk_part_iter_next(&piter))){
      
            if (px != 0 && px == part->partno) {
//#if DEBUG_MMC_IOCTL
                printk("[mt65xx_mmc_change_disk_info]px = %d size %llx -> %x offset %llx -> %x\n",px,part->nr_sects,size,part->start_sect,addr);
//#endif                
               
                    part->start_sect = addr;           
                    part->nr_sects = size;           

                    disk_part_iter_exit(&piter);
                    return 0;
                

             
            }
        
    }
    disk_part_iter_exit(&piter);

    return 1;
#else
    return 0;
#endif
}
Example #3
0
static int __update_disk_info(unsigned int px, unsigned int start, unsigned int size)
{
    int found;
    struct disk_part_iter piter;
	struct hd_struct *part;
	struct gendisk *disk;
	struct storage_info s_info = {0};

	BUG_ON(!msdc_get_info(EMMC_CARD_BOOT, DISK_INFO, &s_info));
	disk = s_info.disk;

    found = 0;

    disk_part_iter_init(&piter, disk, 0);

    while ((part = disk_part_iter_next(&piter))) {
        if (px != 0 && px == part->partno) {
            found = 1;
            pmt_info("[update_disk_info]px = %d size %llx -> %x offset %llx -> %x\n",
                    px, part->nr_sects, size, part->start_sect, start);
            part->start_sect = start;
            part->nr_sects = size;
            break;
        }
    }

    disk_part_iter_exit(&piter);

    return !found;
}
struct hd_struct *get_part(char *name)
{
    dev_t devt;
    int partno;
    struct disk_part_iter piter;
    struct gendisk *disk;
    struct hd_struct *part = NULL; 
    
    if (!name)
        return part;

    devt = blk_lookup_devt("mmcblk0", 0);
    disk = get_gendisk(devt, &partno);

    if (!disk || get_capacity(disk) == 0)
        return 0;

	disk_part_iter_init(&piter, disk, 0);
	while ((part = disk_part_iter_next(&piter))) {
        if (part->info && !strcmp(part->info->volname, name)) {
            get_device(part_to_dev(part));
            break;
        }
	}
	disk_part_iter_exit(&piter);
    
    return part;
}
static int partinfo_show_proc(struct seq_file *m, void *v)
{
    dev_t devt;
    int partno;
    struct disk_part_iter piter;
    struct gendisk *disk;
    struct hd_struct *part; 
    u64 last = 0;

    devt = blk_lookup_devt("mmcblk0", 0);
    disk = get_gendisk(devt, &partno), 

    seq_printf(m, "%-16s %-16s\t%-16s\n", "Name", "Start", "Size");

    if (!disk || get_capacity(disk) == 0)
        return 0;

	disk_part_iter_init(&piter, disk, 0);
    seq_printf(m, "%-16s 0x%016llx\t0x%016llx\n", "pgpt", 0ULL, 512 * 1024ULL);

    while ((part = disk_part_iter_next(&piter))) {
        seq_printf(m, "%-16s 0x%016llx\t0x%016llx\n", 
            part->info ? (char *)(part->info->volname) : "unknown",
            (u64)part->start_sect * 512,
            (u64)part->nr_sects * 512);
        last = (part->start_sect + part->nr_sects) * 512;
	}

    seq_printf(m, "%-16s 0x%016llx\t0x%016llx\n", "sgpt", last, 512 * 1024ULL);
	disk_part_iter_exit(&piter);

	return 0;
}
Example #6
0
static int simple_mmc_get_disk_info(struct mbr_part_info* mpi, unsigned char* name)
{
    char* no_partition_name = "n/a";
    struct disk_part_iter piter;
    struct hd_struct *part;
    struct msdc_host *host;
    struct gendisk *disk;
    struct __mmc_blk_data *md;
    
    /* emmc always in slot0 */
    host = msdc_get_host(MSDC_EMMC,MSDC_BOOT_EN,0);
    BUG_ON(!host);
    BUG_ON(!host->mmc);
    BUG_ON(!host->mmc->card);

    md = mmc_get_drvdata(host->mmc->card);
    BUG_ON(!md);
    BUG_ON(!md->disk);

    disk = md->disk;
    
    /* use this way to find partition info is to avoid handle addr transfer in scatter file 
     * and 64bit address calculate */
    disk_part_iter_init(&piter, disk, 0);
    while ((part = disk_part_iter_next(&piter))){
#if DEBUG_MMC_IOCTL
        printk("part_name = %s    name = %s\n", part->info->volname, name);
#endif                
        if (!strncmp(part->info->volname, name, PARTITION_NAME_LENGTH)){
            mpi->start_sector = part->start_sect;           
            mpi->nr_sects = part->nr_sects;           
            mpi->part_no = part->partno; 
            if (part->info){
                mpi->part_name = part->info->volname;
            } else {
                mpi->part_name = no_partition_name;
            }

            disk_part_iter_exit(&piter);
            return 0;
        }
    }
    disk_part_iter_exit(&piter);

    return 1;
}
static int get_partition_package(struct gendisk *disk, struct partition_package *package)
{
    struct part_t *pinfo;
    struct disk_part_iter piter;
    struct hd_struct *part; 

    pinfo = (void*)package + sizeof(*package);

	disk_part_iter_init(&piter, disk, 0);
	while ((part = disk_part_iter_next(&piter))) {
        pinfo->start = (unsigned long)part->start_sect * 512;
        pinfo->size = (unsigned long)part->nr_sects * 512;
        pinfo->part_id = EMMC_PART_USER;
        if (part->info) {
            memcpy(pinfo->name, part->info->volname, 64);
        }
        part_info("%-16s: 0x%016llx, 0x%016llx\n", pinfo->name, pinfo->start, pinfo->size);
        pinfo++;
	}

	disk_part_iter_exit(&piter);

    return 0;
}
Example #8
0
void show_gend(void)
{
	struct class_dev_iter iter;
	struct device *dev;

	class_dev_iter_init(&iter, my_block_class, NULL, my_disk_type);

	// struct class_dev_iter {
	//   [0] struct klist_iter ki;
	//  [16] const struct device_type *type;
	//}

	//printk("iter %p iter.ki %p i_klist %p i_cur %p\n",
	//	&iter, iter.ki, iter.ki.i_klist, iter.ki.i_cur);

	while ((dev = my_class_dev_iter_next(&iter))) {
		struct gendisk *disk = dev_to_disk(dev);
		struct disk_part_iter piter;
		struct hd_struct *part;
		char name_buf[BDEVNAME_SIZE];
		char devt_buf[BDEVT_SIZE];
		char uuid_buf[PARTITION_META_INFO_UUIDLTH * 2 + 5];

		// printk("gen %p name %s\n", disk, disk->disk_name);

		/*
		 * Don't show empty devices or things that have been
		 * suppressed
		 */
		if (get_capacity(disk) == 0 ||
		    (disk->flags & GENHD_FL_SUPPRESS_PARTITION_INFO))
			continue;

		// James: we only want to verify 'sda'
		if (strcmp(disk->disk_name, "sda") != 0)
			continue;

		/*
		 * Note, unlike /proc/partitions, I am showing the
		 * numbers in hex - the same format as the root=
		 * option takes.
		 */
		disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);

		printk("gen %p name %s\n disk_part_tbl %p ",
			disk, disk->disk_name, disk->part_tbl);

		while ((part = disk_part_iter_next(&piter))) {
			bool is_part0 = part == &disk->part0;

			printk("part %p\n", part);

			uuid_buf[0] = '\0';
			if (part->info)
				snprintf(uuid_buf, sizeof(uuid_buf), "%pU",
					 part->info->uuid);

			printk("%s%s %10llu %s %s", is_part0 ? "" : "  ",
			       bdevt_str(part_devt(part), devt_buf),
			       (unsigned long long)part->nr_sects >> 1,
			       disk_name(disk, part->partno, name_buf),
			       uuid_buf);
			if (is_part0) {
				if (disk->driverfs_dev != NULL &&
				    disk->driverfs_dev->driver != NULL)
					printk(" driver: %s\n",
					      disk->driverfs_dev->driver->name);
				else
					printk(" (driver?)\n");
			} else
				printk("\n");
		}
		disk_part_iter_exit(&piter);
	}
	class_dev_iter_exit(&iter);
}