]>
Commit | Line | Data |
---|---|---|
3839e657 TT |
1 | /* |
2 | * mklost+found.c - Creates a directory lost+found on a mounted second | |
3 | * extended file system | |
4 | * | |
5 | * Copyright (C) 1992, 1993 Remy Card <card@masi.ibp.fr> | |
6 | * | |
7 | * This file can be redistributed under the terms of the GNU General | |
8 | * Public License | |
9 | */ | |
10 | ||
11 | /* | |
12 | * History: | |
13 | * 93/04/22 - Creation | |
14 | */ | |
15 | ||
d1154eb4 | 16 | #include "config.h" |
3839e657 TT |
17 | #include <errno.h> |
18 | #include <fcntl.h> | |
19 | #include <stdio.h> | |
20 | #include <string.h> | |
21 | #include <unistd.h> | |
c8c071a0 | 22 | #include <stdlib.h> |
3839e657 TT |
23 | #include <sys/param.h> |
24 | #include <sys/stat.h> | |
25 | ||
54c637d4 | 26 | #include "ext2fs/ext2_fs.h" |
3839e657 | 27 | #include "../version.h" |
99ceb8ec | 28 | #include "support/nls-enable.h" |
3839e657 TT |
29 | |
30 | #define LPF "lost+found" | |
31 | ||
00e5433e | 32 | int main (int argc, char ** argv) |
3839e657 TT |
33 | { |
34 | char name [EXT2_NAME_LEN]; | |
a418d3ad | 35 | char path [sizeof (LPF) + 1 + 256]; |
3839e657 TT |
36 | struct stat st; |
37 | int i, j; | |
38 | int d; | |
39 | ||
d9c56d3c TT |
40 | #ifdef ENABLE_NLS |
41 | setlocale(LC_MESSAGES, ""); | |
14308a53 | 42 | setlocale(LC_CTYPE, ""); |
d9c56d3c TT |
43 | bindtextdomain(NLS_CAT_NAME, LOCALEDIR); |
44 | textdomain(NLS_CAT_NAME); | |
45 | #endif | |
0f8973fb TT |
46 | fprintf (stderr, "mklost+found %s (%s)\n", E2FSPROGS_VERSION, |
47 | E2FSPROGS_DATE); | |
3839e657 | 48 | if (argc != 1) { |
b969b1b8 | 49 | (void)argv; /* avoid unused argument warning */ |
45ff69ff | 50 | fprintf (stderr, "%s", _("Usage: mklost+found\n")); |
3839e657 TT |
51 | exit(1); |
52 | } | |
64aecc4d | 53 | if (mkdir (LPF, 0700) == -1) { |
3839e657 TT |
54 | perror ("mkdir"); |
55 | exit(1); | |
56 | } | |
efc6f628 | 57 | |
3839e657 | 58 | i = 0; |
fcadc8c8 | 59 | memset (name, 'x', 246); |
3839e657 | 60 | do { |
fcadc8c8 | 61 | sprintf (name + 246, "%08d", i); |
3839e657 TT |
62 | strcpy (path, LPF); |
63 | strcat (path, "/"); | |
64 | strcat (path, name); | |
65 | if ((d = creat (path, 0644)) == -1) { | |
66 | perror ("creat"); | |
67 | exit (1); | |
68 | } | |
69 | i++; | |
70 | close (d); | |
71 | if (stat (LPF, &st) == -1) { | |
72 | perror ("stat"); | |
73 | exit (1); | |
74 | } | |
75 | } while (st.st_size <= (EXT2_NDIR_BLOCKS - 1) * st.st_blksize); | |
76 | for (j = 0; j < i; j++) { | |
fcadc8c8 | 77 | sprintf (name + 246, "%08d", j); |
3839e657 TT |
78 | strcpy (path, LPF); |
79 | strcat (path, "/"); | |
80 | strcat (path, name); | |
81 | if (unlink (path) == -1) { | |
82 | perror ("unlink"); | |
83 | exit (1); | |
84 | } | |
85 | } | |
86 | exit (0); | |
87 | } |