Diff

Differences From Artifact [6b271a3398]:

To Artifact [eb4591d1ce]:


1
2
3
4

5
6
7
8
9
10
11
#include <xvfs-core.h>
#include <unistd.h>
#include <string.h>
#include <tcl.h>


#define XVFS_NAME_LOOKUP_ERROR (-1)
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

typedef enum {
	XVFS_FILE_TYPE_REG,
	XVFS_FILE_TYPE_DIR




>







1
2
3
4
5
6
7
8
9
10
11
12
#include <xvfs-core.h>
#include <unistd.h>
#include <string.h>
#include <tcl.h>
#include <sys/stat.h>

#define XVFS_NAME_LOOKUP_ERROR (-1)
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

typedef enum {
	XVFS_FILE_TYPE_REG,
	XVFS_FILE_TYPE_DIR
127
128
129
130
131
132
133
134



















135



























136
137
138
139
140

141


142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
	*length = resultLength;
	
	/*
	 * Return the data
	 */
	return(fileInfo->data.fileContents + start);
}




















int Xvfs_<?= $::xvfs::fsName ?>_Init(Tcl_Interp *interp) {



























	struct Xvfs_FSInfo fsInfo = {
		.protocolVersion = XVFS_PROTOCOL_VERSION,
		.fsName          = "<?= $::xvfs::fsName ?>",
		.getChildrenProc = xvfs_<?= $::xvfs::fsName ?>_getChildren,
		.getDataProc     = xvfs_<?= $::xvfs::fsName ?>_getData

	};


	int register_ret;

#ifdef USE_TCL_STUBS
	const char *tclInitStubs_ret;
	/* Initialize Stubs */
	tclInitStubs_ret = Tcl_InitStubs(interp, TCL_PATCH_LEVEL, 0);
	if (!tclInitStubs_ret) {
		return(TCL_ERROR);
	}
#endif
	
	register_ret = Xvfs_Register(interp, &fsInfo);
	if (register_ret != TCL_OK) {
		return(register_ret);
	}
	
	return(TCL_OK);
}








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
>
|
>
>











|






128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
	*length = resultLength;
	
	/*
	 * Return the data
	 */
	return(fileInfo->data.fileContents + start);
}

static int xvfs_<?= $::xvfs::fsName ?>_getInfo(const char *path, Tcl_StatBuf *statBuf) {
	struct xvfs_file_data *fileInfo;
	long inode;

	/*
	 * Validate input parameters
	 */
	if (!statBuf) {
		return(-1);
	}
	
	/*
	 * Get the inode from the lookup function
	 */
	inode = xvfs_<?= $::xvfs::fsName ?>_nameToIndex(path);
	if (inode == XVFS_NAME_LOOKUP_ERROR) {
		return(-1);
	}
	
	fileInfo = &xvfs_<?= $::xvfs::fsName ?>_data[inode];
	
	statBuf->st_dev   = 0;
	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;
	
	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) {
		statBuf->st_mode   = 0500;
		statBuf->st_nlink  = fileInfo->size;
		statBuf->st_size   = fileInfo->size;
		statBuf->st_blocks = 1;
	}
	
	return(0);
}


static struct Xvfs_FSInfo xvfs_<?= $::xvfs::fsName ?>_fsInfo = {
	.protocolVersion = XVFS_PROTOCOL_VERSION,
	.name            = "<?= $::xvfs::fsName ?>",
	.getChildrenProc = xvfs_<?= $::xvfs::fsName ?>_getChildren,
	.getDataProc     = xvfs_<?= $::xvfs::fsName ?>_getData,
	.getInfoProc     = xvfs_<?= $::xvfs::fsName ?>_getInfo
};

int Xvfs_<?= $::xvfs::fsName ?>_Init(Tcl_Interp *interp) {
	int register_ret;

#ifdef USE_TCL_STUBS
	const char *tclInitStubs_ret;
	/* Initialize Stubs */
	tclInitStubs_ret = Tcl_InitStubs(interp, TCL_PATCH_LEVEL, 0);
	if (!tclInitStubs_ret) {
		return(TCL_ERROR);
	}
#endif
	
	register_ret = Xvfs_Register(interp, &xvfs_<?= $::xvfs::fsName ?>_fsInfo);
	if (register_ret != TCL_OK) {
		return(register_ret);
	}
	
	return(TCL_OK);
}