2012-08-27 11:51:08 -08:00
|
|
|
/* ncdu - NCurses Disk Usage
|
|
|
|
|
|
2019-02-04 07:30:18 -09:00
|
|
|
Copyright (c) 2007-2019 Yoran Heling
|
2007-07-20 03:15:46 -08:00
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
|
a copy of this software and associated documentation files (the
|
|
|
|
|
"Software"), to deal in the Software without restriction, including
|
|
|
|
|
without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
|
distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
|
permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
|
the following conditions:
|
2012-08-27 11:51:08 -08:00
|
|
|
|
2007-07-20 03:15:46 -08:00
|
|
|
The above copyright notice and this permission notice shall be included
|
|
|
|
|
in all copies or substantial portions of the Software.
|
2012-08-27 11:51:08 -08:00
|
|
|
|
2007-07-20 03:15:46 -08:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
2009-04-26 01:08:40 -08:00
|
|
|
#ifndef _global_h
|
|
|
|
|
#define _global_h
|
2007-07-20 03:15:46 -08:00
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#include <stdio.h>
|
2012-08-27 23:22:46 -08:00
|
|
|
#include <stddef.h>
|
2012-11-22 03:33:32 -09:00
|
|
|
#include <limits.h>
|
2018-01-23 03:17:06 -09:00
|
|
|
#include <string.h>
|
2007-07-20 03:15:46 -08:00
|
|
|
#include <sys/types.h>
|
2009-05-11 09:48:32 -08:00
|
|
|
#include <sys/stat.h>
|
2007-08-11 12:01:16 -08:00
|
|
|
|
2012-08-27 07:20:24 -08:00
|
|
|
#ifdef HAVE_INTTYPES_H
|
|
|
|
|
# include <inttypes.h>
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef HAVE_STDINT_H
|
|
|
|
|
# include <stdint.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2007-07-20 03:15:46 -08:00
|
|
|
/* File Flags (struct dir -> flags) */
|
2007-07-29 06:06:05 -08:00
|
|
|
#define FF_DIR 0x01
|
|
|
|
|
#define FF_FILE 0x02
|
|
|
|
|
#define FF_ERR 0x04 /* error while reading this item */
|
2018-03-29 07:32:46 -08:00
|
|
|
#define FF_OTHFS 0x08 /* excluded because it was another filesystem */
|
2007-07-29 06:06:05 -08:00
|
|
|
#define FF_EXL 0x10 /* excluded using exlude patterns */
|
|
|
|
|
#define FF_SERR 0x20 /* error in subdirectory */
|
2010-02-27 01:29:36 -09:00
|
|
|
#define FF_HLNKC 0x40 /* hard link candidate (file with st_nlink > 1) */
|
|
|
|
|
#define FF_BSEL 0x80 /* selected */
|
2018-01-23 03:17:06 -09:00
|
|
|
#define FF_EXT 0x100 /* extended struct available */
|
2007-07-20 03:15:46 -08:00
|
|
|
|
2009-04-11 03:47:55 -08:00
|
|
|
/* Program states */
|
2009-04-08 09:09:24 -08:00
|
|
|
#define ST_CALC 0
|
|
|
|
|
#define ST_BROWSE 1
|
|
|
|
|
#define ST_DEL 2
|
|
|
|
|
#define ST_HELP 3
|
2014-12-13 14:24:35 -09:00
|
|
|
#define ST_SHELL 4
|
2015-09-17 23:43:37 -08:00
|
|
|
#define ST_QUIT 5
|
2009-04-08 09:09:24 -08:00
|
|
|
|
2007-08-11 12:01:16 -08:00
|
|
|
|
2012-08-27 11:10:07 -08:00
|
|
|
/* structure representing a file or directory */
|
2007-07-20 03:15:46 -08:00
|
|
|
struct dir {
|
2012-08-27 07:20:24 -08:00
|
|
|
int64_t size, asize;
|
2012-08-27 11:10:07 -08:00
|
|
|
uint64_t ino, dev;
|
2012-08-27 23:22:46 -08:00
|
|
|
struct dir *parent, *next, *prev, *sub, *hlnk;
|
2012-08-27 08:32:29 -08:00
|
|
|
int items;
|
2018-01-23 03:17:06 -09:00
|
|
|
unsigned short flags;
|
2017-08-17 07:04:48 -08:00
|
|
|
char name[];
|
2012-08-27 11:51:08 -08:00
|
|
|
};
|
2010-04-28 05:32:47 -08:00
|
|
|
|
2012-08-27 11:10:07 -08:00
|
|
|
/* A note on the ino and dev fields above: ino is usually represented as ino_t,
|
|
|
|
|
* which POSIX specifies to be an unsigned integer. dev is usually represented
|
|
|
|
|
* as dev_t, which may be either a signed or unsigned integer, and in practice
|
|
|
|
|
* both are used. dev represents an index / identifier of a device or
|
|
|
|
|
* filesystem, and I'm unsure whether a negative value has any meaning in that
|
|
|
|
|
* context. Hence my choice of using an unsigned integer. Negative values, if
|
|
|
|
|
* we encounter them, will just get typecasted into a positive value. No
|
|
|
|
|
* information is lost in this conversion, and the semantics remain the same.
|
|
|
|
|
*/
|
2010-04-28 05:32:47 -08:00
|
|
|
|
2018-01-23 03:17:06 -09:00
|
|
|
/* Extended information for a struct dir. This struct is stored in the same
|
|
|
|
|
* memory region as struct dir, placed after the name field. See util.h for
|
|
|
|
|
* macros to help manage this. */
|
|
|
|
|
struct dir_ext {
|
2018-01-23 04:11:40 -09:00
|
|
|
uint64_t mtime;
|
2018-01-23 03:17:06 -09:00
|
|
|
int uid, gid;
|
|
|
|
|
unsigned short mode;
|
|
|
|
|
};
|
|
|
|
|
|
2007-07-20 03:15:46 -08:00
|
|
|
|
2009-04-08 09:40:18 -08:00
|
|
|
/* program state */
|
2009-04-10 23:58:33 -08:00
|
|
|
extern int pstate;
|
2017-01-06 08:35:30 -09:00
|
|
|
/* read-only flag, 1+ = disable deletion, 2+ = also disable shell */
|
2011-09-08 16:41:12 -08:00
|
|
|
extern int read_only;
|
2009-04-25 23:49:51 -08:00
|
|
|
/* minimum screen update interval when calculating, in ms */
|
|
|
|
|
extern long update_delay;
|
2013-04-10 06:41:26 -08:00
|
|
|
/* filter directories with CACHEDIR.TAG */
|
|
|
|
|
extern int cachedir_tags;
|
2015-09-19 15:11:12 -08:00
|
|
|
/* flag if we should ask for confirmation when quitting */
|
|
|
|
|
extern int confirm_quit;
|
2018-01-23 03:40:12 -09:00
|
|
|
/* flag whether we want to enable use of struct dir_ext */
|
|
|
|
|
extern int extended_info;
|
2019-01-22 22:55:38 -09:00
|
|
|
/* flag whether we want to follow symlinks */
|
|
|
|
|
extern int follow_symlinks;
|
2007-07-20 03:15:46 -08:00
|
|
|
|
2009-04-11 03:47:55 -08:00
|
|
|
/* handle input from keyboard and update display */
|
2009-04-10 08:16:33 -08:00
|
|
|
int input_handle(int);
|
2009-04-11 01:37:45 -08:00
|
|
|
|
2019-07-23 01:01:48 -08:00
|
|
|
/* de-initialize ncurses */
|
|
|
|
|
void close_nc();
|
|
|
|
|
|
2009-04-11 01:37:45 -08:00
|
|
|
|
2009-04-26 01:08:40 -08:00
|
|
|
/* import all other global functions and variables */
|
|
|
|
|
#include "browser.h"
|
2012-08-26 04:41:25 -08:00
|
|
|
#include "delete.h"
|
|
|
|
|
#include "dir.h"
|
|
|
|
|
#include "dirlist.h"
|
|
|
|
|
#include "exclude.h"
|
2009-04-26 01:08:40 -08:00
|
|
|
#include "help.h"
|
|
|
|
|
#include "path.h"
|
2012-08-26 04:41:25 -08:00
|
|
|
#include "util.h"
|
2014-12-14 05:13:38 -09:00
|
|
|
#include "shell.h"
|
2015-09-17 23:43:37 -08:00
|
|
|
#include "quit.h"
|
2009-04-26 01:08:40 -08:00
|
|
|
|
2009-04-11 01:37:45 -08:00
|
|
|
#endif
|