Ejemplo n.º 1
0
Archivo: hello.c Proyecto: DBarney/efs
static int hello_getattr(const char *path, struct stat *stbuf)
{
	ETERM * response = erl_rpc(FERL_DATA->erlang_fd,"gen_server","call",erl_format("[nefs,{get_attr,~s}]",path));
	ETERM * pattern = erl_format("{directory,Mode,Nlink}");
	ETERM * pattern2 = erl_format("{file,Mode,Nlink,Size}");
        int res = 0;
	memset(stbuf, 0, sizeof(struct stat));

	if(erl_match(pattern, response)) { //directory
		ETERM * Mode = erl_var_content(pattern, "Mode");
		ETERM * Nlink = erl_var_content(pattern, "Nlink");
		if(ERL_IS_INTEGER(Nlink) && ERL_IS_INTEGER(Mode)){
			stbuf->st_mode = S_IFDIR | ERL_INT_VALUE(Mode); //permissions
        	        stbuf->st_nlink = ERL_INT_VALUE(Nlink); // directories have the number of files in them
		}else{
			res = -ENOENT;
		}
	}else if(erl_match(pattern2, response)){ //file
		ETERM * Mode = erl_var_content(pattern2, "Mode");
                ETERM * Nlink = erl_var_content(pattern2, "Nlink");
		ETERM * Size = erl_var_content(pattern2, "Size");
                if(ERL_IS_INTEGER(Nlink) && ERL_IS_INTEGER(Mode) && ERL_IS_INTEGER(Size)){

			stbuf->st_mode = S_IFREG | ERL_INT_VALUE(Mode); //permissions
			stbuf->st_nlink = ERL_INT_VALUE(Nlink); //files only have 1
			stbuf->st_size = ERL_INT_VALUE(Size); // length of the file
                }else{
                        res = -ENOENT;
                }
	}else{
		res = -ENOENT;
	}	

	return res;
}
Ejemplo n.º 2
0
erlang_pid *erl_whereis(int fd, const char *name)
{
  ETERM *reply;
  ETERM *n;
  /* FIXME problem for threaded ? */
  static erlang_pid pid;
  
  n = erl_format("[~a]",name);
  reply = erl_rpc(fd,"erlang","whereis",n);
  erl_free_term(n);

  if (reply && (ERL_IS_PID(reply))) {
    char *node;
    node =  ERL_PID_NODE(reply);
    strcpy(pid.node,node);
    pid.num = ERL_PID_NUMBER(reply);
    pid.serial = ERL_PID_SERIAL(reply);
    pid.creation = ERL_PID_CREATION(reply);
    erl_free_term(reply);
    return &pid;
  }

  if (reply) erl_free_term(reply);
  return NULL;
}
Ejemplo n.º 3
0
Archivo: hello.c Proyecto: DBarney/efs
static int hello_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
			 off_t offset, struct fuse_file_info *fi)
{
	int res = 0;
	ETERM * response = erl_rpc(FERL_DATA->erlang_fd,"gen_server","call",erl_format("[nefs,{read_dir,~s}]",path));
	ETERM * pattern = erl_format("{ok,Listing}");	
	if(erl_match(pattern, response)) { //directory
		ETERM * Tail = erl_var_content(pattern, "Listing");
		if(ERL_IS_LIST(Tail)){
			while(!ERL_IS_EMPTY_LIST(Tail)){
				ETERM * elem = ERL_CONS_HEAD(Tail);
				// add in the links to the previous folders
				filler(buf, ".", NULL, 0);
        			filler(buf, "..", NULL, 0);
				
				// add in the folders contents
				if(ERL_IS_LIST(elem)){
					filler(buf,(char *)ERL_BIN_PTR(elem),NULL,0);
				}else{
					res = -ENOENT;
					break;
				}
				Tail = ERL_CONS_TAIL(Tail);
			}
		}else{
			res = -ENOENT;
		}
	}else{
                res = -ENOENT;
        }

        return res;
}
Ejemplo n.º 4
0
Archivo: hello.c Proyecto: DBarney/efs
static int hello_read(const char *path, char *buf, size_t size, off_t offset,
		      struct fuse_file_info *fi)
{
	int ret_bytes = 0;
        ETERM * response = erl_rpc(FERL_DATA->erlang_fd,"file","pread",erl_format("[~s,{bof,~i},~i]",offset,size));
        ETERM * pattern = erl_format("{ok,Data}");
	if(erl_match(pattern, response)) {
                ETERM * Data = erl_var_content(pattern, "Data");
                if(ERL_IS_BINARY(Data)){
			ret_bytes = ERL_BIN_SIZE(Data);
			char * data = ERL_BIN_PTR(Data);
			memcpy(buf,data,size); //copy the data over into the buffer
                }
        }
        return ret_bytes;
}
Ejemplo n.º 5
0
Archivo: hello.c Proyecto: DBarney/efs
int main(int argc, char *argv[])
{
	erl_init(NULL, 0);
	if (erl_connect_init(1, "secretcookie", 0) == -1)
    		erl_err_quit("erl_connect_init");
	int fd = -1;
  	if ((fd = erl_connect("nefs@Daniels-MacBook")) < 0)
    		erl_err_quit("erl_connect");
	
	ferl_state FS={
		.erlang_fd = fd
	}; 
	
	fprintf(stderr, "Connected to nefs@Daniels-MacBook\n\r");
	erl_rpc(fd,"io","format",erl_format("[ping]"));
	int retval = fuse_main(argc, argv, &hello_oper, (void *)&FS);
	fprintf(stderr, "Finished\n\r");
	return retval;
}
Ejemplo n.º 6
0
Archivo: hello.c Proyecto: DBarney/efs
static int hello_open(const char *path, struct fuse_file_info *fi)
{
	int res = 0;
        ETERM * response = erl_rpc(FERL_DATA->erlang_fd,"gen_server","call",erl_format("[nefs,{open,~s,~i}]",path,fi->flags));
	ETERM * pattern = erl_format("{ok,Fd}");
	ETERM * pattern2 = erl_format("{error,access}");
	if(erl_match(pattern, response)) {
                ETERM * Fd_Pid = erl_var_content(pattern, "Fd");
		if(ERL_IS_PID(Fd_Pid)){
	                fi->fh = Fd_Pid; //store off the file handle pid to be used in subsequent functions 
		}else{
			res= -ENOENT;
		}
	}else if(erl_match(pattern2, response)){
		res = -EACCES;
	}else{
		res = -ENOENT;
	}
	return res;
}
Ejemplo n.º 7
0
Archivo: efs.c Proyecto: spawn3/efs
/**
 * test utilities.
 * create fcount files, every file size is fsize.
 */
