1997-04-26 21:58:21 +08:00
|
|
|
/*
|
|
|
|
* 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 <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
static void usage(char *progname)
|
|
|
|
{
|
Many files:
badblocks.c, e2fsck.h, ehandler.c, emptydir.c, extend.c, flushb.c,
iscan.c, message.c, pass1.c, pass1b.c, pass3.c pass4.c, pass5.c,
problem.c, scantest.c, swapfs.c, unix.c, util.c: Add
Internationalization support as suggested by Marco d'Itri
<md@linux.it>.
2000-02-07 11:11:03 +08:00
|
|
|
fprintf(stderr, _("%s: %s filename nblocks blocksize\n"),
|
1997-04-26 21:58:21 +08:00
|
|
|
progname, progname);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
char *filename;
|
|
|
|
int nblocks, blocksize;
|
|
|
|
int fd;
|
|
|
|
char *block;
|
|
|
|
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) {
|
Many files:
badblocks.c, e2fsck.h, ehandler.c, emptydir.c, extend.c, flushb.c,
iscan.c, message.c, pass1.c, pass1b.c, pass3.c pass4.c, pass5.c,
problem.c, scantest.c, swapfs.c, unix.c, util.c: Add
Internationalization support as suggested by Marco d'Itri
<md@linux.it>.
2000-02-07 11:11:03 +08:00
|
|
|
fprintf(stderr, _("Illegal number of blocks!\n"));
|
1997-04-26 21:58:21 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
block = malloc(blocksize);
|
|
|
|
if (block == 0) {
|
Many files:
badblocks.c, e2fsck.h, ehandler.c, emptydir.c, extend.c, flushb.c,
iscan.c, message.c, pass1.c, pass1b.c, pass3.c pass4.c, pass5.c,
problem.c, scantest.c, swapfs.c, unix.c, util.c: Add
Internationalization support as suggested by Marco d'Itri
<md@linux.it>.
2000-02-07 11:11:03 +08:00
|
|
|
fprintf(stderr, _("Couldn't allocate block buffer (size=%d)\n"),
|
1997-04-26 21:58:21 +08:00
|
|
|
blocksize);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
memset(block, 0, blocksize);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|