2386 Commits

Author SHA1 Message Date
Pip Cet
cfab00817a fs/procfs: Improve subdirectory recognition
This patch fixes https://github.com/apache/nuttx/issues/16237, where
cd'ing to a non-directory prefix of a procfs entry would succeed.

Signed-off-by: Pip Cet <pipcet@protonmail.com>
2025-05-02 09:28:06 -03:00
zhangshoukui
d3bb1eab0a fs/littlefs: Add read-only parameter
Test command:
./tools/configure.sh -l sim:tcpblaster
make -j
umount /mnt/lfs
mount -t littlefs -o ro /dev/rammtd /data

Signed-off-by: zhangshoukui <zhangshoukui@xiaomi.com>
2025-04-18 12:30:29 +08:00
zhangshoukui
60111786d6 fs/littlefs: Code comment correction
Signed-off-by: zhangshoukui <zhangshoukui@xiaomi.com>
2025-04-18 12:30:29 +08:00
YAMAMOTO Takashi
b59373b270 littlefs_open: sync the file only when O_TRUNC is specified
Because sync is a rather expensive operation.

While I'm here, improve the comment after the recent discussion
in https://github.com/apache/nuttx/pull/2913.

IMHO, we should not perform the sync even for O_TRUNC.
But I'm not going to propose the change for now.

Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
2025-04-10 14:38:18 +08:00
Beat Küng
ac2078a8bf fs/procfs: fix potential null pointer access in procfs_opendir
Some entries have the opendir function set to NULL, for example
g_mount_operations.

A null pointer dereference can be triggered by an
opendir("/proc/fs/blocks") for example.

Signed-off-by: Beat Küng <beat-kueng@gmx.net>
2025-04-09 11:50:35 -03:00
YAMAMOTO Takashi
90e9b2426d add a comment on littlefs_attr_s to explain what it is
i couldn't find any documenation about this attribute.
this comment is purely based on my reading of the code.

Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
2025-04-03 16:23:42 +08:00
Tiago Medicci Serrano
b1bab5c783 fs/vfs/fs_poll: Add noinstrument_function to poll_notify function
Add the noinstrument_function attribute to the poll_notify function
to avoid it being looped if -finstrument-functions is set to the
fs/vfs files.

Signed-off-by: Tiago Medicci Serrano <tiago.medicci@espressif.com>
2025-03-18 09:17:52 +08:00
dongjiuzhu1
cfd359141f fs/drivers: Avoid causing a busy loop in the program due to context switching induced by sem_post.
examples:
There are two threads involved: thread A with a priority of 100 and
thread B with a priority of 101. Here's how they interact:

When thread A releases a semaphore, thread B is scheduled to execute
some code and may reacquire the semaphore. If no other tasks are ready,
thread A will be scheduled to run.
This continuous process can lead to a busy loop.

Thread A:                                                   Thread B:

while (nxsem_get_value(&priv->wait, &semcount) >= 0 &&  <---
       semcount <= 0)                                      |  2)context switch
  {                                  1)contex switch       |
    nxsem_post(&priv->wait);         ------------->     run some code and nxsem_wait again
  }

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-03-17 10:44:26 +01:00
chenrun1
91d895d9a2 fs/virtio-9p:When virtio-9p is not supported, return -ENODEV
Summary:
  When the operating environment does not support virtio-9p and the virtio-9p server driver is not provided, -ENODEV should be returned for virtio-9p to avoid crash caused by continued execution.

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2025-03-13 16:37:20 -03:00
hujun5
f22b93b337 sched/spin_lock: rename raw_spin_lock to spin_lock_notrace
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2025-02-13 20:48:15 +08:00
Yanfeng Liu
225197b779 littlefs/cmake: fix build issue
This fixes issue on Ubuntu 22.04 with cmake v3.22.1:

```
/usr/bin/arm-none-eabi-gcc -D-DLFS_ASSERT=DEBUGASSERT -D-DLFS_CONFIG=/home/yf/Projects/Nuttx/nuttx/fs/littlefs/lfs_vfs.h -D-DLFS_DEBUG=finfo -D-DLFS_ERROR=ferr -D-DLFS_TRACE=finfo -D-DLFS_WARN=fwarn -DLFS_ATTR_MAX=1022 -DLFS_FILE_MAX=2147483647 -DLFS_NAME_MAX=32 -D__KERNEL__ -D__NuttX__
```

