1 / 23

Files

Files. uniform logical view of information storage mapped to physical devices: magnetic disks, magnetic tapes, and optical disks non-volatile ( ถึงไฟดับข้อมูลก็ยังอยู่ ต่างจากพวก volatile เช่น RAM). Physical device ไม่ได้ uniform. File Attributes. Name Identifier (id) Type

leal
Download Presentation

Files

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Files uniformlogical view of information storage mapped to physical devices: magnetic disks, magnetic tapes, and optical disks non-volatile (ถึงไฟดับข้อมูลก็ยังอยู่ต่างจากพวก volatile เช่น RAM) Physical device ไม่ได้ uniform File Attributes Name Identifier (id) Type Location Size Protection Time, date, and user identification ข้อมูลที่อยู่กระจัดกระจายกันจะอ่านเขียนได้ช้ากว่า (ทำ defragment)

  2. File Operations Creating a file Writing a file Reading a file Repositioning within a file (seek) Delete a file Truncating a file Appending, renaming, and copy Open-file table contains all information about open files.Per-process table tracks all files that a process has open. System-wide table contains process independent information. open() returns a pointer to the file in open-file (per-process) table. close() removes the entry in per-process table and decrease file-open count in system-wide table. มี 1 table ต่อ 1 process มี 1 table ต่อ 1 OS

  3. Information associated with an open file File pointer File-open countDisk location of the file Access rights System-wide table Storage File A File-open countDisk location File A File A File pointerAccess rights Per-process table Per-process table

  4. File Locking in Java ถ้า shared lock แล้ว จะ exclusive lock ไม่ได้ Shared (r) several processes can acquire the lock concurrently. Exclusive (w) only one process at a time can acquire such a lock. (prevent reading) File locking in Java (in code Fig 10.1) Exclusive locks 1. Mandatory: OS ensures locking integrity. 2. Advisory: it’s up to software developers (acquired & released). Windows mandatory lockingUnix advisory locking Homework !!!

  5. File Types

  6. Magic number http://en.wikipedia.org/wiki/Magic_number_(programming)

  7. File Structure OS requires that an executable file must has a specific structure. Unix a file is a sequence of bytes (no structures) Macintosh resource fork & data fork (mechanisms & policies) Label (เปลี่ยนภาษาได้) Executable code Internal File Structure logical physical file block block block Internal fragmentation Contiguous blocks external fragmentation (holes) Non-contiguous blocks internal fragmentation (table + the last block)

  8. File Access Methods (ไม่เกี่ยวกับ physical devices) Sequential Access (ถึงแม้ว่า device อาจจะเป็น random access) to access record n, must access record n – 1 Direct Access fixed-length logical records Other Access Methods indexing ISAM (Index sequential-access method, IBM) AAA\n BBBBB\n CCCC\n DDDDDD AAA \n BBBBB \n CCCC \n DDDDDD \n Variable length Fixed length Sequential access หน่วยความจำ เป็น random access HD อนุโลมว่าเป็น random access

  9. Indexing 1 record = 10 bytes (UPC) + 6 bytes (price) รหัสสินค้า ราคา 1 block = 1,024 bytes64 records 10 bytes Index Total2,000 records 20,000 bytes(in memory) Binary search ค้นหาว่าของที่ต้องการอยู่ใน block ไหน แล้วค่อยไป sequential searchใน block นั้น แค่ 64 records Total 2,000 blocks128,000 records Sorted by UPC(universal product code)

  10. Indexing

  11. Directory and Disk Structure ภาษา userเรียกว่า folder pp. 434

  12. Partition Partitioning is to divide physical storage. A partition holds a file system (also called “volume”). Directory Each volume must contain a device directory or volume table of content (information about the files in the system. Storage Structure Figure 10.7 on page 435, more details in the next chapter.

  13. Directory Overview • Symbol table (file names → directory entry) • Basic operations on a directory • Search for a file • Create a file • List a directory • Rename a file • Traverse the file system (backup)

  14. Single-Level Directory • Limitations • when the number of files increases • when the number of user increases • naming collision (unique-name rule is violated)

  15. Two-Level Directory The first level (MFD) separates users.

  16. Tree-Structured Directory Users can manage their own subdirectories.

  17. Acyclic-Graph Directory Sharing is easy. UNIX: soft link vs. hard link ใน Linux ใช้คำสั่ง ln (LN)Deletion: what’s the difference between soft and hard links?

  18. General Graph Directory Avoid searching a file twice (infinite loop). อาจจะเกิดจาก “ไวรัส” หรือ “อุบัติเหตุ”

  19. File-System Mounting A file system must be mounted before it can be available to processes. Current users (disk1) New users (disk2) unmount new. mount old. mount เป็นของ UnixWindows ทำแบบนี้ไม่ได้ !!!Windows 7 ทำได้แล้ว ตัวอย่างการใช้ flash drive บน Ubuntu Linux /media/flashdrive_name

  20. / device ทุกอย่าง เช่น printer, serial port ต้อง mount กับ file system สามารถอ่านเขียนได้เหมือน ไฟล์ปกติ UNIX /users (disk1) ไฟล์ใต้ users จะใช้ space ของ disk1 mount ข้าม network ได้ /users/tom /users/bob /users/joe disk4 disk2 disk3 disk5 Disk (drive C:) Windows ………… C:\users พื้นที่ใต้ users มีจำกัดเพิ่มไม่ได้ จะชี้ไปนอก disk ไม่ได้ ยกเว้น Windows 7 และ Windows Server 2008 R2 Windows: maintaining an extended two-level directory MacOS X: all file systems are mounted under /Volumes

  21. Windows 7 & Windows Server 2008 R2 • To assign a mount-point folder path to a drive by using the Windows interface • In Disk Manager, right-click the partition or volume where you want to assign the mount-point folder path, and then click Change Drive Letter and Paths. • Do one of the following: • To assign a mount-point folder path, click Add. Click Mount in the following empty NTFS folder, type the path to an empty folder on an NTFS volume, or click Browse to locate it. • To remove the mount-point folder path, click it and then click Remove. http://technet.microsoft.com/en-us/library/cc753321.aspx

  22. File Sharing Remote file systems Windows sharing files via network UNIX mount to a file system on another computer Distributed Information Systems Lightweight directory-access protocol (LDAP) Consistency semantics File session is between open() and close() 1. UNIX semantics 2. Session semantics Reading Assignmentปีนี้เอาแค่ LDAP ก่อน

  23. Protection d rwxrwxrwx Owner Group Others Directory

More Related