Changes in uspace/srv/fs/fat/fat_ops.c [efcebe1:b72efe8] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/fat/fat_ops.c
refcebe1 rb72efe8 85 85 static aoff64_t fat_size_get(fs_node_t *); 86 86 static unsigned fat_lnkcnt_get(fs_node_t *); 87 static char fat_plb_get_char(unsigned); 87 88 static bool fat_is_directory(fs_node_t *); 88 89 static bool fat_is_file(fs_node_t *node); … … 900 901 } 901 902 903 char fat_plb_get_char(unsigned pos) 904 { 905 return fat_reg.plb_ro[pos % PLB_SIZE]; 906 } 907 902 908 bool fat_is_directory(fs_node_t *fn) 903 909 { … … 930 936 .size_get = fat_size_get, 931 937 .lnkcnt_get = fat_lnkcnt_get, 938 .plb_get_char = fat_plb_get_char, 932 939 .is_directory = fat_is_directory, 933 940 .is_file = fat_is_file, … … 936 943 937 944 /* 938 * FAT VFS_OUToperations.945 * VFS operations. 939 946 */ 940 947 941 static int 942 fat_mounted(devmap_handle_t devmap_handle, const char *opts, fs_index_t *index, 943 aoff64_t *size, unsigned *linkcnt) 944 { 948 void fat_mounted(ipc_callid_t rid, ipc_call_t *request) 949 { 950 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 945 951 enum cache_mode cmode; 946 952 fat_bs_t *bs; 947 int rc; 948 953 954 /* Accept the mount options */ 955 char *opts; 956 int rc = async_data_write_accept((void **) &opts, true, 0, 0, 0, NULL); 957 958 if (rc != EOK) { 959 async_answer_0(rid, rc); 960 return; 961 } 962 949 963 /* Check for option enabling write through. */ 950 964 if (str_cmp(opts, "wtcache") == 0) … … 953 967 cmode = CACHE_MODE_WB; 954 968 969 free(opts); 970 955 971 /* initialize libblock */ 956 972 rc = block_init(EXCHANGE_SERIALIZE, devmap_handle, BS_SIZE); 957 if (rc != EOK) 958 return rc; 973 if (rc != EOK) { 974 async_answer_0(rid, rc); 975 return; 976 } 959 977 960 978 /* prepare the boot block */ … … 962 980 if (rc != EOK) { 963 981 block_fini(devmap_handle); 964 return rc; 982 async_answer_0(rid, rc); 983 return; 965 984 } 966 985 … … 970 989 if (BPS(bs) != BS_SIZE) { 971 990 block_fini(devmap_handle); 972 return ENOTSUP; 991 async_answer_0(rid, ENOTSUP); 992 return; 973 993 } 974 994 … … 977 997 if (rc != EOK) { 978 998 block_fini(devmap_handle); 979 return rc; 999 async_answer_0(rid, rc); 1000 return; 980 1001 } 981 1002 … … 985 1006 (void) block_cache_fini(devmap_handle); 986 1007 block_fini(devmap_handle); 987 return rc; 1008 async_answer_0(rid, rc); 1009 return; 988 1010 } 989 1011 … … 992 1014 (void) block_cache_fini(devmap_handle); 993 1015 block_fini(devmap_handle); 994 return rc; 1016 async_answer_0(rid, rc); 1017 return; 995 1018 } 996 1019 … … 1001 1024 block_fini(devmap_handle); 1002 1025 fat_idx_fini_by_devmap_handle(devmap_handle); 1003 return ENOMEM; 1026 async_answer_0(rid, ENOMEM); 1027 return; 1004 1028 } 1005 1029 fs_node_initialize(rfn); … … 1010 1034 block_fini(devmap_handle); 1011 1035 fat_idx_fini_by_devmap_handle(devmap_handle); 1012 return ENOMEM; 1036 async_answer_0(rid, ENOMEM); 1037 return; 1013 1038 } 1014 1039 fat_node_initialize(rootp); … … 1021 1046 block_fini(devmap_handle); 1022 1047 fat_idx_fini_by_devmap_handle(devmap_handle); 1023 return ENOMEM; 1048 async_answer_0(rid, ENOMEM); 1049 return; 1024 1050 } 1025 1051 assert(ridxp->index == 0); … … 1038 1064 fibril_mutex_unlock(&ridxp->lock); 1039 1065 1040 *index = ridxp->index; 1041 *size = rootp->size; 1042 *linkcnt = rootp->lnkcnt; 1043 1044 return EOK; 1045 } 1046 1047 static int fat_unmounted(devmap_handle_t devmap_handle) 1048 { 1066 async_answer_3(rid, EOK, ridxp->index, rootp->size, rootp->lnkcnt); 1067 } 1068 1069 void fat_mount(ipc_callid_t rid, ipc_call_t *request) 1070 { 1071 libfs_mount(&fat_libfs_ops, fat_reg.fs_handle, rid, request); 1072 } 1073 1074 void fat_unmounted(ipc_callid_t rid, ipc_call_t *request) 1075 { 1076 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 1049 1077 fs_node_t *fn; 1050 1078 fat_node_t *nodep; … … 1052 1080 1053 1081 rc = fat_root_get(&fn, devmap_handle); 1054 if (rc != EOK) 1055 return rc; 1082 if (rc != EOK) { 1083 async_answer_0(rid, rc); 1084 return; 1085 } 1056 1086 nodep = FAT_NODE(fn); 1057 1087 … … 1062 1092 if (nodep->refcnt != 2) { 1063 1093 (void) fat_node_put(fn); 1064 return EBUSY; 1094 async_answer_0(rid, EBUSY); 1095 return; 1065 1096 } 1066 1097 … … 1081 1112 block_fini(devmap_handle); 1082 1113 1083 return EOK; 1084 } 1085 1086 static int 1087 fat_read(devmap_handle_t devmap_handle, fs_index_t index, aoff64_t pos, 1088 size_t *rbytes) 1089 { 1114 async_answer_0(rid, EOK); 1115 } 1116 1117 void fat_unmount(ipc_callid_t rid, ipc_call_t *request) 1118 { 1119 libfs_unmount(&fat_libfs_ops, rid, request); 1120 } 1121 1122 void fat_lookup(ipc_callid_t rid, ipc_call_t *request) 1123 { 1124 libfs_lookup(&fat_libfs_ops, fat_reg.fs_handle, rid, request); 1125 } 1126 1127 void fat_read(ipc_callid_t rid, ipc_call_t *request) 1128 { 1129 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 1130 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1131 aoff64_t pos = 1132 (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request)); 1090 1133 fs_node_t *fn; 1091 1134 fat_node_t *nodep; … … 1096 1139 1097 1140 rc = fat_node_get(&fn, devmap_handle, index); 1098 if (rc != EOK) 1099 return rc; 1100 if (!fn) 1101 return ENOENT; 1141 if (rc != EOK) { 1142 async_answer_0(rid, rc); 1143 return; 1144 } 1145 if (!fn) { 1146 async_answer_0(rid, ENOENT); 1147 return; 1148 } 1102 1149 nodep = FAT_NODE(fn); 1103 1150 … … 1107 1154 fat_node_put(fn); 1108 1155 async_answer_0(callid, EINVAL); 1109 return EINVAL; 1156 async_answer_0(rid, EINVAL); 1157 return; 1110 1158 } 1111 1159 … … 1130 1178 fat_node_put(fn); 1131 1179 async_answer_0(callid, rc); 1132 return rc; 1180 async_answer_0(rid, rc); 1181 return; 1133 1182 } 1134 1183 (void) async_data_read_finalize(callid, … … 1137 1186 if (rc != EOK) { 1138 1187 fat_node_put(fn); 1139 return rc; 1188 async_answer_0(rid, rc); 1189 return; 1140 1190 } 1141 1191 } … … 1194 1244 rc = fat_node_put(fn); 1195 1245 async_answer_0(callid, rc != EOK ? rc : ENOENT); 1196 *rbytes = 0;1197 return rc != EOK ? rc : ENOENT;1246 async_answer_1(rid, rc != EOK ? rc : ENOENT, 0); 1247 return; 1198 1248 1199 1249 err: 1200 1250 (void) fat_node_put(fn); 1201 1251 async_answer_0(callid, rc); 1202 return rc; 1252 async_answer_0(rid, rc); 1253 return; 1203 1254 1204 1255 hit: … … 1208 1259 1209 1260 rc = fat_node_put(fn); 1210 *rbytes = bytes; 1211 return rc; 1212 } 1213 1214 static int 1215 fat_write(devmap_handle_t devmap_handle, fs_index_t index, aoff64_t pos, 1216 size_t *wbytes, aoff64_t *nsize) 1217 { 1261 async_answer_1(rid, rc, (sysarg_t)bytes); 1262 } 1263 1264 void fat_write(ipc_callid_t rid, ipc_call_t *request) 1265 { 1266 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 1267 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1268 aoff64_t pos = 1269 (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request)); 1218 1270 fs_node_t *fn; 1219 1271 fat_node_t *nodep; 1220 1272 fat_bs_t *bs; 1221 size_t bytes ;1273 size_t bytes, size; 1222 1274 block_t *b; 1223 1275 aoff64_t boundary; … … 1226 1278 1227 1279 rc = fat_node_get(&fn, devmap_handle, index); 1228 if (rc != EOK) 1229 return rc; 1230 if (!fn) 1231 return ENOENT; 1280 if (rc != EOK) { 1281 async_answer_0(rid, rc); 1282 return; 1283 } 1284 if (!fn) { 1285 async_answer_0(rid, ENOENT); 1286 return; 1287 } 1232 1288 nodep = FAT_NODE(fn); 1233 1289 … … 1237 1293 (void) fat_node_put(fn); 1238 1294 async_answer_0(callid, EINVAL); 1239 return EINVAL; 1295 async_answer_0(rid, EINVAL); 1296 return; 1240 1297 } 1241 1298 … … 1265 1322 (void) fat_node_put(fn); 1266 1323 async_answer_0(callid, rc); 1267 return rc; 1324 async_answer_0(rid, rc); 1325 return; 1268 1326 } 1269 1327 rc = fat_block_get(&b, bs, nodep, pos / BPS(bs), flags); … … 1271 1329 (void) fat_node_put(fn); 1272 1330 async_answer_0(callid, rc); 1273 return rc; 1331 async_answer_0(rid, rc); 1332 return; 1274 1333 } 1275 1334 (void) async_data_write_finalize(callid, … … 1279 1338 if (rc != EOK) { 1280 1339 (void) fat_node_put(fn); 1281 return rc; 1340 async_answer_0(rid, rc); 1341 return; 1282 1342 } 1283 1343 if (pos + bytes > nodep->size) { … … 1285 1345 nodep->dirty = true; /* need to sync node */ 1286 1346 } 1287 *wbytes = bytes; 1288 *nsize = nodep->size; 1347 size = nodep->size; 1289 1348 rc = fat_node_put(fn); 1290 return rc; 1349 async_answer_2(rid, rc, bytes, nodep->size); 1350 return; 1291 1351 } else { 1292 1352 /* … … 1304 1364 (void) fat_node_put(fn); 1305 1365 async_answer_0(callid, rc); 1306 return rc; 1366 async_answer_0(rid, rc); 1367 return; 1307 1368 } 1308 1369 /* zero fill any gaps */ … … 1312 1373 (void) fat_node_put(fn); 1313 1374 async_answer_0(callid, rc); 1314 return rc; 1375 async_answer_0(rid, rc); 1376 return; 1315 1377 } 1316 1378 rc = _fat_block_get(&b, bs, devmap_handle, lcl, NULL, … … 1320 1382 (void) fat_node_put(fn); 1321 1383 async_answer_0(callid, rc); 1322 return rc; 1384 async_answer_0(rid, rc); 1385 return; 1323 1386 } 1324 1387 (void) async_data_write_finalize(callid, … … 1329 1392 (void) fat_free_clusters(bs, devmap_handle, mcl); 1330 1393 (void) fat_node_put(fn); 1331 return rc; 1394 async_answer_0(rid, rc); 1395 return; 1332 1396 } 1333 1397 /* … … 1339 1403 (void) fat_free_clusters(bs, devmap_handle, mcl); 1340 1404 (void) fat_node_put(fn); 1341 return rc; 1342 } 1343 *nsize = nodep->size = pos + bytes; 1405 async_answer_0(rid, rc); 1406 return; 1407 } 1408 nodep->size = size = pos + bytes; 1409 nodep->dirty = true; /* need to sync node */ 1344 1410 rc = fat_node_put(fn); 1345 nodep->dirty = true; /* need to sync node */ 1346 *wbytes = bytes; 1347 return rc; 1348 } 1349 } 1350 1351 static int 1352 fat_truncate(devmap_handle_t devmap_handle, fs_index_t index, aoff64_t size) 1353 { 1411 async_answer_2(rid, rc, bytes, size); 1412 return; 1413 } 1414 } 1415 1416 void fat_truncate(ipc_callid_t rid, ipc_call_t *request) 1417 { 1418 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 1419 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1420 aoff64_t size = 1421 (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request)); 1354 1422 fs_node_t *fn; 1355 1423 fat_node_t *nodep; … … 1358 1426 1359 1427 rc = fat_node_get(&fn, devmap_handle, index); 1360 if (rc != EOK) 1361 return rc; 1362 if (!fn) 1363 return ENOENT; 1428 if (rc != EOK) { 1429 async_answer_0(rid, rc); 1430 return; 1431 } 1432 if (!fn) { 1433 async_answer_0(rid, ENOENT); 1434 return; 1435 } 1364 1436 nodep = FAT_NODE(fn); 1365 1437 … … 1405 1477 out: 1406 1478 fat_node_put(fn); 1407 return rc; 1408 } 1409 1410 static int fat_close(devmap_handle_t devmap_handle, fs_index_t index) 1411 { 1412 return EOK; 1413 } 1414 1415 static int fat_destroy(devmap_handle_t devmap_handle, fs_index_t index) 1416 { 1479 async_answer_0(rid, rc); 1480 return; 1481 } 1482 1483 void fat_close(ipc_callid_t rid, ipc_call_t *request) 1484 { 1485 async_answer_0(rid, EOK); 1486 } 1487 1488 void fat_destroy(ipc_callid_t rid, ipc_call_t *request) 1489 { 1490 devmap_handle_t devmap_handle = (devmap_handle_t)IPC_GET_ARG1(*request); 1491 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 1417 1492 fs_node_t *fn; 1418 1493 fat_node_t *nodep; … … 1420 1495 1421 1496 rc = fat_node_get(&fn, devmap_handle, index); 1422 if (rc != EOK) 1423 return rc; 1424 if (!fn) 1425 return ENOENT; 1497 if (rc != EOK) { 1498 async_answer_0(rid, rc); 1499 return; 1500 } 1501 if (!fn) { 1502 async_answer_0(rid, ENOENT); 1503 return; 1504 } 1426 1505 1427 1506 nodep = FAT_NODE(fn); … … 1433 1512 1434 1513 rc = fat_destroy_node(fn); 1435 return rc; 1436 } 1437 1438 static int fat_sync(devmap_handle_t devmap_handle, fs_index_t index) 1439 { 1514 async_answer_0(rid, rc); 1515 } 1516 1517 void fat_open_node(ipc_callid_t rid, ipc_call_t *request) 1518 { 1519 libfs_open_node(&fat_libfs_ops, fat_reg.fs_handle, rid, request); 1520 } 1521 1522 void fat_stat(ipc_callid_t rid, ipc_call_t *request) 1523 { 1524 libfs_stat(&fat_libfs_ops, fat_reg.fs_handle, rid, request); 1525 } 1526 1527 void fat_sync(ipc_callid_t rid, ipc_call_t *request) 1528 { 1529 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 1530 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1531 1440 1532 fs_node_t *fn; 1441 1533 int rc = fat_node_get(&fn, devmap_handle, index); 1442 if (rc != EOK) 1443 return rc; 1444 if (!fn) 1445 return ENOENT; 1534 if (rc != EOK) { 1535 async_answer_0(rid, rc); 1536 return; 1537 } 1538 if (!fn) { 1539 async_answer_0(rid, ENOENT); 1540 return; 1541 } 1446 1542 1447 1543 fat_node_t *nodep = FAT_NODE(fn); … … 1451 1547 1452 1548 fat_node_put(fn); 1453 return rc; 1454 } 1455 1456 vfs_out_ops_t fat_ops = { 1457 .mounted = fat_mounted, 1458 .unmounted = fat_unmounted, 1459 .read = fat_read, 1460 .write = fat_write, 1461 .truncate = fat_truncate, 1462 .close = fat_close, 1463 .destroy = fat_destroy, 1464 .sync = fat_sync, 1465 }; 1549 async_answer_0(rid, rc); 1550 } 1466 1551 1467 1552 /**
Note:
See TracChangeset
for help on using the changeset viewer.