summaryrefslogtreecommitdiff
path: root/libchannel/query.c
blob: 6bcd2d44c50c9dd5c92ca59e442cdfc14492eb87 (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
/* Creating a channel hub from a file name.

   Copyright (C) 1996, 1997, 1998, 2001, 2002, 2007
     Free Software Foundation, Inc.

   Written by Miles Bader <miles@gnu.org>
   Reworked for libchannel by Carl Fredrik Hammar <hammy.lite@gmail.com>

   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 <fcntl.h>
#include <hurd.h>

#include "channel.h"

/* Open the file NAME and return a new hub in HUB, which is either a copy
   of the file's underlying hub or a hub using it through file io, unless
   CHANNEL_NO_FILEIO flag is given.  The class of HUB is found in CLASSES
   or CHANNEL_STD_CLASSES, if CLASSES is null.  FLAGS is set with
   channel_set_hub_flags.  Keeps the SOURCE reference, which may be closed
   using channel_close_hub_source.  */
error_t
channel_create_query_hub (const char *name, int flags,
			  const struct channel_class *const *classes,
			  struct channel_hub **hub)
{
  error_t err;
  file_t node = file_name_lookup (name, O_READ, 0);

  if (node == MACH_PORT_NULL)
    {
      mach_port_deallocate (mach_task_self (), node);
      err = errno;
    }
  else
    err = channel_fetch_hub (node, flags, classes, hub);

  if (! err)
    return 0;

  if (flags & CHANNEL_NO_FILEIO)
    return err;

  /* Try making a hub that does file io to NODE.  */
  return channel_create_file_hub (name, flags, classes, hub);
}

const struct channel_class
channel_query_class = { name: "query", create_hub: channel_create_query_hub };
CHANNEL_STD_CLASS (query);