summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>1997-09-14 16:51:31 +0000
committerphk <phk@FreeBSD.org>1997-09-14 16:51:31 +0000
commitb079abc11c97decabfeb4683ebd3561674cdf55d (patch)
tree2b771099ba7453b6556716fa8dcf87c1f0f6f017
parente2ce0d677e459daf5a1afb3e7317c7d9b2fdfe1c (diff)
downloadFreeBSD-src-b079abc11c97decabfeb4683ebd3561674cdf55d.zip
FreeBSD-src-b079abc11c97decabfeb4683ebd3561674cdf55d.tar.gz
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.
-rw-r--r--sys/kern/init_sysent.c1
-rw-r--r--sys/kern/syscalls.c1
-rw-r--r--sys/kern/syscalls.master3
-rw-r--r--sys/kern/vfs_extattr.c51
-rw-r--r--sys/kern/vfs_syscalls.c51
-rw-r--r--sys/sys/syscall-hide.h1
-rw-r--r--sys/sys/syscall.h3
-rw-r--r--sys/sys/sysproto.h5
8 files changed, 112 insertions, 4 deletions
diff --git a/sys/kern/init_sysent.c b/sys/kern/init_sysent.c
index ff220b8..a86db21 100644
--- a/sys/kern/init_sysent.c
+++ b/sys/kern/init_sysent.c
@@ -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 */
};
diff --git a/sys/kern/syscalls.c b/sys/kern/syscalls.c
index d6946a8..21c6e76 100644
--- a/sys/kern/syscalls.c
+++ b/sys/kern/syscalls.c
@@ -347,4 +347,5 @@ char *syscallnames[] = {
"thr_wakeup", /* 323 = thr_wakeup */
"mlockall", /* 324 = mlockall */
"munlockall", /* 325 = munlockall */
+ "__getcwd", /* 326 = __getcwd */
};
diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master
index 6a19917..62673fa 100644
--- a/sys/kern/syscalls.master
+++ b/sys/kern/syscalls.master
@@ -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); }
diff --git a/sys/kern/vfs_extattr.c b/sys/kern/vfs_extattr.c
index e28f93b..93e0a46 100644
--- a/sys/kern/vfs_extattr.c
+++ b/sys/kern/vfs_extattr.c
@@ -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);
+}
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index e28f93b..93e0a46 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -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);
+}
diff --git a/sys/sys/syscall-hide.h b/sys/sys/syscall-hide.h
index e023d2c..009b26d 100644
--- a/sys/sys/syscall-hide.h
+++ b/sys/sys/syscall-hide.h
@@ -245,3 +245,4 @@ HIDE_BSD(thr_sleep)
HIDE_BSD(thr_wakeup)
HIDE_BSD(mlockall)
HIDE_BSD(munlockall)
+HIDE_BSD(__getcwd)
diff --git a/sys/sys/syscall.h b/sys/sys/syscall.h
index fdf4f8d..f8646a9 100644
--- a/sys/sys/syscall.h
+++ b/sys/sys/syscall.h
@@ -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
diff --git a/sys/sys/sysproto.h b/sys/sys/sysproto.h
index 1111fbf..0a21332 100644
--- a/sys/sys/sysproto.h
+++ b/sys/sys/sysproto.h
@@ -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
OpenPOWER on IntegriCloud