Added fchdir() system call, with corresponding manpage, Changelog and

system include modifications.
This commit is contained in:
Ben Gras 2005-06-29 19:28:26 +00:00
parent 62f7f9e6d2
commit af27dc0cf7
8 changed files with 47 additions and 5 deletions

View file

@ -1,4 +1,4 @@
#define NCALLS 86 /* number of system calls allowed */ #define NCALLS 87 /* number of system calls allowed */
#define EXIT 1 #define EXIT 1
#define FORK 2 #define FORK 2
@ -74,3 +74,4 @@
#define ALLOCMEM 83 /* to PM */ #define ALLOCMEM 83 /* to PM */
#define FREEMEM 84 /* to PM */ #define FREEMEM 84 /* to PM */
#define SELECT 85 /* to FS */ #define SELECT 85 /* to FS */
#define FCHDIR 86 /* to FS */

View file

@ -85,6 +85,7 @@ _PROTOTYPE( void _exit, (int _status) );
_PROTOTYPE( int access, (const char *_path, int _amode) ); _PROTOTYPE( int access, (const char *_path, int _amode) );
_PROTOTYPE( unsigned int alarm, (unsigned int _seconds) ); _PROTOTYPE( unsigned int alarm, (unsigned int _seconds) );
_PROTOTYPE( int chdir, (const char *_path) ); _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 chown, (const char *_path, _mnx_Uid_t _owner, _mnx_Gid_t _group) );
_PROTOTYPE( int close, (int _fd) ); _PROTOTYPE( int close, (int _fd) );
_PROTOTYPE( char *ctermid, (char *_s) ); _PROTOTYPE( char *ctermid, (char *_s) );

View file

@ -10,3 +10,13 @@ _CONST char *name;
_loadname(name, &m); _loadname(name, &m);
return(_syscall(FS, CHDIR, &m)); return(_syscall(FS, CHDIR, &m));
} }
PUBLIC int fchdir(fd)
int fd;
{
message m;
m.m1_i1 = fd;
return(_syscall(FS, FCHDIR, &m));
}

View file

@ -7,18 +7,22 @@
.TH CHDIR 2 "August 26, 1985" .TH CHDIR 2 "August 26, 1985"
.UC 4 .UC 4
.SH NAME .SH NAME
chdir \- change current working directory chdir, fchdir \- change current working directory
.SH SYNOPSIS .SH SYNOPSIS
.nf .nf
.ft B .ft B
#include <unistd.h> #include <unistd.h>
int chdir(const char *\fIpath\fP) int chdir(const char *\fIpath\fP)
int fchdir(int \fIfd\fP)
.ft R .ft R
.fi .fi
.SH DESCRIPTION .SH DESCRIPTION
.I Path .I Path
is the pathname of a directory. is the pathname of a directory.
.I Fd
is the file descriptor of a directory.
.B Chdir .B Chdir
causes this directory causes this directory
to become the current working directory, to become the current working directory,

View file

@ -142,6 +142,7 @@ _PROTOTYPE( zone_t rd_indir, (struct buf *bp, int index) );
/* stadir.c */ /* stadir.c */
_PROTOTYPE( int do_chdir, (void) ); _PROTOTYPE( int do_chdir, (void) );
_PROTOTYPE( int do_fchdir, (void) );
_PROTOTYPE( int do_chroot, (void) ); _PROTOTYPE( int do_chroot, (void) );
_PROTOTYPE( int do_fstat, (void) ); _PROTOTYPE( int do_fstat, (void) );
_PROTOTYPE( int do_stat, (void) ); _PROTOTYPE( int do_stat, (void) );

View file

@ -20,9 +20,24 @@
#include "super.h" #include "super.h"
FORWARD _PROTOTYPE( int change, (struct inode **iip, char *name_ptr, int len)); 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, FORWARD _PROTOTYPE( int stat_inode, (struct inode *rip, struct filp *fil_ptr,
char *user_addr) ); 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 * * do_chdir *
*===========================================================================*/ *===========================================================================*/
@ -86,13 +101,22 @@ char *name_ptr; /* pointer to the directory name to change to */
int len; /* length of the directory name string */ int len; /* length of the directory name string */
{ {
/* Do the actual work for chdir() and chroot(). */ /* Do the actual work for chdir() and chroot(). */
struct inode *rip; struct inode *rip;
register int r;
/* Try to open the new directory. */ /* Try to open the new directory. */
if (fetch_name(name_ptr, len, M3) != OK) return(err_code); if (fetch_name(name_ptr, len, M3) != OK) return(err_code);
if ( (rip = eat_path(user_path)) == NIL_INODE) 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. */ /* It must be a directory and also be searchable. */
if ( (rip->i_mode & I_TYPE) != I_DIRECTORY) if ( (rip->i_mode & I_TYPE) != I_DIRECTORY)
@ -112,7 +136,6 @@ int len; /* length of the directory name string */
return(OK); return(OK);
} }
/*===========================================================================* /*===========================================================================*
* do_stat * * do_stat *
*===========================================================================*/ *===========================================================================*/

View file

@ -103,6 +103,7 @@ PUBLIC _PROTOTYPE (int (*call_vec[]), (void) ) = {
no_sys, /* 83 = memalloc */ no_sys, /* 83 = memalloc */
no_sys, /* 84 = memfree */ no_sys, /* 84 = memfree */
do_select, /* 85 = select */ do_select, /* 85 = select */
do_fchdir, /* 86 = fchdir */
}; };
/* This should not fail with "array size is negative": */ /* This should not fail with "array size is negative": */
extern int dummy[sizeof(call_vec) == NCALLS * sizeof(call_vec[0]) ? 1 : -1]; extern int dummy[sizeof(call_vec) == NCALLS * sizeof(call_vec[0]) ? 1 : -1];

View file

@ -102,6 +102,7 @@ _PROTOTYPE (int (*call_vec[NCALLS]), (void) ) = {
do_allocmem, /* 83 = memalloc */ do_allocmem, /* 83 = memalloc */
do_freemem, /* 84 = memfree */ do_freemem, /* 84 = memfree */
no_sys, /* 85 = select */ no_sys, /* 85 = select */
no_sys, /* 86 = fchdir */
}; };
/* This should not fail with "array size is negative": */ /* This should not fail with "array size is negative": */
extern int dummy[sizeof(call_vec) == NCALLS * sizeof(call_vec[0]) ? 1 : -1]; extern int dummy[sizeof(call_vec) == NCALLS * sizeof(call_vec[0]) ? 1 : -1];