It happeed when building `qemu-armv7a:rpproxy_ivshmem`.

Signed-off-by: Yanfeng Liu <p-liuyanfeng9@xiaomi.com>
2025-02-11 23:22:07 +08:00
chao an
ace7f0c633 fs/spinlock: replace no sched_lock() version to improve the performance
after below change merge to kernel, spin_lock() will turn off preemption by default,
but this change is not applicable to all scenarios. The locations in the kernel that
use spin_lock() extensively only require short critical sections and do not trigger
scheduling, which leads to serious performance degradation of NuttX in AMP mode.

In this PR, I try to expose similar problems and hope that each subsystem will carefully check the code coverage

https://github.com/apache/nuttx/pull/14578
|commit b69111d16a2a330fa272af8175c832e08881844b
|Author: hujun5 <hujun5@xiaomi.com>
|Date:   Thu Jan 23 16:14:18 2025 +0800
|
|    spinlock: add sched_lock to spin_lock_irqsave
|
|    reason:
|    We aim to replace big locks with smaller ones. So we will use spin_lock_irqsave extensively to
|    replace enter_critical_section in the subsequent process. We imitate the implementation of Linux
|    by adding sched_lock to spin_lock_irqsave in order to address scenarios where sem_post occurs
|    within spin_lock_irqsave, which can lead to spinlock failures and deadlocks.
|
|    Signed-off-by: hujun5 <hujun5@xiaomi.com>

Signed-off-by: chao an <anchao.archer@bytedance.com>
2025-01-24 11:48:23 +08:00
Yanfeng Liu
4e8bcf1ba4 procfs/meminfo: align page fields to columns
meminfo before:
```
      total       used       free    maxused    maxfree  nused  nfree name
    3129344      10824    3118520      11184    3118104     25      2 Kmem
   13631488    1114112   12517376   12517376 Page
```
and after:

```
      total       used       free    maxused    maxfree  nused  nfree name
    3129344      10824    3118520      11184    3118104     25      2 Kmem
   13631488    1114112   12517376              12517376               Page
```
Signed-off-by: Yanfeng Liu <p-liuyanfeng9@xiaomi.com>
2025-01-22 20:29:07 +08:00
chao an
ff50bc191c fs/uio: do not overwrite the return value
Signed-off-by: chao an <anchao.archer@bytedance.com>
2025-01-22 16:45:46 +08:00
chao an
2c9b287b2e fs/vfs: initialize uio only if lower implement readv/writev
to simple signle read/write logic, initialize uio only if lower implement readv/writev

Signed-off-by: chao an <anchao.archer@bytedance.com>
2025-01-22 16:45:46 +08:00
YAMAMOTO Takashi
ab9522fd23 file_readv_compat: add a comment to explain limitations 2025-01-22 14:29:35 +08:00
chenrun1
4d17c353dd v9fs:socket driver
Summary:
  1.Add new api for socket parsing header - v9fs_parse_size
  2.Add socket driver for 9pfs

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2025-01-20 17:12:14 +08:00
hujun5
61f0c97193 wqueue: wqueue remove csection
reason:
We decouple semcount from business logic
by using an independent counting variable,
which allows us to remove critical sections in many cases.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2025-01-15 17:26:07 +08:00
chenrun1
06540e7be1 fs_procfsproc:fix proc_heap to get kernel task info
Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2025-01-15 17:12:50 +08:00
chenrun1
38c217bbfd fs_heap:add fs_heap_mallinfo_task
Summary:
  Added fs_heap_mallinfo_task implementation, which is used in proc_heap

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2025-01-15 17:12:50 +08:00
chenrun1
cf66a1d5ce hostfs_open:return errno from host
Summary:
  Returns the error code returned directly by the host to avoid conversion to EBADF

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2025-01-14 23:03:20 +08:00
YAMAMOTO Takashi
30ad31e9d7 uio api tweaks
* Make readv/writev implementations update struct uio
  This can simplify partial result handling.

* change the error number on the overflow from EOVERFLOW to EINVAL
  to match NetBSD

* add a commented out uio_offset field. I used "#if 0" here as
  C comments can't nest.

* add a few helper functions

