00001 /* Part of the culibs project, <http://www.eideticdew.org/culibs/>. 00002 * Copyright (C) 2004--2007 Petter Urkedal <urkedal@nbi.dk> 00003 * 00004 * This program is free software: you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation, either version 3 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00018 #ifndef CUOS_FS_H 00019 #define CUOS_FS_H 00020 00021 #include <cucon/fwd.h> 00022 #include <cu/clos.h> 00023 #include <sys/types.h> 00024 00025 CU_BEGIN_DECLARATIONS 00026 /** \defgroup cuos_fs cuos/fs.h: File System 00027 ** @{ \ingroup cuos_mod 00028 ** 00029 ** These functions probes or manipulates the file system and related metadata. 00030 ** \see cuos_path_h "cuos/path.h" for manipulating file paths. 00031 ** \see cuos_file_h "cuos/file.h" for accessing regular files. 00032 **/ 00033 00034 /*!Catogorisation of files, directories, special files. */ 00035 typedef enum { 00036 cuos_dentry_type_none, /*!< a null value */ 00037 cuos_dentry_type_file, /*!< a normal file */ 00038 cuos_dentry_type_dir, /*!< a directory */ 00039 cuos_dentry_type_char_dev, /*!< a character device special file */ 00040 cuos_dentry_type_block_dev, /*!< a block device special file */ 00041 cuos_dentry_type_fifo, /*!< a first-in first-out pipe */ 00042 cuos_dentry_type_symlink, /*!< a symbolic link */ 00043 cuos_dentry_type_socket, /*!< a socket special file */ 00044 cuos_dentry_type_unknown /*!< undetectable or unknown file type */ 00045 } cuos_dentry_type_t; 00046 00047 /** The directory entry type of \a path as on the file system. */ 00048 cuos_dentry_type_t cuos_dentry_type(cu_str_t path); 00049 00050 /** True iff \a path names a detectable directory entry on the local file 00051 ** system, and it is not a broken symbolic link. */ 00052 cu_bool_t cuos_have_dentry(cu_str_t path); 00053 00054 /** True iff \a path names a detectable directory or link to such on the local 00055 ** file system. */ 00056 cu_bool_t cuos_have_dir(cu_str_t path); 00057 00058 /** True iff \a path names a detectable regular file or link to such on the 00059 ** local file system. */ 00060 cu_bool_t cuos_have_file(cu_str_t path); 00061 00062 /** True iff \a path names a detectable symbolic link on the local file system. 00063 ** Returns true also for broken symbolic links. */ 00064 cu_bool_t cuos_have_link(cu_str_t path); 00065 00066 /** Return the modification time of \a path, or 0 if \a path does not exist. 00067 ** On other errors, write an error message and return 0. */ 00068 time_t cuos_mtime(cu_str_t path); 00069 00070 /** Create all missing components of \a path and \a path itself as a 00071 ** directory. */ 00072 cu_bool_t cuos_mkdir_rec(cu_str_t path, mode_t mode); 00073 00074 /*!Removes \a path, and if it is a directory, descends and removes all 00075 * files and subdirectories recursively. 00076 * \warning This may wipe out all your files if used carelessly. Make 00077 * sure you carefully control the argument passed to this function. */ 00078 cu_bool_t cuos_remove_rec(cu_str_t path); 00079 00080 /*!Run \code cu_call(cb, path)\endcode on each \e path which is \a dname or 00081 * a subdirectory or file under \a dname, using depth-first with no specific 00082 * ordering within each directory. */ 00083 cu_bool_t cuos_dirrec_conj_files(cu_str_t dname, 00084 cu_clop(cb, cu_bool_t, cu_str_t)); 00085 00086 /*!Run \code cu_call(cb, path)\endcode on each \e path which is \a dname or 00087 * a subdirectory or file under \a dname, using a depth-first with collating 00088 * order of file names within each directory. */ 00089 cu_bool_t cuos_dirreccoll_conj_files(cu_str_t dname, 00090 cu_clop(cb, cu_bool_t, cu_str_t)); 00091 00092 /** \deprecated Use \ref cuos_dirpile. */ 00093 cu_bool_t 00094 cuos_prefixsearch_conj(cucon_list_t prefixlist, cu_str_t suffix, 00095 cu_clop(cb, cu_bool_t, cu_str_t result)); 00096 00097 /** \deprecated Use \ref cuos_dirpile. */ 00098 cu_str_t cuos_prefixsearch_first(cucon_list_t prefixlist, cu_str_t suffix); 00099 00100 /** \deprecated Use \ref cuos_dirpile. */ 00101 void cuos_prefixsearch_append_all(cucon_list_t prefixlist, cu_str_t suffix, 00102 cucon_list_t result); 00103 00104 /** Returns a temporary directory for the current process, which will be erased 00105 ** at exit. */ 00106 cu_str_t cuos_tmp_dir(void); 00107 00108 /*!A directory to load and store the state of an interactive application. 00109 * Before using this function, you must set the application name, e.g. by 00110 * calling \ref cu_set_application_name. The session directory will typically 00111 * be <tt>$HOME/.\e appname</tt>. If mode is zero and the directory does not 00112 * exist, \c NULL is returned. If mode is non-zero and the directory does not 00113 * exist, the directory will be created with that mode (permissions). */ 00114 cu_str_t cuos_session_dir(mode_t mode); 00115 00116 /** @} */ 00117 CU_END_DECLARATIONS 00118 00119 #endif