From: Ben Gras Date: Tue, 18 Apr 2006 11:26:04 +0000 (+0000) Subject: Added fchmod() and fchown() X-Git-Tag: v3.1.3~372 X-Git-Url: http://zhaoyanbai.com/repos/Bv9ARM.ch02.html?a=commitdiff_plain;h=461a4fafb1fc882b2de065325597355167f91bba;p=minix.git Added fchmod() and fchown() --- diff --git a/include/minix/callnr.h b/include/minix/callnr.h index 571ddf9db..7e9118ff2 100755 --- a/include/minix/callnr.h +++ b/include/minix/callnr.h @@ -1,4 +1,4 @@ -#define NCALLS 95 /* number of system calls allowed */ +#define NCALLS 97 /* number of system calls allowed */ #define EXIT 1 #define FORK 2 @@ -86,3 +86,5 @@ #define SETEGID 92 /* to PM */ #define TRUNCATE 93 /* to FS */ #define FTRUNCATE 94 /* to FS */ +#define FCHMOD 95 /* to FS */ +#define FCHOWN 96 /* to FS */ diff --git a/include/sys/stat.h b/include/sys/stat.h index 45debc803..4dec6c1ca 100755 --- a/include/sys/stat.h +++ b/include/sys/stat.h @@ -68,6 +68,7 @@ struct stat { /* Function Prototypes. */ _PROTOTYPE( int chmod, (const char *_path, _mnx_Mode_t _mode) ); +_PROTOTYPE( int fchmod, (int fd, _mnx_Mode_t _mode) ); _PROTOTYPE( int fstat, (int _fildes, struct stat *_buf) ); _PROTOTYPE( int mkdir, (const char *_path, _mnx_Mode_t _mode) ); _PROTOTYPE( int mkfifo, (const char *_path, _mnx_Mode_t _mode) ); diff --git a/include/unistd.h b/include/unistd.h index 2d50fcf98..03f741d9f 100755 --- a/include/unistd.h +++ b/include/unistd.h @@ -96,6 +96,7 @@ _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 fchown, (int fd, _mnx_Uid_t _owner, _mnx_Gid_t _group) ); _PROTOTYPE( int close, (int _fd) ); _PROTOTYPE( char *ctermid, (char *_s) ); _PROTOTYPE( char *cuserid, (char *_s) ); diff --git a/lib/posix/Makefile.in b/lib/posix/Makefile.in index 6e0587d1a..3e95fc712 100644 --- a/lib/posix/Makefile.in +++ b/lib/posix/Makefile.in @@ -27,6 +27,8 @@ libc_FILES=" \ _execv.c \ _execve.c \ _execvp.c \ + _fchmod.c \ + _fchown.c \ _fcntl.c \ _fork.c \ _fpathconf.c \ diff --git a/lib/posix/_fchmod.c b/lib/posix/_fchmod.c new file mode 100755 index 000000000..54fdd19eb --- /dev/null +++ b/lib/posix/_fchmod.c @@ -0,0 +1,14 @@ +#include +#define fchmod _fchmod +#include + +PUBLIC int fchmod(fd, mode) +int fd; +_mnx_Mode_t mode; +{ + message m; + + m.m3_i1 = fd; + m.m3_i2 = mode; + return(_syscall(FS, FCHMOD, &m)); +} diff --git a/lib/posix/_fchown.c b/lib/posix/_fchown.c new file mode 100755 index 000000000..49f4e7b77 --- /dev/null +++ b/lib/posix/_fchown.c @@ -0,0 +1,17 @@ +#include +#define fchown _fchown +#include +#include + +PUBLIC int fchown(fd, owner, grp) +int fd; +_mnx_Uid_t owner; +_mnx_Gid_t grp; +{ + message m; + + m.m1_i1 = fd; + m.m1_i2 = owner; + m.m1_i3 = grp; + return(_syscall(FS, FCHOWN, &m)); +} diff --git a/lib/syscall/Makefile.in b/lib/syscall/Makefile.in index c3b7490b1..556aa4f25 100644 --- a/lib/syscall/Makefile.in +++ b/lib/syscall/Makefile.in @@ -29,6 +29,8 @@ libc_FILES=" \ execv.s \ execve.s \ execvp.s \ + fchown.s \ + fchmod.s \ fcntl.s \ fork.s \ fpathconf.s \ diff --git a/lib/syscall/fchmod.s b/lib/syscall/fchmod.s new file mode 100755 index 000000000..a8544ea0b --- /dev/null +++ b/lib/syscall/fchmod.s @@ -0,0 +1,7 @@ +.sect .text +.extern __fchmod +.define _fchmod +.align 2 + +_fchmod: + jmp __fchmod diff --git a/lib/syscall/fchown.s b/lib/syscall/fchown.s new file mode 100755 index 000000000..1a0c9496f --- /dev/null +++ b/lib/syscall/fchown.s @@ -0,0 +1,7 @@ +.sect .text +.extern __fchown +.define _fchown +.align 2 + +_fchown: + jmp __fchown diff --git a/man/man2/chmod.2 b/man/man2/chmod.2 index 9a30318aa..d7f138721 100644 --- a/man/man2/chmod.2 +++ b/man/man2/chmod.2 @@ -7,7 +7,7 @@ .TH CHMOD 2 "May 13, 1986" .UC 4 .SH NAME -chmod \- change mode of file +chmod, fchmod \- change mode of file .SH SYNOPSIS .nf .ft B diff --git a/man/man2/chown.2 b/man/man2/chown.2 index 6d854f07c..e15c6652c 100644 --- a/man/man2/chown.2 +++ b/man/man2/chown.2 @@ -7,7 +7,7 @@ .TH CHOWN 2 "May 22, 1986" .UC 4 .SH NAME -chown \- change owner and group of a file +chown, fchown \- change owner and group of a file .SH SYNOPSIS .nf .ft B @@ -64,7 +64,6 @@ Search permission is denied for a component of the path prefix. .TP 15 [ELOOP] Too many symbolic links were encountered in translating the pathname. -(Minix-vmd) .TP 15 [EPERM] The effective user ID is not the super-user. diff --git a/servers/fs/protect.c b/servers/fs/protect.c index ddca80e89..221d91ff0 100644 --- a/servers/fs/protect.c +++ b/servers/fs/protect.c @@ -2,8 +2,8 @@ * for four system calls that relate to protection. * * The entry points into this file are - * do_chmod: perform the CHMOD system call - * do_chown: perform the CHOWN system call + * do_chmod: perform the CHMOD and FCHMOD system calls + * do_chown: perform the CHOWN and FCHOWN system calls * do_umask: perform the UMASK system call * do_access: perform the ACCESS system call * forbidden: check to see if a given access is allowed on a given inode @@ -29,9 +29,15 @@ PUBLIC int do_chmod() register struct inode *rip; register int r; - /* Temporarily open the file. */ - if (fetch_name(m_in.name, m_in.name_length, M3) != OK) return(err_code); - if ( (rip = eat_path(user_path)) == NIL_INODE) return(err_code); + if(call_nr == CHMOD) { + /* Temporarily open the file. */ + if (fetch_name(m_in.name, m_in.name_length, M3) != OK) return(err_code); + if ( (rip = eat_path(user_path)) == NIL_INODE) return(err_code); + } else if(call_nr == FCHMOD) { + struct filp *filp; + if(!(filp = get_filp(m_in.m3_i1))) return(err_code); + rip = filp->filp_ino; + } else panic(__FILE__, "do_chmod called with strange call_nr", call_nr); /* Only the owner or the super_user may change the mode of a file. * No one may change the mode of a file on a read-only file system. @@ -43,7 +49,7 @@ PUBLIC int do_chmod() /* If error, return inode. */ if (r != OK) { - put_inode(rip); + if(call_nr == CHMOD) put_inode(rip); return(r); } @@ -53,7 +59,7 @@ PUBLIC int do_chmod() rip->i_update |= CTIME; rip->i_dirt = DIRTY; - put_inode(rip); + if(call_nr == CHMOD) put_inode(rip); return(OK); } @@ -67,9 +73,15 @@ PUBLIC int do_chown() register struct inode *rip; register int r; - /* Temporarily open the file. */ - if (fetch_name(m_in.name1, m_in.name1_length, M1) != OK) return(err_code); - if ( (rip = eat_path(user_path)) == NIL_INODE) return(err_code); + if(call_nr == CHOWN) { + /* Temporarily open the file. */ + if (fetch_name(m_in.name1, m_in.name1_length, M1) != OK) return(err_code); + if ( (rip = eat_path(user_path)) == NIL_INODE) return(err_code); + } else if(call_nr == FCHOWN) { + struct filp *filp; + if(!(filp = get_filp(m_in.m1_i1))) return(err_code); + rip = filp->filp_ino; + } else panic(__FILE__, "do_chown called with strange call_nr", call_nr); /* Not permitted to change the owner of a file on a read-only file sys. */ r = read_only(rip); @@ -92,7 +104,7 @@ PUBLIC int do_chown() rip->i_dirt = DIRTY; } - put_inode(rip); + if(call_nr == CHOWN) put_inode(rip); return(r); } diff --git a/servers/fs/table.c b/servers/fs/table.c index 4b1df0811..7c521708d 100644 --- a/servers/fs/table.c +++ b/servers/fs/table.c @@ -112,6 +112,8 @@ PUBLIC _PROTOTYPE (int (*call_vec[]), (void) ) = { no_sys, /* 92 = setegid */ do_truncate, /* 93 = truncate */ do_ftruncate, /* 94 = truncate */ + do_chmod, /* 95 = fchmod */ + do_chown, /* 96 = fchown */ }; /* This should not fail with "array size is negative": */ extern int dummy[sizeof(call_vec) == NCALLS * sizeof(call_vec[0]) ? 1 : -1]; diff --git a/servers/pm/table.c b/servers/pm/table.c index d494f2bc4..d1e8a5b8b 100644 --- a/servers/pm/table.c +++ b/servers/pm/table.c @@ -110,6 +110,8 @@ _PROTOTYPE (int (*call_vec[NCALLS]), (void) ) = { do_getset, /* 92 = setegid */ no_sys, /* 93 = truncate */ no_sys, /* 94 = ftruncate */ + no_sys, /* 95 = fchmod */ + no_sys, /* 96 = fchown */ }; /* This should not fail with "array size is negative": */ extern int dummy[sizeof(call_vec) == NCALLS * sizeof(call_vec[0]) ? 1 : -1];