Assignment 2 - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

Assignment 2

Description:

Assignment 2. Objective: Design and write a program to simulate ... Design Hints. Please note that the data transfer unit is a block. ... Design Hints---Cont. ... – PowerPoint PPT presentation

Number of Views:59
Avg rating:3.0/5.0
Slides: 11
Provided by: office9
Category:
Tags: assignment | hints

less

Transcript and Presenter's Notes

Title: Assignment 2


1
Assignment 2
  • Objective Design and write a program to simulate
    the operations in a file processing system
  • Programming environment
  • OS UNIX
  • Program language C/C
  • Command line format ass2 inputfile
  • Sample inputs will be provided for testing your
    program.
  • Warning Plagiarism

2
Assignment 2
  • Submitted materials
  • studentID_ass2.tar sent to the course account
    including
  • Makefile
  • Source files ass2.c etc.
  • Design report (short and well-written)
  • Name, student ID and email address.
  • Platform / Compiler
  • File structure
  • Data structure
  • Algorithms
  • Due Date Feb. 25th, 2001
  • Late submission policy 20 reduction per day

3
Assumptions
  • There can be multiple files in the system. Each
    file consists of a collection of blocks. The size
    of each block, BlockSize, is equal to 1KBytes.
  • A file contains a set of fixed-length records.
    The record length, RecordSize, varies for
    different files though fixed in one file. There
    is no record cross multiple blocks, i.e.
    RecordSize
  • Each record is made up of two fields, key and
    data. key is unique for each record in a file.
    The lengths of the two fields are KeySize and
    DataSize respectively. KeySize is assumed to be
    10Bytes. RecordSizeKeysizeDataSize

4
Design Hints
  • Please note that the data transfer unit is a
    block. read() or write() one block a time from or
    to the disk.
  • All the blocks are of the same size. To locate
    the starting point of a block identified by
    blockID in a file, use lseek() system call to
    move the file pointer appropriately.
  • The first block in a file is the header block
    which stores the structural information of the
    file, such as block size, block number, record
    size, record number, sorting tag, the first block
    ID etc. ( the header block structure )
  • All the data blocks in a file are organized in a
    doubly linked list. ( the data block structure )

5
Design Hints---Cont.
  • An array in the main memory can be used to keep
    the control information of all the opened files.
  • Bear the following operations in mind when
    choosing from different strategies.
  • Use low level I/O (unbuffered)in C. Such system
    calls in UNIX are
  • open(), close()
  • read(), write()
  • lseek(), rewind()
  • remove(), unlink(),
  • etc.

6
File Operations
  • CREATE filename recsize -s
  • create a new file. Report error if the file
    already exists.
  • filename the name of the file to be created.
  • recsize the record size in the file in term of
    number of bytes. Recall that the KeySize10, so
    the DataSizerecsize-10.
  • -s is optional. When specified, it indicates that
    the file is sorted in ascending order of the key.
    Otherwise the file is not sorted.
  • The newly created file consists of only the
    header block initially.

7
File Operations - Cont.
  • SELECT reckey FROM filename
  • retrieve one record from a file.
  • filename the name of the file to be selected
    from.
  • reckey the key of the record to be retrieved.
  • Open the file first if it has not been opened. If
    the file does not exist, report an error.
  • Scan all the blocks in the file. If the record
    identified by the given key exists, display the
    data field of the record, otherwise show the
    message of nonexistence.

8
File Operations - Cont.
  • INSERT reckey recdata INTO filename
  • insert one record into a file
  • filename the name of the file to be inserted
    into.
  • reckey key of the record to be inserted
  • recdata data of the record to be inserted.
  • Open the file first if the file has not be
    opened. If the file does not exist, report an
    error.
  • Report error if a record with the same key
    already exists in the file since duplicate keys
    are not allowed.
  • Insert the record properly (keep the file sorted
    if required) whether to a new block or an empty
    slot on an existing block of the file.

9
File Operations - Cont.
  • DELETE reckey FROM filename
  • delete one record from a file
  • filename name of the file to be deleted from
  • reckey key of the record to be deleted
  • Open the file first if the file has not be
    opened. If the file does not exist, report an
    error.
  • Report an error if the record with the given key
    does not exist

10
File Operations - Cont.
  • DROP filename
  • remove a file
  • filename the name of file to be removed
  • The file should be closed first.
  • Report an error if the file does not exist
  • ANALYZE filename
  • display the information on all the blocks (header
    block and data block) of a file
  • filename the name of the file
  • Open the file first if it has not been opened.
    Read each block of the file and show the content
    of the block in a readable way.
Write a Comment
User Comments (0)
About PowerShow.com