aboutsummaryrefslogtreecommitdiff
path: root/src/fuse/gnunet-fuse.h
blob: d8f567b6d4b5c32686684c4768d47ba38649505d (plain) (blame)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
  This file is part of gnunet-fuse.
  (C) 2012 Christian Grothoff (and other contributing authors)
  
  gnunet-fuse is free software; you can redistribute it and/or
  modify if under the terms of version 2 of the GNU General Public License
  as published by the Free Software Foundation.
 
  gnunet-fuse 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

*/
/**
 * @file fuse/gnunet-fuse.h
 * @brief global definitions for gnunet-fuse
 * @author Christian Grothoff
 * @author Mauricio Günther
 */
#ifndef GNUNET_FUSE_H
#define GNUNET_FUSE_H

#include <gnunet/platform.h>
#include <gnunet/gnunet_util_lib.h>
#include <gnunet/gnunet_directories.h>
#include <gnunet/gnunet_resolver_service.h>
#include <gnunet/gnunet_fs_service.h>

#define FUSE_USE_VERSION 26
#include <fuse.h>
#include "mutex.h"


/**
 * Anonymity level to use.
 */
extern unsigned int anonymity_level;

/**
 * Configuration to use.
 */
extern const struct GNUNET_CONFIGURATION_Handle *cfg;


/**
 * struct containing mapped Path, with URI and other Information like Attributes etc. 
 */
struct GNUNET_FUSE_PathInfo
{
  /**
   * uri to corresponding path 
   */
  struct GNUNET_FS_Uri *uri;

  /**
   * meta data to corresponding path (can be NULL)
   */
  struct GNUNET_CONTAINER_MetaData *meta;

  /**
   * pathname 
   */
  char* path;

  /**
   * name of temporary file 
   */
  char* tmpfile;
  
  /**
   * file attributes
   */
  struct stat stbuf;
  
  /**
   * Lock for exclusive access to this struct.
   */ 
  struct GNUNET_Mutex *lock;

  /**
   * Reference counter.
   */
  unsigned int rc;

  /**
   * Should the file be deleted after the RC hits zero?
   */
  int delete_later;
};


/**
 * Create a new path info entry in the global map.
 *
 * @param path path the entry represents
 * @param uri URI to use for the path
 * @param is_directory GNUNET_YES if this entry is for a directory
 * @return existing path entry if one already exists, otherwise
 *         new path entry with the desired URI; in both cases
 *         the reference counter has been incremented by 1
 */
struct GNUNET_FUSE_PathInfo *
GNUNET_FUSE_path_info_create (const char *path,
			      const struct GNUNET_FS_Uri *uri,
			      int is_directory);


/**
 * Obtain an existing path info entry from the global map.
 *
 * @param path path the entry represents
 * @return NULL if no such path entry exists, otherwise
 *  an entry with incremented reference counter (!)
 */
struct GNUNET_FUSE_PathInfo *
GNUNET_FUSE_path_info_get (const char *path);


/**
 * Reduce the reference counter of a path info entry.
 *
 * @param pi entry to decrement the RC of
 */
void
GNUNET_FUSE_path_info_done (struct GNUNET_FUSE_PathInfo *pi);


/**
 * Delete a path info entry from the global map (does not actually
 * remove anything from the file system).  Also decrements the RC.
 *
 * @param pi entry to remove
 * @return - ENOENT if the file was already deleted, 0 on success
 */
int
GNUNET_FUSE_path_info_delete (struct GNUNET_FUSE_PathInfo *pi);


/* FUSE function files */
int gn_getattr(const char *path, struct stat *stbuf);

int gn_mknod(const char *path, mode_t mode, dev_t rdev);

int gn_mkdir(const char *path, mode_t mode);

int gn_unlink(const char *path);

int gn_rmdir(const char *path);

int gn_rename(const char *from, const char *to);

int gn_truncate(const char *path, off_t size);

int gn_open(const char *path, struct fuse_file_info *fi);

int gn_read(const char *path, char *buf, size_t size, off_t offset,
	struct fuse_file_info *fi);

int gn_write(const char *path, const char *buf, size_t size, off_t offset,
	struct fuse_file_info *fi);

int gn_release(const char *path, struct fuse_file_info *fi);

int gn_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
	off_t offset, struct fuse_file_info *fi);

int gn_utimens(const char *path, const struct timespec ts[2]);


#endif
/* GNUNET_FUSE_H */