]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/fs/ufs/UFSStrategy.cc
2 * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 47 Store Directory Routines */
13 #include "DiskIO/DiskIOStrategy.h"
14 #include "UFSStoreState.h"
15 #include "UFSStrategy.h"
16 #include "UFSSwapDir.h"
19 Fs::Ufs::UFSStrategy::shedLoad()
21 return io
->shedLoad();
25 Fs::Ufs::UFSStrategy::load()
30 Fs::Ufs::UFSStrategy::UFSStrategy (DiskIOStrategy
*anIO
) : io(anIO
)
33 Fs::Ufs::UFSStrategy::~UFSStrategy ()
39 Fs::Ufs::UFSStrategy::createState(SwapDir
*SD
, StoreEntry
*e
, StoreIOState::STIOCB
* aCallback
, void *callback_data
) const
41 return new Fs::Ufs::UFSStoreState (SD
, e
, aCallback
, callback_data
);
45 Fs::Ufs::UFSStrategy::newFile (char const *path
)
47 return io
->newFile(path
);
51 Fs::Ufs::UFSStrategy::unlinkFile(char const *path
)
57 Fs::Ufs::UFSStrategy::open(SwapDir
* SD
, StoreEntry
* e
, StoreIOState::STFNCB
*,
58 StoreIOState::STIOCB
* aCallback
, void *callback_data
)
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
);
64 /* to consider: make createstate a private UFSStrategy call */
65 StoreIOState::Pointer sio
= createState (SD
, e
, aCallback
, callback_data
);
67 sio
->mode
|= O_RDONLY
;
69 Fs::Ufs::UFSStoreState
*state
= dynamic_cast <Fs::Ufs::UFSStoreState
*>(sio
.getRaw());
73 char *path
= ((UFSSwapDir
*)SD
)->fullPath(e
->swap_filen
, NULL
);
75 DiskFile::Pointer myFile
= newFile (path
);
77 if (myFile
.getRaw() == NULL
)
80 state
->theFile
= myFile
;
82 state
->opening
= true;
84 myFile
->open (sio
->mode
, 0644, state
);
93 Fs::Ufs::UFSStrategy::create(SwapDir
* SD
, StoreEntry
* e
, StoreIOState::STFNCB
*,
94 StoreIOState::STIOCB
* aCallback
, void *callback_data
)
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
);
102 /* Shouldn't we handle a 'bitmap full' error here? */
104 StoreIOState::Pointer sio
= createState (SD
, e
, aCallback
, callback_data
);
106 sio
->mode
|= O_WRONLY
| O_CREAT
| O_TRUNC
;
108 sio
->swap_filen
= filn
;
110 Fs::Ufs::UFSStoreState
*state
= dynamic_cast <Fs::Ufs::UFSStoreState
*>(sio
.getRaw());
114 char *path
= ((UFSSwapDir
*)SD
)->fullPath(filn
, NULL
);
116 DiskFile::Pointer myFile
= newFile (path
);
118 if (myFile
.getRaw() == NULL
) {
119 ((UFSSwapDir
*)SD
)->mapBitReset (filn
);
123 state
->theFile
= myFile
;
125 state
->creating
= true;
127 myFile
->create (state
->mode
, 0644, state
);
129 if (myFile
->error()) {
130 ((UFSSwapDir
*)SD
)->mapBitReset (filn
);
134 /* now insert into the replacement policy */
135 ((UFSSwapDir
*)SD
)->replacementAdd(e
);
141 Fs::Ufs::UFSStrategy::callback()
143 return io
->callback();
147 Fs::Ufs::UFSStrategy::init()
153 Fs::Ufs::UFSStrategy::sync()
159 Fs::Ufs::UFSStrategy::statfs(StoreEntry
& sentry
)const