Commit graph

2357 commits

Author SHA1 Message Date
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 9af5fc5d09)

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
wangjianyu3
d83ab55e00 fs/partition/txtable: Fix panic when no txtable was found in last eraseblock
Panic occured if no txtable was found in last eraseblock of MTD device and `CONFIG_TXTABLE_DEFAULT_PARTITION` was disabled

Backtrace

  sched_dumpstack
  /workspace/nuttx/libs/libc/sched/sched_dumpstack.c:71
  dump_assert_info
  /workspace/nuttx/sched/misc/assert.c:718
  xtensa_user_panic
  /workspace/nuttx/arch/xtensa/src/common/xtensa_assert.c:188 (discriminator 1)
  xtensa_user
  ??:?
  _xtensa_user_handler
  /workspace/nuttx/arch/xtensa/src/common/xtensa_user_handler.S:194
  ??
  ??:0
  parse_txtable_partition
  /workspace/nuttx/fs/partition/fs_txtable.c:136
  parse_partition
  /workspace/nuttx/fs/partition/fs_partition.c:165
  parse_mtd_partition
  /workspace/nuttx/fs/partition/fs_partition.c:291

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2024-11-26 18:23:06 +08:00
YAMAMOTO Takashi
92b9a30878 fs/littlefs: make CONFIG_FS_LITTLEFS_VERSION include the "v" prefix
To allow other tags/branches like "devel" and even sha256 hash.
2024-11-25 20:15:53 -03:00
chao an
24add5eeaf spelling: fix spelling typo premp -> preemp
Signed-off-by: chao an <anchao@lixiang.com>
2024-11-25 22:05:05 +08:00
YAMAMOTO Takashi
72a8764ea8 fs/littlefs: Add a kconfig to override littlefs version
Hopefully, It's more user-friendly than the current method,
which is just an overridable make variable. It would also help
to make some features (and their associated local patches)
conditional on littlefs version in future.

Also, update CMakeLists.txt to use the same littlefs version as Makefile.
2024-11-22 21:02:54 +08:00
chenrun1
6a19264c97 littlefs_fstat:Ignore When the error is LFS_ERR_NOENT, we assume that the attr attribute is not set.
Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-11-19 11:08:07 -03:00
chenrun1
27eaa23219 lfs:Added LITTLEFS_USE_ATTR to control whether to save attributes when
create file

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-11-19 11:08:07 -03:00
YAMAMOTO Takashi
9a2b6be842 Update a few comments after the recent readv/writev changes
No functional changes are expected.
2024-11-18 19:10:24 +08:00
hujun5
19b4911d7f arch: remove up_current_regs in common code
reason:

When entering an exception or interrupt, there are two sets of registers:
one is the "running regs", which we need to save,
and the other is the "ready to running regs", which we may soon use.
For consistency in logic, we can always store the "running regs" in the regs field of g_running_tasks,
otherwise it may lead to errors in the storage location of the "running regs."

When we need to access the "running regs," we should uniformly retrieve them from the regs field of g_running_tasks.

As the next step, we will rename the set_current_regs/up_current_regs functions
for each architecture to more appropriate names, solely for the purpose of identifying interrupts.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-11-15 18:25:35 +08:00
wangjianyu3
4266580319 fs/procfs: The procfsversion should be under control of FS_PROCFS_EXCLUDE_VERSION
Env

  sim:nsh
  - CONFIG_FS_PROCFS_EXCLUDE_PROCESS=y

