Modules/FAT - Implemented GetNodeFromINode
authorJohn Hodge <[email protected]>
Wed, 24 Aug 2011 02:56:51 +0000 (10:56 +0800)
committerJohn Hodge <[email protected]>
Wed, 24 Aug 2011 02:56:51 +0000 (10:56 +0800)
Modules/Filesystems/FAT/fat.c

index 80bf391..97044eb 100644 (file)
@@ -75,6 +75,7 @@ Uint64        FAT_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
 // --- Directory IO\r
 char   *FAT_ReadDir(tVFS_Node *Node, int ID);\r
 tVFS_Node      *FAT_FindDir(tVFS_Node *Node, const char *Name);\r
+tVFS_Node      *FAT_GetNodeFromINode(tVFS_Node *Root, Uint64 Inode);\r
 #if SUPPORT_WRITE\r
  int   FAT_Mknod(tVFS_Node *Node, const char *Name, Uint Flags);\r
  int   FAT_Relink(tVFS_Node *node, const char *OldName, const char *NewName);\r
@@ -88,7 +89,7 @@ void  FAT_CloseFile(tVFS_Node *node);
 MODULE_DEFINE(0, (0<<8)|50 /*v0.50*/, VFAT, FAT_Install, NULL, NULL);\r
 tFAT_VolInfo   gFAT_Disks[8];\r
  int   giFAT_PartCount = 0;\r
-tVFS_Driver    gFAT_FSInfo = {"fat", 0, FAT_InitDevice, FAT_Unmount, NULL};\r
+tVFS_Driver    gFAT_FSInfo = {"fat", 0, FAT_InitDevice, FAT_Unmount, FAT_GetNodeFromINode, NULL};\r
 \r
 // === CODE ===\r
 /**\r
@@ -133,11 +134,15 @@ tVFS_Node *FAT_InitDevice(const char *Device, const char **Options)
        // - From Microsoft FAT Specifcation\r
        RootDirSectors = ((bs->files_in_root*32) + (bs->bps - 1)) / bs->bps;\r
        \r
-       if(bs->fatSz16 != 0)            FATSz = bs->fatSz16;\r
-       else                                    FATSz = bs->spec.fat32.fatSz32;\r
+       if(bs->fatSz16 != 0)\r
+               FATSz = bs->fatSz16;\r
+       else\r
+               FATSz = bs->spec.fat32.fatSz32;\r
        \r
-       if(bs->totalSect16 != 0)                TotSec = bs->totalSect16;\r
-       else                                            TotSec = bs->totalSect32;\r
+       if(bs->totalSect16 != 0)\r
+               TotSec = bs->totalSect16;\r
+       else\r
+               TotSec = bs->totalSect32;\r
        \r
        diskInfo->ClusterCount = (TotSec - (bs->resvSectCount + (bs->fatCount * FATSz) + RootDirSectors)) / bs->spc;\r
        \r
@@ -325,8 +330,8 @@ int FAT_int_GetAddress(tVFS_Node *Node, Uint64 Offset, Uint64 *Addr, Uint32 *Clu
        \r
        ENTER("pNode XOffset", Node, Offset);\r
        \r
-       cluster = Node->Inode & 0xFFFFFFFF;     // Cluster ID\r
-       LOG("cluster = %08x", cluster);\r
+       cluster = Node->Inode & 0xFFFFFFF     // Cluster ID\r
+       LOG("cluster = 0x%07x", cluster);\r
        \r
        // Do Cluster Skip\r
        // - Pre FAT32 had a reserved area for the root.\r
@@ -935,7 +940,7 @@ tVFS_Node *FAT_int_CreateNode(tVFS_Node *Parent, fat_filetable *Entry, int Pos)
        memset(&node, 0, sizeof(tVFS_Node));\r
        \r
        // Set Other Data\r
-       // 0-31: Cluster, 32-63: Parent Cluster\r
+       // 0-27: Cluster, 32-59: Parent Cluster\r
        node.Inode = Entry->cluster | (Entry->clusterHi<<16) | (Parent->Inode << 32);\r
        LOG("node.Inode = %llx", node.Inode);\r
        // Position in parent directory\r
@@ -1398,6 +1403,60 @@ tVFS_Node *FAT_FindDir(tVFS_Node *Node, const char *Name)
        return NULL;\r
 }\r
 \r
+tVFS_Node *FAT_GetNodeFromINode(tVFS_Node *Root, Uint64 Inode)\r
+{\r
+       tFAT_VolInfo    *disk = Root->ImplPtr;\r
+        int    ents_per_sector = 512 / sizeof(fat_filetable); \r
+       fat_filetable   fileinfo[ents_per_sector];\r
+        int    sector = 0, i;\r
+       tVFS_Node       stub_node;\r
+\r
+       ENTER("pRoot XInode", Root, Inode);\r
+\r
+       stub_node.ImplPtr = disk;\r
+       stub_node.Size = -1;\r
+       stub_node.Inode = Inode >> 32;\r
+\r
+       for( i = 0; ; i ++ )\r
+       {\r
+               if( i == 0 || i == ents_per_sector )\r
+               {\r
+                       if(FAT_int_ReadDirSector(&stub_node, sector, fileinfo))\r
+                       {\r
+                               LOG("ReadDirSector failed");\r
+                               LEAVE('n');\r
+                               return NULL;\r
+                       }\r
+                       i = 0;\r
+                       sector ++;\r
+               }\r
+       \r
+               // Check for free/end of list\r
+               if(fileinfo[i].name[0] == '\0') break;  // End of List marker\r
+               if(fileinfo[i].name[0] == '\xE5')       continue;       // Free entry\r
+               \r
+               if(fileinfo[i].attrib == ATTR_LFN)      continue;\r
+\r
+               LOG("fileinfo[i].cluster = %x %04x", fileinfo[i].clusterHi, fileinfo[i].cluster);\r
+               #if DEBUG\r
+               {\r
+                       char    tmpName[13];\r
+                       FAT_int_ProperFilename(tmpName, fileinfo[i].name);\r
+                       LOG("tmpName = '%s'", tmpName);\r
+               }\r
+               #endif\r
+               \r
+       \r
+               if(fileinfo[i].cluster != (Inode & 0xFFFF))     continue;\r
+               if(fileinfo[i].clusterHi != ((Inode >> 16) & 0xFFFF))   continue;\r
+\r
+               LEAVE_RET('p', FAT_int_CreateNode(&stub_node, &fileinfo[i], sector*ents_per_sector+i));\r
+       }\r
+       LOG("sector = %i, i = %i", sector, i);\r
+       LEAVE('n');\r
+       return NULL;\r
+}\r
+\r
 #if SUPPORT_WRITE\r
 /**\r
  * \fn int FAT_Mknod(tVFS_Node *Node, char *Name, Uint Flags)\r

UCC git Repository :: git.ucc.asn.au