Example #1
0
static int ioctl2AddSub(hdd_file_slot_t *fileSlot, char *argp)
{
	int			rv;
	u32 		device=fileSlot->f->unit;
	apa_params_t	params;
	u32			emptyBlocks[32];
	apa_cache_t	*clink;
	u32			sector=0;
	u32			length;

	if(!(fileSlot->f->mode & O_WRONLY))
		return -EACCES;

	if(!(fileSlot->nsub < APA_MAXSUB))
		return -EFBIG;

	memset(&params, 0, sizeof(apa_params_t));

	if((rv=fioPartitionSizeLookUp(argp)) < 0)
		return rv;

	params.size=rv;
	params.flags=APA_FLAG_SUB;
	params.type=fileSlot->type;
	params.main=fileSlot->parts[0].start;
	params.number=fileSlot->nsub+1;
	if((rv=hddCheckPartitionMax(device, params.size)) < 0)
		return rv;

	// walk all looking for any empty blocks
	memset(&emptyBlocks, 0, sizeof(emptyBlocks));
	clink=apaCacheGetHeader(device, 0, APA_IO_MODE_READ, &rv);
	while(clink){
		sector=clink->sector;
		apaAddEmptyBlock(clink->header, emptyBlocks);
		clink=apaGetNextHeader(clink, &rv);
	}
	if(rv!=0)
		return rv;

	if(!(clink=hddAddPartitionHere(device, &params, emptyBlocks, sector, &rv)))
		return rv;

	sector=clink->header->start;
	length=clink->header->length;
	apaCacheFree(clink);
	if(!(clink=apaCacheGetHeader(device, fileSlot->parts[0].start, APA_IO_MODE_READ, &rv)))
		return rv;

	clink->header->subs[clink->header->nsub].start=sector;
	clink->header->subs[clink->header->nsub].length=length;
	clink->header->nsub++;
	fileSlot->nsub++;
	fileSlot->parts[fileSlot->nsub].start=sector;
	fileSlot->parts[fileSlot->nsub].length=length;
	clink->flags|=APA_CACHE_FLAG_DIRTY;
	apaCacheFlushAllDirty(device);
	apaCacheFree(clink);
	return rv;
}
Example #2
0
// NOTE: Changed so format = partitionID,size (used to be partitionID,fpswd,rpswd,size,filesystem)
int fioGetInput(const char *arg, input_param *params)
{
	char	szBuf[32];
	int		rv=0;

	if(params==NULL)
		return -EINVAL;
	memset(params, 0, sizeof(input_param));

	while(arg[0]==' ') arg++;

	if(arg[0]==0 || arg[0]==',')
		return -EINVAL;
	if((rv=fioInputBreaker(&arg, params->id, APA_IDMAX))!=0)
		return rv;
	if((params->id[0]==0) || (arg[0]==0))
		return 0;

	memset(szBuf, 0, sizeof(szBuf));
	if((rv=fioInputBreaker(&arg, szBuf, sizeof(szBuf)))!=0)
		return rv;

	if((rv=fioPartitionSizeLookUp(szBuf))<0)
		return rv;
	params->size=rv;

	// Filesystem type is fixed to PFS!
	params->type = APA_TYPE_PFS;
	return rv;
}
Example #3
0
static int fioGetInput(const char *arg, apa_params_t *params)
{
	char	argBuf[32];
	int		rv=0, i;
	static const struct apaFsType fsTypes[]={
		{"PFS", APA_TYPE_PFS},
		{"CFS", APA_TYPE_CFS},
		{"EXT2", APA_TYPE_EXT2},
		{"EXT2SWAP", APA_TYPE_EXT2SWAP}
	};

	if(params==NULL)
		return -EINVAL;
	memset(params, 0, sizeof(apa_params_t));

	while(arg[0]==' ') arg++;

	if(arg[0]==0 || arg[0]==',')
		return -EINVAL;
	if((rv=fioInputBreaker(&arg, params->id, APA_IDMAX))!=0)
		return rv;
	if(arg[0] == '\0')	// Return if there are no further parameters.
		return 0;

	if((rv=fioInputBreaker(&arg, params->fpwd, APA_PASSMAX))!=0)
		return rv;

	if(params->fpwd[0] != '\0')
		apaEncryptPassword(params->id, params->fpwd, params->fpwd);

	if(arg[0] == '\0')	// Return if there are no further parameters.
		return 0;

	if((rv=fioInputBreaker(&arg, params->rpwd, APA_PASSMAX))!=0)
		return rv;

	if(params->rpwd[0] != '\0')
		apaEncryptPassword(params->id, params->rpwd, params->rpwd);

	if(arg[0] == '\0')	// Return if there are no further parameters.
		return 0;

	memset(argBuf, 0, sizeof(argBuf));
	if((rv=fioInputBreaker(&arg, argBuf, sizeof(argBuf)))!=0)
		return rv;

	if((rv=fioPartitionSizeLookUp(argBuf))<0)
		return rv;
	params->size=rv;

	memset(argBuf, 0, sizeof(argBuf));
	if((rv=fioInputBreaker(&arg, argBuf, sizeof(argBuf)))!=0)
		return rv;

	for(i = 0; i < 4; i++)
	{
		if(!strcmp(argBuf, fsTypes[i].desc))
		{
			params->type = fsTypes[i].type;
			break;
		}
	}

	if(i == 4)
	{
		printf("hdd: error: Invalid fstype, %s.\n", argBuf);
		return -EINVAL;
	}

	return rv;
}