[2] | 1 | #ifndef __FILEMAN_HPP_ |
---|
| 2 | #define __FILEMAN_HPP_ |
---|
| 3 | |
---|
| 4 | #include <unistd.h> |
---|
| 5 | #include "sock.hpp" |
---|
| 6 | #include <stdlib.h> |
---|
| 7 | #include <string.h> |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | class file_manager |
---|
| 11 | { |
---|
| 12 | net_address *default_fs; |
---|
| 13 | int no_security; |
---|
| 14 | |
---|
| 15 | class nfs_client |
---|
| 16 | { |
---|
| 17 | public : |
---|
| 18 | net_socket *sock; |
---|
| 19 | int file_fd; |
---|
| 20 | |
---|
[4] | 21 | nfs_client *next; |
---|
[17] | 22 | int32_t size_to_read; |
---|
| 23 | int32_t size; |
---|
[2] | 24 | nfs_client(net_socket *sock, int file_fd, nfs_client *next); |
---|
| 25 | int send_read(); // flushes as much of size_to_read as possible |
---|
| 26 | ~nfs_client(); |
---|
| 27 | } ; |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | class remote_file // a remote client has opened this file with us |
---|
| 31 | { |
---|
| 32 | public : |
---|
| 33 | net_socket *sock; |
---|
| 34 | void r_close(char *reason); |
---|
[17] | 35 | int32_t size; // server tells us the size of the file when we open it |
---|
[2] | 36 | int open_local; |
---|
| 37 | remote_file *next; |
---|
| 38 | remote_file(net_socket *sock, char *filename, char *mode, remote_file *Next); |
---|
| 39 | |
---|
| 40 | int unbuffered_read(void *buffer, size_t count); |
---|
| 41 | int unbuffered_write(void *buf, size_t count) { return 0; } // not supported |
---|
[17] | 42 | int32_t unbuffered_tell(); |
---|
| 43 | int32_t unbuffered_seek(int32_t offset); |
---|
| 44 | int32_t file_size() { return size; } |
---|
[2] | 45 | int open_failure() { return sock==NULL; } |
---|
| 46 | ~remote_file(); |
---|
| 47 | int fd() { if (sock) return sock->get_fd(); else return -1; } |
---|
| 48 | } ; |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | nfs_client *nfs_list; |
---|
| 52 | remote_file *remote_list; |
---|
| 53 | |
---|
| 54 | int process_nfs_command(nfs_client *c); |
---|
| 55 | void secure_filename(char *filename, char *mode); |
---|
| 56 | remote_file *find_rf(int fd); |
---|
| 57 | net_protocol *proto; |
---|
| 58 | public : |
---|
| 59 | |
---|
| 60 | file_manager(int argc, char **argv, net_protocol *proto); |
---|
| 61 | void process_net(); |
---|
| 62 | void add_nfs_client(net_socket *sock); |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | int rf_open_file(char *&filename, char *mode); |
---|
[17] | 66 | int32_t rf_tell(int fd); |
---|
| 67 | int32_t rf_seek(int fd, int32_t offset); |
---|
[2] | 68 | int rf_read(int fd, void *buffer, size_t count); |
---|
| 69 | int rf_close(int fd); |
---|
[17] | 70 | int32_t rf_file_size(int fd); |
---|
[2] | 71 | void set_default_fs(net_address *def) { default_fs=def->copy(); } |
---|
| 72 | ~file_manager() { if (default_fs) delete default_fs; } |
---|
| 73 | } ; |
---|
| 74 | |
---|
| 75 | extern file_manager *fman; |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | #endif |
---|