Improve the process for GNU tools
[minix3.git] / minix / fs / mfs / protect.c
blob5deb7637bcafff75ec20c441562381721ceffdff
1 #include "fs.h"
2 #include "inode.h"
3 #include "super.h"
6 /*===========================================================================*
7 * fs_chmod *
8 *===========================================================================*/
9 int fs_chmod(ino_t ino_nr, mode_t *mode)
11 /* Perform the chmod(name, mode) system call. */
12 register struct inode *rip;
14 /* Temporarily open the file. */
15 if( (rip = get_inode(fs_dev, ino_nr)) == NULL)
16 return(EINVAL);
18 if(rip->i_sp->s_rd_only) {
19 put_inode(rip);
20 return EROFS;
23 /* Now make the change. Clear setgid bit if file is not in caller's grp */
24 rip->i_mode = (rip->i_mode & ~ALL_MODES) | (*mode & ALL_MODES);
25 rip->i_update |= CTIME;
26 IN_MARKDIRTY(rip);
28 /* Return full new mode to caller. */
29 *mode = rip->i_mode;
31 put_inode(rip);
32 return(OK);
36 /*===========================================================================*
37 * fs_chown *
38 *===========================================================================*/
39 int fs_chown(ino_t ino_nr, uid_t uid, gid_t gid, mode_t *mode)
41 register struct inode *rip;
43 /* Temporarily open the file. */
44 if( (rip = get_inode(fs_dev, ino_nr)) == NULL)
45 return(EINVAL);
47 rip->i_uid = uid;
48 rip->i_gid = gid;
49 rip->i_mode &= ~(I_SET_UID_BIT | I_SET_GID_BIT);
50 rip->i_update |= CTIME;
51 IN_MARKDIRTY(rip);
53 /* Update caller on current mode, as it may have changed. */
54 *mode = rip->i_mode;
55 put_inode(rip);
57 return(OK);