int efs_shell_ww(int fcount, int fsize)
{
        int ret;
        ETERM *args;
        ETERM *reply;

        args = erl_format("[~i,~i]", fcount, fsize);

        reply = erl_rpc(erlang_fd, "efs_shell", "ww", args);
        if (reply == NULL) {
                ret = EINVAL;
                fprintf(stderr, "error %d\n", ret);
                goto err_ret;
        }

        erl_free_term(reply);
        erl_free_term(args);

        return 0;
err_ret:
        erl_free_term(args);
        return ret;
}
Ejemplo n.º 8
0
Archivo: efs.c Proyecto: spawn3/efs
int efs_create(const char *path, int mode)
{
        int ret;
        ETERM *args;
        ETERM *reply;

        args = erl_format("[~s]", path);

        reply = erl_rpc(erlang_fd, "efs", "create", args);
        if (reply == NULL) {
                ret = EINVAL;
                fprintf(stderr, "error %d\n", ret);
                goto err_ret;
        }

        erl_free_term(reply);
        erl_free_term(args);

        return 0;
err_ret:
        erl_free_term(args);
        return ret;
}
Ejemplo n.º 9
0
int main(void)
#endif
{
  ei_x_buff eix;
  int index = 0;
  ETERM **etermpp = NULL, *etermp = NULL;
  char *charp = NULL;
  unsigned char uchar, **ucharpp = NULL, *ucharp = NULL;
  void *voidp = NULL;
  Erl_Heap *erl_heapp = NULL;
  int intx = 0;
  int *intp = NULL;
  unsigned int uintx, *uintp;
  unsigned long *ulongp = NULL;
  long longx = 0;
  double doublex = 0.0;
  short shortx = 42;
  FILE *filep = NULL;
  Erl_IpAddr erl_ipaddr = NULL;
  ErlMessage *erlmessagep = NULL;
  ErlConnect *erlconnectp = NULL;
  struct hostent *hostp = NULL;
  struct in_addr *inaddrp = NULL;

  /* Converion to erl_interface format is in liberl_interface */

  intx = erl_errno;

  ei_encode_term(charp, &index, voidp);
  ei_x_encode_term(&eix, voidp);
  ei_decode_term(charp, &index, voidp);

  erl_init(voidp, longx);
  erl_connect_init(intx, charp,shortx);
  erl_connect_xinit(charp,charp,charp,erl_ipaddr,charp,shortx);
  erl_connect(charp); 
  erl_xconnect(erl_ipaddr,charp);
  erl_close_connection(intx);
  erl_receive(intx, ucharp, intx);
  erl_receive_msg(intx, ucharp, intx, erlmessagep);
  erl_xreceive_msg(intx, ucharpp, intp, erlmessagep);
  erl_send(intx, etermp, etermp);
  erl_reg_send(intx, charp, etermp);
  erl_rpc(intx,charp,charp,etermp);
  erl_rpc_to(intx,charp,charp,etermp);
  erl_rpc_from(intx,intx,erlmessagep);

  erl_publish(intx);
  erl_accept(intx,erlconnectp);

  erl_thiscookie();
  erl_thisnodename();
  erl_thishostname();
  erl_thisalivename();
  erl_thiscreation();
  erl_unpublish(charp);
  erl_err_msg(charp);
  erl_err_quit(charp);
  erl_err_ret(charp);
  erl_err_sys(charp);

  erl_cons(etermp,etermp);
  erl_copy_term(etermp);
  erl_element(intx,etermp);

  erl_hd(etermp);
  erl_iolist_to_binary(etermp);
  erl_iolist_to_string(etermp);
  erl_iolist_length(etermp);
  erl_length(etermp);
  erl_mk_atom(charp);
  erl_mk_binary(charp,intx);
  erl_mk_empty_list();
  erl_mk_estring(charp, intx);
  erl_mk_float(doublex);
  erl_mk_int(intx);
  erl_mk_list(etermpp,intx);
  erl_mk_pid(charp,uintx,uintx,uchar);
  erl_mk_port(charp,uintx,uchar);
  erl_mk_ref(charp,uintx,uchar);
  erl_mk_long_ref(charp,uintx,uintx,uintx,uchar);
  erl_mk_string(charp);
  erl_mk_tuple(etermpp,intx);
  erl_mk_uint(uintx);
  erl_mk_var(charp);
  erl_print_term(filep,etermp);
  /*  erl_sprint_term(charp,etermp); */
  erl_size(etermp);
  erl_tl(etermp);
  erl_var_content(etermp, charp);

  erl_format(charp);
  erl_match(etermp, etermp);

  erl_global_names(intx, intp);
  erl_global_register(intx, charp, etermp);
  erl_global_unregister(intx, charp);
  erl_global_whereis(intx, charp, charp);

  erl_init_malloc(erl_heapp,longx);
  erl_alloc_eterm(uchar);
  erl_eterm_release();
  erl_eterm_statistics(ulongp,ulongp);
  erl_free_array(etermpp,intx);
  erl_free_term(etermp);
  erl_free_compound(etermp);
  erl_malloc(longx);
  erl_free(voidp);

  erl_compare_ext(ucharp, ucharp);
  erl_decode(ucharp);
  erl_decode_buf(ucharpp);
  erl_encode(etermp,ucharp);
  erl_encode_buf(etermp,ucharpp);
  erl_ext_size(ucharp);
  erl_ext_type(ucharp);
  erl_peek_ext(ucharp,intx);
  erl_term_len(etermp);

  erl_gethostbyname(charp);
  erl_gethostbyaddr(charp, intx, intx);
  erl_gethostbyname_r(charp, hostp, charp, intx, intp);
  erl_gethostbyaddr_r(charp, intx, intx, hostp, charp, intx, intp);

  erl_init_resolve();
  erl_distversion(intx);

  erl_epmd_connect(inaddrp);
  erl_epmd_port(inaddrp, charp, intp);

  charp  = ERL_ATOM_PTR(etermp);
  intx   = ERL_ATOM_SIZE(etermp);
  ucharp = ERL_BIN_PTR(etermp);
  intx   = ERL_BIN_SIZE(etermp);
  etermp = ERL_CONS_HEAD(etermp);
  etermp = ERL_CONS_TAIL(etermp);
  intx   = ERL_COUNT(etermp);
  doublex= ERL_FLOAT_VALUE(etermp);
  uintx  = ERL_INT_UVALUE(etermp);
  intx   = ERL_INT_VALUE(etermp);
  intx   = ERL_IS_ATOM(etermp);
  intx   = ERL_IS_BINARY(etermp);
  intx   = ERL_IS_CONS(etermp);
  intx   = ERL_IS_EMPTY_LIST(etermp);
  intx   = ERL_IS_FLOAT(etermp);
  intx   = ERL_IS_INTEGER(etermp);
  intx   = ERL_IS_LIST(etermp);
  intx   = ERL_IS_PID(etermp);
  intx   = ERL_IS_PORT(etermp);
  intx   = ERL_IS_REF(etermp);
  intx   = ERL_IS_TUPLE(etermp);
  intx   = ERL_IS_UNSIGNED_INTEGER(etermp);
  uchar  = ERL_PID_CREATION(etermp);
  charp  = ERL_PID_NODE(etermp);
  uintx  = ERL_PID_NUMBER(etermp);
  uintx  = ERL_PID_SERIAL(etermp);
  uchar  = ERL_PORT_CREATION(etermp);
  charp  = ERL_PORT_NODE(etermp);
  uintx  = ERL_PORT_NUMBER(etermp);
  uchar  = ERL_REF_CREATION(etermp);
  intx   = ERL_REF_LEN(etermp);
  charp  = ERL_REF_NODE(etermp);
  uintx  = ERL_REF_NUMBER(etermp);
  uintp  = ERL_REF_NUMBERS(etermp);
  etermp = ERL_TUPLE_ELEMENT(etermp,intx);
  intx   = ERL_TUPLE_SIZE(etermp);

  return 
      BUFSIZ +
      EAGAIN +
      EHOSTUNREACH +
      EINVAL +
      EIO +
      EMSGSIZE +
      ENOMEM +
      ERL_ATOM +
      ERL_BINARY +
      ERL_ERROR +
      ERL_EXIT +
      ERL_FLOAT +
      ERL_INTEGER +
      ERL_LINK +
      ERL_LIST +
      ERL_MSG +
      ERL_NO_TIMEOUT +
      ERL_PID +
      ERL_PORT +
      ERL_REF +
      ERL_REG_SEND +
      ERL_SEND +
      ERL_SMALL_BIG +
      ERL_TICK +
      ERL_TIMEOUT +
      ERL_TUPLE +
      ERL_UNLINK +
      ERL_U_INTEGER +
      ERL_U_SMALL_BIG +
      ERL_VARIABLE +
      ETIMEDOUT +
      MAXNODELEN +
      MAXREGLEN;
}