De presentatie wordt gedownload. Even geduld aub

De presentatie wordt gedownload. Even geduld aub

Best7-1 Les 7: Bestandssystemen "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible,

Verwante presentaties


Presentatie over: "Best7-1 Les 7: Bestandssystemen "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible,"— Transcript van de presentatie:

1 best7-1 Les 7: Bestandssystemen "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." Brian Kernighan

2 best7-2 Organisatie bestandssysteem IO-controle fysiek bestandssysteem bestandsorganisatie Logisch bestandssysteem Bestandsnamen Logische bloknummers Fysieke bloknummers Bestandssysteem: logisch Bestandssysteem: fysiek

3 best7-3 Overzicht Logisch bestandssysteem –Gegevensbestanden –directory's –Bestandssystemen Bestandsorganisatie –directory's –Gegevensbestanden –Vrije ruimte –Partities –Reservekopieën Optimalisaties

4 best7-4 Gegevensbestanden 8 0 N Attributen Operaties Types Toegangsmethoden Bestand = benoemde verzameling bij elkaar horende gegevens = eenheid van opslag. Gegevensbestand

5 best7-5 Attributen publieke naam systeemnaam versie plaats (data) de grootte eigenaar creatie-ogenblik creatie-programma protectie-informatie reservekopie-informatie ogenblik van laatste gebruik type (op sommige systemen) toegangsmethode Opgeslagen in een directorybestand Gegevensbestand: attributen

6 best7-6 Naamgeving String van letters,cijfers en leestekens, –Beperkt in lengte –Soms onderscheid kleine/hoofdletters (Unix, NTFS ), soms niet (Windows, FAT) –NTFS gebruikt unicode: βαДиהت 탁탢齩 Meestal ook bestandsextentie –8.3 notatie: abcdefgh.ijk –Via extensies worden applicaties geassocieerd

7 best7-7 Operaties op bestanden Win32UnixOmschrijving CreateFilecreatCreëer een bestand OpenFileopenOpen een bestand CreateProcessexecStart een proces Gegevensbestand: operaties

8 best7-8 Bestanden vs. open bestanden bestand open bestand #include int main() { char buffer[100]; int handle; handle = open (“test.txt”, O_RDWR | O_CREAT | O_TRUNC); write (handle, “1234567890”, 10); fsync (handle); lseek (handle, 0, SEEK_SET); read (handle, buffer, 10); buffer[10] = '\0'; printf ("String read = %s.\n", buffer); close (handle); return 0; }

9 best7-9 Operaties op open gegevensbestanden Win32UnixOmschrijving CloseHandlecloseSluit een bestand ReadFilereadLees data uit bestand WriteFilewriteSchrijf data naar bestand SetFilePointerlseekStel de lees/schrijfwijzer in SetEndOfFiletruncateStel de lengte van het bestand in

10 best7-10 Voorbeeldprogramma Unix Details: man 2

11 best7-11 Voorbeeldprogramma Windows if (!copyfile(argv[1], argv[2], false)) exit(3);

12 best7-12 Delen van open bestanden open bestand 1 open bestand 2 open bestand proces 1 proces 2 Bestand (1) Bestand (2) globale bestandentabel schijf lokale bestandentabel

13 best7-13 Bestandstypes directory's Speciale bestanden (Unix, zie I/O) Links, shortcuts Gegevensbestanden –ASCII: leesbaar –Binair: betekenis enkel zinvol voor programma dat indeling kent –Uitvoerbaar –Magic number s om type te bepalen Speciaal geval: uitvoerbaar bestand, OS kent indeling

14 best7-14 Toegangsmethoden Sequentiële toegang Directe toegang Geïndexeerde toegang Tegenwoordig: Directe toegang op byte-niveau

15 best7-15 Sequentiële toegang Toegangstijd naar een bepaalde record hangt af van de plaats van de record in het bestand. huidige positie reset read/write 3 operaties: - reset - read next - write next Toegangsmethode: sequentieel

16 best7-16 Directe toegang Toegangstijd naar een bepaalde record hangt niet af van de plaats van de record in het bestand. 2 operaties: - read n - write n 3 operaties: - seek n - read next - write next read/write seek n of Toegangsmethode: direct

17 best7-17 Geïndexeerde toegang Toegangsmethode: geïndexeerd

