示例#1
0
/* Open files and write the basic headers */
static void
OpenAllFiles(void)
{
    const char *dwarf_h      = "dwarf.h";
    const char *names_h      = "dwarf_names.h";
    const char *names_c      = "dwarf_names.c";
    const char *names_enum_h = "dwarf_names_enum.h";
    const char *names_new_h  = "dwarf_names_new.h";

    f_dwarf_in = open_path(input_name,dwarf_h,"r");
    f_names_enum_h = open_path(output_name,names_enum_h,"w");
    f_names_new_h = open_path(output_name,names_new_h,"w");
    f_names_h = open_path(output_name,names_h,"w");
    f_names_c = open_path(output_name,names_c,"w");
}
示例#2
0
int syscall_chdir(const char *path)
{
	int drive;
	int curdir_handle, olddir_handle;

	if (strlen(path) > 500) return ELONGPATH;

	if (path[1] == ':')	// Drive name present
	{
		drive = toupper(path[0]) - 'A';
		path = path + 2;
	}
	else drive = fileinf->current_drive;

	if (drive !=fileinf->current_drive) return EINVALID_ARGUMENT;

	olddir_handle = get_curdir_handle(drive);
	curdir_handle = open_path(drive, path);

	if (curdir_handle < 0)
		return curdir_handle;	// Error

	set_drive_curdir(drive, curdir_handle);
	close_dir(olddir_handle);

	return 0; // Success
}
示例#3
0
int syscall_open(const char *path, int type, mode_t mode)
{
	int i, drive;
	int curdir_handle, new_handle;
	char name_comp[13], conv_name[11], dir_path[501];

	if (strlen(path) > 500) return ELONGPATH;

	parse_path(path, &drive, dir_path, name_comp);

	if (dir_path[0] != 0)
	{
		curdir_handle = open_path(drive, dir_path);

		if (curdir_handle < 0)
			return curdir_handle;	// Error
	}
	else
	{
		curdir_handle = get_curdir_handle(drive);
		increment_ref_count(curdir_handle);
	}

	// Last file name component.
	if (convert_name(name_comp, conv_name) < 0)
	{
		close_dir(curdir_handle);
		return EINVALIDNAME; // Error
	}

	mode = mode & 0x3f; // Valid bits
	if (mode == 0) mode = 0x20;
	else	mode = mode & (~(FTYPE_DIR | FTYPE_VOLUME));

	if (type == 0) type = O_RDONLY;
	else type = type & (O_RDONLY | O_WRONLY | O_CREAT | O_RDWR | O_APPEND | O_TRUNC); // Clear invalid bits

	new_handle = open_file(curdir_handle, conv_name, type, mode);
	close_dir(curdir_handle);
	if (new_handle >= 0)
	{
		// Store this into task file handle table and return its index
		for (i=3; i<20; i++)
		{
			if (fileinf->fhandles[i] < 0)
			break;
		}	
		if (i < 20) 
		{
			fileinf->fhandles[i] = new_handle;
			new_handle = i;
		}
		else
		{
			close_file(new_handle);
			new_handle = ENO_FREE_FILE_TABLE_SLOT;
		}
	}
	return new_handle; // may be failure or success
}
示例#4
0
int syscall_mkdir(const char *pathname, mode_t mode)
{
	int i, j, drive, res;
	int curdir_handle;
	char name_comp[13], conv_name[11], dir_path[501];

	if (strlen(pathname) > 500) return ELONGPATH;

	parse_path(pathname, &drive, dir_path, name_comp);

	if (name_comp[0] == 0 && strlen(dir_path) > 0)
	{
		// remove the last component
		if (dir_path[strlen(dir_path)-1] == '/' || dir_path[strlen(dir_path)-1] == '\\') dir_path[strlen(dir_path)-1] = 0;
		j = 13;
		for (i=strlen(dir_path); (j>=0 && i>=0 && dir_path[i] != '/' && dir_path[i] != '\\'); i--) 
			name_comp[--j] = dir_path[i];

		if (j<0) j = 0; // Long name. Incorrect results
		if (i == 0) // special case
			dir_path[1] = 0; // only root dir
		else	dir_path[i] = 0; // replace last / with null char

		for (i=0; i<=12; i++)
			name_comp[i] = name_comp[j++];
	}
	if (dir_path[0] != 0)
	{
		curdir_handle = open_path(drive, dir_path);

		if (curdir_handle < 0)
			return curdir_handle;	// Error
	}
	else
	{
		curdir_handle = get_curdir_handle(drive);
		increment_ref_count(curdir_handle);
	}

	// Last new dir name component.
	if (name_comp[0] == 0)
	{
		close_dir(curdir_handle);
		return EDUPLICATE_ENTRY;
	}

	if (convert_name(name_comp, conv_name) < 0)
	{
		close_dir(curdir_handle);
		return EINVALIDNAME; // Error
	}

	res = make_dir(curdir_handle, conv_name);
	close_dir(curdir_handle);

	if (res == 1) return 0; // Success
	else return res; // failure
}
示例#5
0
int syscall_creat(const char *path, mode_t mode)
{
	int i, drive;
	int curdir_handle, new_handle;
	char name_comp[13], conv_name[11], dir_path[501];

	if (strlen(path) > 500) return ELONGPATH;

	parse_path(path, &drive, dir_path, name_comp);
	if (dir_path[0] != 0)
	{
		curdir_handle = open_path(drive, dir_path);

		if (curdir_handle < 0)
			return curdir_handle;	// Error
	}
	else
	{
		curdir_handle = get_curdir_handle(drive);
		increment_ref_count(curdir_handle);
	}

	// Last file name component.
	if (convert_name(name_comp, conv_name) < 0)
	{
		close_dir(curdir_handle);
		return EINVALIDNAME; // Error
	}

	mode = mode & 0x3f; // Valid bits
	if (mode == 0) mode = 0x20;
	else	mode = mode & (~(FTYPE_DIR | FTYPE_VOLUME));

	new_handle = create_file(curdir_handle, conv_name, mode);
	close_dir(curdir_handle);
	
        for (i=3; i<20; i++)
        {
                if (fileinf->fhandles[i] < 0)
                break;
        }
        if (i < 20)
        {
                fileinf->fhandles[i] = new_handle;
                new_handle = i;
        }
        else
        {
                close_file(new_handle);
                new_handle = ENO_FREE_FILE_TABLE_SLOT;
        }

	return new_handle; // may be failure or success
}
示例#6
0
文件: hidasync.c 项目: NoPublic/GIMX
/*
 * \brief Open a hid device.
 *
 * \param vendor   the vendor id of the hid device to open.
 * \param product  the product id of the hid device to open.
 *
 * \return the identifier of the opened device (to be used in further operations), \
 * or -1 in case of failure (e.g. no device found).
 */
