1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) Wipro Technologies Ltd, 2005. All Rights Reserved. 4f08c3bdfSopenharmony_ci * AUTHOR: Prashant P Yendigeri <prashant.yendigeri@wipro.com> 5f08c3bdfSopenharmony_ci * Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com> 6f08c3bdfSopenharmony_ci */ 7f08c3bdfSopenharmony_ci 8f08c3bdfSopenharmony_ci/*\ 9f08c3bdfSopenharmony_ci * [Description] 10f08c3bdfSopenharmony_ci * 11f08c3bdfSopenharmony_ci * Verify that statvfs() executes successfully for all 12f08c3bdfSopenharmony_ci * available filesystems. Verify statvfs.f_namemax field 13f08c3bdfSopenharmony_ci * by trying to create files of valid and invalid length names. 14f08c3bdfSopenharmony_ci */ 15f08c3bdfSopenharmony_ci 16f08c3bdfSopenharmony_ci#include <sys/statvfs.h> 17f08c3bdfSopenharmony_ci#include "tst_test.h" 18f08c3bdfSopenharmony_ci 19f08c3bdfSopenharmony_ci#define MNT_POINT "mntpoint" 20f08c3bdfSopenharmony_ci#define TEST_PATH MNT_POINT"/testfile" 21f08c3bdfSopenharmony_ci#define NLS_MAX_CHARSET_SIZE 6 22f08c3bdfSopenharmony_ci 23f08c3bdfSopenharmony_cistatic void run(void) 24f08c3bdfSopenharmony_ci{ 25f08c3bdfSopenharmony_ci struct statvfs buf; 26f08c3bdfSopenharmony_ci char valid_fname[PATH_MAX], toolong_fname[PATH_MAX]; 27f08c3bdfSopenharmony_ci long fs_type; 28f08c3bdfSopenharmony_ci long valid_len; 29f08c3bdfSopenharmony_ci 30f08c3bdfSopenharmony_ci fs_type = tst_fs_type(TEST_PATH); 31f08c3bdfSopenharmony_ci 32f08c3bdfSopenharmony_ci TST_EXP_PASS(statvfs(TEST_PATH, &buf)); 33f08c3bdfSopenharmony_ci 34f08c3bdfSopenharmony_ci valid_len = buf.f_namemax; 35f08c3bdfSopenharmony_ci if (fs_type == TST_VFAT_MAGIC || fs_type == TST_EXFAT_MAGIC) 36f08c3bdfSopenharmony_ci valid_len = buf.f_namemax / NLS_MAX_CHARSET_SIZE; 37f08c3bdfSopenharmony_ci 38f08c3bdfSopenharmony_ci memset(valid_fname, 'a', valid_len); 39f08c3bdfSopenharmony_ci memset(toolong_fname, 'b', valid_len + 1); 40f08c3bdfSopenharmony_ci 41f08c3bdfSopenharmony_ci valid_fname[valid_len] = 0; 42f08c3bdfSopenharmony_ci toolong_fname[valid_len+1] = 0; 43f08c3bdfSopenharmony_ci 44f08c3bdfSopenharmony_ci TST_EXP_FD(creat(valid_fname, 0444)); 45f08c3bdfSopenharmony_ci if (TST_PASS) 46f08c3bdfSopenharmony_ci SAFE_CLOSE(TST_RET); 47f08c3bdfSopenharmony_ci 48f08c3bdfSopenharmony_ci TST_EXP_FAIL(creat(toolong_fname, 0444), ENAMETOOLONG); 49f08c3bdfSopenharmony_ci} 50f08c3bdfSopenharmony_ci 51f08c3bdfSopenharmony_cistatic void setup(void) 52f08c3bdfSopenharmony_ci{ 53f08c3bdfSopenharmony_ci SAFE_TOUCH(TEST_PATH, 0666, NULL); 54f08c3bdfSopenharmony_ci} 55f08c3bdfSopenharmony_ci 56f08c3bdfSopenharmony_cistatic struct tst_test test = { 57f08c3bdfSopenharmony_ci .test_all = run, 58f08c3bdfSopenharmony_ci .setup = setup, 59f08c3bdfSopenharmony_ci .needs_root = 1, 60f08c3bdfSopenharmony_ci .mount_device = 1, 61f08c3bdfSopenharmony_ci .mntpoint = MNT_POINT, 62f08c3bdfSopenharmony_ci .all_filesystems = 1 63f08c3bdfSopenharmony_ci}; 64