Changeset a35b458 in mainline for uspace/lib/ext4/src/ops.c


Ignore:
Timestamp:
2018-03-02T20:10:49Z (7 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f1380b7
Parents:
3061bc1
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
Message:

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ext4/src/ops.c

    r3061bc1 ra35b458  
    117117        node_key_t *key = (node_key_t *)key_arg;
    118118        ext4_node_t *enode = hash_table_get_inst(item, ext4_node_t, link);
    119        
     119
    120120        return key->service_id == enode->instance->service_id
    121121                && key->index == enode->inode_ref->index;
     
    142142        if (!hash_table_create(&open_nodes, 0, 0, &open_nodes_ops))
    143143                return ENOMEM;
    144        
     144
    145145        return EOK;
    146146}
     
    173173{
    174174        fibril_mutex_lock(&instance_list_mutex);
    175        
     175
    176176        if (list_empty(&instance_list)) {
    177177                fibril_mutex_unlock(&instance_list_mutex);
    178178                return EINVAL;
    179179        }
    180        
     180
    181181        list_foreach(instance_list, link, ext4_instance_t, tmp) {
    182182                if (tmp->service_id == service_id) {
     
    186186                }
    187187        }
    188        
     188
    189189        fibril_mutex_unlock(&instance_list_mutex);
    190190        return EINVAL;
     
    219219        ext4_node_t *eparent = EXT4_NODE(pfn);
    220220        ext4_filesystem_t *fs = eparent->instance->filesystem;
    221        
     221
    222222        if (!ext4_inode_is_type(fs->superblock, eparent->inode_ref->inode,
    223223            EXT4_INODE_MODE_DIRECTORY))
    224224                return ENOTDIR;
    225        
     225
    226226        /* Try to find entry */
    227227        ext4_directory_search_result_t result;
     
    233233                        return EOK;
    234234                }
    235                
    236                 return rc;
    237         }
    238        
     235
     236                return rc;
     237        }
     238
    239239        /* Load node from search result */
    240240        uint32_t inode = ext4_directory_entry_ll_get_inode(result.dentry);
     
    268268        if (rc != EOK)
    269269                return rc;
    270        
     270
    271271        return ext4_node_get_core(rfn, inst, index);
    272272}
     
    285285{
    286286        fibril_mutex_lock(&open_nodes_lock);
    287        
     287
    288288        /* Check if the node is not already open */
    289289        node_key_t key = {
     
    291291                .index = index
    292292        };
    293        
     293
    294294        ht_link_t *already_open = hash_table_find(&open_nodes, &key);
    295295        ext4_node_t *enode = NULL;
     
    298298                *rfn = enode->fs_node;
    299299                enode->references++;
    300                
     300
    301301                fibril_mutex_unlock(&open_nodes_lock);
    302302                return EOK;
    303303        }
    304        
     304
    305305        /* Prepare new enode */
    306306        enode = malloc(sizeof(ext4_node_t));
     
    309309                return ENOMEM;
    310310        }
    311        
     311
    312312        /* Prepare new fs_node and initialize */
    313313        fs_node_t *fs_node = malloc(sizeof(fs_node_t));
     
    317317                return ENOMEM;
    318318        }
    319        
     319
    320320        fs_node_initialize(fs_node);
    321        
     321
    322322        /* Load i-node from filesystem */
    323323        ext4_inode_ref_t *inode_ref;
     
    330330                return rc;
    331331        }
    332        
     332
    333333        /* Initialize enode */
    334334        enode->inode_ref = inode_ref;
     
    336336        enode->references = 1;
    337337        enode->fs_node = fs_node;
    338        
     338
    339339        fs_node->data = enode;
    340340        *rfn = fs_node;
    341        
     341
    342342        hash_table_insert(&open_nodes, &enode->link);
    343343        inst->open_nodes_count++;
    344        
     344
    345345        fibril_mutex_unlock(&open_nodes_lock);
    346        
     346
    347347        return EOK;
    348348}
     
    360360        assert(enode->instance->open_nodes_count > 0);
    361361        enode->instance->open_nodes_count--;
    362        
     362
    363363        /* Put inode back in filesystem */
    364364        errno_t rc = ext4_filesystem_put_inode_ref(enode->inode_ref);
    365365        if (rc != EOK)
    366366                return rc;
    367        
     367
    368368        /* Destroy data structure */
    369369        free(enode->fs_node);
    370370        free(enode);
    371        
     371
    372372        return EOK;
    373373}
     
    399399{
    400400        fibril_mutex_lock(&open_nodes_lock);
    401        
     401
    402402        ext4_node_t *enode = EXT4_NODE(fn);
    403403        assert(enode->references > 0);
     
    410410                }
    411411        }
    412        
     412
    413413        fibril_mutex_unlock(&open_nodes_lock);
    414        
     414
    415415        return EOK;
    416416}
     
    432432        if (enode == NULL)
    433433                return ENOMEM;
    434        
     434
    435435        /* Allocate fs_node */
    436436        fs_node_t *fs_node;
     
    440440                return ENOMEM;
    441441        }
    442        
     442
    443443        /* Load instance */
    444444        ext4_instance_t *inst;
     
    449449                return rc;
    450450        }
    451        
     451
    452452        /* Allocate new i-node in filesystem */
    453453        ext4_inode_ref_t *inode_ref;
     
    458458                return rc;
    459459        }
    460        
     460
    461461        /* Do some interconnections in references */
    462462        enode->inode_ref = inode_ref;
    463463        enode->instance = inst;
    464464        enode->references = 1;
    465        
     465
    466466        fibril_mutex_lock(&open_nodes_lock);
    467467        hash_table_insert(&open_nodes, &enode->link);
    468468        fibril_mutex_unlock(&open_nodes_lock);
    469469        inst->open_nodes_count++;
    470        
     470
    471471        enode->inode_ref->dirty = true;
    472        
     472
    473473        fs_node_initialize(fs_node);
    474474        fs_node->data = enode;
    475475        enode->fs_node = fs_node;
    476476        *rfn = fs_node;
    477        
     477
    478478        return EOK;
    479479}
     
    495495                return rc;
    496496        }
    497        
     497
    498498        if (has_children) {
    499499                ext4_node_put(fn);
    500500                return EINVAL;
    501501        }
    502        
     502
    503503        ext4_node_t *enode = EXT4_NODE(fn);
    504504        ext4_inode_ref_t *inode_ref = enode->inode_ref;
    505        
     505
    506506        /* Release data blocks */
    507507        rc = ext4_filesystem_truncate_inode(inode_ref, 0);
     
    510510                return rc;
    511511        }
    512        
     512
    513513        /*
    514514         * TODO: Sset real deletion time when it will be supported.
     
    517517        ext4_inode_set_deletion_time(inode_ref->inode, 0xdeadbeef);
    518518        inode_ref->dirty = true;
    519        
     519
    520520        /* Free inode */
    521521        rc = ext4_filesystem_free_inode(inode_ref);
     
    524524                return rc;
    525525        }
    526        
     526
    527527        return ext4_node_put(fn);
    528528}
     
    542542        if (str_size(name) > EXT4_DIRECTORY_FILENAME_LEN)
    543543                return ENAMETOOLONG;
    544        
     544
    545545        ext4_node_t *parent = EXT4_NODE(pfn);
    546546        ext4_node_t *child = EXT4_NODE(cfn);
    547547        ext4_filesystem_t *fs = parent->instance->filesystem;
    548        
     548
    549549        /* Add entry to parent directory */
    550550        errno_t rc = ext4_directory_add_entry(parent->inode_ref, name,
     
    552552        if (rc != EOK)
    553553                return rc;
    554        
     554
    555555        /* Fill new dir -> add '.' and '..' entries */
    556556        if (ext4_inode_is_type(fs->superblock, child->inode_ref->inode,
     
    562562                        return rc;
    563563                }
    564                
     564
    565565                rc = ext4_directory_add_entry(child->inode_ref, "..",
    566566                    parent->inode_ref);
     
    570570                        return rc;
    571571                }
    572                
     572
    573573                /* Initialize directory index if supported */
    574574                if (ext4_superblock_has_feature_compatible(fs->superblock,
     
    577577                        if (rc != EOK)
    578578                                return rc;
    579                        
     579
    580580                        ext4_inode_set_flag(child->inode_ref->inode,
    581581                            EXT4_INODE_FLAG_INDEX);
    582582                        child->inode_ref->dirty = true;
    583583                }
    584        
     584
    585585                uint16_t parent_links =
    586586                    ext4_inode_get_links_count(parent->inode_ref->inode);
    587587                parent_links++;
    588588                ext4_inode_set_links_count(parent->inode_ref->inode, parent_links);
    589                
     589
    590590                parent->inode_ref->dirty = true;
    591591        }
    592        
     592
    593593        uint16_t child_links =
    594594            ext4_inode_get_links_count(child->inode_ref->inode);
    595595        child_links++;
    596596        ext4_inode_set_links_count(child->inode_ref->inode, child_links);
    597        
     597
    598598        child->inode_ref->dirty = true;
    599        
     599
    600600        return EOK;
    601601}
     
    616616        if (rc != EOK)
    617617                return rc;
    618        
     618
    619619        /* Cannot unlink non-empty node */
    620620        if (has_children)
    621621                return ENOTEMPTY;
    622        
     622
    623623        /* Remove entry from parent directory */
    624624        ext4_inode_ref_t *parent = EXT4_NODE(pfn)->inode_ref;
     
    626626        if (rc != EOK)
    627627                return rc;
    628        
     628
    629629        /* Decrement links count */
    630630        ext4_inode_ref_t *child_inode_ref = EXT4_NODE(cfn)->inode_ref;
    631        
     631
    632632        uint32_t lnk_count =
    633633            ext4_inode_get_links_count(child_inode_ref->inode);
    634634        lnk_count--;
    635        
     635
    636636        /* If directory - handle links from parent */
    637637        if ((lnk_count <= 1) && (ext4_is_directory(cfn))) {
    638638                assert(lnk_count == 1);
    639                
     639
    640640                lnk_count--;
    641                
     641
    642642                ext4_inode_ref_t *parent_inode_ref = EXT4_NODE(pfn)->inode_ref;
    643                
     643
    644644                uint32_t parent_lnk_count = ext4_inode_get_links_count(
    645645                    parent_inode_ref->inode);
    646                
     646
    647647                parent_lnk_count--;
    648648                ext4_inode_set_links_count(parent_inode_ref->inode, parent_lnk_count);
    649                
     649
    650650                parent->dirty = true;
    651651        }
     
    659659         * parent->dirty = true;
    660660         */
    661        
     661
    662662        /*
    663663         * TODO: Update timestamp for inode.
     
    666666         *     (uint32_t) now);
    667667         */
    668        
     668
    669669        ext4_inode_set_links_count(child_inode_ref->inode, lnk_count);
    670670        child_inode_ref->dirty = true;
    671        
     671
    672672        return EOK;
    673673}
     
    687687        ext4_node_t *enode = EXT4_NODE(fn);
    688688        ext4_filesystem_t *fs = enode->instance->filesystem;
    689        
     689
    690690        /* Check if node is directory */
    691691        if (!ext4_inode_is_type(fs->superblock, enode->inode_ref->inode,
     
    694694                return EOK;
    695695        }
    696        
     696
    697697        ext4_directory_iterator_t it;
    698698        errno_t rc = ext4_directory_iterator_init(&it, enode->inode_ref, 0);
    699699        if (rc != EOK)
    700700                return rc;
    701        
     701
    702702        /* Find a non-empty directory entry */
    703703        bool found = false;
     
    712712                        }
    713713                }
    714                
     714
    715715                rc = ext4_directory_iterator_next(&it);
    716716                if (rc != EOK) {
     
    719719                }
    720720        }
    721        
     721
    722722        rc = ext4_directory_iterator_fini(&it);
    723723        if (rc != EOK)
    724724                return rc;
    725        
     725
    726726        *has_children = found;
    727        
     727
    728728        return EOK;
    729729}
     
    767767        ext4_node_t *enode = EXT4_NODE(fn);
    768768        uint32_t lnkcnt = ext4_inode_get_links_count(enode->inode_ref->inode);
    769        
     769
    770770        if (ext4_is_directory(fn)) {
    771771                if (lnkcnt > 1)
     
    774774                        return 0;
    775775        }
    776        
     776
    777777        /* For regular files return real links count */
    778778        return lnkcnt;
     
    790790        ext4_node_t *enode = EXT4_NODE(fn);
    791791        ext4_superblock_t *sb = enode->instance->filesystem->superblock;
    792        
     792
    793793        return ext4_inode_is_type(sb, enode->inode_ref->inode,
    794794            EXT4_INODE_MODE_DIRECTORY);
     
    806806        ext4_node_t *enode = EXT4_NODE(fn);
    807807        ext4_superblock_t *sb = enode->instance->filesystem->superblock;
    808        
     808
    809809        return ext4_inode_is_type(sb, enode->inode_ref->inode,
    810810            EXT4_INODE_MODE_FILE);
     
    928928{
    929929        ext4_filesystem_t *fs;
    930        
     930
    931931        /* Allocate instance structure */
    932932        ext4_instance_t *inst = (ext4_instance_t *)
     
    934934        if (inst == NULL)
    935935                return ENOMEM;
    936        
     936
    937937        enum cache_mode cmode;
    938938        if (str_cmp(opts, "wtcache") == 0)
     
    940940        else
    941941                cmode = CACHE_MODE_WB;
    942        
     942
    943943        /* Initialize instance */
    944944        link_initialize(&inst->link);
    945945        inst->service_id = service_id;
    946946        inst->open_nodes_count = 0;
    947        
     947
    948948        /* Initialize the filesystem */
    949949        aoff64_t rnsize;
     
    953953                return rc;
    954954        }
    955        
     955
    956956        /* Add instance to the list */
    957957        fibril_mutex_lock(&instance_list_mutex);
    958958        list_append(&inst->link, &instance_list);
    959959        fibril_mutex_unlock(&instance_list_mutex);
    960        
     960
    961961        *index = EXT4_INODE_ROOT_INDEX;
    962962        *size = rnsize;
    963        
     963
    964964        return EOK;
    965965}
     
    980980        if (rc != EOK)
    981981                return rc;
    982        
     982
    983983        fibril_mutex_lock(&open_nodes_lock);
    984        
     984
    985985        if (inst->open_nodes_count != 0) {
    986986                fibril_mutex_unlock(&open_nodes_lock);
    987987                return EBUSY;
    988988        }
    989        
     989
    990990        /* Remove the instance from the list */
    991991        fibril_mutex_lock(&instance_list_mutex);
    992992        list_remove(&inst->link);
    993993        fibril_mutex_unlock(&instance_list_mutex);
    994        
     994
    995995        fibril_mutex_unlock(&open_nodes_lock);
    996        
     996
    997997        rc = ext4_filesystem_close(inst->filesystem);
    998998        if (rc != EOK) {
     
    10281028                return EINVAL;
    10291029        }
    1030        
     1030
    10311031        ext4_instance_t *inst;
    10321032        errno_t rc = ext4_instance_get(service_id, &inst);
     
    10351035                return rc;
    10361036        }
    1037        
     1037
    10381038        /* Load i-node */
    10391039        ext4_inode_ref_t *inode_ref;
     
    10431043                return rc;
    10441044        }
    1045        
     1045
    10461046        /* Read from i-node by type */
    10471047        if (ext4_inode_is_type(inst->filesystem->superblock, inode_ref->inode,
     
    10581058                rc = ENOTSUP;
    10591059        }
    1060        
     1060
    10611061        errno_t const rc2 = ext4_filesystem_put_inode_ref(inode_ref);
    1062        
     1062
    10631063        return rc == EOK ? rc2 : rc;
    10641064}
     
    10761076        if ((name_size == 1) && (name[0] == '.'))
    10771077                return true;
    1078        
     1078
    10791079        if ((name_size == 2) && (name[0] == '.') && (name[1] == '.'))
    10801080                return true;
    1081        
     1081
    10821082        return false;
    10831083}
     
    11041104                return rc;
    11051105        }
    1106        
     1106
    11071107        /*
    11081108         * Find next interesting directory entry.
     
    11141114                if (it.current->inode == 0)
    11151115                        goto skip;
    1116                
     1116
    11171117                uint16_t name_size = ext4_directory_entry_ll_get_name_length(
    11181118                    inst->filesystem->superblock, it.current);
    1119                
     1119
    11201120                /* Skip . and .. */
    11211121                if (ext4_is_dots(it.current->name, name_size))
    11221122                        goto skip;
    1123                
     1123
    11241124                /*
    11251125                 * The on-disk entry does not contain \0 at the end
     
    11331133                        return ENOMEM;
    11341134                }
    1135                
     1135
    11361136                memcpy(buf, &it.current->name, name_size);
    11371137                *(buf + name_size) = 0;
    11381138                found = true;
    1139                
     1139
    11401140                (void) async_data_read_finalize(callid, buf, name_size + 1);
    11411141                free(buf);
    11421142                break;
    1143                
     1143
    11441144skip:
    11451145                rc = ext4_directory_iterator_next(&it);
     
    11501150                }
    11511151        }
    1152        
     1152
    11531153        uint64_t next;
    11541154        if (found) {
     
    11561156                if (rc != EOK)
    11571157                        return rc;
    1158                
     1158
    11591159                next = it.current_offset;
    11601160        }
    1161        
     1161
    11621162        rc = ext4_directory_iterator_fini(&it);
    11631163        if (rc != EOK)
    11641164                return rc;
    1165        
     1165
    11661166        /* Prepare return values */
    11671167        if (found) {
     
    11911191        ext4_superblock_t *sb = inst->filesystem->superblock;
    11921192        uint64_t file_size = ext4_inode_get_size(sb, inode_ref->inode);
    1193        
     1193
    11941194        if (pos >= file_size) {
    11951195                /* Read 0 bytes successfully */
     
    11981198                return EOK;
    11991199        }
    1200        
     1200
    12011201        /* For now, we only read data from one block at a time */
    12021202        uint32_t block_size = ext4_superblock_get_block_size(sb);
     
    12041204        uint32_t offset_in_block = pos % block_size;
    12051205        uint32_t bytes = min(block_size - offset_in_block, size);
    1206        
     1206
    12071207        /* Handle end of file */
    12081208        if (pos + bytes > file_size)
    12091209                bytes = file_size - pos;
    1210        
     1210
    12111211        /* Get the real block number */
    12121212        uint32_t fs_block;
     
    12171217                return rc;
    12181218        }
    1219        
     1219
    12201220        /*
    12211221         * Check for sparse file.
     
    12311231                        return ENOMEM;
    12321232                }
    1233                
     1233
    12341234                memset(buffer, 0, bytes);
    1235                
     1235
    12361236                rc = async_data_read_finalize(callid, buffer, bytes);
    12371237                *rbytes = bytes;
    1238                
     1238
    12391239                free(buffer);
    12401240                return rc;
    12411241        }
    1242        
     1242
    12431243        /* Usual case - we need to read a block from device */
    12441244        block_t *block;
     
    12481248                return rc;
    12491249        }
    1250        
     1250
    12511251        assert(offset_in_block + bytes <= block_size);
    12521252        rc = async_data_read_finalize(callid, block->data + offset_in_block, bytes);
     
    12551255                return rc;
    12561256        }
    1257        
     1257
    12581258        rc = block_put(block);
    12591259        if (rc != EOK)
    12601260                return rc;
    1261        
     1261
    12621262        *rbytes = bytes;
    12631263        return EOK;
     
    12821282        if (rc != EOK)
    12831283                return rc;
    1284        
     1284
    12851285        ipc_callid_t callid;
    12861286        size_t len;
     
    12901290                goto exit;
    12911291        }
    1292        
     1292
    12931293        ext4_node_t *enode = EXT4_NODE(fn);
    12941294        ext4_filesystem_t *fs = enode->instance->filesystem;
    1295        
     1295
    12961296        uint32_t block_size = ext4_superblock_get_block_size(fs->superblock);
    1297        
     1297
    12981298        /* Prevent writing to more than one block */
    12991299        uint32_t bytes = min(len, block_size - (pos % block_size));
    1300        
     1300
    13011301        int flags = BLOCK_FLAGS_NONE;
    13021302        if (bytes == block_size)
    13031303                flags = BLOCK_FLAGS_NOREAD;
    1304        
     1304
    13051305        uint32_t iblock =  pos / block_size;
    13061306        uint32_t fblock;
    1307        
     1307
    13081308        /* Load inode */
    13091309        ext4_inode_ref_t *inode_ref = enode->inode_ref;
     
    13141314                goto exit;
    13151315        }
    1316        
     1316
    13171317        /* Check for sparse file */
    13181318        if (fblock == 0) {
     
    13231323                            ext4_inode_get_size(fs->superblock, inode_ref->inode) /
    13241324                            block_size;
    1325                        
     1325
    13261326                        while (last_iblock < iblock) {
    13271327                                rc = ext4_extent_append_block(inode_ref, &last_iblock,
     
    13321332                                }
    13331333                        }
    1334                        
     1334
    13351335                        rc = ext4_extent_append_block(inode_ref, &last_iblock,
    13361336                            &fblock, false);
     
    13451345                                goto exit;
    13461346                        }
    1347                        
     1347
    13481348                        rc = ext4_filesystem_set_inode_data_block_index(inode_ref,
    13491349                            iblock, fblock);
     
    13541354                        }
    13551355                }
    1356                
     1356
    13571357                flags = BLOCK_FLAGS_NOREAD;
    13581358                inode_ref->dirty = true;
    13591359        }
    1360        
     1360
    13611361        /* Load target block */
    13621362        block_t *write_block;
     
    13661366                goto exit;
    13671367        }
    1368        
     1368
    13691369        if (flags == BLOCK_FLAGS_NOREAD)
    13701370                memset(write_block->data, 0, block_size);
     
    14191419        if (rc != EOK)
    14201420                return rc;
    1421        
     1421
    14221422        ext4_node_t *enode = EXT4_NODE(fn);
    14231423        ext4_inode_ref_t *inode_ref = enode->inode_ref;
    1424        
     1424
    14251425        rc = ext4_filesystem_truncate_inode(inode_ref, new_size);
    14261426        errno_t const rc2 = ext4_node_put(fn);
    1427        
     1427
    14281428        return rc == EOK ? rc2 : rc;
    14291429}
     
    14561456        if (rc != EOK)
    14571457                return rc;
    1458        
     1458
    14591459        /* Destroy the inode */
    14601460        return ext4_destroy_node(fn);
     
    14731473        if (rc != EOK)
    14741474                return rc;
    1475        
     1475
    14761476        ext4_node_t *enode = EXT4_NODE(fn);
    14771477        enode->inode_ref->dirty = true;
    1478        
     1478
    14791479        return ext4_node_put(fn);
    14801480}
Note: See TracChangeset for help on using the changeset viewer.