1 #include "renderfarm.h"
2 #include "renderfarmfsserver.h"
11 RenderFarmFSServer::RenderFarmFSServer(RenderFarmServerThread *server)
13 this->server = server;
18 RenderFarmFSServer::~RenderFarmFSServer()
22 void RenderFarmFSServer::initialize()
26 int RenderFarmFSServer::handle_request(int request_id, int request_size, unsigned char *buffer)
31 printf("RenderFarmFSServer::handle_request request_id=%d\n", request_id);
34 case RENDERFARM_FOPEN:
39 unsigned char datagram[8];
45 mode = (char*)buffer + strlen(path) + 1;
48 file = fopen64(path, mode);
49 file_int64 = Units::ptr_to_int64(file);
50 STORE_INT64(file_int64);
51 server->write_socket((char*)datagram, 8, RENDERFARM_TIMEOUT);
53 printf("RenderFarmFSServer::handle_request RENDERFARM_FOPEN file=%p file_int64=%llx datagram=%02x%02x%02x%02x%02x%02x%02x%02x path=%s mode=%s\n",
54 file, file_int64, datagram[0], datagram[1], datagram[2], datagram[3], datagram[4], datagram[5], datagram[6], datagram[7], path, mode);
59 case RENDERFARM_FCLOSE:
61 int64_t pointer = READ_INT64((unsigned char*)buffer);
62 FILE *file = (FILE*)Units::int64_to_ptr(pointer);
64 printf("RenderFarmFSServer::handle_request RENDERFARM_FCLOSE file=%p\n", file);
70 case RENDERFARM_REMOVE:
72 remove((char*)buffer);
74 printf("RenderFarmFSServer::handle_request path=%s\n", buffer);
79 case RENDERFARM_RENAME:
81 char *oldpath = (char*)buffer;
82 char *newpath = (char*)buffer + strlen(oldpath) + 1;
83 rename(oldpath, newpath);
85 printf("RenderFarmFSServer::handle_request old=%s new=%s\n", oldpath, newpath);
90 case RENDERFARM_FGETC:
92 int64_t pointer = READ_INT64((unsigned char*)buffer);
93 FILE *file = (FILE*)Units::int64_to_ptr(pointer);
94 unsigned char datagram[1];
95 datagram[0] = fgetc(file);
96 server->write_socket((char*)datagram, 1, RENDERFARM_TIMEOUT);
98 printf("RenderFarmFSServer::handle_request file=%p\n", file);
103 case RENDERFARM_FPUTC:
105 int64_t pointer = READ_INT64((unsigned char*)buffer);
106 FILE *file = (FILE*)Units::int64_to_ptr(pointer);
107 fputc(buffer[8], file);
110 printf("RenderFarmFSServer::handle_request file=%p\n", file);
114 case RENDERFARM_FREAD:
116 int64_t pointer = READ_INT64((unsigned char*)buffer);
117 FILE *file = (FILE*)Units::int64_to_ptr(pointer);
118 int size = READ_INT32((unsigned char*)buffer + 8);
119 int num = READ_INT32((unsigned char*)buffer + 12);
120 unsigned char datagram[4];
123 // printf("RenderFarmFSServer::handle_request RENDERFARM_FREAD %02x%02x%02x%02x%02x%02x%02x%02x %p %d %d\n",
124 // buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7],
130 server->reallocate_buffer(size * num);
131 bytes = fread(server->buffer, size, num, file);
133 server->write_socket((char*)datagram, 4, RENDERFARM_TIMEOUT);
134 server->write_socket((char*)server->buffer, size * bytes, RENDERFARM_TIMEOUT);
137 printf("RenderFarmFSServer::handle_request file=%p size=%d num=%d bytes=%d\n",
138 file, size, num, bytes);
142 case RENDERFARM_FGETS:
144 int64_t pointer = READ_INT64((unsigned char*)buffer);
145 FILE *file = (FILE*)Units::int64_to_ptr(pointer);
146 int size = READ_INT32((unsigned char*)buffer + 8);
147 unsigned char datagram[4];
150 server->reallocate_buffer(size);
151 char *return_value = fgets((char*)server->buffer, size, file);
155 bytes = strlen(return_value) + 1;
158 server->write_socket((char*)datagram, 4, RENDERFARM_TIMEOUT);
159 server->write_socket((char*)server->buffer, bytes, RENDERFARM_TIMEOUT);
164 case RENDERFARM_FILENO:
166 int64_t pointer = READ_INT64((unsigned char*)buffer);
167 FILE *file = (FILE*)Units::int64_to_ptr(pointer);
168 unsigned char datagram[4];
171 int return_value = fileno(file);
172 STORE_INT32(return_value);
173 server->write_socket((char*)datagram, 4, RENDERFARM_TIMEOUT);
175 printf("RenderFarmFSServer::handle_request file=%p fileno=%d\n",
181 case RENDERFARM_FWRITE:
183 int64_t pointer = READ_INT64((unsigned char*)buffer);
184 FILE *file = (FILE*)Units::int64_to_ptr(pointer);
185 int size = READ_INT32((unsigned char*)buffer + 8);
186 int num = READ_INT32((unsigned char*)buffer + 12);
187 unsigned char datagram[4];
191 server->reallocate_buffer(size * num);
192 server->read_socket((char*)server->buffer, size * num, RENDERFARM_TIMEOUT);
193 bytes = fwrite(server->buffer, size, num, file);
195 server->write_socket((char*)datagram, 4, RENDERFARM_TIMEOUT);
198 printf("RenderFarmFSServer::handle_request RENDERFARM_FWRITE file=%p size=%d num=%d bytes=%d\n",
199 file, size, num, bytes);
203 case RENDERFARM_FSEEK:
205 int64_t pointer = READ_INT64((unsigned char*)buffer);
206 FILE *file = (FILE*)Units::int64_to_ptr(pointer);
207 // printf("RENDERFARM_FSEEK 1 buffer=%02x%02x%02x%02x%02x%02x%02x%02x %p %llx\n",
208 // buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7], file, pointer);
209 int64_t offset = READ_INT64((unsigned char*)buffer + 8);
210 int whence = READ_INT32((unsigned char*)buffer + 16);
212 unsigned char datagram[4];
215 return_value = fseeko64(file, offset, whence);
216 STORE_INT32(return_value);
217 server->write_socket((char*)datagram, 4, RENDERFARM_TIMEOUT);
220 printf("RenderFarmFSServer::handle_request file=%p offset=%lld whence=%d result=%d\n",
221 file, offset, whence, result);
225 case RENDERFARM_FTELL:
227 int64_t pointer = READ_INT64((unsigned char*)buffer);
228 FILE *file = (FILE*)Units::int64_to_ptr(pointer);
229 unsigned char datagram[8];
231 int64_t return_value = ftello64(file);
232 STORE_INT64(return_value);
233 server->write_socket((char*)datagram, 8, RENDERFARM_TIMEOUT);
236 printf("RenderFarmFSServer::handle_request file=%p result=%lld\n",
241 case RENDERFARM_STAT:
243 struct stat stat_buf;
244 int return_value = stat((char*)buffer, &stat_buf);
245 server->write_socket((char*)&stat_buf, sizeof(struct stat), RENDERFARM_TIMEOUT);
248 printf("RenderFarmFSServer::handle_request path=%s result=%d\n",
249 buffer, return_value);
253 case RENDERFARM_STAT64:
255 struct stat64 stat_buf;
256 int return_value = stat64((char*)buffer, &stat_buf);
258 arg.dev = stat_buf.st_dev;
259 // arg.ino32 = stat_buf.__st_ino;
260 arg.ino = stat_buf.st_ino;
261 arg.nlink = stat_buf.st_nlink;
262 arg.mode = stat_buf.st_mode;
263 arg.uid = stat_buf.st_uid;
264 arg.gid = stat_buf.st_gid;
265 arg.rdev = stat_buf.st_rdev;
266 arg.size = stat_buf.st_size;
267 arg.blksize = stat_buf.st_blksize;
268 arg.blocks = stat_buf.st_blocks;
269 arg.atim = stat_buf.st_atim.tv_sec;
270 arg.mtim = stat_buf.st_mtim.tv_sec;
271 arg.ctim = stat_buf.st_ctim.tv_sec;
272 server->write_socket((char*)&arg, sizeof(arg), RENDERFARM_TIMEOUT);
275 printf("RenderFarmFSServer::handle_request path=%s result=%d\n",
276 buffer, return_value);
286 // c-file-style: "linux"