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 8) and /userland/fstest_utils.c (Article 9)


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 <debug.h>                                021 #include <debug.h>
021                                                   022 
022 #include "fstest_utils.h"                         023 #include "fstest_utils.h"
023                                                   024 
024                                                   025 
025 /** Helper functions that dumps the contents o    026 /** Helper functions that dumps the contents of the current working
026     directory of the process */                   027     directory of the process */
027 static void cwd_ls(int detailed, int recursive    028 static void cwd_ls(int detailed, int recursive, int reclevel)
028 {                                                 029 {
029   char tab[256], *c;                              030   char tab[256], *c;
030   int i;                                          031   int i;
031   struct dirent * dirent;                         032   struct dirent * dirent;
032   DIR * here;                                     033   DIR * here;
033                                                   034 
034   here = opendir(".");                            035   here = opendir(".");
035   if (! here)                                     036   if (! here)
036     return;                                       037     return;
037                                                   038 
038   /* Build initial tabulation */                  039   /* Build initial tabulation */
039   if (recursive)                                  040   if (recursive)
040     {                                             041     {
041       for (c = tab, i = 0 ; (i < reclevel) &&     042       for (c = tab, i = 0 ; (i < reclevel) && (i < sizeof(tab)/2) ; i++)
042         {                                         043         {
043           *c++ = ' ';                             044           *c++ = ' ';
044           *c++ = ' ';                             045           *c++ = ' ';
045         }                                         046         }
046       *c++ = '\0';                                047       *c++ = '\0';
047     }                                             048     }
048   else                                            049   else
049     *tab = '\0';                                  050     *tab = '\0';
050                                                   051 
051   while ((dirent = readdir(here)) != NULL)        052   while ((dirent = readdir(here)) != NULL)
052     {                                             053     {
053       char entrychar;                             054       char entrychar;
054       char * entrysuffix;                         055       char * entrysuffix;
055                                                   056 
056       switch(dirent->type)                        057       switch(dirent->type)
057         {                                         058         {
058         case S_IFREG: entrychar='-'; entrysuff    059         case S_IFREG: entrychar='-'; entrysuffix=""; break;
059         case S_IFDIR: entrychar='d'; entrysuff    060         case S_IFDIR: entrychar='d'; entrysuffix="/"; break;
060         case S_IFLNK: entrychar='l'; entrysuff    061         case S_IFLNK: entrychar='l'; entrysuffix="@"; break;
                                                   >> 062         case S_IFCHR: entrychar='c'; entrysuffix=NULL; break;
061         default: entrychar='?'; entrysuffix="?    063         default: entrychar='?'; entrysuffix="?!?"; break;
062         }                                         064         }
063                                                   065 
064       if (detailed)                               066       if (detailed)
065         {                                         067         {
066           struct stat stat;                       068           struct stat stat;
067           char target_name[SOS_FS_DIRENT_NAME_    069           char target_name[SOS_FS_DIRENT_NAME_MAXLEN];
068                                                !! 070           char majorminor[24];
                                                   >> 071 
069           if (lstat(dirent->name, & stat))        072           if (lstat(dirent->name, & stat))
070             continue;                             073             continue;
071                                                   074 
072           *target_name = '\0';                    075           *target_name = '\0';
073           if (stat.st_type==S_IFLNK)           !! 076           if (stat.st_type == S_IFLNK)
074             {                                     077             {
075               int fd = open(dirent->name, O_RD    078               int fd = open(dirent->name, O_RDONLY | O_NOFOLLOW);
076               if (fd >= 0)                        079               if (fd >= 0)
077                 {                                 080                 {
078                   int len = read(fd, target_na    081                   int len = read(fd, target_name, sizeof(target_name) - 1);
079                   if (len < 0)                    082                   if (len < 0)
080                     *target_name='\0';            083                     *target_name='\0';
081                   else                            084                   else
082                     target_name[len] = '\0';      085                     target_name[len] = '\0';
083                   close(fd);                      086                   close(fd);
084                 }                                 087                 }
                                                   >> 088             }
                                                   >> 089           else if (stat.st_type == S_IFCHR)
                                                   >> 090             {
                                                   >> 091               snprintf(majorminor, sizeof(majorminor), " %d,%d",
                                                   >> 092                        stat.st_rdev_major, stat.st_rdev_minor);
                                                   >> 093               entrysuffix = majorminor;
085             }                                     094             }
086                                                   095 
087           bochs_printf("%s%c%c%c%c %lld %s%s%s    096           bochs_printf("%s%c%c%c%c %lld %s%s%s%s (location=0x%llx)\n",
088                        tab, entrychar,            097                        tab, entrychar,
089                        (stat.st_access_rights&    098                        (stat.st_access_rights&S_IRUSR)?'r':'-',
090                        (stat.st_access_rights&    099                        (stat.st_access_rights&S_IWUSR)?'w':'-',
091                        (stat.st_access_rights&    100                        (stat.st_access_rights&S_IXUSR)?'x':'-',
092                        stat.st_size,              101                        stat.st_size,
093                        dirent->name,              102                        dirent->name,
094                        entrysuffix,               103                        entrysuffix,
095                        (stat.st_type==S_IFLNK)    104                        (stat.st_type==S_IFLNK)?" -> ":"",
096                        target_name,               105                        target_name,
097                        stat.st_storage_locatio    106                        stat.st_storage_location);
098         }                                         107         }
099       else                                        108       else
100           bochs_printf("%s%s%s\n",                109           bochs_printf("%s%s%s\n",
101                        tab, dirent->name, entr    110                        tab, dirent->name, entrysuffix);
102                                                   111 
103       /* Next iteration */                        112       /* Next iteration */
104       if (recursive)                              113       if (recursive)
105         {                                         114         {
106           int fd_here = dirfd(here);              115           int fd_here = dirfd(here);
107           if (chdir(dirent->name))                116           if (chdir(dirent->name))
108             continue;                             117             continue;
109           cwd_ls(detailed, recursive, reclevel    118           cwd_ls(detailed, recursive, reclevel+1);
110           if(fchdir(fd_here))                     119           if(fchdir(fd_here))
111             {                                     120             {
112                 closedir(here);                   121                 closedir(here);
113                 return;                           122                 return;
114             }                                     123             }
115         }                                         124         }
116     }                                             125     }
117   closedir(here);                                 126   closedir(here);
118 }                                                 127 }
119                                                   128 
120                                                   129 
121 void ls(const char * path, int detailed, int r    130 void ls(const char * path, int detailed, int recursive)
122 {                                                 131 {
123   int fd_here = open(".", O_RDONLY | O_DIRECTO    132   int fd_here = open(".", O_RDONLY | O_DIRECTORY);
124   if (fd_here < 0)                                133   if (fd_here < 0)
125     return;                                       134     return;
126                                                   135 
127   if (chdir(path))                                136   if (chdir(path))
128     {                                             137     {
129       close(fd_here);                             138       close(fd_here);
130       return;                                     139       return;
131     }                                             140     }
132                                                   141 
133   bochs_printf("----------- Contents of %s:\n"    142   bochs_printf("----------- Contents of %s:\n", path);
134   cwd_ls(detailed, recursive, 1);                 143   cwd_ls(detailed, recursive, 1);
135   bochs_printf("---------------------------\n"    144   bochs_printf("---------------------------\n");
136                                                   145 
137   fchdir(fd_here);                                146   fchdir(fd_here);
138   close(fd_here);                                 147   close(fd_here);
139 }                                                 148 }
                                                      

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