Skip to content

Commit

Permalink
Decode extended time stamp field for greater resolution
Browse files Browse the repository at this point in the history
Mtime field is implemented. Atime, ctime and archive times can apparently also
be decoded, but this is not implemented.
  • Loading branch information
Martin Panter committed Mar 20, 2011
1 parent 9891bfc commit 32ca296
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
52 changes: 52 additions & 0 deletions rarfs/src/fileblock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "fileblock.h"
#include "main.h"
#include <time.h>
#include <ios>

/* MS-DOS time/date conversion routines derived from: */

Expand Down Expand Up @@ -86,6 +87,20 @@ in(in)
in.read(m, filenamesize);
m[filenamesize] = 0;
filename = m;

if ( flags & 0x0400 ) /* Salt field present */
{
in.seekg(min(in.tellg() + std::streamoff(8),
std::streampos(start + headsize)));
}

/* Extended time stamp field present */
if ( flags & 0x1000 &&
in.tellg() + std::streamoff(2) <= start + headsize )
{
ParseXtime();
}

in.seekg(end);

if ( ( flags & 0xE0 ) == 0xE0 )
Expand All @@ -94,6 +109,43 @@ in(in)
folder = false;
}

/* Derived from _parse_ext_time function in "rarfile" Python module.
http://rarfile.berlios.de/ */
void
FileBlock::ParseXtime()
{
unsigned int flags = in.get();
flags += in.get() * 256;
int field = 4;

--field;
unsigned int field_flags = flags >> field * 4 & 0xF;

unsigned long frac = 0; /* 100 ns units; 24 bits */
if ( field_flags & 8 ) /* mtime field present */
{
filedate += field_flags >> 2 & 1;

for ( unsigned int i = 0; i < (field_flags & 3); ++i )
{
frac >>= 8;
frac += in.get() << 16;
}
}
/* Add frac * 100 nanoseconds to timestamp */

/* Not interested in the three other time fields */
while ( field > 0 )
{
--field;
field_flags = flags >> field * 4 & 0xF;
if ( 0 != (field_flags & 8) )
{
in.seekg(field_flags & 3, std::ios::cur);
}
}
}

time_t
FileBlock::GetFileDate()
{
Expand Down
1 change: 1 addition & 0 deletions rarfs/src/fileblock.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class FileBlock : public RARBlock
bool folder;
bool compressed;
time_t filedate;
void ParseXtime();
};


Expand Down

0 comments on commit 32ca296

Please sign in to comment.