Lines Matching defs:wd
1 /* $NetBSD: wd.c,v 1.18 2019/01/08 19:41:09 jdolecek Exp $ */
44 static int wd_get_params(struct wd_softc *wd);
45 static int wdgetdisklabel(struct wd_softc *wd);
46 static void wdgetdefaultlabel(struct wd_softc *wd, struct disklabel *lp);
52 wd_get_params(struct wd_softc *wd)
58 if ((error = wdc_exec_identify(wd, buf)) != 0)
61 wd->sc_params = *params;
64 if ((wd->sc_params.atap_cmd2_en & ATA_CMD2_LBA48) != 0)
65 wd->sc_flags |= WDF_LBA48;
68 if ((wd->sc_params.atap_capabilities1 & WDC_CAP_LBA) != 0)
69 wd->sc_flags |= WDF_LBA;
71 if ((wd->sc_flags & WDF_LBA48) != 0) {
73 wd->sc_capacity =
74 ((uint64_t)wd->sc_params.atap_max_lba[3] << 48) |
75 ((uint64_t)wd->sc_params.atap_max_lba[2] << 32) |
76 ((uint64_t)wd->sc_params.atap_max_lba[1] << 16) |
77 ((uint64_t)wd->sc_params.atap_max_lba[0] << 0);
79 wd->sc_params.atap_max_lba[3],
80 wd->sc_params.atap_max_lba[2],
81 wd->sc_params.atap_max_lba[1],
82 wd->sc_params.atap_max_lba[0]));
83 wd->sc_capacity28 =
84 ((uint32_t)wd->sc_params.atap_capacity[1] << 16) |
85 ((uint32_t)wd->sc_params.atap_capacity[0] << 0);
87 wd->sc_params.atap_capacity[1],
88 wd->sc_params.atap_capacity[0]));
89 } else if ((wd->sc_flags & WDF_LBA) != 0) {
91 wd->sc_capacity = wd->sc_capacity28 =
92 ((uint32_t)wd->sc_params.atap_capacity[1] << 16) |
93 ((uint32_t)wd->sc_params.atap_capacity[0] << 0);
96 wd->sc_capacity = wd->sc_capacity28 =
97 wd->sc_params.atap_cylinders *
98 wd->sc_params.atap_heads *
99 wd->sc_params.atap_sectors;
101 DPRINTF(("wd->sc_capacity = %" PRId64 ", wd->sc_capacity28 = %d.\n",
102 wd->sc_capacity, wd->sc_capacity28));
111 wdgetdefaultlabel(struct wd_softc *wd, struct disklabel *lp)
117 lp->d_ntracks = wd->sc_params.atap_heads;
118 lp->d_nsectors = wd->sc_params.atap_sectors;
119 lp->d_ncylinders = wd->sc_params.atap_cylinders;
122 if (strcmp(wd->sc_params.atap_model, "ST506") == 0)
127 strncpy(lp->d_typename, wd->sc_params.atap_model, 16);
129 if (wd->sc_capacity > UINT32_MAX)
132 lp->d_secperunit = wd->sc_capacity;
152 wdgetdisklabel(struct wd_softc *wd)
161 wdgetdefaultlabel(wd, &wd->sc_label);
167 if (wdstrategy(wd, F_READ, MBR_BBSECTOR, DEV_BSIZE, buf, &rsize))
188 if (wdstrategy(wd, F_READ, sector + LABELSECTOR, DEV_BSIZE,
192 if ((msg = getdisklabel(buf + LABELOFFSET, &wd->sc_label)))
193 printf("wd%d: getdisklabel: %s\n", wd->sc_unit, msg);
195 lp = &wd->sc_label;
198 if ((wd->sc_part >= lp->d_npartitions) ||
199 (lp->d_partitions[wd->sc_part].p_fstype == FS_UNUSED)) {
206 wd->sc_label.d_secsize,
207 wd->sc_label.d_nsectors,
208 wd->sc_label.d_ncylinders,
209 wd->sc_label.d_ntracks,
210 wd->sc_label.d_secpercyl));
224 struct wd_softc *wd;
233 wd = alloc(sizeof(struct wd_softc));
234 if (wd == NULL)
237 memset(wd, 0, sizeof(struct wd_softc));
239 if (wdc_init(wd, &unit) != 0)
242 wd->sc_part = part;
243 wd->sc_unit = unit;
245 if ((error = wd_get_params(wd)) != 0)
248 if ((error = wdgetdisklabel(wd)) != 0)
251 f->f_devdata = wd;
273 struct wd_softc *wd;
284 wd = f;
285 pp = &wd->sc_label.d_partitions[wd->sc_part];
287 nsect = howmany(size, wd->sc_label.d_secsize);
295 if ((error = wdc_exec_read(wd, WDCC_READ, blkno, buf)) != 0)
298 buf += wd->sc_label.d_secsize;