LCOV - code coverage report
Current view: top level - common - defs.h (source / functions) Hit Total Coverage
Test: a simple test Lines: 13 14 92.9 %
Date: 2024-06-05 20:10:43 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Greate deal of the code was taken from the kernel UBIFS implementation, and
       3             :  * this file contains some "glue" definitions.
       4             :  */
       5             : 
       6             : #ifndef __UBIFS_DEFS_H__
       7             : #define __UBIFS_DEFS_H__
       8             : 
       9             : #include <stdlib.h>
      10             : #include <stdio.h>
      11             : #include <unistd.h>
      12             : #include <limits.h>
      13             : #include <errno.h>
      14             : #include <time.h>
      15             : #include <assert.h>
      16             : #include <execinfo.h>
      17             : 
      18             : #include "ubifs.h"
      19             : 
      20             : /* common.h requires the PROGRAM_NAME macro */
      21             : extern struct ubifs_info info_;
      22             : #define PROGRAM_NAME (info_.program_name)
      23             : #include "common.h"
      24             : 
      25             : #define MKFS_PROGRAM_NAME "mkfs.ubifs"
      26             : #define FSCK_PROGRAM_NAME "fsck.ubifs"
      27             : 
      28             : enum { MKFS_PROGRAM_TYPE = 0, FSCK_PROGRAM_TYPE };
      29             : 
      30             : enum {
      31             :         DUMP_PREFIX_NONE,
      32             :         DUMP_PREFIX_ADDRESS,
      33             :         DUMP_PREFIX_OFFSET
      34             : };
      35             : 
      36             : #define pr_debug(fmt, ...) do { if (info_.debug_level >= DEBUG_LEVEL)        \
      37             :         printf("<DEBUG> %s[%d] (%s): %s: " fmt, PROGRAM_NAME, getpid(), \
      38             :                info_.dev_name, __FUNCTION__, ##__VA_ARGS__);            \
      39             : } while(0)
      40             : 
      41             : #define pr_notice(fmt, ...) do { if (info_.debug_level >= INFO_LEVEL)        \
      42             :         printf("<INFO> %s[%d] (%s): %s: " fmt, PROGRAM_NAME, getpid(),  \
      43             :                info_.dev_name, __FUNCTION__, ##__VA_ARGS__);            \
      44             : } while(0)
      45             : 
      46             : #define pr_warn(fmt, ...) do { if (info_.debug_level >= WARN_LEVEL)  \
      47             :         printf("<WARN> %s[%d] (%s): %s: " fmt, PROGRAM_NAME, getpid(),  \
      48             :                info_.dev_name, __FUNCTION__, ##__VA_ARGS__);            \
      49             : } while(0)
      50             : 
      51             : #define pr_err(fmt, ...) do { if (info_.debug_level >= ERR_LEVEL)    \
      52             :         printf("<ERROR> %s[%d] (%s): %s: " fmt, PROGRAM_NAME, getpid(), \
      53             :                info_.dev_name, __FUNCTION__, ##__VA_ARGS__);            \
      54             : } while(0)
      55             : 
      56             : #define pr_cont(fmt, ...) do { if (info_.debug_level >= ERR_LEVEL)   \
      57             :         printf(fmt, ##__VA_ARGS__);                                     \
      58             : } while(0)
      59             : 
      60      188026 : static inline void dump_stack(void)
      61             : {
      62             : #define STACK_SIZE 512
      63             :         int j, nptrs;
      64             :         void *buffer[STACK_SIZE];
      65             :         char **strings;
      66             : 
      67      188026 :         if (info_.debug_level < ERR_LEVEL)
      68           0 :                 return;
      69             : 
      70      188026 :         nptrs = backtrace(buffer, STACK_SIZE);
      71      188026 :         strings = backtrace_symbols(buffer, nptrs);
      72             : 
      73      188026 :         printf("dump_stack:\n");
      74     1878343 :         for (j = 0; j < nptrs; j++)
      75     1690317 :                 printf("%s\n", strings[j]);
      76             : 
      77      188026 :         free(strings);
      78             : }
      79             : 
      80          18 : static inline u32 get_random_u32(void)
      81             : {
      82          18 :         srand(time(NULL));
      83          18 :         return rand();
      84             : }
      85             : 
      86             : static inline time_t ktime_get_seconds()
      87             : {
      88  4494324440 :         return time(NULL);
      89             : }
      90             : 
      91             : #define likely(x) (x)
      92             : #define unlikely(x) (x)
      93             : 
      94             : #define cond_resched() do {} while(0)
      95             : 
      96             : #define BUG() do {                              \
      97             :         assert(0);                              \
      98             : } while(0)
      99             : #define BUG_ON(cond) do {                       \
     100             :         assert(!cond);                          \
     101             : } while(0)
     102             : 
     103             : #define smp_wmb()               do {} while(0)
     104             : #define smp_rmb()               do {} while(0)
     105             : #define smp_mb__before_atomic() do {} while(0)
     106             : #define smp_mb__after_atomic()  do {} while(0)
     107             : 
     108             : #define min3(x, y, z) min((typeof(x))min(x, y), z)
     109             : 
     110             : static inline u64 div_u64(u64 dividend, u32 divisor)
     111             : {
     112       17002 :         return dividend / divisor;
     113             : }
     114             : 
     115             : #if INT_MAX != 0x7fffffff
     116             : #error : sizeof(int) must be 4 for this program
     117             : #endif
     118             : 
     119             : #if (~0ULL) != 0xffffffffffffffffULL
     120             : #error : sizeof(long long) must be 8 for this program
     121             : #endif
     122             : 
     123             : #endif

Generated by: LCOV version 1.13