From: John Hodge Date: Sat, 14 Jul 2012 12:24:10 +0000 (+0800) Subject: Kernel - Added .Detect method to VFS drivers X-Git-Tag: rel0.15~611^2~34 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=891868f0b4d64eb274b5810ac0c4f0a53d104114;hp=42fb98c5f353bf3e7cfbc202e2ace886b0c85874;p=tpg%2Facess2.git Kernel - Added .Detect method to VFS drivers --- diff --git a/KernelLand/Kernel/include/vfs.h b/KernelLand/Kernel/include/vfs.h index 91dcd693..9cb9e5de 100644 --- a/KernelLand/Kernel/include/vfs.h +++ b/KernelLand/Kernel/include/vfs.h @@ -339,6 +339,15 @@ typedef struct sVFS_Driver */ Uint Flags; + /** + * \brief Detect if a volume is accessible using this driver + * \return Boolean success (with higher numbers being higher priority) + * + * E.g. FAT would return 1 as it's the lowest common denominator while ext2 might return 2, + * because it can be embedded in a FAT volume (and is a more fully featured filesystem). + */ + int (*Detect)(int FD); + /** * \brief Callback to mount a device */ diff --git a/KernelLand/Kernel/vfs/fs/devfs.c b/KernelLand/Kernel/vfs/fs/devfs.c index 354f4020..9ab2b7b4 100644 --- a/KernelLand/Kernel/vfs/fs/devfs.c +++ b/KernelLand/Kernel/vfs/fs/devfs.c @@ -20,7 +20,9 @@ tVFS_Node *DevFS_FindDir(tVFS_Node *Node, const char *Name); // === GLOBALS === tVFS_Driver gDevFS_Info = { - "devfs", 0, DevFS_InitDevice, DevFS_Unmount, NULL + .Name = "devfs", + .InitDevice = DevFS_InitDevice, + .Unmount = DevFS_Unmount }; tVFS_NodeType gDevFS_DirType = { .TypeName = "DevFS-Dir", diff --git a/KernelLand/Kernel/vfs/fs/root.c b/KernelLand/Kernel/vfs/fs/root.c index 6c45f40e..e97231bb 100644 --- a/KernelLand/Kernel/vfs/fs/root.c +++ b/KernelLand/Kernel/vfs/fs/root.c @@ -22,7 +22,8 @@ tRamFS_File *Root_int_AllocFile(void); // === GLOBALS === tVFS_Driver gRootFS_Info = { - "rootfs", 0, Root_InitDevice, NULL, NULL + .Name = "rootfs", + .InitDevice = Root_InitDevice }; tRamFS_File RootFS_Files[MAX_FILES]; tVFS_ACL RootFS_DirACLs[3] = { diff --git a/KernelLand/Modules/Filesystems/Ext2/ext2.c b/KernelLand/Modules/Filesystems/Ext2/ext2.c index f40689e0..971ef28e 100644 --- a/KernelLand/Modules/Filesystems/Ext2/ext2.c +++ b/KernelLand/Modules/Filesystems/Ext2/ext2.c @@ -17,6 +17,7 @@ extern tVFS_NodeType gExt2_DirType; int Ext2_Install(char **Arguments); int Ext2_Cleanup(void); // - Interface Functions + int Ext2_Detect(int FD); tVFS_Node *Ext2_InitDevice(const char *Device, const char **Options); void Ext2_Unmount(tVFS_Node *Node); void Ext2_CloseFile(tVFS_Node *Node); @@ -31,7 +32,11 @@ MODULE_DEFINE(0, VERSION, FS_Ext2, Ext2_Install, Ext2_Cleanup); tExt2_Disk gExt2_disks[6]; int giExt2_count = 0; tVFS_Driver gExt2_FSInfo = { - "ext2", 0, Ext2_InitDevice, Ext2_Unmount, NULL + .Name = "ext2", + .Detect = Ext2_Detect, + .InitDevice = Ext2_InitDevice, + .Unmount = Ext2_Unmount, + .GetNodeFromINode = NULL }; // === CODE === @@ -53,6 +58,31 @@ int Ext2_Cleanup(void) return 0; } +/** + * Detect if a volume is Ext2 formatted + */ +int Ext2_Detect(int FD) +{ + tExt2_SuperBlock sb; + size_t len; + + len = VFS_ReadAt(FD, 1024, 1024, &sb); + + if( len != 1024 ) { + Log_Debug("Ext2", "_Detect: Read failed? (0x%x != 1024)", len); + return 0; + } + + switch(sb.s_magic) + { + case 0xEF53: + return 2; + default: + Log_Debug("Ext2", "_Detect: s_magic = 0x%x", sb.s_magic); + return 0; + } +} + /** \brief Initializes a device to be read by by the driver \param Device String - Device to read from diff --git a/KernelLand/Modules/Filesystems/FAT/fat.c b/KernelLand/Modules/Filesystems/FAT/fat.c index ab91fcb3..f7ebafe5 100644 --- a/KernelLand/Modules/Filesystems/FAT/fat.c +++ b/KernelLand/Modules/Filesystems/FAT/fat.c @@ -27,6 +27,7 @@ // === PROTOTYPES === // --- Driver Core int FAT_Install(char **Arguments); + int FAT_Detect(int FD); tVFS_Node *FAT_InitDevice(const char *device, const char **options); void FAT_Unmount(tVFS_Node *Node); // --- Helpers @@ -46,7 +47,13 @@ void FAT_CloseFile(tVFS_Node *node); MODULE_DEFINE(0, VER2(0,80) /*v0.80*/, VFAT, FAT_Install, NULL, NULL); tFAT_VolInfo gFAT_Disks[8]; int giFAT_PartCount = 0; -tVFS_Driver gFAT_FSInfo = {"fat", 0, FAT_InitDevice, FAT_Unmount, FAT_GetNodeFromINode, NULL}; +tVFS_Driver gFAT_FSInfo = { + .Name = "fat", + .Detect = FAT_Detect, + .InitDevice = FAT_InitDevice, + .Unmount = FAT_Unmount, + .GetNodeFromINode = FAT_GetNodeFromINode +}; tVFS_NodeType gFAT_DirType = { .TypeName = "FAT-Dir", .ReadDir = FAT_ReadDir, @@ -78,6 +85,22 @@ int FAT_Install(char **Arguments) return MODULE_ERR_OK; } +/** + * \brief Detect if a file is a FAT device + */ +int FAT_Detect(int FD) +{ + fat_bootsect bs; + + if( VFS_ReadAt(FD, 0, 512, &bs) != 512) { + return 0; + } + + if(bs.bps == 0 || bs.spc == 0) + return 0; + + return 1; +} /** * \brief Reads the boot sector of a disk and prepares the structures for it */ diff --git a/KernelLand/Modules/Filesystems/NTFS/main.c b/KernelLand/Modules/Filesystems/NTFS/main.c index dbda06e1..87f2a09a 100644 --- a/KernelLand/Modules/Filesystems/NTFS/main.c +++ b/KernelLand/Modules/Filesystems/NTFS/main.c @@ -23,7 +23,12 @@ void NTFS_DumpEntry(tNTFS_Disk *Disk, Uint32 Entry); // === GLOBALS === MODULE_DEFINE(0, 0x0A /*v0.1*/, FS_NTFS, NTFS_Install, NULL); -tVFS_Driver gNTFS_FSInfo = {"ntfs", 0, NTFS_InitDevice, NTFS_Unmount, NULL}; +tVFS_Driver gNTFS_FSInfo = { + .Name = "ntfs", + .InitDevice = NTFS_InitDevice, + .Unmount = NTFS_Unmount, + .GetNodeFromINode = NULL +}; tVFS_NodeType gNTFS_DirType = { .TypeName = "NTFS-File", .ReadDir = NTFS_ReadDir,