| Index: ppapi/examples/filesystem_provider/inode.cc
|
| diff --git a/ppapi/examples/filesystem_provider/inode.cc b/ppapi/examples/filesystem_provider/inode.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..0304edec25282a0fdfe27a176fcae5bc38fb03b5
|
| --- /dev/null
|
| +++ b/ppapi/examples/filesystem_provider/inode.cc
|
| @@ -0,0 +1,196 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +
|
| +#include <ctime>
|
| +#include <iostream>
|
| +#include <vector>
|
| +
|
| +#include "inode.h"
|
| +#include "memfilesystem.h"
|
| +
|
| +namespace filesystem{
|
| +
|
| +Inode::Inode(
|
| + unsigned long long appointed_inode, int file_type,
|
| + const std::string& inode_modified,const std::string& file_modified,
|
| + const std::string& file_access)
|
| + : inode_number_(appointed_inode),
|
| + file_type_(file_type) {
|
| + set_inode_modified(inode_modified);
|
| + set_file_modified(file_modified);
|
| + set_file_access(file_access);
|
| +}
|
| +
|
| +Inode::~Inode(){
|
| +}
|
| +
|
| +void Inode::set_inode_number(unsigned long long appointed_inode) {
|
| + inode_number_ = appointed_inode;
|
| +}
|
| +
|
| +unsigned long long Inode::inode_number() const {
|
| + return inode_number_;
|
| +}
|
| +
|
| +void Inode::set_file_type(int file_type){
|
| + switch (file_type) {
|
| + case FILE_TYPE_FILE:
|
| + case FILE_TYPE_DIR:
|
| + file_type_ = file_type;
|
| + break;
|
| + default:
|
| + file_type_ = FILE_TYPE_UNKNOWN;
|
| + break;
|
| + }
|
| +}
|
| +
|
| +int Inode::file_type() const {
|
| + return file_type_;
|
| +}
|
| +
|
| +void Inode::set_file_access(const std::string& file_access) {
|
| + if (file_access.size()== 0)
|
| + file_access_=Inode::CurentTime();
|
| + else
|
| + file_access_=file_access;
|
| +}
|
| +
|
| +std::string Inode::file_access() const {
|
| + return file_access_;
|
| +}
|
| +
|
| +void Inode::set_file_modified(const std::string& file_modified) {
|
| + if (file_modified.size()== 0)
|
| + file_modified_=Inode::CurentTime();
|
| + else
|
| + file_modified_=file_modified;
|
| +}
|
| +
|
| +std::string Inode::file_modified() const {
|
| + return file_modified_;
|
| +}
|
| +
|
| +void Inode::set_inode_modified(const std::string& inode_modified) {
|
| + if (inode_modified.size() == 0)
|
| + inode_modified_=Inode::CurentTime();
|
| + else
|
| + inode_modified_=inode_modified;
|
| +}
|
| +
|
| +std::string Inode::inode_modified() const {
|
| + return inode_modified_;
|
| +}
|
| +
|
| +std::string Inode::CurentTime(){
|
| + time_t rawtime;
|
| + struct tm * timeinfo;
|
| + char buffer[80];
|
| +
|
| + time(&rawtime);
|
| + timeinfo = localtime(&rawtime);
|
| +
|
| + strftime(buffer, 80, "%d-%m-%Y %I:%M:%S", timeinfo);
|
| + std::string str(buffer);
|
| + return str;
|
| +}
|
| +
|
| +InodeFile::InodeFile(
|
| + unsigned long long appointed_inode,
|
| + std::string inode_modified, std::string file_modified,
|
| + std::string file_access)
|
| + :Inode(
|
| + appointed_inode,Inode::FILE_TYPE_FILE,
|
| + inode_modified,
|
| + file_modified,
|
| + file_access){
|
| +}
|
| +
|
| +InodeFile::~InodeFile(){
|
| +}
|
| +
|
| +bool InodeFile::Truncate(const size_t length) {
|
| + if( data_.size()<length)
|
| + return false;
|
| + data_.resize( length );
|
| + return true;
|
| +}
|
| +
|
| +bool InodeFile::Write(const char *data, uint64_t offset, uint64_t dataSize) {
|
| + if(data==nullptr&&
|
| + dataSize>0)
|
| + return false;
|
| + if(offset>data_.size())
|
| + return false;
|
| + data_.insert( offset, data, dataSize );
|
| + return true;
|
| +}
|
| +
|
| +bool InodeFile::Read(
|
| + size_t offset,
|
| + size_t* inOutLen,
|
| + const char** outData) const {
|
| + if(inOutLen==nullptr ||
|
| + offset>data_.size())
|
| + return false;
|
| + *inOutLen = offset + *inOutLen < data_.size() ?
|
| + *inOutLen : data_.size() - offset;
|
| + *outData = data_.c_str()+ offset;
|
| + return true;
|
| +}
|
| +
|
| +unsigned long long InodeDirectory::GetInodeFromName(const std::string& name) {
|
| + ListOfEntriesIterator it = entries_.find(name);
|
| + if (it != entries_.end())
|
| + return it->second;
|
| + return Inode::NO_INODE;
|
| +}
|
| +
|
| +void InodeDirectory::AddEntry(
|
| + const std::string& name, unsigned long long inode) {
|
| + entries_.insert(std::pair<std::string, unsigned long long>(name, inode));
|
| + // Tell the BookKeeper to add a reference
|
| + if (book_keeper_)
|
| + book_keeper_->AddLink(inode);
|
| +}
|
| +
|
| +void InodeDirectory::DeleteEntry(
|
| + const std::string& name, unsigned long long inode) {
|
| + ListOfEntriesIterator it = entries_.find(name);
|
| + if (it != entries_.end() &&
|
| + it->second == inode) {
|
| + entries_.erase(it);
|
| + // Ask the BookKeeper to delete
|
| + if (book_keeper_)
|
| + book_keeper_->RemoveLink(inode);
|
| + }
|
| +}
|
| +
|
| +void InodeDirectory::GetAllInodes(std::vector<EntryPair>& inodes) {
|
| + for (ListOfEntriesIterator it(entries_.begin());
|
| + it != entries_.end(); ++it) {
|
| + inodes.push_back(EntryPair(it->first, it->second));
|
| + }
|
| +}
|
| +
|
| +InodeDirectory::InodeDirectory(
|
| + BookKeeper* bookKeeper,
|
| + unsigned long long appointed_inode,
|
| + std::string inode_modified,
|
| + std::string file_modified,
|
| + std::string file_access)
|
| + :Inode(
|
| + appointed_inode,
|
| + Inode::FILE_TYPE_DIR,
|
| + inode_modified,
|
| + file_modified,
|
| + file_access),
|
| + book_keeper_(bookKeeper) {
|
| +}
|
| +
|
| +
|
| +InodeDirectory::~InodeDirectory(){
|
| +}
|
| +
|
| +}//namespace filesystem
|
|
|