Changeset 472c09d in mainline for uspace/srv/vfs/vfs_ops.c
- Timestamp:
- 2010-02-03T15:18:40Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b4cbef1
- Parents:
- 28be7fa
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/vfs/vfs_ops.c
r28be7fa r472c09d 266 266 267 267 /* We want the client to send us the mount point. */ 268 ipc_callid_t callid; 269 size_t size; 270 if (!async_data_write_receive(&callid, &size)) { 271 ipc_answer_0(callid, EINVAL); 272 ipc_answer_0(rid, EINVAL); 273 return; 274 } 275 276 /* Check whether size is reasonable wrt. the mount point. */ 277 if ((size < 1) || (size > MAX_PATH_LEN)) { 278 ipc_answer_0(callid, EINVAL); 279 ipc_answer_0(rid, EINVAL); 280 return; 281 } 282 283 /* Allocate buffer for the mount point data being received. */ 284 char *mp = malloc(size + 1); 285 if (!mp) { 286 ipc_answer_0(callid, ENOMEM); 287 ipc_answer_0(rid, ENOMEM); 288 return; 289 } 290 291 /* Deliver the mount point. */ 292 ipcarg_t retval = async_data_write_finalize(callid, mp, size); 293 if (retval != EOK) { 294 ipc_answer_0(rid, retval); 268 char *mp; 269 int rc = async_string_receive(&mp, MAX_PATH_LEN, NULL); 270 if (rc != EOK) { 271 ipc_answer_0(rid, rc); 272 return; 273 } 274 275 /* Now we expect to receive the mount options. */ 276 char *opts; 277 rc = async_string_receive(&opts, MAX_MNTOPTS_LEN, NULL); 278 if (rc != EOK) { 295 279 free(mp); 296 return; 297 } 298 mp[size] = '\0'; 299 300 /* Now we expect to receive the mount options. */ 301 if (!async_data_write_receive(&callid, &size)) { 302 ipc_answer_0(callid, EINVAL); 303 ipc_answer_0(rid, EINVAL); 304 free(mp); 305 return; 306 } 307 308 /* Check the offered options size. */ 309 if (size > MAX_MNTOPTS_LEN) { 310 ipc_answer_0(callid, EINVAL); 311 ipc_answer_0(rid, EINVAL); 312 free(mp); 313 return; 314 } 315 316 /* Allocate buffer for the mount options. */ 317 char *opts = (char *) malloc(size + 1); 318 if (!opts) { 319 ipc_answer_0(callid, ENOMEM); 320 ipc_answer_0(rid, ENOMEM); 321 free(mp); 322 return; 323 } 324 325 /* Deliver the mount options. */ 326 retval = async_data_write_finalize(callid, opts, size); 327 if (retval != EOK) { 328 ipc_answer_0(rid, retval); 280 ipc_answer_0(rid, rc); 281 return; 282 } 283 284 /* 285 * Now, we expect the client to send us data with the name of the file 286 * system. 287 */ 288 char *fs_name; 289 rc = async_string_receive(&fs_name, FS_NAME_MAXLEN, NULL); 290 if (rc != EOK) { 329 291 free(mp); 330 292 free(opts); 331 return; 332 } 333 opts[size] = '\0'; 334 335 /* 336 * Now, we expect the client to send us data with the name of the file 337 * system. 338 */ 339 if (!async_data_write_receive(&callid, &size)) { 340 ipc_answer_0(callid, EINVAL); 341 ipc_answer_0(rid, EINVAL); 342 free(mp); 343 free(opts); 344 return; 345 } 346 347 /* 348 * Don't receive more than is necessary for storing a full file system 349 * name. 350 */ 351 if ((size < 1) || (size > FS_NAME_MAXLEN)) { 352 ipc_answer_0(callid, EINVAL); 353 ipc_answer_0(rid, EINVAL); 354 free(mp); 355 free(opts); 356 return; 357 } 358 359 /* 360 * Allocate buffer for file system name. 361 */ 362 char *fs_name = (char *) malloc(size + 1); 363 if (fs_name == NULL) { 364 ipc_answer_0(callid, ENOMEM); 365 ipc_answer_0(rid, ENOMEM); 366 free(mp); 367 free(opts); 368 return; 369 } 370 371 /* Deliver the file system name. */ 372 retval = async_data_write_finalize(callid, fs_name, size); 373 if (retval != EOK) { 374 ipc_answer_0(rid, retval); 375 free(mp); 376 free(opts); 377 free(fs_name); 378 return; 379 } 380 fs_name[size] = '\0'; 381 293 ipc_answer_0(rid, rc); 294 return; 295 } 296 382 297 /* 383 298 * Wait for IPC_M_PING so that we can return an error if we don't know … … 385 300 */ 386 301 ipc_call_t data; 387 callid = async_get_call(&data);302 ipc_callid_t callid = async_get_call(&data); 388 303 if (IPC_GET_METHOD(data) != IPC_M_PING) { 389 304 ipc_answer_0(callid, ENOTSUP); … … 442 357 * Receive the mount point path. 443 358 */ 444 rc = async_ data_string_receive(&mp, MAX_PATH_LEN);359 rc = async_string_receive(&mp, MAX_PATH_LEN, NULL); 445 360 if (rc != EOK) 446 361 ipc_answer_0(rid, rc); … … 606 521 lflag |= L_EXCLUSIVE; 607 522 608 ipc_callid_t callid; 609 if (!async_data_write_receive(&callid, &len)) { 610 ipc_answer_0(callid, EINVAL); 611 ipc_answer_0(rid, EINVAL); 612 return; 613 } 614 615 char *path = malloc(len + 1); 616 if (!path) { 617 ipc_answer_0(callid, ENOMEM); 618 ipc_answer_0(rid, ENOMEM); 619 return; 620 } 621 622 int rc; 623 if ((rc = async_data_write_finalize(callid, path, len))) { 624 ipc_answer_0(rid, rc); 625 free(path); 626 return; 627 } 628 path[len] = '\0'; 523 char *path; 524 int rc = async_string_receive(&path, 0, NULL); 525 if (rc != EOK) { 526 ipc_answer_0(rid, rc); 527 return; 528 } 629 529 630 530 /* … … 1120 1020 void vfs_stat(ipc_callid_t rid, ipc_call_t *request) 1121 1021 { 1122 size_t len; 1022 char *path; 1023 int rc = async_string_receive(&path, 0, NULL); 1024 if (rc != EOK) { 1025 ipc_answer_0(rid, rc); 1026 return; 1027 } 1028 1123 1029 ipc_callid_t callid; 1124 1125 if (!async_data_write_receive(&callid, &len)) {1126 ipc_answer_0(callid, EINVAL);1127 ipc_answer_0(rid, EINVAL);1128 return;1129 }1130 char *path = malloc(len + 1);1131 if (!path) {1132 ipc_answer_0(callid, ENOMEM);1133 ipc_answer_0(rid, ENOMEM);1134 return;1135 }1136 int rc;1137 if ((rc = async_data_write_finalize(callid, path, len))) {1138 ipc_answer_0(rid, rc);1139 free(path);1140 return;1141 }1142 path[len] = '\0';1143 1144 1030 if (!async_data_read_receive(&callid, NULL)) { 1145 1031 free(path); … … 1187 1073 { 1188 1074 int mode = IPC_GET_ARG1(*request); 1189 1190 size_t len; 1191 ipc_callid_t callid; 1192 1193 if (!async_data_write_receive(&callid, &len)) { 1194 ipc_answer_0(callid, EINVAL); 1195 ipc_answer_0(rid, EINVAL); 1196 return; 1197 } 1198 char *path = malloc(len + 1); 1199 if (!path) { 1200 ipc_answer_0(callid, ENOMEM); 1201 ipc_answer_0(rid, ENOMEM); 1202 return; 1203 } 1204 int rc; 1205 if ((rc = async_data_write_finalize(callid, path, len))) { 1206 ipc_answer_0(rid, rc); 1207 free(path); 1208 return; 1209 } 1210 path[len] = '\0'; 1211 1075 1076 char *path; 1077 int rc = async_string_receive(&path, 0, NULL); 1078 if (rc != EOK) { 1079 ipc_answer_0(rid, rc); 1080 return; 1081 } 1082 1212 1083 /* Ignore mode for now. */ 1213 1084 (void) mode; … … 1224 1095 { 1225 1096 int lflag = IPC_GET_ARG1(*request); 1226 1227 size_t len; 1228 ipc_callid_t callid; 1229 1230 if (!async_data_write_receive(&callid, &len)) { 1231 ipc_answer_0(callid, EINVAL); 1232 ipc_answer_0(rid, EINVAL); 1233 return; 1234 } 1235 char *path = malloc(len + 1); 1236 if (!path) { 1237 ipc_answer_0(callid, ENOMEM); 1238 ipc_answer_0(rid, ENOMEM); 1239 return; 1240 } 1241 int rc; 1242 if ((rc = async_data_write_finalize(callid, path, len))) { 1243 ipc_answer_0(rid, rc); 1244 free(path); 1245 return; 1246 } 1247 path[len] = '\0'; 1097 1098 char *path; 1099 int rc = async_string_receive(&path, 0, NULL); 1100 if (rc != EOK) { 1101 ipc_answer_0(rid, rc); 1102 return; 1103 } 1248 1104 1249 1105 fibril_rwlock_write_lock(&namespace_rwlock); … … 1274 1130 void vfs_rename(ipc_callid_t rid, ipc_call_t *request) 1275 1131 { 1276 size_t olen, nlen;1277 ipc_callid_t callid;1278 int rc;1279 1280 1132 /* Retrieve the old path. */ 1281 if (!async_data_write_receive(&callid, &olen)) { 1282 ipc_answer_0(callid, EINVAL); 1283 ipc_answer_0(rid, EINVAL); 1284 return; 1285 } 1286 char *old = malloc(olen + 1); 1287 if (!old) { 1288 ipc_answer_0(callid, ENOMEM); 1289 ipc_answer_0(rid, ENOMEM); 1290 return; 1291 } 1292 if ((rc = async_data_write_finalize(callid, old, olen))) { 1293 ipc_answer_0(rid, rc); 1133 char *old; 1134 int rc = async_string_receive(&old, 0, NULL); 1135 if (rc != EOK) { 1136 ipc_answer_0(rid, rc); 1137 return; 1138 } 1139 1140 /* Retrieve the new path. */ 1141 char *new; 1142 rc = async_string_receive(&new, 0, NULL); 1143 if (rc != EOK) { 1294 1144 free(old); 1295 return; 1296 } 1297 old[olen] = '\0'; 1298 1299 /* Retrieve the new path. */ 1300 if (!async_data_write_receive(&callid, &nlen)) { 1301 ipc_answer_0(callid, EINVAL); 1302 ipc_answer_0(rid, EINVAL); 1303 free(old); 1304 return; 1305 } 1306 char *new = malloc(nlen + 1); 1307 if (!new) { 1308 ipc_answer_0(callid, ENOMEM); 1309 ipc_answer_0(rid, ENOMEM); 1310 free(old); 1311 return; 1312 } 1313 if ((rc = async_data_write_finalize(callid, new, nlen))) { 1314 ipc_answer_0(rid, rc); 1315 free(old); 1316 free(new); 1317 return; 1318 } 1319 new[nlen] = '\0'; 1320 1145 ipc_answer_0(rid, rc); 1146 return; 1147 } 1148 1149 size_t olen; 1150 size_t nlen; 1321 1151 char *oldc = canonify(old, &olen); 1322 1152 char *newc = canonify(new, &nlen); 1323 if (!oldc || !newc) { 1153 1154 if ((!oldc) || (!newc)) { 1324 1155 ipc_answer_0(rid, EINVAL); 1325 1156 free(old); … … 1327 1158 return; 1328 1159 } 1160 1329 1161 oldc[olen] = '\0'; 1330 1162 newc[nlen] = '\0'; 1163 1331 1164 if ((!str_lcmp(newc, oldc, str_length(oldc))) && 1332 1165 ((newc[str_length(oldc)] == '/') || … … 1349 1182 vfs_lookup_res_t new_par_lr; 1350 1183 fibril_rwlock_write_lock(&namespace_rwlock); 1184 1351 1185 /* Lookup the node belonging to the old file name. */ 1352 1186 rc = vfs_lookup_internal(oldc, L_NONE, &old_lr, NULL); … … 1358 1192 return; 1359 1193 } 1194 1360 1195 vfs_node_t *old_node = vfs_node_get(&old_lr); 1361 1196 if (!old_node) { … … 1366 1201 return; 1367 1202 } 1203 1368 1204 /* Determine the path to the parent of the node with the new name. */ 1369 1205 char *parentc = str_dup(newc); … … 1375 1211 return; 1376 1212 } 1213 1377 1214 char *lastsl = str_rchr(parentc + 1, '/'); 1378 1215 if (lastsl) … … 1380 1217 else 1381 1218 parentc[1] = '\0'; 1219 1382 1220 /* Lookup parent of the new file name. */ 1383 1221 rc = vfs_lookup_internal(parentc, L_NONE, &new_par_lr, NULL); … … 1390 1228 return; 1391 1229 } 1230 1392 1231 /* Check whether linking to the same file system instance. */ 1393 1232 if ((old_node->fs_handle != new_par_lr.triplet.fs_handle) || … … 1399 1238 return; 1400 1239 } 1240 1401 1241 /* Destroy the old link for the new name. */ 1402 1242 vfs_node_t *new_node = NULL; 1403 1243 rc = vfs_lookup_internal(newc, L_UNLINK, &new_lr, NULL); 1244 1404 1245 switch (rc) { 1405 1246 case ENOENT: … … 1426 1267 return; 1427 1268 } 1269 1428 1270 /* Create the new link for the new name. */ 1429 1271 rc = vfs_lookup_internal(newc, L_LINK, NULL, NULL, old_node->index); … … 1437 1279 return; 1438 1280 } 1281 1439 1282 fibril_mutex_lock(&nodes_mutex); 1440 1283 old_node->lnkcnt++; 1441 1284 fibril_mutex_unlock(&nodes_mutex); 1285 1442 1286 /* Destroy the link for the old name. */ 1443 1287 rc = vfs_lookup_internal(oldc, L_UNLINK, NULL, NULL); … … 1452 1296 return; 1453 1297 } 1298 1454 1299 fibril_mutex_lock(&nodes_mutex); 1455 1300 old_node->lnkcnt--; … … 1457 1302 fibril_rwlock_write_unlock(&namespace_rwlock); 1458 1303 vfs_node_put(old_node); 1304 1459 1305 if (new_node) 1460 1306 vfs_node_put(new_node); 1307 1461 1308 free(old); 1462 1309 free(new);
Note:
See TracChangeset
for help on using the changeset viewer.