/** parse date/time yyyymmdd[HH[MM[SS]]] */ time_t str2date( char *str ) { struct tm datetime = { .tm_sec = 0, .tm_min = 0, .tm_hour = 0, .tm_mday = 0, .tm_mon = 0, .tm_year = 0, .tm_wday = 0, .tm_yday = 0, .tm_isdst = -1 }; char tmpstr[16]; int tmpint; char * curr = str; /* extract year */ if (extract_digits(curr, tmpstr, 4) < 4) return (time_t)-1; curr += 4; if ((tmpint = str2int(tmpstr)) == -1) return (time_t)-1; datetime.tm_year = tmpint - 1900; /* 1900 => 0 */ /* extract month */ if (extract_digits(curr, tmpstr, 2) < 2) return (time_t)-1; curr += 2; if ((tmpint = str2int(tmpstr)) <= 0) return (time_t)-1; else if (tmpint > 12) return (time_t)-1; datetime.tm_mon = tmpint - 1; /* January => 0 */ /* extract day */ if (extract_digits(curr, tmpstr, 2) < 2) return (time_t)-1; curr += 2; if ((tmpint = str2int(tmpstr)) <= 0) return (time_t)-1; else if (tmpint > 31) return (time_t)-1; datetime.tm_mday = tmpint; /* 1st => 1 */ /* extract hours */ tmpint = extract_digits(curr, tmpstr, 2); if (tmpint == 0) /* not specified */ goto convert; else if (tmpint < 2) /* invalid */ return (time_t)-1; curr += 2; if ((tmpint = str2int(tmpstr)) == -1) return (time_t)-1; else if (tmpint > 23) return (time_t)-1; datetime.tm_hour = tmpint; /* extract minutes */ tmpint = extract_digits(curr, tmpstr, 2); if (tmpint == 0) /* not specified */ goto convert; else if (tmpint < 2) /* invalid */ return (time_t)-1; curr += 2; if ((tmpint = str2int(tmpstr)) == -1) return (time_t)-1; else if (tmpint > 59) return (time_t)-1; datetime.tm_min = tmpint; /* extract seconds */ tmpint = extract_digits(curr, tmpstr, 2); if (tmpint == 0) /* not specified */ goto convert; else if (tmpint < 2) /* invalid */ return (time_t)-1; curr += 2; if ((tmpint = str2int(tmpstr)) == -1) return (time_t)-1; else if (tmpint > 59) return (time_t)-1; datetime.tm_sec = tmpint; if (*curr != '\0') return (time_t)-1; convert: return mktime(&datetime); } /** * Print attributes to a string */ int PrintAttrs( char *out_str, size_t strsize, const attr_set_t * p_attr_set, int overide_mask ) { int mask = p_attr_set->attr_mask; size_t written = 0; char tmpbuf[256]; if ( overide_mask ) mask = mask & overide_mask; if ( mask & ATTR_MASK_fullpath ) written += snprintf( out_str + written, strsize - written, "Fullpath: \"%s\"\n", ATTR( p_attr_set, fullpath ) ); if ( mask & ATTR_MASK_name ) written += snprintf( out_str + written, strsize - written, "Name: \"%s\"\n", ATTR( p_attr_set, name ) ); #ifdef ATTR_INDEX_type if ( mask & ATTR_MASK_type ) written += snprintf( out_str + written, strsize - written, "Type: %s\n", ATTR( p_attr_set, type ) ); #endif if ( mask & ATTR_MASK_owner ) written += snprintf( out_str + written, strsize - written, "Owner: \"%s\"\n", ATTR( p_attr_set, owner ) ); if ( mask & ATTR_MASK_gr_name ) written += snprintf( out_str + written, strsize - written, "Group: \"%s\"\n", ATTR( p_attr_set, gr_name ) ); if ( mask & ATTR_MASK_size ) { FormatFileSize( tmpbuf, 256, ATTR( p_attr_set, size ) ); written += snprintf( out_str + written, strsize - written, "Size: %s\n", tmpbuf ); } if ( mask & ATTR_MASK_depth ) written += snprintf( out_str + written, strsize - written, "Depth: %d\n", ATTR( p_attr_set, depth ) ); #ifdef ATTR_INDEX_dircount if ( mask & ATTR_MASK_dircount ) written += snprintf( out_str + written, strsize - written, "DirCount: %d\n", ATTR( p_attr_set, dircount ) ); #endif if ( mask & ATTR_MASK_last_access ) { FormatDurationFloat( tmpbuf, 256, time( NULL ) - ATTR( p_attr_set, last_access ) ); written += snprintf( out_str + written, strsize - written, "Last Access: %s ago\n", tmpbuf ); } #ifdef ATTR_INDEX_last_copy if ( mask & ATTR_MASK_last_copy ) { FormatDurationFloat( tmpbuf, 256, time( NULL ) - ATTR( p_attr_set, last_copy ) ); written += snprintf( out_str + written, strsize - written, "Last Copy: %s ago\n", tmpbuf ); } #endif if ( mask & ATTR_MASK_last_mod ) { FormatDurationFloat( tmpbuf, 256, time( NULL ) - ATTR( p_attr_set, last_mod ) ); written += snprintf( out_str + written, strsize - written, "Last Mod: %s ago\n", tmpbuf ); } return written; }
/** Dump FS Scan stats to log file */ int FSScan_DumpStats( ) { int rc; robinhood_fsscan_stat_t stats; struct tm paramtm; char tmp_buff[256]; char tmp_buff2[256]; if ( ( rc = Robinhood_StatsScan( &stats ) ) ) return rc; DisplayLog( LVL_MAJOR, "STATS", "======== FS scan statistics =========" ); if ( stats.last_fsscan_time != 0 ) { strftime( tmp_buff, 256, "%Y/%m/%d %T", localtime_r( &stats.last_fsscan_time, ¶mtm ) ); DisplayLog( LVL_MAJOR, "STATS", "last scan = %s", tmp_buff ); FormatDuration( tmp_buff, 256, stats.last_duration ); DisplayLog( LVL_MAJOR, "STATS", "duration = %s (%u s)", tmp_buff, stats.last_duration ); DisplayLog( LVL_MAJOR, "STATS", "status = %s", ( stats.scan_complete ? "complete" : "incomplete" ) ); } if ( stats.current_scan_interval != 0 ) { FormatDurationFloat( tmp_buff, 256, stats.current_scan_interval ); DisplayLog( LVL_MAJOR, "STATS", "current scan interval = %s", tmp_buff ); } if ( stats.scan_running ) { DisplayLog( LVL_MAJOR, "STATS", "scan is running:" ); strftime( tmp_buff, 256, "%Y/%m/%d %T", localtime_r( &stats.start_time, ¶mtm ) ); FormatDurationFloat( tmp_buff2, 256, time( NULL ) - stats.start_time ); DisplayLog( LVL_MAJOR, "STATS", " started at : %s (%s ago)", tmp_buff, tmp_buff2 ); strftime( tmp_buff, 256, "%Y/%m/%d %T", localtime_r( &stats.last_action, ¶mtm ) ); FormatDurationFloat( tmp_buff2, 256, time( NULL ) - stats.last_action ); DisplayLog( LVL_MAJOR, "STATS", " last action: %s (%s ago)", tmp_buff, tmp_buff2 ); if ( stats.scanned_entries ) { double speed; DisplayLog( LVL_MAJOR, "STATS", " progress : %u entries scanned (%u errors)", stats.scanned_entries, stats.error_count ); if ( stats.avg_ms_per_entry > 0.0 ) speed = ( 1000.0 / stats.avg_ms_per_entry ) * fs_scan_config.nb_threads_scan; else speed = 0.0; DisplayLog( LVL_MAJOR, "STATS", " avg. speed : %.2f ms/entry/thread -> %.2f entries/sec", stats.avg_ms_per_entry, speed ); if ( stats.curr_ms_per_entry > 0.0 ) speed = ( 1000.0 / stats.curr_ms_per_entry ) * fs_scan_config.nb_threads_scan; else speed = 0.0; DisplayLog( LVL_MAJOR, "STATS", " inst. speed: %.2f ms/entry/thread -> %.2f entries/sec", stats.curr_ms_per_entry, speed ); } } if (stats.nb_hang > 0) DisplayLog( LVL_MAJOR, "STATS", "scan operation timeouts = %u", stats.nb_hang ); return 0; }