18 Directe toegang in Java best7-18 import java.io.File; import java.io.RandomAccessFile; import java.io.IOException; public class DemoRandomAccessFile { public static void main(String[] args) { try { RandomAccessFile raf = new RandomAccessFile(“test.txt”, "rw"); byte ch = raf.readByte(); System.out.println("Read first character of file: " + (char)ch); System.out.println("Read full line: " + raf.readLine()); raf.seek(raf.getFilePointer() - 10); raf.writeBytes(“???”); raf.seek(0); System.out.println("Read full line: " + raf.readLine()); raf.seek(file.length()); raf.writeBytes("This will complete the Demo"); raf.close(); } catch (IOException e) { System.out.println("IOException:"); e.printStackTrace(); } } }

19 best7-19 Overzicht Logische bestandssysteem –Gegevensbestanden –directory's –Bestandssystemen Bestandsorganisatie –directory's –Gegevensbestanden –Vrije ruimte –Partities –reservekopieën Optimalisaties

20 best7-20 directory's Directory Gegevensbestanden Operaties Types

21 best7-21 Operaties op directory's Win32UnixOmschrijving CreateDirectorymkdirMaak een nieuwe directory RemoveDirectoryrmdirLaat een directory weg FindFirstFileopendirOpen een directory FindNextFilereaddirLees een directory-element FindCloseclosedirSluit een directory MoveFilerenameHernoem een bestand SetCurrentDirectorychdirVerander van huidige directory DeleteFileunlinkLaat een bestand weg GetFileAttributesfstatLees een bestandsattribuut

22 best7-22 Directorytypes 1 niveau 2 niveaus Boomstructuur Acyclische graaf Graaf

23 best7-23 Eenniveaudirectory testdatamaildoc directory bestanden

24 best7-24 Tweeniveaudirectory testdatamaildoc User file directory (UFD) bestanden mailmarksmailrep usr1usr2usr3 Master file directory (MFD)

25 best7-25 Boomgestructureerde directory statmaildistfindcounthexdatamail spellbinprogs root progcopyprtexporderlistfind listobjspellalllastfirst

26 best7-26 Acyclische graafdirectory's listallwcount words dictspell list root listradew7 Symbolische link

27 best7-27 Links in Unix % ln -s ttt symlink % ls -al drwx--x--x 2 els users 1024 Dec 3 08:48. drwx--x--x 3 els users 1024 Dec 3 08:47.. lrwx--x--x 1 els users 3 Dec 3 08:48 symlink -> ttt -rw------- 1 tom users 23 Dec 3 08:48 ttt % cat symlink dit is een testbestand % ln ttt hardlink % ls -al drwx--x--x 2 els users 1024 Dec 3 08:49. drwx--x--x 3 els users 1024 Dec 3 08:47.. -rw------- 2 tom users 23 Dec 3 08:48 hardlink lrwx--x--x 1 els users 3 Dec 3 08:48 symlink -> ttt -rw------- 2 tom users 23 Dec 3 08:48 ttt % rm ttt % ls -al drwx--x--x 2 els users 1024 Dec 3 08:49. drwx--x--x 3 els users 1024 Dec 3 08:47.. -rw------- 1 tom users 23 Dec 3 08:48 hardlink lrwx--x--x 1 els users 3 Dec 3 08:48 symlink -> ttt % cat symlink cat: cannot open symlink: No such file or directory % cat hardlink dit is een testbestand

28 best7-28 Graafdirectory..mailcountbook avitc unhex root countunhex jim hyp hex...... % ls -al drwx--x--x 2 kdb digit 1024 Dec 3 08:49. drwx--x--x 3 kdb digit 1024 Dec 3 08:47..

29 best7-29 Overzicht Logische bestandssysteem –Gegevensbestanden –directory's –Bestandssystemen Bestandsorganisatie –directory's –Gegevensbestanden –Vrije ruime –Partities –Reservekopieën Optimalisaties

30 best7-30 Monteren van bestandssystemen schijf = subdirectory C:D:E: Monteren(bs) ~ openen(bestand)

31 best7-31 NFS : Network File System

32 best7-32 Virtueel bestandssysteem gebruiker kern http://en.wikipedia.org/wiki/List_of_file_systems VFS

33 best7-33 NFS Architectuur

34 best7-34 Overzicht Logische bestandssysteem –Gegevensbestanden –directory's –Bestandssystemen Bestandsorganisatie –directory's –Gegevensbestanden –Vrije ruimte –Partities –Reservekopieën Optimalisaties

35 best7-35 Organisatie van directory's naam1attrib naam2attrib naam3attrib naam4attrib naam5attrib naam6attrib naam1attrib naam2attrib naam3attrib naam4attrib naam5attrib naam6 Directory: f(naam) → adres_van_attributen Lineaire lijst of via hakselfunctie, of b-tree

36 best7-36 Organisatie van gegevensbestanden Contigue allocatie Gelinkte allocatie Geïndexeerde allocatie

