File Management System The way a user or



















- Slides: 19

File Management System • The way a user or application may access files • Programmer does not need to develop file management software • You take files for granted but they actually are not • FMS is part of Operating System • Provides operation for file access and maintenance

Objectives for FMS • Meet the data management needs and requirements of the user • Guarantee that the data in the file are valid • Optimize performance • Provide I/O support for a variety of storage device types • Minimize or eliminate the potential for lost or destroyed data • Provide a standardized set of I/O interface routines • Provide I/O support for multiple users

Minimal Set of Requirements • Each user should be able to – create, delete, read, and change files – have controlled access to other users’ files – control what type of accesses are allowed to the users’ files – move data between files – back up and recover the user’s files in case of damage – access the user’s files by using symbolic names

File Management Functions • Identify and locate a selected file • Use a directory to describe the location of all files plus their attributes • On a shared system describe user access control • Blocking for access to files • Allocate files to free blocks • Manage free storage for available blocks

File Content • In the responsibility of the user or the application that created the file • Different file types have different conventions • You can only use a file with the correct application – Open a. doc file in the notepad and change something – Now word can’t read it anymore • DOS: defines by the ending • UNIX: the first part of the file “magic number”

Example: a) UNIX executable b)code archive (. jar file)

Directory Structure: A Way to organize things • Files reside on the hard drive • Directories Contains file information – Attributes (Size, Date of change) – Ownership • Directory itself is a file owned by the operating system • Provides mapping between file names and the files themselves

Hierarchical Directory Structure

Tree-Structured Directory • Master directory with user directories underneath it (usually /) • Each user directory may have subdirectories and files as entries • Files can be located by following a path from the root, or master, directory down various branches – This is the pathname for the file, directories are separated by / • Can have several files with the same file name as long as they have unique path names

Tree-Structured Directory • Current directory is the working directory • Files are referenced relative to the working directory • UNIX – ls -la List all files with full information – cd dir change directory – pwd show current path – ~ your home directory –. current directory –. . Parent directory (one step up in the tree)

More UNIX – rm file – mkdir dir – rm -r dir Remove file Create directory dir Remove directory (only if it is empty) Remove it! Empty or not! • Regular Expression: Pattern Matching – Will make your life with UNIX much easier if you get into serious work! – * stands for any character, any number of characters – + Stands for at least one character – example: ls *. ppt Show all Power. Pint files in dir

File Sharing • In multi user system, allow files to be shared among users • Two issues – Access rights – Management of simultaneous access

Access Rights • • None Execution (x) Reading (r) Updating (w) – The user can modify, deleted, and add to the file’s data. This includes creating the file, rewriting it, and removing all or part of the data • UNIX – access right exist for 3 different groups: Owner, same group and rest of the world (ls-la)

Access Rights • Owners – Has all rights previously listed – May grant rights to others using the following classes of users • Himself • Group • Others – chmod nnn file where n is a decimal number <=7 – Alternative: chmod who+access file • who: u=user, g=group, o=other • access: r=read, w=write, x=execute • Restrict access using – instead of + • Remark: All files that you want to be available from you home page have to be world readable!

Simultaneous Access • User locks entire file when it is to be updated • Mutual exclusion and deadlock are issues for shared access

How to find an executable • You wrote a c program and compiled it, you can only start it if you are in the directory or if you include the full path • But how does the OS do with all other applications? It knows where to look! • UNIX: which command tells you where it found it • PATH variable contains a list of all directories in which the OS looks for executable • UNIX: echo $PATH

What is a link? • A shortcut to an existing file or directory across the directory tree • Advantage of link: – If you still change you program you would have to update the copy of the executable every time, no need with link • Command: ln -s source destination

Solution for your applications • If you want to include your own executables: – add them separately to path (cumbersome) – or create a directory that either contains all executables or links to them • Solution: – create cperlich/bin directory – add it to path: setenv PATH $HOME/bin: ${PATH} – create links to all you executable • But where did this $PATH and $HOME come from?

Environment variables • Now we are getting down and dirty with UNIX! • Whenever you log in, the OS executes a number of little scripts for you that define your environment (. login, . cshrc) • In particular you have a list of environment variables: take a look at : setenv • If you want to change the PATH permanently you have to change it in one of those scripts • These scripts are in your home directory and start with. (that is why you don’t see them)