Пример #1
0
bool MountList::addMount(wxString name, wxString encFSPath, wxString driveLetter,
	wxString password, bool isWorldWritable, bool isLocalDrive, bool isMounted)
{
	wxString correctedName = name;

	// Remove any paths in front of name
	wxFileName nameFN(correctedName);
	correctedName = nameFN.GetFullName();

	// Check for double entry
	if(findEntryByName(correctedName) != NULL)
		return false;

	MountEntry newEntry;
	newEntry.name_ = correctedName;
	newEntry.encFSPath_ = encFSPath;
	newEntry.driveLetter_ = driveLetter;
	newEntry.password_ = password;
	newEntry.isWorldWritable_ = isWorldWritable;
	newEntry.isLocalDrive_ = isLocalDrive;
	newEntry.mountState_ = (isMounted ? MountEntry::MSMounted : MountEntry::MSNotMounted);

	mountEntries_.push_back(newEntry);

	return true;
}
Пример #2
0
Файл: fat.c Проект: nielh/dragon
static void* file_open(void* obj, char* path, s64 flag, s64 mode)
{
	assert(IS_PTR(obj));

    fatfile_t* file = (fatfile_t*)obj;

    down(&file->sem);

    if(*path == NULL) // last name in path
    {
        file->ref ++;
        if((!file->attr.directory) && (flag & O_TRUNC))
            file_trunc(file);

		up_one(&file->sem);
        return file;
    }

    if(!file->attr.directory) // 路径中的名称必须是目录
    {
    	up_one(&file->sem);
    	return (void*)-1;
    }

    char filename[32];
    char* end = strchr(path, '/');
    strncpy(filename, path, end -path);
    UpperStr(filename);

    if(*end == '/') // skip '/'
        end ++;

    // find in child list
    fatfile_t* child = findChild(file, filename);
    if(child == NULL)
    {
        child = (fatfile_t*)kmalloc(sizeof(fatfile_t));
        memset(child, 0, sizeof(fatfile_t));
        child->ops = &file_ops;
        sem_init(&child->sem, 1, "file sem");
        child->fatfs = file->fatfs;
        child->name = strdup(filename);

        struct FAT_ENTRY entry;
        int index = findEntryByName(file, filename, &entry);
        if(index >= 0)
        {
            child->index = index;
            child->cluster = (entry.start_clusterHI << 16) | entry.start_clusterLO;
            child->size = entry.file_size;
            child->attr = entry.attribute;

            getEntryCreateDate(child, &entry);
            getEntryWriteDate(child, &entry);
        }
        else
        {
            if((flag &O_CREAT) && (*end == NULL))
            {
                rtcdate rtc;
                cmostime(&rtc);
                child->cdatetime = rtc;
                child->wdatetime = rtc;

                child->dirty = TRUE; // update entry
            }
            else
            {
                kmfree(child->name);
                kmfree(child);

                up_one(&file->sem);
                return (void*)-2;
            }
        }

        insertChild(file, child);
    }

    up_one(&file->sem);
    return file_open(child, end, flag, mode);
}