Transcript PPT

System Interface

Interface that provides services from the OS (Higher than BIOS)




Memory
Scheduler
File/Storage System
Inter-process Communication and Network, etc
program
libc
Operating System
BIOS
File System

A popular but also complex subsystem




File descriptors (pseudo files, like stdin and stdout)
Low level IO
File Management
Examples
file pointer
/
usr




bin
home
file
Tree-like Structure
The top level is called root and is represented by /
The representation of directory is represented as /aa/bb/cc
A file in /aa/bb/cc can be represented as /aa/bb/cc/file
EOF
Several Important Directories


/ : root file system
/bin


Contains executable files
/etc


Configuration files
Some executable shell files
Cont.

/usr






Contains many sub-directories
/usr/inlcude and /usr/lib
/usr/home- the home directories of users
/usr/bin/ - contains more executables
/usr/local- softwares from the third-party
/sbin

Contains executables which can only be
executed by the super user (root)
Cont.

/home


/dev or /devices


Like /usr/home
Contains device files
/var

Contains files the content of which will be
changed frequently. For example : mails ,
logs and so on.
Cont.

/proc


/sys


A special file system which contains
runtime information of the system
A special file system which contains the
information of the system and its kernel
/mnt

Can be used to mount other file sytems
The Home directory


When you log onto the system , you will
be assigned a home directory;
Working directory – The directory which
you are currently in;

pwd- used to list your current working
directory
Some Commands




mkdir -- create a directory
ls ---- list the files in a directory
df ---- display the number of the blocks
of a file system
mount – mount a file system to a
directory
A little about File Attributes

File attributes (srwxrwxrwx)





r:read, w:write and e:execute
Each kind of right can be presented by 0 or 1
The combination of 3 kinds of rights is represented by a octet number (0 - 7),
rwx, desribes the permission to a set of users
Three sets of different users: owner, group and others
Some unix commands: umask, chmod, etc to change the attributes
Cont.
For example:
[gub@mu gub]$ ls -al sommer.pdf
-rw-r--r-- 1 gub
cisgrad 257688 Aug 20 15:09 sommer.pdf

The access right of the file is





rw -> 110 ->6
r->100->4
r->100->4
The access right is 644
Change the access right of a file:

chmod xxx filename
Cont.
The following is required access right for
a file (test1.txt):
1.
Owner: rwx
2.
Group: r—
3.
Others: --How to use chmod to change the access
right of test1.txt?
The File Creating Mask


Umask uu
The required access for files is:

Default access right – uu
For example:
 Default : 555; umask 22
 What is the required access right?
Other commands related to the
access right of a file



chown: change the owner of a file
chgrp: change the group of a file
chmod p + access right


P can be u (user), g (group) ; o(other);
a(all)
Access right can be r , w x.
File Accesses

Read and Write



getc() and putc(); getchar() and putchar()
int read(int fd, char *buf, int n);
int write(int fd, char *buf, int n)
#include <stdio.h>
int main ()
{
char buf[1024];
int n;
while ((n = read(0, buf, 1024)) > 0)
write ( 1, buf, n);
return 0;
}
#include <stdio.h>
int getchar ()
{
char c;
return (read(0, &c, 1) == 1 ) ? c : EOF;
}
File Accesses -- continued

Open, creat, close and unlink





int open(char *name, int flags, int perms);
Persm can be O_RONLY, O_RDWR, O_WRONLY and others
int creat(char *name, int perms); /* within open, O_CREAT */
int close(int fd);
int unlink(char *path);
#include <fcntl.h> /* A copy program*/
int main ()
{
char *f1 =“file1”, *f2=“file2”;
int fd1, fd2, n;
if (fd1 = open(f1, O_RDONLY, 0) == -1)
usage(“uanble to opening source file %s\n”, f1);
if (fd2 = creat(f2, 0666) == -1)
usage(“unable to creating new file %s \n”, f2);
while ((n = read(fd1, buf, 1024) > 0))
write ( fd2, buf, n);
return 0;
}