File-System Interface File Attributes

File-System Interface File Attributes

File-System Interface File คือ 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 Location ข้อมูลทอี่ ยู่กระจัดกระจายกัน จะอ่านเขียนได้ช้ากว่า Size (ทา defragment) Protection Time, date, and user identification 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. มี 1 table ต่อ 1 process Per-process table tracks all files that a process has open. System-wide tableมี 1 tablecontains ต่อ 1 OS 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. Information associated with an open file File pointer File-open count System-wide table Storage Disk location of the file File A Access rights File-open count Disk location File A File A File pointer Access rights Per-process table Per-process table 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 เมื่อ process หนึ่ง open file แล้ว (ยังไม่ close) 1. Mandatory: OS ensures locking integrity. process อื่น ๆ จะ open file นี้ไม่ได้ 2. Advisory: it’s up to software developers (acquired & released). Windows mandatory locking Unix advisory locking File Types Magic number ไฟล์บน Linux ไม่จาเป็นต้อง มีนามสกุล (extension) ดูจาก magic number http://en.wikipedia.org/wiki/Magic_number_(programming) File Structure OS requires that an executable file must has a specific structure. Unix a file is a sequence of bytes (no structures) Mac data fork & resource fork http://mirror.informatimago.com/next/developer.apple.com/documentation/mac/MoreToolbox/MoreToolbox-11.html Internal File Structure logical physical block file block block Internal fragmentation Contiguous blocks external fragmentation (holes) Non-contiguous blocks internal fragmentation (table + the last block) File Access Methods (ไม่เกยี่ วกับ physical devices) Sequential Access (ถึงแม้ว่า device อาจจะเป็น random access) to access record n, must access record n – 1 Direct Access AAA\n AAA \n fixed-length logical records BBBBB\n BBBBB \n CCCC\n CCCC \n DDDDDD DDDDDD \n Other Access Methods Variable length Fixed length indexing ISAM (Index sequential-access method, IBM) Sequential access หน่วยความจา เป็น random access HD อนุโลมว่าเป็น random access Indexing 1 record = 10 bytes (UPC) + 6 bytes (price) รหัสสินค้า ราคา 1 block = 1,024 bytes 64 records 10 bytes Index Total 2,000 records 20,000 bytes (in memory) Binary search Total 2,000 blocks ค้นหาว่าของทตี่ ้องการอยู่ใน 128,000 records block ไหน แล้วค่อยไป Sorted by UPC sequential search (universal product code) ใน block นั้น แค่ 64 records Indexing Directory and Disk Structure ภาษาชาวบ้าน เรียกว่า folder เอา disk หลายตัว มารวมกันก็ได้ pp. 434 Partition Partitioning is to divide physical storage. A partition holds a file system (also called “volume”). อาจจะประกอบด้วย disk หลาย ๆ ตัวก็ได้ 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. 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) Single-Level Directory ชือ่ ไฟล์ ตาแหน่ง ของไฟล์ Limitations • when the number of files increases • when the number of user increases • naming collision (unique-name rule is violated) Two-Level Directory The first level (MFD) separates users. Tree-Structured Directory Users can manage their own subdirectories. Acyclic-Graph Directory มีทั้งแบบ soft link และ hard link ใช้คาสั่ง ln ใน Linux คาสั่ง ln ใน Linux ใช้ยังไง? symbolic or soft link vs. hard link ต่างกันยังไง? https://ostechnix.com/explaining-soft-link-and-hard-link-in-linux-with-examples/ General Graph Directory มี loop ได้ อาจจะเกิดจาก “ไวรัส” หรือ “อุบัติเหตุ” File-System Mounting A file system must be mounted before it can be available to processes. Current users New users (disk1) (disk2) unmount disk1 mount disk2 คา ส่ัง mount เป็นของ Linux และ Windows 7 ขึน้ ไป ตัวอย่างการใช้ flash drive บน Ubuntu Linux /media/flashdrive_name / ใช้ space ของ disk1 UNIX/Linux device ทุกอย่าง เช่น printer, usb port /home ต้อง mount ก่อน แล้วจะอ่านเขียนได้ เหมือนไฟล์ปกติ mount ข้าม network ได้ /home/tom /home/bob /home/joe ใช้ disk1 ใช้ disk2 ใช้ disk3 Windows A B C D ………… Z ข้อดีของ first level แรกเป็น letter คือมัน user-friendly แต่ข้อเสียคือมันมีแค่ A - Z เท่านั้น เพิ่มไม่ได้ (26 drives) Windows เริ่มจาก drive C เพราะยุคแรกมี drive A & B สาหรับ floppy disk แล้วเลิกใช้ไป Windows: maintaining an extended two-level directory MacOS X: all file systems are mounted under /Volumes File Sharing Remote file systems Windows sharing files via network UNIX/Linux 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 Protection d rwx rwx rwx Owner Group Others Directory ใน Linux มีคาสั่ง chown, chgrp, chmod mode 755 คือ 111 101 101 mode 644 คือ 110 100 100 mode 700 คือ 111 000 000 mode 400 คือ 100 000 000 กจิ กรรมทนี่ ่าสนใจ File Server (Samba) network ให้ Drive Z: เป็น network file system Note: ใช้ PC 2 เครื่อง หรือ Windows PC + Linux VM ก็ได้.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    23 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us