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

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



typedef struct Rule Rule;
#pragma incomplete Rule /* See 9fans "new compiler" 2005-01-07 */

typedef struct RuleOperations
{
  void (*free)(Rule *rule);
  bool (*issatisfy)(Rule *rule, char *path, Dir *d);
  bool (*contains)(Rule *rule, char *path, int omode, ulong perm);
} RuleOperations;

struct Rule
{
  RuleOperations *ops;
  char *root;
  char *name;
};

enum { RULE_MAXNAMELEN = 4096 };

/** destructor */
void rule_free(Rule *self);


/** @return the name that the rule represents for debugging purpose */
char *rule_name(Rule *self);

/** 
 * return dir struct representing the path if path points to an existing dir
 * or file that satisfies this rule.
 */
Dir *rule_find(Rule *self, char *path);

/**
 * same as rule_open_file except caller gets the corresponding Dir* which the
 * caller is responsible to free.
 */
int rule_satisfied_open_file(Rule *self, 
  char *path, int omode, Dir **satisfies);

/**
 * same as rule_open_dir except caller gets the corresponding Dir* which the
 * caller is responsible to free.
 */
int rule_satisfied_open_dir(Rule *self, char *path, int omode, Dir **satisfies);

/** 
 * attempts to open path as file if it exists and satisfies 
 * @return file descriptor that was opened.
 */
int rule_open_file(Rule *self, char *path, int omode);

/** 
 * attempts to open path as directory if it exists and satisfies
 * @return file descriptor that was opened.
 */
int rule_open_dir(Rule *self, char *path, int omode);

/** 
 * returns true if the path exists and is contained inside this rule, false
 * otherwise. 
 */
bool rule_exists(Rule *self, char *path);

/** returns true if the path satisfies this rule and false otherwise */ 
bool rule_contains(Rule *self, char *path, int omode, ulong perm);

/** attempts to create the file pointed to by path */
int rule_create(Rule *self, char *path, int omode, ulong perm);

/** 
 * attemps to remove path and returns true if remove was successful or if the
 * path is single file or empty dir.
 */
bool rule_remove(Rule *self, char *path);

/** sets the stat specified by d */
bool rule_set_stat(Rule *self, char *path, Dir *d);

/** @return true if self and rule has the same root path */
bool rule_same_path(Rule *self, Rule *other);

/** @return true if fullpath of this rule and target rule indicates same file */
bool rule_same_file(Rule *self, char *path, Rule *other, char *otherpath);

/** copies file from this rule to another rule with the new path */
bool rule_copy_file(Rule *self, char *path, 
  Rule *target, char *newpath, Dir *d);

/** 
 * private function that user should not use.
 * this function is not designed to be used outside of the rule hierarchy.
 * andrule and orrule use this.
 */
bool rule_issatisfy(Rule *self, char *path, Dir *d);


String *rule_assemble_path(Rule *self, char *path);

bool rule_contains_true(Rule *, char *, int, ulong);

/** generic issatisfy function that always return true */
bool rule_issatisfy_true(Rule *, char *, Dir *);

/** generic free operation that will just call free on self */
void rule_free_self(Rule *self);



Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].