2 * Copyright (c) 2006 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <sys/types.h>
27 #include <attr/attributes.h>
29 #define MAX_EA_NAME 30
32 * multi_open_unlink path_prefix num_files sleep_time
34 * $ multi_open_unlink file 100 60
35 * Creates 100 files: file.1, file.2, ..., file.100
36 * unlinks them all but doesn't close them all until after 60 seconds.
42 fprintf(stderr, "Usage: %s [-e num-eas] [-f path_prefix] [-n num_files] [-s sleep_time] [-v ea-valuesize] \n", prog);
47 main(int argc, char *argv[])
49 char *given_path = "file";
55 int value_size = ATTR_MAX_VALUELEN;
59 while ((c = getopt(argc, argv, "e:f:n:s:v:")) != EOF) {
61 case 'e': /* create eas */
62 num_eas = atoi(optarg);
64 case 'f': /* file prefix */
67 case 'n': /* number of files */
68 num_files = atoi(optarg);
70 case 's': /* sleep time */
71 sleep_time = atoi(optarg);
73 case 'v': /* value size on eas */
74 value_size = atoi(optarg);
81 /* create and unlink a bunch of files */
82 for (i = 0; i < num_files; i++) {
83 sprintf(path, "%s.%d", given_path, i+1);
85 /* if file already exists then error out */
86 if (access(path, F_OK) == 0) {
87 fprintf(stderr, "%s: file \"%s\" already exists\n", prog, path);
91 fd = open(path, O_RDWR|O_CREAT|O_EXCL);
93 fprintf(stderr, "%s: failed to create \"%s\": %s\n", prog, path, strerror(errno));
98 for (j = 0; j < num_eas; j++) {
101 char attrname[MAX_EA_NAME];
104 snprintf(attrname, MAX_EA_NAME, "user.name.%d", j);
106 attrvalue = calloc(value_size, 1);
107 if (attrvalue == NULL) {
108 fprintf(stderr, "%s: failed to create EA value of size %d on path \"%s\": %s\n",
109 prog, value_size, path, strerror(errno));
113 sts = attr_set(path, attrname, attrvalue, value_size, flags);
115 fprintf(stderr, "%s: failed to create EA \"%s\" of size %d on path \"%s\": %s\n",
116 prog, attrname, value_size, path, strerror(errno));
121 if (unlink(path) == -1) {
122 fprintf(stderr, "%s: failed to unlink \"%s\": %s\n",
123 prog, path, strerror(errno));