1 /*********************************************************************\ 2 * Copyright (c) 1991 by Wen-King Su (wen-king@vlsi.cs.caltech.edu) * 3 * Copyright (c) 2003-2009 by Radim Kolar * 4 * * 5 * You may copy or modify this file in any manner you wish, provided * 6 * that this notice is always included, and that you hold the author * 7 * harmless for any loss or damage resulting from the installation or * 8 * use of this software. * 9 \*********************************************************************/ 10 11 #ifndef _FSP_COMMON_DEF_H_ 12 #define _FSP_COMMON_DEF_H_ 1 13 14 #include <stdio.h> 15 16 #include <sys/param.h> 17 #include <sys/types.h> 18 #include <sys/socket.h> 19 #include <sys/stat.h> 20 21 #include <errno.h> 22 #include <netinet/in.h> 23 #include <arpa/inet.h> 24 25 #ifdef HAVE_UNISTD_H 26 #include <unistd.h> 27 #endif 28 #include <stdlib.h> 29 30 #include <time.h> 31 #include <fcntl.h> 32 #include <signal.h> 33 #include <dirent.h> 34 35 /**************************************************************************** 36 * UBUF is the structure of message exchanged between server and clients. 37 * 38 * The 'buf' part of the buffer is variable length up to max of 1024. 39 * The 'key' field is used by the server for sequence identification. 40 * The 'seq' field is used by the client for sequence identification. 41 * 42 * Client's message to server contain a key value that is the same as the 43 * key value of the previous message received from the server. Similarly, 44 * the server's message to client contains a seq value that is the same 45 * as the seq value of the previous message from the client. 46 * 47 * The buf field is logically partitioned into two parts by the len field. 48 * The len field indicate the size of the first part of the buffer starting 49 * at buf[0]. The rest of the buffer is the second field. In some cases 50 * both fields can contain information. 51 * 52 ****************************************************************************/ 53 54 #define UBUF_HSIZE 12 /* 12 bytes for the FSP header. */ 55 #define UBUF_SPACE 1024 /* maximum standard payload. */ 56 #define DEFAULT_SPACE 1492-20-8-12 /* Max packet size for standard */ 57 /* 1492 pppOE mtu ethernet. */ 58 /* 20 bytes is IP header */ 59 /* 8 bytes is UDP header */ 60 /* 12 bytes is FSP header */ 61 #define UBUF_MAXSPACE 4380 /* maximum payload supported by */ 62 /* server. 3 max packets for 1500 */ 63 /* mtu ethernet. */ 64 65 #define NBSIZE (UBUF_MAXSPACE+UBUF_SPACE) 66 67 typedef struct UBUF { unsigned char cmd; /* message code. */ 68 unsigned char sum; /* message checksum. */ 69 unsigned char bb_key[2]; /* message key. */ 70 unsigned char bb_seq[2]; /* message sequence number. */ 71 unsigned char bb_len[2]; /* number of bytes in buf 1. */ 72 unsigned char bb_pos[4]; /* location in the file. */ 73 74 char buf[UBUF_MAXSPACE]; 75 } UBUF; 76 77 /* definition of cmds */ 78 79 #define CC_VERSION 0x10 /* return server's version string. */ 80 #define CC_INFO 0x11 /* return server's extended info block */ 81 #define CC_ERR 0x40 /* error response from server. */ 82 #define CC_GET_DIR 0x41 /* get a directory listing. */ 83 #define CC_GET_FILE 0x42 /* get a file. */ 84 #define CC_UP_LOAD 0x43 /* open a file for writing. */ 85 #define CC_INSTALL 0x44 /* close a file opened for writing. */ 86 #define CC_DEL_FILE 0x45 /* delete a file. */ 87 #define CC_DEL_DIR 0x46 /* delete a directory. */ 88 #define CC_GET_PRO 0x47 /* get directory protection. */ 89 #define CC_SET_PRO 0x48 /* set directory protection. */ 90 #define CC_MAKE_DIR 0x49 /* create a directory. */ 91 #define CC_BYE 0x4A /* finish a session. */ 92 #define CC_GRAB_FILE 0x4B /* atomic get+delete a file. */ 93 #define CC_GRAB_DONE 0x4C /* atomic get+delete a file done. */ 94 #define CC_STAT 0x4D /* get information about file. */ 95 #define CC_RENAME 0x4E /* rename file or directory. */ 96 #define CC_CH_PASSWD 0x4F /* change password */ 97 #define CC_LIMIT 0x80 /* # > 0x7f for future cntrl blk ext. */ 98 #define CC_TEST 0x81 /* reserved for testing */ 99 100 /* definition of global bitfield for version information */ 101 /* Global information is also going to be a bit vector */ 102 #define VER_BYTES 1 /* currently only 8 bits or less of info */ 103 #define VER_LOG 0x01 /* does the server do logging */ 104 #define VER_READONLY 0x02 /* is the server in readonly mode */ 105 #define VER_REVNAME 0x04 /* does the server refuse non reversables */ 106 #define VER_PRIVMODE 0x08 /* Is the server being run 'private' mode */ 107 #define VER_THRUPUT 0x10 /* does the server enforce thruput control*/ 108 #define VER_XTRADATA 0x20 /* server accept packets with xtra data */ 109 110 /* definition of directory bitfield for directory information */ 111 /* directory information is just going to be a bitfield encoding 112 * of which protection bits are set/unset 113 */ 114 #define PRO_BYTES 1 /* currently only 8 bits or less of info */ 115 #define DIR_OWNER 0x01 /* does caller own directory */ 116 #define DIR_DEL 0x02 /* can files be deleted from this dir */ 117 #define DIR_ADD 0x04 /* can files be added to this dir */ 118 #define DIR_MKDIR 0x08 /* can new subdirectories be created */ 119 #define DIR_GET 0x10 /* are files readable by non-owners? */ 120 #define DIR_README 0x20 /* does this dir contain an readme file? */ 121 #define DIR_LIST 0x40 /* public can list directory */ 122 #define DIR_RENAME 0x80 /* can files be renamed in this dir */ 123 124 /**************************************************************************** 125 * RDIRENT is the structure of a directory entry contained in a .FSP_CONTENT 126 * file. Each entry contains a 4 bytes quantity 'time', a 4 bytes quantity 127 * 'size', and 1 byte of 'type'. Then followed by x number of bytes of 128 * 'name'. 'name' is null terminated. Then followed by enough number of 129 * padding to fill to an 4-byte boundary. At this point, if the next entry 130 * to follow will spread across 1k boundary, then two possible things will 131 * happen. 1) if the header fits between this entry and the 1k boundary, 132 * a complete header will be filled in with a 'type' set to RDTYPE_SKIP. 133 * And then enough bytes to padd to 1k boundary. 2) if the header does 134 * not fit, then simply pad to the 1k boundary. This will make sure that 135 * messages carrying directory information carry only complete directory 136 * entries and no fragmented entries. The last entry is type RDTYPE_END. 137 ****************************************************************************/ 138 139 #define RDHSIZE (2*4+1) 140 141 typedef struct RDIRENT { unsigned char bb_time[4]; 142 unsigned char bb_size[4]; 143 unsigned char type ; 144 char name[1] ; } RDIRENT; 145 146 #define RDTYPE_END 0x00 147 #define RDTYPE_FILE 0x01 148 #define RDTYPE_DIR 0x02 149 #define RDTYPE_SKIP 0x2A 150 151 #define NULLP ((char *) 0) 152 153 #define MIN_DELAY 1000L 154 #define DEFAULT_DELAY 1340L 155 #define DEFAULT_MAXDELAY 60000L 156 #define MAX_DELAY 300000L 157 #define DEFAULT_TIMEOUT 360 158 159 #endif /* _FSP_COMMON_DEF_H_ */ 160