From 61c73a867738f3c63cb599378a473c140734e206 Mon Sep 17 00:00:00 2001 From: Ankit Kumar Date: Thu, 11 Dec 2025 11:11:33 +0530 Subject: [PATCH 01/22] Fix race condition in raster slot allocation and release (#6616) --- lib/raster/close.c | 30 +++++++++++++------- lib/raster/open.c | 71 ++++++++++++++++++++++++++++------------------ 2 files changed, 62 insertions(+), 39 deletions(-) diff --git a/lib/raster/close.c b/lib/raster/close.c index 8de233d42fc..d99972ea5c4 100644 --- a/lib/raster/close.c +++ b/lib/raster/close.c @@ -11,7 +11,6 @@ * * \author USACERL and many others */ - #ifdef _WIN32 #include #endif @@ -82,7 +81,7 @@ static void write_fp_format(int fd); * overwrite the support files. See \ref * Raster_Map_Layer_Support_Routines for routines which write raster * support files. - * + * If the map is a new floating point, move the .tmp file * into the fcell element, create an empty file in the * cell directory; write the floating-point range file; write @@ -91,7 +90,7 @@ static void write_fp_format(int fd); * file, with max cat = max value (for backwards compatibility). Move * the .tmp NULL-value bitmap file to the cell_misc * directory. - * + * \param fd file descriptor * * \return void @@ -124,9 +123,9 @@ void Rast_close(int fd) * eventually remove the temporary file, but the file can be quite * large and will take up disk space until GRASS does remove it. Use * this routine as a courtesy to the user. - * + * \param fd file descriptor - * + * \return void */ void Rast_unopen(int fd) @@ -144,13 +143,13 @@ void Rast_unopen(int fd) /*! * \brief Unopen all raster maps - * + * Unopen all raster maps opened for write. Memory allocated for * raster processing is freed, and the temporary file created when the * raster map was opened is removed (see \ref * Creating_and_Opening_New_Raster_Files). This routine is useful when * errors are detected and it is desired to remove temporary files. - * + * \return void */ void Rast__unopen_all(void) @@ -198,7 +197,7 @@ static int close_old(int fd) G_free(fcb->name); if (fcb->reclass_flag) Rast_free_reclass(&fcb->reclass); - fcb->open_mode = -1; + // fcb->open_mode = -1; if (fcb->map_type != CELL_TYPE) { Rast_quant_free(&fcb->quant); @@ -206,6 +205,8 @@ static int close_old(int fd) if (fcb->data_fd >= 0) close(fcb->data_fd); + #pragma omp critical (R_RASTER_OPEN) + fcb->open_mode = -1; return 1; } @@ -347,7 +348,7 @@ static int close_new_gdal(int fd, int ok) Rast_close_gdal_link(fcb->gdal); } - fcb->open_mode = -1; + /* fcb->open_mode = -1; */ if (fcb->data != NULL) G_free(fcb->data); @@ -361,6 +362,9 @@ static int close_new_gdal(int fd, int ok) if (fcb->map_type != CELL_TYPE) Rast_quant_free(&fcb->quant); + #pragma omp critical (R_RASTER_OPEN) + fcb->open_mode = -1; + return stat; } @@ -477,7 +481,7 @@ static int close_new(int fd, int ok) sync_and_close(fcb->data_fd, (fcb->map_type == CELL_TYPE ? "cell" : "fcell"), fcb->name); - fcb->open_mode = -1; + /* fcb->open_mode = -1; */ if (fcb->null_fd >= 0) { sync_and_close(fcb->null_fd, @@ -531,6 +535,8 @@ static int close_new(int fd, int ok) if (fcb->map_type != CELL_TYPE) Rast_quant_free(&fcb->quant); +#pragma omp critical (R_RASTER_OPEN) + fcb->open_mode = -1; return stat; } @@ -577,6 +583,8 @@ void Rast__close_null(int fd) G_free(fcb->null_bits); + /* fcb->open_mode = -1; */ +#pragma omp critical (R_RASTER_OPEN) fcb->open_mode = -1; } @@ -607,4 +615,4 @@ static void write_fp_format(int fd) G_write_key_value_file(path, format_kv); G_free_key_value(format_kv); -} +} \ No newline at end of file diff --git a/lib/raster/open.c b/lib/raster/open.c index bf9b0fb1bb8..62624d1f3a0 100644 --- a/lib/raster/open.c +++ b/lib/raster/open.c @@ -11,7 +11,6 @@ * * \author USACERL and many others */ - #include #include #include @@ -27,43 +26,59 @@ #include "R.h" #define FORMAT_FILE "f_format" #define NULL_FILE "null" -/* cmpressed null file */ +//cmpressed null file #define NULLC_FILE "nullcmpr" static int new_fileinfo(void) { - int oldsize = R__.fileinfo_count; - int newsize = oldsize; + int oldsize; + int newsize; int i; + int fd = -1; - for (i = 0; i < oldsize; i++) - if (R__.fileinfo[i].open_mode <= 0) { - memset(&R__.fileinfo[i], 0, sizeof(struct fileinfo)); - R__.fileinfo[i].open_mode = -1; - return i; +#pragma omp critical (R_RASTER_OPEN) + { + oldsize = R__.fileinfo_count; + newsize = oldsize; + + for (i = 0; i < oldsize; i++) { + if (R__.fileinfo[i].open_mode <= 0) { + memset(&R__.fileinfo[i], 0, sizeof(struct fileinfo)); + // mark as reserved + R__.fileinfo[i].open_mode = 200; + fd = i; + break; + } } - if (newsize < 20) - newsize += 20; - else - newsize *= 2; + if (fd < 0) { + if (newsize < 20) + newsize += 20; + else + newsize *= 2; - R__.fileinfo = G_realloc(R__.fileinfo, newsize * sizeof(struct fileinfo)); + R__.fileinfo = G_realloc(R__.fileinfo, newsize * sizeof(struct fileinfo)); - /* Mark all cell files as closed */ - for (i = oldsize; i < newsize; i++) { - memset(&R__.fileinfo[i], 0, sizeof(struct fileinfo)); - R__.fileinfo[i].open_mode = -1; - } + //Mark all cell files as closed + for (i = oldsize; i < newsize; i++) { + memset(&R__.fileinfo[i], 0, sizeof(struct fileinfo)); + R__.fileinfo[i].open_mode = -1; + } - R__.fileinfo_count = newsize; + R__.fileinfo_count = newsize; - return oldsize; + // mark as reserved + R__.fileinfo[oldsize].open_mode = 200; + fd = oldsize; + } + } + + return fd; } /*! * \brief Open raster file - * + * Arrange for the NULL-value bitmap to be read as well as the raster * map. If no NULL-value bitmap exists, arrange for the production of * NULL-values based on zeros in the raster map. If the map is @@ -73,11 +88,11 @@ static int new_fileinfo(void) * the floating point map using uing quant rules other than the ones * stored in map's quant file, he/she should call Rast_set_quant_rules() * after the call to Rast_open_old(). - * + * \param name map name * \param open_mode mode * \param map_type map type (CELL, FCELL, DCELL) - * + * \return open file descriptor ( >= 0) if successful */ static int open_raster_new(const char *name, int open_mode, @@ -302,7 +317,7 @@ int Rast__open_old(const char *name, const char *mapset) fcb->null_bits = Rast__allocate_null_bits(cellhd.cols); /* mark closed */ - fcb->open_mode = -1; + /* fcb->open_mode = -1; */ /* save name and mapset */ fcb->name = G_store(name); @@ -528,7 +543,7 @@ static int open_raster_new_gdal(char *map, char *mapset, /* mark closed */ fcb->map_type = map_type; - fcb->open_mode = -1; + /* fcb->open_mode = -1; */ fcb->gdal = Rast_create_gdal_link(map, map_type); if (!fcb->gdal) @@ -644,7 +659,7 @@ static int open_raster_new(const char *name, int open_mode, /* mark closed */ fcb->map_type = map_type; - fcb->open_mode = -1; + /* fcb->open_mode = -1; */ fcb->gdal = NULL; fcb->vrt = NULL; @@ -1057,4 +1072,4 @@ void Rast_set_quant_rules(int fd, struct Quant *q) Rast_quant_set_neg_infinite_rule(&fcb->quant, dcell, cell); if (Rast_quant_get_pos_infinite_rule(q, &dcell, &cell) > 0) Rast_quant_set_pos_infinite_rule(&fcb->quant, dcell, cell); -} +} \ No newline at end of file From fbd0c0b1b3f59c630391b1aa709ec235f2dac768 Mon Sep 17 00:00:00 2001 From: Ankit Kumar <138521012+Ankitkumarthakur0@users.noreply.github.com> Date: Thu, 11 Dec 2025 22:23:57 +0530 Subject: [PATCH 02/22] Update lib/raster/close.c Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- lib/raster/close.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/raster/close.c b/lib/raster/close.c index d99972ea5c4..7bf6c461a96 100644 --- a/lib/raster/close.c +++ b/lib/raster/close.c @@ -81,7 +81,6 @@ static void write_fp_format(int fd); * overwrite the support files. See \ref * Raster_Map_Layer_Support_Routines for routines which write raster * support files. - * If the map is a new floating point, move the .tmp file * into the fcell element, create an empty file in the * cell directory; write the floating-point range file; write From 91b4bf826a9c3407cdfa48b329eb7a0049a0c170 Mon Sep 17 00:00:00 2001 From: Ankit Kumar <138521012+Ankitkumarthakur0@users.noreply.github.com> Date: Thu, 11 Dec 2025 22:26:26 +0530 Subject: [PATCH 03/22] Update lib/raster/close.c Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- lib/raster/close.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/raster/close.c b/lib/raster/close.c index 7bf6c461a96..f69b86d4c1f 100644 --- a/lib/raster/close.c +++ b/lib/raster/close.c @@ -89,7 +89,6 @@ static void write_fp_format(int fd); * file, with max cat = max value (for backwards compatibility). Move * the .tmp NULL-value bitmap file to the cell_misc * directory. - * \param fd file descriptor * * \return void From 83f49bbd9fcff439ebf3a6861b5b796a22be629f Mon Sep 17 00:00:00 2001 From: Ankit Kumar <138521012+Ankitkumarthakur0@users.noreply.github.com> Date: Thu, 11 Dec 2025 22:26:46 +0530 Subject: [PATCH 04/22] Update lib/raster/close.c Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- lib/raster/close.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/raster/close.c b/lib/raster/close.c index f69b86d4c1f..d272a7fb7dc 100644 --- a/lib/raster/close.c +++ b/lib/raster/close.c @@ -121,7 +121,6 @@ void Rast_close(int fd) * eventually remove the temporary file, but the file can be quite * large and will take up disk space until GRASS does remove it. Use * this routine as a courtesy to the user. - * \param fd file descriptor * \return void From 979b78c403fcb2d84ed8cdf9de77c7a3b4aeb346 Mon Sep 17 00:00:00 2001 From: Ankit Kumar <138521012+Ankitkumarthakur0@users.noreply.github.com> Date: Thu, 11 Dec 2025 22:27:16 +0530 Subject: [PATCH 05/22] Update lib/raster/open.c Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- lib/raster/open.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/raster/open.c b/lib/raster/open.c index 62624d1f3a0..d1e8ff226ea 100644 --- a/lib/raster/open.c +++ b/lib/raster/open.c @@ -92,7 +92,6 @@ static int new_fileinfo(void) * \param name map name * \param open_mode mode * \param map_type map type (CELL, FCELL, DCELL) - * \return open file descriptor ( >= 0) if successful */ static int open_raster_new(const char *name, int open_mode, From 7c123d8eacd6a99dd5dfa86519757e57c9d6b1a3 Mon Sep 17 00:00:00 2001 From: Ankit Kumar <138521012+Ankitkumarthakur0@users.noreply.github.com> Date: Thu, 11 Dec 2025 22:27:26 +0530 Subject: [PATCH 06/22] Update lib/raster/open.c Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- lib/raster/open.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/raster/open.c b/lib/raster/open.c index d1e8ff226ea..50025d28aa9 100644 --- a/lib/raster/open.c +++ b/lib/raster/open.c @@ -88,7 +88,6 @@ static int new_fileinfo(void) * the floating point map using uing quant rules other than the ones * stored in map's quant file, he/she should call Rast_set_quant_rules() * after the call to Rast_open_old(). - * \param name map name * \param open_mode mode * \param map_type map type (CELL, FCELL, DCELL) From ea30a8c6f510b0d1d97ccab181f34e5fd40c3de4 Mon Sep 17 00:00:00 2001 From: Ankit Kumar <138521012+Ankitkumarthakur0@users.noreply.github.com> Date: Thu, 11 Dec 2025 22:30:10 +0530 Subject: [PATCH 07/22] Update lib/raster/open.c Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- lib/raster/open.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/raster/open.c b/lib/raster/open.c index 50025d28aa9..a6c1eb46522 100644 --- a/lib/raster/open.c +++ b/lib/raster/open.c @@ -78,7 +78,6 @@ static int new_fileinfo(void) /*! * \brief Open raster file - * Arrange for the NULL-value bitmap to be read as well as the raster * map. If no NULL-value bitmap exists, arrange for the production of * NULL-values based on zeros in the raster map. If the map is From d11fe9afd2f4b8e0749a1c4fc5001eda8f8dca06 Mon Sep 17 00:00:00 2001 From: Ankit Kumar <138521012+Ankitkumarthakur0@users.noreply.github.com> Date: Thu, 11 Dec 2025 22:30:24 +0530 Subject: [PATCH 08/22] Update lib/raster/close.c Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- lib/raster/close.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/raster/close.c b/lib/raster/close.c index d272a7fb7dc..4beae46a0b3 100644 --- a/lib/raster/close.c +++ b/lib/raster/close.c @@ -122,7 +122,6 @@ void Rast_close(int fd) * large and will take up disk space until GRASS does remove it. Use * this routine as a courtesy to the user. * \param fd file descriptor - * \return void */ void Rast_unopen(int fd) From 47359e04c476dd913730534f7a416d52c9e43f62 Mon Sep 17 00:00:00 2001 From: Ankit Kumar <138521012+Ankitkumarthakur0@users.noreply.github.com> Date: Fri, 12 Dec 2025 23:50:24 +0530 Subject: [PATCH 09/22] Update lib/raster/close.c Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- lib/raster/close.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/raster/close.c b/lib/raster/close.c index 4beae46a0b3..1ca13079070 100644 --- a/lib/raster/close.c +++ b/lib/raster/close.c @@ -139,7 +139,6 @@ void Rast_unopen(int fd) /*! * \brief Unopen all raster maps - * Unopen all raster maps opened for write. Memory allocated for * raster processing is freed, and the temporary file created when the * raster map was opened is removed (see \ref From 4702539c3af93fc01d5b7d0c78ef32a65c2e534f Mon Sep 17 00:00:00 2001 From: Ankit Kumar <138521012+Ankitkumarthakur0@users.noreply.github.com> Date: Fri, 12 Dec 2025 23:50:38 +0530 Subject: [PATCH 10/22] Update lib/raster/open.c Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- lib/raster/open.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/raster/open.c b/lib/raster/open.c index a6c1eb46522..2d8fe4391fb 100644 --- a/lib/raster/open.c +++ b/lib/raster/open.c @@ -59,7 +59,7 @@ static int new_fileinfo(void) R__.fileinfo = G_realloc(R__.fileinfo, newsize * sizeof(struct fileinfo)); - //Mark all cell files as closed + // Mark all cell files as closed for (i = oldsize; i < newsize; i++) { memset(&R__.fileinfo[i], 0, sizeof(struct fileinfo)); R__.fileinfo[i].open_mode = -1; From 7e58cd07d93978c2f58bedbd6fd8142bd9a7b50d Mon Sep 17 00:00:00 2001 From: Ankit Kumar <138521012+Ankitkumarthakur0@users.noreply.github.com> Date: Fri, 12 Dec 2025 23:50:48 +0530 Subject: [PATCH 11/22] Update lib/raster/open.c Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- lib/raster/open.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/raster/open.c b/lib/raster/open.c index 2d8fe4391fb..71a219eb6ad 100644 --- a/lib/raster/open.c +++ b/lib/raster/open.c @@ -67,7 +67,7 @@ static int new_fileinfo(void) R__.fileinfo_count = newsize; - // mark as reserved + // mark as reserved R__.fileinfo[oldsize].open_mode = 200; fd = oldsize; } From 7e47761cf04b632348045807a1a7fd413f343f0f Mon Sep 17 00:00:00 2001 From: Ankit Kumar <138521012+Ankitkumarthakur0@users.noreply.github.com> Date: Tue, 16 Dec 2025 01:19:45 +0530 Subject: [PATCH 12/22] Update lib/raster/open.c Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- lib/raster/open.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/raster/open.c b/lib/raster/open.c index 71a219eb6ad..7a931b97294 100644 --- a/lib/raster/open.c +++ b/lib/raster/open.c @@ -26,7 +26,7 @@ #include "R.h" #define FORMAT_FILE "f_format" #define NULL_FILE "null" -//cmpressed null file +// cmpressed null file #define NULLC_FILE "nullcmpr" static int new_fileinfo(void) From 03fd9536c21108322be4b2951c1544700a190fd7 Mon Sep 17 00:00:00 2001 From: Ankit Kumar <138521012+Ankitkumarthakur0@users.noreply.github.com> Date: Tue, 16 Dec 2025 01:19:58 +0530 Subject: [PATCH 13/22] Update lib/raster/open.c Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- lib/raster/open.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/raster/open.c b/lib/raster/open.c index 7a931b97294..d28845e4a30 100644 --- a/lib/raster/open.c +++ b/lib/raster/open.c @@ -36,7 +36,7 @@ static int new_fileinfo(void) int i; int fd = -1; -#pragma omp critical (R_RASTER_OPEN) +#pragma omp critical(R_RASTER_OPEN) { oldsize = R__.fileinfo_count; newsize = oldsize; From 9d046e034e56222fb9552e2d8f67a8022df74cae Mon Sep 17 00:00:00 2001 From: Ankit Kumar <138521012+Ankitkumarthakur0@users.noreply.github.com> Date: Tue, 16 Dec 2025 01:20:12 +0530 Subject: [PATCH 14/22] Update lib/raster/open.c Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- lib/raster/open.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/raster/open.c b/lib/raster/open.c index d28845e4a30..f6c81521e92 100644 --- a/lib/raster/open.c +++ b/lib/raster/open.c @@ -44,7 +44,7 @@ static int new_fileinfo(void) for (i = 0; i < oldsize; i++) { if (R__.fileinfo[i].open_mode <= 0) { memset(&R__.fileinfo[i], 0, sizeof(struct fileinfo)); - // mark as reserved + // mark as reserved R__.fileinfo[i].open_mode = 200; fd = i; break; From 03bd45315a5836fc55651115085303836d9f1548 Mon Sep 17 00:00:00 2001 From: Ankit Kumar <138521012+Ankitkumarthakur0@users.noreply.github.com> Date: Tue, 16 Dec 2025 01:20:26 +0530 Subject: [PATCH 15/22] Update lib/raster/open.c Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- lib/raster/open.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/raster/open.c b/lib/raster/open.c index f6c81521e92..77eeb28f9bd 100644 --- a/lib/raster/open.c +++ b/lib/raster/open.c @@ -57,7 +57,8 @@ static int new_fileinfo(void) else newsize *= 2; - R__.fileinfo = G_realloc(R__.fileinfo, newsize * sizeof(struct fileinfo)); + R__.fileinfo = + G_realloc(R__.fileinfo, newsize * sizeof(struct fileinfo)); // Mark all cell files as closed for (i = oldsize; i < newsize; i++) { From 26218baf9b8dcd1f5d6839e0178aa25982fd2602 Mon Sep 17 00:00:00 2001 From: Ankit Kumar <138521012+Ankitkumarthakur0@users.noreply.github.com> Date: Tue, 16 Dec 2025 01:20:50 +0530 Subject: [PATCH 16/22] Update lib/raster/close.c Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- lib/raster/close.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/raster/close.c b/lib/raster/close.c index 1ca13079070..f2d6d530b47 100644 --- a/lib/raster/close.c +++ b/lib/raster/close.c @@ -144,7 +144,6 @@ void Rast_unopen(int fd) * raster map was opened is removed (see \ref * Creating_and_Opening_New_Raster_Files). This routine is useful when * errors are detected and it is desired to remove temporary files. - * \return void */ void Rast__unopen_all(void) From 0b480f2be7edb51494a9a154f876926ebb2a1336 Mon Sep 17 00:00:00 2001 From: Ankit Kumar <138521012+Ankitkumarthakur0@users.noreply.github.com> Date: Tue, 16 Dec 2025 01:20:59 +0530 Subject: [PATCH 17/22] Update lib/raster/close.c Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- lib/raster/close.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/raster/close.c b/lib/raster/close.c index f2d6d530b47..c6ec190d014 100644 --- a/lib/raster/close.c +++ b/lib/raster/close.c @@ -191,7 +191,7 @@ static int close_old(int fd) G_free(fcb->name); if (fcb->reclass_flag) Rast_free_reclass(&fcb->reclass); - // fcb->open_mode = -1; + // fcb->open_mode = -1; if (fcb->map_type != CELL_TYPE) { Rast_quant_free(&fcb->quant); From e6c9cbfafda1df5a136a06151283bd9227829a3c Mon Sep 17 00:00:00 2001 From: Ankit Kumar <138521012+Ankitkumarthakur0@users.noreply.github.com> Date: Tue, 16 Dec 2025 01:21:11 +0530 Subject: [PATCH 18/22] Update lib/raster/close.c Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- lib/raster/close.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/raster/close.c b/lib/raster/close.c index c6ec190d014..79366ffd149 100644 --- a/lib/raster/close.c +++ b/lib/raster/close.c @@ -199,7 +199,7 @@ static int close_old(int fd) if (fcb->data_fd >= 0) close(fcb->data_fd); - #pragma omp critical (R_RASTER_OPEN) +#pragma omp critical(R_RASTER_OPEN) fcb->open_mode = -1; return 1; } From 63ad6796dd938d35f868428c025917976fd73d5a Mon Sep 17 00:00:00 2001 From: Ankit Kumar <138521012+Ankitkumarthakur0@users.noreply.github.com> Date: Tue, 16 Dec 2025 01:21:42 +0530 Subject: [PATCH 19/22] Update lib/raster/close.c Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- lib/raster/close.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/raster/close.c b/lib/raster/close.c index 79366ffd149..f8bc5547bdc 100644 --- a/lib/raster/close.c +++ b/lib/raster/close.c @@ -578,7 +578,7 @@ void Rast__close_null(int fd) G_free(fcb->null_bits); /* fcb->open_mode = -1; */ -#pragma omp critical (R_RASTER_OPEN) +#pragma omp critical(R_RASTER_OPEN) fcb->open_mode = -1; } From 7273c2200fadf2baa1eaff958c5b00f73ddbcc19 Mon Sep 17 00:00:00 2001 From: Ankit Kumar <138521012+Ankitkumarthakur0@users.noreply.github.com> Date: Tue, 16 Dec 2025 01:21:51 +0530 Subject: [PATCH 20/22] Update lib/raster/close.c Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- lib/raster/close.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/raster/close.c b/lib/raster/close.c index f8bc5547bdc..05075bdd639 100644 --- a/lib/raster/close.c +++ b/lib/raster/close.c @@ -529,7 +529,7 @@ static int close_new(int fd, int ok) if (fcb->map_type != CELL_TYPE) Rast_quant_free(&fcb->quant); -#pragma omp critical (R_RASTER_OPEN) +#pragma omp critical(R_RASTER_OPEN) fcb->open_mode = -1; return stat; } From 5e62ab784897c8bd2e82561a4b316ec79e7982cd Mon Sep 17 00:00:00 2001 From: Ankit Kumar <138521012+Ankitkumarthakur0@users.noreply.github.com> Date: Tue, 16 Dec 2025 01:22:15 +0530 Subject: [PATCH 21/22] Update lib/raster/close.c Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- lib/raster/close.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/raster/close.c b/lib/raster/close.c index 05075bdd639..e52b93e957f 100644 --- a/lib/raster/close.c +++ b/lib/raster/close.c @@ -356,7 +356,7 @@ static int close_new_gdal(int fd, int ok) if (fcb->map_type != CELL_TYPE) Rast_quant_free(&fcb->quant); - #pragma omp critical (R_RASTER_OPEN) +#pragma omp critical(R_RASTER_OPEN) fcb->open_mode = -1; return stat; From fbd5ecb6a1cc12950cdd72c6ee1a722e412867e1 Mon Sep 17 00:00:00 2001 From: Ankit Kumar <138521012+Ankitkumarthakur0@users.noreply.github.com> Date: Sun, 18 Jan 2026 21:46:12 +0530 Subject: [PATCH 22/22] lib/raster: clean up PR-introduce style issues and normalize line endings (#6616) --- lib/raster/close.c | 11 +++++++---- lib/raster/open.c | 16 ++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/raster/close.c b/lib/raster/close.c index e52b93e957f..1a7bb636a56 100644 --- a/lib/raster/close.c +++ b/lib/raster/close.c @@ -81,6 +81,7 @@ static void write_fp_format(int fd); * overwrite the support files. See \ref * Raster_Map_Layer_Support_Routines for routines which write raster * support files. + * If the map is a new floating point, move the .tmp file * into the fcell element, create an empty file in the * cell directory; write the floating-point range file; write @@ -89,6 +90,7 @@ static void write_fp_format(int fd); * file, with max cat = max value (for backwards compatibility). Move * the .tmp NULL-value bitmap file to the cell_misc * directory. + * \param fd file descriptor * * \return void @@ -121,7 +123,9 @@ void Rast_close(int fd) * eventually remove the temporary file, but the file can be quite * large and will take up disk space until GRASS does remove it. Use * this routine as a courtesy to the user. + * \param fd file descriptor + * \return void */ void Rast_unopen(int fd) @@ -139,11 +143,13 @@ void Rast_unopen(int fd) /*! * \brief Unopen all raster maps + * Unopen all raster maps opened for write. Memory allocated for * raster processing is freed, and the temporary file created when the * raster map was opened is removed (see \ref * Creating_and_Opening_New_Raster_Files). This routine is useful when * errors are detected and it is desired to remove temporary files. + * \return void */ void Rast__unopen_all(void) @@ -191,7 +197,6 @@ static int close_old(int fd) G_free(fcb->name); if (fcb->reclass_flag) Rast_free_reclass(&fcb->reclass); - // fcb->open_mode = -1; if (fcb->map_type != CELL_TYPE) { Rast_quant_free(&fcb->quant); @@ -475,7 +480,6 @@ static int close_new(int fd, int ok) sync_and_close(fcb->data_fd, (fcb->map_type == CELL_TYPE ? "cell" : "fcell"), fcb->name); - /* fcb->open_mode = -1; */ if (fcb->null_fd >= 0) { sync_and_close(fcb->null_fd, @@ -577,7 +581,6 @@ void Rast__close_null(int fd) G_free(fcb->null_bits); - /* fcb->open_mode = -1; */ #pragma omp critical(R_RASTER_OPEN) fcb->open_mode = -1; } @@ -609,4 +612,4 @@ static void write_fp_format(int fd) G_write_key_value_file(path, format_kv); G_free_key_value(format_kv); -} \ No newline at end of file +} diff --git a/lib/raster/open.c b/lib/raster/open.c index 77eeb28f9bd..8d7c4d691db 100644 --- a/lib/raster/open.c +++ b/lib/raster/open.c @@ -26,7 +26,7 @@ #include "R.h" #define FORMAT_FILE "f_format" #define NULL_FILE "null" -// cmpressed null file +/* compressed null file */ #define NULLC_FILE "nullcmpr" static int new_fileinfo(void) @@ -44,7 +44,7 @@ static int new_fileinfo(void) for (i = 0; i < oldsize; i++) { if (R__.fileinfo[i].open_mode <= 0) { memset(&R__.fileinfo[i], 0, sizeof(struct fileinfo)); - // mark as reserved + /* mark as reserved */ R__.fileinfo[i].open_mode = 200; fd = i; break; @@ -60,7 +60,7 @@ static int new_fileinfo(void) R__.fileinfo = G_realloc(R__.fileinfo, newsize * sizeof(struct fileinfo)); - // Mark all cell files as closed + /* Mark all cell files as closed */ for (i = oldsize; i < newsize; i++) { memset(&R__.fileinfo[i], 0, sizeof(struct fileinfo)); R__.fileinfo[i].open_mode = -1; @@ -68,7 +68,7 @@ static int new_fileinfo(void) R__.fileinfo_count = newsize; - // mark as reserved + /* mark as reserved */ R__.fileinfo[oldsize].open_mode = 200; fd = oldsize; } @@ -79,6 +79,7 @@ static int new_fileinfo(void) /*! * \brief Open raster file + * Arrange for the NULL-value bitmap to be read as well as the raster * map. If no NULL-value bitmap exists, arrange for the production of * NULL-values based on zeros in the raster map. If the map is @@ -88,9 +89,11 @@ static int new_fileinfo(void) * the floating point map using uing quant rules other than the ones * stored in map's quant file, he/she should call Rast_set_quant_rules() * after the call to Rast_open_old(). + * \param name map name * \param open_mode mode * \param map_type map type (CELL, FCELL, DCELL) + * \return open file descriptor ( >= 0) if successful */ static int open_raster_new(const char *name, int open_mode, @@ -315,7 +318,6 @@ int Rast__open_old(const char *name, const char *mapset) fcb->null_bits = Rast__allocate_null_bits(cellhd.cols); /* mark closed */ - /* fcb->open_mode = -1; */ /* save name and mapset */ fcb->name = G_store(name); @@ -541,7 +543,6 @@ static int open_raster_new_gdal(char *map, char *mapset, /* mark closed */ fcb->map_type = map_type; - /* fcb->open_mode = -1; */ fcb->gdal = Rast_create_gdal_link(map, map_type); if (!fcb->gdal) @@ -657,7 +658,6 @@ static int open_raster_new(const char *name, int open_mode, /* mark closed */ fcb->map_type = map_type; - /* fcb->open_mode = -1; */ fcb->gdal = NULL; fcb->vrt = NULL; @@ -1070,4 +1070,4 @@ void Rast_set_quant_rules(int fd, struct Quant *q) Rast_quant_set_neg_infinite_rule(&fcb->quant, dcell, cell); if (Rast_quant_get_pos_infinite_rule(q, &dcell, &cell) > 0) Rast_quant_set_pos_infinite_rule(&fcb->quant, dcell, cell); -} \ No newline at end of file +}