Changeset a7eaaae in rtems


Ignore:
Timestamp:
Oct 20, 2014, 7:33:34 AM (5 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
66c1ef9
Parents:
040ed0b4
git-author:
Sebastian Huber <sebastian.huber@…> (10/20/14 07:33:34)
git-committer:
Sebastian Huber <sebastian.huber@…> (10/23/14 08:21:25)
Message:

dosfs: Support ctime and mtime

Implement ctime and mtime updates according to POSIX. The ctime is
mapped to the FAT create time and date. The mtime is mapped to the FAT
last modified time and date. For the atime use the mtime for
simplicity.

Location:
cpukit/libfs/src/dosfs
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libfs/src/dosfs/fat_file.c

    r040ed0b4 ra7eaaae  
    166166}
    167167
     168int
     169fat_file_update(fat_fs_info_t *fs_info, fat_file_fd_t *fat_fd)
     170{
     171    int ret_rc = RC_OK;
     172
     173    /*
     174     * if fat-file descriptor is not marked as "removed", synchronize
     175     * size, first cluster number, write time and date fields of the file
     176     */
     177    if (!FAT_FILE_IS_REMOVED(fat_fd))
     178    {
     179        int rc;
     180
     181        if (fat_fd->fat_file_type == FAT_FILE)
     182        {
     183            rc = fat_file_write_first_cluster_num(fs_info, fat_fd);
     184            if (rc != RC_OK)
     185                ret_rc = rc;
     186
     187            rc = fat_file_write_file_size(fs_info, fat_fd);
     188            if (rc != RC_OK)
     189                ret_rc = rc;
     190        }
     191
     192        rc = fat_file_write_time_and_date(fs_info, fat_fd);
     193        if (rc != RC_OK)
     194            ret_rc = rc;
     195    }
     196
     197    return ret_rc;
     198}
     199
    168200/* fat_file_close --
    169201 *     Close fat-file. If count of links to fat-file
     
    204236    {
    205237        uint32_t key = fat_construct_key(fs_info, &fat_fd->dir_pos.sname);
     238
     239        fat_file_update(fs_info, fat_fd);
    206240
    207241        if (fat_fd->flags & FAT_FILE_REMOVED)
  • cpukit/libfs/src/dosfs/fat_file.h

    r040ed0b4 ra7eaaae  
    8989    uint8_t          flags;
    9090    fat_file_map_t   map;
     91    time_t           ctime;
    9192    time_t           mtime;
    9293
     
    140141}
    141142
     143static inline void fat_file_set_ctime(fat_file_fd_t *fat_fd, time_t t)
     144{
     145    fat_fd->ctime = t;
     146}
     147
     148static inline void fat_file_set_mtime(fat_file_fd_t *fat_fd, time_t t)
     149{
     150    fat_fd->mtime = t;
     151}
     152
     153static inline void fat_file_set_ctime_mtime(fat_file_fd_t *fat_fd, time_t t)
     154{
     155    fat_fd->ctime = t;
     156    fat_fd->mtime = t;
     157}
     158
    142159/* Prototypes for "fat-file" operations */
    143160int
     
    193210                      fat_file_fd_t                        *fat_fd);
    194211
     212int
     213fat_file_size(fat_fs_info_t                        *fs_info,
     214              fat_file_fd_t                        *fat_fd);
     215
     216int
     217fat_file_write_first_cluster_num(fat_fs_info_t *fs_info,
     218                                 fat_file_fd_t *fat_fd);
     219
     220int
     221fat_file_write_file_size(fat_fs_info_t *fs_info,
     222                         fat_file_fd_t *fat_fd);
     223
     224int
     225fat_file_write_time_and_date(fat_fs_info_t *fs_info,
     226                             fat_file_fd_t *fat_fd);
     227
     228int
     229fat_file_update(fat_fs_info_t *fs_info,
     230                fat_file_fd_t *fat_fd);
     231
    195232#ifdef __cplusplus
    196233}
  • cpukit/libfs/src/dosfs/msdos.h

    r040ed0b4 ra7eaaae  
    135135#define MSDOS_FILE_WTIME_OFFSET           22
    136136#define MSDOS_FILE_ADATE_OFFSET           18
     137#define MSDOS_FILE_CDATE_OFFSET           16
     138#define MSDOS_FILE_CTIME_OFFSET           14
    137139
    138140/*
     
    334336);
    335337
    336 int msdos_file_close(rtems_libio_t *iop /* IN  */);
    337 
    338338ssize_t msdos_file_read(
    339339  rtems_libio_t *iop,              /* IN  */
     
    360360
    361361int msdos_file_sync(rtems_libio_t *iop);
    362 
    363 int msdos_file_datasync(rtems_libio_t *iop);
    364362
    365363ssize_t msdos_dir_read(
     
    462460unsigned int msdos_date_dos2unix(unsigned int dd, unsigned int dt);
    463461
    464 int msdos_set_first_cluster_num(
    465   rtems_filesystem_mount_table_entry_t *mt_entry,
    466   fat_file_fd_t                        *fat_fd
    467 );
    468 
    469 int msdos_set_file_size(
    470   rtems_filesystem_mount_table_entry_t *mt_entry,
    471   fat_file_fd_t                        *fat_fd
    472 );
    473 
    474462int msdos_set_first_char4file_name(
    475463  rtems_filesystem_mount_table_entry_t *mt_entry,
     
    477465  unsigned char                         first_char
    478466);
    479 
    480 int msdos_set_dir_wrt_time_and_date(
    481     rtems_filesystem_mount_table_entry_t *mt_entry,
    482     fat_file_fd_t                        *fat_fd
    483 );
    484 
    485467
    486468int msdos_dir_is_empty(
  • cpukit/libfs/src/dosfs/msdos_create.c

    r040ed0b4 ra7eaaae  
    7171    fat_file_fd_t    *parent_fat_fd = parent_loc->node_access;
    7272    fat_file_fd_t    *fat_fd = NULL;
    73     time_t            time_ret = 0;
     73    time_t            now;
    7474    uint16_t          time_val = 0;
    7575    uint16_t          date = 0;
     
    103103
    104104    /* set up last write date and time */
    105     time_ret = time(NULL);
    106     if ( time_ret == -1 )
    107         return -1;
    108 
    109     msdos_date_unix2dos(time_ret, &date, &time_val);
     105    now = time(NULL);
     106    fat_file_set_ctime_mtime(parent_fat_fd, now);
     107
     108    msdos_date_unix2dos(now, &date, &time_val);
    110109    *MSDOS_DIR_CRT_TIME(short_node) = CT_LE_W(time_val);
    111110    *MSDOS_DIR_CRT_DATE(short_node) = CT_LE_W(date);
     
    193192        fat_fd->fat_file_type = FAT_DIRECTORY;
    194193        fat_fd->size_limit = MSDOS_MAX_DIR_LENGHT;
     194        fat_file_set_ctime_mtime(fat_fd, now);
    195195
    196196        /*
     
    261261
    262262        /* write first cluster num of a new directory to disk */
    263         rc = msdos_set_first_cluster_num(parent_loc->mt_entry, fat_fd);
     263        rc = fat_file_write_first_cluster_num(&fs_info->fat, fat_fd);
    264264        if (rc != RC_OK)
    265265            goto error;
  • cpukit/libfs/src/dosfs/msdos_dir.c

    r040ed0b4 ra7eaaae  
    404404    buf->st_blocks = fat_fd->fat_file_size >> FAT_SECTOR512_BITS;
    405405    buf->st_blksize = fs_info->fat.vol.bps;
     406    buf->st_atime = fat_fd->mtime;
     407    buf->st_ctime = fat_fd->ctime;
    406408    buf->st_mtime = fat_fd->mtime;
    407409
  • cpukit/libfs/src/dosfs/msdos_file.c

    r040ed0b4 ra7eaaae  
    3030
    3131#include "msdos.h"
    32 
    33 static int
    34 msdos_file_update(rtems_libio_t *iop)
    35 {
    36     int              rc = RC_OK;
    37     fat_file_fd_t   *fat_fd = iop->pathinfo.node_access;
    38 
    39     /*
    40      * if fat-file descriptor is not marked as "removed", synchronize
    41      * size, first cluster number, write time and date fields of the file
    42      */
    43     if (!FAT_FILE_IS_REMOVED(fat_fd))
    44     {
    45         rc = msdos_set_first_cluster_num(iop->pathinfo.mt_entry, fat_fd);
    46         if (rc != RC_OK)
    47         {
    48             return rc;
    49         }
    50 
    51         rc = msdos_set_file_size(iop->pathinfo.mt_entry, fat_fd);
    52         if (rc != RC_OK)
    53         {
    54             return rc;
    55         }
    56 
    57         rc = msdos_set_dir_wrt_time_and_date(iop->pathinfo.mt_entry, fat_fd);
    58         if (rc != RC_OK)
    59         {
    60             return rc;
    61         }
    62     }
    63 
    64     return rc;
    65 }
    66 
    67 /* msdos_file_close --
    68  *     Close fat-file which correspondes to the file. If fat-file descriptor
    69  *     which correspondes to the file is not marked "removed", synchronize
    70  *     size, first cluster number, write time and date fields of the file.
    71  *
    72  * PARAMETERS:
    73  *     iop - file control block
    74  *
    75  * RETURNS:
    76  *     RC_OK, if file closed successfully, or -1 if error occured (errno set
    77  *     appropriately)
    78  */
    79 int
    80 msdos_file_close(rtems_libio_t *iop)
    81 {
    82     int                rc = RC_OK;
    83     rtems_status_code  sc = RTEMS_SUCCESSFUL;
    84     msdos_fs_info_t   *fs_info = iop->pathinfo.mt_entry->fs_info;
    85 
    86     sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
    87                                 MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
    88     if (sc != RTEMS_SUCCESSFUL)
    89         rtems_set_errno_and_return_minus_one(EIO);
    90 
    91     rc = msdos_file_update(iop);
    92 
    93     rtems_semaphore_release(fs_info->vol_sema);
    94     return rc;
    95 }
    9632
    9733/* msdos_file_read --
     
    174110    if (iop->offset > fat_fd->fat_file_size)
    175111        fat_fd->fat_file_size = iop->offset;
     112
     113    if (ret > 0)
     114        fat_file_set_ctime_mtime(fat_fd, time(NULL));
    176115
    177116    rtems_semaphore_release(fs_info->vol_sema);
     
    212151      >> FAT_SECTOR512_BITS;
    213152    buf->st_blksize = fs_info->fat.vol.bpc;
     153    buf->st_atime = fat_fd->mtime;
     154    buf->st_ctime = fat_fd->ctime;
    214155    buf->st_mtime = fat_fd->mtime;
    215156
     
    260201    }
    261202
    262     if (rc == RC_OK) {
     203    if (rc == RC_OK)
     204    {
    263205        fat_fd->fat_file_size = length;
     206        fat_file_set_ctime_mtime(fat_fd, time(NULL));
    264207    }
    265208
     
    285228    rtems_status_code  sc = RTEMS_SUCCESSFUL;
    286229    msdos_fs_info_t   *fs_info = iop->pathinfo.mt_entry->fs_info;
    287 
    288     sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
    289                                 MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
    290     if (sc != RTEMS_SUCCESSFUL)
    291         rtems_set_errno_and_return_minus_one(EIO);
    292 
    293     rc = msdos_file_update(iop);
     230    fat_file_fd_t     *fat_fd = iop->pathinfo.node_access;
     231
     232    sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
     233                                MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
     234    if (sc != RTEMS_SUCCESSFUL)
     235        rtems_set_errno_and_return_minus_one(EIO);
     236
     237    rc = fat_file_update(&fs_info->fat, fat_fd);
    294238    if (rc != RC_OK)
    295239    {
  • cpukit/libfs/src/dosfs/msdos_handlers_file.c

    r040ed0b4 ra7eaaae  
    2424const rtems_filesystem_file_handlers_r msdos_file_handlers = {
    2525  .open_h = rtems_filesystem_default_open,
    26   .close_h = msdos_file_close,
     26  .close_h = rtems_filesystem_default_close,
    2727  .read_h = msdos_file_read,
    2828  .write_h = msdos_file_write,
  • cpukit/libfs/src/dosfs/msdos_init.c

    r040ed0b4 ra7eaaae  
    3636}
    3737
     38static int msdos_utime(
     39  const rtems_filesystem_location_info_t *loc,
     40  time_t                                  actime,
     41  time_t                                  modtime
     42)
     43{
     44    fat_file_fd_t *fat_fd = loc->node_access;
     45
     46    if (actime != modtime)
     47        rtems_set_errno_and_return_minus_one( ENOTSUP );
     48
     49    fat_file_set_mtime(fat_fd, modtime);
     50
     51    return RC_OK;
     52}
     53
    3854const rtems_filesystem_operations_table  msdos_ops = {
    3955  .lock_h         =  msdos_lock,
     
    5369  .unmount_h      =  rtems_filesystem_default_unmount,
    5470  .fsunmount_me_h =  msdos_shut_down,
    55   .utime_h        =  rtems_filesystem_default_utime,
     71  .utime_h        =  msdos_utime,
    5672  .symlink_h      =  rtems_filesystem_default_symlink,
    5773  .readlink_h     =  rtems_filesystem_default_readlink,
  • cpukit/libfs/src/dosfs/msdos_misc.c

    r040ed0b4 ra7eaaae  
    380380
    381381        fat_fd->mtime = msdos_date_dos2unix(CF_LE_W(date), CF_LE_W(time_val));
     382
     383        time_val = *MSDOS_DIR_CRT_TIME(node_entry);
     384        date = *MSDOS_DIR_CRT_DATE(node_entry);
     385
     386        fat_fd->ctime = msdos_date_dos2unix(CF_LE_W(date), CF_LE_W(time_val));
    382387
    383388        if ((*MSDOS_DIR_ATTR(node_entry)) & MSDOS_ATTR_DIRECTORY)
     
    671676
    672677
    673 /* msdos_set_dir_wrt_time_and_date --
     678/* fat_file_write_time_and_date --
    674679 *     Write last write date and time for a file to the disk (to corresponded
    675680 *     32bytes node)
    676681 *
    677682 * PARAMETERS:
    678  *     mt_entry - mount table entry
     683 *     fs_info  - fat fs info
    679684 *     fat_fd   - fat-file descriptor
    680685 *
     
    684689 */
    685690int
    686 msdos_set_dir_wrt_time_and_date(
    687     rtems_filesystem_mount_table_entry_t *mt_entry,
     691fat_file_write_time_and_date(
     692    fat_fs_info_t                        *fs_info,
    688693    fat_file_fd_t                        *fat_fd
    689694    )
    690695{
    691     ssize_t          ret1 = 0, ret2 = 0, ret3 = 0;
    692     msdos_fs_info_t *fs_info = mt_entry->fs_info;
     696    int              rc = RC_OK;
     697    ssize_t          ret;
    693698    uint16_t         time_val;
    694699    uint16_t         date;
     
    696701    uint32_t         byte = 0;
    697702
    698     msdos_date_unix2dos(fat_fd->mtime, &date, &time_val);
    699 
    700703    /*
    701704     * calculate input for fat_sector_write: convert (cluster num, offset) to
    702705     * (sector num, new offset)
    703706     */
    704     sec = fat_cluster_num_to_sector_num(&fs_info->fat, fat_fd->dir_pos.sname.cln);
    705     sec += (fat_fd->dir_pos.sname.ofs >> fs_info->fat.vol.sec_log2);
     707    sec = fat_cluster_num_to_sector_num(fs_info, fat_fd->dir_pos.sname.cln);
     708    sec += (fat_fd->dir_pos.sname.ofs >> fs_info->vol.sec_log2);
    706709    /* byte points to start of 32bytes structure */
    707     byte = fat_fd->dir_pos.sname.ofs & (fs_info->fat.vol.bps - 1);
     710    byte = fat_fd->dir_pos.sname.ofs & (fs_info->vol.bps - 1);
     711
     712    msdos_date_unix2dos(fat_fd->mtime, &date, &time_val);
    708713
    709714    time_val = CT_LE_W(time_val);
    710     ret1 = fat_sector_write(&fs_info->fat, sec, byte + MSDOS_FILE_WTIME_OFFSET,
    711                             2, (char *)(&time_val));
     715    ret = fat_sector_write(fs_info, sec, byte + MSDOS_FILE_WTIME_OFFSET,
     716                           2, (char *)(&time_val));
     717    if ( ret < 0 )
     718        rc = -1;
     719
    712720    date = CT_LE_W(date);
    713     ret2 = fat_sector_write(&fs_info->fat, sec, byte + MSDOS_FILE_WDATE_OFFSET,
    714                             2, (char *)(&date));
    715     ret3 = fat_sector_write(&fs_info->fat, sec, byte + MSDOS_FILE_ADATE_OFFSET,
    716                             2, (char *)(&date));
    717 
    718     if ( (ret1 < 0) || (ret2 < 0) || (ret3 < 0) )
    719         return -1;
    720 
    721     return RC_OK;
    722 }
    723 
    724 /* msdos_set_first_cluster_num --
     721    ret = fat_sector_write(fs_info, sec, byte + MSDOS_FILE_WDATE_OFFSET,
     722                           2, (char *)(&date));
     723    if ( ret < 0 )
     724        rc = -1;
     725
     726    ret = fat_sector_write(fs_info, sec, byte + MSDOS_FILE_ADATE_OFFSET,
     727                           2, (char *)(&date));
     728    if ( ret < 0 )
     729        rc = -1;
     730
     731    msdos_date_unix2dos(fat_fd->ctime, &date, &time_val);
     732
     733    time_val = CT_LE_W(time_val);
     734    ret = fat_sector_write(fs_info, sec, byte + MSDOS_FILE_CTIME_OFFSET,
     735                           2, (char *)(&time_val));
     736    if ( ret < 0 )
     737        rc = -1;
     738
     739    date = CT_LE_W(date);
     740    ret = fat_sector_write(fs_info, sec, byte + MSDOS_FILE_CDATE_OFFSET,
     741                           2, (char *)(&date));
     742    if ( ret < 0 )
     743        rc = -1;
     744
     745    return rc;
     746}
     747
     748/* fat_set_first_cluster_num --
    725749 *     Write number of first cluster of the file to the disk (to corresponded
    726750 *     32bytes slot)
    727751 *
    728752 * PARAMETERS:
    729  *     mt_entry - mount table entry
     753 *     fs_info  - fat fs info
    730754 *     fat_fd   - fat-file descriptor
    731755 *
     
    735759 */
    736760int
    737 msdos_set_first_cluster_num(
    738     rtems_filesystem_mount_table_entry_t *mt_entry,
     761fat_file_write_first_cluster_num(
     762    fat_fs_info_t                        *fs_info,
    739763    fat_file_fd_t                        *fat_fd
    740764    )
    741765{
    742766    ssize_t          ret1 = 0, ret2 = 0;
    743     msdos_fs_info_t *fs_info = mt_entry->fs_info;
    744767    uint32_t         new_cln = fat_fd->cln;
    745768    uint16_t         le_cl_low = 0;
     
    752775     * (sector num, new offset)
    753776     */
    754     sec = fat_cluster_num_to_sector_num(&fs_info->fat, fat_fd->dir_pos.sname.cln);
    755     sec += (fat_fd->dir_pos.sname.ofs >> fs_info->fat.vol.sec_log2);
     777    sec = fat_cluster_num_to_sector_num(fs_info, fat_fd->dir_pos.sname.cln);
     778    sec += (fat_fd->dir_pos.sname.ofs >> fs_info->vol.sec_log2);
    756779    /* byte from points to start of 32bytes structure */
    757     byte = fat_fd->dir_pos.sname.ofs & (fs_info->fat.vol.bps - 1);
     780    byte = fat_fd->dir_pos.sname.ofs & (fs_info->vol.bps - 1);
    758781
    759782    le_cl_low = CT_LE_W((uint16_t  )(new_cln & 0x0000FFFF));
    760     ret1 = fat_sector_write(&fs_info->fat, sec,
     783    ret1 = fat_sector_write(fs_info, sec,
    761784                            byte + MSDOS_FIRST_CLUSTER_LOW_OFFSET, 2,
    762785                            (char *)(&le_cl_low));
    763786    le_cl_hi = CT_LE_W((uint16_t  )((new_cln & 0xFFFF0000) >> 16));
    764     ret2 = fat_sector_write(&fs_info->fat, sec,
     787    ret2 = fat_sector_write(fs_info, sec,
    765788                            byte + MSDOS_FIRST_CLUSTER_HI_OFFSET, 2,
    766789                            (char *)(&le_cl_hi));
     
    772795
    773796
    774 /* msdos_set_file size --
     797/* fat_set_file size --
    775798 *     Write file size of the file to the disk (to corresponded 32bytes slot)
    776799 *
    777800 * PARAMETERS:
    778  *     mt_entry - mount table entry
     801 *     fs_info  - fat fs info
    779802 *     fat_fd   - fat-file descriptor
    780803 *
     
    784807 */
    785808int
    786 msdos_set_file_size(
    787     rtems_filesystem_mount_table_entry_t *mt_entry,
     809fat_file_write_file_size(
     810    fat_fs_info_t                        *fs_info,
    788811    fat_file_fd_t                        *fat_fd
    789812    )
    790813{
    791814    ssize_t          ret = 0;
    792     msdos_fs_info_t *fs_info = mt_entry->fs_info;
    793815    uint32_t         le_new_length = 0;
    794816    uint32_t         sec = 0;
    795817    uint32_t         byte = 0;
    796818
    797     sec = fat_cluster_num_to_sector_num(&fs_info->fat, fat_fd->dir_pos.sname.cln);
    798     sec += (fat_fd->dir_pos.sname.ofs >> fs_info->fat.vol.sec_log2);
    799     byte = (fat_fd->dir_pos.sname.ofs & (fs_info->fat.vol.bps - 1));
     819    sec = fat_cluster_num_to_sector_num(fs_info, fat_fd->dir_pos.sname.cln);
     820    sec += (fat_fd->dir_pos.sname.ofs >> fs_info->vol.sec_log2);
     821    byte = (fat_fd->dir_pos.sname.ofs & (fs_info->vol.bps - 1));
    800822
    801823    le_new_length = CT_LE_L((fat_fd->fat_file_size));
    802     ret = fat_sector_write(&fs_info->fat, sec, byte + MSDOS_FILE_SIZE_OFFSET, 4,
     824    ret = fat_sector_write(fs_info, sec, byte + MSDOS_FILE_SIZE_OFFSET, 4,
    803825                           (char *)(&le_new_length));
    804826    if ( ret < 0 )
Note: See TracChangeset for help on using the changeset viewer.