Motr  M0
m0t1fs_fsync_test_helper.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Seagate Technology LLC and/or its Affiliates
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * For any questions about this software or licensing,
17  * please email opensource@seagate.com or cortx-questions@seagate.com.
18  *
19  */
20 
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <fcntl.h>
26 #include <unistd.h>
27 #include <limits.h>
28 #include <errno.h>
29 #include <string.h>
30 
34 int main(int argc, char **argv)
35 {
36  int rv = 0;
37  int fd = 0;
38  char *str = "Hello World\n";
39  char object_path[PATH_MAX];
40 
41  /* Check we were told the mount point. */
42  if (argc != 2) {
43  fprintf(stderr, "Usage: %s /path/to/mount/point\n", argv[0]);
44  exit(1);
45  }
46 
47  /* Build a path for our to-create object. */
48  rv = snprintf(object_path, sizeof(object_path), "%s/0:91837432", argv[1]);
49  if (rv >= sizeof(object_path)) {
50  fprintf(stderr, "Path overflow\n");
51  exit(1);
52  }
53 
54  fd = creat(object_path, 0600);
55  if (fd >= 0) {
56  /* Write some data. */
57  rv = write(fd, str, strlen(str));
58 
59  /* Try and fsync the file. */
60  rv = fsync(fd);
61 
62  /* fsync should return 0 for sucess. */
63  fprintf(stderr, "fsync returned: %d\n", rv);
64  } else {
65  fprintf(stderr, "Failed to creat %s: %s\n",
66  object_path, strerror(errno));
67  exit(1);
68  }
69 
70  return rv;
71 }
int main(int argc, char **argv)
struct m0t1fs_filedata * fd
Definition: dir.c:1030