- Omitted Last time
- O_RDONLY, O_WRONLY, O_RDWR
- O_CREAT, O_EXCL, O_TRUNC
- Error Last Time seek constants reveresed?
#include < sys/types >
#include < unistd.h >
off_t lseek(int filedes, off_t offset, int start_flag);
SEEK_SET(=0)
SEEK_CUR(=1)
SEEK_END(=2)
- Stat Structure < sys/stat.h > revisited
struct stat
{
dev_t st_dev; /* file system ID */
ino_t st_ino; /* the inode number */
mode_t st_mode; /* permissions and type information */
nlink_t st_nlink; /* number of links */
uid_t st_uid; /* File owner user ID */
gid_t st_gid; /* File group ID */
dev_t st_rdev; /* Major and minor device numbers */
off_t st_size; /* size in bytes */
time_t st_atime; /* last access time */
time_t st_mtime; /* last modification time */
time_t st_ctime; /* last status change time */
long st_blksize; /* best I/O block size */
long st_blocks; /* number of 512-byte `blocks' */
};
- st_mode - information on file type and permissions
- filetypes
- regular file
- directory
- symbolic link
- character device file
- block device file
- FIFO
- socket
- mode 32 bits -
- #define _S_IFMT 0170000 /* Octal number type of file; */
- #define _S_IFREG 0100000 /* regular; sync with S_IFREG */
- File type Testing macros from stdio.h
#define S_ISDIR( mode ) (((mode) & _S_IFMT) == _S_IFDIR)
- File Permissions
- User, group, others
- 3 bits for each read, write, execute (rwx)
- ls -l
- chmod command
- Mode Testing definitions
/* file modes */
#define S_IRWXU 00700 /* read, write, execute: owner */
#define S_IRUSR 00400 /* read permission: owner */
#define S_IWUSR 00200 /* write permission: owner */
#define S_IXUSR 00100 /* execute permission: owner *
...
#define S_ISUID 0004000 /* set user id on execution */
#define S_ISGID 0002000 /* set group id on execution */
/*
- The stat, fstat lstat system calls
- int stat(const *path, struct stat *buf) - get statistics on this file
- int fstat(int fd, struct stat *buf) - a version of stat for open files
- int lstat(const *path, struct stat *buf) - a version of stat that does not follow symbolic links
- Command line arguments website/C-Intro/printargs.c
- filetype.c
...
struct stat buf;
char *ptr;
for (i = 1; i < argc; i++) {
printf("%s: ", argv[i]);
if (lstat(argv[i], &buf) < 0) {
err_ret("lstat error");
continue;
}
if (S_ISREG(buf.st_mode)) ptr = "regular";
...
- Inode information
- All of the stat structure info
- Disk block addresses
- Original Unix File system Disk Block Pointers
- 10 direct pointers
- single indirect pointer
- double indirect pointer
- triple indirect pointer
- Assuming 32 bit words, 24 bit disk block pointers and 512 byte blocks
what is the largest possible file using the original Unix Scheme?
- AR - archive and library maintainer
- Why is it needed?
- Syntax: ar -option [ posname ] archive file1 ...fileN
- man 5 ar
A file produced by ar has a magic string at the start, followed by the
constituent files, each preceded by a file header. The magic number and
header layout as described in the include file are:
struct ar_hdr {
char ar_name[16];
char ar_date[12];
char ar_uid[6];
char ar_gid[6];
char ar_mode[8];
char ar_size[10];
char ar_fmag[2];
};
- AR options
- suboptions
- File Times
- [Readings:]
-
- [Assignment:]
- Program 1 due Sept 14 - AR
- Previous Lecture -
- Index -
- Next Lecture -
URL = http://www.cs.sc.edu/~matthews/Courses/510/Lectures/lec3.html