mm: rename alloc_pages_exact_node() to __alloc_pages_node()
[linux/fpc-iii.git] / tools / testing / selftests / efivarfs / open-unlink.c
blob8c0764407b3c349431a6b78ca595e450e2661066
1 #include <stdio.h>
2 #include <stdint.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <fcntl.h>
9 int main(int argc, char **argv)
11 const char *path;
12 char buf[5];
13 int fd, rc;
15 if (argc < 2) {
16 fprintf(stderr, "usage: %s <path>\n", argv[0]);
17 return EXIT_FAILURE;
20 path = argv[1];
22 /* attributes: EFI_VARIABLE_NON_VOLATILE |
23 * EFI_VARIABLE_BOOTSERVICE_ACCESS |
24 * EFI_VARIABLE_RUNTIME_ACCESS
26 *(uint32_t *)buf = 0x7;
27 buf[4] = 0;
29 /* create a test variable */
30 fd = open(path, O_WRONLY | O_CREAT);
31 if (fd < 0) {
32 perror("open(O_WRONLY)");
33 return EXIT_FAILURE;
36 rc = write(fd, buf, sizeof(buf));
37 if (rc != sizeof(buf)) {
38 perror("write");
39 return EXIT_FAILURE;
42 close(fd);
44 fd = open(path, O_RDONLY);
45 if (fd < 0) {
46 perror("open");
47 return EXIT_FAILURE;
50 if (unlink(path) < 0) {
51 perror("unlink");
52 return EXIT_FAILURE;
55 rc = read(fd, buf, sizeof(buf));
56 if (rc > 0) {
57 fprintf(stderr, "reading from an unlinked variable "
58 "shouldn't be possible\n");
59 return EXIT_FAILURE;
62 return EXIT_SUCCESS;