Kernel - Added .Detect method to VFS drivers
[tpg/acess2.git] / KernelLand / Modules / Filesystems / Ext2 / ext2.c
index f40689e..971ef28 100644 (file)
@@ -17,6 +17,7 @@ extern tVFS_NodeType  gExt2_DirType;
  int   Ext2_Install(char **Arguments);\r
  int   Ext2_Cleanup(void);\r
 // - Interface Functions\r
+ int           Ext2_Detect(int FD);\r
 tVFS_Node      *Ext2_InitDevice(const char *Device, const char **Options);\r
 void           Ext2_Unmount(tVFS_Node *Node);\r
 void           Ext2_CloseFile(tVFS_Node *Node);\r
@@ -31,7 +32,11 @@ MODULE_DEFINE(0, VERSION, FS_Ext2, Ext2_Install, Ext2_Cleanup);
 tExt2_Disk     gExt2_disks[6];\r
  int   giExt2_count = 0;\r
 tVFS_Driver    gExt2_FSInfo = {\r
-       "ext2", 0, Ext2_InitDevice, Ext2_Unmount, NULL\r
+       .Name = "ext2",\r
+       .Detect = Ext2_Detect,\r
+       .InitDevice = Ext2_InitDevice,\r
+       .Unmount = Ext2_Unmount,\r
+       .GetNodeFromINode = NULL\r
        };\r
 \r
 // === CODE ===\r
@@ -53,6 +58,31 @@ int Ext2_Cleanup(void)
        return 0;\r
 }\r
 \r
+/**\r
+ * Detect if a volume is Ext2 formatted\r
+ */\r
+int Ext2_Detect(int FD)\r
+{\r
+       tExt2_SuperBlock        sb;\r
+       size_t  len;\r
+       \r
+       len = VFS_ReadAt(FD, 1024, 1024, &sb);\r
+\r
+       if( len != 1024 ) {\r
+               Log_Debug("Ext2", "_Detect: Read failed? (0x%x != 1024)", len);\r
+               return 0;\r
+       }\r
+       \r
+       switch(sb.s_magic)\r
+       {\r
+       case 0xEF53:\r
+               return 2;\r
+       default:\r
+               Log_Debug("Ext2", "_Detect: s_magic = 0x%x", sb.s_magic);\r
+               return 0;\r
+       }\r
+}\r
+\r
 /**\r
  \brief Initializes a device to be read by by the driver\r
  \param Device String - Device to read from\r

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