~ubuntu-branches/ubuntu/utopic/glame/utopic

« back to all changes in this revision

Viewing changes to src/swapfile/swfs_file.h

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2002-04-09 17:14:12 UTC
  • Revision ID: james.westby@ubuntu.com-20020409171412-jzpnov7mbz2w6zsr
Tags: upstream-0.6.2
ImportĀ upstreamĀ versionĀ 0.6.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * swfs_file.h
 
3
 *
 
4
 * Copyright (C) 2000 Richard Guenther
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
 *
 
20
 */
 
21
 
 
22
#ifndef _SWFS_FILE_H
 
23
#define _SWFS_FILE_H
 
24
 
 
25
#include "swfs_ctree.h"
 
26
 
 
27
 
 
28
struct swfile;
 
29
struct swcluster;
 
30
 
 
31
 
 
32
/* File instance, flags are
 
33
 *   SWF_NOT_IN_CORE - swfile.{size,cluster_cnt,clusters} is not filled in
 
34
 *   SWF_UNLINKED - on disk file is unlinked
 
35
 *   SWF_DIRTY - cluster list is dirty */
 
36
#define SWF_NOT_IN_CORE 1
 
37
#define SWF_UNLINKED 2
 
38
#define SWF_DIRTY 4
 
39
struct swfile {
 
40
        struct swfile *next_swfile_hash;
 
41
        struct swfile **pprev_swfile_hash;
 
42
        pthread_mutex_t mx; /* protects flags & clusters */
 
43
        long name;
 
44
        int usage;    /* number of references to this struct swfile,
 
45
                       * protected by FILES lock. */
 
46
        int flags;    /* SWF_* */
 
47
 
 
48
        /* Fields created out of the file metadata */
 
49
        struct ctree *clusters; /* cluster tree */
 
50
};
 
51
 
 
52
 
 
53
/* Gets a reference to the file with the specified name -
 
54
 * creates it, if it does not exist and FILEGET_CREAT is
 
55
 * set. If FILEGET_READCLUSTERS is set, the cluster tree
 
56
 * of the file is brought into the core.
 
57
 * Returns a reference to the file or NULL on error. */
 
58
#define FILEGET_READCLUSTERS 1
 
59
#define FILEGET_CREAT 2
 
60
static struct swfile *file_get(long name, int flags);
 
61
 
 
62
/* Releases the file reference, if FILEPUT_SYNC is set,
 
63
 * the actual cluster tree is synced to the disk, if
 
64
 * FILEPUT_UNLINK is specified, the on-disk representation
 
65
 * is unlinked and as the last reference goes away, the
 
66
 * file and its name is freed. */
 
67
#define FILEPUT_UNLINK 1
 
68
#define FILEPUT_SYNC 2
 
69
static void file_put(struct swfile *f, int flags);
 
70
 
 
71
 
 
72
/* Syncs all hashed and modified file ctrees to disk. */
 
73
static void file_sync();
 
74
 
 
75
 
 
76
/* Get a reference to the cluster containing offset using the
 
77
 * specified flags. Stores the offset of the cluster start in cstart.
 
78
 * Return values/flags like get_cluster. */
 
79
static struct swcluster *file_getcluster(struct swfile *f,
 
80
                                         s64 offset, s64 *cstart,
 
81
                                         int flags);
 
82
 
 
83
/* Get a reference to the cluster containing offset using the
 
84
 * specified flags. Stores the offset of the cluster start in cstart.
 
85
 * Return values/flags like get_cluster. If the cluster is shared,
 
86
 * copy it and replace it with the copy. */
 
87
static struct swcluster *file_getcluster_private(struct swfile *f,
 
88
                                                 s64 offset, s64 *cstart,
 
89
                                                 int flags);
 
90
 
 
91
 
 
92
/* Truncate the file to the given size. Returns 0 on success
 
93
 * and -1 on error. */
 
94
static int file_truncate(struct swfile *f, s64 size);
 
95
 
 
96
 
 
97
/* Insert count bytes from position spos in file sf into file df
 
98
 * at position dpos. Returns -1 on error, 0 on success. */
 
99
static int file_insert(struct swfile *df, s64 dpos,
 
100
                       struct swfile *sf, s64 spos, s64 count);
 
101
 
 
102
/* Replaces count bytes of file df from position dpos with
 
103
 * data from position spos out of file sf. Returns 0 on success,
 
104
 * -1 on error. */
 
105
static int file_replace(struct swfile *df, s64 dpos,
 
106
                        struct swfile *sf, s64 spos, s64 count);
 
107
 
 
108
/* Removes count bytes from position dpos out of file df. Returns
 
109
 * 0 on success, -1 on error. */
 
110
static int file_cut(struct swfile *df, s64 dpos, s64 count);
 
111
 
 
112
 
 
113
#endif