jingfei195887 opened a new pull request, #22535:
URL: https://github.com/apache/nuttx/pull/22535

   ## Summary
   
   Retain the mode supplied at pseudoFS node creation regardless of 
`CONFIG_PSEUDOFS_ATTRIBUTES`. For example, an ioctl-only device registered with 
mode `0640` reports `0640` rather than mode zero when extended attributes are 
disabled. `chmod`/`fchmod` and `rename` update or preserve the stored mode.
   
   Initialize the static eventfd, timerfd, signalfd, inotify, cryptodev and 
OP-TEE shared-memory inodes explicitly so that removing callback-derived 
permissions does not turn their modes into zero. Update Kconfig help and the 
pseudoFS and permission documentation. Owner, group and timestamp fields remain 
optional.
   
   ## Impact
   
   - YES, metadata behavior: stat mode comes from creation/registration and 
subsequent chmod. Driver callback availability no longer determines named 
pseudoFS permission bits.
   - YES, compatibility: pseudo-files intended to be executable need explicit 
execute bits at creation or via chmod. Static eventfd and cryptodev descriptor 
mode is 0666 and OP-TEE shared-memory mode is 0600, timerfd/signalfd 0444, and 
inotify 0444 (0666 with notification injection); these defaults also replace 
the old zero mode with extended attributes enabled.
   - YES, memory: on the tested simulator layouts with extended attributes 
disabled, sizeof(struct inode) is 40 to 44 bytes on 32-bit and 72 to 80 on 
64-bit. With extended attributes enabled, the tested 64-bit layout remains 136 
bytes. Other ABI/configuration layouts can differ.
   - NO new option or permission-enforcement policy: `CONFIG_FS_PERMISSION` 
retains its dependencies and checks. Static inode modes do not add unsupported 
operations or alter descriptor open flags. Mounted filesystems, socket fstat 
and special block/MTD proxy fstat retain their dispatch.
   - YES, documentation and Kconfig help. No build-system change.
   
   ## Testing
   
   Host: Linux x86_64, GCC 13.1.0. Baseline NuttX 
f7a8e713ccf277a36f37652b5e769af8a27d21e1; candidate 
8ab9318affc0d4ef375fd9418941e5c8634a4e92. Functional matrix apps 
0a37af9866b7e558fe186da4de7d99cc3dda51d7; final gate apps 
0a37af9866b7e558fe186da4de7d99cc3dda51d7. Targets: sim:nsh (32/64-bit runtime), 
qemu-armv7r:pnsh and qemu-armv8a:knsh (compile only).
   
   The local fixture exercises ioctl-only/read-only/write-only drivers, 
supplied and zero modes, stat/fstat/chmod/fchmod, rename, directories, 
pseudo-files and execute-mode access, FIFO, symlink/lchmod, hard links, 
block/MTD geometry, a TMPFS control, and eventfd/timerfd/signalfd/inotify/epoll 
descriptors. Additional cryptodev checks cover CRIOGET, dup, empty-session 
CIOCCLONE, descriptor flags, fstat and close; no cryptographic algorithm or 
hardware engine is exercised. The final ANON line is cumulative after the 
ordinary fixture in the same simulator boot; do not add the earlier RESULT 
count to it.
   
   Some configurations print the same pre-existing startup `/tmp` mount error 
on both revisions. The fixture uses `/mode-volume` for its TMPFS control and 
checks that mount and unmount directly.
   
   Permission-enabled runs exclude pseudo-file creation: an independent 
existing file_vopen failure was observed on original baseline 4fbd48185326 and 
the initial candidate (the affected functions are unchanged in the refreshed 
baseline) with that option enabled. Those stopped diagnostic runs are not 
counted as passing tests. The limited permission configuration still checks 
registered devices, zero-mode access rejection, directories, links and mounted 
TMPFS.
   
   No physical hardware, SMP, protected/kernel runtime, OP-TEE secure service 
or real OP-TEE shared-memory allocation was tested. The OP-TEE local check 
stats the driver registered at startup; the shared-memory initializer is 
reviewed and compiled, not exercised through a TEE service.
   
   | Configuration | Before | After |
   |---|---|---|
   | 64-bit, attributes off | 202 checks / 33 failures | 202 checks / 0 
failures |
   | 32-bit, attributes off | 202 checks / 33 failures | 202 checks / 0 
failures |
   | 64-bit, attributes on | 202 checks / 4 failures | 202 checks / 0 failures |
   | Permissions on, pseudo-files disabled | 186 checks / 4 failures | 186 
checks / 0 failures |
   | OP-TEE registered device metadata | 3 checks / 1 failures | 3 checks / 0 
failures |
   | Cryptodev descriptors, 64-bit attributes off | 20 checks / 0 failures | 20 
checks / 0 failures |
   | Cryptodev descriptors, 32-bit attributes off | 20 checks / 0 failures | 20 
checks / 0 failures |
   | Cryptodev descriptors, attributes on | 20 checks / 3 failures | 20 checks 
/ 0 failures |
   | PseudoFS operations disabled | Not repeated | 118 checks / 0 failures |
   | Inotify injection enabled | Not repeated | 33 checks / 0 failures |
   
   All source/branch pairs use identical enabled configuration values. The 
saved configurations confirm the requested attribute, permission and 
notification-injection settings. No compiler warnings in the final functional 
builds.
   
   Default-small, attributes-off simulator image size (text/data/bss): (550589, 
2672, 12992) -> (550597, 2672, 13024), delta (8, 0, 32) bytes. This image 
measurement is separate from the per-inode heap/layout cost above. The 
optimized size builds both emit the same existing apps readline savednch 
warning; it is outside the changed files.
   
   Protected ARM (OP-TEE local backend) and kernel ARM64 (OP-TEE SMC backend) 
