jkh@meepmeep.pcs.com (Jordan K. Hubbard) (02/27/91)
Somehow, "PC532 Minix 1.3/1.5 hybrid" just doesn't roll off one's tongue that easily, but I don't know what else to call this latest incarnation of minix. Anyway. I got tired of not having fchmod() and fchown() around, and they were trivial to add, so I popped them into my kernel. What I did was add two more message types to fs with the corresponding library calls going in lib/posix. I don't see where this should side-effect anything else, but you never know. I've tested them pretty thoroughly (the GNU binutils use them if you don't define FCHMOD_MISSING) and they've performed as advertised. Here are the context diffs so that you can do the same. P.S. My apologies for the rather harsh tone I took in my last posting. I was on very little sleep + too much coffee and, in retrospect, wish I'd just stayed completely away from my terminal the whole day! Considering the price, Minix is a godsend. Jordan *** fs/protect.c Fri Feb 15 18:11:01 1991 --- new/fs/protect.c Tue Feb 26 14:02:55 1991 *************** *** 53,59 **** --- 53,97 ---- return(OK); } + /*===========================================================================* + * do_fchmod * + *===========================================================================*/ + PUBLIC int do_fchmod() + { + /* Perform the fchmod(fd, mode) system call. */ + + register struct inode *rip; + register int r; + register struct filp *rfilp; + + /* Is the file descriptor valid? */ + if ( (rfilp = get_filp(fd)) == NIL_FILP) + return(err_code); + else + rip = rfilp->filp_ino; + + /* 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. + */ + if (rip->i_uid != fp->fp_effuid && !super_user) + r = EPERM; + else + r = read_only(rip); + + /* If error, return inode. */ + if (r != OK) { + put_inode(rip); + return(r); + } + /* Now make the change. */ + rip->i_mode = (rip->i_mode & ~ALL_MODES) | (fmode & ALL_MODES); + rip->i_dirt = DIRTY; + + put_inode(rip); + return(OK); + } + /*===========================================================================* * do_chown * *===========================================================================*/ *************** *** 83,88 **** --- 121,158 ---- return(r); } + + /*===========================================================================* + * do_fchown * + *===========================================================================*/ + PUBLIC int do_fchown() + { + /* Perform the fchown(fd, owner, group) system call. */ + + register struct inode *rip; + register int r; + register struct filp *rfilp; + + /* Only the super_user may perform the fchown() call. */ + if (!super_user) return(EPERM); + + /* Is the file descriptor valid? */ + if ( (rfilp = get_filp(fd)) == NIL_FILP) + return(err_code); + else + rip = rfilp->filp_ino; + + /* Not permitted to change the owner of a file on a read-only file sys. */ + r = read_only(rip); + if (r == OK) { + rip->i_uid = owner; + rip->i_gid = group; + rip->i_dirt = DIRTY; + } + + put_inode(rip); + return(r); + } /*===========================================================================* * do_umask * *** fs/param.h Fri Feb 15 18:10:59 1991 --- new/fs/param.h Mon Feb 25 21:41:45 1991 *************** *** 10,15 **** --- 10,16 ---- #define erki m.m1_p1 #define fd m.m1_i1 #define fd2 m.m1_i2 + #define fmode m.m1_i2 #define ioflags m.m1_i3 #define group m.m1_i3 #define real_grp_id m.m1_i2 *** include/minix/callnr.h Fri Feb 15 18:11:10 1991 --- new/include/minix/callnr.h Mon Feb 25 08:03:01 1991 *************** *** 46,51 **** --- 46,54 ---- #define EXEC 59 #define UMASK 60 #define CHROOT 61 + /* Extended calls beyond this point */ + #define FCHMOD 62 + #define FCHOWN 63 /* The following are not system calls, but are processed like them. */ #define KSIG 64 /* kernel detected a signal */ *** lib/posix/Makefile Thu Feb 21 06:07:09 1991 --- new/lib/posix/Makefile Mon Feb 25 08:38:36 1991 *************** *** 8,14 **** getuid.c isatty.c kill.c link.c lseek.c mkdir.c mkfifo.c open.c \ opendir.c pathconf.c pause.c pipe.c read.c readdir.c rename.c \ rewinddir.c rmdir.c setgid.c setuid.c sleep.c stat.c sysconf.c times.c \ ! ttyname.c umask.c unlink.c utime.c wait.c write.c \ OFILES= _exit.o access.o alarm.o chdir.o chmod.o chown.o close.o \ closedir.o creat.o ctermid.o cuserid.o dup.o dup2.o exec.o execlp.o \ --- 8,14 ---- getuid.c isatty.c kill.c link.c lseek.c mkdir.c mkfifo.c open.c \ opendir.c pathconf.c pause.c pipe.c read.c readdir.c rename.c \ rewinddir.c rmdir.c setgid.c setuid.c sleep.c stat.c sysconf.c times.c \ ! ttyname.c umask.c unlink.c utime.c wait.c write.c fchmod.c fchown.c \ OFILES= _exit.o access.o alarm.o chdir.o chmod.o chown.o close.o \ closedir.o creat.o ctermid.o cuserid.o dup.o dup2.o exec.o execlp.o \ *************** *** 17,23 **** getuid.o isatty.o kill.o link.o lseek.o mkdir.o mkfifo.o open.o \ opendir.o pathconf.o pause.o pipe.o read.o readdir.o rename.o \ rewinddir.o rmdir.o setgid.o setuid.o sleep.o stat.o sysconf.o times.o \ ! ttyname.o umask.o unlink.o utime.o wait.o write.o \ all: $(OFILES) --- 17,23 ---- getuid.o isatty.o kill.o link.o lseek.o mkdir.o mkfifo.o open.o \ opendir.o pathconf.o pause.o pipe.o read.o readdir.o rename.o \ rewinddir.o rmdir.o setgid.o setuid.o sleep.o stat.o sysconf.o times.o \ ! ttyname.o umask.o unlink.o utime.o wait.o write.o fchmod.o fchown.o \ all: $(OFILES) *** /dev/null Tue Feb 26 12:49:47 1991 --- lib/posix/fchmod.c Mon Feb 25 21:38:12 1991 *************** *** 0 **** --- 1,8 ---- + #include <lib.h> + + PUBLIC int fchmod(fd, mode) + int fd; + mode_t mode; + { + return(callm1(FS, FCHMOD, fd, mode, 0, 0, NIL_PTR, NIL_PTR)); + } *** /dev/null Tue Feb 26 12:49:47 1991 --- lib/posix/fchown.c Mon Feb 25 21:39:29 1991 *************** *** 0 **** --- 1,9 ---- + #include <lib.h> + + PUBLIC int fchown(fd, owner, grp) + int fd; + uid_t owner; + gid_t grp; + { + return(callm1(FS, FCHOWN, fd, owner, grp, 0, NIL_PTR, NIL_PTR)); + }