Commit 37703804 authored by Marc Vef's avatar Marc Vef
Browse files

adafs_access() implemented, better documentation

parent f1c419f4
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -5,12 +5,14 @@
#include "access.h"

/**
 *
 * Checks access for mask (can be R_OK, W_OK, or R_OK | W_OK AFAIK and not verified) against metadata's mode.
 * First the mask is checked agains the 3 bits for the user, then for the 3 bits of the group, and lastly other.
 * If all three checks have failed, return -EACCESS (no access)
 * @param md
 * @param mode
 * @param mask
 * @return
 */
int chk_access(const Metadata& md, const int mode) {
int chk_access(const Metadata& md, const int mask) {
    ADAFS_DATA->logger->debug("chk_access() enter: metadata_uid {} fusecontext_uid {}", md.uid(),
                              fuse_get_context()->uid);
    // root user is a god
@@ -20,7 +22,7 @@ int chk_access(const Metadata& md, const int mode) {
    //check user leftmost 3 bits for rwx in md->mode
    if (md.uid() == fuse_get_context()->uid) {
        // Because mode comes only with the first 3 bits used, the user bits have to be shifted to the right to compare
        if ((mode & md.mode() >> 6) == (unsigned int) mode)
        if ((mask & md.mode() >> 6) == (unsigned int) mask)
            return 0;
        else
            return -EACCES;
@@ -28,7 +30,7 @@ int chk_access(const Metadata& md, const int mode) {

    //check group middle 3 bits for rwx in md->mode
    if (md.gid() == fuse_get_context()->gid) {
        if ((mode & md.mode() >> 3) == (unsigned int) mode)
        if ((mask & md.mode() >> 3) == (unsigned int) mask)
            return 0;
        else
            return -EACCES;
@@ -36,7 +38,7 @@ int chk_access(const Metadata& md, const int mode) {

    //check other rightmost 3 bits for rwx in md->mode.
    // Because they are the rightmost bits they don't need to be shifted
    if ((mode & md.mode()) == (unsigned int) mode) {
    if ((mask & md.mode()) == (unsigned int) mask) {
        return 0;
    }

+1 −1
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@
#include "../classes/metadata.h"


int chk_access(const Metadata& md, const int mode);
int chk_access(const Metadata& md, const int mask);


#endif //FS_ACCESS_H
+10 −3
Original line number Diff line number Diff line
@@ -4,6 +4,8 @@

#include "../main.h"
#include "../fuse_ops.h"
#include "../adafs_ops/metadata_ops.h"
#include "../adafs_ops/access.h"

using namespace std;

@@ -17,8 +19,13 @@ using namespace std;
 * This method is not called under Linux kernel versions 2.4.x
 */
int adafs_access(const char* p, int mask) {
    ADAFS_DATA->logger->info("##### FUSE FUNC ###### adafs_access() enter: name '{}' mask {}", p, mask);
    // XXX To be implemented for rm
    return 0;
    ADAFS_DATA->logger->debug("##### FUSE FUNC ###### adafs_access() enter: name '{}' mask {}", p, mask);
    auto path = bfs::path(p);

    auto md = make_shared<Metadata>();
    // XXX error handling
    get_metadata(*md, path);

    return chk_access(*md, mask);
}