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 <[email protected]>
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 *
15 * - The times argument is not NULL.
16 * - The user ID of the process is "root".
17 */
18
19 #include <utime.h>
20 #include "tst_test.h"
21
22 #define MNT_POINT "mntpoint"
23 #define TEMP_FILE MNT_POINT"/tmp_file"
24
25 #define FILE_MODE 0444
26 #define NEW_MODF_TIME 10000
27 #define NEW_ACCESS_TIME 20000
28
29 static struct utimbuf times = {
30 .modtime = NEW_MODF_TIME,
31 .actime = NEW_ACCESS_TIME
32 };
33
setup(void)34 static void setup(void)
35 {
36 SAFE_TOUCH(TEMP_FILE, FILE_MODE, NULL);
37 }
38
run(void)39 static void run(void)
40 {
41 struct stat stat_buf;
42
43 TST_EXP_PASS(utime(TEMP_FILE, ×), "utime(%s, ×)", TEMP_FILE);
44 if (!TST_PASS)
45 return;
46
47 SAFE_STAT(TEMP_FILE, &stat_buf);
48
49 TST_EXP_EQ_LI(stat_buf.st_mtime, NEW_MODF_TIME);
50 TST_EXP_EQ_LI(stat_buf.st_atime, NEW_ACCESS_TIME);
51 }
52
53 static struct tst_test test = {
54 .test_all = run,
55 .setup = setup,
56 .needs_root = 1,
57 .mount_device = 1,
58 .mntpoint = MNT_POINT,
59 .all_filesystems = 1,
60 .skip_filesystems = (const char *const[]) {
61 "vfat",
62 "exfat",
63 NULL
64 }
65 };
66