37 best7-37 Histogram Windows (2010) log2(bestandsgrootte) DataProgramma’s aantal81 469179 545 kleinste00 grootste4 0458 520 192368 228 352

38 Cumulatieve distributie best7-38 > 50% bestanden < 8KiB >75 % bestanden < 64 KiB >90% bestanden < 1 MiB

39 best7-39 Contigue allocatie blokken test.c 3 2 a.out 7 3 test.out 0 1 directory 0 1 2 3 4 5 6 7 8 9 10 begin lengte blok met byte n = beginblok + n div blokgrootte b.v. CD-ROM (iso9660) Bestandsorganisatie: contigu

40 best7-40 Gelinkte allocatie blokken test.c 3 2 a.out 7 4 test.out 0 0 directory 0 1 2 3 4 5 6 7 8 9 10 begin einde blok met byte n = ( n div (blokgrootte-4)) de blok Bestandsorganisatie: gelinkt

41 best7-41 Allocatietabel blokken test.c 3 a.out 7 test.out 0 directory 0 1 2 3 4 5 6 7 8 9 10 blok met byte n = ( n div blokgrootte) de gelinkte blok Bestandsorganisatie: fat

42 best7-42 Indextabel blokken 0 - - - - 3 2 - - - 7 1 4 - - test.c 5 a.out 6 test.out 8 directory 0 1 2 3 4 5 6 7 8 9 10 blok met byte n = indexblok[n div blokgrootte] Bestandsorganisatie: geïndexeerd

43 best7-43 Unix: inodes blokken inode 0 1 2 3 4 5 6 7 8 9 10 Info 12 directe wijzers … … … … Bestandsorganisatie: inode

44 best7-44 Unix Inode OffsetSizeNameDescription 0x0__le16i_mode 0x2__le16i_uidLower 16-bits of Owner UID. 0x4__le32i_size_loLower 32-bits of size in bytes. 0x8__le32i_atimeLast access time, in seconds since the epoch. 0xC__le32i_ctimeLast inode change time, in seconds since the epoch. 0x10__le32i_mtimeLast data modification time, in seconds since the epoch. 0x14__le32i_dtimeDeletion Time, in seconds since the epoch. 0x18__le16i_gidLower 16-bits of GID. 0x1A__le16i_links_countHard link count. 0x1C__le32i_blocks_lo 0x20__le32i_flags 0x244 bytesUnion osd1: 0x2860 bytesi_block[15] (12+1+1+1)Block map or extent tree. See the section "The Contents of inode.i_block". 0x64__le32i_generationFile version (for NFS). 0x68__le32i_file_acl_loLower 32-bits of extended attribute block. 0x6C__le32i_size_high / i_dir_aclUpper 32-bits of file size. 0x70__le32i_obso_faddr(Obsolete) fragment address. 0x7412 bytesUnion osd2: 0x80__le16i_extra_isizeSize of this inode - 128. 0x82__le16i_checksum_hiUpper 16-bits of the inode checksum. 0x84__le32i_ctime_extraExtra change time bits. This provides sub-second precision. 0x88__le32i_mtime_extraExtra modification time bits. This provides sub-second precision. 0x8C__le32i_atime_extraExtra access time bits. This provides sub-second precision. 0x90__le32i_crtimeFile creation time, in seconds since the epoch. 0x94__le32i_crtime_extraExtra file creation time bits. This provides sub-second precision. 0x98__le32i_version_hiUpper 32-bits for version number.

45 best7-45 inodes proces 1 proces 2 Globale bestanden- tabel directory inodes schijf kern

46 best7-46 ijle bestanden main() { int h = open("test.dat", O_CREAT|O_WRONLY, 0777); lseek(h, 100000, SEEK_SET); write(h, "Hallo", 5); close(h); } % ls -al test.dat -rwx--x--x 1 kdb users 100005 Nov 15 20:13 test.dat % du –b test.dat 8192 test.dat Bestand: ijl

47 best7-47 MFT-record Bestand van 9 blokken in 3 runs MFT record

48 best7-48 MFT-records

49 Directory best7-49

50 Compressie best7-50

51 best7-51 NTFS Streams c:\>echo Hallo > test.txt c:\>dir 15/11/2004 19:46 8 test.txt c:\>more test.txt Hallo c:\>echo Nevenboodschap >test.txt:boodschap c:\>dir 15/11/2004 19:46 8 test.txt C:\>more test.txt Hallo C:\>more test.txt:boodschap Nevenboodschap NTFS: streams

52 best7-52 Quota

53 best7-53 Defragmentatie & Compactering schijf

