source: rtems/testsuites/fstests/fslink/test.c @ f8d760b

4.115
Last change on this file since f8d760b was 858e013f, checked in by Joel Sherrill <joel.sherrill@…>, on 08/01/11 at 20:54:15

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

  • Makefile.am, configure.ac, fslink/fslink.doc, fslink/test.c, fssymlink/test.c, imfs_fslink/Makefile.am, imfs_fssymlink/Makefile.am, imfs_support/fs_config.h, imfs_support/fs_support.c, mdosfs_support/fs_config.h, mdosfs_support/fs_support.c, mimfs_fslink/Makefile.am, mimfs_fssymlink/Makefile.am, mimfs_support/fs_config.h, mimfs_support/fs_support.c, mrfs_fslink/Makefile.am, mrfs_fssymlink/Makefile.am, mrfs_support/fs_config.h, mrfs_support/fs_support.c, support/fstest.h, support/fstest_support.c, support/fstest_support.h, support/ramdisk_support.c, support/ramdisk_support.h: Submit correct tarball of current work.
  • fs01/init.c, fsfchx/fsfchx.doc, fsfchx/init.c, fsfile01/fsfile01.doc, fsfile01/test.c, fsfile01/test_cat.c, fsfile01/test_extend.c, fsfile01/test_write.c, fsfile02/fsfile02.doc, fsfile02/init.c, fsfstest/fs-test.c, fsfstest/fsfstest.doc, fsimfs01/fsimfs01.doc, fsimfs01/init.c, fsimfs02/fsimfs02.doc, fsimfs02/init.c, fsmkdir/fsmkdir.doc, fsmkdir/test.c, fsopen/fsopen.doc, fsopen/test.c, fsrdwrv/fsrdwrv.doc, fsrdwrv/test.c, fsreaddir/fsreaddir.doc, fsreaddir/test.c, fsrename/fsrename.doc, fsrename/test.c, fsrmdir/test.c, fsrwfile/fsrwfile.doc, fsrwfile/init.c, fsstat/fsstat.doc, fsstat/test.c, fstruncate/fstruncate.doc, fstruncate/test.c, imfs_fs01/.cvsignore, imfs_fs01/Makefile.am, imfs_fs01/imfs_fs01.scn, imfs_fsfchx/.cvsignore, imfs_fsfchx/Makefile.am, imfs_fsfile01/.cvsignore, imfs_fsfile01/Makefile.am, imfs_fsfile02/.cvsignore, imfs_fsfile02/Makefile.am, imfs_fsfstest/.cvsignore, imfs_fsfstest/Makefile.am, imfs_fsimfs01/.cvsignore, imfs_fsimfs01/Makefile.am, imfs_fsimfs02/.cvsignore, imfs_fsimfs02/Makefile.am, imfs_fslink/.cvsignore, imfs_fsmkdir/.cvsignore, imfs_fsmkdir/Makefile.am, imfs_fsopen/.cvsignore, imfs_fsopen/Makefile.am, imfs_fsrdwrv/.cvsignore, imfs_fsrdwrv/Makefile.am, imfs_fsreaddir/.cvsignore, imfs_fsreaddir/Makefile.am, imfs_fsrename/.cvsignore, imfs_fsrename/Makefile.am, imfs_fsrmdir/.cvsignore, imfs_fsrmdir/Makefile.am, imfs_fsrwfile/.cvsignore, imfs_fsrwfile/Makefile.am, imfs_fsstat/.cvsignore, imfs_fsstat/Makefile.am, imfs_fssymlink/.cvsignore, imfs_fstruncate/.cvsignore, imfs_fstruncate/Makefile.am, mdosfs_fsfchx/.cvsignore, mdosfs_fsfchx/Makefile.am, mdosfs_fsfile01/.cvsignore, mdosfs_fsfile01/Makefile.am, mdosfs_fsfile02/.cvsignore, mdosfs_fsfile02/Makefile.am, mdosfs_fsfstest/.cvsignore, mdosfs_fsfstest/Makefile.am, mdosfs_fsimfs01/.cvsignore, mdosfs_fsimfs01/Makefile.am, mdosfs_fsimfs02/.cvsignore, mdosfs_fsimfs02/Makefile.am, mdosfs_fslink/.cvsignore, mdosfs_fslink/Makefile.am, mdosfs_fsmkdir/.cvsignore, mdosfs_fsmkdir/Makefile.am, mdosfs_fsopen/.cvsignore, mdosfs_fsopen/Makefile.am, mdosfs_fsrdwrv/.cvsignore, mdosfs_fsrdwrv/Makefile.am, mdosfs_fsreaddir/.cvsignore, mdosfs_fsreaddir/Makefile.am, mdosfs_fsrename/.cvsignore, mdosfs_fsrename/Makefile.am, mdosfs_fsrmdir/.cvsignore, mdosfs_fsrmdir/Makefile.am, mdosfs_fsrwfile/.cvsignore, mdosfs_fsrwfile/Makefile.am, mdosfs_fsstat/.cvsignore, mdosfs_fsstat/Makefile.am, mdosfs_fssymlink/.cvsignore, mdosfs_fssymlink/Makefile.am, mdosfs_fstruncate/.cvsignore, mdosfs_fstruncate/Makefile.am, mimfs_fs01/.cvsignore, mimfs_fs01/Makefile.am, mimfs_fs01/mimfs_fs01.scn, mimfs_fsfchx/.cvsignore, mimfs_fsfchx/Makefile.am, mimfs_fsfile01/.cvsignore, mimfs_fsfile01/Makefile.am, mimfs_fsfile02/.cvsignore, mimfs_fsfile02/Makefile.am, mimfs_fsfstest/.cvsignore, mimfs_fsfstest/Makefile.am, mimfs_fsimfs01/.cvsignore, mimfs_fsimfs01/Makefile.am, mimfs_fsimfs02/.cvsignore, mimfs_fsimfs02/Makefile.am, mimfs_fslink/.cvsignore, mimfs_fsmkdir/.cvsignore, mimfs_fsmkdir/Makefile.am, mimfs_fsopen/.cvsignore, mimfs_fsopen/Makefile.am, mimfs_fsrdwrv/.cvsignore, mimfs_fsrdwrv/Makefile.am, mimfs_fsreaddir/.cvsignore, mimfs_fsreaddir/Makefile.am, mimfs_fsrename/.cvsignore, mimfs_fsrename/Makefile.am, mimfs_fsrmdir/.cvsignore, mimfs_fsrmdir/Makefile.am, mimfs_fsrwfile/.cvsignore, mimfs_fsrwfile/Makefile.am, mimfs_fsstat/.cvsignore, mimfs_fsstat/Makefile.am, mimfs_fssymlink/.cvsignore, mimfs_fstruncate/.cvsignore, mimfs_fstruncate/Makefile.am, mrfs_fsfchx/.cvsignore, mrfs_fsfchx/Makefile.am, mrfs_fsfile01/.cvsignore, mrfs_fsfile01/Makefile.am, mrfs_fsfile02/.cvsignore, mrfs_fsfile02/Makefile.am, mrfs_fsfstest/.cvsignore, mrfs_fsfstest/Makefile.am, mrfs_fsimfs01/.cvsignore, mrfs_fsimfs01/Makefile.am, mrfs_fsimfs02/.cvsignore, mrfs_fsimfs02/Makefile.am, mrfs_fslink/.cvsignore, mrfs_fsmkdir/.cvsignore, mrfs_fsmkdir/Makefile.am, mrfs_fsopen/.cvsignore, mrfs_fsopen/Makefile.am, mrfs_fsrdwrv/.cvsignore, mrfs_fsrdwrv/Makefile.am, mrfs_fsreaddir/.cvsignore, mrfs_fsreaddir/Makefile.am, mrfs_fsrename/.cvsignore, mrfs_fsrename/Makefile.am, mrfs_fsrmdir/.cvsignore, mrfs_fsrmdir/Makefile.am, mrfs_fsrwfile/.cvsignore, mrfs_fsrwfile/Makefile.am, mrfs_fsstat/.cvsignore, mrfs_fsstat/Makefile.am, mrfs_fssymlink/.cvsignore, mrfs_fstruncate/.cvsignore, mrfs_fstruncate/Makefile.am: Removed.
  • 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.