Volume* volume_for_device(const char* device)
{
    int i;
    struct dInfo* loc = findDeviceByBlockDevice(device);

    for (i = 0; i < num_volumes; ++i)
    {
        Volume* v = &device_volumes[i];
        if (v->device && strcmp(device, v->device) == 0)
            return v;
        if (v->device && loc && strcmp(loc->mnt, v->device) == 0)
            return v;
    }
    return NULL;
}
예제 #2
0
// This routine handles the case where we can't open either /proc/mtd or /proc/emmc
int setLocationData(const char* label, const char* blockDevice, const char* mtdDevice, const char* fstype, unsigned long long size)
{
    struct dInfo* loc = NULL;

    if (label)                  loc = findDeviceByLabel(label);
			
    if (!loc && blockDevice)    loc = findDeviceByBlockDevice(blockDevice);

    if (!loc)
        return -1;

    if (blockDevice)            strcpy(loc->blk, blockDevice);
	if (label)                  strcpy(loc->mnt, label);
    if (mtdDevice){
		strcpy(loc->dev, mtdDevice);
		loc->memory_type = mtd;
		if (strcmp(loc->mnt, "data") == 0)
			strcpy(loc->format_location, "userdata");
		else
			strcpy(loc->format_location, loc->mnt);
	} else {
		loc->memory_type = emmc;
		strcpy(loc->format_location, loc->blk);
	}

    // This is a simple 
    if (strcmp(loc->mnt, "boot") == 0 && fstype)
    {
        loc->mountable = 0;
        if (strcmp(fstype, "vfat") == 0 || memcmp(fstype, "ext", 3) == 0 || strcmp(fstype, "auto") == 0)
            loc->mountable = 1;
    }

    if (fstype)                 strcpy(loc->fst, fstype);
    if (size && loc->sze == 0)  loc->sze = size;

    return 0;
}
예제 #3
0
void verifyFst()
{
	FILE *fp;
	char blkOutput[255];
	char* blk;
    char* arg;
    char* ptr;
    struct dInfo* dat;

    // This has a tendency to hang on MTD devices.
    if (isMTDdevice)    return;

	LOGI("=> Let's update filesystem types via verifyFst aka blkid.\n");
	fp = __popen("blkid","r");
	while (fgets(blkOutput, sizeof(blkOutput), fp) != NULL)
    {
        blk = blkOutput;
        ptr = blkOutput;
        while (*ptr > 32 && *ptr != ':')        ptr++;
        if (*ptr == 0)                          continue;
        *ptr = 0;

        // Increment by two, but verify that we don't hit a NULL
        ptr++;
        if (*ptr != 0)      ptr++;

        // Now, find the TYPE field
        while (1)
        {
            arg = ptr;
            while (*ptr > 32)       ptr++;
            if (*ptr != 0)
            {
                *ptr = 0;
                ptr++;
            }

            if (strlen(arg) > 6)
            {
				if (memcmp(arg, "TYPE=\"", 6) == 0)  break;
            }

            if (*ptr == 0)
            {
                arg = NULL;
                break;
            }
        }

		if (arg && strlen(arg) > 7)
        {
            arg += 6;   // Skip the TYPE=" portion
            arg[strlen(arg)-1] = '\0';  // Drop the tail quote
        }
        else
            continue;

		dat = findDeviceByBlockDevice(blk);
        if (dat && strcmp(dat->fst, arg) != 0) {
			LOGI("'%s' was '%s' now set to '%s'\n", dat->mnt, dat->fst, arg);
			strcpy(dat->fst,arg);
		}
	}
	__pclose(fp);
}