/*  Header for file handle management routines

    ©1998,1999 Joseph Walton

    This software is distributed under the terms of the GNU General Public
    License; either version 2 of the License, or (at your option) any
    later version.
*/

/*
    25-Sep-1998 Added a few more fields to LocalFile
    30-Sep-1999 Using a timeval instead of a DateStamp
*/

#ifndef NFSD_HANDLE_LIST_H
#define NFSD_HANDLE_LIST_H

#include "nfs.h"
#include "dirlist.h"

#include <dos/dos.h>
#include <exec/lists.h>
#include <devices/timer.h>

/* Every FLUSH_HANDLES_EVERY seconds, release anything that hasn't been used
    for FLUSH_HANDLES_AFTER seconds */
#define FLUSH_HANDLES_EVERY (300)
#define FLUSH_HANDLES_AFTER (600)

struct LocalFile {
    struct MinNode lf_Node;
    STRPTR lf_Name;                 /* The local name of the file */
    nfs_fh lf_NFSHandle;            /* The NFS handle of this file */
    u_int lf_FileID;                /* Unique inode */
    BOOL lf_IsMount;                /* Is this a mount point? If so, do not flush. */
    ftype lf_Type;                  /* The type we think it has */
    struct timeval lf_LastUsed;     /* When we last used all this data */
    BPTR lf_Lock;                   /* Possibly a DOS lock on this resource */
    struct DEList *lf_DEList;       /* Possibly a list of entries in this directory */

    LONG lf_ForcedUID;              /* These override the real values */
    LONG lf_ForcedGID;
    LONG lf_ForcedProtection;

};

/* It might be smart to hold an open lock or file handle here as well,
    but that raises problems with files being renamed during access,
    amongst other things */

BOOL init_handle_list(void);
void persistent_inode_fetch(void);
BOOL persistent_inode_store(void);
struct LocalFile *find_handle(nfs_fh *fh);
struct LocalFile *get_by_handle(nfs_fh *fh, nfsstat *stat, ULONG mode);
void release_lf(struct LocalFile *lf);
BOOL flush_handles(void);
int32 *fh_copy(struct LocalFile *lf, int32 *dest);
void fh_print(nfs_fh *fh);
void correct_struct(struct LocalFile *lf);
struct LocalFile *get_namedlocalfile(STRPTR name);
struct LocalFile *find_namedlocalfile(STRPTR name);
void lose_localfile(STRPTR full_name);

#endif

