Presentation is loading. Please wait.

Presentation is loading. Please wait.

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. 

Similar presentations


Presentation on theme: "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. "— Presentation transcript:

1 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.

2 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.

3 OS Project #2: cont’d 2 zSample 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 zSample 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 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


Download ppt "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. "

Similar presentations


Ads by Google