struct stat {
dev_t st_dev; /* ID of device containing */
/* a directory entry for this file*/
ino_t st_ino; /* File inode number */
ushort st_mode; /* File mode */
short st_nlink; /* Number of links */
ushort st_uid; /* User ID of the file's owner */
ushort st_gid; /* Group ID of the file's group */
dev_t st_rdev; /* ID of device - only for */
/* character or block special */
off_t st_size; /* File size in bytes */
time_t st_atime; /* Time of last access */
time_t st_mtime; /* Time of last data modification */
time_t st_ctime; /* Time of last file status change*/
/* Time measured in seconds since */
/* 00:00:00 GMT, Jan. 1, 1970 */
};
struct dirent {
int d_fileno; /* file number of entry */
int d_reclen; /* length of this record */
int d_type; /* file type */
int d_namlen; /* length of string in d_name */
char d_name[255 + 1]; /* name must be no longer than this */
};
struct timeval {
long tv_sec; /* seconds since Jan. 1, 1970 */
long tv_usec; /* and microseconds */
};
#define S_IRWXU 0000700 /* RWX mask for owner */
#define S_IRUSR 0000400 /* R for owner */
#define S_IWUSR 0000200 /* W for owner */
#define S_IXUSR 0000100 /* X for owner */
#define S_IRWXG 0000070 /* RWX mask for group */
#define S_IRGRP 0000040 /* R for group */
#define S_IWGRP 0000020 /* W for group */
#define S_IXGRP 0000010 /* X for group */
#define S_IRWXO 0000007 /* RWX mask for other */
#define S_IROTH 0000004 /* R for other */
#define S_IWOTH 0000002 /* W for other */
#define S_IXOTH 0000001 /* X for other */
#define S_ISUID 0004000 /* set user id on execution */
#define S_ISGID 0002000 /* set group id on execution */
#define S_ISVTX 0001000 /* sticky bit */
Descriptor = open("temp_file",MODE);
unlink("temp_file");
. . . . .
/*----processing that may crash */
. . . . .
close(Descriptor);
prompt> mknod MyPipeName p
or (FreeBSD)
prompt> mkfifo MyPipeName
or write a program using the same named system calls.
FIFOWrite.c
- Program that writes to a named pipe
CSC322 STOPS HERE
O_WRONLY - open for writing
O_RDWR - open for reading and writing
Exactly one of these must be used in combination with
any of the others.
int pipe(int Descriptors[2]);
creates a bidirectional pipe
int read(int Descriptor,char *Buffer,int NumberOfBytes);and the write system call is declared as:
int write(int Descriptor,char *Buffer,int NumberOfBytes);Complete the internals of the following function, which must copy data from the ReadDescriptor to the WriteDescriptor until end-of-file on the ReadDescriptor, and then close both descriptors. Both descriptors are already open when passed into the function.
void CopyData(int ReadDescriptor,int WriteDescriptor) {
}
int link(char *OldName,char *NewName);and the unlink system call is declared as:
int unlink(char *Pathname);Write a function that takes two filenames as string parameters, and renames the first named file to the second name.