Commit Graph

447 Commits

Author SHA1 Message Date
hujun5 236ec9844f fs: dup3 should pass the fdcheck & fdsan
Signed-off-by: hujun5 <hujun5@xiaomi.com>
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-03-07 09:08:48 +08:00
ligd e1cd082c29 fs: enhance dup3() mulit-threads saftey
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-03-07 09:08:48 +08:00
hujun5 577eb47966 fdcheck: Enable fdcheck to automatically detect ownership of fd
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-03-07 09:08:48 +08:00
chao an 6d50274ebe nuttx/list: rename container_of to list_container_of from public header
Use private naming to avoid conflicts with user applications

In file included from libuv/src/unix/internal.h:25,
                 from libuv/src/unix/udp.c:23:
libuv/src/uv-common.h:57: warning: "container_of" redefined
   57 | #define container_of(ptr, type, member) \
      |
In file included from nuttx/include/nuttx/list.h:47,
                 from nuttx/include/nuttx/tls.h:40,
                 from nuttx/include/nuttx/sched.h:48,
                 from nuttx/include/nuttx/arch.h:87,
                 from nuttx/include/nuttx/userspace.h:35,
                 from nuttx/include/nuttx/mm/mm.h:30,
                 from nuttx/include/nuttx/kmalloc.h:34,
                 from nuttx/include/nuttx/lib/lib.h:31,
                 from nuttx/include/stdio.h:35,
                 from apps/system/libuv/libuv/include/uv.h:59,
                 from libuv/src/unix/udp.c:22:
nuttx/include/nuttx/nuttx.h:48: note: this is the location of the previous definition
   48 | #define container_of(ptr, type, member) \
      |

Signed-off-by: chao an <anchao@lixiang.com>
2024-02-29 19:44:54 +08:00
chenrun1 ae730ac246 fs_lock:Avoid deadlock caused by KILL SIGNAL
Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-02-21 13:29:36 -03:00
chenrun1 6e3e03f6b0 fs/vfs:cmakelists add fs_lock config
Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-02-21 13:29:36 -03:00
Zhe Weng 14602be4cc fs/lock: Limit inode type for file locks
When we close a socket fd, it will call get path on sockets.
`close(socket_fd)` -> `file_closelk(filep)` -> `file_fcntl(F_GETPATH)`
It causes a heavy stack load for each socket close operation.
(We have `GETPATH` for sockets to be used for `fdinfo`)

But the socket fds are not intended to be used for file locks.
And so do some other file types, so we may just limit the usage of flock.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-02-21 13:29:36 -03:00
chenrun1 8cdec83adb fs_locks:Fix getlk's l pid return
When there is no conflicting lock, getlk should not tamper with the l_pid content from the upper layer

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-02-21 13:29:36 -03:00
chenrun1 5c6bd833ed fs_lock:Implementing file locks
Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-02-21 13:29:36 -03:00
Saurav Pal 93d03d0418 fs: Add VFS docs
This commit adds VFS docmentation, and details about the VFS interface.

Signed-off-by: Saurav Pal <resyfer.dev@gmail.com>
2024-02-20 18:28:09 -08:00
Ville Juven f0846e1d2d fs/shmfs: Fix stat() system call for shmfs object
Set i_size for shmfs objects
2024-02-02 09:12:18 -08:00
Ville Juven 43a26220be fs/shmfs: Fix CONFIG_FS_SHM -> CONFIG_FS_SHMFS
The macro was wrong
2024-01-31 08:51:52 -08:00
chao an 8ff97f6210 compiler/tasking: fix unreachable code on tasking toolchain
ctc W544: ["serial/serial.c" 284/3] unreachable code
ctc W544: ["vfs/fs_lseek.c" 96/13] unreachable code
ctc W544: ["wqueue/kwork_thread.c" 210/32] unreachable code
ctc W544: ["stdio/lib_fopen.c" 327/19] unreachable code
ctc W544: ["stdio/lib_fopen.c" 404/13] unreachable code
ctc W544: ["string/lib_strcasestr.c" 120/3] unreachable code
ctc W544: ["unistd/lib_getopt_common.c" 156/21] unreachable code
ctc W544: ["unistd/lib_getopt_common.c" 216/21] unreachable code
ctc W544: ["wctype/lib_iswctype.c" 155/3] unreachable code

