Diff

Differences From Artifact [eb4591d1ce]:

To Artifact [57ce2c31b4]:


1
2
3
4
5
6
7


8
9
10
11
12
13
14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16







+
+







#include <xvfs-core.h>
#include <unistd.h>
#include <string.h>
#include <tcl.h>
#include <sys/stat.h>

#define XVFS_NAME_LOOKUP_ERROR (-1)
#define XVFS_FILE_BLOCKSIZE 1024

#define MIN(a, b) (((a) < (b)) ? (a) : (b))

typedef enum {
	XVFS_FILE_TYPE_REG,
	XVFS_FILE_TYPE_DIR
} xvfs_file_type_t;

25
26
27
28
29
30
31


32
33
34
35
36





37



38
39
40
41











42


43
44
45
46
47
48
49
27
28
29
30
31
32
33
34
35
36
37
38


39
40
41
42
43
44
45
46
47




48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68







+
+



-
-
+
+
+
+
+

+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+

+
+







};

<?
	package require xvfs
	xvfs::main $argv
?>
static long xvfs_<?= $::xvfs::fsName ?>_nameToIndex(const char *path) {
	unsigned int pathHash;
	
	if (path == NULL) {
		return(XVFS_NAME_LOOKUP_ERROR);
	}

<?	for {set index 0} {$index < [llength $::xvfs::outputFiles]} {incr index} {
	
	pathHash = Tcl_ZlibAdler32(0, (const unsigned char *) path, strlen(path));
	switch (pathHash) {
<?
	for {set index 0} {$index < [llength $::xvfs::outputFiles]} {incr index} {
		set outputFile [lindex $::xvfs::outputFiles $index]
		set outputFileHash [zlib adler32 $outputFile 0]
		lappend outputFileHashToIndex($outputFileHash) $index
	}
?>
	if (strcmp(path, "<?= [::xvfs::sanitizeCString $outputFile] ?>") == 0) {
		return(<?= $index ?>);
	}
	
	foreach {outputFileHash outputFileIndexes} [lsort -stride 2 -dictionary [array get outputFileHashToIndex]] {
?>		case <?= $outputFileHash ?>:
<?
			foreach outputFileIndex $outputFileIndexes {
?>			if (strcmp(path, xvfs_<?= $::xvfs::fsName ?>_data[<?= $outputFileIndex ?>].name) == 0) {
				return(<?= $outputFileIndex ?>);
			}
<?
			}
?>			break;
<?	} ?>
	}
	
	return(XVFS_NAME_LOOKUP_ERROR);
}

static const char **xvfs_<?= $::xvfs::fsName ?>_getChildren(const char *path, Tcl_WideInt *count) {
	struct xvfs_file_data *fileInfo;
	long inode;

158
159
160
161
162
163
164
165

166
167
168
169
170
171
172
177
178
179
180
181
182
183

184
185
186
187
188
189
190
191







-
+







	statBuf->st_rdev  = 0;
	statBuf->st_ino   = inode;
	statBuf->st_uid   = -1;
	statBuf->st_gid   = -1;
	statBuf->st_atime = 0;
	statBuf->st_ctime = 0;
	statBuf->st_mtime = 0;
	statBuf->st_blksize = 1024;
	statBuf->st_blksize = XVFS_FILE_BLOCKSIZE;
	
	if (fileInfo->type == XVFS_FILE_TYPE_REG) {
		statBuf->st_mode   = 0400;
		statBuf->st_nlink  = 1;
		statBuf->st_size   = fileInfo->size;
		statBuf->st_blocks = (fileInfo->size + statBuf->st_blksize - 1) / statBuf->st_blksize;
	} else if (fileInfo->type == XVFS_FILE_TYPE_DIR) {