Changeset ea4a3f0 in mainline
- Timestamp:
- 2017-04-03T20:59:19Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a6fc88a
- Parents:
- 2c40637
- Location:
- uspace/lib/c
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/vfs/inbox.c
r2c40637 rea4a3f0 1 /* 2 * Copyright (c) 2013 Jiri Zarevucky 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 /** @addtogroup libc 30 * @{ 31 */ 32 33 /** 34 * @file 35 * @brief 36 */ 1 37 2 38 #include <vfs/inbox.h> … … 10 46 #include <errno.h> 11 47 12 /* This is an attempt at generalization of the "standard files" concept to arbitrary names. 13 * When loading a task, the parent can put arbitrary files to an "inbox" through IPC calls, 14 * every file in an inbox has a name assigned (e.g. "stdin", "stdout", "stderr", "data", "logfile", 15 * etc.). The client then retrieves those files from inbox by name. "stdin", "stdout" and "stderr" 16 * are handled automatically by libc to initialize standard <stdio.h> streams and legacy file 17 * descriptors 0, 1, 2. Other names are subject to conventions and application-specific rules. 48 /* 49 * This is an attempt at generalization of the "standard files" concept to 50 * arbitrary names. When loading a task, the parent can put arbitrary files to 51 * an "inbox" through IPC calls, every file in an inbox has a name assigned 52 * (e.g. "stdin", "stdout", "stderr", "data", "logfile", etc.). The client then 53 * retrieves those files from inbox by name. "stdin", "stdout" and "stderr" are 54 * handled automatically by libc to initialize standard <stdio.h> streams and 55 * legacy file descriptors 0, 1, 2. Other names are subject to conventions and 56 * application-specific rules. 18 57 */ 19 58 … … 27 66 28 67 /* Inserts a named file into the inbox. 29 * If a file with the same name is already present, it overwrites it and returns the original 30 * value. Otherwise, it returns -1. 31 * If the argument 'file' is -1, nothing is inserted and the file with specified name is 32 * removed and returned if present. 68 * 69 * If a file with the same name is already present, it overwrites it and returns 70 * the original value. Otherwise, it returns -1. If the argument 'file' is -1, 71 * nothing is inserted and the file with specified name is removed and returned 72 * if present. 33 73 * 34 74 * @param name Name of the inbox entry. … … 62 102 63 103 out: 64 if (file == -1) {104 if (file == -1) 65 105 return -1; 66 }67 106 68 107 inbox_entry *entry = calloc(sizeof(inbox_entry), 1); … … 98 137 } 99 138 100 /* Writes names of entries that are currently set into and array provided by the user. 139 /* Writes names of entries that are currently set into an array provided by the 140 * user. 101 141 * 102 142 * @param names Array in which names are stored. 103 143 * @param capacity Capacity of the array. 104 * @return Number of entries written. If capacity == 0, return the total number of entries. 144 * @return Number of entries written. If capacity == 0, return the total number 145 * of entries. 105 146 */ 106 147 int inbox_list(const char **names, int capacity) 107 148 { 108 if (capacity == 0) {149 if (capacity == 0) 109 150 return list_count(&inb_list); 110 }111 151 112 152 int used = 0; 113 153 114 154 list_foreach(inb_list, link, inbox_entry, e) { 115 if (used == capacity) {155 if (used == capacity) 116 156 return used; 117 }118 157 names[used] = e->name; 119 158 used++; … … 123 162 } 124 163 125 void __inbox_init(struct pcb_inbox_entry *entries, int count) { 164 void __inbox_init(struct pcb_inbox_entry *entries, int count) 165 { 126 166 for (int i = 0; i < count; i++) { 127 167 int original = inbox_set(entries[i].name, entries[i].file); 128 if (original >= 0) {168 if (original >= 0) 129 169 vfs_put(original); 130 }131 170 } 132 171 } 172 173 /** 174 * @} 175 */ -
uspace/lib/c/include/vfs/inbox.h
r2c40637 rea4a3f0 1 /* 2 * Copyright (c) 2013 Jiri Zarevucky 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 /** @addtogroup libc 30 * @{ 31 */ 32 33 /** 34 * @file 35 * @brief 36 */ 1 37 2 38 #ifndef LIBC_VFS_INBOX_H_ … … 13 49 14 50 #endif 51 52 /** 53 * @} 54 */
Note:
See TracChangeset
for help on using the changeset viewer.