Intial commit
This commit is contained in:
1
prospero/lib/pcompat/.gitignore
vendored
Normal file
1
prospero/lib/pcompat/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Makefile
|
||||
17
prospero/lib/pcompat/FILES
Normal file
17
prospero/lib/pcompat/FILES
Normal file
@@ -0,0 +1,17 @@
|
||||
FILES
|
||||
Makefile
|
||||
closedir.c
|
||||
creat.c
|
||||
execve.c
|
||||
getvdirent.c
|
||||
open.c
|
||||
opendir.c
|
||||
pcompat_init.c
|
||||
pfs_access.c
|
||||
pfs_default.c
|
||||
pfs_quiet.c
|
||||
readdir.c
|
||||
scandir.c
|
||||
seekdir.c
|
||||
stat.c
|
||||
telldir.c
|
||||
129
prospero/lib/pcompat/Makefile.in
Executable file
129
prospero/lib/pcompat/Makefile.in
Executable file
@@ -0,0 +1,129 @@
|
||||
SOURCEBASE = ../..
|
||||
include $(SOURCEBASE)/Makefile.config
|
||||
|
||||
# There used to be a lib/pcompat/Makefile.pcompat and a separate
|
||||
# lib/pcompat/Makefile.nopcompat.
|
||||
# This is no longer the case.
|
||||
|
||||
CFILES = \
|
||||
closedir.c \
|
||||
creat.c \
|
||||
execve.c \
|
||||
getvdirent.c \
|
||||
open.c \
|
||||
opendir.c \
|
||||
pcompat_init.c \
|
||||
pfs_access.c \
|
||||
pfs_default.c \
|
||||
pfs_quiet.c \
|
||||
readdir.c \
|
||||
scandir.c \
|
||||
seekdir.c \
|
||||
stat.c \
|
||||
telldir.c
|
||||
|
||||
|
||||
OBJECTS = \
|
||||
closedir.o \
|
||||
creat.o \
|
||||
execve.o \
|
||||
getvdirent.o \
|
||||
open.o \
|
||||
opendir.o \
|
||||
pcompat_init.o \
|
||||
pfs_access.o \
|
||||
pfs_default.o \
|
||||
pfs_quiet.o \
|
||||
readdir.o \
|
||||
scandir.o \
|
||||
seekdir.o \
|
||||
stat.o \
|
||||
telldir.o
|
||||
|
||||
all: ${CMP_LIB}
|
||||
|
||||
${CMP_LIB}: ${OBJECTS}
|
||||
rm -f ${CMP_LIB}
|
||||
ar rv ${CMP_LIB} ${OBJECTS}
|
||||
ranlib ${CMP_LIB}
|
||||
|
||||
install:
|
||||
|
||||
# $(INSTALL) -o $(OWNER) -g $(GROUP) ${CMP_LIB} ${P_BINARIES}/${CMP_LIB}
|
||||
# ranlib ${P_BINARIES}/${CMP_LIB}
|
||||
|
||||
|
||||
# Dependencies
|
||||
closedir.o : \
|
||||
../../include/pmachine.h
|
||||
creat.o : \
|
||||
../../include/pfs.h \
|
||||
../../include/pfs_utils.h ../../include/ardp.h ../../include/pfs_threads.h \
|
||||
../../include/list_macros.h \
|
||||
../../include/../lib/ardp/flocks.h ../../include/implicit_fixes.h \
|
||||
../../include/pmachine.h \
|
||||
../../include/pcompat.h
|
||||
execve.o : \
|
||||
../../include/pfs.h \
|
||||
../../include/pfs_utils.h ../../include/ardp.h \
|
||||
../../include/pfs_threads.h \
|
||||
../../include/list_macros.h ../../include/../lib/ardp/flocks.h \
|
||||
../../include/implicit_fixes.h \
|
||||
../../include/pmachine.h \
|
||||
../../include/pcompat.h
|
||||
getvdirent.o : \
|
||||
../../include/pmachine.h \
|
||||
../../include/pfs.h ../../include/pfs_utils.h ../../include/ardp.h \
|
||||
../../include/pfs_threads.h \
|
||||
../../include/list_macros.h ../../include/../lib/ardp/flocks.h \
|
||||
../../include/implicit_fixes.h \
|
||||
../../include/pcompat.h ../../include/perrno.h
|
||||
open.o : \
|
||||
../../include/pfs.h \
|
||||
../../include/pfs_utils.h ../../include/ardp.h ../../include/pfs_threads.h \
|
||||
../../include/list_macros.h ../../include/../lib/ardp/flocks.h \
|
||||
../../include/implicit_fixes.h \
|
||||
../../include/pmachine.h \
|
||||
../../include/pcompat.h \
|
||||
../../include/perrno.h
|
||||
opendir.o : \
|
||||
../../include/pmachine.h
|
||||
pcompat_init.o : ../../include/pcompat.h \
|
||||
../../include/pfs_threads.h \
|
||||
../../include/pfs_utils.h ../../include/pmachine.h \
|
||||
../../include/pfs.h ../../include/ardp.h \
|
||||
../../include/list_macros.h ../../include/../lib/ardp/flocks.h \
|
||||
../../include/implicit_fixes.h
|
||||
pfs_access.o : \
|
||||
../../include/pfs.h \
|
||||
../../include/pfs_utils.h ../../include/ardp.h ../../include/pfs_threads.h \
|
||||
../../include/list_macros.h ../../include/../lib/ardp/flocks.h \
|
||||
../../include/implicit_fixes.h \
|
||||
../../include/pmachine.h \
|
||||
../../include/psite.h ../../include/pcompat.h \
|
||||
../../include/perrno.h
|
||||
pfs_default.o : ../../include/pcompat.h \
|
||||
../../include/pfs_threads.h \
|
||||
../../include/pfs_utils.h ../../include/pmachine.h
|
||||
pfs_quiet.o : ../../include/pcompat.h \
|
||||
../../include/pfs_threads.h \
|
||||
../../include/pfs_utils.h ../../include/pmachine.h
|
||||
readdir.o : \
|
||||
../../include/pmachine.h
|
||||
scandir.o : \
|
||||
../../include/pmachine.h \
|
||||
../../include/pfs_threads.h \
|
||||
../../include/pfs_utils.h
|
||||
seekdir.o : \
|
||||
../../include/pmachine.h
|
||||
stat.o : \
|
||||
../../include/pfs.h ../../include/pfs_utils.h \
|
||||
../../include/ardp.h \
|
||||
../../include/pfs_threads.h \
|
||||
../../include/list_macros.h ../../include/../lib/ardp/flocks.h \
|
||||
../../include/implicit_fixes.h \
|
||||
../../include/pmachine.h \
|
||||
../../include/pcompat.h \
|
||||
../../include/perrno.h
|
||||
telldir.o : \
|
||||
../../include/pmachine.h
|
||||
74
prospero/lib/pcompat/closedir.c
Normal file
74
prospero/lib/pcompat/closedir.c
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Derived from Berkeley source code. Those parts are
|
||||
* Copyright (c) 1983 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that: (1) source distributions retain this entire copyright
|
||||
* notice and comment, and (2) distributions including binaries display
|
||||
* the following acknowledgement: ``This product includes software
|
||||
* developed by the University of California, Berkeley and its contributors''
|
||||
* in the documentation or other materials provided with the distribution
|
||||
* and in all advertising materials mentioning features or use of this
|
||||
* software. Neither the name of the University nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)closedir.c 5.8 (Berkeley) 6/1/90";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <pmachine.h>
|
||||
|
||||
#ifdef USE_SYS_DIR_H
|
||||
#include <sys/dir.h>
|
||||
#else
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* close a directory.
|
||||
*/
|
||||
#ifdef CLOSEDIR_RET_TYPE_VOID
|
||||
void
|
||||
#else
|
||||
int
|
||||
#endif
|
||||
closedir(dirp)
|
||||
register DIR *dirp;
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = dirp->dd_fd;
|
||||
dirp->dd_fd = -1;
|
||||
dirp->dd_loc = 0;
|
||||
(void)free((void *)dirp->dd_buf);
|
||||
(void)free((void *)dirp);
|
||||
if(fd < 0) {
|
||||
if(p__delvdirentries(fd)) {
|
||||
errno = EBADF;
|
||||
#ifdef CLOSEDIR_RET_TYPE_VOID
|
||||
return;
|
||||
#else
|
||||
return(-1);
|
||||
#endif
|
||||
}
|
||||
#ifdef CLOSEDIR_RET_TYPE_VOID
|
||||
return;
|
||||
#else
|
||||
return(0);
|
||||
#endif
|
||||
}
|
||||
#ifdef CLOSEDIR_RET_TYPE_VOID
|
||||
else return;
|
||||
#else
|
||||
else return(close(fd));
|
||||
#endif
|
||||
}
|
||||
48
prospero/lib/pcompat/creat.c
Normal file
48
prospero/lib/pcompat/creat.c
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 1989, 1990, 1991 by the University of Washington
|
||||
* Copyright (c) 1992 by the University of Southern California
|
||||
*
|
||||
* For copying and distribution information, please see the files
|
||||
* <uw-copyright.h> and <usc-copyr.h>.
|
||||
*/
|
||||
|
||||
#include <uw-copyright.h>
|
||||
#include <usc-copyr.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <netdb.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/param.h>
|
||||
#ifdef SOLARIS
|
||||
#include <sys/syscall.h>
|
||||
#else
|
||||
#include <syscall.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
|
||||
#include <pfs.h>
|
||||
#include <pcompat.h>
|
||||
#include <pmachine.h>
|
||||
|
||||
|
||||
/* syscall is not MT-safe (at least under Solaris)
|
||||
#ifndef PFS_THREADS
|
||||
creat(const char *name,
|
||||
#ifdef OPEN_MODE_ARG_IS_INT
|
||||
int mode
|
||||
#else
|
||||
mode_t mode
|
||||
#endif
|
||||
)
|
||||
{
|
||||
char npath[MAXPATHLEN];
|
||||
|
||||
int tmp;
|
||||
|
||||
tmp = pfs_access(name, npath, sizeof npath, PFA_CRMAP);
|
||||
|
||||
if(tmp) return(-1);
|
||||
|
||||
return(syscall(SYS_creat,npath,mode));
|
||||
}
|
||||
#endif /*PFS_THREADS*/
|
||||
39
prospero/lib/pcompat/execve.c
Normal file
39
prospero/lib/pcompat/execve.c
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 1992, 1994 by the University of Southern California
|
||||
*
|
||||
* For copying and distribution information, please see the files
|
||||
* <usc-license.h>
|
||||
*/
|
||||
|
||||
#include <usc-license.h>
|
||||
|
||||
#include <sys/param.h>
|
||||
#ifdef SOLARIS
|
||||
#include <sys/syscall.h>
|
||||
#else
|
||||
#include <syscall.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
#include <pfs.h>
|
||||
#include <pcompat.h>
|
||||
|
||||
|
||||
/* syscall is not MT-safe (at least under Solaris) */
|
||||
#ifndef PFS_THREADS
|
||||
int
|
||||
execve(const char *name, char * const*argv, char * const *envp)
|
||||
{
|
||||
char npath[MAXPATHLEN];
|
||||
|
||||
int tmp;
|
||||
|
||||
tmp = pfs_access(name, npath, sizeof npath, PFA_MAP);
|
||||
|
||||
/* Should figure out what correct error return should be */
|
||||
if(tmp) return(-1);
|
||||
|
||||
return(syscall(SYS_execve,npath,argv,envp));
|
||||
}
|
||||
#endif /*PFS_THREADS*/
|
||||
186
prospero/lib/pcompat/getvdirent.c
Normal file
186
prospero/lib/pcompat/getvdirent.c
Normal file
@@ -0,0 +1,186 @@
|
||||
/*
|
||||
* Copyright (c) 1991-1994 by the University of Southern California
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <usc-license.h>.
|
||||
*/
|
||||
|
||||
#include <usc-license.h>
|
||||
|
||||
|
||||
#include <sys/param.h>
|
||||
|
||||
#define DIRSIZ_MACRO /* needed for HPUX; does no harm otherwise. */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h> /* For malloc or free */
|
||||
|
||||
#include <pmachine.h>
|
||||
/* Needed if not already included. */
|
||||
#ifdef USE_SYS_DIR_H /* Support for SYS_DIR_H may be finally dead.
|
||||
I hope. */
|
||||
#include <sys/dir.h>
|
||||
#else
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
#include <pfs.h>
|
||||
#include <pcompat.h>
|
||||
#include <perrno.h>
|
||||
|
||||
/* Maximum open virtual directories */
|
||||
#define MAX_VDDESC 16
|
||||
|
||||
static struct dirent *dirbuf[MAX_VDDESC + 1] = {NULL};
|
||||
static int dirpos[MAX_VDDESC + 1] = {0};
|
||||
static int dirbsz[MAX_VDDESC + 1] = {0};
|
||||
|
||||
int
|
||||
p__getvdirentries(int fd, char *buf, int nbytes, int *basep)
|
||||
{
|
||||
int bytes = 0;
|
||||
struct dirent *dp;
|
||||
char *bp;
|
||||
|
||||
if(fd > -1) return(0);
|
||||
if(fd < - MAX_VDDESC) return(0);
|
||||
|
||||
dp = (struct dirent *) ((char *)dirbuf[-fd] + dirpos[-fd]);
|
||||
|
||||
while(dp->d_reclen && (dp->d_reclen <= nbytes)) {
|
||||
bcopy(dp,buf,dp->d_reclen);
|
||||
nbytes = nbytes - (unsigned short) dp->d_reclen;
|
||||
buf = buf + (unsigned short) dp->d_reclen;
|
||||
bytes = bytes + (unsigned short) dp->d_reclen;
|
||||
bp = (char *) dp;bp += dp->d_reclen;dp = (struct dirent *) bp;
|
||||
}
|
||||
|
||||
*basep = dirpos[-fd];
|
||||
dirpos[-fd] = dirpos[-fd] + bytes;
|
||||
return(bytes);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
p__readvdirentries(char *dirname)
|
||||
{
|
||||
VDIR_ST dir_st;
|
||||
VDIR dir= &dir_st;
|
||||
VLINK l;
|
||||
|
||||
long dsize = 0;
|
||||
int dirnum = 0;
|
||||
struct dirent *dp;
|
||||
int tmp;
|
||||
|
||||
vdir_init(dir);
|
||||
|
||||
check_pfs_default();
|
||||
|
||||
/* If disabled, do no mapping */
|
||||
if(pfs_enable == PMAP_DISABLE) return(PSUCCESS);
|
||||
|
||||
/* This is a kludge. We should not be modifying the */
|
||||
/* path arg, but... */
|
||||
if(pfs_enable == PMAP_ATSIGN) {
|
||||
if(*dirname == '@') {
|
||||
strcpy(dirname,dirname+1);
|
||||
return(PSUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
if(pfs_enable == PMAP_COLON) {
|
||||
if(*dirname == ':') dirname++;
|
||||
else return(PSUCCESS);
|
||||
}
|
||||
|
||||
p__compat_initialize();
|
||||
tmp = rd_vdir(dirname,0,dir,RVD_LREMEXP);
|
||||
|
||||
if(tmp) return(tmp);
|
||||
|
||||
l = dir->links;
|
||||
|
||||
while(l) {
|
||||
/* The next statement should track the DIRSIZ macro */
|
||||
dsize = dsize + (sizeof(struct dirent) - (MAXNAMLEN+1)) +
|
||||
((strlen(l->name)+1 +3) & ~3);
|
||||
|
||||
l = l->next;
|
||||
}
|
||||
|
||||
/* This is just in case */
|
||||
dsize = dsize + 256;
|
||||
|
||||
dirnum = 0;
|
||||
while(dirnum++ <= MAX_VDDESC) {
|
||||
if(!dirbuf[dirnum]) break;
|
||||
}
|
||||
if(dirnum > MAX_VDDESC) RETURNPFAILURE;
|
||||
|
||||
dp = (struct dirent *) malloc(dsize);
|
||||
dirbuf[dirnum] = dp;
|
||||
dirpos[dirnum] = 0;
|
||||
dirbsz[dirnum] = dsize;
|
||||
|
||||
l = dir->links;
|
||||
|
||||
while(l) {
|
||||
dp->d_ino = (unsigned long) 999;
|
||||
#if !defined (SOLARIS)
|
||||
dp->d_namlen = (unsigned short) strlen(l->name);
|
||||
#endif
|
||||
dp->d_reclen = (unsigned short) DIRSIZ(dp);
|
||||
strcpy(dp->d_name,l->name);
|
||||
dp = (struct dirent *) ((char *) dp + dp->d_reclen);
|
||||
l = l->next;
|
||||
}
|
||||
|
||||
dp->d_ino = (unsigned long) 0;
|
||||
dp->d_reclen = (unsigned short) 0;
|
||||
#if !defined (SOLARIS)
|
||||
dp->d_namlen = (unsigned short) 0;
|
||||
#endif
|
||||
*(dp->d_name) = '\0';
|
||||
|
||||
vllfree(dir->links);
|
||||
vllfree(dir->ulinks);
|
||||
|
||||
return(-dirnum);
|
||||
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
p__delvdirentries(int desc)
|
||||
{
|
||||
if(desc > -1) RETURNPFAILURE;
|
||||
if(desc < - MAX_VDDESC) RETURNPFAILURE;
|
||||
|
||||
if(dirbuf[- desc]) {
|
||||
free(dirbuf[- desc]);
|
||||
dirbuf[- desc] = NULL;
|
||||
return(PSUCCESS);
|
||||
}
|
||||
RETURNPFAILURE;
|
||||
}
|
||||
|
||||
int
|
||||
p__seekvdir(int desc, int pos)
|
||||
{
|
||||
if(desc > -1) RETURNPFAILURE;
|
||||
if(desc < - MAX_VDDESC) RETURNPFAILURE;
|
||||
if(!dirbuf[- desc]) RETURNPFAILURE;
|
||||
dirpos[-desc] = pos;
|
||||
return(PSUCCESS);
|
||||
}
|
||||
|
||||
int
|
||||
p__getvdbsize(int desc, int pos)
|
||||
{
|
||||
if(desc > -1) RETURNPFAILURE;
|
||||
if(desc < - MAX_VDDESC) RETURNPFAILURE;
|
||||
if(!dirbuf[- desc]) RETURNPFAILURE;
|
||||
return(dirbsz[-desc]);
|
||||
}
|
||||
|
||||
87
prospero/lib/pcompat/open.c
Normal file
87
prospero/lib/pcompat/open.c
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 1992,1994 by the University of Southern California
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <usc-license.h>.
|
||||
*/
|
||||
|
||||
#include <usc-license.h>
|
||||
|
||||
/* Originally written by Cliff Neuman, 1989
|
||||
Modified by Steven Augart, 1992, 1994
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <netdb.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/param.h>
|
||||
#ifdef SOLARIS
|
||||
#include <sys/syscall.h>
|
||||
#else
|
||||
#include <syscall.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
|
||||
#include <pfs.h>
|
||||
#include <pcompat.h>
|
||||
#include <perrno.h>
|
||||
#include <pmachine.h>
|
||||
|
||||
extern int pfs_quiet;
|
||||
|
||||
/* HPUX prototype: extern int open(const char *, int, ...);
|
||||
SunOS prototype: int open() */
|
||||
|
||||
int
|
||||
#ifndef PROTOTYPE_FOR_OPEN_HAS_EMPTY_ARGLIST
|
||||
open(const char *path, int flags, ...)
|
||||
{
|
||||
va_list ap;
|
||||
#ifdef OPEN_MODE_ARG_IS_INT
|
||||
int mode;
|
||||
#else
|
||||
mode_t mode;
|
||||
#endif
|
||||
#else
|
||||
open(path, flags, mode)
|
||||
char *path;
|
||||
int flags;
|
||||
#ifdef OPEN_MODE_ARG_IS_INT
|
||||
int mode;
|
||||
#else
|
||||
mode_t mode;
|
||||
#endif
|
||||
{
|
||||
#endif
|
||||
char npath[MAXPATHLEN];
|
||||
|
||||
int pfaflags;
|
||||
int tmp;
|
||||
int open_return;
|
||||
|
||||
#ifndef PROTOTYPE_FOR_OPEN_HAS_EMPTY_ARGLIST
|
||||
va_start(ap, flags);
|
||||
#ifdef OPEN_MODE_ARG_IS_INT
|
||||
mode = va_arg(ap, int);
|
||||
#else
|
||||
mode = va_arg(ap, mode_t);
|
||||
#endif
|
||||
#endif
|
||||
if(flags & O_CREAT) pfaflags = PFA_CRMAP;
|
||||
else pfaflags = PFA_MAP;
|
||||
if((flags & (O_ACCMODE)) == O_RDONLY) pfaflags |= PFA_RO;
|
||||
|
||||
tmp = pfs_access(path,npath, sizeof npath, pfaflags);
|
||||
|
||||
if(tmp && (tmp != PMC_DELETE_ON_CLOSE)) {
|
||||
if(!pfs_quiet) printf("open failed: %s\n",p_err_text[tmp]);
|
||||
errno = ENOENT;
|
||||
return(-1);
|
||||
}
|
||||
|
||||
open_return = syscall(SYS_open,npath,flags,mode);
|
||||
if(tmp == PMC_DELETE_ON_CLOSE) unlink(npath);
|
||||
|
||||
return(open_return);
|
||||
}
|
||||
105
prospero/lib/pcompat/opendir.c
Normal file
105
prospero/lib/pcompat/opendir.c
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Derived from Berkeley source code. Those parts are
|
||||
* Copyright (c) 1983 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that: (1) source distributions retain this entire copyright
|
||||
* notice and comment, and (2) distributions including binaries display
|
||||
* the following acknowledgement: ``This product includes software
|
||||
* developed by the University of California, Berkeley and its contributors''
|
||||
* in the documentation or other materials provided with the distribution
|
||||
* and in all advertising materials mentioning features or use of this
|
||||
* software. Neither the name of the University nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)opendir.c 5.10 (Berkeley) 6/1/90";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <pmachine.h>
|
||||
|
||||
#ifdef USE_SYS_DIR_H
|
||||
#include <sys/dir.h>
|
||||
#else
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
#if defined(AIX) && defined(__GNUC__) /* lucb */
|
||||
#define dd_bsize dd_size
|
||||
#endif
|
||||
|
||||
#ifndef DIRBLKSIZ
|
||||
#define DIRBLKSIZ 512
|
||||
#endif
|
||||
|
||||
#include <stdlib.h> /* For malloc */
|
||||
long _rewinddir;
|
||||
|
||||
/*
|
||||
* open a directory.
|
||||
*/
|
||||
DIR *
|
||||
opendir(const char *name)
|
||||
{
|
||||
register DIR *dirp;
|
||||
register int fd;
|
||||
|
||||
fd = p__readvdirentries(name);
|
||||
|
||||
if(fd > 0) {
|
||||
errno = ENOENT;
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
if(fd == 0) {
|
||||
if ((fd = open(name, 0, 0)) == -1)
|
||||
return NULL;
|
||||
if (fcntl(fd, F_SETFD, 1) == -1) {
|
||||
close (fd);
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
if((dirp = (DIR *)malloc(sizeof(DIR))) == NULL) return(NULL);
|
||||
|
||||
/*
|
||||
* If CLSIZE is an exact multiple of DIRBLKSIZ, use a CLSIZE
|
||||
* buffer that it cluster boundary aligned.
|
||||
* Hopefully this can be a big win someday by allowing page trades
|
||||
* to user space to be done by getdirentries()
|
||||
*/
|
||||
#ifdef CLSIZE
|
||||
if ((CLSIZE % DIRBLKSIZ) == 0) {
|
||||
dirp->dd_buf = malloc(CLSIZE);
|
||||
dirp->dd_bsize = CLSIZE;
|
||||
} else {
|
||||
#endif
|
||||
dirp->dd_buf = malloc(DIRBLKSIZ);
|
||||
dirp->dd_bsize = DIRBLKSIZ;
|
||||
#ifdef CLSIZE
|
||||
}
|
||||
#endif
|
||||
if (dirp->dd_buf == NULL) {
|
||||
close (fd);
|
||||
return NULL;
|
||||
}
|
||||
dirp->dd_fd = fd;
|
||||
dirp->dd_loc = 0;
|
||||
#ifdef SUNOS /* lucb */
|
||||
dirp->dd_bbase = 0;
|
||||
#endif
|
||||
/*
|
||||
* Set up seek point for rewinddir.
|
||||
*/
|
||||
_rewinddir = telldir(dirp);
|
||||
return dirp;
|
||||
}
|
||||
29
prospero/lib/pcompat/pcompat_init.c
Normal file
29
prospero/lib/pcompat/pcompat_init.c
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 1994 by the University of Southern California
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <usc-license.h>.
|
||||
*/
|
||||
|
||||
#include <usc-license.h>
|
||||
|
||||
#include <pcompat.h> /* prototype for p__compat_initialize() */
|
||||
#include <pfs.h> /* prototype for p_initialize() */
|
||||
|
||||
/* Author: Steven Seger Augart, Mar. 30, 1994 */
|
||||
/* This file contains automatic initialization routines for the PCOMPAT
|
||||
library. No Prospero functions should be called before p_initialize() has
|
||||
been called. This makes the pcompat library self-initializing. */
|
||||
|
||||
/* This function can be safely called more than once. */
|
||||
|
||||
static int initialized = 0;
|
||||
|
||||
void
|
||||
p__compat_initialize(void)
|
||||
{
|
||||
if (!initialized) {
|
||||
++initialized;
|
||||
p_initialize("uclP", 0, (struct p_initialize_st *) NULL);
|
||||
}
|
||||
}
|
||||
110
prospero/lib/pcompat/pfs_access.c
Normal file
110
prospero/lib/pcompat/pfs_access.c
Normal file
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright (c) 1989, 1990, 1991 by the University of Washington
|
||||
* Copyright (c) 1992 by the University of Southern California
|
||||
*
|
||||
* For copying and distribution information, please see the files
|
||||
* <uw-copyright.h> and <usc-copyr.h>.
|
||||
*/
|
||||
|
||||
#include <uw-copyright.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/param.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <pfs.h>
|
||||
#include <psite.h>
|
||||
#include <pcompat.h>
|
||||
#include <pmachine.h>
|
||||
#include <perrno.h>
|
||||
|
||||
/*
|
||||
* see pcompat.h for the meanings of the flage
|
||||
*/
|
||||
int
|
||||
pfs_access(const char *path, char *npath, int npathlen, int flags)
|
||||
{
|
||||
|
||||
char cpath[MAXPATHLEN];
|
||||
char *prefix;
|
||||
char *suffix;
|
||||
VLINK vl;
|
||||
int tmp;
|
||||
|
||||
suffix = "";
|
||||
|
||||
check_pfs_default();
|
||||
|
||||
errno = 0;
|
||||
|
||||
/* If disabled, do no mapping */
|
||||
if(pfs_enable == PMAP_DISABLE) {
|
||||
strcpy(npath,path);
|
||||
return(PSUCCESS);
|
||||
}
|
||||
|
||||
if(pfs_enable == PMAP_COLON) {
|
||||
if(*path == ':') path++;
|
||||
else if(index(path,':'));
|
||||
else {strcpy(npath,path); return(PSUCCESS);}
|
||||
}
|
||||
|
||||
if((pfs_enable == PMAP_ATSIGN_NF) || (pfs_enable == PMAP_ATSIGN)) {
|
||||
if(*path == '@') {
|
||||
path++;
|
||||
strcpy(npath,path);
|
||||
return(PSUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
p__compat_initialize();
|
||||
/* I should probably choose better values for errno */
|
||||
vl = rd_vlink(path);
|
||||
if((perrno || !vl) && ((flags == PFA_CRMAP)||(flags == PFA_CREATE))) {
|
||||
strcpy(cpath,path);
|
||||
prefix = cpath;
|
||||
suffix = strrchr(cpath,'/');
|
||||
if(suffix) {
|
||||
if(suffix == prefix) prefix = "/";
|
||||
*(suffix++) = '\0';
|
||||
vl = rd_vlink(prefix);
|
||||
if(vl) {
|
||||
sprintf(cpath,"%s/%s",vl->hsoname,suffix);
|
||||
vl->hsoname = stcopyr(cpath,vl->hsoname);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* If not found, but PMAP_ATSIGN_NF, then check if a real file */
|
||||
if(((perrno == PFS_DIR_NOT_FOUND) || (perrno == RVD_DIR_NOT_THERE) ||
|
||||
(!perrno && !vl)) &&
|
||||
(pfs_enable == PMAP_ATSIGN_NF) &&
|
||||
(*path == '/') && ((strncmp(path,"/tmp",4) == 0) ||
|
||||
((flags != PFA_CRMAP) && (flags != PFA_CREATE)))) {
|
||||
strcpy(npath,path);
|
||||
return(PSUCCESS);
|
||||
}
|
||||
|
||||
if(perrno) {errno = ENOENT;return(perrno);}
|
||||
if(!vl) {errno = ENOENT;return(PFS_FILE_NOT_FOUND);}
|
||||
|
||||
#ifdef PCOMPAT_SUPPORT_FTP
|
||||
/* P_AM_FTP requires prompting for a password, which is not something
|
||||
transparent to the user. That's why without the special
|
||||
PCOMPAT_SUPPORT_FTP definition, mapname isn't called with the
|
||||
MAP_PROMPT_OK option. */
|
||||
tmp = mapname(vl,npath, npathlen,
|
||||
MAP_PROMPT_OK | ((flags & PFA_RO) ?
|
||||
MAP_READONLY : MAP_READWRITE));
|
||||
#else
|
||||
tmp = mapname(vl,npath, npathlen, ((flags & PFA_RO) ?
|
||||
MAP_READONLY : MAP_READWRITE));
|
||||
#endif
|
||||
vllfree(vl);
|
||||
if(tmp && (tmp != PMC_DELETE_ON_CLOSE)) errno = ENOENT;
|
||||
return(tmp);
|
||||
}
|
||||
|
||||
39
prospero/lib/pcompat/pfs_default.c
Normal file
39
prospero/lib/pcompat/pfs_default.c
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 1993 by the University of Southern California
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <usc-license.h>
|
||||
*/
|
||||
|
||||
#include <usc-license.h>
|
||||
|
||||
#include <pcompat.h>
|
||||
|
||||
int pfs_default = -1;
|
||||
|
||||
char *getenv();
|
||||
|
||||
extern int pfs_debug;
|
||||
|
||||
void
|
||||
p__get_pfs_default(void)
|
||||
{
|
||||
char *pfs_default_string;
|
||||
char *pfs_debug_string;
|
||||
|
||||
/* if pfs_disable_flag is set to disable, skip as there */
|
||||
/* is probably a reason for it */
|
||||
if(pfs_enable == PMAP_DISABLE) return;
|
||||
|
||||
/* Check PFS_DEFAULT and if set, set pfs_disable_flag */
|
||||
if(pfs_default == -1) {
|
||||
pfs_default_string = getenv("PFS_DEFAULT");
|
||||
if(pfs_default_string == 0) pfs_default = -2;
|
||||
else if(sscanf(pfs_default_string,"%d",&pfs_default) != 1)
|
||||
pfs_default = -2;
|
||||
else pfs_enable = pfs_default;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
28
prospero/lib/pcompat/pfs_quiet.c
Normal file
28
prospero/lib/pcompat/pfs_quiet.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 1994 by the University of Southern California
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <usc-license.h>.
|
||||
*/
|
||||
|
||||
#include <usc-license.h>
|
||||
|
||||
#include <pcompat.h>
|
||||
|
||||
|
||||
/* Written: Cliff Neuman, 1989, 1991. */
|
||||
/* Updated documentation and declarations: swa@ISI.EDU, 1994. */
|
||||
|
||||
/*
|
||||
* pfs_quiet - Printing of error messages on prospero failure
|
||||
*
|
||||
* This file initializes pfs_quiet to 0. It is included
|
||||
* the pcompat library library in case it is left out
|
||||
* by an application. A value of 0 means that open and
|
||||
* other redefined system calls will print an error
|
||||
* message on the standard error stream before returning
|
||||
* if an error was detected by Prospero.
|
||||
*
|
||||
*/
|
||||
|
||||
int pfs_quiet = 0;
|
||||
77
prospero/lib/pcompat/readdir.c
Normal file
77
prospero/lib/pcompat/readdir.c
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Derived from Berkeley source code. Those parts are
|
||||
* Copyright (c) 1983 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that: (1) source distributions retain this entire copyright
|
||||
* notice and comment, and (2) distributions including binaries display
|
||||
* the following acknowledgement: ``This product includes software
|
||||
* developed by the University of California, Berkeley and its contributors''
|
||||
* in the documentation or other materials provided with the distribution
|
||||
* and in all advertising materials mentioning features or use of this
|
||||
* software. Neither the name of the University nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)readdir.c 5.7 (Berkeley) 6/1/90";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <pmachine.h>
|
||||
|
||||
#ifdef USE_SYS_DIR_H
|
||||
#include <sys/dir.h>
|
||||
#else
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* get next entry in a directory.
|
||||
*/
|
||||
struct dirent *
|
||||
readdir(dirp)
|
||||
register DIR *dirp;
|
||||
{
|
||||
register struct dirent *dp;
|
||||
|
||||
for (;;) {
|
||||
if (dirp->dd_loc == 0) {
|
||||
if(dirp->dd_fd >= 0)
|
||||
#if defined(SUNOS)
|
||||
dirp->dd_size = getdents(dirp->dd_fd,
|
||||
dirp->dd_buf, dirp->dd_bsize);
|
||||
#else
|
||||
dirp->dd_size = getdirentries(dirp->dd_fd,
|
||||
dirp->dd_buf, dirp->dd_bsize, &dirp->dd_bbase);
|
||||
#endif
|
||||
else
|
||||
dirp->dd_size = p__getvdirentries(dirp->dd_fd,
|
||||
dirp->dd_buf, dirp->dd_bsize, &dirp->dd_bbase);
|
||||
if (dirp->dd_size <= 0)
|
||||
return NULL;
|
||||
}
|
||||
if (dirp->dd_loc >= dirp->dd_size) {
|
||||
dirp->dd_loc = 0;
|
||||
continue;
|
||||
}
|
||||
dp = (struct dirent *)(dirp->dd_buf + dirp->dd_loc);
|
||||
if ((int)dp & 03) /* bogus pointer check */
|
||||
return NULL;
|
||||
#if defined(SUNOS)
|
||||
dirp->dd_bbase = dp->d_off;
|
||||
#endif
|
||||
if (dp->d_reclen <= 0 ||
|
||||
dp->d_reclen > dirp->dd_bsize + 1 - dirp->dd_loc)
|
||||
return NULL;
|
||||
dirp->dd_loc += dp->d_reclen;
|
||||
if (dp->d_ino == 0)
|
||||
continue;
|
||||
return (dp);
|
||||
}
|
||||
}
|
||||
142
prospero/lib/pcompat/scandir.c
Normal file
142
prospero/lib/pcompat/scandir.c
Normal file
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* Copyright (c) 1983 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted provided
|
||||
* that: (1) source distributions retain this entire copyright notice and
|
||||
* comment, and (2) distributions including binaries display the following
|
||||
* acknowledgement: ``This product includes software developed by the
|
||||
* University of California, Berkeley and its contributors'' in the
|
||||
* documentation or other materials provided with the distribution and in
|
||||
* all advertising materials mentioning features or use of this software.
|
||||
* Neither the name of the University nor the names of its contributors may
|
||||
* be used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)scandir.c 5.9 (Berkeley) 6/24/90";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
/*
|
||||
* Scan the directory dirname calling select to make a list of selected
|
||||
* directory entries then sort using qsort and compare routine dcomp.
|
||||
* Returns the number of entries and a pointer to a list of pointers to
|
||||
* struct dirent (through namelist). Returns -1 if there were any errors.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdlib.h> /* For malloc and free */
|
||||
|
||||
#include <pmachine.h>
|
||||
|
||||
#ifdef USE_SYS_DIR_H
|
||||
#include <sys/dir.h>
|
||||
#else
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
#include <pfs_threads.h> /* For PFS_THREADS */
|
||||
/*
|
||||
* The DIRSIZ macro gives the minimum record length which will hold
|
||||
* the directory entry. This requires the amount of space in struct dirent
|
||||
* without the d_name field, plus enough space for the name with a terminating
|
||||
* null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
|
||||
*/
|
||||
#undef DIRSIZ
|
||||
#define DIRSIZ(dp) \
|
||||
((sizeof (struct dirent) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
|
||||
|
||||
int
|
||||
scandir(const char *dirname, struct dirent ***namelist,
|
||||
int (*select)(const struct dirent *),
|
||||
int (*dcomp)(const struct dirent **, const struct dirent **))
|
||||
{
|
||||
register struct dirent *d, *p, **names;
|
||||
register int nitems;
|
||||
struct stat stb;
|
||||
long arraysz;
|
||||
DIR *dirp;
|
||||
/* The next variable shuts up GCC thinking that dcomp is of a different
|
||||
type from int (*)() */
|
||||
int (*dcomp_qsort_losing_prototype)() = (int (*)()) dcomp;
|
||||
|
||||
#ifdef PFS_THREADS
|
||||
struct {
|
||||
struct dirent a;
|
||||
char b[_POSIX_PATH_MAX];
|
||||
} readdir_result_st;
|
||||
struct dirent *readdir_result = (struct dirent *) &readdir_result_st;
|
||||
#endif
|
||||
if ((dirp = opendir(dirname)) == NULL) {
|
||||
return(-1);
|
||||
}
|
||||
if (fstat(dirp->dd_fd, &stb) < 0) {
|
||||
closedir(dirp);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* estimate the array size by taking the size of the directory file
|
||||
* and dividing it by a multiple of the minimum size entry.
|
||||
*/
|
||||
arraysz = (stb.st_size / 24);
|
||||
names = (struct dirent **)malloc(arraysz * sizeof(struct dirent *));
|
||||
if (names == NULL)
|
||||
return(-1);
|
||||
|
||||
nitems = 0;
|
||||
assert(P_IS_THIS_THREAD_MASTER()); /*SOLARIS: readdir is MT-Unsafe */
|
||||
|
||||
#ifdef PFS_THREADS
|
||||
while ((d = readdir_r(dirp,readdir_result)) != NULL) {
|
||||
#else
|
||||
while ((d = readdir(dirp)) != NULL) {
|
||||
#endif
|
||||
if (select != NULL && !(*select)(d))
|
||||
continue; /* just selected names */
|
||||
/*
|
||||
* Make a minimum size copy of the data
|
||||
*/
|
||||
p = (struct dirent *)malloc(DIRSIZ(d));
|
||||
if (p == NULL)
|
||||
return(-1);
|
||||
p->d_ino = d->d_ino;
|
||||
p->d_reclen = d->d_reclen;
|
||||
p->d_namlen = d->d_namlen;
|
||||
bcopy(d->d_name, p->d_name, p->d_namlen + 1);
|
||||
/*
|
||||
* Check to make sure the array has space left and
|
||||
* realloc the maximum size.
|
||||
*/
|
||||
if (++nitems >= arraysz) {
|
||||
if (fstat(dirp->dd_fd, &stb) < 0)
|
||||
return(-1); /* just might have grown */
|
||||
arraysz = stb.st_size / 12;
|
||||
names = (struct dirent **)realloc((char *)names,
|
||||
arraysz * sizeof(struct dirent *));
|
||||
if (names == NULL)
|
||||
return(-1);
|
||||
}
|
||||
names[nitems-1] = p;
|
||||
}
|
||||
closedir(dirp);
|
||||
if (nitems && dcomp != NULL)
|
||||
qsort(names, nitems, sizeof(struct dirent *),
|
||||
dcomp_qsort_losing_prototype);
|
||||
*namelist = names;
|
||||
return(nitems);
|
||||
}
|
||||
|
||||
/*
|
||||
* Alphabetic order comparison routine for those who want it.
|
||||
*/
|
||||
int
|
||||
alphasort(const struct dirent **d1, const struct dirent **d2)
|
||||
{
|
||||
return strcmp((*d1)->d_name, (*d2)->d_name);
|
||||
}
|
||||
42
prospero/lib/pcompat/seekdir.c
Normal file
42
prospero/lib/pcompat/seekdir.c
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 1983 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that: (1) source distributions retain this entire copyright
|
||||
* notice and comment, and (2) distributions including binaries display
|
||||
* the following acknowledgement: ``This product includes software
|
||||
* developed by the University of California, Berkeley and its contributors''
|
||||
* in the documentation or other materials provided with the distribution
|
||||
* and in all advertising materials mentioning features or use of this
|
||||
* software. Neither the name of the University nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)seekdir.c 5.7 (Berkeley) 6/1/90";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <pmachine.h>
|
||||
|
||||
#ifdef USE_SYS_DIR_H
|
||||
#include <sys/dir.h>
|
||||
#else
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Seek to an entry in a directory.
|
||||
* p__seekdir is in telldir.c so that it can share opaque data structures.
|
||||
*/
|
||||
void
|
||||
seekdir(DIR *dirp, long loc)
|
||||
{
|
||||
|
||||
p__seekdir(dirp, loc);
|
||||
}
|
||||
136
prospero/lib/pcompat/stat.c
Normal file
136
prospero/lib/pcompat/stat.c
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Copyright (c) 1993, 1994 by the University of Southern California
|
||||
*
|
||||
* For copying and distribution information, please see the files
|
||||
* <usc-license.h>
|
||||
*/
|
||||
|
||||
#include <usc-license.h>
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#ifdef SOLARIS
|
||||
#include <sys/syscall.h>
|
||||
#else
|
||||
#include <syscall.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
|
||||
#include <pfs.h>
|
||||
#include <pcompat.h>
|
||||
#include <pmachine.h> /* for bzero */
|
||||
#include <perrno.h> /* for testing against errors returned by
|
||||
prospero subfunctions. */
|
||||
|
||||
static int stat_l(const char *path, struct stat *buf, int lflag);
|
||||
|
||||
/* syscall is not MT-safe (at least under Solaris) */
|
||||
#ifndef PFS_THREADS
|
||||
/* Call stat_l indicating normal stat */
|
||||
int
|
||||
stat(const char *path, struct stat *buf)
|
||||
{
|
||||
return(stat_l(path,buf,0));
|
||||
}
|
||||
|
||||
|
||||
/* Call stat_l indicating lstat */
|
||||
int
|
||||
lstat(const char *path, struct stat *buf)
|
||||
{
|
||||
return(stat_l(path,buf,1));
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
stat_l(const char *path, struct stat *buf, int lflag)
|
||||
{
|
||||
VDIR_ST dir_st;
|
||||
VDIR dir= &dir_st;
|
||||
PATTRIB ap,nextap;
|
||||
int tmp;
|
||||
|
||||
vdir_init(dir);
|
||||
check_pfs_default();
|
||||
|
||||
/* If disabled, make system call */
|
||||
if(pfs_enable == PMAP_DISABLE) {
|
||||
return(syscall((lflag ? SYS_lstat : SYS_stat), path, buf));
|
||||
}
|
||||
|
||||
if(pfs_enable == PMAP_COLON) {
|
||||
if(*path == ':') path++;
|
||||
else if(index(path,':'));
|
||||
else return(syscall((lflag ? SYS_lstat : SYS_stat), path, buf));
|
||||
}
|
||||
|
||||
if((pfs_enable == PMAP_ATSIGN_NF) || (pfs_enable == PMAP_ATSIGN)) {
|
||||
if(*path == '@') {
|
||||
path++;
|
||||
return(syscall((lflag ? SYS_lstat : SYS_stat), path, buf));
|
||||
}
|
||||
}
|
||||
|
||||
bzero(buf,sizeof(struct stat));
|
||||
buf->st_uid = (uid_t) -1;
|
||||
buf->st_gid = (gid_t) -1;
|
||||
|
||||
p__compat_initialize();
|
||||
/* I should probably choose better values for errno */
|
||||
tmp = rd_vdir(path,0,dir,RVD_DFILE_ONLY|RVD_ATTRIB);
|
||||
if((dir->links == NULL) || (tmp && (tmp != DIRSRV_NOT_DIRECTORY))) {
|
||||
|
||||
if(((tmp == PFS_DIR_NOT_FOUND)||(tmp == RVD_DIR_NOT_THERE)|| !tmp)&&
|
||||
(pfs_enable == PMAP_ATSIGN_NF) && (*path == '/')) {
|
||||
return(syscall((lflag ? SYS_lstat : SYS_stat), path, buf));
|
||||
}
|
||||
errno = ENOENT;
|
||||
return(-1);
|
||||
}
|
||||
|
||||
if(tmp == 0) buf->st_mode |= (S_IFDIR | 0555);
|
||||
else buf->st_mode |= 0444;
|
||||
|
||||
if(strncmp(dir->links->target,"EXTERNAL",8) == 0) ap = NULL;
|
||||
else ap = pget_at(dir->links,"#ALL");
|
||||
|
||||
/* If can't get real attributes, try those stored with link */
|
||||
if((ap == NULL) && dir->links->lattrib) {
|
||||
ap = dir->links->lattrib;
|
||||
dir->links->lattrib = NULL;
|
||||
}
|
||||
|
||||
while(ap) {
|
||||
switch (*(ap->aname)) {
|
||||
case 'L':
|
||||
if((strcmp(ap->aname,"LAST-MODIFIED") == 0) &&
|
||||
ap->avtype == ATR_SEQUENCE ) {
|
||||
buf->st_mtime = asntotime(ap->value.sequence->token);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
if((strcmp(ap->aname,"SIZE") == 0) &&
|
||||
ap->avtype == ATR_SEQUENCE) {
|
||||
int size;
|
||||
qsscanf(ap->value.sequence->token,"%d",&size);
|
||||
buf->st_size = size;
|
||||
/* The following is a good guess at number of blocks */
|
||||
buf->st_blocks = (size+511) / 512;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
nextap = ap->next;
|
||||
atfree(ap);
|
||||
ap = nextap;
|
||||
}
|
||||
vllfree(dir->links);
|
||||
vllfree(dir->ulinks);
|
||||
return(0);
|
||||
}
|
||||
#endif /*PFS_THREADS*/
|
||||
129
prospero/lib/pcompat/telldir.c
Normal file
129
prospero/lib/pcompat/telldir.c
Normal file
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Derived from Berkeley source code. Those parts are
|
||||
* Copyright (c) 1983 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that: (1) source distributions retain this entire copyright
|
||||
* notice and comment, and (2) distributions including binaries display
|
||||
* the following acknowledgement: ``This product includes software
|
||||
* developed by the University of California, Berkeley and its contributors''
|
||||
* in the documentation or other materials provided with the distribution
|
||||
* and in all advertising materials mentioning features or use of this
|
||||
* software. Neither the name of the University nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)telldir.c 5.8 (Berkeley) 6/1/90";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <pmachine.h>
|
||||
#include <stdlib.h> /* For malloc and free */
|
||||
|
||||
#ifdef USE_SYS_DIR_H
|
||||
#include <sys/dir.h>
|
||||
#else
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
#if defined(AIX) && defined(__GNUC__) /* lucb */
|
||||
#define dd_bsize dd_size
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The option SINGLEUSE may be defined to say that a telldir
|
||||
* cookie may be used only once before it is freed. This option
|
||||
* is used to avoid having memory usage grow without bound.
|
||||
*/
|
||||
#define SINGLEUSE
|
||||
|
||||
/*
|
||||
* One of these structures is malloced to describe the current directory
|
||||
* position each time telldir is called. It records the current magic
|
||||
* cookie returned by getdirentries and the offset within the buffer
|
||||
* associated with that return value.
|
||||
*/
|
||||
struct ddloc {
|
||||
struct ddloc *loc_next;/* next structure in list */
|
||||
long loc_index; /* key associated with structure */
|
||||
long loc_seek; /* magic cookie returned by getdirentries */
|
||||
long loc_loc; /* offset of entry in buffer */
|
||||
};
|
||||
|
||||
#define NDIRHASH 32 /* Num of hash lists, must be a power of 2 */
|
||||
#define LOCHASH(i) ((i)&(NDIRHASH-1))
|
||||
|
||||
static long dd_loccnt; /* Index of entry for sequential readdir's */
|
||||
static struct ddloc *dd_hash[NDIRHASH]; /* Hash list heads for ddlocs */
|
||||
|
||||
/*
|
||||
* return a pointer into a directory
|
||||
*/
|
||||
long
|
||||
telldir(dirp)
|
||||
DIR *dirp;
|
||||
{
|
||||
register int index;
|
||||
register struct ddloc *lp;
|
||||
|
||||
if ((lp = (struct ddloc *)malloc(sizeof(struct ddloc))) == NULL)
|
||||
return (-1);
|
||||
index = dd_loccnt++;
|
||||
lp->loc_index = index;
|
||||
lp->loc_seek = dirp->dd_bbase;
|
||||
lp->loc_loc = dirp->dd_loc;
|
||||
lp->loc_next = dd_hash[LOCHASH(index)];
|
||||
dd_hash[LOCHASH(index)] = lp;
|
||||
return (index);
|
||||
}
|
||||
|
||||
/*
|
||||
* seek to an entry in a directory.
|
||||
* Only values returned by "telldir" should be passed to seekdir.
|
||||
*/
|
||||
void
|
||||
p__seekdir(register DIR *dirp, long loc)
|
||||
{
|
||||
register struct ddloc *lp;
|
||||
register struct ddloc **prevlp;
|
||||
struct dirent *dp;
|
||||
extern long lseek();
|
||||
|
||||
prevlp = &dd_hash[LOCHASH(loc)];
|
||||
lp = *prevlp;
|
||||
while (lp != NULL) {
|
||||
if (lp->loc_index == loc)
|
||||
break;
|
||||
prevlp = &lp->loc_next;
|
||||
lp = lp->loc_next;
|
||||
}
|
||||
if (lp == NULL)
|
||||
return;
|
||||
if (lp->loc_loc == dirp->dd_loc && lp->loc_seek == dirp->dd_bbase)
|
||||
goto found;
|
||||
|
||||
if(dirp->dd_fd < 0)
|
||||
p__seekvdir(dirp->dd_fd,lp->loc_seek);
|
||||
else
|
||||
(void) lseek(dirp->dd_fd, lp->loc_seek, 0);
|
||||
|
||||
dirp->dd_bbase = lp->loc_seek;
|
||||
dirp->dd_loc = 0;
|
||||
while (dirp->dd_loc < lp->loc_loc) {
|
||||
assert(P_IS_THIS_THREAD_MASTER()); /*SOLARIS: readdir MT-Unsafe */
|
||||
dp = readdir(dirp);
|
||||
if (dp == NULL)
|
||||
break;
|
||||
}
|
||||
found:
|
||||
#ifdef SINGLEUSE
|
||||
*prevlp = lp->loc_next;
|
||||
free((caddr_t)lp);
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user