bool
ExpanderWindow::ValidateDest()
{
	BEntry entry(fDestText->Text(), true);
	BVolume volume;
	if (!entry.Exists()) {
		BAlert* alert = new BAlert("destAlert",
			B_TRANSLATE("The destination folder does not exist."),
			B_TRANSLATE("Cancel"), NULL, NULL,
			B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_WARNING_ALERT);
		alert->Go();
		return false;
	} else if (!entry.IsDirectory()) {
		(new BAlert("destAlert",
			B_TRANSLATE("The destination is not a folder."),
			B_TRANSLATE("Cancel"), NULL, NULL,
			B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_WARNING_ALERT))->Go();
		return false;
	} else if (entry.GetVolume(&volume) != B_OK || volume.IsReadOnly()) {
		(new BAlert("destAlert",
			B_TRANSLATE("The destination is read only."),
			B_TRANSLATE("Cancel"), NULL, NULL, B_WIDTH_AS_USUAL,
			B_EVEN_SPACING,	B_WARNING_ALERT))->Go();
		return false;
	} else {
		entry.GetRef(&fDestRef);
		return true;
	}
}
Esempio n. 2
0
// get_volume_info
bool
get_volume_info( BVolume& volume, BString& volumeName, bool& isCDROM, BString& deviceName )
{
    bool success = false;
    isCDROM = false;
    deviceName = "";
    volumeName = "";
    char name[B_FILE_NAME_LENGTH];
    if ( volume.GetName( name ) >= B_OK )    // disk is currently mounted
    {
        volumeName = name;
        dev_t dev = volume.Device();
        fs_info info;
        if ( fs_stat_dev( dev, &info ) == B_OK )
        {
            success = true;
            deviceName = info.device_name;
            if ( volume.IsReadOnly() )
            {
                int i_dev = open( info.device_name, O_RDONLY );
                if ( i_dev >= 0 )
                {
                    device_geometry g;
                    if ( ioctl( i_dev, B_GET_GEOMETRY, &g, sizeof( g ) ) >= 0 )
                        isCDROM = ( g.device_type == B_CD );
                    close( i_dev );
                }
            }
        }
     }
     return success;
}
status_t
CDDBQuery::_OpenContentFile(const int32 &discID)
{
	// Makes sure that the lookup has a valid file to work with for the CD
	// content. Returns true if there is an existing file, false if a lookup is
	// required.

	BFile file;
	BString predicate;
	predicate << "CD:key == " << discID;
	entry_ref ref;

	BVolumeRoster roster;
	BVolume volume;
	roster.Rewind();
	while (roster.GetNextVolume(&volume) == B_OK) {
		if (volume.IsReadOnly() || !volume.IsPersistent() || !volume.KnowsAttr()
			|| !volume.KnowsQuery())
			continue;

		// make sure the volume we are looking at is indexed right
		fs_create_index(volume.Device(), "CD:key", B_INT32_TYPE, 0);

		BQuery query;
		query.SetVolume(&volume);
		query.SetPredicate(predicate.String());
		if (query.Fetch() != B_OK)
			continue;

		if (query.GetNextRef(&ref) == B_OK) 
			break;
	}

	status_t status = fCDData.Load(ref);
	if (status == B_NO_INIT) {
		// We receive this error when the Load() function couldn't load the
		// track times This just means that we get it from the SCSI data given
		// to us in SetToCD
		vector<CDAudioTime> times;
		GetTrackTimes(&fSCSIData,times);

		for (int32 i = 0; i < fCDData.CountTracks(); i++) {
			CDAudioTime *item = fCDData.TrackTimeAt(i);
			*item = times[i + 1] - times[i];
		}

		status = B_OK;
	}

	return status;
}
void 
TTracker::InstallIndices()
{
	BVolumeRoster roster;
	BVolume volume;

	roster.Rewind();
	while (roster.GetNextVolume(&volume) == B_OK) {
		if (volume.IsReadOnly() || !volume.IsPersistent()
			|| !volume.KnowsAttr() || !volume.KnowsQuery())
			continue;
		InstallIndices(volume.Device());
	}
}
void
BTrashWatcher::WatchTrashDirs()
{
	BVolumeRoster volRoster;
	volRoster.Rewind();
	BVolume	volume;
	while (volRoster.GetNextVolume(&volume) == B_OK) {
		if (volume.IsReadOnly() || !volume.IsPersistent())
			continue;

		BDirectory trashDir;
		if (FSGetTrashDir(&trashDir, volume.Device()) == B_OK) {
			node_ref trash_node;
			trashDir.GetNodeRef(&trash_node);
			watch_node(&trash_node, B_WATCH_DIRECTORY, this);
			fTrashNodeList.AddItem(new node_ref(trash_node));
		}
	}
}
bool GenesisCopyWindow::IsDirReadOnly(const char *destination)
////////////////////////////////////////////////////////////////////////
{
	struct stat statbuf;	
	BDirectory dir(destination);
	BVolume volume;
	
	if (dir.InitCheck()!=B_OK)
		return false;
	
	if (dir.GetStatFor(destination, &statbuf)!=B_OK)
		return false;
	
	volume.SetTo(statbuf.st_dev);
	if (volume.IsReadOnly())
		return true;
	
	return false;	// Not read only
}
bool
BTrashWatcher::CheckTrashDirs()
{
	BVolumeRoster volRoster;
	volRoster.Rewind();
	BVolume	volume;
	while (volRoster.GetNextVolume(&volume) == B_OK) {
		if (volume.IsReadOnly() || !volume.IsPersistent())
			continue;

		BDirectory trashDir;
		FSGetTrashDir(&trashDir, volume.Device());
		trashDir.Rewind();
		BEntry entry;
		if (trashDir.GetNextEntry(&entry) == B_OK)
			return true;
	}

	return false;
}
Esempio n. 8
0
// SymLink handling:
// symlink pose uses the resolved model to retrieve the icon, if not broken
// everything else, like the attributes, etc. is retrieved directly from the
// symlink itself
BPose::BPose(Model* model, BPoseView* view, uint32 clipboardMode,
	bool selected)
	:
	fModel(model),
	fWidgetList(4, true),
	fClipboardMode(clipboardMode),
	fPercent(-1),
	fSelectionTime(0),
	fIsSelected(selected),
	fHasLocation(false),
	fNeedsSaveLocation(false),
	fListModeInited(false),
	fWasAutoPlaced(false),
	fBrokenSymLink(false),
	fBackgroundClean(false)
{
	CreateWidgets(view);

	if (model->IsVolume()) {
		fs_info info;
		dev_t device = model->NodeRef()->device;
		BVolume* volume = new BVolume(device);
		if (volume->InitCheck() == B_OK
			&& fs_stat_dev(device, &info) == B_OK) {
			// Philosophy here:
			// Bars go on all read/write volumes
			// Exceptions: Not on CDDA
			if (strcmp(info.fsh_name,"cdda") != 0
				&& !volume->IsReadOnly()) {
				// The volume is ok and we want space bars on it
				gPeriodicUpdatePoses.AddPose(this, view,
					_PeriodicUpdateCallback, volume);
				if (TrackerSettings().ShowVolumeSpaceBar())
					fPercent = CalcFreeSpace(volume);
			} else
				delete volume;
		} else
			delete volume;
	}
}
Esempio n. 9
0
/*	isVolume
*	checks if selected file is a volume
*	if yes, returns true
*/	
bool
ProjectTypeSelector::isVolume()
{
	BString *SelectedFile = (BString*)FileList->FirstItem();
	BString SelectedFileTMP;
	BVolumeRoster objVolumeRoster;
	objVolumeRoster.Rewind();
	BVolume objVolume;
	char chVolumeName[B_FILE_NAME_LENGTH];
	
	SelectedFile->CopyInto(SelectedFileTMP, 0, (int)SelectedFile->Length());	
	SelectedFileTMP.RemoveAll("/");
	while(objVolumeRoster.GetNextVolume(&objVolume) != B_BAD_VALUE) {
		objVolume.GetName(chVolumeName);
		
		if(SelectedFileTMP.Compare(chVolumeName) == 0 && objVolume.IsReadOnly()) {
			fSizeOfFiles = objVolume.Capacity();
			return true;
		}
	}
	
	return false;
}
Esempio n. 10
0
void
AutoMounter::_GetSettings(BMessage *message)
{
	message->MakeEmpty();

	bool all, bfs, restore;

	_FromMode(fNormalMode, all, bfs, restore);
	message->AddBool("initialMountAll", all);
	message->AddBool("initialMountAllBFS", bfs);
	message->AddBool("initialMountRestore", restore);

	_FromMode(fRemovableMode, all, bfs, restore);
	message->AddBool("autoMountAll", all);
	message->AddBool("autoMountAllBFS", bfs);

	message->AddBool("ejectWhenUnmounting", fEjectWhenUnmounting);

	// Save mounted volumes so we can optionally mount them on next
	// startup
	BVolumeRoster volumeRoster;
	BVolume volume;
	while (volumeRoster.GetNextVolume(&volume) == B_OK) {
        fs_info info;
        if (fs_stat_dev(volume.Device(), &info) == 0
			&& (info.flags & (B_FS_IS_REMOVABLE | B_FS_IS_PERSISTENT)) != 0) {
			message->AddString(info.device_name, info.volume_name);

			BString mountFlagsKey(info.device_name);
			mountFlagsKey << kMountFlagsKeyExtension;
			uint32 mountFlags = 0;
			if (volume.IsReadOnly())
				mountFlags |= B_MOUNT_READ_ONLY;
			message->AddInt32(mountFlagsKey.String(), mountFlags);
		}
	}
}
Esempio n. 11
0
status_t
PackageView::_InstallTypeChanged(int32 index)
{
	if (index < 0)
		return B_ERROR;

	// Clear the choice list
	for (int32 i = fDestination->CountItems() - 1; i >= 0; i--) {
		BMenuItem* item = fDestination->RemoveItem(i);
		delete item;
	}

	fCurrentType = index;
	pkg_profile* profile = fInfo.GetProfile(index);

	if (profile == NULL)
		return B_ERROR;

	BString typeDescription = profile->description;
	if (typeDescription.IsEmpty())
		typeDescription = profile->name;

	fInstallTypeDescriptionView->SetText(typeDescription.String());

	BPath path;
	BVolume volume;

	if (profile->path_type == P_INSTALL_PATH) {
		BMenuItem* item = NULL;
		if (find_directory(B_SYSTEM_NONPACKAGED_DIRECTORY, &path) == B_OK) {
			dev_t device = dev_for_path(path.Path());
			if (volume.SetTo(device) == B_OK && !volume.IsReadOnly()
				&& path.Append("apps") == B_OK) {
				item = _AddDestinationMenuItem(path.Path(), volume.FreeBytes(),
					path.Path());
			}
		}

		if (item != NULL) {
			item->SetMarked(true);
			fCurrentPath.SetTo(path.Path());
			fDestination->AddSeparatorItem();
		}

		_AddMenuItem(B_TRANSLATE("Other" B_UTF8_ELLIPSIS),
			new BMessage(P_MSG_OPEN_PANEL), fDestination);

		fDestField->SetEnabled(true);
	} else if (profile->path_type == P_USER_PATH) {
		bool defaultPathSet = false;
		BVolumeRoster roster;

		while (roster.GetNextVolume(&volume) != B_BAD_VALUE) {
			BDirectory mountPoint;
			if (volume.IsReadOnly() || !volume.IsPersistent()
				|| volume.GetRootDirectory(&mountPoint) != B_OK) {
				continue;
			}

			if (path.SetTo(&mountPoint, NULL) != B_OK)
				continue;

			char volumeName[B_FILE_NAME_LENGTH];
			volume.GetName(volumeName);
	
			BMenuItem* item = _AddDestinationMenuItem(volumeName,
				volume.FreeBytes(), path.Path());

			// The first volume becomes the default element
			if (!defaultPathSet) {
				item->SetMarked(true);
				fCurrentPath.SetTo(path.Path());
				defaultPathSet = true;
			}
		}

		fDestField->SetEnabled(true);
	} else
		fDestField->SetEnabled(false);

	return B_OK;
}
Esempio n. 12
0
    int
    getmntent_haiku(int* cookie, struct mnttab* mp)
    {
        static BLocker mntent_locker;
        mntent_locker.Lock();

        int ret = -1;
        BVolumeRoster roster;
        char buf[B_PATH_NAME_LENGTH];
        int buflen = 0;
        BVolume volume;
        BDirectory rootDir;
        BEntry rootDirEntry;
        BPath rootDirPath;

        roster.Rewind();
        for (int i = 0; i <= *cookie; i++)
            if (roster.GetNextVolume(&volume) != B_NO_ERROR)
                goto bail;

        // volume name
        volume.GetName(buf);
        buflen = strlen(buf);

        if (buflen == 0) {
            buflen = strlen(MNTENT_MP_UNKNOWN);
            strlcpy(buf, MNTENT_MP_UNKNOWN, buflen + 1);
        }

        mp->mnt_special = (char* )malloc(sizeof(char) * (buflen+1));
        strlcpy(mp->mnt_special, buf, buflen+1);

        // mount point
        if (volume.GetRootDirectory(&rootDir) != B_OK ||
                rootDir.GetEntry(&rootDirEntry) != B_OK   ||
                rootDirEntry.GetPath(&rootDirPath) != B_OK)
            goto bail;

        buflen = strlen(rootDirPath.Path());
        mp->mnt_mountp = (char* )malloc(sizeof(char) * (buflen+1));
        strlcpy(mp->mnt_mountp, rootDirPath.Path(), buflen + 1);

        // partition type.
        fs_info info;
        if (fs_stat_dev(volume.Device(), &info) != B_OK)
            goto bail;

        buflen = strlen(info.fsh_name);
        mp->mnt_fstype = (char* )malloc(sizeof(char) * (buflen+1));
        strlcpy(mp->mnt_fstype, info.fsh_name, buflen+1);

        // fs options. set default options for all file systems for now.
        buflen = strlen(MNTENT_MP_DEFAULT_OPTS);
        mp->mnt_mntopts = (char* )malloc(sizeof(char) * (buflen+2+1)); // extra space for ro/rw
        strlcpy(mp->mnt_mntopts, MNTENT_MP_DEFAULT_OPTS, buflen + 2 + 1);
        strcat(mp->mnt_mntopts, volume.IsReadOnly() ? ",ro":",rw");

        // mount time. no idea how i can get this. set it to 0 for now.
        buflen = 1;
        mp->mnt_time = (char* )malloc(sizeof(char) * (buflen+1));
        strlcpy(mp->mnt_time, "0", buflen + 1);

        (*cookie)++;
        ret = 0; /* success! */

bail:
        mntent_locker.Unlock();
        return ret;
    }
