Add a __getcwd() syscall. This is intentionally undocumented, but all

it does is to try to figure the pwd out from the vfs namecache, and
return a reversed string to it.  libc:getcwd() is responsible for
flipping it back.
This commit is contained in:
Poul-Henning Kamp 1997-09-14 16:51:31 +00:00
parent e70ee0f24b
commit 7822f1c624
8 changed files with 112 additions and 4 deletions

View File

@ -358,4 +358,5 @@ struct sysent sysent[] = {
{ 1, (sy_call_t *)thr_wakeup }, /* 323 = thr_wakeup */
{ 1, (sy_call_t *)mlockall }, /* 324 = mlockall */
{ 0, (sy_call_t *)munlockall }, /* 325 = munlockall */
{ 2, (sy_call_t *)__getcwd }, /* 326 = __getcwd */
};

View File

@ -347,4 +347,5 @@ char *syscallnames[] = {
"thr_wakeup", /* 323 = thr_wakeup */
"mlockall", /* 324 = mlockall */
"munlockall", /* 325 = munlockall */
"__getcwd", /* 326 = __getcwd */
};

View File

@ -1,4 +1,4 @@
$Id: syscalls.master,v 1.41 1997/08/19 05:53:48 peter Exp $
$Id: syscalls.master,v 1.42 1997/09/14 02:22:05 peter Exp $
; from: @(#)syscalls.master 8.2 (Berkeley) 1/13/94
;
; System call name/number master file.
@ -476,3 +476,4 @@
323 STD BSD { int thr_wakeup(pid_t pid); }
324 STD BSD { int mlockall(int how); }
325 STD BSD { int munlockall(void); }
326 STD BSD { int __getcwd(u_char *buf, u_int buflen); }

View File

@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)vfs_syscalls.c 8.13 (Berkeley) 4/15/94
* $Id: vfs_syscalls.c,v 1.66 1997/07/17 07:17:33 dfr Exp $
* $Id: vfs_syscalls.c,v 1.67 1997/09/02 20:06:03 bde Exp $
*/
/*
@ -2763,3 +2763,52 @@ getvnode(fdp, fd, fpp)
*fpp = fp;
return (0);
}
#ifndef _SYS_SYSPROTO_H_
struct __getcwd_args {
u_char * buf;
u_int buflen;
};
#endif
/* ARGSUSED */
int
__getcwd(p, uap, retval)
struct proc *p;
register struct __getcwd_args *uap;
register_t *retval;
{
struct filedesc *fdp = p->p_fd;
struct vnode *vp;
struct namecache *ncp;
int i,j=0;
for (vp = fdp->fd_cdir; vp != fdp->fd_rdir && vp != rootvnode;) {
if (vp->v_dd->v_id != vp->v_ddid)
return(ENOENT);
ncp = TAILQ_FIRST(&vp->v_cache_dst);
if (!ncp)
return(ENOENT);
if (ncp->nc_dvp != vp->v_dd)
return(ENOENT);
for (i=ncp->nc_nlen-1; i >= 0; i--) {
if (uap->buflen-- < 2)
return(ENOMEM);
subyte(uap->buf, ncp->nc_name[i]);
uap->buf++;
}
if (uap->buflen-- < 2)
return(ENOMEM);
subyte(uap->buf, '/' );
uap->buf++;
j++;
vp = vp->v_dd;
}
if (!j) {
if (uap->buflen-- < 2)
return(ENOMEM);
subyte(uap->buf, '/' );
uap->buf++;
}
subyte(uap->buf, '\0' );
uap->buf++;
return (0);
}

View File

@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)vfs_syscalls.c 8.13 (Berkeley) 4/15/94
* $Id: vfs_syscalls.c,v 1.66 1997/07/17 07:17:33 dfr Exp $
* $Id: vfs_syscalls.c,v 1.67 1997/09/02 20:06:03 bde Exp $
*/
/*
@ -2763,3 +2763,52 @@ getvnode(fdp, fd, fpp)
*fpp = fp;
return (0);
}
#ifndef _SYS_SYSPROTO_H_
struct __getcwd_args {
u_char * buf;
u_int buflen;
};
#endif
/* ARGSUSED */
int
__getcwd(p, uap, retval)
struct proc *p;
register struct __getcwd_args *uap;
register_t *retval;
{
struct filedesc *fdp = p->p_fd;
struct vnode *vp;
struct namecache *ncp;
int i,j=0;
for (vp = fdp->fd_cdir; vp != fdp->fd_rdir && vp != rootvnode;) {
if (vp->v_dd->v_id != vp->v_ddid)
return(ENOENT);
ncp = TAILQ_FIRST(&vp->v_cache_dst);
if (!ncp)
return(ENOENT);
if (ncp->nc_dvp != vp->v_dd)
return(ENOENT);
for (i=ncp->nc_nlen-1; i >= 0; i--) {
if (uap->buflen-- < 2)
return(ENOMEM);
subyte(uap->buf, ncp->nc_name[i]);
uap->buf++;
}
if (uap->buflen-- < 2)
return(ENOMEM);
subyte(uap->buf, '/' );
uap->buf++;
j++;
vp = vp->v_dd;
}
if (!j) {
if (uap->buflen-- < 2)
return(ENOMEM);
subyte(uap->buf, '/' );
uap->buf++;
}
subyte(uap->buf, '\0' );
uap->buf++;
return (0);
}

View File

@ -245,3 +245,4 @@ HIDE_BSD(thr_sleep)
HIDE_BSD(thr_wakeup)
HIDE_BSD(mlockall)
HIDE_BSD(munlockall)
HIDE_BSD(__getcwd)

View File

@ -239,4 +239,5 @@
#define SYS_thr_wakeup 323
#define SYS_mlockall 324
#define SYS_munlockall 325
#define SYS_MAXSYSCALL 326
#define SYS___getcwd 326
#define SYS_MAXSYSCALL 327

View File

@ -844,6 +844,10 @@ struct mlockall_args {
struct munlockall_args {
int dummy;
};
struct __getcwd_args {
u_char * buf;
u_int buflen;
};
int nosys __P((struct proc *, struct nosys_args *, int []));
void exit __P((struct proc *, struct rexit_args *, int [])) __dead2;
int fork __P((struct proc *, struct fork_args *, int []));
@ -1047,6 +1051,7 @@ int thr_sleep __P((struct proc *, struct thr_sleep_args *, int []));
int thr_wakeup __P((struct proc *, struct thr_wakeup_args *, int []));
int mlockall __P((struct proc *, struct mlockall_args *, int []));
int munlockall __P((struct proc *, struct munlockall_args *, int []));
int __getcwd __P((struct proc *, struct __getcwd_args *, int []));
#ifdef COMPAT_43