public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: chrubis@suse.cz
To: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
Cc: ltp-list@lists.sourceforge.net
Subject: Re: [LTP] [PATCH 1/2] lib/tst_fs_has_free.c: add tst_fs_has_free() to determine filesystem's free space
Date: Thu, 10 Apr 2014 13:11:37 +0200	[thread overview]
Message-ID: <20140410111137.GA24517@rei> (raw)
In-Reply-To: <1395402240-6619-2-git-send-email-wangxg.fnst@cn.fujitsu.com>

Hi!
> +/*
> + * Copyright (c) 2014 Fujitsu Ltd.
> + * Author: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of version 2 of the GNU General Public License as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it would be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with this program; if not, write the Free Software Foundation, Inc.,
> + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
> + */
> +
> +/*
> + * DESCRIPTION
> + * 	Check if the mounted file system has enough free space,
> + * 	if it is, tst_fs_has_free() returns 1, otherwise 0.
> + */
> +
> +#include <sys/vfs.h>
> +#include "test.h"
> +
> +int tst_fs_has_free(void (*cleanup)(void), const char *path, int required_kib)
> +{
> +	struct statfs sf;
> +
> +	if (statfs(path, &sf)) {
> +		tst_brkm(TBROK | TERRNO, cleanup,
> +			 "tst_fs_has_free: failed to statfs(%s)", path);
> +	}
> +
> +	return (sf.f_bfree * sf.f_bsize / 1024) >= required_kib ? 1 : 0;

The f_bfree is unsigned long (via typedef to the fsblkcnt_t) so if I'm
counting right on 32bit system the multiplication will overflow on > 4TB
filesystem.

If we do the multiplication first we should cast the b_free to 64 bit
unsigned integer.

The rest looks fine.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment 
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

  reply	other threads:[~2014-04-10 11:12 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-21 11:43 [LTP] Usage about LTP_BIG_DEV exported by runltp Xiaoguang Wang
2014-03-21 11:43 ` [LTP] [PATCH 1/2] lib/tst_fs_has_free.c: add tst_fs_has_free() to determine filesystem's free space Xiaoguang Wang
2014-04-10 11:11   ` chrubis [this message]
2014-03-21 11:44 ` [LTP] [PATCH 2/2] testcases/lib/misc.sh: add tst_fs_has_free function Xiaoguang Wang
     [not found]   ` <5344F4E5.2050600@cn.fujitsu.com>
2014-04-09 17:06     ` chrubis
2014-04-10 11:13   ` chrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140410111137.GA24517@rei \
    --to=chrubis@suse.cz \
    --cc=ltp-list@lists.sourceforge.net \
    --cc=wangxg.fnst@cn.fujitsu.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox