当前位置: 代码迷 >> 综合 >> android 如何修改USB存储在我的电脑中显示的label名称
  详细解决方案

android 如何修改USB存储在我的电脑中显示的label名称

热度:10   发布时间:2024-01-19 17:57:29.0

说明:

内置SD卡即是eMMC上的FAT partition,可以指定label。 外置SD card是外部设备,无法指定label。

  • Internal SD card à You can assign label
  • External SD card à You cannot assign label

 

步骤:

主要是在format时去指定 “–L”  的参数值,并给出label name。具体修改涉及三个文件:

1. /system/vold/Fat.cpp 

添加一个新的format函数,第三个参数为bool isInternalSd:

     Fat::format(const char *fsPath, unsigned int numSectors, bool isInternalSd)

     修改新增format函数的实现:

         ......

#ifdef MTK_FORMAT_NOT_PARAM_CLUSTER
    args[1] = "-O";
    args[2] = "android";
    close(fd);
   if(numSectors)
 {
    char tmp[32];
    snprintf(tmp,sizeof(tmp),"%u",numSectors);
    const char *size = tmp;
    args[3] = "-s";
    args[4] = size;
    args[5] = fsPath;
    args[6]= NULL;
    rc = logwrap(7,args,1); 
 }
 else
 {
    if(isInternalSd)
    {
        args[3] = "-L";
        args[4] = "YOUR LABEL NAME";       // 修改label,注意长度不能超过11个字符
        args[5] = fsPath;
        args[6]= NULL;
        rc = logwrap(7,args,1); 
     }
    else
    {
        args[3] = fsPath;
        args[4] = NULL;
        rc = logwrap(9,args,1); 
    }
 }
    
#else

......

 if(numSectors)
 {
    char tmp[32];
    snprintf(tmp,sizeof(tmp),"%u",numSectors);
    const char *size = tmp;
    args[7] = "-s";
    args[8] = size;
    args[9] = fsPath;
    args[10]= NULL;
    rc = logwrap(11,args,1); 
 }
 else
 {
    if(isInternalSd)
    {
        args[7] = "-L";
        args[8] = "YOUR LABEL NAME";       // 修改label,注意长度不能超过11个字符
        args[9] = fsPath;
        args[10]= NULL;
        rc = logwrap(11,args,1); 
     }
     else
     {
        args[7] = fsPath;
        args[8] = NULL;
        rc = logwrap(9,args,1); 
    }
 }
#endif

......

2. /system/vold/Fat.h

    添加新增format函数的定义

3. /system/vold/Volume.cpp

    在调用Fat::format函数的地方,增加第三个参数IsEmmcStorage()        

    Fat::format(devicePath, 0, IsEmmcStorage())

 

注意:

1. VolumeManger.cpp里面调用Fat::format() 的地方不需要修改

2. 下载image时,需要进行格式化下载

  相关解决方案