[10] | 1 | /* |
---|
| 2 | FTP file system |
---|
| 3 | Copyright (C) 2006 Robson Braga Araujo <robsonbraga@gmail.com> |
---|
| 4 | |
---|
| 5 | This program can be distributed under the terms of the GNU GPL. |
---|
| 6 | See the file COPYING. |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | #define _XOPEN_SOURCE 600 /* glibc2 needs this */ |
---|
| 10 | #include <time.h> |
---|
| 11 | #include <stdlib.h> |
---|
| 12 | #include <stdio.h> |
---|
| 13 | #include <string.h> |
---|
| 14 | #include <assert.h> |
---|
| 15 | |
---|
| 16 | #include "ftpfs.h" |
---|
| 17 | #include "ftpfs-ls.h" |
---|
| 18 | |
---|
| 19 | struct ftpfs ftpfs; |
---|
| 20 | |
---|
| 21 | #define check(sbuf, dev, ino, mode, nlink, uid, gid, \ |
---|
| 22 | rdev, size, blksize, blocks, date) \ |
---|
| 23 | do { \ |
---|
| 24 | struct tm tm; \ |
---|
| 25 | time_t tt; \ |
---|
| 26 | memset(&tm, 0, sizeof(tm)); \ |
---|
| 27 | strptime(date, "%H:%M:%S %d/%m/%Y", &tm); \ |
---|
| 28 | tt = mktime(&tm); \ |
---|
| 29 | assert(sbuf.st_dev == (dev)); \ |
---|
| 30 | assert(sbuf.st_ino == (ino)); \ |
---|
| 31 | assert(sbuf.st_mode == (mode)); \ |
---|
| 32 | assert(sbuf.st_nlink == (nlink)); \ |
---|
| 33 | assert(sbuf.st_uid == (uid)); \ |
---|
| 34 | assert(sbuf.st_gid == (gid)); \ |
---|
| 35 | assert(sbuf.st_rdev == (rdev)); \ |
---|
| 36 | assert(sbuf.st_size == (size)); \ |
---|
| 37 | assert(sbuf.st_blksize == (blksize)); \ |
---|
| 38 | assert(sbuf.st_blocks == (blocks)); \ |
---|
| 39 | assert(sbuf.st_atime == tt); \ |
---|
| 40 | assert(sbuf.st_ctime == tt); \ |
---|
| 41 | assert(sbuf.st_mtime == tt); \ |
---|
| 42 | } while (0); |
---|
| 43 | |
---|
| 44 | int main(int argc, char **argv) { |
---|
| 45 | const char *list; |
---|
| 46 | char line[256]; |
---|
| 47 | struct fuse_cache_operations dummy_oper; |
---|
| 48 | struct stat sbuf; |
---|
| 49 | int err; |
---|
| 50 | struct fuse_args args = FUSE_ARGS_INIT(argc, argv); |
---|
| 51 | char linkbuf[1024]; |
---|
| 52 | char date[20]; |
---|
| 53 | time_t tt; |
---|
| 54 | struct tm tm; |
---|
| 55 | struct tm test_tm; |
---|
| 56 | |
---|
| 57 | ftpfs.debug = 1; |
---|
| 58 | |
---|
| 59 | tt = time(NULL); |
---|
| 60 | gmtime_r(&tt, &tm); |
---|
| 61 | ftpfs.blksize = 4096; |
---|
| 62 | |
---|
| 63 | memset(&dummy_oper, 0, sizeof(dummy_oper)); |
---|
| 64 | err = cache_parse_options(&args); |
---|
| 65 | cache_init(&dummy_oper); |
---|
| 66 | |
---|
| 67 | list = "05-22-03 12:13PM <DIR> chinese_pr\r\n"; |
---|
| 68 | err = parse_dir(list, "/", "chinese_pr", &sbuf, NULL, 0, NULL, NULL); |
---|
| 69 | assert(err == 0); |
---|
| 70 | check(sbuf, 0, 0, S_IFDIR, 1, 0, 0, 0, 0, 0, 0, "12:13:00 22/05/2003"); |
---|
| 71 | |
---|
| 72 | err = parse_dir(list, "/", "hinese_pr", &sbuf, NULL, 0, NULL, NULL); |
---|
| 73 | assert(err == 1); |
---|
| 74 | |
---|
| 75 | list = "05-14-03 02:49PM 40448 PR_AU13_CH.doc\r\n"; |
---|
| 76 | err = parse_dir(list, "/", "PR_AU13_CH.doc", &sbuf, NULL, 0, NULL, NULL); |
---|
| 77 | assert(err == 0); |
---|
| 78 | check(sbuf, 0, 0, S_IFREG, 1, 0, 0, 0, 40448, 4096, 80, "14:49:00 14/05/2003"); |
---|
| 79 | |
---|
| 80 | list = "11-25-04 09:17AM 20075882 242_310_Condor_en_ok.pdf\r\n"; |
---|
| 81 | err = parse_dir(list, "/", "242_310_Condor_en_ok.pdf", &sbuf, NULL, 0, NULL, NULL); |
---|
| 82 | assert(err == 0); |
---|
| 83 | check(sbuf, 0, 0, S_IFREG, 1, 0, 0, 0, 20075882, 4096, 39216, "09:17:00 25/11/2004"); |
---|
| 84 | |
---|
| 85 | list = "lrwxrwxrwx 1 1 17 Nov 24 2002 lg -> cidirb/documentos\r\n"; |
---|
| 86 | err = parse_dir(list, "/", "lg", &sbuf, linkbuf, 1024, NULL, NULL); |
---|
| 87 | assert(err == 0); |
---|
| 88 | assert(!strcmp(linkbuf, "cidirb/documentos")); |
---|
| 89 | check(sbuf, 0, 0, S_IFLNK|S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH, 1, 0, 0, 0, 17, 4096, 8, "00:00:00 24/11/2002"); |
---|
| 90 | |
---|
| 91 | list = "lrwxrwxrwx 1 1137 1100 14 Mar 12 2004 molbio -> Science/molbio\r\n"; |
---|
| 92 | err = parse_dir(list, "/", "molbio", &sbuf, linkbuf, 1024, NULL, NULL); |
---|
| 93 | assert(err == 0); |
---|
| 94 | assert(!strcmp(linkbuf, "Science/molbio")); |
---|
| 95 | check(sbuf, 0, 0, S_IFLNK|S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH, 1, 0, 0, 0, 14, 4096, 8, "00:00:00 12/03/2004"); |
---|
| 96 | |
---|
| 97 | // Test a date six months in the past |
---|
| 98 | test_tm = tm; |
---|
| 99 | test_tm.tm_mon -= 6; |
---|
| 100 | if (test_tm.tm_mon < 0) { |
---|
| 101 | test_tm.tm_mon += 12; |
---|
| 102 | test_tm.tm_year--; |
---|
| 103 | } |
---|
| 104 | strftime(line, 256, |
---|
| 105 | "drwxr-xr-x 4 robson users 4096 %b %d 00:00 tests\r\n", &test_tm); |
---|
| 106 | err = parse_dir(line, "/", "tests", &sbuf, NULL, 0, NULL, NULL); |
---|
| 107 | assert(err == 0); |
---|
| 108 | strftime(date, 20, "00:00:00 %d/%m/%Y", &test_tm); |
---|
| 109 | check(sbuf, 0, 0, S_IFDIR|S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH, 4, 0, 0, 0, 4096, 4096, 8, date); |
---|
| 110 | |
---|
| 111 | list = "dr-xr-xr-x 2 root 512 Apr 8 1994 etc\r\n"; |
---|
| 112 | err = parse_dir(list, "/", "etc", &sbuf, NULL, 0, NULL, NULL); |
---|
| 113 | assert(err == 0); |
---|
| 114 | check(sbuf, 0, 0, S_IFDIR|S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH, 2, 0, 0, 0, 512, 4096, 8, "00:00:00 08/04/1994"); |
---|
| 115 | |
---|
| 116 | // Test a date a little bit in the past |
---|
| 117 | test_tm = tm; |
---|
| 118 | strftime(line, 256, |
---|
| 119 | "---------- 1 robson users 1803128 %b %d 00:00 ls-lR.Z\r\n", |
---|
| 120 | &test_tm); |
---|
| 121 | err = parse_dir(line, "/", "ls-lR.Z", &sbuf, NULL, 0, NULL, NULL); |
---|
| 122 | assert(err == 0); |
---|
| 123 | strftime(date, 20, "00:00:00 %d/%m/%Y", &test_tm); |
---|
| 124 | check(sbuf, 0, 0, S_IFREG, 1, 0, 0, 0, 1803128, 4096, 3528, date); |
---|
| 125 | |
---|
| 126 | // Test a file with space |
---|
| 127 | list = "-rw-r--r-- 1 robson users 1803128 Jan 01 2001 test\r\n"; |
---|
| 128 | err = parse_dir(list, "/", " test", &sbuf, NULL, 0, NULL, NULL); |
---|
| 129 | assert(err == 0); |
---|
| 130 | check(sbuf, 0, 0, S_IFREG|S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH, 1, 0, 0, 0, 1803128, 4096, 3528, "00:00:00 01/01/2001"); |
---|
| 131 | |
---|
| 132 | list = "drwxrwsr-x+ 14 cristol molvis 1024 Feb 17 2000 v2\r\n"; |
---|
| 133 | err = parse_dir(list, "/", "v2", &sbuf, NULL, 0, NULL, NULL); |
---|
| 134 | assert(err == 0); |
---|
| 135 | check(sbuf, 0, 0, S_IFDIR|S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IXOTH, 14, 0, 0, 0, 1024, 4096, 8, "00:00:00 17/02/2000"); |
---|
| 136 | |
---|
| 137 | list = "drwxrwsr-x+144 cristol molvis 10240 Dec 31 2005 v11\r\n"; |
---|
| 138 | err = parse_dir(list, "/", "v11", &sbuf, NULL, 0, NULL, NULL); |
---|
| 139 | assert(err == 0); |
---|
| 140 | check(sbuf, 0, 0, S_IFDIR|S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IXOTH, 144, 0, 0, 0, 10240, 4096, 24, "00:00:00 31/12/2005"); |
---|
| 141 | |
---|
| 142 | list = "-rw------- 1 6700 2000 6561177600 Oct 15 2005 home.backup.tar\r\n"; |
---|
| 143 | err = parse_dir(list, "/", "home.backup.tar", &sbuf, NULL, 0, NULL, NULL); |
---|
| 144 | assert(err == 0); |
---|
| 145 | check(sbuf, 0, 0, S_IFREG|S_IRUSR|S_IWUSR, 1, 0, 0, 0, 6561177600LL, 4096, 4426192, "00:00:00 15/10/2005"); |
---|
| 146 | |
---|
| 147 | return 0; |
---|
| 148 | } |
---|