123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659 |
- #include <dirent.h>
- #include <time.h>
- #include "zip.h"
- #include <paru.h> /* parameter definitions */
- #include <sys_calls.h> /* AOS/VS system call interface */
- #include <packets/filestatus.h> /* AOS/VS ?FSTAT packet defs */
- #ifndef UTIL
- #define PAD 0
- #define PATH_END ':'
- typedef union zvsfstat_stru
- {
- P_FSTAT norm_fstat_packet;
- P_FSTAT_DIR dir_fstat_packet;
- P_FSTAT_UNIT unit_fstat_packet;
- P_FSTAT_IPC ipc_fstat_packet;
- } ZVSFSTAT_STRU;
- typedef struct zextrafld
- {
- char extra_header_id[2];
- char extra_data_size[2];
- char extra_sentinel[4];
- unsigned char extra_rev;
- ZVSFSTAT_STRU fstat_packet;
- char aclbuf[$MXACL];
- } ZEXTRAFLD;
- #define ZEXTRA_HEADID "VS"
- #define ZEXTRA_SENTINEL "FCI"
- #define ZEXTRA_REV (unsigned char) 10
- local ZEXTRAFLD zzextrafld;
- local char zlinkres[$MXPL];
- local char znamebuf[$MXPL];
- static char vsnamebuf[$MXPL];
- static char uxnamebuf[FNMAX];
- static P_FSTAT vsfstatbuf;
- local ulg label_time = 0;
- local ulg label_mode = 0;
- local time_t label_utim = 0;
- local char *readd OF((DIR *));
- char *readd(d)
- DIR *d;
- {
- struct dirent *e;
- e = readdir(d);
- return e == NULL ? (char *) NULL : e->d_name;
- }
- int procname(n, caseflag)
- char *n;
- int caseflag;
- {
- char *a;
- DIR *d;
- char *e;
- int m;
- char *p;
- struct stat s;
- struct zlist far *z;
- if (strcmp(n, "-") == 0)
- return newname(n, 0, caseflag);
- else if (LSSTAT(n, &s))
- {
-
- p = ex2in(n, 0, (int *)NULL);
- m = 1;
- for (z = zfiles; z != NULL; z = z->nxt) {
- if (MATCH(p, z->iname, caseflag))
- {
- z->mark = pcount ? filter(z->zname, caseflag) : 1;
- if (verbose)
- fprintf(mesg, "zip diagnostic: %scluding %s\n",
- z->mark ? "in" : "ex", z->name);
- m = 0;
- }
- }
- free((zvoid *)p);
- return m ? ZE_MISS : ZE_OK;
- }
-
- if ((s.st_mode & S_IFDIR) == 0)
- {
-
- if ((m = newname(n, 0, caseflag)) != ZE_OK)
- return m;
- } else {
-
- if ((p = malloc(strlen(n)+2)) == NULL)
- return ZE_MEM;
- if (strcmp(n, ".") == 0) {
- *p = '\0';
- } else {
- strcpy(p, n);
- a = p + strlen(p);
- if (a[-1] != '/')
- strcpy(a, "/");
- if (dirnames && (m = newname(p, 1, caseflag)) != ZE_OK) {
- free((zvoid *)p);
- return m;
- }
- }
-
- if (recurse && (d = opendir(n)) != NULL)
- {
- while ((e = readd(d)) != NULL) {
- if (strcmp(e, ".") && strcmp(e, ".."))
- {
- if ((a = malloc(strlen(p) + strlen(e) + 1)) == NULL)
- {
- closedir(d);
- free((zvoid *)p);
- return ZE_MEM;
- }
- strcat(strcpy(a, p), e);
- if ((m = procname(a, caseflag)) != ZE_OK)
- {
- if (m == ZE_MISS)
- zipwarn("name not matched: ", a);
- else
- ziperr(m, a);
- }
- free((zvoid *)a);
- }
- }
- closedir(d);
- }
- free((zvoid *)p);
- }
- return ZE_OK;
- }
- char *strlower(s)
- char *s;
- {
- char *p;
- for (p = s; *p; p++)
- if (*p >= 'A' && *p <= 'Z')
- *p += 'a' - 'A';
- return s;
- }
- char *strupper(s)
- char *s;
- {
- char *p;
- for (p = s; *p; p++)
- if (*p >= 'a' && *p <= 'z')
- *p -= 'a' - 'A';
- return s;
- }
- char *ex2in(x, isdir, pdosflag)
- char *x;
- int isdir;
- int *pdosflag;
- {
- char *n;
- char *t;
- int dosflag;
- dosflag = dosify;
-
- for (t = x; *t == '/'; t++)
- ;
- if (*t == '=')
- t++;
- else if (*t == ':')
- t++;
- if (!pathput)
- t = last(t, PATH_END);
- if (*t == '^')
- {
- if ((n = malloc(strlen(t) + 3)) == NULL)
- return NULL;
- strcpy(n, "../");
- strcpy(n + 3, t + 1);
- }
- else if (*t == '@')
- {
- if ((n = malloc(strlen(t) + 5)) == NULL)
- return NULL;
- strcpy(n, "/PER/");
- strcpy(n + 5, t + 1);
- }
- else
- {
- if ((n = malloc(strlen(t) + 1)) == NULL)
- return NULL;
- strcpy(n, t);
- }
-
- for (t = n; *t != '\0'; t++)
- if (*t == ':')
- *t = '/';
-
- strupper(n);
- if (dosify)
- msname(n);
-
- if (pdosflag)
- *pdosflag = dosflag;
- return n;
- }
- char *in2ex(n)
- char *n;
- {
- char *x;
- if ((x = malloc(strlen(n) + 1 + PAD)) == NULL)
- return NULL;
- strcpy(x, n);
- return x;
- }
- void stamp(f, d)
- char *f;
- ulg d;
- {
- time_t u[2];
-
- u[0] = u[1] = dos2unixtime(d);
- utime(f, u);
- }
- ulg filetime(f, a, n, t)
- char *f;
- ulg *a;
- long *n;
- iztimes *t;
- {
- struct stat s;
-
- char *name;
- int len = strlen(f);
- if (f == label) {
- if (a != NULL)
- *a = label_mode;
- if (n != NULL)
- *n = -2L;
- if (t != NULL)
- t->atime = t->mtime = t->ctime = label_utim;
- return label_time;
- }
- if ((name = malloc(len + 1)) == NULL) {
- ZIPERR(ZE_MEM, "filetime");
- }
- strcpy(name, f);
- if (name[len - 1] == '/')
- name[len - 1] = '\0';
-
- if (strcmp(f, "-") == 0) {
- if (fstat(fileno(stdin), &s) != 0)
- error("fstat(stdin)");
- } else if (LSSTAT(name, &s) != 0) {
-
- free(name);
- return 0;
- }
- free(name);
- if (a != NULL) {
- *a = ((ulg)s.st_mode << 16) | !(s.st_mode & S_IWRITE);
- if ((s.st_mode & S_IFDIR) != 0) {
- *a |= MSDOS_DIR_ATTR;
- }
- }
- if (n != NULL)
- *n = (s.st_mode & S_IFMT) == S_IFREG ? s.st_size : -1L;
- if (t != NULL) {
- t->atime = s.st_atime;
- t->mtime = s.st_mtime;
- t->ctime = s.st_ctime;
- }
- return unix2dostime(&s.st_ctime);
- }
- int deletedir(d)
- char *d;
- {
- return rmdir(d);
- }
- int set_extra_field(z, z_utim)
- struct zlist far *z;
- iztimes *z_utim;
-
-
- {
- int aclend = 0;
- unsigned short errc;
- z->ext = 0;
- strncpy(znamebuf, z->name, $MXPL);
- znamebuf[$MXPL-1] = '\0';
- if (znamebuf[strlen(znamebuf)-1] == '/')
- znamebuf[strlen(znamebuf)-1] = '\0';
- if (linkput)
- errc = sys_fstat(znamebuf, BIT1, &(zzextrafld.fstat_packet));
- else
- errc = sys_fstat(znamebuf, 0, &(zzextrafld.fstat_packet));
- if (errc)
- {
- fprintf(stderr,
- "\n Warning: can't get ?FSTAT info & acl of %s - error %d\n ",
- znamebuf, errc);
- perror("sys_fstat()");
- }
- else
- {
-
- if (zzextrafld.fstat_packet.norm_fstat_packet.styp_type != $FLNK)
- {
- if ((errc = sys_gacl(znamebuf, zzextrafld.aclbuf)) != 0)
- {
- fprintf(stderr, "\n Warning: can't get acl of %s - error %d\n ",
- z->name, errc);
- perror("sys_gacl()");
- }
- else
- {
-
- while (aclend++ < $MXACL &&
- (zzextrafld.aclbuf[aclend - 1] != '\0' ||
- zzextrafld.aclbuf[aclend] != '\0'))
- ;
- if ((z->cextra = z->extra =
- malloc(sizeof(ZEXTRAFLD) - $MXACL + aclend + 4)) != NULL)
- {
- strncpy(zzextrafld.extra_header_id, ZEXTRA_HEADID,
- sizeof(zzextrafld.extra_header_id));
- strncpy(zzextrafld.extra_sentinel, ZEXTRA_SENTINEL,
- sizeof(zzextrafld.extra_sentinel));
- zzextrafld.extra_rev = ZEXTRA_REV;
-
- errc = (unsigned short) (sizeof(ZEXTRAFLD) - $MXACL + aclend + 4 -
- sizeof(zzextrafld.extra_header_id) -
- sizeof(zzextrafld.extra_data_size));
- zzextrafld.extra_data_size[0] = errc & 0xFF;
- zzextrafld.extra_data_size[1] = errc >> 8;
- memcpy((char *) z->extra, (char *) &zzextrafld,
- sizeof(ZEXTRAFLD) - $MXACL + aclend + 4);
- z->cext = z->ext = sizeof(ZEXTRAFLD) - $MXACL + aclend + 4;
- }
- }
- }
- else
- {
- if ((errc = sys_glink(z->name, zzextrafld.aclbuf)) != 0)
- {
- fprintf(stderr,
- "\n Warning: can't get link-resolution of %s - error %d\n ",
- z->name, errc);
- perror("sys_glink()");
- }
- else
- {
- aclend = strlen(zzextrafld.aclbuf) + 1;
- if ((z->extra = malloc(sizeof(ZEXTRAFLD) - $MXACL + aclend + 4))
- != NULL)
- {
- strncpy(zzextrafld.extra_header_id, ZEXTRA_HEADID,
- sizeof(zzextrafld.extra_header_id));
- strncpy(zzextrafld.extra_sentinel, ZEXTRA_SENTINEL,
- sizeof(zzextrafld.extra_sentinel));
- zzextrafld.extra_rev = ZEXTRA_REV;
-
- errc = (unsigned short) (sizeof(ZEXTRAFLD) - $MXACL + aclend + 4 -
- sizeof(zzextrafld.extra_header_id) -
- sizeof(zzextrafld.extra_data_size));
- zzextrafld.extra_data_size[0] = errc & 0xFF;
- zzextrafld.extra_data_size[1] = errc >> 8;
- memcpy((char *) z->extra, (char *) &zzextrafld,
- sizeof(ZEXTRAFLD) - $MXACL + aclend + 4);
- z->ext = sizeof(ZEXTRAFLD) - $MXACL + aclend + 4;
- }
- }
- }
- }
- return ZE_OK;
- }
- #endif
- void version_local()
- {
- printf("Compiled with %s under %s.\n",
- "a C compiler",
- "AOS/VS"
- );
- }
- int zvs_lstat(char *path, struct stat *buf)
- {
- char *cp_vs = vsnamebuf;
- char *cp_ux = path;
- int mm, dd, yy;
-
- if (!strncmp(cp_ux, "../", 3))
- {
- *cp_vs++ = '^';
- cp_ux += 3;
- }
- else if (!strncmp(cp_ux, "./", 2))
- {
- *cp_vs++ = '=';
- cp_ux += 2;
- }
- do
- {
- if (*cp_ux == '/')
- {
- *cp_vs++ = ':';
- }
- else
- {
- *cp_vs++ = (char) toupper(*cp_ux);
- }
- } while (*cp_ux++ != '\0' && cp_vs - vsnamebuf < sizeof(vsnamebuf));
-
- if (cp_vs - vsnamebuf >= sizeof(vsnamebuf) && *(cp_vs - 1) != '\0')
- return (-1);
-
- if (sys_fstat(vsnamebuf,
- BIT1,
- &vsfstatbuf))
- return (-1);
-
- if (vsfstatbuf.styp_type != $FLNK)
- return (stat(path, buf));
-
- memset((char *) buf, 0, sizeof(*buf));
- buf->st_mode = S_IFLNK | 0777;
- buf->st_uid = -1;
- buf->st_nlink = 1;
-
- if (vsfstatbuf.stch.short_time[0] < 732)
- buf->st_ctime = buf->st_mtime = buf->st_atime = 0L;
- else
- {
- buf->st_ctime = buf->st_mtime = buf->st_atime =
- ((long) vsfstatbuf.stch.short_time[0] - 732L) * 24L * 3600L +
- 2L * (long) vsfstatbuf.stch.short_time[1];
- }
-
- if ((buf->st_size = zvs_readlink(vsnamebuf, uxnamebuf, FNMAX)) < 0)
- return (-1);
- else
- return (0);
- }
- int zvs_readlink(char *path, char *buf, int nbytes)
- {
- char *cp_vs = vsnamebuf;
- char *cp_ux = buf;
-
- if (sys_glink(path, vsnamebuf))
- return (-1);
-
- if (*cp_vs == '^')
- {
- strncpy(cp_ux, "../", 3);
- cp_ux += 3;
- cp_vs++;
- }
- else if (*cp_vs == '@')
- {
- strncpy(cp_ux, "/PER/", 5);
- cp_ux += 5;
- cp_vs++;
- }
- else if (*cp_vs == '=')
- {
- strncpy(cp_ux, "./", 2);
- cp_ux += 2;
- cp_vs++;
- }
- while (*cp_vs != '\0' && cp_ux - buf < nbytes)
- {
- if (*cp_vs == ':')
- {
- *cp_ux++ = '/';
- }
- else
- {
- *cp_ux++ = (char) toupper(*cp_vs);
- }
- cp_vs++;
- }
- return (cp_ux - buf);
- }
|