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