4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * This file contains functions that implement the fdisk menu commands.
31 #include <sys/resource.h>
35 #include <sys/fcntl.h>
38 #include <sys/dklabel.h>
45 #include "menu_command.h"
46 #include "menu_defect.h"
47 #include "menu_partition.h"
48 #if defined(_FIRMWARE_NEEDS_FDISK)
49 #include "menu_fdisk.h"
50 #endif /* defined(_FIRMWARE_NEEDS_FDISK) */
55 #include "partition.h"
59 #include "ctlr_scsi.h"
60 #include "auto_sense.h"
64 * Local prototypes for ANSI C compilers
66 static int generic_ck_format(void);
67 static int generic_rdwr(int dir
, int fd
, diskaddr_t blkno
, int secnt
,
68 caddr_t bufaddr
, int flags
, int *xfercntp
);
71 static int generic_ck_format();
72 static int generic_rdwr();
76 struct ctlr_ops genericops
= {
88 * Check to see if the disk has been formatted.
89 * If we are able to read the first track, we conclude that
90 * the disk has been formatted.
98 * Try to read the first four blocks.
100 status
= generic_rdwr(DIR_READ
, cur_file
, 0, 4, (caddr_t
)cur_buf
,
106 * Read or write the disk.
107 * Temporary interface until IOCTL interface finished.
111 generic_rdwr(dir
, fd
, blkno
, secnt
, bufaddr
, flags
, xfercntp
)
121 offset_t tmpsec
, status
, tmpblk
;
124 tmpsec
= (offset_t
)secnt
* cur_blksz
;
125 tmpblk
= (offset_t
)blkno
* cur_blksz
;
127 #if defined(_FIRMWARE_NEEDS_FDISK)
128 /* Use "p0" file to seek/read the data */
129 (void) open_cur_file(FD_USE_P0_PATH
);
131 if (dir
== DIR_READ
) {
132 status
= llseek(fd
, tmpblk
, SEEK_SET
);
133 if (status
!= tmpblk
) {
138 status
= read(fd
, bufaddr
, (size_t)tmpsec
);
139 if (status
!= tmpsec
)
144 status
= llseek(fd
, tmpblk
, SEEK_SET
);
145 if (status
!= tmpblk
) {
150 status
= write(fd
, bufaddr
, (size_t)tmpsec
);
151 if (status
!= tmpsec
)
157 #if defined(_FIRMWARE_NEEDS_FDISK)
158 /* Restore cur_file with cur_disk->disk_path */
159 (void) open_cur_file(FD_USE_CUR_DISK_PATH
);