readdir.c (2581B)
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 modify 6 it under the terms of the GNU General Public License as published 7 by the Free Software Foundation; either version 3, or (at your 8 option) any later version. 9 10 gnunet-fuse is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 19 */ 20 /* 21 * readdir.c - FUSE read directory function 22 * 23 * Created on: Mar 14, 2012 24 * Author: MG, Christian Grothoff, Matthias Wachs, 25 * Krista Bennett, James Blackwell, Igor Wronsky 26 * 27 * Read directory 28 * 29 * This supersedes the old getdir() interface. New applications 30 * should use this. 31 * 32 * The filesystem may choose between two modes of operation: 33 * 34 * 1) The readdir implementation ignores the offset parameter, and 35 * passes zero to the filler function's offset. The filler 36 * function will not return '1' (unless an error happens), so the 37 * whole directory is read in a single readdir operation. This 38 * works just like the old getdir() method. 39 * 40 * 2) The readdir implementation keeps track of the offsets of the 41 * directory entries. It uses the offset parameter and always 42 * passes non-zero offset to the filler function. When the buffer 43 * is full (or an error happens) the filler function will return 44 * '1'. 45 * 46 * Introduced in version 2.3 47 */ 48 /** 49 * @file fuse/readdir.c 50 * @brief readdir of fuse 51 * @author Christian Grothoff 52 */ 53 #include "gnunet-fuse.h" 54 #include "gfs_download.h" 55 56 57 int 58 gn_readdir (const char *path, void *buf, fuse_fill_dir_t filler, 59 off_t offset, struct fuse_file_info *fi) 60 { 61 struct GNUNET_FUSE_PathInfo *path_info; 62 struct GNUNET_FUSE_PathInfo *pos; 63 int eno; 64 65 path_info = GNUNET_FUSE_path_info_get (path, &eno); 66 if (NULL == path_info) 67 return - eno; 68 if ( (NULL == path_info->tmpfile) && 69 (GNUNET_OK != GNUNET_FUSE_load_directory (path_info, &eno)) ) 70 return - eno; 71 filler (buf, ".", NULL, 0); 72 filler (buf, "..", NULL, 0); 73 for (pos = path_info->child_head; NULL != pos; pos = pos->next) 74 filler (buf, pos->filename, 75 &pos->stbuf, 76 0); 77 GNUNET_FUSE_path_info_done (path_info); 78 return 0; 79 } 80 81 /* end of readdir.c */