system include modifications.
-#define NCALLS 86 /* number of system calls allowed */
+#define NCALLS 87 /* number of system calls allowed */
#define EXIT 1
#define FORK 2
#define ALLOCMEM 83 /* to PM */
#define FREEMEM 84 /* to PM */
#define SELECT 85 /* to FS */
+#define FCHDIR 86 /* to FS */
_PROTOTYPE( int access, (const char *_path, int _amode) );
_PROTOTYPE( unsigned int alarm, (unsigned int _seconds) );
_PROTOTYPE( int chdir, (const char *_path) );
+_PROTOTYPE( int fchdir, (int fd) );
_PROTOTYPE( int chown, (const char *_path, _mnx_Uid_t _owner, _mnx_Gid_t _group) );
_PROTOTYPE( int close, (int _fd) );
_PROTOTYPE( char *ctermid, (char *_s) );
_loadname(name, &m);
return(_syscall(FS, CHDIR, &m));
}
+
+PUBLIC int fchdir(fd)
+int fd;
+{
+ message m;
+
+ m.m1_i1 = fd;
+ return(_syscall(FS, FCHDIR, &m));
+}
+
.TH CHDIR 2 "August 26, 1985"
.UC 4
.SH NAME
-chdir \- change current working directory
+chdir, fchdir \- change current working directory
.SH SYNOPSIS
.nf
.ft B
#include <unistd.h>
int chdir(const char *\fIpath\fP)
+int fchdir(int \fIfd\fP)
.ft R
.fi
.SH DESCRIPTION
.I Path
is the pathname of a directory.
+.I Fd
+is the file descriptor of a directory.
+
.B Chdir
causes this directory
to become the current working directory,
/* stadir.c */
_PROTOTYPE( int do_chdir, (void) );
+_PROTOTYPE( int do_fchdir, (void) );
_PROTOTYPE( int do_chroot, (void) );
_PROTOTYPE( int do_fstat, (void) );
_PROTOTYPE( int do_stat, (void) );
#include "super.h"
FORWARD _PROTOTYPE( int change, (struct inode **iip, char *name_ptr, int len));
+FORWARD _PROTOTYPE( int change_into, (struct inode **iip, struct inode *ip));
FORWARD _PROTOTYPE( int stat_inode, (struct inode *rip, struct filp *fil_ptr,
char *user_addr) );
+/*===========================================================================*
+ * do_fchdir *
+ *===========================================================================*/
+PUBLIC int do_fchdir()
+{
+ /* Change directory on already-opened fd. */
+ struct filp *rfilp;
+
+ /* Is the file descriptor valid? */
+ if ( (rfilp = get_filp(m_in.fd)) == NIL_FILP) return(err_code);
+
+ return change_into(&fp->fp_workdir, rfilp->filp_ino);
+}
+
/*===========================================================================*
* do_chdir *
*===========================================================================*/
int len; /* length of the directory name string */
{
/* Do the actual work for chdir() and chroot(). */
-
struct inode *rip;
- register int r;
/* Try to open the new directory. */
if (fetch_name(name_ptr, len, M3) != OK) return(err_code);
if ( (rip = eat_path(user_path)) == NIL_INODE) return(err_code);
+ return change_into(iip, rip);
+}
+
+/*===========================================================================*
+ * change_into *
+ *===========================================================================*/
+PRIVATE int change_into(iip, rip)
+struct inode **iip; /* pointer to the inode pointer for the dir */
+struct inode *rip; /* this is what the inode has to become */
+{
+ register int r;
/* It must be a directory and also be searchable. */
if ( (rip->i_mode & I_TYPE) != I_DIRECTORY)
return(OK);
}
-
/*===========================================================================*
* do_stat *
*===========================================================================*/
no_sys, /* 83 = memalloc */
no_sys, /* 84 = memfree */
do_select, /* 85 = select */
+ do_fchdir, /* 86 = fchdir */
};
/* This should not fail with "array size is negative": */
extern int dummy[sizeof(call_vec) == NCALLS * sizeof(call_vec[0]) ? 1 : -1];
do_allocmem, /* 83 = memalloc */
do_freemem, /* 84 = memfree */
no_sys, /* 85 = select */
+ no_sys, /* 86 = fchdir */
};
/* This should not fail with "array size is negative": */
extern int dummy[sizeof(call_vec) == NCALLS * sizeof(call_vec[0]) ? 1 : -1];