]>
Commit | Line | Data |
---|---|---|
93afd047 MT |
1 | #include <stdio.h> |
2 | #include <stdlib.h> | |
3 | #include <string.h> | |
4 | #include <unistd.h> | |
5 | #include <fcntl.h> | |
6 | #include <sys/types.h> | |
7 | #include <sys/stat.h> | |
8 | ||
9 | #include "hd.h" | |
10 | #include "hd_int.h" | |
11 | #include "klog.h" | |
12 | #include "floppy.h" | |
13 | ||
14 | static void dump_floppy_data(hd_data_t *hd_data); | |
15 | ||
16 | /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | |
17 | * floppy info | |
18 | * | |
19 | * This should currently be called *before* scan_misc() so we can try to get | |
20 | * the floppy controller resources in scan_misc() by actually accessing the | |
21 | * floppy drive. (Otherwise there would be a rather longish timeout.) | |
22 | * | |
23 | * This is all rather strange and should be rewritten... | |
24 | * | |
25 | * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | |
26 | */ | |
27 | ||
28 | ||
29 | void hd_scan_floppy(hd_data_t *hd_data) | |
30 | { | |
31 | hd_t *hd; | |
32 | char b0[10], b1[10], c; | |
33 | unsigned u; | |
34 | int fd, i, floppy_ctrls = 0, floppy_ctrl_idx = 0; | |
35 | str_list_t *sl; | |
36 | hd_res_t *res; | |
37 | int floppy_stat[2] = { 1, 1 }; | |
38 | ||
39 | if(!hd_probe_feature(hd_data, pr_floppy)) return; | |
40 | ||
41 | hd_data->module = mod_floppy; | |
42 | ||
43 | /* some clean-up */ | |
44 | remove_hd_entries(hd_data); | |
45 | hd_data->floppy = free_str_list(hd_data->floppy); | |
46 | ||
47 | PROGRESS(1, 0, "get nvram"); | |
48 | ||
49 | /* | |
50 | * Look for existing floppy controller entries (typically there will be | |
51 | * *none*). | |
52 | */ | |
53 | for(hd = hd_data->hd; hd; hd = hd->next) { | |
54 | if(hd->base_class.id == bc_storage && hd->sub_class.id == sc_sto_floppy) { | |
55 | floppy_ctrls++; | |
56 | floppy_ctrl_idx = hd->idx; | |
57 | } | |
58 | } | |
59 | ||
60 | /* | |
61 | * Is enough to load the nvram module. | |
62 | * | |
63 | * Note: although you must be root to access /dev/nvram, every | |
64 | * user can read /proc/nvram. | |
65 | */ | |
66 | fd = open(DEV_NVRAM, O_RDONLY | O_NONBLOCK); | |
67 | if(fd >= 0) close(fd); | |
68 | ||
69 | if( | |
70 | !(hd_data->floppy = read_file(PROC_NVRAM_24, 0, 0)) && | |
71 | !(hd_data->floppy = read_file(PROC_NVRAM_22, 0, 0)) | |
72 | ); | |
73 | ||
74 | if(hd_data->floppy && (hd_data->debug & HD_DEB_FLOPPY)) dump_floppy_data(hd_data); | |
75 | ||
76 | if(!hd_data->klog) read_klog(hd_data); | |
77 | ||
78 | for(sl = hd_data->klog; sl; sl = sl->next) { | |
79 | if(sscanf(sl->str, "<4>floppy%u: no floppy controllers foun%c", &u, &c) == 2) { | |
80 | if(u < sizeof floppy_stat / sizeof *floppy_stat) { | |
81 | floppy_stat[u] = 0; | |
82 | } | |
83 | } | |
84 | } | |
85 | ||
86 | if(hd_data->floppy) { | |
87 | PROGRESS(2, 0, "nvram info"); | |
88 | sl = hd_data->floppy; | |
89 | } | |
90 | else { | |
91 | PROGRESS(2, 0, "klog info"); | |
92 | sl = hd_data->klog; | |
93 | } | |
94 | ||
95 | for(; sl; sl = sl->next) { | |
96 | if(hd_data->floppy) { | |
97 | i = sscanf(sl->str, " Floppy %u type : %8[0-9.]'' %8[0-9.]%c", &u, b0, b1, &c) == 4; | |
98 | } | |
99 | else { | |
100 | i = sscanf(sl->str, "<6>Floppy drive(s): fd%u is %8[0-9.]%c", &u, b1, &c) == 3; | |
101 | *b0 = 0; | |
102 | } | |
103 | ||
104 | if(i) { | |
105 | if( | |
106 | !floppy_ctrls && | |
107 | u < sizeof floppy_stat / sizeof *floppy_stat && | |
108 | floppy_stat[u] | |
109 | ) { | |
110 | /* create one, if missing (there's no floppy without a controller...) */ | |
111 | hd = add_hd_entry(hd_data, __LINE__, 0); | |
112 | hd->base_class.id = bc_storage; | |
113 | hd->sub_class.id = sc_sto_floppy; | |
114 | floppy_ctrl_idx = hd->idx; | |
115 | floppy_ctrls++; | |
116 | } | |
117 | ||
118 | if(floppy_ctrls) { | |
119 | hd = add_hd_entry(hd_data, __LINE__, 0); | |
120 | hd->base_class.id = bc_storage_device; | |
121 | hd->sub_class.id = sc_sdev_floppy; | |
122 | hd->bus.id = bus_floppy; | |
123 | hd->slot = u; | |
124 | str_printf(&hd->unix_dev_name, 0, "/dev/fd%u", u); | |
125 | ||
126 | if(*b0) { | |
127 | res = add_res_entry(&hd->res, new_mem(sizeof *res)); | |
128 | res->size.type = res_size; | |
129 | res->size.val1 = str2float(b0, 2); | |
130 | res->size.unit = size_unit_cinch; | |
131 | } | |
132 | ||
133 | /* 'k' or 'M' */ | |
134 | i = c == 'M' ? str2float(b1, 3) : str2float(b1, 0); | |
135 | ||
136 | res = add_res_entry(&hd->res, new_mem(sizeof *res)); | |
137 | res->size.type = res_size; | |
138 | res->size.val1 = i << 1; | |
139 | res->size.val2 = 0x200; | |
140 | res->size.unit = size_unit_sectors; | |
141 | ||
142 | /* the only choice... */ | |
143 | if(floppy_ctrls == 1) hd->attached_to = floppy_ctrl_idx; | |
144 | } | |
145 | } | |
146 | } | |
147 | } | |
148 | ||
149 | ||
150 | /* | |
151 | * Add floppy data to the global log. | |
152 | */ | |
153 | void dump_floppy_data(hd_data_t *hd_data) | |
154 | { | |
155 | str_list_t *sl; | |
156 | ||
157 | ADD2LOG("----- /proc/nvram -----\n"); | |
158 | for(sl = hd_data->floppy; sl; sl = sl->next) { | |
159 | ADD2LOG(" %s", sl->str); | |
160 | } | |
161 | ADD2LOG("----- /proc/nvram end -----\n"); | |
162 | } |