4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
29 #include <sys/types.h>
30 #include <sys/socket.h>
32 #include <sys/dmu_ctl.h>
33 #include <sys/dmu_ctl_impl.h>
35 int dctl_read_msg(int fd, dctl_cmd_t *cmd)
40 * First, read only the magic number and the protocol version.
42 * This prevents blocking forever in case the size of dctl_cmd_t
43 * shrinks in future protocol versions.
45 error = dctl_read_data(fd, cmd, DCTL_CMD_HEADER_SIZE);
47 if (!error &&cmd->dcmd_magic != DCTL_MAGIC) {
48 fprintf(stderr, "%s(): invalid magic number\n", __func__);
52 if (!error && cmd->dcmd_version != DCTL_PROTOCOL_VER) {
53 fprintf(stderr, "%s(): invalid protocol version\n", __func__);
60 /* Get the rest of the command */
61 return dctl_read_data(fd, (caddr_t) cmd + DCTL_CMD_HEADER_SIZE,
62 sizeof(dctl_cmd_t) - DCTL_CMD_HEADER_SIZE);
65 int dctl_send_msg(int fd, dctl_cmd_t *cmd)
67 cmd->dcmd_magic = DCTL_MAGIC;
68 cmd->dcmd_version = DCTL_PROTOCOL_VER;
70 return dctl_send_data(fd, cmd, sizeof(dctl_cmd_t));
73 int dctl_read_data(int fd, void *ptr, size_t size)
80 rc = recv(fd, (caddr_t) ptr + read, left, 0);
82 /* File descriptor closed */
99 int dctl_send_data(int fd, const void *ptr, size_t size)
104 rc = send(fd, ptr, size, MSG_NOSIGNAL);
105 } while(rc == -1 && errno == EINTR);
107 return rc == size ? 0 : EIO;