2 * Copyright (c) 2008 Jakub Jermar
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <str_error.h>
38 #include "../tester.h"
40 #define TEST_DIRECTORY "/tmp/testdir"
41 #define TEST_FILE TEST_DIRECTORY "/testfile"
42 #define TEST_FILE2 TEST_DIRECTORY "/nextfile"
44 #define MAX_DEVICE_NAME 32
47 static char text
[] = "Lorem ipsum dolor sit amet, consectetur adipisicing elit";
49 static const char *read_root(void)
51 TPRINTF("Opening the root directory...");
53 DIR *dirp
= opendir("/");
56 return "opendir() failed";
61 while ((dp
= readdir(dirp
)))
62 TPRINTF(" node \"%s\"\n", dp
->d_name
);
68 const char *test_vfs1(void)
73 rc
= vfs_link_path(TEST_DIRECTORY
, KIND_DIRECTORY
, NULL
);
75 TPRINTF("rc=%s\n", str_error_name(rc
));
76 return "vfs_link_path() failed";
78 TPRINTF("Created directory %s\n", TEST_DIRECTORY
);
81 rc
= vfs_lookup_open(TEST_FILE
, WALK_REGULAR
| WALK_MAY_CREATE
,
82 MODE_READ
| MODE_WRITE
, &fd0
);
84 return "vfs_lookup_open() failed";
85 TPRINTF("Created file %s (fd=%d)\n", TEST_FILE
, fd0
);
87 size_t size
= sizeof(text
);
89 rc
= vfs_write(fd0
, &pos
, text
, size
, &cnt
);
91 return "write() failed";
92 TPRINTF("Written %zd bytes\n", cnt
);
98 while ((rc
= vfs_read(fd0
, &pos
, buf
, BUF_SIZE
, &cnt
))) {
99 TPRINTF("read returns rc = %s, cnt = %zu\n", str_error_name(rc
), cnt
);
101 return "read() failed";
103 int icnt
= (int) cnt
;
104 if ((size_t) icnt
!= cnt
) {
105 /* Count overflow, just to be sure. */
106 TPRINTF("Read %zd bytes\n", cnt
);
108 TPRINTF("Read %zd bytes: \"%.*s\"\n", cnt
, icnt
, buf
);
114 const char *rv
= read_root();
118 if (vfs_rename_path(TEST_FILE
, TEST_FILE2
) != EOK
)
119 return "vfs_rename_path() failed";
120 TPRINTF("Renamed %s to %s\n", TEST_FILE
, TEST_FILE2
);
122 if (vfs_unlink_path(TEST_FILE2
) != EOK
)
123 return "vfs_unlink_path() failed";
124 TPRINTF("Unlinked %s\n", TEST_FILE2
);
126 if (vfs_unlink_path(TEST_DIRECTORY
) != EOK
)
127 return "vfs_unlink_path() failed";
128 TPRINTF("Removed directory %s\n", TEST_DIRECTORY
);