Changeset 58898d1d in mainline for uspace/app
- Timestamp:
- 2017-03-24T20:31:54Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8e9b2534
- Parents:
- c9e3692
- Location:
- uspace/app
- Files:
-
- 12 edited
-
bdsh/cmds/modules/cat/cat.c (modified) (5 diffs)
-
bdsh/cmds/modules/cmp/cmp.c (modified) (2 diffs)
-
bdsh/cmds/modules/cp/cp.c (modified) (3 diffs)
-
bdsh/cmds/modules/mkfile/mkfile.c (modified) (3 diffs)
-
sysinst/futil.c (modified) (5 diffs)
-
taskdump/elf_core.c (modified) (13 diffs)
-
taskdump/symtab.c (modified) (5 diffs)
-
tester/mm/pager1.c (modified) (1 diff)
-
tester/vfs/vfs1.c (modified) (2 diffs)
-
trace/trace.c (modified) (1 diff)
-
viewer/viewer.c (modified) (1 diff)
-
websrv/websrv.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/modules/cat/cat.c
rc9e3692 r58898d1d 31 31 #include <stdlib.h> 32 32 #include <unistd.h> 33 #include <sys/stat.h> 33 34 #include <getopt.h> 34 35 #include <str.h> … … 187 188 size_t offset = 0, copied_bytes = 0; 188 189 off64_t file_size = 0, length = 0; 190 aoff64_t pos = 0; 189 191 190 192 bool reading_stdin = dash_represents_stdin && (str_cmp(fname, "-") == 0); … … 205 207 close(fd); 206 208 printf("Unable to allocate enough memory to read %s\n", 207 fname);209 fname); 208 210 return 1; 209 211 } 210 212 211 213 if (tail != CAT_FULL_FILE) { 212 file_size = lseek(fd, 0, SEEK_END); 214 struct stat st; 215 216 if (fstat(fd, &st) != EOK) { 217 close(fd); 218 free(buff); 219 printf("Unable to fstat %d\n", fd); 220 return 1; 221 } 222 file_size = st.size; 213 223 if (head == CAT_FULL_FILE) { 214 224 head = file_size; … … 223 233 224 234 if (tail_first) { 225 lseek(fd, (tail >= file_size) ? 0 : (file_size - tail), SEEK_SET);235 pos = (tail >= file_size) ? 0 : (file_size - tail); 226 236 } else { 227 lseek(fd, ((head - tail) >= file_size) ? 0 : (head - tail), SEEK_SET);237 pos = ((head - tail) >= file_size) ? 0 : (head - tail); 228 238 } 229 239 } else … … 243 253 } 244 254 245 bytes = read(fd, buff + copied_bytes, bytes_to_read);255 bytes = read(fd, &pos, buff + copied_bytes, bytes_to_read); 246 256 copied_bytes = 0; 247 257 -
uspace/app/bdsh/cmds/modules/cmp/cmp.c
rc9e3692 r58898d1d 79 79 char buffer[2][CMP_BUFLEN]; 80 80 ssize_t offset[2]; 81 aoff64_t pos[2] = {}; 81 82 82 83 for (int i = 0; i < 2; i++) { … … 94 95 ssize_t size; 95 96 do { 96 size = read(fd[i], buffer[i] + offset[i], 97 size = read(fd[i], &pos[i], 98 buffer[i] + offset[i], 97 99 CMP_BUFLEN - offset[i]); 98 100 if (size < 0) { -
uspace/app/bdsh/cmds/modules/cp/cp.c
rc9e3692 r58898d1d 377 377 int64_t copied = 0; 378 378 char *buff = NULL; 379 aoff64_t posr = 0, posw = 0; 380 struct stat st; 379 381 380 382 if (vb) … … 392 394 } 393 395 394 total = lseek(fd1, 0, SEEK_END); 395 396 if (fstat(fd1, &st) != EOK) { 397 printf("Unable to fstat %d\n", fd1); 398 close(fd1); 399 close(fd2); 400 return -1; 401 } 402 403 total = st.size; 396 404 if (vb) 397 405 printf("%" PRIu64 " bytes to copy\n", total); 398 399 lseek(fd1, 0, SEEK_SET);400 406 401 407 if (NULL == (buff = (char *) malloc(blen))) { … … 406 412 } 407 413 408 while ((bytes = read(fd1, buff, blen)) > 0) {409 if ((bytes = write(fd2, buff, bytes)) < 0)414 while ((bytes = read(fd1, &posr, buff, blen)) > 0) { 415 if ((bytes = write(fd2, &posw, buff, bytes)) < 0) 410 416 break; 411 417 copied += bytes; -
uspace/app/bdsh/cmds/modules/mkfile/mkfile.c
rc9e3692 r58898d1d 121 121 void *buffer; 122 122 bool create_sparse = false; 123 aoff64_t pos = 0; 123 124 124 125 file_size = 0; … … 164 165 if (create_sparse && file_size > 0) { 165 166 const char byte = 0x00; 166 167 if ((rc2 = lseek(fd, file_size - 1, SEEK_SET)) < 0) { 168 close(fd); 169 goto error; 170 } 171 172 rc2 = write(fd, &byte, sizeof(char)); 167 168 pos = file_size - 1; 169 rc2 = write(fd, &pos, &byte, sizeof(char)); 173 170 if (rc2 < 0) { 174 171 close(fd); … … 187 184 while (total_written < file_size) { 188 185 to_write = min(file_size - total_written, BUFFER_SIZE); 189 rc = write(fd, buffer, to_write);186 rc = write(fd, &pos, buffer, to_write); 190 187 if (rc <= 0) { 191 188 printf("%s: Error writing file (%d).\n", cmdname, errno); -
uspace/app/sysinst/futil.c
rc9e3692 r58898d1d 60 60 ssize_t nr, nw; 61 61 int rc; 62 aoff64_t posr = 0, posw = 0; 62 63 63 64 printf("Copy '%s' to '%s'.\n", srcp, destp); … … 72 73 73 74 do { 74 nr = read(sf, buf, BUF_SIZE);75 nr = read(sf, &posr, buf, BUF_SIZE); 75 76 if (nr == 0) 76 77 break; … … 78 79 return EIO; 79 80 80 nw = write(df, buf, nr);81 nw = write(df, &posw, buf, nr); 81 82 if (nw <= 0) 82 83 return EIO; … … 157 158 int sf; 158 159 ssize_t nr; 159 off64_t off;160 160 size_t fsize; 161 161 char *data; 162 struct stat st; 162 163 163 164 sf = open(srcp, O_RDONLY); … … 165 166 return ENOENT; 166 167 167 off = lseek(sf, 0, SEEK_END);168 if (off == (off64_t)-1)168 if (fstat(sf, &st) != EOK) { 169 close(sf); 169 170 return EIO; 171 } 170 172 171 fsize = (size_t)off; 172 173 off = lseek(sf, 0, SEEK_SET); 174 if (off == (off64_t)-1) 175 return EIO; 173 fsize = st.size; 176 174 177 175 data = calloc(fsize, 1); 178 if (data == NULL) 176 if (data == NULL) { 177 close(sf); 179 178 return ENOMEM; 179 } 180 180 181 nr = read(sf, data, fsize); 182 if (nr != (ssize_t)fsize) 181 nr = read(sf, (aoff64_t []) { 0 }, data, fsize); 182 if (nr != (ssize_t)fsize) { 183 close(sf); 184 free(data); 183 185 return EIO; 186 } 184 187 185 188 (void) close(sf); -
uspace/app/taskdump/elf_core.c
rc9e3692 r58898d1d 67 67 68 68 static off64_t align_foff_up(off64_t, uintptr_t, size_t); 69 static int align_pos(int, size_t); 70 static int write_mem_area(int, as_area_info_t *, async_sess_t *); 69 static int write_mem_area(int, aoff64_t *, as_area_info_t *, async_sess_t *); 71 70 72 71 #define BUFFER_SIZE 0x1000 … … 97 96 elf_note_t note; 98 97 size_t word_size; 98 aoff64_t pos = 0; 99 99 100 100 int fd; … … 207 207 } 208 208 209 rc = write(fd, & elf_hdr, sizeof(elf_hdr));209 rc = write(fd, &pos, &elf_hdr, sizeof(elf_hdr)); 210 210 if (rc != sizeof(elf_hdr)) { 211 211 printf("Failed writing ELF header.\n"); … … 215 215 216 216 for (i = 0; i < n_ph; ++i) { 217 rc = write(fd, &p _hdr[i], sizeof(p_hdr[i]));217 rc = write(fd, &pos, &p_hdr[i], sizeof(p_hdr[i])); 218 218 if (rc != sizeof(p_hdr[i])) { 219 219 printf("Failed writing program header.\n"); … … 223 223 } 224 224 225 if (lseek(fd, p_hdr[0].p_offset, SEEK_SET) == (off64_t) -1) { 226 printf("Failed writing memory data.\n"); 227 free(p_hdr); 228 return EIO; 229 } 225 pos = p_hdr[0].p_offset; 230 226 231 227 /* … … 236 232 note.type = NT_PRSTATUS; 237 233 238 rc = write(fd, & note, sizeof(elf_note_t));234 rc = write(fd, &pos, ¬e, sizeof(elf_note_t)); 239 235 if (rc != sizeof(elf_note_t)) { 240 236 printf("Failed writing note header.\n"); … … 243 239 } 244 240 245 rc = write(fd, "CORE", note.namesz);241 rc = write(fd, &pos, "CORE", note.namesz); 246 242 if (rc != (ssize_t) note.namesz) { 247 243 printf("Failed writing note header.\n"); … … 250 246 } 251 247 252 rc = align_pos(fd, word_size); 253 if (rc != EOK) { 254 printf("Failed writing note header.\n"); 255 free(p_hdr); 256 return EIO; 257 } 258 259 rc = write(fd, &pr_status, sizeof(elf_prstatus_t)); 248 pos = ALIGN_UP(pos, word_size); 249 250 rc = write(fd, &pos, &pr_status, sizeof(elf_prstatus_t)); 260 251 if (rc != sizeof(elf_prstatus_t)) { 261 252 printf("Failed writing register data.\n"); … … 265 256 266 257 for (i = 1; i < n_ph; ++i) { 267 if (lseek(fd, p_hdr[i].p_offset, SEEK_SET) == (off64_t) -1) { 268 printf("Failed writing memory data.\n"); 269 free(p_hdr); 270 return EIO; 271 } 272 if (write_mem_area(fd, &ainfo[i - 1], sess) != EOK) { 258 pos = p_hdr[i].p_offset; 259 if (write_mem_area(fd, &pos, &ainfo[i - 1], sess) != EOK) { 273 260 printf("Failed writing memory data.\n"); 274 261 free(p_hdr); … … 297 284 * 298 285 * @param fd File to write to. 286 * @param pos Pointer to the position to write to. 299 287 * @param area Memory area info structure. 300 288 * @param sess Debugging session. … … 303 291 * 304 292 */ 305 static int write_mem_area(int fd, as_area_info_t *area, async_sess_t *sess) 293 static int write_mem_area(int fd, aoff64_t *pos, as_area_info_t *area, 294 async_sess_t *sess) 306 295 { 307 296 size_t to_copy; … … 321 310 } 322 311 323 rc = write(fd, buffer, to_copy);312 rc = write(fd, pos, buffer, to_copy); 324 313 if (rc != (ssize_t) to_copy) { 325 314 printf("Failed writing memory contents.\n"); … … 334 323 } 335 324 336 static int align_pos(int fd, size_t align)337 {338 off64_t cur_pos;339 size_t rem, adv;340 341 cur_pos = lseek(fd, 0, SEEK_CUR);342 if (cur_pos < 0)343 return -1;344 345 rem = cur_pos % align;346 adv = align - rem;347 348 cur_pos = lseek(fd, adv, SEEK_CUR);349 if (cur_pos < 0)350 return -1;351 352 return EOK;353 }354 355 325 /** @} 356 326 */ -
uspace/app/taskdump/symtab.c
rc9e3692 r58898d1d 68 68 char *shstrt, *sec_name; 69 69 void *data; 70 aoff64_t pos = 0; 70 71 71 72 int fd; … … 88 89 } 89 90 90 rc = read(fd, & elf_hdr, sizeof(elf_header_t));91 rc = read(fd, &pos, &elf_hdr, sizeof(elf_header_t)); 91 92 if (rc != sizeof(elf_header_t)) { 92 93 printf("failed reading elf header\n"); … … 304 305 { 305 306 int rc; 306 307 rc = lseek(fd, elf_hdr->e_shoff + idx * sizeof(elf_section_header_t), 308 SEEK_SET); 309 if (rc == (off64_t) -1) 310 return EIO; 311 312 rc = read(fd, sec_hdr, sizeof(elf_section_header_t)); 307 aoff64_t pos = elf_hdr->e_shoff + idx * sizeof(elf_section_header_t); 308 309 rc = read(fd, &pos, sec_hdr, sizeof(elf_section_header_t)); 313 310 if (rc != sizeof(elf_section_header_t)) 314 311 return EIO; … … 331 328 { 332 329 ssize_t rc; 333 off64_t offs; 334 335 offs = lseek(fd, start, SEEK_SET); 336 if (offs == (off64_t) -1) { 337 printf("failed seeking chunk\n"); 338 *ptr = NULL; 339 return EIO; 340 } 330 aoff64_t pos = start; 341 331 342 332 *ptr = malloc(size); … … 346 336 } 347 337 348 rc = read(fd, *ptr, size);338 rc = read(fd, &pos, *ptr, size); 349 339 if (rc != (ssize_t) size) { 350 340 printf("failed reading chunk\n"); -
uspace/app/tester/mm/pager1.c
rc9e3692 r58898d1d 52 52 return NULL; 53 53 (void) unlink(TEST_FILE); 54 if (write(fd, text, sizeof(text)) != sizeof(text)) { 54 55 if (write(fd, (aoff64_t []) {0}, text, sizeof(text)) != sizeof(text)) { 55 56 close(fd); 56 57 return NULL; -
uspace/app/tester/vfs/vfs1.c
rc9e3692 r58898d1d 70 70 const char *test_vfs1(void) 71 71 { 72 aoff64_t pos = 0; 73 72 74 if (mkdir(TEST_DIRECTORY, 0) != 0) { 73 75 TPRINTF("rc=%d\n", errno); … … 82 84 83 85 size_t size = sizeof(text); 84 ssize_t cnt = write(fd0, text, size);86 ssize_t cnt = write(fd0, &pos, text, size); 85 87 if (cnt < 0) 86 88 return "write() failed"; 87 89 TPRINTF("Written %zd bytes\n", cnt); 88 89 if (lseek(fd0, 0, SEEK_SET) != 0) 90 return "lseek() failed"; 91 TPRINTF("Sought to position 0\n"); 90 91 pos = 0; 92 92 93 93 char buf[BUF_SIZE]; 94 94 TPRINTF("read..\n"); 95 while ((cnt = read(fd0, buf, BUF_SIZE))) {95 while ((cnt = read(fd0, &pos, buf, BUF_SIZE))) { 96 96 TPRINTF("read returns %zd\n", cnt); 97 97 if (cnt < 0) -
uspace/app/trace/trace.c
rc9e3692 r58898d1d 701 701 702 702 p = proto_new("vfs"); 703 o = oper_new("read", 1, arg_def, V_ERRNO, 1, resp_def);703 o = oper_new("read", 3, arg_def, V_ERRNO, 1, resp_def); 704 704 proto_add_oper(p, VFS_IN_READ, o); 705 o = oper_new("write", 1, arg_def, V_ERRNO, 1, resp_def);705 o = oper_new("write", 3, arg_def, V_ERRNO, 1, resp_def); 706 706 proto_add_oper(p, VFS_IN_WRITE, o); 707 o = oper_new("seek", 3, arg_def, V_ERRNO, 0, resp_def);708 proto_add_oper(p, VFS_IN_SEEK, o);709 707 o = oper_new("truncate", 5, arg_def, V_ERRNO, 0, resp_def); 710 708 proto_add_oper(p, VFS_IN_TRUNCATE, o); -
uspace/app/viewer/viewer.c
rc9e3692 r58898d1d 126 126 return false; 127 127 } 128 129 ssize_t rd = read(fd, tga, stat.size);128 129 ssize_t rd = read(fd, (aoff64_t []) {0}, tga, stat.size); 130 130 if ((rd < 0) || (rd != (ssize_t) stat.size)) { 131 131 free(tga); -
uspace/app/websrv/websrv.c
rc9e3692 r58898d1d 238 238 return rc; 239 239 240 aoff64_t pos = 0; 240 241 while (true) { 241 ssize_t nr = read(fd, fbuf, BUFFER_SIZE);242 ssize_t nr = read(fd, &pos, fbuf, BUFFER_SIZE); 242 243 if (nr == 0) 243 244 break;
Note:
See TracChangeset
for help on using the changeset viewer.