Note on uio_copyfrom/uio_copyto:
although i'm not quite happy with the "offset" functionality,
it's necessary to simplify the adaptation of some drivers like
drivers/serial/serial.c, which (ab)uses the user-supplied buffer
as a line-buffer.
2025-01-14 20:18:21 +08:00
chenrun1
b973bf3191 fs_procfs:Fix closedir should handle the release dir handle on a case-by-case basis
Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2025-01-14 19:37:08 +08:00
chenrun1
6f4f50e2fe v9fs/client.c:Use int ret as the return value to avoid uint32_t not supporting negative values
Summary:
 iModify the return variable in the v9fs_client_walk

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2025-01-02 22:34:35 +08:00
chenrun1
1f540a93d2 v9fs/client.c:add check response.nwqid == nwname
Summary:
  There are differences in different server implementations, so it is necessary to check whether the returned nwqid satisfies the requested number.

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2025-01-02 22:34:35 +08:00
chenrun1
2ac2d5d511 v9fs/client.c:fix struct attach wrong parameter size
Summary:
  Change uint16_t afid -> uint32_t afid in struct v9fs_attach_s
  See: https://github.com/chaos/diod/blob/master/protocol.md

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2025-01-02 22:34:35 +08:00
chenrun1
928656f3cb v9fs/client.c:count should be assigned a value before being used
Summary:
  move request.count = buflen > fidp->iounit ? fidp->iounit : buflen
before request.header.size

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2025-01-02 22:34:35 +08:00
YAMAMOTO Takashi
a393f7fbd3 littlefs: fix EINVAL on path operations with littlefs 2.10.0
littlefs 2.10.0 and later rejects empty paths.  use "/" instead.

tested with esp32s3-devkit:toywasm.
2024-12-29 20:43:33 -03:00
George Poulios
884b4604c2 Map user memory passed to accept() in kernel build
Fixes an issue in kernel build where the user addresses passed
to accept() would be accessed when the wrong MMU mappings were
active. A crash would manifest when attempting to accept() on a
TCP server socket for instance under significant load. The accept
event handler would be called by the HP worker upon client
connection. At this point, accept_tcpsender() would attempt to
write to `addr` resulting in a page fault. Reproducibility would
depend on the current system load (num tasks or CPU stress) but
in loaded environments, it would crash almost 100% of the times.

It should be noted that Linux does this the other way around: it
operates on kernel stack allocated data and once done, it copies
them to user. This can also be a viable alternative, albeit with
one extra copy and a little extra memory.

Signed-off-by: George Poulios <gpoulios@census-labs.com>
2024-12-20 00:57:40 +02:00
anjiahao
20a0eb1064 procfs:add missing ',' to end of line
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-12-19 14:47:32 +08:00
hujun5
ccf477710a fs: Move fl_lock to a more appropriate location.
reason:
The list->fl_files may be modified by files_extend.
If it is being modified, there will be a race condition for fl_files[l1][l2].

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-12-17 20:48:59 +08:00
YAMAMOTO Takashi
097543681a fs/littlefs/Make.defs: fix a littlefs unpack regression
Note that $(CONFIG_FS_LITTLEFS_VERSION).tar.gz is expanded to
eg. "v2.5.1".tar.gz. The extra quotes break make's file existence
checks.

Fixes: https://github.com/apache/nuttx/issues/15148

The regression was caused by https://github.com/apache/nuttx/pull/14903
2024-12-16 17:09:16 +08:00
hujun5
7036098d23 fs: fix comment in https://github.com/apache/nuttx/pull/15163
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-12-16 14:33:50 +08:00
hujun5
a459280fac use atomic to protect f_refs
fix regresion from https://github.com/apache/nuttx/pull/14801

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-12-15 09:43:36 -03:00
hujun5
98ce36cdc7 remove fl_crefs
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-12-13 23:04:10 +08:00
YAMAMOTO Takashi
fa8d5cd53d littlefs: Use LFS_DEFINES if available 2024-12-13 18:22:30 +08:00
Windrow14
5cdc6c77cf fs/fat/fs_fat32util.c: fix potential exception due to dividing zero during mounting when fat is corrupted
Check fs_fatsecperclus' value when read from eMMC device. Return an error if it is zero.

