summaryrefslogtreecommitdiff
path: root/fs.c
blob: d2d878ceeea22a5aed86971f2ddb7b51e26d95c8 (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
/* Gopher filesystem

   Copyright (C) 2010 Manuel Menal <mmenal@hurdfr.org>
   This file is part of the Gopherfs translator.

   Gopherfs 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.

   Gopherfs 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 <stdlib.h>
#include <unistd.h>
#include <sys/types.h>

#include <stdio.h>

#include "fs.h"

error_t
gopherfs_create (struct gopherfs_params *params)
{
  error_t err = 0;
  struct gopher_entry *root;

  gopherfs = malloc (sizeof (struct gopherfs));
  if (!gopherfs)
    return ENOMEM;

  gopherfs->umask = 0;
  gopherfs->uid = getuid();
  gopherfs->gid = getgid();
  gopherfs->next_inode = 0;

  root = malloc (sizeof (struct gopher_entry));
  if (!root)
    return ENOMEM;
  root->type = GPHR_DIR;
  root->name = "dir";
  root->selector = "";
  root->server = params->server;
  root->port = params->port;

  debug ("creating root node for %s:%hu%s", root->server, root->port);
  gopherfs->root = gopherfs_make_node (root, NULL);
  if (!gopherfs->root)
    err = ENOMEM;
  free (root);

  gopherfs->params = params;

  return err;
}