Trove hackfest work with appropriate copyright notices and licence files added
[hurd/trovefs.git] / node.c
1 /*
2  * Copyright (C) 1997, 2006 Free Software Foundation, Inc.
3  * Copyright (C) 2013  Steven McDonald <steven@steven-mcdonald.id.au>
4  *
5  * ftpfs translator written by Miles Bader <miles@gnu.ai.mit.edu>
6  * Modified for trovefs by Steven McDonald <steven@steven-mcdonald.id.au>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2, or (at your option)
11  * any later version.
12  *
13  * This software is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
21  */
22
23 #include <stdlib.h>
24 #include <string.h>
25 #include <hurd/netfs.h>
26 #include "trovefs.h"
27
28 error_t
29 trovefs_create_node (struct trovefs_dir_entry *e, const char *rmt_path, struct node **node)
30 {
31         struct node *new;
32         struct netnode *nn = malloc (sizeof (struct netnode));
33         error_t err;
34
35         if (! nn)
36                 return ENOMEM;
37
38         nn->fs = e->dir->fs;
39         nn->dir_entry = e;
40         nn->contents = 0;
41         nn->dir = 0;
42         nn->rmt_path = strdup (rmt_path);
43         nn->ncache_next = nn->ncache_prev = 0;
44
45         new = netfs_make_node (nn);
46         if (! new)
47         {
48                 free (nn);
49                 return ENOMEM;
50         }
51
52         pthread_spin_lock (&nn->fs->inode_mappings_lock);
53         err = hurd_ihash_add (&nn->fs->inode_mappings, e->stat.st_ino, e);
54         pthread_spin_unlock (&nn->fs->inode_mappings_lock);
55
56         if (err)
57         {
58                 free (nn);
59                 free (new);
60                 return err;
61         }
62
63         e->node = new;
64         *node = new;
65
66         return 0;
67 }