Signed-off-by: Yinzhe Wu <Yinzhe.Wu@sony.com>
Reviewed-by: Jacky Cao <Jacky.Cao@sony.com>
Tested-by: Yinzhe Wu <Yinzhe.Wu@sony.com>
2024-12-13 11:22:54 +08:00
Jukka Laitinen
366977b767 fs/shm/shmfs_alloc.c: Allocate zero-initialized memory in flat build
POSIX requires that the shm objects are zero-initialized. This has been broken
in some earlier commits (starting from 9af5fc5d09724a5d300bc07ce85b9ba5c01ffadd)

Also fix the flat build memory allocation to allocate both object data and payload
in the same chunk (as the comment also suggests). This saves allocations and memory
in a system with lots of shm objects.

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2024-12-12 21:47:41 +08:00
chao an
b46edd1252 fs/reference_count: set default reference count option depends on DISABLE_PTHREAD
Most of developers will not have the scenarios of open/close file descriptors in multi-threads,
The default option will incur additional code size overhead for such devices.
this PR will preserve the behavior before PR#13296 was introduced, and ensure that the default code size is not affected.

Note that this option will ensure the safety of access to the file
system from multi-tasks (Task A blocking rw(fd), then Task B close(fd)),
the disadvantage is that it will increase the amount of code-size,
there is no need to enable this option if the application could ensure
he file operations are safe.

Signed-off-by: chao an <anchao@lixiang.com>
2024-12-12 13:47:22 +08:00
anjiahao
e15fe23424 procfs:fix cmdline overflow
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-12-12 11:49:37 +08:00
chao an
b99e7617aa fs/inode: refresh tcb after each file sync() is completed
After tcb is destroyed, it is very dangerous to back reference tcb through file.
This commit will perform file operations while ensuring the validity of tcb during
fsync, with will avoid tcb check in each subsystem.

Signed-off-by: chao an <anchao@lixiang.com>
2024-12-12 02:21:32 +08:00
simbit18
11f412b7af fix nxstyle
Removed extra spaces from .h and .c files
2024-12-10 01:29:00 +08:00
wangjianyu3
d4bcdcb2fc fs/tmpfs: Skip any slash at the beginning of relpath
`tmpfs_stat()` fails when relpath start with slash.

Log

  Host
    $ adb -s 1234 pull /tmp/subdir
    adb: warning: skipping special file '/tmp/subdir/uname' (mode = 0o0)
    /tmp/subdir/: 0 files pulled. 1 file skipped.

  Device
    state_process_list (411): stat failed </tmp/subdir//uname> -1 22

Ref: https://github.com/apache/nuttx/blame/master/libs/libc/stdlib/lib_realpath.c#L111
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2024-12-07 11:40:00 +08:00
zhangyuan29
dcea1b90e7 arch_atomic: only support atomic_xx and atomic64_xx function
Modify the kernel to use only atomic_xx and atomic64_xx interfaces,
avoiding the use of sizeof or typeof to determine the type of
atomic operations, thereby simplifying the kernel's atomic
interface operations.

Signed-off-by: zhangyuan29 <zhangyuan29@xiaomi.com>
2024-12-04 14:03:14 +01:00
hujun5
16f39fbb56 fs: use small lock to protect filelist
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-11-30 03:25:17 +08:00
wangmingrong1
4daafd0781 Fix path error
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-11-28 15:04:59 +08:00
YAMAMOTO Takashi
610c72ccd0 fs/littlefs: add LFS_MULTIVERSION support 2024-11-27 02:56:52 +08:00
YAMAMOTO Takashi
abd769dcb0 fs/littlefs: disable -Wshadow and explain why 2024-11-27 02:56:52 +08:00
YAMAMOTO Takashi
f7e2e23f12 fs/littlefs: stop applying local patches for unknown versions of littlefs
Because they are not expected to apply cleanly.
In that case, disable all features which require the local patches.

Note: lfs_util.patch is actually necessary regardless of
the littlefs version. It should be ok to drop it for the simplest
flat memory model configurations with a single heap though. I plan
to fix it once littlefs 2.9.4 is released.

Tested with esp32s3-devkitc:toywasm + CONFIG_FS_LITTLEFS_VERSION="v2.9.3".
2024-11-27 02:56:52 +08:00
YAMAMOTO Takashi
0157118ead fs/littlefs: don't use lfs_getsetattr.patch unless FS_LITTLEFS_ATTR_UPDATE 2024-11-27 02:56:52 +08:00