Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Readonly to dav open #351

Merged
merged 4 commits into from
Apr 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/fusedav.c
Original file line number Diff line number Diff line change
Expand Up @@ -1557,10 +1557,28 @@ static void do_open(const char *path, struct fuse_file_info *info, GError **gerr
return;
}

static bool write_flag(int flags) {
// O_RDWR technically belongs in the list, but since it might be used for files
// which are only read, I leave it out.
// O_CREAT on a file which already exists is a noop unless O_EXCL is also included.
// So, only respond if both are present.
if ((flags & O_WRONLY) || ((flags & O_CREAT) && (flags & O_EXCL)) || (flags & O_TRUNC) || (flags & O_APPEND)) {
return true;
}
return false;
}

static int dav_open(const char *path, struct fuse_file_info *info) {
struct fusedav_config *config = fuse_get_context()->private_data;
GError *gerr = NULL;

// If we are in readonly mode, and we are opening a file for writing, exit
if (use_readonly_mode() && write_flag(info->flags)) {
log_print(LOG_WARNING, SECTION_FUSEDAV_FILE, "dav_flush: %s aborted; in readonly mode", path ? path : "null path");
g_set_error(&gerr, fusedav_quark(), EROFS, "aborted; in readonly mode");
return processed_gerror("dav_flush: ", path, &gerr);
}

BUMP(dav_open);

if (config->grace && use_saint_mode() && ((info->flags & O_TRUNC) || (info->flags & O_APPEND))) {
Expand All @@ -1576,7 +1594,7 @@ static int dav_open(const char *path, struct fuse_file_info *info) {
info->flags |= O_RDWR;
}

log_print(LOG_INFO, SECTION_FUSEDAV_FILE, "CALLBACK: dav_open: open(%s, %x, trunc=%x)", path, info->flags, info->flags & O_TRUNC);
log_print(LOG_INFO, SECTION_FUSEDAV_FILE, "CALLBACK: dav_open: open(%s, %o, trunc=%x)", path, info->flags, info->flags & O_TRUNC);
do_open(path, info, &gerr);
if (gerr) {
int ret = processed_gerror("dav_open: ", path, &gerr);
Expand Down
2 changes: 1 addition & 1 deletion tests/readrecursive.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static int readdirectory(char *dirname, int *dirsread, int *filesread, int *erro
else {
int bytes_read;
char rbuf [1025];
fd = open(fn, O_RDWR);
fd = open(fn, O_RDONLY);
v_printf("file: %s\n", fn);
++*filesread;
bytes_read = read(fd, rbuf, 1024);
Expand Down