Exemplo n.º 1
0
int __cdecl
main()
{
    HANDLE find_handle;
    char vol_name[MAX_PATH+1];

    flush_registry();

    /* Now loop over every volume and sync them as well. */
    find_handle = FindFirstVolume(vol_name, ARRAYSIZE(vol_name));
    if (find_handle == INVALID_HANDLE_VALUE)
        xs_win_err(1, &xs_render_error_msgbox,
                   "failed to start enumerating disk volumes");
    while (1) {
        sync_this_volume(vol_name);

        if (!FindNextVolume(find_handle, vol_name, ARRAYSIZE(vol_name))) {
            if (GetLastError() == ERROR_NO_MORE_FILES)
                break;
            xs_win_err(1, &xs_render_error_msgbox,
                       "failed to enumerate disk volumes");
        }
    }
    FindVolumeClose(find_handle);

    return 0;
}
Exemplo n.º 2
0
int EnumerateVolumes()
{
	HRESULT error;
    WCHAR volname[MAX_PATH+1];
	auto hFind = FindFirstVolume(volname, ARRAYSIZE(volname));
	if (hFind==INVALID_HANDLE_VALUE)
		return Usage(GetLastError(), L"FindFirstVolume() failed");
	while(true)
	{
		auto len = wcslen(volname);
		volname[len] = 0;
		auto v = new Volume();
		v->Init(volname, len);
		g_volumes.push_back(shared_ptr<Volume>(v));
		auto hasNext = FindNextVolume(hFind, volname, ARRAYSIZE(volname));
		if (hasNext)
			continue;
		error = GetLastError();
		if (error==ERROR_NO_MORE_FILES)
			error = 0;
		break;
	}
	FindVolumeClose(hFind);
	if (error!=0)
		return Usage(error, L"ProcessLv failed");
	return 0;
}
Exemplo n.º 3
0
int dc_first_volume(vol_inf *info)
{
	wchar_t name[MAX_PATH];
	
	info->find = FindFirstVolume(name, sizeof_w(name));

	if (info->find != INVALID_HANDLE_VALUE) 
	{
		if (dc_get_vol_info(name, info) != ST_OK) {
			return dc_next_volume(info);
		} else {
			return ST_OK;
		}
	} 

	return ST_ERROR;
}
Exemplo n.º 4
0
UINT fileManage::getVolume(WCHAR* volumePathName, UINT num) const {
	HANDLE findHandle = NULL;
	DWORD charCount = MAX_PATH+1;
	WCHAR volumeName[MAX_PATH+1];
	WCHAR deviceName[MAX_PATH+1];
	DWORD index = 0;
	UINT result = 0;
	UINT count = 0;

	findHandle = FindFirstVolume(volumeName, ARRAYSIZE(volumeName));
	if(INVALID_HANDLE_VALUE==findHandle) return 0;
	while(TRUE) {
		index = wcslen(volumeName)-1;
		volumeName[index] = L'\0';
		result = QueryDosDevice(&volumeName[4], deviceName, ARRAYSIZE(deviceName));
		volumeName[index] = L'\\';

		if(ERROR_INSUFFICIENT_BUFFER==result || 0==result) {
			result = 0;
			break;
		}
		result = retrieveDevName(deviceName);
		if(!result) {
			size_t temp = wcslen(volumePathName);
			if(volumePathName[temp]==L'\0') result=1;
			break;
		}
		result = GetVolumePathNamesForVolumeName(volumeName, volumePathName, charCount, &charCount);
		if(result) {
			if(count++==num) {
				size_t temp = wcslen(volumePathName);
				if(volumePathName[temp]==L'\0') result=1;
				break;
			}
			result = FindNextVolume(findHandle, volumeName, ARRAYSIZE(volumeName));
		}
	}

	FindVolumeClose(findHandle);
	findHandle = INVALID_HANDLE_VALUE;
	return result;
}
Exemplo n.º 5
0
// This does the same as GetVolumePathNamesForVolumeNameW() on Windows XP and
// later. It is built into 32 bit versions of this library to make sure that
// the DLL can load correctly on Windows 2000 as well.
BOOL
WINAPI
ImScsiLegacyGetVolumePathNamesForVolumeName(
__in   LPCWSTR lpszVolumeName,
__out  LPWSTR  lpszVolumePathNames,
__in   DWORD   cchBufferLength,
__out  PDWORD  lpcchReturnLength)
{
    *lpcchReturnLength = 0;

    DWORD dw;
    dw;

    LPWSTR cur_ptr = lpszVolumePathNames;
    LPWSTR end_ptr = lpszVolumePathNames + cchBufferLength;

    WCHAR vol_target[MAX_PATH];

    wcsncpy(vol_target, lpszVolumeName + 4, 44);
    vol_target[44] = 0;

    if (!QueryDosDevice(vol_target, vol_target, _countof(vol_target)))
    {
        return FALSE;
    }

    WHeapMem<WCHAR> dosdevs(UNICODE_STRING_MAX_BYTES,
        HEAP_GENERATE_EXCEPTIONS);

    if (!QueryDosDevice(NULL, dosdevs, (DWORD)dosdevs.Count()))
    {
        return FALSE;
    }

    DWORD good = cchBufferLength >= 2;
    
    *lpcchReturnLength = 2;

    WCHAR dev_target[MAX_PATH];

    SIZE_T length;
    for (LPCWSTR ptr = dosdevs;
        (length = wcslen(ptr)) != 0;
        ptr += length + 1)
    {
        if (good)
        {
            *cur_ptr = 0;
        }

        if ((length != 2) ||
            (ptr[1] != L':') ||
            (!QueryDosDevice(ptr, dev_target, _countof(dev_target))) ||
            (_wcsicmp(dev_target, vol_target) != 0))
        {
            continue;
        }

        *lpcchReturnLength += 4;

        if ((cur_ptr + 4) >= end_ptr)
        {
            good = FALSE;
        }

        if (good)
        {
            swprintf(cur_ptr, L"%ws\\", ptr);
            cur_ptr += 4;
        }
    }

    WCHAR vol_name[50];

    HANDLE volume = FindFirstVolume(vol_name, _countof(vol_name));

    if (volume == INVALID_HANDLE_VALUE)
    {
        return FALSE;
    }

    DWORD error_mode = SetErrorMode(SEM_FAILCRITICALERRORS |
        SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);

    do
    {
        HANDLE vol_mnt = FindFirstVolumeMountPoint(vol_name, dosdevs,
            (DWORD)dosdevs.Count());

        if (vol_mnt == INVALID_HANDLE_VALUE)
        {
            continue;
        }

        do
        {
            WMem<WCHAR> mnt_path;
            
            mnt_path = ImDiskAllocPrintF(L"%1!ws!%2!ws!", vol_name, dosdevs);

            if (!mnt_path)
            {
                continue;
            }

            WCHAR mnt_vol_name[50];
            if (!GetVolumeNameForVolumeMountPoint(mnt_path, mnt_vol_name,
                _countof(mnt_vol_name)))
            {
                continue;
            }

            if (_wcsicmp(mnt_vol_name, lpszVolumeName) == 0)
            {
                if (ImScsiLegacyGetVolumePathNamesForVolumeName(vol_name,
                    vol_target, _countof(vol_target), &dw))
                {
                    mnt_path = ImDiskAllocPrintF(L"%1!ws!%2!ws!", vol_target,
                        dosdevs);

                }

                size_t len = wcslen(mnt_path) + 1;

                *lpcchReturnLength += (DWORD)len;

                if ((cur_ptr + len) >= end_ptr)
                {
                    good = FALSE;
                }

                if (good)
                {
                    wcscpy(cur_ptr, mnt_path);
                    cur_ptr += len;
                }
            }

        } while (FindNextVolumeMountPoint(vol_mnt, dosdevs,
            (DWORD)dosdevs.Count()));
        
        FindVolumeMountPointClose(vol_mnt);

    } while (FindNextVolume(volume, vol_name, _countof(vol_name)));

    FindVolumeClose(volume);

    SetErrorMode(error_mode);

    if (cur_ptr >= end_ptr)
    {
        good = FALSE;
    }

    if (good)
    {
        *cur_ptr = 0;
        ++*lpcchReturnLength;
    }
    else
    {
        SetLastError(ERROR_MORE_DATA);
    }

    return good;
}
Exemplo n.º 6
0
	void g_scan_drives (DWORD mask)
	{
	//pfc::hires_timer timer;
	//timer.start();
	//profiler(scandrives);
#if 0
		{
			TCHAR volume[128], mount[512];
			memset(volume, 0, sizeof(volume));
			HANDLE vol = FindFirstVolume(volume, tabsize(volume)-1);
			if (vol != INVALID_HANDLE_VALUE)
			{
				do
				{
					console::formatter() << "Volume: " << pfc::stringcvt::string_utf8_from_wide(volume, 128);
					memset(mount, 0, sizeof(mount));
					HANDLE hmount = FindFirstVolumeMountPoint(volume, mount, tabsize(mount)-1);
					if (hmount != INVALID_HANDLE_VALUE)
					{
						do
						{
							console::formatter() << "mountpoint: " << pfc::stringcvt::string_utf8_from_wide(mount, tabsize(mount));
							memset(mount, 0, sizeof(mount));
						}
						while (FindNextVolumeMountPoint(hmount, mount, tabsize(mount)-1) || GetLastError() != ERROR_NO_MORE_FILES);
						FindVolumeMountPointClose(hmount);

					}
					memset(volume, 0, sizeof(volume));
				}
				while (FindNextVolume(vol, volume, tabsize(volume)-1) || GetLastError() != ERROR_NO_MORE_FILES);
				FindVolumeClose(vol);
			}
		}
#endif
		if (mask)
		{
			t_volumes volumes;
			build_volumes_v2(volumes);

			t_size i =0;
			for (i=0; i<32; i++)
			{
				if (mask & 1<<i) 
				{
					pfc::string8 drive; drive.add_byte('A'+i);
					pfc::array_t<WCHAR> path, itunesdb_path;
					path.append_single('A'+i);
					path.append_fromptr(L":\\", 3);
					{
						WCHAR volumename[129];
						memset(volumename, 0, sizeof(volumename));
						if (GetDriveType(path.get_ptr()) == DRIVE_REMOVABLE && GetVolumeNameForVolumeMountPoint(path.get_ptr(), volumename, 128))
						{
							t_size indexvol;
							//if (volumes.find(volumename, 128, indexvol))
							{
								//FIXME WTF
								if (volumes.find(volumename, 128, indexvol) /*&& g_check_devid_is_ipod(volumes[indexvol].disk_device_id)*/)
								{
									ipod_device_ptr_t temp = new ipod_device_t('A' + i, volumes[indexvol].model, volumes[indexvol].shuffle, volumes[indexvol].disk_device_id.get_ptr(), volumes[indexvol].volume_name.get_ptr(), volumes[indexvol].driver_symbolic_path.get_ptr(), volumes[indexvol].instance, device_properties_t());

									pfc::string8 pl;
									try {
										g_get_device_xml(temp, pl);
#if 0//_DEBUG
										{
											file::ptr f;
											abort_callback_dummy noabort;
											filesystem::g_open_read(f, "i:\\nano6g.plist", noabort);
											pfc::array_staticsize_t<char> d(pfc::downcast_guarded<t_uint32>(f->get_size_ex(noabort)));
											f->read(d.get_ptr(), d.get_size(), noabort);
											pl.set_string(d.get_ptr(), d.get_size());
										}
#endif
										g_get_artwork_info(pl, temp->m_device_properties);
									} 
									catch (const pfc::exception & ex) 
									{
										console::formatter() << "iPod manager: Failed to get iPod checkpoint data - " << ex.what() << ". Artwork functionality will be unavailable.";
										temp->m_device_properties.m_artwork_formats.remove_all();
									};
									//console::formatter() << "New iPod detected. Drive: " << drive << " Device Instance ID: " << pfc::stringcvt::string_utf8_from_wide(volumes[indexvol].disk_device_id);
									if (m_abort)
										g_drive_manager.add_drive(temp, *m_abort);
									else
										g_drive_manager.add_drive(temp, abort_callback_dummy());
								}
								//else
								//	console::formatter() << "New drive detected. Drive: " << drive << " Device Instance ID: " << pfc::stringcvt::string_utf8_from_wide(volumes[indexvol].disk_device_id);// << " Volume ID: " << pfc::stringcvt::string_utf8_from_wide(volumes[indexvol].volume_name);
							}
						}
						//else
						//	console::formatter() << "Drive is not expected type or GetVolumeNameForVolumeMountPoint failed. Drive: " << drive;
					}
				}

			}
		}
		//console::formatter() << "old:" << timer.query();
	}