Changeset a35b458 in mainline for uspace/lib/c/generic/vfs/vfs.c
- Timestamp:
- 2018-03-02T20:10:49Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/vfs/vfs.c
r3061bc1 ra35b458 264 264 { 265 265 fibril_mutex_lock(&cwd_mutex); 266 266 267 267 if ((cwd_size == 0) || (size < cwd_size + 1)) { 268 268 fibril_mutex_unlock(&cwd_mutex); 269 269 return ERANGE; 270 270 } 271 271 272 272 str_cpy(buf, size, cwd_path); 273 273 fibril_mutex_unlock(&cwd_mutex); 274 274 275 275 return EOK; 276 276 } … … 288 288 if (!abs) 289 289 return ENOMEM; 290 290 291 291 int fd; 292 292 errno_t rc = vfs_lookup(abs, WALK_DIRECTORY, &fd); … … 295 295 return rc; 296 296 } 297 297 298 298 fibril_mutex_lock(&cwd_mutex); 299 299 300 300 if (cwd_fd >= 0) 301 301 vfs_put(cwd_fd); 302 302 303 303 if (cwd_path) 304 304 free(cwd_path); 305 305 306 306 cwd_fd = fd; 307 307 cwd_path = abs; 308 308 cwd_size = abs_size; 309 309 310 310 fibril_mutex_unlock(&cwd_mutex); 311 311 return EOK; … … 319 319 { 320 320 fibril_mutex_lock(&vfs_mutex); 321 321 322 322 while (vfs_sess == NULL) { 323 323 vfs_sess = service_connect_blocking(SERVICE_VFS, INTERFACE_VFS, 324 324 0); 325 325 } 326 326 327 327 fibril_mutex_unlock(&vfs_mutex); 328 328 329 329 return async_exchange_begin(vfs_sess); 330 330 } … … 356 356 if (rc != EOK) 357 357 return NULL; 358 358 359 359 if (stat.service == 0) 360 360 return NULL; 361 361 362 362 return loc_service_connect(stat.service, iface, 0); 363 363 } … … 376 376 { 377 377 errno_t rc; 378 378 379 379 ipc_call_t answer; 380 380 async_exch_t *exch = vfs_exchange_begin(); 381 381 aid_t req = async_send_1(exch, VFS_IN_FSPROBE, serv, &answer); 382 382 383 383 rc = async_data_write_start(exch, (void *) fs_name, 384 384 str_size(fs_name)); 385 385 386 386 async_wait_for(req, &rc); 387 387 388 388 if (rc != EOK) { 389 389 vfs_exchange_end(exch); 390 390 return rc; 391 391 } 392 392 393 393 rc = async_data_read_start(exch, info, sizeof(*info)); 394 394 vfs_exchange_end(exch); 395 395 396 396 return rc; 397 397 } … … 620 620 { 621 621 errno_t rc, rc1; 622 622 623 623 if (!mountedfd) 624 624 flags |= VFS_MOUNT_NO_REF; 625 625 if (mp < 0) 626 626 flags |= VFS_MOUNT_CONNECT_ONLY; 627 627 628 628 ipc_call_t answer; 629 629 async_exch_t *exch = vfs_exchange_begin(); … … 643 643 if (mountedfd) 644 644 *mountedfd = (int) IPC_GET_ARG1(answer); 645 645 646 646 if (rc != EOK) 647 647 return rc; … … 665 665 int null_id = -1; 666 666 char null[LOC_NAME_MAXLEN]; 667 667 668 668 if (str_cmp(fqsn, "") == 0) { 669 669 /* … … 671 671 */ 672 672 null_id = loc_null_create(); 673 673 674 674 if (null_id == -1) 675 675 return ENOMEM; 676 676 677 677 snprintf(null, LOC_NAME_MAXLEN, "null/%d", null_id); 678 678 fqsn = null; 679 679 } 680 680 681 681 if (flags & IPC_FLAG_BLOCKING) 682 682 flags = VFS_MOUNT_BLOCKING; 683 683 else 684 684 flags = 0; 685 685 686 686 service_id_t service_id; 687 687 errno_t res = loc_service_get_id(fqsn, &service_id, flags); … … 689 689 if (null_id != -1) 690 690 loc_null_destroy(null_id); 691 691 692 692 return res; 693 693 } 694 694 695 695 size_t mpa_size; 696 696 char *mpa = vfs_absolutize(mp, &mpa_size); … … 698 698 if (null_id != -1) 699 699 loc_null_destroy(null_id); 700 700 701 701 return ENOMEM; 702 702 } 703 703 704 704 fibril_mutex_lock(&root_mutex); 705 705 706 706 errno_t rc; 707 707 708 708 if (str_cmp(mpa, "/") == 0) { 709 709 /* Mounting root. */ 710 710 711 711 if (root_fd >= 0) { 712 712 fibril_mutex_unlock(&root_mutex); … … 715 715 return EBUSY; 716 716 } 717 717 718 718 int root; 719 719 rc = vfs_mount(-1, fs_name, service_id, opts, flags, instance, … … 728 728 return EINVAL; 729 729 } 730 730 731 731 int mpfd; 732 732 rc = vfs_walk(root_fd, mpa, WALK_DIRECTORY, &mpfd); … … 737 737 } 738 738 } 739 739 740 740 fibril_mutex_unlock(&root_mutex); 741 741 742 742 if ((rc != EOK) && (null_id != -1)) 743 743 loc_null_destroy(null_id); 744 744 745 745 return (errno_t) rc; 746 746 } … … 759 759 errno_t rc = async_req_2_0(exch, VFS_IN_OPEN, file, mode); 760 760 vfs_exchange_end(exch); 761 761 762 762 return rc; 763 763 } … … 788 788 errno_t rc = async_req_1_0(exch, VFS_IN_PUT, file); 789 789 vfs_exchange_end(exch); 790 790 791 791 return rc; 792 792 } … … 845 845 uint8_t *bp = (uint8_t *) buf; 846 846 errno_t rc; 847 847 848 848 do { 849 849 bp += cnt; … … 852 852 rc = vfs_read_short(file, *pos, bp, nbyte - nr, &cnt); 853 853 } while (rc == EOK && cnt > 0 && (nbyte - nr - cnt) > 0); 854 854 855 855 if (rc != EOK) { 856 856 *nread = nr; 857 857 return rc; 858 858 } 859 859 860 860 nr += cnt; 861 861 *pos += cnt; … … 885 885 ipc_call_t answer; 886 886 aid_t req; 887 887 888 888 if (nbyte > DATA_XFER_LIMIT) 889 889 nbyte = DATA_XFER_LIMIT; 890 891 async_exch_t *exch = vfs_exchange_begin(); 892 890 891 async_exch_t *exch = vfs_exchange_begin(); 892 893 893 req = async_send_3(exch, VFS_IN_READ, file, LOWER32(pos), 894 894 UPPER32(pos), &answer); … … 896 896 897 897 vfs_exchange_end(exch); 898 898 899 899 if (rc == EOK) 900 900 async_wait_for(req, &rc); 901 901 else 902 902 async_forget(req); 903 903 904 904 if (rc != EOK) 905 905 return rc; 906 906 907 907 *nread = (ssize_t) IPC_GET_ARG1(answer); 908 908 return EOK; … … 926 926 errno_t rc_orig; 927 927 aid_t req; 928 928 929 929 size_t olda_size; 930 930 char *olda = vfs_absolutize(old, &olda_size); … … 938 938 return ENOMEM; 939 939 } 940 940 941 941 async_exch_t *exch = vfs_exchange_begin(); 942 942 int root = vfs_root(); … … 946 946 return ENOENT; 947 947 } 948 948 949 949 req = async_send_1(exch, VFS_IN_RENAME, root, NULL); 950 950 rc = async_data_write_start(exch, olda, olda_size); … … 994 994 UPPER32(length)); 995 995 vfs_exchange_end(exch); 996 996 997 997 return rc; 998 998 } … … 1056 1056 errno_t rc; 1057 1057 aid_t req; 1058 1059 async_exch_t *exch = vfs_exchange_begin(); 1060 1058 1059 async_exch_t *exch = vfs_exchange_begin(); 1060 1061 1061 req = async_send_1(exch, VFS_IN_STAT, file, NULL); 1062 1062 rc = async_data_read_start(exch, (void *) stat, sizeof(vfs_stat_t)); 1063 1063 if (rc != EOK) { 1064 1064 vfs_exchange_end(exch); 1065 1065 1066 1066 errno_t rc_orig; 1067 1067 async_wait_for(req, &rc_orig); 1068 1068 1069 1069 if (rc_orig != EOK) 1070 1070 rc = rc_orig; 1071 1072 return rc; 1073 } 1074 1071 1072 return rc; 1073 } 1074 1075 1075 vfs_exchange_end(exch); 1076 1076 async_wait_for(req, &rc); 1077 1077 1078 1078 return rc; 1079 1079 } … … 1092 1092 if (rc != EOK) 1093 1093 return rc; 1094 1094 1095 1095 rc = vfs_stat(file, stat); 1096 1096 … … 1138 1138 if (rc != EOK) 1139 1139 return rc; 1140 1140 1141 1141 rc = vfs_statfs(file, st); 1142 1142 … … 1157 1157 errno_t rc = async_req_1_0(exch, VFS_IN_SYNC, file); 1158 1158 vfs_exchange_end(exch); 1159 1159 1160 1160 return rc; 1161 1161 } … … 1178 1178 errno_t rc; 1179 1179 aid_t req; 1180 1181 async_exch_t *exch = vfs_exchange_begin(); 1182 1180 1181 async_exch_t *exch = vfs_exchange_begin(); 1182 1183 1183 req = async_send_2(exch, VFS_IN_UNLINK, parent, expect, NULL); 1184 1184 rc = async_data_write_start(exch, child, str_size(child)); 1185 1186 vfs_exchange_end(exch); 1187 1185 1186 vfs_exchange_end(exch); 1187 1188 1188 errno_t rc_orig; 1189 1189 async_wait_for(req, &rc_orig); 1190 1190 1191 1191 if (rc_orig != EOK) 1192 1192 return (errno_t) rc_orig; … … 1219 1219 1220 1220 rc = vfs_unlink(parent, child, expect); 1221 1221 1222 1222 free(child); 1223 1223 vfs_put(parent); … … 1252 1252 if (rc != EOK) 1253 1253 return rc; 1254 1254 1255 1255 rc = vfs_unmount(mp); 1256 1256 vfs_put(mp); … … 1270 1270 { 1271 1271 async_exch_t *exch = vfs_exchange_begin(); 1272 1272 1273 1273 ipc_call_t answer; 1274 1274 aid_t req = async_send_2(exch, VFS_IN_WALK, parent, flags, &answer); 1275 1275 errno_t rc = async_data_write_start(exch, path, str_size(path)); 1276 1276 vfs_exchange_end(exch); 1277 1277 1278 1278 errno_t rc_orig; 1279 1279 async_wait_for(req, &rc_orig); … … 1281 1281 if (rc_orig != EOK) 1282 1282 return (errno_t) rc_orig; 1283 1283 1284 1284 if (rc != EOK) 1285 1285 return (errno_t) rc; 1286 1286 1287 1287 *handle = (int) IPC_GET_ARG1(answer); 1288 1288 return EOK; … … 1349 1349 ipc_call_t answer; 1350 1350 aid_t req; 1351 1351 1352 1352 if (nbyte > DATA_XFER_LIMIT) 1353 1353 nbyte = DATA_XFER_LIMIT; 1354 1355 async_exch_t *exch = vfs_exchange_begin(); 1356 1354 1355 async_exch_t *exch = vfs_exchange_begin(); 1356 1357 1357 req = async_send_3(exch, VFS_IN_WRITE, file, LOWER32(pos), 1358 1358 UPPER32(pos), &answer); 1359 1359 rc = async_data_write_start(exch, (void *) buf, nbyte); 1360 1361 vfs_exchange_end(exch); 1362 1360 1361 vfs_exchange_end(exch); 1362 1363 1363 if (rc == EOK) 1364 1364 async_wait_for(req, &rc); … … 1368 1368 if (rc != EOK) 1369 1369 return rc; 1370 1370 1371 1371 *nwritten = (ssize_t) IPC_GET_ARG1(answer); 1372 1372 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.