blob: 027c89958488687f2aba0c1982d377c905693948 [file] [log] [blame]
Theodore Ts'o3839e651997-04-26 13:21:57 +00001/*
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>
Theodore Ts'oc8c071a2001-01-11 16:08:23 +000021#include <stdlib.h>
Theodore Ts'o3839e651997-04-26 13:21:57 +000022#include <sys/param.h>
23#include <sys/stat.h>
24
Theodore Ts'o54c637d2001-05-14 11:45:38 +000025#include "ext2fs/ext2_fs.h"
Theodore Ts'o3839e651997-04-26 13:21:57 +000026#include "../version.h"
Theodore Ts'od9c56d32000-02-08 00:47:55 +000027#include "nls-enable.h"
Theodore Ts'o3839e651997-04-26 13:21:57 +000028
29#define LPF "lost+found"
30
Theodore Ts'o00e54331997-09-16 02:13:52 +000031int main (int argc, char ** argv)
Theodore Ts'o3839e651997-04-26 13:21:57 +000032{
33 char name [EXT2_NAME_LEN];
Theodore Ts'oa418d3a1997-04-26 14:00:26 +000034 char path [sizeof (LPF) + 1 + 256];
Theodore Ts'o3839e651997-04-26 13:21:57 +000035 struct stat st;
36 int i, j;
37 int d;
38
Theodore Ts'od9c56d32000-02-08 00:47:55 +000039#ifdef ENABLE_NLS
40 setlocale(LC_MESSAGES, "");
Theodore Ts'o14308a52002-03-05 03:26:52 -050041 setlocale(LC_CTYPE, "");
Theodore Ts'od9c56d32000-02-08 00:47:55 +000042 bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
43 textdomain(NLS_CAT_NAME);
44#endif
Theodore Ts'o0f8973f2001-08-27 12:44:23 -040045 fprintf (stderr, "mklost+found %s (%s)\n", E2FSPROGS_VERSION,
46 E2FSPROGS_DATE);
Theodore Ts'o3839e651997-04-26 13:21:57 +000047 if (argc != 1) {
Matthias Andreeb969b1b2003-12-28 13:04:35 +010048 (void)argv; /* avoid unused argument warning */
Theodore Ts'od9c56d32000-02-08 00:47:55 +000049 fprintf (stderr, _("Usage: mklost+found\n"));
Theodore Ts'o3839e651997-04-26 13:21:57 +000050 exit(1);
51 }
Theodore Ts'o64aecc42002-10-11 17:44:12 -040052 if (mkdir (LPF, 0700) == -1) {
Theodore Ts'o3839e651997-04-26 13:21:57 +000053 perror ("mkdir");
54 exit(1);
55 }
56
57 i = 0;
58 memset (name, 'x', 252);
59 do {
60 sprintf (name + 252, "%02d", i);
61 strcpy (path, LPF);
62 strcat (path, "/");
63 strcat (path, name);
64 if ((d = creat (path, 0644)) == -1) {
65 perror ("creat");
66 exit (1);
67 }
68 i++;
69 close (d);
70 if (stat (LPF, &st) == -1) {
71 perror ("stat");
72 exit (1);
73 }
74 } while (st.st_size <= (EXT2_NDIR_BLOCKS - 1) * st.st_blksize);
75 for (j = 0; j < i; j++) {
76 sprintf (name + 252, "%02d", j);
77 strcpy (path, LPF);
78 strcat (path, "/");
79 strcat (path, name);
80 if (unlink (path) == -1) {
81 perror ("unlink");
82 exit (1);
83 }
84 }
85 exit (0);
86}