Ignore:
File:
1 edited

Legend:

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

    r5c702a8 r48e3190  
    5757 *
    5858 */
    59 static int udf_read_extended_allocator(udf_node_t *node, uint16_t icb_flag,
     59int udf_read_extended_allocator(udf_node_t *node, uint16_t icb_flag,
    6060    uint32_t pos)
    6161{
     
    185185                         */
    186186                        if (FLE32(long_d->length) >> 30 == 3) {
    187                                 udf_read_extended_allocator(node, icb_flag, pos_long_ad);
     187                                udf_read_extended_allocator (node, icb_flag, pos_long_ad);
    188188                                break;
    189189                        }
     
    296296}
    297297
     298/** Read ICB sequence of allocators in Unallocated space entry descriptor
     299 *
     300 * This function read ICB sequence if free space is saved by space table.
     301 * Not finished.
     302 *
     303 * @param uased       Unallocated space entry descriptor
     304 * @param icb_flag    Type of allocators in sequence.
     305 *                    According to ECMA 167 4/14.8.8
     306 * @param start_alloc Offset of the allocator
     307 * @param len         Length of sequence
     308 *
     309 * @return EOK on success or a negative error code.
     310 *
     311 */
     312int udf_read_free_space(uint8_t *uased, uint16_t icb_flag,
     313    uint32_t start_alloc, uint32_t len)
     314{
     315        switch (icb_flag) {
     316        case UDF_SHORT_AD:
     317                log_msg(LVL_DEBUG,
     318                    "UAICB: sequence of allocation descriptors - icbflag = short_ad_t");
     319               
     320                /* Identify number of current partition */
     321               
     322                size_t cnt = len / sizeof(udf_short_ad_t);
     323                size_t n = 0;
     324               
     325                while (n < cnt) {
     326                        udf_short_ad_t *short_d =
     327                            (udf_short_ad_t *) (uased + start_alloc + n * sizeof(udf_short_ad_t));
     328                       
     329                        if (short_d->length == 0)
     330                                break;
     331                       
     332                        n++;
     333                }
     334               
     335                break;
     336               
     337        case UDF_LONG_AD:
     338                log_msg(LVL_DEBUG,
     339                    "UAICB: sequence of allocation descriptors - icbflag = long_ad_t");
     340               
     341                cnt = len / sizeof(udf_long_ad_t);
     342                n = 0;
     343               
     344                while (n < cnt) {
     345                        udf_long_ad_t *long_d =
     346                            (udf_long_ad_t *) (uased + start_alloc + n * sizeof(udf_long_ad_t));
     347                       
     348                        if (long_d->length == 0)
     349                                break;
     350                       
     351                        n++;
     352                }
     353               
     354                break;
     355               
     356        case UDF_EXTENDED_AD:
     357                log_msg(LVL_DEBUG,
     358                    "UAICB: sequence of allocation descriptors - icbflag = extended_ad_t");
     359                break;
     360               
     361        case UDF_DATA_AD:
     362                log_msg(LVL_DEBUG,
     363                    "UAICB: sequence of allocation descriptors - icbflag = 3, node contains data itself");
     364                break;
     365        }
     366       
     367        return EOK;
     368}
     369
     370/** Read Unallocated space entry descriptor
     371 *
     372 * Read ICB sequence if free space is saved by space table.
     373 * Not finished.
     374 *
     375 */
     376int udf_read_unallocated_space_entry(udf_instance_t * instance, uint64_t pos,
     377    uint32_t len)
     378{
     379        block_t *block = NULL;
     380        int rc = block_get(&block, instance->service_id, pos, BLOCK_FLAGS_NONE);
     381        if (rc != EOK)
     382                return rc;
     383       
     384        udf_descriptor_tag_t *desc = (udf_descriptor_tag_t *) block->data;
     385        if (desc->checksum != udf_tag_checksum((uint8_t *) desc)) {
     386                block_put(block);
     387                return EINVAL;
     388        }
     389       
     390        if (FLE16(desc->id) != UDF_UASPACE_ENTRY) {
     391                // FIXME: Memory leak
     392                return EINVAL;
     393        }
     394       
     395        udf_unallocated_space_entry_descriptor_t *uased =
     396            (udf_unallocated_space_entry_descriptor_t *) block->data;
     397        if (uased->icbtag.file_type != UDF_ICBTYPE_UASE) {
     398                // FIXME: Memory leak
     399                return EINVAL;
     400        }
     401       
     402        uint16_t icb_flag = uased->icbtag.flags & UDF_ICBFLAG_MASK;
     403       
     404        rc = udf_read_free_space((uint8_t *) uased, icb_flag,
     405            UDF_UASE_OFFSET, uased->ad_lenght);
     406       
     407        return block_put(block);
     408}
     409
    298410/** Read data from disk - filling UDF node by allocators
    299411 *
     
    307419        node->link_cnt = 1;
    308420        return udf_read_icb(node);
     421}
     422
     423/** Read directory entry
     424 *
     425 * @param fid   Returned value
     426 * @param block Returned value
     427 * @param node  UDF node
     428 * @param pos   Number of FID which we need to find
     429 *
     430 * @return EOK on success or a negative error code.
     431 *
     432 */
     433int udf_get_fid(udf_file_identifier_descriptor_t **fid, block_t **block,
     434    udf_node_t *node, aoff64_t pos)
     435{
     436        if (node->data == NULL)
     437                return udf_get_fid_in_allocator(fid, block, node, pos);
     438       
     439        return udf_get_fid_in_data(fid, node, pos);
    309440}
    310441
     
    318449 *
    319450 */
    320 static int udf_get_fid_in_data(udf_file_identifier_descriptor_t **fid,
     451int udf_get_fid_in_data(udf_file_identifier_descriptor_t **fid,
    321452    udf_node_t *node, aoff64_t pos)
    322453{
     
    357488       
    358489        return ENOENT;
    359 }
    360 
    361 /** Read directory entry
    362  *
    363  * @param fid   Returned value
    364  * @param block Returned value
    365  * @param node  UDF node
    366  * @param pos   Number of FID which we need to find
    367  *
    368  * @return EOK on success or a negative error code.
    369  *
    370  */
    371 int udf_get_fid(udf_file_identifier_descriptor_t **fid, block_t **block,
    372     udf_node_t *node, aoff64_t pos)
    373 {
    374         if (node->data == NULL)
    375                 return udf_get_fid_in_allocator(fid, block, node, pos);
    376        
    377         return udf_get_fid_in_data(fid, node, pos);
    378490}
    379491
Note: See TracChangeset for help on using the changeset viewer.