From 3d37fe17072821361e7368c28ef210f88437e2e5 Mon Sep 17 00:00:00 2001 From: hno <> Date: Sun, 19 May 2002 22:40:56 +0000 Subject: [PATCH] COSS fixes by Guido. Also triggered a small cleanup in the othere store implementations to get rid of a unneccesary CYGWIN dependency. (binary file mode) --- src/fs/aufs/store_dir_aufs.cc | 7 ++----- src/fs/coss/store_dir_coss.cc | 27 +++++++++++++++------------ src/fs/diskd/store_dir_diskd.cc | 4 ++-- src/fs/ufs/store_dir_ufs.cc | 7 ++----- 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/fs/aufs/store_dir_aufs.cc b/src/fs/aufs/store_dir_aufs.cc index 85e2e384ff..0af80c1437 100644 --- a/src/fs/aufs/store_dir_aufs.cc +++ b/src/fs/aufs/store_dir_aufs.cc @@ -1,6 +1,6 @@ /* - * $Id: store_dir_aufs.cc,v 1.44 2002/04/07 11:52:33 hno Exp $ + * $Id: store_dir_aufs.cc,v 1.45 2002/05/19 16:40:56 hno Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -912,14 +912,11 @@ storeAufsDirOpenTmpSwapLog(SwapDir * sd, int *clean_flag, int *zero_flag) } aioinfo->swaplog_fd = fd; /* open a read-only stream of the old log */ - fp = fopen(swaplog_path, "r"); + fp = fopen(swaplog_path, "rb"); if (fp == NULL) { debug(50, 0) ("%s: %s\n", swaplog_path, xstrerror()); fatal("Failed to open swap log for reading"); } -#if defined(_SQUID_CYGWIN_) - setmode(fileno(fp), O_BINARY); -#endif memset(&clean_sb, '\0', sizeof(struct stat)); if (stat(clean_path, &clean_sb) < 0) *clean_flag = 0; diff --git a/src/fs/coss/store_dir_coss.cc b/src/fs/coss/store_dir_coss.cc index ca81999184..15927dc462 100644 --- a/src/fs/coss/store_dir_coss.cc +++ b/src/fs/coss/store_dir_coss.cc @@ -1,6 +1,6 @@ /* - * $Id: store_dir_coss.cc,v 1.33 2002/04/07 11:52:33 hno Exp $ + * $Id: store_dir_coss.cc,v 1.34 2002/05/19 16:40:57 hno Exp $ * * DEBUG: section 81 Store COSS Directory Routines * AUTHOR: Eric Stern @@ -130,7 +130,7 @@ storeCossDirOpenSwapLog(SwapDir * sd) char *path; int fd; path = storeCossDirSwapLogFile(sd, NULL); - fd = file_open(path, O_WRONLY | O_CREAT); + fd = file_open(path, O_WRONLY | O_CREAT | O_BINARY); if (fd < 0) { debug(81, 1) ("%s: %s\n", path, xstrerror()); fatal("storeCossDirOpenSwapLog: Failed to open swap log."); @@ -390,7 +390,7 @@ storeCossDirCloseTmpSwapLog(SwapDir * sd) char *new_path = xstrdup(storeCossDirSwapLogFile(sd, ".new")); int fd; file_close(cs->swaplog_fd); -#ifdef _SQUID_OS2_ +#if defined (_SQUID_OS2_) || defined (_SQUID_CYGWIN_) if (unlink(swaplog_path) < 0) { debug(50, 0) ("%s: %s\n", swaplog_path, xstrerror()); fatal("storeCossDirCloseTmpSwapLog: unlink failed"); @@ -399,7 +399,7 @@ storeCossDirCloseTmpSwapLog(SwapDir * sd) if (xrename(new_path, swaplog_path) < 0) { fatal("storeCossDirCloseTmpSwapLog: rename failed"); } - fd = file_open(swaplog_path, O_WRONLY | O_CREAT); + fd = file_open(swaplog_path, O_WRONLY | O_CREAT | O_BINARY); if (fd < 0) { debug(50, 1) ("%s: %s\n", swaplog_path, xstrerror()); fatal("storeCossDirCloseTmpSwapLog: Failed to open swap log."); @@ -433,14 +433,14 @@ storeCossDirOpenTmpSwapLog(SwapDir * sd, int *clean_flag, int *zero_flag) if (cs->swaplog_fd >= 0) file_close(cs->swaplog_fd); /* open a write-only FD for the new log */ - fd = file_open(new_path, O_WRONLY | O_CREAT | O_TRUNC); + fd = file_open(new_path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY); if (fd < 0) { debug(50, 1) ("%s: %s\n", new_path, xstrerror()); fatal("storeDirOpenTmpSwapLog: Failed to open swap log."); } cs->swaplog_fd = fd; /* open a read-only stream of the old log */ - fp = fopen(swaplog_path, "r"); + fp = fopen(swaplog_path, "rb"); if (fp == NULL) { debug(50, 0) ("%s: %s\n", swaplog_path, xstrerror()); fatal("Failed to open swap log for reading"); @@ -484,7 +484,7 @@ storeCossDirWriteCleanStart(SwapDir * sd) struct stat sb; #endif state->new = xstrdup(storeCossDirSwapLogFile(sd, ".clean")); - state->fd = file_open(state->new, O_WRONLY | O_CREAT | O_TRUNC); + state->fd = file_open(state->new, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY); if (state->fd < 0) { xfree(state->new); xfree(state); @@ -567,6 +567,7 @@ storeCossDirWriteCleanEntry(SwapDir * sd, const StoreEntry * e) static void storeCossDirWriteCleanDone(SwapDir * sd) { + int fd; struct _clean_state *state = sd->log.clean.state; if (NULL == state) return; @@ -587,24 +588,26 @@ storeCossDirWriteCleanDone(SwapDir * sd) * so we have to close before renaming. */ storeCossDirCloseSwapLog(sd); + /* save the fd value for a later test */ + fd = state->fd; /* rename */ if (state->fd >= 0) { -#ifdef _SQUID_OS2_ +#if defined(_SQUID_OS2_) || defined (_SQUID_CYGWIN_) file_close(state->fd); state->fd = -1; - if (unlink(cur) < 0) + if (unlink(state->cur) < 0) debug(50, 0) ("storeCossDirWriteCleanLogs: unlinkd failed: %s, %s\n", - xstrerror(), cur); + xstrerror(), state->cur); #endif xrename(state->new, state->cur); } /* touch a timestamp file if we're not still validating */ if (store_dirs_rebuilding) (void) 0; - else if (state->fd < 0) + else if (fd < 0) (void) 0; else - file_close(file_open(state->cln, O_WRONLY | O_CREAT | O_TRUNC)); + file_close(file_open(state->cln, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY)); /* close */ safe_free(state->cur); safe_free(state->new); diff --git a/src/fs/diskd/store_dir_diskd.cc b/src/fs/diskd/store_dir_diskd.cc index 32d66db52f..f8c29b5f67 100644 --- a/src/fs/diskd/store_dir_diskd.cc +++ b/src/fs/diskd/store_dir_diskd.cc @@ -1,6 +1,6 @@ /* - * $Id: store_dir_diskd.cc,v 1.65 2002/04/14 16:10:03 hno Exp $ + * $Id: store_dir_diskd.cc,v 1.66 2002/05/19 16:40:59 hno Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -1099,7 +1099,7 @@ storeDiskdDirOpenTmpSwapLog(SwapDir * sd, int *clean_flag, int *zero_flag) } diskdinfo->swaplog_fd = fd; /* open a read-only stream of the old log */ - fp = fopen(swaplog_path, "r"); + fp = fopen(swaplog_path, "rb"); if (fp == NULL) { debug(50, 0) ("%s: %s\n", swaplog_path, xstrerror()); fatal("Failed to open swap log for reading"); diff --git a/src/fs/ufs/store_dir_ufs.cc b/src/fs/ufs/store_dir_ufs.cc index 818fbec97f..61122f5f6d 100644 --- a/src/fs/ufs/store_dir_ufs.cc +++ b/src/fs/ufs/store_dir_ufs.cc @@ -1,6 +1,6 @@ /* - * $Id: store_dir_ufs.cc,v 1.43 2002/04/07 11:52:34 hno Exp $ + * $Id: store_dir_ufs.cc,v 1.44 2002/05/19 16:41:01 hno Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -910,14 +910,11 @@ storeUfsDirOpenTmpSwapLog(SwapDir * sd, int *clean_flag, int *zero_flag) } ufsinfo->swaplog_fd = fd; /* open a read-only stream of the old log */ - fp = fopen(swaplog_path, "r"); + fp = fopen(swaplog_path, "rb"); if (fp == NULL) { debug(50, 0) ("%s: %s\n", swaplog_path, xstrerror()); fatal("Failed to open swap log for reading"); } -#if defined(_SQUID_CYGWIN_) - setmode(fileno(fp), O_BINARY); -#endif memset(&clean_sb, '\0', sizeof(struct stat)); if (stat(clean_path, &clean_sb) < 0) *clean_flag = 0; -- 2.47.3