1 /* Filter driver - general include file */ 2 #define _SYSTEM 1 3 #include <minix/config.h> 4 #include <minix/const.h> 5 #include <minix/type.h> 6 #include <minix/com.h> 7 #include <minix/ipc.h> 8 #include <sys/ioc_disk.h> 9 #include <minix/sysutil.h> 10 #include <minix/syslib.h> 11 #include <minix/partition.h> 12 #include <minix/ds.h> 13 #include <minix/callnr.h> 14 #include <minix/blockdriver.h> 15 #include <minix/optset.h> 16 #include <unistd.h> 17 #include <stdio.h> 18 #include <stdlib.h> 19 #include <errno.h> 20 #include <string.h> 21 22 #define SECTOR_SIZE 512 23 24 typedef enum { 25 ST_NIL, /* Zero checksums */ 26 ST_XOR, /* XOR-based checksums */ 27 ST_CRC, /* CRC32-based checksums */ 28 ST_MD5 /* MD5-based checksums */ 29 } checksum_type; 30 31 typedef enum { 32 FLT_WRITE, /* write to up to two disks */ 33 FLT_READ, /* read from one disk */ 34 FLT_READ2 /* read from both disks */ 35 } disk_operation; 36 37 struct driverinfo { 38 char *label; 39 int minor; 40 endpoint_t endpt; 41 int up_event; 42 43 int problem; /* one of BD_* */ 44 int error; /* one of E*, only relevant if problem>0 */ 45 int retries; 46 int kills; 47 }; 48 49 /* UP event characterization. */ 50 #define UP_EXPECTED 0 51 #define UP_NONE 1 52 #define UP_PENDING 2 53 54 /* Something was wrong and the disk driver has been restarted/refreshed, 55 * so the request needs to be redone. 56 */ 57 #define RET_REDO 1 58 59 /* The cases where the disk driver need to be restarted/refreshed by RS. 60 * BD_DEAD: the disk driver has died. Restart it. 61 * BD_PROTO: a protocol error has occurred. Refresh it. 62 * BD_DATA: a data error has occurred. Refresh it. 63 */ 64 typedef enum { 65 BD_NONE, 66 BD_DEAD, 67 BD_PROTO, 68 BD_DATA, 69 BD_LAST 70 } driver_state; 71 72 #define DRIVER_MAIN 0 73 #define DRIVER_BACKUP 1 74 75 /* Requests for more than this many bytes will be allocated dynamically. */ 76 #define BUF_SIZE (256 * 1024) 77 #define SBUF_SIZE (BUF_SIZE * 2) 78 79 #define LABEL_SIZE 32 80 81 typedef unsigned long sector_t; 82 83 /* main.c */ 84 extern int USE_CHECKSUM; 85 extern int USE_MIRROR; 86 extern int BAD_SUM_ERROR; 87 extern int USE_SUM_LAYOUT; 88 extern int SUM_TYPE; 89 extern int SUM_SIZE; 90 extern int NR_SUM_SEC; 91 extern int NR_RETRIES; 92 extern int NR_RESTARTS; 93 extern int DRIVER_TIMEOUT; 94 extern int CHUNK_SIZE; 95 96 extern char MAIN_LABEL[LABEL_SIZE]; 97 extern char BACKUP_LABEL[LABEL_SIZE]; 98 extern int MAIN_MINOR; 99 extern int BACKUP_MINOR; 100 101 /* sum.c */ 102 extern void sum_init(void); 103 extern int transfer(u64_t pos, char *buffer, size_t *sizep, int flag_rw); 104 extern u64_t convert(u64_t size); 105 106 /* driver.c */ 107 extern void driver_init(void); 108 extern void driver_shutdown(void); 109 extern u64_t get_raw_size(void); 110 extern void reset_kills(void); 111 extern int check_driver(int which); 112 extern int bad_driver(int which, int type, int error); 113 extern int read_write(u64_t pos, char *bufa, char *bufb, size_t *sizep, 114 int flag_rw); 115 extern void ds_event(void); 116 117 /* util.c */ 118 extern char *flt_malloc(size_t size, char *sbuf, size_t ssize); 119 extern void flt_free(char *buf, size_t size, const char *sbuf); 120 extern clock_t flt_alarm(clock_t dt); 121 122