1*83c4dfe9Sjg /* 2*83c4dfe9Sjg * CDDL HEADER START 3*83c4dfe9Sjg * 4*83c4dfe9Sjg * The contents of this file are subject to the terms of the 5*83c4dfe9Sjg * Common Development and Distribution License (the "License"). 6*83c4dfe9Sjg * You may not use this file except in compliance with the License. 7*83c4dfe9Sjg * 8*83c4dfe9Sjg * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*83c4dfe9Sjg * or http://www.opensolaris.org/os/licensing. 10*83c4dfe9Sjg * See the License for the specific language governing permissions 11*83c4dfe9Sjg * and limitations under the License. 12*83c4dfe9Sjg * 13*83c4dfe9Sjg * When distributing Covered Code, include this CDDL HEADER in each 14*83c4dfe9Sjg * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*83c4dfe9Sjg * If applicable, add the following below this CDDL HEADER, with the 16*83c4dfe9Sjg * fields enclosed by brackets "[]" replaced with your own identifying 17*83c4dfe9Sjg * information: Portions Copyright [yyyy] [name of copyright owner] 18*83c4dfe9Sjg * 19*83c4dfe9Sjg * CDDL HEADER END 20*83c4dfe9Sjg */ 21*83c4dfe9Sjg /* 22*83c4dfe9Sjg * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 23*83c4dfe9Sjg * Use is subject to license terms. 24*83c4dfe9Sjg */ 25*83c4dfe9Sjg 26*83c4dfe9Sjg #ifndef _SYS_DEVCACHE_IMPL_H 27*83c4dfe9Sjg #define _SYS_DEVCACHE_IMPL_H 28*83c4dfe9Sjg 29*83c4dfe9Sjg #pragma ident "%Z%%M% %I% %E% SMI" 30*83c4dfe9Sjg 31*83c4dfe9Sjg #ifdef __cplusplus 32*83c4dfe9Sjg extern "C" { 33*83c4dfe9Sjg #endif 34*83c4dfe9Sjg 35*83c4dfe9Sjg #include <sys/list.h> 36*83c4dfe9Sjg 37*83c4dfe9Sjg /* 38*83c4dfe9Sjg * /etc/devices cache files format 39*83c4dfe9Sjg * Leave some padding for easy extension in the future 40*83c4dfe9Sjg */ 41*83c4dfe9Sjg 42*83c4dfe9Sjg #define NVPF_HDR_MAGIC 0xdeb1dcac 43*83c4dfe9Sjg #define NVPF_HDR_VERSION 1 44*83c4dfe9Sjg #define NVPF_HDR_SIZE 128 45*83c4dfe9Sjg 46*83c4dfe9Sjg typedef struct nvpacked_file_hdr { 47*83c4dfe9Sjg union { 48*83c4dfe9Sjg struct nvfp_hdr { 49*83c4dfe9Sjg uint32_t magic; 50*83c4dfe9Sjg int32_t version; 51*83c4dfe9Sjg int64_t size; 52*83c4dfe9Sjg uint16_t hdr_chksum; 53*83c4dfe9Sjg uint16_t chksum; 54*83c4dfe9Sjg } nvpf; 55*83c4dfe9Sjg uchar_t nvpf_pad[NVPF_HDR_SIZE]; 56*83c4dfe9Sjg } un; 57*83c4dfe9Sjg } nvpf_hdr_t; 58*83c4dfe9Sjg 59*83c4dfe9Sjg #define nvpf_magic un.nvpf.magic 60*83c4dfe9Sjg #define nvpf_version un.nvpf.version 61*83c4dfe9Sjg #define nvpf_size un.nvpf.size 62*83c4dfe9Sjg #define nvpf_hdr_chksum un.nvpf.hdr_chksum 63*83c4dfe9Sjg #define nvpf_chksum un.nvpf.chksum 64*83c4dfe9Sjg 65*83c4dfe9Sjg 66*83c4dfe9Sjg #ifdef _KERNEL 67*83c4dfe9Sjg 68*83c4dfe9Sjg /* 69*83c4dfe9Sjg * Descriptor used for kernel-level file i/o 70*83c4dfe9Sjg */ 71*83c4dfe9Sjg typedef struct kfile { 72*83c4dfe9Sjg struct vnode *kf_vp; 73*83c4dfe9Sjg int kf_vnflags; 74*83c4dfe9Sjg char *kf_fname; 75*83c4dfe9Sjg offset_t kf_fpos; 76*83c4dfe9Sjg int kf_state; 77*83c4dfe9Sjg } kfile_t; 78*83c4dfe9Sjg 79*83c4dfe9Sjg /* 80*83c4dfe9Sjg * File descriptor for files in the nvlist format 81*83c4dfe9Sjg */ 82*83c4dfe9Sjg typedef struct nvfiledesc nvfd_t; 83*83c4dfe9Sjg 84*83c4dfe9Sjg /* 85*83c4dfe9Sjg * Descriptor for a file managed as a backing store for some 86*83c4dfe9Sjg * kernel-generated device state such as device devids, 87*83c4dfe9Sjg * vhci-to-phci mapping, etc. 88*83c4dfe9Sjg * Each client can manage the data in any form convenient. 89*83c4dfe9Sjg * providing functions to unpack (read) and pack (write) 90*83c4dfe9Sjg * the data as an nvlist. 91*83c4dfe9Sjg * 92*83c4dfe9Sjg * Clients should not reference this structure directly 93*83c4dfe9Sjg * but through the handle returned when registering. 94*83c4dfe9Sjg */ 95*83c4dfe9Sjg struct nvfiledesc { 96*83c4dfe9Sjg nvf_ops_t *nvf_ops; /* client ops vectors */ 97*83c4dfe9Sjg int nvf_flags; /* flags */ 98*83c4dfe9Sjg list_t nvf_data_list; /* data list */ 99*83c4dfe9Sjg krwlock_t nvf_lock; /* lock for data list */ 100*83c4dfe9Sjg list_node_t nvf_link; /* link to next file desc */ 101*83c4dfe9Sjg }; 102*83c4dfe9Sjg 103*83c4dfe9Sjg /* 104*83c4dfe9Sjg * nvf_flags 105*83c4dfe9Sjg */ 106*83c4dfe9Sjg #define NVF_F_DIRTY 0x01 /* needs to be flushed */ 107*83c4dfe9Sjg #define NVF_F_FLUSHING 0x02 /* in process of being flushed */ 108*83c4dfe9Sjg #define NVF_F_ERROR 0x04 /* most recent flush failed */ 109*83c4dfe9Sjg #define NVF_F_READONLY 0x10 /* file is read-only */ 110*83c4dfe9Sjg #define NVF_F_CREATE_MSG 0x20 /* file not found on boot, emit msg */ 111*83c4dfe9Sjg #define NVF_F_REBUILD_MSG 0x40 /* file was found corrupted, emit msg */ 112*83c4dfe9Sjg 113*83c4dfe9Sjg #define NVF_IS_DIRTY(nvfd) ((nvfd)->nvf_flags & NVF_F_DIRTY) 114*83c4dfe9Sjg #define NVF_MARK_DIRTY(nvfd) ((nvfd)->nvf_flags |= NVF_F_DIRTY) 115*83c4dfe9Sjg #define NVF_CLEAR_DIRTY(nvfd) ((nvfd)->nvf_flags &= ~NVF_F_DIRTY) 116*83c4dfe9Sjg 117*83c4dfe9Sjg #define NVF_IS_READONLY(nvfd) ((nvfd)->nvf_flags & NVF_F_READONLY) 118*83c4dfe9Sjg #define NVF_MARK_READONLY(nvfd) ((nvfd)->nvf_flags |= NVF_F_READONLY) 119*83c4dfe9Sjg 120*83c4dfe9Sjg /* shorthand to client ops */ 121*83c4dfe9Sjg #define nvf_cache_path nvf_ops->nvfr_cache_path 122*83c4dfe9Sjg #define nvf_unpack_nvlist nvf_ops->nvfr_unpack_nvlist 123*83c4dfe9Sjg #define nvf_pack_list nvf_ops->nvfr_pack_list 124*83c4dfe9Sjg #define nvf_list_free nvf_ops->nvfr_list_free 125*83c4dfe9Sjg #define nvf_write_complete nvf_ops->nvfr_write_complete 126*83c4dfe9Sjg 127*83c4dfe9Sjg 128*83c4dfe9Sjg /* 129*83c4dfe9Sjg * More thorough error reporting available both debug & 130*83c4dfe9Sjg * non-debug kernels, but turned off by default. 131*83c4dfe9Sjg */ 132*83c4dfe9Sjg extern int kfio_report_error; /* kernel file i/o operations */ 133*83c4dfe9Sjg 134*83c4dfe9Sjg /* 135*83c4dfe9Sjg * Suffix of temporary file for updates 136*83c4dfe9Sjg */ 137*83c4dfe9Sjg #define MAX_SUFFIX_LEN 4 138*83c4dfe9Sjg #define NEW_FILENAME_SUFFIX "new" 139*83c4dfe9Sjg 140*83c4dfe9Sjg 141*83c4dfe9Sjg #ifdef DEBUG 142*83c4dfe9Sjg 143*83c4dfe9Sjg #define NVPDAEMON_DEBUG(args) { if (nvpdaemon_debug) cmn_err args; } 144*83c4dfe9Sjg #define KFDEBUG(args) { if (kfio_debug) cmn_err args; } 145*83c4dfe9Sjg #define KFDEBUG1(args) { if (kfio_debug > 1) cmn_err args; } 146*83c4dfe9Sjg #define KFDEBUG2(args) { if (kfio_debug > 2) cmn_err args; } 147*83c4dfe9Sjg #define KFDUMP(args) { if (kfio_debug > 2) args; } 148*83c4dfe9Sjg 149*83c4dfe9Sjg #else 150*83c4dfe9Sjg 151*83c4dfe9Sjg #define NVPDAEMON_DEBUG(args) 152*83c4dfe9Sjg #define KFDEBUG(args) 153*83c4dfe9Sjg #define KFDEBUG1(args) 154*83c4dfe9Sjg #define KFDEBUG2(args) 155*83c4dfe9Sjg #define KFDUMP(args) 156*83c4dfe9Sjg 157*83c4dfe9Sjg #endif /* DEBUG */ 158*83c4dfe9Sjg 159*83c4dfe9Sjg 160*83c4dfe9Sjg #endif /* _KERNEL */ 161*83c4dfe9Sjg 162*83c4dfe9Sjg #ifdef __cplusplus 163*83c4dfe9Sjg } 164*83c4dfe9Sjg #endif 165*83c4dfe9Sjg 166*83c4dfe9Sjg #endif /* _SYS_DEVCACHE_IMPL_H */ 167