Changeset 8565a42 in mainline for uspace/srv/fs/udf/udf_file.c


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/udf/udf_file.c

    r3061bc1 r8565a42  
    6565        if (rc != EOK)
    6666                return rc;
    67        
     67
    6868        udf_ext_ad_t *exd = (udf_ext_ad_t *) block->data;
    6969        uint32_t start = node->instance->partitions[
    7070            FLE16(exd->extent_location.partition_num)].start +
    7171            FLE32(exd->extent_location.lblock_num);
    72        
     72
    7373        log_msg(LOG_DEFAULT, LVL_DEBUG,
    7474            "Extended allocator: start=%d, block_num=%d, len=%d", start,
    7575            FLE32(exd->extent_location.lblock_num), FLE32(exd->info_length));
    76        
     76
    7777        uint32_t len = FLE32(exd->info_length);
    7878        block_put(block);
    79        
     79
    8080        return udf_read_allocation_sequence(node, NULL, icb_flag, start, len);
    8181}
     
    9797{
    9898        node->alloc_size = 0;
    99        
     99
    100100        switch (icb_flag) {
    101101        case UDF_SHORT_AD:
    102102                log_msg(LOG_DEFAULT, LVL_DEBUG,
    103103                    "ICB: sequence of allocation descriptors - icbflag = short_ad_t");
    104                
     104
    105105                /*
    106106                 * Identify number of current partition. Virtual partition
     
    110110                size_t pd_num = (size_t) -1;
    111111                size_t min_start = 0;
    112                
     112
    113113                for (size_t i = 0; i < node->instance->partition_cnt; i++) {
    114114                        if ((node->index >= node->instance->partitions[i].start) &&
     
    121121                        }
    122122                }
    123                
     123
    124124                if (pd_num == (size_t) -1)
    125125                        return ENOENT;
    126                
     126
    127127                /*
    128128                 * According to doc, in this we should stop our loop if pass
     
    133133                 * which we check inside of loop.
    134134                 */
    135                
     135
    136136                while (true) {
    137137                        udf_short_ad_t *short_d =
    138138                            (udf_short_ad_t *) (af + start_alloc +
    139139                            node->alloc_size * sizeof(udf_short_ad_t));
    140                        
     140
    141141                        if (FLE32(short_d->length) == 0)
    142142                                break;
    143                        
     143
    144144                        /*
    145145                         * ECMA 167 4/12 - next sequence of allocation descriptors
     
    152152                                break;
    153153                        }
    154                        
     154
    155155                        node->allocators = realloc(node->allocators,
    156156                            (node->alloc_size + 1) * sizeof(udf_allocator_t));
     
    161161                        node->alloc_size++;
    162162                }
    163                
     163
    164164                node->allocators = realloc(node->allocators,
    165165                    node->alloc_size * sizeof(udf_allocator_t));
    166166                break;
    167                
     167
    168168        case UDF_LONG_AD:
    169169                log_msg(LOG_DEFAULT, LVL_DEBUG,
    170170                    "ICB: sequence of allocation descriptors - icbflag = long_ad_t");
    171                
     171
    172172                while (true) {
    173173                        udf_long_ad_t *long_d =
    174174                            (udf_long_ad_t *) (af + start_alloc +
    175175                            node->alloc_size * sizeof(udf_long_ad_t));
    176                        
     176
    177177                        if (FLE32(long_d->length) == 0)
    178178                                break;
    179                        
     179
    180180                        uint32_t pos_long_ad = udf_long_ad_to_pos(node->instance, long_d);
    181                        
     181
    182182                        /*
    183183                         * ECMA 167 4/12 - next sequence of allocation descriptors
     
    188188                                break;
    189189                        }
    190                        
     190
    191191                        node->allocators = realloc(node->allocators,
    192192                            (node->alloc_size + 1) * sizeof(udf_allocator_t));
     
    194194                            EXT_LENGTH(FLE32(long_d->length));
    195195                        node->allocators[node->alloc_size].position = pos_long_ad;
    196                        
     196
    197197                        node->alloc_size++;
    198198                }
    199                
     199
    200200                node->allocators = realloc(node->allocators,
    201201                    node->alloc_size * sizeof(udf_allocator_t));
    202202                break;
    203                
     203
    204204        case UDF_EXTENDED_AD:
    205205                log_msg(LOG_DEFAULT, LVL_DEBUG,
    206206                    "ICB: sequence of allocation descriptors - icbflag = extended_ad_t");
    207207                break;
    208                
     208
    209209        case UDF_DATA_AD:
    210210                log_msg(LOG_DEFAULT, LVL_DEBUG,
    211211                    "ICB: sequence of allocation descriptors - icbflag = 3, node contains data itself");
    212                
     212
    213213                node->data = malloc(node->data_size);
    214214                if (!node->data)
    215215                        return ENOMEM;
    216                
     216
    217217                memcpy(node->data, (af + start_alloc), node->data_size);
    218218                node->alloc_size = 0;
    219219                break;
    220220        }
    221        
     221
    222222        return EOK;
    223223}
     
    237237        while (true) {
    238238                fs_index_t pos = node->index;
    239                
     239
    240240                block_t *block = NULL;
    241241                errno_t rc = block_get(&block, node->instance->service_id, pos,
     
    243243                if (rc != EOK)
    244244                        return rc;
    245                
     245
    246246                udf_descriptor_tag_t *data = (udf_descriptor_tag_t *) block->data;
    247247                if (data->checksum != udf_tag_checksum((uint8_t *) data)) {
     
    249249                        return EINVAL;
    250250                }
    251                
     251
    252252                /* One sector size descriptors */
    253253                switch (FLE16(data->id)) {
    254254                case UDF_FILE_ENTRY:
    255255                        log_msg(LOG_DEFAULT, LVL_DEBUG, "ICB: File entry descriptor found");
    256                        
     256
    257257                        udf_file_entry_descriptor_t *file =
    258258                            (udf_file_entry_descriptor_t *) block->data;
     
    260260                        node->data_size = FLE64(file->info_lenght);
    261261                        node->type = (file->icbtag.file_type == UDF_ICBTYPE_DIR) ? NODE_DIR : NODE_FILE;
    262                        
     262
    263263                        rc = udf_read_allocation_sequence(node, (uint8_t *) file, icb_flag,
    264264                            FLE32(file->ea_lenght) + UDF_FE_OFFSET, FLE32(file->ad_lenght));
    265265                        block_put(block);
    266266                        return rc;
    267                        
     267
    268268                case UDF_EFILE_ENTRY:
    269269                        log_msg(LOG_DEFAULT, LVL_DEBUG, "ICB: Extended file entry descriptor found");
    270                        
     270
    271271                        udf_extended_file_entry_descriptor_t *efile =
    272272                            (udf_extended_file_entry_descriptor_t *) block->data;
     
    274274                        node->data_size = FLE64(efile->info_lenght);
    275275                        node->type = (efile->icbtag.file_type == UDF_ICBTYPE_DIR) ? NODE_DIR : NODE_FILE;
    276                        
     276
    277277                        rc = udf_read_allocation_sequence(node, (uint8_t *) efile, icb_flag,
    278278                            FLE32(efile->ea_lenght) + UDF_EFE_OFFSET, FLE32(efile->ad_lenght));
    279279                        block_put(block);
    280280                        return rc;
    281                        
     281
    282282                case UDF_ICB_TERMINAL:
    283283                        log_msg(LOG_DEFAULT, LVL_DEBUG, "ICB: Terminal entry descriptor found");
     
    285285                        return EOK;
    286286                }
    287                
     287
    288288                pos++;
    289                
     289
    290290                rc = block_put(block);
    291291                if (rc != EOK)
    292292                        return rc;
    293293        }
    294        
     294
    295295        return EOK;
    296296}
     
    323323        size_t fid_sum = 0;
    324324        size_t n = 0;
    325        
     325
    326326        while (node->data_size - fid_sum >= MIN_FID_LEN) {
    327327                udf_descriptor_tag_t *desc =
     
    333333                                return ENOENT;
    334334                }
    335                
     335
    336336                *fid = (udf_file_identifier_descriptor_t *)
    337337                    (node->data + fid_sum);
    338                
     338
    339339                /* According to ECMA 167 4/14.4.9 */
    340340                size_t padding = 4 * (((*fid)->lenght_file_id +
     
    343343                size_t size_fid = (*fid)->lenght_file_id +
    344344                    FLE16((*fid)->lenght_iu) + padding + 38;
    345                
     345
    346346                fid_sum += size_fid;
    347                
     347
    348348                /* aAcording to ECMA 167 4/8.6 */
    349349                if (((*fid)->lenght_file_id != 0) &&
    350350                    (((*fid)->file_characteristics & 4) == 0)) {
    351351                        n++;
    352                        
     352
    353353                        if (n == pos + 1)
    354354                                return EOK;
    355355                }
    356356        }
    357        
     357
    358358        return ENOENT;
    359359}
     
    374374        if (node->data == NULL)
    375375                return udf_get_fid_in_allocator(fid, block, node, pos);
    376        
     376
    377377        return udf_get_fid_in_data(fid, node, pos);
    378378}
     
    392392{
    393393        void *buf = malloc(node->instance->sector_size);
    394        
     394
    395395        // FIXME: Check for NULL return value
    396        
     396
    397397        size_t j = 0;
    398398        size_t n = 0;
    399399        size_t len = 0;
    400        
     400
    401401        while (j < node->alloc_size) {
    402402                size_t i = 0;
     
    408408                                return rc;
    409409                        }
    410                        
     410
    411411                        /*
    412412                         * Last item in allocator is a part of sector. We take
     
    422422                                break;
    423423                        }
    424                        
     424
    425425                        rc = udf_get_fid_in_sector(fid, block, node, pos, &n, &buf, &len);
    426426                        if (rc == EOK) {
     
    428428                                return EOK;
    429429                        }
    430                        
     430
    431431                        if (rc == EINVAL) {
    432432                                // FIXME: Memory leak
    433433                                return ENOENT;
    434434                        }
    435                        
     435
    436436                        if (rc == ENOENT) {
    437437                                if (block) {
    438438                                        rc = block_put(*block);
    439439                                        *block = NULL;
    440                                        
     440
    441441                                        if (rc != EOK)
    442442                                                return rc;
    443443                                }
    444444                        }
    445                        
     445
    446446                        i++;
    447447                }
    448                
     448
    449449                j++;
    450450        }
    451        
     451
    452452        if (buf)
    453453                free(buf);
    454        
     454
    455455        return ENOENT;
    456456}
     
    474474{
    475475        void *fidbuf = malloc(node->instance->sector_size);
    476        
     476
    477477        // FIXME: Check for NULL return value
    478        
     478
    479479        bool buf_flag;
    480        
     480
    481481        if (*len > 0) {
    482482                memcpy(fidbuf, *buf, *len);
     
    484484        } else
    485485                buf_flag = false;
    486        
     486
    487487        size_t fid_sum = 0;
    488488        while (node->instance->sector_size - fid_sum > 0) {
    489489                if (node->instance->sector_size - fid_sum >= MIN_FID_LEN) {
    490490                        void *fid_data;
    491                        
     491
    492492                        if (buf_flag) {
    493493                                memcpy((fidbuf + *len), (*block)->data,
     
    496496                        } else
    497497                                fid_data = (*block)->data + fid_sum;
    498                        
     498
    499499                        udf_descriptor_tag_t *desc =
    500500                            (udf_descriptor_tag_t *) fid_data;
    501                        
     501
    502502                        if (desc->checksum != udf_tag_checksum((uint8_t *) desc)) {
    503503                                if (fidbuf)
    504504                                        free(fidbuf);
    505                                
     505
    506506                                if (*buf) {
    507507                                        free(*buf);
     
    509509                                        *len = 0;
    510510                                }
    511                                
     511
    512512                                return EINVAL;
    513513                        }
    514                        
     514
    515515                        *fid = (udf_file_identifier_descriptor_t *) fid_data;
    516                        
     516
    517517                        /* According to ECMA 167 4/14.4.9 */
    518518                        size_t padding = 4 * (((*fid)->lenght_file_id +
     
    525525                        else
    526526                                fid_sum += size_fid;
    527                        
     527
    528528                        /* According to ECMA 167 4/8.6 */
    529529                        if (((*fid)->lenght_file_id != 0) &&
     
    533533                                        if (fidbuf)
    534534                                                free(fidbuf);
    535                                        
     535
    536536                                        return EOK;
    537537                                }
    538538                        }
    539                        
     539
    540540                        if (fidbuf) {
    541541                                buf_flag = false;
     
    543543                                fidbuf = NULL;
    544544                        }
    545                        
     545
    546546                        if (*buf) {
    547547                                free(*buf);
     
    552552                        if (*buf)
    553553                                free(*buf);
    554                        
     554
    555555                        *len = node->instance->sector_size - fid_sum;
    556556                        *buf = malloc(*len);
    557557                        buf_flag = false;
    558558                        memcpy(*buf, ((*block)->data + fid_sum), *len);
    559                        
     559
    560560                        return ENOENT;
    561561                }
    562562        }
    563        
     563
    564564        return ENOENT;
    565565}
     
    581581        size_t i = 0;
    582582        size_t l = 0;
    583        
     583
    584584        while (i < node->alloc_size) {
    585585                if (pos >= l + node->allocators[i].length) {
     
    589589                        break;
    590590        }
    591        
     591
    592592        size_t sector_cnt = ALL_UP(l, node->instance->sector_size);
    593593        size_t sector_num = pos / node->instance->sector_size;
    594        
     594
    595595        block_t *block = NULL;
    596596        errno_t rc = block_get(&block, node->instance->service_id,
     
    601601                return rc;
    602602        }
    603        
     603
    604604        size_t sector_pos = pos % node->instance->sector_size;
    605        
     605
    606606        if (sector_pos + len < node->instance->sector_size)
    607607                *read_len = len;
    608608        else
    609609                *read_len = node->instance->sector_size - sector_pos;
    610        
     610
    611611        if (ALL_UP(node->allocators[i].length, node->instance->sector_size) ==
    612612            sector_num - sector_cnt + 1) {
     
    618618                        *read_len = len;
    619619        }
    620        
     620
    621621        async_data_read_finalize(callid, block->data + sector_pos, *read_len);
    622622        return block_put(block);
Note: See TracChangeset for help on using the changeset viewer.