Plan 9 from Bell Labs’s /usr/web/sources/contrib/de0u/root/sys/src/cmd/divergefs/filedirrule.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include <u.h>
#include <libc.h>
#include <fcall.h>
#include <String.h>
#include "common.h"
#include "debug.h"
#include "utils.h"
#include "rule.h"
#include "filedirrule.h"

enum { DEBUG_FILEDIRRULE = false };

bool filedirrule_contains(Rule *rule, char *path, int, ulong perm)
{
  bool (*contains)(FileDirRule *, char *);
  FileDirRule *self = (FileDirRule *)rule;
  NOISE(DEBUG_FILEDIRRULE, 
    "entering filedirrule_contains %s with path: %s perm: %ul",
    self->name, path, perm);

  if(perm_isdir(perm))
  {
    NOISE(DEBUG_FILEDIRRULE, 
      "filedirrule_contains checking directory: %s", path);
  }
  else
  {
    NOISE(DEBUG_FILEDIRRULE, 
      "filedirrule_contains checking file: %s", path);
  }

  contains = perm_isdir(perm) ? 
    self->fdops->contains_dir : self->fdops->contains_file;
  return contains(self, path);
}

bool filedirrule_contains_true(FileDirRule *, char *)
{
  return true;
}

bool filedirrule_contains_false(FileDirRule *, char *)
{
  return false;
}

static bool filedirrule_contains_file(FileDirRule *self, char *path)
{
  assert_valid(self->fdops);
  assert_valid(self->fdops->contains_file);
  return self->fdops->contains_file(self, path);
}

static bool filedirrule_contains_dir(FileDirRule *self, char *path)
{
  assert_valid(self->fdops);
  assert_valid(self->fdops->contains_dir);
  return self->fdops->contains_dir(self, path);
}

bool filedirrule_file_issatisfy(Rule *rule, char *path, Dir *d)
{
  FileDirRule *self = (FileDirRule *)rule;
  NOISE(DEBUG_FILEDIRRULE, "entering filedirrule_file_issatisfy %s", 
    self->name);
  return qid_isdir(&(d->qid)) || filedirrule_contains_file(self, path);
}

bool filedirrule_dir_issatisfy(Rule *rule, char *path, Dir *d)
{
  FileDirRule *self = (FileDirRule *)rule;
  NOISE(DEBUG_FILEDIRRULE, "entering filedirrule_dir_issatisfy %s", self->name);
  return !qid_isdir(&(d->qid)) || filedirrule_contains_dir(self, path);
}

bool filedirrule_file_dir_issatisfy(Rule *rule, char *path, Dir *d)
{
  FileDirRule *self = (FileDirRule *)rule;
  NOISE(DEBUG_FILEDIRRULE, "entering filedirrule_file_dir_issatisfy %s",
      self->name);
  if(qid_isdir(&(d->qid)))
  {
    return filedirrule_contains_dir(self, path);
  }
  return filedirrule_contains_file(self, path);
}



Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.