source: mainline/uspace/app/tester/vfs/vfs1.c@ 3061bc1

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3061bc1 was b7fd2a0, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 8 years ago

Use errno_t in all uspace and kernel code.

Change type of every variable, parameter and return value that holds an
<errno.h> constant to either errno_t (the usual case), or sys_errno_t
(some places in kernel). This is for the purpose of self-documentation,
as well as for type-checking with a bit of type definition hackery.

Although this is a massive commit, it is a simple text replacement, and thus
is very easy to verify. Simply do the following:

`
git checkout <this commit's hash>
git reset HEAD
git add .
tools/srepl '\berrno_t\b' int
git add .
tools/srepl '\bsys_errno_t\b' sysarg_t
git reset
git diff
`

While this doesn't ensure that the replacements are correct, it does ensure
that the commit doesn't do anything except those replacements. Since errno_t
is typedef'd to int in the usual case (and sys_errno_t to sysarg_t), even if
incorrect, this commit cannot change behavior.

  • Property mode set to 100644
File size: 3.8 KB
RevLine 
[6344851]1/*
[5973fd0]2 * Copyright (c) 2008 Jakub Jermar
[6344851]3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
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.
16 *
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.
27 */
28
29#include <errno.h>
30#include <stdio.h>
[986332aa]31#include <stdlib.h>
[8d2dd7f2]32#include <stddef.h>
[c1694b6b]33#include <str_error.h>
[19f857a]34#include <str.h>
[5fec355]35#include <vfs/vfs.h>
[5973fd0]36#include <dirent.h>
[15f3c3f]37#include <loc.h>
[6344851]38#include "../tester.h"
39
[6118ccaf]40#define TEST_DIRECTORY "/tmp/testdir"
[2d11a7d8]41#define TEST_FILE TEST_DIRECTORY "/testfile"
42#define TEST_FILE2 TEST_DIRECTORY "/nextfile"
43
44#define MAX_DEVICE_NAME 32
45#define BUF_SIZE 16
46
47static char text[] = "Lorem ipsum dolor sit amet, consectetur adipisicing elit";
48
[a000878c]49static const char *read_root(void)
[6344851]50{
[2d11a7d8]51 TPRINTF("Opening the root directory...");
52
53 DIR *dirp = opendir("/");
54 if (!dirp) {
55 TPRINTF("\n");
56 return "opendir() failed";
57 } else
58 TPRINTF("OK\n");
59
60 struct dirent *dp;
61 while ((dp = readdir(dirp)))
62 TPRINTF(" node \"%s\"\n", dp->d_name);
63 closedir(dirp);
64
65 return NULL;
66}
[2f60a529]67
[a000878c]68const char *test_vfs1(void)
[2d11a7d8]69{
[58898d1d]70 aoff64_t pos = 0;
[b7fd2a0]71 errno_t rc;
[58898d1d]72
[a6fc88a]73 rc = vfs_link_path(TEST_DIRECTORY, KIND_DIRECTORY, NULL);
[6e5562a]74 if (rc != EOK) {
[f77c1c9]75 TPRINTF("rc=%s\n", str_error_name(rc));
[6e5562a]76 return "vfs_link_path() failed";
[2f60a529]77 }
[2d11a7d8]78 TPRINTF("Created directory %s\n", TEST_DIRECTORY);
79
[f77c1c9]80 int fd0;
81 rc = vfs_lookup_open(TEST_FILE, WALK_REGULAR | WALK_MAY_CREATE,
82 MODE_READ | MODE_WRITE, &fd0);
83 if (rc != EOK)
[b19e892]84 return "vfs_lookup_open() failed";
[2d11a7d8]85 TPRINTF("Created file %s (fd=%d)\n", TEST_FILE, fd0);
86
[f7017572]87 size_t size = sizeof(text);
[8e3498b]88 size_t cnt;
89 rc = vfs_write(fd0, &pos, text, size, &cnt);
90 if (rc != EOK)
[2d11a7d8]91 return "write() failed";
[0b0f4bb]92 TPRINTF("Written %zd bytes\n", cnt);
[58898d1d]93
94 pos = 0;
[2d11a7d8]95
96 char buf[BUF_SIZE];
[6afc9d7]97 TPRINTF("read..\n");
[8e3498b]98 while ((rc = vfs_read(fd0, &pos, buf, BUF_SIZE, &cnt))) {
[c1694b6b]99 TPRINTF("read returns rc = %s, cnt = %zu\n", str_error_name(rc), cnt);
[8e3498b]100 if (rc != EOK)
[2d11a7d8]101 return "read() failed";
102
[8e3498b]103 int icnt = (int) cnt;
104 if ((size_t) icnt != cnt) {
[0b0f4bb]105 /* Count overflow, just to be sure. */
106 TPRINTF("Read %zd bytes\n", cnt);
107 } else {
[8e3498b]108 TPRINTF("Read %zd bytes: \"%.*s\"\n", cnt, icnt, buf);
[0b0f4bb]109 }
[1a60feeb]110 }
[2d11a7d8]111
[9c4cf0d]112 vfs_put(fd0);
[343dc9e3]113
[a000878c]114 const char *rv = read_root();
[2d11a7d8]115 if (rv != NULL)
116 return rv;
117
[163fc09]118 if (vfs_rename_path(TEST_FILE, TEST_FILE2) != EOK)
119 return "vfs_rename_path() failed";
[2d11a7d8]120 TPRINTF("Renamed %s to %s\n", TEST_FILE, TEST_FILE2);
121
[79ea5af]122 if (vfs_unlink_path(TEST_FILE2) != EOK)
123 return "vfs_unlink_path() failed";
[2d11a7d8]124 TPRINTF("Unlinked %s\n", TEST_FILE2);
125
[79ea5af]126 if (vfs_unlink_path(TEST_DIRECTORY) != EOK)
127 return "vfs_unlink_path() failed";
[2d11a7d8]128 TPRINTF("Removed directory %s\n", TEST_DIRECTORY);
129
130 rv = read_root();
131 if (rv != NULL)
132 return rv;
[343dc9e3]133
[6344851]134 return NULL;
135}
Note: See TracBrowser for help on using the repository browser.