builds include the changed static descriptors; no target execution was 
performed. An additional ARMv7-R SMC build failed with unresolved arm_smccc_smc 
on original baseline 4fbd48185326 and the pre-rebase candidate; the affected 
SMC files are unchanged in the refreshed baseline and that unsupported 
combination is not counted as a passing build. Make, CMake, OSTest, full-file 
checkpatch, commit checks and the current HEAD gate pass.
   
   <details>
   <summary>Actual functional logs (before and after)</summary>
   
   `baseline-all`
   ```text
   Error mount tmpfs '' on '/tmp' failed: 20
   nsh> inodemodecheck
   MODECHECK layout bits=64 inode=72 name_offset=64
   MODE /mode-ioctl actual=0000 expected=0640
   FAIL stat mode errno=0
   FD MODE actual=0000 expected=0640
   FAIL fstat mode errno=0
   FD MODE actual=0000 expected=0460
   FAIL fstat mode errno=25
   MODE /mode-ioctl actual=0000 expected=0460
   FAIL stat mode errno=25
   FD MODE actual=0000 expected=0641
   FAIL fstat mode errno=25
   MODE /mode-moved actual=0000 expected=0641
   FAIL stat mode errno=25
   MODE /mode-read actual=0444 expected=0440
   FAIL stat mode errno=25
   FD MODE actual=0444 expected=0440
   FAIL fstat mode errno=25
   FD MODE actual=0444 expected=0460
   FAIL fstat mode errno=25
   MODE /mode-read actual=0444 expected=0460
   FAIL stat mode errno=25
   FD MODE actual=0444 expected=0641
   FAIL fstat mode errno=25
   MODE /mode-moved actual=0444 expected=0641
   FAIL stat mode errno=25
   MODE /mode-write actual=0222 expected=0220
   FAIL stat mode errno=25
   FD MODE actual=0222 expected=0220
   FAIL fstat mode errno=25
   FD MODE actual=0222 expected=0460
   FAIL fstat mode errno=25
   MODE /mode-write actual=0222 expected=0460
   FAIL stat mode errno=25
   FD MODE actual=0222 expected=0641
   FAIL fstat mode errno=25
   MODE /mode-moved actual=0222 expected=0641
   FAIL stat mode errno=25
   MODE /mode-block actual=0666 expected=0640
   FAIL stat mode errno=25
   MODE /mode-mtd actual=0666 expected=0440
   FAIL stat mode errno=25
   MODE /mode-dir actual=0555 expected=0750
   FAIL stat mode errno=25
   MODE /mode-renamed actual=0555 expected=0710
   FAIL stat mode errno=25
   MODE /mode-file actual=0777 expected=0640
   FAIL stat mode errno=25
   FD MODE actual=0777 expected=0640
   FAIL fstat mode errno=25
   FAIL non-executable pseudo file errno=25
   FD MODE actual=0777 expected=0750
   FAIL fstat mode errno=25
   MODE /mode-fifo actual=0777 expected=0620
   FAIL stat mode errno=25
   MODE /mode-fifo actual=0777 expected=0600
   FAIL stat mode errno=25
   MODE /mode-soft actual=0000 expected=0640
   FAIL stat mode errno=25
   FAIL lstat changed symlink errno=25
   MODE /mode-target actual=0000 expected=0640
   FAIL stat mode errno=25
   MODE /mode-hard actual=0000 expected=0640
   FAIL stat mode errno=25
   MODE /mode-target actual=0000 expected=0660
   FAIL stat mode errno=25
   MODECHECK RESULT checks=169 failures=33
   nsh> inodemodecheck anon
   MODECHECK layout bits=64 inode=72 name_offset=64
   MODECHECK ANON checks=202 failures=33
   nsh> poweroff
   ```
   
   `final-all`
   ```text
   Error mount tmpfs '' on '/tmp' failed: 20
   nsh> inodemodecheck
   MODECHECK layout bits=64 inode=80 name_offset=72
   MODECHECK RESULT checks=169 failures=0
   nsh> inodemodecheck anon
   MODECHECK layout bits=64 inode=80 name_offset=72
   MODECHECK ANON checks=202 failures=0
   nsh> poweroff
   ```
   
   `baseline32-all`
   ```text
   Error mount tmpfs '' on '/tmp' failed: 20
   nsh> inodemodecheck
   MODECHECK layout bits=32 inode=40 name_offset=36
   MODE /mode-ioctl actual=0000 expected=0640
   FAIL stat mode errno=0
   FD MODE actual=0000 expected=0640
   FAIL fstat mode errno=0
   FD MODE actual=0000 expected=0460
   FAIL fstat mode errno=25
   MODE /mode-ioctl actual=0000 expected=0460
   FAIL stat mode errno=25
   FD MODE actual=0000 expected=0641
   FAIL fstat mode errno=25
   MODE /mode-moved actual=0000 expected=0641
   FAIL stat mode errno=25
   MODE /mode-read actual=0444 expected=0440
   FAIL stat mode errno=25
   FD MODE actual=0444 expected=0440
   FAIL fstat mode errno=25
   FD MODE actual=0444 expected=0460
   FAIL fstat mode errno=25
   MODE /mode-read actual=0444 expected=0460
   FAIL stat mode errno=25
   FD MODE actual=0444 expected=0641
   FAIL fstat mode errno=25
   MODE /mode-moved actual=0444 expected=0641
   FAIL stat mode errno=25
   MODE /mode-write actual=0222 expected=0220
   FAIL stat mode errno=25
   FD MODE actual=0222 expected=0220
   FAIL fstat mode errno=25
   FD MODE actual=0222 expected=0460
   FAIL fstat mode errno=25
   MODE /mode-write actual=0222 expected=0460
   FAIL stat mode errno=25
   FD MODE actual=0222 expected=0641
   FAIL fstat mode errno=25
   MODE /mode-moved actual=0222 expected=0641
   FAIL stat mode errno=25
   MODE /mode-block actual=0666 expected=0640
   FAIL stat mode errno=25
   MODE /mode-mtd actual=0666 expected=0440
   FAIL stat mode errno=25
   MODE /mode-dir actual=0555 expected=0750
   FAIL stat mode errno=25
   MODE /mode-renamed actual=0555 expected=0710
   FAIL stat mode errno=25
   MODE /mode-file actual=0777 expected=0640
   FAIL stat mode errno=25
   FD MODE actual=0777 expected=0640
   FAIL fstat mode errno=25
   FAIL non-executable pseudo file errno=25
   FD MODE actual=0777 expected=0750
   FAIL fstat mode errno=25
   MODE /mode-fifo actual=0777 expected=0620
   FAIL stat mode errno=25
   MODE /mode-fifo actual=0777 expected=0600
   FAIL stat mode errno=25
   MODE /mode-soft actual=0000 expected=0640
   FAIL stat mode errno=25
   FAIL lstat changed symlink errno=25
   MODE /mode-target actual=0000 expected=0640
   FAIL stat mode errno=25
   MODE /mode-hard actual=0000 expected=0640
   FAIL stat mode errno=25
   MODE /mode-target actual=0000 expected=0660
   FAIL stat mode errno=25
   MODECHECK RESULT checks=169 failures=33
   nsh> inodemodecheck anon
   MODECHECK layout bits=32 inode=40 name_offset=36
   MODECHECK ANON checks=202 failures=33
   nsh> poweroff
   ```
   
   `final32-all`
   ```text
   Error mount tmpfs '' on '/tmp' failed: 20
   nsh> inodemodecheck
   MODECHECK layout bits=32 inode=44 name_offset=40
   MODECHECK RESULT checks=169 failures=0
   nsh> inodemodecheck anon
   MODECHECK layout bits=32 inode=44 name_offset=40
   MODECHECK ANON checks=202 failures=0
   nsh> poweroff
   ```
   
   `baseline-attrs-all`
   ```text
   Error mount tmpfs '' on '/tmp' failed: 20
   nsh> inodemodecheck
   MODECHECK layout bits=64 inode=136 name_offset=128
   MODECHECK RESULT checks=169 failures=0
   nsh> inodemodecheck anon
   MODECHECK layout bits=64 inode=136 name_offset=128
   FD MODE actual=0000 expected=0666
   FAIL fstat mode errno=0
   FD MODE actual=0000 expected=0444
   FAIL fstat mode errno=0
   FD MODE actual=0000 expected=0444
   FAIL fstat mode errno=0
   FD MODE actual=0000 expected=0444
   FAIL fstat mode errno=11
   MODECHECK ANON checks=202 failures=4
   nsh> poweroff
   ```
   
   `final-attrs-all`
   ```text
   Error mount tmpfs '' on '/tmp' failed: 20
   nsh> inodemodecheck
   MODECHECK layout bits=64 inode=136 name_offset=128
   MODECHECK RESULT checks=169 failures=0
   nsh> inodemodecheck anon
   MODECHECK layout bits=64 inode=136 name_offset=128
   MODECHECK ANON checks=202 failures=0
   nsh> poweroff
   ```
   
   `baseline-permission-limited`
   ```text
   Error mount tmpfs '' on '/tmp' failed: 20
   nsh> inodemodecheck
   MODECHECK layout bits=64 inode=136 name_offset=128
   MODECHECK RESULT checks=153 failures=0
   nsh> inodemodecheck anon
   MODECHECK layout bits=64 inode=136 name_offset=128
   FD MODE actual=0000 expected=0666
   FAIL fstat mode errno=0
   FD MODE actual=0000 expected=0444
   FAIL fstat mode errno=0
   FD MODE actual=0000 expected=0444
   FAIL fstat mode errno=0
   FD MODE actual=0000 expected=0444
   FAIL fstat mode errno=11
   MODECHECK ANON checks=186 failures=4
   nsh> poweroff
   ```
   
   `final-permission-limited`
   ```text
   Error mount tmpfs '' on '/tmp' failed: 20
   nsh> inodemodecheck
   MODECHECK layout bits=64 inode=136 name_offset=128
   MODECHECK RESULT checks=153 failures=0
   nsh> inodemodecheck anon
   MODECHECK layout bits=64 inode=136 name_offset=128
   MODECHECK ANON checks=186 failures=0
   nsh> poweroff
   ```
   
   `baseline-optee`
   ```text
   nsh> inodemodecheck optee
   MODECHECK layout bits=64 inode=72 name_offset=64
   MODE /dev/tee0 actual=0000 expected=0600
   FAIL stat mode errno=0
   MODECHECK OPTEE checks=3 failures=1
   nsh> poweroff
   ```
   
   `final-optee`
   ```text
   nsh> inodemodecheck optee
   MODECHECK layout bits=64 inode=80 name_offset=72
   MODECHECK OPTEE checks=3 failures=0
   nsh> poweroff
   ```
   
   `baseline-crypto`
   ```text
   nsh> inodemodecheck crypto
   MODECHECK layout bits=64 inode=72 name_offset=64
   MODECHECK CRYPTO checks=20 failures=0
   nsh> poweroff
   ```
   
   `final-crypto`
   ```text
   nsh> inodemodecheck crypto
   MODECHECK layout bits=64 inode=80 name_offset=72
   MODECHECK CRYPTO checks=20 failures=0
   nsh> poweroff
   ```
   
   `baseline-crypto32`
   ```text
   nsh> inodemodecheck crypto
   MODECHECK layout bits=32 inode=40 name_offset=36
   MODECHECK CRYPTO checks=20 failures=0
   nsh> poweroff
   ```
   
   `final-crypto32`
   ```text
   nsh> inodemodecheck crypto
   MODECHECK layout bits=32 inode=44 name_offset=40
   MODECHECK CRYPTO checks=20 failures=0
   nsh> poweroff
   ```
   
   `baseline-crypto-attrs`
   ```text
   nsh> inodemodecheck crypto
   MODECHECK layout bits=64 inode=136 name_offset=128
   FD MODE actual=0000 expected=0666
   FAIL fstat mode errno=0
   FD MODE actual=0000 expected=0666
   FAIL fstat mode errno=0
   FD MODE actual=0000 expected=0666
   FAIL fstat mode errno=0
   MODECHECK CRYPTO checks=20 failures=3
   nsh> poweroff
   ```
   
   `final-crypto-attrs`
   ```text
   nsh> inodemodecheck crypto
   MODECHECK layout bits=64 inode=136 name_offset=128
   MODECHECK CRYPTO checks=20 failures=0
   nsh> poweroff
   ```
   
   </details>
   
   <details>
   <summary>Final local build gate</summary>
   
   ```text
   target   : nuttx
   branch   : fs/inode-mode
   head     : 8ab9318affc0d4ef375fd9418941e5c8634a4e92
   subject  : fs/inode: always define i_mode
   commits  : 1
   base     : f7a8e713cc (merge-base with upstream/master)
   behind   : 5 commits of upstream/master
   nuttx    : 8ab9318aff
   apps     : 0a37af9866
   options  : CONFIG_PSEUDOFS_FILE CONFIG_FS_LINKS CONFIG_MTD CONFIG_FS_TMPFS 
CONFIG_DEBUG_ASSERTIONS CONFIG_EVENT_FD CONFIG_TIMER_FD CONFIG_SIGNAL_FD 
CONFIG_FS_NOTIFY CONFIG_NET CONFIG_NET_LOCAL CONFIG_FS_ANONMAP CONFIG_FS_SHMFS 
CONFIG_ALLOW_BSD_COMPONENTS CONFIG_DEV_OPTEE_LOCAL CONFIG_CRYPTO 
CONFIG_CRYPTO_CRYPTODEV
   host     : Linux x86_64, gcc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0
   checkpatch: rc=0
   signer   : jingfei <[email protected]>
   commits missing your Signed-off-by: 0
   make build: rc=0
   warnings in changed files: 0
   ostest: Exiting with status 0
   cmake reconfigure: rc=0
   cmake build: rc=0
   worktree tracked changes after: 0
   RESULT: PASS
   ```
   </details>
   
   <details>
   <summary>Local functional fixture and commands</summary>
   
   The fixture is local validation input; it is not added to nuttx-apps by this 
