db_files.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. /* Copyright (C) 2014 Stony Brook University
  2. This file is part of Graphene Library OS.
  3. Graphene Library OS is free software: you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public License
  5. as published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. Graphene Library OS is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. /*
  14. * db_files.c
  15. *
  16. * This file contains operands to handle streams with URIs that start with
  17. * "file:" or "dir:".
  18. */
  19. #include <linux/types.h>
  20. #include "api.h"
  21. #include "assert.h"
  22. #include "pal.h"
  23. #include "pal_debug.h"
  24. #include "pal_defs.h"
  25. #include "pal_error.h"
  26. #include "pal_internal.h"
  27. #include "pal_linux.h"
  28. #include "pal_linux_defs.h"
  29. #include "pal_linux_error.h"
  30. typedef __kernel_pid_t pid_t;
  31. #undef __GLIBC__
  32. #include <asm/fcntl.h>
  33. #include <asm/stat.h>
  34. #include <linux/fs.h>
  35. #include <linux/stat.h>
  36. #include "enclave_pages.h"
  37. /* 'open' operation for file streams */
  38. static int file_open(PAL_HANDLE* handle, const char* type, const char* uri, int access, int share,
  39. int create, int options) {
  40. if (strcmp_static(type, "file"))
  41. return -PAL_ERROR_INVAL;
  42. /* try to do the real open */
  43. int fd = ocall_open(uri, access | create | options, share);
  44. if (IS_ERR(fd))
  45. return unix_to_pal_error(ERRNO(fd));
  46. /* if try_create_path succeeded, prepare for the file handle */
  47. size_t len = strlen(uri) + 1;
  48. PAL_HANDLE hdl = malloc(HANDLE_SIZE(file) + len);
  49. SET_HANDLE_TYPE(hdl, file);
  50. HANDLE_HDR(hdl)->flags |= RFD(0) | WFD(0) | WRITABLE(0);
  51. hdl->file.fd = fd;
  52. char* path = (void*)hdl + HANDLE_SIZE(file);
  53. int ret;
  54. if ((ret = get_norm_path(uri, path, &len)) < 0) {
  55. SGX_DBG(DBG_E, "Could not normalize path (%s): %s\n", uri, pal_strerror(ret));
  56. free(hdl);
  57. return ret;
  58. }
  59. hdl->file.realpath = (PAL_STR)path;
  60. sgx_stub_t* stubs;
  61. uint64_t total;
  62. ret = load_trusted_file(hdl, &stubs, &total, create);
  63. if (ret < 0) {
  64. SGX_DBG(DBG_E,
  65. "Accessing file:%s is denied. (%s) "
  66. "This file is not trusted or allowed.\n",
  67. hdl->file.realpath, pal_strerror(ret));
  68. free(hdl);
  69. return ret;
  70. }
  71. hdl->file.stubs = (PAL_PTR)stubs;
  72. hdl->file.total = total;
  73. hdl->file.offset = 0;
  74. if (hdl->file.stubs) {
  75. /* case of trusted file: mmap the whole file in untrusted memory for future reads/writes */
  76. ret = ocall_map_untrusted(hdl->file.fd, 0, hdl->file.total, PROT_READ, &hdl->file.umem);
  77. if (IS_ERR(ret)) {
  78. /* note that we don't free stubs because they are re-used in same trusted file */
  79. free(hdl);
  80. return unix_to_pal_error(ERRNO(ret));
  81. }
  82. }
  83. *handle = hdl;
  84. return 0;
  85. }
  86. /* 'read' operation for file streams. */
  87. static int64_t file_read(PAL_HANDLE handle, uint64_t offset, uint64_t count, void* buffer) {
  88. int64_t ret;
  89. sgx_stub_t* stubs = (sgx_stub_t*)handle->file.stubs;
  90. if (!stubs) {
  91. /* case of allowed file: emulate via lseek + read */
  92. if (handle->file.offset != offset) {
  93. ret = ocall_lseek(handle->file.fd, offset, SEEK_SET);
  94. if (IS_ERR(ret))
  95. return -PAL_ERROR_DENIED;
  96. handle->file.offset = offset;
  97. }
  98. ret = ocall_read(handle->file.fd, buffer, count);
  99. if (IS_ERR(ret))
  100. return unix_to_pal_error(ERRNO(ret));
  101. handle->file.offset = offset + ret;
  102. return ret;
  103. }
  104. /* case of trusted file: already mmaped in umem, copy from there and verify hash */
  105. uint64_t total = handle->file.total;
  106. if (offset >= total)
  107. return 0;
  108. uint64_t end = (offset + count > total) ? total : offset + count;
  109. uint64_t map_start = ALIGN_DOWN(offset, TRUSTED_STUB_SIZE);
  110. uint64_t map_end = ALIGN_UP(end, TRUSTED_STUB_SIZE);
  111. if (map_end > total)
  112. map_end = ALLOC_ALIGNUP(total);
  113. ret = copy_and_verify_trusted_file(handle->file.realpath, handle->file.umem + map_start,
  114. map_start, map_end, buffer, offset, end - offset, stubs, total);
  115. if (ret < 0)
  116. return ret;
  117. return end - offset;
  118. }
  119. /* 'write' operation for file streams. */
  120. static int64_t file_write(PAL_HANDLE handle, uint64_t offset, uint64_t count, const void* buffer) {
  121. int64_t ret;
  122. sgx_stub_t* stubs = (sgx_stub_t*)handle->file.stubs;
  123. if (!stubs) {
  124. /* case of allowed file: emulate via lseek + write */
  125. if (handle->file.offset != offset) {
  126. ret = ocall_lseek(handle->file.fd, offset, SEEK_SET);
  127. if (IS_ERR(ret))
  128. return -PAL_ERROR_DENIED;
  129. handle->file.offset = offset;
  130. }
  131. ret = ocall_write(handle->file.fd, buffer, count);
  132. if (IS_ERR(ret))
  133. return unix_to_pal_error(ERRNO(ret));
  134. handle->file.offset = offset + ret;
  135. return ret;
  136. }
  137. /* case of trusted file: disallow writing completely */
  138. SGX_DBG(DBG_E, "Writing to a trusted file (%s) is disallowed!\n", handle->file.realpath);
  139. return -PAL_ERROR_DENIED;
  140. }
  141. /* 'close' operation for file streams. In this case, it will only
  142. close the file without deleting it. */
  143. static int file_close(PAL_HANDLE handle) {
  144. int fd = handle->file.fd;
  145. if (handle->file.stubs) {
  146. /* case of trusted file: the whole file was mmapped in untrusted memory */
  147. ocall_unmap_untrusted(handle->file.umem, handle->file.total);
  148. }
  149. ocall_close(fd);
  150. /* initial realpath is part of handle object and will be freed with it */
  151. if (handle->file.realpath && handle->file.realpath != (void*)handle + HANDLE_SIZE(file))
  152. free((void*)handle->file.realpath);
  153. return 0;
  154. }
  155. /* 'delete' operation for file streams. It will actually delete
  156. the file if we can successfully close it. */
  157. static int file_delete(PAL_HANDLE handle, int access) {
  158. if (access)
  159. return -PAL_ERROR_INVAL;
  160. int ret = ocall_delete(handle->file.realpath);
  161. return IS_ERR(ret) ? unix_to_pal_error(ERRNO(ret)) : ret;
  162. }
  163. /* 'map' operation for file stream. */
  164. static int file_map(PAL_HANDLE handle, void** addr, int prot, uint64_t offset, uint64_t size) {
  165. sgx_stub_t* stubs = (sgx_stub_t*)handle->file.stubs;
  166. uint64_t total = handle->file.total;
  167. void* mem = *addr;
  168. void* umem;
  169. int ret;
  170. /*
  171. * If the file is listed in the manifest as an "allowed" file,
  172. * we allow mapping the file outside the enclave, if the library OS
  173. * does not request a specific address.
  174. */
  175. if (!mem && !stubs && !(prot & PAL_PROT_WRITECOPY)) {
  176. ret = ocall_map_untrusted(handle->file.fd, offset, size, HOST_PROT(prot), &mem);
  177. if (!IS_ERR(ret))
  178. *addr = mem;
  179. return IS_ERR(ret) ? unix_to_pal_error(ERRNO(ret)) : ret;
  180. }
  181. if (!(prot & PAL_PROT_WRITECOPY) && (prot & PAL_PROT_WRITE)) {
  182. SGX_DBG(DBG_E,
  183. "file_map does not currently support writable pass-through mappings on SGX. You "
  184. "may add the PAL_PROT_WRITECOPY (MAP_PRIVATE) flag to your file mapping to keep "
  185. "the writes inside the enclave but they won't be reflected outside of the "
  186. "enclave.\n");
  187. return -PAL_ERROR_DENIED;
  188. }
  189. mem = get_reserved_pages(mem, size);
  190. if (!mem)
  191. return -PAL_ERROR_NOMEM;
  192. uint64_t end = (offset + size > total) ? total : offset + size;
  193. uint64_t map_start, map_end;
  194. if (stubs) {
  195. map_start = ALIGN_DOWN(offset, TRUSTED_STUB_SIZE);
  196. map_end = ALIGN_UP(end, TRUSTED_STUB_SIZE);
  197. } else {
  198. map_start = ALLOC_ALIGNDOWN(offset);
  199. map_end = ALLOC_ALIGNUP(end);
  200. }
  201. ret = ocall_map_untrusted(handle->file.fd, map_start, map_end - map_start, PROT_READ, &umem);
  202. if (IS_ERR(ret)) {
  203. SGX_DBG(DBG_E, "file_map - ocall returned %d\n", ret);
  204. return unix_to_pal_error(ERRNO(ret));
  205. }
  206. if (stubs) {
  207. ret = copy_and_verify_trusted_file(handle->file.realpath, umem, map_start, map_end, mem,
  208. offset, end - offset, stubs, total);
  209. if (ret < 0) {
  210. SGX_DBG(DBG_E, "file_map - verify trusted returned %d\n", ret);
  211. ocall_unmap_untrusted(umem, map_end - map_start);
  212. return ret;
  213. }
  214. } else {
  215. memcpy(mem, umem + (offset - map_start), end - offset);
  216. }
  217. ocall_unmap_untrusted(umem, map_end - map_start);
  218. *addr = mem;
  219. return 0;
  220. }
  221. /* 'setlength' operation for file stream. */
  222. static int64_t file_setlength(PAL_HANDLE handle, uint64_t length) {
  223. int ret = ocall_ftruncate(handle->file.fd, length);
  224. if (IS_ERR(ret))
  225. return unix_to_pal_error(ERRNO(ret));
  226. handle->file.total = length;
  227. return (int64_t)length;
  228. }
  229. /* 'flush' operation for file stream. */
  230. static int file_flush(PAL_HANDLE handle) {
  231. ocall_fsync(handle->file.fd);
  232. return 0;
  233. }
  234. static inline int file_stat_type(struct stat* stat) {
  235. if (S_ISREG(stat->st_mode))
  236. return pal_type_file;
  237. if (S_ISDIR(stat->st_mode))
  238. return pal_type_dir;
  239. if (S_ISCHR(stat->st_mode))
  240. return pal_type_dev;
  241. if (S_ISFIFO(stat->st_mode))
  242. return pal_type_pipe;
  243. if (S_ISSOCK(stat->st_mode))
  244. return pal_type_dev;
  245. return 0;
  246. }
  247. /* copy attr content from POSIX stat struct to PAL_STREAM_ATTR */
  248. static inline void file_attrcopy(PAL_STREAM_ATTR* attr, struct stat* stat) {
  249. attr->handle_type = file_stat_type(stat);
  250. attr->disconnected = PAL_FALSE;
  251. attr->nonblocking = PAL_FALSE;
  252. attr->readable = stataccess(stat, ACCESS_R);
  253. attr->writable = stataccess(stat, ACCESS_W);
  254. attr->runnable = stataccess(stat, ACCESS_X);
  255. attr->share_flags = stat->st_mode;
  256. attr->pending_size = stat->st_size;
  257. }
  258. /* 'attrquery' operation for file streams */
  259. static int file_attrquery(const char* type, const char* uri, PAL_STREAM_ATTR* attr) {
  260. if (strcmp_static(type, "file") && strcmp_static(type, "dir"))
  261. return -PAL_ERROR_INVAL;
  262. /* try to do the real open */
  263. int fd = ocall_open(uri, 0, 0);
  264. if (IS_ERR(fd))
  265. return unix_to_pal_error(ERRNO(fd));
  266. struct stat stat_buf;
  267. int ret = ocall_fstat(fd, &stat_buf);
  268. ocall_close(fd);
  269. /* if it failed, return the right error code */
  270. if (IS_ERR(ret))
  271. return unix_to_pal_error(ERRNO(ret));
  272. file_attrcopy(attr, &stat_buf);
  273. return 0;
  274. }
  275. /* 'attrquerybyhdl' operation for file streams */
  276. static int file_attrquerybyhdl(PAL_HANDLE handle, PAL_STREAM_ATTR* attr) {
  277. int fd = handle->file.fd;
  278. struct stat stat_buf;
  279. int ret = ocall_fstat(fd, &stat_buf);
  280. if (IS_ERR(ret))
  281. return unix_to_pal_error(ERRNO(ret));
  282. file_attrcopy(attr, &stat_buf);
  283. return 0;
  284. }
  285. static int file_attrsetbyhdl(PAL_HANDLE handle, PAL_STREAM_ATTR* attr) {
  286. int fd = handle->file.fd;
  287. int ret = ocall_fchmod(fd, attr->share_flags | 0600);
  288. if (IS_ERR(ret))
  289. return unix_to_pal_error(ERRNO(ret));
  290. return 0;
  291. }
  292. static int file_rename(PAL_HANDLE handle, const char* type, const char* uri) {
  293. if (strcmp_static(type, "file"))
  294. return -PAL_ERROR_INVAL;
  295. char* tmp = strdup(uri);
  296. if (!tmp)
  297. return -PAL_ERROR_NOMEM;
  298. int ret = ocall_rename(handle->file.realpath, uri);
  299. if (IS_ERR(ret)) {
  300. free(tmp);
  301. return unix_to_pal_error(ERRNO(ret));
  302. }
  303. /* initial realpath is part of handle object and will be freed with it */
  304. if (handle->file.realpath && handle->file.realpath != (void*)handle + HANDLE_SIZE(file)) {
  305. free((void*)handle->file.realpath);
  306. }
  307. handle->file.realpath = tmp;
  308. return 0;
  309. }
  310. static int file_getname(PAL_HANDLE handle, char* buffer, size_t count) {
  311. if (!handle->file.realpath)
  312. return 0;
  313. int len = strlen(handle->file.realpath);
  314. char* tmp = strcpy_static(buffer, "file:", count);
  315. if (!tmp || buffer + count < tmp + len + 1)
  316. return -PAL_ERROR_TOOLONG;
  317. memcpy(tmp, handle->file.realpath, len + 1);
  318. return tmp + len - buffer;
  319. }
  320. const char* file_getrealpath(PAL_HANDLE handle) {
  321. return handle->file.realpath;
  322. }
  323. struct handle_ops file_ops = {
  324. .getname = &file_getname,
  325. .getrealpath = &file_getrealpath,
  326. .open = &file_open,
  327. .read = &file_read,
  328. .write = &file_write,
  329. .close = &file_close,
  330. .delete = &file_delete,
  331. .map = &file_map,
  332. .setlength = &file_setlength,
  333. .flush = &file_flush,
  334. .attrquery = &file_attrquery,
  335. .attrquerybyhdl = &file_attrquerybyhdl,
  336. .attrsetbyhdl = &file_attrsetbyhdl,
  337. .rename = &file_rename,
  338. };
  339. /* 'open' operation for directory stream. Directory stream does not have a
  340. specific type prefix, its URI looks the same file streams, plus it
  341. ended with slashes. dir_open will be called by file_open. */
  342. static int dir_open(PAL_HANDLE* handle, const char* type, const char* uri, int access, int share,
  343. int create, int options) {
  344. if (strcmp_static(type, "dir"))
  345. return -PAL_ERROR_INVAL;
  346. if (!WITHIN_MASK(access, PAL_ACCESS_MASK))
  347. return -PAL_ERROR_INVAL;
  348. int ret;
  349. if (create & PAL_CREATE_TRY) {
  350. ret = ocall_mkdir(uri, share);
  351. if (IS_ERR(ret) && ERRNO(ret) == EEXIST && create & PAL_CREATE_ALWAYS)
  352. return -PAL_ERROR_STREAMEXIST;
  353. }
  354. ret = ocall_open(uri, O_DIRECTORY | options, 0);
  355. if (IS_ERR(ret))
  356. return unix_to_pal_error(ERRNO(ret));
  357. int len = strlen(uri);
  358. PAL_HANDLE hdl = malloc(HANDLE_SIZE(dir) + len + 1);
  359. SET_HANDLE_TYPE(hdl, dir);
  360. HANDLE_HDR(hdl)->flags |= RFD(0);
  361. hdl->dir.fd = ret;
  362. char* path = (void*)hdl + HANDLE_SIZE(dir);
  363. memcpy(path, uri, len + 1);
  364. hdl->dir.realpath = (PAL_STR)path;
  365. hdl->dir.buf = (PAL_PTR)NULL;
  366. hdl->dir.ptr = (PAL_PTR)NULL;
  367. hdl->dir.end = (PAL_PTR)NULL;
  368. hdl->dir.endofstream = PAL_FALSE;
  369. *handle = hdl;
  370. return 0;
  371. }
  372. #define DIRBUF_SIZE 1024
  373. static inline bool is_dot_or_dotdot(const char* name) {
  374. return (name[0] == '.' && !name[1]) || (name[0] == '.' && name[1] == '.' && !name[2]);
  375. }
  376. /* 'read' operation for directory stream. Directory stream will not
  377. need a 'write' operation. */
  378. static int64_t dir_read(PAL_HANDLE handle, uint64_t offset, size_t count, void* _buf) {
  379. size_t bytes_written = 0;
  380. char* buf = (char*)_buf;
  381. if (offset) {
  382. return -PAL_ERROR_INVAL;
  383. }
  384. if (handle->dir.endofstream == PAL_TRUE) {
  385. return -PAL_ERROR_ENDOFSTREAM;
  386. }
  387. while (1) {
  388. while ((char*)handle->dir.ptr < (char*)handle->dir.end) {
  389. struct linux_dirent64* dirent = (struct linux_dirent64*)handle->dir.ptr;
  390. if (is_dot_or_dotdot(dirent->d_name)) {
  391. goto skip;
  392. }
  393. bool is_dir = dirent->d_type == DT_DIR;
  394. size_t len = strlen(dirent->d_name);
  395. if (len + 1 + (is_dir ? 1 : 0) > count) {
  396. goto out;
  397. }
  398. memcpy(buf, dirent->d_name, len);
  399. if (is_dir) {
  400. buf[len++] = '/';
  401. }
  402. buf[len++] = '\0';
  403. buf += len;
  404. bytes_written += len;
  405. count -= len;
  406. skip:
  407. handle->dir.ptr = (char*)handle->dir.ptr + dirent->d_reclen;
  408. }
  409. if (!count) {
  410. /* No space left, returning */
  411. goto out;
  412. }
  413. if (!handle->dir.buf) {
  414. handle->dir.buf = (PAL_PTR)malloc(DIRBUF_SIZE);
  415. if (!handle->dir.buf) {
  416. return -PAL_ERROR_NOMEM;
  417. }
  418. }
  419. int size = ocall_getdents(handle->dir.fd, handle->dir.buf, DIRBUF_SIZE);
  420. if (IS_ERR(size)) {
  421. /*
  422. * If something was written just return that and pretend no error
  423. * was seen - it will be caught next time.
  424. */
  425. if (bytes_written) {
  426. return bytes_written;
  427. }
  428. return unix_to_pal_error(ERRNO(size));
  429. }
  430. if (!size) {
  431. handle->dir.endofstream = PAL_TRUE;
  432. goto out;
  433. }
  434. handle->dir.ptr = handle->dir.buf;
  435. handle->dir.end = (char*)handle->dir.buf + size;
  436. }
  437. out:
  438. return (int64_t)bytes_written ?: -PAL_ERROR_ENDOFSTREAM;
  439. }
  440. /* 'close' operation of directory streams */
  441. static int dir_close(PAL_HANDLE handle) {
  442. int fd = handle->dir.fd;
  443. ocall_close(fd);
  444. if (handle->dir.buf) {
  445. free((void*)handle->dir.buf);
  446. handle->dir.buf = handle->dir.ptr = handle->dir.end = (PAL_PTR)NULL;
  447. }
  448. /* initial realpath is part of handle object and will be freed with it */
  449. if (handle->dir.realpath && handle->dir.realpath != (void*)handle + HANDLE_SIZE(dir))
  450. free((void*)handle->dir.realpath);
  451. return 0;
  452. }
  453. /* 'delete' operation of directoy streams */
  454. static int dir_delete(PAL_HANDLE handle, int access) {
  455. if (access)
  456. return -PAL_ERROR_INVAL;
  457. int ret = dir_close(handle);
  458. if (ret < 0)
  459. return ret;
  460. ret = ocall_delete(handle->dir.realpath);
  461. return IS_ERR(ret) ? unix_to_pal_error(ERRNO(ret)) : ret;
  462. }
  463. static int dir_rename(PAL_HANDLE handle, const char* type, const char* uri) {
  464. if (strcmp_static(type, "dir"))
  465. return -PAL_ERROR_INVAL;
  466. char* tmp = strdup(uri);
  467. if (!tmp)
  468. return -PAL_ERROR_NOMEM;
  469. int ret = ocall_rename(handle->dir.realpath, uri);
  470. if (IS_ERR(ret)) {
  471. free(tmp);
  472. return unix_to_pal_error(ERRNO(ret));
  473. }
  474. /* initial realpath is part of handle object and will be freed with it */
  475. if (handle->dir.realpath && handle->dir.realpath != (void*)handle + HANDLE_SIZE(dir)) {
  476. free((void*)handle->dir.realpath);
  477. }
  478. handle->dir.realpath = tmp;
  479. return 0;
  480. }
  481. static int dir_getname(PAL_HANDLE handle, char* buffer, size_t count) {
  482. if (!handle->dir.realpath)
  483. return 0;
  484. size_t len = strlen(handle->dir.realpath);
  485. char* tmp = strcpy_static(buffer, "dir:", count);
  486. if (!tmp || buffer + count < tmp + len + 1)
  487. return -PAL_ERROR_TOOLONG;
  488. memcpy(tmp, handle->dir.realpath, len + 1);
  489. return tmp + len - buffer;
  490. if (len + 6 >= count)
  491. return -PAL_ERROR_TOOLONG;
  492. }
  493. static const char* dir_getrealpath(PAL_HANDLE handle) {
  494. return handle->dir.realpath;
  495. }
  496. struct handle_ops dir_ops = {
  497. .getname = &dir_getname,
  498. .getrealpath = &dir_getrealpath,
  499. .open = &dir_open,
  500. .read = &dir_read,
  501. .close = &dir_close,
  502. .delete = &dir_delete,
  503. .attrquery = &file_attrquery,
  504. .attrquerybyhdl = &file_attrquerybyhdl,
  505. .attrsetbyhdl = &file_attrsetbyhdl,
  506. .rename = &dir_rename,
  507. };