Changeset 6afc9d7 in mainline
- Timestamp:
- 2015-10-06T19:01:36Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0328987
- Parents:
- f1f7584
- Files:
-
- 51 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/console/console.c
rf1f7584 r6afc9d7 437 437 } 438 438 439 return size;439 return EOK; 440 440 } 441 441 -
uspace/app/bdsh/cmds/builtins/cd/cd.c
rf1f7584 r6afc9d7 57 57 previous_directory_set = true; 58 58 59 int rc = chdir(new_dir); 60 if (rc != EOK) { 61 return rc; 62 } 59 if (chdir(new_dir) != 0) 60 return errno; 63 61 64 62 str_cpy(previous_directory, PATH_MAX, previous_directory_tmp); -
uspace/app/bdsh/cmds/modules/cat/cat.c
rf1f7584 r6afc9d7 244 244 245 245 bytes = read(fd, buff + copied_bytes, bytes_to_read); 246 bytes += copied_bytes;247 246 copied_bytes = 0; 248 247 -
uspace/app/bdsh/cmds/modules/cp/cp.c
rf1f7584 r6afc9d7 27 27 */ 28 28 29 #include <errno.h> 29 30 #include <stdio.h> 30 31 #include <stdlib.h> … … 84 85 int r = stat(path, &s); 85 86 86 if (r )87 if (r != 0) 87 88 return TYPE_NONE; 88 89 else if (s.is_directory) … … 234 235 */ 235 236 if (force && !interactive) { 236 if (unlink(dest_path) ) {237 if (unlink(dest_path) != 0) { 237 238 printf("Unable to remove %s\n", 238 239 dest_path); … … 245 246 if (overwrite) { 246 247 printf("Overwriting file: %s\n", dest_path); 247 if (unlink(dest_path) ) {248 if (unlink(dest_path) != 0) { 248 249 printf("Unable to remove %s\n", dest_path); 249 250 goto exit; … … 294 295 merge_paths(dest_path, PATH_MAX, src_dirname); 295 296 296 if (mkdir(dest_path, 0) == -1) {297 if (mkdir(dest_path, 0) != 0) { 297 298 printf("Unable to create " 298 299 "dest directory %s\n", dest_path); … … 308 309 * e.g. cp -r /src /data/new_dir_src 309 310 */ 310 if (mkdir(dest_path, 0) ) {311 if (mkdir(dest_path, 0) != 0) { 311 312 printf("Unable to create " 312 313 "dest directory %s\n", dest_path); … … 405 406 } 406 407 407 while ((bytes = read _all(fd1, buff, blen)) > 0) {408 if ((bytes = write _all(fd2, buff, bytes)) < 0)408 while ((bytes = read(fd1, buff, blen)) > 0) { 409 if ((bytes = write(fd2, buff, bytes)) < 0) 409 410 break; 410 411 copied += bytes; … … 412 413 413 414 if (bytes < 0) { 414 printf("\nError copying %s, (%d)\n", src, bytes);415 printf("\nError copying %s, (%d)\n", src, errno); 415 416 copied = bytes; 416 417 } -
uspace/app/bdsh/cmds/modules/ls/ls.c
rf1f7584 r6afc9d7 31 31 * As more stuff is completed and exposed in libc, this will improve */ 32 32 33 #include <errno.h> 33 34 #include <stdio.h> 34 35 #include <stdlib.h> … … 187 188 if (rc != 0) { 188 189 printf("ls: skipping bogus node %s\n", buff); 189 printf(" rc=%d\n", rc);190 printf("error=%d\n", errno); 190 191 goto out; 191 192 } … … 314 315 static unsigned int ls_scope(const char *path, struct dir_elem_t *de) 315 316 { 316 if (stat(path, &de->s) ) {317 if (stat(path, &de->s) != 0) { 317 318 cli_error(CL_ENOENT, "%s", path); 318 319 return LS_BOGUS; … … 376 377 } 377 378 } 378 379 379 380 argc -= optind; 380 381 381 382 de.name = (char *) malloc(PATH_MAX); 382 383 if (!de.name) { 383 cli_error(CL_ENOMEM, "%s: ", cmdname);384 cli_error(CL_ENOMEM, "%s: Out of memory", cmdname); 384 385 return CMD_FAILURE; 385 386 } 386 387 memset(de.name, 0, PATH_MAX); 387 388 if (argc == 0) 389 getcwd(de.name, PATH_MAX); 390 else 388 389 if (argc == 0) { 390 if (getcwd(de.name, PATH_MAX) == NULL) { 391 cli_error(CL_EFAIL, "%s: Failed determining working " 392 "directory", cmdname); 393 return CMD_FAILURE; 394 } 395 } else { 391 396 str_cpy(de.name, PATH_MAX, argv[optind]); 397 } 392 398 393 399 scope = ls_scope(de.name, &de); -
uspace/app/bdsh/cmds/modules/mkdir/mkdir.c
rf1f7584 r6afc9d7 89 89 { 90 90 /* Ensure we would always work with absolute and canonified path. */ 91 char *path = absolutize(user_path, NULL);91 char *path = vfs_absolutize(user_path, NULL); 92 92 if (path == NULL) { 93 93 cli_error(CL_ENOMEM, "%s: path too big?", cmdname); … … 95 95 } 96 96 97 int rc;98 97 int ret = 0; 99 98 100 99 if (!create_parents) { 101 rc = mkdir(path, 0); 102 if (rc != EOK) { 100 if (mkdir(path, 0) != 0) { 103 101 cli_error(CL_EFAIL, "%s: could not create %s (%s)", 104 cmdname, path, str_error( rc));102 cmdname, path, str_error(errno)); 105 103 ret = 1; 106 104 } … … 137 135 char slash_char = path[prev_off]; 138 136 path[prev_off] = 0; 139 rc = mkdir(path, 0); 140 if (rc == EEXIST) { 141 rc = EOK; 142 } 143 144 if (rc != EOK) { 137 138 if (mkdir(path, 0) != 0 && errno != EEXIST) { 145 139 cli_error(CL_EFAIL, "%s: could not create %s (%s)", 146 cmdname, path, str_error( rc));140 cmdname, path, str_error(errno)); 147 141 ret = 1; 148 142 goto leave; … … 152 146 } 153 147 /* Create the final directory. */ 154 rc = mkdir(path, 0); 155 if (rc != EOK) { 148 if (mkdir(path, 0) != 0) { 156 149 cli_error(CL_EFAIL, "%s: could not create %s (%s)", 157 cmdname, path, str_error( rc));150 cmdname, path, str_error(errno)); 158 151 ret = 1; 159 152 } … … 214 207 215 208 if (follow && (argv[optind] != NULL)) { 216 chdir(argv[optind]); 209 if (chdir(argv[optind]) != 0) 210 printf("%s: Error switching to directory.", cmdname); 217 211 } 218 212 -
uspace/app/bdsh/cmds/modules/mkfile/mkfile.c
rf1f7584 r6afc9d7 27 27 */ 28 28 29 #include <errno.h> 29 30 #include <stdio.h> 30 31 #include <stdlib.h> … … 166 167 167 168 if ((rc2 = lseek(fd, file_size - 1, SEEK_SET)) < 0) 168 goto e xit;169 goto error; 169 170 170 171 rc2 = write(fd, &byte, sizeof(char)); 171 goto exit; 172 if (rc2 < 0) 173 goto error; 174 return CMD_SUCCESS; 172 175 } 173 176 … … 183 186 rc = write(fd, buffer, to_write); 184 187 if (rc <= 0) { 185 printf("%s: Error writing file (% zd).\n", cmdname, rc);188 printf("%s: Error writing file (%d).\n", cmdname, errno); 186 189 close(fd); 187 190 return CMD_FAILURE; … … 191 194 192 195 free(buffer); 193 exit: 194 rc = close(fd); 195 196 if (rc != 0 || rc2 < 0) { 197 printf("%s: Error writing file (%zd).\n", cmdname, rc); 198 return CMD_FAILURE; 199 } 196 197 if (close(fd) < 0) 198 goto error; 200 199 201 200 return CMD_SUCCESS; 201 error: 202 printf("%s: Error writing file (%d).\n", cmdname, errno); 203 return CMD_FAILURE; 202 204 } -
uspace/app/bdsh/cmds/modules/mount/mount.c
rf1f7584 r6afc9d7 72 72 int rc; 73 73 74 get_mtab_list(&mtab_list);74 vfs_get_mtab_list(&mtab_list); 75 75 76 76 list_foreach(mtab_list, link, mtab_ent_t, mtab_ent) { … … 150 150 mopts = t_argv[4]; 151 151 152 rc = mount(t_argv[1], t_argv[2], dev, mopts, 0, instance);152 rc = vfs_mount(t_argv[1], t_argv[2], dev, mopts, 0, instance); 153 153 if (rc != EOK) { 154 154 printf("Unable to mount %s filesystem to %s on %s (rc=%d)\n", -
uspace/app/bdsh/cmds/modules/mv/mv.c
rf1f7584 r6afc9d7 60 60 61 61 rc = rename(argv[1], argv[2]); 62 if (rc != EOK) {63 printf("Unable to rename %s to %s ( rc=%d)\n",64 argv[1], argv[2], rc);62 if (rc != 0) { 63 printf("Unable to rename %s to %s (error=%d)\n", 64 argv[1], argv[2], errno); 65 65 return CMD_FAILURE; 66 66 } -
uspace/app/bdsh/cmds/modules/pwd/pwd.c
rf1f7584 r6afc9d7 56 56 57 57 memset(buff, 0, PATH_MAX); 58 getcwd(buff, PATH_MAX);59 58 60 if ( ! buff) {59 if (getcwd(buff, PATH_MAX) == NULL) { 61 60 cli_error(CL_EFAIL, 62 61 "Unable to determine the current working directory"); -
uspace/app/bdsh/cmds/modules/rm/rm.c
rf1f7584 r6afc9d7 27 27 */ 28 28 29 #include <errno.h> 29 30 #include <stdio.h> 30 31 #include <stdlib.h> … … 131 132 static unsigned int rm_single(const char *path) 132 133 { 133 if (unlink(path) ) {134 if (unlink(path) != 0) { 134 135 cli_error(CL_EFAIL, "rm: could not remove file %s", path); 135 136 return 1; … … 150 151 151 152 fd = open(path, O_RDONLY); 152 if (fd > 0) {153 if (fd >= 0) { 153 154 close(fd); 154 155 return RM_FILE; … … 210 211 rc = rmdir(path); 211 212 if (rc == 0) 212 return ret;213 return errno; 213 214 214 215 cli_error(CL_ENOTSUP, "Can not remove %s", path); -
uspace/app/bdsh/cmds/modules/touch/touch.c
rf1f7584 r6afc9d7 123 123 124 124 /* Check whether file exists if -c (--no-create) option is given */ 125 if ((!no_create) || ((no_create) && (stat(buff, &file_stat) == EOK)))125 if ((!no_create) || ((no_create) && (stat(buff, &file_stat) == 0))) 126 126 fd = open(buff, O_RDWR | O_CREAT); 127 127 -
uspace/app/bdsh/cmds/modules/unmount/unmount.c
rf1f7584 r6afc9d7 66 66 } 67 67 68 rc = unmount(argv[1]);68 rc = vfs_unmount(argv[1]); 69 69 if (rc != EOK) { 70 70 printf("Unable to unmount %s (rc=%d)\n", argv[1], rc); -
uspace/app/bdsh/compl.c
rf1f7584 r6afc9d7 360 360 asprintf(&ent_path, "%s/%s", *cs->path, dent->d_name); 361 361 struct stat ent_stat; 362 if (stat(ent_path, &ent_stat) != EOK) {362 if (stat(ent_path, &ent_stat) != 0) { 363 363 /* Error */ 364 364 free(ent_path); -
uspace/app/bdsh/exec.c
rf1f7584 r6afc9d7 61 61 62 62 fd = open(f, O_RDONLY); 63 if (fd > -1) {63 if (fd >= 0) { 64 64 close(fd); 65 65 return 0; … … 113 113 114 114 for (i = 0; i < 3 && files[i] != NULL; i++) { 115 if ( fhandle(files[i], &file_handles[i]) == EOK) {115 if (vfs_fhandle(files[i], &file_handles[i]) == EOK) { 116 116 file_handles_p[i] = &file_handles[i]; 117 117 } -
uspace/app/df/df.c
rf1f7584 r6afc9d7 119 119 120 120 LIST_INITIALIZE(mtab_list); 121 get_mtab_list(&mtab_list);121 vfs_get_mtab_list(&mtab_list); 122 122 123 123 print_header(); 124 124 list_foreach(mtab_list, link, mtab_ent_t, mtab_ent) { 125 statfs(mtab_ent->mp, &st); 126 print_statfs(&st, mtab_ent->fs_name, mtab_ent->mp); 125 if (statfs(mtab_ent->mp, &st) == 0) { 126 print_statfs(&st, mtab_ent->fs_name, mtab_ent->mp); 127 } else { 128 fprintf(stderr, "Cannot get information for '%s' (%d).\n", 129 mtab_ent->mp, errno); 130 } 127 131 } 128 132 -
uspace/app/init/init.c
rf1f7584 r6afc9d7 126 126 opts = "restore"; 127 127 128 int rc = mount(fstype, ROOT_MOUNT_POINT, ROOT_DEVICE, opts,128 int rc = vfs_mount(fstype, ROOT_MOUNT_POINT, ROOT_DEVICE, opts, 129 129 IPC_FLAG_BLOCKING, 0); 130 130 return mount_report("Root filesystem", ROOT_MOUNT_POINT, fstype, … … 143 143 static bool mount_locfs(void) 144 144 { 145 int rc = mount(LOCFS_FS_TYPE, LOCFS_MOUNT_POINT, "", "",145 int rc = vfs_mount(LOCFS_FS_TYPE, LOCFS_MOUNT_POINT, "", "", 146 146 IPC_FLAG_BLOCKING, 0); 147 147 return mount_report("Location service filesystem", LOCFS_MOUNT_POINT, … … 152 152 { 153 153 struct stat s; 154 if (stat(path, &s) == ENOENT) {154 if (stat(path, &s) != 0) { 155 155 printf("%s: Unable to stat %s\n", NAME, path); 156 156 return ENOENT; … … 299 299 static bool mount_tmpfs(void) 300 300 { 301 int rc = mount(TMPFS_FS_TYPE, TMPFS_MOUNT_POINT, "", "", 0, 0);301 int rc = vfs_mount(TMPFS_FS_TYPE, TMPFS_MOUNT_POINT, "", "", 0, 0); 302 302 return mount_report("Temporary filesystem", TMPFS_MOUNT_POINT, 303 303 TMPFS_FS_TYPE, NULL, rc); -
uspace/app/taskdump/elf_core.c
rf1f7584 r6afc9d7 207 207 } 208 208 209 rc = write _all(fd, &elf_hdr, sizeof(elf_hdr));209 rc = write(fd, &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 _all(fd, &p_hdr[i], sizeof(p_hdr[i]));217 rc = write(fd, &p_hdr[i], sizeof(p_hdr[i])); 218 218 if (rc != sizeof(p_hdr[i])) { 219 219 printf("Failed writing program header.\n"); … … 236 236 note.type = NT_PRSTATUS; 237 237 238 rc = write _all(fd, ¬e, sizeof(elf_note_t));238 rc = write(fd, ¬e, sizeof(elf_note_t)); 239 239 if (rc != sizeof(elf_note_t)) { 240 240 printf("Failed writing note header.\n"); … … 243 243 } 244 244 245 rc = write _all(fd, "CORE", note.namesz);245 rc = write(fd, "CORE", note.namesz); 246 246 if (rc != (ssize_t) note.namesz) { 247 247 printf("Failed writing note header.\n"); … … 257 257 } 258 258 259 rc = write _all(fd, &pr_status, sizeof(elf_prstatus_t));259 rc = write(fd, &pr_status, sizeof(elf_prstatus_t)); 260 260 if (rc != sizeof(elf_prstatus_t)) { 261 261 printf("Failed writing register data.\n"); … … 321 321 } 322 322 323 rc = write _all(fd, buffer, to_copy);323 rc = write(fd, buffer, to_copy); 324 324 if (rc != (ssize_t) to_copy) { 325 325 printf("Failed writing memory contents.\n"); -
uspace/app/taskdump/symtab.c
rf1f7584 r6afc9d7 88 88 } 89 89 90 rc = read _all(fd, &elf_hdr, sizeof(elf_header_t));90 rc = read(fd, &elf_hdr, sizeof(elf_header_t)); 91 91 if (rc != sizeof(elf_header_t)) { 92 92 printf("failed reading elf header\n"); … … 310 310 return EIO; 311 311 312 rc = read _all(fd, sec_hdr, sizeof(elf_section_header_t));312 rc = read(fd, sec_hdr, sizeof(elf_section_header_t)); 313 313 if (rc != sizeof(elf_section_header_t)) 314 314 return EIO; … … 346 346 } 347 347 348 rc = read _all(fd, *ptr, size);348 rc = read(fd, *ptr, size); 349 349 if (rc != (ssize_t) size) { 350 350 printf("failed reading chunk\n"); -
uspace/app/tester/hw/misc/virtchar1.c
rf1f7584 r6afc9d7 58 58 int fd = open(path, O_RDONLY); 59 59 if (fd < 0) { 60 TPRINTF(" ...error: %s\n", str_error( fd));60 TPRINTF(" ...error: %s\n", str_error(errno)); 61 61 if (fd == ENOENT) { 62 62 TPRINTF(" (error was ENOENT: " \ … … 69 69 70 70 TPRINTF(" Asking for session...\n"); 71 async_sess_t *sess = fd_session(fd, INTERFACE_DDF);71 async_sess_t *sess = vfs_fd_session(fd, INTERFACE_DDF); 72 72 if (!sess) { 73 73 close(fd); -
uspace/app/tester/vfs/vfs1.c
rf1f7584 r6afc9d7 70 70 const char *test_vfs1(void) 71 71 { 72 int rc; 73 if ((rc = mkdir(TEST_DIRECTORY, 0)) != 0) { 74 TPRINTF("rc=%d\n", rc); 72 if (mkdir(TEST_DIRECTORY, 0) != 0) { 73 TPRINTF("rc=%d\n", errno); 75 74 return "mkdir() failed"; 76 75 } … … 93 92 94 93 char buf[BUF_SIZE]; 94 TPRINTF("read..\n"); 95 95 while ((cnt = read(fd0, buf, BUF_SIZE))) { 96 TPRINTF("read returns %zd\n", cnt); 96 97 if (cnt < 0) 97 98 return "read() failed"; … … 112 113 return rv; 113 114 114 if (rename(TEST_FILE, TEST_FILE2) )115 if (rename(TEST_FILE, TEST_FILE2) != 0) 115 116 return "rename() failed"; 116 117 TPRINTF("Renamed %s to %s\n", TEST_FILE, TEST_FILE2); 117 118 118 if (unlink(TEST_FILE2) )119 if (unlink(TEST_FILE2) != 0) 119 120 return "unlink() failed"; 120 121 TPRINTF("Unlinked %s\n", TEST_FILE2); 121 122 122 if (rmdir(TEST_DIRECTORY) )123 if (rmdir(TEST_DIRECTORY) != 0) 123 124 return "rmdir() failed"; 124 125 TPRINTF("Removed directory %s\n", TEST_DIRECTORY); -
uspace/app/trace/trace.c
rf1f7584 r6afc9d7 57 57 #include "proto.h" 58 58 #include <ipc/services.h> 59 #include "../../srv/vfs/vfs.h"59 #include <ipc/vfs.h> 60 60 #include <ipc/console.h> 61 61 … … 528 528 int fd_stderr; 529 529 530 if ((stdin != NULL) && ( fhandle(stdin, &fd_stdin) == EOK))530 if ((stdin != NULL) && (vfs_fhandle(stdin, &fd_stdin) == EOK)) 531 531 files[0] = &fd_stdin; 532 532 else 533 533 files[0] = NULL; 534 534 535 if ((stdout != NULL) && ( fhandle(stdout, &fd_stdout) == EOK))535 if ((stdout != NULL) && (vfs_fhandle(stdout, &fd_stdout) == EOK)) 536 536 files[1] = &fd_stdout; 537 537 else 538 538 files[1] = NULL; 539 539 540 if ((stderr != NULL) && ( fhandle(stderr, &fd_stderr) == EOK))540 if ((stderr != NULL) && (vfs_fhandle(stderr, &fd_stderr) == EOK)) 541 541 files[2] = &fd_stderr; 542 542 else -
uspace/app/untar/main.c
rf1f7584 r6afc9d7 103 103 static int handle_directory(const tar_header_t *header, FILE *tarfile) 104 104 { 105 int rc = mkdir(header->filename, 0755); 106 if (rc == EEXIST) { 107 // printf("Note: directory %s already exists.\n", header->filename); 108 rc = EOK; 109 } 110 if (rc != EOK) { 111 fprintf(stderr, "Failed to create directory %s: %s.\n", 112 header->filename, str_error(rc)); 113 return rc; 105 if (mkdir(header->filename, 0755) != 0) { 106 if (errno != EEXIST) { 107 fprintf(stderr, "Failed to create directory %s: %s.\n", 108 header->filename, str_error(errno)); 109 return errno; 110 } 114 111 } 115 112 -
uspace/app/viewer/viewer.c
rf1f7584 r6afc9d7 98 98 { 99 99 int fd = open(fname, O_RDONLY); 100 if (fd <0)100 if (fd != 0) 101 101 return false; 102 102 103 103 struct stat stat; 104 104 int rc = fstat(fd, &stat); 105 if (rc != EOK) {105 if (rc != 0) { 106 106 close(fd); 107 107 return false; … … 114 114 } 115 115 116 ssize_t rd = read _all(fd, tga, stat.size);116 ssize_t rd = read(fd, tga, stat.size); 117 117 if ((rd < 0) || (rd != (ssize_t) stat.size)) { 118 118 free(tga); -
uspace/drv/bus/isa/isa.c
rf1f7584 r6afc9d7 270 270 } 271 271 272 r = read _all(fd, buf, len);272 r = read(fd, buf, len); 273 273 if (r < 0) { 274 274 ddf_msg(LVL_ERROR, "Unable to read file '%s'.", conf_path); -
uspace/lib/bithenge/src/file.c
rf1f7584 r6afc9d7 114 114 struct stat stat; 115 115 int rc = fstat(fd, &stat); 116 if (rc != EOK) {116 if (rc != 0) { 117 117 if (needs_close) 118 118 close(fd); … … 157 157 int fd = open(filename, O_RDONLY); 158 158 if (fd < 0) 159 return fd;159 return errno; 160 160 161 161 return new_file_blob(out, fd, true); -
uspace/lib/c/generic/elf/elf_load.c
rf1f7584 r6afc9d7 97 97 int fd; 98 98 int rc; 99 99 100 100 fd = open(file_name, O_RDONLY); 101 101 if (fd < 0) { … … 147 147 int i, rc; 148 148 149 rc = read _all(elf->fd, header, sizeof(elf_header_t));149 rc = read(elf->fd, header, sizeof(elf_header_t)); 150 150 if (rc != sizeof(elf_header_t)) { 151 151 DPRINTF("Read error.\n"); … … 209 209 + i * sizeof(elf_segment_header_t), SEEK_SET); 210 210 211 rc = read _all(elf->fd, &segment_hdr,211 rc = read(elf->fd, &segment_hdr, 212 212 sizeof(elf_segment_header_t)); 213 213 if (rc != sizeof(elf_segment_header_t)) { … … 231 231 + i * sizeof(elf_section_header_t), SEEK_SET); 232 232 233 rc = read _all(elf->fd, §ion_hdr,233 rc = read(elf->fd, §ion_hdr, 234 234 sizeof(elf_section_header_t)); 235 235 if (rc != sizeof(elf_section_header_t)) { … … 399 399 if (now > left) now = left; 400 400 401 rc = read _all(elf->fd, dp, now);401 rc = read(elf->fd, dp, now); 402 402 403 403 if (rc != (ssize_t) now) { -
uspace/lib/c/generic/io/console.c
rf1f7584 r6afc9d7 49 49 return NULL; 50 50 51 ctrl->input_sess = fsession(ifile, INTERFACE_CONSOLE);51 ctrl->input_sess = vfs_fsession(ifile, INTERFACE_CONSOLE); 52 52 if (!ctrl->input_sess) { 53 53 free(ctrl); … … 55 55 } 56 56 57 ctrl->output_sess = fsession(ofile, INTERFACE_CONSOLE);57 ctrl->output_sess = vfs_fsession(ofile, INTERFACE_CONSOLE); 58 58 if (!ctrl->output_sess) { 59 59 free(ctrl); -
uspace/lib/c/generic/io/io.c
rf1f7584 r6afc9d7 231 231 if (stream->buf == NULL) { 232 232 errno = ENOMEM; 233 return -1;233 return EOF; 234 234 } 235 235 … … 365 365 * @param nmemb Number of records to read. 366 366 * @param stream Pointer to the stream. 367 * 368 * @return Number of elements successfully read. On error this is less than 369 * nmemb, stream error indicator is set and errno is set. 367 370 */ 368 371 static size_t _fread(void *buf, size_t size, size_t nmemb, FILE *stream) … … 379 382 ssize_t rd = read(stream->fd, buf + done, left); 380 383 381 if (rd < 0) 384 if (rd < 0) { 385 /* errno was set by read() */ 382 386 stream->error = true; 383 else if (rd == 0)387 } else if (rd == 0) { 384 388 stream->eof = true; 385 else {389 } else { 386 390 left -= rd; 387 391 done += rd; … … 398 402 * @param nmemb Number of records to write. 399 403 * @param stream Pointer to the stream. 404 * 405 * @return Number of elements successfully written. On error this is less than 406 * nmemb, stream error indicator is set and errno is set. 400 407 */ 401 408 static size_t _fwrite(const void *buf, size_t size, size_t nmemb, FILE *stream) … … 403 410 size_t left; 404 411 size_t done; 412 int rc; 405 413 406 414 if (size == 0 || nmemb == 0) … … 412 420 while ((left > 0) && (!stream->error)) { 413 421 ssize_t wr; 422 size_t uwr; 414 423 415 if (stream->kio) 416 wr = kio_write(buf + done, left); 417 else 424 if (stream->kio) { 425 uwr = 0; 426 rc = kio_write(buf + done, left, &uwr); 427 if (rc != EOK) 428 errno = rc; 429 } else { 418 430 wr = write(stream->fd, buf + done, left); 431 if (wr >= 0) { 432 uwr = (size_t)wr; 433 rc = EOK; 434 } else { 435 /* errno was set by write */ 436 uwr = 0; 437 rc = errno; 438 } 439 } 419 440 420 if (wr <= 0) 441 if (rc != EOK) { 442 /* errno was set above */ 421 443 stream->error = true; 422 else {423 left -= wr;424 done += wr;444 } else { 445 left -= uwr; 446 done += uwr; 425 447 } 426 448 } … … 432 454 } 433 455 434 /** Read some data in stream buffer. */ 456 /** Read some data in stream buffer. 457 * 458 * On error, stream error indicator is set and errno is set. 459 */ 435 460 static void _ffillbuf(FILE *stream) 436 461 { … … 441 466 rc = read(stream->fd, stream->buf, stream->buf_size); 442 467 if (rc < 0) { 468 /* errno was set by read() */ 443 469 stream->error = true; 444 470 return; … … 465 491 466 492 /* If buffer has prefetched read data, we need to seek back. */ 467 if (bytes_used > 0 && stream->buf_state == _bs_read) 468 lseek(stream->fd, - (ssize_t) bytes_used, SEEK_CUR); 493 if (bytes_used > 0 && stream->buf_state == _bs_read) { 494 off64_t rc; 495 rc = lseek(stream->fd, - (ssize_t) bytes_used, SEEK_CUR); 496 if (rc == (off64_t)-1) { 497 /* errno was set by lseek */ 498 stream->error = 1; 499 return; 500 } 501 } 469 502 470 503 /* If buffer has unwritten data, we need to write them out. */ 471 if (bytes_used > 0 && stream->buf_state == _bs_write) 504 if (bytes_used > 0 && stream->buf_state == _bs_write) { 472 505 (void) _fwrite(stream->buf_tail, 1, bytes_used, stream); 506 /* On error stream error indicator and errno are set by _fwrite */ 507 if (stream->error) 508 return; 509 } 473 510 474 511 stream->buf_head = stream->buf; … … 528 565 _ffillbuf(stream); 529 566 530 if (stream->error || stream->eof) 567 if (stream->error || stream->eof) { 568 /* On error errno was set by _ffillbuf() */ 531 569 break; 570 } 532 571 533 572 data_avail = stream->buf_head - stream->buf_tail; … … 584 623 if (stream->buf_state == _bs_read) 585 624 _fflushbuf(stream); 586 587 625 588 626 /* Perform lazy allocation of stream buffer. */ … … 622 660 /* Only need to drain buffer. */ 623 661 _fflushbuf(stream); 624 need_flush = false; 662 if (!stream->error) 663 need_flush = false; 625 664 } 626 665 } … … 734 773 off64_t rc; 735 774 775 if (stream->error) 776 return EOF; 777 736 778 _fflushbuf(stream); 779 if (stream->error) { 780 /* errno was set by _fflushbuf() */ 781 return EOF; 782 } 783 737 784 stream->ungetc_chars = 0; 738 785 739 786 rc = lseek(stream->fd, offset, whence); 740 787 if (rc == (off64_t) (-1)) { 741 /* errno has been set by lseek 64.*/742 return -1;788 /* errno has been set by lseek() */ 789 return EOF; 743 790 } 744 791 … … 749 796 off64_t ftell(FILE *stream) 750 797 { 798 off64_t pos; 799 800 if (stream->error) 801 return EOF; 802 751 803 _fflushbuf(stream); 752 return lseek(stream->fd, 0, SEEK_CUR) - stream->ungetc_chars; 804 if (stream->error) { 805 /* errno was set by _fflushbuf() */ 806 return EOF; 807 } 808 809 pos = lseek(stream->fd, 0, SEEK_CUR); 810 if (pos == (off64_t) -1) { 811 /* errno was set by lseek */ 812 return (off64_t) -1; 813 } 814 815 return pos - stream->ungetc_chars; 753 816 } 754 817 … … 760 823 int fflush(FILE *stream) 761 824 { 825 if (stream->error) 826 return EOF; 827 762 828 _fflushbuf(stream); 829 if (stream->error) { 830 /* errno was set by _fflushbuf() */ 831 return EOF; 832 } 763 833 764 834 if (stream->kio) { 765 835 kio_update(); 766 return EOK;836 return 0; 767 837 } 768 838 … … 773 843 */ 774 844 stream->need_sync = false; 775 return fsync(stream->fd); 776 } 777 778 return ENOENT; 845 if (fsync(stream->fd) != 0) { 846 /* errno was set by fsync() */ 847 return EOF; 848 } 849 850 return 0; 851 } 852 853 return 0; 779 854 } 780 855 … … 799 874 if (stream->kio) { 800 875 errno = EBADF; 801 return -1;876 return EOF; 802 877 } 803 878 … … 805 880 } 806 881 807 async_sess_t * fsession(FILE *stream, iface_t iface)882 async_sess_t *vfs_fsession(FILE *stream, iface_t iface) 808 883 { 809 884 if (stream->fd >= 0) { 810 885 if (stream->sess == NULL) 811 stream->sess = fd_session(stream->fd, iface);886 stream->sess = vfs_fd_session(stream->fd, iface); 812 887 813 888 return stream->sess; … … 817 892 } 818 893 819 int fhandle(FILE *stream, int *handle)894 int vfs_fhandle(FILE *stream, int *handle) 820 895 { 821 896 if (stream->fd >= 0) { -
uspace/lib/c/generic/io/kio.c
rf1f7584 r6afc9d7 43 43 #include <io/printf_core.h> 44 44 45 size_t kio_write(const void *buf, size_t size)45 int kio_write(const void *buf, size_t size, size_t *nwritten) 46 46 { 47 ssize_t ret = (ssize_t) __SYSCALL3(SYS_KIO, KIO_WRITE, (sysarg_t) buf, size);47 int rc = (int) __SYSCALL3(SYS_KIO, KIO_WRITE, (sysarg_t) buf, size); 48 48 49 if (ret >= 0) 50 return (size_t) ret; 51 52 return 0; 49 if (rc == EOK) 50 *nwritten = size; 51 return rc; 53 52 } 54 53 … … 84 83 static int kio_vprintf_str_write(const char *str, size_t size, void *data) 85 84 { 86 size_t wr = kio_write(str, size); 85 size_t wr; 86 87 wr = 0; 88 (void) kio_write(str, size, &wr); 87 89 return str_nlength(str, wr); 88 90 } … … 92 94 size_t offset = 0; 93 95 size_t chars = 0; 96 size_t wr; 94 97 95 98 while (offset < size) { … … 98 101 99 102 if (chr_encode(str[chars], buf, &sz, STR_BOUNDS(1)) == EOK) 100 kio_write(buf, sz );103 kio_write(buf, sz, &wr); 101 104 102 105 chars++; -
uspace/lib/c/generic/loader.c
rf1f7584 r6afc9d7 124 124 return ENOMEM; 125 125 126 if ( !getcwd(cwd, MAX_PATH_LEN + 1))126 if (getcwd(cwd, MAX_PATH_LEN + 1) == NULL) 127 127 str_cpy(cwd, MAX_PATH_LEN + 1, "/"); 128 128 … … 162 162 { 163 163 size_t pa_len; 164 char *pa = absolutize(path, &pa_len);164 char *pa = vfs_absolutize(path, &pa_len); 165 165 if (!pa) 166 166 return ENOMEM; -
uspace/lib/c/generic/task.c
rf1f7584 r6afc9d7 112 112 int fd_stderr; 113 113 114 if ((stdin != NULL) && ( fhandle(stdin, &fd_stdin) == EOK))114 if ((stdin != NULL) && (vfs_fhandle(stdin, &fd_stdin) == EOK)) 115 115 files[0] = &fd_stdin; 116 116 else 117 117 files[0] = NULL; 118 118 119 if ((stdout != NULL) && ( fhandle(stdout, &fd_stdout) == EOK))119 if ((stdout != NULL) && (vfs_fhandle(stdout, &fd_stdout) == EOK)) 120 120 files[1] = &fd_stdout; 121 121 else 122 122 files[1] = NULL; 123 123 124 if ((stderr != NULL) && ( fhandle(stderr, &fd_stderr) == EOK))124 if ((stderr != NULL) && (vfs_fhandle(stderr, &fd_stderr) == EOK)) 125 125 files[2] = &fd_stderr; 126 126 else -
uspace/lib/c/generic/vfs/vfs.c
rf1f7584 r6afc9d7 93 93 } 94 94 95 char * absolutize(const char *path, size_t *retlen)95 char *vfs_absolutize(const char *path, size_t *retlen) 96 96 { 97 97 char *ncwd_path; … … 101 101 size_t size = str_size(path); 102 102 if (*path != '/') { 103 if ( !cwd_path) {103 if (cwd_path == NULL) { 104 104 fibril_mutex_unlock(&cwd_mutex); 105 105 return NULL; 106 106 } 107 107 ncwd_path_nc = malloc(cwd_size + 1 + size + 1); 108 if ( !ncwd_path_nc) {108 if (ncwd_path_nc == NULL) { 109 109 fibril_mutex_unlock(&cwd_mutex); 110 110 return NULL; … … 115 115 } else { 116 116 ncwd_path_nc = malloc(size + 1); 117 if ( !ncwd_path_nc) {117 if (ncwd_path_nc == NULL) { 118 118 fibril_mutex_unlock(&cwd_mutex); 119 119 return NULL; … … 123 123 str_append(ncwd_path_nc, cwd_size + 1 + size + 1, path); 124 124 ncwd_path = canonify(ncwd_path_nc, retlen); 125 if ( !ncwd_path) {125 if (ncwd_path == NULL) { 126 126 fibril_mutex_unlock(&cwd_mutex); 127 127 free(ncwd_path_nc); … … 135 135 ncwd_path = str_dup(ncwd_path); 136 136 free(ncwd_path_nc); 137 if ( !ncwd_path) {137 if (ncwd_path == NULL) { 138 138 fibril_mutex_unlock(&cwd_mutex); 139 139 return NULL; … … 143 143 } 144 144 145 int mount(const char *fs_name, const char *mp, const char *fqsn,145 int vfs_mount(const char *fs_name, const char *mp, const char *fqsn, 146 146 const char *opts, unsigned int flags, unsigned int instance) 147 147 { … … 171 171 172 172 size_t mpa_size; 173 char *mpa = absolutize(mp, &mpa_size);174 if ( !mpa) {173 char *mpa = vfs_absolutize(mp, &mpa_size); 174 if (mpa == NULL) { 175 175 if (null_id != -1) 176 176 loc_null_destroy(null_id); … … 255 255 } 256 256 257 int unmount(const char *mp)257 int vfs_unmount(const char *mp) 258 258 { 259 259 sysarg_t rc; … … 263 263 char *mpa; 264 264 265 mpa = absolutize(mp, &mpa_size);266 if ( !mpa)265 mpa = vfs_absolutize(mp, &mpa_size); 266 if (mpa == NULL) 267 267 return ENOMEM; 268 268 … … 289 289 } 290 290 291 static int open_internal(const char *abs, size_t abs_size, int lflag, int oflag) 291 /** Open file (internal). 292 * 293 * @param abs Absolute path to file 294 * @param abs_size Size of @a abs string 295 * @param lflag L_xxx flags 296 * @param oflag O_xxx flags 297 * @param fd Place to store new file descriptor 298 * 299 * @return EOK on success, non-zero error code on error 300 */ 301 static int open_internal(const char *abs, size_t abs_size, int lflag, int oflag, 302 int *fd) 292 303 { 293 304 async_exch_t *exch = vfs_exchange_begin(); … … 315 326 return (int) rc; 316 327 317 return (int) IPC_GET_ARG1(answer); 318 } 319 328 *fd = (int) IPC_GET_ARG1(answer); 329 return EOK; 330 } 331 332 /** Open file. 333 * 334 * @param path File path 335 * @param oflag O_xxx flags 336 * @param mode File mode (only with O_CREAT) 337 * 338 * @return Nonnegative file descriptor on success. On error -1 is returned 339 * and errno is set. 340 */ 320 341 int open(const char *path, int oflag, ...) 321 342 { 322 343 size_t abs_size; 323 char *abs = absolutize(path, &abs_size); 324 if (!abs) 325 return ENOMEM; 326 327 int ret = open_internal(abs, abs_size, L_FILE, oflag); 344 char *abs = vfs_absolutize(path, &abs_size); 345 int fd = -1; 346 347 if (abs == NULL) { 348 errno = ENOMEM; 349 return -1; 350 } 351 352 int rc = open_internal(abs, abs_size, L_FILE, oflag, &fd); 328 353 free(abs); 329 354 330 return ret; 331 } 332 355 if (rc != EOK) { 356 errno = rc; 357 return -1; 358 } 359 360 return fd; 361 } 362 363 /** Close file. 364 * 365 * @param fildes File descriptor 366 * @return Zero on success. On error -1 is returned and errno is set. 367 */ 333 368 int close(int fildes) 334 369 { … … 339 374 vfs_exchange_end(exch); 340 375 341 return (int) rc; 342 } 343 344 ssize_t read(int fildes, void *buf, size_t nbyte) 376 if (rc != EOK) { 377 errno = rc; 378 return -1; 379 } 380 381 return 0; 382 } 383 384 /** Read bytes from file. 385 * 386 * Read up to @a nbyte bytes from file. The actual number of bytes read 387 * may be lower, but greater than zero if there are any bytes available. 388 * If there are no bytes available for reading, then the function will 389 * return success with zero bytes read. 390 * 391 * @param fildes File descriptor 392 * @param buf Buffer 393 * @param nbyte Maximum number of bytes to read 394 * @param nread Place to store actual number of bytes read (0 or more) 395 * 396 * @return EOK on success, non-zero error code on error. 397 */ 398 static int _read_short(int fildes, void *buf, size_t nbyte, ssize_t *nread) 345 399 { 346 400 sysarg_t rc; … … 357 411 if (rc != EOK) { 358 412 vfs_exchange_end(exch); 359 413 360 414 sysarg_t rc_orig; 361 415 async_wait_for(req, &rc_orig); 362 416 363 417 if (rc_orig == EOK) 364 return (ssize_t)rc;418 return rc; 365 419 else 366 return (ssize_t) rc_orig; 367 } 420 return rc_orig; 421 } 422 368 423 vfs_exchange_end(exch); 369 424 async_wait_for(req, &rc); 370 if (rc == EOK) 371 return (ssize_t) IPC_GET_ARG1(answer); 372 else 425 426 if (rc != EOK) 373 427 return rc; 374 } 375 376 ssize_t write(int fildes, const void *buf, size_t nbyte) 428 429 *nread = (ssize_t) IPC_GET_ARG1(answer); 430 return EOK; 431 } 432 433 /** Write bytes to file. 434 * 435 * Write up to @a nbyte bytes from file. The actual number of bytes written 436 * may be lower, but greater than zero. 437 * 438 * @param fildes File descriptor 439 * @param buf Buffer 440 * @param nbyte Maximum number of bytes to write 441 * @param nread Place to store actual number of bytes written (0 or more) 442 * 443 * @return EOK on success, non-zero error code on error. 444 */ 445 static int _write_short(int fildes, const void *buf, size_t nbyte, 446 ssize_t *nwritten) 377 447 { 378 448 sysarg_t rc; … … 389 459 if (rc != EOK) { 390 460 vfs_exchange_end(exch); 391 461 392 462 sysarg_t rc_orig; 393 463 async_wait_for(req, &rc_orig); 394 464 395 465 if (rc_orig == EOK) 396 return (ssize_t)rc;466 return rc; 397 467 else 398 return (ssize_t) rc_orig; 399 } 468 return rc_orig; 469 } 470 400 471 vfs_exchange_end(exch); 401 472 async_wait_for(req, &rc); 402 if (rc == EOK) 403 return (ssize_t) IPC_GET_ARG1(answer); 404 else 405 return -1; 406 } 407 408 /** Read entire buffer. 409 * 410 * In face of short reads this function continues reading until either 411 * the entire buffer is read or no more data is available (at end of file). 473 474 if (rc != EOK) 475 return rc; 476 477 *nwritten = (ssize_t) IPC_GET_ARG1(answer); 478 return EOK; 479 } 480 481 /** Read data. 482 * 483 * Read up to @a nbytes bytes from file if available. This function always reads 484 * all the available bytes up to @a nbytes. 412 485 * 413 486 * @param fildes File descriptor … … 415 488 * @param nbytes Number of bytes to read 416 489 * 417 * @return On success, positive number of bytes read.418 * On failure, negative error code from read().419 */ 420 ssize_t read _all(int fildes, void *buf, size_t nbyte)490 * @return On success, nonnegative number of bytes read. 491 * On failure, -1 and sets errno. 492 */ 493 ssize_t read(int fildes, void *buf, size_t nbyte) 421 494 { 422 495 ssize_t cnt = 0; 423 496 size_t nread = 0; 424 497 uint8_t *bp = (uint8_t *) buf; 425 498 int rc; 499 426 500 do { 427 501 bp += cnt; 428 502 nread += cnt; 429 cnt = read(fildes, bp, nbyte - nread); 430 } while (cnt > 0 && (nbyte - nread - cnt) > 0); 431 432 if (cnt < 0) 433 return cnt; 434 503 rc = _read_short(fildes, bp, nbyte - nread, &cnt); 504 } while (rc == EOK && cnt > 0 && (nbyte - nread - cnt) > 0); 505 506 if (rc != EOK) { 507 errno = rc; 508 return -1; 509 } 510 435 511 return nread + cnt; 436 512 } 437 513 438 /** Write entire buffer.514 /** Write data. 439 515 * 440 516 * This function fails if it cannot write exactly @a len bytes to the file. … … 444 520 * @param nbytes Number of bytes to write 445 521 * 446 * @return EOK on error, return value from write() if writing447 * failed.448 */ 449 ssize_t write _all(int fildes, const void *buf, size_t nbyte)522 * @return On success, nonnegative number of bytes written. 523 * On failure, -1 and sets errno. 524 */ 525 ssize_t write(int fildes, const void *buf, size_t nbyte) 450 526 { 451 527 ssize_t cnt = 0; 452 528 ssize_t nwritten = 0; 453 529 const uint8_t *bp = (uint8_t *) buf; 530 int rc; 454 531 455 532 do { 456 533 bp += cnt; 457 534 nwritten += cnt; 458 cnt = write(fildes, bp, nbyte - nwritten); 459 } while (cnt > 0 && ((ssize_t )nbyte - nwritten - cnt) > 0); 460 461 if (cnt < 0) 462 return cnt; 463 464 if ((ssize_t)nbyte - nwritten - cnt > 0) 465 return EIO; 535 rc = _write_short(fildes, bp, nbyte - nwritten, &cnt); 536 } while (rc == EOK && ((ssize_t )nbyte - nwritten - cnt) > 0); 537 538 if (rc != EOK) { 539 errno = rc; 540 return -1; 541 } 466 542 467 543 return nbyte; 468 544 } 469 545 546 /** Synchronize file. 547 * 548 * @param fildes File descriptor 549 * @return 0 on success. On error returns -1 and sets errno. 550 */ 470 551 int fsync(int fildes) 471 552 { … … 474 555 vfs_exchange_end(exch); 475 556 476 return (int) rc; 477 } 478 557 if (rc != EOK) { 558 errno = rc; 559 return -1; 560 } 561 562 return 0; 563 } 564 565 /** Seek to a position. 566 * 567 * @param fildes File descriptor 568 * @param offset Offset 569 * @param whence SEEK_SET, SEEK_CUR or SEEK_END 570 * 571 * @return On success the nonnegative offset from start of file. On error 572 * returns (off64_t)-1 and sets errno. 573 */ 479 574 off64_t lseek(int fildes, off64_t offset, int whence) 480 575 { … … 489 584 vfs_exchange_end(exch); 490 585 491 if (rc != EOK) 586 if (rc != EOK) { 587 errno = rc; 492 588 return (off64_t) -1; 589 } 493 590 494 591 return (off64_t) MERGE_LOUP32(newoff_lo, newoff_hi); 495 592 } 496 593 594 /** Truncate file to a specified length. 595 * 596 * Truncate file so that its size is exactly @a length 597 * 598 * @param fildes File descriptor 599 * @param length Length 600 * 601 * @return 0 on success, -1 on error and sets errno. 602 */ 497 603 int ftruncate(int fildes, aoff64_t length) 498 604 { … … 504 610 vfs_exchange_end(exch); 505 611 506 return (int) rc; 507 } 508 612 if (rc != EOK) { 613 errno = rc; 614 return -1; 615 } 616 617 return 0; 618 } 619 620 /** Get file status. 621 * 622 * @param fildes File descriptor 623 * @param stat Place to store file information 624 * 625 * @return 0 on success, -1 on error and sets errno. 626 */ 509 627 int fstat(int fildes, struct stat *stat) 510 628 { … … 518 636 if (rc != EOK) { 519 637 vfs_exchange_end(exch); 520 638 521 639 sysarg_t rc_orig; 522 640 async_wait_for(req, &rc_orig); 523 524 if (rc_orig == EOK) 525 return (ssize_t) rc; 526 else 527 return (ssize_t) rc_orig; 528 } 641 642 if (rc_orig != EOK) 643 rc = rc_orig; 644 if (rc != EOK) { 645 errno = rc; 646 return -1; 647 } 648 649 return 0; 650 } 651 529 652 vfs_exchange_end(exch); 530 653 async_wait_for(req, &rc); 531 532 return rc; 533 } 534 654 655 if (rc != EOK) { 656 errno = rc; 657 return -1; 658 } 659 660 return 0; 661 } 662 663 /** Get file status. 664 * 665 * @param path Path to file 666 * @param stat Place to store file information 667 * 668 * @return 0 on success, -1 on error and sets errno. 669 */ 535 670 int stat(const char *path, struct stat *stat) 536 671 { … … 540 675 541 676 size_t pa_size; 542 char *pa = absolutize(path, &pa_size); 543 if (!pa) 544 return ENOMEM; 677 char *pa = vfs_absolutize(path, &pa_size); 678 if (pa == NULL) { 679 errno = ENOMEM; 680 return -1; 681 } 545 682 546 683 async_exch_t *exch = vfs_exchange_begin(); … … 552 689 free(pa); 553 690 async_wait_for(req, &rc_orig); 691 if (rc_orig != EOK) 692 rc = rc_orig; 693 if (rc != EOK) { 694 errno = rc; 695 return -1; 696 } 697 } 698 rc = async_data_read_start(exch, stat, sizeof(struct stat)); 699 if (rc != EOK) { 700 vfs_exchange_end(exch); 701 free(pa); 702 async_wait_for(req, &rc_orig); 703 if (rc_orig != EOK) 704 rc = rc_orig; 705 if (rc != EOK) { 706 errno = rc; 707 return -1; 708 } 709 } 710 vfs_exchange_end(exch); 711 free(pa); 712 async_wait_for(req, &rc); 713 if (rc != EOK) { 714 errno = rc; 715 return -1; 716 } 717 return 0; 718 } 719 720 /** Open directory. 721 * 722 * @param dirname Directory pathname 723 * 724 * @return Non-NULL pointer on success. On error returns @c NULL and sets errno. 725 */ 726 DIR *opendir(const char *dirname) 727 { 728 DIR *dirp = malloc(sizeof(DIR)); 729 int fd = -1; 730 731 if (dirp == NULL) { 732 errno = ENOMEM; 733 return NULL; 734 } 735 736 size_t abs_size; 737 char *abs = vfs_absolutize(dirname, &abs_size); 738 if (abs == NULL) { 739 free(dirp); 740 errno = ENOMEM; 741 return NULL; 742 } 743 744 int rc = open_internal(abs, abs_size, L_DIRECTORY, 0, &fd); 745 free(abs); 746 747 if (rc != EOK) { 748 free(dirp); 749 errno = rc; 750 return NULL; 751 } 752 753 dirp->fd = fd; 754 return dirp; 755 } 756 757 /** Read directory entry. 758 * 759 * @param dirp Open directory 760 * @return Non-NULL pointer to directory entry on success. On error returns 761 * @c NULL and sets errno. 762 */ 763 struct dirent *readdir(DIR *dirp) 764 { 765 int rc; 766 ssize_t len; 767 768 rc = _read_short(dirp->fd, &dirp->res.d_name[0], NAME_MAX + 1, &len); 769 if (rc != EOK) { 770 errno = rc; 771 return NULL; 772 } 773 774 (void) len; 775 return &dirp->res; 776 } 777 778 /** Rewind directory position to the beginning. 779 * 780 * @param dirp Open directory 781 */ 782 void rewinddir(DIR *dirp) 783 { 784 (void) lseek(dirp->fd, 0, SEEK_SET); 785 } 786 787 /** Close directory. 788 * 789 * @param dirp Open directory 790 * @return 0 on success. On error returns -1 and sets errno. 791 */ 792 int closedir(DIR *dirp) 793 { 794 int rc; 795 796 rc = close(dirp->fd); 797 free(dirp); 798 799 /* On error errno was set by close() */ 800 return rc; 801 } 802 803 /** Create directory. 804 * 805 * @param path Path 806 * @param mode File mode 807 * @return 0 on success. On error returns -1 and sets errno. 808 */ 809 int mkdir(const char *path, mode_t mode) 810 { 811 sysarg_t rc; 812 aid_t req; 813 814 size_t pa_size; 815 char *pa = vfs_absolutize(path, &pa_size); 816 if (pa == NULL) { 817 errno = ENOMEM; 818 return -1; 819 } 820 821 async_exch_t *exch = vfs_exchange_begin(); 822 823 req = async_send_1(exch, VFS_IN_MKDIR, mode, NULL); 824 rc = async_data_write_start(exch, pa, pa_size); 825 if (rc != EOK) { 826 vfs_exchange_end(exch); 827 free(pa); 828 829 sysarg_t rc_orig; 830 async_wait_for(req, &rc_orig); 831 832 if (rc_orig != EOK) 833 rc = rc_orig; 834 835 if (rc != EOK) { 836 errno = rc; 837 return -1; 838 } 839 840 return 0; 841 } 842 843 vfs_exchange_end(exch); 844 free(pa); 845 async_wait_for(req, &rc); 846 847 if (rc != EOK) { 848 errno = rc; 849 return -1; 850 } 851 852 return 0; 853 } 854 855 /** Unlink a file or directory. 856 * 857 * @param path Path to file or empty directory 858 * @param lflag L_xxx flag (L_NONE, L_FILE or L_DIRECTORY) 859 * @return EOK on success, non-zero error code on error 860 */ 861 static int _unlink(const char *path, int lflag) 862 { 863 sysarg_t rc; 864 aid_t req; 865 866 size_t pa_size; 867 char *pa = vfs_absolutize(path, &pa_size); 868 if (pa == NULL) 869 return ENOMEM; 870 871 async_exch_t *exch = vfs_exchange_begin(); 872 873 req = async_send_1(exch, VFS_IN_UNLINK, lflag, NULL); 874 rc = async_data_write_start(exch, pa, pa_size); 875 if (rc != EOK) { 876 vfs_exchange_end(exch); 877 free(pa); 878 879 sysarg_t rc_orig; 880 async_wait_for(req, &rc_orig); 881 554 882 if (rc_orig == EOK) 555 883 return (int) rc; … … 557 885 return (int) rc_orig; 558 886 } 559 rc = async_data_read_start(exch, stat, sizeof(struct stat));560 if (rc != EOK) {561 vfs_exchange_end(exch);562 free(pa);563 async_wait_for(req, &rc_orig);564 if (rc_orig == EOK)565 return (int) rc;566 else567 return (int) rc_orig;568 }569 887 vfs_exchange_end(exch); 570 888 free(pa); … … 573 891 } 574 892 575 DIR *opendir(const char *dirname) 576 { 577 DIR *dirp = malloc(sizeof(DIR)); 578 if (!dirp) 579 return NULL; 580 581 size_t abs_size; 582 char *abs = absolutize(dirname, &abs_size); 583 if (!abs) { 584 free(dirp); 585 return NULL; 586 } 587 588 int ret = open_internal(abs, abs_size, L_DIRECTORY, 0); 589 free(abs); 590 591 if (ret < 0) { 592 free(dirp); 593 return NULL; 594 } 595 596 dirp->fd = ret; 597 return dirp; 598 } 599 600 struct dirent *readdir(DIR *dirp) 601 { 602 ssize_t len = read(dirp->fd, &dirp->res.d_name[0], NAME_MAX + 1); 603 if (len <= 0) 604 return NULL; 605 return &dirp->res; 606 } 607 608 void rewinddir(DIR *dirp) 609 { 610 (void) lseek(dirp->fd, 0, SEEK_SET); 611 } 612 613 int closedir(DIR *dirp) 614 { 615 (void) close(dirp->fd); 616 free(dirp); 893 /** Unlink file or directory. 894 * 895 * @param path Path 896 * @return EOk on success, error code on error 897 */ 898 int unlink(const char *path) 899 { 900 int rc; 901 902 rc = _unlink(path, L_NONE); 903 if (rc != EOK) { 904 errno = rc; 905 return -1; 906 } 907 617 908 return 0; 618 909 } 619 910 620 int mkdir(const char *path, mode_t mode) 621 { 622 sysarg_t rc; 623 aid_t req; 624 625 size_t pa_size; 626 char *pa = absolutize(path, &pa_size); 627 if (!pa) 628 return ENOMEM; 629 630 async_exch_t *exch = vfs_exchange_begin(); 631 632 req = async_send_1(exch, VFS_IN_MKDIR, mode, NULL); 633 rc = async_data_write_start(exch, pa, pa_size); 634 if (rc != EOK) { 635 vfs_exchange_end(exch); 636 free(pa); 637 638 sysarg_t rc_orig; 639 async_wait_for(req, &rc_orig); 640 641 if (rc_orig == EOK) 642 return (int) rc; 643 else 644 return (int) rc_orig; 645 } 646 vfs_exchange_end(exch); 647 free(pa); 648 async_wait_for(req, &rc); 649 return rc; 650 } 651 652 static int _unlink(const char *path, int lflag) 653 { 654 sysarg_t rc; 655 aid_t req; 656 657 size_t pa_size; 658 char *pa = absolutize(path, &pa_size); 659 if (!pa) 660 return ENOMEM; 661 662 async_exch_t *exch = vfs_exchange_begin(); 663 664 req = async_send_1(exch, VFS_IN_UNLINK, lflag, NULL); 665 rc = async_data_write_start(exch, pa, pa_size); 666 if (rc != EOK) { 667 vfs_exchange_end(exch); 668 free(pa); 669 670 sysarg_t rc_orig; 671 async_wait_for(req, &rc_orig); 672 673 if (rc_orig == EOK) 674 return (int) rc; 675 else 676 return (int) rc_orig; 677 } 678 vfs_exchange_end(exch); 679 free(pa); 680 async_wait_for(req, &rc); 681 return rc; 682 } 683 684 int unlink(const char *path) 685 { 686 return _unlink(path, L_NONE); 687 } 688 911 /** Remove empty directory. 912 * 913 * @param path Path 914 * @return 0 on success. On error returns -1 and sets errno. 915 */ 689 916 int rmdir(const char *path) 690 917 { 691 return _unlink(path, L_DIRECTORY); 692 } 693 918 int rc; 919 920 rc = _unlink(path, L_DIRECTORY); 921 if (rc != EOK) { 922 errno = rc; 923 return -1; 924 } 925 926 return 0; 927 } 928 929 /** Rename directory entry. 930 * 931 * @param old Old name 932 * @param new New name 933 * 934 * @return 0 on success. On error returns -1 and sets errno. 935 */ 694 936 int rename(const char *old, const char *new) 695 937 { … … 699 941 700 942 size_t olda_size; 701 char *olda = absolutize(old, &olda_size); 702 if (!olda) 703 return ENOMEM; 943 char *olda = vfs_absolutize(old, &olda_size); 944 if (olda == NULL) { 945 errno = ENOMEM; 946 return -1; 947 } 704 948 705 949 size_t newa_size; 706 char *newa = absolutize(new, &newa_size);707 if ( !newa) {950 char *newa = vfs_absolutize(new, &newa_size); 951 if (newa == NULL) { 708 952 free(olda); 709 return ENOMEM; 953 errno = ENOMEM; 954 return -1; 710 955 } 711 956 … … 719 964 free(newa); 720 965 async_wait_for(req, &rc_orig); 721 if (rc_orig == EOK) 722 return (int) rc; 723 else 724 return (int) rc_orig; 966 if (rc_orig != EOK) 967 rc = rc_orig; 968 if (rc != EOK) { 969 errno = rc; 970 return -1; 971 } 972 return 0; 725 973 } 726 974 rc = async_data_write_start(exch, newa, newa_size); … … 730 978 free(newa); 731 979 async_wait_for(req, &rc_orig); 732 if (rc_orig == EOK) 733 return (int) rc; 734 else 735 return (int) rc_orig; 980 if (rc_orig != EOK) 981 rc = rc_orig; 982 if (rc != EOK) { 983 errno = rc; 984 return -1; 985 } 986 return 0; 736 987 } 737 988 vfs_exchange_end(exch); … … 739 990 free(newa); 740 991 async_wait_for(req, &rc); 741 return rc; 742 } 743 992 993 if (rc != EOK) { 994 errno = rc; 995 return -1; 996 } 997 998 return 0; 999 } 1000 1001 /** Remove directory entry. 1002 * 1003 * @param path Path 1004 * @return 0 on success. On error returns -1 and sets errno. 1005 */ 744 1006 int remove(const char *path) 745 1007 { … … 747 1009 } 748 1010 1011 /** Change working directory. 1012 * 1013 * @param path Path 1014 * @return 0 on success. On error returns -1 and sets errno. 1015 */ 749 1016 int chdir(const char *path) 750 1017 { 751 1018 size_t abs_size; 752 char *abs = absolutize(path, &abs_size); 753 if (!abs) 754 return ENOMEM; 755 756 int fd = open_internal(abs, abs_size, L_DIRECTORY, O_DESC); 757 758 if (fd < 0) { 1019 char *abs = vfs_absolutize(path, &abs_size); 1020 int fd = -1; 1021 1022 if (abs == NULL) { 1023 errno = ENOMEM; 1024 return -1; 1025 } 1026 1027 int rc = open_internal(abs, abs_size, L_DIRECTORY, O_DESC, &fd); 1028 1029 if (rc != EOK) { 759 1030 free(abs); 760 return ENOENT; 1031 errno = rc; 1032 return -1; 761 1033 } 762 1034 … … 765 1037 if (cwd_fd >= 0) 766 1038 close(cwd_fd); 767 768 1039 769 1040 if (cwd_path) … … 775 1046 776 1047 fibril_mutex_unlock(&cwd_mutex); 777 return EOK; 778 } 779 1048 return 0; 1049 } 1050 1051 /** Get current working directory path. 1052 * 1053 * @param buf Buffer 1054 * @param size Size of @a buf 1055 * @return On success returns @a buf. On failure returns @c NULL and sets errno. 1056 */ 780 1057 char *getcwd(char *buf, size_t size) 781 1058 { 782 if (size == 0) 1059 if (size == 0) { 1060 errno = EINVAL; 783 1061 return NULL; 1062 } 784 1063 785 1064 fibril_mutex_lock(&cwd_mutex); … … 787 1066 if ((cwd_size == 0) || (size < cwd_size + 1)) { 788 1067 fibril_mutex_unlock(&cwd_mutex); 1068 errno = ERANGE; 789 1069 return NULL; 790 1070 } … … 796 1076 } 797 1077 798 async_sess_t *fd_session(int fildes, iface_t iface) 1078 /** Open session to service represented by a special file. 1079 * 1080 * Given that the file referred to by @a fildes represents a service, 1081 * open a session to that service. 1082 * 1083 * @param fildes File descriptor 1084 * @param iface Interface to connect to (XXX Should be automatic) 1085 * @return On success returns session pointer. On error returns @c NULL. 1086 */ 1087 async_sess_t *vfs_fd_session(int fildes, iface_t iface) 799 1088 { 800 1089 struct stat stat; 801 1090 int rc = fstat(fildes, &stat); 802 if (rc != 0) { 803 errno = rc; 1091 if (rc != 0) 804 1092 return NULL; 805 } 806 807 if (!stat.service) { 808 errno = ENOENT; 1093 1094 if (stat.service == 0) 809 1095 return NULL; 810 }811 1096 812 1097 return loc_service_connect(stat.service, iface, 0); 813 1098 } 814 1099 1100 /** Duplicate open file. 1101 * 1102 * Duplicate open file under a new file descriptor. 1103 * 1104 * @param oldfd Old file descriptor 1105 * @param newfd New file descriptor 1106 * @return 0 on success. On error -1 is returned and errno is set 1107 */ 815 1108 int dup2(int oldfd, int newfd) 816 1109 { … … 823 1116 824 1117 if (rc == EOK) 825 return (int) ret; 826 827 return (int) rc; 828 } 829 830 int fd_wait(void) 1118 rc = ret; 1119 1120 if (rc != EOK) { 1121 errno = rc; 1122 return -1; 1123 } 1124 1125 return 0; 1126 } 1127 1128 int vfs_fd_wait(void) 831 1129 { 832 1130 async_exch_t *exch = vfs_exchange_begin(); … … 843 1141 } 844 1142 845 int get_mtab_list(list_t *mtab_list)1143 int vfs_get_mtab_list(list_t *mtab_list) 846 1144 { 847 1145 sysarg_t rc; … … 863 1161 864 1162 mtab_ent = malloc(sizeof(mtab_ent_t)); 865 if ( !mtab_ent) {1163 if (mtab_ent == NULL) { 866 1164 rc = ENOMEM; 867 1165 goto exit; … … 904 1202 } 905 1203 1204 /** Get filesystem statistics. 1205 * 1206 * @param path Mount point path 1207 * @param st Buffer for storing information 1208 * @return 0 on success. On error -1 is returned and errno is set. 1209 */ 906 1210 int statfs(const char *path, struct statfs *st) 907 1211 { … … 910 1214 size_t pa_size; 911 1215 912 char *pa = absolutize(path, &pa_size); 913 if (!pa) 914 return ENOMEM; 1216 char *pa = vfs_absolutize(path, &pa_size); 1217 if (pa == NULL) { 1218 errno = ENOMEM; 1219 return -1; 1220 } 915 1221 916 1222 async_exch_t *exch = vfs_exchange_begin(); … … 927 1233 free(pa); 928 1234 async_wait_for(req, &rc_orig); 929 return (int) (rc_orig != EOK ? rc_orig : rc); 1235 rc = (rc_orig != EOK ? rc_orig : rc); 1236 1237 if (rc != EOK) { 1238 errno = rc; 1239 return -1; 1240 } 1241 1242 return 0; 930 1243 } 931 1244 -
uspace/lib/c/include/io/kio.h
rf1f7584 r6afc9d7 40 40 #include <io/verify.h> 41 41 42 extern size_t kio_write(const void *, size_t);42 extern int kio_write(const void *, size_t, size_t *); 43 43 extern void kio_update(void); 44 44 extern void kio_command(const void *, size_t); -
uspace/lib/c/include/sys/statfs.h
rf1f7584 r6afc9d7 46 46 47 47 extern int statfs(const char *, struct statfs *); 48 48 49 #endif 49 50 -
uspace/lib/c/include/unistd.h
rf1f7584 r6afc9d7 63 63 extern ssize_t read(int, void *, size_t); 64 64 65 extern ssize_t read_all(int, void *, size_t);66 extern ssize_t write_all(int, const void *, size_t);67 68 65 extern off64_t lseek(int, off64_t, int); 69 66 extern int ftruncate(int, aoff64_t); -
uspace/lib/c/include/vfs/vfs.h
rf1f7584 r6afc9d7 50 50 51 51 52 extern char * absolutize(const char *, size_t *);52 extern char *vfs_absolutize(const char *, size_t *); 53 53 54 extern int mount(const char *, const char *, const char *, const char *,54 extern int vfs_mount(const char *, const char *, const char *, const char *, 55 55 unsigned int, unsigned int); 56 extern int unmount(const char *);56 extern int vfs_unmount(const char *); 57 57 58 extern int fhandle(FILE *, int *);58 extern int vfs_fhandle(FILE *, int *); 59 59 60 extern int fd_wait(void);61 extern int get_mtab_list(list_t *mtab_list);60 extern int vfs_fd_wait(void); 61 extern int vfs_get_mtab_list(list_t *mtab_list); 62 62 63 63 extern async_exch_t *vfs_exchange_begin(void); 64 64 extern void vfs_exchange_end(async_exch_t *); 65 65 66 #endif 66 67 -
uspace/lib/c/include/vfs/vfs_sess.h
rf1f7584 r6afc9d7 39 39 #include <stdio.h> 40 40 41 extern async_sess_t * fd_session(int, iface_t);42 extern async_sess_t * fsession(FILE *, iface_t);41 extern async_sess_t *vfs_fd_session(int, iface_t); 42 extern async_sess_t *vfs_fsession(FILE *, iface_t); 43 43 44 44 #endif -
uspace/lib/pcut/src/os/helenos.c
rf1f7584 r6afc9d7 220 220 fibril_mutex_unlock(&forced_termination_mutex); 221 221 222 read _all(tempfile, extra_output_buffer, OUTPUT_BUFFER_SIZE);222 read(tempfile, extra_output_buffer, OUTPUT_BUFFER_SIZE); 223 223 224 224 leave_close_tempfile: -
uspace/lib/posix/source/fcntl.c
rf1f7584 r6afc9d7 112 112 } 113 113 114 int rc = open(pathname, flags, mode); 115 if (rc < 0) { 116 errno = -rc; 117 rc = -1; 118 } 119 120 return rc; 114 return negerrno(open, pathname, flags, mode); 121 115 } 122 116 -
uspace/lib/posix/source/internal/common.h
rf1f7584 r6afc9d7 48 48 } while (0) 49 49 50 /* A little helper macro to avoid typing this over and over.*/50 /* Convert negative error return value to positive errno */ 51 51 #define errnify(func, ...) ({ \ 52 52 int rc = func(__VA_ARGS__); \ … … 58 58 }) 59 59 60 /* Convert negative errno to positive errno */ 61 #define negerrno(func, ...) ({ \ 62 int rc = func(__VA_ARGS__); \ 63 if (rc < 0) { \ 64 errno = -errno; \ 65 } \ 66 rc; \ 67 }) 68 60 69 #endif /* LIBPOSIX_COMMON_H_ */ 61 70 -
uspace/lib/posix/source/stdio.c
rf1f7584 r6afc9d7 315 315 int posix_fflush(FILE *stream) 316 316 { 317 int rc = fflush(stream); 318 if (rc < 0) { 319 errno = -rc; 320 return EOF; 321 } else { 322 return 0; 323 } 317 return negerrno(fflush, stream); 324 318 } 325 319 … … 351 345 { 352 346 ssize_t wr = write(*(int *) fd, str, size); 347 if (wr < 0) 348 return errno; 353 349 return str_nlength(str, wr); 354 350 } … … 579 575 int posix_remove(const char *path) 580 576 { 581 struct stat st; 582 int rc = stat(path, &st); 583 584 if (rc != EOK) { 585 errno = -rc; 586 return -1; 587 } 588 589 if (st.is_directory) { 590 rc = rmdir(path); 591 } else { 592 rc = unlink(path); 593 } 594 595 if (rc != EOK) { 596 errno = -rc; 597 return -1; 598 } 599 return 0; 577 return negerrno(remove, path); 600 578 } 601 579 … … 609 587 int posix_rename(const char *old, const char *new) 610 588 { 611 return errnify(rename, old, new);589 return negerrno(rename, old, new); 612 590 } 613 591 -
uspace/lib/posix/source/stdlib.c
rf1f7584 r6afc9d7 278 278 * to be updated when that support is implemented. 279 279 */ 280 char* absolute = absolutize(name, NULL);280 char* absolute = vfs_absolutize(name, NULL); 281 281 282 282 if (absolute == NULL) { -
uspace/lib/posix/source/sys/stat.c
rf1f7584 r6afc9d7 80 80 { 81 81 struct stat hst; 82 int rc = fstat(fd, &hst); 83 if (rc < 0) { 84 /* fstat() returns negative error code instead of using errno. */ 85 errno = -rc; 86 return -1; 87 } 82 int rc = negerrno(fstat, fd, &hst); 83 if (rc < 0) 84 return rc; 88 85 stat_to_posix(st, &hst); 89 86 return 0; … … 113 110 { 114 111 struct stat hst; 115 int rc = stat(path, &hst); 116 if (rc < 0) { 117 /* stat() returns negative error code instead of using errno. */ 118 errno = -rc; 119 return -1; 120 } 112 int rc = negerrno(stat, path, &hst); 113 if (rc < 0) 114 return rc; 121 115 stat_to_posix(st, &hst); 122 116 return 0; -
uspace/lib/posix/source/unistd.c
rf1f7584 r6afc9d7 105 105 char *posix_getcwd(char *buf, size_t size) 106 106 { 107 /* Native getcwd() does not set any errno despite the fact that general 108 * usage pattern of this function depends on it (caller is repeatedly 109 * guessing the required size of the buffer by checking for ERANGE on 110 * failure). */ 111 if (size == 0) { 112 errno = EINVAL; 107 char *p = getcwd(buf, size); 108 109 if (p == NULL) { 110 errno = -errno; 113 111 return NULL; 114 112 } 115 116 /* Save the original value to comply with the "no modification on 117 * success" semantics. 118 */ 119 int orig_errno = errno; 120 errno = EOK; 121 122 char *ret = getcwd(buf, size); 123 if (ret == NULL) { 124 /* Check errno to avoid shadowing other possible errors. */ 125 if (errno == EOK) { 126 errno = ERANGE; 127 } 128 } else { 129 /* Success, restore previous errno value. */ 130 errno = orig_errno; 131 } 132 133 return ret; 113 114 return p; 134 115 } 135 116 … … 141 122 int posix_chdir(const char *path) 142 123 { 143 return errnify(chdir, path);124 return negerrno(chdir, path); 144 125 } 145 126 … … 194 175 int posix_close(int fildes) 195 176 { 196 return errnify(close, fildes);177 return negerrno(close, fildes); 197 178 } 198 179 … … 207 188 ssize_t posix_read(int fildes, void *buf, size_t nbyte) 208 189 { 209 return errnify(read, fildes, buf, nbyte);190 return negerrno(read, fildes, buf, nbyte); 210 191 } 211 192 … … 220 201 ssize_t posix_write(int fildes, const void *buf, size_t nbyte) 221 202 { 222 return errnify(write, fildes, buf, nbyte);203 return negerrno(write, fildes, buf, nbyte); 223 204 } 224 205 … … 234 215 posix_off_t posix_lseek(int fildes, posix_off_t offset, int whence) 235 216 { 236 return errnify(lseek, fildes, offset, whence);217 return negerrno(lseek, fildes, offset, whence); 237 218 } 238 219 … … 245 226 int posix_fsync(int fildes) 246 227 { 247 return errnify(fsync, fildes);228 return negerrno(fsync, fildes); 248 229 } 249 230 … … 257 238 int posix_ftruncate(int fildes, posix_off_t length) 258 239 { 259 return errnify(ftruncate, fildes, (aoff64_t) length);240 return negerrno(ftruncate, fildes, (aoff64_t) length); 260 241 } 261 242 … … 268 249 int posix_rmdir(const char *path) 269 250 { 270 return errnify(rmdir, path);251 return negerrno(rmdir, path); 271 252 } 272 253 … … 279 260 int posix_unlink(const char *path) 280 261 { 281 return errnify(unlink, path);262 return negerrno(unlink, path); 282 263 } 283 264 … … 303 284 int posix_dup2(int fildes, int fildes2) 304 285 { 305 return errnify(dup2, fildes, fildes2);286 return negerrno(dup2, fildes, fildes2); 306 287 } 307 288 … … 321 302 * Check file existence by attempting to open it. 322 303 */ 323 int fd = open(path, O_RDONLY);304 int fd = negerrno(open, path, O_RDONLY); 324 305 if (fd < 0) { 325 errno = -fd;306 /* errno was set by open() */ 326 307 return -1; 327 308 } -
uspace/srv/devman/driver.c
rf1f7584 r6afc9d7 142 142 /* Check whether the driver's binary exists. */ 143 143 struct stat s; 144 if (stat(drv->binary_path, &s) == ENOENT) { /* FIXME!! */144 if (stat(drv->binary_path, &s) != 0) { 145 145 log_msg(LOG_DEFAULT, LVL_ERROR, "Driver not found at path `%s'.", 146 146 drv->binary_path); -
uspace/srv/devman/match.c
rf1f7584 r6afc9d7 31 31 */ 32 32 33 #include <errno.h> 33 34 #include <fcntl.h> 34 35 #include <io/log.h> … … 197 198 if (fd < 0) { 198 199 log_msg(LOG_DEFAULT, LVL_ERROR, "Unable to open `%s' for reading: %s.", 199 conf_path, str_error( fd));200 conf_path, str_error(errno)); 200 201 goto cleanup; 201 202 } … … 217 218 } 218 219 219 ssize_t read_bytes = read _all(fd, buf, len);220 ssize_t read_bytes = read(fd, buf, len); 220 221 if (read_bytes <= 0) { 221 log_msg(LOG_DEFAULT, LVL_ERROR, "Unable to read file '%s' (% zd).", conf_path,222 read_bytes);222 log_msg(LOG_DEFAULT, LVL_ERROR, "Unable to read file '%s' (%d).", conf_path, 223 errno); 223 224 goto cleanup; 224 225 } -
uspace/srv/loader/main.c
rf1f7584 r6afc9d7 249 249 } 250 250 async_state_change_finalize(callid, vfs_exch); 251 fd = fd_wait();251 fd = vfs_fd_wait(); 252 252 assert(fd == (int) filc); 253 253 } -
uspace/srv/vfs/vfs.c
rf1f7584 r6afc9d7 74 74 break; 75 75 case VFS_IN_MOUNT: 76 vfs_mount (callid, &call);76 vfs_mount_srv(callid, &call); 77 77 break; 78 78 case VFS_IN_UNMOUNT: 79 vfs_unmount (callid, &call);79 vfs_unmount_srv(callid, &call); 80 80 break; 81 81 case VFS_IN_OPEN: -
uspace/srv/vfs/vfs.h
rf1f7584 r6afc9d7 205 205 206 206 extern void vfs_register(ipc_callid_t, ipc_call_t *); 207 extern void vfs_mount (ipc_callid_t, ipc_call_t *);208 extern void vfs_unmount (ipc_callid_t, ipc_call_t *);207 extern void vfs_mount_srv(ipc_callid_t, ipc_call_t *); 208 extern void vfs_unmount_srv(ipc_callid_t, ipc_call_t *); 209 209 extern void vfs_open(ipc_callid_t, ipc_call_t *); 210 210 extern void vfs_sync(ipc_callid_t, ipc_call_t *); -
uspace/srv/vfs/vfs_ops.c
rf1f7584 r6afc9d7 266 266 } 267 267 268 void vfs_mount (ipc_callid_t rid, ipc_call_t *request)268 void vfs_mount_srv(ipc_callid_t rid, ipc_call_t *request) 269 269 { 270 270 service_id_t service_id; … … 405 405 } 406 406 407 void vfs_unmount (ipc_callid_t rid, ipc_call_t *request)407 void vfs_unmount_srv(ipc_callid_t rid, ipc_call_t *request) 408 408 { 409 409 int rc;
Note:
See TracChangeset
for help on using the changeset viewer.