10_filesystem.rst 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. ======================
  2. File System Interfaces
  3. ======================
  4. .. _file_system_overview:
  5. NuttX File System Overview
  6. ==========================
  7. **Overview**. NuttX includes an optional, scalable file system. This
  8. file-system may be omitted altogether; NuttX does not depend on the
  9. presence of any file system.
  10. **Pseudo Root File System**. A simple *in-memory*, *pseudo* file system
  11. can be enabled by default. This is an *in-memory* file system because it
  12. does not require any storage medium or block driver support. Rather,
  13. file system contents are generated on-the-fly as referenced via standard
  14. file system operations (open, close, read, write, etc.). In this sense,
  15. the file system is *pseudo* file system (in the same sense that the
  16. Linux ``/proc`` file system is also referred to as a pseudo file
  17. system).
  18. Any user supplied data or logic can be accessed via the pseudo-file
  19. system. Built in support is provided for character and block
  20. :ref:`driver <drivers-porting>` *nodes* in the any
  21. pseudo file system directory. (By convention, however, all driver nodes
  22. should be in the ``/dev`` pseudo file system directory).
  23. **Mounted File Systems** The simple in-memory file system can be
  24. extended my mounting block devices that provide access to true file
  25. systems backed up via some mass storage device. NuttX supports the
  26. standard ``mount()`` command that allows a block driver to be bound to a
  27. mount-point within the pseudo file system and to a a file system. At
  28. present, NuttX supports only the VFAT file system.
  29. **Comparison to Linux** From a programming perspective, the NuttX file
  30. system appears very similar to a Linux file system. However, there is a
  31. fundamental difference: The NuttX root file system is a pseudo file
  32. system and true file systems may be mounted in the pseudo file system.
  33. In the typical Linux installation by comparison, the Linux root file
  34. system is a true file system and pseudo file systems may be mounted in
  35. the true, root file system. The approach selected by NuttX is intended
  36. to support greater scalability from the very tiny platform to the
  37. moderate platform.
  38. **File System Interfaces**. The NuttX file system simply supports a set
  39. of standard, file system APIs (``open()``, ``close()``, ``read()``,
  40. ``write``, etc.) and a registration mechanism that allows devices
  41. drivers to a associated with *nodes* in a file-system-like name space.
  42. Driver Operations
  43. =================
  44. ``fcntl.h``
  45. -----------
  46. .. c:function:: int creat(FAR const char *path, mode_t mode);
  47. .. c:function:: int open(FAR const char *path, int oflag, ...);
  48. .. c:function:: int fcntl(int fd, int cmd, ...);
  49. ``unistd.h``
  50. ------------
  51. .. c:function:: int close(int fd);
  52. .. c:function:: int dup(int fd);
  53. .. c:function:: int dup2(int fd1, int fd2);
  54. .. c:function:: off_t lseek(int fd, off_t offset, int whence);
  55. .. c:function:: ssize_t pread(int fd, void *buf, size_t nbytes, off_t offset);
  56. .. c:function:: ssize_t pwrite(int fd, const void *buf, size_t nbytes, off_t offset);
  57. .. c:function:: ssize_t read(int fd, void *buf, size_t nbytes);
  58. .. c:function:: int unlink(const char *path);
  59. .. c:function:: ssize_t write(int fd, const void *buf, size_t nbytes);
  60. ``sys/ioctl.h``
  61. ---------------
  62. .. c:function:: int ioctl(int fd, int req, ...)
  63. ``poll.h``
  64. ----------
  65. .. c:function:: int poll(struct pollfd *fds, nfds_t nfds, int timeout)
  66. Waits for one of a set of file descriptors
  67. to become ready to perform I/O. If none of the events requested (and no
  68. error) has occurred for any of the file descriptors, then ``poll()``
  69. blocks until one of the events occurs.
  70. **Configuration Settings**. In order to use the select with TCP/IP
  71. sockets test, you must have the following things selected in your NuttX
  72. configuration file:
  73. - ``CONFIG_NET`` Defined for general network support
  74. - ``CONFIG_NET_TCP`` Defined for TCP/IP support
  75. In order to for select to work with incoming connections, you must also
  76. select:
  77. - ``CONFIG_NET_TCPBACKLOG`` Incoming connections pend in a backlog
  78. until ``accept()`` is called. The size of the backlog is selected
  79. when ``listen()`` is called.
  80. :param fds: List of structures describing file descriptors to be
  81. monitored.
  82. :param nfds: The number of entries in the list.
  83. :param timeout: Specifies an upper limit on the time for which
  84. ``poll()`` will block in milliseconds. A negative value of
  85. ``timeout`` means an infinite timeout.
  86. :return:
  87. On success, the number of structures that have nonzero ``revents``
  88. fields. A value of 0 indicates that the call timed out and no file
  89. descriptors were ready. On error, -1 is returned, and ``errno`` is set
  90. appropriately:
  91. - ``EBADF``. An invalid file descriptor was given in one of the sets.
  92. - ``EFAULT``. The fds address is invalid
  93. - ``EINTR``. A signal occurred before any requested event.
  94. - ``EINVAL``. The nfds value exceeds a system limit.
  95. - ``ENOMEM``. There was no space to allocate internal data structures.
  96. - ``ENOSYS``. One or more of the drivers supporting the file descriptor
  97. does not support the poll method.
  98. ``sys/select.h``
  99. ----------------
  100. .. c:function:: int select(int nfds, FAR fd_set *readfds, FAR fd_set *writefds, \
  101. FAR fd_set *exceptfds, FAR struct timeval *timeout)
  102. Allows a program to monitor multiple file
  103. descriptors, waiting until one or more of the file descriptors become
  104. "ready" for some class of I/O operation (e.g., input possible). A file
  105. descriptor is considered ready if it is possible to perform the
  106. corresponding I/O operation (e.g., read(2)) without blocking.
  107. **NOTE:** ```poll()`` <#poll>`__ is the fundamental API for performing
  108. such monitoring operation under NuttX. ``select()`` is provided for
  109. compatibility and is simply a layer of added logic on top of ``poll()``.
  110. As such, ``select()`` is more wasteful of resources and
  111. ```poll()`` <#poll>`__ is the recommended API to be used.
  112. :param nfds: the maximum file descriptor number (+1) of any descriptor
  113. in any of the three sets.
  114. :param readfds: the set of descriptions to monitor for read-ready events
  115. :param writefds: the set of descriptions to monitor for write-ready
  116. events
  117. :param exceptfds: the set of descriptions to monitor for error events
  118. :param timeout: Return at this time if none of these events of interest
  119. occur.
  120. :return:
  121. - ``0:`` Timer expired
  122. - ``>0:`` The number of bits set in the three sets of descriptors
  123. - ``-1:`` An error occurred (``errno`` will be set appropriately, see
  124. ```poll()`` <#poll>`__).
  125. Directory Operations (``dirent.h``)
  126. -----------------------------------
  127. .. c:function:: int closedir(DIR *dirp);
  128. .. c:function:: FAR DIR *opendir(const char *path);
  129. .. c:function:: FAR struct dirent *readdir(FAR DIR *dirp);
  130. .. c:function:: int readdir_r(FAR DIR *dirp, FAR struct dirent *entry, FAR struct dirent **result);
  131. .. c:function:: void rewinddir(FAR DIR *dirp);
  132. .. c:function:: void seekdir(FAR DIR *dirp, int loc);
  133. .. c:function:: int telldir(FAR DIR *dirp);
  134. UNIX Standard Operations (``unistd.h``)
  135. ---------------------------------------
  136. .. code-block:: c
  137. #include <unistd.h>
  138. /* Task Control Interfaces */
  139. pid_t vfork(void);
  140. pid_t getpid(void);
  141. void _exit(int status) noreturn_function;
  142. unsigned int sleep(unsigned int seconds);
  143. void usleep(unsigned long usec);
  144. int pause(void);
  145. /* File descriptor operations */
  146. int close(int fd);
  147. int dup(int fd);
  148. int dup2(int fd1, int fd2);
  149. int fsync(int fd);
  150. off_t lseek(int fd, off_t offset, int whence);
  151. ssize_t read(int fd, FAR void *buf, size_t nbytes);
  152. ssize_t write(int fd, FAR const void *buf, size_t nbytes);
  153. ssize_t pread(int fd, FAR void *buf, size_t nbytes, off_t offset);
  154. ssize_t pwrite(int fd, FAR const void *buf, size_t nbytes, off_t offset);
  155. /* Check if a file descriptor corresponds to a terminal I/O file */
  156. int isatty(int fd);
  157. /* Memory management */
  158. #if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_MM_PGALLOC) && \
  159. defined(CONFIG_ARCH_USE_MMU)
  160. FAR void *sbrk(intptr_t incr);
  161. #endif
  162. /* Special devices */
  163. int pipe(int fd[2]);
  164. /* Working directory operations */
  165. int chdir(FAR const char *path);
  166. FAR char *getcwd(FAR char *buf, size_t size);
  167. /* File path operations */
  168. int access(FAR const char *path, int amode);
  169. int rmdir(FAR const char *pathname);
  170. int unlink(FAR const char *pathname);
  171. #ifdef CONFIG_PSEUDOFS_SOFTLINKS
  172. int link(FAR const char *path1, FAR const char *path2);
  173. ssize_t readlink(FAR const char *path, FAR char *buf, size_t bufsize);
  174. #endif
  175. /* Execution of programs from files */
  176. #ifdef CONFIG_LIBC_EXECFUNCS
  177. int execl(FAR const char *path, ...);
  178. int execv(FAR const char *path, FAR char * const argv[]);
  179. #endif
  180. /* Networking */
  181. #ifdef CONFIG_NET
  182. int gethostname(FAR char *name, size_t size);
  183. int sethostname(FAR const char *name, size_t size);
  184. #endif
  185. /* Other */
  186. int getopt(int argc, FAR char * const argv[], FAR const char *optstring);
  187. Standard I/O
  188. ------------
  189. .. code-block:: c
  190. #include <stdio.h>
  191. /* Operations on streams (FILE) */
  192. void clearerr(FAR FILE *stream);
  193. int fclose(FAR FILE *stream);
  194. int fflush(FAR FILE *stream);
  195. int feof(FAR FILE *stream);
  196. int ferror(FAR FILE *stream);
  197. int fileno(FAR FILE *stream);
  198. int fgetc(FAR FILE *stream);
  199. int fgetpos(FAR FILE *stream, FAR fpos_t *pos);
  200. FAR char *fgets(FAR char *s, int n, FAR FILE *stream);
  201. FAR FILE *fopen(FAR const char *path, FAR const char *type);
  202. int fprintf(FAR FILE *stream, FAR const char *format, ...);
  203. int fputc(int c, FAR FILE *stream);
  204. int fputs(FAR const char *s, FAR FILE *stream);
  205. size_t fread(FAR void *ptr, size_t size, size_t n_items, FAR FILE *stream);
  206. FAR FILE *freopen(FAR const char *path, FAR const char *mode,
  207. FAR FILE *stream);
  208. int fseek(FAR FILE *stream, long int offset, int whence);
  209. int fsetpos(FAR FILE *stream, FAR fpos_t *pos);
  210. long ftell(FAR FILE *stream);
  211. size_t fwrite(FAR const void *ptr, size_t size, size_t n_items, FAR FILE *stream);
  212. FAR char *gets(FAR char *s);
  213. FAR char *gets_s(FAR char *s, rsize_t n);
  214. void setbuf(FAR FILE *stream, FAR char *buf);
  215. int setvbuf(FAR FILE *stream, FAR char *buffer, int mode, size_t size);
  216. int ungetc(int c, FAR FILE *stream);
  217. /* Operations on the stdout stream, buffers, paths, and the whole printf-family * /
  218. int printf(FAR const char *format, ...);
  219. int puts(FAR const char *s);
  220. int rename(FAR const char *source, FAR const char *target);
  221. int sprintf(FAR char *dest, FAR const char *format, ...);
  222. int asprintf(FAR char **ptr, FAR const char *fmt, ...);
  223. int snprintf(FAR char *buf, size_t size, FAR const char *format, ...);
  224. int sscanf(FAR const char *buf, FAR const char *fmt, ...);
  225. void perror(FAR const char *s);
  226. int vprintf(FAR const char *s, va_list ap);
  227. int vfprintf(FAR FILE *stream, FAR const char *s, va_list ap);
  228. int vsprintf(FAR char *buf, FAR const char *s, va_list ap);
  229. int vasprintf(FAR char **ptr, FAR const char *fmt, va_list ap);
  230. int vsnprintf(FAR char *buf, size_t size, FAR const char *format, va_list ap);
  231. int vsscanf(FAR char *buf, FAR const char *s, va_list ap);
  232. /* Operations on file descriptors including:
  233. *
  234. * POSIX-like File System Interfaces (fdopen), and
  235. * Extensions from the Open Group Technical Standard, 2006, Extended API Set
  236. * Part 1 (dprintf and vdprintf)
  237. */
  238. FAR FILE *fdopen(int fd, FAR const char *type);
  239. int dprintf(int fd, FAR const char *fmt, ...);
  240. int vdprintf(int fd, FAR const char *fmt, va_list ap);
  241. /* Operations on paths */
  242. FAR char *tmpnam(FAR char *s);
  243. FAR char *tempnam(FAR const char *dir, FAR const char *pfx);
  244. int remove(FAR const char *path);
  245. #include <sys/stat.h>
  246. int mkdir(FAR const char *pathname, mode_t mode);
  247. int mkfifo(FAR const char *pathname, mode_t mode);
  248. int stat(FAR const char *path, FAR struct stat *buf);
  249. int fstat(int fd, FAR struct stat *buf);
  250. #include <sys/statfs.h>
  251. int statfs(FAR const char *path, FAR struct statfs *buf);
  252. int fstatfs(int fd, FAR struct statfs *buf);
  253. Standard Library (``stdlib.h``)
  254. -------------------------------
  255. Generally addresses other operating system interfaces.
  256. However, the following may also be considered as file system interfaces:
  257. .. c:function:: int mktemp(FAR char *template);
  258. .. c:function:: int mkstemp(FAR char *template);
  259. Asynchronous I/O
  260. ----------------
  261. .. code-block:: c
  262. #include <aio.h>
  263. int aio_cancel(int, FAR struct aiocb *aiocbp);
  264. int aio_error(FAR const struct aiocb *aiocbp);
  265. int aio_fsync(int, FAR struct aiocb *aiocbp);
  266. int aio_read(FAR struct aiocb *aiocbp);
  267. ssize_t aio_return(FAR struct aiocb *aiocbp);
  268. int aio_suspend(FAR const struct aiocb * const list[], int nent,
  269. FAR const struct timespec *timeout);
  270. int aio_write(FAR struct aiocb *aiocbp);
  271. int lio_listio(int mode, FAR struct aiocb * const list[], int nent,
  272. FAR struct sigevent *sig);
  273. Standard String Operations
  274. --------------------------
  275. .. code-block:: c
  276. #include <string.h>
  277. char *strchr(const char *s, int c);
  278. FAR char *strdup(const char *s);
  279. const char *strerror(int);
  280. size_t strlen(const char *);
  281. size_t strnlen(const char *, size_t);
  282. char *strcat(char *, const char *);
  283. char *strncat(char *, const char *, size_t);
  284. int strcmp(const char *, const char *);
  285. int strncmp(const char *, const char *, size_t);
  286. int strcasecmp(const char *, const char *);
  287. int strncasecmp(const char *, const char *, size_t);
  288. char *strcpy(char *dest, const char *src);
  289. char *strncpy(char *, const char *, size_t);
  290. char *strpbrk(const char *, const char *);
  291. char *strchr(const char *, int);
  292. char *strrchr(const char *, int);
  293. size_t strspn(const char *, const char *);
  294. size_t strcspn(const char *, const char *);
  295. char *strstr(const char *, const char *);
  296. char *strtok(char *, const char *);
  297. char *strtok_r(char *, const char *, char **);
  298. void *memset(void *s, int c, size_t n);
  299. void *memcpy(void *dest, const void *src, size_t n);
  300. int memcmp(const void *s1, const void *s2, size_t n);
  301. void *memmove(void *dest, const void *src, size_t count);
  302. #include <strings.h>
  303. #define bcmp(b1,b2,len) memcmp(b1,b2,(size_t)len)
  304. #define bcopy(b1,b2,len) (void)memmove(b2,b1,len)
  305. #define bzero(s,n) (void)memset(s,0,n)
  306. #define index(s,c) strchr(s,c)
  307. #define rindex(s,c) strrchr(s,c)
  308. int ffs(int j);
  309. int strcasecmp(const char *, const char *);
  310. int strncasecmp(const char *, const char *, size_t);
  311. Pipes and FIFOs
  312. ---------------
  313. .. c:function:: int pipe(int fd[2])
  314. Creates a pair of file descriptors, pointing to a pipe inode,
  315. and places them in the array pointed to by ``fd``.
  316. :param fd: The user provided array in which to catch the pipe file
  317. descriptors. ``fd[0]`` is for reading, ``fd[1]`` is for writing.
  318. :return: 0 is returned on success; otherwise, -1 is returned with errno set appropriately.
  319. .. c:function:: int mkfifo(FAR const char *pathname, mode_t mode);
  320. mkfifo() makes a FIFO device driver file with name pathname. Unlike Linux,
  321. a NuttX FIFO is not a special file type but simply a device driver instance.
  322. mode specifies the FIFO's permissions (but is ignored in the current implementation).
  323. Once the FIFO has been created by mkfifo(), any thread can open it for reading
  324. or writing, in the same way as an ordinary file. However, it must have been
  325. opened from both reading and writing before input or output can be performed.
  326. This FIFO implementation will block all attempts to open a FIFO read-only
  327. until at least one thread has opened the FIFO for writing.
  328. If all threads that write to the FIFO have closed, subsequent calls to
  329. read() on the FIFO will return 0 (end-of-file).
  330. :param pathname: The full path to the FIFO instance to attach to or to
  331. create (if not already created).
  332. :param mode: Ignored for now
  333. :return: 0 is returned on success; otherwise, -1 is returned with errno set appropriately.
  334. ``mmap()`` and eXecute In Place (XIP)
  335. -------------------------------------
  336. NuttX operates in a flat open address space and is focused on MCUs that
  337. do support Memory Management Units (MMUs). Therefore, NuttX generally
  338. does not require ``mmap()`` functionality and the MCUs generally cannot
  339. support true memory-mapped files.
  340. However, memory mapping of files is the mechanism used by NXFLAT, the
  341. NuttX tiny binary format, to get files into memory in order to execute
  342. them. ``mmap()`` support is therefore required to support NXFLAT. There
  343. are two conditions where ``mmap()`` can be supported:
  344. 1. ``mmap()`` can be used to support *eXecute In Place* (XIP) on random
  345. access media under the following very restrictive conditions:
  346. a. The file-system supports the ``FIOC_MMAP`` ioctl command. Any file
  347. system that maps files contiguously on the media should support
  348. this ``ioctl`` command. By comparison, most file system scatter
  349. files over the media in non-contiguous sectors. As of this
  350. writing, ROMFS is the only file system that meets this
  351. requirement.
  352. b. The underlying block driver supports the ``BIOC_XIPBASE``
  353. ``ioctl`` command that maps the underlying media to a randomly
  354. accessible address. At present, only the RAM/ROM disk driver does
  355. this.
  356. Some limitations of this approach are as follows:
  357. a. Since no real mapping occurs, all of the file contents are
  358. "mapped" into memory.
  359. b. All mapped files are read-only.
  360. c. There are no access privileges.
  361. 2. If ``CONFIG_FS_RAMMAP`` is defined in the configuration, then
  362. ``mmap()`` will support simulation of memory mapped files by copying
  363. files whole into RAM. These copied files have some of the properties
  364. of standard memory mapped files. There are many, many exceptions
  365. exceptions, however. Some of these include:
  366. a. The goal is to have a single region of memory that represents a
  367. single file and can be shared by many threads. That is, given a
  368. filename a thread should be able to open the file, get a file
  369. descriptor, and call ``mmap()`` to get a memory region. Different
  370. file descriptors opened with the same file path should get the
  371. same memory region when mapped.
  372. The limitation in the current design is that there is insufficient
  373. knowledge to know that these different file descriptors correspond
  374. to the same file. So, for the time being, a new memory region is
  375. created each time that ``rammmap()`` is called. Not very useful!
  376. b. The entire mapped portion of the file must be present in memory.
  377. Since it is assumed that the MCU does not have an MMU,
  378. on-demanding paging in of file blocks cannot be supported. Since
  379. the while mapped portion of the file must be present in memory,
  380. there are limitations in the size of files that may be memory
  381. mapped (especially on MCUs with no significant RAM resources).
  382. c. All mapped files are read-only. You can write to the in-memory
  383. image, but the file contents will not change.
  384. d. There are no access privileges.
  385. e. Since there are no processes in NuttX, all ``mmap()`` and
  386. ``munmap()`` operations have immediate, global effects. Under
  387. Linux, for example, ``munmap()`` would eliminate only the mapping
  388. with a process; the mappings to the same file in other processes
  389. would not be effected.
  390. f. Like true mapped file, the region will persist after closing the
  391. file descriptor. However, at present, these ram copied file
  392. regions are *not* automatically "unmapped" (i.e., freed) when a
  393. thread is terminated. This is primarily because it is not possible
  394. to know how many users of the mapped region there are and,
  395. therefore, when would be the appropriate time to free the region
  396. (other than when munmap is called).
  397. NOTE: Note, if the design limitation of a) were solved, then it
  398. would be easy to solve exception d) as well.
  399. .. c:function:: FAR void *mmap(FAR void *start, size_t length, int prot, int flags, int fd, off_t offset);
  400. Provides minimal mmap() as needed to support eXecute In Place (XIP) operation (as described above).
  401. :param start: A hint at where to map the memory -- ignored. The address
  402. of the underlying media is fixed and cannot be re-mapped without MMU
  403. support.
  404. :param length: The length of the mapping -- ignored. The entire
  405. underlying media is always accessible.
  406. :param prot: See the ``PROT_*`` definitions in ``sys/mman.h``.
  407. - ``PROT_NONE`` - Will cause an error.
  408. - ``PROT_READ`` - ``PROT_WRITE`` and ``PROT_EXEC`` also assumed.
  409. - ``PROT_WRITE`` - ``PROT_READ`` and ``PROT_EXEC`` also assumed.
  410. - ``PROT_EXEC`` - ``PROT_READ`` and ``PROT_WRITE`` also assumed.
  411. :param flags: See the ``MAP_*`` definitions in ``sys/mman.h``.
  412. - ``MAP_SHARED`` - Required
  413. - ``MAP_PRIVATE`` - Will cause an error
  414. - ``MAP_FIXED`` - Will cause an error
  415. - ``MAP_FILE`` - Ignored
  416. - ``MAP_ANONYMOUS`` - Will cause an error
  417. - ``MAP_ANON`` - Will cause an error
  418. - ``MAP_GROWSDOWN`` - Ignored
  419. - ``MAP_DENYWRITE`` - Will cause an error
  420. - ``MAP_EXECUTABLE`` - Ignored
  421. - ``MAP_LOCKED`` - Ignored
  422. - ``MAP_NORESERVE`` - Ignored
  423. - ``MAP_POPULATE`` - Ignored
  424. - ``AP_NONBLOCK`` - Ignored
  425. :param fd: file descriptor of the backing file -- required.
  426. :param offset: The offset into the file to map.
  427. :return:
  428. On success, ``mmap()`` returns a pointer to the mapped area. On error,
  429. the value ``MAP_FAILED`` is returned, and ``errno`` is set
  430. appropriately.
  431. - ``ENOSYS`` - Returned if any of the unsupported ``mmap()`` features
  432. are attempted.
  433. - ``EBADF`` - ``fd`` is not a valid file descriptor.
  434. - ``EINVAL`` - Length is 0. flags contained neither ``MAP_PRIVATE`` or
  435. ``MAP_SHARED``, or contained both of these values.
  436. - ``ENODEV`` - The underlying file-system of the specified file does
  437. not support memory mapping.