1 /* ncdu - NCurses Disk Usage
2 
3   Copyright (c) 2007-2021 Yoran Heling
4 
5   Permission is hereby granted, free of charge, to any person obtaining
6   a copy of this software and associated documentation files (the
7   "Software"), to deal in the Software without restriction, including
8   without limitation the rights to use, copy, modify, merge, publish,
9   distribute, sublicense, and/or sell copies of the Software, and to
10   permit persons to whom the Software is furnished to do so, subject to
11   the following conditions:
12 
13   The above copyright notice and this permission notice shall be included
14   in all copies or substantial portions of the Software.
15 
16   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20   CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21   TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22   SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 
24 */
25 
26 #ifndef _global_h
27 #define _global_h
28 
29 #include "config.h"
30 #include <stdio.h>
31 #include <stddef.h>
32 #include <limits.h>
33 #include <string.h>
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 
37 #ifdef HAVE_INTTYPES_H
38 # include <inttypes.h>
39 #endif
40 #ifdef HAVE_STDINT_H
41 # include <stdint.h>
42 #endif
43 
44 /* File Flags (struct dir -> flags) */
45 #define FF_DIR     0x01
46 #define FF_FILE    0x02
47 #define FF_ERR     0x04 /* error while reading this item */
48 #define FF_OTHFS   0x08 /* excluded because it was another filesystem */
49 #define FF_EXL     0x10 /* excluded using exclude patterns */
50 #define FF_SERR    0x20 /* error in subdirectory */
51 #define FF_HLNKC   0x40 /* hard link candidate (file with st_nlink > 1) */
52 #define FF_BSEL    0x80 /* selected */
53 #define FF_EXT    0x100 /* extended struct available */
54 #define FF_KERNFS 0x200 /* excluded because it was a Linux pseudo filesystem */
55 #define FF_FRMLNK 0x400 /* excluded because it was a firmlink */
56 
57 /* Program states */
58 #define ST_CALC   0
59 #define ST_BROWSE 1
60 #define ST_DEL    2
61 #define ST_HELP   3
62 #define ST_SHELL  4
63 #define ST_QUIT   5
64 
65 
66 /* structure representing a file or directory */
67 struct dir {
68   int64_t size, asize;
69   uint64_t ino, dev;
70   struct dir *parent, *next, *prev, *sub, *hlnk;
71   int items;
72   unsigned short flags;
73   char name[];
74 };
75 
76 /* A note on the ino and dev fields above: ino is usually represented as ino_t,
77  * which POSIX specifies to be an unsigned integer.  dev is usually represented
78  * as dev_t, which may be either a signed or unsigned integer, and in practice
79  * both are used. dev represents an index / identifier of a device or
80  * filesystem, and I'm unsure whether a negative value has any meaning in that
81  * context. Hence my choice of using an unsigned integer. Negative values, if
82  * we encounter them, will just get typecasted into a positive value. No
83  * information is lost in this conversion, and the semantics remain the same.
84  */
85 
86 /* Extended information for a struct dir. This struct is stored in the same
87  * memory region as struct dir, placed after the name field. See util.h for
88  * macros to help manage this. */
89 struct dir_ext {
90   uint64_t mtime;
91   int uid, gid;
92   unsigned short mode;
93 };
94 
95 
96 /* program state */
97 extern int pstate;
98 /* read-only flag, 1+ = disable deletion, 2+ = also disable shell */
99 extern int read_only;
100 /* minimum screen update interval when calculating, in ms */
101 extern long update_delay;
102 /* filter directories with CACHEDIR.TAG */
103 extern int cachedir_tags;
104 /* flag if we should ask for confirmation when quitting */
105 extern int confirm_quit;
106 /* flag whether we want to enable use of struct dir_ext */
107 extern int extended_info;
108 /* flag whether we want to follow symlinks */
109 extern int follow_symlinks;
110 /* flag whether we want to follow firmlinks */
111 extern int follow_firmlinks;
112 
113 /* handle input from keyboard and update display */
114 int input_handle(int);
115 
116 /* de-initialize ncurses */
117 void close_nc(void);
118 
119 
120 /* import all other global functions and variables */
121 #include "browser.h"
122 #include "delete.h"
123 #include "dir.h"
124 #include "dirlist.h"
125 #include "exclude.h"
126 #include "help.h"
127 #include "path.h"
128 #include "util.h"
129 #include "shell.h"
130 #include "quit.h"
131 
132 #endif
133