Physical vs Logical Files Whats the Difference Who

  • Slides: 21
Download presentation
Physical vs Logical Files What’s the Difference? Who cares? Physical / Logical 13 -Sep-03

Physical vs Logical Files What’s the Difference? Who cares? Physical / Logical 13 -Sep-03 1

Physical vs Logical There are 2 places where it counts: 1. File operations (read

Physical vs Logical There are 2 places where it counts: 1. File operations (read / write; open / close) 2. File organization (where stuff is in the file) Physical / Logical 13 -Sep-03 2

Physical vs Logical We need to be aware of the physical perspective • Even

Physical vs Logical We need to be aware of the physical perspective • Even when we have no control over it • It still affects our program (what we don’t know can hurt us) • While we are working at the logical level • We can help; or get in the way – our choice Physical / Logical 13 -Sep-03 3

Logical View logical = how we (as programmers) see the file • The file

Logical View logical = how we (as programmers) see the file • The file is in one piece. • The file can be anything (ASCII, pictures, records, music). • Its sub-structure imposed by software that we design and write. Physical / Logical 13 -Sep-03 4

Physical View physical = how O/S sees the file • Usually split into in

Physical View physical = how O/S sees the file • Usually split into in chunks, the file may be scattered all over the place. • UNIX views a file as a stream of bytes. • The file’s sub-structure is none of our business (no peeking). Physical / Logical 13 -Sep-03 5

Logical View: File Organization File 1: ASCII “Luck is my middle name, ” said

Logical View: File Organization File 1: ASCII “Luck is my middle name, ” said Rincewind, indistinctly. “Mind you, my first name is Bad. ”[Interesting Times, T. Pratchett] File 2: Mixed records Record 1 Record 2 Record 3 Record 4 Record 5 File 3: An image Physical / Logical 13 -Sep-03 6

Physical View: File Organization* Directory: 6 blocks File 1 Track 9; sector 8, block

Physical View: File Organization* Directory: 6 blocks File 1 Track 9; sector 8, block 14 4 6 5 7 Track 9; sector 8, block 15 8 Track 9; sector 8, block 16 Track 9; sector 9, block 01 : 6 Track 9; sector 10, block 1 File 2 7 blocks 9 7 3 3 5 2 2 Track 3; sector 9, block 10 : Track 5; sector 12, block 8 File 3 6 4 1 10 blocks : 1 2 3 4 5 6 7 8 11 5 14 1 4 10 3 Track 2; sector 1, block 4 9 10 13 12 1 2 Track 3; sector 9, block 11 * Not exactly as shown Physical / Logical 13 -Sep-03 7

Logical View: File Operations “Luck is my middle name, ” said Rincewind, indistinctly. “Mind

Logical View: File Operations “Luck is my middle name, ” said Rincewind, indistinctly. “Mind you, my first name is Bad. ” [Interesting Times, T. Pratchett] • Open file (need to establish connection between logical and physical file) • While (not end-of-file) do – Read char – Do some stuff with it • Blaa Physical / Logical 13 -Sep-03 8

Physical View: File Operations <READ char>1 4 6 5 7 8 6 9 7

Physical View: File Operations <READ char>1 4 6 5 7 8 6 9 7 3 Program data space Memory 3 5 2 2 6 4 1 1 2 3 4 5 6 7 8 11 5 14 1 4 10 3 RTS gets read request ---- suspend program ----- 9 10 13 12 1 2 * Not exactly as shown Physical / Logical 13 -Sep-03 9

Physical View: File Operations <READ char>2 1 4 6 5 7 8 6 9

Physical View: File Operations <READ char>2 1 4 6 5 7 8 6 9 7 3 Program data space Memory 5 2 2 6 4 1 1 2 3 4 5 6 7 8 9 10 11 13 12 5 14 1 4 10 3 Locate block containing char (dir ; file-ptr) Load block into memory 3 1 2 * Not exactly as shown Physical / Logical 13 -Sep-03 10

Physical View: File Operations <READ char>3 1 4 6 5 7 8 6 9

Physical View: File Operations <READ char>3 1 4 6 5 7 8 6 9 7 3 Program data space Memory 5 2 2 6 4 1 1 2 3 4 5 6 7 8 9 10 11 13 12 5 14 1 4 10 3 Move designated char from I/O buffer to program data space ---resume program---- 3 1 2 * Not exactly as shown Physical / Logical 13 -Sep-03 11

Physical View: File Operations <READ char>4 1 4 6 5 7 8 6 9

Physical View: File Operations <READ char>4 1 4 6 5 7 8 6 9 7 3 Program data space Memory 5 2 2 6 4 1 1 2 3 4 5 6 7 8 9 10 11 13 12 5 14 1 4 10 3 Next read: Move designated char from I/O buffer to program data space ---resume program---- 3 1 2 * Not exactly as shown Physical / Logical 13 -Sep-03 12

Physical View: File Operations <READ char>5 1 4 6 5 7 8 6 9

Physical View: File Operations <READ char>5 1 4 6 5 7 8 6 9 7 3 Program data space Memory 5 2 2 6 4 1 1 2 3 4 5 6 7 8 9 10 11 13 12 5 14 1 4 10 3 Next read: Move designated char from I/O buffer to program data space ---resume program---- 3 1 2 * Not exactly as shown Physical / Logical 13 -Sep-03 13

Physical View: File Operations <READ char>6 1 4 6 5 7 8 6 9

Physical View: File Operations <READ char>6 1 4 6 5 7 8 6 9 7 3 Program data space Memory 5 2 2 6 4 1 1 2 3 4 5 6 7 8 9 10 11 13 12 5 14 1 4 10 3 Next read: Move designated char from I/O buffer to program data space ---resume program---- 3 1 2 * Not exactly as shown Physical / Logical 13 -Sep-03 14

Physical View: File Operations <READ char>7 2 4 6 5 7 8 6 9

Physical View: File Operations <READ char>7 2 4 6 5 7 8 6 9 7 3 Program data space Memory 5 2 2 6 4 1 1 2 3 4 5 6 7 8 9 10 11 13 12 5 14 1 4 10 3 Next read: Data NOT in memory… ---- suspend program ----Locate block containing char (dir ; file-ptr) Load block into memory 3 1 2 * Not exactly as shown Physical / Logical 13 -Sep-03 15

Physical View: File Operations <READ char>8 2 4 6 5 7 8 6 9

Physical View: File Operations <READ char>8 2 4 6 5 7 8 6 9 7 3 Program data space Memory 5 2 2 6 4 1 1 2 3 4 5 6 7 8 9 10 11 13 12 5 14 1 4 10 3 Move designated char from I/O buffer to program data space ---resume program---- 3 1 2 * Not exactly as shown Physical / Logical 13 -Sep-03 16

Physical View: File Operations <READ char>9 2 4 6 5 7 8 6 9

Physical View: File Operations <READ char>9 2 4 6 5 7 8 6 9 7 3 Program data space Memory 5 2 2 6 4 1 1 2 3 4 5 6 7 8 9 10 11 13 12 5 14 1 4 10 3 And so on 3 1 2 * Not exactly as shown Physical / Logical 13 -Sep-03 17

What we have learned so far: • We design our programs with the logical

What we have learned so far: • We design our programs with the logical view in mind. • We run our programs using our logical perspective; but the file still gets manipulated from the physical perspective. Physical / Logical 13 -Sep-03 18

Uh huh. That’s nice. So what. Physical / Logical 13 -Sep-03 19

Uh huh. That’s nice. So what. Physical / Logical 13 -Sep-03 19

What’s it to me…. . • Know your device (or O/S). • Match your

What’s it to me…. . • Know your device (or O/S). • Match your internal sub-structure to fit the device (but, what about portability? ) • Let your algorithms account for physical operations. • Be aware that access between physical blocks is likely to take more time than access inside physical blocks. Physical / Logical 13 -Sep-03 20

Summary • Physical organization of file (and hence behaviour at HW level may be

Summary • Physical organization of file (and hence behaviour at HW level may be different from logical organization. • Physical reads/writes may happen at different times from logical reads/writes. • We usually have little control over the physical view. Physical / Logical 13 -Sep-03 21