Title: Secondary Storage Devices and Records
1Secondary Storage Devices and Records
2Make up of Disk Devices
- Bytes
- Capacity
- Disk Pack
- Track
- Sector
- Cylinder
3Illustrations Disk Surface Disk Pack
4Accessing the Disk
- Amount of data transferred
- Block address
- Read/Write Head
- Seek
- Rotational delay (latency)
- Block transfer time
5Seagate Cheetah 73
Configuration Number of Discs (physical)
12 Number of Heads (physical) 24 Total
Cylinders 14,100 Bytes Per
Sector 512
Capacity/Interface Formatted Capacity 73.4
Gbytes Interface Type 80-pin Performance
Transfer Rates Internal Rate (min) 28
Mbits/sec Internal Rate (max) 427
Mbits/sec Formatted Int Rate (min) 26.7
Mbits/sec Formatted Int Rate (max) 40.2
Mbits/sec External (I/O) Rate (max1 60
MBytes/secAvg Formatted Rate 35.5
MBytes/sec Seek Times Average Time, Read 5.6
msec typical Average Time, Write 6.2 msec
typical Track-to-Track, Read 0.6 msec
typical Track-to-Track, Write 0.9 msec
typical Average Latency 2.99 msec Other
Default Buffer (cache) 4,096 Kbytes Spindle
Speed 10,000 RPM
6File Allocation
- Clusters
- Allocation units
- Fragmentation
- File Allocation Table (FAT)
- UNIX
- Super block
- Inodes
- Data blocks
7UNIX Inode Structure
8Journey of a Byte - reading
- thefile.read(ch, 1)
- Read sector (or minimum access amount) containing
info if not already there - Copy character from buffer to user program
location
9Journey of a Byte - writing
- thefile.write(ch, 1)
- Read sector where info will be if not already
there - Copy character from user program location to
buffer - Write buffer to sector on disk
Sector Writing to
10Buffer Management
- Single buffer
- Double buffer
- Buffer pooling
- Least recently used
- Least used
11Sequential Organization
- Sequential access
- Read block
- Take out records one by one
- Direct access by location
- Fixed length records
- Relative record number (rrn)
- Byte offset (rrn-1) sizeof record
- Variable length records
- Byte offset must be known
- Direct access by key
12Sequential Organization (cont)
- Reclaiming Space
- Off line - compaction
- On the fly
- Fixed length records
- Avail stack
- Variable length records
- First fit placement strategy
- Best fit placement strategy
- Worst fit placement strategy
13From Bytes to Fields
- Values that describe attributes
- Fixed length
- Variable length
- Size indicator
- Delimiter
10John Smith9Kutztown2PA
John SmithKutztownPA
14From Fields to Records
- Collection of fields that describes one entity
- Fixed length
- Fixed length fields
- Variable length fields, always same number of
bytes
15From Fields to Records (cont)
- Variable length
- Size recorded
- Delimiter
16From Records to Blocks
- Recall file transfer done by block
- Several records per block
- Logical structure pick up entire block
- All in order
- One at a time
17Recall API for File Class
- Open,Create,Close as before
- Other operations do the buffer access
- Write
- Pack record into buffer
- Write buffer to file
- Read
- Read in buffer from file
- Unpack record from buffer
- Append
- Seek to end of file
- Write record with location of -1
18Variable Length Information Files
- Variable length fields and/or records
- Buffer needed to collect data
- Buffer knows how data stored
- Operations for buffer
- Pack a field into a buffer
- Unpack a field from a buffer
- Read from file into buffer
- Write from buffer to file
19API for a Buffer Class
//Copies the size into the buffer then the size
bytes from field to buffer //Return number of
bytes packed int Pack(void field, int
size) //Copies the size from the buffer then
copies that many bytes from buffer to field //If
the size found is gt maxAllowed, Unpack returns
-1 //Return the value of size, the number of
bytes unpacked int Unpack(void field, int
maxAllowed) //Sets marker back to beginning of
buffer to begin packing or unpacking a
record void ResetBuffer()
20API for a Buffer Class (cont)
//If recref ! -1, reads the record at recref
from file into the buffer //If recref -1, reads
the currrent record from file into the
buffer //Return relative record number of the
record read int Read(istream file, int
recref-1) //If recref ! -1, writes the record
in the buffer to relative record number
recref //If recref -1, writes the record in the
buffer to the current location in the
file //Return relative record number of the
record written int Write(ostream file, int
recref-1)
21Using the buffer
class person public ..
private string name int age
- Save
- person gal
- gal.Pack(b) //put bytes from object into buffer
- b.Write(f) //write buffer to file
- Class must provide Pack
- Example
- b.Pack(name.c_str(), name.length() 1)
- b.Pack(age, sizeof(int))
22Using the buffer (cont)
- Retrieve
- person gal
- b.Read(f) //read into buffer from file
- gal.Unpack(b) //put bytes into object
- Class must provide Unpack
- Example
- Char cnameMAX
- b.Unpack(cname, MAX)
- name cname
- b.Unpack(age, sizeof(int))