Advertisement
Guest User

Hide Corrupt FAT32 partitions in XBMC

a guest
Jun 17th, 2010
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 10.51 KB | None | 0 0
  1. Index: trunk/xbmc/Application.cpp
  2. ===================================================================
  3. --- trunk/xbmc/Application.cpp  (revision 30397)
  4. +++ trunk/xbmc/Application.cpp  (working copy)
  5. @@ -894,15 +894,35 @@
  6.    if (CIoSupport::HasPartitionTable())
  7.    {
  8.      // Mount up to Partition15 (drive O:) if they are available.
  9. -    for (int i=EXTEND_PARTITION_BEGIN; i <= EXTEND_PARTITION_END; i++)
  10. +       PARTITION_SIZES psizes;
  11. +   memcpy (&psizes,CIoSupport::GetPartitionSizes(),sizeof(PARTITION_SIZES));
  12. +
  13. +   for (int i=EXTEND_PARTITION_BEGIN; i <= (EXTEND_PARTITION_BEGIN+EXTEND_PARTITIONS_LIMIT-1); i++)
  14.      {
  15.        char szDevice[32];
  16.        if (CIoSupport::PartitionExists(i))
  17.        {
  18. -        char cDriveLetter = 'A' + i - 1;
  19. -        sprintf(szDevice, "Harddisk0\\Partition%u", i);
  20. +        if (CIoSupport::GetPartitionClusterSize(i-1)>0 && (psizes[i-1]>=LBASIZE_512GB && CIoSupport::GetPartitionClusterSize(i)<64)||
  21. +                               (psizes[i-1]>=LBASIZE_256GB && CIoSupport::GetPartitionClusterSize(i)<32))
  22. +       {
  23. +           char cDriveLetter = 'A' + i - 1;
  24. +                  
  25. +           char extendDriveLetter = CIoSupport::GetExtendedPartitionDriveLetter(cDriveLetter-EXTEND_DRIVE_BEGIN);
  26. +           CLog::Log(LOGWARNING, " extended drive %c has wrong cluster size ", extendDriveLetter);
  27. +      
  28. +       }
  29. +       else
  30. +       {
  31. +           char cDriveLetter = 'A' + i - 1;
  32. +                  
  33. +           char extendDriveLetter = CIoSupport::GetExtendedPartitionDriveLetter(cDriveLetter-EXTEND_DRIVE_BEGIN);
  34. +           CLog::Log(LOGNOTICE, "  map extended drive %c:", extendDriveLetter);
  35. +      
  36. +           sprintf(szDevice, "Harddisk0\\Partition%u", i);
  37.  
  38. -        CIoSupport::RemapDriveLetter(cDriveLetter, szDevice);
  39. +           CIoSupport::RemapDriveLetter(extendDriveLetter, szDevice);
  40. +   //        CIoSupport::RemapDriveLetter(cDriveLetter, szDevice);
  41. +       }
  42.        }
  43.      }
  44.    }
  45. Index: trunk/xbmc/MediaManager.cpp
  46. ===================================================================
  47. --- trunk/xbmc/MediaManager.cpp (revision 30397)
  48. +++ trunk/xbmc/MediaManager.cpp (working copy)
  49. @@ -111,16 +111,35 @@
  50.    share.m_iDriveType = CMediaSource::SOURCE_TYPE_LOCAL;
  51.    share.strName.Format(g_localizeStrings.Get(21438),'E');
  52.    localDrives.push_back(share);
  53. -  for (char driveletter=EXTEND_DRIVE_BEGIN; driveletter<=EXTEND_DRIVE_END; driveletter++)
  54. +  //for (char driveletter=EXTEND_DRIVE_BEGIN; driveletter<=EXTEND_DRIVE_BEGIN+EXTEND_PARTITIONS_LIMIT; driveletter++)
  55. +  for (int driveCount=EXTEND_PARTITION_BEGIN;driveCount<=(EXTEND_PARTITION_BEGIN+EXTEND_PARTITIONS_LIMIT-1);driveCount++)
  56.    {
  57. -    if (CIoSupport::DriveExists(driveletter))
  58. +   if (CIoSupport::DriveExists(CIoSupport::GetExtendedPartitionDriveLetter(driveCount-EXTEND_PARTITION_BEGIN)))
  59.      {
  60.        CMediaSource share;
  61. -      share.strPath.Format("%c:\\", driveletter);
  62. -      share.strName.Format(g_localizeStrings.Get(21438),driveletter);
  63. -      share.m_ignore = true;
  64. -      localDrives.push_back(share);
  65. -    }
  66. +     PARTITION_SIZES psizes;
  67. +     memcpy (&psizes,CIoSupport::GetPartitionSizes(),sizeof(PARTITION_SIZES));
  68. +     if (CIoSupport::GetPartitionClusterSize(driveCount)!=0 && (psizes[driveCount-1]>=LBASIZE_512GB && CIoSupport::GetPartitionClusterSize(driveCount)<64)||
  69. +                               (psizes[driveCount-1]>=LBASIZE_256GB && CIoSupport::GetPartitionClusterSize(driveCount)<32))
  70. +     {
  71. +         share.m_iDriveType = CMediaSource::SOURCE_TYPE_UNKNOWN;
  72. +         share.m_ignore = true;
  73. +         share.strName.Format(g_localizeStrings.Get(21438),CIoSupport::GetExtendedPartitionDriveLetter(driveCount-EXTEND_PARTITION_BEGIN));
  74. +         share.strPath.Format("%c:\\", CIoSupport::GetExtendedPartitionDriveLetter(driveCount-EXTEND_PARTITION_BEGIN));
  75. +         CLog::Log(LOGWARNING, "  Local Source Drive %c: wrong cluster size", CIoSupport::GetExtendedPartitionDriveLetter(driveCount-EXTEND_PARTITION_BEGIN));
  76. +         localDrives.push_back(share);
  77. +  
  78. +     }
  79. +     else
  80. +     {
  81. +       share.strPath.Format("%c:\\", CIoSupport::GetExtendedPartitionDriveLetter(driveCount-EXTEND_PARTITION_BEGIN));
  82. +       CLog::Log(LOGNOTICE, "  Local Source Drive %c:", CIoSupport::GetExtendedPartitionDriveLetter(driveCount-EXTEND_PARTITION_BEGIN));
  83. +       share.strName.Format(g_localizeStrings.Get(21438),CIoSupport::GetExtendedPartitionDriveLetter(driveCount-EXTEND_PARTITION_BEGIN));
  84. +       share.m_ignore = true;
  85. +       localDrives.push_back(share);
  86. +
  87. +     }
  88. +   }
  89.    }
  90.    if (includeQ)
  91.    {
  92. Index: trunk/xbmc/xbox/IoSupport.cpp
  93. ===================================================================
  94. --- trunk/xbmc/xbox/IoSupport.cpp   (revision 30397)
  95. +++ trunk/xbmc/xbox/IoSupport.cpp   (working copy)
  96. @@ -55,6 +55,11 @@
  97.      { 'Y', "Harddisk0\\Partition4", 4},
  98.      { 'Z', "Harddisk0\\Partition5", 5},
  99.    };
  100. +char extendPartitionMapping[] =
  101. +{
  102. +   'F','G','R','S','V','W','A','B' // Bomb Bloke Partitioning scheme
  103. +};
  104. +
  105.  #else
  106.  stDriveMapping driveMapping[] =
  107.    {
  108. @@ -169,11 +174,17 @@
  109.  void CIoSupport::GetPartition(char cDriveLetter, char* szPartition)
  110.  {
  111.    char upperLetter = toupper(cDriveLetter);
  112. -  if (upperLetter >= 'F' && upperLetter <= 'O')
  113. +  if (ExtendedPartitionMappingExists(upperLetter))
  114.    {
  115. -    sprintf(szPartition, "Harddisk0\\Partition%u", upperLetter - 'A' + 1);
  116. -    return;
  117. +   sprintf(szPartition, "Harddisk0\\Partition%u", EXTEND_PARTITION_BEGIN+GetExtendedPartitionPosition(upperLetter));
  118. +    CLog::Log(LOGNOTICE, "Partition %s", szPartition);
  119. +   return;  
  120.    }
  121. +  //if (upperLetter >= 'F' && upperLetter <= 'O')// to change
  122. +  //{
  123. +  //  sprintf(szPartition, "Harddisk0\\Partition%u", upperLetter - 'A' + 1);
  124. +  //  return;
  125. +  //}
  126.    for (unsigned int i=0; i < NUM_OF_DRIVES; i++)
  127.      if (driveMapping[i].cDriveLetter == upperLetter)
  128.      {
  129. @@ -196,10 +207,11 @@
  130.  
  131.    part_num = atoi(szPartition + 19);
  132.  
  133. -  if (part_num >= 6)
  134. +  if (part_num >= EXTEND_PARTITION_BEGIN) // EP changed
  135.    {
  136. -    *cDriveLetter = part_num + 'A' - 1;
  137. -    return;
  138. +    *cDriveLetter = extendPartitionMapping[part_num-EXTEND_PARTITION_BEGIN];
  139. +   CLog::Log(LOGNOTICE, "Drive %c", *cDriveLetter);
  140. +   return;
  141.    }
  142.    for (unsigned int i=0; i < NUM_OF_DRIVES; i++)
  143.      if (strnicmp(driveMapping[i].szDevice, szPartition, strlen(driveMapping[i].szDevice)) == 0)
  144. @@ -537,7 +549,48 @@
  145.    return (drivelist >> bitposition) & 1;
  146.  #endif
  147.  }
  148. +unsigned int CIoSupport::GetPartitionClusterSize(int nPartition)
  149. +{
  150. +#ifdef _XBOX
  151. +  char szPartition[32];
  152. +  ANSI_STRING part_string;
  153. +  NTSTATUS status;
  154. +  HANDLE hDisk;
  155. +  OBJECT_ATTRIBUTES oa;
  156. +  IO_STATUS_BLOCK iosb;
  157.  
  158. +  sprintf(szPartition, "\\Device\\Harddisk0\\Partition%u", nPartition);
  159. +  RtlInitAnsiString(&part_string, szPartition);
  160. +
  161. +  oa.Attributes = OBJ_CASE_INSENSITIVE;
  162. +  oa.ObjectName = &part_string;
  163. +  oa.RootDirectory = 0;
  164. +
  165. +  status = NtOpenFile(&hDisk, GENERIC_READ | GENERIC_WRITE, &oa, &iosb, FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_SYNCHRONOUS_IO_ALERT);
  166. +
  167. +  if (NT_SUCCESS(status))
  168. +  {
  169. +   BYTE PartSector[4096];
  170. +   LARGE_INTEGER RWOffset;
  171. +   FATX_SUPERBLOCK fsb;
  172. +
  173. +   RWOffset.QuadPart = 0;
  174. +   memset(PartSector, 0, sizeof(PartSector));
  175. +  
  176. +   status = NtReadFile(hDisk, NULL, NULL, NULL, &iosb, (PVOID) PartSector, sizeof(PartSector), &RWOffset);
  177. +   if (!NT_SUCCESS(status))
  178. +       return 0;
  179. +   NtClose(hDisk);
  180. +   memcpy (&fsb,PartSector,sizeof(PartSector));
  181. +   return fsb.ClusterSize/2;
  182. +
  183. +  }
  184. +#else
  185. +  return 0;
  186. +#endif
  187. +
  188. +}
  189. +
  190.  bool CIoSupport::PartitionExists(int nPartition)
  191.  {
  192.  #ifdef _XBOX
  193. @@ -632,6 +685,41 @@
  194.  #endif
  195.  }
  196.  
  197. +PARTITION_SIZES * CIoSupport::GetPartitionSizes()
  198. +{
  199. +   PARTITION_SIZES table;
  200. +   for (int i=0;i<MAX_PARTITIONS;i++)
  201. +   {
  202. +       table[i] = m_partitionTable.pt_entries[i].pe_lba_size;
  203. +   }
  204. +   return &table;
  205. +}
  206. +bool CIoSupport::ExtendedPartitionMappingExists(char mapLetter)
  207. +{
  208. +   int i;
  209. +   for (i=0;i<EXTEND_PARTITIONS_LIMIT;i++)
  210. +   {
  211. +       if (mapLetter == extendPartitionMapping[i])
  212. +           return true;
  213. +   }
  214. +   return false;
  215. +}
  216. +
  217. +INT CIoSupport::GetExtendedPartitionPosition(char mapLetter)
  218. +{
  219. +   int i;
  220. +   for (i=0;i<EXTEND_PARTITIONS_LIMIT;i++)
  221. +   {
  222. +       if (mapLetter == extendPartitionMapping[i])
  223. +           return i;
  224. +   }
  225. +   return 0;
  226. +}
  227. +char CIoSupport::GetExtendedPartitionDriveLetter(int pos)
  228. +{
  229. +   return extendPartitionMapping[pos];
  230. +}
  231. +
  232.  bool CIoSupport::HasPartitionTable()
  233.  {
  234.    return m_fPartitionTableIsValid;
  235. @@ -644,16 +732,20 @@
  236.      return;
  237.    char szDevice[32] = "\\Harddisk0\\Partition0";
  238.    char driveletter;
  239. +  char extenddriveletter;
  240. +
  241.    // we start at 5 - the first 5 partitions are the mandatory standard Xbox partitions
  242.    // we don't deal with those here.
  243. -  for (int i = EXTEND_PARTITION_BEGIN; i <= EXTEND_PARTITION_END; i++)
  244. +  for (int i = EXTEND_PARTITION_BEGIN; i <= (EXTEND_PARTITION_BEGIN+EXTEND_PARTITIONS_LIMIT); i++)
  245.    {
  246.      if (m_partitionTable.pt_entries[i - 1].pe_flags & PE_PARTFLAGS_IN_USE)
  247.      {
  248.        driveletter = 'A' + i - 1;
  249. +     extenddriveletter = extendPartitionMapping[driveletter-EXTEND_DRIVE_BEGIN];
  250.        CLog::Log(LOGINFO, "  map drive %c:", driveletter);
  251. +      CLog::Log(LOGINFO, "  map extended drive %c:", extenddriveletter);
  252.        szDevice[20] = '1' + i - 1;
  253. -      MapDriveLetter(driveletter, szDevice);
  254. +      MapDriveLetter(extenddriveletter, szDevice);
  255.      }
  256.    }
  257.  #endif
  258. Index: trunk/xbmc/xbox/IoSupport.h
  259. ===================================================================
  260. --- trunk/xbmc/xbox/IoSupport.h (revision 30397)
  261. +++ trunk/xbmc/xbox/IoSupport.h (working copy)
  262. @@ -51,6 +51,9 @@
  263.  #define EXTEND_PARTITION_END    7
  264.  #define EXTEND_DRIVE_BEGIN     'F'
  265.  #define EXTEND_DRIVE_END       'G'
  266. +#define EXTEND_PARTITIONS_LIMIT    8
  267. +#define LBASIZE_512GB  1073741824
  268. +#define LBASIZE_256GB  536870912
  269.  
  270.  // This flag (part of PARTITION_ENTRY.pe_flags) tells you whether/not a
  271.  // partition is being used (whether/not drive G is active, for example)
  272. @@ -87,6 +90,18 @@
  273.    PARTITION_ENTRY pt_entries[MAX_PARTITIONS];
  274.  } PARTITION_TABLE;
  275.  
  276. +typedef unsigned long PARTITION_SIZES[MAX_PARTITIONS];
  277. +
  278. +typedef struct _FATX_SUPERBLOCK
  279. +{
  280. +   char    Tag[4];
  281. +   unsigned int        VolumeID;
  282. +   unsigned int    ClusterSize;
  283. +   unsigned short  FatCopies;
  284. +   int     Resvd;
  285. +   char    Unused[4078];
  286. +} FATX_SUPERBLOCK;
  287. +
  288.  class CIoSupport
  289.  {
  290.  public:
  291. @@ -106,8 +121,14 @@
  292.  
  293.    static bool ReadPartitionTable();
  294.    static bool HasPartitionTable();
  295. +  static bool ExtendedPartitionMappingExists(char mapLetter);
  296. +  static INT GetExtendedPartitionPosition(char mapLetter);
  297. +  static char GetExtendedPartitionDriveLetter(int pos);
  298. +  static unsigned int GetPartitionClusterSize(int nPartition);
  299.    static void MapExtendedPartitions();
  300. +  static PARTITION_SIZES * CIoSupport::GetPartitionSizes();
  301.  
  302. +
  303.    static LARGE_INTEGER GetDriveSize();
  304.  
  305.    static DWORD   GetTrayState();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement