コード例 #1
0
bool TWPartition::Update_Size(bool Display_Error) {
	bool ret = false, Was_Already_Mounted = false;

	if (!Can_Be_Mounted && !Is_Encrypted)
		return false;

	Was_Already_Mounted = Is_Mounted();
	if (Removable || Is_Encrypted) {
		if (!Mount(false))
			return true;
	} else if (!Mount(Display_Error))
		return false;

	ret = Get_Size_Via_statfs(Display_Error);
	if (!ret || Size == 0) {
		if (!Get_Size_Via_df(Display_Error)) {
			if (!Was_Already_Mounted)
				UnMount(false);
			return false;
		}
	}

	if (Has_Data_Media) {
		if (Mount(Display_Error)) {
			unsigned long long data_media_used, actual_data;
			Used = TWFunc::Get_Folder_Size("/data", Display_Error);
			data_media_used = TWFunc::Get_Folder_Size("/data/media", Display_Error);
			actual_data = Used - data_media_used;
			Backup_Size = actual_data;
			int bak = (int)(Backup_Size / 1048576LLU);
			int total = (int)(Size / 1048576LLU);
			int us = (int)(Used / 1048576LLU);
			int fre = (int)(Free / 1048576LLU);
			int datmed = (int)(data_media_used / 1048576LLU);
			LOGI("Data backup size is %iMB, size: %iMB, used: %iMB, free: %iMB, in data/media: %iMB.\n", bak, total, us, fre, datmed);
		} else {
			if (!Was_Already_Mounted)
				UnMount(false);
			return false;
		}
	} else if (Has_Android_Secure) {
		if (Mount(Display_Error))
			Backup_Size = TWFunc::Get_Folder_Size(Backup_Path, Display_Error);
		else {
			if (!Was_Already_Mounted)
				UnMount(false);
			return false;
		}
	}
	if (!Was_Already_Mounted)
		UnMount(false);
	return true;
}
コード例 #2
0
ファイル: VirtualDrive.cpp プロジェクト: Tevic/ISOCmdX
//弹出所有光驱
void VirtualDrive::UnMountAll()
{
	for (int i = 0; i < GetDriveCount(); i++)
	{
		UnMount();
	}
}
コード例 #3
0
ファイル: HALManager.cpp プロジェクト: Ayu222/android
void CHALManager::Stop()
{
  if (g_advancedSettings.m_handleMounting)
  { // Unmount all media XBMC have mounted
    for (unsigned int i = 0; i < m_Volumes.size(); i++)
    {
      if (m_Volumes[i].MountedByXBMC && m_Volumes[i].Mounted)
      {
        CLog::Log(LOGNOTICE, "HAL: Unmounts %s", m_Volumes[i].FriendlyName.c_str());
        UnMount(m_Volumes[i]);
      }
    }
  }

  m_Volumes.clear();

  if (m_Context != NULL)
    libhal_ctx_shutdown(m_Context, NULL);
  if (m_Context != NULL)
    libhal_ctx_free(m_Context);

  if (m_DBusSystemConnection != NULL)
  {
    dbus_connection_unref(m_DBusSystemConnection);
    m_DBusSystemConnection = NULL;
  }
  dbus_error_free(&m_Error); // Needed?
}
コード例 #4
0
bool TWPartition::Wipe_FAT() {
	char command[512];

	if (TWFunc::Path_Exists("/sbin/mkdosfs")) {
		if (!UnMount(true))
			return false;

		ui_print("Formatting %s using mkdosfs...\n", Display_Name.c_str());
		Find_Actual_Block_Device();
		sprintf(command,"mkdosfs %s", Actual_Block_Device.c_str()); // use mkdosfs to format it
		if (system(command) == 0) {
			Recreate_AndSec_Folder();
			ui_print("Done.\n");
			return true;
		} else {
			LOGE("Unable to wipe '%s'.\n", Mount_Point.c_str());
			return false;
		}
		return true;
	}
	else
		return Wipe_RMRF();

	return false;
}
コード例 #5
0
bool TWPartition::Wipe_EXT4() {
	if (!UnMount(true))
		return false;

	if (TWFunc::Path_Exists("/sbin/make_ext4fs")) {
		string Command;

		ui_print("Formatting %s using make_ext4fs...\n", Display_Name.c_str());
		Find_Actual_Block_Device();
		Command = "make_ext4fs";
		if (!Is_Decrypted && Length != 0) {
			// Only use length if we're not decrypted
			char len[32];
			sprintf(len, "%i", Length);
			Command += " -l ";
			Command += len;
		}
		Command += " " + Actual_Block_Device;
		LOGI("make_ext4fs command: %s\n", Command.c_str());
		if (system(Command.c_str()) == 0) {
			Recreate_AndSec_Folder();
			ui_print("Done.\n");
			return true;
		} else {
			LOGE("Unable to wipe '%s'.\n", Mount_Point.c_str());
			return false;
		}
	} else
		return Wipe_EXT23();

	return false;
}
コード例 #6
0
bool TWPartition::Wipe_Encryption() {
	bool Save_Data_Media = Has_Data_Media;

	if (!UnMount(true))
		return false;

	Current_File_System = Fstab_File_System;
	Is_Encrypted = false;
	Is_Decrypted = false;
	Decrypted_Block_Device = "";
	Has_Data_Media = false;
	if (Wipe()) {
		Has_Data_Media = Save_Data_Media;
		if (Has_Data_Media && !Symlink_Mount_Point.empty()) {
			Recreate_Media_Folder();
		}
		ui_print("You may need to reboot recovery to be able to use /data again.\n");
		return true;
	} else {
		Has_Data_Media = Save_Data_Media;
		LOGE("Unable to format to remove encryption.\n");
		return false;
	}
	return false;
}
コード例 #7
0
bool TWPartition::Wipe_MTD() {
	if (!UnMount(true))
		return false;

	ui_print("MTD Formatting \"%s\"\n", MTD_Name.c_str());

    mtd_scan_partitions();
    const MtdPartition* mtd = mtd_find_partition_by_name(MTD_Name.c_str());
    if (mtd == NULL) {
        LOGE("No mtd partition named '%s'", MTD_Name.c_str());
        return false;
    }

    MtdWriteContext* ctx = mtd_write_partition(mtd);
    if (ctx == NULL) {
        LOGE("Can't write '%s', failed to format.", MTD_Name.c_str());
        return false;
    }
    if (mtd_erase_blocks(ctx, -1) == -1) {
        mtd_write_close(ctx);
        LOGE("Failed to format '%s'", MTD_Name.c_str());
        return false;
    }
    if (mtd_write_close(ctx) != 0) {
        LOGE("Failed to close '%s'", MTD_Name.c_str());
        return false;
    }
	Recreate_AndSec_Folder();
	ui_print("Done.\n");
    return true;
}
コード例 #8
0
ファイル: HALManager.cpp プロジェクト: Ayu222/android
bool CHALManager::Eject(CStdString path)
{
  for (unsigned int i = 0; i < m_Volumes.size(); i++)
  {
    if (m_Volumes[i].MountPoint.Equals(path))
      return m_Volumes[i].HotPlugged ? UnMount(m_Volumes[i]) : false;
  }

  return false;
}
コード例 #9
0
ファイル: profiserial.c プロジェクト: FMMT666/ProfiLua
//**************************************************************************************
//*** plSerialUnMount
//***
//***
//*** LUA STACK IN:
//***  L1: handle
//*** LUA STACK OUT:
//***  number   : 0  ->  error
//***             1  ->  success
//**************************************************************************************
static int plSerialUnMount( lua_State *L )
{
	int ret = 0;

	if( lua_gettop(L) == 1 )
		ret = UnMount( lua_tonumber( L, 1 ) );

	lua_pushnumber( L, ret );

	return 1;
}
コード例 #10
0
ファイル: VFS.cpp プロジェクト: Rabarberpapa/rpcs3
void VFS::Mount(const wxString& ps3_path, const wxString& local_path, vfsDevice* device)
{
	UnMount(ps3_path);

	device->SetPath(ps3_path, local_path);
	m_devices.Add(device);

	if(m_devices.GetCount() > 1)
	{
		//std::qsort(m_devices.GetPtr(), m_devices.GetCount(), sizeof(vfsDevice*), sort_devices);
	}
}
コード例 #11
0
ファイル: VFS.cpp プロジェクト: ss23/rpcs3
void VFS::Mount(const std::string& ps3_path, const std::string& local_path, vfsDevice* device)
{
	std::string simpl_ps3_path = simplify_path(ps3_path, true, true);

	UnMount(simpl_ps3_path);

	device->SetPath(simpl_ps3_path, simplify_path(local_path, true, false));
	m_devices.push_back(device);

	if (m_devices.size() > 1)
	{
		std::sort(m_devices.begin(), m_devices.end(), [](vfsDevice *a, vfsDevice *b) { return b->GetPs3Path().length() < a->GetPs3Path().length(); });
	}
}
コード例 #12
0
void DeviceHandler::UnMountAll()
{
	/* Kill possible USB thread */
	KillUSBKeepAliveThread();

	for(u32 i = SD; i < MAXDEVICES; i++)
		UnMount(i);
	USBStorage2_Deinit();
	USB_Deinitialize();
	SDHC_Close();

	sd.Cleanup();
	usb.Cleanup();
}
コード例 #13
0
bool PartitionHandle::Mount(int pos, const char * name)
{
	if(!valid(pos))
		return false;

	if(!name)
		return false;

	UnMount(pos);

	if(pos >= (int) MountNameList.size())
		MountNameList.resize(GetPartitionCount());

	MountNameList[pos] = name;

	if(strncmp(GetFSName(pos), "FAT", 3) == 0 || strcmp(GetFSName(pos), "GUID-Entry") == 0)
	{
		if (fatMount(MountNameList[pos].c_str(), interface, GetLBAStart(pos), CACHE, SECTORS))
		{
			if(strcmp(GetFSName(pos), "GUID-Entry") == 0)
				PartitionList[pos].FSName = "FAT";
			return true;
		}
	}

	if(strncmp(GetFSName(pos), "NTFS", 4) == 0 || strcmp(GetFSName(pos), "GUID-Entry") == 0)
	{
		if(ntfsMount(MountNameList[pos].c_str(), interface, GetLBAStart(pos), CACHE, SECTORS, NTFS_SHOW_HIDDEN_FILES | NTFS_RECOVER))
		{
			PartitionList[pos].FSName = "NTFS";
			return true;
		}
	}

	if(strncmp(GetFSName(pos), "LINUX", 5) == 0 || strcmp(GetFSName(pos), "GUID-Entry") == 0)
	{
		if(ext2Mount(MountNameList[pos].c_str(), interface, GetLBAStart(pos), CACHE, SECTORS, EXT2_FLAG_DEFAULT))
		{
			PartitionList[pos].FSName = "LINUX";
			return true;
		}
	}
	MountNameList[pos].clear();

	return false;
}
コード例 #14
0
ファイル: HALManager.cpp プロジェクト: Ayu222/android
/* Here we should iterate through our remembered devices if any of them are removed */
bool CHALManager::RemoveDevice(const char *udi)
{
  CSingleLock lock(m_lock);
  for (unsigned int i = 0; i < m_Volumes.size(); i++)
  {
    if (strcmp(m_Volumes[i].UDI.c_str(), udi) == 0)
    {
      CLog::Log(LOGNOTICE, "HAL: Removed - %s | %s", CHALManager::StorageTypeToString(m_Volumes[i].Type), m_Volumes[i].toString().c_str());

      if (m_Volumes[i].Mounted)
      {
        if (g_advancedSettings.m_handleMounting)
          UnMount(m_Volumes[i]);
        if (m_Notifications)
          CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Warning, g_localizeStrings.Get(13022), m_Volumes[i].FriendlyName.c_str());
        CLog::Log(LOGNOTICE, "HAL: Unsafe drive removal");
      }
      m_Volumes.erase(m_Volumes.begin() + i);
      return true;
    }
  }
