Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 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> |
Theodore Ts'o | c8c071a | 2001-01-11 16:08:23 +0000 | [diff] [blame] | 21 | #include <stdlib.h> |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 22 | #include <sys/param.h> |
| 23 | #include <sys/stat.h> |
| 24 | |
Theodore Ts'o | 54c637d | 2001-05-14 11:45:38 +0000 | [diff] [blame] | 25 | #include "ext2fs/ext2_fs.h" |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 26 | #include "../version.h" |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 27 | #include "nls-enable.h" |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 28 | |
| 29 | #define LPF "lost+found" |
| 30 | |
Theodore Ts'o | 00e5433 | 1997-09-16 02:13:52 +0000 | [diff] [blame] | 31 | int main (int argc, char ** argv) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 32 | { |
| 33 | char name [EXT2_NAME_LEN]; |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 34 | char path [sizeof (LPF) + 1 + 256]; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 35 | struct stat st; |
| 36 | int i, j; |
| 37 | int d; |
| 38 | |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 39 | #ifdef ENABLE_NLS |
| 40 | setlocale(LC_MESSAGES, ""); |
| 41 | bindtextdomain(NLS_CAT_NAME, LOCALEDIR); |
| 42 | textdomain(NLS_CAT_NAME); |
| 43 | #endif |
Theodore Ts'o | 0f8973f | 2001-08-27 12:44:23 -0400 | [diff] [blame^] | 44 | fprintf (stderr, "mklost+found %s (%s)\n", E2FSPROGS_VERSION, |
| 45 | E2FSPROGS_DATE); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 46 | if (argc != 1) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 47 | fprintf (stderr, _("Usage: mklost+found\n")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 48 | exit(1); |
| 49 | } |
| 50 | if (mkdir (LPF, 0755) == -1) { |
| 51 | perror ("mkdir"); |
| 52 | exit(1); |
| 53 | } |
| 54 | |
| 55 | i = 0; |
| 56 | memset (name, 'x', 252); |
| 57 | do { |
| 58 | sprintf (name + 252, "%02d", i); |
| 59 | strcpy (path, LPF); |
| 60 | strcat (path, "/"); |
| 61 | strcat (path, name); |
| 62 | if ((d = creat (path, 0644)) == -1) { |
| 63 | perror ("creat"); |
| 64 | exit (1); |
| 65 | } |
| 66 | i++; |
| 67 | close (d); |
| 68 | if (stat (LPF, &st) == -1) { |
| 69 | perror ("stat"); |
| 70 | exit (1); |
| 71 | } |
| 72 | } while (st.st_size <= (EXT2_NDIR_BLOCKS - 1) * st.st_blksize); |
| 73 | for (j = 0; j < i; j++) { |
| 74 | sprintf (name + 252, "%02d", j); |
| 75 | strcpy (path, LPF); |
| 76 | strcat (path, "/"); |
| 77 | strcat (path, name); |
| 78 | if (unlink (path) == -1) { |
| 79 | perror ("unlink"); |
| 80 | exit (1); |
| 81 | } |
| 82 | } |
| 83 | exit (0); |
| 84 | } |