From cdef6cbc0470d109f20b82c8f0af7009b92741de Mon Sep 17 00:00:00 2001 From: ksherlock Date: Tue, 5 May 2009 01:04:47 +0000 Subject: [PATCH] fix dst. git-svn-id: https://profuse.googlecode.com/svn/trunk@43 aa027e90-d47c-11dd-86d7-074df07e0730 --- File.cpp | 13 +++++ profuse_xattr.cpp | 11 +++- xattr.c | 130 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 xattr.c diff --git a/File.cpp b/File.cpp index 37e6943..05443d7 100644 --- a/File.cpp +++ b/File.cpp @@ -12,6 +12,7 @@ #include #include #include +#include /* @@ -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? } diff --git a/profuse_xattr.cpp b/profuse_xattr.cpp index cb200dd..1e54fa3 100644 --- a/profuse_xattr.cpp +++ b/profuse_xattr.cpp @@ -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); diff --git a/xattr.c b/xattr.c new file mode 100644 index 0000000..f2a04d2 --- /dev/null +++ b/xattr.c @@ -0,0 +1,130 @@ +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + + +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; +}