Signed-off-by: chao an <anchao@lixiang.com>
2024-01-30 20:53:00 -08:00
yinshengkai 9852428953 fs: procfs add poll support
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-12-26 19:23:13 -08:00
Xiang Xiao eddd90de78 poll: pollsetup should notify only one fd passd by caller
since it's redundant to iterate the whole fds array in setup

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-11-21 09:07:17 +01:00
zhanghongyu 3610b25c91 cmake: add include path for special source
fix the cmake build error.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-11-07 17:39:03 +01:00
Bowen Wang 2f9c082f8f fs_epoll: serveral epoll issues fix
1. fs_epoll: try again when epoll_teardown() return 0
when poll_notify() called larger than twice when epoll_wait() blocked
in the eph->sem, the semcount will be larger than 1 when epoll_wait()
unblocked and will return 0 directly at the next epoll_wait.
So retry to wait the eph->sem again when epoll_teardown return 0.

2. fs_epoll: poll_setup the fd again even this fd got non-expected event
Some poll implementations need call poll_setup again when their internal
states changed (e.g., local socket), so should add the fd to the epoll
teardown list and poll_setup again at the next epoll_wait even this fd
got the user non-expected event.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2023-11-02 00:44:52 +08:00
dongjiuzhu1 73dc8f84cc fs/dup3: impletement dup3/nx_dup3_from_tcb function
refs: https://man7.org/linux/man-pages/man2/dup.2.html

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-10-27 21:15:07 +08:00
dongjiuzhu1 dc2dac2377 fs/dup/dup2: don't add O_CLOEXEC for new file descriptor
refs: https://man7.org/linux/man-pages/man2/dup.2.html

The two file descriptors do not share file descriptor flags (the
close-on-exec flag).  The close-on-exec flag (FD_CLOEXEC; see
fcntl(2)) for the duplicate descriptor is off.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-10-27 21:15:07 +08:00
dongjiuzhu1 dcc006035d fs/rename: fix use after free issue about rename
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-10-26 01:04:23 +08:00
Xiang Xiao d84aba8a42 fs: Change inode_checkflags to static function
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-10-22 21:23:08 +03:00
Xiang Xiao b1c8c84e81 stdio: Merge fs_fdopen into fdopen to simplify the code logi
since fs_fdopen could avoid call the kernel specific function now

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-10-17 13:34:00 +08:00
Xiang Xiao 62c2b1abba stdio: Initialize stdin, stdout and stderr directly
and then remove group_setupstreams

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-10-17 13:34:00 +08:00
ThomasNS 696717b28b add munmap logic to pseudofs 2023-10-13 03:17:27 +08:00
guohao15 2bce0f404c fs:add syncfs api for sync whole fs data
Signed-off-by: guohao15 <guohao15@xiaomi.com>
2023-09-23 15:58:00 +08:00
Petro Karashchenko 0e42808923 fs/vfs: remove redundant return in nx_vopen
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-09-16 14:17:47 +08:00
dongjiuzhu1 6367f2469c fs/vfs: fix dup issue for eventfd/signalfd/timerfd
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-09-11 19:57:34 +08:00
xuxin19 b1cc5b50b1 cmake:complete missing changes during cmake reforming for fs
Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2023-09-08 21:20:16 +03:00
wanggang26 3dbface167 Revert commit 35602cc2ef
Reason for revert: when block device enable bch proxy, fsync calling would be failed

Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2023-08-25 20:37:38 +03:00
wanggang26 d8f316b998 fs/ioctl: add BIOC_BLKGETSIZE cmd to get block sector numbers
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2023-08-19 01:43:59 +08:00
chenrun1 35602cc2ef fs_fsync.c:Fix unknown command message in non-block device situations
This command is called only if the device is a block device or mtd
device.

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2023-08-18 14:47:27 +08:00
Petro Karashchenko 1b0baa8337 nuttx: use lib_free for memory de-allocation after strdup or asprintf
The memory allocated with strdup and asprintf is done via lib_malloc
so we need to use lib_free to deallocate memory otherwise the assertion
"Free memory from the wrong heap" is hit with flat mode and user separated
heap enabled mode.

Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-08-08 11:58:29 -03:00
Petro Karashchenko b3d620152e Revert "Don't call lib_free in the kernel code"
This reverts commit 7884c18620.
2023-08-08 11:58:29 -03:00
xucheng5 f1287a9996 fs_open: add ioctl checkflag
fixed open error when driver not implement write

Signed-off-by: xucheng5 <xucheng5@xiaomi.com>
2023-08-07 01:09:52 -07:00
Xiang Xiao 7884c18620 Don't call lib_free in the kernel code
since kernel just allocate memory from kmm_malloc

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-08-06 06:51:24 -03:00
yinshengkai a6fcb0a5a9 fs: add pipe type support to inode
Both the device and the pipe used the FSNODEFLAG_TYPE_DRIVER type before,
and now add an independent pipe type

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-08-05 06:32:50 -07:00
fangxinyong ea52220509 fs/shmfs: fix inode leak issue
If the shm file is removed and a subsequent close, only release shm
object, but inode is leaked. Should decrease refcount to release inode
when unmapped, that matched with refcount increase when mapped.

