コード例 #1
0
/* This function is workaround replacement of ensure_path_mounted we
 * cannot use due to link issues.  Ideally, this we shoud get rid of
 * this new function as soon as we find a better solution.  */
static int ensure_esp_mounted()
{
	int ret;
	char *path = NULL;

	ret = get_device_path(&path, ESP_LABEL);
	if (ret) {
		error("%s: Unable to get the ESP block device path\n", __func__);
		goto out;
	}

	ret = mkdir(ESP_MOUNT_POINT, S_IRWXU | S_IRWXG | S_IRWXO);
	if (ret == -1 && errno != EEXIST) {
		error("%s: mkdir %s failed\n", __func__, ESP_MOUNT_POINT);
		goto out;
	}

	ret = mount(path, ESP_MOUNT_POINT, ESP_FS_TYPE, MS_NOATIME | MS_NODEV | MS_NODIRATIME, "");
	/* EBUSY means that the filesystem is already mounted. */
	if (ret == -1 && errno != EBUSY) {
		error("%s: mount %s failed\n", __func__, ESP_MOUNT_POINT);
		goto out;
	} else if (errno == EBUSY)
		ret = 0;

out:
	free(path);
	return ret;
}
コード例 #2
0
bool is_fdk(void)
{
	char *path = NULL;

	if (!get_device_path(&path, CAPSULE_PARTITION_LABEL))
		free(path);

	return !!path;
}
コード例 #3
0
bool is_edk2(void)
{
	char *path = NULL;

	if (!get_device_path(&path, ESP_LABEL))
		free(path);

	return !!path;
}
コード例 #4
0
bool is_gpt(void)
{
	char *path = NULL;

	if (!get_device_path(&path, "fastboot"))
		free(path);

	return !!path;
}
コード例 #5
0
int flash_image_gpt(void *data, unsigned sz, const char *name)
{
	char *block_dev;
	int ret;

	if (!strcmp(name, TEST_OS_NAME))
		name = ANDROID_OS_NAME;

	if (get_device_path(&block_dev, name))
		return -1;

	ret = file_write(block_dev, data, sz);
	free(block_dev);
	return ret;
}
コード例 #6
0
ファイル: sys_darwin.cpp プロジェクト: Klozz/iwidarwin
static void media_removed(int type, io_iterator_t iterator)
{
	io_object_t obj;
	while ((obj = IOIteratorNext(iterator)) != NULL) {
		char path[MAXPATHLEN];
		kern_return_t kernResult = get_device_path(obj, path, sizeof(path));
		if (kernResult == KERN_SUCCESS) {
			D(bug("Media Removed: %s\n", path));
			SysMediaRemoved(path, type);
		}
		kernResult = IOObjectRelease(obj);
		if (kernResult != KERN_SUCCESS) {
			fprintf(stderr, "IOObjectRelease() returned %d\n", kernResult);
		}
	}
}
コード例 #7
0
int open_bootimage(const char *name)
{
	char *block_dev;
	int fd = -1;

	if (get_device_path(&block_dev, name))
		goto out;

	fd = open(block_dev, O_RDONLY);
	if (fd < 0)
		error("Failed to open %s: %s\n", block_dev, strerror(errno));

	free(block_dev);
out:
	return fd;
}
コード例 #8
0
ファイル: srv_ntsvcs_nt.c プロジェクト: Alexander--/samba
WERROR _PNP_GetDeviceList(struct pipes_struct *p,
			  struct PNP_GetDeviceList *r)
{
	char *devicepath;
	uint32_t size = 0;
	const char **multi_sz = NULL;
	DATA_BLOB blob;

	if ((r->in.flags & CM_GETIDLIST_FILTER_SERVICE) &&
	    (!r->in.filter)) {
		return WERR_CM_INVALID_POINTER;
	}

	if (!(devicepath = get_device_path(p->mem_ctx, r->in.filter))) {
		return WERR_NOT_ENOUGH_MEMORY;
	}

	size = strlen(devicepath) + 2;

	if (*r->in.length < size) {
		return WERR_CM_BUFFER_SMALL;
	}

	multi_sz = talloc_zero_array(p->mem_ctx, const char *, 2);
	if (!multi_sz) {
		return WERR_NOT_ENOUGH_MEMORY;
	}

	multi_sz[0] = devicepath;

	if (!push_reg_multi_sz(multi_sz, &blob, multi_sz)) {
		return WERR_NOT_ENOUGH_MEMORY;
	}

