From 464df1d5e5ab1322e2dd0a7796939fff1aeefa9a Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 17:49:25 +0200 Subject: Adding upstream version 1.47.0. Signed-off-by: Daniel Baumann --- misc/mklost+found.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 misc/mklost+found.c (limited to 'misc/mklost+found.c') diff --git a/misc/mklost+found.c b/misc/mklost+found.c new file mode 100644 index 0000000..1431187 --- /dev/null +++ b/misc/mklost+found.c @@ -0,0 +1,87 @@ +/* + * mklost+found.c - Creates a directory lost+found on a mounted second + * extended file system + * + * Copyright (C) 1992, 1993 Remy Card + * + * This file can be redistributed under the terms of the GNU General + * Public License + */ + +/* + * History: + * 93/04/22 - Creation + */ + +#include "config.h" +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ext2fs/ext2_fs.h" +#include "../version.h" +#include "support/nls-enable.h" + +#define LPF "lost+found" + +int main (int argc, char ** argv) +{ + char name[EXT2_NAME_LEN + 2]; + char path[sizeof (LPF) + 1 + 256]; + struct stat st; + int i, j; + int d; + +#ifdef ENABLE_NLS + setlocale(LC_MESSAGES, ""); + setlocale(LC_CTYPE, ""); + bindtextdomain(NLS_CAT_NAME, LOCALEDIR); + textdomain(NLS_CAT_NAME); +#endif + fprintf (stderr, "mklost+found %s (%s)\n", E2FSPROGS_VERSION, + E2FSPROGS_DATE); + if (argc != 1) { + (void)argv; /* avoid unused argument warning */ + fprintf (stderr, "%s", _("Usage: mklost+found\n")); + exit(1); + } + if (mkdir (LPF, 0700) == -1) { + perror ("mkdir"); + exit(1); + } + + i = 0; + memset (name, 'x', 246); + do { + sprintf (name + 246, "%08d", i); + strcpy (path, LPF); + strcat (path, "/"); + strcat (path, name); + if ((d = creat (path, 0644)) == -1) { + perror ("creat"); + exit (1); + } + i++; + close (d); + if (stat (LPF, &st) == -1) { + perror ("stat"); + exit (1); + } + } while (st.st_size <= (EXT2_NDIR_BLOCKS - 1) * st.st_blksize); + for (j = 0; j < i; j++) { + sprintf (name + 246, "%08d", j); + strcpy (path, LPF); + strcat (path, "/"); + strcat (path, name); + if (unlink (path) == -1) { + perror ("unlink"); + exit (1); + } + } + exit (0); +} -- cgit v1.2.3