Changeset 368ee04 in mainline for uspace/app
- Timestamp:
- 2017-04-05T18:10:39Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 93ad8166
- Parents:
- 39f892a9 (diff), 2166728 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- uspace/app
- Files:
-
- 35 edited
-
bdsh/cmds/builtins/cd/cd.c (modified) (2 diffs)
-
bdsh/cmds/modules/cat/cat.c (modified) (7 diffs)
-
bdsh/cmds/modules/cmp/cmp.c (modified) (4 diffs)
-
bdsh/cmds/modules/cp/cp.c (modified) (10 diffs)
-
bdsh/cmds/modules/ls/ls.c (modified) (4 diffs)
-
bdsh/cmds/modules/ls/ls.h (modified) (1 diff)
-
bdsh/cmds/modules/mkdir/mkdir.c (modified) (5 diffs)
-
bdsh/cmds/modules/mkfile/mkfile.c (modified) (7 diffs)
-
bdsh/cmds/modules/mount/mount.c (modified) (4 diffs)
-
bdsh/cmds/modules/mv/mv.c (modified) (2 diffs)
-
bdsh/cmds/modules/pwd/pwd.c (modified) (2 diffs)
-
bdsh/cmds/modules/rm/rm.c (modified) (6 diffs)
-
bdsh/cmds/modules/touch/touch.c (modified) (3 diffs)
-
bdsh/cmds/modules/unmount/unmount.c (modified) (1 diff)
-
bdsh/compl.c (modified) (2 diffs)
-
bdsh/exec.c (modified) (4 diffs)
-
bdsh/util.c (modified) (2 diffs)
-
df/df.c (modified) (2 diffs)
-
fontviewer/fontviewer.c (modified) (1 diff)
-
getterm/getterm.c (modified) (5 diffs)
-
init/init.c (modified) (6 diffs)
-
kio/kio.c (modified) (2 diffs)
-
redir/redir.c (modified) (7 diffs)
-
sysinst/futil.c (modified) (6 diffs)
-
sysinst/sysinst.c (modified) (4 diffs)
-
taskdump/elf_core.c (modified) (15 diffs)
-
taskdump/symtab.c (modified) (8 diffs)
-
tester/hw/misc/virtchar1.c (modified) (4 diffs)
-
tester/mm/pager1.c (modified) (5 diffs)
-
tester/vfs/vfs1.c (modified) (4 diffs)
-
tetris/scores.c (modified) (1 diff)
-
trace/trace.c (modified) (3 diffs)
-
untar/main.c (modified) (2 diffs)
-
viewer/viewer.c (modified) (3 diffs)
-
websrv/websrv.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/builtins/cd/cd.c
r39f892a9 r368ee04 29 29 #include <stdio.h> 30 30 #include <stdlib.h> 31 #include <unistd.h>32 31 #include <str.h> 33 32 #include <errno.h> 33 #include <vfs/vfs.h> 34 34 35 35 #include "util.h" … … 51 51 static bool previous_directory_set = false; 52 52 53 static int chdir_and_remember(const char *new_dir) { 53 static int chdir_and_remember(const char *new_dir) 54 { 54 55 55 char *ok = getcwd(previous_directory_tmp, PATH_MAX);56 previous_directory_valid = ok != NULL;56 int rc = vfs_cwd_get(previous_directory_tmp, PATH_MAX); 57 previous_directory_valid = (rc == EOK); 57 58 previous_directory_set = true; 58 59 59 if (chdir(new_dir) != 0) 60 return errno; 60 rc = vfs_cwd_set(new_dir); 61 if (rc != EOK) 62 return rc; 61 63 62 64 str_cpy(previous_directory, PATH_MAX, previous_directory_tmp); -
uspace/app/bdsh/cmds/modules/cat/cat.c
r39f892a9 r368ee04 33 33 #include <getopt.h> 34 34 #include <str.h> 35 #include <fcntl.h>36 35 #include <io/console.h> 37 36 #include <io/color.h> … … 187 186 size_t offset = 0, copied_bytes = 0; 188 187 off64_t file_size = 0, length = 0; 188 aoff64_t pos = 0; 189 189 190 190 bool reading_stdin = dash_represents_stdin && (str_cmp(fname, "-") == 0); … … 195 195 blen = STR_BOUNDS(1); 196 196 } else 197 fd = open(fname, O_RDONLY);197 fd = vfs_lookup_open(fname, WALK_REGULAR, MODE_READ); 198 198 199 199 if (fd < 0) { … … 203 203 204 204 if (NULL == (buff = (char *) malloc(blen + 1))) { 205 close(fd);205 vfs_put(fd); 206 206 printf("Unable to allocate enough memory to read %s\n", 207 fname);207 fname); 208 208 return 1; 209 209 } 210 210 211 211 if (tail != CAT_FULL_FILE) { 212 file_size = lseek(fd, 0, SEEK_END); 212 struct stat st; 213 214 if (vfs_stat(fd, &st) != EOK) { 215 vfs_put(fd); 216 free(buff); 217 printf("Unable to vfs_stat %d\n", fd); 218 return 1; 219 } 220 file_size = st.size; 213 221 if (head == CAT_FULL_FILE) { 214 222 head = file_size; … … 223 231 224 232 if (tail_first) { 225 lseek(fd, (tail >= file_size) ? 0 : (file_size - tail), SEEK_SET);233 pos = (tail >= file_size) ? 0 : (file_size - tail); 226 234 } else { 227 lseek(fd, ((head - tail) >= file_size) ? 0 : (head - tail), SEEK_SET);235 pos = ((head - tail) >= file_size) ? 0 : (head - tail); 228 236 } 229 237 } else … … 243 251 } 244 252 245 bytes = read(fd, buff + copied_bytes, bytes_to_read);253 bytes = vfs_read(fd, &pos, buff + copied_bytes, bytes_to_read); 246 254 copied_bytes = 0; 247 255 … … 279 287 } while (bytes > 0 && !should_quit && (count < length || length == CAT_FULL_FILE)); 280 288 281 close(fd);289 vfs_put(fd); 282 290 if (bytes == -1) { 283 291 printf("Error reading %s\n", fname); -
uspace/app/bdsh/cmds/modules/cmp/cmp.c
r39f892a9 r368ee04 28 28 29 29 #include <errno.h> 30 #include <fcntl.h>31 30 #include <getopt.h> 32 31 #include <mem.h> … … 79 78 char buffer[2][CMP_BUFLEN]; 80 79 ssize_t offset[2]; 80 aoff64_t pos[2] = {}; 81 81 82 82 for (int i = 0; i < 2; i++) { 83 fd[i] = open(fn[i], O_RDONLY);83 fd[i] = vfs_lookup_open(fn[i], WALK_REGULAR, MODE_READ); 84 84 if (fd[i] < 0) { 85 rc = errno;85 rc = fd[i]; 86 86 printf("Unable to open %s\n", fn[i]); 87 87 goto end; … … 94 94 ssize_t size; 95 95 do { 96 size = read(fd[i], buffer[i] + offset[i], 96 size = vfs_read(fd[i], &pos[i], 97 buffer[i] + offset[i], 97 98 CMP_BUFLEN - offset[i]); 98 99 if (size < 0) { 99 rc = errno;100 rc = size; 100 101 printf("Error reading from %s\n", 101 102 fn[i]); … … 115 116 end: 116 117 if (fd[0] >= 0) 117 close(fd[0]);118 vfs_put(fd[0]); 118 119 if (fd[1] >= 0) 119 close(fd[1]);120 vfs_put(fd[1]); 120 121 return rc; 121 122 } -
uspace/app/bdsh/cmds/modules/cp/cp.c
r39f892a9 r368ee04 35 35 #include <getopt.h> 36 36 #include <str.h> 37 #include <fcntl.h> 38 #include <sys/stat.h> 37 #include <vfs/vfs.h> 39 38 #include <dirent.h> 40 39 #include "config.h" … … 83 82 struct stat s; 84 83 85 int r = stat(path, &s);86 87 if (r != 0)84 int r = vfs_stat_path(path, &s); 85 86 if (r != EOK) 88 87 return TYPE_NONE; 89 88 else if (s.is_directory) … … 235 234 */ 236 235 if (force && !interactive) { 237 if ( unlink(dest_path) != 0) {236 if (vfs_unlink_path(dest_path) != EOK) { 238 237 printf("Unable to remove %s\n", 239 238 dest_path); … … 246 245 if (overwrite) { 247 246 printf("Overwriting file: %s\n", dest_path); 248 if ( unlink(dest_path) != 0) {247 if (vfs_unlink_path(dest_path) != EOK) { 249 248 printf("Unable to remove %s\n", dest_path); 250 249 goto exit; … … 295 294 merge_paths(dest_path, PATH_MAX, src_dirname); 296 295 297 if (mkdir(dest_path, 0) != 0) { 296 if (vfs_link_path(dest_path, KIND_DIRECTORY, 297 NULL) != EOK) { 298 298 printf("Unable to create " 299 299 "dest directory %s\n", dest_path); … … 309 309 * e.g. cp -r /src /data/new_dir_src 310 310 */ 311 if (mkdir(dest_path, 0) != 0) { 311 if (vfs_link_path(dest_path, KIND_DIRECTORY, 312 NULL) != EOK) { 312 313 printf("Unable to create " 313 314 "dest directory %s\n", dest_path); … … 341 342 342 343 /* Check if we are copying a directory into itself */ 343 stat(src_dent, &src_s);344 stat(dest_path, &dest_s);344 vfs_stat_path(src_dent, &src_s); 345 vfs_stat_path(dest_path, &dest_s); 345 346 346 347 if (dest_s.index == src_s.index && … … 377 378 int64_t copied = 0; 378 379 char *buff = NULL; 380 aoff64_t posr = 0, posw = 0; 381 struct stat st; 379 382 380 383 if (vb) 381 384 printf("Copying %s to %s\n", src, dest); 382 385 383 if (-1 == (fd1 = open(src, O_RDONLY))) { 386 fd1 = vfs_lookup_open(src, WALK_REGULAR, MODE_READ); 387 if (fd1 < 0) { 384 388 printf("Unable to open source file %s\n", src); 385 389 return -1; 386 390 } 387 391 388 if (-1 == (fd2 = open(dest, O_CREAT))) { 392 fd2 = vfs_lookup_open(dest, WALK_REGULAR | WALK_MAY_CREATE, MODE_WRITE); 393 if (fd2 < 0) { 389 394 printf("Unable to open destination file %s\n", dest); 390 close(fd1);395 vfs_put(fd1); 391 396 return -1; 392 397 } 393 398 394 total = lseek(fd1, 0, SEEK_END); 395 399 if (vfs_stat(fd1, &st) != EOK) { 400 printf("Unable to fstat %d\n", fd1); 401 vfs_put(fd1); 402 vfs_put(fd2); 403 return -1; 404 } 405 406 total = st.size; 396 407 if (vb) 397 408 printf("%" PRIu64 " bytes to copy\n", total); 398 399 lseek(fd1, 0, SEEK_SET);400 409 401 410 if (NULL == (buff = (char *) malloc(blen))) { … … 406 415 } 407 416 408 while ((bytes = read(fd1, buff, blen)) > 0) {409 if ((bytes = write(fd2, buff, bytes)) < 0)417 while ((bytes = vfs_read(fd1, &posr, buff, blen)) > 0) { 418 if ((bytes = vfs_write(fd2, &posw, buff, bytes)) < 0) 410 419 break; 411 420 copied += bytes; … … 413 422 414 423 if (bytes < 0) { 415 printf("\nError copying %s, (%d)\n", src, errno);424 printf("\nError copying %s, (%d)\n", src, bytes); 416 425 copied = bytes; 417 426 } 418 427 419 428 out: 420 close(fd1);421 close(fd2);429 vfs_put(fd1); 430 vfs_put(fd2); 422 431 if (buff) 423 432 free(buff); -
uspace/app/bdsh/cmds/modules/ls/ls.c
r39f892a9 r368ee04 34 34 #include <stdio.h> 35 35 #include <stdlib.h> 36 #include <unistd.h>37 36 #include <dirent.h> 38 #include <fcntl.h>39 37 #include <getopt.h> 40 38 #include <sys/types.h> 41 #include < sys/stat.h>39 #include <vfs/vfs.h> 42 40 #include <str.h> 43 41 #include <sort.h> … … 185 183 buff[len] = '\0'; 186 184 187 rc = stat(buff, &tosort[nbdirs++].s);188 if (rc != 0) {185 rc = vfs_stat_path(buff, &tosort[nbdirs++].s); 186 if (rc != EOK) { 189 187 printf("ls: skipping bogus node %s\n", buff); 190 printf("error=%d\n", errno);188 printf("error=%d\n", rc); 191 189 goto out; 192 190 } … … 315 313 static unsigned int ls_scope(const char *path, struct dir_elem_t *de) 316 314 { 317 if ( stat(path, &de->s) != 0) {315 if (vfs_stat_path(path, &de->s) != EOK) { 318 316 cli_error(CL_ENOENT, "%s", path); 319 317 return LS_BOGUS; … … 388 386 389 387 if (argc == 0) { 390 if ( getcwd(de.name, PATH_MAX) == NULL) {388 if (vfs_cwd_get(de.name, PATH_MAX) != EOK) { 391 389 cli_error(CL_EFAIL, "%s: Failed determining working " 392 390 "directory", cmdname); -
uspace/app/bdsh/cmds/modules/ls/ls.h
r39f892a9 r368ee04 1 1 #ifndef LS_H 2 2 #define LS_H 3 4 #include <vfs/vfs.h> 3 5 4 6 /* Various values that can be returned by ls_scope() */ -
uspace/app/bdsh/cmds/modules/mkdir/mkdir.c
r39f892a9 r368ee04 30 30 #include <stdlib.h> 31 31 #include <dirent.h> 32 #include <fcntl.h>33 32 #include <sys/types.h> 34 #include <sys/stat.h>35 33 #include <getopt.h> 36 34 #include <stdarg.h> … … 98 96 99 97 if (!create_parents) { 100 if (mkdir(path, 0) != 0) { 98 ret = vfs_link_path(path, KIND_DIRECTORY, NULL); 99 if (ret != EOK) { 101 100 cli_error(CL_EFAIL, "%s: could not create %s (%s)", 102 cmdname, path, str_error( errno));101 cmdname, path, str_error(ret)); 103 102 ret = 1; 104 103 } … … 136 135 path[prev_off] = 0; 137 136 138 if (mkdir(path, 0) != 0 && errno != EEXIST) { 137 ret = vfs_link_path(path, KIND_DIRECTORY, NULL); 138 if (ret != EOK && ret != EEXIST) { 139 139 cli_error(CL_EFAIL, "%s: could not create %s (%s)", 140 cmdname, path, str_error( errno));140 cmdname, path, str_error(ret)); 141 141 ret = 1; 142 142 goto leave; … … 146 146 } 147 147 /* Create the final directory. */ 148 if (mkdir(path, 0) != 0) { 148 ret = vfs_link_path(path, KIND_DIRECTORY, NULL); 149 if (ret != EOK) { 149 150 cli_error(CL_EFAIL, "%s: could not create %s (%s)", 150 cmdname, path, str_error( errno));151 cmdname, path, str_error(ret)); 151 152 ret = 1; 152 153 } … … 207 208 208 209 if (follow && (argv[optind] != NULL)) { 209 if ( chdir(argv[optind]) != 0)210 if (vfs_cwd_set(argv[optind]) != EOK) 210 211 printf("%s: Error switching to directory.", cmdname); 211 212 } -
uspace/app/bdsh/cmds/modules/mkfile/mkfile.c
r39f892a9 r368ee04 31 31 #include <stdlib.h> 32 32 #include <dirent.h> 33 #include <fcntl.h>34 33 #include <sys/types.h> 35 #include <sys/stat.h>36 34 #include <macros.h> 37 35 #include <getopt.h> … … 39 37 #include <str.h> 40 38 #include <ctype.h> 39 #include <vfs/vfs.h> 41 40 42 41 #include "config.h" … … 121 120 void *buffer; 122 121 bool create_sparse = false; 122 aoff64_t pos = 0; 123 123 124 124 file_size = 0; … … 156 156 file_name = argv[optind]; 157 157 158 fd = open(file_name, O_CREAT | O_EXCL | O_WRONLY, 0666);158 fd = vfs_lookup_open(file_name, WALK_REGULAR | WALK_MUST_CREATE, MODE_WRITE); 159 159 if (fd < 0) { 160 160 printf("%s: failed to create file %s.\n", cmdname, file_name); … … 164 164 if (create_sparse && file_size > 0) { 165 165 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)); 166 167 pos = file_size - 1; 168 rc2 = vfs_write(fd, &pos, &byte, sizeof(char)); 173 169 if (rc2 < 0) { 174 close(fd);170 vfs_put(fd); 175 171 goto error; 176 172 } … … 187 183 while (total_written < file_size) { 188 184 to_write = min(file_size - total_written, BUFFER_SIZE); 189 rc = write(fd, buffer, to_write);185 rc = vfs_write(fd, &pos, buffer, to_write); 190 186 if (rc <= 0) { 191 187 printf("%s: Error writing file (%d).\n", cmdname, errno); 192 close(fd);188 vfs_put(fd); 193 189 free(buffer); 194 190 return CMD_FAILURE; … … 199 195 free(buffer); 200 196 201 if ( close(fd) < 0)197 if (vfs_put(fd) < 0) 202 198 goto error; 203 199 -
uspace/app/bdsh/cmds/modules/mount/mount.c
r39f892a9 r368ee04 32 32 #include <str_error.h> 33 33 #include <vfs/vfs.h> 34 #include <vfs/vfs_mtab.h> 34 35 #include <adt/list.h> 35 36 #include <errno.h> … … 82 83 83 84 printf("%s", mtab_ent->fs_name); 84 if (mtab_ent->instance)85 printf("/%d", mtab_ent->instance);86 85 87 86 printf(" %s", mtab_ent->mp); … … 94 93 printf(" (%" PRIun ")", mtab_ent->service_id); 95 94 } 96 97 if (str_size(mtab_ent->opts) > 0)98 printf(" (%s)", mtab_ent->opts);99 95 100 96 putchar('\n'); … … 151 147 mopts = t_argv[4]; 152 148 153 rc = vfs_mount (t_argv[1], t_argv[2], dev, mopts, 0, instance);149 rc = vfs_mount_path(t_argv[2], t_argv[1], dev, mopts, 0, instance); 154 150 if (rc != EOK) { 155 151 printf("Unable to mount %s filesystem to %s on %s (rc=%s)\n", 156 t_argv[ 1], t_argv[2], t_argv[3], str_error(rc));152 t_argv[2], t_argv[1], t_argv[3], str_error(rc)); 157 153 return CMD_FAILURE; 158 154 } -
uspace/app/bdsh/cmds/modules/mv/mv.c
r39f892a9 r368ee04 30 30 #include <stdlib.h> 31 31 #include <errno.h> 32 #include <vfs/vfs.h> 32 33 #include "config.h" 33 34 #include "util.h" … … 59 60 } 60 61 61 rc = rename(argv[1], argv[2]);62 if (rc != 0) {62 rc = vfs_rename_path(argv[1], argv[2]); 63 if (rc != EOK) { 63 64 printf("Unable to rename %s to %s (error=%d)\n", 64 argv[1], argv[2], errno);65 argv[1], argv[2], rc); 65 66 return CMD_FAILURE; 66 67 } -
uspace/app/bdsh/cmds/modules/pwd/pwd.c
r39f892a9 r368ee04 30 30 #include <stdlib.h> 31 31 #include <mem.h> 32 #include <vfs/vfs.h> 33 #include <abi/errno.h> 32 34 33 35 #include "config.h" … … 57 59 memset(buff, 0, PATH_MAX); 58 60 59 if ( getcwd(buff, PATH_MAX) == NULL) {61 if (vfs_cwd_get(buff, PATH_MAX) != EOK) { 60 62 cli_error(CL_EFAIL, 61 63 "Unable to determine the current working directory"); -
uspace/app/bdsh/cmds/modules/rm/rm.c
r39f892a9 r368ee04 30 30 #include <stdio.h> 31 31 #include <stdlib.h> 32 #include <unistd.h>33 #include <fcntl.h>34 32 #include <dirent.h> 35 33 #include <getopt.h> 36 34 #include <mem.h> 37 35 #include <str.h> 36 #include <vfs/vfs.h> 38 37 39 38 #include "config.h" … … 110 109 memset(rm->cwd, 0, PATH_MAX); 111 110 112 chdir(".");113 114 if ( NULL == (getcwd(rm->owd, PATH_MAX)))111 vfs_cwd_set("."); 112 113 if (EOK != vfs_cwd_get(rm->owd, PATH_MAX)) 115 114 return 0; 116 115 … … 132 131 static unsigned int rm_single(const char *path) 133 132 { 134 if ( unlink(path) != 0) {133 if (vfs_unlink_path(path) != EOK) { 135 134 cli_error(CL_EFAIL, "rm: could not remove file %s", path); 136 135 return 1; … … 150 149 } 151 150 152 fd = open(path, O_RDONLY);151 fd = vfs_lookup(path, WALK_REGULAR); 153 152 if (fd >= 0) { 154 close(fd);153 vfs_put(fd); 155 154 return RM_FILE; 156 155 } … … 201 200 202 201 /* First see if it will just go away */ 203 rc = rmdir(path);204 if (rc == 0)202 rc = vfs_unlink_path(path); 203 if (rc == EOK) 205 204 return 0; 206 205 … … 209 208 210 209 /* Delete directory */ 211 rc = rmdir(path);212 if (rc == 0)213 return errno;210 rc = vfs_unlink_path(path); 211 if (rc == EOK) 212 return EOK; 214 213 215 214 cli_error(CL_ENOTSUP, "Can not remove %s", path); -
uspace/app/bdsh/cmds/modules/touch/touch.c
r39f892a9 r368ee04 35 35 #include <stdlib.h> 36 36 #include <unistd.h> 37 #include <fcntl.h>38 37 #include <dirent.h> 39 38 #include <sys/types.h> 40 39 #include <str.h> 41 40 #include <getopt.h> 42 #include <sys/stat.h>43 41 #include <errno.h> 42 #include <vfs/vfs.h> 44 43 45 44 #include "config.h" … … 123 122 124 123 /* Check whether file exists if -c (--no-create) option is given */ 125 if ((!no_create) || ((no_create) && (stat(buff, &file_stat) == 0))) 126 fd = open(buff, O_RDWR | O_CREAT); 124 if ((!no_create) || 125 ((no_create) && (vfs_stat_path(buff, &file_stat) == EOK))) { 126 fd = vfs_lookup(buff, WALK_REGULAR | WALK_MAY_CREATE); 127 } 127 128 128 129 if (fd < 0) { … … 132 133 continue; 133 134 } else { 134 close(fd);135 vfs_put(fd); 135 136 fd = -1; 136 137 } -
uspace/app/bdsh/cmds/modules/unmount/unmount.c
r39f892a9 r368ee04 66 66 } 67 67 68 rc = vfs_unmount (argv[1]);68 rc = vfs_unmount_path(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
r39f892a9 r368ee04 33 33 #include <macros.h> 34 34 #include <stdlib.h> 35 #include < sys/stat.h>35 #include <vfs/vfs.h> 36 36 37 37 #include "cmds/cmds.h" … … 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) != 0) {362 if (vfs_stat_path(ent_path, &ent_stat) != EOK) { 363 363 /* Error */ 364 364 free(ent_path); -
uspace/app/bdsh/exec.c
r39f892a9 r368ee04 37 37 #include <unistd.h> 38 38 #include <str.h> 39 #include <fcntl.h>40 39 #include <str_error.h> 41 40 #include <errno.h> … … 60 59 int fd; 61 60 62 fd = open(f, O_RDONLY);61 fd = vfs_lookup_open(f, WALK_REGULAR, MODE_READ); 63 62 if (fd >= 0) { 64 close(fd);63 vfs_put(fd); 65 64 return 0; 66 65 } else … … 101 100 char *tmp; 102 101 int rc, retval, i; 103 int file_handles[3]; 104 int *file_handles_p[4]; 102 int file_handles[3] = { -1, -1, -1 }; 105 103 FILE *files[3]; 106 104 … … 113 111 114 112 for (i = 0; i < 3 && files[i] != NULL; i++) { 115 if (vfs_fhandle(files[i], &file_handles[i]) == EOK) { 116 file_handles_p[i] = &file_handles[i]; 117 } 118 else { 119 file_handles_p[i] = NULL; 120 } 113 vfs_fhandle(files[i], &file_handles[i]); 121 114 } 122 file_handles_p[i] = NULL;123 115 124 rc = task_spawnvf(&tid, &twait, tmp, (const char **) argv, file_handles_p); 116 rc = task_spawnvf(&tid, &twait, tmp, (const char **) argv, 117 file_handles[0], file_handles[1], file_handles[2]); 125 118 free(tmp); 126 119 -
uspace/app/bdsh/util.c
r39f892a9 r368ee04 31 31 #include <stdarg.h> 32 32 #include <stdlib.h> 33 #include <vfs/vfs.h> 34 #include <abi/errno.h> 33 35 34 36 #include "config.h" … … 58 60 return 1; 59 61 } 60 if ( !getcwd(usr->cwd, PATH_MAX))62 if (vfs_cwd_get(usr->cwd, PATH_MAX) != EOK) 61 63 snprintf(usr->cwd, PATH_MAX, "(unknown)"); 62 64 -
uspace/app/df/df.c
r39f892a9 r368ee04 40 40 #include <stdint.h> 41 41 #include <getopt.h> 42 #include <sys/statfs.h>43 42 #include <errno.h> 44 43 #include <adt/list.h> 45 44 #include <vfs/vfs.h> 45 #include <vfs/vfs_mtab.h> 46 46 47 47 #define NAME "df" … … 123 123 print_header(); 124 124 list_foreach(mtab_list, link, mtab_ent_t, mtab_ent) { 125 if ( statfs(mtab_ent->mp, &st) == 0) {125 if (vfs_statfs_path(mtab_ent->mp, &st) == 0) { 126 126 print_statfs(&st, mtab_ent->fs_name, mtab_ent->mp); 127 127 } else { -
uspace/app/fontviewer/fontviewer.c
r39f892a9 r368ee04 34 34 35 35 #include <stdio.h> 36 #include <unistd.h> 37 #include <fcntl.h> 38 #include <sys/stat.h> 36 #include <stdlib.h> 39 37 #include <errno.h> 40 38 #include <malloc.h> -
uspace/app/getterm/getterm.c
r39f892a9 r368ee04 36 36 37 37 #include <sys/types.h> 38 #include <fcntl.h>39 38 #include <unistd.h> 40 39 #include <stdio.h> … … 43 42 #include <errno.h> 44 43 #include <loc.h> 44 #include <vfs/vfs.h> 45 45 #include "version.h" 46 46 #include "welcome.h" … … 58 58 } 59 59 60 static void reopen(FILE **stream, int fd, const char *path, int flags,61 const char * mode)60 static void reopen(FILE **stream, int fd, const char *path, int mode, 61 const char *fmode) 62 62 { 63 63 if (fclose(*stream)) … … 66 66 *stream = NULL; 67 67 68 int oldfd = open(path, flags);68 int oldfd = vfs_lookup_open(path, WALK_REGULAR, mode); 69 69 if (oldfd < 0) 70 70 return; 71 71 72 72 if (oldfd != fd) { 73 if ( dup2(oldfd, fd) != fd)73 if (vfs_clone(oldfd, fd, false) != fd) 74 74 return; 75 75 76 if ( close(oldfd))76 if (vfs_put(oldfd)) 77 77 return; 78 78 } 79 79 80 *stream = fdopen(fd, mode);80 *stream = fdopen(fd, fmode); 81 81 } 82 82 … … 141 141 snprintf(term_node, LOC_NAME_MAXLEN, "%s/%s", locfs, term); 142 142 143 reopen(&stdin, 0, term_node, O_RDONLY, "r");144 reopen(&stdout, 1, term_node, O_WRONLY, "w");145 reopen(&stderr, 2, term_node, O_WRONLY, "w");143 reopen(&stdin, 0, term_node, MODE_READ, "r"); 144 reopen(&stdout, 1, term_node, MODE_WRITE, "w"); 145 reopen(&stderr, 2, term_node, MODE_WRITE, "w"); 146 146 147 147 if (stdin == NULL) -
uspace/app/init/init.c
r39f892a9 r368ee04 41 41 #include <stdbool.h> 42 42 #include <errno.h> 43 #include <fcntl.h>44 #include <sys/stat.h>45 43 #include <task.h> 46 44 #include <malloc.h> … … 50 48 #include <str_error.h> 51 49 #include <config.h> 50 #include <io/logctl.h> 52 51 #include "init.h" 53 52 … … 127 126 opts = "restore"; 128 127 129 int rc = vfs_mount (fstype, ROOT_MOUNT_POINT, ROOT_DEVICE, opts,128 int rc = vfs_mount_path(ROOT_MOUNT_POINT, fstype, ROOT_DEVICE, opts, 130 129 IPC_FLAG_BLOCKING, 0); 130 if (rc == EOK) 131 logctl_set_root(); 131 132 return mount_report("Root filesystem", ROOT_MOUNT_POINT, fstype, 132 133 ROOT_DEVICE, rc); … … 144 145 static bool mount_locfs(void) 145 146 { 146 int rc = vfs_mount (LOCFS_FS_TYPE, LOCFS_MOUNT_POINT, "", "",147 int rc = vfs_mount_path(LOCFS_MOUNT_POINT, LOCFS_FS_TYPE, "", "", 147 148 IPC_FLAG_BLOCKING, 0); 148 149 return mount_report("Location service filesystem", LOCFS_MOUNT_POINT, … … 153 154 { 154 155 struct stat s; 155 if ( stat(path, &s) != 0) {156 if (vfs_stat_path(path, &s) != EOK) { 156 157 printf("%s: Unable to stat %s\n", NAME, path); 157 158 return ENOENT; … … 300 301 static bool mount_tmpfs(void) 301 302 { 302 int rc = vfs_mount (TMPFS_FS_TYPE, TMPFS_MOUNT_POINT, "", "", 0, 0);303 int rc = vfs_mount_path(TMPFS_MOUNT_POINT, TMPFS_FS_TYPE, "", "", 0, 0); 303 304 return mount_report("Temporary filesystem", TMPFS_MOUNT_POINT, 304 305 TMPFS_FS_TYPE, NULL, rc); -
uspace/app/kio/kio.c
r39f892a9 r368ee04 48 48 #include <adt/prodcons.h> 49 49 #include <tinput.h> 50 #include <vfs/vfs.h> 50 51 51 52 #define NAME "kio" … … 128 129 129 130 fflush(log); 130 fsync(fileno(log));131 vfs_sync(fileno(log)); 131 132 } 132 133 -
uspace/app/redir/redir.c
r39f892a9 r368ee04 37 37 #include <sys/types.h> 38 38 #include <stdlib.h> 39 #include <fcntl.h>40 39 #include <unistd.h> 41 40 #include <str.h> … … 44 43 #include <str_error.h> 45 44 #include <errno.h> 45 #include <vfs/vfs.h> 46 46 47 47 #define NAME "redir" … … 53 53 } 54 54 55 static void reopen(FILE **stream, int fd, const char *path, int flags, const char *mode) 55 static void reopen(FILE **stream, int fd, const char *path, int flags, int mode, 56 const char *fmode) 56 57 { 57 58 if (fclose(*stream)) … … 60 61 *stream = NULL; 61 62 62 int oldfd = open(path, flags);63 int oldfd = vfs_lookup_open(path, WALK_REGULAR | flags, mode); 63 64 if (oldfd < 0) 64 65 return; 65 66 66 67 if (oldfd != fd) { 67 if ( dup2(oldfd, fd) != fd)68 if (vfs_clone(oldfd, fd, false) != fd) 68 69 return; 69 70 70 if ( close(oldfd))71 if (vfs_put(oldfd)) 71 72 return; 72 73 } 73 74 74 *stream = fdopen(fd, mode);75 *stream = fdopen(fd, fmode); 75 76 } 76 77 … … 121 122 return -2; 122 123 } 123 reopen(&stdin, 0, argv[i], O_RDONLY, "r");124 reopen(&stdin, 0, argv[i], 0, MODE_READ, "r"); 124 125 } else if (str_cmp(argv[i], "-o") == 0) { 125 126 i++; … … 128 129 return -3; 129 130 } 130 reopen(&stdout, 1, argv[i], O_WRONLY | O_CREAT, "w"); 131 reopen(&stdout, 1, argv[i], WALK_MAY_CREATE, MODE_WRITE, 132 "w"); 131 133 } else if (str_cmp(argv[i], "-e") == 0) { 132 134 i++; … … 135 137 return -4; 136 138 } 137 reopen(&stderr, 2, argv[i], O_WRONLY | O_CREAT, "w"); 139 reopen(&stderr, 2, argv[i], WALK_MAY_CREATE, MODE_WRITE, 140 "w"); 138 141 } else if (str_cmp(argv[i], "--") == 0) { 139 142 i++; -
uspace/app/sysinst/futil.c
r39f892a9 r368ee04 35 35 #include <dirent.h> 36 36 #include <errno.h> 37 #include <fcntl.h>38 37 #include <stdbool.h> 39 38 #include <stdio.h> 40 39 #include <stdlib.h> 41 #include < sys/stat.h>40 #include <vfs/vfs.h> 42 41 #include <sys/types.h> 43 42 #include <dirent.h> … … 60 59 ssize_t nr, nw; 61 60 int rc; 61 aoff64_t posr = 0, posw = 0; 62 62 63 63 printf("Copy '%s' to '%s'.\n", srcp, destp); 64 64 65 sf = open(srcp, O_RDONLY);65 sf = vfs_lookup_open(srcp, WALK_REGULAR, MODE_READ); 66 66 if (sf < 0) 67 67 return EIO; 68 68 69 df = open(destp, O_CREAT | O_WRONLY, 0);69 df = vfs_lookup_open(destp, WALK_REGULAR | WALK_MAY_CREATE, MODE_WRITE); 70 70 if (df < 0) 71 71 return EIO; 72 72 73 73 do { 74 nr = read(sf, buf, BUF_SIZE);74 nr = vfs_read(sf, &posr, buf, BUF_SIZE); 75 75 if (nr == 0) 76 76 break; … … 78 78 return EIO; 79 79 80 nw = write(df, buf, nr);80 nw = vfs_write(df, &posw, buf, nr); 81 81 if (nw <= 0) 82 82 return EIO; 83 83 } while (true); 84 84 85 (void) close(sf);85 (void) vfs_put(sf); 86 86 87 rc = close(df);87 rc = vfs_put(df); 88 88 if (rc < 0) 89 89 return EIO; … … 118 118 return ENOMEM; 119 119 120 rc = stat(srcp, &s);120 rc = vfs_stat_path(srcp, &s); 121 121 if (rc != EOK) 122 122 return EIO; … … 128 128 } else if (s.is_directory) { 129 129 printf("Create directory '%s'\n", destp); 130 rc = mkdir(destp, 0);130 rc = vfs_link_path(destp, KIND_DIRECTORY, NULL); 131 131 if (rc != EOK) 132 132 return EIO; … … 157 157 int sf; 158 158 ssize_t nr; 159 off64_t off;160 159 size_t fsize; 161 160 char *data; 161 struct stat st; 162 162 163 sf = open(srcp, O_RDONLY);163 sf = vfs_lookup_open(srcp, WALK_REGULAR, MODE_READ); 164 164 if (sf < 0) 165 165 return ENOENT; 166 166 167 off = lseek(sf, 0, SEEK_END);168 if (off == (off64_t)-1)167 if (vfs_stat(sf, &st) != EOK) { 168 vfs_put(sf); 169 169 return EIO; 170 } 170 171 171 fsize = (size_t)off; 172 173 off = lseek(sf, 0, SEEK_SET); 174 if (off == (off64_t)-1) 175 return EIO; 172 fsize = st.size; 176 173 177 174 data = calloc(fsize, 1); 178 if (data == NULL) 175 if (data == NULL) { 176 vfs_put(sf); 179 177 return ENOMEM; 178 } 180 179 181 nr = read(sf, data, fsize); 182 if (nr != (ssize_t)fsize) 180 nr = vfs_read(sf, (aoff64_t []) { 0 }, data, fsize); 181 if (nr != (ssize_t)fsize) { 182 vfs_put(sf); 183 free(data); 183 184 return EIO; 185 } 184 186 185 (void) close(sf);187 (void) vfs_put(sf); 186 188 *rdata = data; 187 189 *rsize = fsize; -
uspace/app/sysinst/sysinst.c
r39f892a9 r368ee04 43 43 #include <stdio.h> 44 44 #include <stdlib.h> 45 #include <sys/stat.h>46 45 #include <task.h> 47 46 #include <vfs/vfs.h> … … 175 174 return EIO; 176 175 177 rc = mkdir(MOUNT_POINT, 0);176 rc = vfs_link_path(MOUNT_POINT, KIND_DIRECTORY, NULL); 178 177 if (rc != EOK) 179 178 return rc; 180 179 181 180 printf("sysinst_fs_mount(): mount filesystem\n"); 182 rc = vfs_mount (FS_TYPE, MOUNT_POINT, dev, "", 0, 0);181 rc = vfs_mount_path(MOUNT_POINT, FS_TYPE, dev, "", 0, 0); 183 182 if (rc != EOK) 184 183 return rc; … … 214 213 215 214 printf("sysinst_copy_boot_files(): create CD mount point\n"); 216 rc = mkdir(CD_MOUNT_POINT, 0);215 rc = vfs_link_path(CD_MOUNT_POINT, KIND_DIRECTORY, NULL); 217 216 if (rc != EOK) 218 217 return rc; 219 218 220 219 printf("sysinst_copy_boot_files(): mount CD filesystem\n"); 221 rc = vfs_mount (CD_FS_TYPE, CD_MOUNT_POINT, CD_DEV, "", 0, 0);220 rc = vfs_mount_path(CD_MOUNT_POINT, CD_FS_TYPE, CD_DEV, "", 0, 0); 222 221 if (rc != EOK) 223 222 return rc; … … 229 228 230 229 printf("sysinst_copy_boot_files(): unmount %s\n", MOUNT_POINT); 231 rc = vfs_unmount (MOUNT_POINT);230 rc = vfs_unmount_path(MOUNT_POINT); 232 231 if (rc != EOK) 233 232 return rc; -
uspace/app/taskdump/elf_core.c
r39f892a9 r368ee04 54 54 #include <errno.h> 55 55 #include <sys/types.h> 56 #include <sys/stat.h>57 56 #include <unistd.h> 58 #include <fcntl.h>59 57 #include <mem.h> 60 58 #include <stdint.h> … … 63 61 #include <macros.h> 64 62 #include <libarch/istate.h> 63 #include <vfs/vfs.h> 65 64 66 65 #include "elf_core.h" 67 66 68 67 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 *); 68 static int write_mem_area(int, aoff64_t *, as_area_info_t *, async_sess_t *); 71 69 72 70 #define BUFFER_SIZE 0x1000 … … 97 95 elf_note_t note; 98 96 size_t word_size; 97 aoff64_t pos = 0; 99 98 100 99 int fd; … … 124 123 } 125 124 126 fd = open(file_name, O_CREAT | O_WRONLY, 0644); 125 fd = vfs_lookup_open(file_name, WALK_REGULAR | WALK_MAY_CREATE, 126 MODE_WRITE); 127 127 if (fd < 0) { 128 128 printf("Failed opening file.\n"); … … 207 207 } 208 208 209 rc = write(fd, &elf_hdr, sizeof(elf_hdr));209 rc = vfs_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 = vfs_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, ¬e, sizeof(elf_note_t));234 rc = vfs_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 = vfs_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 = vfs_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 = vfs_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
r39f892a9 r368ee04 41 41 #include <errno.h> 42 42 #include <sys/types.h> 43 #include <sys/stat.h> 44 #include <fcntl.h> 43 #include <vfs/vfs.h> 45 44 46 45 #include "include/symtab.h" … … 68 67 char *shstrt, *sec_name; 69 68 void *data; 69 aoff64_t pos = 0; 70 70 71 71 int fd; … … 81 81 return ENOMEM; 82 82 83 fd = open(file_name, O_RDONLY);83 fd = vfs_lookup_open(file_name, WALK_REGULAR, MODE_READ); 84 84 if (fd < 0) { 85 85 printf("failed opening file\n"); … … 88 88 } 89 89 90 rc = read(fd, &elf_hdr, sizeof(elf_header_t));90 rc = vfs_read(fd, &pos, &elf_hdr, sizeof(elf_header_t)); 91 91 if (rc != sizeof(elf_header_t)) { 92 92 printf("failed reading elf header\n"); … … 165 165 166 166 free(shstrt); 167 close(fd);167 vfs_put(fd); 168 168 169 169 if (stab->sym == NULL || stab->strtab == NULL) { … … 304 304 { 305 305 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)); 306 aoff64_t pos = elf_hdr->e_shoff + idx * sizeof(elf_section_header_t); 307 308 rc = vfs_read(fd, &pos, sec_hdr, sizeof(elf_section_header_t)); 313 309 if (rc != sizeof(elf_section_header_t)) 314 310 return EIO; … … 331 327 { 332 328 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 } 329 aoff64_t pos = start; 341 330 342 331 *ptr = malloc(size); … … 346 335 } 347 336 348 rc = read(fd, *ptr, size);337 rc = vfs_read(fd, &pos, *ptr, size); 349 338 if (rc != (ssize_t) size) { 350 339 printf("failed reading chunk\n"); -
uspace/app/tester/hw/misc/virtchar1.c
r39f892a9 r368ee04 45 45 #include <vfs/vfs.h> 46 46 #include <vfs/vfs_sess.h> 47 #include <sys/stat.h>48 #include <fcntl.h>49 47 #include "../../tester.h" 50 48 … … 56 54 { 57 55 TPRINTF("Opening `%s'...\n", path); 58 int fd = open(path, O_RDONLY);56 int fd = vfs_lookup(path, WALK_REGULAR); 59 57 if (fd < 0) { 60 58 TPRINTF(" ...error: %s\n", str_error(errno)); … … 71 69 async_sess_t *sess = vfs_fd_session(fd, INTERFACE_DDF); 72 70 if (!sess) { 73 close(fd);71 vfs_put(fd); 74 72 TPRINTF(" ...error: %s\n", str_error(errno)); 75 73 return "Failed to get session to device"; … … 92 90 TPRINTF(" Closing session and file descriptor\n"); 93 91 async_hangup(sess); 94 close(fd);92 vfs_put(fd); 95 93 96 94 return NULL; -
uspace/app/tester/mm/pager1.c
r39f892a9 r368ee04 28 28 29 29 #include <stdio.h> 30 #include <unistd.h> 31 #include <fcntl.h> 30 #include <vfs/vfs.h> 32 31 #include <stdlib.h> 33 32 #include <malloc.h> … … 48 47 TPRINTF("Creating temporary file...\n"); 49 48 50 fd = open(TEST_FILE, O_CREAT); 49 fd = vfs_lookup_open(TEST_FILE, WALK_REGULAR | WALK_MAY_CREATE, 50 MODE_READ | MODE_WRITE); 51 51 if (fd < 0) 52 52 return NULL; 53 (void) unlink(TEST_FILE); 54 if (write(fd, text, sizeof(text)) != sizeof(text)) { 55 close(fd); 53 (void) vfs_unlink_path(TEST_FILE); 54 55 if (vfs_write(fd, (aoff64_t []) {0}, text, sizeof(text)) < 0) { 56 vfs_put(fd); 56 57 return NULL; 57 58 } … … 64 65 65 66 if (!vfs_pager_sess) { 66 close(fd);67 vfs_put(fd); 67 68 return NULL; 68 69 } … … 73 74 AS_AREA_READ | AS_AREA_CACHEABLE, vfs_pager_sess, fd, 0, 0); 74 75 if (result == AS_MAP_FAILED) { 75 close(fd);76 vfs_put(fd); 76 77 return NULL; 77 78 } … … 101 102 102 103 as_area_destroy(buffer); 103 close(fd);104 vfs_put(fd); 104 105 105 106 return NULL; -
uspace/app/tester/vfs/vfs1.c
r39f892a9 r368ee04 33 33 #include <vfs/vfs.h> 34 34 #include <unistd.h> 35 #include <fcntl.h>36 35 #include <dirent.h> 37 36 #include <loc.h> 38 37 #include <sys/types.h> 39 #include <sys/stat.h>40 38 #include "../tester.h" 41 39 … … 70 68 const char *test_vfs1(void) 71 69 { 72 if (mkdir(TEST_DIRECTORY, 0) != 0) { 73 TPRINTF("rc=%d\n", errno); 74 return "mkdir() failed"; 70 aoff64_t pos = 0; 71 int rc; 72 73 rc = vfs_link_path(TEST_DIRECTORY, KIND_DIRECTORY, NULL); 74 if (rc != EOK) { 75 TPRINTF("rc=%d\n", rc); 76 return "vfs_link_path() failed"; 75 77 } 76 78 TPRINTF("Created directory %s\n", TEST_DIRECTORY); 77 79 78 int fd0 = open(TEST_FILE, O_CREAT); 80 int fd0 = vfs_lookup_open(TEST_FILE, WALK_REGULAR | WALK_MAY_CREATE, 81 MODE_READ | MODE_WRITE); 79 82 if (fd0 < 0) 80 return " open() failed";83 return "vfs_lookup_open() failed"; 81 84 TPRINTF("Created file %s (fd=%d)\n", TEST_FILE, fd0); 82 85 83 86 size_t size = sizeof(text); 84 ssize_t cnt = write(fd0, text, size);87 ssize_t cnt = vfs_write(fd0, &pos, text, size); 85 88 if (cnt < 0) 86 89 return "write() failed"; 87 90 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"); 91 92 pos = 0; 92 93 93 94 char buf[BUF_SIZE]; 94 95 TPRINTF("read..\n"); 95 while ((cnt = read(fd0, buf, BUF_SIZE))) {96 while ((cnt = vfs_read(fd0, &pos, buf, BUF_SIZE))) { 96 97 TPRINTF("read returns %zd\n", cnt); 97 98 if (cnt < 0) … … 107 108 } 108 109 109 close(fd0);110 vfs_put(fd0); 110 111 111 112 const char *rv = read_root(); … … 113 114 return rv; 114 115 115 if ( rename(TEST_FILE, TEST_FILE2) != 0)116 return " rename() failed";116 if (vfs_rename_path(TEST_FILE, TEST_FILE2) != EOK) 117 return "vfs_rename_path() failed"; 117 118 TPRINTF("Renamed %s to %s\n", TEST_FILE, TEST_FILE2); 118 119 119 if ( unlink(TEST_FILE2) != 0)120 return " unlink() failed";120 if (vfs_unlink_path(TEST_FILE2) != EOK) 121 return "vfs_unlink_path() failed"; 121 122 TPRINTF("Unlinked %s\n", TEST_FILE2); 122 123 123 if ( rmdir(TEST_DIRECTORY) != 0)124 return " rmdir() failed";124 if (vfs_unlink_path(TEST_DIRECTORY) != EOK) 125 return "vfs_unlink_path() failed"; 125 126 TPRINTF("Removed directory %s\n", TEST_DIRECTORY); 126 127 -
uspace/app/tetris/scores.c
r39f892a9 r368ee04 65 65 #include <vfs/vfs.h> 66 66 #include <stdlib.h> 67 #include <fcntl.h>68 67 #include <err.h> 69 68 #include <time.h> -
uspace/app/trace/trace.c
r39f892a9 r368ee04 512 512 goto error; 513 513 514 /* Send program pathname*/515 rc = loader_set_p athname(ldr, path);514 /* Send program. */ 515 rc = loader_set_program_path(ldr, path); 516 516 if (rc != EOK) 517 517 goto error; … … 523 523 524 524 /* Send default files */ 525 int *files[4];525 int fd_root; 526 526 int fd_stdin; 527 527 int fd_stdout; 528 528 int fd_stderr; 529 529 530 if ((stdin != NULL) && (vfs_fhandle(stdin, &fd_stdin) == EOK)) 531 files[0] = &fd_stdin; 532 else 533 files[0] = NULL; 534 535 if ((stdout != NULL) && (vfs_fhandle(stdout, &fd_stdout) == EOK)) 536 files[1] = &fd_stdout; 537 else 538 files[1] = NULL; 539 540 if ((stderr != NULL) && (vfs_fhandle(stderr, &fd_stderr) == EOK)) 541 files[2] = &fd_stderr; 542 else 543 files[2] = NULL; 544 545 files[3] = NULL; 546 547 rc = loader_set_files(ldr, files); 548 if (rc != EOK) 549 goto error; 550 530 fd_root = vfs_root(); 531 if (fd_root >= 0) { 532 rc = loader_add_inbox(ldr, "root", fd_root); 533 vfs_put(fd_root); 534 if (rc != EOK) 535 goto error; 536 } 537 538 if ((stdin != NULL) && (vfs_fhandle(stdin, &fd_stdin) == EOK)) { 539 rc = loader_add_inbox(ldr, "stdin", fd_stdin); 540 if (rc != EOK) 541 goto error; 542 } 543 544 if ((stdout != NULL) && (vfs_fhandle(stdout, &fd_stdout) == EOK)) { 545 rc = loader_add_inbox(ldr, "stdout", fd_stdout); 546 if (rc != EOK) 547 goto error; 548 } 549 550 if ((stderr != NULL) && (vfs_fhandle(stderr, &fd_stderr) == EOK)) { 551 rc = loader_add_inbox(ldr, "stderr", fd_stderr); 552 if (rc != EOK) 553 goto error; 554 } 555 551 556 /* Load the program. */ 552 557 rc = loader_load_program(ldr); … … 696 701 697 702 p = proto_new("vfs"); 698 o = oper_new("open", 2, arg_def, V_INT_ERRNO, 0, resp_def); 699 proto_add_oper(p, VFS_IN_OPEN, o); 700 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); 701 704 proto_add_oper(p, VFS_IN_READ, o); 702 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); 703 706 proto_add_oper(p, VFS_IN_WRITE, o); 704 o = oper_new("seek", 3, arg_def, V_ERRNO, 0, resp_def); 705 proto_add_oper(p, VFS_IN_SEEK, o); 706 o = oper_new("truncate", 5, arg_def, V_ERRNO, 0, resp_def); 707 proto_add_oper(p, VFS_IN_TRUNCATE, o); 708 o = oper_new("fstat", 1, arg_def, V_ERRNO, 0, resp_def); 709 proto_add_oper(p, VFS_IN_FSTAT, o); 710 o = oper_new("close", 1, arg_def, V_ERRNO, 0, resp_def); 711 proto_add_oper(p, VFS_IN_CLOSE, o); 712 o = oper_new("mount", 2, arg_def, V_ERRNO, 0, resp_def); 707 o = oper_new("vfs_resize", 5, arg_def, V_ERRNO, 0, resp_def); 708 proto_add_oper(p, VFS_IN_RESIZE, o); 709 o = oper_new("vfs_stat", 1, arg_def, V_ERRNO, 0, resp_def); 710 proto_add_oper(p, VFS_IN_STAT, o); 711 o = oper_new("vfs_put", 1, arg_def, V_ERRNO, 0, resp_def); 712 proto_add_oper(p, VFS_IN_PUT, o); 713 o = oper_new("vfs_mount", 2, arg_def, V_ERRNO, 0, resp_def); 713 714 proto_add_oper(p, VFS_IN_MOUNT, o); 714 715 /* o = oper_new("unmount", 0, arg_def); 715 716 proto_add_oper(p, VFS_IN_UNMOUNT, o);*/ 716 o = oper_new(" sync", 1, arg_def, V_ERRNO, 0, resp_def);717 o = oper_new("vfs_sync", 1, arg_def, V_ERRNO, 0, resp_def); 717 718 proto_add_oper(p, VFS_IN_SYNC, o); 718 o = oper_new("mkdir", 1, arg_def, V_ERRNO, 0, resp_def);719 proto_add_oper(p, VFS_IN_MKDIR, o);720 o = oper_new("unlink", 0, arg_def, V_ERRNO, 0, resp_def);721 proto_add_oper(p, VFS_IN_UNLINK, o);722 719 o = oper_new("rename", 0, arg_def, V_ERRNO, 0, resp_def); 723 720 proto_add_oper(p, VFS_IN_RENAME, o); 724 o = oper_new("stat", 0, arg_def, V_ERRNO, 0, resp_def); 725 proto_add_oper(p, VFS_IN_STAT, o); 726 o = oper_new("statfs", 0, arg_def, V_ERRNO, 0, resp_def); 721 o = oper_new("vfs_statfs", 0, arg_def, V_ERRNO, 0, resp_def); 727 722 proto_add_oper(p, VFS_IN_STATFS, o); 723 o = oper_new("vfs_walk", 2, arg_def, V_INT_ERRNO, 0, resp_def); 724 proto_add_oper(p, VFS_IN_WALK, o); 725 o = oper_new("vfs_open", 2, arg_def, V_ERRNO, 0, resp_def); 726 proto_add_oper(p, VFS_IN_OPEN, o); 727 o = oper_new("vfs_unlink", 3, arg_def, V_ERRNO, 0, resp_def); 728 proto_add_oper(p, VFS_IN_UNLINK, o); 728 729 729 730 proto_register(SERVICE_VFS, p); -
uspace/app/untar/main.c
r39f892a9 r368ee04 35 35 #include <stdio.h> 36 36 #include <stdlib.h> 37 #include <sys/stat.h>38 37 #include <errno.h> 39 38 #include <str_error.h> 39 #include <vfs/vfs.h> 40 40 #include "tar.h" 41 41 … … 103 103 static int handle_directory(const tar_header_t *header, FILE *tarfile) 104 104 { 105 if (mkdir(header->filename, 0755) != 0) { 106 if (errno != EEXIST) { 105 int rc; 106 107 rc = vfs_link_path(header->filename, KIND_DIRECTORY, NULL); 108 if (rc != EOK) { 109 if (rc != EEXIST) { 107 110 fprintf(stderr, "Failed to create directory %s: %s.\n", 108 header->filename, str_error( errno));109 return errno;111 header->filename, str_error(rc)); 112 return rc; 110 113 } 111 114 } -
uspace/app/viewer/viewer.c
r39f892a9 r368ee04 34 34 35 35 #include <stdio.h> 36 #include <unistd.h> 37 #include <fcntl.h> 38 #include <sys/stat.h> 36 #include <stdlib.h> 37 #include <vfs/vfs.h> 39 38 #include <errno.h> 40 39 #include <malloc.h> … … 110 109 static bool img_load(const char *fname, surface_t **p_local_surface) 111 110 { 112 int fd = open(fname, O_RDONLY);111 int fd = vfs_lookup_open(fname, WALK_REGULAR, MODE_READ); 113 112 if (fd < 0) 114 113 return false; 115 114 116 115 struct stat stat; 117 int rc = fstat(fd, &stat);118 if (rc != 0) {119 close(fd);116 int rc = vfs_stat(fd, &stat); 117 if (rc != EOK) { 118 vfs_put(fd); 120 119 return false; 121 120 } … … 123 122 void *tga = malloc(stat.size); 124 123 if (tga == NULL) { 125 close(fd);126 return false; 127 } 128 129 ssize_t rd = read(fd, tga, stat.size);124 vfs_put(fd); 125 return false; 126 } 127 128 ssize_t rd = vfs_read(fd, (aoff64_t []) {0}, tga, stat.size); 130 129 if ((rd < 0) || (rd != (ssize_t) stat.size)) { 131 130 free(tga); 132 close(fd);133 return false; 134 } 135 136 close(fd);131 vfs_put(fd); 132 return false; 133 } 134 135 vfs_put(fd); 137 136 138 137 *p_local_surface = decode_tga(tga, stat.size, 0); -
uspace/app/websrv/websrv.c
r39f892a9 r368ee04 39 39 #include <stdio.h> 40 40 #include <sys/types.h> 41 #include <sys/stat.h>42 41 #include <stdlib.h> 43 #include <fcntl.h>44 42 #include <task.h> 43 44 #include <vfs/vfs.h> 45 45 46 46 #include <inet/addr.h> … … 225 225 return ENOMEM; 226 226 227 int fd = open(fname, O_RDONLY);227 int fd = vfs_lookup_open(fname, WALK_REGULAR, MODE_READ); 228 228 if (fd < 0) { 229 229 rc = send_response(conn, msg_not_found); … … 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 = vfs_read(fd, &pos, fbuf, BUFFER_SIZE); 242 243 if (nr == 0) 243 244 break; 244 245 245 246 if (nr < 0) { 246 close(fd);247 vfs_put(fd); 247 248 return EIO; 248 249 } … … 251 252 if (rc != EOK) { 252 253 fprintf(stderr, "tcp_conn_send() failed\n"); 253 close(fd);254 vfs_put(fd); 254 255 return rc; 255 256 } 256 257 } 257 258 258 close(fd);259 vfs_put(fd); 259 260 260 261 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.
