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) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 *
24 * Portions Copyright 2010 Robert Milkowski
25 *
26 * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
27 * Copyright (c) 2012, 2017 by Delphix. All rights reserved.
28 * Copyright (c) 2013, Joyent, Inc. All rights reserved.
29 * Copyright (c) 2014 Integros [integros.com]
30 */
31
32 /*
33 * ZFS volume emulation driver.
34 *
35 * Makes a DMU object look like a volume of arbitrary size, up to 2^64 bytes.
36 * Volumes are accessed through the symbolic links named:
37 *
38 * /dev/zvol/dsk/<pool_name>/<dataset_name>
39 * /dev/zvol/rdsk/<pool_name>/<dataset_name>
40 *
41 * These links are created by the /dev filesystem (sdev_zvolops.c).
42 * Volumes are persistent through reboot. No user command needs to be
43 * run before opening and using a device.
44 */
45
46 #include <sys/types.h>
47 #include <sys/param.h>
48 #include <sys/errno.h>
49 #include <sys/uio.h>
1492 length = efi.dki_length;
1493 /*
1494 * Some clients may attempt to request a PMBR for the
1495 * zvol. Currently this interface will return EINVAL to
1496 * such requests. These requests could be supported by
1497 * adding a check for lba == 0 and consing up an appropriate
1498 * PMBR.
1499 */
1500 if (efi.dki_lba < 1 || efi.dki_lba > 2 || length <= 0)
1501 return (SET_ERROR(EINVAL));
1502
1503 gpe.efi_gpe_StartingLBA = LE_64(34ULL);
1504 gpe.efi_gpe_EndingLBA = LE_64((vs >> bs) - 1);
1505 UUID_LE_CONVERT(gpe.efi_gpe_PartitionTypeGUID, uuid);
1506
1507 if (efi.dki_lba == 1) {
1508 efi_gpt_t gpt = { 0 };
1509
1510 gpt.efi_gpt_Signature = LE_64(EFI_SIGNATURE);
1511 gpt.efi_gpt_Revision = LE_32(EFI_VERSION_CURRENT);
1512 gpt.efi_gpt_HeaderSize = LE_32(sizeof (gpt));
1513 gpt.efi_gpt_MyLBA = LE_64(1ULL);
1514 gpt.efi_gpt_FirstUsableLBA = LE_64(34ULL);
1515 gpt.efi_gpt_LastUsableLBA = LE_64((vs >> bs) - 1);
1516 gpt.efi_gpt_PartitionEntryLBA = LE_64(2ULL);
1517 gpt.efi_gpt_NumberOfPartitionEntries = LE_32(1);
1518 gpt.efi_gpt_SizeOfPartitionEntry =
1519 LE_32(sizeof (efi_gpe_t));
1520 CRC32(crc, &gpe, sizeof (gpe), -1U, crc32_table);
1521 gpt.efi_gpt_PartitionEntryArrayCRC32 = LE_32(~crc);
1522 CRC32(crc, &gpt, sizeof (gpt), -1U, crc32_table);
1523 gpt.efi_gpt_HeaderCRC32 = LE_32(~crc);
1524 if (ddi_copyout(&gpt, ptr, MIN(sizeof (gpt), length),
1525 flag))
1526 return (SET_ERROR(EFAULT));
1527 ptr += sizeof (gpt);
1528 length -= sizeof (gpt);
1529 }
1530 if (length > 0 && ddi_copyout(&gpe, ptr, MIN(sizeof (gpe),
1531 length), flag))
1532 return (SET_ERROR(EFAULT));
1533 return (0);
1534 }
1535
1536 /*
1537 * BEGIN entry points to allow external callers access to the volume.
1538 */
1539 /*
1540 * Return the volume parameters needed for access from an external caller.
1541 * These values are invariant as long as the volume is held open.
1542 */
|
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) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 *
24 * Portions Copyright 2010 Robert Milkowski
25 *
26 * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
27 * Copyright (c) 2012, 2017 by Delphix. All rights reserved.
28 * Copyright (c) 2013, Joyent, Inc. All rights reserved.
29 * Copyright (c) 2014 Integros [integros.com]
30 * Copyright (c) 2019, Joyent, Inc.
31 */
32
33 /*
34 * ZFS volume emulation driver.
35 *
36 * Makes a DMU object look like a volume of arbitrary size, up to 2^64 bytes.
37 * Volumes are accessed through the symbolic links named:
38 *
39 * /dev/zvol/dsk/<pool_name>/<dataset_name>
40 * /dev/zvol/rdsk/<pool_name>/<dataset_name>
41 *
42 * These links are created by the /dev filesystem (sdev_zvolops.c).
43 * Volumes are persistent through reboot. No user command needs to be
44 * run before opening and using a device.
45 */
46
47 #include <sys/types.h>
48 #include <sys/param.h>
49 #include <sys/errno.h>
50 #include <sys/uio.h>
1493 length = efi.dki_length;
1494 /*
1495 * Some clients may attempt to request a PMBR for the
1496 * zvol. Currently this interface will return EINVAL to
1497 * such requests. These requests could be supported by
1498 * adding a check for lba == 0 and consing up an appropriate
1499 * PMBR.
1500 */
1501 if (efi.dki_lba < 1 || efi.dki_lba > 2 || length <= 0)
1502 return (SET_ERROR(EINVAL));
1503
1504 gpe.efi_gpe_StartingLBA = LE_64(34ULL);
1505 gpe.efi_gpe_EndingLBA = LE_64((vs >> bs) - 1);
1506 UUID_LE_CONVERT(gpe.efi_gpe_PartitionTypeGUID, uuid);
1507
1508 if (efi.dki_lba == 1) {
1509 efi_gpt_t gpt = { 0 };
1510
1511 gpt.efi_gpt_Signature = LE_64(EFI_SIGNATURE);
1512 gpt.efi_gpt_Revision = LE_32(EFI_VERSION_CURRENT);
1513 gpt.efi_gpt_HeaderSize = LE_32(EFI_HEADER_SIZE);
1514 gpt.efi_gpt_MyLBA = LE_64(1ULL);
1515 gpt.efi_gpt_FirstUsableLBA = LE_64(34ULL);
1516 gpt.efi_gpt_LastUsableLBA = LE_64((vs >> bs) - 1);
1517 gpt.efi_gpt_PartitionEntryLBA = LE_64(2ULL);
1518 gpt.efi_gpt_NumberOfPartitionEntries = LE_32(1);
1519 gpt.efi_gpt_SizeOfPartitionEntry =
1520 LE_32(sizeof (efi_gpe_t));
1521 CRC32(crc, &gpe, sizeof (gpe), -1U, crc32_table);
1522 gpt.efi_gpt_PartitionEntryArrayCRC32 = LE_32(~crc);
1523 CRC32(crc, &gpt, EFI_HEADER_SIZE, -1U, crc32_table);
1524 gpt.efi_gpt_HeaderCRC32 = LE_32(~crc);
1525 if (ddi_copyout(&gpt, ptr, MIN(sizeof (gpt), length),
1526 flag))
1527 return (SET_ERROR(EFAULT));
1528 ptr += sizeof (gpt);
1529 length -= sizeof (gpt);
1530 }
1531 if (length > 0 && ddi_copyout(&gpe, ptr, MIN(sizeof (gpe),
1532 length), flag))
1533 return (SET_ERROR(EFAULT));
1534 return (0);
1535 }
1536
1537 /*
1538 * BEGIN entry points to allow external callers access to the volume.
1539 */
1540 /*
1541 * Return the volume parameters needed for access from an external caller.
1542 * These values are invariant as long as the volume is held open.
1543 */
|