]> git.ipfire.org Git - thirdparty/squid.git/blame - src/fs/ufs/UFSStrategy.cc
Docs: Copyright updates for 2018 (#114)
[thirdparty/squid.git] / src / fs / ufs / UFSStrategy.cc
CommitLineData
58373ff8 1/*
5b74111a 2 * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
58373ff8 3 *
bbc27441
AJ
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
58373ff8
FC
7 */
8
bbc27441
AJ
9/* DEBUG: section 47 Store Directory Routines */
10
58373ff8
FC
11#include "squid.h"
12
13#include "DiskIO/DiskIOStrategy.h"
58373ff8 14#include "UFSStoreState.h"
602d9612 15#include "UFSStrategy.h"
58373ff8
FC
16#include "UFSSwapDir.h"
17
18bool
19Fs::Ufs::UFSStrategy::shedLoad()
20{
21 return io->shedLoad();
22}
23
24int
25Fs::Ufs::UFSStrategy::load()
26{
27 return io->load();
28}
29
30Fs::Ufs::UFSStrategy::UFSStrategy (DiskIOStrategy *anIO) : io(anIO)
31{}
32
33Fs::Ufs::UFSStrategy::~UFSStrategy ()
34{
35 delete io;
36}
37
38StoreIOState::Pointer
39Fs::Ufs::UFSStrategy::createState(SwapDir *SD, StoreEntry *e, StoreIOState::STIOCB * aCallback, void *callback_data) const
40{
41 return new Fs::Ufs::UFSStoreState (SD, e, aCallback, callback_data);
42}
43
44DiskFile::Pointer
45Fs::Ufs::UFSStrategy::newFile (char const *path)
46{
47 return io->newFile(path);
48}
49
50void
51Fs::Ufs::UFSStrategy::unlinkFile(char const *path)
52{
53 io->unlinkFile(path);
54}
55
56StoreIOState::Pointer
ced8def3 57Fs::Ufs::UFSStrategy::open(SwapDir * SD, StoreEntry * e, StoreIOState::STFNCB *,
187642d0 58 StoreIOState::STIOCB * aCallback, void *callback_data)
58373ff8
FC
59{
60 assert (((UFSSwapDir *)SD)->IO == this);
61 debugs(79, 3, HERE << "fileno "<< std::setfill('0') << std::hex
187642d0 62 << std::uppercase << std::setw(8) << e->swap_filen);
58373ff8
FC
63
64 /* to consider: make createstate a private UFSStrategy call */
65 StoreIOState::Pointer sio = createState (SD, e, aCallback, callback_data);
66
67 sio->mode |= O_RDONLY;
68
69 Fs::Ufs::UFSStoreState *state = dynamic_cast <Fs::Ufs::UFSStoreState *>(sio.getRaw());
70
71 assert (state);
72
73 char *path = ((UFSSwapDir *)SD)->fullPath(e->swap_filen, NULL);
74
75 DiskFile::Pointer myFile = newFile (path);
76
77 if (myFile.getRaw() == NULL)
78 return NULL;
79
80 state->theFile = myFile;
81
82 state->opening = true;
83
84 myFile->open (sio->mode, 0644, state);
85
86 if (myFile->error())
87 return NULL;
88
89 return sio;
90}
91
92StoreIOState::Pointer
ced8def3 93Fs::Ufs::UFSStrategy::create(SwapDir * SD, StoreEntry * e, StoreIOState::STFNCB *,
187642d0 94 StoreIOState::STIOCB * aCallback, void *callback_data)
58373ff8
FC
95{
96 assert (((UFSSwapDir *)SD)->IO == this);
97 /* Allocate a number */
98 sfileno filn = ((UFSSwapDir *)SD)->mapBitAllocate();
99 debugs(79, 3, HERE << "fileno "<< std::setfill('0') <<
187642d0 100 std::hex << std::uppercase << std::setw(8) << filn);
58373ff8
FC
101
102 /* Shouldn't we handle a 'bitmap full' error here? */
103
104 StoreIOState::Pointer sio = createState (SD, e, aCallback, callback_data);
105
106 sio->mode |= O_WRONLY | O_CREAT | O_TRUNC;
107
108 sio->swap_filen = filn;
109
110 Fs::Ufs::UFSStoreState *state = dynamic_cast <Fs::Ufs::UFSStoreState *>(sio.getRaw());
111
112 assert (state);
113
114 char *path = ((UFSSwapDir *)SD)->fullPath(filn, NULL);
115
116 DiskFile::Pointer myFile = newFile (path);
117
118 if (myFile.getRaw() == NULL) {
119 ((UFSSwapDir *)SD)->mapBitReset (filn);
120 return NULL;
121 }
122
123 state->theFile = myFile;
124
125 state->creating = true;
126
127 myFile->create (state->mode, 0644, state);
128
129 if (myFile->error()) {
130 ((UFSSwapDir *)SD)->mapBitReset (filn);
131 return NULL;
132 }
133
134 /* now insert into the replacement policy */
135 ((UFSSwapDir *)SD)->replacementAdd(e);
136
137 return sio;
138}
139
140int
141Fs::Ufs::UFSStrategy::callback()
142{
143 return io->callback();
144}
145
146void
147Fs::Ufs::UFSStrategy::init()
148{
149 io->init();
150}
151
152void
153Fs::Ufs::UFSStrategy::sync()
154{
155 io->sync();
156}
157
158void
159Fs::Ufs::UFSStrategy::statfs(StoreEntry & sentry)const
160{
161 io->statfs(sentry);
162}
f53969cc 163