1 / 5

OS Project #2:Random File Access

OS Project #2:Random File Access. Random file access: using the lseek() system call to access files in UNIX. Take arguments from the command line. Syntax: viewfile <filename> [pos] [length]

Download Presentation

OS Project #2:Random File Access

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. OS Project #2:Random File Access • Random file access: using the lseek() system call to access files in UNIX. • Take arguments from the command line. • Syntax: viewfile <filename> [pos] [length] • Position the I/O head of a file starting from the position [pos] by lseek() system calls; print the contenet of the file for exactly [length] numbers of bytes using read() system calls. • NB: [pos] can be very large.

  2. OS Project #2: cont’d 1 • Using Makefile and make statement. • Write a shell script to automatically test your program. • Note: Read the manuals of • read(), open(), lseek() system calls. • make statement and Makefile syntax. • the isprint() library function for testing chars. • Hints: reference the output formats of the usual od (octal dump) command in UNIX.

  3. OS Project #2: cont’d 2 • Sample usage: • simon> viewfile sample.txt 200 100 • 0000200 c a t h e a d . t x t i d s • 6361 7420 6865 6164 2e74 7874 2069 6473 • 0000216 . p s | m a i l - s " S • 2e70 7320 7c20 6d61 696c 202d 7320 2253 • 0000232 U B M I T " s u b m i s s i o • 5542 4d49 5422 2073 7562 6d69 7373 696f • 0000248 n @ j u p i t e r . k a i s t . • 6e40 6a75 7069 7465 722e 6b61 6973 742e • 0000264 a c . k r y l l i n y a w l • 6163 2e6b 7220 796c 6c69 6e20 7961 776c • 0000280 i n @ y e l l o w . c s . n t h • 696e 4079 656c 6c6f 772e 6373 2e6e 7468 • 0000296 u . e d • 752e 6564

  4. OS Project #2: cont’d 3 • Sample usage: • simon> viewfile /home/mike/foo.bin 200 100 • 0000200 \0 \0 : D \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 • 0000 3a44 0000 2020 0000 0000 0000 0000 • 0000216 274 020 \0 320 003 240 @ 222 003 240 D 225 * 002 • bc10 2000 d003 a040 9203 a044 952a 2002 • 0000232 224 002 240 004 224 002 @ \n 027 \0 \0 371 324 " 341 8 • 9402 a004 9402 400a 1700 00f9 d422 e138 • 0000248 003 \0 \0 \b 302 \0 b \b 200 220 \0 001 002 200 \0 004 • 0300 0008 c200 6208 8090 0001 0280 0004 • 0000264 001 \0 \0 \0 @ \0 \0 \n 001 \0 \0 \0 @ \0 360 004 • 0100 0000 4000 000a 0100 0000 4000 f004 • 0000280 001 \0 \0 \0 @ \0 ? 311 234 # 240 @ \0 360 003 • 0100 0000 4000 3fc9 9c23 a020 4000 f003 • 0000296 001 \0 \0 \0 • 0100 0000

  5. lseek() - move read/write file pointer • #include <sys/types.h> • #include <unistd.h> • off_t lseek(int fildes, off_t offset, int whence); • DESCRIPTION • The lseek() function sets the file pointer associated with • the open file descriptor specified by fildes as follows: • o If whence is SEEK_SET, the pointer is set to offset • bytes. • o If whence is SEEK_CUR, the pointer is set to its • current location plus offset. • o If whence is SEEK_END, the pointer is set to the size • of the file plus offset. • The symbolic constants SEEK_SET, SEEK_CUR, and SEEK_END are • defined in the header <unistd.h>.

More Related