file structures 1
DESCRIPTION
file structures conceptsTRANSCRIPT
Organizing file for better performance of disk
File Structures
Introduction to File Structures Applications of File Structures File structures in software's File organizer in windows File organizing in ubuntu Chapter 1 : File processing operations Road map of Syllabus Text book
Topics under discussionTopics under discussion
2B.Meena,Asst.Prof.,IT Dept,ANITS
Is a combination of representations for data in files
Operations for accessing data Allows applications to read, write, modify data Very important in needs of applications and tremendous variety of applications
File structure
3B.Meena,Asst.Prof.,IT Dept,ANITS
For representing a city region telephone network. store a set of fixed key words which are referenced very frequently.
represent an image in the form of a bitmap. implement back functionality in the internet browser. implement printer spooler so that jobs can be printed in the order of their arrival.
record the sequence of all the pages browsed in one session.
store information about the directories and files in a system.
Applications
4B.Meena,Asst.Prof.,IT Dept,ANITS
File structures in software's
5B.Meena,Asst.Prof.,IT Dept,ANITS
Programming files – c ,cpp,java,html,xml…. Database files - dbase ,foxpro,oracle-log,dmp… Log data and software files … Text files – doc,txt,docx…
6B.Meena,Asst.Prof.,IT Dept,ANITS
File organizer in windows
7B.Meena,Asst.Prof.,IT Dept,ANITS
In ubuntu
8B.Meena,Asst.Prof.,IT Dept,ANITS
Why Study File Structure Design?I. Data Storage
Computer data can be stored in three kinds of locations:
Primary Storage ==> Memory [Computer Memory] Secondary Storage
[Online Disk/ Tape/ CDRom that can be accessed by the computer]
Tertiary Storage ==> Archival Data
[Offline Disk/Tape/ CDRom not directly available to the computer.]
OurFocus
9B.Meena,Asst.Prof.,IT Dept,ANITS
Why Study File Structure Design?II. Memory versus Secondary Storage
Secondary storage such as disks can pack thousands of megabytes in a small physical location.
Computer Memory (RAM) is limited. However, relative to Memory, access to secondary storage is extremely slow [E.g., getting information from slow RAM takes 120. 10-9 seconds (= 120 nanoseconds) while getting information from Disk takes 30. 10-3 seconds (= 30 milliseconds)]
10B.Meena,Asst.Prof.,IT Dept,ANITS
Physical file and logical file Opening files Closing files Reading and writing Seeking Special characters in unix Unix directory structure Physical devices and logical files File related header files Unix file system commands
Chapter 1 : file processing operations
11B.Meena,Asst.Prof.,IT Dept,ANITS
Physical file and logical file
12B.Meena,Asst.Prof.,IT Dept,ANITS
C FILE *fp fp=fopen(“student.txt”,”r”); student.txt
CPP fstream f1; f1.open(“student.txt”,ios::in);
In c and cpp
13B.Meena,Asst.Prof.,IT Dept,ANITS
Physical file : Actually exists on the storage File known by computer OS and appears in the directory Logical file : file seen by the program Allows to describe the operations performed on physical
file
14B.Meena,Asst.Prof.,IT Dept,ANITS
15
Opening Files
Once we have a logical file identifier hooked up to a physical file or device,
need to declare what we intend to do with the file:
Open an existing file Create a new file
That makes the file ready to use by the programWe are positioned at the beginning of the file and are ready to read or write.
B.Meena,Asst.Prof.,IT Dept,ANITS
16
Opening Files in C and C++ : unix syntax fd = open(filename, flags [, pmode]);
fd = file descriptor filename = physical file name flags = O_APPEND, O_CREAT, O_EXCL, O_RDONLY,
O_RDWR, O_TRUNC, O_WRONLY. pmode = rwe rwe rwe
owner group world
B.Meena,Asst.Prof.,IT Dept,ANITS
B.Meena,Asst.Prof.,IT Dept,ANITS 17
FILE *fopen( const char * filename, const char * mode );
B.Meena,Asst.Prof.,IT Dept,ANITS 18
B.Meena,Asst.Prof.,IT Dept,ANITS 19
20
Closing Files
Makes the logical file name available for another physical file (it’s like hanging up the telephone after a call).
Ensures that everything has been written to the file [since data is written to a buffer prior to the file].
Files are usually closed automatically by the operating system (unless the program is abnormally interrupted).
B.Meena,Asst.Prof.,IT Dept,ANITS
21
Reading
Read(Source_file, Destination_addr, Size)
Source_file = location the program reads from, i.e., its logical file name
Destination_addr = first address of the memory block where we want to store the data.
Size = how much information is being brought in from the file (byte count).
B.Meena,Asst.Prof.,IT Dept,ANITS
B.Meena,Asst.Prof.,IT Dept,ANITS 22
23
Writing
Write(Destination_file, Source_addr, Size)
Destination_file = the logical file name where the data will be written.
Source_addr = first address of the memory block where the data to be written is stored.
Size = the number of bytes to be written.
B.Meena,Asst.Prof.,IT Dept,ANITS
B.Meena,Asst.Prof.,IT Dept,ANITS 24
25
Seeking A program does not necessarily have to read through a
file sequentially: It can jump to specific locations in the file or to the end of file so as to append to it.
The action of moving directly to a certain position in a file is often called seeking.
Seek(Source_file, Offset) Source_file = the logical file name in which the seek will occur Offset = the number of positions in the file the pointer is to be
moved from the start of the file.
B.Meena,Asst.Prof.,IT Dept,ANITS
B.Meena,Asst.Prof.,IT Dept,ANITS 26
B.Meena,Asst.Prof.,IT Dept,ANITS 27
B.Meena,Asst.Prof.,IT Dept,ANITS 28
B.Meena,Asst.Prof.,IT Dept,ANITS 29
30
Special Characters in Files I
Sometimes, the operating system attempts to make “regular” user’s life easier by automatically adding or deleting characters for them.
F6 Ctrl – z
B.Meena,Asst.Prof.,IT Dept,ANITS
31
The Unix Directory Structure
The Unix File System is a tree-structured organization of directories. With the root of the tree represented by the character “/”.
Each directory can contain regular files or other directories.
The file name stored in a Unix directory corresponds to its physical name.
B.Meena,Asst.Prof.,IT Dept,ANITS
B.Meena,Asst.Prof.,IT Dept,ANITS 32
33
Physical Devices and Logical Files Magnetic disks or tapes can be thought of as files and so can the keyboard and the console.
No matter what the physical form of a Unix file (real file or device), it is represented in the same way in Unix: by an integer.
B.Meena,Asst.Prof.,IT Dept,ANITS
34
Stdout, Stdin, Stderr
Stdout --> Console fwrite(&ch, 1, 1, stdout); Stdin --> Keyboard fread(&ch, 1, 1, stdin); Stderr --> Standard Error (again, Console) [When the compiler detects an error, the error message is written in this file]
B.Meena,Asst.Prof.,IT Dept,ANITS
35
I/O Redirection and Pipes < filename [redirect stdin to “filename”] > filename [redirect stdout to “filename”] program1 | program2 [take any stdout output from program1 and use it in place of any stdin input to program2.
E.g., list | sort
B.Meena,Asst.Prof.,IT Dept,ANITS
36
Unix System Commands
cat filenames --> Print the content of the named textfiles. tail filename --> Print the last 10 lines of the text file. cp file1 file2 --> Copy file1 to file2. mv file1 file2 --> Move (rename) file1 to file2. rm filenames --> Remove (delete) the named files. chmod mode filename --> Change the protection mode on the named file.
ls --> List the contents of the directory. mkdir name --> Create a directory with the given name. rmdir name --> Remove the named directory.
B.Meena,Asst.Prof.,IT Dept,ANITS
37B.Meena,Asst.Prof.,IT Dept,ANITS
B.Meena,Asst.Prof.,IT Dept,ANITS 38
Text book
39B.Meena,Asst.Prof.,IT Dept,ANITS
Look up the operations equivalent to open,close,create,read,write, seek in COBOL,Ada,Fortran. compare them with c and c++
How do you use fseek, illustrate What is the difference between pmode,O_RDWR A couple of years ago a company bought a new cobol compiler . One difference between the new compiler and old one is , it did not automatically close files when program execution terminates , where as old compiler did . What sorts of problems would this cause ?
Assignment
B.Meena,Asst.Prof.,IT Dept,ANITS 40
Look up the unix command wc . Execute the following in unix and explain why it gives no.of files in ls|wc-c
In some typical environments such as unix , dos, all the following represent to move the data from one place to another : scanf, fgetc , read , cat , fscanf , gets , < ,main(argc,argv) , getc, fgets , |
Describe which are quite useful , which of them belong to c++ and OS.
Implement tail –n command in your own way
Date of submission : 07-07-14
B.Meena,Asst.Prof.,IT Dept,ANITS 41