void set_gadget_filename(gadget_read_info *fp_gadget, int multifile_number, char *filename) {
    // Determine/set the filename root and path
    char filename_root[SID_MAX_FILENAME_LENGTH];
    char filename_path[SID_MAX_FILENAME_LENGTH];
    strcpy(filename_root, fp_gadget->filename_root);
    strip_path(filename_root);
    if(strlen(filename_root) == 0)
        sprintf(filename_root, "snapshot");
    strcpy(filename_path, fp_gadget->filename_root);
    strip_file_root(filename_path);

    if(fp_gadget->flag_file_type == 0)
        sprintf(filename, "%s/%s_%03d/%s_%03d", filename_path, filename_root, fp_gadget->snapshot_number, filename_root, fp_gadget->snapshot_number);
    else if(fp_gadget->flag_file_type == 1)
        sprintf(filename, "%s/%s_%03d", filename_path, filename_root, fp_gadget->snapshot_number);
    else if(fp_gadget->flag_file_type == 2)
        sprintf(filename, "%s/%s", filename_path, filename_root);
    else if(fp_gadget->flag_file_type == 3)
        sprintf(filename, "%s_%03d", fp_gadget->filename_root, fp_gadget->snapshot_number);
    else if(fp_gadget->flag_file_type == 4)
        sprintf(filename, "%s", fp_gadget->filename_root);

    if(fp_gadget->flag_multifile)
        sprintf(filename, "%s.%d", filename, multifile_number);
}
Exemple #2
0
static DBusMessage *agent_report_error(DBusConnection *connection,
		DBusMessage *message, void *user_data)
{
	struct agent_data *request = user_data;
	DBusMessageIter iter;
	char *path, *service, *error;

	if (handle_message(message, request, agent_report_error) == false)
		return NULL;

	dbus_message_iter_init(message, &iter);

	dbus_message_iter_get_basic(&iter, &path);
	service = strip_path(path);

	dbus_message_iter_next(&iter);
	dbus_message_iter_get_basic(&iter, &error);

	__connmanctl_save_rl();
	if (strcmp(request->interface, AGENT_INTERFACE) == 0)
		fprintf(stdout, "Agent ReportError %s\n", service);
	else
		fprintf(stdout, "VPN Agent ReportError %s\n", service);
	fprintf(stdout, "  %s\n", error);
	__connmanctl_redraw_rl();

	request->message = dbus_message_ref(message);
	__connmanctl_agent_mode("Retry (yes/no)? ", report_error_return,
			request);

	return NULL;
}
Exemple #3
0
static DBusMessage *agent_report_peer_error(DBusConnection *connection,
					DBusMessage *message, void *user_data)
{
	struct agent_data *request = user_data;
	char *path, *peer, *error;
	DBusMessageIter iter;

	if (handle_message(message, request,
				agent_report_peer_error) == false)
		return NULL;

	dbus_message_iter_init(message, &iter);

	dbus_message_iter_get_basic(&iter, &path);
	peer = strip_path(path);

	dbus_message_iter_next(&iter);
	dbus_message_iter_get_basic(&iter, &error);

	__connmanctl_save_rl();
	fprintf(stdout, "Agent ReportPeerError %s\n", peer);
	fprintf(stdout, "  %s\n", error);
	__connmanctl_redraw_rl();

	request->message = dbus_message_ref(message);
	__connmanctl_agent_mode("Retry (yes/no)? ",
				report_error_return, request);
	return NULL;
}
Exemple #4
0
static DBusMessage *agent_request_browser(DBusConnection *connection,
		DBusMessage *message, void *user_data)
{
	struct agent_data *request = user_data;
	DBusMessageIter iter;
	char *service, *url;

	if (handle_message(message, request, agent_request_browser) == false)
		return NULL;

	dbus_message_iter_init(message, &iter);

	dbus_message_iter_get_basic(&iter, &service);
	dbus_message_iter_next(&iter);
	dbus_message_iter_get_basic(&iter, &url);

	__connmanctl_save_rl();
	fprintf(stdout, "Agent RequestBrowser %s\n", strip_path(service));
	fprintf(stdout, "  %s\n", url);
	__connmanctl_redraw_rl();

	request->message = dbus_message_ref(message);
	__connmanctl_agent_mode("Connected (yes/no)? ",
			request_browser_return, request);

	return NULL;
}
Exemple #5
0
PUBLIC int search_file(char *path)
{
    /* 获得文件所在目录的 inode */
    char filename[MAX_PATH];
    memset(filename, 0, MAX_FILENAME_LEN);
    struct inode *dir_inode;
    if (strip_path(filename, path, &dir_inode) != 0)
        return 0;

    if (filename[0] == 0)
        return dir_inode->i_num;

    /* 根据这个 inode 找到对应扇区 */
    int dir_blk0_nr = dir_inode->i_start_sect;                             // 目录起始扇区
    int nr_dir_blks = (dir_inode->i_size + SECTOR_SIZE - 1) / SECTOR_SIZE; // 占用几个扇区(至少一个)
    int nr_dir_entries = dir_inode->i_size / DIR_ENTRY_SIZE;               // 一共有几个条目
    int m = 0;
    struct dir_entry *pde;
    for (int i = 0; i < nr_dir_blks; i++) {
        RD_SECT(dir_inode->i_dev, dir_blk0_nr + i);
        pde = (struct dir_entry *)fsbuf;

        for (int j = 0; j < SECTOR_SIZE / DIR_ENTRY_SIZE; j++, pde++) {
            if (memcmp(filename, pde->name, MAX_FILENAME_LEN) == 0)
                return pde->inode_nr; // 文件存在
            if (++m > nr_dir_entries)
                break;
        }

        if (m > nr_dir_entries)
            break;
    }

    return 0; // 文件不存在
}
Exemple #6
0
/* Function that checks whether we need to mask the specified pid */
int should_mask(const char *name)
{
	char *stripped = strip_path(name);
	char *res = strstr(stripped, PREF);

	return (res == stripped) ? 1 : 0;
}
void set_smooth_filename(char *filename_root_in,int snapshot_number,int multifile_number,int flag_multifile,int flag_file_type,char *filename){
  char filename_root[MAX_FILENAME_LENGTH];
  char filename_path[MAX_FILENAME_LENGTH];

  // Determine/set the filename root and path
  strcpy(filename_root,filename_root_in);
  strip_path(filename_root);
  if(strlen(filename_root)==0)
     sprintf(filename_root,"smooth");
  strcpy(filename_path,filename_root_in);
  strip_file_root(filename_path);

  if(flag_file_type==0)
     sprintf(filename,"%s/%s_%03d/%s_%03d",filename_path,filename_root,snapshot_number,filename_root,snapshot_number);
  else if(flag_file_type==1)
     sprintf(filename,"%s/%s_%03d",filename_path,filename_root,snapshot_number);
  else if(flag_file_type==2)
     sprintf(filename,"%s/%s",filename_path,filename_root);
  else if(flag_file_type==3)
     sprintf(filename,"%s_%03d",filename_root_in,snapshot_number);
  else if(flag_file_type==4)
     sprintf(filename,"%s",filename_root_in);

  if(flag_multifile)
    sprintf(filename,"%s.%d",filename,multifile_number);
}
Exemple #8
0
static BOOL do_create(MESSAGE *message){
    const char *path;
    char dirname[MAX_FILENAME_LENGTH]={0};
    char filename[MAX_FILENAME_LENGTH]={0};
    int flags,inode_index;

    path=message->arg_pointer;
    flags=message->flags;

    //分离父目录路径和文件名
    if(!strip_path(path,dirname,filename)){
        return FALSE;
    }

    inode_index=search_file(dirname,filename,GET_FILE_TYPE(flags));
    if(inode_index<0){
        inode_index=create_file(dirname,filename,GET_FILE_TYPE(flags));
        if(inode_index<0){
            return FALSE;
        }
    }
    else{
        set_error_index(FILE_EXIST);
        return FALSE;
    }
    return TRUE;
}
Exemple #9
0
static DBusMessage *
agent_request_peer_authorization(DBusConnection *connection,
					DBusMessage *message, void *user_data)
{
	struct agent_data *request = user_data;
	DBusMessageIter iter, dict;
	char *peer, *str;
	bool input;
	int i;

	if (handle_message(message, request, agent_request_peer_authorization)
								== false)
		return NULL;

	dbus_message_iter_init(message, &iter);

	dbus_message_iter_get_basic(&iter, &str);
	peer = strip_path(str);

	dbus_message_iter_next(&iter);
	dbus_message_iter_recurse(&iter, &dict);

	__connmanctl_save_rl();
	fprintf(stdout, "Agent RequestPeerAuthorization %s\n", peer);
	__connmanctl_dbus_print(&dict, "  ", " = ", "\n");
	fprintf(stdout, "\n");

	parse_agent_request(request, &iter);

	for (input = false, i = 0; request->input[i].attribute; i++) {
		if (request->input[i].requested == true) {
			input = true;
			break;
		}
	}

	if (!input) {
		request->message = dbus_message_ref(message);
		__connmanctl_agent_mode("Accept connection (yes/no)? ",
					request_authorization_return, request);
		return NULL;
	}

	request->reply = dbus_message_new_method_return(message);
	dbus_message_iter_init_append(request->reply, &request->iter);

	dbus_message_iter_open_container(&request->iter, DBUS_TYPE_ARRAY,
                        DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
                        DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
                        DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
			&request->dict);

	request_input_next(request);

	return NULL;
}
void sleep_tracker_lock(const char* const filename, int line)
{
    const char* const stripped_path = strip_path(filename);

    sleep_statistic_t* stat = sleep_tracker_find(stripped_path);

    // Entry for this driver does not exist, create one.
    if (stat == NULL) {
        stat = sleep_tracker_add(stripped_path);
    }

    core_util_atomic_incr_u8(&stat->count, 1);

    debug("LOCK: %s, ln: %i, lock count: %u\r\n", stripped_path, line, deep_sleep_lock);
}
void sleep_tracker_unlock(const char* const filename, int line)
{
    const char* const stripped_path = strip_path(filename);
    sleep_statistic_t* stat = sleep_tracker_find(stripped_path);

    // Entry for this driver does not exist, something went wrong.
    if (stat == NULL) {
        debug("Unlocking sleep for driver that was not previously locked: %s, ln: %i\r\n", stripped_path, line);
        return;
    }

    core_util_atomic_decr_u8(&stat->count, 1);

    debug("UNLOCK: %s, ln: %i, lock count: %u\r\n", stripped_path, line, deep_sleep_lock);
}
Exemple #12
0
/*****************************************************************************
 *                                do_stat
 *************************************************************************//**
 * Perform the stat() syscall.
 * 
 * @return  On success, zero is returned. On error, -1 is returned.
 *****************************************************************************/
