summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
Diffstat (limited to 'misc')
-rw-r--r--misc/ChangeLog42
-rw-r--r--misc/Makefile.in45
-rw-r--r--misc/chattr.c6
-rw-r--r--misc/dumpe2fs.c13
-rw-r--r--misc/mke2fs.8.in39
-rw-r--r--misc/mke2fs.c117
-rw-r--r--misc/tune2fs.8.in31
-rw-r--r--misc/tune2fs.c158
8 files changed, 378 insertions, 73 deletions
diff --git a/misc/ChangeLog b/misc/ChangeLog
index 1fa8a925..d5217737 100644
--- a/misc/ChangeLog
+++ b/misc/ChangeLog
@@ -1,3 +1,45 @@
+Sat Sep 7 07:34:11 1996 Theodore Ts'o <tytso@rsts-11.mit.edu>
+
+ * tune2fs.c (main): Add support for new option -C, which sets the
+ current number of mounts.
+ (main): Allow the interval to be specified in seconds,
+ mostly for debugging.
+
+Tue Aug 27 17:27:43 1996 Miles Bader <miles@gnu.ai.mit.edu>
+
+ * Makefile.in (SMANPAGES): Use @FSCK_MAN@ instead of fsck.8.
+ (SPROGS): Use @FSCK_PROG@ instead of fsck.
+
+Thu Aug 22 00:51:44 1996 Theodore Ts'o <tytso@rsts-11.mit.edu>
+
+ * mke2fs.c (zap_bootblock): Don't do zap_bootblock on a
+ sparc.
+
+Tue Aug 20 00:15:46 1996 Theodore Ts'o <tytso@rsts-11.mit.edu>
+
+ * chattr.c (main): Fixed bug so that chattr -v works. (Bug report
+ and fix sent by Charles Howes, chowes@eznet.ca)
+
+Fri Aug 9 11:52:42 1996 Theodore Ts'o <tytso@rsts-11.mit.edu>
+
+ * tune2fs.8.in:
+ * tune2fs.c: Added support for the -L option which sets the volume
+ label, the -M option which sets the last mounted
+ directory, and the -U option which sets the filesystem UUID.
+
+ * mke2fs.8.in:
+ * mke2fs.c: Added support for the -o option, which overrides the
+ creator OS. Generate a UUID for the filesystem, if
+ applicable. Added support for the -L option which sets
+ the volume label, and the -M option which sets the last
+ mounted directory.
+
+Sat Jun 22 17:43:17 1996 Remy Card <card@bbj.linux.eu.org>
+
+ * chattr.c (decode_arg): Integrated Michael Nonweiler's fix to
+ avoid a segmentation fault when the "-v" option is used
+ and no version number is specified.
+
Thu May 16 11:12:30 1996 Theodore Ts'o <tytso@rsts-11.mit.edu>
* Release of E2fsprogs version 1.04
diff --git a/misc/Makefile.in b/misc/Makefile.in
index 69f164cf..b0d06a20 100644
--- a/misc/Makefile.in
+++ b/misc/Makefile.in
@@ -6,13 +6,15 @@ srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
top_builddir = ..
+my_dir = misc
INSTALL = @INSTALL@
@MCONFIG@
-SPROGS= mke2fs badblocks tune2fs dumpe2fs fsck
+SPROGS= mke2fs badblocks tune2fs dumpe2fs @FSCK_PROG@
USPROGS= mklost+found
-SMANPAGES= tune2fs.8 mklost+found.8 mke2fs.8 dumpe2fs.8 badblocks.8 fsck.8
+SMANPAGES= tune2fs.8 mklost+found.8 mke2fs.8 dumpe2fs.8 badblocks.8 \
+ @FSCK_MAN@
UPROGS= chattr lsattr
UMANPAGES= chattr.1 lsattr.1
@@ -44,18 +46,21 @@ DEPLIBS_E2P= $(LIBEXT2FS) $(LIBE2P) $(LIBCOM_ERR)
all:: $(SPROGS) $(UPROGS) $(USPROGS) fix_substitute $(SMANPAGES) $(UMANPAGES)
-tune2fs: $(TUNE2FS_OBJS) $(DEPLIBS_E2P)
- $(CC) $(ALL_LDFLAGS) -o tune2fs $(TUNE2FS_OBJS) $(LIBS_E2P)
+tune2fs: $(TUNE2FS_OBJS) $(DEPLIBS_E2P) $(LIBUUID)
+ $(CC) $(ALL_LDFLAGS) -o tune2fs $(TUNE2FS_OBJS) $(LIBS_E2P) $(LIBUUID)
mklost+found: $(MKLPF_OBJS)
$(CC) $(ALL_LDFLAGS) -o mklost+found $(MKLPF_OBJS)
-mke2fs: $(MKE2FS_OBJS) $(DEPLIBS)
- $(CC) $(ALL_LDFLAGS) -o mke2fs $(MKE2FS_OBJS) $(LIBS)
+mke2fs: $(MKE2FS_OBJS) $(DEPLIBS) $(LIBUUID)
+ $(CC) $(ALL_LDFLAGS) -o mke2fs $(MKE2FS_OBJS) $(LIBS) $(LIBUUID)
-mke2fs.static: $(MKE2FS_OBJS) $(STATIC_DEPLIBS)
+mke2fs.static: $(MKE2FS_OBJS) $(STATIC_DEPLIBS) $(STATIC_LIBUUID)
$(CC) $(ALL_LDFLAGS) -static -o mke2fs.static $(MKE2FS_OBJS) \
- $(STATIC_LIBS)
+ $(STATIC_LIBS) $(STATIC_LIBUUID)
+
+resize2fs: resize2fs.o $(DEPLIBS)
+ $(CC) $(ALL_LDFLAGS) -o resize2fs resize2fs.o $(LIBS)
chattr: $(CHATTR_OBJS) $(DEPLIBS_E2P)
$(CC) $(ALL_LDFLAGS) -o chattr $(CHATTR_OBJS) $(LIBS_E2P)
@@ -156,26 +161,24 @@ distclean: clean
# Makefile dependencies follow. This must be the last section in
# the Makefile.in file
#
-tune2fs.o: $(srcdir)/tune2fs.c \
- $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/lib/et/com_err.h \
- $(top_srcdir)/lib/ext2fs/io.h $(top_builddir)/lib/ext2fs/ext2_err.h \
- $(top_srcdir)/lib/ext2fs/bitops.h $(top_srcdir)/lib/e2p/e2p.h \
+tune2fs.o: $(srcdir)/tune2fs.c $(top_srcdir)/lib/ext2fs/ext2fs.h \
+ $(top_srcdir)/lib/et/com_err.h $(top_srcdir)/lib/ext2fs/io.h \
+ $(top_builddir)/lib/ext2fs/ext2_err.h $(top_srcdir)/lib/ext2fs/bitops.h \
+ $(top_srcdir)/lib/uuid/uuid.h $(top_srcdir)/lib/e2p/e2p.h \
$(srcdir)/../version.h
mklost+found.o: $(srcdir)/mklost+found.c $(srcdir)/../version.h
mke2fs.o: $(srcdir)/mke2fs.c $(top_srcdir)/lib/et/com_err.h \
- $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/lib/ext2fs/io.h \
- $(top_builddir)/lib/ext2fs/ext2_err.h $(top_srcdir)/lib/ext2fs/bitops.h \
- $(srcdir)/../version.h
+ $(top_srcdir)/lib/uuid/uuid.h $(top_srcdir)/lib/ext2fs/ext2fs.h \
+ $(top_srcdir)/lib/ext2fs/io.h $(top_builddir)/lib/ext2fs/ext2_err.h \
+ $(top_srcdir)/lib/ext2fs/bitops.h $(srcdir)/../version.h
chattr.o: $(srcdir)/chattr.c $(top_srcdir)/lib/et/com_err.h \
$(top_srcdir)/lib/e2p/e2p.h $(srcdir)/../version.h
lsattr.o: $(srcdir)/lsattr.c $(top_srcdir)/lib/et/com_err.h \
$(top_srcdir)/lib/e2p/e2p.h $(srcdir)/../version.h
-dumpe2fs.o: $(srcdir)/dumpe2fs.c \
- $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/lib/et/com_err.h \
- $(top_srcdir)/lib/ext2fs/io.h $(top_builddir)/lib/ext2fs/ext2_err.h \
- $(top_srcdir)/lib/ext2fs/bitops.h $(top_srcdir)/lib/e2p/e2p.h \
- $(srcdir)/../version.h
+dumpe2fs.o: $(srcdir)/dumpe2fs.c $(top_srcdir)/lib/ext2fs/ext2fs.h \
+ $(top_srcdir)/lib/et/com_err.h $(top_srcdir)/lib/ext2fs/io.h \
+ $(top_builddir)/lib/ext2fs/ext2_err.h $(top_srcdir)/lib/ext2fs/bitops.h \
+ $(top_srcdir)/lib/e2p/e2p.h $(srcdir)/../version.h
badblocks.o: $(srcdir)/badblocks.c $(top_srcdir)/lib/et/com_err.h \
$(top_srcdir)/lib/ext2fs/io.h
fsck.o: $(srcdir)/fsck.c $(srcdir)/../version.h $(srcdir)/fsck.h
-
diff --git a/misc/chattr.c b/misc/chattr.c
index a90bdf4d..b359248a 100644
--- a/misc/chattr.c
+++ b/misc/chattr.c
@@ -114,9 +114,9 @@ static int decode_arg (int * i, int argc, char ** argv)
rem = 1;
break;
case 'v':
+ (*i)++;
if (*i >= argc)
usage ();
- (*i)++;
version = strtol (argv[*i], &tmp, 0);
if (*tmp)
{
@@ -310,9 +310,9 @@ void main (int argc, char ** argv)
fprintf (stderr, "= is incompatible with - and +\n");
exit (1);
}
- if (!(add || rem || set))
+ if (!(add || rem || set || set_version))
{
- fprintf (stderr, "Must use =, - or +\n");
+ fprintf (stderr, "Must use '-v', =, - or +\n");
exit (1);
}
for (j = i; j < argc; j++)
diff --git a/misc/dumpe2fs.c b/misc/dumpe2fs.c
index 1161e3b3..740f01bc 100644
--- a/misc/dumpe2fs.c
+++ b/misc/dumpe2fs.c
@@ -150,12 +150,20 @@ static void dump_bad_blocks(ext2_filsys fs)
badblocks_list_iterate_end(bb_iter);
}
+static int i386_byteorder(void)
+{
+ int one = 1;
+ char *cp = (char *) &one;
+
+ return (*cp == 1);
+}
void main (int argc, char ** argv)
{
errcode_t retval;
ext2_filsys fs;
int print_badblocks = 0;
+ int big_endian;
char c;
fprintf (stderr, "dumpe2fs %s, %s for EXT2 FS %s, %s\n",
@@ -195,6 +203,11 @@ void main (int argc, char ** argv)
ext2fs_close (fs);
exit (1);
}
+ big_endian = ((fs->flags & EXT2_SWAP_BYTES) != 0);
+ if (!i386_byteorder())
+ big_endian = !big_endian;
+ if (big_endian)
+ printf("Note: This is a byte-swapped filesystem\n");
list_super (fs->super);
list_bad_blocks (fs);
list_desc (fs);
diff --git a/misc/mke2fs.8.in b/misc/mke2fs.8.in
index 10d6aa87..55265516 100644
--- a/misc/mke2fs.8.in
+++ b/misc/mke2fs.8.in
@@ -14,23 +14,27 @@ mke2fs \- create a Linux second extended file system
.\" test
.\" |
.B \-l
-filename
+.I filename
]
[
.B \-b
-block-size
+.I block-size
]
[
.B \-f
-fragment-size
+.I fragment-size
]
[
.B \-i
-bytes-per-inode
+.I bytes-per-inode
]
[
.B \-m
-reserved-blocks-percentage
+.I reserved-blocks-percentage
+]
+[
+.B \-o
+.I creator-os
]
[
.B \-q
@@ -42,11 +46,19 @@ reserved-blocks-percentage
.B \-F
]
[
+.B \-L
+.I volume-label
+]
+[
+.B \-M
+.I last-mounted-directory
+]
+[
.B \-S
]
-device
+.I device
[
-blocks-count
+.I blocks-count
]
.SH DESCRIPTION
.B mke2fs
@@ -94,6 +106,11 @@ defaults to 5%.
.\" Check the device for bad blocks before creating the file system
.\" using the specified test.
.TP
+.I -o
+Manually override the default value of the "creator os" field of the
+filesystem. Normally the creator field is set by default to the native OS
+of the mke2fs executable.
+.TP
.I -q
Quiet execution. Useful if mke2fs is run in a script.
.TP
@@ -104,6 +121,14 @@ Verbose execution.
Force mke2fs to run, even if the specified device is not a
block special device.
.TP
+.I -L
+Set the volume label for the filesystem.
+.TP
+.I -M
+Set the last mounted directory for the filesystem. This might be useful
+for the sake of utilities that key off of the last mounted directory to
+determine where the filesytem should be mounted.
+.TP
.I -S
Write superblock and group descriptors only. This is useful if all of
the superblock and backup superblocks are corrupted, and a last-ditch
diff --git a/misc/mke2fs.c b/misc/mke2fs.c
index 69f5c397..0cdcc059 100644
--- a/misc/mke2fs.c
+++ b/misc/mke2fs.c
@@ -47,11 +47,16 @@
#endif
#include "et/com_err.h"
+#include "uuid/uuid.h"
#include "ext2fs/ext2fs.h"
#include "../version.h"
#define STRIDE_LENGTH 8
+#ifndef sparc
+#define ZAP_BOOTBLOCK
+#endif
+
extern int isatty(int);
extern FILE *fpopen(const char *cmd, const char *mode);
@@ -67,14 +72,17 @@ int force = 0;
char *bad_blocks_filename = 0;
struct ext2_super_block param;
+char *creator_os = NULL;
+char *volume_label = NULL;
+char *mount_dir = NULL;
static void usage(NOARGS)
{
- fprintf(stderr,
- "Usage: %s [-c|-t|-l filename] [-b block-size] "
- "[-f fragment-size]\n\t[-i bytes-per-inode] "
- "[-m reserved-blocks-percentage] [-qvS]\n"
- "\t[-g blocks-per-group] device [blocks-count]\n",
+ fprintf(stderr, "Usage: %s [-c|-t|-l filename] [-b block-size] "
+ "[-f fragment-size]\n\t[-i bytes-per-inode] "
+ "[-m reserved-blocks-percentage] [-qvS]\n\t"
+ "[-o creator-os] [-g blocks-per-group] [-L volume-label]\n\t"
+ "[-M last-mounted-directory] device [blocks-count]\n",
program_name);
exit(1);
}
@@ -437,6 +445,7 @@ static void reserve_inodes(ext2_filsys fs)
ext2fs_mark_ib_dirty(fs);
}
+#ifdef ZAP_BOOTBLOCK
static void zap_bootblock(ext2_filsys fs)
{
char buf[512];
@@ -449,11 +458,13 @@ static void zap_bootblock(ext2_filsys fs)
printf("Warning: could not erase block 0: %s\n",
error_message(retval));
}
+#endif
static void show_stats(ext2_filsys fs)
{
- struct ext2_super_block *s = fs->super;
+ struct ext2fs_sb *s = (struct ext2fs_sb *) fs->super;
+ char buf[80];
blk_t group_block;
int i, col_left;
@@ -461,6 +472,16 @@ static void show_stats(ext2_filsys fs)
printf("warning: %d blocks unused.\n\n",
param.s_blocks_count - s->s_blocks_count);
+ switch (fs->super->s_creator_os) {
+ case EXT2_OS_LINUX: printf ("Linux"); break;
+ case EXT2_OS_HURD: printf ("GNU/hurd"); break;
+ case EXT2_OS_MASIX: printf ("Masix"); break;
+ default: printf ("(unknown os)");
+ }
+ printf (" ext2 filesystem format\n");
+ memset(buf, 0, sizeof(buf));
+ strncpy(buf, s->s_volume_name, sizeof(s->s_volume_name));
+ printf("Filesystem label=%s\n", buf);
printf("%u inodes, %u blocks\n", s->s_inodes_count,
s->s_blocks_count);
printf("%u blocks (%2.2f%%) reserved for the super user\n",
@@ -498,6 +519,41 @@ static void show_stats(ext2_filsys fs)
printf("\n\n");
}
+#ifndef HAVE_STRCASECMP
+static int strcasecmp (char *s1, char *s2)
+{
+ while (*s1 && *s2) {
+ int ch1 = *s1++, ch2 = *s2++;
+ if (isupper (ch1))
+ ch1 = tolower (ch1);
+ if (isupper (ch2))
+ ch2 = tolower (ch2);
+ if (ch1 != ch2)
+ return ch1 - ch2;
+ }
+ return *s1 ? 1 : *s2 ? -1 : 0;
+}
+#endif
+
+/*
+ * Set the S_CREATOR_OS field. Return true if OS is known,
+ * otherwise, 0.
+ */
+static int set_os(struct ext2_super_block *sb, char *os)
+{
+ if (isdigit (*os))
+ sb->s_creator_os = atoi (os);
+ else if (strcasecmp(os, "linux") == 0)
+ sb->s_creator_os = EXT2_OS_LINUX;
+ else if (strcasecmp(os, "GNU") == 0 || strcasecmp(os, "hurd") == 0)
+ sb->s_creator_os = EXT2_OS_HURD;
+ else if (strcasecmp(os, "masix") == 0)
+ sb->s_creator_os = EXT2_OS_MASIX;
+ else
+ return 0;
+ return 1;
+}
+
#define PATH_SET "PATH=/sbin"
static void PRS(int argc, char *argv[])
@@ -532,7 +588,8 @@ static void PRS(int argc, char *argv[])
EXT2FS_VERSION, EXT2FS_DATE);
if (argc && *argv)
program_name = *argv;
- while ((c = getopt (argc, argv, "b:cf:g:i:l:m:qr:tvI:SF")) != EOF)
+ while ((c = getopt (argc, argv,
+ "b:cf:g:i:l:m:o:qr:tvI:SFL:M:")) != EOF)
switch (c) {
case 'b':
size = strtoul(optarg, &tmp, 0);
@@ -606,6 +663,9 @@ static void PRS(int argc, char *argv[])
exit(1);
}
break;
+ case 'o':
+ creator_os = optarg;
+ break;
case 'r':
param.s_rev_level = atoi(optarg);
break;
@@ -623,6 +683,12 @@ static void PRS(int argc, char *argv[])
case 'F':
force = 1;
break;
+ case 'L':
+ volume_label = optarg;
+ break;
+ case 'M':
+ mount_dir = optarg;
+ break;
case 'S':
super_only = 1;
break;
@@ -655,7 +721,7 @@ static void PRS(int argc, char *argv[])
EXT2_BLOCK_SIZE(&param),
&param.s_blocks_count);
if (retval) {
- com_err(program_name, 0,
+ com_err(program_name, retval,
"while trying to determine filesystem size");
exit(1);
}
@@ -679,6 +745,7 @@ int main (int argc, char *argv[])
errcode_t retval = 0;
ext2_filsys fs;
badblocks_list bb_list = 0;
+ struct ext2fs_sb *s;
PRS(argc, argv);
@@ -692,6 +759,38 @@ int main (int argc, char *argv[])
exit(1);
}
+ /*
+ * Generate a UUID for it...
+ */
+ s = (struct ext2fs_sb *) fs->super;
+ uuid_generate(s->s_uuid);
+
+ /*
+ * Override the creator OS, if applicable
+ */
+ if (creator_os && !set_os(fs->super, creator_os)) {
+ com_err (program_name, 0, "unknown os - %s", creator_os);
+ exit(1);
+ }
+
+ /*
+ * Set the volume label...
+ */
+ if (volume_label) {
+ memset(s->s_volume_name, 0, sizeof(s->s_volume_name));
+ strncpy(s->s_volume_name, volume_label,
+ sizeof(s->s_volume_name));
+ }
+
+ /*
+ * Set the last mount directory
+ */
+ if (mount_dir) {
+ memset(s->s_last_mounted, 0, sizeof(s->s_last_mounted));
+ strncpy(s->s_last_mounted, mount_dir,
+ sizeof(s->s_last_mounted));
+ }
+
if (!quiet)
show_stats(fs);
@@ -710,7 +809,9 @@ int main (int argc, char *argv[])
create_lost_and_found(fs);
reserve_inodes(fs);
create_bad_block_inode(fs, bb_list);
+#ifdef ZAP_BOOTBLOCK
zap_bootblock(fs);
+#endif
}
if (!quiet)
diff --git a/misc/tune2fs.8.in b/misc/tune2fs.8.in
index ee123d28..9b927112 100644
--- a/misc/tune2fs.8.in
+++ b/misc/tune2fs.8.in
@@ -38,6 +38,22 @@ tune2fs \- adjust tunable filesystem parameters on second extended filesystems
.B -g
.I group
]
+[
+.B -C
+.I mount-count
+]
+[
+.B -L
+.I volume-name
+]
+[
+.B -M
+.I last-mounted-directory
+]
+[
+.B -U
+.I UUID
+]
device
.SH DESCRIPTION
.BI tune2fs
@@ -85,6 +101,21 @@ adjust the reserved blocks count on the given device.
set the user who can benefit from the reserved blocks.
.I user
can be a numerical uid or a user name.
+.IP
+.I -C mount-count
+set the number of times the filesystem has been mounted.
+.TP
+.I -L volume-label
+set the volume label of the filesystem.
+.TP
+.I -M last-mounted-directory
+set the last-mounted direcctory for the filesystem.
+.TP
+.I -U UUID
+set the UUID of the filesystem. A sample UUID looks like this:
+"c1b9d5a2-f162-11cf-9ece-0020afc76f16". The uuid may also be "null",
+which will set the filesystem UUID to the null UUID. The uuid may also
+be "random", which will generate a new random UUID for the filesystem.
.PP
.SH BUGS
We didn't find any bugs yet. Perhaps there are bugs but it's unlikely.
diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index 1576ce44..a6e24865 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -39,21 +39,29 @@
#include "ext2fs/ext2fs.h"
#include "et/com_err.h"
+#include "uuid/uuid.h"
#include "e2p/e2p.h"
#include "../version.h"
const char * program_name = "tune2fs";
char * device_name = NULL;
+char * new_label = NULL;
+char * new_last_mounted = NULL;
+char * new_UUID = NULL;
int c_flag = 0;
+int C_flag = 0;
int e_flag = 0;
int g_flag = 0;
int i_flag = 0;
int l_flag = 0;
+int L_flag = 0;
int m_flag = 0;
+int M_flag = 0;
int r_flag = 0;
int u_flag = 0;
-int max_mount_count;
+int U_flag = 0;
+int max_mount_count, mount_count;
unsigned long interval;
unsigned long reserved_ratio = 0;
unsigned long reserved_blocks = 0;
@@ -61,12 +69,30 @@ unsigned short errors;
unsigned long resgid = 0;
unsigned long resuid = 0;
+#ifndef HAVE_STRCASECMP
+static int strcasecmp (char *s1, char *s2)
+{
+ while (*s1 && *s2) {
+ int ch1 = *s1++, ch2 = *s2++;
+ if (isupper (ch1))
+ ch1 = tolower (ch1);
+ if (isupper (ch2))
+ ch2 = tolower (ch2);
+ if (ch1 != ch2)
+ return ch1 - ch2;
+ }
+ return *s1 ? 1 : *s2 ? -1 : 0;
+}
+#endif
+
static volatile void usage (void)
{
fprintf (stderr, "Usage: %s [-c max-mounts-count] [-e errors-behavior] "
"[-g group]\n"
"\t[-i interval[d|m|w]] [-l] [-m reserved-blocks-percent]\n"
- "\t[-r reserved-blocks-count] [-u user] device\n", program_name);
+ "\t[-r reserved-blocks-count] [-u user] [-C mount-count]\n"
+ "\t[-L volume-label] [-M last-mounted-dir] [-U UUID] "
+ "device\n", program_name);
exit (1);
}
@@ -76,8 +102,10 @@ void main (int argc, char ** argv)
char * tmp;
errcode_t retval;
ext2_filsys fs;
+ struct ext2fs_sb *sb;
struct group * gr;
struct passwd * pw;
+ int open_flag = 0;
fprintf (stderr, "tune2fs %s, %s for EXT2 FS %s, %s\n",
E2FSPROGS_VERSION, E2FSPROGS_DATE,
@@ -85,7 +113,7 @@ void main (int argc, char ** argv)
if (argc && *argv)
program_name = *argv;
initialize_ext2_error_table();
- while ((c = getopt (argc, argv, "c:e:g:i:lm:r:u:")) != EOF)
+ while ((c = getopt (argc, argv, "c:e:g:i:lm:r:u:C:L:M:U:")) != EOF)
switch (c)
{
case 'c':
@@ -98,6 +126,19 @@ void main (int argc, char ** argv)
usage ();
}
c_flag = 1;
+ open_flag = EXT2_FLAG_RW;
+ break;
+ case 'C':
+ mount_count = strtoul (optarg, &tmp, 0);
+ if (*tmp || mount_count > 16000)
+ {
+ com_err (program_name, 0,
+ "bad mounts count - %s",
+ optarg);
+ usage ();
+ }
+ C_flag = 1;
+ open_flag = EXT2_FLAG_RW;
break;
case 'e':
if (strcmp (optarg, "continue") == 0)
@@ -114,6 +155,7 @@ void main (int argc, char ** argv)
usage ();
}
e_flag = 1;
+ open_flag = EXT2_FLAG_RW;
break;
case 'g':
resgid = strtoul (optarg, &tmp, 0);
@@ -135,28 +177,31 @@ void main (int argc, char ** argv)
usage ();
}
g_flag = 1;
+ open_flag = EXT2_FLAG_RW;
break;
case 'i':
interval = strtoul (optarg, &tmp, 0);
- switch (*tmp)
- {
- case '\0':
- case 'd':
- case 'D': /* days */
- interval *= 86400;
- if (*tmp != '\0')
- tmp++;
- break;
- case 'm':
- case 'M': /* months! */
- interval *= 86400 * 30;
- tmp++;
- break;
- case 'w':
- case 'W': /* weeks */
- interval *= 86400 * 7;
+ switch (*tmp) {
+ case 's':
+ tmp++;
+ break;
+ case '\0':
+ case 'd':
+ case 'D': /* days */
+ interval *= 86400;
+ if (*tmp != '\0')
tmp++;
- break;
+ break;
+ case 'm':
+ case 'M': /* months! */
+ interval *= 86400 * 30;
+ tmp++;
+ break;
+ case 'w':
+ case 'W': /* weeks */
+ interval *= 86400 * 7;
+ tmp++;
+ break;
}
if (*tmp || interval > (365 * 86400))
{
@@ -165,10 +210,16 @@ void main (int argc, char ** argv)
usage ();
}
i_flag = 1;
+ open_flag = EXT2_FLAG_RW;
break;
case 'l':
l_flag = 1;
break;
+ case 'L':
+ new_label = optarg;
+ L_flag = 1;
+ open_flag = EXT2_FLAG_RW;
+ break;
case 'm':
reserved_ratio = strtoul (optarg, &tmp, 0);
if (*tmp || reserved_ratio > 50)
@@ -179,6 +230,12 @@ void main (int argc, char ** argv)
usage ();
}
m_flag = 1;
+ open_flag = EXT2_FLAG_RW;
+ break;
+ case 'M':
+ new_last_mounted = optarg;
+ M_flag = 1;
+ open_flag = EXT2_FLAG_RW;
break;
case 'r':
reserved_blocks = strtoul (optarg, &tmp, 0);
@@ -190,6 +247,7 @@ void main (int argc, char ** argv)
usage ();
}
r_flag = 1;
+ open_flag = EXT2_FLAG_RW;
break;
case 'u':
resuid = strtoul (optarg, &tmp, 0);
@@ -211,20 +269,23 @@ void main (int argc, char ** argv)
usage ();
}
u_flag = 1;
+ open_flag = EXT2_FLAG_RW;
+ break;
+ case 'U':
+ new_UUID = optarg;
+ U_flag = 1;
+ open_flag = EXT2_FLAG_RW;
break;
default:
usage ();
}
if (optind < argc - 1 || optind == argc)
usage ();
- if (!c_flag && !e_flag && !g_flag && !i_flag && !l_flag && !m_flag
- && !r_flag && !u_flag)
- usage ();
+ if (!open_flag && !l_flag)
+ usage();
device_name = argv[optind];
- retval = ext2fs_open (device_name,
- (c_flag || e_flag || g_flag || i_flag || m_flag
- || r_flag || u_flag) ? EXT2_FLAG_RW : 0,
- 0, 0, unix_io_manager, &fs);
+ retval = ext2fs_open (device_name, open_flag, 0, 0,
+ unix_io_manager, &fs);
if (retval)
{
com_err (program_name, retval, "while trying to open %s",
@@ -232,15 +293,20 @@ void main (int argc, char ** argv)
printf("Couldn't find valid filesystem superblock.\n");
exit(1);
}
+ sb = (struct ext2fs_sb *) fs->super;
- if (c_flag)
- {
+ if (c_flag) {
fs->super->s_max_mnt_count = max_mount_count;
ext2fs_mark_super_dirty(fs);
- printf ("Setting maximal mount count to %d\n", max_mount_count);
+ printf ("Setting maximal mount count to %d\n",
+ max_mount_count);
}
- if (e_flag)
- {
+ if (C_flag) {
+ fs->super->s_mnt_count = mount_count;
+ ext2fs_mark_super_dirty(fs);
+ printf ("Setting current mount count to %d\n", mount_count);
+ }
+ if (e_flag) {
fs->super->s_errors = errors;
ext2fs_mark_super_dirty(fs);
printf ("Setting error behavior to %d\n", errors);
@@ -268,7 +334,7 @@ void main (int argc, char ** argv)
fs->super->s_r_blocks_count = (fs->super->s_blocks_count / 100)
* reserved_ratio;
ext2fs_mark_super_dirty(fs);
- printf ("Setting reserved blocks percentage to %lu (%lu blocks)\n",
+ printf ("Setting reserved blocks percentage to %lu (%u blocks)\n",
reserved_ratio, fs->super->s_r_blocks_count);
}
if (r_flag)
@@ -297,6 +363,30 @@ void main (int argc, char ** argv)
"The -u option is not supported by this version -- "
"Recompile with a newer kernel");
#endif
+ if (L_flag) {
+ memset(sb->s_volume_name, 0, sizeof(sb->s_volume_name));
+ strncpy(sb->s_volume_name, new_label,
+ sizeof(sb->s_volume_name));
+ ext2fs_mark_super_dirty(fs);
+ }
+ if (M_flag) {
+ memset(sb->s_last_mounted, 0, sizeof(sb->s_last_mounted));
+ strncpy(sb->s_last_mounted, new_last_mounted,
+ sizeof(sb->s_last_mounted));
+ ext2fs_mark_super_dirty(fs);
+ }
+ if (U_flag) {
+ if (strcasecmp(new_UUID, "null") == 0) {
+ uuid_clear(sb->s_uuid);
+ } else if (strcasecmp(new_UUID, "random") == 0) {
+ uuid_generate(sb->s_uuid);
+ } else if (uuid_parse(new_UUID, sb->s_uuid)) {
+ com_err(program_name, 0, "Invalid UUID format\n");
+ exit(1);
+ }
+ ext2fs_mark_super_dirty(fs);
+ }
+
if (l_flag)
list_super (fs->super);
ext2fs_close (fs);