Skip to content

Commit

Permalink
Merge branch 'toccfs-writable' of https://github.com/aidin36/tocc int…
Browse files Browse the repository at this point in the history
…o toccfs-writable
  • Loading branch information
aidin36 committed Nov 28, 2014
2 parents 343d145 + b537c4b commit 92d6bc0
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 10 deletions.
11 changes: 11 additions & 0 deletions toccfs/src/engine/fs_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ namespace toccfs
std::vector<std::string>::iterator path_items_iterator = path_items.begin();
for (; path_items_iterator != path_items.end(); path_items_iterator++)
{
if (*path_items_iterator == ".." || *path_items_iterator == ".")
{
// Ignore . or ..
continue;
}
libtocc::Tag tag_expr(path_items_iterator->c_str());
main_and.add(tag_expr);
}
Expand Down Expand Up @@ -128,6 +133,12 @@ namespace toccfs

for (; path_items_iterator != path_items.end(); path_items_iterator++)
{
if (*path_items_iterator == ".." || *path_items_iterator == ".")
{
// Ignore . or ..
continue;
}

libtocc::Tag tag_expr(path_items_iterator->c_str());
third_main_and.add(tag_expr);
}
Expand Down
100 changes: 90 additions & 10 deletions toccfs/src/fuse/fuse_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
#include "fuse/fuse_interface.h"

#include <errno.h>
#include <unistd.h> // pread, open
#include <sys/statvfs.h> // statvfs
#include <unistd.h>
#include <sys/statvfs.h>
#include <sys/types.h>
#include <vector>
#include <cstring>
#include <string>
Expand Down Expand Up @@ -318,27 +319,106 @@ namespace toccfs

int toccfs_fuse_chmod(const char* path, mode_t mode)
{
// Returning `Read-only File System' error.
return -EROFS;
int result;
struct FSHandler* fs_handler = get_fs_handler();

// Getting the file that matches this path.
libtocc::FileInfo founded_file = fs_handler->get_by_path(path);

// If no file found, return an error.
if (strcmp(founded_file.get_id(), "-1") == 0)
{
return -ENOENT;
}

result = chmod(founded_file.get_physical_path(), mode);
if (result == -1)
{
return -errno;
}

return 0;
}

int toccfs_fuse_chown(const char* path, uid_t uid, gid_t gid)
{
// Returning `Read-only File System' error.
return -EROFS;
int result;
struct FSHandler* fs_handler = get_fs_handler();

// Getting the file that matches this path.
libtocc::FileInfo founded_file = fs_handler->get_by_path(path);

// If no file found, return an error.
if (strcmp(founded_file.get_id(), "-1") == 0)
{
return -ENOENT;
}

result = lchown(founded_file.get_physical_path(), uid, gid);
if (result == -1)
{
return -errno;
}

return 0;
}

int toccfs_fuse_truncate(const char* path, off_t size)
{
// Returning `Read-only File System' error.
return -EROFS;
int result;
struct FSHandler* fs_handler = get_fs_handler();

// Getting the file that matches this path.
libtocc::FileInfo founded_file = fs_handler->get_by_path(path);

// If no file found, return an error.
if (strcmp(founded_file.get_id(), "-1") == 0)
{
return -ENOENT;
}

result = truncate(founded_file.get_physical_path(), size);
if (result == -1)
{
return -errno;
}

return 0;
}

int toccfs_fuse_write(const char* path, const char* buf, size_t size,
off_t offset, struct fuse_file_info* fi)
{
// Returning `Read-only File System' error.
return -EROFS;
int file_descriptor;
int result;
struct FSHandler* fs_handler = get_fs_handler();

// Getting the file that matches this path.
libtocc::FileInfo founded_file = fs_handler->get_by_path(path);

// If no file found, return an error.
if (strcmp(founded_file.get_id(), "-1") == 0)
{
return -ENOENT;
}

// Openning physical file for writing.
file_descriptor = open(founded_file.get_physical_path(),
O_WRONLY);
if (file_descriptor == -1)
{
return -errno;
}

// Writing buffer to file.
result = pwrite(file_descriptor, buf, size, offset);
if (result == -1)
{
return -errno;
}

close(file_descriptor);
return result;
}

}

0 comments on commit 92d6bc0

Please sign in to comment.