From: jeffm@suse.com
To: ReiserFS Development List <reiserfs-devel@vger.kernel.org>
Cc: Edward Shishkin <edward.shishkin@gmail.com>
Subject: [patch 7/9] [PATCH] reiserfsprogs: enforce 2^32-1 block limit
Date: Thu, 24 Jan 2008 15:02:33 -0500 [thread overview]
Message-ID: <20080124200337.726114000@suse.com> (raw)
In-Reply-To: 20080124200226.606635000@suse.com
[-- Attachment #1: reiserfsprogs-enforce-block-limit.diff --]
[-- Type: text/plain, Size: 3173 bytes --]
Currently, mkreiserfs on a block device >= 16 TiB will fail with this error:
reiserfs_create_journal: cannot create a journal of 8193 blocks with
18 offset on 0 blocks
The message doesn't adequately describe that the problem is that reiserfs
supports file system sizes up to 2^32-1 blocks, and it silently overflows.
This patch treats the block device size, as well as the <blocks> command
line parameter as __u64's, so that they can be safely compared to UINT_MAX.
If the block device is too large, we warn the user, offer to truncate the
file system to 2^32-1 blocks, and confirm. This is overridable by the -f
option, which will elect to truncate automatically.
If the user has specified a block count that is too large, we fail always
since the user has provided invalid input.
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
mkreiserfs/mkreiserfs.c | 41 +++++++++++++++++++++++++++++++++++++++--
1 file changed, 39 insertions(+), 2 deletions(-)
--- a/mkreiserfs/mkreiserfs.c 2008-01-24 13:39:04.000000000 -0500
+++ b/mkreiserfs/mkreiserfs.c 2008-01-24 13:39:05.000000000 -0500
@@ -27,6 +27,7 @@
#include <stdarg.h>
#include <string.h>
#include <errno.h>
+#include <limits.h>
#include <sys/utsname.h>
#if defined(HAVE_LIBUUID) && defined(HAVE_UUID_UUID_H)
@@ -434,6 +435,21 @@ static int str2int (char * str)
return val;
}
+static __u64 str2u64 (char *str)
+{
+ __u64 val;
+ char *tmp;
+
+ val = (__u64)strtoll(str, &tmp, 0);
+
+ if (*tmp) {
+ reiserfs_exit (1, "%s: strtoll is unable to make an integer of %s\n",
+ program_name, str);
+ }
+
+ return val;
+}
+
static void set_block_size (char * str, int *b_size)
{
@@ -537,7 +553,7 @@ int main (int argc, char **argv)
int force = 0;
char * device_name = NULL;
char * jdevice_name = NULL;
- unsigned long fs_size = 0;
+ __u64 fs_size = 0;
int c;
static int flag;
@@ -672,7 +688,7 @@ int main (int argc, char **argv)
if (optind == argc - 2) {
/* number of blocks for filesystem is specified */
- fs_size = str2int (argv[optind + 1]);
+ fs_size = str2u64 (argv[optind + 1]);
} else if (optind == argc - 1) {
/* number of blocks is not specified */
if (!(fs_size = count_blocks (device_name, Block_size)))
@@ -681,6 +697,27 @@ int main (int argc, char **argv)
print_usage_and_exit ();
}
+ if (fs_size >= UINT_MAX) {
+ fprintf(stderr, ">>> ReiserFS supports file systems of up to %u "
+ "blocks.\n>>> The maximum size with a block size of %u bytes "
+ "is about %Lu MiB.\n>>> This file system would occupy %Lu "
+ "blocks. ", UINT_MAX, Block_size,
+ ((__u64)UINT_MAX * Block_size) / (1024 * 1024), fs_size);
+
+ if (optind == argc - 1) {
+ if (!force &&
+ !user_confirmed (stderr, "Truncate? (y/N): ", "y\n")) {
+ fprintf(stderr, "\nExiting.\n\n");
+ exit(1);
+ }
+ fprintf(stderr, "Truncating.\n\n");
+ fs_size = UINT_MAX;
+ } else {
+ fprintf(stderr, "Exiting.\n\n");
+ exit(1);
+ }
+ }
+
if (is_journal_default (device_name, jdevice_name, Block_size))
Create_default_journal = 1;
next prev parent reply other threads:[~2008-01-24 20:02 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-24 20:02 [patch 0/9] reiserfsprogs patch queue jeffm
2008-01-24 20:02 ` [patch 1/9] [PATCH] reiserfsprogs: QUIET_MODE should silence credits too jeffm
2008-01-24 20:02 ` [patch 2/9] [PATCH] reiserfsprogs: Warn on block sizes > 4k jeffm
2008-01-24 20:02 ` [patch 3/9] [PATCH] reiserfsprogs: id_map_init off-by-one jeffm
2008-01-24 20:02 ` [patch 4/9] [PATCH] reiserfsprogs: changes for better external journal defaults jeffm
2008-01-24 20:02 ` [patch 5/9] reiserfsprogs: remove fsck_sleep jeffm
2008-01-24 20:02 ` [patch 6/9] reiserfsprogs: mkfs should use O_EXCL jeffm
2008-01-24 20:02 ` jeffm [this message]
2008-01-24 20:02 ` [patch 8/9] [PATCH] reiserfsprogs: Support for file systems > 8 TB jeffm
2008-01-24 20:02 ` [patch 9/9] [PATCH 1/2] reiserfsprogs: add ext3-style mount count and last check expiry for better fsck -a behavior jeffm
2008-01-25 11:01 ` [patch 0/9] reiserfsprogs patch queue Edward Shishkin
2008-01-25 15:45 ` Jeff Mahoney
2008-01-25 15:50 ` Jeff Mahoney
2008-03-24 0:28 ` Edward Shishkin
2008-03-24 2:25 ` Jeff Mahoney
2009-01-09 22:15 ` Edward Shishkin
2009-01-09 23:26 ` Jeff Mahoney
2008-01-25 16:00 ` [PATCH] reiserfsprogs: remove dependency on asm/unaligned.h Jeff Mahoney
2008-02-25 0:58 ` [patch 0/9] reiserfsprogs patch queue Domenico Andreoli
2008-02-25 13:17 ` Edward Shishkin
2008-02-25 16:58 ` Jeff Mahoney
2008-02-25 18:51 ` Edward Shishkin
2008-03-24 0:19 ` Edward Shishkin
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=20080124200337.726114000@suse.com \
--to=jeffm@suse.com \
--cc=edward.shishkin@gmail.com \
--cc=reiserfs-devel@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).