	if (*r->in.length < blob.length/2) {
		return WERR_CM_BUFFER_SMALL;
	}

	memcpy(r->out.buffer, blob.data, blob.length);

	return WERR_OK;
}
コード例 #9
0
ファイル: srv_ntsvcs_nt.c プロジェクト: Alexander--/samba
WERROR _PNP_GetDeviceListSize(struct pipes_struct *p,
			      struct PNP_GetDeviceListSize *r)
{
	char *devicepath;

	if ((r->in.flags & CM_GETIDLIST_FILTER_SERVICE) &&
	    (!r->in.devicename)) {
		return WERR_CM_INVALID_POINTER;
	}

	if (!(devicepath = get_device_path(p->mem_ctx, r->in.devicename))) {
		return WERR_NOT_ENOUGH_MEMORY;
	}

	*r->out.size = strlen(devicepath) + 2;

	TALLOC_FREE(devicepath);

	return WERR_OK;
}
コード例 #10
0
ファイル: volume_list.cpp プロジェクト: AKKF/altWinDirStat
list<VolumeItem> enum_volumes( ) {
	list<VolumeItem> vol_list;
	LogicalDrivesEnum drive_enum;
	map<wstring, wstring> vol_guid_to_drive_map;
	while ( drive_enum.next( ) ) {
		wstring drive = drive_enum.get_drive( );
		wstring vol_guid_path;
		if ( get_volume_guid_path( drive, vol_guid_path ) ) {
			vol_guid_to_drive_map[ vol_guid_path ] = drive;
			}
		}

	VolumeEnum vol_enum;
	while ( vol_enum.next( ) ) {
		VolumeItem vol_item;
		vol_item.guid_path = vol_enum.get_volume_path( );
		auto vol_iter = vol_guid_to_drive_map.find( vol_item.guid_path );
		if ( vol_iter != vol_guid_to_drive_map.end( ) ) {
			vol_item.drive_path = vol_iter->second;
			}

		get_device_path( vol_item.guid_path, vol_item.dev_path );

		vol_item.mount_points = get_volume_mount_points( vol_item.guid_path );
		auto mp_iter = vol_item.mount_points.begin( );
		while ( mp_iter != vol_item.mount_points.end( ) ) {
			if ( is_root_path( std::string( mp_iter->data( ), mp_iter->size( ) ) ) ) {
				mp_iter = vol_item.mount_points.erase( mp_iter );
				}
			else {
				++mp_iter;
				}
			}

		vol_list.push_back( vol_item );
		}

	return vol_list;
	}
コード例 #11
0
int flash_capsule_fdk(void *data, unsigned sz)
{
	int ret_status = -1;
	char capsule_trigger = '1';
	bool capsule_update;
	struct capsule *c;

	char iafw_stage1_version_str[PROPERTY_VALUE_MAX];
	u32 iafw_version_msb = 0;
	u32 iafw_version = 0;

	char sec_version_str[PROPERTY_VALUE_MAX];
	sec_version_t sec_version;

	char pdr_version_str[PROPERTY_VALUE_MAX];
	u32 pdr_version_msb = 0;
	u32 pdr_version = 0;

	char *dev_path = NULL;

	/* Get current FW version */
	property_get("sys.ia32.version", iafw_stage1_version_str, "00.00");
	property_get("sys.chaabi.version", sec_version_str, "00.00");
	property_get("sys.pdr.version", pdr_version_str, "00.00");

	sscanf(iafw_stage1_version_str, "%x.%x", &iafw_version_msb, &iafw_version);
	iafw_version |= iafw_version_msb << 16;
	sscanf(sec_version_str, "%*d.%d.%d.%d", &sec_version.val_2, &sec_version.val_1, &sec_version.val_0);
	sscanf(pdr_version_str, "%x.%x", &pdr_version_msb, &pdr_version);
	pdr_version |= pdr_version_msb << 16;

	printf("current iafw version: %s (0x%02x)\n", iafw_stage1_version_str, iafw_version);

	printf("current sec version: %s (%d.%d.%d)\n", sec_version_str,
	       sec_version.val_2, sec_version.val_1, sec_version.val_0);

	printf("current pdr version: %s (0x%2x)\n", pdr_version_str, pdr_version);

	if (!data || sz <= sizeof(struct capsule_header)) {
		error("Capsule file is not valid: %s\n", strerror(errno));
		goto exit;
	}

	c = (struct capsule *)data;
	print_capsule_header(c);

	/* Check capsule vs current FW version */
	capsule_update = check_capsule(c, iafw_version, sec_version, pdr_version);

	/* Flash capsule file only if versions missmatch */
	if (!capsule_update) {
		printf("Capsule contains same FW versions as current ones , do not request update\n");
		ret_status = 0;
		goto exit;
	}

	if (get_device_path(&dev_path, CAPSULE_PARTITION_LABEL)) {
		error("Unable to get the capsule partition device path\n");
		goto exit;
	}

	if ((ret_status = file_write(dev_path, data, sz))) {
		error("Capsule flashing failed: %s\n", strerror(errno));
		goto exit;
	}

	if ((ret_status = file_write(CAPSULE_UPDATE_FLAG_PATH, &capsule_trigger, sizeof(capsule_trigger)))) {
		error("Can't set fw_update bit: %s\n", strerror(errno));
		goto exit;
	}

exit:
	free(dev_path);
	return ret_status;
}
コード例 #12
0
ファイル: evdev_trace.c プロジェクト: kvahlman/mce
/** Main entry point
 */