PUBLIC int do_stat()
{
	char pathname[MAX_PATH]; /* parameter from the caller */
	char filename[MAX_PATH]; /* directory has been stipped */

	/* get parameters from the message */
	int name_len = fs_msg.NAME_LEN;	/* length of filename */
	int src = fs_msg.source;	/* caller proc nr. */
	assert(name_len < MAX_PATH);
	phys_copy((void*)va2la(TASK_FS, pathname),    /* to   */
		  (void*)va2la(src, fs_msg.PATHNAME), /* from */
		  name_len);
	pathname[name_len] = 0;	/* terminate the string */

	int inode_nr = search_file(pathname);
	if (inode_nr == INVALID_INODE) {	/* file not found */
		printl("{FS} FS::do_stat():: search_file() returns "
		       "invalid inode: %s\n", pathname);
		return -1;
	}

	struct inode * pin = 0;

	struct inode * dir_inode;
	if (strip_path(filename, pathname, &dir_inode) != 0) {
		/* theoretically never fail here
		 * (it would have failed earlier when
		 *  search_file() was called)
		 */
		assert(0);
	}
	pin = get_inode(dir_inode->i_dev, inode_nr);

	struct stat s;		/* the thing requested */
	s.st_dev = pin->i_dev;
	s.st_ino = pin->i_num;
	s.st_mode= pin->i_mode;
	s.st_rdev= is_special(pin->i_mode) ? pin->i_start_sect : NO_DEV;
	s.st_size= pin->i_size;

	put_inode(pin);

	phys_copy((void*)va2la(src, fs_msg.BUF), /* to   */
		  (void*)va2la(TASK_FS, &s),	 /* from */
		  sizeof(struct stat));

	return 0;
}
Exemple #13
0
Fichier : open.c Projet : Zach41/OS
PRIVATE struct inode* create_file(char* path, int flags) {
    char filename[MAX_PATH];
    struct inode* dir_inode;

    if (strip_path(filename, path, &dir_inode) != 0)
	return 0;
    int inode_nr = alloc_imap_bit(dir_inode -> i_dev);

    int free_sect_nr = alloc_smap_bit(dir_inode -> i_dev, NR_DEFAULT_FILE_SECTS);

    struct inode* nd = new_inode(dir_inode -> i_dev, inode_nr, free_sect_nr);

    new_dir_entry(dir_inode, nd -> i_num, filename);

    return nd;
}
Exemple #14
0
/**************************************************************************************************
 * 					create_file
 **************************************************************************************************
 * Create a file and return it's inode pointer.
 *
 * @param path	The full path of the new file.
 * @param flags	Attributes of the new file.
 *
 * @return	Pointer to inode of the new file if successed, otherwise 0.
 *************************************************************************************************/
PRIVATE struct inode* create_file(char* path, int flags){
	char filename[MAX_PATH];
	struct inode* dir_inode;

	if(strip_path(filename, path, &dir_inode) != 0){
		return 0;
	}

	int nr_inode		= alloc_imap_bit(dir_inode->i_dev);
	/* one file at least is 1MB... */
	int nr_free_sect	= alloc_smap_bit(dir_inode->i_dev, NR_DEFAULT_FILE_SECTS);

	struct inode* newino	= new_inode(dir_inode->i_dev, nr_inode, nr_free_sect);

	new_dir_entry(dir_inode, newino->i_num, filename);

	return newino;
}
Exemple #15
0
PUBLIC int do_stat() {
    char pathname[MAX_PATH];
    char filename[MAX_PATH];

    int name_len = fs_msg.NAME_LEN;
    int src      = fs_msg.source;
    
    memcpy((void*)va2la(TASK_FS, pathname),
	   (void*)va2la(src, fs_msg.PATHNAME),
	   name_len);
    pathname[name_len] = 0;

    int inode_nr = search_file(pathname);

    if (inode_nr == INVALID_INODE) {
	printl("FS::do_stat() failed, search file %s return INVALID INODE.\n", pathname);
	return -1;
    }

    struct inode* pin = 0;
    struct inode* dir_inode = 0;
    if(strip_path(filename, pathname, &dir_inode) != 0) {
	assert(0);
    }

    pin = get_inode(dir_inode -> i_dev, inode_nr);

    struct stat s;

    s.st_dev  = pin -> i_dev;
    s.st_ino  = pin -> i_num;
    s.st_mode = pin -> i_mode;
    s.st_rdev = pin -> i_mode == I_CHAR_SPECIAL ? pin -> i_start_sect : NO_DEV;
    s.st_size = pin -> i_size;

    put_inode(pin);

    memcpy((void*)va2la(src, fs_msg.BUF),
	   (void*)va2la(TASK_FS, &s),
	   sizeof(struct stat));

    return 0;
}
Exemple #16
0
/**
 * Search the file and return the inode_nr.
 *
 * @param[in] path The full path of the file to search.
 * @return         Ptr to the i-node of the file if successful, otherwise zero.
 * 
 * @see open()
 * @see do_open()
 *****************************************************************************/
