17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5342440ecSPrasad Singamsetty * Common Development and Distribution License (the "License").
6342440ecSPrasad Singamsetty * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22*65908c77Syu, larry liu - Sun Microsystems - Beijing China * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
233e1bd7a2Ssjelinek * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate * This file contains functions that implement the fdisk menu commands.
287c478bd9Sstevel@tonic-gate */
297c478bd9Sstevel@tonic-gate #include "global.h"
307c478bd9Sstevel@tonic-gate #include <sys/time.h>
317c478bd9Sstevel@tonic-gate #include <sys/resource.h>
327c478bd9Sstevel@tonic-gate #include <sys/wait.h>
337c478bd9Sstevel@tonic-gate #include <signal.h>
347c478bd9Sstevel@tonic-gate #include <string.h>
357c478bd9Sstevel@tonic-gate #include <sys/fcntl.h>
367c478bd9Sstevel@tonic-gate #include <sys/stat.h>
377c478bd9Sstevel@tonic-gate
387c478bd9Sstevel@tonic-gate #include <sys/dklabel.h>
397c478bd9Sstevel@tonic-gate #include <errno.h>
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate #include "main.h"
437c478bd9Sstevel@tonic-gate #include "analyze.h"
447c478bd9Sstevel@tonic-gate #include "menu.h"
457c478bd9Sstevel@tonic-gate #include "menu_command.h"
467c478bd9Sstevel@tonic-gate #include "menu_defect.h"
477c478bd9Sstevel@tonic-gate #include "menu_partition.h"
487c478bd9Sstevel@tonic-gate #if defined(_FIRMWARE_NEEDS_FDISK)
497c478bd9Sstevel@tonic-gate #include "menu_fdisk.h"
507c478bd9Sstevel@tonic-gate #endif /* defined(_FIRMWARE_NEEDS_FDISK) */
517c478bd9Sstevel@tonic-gate #include "param.h"
527c478bd9Sstevel@tonic-gate #include "misc.h"
537c478bd9Sstevel@tonic-gate #include "label.h"
547c478bd9Sstevel@tonic-gate #include "startup.h"
557c478bd9Sstevel@tonic-gate #include "partition.h"
567c478bd9Sstevel@tonic-gate #include "prompts.h"
573e1bd7a2Ssjelinek #include "checkdev.h"
587c478bd9Sstevel@tonic-gate #include "io.h"
597c478bd9Sstevel@tonic-gate #include "ctlr_scsi.h"
607c478bd9Sstevel@tonic-gate #include "auto_sense.h"
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gate #ifdef __STDC__
637c478bd9Sstevel@tonic-gate /*
647c478bd9Sstevel@tonic-gate * Local prototypes for ANSI C compilers
657c478bd9Sstevel@tonic-gate */
667c478bd9Sstevel@tonic-gate static int generic_ck_format(void);
67342440ecSPrasad Singamsetty static int generic_rdwr(int dir, int fd, diskaddr_t blkno, int secnt,
687c478bd9Sstevel@tonic-gate caddr_t bufaddr, int flags, int *xfercntp);
697c478bd9Sstevel@tonic-gate #else /* __STDC__ */
707c478bd9Sstevel@tonic-gate
717c478bd9Sstevel@tonic-gate static int generic_ck_format();
727c478bd9Sstevel@tonic-gate static int generic_rdwr();
737c478bd9Sstevel@tonic-gate
747c478bd9Sstevel@tonic-gate #endif /* __STDC__ */
757c478bd9Sstevel@tonic-gate
767c478bd9Sstevel@tonic-gate struct ctlr_ops genericops = {
777c478bd9Sstevel@tonic-gate generic_rdwr,
787c478bd9Sstevel@tonic-gate generic_ck_format,
797c478bd9Sstevel@tonic-gate 0,
807c478bd9Sstevel@tonic-gate 0,
817c478bd9Sstevel@tonic-gate 0,
827c478bd9Sstevel@tonic-gate 0,
837c478bd9Sstevel@tonic-gate 0,
847c478bd9Sstevel@tonic-gate };
857c478bd9Sstevel@tonic-gate
867c478bd9Sstevel@tonic-gate
877c478bd9Sstevel@tonic-gate /*
887c478bd9Sstevel@tonic-gate * Check to see if the disk has been formatted.
897c478bd9Sstevel@tonic-gate * If we are able to read the first track, we conclude that
907c478bd9Sstevel@tonic-gate * the disk has been formatted.
917c478bd9Sstevel@tonic-gate */
927c478bd9Sstevel@tonic-gate static int
generic_ck_format()937c478bd9Sstevel@tonic-gate generic_ck_format()
947c478bd9Sstevel@tonic-gate {
957c478bd9Sstevel@tonic-gate int status;
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gate /*
987c478bd9Sstevel@tonic-gate * Try to read the first four blocks.
997c478bd9Sstevel@tonic-gate */
1007c478bd9Sstevel@tonic-gate status = generic_rdwr(DIR_READ, cur_file, 0, 4, (caddr_t)cur_buf,
1017c478bd9Sstevel@tonic-gate F_SILENT, NULL);
1027c478bd9Sstevel@tonic-gate return (!status);
1037c478bd9Sstevel@tonic-gate }
1047c478bd9Sstevel@tonic-gate
1057c478bd9Sstevel@tonic-gate /*
1067c478bd9Sstevel@tonic-gate * Read or write the disk.
1077c478bd9Sstevel@tonic-gate * Temporary interface until IOCTL interface finished.
1087c478bd9Sstevel@tonic-gate */
1097c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1107c478bd9Sstevel@tonic-gate static int
generic_rdwr(dir,fd,blkno,secnt,bufaddr,flags,xfercntp)1117c478bd9Sstevel@tonic-gate generic_rdwr(dir, fd, blkno, secnt, bufaddr, flags, xfercntp)
1127c478bd9Sstevel@tonic-gate int dir;
1137c478bd9Sstevel@tonic-gate int fd;
114342440ecSPrasad Singamsetty diskaddr_t blkno;
1157c478bd9Sstevel@tonic-gate int secnt;
1167c478bd9Sstevel@tonic-gate caddr_t bufaddr;
1177c478bd9Sstevel@tonic-gate int flags;
1187c478bd9Sstevel@tonic-gate int *xfercntp;
1197c478bd9Sstevel@tonic-gate {
1207c478bd9Sstevel@tonic-gate
121342440ecSPrasad Singamsetty offset_t tmpsec, status, tmpblk;
122342440ecSPrasad Singamsetty int ret;
1237c478bd9Sstevel@tonic-gate
124*65908c77Syu, larry liu - Sun Microsystems - Beijing China tmpsec = (offset_t)secnt * cur_blksz;
125*65908c77Syu, larry liu - Sun Microsystems - Beijing China tmpblk = (offset_t)blkno * cur_blksz;
1267c478bd9Sstevel@tonic-gate
127342440ecSPrasad Singamsetty #if defined(_FIRMWARE_NEEDS_FDISK)
128342440ecSPrasad Singamsetty /* Use "p0" file to seek/read the data */
129342440ecSPrasad Singamsetty (void) open_cur_file(FD_USE_P0_PATH);
130342440ecSPrasad Singamsetty #endif
1317c478bd9Sstevel@tonic-gate if (dir == DIR_READ) {
132342440ecSPrasad Singamsetty status = llseek(fd, tmpblk, SEEK_SET);
133342440ecSPrasad Singamsetty if (status != tmpblk) {
134342440ecSPrasad Singamsetty ret = (int)status;
135342440ecSPrasad Singamsetty goto out;
1367c478bd9Sstevel@tonic-gate }
137342440ecSPrasad Singamsetty
138342440ecSPrasad Singamsetty status = read(fd, bufaddr, (size_t)tmpsec);
139342440ecSPrasad Singamsetty if (status != tmpsec)
140342440ecSPrasad Singamsetty ret = (int)tmpsec;
141342440ecSPrasad Singamsetty else
142342440ecSPrasad Singamsetty ret = 0;
143342440ecSPrasad Singamsetty } else {
144342440ecSPrasad Singamsetty status = llseek(fd, tmpblk, SEEK_SET);
145342440ecSPrasad Singamsetty if (status != tmpblk) {
146342440ecSPrasad Singamsetty ret = (int)status;
147342440ecSPrasad Singamsetty goto out;
148342440ecSPrasad Singamsetty }
149342440ecSPrasad Singamsetty
150342440ecSPrasad Singamsetty status = write(fd, bufaddr, (size_t)tmpsec);
151342440ecSPrasad Singamsetty if (status != tmpsec)
152342440ecSPrasad Singamsetty ret = (int)tmpsec;
153342440ecSPrasad Singamsetty else
154342440ecSPrasad Singamsetty ret = 0;
155342440ecSPrasad Singamsetty }
156342440ecSPrasad Singamsetty out:
157342440ecSPrasad Singamsetty #if defined(_FIRMWARE_NEEDS_FDISK)
158342440ecSPrasad Singamsetty /* Restore cur_file with cur_disk->disk_path */
159342440ecSPrasad Singamsetty (void) open_cur_file(FD_USE_CUR_DISK_PATH);
160342440ecSPrasad Singamsetty #endif
161342440ecSPrasad Singamsetty return (ret);
1627c478bd9Sstevel@tonic-gate }
163