int
main(int argc, char **argv)
{
  int result = EXIT_FAILURE;

  int f_trace    = 0;
  int f_identify = 0;

  glob_t gb;

  memset(&gb, 0, sizeof gb);

  progname = basename(*argv);

  for( ;; )
  {
    int opt = getopt_long(argc, argv, optS, optL, 0);

    if( opt < 0 )
    {
      break;
    }

    switch( opt )
    {
    case 'h':
      usage();
      exit(EXIT_SUCCESS);

    case 't':
      f_trace = 1;
      break;

    case 'i':
      f_identify = 1;
      break;

    case 'e':
      emit_time_of_day = true;
      break;

    case 'E':
      emit_time_of_day = true;
      emit_event_time  = false;
      break;

    case '?':
    case ':':
      goto cleanup;

    default:
      fprintf(stderr, "getopt() -> %d\n", opt);
      goto cleanup;
    }
  }

  if( !f_identify && !f_trace )
  {
    f_identify = 1;
  }

  if( optind < argc )
  {
    argc = 0;
    for( int i = optind; argv[i]; ++i )
    {
      char *path = get_device_path(argv[i]);
      if( path ) argv[argc++] = path;
    }
    mainloop(argv, argc, f_identify, f_trace);
    while( argc > 0 )
    {
      free(argv[--argc]);
    }
  }
  else
  {
    static const char pattern[] = "/dev/input/event*";

    if( glob(pattern, 0, 0, &gb) != 0 )
    {
      printf("%s: no matching files found\n", pattern);
      goto cleanup;
    }

    mainloop(gb.gl_pathv, gb.gl_pathc, f_identify, f_trace);
  }

  result = EXIT_SUCCESS;

cleanup:

  globfree(&gb);

  return result;
}
コード例 #13
0
ファイル: nemo-action.c プロジェクト: IanLee1521/nemo
static gchar *
get_insertion_string (NemoAction *action, TokenType token_type, GList *selection, NemoFile *parent)
{
    GList *l;

    GString *str = g_string_new("");
    gboolean first = TRUE;

    switch (token_type) {
        case TOKEN_PATH_LIST:
            if (g_list_length (selection) > 0) {
                for (l = selection; l != NULL; l = l->next) {
                    if (!first)
                        str = insert_separator (action, str);
                    str = insert_quote (action, str);
                    gchar *path = get_path (action, NEMO_FILE (l->data));
                    if (path)
                        str = score_append (action, str, path);
                    g_free (path);
                    str = insert_quote (action, str);
                    first = FALSE;
                }
            } else {
                goto default_parent_path;
            }
            break;
        case TOKEN_URI_LIST:
            if (g_list_length (selection) > 0) {
                for (l = selection; l != NULL; l = l->next) {
                    if (!first)
                        str = insert_separator (action, str);
                    str = insert_quote (action, str);
                    gchar *uri = nemo_file_get_uri (NEMO_FILE (l->data));
                    str = score_append (action, str, uri);
                    g_free (uri);
                    str = insert_quote (action, str);
                    first = FALSE;
                }
            } else {
                goto default_parent_path;
            }
            break;
        case TOKEN_PARENT_PATH:
            ;
default_parent_path:
            ;
            gchar *path = get_path (action, parent);
            if (path == NULL) {
                gchar *name = nemo_file_get_display_name (parent);
                if (g_strcmp0 (name, "x-nemo-desktop") == 0)
                    path = nemo_get_desktop_directory ();
                else
                    path = g_strdup ("");
                g_free (name);
            }
            str = insert_quote (action, str);
            str = score_append (action, str, path);
            str = insert_quote (action, str);
            g_free (path);
            break;
        case TOKEN_FILE_DISPLAY_NAME:
            if (g_list_length (selection) > 0) {
                gchar *file_display_name = nemo_file_get_display_name (NEMO_FILE (selection->data));
                str = score_append (action, str, file_display_name);
                g_free (file_display_name);
            } else {
                goto default_parent_display_name;
            }
            break;
        case TOKEN_PARENT_DISPLAY_NAME:
            ;
default_parent_display_name:
            ;
            gchar *parent_display_name;
            gchar *real_display_name = nemo_file_get_display_name (parent);
            if (g_strcmp0 (real_display_name, "x-nemo-desktop") == 0)
                parent_display_name = g_strdup_printf (_("Desktop"));
            else
                parent_display_name = nemo_file_get_display_name (parent);
            g_free (real_display_name);
            str = insert_quote (action, str);
            str = score_append (action, str, parent_display_name);
            str = insert_quote (action, str);
            g_free (parent_display_name);
            break;
        case TOKEN_DEVICE:
            if (g_list_length (selection) > 0) {
                for (l = selection; l != NULL; l = l->next) {
                    if (!first)
                        str = insert_separator (action, str);
                    str = insert_quote (action, str);
                    gchar *dev = get_device_path (action, NEMO_FILE (l->data));
                    if (dev)
                        str = score_append (action, str, dev);
                    g_free (dev);
                    str = insert_quote (action, str);
                    first = FALSE;
                }
            } else {
                goto default_parent_path;
            }
            break;
        default:
            break; 
    }

    gchar *ret = str->str;

    g_string_free (str, FALSE);

    return ret;
}
コード例 #14
0
ファイル: sys_darwin.cpp プロジェクト: Klozz/iwidarwin
void DarwinAddFloppyPrefs(void)
{
	mach_port_t				masterPort;		// The way to talk to the kernel
	io_iterator_t			allFloppies;	// List of possible floppys
	CFMutableDictionaryRef	classesToMatch;
	io_object_t				nextFloppy;


	if ( IOMasterPort(MACH_PORT_NULL, &masterPort) != KERN_SUCCESS )
		bug("IOMasterPort failed. Won't be able to do anything with floppy drives\n");


	// This selects all partitions of all disks
	classesToMatch = IOServiceMatching(kIOMediaClass); 
	if ( classesToMatch )
	{
		// Skip drivers and partitions
		CFDictionarySetValue(classesToMatch,
							 CFSTR(kIOMediaWholeKey), kCFBooleanTrue); 
	
		// Skip fixed drives (hard disks?)
		CFDictionarySetValue(classesToMatch,
							 CFSTR(kIOMediaEjectableKey), kCFBooleanTrue); 
	}

	if ( IOServiceGetMatchingServices(masterPort,
									  classesToMatch, &allFloppies) != KERN_SUCCESS )
	{
		D(bug("IOServiceGetMatchingServices failed. No removable drives found?\n"));
		return;
	}

	// Iterate through each floppy
	while ( nextFloppy = IOIteratorNext(allFloppies))
	{
		char		bsdPath[MAXPATHLEN];
		long		size;
		CFTypeRef	sizeAsCFNumber =
						IORegistryEntryCreateCFProperty(nextFloppy,
														CFSTR(kIOMediaSizeKey),
														kCFAllocatorDefault, 0);

		if ( CFNumberGetValue((CFNumberRef)sizeAsCFNumber,
								kCFNumberSInt32Type, &size) )
		{
			D(bug("Got size of %ld\n", size));
			if ( size < 800 * 1024 || size > 1440 * 1024 )
			{
				D(puts("Device does not appear to be 800k or 1440k"));
				continue;
			}
		}
		else {
			D(puts("Couldn't get kIOMediaSizeKey of device"));
			continue; // if kIOMediaSizeKey is unavailable, we shouldn't use it anyway
		}

		if (get_device_path(nextFloppy, bsdPath, sizeof(bsdPath)) == KERN_SUCCESS) {
			PrefsAddString("floppy", bsdPath);
		} else {
			D(bug("Could not get BSD device path for floppy\n"));
		}
	}

	IOObjectRelease(nextFloppy);
	IOObjectRelease(allFloppies);
}