1 /** 2 * @file libcomprex/file.h File structures 3 * 4 * $Id: file.h,v 1.32 2003/01/01 06:22:35 chipx86 Exp $ 5 * 6 * @Copyright (C) 2001-2003 The GNUpdate Project. 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Library General Public 10 * License as published by the Free Software Foundation; either 11 * version 2 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Library General Public License for more details. 17 * 18 * You should have received a copy of the GNU Library General Public 19 * License along with this library; if not, write to the 20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 21 * Boston, MA 02111-1307, USA. 22 */ 23 #ifndef _LIBCOMPREX_FILE_H_ 24 #define _LIBCOMPREX_FILE_H_ 25 26 #include <sys/types.h> 27 #include <time.h> 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 typedef struct _CxFsNode CxFile; /**< A single file. */ 34 typedef struct _CxFileData CxFileData; /**< File data. */ 35 36 #include <libcomprex/fsnode.h> 37 #include <libcomprex/archive.h> 38 #include <libcomprex/types.h> 39 40 /** 41 * The data specific to a file node. 42 */ 43 struct _CxFileData 44 { 45 /** 46 * The full physical path to the file. If the file 47 * is non-local, this will be a temporary filename. 48 */ 49 char *physPath; 50 51 unsigned int compressedSize; /**< The compressed file size. */ 52 unsigned int uncompressedSize; /**< The uncompressed file size. */ 53 }; 54 55 /**************************************************************************/ 56 /** @name Structure (De)allocation Functions */ 57 /**************************************************************************/ 58 /*@{*/ 59 60 /** 61 * Creates a new CxFile structure. 62 * 63 * @return A new, empty CxFile structure. 64 * 65 * @see cxDestroyFile() 66 */ 67 CxFile *cxNewFile(void); 68 69 /** 70 * Destroys a CxFile structure. 71 * 72 * @param file The CxFile to destroy. 73 * 74 * @see cxNewFile() 75 */ 76 void cxDestroyFile(CxFile *file); 77 78 /*@}*/ 79 80 /**************************************************************************/ 81 /** @name Attribute Modification Functions */ 82 /**************************************************************************/ 83 /*@{*/ 84 85 /** 86 * Sets the archive that owns the file. 87 * 88 * This should only be used by libcomprex. 89 * 90 * @param file The file. 91 * @param archive The archive that owns this file. 92 * 93 * @see cxGetFileArchive() 94 */ 95 void cxSetFileArchive(CxFile *file, CxArchive *archive); 96 97 /** 98 * Sets the specified file's parent directory. 99 * 100 * @param file The file. 101 * @param parent The parent directory. 102 * 103 * @see cxGetFileParent() 104 */ 105 void cxSetFileParent(CxFile *file, CxDirectory *parent); 106 107 /** 108 * Sets the base name of the specified file. 109 * 110 * @param file The file. 111 * @param name The filename. 112 * 113 * @see cxGetFileName() 114 */ 115 void cxSetFileName(CxFile *file, const char *name); 116 117 /** 118 * Sets the full physical path to the file. 119 * 120 * If the file is non-local, this should be a temporary file. 121 * 122 * @param file The file. 123 * @param path The physical path to the file. 124 * 125 * @see cxGetFilePhysicalPath() 126 * @see cxGetFilePath() 127 */ 128 void cxSetFilePhysicalPath(CxFile *file, const char *path); 129 130 /** 131 * Sets the mode of the specified file. 132 * 133 * @param file The file. 134 * @param mode The mode. 135 * 136 * @see cxGetFileMode() 137 */ 138 void cxSetFileMode(CxFile *file, mode_t mode); 139 140 /** 141 * Sets the user ID of the specified file. 142 * 143 * @param file The file. 144 * @param uid The user ID. 145 * 146 * @see cxGetFileUid() 147 */ 148 void cxSetFileUid(CxFile *file, uid_t uid); 149 150 /** 151 * Sets the group ID of the specified file. 152 * 153 * @param file The file. 154 * @param gid The group ID. 155 * 156 * @see cxGetFileGid() 157 */ 158 void cxSetFileGid(CxFile *file, gid_t gid); 159 160 /** 161 * Sets the compressed size of the specified file. 162 * 163 * @param file The file. 164 * @param size The file's compressed size. 165 * 166 * @see cxGetFileCompressedSize() 167 */ 168 void cxSetFileCompressedSize(CxFile *file, unsigned int size); 169 170 /** 171 * Sets the uncompressed size of the specified file. 172 * 173 * @param file The file. 174 * @param size The file's uncompressed size. 175 * 176 * @see cxGetFileSize() 177 */ 178 void cxSetFileSize(CxFile *file, unsigned int size); 179 180 /** 181 * Sets the timestamp of the specified file. 182 * 183 * @param file The file. 184 * @param date The date/time timestamp in seconds since the epoch. 185 * 186 * @see cxGetFileDate() 187 */ 188 void cxSetFileDate(CxFile *file, time_t date); 189 190 /** 191 * Sets whether or not the file is stored locally. 192 * 193 * If the file is located online, or within an archive, this should be 0. 194 * Otherwise, this should be 1. 195 * 196 * @param file The file. 197 * @param isLocal 1 if the file is stored locally; 0 otherwise. 198 * 199 * @see cxIsFileLocal() 200 */ 201 void cxSetFileLocal(CxFile *file, char isLocal); 202 203 /*@}*/ 204 205 /**************************************************************************/ 206 /** @name Attribute Retrieval Functions */ 207 /**************************************************************************/ 208 /*@{*/ 209 210 /** 211 * Returns the archive that owns the specified file. 212 * 213 * @param file The file. 214 * 215 * @return The archive that owns this file. 216 * 217 * @see cxSetFileArchive() 218 */ 219 CxArchive *cxGetFileArchive(CxFile *file); 220 221 /** 222 * Returns the specified file's parent directory. 223 * 224 * @param file The file. 225 * 226 * @return The specified file's parent directory. 227 * 228 * @see cxSetFileParent() 229 */ 230 CxDirectory *cxGetFileParent(CxFile *file); 231 232 /** 233 * Returns the name of the specified file. 234 * 235 * @param file The file. 236 * 237 * @return The file's name. 238 * 239 * @see cxSetFileName() 240 */ 241 const char *cxGetFileName(CxFile *file); 242 243 /** 244 * Returns the full path to the specified file. 245 * 246 * This may include such non-physical elements as FTP sites, archives, 247 * etc. in the path. 248 * 249 * @param file The file. 250 * 251 * @return The path to the file. 252 * 253 * @see cxGetFilePhysicalPath() 254 * @see cxSetFilePhysicalPath() 255 */ 256 const char *cxGetFilePath(CxFile *file); 257 258 /** 259 * Returns the full physical path to the file. 260 * 261 * If the file is non-local, this will be a temporary file. 262 * 263 * @param file The file. 264 * 265 * @return The physical path to the file. 266 * 267 * @see cxSetFilePhysicalPath() 268 * @see cxGetFilePath() 269 */ 270 const char *cxGetFilePhysicalPath(CxFile *file); 271 272 /** 273 * Returns the mode of the specified file. 274 * 275 * @param file The file. 276 * 277 * @return The file's mode. 278 * 279 * @see cxSetFileMode() 280 */ 281 mode_t cxGetFileMode(CxFile *file); 282 283 /** 284 * Returns the user ID of the specified file. 285 * 286 * @param file The file. 287 * 288 * @return The user ID of the specified file. 289 * 290 * @see cxSetFileUid() 291 */ 292 uid_t cxGetFileUid(CxFile *file); 293 294 /** 295 * Returns the group ID of the specified file. 296 * 297 * @param file The file. 298 * 299 * @return The group ID of the specified file. 300 * 301 * @see cxSetFileGid() 302 */ 303 gid_t cxGetFileGid(CxFile *file); 304 305 /** 306 * Returns the compressed size of the specified file. 307 * 308 * @param file The file. 309 * 310 * @return The file's compressed size. 311 * 312 * @see cxSetFileCompressedSize() 313 */ 314 unsigned int cxGetFileCompressedSize(CxFile *file); 315 316 /** 317 * Returns the uncompressed size of the specified file. 318 * 319 * @param file The file. 320 * 321 * @return The file's uncompressed size. 322 * 323 * @see cxSetFileSize() 324 */ 325 unsigned int cxGetFileSize(CxFile *file); 326 327 /** 328 * Returns the timestamp of the specified file. 329 * 330 * @param file The file. 331 * 332 * @return The date/time timestamp in seconds since the epoch. 333 * 334 * @see cxSetFileDate() 335 */ 336 time_t cxGetFileDate(CxFile *file); 337 338 /** 339 * Returns whether or not the file is stored locally. 340 * 341 * If the file is located online, or within an archive, this will be 0. 342 * Otherwise, this will be 1. 343 * 344 * @param file The file. 345 * 346 * @return 1 if the file is stored locally; 0 otherwise. 347 * 348 * @see cxSetFileLocal() 349 */ 350 char cxIsFileLocal(CxFile *file); 351 352 /*@}*/ 353 354 /**************************************************************************/ 355 /** @name Iteration Functions */ 356 /**************************************************************************/ 357 /*@{*/ 358 359 /** 360 * Returns the next file in a list of files. 361 * 362 * @param file The current file. 363 * 364 * @return The next file in the list. 365 * 366 * @see cxGetFirstFile() 367 * @see cxGetPreviousFile() 368 */ 369 CxFile *cxGetNextFile(CxFile *file); 370 371 /** 372 * Returns the previous file in a list of files. 373 * 374 * @param file The current file. 375 * 376 * @return The previous file in the list. 377 * 378 * @see cxGetFirstFile() 379 * @see cxGetNextFile() 380 */ 381 CxFile *cxGetPreviousFile(CxFile *file); 382 383 /*@}*/ 384 385 #ifdef __cplusplus 386 } 387 #endif 388 389 #endif /* _LIBCOMPREX_FILE_H_ */ 390 391