yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * hold_inode.c --- test program which holds an inode or directory |
| 3 | * open. |
| 4 | * |
| 5 | * Copyright (C) 2000 Theodore Ts'o. |
| 6 | * |
| 7 | * %Begin-Header% |
| 8 | * This file may be redistributed under the terms of the GNU Public |
| 9 | * License. |
| 10 | * %End-Header% |
| 11 | */ |
| 12 | |
| 13 | #include "config.h" |
| 14 | #include <unistd.h> |
| 15 | #include <stdio.h> |
| 16 | #include <dirent.h> |
| 17 | #include <sys/types.h> |
| 18 | #include <sys/stat.h> |
| 19 | #include <fcntl.h> |
| 20 | |
| 21 | |
| 22 | main(int argc, char **argv) |
| 23 | { |
| 24 | struct stat statbuf; |
| 25 | char *filename; |
| 26 | |
| 27 | if (argc != 2) { |
| 28 | fprintf(stderr, "Usage: %s dir\n", argv[0]); |
| 29 | exit(1); |
| 30 | } |
| 31 | filename = argv[1]; |
| 32 | if (stat(filename, &statbuf) < 0) { |
| 33 | perror(filename); |
| 34 | exit(1); |
| 35 | } |
| 36 | if (S_ISDIR(statbuf.st_mode)) { |
| 37 | if (!opendir(filename)) { |
| 38 | perror(filename); |
| 39 | exit(1); |
| 40 | } |
| 41 | } else { |
| 42 | if (open(filename, O_RDONLY) < 0) { |
| 43 | perror(filename); |
| 44 | exit(1); |
| 45 | } |
| 46 | } |
| 47 | sleep(30); |
| 48 | } |