OS Project #2:Random File Access Random file access: using the lseek() system call to access files in UNIX. zTake arguments from the command line. Syntax: viewfile [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.
OS Project #2: cont’d 1 zUsing Makefile and make statement. zWrite a shell script to automatically test your program. zNote: Read the manuals of read(), open(), lseek() system calls. ymake 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.
OS Project #2: cont’d 2 zSample usage: simon> viewfile sample.txt c a t h e a d. t x t i d s e p s | m a i l - s " S 2e c20 6d61 696c 202d U B M I T " s u b m i s s i o d d f j u p i t e r. k a i s t. 6e40 6a e 6b e a c. k r y l l i n y a w l e6b c 6c69 6e c i y e l l o w. c s. n t h 696e c 6c6f 772e e6e 7468 u. e d 752e 6564
OS Project #2: cont’d 3 zSample usage: simon> viewfile /home/mike/foo.bin \0 \0 : D \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 a \ D 225 * 002 bc d003 a a a 2002 \n 027 \0 \ " 9402 a a f9 d422 e138 \0 \0 \b 302 \0 b \b \ \0 004 c \0 \0 \0 \0 \n 001 \0 \0 \ a f004 \0 \0 \0 ? # \ fc9 9c23 a f003 \0 \0 \0
z #include z off_t lseek(int fildes, off_t offset, int whence); zDESCRIPTION z The lseek() function sets the file pointer associated with z the open file descriptor specified by fildes as follows: z o If whence is SEEK_SET, the pointer is set to offset z bytes. z o If whence is SEEK_CUR, the pointer is set to its z current location plus offset. z o If whence is SEEK_END, the pointer is set to the size z of the file plus offset. z The symbolic constants SEEK_SET, SEEK_CUR, and SEEK_END are z defined in the header. lseek() - move read/write file pointer