Changes in uspace/lib/c/generic/vfs/vfs.c [cde999a:a53ed3a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/vfs/vfs.c
rcde999a ra53ed3a 86 86 * and consume system resources. 87 87 * 88 * Functions that return int return an error code on error and do not88 * Functions that return errno_t return an error code on error and do not 89 89 * set errno. Depending on function, success is signalled by returning either 90 90 * EOK or a non-negative file handle. … … 97 97 * if (file < 0) 98 98 * return file; 99 * int rc = vfs_open(file, MODE_READ);99 * errno_t rc = vfs_open(file, MODE_READ); 100 100 * if (rc != EOK) { 101 101 * (void) vfs_put(file); … … 128 128 static int root_fd = -1; 129 129 130 static int get_parent_and_child(const char *path, int *parent, char **child)130 static errno_t get_parent_and_child(const char *path, int *parent, char **child) 131 131 { 132 132 size_t size; … … 146 146 } else { 147 147 *slash = '\0'; 148 int rc = vfs_lookup(apath, WALK_DIRECTORY, parent);148 errno_t rc = vfs_lookup(apath, WALK_DIRECTORY, parent); 149 149 if (rc != EOK) { 150 150 free(apath); … … 238 238 * @return New file handle on success or an error code 239 239 */ 240 int vfs_clone(int file_from, int file_to, bool high, int *handle)240 errno_t vfs_clone(int file_from, int file_to, bool high, int *handle) 241 241 { 242 242 assert(handle != NULL); … … 244 244 async_exch_t *vfs_exch = vfs_exchange_begin(); 245 245 sysarg_t ret; 246 int rc = async_req_3_1(vfs_exch, VFS_IN_CLONE, (sysarg_t) file_from,246 errno_t rc = async_req_3_1(vfs_exch, VFS_IN_CLONE, (sysarg_t) file_from, 247 247 (sysarg_t) file_to, (sysarg_t) high, &ret); 248 248 vfs_exchange_end(vfs_exch); … … 261 261 * @return EOK on success or a non-error code 262 262 */ 263 int vfs_cwd_get(char *buf, size_t size)263 errno_t vfs_cwd_get(char *buf, size_t size) 264 264 { 265 265 fibril_mutex_lock(&cwd_mutex); … … 282 282 * @return EOK on success or an error code 283 283 */ 284 int vfs_cwd_set(const char *path)284 errno_t vfs_cwd_set(const char *path) 285 285 { 286 286 size_t abs_size; … … 290 290 291 291 int fd; 292 int rc = vfs_lookup(abs, WALK_DIRECTORY, &fd);292 errno_t rc = vfs_lookup(abs, WALK_DIRECTORY, &fd); 293 293 if (rc != EOK) { 294 294 free(abs); … … 353 353 { 354 354 struct stat stat; 355 int rc = vfs_stat(file, &stat);356 if (rc != 0)355 errno_t rc = vfs_stat(file, &stat); 356 if (rc != EOK) 357 357 return NULL; 358 358 … … 372 372 * @return EOK on success or an error code 373 373 */ 374 int vfs_fsprobe(const char *fs_name, service_id_t serv,374 errno_t vfs_fsprobe(const char *fs_name, service_id_t serv, 375 375 vfs_fs_probe_info_t *info) 376 376 { 377 int rc;377 errno_t rc; 378 378 379 379 ipc_call_t answer; … … 406 406 * @return EOK on success or an error code 407 407 */ 408 int vfs_fstypes(vfs_fstypes_t *fstypes)408 errno_t vfs_fstypes(vfs_fstypes_t *fstypes) 409 409 { 410 410 sysarg_t size; … … 414 414 415 415 async_exch_t *exch = vfs_exchange_begin(); 416 int rc = async_req_0_1(exch, VFS_IN_FSTYPES, &size);416 errno_t rc = async_req_0_1(exch, VFS_IN_FSTYPES, &size); 417 417 418 418 if (rc != EOK) { … … 501 501 * @return EOK on success or an error code 502 502 */ 503 int vfs_link(int parent, const char *child, vfs_file_kind_t kind, int *linkedfd)503 errno_t vfs_link(int parent, const char *child, vfs_file_kind_t kind, int *linkedfd) 504 504 { 505 505 int flags = (kind == KIND_DIRECTORY) ? WALK_DIRECTORY : WALK_REGULAR; 506 506 int file = -1; 507 int rc = vfs_walk(parent, child, WALK_MUST_CREATE | flags, &file);507 errno_t rc = vfs_walk(parent, child, WALK_MUST_CREATE | flags, &file); 508 508 if (rc != EOK) 509 509 return rc; … … 531 531 * @return EOK on success or an error code 532 532 */ 533 int vfs_link_path(const char *path, vfs_file_kind_t kind, int *linkedfd)533 errno_t vfs_link_path(const char *path, vfs_file_kind_t kind, int *linkedfd) 534 534 { 535 535 char *child; 536 536 int parent; 537 int rc = get_parent_and_child(path, &parent, &child);537 errno_t rc = get_parent_and_child(path, &parent, &child); 538 538 if (rc != EOK) 539 539 return rc; … … 554 554 * @return EOK on success or an error code. 555 555 */ 556 int vfs_lookup(const char *path, int flags, int *handle)556 errno_t vfs_lookup(const char *path, int flags, int *handle) 557 557 { 558 558 size_t size; … … 570 570 *handle = -1; 571 571 572 int rc = vfs_walk(root, p, flags, handle);572 errno_t rc = vfs_walk(root, p, flags, handle); 573 573 vfs_put(root); 574 574 free(p); … … 587 587 * @return EOK on success or an error code 588 588 */ 589 int vfs_lookup_open(const char *path, int flags, int mode, int *handle)589 errno_t vfs_lookup_open(const char *path, int flags, int mode, int *handle) 590 590 { 591 591 int file; 592 int rc = vfs_lookup(path, flags, &file);592 errno_t rc = vfs_lookup(path, flags, &file); 593 593 if (rc != EOK) 594 594 return rc; … … 616 616 * @return EOK on success or an error code 617 617 */ 618 int vfs_mount(int mp, const char *fs_name, service_id_t serv, const char *opts,618 errno_t vfs_mount(int mp, const char *fs_name, service_id_t serv, const char *opts, 619 619 unsigned int flags, unsigned int instance, int *mountedfd) 620 620 { 621 int rc, rc1;621 errno_t rc, rc1; 622 622 623 623 if (!mountedfd) … … 660 660 * @return EOK on success or an error code 661 661 */ 662 int vfs_mount_path(const char *mp, const char *fs_name, const char *fqsn,662 errno_t vfs_mount_path(const char *mp, const char *fs_name, const char *fqsn, 663 663 const char *opts, unsigned int flags, unsigned int instance) 664 664 { … … 685 685 686 686 service_id_t service_id; 687 int res = loc_service_get_id(fqsn, &service_id, flags);687 errno_t res = loc_service_get_id(fqsn, &service_id, flags); 688 688 if (res != EOK) { 689 689 if (null_id != -1) … … 704 704 fibril_mutex_lock(&root_mutex); 705 705 706 int rc;706 errno_t rc; 707 707 708 708 if (str_cmp(mpa, "/") == 0) { … … 743 743 loc_null_destroy(null_id); 744 744 745 return ( int) rc;745 return (errno_t) rc; 746 746 } 747 747 … … 754 754 * @return EOK on success or an error code 755 755 */ 756 int vfs_open(int file, int mode)757 { 758 async_exch_t *exch = vfs_exchange_begin(); 759 int rc = async_req_2_0(exch, VFS_IN_OPEN, file, mode);756 errno_t vfs_open(int file, int mode) 757 { 758 async_exch_t *exch = vfs_exchange_begin(); 759 errno_t rc = async_req_2_0(exch, VFS_IN_OPEN, file, mode); 760 760 vfs_exchange_end(exch); 761 761 … … 771 771 * @return EOK on success or an error code 772 772 */ 773 int vfs_pass_handle(async_exch_t *vfs_exch, int file, async_exch_t *exch)773 errno_t vfs_pass_handle(async_exch_t *vfs_exch, int file, async_exch_t *exch) 774 774 { 775 775 return async_state_change_start(exch, VFS_PASS_HANDLE, (sysarg_t) file, … … 783 783 * @return EOK on success or an error code 784 784 */ 785 int vfs_put(int file)786 { 787 async_exch_t *exch = vfs_exchange_begin(); 788 int rc = async_req_1_0(exch, VFS_IN_PUT, file);785 errno_t vfs_put(int file) 786 { 787 async_exch_t *exch = vfs_exchange_begin(); 788 errno_t rc = async_req_1_0(exch, VFS_IN_PUT, file); 789 789 vfs_exchange_end(exch); 790 790 … … 800 800 * @return EOK on success or an error code 801 801 */ 802 int vfs_receive_handle(bool high, int *handle)802 errno_t vfs_receive_handle(bool high, int *handle) 803 803 { 804 804 ipc_callid_t callid; … … 813 813 814 814 sysarg_t ret; 815 int rc = async_req_1_1(vfs_exch, VFS_IN_WAIT_HANDLE, high, &ret);815 errno_t rc = async_req_1_1(vfs_exch, VFS_IN_WAIT_HANDLE, high, &ret); 816 816 817 817 async_exchange_end(vfs_exch); … … 839 839 * @return On failure, an error code 840 840 */ 841 int vfs_read(int file, aoff64_t *pos, void *buf, size_t nbyte, size_t *nread)841 errno_t vfs_read(int file, aoff64_t *pos, void *buf, size_t nbyte, size_t *nread) 842 842 { 843 843 ssize_t cnt = 0; 844 844 size_t nr = 0; 845 845 uint8_t *bp = (uint8_t *) buf; 846 int rc;846 errno_t rc; 847 847 848 848 do { … … 879 879 * @return EOK on success or an error code 880 880 */ 881 int vfs_read_short(int file, aoff64_t pos, void *buf, size_t nbyte,881 errno_t vfs_read_short(int file, aoff64_t pos, void *buf, size_t nbyte, 882 882 ssize_t *nread) 883 883 { 884 int rc;884 errno_t rc; 885 885 ipc_call_t answer; 886 886 aid_t req; … … 921 921 * @return EOK on success or an error code 922 922 */ 923 int vfs_rename_path(const char *old, const char *new)924 { 925 int rc;926 int rc_orig;923 errno_t vfs_rename_path(const char *old, const char *new) 924 { 925 errno_t rc; 926 errno_t rc_orig; 927 927 aid_t req; 928 928 … … 988 988 * @return EOK on success or an error code 989 989 */ 990 int vfs_resize(int file, aoff64_t length)991 { 992 async_exch_t *exch = vfs_exchange_begin(); 993 int rc = async_req_3_0(exch, VFS_IN_RESIZE, file, LOWER32(length),990 errno_t vfs_resize(int file, aoff64_t length) 991 { 992 async_exch_t *exch = vfs_exchange_begin(); 993 errno_t rc = async_req_3_0(exch, VFS_IN_RESIZE, file, LOWER32(length), 994 994 UPPER32(length)); 995 995 vfs_exchange_end(exch); … … 1009 1009 fd = -1; 1010 1010 } else { 1011 int rc = vfs_clone(root_fd, -1, true, &fd);1011 errno_t rc = vfs_clone(root_fd, -1, true, &fd); 1012 1012 if (rc != EOK) { 1013 1013 fd = -1; … … 1028 1028 * @return Error code 1029 1029 */ 1030 int vfs_root_set(int nroot)1030 errno_t vfs_root_set(int nroot) 1031 1031 { 1032 1032 int new_root; 1033 int rc = vfs_clone(nroot, -1, true, &new_root);1033 errno_t rc = vfs_clone(nroot, -1, true, &new_root); 1034 1034 if (rc != EOK) { 1035 1035 return rc; … … 1052 1052 * @return EOK on success or an error code 1053 1053 */ 1054 int vfs_stat(int file, struct stat *stat)1055 { 1056 int rc;1054 errno_t vfs_stat(int file, struct stat *stat) 1055 { 1056 errno_t rc; 1057 1057 aid_t req; 1058 1058 … … 1064 1064 vfs_exchange_end(exch); 1065 1065 1066 int rc_orig;1066 errno_t rc_orig; 1067 1067 async_wait_for(req, &rc_orig); 1068 1068 … … 1086 1086 * @return EOK on success or an error code 1087 1087 */ 1088 int vfs_stat_path(const char *path, struct stat *stat)1088 errno_t vfs_stat_path(const char *path, struct stat *stat) 1089 1089 { 1090 1090 int file; 1091 int rc = vfs_lookup(path, 0, &file);1091 errno_t rc = vfs_lookup(path, 0, &file); 1092 1092 if (rc != EOK) 1093 1093 return rc; … … 1107 1107 * @return EOK on success or an error code 1108 1108 */ 1109 int vfs_statfs(int file, struct statfs *st)1110 { 1111 int rc, ret;1109 errno_t vfs_statfs(int file, struct statfs *st) 1110 { 1111 errno_t rc, ret; 1112 1112 aid_t req; 1113 1113 … … 1132 1132 * @return EOK on success or an error code 1133 1133 */ 1134 int vfs_statfs_path(const char *path, struct statfs *st)1134 errno_t vfs_statfs_path(const char *path, struct statfs *st) 1135 1135 { 1136 1136 int file; 1137 int rc = vfs_lookup(path, 0, &file);1137 errno_t rc = vfs_lookup(path, 0, &file); 1138 1138 if (rc != EOK) 1139 1139 return rc; … … 1152 1152 * @return EOK on success or an error code 1153 1153 */ 1154 int vfs_sync(int file)1155 { 1156 async_exch_t *exch = vfs_exchange_begin(); 1157 int rc = async_req_1_0(exch, VFS_IN_SYNC, file);1154 errno_t vfs_sync(int file) 1155 { 1156 async_exch_t *exch = vfs_exchange_begin(); 1157 errno_t rc = async_req_1_0(exch, VFS_IN_SYNC, file); 1158 1158 vfs_exchange_end(exch); 1159 1159 … … 1174 1174 * @return EOK on success or an error code 1175 1175 */ 1176 int vfs_unlink(int parent, const char *child, int expect)1177 { 1178 int rc;1176 errno_t vfs_unlink(int parent, const char *child, int expect) 1177 { 1178 errno_t rc; 1179 1179 aid_t req; 1180 1180 … … 1186 1186 vfs_exchange_end(exch); 1187 1187 1188 int rc_orig;1188 errno_t rc_orig; 1189 1189 async_wait_for(req, &rc_orig); 1190 1190 1191 1191 if (rc_orig != EOK) 1192 return ( int) rc_orig;1192 return (errno_t) rc_orig; 1193 1193 return rc; 1194 1194 } … … 1203 1203 * @return EOK on success or an error code 1204 1204 */ 1205 int vfs_unlink_path(const char *path)1205 errno_t vfs_unlink_path(const char *path) 1206 1206 { 1207 1207 int expect; 1208 int rc = vfs_lookup(path, 0, &expect);1208 errno_t rc = vfs_lookup(path, 0, &expect); 1209 1209 if (rc != EOK) 1210 1210 return rc; … … 1232 1232 * @return EOK on success or an error code 1233 1233 */ 1234 int vfs_unmount(int mp)1235 { 1236 async_exch_t *exch = vfs_exchange_begin(); 1237 int rc = async_req_1_0(exch, VFS_IN_UNMOUNT, mp);1234 errno_t vfs_unmount(int mp) 1235 { 1236 async_exch_t *exch = vfs_exchange_begin(); 1237 errno_t rc = async_req_1_0(exch, VFS_IN_UNMOUNT, mp); 1238 1238 vfs_exchange_end(exch); 1239 1239 return rc; … … 1246 1246 * @return EOK on success or an error code 1247 1247 */ 1248 int vfs_unmount_path(const char *mpp)1248 errno_t vfs_unmount_path(const char *mpp) 1249 1249 { 1250 1250 int mp; 1251 int rc = vfs_lookup(mpp, WALK_MOUNT_POINT | WALK_DIRECTORY, &mp);1251 errno_t rc = vfs_lookup(mpp, WALK_MOUNT_POINT | WALK_DIRECTORY, &mp); 1252 1252 if (rc != EOK) 1253 1253 return rc; … … 1267 1267 * @return Error code. 1268 1268 */ 1269 int vfs_walk(int parent, const char *path, int flags, int *handle)1269 errno_t vfs_walk(int parent, const char *path, int flags, int *handle) 1270 1270 { 1271 1271 async_exch_t *exch = vfs_exchange_begin(); … … 1273 1273 ipc_call_t answer; 1274 1274 aid_t req = async_send_2(exch, VFS_IN_WALK, parent, flags, &answer); 1275 int rc = async_data_write_start(exch, path, str_size(path));1275 errno_t rc = async_data_write_start(exch, path, str_size(path)); 1276 1276 vfs_exchange_end(exch); 1277 1277 1278 int rc_orig;1278 errno_t rc_orig; 1279 1279 async_wait_for(req, &rc_orig); 1280 1280 1281 1281 if (rc_orig != EOK) 1282 return ( int) rc_orig;1282 return (errno_t) rc_orig; 1283 1283 1284 1284 if (rc != EOK) 1285 return ( int) rc;1285 return (errno_t) rc; 1286 1286 1287 1287 *handle = (int) IPC_GET_ARG1(answer); … … 1304 1304 * @return On failure, an error code 1305 1305 */ 1306 int vfs_write(int file, aoff64_t *pos, const void *buf, size_t nbyte,1306 errno_t vfs_write(int file, aoff64_t *pos, const void *buf, size_t nbyte, 1307 1307 size_t *nwritten) 1308 1308 { … … 1310 1310 ssize_t nwr = 0; 1311 1311 const uint8_t *bp = (uint8_t *) buf; 1312 int rc;1312 errno_t rc; 1313 1313 1314 1314 do { … … 1343 1343 * @return EOK on success or an error code 1344 1344 */ 1345 int vfs_write_short(int file, aoff64_t pos, const void *buf, size_t nbyte,1345 errno_t vfs_write_short(int file, aoff64_t pos, const void *buf, size_t nbyte, 1346 1346 ssize_t *nwritten) 1347 1347 { 1348 int rc;1348 errno_t rc; 1349 1349 ipc_call_t answer; 1350 1350 aid_t req;
Note:
See TracChangeset
for help on using the changeset viewer.