MESSAGE
DATE | 2015-03-08 |
FROM | Ruben Safir
|
SUBJECT | Subject: [LIU Comp Sci] Operating systems HW
|
From owner-learn-outgoing-at-mrbrklyn.com Sun Mar 8 20:23:17 2015 Return-Path: X-Original-To: archive-at-mrbrklyn.com Delivered-To: archive-at-mrbrklyn.com Received: by mrbrklyn.com (Postfix) id BE5A1161304; Sun, 8 Mar 2015 20:23:17 -0400 (EDT) Delivered-To: learn-outgoing-at-mrbrklyn.com Received: by mrbrklyn.com (Postfix, from userid 28) id AC394161307; Sun, 8 Mar 2015 20:23:17 -0400 (EDT) Delivered-To: learn-at-nylxs.com Received: from mailbackend.panix.com (mailbackend.panix.com [166.84.1.89]) by mrbrklyn.com (Postfix) with ESMTP id ED4F4161304 for ; Sun, 8 Mar 2015 20:22:52 -0400 (EDT) Received: from [10.0.0.19] (unknown [96.57.23.82]) by mailbackend.panix.com (Postfix) with ESMTPSA id 1210E11D58; Sun, 8 Mar 2015 20:22:51 -0400 (EDT) Message-ID: <54FCE7DB.3000700-at-panix.com> Date: Sun, 08 Mar 2015 20:22:51 -0400 From: Ruben Safir User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: mohammed Ghriga Subject: [LIU Comp Sci] Operating systems HW Content-Type: multipart/mixed; boundary="------------030300070906050409080202" Sender: owner-learn-at-mrbrklyn.com Precedence: bulk Reply-To: learn-at-mrbrklyn.com
This is a multi-part message in MIME format. --------------030300070906050409080202 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit
I lost track of what the home work was, but before I moved forward answering quiz questions, I wanted to tackle some of the coding assignments in Chapter 2, because I thought I could learn a lot more from them. So I did read Cpt 2 and 3, but I wanted to finish this which was good because I completely forgot a number of things about fstat, fopen and the use of strace, I had never done that before actually although I am familiar and used extensively nm. I made a lot of blunders on the way to finishing this, but others might benefit from this as well. I'm going on to doing the kernel programming tonight, I hope and tackle chapter 3 'quiz' questions at school in the AM before class.
Ruben
#include #include #include #include #include
char buf[500] = {0}; char buf2[500] = {0}; char * buf3; int fd, ret; size_t len; const char * PASSWD = "/etc/passwd"; off_t tmpsize;
struct stat filetmp;
FILE * INPUT; FILE * OUTPUT; int main( int argc, char * argv[]) { puts ("Enter a file to copy\n"); if ( ! fgets( buf, 500, stdin) ) return EXIT_FAILURE; len = strlen(buf); buf[len-1] = 0;
puts ("Enter the file to copy to\n"); if ( ! fgets( buf2, 500, stdin) ) return EXIT_FAILURE; len = strlen(buf2); buf2[len-1] = 0;
if( access( buf, F_OK|R_OK ) == 0 ) { INPUT = fopen( buf, "r"); if (INPUT == NULL){ printf("Can't Open %s\n", buf); exit(EXIT_FAILURE); } }else{ perror("access INPUT file stat"); exit (EXIT_FAILURE); } //File Opened for reading fd = fileno(INPUT); if (fstat(fd, &filetmp ) == -1){ perror("stat on reading file:"); exit(EXIT_FAILURE); } //FILE IS STATTED tmpsize = filetmp.st_size; if( (buf3 = (char *) malloc( sizeof(int) * tmpsize)) == NULL) exit (EXIT_FAILURE); ret = fread(buf3, tmpsize, 1, INPUT); if( ret != 1){ fprintf(stderr, "Read not complete: Req ==> %d Rec ==> %zu \n", ret, tmpsize); exit(EXIT_FAILURE); }
OUTPUT = fopen(buf2, "w"); if(OUTPUT == NULL){ printf("Can't Open %s\n ", buf2); exit(EXIT_FAILURE); } //File Open for Writing ret = fwrite(buf3, tmpsize, 1, OUTPUT); if(ret != 1){ perror("WRITE"); fprintf(stderr, "WRITE not complete: Req ==> %d Rec ==> %zu\n", ret, tmpsize); exit(EXIT_FAILURE); } free(buf3); fclose(INPUT); fclose(OUTPUT); return 1; }
execve("./a.out", ["./a.out"], [/* 55 vars */]) = 0 brk(0) = 0x68b000 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f71c0fdb000 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) open("/home/ruben/GNUstep/Library/Libraries/tls/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) stat("/home/ruben/GNUstep/Library/Libraries/tls/x86_64", 0x7fffd1634d10) = -1 ENOENT (No such file or directory) open("/home/ruben/GNUstep/Library/Libraries/tls/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) stat("/home/ruben/GNUstep/Library/Libraries/tls", 0x7fffd1634d10) = -1 ENOENT (No such file or directory) open("/home/ruben/GNUstep/Library/Libraries/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) stat("/home/ruben/GNUstep/Library/Libraries/x86_64", 0x7fffd1634d10) = -1 ENOENT (No such file or directory) open("/home/ruben/GNUstep/Library/Libraries/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) stat("/home/ruben/GNUstep/Library/Libraries", 0x7fffd1634d10) = -1 ENOENT (No such file or directory) open("/root/GNUstep/Library/Libraries/tls/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) stat("/root/GNUstep/Library/Libraries/tls/x86_64", 0x7fffd1634d10) = -1 ENOENT (No such file or directory) open("/root/GNUstep/Library/Libraries/tls/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) stat("/root/GNUstep/Library/Libraries/tls", 0x7fffd1634d10) = -1 ENOENT (No such file or directory) open("/root/GNUstep/Library/Libraries/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) stat("/root/GNUstep/Library/Libraries/x86_64", 0x7fffd1634d10) = -1 ENOENT (No such file or directory) open("/root/GNUstep/Library/Libraries/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) stat("/root/GNUstep/Library/Libraries", 0x7fffd1634d10) = -1 ENOENT (No such file or directory) open("/usr/lib/tls/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) stat("/usr/lib/tls/x86_64", 0x7fffd1634d10) = -1 ENOENT (No such file or directory) open("/usr/lib/tls/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) stat("/usr/lib/tls", 0x7fffd1634d10) = -1 ENOENT (No such file or directory) open("/usr/lib/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) stat("/usr/lib/x86_64", 0x7fffd1634d10) = -1 ENOENT (No such file or directory) open("/usr/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = 3 read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0`\1\2\0\0\0\0\0"..., 832) = 832 fstat(3, {st_mode=S_IFREG|0755, st_size=1984416, ...}) = 0 mmap(NULL, 3813200, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f71c0a18000 mprotect(0x7f71c0bb1000, 2097152, PROT_NONE) = 0 mmap(0x7f71c0db1000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x199000) = 0x7f71c0db1000 mmap(0x7f71c0db7000, 16208, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f71c0db7000 close(3) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f71c0fda000 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f71c0fd9000 arch_prctl(ARCH_SET_FS, 0x7f71c0fda700) = 0 mprotect(0x7f71c0db1000, 16384, PROT_READ) = 0 mprotect(0x7f71c0fdc000, 4096, PROT_READ) = 0 fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 6), ...}) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f71c0fd8000 write(1, "Enter a file to copy\n", 21) = 21 write(1, "\n", 1) = 1 fstat(0, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 6), ...}) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f71c0fd7000 read(0, "/etc/passwd\n", 1024) = 12 write(1, "Enter the file to copy to\n", 26) = 26 write(1, "\n", 1) = 1 read(0, "/home/ruben/ssadsa.tmp\n", 1024) = 23 access("/etc/passwd", R_OK) = 0 brk(0) = 0x68b000 brk(0x6ac000) = 0x6ac000 open("/etc/passwd", O_RDONLY) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=1637, ...}) = 0 fstat(3, {st_mode=S_IFREG|0644, st_size=1637, ...}) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f71c0fd6000 read(3, "root:x:0:0:root:/root:/bin/bash\n"..., 4096) = 1637 open("/home/ruben/ssadsa.tmp", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 5 fstat(5, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f71c0fd5000 close(3) = 0 munmap(0x7f71c0fd6000, 4096) = 0 write(5, "root:x:0:0:root:/root:/bin/bash\n"..., 1637) = 1637 close(5) = 0 munmap(0x7f71c0fd5000, 4096) = 0 exit_group(1) = ? +++ exited with 1 +++
--------------030300070906050409080202 Content-Type: text/plain; charset=UTF-8; name="output" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="output"
ZXhlY3ZlKCIuL2Eub3V0IiwgWyIuL2Eub3V0Il0sIFsvKiA1NSB2YXJzICovXSkgPSAwCmJy aygwKSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA9IDB4NjhiMDAwCm1tYXAo TlVMTCwgNDA5NiwgUFJPVF9SRUFEfFBST1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bi9iYXNoXG4iLi4uLCAxNjM3KSA9IDE2MzcKY2xv c2UoNSkgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgID0gMAptdW5tYXAoMHg3Zjcx YzBmZDUwMDAsIDQwOTYpICAgICAgICAgICAgPSAwCmV4aXRfZ3JvdXAoMSkgICAgICAgICAg ICAgICAgICAgICAgICAgICA9ID8KKysrIGV4aXRlZCB3aXRoIDEgKysrCg== --------------030300070906050409080202 Content-Type: text/x-csrc; name="mycp.c" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="mycp.c"
#include #include #include #include #include
char buf[500] = {0}; char buf2[500] = {0}; char * buf3; int fd, ret; size_t len; const char * PASSWD = "/etc/passwd"; off_t tmpsize;
struct stat filetmp;
FILE * INPUT; FILE * OUTPUT; int main( int argc, char * argv[]) { puts ("Enter a file to copy\n"); if ( ! fgets( buf, 500, stdin) ) return EXIT_FAILURE; len = strlen(buf); buf[len-1] = 0;
puts ("Enter the file to copy to\n"); if ( ! fgets( buf2, 500, stdin) ) return EXIT_FAILURE; len = strlen(buf2); buf2[len-1] = 0;
if( access( buf, F_OK|R_OK ) == 0 ) { INPUT = fopen( buf, "r"); if (INPUT == NULL){ printf("Can't Open %s\n", buf); exit(EXIT_FAILURE); } }else{ perror("access INPUT file stat"); exit (EXIT_FAILURE); } //File Opened for reading fd = fileno(INPUT); if (fstat(fd, &filetmp ) == -1){ perror("stat on reading file:"); exit(EXIT_FAILURE); } //FILE IS STATTED tmpsize = filetmp.st_size; if( (buf3 = (char *) malloc( sizeof(int) * tmpsize)) == NULL) exit (EXIT_FAILURE); ret = fread(buf3, tmpsize, 1, INPUT); if( ret != 1){ fprintf(stderr, "Read not complete: Req ==> %d Rec ==> %zu \n", ret, tmpsize); exit(EXIT_FAILURE); }
OUTPUT = fopen(buf2, "w"); if(OUTPUT == NULL){ printf("Can't Open %s\n ", buf2); exit(EXIT_FAILURE); } //File Open for Writing ret = fwrite(buf3, tmpsize, 1, OUTPUT); if(ret != 1){ perror("WRITE"); fprintf(stderr, "WRITE not complete: Req ==> %d Rec ==> %zu\n", ret, tmpsize); exit(EXIT_FAILURE); } free(buf3); fclose(INPUT); fclose(OUTPUT); return 1; }
--------------030300070906050409080202--
|
|