SimpleOS

LXR

Navigation



Site hébergé par : enix

The LXR Cross Referencer for SOS

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Article:1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 6.5 ] [ 7 ] [ 7.5 ] [ 8 ] [ 9 ] [ 9.5 ]

Diff markup

Differences between /userland/fstest_utils.c (Article 9) and /userland/fstest_utils.c (Article 9.5)


001 /* Copyright (C) 2005  David Decotigny            001 /* Copyright (C) 2005  David Decotigny
002                                                   002 
003    This program is free software; you can redi    003    This program is free software; you can redistribute it and/or
004    modify it under the terms of the GNU Genera    004    modify it under the terms of the GNU General Public License
005    as published by the Free Software Foundatio    005    as published by the Free Software Foundation; either version 2
006    of the License, or (at your option) any lat    006    of the License, or (at your option) any later version.
007                                                   007    
008    This program is distributed in the hope tha    008    This program is distributed in the hope that it will be useful,
009    but WITHOUT ANY WARRANTY; without even the     009    but WITHOUT ANY WARRANTY; without even the implied warranty of
010    MERCHANTABILITY or FITNESS FOR A PARTICULAR    010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
011    GNU General Public License for more details    011    GNU General Public License for more details.
012                                                   012    
013    You should have received a copy of the GNU     013    You should have received a copy of the GNU General Public License
014    along with this program; if not, write to t    014    along with this program; if not, write to the Free Software
015    Foundation, Inc., 59 Temple Place - Suite 3    015    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
016    USA.                                           016    USA. 
017 */                                                017 */
018                                                   018 
019 #include <libc.h>                                 019 #include <libc.h>
020 #include <stdarg.h>                               020 #include <stdarg.h>
021 #include <debug.h>                                021 #include <debug.h>
022                                                   022 
023 #include "fstest_utils.h"                         023 #include "fstest_utils.h"
024                                                   024 
025                                                   025 
026 /** Helper functions that dumps the contents o    026 /** Helper functions that dumps the contents of the current working
027     directory of the process */                   027     directory of the process */
028 static void cwd_ls(int detailed, int recursive    028 static void cwd_ls(int detailed, int recursive, int reclevel)
029 {                                                 029 {
030   char tab[256], *c;                              030   char tab[256], *c;
031   int i;                                          031   int i;
032   struct dirent * dirent;                         032   struct dirent * dirent;
033   DIR * here;                                     033   DIR * here;
034                                                   034 
035   here = opendir(".");                            035   here = opendir(".");
036   if (! here)                                     036   if (! here)
037     return;                                       037     return;
038                                                   038 
039   /* Build initial tabulation */                  039   /* Build initial tabulation */
040   if (recursive)                                  040   if (recursive)
041     {                                             041     {
042       for (c = tab, i = 0 ; (i < reclevel) &&     042       for (c = tab, i = 0 ; (i < reclevel) && (i < sizeof(tab)/2) ; i++)
043         {                                         043         {
044           *c++ = ' ';                             044           *c++ = ' ';
045           *c++ = ' ';                             045           *c++ = ' ';
046         }                                         046         }
047       *c++ = '\0';                                047       *c++ = '\0';
048     }                                             048     }
049   else                                            049   else
050     *tab = '\0';                                  050     *tab = '\0';
051                                                   051 
052   while ((dirent = readdir(here)) != NULL)        052   while ((dirent = readdir(here)) != NULL)
053     {                                             053     {
054       char entrychar;                             054       char entrychar;
055       char * entrysuffix;                         055       char * entrysuffix;
056                                                   056 
057       switch(dirent->type)                        057       switch(dirent->type)
058         {                                         058         {
059         case S_IFREG: entrychar='-'; entrysuff    059         case S_IFREG: entrychar='-'; entrysuffix=""; break;
060         case S_IFDIR: entrychar='d'; entrysuff    060         case S_IFDIR: entrychar='d'; entrysuffix="/"; break;
061         case S_IFLNK: entrychar='l'; entrysuff    061         case S_IFLNK: entrychar='l'; entrysuffix="@"; break;
062         case S_IFCHR: entrychar='c'; entrysuff    062         case S_IFCHR: entrychar='c'; entrysuffix=NULL; break;
                                                   >> 063         case S_IFBLK: entrychar='b'; entrysuffix=NULL; break;
063         default: entrychar='?'; entrysuffix="?    064         default: entrychar='?'; entrysuffix="?!?"; break;
064         }                                         065         }
065                                                   066 
066       if (detailed)                               067       if (detailed)
067         {                                         068         {
068           struct stat stat;                       069           struct stat stat;
069           char target_name[SOS_FS_DIRENT_NAME_    070           char target_name[SOS_FS_DIRENT_NAME_MAXLEN];
070           char majorminor[24];                    071           char majorminor[24];
071                                                   072 
072           if (lstat(dirent->name, & stat))        073           if (lstat(dirent->name, & stat))
073             continue;                             074             continue;
074                                                   075 
075           *target_name = '\0';                    076           *target_name = '\0';
076           if (stat.st_type == S_IFLNK)            077           if (stat.st_type == S_IFLNK)
077             {                                     078             {
078               int fd = open(dirent->name, O_RD    079               int fd = open(dirent->name, O_RDONLY | O_NOFOLLOW);
079               if (fd >= 0)                        080               if (fd >= 0)
080                 {                                 081                 {
081                   int len = read(fd, target_na    082                   int len = read(fd, target_name, sizeof(target_name) - 1);
082                   if (len < 0)                    083                   if (len < 0)
083                     *target_name='\0';            084                     *target_name='\0';
084                   else                            085                   else
085                     target_name[len] = '\0';      086                     target_name[len] = '\0';
086                   close(fd);                      087                   close(fd);
087                 }                                 088                 }
088             }                                     089             }
089           else if (stat.st_type == S_IFCHR)    !! 090           else if ( (stat.st_type == S_IFCHR) || (stat.st_type == S_IFBLK) )
090             {                                     091             {
091               snprintf(majorminor, sizeof(majo    092               snprintf(majorminor, sizeof(majorminor), " %d,%d",
092                        stat.st_rdev_major, sta    093                        stat.st_rdev_major, stat.st_rdev_minor);
093               entrysuffix = majorminor;           094               entrysuffix = majorminor;
094             }                                     095             }
095                                                   096 
096           bochs_printf("%s%c%c%c%c %lld %s%s%s    097           bochs_printf("%s%c%c%c%c %lld %s%s%s%s (location=0x%llx)\n",
097                        tab, entrychar,            098                        tab, entrychar,
098                        (stat.st_access_rights&    099                        (stat.st_access_rights&S_IRUSR)?'r':'-',
099                        (stat.st_access_rights&    100                        (stat.st_access_rights&S_IWUSR)?'w':'-',
100                        (stat.st_access_rights&    101                        (stat.st_access_rights&S_IXUSR)?'x':'-',
101                        stat.st_size,              102                        stat.st_size,
102                        dirent->name,              103                        dirent->name,
103                        entrysuffix,               104                        entrysuffix,
104                        (stat.st_type==S_IFLNK)    105                        (stat.st_type==S_IFLNK)?" -> ":"",
105                        target_name,               106                        target_name,
106                        stat.st_storage_locatio    107                        stat.st_storage_location);
107         }                                         108         }
108       else                                        109       else
109           bochs_printf("%s%s%s\n",                110           bochs_printf("%s%s%s\n",
110                        tab, dirent->name, entr    111                        tab, dirent->name, entrysuffix);
111                                                   112 
112       /* Next iteration */                        113       /* Next iteration */
113       if (recursive)                           !! 114       if (recursive && (dirent->type == S_IFDIR))
114         {                                         115         {
115           int fd_here = dirfd(here);              116           int fd_here = dirfd(here);
116           if (chdir(dirent->name))                117           if (chdir(dirent->name))
117             continue;                             118             continue;
118           cwd_ls(detailed, recursive, reclevel    119           cwd_ls(detailed, recursive, reclevel+1);
119           if(fchdir(fd_here))                     120           if(fchdir(fd_here))
120             {                                     121             {
121                 closedir(here);                   122                 closedir(here);
122                 return;                           123                 return;
123             }                                     124             }
124         }                                         125         }
125     }                                             126     }
126   closedir(here);                                 127   closedir(here);
127 }                                                 128 }
128                                                   129 
129                                                   130 
130 void ls(const char * path, int detailed, int r    131 void ls(const char * path, int detailed, int recursive)
131 {                                                 132 {
132   int fd_here = open(".", O_RDONLY | O_DIRECTO    133   int fd_here = open(".", O_RDONLY | O_DIRECTORY);
133   if (fd_here < 0)                                134   if (fd_here < 0)
134     return;                                       135     return;
135                                                   136 
136   if (chdir(path))                                137   if (chdir(path))
137     {                                             138     {
138       close(fd_here);                             139       close(fd_here);
139       return;                                     140       return;
140     }                                             141     }
141                                                   142 
142   bochs_printf("----------- Contents of %s:\n"    143   bochs_printf("----------- Contents of %s:\n", path);
143   cwd_ls(detailed, recursive, 1);                 144   cwd_ls(detailed, recursive, 1);
144   bochs_printf("---------------------------\n"    145   bochs_printf("---------------------------\n");
145                                                   146 
146   fchdir(fd_here);                                147   fchdir(fd_here);
147   close(fd_here);                                 148   close(fd_here);
148 }                                                 149 }
                                                      

source navigation ] diff markup ] identifier search ] general search ]