This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git


The following commit(s) were added to refs/heads/master by this push:
     new 2234c3a2e nshlib: support list numeric user and group IDs
2234c3a2e is described below

commit 2234c3a2e60677a266bb7ee2a830df3bdeec8f23
Author: fangxinyong <[email protected]>
AuthorDate: Mon Apr 24 11:39:00 2023 +0800

    nshlib: support list numeric user and group IDs
    
    Signed-off-by: fangxinyong <[email protected]>
---
 nshlib/nsh_fscmds.c | 35 +++++++++++++++++++++++++++++++----
 1 file changed, 31 insertions(+), 4 deletions(-)

diff --git a/nshlib/nsh_fscmds.c b/nshlib/nsh_fscmds.c
index 62a202e45..73b9292fa 100644
--- a/nshlib/nsh_fscmds.c
+++ b/nshlib/nsh_fscmds.c
@@ -86,6 +86,7 @@
 #define LSFLAGS_SIZE          1
 #define LSFLAGS_LONG          2
 #define LSFLAGS_RECURSIVE     4
+#define LSFLAGS_UID_GID       8
 #define LSFLAGS_HUMANREADBLE  16
 
 #define KB                   (1UL << 10)
@@ -125,10 +126,12 @@ static int ls_handler(FAR struct nsh_vtbl_s *vtbl, FAR 
const char *dirpath,
 
   /* Check if any options will require that we stat the file */
 
-  if ((lsflags & (LSFLAGS_SIZE | LSFLAGS_LONG)) != 0)
+  if ((lsflags & (LSFLAGS_SIZE | LSFLAGS_LONG | LSFLAGS_UID_GID)) != 0)
     {
       struct stat buf;
 
+      memset(&buf, 0, sizeof(struct stat));
+
       /* stat the file */
 
       if (entryp != NULL)
@@ -219,7 +222,15 @@ static int ls_handler(FAR struct nsh_vtbl_s *vtbl, FAR 
const char *dirpath,
               details[2] = 'w';
             }
 
-          if ((buf.st_mode & S_IXUSR) != 0)
+          if ((buf.st_mode & S_IXUSR) != 0 && (buf.st_mode & S_ISUID) != 0)
+            {
+              details[3] = 's';
+            }
+          else if ((buf.st_mode & S_ISUID) != 0)
+            {
+              details[3] = 'S';
+            }
+          else if ((buf.st_mode & S_IXUSR) != 0)
             {
               details[3] = 'x';
             }
@@ -234,7 +245,15 @@ static int ls_handler(FAR struct nsh_vtbl_s *vtbl, FAR 
const char *dirpath,
               details[5] = 'w';
             }
 
-          if ((buf.st_mode & S_IXGRP) != 0)
+          if ((buf.st_mode & S_IXGRP) != 0 && (buf.st_mode & S_ISGID) != 0)
+            {
+              details[6] = 's';
+            }
+          else if ((buf.st_mode & S_ISGID) != 0)
+            {
+              details[6] = 'S';
+            }
+          else if ((buf.st_mode & S_IXGRP) != 0)
             {
               details[6] = 'x';
             }
@@ -257,6 +276,14 @@ static int ls_handler(FAR struct nsh_vtbl_s *vtbl, FAR 
const char *dirpath,
           nsh_output(vtbl, " %s", details);
         }
 
+#ifdef CONFIG_SCHED_USER_IDENTITY
+      if ((lsflags & LSFLAGS_UID_GID) != 0)
+        {
+          nsh_output(vtbl, "%8d", buf.st_uid);
+          nsh_output(vtbl, "%8d", buf.st_gid);
+        }
+#endif
+
       if ((lsflags & LSFLAGS_SIZE) != 0)
         {
           if (lsflags & LSFLAGS_HUMANREADBLE && buf.st_size >= KB)
@@ -1340,7 +1367,7 @@ int cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, FAR 
char **argv)
       switch (option)
         {
           case 'l':
-            lsflags |= (LSFLAGS_SIZE | LSFLAGS_LONG);
+            lsflags |= (LSFLAGS_SIZE | LSFLAGS_LONG | LSFLAGS_UID_GID);
             break;
 
           case 'R':

Reply via email to