source: rtems/testsuites/fstests/fslink/test.c @ 6fed43e

4.115
Last change on this file since 6fed43e was 6fed43e, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 2, 2011 at 2:24:59 PM

2011-08-02 Xiang Cui <medivhc@…>

  • configure.ac, fserror/test.c, fslink/test.c, fspermission/test.c, fsrdwr/init.c, fssymlink/test.c, fstime/test.c, mdosfs_support/fs_config.h, mdosfs_support/fs_support.c, mimfs_support/fs_support.c, mrfs_support/fs_config.h, support/fstest.h, support/fstest_support.c, support/ramdisk_support.c, support/ramdisk_support.h: Perform first phase of clean up.
  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2011.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.com/license/LICENSE.
8 *
9 *  $Id Exp $
10 */
11
12#include <unistd.h>
13#include <fcntl.h>
14#include <limits.h>
15#include <stdio.h>
16#include <unistd.h>
17#include <errno.h>
18#include <sys/stat.h>
19#include <time.h>
20#include <stdint.h>
21#include <math.h>
22
23#include "fstest.h"
24
25/*
26 * Test if the successful call works as expect
27 */
28void link_test01 (void)
29{
30  char *name0 = "t0";
31  char *name1 = "t1";
32  char *name2 = "t2";
33
34
35  int status;
36  int fd;
37
38  mode_t mode = 0644;
39  struct stat statbuf;
40
41
42  puts ("link creates hardlinks");
43  fd = creat (name0, mode);
44  status = close (fd);
45  rtems_test_assert (status == 0);
46
47  status = stat (name0, &statbuf);
48  rtems_test_assert (status == 0);
49  rtems_test_assert (statbuf.st_nlink == 1);
50
51  puts ("test if the stat is the same");
52  status = link (name0, name1);
53  rtems_test_assert (status == 0);
54
55  status = stat (name0, &statbuf);
56  rtems_test_assert (status == 0);
57
58  rtems_test_assert (S_ISREG (statbuf.st_mode));
59  rtems_test_assert (statbuf.st_nlink == 2);
60
61  status = stat (name1, &statbuf);
62  rtems_test_assert (status == 0);
63
64  rtems_test_assert (S_ISREG (statbuf.st_mode));
65  rtems_test_assert (statbuf.st_nlink == 2);
66
67  /*
68   * link the file and check the nlink
69   */
70  status = link (name1, name2);
71  rtems_test_assert (status == 0);
72
73  status = stat (name0, &statbuf);
74  rtems_test_assert (status == 0);
75
76  rtems_test_assert (S_ISREG (statbuf.st_mode));
77  rtems_test_assert (statbuf.st_nlink == 3);
78
79  status = stat (name1, &statbuf);
80  rtems_test_assert (status == 0);
81
82  rtems_test_assert (S_ISREG (statbuf.st_mode));
83  rtems_test_assert (statbuf.st_nlink == 3);
84
85  status = stat (name2, &statbuf);
86  rtems_test_assert (status == 0);
87
88  rtems_test_assert (S_ISREG (statbuf.st_mode));
89  rtems_test_assert (statbuf.st_nlink == 3);
90
91  /*
92   *  call chmod and chown and test.
93   */
94  puts ("chmod and chown");
95
96  chown (name1, 65534, 65533);
97
98  status = stat (name0, &statbuf);
99  rtems_test_assert (status == 0);
100
101  rtems_test_assert (S_ISREG (statbuf.st_mode));
102  rtems_test_assert (statbuf.st_nlink == 3);
103  rtems_test_assert (statbuf.st_uid = 65534);
104  rtems_test_assert (statbuf.st_gid = 65533);
105
106  status = stat (name1, &statbuf);
107  rtems_test_assert (status == 0);
108
109  rtems_test_assert (S_ISREG (statbuf.st_mode));
110  rtems_test_assert (statbuf.st_nlink == 3);
111  rtems_test_assert (statbuf.st_uid = 65534);
112  rtems_test_assert (statbuf.st_gid = 65533);
113
114  status = stat (name2, &statbuf);
115  rtems_test_assert (status == 0);
116
117  rtems_test_assert (S_ISREG (statbuf.st_mode));
118  rtems_test_assert (statbuf.st_nlink == 3);
119  rtems_test_assert (statbuf.st_uid = 65534);
120  rtems_test_assert (statbuf.st_gid = 65533);
121
122  /*
123   *
124   *  unlink then test if the nlink changes
125   */
126  puts ("unlink then stat the file ");
127
128  status = unlink (name0);
129  rtems_test_assert (status == 0);
130
131  status = stat (name0, &statbuf);
132  rtems_test_assert (status == -1);
133  rtems_test_assert (errno = ENOENT);
134
135  status = stat (name1, &statbuf);
136  rtems_test_assert (status == 0);
137  rtems_test_assert (S_ISREG (statbuf.st_mode));
138  rtems_test_assert (statbuf.st_nlink == 2);
139
140  status = stat (name2, &statbuf);
141  rtems_test_assert (status == 0);
142  rtems_test_assert (S_ISREG (statbuf.st_mode));
143  rtems_test_assert (statbuf.st_nlink == 2);
144
145  status = unlink (name1);
146  rtems_test_assert (status == 0);
147
148  status = unlink (name2);
149  rtems_test_assert (status == 0);
150
151}
152
153void test (void)
154{
155  puts ("\n\n*** LINK TEST ***");
156  link_test01 ();
157  puts ("*** END OF LINK TEST ***");
158}
Note: See TracBrowser for help on using the repository browser.