// =======================================================
char *processHardDrive(char *cPtr, newtComponent editPartition)
{
  char *cOldPtr;
  int nMajor, nMinor, nBlocks;
  int nPartNum;
  char szDevice[128];
  char szFullDevice[128];
  char cFormat[1024];
  char szTemp[1024];
  char *szDeviceName;
  int nRes;
  QWORD qwSize;

  cOldPtr = cPtr;
  nPartNum = 1;

  showDebug(9, "decode HD\n");

  while (*(cPtr) && *(cPtr+1) && *(cPtr+2) && nPartNum)
    {
      cPtr = decodePartitionEntry(cPtr, &nMajor, &nMinor, &nBlocks, &nPartNum, szDevice);
      if (nPartNum)
	{
	  cOldPtr = cPtr;

	  memset(cFormat, ' ', 50);
	  memset(cFormat+50, 0, 50);
	  
	  memcpy(cFormat, szDevice, strlen(szDevice)); // Device
	  
	  SNPRINTF(szFullDevice, "/dev/%s", szDevice);
	  checkInodeForDevice(szFullDevice);
	  
	  if (nBlocks > 1) // a standard device
	    {
	      nRes = detectFileSystem(szFullDevice, szTemp);
	      memcpy(cFormat+37, szTemp, strlen(szTemp)); // File system
	      
	      qwSize = getPartitionSize(szFullDevice);
	      formatSize(qwSize, szTemp);	
	      memcpy(cFormat+50, szTemp, strlen(szTemp)); // Size
	    }
	  else if (nBlocks == 1) // an extended partition
	    {
	      SNPRINTF(szTemp, "-extended-");
	      memcpy(cFormat+37, szTemp, strlen(szTemp)); // File system
	    }
	  
          szDeviceName = strdup(szFullDevice); // TOTO: never freed
	  newtListboxAppendEntry(editPartition, cFormat, (void*)szDeviceName);
          showDebug(9, "inserted[2]: %s\n", cFormat);
	  //debugWin("add[%s] and *cPtr=%d and 1=%d and 2=%d and 3=%d and 4=%d", cFormat, *(cPtr), *(cPtr+1), *(cPtr+2), *(cPtr+3), *(cPtr+4));
	}
    }

  return cOldPtr;
}
Exemple #2
0
void luks::loadInnerFileSystem(const QString& mapperNode)
{
    Q_ASSERT(!m_innerFs);
    FileSystem::Type innerFsType = detectFileSystem(mapperNode);
    m_innerFs = FileSystemFactory::cloneWithNewType(innerFsType,
                                                    *this);
    setLabel(m_innerFs->readLabel(mapperNode));
    setUUID(m_innerFs->readUUID(mapperNode));
    if (m_innerFs->supportGetUsed() == FileSystem::cmdSupportFileSystem)
        setSectorsUsed((m_innerFs->readUsedCapacity(mapperNode) + payloadOffset()) / m_logicalSectorSize );
    m_innerFs->scan(mapperNode);
}
// =======================================================
int fillPartitionList(newtComponent editPartition)
{
  BEGIN;

  FILE *fPart;
  int nMajor, nMinor, nBlocks;
  char szDevice[128];
  char szFullDevice[128];
  char cBuffer[32768];
  char cFormat[1024];
  char szTemp[1024];
  char *cPtr;
  int nLines;
  unsigned int nSize;
  QWORD qwSize;
  int i;
  int nRes;
  char *szDeviceName;
  int nPartNum;
  
  errno = 0;
  fPart = fopen("/proc/partitions", "rb");
  if (!fPart)
    {	
      g_interface->msgBoxError(i18n("Cannot read \"/proc/partitions\" (%s). Then, you must use the "
				    "command line to run Partition Image. Type \"partimage --help\" for help."), strerror(errno));
      RETURN_int(-1);	
    }
  
  nSize = 0;
  nLines = 0;
  memset(cBuffer, 0, sizeof(cBuffer));
  showDebug(9, "Reading /proc/partitions file\n");
  while (nSize < sizeof(cBuffer) && !feof(fPart))
    {
      nRes = fgetc(fPart);
      if (nRes != -1)
        cBuffer[nSize] = nRes;
      else
        showDebug(9, "error in fgetc\n");
      if (cBuffer[nSize] == '\n')
        {
	  ++nLines;
          showDebug(9, "%d lines read\n", nLines);
        }
      ++nSize;
    }
  if (nSize < sizeof(cBuffer)) 
    cBuffer[nSize] = '\0';
  else
    cBuffer[sizeof(cBuffer)-1] = '\0';

  fclose(fPart);
  showDebug(9, "/proc/partitions read -> \n%s\n", cBuffer);
  
  cPtr = cBuffer;
  
  // skip two first lines
  nLines -= 2;
  for (i=0; i < 2; i++)
    {
      while (*cPtr != '\n')
	cPtr++;
      cPtr++;
    }
  
  while (*(cPtr) && *(cPtr+1)&& *(cPtr+2))
  //for (i=0; i < nLines; i++) // TO BE CHANGED
    {
      cPtr = decodePartitionEntry(cPtr, &nMajor, &nMinor, &nBlocks, &nPartNum, szDevice);
      
      // detect file system of the hard disk
      SNPRINTF(szFullDevice, "/dev/%s", szDevice);
      checkInodeForDevice(szFullDevice);
      nRes = detectFileSystem(szFullDevice, szTemp);

      showDebug(9, "device %s\n", szDevice);     
 
      if (nRes != -1) // if a removable media
	{
          showDebug(9, "removable media found: %s\n", szTemp);
	  // add media
	  memset(cFormat, ' ', 50);
	  memset(cFormat+50, 0, 50);
	  
	  memcpy(cFormat, szDevice, strlen(szDevice)); // Device

	  memcpy(cFormat+37, szTemp, strlen(szTemp)); // File system
	  
	  qwSize = getPartitionSize(szFullDevice);
	  formatSize(qwSize, szTemp);	
	  memcpy(cFormat+50, szTemp, strlen(szTemp)); // Size

          szDeviceName = strdup(szFullDevice); // TODO: never freed
	  newtListboxAppendEntry(editPartition, cFormat, (void*)szDeviceName);
          showDebug(9, "inserted: %s\n", cFormat);

	  // skip partitions
	  cPtr = skipPartitionsEntries(cPtr);
	}
      else // if an hard disk
	{
	  cPtr = processHardDrive(cPtr, editPartition);
	}
    }

  RETURN_int(0);
}