]> git.ipfire.org Git - thirdparty/squid.git/blob - src/fs/ufs/UFSStrategy.cc
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / fs / ufs / UFSStrategy.cc
1 /*
2 * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9 /* DEBUG: section 47 Store Directory Routines */
10
11 #include "squid.h"
12
13 #include "DiskIO/DiskIOStrategy.h"
14 #include "UFSStoreState.h"
15 #include "UFSStrategy.h"
16 #include "UFSSwapDir.h"
17
18 bool
19 Fs::Ufs::UFSStrategy::shedLoad()
20 {
21 return io->shedLoad();
22 }
23
24 int
25 Fs::Ufs::UFSStrategy::load()
26 {
27 return io->load();
28 }
29
30 Fs::Ufs::UFSStrategy::UFSStrategy (DiskIOStrategy *anIO) : io(anIO)
31 {}
32
33 Fs::Ufs::UFSStrategy::~UFSStrategy ()
34 {
35 delete io;
36 }
37
38 StoreIOState::Pointer
39 Fs::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
44 DiskFile::Pointer
45 Fs::Ufs::UFSStrategy::newFile (char const *path)
46 {
47 return io->newFile(path);
48 }
49
50 void
51 Fs::Ufs::UFSStrategy::unlinkFile(char const *path)
52 {
53 io->unlinkFile(path);
54 }
55
56 StoreIOState::Pointer
57 Fs::Ufs::UFSStrategy::open(SwapDir * SD, StoreEntry * e, StoreIOState::STFNCB *,
58 StoreIOState::STIOCB * aCallback, void *callback_data)
59 {
60 assert (((UFSSwapDir *)SD)->IO == this);
61 debugs(79, 3, HERE << "fileno "<< std::setfill('0') << std::hex
62 << std::uppercase << std::setw(8) << e->swap_filen);
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
92 StoreIOState::Pointer
93 Fs::Ufs::UFSStrategy::create(SwapDir * SD, StoreEntry * e, StoreIOState::STFNCB *,
94 StoreIOState::STIOCB * aCallback, void *callback_data)
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') <<
100 std::hex << std::uppercase << std::setw(8) << filn);
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
140 int
141 Fs::Ufs::UFSStrategy::callback()
142 {
143 return io->callback();
144 }
145
146 void
147 Fs::Ufs::UFSStrategy::init()
148 {
149 io->init();
150 }
151
152 void
153 Fs::Ufs::UFSStrategy::sync()
154 {
155 io->sync();
156 }
157
158 void
159 Fs::Ufs::UFSStrategy::statfs(StoreEntry & sentry)const
160 {
161 io->statfs(sentry);
162 }
163