Changeset d8df2fb in mainline


Ignore:
Timestamp:
2011-08-14T19:31:52Z (13 years ago)
Author:
Oleg Romanenko <romanenko.oleg@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4ba3535
Parents:
151a4e2
Message:

exFAT: implement exfat_directory_sync_file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/exfat/exfat_directory.c

    r151a4e2 rd8df2fb  
    4242#include <byteorder.h>
    4343#include <mem.h>
     44#include <malloc.h>
    4445#include <str.h>
    4546
     
    249250}
    250251
    251 int exfat_directory_sync_file(exfat_directory_t *di,
    252     exfat_file_dentry_t *df, exfat_stream_dentry_t *ds)
    253 {
     252static uint16_t exfat_directory_set_checksum(const uint8_t *bytes, size_t count)
     253{
     254        uint16_t checksum = 0;
     255        size_t idx;
     256
     257        for (idx = 0; idx < count; idx++) {
     258                if (idx == 2 || idx == 3)
     259                        continue;
     260                checksum = ((checksum << 15) | (checksum >> 1)) + (uint16_t)bytes[idx];
     261        }
     262        return checksum;
     263}
     264
     265int exfat_directory_sync_file(exfat_directory_t *di, exfat_file_dentry_t *df,
     266    exfat_stream_dentry_t *ds)
     267{
     268        int rc, i, count;
     269        exfat_dentry_t *array=NULL, *de;
     270        aoff64_t pos = di->pos;
     271
     272        rc = exfat_directory_get(di, &de);
     273        if (rc != EOK)
     274                return rc;
     275        count = de->file.count+1;
     276        array = (exfat_dentry_t *) malloc(count*sizeof(exfat_dentry_t));
     277        if (!array)
     278                return ENOMEM;
     279        for (i=0; i<count; i++) {
     280                rc = exfat_directory_get(di, &de);
     281                if (rc != EOK)
     282                        return rc;
     283                memcpy((uint8_t *)&array[i], (uint8_t *)de, sizeof(exfat_dentry_t));
     284                rc = exfat_directory_next(di);
     285                if (rc!=EOK) {
     286                        free(array);
     287                        return rc;
     288                }
     289        }
     290        rc = exfat_directory_seek(di, pos);
     291        if (rc!=EOK) {
     292                free(array);
     293                return rc;
     294        }
     295
     296        /* Sync */
     297        array[0].file.attr = df->attr;
     298        array[1].stream.firstc = ds->firstc;
     299        array[1].stream.flags = ds->flags;
     300        array[1].stream.valid_data_size = ds->valid_data_size;
     301        array[1].stream.data_size = ds->data_size;
     302        array[0].file.checksum = exfat_directory_set_checksum((uint8_t *)array,
     303            count*sizeof(exfat_dentry_t));
     304
     305        /* Store */
     306        for (i=0; i<count; i++) {
     307                rc = exfat_directory_get(di, &de);
     308                if (rc != EOK)
     309                        return rc;
     310                memcpy((uint8_t *)de, (uint8_t *)&array[i], sizeof(exfat_dentry_t));
     311                di->b->dirty = true;
     312                rc = exfat_directory_next(di);
     313                if (rc!=EOK) {
     314                        free(array);
     315                        return rc;
     316                }
     317        }
     318
    254319        return EOK;
    255320}
Note: See TracChangeset for help on using the changeset viewer.