1 /* 2 * Copyright (c) 2017, Peter Haag 3 * Copyright (c) 2014, Peter Haag 4 * Copyright (c) 2009, Peter Haag 5 * Copyright (c) 2004-2008, SWITCH - Teleinformatikdienste fuer Lehre und Forschung 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions are met: 10 * 11 * * Redistributions of source code must retain the above copyright notice, 12 * this list of conditions and the following disclaimer. 13 * * Redistributions in binary form must reproduce the above copyright notice, 14 * this list of conditions and the following disclaimer in the documentation 15 * and/or other materials provided with the distribution. 16 * * Neither the name of the author nor the names of its contributors may be 17 * used to endorse or promote products derived from this software without 18 * specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 * 32 */ 33 34 #ifndef _NFSTATFILE_H 35 #define _NFSTATFILE_H 1 36 37 #include "config.h" 38 39 #include <sys/types.h> 40 #ifdef HAVE_STDINT_H 41 #include <stdint.h> 42 #endif 43 44 typedef struct dirstat_s { 45 uint64_t first; // for more easy parsing and assigning, take a uint64_t also for the time_t type 46 uint64_t last; 47 uint64_t numfiles; 48 uint64_t filesize; 49 uint64_t max_size; 50 uint64_t max_lifetime; 51 uint64_t low_water; 52 uint64_t status; 53 } dirstat_t; 54 55 typedef struct dirstat_env_s { 56 dirstat_t *dirstat; 57 int fd; 58 char *filename; 59 int index; 60 } dirstat_env_t; 61 62 enum { STATFILE_OK = 0, ERR_FAIL, ERR_NOSTATFILE, FORCE_REBUILD }; 63 64 #define READ_ONLY 0 65 #define CREATE_AND_LOCK 1 66 #define LOCK_IF_EXISTS 2 67 68 #define stat_filename ".nfstat" 69 70 char *ScaleValue(uint64_t v); 71 72 char *ScaleTime(uint64_t v); 73 74 void PrintDirStat(dirstat_t *dirstat); 75 76 int ReadStatInfo(char *dirname, dirstat_t **dirstat_p, int lock ); 77 78 int WriteStatInfo(dirstat_t *dirstat); 79 80 int ReleaseStatInfo(dirstat_t *dirstat); 81 82 #endif //_NFSTATFILE_H 83