summaryrefslogtreecommitdiff
path: root/libdiskfs/file-getfh.c
blob: c755e911509891ad3368746a35a1fe4642823882 (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
/* Return a file handle (for nfs server support)

   Copyright (C) 1997, 1999 Free Software Foundation

   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 the GNU Hurd; see the file COPYING.  If not, write to
   the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */

#include <string.h>

#include "priv.h"
#include "fs_S.h"
#include "fhandle.h"

/* Return an NFS file handle for CRED in FH & FN_LEN.  */
error_t
diskfs_S_file_getfh (struct protid *cred, char **fh, unsigned *fh_len)
{
  struct node *node;
  struct diskfs_fhandle *f;

  if (! cred)
    return EOPNOTSUPP;

  if (! idvec_contains (cred->user->uids, 0))
    return EPERM;
  
  node = cred->po->np;

  mutex_lock (&node->lock);

  if (*fh_len < sizeof (struct diskfs_fhandle))
    *fh = mmap (0, sizeof (struct diskfs_fhandle), PROT_READ|PROT_WRITE, 
		MAP_ANON, 0, 0);
  *fh_len = sizeof (struct diskfs_fhandle);
  
  f = (struct diskfs_fhandle *)*fh;

  f->cache_id = node->cache_id;
  f->gen = node->dn_stat.st_gen;

  f->filler1 = 0;
  bzero (f->filler2, sizeof f->filler2);

  mutex_unlock (&node->lock);

  return 0;
}