r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / renderfarmfsclient.C
blobe0fc4f6ec05596e01b1c6d357bcfb0b537b921ea
1 // Disable 64 bit indirections so we can override both functions.
2 #undef _LARGEFILE64_SOURCE
3 #undef _LARGEFILE_SOURCE
4 #undef _FILE_OFFSET_BITS
6 #include "mutex.h"
7 #include "renderfarm.h"
8 #include "renderfarmclient.h"
9 #include "renderfarmfsclient.h"
10 #include "renderfarmfsserver.inc"
11 #include "units.h"
13 #include <dlfcn.h>
14 #include <fcntl.h>
15 #include <stdarg.h>
16 #include <stdio.h>
17 #include <string.h>
18 #include <sys/stat.h>
19 #include <unistd.h>
22 #define DEBUG 0
24 // These are hacks to get all the file I/O libraries to transparently 
25 // go over the network without rewriting them.
28 extern "C"
37 RenderFarmFSClient *renderfarm_fs_global = 0;
41 FILE* fopen(const char *path, const char *mode)
43         static FILE* (*func)(const char *path, const char *mode) = 0;
44 // This pointer is meaningless except on the server.
45         FILE *result = 0;
47 //printf("fopen %s\n", path);
48         if (!func)
49         func = (FILE*(*)(const char *path, const char *mode))dlsym(RTLD_NEXT, "fopen");
51 // VFS path
52         if(!strncmp(path, RENDERFARM_FS_PREFIX, strlen(RENDERFARM_FS_PREFIX)))
53         {
54                 renderfarm_fs_global->lock();
55                 result = renderfarm_fs_global->fopen(path, mode);
56                 renderfarm_fs_global->unlock();
57         }
58         else
59                 result = (*func)(path, mode);
61     return result;
64 FILE* fopen64(const char *path, const char *mode)
66         static FILE* (*func)(const char *path, const char *mode) = 0;
67 // This pointer is meaningless except on the server.
68         FILE *result = 0;
70 //printf("fopen64 %s\n", path);
71         if (!func)
72         func = (FILE*(*)(const char *path, const char *mode))dlsym(RTLD_NEXT, "fopen64");
74 // VFS path
75         if(!strncmp(path, RENDERFARM_FS_PREFIX, strlen(RENDERFARM_FS_PREFIX)))
76         {
77                 renderfarm_fs_global->lock();
78                 result = renderfarm_fs_global->fopen(path, mode);
79                 renderfarm_fs_global->unlock();
80         }
81         else
82                 result = (*func)(path, mode);
84     return result;
89 int fclose(FILE *file)
91         static int (*func)(FILE *) = 0;
92         int result = 0, done = 0;
93         if(!func)
94         func = (int(*)(FILE *))dlsym(RTLD_NEXT, "fclose");
95 //printf("fclose\n");
97         if(renderfarm_fs_global)
98         {
99                 renderfarm_fs_global->lock();
100                 if(renderfarm_fs_global->is_open(file))
101                 {
102                         result = renderfarm_fs_global->fclose(file);
103                         done = 1;
104                 }
105                 renderfarm_fs_global->unlock();
106         }
108         if(!done) result = (*func)(file);
109         return result;
112 // int fflush(FILE *file)
113 // {
114 //      static int (*func)(FILE *) = 0;
115 //      int result = 0, done = 0;
116 //      if(!func)
117 //      func = (int(*)(FILE *))dlsym(RTLD_NEXT, "fflush");
118 // //printf("fflush\n");
119 // 
120 //      renderfarm_fs_global->lock();
121 //      if(renderfarm_fs_global->is_open(file))
122 //      {
123 //              result = renderfarm_fs_global->fflush(file);
124 //              done = 1;
125 //      }
126 //      renderfarm_fs_global->unlock();
127 //      
128 //      if(!done) result = (*func)(file);
129 //      return result;
130 // }
132 int remove (__const char *__filename)
134         static int (*func)(__const char *) = 0;
135         int result = 0;
136         if(!func)
137         func = (int(*)(__const char *))dlsym(RTLD_NEXT, "remove");
138 //printf("remove\n");
140 // VFS path
141         if(!strncmp(__filename, RENDERFARM_FS_PREFIX, strlen(RENDERFARM_FS_PREFIX)))
142         {
143                 renderfarm_fs_global->lock();
144                 result = renderfarm_fs_global->remove(__filename);
145                 renderfarm_fs_global->unlock();
146         }
147         else
148                 result = (*func)(__filename);
150         return result;
153 int rename (__const char *__old, __const char *__new)
155         static int (*func)(__const char *, __const char *) = 0;
156         int result = 0;
157         if(!func)
158         func = (int(*)(__const char *, __const char *))dlsym(RTLD_NEXT, "rename");
159 //printf("rename\n");
161 // VFS path
162         if(!strncmp(__old, RENDERFARM_FS_PREFIX, strlen(RENDERFARM_FS_PREFIX)))
163         {
164                 renderfarm_fs_global->lock();
165                 result = renderfarm_fs_global->rename(__old, __new);
166                 renderfarm_fs_global->unlock();
167         }
168         else
169                 result = (*func)(__old, __new);
171         return result;
174 int fgetc (FILE *__stream)
176         static int (*func)(FILE *) = 0;
177         int result = 0, done = 0;
178         if(!func)
179         func = (int(*)(FILE *))dlsym(RTLD_NEXT, "fgetc");
180 //printf("fgetc\n");
182         if(renderfarm_fs_global)
183         {
184                 renderfarm_fs_global->lock();
185                 if(renderfarm_fs_global->is_open(__stream))
186                 {
187                         result = renderfarm_fs_global->fgetc(__stream);
188                         done = 1;
189                 }
190                 renderfarm_fs_global->unlock();
191         }
193         if(!done) result = (*func)(__stream);
194         return result;
197 int getc (FILE *__stream)
199         return fgetc(__stream);
202 int fputc (int __c, FILE *__stream)
204         static int (*func)(int, FILE *) = 0;
205         int result = 0, done = 0;
206         if(!func)
207         func = (int(*)(int, FILE *))dlsym(RTLD_NEXT, "fputc");
208 //printf("fputc\n");
210         if(renderfarm_fs_global)
211         {
212                 renderfarm_fs_global->lock();
213                 if(renderfarm_fs_global->is_open(__stream))
214                 {
215                         result = renderfarm_fs_global->fputc(__c, __stream);
216                         done = 1;
217                 }
218                 renderfarm_fs_global->unlock();
219         }
221         if(!done) result = (*func)(__c, __stream);
222         return result;
225 int putc (int __c, FILE *__stream)
227         return fputc(__c, __stream);
230 size_t fread (void *__restrict __ptr, size_t __size,
231                      size_t __n, FILE *__restrict __stream)
233         static int (*func)(void *, size_t, size_t, FILE *) = 0;
234         size_t result = 0;
235         int done = 0;
236         if(!func)
237         func = (int(*)(void *, size_t, size_t, FILE *))dlsym(RTLD_NEXT, "fread");
238 //printf("fread\n");
240         if(renderfarm_fs_global)
241         {
242                 renderfarm_fs_global->lock();
243                 if(renderfarm_fs_global->is_open(__stream))
244                 {
245                         result = renderfarm_fs_global->fread(__ptr, __size, __n, __stream);
246                         done = 1;
247                 }
248                 renderfarm_fs_global->unlock();
249         }
251         if(!done) result = (*func)(__ptr, __size, __n, __stream);
253         return result;
256 size_t fwrite (__const void *__restrict __ptr, size_t __size,
257                       size_t __n, FILE *__restrict __s)
259         static int (*func)(__const void *, size_t, size_t, FILE *) = 0;
260         size_t result = 0;
261         int done = 0;
262         if(!func)
263         func = (int(*)(__const void *, size_t, size_t, FILE *))dlsym(RTLD_NEXT, "fwrite");
264 //printf("fwrite\n");
266         if(renderfarm_fs_global)
267         {
268                 renderfarm_fs_global->lock();
269                 if(renderfarm_fs_global->is_open(__s))
270                 {
271                         result = renderfarm_fs_global->fwrite(__ptr, __size, __n, __s);
272                         done = 1;
273                 }
274                 renderfarm_fs_global->unlock();
275         }
277         if(!done) result = (*func)(__ptr, __size, __n, __s);
279         return result;
282 int fseek (FILE *__stream, long int __off, int __whence)
284         static int (*func)(FILE *, long int, int) = 0;
285         int result = 0;
286         int done = 0;
287         if(!func)
288         func = (int(*)(FILE *, long int, int))dlsym(RTLD_NEXT, "fseek");
289 //printf("fseek\n");
291         if(renderfarm_fs_global)
292         {
293                 renderfarm_fs_global->lock();
294                 if(renderfarm_fs_global->is_open(__stream))
295                 {
296                         result = renderfarm_fs_global->fseek(__stream, __off, __whence);
297                         done = 1;
298                 }
299                 renderfarm_fs_global->unlock();
300         }
302         if(!done) result = (*func)(__stream, __off, __whence);
304         return result;
307 int fseeko64 (FILE *__stream, __off64_t __off, int __whence)
309         static int (*func)(FILE *, __off64_t, int) = 0;
310         int result = 0;
311         int done = 0;
312         if(!func)
313         func = (int(*)(FILE *, __off64_t, int))dlsym(RTLD_NEXT, "fseeko64");
314 //printf("fseeko64\n");
316         if(renderfarm_fs_global)
317         {
318                 renderfarm_fs_global->lock();
319                 if(renderfarm_fs_global->is_open(__stream))
320                 {
321                         result = renderfarm_fs_global->fseek(__stream, __off, __whence);
322                         done = 1;
323                 }
324                 renderfarm_fs_global->unlock();
325         }
327         if(!done) result = (*func)(__stream, __off, __whence);
329         return result;
332 long int ftell (FILE *__stream)
334         static long int (*func)(FILE *) = 0;
335         int result = 0;
336         int done = 0;
337         if(!func)
338         func = (long int(*)(FILE *))dlsym(RTLD_NEXT, "ftell");
339 //printf("ftell\n");
341         if(renderfarm_fs_global)
342         {
343                 renderfarm_fs_global->lock();
344                 if(renderfarm_fs_global->is_open(__stream))
345                 {
346                         result = renderfarm_fs_global->ftell(__stream);
347                         done = 1;
348                 }
349                 renderfarm_fs_global->unlock();
350         }
352         if(!done) result = (*func)(__stream);
354         return result;
357 __off64_t ftello64 (FILE *__stream)
359         static __off64_t (*func)(FILE *) = 0;
360         __off64_t result = 0;
361         int done = 0;
362         if(!func)
363         func = (__off64_t(*)(FILE *))dlsym(RTLD_NEXT, "ftello64");
365         if(renderfarm_fs_global)
366         {
367                 renderfarm_fs_global->lock();
368                 if(renderfarm_fs_global->is_open(__stream))
369                 {
370                         result = renderfarm_fs_global->ftell(__stream);
371                         done = 1;
372                 }
373                 renderfarm_fs_global->unlock();
374         }
376         if(!done) result = (*func)(__stream);
378         return result;
379         return (*func)(__stream);
382 // Glibc inlines the stat functions and redirects them to __xstat functions
383 int __xstat (int __ver, __const char *__filename,
384                     struct stat *__stat_buf)
386         static int (*func)(int __ver, __const char *__filename,
387                     struct stat *__stat_buf) = 0;
388 // This pointer is meaningless except on the server.
389         int result = 0;
391         if (!func)
392         func = (int(*)(int __ver, __const char *__filename,
393                     struct stat *__stat_buf))dlsym(RTLD_NEXT, "__xstat");
395 // VFS path
396         if(!strncmp(__filename, RENDERFARM_FS_PREFIX, strlen(RENDERFARM_FS_PREFIX)))
397         {
398                 renderfarm_fs_global->lock();
399                 result = renderfarm_fs_global->stat(__filename, __stat_buf);
400                 renderfarm_fs_global->unlock();
401         }
402         else
403                 result = (*func)(__ver, __filename, __stat_buf);
405     return result;
408 int __xstat64 (int __ver, __const char *__filename,
409                       struct stat64 *__stat_buf)
411         static int (*func)(int __ver, __const char *__restrict __file,
412                  struct stat64 *__restrict __buf) = 0;
413 // This pointer is meaningless except on the server.
414         int result = 0;
416         if (!func)
417         func = (int(*)(int __ver, __const char *__restrict __file,
418                                         struct stat64 *__restrict __buf))dlsym(RTLD_NEXT, "__xstat64");
420 // VFS path
421         if(!strncmp(__filename, RENDERFARM_FS_PREFIX, strlen(RENDERFARM_FS_PREFIX)))
422         {
423                 renderfarm_fs_global->lock();
424                 result = renderfarm_fs_global->stat64(__filename, __stat_buf);
425                 renderfarm_fs_global->unlock();
426         }
427         else
428                 result = (*func)(__ver, __filename, __stat_buf);
430     return result;
433 char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream)
435         static char* (*func)(char *__restrict __s, int __n, FILE *__restrict __stream) = 0;
436         char *result = 0;
437         int done = 0;
438         if(!func)
439         func = (char*(*)(char *__restrict __s, int __n, FILE *__restrict __stream))dlsym(RTLD_NEXT, "fgets");
441         if(renderfarm_fs_global)
442         {
443                 renderfarm_fs_global->lock();
444                 if(renderfarm_fs_global->is_open(__stream))
445                 {
446                         result = renderfarm_fs_global->fgets(__s, __n, __stream);
447                         done = 1;
448                 }
449                 renderfarm_fs_global->unlock();
450         }
452         if(!done) result = (*func)(__s, __n, __stream);
454         return result;
481 RenderFarmFSClient::RenderFarmFSClient(RenderFarmClientThread *client)
483         mutex_lock = new Mutex;
484         this->client = client;
487 RenderFarmFSClient::~RenderFarmFSClient()
489         delete mutex_lock;
490 // Must not access filesystem until we get here
491         renderfarm_fs_global = 0;
494 void RenderFarmFSClient::initialize()
496         renderfarm_fs_global = this;
499 void RenderFarmFSClient::lock()
501         mutex_lock->lock();
504 void RenderFarmFSClient::unlock()
506         mutex_lock->unlock();
509 int RenderFarmFSClient::is_open(FILE *ptr)
511         for(int i = 0; i < files.total; i++)
512                 if(files.values[i] == ptr) return 1;
513         return 0;
516 void RenderFarmFSClient::set_open(FILE *ptr)
518         files.append(ptr);
521 void RenderFarmFSClient::unset_open(FILE *ptr)
523         files.remove(ptr);
527 FILE* RenderFarmFSClient::fopen(const char *path, const char *mode)
529         int len = strlen(path) - strlen(RENDERFARM_FS_PREFIX) + strlen(mode) + 2;
530         char *buffer = new char[len];
531         FILE *file = 0;
532         strcpy(buffer, path + strlen(RENDERFARM_FS_PREFIX));
533         strcpy(buffer + strlen(buffer) + 1, mode);
536         client->lock();
537         if(!client->send_request_header(RENDERFARM_FOPEN, 
538                 len))
539         {
540                 if(client->write_socket(buffer, len, RENDERFARM_TIMEOUT) == len)
541                 {
542                         unsigned char data[8];
543                         if(client->read_socket((char*)data, 8, RENDERFARM_TIMEOUT) == 8)
544                         {
545                                 int64_t file_int64 = READ_INT64(data);
546                                 file = (FILE*)Units::int64_to_ptr(file_int64);
547                         }
548                 }
549         }
550         client->unlock();
551         if(file) set_open(file);
552         delete [] buffer;
554 if(DEBUG)
555 printf("RenderFarmFSClient::fopen path=%s mode=%s file=%p\n", path, mode, file);
557         return file;
560 int RenderFarmFSClient::fclose(FILE *file)
562         int result = 0;
563         unsigned char datagram[8];
564         int i = 0;
565         int file_int64 = Units::ptr_to_int64(file);
566         STORE_INT64(file_int64);
568         client->lock();
569         if(!client->send_request_header(RENDERFARM_FCLOSE, 8))
570         {
571                 if(client->write_socket((char*)datagram, 8, RENDERFARM_TIMEOUT) == 8)
572                         result = 0;
573                 else
574                         result = -1;
575         }
576         else
577                 result = -1;
578         client->unlock();
579         unset_open(file);
580 if(DEBUG)
581 printf("RenderFarmFSClient::fclose file=%p\n", file);
582         return result;
585 int RenderFarmFSClient::remove (__const char *__filename)
587         int result = 0;
588         int len = strlen(__filename) + 1;
589         char *datagram = new char[len];
590         strcpy(datagram, __filename);
591         
592         client->lock();
593         if(!client->send_request_header(RENDERFARM_REMOVE, len))
594         {
595                 if(client->write_socket(datagram, len, RENDERFARM_TIMEOUT) != len)
596                         result = -1;
597                 else
598                         result = 0;
599         }
600         else
601                 result = -1;
602         client->unlock();
604         delete [] datagram;
605 if(DEBUG)
606 printf("RenderFarmFSClient::remove path=%s\n", __filename);
607         return result;
610 int RenderFarmFSClient::rename (__const char *__old, __const char *__new)
612         int result = 0;
613         int len = strlen(__old) + 1 + strlen(__new) + 1;
614         char *datagram = new char[len];
615         strcpy(datagram, __old);
616         strcpy(datagram + strlen(__old) + 1, __new);
617         
618         client->lock();
619         if(!client->send_request_header(RENDERFARM_RENAME, len))
620         {
621                 if(client->write_socket(datagram, len, RENDERFARM_TIMEOUT) != len)
622                         result = -1;
623                 else
624                         result = 0;
625         }
626         else
627                 result = -1;
628         client->unlock();
630         delete [] datagram;
631 if(DEBUG)
632 printf("RenderFarmFSClient::remove old=%s new=%s\n", __old, __new);
633         return result;
636 int RenderFarmFSClient::fgetc (FILE *__stream)
638         int result = 0;
639         unsigned char datagram[8];
640         int i = 0;
641         int file_int64 = Units::ptr_to_int64(__stream);
642         STORE_INT64(file_int64);
643         
644         client->lock();
645         if(!client->send_request_header(RENDERFARM_FGETC, 8))
646         {
647                 if(client->write_socket((char*)datagram, 8, RENDERFARM_TIMEOUT) != 8)
648                         result = -1;
649                 else
650                 {
651                         if(client->read_socket((char*)datagram, 1, RENDERFARM_TIMEOUT) != 1)
652                                 result = -1;
653                         else
654                         {
655                                 result = datagram[0];
656                         }
657                 }
658         }
659         else
660                 result = -1;
661         client->unlock();
662 if(DEBUG)
663 printf("RenderFarmFSClient::fgetc file=%p result=%02x\n", __stream, result);
665         return result;
668 int RenderFarmFSClient::fputc (int __c, FILE *__stream)
670         int result = 0;
671         unsigned char datagram[9];
672         int i = 0;
673         int file_int64 = Units::ptr_to_int64(__stream);
674         STORE_INT64(file_int64);
675         datagram[i++] = __c;
676         
677         client->lock();
678         if(!client->send_request_header(RENDERFARM_FPUTC, 9))
679         {
680                 if(client->write_socket((char*)datagram, 9, RENDERFARM_TIMEOUT) != 9)
681                         result = -1;
682                 else
683                         result = __c;
684         }
685         else
686                 result = -1;
687         client->unlock();
688 if(DEBUG)
689 printf("RenderFarmFSClient::fputc file=%p result=%02x\n", __stream, result);
691         return result;
694 char* RenderFarmFSClient::fgets (char *__restrict __s, int __n, FILE *__restrict __stream)
696         char *result = 0;
697         int bytes = 0;
698         unsigned char datagram[12];
699         int i = 0;
700         int file_int64 = Units::ptr_to_int64(__stream);
701         STORE_INT64(file_int64);
702         STORE_INT32(__n);
703         
704         client->lock();
705         if(!client->send_request_header(RENDERFARM_FGETS, 12))
706         {
707                 if(client->write_socket((char*)datagram, 12, RENDERFARM_TIMEOUT) == 12)
708                 {
709 // fgets bytes to follow
710                         if(client->read_socket((char*)datagram, 4, RENDERFARM_TIMEOUT) == 4)
711                         {
712 // fgets data
713                                 bytes = READ_INT32(datagram);
714                                 if(bytes)
715                                 {
716                                         if(client->read_socket((char*)__s, bytes, RENDERFARM_TIMEOUT) == bytes)
717                                         {
718                                                 result = __s;
719                                         }
720                                 }
721                         }
722                 }
723         }
724         else
725                 result = 0;
726         client->unlock();
727 if(DEBUG)
728 printf("RenderFarmFSClient::fgets file=%p string=%p size=%d bytes=%p\n", 
729 __stream, __s, bytes, bytes);
731         return result;
735 size_t RenderFarmFSClient::fread (void *__restrict __ptr, size_t __size,
736                      size_t __n, FILE *__restrict __stream)
738         size_t result = 0;
739         unsigned char datagram[16];
740         int i = 0;
741         int file_int64 = Units::ptr_to_int64(__stream);
742         STORE_INT64(file_int64);
743         STORE_INT32(__size);
744         STORE_INT32(__n);
745         
746         client->lock();
747         if(!client->send_request_header(RENDERFARM_FREAD, 16))
748         {
749                 if(client->write_socket((char*)datagram, 16, RENDERFARM_TIMEOUT) != 16)
750                         result = 0;
751                 else
752                 {
753 // fread result
754                         if(client->read_socket((char*)datagram, 4, RENDERFARM_TIMEOUT) != 4)
755                                 result = 0;
756                         else
757                         {
758 // fread data
759                                 result = READ_INT32(datagram);
760                                 if(client->read_socket((char*)__ptr, __size * result, RENDERFARM_TIMEOUT) != 
761                                         __size * result)
762                                         result = 0;
763                         }
764                 }
765         }
766         else
767                 result = 0;
768         client->unlock();
769 if(DEBUG)
770 printf("RenderFarmFSClient::fread file=%p size=%d num=%d result=%d\n", 
771 __stream, __size, __n, result);
773         return result;
776 size_t RenderFarmFSClient::fwrite (__const void *__restrict __ptr, size_t __size,
777                       size_t __n, FILE *__restrict __s)
779         size_t result = 0;
780         unsigned char datagram[16];
781         int i = 0;
782         int file_int64 = Units::ptr_to_int64(__s);
783         STORE_INT64(file_int64);
784         STORE_INT32(__size);
785         STORE_INT32(__n);
786         
787         client->lock();
788         if(!client->send_request_header(RENDERFARM_FWRITE, 16))
789         {
790                 if(client->write_socket((char*)datagram, 16, RENDERFARM_TIMEOUT) != 16)
791                         result = 0;
792                 else
793                 {
794 // fwrite data
795                         if(client->write_socket((char*)__ptr, __size * __n, RENDERFARM_TIMEOUT) != 
796                                 __size * __n)
797                         result = 0;
798                         else
799                         {
800 // fwrite result
801                                 if(client->read_socket((char*)datagram, 4, RENDERFARM_TIMEOUT) != 4)
802                                         result = 0;
803                                 else
804                                 {
805                                         result = READ_INT32(datagram);
806                                 }
807                         }
808                 }
809         }
810         else
811                 result = 0;
812         client->unlock();
813 if(DEBUG)
814 printf("RenderFarmFSClient::fwrite file=%p size=%d num=%d result=%d\n", 
815 __s, __size, __n, result);
817         return result;
820 int RenderFarmFSClient::fseek (FILE *__stream, int64_t __off, int __whence)
822         int result = 0;
823         unsigned char datagram[20];
824         int i = 0;
825         int file_int64 = Units::ptr_to_int64(__stream);
826         STORE_INT64(file_int64);
827         STORE_INT64(__off);
828         STORE_INT32(__whence);
830         client->lock();
831         if(!client->send_request_header(RENDERFARM_FSEEK, 20))
832         {
833                 if(client->write_socket((char*)datagram, 20, RENDERFARM_TIMEOUT) != 20)
834                         result = -1;
835                 else
836                 {
837                         if(client->read_socket((char*)datagram, 4, RENDERFARM_TIMEOUT) != 4)
838                                 result = -1;
839                         else
840                                 result = READ_INT32(datagram);
841                 }
842         }
843         else
844                 result = -1;
845         client->unlock();
846 if(DEBUG)
847 printf("RenderFarmFSClient::fseek stream=%p offset=%lld whence=%d result=%d\n", 
848 __stream, __off, __whence, result);
849         return result;
852 int64_t RenderFarmFSClient::ftell (FILE *__stream)
854         int64_t result = 0;
855         unsigned char datagram[8];
856         int i = 0;
857         int file_int64 = Units::ptr_to_int64(__stream);
858         STORE_INT64(file_int64);
860         client->lock();
861         if(!client->send_request_header(RENDERFARM_FTELL, 8))
862         {
863                 if(client->write_socket((char*)datagram, 8, RENDERFARM_TIMEOUT) != 8)
864                         result = -1;
865                 else
866                 {
867                         if(client->read_socket((char*)datagram, 8, RENDERFARM_TIMEOUT) != 8)
868                                 result = -1;
869                         else
870                                 result = READ_INT64(datagram);
871                 }
872         }
873         else
874                 result = -1;
875         client->unlock();
876 if(DEBUG)
877 printf("RenderFarmFSClient::fseek stream=%p result=%lld\n", 
878 __stream, result);
879         return result;
882 int RenderFarmFSClient::stat (__const char *__restrict __file,
883                  struct stat *__restrict __buf)
885         int len = strlen(__file) + 1;
886         int result = 0;
888         client->lock();
889         if(!client->send_request_header(RENDERFARM_STAT, len))
890         {
891                 if(client->write_socket((char*)__file + strlen(RENDERFARM_FS_PREFIX), len, RENDERFARM_TIMEOUT) == len)
892                 {
893                         if(client->read_socket((char*)__buf, sizeof(struct stat), RENDERFARM_TIMEOUT) == sizeof(struct stat))
894                         {
895                                 ;
896                         }
897                         else
898                                 result = 1;
899                 }
900                 else
901                         result = 1;
902         }
903         else
904                 result = 1;
905         client->unlock();
906 if(DEBUG)
907 printf("RenderFarmFSClient::stat path=%s\n", __file);
909         return result;
914 int RenderFarmFSClient::stat64 (__const char *__restrict __file,
915                    struct stat64 *__restrict __buf)
917         int len = strlen(__file) + 1;
918         int result = 0;
920         client->lock();
921         if(!client->send_request_header(RENDERFARM_STAT64, len))
922         {
923                 if(client->write_socket((char*)__file + strlen(RENDERFARM_FS_PREFIX), len, RENDERFARM_TIMEOUT) == len)
924                 {
925                         if(client->read_socket((char*)__buf, sizeof(struct stat64), RENDERFARM_TIMEOUT) == sizeof(struct stat64))
926                         {
927                                 ;
928                         }
929                         else
930                                 result = 1;
931                 }
932                 else
933                         result = 1;
934         }
935         else
936                 result = 1;
937         client->unlock();
938 if(DEBUG)
939 printf("RenderFarmFSClient::stat64 path=%s\n", __file);
941         return result;