1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) International Business Machines Corp., 2001 4f08c3bdfSopenharmony_ci * 07/2001 ported by John George 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 the system call utime() successfully changes the last 12f08c3bdfSopenharmony_ci * access and modification times of a file to the values specified by 13f08c3bdfSopenharmony_ci * times argument, under the following constraints: 14f08c3bdfSopenharmony_ci * 15f08c3bdfSopenharmony_ci * - The times argument is not NULL. 16f08c3bdfSopenharmony_ci * - The user ID of the process is "root". 17f08c3bdfSopenharmony_ci */ 18f08c3bdfSopenharmony_ci 19f08c3bdfSopenharmony_ci#include <utime.h> 20f08c3bdfSopenharmony_ci#include "tst_test.h" 21f08c3bdfSopenharmony_ci 22f08c3bdfSopenharmony_ci#define MNT_POINT "mntpoint" 23f08c3bdfSopenharmony_ci#define TEMP_FILE MNT_POINT"/tmp_file" 24f08c3bdfSopenharmony_ci 25f08c3bdfSopenharmony_ci#define FILE_MODE 0444 26f08c3bdfSopenharmony_ci#define NEW_MODF_TIME 10000 27f08c3bdfSopenharmony_ci#define NEW_ACCESS_TIME 20000 28f08c3bdfSopenharmony_ci 29f08c3bdfSopenharmony_cistatic struct utimbuf times = { 30f08c3bdfSopenharmony_ci .modtime = NEW_MODF_TIME, 31f08c3bdfSopenharmony_ci .actime = NEW_ACCESS_TIME 32f08c3bdfSopenharmony_ci}; 33f08c3bdfSopenharmony_ci 34f08c3bdfSopenharmony_cistatic void setup(void) 35f08c3bdfSopenharmony_ci{ 36f08c3bdfSopenharmony_ci SAFE_TOUCH(TEMP_FILE, FILE_MODE, NULL); 37f08c3bdfSopenharmony_ci} 38f08c3bdfSopenharmony_ci 39f08c3bdfSopenharmony_cistatic void run(void) 40f08c3bdfSopenharmony_ci{ 41f08c3bdfSopenharmony_ci struct stat stat_buf; 42f08c3bdfSopenharmony_ci 43f08c3bdfSopenharmony_ci TST_EXP_PASS(utime(TEMP_FILE, ×), "utime(%s, ×)", TEMP_FILE); 44f08c3bdfSopenharmony_ci if (!TST_PASS) 45f08c3bdfSopenharmony_ci return; 46f08c3bdfSopenharmony_ci 47f08c3bdfSopenharmony_ci SAFE_STAT(TEMP_FILE, &stat_buf); 48f08c3bdfSopenharmony_ci 49f08c3bdfSopenharmony_ci TST_EXP_EQ_LI(stat_buf.st_mtime, NEW_MODF_TIME); 50f08c3bdfSopenharmony_ci TST_EXP_EQ_LI(stat_buf.st_atime, NEW_ACCESS_TIME); 51f08c3bdfSopenharmony_ci} 52f08c3bdfSopenharmony_ci 53f08c3bdfSopenharmony_cistatic struct tst_test test = { 54f08c3bdfSopenharmony_ci .test_all = run, 55f08c3bdfSopenharmony_ci .setup = setup, 56f08c3bdfSopenharmony_ci .needs_root = 1, 57f08c3bdfSopenharmony_ci .mount_device = 1, 58f08c3bdfSopenharmony_ci .mntpoint = MNT_POINT, 59f08c3bdfSopenharmony_ci .all_filesystems = 1, 60f08c3bdfSopenharmony_ci .skip_filesystems = (const char *const[]) { 61f08c3bdfSopenharmony_ci "vfat", 62f08c3bdfSopenharmony_ci "exfat", 63f08c3bdfSopenharmony_ci NULL 64f08c3bdfSopenharmony_ci } 65f08c3bdfSopenharmony_ci}; 66