PUBLIC int search_file(char * path)
{
	int i, j;

	char filename[MAX_PATH];
	memset(filename, 0, MAX_FILENAME_LEN);
	struct inode * dir_inode;
	if (strip_path(filename, path, &dir_inode) != 0)
		return 0;

	if (filename[0] == 0)	/* path: "/" */
		return dir_inode->i_num;

	/**
	 * Search the dir for the file.
	 */
	int dir_blk0_nr = dir_inode->i_start_sect;
	int nr_dir_blks = (dir_inode->i_size + SECTOR_SIZE - 1) / SECTOR_SIZE;
	int nr_dir_entries =
	  dir_inode->i_size / DIR_ENTRY_SIZE; /**
					       * including unused slots
					       * (the file has been deleted
					       * but the slot is still there)
					       */
	int m = 0;
	struct dir_entry * pde;
	for (i = 0; i < nr_dir_blks; i++) {
		RD_SECT(dir_inode->i_dev, dir_blk0_nr + i);
		pde = (struct dir_entry *)fsbuf;
		for (j = 0; j < SECTOR_SIZE / DIR_ENTRY_SIZE; j++,pde++) {
			if (memcmp(filename, pde->name, MAX_FILENAME_LEN) == 0)
				return pde->inode_nr;
			if (++m > nr_dir_entries)
				break;
		}
		if (m > nr_dir_entries) /* all entries have been iterated */
			break;
	}

	/* file not found */
	return 0;
}
Exemple #17
0
void commandoptions::print_usage(std::string executable)
{
  // print usage and program name
  std::cerr << "Usage: " << strip_path(executable);

  // gather and print flags
  std::string shorts = "-";	// we sort the flags into short and long ones
  std::string longs;

  for (flag_iterator i = flag_table.begin(); i != flag_table.end(); ++i) {
    if (i->short_name != '\0')
      shorts += i->short_name;
    else
      longs += ' ' + optionalify("--" + i->long_name);
  }

  // insert -? (for help)
  shorts += '?';
    
  std::cerr << ' ' << optionalify(shorts) << longs; 

  
  // print options
  for (option_iterator i = option_table.begin(); i != option_table.end(); ++i)
    if (i->short_name != '\0')
      std::cerr << ' ' << optionalify(std::string("-") + i->short_name  + " " + i->arg_name);
    else
      std::cerr << ' ' << optionalify("--" + i->long_name + " " + i->arg_name);

  // then print --usage so it doesn't clutter up the more interesting options
  std::cerr << ' ' + optionalify("--usage");
  
  
  // and finally print arguments
  for (argument_iterator i = argument_table.begin(); i != argument_table.end(); ++i)
    std::cerr << ' ' << requirify(i->name);

  
  std::cerr << std::endl;
  
  std::exit(1);
}
Exemple #18
0
static DBusMessage *agent_request_input(DBusConnection *connection,
		DBusMessage *message, void *user_data)
{
	struct agent_data *request = user_data;
	DBusMessageIter iter, dict;
	char *service, *str;

	if (handle_message(message, request, agent_request_input) == false)
		return NULL;

	dbus_message_iter_init(message, &iter);

	dbus_message_iter_get_basic(&iter, &str);
	service = strip_path(str);

	dbus_message_iter_next(&iter);
	dbus_message_iter_recurse(&iter, &dict);

	__connmanctl_save_rl();
	if (strcmp(request->interface, AGENT_INTERFACE) == 0)
		fprintf(stdout, "Agent RequestInput %s\n", service);
	else
		fprintf(stdout, "VPN Agent RequestInput %s\n", service);
	__connmanctl_dbus_print(&dict, "  ", " = ", "\n");
	fprintf(stdout, "\n");

	parse_agent_request(request, &iter);

	request->reply = dbus_message_new_method_return(message);
	dbus_message_iter_init_append(request->reply, &request->iter);

	dbus_message_iter_open_container(&request->iter, DBUS_TYPE_ARRAY,
                        DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
                        DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
                        DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
			&request->dict);

	request_input_next(request);

	return NULL;
}
Exemple #19
0
static BOOL do_unlink(MESSAGE *message){
    int inode_index,flags,sector_index,sector_length;
    const char *path;
    char dir_name[MAX_FILENAME_LENGTH]={0};
    char file_name[MAX_FILENAME_LENGTH]={0};
    INODE inode;

    flags=message->flags;
    path=message->arg_pointer;
    //分离父目录路径和文件名
    if(!strip_path(path,dir_name,file_name)){
        return FALSE;
    }
    
    //1.get inode_index,and remove the dir_entry
    inode_index=search_file(dir_name,file_name,GET_FILE_TYPE(flags));
#ifdef DEBUG_FS
    printl("inode_index=%d(in do_unlink)\n",inode_index);
#endif
    if(inode_index<0){
        set_error_index(FILE_NOT_EXIST);
        return FALSE;
    }
    if(!remove_dir_entry(dir_name,inode_index)){
        set_error_index(FILE_NOT_EXIST);
        return FALSE;
    }
    //2.get file inode by inode_index
    get_inode_by_index(inode_index,&inode);
    
    //3.clear imap by inode_index
    free_imap_bit(inode_index);
    
    //4.clear smap inode
    sector_index=inode.i_start_sector_index-get_data_block_first_index(super_block);
    sector_length=inode.i_sectors_length;
    /* printl("sector_index=%d sector_length=%d data_first_index=%d\n",inode.i_start_sector_index,sector_length,get_data_block_first_index(super_block)); */
    free_smap_bit(sector_index,sector_length);
    
    return TRUE;
}
Exemple #20
0
//path:the full name of the file
//return:inode num of the file if success, otherwise zero
int search_file(char *path)
{
#ifdef DEBUG_rw
    printl("search_file : path =%s|\n", path );
#endif
    int i,j;
    char filename[MAX_PATH_LEN];
    memset(filename , 0, MAX_FILENAME_LEN);
    struct inode *dir_inode;
    if(strip_path(filename, path, &dir_inode)!=0)
        return 0;
#ifdef DEBUG_rw
    printl("search_file : filename =%s|\n", filename );
#endif
    if(filename[0]== 0)//path '/'
        return dir_inode->i_num;

    //search the dir for the file
    int dir_sects0_index = dir_inode->i_start_sect;
    int nr_dir_sects = (dir_inode->i_size +SECTOR_SIZE -1)/SECTOR_SIZE;
    int nr_dir_dentries = (dir_inode->i_size)/DIR_ENTRY_SIZE;

    int m= 0;
    struct dir_entry *pde;
    for (i = 0; i < nr_dir_sects; ++i) { //里面有空的
        RD_SECT(dir_inode->i_dev, dir_sects0_index +i);
        pde = (struct dir_entry *)fsbuf;
        for(j=0; j<SECTOR_SIZE/DIR_ENTRY_SIZE; j++ , pde++) {
            if(memcmp(filename , pde->name, MAX_FILENAME_LEN) == 0)
                return pde->inode_nr;
            if(++m >nr_dir_dentries)
                break;
        }
        if(m> nr_dir_dentries)
            break;
    }
    return 0;
}
Exemple #21
0
/**************************************************************
 *               do_stat
 **************************************************************
	@function:get the information of a pathname
		The information we need for stat hided in the inode. So we just need to get the info of inode of pathname.
	@input:
	@return:0 if sucess
**************************************************************/
int hykdo_stat()
{
    char filename[MAX_FILENAME_LEN];
    char pathname[MAX_PATH_LEN];
    int pathname_len = fs_msg.NAME_LEN;
    int src = fs_msg.source;
//	pathname = fs_msg.PATHNAME; /*no!!! you can not do this directly! For they are not in the same address space*/
    phys_copy( (void *)va2la(TASK_FS, pathname),\
               (void *)va2la(src, fs_msg.PATHNAME),\
               fs_msg.NAME_LEN);
    pathname[pathname_len] = 0;

    int inode_nr_path = search_file(pathname);
    if(inode_nr_path == INVALID_INODE) {
        printl("[FS]:stat faild becase of invalid inode\n");
        return -1;
    }
    struct inode *dir_inode;
    if(strip_path(filename, pathname, &dir_inode)!=0) {
        assert(0);
    }
    struct inode *file_inode=get_inode(dir_inode->i_dev, inode_nr_path);

    struct stat s;
    s.dev = file_inode->i_dev;
    s.size = file_inode->i_size;
    s.mode = file_inode->i_mode;
    s.ino = file_inode->i_num;
    s.rdev = is_special(file_inode->i_mode) ? file_inode->i_start_sect: NO_DEV;

    put_inode(file_inode);

    phys_copy( (void *)va2la(src, fs_msg.BUF),\
               (void *)va2la(TASK_FS, &stat),\
               sizeof(struct stat));
    printl("fs_msg.buf.size:%x", ((struct stat *)va2la(src, fs_msg.BUF))->size);
    return 0;
}
Exemple #22
0
PRIVATE struct inode *creat_file(char *path, int flags)
{
    char filename[MAX_PATH];
    struct inode *dir_inode;

    /* 准备好文件名和文件夹的 inode */
    if (strip_path(filename, path, &dir_inode) != 0)
        return 0;

    /* 分配 inode */
    int inode_nr = alloc_imap_bit(dir_inode->i_dev);

    /* 分配 sector */
    int free_sect_nr = alloc_smap_bit(dir_inode->i_dev, NR_DEFAULT_FILE_SECTS);

    /* 在 inode array 中分配一个 inode */
    struct inode *newino = new_inode(dir_inode->i_dev, inode_nr, free_sect_nr);

    /* 新建一个目录项 */
    new_dir_entry(dir_inode, newino->i_num, filename);

    return newino;
}
// get the directory associated with the riff - free with delete[]
static char * riff_basename(Chunk_With_Children * envd)
{
	RIF_Name_Chunk * rnc = 0;

	List<Chunk *> chlst = envd->lookup_child("RIFFNAME");

	if (chlst.size())
	{
		rnc = (RIF_Name_Chunk *)chlst.first_entry();
		const char * rif_name = strip_path(rnc->rif_name);

		char * basename = new char[strlen(rif_name)+1];
		strcpy(basename,rif_name);
		strip_file_extension(basename);

		return basename;
	}
	const char * deflt = "empty";
	char * basename = new char [strlen(deflt)+1];
	strcpy(basename,deflt);

	return basename;
}
Exemple #24
0
bool encode_and_send_attributes(JCR *jcr, FF_PKT *ff_pkt, int &data_stream)
{
   BSOCK *sd = jcr->store_bsock;
   POOL_MEM attribs(PM_NAME),
            attribsExBuf(PM_NAME);
   char *attribsEx = NULL;
   int attr_stream;
   int comp_len;
   bool status;
   int hangup = get_hangup();
#ifdef FD_NO_SEND_TEST
   return true;
#endif

   Dmsg1(300, "encode_and_send_attrs fname=%s\n", ff_pkt->fname);
   /** Find what data stream we will use, then encode the attributes */
   if ((data_stream = select_data_stream(ff_pkt, me->compatible)) == STREAM_NONE) {
      /* This should not happen */
      Jmsg0(jcr, M_FATAL, 0, _("Invalid file flags, no supported data stream type.\n"));
      return false;
   }
   encode_stat(attribs.c_str(), &ff_pkt->statp, sizeof(ff_pkt->statp), ff_pkt->LinkFI, data_stream);

   /** Now possibly extend the attributes */
   if (IS_FT_OBJECT(ff_pkt->type)) {
      attr_stream = STREAM_RESTORE_OBJECT;
   } else {
      attribsEx = attribsExBuf.c_str();
      attr_stream = encode_attribsEx(jcr, attribsEx, ff_pkt);
   }

   Dmsg3(300, "File %s\nattribs=%s\nattribsEx=%s\n", ff_pkt->fname, attribs.c_str(), attribsEx);

   jcr->lock();
   jcr->JobFiles++;                    /* increment number of files sent */
   ff_pkt->FileIndex = jcr->JobFiles;  /* return FileIndex */
   pm_strcpy(jcr->last_fname, ff_pkt->fname);
   jcr->unlock();

   /*
    * Debug code: check if we must hangup
    */
   if (hangup && (jcr->JobFiles > (uint32_t)hangup)) {
      jcr->setJobStatus(JS_Incomplete);
      Jmsg1(jcr, M_FATAL, 0, "Debug hangup requested after %d files.\n", hangup);
      set_hangup(0);
      return false;
   }

   /**
    * Send Attributes header to Storage daemon
    *    <file-index> <stream> <info>
    */
   if (!sd->fsend("%ld %d 0", jcr->JobFiles, attr_stream)) {
      if (!jcr->is_canceled() && !jcr->is_incomplete()) {
         Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"), sd->bstrerror());
      }
      return false;
   }
   Dmsg1(300, ">stored: attrhdr %s", sd->msg);

   /**
    * Send file attributes to Storage daemon
    *   File_index
    *   File type
    *   Filename (full path)
    *   Encoded attributes
    *   Link name (if type==FT_LNK or FT_LNKSAVED)
    *   Encoded extended-attributes (for Win32)
    *   Delta Sequence Number
    *
    * or send Restore Object to Storage daemon
    *   File_index
    *   File_type
    *   Object_index
    *   Object_len  (possibly compressed)
    *   Object_full_len (not compressed)
    *   Object_compression
    *   Plugin_name
    *   Object_name
    *   Binary Object data
    *
    * For a directory, link is the same as fname, but with trailing
    * slash. For a linked file, link is the link.
    */
   if (!IS_FT_OBJECT(ff_pkt->type) && ff_pkt->type != FT_DELETED) { /* already stripped */
      strip_path(ff_pkt);
   }
   switch (ff_pkt->type) {
   case FT_JUNCTION:
   case FT_LNK:
   case FT_LNKSAVED:
      Dmsg3(300, "Link %d %s to %s\n", jcr->JobFiles, ff_pkt->fname, ff_pkt->link);
      status = sd->fsend("%ld %d %s%c%s%c%s%c%s%c%u%c", jcr->JobFiles,
                         ff_pkt->type, ff_pkt->fname, 0, attribs.c_str(), 0,
                         ff_pkt->link, 0, attribsEx, 0, ff_pkt->delta_seq, 0);
      break;
   case FT_DIREND:
   case FT_REPARSE:
      /* Here link is the canonical filename (i.e. with trailing slash) */
      status = sd->fsend("%ld %d %s%c%s%c%c%s%c%u%c", jcr->JobFiles,
                         ff_pkt->type, ff_pkt->link, 0, attribs.c_str(), 0, 0,
                         attribsEx, 0, ff_pkt->delta_seq, 0);
      break;
   case FT_PLUGIN_CONFIG:
   case FT_RESTORE_FIRST:
      comp_len = ff_pkt->object_len;
      ff_pkt->object_compression = 0;

      if (ff_pkt->object_len > 1000) {
         /*
          * Big object, compress it
          */
         comp_len = compressBound(ff_pkt->object_len);
         POOLMEM *comp_obj = get_memory(comp_len);
         /*
          * FIXME: check Zdeflate error
          */
         Zdeflate(ff_pkt->object, ff_pkt->object_len, comp_obj, comp_len);
         if (comp_len < ff_pkt->object_len) {
            ff_pkt->object = comp_obj;
            ff_pkt->object_compression = 1;    /* zlib level 9 compression */
         } else {
            /*
             * Uncompressed object smaller, use it
             */
            comp_len = ff_pkt->object_len;
         }
         Dmsg2(100, "Object compressed from %d to %d bytes\n", ff_pkt->object_len, comp_len);
      }

      sd->msglen = Mmsg(sd->msg, "%d %d %d %d %d %d %s%c%s%c",
                        jcr->JobFiles, ff_pkt->type, ff_pkt->object_index,
                        comp_len, ff_pkt->object_len, ff_pkt->object_compression,
                        ff_pkt->fname, 0, ff_pkt->object_name, 0);
      sd->msg = check_pool_memory_size(sd->msg, sd->msglen + comp_len + 2);
      memcpy(sd->msg + sd->msglen, ff_pkt->object, comp_len);

      /*
       * Note we send one extra byte so Dir can store zero after object
       */
      sd->msglen += comp_len + 1;
      status = sd->send();
      if (ff_pkt->object_compression) {
         free_and_null_pool_memory(ff_pkt->object);
      }
      break;
   case FT_REG:
      status = sd->fsend("%ld %d %s%c%s%c%c%s%c%d%c", jcr->JobFiles,
                         ff_pkt->type, ff_pkt->fname, 0, attribs.c_str(), 0, 0,
                         attribsEx, 0, ff_pkt->delta_seq, 0);
      break;
   default:
      status = sd->fsend("%ld %d %s%c%s%c%c%s%c%u%c", jcr->JobFiles,
                         ff_pkt->type, ff_pkt->fname, 0, attribs.c_str(), 0, 0,
                         attribsEx, 0, ff_pkt->delta_seq, 0);
      break;
   }

   if (!IS_FT_OBJECT(ff_pkt->type) && ff_pkt->type != FT_DELETED) {
      unstrip_path(ff_pkt);
   }

   Dmsg2(300, ">stored: attr len=%d: %s\n", sd->msglen, sd->msg);
   if (!status && !jcr->is_job_canceled()) {
      Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"), sd->bstrerror());
   }

   sd->signal(BNET_EOD);            /* indicate end of attributes data */

   return status;
}
bool PhotoGeocoder::geocoding_pipeline(string photoPath, GPSCoords &lla){

    //--- Extract Exif data
    //---------------------
    cv::Mat K;
    extract_k_matrix(photoPath, ccdData, K);

    //--- Extract Features & Descriptors
    //----------------------------------
    vector<Feature> features;
    vector<Descriptor> descriptors;

    ftk->extract_features(photoPath,features,descriptors);

    //--- VTree Match
    //---------------
    logger << INDENT << "Quering vocabulary tree for similar documents..." << "\n";

    QueryResults listDocuments = vtree.query(descriptors, MAX_DOCUMENTS);

    for(int i = 0; i < MAX_DOCUMENTS && i < (int) listDocuments.size(); i++){

        logger << INDENT << "Loading document " << i << "\n";

        vector<Descriptor> documentDescs;
        vector<Point3D> points3D;

        string pathDoc;
        dbm.query_synth_path(listDocuments[i].Id, pathDoc);

        //--- Load documents
        //------------------
        if(!load_synthetic(pathDoc, points3D, documentDescs))
            return EXIT_FAILURE;

        //--- Match photo<->documents
        //---------------------------
        logger << INDENT << "Matching with document... " << "\n";

        vector<pair<int,int> > matches;
        int nMatches = ftk->match_features(descriptors, documentDescs, matches);

        logger << INDENT << nMatches << " sift matches were found" << "\n";

        //--- If not enough matches
        if(nMatches < M_LIMIT){
            logger << INDENT << "not enough matches...skipping." << "\n";
            continue;
        }

        vector<cv::Point2f> matchedPoints2D = vector<cv::Point2f>(nMatches);
        vector<cv::Point3f> matchedPoints3D = vector<cv::Point3f>(nMatches);
        for(int j = 0; j < nMatches; j++){
            matchedPoints2D[j] = features[matches[j].first].pt;
            matchedPoints3D[j] = points3D[matches[j].second];
        }

        //--- Compute Projection
        //----------------------
        cv::Matx34f P;
        if(!find_proj_matrix(matchedPoints2D, matchedPoints3D,K,P)){
            logger << INDENT << "Fail to compute P...skipping." << "\n";
            continue;
        }

        cv::Matx44f G;
        float error;
        load_transformation_mat(strip_path(pathDoc) + "/../" + "transformMat.txt", error, G);

        //--- Apply GPS transformation
        //----------------------------
        lla = apply_transformation(P, G);

        //--- Compute Error
        //-----------------
        //TODO: this
        //distance_gps(lla1,lla2);

        logger << INDENT << photoPath << " --> geocoded at:" << "\n";
        logger << INDENT << INDENT << "Latitude: " << lla.lat << "\n";
        logger << INDENT << INDENT << "Longitude: " << lla.lon << "\n";

        return true;
    }

    logger << INDENT << photoPath << " --> not geocoded" << "\n";

    return false;
}
Exemple #26
0
PUBLIC int do_open()
{
    int i = 0;
    int fd = -1; // return value
    char pathname[MAX_PATH];

    int flags = fs_msg.FLAGS;
    int name_len = fs_msg.NAME_LEN;
    int src = fs_msg.source;

    assert(name_len < MAX_PATH);
    phys_copy(
        (void *)va2la(TASK_FS, pathname),
        (void *)va2la(src, fs_msg.PATHNAME),
        name_len
    );
    pathname[name_len] = 0;

    /* 先在调用者进程中查找空闲文件描述符 */
    for (i = 0; i < NR_FILES; i++)
        if (pcaller->filp[i] == 0) {
            fd = i;
            break;
        }
    if ((fd < 0) || (fd >= NR_FILES))
        panic("filp[] is full (PID:%d)", proc2pid(pcaller));

    /* 然后在 f_desc_table 中查找空闲位置 */
    for (i = 0; i < NR_FILE_DESC; i++)
        if (f_desc_table[i].fd_inode == 0)
            break;
    if (i >= NR_FILE_DESC)
        panic("f_desc_table[] is full (PID:%d)", proc2pid(pcaller));

    /* 在磁盘中查找文件 */
    int inode_nr = search_file(pathname);

    /* 准备创建或打开文件 */
    struct inode *pin = 0;
    if (flags & O_CREAT) {
        if (inode_nr) {
            printl("file exists.\n");
            return -1;
        }
        else { // 文件不存在且标志位 O_CREAT
            pin = creat_file(pathname, flags);
        }
    }
    else {
        assert(flags & O_RDWR);

        char filename[MAX_PATH];
        struct inode * dir_inode;
        if (strip_path(filename, pathname, &dir_inode) != 0)
            return -1;
        pin = get_inode(dir_inode->i_dev, inode_nr);
    }

    /* 关联文件描述符 */
    if (pin) {
        /* proc <- fd (connects proc with file_descriptor) */
        pcaller->filp[fd] = &f_desc_table[i];

        /* fd <- inode (connects file_descriptor with inode) */
        f_desc_table[i].fd_mode = flags;
        f_desc_table[i].fd_pos = 0;
        f_desc_table[i].fd_inode = pin;

        int imode = pin->i_mode & I_TYPE_MASK;
        if (imode == I_CHAR_SPECIAL) {
            MESSAGE driver_msg;

            driver_msg.type = DEV_OPEN;
            int dev = pin->i_start_sect;
            driver_msg.DEVICE = MINOR(dev);
            assert(MAJOR(dev) == 4);
            assert(dd_map[MAJOR(dev)].driver_nr != INVALID_DRIVER);

            /* 如果是字符设备则交给该设备的驱动处理 */
            send_recv(BOTH, dd_map[MAJOR(dev)].driver_nr, &driver_msg);
        }
        else if (imode == I_DIRECTORY)
            assert(pin->i_num == ROOT_INODE);
        else
            assert(pin->i_mode == I_REGULAR);
    }
    else
        return -1; // open file failed

    return fd;
}
Exemple #27
0
/**
 * Open a file and return the file descriptor.
 *
 * @return File descriptor if successful, otherwise a negative error code.
 *****************************************************************************/
