Debian Codegraph @

libnpclient/remove.c

raw
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 <unistd.h>
29 #include <sys/types.h>
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <stdarg.h>
33 #include <string.h>
34 #include <unistd.h>
35 #include <pthread.h>
36 #include <errno.h>
37 #include <stdint.h>
38 #include <inttypes.h>
39 #include <libgen.h>
40
41 #include "9p.h"
42 #include "npfs.h"
43 #include "npclient.h"
44 #include "npcimpl.h"
45
46 int
47 npc_remove (Npcfid *fid)
48 {
49 Npfcall *tc = NULL, *rc = NULL;
50 int ret = -1;
51
52 if (!(tc = np_create_tremove(fid->fid))) {
53 np_uerror (ENOMEM);
54 goto done;
55 }
56 if (fid->fsys->rpc(fid->fsys, tc, &rc) < 0)
57 goto done;
58 ret = 0;
59 done:
60 npc_fid_free (fid); /* fid is no longer valid after remove */
61 if (tc)
62 free(tc);
63 if (rc)
64 free(rc);
65 return ret;
66 }
67
68 int
69 npc_remove_bypath (Npcfid *root, char *path)
70 {
71 Npcfid *fid;
72
73 if (!(fid = npc_walk (root, path)))
74 return -1;
75 if (npc_remove (fid) < 0)
76 return -1;
77 return 0;
78 }