File Organisation Simple Structure1
File Organisation Simple Structure1
Year 2023-2024.
1
PLAN
Introduction.
Remember.
File Madeling.
Acces Methode.
Global Organisation of blocks
Internal Organisation of bloks
Taxonomy of simple file structure
Conclusion.
2
OBJECTIVES
define file organisation.
another
3
Introduction
we use the term file organisation to refer to the structure of a file (especially a data
file) defined in terms of its components and how they are mapped onto backing store.
Any given file organisation supports one or more file access methods. Access
method is any algorithm used for the storage and retrieval of records from a data file
by determining the structural characteristics of the file on which it is used.
4
Remember
A file is the concept by which a program or application stores data in SM. Files are
used at different levels of abstraction with different semantics
System level
Level application
5
Level application
File(level application)
6
Remarque
A typed file consists of individual data records. The records are accessed by means of
special operations for files (e.g. in Pascal: read(f,e), write(f,e), reset(f), ...).
With untyped files, the content of a file is read line by line. Conversely, the file is
written line by line. The data records of an untyped file can be of different lengths.(ex in
C : FILE *).
7
System level (physical level)
Record1 Record4 Record7 Record(n-2)
Record2 Record5 Record8 Record2(n-1)
Record3 Record6 Record9 …………… Record(n)
8
Remarque
The system maintains a special area of limited size in the MC (the buffer cache),
which allows it to keep copies of a few physical blocks in the MC, selected
according to certain strategies (for example, the most frequently used ones).
When an application requests to read a particular record, the system first checks
that the block is not already in MC (in the buffer zone). If this is the case, the
record is sent directly to the application without any physical reading.
9
Modeling file
The MS is modelled by a contiguous zone of sequentially numbered blocks (these
numbers represent the block addresses), which are contiguous zones of bytes of the
same size
To be able to manage a file, the system needs to know information about its
characteristics: the blocks it uses, the way it is organised, the associated access rights,
etc.
11
Modeling file
For a particular type of file system, block 0 could be reserved to contain a table,
each row of which contains information about the characteristics of a file (name,
size, blocks used, etc.). When an application wants to open a file with a given
name, the system retrieves the information from this table.
12
Access Methods
A file structure (access method) consists of the definition of :
- a way of organising the blocks of an MS file
- the placement of records within blocks
- the implementation of access operations (search, insert, delete, etc.).
The aim of file structures is to optimise access performance (execution time and
memory occupation).
13
Global organisation of the blocks
File as a list
File as a table
Linked organisation
Contiguous organisation
14
Remarques
The properties required to manipulate a file seen as an array are, for example, :
The number of the first block,The number of the last block (or the number of
blocks used).
For a file seen as a list, it would be sufficient to know the number of the first block
(the head of the list), because in each block there is the number of the next block
(like the next field in a list). In the last block, the number of the next block can be
set to a special value (for example, -1) to indicate the end of the list.
15
2- Internal organisation of blocks
Variable Length
Fixed Length
16
2.1 A fixed length record
An array of records of the same type can be stored in each block..
17
2.2 Variable length record
To separate the records from each other , you can either use a special character ('#'), or prefix the
start of the record with their size (in a fixed number of positions). In the example below, we use 3
positions to indicate the size of the records.
...|0|2|7|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|0|1|7|b|b|b|b|b|b|b|b|b|b|b|b|b|
b|0|3|7|c|c|c|.......|c|c|.....
<-------------------------------------------------> <--------------------------------> <----------....------>
18
An example of the declaration of a block type that can be used in the definition of a file seen as a
list with variable record format (size)
19
Overlapping
If you want to insert a new record into a block that is not yet full, and where the
remaining empty space is not sufficient to contain the entire record, the record is split
into 2 parts so that the first part occupies all the empty space in the block in question,
The remainder (the 2nd part) is inserted into a new block assigned to the file. The
record is then called the record spans 2 blocks.
20
3) Taxonomy of simple file structure
the leaves of the following tree represent the 12 simple access methods
Simple structure
T L
O ~O O ~O
F V F V F V F V
C ~C C ~C C ~C C ~C
21
Remarque 1
Utilisons la notation suivante:
T : for file seen as table, L : fo file seen as list
O : for order file , ~O : for no order file
F : for fixed length record, V :for variable length record
C : with overlapping , ~C : without overlapping
22
Example 1
For example, the T ~O VC method represents the organisation of a file seen as a table (T),
not ordered (~O), with records of variable size (V) and accepting overlaps between blocks
(C):
23
Exemple 2
In the case of a LOF file (file seen as a list, ordered with fixed-size records), each
block may contain for example, an array of records (tab), an integer indicating the
number of records in the array ( nb) and an integer to keep track of the next block in
the list (next):
The search is sequential, the insertion causes intra-block (to keep the order of the records)
and the deletion can be logical or physical.
24
Example 3
“TOF” type file (file seen as an array, ordered with fixed-size records) .
The initial load operation consists of constructing an ordered file with n initial records,
leaving a little space in each block. This will help minimize offsets that may be caused by
future insertions. Searching for a record is dichotomous (fast).
25
const
b = 30; // maximum block capacity (number of records)
type
Trecor = structure // Record structure :
del : boolean; // Boolean for logical deletion
key : typeanyth;
field2 : typeanyth;
field3 :typeanyth;...
end;
26
var
F : File of Tbloc Buffer buf Header(integer, integer);
/* Description of the file header: The header contains two integer type characteristics.
- the first is used to keep track of the number of blocks used (or the logical number of
the last block of the file) - the second will serve as an insertion counter to be able to
quickly calculate the loading factor, and therefore see if there is a need to reorganize
the file. */
27
Initial loading( namef : charaters; n : integer; u : real )
// u is a real number between 0 and 1 and indicates the desired charge rate at the start
var
e : Trecor;
i,j,k : integerr;
BEGIN
OPEN(F, namef, 'N' ); // a new file
i ← 1; // block number to fill
j ← 1; // record number in the block
write(‘List records in ascending order by key:’ );
FOR k←1 , n
Read ( e );
IF j <= u*b // e.g. if u=0.5, the blocks will be filled up to b/2 records
buf.tab[j] ← e
j ← j+1;
ELSE // j > u*b : buf must be written to disc
buf.NB = j-1;
WriteBlock( F, i, buf );
buf.tab[1] ← e; // the kth record will be placed in the next block, at position 1
i ← i+1;
j ← 2;
ENDIF
ENDFOR
// at the end of the loop, there are still records in buf that have not been saved to disk
buf.NB ← j-1;
WriteBlock( F, i, buf );
// update the header (the number of the last block and the insertion counter)
Ass-header( F, 1, i );
Ass-header( F, 2, n );
Close( F )
FIN // Initial loading 28
Search( c:typeanyth; namef:charaters; var find:bool; var i,j:integer )
var
bi, bs, inf, sup : integer;
stop : boolean;
BEGEIN
OPEN( F, namef, 'A' );
bs ← header( F,1 ); // the number of the last block
bi : = 1; // the number of the first block
found ←false; stop ← false; j ← 1;
While ( bi <= bs and no found and No stop )
i ← (bi + bs) div 2; // the middle block between bi an bs
ReadBlock( F, i, buf );
IF( c >= buf.tab[1].cle and c <= buf.tab[buf.NB].cle )
// dichotomous search inside the block (in the buf variable).
inf ← 1; sup ← buf.NB;
While (inf <= sup and No found)
j : = (inf + sup) div 2;
IF (c = buf.tab[j].cle) Found ← true
ELSE
IF (c < buf.tab[j].cle) sup ← j-1
ELSE inf ← j+1
ENDIF
ENDIF
ENDWHILE
IF ( Non Trouv ) j ← inf ENDIF
// the end of the internal search. j indicates the place where c is to be found.
stop ← true
ELSE // no ( c >= buf.tab[1] .cle and c <= buf.tab[buf.NB] .cle )
IF ( c < buf.tab[1].cle )
bs ← i-1
ELSE // c > buf.tab[buf.NB] .cle
bi ← i+1
ENDIF
ENDIF
ENDWHILE
IF( Non Trouv ) i ← bi ENDIF
close( F )
END 29
4. Conclusion
The type of organisation chosen and the storage medium used will determine
how the stored data is accessed.
References
Mc BELAID et Sabiha LIMAME née MERZOUK ,Fichiers Organisation
Accès,les pages bleues internationales Maison d’ édition pour l’enseignement et
la formation, ISBN: 978-9947-850-71-8
https://sites.google.com/a/esi.dz/hidouci/competences-professionnelles/algo2
30
TOVC
Internal
Taxonomy
Organisation Fixed length
TOF
record
TOV C
TOF
TOVC
Simple File Organisation Variable
Structure length record
TOVC
LOVC
LOF Global
LOVC LOVC Organisation
LOF
LOVC
File as Table(Array)
File as List