ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libeio/eio.c
(Generate patch)

Comparing libeio/eio.c (file contents):
Revision 1.31 by root, Sat Jun 6 17:25:13 2009 UTC vs.
Revision 1.32 by root, Sat Jun 6 18:06:55 2009 UTC

178 if (wrk->dirp) \ 178 if (wrk->dirp) \
179 { \ 179 { \
180 closedir (wrk->dirp); \ 180 closedir (wrk->dirp); \
181 wrk->dirp = 0; \ 181 wrk->dirp = 0; \
182 } 182 }
183
183#define ETP_WORKER_COMMON \ 184#define ETP_WORKER_COMMON \
184 void *dbuf; \ 185 void *dbuf; \
185 DIR *dirp; 186 DIR *dirp;
186 187
187/*****************************************************************************/ 188/*****************************************************************************/
1010 1011
1011 if (!(flags & EIO_READDIR_DENTS)) 1012 if (!(flags & EIO_READDIR_DENTS))
1012 flags &= ~(EIO_READDIR_DIRS_FIRST | EIO_READDIR_STAT_ORDER); 1013 flags &= ~(EIO_READDIR_DIRS_FIRST | EIO_READDIR_STAT_ORDER);
1013 1014
1014 X_LOCK (wrklock); 1015 X_LOCK (wrklock);
1015
1016 /* the corresponding closedir is in ETP_WORKER_CLEAR */ 1016 /* the corresponding closedir is in ETP_WORKER_CLEAR */
1017 self->dirp = dirp = opendir (req->ptr1); 1017 self->dirp = dirp = opendir (req->ptr1);
1018 req->flags |= EIO_FLAG_PTR1_FREE | EIO_FLAG_PTR2_FREE; 1018 req->flags |= EIO_FLAG_PTR1_FREE | EIO_FLAG_PTR2_FREE;
1019 req->ptr1 = names = malloc (namesalloc); 1019 req->ptr1 = names = malloc (namesalloc);
1020 req->ptr2 = dents = flags ? malloc (dentalloc * sizeof (eio_dirent)) : 0; 1020 req->ptr2 = dents = flags ? malloc (dentalloc * sizeof (eio_dirent)) : 0;
1021
1022 X_UNLOCK (wrklock); 1021 X_UNLOCK (wrklock);
1023 1022
1024 if (dirp && names && (!flags || dents)) 1023 if (dirp && names && (!flags || dents))
1025 for (;;) 1024 for (;;)
1026 { 1025 {
1034 1033
1035 /* sort etc. */ 1034 /* sort etc. */
1036 req->int1 = flags; 1035 req->int1 = flags;
1037 req->result = dentoffs; 1036 req->result = dentoffs;
1038 1037
1038 if (dents)
1039 {
1040 eio_dirent *ent = dents + dentoffs;
1041
1042 while (ent > dents)
1043 (--ent)->name = names + (size_t)ent->name;
1044 }
1045
1046 if (flags & EIO_READDIR_STAT_ORDER
1039 if (flags & EIO_READDIR_STAT_ORDER || !(~flags & (EIO_READDIR_DIRS_FIRST | EIO_READDIR_FOUND_UNKNOWN)) 1047 || !(~flags & (EIO_READDIR_DIRS_FIRST | EIO_READDIR_FOUND_UNKNOWN)))
1040 { 1048 {
1041 /* pray your qsort doesn't use quicksort */ 1049 /* pray your qsort doesn't use quicksort */
1042 qsort (dents, dentoffs, sizeof (*dents), eio_dent_cmp); /* score depends of DIRS_FIRST */ 1050 qsort (dents, dentoffs, sizeof (*dents), eio_dent_cmp); /* score depends of DIRS_FIRST */
1043 } 1051 }
1044 else if (flags & EIO_READDIR_DIRS_FIRST && !(flags & EIO_READDIR_FOUND_UNKNOWN)) 1052 else if (flags & EIO_READDIR_DIRS_FIRST)
1045 { 1053 {
1046 /* in this case, all is known, and we just put dirs first and sort them */ 1054 /* in this case, all is known, and we just put dirs first and sort them */
1047 eio_dirent *ent = dents + dentoffs; 1055 eio_dirent *ent = dents + dentoffs;
1048 eio_dirent *dir = dents; 1056 eio_dirent *dir = dents;
1049 1057
1068 1076
1069 /* now sort the dirs only */ 1077 /* now sort the dirs only */
1070 qsort (dents, dir - dents, sizeof (*dents), eio_dent_cmp); 1078 qsort (dents, dir - dents, sizeof (*dents), eio_dent_cmp);
1071 } 1079 }
1072 1080
1073 {int i; for(i=0;i<dentoffs;++i){eio_dirent *e=dents+i; printf ("%9ld %3d %s\n", e->inode,e->score,e->name);}}//D 1081 /* only provide the names array unless DENTS is specified */
1082 if (!(flags & EIO_READDIR_DENTS))
1083 {
1084 X_LOCK (wrklock);
1085 assert (!dents);
1086 req->ptr1 = 0;
1087 req->ptr2 = names;
1088 X_UNLOCK (wrklock);
1089 }
1074 1090
1075 break; 1091 break;
1076 } 1092 }
1077 1093
1094 /* now add the entry to our list(s) */
1078 name = entp->d_name; 1095 name = entp->d_name;
1079 1096
1097 /* skip . and .. entries */
1080 if (name [0] != '.' || (name [1] && (name [1] != '.' || name [2]))) 1098 if (name [0] != '.' || (name [1] && (name [1] != '.' || name [2])))
1081 { 1099 {
1082 int len = strlen (name) + 1; 1100 int len = strlen (name) + 1;
1083 1101
1084 while (expect_false (namesoffs + len > namesalloc)) 1102 while (expect_false (namesoffs + len > namesalloc))
1109 break; 1127 break;
1110 } 1128 }
1111 1129
1112 ent = dents + dentoffs; 1130 ent = dents + dentoffs;
1113 1131
1114 ent->name = names + namesoffs; 1132 ent->name = (char *)(size_t)namesoffs; /* rather dirtily we store the offset in the pointer */
1115 ent->namelen = len - 1; 1133 ent->namelen = len - 1;
1116 ent->inode = D_INO (entp); 1134 ent->inode = D_INO (entp);
1117 1135
1118 switch (D_TYPE (entp)) 1136 switch (D_TYPE (entp))
1119 { 1137 {
1126 case DT_FIFO: ent->type = EIO_DT_FIFO; break; 1144 case DT_FIFO: ent->type = EIO_DT_FIFO; break;
1127 #endif 1145 #endif
1128 #ifdef DT_CHR 1146 #ifdef DT_CHR
1129 case DT_CHR: ent->type = EIO_DT_CHR; break; 1147 case DT_CHR: ent->type = EIO_DT_CHR; break;
1130 #endif 1148 #endif
1131 #ifdef DT_DIR 1149 #ifdef DT_DIR
1132 case DT_DIR: ent->type = EIO_DT_DIR; break; 1150 case DT_DIR: ent->type = EIO_DT_DIR; break;
1133 #endif 1151 #endif
1134 #ifdef DT_BLK 1152 #ifdef DT_BLK
1135 case DT_BLK: ent->type = EIO_DT_BLK; break; 1153 case DT_BLK: ent->type = EIO_DT_BLK; break;
1136 #endif 1154 #endif
1137 #ifdef DT_REG 1155 #ifdef DT_REG
1138 case DT_REG: ent->type = EIO_DT_REG; break; 1156 case DT_REG: ent->type = EIO_DT_REG; break;
1139 #endif 1157 #endif
1140 #ifdef DT_LNK 1158 #ifdef DT_LNK
1141 case DT_LNK: ent->type = EIO_DT_LNK; break; 1159 case DT_LNK: ent->type = EIO_DT_LNK; break;
1142 #endif 1160 #endif
1143 #ifdef DT_SOCK 1161 #ifdef DT_SOCK
1144 case DT_SOCK: ent->type = EIO_DT_SOCK; break; 1162 case DT_SOCK: ent->type = EIO_DT_SOCK; break;
1145 #endif 1163 #endif
1168 ++dentoffs; 1186 ++dentoffs;
1169 } 1187 }
1170 } 1188 }
1171 else 1189 else
1172 req->result = -1; 1190 req->result = -1;
1173
1174 /* if user doesn't want the dents, do not provide it */
1175 if (!(flags & EIO_READDIR_DENTS))
1176 {
1177 X_LOCK (wrklock);
1178 free (dents);
1179 req->ptr2 = req->ptr1;
1180 req->ptr1 = 0;
1181 X_UNLOCK (wrklock);
1182 }
1183} 1191}
1184 1192
1185#if !(_POSIX_MAPPED_FILES && _POSIX_SYNCHRONIZED_IO) 1193#if !(_POSIX_MAPPED_FILES && _POSIX_SYNCHRONIZED_IO)
1186# undef msync 1194# undef msync
1187# define msync(a,b,c) ((errno = ENOSYS), -1) 1195# define msync(a,b,c) ((errno = ENOSYS), -1)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines