git-svn-id: https://profuse.googlecode.com/svn/trunk@43 aa027e90-d47c-11dd-86d7-074df07e0730
This commit is contained in:
ksherlock 2009-05-05 01:04:47 +00:00
parent 1768d932ee
commit cdef6cbc04
3 changed files with 152 additions and 2 deletions

View File

@ -12,6 +12,7 @@
#include <string.h>
#include <stdint.h>
#include <ctype.h>
#include <stdio.h>
/*
@ -25,15 +26,26 @@
* o Year values from 40 to 99 represent 1940 through 1999
* o Year values from 0 to 39 represent 2000 through 2039
*/
/*
* A positive or 0 value for tm_isdst causes mktime() to presume initially
* that Daylight Savings Time, respectively, is or is not in effect for
* the specified time. A negative value for tm_isdst causes mktime() to
* attempt to determine whether Daylight Saving Time is in effect for the
* specified time.
*/
static time_t timeToUnix(unsigned yymmdd, unsigned hhmm)
{
printf("%x %x\n", yymmdd, hhmm);
if (yymmdd == 0) return 0;
tm t;
bzero(&t, sizeof(tm));
t.tm_min = hhmm & 0x3f;
// tm_hour is 0-23, but is_dst -1 compensates
t.tm_hour = (hhmm >> 8) & 0x1f;
t.tm_isdst = -1;
t.tm_mday = yymmdd & 0x1f;
t.tm_mon = ((yymmdd >> 5) & 0x0f) - 1;
@ -42,6 +54,7 @@ static time_t timeToUnix(unsigned yymmdd, unsigned hhmm)
if (t.tm_year <= 39) t.tm_year += 100;
return mktime(&t);
// convert back via locatime & fudge for dst?
}

View File

@ -21,7 +21,7 @@ using std::string;
static bool isTextFile(unsigned ftype, unsigned auxtype)
{
if (ftype == 0x04) return true; // ascii text
if (ftype == 0x80) return true; // source code.
if (ftype == 0xb0) return true; // source code.
if (ftype == 0x50 && auxtype == 0x5445) return true; // teach text
return false;
@ -115,7 +115,7 @@ static void xattr_charset(FileEntry& e, fuse_req_t req, size_t size, off_t off)
//apple.TextEncoding
static void xattr_textencoding(FileEntry& e, fuse_req_t req, size_t size, off_t off)
{
const char attr[] = "MACINTOSH";0;
const char attr[] = "MACINTOSH;0";
unsigned attr_size = sizeof(attr) - 1;
ERROR(!isTextFile(e.file_type, e.aux_type), ENOENT)
@ -285,6 +285,13 @@ static void xattr_finfo(FileEntry& e, fuse_req_t req, size_t size, off_t off)
case SEEDLING_FILE:
case SAPLING_FILE:
case TREE_FILE:
if (size == 0)
{
fuse_reply_xattr(req, attr_size);
return;
}
bzero(attr, attr_size);
set_creator(attr, e.file_type, e.aux_type);
fuse_reply_buf(req, (char *)attr, attr_size);

130
xattr.c Normal file
View File

@ -0,0 +1,130 @@
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <strings.h>
#include <stdio.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/xattr.h>
void dumpxattr(const char *file, const char *attr)
{
ssize_t asize;
char *buffer;
asize = getxattr(file, attr, NULL, 0);
if (asize < 0) return;
printf("%s: %d\n", attr, asize);
buffer = (char *)malloc(asize);
if (!buffer) return;
if ( (asize = getxattr(file, attr, buffer, asize)) > 0)
{
char *cp = buffer;
char buffer1[16 * 3 + 1 + 1];
char buffer2[16 + 1];
ssize_t offset = 0;
unsigned i, j;
unsigned max;
while(asize > 0)
{
memset(buffer1, ' ', sizeof(buffer1));
memset(buffer2, ' ', sizeof(buffer2));
max = asize > 16 ? 16 : asize;
for (i = 0, j = 0; i < max; i++)
{
unsigned x = cp[i];
buffer1[j++] = "0123456789abcdef"[x >> 4];
buffer1[j++] = "0123456789abcdef"[x & 0x0f];
j++;
if (i == 7) j++;
buffer2[i] = isprint(x) ? x : '.';
}
buffer1[sizeof(buffer1)-1] = 0;
buffer2[sizeof(buffer2)-1] = 0;
printf("%06x:\t%s\t%s\n", offset, buffer1, buffer2);
offset += 16;
cp += 16;
asize -= 16;
}
}
free(buffer);
}
void listx(const char *file)
{
ssize_t asize;
char *buffer;
asize = listxattr(file, NULL, 0);
if (asize < 0) return;
buffer = (char *)malloc(asize);
if (!buffer) return;
if ((asize = listxattr(file, buffer, asize)) > 0)
{
char *cp = buffer;
ssize_t len;
while (asize > 0)
{
dumpxattr(file, cp);
len = strlen(cp) + 1;
cp += len;
asize -= len;
}
}
free(buffer);
}
int main(int argc, char **argv)
{
struct stat st;
unsigned i;
ssize_t asize;
for (i = 1; i < argc; ++i)
{
if (stat(argv[i], &st) != 0)
{
fprintf(stderr, "Unable to stat %s\n", argv[i]);
continue;
}
printf("%s\n", argv[i]);
printf("\tChange Time : %s\n", asctime(localtime(&st.st_ctime)));
printf("\tModification Time: %s\n", asctime(localtime(&st.st_mtime)));
printf("\tAccess Time : %s\n", asctime(localtime(&st.st_atime)));
listx(argv[i]);
printf("\n");
}
return 0;
}