xref: /illumos-gate/usr/src/cmd/format/menu_cache.c (revision b12aaafbf56c5a06b6cfd21655531a33e38a8ed9)
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
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate 
237c478bd9Sstevel@tonic-gate /*
243e1bd7a2Ssjelinek  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
253e1bd7a2Ssjelinek  * Use is subject to license terms.
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate  * This file contains functions that implement the cache menu commands.
307c478bd9Sstevel@tonic-gate  */
317c478bd9Sstevel@tonic-gate #include "global.h"
327c478bd9Sstevel@tonic-gate #include <sys/time.h>
337c478bd9Sstevel@tonic-gate #include <sys/resource.h>
347c478bd9Sstevel@tonic-gate #include <sys/wait.h>
357c478bd9Sstevel@tonic-gate #include <signal.h>
367c478bd9Sstevel@tonic-gate #include <string.h>
377c478bd9Sstevel@tonic-gate #include <sys/fcntl.h>
387c478bd9Sstevel@tonic-gate #include <sys/stat.h>
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #include <sys/dklabel.h>
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_cache.h"
467c478bd9Sstevel@tonic-gate #include "param.h"
477c478bd9Sstevel@tonic-gate #include "misc.h"
487c478bd9Sstevel@tonic-gate #include "label.h"
497c478bd9Sstevel@tonic-gate #include "startup.h"
507c478bd9Sstevel@tonic-gate #include "partition.h"
517c478bd9Sstevel@tonic-gate #include "prompts.h"
523e1bd7a2Ssjelinek #include "checkdev.h"
537c478bd9Sstevel@tonic-gate #include "io.h"
547c478bd9Sstevel@tonic-gate #include "ctlr_scsi.h"
557c478bd9Sstevel@tonic-gate #include "auto_sense.h"
567c478bd9Sstevel@tonic-gate #include "hardware_structs.h"
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate extern	struct menu_item menu_cache[];
597c478bd9Sstevel@tonic-gate extern	struct menu_item menu_write_cache[];
607c478bd9Sstevel@tonic-gate extern	struct menu_item menu_read_cache[];
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate int
c_cache(void)64*b12aaafbSToomas Soome c_cache(void)
657c478bd9Sstevel@tonic-gate {
667c478bd9Sstevel@tonic-gate 	cur_menu++;
677c478bd9Sstevel@tonic-gate 	last_menu = cur_menu;
687c478bd9Sstevel@tonic-gate 	run_menu(menu_cache, "CACHE", "cache", 0);
697c478bd9Sstevel@tonic-gate 	cur_menu--;
707c478bd9Sstevel@tonic-gate 	return (0);
717c478bd9Sstevel@tonic-gate }
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate int
ca_write_cache(void)74*b12aaafbSToomas Soome ca_write_cache(void)
757c478bd9Sstevel@tonic-gate {
767c478bd9Sstevel@tonic-gate 	cur_menu++;
777c478bd9Sstevel@tonic-gate 	last_menu = cur_menu;
787c478bd9Sstevel@tonic-gate 	run_menu(menu_write_cache, "WRITE_CACHE", "write_cache", 0);
797c478bd9Sstevel@tonic-gate 	cur_menu--;
807c478bd9Sstevel@tonic-gate 	return (0);
817c478bd9Sstevel@tonic-gate }
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate int
ca_read_cache(void)84*b12aaafbSToomas Soome ca_read_cache(void)
857c478bd9Sstevel@tonic-gate {
867c478bd9Sstevel@tonic-gate 	cur_menu++;
877c478bd9Sstevel@tonic-gate 	last_menu = cur_menu;
887c478bd9Sstevel@tonic-gate 	run_menu(menu_read_cache, "READ_CACHE", "read_cache", 0);
897c478bd9Sstevel@tonic-gate 	cur_menu--;
907c478bd9Sstevel@tonic-gate 	return (0);
917c478bd9Sstevel@tonic-gate }
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate int
ca_write_display(void)94*b12aaafbSToomas Soome ca_write_display(void)
957c478bd9Sstevel@tonic-gate {
967c478bd9Sstevel@tonic-gate 	struct mode_cache		*page8;
977c478bd9Sstevel@tonic-gate 	struct scsi_ms_header		header;
987c478bd9Sstevel@tonic-gate 	int				status;
997c478bd9Sstevel@tonic-gate 	union {
1007c478bd9Sstevel@tonic-gate 		struct mode_cache	page8;
1017c478bd9Sstevel@tonic-gate 		char			rawbuf[MAX_MODE_SENSE_SIZE];
1027c478bd9Sstevel@tonic-gate 	} u_page8;
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate 	page8 = &u_page8.page8;
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate 	status = uscsi_mode_sense(cur_file, DAD_MODE_CACHE,
1077c478bd9Sstevel@tonic-gate 	    MODE_SENSE_PC_CURRENT, (caddr_t)page8,
1087c478bd9Sstevel@tonic-gate 	    MAX_MODE_SENSE_SIZE, &header);
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate 	if (status == 0) {
1117c478bd9Sstevel@tonic-gate 		if (page8->wce) {
1127c478bd9Sstevel@tonic-gate 			fmt_print("Write Cache is enabled\n");
1137c478bd9Sstevel@tonic-gate 		} else {
1147c478bd9Sstevel@tonic-gate 			fmt_print("Write Cache is disabled\n");
1157c478bd9Sstevel@tonic-gate 		}
1167c478bd9Sstevel@tonic-gate 	} else {
1177c478bd9Sstevel@tonic-gate 		err_print("Mode sense failed.\n");
1187c478bd9Sstevel@tonic-gate 	}
1197c478bd9Sstevel@tonic-gate 	return (0);
1207c478bd9Sstevel@tonic-gate }
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate int
ca_write_enable(void)123*b12aaafbSToomas Soome ca_write_enable(void)
1247c478bd9Sstevel@tonic-gate {
1257c478bd9Sstevel@tonic-gate 	struct mode_cache		*page8;
1267c478bd9Sstevel@tonic-gate 	struct scsi_ms_header		header;
1277c478bd9Sstevel@tonic-gate 	int				status;
1287c478bd9Sstevel@tonic-gate 	int				length;
1297c478bd9Sstevel@tonic-gate 	int				sp_flags;
1307c478bd9Sstevel@tonic-gate 	union {
1317c478bd9Sstevel@tonic-gate 		struct mode_cache	page8;
1327c478bd9Sstevel@tonic-gate 		char			rawbuf[MAX_MODE_SENSE_SIZE];
1337c478bd9Sstevel@tonic-gate 	} u_page8;
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate 	page8 = &u_page8.page8;
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate 	status = uscsi_mode_sense(cur_file, DAD_MODE_CACHE,
1387c478bd9Sstevel@tonic-gate 	    MODE_SENSE_PC_CHANGEABLE, (caddr_t)page8,
1397c478bd9Sstevel@tonic-gate 	    MAX_MODE_SENSE_SIZE, &header);
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate 	if (status == 0) {
1427c478bd9Sstevel@tonic-gate 		if (page8->wce) {
1437c478bd9Sstevel@tonic-gate 			status = uscsi_mode_sense(cur_file, DAD_MODE_CACHE,
1447c478bd9Sstevel@tonic-gate 			    MODE_SENSE_PC_SAVED, (caddr_t)page8,
1457c478bd9Sstevel@tonic-gate 			    MAX_MODE_SENSE_SIZE, &header);
1467c478bd9Sstevel@tonic-gate 			if (status != 0) {
1477c478bd9Sstevel@tonic-gate 				status = uscsi_mode_sense(cur_file,
1487c478bd9Sstevel@tonic-gate 				    DAD_MODE_CACHE, MODE_SENSE_PC_CURRENT,
149*b12aaafbSToomas Soome 				    (caddr_t)page8, MAX_MODE_SENSE_SIZE,
150*b12aaafbSToomas Soome 				    &header);
1517c478bd9Sstevel@tonic-gate 			}
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate 			if (status == 0) {
1547c478bd9Sstevel@tonic-gate 				length = MODESENSE_PAGE_LEN(page8);
1557c478bd9Sstevel@tonic-gate 				sp_flags = MODE_SELECT_PF;
1567c478bd9Sstevel@tonic-gate 				if (page8->mode_page.ps) {
1577c478bd9Sstevel@tonic-gate 					sp_flags |= MODE_SELECT_SP;
1587c478bd9Sstevel@tonic-gate 				} else {
1597c478bd9Sstevel@tonic-gate 					err_print("\
1607c478bd9Sstevel@tonic-gate This setting is valid until next reset only. It is not saved permanently.\n");
1617c478bd9Sstevel@tonic-gate 				}
1627c478bd9Sstevel@tonic-gate 				page8->mode_page.ps = 0;
1637c478bd9Sstevel@tonic-gate 				page8->wce = 1;
1647c478bd9Sstevel@tonic-gate 				header.mode_header.length = 0;
1657c478bd9Sstevel@tonic-gate 				header.mode_header.device_specific = 0;
1667c478bd9Sstevel@tonic-gate 				status = uscsi_mode_select(cur_file,
1677c478bd9Sstevel@tonic-gate 				    DAD_MODE_CACHE, sp_flags,
1687c478bd9Sstevel@tonic-gate 				    (caddr_t)page8, length, &header);
1697c478bd9Sstevel@tonic-gate 				if (status != 0) {
1707c478bd9Sstevel@tonic-gate 					err_print("Mode select failed\n");
1717c478bd9Sstevel@tonic-gate 					return (0);
1727c478bd9Sstevel@tonic-gate 				}
1737c478bd9Sstevel@tonic-gate 			}
1747c478bd9Sstevel@tonic-gate 		} else {
1757c478bd9Sstevel@tonic-gate 			err_print("Write cache setting is not changeable\n");
1767c478bd9Sstevel@tonic-gate 		}
1777c478bd9Sstevel@tonic-gate 	}
1787c478bd9Sstevel@tonic-gate 	if (status != 0) {
1797c478bd9Sstevel@tonic-gate 		err_print("Mode sense failed.\n");
1807c478bd9Sstevel@tonic-gate 	}
1817c478bd9Sstevel@tonic-gate 	return (0);
1827c478bd9Sstevel@tonic-gate }
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate int
ca_write_disable(void)185*b12aaafbSToomas Soome ca_write_disable(void)
1867c478bd9Sstevel@tonic-gate {
1877c478bd9Sstevel@tonic-gate 	struct mode_cache		*page8;
1887c478bd9Sstevel@tonic-gate 	struct scsi_ms_header		header;
1897c478bd9Sstevel@tonic-gate 	int				status;
1907c478bd9Sstevel@tonic-gate 	int				length;
1917c478bd9Sstevel@tonic-gate 	int				sp_flags;
1927c478bd9Sstevel@tonic-gate 	union {
1937c478bd9Sstevel@tonic-gate 		struct mode_cache	page8;
1947c478bd9Sstevel@tonic-gate 		char			rawbuf[MAX_MODE_SENSE_SIZE];
1957c478bd9Sstevel@tonic-gate 	} u_page8;
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate 	page8 = &u_page8.page8;
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate 	status = uscsi_mode_sense(cur_file, DAD_MODE_CACHE,
2007c478bd9Sstevel@tonic-gate 	    MODE_SENSE_PC_CHANGEABLE, (caddr_t)page8,
2017c478bd9Sstevel@tonic-gate 	    MAX_MODE_SENSE_SIZE, &header);
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate 	if (status == 0) {
2047c478bd9Sstevel@tonic-gate 		if (page8->wce) {
2057c478bd9Sstevel@tonic-gate 			status = uscsi_mode_sense(cur_file, DAD_MODE_CACHE,
2067c478bd9Sstevel@tonic-gate 			    MODE_SENSE_PC_SAVED, (caddr_t)page8,
2077c478bd9Sstevel@tonic-gate 			    MAX_MODE_SENSE_SIZE, &header);
2087c478bd9Sstevel@tonic-gate 			if (status != 0) {
2097c478bd9Sstevel@tonic-gate 				status = uscsi_mode_sense(cur_file,
2107c478bd9Sstevel@tonic-gate 				    DAD_MODE_CACHE, MODE_SENSE_PC_CURRENT,
211*b12aaafbSToomas Soome 				    (caddr_t)page8, MAX_MODE_SENSE_SIZE,
212*b12aaafbSToomas Soome 				    &header);
2137c478bd9Sstevel@tonic-gate 			}
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate 			if (status == 0) {
2167c478bd9Sstevel@tonic-gate 				length = MODESENSE_PAGE_LEN(page8);
2177c478bd9Sstevel@tonic-gate 				sp_flags = MODE_SELECT_PF;
2187c478bd9Sstevel@tonic-gate 				if (page8->mode_page.ps) {
2197c478bd9Sstevel@tonic-gate 					sp_flags |= MODE_SELECT_SP;
2207c478bd9Sstevel@tonic-gate 				} else {
2217c478bd9Sstevel@tonic-gate 					err_print("\
2227c478bd9Sstevel@tonic-gate This setting is valid until next reset only. It is not saved permanently.\n");
2237c478bd9Sstevel@tonic-gate 				}
2247c478bd9Sstevel@tonic-gate 				page8->mode_page.ps = 0;
2257c478bd9Sstevel@tonic-gate 				page8->wce = 0;
2267c478bd9Sstevel@tonic-gate 				header.mode_header.length = 0;
2277c478bd9Sstevel@tonic-gate 				header.mode_header.device_specific = 0;
2287c478bd9Sstevel@tonic-gate 				status = uscsi_mode_select(cur_file,
2297c478bd9Sstevel@tonic-gate 				    DAD_MODE_CACHE, sp_flags,
2307c478bd9Sstevel@tonic-gate 				    (caddr_t)page8, length, &header);
2317c478bd9Sstevel@tonic-gate 				if (status != 0) {
2327c478bd9Sstevel@tonic-gate 					err_print("Mode select failed\n");
2337c478bd9Sstevel@tonic-gate 					return (0);
2347c478bd9Sstevel@tonic-gate 				}
2357c478bd9Sstevel@tonic-gate 			}
2367c478bd9Sstevel@tonic-gate 		} else {
2377c478bd9Sstevel@tonic-gate 			err_print("Write cache setting is not changeable\n");
2387c478bd9Sstevel@tonic-gate 		}
2397c478bd9Sstevel@tonic-gate 	}
2407c478bd9Sstevel@tonic-gate 	if (status != 0) {
2417c478bd9Sstevel@tonic-gate 		err_print("Mode sense failed.\n");
2427c478bd9Sstevel@tonic-gate 	}
2437c478bd9Sstevel@tonic-gate 	return (0);
2447c478bd9Sstevel@tonic-gate }
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate int
ca_read_display(void)247*b12aaafbSToomas Soome ca_read_display(void)
2487c478bd9Sstevel@tonic-gate {
2497c478bd9Sstevel@tonic-gate 	struct mode_cache		*page8;
2507c478bd9Sstevel@tonic-gate 	struct scsi_ms_header		header;
2517c478bd9Sstevel@tonic-gate 	int				status;
2527c478bd9Sstevel@tonic-gate 	union {
2537c478bd9Sstevel@tonic-gate 		struct mode_cache	page8;
2547c478bd9Sstevel@tonic-gate 		char			rawbuf[MAX_MODE_SENSE_SIZE];
2557c478bd9Sstevel@tonic-gate 	} u_page8;
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate 	page8 = &u_page8.page8;
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate 	status = uscsi_mode_sense(cur_file, DAD_MODE_CACHE,
2607c478bd9Sstevel@tonic-gate 	    MODE_SENSE_PC_CURRENT, (caddr_t)page8,
2617c478bd9Sstevel@tonic-gate 	    MAX_MODE_SENSE_SIZE, &header);
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate 	if (status == 0) {
2647c478bd9Sstevel@tonic-gate 		if (page8->rcd) {
2657c478bd9Sstevel@tonic-gate 			fmt_print("Read Cache is disabled\n");
2667c478bd9Sstevel@tonic-gate 		} else {
2677c478bd9Sstevel@tonic-gate 			fmt_print("Read Cache is enabled\n");
2687c478bd9Sstevel@tonic-gate 		}
2697c478bd9Sstevel@tonic-gate 	} else {
2707c478bd9Sstevel@tonic-gate 		err_print("Mode sense failed.\n");
2717c478bd9Sstevel@tonic-gate 	}
2727c478bd9Sstevel@tonic-gate 	return (0);
2737c478bd9Sstevel@tonic-gate }
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate int
ca_read_enable(void)276*b12aaafbSToomas Soome ca_read_enable(void)
2777c478bd9Sstevel@tonic-gate {
2787c478bd9Sstevel@tonic-gate 	struct mode_cache		*page8;
2797c478bd9Sstevel@tonic-gate 	struct scsi_ms_header		header;
2807c478bd9Sstevel@tonic-gate 	int				status;
2817c478bd9Sstevel@tonic-gate 	int				length;
2827c478bd9Sstevel@tonic-gate 	int				sp_flags;
2837c478bd9Sstevel@tonic-gate 	union {
2847c478bd9Sstevel@tonic-gate 		struct mode_cache	page8;
2857c478bd9Sstevel@tonic-gate 		char			rawbuf[MAX_MODE_SENSE_SIZE];
2867c478bd9Sstevel@tonic-gate 	} u_page8;
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate 	page8 = &u_page8.page8;
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate 	status = uscsi_mode_sense(cur_file, DAD_MODE_CACHE,
2917c478bd9Sstevel@tonic-gate 	    MODE_SENSE_PC_CHANGEABLE, (caddr_t)page8,
2927c478bd9Sstevel@tonic-gate 	    MAX_MODE_SENSE_SIZE, &header);
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate 	if (status == 0) {
2957c478bd9Sstevel@tonic-gate 		if (page8->rcd) {
2967c478bd9Sstevel@tonic-gate 			status = uscsi_mode_sense(cur_file, DAD_MODE_CACHE,
2977c478bd9Sstevel@tonic-gate 			    MODE_SENSE_PC_SAVED, (caddr_t)page8,
2987c478bd9Sstevel@tonic-gate 			    MAX_MODE_SENSE_SIZE, &header);
2997c478bd9Sstevel@tonic-gate 			if (status != 0) {
3007c478bd9Sstevel@tonic-gate 				status = uscsi_mode_sense(cur_file,
3017c478bd9Sstevel@tonic-gate 				    DAD_MODE_CACHE, MODE_SENSE_PC_CURRENT,
302*b12aaafbSToomas Soome 				    (caddr_t)page8, MAX_MODE_SENSE_SIZE,
303*b12aaafbSToomas Soome 				    &header);
3047c478bd9Sstevel@tonic-gate 			}
3057c478bd9Sstevel@tonic-gate 
3067c478bd9Sstevel@tonic-gate 			if (status == 0) {
3077c478bd9Sstevel@tonic-gate 				length = MODESENSE_PAGE_LEN(page8);
3087c478bd9Sstevel@tonic-gate 				sp_flags = MODE_SELECT_PF;
3097c478bd9Sstevel@tonic-gate 				if (page8->mode_page.ps) {
3107c478bd9Sstevel@tonic-gate 					sp_flags |= MODE_SELECT_SP;
3117c478bd9Sstevel@tonic-gate 				} else {
3127c478bd9Sstevel@tonic-gate 					err_print("\
3137c478bd9Sstevel@tonic-gate This setting is valid until next reset only. It is not saved permanently.\n");
3147c478bd9Sstevel@tonic-gate 				}
3157c478bd9Sstevel@tonic-gate 				page8->mode_page.ps = 0;
3167c478bd9Sstevel@tonic-gate 				page8->rcd = 0;
3177c478bd9Sstevel@tonic-gate 				header.mode_header.length = 0;
3187c478bd9Sstevel@tonic-gate 				header.mode_header.device_specific = 0;
3197c478bd9Sstevel@tonic-gate 				status = uscsi_mode_select(cur_file,
3207c478bd9Sstevel@tonic-gate 				    DAD_MODE_CACHE, sp_flags,
3217c478bd9Sstevel@tonic-gate 				    (caddr_t)page8, length, &header);
3227c478bd9Sstevel@tonic-gate 				if (status != 0) {
3237c478bd9Sstevel@tonic-gate 					err_print("Mode select failed\n");
3247c478bd9Sstevel@tonic-gate 					return (0);
3257c478bd9Sstevel@tonic-gate 				}
3267c478bd9Sstevel@tonic-gate 			}
3277c478bd9Sstevel@tonic-gate 		} else {
3287c478bd9Sstevel@tonic-gate 			err_print("Read cache setting is not changeable\n");
3297c478bd9Sstevel@tonic-gate 		}
3307c478bd9Sstevel@tonic-gate 	}
3317c478bd9Sstevel@tonic-gate 	if (status != 0) {
3327c478bd9Sstevel@tonic-gate 		err_print("Mode sense failed.\n");
3337c478bd9Sstevel@tonic-gate 	}
3347c478bd9Sstevel@tonic-gate 	return (0);
3357c478bd9Sstevel@tonic-gate }
3367c478bd9Sstevel@tonic-gate 
3377c478bd9Sstevel@tonic-gate int
ca_read_disable(void)338*b12aaafbSToomas Soome ca_read_disable(void)
3397c478bd9Sstevel@tonic-gate {
3407c478bd9Sstevel@tonic-gate 	struct mode_cache		*page8;
3417c478bd9Sstevel@tonic-gate 	struct scsi_ms_header		header;
3427c478bd9Sstevel@tonic-gate 	int				status;
3437c478bd9Sstevel@tonic-gate 	int				length;
3447c478bd9Sstevel@tonic-gate 	int				sp_flags;
3457c478bd9Sstevel@tonic-gate 	union {
3467c478bd9Sstevel@tonic-gate 		struct mode_cache	page8;
3477c478bd9Sstevel@tonic-gate 		char			rawbuf[MAX_MODE_SENSE_SIZE];
3487c478bd9Sstevel@tonic-gate 	} u_page8;
3497c478bd9Sstevel@tonic-gate 
3507c478bd9Sstevel@tonic-gate 	page8 = &u_page8.page8;
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate 	status = uscsi_mode_sense(cur_file, DAD_MODE_CACHE,
3537c478bd9Sstevel@tonic-gate 	    MODE_SENSE_PC_CHANGEABLE, (caddr_t)page8,
3547c478bd9Sstevel@tonic-gate 	    MAX_MODE_SENSE_SIZE, &header);
3557c478bd9Sstevel@tonic-gate 
3567c478bd9Sstevel@tonic-gate 	if (status == 0) {
3577c478bd9Sstevel@tonic-gate 		if (page8->rcd) {
3587c478bd9Sstevel@tonic-gate 			status = uscsi_mode_sense(cur_file, DAD_MODE_CACHE,
3597c478bd9Sstevel@tonic-gate 			    MODE_SENSE_PC_SAVED, (caddr_t)page8,
3607c478bd9Sstevel@tonic-gate 			    MAX_MODE_SENSE_SIZE, &header);
3617c478bd9Sstevel@tonic-gate 			if (status != 0) {
3627c478bd9Sstevel@tonic-gate 				status = uscsi_mode_sense(cur_file,
3637c478bd9Sstevel@tonic-gate 				    DAD_MODE_CACHE, MODE_SENSE_PC_CURRENT,
364*b12aaafbSToomas Soome 				    (caddr_t)page8, MAX_MODE_SENSE_SIZE,
365*b12aaafbSToomas Soome 				    &header);
3667c478bd9Sstevel@tonic-gate 			}
3677c478bd9Sstevel@tonic-gate 
3687c478bd9Sstevel@tonic-gate 			if (status == 0) {
3697c478bd9Sstevel@tonic-gate 				length = MODESENSE_PAGE_LEN(page8);
3707c478bd9Sstevel@tonic-gate 				sp_flags = MODE_SELECT_PF;
3717c478bd9Sstevel@tonic-gate 				if (page8->mode_page.ps) {
3727c478bd9Sstevel@tonic-gate 					sp_flags |= MODE_SELECT_SP;
3737c478bd9Sstevel@tonic-gate 				} else {
3747c478bd9Sstevel@tonic-gate 					err_print("\
3757c478bd9Sstevel@tonic-gate This setting is valid until next reset only. It is not saved permanently.\n");
3767c478bd9Sstevel@tonic-gate 				}
3777c478bd9Sstevel@tonic-gate 				page8->mode_page.ps = 0;
3787c478bd9Sstevel@tonic-gate 				page8->rcd = 1;
3797c478bd9Sstevel@tonic-gate 				header.mode_header.length = 0;
3807c478bd9Sstevel@tonic-gate 				header.mode_header.device_specific = 0;
3817c478bd9Sstevel@tonic-gate 				status = uscsi_mode_select(cur_file,
3827c478bd9Sstevel@tonic-gate 				    DAD_MODE_CACHE, sp_flags,
3837c478bd9Sstevel@tonic-gate 				    (caddr_t)page8, length, &header);
3847c478bd9Sstevel@tonic-gate 				if (status != 0) {
3857c478bd9Sstevel@tonic-gate 					err_print("Mode select failed\n");
3867c478bd9Sstevel@tonic-gate 					return (0);
3877c478bd9Sstevel@tonic-gate 				}
3887c478bd9Sstevel@tonic-gate 			}
3897c478bd9Sstevel@tonic-gate 		} else {
3907c478bd9Sstevel@tonic-gate 			err_print("Read cache setting is not changeable\n");
3917c478bd9Sstevel@tonic-gate 		}
3927c478bd9Sstevel@tonic-gate 	}
3937c478bd9Sstevel@tonic-gate 	if (status != 0) {
3947c478bd9Sstevel@tonic-gate 		err_print("Mode sense failed.\n");
3957c478bd9Sstevel@tonic-gate 	}
3967c478bd9Sstevel@tonic-gate 	return (0);
3977c478bd9Sstevel@tonic-gate }
398