559 Commits

Author SHA1 Message Date
Xiang Xiao c47b1e2c5b !sys/types.h: change time_t and clock_t to int64_t to align with other OSes
POSIX leaves the signedness of time_t and clock_t unspecified, but
mainstream implementations (Linux glibc/musl, the BSDs, macOS, RTEMS,
Zephyr's POSIX layer, Windows _time64) expose time_t as signed 64-bit.
NuttX has historically used uint64_t only because it was tied to the
CONFIG_SYSTEM_TIME64 knob; with that gone, switch:

  time_t   : uint64_t  -> int64_t
  clock_t  : uint64_t  -> int64_t
  CLOCK_MAX: UINT64_MAX -> INT64_MAX

This lets (time_t)-1 sentinels, negative tick deltas, and host-side
headers behave as on every other POSIX system without source churn.

Headers updated:
  - include/sys/types.h, include/limits.h, include/nuttx/clock.h
  - include/nuttx/fs/hostfs.h (nuttx_time_t alias)
  - include/nuttx/{mqueue.h,wdog.h,wqueue.h,timers/clkcnt.h}

Because clock_t is now signed 64-bit, the NuttX-internal sclock_t
alias becomes redundant: every sclock_t/SCLOCK_MAX use is folded
back to clock_t/CLOCK_MAX (notably in sched/wdog, sched/mqueue,
sched/sched, sched/clock, sched/timer, libs/libc/time, fs/vfs and
the drivers/arch consumers below).

Tick/period constants (NSEC_PER_SEC, USEC_PER_SEC, MSEC_PER_SEC,
SEC_PER_MIN, ...) in include/nuttx/clock.h are retyped from "long"
literals to INT64_C(...) so that 64-bit arithmetic no longer
depends on the host's long width.

Strip now-redundant (time_t)/(clock_t)/(unsigned long) casts and
unsigned-only branches across the tree:
  - arch RTC / oneshot / tickless lowerhalfs:
      arm: cxd56xx, efm32, imxrt, lc823450, max326xx, sam34, sama5,
           samd5e5, samv7, stm32, stm32f7, stm32h7, stm32l4, stm32wb,
           xmc4
      mips: pic32mz       sparc: bm3803       x86_64: intel64
      risc-v/xtensa: espressif (esp_i2c[_slave], esp_rtc,
           esp32c3{_i2c,_rtc,_wifi_adapter}, esp32{,s2,s3}_*),
           mpfs_perf
  - drivers: audio/tone, input/aw86225, power/pm/{activity,
           stability}_governor, rpmsg/rpmsg_ping,
           timers/{ds3231,mcp794xx,pcf85263,rx8010},
           wireless/ieee80211/bcm43xxx, wireless/spirit/spirit_spi
  - core: fs/vfs/{fs_poll,fs_timerfd}, mm/iob/iob_alloc,
          libs/libc/{netdb/lib_dnscache,time/{lib_calendar2utc,
          lib_time}}, net/icmp/icmp_pmtu, net/icmpv6/icmpv6_pmtu,
          net/ipfrag, net/tcp/{tcp.h,tcp_timer},
          net/utils/net_snoop, net/mld/mld_query (drop the now-dead
          mld_mrc2mrd helper since signed math handles it directly),
          sched/clock/{clock,clock_initialize},
          sched/sched/{sched_profil,sched_setparam,sched_setscheduler},
          sched/pthread/pthread_create,
          sched/wdog/{wd_gettime,wd_start,wdog.h},
          sched/timer/timer_gettime, sched/mqueue/*

Flip the few in-tree printf format strings that assumed an
unsigned 64-bit tv_sec:
  * drivers/rpmsg/rpmsg_ping.c                       PRIu64 -> PRId64
  * arch/xtensa/src/esp32{,s2,s3}/esp32*_oneshot_lowerhalf.c
                                          PRIu32 (already wrong) -> PRId64

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2026-05-19 16:21:28 +08:00
Abhishek Mishra 702fd85acc fs/vfs: enforce pseudoFS permissions on open()
Add inode_checkperm() and integrate it into file_vopen()
to enforce UNIX-style read/write permission checks for
pseudoFS inodes using effective uid/gid credentials.

Skip permission enforcement for mountpoint inodes and
allow kernel threads to bypass checks.

Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
2026-05-17 15:48:29 -03:00
Abhishek Mishra 08dded1f22 fs/vfs: fix pseudoFS mode reporting
Preserve only the existing file type bits (S_IFMT) and
replace permission bits from inode->i_mode instead of
merging them with |= semantics.

This fixes pseudoFS stat()/ls mode reporting after
chmod() updates.

Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
2026-05-14 02:43:41 -04:00
Lwazi Dube 7e0f282718 fs/vfs: allow NULL iov_base in KERNEL build with zero-based text
Build Documentation / build-html (push) Has been cancelled
This commit fixes a regression introduced by
89df084b0e. That commit
added a check to ensure iov_base is not NULL, assuming NULL
always represents an inaccessible address.

However, in CONFIG_BUILD_KERNEL mode where CONFIG_ARCH_TEXT_VBASE
is set to 0, address zero is a valid virtual address for the
user-space text segment. The previous check caused libelf to
fail with -EFAULT when attempting to load ELF program headers
into the base of the user address space.

This patch wraps the safety check in a conditional to ensure it is
only executed when address zero is not considered a valid
executable base.

Signed-off-by: Lwazi Dube <lwazeh@gmail.com>
2026-05-06 01:37:53 +08:00
zhanxiaoqi 786b315947 fs/inode: add optional manual FD backtrace control via task group flag
When CONFIG_FS_BACKTRACE is enabled, collecting a stack trace for every
new file descriptor adds overhead to fast path operations like open(),
dup(), and socket().

This patch adds a new configuration option CONFIG_FS_BACKTRACE_DEFAULT.
When enabled (default behavior), the GROUP_FLAG_FD_BACKTRACE flag is
automatically set during group allocation, causing backtrace to be
captured for all tasks globally, preserving the original diagnostic
capability.

When disabled, backtrace capture is zero-cost by default and must be
explicitly enabled per task group using GROUP_FLAG_FD_BACKTRACE.

Signed-off-by: zhanxiaoqi <zhanxiaoqi@bytedance.com>
2026-04-28 09:53:27 +02:00
Jari Nippula 62b71c3b30 fs/vfs/fs_lock.c: Close stale locks unconditionally
Allow to close the lock even the dying task is in
signal handler context. Also the file type check can
be ignored as they are already validated in create phase.

Signed-off-by: Jari Nippula <jari.nippula@tii.ae>
2026-04-28 11:51:35 +08:00
Sumit6307 b2b78d2f8a fs: Add Kernel-level VFS Performance Profiler
Build Documentation / build-html (push) Has been cancelled
This adds a kernel-level performance profiler for the VFS.
By enabling CONFIG_FS_PROFILER, the core VFS system calls
(file_read, file_write, file_open, and file_close) are
instrumented to track high-resolution execution times using
clock_systime_timespec() seamlessly.

The collected statistics are exposed dynamically via a new
procfs node at /proc/fs/profile, allowing CI regression
testing without needing external debugging tools.

Signed-off-by: Sumit6307 <sumitkesar6307@gmail.com>
2026-04-26 11:50:09 -03:00
Abhishek Mishra 5c9de46c79 fs/vfs/fs_fstat.c: fix write capability check in proxy_fstat()
Build Documentation / build-html (push) Has been cancelled
In proxy_fstat(), the write permission bits for a block driver proxy
were gated on `i_ops->read` instead of `i_ops->write`:
The effect is that a driver implementing read but not write would have
S_IWOTH | S_IWGRP | S_IWUSR incorrectly set in the fstat() result,
reporting the file as writable when it is not.

Fix: replace `->read` with `->write` in the write check condition.

Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
2026-04-16 13:35:41 +02:00
Piyush Patle 0dccc8ba21 include/debug.h: Move to include/nuttx/debug.h
debug.h is a NuttX-specific, non-POSIX header. Placing it in the
top-level include/ directory creates naming conflicts with external
projects that define their own debug.h.
This commit moves the canonical header to include/nuttx/debug.h,
following the NuttX convention for non-POSIX/non-standard headers,
and updates all in-tree references.

A backward-compatibility shim is left at include/debug.h that
emits a deprecation #warning and re-includes <nuttx/debug.h>,
allowing out-of-tree code to continue building while migrating.

Signed-off-by: Piyush Patle <piyushpatle228@gmail.com>
2026-04-07 07:50:06 -03:00
Huang Qi e3eeaefd6d style: Fix "the the" typo across the codebase.
Fix 269 occurrences of duplicate "the" word typo found in 209 files
across source code, header files, and configuration.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2026-03-23 11:07:49 +01:00
dongjiuzhu1 3c486b98dd fs/timerfd: implement TFD_TIMER_CANCEL_ON_SET to detect clock changes
Implement Linux-compatible TFD_TIMER_CANCEL_ON_SET flag for timerfd to
allow applications to detect discontinuous changes to CLOCK_REALTIME.

Background:
According to Linux timerfd_create(2) man page, when a timerfd is created
with CLOCK_REALTIME and TFD_TIMER_CANCEL_ON_SET flag is specified, the
read() operation should fail with ECANCELED if the real-time clock
undergoes a discontinuous change. This allows applications to detect
and respond to system time changes.

Implementation:
1. Add clock notifier infrastructure (clock_notifier.h/c) to notify
   interested parties when system time changes
2. Implement TFD_TIMER_CANCEL_ON_SET flag support in timerfd
3. Register timerfd with clock notifier when flag is set
4. Cancel timer and return ECANCELED when clock change is detected
5. Notify clock changes in:
   - clock_settime()
   - clock_initialize()
   - clock_timekeeping_set_wall_time()
   - rpmsg_rtc time synchronization

Changes include:
- New files: include/nuttx/clock_notifier.h, sched/clock/clock_notifier.c
- Modified: fs/vfs/fs_timerfd.c to handle TFD_TIMER_CANCEL_ON_SET
- Modified: clock subsystem to call notifier chain on time changes
- Modified: rpmsg_rtc to notify time changes during sync

Use case example:
Applications using timerfd with absolute time can now detect when
system time is adjusted (e.g., NTP sync, manual time change) and
take appropriate action such as recalculating timeouts or updating
scheduled events.

Reference: https://man7.org/linux/man-pages/man2/timerfd_create.2.html

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2026-01-30 17:20:24 +08:00
buxiasen d3e5e756c5 fs/vfs/symlink: fix the inode information update outside of lock
For re-enter case, the inode information may unlock with not filled,
and get by other user. that lead to the error behavior.
Especially SMP scene.

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2026-01-28 10:03:06 +08:00
jiangtao16 3491cef8a8 sched/timer: Fix MISRA Rule 10.3
Fix MISRA Rule 10.3 exist clock to sclock cause wide type implicit conversion to narrow type, NSEC_PER_USEC to l

Signed-off-by: jiangtao16 <jiangtao16@xiaomi.com>
2026-01-22 22:14:00 +08:00
wangchengdong faf864b04f sched/signal: Add support for disabling all signal functions
Signals in NuttX serve two primary purposes:

      1. Synchronization and wake-up:
        Signals can be used to block threads on specific signal sets and later
        wake them up by delivering the corresponding signals to those threads.

      2. Asynchronous notification:
        Signals can also be used to install callback handlers for specific signals, allowing threads to
        asynchronously invoke those handlers when the signals are delivered.

    This change introduces the ability to  disable all signal functionality to reduce footprint for NuttX.

Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
2026-01-18 08:24:13 -03:00
dongjiuzhu1 148f0ce7dd fs/inode: use file_allocate,file_dup to avoid racecondition to allocate fd
issue description:
task A:                                            NSH:
1.open->                                           reboot->sync->task_fsfsync
2.nx_vopen->               context switch
3.fdlist_allocate:            ---->                4.fsync->file_sync->assert(inode or priv is empty)
(new fd with empty filep)
5.file_vopen:
(init empty filep)
6.return fd

Task A allocates a new fd with an empty filep in fdlist_allocate. Before
it can fully initialize the filep in file_vopen, the NSH task triggers a
file - system sync operation. The sync operation encounters the empty
filep associated with the newly allocated fd, causing the assertion to
fail and the system to crash.

To resolve this race condition, we should modify the fd allocation
process. Instead of allocating a new fd with an empty filep first and
then initializing it later, we should use the file_allocate_from_inode
function. This function allows us to initialize the file structure first
and then bind it to the new filep when allocating the fd. By doing so,
we ensure that the filep is always properly initialized before it is
used in any file - system operations, thus preventing the assertion
failure and the subsequent system crash.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2026-01-09 17:11:25 +08:00
dongjiuzhu1 12079a213d fs/eventfd/timerfd: update sem next to avoid busy loop
Build Documentation / build-html (push) Has been cancelled
fix bug about busy loop

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2026-01-02 07:55:37 -03:00
dongjiuzhu1 cd8e3e18a8 fs/file: add reference count protection for stack-allocated file structures
Issue:
When using a stack-allocated file structure, the sequence:
1. file_open() initializes the stack file structure
2. file_mmap() creates memory mapping and increments reference count
3. file_munmap() decrements reference count and may free the file structure
4. file_close() attempts to close already freed structure → crash

Root cause:
The memory mapping operations (fs_reffilep/fs_putfilep) manage reference counts
independently and can free the stack-allocated file structure prematurely.

Solution:
- Add reference count protection during file_open() for stack-allocated files
- Clear reference count appropriately during file_close()
- This ensures the file structure remains valid throughout its lifetime

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2026-01-01 17:06:17 +08:00
dongjiuzhu1 291199f833 fs/epoll: add TLS cleanup handler to release epoll fd reference on thread exit
When a thread is terminated via pthread_exit() while blocked in epoll_wait(),
the file reference taken at the beginning of epoll_wait() is not properly
released, leading to resource leaks.

Problem scenario found during libuv test:
1. Echo server thread is blocked in epoll_wait()
2. Main task sends pthread_kill signal to the server thread
3. Signal handler calls pthread_exit() to terminate the thread
4. epoll_wait() is interrupted before reaching the file_put() call
5. The epoll fd reference count remains elevated
6. epoll_do_close() is never called, leaving fds in internal queues
7. File descriptors leak

Solution:
Register a TLS (Thread Local Storage) cleanup handler using tls_cleanup_push()
at the beginning of epoll_wait() blocking section. This ensures that if the
thread exits abnormally (via pthread_exit, pthread_cancel, etc.), the cleanup
handler (epoll_cleanup) will be called automatically to release the file
reference via file_put().

The cleanup handler is properly paired with tls_cleanup_pop() when epoll_wait()
completes normally, ensuring the handler is only invoked on abnormal exit.

This fix is applied to both epoll_wait() code paths (with and without extended
mode) to ensure consistent behavior.

Impact:
- Prevents epoll fd reference count leaks on thread cancellation
- Ensures proper cleanup even when epoll_wait() is interrupted by pthread_exit
- Critical for multi-threaded applications using signals and thread termination
- Works together with previous fix for teardown/oneshot list cleanup

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-12-31 08:49:04 -03:00
dongjiuzhu1 61a2ab98ef fs/epoll: release refs count of teardown/oneshot to avoid fd leak on close
When an epoll fd is closed, the file descriptors in the teardown and
oneshot lists were not being properly dereferenced, leading to fd leaks.

This fix ensures that all fds in the teardown and oneshot lists are
properly released via file_put() during epoll_do_close(), matching the
behavior for fds in the setup list.

Impact:
- Prevents fd leaks when epoll fd is closed
- Ensures proper cleanup of all tracked file descriptors
- Critical for applications using EPOLLONESHOT or fd removal operations

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-12-31 08:49:04 -03:00
guohao15 14942b5ab4 bugfix/fs:write Bad buf addr should return EINVAL
return EINVAL if iov_base == NULL

Signed-off-by: guohao15 <guohao15@xiaomi.com>
2025-12-16 19:41:19 +08:00
dongjiuzhu1 c1b2b1b4fb poll: fix covertify issue about out-of-bound access fds
when i is zero and file_get is failed, num is -1,
it's uint32_max for nfds.
so remove num and simplify code logic.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-12-15 10:16:05 +08:00
zhanghongyu 1bf71795fc select: fix too small timeout will be counted as 0
avoiding timeouts less than 1ms may lead to busyloop

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-06 17:46:20 +08:00
wangchengdong ba05c7f133 sched/signal: Fix nxsig_ismember() return value behavior
Build Documentation / build-html (push) Has been cancelled
nxsig_ismember() has a return type of int, but the current
implementation returns a boolean value, which is incorrect.

All callers should determine membership by checking whether
the return value is 1 or 0, which is also consistent with the POSIX sigismember() API.

Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
2025-11-25 10:02:52 +08:00
Antoine Juckler 23de88e70e fs/fs.h: Add register_driver_with_size function
It acts as register_driver but also populates the inode size.
This allows to return a non-zero size when calling stat() on an eeprom
driver.

The conditions (CONFIG_PSEUDOFS_FILE or CONFIG_FS_SHMFS) for the
declaration of the inode size field have also been removed so that other
drivers can populate this field in the future.

Signed-off-by: Antoine Juckler <6445757+ajuckler@users.noreply.github.com>
2025-11-13 08:57:52 -03:00
chao an 10fd309452 sched/signal: Remove shadow definitions to reduce unnecessary API
Reduce unnecessary API definitions:

nxsig_waitinfo() -> nxsig_timedwait()

Signed-off-by: chao an <anchao.archer@bytedance.com>
2025-10-14 17:40:18 +08:00
Zhe Weng 61c8240458 fs/lock: Allow driver lock
Sometimes we need to flock a driver node, which we can support easily.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2025-08-12 20:17:06 +08:00
Liu, Richard Jiayang d2282ec26a fs/vfs/fs_rename: fix directory move operation.
* Recurrency is removed from filesystem directory rename.
* Fixes use after free in buffer that was used as output and argument.

Signed-off-by: Tomasz 'CeDeROM' CEDRO <tomek@cedro.info>
2025-07-31 01:53:59 +08:00
jingfei c3e87dd3d1 drivers/fs: Control the behavior of FTL by passing oflags during the open process.
To save more space (equivalent to the size of one erase sector of
MTD device) and to achieve faster read and write speeds, a method
for direct writing was introduced at the FTL layer.
This can be accomplished simply by using the following oflags during
the open operation:

1. O_DIRECT. when this flag is passed in, ftl internally uses
   the direct write strategy and no read cache is used in ftl;
   otherwise, each write will be executed with the minimum
   granularity of flash erase sector size which means a
   "sector read back - erase sector - write sector" operation
   is performed by using a read cache buffer in heap.

2. O_SYNC. When this flag is passed in, we assume that the
   flash has been erased in advance and no erasure operation
   will be performed internally within ftl. O_SYNC will take
   effect only when both O_DIRECT and O_SYNC are passed in
   simultaneously.

3. For uniformity, we remapped the mount flag in mount.h and
   unified it with the open flag in fcntl.h. The repetitive
   parts of their definitions were reused, and the remaining
   part of the mount flag redefine to the unused bit of open
   flags.

Signed-off-by: jingfei <jingfei@xiaomi.com>
2025-07-16 14:11:41 +08:00
dongjiuzhu1 ae33447220 fs/vfs: fix bug about lost dup oflags in dup2
this issue is caused by commit: b8e30b54ec

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-07-15 19:46:24 +08:00
dongjiuzhu1 e85cdac2ed fs/vfs: clear filep when call file_open/file_mq_open to avoid random value
fix crash caused by stack random value

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-06-26 09:31:14 -03:00
Xiang Xiao c9dc89142c fs: Move inotify.c from fs/notify/ to fs/vfs/
and merge fs/notify/notify.h into fs/vfs/vfs.h

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2025-06-23 18:17:10 -03:00
Xiang Xiao 1ea0ae8073 fs/vfs: Rename lock.h to vfs.h
vfs.h will contain other internal functions in the future

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2025-06-23 18:17:10 -03:00
Michal Lenc 01bfa1a500 fs/vfs/fs_close.c: avoid double free if CONFIG_FS_NOTIFY is set
Double free occurred in lib_put_pathbuffer if CONFIG_FS_NOTIFY option
was enabled. The second if statement has to be called only if the
close operation returned error. The bug was introduced in 14f5c48
and was causing misc/lib_tempbuffer.c:141 debug assertion.

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
2025-06-16 20:23:53 +08:00
dongjiuzhu1 5fd1ab8e0f fs/fcntl: using ioctl to implement FIOGCLEX/FIOCLEX/FIONCLEX
these command FIOGCLEX/FIOCLEX/FIONCLEX are related to struct fd,
so need to use ioctl to implement.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-06-15 07:12:44 -03:00
Ville Juven b8e30b54ec fs/vfs: Separate file descriptors from file descriptions
This patch is a rework of the NuttX file descriptor implementation. The
goal is two-fold:

1. Improve POSIX compliance. The old implementation tied file description
to inode only, not the file struct. POSIX however dictates otherwise.
2. Fix a bug with descriptor duplication (dup2() and dup3()). There is
an existing race condition with this POSIX API that currently results
in a kernel side crash.

The crash occurs when a partially open / closed file descriptor is
duplicated. The reason for the crash is that even if the descriptor is
closed, the file might still be in use by the kernel (due to e.g. ongoing
write to file). The open file data is changed by file_dup3() and this
causes a crash in the device / drivers themselves as they lose access to
the inode and private data.

The fix is done by separating struct file into file and file descriptor
structs. The file struct can live on even if the descriptor is closed,
fixing the crash. This also fixes the POSIX issue, as two descriptors
can now point to the same file.

Signed-off-by: Ville Juven <ville.juven@unikie.com>
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-06-12 18:12:42 +08:00
dongjiuzhu1 a12d21e830 fs/file: unify prefix about file_xxx api, like file_open, file_ioctl
old:
fs_getfilep, fs_putfilep, fs_reffilep
new:
file_get, file_put, file_ref

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-06-12 18:12:42 +08:00
dongjiuzhu1 9ca5c1d9c6 fs/file: unify prefix f_ for member locked
update locked to f_locked

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-06-12 18:12:42 +08:00
dongjiuzhu1 70fc5c3e77 fs/dup: remove unnecessary backup about fdcheck_tag and fdsan_tag
1. The call to file_close_without_clear in file_dup3 does not clear
the tag information, so there is no need to back it up.
2. file_dup3 don't need to copy tag information, tag is only valid for fd.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-06-12 18:12:42 +08:00
Ville Juven 1e787ea280 nuttx/fs: Reorganize the code for close, dup, et. al.
Currently the code is dumped into one massive file; fs_files. Move the
different logical parts into their own files.

Signed-off-by: Ville Juven <ville.juven@unikie.com>
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-06-12 18:12:42 +08:00
Ville Juven 3fe1d1a54d fs/pseudofs: Add missing bumping of inode refcount
When a new pseudofile is created, the inode reference count needs to
be bumped to protect the node.

Signed-off-by: Ville Juven <ville.juven@unikie.com>
2025-06-12 18:12:42 +08:00
wangjianyu3 5e94d4482b fs/vfs: check buffer count and pointer for iovec
There are iovecs provided by user such as readv().

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2025-06-10 09:58:25 +08:00
wangjianyu3 89df084b0e fs/vfs: check if all iov_base are accessible
Check if all `iov_base` are inside accessible address space.

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2025-06-10 09:58:25 +08:00
dongjiuzhu1 4f57ebce66 fs/poll: remove poll_fdsetup
Build Documentation / build-html (push) Has been cancelled
Allow users to operate poll in the kernel using the file_poll
approach, as file is protected with reference counting,
making it more secure.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-05-26 18:49:45 +08:00
dongjiuzhu1 77a0478095 fs/epoll: using filep with reference counting instead of file descriptors
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-05-26 18:49:45 +08:00
Lars Kruse 3ce85ca54e style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
zhangshoukui f57a5a6802 fs/vfs/fs_dup.c: before file_allocate should restore minfd if define FDCHECK
When we use fcntl for dup, an fd is directly passed. If we have opened FDCHECK. we need to restore this file descriptor.

open FDCHECK and test this:

`
int main(int ac, char **av)
{
  int fd1= open("./1.txt", O_WRONLY | O_CREAT, 0666);
  if (fd1 < 0)
    {
      printf("open err\n");
      return fd1;
  }

  int fd2= open("./2.txt", O_WRONLY | O_CREAT, 0666);
  if (fd2 < 0)
    {
      printf("open err\n");
      close(fd1);
      return fd2;
    }

  //close(fd2);
  int fd3 = fcntl(fd1, F_DUPFD, fd2);
  printf("fd3 = %d\n", fd3);
  close(fd1);
  close(fd3);
  return 0;
}
`

Signed-off-by: zhangshoukui <zhangshoukui@xiaomi.com>
2025-05-15 16:51:40 -03:00
dongjiuzhu1 83967601aa fs/close: move inode to last to void race condition
race condition:

A Thread:                                    B Thread:
close
file_close
filep->inode = NULL
                         context switch
	               ------------------->  open to alloc same fd
                                             read from IO
filep->f_tag = 0       <-------------------
filep->f_san = 0       ------------------->  ioctl(fd, ...)
                                             fdcheck trigger assert

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-05-14 15:02:38 +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
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