Esempio n. 1
0
/**
 * FS_User::OpenFile service function
 *  Inputs:
 *      1 : Transaction
 *      2 : Archive handle lower word
 *      3 : Archive handle upper word
 *      4 : Low path type
 *      5 : Low path size
 *      6 : Open flags
 *      7 : Attributes
 *      8 : (LowPathSize << 14) | 2
 *      9 : Low path data pointer
 *  Outputs:
 *      1 : Result of function, 0 on success, otherwise error code
 *      3 : File handle
 */
static void OpenFile(Service::Interface* self) {
    u32* cmd_buff = Service::GetCommandBuffer();

    // TODO(Link Mauve): cmd_buff[2], aka archive handle lower word, isn't used according to
    // 3dmoo's or ctrulib's implementations.  Triple check if it's really the case.
    Handle archive_handle = static_cast<Handle>(cmd_buff[3]);
    auto filename_type    = static_cast<FileSys::LowPathType>(cmd_buff[4]);
    u32 filename_size     = cmd_buff[5];
    FileSys::Mode mode; mode.hex = cmd_buff[6];
    u32 attributes        = cmd_buff[7]; // TODO(Link Mauve): do something with those attributes.
    u32 filename_ptr      = cmd_buff[9];
    FileSys::Path file_path(filename_type, filename_size, filename_ptr);

    DEBUG_LOG(KERNEL, "path=%s, mode=%d attrs=%u", file_path.DebugStr().c_str(), mode.hex, attributes);

    ResultVal<Handle> handle = Kernel::OpenFileFromArchive(archive_handle, file_path, mode);
    cmd_buff[1] = handle.Code().raw;
    if (handle.Succeeded()) {
        cmd_buff[3] = *handle;
    } else {
        ERROR_LOG(KERNEL, "failed to get a handle for file %s", file_path.DebugStr().c_str());
    }

    DEBUG_LOG(KERNEL, "called");
}
Esempio n. 2
0
/**
 * FS_User::OpenArchive service function
 *  Inputs:
 *      1 : Archive ID
 *      2 : Archive low path type
 *      3 : Archive low path size
 *      4 : (LowPathSize << 14) | 2
 *      5 : Archive low path
 *  Outputs:
 *      1 : Result of function, 0 on success, otherwise error code
 *      2 : Archive handle lower word (unused)
 *      3 : Archive handle upper word (same as file handle)
 */
static void OpenArchive(Service::Interface* self) {
    u32* cmd_buff = Service::GetCommandBuffer();

    auto archive_id       = static_cast<FileSys::Archive::IdCode>(cmd_buff[1]);
    auto archivename_type = static_cast<FileSys::LowPathType>(cmd_buff[2]);
    u32 archivename_size  = cmd_buff[3];
    u32 archivename_ptr   = cmd_buff[5];
    FileSys::Path archive_path(archivename_type, archivename_size, archivename_ptr);

    DEBUG_LOG(KERNEL, "archive_path=%s", archive_path.DebugStr().c_str());

    if (archive_path.GetType() != FileSys::Empty) {
        ERROR_LOG(KERNEL, "archive LowPath type other than empty is currently unsupported");
        cmd_buff[1] = UnimplementedFunction(ErrorModule::FS).raw;
        return;
    }

    ResultVal<Handle> handle = Kernel::OpenArchive(archive_id);
    cmd_buff[1] = handle.Code().raw;
    if (handle.Succeeded()) {
        // cmd_buff[2] isn't used according to 3dmoo's implementation.
        cmd_buff[3] = *handle;
    } else {
        ERROR_LOG(KERNEL, "failed to get a handle for archive");
    }

    DEBUG_LOG(KERNEL, "called");
}
Esempio n. 3
0
/**
 * FS_User::OpenFileDirectly service function
 *  Inputs:
 *      1 : Transaction
 *      2 : Archive ID
 *      3 : Archive low path type
 *      4 : Archive low path size
 *      5 : File low path type
 *      6 : File low path size
 *      7 : Flags
 *      8 : Attributes
 *      9 : (ArchiveLowPathSize << 14) | 0x802
 *      10 : Archive low path
 *      11 : (FileLowPathSize << 14) | 2
 *      12 : File low path
 *  Outputs:
 *      1 : Result of function, 0 on success, otherwise error code
 *      3 : File handle
 */
