]>
Commit | Line | Data |
---|---|---|
2262cfee WD |
1 | /* |
2 | * (C) Copyright 2002 | |
fa82f871 | 3 | * Stäubli Faverges - <www.staubli.com> |
2262cfee WD |
4 | * Pierre AUBERT [email protected] |
5 | * | |
6 | * See file CREDITS for list of people who contributed to this | |
7 | * project. | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or | |
10 | * modify it under the terms of the GNU General Public License as | |
11 | * published by the Free Software Foundation; either version 2 of | |
12 | * the License, or (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, | |
22 | * MA 02111-1307 USA | |
23 | */ | |
24 | ||
25 | #include <common.h> | |
26 | #include <config.h> | |
27 | #include <malloc.h> | |
28 | ||
2262cfee WD |
29 | #include "dos.h" |
30 | #include "fdos.h" | |
31 | ||
32 | ||
33 | /*----------------------------------------------------------------------------- | |
8bde7f77 | 34 | * fill_fs -- Read info on file system |
2262cfee WD |
35 | *----------------------------------------------------------------------------- |
36 | */ | |
37 | static int fill_fs (BootSector_t *boot, Fs_t *fs) | |
38 | { | |
8bde7f77 | 39 | |
2262cfee WD |
40 | fs -> fat_start = __le16_to_cpu (boot -> nrsvsect); |
41 | fs -> fat_len = __le16_to_cpu (boot -> fatlen); | |
42 | fs -> nb_fat = boot -> nfat; | |
8bde7f77 | 43 | |
2262cfee WD |
44 | fs -> dir_start = fs -> fat_start + fs -> nb_fat * fs -> fat_len; |
45 | fs -> dir_len = __le16_to_cpu (boot -> dirents) * MDIR_SIZE / SZ_STD_SECTOR; | |
46 | fs -> cluster_size = boot -> clsiz; | |
47 | fs -> num_clus = (fs -> tot_sectors - fs -> dir_start - fs -> dir_len) / fs -> cluster_size; | |
48 | ||
49 | return (0); | |
50 | } | |
51 | ||
52 | /*----------------------------------------------------------------------------- | |
8bde7f77 | 53 | * fs_init -- |
2262cfee WD |
54 | *----------------------------------------------------------------------------- |
55 | */ | |
56 | int fs_init (Fs_t *fs) | |
57 | { | |
58 | BootSector_t *boot; | |
59 | ||
60 | /* Initialize physical device */ | |
61 | if (dev_open () < 0) { | |
8bde7f77 WD |
62 | PRINTF ("Unable to initialize the fdc\n"); |
63 | return (-1); | |
2262cfee WD |
64 | } |
65 | init_subdir (); | |
8bde7f77 | 66 | |
2262cfee WD |
67 | /* Allocate space for read the boot sector */ |
68 | if ((boot = (BootSector_t *)malloc (sizeof (BootSector_t))) == NULL) { | |
8bde7f77 WD |
69 | PRINTF ("Unable to allocate space for boot sector\n"); |
70 | return (-1); | |
2262cfee | 71 | } |
8bde7f77 | 72 | |
2262cfee WD |
73 | /* read boot sector */ |
74 | if (dev_read (boot, 0, 1)){ | |
8bde7f77 WD |
75 | PRINTF ("Error during boot sector read\n"); |
76 | free (boot); | |
77 | return (-1); | |
2262cfee WD |
78 | } |
79 | ||
80 | /* we verify it'a a DOS diskette */ | |
81 | if (boot -> jump [0] != JUMP_0_1 && boot -> jump [0] != JUMP_0_2) { | |
8bde7f77 WD |
82 | PRINTF ("Not a DOS diskette\n"); |
83 | free (boot); | |
84 | return (-1); | |
2262cfee WD |
85 | } |
86 | ||
87 | if (boot -> descr < MEDIA_STD) { | |
8bde7f77 WD |
88 | /* We handle only recent medias (type F0) */ |
89 | PRINTF ("unrecognized diskette type\n"); | |
90 | free (boot); | |
91 | return (-1); | |
2262cfee WD |
92 | } |
93 | ||
94 | if (check_dev (boot, fs) < 0) { | |
8bde7f77 WD |
95 | PRINTF ("Bad diskette\n"); |
96 | free (boot); | |
97 | return (-1); | |
2262cfee | 98 | } |
8bde7f77 | 99 | |
2262cfee | 100 | if (fill_fs (boot, fs) < 0) { |
8bde7f77 | 101 | free (boot); |
2262cfee | 102 | |
8bde7f77 | 103 | return (-1); |
2262cfee WD |
104 | } |
105 | ||
106 | /* Read FAT */ | |
107 | if (read_fat (boot, fs) < 0) { | |
8bde7f77 WD |
108 | free (boot); |
109 | return (-1); | |
2262cfee WD |
110 | } |
111 | ||
112 | free (boot); | |
113 | return (0); | |
114 | } |