1 /*@-type@*/ /* LCL: function typedefs */
8 #if defined(HAVE_PTHREAD_H) && !defined(__LCLINT__)
12 #include <rpmio_internal.h>
20 /* =============================================================== */
21 static int ftpMkdir(const char * path, /*@unused@*/ mode_t mode)
22 /*@globals fileSystem @*/
23 /*@modifies fileSystem @*/
26 if ((rc = ftpCmd("MKD", path, NULL)) != 0)
30 sprintf(buf, " 0%o", mode);
31 (void) ftpCmd("SITE CHMOD", path, buf);
37 static int ftpChdir(const char * path)
38 /*@globals fileSystem @*/
39 /*@modifies fileSystem @*/
41 return ftpCmd("CWD", path, NULL);
44 static int ftpRmdir(const char * path)
45 /*@globals fileSystem @*/
46 /*@modifies fileSystem @*/
48 return ftpCmd("RMD", path, NULL);
51 static int ftpRename(const char * oldpath, const char * newpath)
52 /*@globals fileSystem @*/
53 /*@modifies fileSystem @*/
56 if ((rc = ftpCmd("RNFR", oldpath, NULL)) != 0)
58 return ftpCmd("RNTO", newpath, NULL);
61 static int ftpUnlink(const char * path)
62 /*@globals fileSystem @*/
63 /*@modifies fileSystem @*/
65 return ftpCmd("DELE", path, NULL);
68 /* =============================================================== */
69 /* XXX rebuilddb.c: analogues to mkdir(2)/rmdir(2). */
70 int Mkdir (const char * path, mode_t mode)
73 int ut = urlPath(path, &lpath);
77 return ftpMkdir(path, mode);
78 /*@notreached@*/ break;
79 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
88 /*@notreached@*/ break;
90 return mkdir(path, mode);
93 int Chdir (const char * path)
96 int ut = urlPath(path, &lpath);
100 return ftpChdir(path);
101 /*@notreached@*/ break;
102 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
111 /*@notreached@*/ break;
116 int Rmdir (const char * path)
119 int ut = urlPath(path, &lpath);
123 return ftpRmdir(path);
124 /*@notreached@*/ break;
125 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
134 /*@notreached@*/ break;
139 /* XXX rpmdb.c: analogue to rename(2). */
141 int Rename (const char * oldpath, const char * newpath)
143 const char *oe = NULL;
144 const char *ne = NULL;
147 /* XXX lib/install.c used to rely on this behavior. */
148 if (!strcmp(oldpath, newpath)) return 0;
150 oldut = urlPath(oldpath, &oe);
152 case URL_IS_FTP: /* XXX WRONG WRONG WRONG */
153 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
160 /*@notreached@*/ break;
163 newut = urlPath(newpath, &ne);
167 fprintf(stderr, "*** rename old %*s new %*s\n", (int)(oe - oldpath), oldpath, (int)(ne - newpath), newpath);
168 if (!(oldut == newut && oe && ne && (oe - oldpath) == (ne - newpath) &&
169 !xstrncasecmp(oldpath, newpath, (oe - oldpath))))
171 return ftpRename(oldpath, newpath);
172 /*@notreached@*/ break;
173 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
183 /*@notreached@*/ break;
185 return rename(oldpath, newpath);
188 int Link (const char * oldpath, const char * newpath)
190 const char *oe = NULL;
191 const char *ne = NULL;
194 oldut = urlPath(oldpath, &oe);
196 case URL_IS_FTP: /* XXX WRONG WRONG WRONG */
197 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
204 /*@notreached@*/ break;
207 newut = urlPath(newpath, &ne);
209 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
210 case URL_IS_FTP: /* XXX WRONG WRONG WRONG */
213 fprintf(stderr, "*** link old %*s new %*s\n", (int)(oe - oldpath), oldpath, (int)(ne - newpath), newpath);
214 if (!(oldut == newut && oe && ne && (oe - oldpath) == (ne - newpath) &&
215 !xstrncasecmp(oldpath, newpath, (oe - oldpath))))
225 /*@notreached@*/ break;
227 return link(oldpath, newpath);
230 /* XXX build/build.c: analogue to unlink(2). */
232 int Unlink(const char * path) {
234 int ut = urlPath(path, &lpath);
238 return ftpUnlink(path);
239 /*@notreached@*/ break;
240 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
249 /*@notreached@*/ break;
254 /* XXX swiped from mc-4.5.39-pre9 vfs/ftpfs.c */
256 #define g_strdup xstrdup
260 * FIXME: this is broken. It depends on mc not crossing border on month!
263 static int current_mday;
265 static int current_mon;
267 static int current_year;
269 /* Following stuff (parse_ls_lga) is used by ftpfs and extfs */
273 static char *columns [MAXCOLS]; /* Points to the string in column n */
275 static int column_ptr [MAXCOLS]; /* Index from 0 to the starting positions of the columns */
278 vfs_split_text (char *p)
279 /*@globals columns, column_ptr @*/
280 /*@modifies *p, columns, column_ptr @*/
286 for (numcols = 0; *p && numcols < MAXCOLS; numcols++){
287 while (*p == ' ' || *p == '\r' || *p == '\n'){
291 columns [numcols] = p;
292 column_ptr [numcols] = p - original;
293 while (*p && *p != ' ' && *p != '\r' && *p != '\n')
303 if (!columns [idx] || columns [idx][0] < '0' || columns [idx][0] > '9')
309 is_dos_date(/*@null@*/ const char *str)
312 if (str != NULL && strlen(str) == 8 &&
313 str[2] == str[5] && strchr("\\-/", (int)str[2]) != NULL)
319 is_week (/*@null@*/ const char * str, /*@out@*/ struct tm * tim)
322 /*@observer@*/ static const char * week = "SunMonTueWedThuFriSat";
325 /*@-observertrans -mayaliasunique@*/
326 if (str != NULL && (pos=strstr(week, str)) != NULL) {
327 /*@=observertrans =mayaliasunique@*/
329 tim->tm_wday = (pos - week)/3;
336 is_month (/*@null@*/ const char * str, /*@out@*/ struct tm * tim)
339 /*@observer@*/ static const char * month = "JanFebMarAprMayJunJulAugSepOctNovDec";
342 /*@-observertrans -mayaliasunique@*/
343 if (str != NULL && (pos = strstr(month, str)) != NULL) {
344 /*@=observertrans -mayaliasunique@*/
346 tim->tm_mon = (pos - month)/3;
353 is_time (/*@null@*/ const char * str, /*@out@*/ struct tm * tim)
356 const char * p, * p2;
358 if (str != NULL && (p = strchr(str, ':')) && (p2 = strrchr(str, ':'))) {
360 if (sscanf (str, "%2d:%2d:%2d", &tim->tm_hour, &tim->tm_min, &tim->tm_sec) != 3)
363 if (sscanf (str, "%2d:%2d", &tim->tm_hour, &tim->tm_min) != 2)
372 static int is_year(/*@null@*/ const char * str, /*@out@*/ struct tm * tim)
383 if (strlen(str) != 4)
386 if (sscanf(str, "%ld", &year) != 1)
389 if (year < 1900 || year > 3000)
392 tim->tm_year = (int) (year - 1900);
398 * FIXME: this is broken. Consider following entry:
399 * -rwx------ 1 root root 1 Aug 31 10:04 2904 1234
400 * where "2904 1234" is filename. Well, this code decodes it as year :-(.
404 vfs_parse_filetype (char c)
408 case 'd': return S_IFDIR;
409 case 'b': return S_IFBLK;
410 case 'c': return S_IFCHR;
411 case 'l': return S_IFLNK;
413 #ifdef IS_IFSOCK /* And if not, we fall through to IFIFO, which is pretty close */
416 case 'p': return S_IFIFO;
417 case 'm': case 'n': /* Don't know what these are :-) */
418 case '-': case '?': return S_IFREG;
423 static int vfs_parse_filemode (const char *p)
425 { /* converts rw-rw-rw- into 0666 */
428 case 'r': res |= 0400; break;
433 case 'w': res |= 0200; break;
438 case 'x': res |= 0100; break;
439 case 's': res |= 0100 | S_ISUID; break;
440 case 'S': res |= S_ISUID; break;
445 case 'r': res |= 0040; break;
450 case 'w': res |= 0020; break;
455 case 'x': res |= 0010; break;
456 case 's': res |= 0010 | S_ISGID; break;
457 case 'l': /* Solaris produces these */
458 case 'S': res |= S_ISGID; break;
463 case 'r': res |= 0004; break;
468 case 'w': res |= 0002; break;
473 case 'x': res |= 0001; break;
474 case 't': res |= 0001 | S_ISVTX; break;
475 case 'T': res |= S_ISVTX; break;
482 static int vfs_parse_filedate(int idx, /*@out@*/ time_t *t)
484 { /* This thing parses from idx in columns[] array */
491 /* Let's setup default time values */
492 tim.tm_year = current_year;
493 tim.tm_mon = current_mon;
494 tim.tm_mday = current_mday;
498 tim.tm_isdst = -1; /* Let mktime() try to guess correct dst offset */
502 /* We eat weekday name in case of extfs */
507 if(is_month(p, &tim)){
508 /* And we expect, it followed by day number */
510 tim.tm_mday = (int)atol (columns [idx++]);
512 return 0; /* No day */
515 /* We usually expect:
518 But in case of extfs we allow these date formats:
521 Wek Mon DD hh:mm:ss YYYY
523 where Mon is Jan-Dec, DD, MM, YY two digit day, month, year,
524 YYYY four digit year, hh, mm, ss two digit hour, minute or second. */
526 /* Here just this special case with MM-DD-YY */
532 memset(d, 0, sizeof(d));
533 if (sscanf(p, "%2d-%2d-%2d", &d[0], &d[1], &d[2]) == 3){
540 /* Hmm... maybe, next time :)*/
542 /* At last, MM-DD-YY */
543 d[0]--; /* Months are zerobased */
553 return 0; /* sscanf failed */
555 return 0; /* unsupported format */
558 /* Here we expect to find time and/or year */
561 if(is_time(columns[idx], &tim) || (got_year = is_year(columns[idx], &tim))) {
564 /* This is a special case for ctime() or Mon DD YYYY hh:mm */
566 ((got_year = is_year(columns[idx], &tim)) || is_time(columns[idx], &tim)))
567 idx++; /* time & year or reverse */
568 } /* only time or date */
571 return 0; /* Nor time or date */
574 * If the date is less than 6 months in the past, it is shown without year
575 * other dates in the past or future are shown with year but without time
576 * This does not check for years before 1900 ... I don't know, how
577 * to represent them at all
580 current_mon < 6 && current_mon < tim.tm_mon &&
581 tim.tm_mon - current_mon >= 6)
585 if ((*t = mktime(&tim)) < 0)
591 vfs_parse_ls_lga (char * p, /*@out@*/ struct stat * st,
592 /*@out@*/ const char ** filename,
593 /*@out@*/ const char ** linkname)
594 /*@modifies *p, *st, *filename, *linkname @*/
596 int idx, idx2, num_cols;
600 if (strncmp (p, "total", 5) == 0)
603 p_copy = g_strdup(p);
604 /* XXX FIXME: parse out inode number from "NLST -lai ." */
605 /* XXX FIXME: parse out sizein blocks from "NLST -lais ." */
607 if ((i = vfs_parse_filetype(*(p++))) == -1)
611 if (*p == ' ') /* Notwell 4 */
614 if (strlen (p) <= 8 || p [8] != ']')
616 /* Should parse here the Notwell permissions :) */
618 if (S_ISDIR (st->st_mode))
619 st->st_mode |= (S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR | S_IXUSR | S_IXGRP | S_IXOTH);
621 st->st_mode |= (S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR);
625 if ((i = vfs_parse_filemode(p)) == -1)
630 /* This is for an extra ACL attribute (HP-UX) */
636 p_copy = g_strdup(p);
637 num_cols = vfs_split_text (p);
639 st->st_nlink = atol (columns [0]);
640 if (st->st_nlink < 0)
645 st->st_uid = finduid (columns [1]);
647 (void) unameToUid (columns [1], &st->st_uid);
650 st->st_uid = (uid_t) atol (columns [1]);
652 /* Mhm, the ls -lg did not produce a group field */
653 for (idx = 3; idx <= 5; idx++)
654 if (is_month(columns [idx], NULL) || is_week(columns [idx], NULL) || is_dos_date(columns[idx]))
657 if (idx == 6 || (idx == 5 && !S_ISCHR (st->st_mode) && !S_ISBLK (st->st_mode)))
660 /* We don't have gid */
661 if (idx == 3 || (idx == 4 && (S_ISCHR(st->st_mode) || S_ISBLK (st->st_mode))))
664 /* We have gid field */
666 st->st_gid = (gid_t) atol (columns [2]);
669 st->st_gid = findgid (columns [2]);
671 (void) gnameToGid (columns [1], &st->st_gid);
677 if (S_ISCHR (st->st_mode) || S_ISBLK (st->st_mode)){
680 if (!is_num (idx2) || sscanf(columns [idx2], " %d,", &maj) != 1)
683 if (!is_num (++idx2) || sscanf(columns [idx2], " %d", &min) != 1)
687 st->st_rdev = ((maj & 0xff) << 8) | (min & 0xffff00ff);
692 /* Common file size */
696 st->st_size = (size_t) atol (columns [idx2]);
702 idx = vfs_parse_filedate(idx, &st->st_mtime);
705 /* Use resulting time value */
706 st->st_atime = st->st_ctime = st->st_mtime;
709 #ifdef HAVE_ST_BLKSIZE
710 st->st_blksize = 512;
712 #ifdef HAVE_ST_BLOCKS
713 st->st_blocks = (st->st_size + 511) / 512;
716 for (i = idx + 1, idx2 = 0; i < num_cols; i++ )
717 if (strcmp (columns [i], "->") == 0){
722 if (((S_ISLNK (st->st_mode) ||
723 (num_cols == idx + 3 && st->st_nlink > 1))) /* Maybe a hardlink? (in extfs) */
730 t = g_strndup (p_copy + column_ptr [idx], column_ptr [idx2] - column_ptr [idx] - 1);
732 int nb = column_ptr [idx2] - column_ptr [idx] - 1;
734 strncpy(t, p_copy + column_ptr [idx], nb);
739 t = g_strdup (p_copy + column_ptr [idx2+1]);
741 if (t [tlen-1] == '\r' || t [tlen-1] == '\n')
743 if (t [tlen-2] == '\r' || t [tlen-2] == '\n')
749 /* Extract the filename from the string copy, not from the columns
750 * this way we have a chance of entering hidden directories like ". ."
754 *filename = g_strdup (columns [idx++]);
759 t = g_strdup (p_copy + column_ptr [idx]); idx++;
762 if (t [tlen-1] == '\r' || t [tlen-1] == '\n')
764 if (t [tlen-2] == '\r' || t [tlen-2] == '\n')
778 static int errorcount = 0;
780 if (++errorcount < 5) {
781 message_1s (1, "Could not parse:", p_copy);
782 } else if (errorcount == 5)
783 message_1s (1, "More parsing errors will be ignored.", "(sorry)" );
788 if (p_copy != p) /* Carefull! */
805 static size_t ftpBufAlloced = 0;
810 static /*@only@*/ char * ftpBuf = NULL;
812 #define alloca_strdup(_s) strcpy(alloca(strlen(_s)+1), (_s))
815 static int ftpNLST(const char * url, ftpSysCall_t ftpSysCall,
816 /*@out@*/ /*@null@*/ struct stat * st,
817 /*@out@*/ /*@null@*/ char * rlbuf, size_t rlbufsiz)
818 /*@globals fileSystem @*/
819 /*@modifies *st, *rlbuf, fileSystem @*/
823 int bufLength, moretodo;
824 const char *n, *ne, *o, *oe;
833 n = ne = o = oe = NULL;
834 (void) urlPath(url, &path);
838 switch (ftpSysCall) {
840 fd = ftpOpen(url, 0, 0, &u);
841 if (fd == NULL || u == NULL)
844 u->openError = ftpReq(fd, "LIST", path);
847 urldn = alloca_strdup(url);
849 if ((bn = strrchr(urldn, '/')) == NULL)
858 rc = ftpChdir(urldn); /* XXX don't care about CWD */
862 fd = ftpOpen(url, 0, 0, &u);
863 if (fd == NULL || u == NULL)
866 /* XXX possibly should do "NLST -lais" to get st_ino/st_blocks also */
867 u->openError = ftpReq(fd, "NLST", "-la");
869 if (bn == NULL || nbn <= 0) {
876 if (u->openError < 0) {
877 fd = fdLink(fd, "error data (ftpStat)");
882 if (ftpBufAlloced == 0 || ftpBuf == NULL) {
883 ftpBufAlloced = _url_iobuf_size;
884 ftpBuf = xcalloc(ftpBufAlloced, sizeof(ftpBuf[0]));
893 /* XXX FIXME: realloc ftpBuf if < ~128 chars remain */
894 if ((ftpBufAlloced - bufLength) < (1024+80)) {
896 ftpBuf = xrealloc(ftpBuf, ftpBufAlloced);
898 s = se = ftpBuf + bufLength;
901 rc = fdFgets(fd, se, (ftpBufAlloced - bufLength));
906 if (ftpSysCall == DO_FTP_GLOB) { /* XXX HACK */
907 bufLength += strlen(se);
911 for (s = se; *s != '\0'; s = se) {
914 while (*se && *se != '\n') se++;
915 if (se > s && se[-1] == '\r') se[-1] = '\0';
917 /*@innerbreak@*/ break;
920 if (!strncmp(s, "total ", sizeof("total ")-1))
921 /*@innercontinue@*/ continue;
924 for (bingo = 0, n = se; n >= s; n--) {
928 /*@switchbreak@*/ break;
930 if (o || !(n[-3] == ' ' && n[-2] == '-' && n[-1] == '>')) {
931 while (*(++n) == ' ')
934 /*@switchbreak@*/ break;
936 for (o = n + 1; *o == ' '; o++)
940 /*@switchbreak@*/ break;
942 /*@switchbreak@*/ break;
945 /*@innerbreak@*/ break;
948 if (nbn != (ne - n)) /* Same name length? */
949 /*@innercontinue@*/ continue;
950 if (strncmp(n, bn, nbn)) /* Same name? */
951 /*@innercontinue@*/ continue;
954 /*@innerbreak@*/ break;
957 if (moretodo && se > s) {
958 bufLength = se - s - 1;
960 memmove(ftpBuf, s, bufLength);
966 switch (ftpSysCall) {
969 /* XXX FIXME: symlink, replace urldn/bn from [o,oe) and restart */
973 if (st == NULL || !(n && ne)) {
976 rc = ((vfs_parse_ls_lga(s, st, NULL, NULL) > 0) ? 0 : -1);
979 case DO_FTP_READLINK:
980 if (rlbuf == NULL || !(o && oe)) {
986 memcpy(rlbuf, o, rc);
992 rc = 0; /* XXX WRONG WRONG WRONG */
995 rc = 0; /* XXX WRONG WRONG WRONG */
1000 (void) ufdClose(fd);
1005 static const char * statstr(const struct stat * st,
1006 /*@returned@*/ /*@out@*/ char * buf)
1007 /*@modifies *buf @*/
1010 "*** dev %x ino %x mode %0o nlink %d uid %d gid %d rdev %x size %x\n",
1011 (unsigned)st->st_dev,
1012 (unsigned)st->st_ino,
1017 (unsigned)st->st_rdev,
1018 (unsigned)st->st_size);
1023 static int ftp_st_ino = 0xdead0000;
1025 static int ftpStat(const char * path, /*@out@*/ struct stat *st)
1026 /*@globals fileSystem @*/
1027 /*@modifies *st, fileSystem @*/
1031 rc = ftpNLST(path, DO_FTP_STAT, st, NULL, 0);
1032 /* XXX fts(3) needs/uses st_ino, make something up for now. */
1034 if (st->st_ino == 0)
1035 st->st_ino = ftp_st_ino++;
1038 fprintf(stderr, "*** ftpStat(%s) rc %d\n%s", path, rc, statstr(st, buf));
1042 static int ftpLstat(const char * path, /*@out@*/ struct stat *st)
1043 /*@globals fileSystem @*/
1044 /*@modifies *st, fileSystem @*/
1048 rc = ftpNLST(path, DO_FTP_LSTAT, st, NULL, 0);
1049 /* XXX fts(3) needs/uses st_ino, make something up for now. */
1051 if (st->st_ino == 0)
1052 st->st_ino = ftp_st_ino++;
1055 fprintf(stderr, "*** ftpLstat(%s) rc %d\n%s\n", path, rc, statstr(st, buf));
1059 static int ftpReadlink(const char * path, /*@out@*/ char * buf, size_t bufsiz)
1060 /*@globals fileSystem @*/
1061 /*@modifies *buf, fileSystem @*/
1064 rc = ftpNLST(path, DO_FTP_READLINK, NULL, buf, bufsiz);
1066 fprintf(stderr, "*** ftpReadlink(%s) rc %d\n", path, rc);
1070 struct __dirstream {
1071 int fd; /* File descriptor. */
1072 char * data; /* Directory block. */
1073 size_t allocation; /* Space allocated for the block. */
1074 size_t size; /* Total valid data in the block. */
1075 size_t offset; /* Current offset into the block. */
1076 off_t filepos; /* Position of next entry to read. */
1077 #if defined(HAVE_PTHREAD_H) && !defined(__LCLINT__)
1078 pthread_mutex_t lock; /* Mutex lock for this structure. */
1083 static int ftpmagicdir = 0x8440291;
1084 #define ISFTPMAGIC(_dir) (!memcmp((_dir), &ftpmagicdir, sizeof(ftpmagicdir)))
1087 static DIR * ftpOpendir(const char * path)
1088 /*@globals fileSystem @*/
1089 /*@modifies fileSystem @*/
1094 const char * s, * sb, * se;
1103 fprintf(stderr, "*** ftpOpendir(%s)\n", path);
1104 rc = ftpNLST(path, DO_FTP_GLOB, NULL, NULL, 0);
1109 * ftpBuf now contains absolute paths, newline terminated.
1110 * Calculate the number of bytes to hold the directory info.
1112 nb = sizeof(".") + sizeof("..");
1116 while ((c = *se) != '\0') {
1121 /*@switchbreak@*/ break;
1124 for (sb = se; sb > s && sb[-1] != ' '; sb--)
1130 if (*se == '\n') se++;
1133 /*@switchbreak@*/ break;
1135 /*@switchbreak@*/ break;
1139 nb += sizeof(*dir) + sizeof(*dp) + ((ac + 1) * sizeof(*av)) + (ac + 1);
1140 dir = xcalloc(1, nb);
1142 dp = (struct dirent *) (dir + 1);
1143 av = (const char **) (dp + 1);
1144 dt = (char *) (av + (ac + 1));
1145 t = (char *) (dt + ac + 1);
1148 dir->fd = ftpmagicdir;
1149 dir->data = (char *) dp;
1150 dir->allocation = nb;
1156 /*@-dependenttrans -unrecog@*/
1157 dt[ac] = DT_DIR; av[ac++] = t; t = stpcpy(t, "."); t++;
1158 dt[ac] = DT_DIR; av[ac++] = t; t = stpcpy(t, ".."); t++;
1159 /*@=dependenttrans =unrecog@*/
1162 while ((c = *se) != '\0') {
1167 /*@switchbreak@*/ break;
1169 /*@-dependenttrans@*/
1171 /*@=dependenttrans@*/
1177 /*@innerbreak@*/ break;
1180 /*@innerbreak@*/ break;
1183 /*@innerbreak@*/ break;
1186 /*@innerbreak@*/ break;
1189 /*@innerbreak@*/ break;
1192 /*@innerbreak@*/ break;
1195 /*@innerbreak@*/ break;
1197 dt[ac] = DT_UNKNOWN;
1198 /*@innerbreak@*/ break;
1201 for (sb = se; sb > s && sb[-1] != ' '; sb--)
1205 t = stpncpy(t, sb, (se - sb));
1207 if (*se == '\n') se++;
1210 /*@switchbreak@*/ break;
1212 /*@switchbreak@*/ break;
1221 static struct dirent * ftpReaddir(DIR * dir)
1222 /*@globals fileSystem @*/
1223 /*@modifies fileSystem @*/
1232 if (dir == NULL || !ISFTPMAGIC(dir) || dir->data == NULL) {
1233 /* XXX TODO: EBADF errno. */
1238 dp = (struct dirent *) dir->data;
1239 av = (const char **) (dp + 1);
1241 dt = (char *) (av + (ac + 1));
1242 i = dir->offset + 1;
1244 if (i < 0 || i >= ac || av[i] == NULL)
1249 /* XXX glob(3) uses REAL_DIR_ENTRY(dp) test on d_ino */
1250 dp->d_ino = i + 1; /* W2DO? */
1251 dp->d_off = 0; /* W2DO? */
1252 dp->d_reclen = 0; /* W2DO? */
1255 strncpy(dp->d_name, av[i], sizeof(dp->d_name));
1258 fprintf(stderr, "*** ftpReaddir(%p) %p \"%s\"\n", (void *)dir, dp, dp->d_name);
1264 static int ftpClosedir(/*@only@*/ DIR * dir)
1265 /*@globals fileSystem @*/
1266 /*@modifies dir, fileSystem @*/
1270 fprintf(stderr, "*** ftpClosedir(%p)\n", (void *)dir);
1271 if (dir == NULL || !ISFTPMAGIC(dir)) {
1272 /* XXX TODO: EBADF errno. */
1281 int Stat(const char * path, struct stat * st)
1284 int ut = urlPath(path, &lpath);
1287 fprintf(stderr, "*** Stat(%s,%p)\n", path, st);
1290 return ftpStat(path, st);
1291 /*@notreached@*/ break;
1292 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
1296 case URL_IS_UNKNOWN:
1301 /*@notreached@*/ break;
1303 return stat(path, st);
1306 int Lstat(const char * path, struct stat * st)
1309 int ut = urlPath(path, &lpath);
1312 fprintf(stderr, "*** Lstat(%s,%p)\n", path, st);
1315 return ftpLstat(path, st);
1316 /*@notreached@*/ break;
1317 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
1321 case URL_IS_UNKNOWN:
1326 /*@notreached@*/ break;
1328 return lstat(path, st);
1331 int Readlink(const char * path, char * buf, size_t bufsiz)
1334 int ut = urlPath(path, &lpath);
1338 return ftpReadlink(path, buf, bufsiz);
1339 /*@notreached@*/ break;
1340 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
1344 case URL_IS_UNKNOWN:
1349 /*@notreached@*/ break;
1351 return readlink(path, buf, bufsiz);
1354 int Access(const char * path, int amode)
1357 int ut = urlPath(path, &lpath);
1360 fprintf(stderr, "*** Access(%s,%d)\n", path, amode);
1362 case URL_IS_FTP: /* XXX WRONG WRONG WRONG */
1363 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
1367 case URL_IS_UNKNOWN:
1372 /*@notreached@*/ break;
1374 return access(path, amode);
1377 int Glob(const char *pattern, int flags,
1378 int errfunc(const char * epath, int eerrno), glob_t *pglob)
1381 int ut = urlPath(pattern, &lpath);
1385 fprintf(stderr, "*** Glob(%s,0x%x,%p,%p)\n", pattern, (unsigned)flags, (void *)errfunc, pglob);
1389 pglob->gl_closedir = Closedir;
1390 pglob->gl_readdir = Readdir;
1391 pglob->gl_opendir = Opendir;
1392 pglob->gl_lstat = Lstat;
1393 pglob->gl_stat = Stat;
1394 flags |= GLOB_ALTDIRFUNC;
1396 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
1400 case URL_IS_UNKNOWN:
1405 /*@notreached@*/ break;
1407 return glob(pattern, flags, errfunc, pglob);
1410 void Globfree(glob_t *pglob)
1413 fprintf(stderr, "*** Globfree(%p)\n", pglob);
1417 DIR * Opendir(const char * path)
1420 int ut = urlPath(path, &lpath);
1423 fprintf(stderr, "*** Opendir(%s)\n", path);
1426 return ftpOpendir(path);
1427 /*@notreached@*/ break;
1428 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
1432 case URL_IS_UNKNOWN:
1437 /*@notreached@*/ break;
1439 /*@-dependenttrans@*/
1440 return opendir(path);
1441 /*@=dependenttrans@*/
1445 struct dirent * Readdir(DIR * dir)
1448 fprintf(stderr, "*** Readdir(%p)\n", (void *)dir);
1449 if (dir == NULL || ISFTPMAGIC(dir))
1450 return ftpReaddir(dir);
1451 return readdir(dir);
1454 int Closedir(DIR * dir)
1457 fprintf(stderr, "*** Closedir(%p)\n", (void *)dir);
1458 if (dir == NULL || ISFTPMAGIC(dir))
1459 return ftpClosedir(dir);
1460 return closedir(dir);