Example #1
0
    std::string FS::readlink(std::string path) const
    {
        LowLevel::INode buf;
        if (!this->retrievePathToINode(path, buf))
            throw Exception::FileNotFound();

        if (buf.type == LowLevel::INodeType::INT_SYMLINK)
        {
            // Read the link information out of the file.
            FSFile* file = new FSFile(this->filesystem, this->stream, buf.inodeid);
            file->open(std::ios_base::in);
            char* buffer = (char*)malloc(buf.dat_len + 1);
            std::streamsize count = file->read(buffer, buf.dat_len);
            if (count < buf.dat_len)
                buffer[count] = '\0';
            else
                buffer[buf.dat_len] = '\0';
            std::string result = buffer;
            free(buffer);

            // Check to make sure it is valid.
            if (count != buf.dat_len)
                throw Exception::InternalInconsistency();
            
            return result;
        }
        else
            throw Exception::NotSupported();
    }
Example #2
0
        int FuseLink::read(const char *path, char *out, size_t length,
                off_t offset, struct fuse_file_info *options)
        {
            FuseLink::filesystem->setuid(fuse_get_context()->uid);
            FuseLink::filesystem->setgid(fuse_get_context()->gid);

            // Read data from the file.
            try
            {
                if (offset > MSIZE_FILE || ((uint64_t) offset + (uint64_t) length) > MSIZE_FILE)
                    return -EFBIG;
                FuseLink::filesystem->touch(path, "a");
                FSFile file = FuseLink::filesystem->open(path);
                file.seekg(offset);
                uint32_t read = file.read(out, length);
                file.close();
                if (file.fail() || file.bad())
                    return -EIO;
                return read;
            }
            catch (std::exception& e)
            {
                return FuseLink::handleException(e, "read");
            }
        }
Example #3
0
void Media::add_cache(unsigned int id, FSFile & fp)
{
    FileStream stream(fp);
    AudioType type = (AudioType)stream.read_uint32();
    if (type == NONE)
        return;
    unsigned int size = stream.read_uint32();
    size_t pos = fp.tell();

    bool is_wav = type == WAV;
    SoundData * data;
    if ((is_wav && size <= WAV_STREAM_THRESHOLD) ||
        (!is_wav && size <= OGG_STREAM_THRESHOLD))
    {
#ifdef CHOWDREN_IS_3DS
        data = new SoundMemory(id, fp, type, size);
#else
        unsigned char * sound_data = new unsigned char[size];
        fp.read(sound_data, size); 
        data = new SoundMemory(id, sound_data, type, size);
        delete[] sound_data;
#endif
    } else {
        data = new SoundCache(id, fp.tell(), type, size);
    }
    media.sounds[id] = data;
    fp.seek(pos + size);
}