Print this page
5857 lofiadm should ask passphrase once if the crypto is already set up
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Toomas Soome <tsoome@me.com>


   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   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.
  12  *
  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]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
  23  *
  24  * Copyright 2013 Nexenta Systems, Inc. All rights reserved.

  25  */
  26 
  27 #ifndef _SYS_LOFI_H
  28 #define _SYS_LOFI_H
  29 
  30 #include <sys/types.h>
  31 #include <sys/time.h>
  32 #include <sys/taskq.h>
  33 #include <sys/vtoc.h>
  34 #include <sys/dkio.h>
  35 #include <sys/vnode.h>
  36 #include <sys/list.h>
  37 #include <sys/crypto/api.h>
  38 #include <sys/zone.h>
  39 
  40 #ifdef  __cplusplus
  41 extern "C" {
  42 #endif
  43 
  44 /*


 146 };
 147 
 148 #define LOFI_IOC_BASE           (('L' << 16) | ('F' << 8))
 149 
 150 #define LOFI_MAP_FILE           (LOFI_IOC_BASE | 0x01)
 151 #define LOFI_MAP_FILE_MINOR     (LOFI_IOC_BASE | 0x02)
 152 #define LOFI_UNMAP_FILE         (LOFI_IOC_BASE | 0x03)
 153 #define LOFI_UNMAP_FILE_MINOR   (LOFI_IOC_BASE | 0x04)
 154 #define LOFI_GET_FILENAME       (LOFI_IOC_BASE | 0x05)
 155 #define LOFI_GET_MINOR          (LOFI_IOC_BASE | 0x06)
 156 #define LOFI_GET_MAXMINOR       (LOFI_IOC_BASE | 0x07)
 157 #define LOFI_CHECK_COMPRESSED   (LOFI_IOC_BASE | 0x08)
 158 
 159 /*
 160  * file types that might be usable with lofi, maybe. Only regular
 161  * files are documented though.
 162  */
 163 #define S_ISLOFIABLE(mode) \
 164         (S_ISREG(mode) || S_ISBLK(mode) || S_ISCHR(mode))
 165 











 166 #if defined(_KERNEL)
 167 
 168 
 169 /*
 170  * Cache decompressed data segments for the compressed lofi images.
 171  *
 172  * To avoid that we have to decompress data of a compressed
 173  * segment multiple times when accessing parts of the segment's
 174  * data we cache the uncompressed data, using a simple linked list.
 175  */
 176 struct lofi_comp_cache {
 177         list_node_t     lc_list;                /* linked list */
 178         uchar_t         *lc_data;               /* decompressed segment data */
 179         uint64_t        lc_index;               /* segment index */
 180 };
 181 
 182 #define V_ISLOFIABLE(vtype) \
 183         ((vtype == VREG) || (vtype == VBLK) || (vtype == VCHR))
 184 
 185 /*
 186  * Pre-allocated memory buffers for the purpose of compression
 187  */
 188 struct compbuf {
 189         void            *buf;
 190         uint32_t        bufsize;
 191         int             inuse;
 192 };
 193 
 194 /*
 195  * Need exactly 6 bytes to identify encrypted lofi image
 196  */
 197 extern const char lofi_crypto_magic[6];
 198 #define LOFI_CRYPTO_MAGIC       { 'C', 'F', 'L', 'O', 'F', 'I' }
 199 #define LOFI_CRYPTO_VERSION     ((uint16_t)0)
 200 #define LOFI_CRYPTO_DATA_SECTOR ((uint32_t)16)          /* for version 0 */
 201 
 202 /*
 203  * Crypto metadata for encrypted lofi images
 204  * The fields here only satisfy initial implementation requirements.
 205  */
 206 struct crypto_meta {
 207         char            magic[6];               /* LOFI_CRYPTO_MAGIC */
 208         uint16_t        version;                /* version of encrypted lofi */
 209         char            reserved1[96];          /* future use */
 210         uint32_t        data_sector;            /* start of data area */
 211         char            pad[404];               /* end on DEV_BSIZE bdry */
 212         /* second header block is not defined at this time */
 213 };
 214 
 215 struct lofi_state {
 216         vnode_t         *ls_vp;         /* open real vnode */
 217         vnode_t         *ls_stacked_vp; /* open vnode */
 218         kmutex_t        ls_vp_lock;     /* protects ls_vp */




   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   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.
  12  *
  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]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
  23  *
  24  * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
  25  * Copyright (c) 2016 Andrey Sokolov
  26  */
  27 
  28 #ifndef _SYS_LOFI_H
  29 #define _SYS_LOFI_H
  30 
  31 #include <sys/types.h>
  32 #include <sys/time.h>
  33 #include <sys/taskq.h>
  34 #include <sys/vtoc.h>
  35 #include <sys/dkio.h>
  36 #include <sys/vnode.h>
  37 #include <sys/list.h>
  38 #include <sys/crypto/api.h>
  39 #include <sys/zone.h>
  40 
  41 #ifdef  __cplusplus
  42 extern "C" {
  43 #endif
  44 
  45 /*


 147 };
 148 
 149 #define LOFI_IOC_BASE           (('L' << 16) | ('F' << 8))
 150 
 151 #define LOFI_MAP_FILE           (LOFI_IOC_BASE | 0x01)
 152 #define LOFI_MAP_FILE_MINOR     (LOFI_IOC_BASE | 0x02)
 153 #define LOFI_UNMAP_FILE         (LOFI_IOC_BASE | 0x03)
 154 #define LOFI_UNMAP_FILE_MINOR   (LOFI_IOC_BASE | 0x04)
 155 #define LOFI_GET_FILENAME       (LOFI_IOC_BASE | 0x05)
 156 #define LOFI_GET_MINOR          (LOFI_IOC_BASE | 0x06)
 157 #define LOFI_GET_MAXMINOR       (LOFI_IOC_BASE | 0x07)
 158 #define LOFI_CHECK_COMPRESSED   (LOFI_IOC_BASE | 0x08)
 159 
 160 /*
 161  * file types that might be usable with lofi, maybe. Only regular
 162  * files are documented though.
 163  */
 164 #define S_ISLOFIABLE(mode) \
 165         (S_ISREG(mode) || S_ISBLK(mode) || S_ISCHR(mode))
 166 
 167 /*
 168  * The basis for CRYOFF is derived from usr/src/uts/common/sys/fs/ufs_fs.h.
 169  * Crypto metadata, if it exists, is located at the end of the boot block
 170  * (BBOFF + BBSIZE, which is SBOFF).  The super block and everything after
 171  * is offset by the size of the crypto metadata which is handled by
 172  * lsp->ls_crypto_offset.
 173  */
 174 #define CRYOFF  ((off_t)8192)
 175 
 176 #define LOFI_CRYPTO_MAGIC       { 'C', 'F', 'L', 'O', 'F', 'I' }
 177 
 178 #if defined(_KERNEL)
 179 
 180 
 181 /*
 182  * Cache decompressed data segments for the compressed lofi images.
 183  *
 184  * To avoid that we have to decompress data of a compressed
 185  * segment multiple times when accessing parts of the segment's
 186  * data we cache the uncompressed data, using a simple linked list.
 187  */
 188 struct lofi_comp_cache {
 189         list_node_t     lc_list;                /* linked list */
 190         uchar_t         *lc_data;               /* decompressed segment data */
 191         uint64_t        lc_index;               /* segment index */
 192 };
 193 
 194 #define V_ISLOFIABLE(vtype) \
 195         ((vtype == VREG) || (vtype == VBLK) || (vtype == VCHR))
 196 
 197 /*
 198  * Pre-allocated memory buffers for the purpose of compression
 199  */
 200 struct compbuf {
 201         void            *buf;
 202         uint32_t        bufsize;
 203         int             inuse;
 204 };
 205 
 206 /*
 207  * Need exactly 6 bytes to identify encrypted lofi image
 208  */
 209 extern const char lofi_crypto_magic[6];

 210 #define LOFI_CRYPTO_VERSION     ((uint16_t)0)
 211 #define LOFI_CRYPTO_DATA_SECTOR ((uint32_t)16)          /* for version 0 */
 212 
 213 /*
 214  * Crypto metadata for encrypted lofi images
 215  * The fields here only satisfy initial implementation requirements.
 216  */
 217 struct crypto_meta {
 218         char            magic[6];               /* LOFI_CRYPTO_MAGIC */
 219         uint16_t        version;                /* version of encrypted lofi */
 220         char            reserved1[96];          /* future use */
 221         uint32_t        data_sector;            /* start of data area */
 222         char            pad[404];               /* end on DEV_BSIZE bdry */
 223         /* second header block is not defined at this time */
 224 };
 225 
 226 struct lofi_state {
 227         vnode_t         *ls_vp;         /* open real vnode */
 228         vnode_t         *ls_stacked_vp; /* open vnode */
 229         kmutex_t        ls_vp_lock;     /* protects ls_vp */