Error

  LD:  nuttx
  /usr/bin/ld: nuttx.rel:(.rodata.g_procfs_entries+0xc8): undefined reference to `g_version_operations'
  collect2: error: ld returned 1 exit status
  make[1]: *** [Makefile:429: nuttx] Error 1
  make: *** [tools/Unix.mk:551: nuttx] Error 2

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2024-11-13 12:31:46 -03:00
chenrun1
8068ba75ec fs_automount:fix ci break
====================================================================================
Configuration/Tool: spresense/example_camera,CONFIG_ARM_TOOLCHAIN_GNU_EABI
2024-11-12 12:24:37
------------------------------------------------------------------------------------
  Cleaning...
  Configuring...
  Disabling CONFIG_ARM_TOOLCHAIN_GNU_EABI
  Enabling CONFIG_ARM_TOOLCHAIN_GNU_EABI
  Building NuttX...
mount/fs_automount.c: In function 'automount_initialize':
Error: mount/fs_automount.c:816:7: error: 'return' with no value, in function returning non-void [-Werror=return-type]
  816 |       return;
      |       ^~~~~~
In file included from mount/fs_automount.c:43:
/github/workspace/sources/nuttx/include/nuttx/fs/automount.h:176:11: note: declared here
  176 | FAR void *automount_initialize(FAR const struct automount_lower_s *lower);
      |           ^~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-11-13 13:16:51 +08:00
chenrun1
2cf26036a5 Use lib_get_pathbuffer instead of stack variables
Summary:
  Modified the usage logic, mainly introduced lib_get_pathbuffer and lib_put_pathbuffer

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-11-12 17:21:42 +08:00
chenrun1
0c9203b48e v9fs/CMakeLists.txt:Fix the problem that virtio-9p is not compiled properly in cmake
Summary:
  change CONFIG_DRIVERS_VIRTIO_9P -> CONFIG_V9FS_VIRTIO_9P

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-11-12 16:13:27 +08:00
wangjianyu3
0702dc5361 fs/vfs: Fix initialization of g_pseudofile_ops
Config: sim:nsh

Log

  CC:  driver/fs_registerblockdriver.c vfs/fs_pseudofile.c:99:3: warning: initialization of ‘ssize_t (*)(struct file *, const struct uio *)’ {aka ‘long int (*)(struct file *, const struct uio *)’} from incompatible pointer type ‘int (*)(struct inode *)’ [-Wincompatible-pointer-types]
      99 |   pseudofile_unlink,   /* unlink */
         |   ^~~~~~~~~~~~~~~~~
  vfs/fs_pseudofile.c:99:3: note: (near initialization for ‘g_pseudofile_ops.readv’)

Related: https://github.com/apache/nuttx/pull/13498

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2024-11-10 00:53:40 +08:00
wanggang26
929bbf0be8 fs: add merge partitions support
Usage example for merging the factory partition and reserve
partition into the merge partition:
register_merge_blockdriver("/dev/merge", "/dev/factory", "/dev/reserve",
NULL)

Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2024-11-07 14:59:23 +08:00
Alin Jerpelea
6833b8787e fs: migrate to SPDX identifier
Most tools used for compliance and SBOM generation use SPDX identifiers
This change brings us a step closer to an easy SBOM generation.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2024-11-06 01:58:54 +08:00
YAMAMOTO Takashi
8241a10ebc file_readv_compat/file_writev_compat: Fix partial success handling
The problem has been inherited from the original libc readv/writev
implementation. However, now it's exposed in more situations because
this implemenation is used to back read/write as well.

I expect this fixes the regressions observed on the Espressif CI.
https://github.com/apache/nuttx/pull/13498#issuecomment-2448031197

Note that, even with this fix, these "compat" readv/writev
implementations are still inheritedly broken. (E.g. consider that
a data boundary happens to match one of iovec boundaries) However,
this fix is enough for read/write, where iovcnt is always 1.
2024-11-05 16:57:05 +08:00
Saurav Pal
4e53ee4486 fs/mnemofs: Fix open and rmdir return value and seek out of bounds.
- Update open return value to ENOTDIR when ancestor is a file.
- Update rmdir return value to ENOTDIR when path is not a directory.
- Better logs for file and dir operations.

Signed-off-by: Saurav Pal <resyfer.dev@gmail.com>
2024-11-03 16:01:58 +08:00
ouyangxiangzhen
17c51c0667 userspace: Exclude nuttx/arch.h
This patch fixed userspace headers conflict. Architecture-related definition and API should not be exposed to users.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2024-11-01 16:59:37 +08:00
dongjiuzhu1
47478e543d fs/shm: support shm_open with flags O_TRUNC
testcase:
https://fossies.org/linux/posixtestsuite/conformance/interfaces/shm_open/25-1.c

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2024-10-31 18:47:51 -03:00
xuxin19
36b891c1e1 cmake(bugfix):fix fs cmake typo
Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2024-10-30 22:14:40 +08:00
YAMAMOTO Takashi
761ee81956 move readv/writev to the kernel
currently, nuttx implements readv/writev on the top of read/write.
while it might work for the simplest cases, it's broken by design.
for example, it's impossible to make it work correctly for files
which need to preserve data boundaries without allocating a single
contiguous buffer. (udp socket, some character devices, etc)

this change is a start of the migration to a better design.
that is, implement read/write on the top of readv/writev.

to avoid a single huge change, following things will NOT be done in
this commit:

* fix actual bugs caused by the original readv-based-on-read design.
  (cf. https://github.com/apache/nuttx/pull/12674)

* adapt filesystems/drivers to actually benefit from the new interface.
  (except a few trivial examples)

* eventually retire the old interface.

* retire read/write syscalls. implement them in libc instead.

* pread/pwrite/preadv/pwritev (except the introduction of struct uio,
  which is a preparation to back these variations with the new
  interface.)
2024-10-30 17:07:54 +08:00
zhangshoukui
198dd93713 shmfs: return EINVAL if group null
Signed-off-by: zhangshoukui <zhangshoukui@xiaomi.com>
2024-10-29 18:11:33 +08:00
zhangshoukui
646bf48ed2 shmfs: Assign a variable when object is not null
Signed-off-by: zhangshoukui <zhangshoukui@xiaomi.com>
2024-10-29 18:11:33 +08:00
Saurav Pal
17bca89f07 fs/mnemofs: Fix mkdir for depth > 3 bug, better logs
- Fix bug which prevents mkdir for depth > 3.
- Better logs for mnemofs

Signed-off-by: Saurav Pal <resyfer.dev@gmail.com>
2024-10-29 02:23:58 +08:00
Alejandro Aguirre
0095009076 fs/nfs: fix offset in append mode and attributes after create
- When opening a NFS file in append mode, its file pointer was at offset
  0 instead of the end of file.

- When creating a NFS file, the response read pointer wasn't advanced
  after reading the attributes_follows bool, which caused the attributes
  to be off by 4 bytes. For example, the file size read the GID.

Signed-off-by: Alejandro Aguirre <alejandro.aguirre@midokura.com>
2024-10-28 19:40:30 +08:00
Neo Xu
8a70377fc4 fs/shm: align memory size to cache line size
Make sure the share memory takes the full cache line.

Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
2024-10-27 10:38:58 +08:00
xuxingliang
9af5fc5d09 fs/shm: alloc aligned memory if CPU has cache
For kernel builds, shared memory is automatically aligned to page size.
For flat and protected builds, we align the memory size to the CPU cache
line size.

Failure to align memory properly could result in partial data read/write
by the CPU and peripherals, potentially causing data corruption during
cache flushes or invalidations.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-10-27 10:38:58 +08:00
xuxingliang
22bcb88687 fs_heap: add memalign interface
So the share memory can use it to malloc aligned memory.
Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-10-27 10:38:58 +08:00
ligd
662bbeb33e container_of: fix compile failed cause of list.h not support container_of
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-10-23 20:10:43 +08:00