parse_node_t *make_range_node P4(int, code, parse_node_t *, expr, parse_node_t *, l, parse_node_t *, r) { parse_node_t *newnode; if (r) { CREATE_TERNARY_OP(newnode, code, 0, l, r, expr); } else { CREATE_BINARY_OP(newnode, code, 0, l, expr); } if (exact_types){ switch(expr->type){ case TYPE_ANY: case TYPE_STRING: case TYPE_BUFFER: newnode->type = expr->type; break; default: if (expr->type & TYPE_MOD_ARRAY) newnode->type = expr->type; else{ type_error("Bad type of argument used for range: ", expr->type); newnode->type = TYPE_ANY; } } if (!IS_TYPE(l->type, TYPE_NUMBER)) type_error("Bad type of left index to range operator", l->type); if (r && !IS_TYPE(r->type, TYPE_NUMBER)) type_error("Bad type of right index to range operator", r->type); } else newnode->type = TYPE_ANY; return newnode; }
binary_int_op P4(parse_node_t *, l, parse_node_t *, r, char, op, char *, name) { parse_node_t *ret; if (exact_types){ if (!IS_TYPE(l->type, TYPE_NUMBER)) { char buf[256]; strcpy(buf, "Bad left argument to '"); strcat(buf, name); strcat(buf, "' : \""); strcat(buf, get_type_name(l->type)); strcat(buf, "\""); yyerror(buf); } if (!IS_TYPE(r->type,TYPE_NUMBER)) { char buf[256]; strcpy(buf, "Bad right argument to '"); strcat(buf, name); strcat(buf, "' : \""); strcat(buf, get_type_name(r->type)); strcat(buf, "\""); yyerror(buf); } } if (l->kind == NODE_NUMBER) { if (r->kind == NODE_NUMBER) { switch (op) { case F_OR: l->v.number |= r->v.number; break; case F_XOR: l->v.number ^= r->v.number; break; case F_AND: l->v.number &= r->v.number; break; case F_LSH: l->v.number <<= r->v.number; break; case F_RSH: l->v.number >>= r->v.number; break; case F_MOD: if (r->v.number == 0) { yyerror("Modulo by zero constant"); break; } l->v.number %= r->v.number; break; default: fatal("Unknown opcode in binary_int_op()\n"); } return l; } switch (op) { case F_OR: case F_XOR: case F_AND: CREATE_BINARY_OP(ret, op, TYPE_NUMBER, r, l); return ret; } } CREATE_BINARY_OP(ret, op, TYPE_NUMBER, l, r); return ret; }
/* * This is called when a user reads the characters or chartab sys file. */ static ssize_t chars_chartab_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { int i; int len = 0; char *cp; char *buf_pointer = buf; size_t bufsize = PAGE_SIZE; unsigned long flags; spk_lock(flags); *buf_pointer = '\0'; for (i = 0; i < 256; i++) { if (bufsize <= 1) break; if (strcmp("characters", attr->attr.name) == 0) { len = scnprintf(buf_pointer, bufsize, "%d\t%s\n", i, characters[i]); } else { /* show chartab entry */ if (IS_TYPE(i, B_CTL)) cp = "B_CTL"; else if (IS_TYPE(i, WDLM)) cp = "WDLM"; else if (IS_TYPE(i, A_PUNC)) cp = "A_PUNC"; else if (IS_TYPE(i, PUNC)) cp = "PUNC"; else if (IS_TYPE(i, NUM)) cp = "NUM"; else if (IS_TYPE(i, A_CAP)) cp = "A_CAP"; else if (IS_TYPE(i, ALPHA)) cp = "ALPHA"; else if (IS_TYPE(i, B_CAPSYM)) cp = "B_CAPSYM"; else if (IS_TYPE(i, B_SYM)) cp = "B_SYM"; else cp = "0"; len = scnprintf(buf_pointer, bufsize, "%d\t%s\n", i, cp); } bufsize -= len; buf_pointer += len; } spk_unlock(flags); return buf_pointer - buf; }
int main (int argc, char **argv) { char *diskType = "auto"; char *imagefilename = NULL; char *mountpoint = NULL; int debug = 0; int foreground = 0; char c; int i; char *differencing[DIFFERENCING_MAX]; int differencingLen = 0; extern char *optarg; extern int optind, optopt; // // *** Parse the command line options *** // processName = argv[0]; while ((c = getopt (argc, argv, GETOPT_ARGS)) != -1) { switch (c) { case 'r': readonly = 1; break; case 'g': foreground = 1; break; case 'v': verbose = 1; break; case 'a': allowall = 1; break; case 'w': allowall = 1; allowallw = 1; break; case 't': diskType = (char *) optarg; break; // ignored if OLDAPI case 's': if (differencingLen == DIFFERENCING_MAX) usageAndExit ("Too many differencing disks"); differencing[differencingLen++] = (char *) optarg; break; case 'f': imagefilename = (char *) optarg; break; case 'd': foreground = 1; debug = 1; break; case 'h': usageAndExit (NULL); case '?': usageAndExit ("Unknown option"); } } // // *** Validate the command line *** // if (argc != optind + 1) usageAndExit ("a single mountpoint must be specified"); mountpoint = argv[optind]; if (!mountpoint) usageAndExit ("no mountpoint specified"); if (!imagefilename) usageAndExit ("no image chosen"); if (stat (imagefilename, &VDfile_stat) < 0) usageAndExit ("cannot access imagefile"); if (access (imagefilename, F_OK | R_OK | ((!readonly) ? W_OK : 0)) < 0) usageAndExit ("cannot access imagefile"); for (i = 0; i < differencingLen; i++) if (access (differencing[i], F_OK | R_OK | ((readonly) ? 0 : W_OK)) < 0) usageAndExit ("cannot access differencing imagefile %s", differencing[i]); #define IS_TYPE(s) (strcmp (s, diskType) == 0) if (! (IS_TYPE ("auto") || IS_TYPE ("VDI") || IS_TYPE ("VMDK") || IS_TYPE ("VHD") || IS_TYPE ("auto"))) usageAndExit ("invalid disk type specified"); if (strcmp ("auto", diskType) == 0 && detectDiskType (&diskType, imagefilename) < 0) return 1; // // *** Open the VDI, parse the MBR + EBRs and connect to the fuse service *** // if (RT_FAILURE (VDInterfaceAdd (&vdError, "VD Error", VDINTERFACETYPE_ERROR, &vdErrorCallbacks, NULL, &pVDifs))) usageAndExit ("invalid initialisation of VD interface"); if (RT_FAILURE (VDCreate (&vdError, VDTYPE_HDD, &hdDisk))) usageAndExit ("invalid initialisation of VD interface"); DISKopen (diskType, imagefilename); for (i = 0; i < differencingLen; i++) { char *diffType; char *diffFilename = differencing[i]; detectDiskType (&diffType, diffFilename); DISKopen (diffType, diffFilename); } initialisePartitionTable (); myuid = geteuid (); mygid = getegid (); fuse_opt_add_arg (&fuseArgs, "vdfuse"); { char fsname[strlen (imagefilename) + 12]; strcpy (fsname, "-ofsname=\0"); strcat (fsname, imagefilename); fuse_opt_add_arg (&fuseArgs, fsname); } fuse_opt_add_arg (&fuseArgs, "-osubtype=vdfuse"); fuse_opt_add_arg (&fuseArgs, "-o"); fuse_opt_add_arg (&fuseArgs, (allowall) ? "allow_other" : "allow_root"); if (foreground) fuse_opt_add_arg (&fuseArgs, "-f"); if (debug) fuse_opt_add_arg (&fuseArgs, "-d"); fuse_opt_add_arg (&fuseArgs, mountpoint); return fuse_main (fuseArgs.argc, fuseArgs.argv, &fuseOperations #if FUSE_USE_VERSION >= 26 , NULL #endif ); }
bool ImageHeader::read(std::ifstream& f, bool skip_type_check, bool force_reversed, bool skip_extra_checkings) { float tmp; unsigned tmpSize; unsigned long size; /* Determine reverse status according to the next table ................. (computed in Linux) */ #define TYPE_TABLE_SIZE 10 int type_table[TYPE_TABLE_SIZE][5] = {{0, 0, 48, 65, 11}, {0, 0, 32, 65, 10}, {0, 0, 16, 65, 9}, {0, 0, 0, 65, 8}, {0, 0, 64, 64, 3}, {0, 0, 128, 63, 1}, {0, 0, 128, 191, -1}, {0, 0, 64, 192, -3}, {0, 0, 160, 192, -5}, {0, 0, 224, 192, -7}}; union { unsigned char c[4]; float f; } file_type; unsigned long current_position = f.tellg(); if (!skip_type_check) { // Read file type f.seekg(current_position + 16, std::ios::beg); for (int i = 0; i < 4; i++) { f.read(reinterpret_cast<char*>(&(file_type.c[i])), sizeof(char)); } f.seekg(current_position + 0, std::ios::beg); // Select type int correct_type = 0; reversed_ = false; #define IS_TYPE(n) \ (type_table[n][0] == (int)file_type.c[0] && \ type_table[n][1] == (int)file_type.c[1] && \ type_table[n][2] == (int)file_type.c[2] && \ type_table[n][3] == (int)file_type.c[3]) #define IS_REVERSE_TYPE(n) \ (type_table[n][0] == file_type.c[3] && type_table[n][1] == file_type.c[2] && \ type_table[n][2] == file_type.c[1] && type_table[n][3] == file_type.c[0]) for (int i = 0; i < TYPE_TABLE_SIZE; i++) { if (IS_TYPE(i)) { correct_type = type_table[i][4]; break; } else if (IS_REVERSE_TYPE(i)) { correct_type = type_table[i][4]; reversed_ = true; break; } } if (correct_type == 0) { return false; } // Now check this machine type file_type.f = 1; if (IS_REVERSE_TYPE(5)) { reversed_ = !reversed_; } } else { reversed_ = force_reversed; } // Read header if (!reversed_) { f.read(reinterpret_cast<char*>(&spider_header_), sizeof(SpiderHeader)); } // Read numerical fields reversed else { IMP::algebra::reversed_read(&spider_header_, sizeof(float), 36, f, true); IMP::algebra::reversed_read(&spider_header_.fGeo_matrix, sizeof(double), 9, f, true); // 14 is the number of fields in the SpiderHeader struct after fGeo_matrix IMP::algebra::reversed_read(&spider_header_.fAngle1, sizeof(float), 14, f, true); IMP::algebra::reversed_read(&spider_header_.empty, sizeof(char), 752, f, true); } unsigned long usfNcol = (unsigned long)spider_header_.fNcol; unsigned long usfNrow = (unsigned long)spider_header_.fNrow; if (usfNcol == 0 || usfNrow == 0) { IMP_THROW("Zero size read for image", IOException); } unsigned long usfNslice = (unsigned long)spider_header_.fNslice; unsigned long usfHeader = (unsigned long)get_spider_header_size(); // Get file size current_position = f.tellg(); unsigned long init_pos, file_size; f.seekg(0, std::ios::beg); init_pos = f.tellg(); f.seekg(0, std::ios::end); file_size = (unsigned long)f.tellg() - init_pos; f.seekg(current_position, std::ios::beg); // Check if it is an "aberrant" image if (spider_header_.fIform == IMG_IMPEM) { if ((usfNcol * usfNrow * sizeof(float)) == file_size) { usfNrow = (unsigned long)(--spider_header_.fNrow); --spider_header_.fNrec; } } // Extra checking if (!skip_extra_checkings) { switch ((int)spider_header_.fIform) { case IMG_BYTE: size = usfNcol * usfNrow * sizeof(float); if ((size != file_size)) { return false; } break; case IMG_IMPEM: size = usfHeader + usfNcol * usfNrow * sizeof(float); if ((size != file_size) || (spider_header_.fIform != 1)) { return false; } else if (skip_type_check) { spider_header_.fIform = 1; } break; case IMG_INT: size = usfHeader + usfNcol * usfNrow * sizeof(float); if ((size != file_size) || (spider_header_.fIform != 9)) { return false; } else if (skip_type_check) { spider_header_.fIform = 9; // This is done to recover // files which are not properly converted from other packages } break; case VOL_BYTE: size = usfNslice * usfNcol * usfNrow * sizeof(float); if ((size != file_size)) { return false; } break; case VOL_IMPEM: size = usfHeader + usfNslice * usfNcol * usfNrow * sizeof(float); if ((size != file_size) || (spider_header_.fIform != 3)) { return false; } else if (skip_type_check) { spider_header_.fIform = 3; } break; case VOL_INT: size = usfHeader + usfNslice * usfNcol * usfNrow * sizeof(float); if ((size != file_size) || (spider_header_.fIform != 10)) { return false; } else if (skip_type_check) { spider_header_.fIform = 10; } break; case IMG_FOURIER: size = usfHeader + 2 * usfNcol * usfNrow * sizeof(float); // The term 2 is to take into account that IMG_FOURIER // stores complex numbers with 2 floats for each one. if ((size != file_size) || (spider_header_.fIform != -5 && spider_header_.fIform != -1)) return false; else if (skip_type_check) { spider_header_.fIform = -1; } break; case VOL_FOURIER: size = usfHeader + 2 * usfNcol * usfNrow * sizeof(float); // The term 2 is to take into account that VOL_FOURIER // stores complex numbers with 2 floats for each one. if ((size != file_size) || (spider_header_.fIform != -7 && spider_header_.fIform != -3)) { return false; } else if (skip_type_check) { spider_header_.fIform = -3; } break; } } /* Spider images contain: - a header with the size of the struct SpiderHeader, - a "filling" empty space - the data of size cols*rows*sizeof(float). */ spider_header_.fLabrec = (float)ceil((float)256 / spider_header_.fNcol); // Size of whole header tmpSize = (int)(spider_header_.fNcol * spider_header_.fLabrec * 4); // Subtract the real header tmpSize -= sizeof(SpiderHeader); // read empty filling space for (unsigned i = 0; i < tmpSize / 4; i++) { IMP::algebra::reversed_read(&tmp, sizeof(float), 1, f, reversed_); } return true; }