* file named AUTHORS, in the root directory of this distribution.
*/
/*
- * $Id: calcsize.c,v 1.44.2.1 2006/10/19 18:47:25 martinea Exp $
+ * $Id: calcsize.c,v 1.44 2006/07/25 18:27:56 martinea Exp $
*
* traverse directory tree to get backup size estimates
*
* argv[1] is the config name or NOCONFIG
*/
#include "amanda.h"
-#include "statfs.h"
-#include "version.h"
+#include "match.h"
+#include "conffile.h"
+#include "fsusage.h"
#include "sl.h"
#include "util.h"
char *d;
int l, w;
+ /*
+ * Configure program for internationalization:
+ * 1) Only set the message locale for now.
+ * 2) Set textdomain for all amanda related programs to "amanda"
+ * We don't want to be forced to support dozens of message catalogs.
+ */
+ setlocale(LC_MESSAGES, "C");
+ textdomain("amanda");
+
safe_fd(-1, 0);
set_pname("calcsize");
dbopen(NULL);
+ config_init(CONFIG_INIT_CLIENT, NULL);
/* Don't die when child closes pipe */
signal(SIGPIPE, SIG_IGN);
if (argc < 2) {
- fprintf(stderr,"Usage: %s file[s]\n",argv[0]);
+ g_fprintf(stderr,_("Usage: %s file[s]\n"),argv[0]);
return 1;
}
for(i=1; i<argc; i++) {
if(lstat(argv[i], &finfo) == -1) {
- fprintf(stderr, "%s: %s\n", argv[i], strerror(errno));
+ g_fprintf(stderr, "%s: %s\n", argv[i], strerror(errno));
continue;
}
- printf("%s: st_size=%lu", argv[i],(unsigned long)finfo.st_size);
- printf(": blocks=%llu\n", ST_BLOCKS(finfo));
+ g_printf("%s: st_size=%lu", argv[i],(unsigned long)finfo.st_size);
+ g_printf(": blocks=%llu\n", ST_BLOCKS(finfo));
dump_total += (ST_BLOCKS(finfo) + (off_t)1) / (off_t)2 + (off_t)1;
gtar_total += ROUND(4,(ST_BLOCKS(finfo) + (off_t)1));
}
- printf(" gtar dump\n");
- printf("total %-9lu %-9lu\n",gtar_total,dump_total);
+ g_printf(" gtar dump\n");
+ g_printf("total %-9lu %-9lu\n",gtar_total,dump_total);
return 0;
#else
int i;
char *dirname=NULL;
- char *amname=NULL, *qamname = NULL;
+ char *amname=NULL, *qamname=NULL;
char *filename=NULL, *qfilename = NULL;
- unsigned long malloc_hist_1, malloc_size_1;
- unsigned long malloc_hist_2, malloc_size_2;
safe_fd(-1, 0);
safe_cd();
set_pname("calcsize");
dbopen(DBG_SUBDIR_CLIENT);
- dbprintf(("%s: version %s\n", debug_prefix(NULL), version()));
-
- malloc_size_1 = malloc_inuse(&malloc_hist_1);
-
-#if 0
- erroutput_type = (ERR_INTERACTIVE|ERR_SYSLOG);
+ config_init(CONFIG_INIT_CLIENT, NULL);
+ dbprintf(_("version %s\n"), VERSION);
+
+ /* drop root privileges; we'll regain them for the required operations */
+#ifdef WANT_SETUID_CLIENT
+ check_running_as(RUNNING_AS_CLIENT_LOGIN | RUNNING_AS_UID_ONLY);
+ if (!set_root_privs(0)) {
+ error(_("calcsize must be run setuid root"));
+ }
+#else
+ check_running_as(RUNNING_AS_CLIENT_LOGIN);
#endif
argc--, argv++; /* skip program name */
/* need at least program, amname, and directory name */
if(argc < 4) {
- error("Usage: %s config [DUMP|GNUTAR] name dir [-X exclude-file] [-I include-file] [level date]*",
+ error(_("Usage: %s config [DUMP|STAR|GNUTAR] name dir [-X exclude-file] [-I include-file] [level date]*"),
get_pname());
/*NOTREACHED*/
}
- dbprintf(("config: %s\n", *argv));
+ dbprintf(_("config: %s\n"), *argv);
if (strcmp(*argv, "NOCONFIG") != 0) {
dbrename(*argv, DBG_SUBDIR_CLIENT);
}
filename = stralloc(*argv);
qfilename = quote_string(filename);
if (access(filename, R_OK) != 0) {
- fprintf(stderr,"Cannot open exclude file %s\n", qfilename);
+ g_fprintf(stderr,"Cannot open exclude file %s\n", qfilename);
use_gtar_excl = use_star_excl = 0;
} else {
exclude_sl = calc_load_file(filename);
if (!exclude_sl) {
- fprintf(stderr,"Cannot open exclude file %s: %s\n", qfilename,
+ g_fprintf(stderr,"Cannot open exclude file %s: %s\n", qfilename,
strerror(errno));
use_gtar_excl = use_star_excl = 0;
}
filename = stralloc(*argv);
qfilename = quote_string(filename);
if (access(filename, R_OK) != 0) {
- fprintf(stderr,"Cannot open include file %s\n", qfilename);
+ g_fprintf(stderr,"Cannot open include file %s\n", qfilename);
use_gtar_excl = use_star_excl = 0;
} else {
include_sl = calc_load_file(filename);
if (!include_sl) {
- fprintf(stderr,"Cannot open include file %s: %s\n", qfilename,
+ g_fprintf(stderr,"Cannot open include file %s: %s\n", qfilename,
strerror(errno));
use_gtar_excl = use_star_excl = 0;
}
amflock(1, "size");
- if (fseek(stderr, 0L, SEEK_END) < 0) {
- dbprintf(("calcsize: warning - seek failed: %s\n",
- strerror(errno)));
- }
-
- dbprintf(("calcsize: %s %d SIZE " OFF_T_FMT "\n",
+ dbprintf("calcsize: %s %d SIZE %lld\n",
qamname, dumplevel[i],
- (OFF_T_FMT_TYPE)final_size(i, dirname)));
- fprintf(stderr, "%s %d SIZE " OFF_T_FMT "\n",
+ (long long)final_size(i, dirname));
+ g_fprintf(stderr, "%s %d SIZE %lld\n",
qamname, dumplevel[i],
- (OFF_T_FMT_TYPE)final_size(i, dirname));
+ (long long)final_size(i, dirname));
fflush(stderr);
amfunlock(1, "size");
}
-
- malloc_size_2 = malloc_inuse(&malloc_hist_2);
-
- if(malloc_size_1 != malloc_size_2) {
- malloc_list(fileno(stderr), malloc_hist_1, malloc_hist_2);
- }
+ amfree(qamname);
return 0;
#endif
has_exclude = !is_empty_sl(exclude_sl) && (use_gtar_excl || use_star_excl);
aparent = vstralloc(parent_dir, "/", include, NULL);
+ /* We (may) need root privs for the *stat() calls here. */
+ set_root_privs(1);
if(stat(parent_dir, &finfo) != -1)
parent_dev = finfo.st_dev;
newname = newstralloc2(newname, newbase, f->d_name);
if(lstat(newname, &finfo) == -1) {
- fprintf(stderr, "%s/%s: %s\n",
+ g_fprintf(stderr, "%s/%s: %s\n",
dirname, f->d_name, strerror(errno));
continue;
}
perror(dirname);
#endif
}
+
+ /* drop root privs -- we're done with the permission-sensitive calls */
+ set_root_privs(0);
+
amfree(newbase);
amfree(newname);
amfree(aparent);
int level,
char * topdir)
{
- generic_fs_stats_t stats;
+ struct fs_usage fsusage;
off_t mapsize;
char *s;
/* calculate the map sizes */
s = stralloc2(topdir, "/.");
- if(get_fs_stats(s, &stats) == -1) {
+ if(get_fs_usage(s, NULL, &fsusage) == -1) {
error("statfs %s: %s", s, strerror(errno));
/*NOTREACHED*/
}
amfree(s);
- mapsize = (stats.files + (off_t)7) / (off_t)8; /* in bytes */
+ mapsize = (fsusage.fsu_files + (off_t)7) / (off_t)8; /* in bytes */
mapsize = (mapsize + (off_t)1023) / (off_t)1024; /* in kbytes */
/* the dump contains three maps plus the files */