54 best7-54 Overzicht Logische bestandssysteem –Gegevensbestanden –directory's –Bestandssystemen Bestandsorganisatie –directory's –Gegevensbestanden –Vrije ruimte –Partities –Reservekopieën Optimalisaties

55 best7-55 Beheer van vrije ruimte: bitmap Soms is het beheer gratis: b.v. FAT blokken 0 1 2 3 4 5 6 7 8 9 10 11111001000... In gebruik Bestandssysteem: vrije ruimte

56 best7-56 Beheer van vrije ruimte: links blokken 0 1 2 3 4 5 6 7 8 9 10 vrij

57 best7-57 Beheer van vrije ruimte: wijzerblok blokken 0 1 2 3 4 5 6 7 8 9 10 vrij

58 best7-58 Consistentie controleren 01000111 10111000 01000111 10011000 01000111 10121000 vrij 01001111 10111000 1 bezet 1 0 01000211 10111000 vrij bezet 1 0 0 1 2 3 4 5 6 7 1

59 best7-59 Loggestructureerde bestandssystemen logbestand transacties Bestandssysteem: loggestructureerd

60 best7-60 Overzicht Logische bestandssysteem –Gegevensbestanden –directory's –Bestandssystemen Bestandsorganisatie –directory's –Gegevensbestanden –Vrije ruimte –Partities –Reservekopieën Optimalisaties

61 best7-61 Partities of volumes Partitie A Partitie B Partitie C Partitie D schijf 1 schijf 2 schijf 3 schijf 4 partitie = logische schijf BB MBR

62 best7-62 Indeling partitie (cooked) BCBPCBFCBrootdata Boot block Super block+free space mgmt i-nodes Root directory Partition boot sector (8 KiB) + BIOS Parameter Block (BPB) Master File Table Unix File System ( UFS ) NTFS

63 best7-63 Overzicht Logische bestandssysteem –Gegevensbestanden –directory's –Bestandssystemen Bestandsorganisatie –directory's –Gegevensbestanden –Vrije ruimte –Partities –Reservekopieën Optimalisaties

64 best7-64 Reservekopie ( back-up ) Fysieke reservekopie Logische reservekopie Bescherming tegen Hardwareproblemen Ongelukjes

65 best7-65 Fysieke reservekopie Schijfblokken 0..N reservekopie: fysiek

66 best7-66 Logische reservekopie Schijfblokken 0..N Bestand per bestand reservekopie: logisch

67 best7-67 Logische incrementele reservekopieën reservekopie: incrementeel

68 best7-68 Overzicht Logische bestandssysteem Bestandsorganisatie Optimalisaties –Vergrendelen bestanden –Variabele blokgrootte –Beperkte dynamische informatie –RAM-disk –Virtuele schijf –Disk caches –Free-behind - Read-ahead –Compressie

69 Vergrendelen bestanden best7-69 import java.io.*; import java.nio.channels.*; public class LockingExample { public static void main(String arsg[]) throws IOException { RandomAccessFile raf = new RandomAccessFile("file.txt", "rw"); // get the channel for the file FileChannel ch = raf.getChannel(); // this locks the first half of the file - exclusive FileLock exclusiveLock = ch.lock(0, raf.length()/2, false); /** Now modify the data... */ exclusiveLock.release(); // this locks the second half of the file - shared FileLock sharedLock = ch.lock(raf.length()/2+1, raf.length(), true); /** Now read the data... */ sharedLock.release(); } catch (java.io.IOException ioe) { } finally { } } Mandatory locks: hard afgedwongen Advisory locks: kunnen genegeerd worden Bestand: lock

70 best7-70 Blokgrootte Unix GB

71 best7-71 Variabele blokgrootte Kleine blokken voor kleine bestanden Grote blokken voor grote bestanden

72 best7-72 Beperkte dynamische informatie Voornamelijk toegangstijdstippen

73 best7-73 RAM-disk / tempfs Partitie A Partitie B schijf BB MBR Fysiek geheugen

74 Virtuele schijf best7-74 Partitie A BB MBR bestand Virtuele schijf BB MBR

75 best7-75 Disk caches Spoorbuffer hoofdgeheugen CVE Disk cache

76 best7-76 Free-behind Bij sequentieel lezen is het beter om een gelezen blok vrij te geven bij het inlezen van het volgende blok. Read-ahead Bij sequentieel lezen een aantal extra sequentiële blokken inlezen.

77 best7-77 Schijfcompressie Verhoogt de capaciteit van de schijf Verhoogt de effectieve bandbreedte naar de schijf

78 best7-78


Download ppt "Best7-1 Les 7: Bestandssystemen "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible,"

Verwante presentaties


Ads door Google