Changeset 696979ce in mainline for uspace/srv


Ignore:
Timestamp:
2010-02-06T10:54:21Z (15 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5bda2f96
Parents:
3f93cdbe (diff), 25e963a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge from mainline.

Location:
uspace/srv
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/clip/clip.c

    r3f93cdbe r696979ce  
    6464                ipc_answer_0(rid, EOK);
    6565                break;
    66         case CLIPBOARD_TAG_BLOB:
    67                 rc = async_data_blob_receive(&data, 0, &size);
     66        case CLIPBOARD_TAG_DATA:
     67                rc = async_data_write_accept((void **) &data, false, 0, 0, 0, &size);
    6868                if (rc != EOK) {
    6969                        ipc_answer_0(rid, rc);
     
    7878                clip_data = data;
    7979                clip_size = size;
    80                 clip_tag = CLIPBOARD_TAG_BLOB;
     80                clip_tag = CLIPBOARD_TAG_DATA;
    8181               
    8282                fibril_mutex_unlock(&clip_mtx);
     
    9797        /* Check for clipboard data tag compatibility */
    9898        switch (IPC_GET_ARG1(*request)) {
    99         case CLIPBOARD_TAG_BLOB:
     99        case CLIPBOARD_TAG_DATA:
    100100                if (!async_data_read_receive(&callid, &size)) {
    101101                        ipc_answer_0(callid, EINVAL);
     
    104104                }
    105105               
    106                 if (clip_tag != CLIPBOARD_TAG_BLOB) {
    107                         /* So far we only understand BLOB */
     106                if (clip_tag != CLIPBOARD_TAG_DATA) {
     107                        /* So far we only understand binary data */
    108108                        ipc_answer_0(callid, EOVERFLOW);
    109109                        ipc_answer_0(rid, EOVERFLOW);
  • uspace/srv/devmap/devmap.c

    r3f93cdbe r696979ce  
    396396         * Get driver name
    397397         */
    398         int rc = async_data_string_receive(&driver->name, DEVMAP_NAME_MAXLEN);
     398        int rc = async_data_write_accept((void **) &driver->name, true, 0,
     399            DEVMAP_NAME_MAXLEN, 0, NULL);
    399400        if (rc != EOK) {
    400401                free(driver);
     
    510511        /* Get fqdn */
    511512        char *fqdn;
    512         int rc = async_data_string_receive(&fqdn, DEVMAP_NAME_MAXLEN);
     513        int rc = async_data_write_accept((void **) &fqdn, true, 0,
     514            DEVMAP_NAME_MAXLEN, 0, NULL);
    513515        if (rc != EOK) {
    514516                free(device);
     
    622624       
    623625        /* Get fqdn */
    624         int rc = async_data_string_receive(&fqdn, DEVMAP_NAME_MAXLEN);
     626        int rc = async_data_write_accept((void **) &fqdn, true, 0,
     627            DEVMAP_NAME_MAXLEN, 0, NULL);
    625628        if (rc != EOK) {
    626629                ipc_answer_0(iid, rc);
     
    683686       
    684687        /* Get device name */
    685         int rc = async_data_string_receive(&name, DEVMAP_NAME_MAXLEN);
     688        int rc = async_data_write_accept((void **) &name, true, 0,
     689            DEVMAP_NAME_MAXLEN, 0, NULL);
    686690        if (rc != EOK) {
    687691                ipc_answer_0(iid, rc);
  • uspace/srv/fs/devfs/devfs_ops.c

    r3f93cdbe r696979ce  
    419419       
    420420        /* Accept the mount options */
    421         ipcarg_t retval = async_data_string_receive(&opts, 0);
     421        ipcarg_t retval = async_data_write_accept((void **) &opts, true, 0, 0,
     422            0, NULL);
    422423        if (retval != EOK) {
    423424                ipc_answer_0(rid, retval);
  • uspace/srv/fs/fat/fat_ops.c

    r3f93cdbe r696979ce  
    974974        uint16_t bps;
    975975        uint16_t rde;
    976         int rc;
    977 
    978         /* accept the mount options */
    979         ipc_callid_t callid;
    980         size_t size;
    981         if (!async_data_write_receive(&callid, &size)) {
    982                 ipc_answer_0(callid, EINVAL);
    983                 ipc_answer_0(rid, EINVAL);
    984                 return;
    985         }
    986         char *opts = malloc(size + 1);
    987         if (!opts) {
    988                 ipc_answer_0(callid, ENOMEM);
    989                 ipc_answer_0(rid, ENOMEM);
    990                 return;
    991         }
    992         ipcarg_t retval = async_data_write_finalize(callid, opts, size);
    993         if (retval != EOK) {
    994                 ipc_answer_0(rid, retval);
    995                 free(opts);
    996                 return;
    997         }
    998         opts[size] = '\0';
     976       
     977        /* Accept the mount options */
     978        char *opts;
     979        int rc = async_data_write_accept((void **) &opts, true, 0, 0, 0, NULL);
     980       
     981        if (rc != EOK) {
     982                ipc_answer_0(rid, rc);
     983                return;
     984        }
    999985
    1000986        /* Check for option enabling write through. */
  • uspace/srv/fs/tmpfs/tmpfs_ops.c

    r3f93cdbe r696979ce  
    443443        fs_node_t *rootfn;
    444444        int rc;
    445 
    446         /* accept the mount options */
    447         ipc_callid_t callid;
    448         size_t size;
    449         if (!async_data_write_receive(&callid, &size)) {
    450                 ipc_answer_0(callid, EINVAL);
    451                 ipc_answer_0(rid, EINVAL);
    452                 return;
    453         }
    454         char *opts = malloc(size + 1);
    455         if (!opts) {
    456                 ipc_answer_0(callid, ENOMEM);
    457                 ipc_answer_0(rid, ENOMEM);
    458                 return;
    459         }
    460         ipcarg_t retval = async_data_write_finalize(callid, opts, size);
    461         if (retval != EOK) {
    462                 ipc_answer_0(rid, retval);
    463                 free(opts);
    464                 return;
    465         }
    466         opts[size] = '\0';
    467 
    468         /*
    469          * Check if this device is not already mounted.
    470          */
     445       
     446        /* Accept the mount options. */
     447        char *opts;
     448        rc = async_data_write_accept((void **) &opts, true, 0, 0, 0, NULL);
     449        if (rc != EOK) {
     450                ipc_answer_0(rid, rc);
     451                return;
     452        }
     453
     454        /* Check if this device is not already mounted. */
    471455        rc = tmpfs_root_get(&rootfn, dev_handle);
    472456        if ((rc == EOK) && (rootfn)) {
  • uspace/srv/hid/console/console.c

    r3f93cdbe r696979ce  
    475475static void cons_write(console_t *cons, ipc_callid_t rid, ipc_call_t *request)
    476476{
    477         ipc_callid_t callid;
     477        void *buf;
    478478        size_t size;
    479         if (!async_data_write_receive(&callid, &size)) {
    480                 ipc_answer_0(callid, EINVAL);
    481                 ipc_answer_0(rid, EINVAL);
     479        int rc = async_data_write_accept(&buf, false, 0, 0, 0, &size);
     480       
     481        if (rc != EOK) {
     482                ipc_answer_0(rid, rc);
    482483                return;
    483484        }
    484        
    485         char *buf = (char *) malloc(size);
    486         if (buf == NULL) {
    487                 ipc_answer_0(callid, ENOMEM);
    488                 ipc_answer_0(rid, ENOMEM);
    489                 return;
    490         }
    491        
    492         (void) async_data_write_finalize(callid, buf, size);
    493485       
    494486        async_serialize_start();
  • uspace/srv/loader/main.c

    r3f93cdbe r696979ce  
    125125static void ldr_set_cwd(ipc_callid_t rid, ipc_call_t *request)
    126126{
    127         ipc_callid_t callid;
    128         size_t len;
    129        
    130         if (!async_data_write_receive(&callid, &len)) {
    131                 ipc_answer_0(callid, EINVAL);
    132                 ipc_answer_0(rid, EINVAL);
    133                 return;
    134         }
    135        
    136         cwd = malloc(len + 1);
    137         if (!cwd) {
    138                 ipc_answer_0(callid, ENOMEM);
    139                 ipc_answer_0(rid, ENOMEM);
    140                 return;
    141         }
    142        
    143         async_data_write_finalize(callid, cwd, len);
    144         cwd[len] = '\0';
    145        
    146         ipc_answer_0(rid, EOK);
     127        char *buf;
     128        int rc = async_data_write_accept((void **) &buf, true, 0, 0, 0, NULL);
     129       
     130        if (rc == EOK) {
     131                if (cwd != NULL)
     132                        free(cwd);
     133               
     134                cwd = buf;
     135        }
     136       
     137        ipc_answer_0(rid, rc);
    147138}
    148139
     
    154145static void ldr_set_pathname(ipc_callid_t rid, ipc_call_t *request)
    155146{
    156         ipc_callid_t callid;
    157         size_t len;
    158         char *name_buf;
    159        
    160         if (!async_data_write_receive(&callid, &len)) {
    161                 ipc_answer_0(callid, EINVAL);
    162                 ipc_answer_0(rid, EINVAL);
    163                 return;
    164         }
    165        
    166         name_buf = malloc(len + 1);
    167         if (!name_buf) {
    168                 ipc_answer_0(callid, ENOMEM);
    169                 ipc_answer_0(rid, ENOMEM);
    170                 return;
    171         }
    172        
    173         async_data_write_finalize(callid, name_buf, len);
    174         ipc_answer_0(rid, EOK);
    175        
    176         if (pathname != NULL) {
    177                 free(pathname);
    178                 pathname = NULL;
    179         }
    180        
    181         name_buf[len] = '\0';
    182         pathname = name_buf;
     147        char *buf;
     148        int rc = async_data_write_accept((void **) &buf, true, 0, 0, 0, NULL);
     149       
     150        if (rc == EOK) {
     151                if (pathname != NULL)
     152                        free(pathname);
     153               
     154                pathname = buf;
     155        }
     156       
     157        ipc_answer_0(rid, rc);
    183158}
    184159
     
    190165static void ldr_set_args(ipc_callid_t rid, ipc_call_t *request)
    191166{
    192         ipc_callid_t callid;
    193         size_t buf_size, arg_size;
    194         char *p;
    195         int n;
    196        
    197         if (!async_data_write_receive(&callid, &buf_size)) {
    198                 ipc_answer_0(callid, EINVAL);
    199                 ipc_answer_0(rid, EINVAL);
    200                 return;
    201         }
    202        
    203         if (arg_buf != NULL) {
    204                 free(arg_buf);
    205                 arg_buf = NULL;
    206         }
    207        
    208         if (argv != NULL) {
    209                 free(argv);
    210                 argv = NULL;
    211         }
    212        
    213         arg_buf = malloc(buf_size + 1);
    214         if (!arg_buf) {
    215                 ipc_answer_0(callid, ENOMEM);
    216                 ipc_answer_0(rid, ENOMEM);
    217                 return;
    218         }
    219        
    220         async_data_write_finalize(callid, arg_buf, buf_size);
    221        
    222         arg_buf[buf_size] = '\0';
    223        
    224         /*
    225          * Count number of arguments
    226          */
    227         p = arg_buf;
    228         n = 0;
    229         while (p < arg_buf + buf_size) {
    230                 arg_size = str_size(p);
    231                 p = p + arg_size + 1;
    232                 ++n;
    233         }
    234        
    235         /* Allocate argv */
    236         argv = malloc((n + 1) * sizeof(char *));
    237        
    238         if (argv == NULL) {
    239                 free(arg_buf);
    240                 ipc_answer_0(rid, ENOMEM);
    241                 return;
    242         }
    243 
    244         /*
    245          * Fill argv with argument pointers
    246          */
    247         p = arg_buf;
    248         n = 0;
    249         while (p < arg_buf + buf_size) {
    250                 argv[n] = p;
    251                
    252                 arg_size = str_size(p);
    253                 p = p + arg_size + 1;
    254                 ++n;
    255         }
    256        
    257         argc = n;
    258         argv[n] = NULL;
    259 
    260         ipc_answer_0(rid, EOK);
     167        char *buf;
     168        size_t buf_size;
     169        int rc = async_data_write_accept((void **) &buf, true, 0, 0, 0, &buf_size);
     170       
     171        if (rc == EOK) {
     172                /*
     173                 * Count number of arguments
     174                 */
     175                char *cur = buf;
     176                int count = 0;
     177               
     178                while (cur < buf + buf_size) {
     179                        size_t arg_size = str_size(cur);
     180                        cur += arg_size + 1;
     181                        count++;
     182                }
     183               
     184                /*
     185                 * Allocate new argv
     186                 */
     187                char **_argv = (char **) malloc((count + 1) * sizeof(char *));
     188                if (_argv == NULL) {
     189                        free(buf);
     190                        ipc_answer_0(rid, ENOMEM);
     191                        return;
     192                }
     193               
     194                /*
     195                 * Fill the new argv with argument pointers
     196                 */
     197                cur = buf;
     198                count = 0;
     199                while (cur < buf + buf_size) {
     200                        _argv[count] = cur;
     201                       
     202                        size_t arg_size = str_size(cur);
     203                        cur += arg_size + 1;
     204                        count++;
     205                }
     206                _argv[count] = NULL;
     207               
     208                /*
     209                 * Copy temporary data to global variables
     210                 */
     211                if (arg_buf != NULL)
     212                        free(arg_buf);
     213               
     214                if (argv != NULL)
     215                        free(argv);
     216               
     217                argc = count;
     218                arg_buf = buf;
     219                argv = _argv;
     220        }
     221       
     222        ipc_answer_0(rid, rc);
    261223}
    262224
     
    268230static void ldr_set_files(ipc_callid_t rid, ipc_call_t *request)
    269231{
    270         ipc_callid_t callid;
     232        fdi_node_t *buf;
    271233        size_t buf_size;
    272         if (!async_data_write_receive(&callid, &buf_size)) {
    273                 ipc_answer_0(callid, EINVAL);
    274                 ipc_answer_0(rid, EINVAL);
    275                 return;
    276         }
    277        
    278         if ((buf_size % sizeof(fdi_node_t)) != 0) {
    279                 ipc_answer_0(callid, EINVAL);
    280                 ipc_answer_0(rid, EINVAL);
    281                 return;
    282         }
    283        
    284         if (fil_buf != NULL) {
    285                 free(fil_buf);
    286                 fil_buf = NULL;
    287         }
    288        
    289         if (filv != NULL) {
    290                 free(filv);
    291                 filv = NULL;
    292         }
    293        
    294         fil_buf = malloc(buf_size);
    295         if (!fil_buf) {
    296                 ipc_answer_0(callid, ENOMEM);
    297                 ipc_answer_0(rid, ENOMEM);
    298                 return;
    299         }
    300        
    301         async_data_write_finalize(callid, fil_buf, buf_size);
    302        
    303         int count = buf_size / sizeof(fdi_node_t);
    304        
    305         /* Allocate filvv */
    306         filv = malloc((count + 1) * sizeof(fdi_node_t *));
    307        
    308         if (filv == NULL) {
    309                 free(fil_buf);
    310                 ipc_answer_0(rid, ENOMEM);
    311                 return;
    312         }
    313        
    314         /*
    315          * Fill filv with argument pointers
    316          */
    317         int i;
    318         for (i = 0; i < count; i++)
    319                 filv[i] = &fil_buf[i];
    320        
    321         filc = count;
    322         filv[count] = NULL;
     234        int rc = async_data_write_accept((void **) &buf, false, 0, 0,
     235            sizeof(fdi_node_t), &buf_size);
     236       
     237        if (rc == EOK) {
     238                int count = buf_size / sizeof(fdi_node_t);
     239               
     240                /*
     241                 * Allocate new filv
     242                 */
     243                fdi_node_t **_filv = (fdi_node_t *) malloc((count + 1) * sizeof(fdi_node_t *));
     244                if (_filv == NULL) {
     245                        free(buf);
     246                        ipc_answer_0(rid, ENOMEM);
     247                        return;
     248                }
     249               
     250                /*
     251                 * Fill the new filv with argument pointers
     252                 */
     253                int i;
     254                for (i = 0; i < count; i++)
     255                        _filv[i] = &buf[i];
     256               
     257                _filv[count] = NULL;
     258               
     259                /*
     260                 * Copy temporary data to global variables
     261                 */
     262                if (fil_buf != NULL)
     263                        free(fil_buf);
     264               
     265                if (filv != NULL)
     266                        free(filv);
     267               
     268                filc = count;
     269                fil_buf = buf;
     270                filv = _filv;
     271        }
    323272       
    324273        ipc_answer_0(rid, EOK);
  • uspace/srv/vfs/vfs_ops.c

    r3f93cdbe r696979ce  
    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_data_write_accept((void **) &mp, true, 0, MAX_PATH_LEN,
     270            0, NULL);
     271        if (rc != EOK) {
     272                ipc_answer_0(rid, rc);
     273                return;
     274        }
     275       
     276        /* Now we expect to receive the mount options. */
     277        char *opts;
     278        rc = async_data_write_accept((void **) &opts, true, 0, MAX_MNTOPTS_LEN,
     279            0, NULL);
     280        if (rc != EOK) {
    295281                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);
     282                ipc_answer_0(rid, rc);
     283                return;
     284        }
     285       
     286        /*
     287         * Now, we expect the client to send us data with the name of the file
     288         * system.
     289         */
     290        char *fs_name;
     291        rc = async_data_write_accept((void **) &fs_name, true, 0, FS_NAME_MAXLEN,
     292            0, NULL);
     293        if (rc != EOK) {
    329294                free(mp);
    330295                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 
     296                ipc_answer_0(rid, rc);
     297                return;
     298        }
     299       
    382300        /*
    383301         * Wait for IPC_M_PING so that we can return an error if we don't know
     
    385303         */
    386304        ipc_call_t data;
    387         callid = async_get_call(&data);
     305        ipc_callid_t callid = async_get_call(&data);
    388306        if (IPC_GET_METHOD(data) != IPC_M_PING) {
    389307                ipc_answer_0(callid, ENOTSUP);
     
    442360         * Receive the mount point path.
    443361         */
    444         rc = async_data_string_receive(&mp, MAX_PATH_LEN);
     362        rc = async_data_write_accept((void **) &mp, true, 0, MAX_PATH_LEN,
     363            0, NULL);
    445364        if (rc != EOK)
    446365                ipc_answer_0(rid, rc);
     
    606525                lflag |= L_EXCLUSIVE;
    607526       
    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';
     527        char *path;
     528        int rc = async_data_write_accept((void **) &path, true, 0, 0, 0, NULL);
     529        if (rc != EOK) {
     530                ipc_answer_0(rid, rc);
     531                return;
     532        }
    629533       
    630534        /*
     
    894798       
    895799        /*
    896          * Now we need to receive a call with client's
    897          * IPC_M_DATA_READ/IPC_M_DATA_WRITE request.
    898          */
    899         ipc_callid_t callid;
    900         int res;
    901         if (read)
    902                 res = async_data_read_receive(&callid, NULL);
    903         else
    904                 res = async_data_write_receive(&callid, NULL);
    905         if (!res) {
    906                 ipc_answer_0(callid, EINVAL);
    907                 ipc_answer_0(rid, EINVAL);
    908                 return;
    909         }
    910        
    911         /*
    912800         * Lock the open file structure so that no other thread can manipulate
    913801         * the same open file at a time.
     
    933821        }
    934822       
    935         int fs_phone = vfs_grab_phone(file->node->fs_handle);   
    936        
    937         /* Make a VFS_READ/VFS_WRITE request at the destination FS server. */
    938         aid_t msg;
    939         ipc_call_t answer;
    940         if (!read && file->append)
    941                 file->pos = file->node->size;
    942         msg = async_send_3(fs_phone, read ? VFS_OUT_READ : VFS_OUT_WRITE,
    943             file->node->dev_handle, file->node->index, file->pos, &answer);
    944        
    945         /*
    946          * Forward the IPC_M_DATA_READ/IPC_M_DATA_WRITE request to the
     823        int fs_phone = vfs_grab_phone(file->node->fs_handle);
     824       
     825        /*
     826         * Make a VFS_READ/VFS_WRITE request at the destination FS server
     827         * and forward the IPC_M_DATA_READ/IPC_M_DATA_WRITE request to the
    947828         * destination FS server. The call will be routed as if sent by
    948829         * ourselves. Note that call arguments are immutable in this case so we
    949830         * don't have to bother.
    950831         */
    951         ipc_forward_fast(callid, fs_phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME);
    952 
    953         /* Wait for reply from the FS server. */
    954832        ipcarg_t rc;
    955         async_wait_for(msg, &rc);
     833        ipc_call_t answer;
     834        if (read) {
     835                if (file->append)
     836                        file->pos = file->node->size;
     837               
     838                rc = async_data_read_forward_3_1(fs_phone, VFS_OUT_READ,
     839                    file->node->dev_handle, file->node->index, file->pos,
     840                    &answer);
     841        } else {
     842                rc = async_data_write_forward_3_1(fs_phone, VFS_OUT_WRITE,
     843                    file->node->dev_handle, file->node->index, file->pos,
     844                    &answer);
     845        }
    956846       
    957847        vfs_release_phone(fs_phone);
    958848       
    959849        size_t bytes = IPC_GET_ARG1(answer);
    960 
     850       
    961851        if (file->node->type == VFS_NODE_DIRECTORY)
    962852                fibril_rwlock_read_unlock(&namespace_rwlock);
     
    11201010void vfs_stat(ipc_callid_t rid, ipc_call_t *request)
    11211011{
    1122         size_t len;
     1012        char *path;
     1013        int rc = async_data_write_accept((void **) &path, true, 0, 0, 0, NULL);
     1014        if (rc != EOK) {
     1015                ipc_answer_0(rid, rc);
     1016                return;
     1017        }
     1018       
    11231019        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 
    11441020        if (!async_data_read_receive(&callid, NULL)) {
    11451021                free(path);
     
    11871063{
    11881064        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 
     1065       
     1066        char *path;
     1067        int rc = async_data_write_accept((void **) &path, true, 0, 0, 0, NULL);
     1068        if (rc != EOK) {
     1069                ipc_answer_0(rid, rc);
     1070                return;
     1071        }
     1072       
    12121073        /* Ignore mode for now. */
    12131074        (void) mode;
     
    12241085{
    12251086        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';
     1087       
     1088        char *path;
     1089        int rc = async_data_write_accept((void **) &path, true, 0, 0, 0, NULL);
     1090        if (rc != EOK) {
     1091                ipc_answer_0(rid, rc);
     1092                return;
     1093        }
    12481094       
    12491095        fibril_rwlock_write_lock(&namespace_rwlock);
     
    12741120void vfs_rename(ipc_callid_t rid, ipc_call_t *request)
    12751121{
    1276         size_t olen, nlen;
    1277         ipc_callid_t callid;
    1278         int rc;
    1279 
    12801122        /* 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);
     1123        char *old;
     1124        int rc = async_data_write_accept((void **) &old, true, 0, 0, 0, NULL);
     1125        if (rc != EOK) {
     1126                ipc_answer_0(rid, rc);
     1127                return;
     1128        }
     1129       
     1130        /* Retrieve the new path. */
     1131        char *new;
     1132        rc = async_data_write_accept((void **) &new, true, 0, 0, 0, NULL);
     1133        if (rc != EOK) {
    12941134                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 
     1135                ipc_answer_0(rid, rc);
     1136                return;
     1137        }
     1138       
     1139        size_t olen;
     1140        size_t nlen;
    13211141        char *oldc = canonify(old, &olen);
    13221142        char *newc = canonify(new, &nlen);
    1323         if (!oldc || !newc) {
     1143       
     1144        if ((!oldc) || (!newc)) {
    13241145                ipc_answer_0(rid, EINVAL);
    13251146                free(old);
     
    13271148                return;
    13281149        }
     1150       
    13291151        oldc[olen] = '\0';
    13301152        newc[nlen] = '\0';
     1153       
    13311154        if ((!str_lcmp(newc, oldc, str_length(oldc))) &&
    13321155            ((newc[str_length(oldc)] == '/') ||
     
    13491172        vfs_lookup_res_t new_par_lr;
    13501173        fibril_rwlock_write_lock(&namespace_rwlock);
     1174       
    13511175        /* Lookup the node belonging to the old file name. */
    13521176        rc = vfs_lookup_internal(oldc, L_NONE, &old_lr, NULL);
     
    13581182                return;
    13591183        }
     1184       
    13601185        vfs_node_t *old_node = vfs_node_get(&old_lr);
    13611186        if (!old_node) {
     
    13661191                return;
    13671192        }
     1193       
    13681194        /* Determine the path to the parent of the node with the new name. */
    13691195        char *parentc = str_dup(newc);
     
    13751201                return;
    13761202        }
     1203       
    13771204        char *lastsl = str_rchr(parentc + 1, '/');
    13781205        if (lastsl)
     
    13801207        else
    13811208                parentc[1] = '\0';
     1209       
    13821210        /* Lookup parent of the new file name. */
    13831211        rc = vfs_lookup_internal(parentc, L_NONE, &new_par_lr, NULL);
     
    13901218                return;
    13911219        }
     1220       
    13921221        /* Check whether linking to the same file system instance. */
    13931222        if ((old_node->fs_handle != new_par_lr.triplet.fs_handle) ||
     
    13991228                return;
    14001229        }
     1230       
    14011231        /* Destroy the old link for the new name. */
    14021232        vfs_node_t *new_node = NULL;
    14031233        rc = vfs_lookup_internal(newc, L_UNLINK, &new_lr, NULL);
     1234       
    14041235        switch (rc) {
    14051236        case ENOENT:
     
    14261257                return;
    14271258        }
     1259       
    14281260        /* Create the new link for the new name. */
    14291261        rc = vfs_lookup_internal(newc, L_LINK, NULL, NULL, old_node->index);
     
    14371269                return;
    14381270        }
     1271       
    14391272        fibril_mutex_lock(&nodes_mutex);
    14401273        old_node->lnkcnt++;
    14411274        fibril_mutex_unlock(&nodes_mutex);
     1275       
    14421276        /* Destroy the link for the old name. */
    14431277        rc = vfs_lookup_internal(oldc, L_UNLINK, NULL, NULL);
     
    14521286                return;
    14531287        }
     1288       
    14541289        fibril_mutex_lock(&nodes_mutex);
    14551290        old_node->lnkcnt--;
     
    14571292        fibril_rwlock_write_unlock(&namespace_rwlock);
    14581293        vfs_node_put(old_node);
     1294       
    14591295        if (new_node)
    14601296                vfs_node_put(new_node);
     1297       
    14611298        free(old);
    14621299        free(new);
  • uspace/srv/vfs/vfs_register.c

    r3f93cdbe r696979ce  
    110110void vfs_register(ipc_callid_t rid, ipc_call_t *request)
    111111{
    112         ipc_callid_t callid;
    113         ipc_call_t call;
    114         int rc;
    115         size_t size;
    116 
    117112        dprintf("Processing VFS_REGISTER request received from %p.\n",
    118113            request->in_phone_hash);
    119 
    120         /*
    121          * The first call has to be IPC_M_DATA_SEND in which we receive the
    122          * VFS info structure from the client FS.
    123          */
    124         if (!async_data_write_receive(&callid, &size)) {
    125                 /*
    126                  * The client doesn't obey the same protocol as we do.
    127                  */
    128                 dprintf("Receiving of VFS info failed.\n");
    129                 ipc_answer_0(callid, EINVAL);
    130                 ipc_answer_0(rid, EINVAL);
    131                 return;
    132         }
    133        
    134         dprintf("VFS info received, size = %d\n", size);
    135        
    136         /*
    137          * We know the size of the VFS info structure. See if the client
    138          * understands this easy concept too.
    139          */
    140         if (size != sizeof(vfs_info_t)) {
    141                 /*
    142                  * The client is sending us something, which cannot be
    143                  * the info structure.
    144                  */
    145                 dprintf("Received VFS info has bad size.\n");
    146                 ipc_answer_0(callid, EINVAL);
    147                 ipc_answer_0(rid, EINVAL);
    148                 return;
    149         }
    150 
    151         /*
    152          * Allocate and initialize a buffer for the fs_info structure.
    153          */
    154         fs_info_t *fs_info;
    155         fs_info = (fs_info_t *) malloc(sizeof(fs_info_t));
    156         if (!fs_info) {
    157                 dprintf("Could not allocate memory for FS info.\n");
    158                 ipc_answer_0(callid, ENOMEM);
    159                 ipc_answer_0(rid, ENOMEM);
    160                 return;
    161         }
    162         link_initialize(&fs_info->fs_link);
    163         fibril_mutex_initialize(&fs_info->phone_lock);
    164                
    165         rc = async_data_write_finalize(callid, &fs_info->vfs_info, size);
     114       
     115        vfs_info_t *vfs_info;
     116        int rc = async_data_write_accept((void **) &vfs_info, false,
     117            sizeof(vfs_info_t), sizeof(vfs_info_t), 0, NULL);
     118       
    166119        if (rc != EOK) {
    167120                dprintf("Failed to deliver the VFS info into our AS, rc=%d.\n",
    168121                    rc);
    169                 free(fs_info);
    170                 ipc_answer_0(callid, rc);
    171122                ipc_answer_0(rid, rc);
    172123                return;
    173124        }
    174 
     125       
     126        /*
     127         * Allocate and initialize a buffer for the fs_info structure.
     128         */
     129        fs_info_t *fs_info = (fs_info_t *) malloc(sizeof(fs_info_t));
     130        if (!fs_info) {
     131                dprintf("Could not allocate memory for FS info.\n");
     132                ipc_answer_0(rid, ENOMEM);
     133                return;
     134        }
     135       
     136        link_initialize(&fs_info->fs_link);
     137        fibril_mutex_initialize(&fs_info->phone_lock);
     138        fs_info->vfs_info = *vfs_info;
     139        free(vfs_info);
     140       
    175141        dprintf("VFS info delivered.\n");
    176                
     142       
    177143        if (!vfs_info_sane(&fs_info->vfs_info)) {
    178144                free(fs_info);
    179                 ipc_answer_0(callid, EINVAL);
    180145                ipc_answer_0(rid, EINVAL);
    181146                return;
    182147        }
    183                
     148       
    184149        fibril_mutex_lock(&fs_head_lock);
    185 
     150       
    186151        /*
    187152         * Check for duplicit registrations.
     
    194159                fibril_mutex_unlock(&fs_head_lock);
    195160                free(fs_info);
    196                 ipc_answer_0(callid, EEXISTS);
    197161                ipc_answer_0(rid, EEXISTS);
    198162                return;
    199163        }
    200 
     164       
    201165        /*
    202166         * Add fs_info to the list of registered FS's.
     
    210174         * which to forward VFS requests to it.
    211175         */
    212         callid = async_get_call(&call);
     176        ipc_call_t call;
     177        ipc_callid_t callid = async_get_call(&call);
    213178        if (IPC_GET_METHOD(call) != IPC_M_CONNECT_TO_ME) {
    214179                dprintf("Unexpected call, method = %d\n", IPC_GET_METHOD(call));
     
    222187        fs_info->phone = IPC_GET_ARG5(call);
    223188        ipc_answer_0(callid, EOK);
    224 
     189       
    225190        dprintf("Callback connection to FS created.\n");
    226 
     191       
    227192        /*
    228193         * The client will want us to send him the address space area with PLB.
    229194         */
    230 
     195       
     196        size_t size;
    231197        if (!async_share_in_receive(&callid, &size)) {
    232198                dprintf("Unexpected call, method = %d\n", IPC_GET_METHOD(call));
     
    253219                return;
    254220        }
    255 
     221       
    256222        /*
    257223         * Commit to read-only sharing the PLB with the client.
     
    259225        (void) async_share_in_finalize(callid, plb,
    260226            AS_AREA_READ | AS_AREA_CACHEABLE);
    261 
     227       
    262228        dprintf("Sharing PLB.\n");
    263 
     229       
    264230        /*
    265231         * That was it. The FS has been registered.
Note: See TracChangeset for help on using the changeset viewer.