Esempio n. 13
0
status_t
Settings::ReadSwapSettings()
{
	void* settings = load_driver_settings(kVirtualMemorySettings);
	if (settings == NULL)
		return kErrorSettingsNotFound;
	CObjectDeleter<void, status_t> settingDeleter(settings,
		&unload_driver_settings);

	const char* enabled = get_driver_parameter(settings, "vm", NULL, NULL);
	const char* automatic = get_driver_parameter(settings, "swap_auto",
		NULL, NULL);
	const char* size = get_driver_parameter(settings, "swap_size", NULL, NULL);
	const char* volume = get_driver_parameter(settings, "swap_volume_name",
		NULL, NULL);
	const char* device = get_driver_parameter(settings,
		"swap_volume_device", NULL, NULL);
	const char* filesystem = get_driver_parameter(settings,
		"swap_volume_filesystem", NULL, NULL);
	const char* capacity = get_driver_parameter(settings,
		"swap_volume_capacity", NULL, NULL);

	if (enabled == NULL	|| automatic == NULL || size == NULL || device == NULL
		|| volume == NULL || capacity == NULL || filesystem == NULL)
		return kErrorSettingsInvalid;

	off_t volCapacity = atoll(capacity);

	SetSwapEnabled(get_driver_boolean_parameter(settings,
		"vm", true, false));
	SetSwapAutomatic(get_driver_boolean_parameter(settings,
		"swap_auto", true, false));
	SetSwapSize(atoll(size));

	int32 bestScore = -1;
	dev_t bestVol = -1;

	BVolume vol;
	fs_info volStat;
	BVolumeRoster roster;
	while (roster.GetNextVolume(&vol) == B_OK) {
		if (!vol.IsPersistent() || vol.IsReadOnly() || vol.IsRemovable()
			|| vol.IsShared())
			continue;
		if (fs_stat_dev(vol.Device(), &volStat) == 0) {
			int32 score = 0;
			if (strcmp(volume, volStat.volume_name) == 0)
				score += 4;
			if (strcmp(device, volStat.device_name) == 0)
				score += 3;
			if (volCapacity == volStat.total_blocks * volStat.block_size)
				score += 2;
			if (strcmp(filesystem, volStat.fsh_name) == 0)
				score += 1;
			if (score >= 4 && score > bestScore) {
				bestVol = vol.Device();
				bestScore = score;
			}
		}
	}

	SetSwapVolume(bestVol);
	fInitialSettings = fCurrentSettings;

	if (bestVol < 0)
		return kErrorVolumeNotFound;

	return B_OK;
}
Esempio n. 14
0
bool
BNavMenu::StartBuildingItemList()
{
	BEntry entry;

	if (fNavDir.device < 0 || entry.SetTo(&fNavDir) != B_OK
		|| !entry.Exists())
		return false;

	fItemList = new BObjectList<BMenuItem>(50);

	fIteratingDesktop = false;

	BDirectory parent;
	status_t status = entry.GetParent(&parent);

	// if ref is the root item then build list of volume root dirs
	fFlags = uint8((fFlags & ~kVolumesOnly)
		| (status == B_ENTRY_NOT_FOUND ? kVolumesOnly : 0));
	if (fFlags & kVolumesOnly)
		return true;

	Model startModel(&entry, true);
	if (startModel.InitCheck() != B_OK || !startModel.IsContainer())
		return false;

	if (startModel.IsQuery())
		fContainer = new QueryEntryListCollection(&startModel);
	else if (startModel.IsVirtualDirectory())
		fContainer = new VirtualDirectoryEntryList(&startModel);
	else if (startModel.IsDesktop()) {
		fIteratingDesktop = true;
		fContainer = DesktopPoseView::InitDesktopDirentIterator(
			0, 	startModel.EntryRef());
		AddRootItemsIfNeeded();
		AddTrashItem();
	} else if (startModel.IsTrash()) {
		// the trash window needs to display a union of all the
		// trash folders from all the mounted volumes
		BVolumeRoster volRoster;
		volRoster.Rewind();
		BVolume volume;
		fContainer = new EntryIteratorList();

		while (volRoster.GetNextVolume(&volume) == B_OK) {
			if (volume.IsReadOnly() || !volume.IsPersistent())
				continue;

			BDirectory trashDir;

			if (FSGetTrashDir(&trashDir, volume.Device()) == B_OK)
				dynamic_cast<EntryIteratorList*>(fContainer)->
					AddItem(new DirectoryEntryList(trashDir));
		}
	} else
		fContainer = new DirectoryEntryList(*dynamic_cast<BDirectory*>
			(startModel.Node()));

	if (fContainer == NULL || fContainer->InitCheck() != B_OK)
		return false;

	fContainer->Rewind();

	return true;
}