Changeset 34fdb75 in mainline for uspace/srv/fs/fat/fat_dentry.c


Ignore:
Timestamp:
2011-06-10T16:55:14Z (13 years ago)
Author:
Oleg Romanenko <romanenko.oleg@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
65ccd23
Parents:
ed19497
Message:

Macros and functions for managing Long Entry and extracting long name

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/fat/fat_dentry.c

    red19497 r34fdb75  
    3939#include <ctype.h>
    4040#include <str.h>
     41#include <errno.h>
    4142
    4243static bool is_d_char(const char ch)
     
    218219fat_dentry_clsf_t fat_classify_dentry(const fat_dentry_t *d)
    219220{
     221/*      if (d->attr == FAT_ATTR_LFN) { */
     222                /* long name entry */
     223/*              if (d->attr & FAT_LFN_ERASED)
     224                        return FAT_DENTRY_FREE;
     225                else
     226                        return FAT_DENTRY_LFN;
     227        }*/
    220228        if (d->attr & FAT_ATTR_VOLLABEL) {
    221229                /* volume label entry */
     
    259267}
    260268
     269/** Get number of bytes in a string with size limit.
     270 *
     271 * @param str  NULL-terminated (or not) string.
     272 * @param size Maximum number of bytes to consider.
     273 *
     274 * @return Number of bytes in string (without 0 and ff).
     275 *
     276 */
     277size_t fat_lfn_str_nlength(const uint8_t *str, size_t size)
     278{
     279        size_t offset = 0;
     280
     281        while (offset < size) {
     282                if ((str[offset] == 0x00 && str[offset+1] == 0x00) ||
     283                        (str[offset] == 0xff && str[offset+1] == 0xff))
     284                        break;
     285               
     286                offset += 2;
     287        }
     288        return offset;
     289}
     290
     291/** Get number of bytes in a FAT long entry occuped by characters.
     292 *
     293 * @param d FAT long entry.
     294 *
     295 * @return Number of bytes.
     296 *
     297 */
     298size_t fat_lfn_size(const fat_dentry_t *d)
     299{
     300        size_t size = 0;
     301       
     302        size += fat_lfn_str_nlength(FAT_LFN_PART1(d), FAT_LFN_PART1_SIZE);
     303        size += fat_lfn_str_nlength(FAT_LFN_PART2(d), FAT_LFN_PART2_SIZE);
     304        size += fat_lfn_str_nlength(FAT_LFN_PART3(d), FAT_LFN_PART3_SIZE);     
     305       
     306        return size;
     307}
     308
     309void fat_lfn_copy_part(const uint8_t *src, size_t src_size, uint8_t *dst, size_t *offset)
     310{
     311        int i;
     312        for (i=src_size-1; i>0 && (*offset)>1; i-=2) {
     313                if ((src[i] == 0x00 && src[i-1] == 0x00) ||
     314                        (src[i] == 0xff && src[i-1] == 0xff))
     315                        continue;
     316                dst[(*offset)-1] = src[i];
     317                dst[(*offset)-2] = src[i-1];
     318                (*offset)-=2;
     319        }
     320}
     321
     322void fat_lfn_copy_entry(const fat_dentry_t *d, uint8_t *dst, size_t *offset)
     323{
     324        fat_lfn_copy_part(FAT_LFN_PART3(d), FAT_LFN_PART3_SIZE, dst, offset);
     325        fat_lfn_copy_part(FAT_LFN_PART2(d), FAT_LFN_PART2_SIZE, dst, offset);
     326        fat_lfn_copy_part(FAT_LFN_PART1(d), FAT_LFN_PART1_SIZE, dst, offset);
     327}
     328
     329int fat_lfn_convert_name(const uint8_t *src, size_t src_size, uint8_t *dst, size_t dst_size)
     330{
     331        size_t i, offset = 0;
     332        uint16_t c;
     333        int rc;
     334        for (i=0; i<src_size; i+=2) {
     335                if (src[i+1] == 0x00) {
     336                        if (offset+1 < dst_size)
     337                                dst[offset++] = src[i];
     338                        else
     339                                return EOVERFLOW;
     340                } else {
     341                        c = (src[i] << 8) | src[i+1];
     342                        rc = chr_encode(c, (char*)dst, &offset, dst_size);
     343                        if (rc!=EOK) {
     344                                return rc;
     345                        }
     346                }
     347        }
     348        dst[offset] = 0;       
     349        return EOK;
     350}
     351
    261352
    262353/**
Note: See TracChangeset for help on using the changeset viewer.