int hidasync_open_ids(unsigned short vendor, unsigned short product)
{
  int ret = -1;

  GUID guid;
  HDEVINFO info;
  DWORD reqd_size;
  SP_DEVICE_INTERFACE_DATA iface;
  SP_DEVICE_INTERFACE_DETAIL_DATA *details;
  int index;
  
  HidD_GetHidGuid(&guid);
  info = SetupDiGetClassDevs(&guid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
  if(info != INVALID_HANDLE_VALUE) {
    for(index = 0; ; ++index) {
	    iface.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
      if(SetupDiEnumDeviceInterfaces(info, NULL, &guid, index, &iface) == FALSE) {
        break; //no more device
      }
      if(SetupDiGetInterfaceDeviceDetail(info, &iface, NULL, 0, &reqd_size, NULL) == FALSE) {
        if(GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
          continue;
	      }
      }
      details = calloc(reqd_size, sizeof(char));
      if(details == NULL) {
        fprintf(stderr, "%s:%d calloc failed\n", __FILE__, __LINE__);
        continue;
      }
      details->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
      if(SetupDiGetDeviceInterfaceDetail(info, &iface, details, reqd_size, NULL, NULL) == FALSE) {
        ASYNC_PRINT_ERROR("SetupDiGetDeviceInterfaceDetail")
        free(details);
        details = NULL;
        continue;
      }
      int device = open_path(details->DevicePath, 0);
      free(details);
      details = NULL;
      if(device >= 0) {
        if(devices[device].hidInfo.vendor_id == vendor && devices[device].hidInfo.product_id == product)
        {
          ret = device;
          break;
        }
        async_close(device);
      }
    }
  }

  return ret;
}
示例#7
0
int syscall_unlink(const char *pathname)
{
	int drive;
	int curdir_handle;
	char name_comp[13], conv_name[11], dir_path[501];
	struct dir_entry dent;
	int err;

	if (strlen(pathname) > 500) return ELONGPATH;

	parse_path(pathname, &drive, dir_path, name_comp);

	if (dir_path[0] != 0)
	{
		curdir_handle = open_path(drive, dir_path);

		if (curdir_handle < 0)
			return curdir_handle;	// Error
	}
	else
	{
		curdir_handle = get_curdir_handle(drive);
		increment_ref_count(curdir_handle);
	}

	// Last file name component.
	if (convert_name(name_comp, conv_name) < 0)
	{
		err =  EINVALIDNAME; // Error
	}
	else if (find_entry(curdir_handle, conv_name, &dent) == 1)
	{	// Check whether it is a deletable file
		if ((dent.attrib & (FTYPE_READONLY | FTYPE_DIR | FTYPE_VOLUME)) == 0)
		{
			delete_dir_entry(curdir_handle, conv_name);
			free_cluster_chain(dent.start_cluster);
			err = 0;
		}
		else
		{
			err = EACCESS; // Error
		}
	}
	else 
	{
		err = EFILE_NOT_FOUND;
	}

	close_dir(curdir_handle);
	return err;
}
示例#8
0
文件: hidasync.c 项目: NoPublic/GIMX
s_hid_dev * hidasync_enumerate(unsigned short vendor, unsigned short product) {

  s_hid_dev * hid_devs = NULL;
  unsigned int nb_hid_devs = 0;

  GUID guid;
	HidD_GetHidGuid(&guid);

	HDEVINFO info = SetupDiGetClassDevs(&guid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);

	if(info != INVALID_HANDLE_VALUE) {
		int index;
		for(index = 0; ; ++index) {
			SP_DEVICE_INTERFACE_DATA iface;
			iface.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
			if(SetupDiEnumDeviceInterfaces(info, NULL, &guid, index, &iface) == FALSE) {
				break; //no more device
			}
			DWORD reqd_size;
			if(SetupDiGetInterfaceDeviceDetail(info, &iface, NULL, 0, &reqd_size, NULL) == FALSE) {
				if(GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
					continue;
				}
			}
			SP_DEVICE_INTERFACE_DETAIL_DATA * details = calloc(reqd_size, sizeof(char));
			if(details == NULL) {
				fprintf(stderr, "%s:%d calloc failed\n", __FILE__, __LINE__);
				continue;
			}
			details->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
			if(SetupDiGetDeviceInterfaceDetail(info, &iface, details, reqd_size, NULL, NULL) == FALSE) {
				ASYNC_PRINT_ERROR("SetupDiGetDeviceInterfaceDetail")
				free(details);
				continue;
			}
			int device = open_path(details->DevicePath, 0);
			free(details);

			if(device >= 0) {
				if(vendor) {
					if (devices[device].hidInfo.vendor_id != vendor) {
						async_close(device);
						continue;
					}
					if(product) {
						if(devices[device].hidInfo.product_id != product) {
							async_close(device);
							continue;
						}
					}
				}

				char * path = strdup(devices[device].path);

				if(path == NULL) {
					PRINT_ERROR_OTHER("strdup failed")
	        async_close(device);
					continue;
				}

				void * ptr = realloc(hid_devs, (nb_hid_devs + 1) * sizeof(*hid_devs));

				if(ptr == NULL) {
					PRINT_ERROR_ALLOC_FAILED("realloc")
					free(path);
					async_close(device);
					continue;
				}

				hid_devs = ptr;

				if(nb_hid_devs > 0) {
					hid_devs[nb_hid_devs - 1].next = 1;
				}

				hid_devs[nb_hid_devs].path = path;
				hid_devs[nb_hid_devs].vendor_id = devices[device].hidInfo.vendor_id;
				hid_devs[nb_hid_devs].product_id = devices[device].hidInfo.product_id;
				hid_devs[nb_hid_devs].next = 0;

				++nb_hid_devs;

				async_close(device);
			}
		}
	}

  return hid_devs;
}
示例#9
0
文件: hidasync.c 项目: NoPublic/GIMX
/*
 * \brief Open a hid device.
 *
 * \param path  the path of the hid device to open.
 *
 * \return the identifier of the opened device (to be used in further operations), \
 * or -1 in case of failure (e.g. bad path, device already opened).
 */
int hidasync_open_path(const char * path) {
    
  return open_path(path, 1);
}
示例#10
0
void input_helper::open(service_ptr_t<file> p_filehint,const playable_location & p_location,unsigned p_flags,abort_callback & p_abort,bool p_from_redirect,bool p_skip_hints) {
	open_path(p_filehint, p_location.get_path(), p_abort, p_from_redirect, p_skip_hints);

	open_decoding(p_location.get_subsong(), p_flags, p_abort);
}
示例#11
0
void spectrogram::load_files(
	const std::string& path, 
	const commands& cmd,
	i_fft_f* fft_instance,
	int64_t start_time,
	int64_t end_time) 
{
	data_.clear();
	time_.clear();
	bunch_pattern_.clear();
	try {
		fs::path open_path(path.c_str());
		std::vector<fs::path> list_file;
		if (fs::exists(open_path) && fs::is_directory(open_path)) {
			std::copy(
				fs::directory_iterator(open_path), 
				fs::directory_iterator(), 
				std::back_inserter(list_file));
			sort(list_file.begin(), list_file.end());
		} else {
			throw std::runtime_error(path + " is not a directory!");
		}
		std::vector<fs::path>::iterator ite;
		bunch_buffer_f acc_bb;
		std::vector<float> temp;
		unsigned int acc_count = 1;
		unsigned int file_count = 0;
		for (ite = list_file.begin(); ite != list_file.end(); ++ite) {
			std::string full_path = (*ite).string();
			long long time_stamp = time_stamp_from_file(*ite);
			// check boundaries
			if (time_stamp < start_time || time_stamp > end_time)
				continue;
			boost::posix_time::ptime file_time = ptime_from_file(*ite);
			std::cout 
				<< "\rloading (data)  : " 
				<< ++file_count << "/"
				<< list_file.size() << " "
				<< file_time;
			std::cout.flush();
			bunch_buffer_f bb = buffer_from_file(*ite, fft_instance);
			if (bb.empty()) {
				std::cout 
					<< std::endl
					<< "empty (data)    : " << full_path << " Not saved!" 
					<< std::endl;
				continue;
			}
			if (!pitch_) {
				pitch_ = bb.buffer_size() / 2;
			}
			// save the bunch pattern
			if (bb.get_bunch_pattern() != bunch_pattern_) { 
				bunch_pattern_ = bb.get_bunch_pattern();
				std::cout << std::endl;
				std::cout << "bunch pattern   : ";
				for (size_t i = 0; i < bunch_pattern_.size(); ++i)
					std::cout << bunch_pattern_[i] << " ";
				std::cout << std::endl;
			}
			time_.push_back(time_stamp);
			acc_bb += bb;
			if (!(acc_count % nb_acc_)) {
				std::vector<float> temp;
				// here come the computing
				cmd(acc_bb, temp);
				pitch_ = acc_bb.buffer_size();
				// apply bunch mask!
				data_.insert(data_.end(), temp.begin(), temp.end());
				acc_bb.clear();
			}
			acc_count++;
		}
//		if (!data_.empty())
//			normalize(data_);
		std::cout << std::endl;
	} catch (const fs::filesystem_error& er) {
		std::cerr << "exception (fs)  : " << er.what() << std::endl;
	}
}
示例#12
0
int syscall_stat(const char *file_name, struct stat *buf)
{
	int drive;
	int curdir_handle;
	char name_comp[13], conv_name[11], dir_path[501];
	struct dir_entry dent;
	int err, count;
	struct date_time dt;
	int clno;

	if (strlen(file_name) > 500) return ELONGPATH;

	parse_path(file_name, &drive, dir_path, name_comp);

	if (dir_path[0] != 0)
	{
		curdir_handle = open_path(drive, dir_path);

		if (curdir_handle < 0)
		{
			return curdir_handle;	// Error
		}
	}
	else
	{
		curdir_handle = get_curdir_handle(drive);
		increment_ref_count(curdir_handle);
	}

	// Last file name component.
	if (convert_name(name_comp, conv_name) < 0)
	{
		err =  EINVALIDNAME; // Error
	}
	else if (find_entry(curdir_handle, conv_name, &dent) == 1)
	{
		// Fill up the stat buf
		buf->st_dev = drive;
		buf->st_ino = 0;
		buf->st_mode = dent.attrib;
		buf->st_nlink = 1;
		buf->st_uid = buf->st_gid = 0;
		buf->st_rdev = 0;
		buf->st_size = dent.fsize;
		buf->st_blksize = 512;
		// Find time in seconds
		dt.seconds = (dent.time & 0x1f) * 2;
		dt.minutes = ((dent.time & 0x7e0) >> 5);
		dt.hours = (((unsigned short int)(dent.time & 0xf800)) >> 11);
		dt.date = dent.date & 0x1f;
		dt.month = ((dent.date & 0x1e0) >> 5);
		dt.year = (((unsigned short int)(dent.date & 0xfe00)) >> 9);

		buf->st_atime = buf->st_mtime = buf->st_ctime = date_to_secs(dt);

		// Find number of blocks
		count = 0;
		clno = dent.start_cluster;
		while (clno < 0xff8)
		{
			count++;
			clno = next_cluster_12(clno);
		}
		buf->st_blocks = count;
		err = 0;
	}
示例#13
0
int syscall_rename(const char *a_oldpath, const char *a_newpath)
{
	int ohandle, nhandle;
	int drive1, drive2;
	char dir_path1[512], dir_path2[512];
	char name_comp1[13], name_comp2[13], conv_name1[11], conv_name2[11];
	char oldpath[512], newpath[512];
	struct dir_entry dent1, dent2;
	int exist1, exist2;
	struct DIR_FILE *dirf;
	int len1, len2;
	int i,t;

	len1 = strlen(a_oldpath);
	len2 = strlen(a_newpath);

	if (len1 > 512 || len2 > 512) return ELONGPATH;

	strcpy(oldpath,a_oldpath);
	strcpy(newpath,a_newpath);

	if (oldpath[len1-1] == '/' || oldpath[len1-1] == '\\') oldpath[len1-1] = '\0';
	if (newpath[len2-1] == '/' || newpath[len2-1] == '\\') newpath[len2-1] = '\0';
	parse_path(oldpath, &drive1, dir_path1, name_comp1);
	parse_path(newpath, &drive2, dir_path2, name_comp2);

	if (drive1 != drive2) return EDEVICE_DIFFERENT;

	nhandle = open_path(drive2, dir_path2);
	if (nhandle < 0) return nhandle;

	if (name_comp2[0] !='\0')
	{
		if (convert_name(name_comp2, conv_name2) < 0)
		{
			close_dir(nhandle);
			return EINVALIDNAME; // Error
		}

		exist2 = find_entry(nhandle, conv_name2, &dent2);
	}
	
	ohandle = open_path(drive1, dir_path1);
	if (ohandle < 0)
	{
		close_dir(nhandle);
		return ohandle;
	}
	if (name_comp1[0] != '\0')
	{
		if (convert_name(name_comp1, conv_name1) < 0)
		{
			close_dir(nhandle);
			close_dir(ohandle);
			return EINVALIDNAME; // Error
		}

		exist1 = find_entry(ohandle, conv_name1, &dent1);
	}

	// Check whether new path exists and is removable
	if ((exist2 == 1) && ((dent2.attrib & FTYPE_READONLY) || ((dent2.attrib & FTYPE_DIR) && (empty_dir(nhandle, &dent2) != 1))))
	{
		close_dir(nhandle);
		close_dir(ohandle);
		return ETARGET_EXISTS;
	}

	// Check if source exists and is movable
	if (exist1 != 1)
	{
		close_dir(nhandle);
		close_dir(ohandle);
		return EPATH_NOT_EXISTS;
	}
	if ((dent1.attrib & FTYPE_READONLY) != 0)
	{
		close_dir(nhandle);
		close_dir(ohandle);
		return EREADONLY;
	}
	// Check whether oldpath is not a subpath of newpath
	if ((dent1.attrib & FTYPE_DIR) && (ohandle != nhandle))
	{	
		t = nhandle;
		dirf = &dir_file_list[t];

		while (dirf->parent_index >= 0 && dirf->parent_index != ohandle)
		{
			t = dirf->parent_index;
			dirf = &dir_file_list[t];
		}
		
		if (dirf->parent_index == ohandle)
		{
			close_dir(nhandle);
			close_dir(ohandle);
			return EOLDPATH_PARENT_OF_NEWPATH;
		}
	}

	// Check if newpath already exists whether it is compatible or not
	if ((exist2 == 1) && (((dent1.attrib & FTYPE_DIR) != 0 && (dent2.attrib & FTYPE_DIR) == 0) || ((dent1.attrib & FTYPE_DIR) == 0 && (dent2.attrib & FTYPE_DIR) != 0))) 
	{
		close_dir(nhandle);
		close_dir(ohandle);
		return ESRC_DEST_NOT_SAME_TYPE;
	}

	// Remove destination entry if exists
	if (exist2 == 1)
	{
		if (dent2.attrib & FTYPE_DIR)
			syscall_rmdir(newpath);
		else	syscall_unlink(newpath);
	}

	// Add the source dir entry after changing the name
	// to destination directory
	bcopy( (char *)&dent1, (char *)&dent2, sizeof(struct dir_entry));
	for (i=0; i<11; i++)	// Both name and extension
		dent2.name[i] = conv_name2[i];

	t = add_dir_entry(nhandle, &dent2);
	if (t == 1)
	{
		delete_dir_entry(ohandle, dent1.name);
	}

	// Close the handles of parent directories
	close_dir(ohandle);
	close_dir(nhandle);
	
	if (t == 1) return 0;
	else	return t;

}