Changeset 472c09d in mainline for uspace/srv/vfs/vfs_ops.c


Ignore:
Timestamp:
2010-02-03T15:18:40Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b4cbef1
Parents:
28be7fa
Message:

more consistent naming scheme:

async_data_blob_receive → async_data_receive
async_data_string_receive → async_string_receive
CLIPBOARD_TAG_BLOB → CLIPBOARD_TAG_DATA

async_data_receive can now check the granularity of the received data
async_string_receive can now return the raw size of the received data

replace several common patterns of async_data_write_receive/_finalize
with a single async_data_receive/_string_receive (this greatly improves
code readability)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/vfs/vfs_ops.c

    r28be7fa r472c09d  
    266266       
    267267        /* 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) {
    295279                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) {
    329291                free(mp);
    330292                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       
    382297        /*
    383298         * Wait for IPC_M_PING so that we can return an error if we don't know
     
    385300         */
    386301        ipc_call_t data;
    387         callid = async_get_call(&data);
     302        ipc_callid_t callid = async_get_call(&data);
    388303        if (IPC_GET_METHOD(data) != IPC_M_PING) {
    389304                ipc_answer_0(callid, ENOTSUP);
     
    442357         * Receive the mount point path.
    443358         */
    444         rc = async_data_string_receive(&mp, MAX_PATH_LEN);
     359        rc = async_string_receive(&mp, MAX_PATH_LEN, NULL);
    445360        if (rc != EOK)
    446361                ipc_answer_0(rid, rc);
     
    606521                lflag |= L_EXCLUSIVE;
    607522       
    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        }
    629529       
    630530        /*
     
    11201020void vfs_stat(ipc_callid_t rid, ipc_call_t *request)
    11211021{
    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       
    11231029        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 
    11441030        if (!async_data_read_receive(&callid, NULL)) {
    11451031                free(path);
     
    11871073{
    11881074        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       
    12121083        /* Ignore mode for now. */
    12131084        (void) mode;
     
    12241095{
    12251096        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        }
    12481104       
    12491105        fibril_rwlock_write_lock(&namespace_rwlock);
     
    12741130void vfs_rename(ipc_callid_t rid, ipc_call_t *request)
    12751131{
    1276         size_t olen, nlen;
    1277         ipc_callid_t callid;
    1278         int rc;
    1279 
    12801132        /* 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) {
    12941144                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;
    13211151        char *oldc = canonify(old, &olen);
    13221152        char *newc = canonify(new, &nlen);
    1323         if (!oldc || !newc) {
     1153       
     1154        if ((!oldc) || (!newc)) {
    13241155                ipc_answer_0(rid, EINVAL);
    13251156                free(old);
     
    13271158                return;
    13281159        }
     1160       
    13291161        oldc[olen] = '\0';
    13301162        newc[nlen] = '\0';
     1163       
    13311164        if ((!str_lcmp(newc, oldc, str_length(oldc))) &&
    13321165            ((newc[str_length(oldc)] == '/') ||
     
    13491182        vfs_lookup_res_t new_par_lr;
    13501183        fibril_rwlock_write_lock(&namespace_rwlock);
     1184       
    13511185        /* Lookup the node belonging to the old file name. */
    13521186        rc = vfs_lookup_internal(oldc, L_NONE, &old_lr, NULL);
     
    13581192                return;
    13591193        }
     1194       
    13601195        vfs_node_t *old_node = vfs_node_get(&old_lr);
    13611196        if (!old_node) {
     
    13661201                return;
    13671202        }
     1203       
    13681204        /* Determine the path to the parent of the node with the new name. */
    13691205        char *parentc = str_dup(newc);
     
    13751211                return;
    13761212        }
     1213       
    13771214        char *lastsl = str_rchr(parentc + 1, '/');
    13781215        if (lastsl)
     
    13801217        else
    13811218                parentc[1] = '\0';
     1219       
    13821220        /* Lookup parent of the new file name. */
    13831221        rc = vfs_lookup_internal(parentc, L_NONE, &new_par_lr, NULL);
     
    13901228                return;
    13911229        }
     1230       
    13921231        /* Check whether linking to the same file system instance. */
    13931232        if ((old_node->fs_handle != new_par_lr.triplet.fs_handle) ||
     
    13991238                return;
    14001239        }
     1240       
    14011241        /* Destroy the old link for the new name. */
    14021242        vfs_node_t *new_node = NULL;
    14031243        rc = vfs_lookup_internal(newc, L_UNLINK, &new_lr, NULL);
     1244       
    14041245        switch (rc) {
    14051246        case ENOENT:
     
    14261267                return;
    14271268        }
     1269       
    14281270        /* Create the new link for the new name. */
    14291271        rc = vfs_lookup_internal(newc, L_LINK, NULL, NULL, old_node->index);
     
    14371279                return;
    14381280        }
     1281       
    14391282        fibril_mutex_lock(&nodes_mutex);
    14401283        old_node->lnkcnt++;
    14411284        fibril_mutex_unlock(&nodes_mutex);
     1285       
    14421286        /* Destroy the link for the old name. */
    14431287        rc = vfs_lookup_internal(oldc, L_UNLINK, NULL, NULL);
     
    14521296                return;
    14531297        }
     1298       
    14541299        fibril_mutex_lock(&nodes_mutex);
    14551300        old_node->lnkcnt--;
     
    14571302        fibril_rwlock_write_unlock(&namespace_rwlock);
    14581303        vfs_node_put(old_node);
     1304       
    14591305        if (new_node)
    14601306                vfs_node_put(new_node);
     1307       
    14611308        free(old);
    14621309        free(new);
Note: See TracChangeset for help on using the changeset viewer.