Changes in v1.8.7 (4/22/2003) (brianp)
[reactos.git] / freeldr / freeldr / fs / fsrec.c
1 /*
2 * FreeLoader
3 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include <freeldr.h>
21 #include <fs.h>
22 #include "fsrec.h"
23 #include "fat.h"
24 #include "iso.h"
25 #include "ext2.h"
26 #include <disk.h>
27 #include <rtl.h>
28 #include <arch.h>
29 #include <debug.h>
30
31
32
33
34 /////////////////////////////////////////////////////////////////////////////////////////////
35 // FUNCTIONS
36 /////////////////////////////////////////////////////////////////////////////////////////////
37
38 /*
39 *
40 * BOOL FsRecognizeVolume(U32 DriveNumber, U32 VolumeStartSector, U8* VolumeType);
41 *
42 */
43 BOOL FsRecognizeVolume(U32 DriveNumber, U32 VolumeStartSector, U8* VolumeType)
44 {
45
46 DbgPrint((DPRINT_FILESYSTEM, "FsRecognizeVolume() DriveNumber: 0x%x VolumeStartSector: %d\n", DriveNumber, VolumeStartSector));
47
48 if (FsRecIsExt2(DriveNumber, VolumeStartSector))
49 {
50 *VolumeType = PARTITION_EXT2;
51 return TRUE;
52 }
53 else if (FsRecIsFat(DriveNumber, VolumeStartSector))
54 {
55 *VolumeType = PARTITION_FAT32;
56 return TRUE;
57 }
58
59 return FALSE;
60 }
61
62 BOOL FsRecIsIso9660(U32 DriveNumber)
63 {
64 PUCHAR Sector = (PUCHAR)DISKREADBUFFER;
65
66 if (!DiskReadLogicalSectors(DriveNumber, 16, 1, Sector))
67 {
68 FileSystemError("Failed to read the PVD.");
69 return FALSE;
70 }
71
72 return (Sector[0] == 1 &&
73 Sector[1] == 'C' &&
74 Sector[2] == 'D' &&
75 Sector[3] == '0' &&
76 Sector[4] == '0' &&
77 Sector[5] == '1');
78 }
79
80 BOOL FsRecIsExt2(U32 DriveNumber, U32 VolumeStartSector)
81 {
82 PEXT2_SUPER_BLOCK SuperBlock = (PEXT2_SUPER_BLOCK)DISKREADBUFFER;
83
84 if (!DiskReadLogicalSectors(DriveNumber, VolumeStartSector + 2, 2, SuperBlock))
85 {
86 FileSystemError("Failed to read the super block.");
87 return FALSE;
88 }
89
90 if (SuperBlock->s_magic == EXT3_SUPER_MAGIC)
91 {
92 return TRUE;
93 }
94
95 return FALSE;
96 }
97
98 BOOL FsRecIsFat(U32 DriveNumber, U32 VolumeStartSector)
99 {
100 PFAT_BOOTSECTOR BootSector = (PFAT_BOOTSECTOR)DISKREADBUFFER;
101
102 if (!DiskReadLogicalSectors(DriveNumber, VolumeStartSector, 1, BootSector))
103 {
104 FileSystemError("Failed to read the boot sector.");
105 return FALSE;
106 }
107
108 if (strncmp(BootSector->FileSystemType, "FAT12 ", 8) == 0 ||
109 strncmp(BootSector->FileSystemType, "FAT16 ", 8) == 0 ||
110 strncmp(BootSector->FileSystemType, "FAT32 ", 8) == 0)
111 {
112 return TRUE;
113 }
114
115 return FALSE;
116 }