Another fix that remove the shm file failed.
nsh> rm /var/shm/pts_mmap_1_2_5
nsh: rm: unlink failed: 6

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2023-08-02 22:57:28 -07:00
fangxinyong 5176fb917a fs/vfs: ftruncate produce EINVAL if fd is not open for writing
As posix spec, ftruncate should produce EBADF or EINVAL error,
if the file descriptor fd is not open for writing.

Change the behavior to be similar to Linux and pass ltp open_posix test:
testcases/open_posix_testsuite/conformance/interfaces/shm_open/20-1.c

https://pubs.opengroup.org/onlinepubs/9699919799/functions/ftruncate.html
https://man7.org/linux/man-pages/man2/ftruncate.2.html

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2023-08-02 22:57:28 -07:00
Fotis Panagiotopoulos 0fcf6f2e41 open: Use file mode only when O_CREAT is specified. 2023-08-02 06:08:20 -07:00
dongjiuzhu1 f8ce0cd4ca fs/pseudofile: config pseudofile feature
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-07-31 22:22:58 -07:00
dongjiuzhu1 8336ee78b8 vfs/fs_pseudofile: fix coverity issue
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-07-31 22:22:58 -07:00
dongjiuzhu1 0f6d0eac52 fs/pesudofile: support pseudo-file operation
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-07-31 22:22:58 -07:00
yangyalei f2844a2e3c vfs: return OK when fsync dir
Signed-off-by: yangyalei <yangyalei@xiaomi.com>
2023-07-31 07:50:10 -07:00
dongjiuzhu1 f8991f7782 vfs/dup: add nonblock flag to avoid happening block when dup
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-07-28 07:41:51 -07:00
chao an f10b54a081 cmake: fix CMake build break
Signed-off-by: chao an <anchao@xiaomi.com>
2023-07-15 23:32:36 +08:00
dulibo1 13c7138c8d add refcnt using epoll_create to fix bug when use popen which dup the fd and close at end after epoll_create
Signed-off-by: dulibo1 <dulibo1@xiaomi.com>
2023-07-13 01:06:53 +08:00
chao an 6ee9ec7656 build: add initial cmake build system
1. Update all CMakeLists.txt to adapt to new layout
2. Fix cmake build break
3. Update all new file license
4. Fully compatible with current compilation environment(use configure.sh or cmake as you choose)

------------------

How to test

From within nuttx/. Configure:

cmake -B build -DBOARD_CONFIG=sim/nsh -GNinja
cmake -B build -DBOARD_CONFIG=sim:nsh -GNinja
cmake -B build -DBOARD_CONFIG=sabre-6quad/smp -GNinja
cmake -B build -DBOARD_CONFIG=lm3s6965-ek/qemu-flat -GNinja

(or full path in custom board) :
cmake -B build -DBOARD_CONFIG=$PWD/boards/sim/sim/sim/configs/nsh -GNinja

This uses ninja generator (install with sudo apt install ninja-build). To build:

$ cmake --build build

menuconfig:

$ cmake --build build -t menuconfig

--------------------------

2. cmake/build: reformat the cmake style by cmake-format

https://github.com/cheshirekow/cmake_format

$ pip install cmakelang

$ for i in `find -name CMakeLists.txt`;do cmake-format $i -o $i;done
$ for i in `find -name *\.cmake`;do cmake-format $i -o $i;done

Co-authored-by: Matias N <matias@protobits.dev>
Signed-off-by: chao an <anchao@xiaomi.com>
2023-07-08 13:50:48 +08:00
Xiang Xiao 935f43185f libc/modlib: Replace nx_stat with file_stat
to avoid searching the path twice

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-07-06 09:20:24 -03:00
Fotis Panagiotopoulos 880d78f903 sendfile: Fixed behavior of sendfile when count is set to zero.
If sendfile() is called with a zero count, it will nevertheless
try to send the data. This is mostly meaningless, it causes
waste of resources, and in some cases delays.

This commit adds special handling for this case, allowing
sendfile to return immediately zero. The new behavior is
in line with the Linux variant of sendfile.
2023-06-22 16:10:58 +08:00
wangbowen6 7117d3ea8a fs_fsync: should not call fs's ioctl when fs not support sync api
Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
2023-06-17 19:31:17 +08:00