/*
 * 2007+ Copyright (c) Evgeniy Polyakov <johnpol@2ka.mipt.ru>
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#define _ATFILE_SOURCE
#define _GNU_SOURCE
#define __USE_FILE_OFFSET64
#define __USE_LARGEFILE64

#include <sys/types.h>
#include <sys/stat.h>
#include <sys/vfs.h>

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <dirent.h>
#include <string.h>

#include <linux/types.h>

#include "fserver.h"

int fserver_stat_root(int rootfd, char *path, struct ac_stat *st)
{
	struct statfs stfs;
	int err;

	memset(st, 0, sizeof(struct ac_stat));
	err = statfs(path, &stfs);
	if (err)
		return err;

	st->avail = stfs.f_bavail;
	st->avail *= stfs.f_bsize;
	st->nr_files = stfs.f_files;
	st->used = stfs.f_blocks - stfs.f_bavail;
	st->used *= stfs.f_bsize;

	ulog("%s: files: %llu, used: %llu, avail: %llu.\n",
		path, st->nr_files, st->used, st->avail);
	return 0;
}

