Lines Matching defs:wd
1 /* $NetBSD: wd.c,v 1.4 2019/01/08 19:41:09 jdolecek Exp $ */
50 static int wd_get_params(struct wd_softc *wd);
51 static int wdgetdisklabel(struct wd_softc *wd);
52 static void wdgetdefaultlabel(struct wd_softc *wd, struct disklabel *lp);
62 wd_get_params(struct wd_softc *wd)
67 if ((error = wdc_exec_identify(wd, buf)) != 0)
70 wd->sc_params = *(struct ataparams *)buf;
73 if ((wd->sc_params.atap_cmd2_en & ATA_CMD2_LBA48) != 0)
74 wd->sc_flags |= WDF_LBA48;
77 if ((wd->sc_params.atap_capabilities1 & WDC_CAP_LBA) != 0)
78 wd->sc_flags |= WDF_LBA;
80 if ((wd->sc_flags & WDF_LBA48) != 0) {
82 wd->sc_capacity =
83 ((uint64_t)wd->sc_params.atap_max_lba[3] << 48) |
84 ((uint64_t)wd->sc_params.atap_max_lba[2] << 32) |
85 ((uint64_t)wd->sc_params.atap_max_lba[1] << 16) |
86 ((uint64_t)wd->sc_params.atap_max_lba[0] << 0);
88 wd->sc_params.atap_max_lba[3],
89 wd->sc_params.atap_max_lba[2],
90 wd->sc_params.atap_max_lba[1],
91 wd->sc_params.atap_max_lba[0]));
92 wd->sc_capacity28 =
93 ((uint32_t)wd->sc_params.atap_capacity[1] << 16) |
94 ((uint32_t)wd->sc_params.atap_capacity[0] << 0);
96 wd->sc_params.atap_capacity[1],
97 wd->sc_params.atap_capacity[0]));
98 } else if ((wd->sc_flags & WDF_LBA) != 0) {
100 wd->sc_capacity =
101 ((uint32_t)wd->sc_params.atap_capacity[1] << 16) |
102 ((uint32_t)wd->sc_params.atap_capacity[0] << 0);
103 wd->sc_capacity28 =
104 ((uint32_t)wd->sc_params.atap_capacity[1] << 16) |
105 ((uint32_t)wd->sc_params.atap_capacity[0] << 0);
108 wd->sc_capacity = wd->sc_capacity28 =
109 wd->sc_params.atap_cylinders *
110 wd->sc_params.atap_heads *
111 wd->sc_params.atap_sectors;
113 DPRINTF(("wd->sc_capacity = %" PRId64 ", wd->sc_capacity28 = %d.\n",
114 wd->sc_capacity, wd->sc_capacity28));
123 wdgetdefaultlabel(struct wd_softc *wd, struct disklabel *lp)
129 lp->d_ntracks = wd->sc_params.atap_heads;
130 lp->d_nsectors = wd->sc_params.atap_sectors;
131 lp->d_ncylinders = wd->sc_params.atap_cylinders;
134 if (strcmp((const char *)wd->sc_params.atap_model, "ST506") == 0)
139 strncpy(lp->d_typename, (const char *)wd->sc_params.atap_model, 16);
141 if (wd->sc_capacity > UINT32_MAX)
144 lp->d_secperunit = wd->sc_capacity;
164 wdgetdisklabel(struct wd_softc *wd)
174 wdgetdefaultlabel(wd, &wd->sc_label);
180 if (wdstrategy(wd, F_READ, MBR_BBSECTOR, DEV_BSIZE, buf, &rsize))
198 if (wdstrategy(wd, F_READ, sector + LABELSECTOR, DEV_BSIZE,
202 msg = getdisklabel((const char *)buf + LABELOFFSET, &wd->sc_label);
205 (wd->sc_unit == 0) ? "master" : "slave", msg);
207 lp = &wd->sc_label;
210 if ((wd->sc_part >= lp->d_npartitions) ||
211 (lp->d_partitions[wd->sc_part].p_fstype == FS_UNUSED)) {
218 wd->sc_label.d_secsize,
219 wd->sc_label.d_nsectors,
220 wd->sc_label.d_ncylinders,
221 wd->sc_label.d_ntracks,
222 wd->sc_label.d_secpercyl));
236 struct wd_softc *wd;
250 wd = alloc(sizeof(struct wd_softc));
251 if (wd == NULL)
254 memset(wd, 0, sizeof(struct wd_softc));
256 wd->sc_part = part;
257 wd->sc_unit = unit;
258 wd->sc_ctlr = ctlr;
260 if ((error = wd_get_params(wd)) != 0)
263 if ((error = wdgetdisklabel(wd)) != 0)
266 f->f_devdata = wd;
288 struct wd_softc *wd;
299 wd = f;
300 pp = &wd->sc_label.d_partitions[wd->sc_part];
302 nsect = howmany(size, wd->sc_label.d_secsize);
310 if ((error = wdc_exec_read(wd, WDCC_READ, blkno, buf)) != 0)
313 buf += wd->sc_label.d_secsize;