summaryrefslogtreecommitdiff
path: root/lnode.h
blob: f5a50f79e143c79fbbd879bff4fe9a31b7eb9ea1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* Hurd unionfs
   Copyright (C) 2001, 2002 Free Software Foundation, Inc.
   Written by Moritz Schulte <moritz@duesseldorf.ccc.de>.

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or * (at your option) any later version.
 
   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.
 
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
   USA.  */

/* `light node' management.  */

#ifndef INCLUDED_LNODE_H
#define INCLUDED_LNODE_H

#include <pthread.h>
#include <error.h>

struct lnode
{
  char *name;			/* The name of this light node.  */
  int name_len;			/* This is used quite often and since
				   NAME does not change, just
				   calculate it once.  */
  int flags;			/* Associated flags.  */
  int references;		/* References to this light node.  */
  struct node *node;	        /* Reference to the real node.  */
  struct lnode *next, **prevp;	/* Light nodes are connected in a
				   linked list.  */
  struct lnode *dir;		/* The light node this light node is
				   contained int.  */
  struct lnode *entries;	/* A reference to the list containing
				   the entries of this light node.  */
  pthread_mutex_t lock;		/* A lock.  */
};
typedef struct lnode lnode_t;

/* Create a new light node as an entry with the name NAME and store it
   in *NODE.  The new node is not locked and contains a single
   reference.  */
error_t lnode_create (char *name, lnode_t **node);

/* Destroy a light node.  */
void lnode_destroy (lnode_t *node);

/* Install the node in the node tree; add a reference to DIR.  */
void lnode_install (lnode_t *dir, lnode_t *node);

/* Uninstall the node from the node tree; remove a reference from the
   lnode containing NODE.  */
void lnode_uninstall (lnode_t *node);

/* Add a reference to NODE, which must be locked.  */
void lnode_ref_add (lnode_t *node);

/* Remove a reference to NODE, which must be locked.  If that was the
   last reference, destroy the node, otherwise simply unlock NODE.  */
void lnode_ref_remove (lnode_t *node);

/* Get a light node by it's name.  The looked up node is locked and
   got one reference added.  */
error_t lnode_get (lnode_t *dir, char *name,
		   lnode_t **node);

/* Construct the full path for a given light node.  */
error_t lnode_path_construct (lnode_t *node, char **path);

#endif