CS 311 – Lecture 13 Outline File management system calls chown() chmod() dup() and dup2() link() Lecture 131CS Operating Systems 1
chown() Changes the owner and/or group of a file Prototype: int chown (const char* filename, uid_t ownerid, gid_t groupid) int lchown (const char* filename, uid_t ownerid, gid_t groupid) int fchown (int fd, uid_t ownerid, gid_t groupid) A value of -1 for ownerid and groupid means that the field should be left unchanged. Lecture 122CS Operating Systems 1
chmod() Changes the file permissions Prototype: int chmod (const char* filename, int mode) int fchmod (int fd, mode_t mode) mode – octal representation for file permissions Lecture 133CS Operating Systems 1
dup() Duplicate a file descriptor. Fd duplication done internally when a pipe or redirection takes place. Prototype: int dup (int oldFd) int dup2 (int oldfd, int newfd) – closes newfd if its active and then points it to the same file as oldfd. Lecture 134CS Operating Systems 1
Link() Creates hard links to an existing file. Prototype: int link(const char* oldpath, const char* newpath) Creates a new label called newpath and links it to the same file referred by oldpath. Returns -1 if unsuccessful and 0 otherwise. Lecture 135CS Operating Systems 1