summaryrefslogtreecommitdiffstats
path: root/e2fsck/extend.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 15:49:25 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 15:49:25 +0000
commit464df1d5e5ab1322e2dd0a7796939fff1aeefa9a (patch)
tree6a403684e0978f0287d7f0ec0e5aab1fd31a59e1 /e2fsck/extend.c
parentInitial commit. (diff)
downloade2fsprogs-464df1d5e5ab1322e2dd0a7796939fff1aeefa9a.tar.xz
e2fsprogs-464df1d5e5ab1322e2dd0a7796939fff1aeefa9a.zip
Adding upstream version 1.47.0.upstream/1.47.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--e2fsck/extend.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/e2fsck/extend.c b/e2fsck/extend.c
new file mode 100644
index 0000000..9d17e44
--- /dev/null
+++ b/e2fsck/extend.c
@@ -0,0 +1,83 @@
+/*
+ * extend.c --- extend a file so that it has at least a specified
+ * number of blocks.
+ *
+ * Copyright (C) 1993, 1994, 1995 Theodore Ts'o.
+ *
+ * This file may be redistributed under the terms of the GNU Public
+ * License.
+ */
+
+#include "config.h"
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include "../misc/nls-enable.h"
+
+static void usage(char *progname)
+{
+ fprintf(stderr, _("%s: %s filename nblocks blocksize\n"),
+ progname, progname);
+ exit(1);
+}
+
+
+int main(int argc, char **argv)
+{
+ char *filename;
+ int nblocks, blocksize;
+ int fd;
+ char *block;
+ errcode_t retval;
+ int ret;
+
+ if (argc != 4)
+ usage(argv[0]);
+
+ filename = argv[1];
+ nblocks = strtoul(argv[2], 0, 0) - 1;
+ blocksize = strtoul(argv[3], 0, 0);
+
+ if (nblocks < 0) {
+ fprintf(stderr, _("Illegal number of blocks!\n"));
+ exit(1);
+ }
+
+ retval = ext2fs_get_memzero(blocksize, &block);
+ if (retval) {
+ fprintf(stderr, _("Couldn't allocate block buffer (size=%d)\n"),
+ blocksize);
+ exit(1);
+ }
+
+ fd = open(filename, O_RDWR);
+ if (fd < 0) {
+ perror(filename);
+ exit(1);
+ }
+ ret = lseek(fd, nblocks*blocksize, SEEK_SET);
+ if (ret < 0) {
+ perror("lseek");
+ exit(1);
+ }
+ ret = read(fd, block, blocksize);
+ if (ret < 0) {
+ perror("read");
+ exit(1);
+ }
+ ret = lseek(fd, nblocks*blocksize, SEEK_SET);
+ if (ret < 0) {
+ perror("lseek #2");
+ exit(1);
+ }
+ ret = write(fd, block, blocksize);
+ if (ret < 0) {
+ perror("read");
+ exit(1);
+ }
+ ext2fs_free_mem(&block);
+ return(0);
+}