]>
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 | ||
16 | #include <errno.h> | |
17 | #include <fcntl.h> | |
18 | #include <stdio.h> | |
19 | #include <string.h> | |
20 | #include <unistd.h> | |
c8c071a0 | 21 | #include <stdlib.h> |
3839e657 TT |
22 | #include <sys/param.h> |
23 | #include <sys/stat.h> | |
24 | ||
54c637d4 | 25 | #include "ext2fs/ext2_fs.h" |
3839e657 | 26 | #include "../version.h" |
d9c56d3c | 27 | #include "nls-enable.h" |
3839e657 TT |
28 | |
29 | #define LPF "lost+found" | |
30 | ||
00e5433e | 31 | int main (int argc, char ** argv) |
3839e657 TT |
32 | { |
33 | char name [EXT2_NAME_LEN]; | |
a418d3ad | 34 | char path [sizeof (LPF) + 1 + 256]; |
3839e657 TT |
35 | struct stat st; |
36 | int i, j; | |
37 | int d; | |
38 | ||
d9c56d3c TT |
39 | #ifdef ENABLE_NLS |
40 | setlocale(LC_MESSAGES, ""); | |
41 | bindtextdomain(NLS_CAT_NAME, LOCALEDIR); | |
42 | textdomain(NLS_CAT_NAME); | |
43 | #endif | |
44 | fprintf (stderr, _("mklost+found %s, %s for EXT2 FS %s, %s\n"), | |
3839e657 TT |
45 | E2FSPROGS_VERSION, E2FSPROGS_DATE, |
46 | EXT2FS_VERSION, EXT2FS_DATE); | |
47 | if (argc != 1) { | |
d9c56d3c | 48 | fprintf (stderr, _("Usage: mklost+found\n")); |
3839e657 TT |
49 | exit(1); |
50 | } | |
51 | if (mkdir (LPF, 0755) == -1) { | |
52 | perror ("mkdir"); | |
53 | exit(1); | |
54 | } | |
55 | ||
56 | i = 0; | |
57 | memset (name, 'x', 252); | |
58 | do { | |
59 | sprintf (name + 252, "%02d", i); | |
60 | strcpy (path, LPF); | |
61 | strcat (path, "/"); | |
62 | strcat (path, name); | |
63 | if ((d = creat (path, 0644)) == -1) { | |
64 | perror ("creat"); | |
65 | exit (1); | |
66 | } | |
67 | i++; | |
68 | close (d); | |
69 | if (stat (LPF, &st) == -1) { | |
70 | perror ("stat"); | |
71 | exit (1); | |
72 | } | |
73 | } while (st.st_size <= (EXT2_NDIR_BLOCKS - 1) * st.st_blksize); | |
74 | for (j = 0; j < i; j++) { | |
75 | sprintf (name + 252, "%02d", j); | |
76 | strcpy (path, LPF); | |
77 | strcat (path, "/"); | |
78 | strcat (path, name); | |
79 | if (unlink (path) == -1) { | |
80 | perror ("unlink"); | |
81 | exit (1); | |
82 | } | |
83 | } | |
84 | exit (0); | |
85 | } |