1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. 4f08c3bdfSopenharmony_ci * Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com> 5f08c3bdfSopenharmony_ci */ 6f08c3bdfSopenharmony_ci 7f08c3bdfSopenharmony_ci/*\ 8f08c3bdfSopenharmony_ci * [Description] 9f08c3bdfSopenharmony_ci * 10f08c3bdfSopenharmony_ci * Verify that fstatfs() syscall executes successfully for all 11f08c3bdfSopenharmony_ci * available filesystems. 12f08c3bdfSopenharmony_ci */ 13f08c3bdfSopenharmony_ci 14f08c3bdfSopenharmony_ci 15f08c3bdfSopenharmony_ci#include <stdio.h> 16f08c3bdfSopenharmony_ci#include "tst_test.h" 17f08c3bdfSopenharmony_ci 18f08c3bdfSopenharmony_ci#define MNT_POINT "mntpoint" 19f08c3bdfSopenharmony_ci#define TEMP_FILE MNT_POINT"/test_file" 20f08c3bdfSopenharmony_ci 21f08c3bdfSopenharmony_cistatic int file_fd; 22f08c3bdfSopenharmony_cistatic int pipe_fd; 23f08c3bdfSopenharmony_ci 24f08c3bdfSopenharmony_cistatic struct tcase { 25f08c3bdfSopenharmony_ci int *fd; 26f08c3bdfSopenharmony_ci const char *msg; 27f08c3bdfSopenharmony_ci} tcases[] = { 28f08c3bdfSopenharmony_ci {&file_fd, "fstatfs() on a file"}, 29f08c3bdfSopenharmony_ci {&pipe_fd, "fstatfs() on a pipe"}, 30f08c3bdfSopenharmony_ci}; 31f08c3bdfSopenharmony_ci 32f08c3bdfSopenharmony_cistatic void run(unsigned int i) 33f08c3bdfSopenharmony_ci{ 34f08c3bdfSopenharmony_ci struct tcase *tc = &tcases[i]; 35f08c3bdfSopenharmony_ci struct statfs buf; 36f08c3bdfSopenharmony_ci 37f08c3bdfSopenharmony_ci TST_EXP_PASS(fstatfs(*tc->fd, &buf), "%s", tc->msg); 38f08c3bdfSopenharmony_ci} 39f08c3bdfSopenharmony_ci 40f08c3bdfSopenharmony_cistatic void setup(void) 41f08c3bdfSopenharmony_ci{ 42f08c3bdfSopenharmony_ci int pipe[2]; 43f08c3bdfSopenharmony_ci 44f08c3bdfSopenharmony_ci file_fd = SAFE_OPEN(TEMP_FILE, O_RDWR | O_CREAT, 0700); 45f08c3bdfSopenharmony_ci SAFE_PIPE(pipe); 46f08c3bdfSopenharmony_ci pipe_fd = pipe[0]; 47f08c3bdfSopenharmony_ci SAFE_CLOSE(pipe[1]); 48f08c3bdfSopenharmony_ci} 49f08c3bdfSopenharmony_ci 50f08c3bdfSopenharmony_cistatic void cleanup(void) 51f08c3bdfSopenharmony_ci{ 52f08c3bdfSopenharmony_ci if (file_fd > 0) 53f08c3bdfSopenharmony_ci SAFE_CLOSE(file_fd); 54f08c3bdfSopenharmony_ci if (pipe_fd > 0) 55f08c3bdfSopenharmony_ci SAFE_CLOSE(pipe_fd); 56f08c3bdfSopenharmony_ci} 57f08c3bdfSopenharmony_ci 58f08c3bdfSopenharmony_cistatic struct tst_test test = { 59f08c3bdfSopenharmony_ci .setup = setup, 60f08c3bdfSopenharmony_ci .cleanup = cleanup, 61f08c3bdfSopenharmony_ci .tcnt = ARRAY_SIZE(tcases), 62f08c3bdfSopenharmony_ci .test = run, 63f08c3bdfSopenharmony_ci .mount_device = 1, 64f08c3bdfSopenharmony_ci .mntpoint = MNT_POINT, 65f08c3bdfSopenharmony_ci .all_filesystems = 1, 66f08c3bdfSopenharmony_ci .needs_root = 1 67f08c3bdfSopenharmony_ci}; 68