source: mainline/uspace/srv/fs/tmpfs/tmpfs.c@ b596d0d

ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b596d0d was 01900b6, checked in by Martin Decky <martin@…>, 5 years ago

Use an optional output argument instead of errno to propagate the error

The use of errno is troublesome in all other than top-level library
functions since the value in errno might get overwritten by subsequent
inner calls on the error path (e.g. cleanup, deallocation, etc.). The
optional output argument makes it possible to explicitly ignore the
error code if it is not needed, but still to pass it reliably back to
the original caller.

This change affecs async_connect_me_to(),
async_connect_me_to_blocking(), async_connect_kbox(), service_connect(),
service_connect_blocking() and loader_connect().

  • Property mode set to 100644
File size: 3.0 KB
RevLine 
[d5cdffe]1/*
2 * Copyright (c) 2006 Martin Decky
[cad9c72]3 * Copyright (c) 2008 Jakub Jermar
[d5cdffe]4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
[b1834a01]30/** @addtogroup tmpfs
[d5cdffe]31 * @{
[79ae36dd]32 */
[d5cdffe]33
34/**
35 * @file tmpfs.c
36 * @brief File system driver for in-memory file system.
37 *
38 * Every instance of tmpfs exists purely in memory and has neither a disk layout
39 * nor any permanent storage (e.g. disk blocks). With each system reboot, data
40 * stored in a tmpfs file system is lost.
41 */
42
43#include "tmpfs.h"
44#include <ipc/services.h>
[79ae36dd]45#include <ns.h>
[d5cdffe]46#include <async.h>
47#include <errno.h>
[c1694b6b]48#include <str_error.h>
[d5cdffe]49#include <stdio.h>
[bbddafb]50#include <task.h>
[d5cdffe]51#include <libfs.h>
[1d6dd2a]52#include <str.h>
[d5cdffe]53#include "../../vfs/vfs.h"
54
[76f566d]55#define NAME "tmpfs"
[d5cdffe]56
57vfs_info_t tmpfs_vfs_info = {
[5643a04]58 .name = NAME,
[5581b469]59 .concurrent_read_write = false,
60 .write_retains_size = false,
[4979403]61 .instance = 0,
[d5cdffe]62};
63
64int main(int argc, char **argv)
65{
[76f566d]66 printf("%s: HelenOS TMPFS file system server\n", NAME);
[4979403]67
68 if (argc == 3) {
69 if (!str_cmp(argv[1], "--instance"))
70 tmpfs_vfs_info.instance = strtol(argv[2], NULL, 10);
71 else {
[76f566d]72 printf("%s: Unrecognized parameters", NAME);
[4979403]73 return -1;
74 }
75 }
[a35b458]76
[8d049ee0]77 if (!tmpfs_init()) {
[76f566d]78 printf("%s: Failed to initialize TMPFS\n", NAME);
[8d049ee0]79 return -1;
80 }
[a35b458]81
[01900b6]82 errno_t rc;
[f9b2cb4c]83 async_sess_t *vfs_sess = service_connect_blocking(SERVICE_VFS,
[01900b6]84 INTERFACE_VFS_DRIVER, 0, &rc);
[79ae36dd]85 if (!vfs_sess) {
[01900b6]86 printf("%s: Unable to connect to VFS: %s\n", NAME, str_error(rc));
[a32c9bb]87 return -1;
[d5cdffe]88 }
[a35b458]89
[01900b6]90 rc = fs_register(vfs_sess, &tmpfs_vfs_info, &tmpfs_ops,
[efcebe1]91 &tmpfs_libfs_ops);
[d5cdffe]92 if (rc != EOK) {
[76f566d]93 printf("%s: Failed to register file system: %s\n", NAME,
94 str_error(rc));
[d5cdffe]95 return rc;
96 }
[a35b458]97
[76f566d]98 printf("%s: Accepting connections\n", NAME);
[bbddafb]99 task_retval(0);
[d5cdffe]100 async_manager();
[a35b458]101
[79ae36dd]102 /* Not reached */
[d5cdffe]103 return 0;
104}
105
106/**
107 * @}
[79ae36dd]108 */
Note: See TracBrowser for help on using the repository browser.