3 * Copyright (C) 2003 ReactOS Team
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.
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.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS text-mode setup
22 * FILE: base/setup/usetup/fslist.c
23 * PURPOSE: Filesystem list functions
24 * PROGRAMMER: Eric Kohl
25 * Casper S. Hornstrup (chorns@users.sourceforge.net)
33 /* FUNCTIONS ****************************************************************/
37 IN OUT PFILE_SYSTEM_LIST List
,
38 IN LPCWSTR FileSystemName
,
39 IN FORMATEX FormatFunc
,
40 IN CHKDSKEX ChkdskFunc
)
42 PFILE_SYSTEM_ITEM Item
;
44 Item
= (PFILE_SYSTEM_ITEM
)RtlAllocateHeap(ProcessHeap
, 0, sizeof(FILE_SYSTEM_ITEM
));
48 Item
->FileSystemName
= FileSystemName
;
49 Item
->FormatFunc
= FormatFunc
;
50 Item
->ChkdskFunc
= ChkdskFunc
;
51 Item
->QuickFormat
= TRUE
;
52 InsertTailList(&List
->ListHead
, &Item
->ListEntry
);
57 Item
= (PFILE_SYSTEM_ITEM
)RtlAllocateHeap(ProcessHeap
, 0, sizeof(FILE_SYSTEM_ITEM
));
61 Item
->FileSystemName
= FileSystemName
;
62 Item
->FormatFunc
= FormatFunc
;
63 Item
->ChkdskFunc
= ChkdskFunc
;
64 Item
->QuickFormat
= FALSE
;
65 InsertTailList(&List
->ListHead
, &Item
->ListEntry
);
71 IN PFILE_SYSTEM_LIST List
,
72 IN LPWSTR FileSystemName
)
74 PLIST_ENTRY ListEntry
;
75 PFILE_SYSTEM_ITEM Item
;
77 ListEntry
= List
->ListHead
.Flink
;
78 while (ListEntry
!= &List
->ListHead
)
80 Item
= CONTAINING_RECORD(ListEntry
, FILE_SYSTEM_ITEM
, ListEntry
);
81 if (Item
->FileSystemName
&& wcsicmp(FileSystemName
, Item
->FileSystemName
) == 0)
84 ListEntry
= ListEntry
->Flink
;
93 IN PFILE_SYSTEM_LIST FileSystemList
,
94 IN
struct _PARTENTRY
* PartEntry
)
96 PFILE_SYSTEM_ITEM CurrentFileSystem
;
97 LPWSTR FileSystemName
= NULL
;
99 CurrentFileSystem
= PartEntry
->FileSystem
;
101 /* We have a file system, return it */
102 if (CurrentFileSystem
!= NULL
&& CurrentFileSystem
->FileSystemName
!= NULL
)
103 return CurrentFileSystem
;
105 DPRINT1("File system not found, try to guess one...\n");
107 CurrentFileSystem
= NULL
;
110 * We don't have one...
112 * Try to infer a preferred file system for this partition, given its ID.
114 * WARNING: This is partly a hack, since partitions with the same ID can
115 * be formatted with different file systems: for example, usual Linux
116 * partitions that are formatted in EXT2/3/4, ReiserFS, etc... have the
117 * same partition ID 0x83.
119 * The proper fix is to make a function that detects the existing FS
120 * from a given partition (not based on the partition ID).
121 * On the contrary, for unformatted partitions with a given ID, the
122 * following code is OK.
124 if ((PartEntry
->PartitionType
== PARTITION_FAT_12
) ||
125 (PartEntry
->PartitionType
== PARTITION_FAT_16
) ||
126 (PartEntry
->PartitionType
== PARTITION_HUGE
) ||
127 (PartEntry
->PartitionType
== PARTITION_XINT13
) ||
128 (PartEntry
->PartitionType
== PARTITION_FAT32
) ||
129 (PartEntry
->PartitionType
== PARTITION_FAT32_XINT13
))
131 FileSystemName
= L
"FAT";
133 else if (PartEntry
->PartitionType
== PARTITION_EXT2
)
135 // WARNING: See the warning above.
136 FileSystemName
= L
"EXT2";
138 else if (PartEntry
->PartitionType
== PARTITION_IFS
)
140 // WARNING: See the warning above.
141 FileSystemName
= L
"NTFS"; /* FIXME: Not quite correct! */
144 // HACK: WARNING: We cannot write on this FS yet!
145 if (PartEntry
->PartitionType
== PARTITION_EXT2
|| PartEntry
->PartitionType
== PARTITION_IFS
)
146 DPRINT1("Recognized file system %S that doesn't support write support yet!\n", FileSystemName
);
148 DPRINT1("GetFileSystem -- PartitionType: 0x%02X ; FileSystemName (guessed): %S\n",
149 PartEntry
->PartitionType
, FileSystemName
);
151 if (FileSystemName
!= NULL
)
152 CurrentFileSystem
= GetFileSystemByName(FileSystemList
, FileSystemName
);
154 return CurrentFileSystem
;
159 CreateFileSystemList(
162 IN BOOLEAN ForceFormat
,
163 IN LPCWSTR ForceFileSystem
)
165 PFILE_SYSTEM_LIST List
;
166 PFILE_SYSTEM_ITEM Item
;
167 PLIST_ENTRY ListEntry
;
169 List
= (PFILE_SYSTEM_LIST
)RtlAllocateHeap(ProcessHeap
, 0, sizeof(FILE_SYSTEM_LIST
));
175 List
->Selected
= NULL
;
176 InitializeListHead(&List
->ListHead
);
178 AddProvider(List
, L
"FAT", VfatFormat
, VfatChkdsk
);
180 AddProvider(List
, L
"EXT2", Ext2Format
, Ext2Chkdsk
);
181 AddProvider(List
, L
"NTFS", NtfsFormat
, NtfsChkdsk
);
186 /* Add 'Keep' provider */
187 AddProvider(List
, NULL
, NULL
, NULL
);
190 /* Search for ForceFileSystem in list */
191 ListEntry
= List
->ListHead
.Flink
;
192 while (ListEntry
!= &List
->ListHead
)
194 Item
= CONTAINING_RECORD(ListEntry
, FILE_SYSTEM_ITEM
, ListEntry
);
195 if (Item
->FileSystemName
&& wcscmp(ForceFileSystem
, Item
->FileSystemName
) == 0)
197 List
->Selected
= Item
;
200 ListEntry
= ListEntry
->Flink
;
203 List
->Selected
= CONTAINING_RECORD(List
->ListHead
.Flink
, FILE_SYSTEM_ITEM
, ListEntry
);
210 DestroyFileSystemList(
211 IN PFILE_SYSTEM_LIST List
)
213 PLIST_ENTRY ListEntry
= List
->ListHead
.Flink
;
214 PFILE_SYSTEM_ITEM Item
;
217 while (ListEntry
!= &List
->ListHead
)
219 Item
= CONTAINING_RECORD(ListEntry
, FILE_SYSTEM_ITEM
, ListEntry
);
220 Next
= ListEntry
->Flink
;
222 RtlFreeHeap(ProcessHeap
, 0, Item
);
226 RtlFreeHeap(ProcessHeap
, 0, List
);
232 IN PFILE_SYSTEM_LIST List
)
234 PLIST_ENTRY ListEntry
;
235 PFILE_SYSTEM_ITEM Item
;
241 ListEntry
= List
->ListHead
.Flink
;
242 while (ListEntry
!= &List
->ListHead
)
244 Item
= CONTAINING_RECORD(ListEntry
, FILE_SYSTEM_ITEM
, ListEntry
);
246 coPos
.X
= List
->Left
;
247 coPos
.Y
= List
->Top
+ (SHORT
)Index
;
248 FillConsoleOutputAttribute(StdOutput
,
249 FOREGROUND_WHITE
| BACKGROUND_BLUE
,
253 FillConsoleOutputCharacterA(StdOutput
,
259 if (Item
->FileSystemName
)
261 if (Item
->QuickFormat
)
262 snprintf(Buffer
, sizeof(Buffer
), MUIGetString(STRING_FORMATDISK1
), Item
->FileSystemName
);
264 snprintf(Buffer
, sizeof(Buffer
), MUIGetString(STRING_FORMATDISK2
), Item
->FileSystemName
);
267 snprintf(Buffer
, sizeof(Buffer
), MUIGetString(STRING_KEEPFORMAT
));
269 if (ListEntry
== &List
->Selected
->ListEntry
)
270 CONSOLE_SetInvertedTextXY(List
->Left
,
271 List
->Top
+ (SHORT
)Index
,
274 CONSOLE_SetTextXY(List
->Left
,
275 List
->Top
+ (SHORT
)Index
,
278 ListEntry
= ListEntry
->Flink
;
284 ScrollDownFileSystemList(
285 IN PFILE_SYSTEM_LIST List
)
287 if (List
->Selected
->ListEntry
.Flink
!= &List
->ListHead
)
289 List
->Selected
= CONTAINING_RECORD(List
->Selected
->ListEntry
.Flink
, FILE_SYSTEM_ITEM
, ListEntry
);
290 DrawFileSystemList(List
);
296 ScrollUpFileSystemList(
297 IN PFILE_SYSTEM_LIST List
)
299 if (List
->Selected
->ListEntry
.Blink
!= &List
->ListHead
)
301 List
->Selected
= CONTAINING_RECORD(List
->Selected
->ListEntry
.Blink
, FILE_SYSTEM_ITEM
, ListEntry
);
302 DrawFileSystemList(List
);