PR.
   
   ```c
   /****************************************************************************
    * apps/examples/inodemodecheck/inodemodecheck_main.c
    *
    * SPDX-License-Identifier: Apache-2.0
    *
    * 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
    *
    *   http://www.apache.org/licenses/LICENSE-2.0
    *
    * 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.
    *
    
****************************************************************************/
   
   /****************************************************************************
    * Included Files
    
****************************************************************************/
   
   #include <nuttx/config.h>
   #ifdef CONFIG_CRYPTO_CRYPTODEV
   #  include <crypto/cryptodev.h>
   #endif
   #include <sys/stat.h>
   #include <sys/ioctl.h>
   #include <sys/mount.h>
   #include <sys/epoll.h>
   #ifdef CONFIG_EVENT_FD
   #  include <sys/eventfd.h>
   #endif
   #ifdef CONFIG_TIMER_FD
   #  include <sys/timerfd.h>
   #endif
   #ifdef CONFIG_SIGNAL_FD
   #  include <sys/signalfd.h>
   #endif
   #ifdef CONFIG_FS_NOTIFY
   #  include <sys/inotify.h>
   #endif
   #include <errno.h>
   #include <fcntl.h>
   #include <stddef.h>
   #include <stdio.h>
   #include <string.h>
   #include <unistd.h>
   
   #include <nuttx/fs/fs.h>
   #include <nuttx/fs/ioctl.h>
   #include <nuttx/mtd/mtd.h>
   
   /****************************************************************************
    * Private Data
    
****************************************************************************/
   
   static int g_checks;
   static int g_failures;
   
   /****************************************************************************
    * Private Functions
    
****************************************************************************/
   
   static void check(int condition, FAR const char *label)
   {
     g_checks++;
     if (!condition)
       {
         g_failures++;
         printf("FAIL %s errno=%d\n", label, errno);
       }
   }
   
   static int ioctl_only(FAR struct file *filep, int cmd, unsigned long arg)
   {
     return -ENOTTY;
   }
   
   static ssize_t read_only(FAR struct file *filep, FAR char *buf, size_t len)
   {
     if (len > 0)
       {
         buf[0] = 'r';
         return 1;
       }
   
     return 0;
   }
   
   static ssize_t write_only(FAR struct file *filep, FAR const char *buf,
                             size_t len)
   {
     return len;
   }
   
   static const struct file_operations g_ioctl_ops =
   {
     .ioctl = ioctl_only
   };
   
   static const struct file_operations g_read_ops =
   {
     .read = read_only
   };
   
   static const struct file_operations g_write_ops =
   {
     .write = write_only
   };
   
   static void pathmode(FAR const char *path, mode_t type, mode_t mode)
   {
     struct stat st;
     int ret;
   
     memset(&st, 0, sizeof(st));
     ret = stat(path, &st);
     check(ret == 0, "stat status");
     if (ret == 0)
       {
         check((st.st_mode & S_IFMT) == type, "stat type");
         if ((st.st_mode & 07777) != mode)
           {
             printf("MODE %s actual=%04o expected=%04o\n", path,
                    (unsigned int)(st.st_mode & 07777), (unsigned int)mode);
           }
   
         check((st.st_mode & 07777) == mode, "stat mode");
       }
   }
   
   static void fdmode(int fd, mode_t type, mode_t mode)
   {
     struct stat st;
     int ret;
   
     memset(&st, 0, sizeof(st));
     ret = fstat(fd, &st);
     check(ret == 0, "fstat status");
     if (ret == 0)
       {
         check((st.st_mode & S_IFMT) == type, "fstat type");
         if ((st.st_mode & 07777) != mode)
           {
             printf("FD MODE actual=%04o expected=%04o\n",
                    (unsigned int)(st.st_mode & 07777), (unsigned int)mode);
           }
   
         check((st.st_mode & 07777) == mode, "fstat mode");
       }
   }
   
   static void anonymous_modes(void)
   {
     struct epoll_event ev;
   #ifdef CONFIG_EVENT_FD
     eventfd_t value = 0;
   #endif
   #ifdef CONFIG_TIMER_FD
     struct itimerspec timer;
   #endif
   #ifdef CONFIG_SIGNAL_FD
     sigset_t mask;
     struct signalfd_siginfo info;
   #endif
   #ifdef CONFIG_FS_NOTIFY
     char events[128];
   #endif
     int fd;
   
   #ifdef CONFIG_EVENT_FD
     fd = eventfd(3, EFD_NONBLOCK);
     check(fd >= 0, "eventfd create");
     if (fd >= 0)
       {
         fdmode(fd, S_IFCHR, 0666);
         check(eventfd_read(fd, &value) == 0 && value == 3, "eventfd read");
         check(eventfd_write(fd, 2) == 0, "eventfd write");
         check(eventfd_read(fd, &value) == 0 && value == 2,
               "eventfd read written value");
         check(close(fd) == 0, "eventfd close");
       }
   #endif
   
   #ifdef CONFIG_TIMER_FD
     fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK);
     check(fd >= 0, "timerfd create");
     if (fd >= 0)
       {
         fdmode(fd, S_IFCHR, 0444);
         check(timerfd_gettime(fd, &timer) == 0, "timerfd gettime");
         check(timer.it_value.tv_sec == 0 && timer.it_value.tv_nsec == 0,
               "timerfd initially disarmed");
         check(close(fd) == 0, "timerfd close");
       }
   #endif
   
   #ifdef CONFIG_SIGNAL_FD
     sigemptyset(&mask);
     fd = signalfd(-1, &mask, SFD_NONBLOCK);
     check(fd >= 0, "signalfd create");
     if (fd >= 0)
       {
         fdmode(fd, S_IFCHR, 0444);
         check(read(fd, &info, sizeof(info)) == -1 && errno == EAGAIN,
               "signalfd empty read");
         check(close(fd) == 0, "signalfd close");
       }
   #endif
   
   #ifdef CONFIG_FS_NOTIFY
     fd = inotify_init1(IN_NONBLOCK);
     check(fd >= 0, "inotify create");
     if (fd >= 0)
       {
   #ifdef CONFIG_FS_NOTIFY_INJECT
         fdmode(fd, S_IFCHR, 0666);
   #else
         fdmode(fd, S_IFCHR, 0444);
   #endif
         check(read(fd, events, sizeof(events)) == -1 && errno == EAGAIN,
               "inotify empty read");
         check(close(fd) == 0, "inotify close");
       }
   #endif
   
     fd = epoll_create1(0);
     check(fd >= 0, "epoll create");
     if (fd >= 0)
       {
         fdmode(fd, S_IFCHR, 0);
         check(epoll_wait(fd, &ev, 1, 0) == 0, "epoll empty wait");
         check(close(fd) == 0, "epoll close");
       }
   }
   
   #ifdef CONFIG_CRYPTO_CRYPTODEV
   static void crypto_modes(void)
   {
     int parent;
     int child = -1;
     int cloned = -1;
     int copied;
   
     parent = open("/dev/crypto", O_RDWR);
     check(parent >= 0, "crypto device open");
     if (parent < 0)
       {
         return;
       }
   
     check(ioctl(parent, CRIOGET, &child) == 0, "crypto descriptor create");
     check(child >= 0, "crypto descriptor returned");
     if (child >= 0)
       {
         fdmode(child, S_IFCHR, 0666);
         check((fcntl(child, F_GETFL) & O_ACCMODE) == O_RDONLY,
               "crypto descriptor flags unchanged");
         copied = dup(child);
         check(copied >= 0, "crypto dup");
         if (copied >= 0)
           {
             fdmode(copied, S_IFCHR, 0666);
             check(close(copied) == 0, "crypto dup close");
           }
   
         check(ioctl(child, CIOCCLONE, &cloned) == 0, "crypto empty clone");
         check(cloned >= 0, "crypto clone returned");
         if (cloned >= 0)
           {
             fdmode(cloned, S_IFCHR, 0666);
             check(close(cloned) == 0, "crypto clone close");
           }
   
         check(close(child) == 0, "crypto descriptor close");
       }
   
     check(close(parent) == 0, "crypto device close");
   }
   #endif
   
   static void device(FAR const char *path,
                      FAR const struct file_operations *ops,
                      mode_t mode, int oflags)
   {
     char byte = 'w';
     int fd;
   
     check(register_driver(path, ops, mode, NULL) == 0, "register char");
     pathmode(path, S_IFCHR, mode);
     fd = open(path, oflags);
     check(fd >= 0, "open char");
     if (fd >= 0)
       {
         fdmode(fd, S_IFCHR, mode);
         if (ops == &g_read_ops)
           {
             check(read(fd, &byte, 1) == 1 && byte == 'r', "driver read");
           }
         else if (ops == &g_write_ops)
           {
             check(write(fd, &byte, 1) == 1, "driver write");
           }
         else
           {
             check(ioctl(fd, FIONREAD, &byte) == -1 && errno == ENOTTY,
                   "driver ioctl");
           }
   
         check(fchmod(fd, 0460) == 0, "fchmod char");
         fdmode(fd, S_IFCHR, 0460);
         pathmode(path, S_IFCHR, 0460);
         check(chmod(path, 0641) == 0, "chmod char");
         fdmode(fd, S_IFCHR, 0641);
         check(close(fd) == 0, "close char");
       }
   
   #ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
     check(rename(path, "/mode-moved") == 0, "rename char");
     pathmode("/mode-moved", S_IFCHR, 0641);
     check(unregister_driver("/mode-moved") == 0, "unregister moved char");
   #else
     check(unregister_driver(path) == 0, "unregister char");
   #endif
   }
   
   #ifdef CONFIG_FS_BLOCK_DRIVER
   static int geometry(FAR struct inode *inode, FAR struct geometry *geo)
   {
     memset(geo, 0, sizeof(*geo));
     geo->geo_available = true;
     geo->geo_sectorsize = 128;
     geo->geo_nsectors = 4;
     return 0;
   }
   
   static const struct block_operations g_block_ops =
   {
     .geometry = geometry
   };
   #endif
   
   #ifdef CONFIG_MTD
   static int mtd_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg)
   {
     FAR struct mtd_geometry_s *geo = (FAR struct mtd_geometry_s *)arg;
   
     if (cmd != MTDIOC_GEOMETRY)
       {
         return -ENOTTY;
       }
   
     memset(geo, 0, sizeof(*geo));
     geo->blocksize = 128;
     geo->erasesize = 512;
     geo->neraseblocks = 4;
     return 0;
   }
   
   static struct mtd_dev_s g_mtd =
   {
     .ioctl = mtd_ioctl
   };
   #endif
   
   #ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
   static void namespace_modes(void)
   {
     struct stat st;
     int fd;
   
     check(mkdir("/mode-dir", 0750) == 0, "mkdir");
     pathmode("/mode-dir", S_IFDIR, 0750);
     check(chmod("/mode-dir", 0710) == 0, "chmod directory");
     check(rename("/mode-dir", "/mode-renamed") == 0, "rename directory");
     pathmode("/mode-renamed", S_IFDIR, 0710);
     check(rmdir("/mode-renamed") == 0, "rmdir");
   
   #ifdef CONFIG_PSEUDOFS_FILE
     fd = open("/mode-file", O_CREAT | O_RDWR, 0640);
     check(fd >= 0, "create pseudo file");
     if (fd >= 0)
       {
         pathmode("/mode-file", S_IFREG, 0640);
         fdmode(fd, S_IFREG, 0640);
         check(access("/mode-file", X_OK) == -1 && errno == EACCES,
               "non-executable pseudo file");
         check(fchmod(fd, 0750) == 0, "set execute mode");
         check(access("/mode-file", X_OK) == 0, "executable pseudo file");
         fdmode(fd, S_IFREG, 0750);
         check(close(fd) == 0, "close pseudo file");
         check(unlink("/mode-file") == 0, "unlink pseudo file");
       }
   #endif
   
   #ifdef CONFIG_PIPES
     check(mkfifo("/mode-fifo", 0620) == 0, "create fifo");
     pathmode("/mode-fifo", S_IFIFO, 0620);
     check(chmod("/mode-fifo", 0600) == 0, "chmod fifo");
     pathmode("/mode-fifo", S_IFIFO, 0600);
     check(unlink("/mode-fifo") == 0, "unlink fifo");
   #endif
   
   #ifdef CONFIG_FS_LINKS
     check(register_driver("/mode-target", &g_ioctl_ops, 0640, NULL) == 0,
           "link target");
     check(symlink("/mode-target", "/mode-soft") == 0, "symlink");
     pathmode("/mode-soft", S_IFCHR, 0640);
     check(lstat("/mode-soft", &st) == 0 && S_ISLNK(st.st_mode) &&
           (st.st_mode & 07777) == 0777, "lstat symlink");
     check(lchmod("/mode-soft", 0700) == 0, "lchmod symlink");
     check(lstat("/mode-soft", &st) == 0 && S_ISLNK(st.st_mode) &&
           (st.st_mode & 07777) == 0700, "lstat changed symlink");
     pathmode("/mode-target", S_IFCHR, 0640);
     check(link("/mode-target", "/mode-hard") == 0, "hard link");
     pathmode("/mode-hard", S_IFCHR, 0640);
     check(chmod("/mode-hard", 0660) == 0, "chmod hard link");
     pathmode("/mode-target", S_IFCHR, 0660);
     check(unlink("/mode-hard") == 0, "unlink hard link");
     check(unlink("/mode-soft") == 0, "unlink soft link");
     check(unregister_driver("/mode-target") == 0, "unlink target");
   #endif
   
   #ifdef CONFIG_FS_TMPFS
     check(mount(NULL, "/mode-volume", "tmpfs", 0, NULL) == 0, "mount tmpfs");
     fd = open("/mode-volume/file", O_CREAT | O_RDWR, 0640);
     check(fd >= 0, "create mounted file");
     if (fd >= 0)
       {
   #ifdef CONFIG_FS_PERMISSION
         pathmode("/mode-volume/file", S_IFREG, 0640);
         fdmode(fd, S_IFREG, 0640);
   #else
         pathmode("/mode-volume/file", S_IFREG, 0777);
         fdmode(fd, S_IFREG, 0777);
   #endif
         check(fchmod(fd, 0600) == 0, "chmod mounted file");
   #ifdef CONFIG_FS_PERMISSION
         fdmode(fd, S_IFREG, 0600);
   #else
         fdmode(fd, S_IFREG, 0777);
   #endif
         check(close(fd) == 0, "close mounted file");
       }
   
     check(unlink("/mode-volume/file") == 0, "unlink mounted file");
     check(umount("/mode-volume") == 0, "umount tmpfs");
     check(stat("/mode-volume", &st) == -1 && errno == ENOENT,
           "mount node removed");
   #endif
   }
   #endif
   
   /****************************************************************************
    * Public Functions
    
****************************************************************************/
   
   int main(int argc, FAR char *argv[])
   {
     struct stat st;
     mode_t saved = umask(0);
     int fd;
   
     printf("MODECHECK layout bits=%zu inode=%zu name_offset=%zu\n",
            sizeof(void *) * 8, sizeof(struct inode),
            offsetof(struct inode, i_name));
     if (argc > 1 && strcmp(argv[1], "anon") == 0)
       {
         anonymous_modes();
         umask(saved);
         printf("MODECHECK ANON checks=%d failures=%d\n", g_checks, g_failures);
         return g_failures != 0;
       }
   
   #ifdef CONFIG_CRYPTO_CRYPTODEV
     if (argc > 1 && strcmp(argv[1], "crypto") == 0)
       {
         crypto_modes();
         umask(saved);
         printf("MODECHECK CRYPTO checks=%d failures=%d\n",
                g_checks, g_failures);
         return g_failures != 0;
       }
   #endif
   
   #ifdef CONFIG_DEV_OPTEE_LOCAL
     if (argc > 1 && strcmp(argv[1], "optee") == 0)
       {
         pathmode("/dev/tee0", S_IFCHR, 0600);
         umask(saved);
         printf("MODECHECK OPTEE checks=%d failures=%d\n",
                g_checks, g_failures);
         return g_failures != 0;
       }
   #endif
   
     device("/mode-ioctl", &g_ioctl_ops, 0640, O_RDWR);
     device("/mode-read", &g_read_ops, 0440, O_RDONLY);
     device("/mode-write", &g_write_ops, 0220, O_WRONLY);
     check(register_driver("/mode-zero", &g_ioctl_ops, 0, NULL) == 0,
           "register zero-mode device");
     pathmode("/mode-zero", S_IFCHR, 0);
     fd = open("/mode-zero", O_RDWR);
   #ifdef CONFIG_FS_PERMISSION
     check(fd < 0 && errno == EACCES, "permission enforcement unchanged");
   #else
     check(fd >= 0, "disabled permission enforcement unchanged");
   #endif
     if (fd >= 0)
       {
         check(close(fd) == 0, "close zero-mode device");
       }
   
     check(unregister_driver("/mode-zero") == 0, "unregister zero-mode device");
   
   #ifdef CONFIG_FS_BLOCK_DRIVER
     check(register_blockdriver("/mode-block", &g_block_ops, 0640, NULL) == 0,
           "register block");
     pathmode("/mode-block", S_IFBLK, 0640);
     check(stat("/mode-block", &st) == 0 && st.st_size == 512,
           "block geometry unchanged");
     check(unregister_blockdriver("/mode-block") == 0, "unregister block");
   #endif
   #ifdef CONFIG_MTD
     check(register_mtddriver("/mode-mtd", &g_mtd, 0440, NULL) == 0,
           "register mtd");
     pathmode("/mode-mtd", S_IFMTD, 0440);
     check(stat("/mode-mtd", &st) == 0 && st.st_size == 2048,
           "mtd geometry unchanged");
     check(unregister_mtddriver("/mode-mtd") == 0, "unregister mtd");
   #endif
   #ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
     namespace_modes();
   #endif
     umask(saved);
     printf("MODECHECK RESULT checks=%d failures=%d\n", g_checks, g_failures);
     return g_failures != 0;
   }
   ```
   
   ```sh
   #!/bin/bash
   set -euo pipefail
   cd /home/mi/test/nuttx_apache/fs-upstream
   
runner=/home/mi/dev-system_car/nuttx/.claude/kernel/skills/fs-community-sync/scripts/func-test.sh
   base=f7a8e713ccf277a36f37652b5e769af8a27d21e1
   common=(CONFIG_EXAMPLES_INODEMODECHECK CONFIG_MTD CONFIG_FS_TMPFS 
CONFIG_PSEUDOFS_FILE CONFIG_PSEUDOFS_FILE_READONLY=n CONFIG_FS_LINKS 
CONFIG_DEBUG_ASSERTIONS)
   anon=(CONFIG_EVENT_FD CONFIG_TIMER_FD CONFIG_SIGNAL_FD CONFIG_FS_NOTIFY)
   for mode in ${MODECHECK_MODES:-final-attrs-all baseline-permission-limited 
final-permission-limited final-static final-inject final-optee}; do
     rev=fs/inode-mode
     opts=("${common[@]}" "${anon[@]}" CONFIG_PSEUDOFS_ATTRIBUTES=n)
     script=pr-inode-mode/run-all.nsh
     if [[ "$mode" == baseline* ]]; then rev=$base; fi
     if [[ "$mode" == *32* ]]; then opts+=(CONFIG_SIM_M32); fi
     if [[ "$mode" == *attrs* ]]; then opts=("${common[@]}" "${anon[@]}" 
CONFIG_PSEUDOFS_ATTRIBUTES); fi
     if [[ "$mode" == *permission* ]]; then
       opts=(CONFIG_EXAMPLES_INODEMODECHECK CONFIG_MTD CONFIG_FS_TMPFS 
CONFIG_FS_LINKS CONFIG_DEBUG_ASSERTIONS "${anon[@]}" CONFIG_PSEUDOFS_FILE=n 
CONFIG_PSEUDOFS_ATTRIBUTES CONFIG_SCHED_USER_IDENTITY CONFIG_FS_PERMISSION)
     fi
     if [[ "$mode" == final-static ]]; then
       opts=(CONFIG_EXAMPLES_INODEMODECHECK CONFIG_MTD CONFIG_DEBUG_ASSERTIONS 
"${anon[@]}" CONFIG_DISABLE_PSEUDOFS_OPERATIONS CONFIG_PSEUDOFS_ATTRIBUTES=n)
     fi
     if [[ "$mode" == final-inject ]]; then
       opts+=(CONFIG_NET CONFIG_NET_IPv4 CONFIG_NET_UDP CONFIG_NET_LOOPBACK 
CONFIG_FS_USERFS)
       script=pr-inode-mode/run-anon.nsh
     fi
     if [[ "$mode" == *optee ]]; then
       opts=(CONFIG_EXAMPLES_INODEMODECHECK CONFIG_MTD CONFIG_NET 
CONFIG_NET_LOCAL CONFIG_FS_ANONMAP CONFIG_ALLOW_BSD_COMPONENTS 
CONFIG_DEV_OPTEE_LOCAL CONFIG_FS_SHMFS CONFIG_PSEUDOFS_ATTRIBUTES=n)
       script=pr-inode-mode/run-optee.nsh
     fi
     taskset -c 0,1 "$runner" "$rev" "pr-inode-mode/$mode" "$script" 
"${opts[@]}" > "pr-inode-mode/$mode-driver.log" 2>&1
     grep -q 'build rc=0' "pr-inode-mode/$mode-driver.log"
     grep -q 'run rc=0 ' "pr-inode-mode/$mode-driver.log"
     if grep -q '^WARNING:' "pr-inode-mode/$mode-driver.log"; then exit 1; fi
     grep 'MODECHECK' "pr-inode-mode/$mode/run.log"
     if [[ "$mode" == final* ]]; then
       if grep -q '^FAIL ' "pr-inode-mode/$mode/run.log"; then exit 1; fi
       grep -q 'checks=.* failures=0' "pr-inode-mode/$mode/run.log"
     fi
     if [[ "$mode" == final-inject ]]; then
       grep -qx 'CONFIG_FS_NOTIFY_INJECT=y' "pr-inode-mode/$mode/config"
     fi
   done
   ```
   
   ```sh
   #!/bin/bash
   set -euo pipefail
   cd /home/mi/test/nuttx_apache/fs-upstream
   
runner=/home/mi/dev-system_car/nuttx/.claude/kernel/skills/fs-community-sync/scripts/func-test.sh
   base=f7a8e713ccf277a36f37652b5e769af8a27d21e1
   for variant in final-crypto baseline-crypto32 final-crypto32 
baseline-crypto-attrs final-crypto-attrs; do
     rev=fs/inode-mode
     attrs=CONFIG_PSEUDOFS_ATTRIBUTES=n
     if [[ "$variant" == baseline* ]]; then rev=$base; fi
     if [[ "$variant" == *attrs ]]; then attrs=CONFIG_PSEUDOFS_ATTRIBUTES; fi
     opts=(CONFIG_EXAMPLES_INODEMODECHECK CONFIG_ALLOW_BSD_COMPONENTS 
CONFIG_CRYPTO CONFIG_CRYPTO_CRYPTODEV "$attrs")
     if [[ "$variant" == *32 ]]; then opts+=(CONFIG_SIM_M32); fi
     taskset -c 0,1 "$runner" "$rev" "pr-inode-mode/$variant" 
pr-inode-mode/run-crypto.nsh "${opts[@]}" > "pr-inode-mode/$variant-driver.log" 
2>&1
     grep -q 'build rc=0' "pr-inode-mode/$variant-driver.log"
     grep -q 'run rc=0 ' "pr-inode-mode/$variant-driver.log"
     ! grep -q '^WARNING:' "pr-inode-mode/$variant-driver.log"
     grep -qx 'CONFIG_CRYPTO_CRYPTODEV=y' "pr-inode-mode/$variant/config"
     if [[ "$variant" == final* ]]; then grep -q 'MODECHECK CRYPTO checks=20 
failures=0' "pr-inode-mode/$variant/run.log"; fi
     cat "pr-inode-mode/$variant/run.log"
   done
   ```
   </details>
   
   `apps/examples/inodemodecheck/Kconfig`
   ```kconfig
   config EXAMPLES_INODEMODECHECK
        tristate "PseudoFS mode regression checks"
        default n
   ```
   
   
   `apps/examples/inodemodecheck/Makefile`
   ```makefile
   include $(APPDIR)/Make.defs
   PROGNAME = inodemodecheck
   PRIORITY = SCHED_PRIORITY_DEFAULT
   STACKSIZE = 8192
   MODULE = $(CONFIG_EXAMPLES_INODEMODECHECK)
   MAINSRC = inodemodecheck_main.c
   include $(APPDIR)/Application.mk
   ```
   
   
   `apps/examples/inodemodecheck/CMakeLists.txt`
   ```cmake
   if(CONFIG_EXAMPLES_INODEMODECHECK)
     nuttx_add_application(NAME inodemodecheck SRCS inodemodecheck_main.c 
STACKSIZE 8192)
   endif()
   ```
   
   
   During validation, upstream master advanced to 
f9d3eb13c3f412426a2658227f2b332e21e3a526. The five added commits concern 
ARM7TDMI/PP502x and the iPod Video board, which are disabled in every saved 
test configuration. The complete patch applies cleanly to that master; the 
tested commit is unchanged. This applicability check is not a build or runtime 
claim for the new board.
   
   
   ## PR verification Self-Check
   
   - [x] This PR introduces only one functional change.
   - [x] I have updated all required description fields above.
   - [x] Commit message, author/sign-off and code style checks pass.
   - [ ] My PR is still work in progress (not ready for review).
   - [x] My PR is ready for review and can be safely merged into a codebase.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

  • [PR] fs/inode: always define ... jingfei195887 (via GitHub) via commits

Reply via email to