format HDD 格式化硬盘 块设备 code

int format_device(int *guid,device_info_t *pinfo)
{
return change_state_device(guid,pinfo,1);
}


 int change_state_device(int *guid,device_info_t *pinfo,int bformat)

{

int i;
int count;
int found_device=0;
int total_size=0;
int fd_device=0;
disk_partition *pdisk_partition;
int pre_cylnder=0;
struct hd_big_geometry hdd_geometry;
#ifdef GPT_SUPPORT
unsigned long long bytesize=0;
unsigned short sel_over_tera=0;
#endif
unsigned long sector_number=0;


int unit_one = 1;
int full_bit=0;
int display_factor =1;
float ratio_cylnder=0.0;
long start_cyl,stop_cyl;
int internal_use=0;
int system_timeout=0;


int sepcl;
char s_data[1024] = {0,};


if(s_init == 0)
{
DEVICE_ERR_MSG("not init\n");
return DEVICE_INFO_ERROR;
}


if(guid == NULL)
{
DEVICE_ERR_MSG("guid is NULL\n");
return DEVICE_INFO_ERROR;
}


if(pinfo == NULL)
{
DEVICE_ERR_MSG("pinfo is NULL\n");
return DEVICE_INFO_ERROR;
}


if(pinfo->partition_number > DEVICE_MAX_PARTITION ||  pinfo->partition_number <=0)
{
DEVICE_ERR("partion number(%d) is wrong it must range of [1..4]\n",pinfo->partition_number);
return DEVICE_INFO_ERROR;
}


for(i=0;i<s_device_count;i++)
{
if(memcmp(guid,s_device_info[i].guid,sizeof(int)*3) == 0)
{
count = i;
DEVICE_INFO("found device %s\n",s_device_info[count].device_name);
found_device = 1;
break;
}
}


if(found_device == 0)
{
DEVICE_ERR("not found device [0:%x][1:%x][2:%x]\n",guid[0],guid[1],guid[2]);
return DEVICE_INFO_ERROR;
}


// check label size
for(i=0;i<pinfo->partition_number;i++)
{


switch(pinfo->file_system[i])
{
case DEVICE_EXT2:
case DEVICE_EXT3:
case DEVICE_KLOTHO:
if(strlen(pinfo->label_name[i]) > VOLUME_LABLE_LEN)
{
DEVICE_ERR("label_name(%s) is big than %d ext\n",pinfo->label_name[i],VOLUME_LABLE_LEN);
//return DEVICE_INFO_ERROR;
}
break;


case DEVICE_FAT16:
case DEVICE_FAT32:
if(strlen(pinfo->label_name[i]) > 11)
{
DEVICE_ERR("label_name(%s) is big than %d fat\n",pinfo->label_name[i],11);
//return DEVICE_INFO_ERROR;
}
break;


case DEVICE_XFS:
if(strlen(pinfo->label_name[i]) > 12)
{
DEVICE_ERR("label_name(%s) is big than %d fat\n",pinfo->label_name[i],12);
//return DEVICE_INFO_ERROR;
}
break;


#ifdef SUPPORT_REISERFS
case DEVICE_REISERFS :
if(strlen(pinfo->label_name[i]) > 16) 
{
DEVICE_ERR("label_name(%s) is big than %d Reiserfs\n",pinfo->label_name[i],16);
}
break;
#endif


default:
found_device = -1;
break;
}


if(found_device != 1)
{
DEVICE_ERR("filesystem[0x%x] is not support \n",pinfo->file_system[i]);
return DEVICE_INFO_ERROR;
}


if(pinfo->total_size_in_mega[i] <=0 || pinfo->total_size_in_mega[i] >s_device_info[count].total_size_in_mega[s_device_info[count].partition_number])
{
if(pinfo->total_size_in_mega[i] == -1 && pinfo->partition_number-1 == i)
{
}
else
{
DEVICE_ERR("patitioan size(%d MB) is less than 0 or big than %d MB(Total Size)\n",pinfo->total_size_in_mega[i],pinfo->total_size_in_mega[pinfo->partition_number]);
return DEVICE_INFO_ERROR;
}
}


total_size=total_size + pinfo->total_size_in_mega[i];
}


/*
if(total_size != s_device_info[count].total_size_in_mega[s_device_info[count].partition_number])
{
DEVICE_INFO("sum of partition size(%d MB) is not equal total size(%d MB)\n",total_size,s_device_info[count].total_size_in_mega[s_device_info[count].partition_number]);
}
*/




memcpy(pinfo->device_name,s_device_info[count].device_name,DEVICE_CHAR_MAX);


if(s_device_info[count].flag !=0)
internal_use = 1;
else
internal_use = 0;
pinfo->flag = s_device_info[count].flag;


if(bformat != 0)
{
memset(s_data,0,1024);
#if 0 // qangel (2008.10.29): change system() to stdlib api
if(internal_use != 0)
snprintf(s_data, sizeof(s_data), "umount %s",pinfo->device_name);
else
snprintf(s_data, sizeof(s_data), "umount %s?",pinfo->device_name);
SYSTEM_T(s_data,30);
#else // 0
// umount(pinfo->device_name);
#endif // 0
// mount ?
// delete all  partition
fd_device=open(pinfo->device_name,O_RDWR);
if(fd_device == -1)
{
DEVICE_ERR("open error(0x%x)\n",errno);
perror("device_info");
return DEVICE_INFO_ERROR;
}


// get geometry
#ifdef GPT_SUPPORT
if(ioctl(fd_device, BLKGETSIZE64, &bytesize) == -1)
{
DEVICE_ERR("ioctl BLKETSIZE error(0x%x)\n",errno);
perror("device_info");
close(fd_device);
return DEVICE_INFO_ERROR;
}
//songholee_110712 
// 1) backup(fat32)侩篮 力寇窃 (蝶扼辑 扁粮(MBR)措肺 荤侩窃) 
// 2) extended, internal荤侩矫俊父 利侩窃 
// 3) 2)狼 炼扒俊辑 1TB檬苞矫 gpt利侩苞 parttition megabyte(2048s)肺 利侩, 1TB捞窍绰 扁粮单肺 荤侩窃  
// 4) 3)狼 炼扒矫俊 4KB Align利侩栏肺 牢秦 mk.xfs format 利侩矫 扁粮 512byte俊辑 4096byte肺 荐沥窃 
// 5) 氢饶, 扁粮(MBR)备炼俊辑 parted 函版 沥氓栏肺 肯傈洒 官曹 抗沥 (~ 2011斥 11岿, 捞码 3TB 矫厘俊 傍蜡瞪 俊沥 ) 
 
(bytesize > ((unsigned long long) ONE_TERA_THRESHOLD ))?(sel_over_tera=1):(sel_over_tera=0);


if(sel_over_tera)
{
DEVICE_INFO("Disk Size is over %d TB. \n", _TERA_1UNIT);


if(pinfo->partition_number == MAX_REC_HDD_PARTITION) // 2010.08.23 Ra,Jean - 2TB甫 逞绰 版快 踌拳侩栏肺 荤侩窍档废 力救窃.
{
if(make_gpt_partition(pinfo))
{
umount(pinfo->device_name);
goto format;
}
else 
{
close(fd_device);
return DEVICE_INFO_ERROR;
}
}
else 
{
//songholee_110712 this is backup(fat) loutine ...! fat is until 2TB;
if((bytesize > ((unsigned long long) 2*_TERA_1UNIT*_MEGA_BYTE*_MEGA_BYTE )))
{
close(fd_device);
return DEVICE_INFO_ERROR;
}


umount(pinfo->device_name);


if(CheckGPTInfo(pinfo)==1) // GPT 颇萍记捞 乐栏搁 昏力
{
int i=0;
char cmd[128]={'\0',};
//sample -> parted -s /dev/sda rm 1
for(i=0; i<MAX_REC_HDD_PARTITION; i++)
{
snprintf(cmd, sizeof(cmd), "parted -s %s rm %d",pinfo->device_name, i+1);
if(SYSTEM_T(cmd,60*60) != 0)
{
DEVICE_ERR_MSG("parted error ( remove_partition ).\n");
}
}


snprintf(cmd, sizeof(cmd), "parted -s %s mklabel msdos",pinfo->device_name);


if(SYSTEM_T(cmd,system_timeout) != 0)
{
DEVICE_ERR_MSG("parted error ( make partition infomation ).\n");
}
sync();
sleep(2);
}




}
}
else
{
umount(pinfo->device_name);
}
#endif
if(ioctl(fd_device, BLKGETSIZE, &sector_number) == -1)
{
DEVICE_ERR("ioctl BLKETSIZE error(0x%x)\n",errno);
perror("device_info");
close(fd_device);
return DEVICE_INFO_ERROR;
}


if(ioctl(fd_device,HDIO_GETGEO_BIG,&hdd_geometry) == -1)
{
// kernerl 2.6 not support HDIO_GETGEO_BIG


{
struct hd_geometry hd_geo;
if(ioctl(fd_device,HDIO_GETGEO,&hd_geo) == -1)
{


DEVICE_ERR("ioctl HDIO_GET_GERO error(0x%x)\n",errno);
perror("device_info");
close(fd_device);
return DEVICE_INFO_ERROR;
}
else
{


hdd_geometry.heads = hd_geo.heads;
hdd_geometry.sectors = hd_geo.sectors;
hdd_geometry.cylinders = sector_number / (hdd_geometry.heads * hdd_geometry.sectors);
}
}
}


memset(s_data,0,1024);
// read MBR
lseek(fd_device,0,SEEK_SET);
if(read(fd_device,s_data,sizeof(master_boot_record)) == -1)
{
DEVICE_ERR("read error(0x%x)\n",errno);
perror("device_info");
close(fd_device);
return DEVICE_INFO_ERROR;
}


DEVICE_INFO("sector_number %lud\n",sector_number);
DEVICE_INFO("head %d\nsector %d\ncylunder %d start%ld\n",hdd_geometry.heads,hdd_geometry.sectors,hdd_geometry.cylinders,hdd_geometry.start);
// FIXME XXX sector size is 512 byte !!


full_bit = 1024 * hdd_geometry.sectors * hdd_geometry.heads;
if( unit_one && full_bit)
display_factor = full_bit>>10;
else
display_factor = 1;




for(i=0;i<DEVICE_MAX_PARTITION;i++)
{
pdisk_partition = (disk_partition *) &s_data[446+i*sizeof(disk_partition)];
// FIXME endian
pdisk_partition->relsect = __le32_to_cpu(pdisk_partition->relsect);
pdisk_partition->numsect = __le32_to_cpu(pdisk_partition->numsect);


/*
DEVICE_INFO("bootid 0x%x\n",pdisk_partition->bootid);
DEVICE_INFO("beghead %d\n",pdisk_partition->beghead);
DEVICE_INFO("begsect %d\n",pdisk_partition->begsect);
DEVICE_INFO("begcyl %d\n",pdisk_partition->begcyl);
DEVICE_INFO("systid 0x%x\n",pdisk_partition->systid);
DEVICE_INFO("endhead %d\n",pdisk_partition->endhead);
DEVICE_INFO("endsect %d\n",pdisk_partition->endsect);
DEVICE_INFO("endcyl %d\n",pdisk_partition->endcyl);
// relsect endian
DEVICE_INFO("relsect %d\n",pdisk_partition->relsect);
DEVICE_INFO("numsect %d\n",pdisk_partition->numsect);
DEVICE_INFO("display %d\n",display_factor);
*/
memset(pdisk_partition,0,sizeof(disk_partition));
}


for(i=0;i<pinfo->partition_number;i++)
{
pdisk_partition = (disk_partition *) &s_data[446+i*sizeof(disk_partition)];
// FIXME endian
#ifdef CPU_IS_BIG_ENDIAN
pdisk_partition->relsect = __le32_to_cpu(pdisk_partition->relsect);
pdisk_partition->numsect = __le32_to_cpu(pdisk_partition->numsect);
#elif CPU_IS_LITTLE_ENDIAN
pdisk_partition->relsect = __be32_to_cpu(pdisk_partition->relsect);
pdisk_partition->numsect = __be32_to_cpu(pdisk_partition->numsect);
#endif 
/* neonomad 061213
DEVICE_INFO("bootid 0x%x\n",pdisk_partition->bootid);
DEVICE_INFO("beghead %d\n",pdisk_partition->beghead);
DEVICE_INFO("begsect %d\n",pdisk_partition->begsect);
DEVICE_INFO("begcyl %d\n",pdisk_partition->begcyl);
DEVICE_INFO("systid 0x%x\n",pdisk_partition->systid);
DEVICE_INFO("endhead %d\n",pdisk_partition->endhead);
DEVICE_INFO("endsect %d\n",pdisk_partition->endsect);
DEVICE_INFO("endcyl %d\n",pdisk_partition->endcyl);
DEVICE_INFO("relsect %d\n",pdisk_partition->relsect);
DEVICE_INFO("numsect %d\n",pdisk_partition->numsect);
DEVICE_INFO("display %d\n",display_factor);


memset(pdisk_partition,0,sizeof(disk_partition));
*/


pdisk_partition->bootid = 0; // Bootable no
if(i==0)
start_cyl = 1;
else
{
if(pre_cylnder <= 0)
DEVICE_ERR("pre_cylnder is %d\n",pre_cylnder);
start_cyl = pre_cylnder + 1;
}


if(sector_number>0)
{
ratio_cylnder = (float)pinfo->total_size_in_mega[i]*2048 /sector_number;
}
stop_cyl = start_cyl +  (int)(ratio_cylnder  * hdd_geometry.cylinders);
if(pinfo->total_size_in_mega[i] == -1)
{
DEVICE_INFO("%d parti!\n",i);
stop_cyl =  hdd_geometry.cylinders;
}


pre_cylnder = stop_cyl;




{
unsigned int start,stop;


start = (start_cyl -1 )* display_factor;
stop = stop_cyl*display_factor - 1;


if(stop > sector_number)
stop = (((sector_number) + display_factor * unit_one) / display_factor) ;


if(start == 0)
start = 1;


// why ? FIXME
if(i== 0 && (pinfo->file_system[i] == DEVICE_FAT32 || pinfo->file_system[i] == DEVICE_FAT32))
start = hdd_geometry.sectors ;


// FIXME endian
pdisk_partition->numsect = stop - start + 1;
// FIXME endian
pdisk_partition->relsect = start;


if(pinfo->file_system[i] == DEVICE_FAT32 || pinfo->file_system[i] == DEVICE_FAT32)
{
if(start / (hdd_geometry.sectors* hdd_geometry.heads) > 1023)
start = hdd_geometry.sectors* hdd_geometry.heads * 1024 -1 ;


if(stop / (hdd_geometry.sectors* hdd_geometry.heads) > 1023)
stop = hdd_geometry.sectors * hdd_geometry.heads * 1024 -1 ;
}


pdisk_partition->begsect = start % hdd_geometry.sectors + 1;
start /=  hdd_geometry.sectors;
pdisk_partition->beghead = start % hdd_geometry.heads;
start /= hdd_geometry.heads;
pdisk_partition->begcyl = start & 0xff;
pdisk_partition->begsect |= (start >> 2) & 0xc0;


pdisk_partition->endsect = stop % hdd_geometry.sectors + 1;
stop /=  hdd_geometry.sectors;
pdisk_partition->endhead = stop % hdd_geometry.heads;
stop /= hdd_geometry.heads;
pdisk_partition->endcyl = stop & 0xff;
pdisk_partition->endsect |= (stop >> 2) & 0xc0;
}


if(pinfo->file_system[i] == DEVICE_FAT16)
pdisk_partition->systid=0x06; // FAT16
else if(pinfo->file_system[i] == DEVICE_FAT32)
pdisk_partition->systid=0xC; // W95 FAT32(LBA)
else
pdisk_partition->systid=0x83; // Linux system


// write措厚窍咯 endian process
pdisk_partition->relsect = __cpu_to_le32(pdisk_partition->relsect);
pdisk_partition->numsect = __cpu_to_le32(pdisk_partition->numsect);


}


// set magic
s_data[510] = 0x55;
s_data[511] = 0xAA;


if(internal_use !=0 && pinfo->major != DEVICE_ATA)
{
DEVICE_INFO("this flash is no partition because china model or old backup%c",'\n');
}
else
{
lseek(fd_device,0,SEEK_SET);
// endian 绊妨秦具窃
// signature绰 byte opreration沁栏骨肺 扒呈盾
//
if(write(fd_device,s_data,sizeof(master_boot_record)) == -1)
{
DEVICE_ERR("write error(0x%x)\n",errno);
perror("device_info");
close(fd_device);
return DEVICE_INFO_ERROR;
}
}


#ifdef GPT_SUPPORT
format :
#endif
// sync system partition table re-read
#ifdef USED_HI3520 // Partition 沥焊甫 佬绢 坷绰巴俊 角菩窍绰 版快啊 乐绢 sync()甫  fsync()肺 措眉窃.. 2012.02.01 rajean
if ( -1 == fsync( fd_device ))
{
DEVICE_ERR("re-read partition error(0x%x0)\n",errno);
}
#endif
DEVICE_INFO("system sync wait please %d\n",0);
sync();
sleep(2);
if(ioctl(fd_device, BLKRRPART) != 0 )
{
#ifdef USED_HI3520 // Partition 沥焊甫 佬绢 坷绰巴俊 角菩窍绰 版快啊 乐绢 sync()甫  fsync()肺 措眉窃.. 2012.02.01 rajean
sync();
sleep(4);
if ((ioctl(fd_device, BLKRRPART)) != 0)
{
DEVICE_ERR("re-read partition error(0x%x0)\n",errno);
perror("mid_storage");
}
#else
DEVICE_ERR("re-read partition error(0x%x0)\n",errno);
perror("mid_storage");
#endif
}
  else
  {
/* some kernel versions (1.2.x) seem to have trouble
*            rereading the partition table, but if asked to do it
*                       twice, the second time works. - biro@yggdrasil.com */
sync();
sleep(2);
if ((ioctl(fd_device, BLKRRPART)) != 0)
{
DEVICE_ERR("re-read partition error(0x%x0)\n",errno);
perror("mid_storage");
}
}


close(fd_device);
sleep(2);


DEVICE_INFO("system sync wait please %d\n",1);


for(i=0;i<pinfo->partition_number;i++)
{
memset(s_data,0,1024);
/* neonomad 070106
if the number of sectors per a cluster is small, much system memory is needed.
for formatting large size of storage as FATXX, use sepcl = 128;
*/
if(s_device_info[count].total_size_in_mega[s_device_info[count].partition_number] > 20*1024) // big size storage (more than 20GB)
{
DEVICE_INFO("sector 128, s_device_info[%d].total_size_in_mega[%d] : %d\n"
,count,s_device_info[count].partition_number, s_device_info[count].total_size_in_mega[s_device_info[count].partition_number]);
sepcl = 128; //sectors per a cluster
}
else if(s_device_info[count].total_size_in_mega[s_device_info[count].partition_number] > 512)
{
DEVICE_INFO("sector 8, s_device_info[%d].total_size_in_mega[%d] : %d\n"
,count,s_device_info[count].partition_number,s_device_info[count].total_size_in_mega[s_device_info[count].partition_number]);
sepcl = 8; //sectors per a cluster
}
else
{
DEVICE_INFO(" sector 2, s_device_info[%d].total_size_in_mega[%d] : %d\n"
,count,s_device_info[count].partition_number,s_device_info[count].total_size_in_mega[s_device_info[count].partition_number]);
//sepcl = 4; //sectors per a cluster
sepcl = 2; //ruein 080917 sectors per a cluster
}


system_timeout = 2*60;
switch(pinfo->file_system[i])
{
case DEVICE_FAT32:
if(internal_use !=0)
snprintf(s_data, sizeof(s_data),"mkfs.vfat %s -n \"%s\" -F 32 -s %d -I\n",pinfo->device_name,pinfo->label_name[i],sepcl); //neonomad 061213 for lager cluster size.
else
snprintf(s_data, sizeof(s_data),"mkfs.vfat %s%d -n \"%s\" -F 32 -s %d \n",pinfo->device_name,i+1,pinfo->label_name[i],sepcl);
        system_timeout=30*60;
        DEVICE_INFO("%s\n",s_data);
        if(SYSTEM_T(s_data,system_timeout) != 0)
        {
        DEVICE_ERR_MSG("mkfs error\n");
        return DEVICE_INFO_ERROR;
        }
break;


case DEVICE_FAT16:
if(internal_use !=0)
snprintf(s_data, sizeof(s_data),"mkfs.vfat %s -n \"%s\" -s %d -I\n",pinfo->device_name,pinfo->label_name[i],sepcl);
else
snprintf(s_data, sizeof(s_data),"mkfs.vfat %s%d -n \"%s\" -s %d\n",pinfo->device_name,i+1,pinfo->label_name[i],sepcl);
system_timeout=30*60;
        DEVICE_INFO("%s\n",s_data);
        if(SYSTEM_T(s_data,system_timeout) != 0)
        {
        DEVICE_ERR_MSG("mkfs error\n");
        return DEVICE_INFO_ERROR;
        }
break;


case DEVICE_EXT2:
case DEVICE_EXT3:
                    system_timeout = 10*60;
                    if (i==0)
                    {
                        snprintf(s_data, sizeof(s_data),"mkfs.ext3 -j %s%d -m 0 -F -L \"%s\"",pinfo->device_name,i+1,pinfo->label_name[i]);
                        DEVICE_DBG("%s\n",s_data);
                        SYSTEM_T("date",10);
                        if(SYSTEM_T(s_data,system_timeout) != 0)
                        {
                            DEVICE_ERR_MSG("mkfs.ext3\n");
                            return DEVICE_INFO_ERROR;
                        }
                    }
                    else if(i==1)
                    {
                        //mount /dev/sda1 /mnt/sda1
                        snprintf(s_data, sizeof(s_data),"mount -t ext3 %s%d /mnt/%s%d",pinfo->device_name,i,pinfo->device_name+5,i);
                        DEVICE_DBG("%s\n",s_data);
                        SYSTEM_T("date",10);
                        if(SYSTEM_T(s_data,system_timeout) != 0)
                        {
                            DEVICE_ERR_MSG("mount\n");
                            return DEVICE_INFO_ERROR;
                        }
                        //mkdir /mnt/sda1/disk
                        snprintf(s_data, sizeof(s_data),"mkdir /mnt/%s%d/disk",pinfo->device_name+5,i);
                        DEVICE_DBG("%s\n",s_data);
                        SYSTEM_T("date",10);
                        if(SYSTEM_T(s_data,system_timeout) != 0)
                        {
                            DEVICE_ERR_MSG("mkdir\n");
                            return DEVICE_INFO_ERROR;
                        }
                        //dd
                        snprintf(s_data, sizeof(s_data),"/bin/dd if=/dev/zero of=/mnt/%s%d/disk/extra-swap bs=1024 count=262144",pinfo->device_name+5,i);
                        DEVICE_DBG("%s\n",s_data);
                        SYSTEM_T("date",10);
                        if(SYSTEM_T(s_data,system_timeout) != 0)
                        {
                            DEVICE_ERR_MSG("mkdir\n");
                            return DEVICE_INFO_ERROR; 
                        }
                        //make swap
                        snprintf(s_data, sizeof(s_data),"/sbin/mkswap /mnt/%s%d/disk/extra-swap 262144",pinfo->device_name+5,i);
                        DEVICE_DBG("%s\n",s_data);                    
                        SYSTEM_T("date",10);
                        if(SYSTEM_T(s_data,system_timeout) != 0)
                        {
                            DEVICE_ERR_MSG("mkswap\n");
                            return DEVICE_INFO_ERROR;
                        }
                        //swap on
                        snprintf(s_data, sizeof(s_data),"/sbin/swapon /mnt/%s%d/disk/extra-swap",pinfo->device_name+5,i);
                        DEVICE_DBG("%s\n",s_data);
                        SYSTEM_T("date",10);
                        if(SYSTEM_T(s_data,system_timeout) != 0)
                        {
                            DEVICE_ERR_MSG("swapon\n");
                            return DEVICE_INFO_ERROR;
                        }
                        //mke2fs_quick_format
                        //snprintf(s_data, sizeof(s_data),"mke2fs_quick_format -j %s%d -m 0 -F -L \"%s\"",pinfo->device_name,i+1,pinfo->label_name[i]);
                        snprintf(s_data, sizeof(s_data),"mke2fs -j %s%d -b 4096 -T largefile4 -m 0 -F -L \"%s\"",pinfo->device_name,i+1,pinfo->label_name[i]);
            DEVICE_INFO("%s\n",s_data);
                        SYSTEM_T("date",10);
            if(SYSTEM_T(s_data,system_timeout) != 0)
            {
            DEVICE_ERR_MSG("mkfs error\n");
            return DEVICE_INFO_ERROR;
            }
                        //swap off
                        snprintf(s_data, sizeof(s_data),"/sbin/swapoff /mnt/%s%d/disk/extra-swap",pinfo->device_name+5,i);
            DEVICE_INFO("%s\n",s_data);
                        SYSTEM_T("date",10);
                        if(SYSTEM_T(s_data,system_timeout) != 0)
                        {
                            DEVICE_ERR_MSG("swapoff \n");
                            return DEVICE_INFO_ERROR;
                        }
                        //rm /mnt/sda1/disk
                        snprintf(s_data, sizeof(s_data),"rm -rf /mnt/%s%d/disk",pinfo->device_name+5,i);
            DEVICE_INFO("%s\n",s_data);
                        SYSTEM_T("date",10);
                        if(SYSTEM_T(s_data,system_timeout) != 0)
                        {
                            DEVICE_ERR_MSG("rm\n");
                            return DEVICE_INFO_ERROR;
                        }
                        //umount /mnt/sda1
                        snprintf(s_data, sizeof(s_data),"umount /mnt/%s%d",pinfo->device_name+5,i);
            DEVICE_INFO("%s\n",s_data);
                        SYSTEM_T("date",10);
                        if(SYSTEM_T(s_data,system_timeout) != 0)
                        {
                            DEVICE_ERR_MSG("umount\n");
                            return DEVICE_INFO_ERROR;
                        }   
                    }
                    else
                    {
                       DEVICE_DBG("Unexpected case.\n");
                    }
                    break;               


case DEVICE_XFS:
if (i==0)
{
#ifdef GPT_SUPPORT
if(sel_over_tera)
snprintf(s_data, sizeof(s_data),"mkfs.xfs %s%d -f -s size=4096 -L \"%s\"\n",pinfo->device_name,i+1,pinfo->label_name[i]);
else
snprintf(s_data, sizeof(s_data),"mkfs.xfs %s%d -f -L \"%s\"\n",pinfo->device_name,i+1,pinfo->label_name[i]);
#else
snprintf(s_data, sizeof(s_data),"mkfs.xfs %s%d -f -L \"%s\"\n",pinfo->device_name,i+1,pinfo->label_name[i]);
#endif
}
else
{
#ifdef GPT_SUPPORT
if(sel_over_tera)
snprintf(s_data, sizeof(s_data),"mkfs.xfs %s%d -f -s size=4096 -L \"%s\"\n",pinfo->device_name,i+1,pinfo->label_name[i]);
else
snprintf(s_data, sizeof(s_data),"mkfs.xfs %s%d -f -L \"%s\"\n",pinfo->device_name,i+1,pinfo->label_name[i]);
#else
snprintf(s_data, sizeof(s_data),"mkfs.xfs %s%d -f -L \"%s\"\n",pinfo->device_name,i+1,pinfo->label_name[i]);
#endif
}
system_timeout = 10*60;
        DEVICE_INFO("%s\n",s_data);
        if(SYSTEM_T(s_data,system_timeout) != 0)
        {
        DEVICE_ERR_MSG("mkfs error\n");
        return DEVICE_INFO_ERROR;
        }
break;


case DEVICE_KLOTHO:
if (i==0)
snprintf(s_data, sizeof(s_data),"mkfs.klotho %s%d -d 1024 -e 8k -s  -l \"%s\"\n",pinfo->device_name,i+1,pinfo->label_name[i]);
else
snprintf(s_data, sizeof(s_data),"mkfs.klotho %s%d  -c -s -l \"%s\"\n",pinfo->device_name,i+1,pinfo->label_name[i]);
system_timeout = 10*60;
        DEVICE_INFO("%s\n",s_data);
        if(SYSTEM_T(s_data,system_timeout) != 0)
        {
        DEVICE_ERR_MSG("mkfs error\n");
        return DEVICE_INFO_ERROR;
        }
break;


#ifdef SUPPORT_REISERFS
case DEVICE_REISERFS : 
if(i==0) {
snprintf(s_data, sizeof(s_data), "mkreiserfs %s%d -f -l \"%s\"\n", pinfo->device_name, i+1, pinfo->label_name[i]); 
}
else {
snprintf(s_data, sizeof(s_data), "mkreiserfs %s%d -f -l \"%s\"\n", pinfo->device_name, i+1, pinfo->label_name[i]); 
}


system_timeout = 60*60;
        DEVICE_INFO("%s\n",s_data);
        if(SYSTEM_T(s_data,system_timeout) != 0)
        {
        DEVICE_ERR_MSG("mkfs error\n");
        return DEVICE_INFO_ERROR;
        }
break;
#endif

default:
DEVICE_ERR("not support file system[0x%x]\n",pinfo->file_system[i]);
break;
}
}
}
else
{
for(i=0;i<pinfo->partition_number;i++)
{
switch(pinfo->file_system[i])
{
case DEVICE_FAT32:
case DEVICE_FAT16:
change_label_fat(pinfo,i);
break;


case DEVICE_EXT2:
case DEVICE_EXT3:
change_label_ext(pinfo,i);
break;


case DEVICE_KLOTHO:
change_label_klotho(pinfo,i);
break;


case DEVICE_XFS:
change_label_xfs(pinfo,i);
break;


#ifdef SUPPORT_REISERFS
case DEVICE_REISERFS : 
change_label_reiserfs(pinfo, i);
break;
#endif


default:
DEVICE_ERR("not support file system[0x%x]\n",pinfo->file_system[i]);
break;
}
}
}




// copy content
get_partition_info(&s_device_info[count]);
if(bformat != 0 )
{
// clear mount information
s_device_info[count].use = 0;
for(i=0;i<s_device_info[count].partition_number;i++)
memset(s_device_info[count].mount_point[i],0,DEVICE_CHAR_MAX);
}
memcpy(pinfo,&s_device_info[count],sizeof(device_info_t));


// is ata or usb ?
lock_change();
if(s_device_info[count].major == DEVICE_ATA)
s_skip_ata = 1;
else
s_skip_plug_storage = 1;
unlock_change();


return DEVICE_INFO_OK;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值