blob: 299e47c91b3614c8d316a10cd981b19db9a17e6a [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>
21#include <sys/param.h>
22#include <sys/stat.h>
23
24#include <linux/ext2_fs.h>
25
26#include "../version.h"
27
28#define LPF "lost+found"
29
30void main (int argc, char ** argv)
31{
32 char name [EXT2_NAME_LEN];
33 char path [MAXPATHLEN];
34 struct stat st;
35 int i, j;
36 int d;
37
38 fprintf (stderr, "mklost+found %s, %s for EXT2 FS %s, %s\n",
39 E2FSPROGS_VERSION, E2FSPROGS_DATE,
40 EXT2FS_VERSION, EXT2FS_DATE);
41 if (argc != 1) {
42 fprintf (stderr, "Usage: mklost+found\n");
43 exit(1);
44 }
45 if (mkdir (LPF, 0755) == -1) {
46 perror ("mkdir");
47 exit(1);
48 }
49
50 i = 0;
51 memset (name, 'x', 252);
52 do {
53 sprintf (name + 252, "%02d", i);
54 strcpy (path, LPF);
55 strcat (path, "/");
56 strcat (path, name);
57 if ((d = creat (path, 0644)) == -1) {
58 perror ("creat");
59 exit (1);
60 }
61 i++;
62 close (d);
63 if (stat (LPF, &st) == -1) {
64 perror ("stat");
65 exit (1);
66 }
67 } while (st.st_size <= (EXT2_NDIR_BLOCKS - 1) * st.st_blksize);
68 for (j = 0; j < i; j++) {
69 sprintf (name + 252, "%02d", j);
70 strcpy (path, LPF);
71 strcat (path, "/");
72 strcat (path, name);
73 if (unlink (path) == -1) {
74 perror ("unlink");
75 exit (1);
76 }
77 }
78 exit (0);
79}