|
| 1 | +import nfs_proto as nfs |
| 2 | +import os |
| 3 | +import os.path |
| 4 | + |
| 5 | +ip = input('Give server IP: ') |
| 6 | +port = input('Give server port: ') |
| 7 | + |
| 8 | +nfs.mynfs_set_srv_addr(ip, int(port)) |
| 9 | + |
| 10 | +while True: |
| 11 | + command = input('\n---\nGive command\no : open \nr : read\nw : write\ns : seek\nc : close\n') |
| 12 | + if command == 'o': |
| 13 | + fname = input('Give file name: ') |
| 14 | + flags = input('Give flags: ') |
| 15 | + fd = nfs.mynfs_open(fname, flags) |
| 16 | + if fd == -1: |
| 17 | + print('\nContinuing with the next command\n\n') |
| 18 | + continue |
| 19 | + else: |
| 20 | + print('\nFile ['+ fname +'] opened, with fd = ' + str(fd)) |
| 21 | + elif command == 'r': |
| 22 | + tmp_fd = input('Give fd: ') |
| 23 | + bytesToRead = input('Give number of bytes to read: ') |
| 24 | + bytesToRead = int(bytesToRead) |
| 25 | + data = nfs.mynfs_read(tmp_fd ,'', bytesToRead) |
| 26 | + if data == -1: |
| 27 | + print('\nContinuing with the next command\n\n') |
| 28 | + continue |
| 29 | + print('\nData recieved: ', data) |
| 30 | + |
| 31 | + elif command == 'w': |
| 32 | + tmp_fd = input('Give fd: ') |
| 33 | + tmp_fd = int(tmp_fd) |
| 34 | + inp = input('Give input: ') |
| 35 | + numBytes = input('Give number of bytes to write: ') |
| 36 | + numBytes = int(numBytes) |
| 37 | + isFile = os.path.isfile(inp) |
| 38 | + if isFile == True: |
| 39 | + f = open(inp, 'rb') |
| 40 | + bytesToWrite = f.read(numBytes) |
| 41 | + else: |
| 42 | + bytesToWrite = inp[:numBytes] |
| 43 | + numofb = nfs.mynfs_write(tmp_fd, bytesToWrite, len(bytesToWrite)) |
| 44 | + if numofb == -1: |
| 45 | + print('\nContinuing with the next command\n\n') |
| 46 | + continue |
| 47 | + else: |
| 48 | + print('Bytes written in file: ', numofb) |
| 49 | + elif command == 's': |
| 50 | + tmp_fd = input('Give fd: ') |
| 51 | + whence = input('Give whence:\n0 : SEEK_START\n1 : SEEK_CURR\n2 : SEEK_END\n') |
| 52 | + whence = int(whence) |
| 53 | + bytesoffset = input('Give bytes offset: ') |
| 54 | + bytesoffset = int(bytesoffset) |
| 55 | + nfs.mynfs_seek(tmp_fd, bytesoffset, whence) |
| 56 | + |
| 57 | + elif command == 'c': |
| 58 | + tmp_fd = input('Give fd: ') |
| 59 | + tmp_fd = int(tmp_fd) |
| 60 | + nfs.mynfs_close(tmp_fd) |
| 61 | + |
| 62 | + |
0 commit comments