]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/fs/ufs/UFSStrategy.cc
2 * DEBUG: section 47 Store Directory Routines
3 * AUTHOR: Robert Collins
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
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.
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.
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.
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.
34 #include "DiskIO/DiskIOStrategy.h"
35 #include "UFSStoreState.h"
36 #include "UFSStrategy.h"
37 #include "UFSSwapDir.h"
40 Fs::Ufs::UFSStrategy::shedLoad()
42 return io
->shedLoad();
46 Fs::Ufs::UFSStrategy::load()
51 Fs::Ufs::UFSStrategy::UFSStrategy (DiskIOStrategy
*anIO
) : io(anIO
)
54 Fs::Ufs::UFSStrategy::~UFSStrategy ()
60 Fs::Ufs::UFSStrategy::createState(SwapDir
*SD
, StoreEntry
*e
, StoreIOState::STIOCB
* aCallback
, void *callback_data
) const
62 return new Fs::Ufs::UFSStoreState (SD
, e
, aCallback
, callback_data
);
66 Fs::Ufs::UFSStrategy::newFile (char const *path
)
68 return io
->newFile(path
);
72 Fs::Ufs::UFSStrategy::unlinkFile(char const *path
)
78 Fs::Ufs::UFSStrategy::open(SwapDir
* SD
, StoreEntry
* e
, StoreIOState::STFNCB
* file_callback
,
79 StoreIOState::STIOCB
* aCallback
, void *callback_data
)
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
);
85 /* to consider: make createstate a private UFSStrategy call */
86 StoreIOState::Pointer sio
= createState (SD
, e
, aCallback
, callback_data
);
88 sio
->mode
|= O_RDONLY
;
90 Fs::Ufs::UFSStoreState
*state
= dynamic_cast <Fs::Ufs::UFSStoreState
*>(sio
.getRaw());
94 char *path
= ((UFSSwapDir
*)SD
)->fullPath(e
->swap_filen
, NULL
);
96 DiskFile::Pointer myFile
= newFile (path
);
98 if (myFile
.getRaw() == NULL
)
101 state
->theFile
= myFile
;
103 state
->opening
= true;
105 myFile
->open (sio
->mode
, 0644, state
);
113 StoreIOState::Pointer
114 Fs::Ufs::UFSStrategy::create(SwapDir
* SD
, StoreEntry
* e
, StoreIOState::STFNCB
* file_callback
,
115 StoreIOState::STIOCB
* aCallback
, void *callback_data
)
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
);
123 /* Shouldn't we handle a 'bitmap full' error here? */
125 StoreIOState::Pointer sio
= createState (SD
, e
, aCallback
, callback_data
);
127 sio
->mode
|= O_WRONLY
| O_CREAT
| O_TRUNC
;
129 sio
->swap_filen
= filn
;
131 Fs::Ufs::UFSStoreState
*state
= dynamic_cast <Fs::Ufs::UFSStoreState
*>(sio
.getRaw());
135 char *path
= ((UFSSwapDir
*)SD
)->fullPath(filn
, NULL
);
137 DiskFile::Pointer myFile
= newFile (path
);
139 if (myFile
.getRaw() == NULL
) {
140 ((UFSSwapDir
*)SD
)->mapBitReset (filn
);
144 state
->theFile
= myFile
;
146 state
->creating
= true;
148 myFile
->create (state
->mode
, 0644, state
);
150 if (myFile
->error()) {
151 ((UFSSwapDir
*)SD
)->mapBitReset (filn
);
155 /* now insert into the replacement policy */
156 ((UFSSwapDir
*)SD
)->replacementAdd(e
);
162 Fs::Ufs::UFSStrategy::callback()
164 return io
->callback();
168 Fs::Ufs::UFSStrategy::init()
174 Fs::Ufs::UFSStrategy::sync()
180 Fs::Ufs::UFSStrategy::statfs(StoreEntry
& sentry
)const