gnunet-fuse.h (6065B)
1 /* 2 This file is part of gnunet-fuse. 3 Copyright (C) 2012 GNUnet e.V. 4 5 gnunet-fuse is free software; you can redistribute it and/or 6 modify if under the terms of version 2 of the GNU General Public License 7 as published by the Free Software Foundation. 8 9 gnunet-fuse is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, write to the Free Software 16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 18 */ 19 /** 20 * @file fuse/gnunet-fuse.h 21 * @brief global definitions for gnunet-fuse 22 * @author Christian Grothoff 23 * @author Mauricio Günther 24 */ 25 #ifndef GNUNET_FUSE_H 26 #define GNUNET_FUSE_H 27 28 #include <stdio.h> 29 #include <sys/ioctl.h> 30 #include <sys/wait.h> 31 #include <errno.h> 32 #include <signal.h> 33 #include <unistd.h> 34 #include <gnunet/gnunet_util_lib.h> 35 #include <gnunet/gnunet_resolver_service.h> 36 #include <gnunet/gnunet_fs_service.h> 37 #include "gettext.h" 38 39 #define _(String) dgettext (PACKAGE, String) 40 41 42 #define FUSE_USE_VERSION 26 43 #include <fuse.h> 44 #include "mutex.h" 45 46 47 /** 48 * Anonymity level to use. 49 */ 50 extern unsigned int anonymity_level; 51 52 /** 53 * Configuration to use. 54 */ 55 extern const struct GNUNET_CONFIGURATION_Handle *cfg; 56 57 58 /** 59 * struct containing mapped Path, with URI and other Information like Attributes etc. 60 */ 61 struct GNUNET_FUSE_PathInfo 62 { 63 64 /** 65 * All files in a directory are kept in a DLL. 66 */ 67 struct GNUNET_FUSE_PathInfo *next; 68 69 /** 70 * All files in a directory are kept in a DLL. 71 */ 72 struct GNUNET_FUSE_PathInfo *prev; 73 74 /** 75 * Parent directory, NULL for the root. 76 */ 77 struct GNUNET_FUSE_PathInfo *parent; 78 79 /** 80 * Head of linked list of entries in this directory 81 * (NULL if this is a file). 82 */ 83 struct GNUNET_FUSE_PathInfo *child_head; 84 85 /** 86 * Head of linked list of entries in this directory 87 * (NULL if this is a file). 88 */ 89 struct GNUNET_FUSE_PathInfo *child_tail; 90 91 /** 92 * URI of the file or directory. 93 */ 94 struct GNUNET_FS_Uri *uri; 95 96 /** 97 * meta data to corresponding path (can be NULL) 98 */ 99 struct GNUNET_FS_MetaData *meta; 100 101 /** 102 * Name of the file for this path (i.e. "home"). '/' for the root (all other 103 * filenames must not contain '/') 104 */ 105 char *filename; 106 107 /** 108 * Name of temporary file, NULL if we never accessed this file or directory. 109 */ 110 char *tmpfile; 111 112 /** 113 * file attributes 114 */ 115 struct stat stbuf; 116 117 /** 118 * Lock for exclusive access to this struct (i.e. for downloading blocks). 119 * Lock order: always lock parents before children. 120 */ 121 struct GNUNET_Mutex *lock; 122 123 /** 124 * Beginning of a contiguous range of blocks of the file what we 125 * have downloaded already to 'tmpfile'. 126 */ 127 uint64_t download_start; 128 129 /** 130 * End of a contiguous range of blocks of the file what we 131 * have downloaded already to 'tmpfile'. 132 */ 133 uint64_t download_end; 134 135 /** 136 * Reference counter (used if the file is deleted while being opened, etc.) 137 */ 138 unsigned int rc; 139 140 /** 141 * Should the file be deleted after the RC hits zero? 142 */ 143 int delete_later; 144 }; 145 146 147 /** 148 * Create a new path info entry in the global map. 149 * 150 * @param parent parent directory (can be NULL) 151 * @param filename name of the file to create 152 * @param uri URI to use for the path 153 * @param is_directory GNUNET_YES if this entry is for a directory 154 * @return existing path entry if one already exists, otherwise 155 * new path entry with the desired URI; in both cases 156 * the reference counter has been incremented by 1 157 */ 158 struct GNUNET_FUSE_PathInfo * 159 GNUNET_FUSE_path_info_create (struct GNUNET_FUSE_PathInfo *parent, 160 const char *filename, 161 const struct GNUNET_FS_Uri *uri, 162 int is_directory); 163 164 165 /** 166 * Obtain an existing path info entry from the global map. 167 * 168 * @param path path the entry represents 169 * @param eno where to store 'errno' on errors 170 * @return NULL if no such path entry exists, otherwise 171 * an entry with incremented reference counter (!) 172 */ 173 struct GNUNET_FUSE_PathInfo * 174 GNUNET_FUSE_path_info_get (const char *path, 175 int *eno); 176 177 178 /** 179 * Reduce the reference counter of a path info entry. 180 * 181 * @param pi entry to decrement the RC of 182 */ 183 void 184 GNUNET_FUSE_path_info_done (struct GNUNET_FUSE_PathInfo *pi); 185 186 187 /** 188 * Delete a path info entry from the global map (does not actually 189 * remove anything from the file system). Also decrements the RC. 190 * 191 * @param pi entry to remove 192 * @return - ENOENT if the file was already deleted, 0 on success 193 */ 194 int 195 GNUNET_FUSE_path_info_delete (struct GNUNET_FUSE_PathInfo *pi); 196 197 198 /** 199 * Load and parse a directory. 200 * 201 * @param pi path to the directory 202 * @param eno where to store 'errno' on errors 203 * @return GNUNET_OK on success 204 */ 205 int 206 GNUNET_FUSE_load_directory (struct GNUNET_FUSE_PathInfo *pi, 207 int *eno); 208 209 210 /* FUSE function files */ 211 int gn_getattr (const char *path, struct stat *stbuf); 212 213 int gn_open (const char *path, struct fuse_file_info *fi); 214 215 int gn_read (const char *path, char *buf, size_t size, off_t offset, 216 struct fuse_file_info *fi); 217 218 int gn_readdir (const char *path, void *buf, fuse_fill_dir_t filler, 219 off_t offset, struct fuse_file_info *fi); 220 221 222 int gn_mknod (const char *path, mode_t mode, dev_t rdev); 223 224 int gn_mkdir (const char *path, mode_t mode); 225 226 int gn_unlink (const char *path); 227 228 int gn_rmdir (const char *path); 229 230 int gn_rename (const char *from, const char *to); 231 232 int gn_truncate (const char *path, off_t size); 233 234 int gn_write (const char *path, const char *buf, size_t size, off_t offset, 235 struct fuse_file_info *fi); 236 237 int gn_release (const char *path, struct fuse_file_info *fi); 238 239 int gn_utimens (const char *path, const struct timespec ts[2]); 240 241 242 #endif 243 /* GNUNET_FUSE_H */