1 | /** @file
|
---|
2 | * VirtualBox Guest Additions Driver for Solaris - Solaris helper functions.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2012 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | */
|
---|
16 |
|
---|
17 | /******************************************************************************
|
---|
18 | * Header Files *
|
---|
19 | ******************************************************************************/
|
---|
20 |
|
---|
21 | #include "solaris.h"
|
---|
22 |
|
---|
23 | /******************************************************************************
|
---|
24 | * Helper functions *
|
---|
25 | ******************************************************************************/
|
---|
26 |
|
---|
27 | void miocack(queue_t *pWriteQueue, mblk_t *pMBlk, int cbData, int rc)
|
---|
28 | {
|
---|
29 | struct iocblk *pIOCBlk = (struct iocblk *)pMBlk->b_rptr;
|
---|
30 |
|
---|
31 | pMBlk->b_datap->db_type = M_IOCACK;
|
---|
32 | pIOCBlk->ioc_count = cbData;
|
---|
33 | pIOCBlk->ioc_rval = rc;
|
---|
34 | pIOCBlk->ioc_error = 0;
|
---|
35 | qreply(pWriteQueue, pMBlk);
|
---|
36 | }
|
---|
37 |
|
---|
38 | void miocnak(queue_t *pWriteQueue, mblk_t *pMBlk, int cbData, int iErr)
|
---|
39 | {
|
---|
40 | struct iocblk *pIOCBlk = (struct iocblk *)pMBlk->b_rptr;
|
---|
41 |
|
---|
42 | pMBlk->b_datap->db_type = M_IOCNAK;
|
---|
43 | pIOCBlk->ioc_count = cbData;
|
---|
44 | pIOCBlk->ioc_error = iErr ? iErr : EINVAL;
|
---|
45 | pIOCBlk->ioc_rval = 0;
|
---|
46 | qreply(pWriteQueue, pMBlk);
|
---|
47 | }
|
---|
48 |
|
---|
49 | /* This does not work like the real version, but does some sanity testing
|
---|
50 | * and sets a flag. */
|
---|
51 | int miocpullup(mblk_t *pMBlk, size_t cbMsg)
|
---|
52 | {
|
---|
53 | struct iocblk *pIOCBlk = (struct iocblk *)pMBlk->b_rptr;
|
---|
54 |
|
---|
55 | if (pIOCBlk->ioc_count == TRANSPARENT)
|
---|
56 | return EINVAL;
|
---|
57 | if ( !pMBlk->b_cont
|
---|
58 | || pMBlk->b_cont->b_wptr < pMBlk->b_cont->b_rptr + cbMsg)
|
---|
59 | return EINVAL;
|
---|
60 | pMBlk->b_flag |= F_TEST_PULLUP;
|
---|
61 | return 0;
|
---|
62 | }
|
---|
63 |
|
---|
64 | void mcopyin(mblk_t *pMBlk, void *pvState, size_t cbData, void *pvUser)
|
---|
65 | {
|
---|
66 | struct iocblk *pIOCBlk = (struct iocblk *)pMBlk->b_rptr;
|
---|
67 | struct copyreq *pCopyReq = (struct copyreq *)pMBlk->b_rptr;
|
---|
68 |
|
---|
69 | AssertReturnVoid( pvUser
|
---|
70 | || ( pMBlk->b_datap->db_type == M_IOCTL
|
---|
71 | && pIOCBlk->ioc_count == TRANSPARENT
|
---|
72 | && pMBlk->b_cont->b_rptr));
|
---|
73 | pMBlk->b_datap->db_type = M_COPYIN;
|
---|
74 | pMBlk->b_wptr = pMBlk->b_rptr + sizeof(*pCopyReq);
|
---|
75 | pCopyReq->cq_private = pvState;
|
---|
76 | pCopyReq->cq_size = cbData;
|
---|
77 | pCopyReq->cq_addr = pvUser ? pvUser : pMBlk->b_cont->b_rptr;
|
---|
78 | if (pMBlk->b_cont)
|
---|
79 | {
|
---|
80 | freemsg(pMBlk->b_cont);
|
---|
81 | pMBlk->b_cont = NULL;
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | void mcopyout(mblk_t *pMBlk, void *pvState, size_t cbData, void *pvUser,
|
---|
86 | mblk_t *pMBlkData)
|
---|
87 | {
|
---|
88 | struct iocblk *pIOCBlk = (struct iocblk *)pMBlk->b_rptr;
|
---|
89 | struct copyreq *pCopyReq = (struct copyreq *)pMBlk->b_rptr;
|
---|
90 |
|
---|
91 | AssertReturnVoid( pvUser
|
---|
92 | || ( pMBlk->b_datap->db_type == M_IOCTL
|
---|
93 | && pIOCBlk->ioc_count == TRANSPARENT
|
---|
94 | && pMBlk->b_cont->b_rptr));
|
---|
95 | pMBlk->b_datap->db_type = M_COPYOUT;
|
---|
96 | pMBlk->b_wptr = pMBlk->b_rptr + sizeof(*pCopyReq);
|
---|
97 | pCopyReq->cq_private = pvState;
|
---|
98 | pCopyReq->cq_size = cbData;
|
---|
99 | pCopyReq->cq_addr = pvUser ? pvUser : pMBlk->b_cont->b_rptr;
|
---|
100 | if (pMBlkData)
|
---|
101 | {
|
---|
102 | if (pMBlk->b_cont)
|
---|
103 | freemsg(pMBlk->b_cont);
|
---|
104 | pMBlk->b_cont = pMBlkData;
|
---|
105 | pMBlkData->b_wptr = pMBlkData->b_rptr + cbData;
|
---|
106 | }
|
---|
107 | }
|
---|
108 |
|
---|
109 | /* This does not work like the real version but is easy to test the result of.
|
---|
110 | */
|
---|
111 | void qreply(queue_t *pQueue, mblk_t *pMBlk)
|
---|
112 | {
|
---|
113 | OTHERQ(pQueue)->q_first = pMBlk;
|
---|
114 | }
|
---|