qtmobility/src/systeminfo/qsysteminfo_linux_common.cpp
changeset 5 453da2cfceef
parent 4 90517678cc4f
child 8 71781823f776
equal deleted inserted replaced
4:90517678cc4f 5:453da2cfceef
   985     if(driveVolume.left(2) == "//") {
   985     if(driveVolume.left(2) == "//") {
   986         return 0;
   986         return 0;
   987     }
   987     }
   988     mountEntries();
   988     mountEntries();
   989     struct statfs fs;
   989     struct statfs fs;
   990     if(statfs(mountEntriesMap[driveVolume].toLatin1(), &fs ) == 0 ) {
   990     if(statfs(driveVolume.toLatin1(), &fs ) == 0 ) {
   991                 long blockSize = fs.f_bsize;
   991                 long blockSize = fs.f_bsize;
   992                 long availBlocks = fs.f_bavail;
   992                 long availBlocks = fs.f_bavail;
   993                 return (double)availBlocks * blockSize;
   993                 return (double)availBlocks * blockSize;
   994             }
   994             }
   995     return 0;
   995     return 0;
  1000     if(driveVolume.left(2) == "//") {
  1000     if(driveVolume.left(2) == "//") {
  1001         return 0;
  1001         return 0;
  1002     }
  1002     }
  1003     mountEntries();
  1003     mountEntries();
  1004     struct statfs fs;
  1004     struct statfs fs;
  1005     if(statfs(mountEntriesMap[driveVolume].toLatin1(), &fs ) == 0 ) {
  1005     if(statfs(driveVolume.toLatin1(), &fs ) == 0 ) {
  1006         const long blockSize = fs.f_bsize;
  1006         const long blockSize = fs.f_bsize;
  1007         const long totalBlocks = fs.f_blocks;
  1007         const long totalBlocks = fs.f_blocks;
  1008         return (double)totalBlocks * blockSize;
  1008         return (double)totalBlocks * blockSize;
  1009     }
  1009     }
  1010     return 0;
  1010     return 0;
  1018         QHalInterface iface;
  1018         QHalInterface iface;
  1019         const QStringList list = iface.findDeviceByCapability("volume");
  1019         const QStringList list = iface.findDeviceByCapability("volume");
  1020         if(!list.isEmpty()) {
  1020         if(!list.isEmpty()) {
  1021             foreach(const QString vol, list) {
  1021             foreach(const QString vol, list) {
  1022                 QHalDeviceInterface ifaceDevice(vol);
  1022                 QHalDeviceInterface ifaceDevice(vol);
  1023                 if(driveVolume == ifaceDevice.getPropertyString("block.device")) {
  1023                 if(mountEntriesMap.value(driveVolume) == ifaceDevice.getPropertyString("block.device")) {
  1024                     QHalDeviceInterface ifaceDeviceParent(ifaceDevice.getPropertyString("info.parent"), this);
  1024                     QHalDeviceInterface ifaceDeviceParent(ifaceDevice.getPropertyString("info.parent"), this);
  1025 
  1025 
  1026                     if(ifaceDeviceParent.getPropertyBool("storage.removable")
  1026                     if(ifaceDeviceParent.getPropertyBool("storage.removable")
  1027                         ||  ifaceDeviceParent.getPropertyString("storage.drive_type") != "disk") {
  1027                         ||  ifaceDeviceParent.getPropertyString("storage.drive_type") != "disk") {
  1028                         return QSystemStorageInfo::RemovableDrive;
  1028                         return QSystemStorageInfo::RemovableDrive;
  1036 #endif
  1036 #endif
  1037     } else {
  1037     } else {
  1038         //no hal need to manually read sys file for block device
  1038         //no hal need to manually read sys file for block device
  1039         QString dmFile;
  1039         QString dmFile;
  1040 
  1040 
  1041         if(driveVolume.contains("mapper")) {
  1041         if(mountEntriesMap.value(driveVolume).contains("mapper")) {
  1042             struct stat stat_buf;
  1042             struct stat stat_buf;
  1043             stat( driveVolume.toLatin1(), &stat_buf);
  1043             stat( mountEntriesMap.value(driveVolume).toLatin1(), &stat_buf);
  1044 
  1044 
  1045             dmFile = QString("/sys/block/dm-%1/removable").arg(stat_buf.st_rdev & 0377);
  1045             dmFile = QString("/sys/block/dm-%1/removable").arg(stat_buf.st_rdev & 0377);
  1046 
  1046 
  1047         } else {
  1047         } else {
  1048 
  1048 
  1049             dmFile = driveVolume.section("/",2,3);
  1049             dmFile = mountEntriesMap.value(driveVolume).section("/",2,3);
  1050             if (dmFile.left(3) == "mmc") { //assume this dev is removable sd/mmc card.
  1050             if (dmFile.left(3) == "mmc") { //assume this dev is removable sd/mmc card.
  1051                 return QSystemStorageInfo::RemovableDrive;
  1051                 return QSystemStorageInfo::RemovableDrive;
  1052             }
  1052             }
  1053 
  1053 
  1054             if(dmFile.length() > 3) { //if device has number, we need the 'parent' device
  1054             if(dmFile.length() > 3) { //if device has number, we need the 'parent' device
  1112                 }
  1112                 }
  1113             }
  1113             }
  1114         } else {
  1114         } else {
  1115             ok = true;
  1115             ok = true;
  1116         }
  1116         }
  1117         if(ok && !mountEntriesMap.keys().contains(me->mnt_dir)) {
  1117         if(ok && !mountEntriesMap.keys().contains(me->mnt_fsname)) {
  1118             mountEntriesMap[me->mnt_fsname] = me->mnt_dir;
  1118             mountEntriesMap[me->mnt_dir] = me->mnt_fsname;
  1119         }
  1119         }
  1120 
  1120 
  1121         me = getmntent(mntfp);
  1121         me = getmntent(mntfp);
  1122     }
  1122     }
  1123     endmntent(mntfp);
  1123     endmntent(mntfp);