#if defined(HAS_SDL_JOYSTICK)
  for(uint i = 0; i < m_Joysticks.size(); i++)
  {
    if (strcmp(m_Joysticks[i].UDI.c_str(), udi) == 0)
    {
      if(m_Joysticks.size() < 3 || m_bMultipleJoysticksSupport)
      {
        // Restart SDL joystick subsystem
        if (!g_Joystick.Reinitialize())
          return false;

        if (m_Notifications)
          CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Warning, g_localizeStrings.Get(13025), m_Joysticks[i].FriendlyName.c_str(), TOAST_DISPLAY_TIME, false);
      }
      m_Joysticks.erase(m_Joysticks.begin() + i);
      return true;
    }
  }
#endif
  return false;
}
コード例 #15
0
void DeviceHandler::UnMountAll()
{
	for(u32 i = SD; i <= USB10; i++)
		UnMount(i);

	if(sd)
		delete sd;
	/*if(gca)
		delete gca;
	if(gcb)
		delete gca;*/
	if(usb0)
		delete usb0;
	if(usb1)
		delete usb1;

	sd = NULL;
	//gca = NULL;
	//gcb = NULL;
	usb0 = NULL;
	usb1 = NULL;
	USBStorage2_Deinit();
}
コード例 #16
0
bool TWPartition::Wipe_EXT23() {
	if (!UnMount(true))
		return false;

	if (TWFunc::Path_Exists("/sbin/mke2fs")) {
		char command[512];

		ui_print("Formatting %s using mke2fs...\n", Display_Name.c_str());
		Find_Actual_Block_Device();
		sprintf(command, "mke2fs -t %s -m 0 %s", Current_File_System.c_str(), Actual_Block_Device.c_str());
		LOGI("mke2fs command: %s\n", command);
		if (system(command) == 0) {
			Recreate_AndSec_Folder();
			ui_print("Done.\n");
			return true;
		} else {
			LOGE("Unable to wipe '%s'.\n", Mount_Point.c_str());
			return false;
		}
	} else
		return Wipe_RMRF();

	return false;
}
コード例 #17
0
bool PartitionHandle::Mount(int pos, const char *name, bool forceFAT)
{
	if(valid(pos))
		UnMount(pos);

	if(!name)
		return false;

	if(pos >= (int)MountNameList.size())
		MountNameList.resize(pos + 1);

	MountNameList[pos] = name;
	char DeviceSyn[10];
	memcpy(DeviceSyn, name, 8);
	strcat(DeviceSyn, ":");
	DeviceSyn[9] = '\0';

	//! Some stupid partition manager think they don't need to edit the freaken MBR.
	//! So we need to check the first 64 sectors and see if some partition is there.
	//! libfat does that by default so let's use it.
	if(forceFAT && (strlen(GetFSName(pos)) == 0 || strcmp(GetFSName(pos), "Unknown") == 0))
	{
		if(fatMount(MountNameList[pos].c_str(), interface, 0, CACHE, SECTORS))
		{
			sec_t FAT_startSector = FindFirstValidPartition(interface);
			AddPartition("FAT", FAT_startSector, 0xdeadbeaf, true, 0x0c, 0);
			gprintf("FAT Partition at %s (forceFAT) mounted.\n", DeviceSyn);
			SetWbfsHandle(pos, NULL);
			return true;
		}
	}
	if(!valid(pos))
		return false;

	SetWbfsHandle(pos, NULL);
	if(strncmp(GetFSName(pos), "FAT", 3) == 0 || strcmp(GetFSName(pos), "GUID-Entry") == 0)
	{
		if(fatMount(MountNameList[pos].c_str(), interface, GetLBAStart(pos), CACHE, SECTORS))
		{
			gprintf("FAT Partition at %s mounted.\n", DeviceSyn);
			PartitionList[pos].FSName = "FAT";
			return true;
		}
	}
	else if(strncmp(GetFSName(pos), "NTFS", 4) == 0 || strcmp(GetFSName(pos), "GUID-Entry") == 0)
	{
		if(ntfsMount(MountNameList[pos].c_str(), interface, GetLBAStart(pos), CACHE, SECTORS, NTFS_SHOW_HIDDEN_FILES | NTFS_RECOVER))
		{
			gprintf("NTFS Partition at %s mounted.\n", DeviceSyn);
			PartitionList[pos].FSName = "NTFS";
			return true;
		}
	}
	else if(strncmp(GetFSName(pos), "LINUX", 5) == 0 || strcmp(GetFSName(pos), "GUID-Entry") == 0)
	{
		if(ext2Mount(MountNameList[pos].c_str(), interface, GetLBAStart(pos), CACHE, SECTORS, EXT2_FLAG_DEFAULT))
		{
			gprintf("EXT Partition at %s mounted.\n", DeviceSyn);
			PartitionList[pos].FSName = "LINUX";
			return true;
		}
	}
	else if(strncmp(GetFSName(pos), "WBFS", 4) == 0)
	{
		if(interface == &__io_usbstorage2_port0 || interface == &__io_usbstorage2_port1)
			SetWbfsHandle(pos, wbfs_open_partition(__WBFS_ReadUSB, __WBFS_WriteUSB, NULL, USBStorage2_GetSectorSize(), GetSecCount(pos), GetLBAStart(pos), 0));
		else if(interface == &__io_sdhc)
			SetWbfsHandle(pos, wbfs_open_partition(__WBFS_ReadSDHC, __WBFS_WriteSDHC, NULL, 512, GetSecCount(pos), GetLBAStart(pos), 0));
		if(GetWbfsHandle(pos))
		{
			gprintf("WBFS Partition at %s mounted.\n", DeviceSyn);
			PartitionList[pos].FSName = "WBFS";
			return true;
		}
	}
	/* FAIL */
	MountNameList[pos].clear();
	return false;
}
コード例 #18
0
ファイル: fsysssh2.c プロジェクト: seem8/friendup
void *Mount( struct FHandler *s, struct TagItem *ti )
{
    File *dev = NULL;
    char *path = NULL;
    char *name = NULL;
    char *host = NULL;
    char *ulogin = NULL;
    char *upass = NULL;
    int port = 22;
    User *usr = NULL;

    if( s == NULL )
    {
        return NULL;
    }

    DEBUG("Mounting ssh2 filesystem!\n");

    if( ( dev = calloc( sizeof( File ), 1 ) ) != NULL )
    {
        struct TagItem *lptr = ti;

        //
        // checking passed arguments

        while( lptr->ti_Tag != TAG_DONE )
        {
            switch( lptr->ti_Tag )
            {
            case FSys_Mount_Path:
                path = (char *)lptr->ti_Data;
                DEBUG("Mount FS path set '%s'\n", path );
                break;
            case FSys_Mount_Host:
                host = (char *)lptr->ti_Data;
                break;
            case FSys_Mount_Port:
                port = atol( (char *)lptr->ti_Data );
                break;
            case FSys_Mount_Name:
                name = (char *)lptr->ti_Data;
                break;
            case FSys_Mount_User:
                usr = (User *)lptr->ti_Data;
                break;
            case FSys_Mount_LoginUser:
                ulogin = (char *)lptr->ti_Data;
                break;
            case FSys_Mount_LoginPass:
                upass = (char *)lptr->ti_Data;
                break;
            }

            lptr++;
        }

        //

        if( path == NULL )
        {
            DEBUG("[ERROR]: Path option not found!\n");
            free( dev );
            return NULL;
        }

        init( s );

        // we are trying to open folder/connection

        struct stat st;
        if( stat( path, &st ) == 0 && S_ISDIR( st.st_mode ) )
        {
            DEBUG("Mounting localfsys, Its directory FSYS: %s!\n", s->GetPrefix() );

            dev->f_Path = StringDup( path );
            DEBUG("localfs path is ok '%s'\n", dev->f_Path );
            dev->f_FSys = s;
            dev->f_Type = FType_Directory;
            dev->f_Size = 0;
            dev->f_Position = 0;
            dev->f_User = usr;
            dev->f_Name = StringDup( name );



            DEBUG("data filled\n");
        }

    }

    //
    // we will hold here special data SSH2
    //

    dev->f_SpecialData = calloc( sizeof(SpecialData), 1 );
    SpecialData *sdat = (SpecialData *) dev->f_SpecialData;
    if( sdat != NULL )
    {
        sdat->sd_Host = StringDup( host );
        sdat->sd_Port = port;
        sdat->sd_LoginUser = StringDup( ulogin );
        sdat->sd_LoginPass = StringDup( upass );

        sdat->rc = libssh2_init (0);

        if( sdat->rc != 0 )
        {
            ERROR ( "libssh2 initialization failed (%d)\n", sdat->rc );
            return NULL;
        }

        // Ultra basic "connect to port 22 on localhost".  Your code is
        //responsible for creating the socket establishing the connection
        ///
        sdat->hostaddr = inet_addr( sdat->sd_Host );

        sdat->sock = socket( AF_INET, SOCK_STREAM, 0 );

        sdat->sin.sin_family = AF_INET;
        sdat->sin.sin_port = htons( sdat->sd_Port );
        sdat->sin.sin_addr.s_addr = sdat->hostaddr;

        if ( connect( sdat->sock, (struct sockaddr*)( &(sdat->sin) ), sizeof(struct sockaddr_in)) != 0)
        {
            ERROR( "failed to connect!\n");
            goto shutdown;
        }

        // Create a session instance and start it up. This will trade welcome
        // banners, exchange keys, and setup crypto, compression, and MAC layers
        //
        sdat->session = libssh2_session_init( );

        if (libssh2_session_handshake( sdat->session, sdat->sock) )
        {
            ERROR("Failure establishing SSH session\n");
            goto shutdown;
        }

        // At this point we havn't authenticated. The first thing to do is check
        // the hostkey's fingerprint against our known hosts Your app may have it
        // hard coded, may go to a file, may present it to the user, that's your
        // call
        //
        sdat->fingerprint = libssh2_hostkey_hash( sdat->session, LIBSSH2_HOSTKEY_HASH_SHA1 );

        DEBUG("Fingerprint: ");
        int i;

        for(i = 0; i < 20; i++)
        {
            DEBUG(  "%02X ", (unsigned char)sdat->fingerprint[i]);
        }
        DEBUG("\n");


        sdat->rc = libssh2_userauth_password( sdat->session, sdat->sd_LoginUser, sdat->sd_LoginPass );
        /*
        		if (!(sdat->channel = libssh2_channel_open_session(session)))
        		{
        			ERROR( "Unable to open a session\n");
        			goto shutdown;
        		}*/
        sdat->sftp_session = libssh2_sftp_init( sdat->session );


        if (!sdat->sftp_session)
        {
            DEBUG("Unable to init SFTP session\n");
            goto shutdown;
        }

        /* Since we have not set non-blocking, tell libssh2 we are blocking */
        libssh2_session_set_blocking( sdat->session, 1);

        return dev;
    }


    DEBUG("localfs mount ok\n");

shutdown:
    if( sdat != NULL )
    {
        UnMount( s, dev );
    }

    return NULL;
}