]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/hwinfo/src/hd/floppy.c
14 static void dump_floppy_data(hd_data_t
*hd_data
);
16 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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.)
23 * This is all rather strange and should be rewritten...
25 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
29 void hd_scan_floppy(hd_data_t
*hd_data
)
32 char b0
[10], b1
[10], c
;
34 int fd
, i
, floppy_ctrls
= 0, floppy_ctrl_idx
= 0;
37 int floppy_stat
[2] = { 1, 1 };
39 if(!hd_probe_feature(hd_data
, pr_floppy
)) return;
41 hd_data
->module
= mod_floppy
;
44 remove_hd_entries(hd_data
);
45 hd_data
->floppy
= free_str_list(hd_data
->floppy
);
47 PROGRESS(1, 0, "get nvram");
50 * Look for existing floppy controller entries (typically there will be
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
) {
56 floppy_ctrl_idx
= hd
->idx
;
61 * Is enough to load the nvram module.
63 * Note: although you must be root to access /dev/nvram, every
64 * user can read /proc/nvram.
66 fd
= open(DEV_NVRAM
, O_RDONLY
| O_NONBLOCK
);
67 if(fd
>= 0) close(fd
);
70 !(hd_data
->floppy
= read_file(PROC_NVRAM_24
, 0, 0)) &&
71 !(hd_data
->floppy
= read_file(PROC_NVRAM_22
, 0, 0))
74 if(hd_data
->floppy
&& (hd_data
->debug
& HD_DEB_FLOPPY
)) dump_floppy_data(hd_data
);
76 if(!hd_data
->klog
) read_klog(hd_data
);
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
) {
87 PROGRESS(2, 0, "nvram info");
91 PROGRESS(2, 0, "klog info");
95 for(; sl
; sl
= sl
->next
) {
97 i
= sscanf(sl
->str
, " Floppy %u type : %8[0-9.]'' %8[0-9.]%c", &u
, b0
, b1
, &c
) == 4;
100 i
= sscanf(sl
->str
, "<6>Floppy drive(s): fd%u is %8[0-9.]%c", &u
, b1
, &c
) == 3;
107 u
< sizeof floppy_stat
/ sizeof *floppy_stat
&&
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
;
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
;
124 str_printf(&hd
->unix_dev_name
, 0, "/dev/fd%u", u
);
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
;
134 i
= c
== 'M' ? str2float(b1
, 3) : str2float(b1
, 0);
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
;
142 /* the only choice... */
143 if(floppy_ctrls
== 1) hd
->attached_to
= floppy_ctrl_idx
;
151 * Add floppy data to the global log.
153 void dump_floppy_data(hd_data_t
*hd_data
)
157 ADD2LOG("----- /proc/nvram -----\n");
158 for(sl
= hd_data
->floppy
; sl
; sl
= sl
->next
) {
159 ADD2LOG(" %s", sl
->str
);
161 ADD2LOG("----- /proc/nvram end -----\n");