file structures 1
DESCRIPTION
file structures conceptsTRANSCRIPT
![Page 1: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/1.jpg)
Organizing file for better performance of disk
File Structures
![Page 2: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/2.jpg)
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
![Page 3: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/3.jpg)
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
![Page 4: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/4.jpg)
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
![Page 5: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/5.jpg)
File structures in software's
5B.Meena,Asst.Prof.,IT Dept,ANITS
![Page 6: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/6.jpg)
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
![Page 7: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/7.jpg)
File organizer in windows
7B.Meena,Asst.Prof.,IT Dept,ANITS
![Page 8: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/8.jpg)
In ubuntu
8B.Meena,Asst.Prof.,IT Dept,ANITS
![Page 9: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/9.jpg)
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
![Page 10: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/10.jpg)
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
![Page 11: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/11.jpg)
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
![Page 12: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/12.jpg)
Physical file and logical file
12B.Meena,Asst.Prof.,IT Dept,ANITS
![Page 13: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/13.jpg)
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
![Page 14: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/14.jpg)
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
![Page 15: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/15.jpg)
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
![Page 16: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/16.jpg)
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
![Page 17: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/17.jpg)
B.Meena,Asst.Prof.,IT Dept,ANITS 17
![Page 18: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/18.jpg)
FILE *fopen( const char * filename, const char * mode );
B.Meena,Asst.Prof.,IT Dept,ANITS 18
![Page 19: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/19.jpg)
B.Meena,Asst.Prof.,IT Dept,ANITS 19
![Page 20: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/20.jpg)
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
![Page 21: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/21.jpg)
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
![Page 22: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/22.jpg)
B.Meena,Asst.Prof.,IT Dept,ANITS 22
![Page 23: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/23.jpg)
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
![Page 24: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/24.jpg)
B.Meena,Asst.Prof.,IT Dept,ANITS 24
![Page 25: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/25.jpg)
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
![Page 26: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/26.jpg)
B.Meena,Asst.Prof.,IT Dept,ANITS 26
![Page 27: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/27.jpg)
B.Meena,Asst.Prof.,IT Dept,ANITS 27
![Page 28: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/28.jpg)
B.Meena,Asst.Prof.,IT Dept,ANITS 28
![Page 29: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/29.jpg)
B.Meena,Asst.Prof.,IT Dept,ANITS 29
![Page 30: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/30.jpg)
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
![Page 31: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/31.jpg)
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
![Page 32: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/32.jpg)
B.Meena,Asst.Prof.,IT Dept,ANITS 32
![Page 33: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/33.jpg)
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
![Page 34: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/34.jpg)
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
![Page 35: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/35.jpg)
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
![Page 36: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/36.jpg)
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
![Page 37: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/37.jpg)
37B.Meena,Asst.Prof.,IT Dept,ANITS
![Page 38: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/38.jpg)
B.Meena,Asst.Prof.,IT Dept,ANITS 38
![Page 39: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/39.jpg)
Text book
39B.Meena,Asst.Prof.,IT Dept,ANITS
![Page 40: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/40.jpg)
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
![Page 41: File Structures 1](https://reader035.vdocuments.mx/reader035/viewer/2022062304/55cf9291550346f57b97883f/html5/thumbnails/41.jpg)
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