|
|
1.1 ! root 1: #include <string.h> ! 2: #include <errno.h> ! 3: #include <fcntl.h> ! 4: #include <sys/types.h> ! 5: #include <utime.h> ! 6: #include <sys/stat.h> ! 7: ! 8: #include <linux/sched.h> ! 9: #include <linux/tty.h> ! 10: #include <linux/kernel.h> ! 11: #include <asm/segment.h> ! 12: ! 13: int sys_utime(char * filename, struct utimbuf * times) ! 14: { ! 15: struct m_inode * inode; ! 16: long actime,modtime; ! 17: ! 18: if (!(inode=namei(filename))) ! 19: return -ENOENT; ! 20: if (times) { ! 21: actime = get_fs_long((unsigned long *) ×->actime); ! 22: modtime = get_fs_long((unsigned long *) ×->modtime); ! 23: } else ! 24: actime = modtime = CURRENT_TIME; ! 25: inode->i_atime = actime; ! 26: inode->i_mtime = modtime; ! 27: inode->i_dirt = 1; ! 28: iput(inode); ! 29: return 0; ! 30: } ! 31: ! 32: int sys_access(const char * filename,int mode) ! 33: { ! 34: struct m_inode * inode; ! 35: int res; ! 36: ! 37: mode &= 0007; ! 38: if (!(inode=namei(filename))) ! 39: return -EACCES; ! 40: res = inode->i_mode & 0777; ! 41: iput(inode); ! 42: if (!(current->euid && current->uid)) ! 43: if (res & 0111) ! 44: res = 0777; ! 45: else ! 46: res = 0666; ! 47: if (current->euid == inode->i_uid) ! 48: res >>= 6; ! 49: else if (current->egid == inode->i_gid) ! 50: res >>= 6; ! 51: if ((res & 0007 & mode) == mode) ! 52: return 0; ! 53: return -EACCES; ! 54: } ! 55: ! 56: int sys_chdir(const char * filename) ! 57: { ! 58: struct m_inode * inode; ! 59: ! 60: if (!(inode = namei(filename))) ! 61: return -ENOENT; ! 62: if (!S_ISDIR(inode->i_mode)) { ! 63: iput(inode); ! 64: return -ENOTDIR; ! 65: } ! 66: iput(current->pwd); ! 67: current->pwd = inode; ! 68: return (0); ! 69: } ! 70: ! 71: int sys_chroot(const char * filename) ! 72: { ! 73: struct m_inode * inode; ! 74: ! 75: if (!(inode=namei(filename))) ! 76: return -ENOENT; ! 77: if (!S_ISDIR(inode->i_mode)) { ! 78: iput(inode); ! 79: return -ENOTDIR; ! 80: } ! 81: iput(current->root); ! 82: current->root = inode; ! 83: return (0); ! 84: } ! 85: ! 86: int sys_chmod(const char * filename,int mode) ! 87: { ! 88: struct m_inode * inode; ! 89: ! 90: if (!(inode=namei(filename))) ! 91: return -ENOENT; ! 92: if (current->uid && current->euid) ! 93: if (current->uid!=inode->i_uid && current->euid!=inode->i_uid) { ! 94: iput(inode); ! 95: return -EACCES; ! 96: } else ! 97: mode = (mode & 0777) | (inode->i_mode & 07000); ! 98: inode->i_mode = (mode & 07777) | (inode->i_mode & ~07777); ! 99: inode->i_dirt = 1; ! 100: iput(inode); ! 101: return 0; ! 102: } ! 103: ! 104: int sys_chown(const char * filename,int uid,int gid) ! 105: { ! 106: struct m_inode * inode; ! 107: ! 108: if (!(inode=namei(filename))) ! 109: return -ENOENT; ! 110: if (current->uid && current->euid) { ! 111: iput(inode); ! 112: return -EACCES; ! 113: } ! 114: inode->i_uid=uid; ! 115: inode->i_gid=gid; ! 116: inode->i_dirt=1; ! 117: iput(inode); ! 118: return 0; ! 119: } ! 120: ! 121: int sys_open(const char * filename,int flag,int mode) ! 122: { ! 123: struct m_inode * inode; ! 124: struct file * f; ! 125: int i,fd; ! 126: ! 127: mode &= 0777 & ~current->umask; ! 128: for(fd=0 ; fd<NR_OPEN ; fd++) ! 129: if (!current->filp[fd]) ! 130: break; ! 131: if (fd>=NR_OPEN) ! 132: return -EINVAL; ! 133: current->close_on_exec &= ~(1<<fd); ! 134: f=0+file_table; ! 135: for (i=0 ; i<NR_FILE ; i++,f++) ! 136: if (!f->f_count) break; ! 137: if (i>=NR_FILE) ! 138: return -EINVAL; ! 139: (current->filp[fd]=f)->f_count++; ! 140: if ((i=open_namei(filename,flag,mode,&inode))<0) { ! 141: current->filp[fd]=NULL; ! 142: f->f_count=0; ! 143: return i; ! 144: } ! 145: /* ttys are somewhat special (ttyxx major==4, tty major==5) */ ! 146: if (S_ISCHR(inode->i_mode)) ! 147: if (MAJOR(inode->i_zone[0])==4) { ! 148: if (current->leader && current->tty<0) { ! 149: current->tty = MINOR(inode->i_zone[0]); ! 150: tty_table[current->tty].pgrp = current->pgrp; ! 151: } ! 152: } else if (MAJOR(inode->i_zone[0])==5) ! 153: if (current->tty<0) { ! 154: iput(inode); ! 155: current->filp[fd]=NULL; ! 156: f->f_count=0; ! 157: return -EPERM; ! 158: } ! 159: f->f_mode = inode->i_mode; ! 160: f->f_flags = flag; ! 161: f->f_count = 1; ! 162: f->f_inode = inode; ! 163: f->f_pos = 0; ! 164: return (fd); ! 165: } ! 166: ! 167: int sys_creat(const char * pathname, int mode) ! 168: { ! 169: return sys_open(pathname, O_CREAT | O_TRUNC, mode); ! 170: } ! 171: ! 172: int sys_close(unsigned int fd) ! 173: { ! 174: struct file * filp; ! 175: ! 176: if (fd >= NR_OPEN) ! 177: return -EINVAL; ! 178: current->close_on_exec &= ~(1<<fd); ! 179: if (!(filp = current->filp[fd])) ! 180: return -EINVAL; ! 181: current->filp[fd] = NULL; ! 182: if (filp->f_count == 0) ! 183: panic("Close: file count is 0"); ! 184: if (--filp->f_count) ! 185: return (0); ! 186: iput(filp->f_inode); ! 187: return (0); ! 188: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.