PUBLIC int do_open()
{
    int fd = -1;		/* return value */

    char pathname[MAX_PATH];

    /* get parameters from the message */
    int flags = fs_msg.FLAGS;	/* access mode */
    int name_len = fs_msg.NAME_LEN;	/* length of filename */
    int src = fs_msg.source;	/* caller proc nr. */
    assert(name_len < MAX_PATH);
    phys_copy((void*)va2la(TASK_FS, pathname),
              (void*)va2la(src, fs_msg.PATHNAME),
              name_len);
    pathname[name_len] = 0;

    /* find a free slot in PROCESS::filp[] */
    int i;
    for (i = 0; i < NR_FILES; i++) {
        if (pcaller->filp[i] == 0) {
            fd = i;
            break;
        }
    }
    if ((fd < 0) || (fd >= NR_FILES))
        panic("filp[] is full (PID:%d)", proc2pid(pcaller));

    /* find a free slot in f_desc_table[] */
    for (i = 0; i < NR_FILE_DESC; i++)
        if (f_desc_table[i].fd_inode == 0)
            break;
    if (i >= NR_FILE_DESC)
        panic("f_desc_table[] is full (PID:%d)", proc2pid(pcaller));

    int inode_nr = search_file(pathname);

    struct inode * pin = 0;
    if (flags & O_CREAT) {
        if (inode_nr) {
            printl("file exists.\n");
            return -1;
        }
        else {
            pin = create_file(pathname, flags);
        }
    }
    else {
        assert(flags & O_RDWR);

        char filename[MAX_PATH];
        struct inode * dir_inode;
        if (strip_path(filename, pathname, &dir_inode) != 0)
            return -1;
        pin = get_inode(dir_inode->i_dev, inode_nr);
    }

    if (pin) {
        /* connects proc with file_descriptor */
        pcaller->filp[fd] = &f_desc_table[i];

        /* connects file_descriptor with inode */
        f_desc_table[i].fd_inode = pin;

        f_desc_table[i].fd_mode = flags;
        /* f_desc_table[i].fd_cnt = 1; */
        f_desc_table[i].fd_pos = 0;

        int imode = pin->i_mode & I_TYPE_MASK;

        if (imode == I_CHAR_SPECIAL) {
            MESSAGE driver_msg;
            driver_msg.type = DEV_OPEN;
            int dev = pin->i_start_sect;
            driver_msg.DEVICE = MINOR(dev);
            assert(MAJOR(dev) == 4);
            assert(dd_map[MAJOR(dev)].driver_nr != INVALID_DRIVER);
            send_recv(BOTH,
                      dd_map[MAJOR(dev)].driver_nr,
                      &driver_msg);
        }
        else if (imode == I_DIRECTORY) {
            assert(pin->i_num == ROOT_INODE);
        }
        else {
            assert(pin->i_mode == I_REGULAR);
        }
    }
    else {
        return -1;
    }

    return fd;
}
Exemple #28
0
void SID_init(int       *argc,
              char     **argv[],
              SID_args   args[],
              void      *mpi_comm_as_void){
  int  status;
  int  i_level;
  int  i_char;
  int  flag_continue;
  int  flag_passed_comm;

  // MPI-specific things
#if USE_MPI
  int      n_keys;
  int      i_key;
  char     key[256];
  char     key_value[256];
  int      key_exists;
  char     nodes_string[256];
  SID_fp   fp_tmp;
  FILE    *fp_hack;
  int      node_name_length;
  MPI_Comm mpi_comm;
#if USE_MPI_IO
  MPI_Info info_disp;
#endif

  if (mpi_comm_as_void == NULL)
  {
    flag_passed_comm = 0;
    MPI_Init(argc,argv);
    MPI_Comm_dup(MPI_COMM_WORLD, &mpi_comm);
  }
  else
  {
    mpi_comm = *((MPI_Comm *) mpi_comm_as_void);
    flag_passed_comm = 1;
  }

  MPI_Comm_size(mpi_comm, &(SID.n_proc));
  MPI_Comm_rank(mpi_comm, &(SID.My_rank));

  SID.My_node =(char *)SID_malloc(SID_MAXLENGTH_PROCESSOR_NAME * sizeof(char));
#if USE_MPI
  MPI_Get_processor_name(SID.My_node, &node_name_length);
#else
  sprintf(SID.My_node,"localhost");
  node_name_length=strlen(SID.My_node);
#endif
  if (node_name_length >= SID_MAXLENGTH_PROCESSOR_NAME-1)
    SID_trap_error("SID_MAXLENGTH_PROCESSOR_NAME needs to be increased",ERROR_LOGIC);

  // Make my_rank=MASTER_RANK the master
  if(SID.My_rank==MASTER_RANK)
    SID.I_am_Master=TRUE;
  else
    SID.I_am_Master=FALSE;

  // Identify the last rank
  if(SID.My_rank==SID.n_proc-1)
    SID.I_am_last_rank=TRUE;
  else
    SID.I_am_last_rank=FALSE;

  #if USE_MPI_IO
  // Fetch collective buffering defaults
  MPI_Info_create(&(SID.file_info));
  if(SID.I_am_Master){
    fp_hack=fopen(".tmp.SID","w+");    
    fclose(fp_hack);
  }
  MPI_Barrier(mpi_comm);
  MPI_File_open(mpi_comm,
                ".tmp.SID",
                MPI_MODE_WRONLY,
                MPI_INFO_NULL,
                &(fp_tmp.fp));
  MPI_File_get_info(fp_tmp.fp,&info_disp);
  MPI_Info_get_nkeys(info_disp,&n_keys);
  for(i_key=0;i_key<n_keys;i_key++){
    MPI_Info_get_nthkey(info_disp,i_key,key);
    MPI_Info_get(info_disp,key,MPI_MAX_INFO_VAL,key_value,&key_exists);
    if(key_exists)
      MPI_Info_set((SID.file_info),key,key_value);
  }
  MPI_File_close(&(fp_tmp.fp));
  if(SID.I_am_Master)
    remove(".tmp.SID");

  // Set user-defined colective buffering optimizations
  sprintf(nodes_string,"%d",MIN(SID.n_proc,N_IO_FILES_MAX));
  MPI_Info_set((SID.file_info),"cb_nodes",            nodes_string);
  MPI_Info_set((SID.file_info),"cb_config_list",      "*:1");
  #endif
#else
  SID.My_rank=MASTER_RANK;
  SID.n_proc =1;
#endif

/*
#if !USE_MPI_IO
    SID.n_groups=SID.n_proc/N_IO_FILES_MAX;
    if(SID.n_proc%N_IO_FILES_MAX) SID.n_groups++;
    SID.My_group=SID.My_rank/N_IO_FILES_MAX;
#endif
*/

  // Set ranks to the left and right
  SID.rank_to_right  =(SID.My_rank+1)%SID.n_proc;
  SID.rank_to_left   = SID.My_rank-1;
  if(SID.rank_to_left<0)
    SID.rank_to_left = SID.n_proc-1;

  // Intitialize log timing information
  SID.time_start_level=(time_t *)SID_malloc(sizeof(time_t)*SID_LOG_MAX_LEVELS);
  SID.time_stop_level =(time_t *)SID_malloc(sizeof(time_t)*SID_LOG_MAX_LEVELS);
  SID.time_total_level=(int    *)SID_malloc(sizeof(int)   *SID_LOG_MAX_LEVELS);
  SID.IO_size         =(double *)SID_malloc(sizeof(double)*SID_LOG_MAX_LEVELS);
  SID.flag_use_timer  =(int    *)SID_malloc(sizeof(int)   *SID_LOG_MAX_LEVELS);
  for(i_level=0;i_level<SID_LOG_MAX_LEVELS;i_level++){
    SID.time_start_level[i_level]=0;
    SID.time_stop_level[i_level] =0;
    SID.time_total_level[i_level]=0;
    SID.IO_size[i_level]         =0.;
    SID.flag_use_timer[i_level]  =FALSE;
  }

  // Initialize other log information
#if USE_MPI
  if(*argc>1)
    SID.fp_in        =fopen((*argv)[1],"r");
  else
    SID.fp_in        =NULL;
#else
  SID.fp_in          =stdin;
#endif
  if (flag_passed_comm)
    SID.fp_log       = NULL;
  else
    SID.fp_log       = stderr;
  SID.level          =0;
  SID.indent         =TRUE;
  SID.awake          =TRUE;
  SID.flag_results_on=FALSE;
  SID.verbosity      =SID_LOG_MAX_LEVELS;

  // Store the name of the binary executable that brought us here
  strcpy(SID.My_binary,(*argv)[0]);
  strip_path(SID.My_binary);

  // Initialize argument information
  if(args!=NULL){
    if((status=SID_parse_args(*argc,*argv,args))>0){
      SID_print_syntax(*argc,*argv,args);
      SID_exit(status);
    }
  }
  else
    SID.args=NULL;

#if USE_MPI_IO
  if(SID.I_am_Master){
    fp_hack=fopen(".tmp.SID","w+");
    fclose(fp_hack);
  }
  MPI_Barrier(mpi_comm);
  SID_fopen(".tmp.SID","w",&fp_tmp);
  MPI_File_get_info(fp_tmp.fp,&info_disp);
  if(SID.I_am_Master){
    fprintf(stdout,"\n");
    fprintf(stdout,"MPI-I/O Configuration:\n");
    fprintf(stdout,"---------------------\n");
    MPI_Info_get_nkeys(info_disp,&n_keys);
    for(i_key=0;i_key<n_keys;i_key++){
      MPI_Info_get_nthkey(info_disp,i_key,key);
      MPI_Info_get(info_disp,key,MPI_MAX_INFO_VAL,key_value,&key_exists);
      if(key_exists)
        fprintf(stdout,"key %2d of %d: {%s}={%s}\n",i_key+1,n_keys,key,key_value);
    }
    fprintf(stdout,"\n");
  }
  SID_fclose(&fp_tmp);
  if(SID.I_am_Master)
    remove(".tmp.SID");
#else
  #if USE_MPI
  if(SID.I_am_Master)
    fprintf(stdout,"MPI-I/O switched off.\n\n");
  #endif
#endif

  // Create private COMM_WORLD
  SID_Comm_init(&(SID.COMM_WORLD));
#if USE_MPI
  MPI_Comm_dup(mpi_comm,                &((SID.COMM_WORLD)->comm));
  MPI_Comm_group((SID.COMM_WORLD)->comm,&((SID.COMM_WORLD)->group));
  MPI_Comm_size(SID.COMM_WORLD->comm,   &((SID.COMM_WORLD)->n_proc));
  MPI_Comm_rank(SID.COMM_WORLD->comm,   &((SID.COMM_WORLD)->My_rank));

  // We have duplicated our duplicate mpi communicator - now we can free the
  // original duplicate
  MPI_Comm_free(&mpi_comm);
#else
  SID.COMM_WORLD->comm   =NULL;
  SID.COMM_WORLD->group  =NULL;
  SID.COMM_WORLD->n_proc =1;
  SID.COMM_WORLD->My_rank=MASTER_RANK;
#endif

  // Start total-run-ime timer
  (void)time(&(SID.time_start));

  // Default max wallclock
  SID.max_wallclock=DEFAULT_MAX_WALLCLOCK_TIME;
}
Exemple #29
0
int main(int argc, char *argv[]){
  int     n_search;
  int     i_halo;
  char    filename_SSimPL_root[MAX_FILENAME_LENGTH];
  char    filename_in[MAX_FILENAME_LENGTH];
  char    group_text_prefix[4];
  int     n_files;
  int     k_read;
  int     max_n_groups;
  int     l_read;
  int     n_groups;
  int     j_read;
  int     mode;
  int     n_groups_i;
  int     n_groups_j;
  int     j_halo;
  int     match;
  int     i_read;
  int     i_read_start;
  int     i_read_stop;
  SID_fp  fp_in;

  SID_init(&argc,&argv,NULL,NULL);

  // Fetch user inputs
  strcpy(filename_SSimPL_root,argv[1]);
  if(!strcmp(argv[2],"groups") || !strcmp(argv[2],"group"))
     mode=MATCH_GROUPS;
  else if(!strcmp(argv[2],"subgroups") || !strcmp(argv[2],"subgroup"))
     mode=MATCH_SUBGROUPS;
  else{
     SID_log("Invalid mode selection {%s}.  Should be 'group' or 'subgroup'.",SID_LOG_COMMENT,argv[2]);
     SID_exit(ERROR_SYNTAX);
  }
  i_read=atoi(argv[3]);
  j_read=atoi(argv[4]);
  SID_log("Searching match information for halo #%d in file #%d of {%s}...",SID_LOG_OPEN|SID_LOG_TIMER,i_halo,i_read,filename_SSimPL_root);

  // Convert filename_root to filename
  switch(mode){
     case MATCH_SUBGROUPS:
     sprintf(group_text_prefix,"sub");
     break;
     case MATCH_GROUPS:
     sprintf(group_text_prefix,"");
     break;
  }

  // Set the standard SSiMPL match file path
  char filename_root_in[MAX_FILENAME_LENGTH];
  sprintf(filename_root_in,"%s/trees/matches/",filename_SSimPL_root);

  // Set the output file
  char filename_base[MAX_FILENAME_LENGTH];
  char filename_out[MAX_FILENAME_LENGTH];
  sprintf(filename_base,filename_SSimPL_root);
  if(!strcmp(&(filename_base[strlen(filename_base)-1]),"/"))
     strcpy(&(filename_base[strlen(filename_base)-1]),"\0");
  strip_path(filename_base);
  sprintf(filename_out,"%s_%d_%d_2way_matches.txt",filename_base,i_read,j_read);

  // Read header information
  SID_log("Reading header information...",SID_LOG_OPEN);
  sprintf(filename_in,"%s/%sgroup_matches_header.dat",filename_root_in,group_text_prefix);
  SID_fopen(filename_in,"r",&fp_in);
  SID_fread(&i_read_start,sizeof(int),1,&fp_in);SID_log("snap start  =%d",SID_LOG_COMMENT,i_read_start);
  SID_fread(&i_read_stop, sizeof(int),1,&fp_in);SID_log("snap stop   =%d",SID_LOG_COMMENT,i_read_stop);
  SID_fread(&n_search,    sizeof(int),1,&fp_in);SID_log("search range=%d",SID_LOG_COMMENT,n_search);
  SID_fread(&n_files,     sizeof(int),1,&fp_in);SID_log("# of files  =%d",SID_LOG_COMMENT,n_files);
  for(k_read=0,max_n_groups=0;k_read<n_files;k_read++){
     SID_fread(&l_read,  sizeof(int),1,&fp_in);
     SID_fread(&n_groups,sizeof(int),1,&fp_in);
     SID_fseek(&fp_in,   sizeof(int),n_groups,SID_SEEK_CUR);
     if(mode==MATCH_GROUPS)
        SID_fseek(&fp_in,   sizeof(int),n_groups,SID_SEEK_CUR);
     max_n_groups=MAX(max_n_groups,n_groups);
  }
  SID_log("Max # groups=%d",SID_LOG_COMMENT,max_n_groups);
  SID_fclose(&fp_in);
  SID_log("Done.",SID_LOG_CLOSE);

  // Initialize some arrays
  int    *n_particles_i       =(int    *)SID_malloc(sizeof(int)   *max_n_groups);
  int    *n_particles_j       =(int    *)SID_malloc(sizeof(int)   *max_n_groups);
  int    *match_forward_ids   =(int    *)SID_malloc(sizeof(int)   *max_n_groups);
  size_t *match_forward_index =(size_t *)SID_malloc(sizeof(size_t)*max_n_groups);
  float  *match_forward_score =(float  *)SID_malloc(sizeof(float) *max_n_groups);
  char   *match_forward_2way  =(char   *)SID_malloc(sizeof(char)  *max_n_groups);
  int    *match_backward_ids  =(int    *)SID_malloc(sizeof(int)   *max_n_groups);
  size_t *match_backward_index=(size_t *)SID_malloc(sizeof(size_t)*max_n_groups);
  float  *match_backward_score=(float  *)SID_malloc(sizeof(float) *max_n_groups);
  char   *match_backward_2way =(char   *)SID_malloc(sizeof(char)  *max_n_groups);

  // Loop over all matching combinations
  SID_log("Reading forward matches...",SID_LOG_OPEN|SID_LOG_TIMER);
  SID_set_verbosity(SID_SET_VERBOSITY_DEFAULT);
  read_matches(filename_root_in,
               i_read,
               j_read,
               max_n_groups,
               mode,
               &n_groups_i,
               &n_groups_j,
               n_particles_i,
               n_particles_j,
               NULL,
               NULL,
               match_forward_ids,
               match_forward_score,
               match_forward_index,
               match_forward_2way,
               FALSE);
  SID_log("Done.",SID_LOG_CLOSE);
  SID_log("Processing backwards matches...",SID_LOG_OPEN|SID_LOG_TIMER);
  read_matches(filename_root_in,
               j_read,
               i_read,
               max_n_groups,
               mode,
               &n_groups_j,
               &n_groups_i,
               n_particles_j,
               n_particles_i,
               NULL,
               NULL,
               match_backward_ids,
               match_backward_score,
               match_backward_index,
               match_backward_2way,
               FALSE);
  SID_log("Done.",SID_LOG_CLOSE);

  // Open output file
  FILE *fp_out;
  fp_out=fopen(filename_out,"w");
  int i_column=1;
  fprintf(fp_out,"# Column (%02d): Halo index for snapshot %d\n",          i_column++,i_read);
  fprintf(fp_out,"#        (%02d): Halo index for snapshot %d\n",          i_column++,j_read);
  fprintf(fp_out,"#        (%02d): No. particles in snapshot %d\n",        i_column++,i_read);
  fprintf(fp_out,"#        (%02d): No. particles in snapshot %d\n",        i_column++,j_read);
  fprintf(fp_out,"#        (%02d): Forward  match score\n",                i_column++);
  fprintf(fp_out,"#        (%02d): Forward  match score/min match score\n",i_column++);
  fprintf(fp_out,"#        (%02d): Backward match score\n",                i_column++);
  fprintf(fp_out,"#        (%02d): Backward match score/min match score\n",i_column++);
  for(int i_halo=0;i_halo<n_groups_i;i_halo++){
     int j_halo=match_forward_ids[i_halo];
     if(match_forward_2way[i_halo]){
        if(j_halo<0 || j_halo>n_groups_j)
           SID_trap_error("There's an invalid match id (ie. %d<0 || %d>%d)  attached to a 2-way match!",ERROR_LOGIC,j_halo,j_halo,n_groups_j);
        fprintf(fp_out,"%7d %7d %6d %6d %10.3le %10.3le %10.3le %10.3le\n",
                i_halo,
                j_halo,
                n_particles_i[i_halo],
                n_particles_j[j_halo],
                match_forward_score[i_halo],
                match_forward_score[i_halo]/minimum_match_score((double)n_particles_i[i_halo]),
                match_backward_score[j_halo],
                match_backward_score[j_halo]/minimum_match_score((double)n_particles_j[j_halo]));
     }                
  }
  fclose(fp_out);

  // Clean-up
  SID_free(SID_FARG n_particles_i);
  SID_free(SID_FARG n_particles_j);
  SID_free(SID_FARG match_forward_ids);
  SID_free(SID_FARG match_forward_index);
  SID_free(SID_FARG match_forward_score);
  SID_free(SID_FARG match_forward_2way);
  SID_free(SID_FARG match_backward_ids);
  SID_free(SID_FARG match_backward_index);
  SID_free(SID_FARG match_backward_score);
  SID_free(SID_FARG match_backward_2way);
  
  SID_log("Done.",SID_LOG_CLOSE);
  SID_exit(ERROR_NONE);
}
void CL_RIFFImage::GetPath(ImageDescriptor const & idsc, Environment_Data_Chunk * envd, BMPN_Flags bflags)
{
	if (fname) delete[] fname;
	fname = 0; 
	
	// set the name
	if (name) delete[] name;
	char * nptr = strip_path(idsc.filename);
	name = new char[strlen(nptr)+1];
	strcpy(name,nptr);
	#if 0
	char orig_ext[32];
	char const * oeP = strrchr(name,'.');
	if (!oeP) eoP = "";
	strcpy(orig_ext,oeP);
	#endif
	strip_file_extension(name);
					
	// load this image
	char const * pg0ext = ".PG0";
	switch (imode)
	{
		case CLM_16BIT:
		case CLM_24BIT:
		case CLM_32BIT:
		#if ALLOW_LOAD_ORIGINAL
		{
			char const * dir2 = idsc.flags & IDSCF_SPRITE ? "Sprites\\" : "";
			char * riffname = riff_basename(envd);
			char const * dir3 = idsc.flags & IDSCF_INCLUDED ? idsc.rifname : riffname;
			fname = new char[strlen(ToolsTex_Directory)+strlen(dir2)+strlen(dir3)+1+strlen(name)+5];
			strcpy(fname,ToolsTex_Directory);
			strcat(fname,dir2);
			strcat(fname,dir3);
			strcat(fname,"\\");
			strcat(fname,name);
			strcat(fname,".PP0");
			delete[] riffname;
			break;
		}
		#endif
		case CLM_ATTACHEDPALETTE:
		{
			char const * dir2 = idsc.flags & IDSCF_SPRITE ? "Sprites\\" : idsc.flags & IDSCF_SUBSHAPE ? "SubShps\\All\\" : "";
			char * riffname = riff_basename(envd);
			char const * dir3 = idsc.flags & IDSCF_INCLUDED ? idsc.rifname : riffname;
			fname = new char[strlen(GenTex_Directory)+strlen(dir2)+strlen(dir3)+1+strlen(name)+5];
			strcpy(fname,GenTex_Directory);
			strcat(fname,dir2);
			strcat(fname,dir3);
			strcat(fname,"\\");
			strcat(fname,name);
			strcat(fname,".BM0");
			delete[] riffname;
			#if TRY_OLD_DIRS // temporary until all textures go into subshps directory
			FFILE * ftest = ffopen(fname,"rb");
			if (ftest) ffclose(ftest);
			else
			{
				_LOGPUT("WARNING! Not found in SubShps directory\n");
				char const * dir2 = idsc.flags & IDSCF_SPRITE ? "Sprites\\" : "";
				char * riffname = riff_basename(envd);
				char const * dir3 = idsc.flags & IDSCF_INCLUDED ? idsc.rifname : riffname;
				delete[] fname;
				fname = new char[strlen(GenTex_Directory)+strlen(dir2)+strlen(dir3)+1+strlen(name)+5];
				strcpy(fname,GenTex_Directory);
				strcat(fname,dir2);
				strcat(fname,dir3);
				strcat(fname,"\\");
				strcat(fname,name);
				strcat(fname,".BM0");
				delete[] riffname;
			}
			#endif
			break;
		}
		case CLM_TLTPALETTE:
			if (!(bflags & ChunkBMPFlag_NotLit))
			{
				pg0ext = ".PW0";
				flags.tltpalette = 1;
			}
		case CLM_GLOBALPALETTE:
		{
			if (idsc.flags & IDSCF_FIXEDPALETTE)
			{
				char const * dir2 = idsc.fixrifname ? *idsc.fixrifname ? idsc.fixrifname : 0 : 0;
				char const * dir3 = idsc.flags & IDSCF_SPRITE ? "Sprites\\" : "";
				char * riffname = riff_basename(envd);
				char const * dir4 = idsc.flags & IDSCF_INCLUDED ? idsc.rifname : riffname;
				fname = new char[strlen(FixTex_Directory)+(dir2 ? strlen(dir2)+1 : 0)+strlen(dir3)+strlen(dir4)+1+strlen(name)+5];
				strcpy(fname,FixTex_Directory);
				if (dir2)
				{
					strcat(fname,dir2);
					strcat(fname,"\\");
				}
				strcat(fname,dir3);
				strcat(fname,dir4);
				strcat(fname,"\\");
				strcat(fname,name);
				strcat(fname,pg0ext);
				delete[] riffname;
			}
			else
			{
				char const * dir1 = game_mode ? GameTex_Directory : ToolsTex_Directory;
				char * dir2 = riff_basename(envd);
				char const * dir4 = idsc.flags & IDSCF_SPRITE ? "Sprites\\" : "";
				char const * dir5 = idsc.flags & IDSCF_INCLUDED ? idsc.rifname : 0;
				fname = new char[strlen(dir1)+strlen(dir2)+1+(game_mode ? strlen(game_mode)+1 : 0)+strlen(dir4)+(dir5 ? strlen(dir5)+1 : 0)+strlen(name)+5];
				strcpy(fname,dir1);
				strcat(fname,dir2);
				strcat(fname,"\\");
				if (game_mode)
				{
					strcat(fname,game_mode);
					strcat(fname,"\\");
				}
				strcat(fname,dir4);
				if (dir5)
				{
					strcat(fname,dir5);
					strcat(fname,"\\");
				}
				strcat(fname,name);
				strcat(fname,pg0ext);
				delete[] dir2;
			}
			break;
		}
	}

	if (!fname)
	{
		_LOGPUT("WARNING! GetPath returning NULL pointer\n");
	}
	else
		_LOGPRINT(("file expected to be %s\n",fname));
}