Ticket #11120: 0001-Add-support-for-creation-times.patch

File 0001-Add-support-for-creation-times.patch, 7.2 KB (added by MatejHorvat, 10 years ago)
  • src/add-ons/kernel/file_systems/fat/dir.c

    From 0400457755e6b5267e730ab5163733edf58539fa Mon Sep 17 00:00:00 2001
    From: Matej Horvat <matej.horvat@guest.arnes.si>
    Date: Sat, 30 Aug 2014 20:02:56 +0200
    Subject: [PATCH] Add support for creation times
    
    ---
     src/add-ons/kernel/file_systems/fat/dir.c   | 10 ++++++++++
     src/add-ons/kernel/file_systems/fat/dosfs.c |  7 ++++---
     src/add-ons/kernel/file_systems/fat/dosfs.h |  1 +
     src/add-ons/kernel/file_systems/fat/file.c  | 27 ++++++++++++++++++++++++++-
     4 files changed, 41 insertions(+), 4 deletions(-)
    
    diff --git a/src/add-ons/kernel/file_systems/fat/dir.c b/src/add-ons/kernel/file_systems/fat/dir.c
    index 96753be..62eddab 100644
    a b struct _dirent_info_ {  
    4949    uint32 cluster;
    5050    uint32 size;
    5151    uint32 time;
     52    uint32 ctime;
    5253};
    5354
    5455
    _next_dirent_(struct diri *iter, struct _dirent_info_ *oinfo, char *filename,  
    195196            oinfo->cluster += 0x10000*read16(buffer,0x14);
    196197        oinfo->size = read32(buffer,0x1c);
    197198        oinfo->time = read32(buffer,0x16);
     199        oinfo->ctime = read32(buffer,0x0e);
    198200    }
    199201
    200202    diri_next_entry(iter);
    struct _entry_info_ {  
    578580    uint32 cluster;
    579581    uint32 size;
    580582    time_t time;
     583    time_t ctime;
    581584};
    582585
    583586
    _create_dir_entry_(nspace *vol, vnode *dir, struct _entry_info_ *info,  
    728731    memcpy(buffer, nshort, 11);
    729732    buffer[0x0b] = info->mode;
    730733    memset(buffer+0xc, 0, 0x16-0xc);
     734    i = time_t2dos(info->ctime);
     735    buffer[0x0e] = i & 0xff;
     736    buffer[0x0f] = (i >> 8) & 0xff;
     737    buffer[0x10] = (i >> 16) & 0xff;
     738    buffer[0x11] = (i >> 24) & 0xff;
    731739    i = time_t2dos(info->time);
    732740    buffer[0x16] = i & 0xff;
    733741    buffer[0x17] = (i >> 8) & 0xff;
    create_dir_entry(nspace *vol, vnode *dir, vnode *node, const char *name,  
    905913    info.cluster = node->cluster;
    906914    info.size = node->st_size;
    907915    info.time = node->st_time;
     916    info.ctime = node->st_ctim;
    908917
    909918    return _create_dir_entry_(vol, dir, &info, (char *)nshort,
    910919        (char *)nlong, len, ns, ne);
    dosfs_read_vnode(fs_volume *_vol, ino_t vnid, fs_vnode *_node, int *_type,  
    10201029    } else
    10211030        entry->end_cluster = 0;
    10221031    entry->st_time = dos2time_t(info.time);
     1032    entry->st_ctim = dos2time_t(info.ctime);
    10231033#if TRACK_FILENAME
    10241034    entry->filename = malloc(sizeof(filename) + 1);
    10251035    if (entry->filename) strcpy(entry->filename, filename);
  • src/add-ons/kernel/file_systems/fat/dosfs.c

    diff --git a/src/add-ons/kernel/file_systems/fat/dosfs.c b/src/add-ons/kernel/file_systems/fat/dosfs.c
    index f088e3a..f89b182 100644
    a b debug_dvnode(int argc, char **argv)  
    111111        kprintf("\nvnid %Lx, dir vnid %Lx\n", n->vnid, n->dir_vnid);
    112112        kprintf("iteration %lx, si=%lx, ei=%lx, cluster=%lx\n",
    113113            n->iteration, n->sindex, n->eindex, n->cluster);
    114         kprintf("mode %lx, size %Lx, time %lx\n",
    115             n->mode, n->st_size, n->st_time);
     114        kprintf("mode %lx, size %Lx, time %lx, ctim %lx\n",
     115            n->mode, n->st_size, n->st_time, n->st_ctim);
    116116        kprintf("end cluster = %lx\n", n->end_cluster);
    117117        if (n->mime) kprintf("mime type %s\n", n->mime);
    118118    }
    mount_fat_disk(const char *path, fs_volume *_vol, const int flags,  
    651651    vol->root_vnode.sindex = vol->root_vnode.eindex = 0xffffffff;
    652652    vol->root_vnode.mode = FAT_SUBDIR;
    653653    time(&(vol->root_vnode.st_time));
     654    vol->root_vnode.st_ctim = vol->root_vnode.st_time;
    654655    vol->root_vnode.mime = NULL;
    655656    vol->root_vnode.dirty = false;
    656657    dlist_add(vol, vol->root_vnode.vnid);
    dosfs_ioctl(fs_volume *_vol, fs_vnode *_node, void *cookie, uint32 code,  
    11511152
    11521153    switch (code) {
    11531154        case 10002 : /* return real creation time */
    1154                 if (buf) *(bigtime_t *)buf = node->st_time;
     1155                if (buf) *(bigtime_t *)buf = node->st_ctim;
    11551156                break;
    11561157        case 10003 : /* return real last modification time */
    11571158                if (buf) *(bigtime_t *)buf = node->st_time;
  • src/add-ons/kernel/file_systems/fat/dosfs.h

    diff --git a/src/add-ons/kernel/file_systems/fat/dosfs.h b/src/add-ons/kernel/file_systems/fat/dosfs.h
    index 70fc386..0340ca3 100644
    a b typedef struct vnode {  
    8686    uint32      mode;           // dos-style attributes
    8787    off_t       st_size;        // in bytes
    8888    time_t      st_time;
     89    time_t      st_ctim;
    8990
    9091    uint32      end_cluster;    // last cluster of the data
    9192
  • src/add-ons/kernel/file_systems/fat/file.c

    diff --git a/src/add-ons/kernel/file_systems/fat/file.c b/src/add-ons/kernel/file_systems/fat/file.c
    index 5d5f028..51a2a7c 100644
    a b status_t write_vnode_entry(nspace *vol, vnode *node)  
    9494    buffer[0x0b] = node->mode; // file attributes
    9595
    9696    memset(buffer+0xc, 0, 0x16-0xc);
     97    i = time_t2dos(node->st_ctim);
     98    buffer[0x0e] = i & 0xff;
     99    buffer[0x0f] = (i >> 8) & 0xff;
     100    buffer[0x10] = (i >> 16) & 0xff;
     101    buffer[0x11] = (i >> 24) & 0xff;
    97102    i = time_t2dos(node->st_time);
    98103    buffer[0x16] = i & 0xff;
    99104    buffer[0x17] = (i >> 8) & 0xff;
    dosfs_rstat(fs_volume *_vol, fs_vnode *_node, struct stat *st)  
    181186    st->st_blocks = (node->st_size + 511) / 512;
    182187    st->st_blksize = 0x10000; /* this value was chosen arbitrarily */
    183188    st->st_atim.tv_sec = st->st_mtim.tv_sec = st->st_ctim.tv_sec
    184         = st->st_crtim.tv_sec = node->st_time;
     189        = node->st_time;
    185190    st->st_atim.tv_nsec = st->st_mtim.tv_nsec = st->st_ctim.tv_nsec
    186191        = st->st_crtim.tv_nsec = 0;
     192    st->st_crtim.tv_sec = node->st_ctim;
    187193
    188194    UNLOCK_VOL(vol);
    189195
    dosfs_wstat(fs_volume *_vol, fs_vnode *_node, const struct stat *st,  
    254260        dirty = true;
    255261    }
    256262
     263    if (mask & B_STAT_CREATION_TIME) {
     264        DPRINTF(0, ("setting creation time\n"));
     265        // As a file's modification time is also set when it is created,
     266        // the archive bit should be set automatically.
     267        node->st_ctim = st->st_crtime;
     268        dirty = true;
     269    }
     270
    257271    if (dirty) {
    258272        write_vnode_entry(vol, node);
    259273
    dosfs_create(fs_volume *_vol, fs_vnode *_dir, const char *name, int omode,  
    806820        dummy.mode = 0;
    807821        dummy.st_size = 0;
    808822        time(&(dummy.st_time));
     823        dummy.st_ctim = dummy.st_time;
    809824
    810825        if ((result = create_dir_entry(vol, dir, &dummy, name, &(dummy.sindex), &(dummy.eindex))) != B_OK) {
    811826            dprintf("dosfs_create: error creating directory entry for %s (%s)\n", name, strerror(result));
    dosfs_mkdir(fs_volume *_vol, fs_vnode *_dir, const char *name, int perms)  
    906921    }
    907922    dummy.st_size = vol->bytes_per_sector*vol->sectors_per_cluster;
    908923    time(&(dummy.st_time));
     924    dummy.st_ctim = dummy.st_time;
    909925
    910926    dummy.vnid = GENERATE_DIR_CLUSTER_VNID(dummy.dir_vnid, dummy.cluster);
    911927    // XXX: dangerous construct
    dosfs_mkdir(fs_volume *_vol, fs_vnode *_dir, const char *name, int perms)  
    938954    buffer[0] = buffer[0x20] = buffer[0x21] = '.';
    939955    buffer[0x0b] = buffer[0x2b] = FAT_SUBDIR;
    940956    i = time_t2dos(dummy.st_time);
     957    buffer[0x0e] = i & 0xff;
     958    buffer[0x0f] = (i >> 8) & 0xff;
     959    buffer[0x10] = (i >> 16) & 0xff;
     960    buffer[0x11] = (i >> 24) & 0xff;
    941961    buffer[0x16] = i & 0xff;
    942962    buffer[0x17] = (i >> 8) & 0xff;
    943963    buffer[0x18] = (i >> 16) & 0xff;
    944964    buffer[0x19] = (i >> 24) & 0xff;
     965    i = time_t2dos(dir->st_ctim);
     966    buffer[0x2e] = i & 0xff;
     967    buffer[0x2f] = (i >> 8) & 0xff;
     968    buffer[0x30] = (i >> 16) & 0xff;
     969    buffer[0x31] = (i >> 24) & 0xff;
    945970    i = time_t2dos(dir->st_time);
    946971    buffer[0x36] = i & 0xff;
    947972    buffer[0x37] = (i >> 8) & 0xff;