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 basep
->vtbl
= (struct NaClDescVtbl
*) NULL
;
73 if (!NaClDescCtor(basep
)) {
77 basep
->vtbl
= &kNaClDescDirDescVtbl
;
81 void NaClDescDirDescDtor(struct NaClDesc
*vself
)
83 struct NaClDescDirDesc
*self
= (struct NaClDescDirDesc
*) vself
;
85 NaClLog(4, "NaClDescDirDescDtor(0x%08"PRIxPTR
").\n",
87 NaClHostDirClose(self
->hd
);
90 vself
->vtbl
= (struct NaClDescVtbl
*) NULL
;
91 NaClDescDtor(&self
->base
);
94 struct NaClDescDirDesc
*NaClDescDirDescMake(struct NaClHostDir
*nhdp
)
96 struct NaClDescDirDesc
*ndp
;
98 ndp
= malloc(sizeof *ndp
);
101 "NaClDescDirDescMake: no memory for 0x%08"PRIxPTR
"\n",
104 if (!NaClDescDirDescCtor(ndp
, nhdp
)) {
106 ("NaClDescDirDescMake:"
107 " NaClDescDirDescCtor(0x%08"PRIxPTR
",0x%08"PRIxPTR
") failed\n"),
114 struct NaClDescDirDesc
*NaClDescDirDescOpen(char *path
)
116 struct NaClHostDir
*nhdp
;
118 nhdp
= malloc(sizeof *nhdp
);
120 NaClLog(LOG_FATAL
, "NaClDescDirDescOpen: no memory for %s\n", path
);
122 if (!NaClHostDirOpen(nhdp
, path
)) {
123 NaClLog(LOG_FATAL
, "NaClDescDirDescOpen: NaClHostDirOpen failed for %s\n",
126 return NaClDescDirDescMake(nhdp
);
129 ssize_t
NaClDescDirDescRead(struct NaClDesc
*vself
,
130 struct NaClDescEffector
*effp
,
134 /* NaClLog(LOG_ERROR, "NaClDescDirDescRead: Read not allowed on dir\n"); */
135 return NaClDescDirDescGetdents(vself
, effp
, buf
, len
);
136 /* return -NACL_ABI_EINVAL; */
139 ssize_t
NaClDescDirDescGetdents(struct NaClDesc
*vself
,
140 struct NaClDescEffector
*effp
,
144 struct NaClDescDirDesc
*self
= (struct NaClDescDirDesc
*) vself
;
145 struct nacl_abi_dirent
*direntp
= (struct nacl_abi_dirent
*) dirp
;
148 NaClLog(3, "NaClDescDirDescGetdents(0x%08"PRIxPTR
", %"PRIuS
"):\n",
149 (uintptr_t) dirp
, count
);
150 retval
= NaClHostDirGetdents(self
->hd
, dirp
, count
);
151 NaClLog(3, "NaClDescDirDescGetdents(d_ino=%lu, d_off=%lu, d_reclen=%u, "
153 direntp
->nacl_abi_d_ino
,
154 direntp
->nacl_abi_d_off
,
155 direntp
->nacl_abi_d_reclen
,
156 direntp
->nacl_abi_d_name
);
160 int NaClDescDirDescClose(struct NaClDesc
*vself
,
161 struct NaClDescEffector
*effp
)
163 NaClDescUnref(vself
);
167 int NaClDescDirDescExternalizeSize(struct NaClDesc
*vself
,
176 struct NaClDescVtbl
const kNaClDescDirDescVtbl
= {
178 NaClDescMapNotImplemented
,
179 NaClDescUnmapUnsafeNotImplemented
,
180 NaClDescUnmapNotImplemented
,
182 NaClDescWriteNotImplemented
,
183 NaClDescSeekNotImplemented
,
184 NaClDescIoctlNotImplemented
,
185 NaClDescFstatNotImplemented
,
186 NaClDescDirDescClose
,
187 NaClDescDirDescGetdents
,
189 NaClDescDirDescExternalizeSize
,
190 NaClDescExternalizeNotImplemented
,
191 NaClDescLockNotImplemented
,
192 NaClDescTryLockNotImplemented
,
193 NaClDescUnlockNotImplemented
,
194 NaClDescWaitNotImplemented
,
195 NaClDescTimedWaitAbsNotImplemented
,
196 NaClDescSignalNotImplemented
,
197 NaClDescBroadcastNotImplemented
,
198 NaClDescSendMsgNotImplemented
,
199 NaClDescRecvMsgNotImplemented
,
200 NaClDescConnectAddrNotImplemented
,
201 NaClDescAcceptConnNotImplemented
,
202 NaClDescPostNotImplemented
,
203 NaClDescSemWaitNotImplemented
,
204 NaClDescGetValueNotImplemented
,
207 int NaClDescDirInternalize(struct NaClDesc
**baseptr
,
208 struct NaClDescXferState
*xfer
)
210 NaClLog(LOG_ERROR
, "NaClDescDirDescInternalize: not implemented for dir\n");
211 return -NACL_ABI_EINVAL
;