summaryrefslogtreecommitdiff
path: root/ftpfs/fs.c
blob: 18f5a358a73afb01a039ab4ae437eedb2762c1ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* Fs operations

   Copyright (C) 1997 Free Software Foundation, Inc.
   Written by Miles Bader <miles@gnu.ai.mit.edu>
   This file is part of the GNU Hurd.

   The GNU Hurd is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2, or (at
   your option) any later version.

   The GNU Hurd is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA. */

#include <string.h>

#include <hurd/ihash.h>
#include <hurd/netfs.h>

#include "ftpfs.h"

/* Create a new ftp filesystem with the given parameters.  */
error_t
ftpfs_create (char *rmt_path, int fsid,
	      struct ftp_conn_params *ftp_params,
	      struct ftp_conn_hooks *ftp_hooks,
	      struct ftpfs_params *params,
	      struct ftpfs **fs)
{
  error_t err;
  /* Since nodes keep some of their state in the enclosing directory, we need
     one for the root node.  */
  struct ftpfs_dir *super_root_dir;
  /* And also a super-root node, just used for locking SUPER_ROOT_DIR.  */
  struct node *super_root;
  /* The new node.  */
  struct ftpfs *new = malloc (sizeof (struct ftpfs));

  if (! new)
    return ENOMEM;

  new->free_conns = 0;
  new->conns = 0;
  spin_lock_init (&new->conn_lock);
  new->node_cache_mru = new->node_cache_lru = 0;
  new->node_cache_len = 0;
  mutex_init (&new->node_cache_lock);

  new->fsid = fsid;
  new->next_inode = 2;

  new->params = *params;
  new->ftp_params = ftp_params;
  new->ftp_hooks = ftp_hooks;

  err = ihash_create (&new->inode_mappings);
  spin_lock_init (&new->inode_mappings_lock);

  if (! err)
    {
      super_root = netfs_make_node (0);
      if (! super_root)
	err = ENOMEM;
    }
  if (! err)
    err = ftpfs_dir_create (new, super_root, rmt_path, &super_root_dir);
  if (! err)
    err = ftpfs_dir_lookup (super_root_dir, "", &new->root);

  if (err)
    free (new);
  else
    {
      mutex_unlock (&new->root->lock);
      *fs = new;
    }

  return err;
}