2 * Copyright 2008, Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * NaCl Service Runtime. Directory descriptor abstraction.
36 #include "native_client/include/portability.h"
44 #include "native_client/service_runtime/nacl_config.h"
45 #include "native_client/service_runtime/nacl_log.h"
46 #include "native_client/service_runtime/nacl_desc_base.h"
47 #include "native_client/service_runtime/nacl_desc_dir.h"
48 #include "native_client/service_runtime/internal_errno.h"
50 #include "native_client/service_runtime/include/sys/dirent.h"
51 #include "native_client/service_runtime/include/sys/errno.h"
52 #include "native_client/service_runtime/include/sys/fcntl.h"
53 #include "native_client/service_runtime/include/sys/mman.h"
55 #include "native_client/intermodule_comm/nacl_imc_c.h"
58 * This file contains the implementation for the NaClDirDesc subclass
61 * NaClDescDirDesc is the subclass that wraps host-OS directory information.
65 * Takes ownership of hd, will close in Dtor.
67 int NaClDescDirDescCtor(struct NaClDescDirDesc
*self
,
68 struct NaClHostDir
*hd
)
70 struct NaClDesc
*basep
= (struct NaClDesc
*) self
;
72 if (!NaClDescCtor(basep
)) {
76 basep
->vtbl
= &kNaClDescDirDescVtbl
;
80 void NaClDescDirDescDtor(struct NaClDesc
*vself
)
82 struct NaClDescDirDesc
*self
= (struct NaClDescDirDesc
*) vself
;
84 NaClLog(4, "NaClDescDirDescDtor(0x%08x).\n",
86 NaClHostDirClose(self
->hd
);
89 NaClDescDtor(&self
->base
);
92 struct NaClDescDirDesc
*NaClDescDirDescMake(struct NaClHostDir
*nhdp
)
94 struct NaClDescDirDesc
*ndp
;
96 ndp
= malloc(sizeof *ndp
);
99 "NaClDescDirDescMake: no memory for 0x%08x\n",
102 if (!NaClDescDirDescCtor(ndp
, nhdp
)) {
104 "NaClDescDirDescMake: NaClDescDirDescCtor(0x%08x,0x%08x) failed\n",
111 struct NaClDescDirDesc
*NaClDescDirDescOpen(char *path
)
113 struct NaClHostDir
*nhdp
;
115 nhdp
= malloc(sizeof *nhdp
);
117 NaClLog(LOG_FATAL
, "NaClDescDirDescOpen: no memory for %s\n", path
);
119 if (!NaClHostDirOpen(nhdp
, path
)) {
120 NaClLog(LOG_FATAL
, "NaClDescDirDescOpen: NaClHostDirOpen failed for %s\n",
123 return NaClDescDirDescMake(nhdp
);
126 ssize_t
NaClDescDirDescRead(struct NaClDesc
*vself
,
127 struct NaClDescEffector
*effp
,
131 /* NaClLog(LOG_ERROR, "NaClDescDirDescRead: Read not allowed on dir\n"); */
132 return NaClDescDirDescGetdents(vself
, effp
, buf
, len
);
133 /* return -NACL_ABI_EINVAL; */
136 ssize_t
NaClDescDirDescGetdents(struct NaClDesc
*vself
,
137 struct NaClDescEffector
*effp
,
141 struct NaClDescDirDesc
*self
= (struct NaClDescDirDesc
*) vself
;
142 struct nacl_abi_dirent
*direntp
= (struct nacl_abi_dirent
*) dirp
;
145 NaClLog(3, "NaClDescDirDescGetdents(0x%08x, %u):\n", dirp
, count
);
146 retval
= NaClHostDirGetdents(self
->hd
, dirp
, count
);
147 NaClLog(3, "NaClDescDirDescGetdents(d_ino=%u, d_off=%u, d_reclen=%u, "
149 direntp
->nacl_abi_d_ino
,
150 direntp
->nacl_abi_d_off
,
151 direntp
->nacl_abi_d_reclen
,
152 direntp
->nacl_abi_d_name
);
156 int NaClDescDirDescClose(struct NaClDesc
*vself
,
157 struct NaClDescEffector
*effp
)
159 NaClDescUnref(vself
);
163 int NaClDescDirDescExternalizeSize(struct NaClDesc
*vself
,
172 struct NaClDescVtbl
const kNaClDescDirDescVtbl
= {
174 NaClDescMapNotImplemented
,
175 NaClDescUnmapUnsafeNotImplemented
,
176 NaClDescUnmapNotImplemented
,
178 NaClDescWriteNotImplemented
,
179 NaClDescSeekNotImplemented
,
180 NaClDescIoctlNotImplemented
,
181 NaClDescFstatNotImplemented
,
182 NaClDescDirDescClose
,
183 NaClDescDirDescGetdents
,
185 NaClDescDirDescExternalizeSize
,
186 NaClDescExternalizeNotImplemented
,
187 NaClDescLockNotImplemented
,
188 NaClDescTryLockNotImplemented
,
189 NaClDescUnlockNotImplemented
,
190 NaClDescWaitNotImplemented
,
191 NaClDescTimedWaitAbsNotImplemented
,
192 NaClDescSignalNotImplemented
,
193 NaClDescBroadcastNotImplemented
,
194 NaClDescSendMsgNotImplemented
,
195 NaClDescRecvMsgNotImplemented
,
196 NaClDescConnectAddrNotImplemented
,
197 NaClDescAcceptConnNotImplemented
,
198 NaClDescPostNotImplemented
,
199 NaClDescSemWaitNotImplemented
,
200 NaClDescGetValueNotImplemented
,
203 int NaClDescDirInternalize(struct NaClDesc
**baseptr
,
204 struct NaClDescXferState
*xfer
)
206 NaClLog(LOG_ERROR
, "NaClDescDirDescInternalize: not implemented for dir\n");
207 return -NACL_ABI_EINVAL
;