]> git.ipfire.org Git - thirdparty/squid.git/blob - src/fs/ufs/UFSStrategy.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / fs / ufs / UFSStrategy.cc
1 /*
2 * DEBUG: section 47 Store Directory Routines
3 * AUTHOR: Robert Collins
4 *
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
7 *
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
30 */
31
32 #include "squid.h"
33
34 #include "DiskIO/DiskIOStrategy.h"
35 #include "UFSStoreState.h"
36 #include "UFSStrategy.h"
37 #include "UFSSwapDir.h"
38
39 bool
40 Fs::Ufs::UFSStrategy::shedLoad()
41 {
42 return io->shedLoad();
43 }
44
45 int
46 Fs::Ufs::UFSStrategy::load()
47 {
48 return io->load();
49 }
50
51 Fs::Ufs::UFSStrategy::UFSStrategy (DiskIOStrategy *anIO) : io(anIO)
52 {}
53
54 Fs::Ufs::UFSStrategy::~UFSStrategy ()
55 {
56 delete io;
57 }
58
59 StoreIOState::Pointer
60 Fs::Ufs::UFSStrategy::createState(SwapDir *SD, StoreEntry *e, StoreIOState::STIOCB * aCallback, void *callback_data) const
61 {
62 return new Fs::Ufs::UFSStoreState (SD, e, aCallback, callback_data);
63 }
64
65 DiskFile::Pointer
66 Fs::Ufs::UFSStrategy::newFile (char const *path)
67 {
68 return io->newFile(path);
69 }
70
71 void
72 Fs::Ufs::UFSStrategy::unlinkFile(char const *path)
73 {
74 io->unlinkFile(path);
75 }
76
77 StoreIOState::Pointer
78 Fs::Ufs::UFSStrategy::open(SwapDir * SD, StoreEntry * e, StoreIOState::STFNCB * file_callback,
79 StoreIOState::STIOCB * aCallback, void *callback_data)
80 {
81 assert (((UFSSwapDir *)SD)->IO == this);
82 debugs(79, 3, HERE << "fileno "<< std::setfill('0') << std::hex
83 << std::uppercase << std::setw(8) << e->swap_filen);
84
85 /* to consider: make createstate a private UFSStrategy call */
86 StoreIOState::Pointer sio = createState (SD, e, aCallback, callback_data);
87
88 sio->mode |= O_RDONLY;
89
90 Fs::Ufs::UFSStoreState *state = dynamic_cast <Fs::Ufs::UFSStoreState *>(sio.getRaw());
91
92 assert (state);
93
94 char *path = ((UFSSwapDir *)SD)->fullPath(e->swap_filen, NULL);
95
96 DiskFile::Pointer myFile = newFile (path);
97
98 if (myFile.getRaw() == NULL)
99 return NULL;
100
101 state->theFile = myFile;
102
103 state->opening = true;
104
105 myFile->open (sio->mode, 0644, state);
106
107 if (myFile->error())
108 return NULL;
109
110 return sio;
111 }
112
113 StoreIOState::Pointer
114 Fs::Ufs::UFSStrategy::create(SwapDir * SD, StoreEntry * e, StoreIOState::STFNCB * file_callback,
115 StoreIOState::STIOCB * aCallback, void *callback_data)
116 {
117 assert (((UFSSwapDir *)SD)->IO == this);
118 /* Allocate a number */
119 sfileno filn = ((UFSSwapDir *)SD)->mapBitAllocate();
120 debugs(79, 3, HERE << "fileno "<< std::setfill('0') <<
121 std::hex << std::uppercase << std::setw(8) << filn);
122
123 /* Shouldn't we handle a 'bitmap full' error here? */
124
125 StoreIOState::Pointer sio = createState (SD, e, aCallback, callback_data);
126
127 sio->mode |= O_WRONLY | O_CREAT | O_TRUNC;
128
129 sio->swap_filen = filn;
130
131 Fs::Ufs::UFSStoreState *state = dynamic_cast <Fs::Ufs::UFSStoreState *>(sio.getRaw());
132
133 assert (state);
134
135 char *path = ((UFSSwapDir *)SD)->fullPath(filn, NULL);
136
137 DiskFile::Pointer myFile = newFile (path);
138
139 if (myFile.getRaw() == NULL) {
140 ((UFSSwapDir *)SD)->mapBitReset (filn);
141 return NULL;
142 }
143
144 state->theFile = myFile;
145
146 state->creating = true;
147
148 myFile->create (state->mode, 0644, state);
149
150 if (myFile->error()) {
151 ((UFSSwapDir *)SD)->mapBitReset (filn);
152 return NULL;
153 }
154
155 /* now insert into the replacement policy */
156 ((UFSSwapDir *)SD)->replacementAdd(e);
157
158 return sio;
159 }
160
161 int
162 Fs::Ufs::UFSStrategy::callback()
163 {
164 return io->callback();
165 }
166
167 void
168 Fs::Ufs::UFSStrategy::init()
169 {
170 io->init();
171 }
172
173 void
174 Fs::Ufs::UFSStrategy::sync()
175 {
176 io->sync();
177 }
178
179 void
180 Fs::Ufs::UFSStrategy::statfs(StoreEntry & sentry)const
181 {
182 io->statfs(sentry);
183 }