Example #1
0
int split_raw_test(const char *fn)
{
    void srp_dump(AFFILE *af);
    AFFILE *af = af_open(fn,O_RDONLY,0666);
    printf("split_raw imagesize: %"PRId64"\n",af_get_imagesize(af));
    srp_dump(af);
    af_close(af);
    return 0;
}
Example #2
0
int main(int argc, char **argv)
{
    char *af_path = NULL, *af_basename = NULL;
    size_t raw_path_len = 0;
    char **fargv = NULL;
    int fargc = 0;

    if (argc < 3) {
        usage();
	exit(EXIT_FAILURE);
    }

    /* Prepare fuse args, af_image is omitted, but "-s" is added */
    fargv = XCALLOC(char *, argc); /* usually not free'd */
    fargv[0] = argv[0];
    fargv[1] = argv[argc - 1];
    fargc = 2;
    while (fargc <= (argc - 2)) {
        fargv[fargc] = argv[fargc - 1];
	if (strcmp(fargv[fargc], "-h") == 0 ||
	    strcmp(fargv[fargc], "--help") == 0 ) {
	    usage();
	    XFREE(fargv);
	    exit(EXIT_SUCCESS);
	}
	fargc++;
    }
    /* disable multi-threaded operation
     * (we don't know if afflib is thread safe!)
     */
    fargv[fargc] = "-s";
    fargc++;

    if ((af_image = af_open(argv[argc - 2], O_RDONLY|O_EXCL, 0)) == NULL) {
        perror("Can't open image file");
	XFREE(fargv);
	exit(EXIT_FAILURE);
    }

    af_path = xstrdup(argv[argc - 2]);
    af_basename = basename(af_path);
    /*             "/"       af_basename            raw_ext  "/0"*/
    raw_path_len = 1 + strlen(af_basename) + strlen(raw_ext) + 1;
    raw_path = XCALLOC(char, raw_path_len);
    raw_path[0] = '/';
    strcat(raw_path, af_basename);
    strcat(raw_path, raw_ext);
    raw_path[raw_path_len -1] = 0;
    XFREE(af_path);
    raw_size = af_get_imagesize(af_image);

    return fuse_main(fargc, fargv, &affuse_oper, NULL);
}
Example #3
0
File: aff.cpp Project: halbbob/dff
void aff::start(std::map<std::string, Variant* > args)
{
  std::list<Variant *> vl; 
  std::list<Variant *>::iterator 		 vpath; 
  AffNode*					 node;

  if (args["parent"])
    this->parent = args["parent"]->value<Node* >();
  else
    this->parent = VFS::Get().GetNode("/");
  if (args["path"])
    vl = args["path"]->value<std::list<Variant* > >();
  else
    throw(envError("aff module requires path argument"));
  if (args["cache size"])
  {
    std::ostringstream cs;
    cs << args["cache size"]->value<uint32_t >();
    this->cache_size = cs.str(); 
  }
  else
    this->cache_size = "2";
#ifndef WIN32
  setenv("AFFLIB_CACHE_PAGES", this->cache_size.c_str(), 1);
#else
  _putenv_s("AFFLIB_CACHE_PAGES", this->cache_size.c_str());
#endif

  for (vpath = vl.begin(); vpath != vl.end(); vpath++)
  {
     std::string path = (*vpath)->value<Path* >()->path;
     AFFILE* affile = af_open(path.c_str(), O_RDONLY, 0);
     if (affile)
     {
	std::string nname = path.substr(path.rfind('/') + 1);
	node = new AffNode(nname, af_get_imagesize(affile), NULL, this, path, affile);
   	this->registerTree(this->parent, node);   
	this->res[path] = new Variant(std::string("added successfully by aff module"));
     }
     else 
        this->res[path] = new Variant(std::string("can't be added by aff module"));
  }

  return ;

}
Example #4
0
void readfile_test(const char *fname)
{
    unsigned char buf[1024];
    memset(buf,0,sizeof(buf));
    AFFILE *af = af_open(fname,O_RDONLY,0666);
    if(!af){
	af_perror(fname);
	err(1,"af_open(%s)",fname);
    }
    printf("using '%s'\n",af->v->name);
    printf("af_get_imagesize()=%"PRId64" errno=%d\n",af_get_imagesize(af),errno);

    int r = af_read(af,buf,sizeof(buf));
    printf("af_read(af,buf,1024)=%d  errno=%d\n",r,errno);
    r = fwrite(buf,1,512,stdout);
    assert(r==512);
    af_close(af);
    exit(0);
}
Example #5
0
static int
affile_init(affile *self, PyObject *args, PyObject *kwds) {
	char *filename;
    static char *kwlist[] = {"filename", NULL};

    self->size = 0;

    if(!PyArg_ParseTupleAndKeywords(args, kwds, "s", kwlist, &filename))
        return -1;

    self->af = af_open(filename, O_RDONLY, 0);
    if(self->af == NULL) {
    	PyErr_Format(PyExc_IOError, "Failed to initialise afflib");
    	return -1;
    }

#if LIBAFFLIB_VERSION < 3
    self->size = self->af->image_size;
#else
    self->size = af_get_imagesize(self->af);
#endif

    return 0;
}