File indexing completed on 2025-05-11 08:24:31
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #ifdef HAVE_CONFIG_H
0030 #include "config.h"
0031 #endif
0032
0033 #include <unistd.h>
0034 #include <fcntl.h>
0035 #include <limits.h>
0036 #include <stdio.h>
0037 #include <unistd.h>
0038 #include <errno.h>
0039 #include <sys/stat.h>
0040 #include <time.h>
0041 #include <stdint.h>
0042 #include <math.h>
0043
0044 #include "fstest.h"
0045 #include "fs_config.h"
0046 #include <tmacros.h>
0047
0048 const char rtems_test_name[] = "FSLINK " FILESYSTEM;
0049 const RTEMS_TEST_STATE rtems_test_state = TEST_STATE;
0050
0051
0052
0053
0054 static void link_test01 (void)
0055 {
0056 char *name0 = "t0";
0057 char *name1 = "t1";
0058 char *name2 = "t2";
0059
0060
0061 int status;
0062 int fd;
0063
0064 mode_t mode = 0644;
0065 struct stat statbuf;
0066
0067
0068 puts ("link creates hardlinks");
0069 fd = creat (name0, mode);
0070 status = close (fd);
0071 rtems_test_assert (status == 0);
0072
0073 status = stat (name0, &statbuf);
0074 rtems_test_assert (status == 0);
0075 rtems_test_assert (statbuf.st_nlink == 1);
0076
0077 puts ("test if the stat is the same");
0078 status = link (name0, name1);
0079 rtems_test_assert (status == 0);
0080
0081 status = stat (name0, &statbuf);
0082 rtems_test_assert (status == 0);
0083
0084 rtems_test_assert (S_ISREG (statbuf.st_mode));
0085 rtems_test_assert (statbuf.st_nlink == 2);
0086
0087 status = stat (name1, &statbuf);
0088 rtems_test_assert (status == 0);
0089
0090 rtems_test_assert (S_ISREG (statbuf.st_mode));
0091 rtems_test_assert (statbuf.st_nlink == 2);
0092
0093
0094
0095
0096 status = link (name1, name2);
0097 rtems_test_assert (status == 0);
0098
0099 status = stat (name0, &statbuf);
0100 rtems_test_assert (status == 0);
0101
0102 rtems_test_assert (S_ISREG (statbuf.st_mode));
0103 rtems_test_assert (statbuf.st_nlink == 3);
0104
0105 status = stat (name1, &statbuf);
0106 rtems_test_assert (status == 0);
0107
0108 rtems_test_assert (S_ISREG (statbuf.st_mode));
0109 rtems_test_assert (statbuf.st_nlink == 3);
0110
0111 status = stat (name2, &statbuf);
0112 rtems_test_assert (status == 0);
0113
0114 rtems_test_assert (S_ISREG (statbuf.st_mode));
0115 rtems_test_assert (statbuf.st_nlink == 3);
0116
0117
0118
0119
0120 puts ("chmod and chown");
0121
0122 chown (name1, 65534, 65533);
0123
0124 status = stat (name0, &statbuf);
0125 rtems_test_assert (status == 0);
0126
0127 rtems_test_assert (S_ISREG (statbuf.st_mode));
0128 rtems_test_assert (statbuf.st_nlink == 3);
0129 rtems_test_assert (statbuf.st_uid = 65534);
0130 rtems_test_assert (statbuf.st_gid = 65533);
0131
0132 status = stat (name1, &statbuf);
0133 rtems_test_assert (status == 0);
0134
0135 rtems_test_assert (S_ISREG (statbuf.st_mode));
0136 rtems_test_assert (statbuf.st_nlink == 3);
0137 rtems_test_assert (statbuf.st_uid = 65534);
0138 rtems_test_assert (statbuf.st_gid = 65533);
0139
0140 status = stat (name2, &statbuf);
0141 rtems_test_assert (status == 0);
0142
0143 rtems_test_assert (S_ISREG (statbuf.st_mode));
0144 rtems_test_assert (statbuf.st_nlink == 3);
0145 rtems_test_assert (statbuf.st_uid = 65534);
0146 rtems_test_assert (statbuf.st_gid = 65533);
0147
0148
0149
0150
0151
0152 puts ("unlink then stat the file ");
0153
0154 status = unlink (name0);
0155 rtems_test_assert (status == 0);
0156
0157 status = stat (name0, &statbuf);
0158 rtems_test_assert (status == -1);
0159 rtems_test_assert (errno = ENOENT);
0160
0161 status = stat (name1, &statbuf);
0162 rtems_test_assert (status == 0);
0163 rtems_test_assert (S_ISREG (statbuf.st_mode));
0164 rtems_test_assert (statbuf.st_nlink == 2);
0165
0166 status = stat (name2, &statbuf);
0167 rtems_test_assert (status == 0);
0168 rtems_test_assert (S_ISREG (statbuf.st_mode));
0169 rtems_test_assert (statbuf.st_nlink == 2);
0170
0171 status = unlink (name1);
0172 rtems_test_assert (status == 0);
0173
0174 status = unlink (name2);
0175 rtems_test_assert (status == 0);
0176
0177 }
0178
0179 void test (void)
0180 {
0181 link_test01 ();
0182 }