2023-05-03 16:11:05 +02:00
|
|
|
/****************************************************************************
|
2008-11-16 17:36:30 +01:00
|
|
|
* include/fcntl.h
|
2007-03-20 17:51:12 +01:00
|
|
|
*
|
2021-02-03 11:33:49 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2007-03-20 17:51:12 +01:00
|
|
|
*
|
2021-02-03 11:33:49 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-03-20 17:51:12 +01:00
|
|
|
*
|
2021-02-03 11:33:49 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2007-03-20 17:51:12 +01:00
|
|
|
*
|
2023-05-03 16:11:05 +02:00
|
|
|
****************************************************************************/
|
2007-03-20 17:51:12 +01:00
|
|
|
|
2008-11-16 17:36:30 +01:00
|
|
|
#ifndef __INCLUDE_FCNTL_H
|
|
|
|
#define __INCLUDE_FCNTL_H
|
2007-03-20 17:51:12 +01:00
|
|
|
|
2023-05-03 16:11:05 +02:00
|
|
|
/****************************************************************************
|
2007-03-20 17:51:12 +01:00
|
|
|
* Included Files
|
2023-05-03 16:11:05 +02:00
|
|
|
****************************************************************************/
|
2007-03-20 17:51:12 +01:00
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
2009-12-15 00:32:23 +01:00
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
#include <sys/types.h>
|
2009-12-15 00:32:23 +01:00
|
|
|
#include <stdint.h>
|
2007-03-20 17:51:12 +01:00
|
|
|
|
2023-05-03 16:11:05 +02:00
|
|
|
/****************************************************************************
|
2014-09-28 18:15:33 +02:00
|
|
|
* Pre-processor Definitions
|
2023-05-03 16:11:05 +02:00
|
|
|
****************************************************************************/
|
2007-03-20 17:51:12 +01:00
|
|
|
|
|
|
|
/* open flag settings for open() (and related APIs) */
|
|
|
|
|
2012-04-18 17:57:45 +02:00
|
|
|
#define O_RDONLY (1 << 0) /* Open for read access (only) */
|
|
|
|
#define O_RDOK O_RDONLY /* Read access is permitted (non-standard) */
|
|
|
|
#define O_WRONLY (1 << 1) /* Open for write access (only) */
|
|
|
|
#define O_WROK O_WRONLY /* Write access is permitted (non-standard) */
|
|
|
|
#define O_RDWR (O_RDOK|O_WROK) /* Open for both read & write access */
|
|
|
|
#define O_CREAT (1 << 2) /* Create file/sem/mq object */
|
|
|
|
#define O_EXCL (1 << 3) /* Name must not exist when opened */
|
|
|
|
#define O_APPEND (1 << 4) /* Keep contents, append to end */
|
|
|
|
#define O_TRUNC (1 << 5) /* Delete contents */
|
|
|
|
#define O_NONBLOCK (1 << 6) /* Don't wait for data */
|
|
|
|
#define O_NDELAY O_NONBLOCK /* Synonym for O_NONBLOCK */
|
|
|
|
#define O_SYNC (1 << 7) /* Synchronize output on write */
|
|
|
|
#define O_DSYNC O_SYNC /* Equivalent to OSYNC in NuttX */
|
2022-06-02 18:23:24 +02:00
|
|
|
#define O_TEXT (1 << 8) /* Open the file in text (translated) mode. */
|
This commit brings in an inital port of the SPIFFS flash file system into NuttX. The file system is still untested at this point (and subject to some additional review). It is, however, marked EXPERIMENTAL should this should not cause a problem for anyone.
Squashed commit of the following:
fs/spiffs: Fix last compilation issue. Now compiles without error. It is still not quite ready for testing as there is additional code review that must be be performed. It is now marked as EXPERIMENTAL so that it can be brought onto the master branch with little risk.
fs/spiffs: Remove some dead code.
fs/spiffs: Weak start of analysis of spiffs_nucleus.c. Renamed to spiffs_core.c
fs/spiffs: Rename spiffs_nucleus.c to spiffs_core.c
fs/spiffs: Remove spiffs_config.h. All configuration settings are now available in the SPIFFS Kconfig options.
fs/spiffs: Finished review, update, and repartitioning of spiffs_check.c. Added spiffs_check.h.
fs/spiffs: Finished review, update, and repartitioning of spiffs_cache.c. Added spiffs_cache.h.
fs/spiffs: Clean up some defines used in debug output statements.
fs/spiffs: Finished review, update, and repartitioning of spiffs_gc.c. Added spiffs_gc.h.
fs/spiffs: Now that VFS interface is completed, I have begun the long march of repartitioning the remaining functionality, reviewing logic, identifying dead code, and cleaning up loose ends.
fs/spiffs: Initial integration of MTD interface, replacing the SPIFFS native flash interface. Lots of open issues such as the use of pages vs. blocks vs. erase blocks and units of addresses, offsets, and lengths that are passed in function calls. Remove SPIFFS_USE_MAGIC support. That option (which default to OFF anyway), wrote a magic value at the beginning of every sector and support verifiable identification of the file system. It was not being and used and removing it makes life simpler.
fs/spiffs: Remove semaphore lock on the file object structure. Ultimately, the file access must modify the volume and access the volume structue which also has a exclusivity lock. So use of the volume lock alone should be sufficient.
Integrated the SPIFFS rename logic into the NuttX VFS. Removed non-standard application calls or convert them to IOCTL commands. These were converted to IOCTL commands: (1) integrity check, (2) garbage collection, and (3) format flash. These were removed: (1) Integrity check callback. These provided a lot of good information about the state of the file system, but such callbacks are not compatible with a POSIX compliant file system. (2) Index maps. The index maps were a performance improvement feature. The user could provide the memory and request that a region of a a file use that memory for improved lookup performance when accessing parts of the file. The fallback is the less performance lookup by traversing the FLASH memory. (3) Removed the quick garbage collection interface (the code is still used internally). Only the full garbage collection is available to the user application via IOCTL.
configs/sim/spiffs: A simulator configuration to use for testing SPIFFS.
fs/spiffs: Integrate SPIFFS logic into NuttX VFS bind() and unbind() methods.
fs/mount/fs_mount.c: Add SPIFFS to the list of drivers that require MTD vs block drivers.
fs/spiffs: Trivial changes, mostly from analysis of how to integrate the rename() VFS method.
fs/spiffs: Connect NuttX VFS unlink method to the SPIFFS_remove() function. Lots of name-changing.
fs/spiffs: Remove non-standard errno support. Remove bogus SPIFFS_LOCK() and SPIFFS_UNLOCK() macros.
fs/spiffs: Add NuttX VFS implementation for statfs() method. Clean up some of the accumulating compilation problems.
fs/spiffs: Add stat(), truncate() methods. Dummy out unsupport mkdir() and rmdir() methods.
fs/spiffs: Replace some of the custom error numbers with standard error numbers.
fs/spiffs: Hooks read(), write(), fstat(), ioctl(), opendir(), closedir(), rewindif(), and readdir() into the NuttX VFS.
fs/spiffs: Beginning the organization to work with the NuttX VFS. Lots of things are get broken!
fs/spiffs: Add spiffs.c which will be the interface between SPIFFS and NuttX. No very close at present, however.
fs/spiffs: Clean up some compile problems introduced by coding standard changes.
fs/spiffs: A little closer to NuttX coding standard.
fs/spiffs: Ran tools/indent.sh against all files. Closer to NuttX coding standard, but needs a lot more effort to be fully compliant.
fs/spiffs: This commit brings in version 0.3.7 of Peter Anderson's SPIFFS. The initial commit includes the core FS files (with some definitions destributed to their correct header files) and hooks into the build system.
2018-09-25 02:05:09 +02:00
|
|
|
#define O_DIRECT (1 << 9) /* Avoid caching, write directly to hardware */
|
2020-02-03 15:21:54 +01:00
|
|
|
#define O_CLOEXEC (1 << 10) /* Close on execute */
|
2022-07-26 08:53:39 +02:00
|
|
|
#define O_DIRECTORY (1 << 11) /* Must be a directory */
|
2023-01-14 17:57:09 +01:00
|
|
|
#define O_NOFOLLOW (1 << 12) /* Don't follow links */
|
2023-11-06 11:56:19 +01:00
|
|
|
#define O_LARGEFILE (1 << 13) /* Large File */
|
2023-07-04 06:27:59 +02:00
|
|
|
#define O_NOATIME (1 << 18) /* Don't update the file last access time */
|
2007-03-20 17:51:12 +01:00
|
|
|
|
2012-04-18 17:57:45 +02:00
|
|
|
/* Unsupported, but required open flags */
|
2007-03-20 17:51:12 +01:00
|
|
|
|
2012-04-18 17:57:45 +02:00
|
|
|
#define O_RSYNC 0 /* Synchronize input on read */
|
2014-10-05 01:30:24 +02:00
|
|
|
#define O_ACCMODE O_RDWR /* Mask for access mode */
|
2012-04-18 17:57:45 +02:00
|
|
|
#define O_NOCTTY 0 /* Required by POSIX */
|
2022-06-02 18:23:24 +02:00
|
|
|
#define O_BINARY 0 /* Open the file in binary (untranslated) mode. */
|
2012-04-18 17:57:45 +02:00
|
|
|
|
|
|
|
/* This is the highest bit number used in the open flags bitset. Bits above
|
|
|
|
* this bit number may be used within NuttX for other, internal purposes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define _O_MAXBIT 8
|
2007-03-20 17:51:12 +01:00
|
|
|
|
2013-02-12 17:28:33 +01:00
|
|
|
/* Synonyms historically used as F_SETFL flags (BSD). */
|
2013-02-12 15:05:30 +01:00
|
|
|
|
2013-02-12 17:28:33 +01:00
|
|
|
#define FNDELAY O_NONBLOCK /* Don't wait for data */
|
|
|
|
#define FNONBLOCK O_NONBLOCK /* Don't wait for data */
|
|
|
|
#define FAPPEND O_APPEND /* Keep contents, append to end */
|
|
|
|
#define FSYNC O_SYNC /* Synchronize output on write */
|
|
|
|
#define FASYNC 0 /* No counterpart in NuttX */
|
|
|
|
|
|
|
|
/* FFCNTL is all the bits that may be set via fcntl. */
|
|
|
|
|
|
|
|
#define FFCNTL (FNONBLOCK | FNDELAY | FAPPEND | FSYNC | FASYNC)
|
2013-02-12 15:05:30 +01:00
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
/* fcntl() commands */
|
|
|
|
|
2023-01-30 15:12:30 +01:00
|
|
|
#define F_DUPFD 0 /* Duplicate a file descriptor */
|
|
|
|
#define F_GETFD 1 /* Read the file descriptor flags */
|
|
|
|
#define F_GETFL 2 /* Read the file status flags */
|
|
|
|
#define F_GETLEASE 3 /* Indicates what type of lease is held on fd (linux) */
|
|
|
|
#define F_GETLK 4 /* Check if we could place a lock */
|
2023-03-21 13:40:47 +01:00
|
|
|
#define F_GETOWN 5 /* Get the pid receiving SIGIO and SIGURG signals for fd */
|
2023-01-30 15:12:30 +01:00
|
|
|
#define F_GETSIG 6 /* Get the signal sent */
|
2023-03-21 13:40:47 +01:00
|
|
|
#define F_NOTIFY 7 /* Provide notification when directory referred to by fd changes (linux) */
|
2023-01-30 15:12:30 +01:00
|
|
|
#define F_SETFD 8 /* Set the file descriptor flags to value */
|
|
|
|
#define F_SETFL 9 /* Set the file status flags to the value */
|
|
|
|
#define F_SETLEASE 10 /* Set or remove file lease (linux) */
|
|
|
|
#define F_SETLK 11 /* Acquire or release a lock on range of bytes */
|
|
|
|
#define F_SETLKW 12 /* Like F_SETLK, but wait for lock to become available */
|
|
|
|
#define F_SETOWN 13 /* Set pid that will receive SIGIO and SIGURG signals for fd */
|
|
|
|
#define F_SETSIG 14 /* Set the signal to be sent */
|
|
|
|
#define F_GETPATH 15 /* Get the path of the file descriptor(BSD/macOS) */
|
|
|
|
#define F_ADD_SEALS 16 /* Add the bit-mask argument arg to the set of seals of the inode */
|
|
|
|
#define F_GET_SEALS 17 /* Get (as the function result) the current set of seals of the inode */
|
|
|
|
#define F_DUPFD_CLOEXEC 18 /* Duplicate file descriptor with close-on-exit set. */
|
2024-08-23 09:03:57 +02:00
|
|
|
#define F_SETPIPE_SZ 19 /* Modify the capacity of the pipe to arg bytes, but not larger than CONFIG_DEV_PIPE_MAXSIZE */
|
|
|
|
#define F_GETPIPE_SZ 20 /* Return the capacity of the pipe */
|
2007-03-20 17:51:12 +01:00
|
|
|
|
2009-07-18 23:39:59 +02:00
|
|
|
/* For posix fcntl() and lockf() */
|
|
|
|
|
2011-09-16 01:06:41 +02:00
|
|
|
#define F_RDLCK 0 /* Take out a read lease */
|
2009-08-02 15:24:47 +02:00
|
|
|
#define F_WRLCK 1 /* Take out a write lease */
|
|
|
|
#define F_UNLCK 2 /* Remove a lease */
|
2009-07-18 23:39:59 +02:00
|
|
|
|
2024-06-17 17:26:28 +02:00
|
|
|
/* Operations for bsd flock(), also used by the kernel implementation */
|
|
|
|
|
|
|
|
#define LOCK_SH 1 /* Shared lock */
|
|
|
|
#define LOCK_EX 2 /* Exclusive lock */
|
|
|
|
#define LOCK_NB 4 /* Or'd with one of the above to prevent blocking */
|
|
|
|
#define LOCK_UN 8 /* Remove lock */
|
|
|
|
|
2022-03-04 04:53:57 +01:00
|
|
|
/* close-on-exec flag for F_GETFD and F_SETFD */
|
2007-03-20 17:51:12 +01:00
|
|
|
|
|
|
|
#define FD_CLOEXEC 1
|
|
|
|
|
2023-02-04 02:00:49 +01:00
|
|
|
/* The flag for openat, faccessat, ... */
|
|
|
|
|
|
|
|
#define AT_FDCWD -100 /* Special value used to indicate openat should use the current
|
|
|
|
* working directory.
|
|
|
|
*/
|
|
|
|
#define AT_SYMLINK_NOFOLLOW 0x0100 /* Do not follow symbolic links. */
|
|
|
|
#define AT_EACCESS 0x0200 /* Test access permitted for effective IDs, not real IDs. */
|
|
|
|
#define AT_REMOVEDIR 0x0200 /* Remove directory instead of unlinking file. */
|
|
|
|
#define AT_SYMLINK_FOLLOW 0x0400 /* Follow symbolic links. */
|
|
|
|
#define AT_NO_AUTOMOUNT 0x0800 /* Suppress terminal automount traversal */
|
|
|
|
#define AT_EMPTY_PATH 0x1000 /* Allow empty relative pathname */
|
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
/* These are the notifications that can be received from F_NOTIFY (linux) */
|
|
|
|
|
|
|
|
#define DN_ACCESS 0 /* A file was accessed */
|
|
|
|
#define DN_MODIFY 1 /* A file was modified */
|
|
|
|
#define DN_CREATE 2 /* A file was created */
|
|
|
|
#define DN_DELETE 3 /* A file was unlinked */
|
|
|
|
#define DN_RENAME 4 /* A file was renamed */
|
|
|
|
#define DN_ATTRIB 5 /* Attributes of a file were changed */
|
|
|
|
|
2022-08-07 18:17:41 +02:00
|
|
|
/* Types of seals */
|
|
|
|
|
|
|
|
#define F_SEAL_SEAL 0x0001 /* Prevent further seals from being set */
|
|
|
|
#define F_SEAL_SHRINK 0x0002 /* Prevent file from shrinking */
|
|
|
|
#define F_SEAL_GROW 0x0004 /* Prevent file from growing */
|
|
|
|
#define F_SEAL_WRITE 0x0008 /* Prevent writes */
|
|
|
|
#define F_SEAL_FUTURE_WRITE 0x0010 /* Prevent future writes while mapped */
|
|
|
|
|
2014-10-04 14:44:57 +02:00
|
|
|
/* int creat(const char *path, mode_t mode);
|
|
|
|
*
|
|
|
|
* is equivalent to open with O_WRONLY|O_CREAT|O_TRUNC.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define creat(path, mode) open(path, O_WRONLY|O_CREAT|O_TRUNC, mode)
|
|
|
|
|
2023-02-25 09:02:11 +01:00
|
|
|
#if defined(CONFIG_FS_LARGEFILE)
|
2021-07-21 05:46:21 +02:00
|
|
|
# define F_GETLK64 F_GETLK
|
|
|
|
# define F_SETLK64 F_SETLK
|
|
|
|
# define F_SETLKW64 F_SETLKW
|
|
|
|
|
|
|
|
# define flock64 flock
|
|
|
|
# define open64 open
|
|
|
|
# define openat64 openat
|
|
|
|
# define creat64 creat
|
|
|
|
# define fallocate64 fallocate
|
|
|
|
# define posix_fadvise64 posix_fadvise
|
|
|
|
# define posix_fallocate64 posix_fallocate
|
|
|
|
#endif
|
|
|
|
|
2023-05-03 16:11:05 +02:00
|
|
|
/****************************************************************************
|
2007-03-20 17:51:12 +01:00
|
|
|
* Public Type Definitions
|
2023-05-03 16:11:05 +02:00
|
|
|
****************************************************************************/
|
2007-03-20 17:51:12 +01:00
|
|
|
|
|
|
|
/* struct flock is the third argument for F_GETLK, F_SETLK and F_SETLKW */
|
|
|
|
|
|
|
|
struct flock
|
|
|
|
{
|
2009-12-15 00:32:23 +01:00
|
|
|
int16_t l_type; /* Type of lock: F_RDLCK, F_WRLCK, F_UNLCK */
|
|
|
|
int16_t l_whence; /* How to interpret l_start: SEEK_SET, SEEK_CUR, SEEK_END */
|
|
|
|
off_t l_start; /* Starting offset for lock */
|
|
|
|
off_t l_len; /* Number of bytes to lock */
|
|
|
|
pid_t l_pid; /* PID of process blocking our lock (F_GETLK only) */
|
2007-03-20 17:51:12 +01:00
|
|
|
};
|
|
|
|
|
2023-05-03 16:11:05 +02:00
|
|
|
/****************************************************************************
|
2007-03-20 17:51:12 +01:00
|
|
|
* Public Function Prototypes
|
2023-05-03 16:11:05 +02:00
|
|
|
****************************************************************************/
|
2007-03-20 17:51:12 +01:00
|
|
|
|
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
#define EXTERN extern "C"
|
2014-10-04 14:44:57 +02:00
|
|
|
extern "C"
|
|
|
|
{
|
2007-03-20 17:51:12 +01:00
|
|
|
#else
|
|
|
|
#define EXTERN extern
|
|
|
|
#endif
|
|
|
|
|
2023-05-03 16:11:05 +02:00
|
|
|
/****************************************************************************
|
2014-10-04 14:44:57 +02:00
|
|
|
* Public Data
|
2023-05-03 16:11:05 +02:00
|
|
|
****************************************************************************/
|
2014-10-04 14:44:57 +02:00
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
/* POSIX-like File System Interfaces */
|
|
|
|
|
2020-05-06 11:24:42 +02:00
|
|
|
int open(FAR const char *path, int oflag, ...);
|
2023-02-04 02:00:49 +01:00
|
|
|
int openat(int dirfd, FAR const char *path, int oflag, ...);
|
2014-10-04 14:44:57 +02:00
|
|
|
int fcntl(int fd, int cmd, ...);
|
2007-03-20 17:51:12 +01:00
|
|
|
|
2020-12-14 03:56:23 +01:00
|
|
|
int posix_fallocate(int fd, off_t offset, off_t len);
|
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-11-16 17:36:30 +01:00
|
|
|
#endif /* __INCLUDE_FCNTL_H */
|