m5.c (12002:3f51adda9470) | m5.c (12003:bbe320b2f604) |
---|---|
1/* | 1/* |
2 * Copyright (c) 2011 ARM Limited | 2 * Copyright (c) 2011, 2017 ARM Limited |
3 * All rights reserved 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software 9 * licensed hereunder. You may use the software subject to the license 10 * terms below provided that you ensure that this notice is replicated --- 91 unchanged lines hidden (view full) --- 102 if ((n % 8) == 7) 103 i++; 104 } 105} 106 107int 108read_file(int dest_fid) 109{ | 3 * All rights reserved 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software 9 * licensed hereunder. You may use the software subject to the license 10 * terms below provided that you ensure that this notice is replicated --- 91 unchanged lines hidden (view full) --- 102 if ((n % 8) == 7) 103 i++; 104 } 105} 106 107int 108read_file(int dest_fid) 109{ |
110 char buf[256*1024]; | 110 uint8_t buf[256*1024]; |
111 int offset = 0; | 111 int offset = 0; |
112 int len; | 112 int len, ret; |
113 114 // Touch all buffer pages to ensure they are mapped in the 115 // page table. This is required in the case of X86_FS, where 116 // Linux does demand paging. 117 memset(buf, 0, sizeof(buf)); 118 119 while ((len = m5_readfile(buf, sizeof(buf), offset)) > 0) { | 113 114 // Touch all buffer pages to ensure they are mapped in the 115 // page table. This is required in the case of X86_FS, where 116 // Linux does demand paging. 117 memset(buf, 0, sizeof(buf)); 118 119 while ((len = m5_readfile(buf, sizeof(buf), offset)) > 0) { |
120 write(dest_fid, buf, len); | 120 uint8_t *base = buf; |
121 offset += len; | 121 offset += len; |
122 do { 123 ret = write(dest_fid, base, len); 124 if (ret < 0) { 125 perror("Failed to write file"); 126 exit(2); 127 } else if (ret == 0) { 128 fprintf(stderr, "Failed to write file: " 129 "Unhandled short write\n"); 130 exit(2); 131 } 132 133 base += ret; 134 len -= ret; 135 } while (len); |
|
122 } | 136 } |
137 138 return offset; |
|
123} 124 125void 126write_file(const char *filename) 127{ 128 fprintf(stderr, "opening %s\n", filename); 129 int src_fid = open(filename, O_RDONLY); 130 --- 273 unchanged lines hidden --- | 139} 140 141void 142write_file(const char *filename) 143{ 144 fprintf(stderr, "opening %s\n", filename); 145 int src_fid = open(filename, O_RDONLY); 146 --- 273 unchanged lines hidden --- |