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 /*
  28  * lofi (loopback file) driver - allows you to attach a file to a device,
  29  * which can then be accessed through that device. The simple model is that
  30  * you tell lofi to open a file, and then use the block device you get as
  31  * you would any block device. lofi translates access to the block device
  32  * into I/O on the underlying file. This is mostly useful for
  33  * mounting images of filesystems.
  34  *
  35  * lofi is controlled through /dev/lofictl - this is the only device exported
  36  * during attach, and is minor number 0. lofiadm communicates with lofi through
  37  * ioctls on this device. When a file is attached to lofi, block and character
  38  * devices are exported in /dev/lofi and /dev/rlofi. Currently, these devices
  39  * are identified by their minor number, and the minor number is also used
  40  * as the name in /dev/lofi. If we ever decide to support virtual disks,
  41  * we'll have to divide the minor number space to identify fdisk partitions
  42  * and slices, and the name will then be the minor number shifted down a
  43  * few bits. Minor devices are tracked with state structures handled with
  44  * ddi_soft_state(9F) for simplicity.


 114 #include <sys/conf.h>
 115 #include <sys/debug.h>
 116 #include <sys/vnode.h>
 117 #include <sys/lofi.h>
 118 #include <sys/fcntl.h>
 119 #include <sys/pathname.h>
 120 #include <sys/filio.h>
 121 #include <sys/fdio.h>
 122 #include <sys/open.h>
 123 #include <sys/disp.h>
 124 #include <vm/seg_map.h>
 125 #include <sys/ddi.h>
 126 #include <sys/sunddi.h>
 127 #include <sys/zmod.h>
 128 #include <sys/id_space.h>
 129 #include <sys/mkdev.h>
 130 #include <sys/crypto/common.h>
 131 #include <sys/crypto/api.h>
 132 #include <sys/rctl.h>
 133 #include <LzmaDec.h>
 134 
 135 /*
 136  * The basis for CRYOFF is derived from usr/src/uts/common/sys/fs/ufs_fs.h.
 137  * Crypto metadata, if it exists, is located at the end of the boot block
 138  * (BBOFF + BBSIZE, which is SBOFF).  The super block and everything after
 139  * is offset by the size of the crypto metadata which is handled by
 140  * lsp->ls_crypto_offset.
 141  */
 142 #define CRYOFF  ((off_t)8192)
 143 
 144 #define NBLOCKS_PROP_NAME       "Nblocks"
 145 #define SIZE_PROP_NAME          "Size"
 146 #define ZONE_PROP_NAME          "zone"
 147 
 148 #define SETUP_C_DATA(cd, buf, len)              \
 149         (cd).cd_format = CRYPTO_DATA_RAW;       \
 150         (cd).cd_offset = 0;                     \
 151         (cd).cd_miscdata = NULL;                \
 152         (cd).cd_length = (len);                 \
 153         (cd).cd_raw.iov_base = (buf);           \
 154         (cd).cd_raw.iov_len = (len);
 155 
 156 #define UIO_CHECK(uio)  \
 157         if (((uio)->uio_loffset % DEV_BSIZE) != 0 || \
 158             ((uio)->uio_resid % DEV_BSIZE) != 0) { \
 159                 return (EINVAL); \
 160         }
 161 
 162 static dev_info_t *lofi_dip = NULL;




   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 /*
  29  * lofi (loopback file) driver - allows you to attach a file to a device,
  30  * which can then be accessed through that device. The simple model is that
  31  * you tell lofi to open a file, and then use the block device you get as
  32  * you would any block device. lofi translates access to the block device
  33  * into I/O on the underlying file. This is mostly useful for
  34  * mounting images of filesystems.
  35  *
  36  * lofi is controlled through /dev/lofictl - this is the only device exported
  37  * during attach, and is minor number 0. lofiadm communicates with lofi through
  38  * ioctls on this device. When a file is attached to lofi, block and character
  39  * devices are exported in /dev/lofi and /dev/rlofi. Currently, these devices
  40  * are identified by their minor number, and the minor number is also used
  41  * as the name in /dev/lofi. If we ever decide to support virtual disks,
  42  * we'll have to divide the minor number space to identify fdisk partitions
  43  * and slices, and the name will then be the minor number shifted down a
  44  * few bits. Minor devices are tracked with state structures handled with
  45  * ddi_soft_state(9F) for simplicity.


 115 #include <sys/conf.h>
 116 #include <sys/debug.h>
 117 #include <sys/vnode.h>
 118 #include <sys/lofi.h>
 119 #include <sys/fcntl.h>
 120 #include <sys/pathname.h>
 121 #include <sys/filio.h>
 122 #include <sys/fdio.h>
 123 #include <sys/open.h>
 124 #include <sys/disp.h>
 125 #include <vm/seg_map.h>
 126 #include <sys/ddi.h>
 127 #include <sys/sunddi.h>
 128 #include <sys/zmod.h>
 129 #include <sys/id_space.h>
 130 #include <sys/mkdev.h>
 131 #include <sys/crypto/common.h>
 132 #include <sys/crypto/api.h>
 133 #include <sys/rctl.h>
 134 #include <LzmaDec.h>









 135 
 136 #define NBLOCKS_PROP_NAME       "Nblocks"
 137 #define SIZE_PROP_NAME          "Size"
 138 #define ZONE_PROP_NAME          "zone"
 139 
 140 #define SETUP_C_DATA(cd, buf, len)              \
 141         (cd).cd_format = CRYPTO_DATA_RAW;       \
 142         (cd).cd_offset = 0;                     \
 143         (cd).cd_miscdata = NULL;                \
 144         (cd).cd_length = (len);                 \
 145         (cd).cd_raw.iov_base = (buf);           \
 146         (cd).cd_raw.iov_len = (len);
 147 
 148 #define UIO_CHECK(uio)  \
 149         if (((uio)->uio_loffset % DEV_BSIZE) != 0 || \
 150             ((uio)->uio_resid % DEV_BSIZE) != 0) { \
 151                 return (EINVAL); \
 152         }
 153 
 154 static dev_info_t *lofi_dip = NULL;