Changeset 298a6ce in mainline


Ignore:
Timestamp:
2011-06-28T05:47:36Z (13 years ago)
Author:
Oleg Romanenko <romanenko.oleg@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
82374b2
Parents:
620a367
Message:

Using local variables for storing LFN data instead of global fat_directory_t struct

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

Legend:

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

    r620a367 r298a6ce  
    5959        di->bnum = 0;
    6060        di->last = false;
    61 
    62         di->wname[0] = '\0';
    63         di->lfn_offset = 0;
    64         di->lfn_size = 0;
    65         di->long_entry = false;
    66         di->long_entry_count = 0;
    67         di->checksum=0;
    68 
    6961        return EOK;
    7062}
     
    162154{
    163155        fat_dentry_t *d = NULL;
     156        wchar_t wname[FAT_LFN_NAME_SIZE];
     157        size_t lfn_offset, lfn_size;
     158        bool long_entry = false;
     159        int long_entry_count = 0;
     160        uint8_t checksum = 0;
    164161
    165162        do {
     
    167164                        switch (fat_classify_dentry(d)) {
    168165                        case FAT_DENTRY_LAST:
    169                                 di->long_entry_count = 0;
    170                                 di->long_entry = false;
     166                                long_entry_count = 0;
     167                                long_entry = false;
    171168                                return ENOENT;
    172169                        case FAT_DENTRY_LFN:
    173                                 if (di->long_entry) {
     170                                if (long_entry) {
    174171                                        /* We found long entry */
    175                                         di->long_entry_count--;
    176                                         if ((FAT_LFN_ORDER(d) == di->long_entry_count) &&
    177                                                 (di->checksum == FAT_LFN_CHKSUM(d))) {
     172                                        long_entry_count--;
     173                                        if ((FAT_LFN_ORDER(d) == long_entry_count) &&
     174                                                (checksum == FAT_LFN_CHKSUM(d))) {
    178175                                                /* Right order! */
    179                                                 fat_lfn_get_entry(d, di->wname, &di->lfn_offset);
     176                                                fat_lfn_get_entry(d, wname, &lfn_offset);
    180177                                        } else {
    181178                                                /* Something wrong with order. Skip this long entries set */
    182                                                 di->long_entry_count = 0;
    183                                                 di->long_entry = false;
     179                                                long_entry_count = 0;
     180                                                long_entry = false;
    184181                                        }
    185182                                } else {
     
    187184                                                /* We found Last long entry! */
    188185                                                if (FAT_LFN_COUNT(d) <= FAT_LFN_MAX_COUNT) {
    189                                                         di->long_entry = true;
    190                                                         di->long_entry_count = FAT_LFN_COUNT(d);
    191                                                         di->lfn_size = (FAT_LFN_ENTRY_SIZE *
     186                                                        long_entry = true;
     187                                                        long_entry_count = FAT_LFN_COUNT(d);
     188                                                        lfn_size = (FAT_LFN_ENTRY_SIZE *
    192189                                                                (FAT_LFN_COUNT(d) - 1)) + fat_lfn_size(d);
    193                                                         di->lfn_offset = di->lfn_size;
    194                                                         fat_lfn_get_entry(d, di->wname, &di->lfn_offset);
    195                                                         di->checksum = FAT_LFN_CHKSUM(d);
     190                                                        lfn_offset = lfn_size;
     191                                                        fat_lfn_get_entry(d, wname, &lfn_offset);
     192                                                        checksum = FAT_LFN_CHKSUM(d);
    196193                                                }
    197194                                        }
     
    199196                                break;
    200197                        case FAT_DENTRY_VALID:
    201                                 if (di->long_entry &&
    202                                         (di->checksum == fat_dentry_chksum(d->name))) {
    203                                         di->wname[di->lfn_size] = '\0';
    204                                         if (wstr_to_str(name, FAT_LFN_NAME_SIZE, di->wname)!=EOK)
     198                                if (long_entry &&
     199                                        (checksum == fat_dentry_chksum(d->name))) {
     200                                        wname[lfn_size] = '\0';
     201                                        if (wstr_to_str(name, FAT_LFN_NAME_SIZE, wname)!=EOK)
    205202                                                fat_dentry_name_get(d, name);
    206203                                }
     
    209206                               
    210207                                *de = d;
    211                                 di->long_entry_count = 0;
    212                                 di->long_entry = false;
    213208                                return EOK;
    214209                        default:
    215210                        case FAT_DENTRY_SKIP:
    216211                        case FAT_DENTRY_FREE:
    217                                 di->long_entry_count = 0;
    218                                 di->long_entry = false;
     212                                long_entry_count = 0;
     213                                long_entry = false;
    219214                                break;
    220215                        }
     
    230225        fat_dentry_t *d;
    231226        bool flag = false;
     227        uint8_t checksum;
    232228
    233229        rc = fat_directory_get(di, &d);
    234230        if (rc != EOK)
    235231                return rc;
    236         di->checksum = fat_dentry_chksum(d->name);
     232        checksum = fat_dentry_chksum(d->name);
    237233
    238234        d->name[0] = FAT_DENTRY_ERASED;
     
    242238                if (fat_directory_get(di, &d) == EOK &&
    243239                        fat_classify_dentry(d) == FAT_DENTRY_LFN &&                     
    244                         di->checksum == FAT_LFN_CHKSUM(d)) {
     240                        checksum == FAT_LFN_CHKSUM(d)) {
    245241                                if (FAT_IS_LFN(d))
    246242                                        flag = true;
     
    259255{
    260256        int rc;
    261         rc = str_to_wstr(di->wname, FAT_LFN_NAME_SIZE, name);
     257        int long_entry_count;
     258        uint8_t checksum;
     259        wchar_t wname[FAT_LFN_NAME_SIZE];
     260        size_t lfn_size, lfn_offset;
     261       
     262        rc = str_to_wstr(wname, FAT_LFN_NAME_SIZE, name);
    262263        if (rc != EOK)
    263264                return rc;
    264         if (fat_dentry_is_sfn(di->wname)) {
     265        if (fat_dentry_is_sfn(wname)) {
    265266                /* NAME could be directly stored in dentry without creating LFN */
    266267                fat_dentry_name_set(de, name);
     
    280281        {
    281282                /* We should create long entries to store name */
    282                 di->lfn_size = wstr_length(di->wname);
    283                 di->long_entry_count = di->lfn_size / FAT_LFN_ENTRY_SIZE;
    284                 if (di->lfn_size % FAT_LFN_ENTRY_SIZE)
    285                         di->long_entry_count++;
    286                 rc = fat_directory_lookup_free(di, di->long_entry_count+1);
     283                lfn_size = wstr_length(wname);
     284                long_entry_count = lfn_size / FAT_LFN_ENTRY_SIZE;
     285                if (lfn_size % FAT_LFN_ENTRY_SIZE)
     286                        long_entry_count++;
     287                rc = fat_directory_lookup_free(di, long_entry_count+1);
    287288                if (rc != EOK)
    288289                        return rc;
     
    290291
    291292                /* Write Short entry */
    292                 rc = fat_directory_create_sfn(di, de);
    293                 if (rc != EOK)
    294                         return rc;
    295                 di->checksum = fat_dentry_chksum(de->name);
    296 
    297                 rc = fat_directory_seek(di, start_pos+di->long_entry_count);
     293                rc = fat_directory_create_sfn(di, de, wname);
     294                if (rc != EOK)
     295                        return rc;
     296                checksum = fat_dentry_chksum(de->name);
     297
     298                rc = fat_directory_seek(di, start_pos+long_entry_count);
    298299                if (rc != EOK)
    299300                        return rc;
     
    303304
    304305                /* Write Long entry by parts */
    305                 di->lfn_offset = 0;
     306                lfn_offset = 0;
    306307                fat_dentry_t *d;
    307308                size_t idx = 0;
     
    313314                        if (rc != EOK)
    314315                                return rc;
    315                         fat_lfn_set_entry(di->wname, &di->lfn_offset, di->lfn_size+1, d);
    316                         FAT_LFN_CHKSUM(d) = di->checksum;
     316                        fat_lfn_set_entry(wname, &lfn_offset, lfn_size+1, d);
     317                        FAT_LFN_CHKSUM(d) = checksum;
    317318                        FAT_LFN_ORDER(d) = ++idx;
    318319                        di->b->dirty = true;
    319                 } while (di->lfn_offset < di->lfn_size);
     320                } while (lfn_offset < lfn_size);
    320321                FAT_LFN_ORDER(d) |= FAT_LFN_LAST;
    321322
    322                 rc = fat_directory_seek(di, start_pos+di->long_entry_count);
     323                rc = fat_directory_seek(di, start_pos+long_entry_count);
    323324                if (rc != EOK)
    324325                        return rc;
     
    327328}
    328329
    329 int fat_directory_create_sfn(fat_directory_t *di, fat_dentry_t *de)
     330int fat_directory_create_sfn(fat_directory_t *di, fat_dentry_t *de, const wchar_t *wname)
    330331{
    331332        char name[FAT_NAME_LEN+1];
     
    336337        memset(number, FAT_PAD, FAT_NAME_LEN);
    337338
    338         size_t name_len = wstr_size(di->wname);
    339         wchar_t *pdot = wstr_rchr(di->wname, '.');
     339        size_t name_len = wstr_size(wname);
     340        wchar_t *pdot = wstr_rchr(wname, '.');
    340341        ext[FAT_EXT_LEN] = '\0';
    341342        if (pdot) {
    342343                pdot++;
    343344                wstr_to_ascii(ext, pdot, FAT_EXT_LEN, FAT_SFN_CHAR);
    344                 name_len = (pdot - di->wname - 1);
     345                name_len = (pdot - wname - 1);
    345346        }
    346347        if (name_len > FAT_NAME_LEN)
    347348                name_len = FAT_NAME_LEN;
    348         wstr_to_ascii(name, di->wname, name_len, FAT_SFN_CHAR);
     349        wstr_to_ascii(name, wname, name_len, FAT_SFN_CHAR);
    349350
    350351        size_t idx;
  • uspace/srv/fs/fat/fat_directory.h

    r620a367 r298a6ce  
    4949        block_t *b;
    5050        bool last;
    51         /* Long entry data */
    52         wchar_t wname[FAT_LFN_NAME_SIZE];
    53         size_t lfn_offset;
    54         size_t lfn_size;
    55         bool long_entry;
    56         int long_entry_count;
    57         uint8_t checksum;
    5851} __attribute__ ((packed)) fat_directory_t;
    5952
     
    7568extern int fat_directory_lookup_free(fat_directory_t *di, size_t count);
    7669extern int fat_directory_write_dentry(fat_directory_t *di, fat_dentry_t *de);
    77 extern int fat_directory_create_sfn(fat_directory_t *di, fat_dentry_t *de);
     70extern int fat_directory_create_sfn(fat_directory_t *di, fat_dentry_t *de, const wchar_t *wname);
    7871extern int fat_directory_expand(fat_directory_t *di);
    7972
  • uspace/srv/fs/fat/fat_ops.c

    r620a367 r298a6ce  
    587587        fat_dentry_t de;
    588588        int rc;
     589        wchar_t wname[FAT_LFN_NAME_SIZE];
    589590
    590591        fibril_mutex_lock(&childp->lock);
     
    599600        fibril_mutex_unlock(&childp->lock);
    600601
    601         rc = str_to_wstr(di.wname, FAT_LFN_NAME_SIZE, name);
     602        rc = str_to_wstr(wname, FAT_LFN_NAME_SIZE, name);
    602603        if (rc != EOK)
    603604                return rc;
    604605
    605         if (!fat_lfn_valid(di.wname))
     606        if (!fat_lfn_valid(wname))
    606607                return ENOTSUP;
    607608
Note: See TracChangeset for help on using the changeset viewer.