| 1 |
/* |
| 2 |
* Copyright (C) 2006 by Latchesar Ionkov <[email protected]> |
| 3 |
* Copyright (C) 2010-2014 by Lawrence Livermore National Security, LLC |
| 4 |
* |
| 5 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 6 |
* copy of this software and associated documentation files (the "Software"), |
| 7 |
* to deal in the Software without restriction, including without limitation |
| 8 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 10 |
* Software is furnished to do so, subject to the following conditions: |
| 11 |
* |
| 12 |
* The above copyright notice and this permission notice (including the next |
| 13 |
* paragraph) shall be included in all copies or substantial portions of the |
| 14 |
* Software. |
| 15 |
* |
| 16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 |
* PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 20 |
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 21 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 |
* DEALINGS IN THE SOFTWARE. |
| 23 |
*/ |
| 24 |
|
| 25 |
#if HAVE_CONFIG_H |
| 26 |
#include "config.h" |
| 27 |
#endif |
| 28 |
#include <stdlib.h> |
| 29 |
#include <stdarg.h> |
| 30 |
#include <stdio.h> |
| 31 |
#include <string.h> |
| 32 |
#include <unistd.h> |
| 33 |
#include <pthread.h> |
| 34 |
#include <errno.h> |
| 35 |
#include <stdint.h> |
| 36 |
#include <inttypes.h> |
| 37 |
|
| 38 |
#include "9p.h" |
| 39 |
#include "npfs.h" |
| 40 |
#include "npclient.h" |
| 41 |
#include "npcimpl.h" |
| 42 |
|
| 43 |
Npcfid * |
| 44 |
npc_fid_alloc(Npcfsys *fs) |
| 45 |
{ |
| 46 |
Npcfid *ret; |
| 47 |
|
| 48 |
ret = malloc(sizeof(*ret)); |
| 49 |
if (!ret) { |
| 50 |
np_uerror(ENOMEM); |
| 51 |
return NULL; |
| 52 |
} |
| 53 |
|
| 54 |
ret->fsys = fs; |
| 55 |
ret->fid = npc_get_id(fs->fidpool); |
| 56 |
ret->offset = 0; |
| 57 |
ret->iounit = 0; |
| 58 |
ret->buf = NULL; |
| 59 |
|
| 60 |
fs->incref(fs); |
| 61 |
return ret; |
| 62 |
} |
| 63 |
|
| 64 |
void |
| 65 |
npc_fid_free(Npcfid *fid) |
| 66 |
{ |
| 67 |
if (fid) { |
| 68 |
if (fid->buf) |
| 69 |
free (fid->buf); |
| 70 |
npc_put_id(fid->fsys->fidpool, fid->fid); |
| 71 |
fid->fsys->decref(fid->fsys); |
| 72 |
free(fid); |
| 73 |
} |
| 74 |
} |