Changeset 2d0d637 in mainline


Ignore:
Timestamp:
2011-06-21T18:56:31Z (13 years ago)
Author:
Oleg Romanenko <romanenko.oleg@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
61e29a4d
Parents:
9553d7d
Message:

Functions for checking string compatibility with SFN requirements

Location:
uspace/srv/fs/fat
Files:
4 edited

Legend:

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

    r9553d7d r2d0d637  
    394394}
    395395
     396bool fat_lfn_valid_char(uint16_t c)
     397{
     398        char valid[] = {"_.$%\'-@~!(){}^#&"};
     399        size_t idx=0;
     400
     401        if (c > 0xff) return false;
     402        if (isdigit(c) || (isalpha(c) && isupper(c)))
     403                return true;   
     404        while(valid[idx]!=0)
     405                if (c == valid[idx++])
     406                        return true;
     407
     408        return false;
     409}
     410
     411bool fat_lfn_valid_str(const uint16_t *str)
     412{
     413        uint16_t c;
     414        size_t idx=0;
     415        if (str[idx] == 0 || str[idx] == '.')
     416                return false;
     417        while ((c=str[idx++]) != 0) {
     418                if (!fat_lfn_valid_char(c))
     419                        return false;
     420        }
     421        return true;
     422}
     423
     424/** Get number of characters in a wide string.
     425 *
     426 * @param str NULL-terminated wide string.
     427 *
     428 * @return Number of characters in @a str.
     429 *
     430 */
     431size_t utf16_length(const uint16_t *wstr)
     432{
     433        size_t len = 0;
     434       
     435        while (*wstr++ != 0)
     436                len++;
     437        return len;
     438}
     439
     440bool fat_dentry_is_sfn(const uint16_t *str)
     441{
     442        /* 1. Length <= 11 characters */
     443        if (utf16_length(str) > (FAT_NAME_LEN + FAT_EXT_LEN))
     444                return false;
     445        /*
     446         * 2. All characters in string should be ASCII
     447         * 3. All letters must be uppercase
     448         * 4. String should not contain invalid characters
     449         */
     450        if (!fat_lfn_valid_str(str))
     451                return false;
     452       
     453        return true;
     454}
     455
    396456
    397457/**
  • uspace/srv/fs/fat/fat_dentry.h

    r9553d7d r2d0d637  
    140140extern size_t fat_lfn_copy_part(const uint16_t *, size_t, uint16_t *, size_t *);
    141141extern size_t fat_lfn_copy_entry(const fat_dentry_t *, uint16_t *, size_t *);
     142
    142143extern int utf16_to_str(char *, size_t, const uint16_t *);
    143144extern int str_to_utf16(uint16_t *, size_t, const char *);
     145extern bool fat_lfn_valid_char(uint16_t);
     146extern bool fat_lfn_valid_str(const uint16_t *);
     147extern size_t utf16_length(const uint16_t *);
     148extern bool fat_dentry_is_sfn(const uint16_t *);
    144149
    145150
  • uspace/srv/fs/fat/fat_directory.c

    r9553d7d r2d0d637  
    254254}
    255255
     256int fat_directory_write(fat_directory_t *di, char *name, fat_dentry_t *de)
     257{
     258        /* TODO: create LFN records if necessarry and create SFN record */
     259        return EOK;
     260}
     261
     262
    256263
    257264/**
  • uspace/srv/fs/fat/fat_directory.h

    r9553d7d r2d0d637  
    6767
    6868extern int fat_directory_read(fat_directory_t *, char *, fat_dentry_t **);
     69extern int fat_directory_write(fat_directory_t *, char *, fat_dentry_t *);
    6970extern int fat_directory_erase(fat_directory_t *);
    7071
Note: See TracChangeset for help on using the changeset viewer.