static void OpenFileDirectly(Service::Interface* self) {
    u32* cmd_buff = Service::GetCommandBuffer();

    auto archive_id       = static_cast<FileSys::Archive::IdCode>(cmd_buff[2]);
    auto archivename_type = static_cast<FileSys::LowPathType>(cmd_buff[3]);
    u32 archivename_size  = cmd_buff[4];
    auto filename_type    = static_cast<FileSys::LowPathType>(cmd_buff[5]);
    u32 filename_size     = cmd_buff[6];
    FileSys::Mode mode; mode.hex = cmd_buff[7];
    u32 attributes        = cmd_buff[8]; // TODO(Link Mauve): do something with those attributes.
    u32 archivename_ptr   = cmd_buff[10];
    u32 filename_ptr      = cmd_buff[12];
    FileSys::Path archive_path(archivename_type, archivename_size, archivename_ptr);
    FileSys::Path file_path(filename_type, filename_size, filename_ptr);

    DEBUG_LOG(KERNEL, "archive_path=%s file_path=%s, mode=%u attributes=%d",
              archive_path.DebugStr().c_str(), file_path.DebugStr().c_str(), mode.hex, attributes);

    if (archive_path.GetType() != FileSys::Empty) {
        ERROR_LOG(KERNEL, "archive LowPath type other than empty is currently unsupported");
        cmd_buff[1] = UnimplementedFunction(ErrorModule::FS).raw;
        return;
    }

    // TODO(Link Mauve): Check if we should even get a handle for the archive, and don't leak it
    // TODO(yuriks): Why is there all this duplicate (and seemingly useless) code up here?
    ResultVal<Handle> archive_handle = Kernel::OpenArchive(archive_id);
    cmd_buff[1] = archive_handle.Code().raw;
    if (archive_handle.Failed()) {
        ERROR_LOG(KERNEL, "failed to get a handle for archive");
        return;
    }
    // cmd_buff[2] isn't used according to 3dmoo's implementation.
    cmd_buff[3] = *archive_handle;

    ResultVal<Handle> handle = Kernel::OpenFileFromArchive(*archive_handle, file_path, mode);
    cmd_buff[1] = handle.Code().raw;
    if (handle.Succeeded()) {
        cmd_buff[3] = *handle;
    } else {
        ERROR_LOG(KERNEL, "failed to get a handle for file %s", file_path.DebugStr().c_str());
    }

    DEBUG_LOG(KERNEL, "called");
}
Esempio n. 4
0
/// Synchronize to an OS service
static Result SendSyncRequest(Handle handle) {
    // TODO(yuriks): ObjectPool::Get tries to check the Object type, which fails since this is a generic base Object,
    // so we are forced to use GetFast and manually verify the handle.
    if (!Kernel::g_object_pool.IsValid(handle)) {
        return InvalidHandle(ErrorModule::Kernel).raw;
    }
    Kernel::Object* object = Kernel::g_object_pool.GetFast<Kernel::Object>(handle);

    _assert_msg_(KERNEL, (object != nullptr), "called, but kernel object is nullptr!");
    DEBUG_LOG(SVC, "called handle=0x%08X(%s)", handle, object->GetTypeName().c_str());

    ResultVal<bool> wait = object->SyncRequest();
    if (wait.Succeeded() && *wait) {
        Kernel::WaitCurrentThread(WAITTYPE_SYNCH); // TODO(bunnei): Is this correct?
    }

    return wait.Code().raw;
}
Esempio n. 5
0
/// Wait for a handle to synchronize, timeout after the specified nanoseconds
static Result WaitSynchronization1(Handle handle, s64 nano_seconds) {
    // TODO(bunnei): Do something with nano_seconds, currently ignoring this
    bool wait_infinite = (nano_seconds == -1); // Used to wait until a thread has terminated

    if (!Kernel::g_object_pool.IsValid(handle)) {
        return InvalidHandle(ErrorModule::Kernel).raw;
    }
    Kernel::Object* object = Kernel::g_object_pool.GetFast<Kernel::Object>(handle);
    _dbg_assert_(KERNEL, object != nullptr);

    DEBUG_LOG(SVC, "called handle=0x%08X(%s:%s), nanoseconds=%lld", handle, object->GetTypeName().c_str(),
            object->GetName().c_str(), nano_seconds);

    ResultVal<bool> wait = object->WaitSynchronization();

    // Check for next thread to schedule
    if (wait.Succeeded() && *wait) {
        HLE::Reschedule(__func__);
    }

    return wait.Code().raw;
}
Esempio n. 6
0
static void OpenDirectory(Service::Interface* self) {
    u32* cmd_buff = Service::GetCommandBuffer();

    // TODO(Link Mauve): cmd_buff[2], aka archive handle lower word, isn't used according to
    // 3dmoo's or ctrulib's implementations.  Triple check if it's really the case.
    Handle archive_handle = static_cast<Handle>(cmd_buff[2]);
    auto dirname_type = static_cast<FileSys::LowPathType>(cmd_buff[3]);
    u32 dirname_size = cmd_buff[4];
    u32 dirname_ptr = cmd_buff[6];

    FileSys::Path dir_path(dirname_type, dirname_size, dirname_ptr);

    DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_path.DebugStr().c_str());

    ResultVal<Handle> handle = Kernel::OpenDirectoryFromArchive(archive_handle, dir_path);
    cmd_buff[1] = handle.Code().raw;
    if (handle.Succeeded()) {
        cmd_buff[3] = *handle;
    } else {
        ERROR_LOG(KERNEL, "failed to get a handle for directory");
    }

    DEBUG_LOG(KERNEL, "called");
}