Changeset 8565a42 in mainline for uspace/srv/vfs


Ignore:
Timestamp:
2018-03-02T20:34:50Z (7 years ago)
Author:
GitHub <noreply@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a1a81f69, d5e5fd1
Parents:
3061bc1 (diff), 34e1206 (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.
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:34:50)
git-committer:
GitHub <noreply@…> (2018-03-02 20:34:50)
Message:

Remove all trailing whitespace, everywhere.

See individual commit messages for details.

Location:
uspace/srv/vfs
Files:
8 edited

Legend:

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

    r3061bc1 r8565a42  
    6262                ipc_call_t call;
    6363                ipc_callid_t callid = async_get_call(&call);
    64                
     64
    6565                if (!IPC_GET_IMETHOD(call))
    6666                        break;
    67                
     67
    6868                switch (IPC_GET_IMETHOD(call)) {
    6969                case IPC_M_PAGE_IN:
     
    9191
    9292        printf("%s: HelenOS VFS server\n", NAME);
    93        
     93
    9494        /*
    9595         * Initialize VFS node hash table.
     
    100100                return ENOMEM;
    101101        }
    102        
     102
    103103        /*
    104104         * Allocate and initialize the Path Lookup Buffer.
     
    111111        }
    112112        memset(plb, 0, PLB_SIZE);
    113        
     113
    114114        /*
    115115         * Set client data constructor and destructor.
     
    138138        async_event_task_subscribe(EVENT_TASK_STATE_CHANGE, notification_handler,
    139139            NULL);
    140        
     140
    141141        /*
    142142         * Register at the naming service.
     
    147147                return rc;
    148148        }
    149        
     149
    150150        /*
    151151         * Start accepting connections.
  • uspace/srv/vfs/vfs.h

    r3061bc1 r8565a42  
    110110         */
    111111        unsigned refcnt;
    112        
     112
    113113        ht_link_t nh_link;              /**< Node hash-table link. */
    114114
     
    121121         */
    122122        fibril_rwlock_t contents_rwlock;
    123        
     123
    124124        struct _vfs_node *mount;
    125125} vfs_node_t;
     
    134134
    135135        vfs_node_t *node;
    136        
     136
    137137        /** Number of file handles referencing this file. */
    138138        unsigned refcnt;
  • uspace/srv/vfs/vfs_file.c

    r3061bc1 r8565a42  
    9494                        (void) _vfs_fd_free(vfs_data, i);
    9595        }
    96        
     96
    9797        free(vfs_data->files);
    9898
     
    100100                link_t *lnk;
    101101                vfs_boxed_handle_t *bh;
    102                
     102
    103103                lnk = list_first(&vfs_data->passed_handles);
    104104                list_remove(lnk);
     
    120120                vfs_data->files = NULL;
    121121        }
    122        
     122
    123123        return vfs_data;
    124124}
     
    136136{
    137137        assert(!file->refcnt);
    138        
     138
    139139        async_exch_t *exch = vfs_exchange_grab(file->node->fs_handle);
    140        
     140
    141141        ipc_call_t answer;
    142142        aid_t msg = async_send_2(exch, VFS_OUT_CLOSE, file->node->service_id,
    143143            file->node->index, &answer);
    144        
     144
    145145        vfs_exchange_release(exch);
    146        
     146
    147147        errno_t rc;
    148148        async_wait_for(msg, &rc);
    149        
     149
    150150        return IPC_GET_RETVAL(answer);
    151151}
     
    179179                 * endpoint FS and drop our reference to the underlying VFS node.
    180180                 */
    181                
     181
    182182                if (file->node != NULL) {
    183183                        if (file->open_read || file->open_write) {
     
    196196        if (!vfs_files_init(vfs_data))
    197197                return ENOMEM;
    198        
     198
    199199        unsigned int i;
    200200        if (desc)
     
    202202        else
    203203                i = 0;
    204        
     204
    205205        fibril_mutex_lock(&vfs_data->lock);
    206206        while (true) {
     
    211211                                return ENOMEM;
    212212                        }
    213                        
    214                        
     213
     214
    215215                        memset(vfs_data->files[i], 0, sizeof(vfs_file_t));
    216                        
     216
    217217                        fibril_mutex_initialize(&vfs_data->files[i]->_lock);
    218218                        fibril_mutex_lock(&vfs_data->files[i]->_lock);
    219219                        vfs_file_addref(vfs_data, vfs_data->files[i]);
    220                        
     220
    221221                        *file = vfs_data->files[i];
    222222                        vfs_file_addref(vfs_data, *file);
    223                        
     223
    224224                        fibril_mutex_unlock(&vfs_data->lock);
    225225                        *out_fd = (int) i;
    226226                        return EOK;
    227227                }
    228                
     228
    229229                if (desc) {
    230230                        if (i == 0)
    231231                                break;
    232                        
     232
    233233                        i--;
    234234                } else {
    235235                        if (i == MAX_OPEN_FILES - 1)
    236236                                break;
    237                        
     237
    238238                        i++;
    239239                }
    240240        }
    241241        fibril_mutex_unlock(&vfs_data->lock);
    242        
     242
    243243        return EMFILE;
    244244}
     
    280280        rc = _vfs_fd_free_locked(vfs_data, fd);
    281281        fibril_mutex_unlock(&vfs_data->lock);
    282        
     282
    283283        return rc;
    284284}
     
    319319        (void) _vfs_fd_free_locked(VFS_DATA, fd);
    320320        assert(FILES[fd] == NULL);
    321        
     321
    322322        FILES[fd] = file;
    323323        vfs_file_addref(VFS_DATA, FILES[fd]);
    324324        fibril_mutex_unlock(&VFS_DATA->lock);
    325        
     325
    326326        return EOK;
    327327}
     
    330330{
    331331        fibril_mutex_unlock(&file->_lock);
    332        
     332
    333333        fibril_mutex_lock(&vfs_data->lock);
    334334        vfs_file_delref(vfs_data, file);
     
    340340        if (!vfs_files_init(vfs_data))
    341341                return NULL;
    342        
     342
    343343        fibril_mutex_lock(&vfs_data->lock);
    344344        if ((fd >= 0) && (fd < MAX_OPEN_FILES)) {
     
    347347                        vfs_file_addref(vfs_data, file);
    348348                        fibril_mutex_unlock(&vfs_data->lock);
    349                        
     349
    350350                        fibril_mutex_lock(&file->_lock);
    351351                        if (file->node == NULL) {
     
    359359        }
    360360        fibril_mutex_unlock(&vfs_data->lock);
    361        
     361
    362362        return NULL;
    363363}
     
    432432{
    433433        vfs_client_data_t *vfs_data = VFS_DATA;
    434        
     434
    435435        fibril_mutex_lock(&vfs_data->lock);
    436436        while (list_empty(&vfs_data->passed_handles))
     
    449449                return rc;
    450450        }
    451        
     451
    452452        file->node = bh->node;
    453453        file->permissions = bh->permissions;
  • uspace/srv/vfs/vfs_ipc.c

    r3061bc1 r8565a42  
    4040        int newfd = IPC_GET_ARG2(*request);
    4141        bool desc = IPC_GET_ARG3(*request);
    42        
     42
    4343        int outfd = -1;
    4444        errno_t rc = vfs_op_clone(oldfd, newfd, desc, &outfd);
     
    5454        size_t len;
    5555        errno_t rc;
    56        
     56
    5757        /*
    5858         * Now we expect the client to send us data with the name of the file
     
    6565                return;
    6666        }
    67        
     67
    6868        rc = vfs_op_fsprobe(fs_name, service_id, &info);
    6969        async_answer_0(rid, rc);
    7070        if (rc != EOK)
    7171                goto out;
    72        
     72
    7373        /* Now we should get a read request */
    7474        if (!async_data_read_receive(&callid, &len))
     
    114114{
    115115        int mpfd = IPC_GET_ARG1(*request);
    116        
     116
    117117        /*
    118118         * We expect the library to do the device-name to device-handle
     
    121121         */
    122122        service_id_t service_id = (service_id_t) IPC_GET_ARG2(*request);
    123        
     123
    124124        unsigned int flags = (unsigned int) IPC_GET_ARG3(*request);
    125125        unsigned int instance = IPC_GET_ARG4(*request);
    126        
     126
    127127        char *opts = NULL;
    128128        char *fs_name = NULL;
    129        
     129
    130130        /* Now we expect to receive the mount options. */
    131131        errno_t rc = async_data_write_accept((void **) &opts, true, 0,
     
    135135                return;
    136136        }
    137        
     137
    138138        /* Now, we expect the client to send us data with the name of the file
    139139         * system.
     
    146146                return;
    147147        }
    148        
     148
    149149        int outfd = 0;
    150150        rc = vfs_op_mount(mpfd, service_id, flags, instance, opts, fs_name,
    151151             &outfd);
    152152        async_answer_1(rid, rc, outfd);
    153        
     153
    154154        free(opts);
    155155        free(fs_name);
     
    190190        char *new = NULL;
    191191        errno_t rc;
    192        
     192
    193193        basefd = IPC_GET_ARG1(*request);
    194        
     194
    195195        /* Retrieve the old path. */
    196196        rc = async_data_write_accept((void **) &old, true, 0, 0, 0, NULL);
    197197        if (rc != EOK)
    198198                goto out;
    199        
     199
    200200        /* Retrieve the new path. */
    201201        rc = async_data_write_accept((void **) &new, true, 0, 0, 0, NULL);
    202202        if (rc != EOK)
    203203                goto out;
    204        
     204
    205205        size_t olen;
    206206        size_t nlen;
    207207        char *oldc = canonify(old, &olen);
    208208        char *newc = canonify(new, &nlen);
    209        
     209
    210210        if ((!oldc) || (!newc)) {
    211211                rc = EINVAL;
    212212                goto out;
    213213        }
    214        
     214
    215215        assert(oldc[olen] == '\0');
    216216        assert(newc[nlen] == '\0');
    217        
     217
    218218        rc = vfs_op_rename(basefd, oldc, newc);
    219219
     
    245245{
    246246        int fd = (int) IPC_GET_ARG1(*request);
    247        
     247
    248248        errno_t rc = vfs_op_statfs(fd);
    249249        async_answer_0(rid, rc);
     
    261261        int parentfd = IPC_GET_ARG1(*request);
    262262        int expectfd = IPC_GET_ARG2(*request);
    263        
     263
    264264        char *path;
    265265        errno_t rc = async_data_write_accept((void **) &path, true, 0, 0, 0, NULL);
    266266        if (rc == EOK)
    267267                rc = vfs_op_unlink(parentfd, expectfd, path);
    268        
     268
    269269        async_answer_0(rid, rc);
    270270}
     
    293293        int parentfd = IPC_GET_ARG1(*request);
    294294        int flags = IPC_GET_ARG2(*request);
    295        
     295
    296296        int fd = 0;
    297297        char *path;
     
    318318{
    319319        bool cont = true;
    320        
     320
    321321        /*
    322322         * The connection was opened via the IPC_CONNECT_ME_TO call.
     
    324324         */
    325325        async_answer_0(iid, EOK);
    326        
     326
    327327        while (cont) {
    328328                ipc_call_t call;
    329329                ipc_callid_t callid = async_get_call(&call);
    330                
     330
    331331                if (!IPC_GET_IMETHOD(call))
    332332                        break;
    333                
     333
    334334                switch (IPC_GET_IMETHOD(call)) {
    335335                case VFS_IN_CLONE:
     
    393393                }
    394394        }
    395        
     395
    396396        /*
    397397         * Open files for this client will be cleaned up when its last
  • uspace/srv/vfs/vfs_lookup.c

    r3061bc1 r8565a42  
    108108         */
    109109        list_append(&entry->plb_link, &plb_entries);
    110        
     110
    111111        fibril_mutex_unlock(&plb_mutex);
    112112
     
    116116        size_t cnt1 = min(len, (PLB_SIZE - first) + 1);
    117117        size_t cnt2 = len - cnt1;
    118        
     118
    119119        memcpy(&plb[first], path, cnt1);
    120120        memcpy(plb, &path[cnt1], cnt2);
     
    145145        assert(child->fs_handle);
    146146        assert(path != NULL);
    147        
     147
    148148        vfs_lookup_res_t res;
    149149        char component[NAME_MAX + 1];
    150150        errno_t rc;
    151        
     151
    152152        size_t len;
    153153        char *npath = canonify(path, &len);
     
    157157        }
    158158        path = npath;
    159        
     159
    160160        vfs_triplet_t *triplet;
    161        
     161
    162162        char *slash = str_rchr(path, L'/');
    163163        if (slash && slash != path) {
     
    166166                        goto out;
    167167                }
    168                
     168
    169169                memcpy(component, slash + 1, str_size(slash));
    170170                *slash = 0;
    171                
     171
    172172                rc = vfs_lookup_internal(base, path, L_DIRECTORY, &res);
    173173                if (rc != EOK)
    174174                        goto out;
    175175                triplet = &res.triplet;
    176                
     176
    177177                *slash = '/';
    178178        } else {
     
    181181                        goto out;
    182182                }
    183                
     183
    184184                memcpy(component, path + 1, str_size(path));
    185185                triplet = (vfs_triplet_t *) base;
    186186        }
    187        
     187
    188188        if (triplet->fs_handle != child->fs_handle ||
    189189            triplet->service_id != child->service_id) {
     
    191191                goto out;
    192192        }
    193        
     193
    194194        async_exch_t *exch = vfs_exchange_grab(triplet->fs_handle);
    195195        aid_t req = async_send_3(exch, VFS_OUT_LINK, triplet->service_id,
    196196            triplet->index, child->index, NULL);
    197        
     197
    198198        rc = async_data_write_start(exch, component, str_size(component) + 1);
    199199        errno_t orig_rc;
     
    202202        if (orig_rc != EOK)
    203203                rc = orig_rc;
    204        
     204
    205205out:
    206206        return rc;
     
    212212        assert(base);
    213213        assert(result);
    214        
     214
    215215        errno_t rc;
    216216        ipc_call_t answer;
     
    221221        async_wait_for(req, &rc);
    222222        vfs_exchange_release(exch);
    223        
     223
    224224        if (rc != EOK)
    225225                return rc;
    226        
     226
    227227        unsigned last = *pfirst + *plen;
    228228        *pfirst = IPC_GET_ARG3(answer) & 0xffff;
    229229        *plen = last - *pfirst;
    230        
     230
    231231        result->triplet.fs_handle = (fs_handle_t) IPC_GET_ARG1(answer);
    232232        result->triplet.service_id = base->service_id;
     
    248248        if (rc != EOK)
    249249                return rc;
    250        
     250
    251251        size_t next = first;
    252252        size_t nlen = len;
    253        
     253
    254254        vfs_lookup_res_t res;
    255        
     255
    256256        /* Resolve path as long as there are mount points to cross. */
    257257        while (nlen > 0) {
     
    261261                                goto out;
    262262                        }
    263                        
     263
    264264                        base = base->mount;
    265265                }
    266                
     266
    267267                rc = out_lookup((vfs_triplet_t *) base, &next, &nlen, lflag,
    268268                    &res);
    269269                if (rc != EOK)
    270270                        goto out;
    271                
     271
    272272                if (nlen > 0) {
    273273                        base = vfs_node_peek(&res);
     
    288288                }
    289289        }
    290        
     290
    291291        assert(nlen == 0);
    292292        rc = EOK;
    293        
     293
    294294        if (result != NULL) {
    295295                /* The found file may be a mount point. Try to cross it. */
     
    303303                                        base = nbase;
    304304                                }
    305                                
     305
    306306                                result->triplet = *((vfs_triplet_t *) base);
    307307                                result->type = base->type;
     
    316316                *result = res;
    317317        }
    318        
     318
    319319out:
    320320        plb_clear_entry(&entry, first, len);
     
    339339        assert(base != NULL);
    340340        assert(path != NULL);
    341        
     341
    342342        size_t len;
    343343        errno_t rc;
     
    348348        }
    349349        path = npath;
    350        
     350
    351351        assert(path[0] == '/');
    352352
     
    367367                char *slash = str_rchr(path, L'/');
    368368                vfs_node_t *parent = base;
    369                
     369
    370370                if (slash != path) {
    371371                        int tflag = lflag;
     
    392392                rc = _vfs_lookup_internal(base, path, lflag, result, len);
    393393        }
    394        
     394
    395395        return rc;
    396396}
  • uspace/srv/vfs/vfs_node.c

    r3061bc1 r8565a42  
    108108{
    109109        bool free_node = false;
    110        
    111         fibril_mutex_lock(&nodes_mutex);
    112        
     110
     111        fibril_mutex_lock(&nodes_mutex);
     112
    113113        node->refcnt--;
    114114        if (node->refcnt == 0) {
     
    117117                 * Remove it from the VFS node hash table.
    118118                 */
    119                
     119
    120120                hash_table_remove_item(&nodes, &node->nh_link);
    121121                free_node = true;
    122122        }
    123        
    124         fibril_mutex_unlock(&nodes_mutex);
    125        
     123
     124        fibril_mutex_unlock(&nodes_mutex);
     125
    126126        if (free_node) {
    127127                /*
     
    129129                 * are no more hard links.
    130130                 */
    131                
     131
    132132                async_exch_t *exch = vfs_exchange_grab(node->fs_handle);
    133133                async_msg_2(exch, VFS_OUT_DESTROY, (sysarg_t) node->service_id,
     
    239239            (node->service_id == rd->service_id))
    240240                rd->refcnt += node->refcnt;
    241        
     241
    242242        return true;
    243243}
     
    268268{
    269269        async_exch_t *exch = vfs_exchange_grab(node->fs_handle);
    270        
     270
    271271        ipc_call_t answer;
    272272        aid_t req = async_send_2(exch, VFS_OUT_OPEN_NODE,
    273273            (sysarg_t) node->service_id, (sysarg_t) node->index, &answer);
    274        
     274
    275275        vfs_exchange_release(exch);
    276276
    277277        errno_t rc;
    278278        async_wait_for(req, &rc);
    279        
     279
    280280        return rc;
    281281}
     
    311311                .index = node->index
    312312        };
    313        
     313
    314314        return tri;
    315315}
  • uspace/srv/vfs/vfs_ops.c

    r3061bc1 r8565a42  
    6464{
    6565        size_t res = 0;
    66        
     66
    6767        while (a[res] == b[res] && a[res] != 0)
    6868                res++;
    69        
     69
    7070        if (a[res] == b[res])
    7171                return res;
    72        
     72
    7373        res--;
    7474        while (a[res] != '/')
     
    9393        if (oldfd == newfd)
    9494                return EOK;
    95        
     95
    9696        /* Lookup the file structure corresponding to fd. */
    9797        vfs_file_t *oldfile = vfs_file_get(oldfd);
     
    112112                        newfile->permissions = oldfile->permissions;
    113113                        vfs_node_addref(newfile->node);
    114        
     114
    115115                        vfs_file_put(newfile);
    116116                }
    117117        }
    118118        vfs_file_put(oldfile);
    119        
     119
    120120        return rc;
    121121}
     
    131131{
    132132        fs_handle_t fs_handle = 0;
    133        
     133
    134134        fibril_mutex_lock(&fs_list_lock);
    135135        while (true) {
    136136                fs_handle = fs_name_to_handle(instance, fsname, false);
    137                
     137
    138138                if (fs_handle != 0 || !(flags & VFS_MOUNT_BLOCKING))
    139139                        break;
    140                
     140
    141141                fibril_condvar_wait(&fs_list_cv, &fs_list_lock);
    142142        }
     
    145145        if (fs_handle == 0)
    146146                return ENOFS;
    147        
     147
    148148        /* Tell the mountee that it is being mounted. */
    149149        ipc_call_t answer;
     
    164164                return rc;
    165165        }
    166        
     166
    167167        vfs_lookup_res_t res;
    168168        res.triplet.fs_handle = fs_handle;
     
    172172            IPC_GET_ARG3(answer));
    173173        res.type = VFS_NODE_DIRECTORY;
    174        
     174
    175175        /* Add reference to the mounted root. */
    176176        *root = vfs_node_get(&res);
     
    182182                return ENOMEM;
    183183        }
    184                        
     184
    185185        vfs_exchange_release(exch);
    186186
     
    194194        errno_t rc;
    195195        errno_t retval;
    196        
     196
    197197        fibril_mutex_lock(&fs_list_lock);
    198198        fs_handle = fs_name_to_handle(0, fs_name, false);
    199199        fibril_mutex_unlock(&fs_list_lock);
    200        
     200
    201201        if (fs_handle == 0)
    202202                return ENOFS;
    203        
     203
    204204        /* Send probe request to the file system server */
    205205        ipc_call_t answer;
     
    209209        if (msg == 0)
    210210                return EINVAL;
    211        
     211
    212212        /* Read probe information */
    213213        retval = async_data_read_start(exch, info, sizeof(*info));
     
    216216                return retval;
    217217        }
    218        
     218
    219219        async_wait_for(msg, &rc);
    220220        vfs_exchange_release(exch);
     
    229229        vfs_file_t *file = NULL;
    230230        *out_fd = -1;
    231        
     231
    232232        if (!(flags & VFS_MOUNT_CONNECT_ONLY)) {
    233233                mp = vfs_file_get(mpfd);
     
    236236                        goto out;
    237237                }
    238                
     238
    239239                if (mp->node->mount != NULL) {
    240240                        rc = EBUSY;
    241241                        goto out;
    242242                }
    243                
     243
    244244                if (mp->node->type != VFS_NODE_DIRECTORY) {
    245245                        rc = ENOTDIR;
    246246                        goto out;
    247247                }
    248                
     248
    249249                if (vfs_node_has_children(mp->node)) {
    250250                        rc = ENOTEMPTY;
     
    252252                }
    253253        }
    254        
     254
    255255        if (!(flags & VFS_MOUNT_NO_REF)) {
    256256                rc = vfs_fd_alloc(&file, false, out_fd);
     
    259259                }
    260260        }
    261        
     261
    262262        vfs_node_t *root = NULL;
    263        
     263
    264264        fibril_rwlock_write_lock(&namespace_rwlock);
    265265
     
    271271                mp->node->mount = root;
    272272        }
    273        
     273
    274274        fibril_rwlock_write_unlock(&namespace_rwlock);
    275        
     275
    276276        if (rc != EOK)
    277277                goto out;
    278        
     278
    279279        if (flags & VFS_MOUNT_NO_REF) {
    280280                vfs_node_delref(root);
    281281        } else {
    282282                assert(file != NULL);
    283                
     283
    284284                file->node = root;
    285285                file->permissions = MODE_READ | MODE_WRITE | MODE_APPEND;
     
    287287                file->open_write = false;
    288288        }
    289        
     289
    290290out:
    291291        if (mp)
     
    298298                *out_fd = -1;
    299299        }
    300        
     300
    301301        return rc;
    302302}
     
    310310        if (!file)
    311311                return EBADF;
    312        
     312
    313313        if ((mode & ~file->permissions) != 0) {
    314314                vfs_file_put(file);
    315315                return EPERM;
    316316        }
    317        
     317
    318318        if (file->open_read || file->open_write) {
    319319                vfs_file_put(file);
    320320                return EBUSY;
    321321        }
    322        
     322
    323323        file->open_read = (mode & MODE_READ) != 0;
    324324        file->open_write = (mode & (MODE_WRITE | MODE_APPEND)) != 0;
    325325        file->append = (mode & MODE_APPEND) != 0;
    326        
     326
    327327        if (!file->open_read && !file->open_write) {
    328328                vfs_file_put(file);
    329329                return EINVAL;
    330330        }
    331        
     331
    332332        if (file->node->type == VFS_NODE_DIRECTORY && file->open_write) {
    333333                file->open_read = file->open_write = false;
     
    335335                return EINVAL;
    336336        }
    337        
     337
    338338        errno_t rc = vfs_open_node_remote(file->node);
    339339        if (rc != EOK) {
     
    342342                return rc;
    343343        }
    344        
     344
    345345        vfs_file_put(file);
    346346        return EOK;
     
    385385        if (exch == NULL)
    386386                return ENOENT;
    387        
     387
    388388        aid_t msg = async_send_fast(exch, read ? VFS_OUT_READ : VFS_OUT_WRITE,
    389389            file->node->service_id, file->node->index, LOWER32(pos),
     
    397397                return retval;
    398398        }
    399        
     399
    400400        errno_t rc;
    401401        async_wait_for(msg, &rc);
    402        
     402
    403403        chunk->size = IPC_GET_ARG1(*answer);
    404404
     
    418418         * open files supports parallel access!
    419419         */
    420        
     420
    421421        /* Lookup the file structure corresponding to the file descriptor. */
    422422        vfs_file_t *file = vfs_file_get(fd);
    423423        if (!file)
    424424                return EBADF;
    425        
     425
    426426        if ((read && !file->open_read) || (!read && !file->open_write)) {
    427427                vfs_file_put(file);
    428428                return EINVAL;
    429429        }
    430        
     430
    431431        vfs_info_t *fs_info = fs_handle_to_info(file->node->fs_handle);
    432432        assert(fs_info);
    433        
     433
    434434        bool rlock = read ||
    435435            (fs_info->concurrent_read_write && fs_info->write_retains_size);
    436        
     436
    437437        /*
    438438         * Lock the file's node so that no other client can read/write to it at
     
    444444        else
    445445                fibril_rwlock_write_lock(&file->node->contents_rwlock);
    446        
     446
    447447        if (file->node->type == VFS_NODE_DIRECTORY) {
    448448                /*
     
    450450                 * while we are in readdir().
    451451                 */
    452                
     452
    453453                if (!read) {
    454454                        if (rlock) {
     
    462462                        return EINVAL;
    463463                }
    464                
     464
    465465                fibril_rwlock_read_lock(&namespace_rwlock);
    466466        }
    467        
     467
    468468        async_exch_t *fs_exch = vfs_exchange_grab(file->node->fs_handle);
    469        
     469
    470470        if (!read && file->append)
    471471                pos = file->node->size;
    472        
     472
    473473        /*
    474474         * Handle communication with the endpoint FS.
     
    476476        ipc_call_t answer;
    477477        errno_t rc = ipc_cb(fs_exch, file, pos, &answer, read, ipc_cb_data);
    478        
     478
    479479        vfs_exchange_release(fs_exch);
    480        
     480
    481481        if (file->node->type == VFS_NODE_DIRECTORY)
    482482                fibril_rwlock_read_unlock(&namespace_rwlock);
    483        
     483
    484484        /* Unlock the VFS node. */
    485485        if (rlock) {
     
    493493                fibril_rwlock_write_unlock(&file->node->contents_rwlock);
    494494        }
    495        
     495
    496496        vfs_file_put(file);
    497497
     
    518518        vfs_node_addref(base);
    519519        vfs_file_put(base_file);
    520        
     520
    521521        vfs_lookup_res_t base_lr;
    522522        vfs_lookup_res_t old_lr;
    523523        vfs_lookup_res_t new_lr_orig;
    524524        bool orig_unlinked = false;
    525        
     525
    526526        errno_t rc;
    527        
     527
    528528        size_t shared = shared_path(old, new);
    529        
     529
    530530        /* Do not allow one path to be a prefix of the other. */
    531531        if (old[shared] == 0 || new[shared] == 0) {
     
    535535        assert(old[shared] == '/');
    536536        assert(new[shared] == '/');
    537        
     537
    538538        fibril_rwlock_write_lock(&namespace_rwlock);
    539        
     539
    540540        /* Resolve the shared portion of the path first. */
    541541        if (shared != 0) {
     
    547547                        return rc;
    548548                }
    549                
     549
    550550                vfs_node_put(base);
    551551                base = vfs_node_get(&base_lr);
     
    565565                return rc;
    566566        }
    567                
     567
    568568        rc = vfs_lookup_internal(base, new, L_UNLINK | L_DISABLE_MOUNTS,
    569569            &new_lr_orig);
     
    595595                return rc;
    596596        }
    597        
     597
    598598        /* If the node is not held by anyone, try to destroy it. */
    599599        if (orig_unlinked) {
     
    604604                        vfs_node_put(node);
    605605        }
    606        
     606
    607607        vfs_node_put(base);
    608608        fibril_rwlock_write_unlock(&namespace_rwlock);
     
    617617
    618618        fibril_rwlock_write_lock(&file->node->contents_rwlock);
    619        
     619
    620620        errno_t rc = vfs_truncate_internal(file->node->fs_handle,
    621621            file->node->service_id, file->node->index, size);
    622622        if (rc == EOK)
    623623                file->node->size = size;
    624        
     624
    625625        fibril_rwlock_write_unlock(&file->node->contents_rwlock);
    626626        vfs_file_put(file);
     
    640640            node->service_id, node->index, true, 0, NULL);
    641641        vfs_exchange_release(exch);
    642        
     642
    643643        vfs_file_put(file);
    644644        return rc;
     
    667667        if (!file)
    668668                return EBADF;
    669        
     669
    670670        async_exch_t *fs_exch = vfs_exchange_grab(file->node->fs_handle);
    671        
     671
    672672        aid_t msg;
    673673        ipc_call_t answer;
    674674        msg = async_send_2(fs_exch, VFS_OUT_SYNC, file->node->service_id,
    675675            file->node->index, &answer);
    676        
     676
    677677        vfs_exchange_release(fs_exch);
    678        
     678
    679679        errno_t rc;
    680680        async_wait_for(msg, &rc);
    681        
     681
    682682        vfs_file_put(file);
    683683        return rc;
    684        
     684
    685685}
    686686
     
    693693            UPPER32(size));
    694694        vfs_exchange_release(exch);
    695        
     695
    696696        return (errno_t) rc;
    697697}
     
    702702        vfs_file_t *parent = NULL;
    703703        vfs_file_t *expect = NULL;
    704        
     704
    705705        if (parentfd == expectfd)
    706706                return EINVAL;
    707        
     707
    708708        fibril_rwlock_write_lock(&namespace_rwlock);
    709        
     709
    710710        /*
    711711         * Files are retrieved in order of file descriptors, to prevent
     
    719719                }
    720720        }
    721        
     721
    722722        if (expectfd >= 0) {
    723723                expect = vfs_file_get(expectfd);
     
    727727                }
    728728        }
    729        
     729
    730730        if (parentfd > expectfd) {
    731731                parent = vfs_file_get(parentfd);
     
    735735                }
    736736        }
    737        
     737
    738738        assert(parent != NULL);
    739        
     739
    740740        if (expectfd >= 0) {
    741741                vfs_lookup_res_t lr;
     
    743743                if (rc != EOK)
    744744                        goto exit;
    745                
     745
    746746                vfs_node_t *found_node = vfs_node_peek(&lr);
    747747                vfs_node_put(found_node);
     
    750750                        goto exit;
    751751                }
    752                
     752
    753753                vfs_file_put(expect);
    754754                expect = NULL;
    755755        }
    756        
     756
    757757        vfs_lookup_res_t lr;
    758758        rc = vfs_lookup_internal(parent->node, path, L_UNLINK, &lr);
     
    783783        if (mp == NULL)
    784784                return EBADF;
    785        
     785
    786786        if (mp->node->mount == NULL) {
    787787                vfs_file_put(mp);
    788788                return ENOENT;
    789789        }
    790        
     790
    791791        fibril_rwlock_write_lock(&namespace_rwlock);
    792        
     792
    793793        /*
    794794         * Count the total number of references for the mounted file system. We
     
    804804                return EBUSY;
    805805        }
    806        
     806
    807807        async_exch_t *exch = vfs_exchange_grab(mp->node->mount->fs_handle);
    808808        errno_t rc = async_req_1_0(exch, VFS_OUT_UNMOUNTED,
    809809            mp->node->mount->service_id);
    810810        vfs_exchange_release(exch);
    811        
     811
    812812        if (rc != EOK) {
    813813                vfs_file_put(mp);
     
    815815                return rc;
    816816        }
    817        
     817
    818818        vfs_node_forget(mp->node->mount);
    819819        vfs_node_put(mp->node);
    820820        mp->node->mount = NULL;
    821        
     821
    822822        fibril_rwlock_write_unlock(&namespace_rwlock);
    823        
     823
    824824        vfs_file_put(mp);
    825825        return EOK;
     
    866866        if (!walk_flags_valid(flags))
    867867                return EINVAL;
    868        
     868
    869869        vfs_file_t *parent = vfs_file_get(parentfd);
    870870        if (!parent)
    871871                return EBADF;
    872        
     872
    873873        fibril_rwlock_read_lock(&namespace_rwlock);
    874        
     874
    875875        vfs_lookup_res_t lr;
    876876        errno_t rc = vfs_lookup_internal(parent->node, path,
     
    881881                return rc;
    882882        }
    883        
     883
    884884        vfs_node_t *node = vfs_node_get(&lr);
    885885        if (!node) {
     
    888888                return ENOMEM;
    889889        }
    890        
     890
    891891        vfs_file_t *file;
    892892        rc = vfs_fd_alloc(&file, false, out_fd);
     
    897897        }
    898898        assert(file != NULL);
    899        
     899
    900900        file->node = node;
    901901        file->permissions = parent->permissions;
    902902        file->open_read = false;
    903903        file->open_write = false;
    904        
     904
    905905        vfs_file_put(file);
    906906        vfs_file_put(parent);
    907        
     907
    908908        fibril_rwlock_read_unlock(&namespace_rwlock);
    909909
  • uspace/srv/vfs/vfs_register.c

    r3061bc1 r8565a42  
    7171{
    7272        int i;
    73        
     73
    7474        /*
    7575         * Check if the name is non-empty and is composed solely of ASCII
     
    8080                return false;
    8181        }
    82        
     82
    8383        for (i = 1; i < FS_NAME_MAXLEN; i++) {
    8484                if (!(islower(info->name[i]) || isdigit(info->name[i])) &&
     
    9393                }
    9494        }
    95        
     95
    9696        /*
    9797         * This check is not redundant. It ensures that the name is
     
    102102                return false;
    103103        }
    104        
     104
    105105        return true;
    106106}
     
    116116        dprintf("Processing VFS_REGISTER request received from %zx.\n",
    117117            request->in_phone_hash);
    118        
     118
    119119        vfs_info_t *vfs_info;
    120120        errno_t rc = async_data_write_accept((void **) &vfs_info, false,
    121121            sizeof(vfs_info_t), sizeof(vfs_info_t), 0, NULL);
    122        
     122
    123123        if (rc != EOK) {
    124124                dprintf("Failed to deliver the VFS info into our AS, rc=%d.\n",
     
    127127                return;
    128128        }
    129        
     129
    130130        /*
    131131         * Allocate and initialize a buffer for the fs_info structure.
     
    137137                return;
    138138        }
    139        
     139
    140140        link_initialize(&fs_info->fs_link);
    141141        fs_info->vfs_info = *vfs_info;
    142142        free(vfs_info);
    143        
     143
    144144        dprintf("VFS info delivered.\n");
    145        
     145
    146146        if (!vfs_info_sane(&fs_info->vfs_info)) {
    147147                free(fs_info);
     
    149149                return;
    150150        }
    151        
     151
    152152        fibril_mutex_lock(&fs_list_lock);
    153        
     153
    154154        /*
    155155         * Check for duplicit registrations.
     
    166166                return;
    167167        }
    168        
     168
    169169        /*
    170170         * Add fs_info to the list of registered FS's.
     
    172172        dprintf("Inserting FS into the list of registered file systems.\n");
    173173        list_append(&fs_info->fs_link, &fs_list);
    174        
     174
    175175        /*
    176176         * Now we want the client to send us the IPC_M_CONNECT_TO_ME call so
     
    187187                return;
    188188        }
    189        
     189
    190190        dprintf("Callback connection to FS created.\n");
    191        
     191
    192192        /*
    193193         * The client will want us to send him the address space area with PLB.
    194194         */
    195        
     195
    196196        size_t size;
    197197        ipc_callid_t callid;
     
    206206                return;
    207207        }
    208        
     208
    209209        /*
    210210         * We can only send the client address space area PLB_SIZE bytes long.
     
    220220                return;
    221221        }
    222        
     222
    223223        /*
    224224         * Commit to read-only sharing the PLB with the client.
     
    226226        (void) async_share_in_finalize(callid, plb,
    227227            AS_AREA_READ | AS_AREA_CACHEABLE);
    228        
     228
    229229        dprintf("Sharing PLB.\n");
    230        
     230
    231231        /*
    232232         * That was it. The FS has been registered.
     
    236236        fs_info->fs_handle = (fs_handle_t) atomic_postinc(&fs_handle_next);
    237237        async_answer_1(rid, EOK, (sysarg_t) fs_info->fs_handle);
    238        
     238
    239239        fibril_condvar_broadcast(&fs_list_cv);
    240240        fibril_mutex_unlock(&fs_list_lock);
    241        
     241
    242242        dprintf("\"%.*s\" filesystem successfully registered, handle=%d.\n",
    243243            FS_NAME_MAXLEN, fs_info->vfs_info.name, fs_info->fs_handle);
     
    260260         */
    261261        fibril_mutex_lock(&fs_list_lock);
    262        
     262
    263263        list_foreach(fs_list, fs_link, fs_info_t, fs) {
    264264                if (fs->fs_handle == handle) {
    265265                        fibril_mutex_unlock(&fs_list_lock);
    266                        
     266
    267267                        assert(fs->sess);
    268268                        async_exch_t *exch = async_exchange_begin(fs->sess);
    269                        
     269
    270270                        assert(exch);
    271271                        return exch;
    272272                }
    273273        }
    274        
     274
    275275        fibril_mutex_unlock(&fs_list_lock);
    276        
     276
    277277        return NULL;
    278278}
     
    300300{
    301301        int handle = 0;
    302        
     302
    303303        if (lock)
    304304                fibril_mutex_lock(&fs_list_lock);
    305        
     305
    306306        list_foreach(fs_list, fs_link, fs_info_t, fs) {
    307307                if (str_cmp(fs->vfs_info.name, name) == 0 &&
     
    311311                }
    312312        }
    313        
     313
    314314        if (lock)
    315315                fibril_mutex_unlock(&fs_list_lock);
    316        
     316
    317317        return handle;
    318318}
     
    328328{
    329329        vfs_info_t *info = NULL;
    330        
     330
    331331        fibril_mutex_lock(&fs_list_lock);
    332332        list_foreach(fs_list, fs_link, fs_info_t, fs) {
     
    337337        }
    338338        fibril_mutex_unlock(&fs_list_lock);
    339        
     339
    340340        return info;
    341341}
     
    355355
    356356        fibril_mutex_lock(&fs_list_lock);
    357        
     357
    358358        size = 0;
    359359        count = 0;
     
    362362                count++;
    363363        }
    364        
     364
    365365        if (size == 0)
    366366                size = 1;
    367        
     367
    368368        fstypes->buf = calloc(1, size);
    369369        if (fstypes->buf == NULL) {
     
    371371                return ENOMEM;
    372372        }
    373        
     373
    374374        fstypes->fstypes = calloc(sizeof(char *), count);
    375375        if (fstypes->fstypes == NULL) {
     
    379379                return ENOMEM;
    380380        }
    381        
     381
    382382        fstypes->size = size;
    383        
     383
    384384        size = 0; count = 0;
    385385        list_foreach(fs_list, fs_link, fs_info_t, fs) {
Note: See TracChangeset for help on using the changeset viewer.