[Ocfs-tools-commits] smushran commits r220 - trunk/fsck
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Thu Oct 14 18:58:44 CDT 2004
Author: smushran
Date: 2004-10-14 18:58:42 -0500 (Thu, 14 Oct 2004)
New Revision: 220
Modified:
trunk/fsck/Makefile
trunk/fsck/blked.c
trunk/fsck/class_print.c
trunk/fsck/class_rw.c
trunk/fsck/fsck.c
trunk/fsck/fsck.h
trunk/fsck/utils.c
trunk/fsck/verify.c
Log:
fixed blked
Modified: trunk/fsck/Makefile
===================================================================
--- trunk/fsck/Makefile 2004-10-07 20:55:26 UTC (rev 219)
+++ trunk/fsck/Makefile 2004-10-14 23:58:42 UTC (rev 220)
@@ -20,7 +20,7 @@
CFLAGS = $(OPTS) -fno-strict-aliasing $(WARNINGS) $(LIBOCFS_CFLAGS)
INCLUDES = -I. -I$(TOPDIR)/libocfs/Common/inc -I$(TOPDIR)/libocfs/Linux/inc
-DEFINES = -DLINUX -DUSERSPACE_TOOL -DSHOW_INVALID_VALUES -DFSCK_OCFS
+DEFINES = -DLINUX -DUSERSPACE_TOOL -DFSCK_OCFS
OPTIMIZE = -O2
Modified: trunk/fsck/blked.c
===================================================================
--- trunk/fsck/blked.c 2004-10-07 20:55:26 UTC (rev 219)
+++ trunk/fsck/blked.c 2004-10-14 23:58:42 UTC (rev 220)
@@ -46,6 +46,10 @@
__u32 fs_num;
+__u32 live_nodes = 0;
+__u64 publ_times[OCFS_MAXIMUM_NODES];
+time_t start_time = 0;
+
ocfs_global_ctxt OcfsGlobalCtxt;
ocfsck_context ctxt;
extern void version(char *progname);
@@ -53,13 +57,16 @@
int parse_blked_cmdline(int argc, char **argv);
int blked_initialize(char **buf);
bool verify_params(void);
-int edit_structure(ocfs_disk_structure *s, char *buf, int idx, int *changed,
- char *option);
+int blked_edit(ocfs_disk_structure *s, char *buf, int idx, int *changed);
+int blked_confirm(__u64 off, ocfs_disk_structure *s, char *buf, int idx,
+ GHashTable *bad);
+int read_publish_times(int fd, bool first_time);
char *usage_str =
-"usage: blked.ocfs [OPTIONS] device\n"
-" -n No hearbeat check\n"
+"usage: blked.ocfs [-I] -o <offset> [-t type] [-V] [-w] device\n"
+" -I Show invalid values\n"
" -o Byte offset\n"
+" -t Type (dir, fe, exth, extd)\n"
" -V Version\n"
" -w Write";
@@ -76,6 +83,9 @@
ctxt.no_hb_chk = false;
ctxt.write_changes = false;
ctxt.verbose = false;
+ ctxt.show_warnings = false;
+ ctxt.hide_invalids = true;
+ ctxt.disk_struct = NULL;
if (argc < 2) {
usage();
@@ -83,12 +93,15 @@
}
while (1) {
- c = getopt(argc, argv, "nwvV?h:l:o:");
+ c = getopt(argc, argv, "InwvV?h:l:o:t:");
if (c == -1)
break;
switch (c) {
+ case 'I':
+ ctxt.hide_invalids = false;
+ break;
case 'o':
p = strchr(optarg, '.');
if (!p)
@@ -108,6 +121,21 @@
case 'n':
ctxt.no_hb_chk = true;
break;
+ case 't':
+ if (!strcasecmp(optarg, "fe"))
+ ctxt.disk_struct = &fileent_t;
+ else if(!strcasecmp(optarg, "dir"))
+ ctxt.disk_struct = &dirnode_t;
+ else if (!strcasecmp(optarg, "exth"))
+ ctxt.disk_struct = &exthdr_t;
+ else if (!strcasecmp(optarg, "extd"))
+ ctxt.disk_struct = &extdat_t;
+ else {
+ usage();
+ goto bail;
+ }
+ break;
+
case 'w':
ctxt.write_changes = true;
break;
@@ -130,7 +158,7 @@
ret = 0;
bail:
return ret;
-} /* parse_blked_cmdline */
+}
/*
* blked_initialize()
@@ -186,7 +214,7 @@
bail:
return ret;
-} /* blked_initialize */
+}
/*
* verify_params()
@@ -204,7 +232,7 @@
ret = true;
bail:
return ret;
-} /* verify_params */
+}
/*
* main()
@@ -212,12 +240,12 @@
*/
int main(int argc, char **argv)
{
- int i, changed;
+ int i;
+ int changed;
char *buf = NULL;
ocfs_disk_structure *s;
ocfs_layout_t *l;
__u64 blocknum;
- char option = '\0';
memset(&ctxt, 0, sizeof(ctxt));
init_global_context();
@@ -235,6 +263,8 @@
init_raw_cleanup_message();
+ memset (publ_times, 0, sizeof(publ_times));
+
if (parse_blked_cmdline(argc, argv) == -1)
goto bail;
@@ -261,12 +291,9 @@
goto bail;
}
- /* Exit if heartbeat detected */
- if (!ctxt.no_hb_chk) {
- if (!check_heart_beat(&ctxt.fd, OCFSCK_PUBLISH_OFF,
- OCFS_SECTOR_SIZE))
- goto bail;
- }
+ /* initialize publish times */
+ if (!read_publish_times(ctxt.fd, true))
+ goto bail;
if (read_one_sector(ctxt.fd, buf, ctxt.offset, 0) == -1) {
LOG_INTERNAL();
@@ -278,7 +305,6 @@
l = &(ocfs_header_layout[ocfs_header_layout_sz - 1]);
if (blocknum < l->block + l->num_blocks) {
for (i = 0; i < ocfs_header_layout_sz; ++i) {
- option = '\0';
l = &(ocfs_header_layout[i]);
if ((s = l->kind) == NULL || s->cls == NULL ||
s->read == NULL || s->write == NULL)
@@ -288,33 +314,39 @@
s->output(buf, 0, NULL, stdout);
while (ctxt.write_changes) {
changed = 0;
- if (edit_structure(s, buf, 0, &changed, &option) != -1)
+ if (blked_edit(s, buf, 0, &changed) != -1)
continue;
if (!changed)
break;
- if ((confirm_changes(ctxt.offset, s, buf, 0, NULL)) == -1)
- LOG_PRINT("Abort write");
+ if ((blked_confirm(ctxt.offset, s, buf, 0, NULL)) == -1)
+ LOG_PRINT("Changes not written to disk.\n");
+ else
+ LOG_PRINT("Changes written to disk.\n");
break;
}
}
}
} else {
- s = find_matching_struct(buf, 0);
+ s = ctxt.disk_struct;
+ if (!s)
+ s = find_matching_struct(buf, 0);
if (s) {
s->output(buf, 0, NULL, stdout);
while (ctxt.write_changes) {
changed = 0;
- if (edit_structure(s, buf, 0, &changed, &option) != -1)
+ if (blked_edit(s, buf, 0, &changed) != -1)
continue;
if (!changed)
break;
- if ((confirm_changes(ctxt.offset, s, buf, 0, NULL)) == -1)
- LOG_PRINT("Abort write");
+ if ((blked_confirm(ctxt.offset, s, buf, 0, NULL)) == -1)
+ LOG_PRINT("Changes not written to disk.\n");
+ else
+ LOG_PRINT("Changes written to disk.\n");
break;
}
@@ -330,20 +362,20 @@
free_aligned(buf);
free_aligned(ctxt.hdr);
exit(0);
-} /* main */
+}
/*
- * edit_structure()
+ * blked_edit()
*
*/
-int edit_structure(ocfs_disk_structure *s, char *buf, int idx, int *changed, char *option)
+int blked_edit(ocfs_disk_structure *s, char *buf, int idx, int *changed)
{
int ret = 0;
int fld;
ocfs_class *cls;
ocfs_class_member *m;
- GString *cur;
- GString *dflt;
+ GString *cur = NULL;
+ GString *dflt = NULL;
char *newval = NULL;
char *bad;
char *loc;
@@ -355,13 +387,12 @@
*changed = 0;
cls = s->cls;
- *option = '\0';
while (1) {
cur = dflt = NULL;
bad = NULL;
- LOG_PRINT("choose a field to edit (1-%d) or 'q' to quit) : ", cls->num_members);
+ LOG_PRINT("choose a field (1-%d) to edit or 'z' to zero-out the block or 'q' to quit) : ", cls->num_members);
if (fgets(newval, USER_INPUT_MAX, stdin) == NULL) {
ret = -1;
break;
@@ -371,38 +402,39 @@
*loc = '\0';
if (strcasecmp(newval, "q") == 0 || strcasecmp(newval, "quit") == 0) {
- *option = tolower(*newval);
ret = -1;
break;
}
+ if (strcasecmp(newval, "z") == 0 || strcasecmp(newval, "zero") == 0) {
+ memset(buf, 0, OCFS_SECTOR_SIZE);
+ (*changed)++;
+ goto end_of_loop;
+ }
+
fld = strtol(newval, &bad, 10);
fld--;
if (bad == newval || IS_INVALID_FIELD_NUM(cls, fld)) {
ret = 0;
- LOG_ERROR("bad field number");
- break;
+ LOG_ERROR("Bad field number");
+ goto end_of_loop;
}
- // show current value and default value
+ /* show current and default values */
m = &(cls->members[fld]);
- if (m->to_string(&cur, buf, &(m->type))==-1) {
- ret = -1;
- LOG_ERROR("to_string failed");
- break;
- }
+ m->to_string(&cur, buf, &(m->type));
if (s->defaults(buf, &dflt, idx, fld)==-1) {
ret = -1;
- LOG_ERROR("defaults failed");
+ LOG_ERROR("Defaults failed");
break;
}
LOG_PRINT("%s : %s (default=%s)\n", m->name,
cur ? cur->str : "", dflt ? dflt->str : "");
- // get new value and validate it
+ /* get new value and validate it */
if (fgets(newval, USER_INPUT_MAX, stdin) == NULL) {
ret = -1;
break;
@@ -424,14 +456,16 @@
break;
}
- if ((ret = m->from_string(newval, buf, &(m->type))) == -1) {
- LOG_ERROR("bad entry");
- ret = -1;
- break;
+ if (strlen(newval)) {
+ if ((ret = m->from_string(newval, buf, &(m->type))) == -1) {
+ LOG_ERROR("Invalid value");
+ ret = 0;
+ } else
+ (*changed)++;
}
+end_of_loop:
+ s->output(buf, 0, NULL, stdout);
- (*changed)++;
-
if (dflt) {
g_string_free(dflt, true);
dflt = NULL;
@@ -453,4 +487,120 @@
safefree(newval);
return ret;
-} /* edit_structure */
+}
+
+/*
+ * blked_confirm()
+ *
+ */
+int blked_confirm(__u64 off, ocfs_disk_structure *s, char *buf, int idx,
+ GHashTable *bad)
+{
+ int ret = -1;
+ char *yesno, *loc;
+ int fd = ctxt.fd;
+
+ yesno = malloc(USER_INPUT_MAX);
+ if (!yesno) {
+ LOG_INTERNAL();
+ goto bail;
+ }
+
+ s->output(buf, 0, NULL, stdout);
+// if (s->output(buf, idx, bad, stdout)==-1) {
+// //fprintf(stderr, "at least one bad field found\n");
+// }
+
+ LOG_PRINT("Do you really want to write your changes out (y/N)? : ");
+
+ if (fgets(yesno, USER_INPUT_MAX, stdin) == NULL) {
+ ret = -1;
+ goto bail;
+ }
+
+ if ((loc = rindex(yesno, '\n')) != NULL)
+ *loc = '\0';
+
+ if (strcasecmp(yesno, "yes")==0 || strcasecmp(yesno, "y")==0) {
+ if (!live_nodes) {
+ if (!read_publish_times (fd, false)) {
+ LOG_INTERNAL();
+ goto bail;
+ }
+ }
+
+ if (live_nodes) {
+ LOG_PRINT("ERROR: One or more nodes mounted the volume during "
+ "the editing. Aborting.");
+ goto bail;
+ }
+
+ if ((ret = s->write(fd, buf, off, idx)) == -1) {
+ LOG_INTERNAL();
+ goto bail;
+ }
+ }
+
+bail:
+ safefree(yesno);
+ return ret;
+}
+
+/*
+ * read_publish_times()
+ *
+ */
+int read_publish_times(int fd, bool first_time)
+{
+ ocfs_publish *publish = NULL;
+ char *buf = NULL;
+ char *p;
+ int i;
+ int ret = 0;
+ __u32 node;
+
+ if (!first_time) {
+ printf("Checking heart beat on volume ");
+ while(time(NULL) - start_time < OCFS_HBT_WAIT) {
+ printf(".");
+ fflush(stdout);
+ sleep(1);
+ }
+ printf("\r \r");
+ fflush(stdout);
+ }
+
+ if (!read_publish(fd, OCFSCK_PUBLISH_OFF, OCFS_SECTOR_SIZE,
+ (void **)&buf)) {
+ LOG_INTERNAL();
+ goto bail;
+ }
+
+ if (first_time) {
+ start_time = time(NULL);
+ p = (char *)buf;
+ for (i = 0; i < OCFS_MAXIMUM_NODES; i++) {
+ publish = (ocfs_publish *) p;
+ publ_times[i] = publish->time;
+ p += OCFS_SECTOR_SIZE;
+ }
+ } else {
+ p = (char *)buf;
+ for (i = 0, node = 1; i < OCFS_MAXIMUM_NODES;
+ i++, node <<= 1) {
+ publish = (ocfs_publish *) p;
+ if (publ_times[i] != publish->time) {
+ publ_times[i] = publish->time;
+ live_nodes |= node;
+ } else
+ live_nodes &= ~node;
+ p += OCFS_SECTOR_SIZE;
+ }
+ }
+
+ ret = 1;
+
+bail:
+ safefree (buf);
+ return ret;
+}
Modified: trunk/fsck/class_print.c
===================================================================
--- trunk/fsck/class_print.c 2004-10-07 20:55:26 UTC (rev 219)
+++ trunk/fsck/class_print.c 2004-10-14 23:58:42 UTC (rev 220)
@@ -3,7 +3,7 @@
*
* generic print for structures in ocfs file system check utility
*
- * Copyright (C) 2003 Oracle. All rights reserved.
+ * Copyright (C) 2003, 2004 Oracle. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
@@ -25,6 +25,8 @@
#include "fsck.h"
+extern ocfsck_context ctxt;
+
/*
* print_class_member()
*
@@ -34,14 +36,17 @@
{
GString *gs = NULL;
int ret;
- char *inval_str = "";
ret = mbr->to_string(&gs, buf, &mbr->type);
- if (ret != 0 || bad)
- inval_str = "<INVALID VALUE> ";
-
- fprintf(out, "%s: %s%s", mbr->name, inval_str, gs==NULL ? "NULL" : gs->str);
+ fprintf(out, "%s:", mbr->name);
+ if (ret != 0 || bad) {
+ fprintf(out, " <invalid>");
+ if (!ctxt.hide_invalids)
+ fprintf(out, " %s", gs==NULL ? "NULL" : gs->str);
+ } else
+ fprintf(out, " %s", gs==NULL ? "NULL" : gs->str);
+
if (gs)
g_string_free(gs, true);
@@ -90,8 +95,5 @@
*/
int print_class(char *buf, ocfs_class *cl, FILE *out, GHashTable *ht)
{
- if (ctxt.write_changes)
- return _print_class(buf, cl, out, true, ht);
- else
- return _print_class(buf, cl, out, false, ht);
+ return _print_class(buf, cl, out, ctxt.write_changes, ht);
} /* print_class */
Modified: trunk/fsck/class_rw.c
===================================================================
--- trunk/fsck/class_rw.c 2004-10-07 20:55:26 UTC (rev 219)
+++ trunk/fsck/class_rw.c 2004-10-14 23:58:42 UTC (rev 220)
@@ -3,7 +3,7 @@
*
* reader-writer functions for each type
*
- * Copyright (C) 2003 Oracle. All rights reserved.
+ * Copyright (C) 2003, 2004 Oracle. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
@@ -51,6 +51,8 @@
#include "fsck.h"
#include "classes.h"
+extern ocfsck_context ctxt;
+
// for now, ultraslow-nonhashed-stinkyperformance
// eh, who cares
ocfs_class_member * find_class_member(ocfs_class *cl, const char *name, int *idx)
@@ -91,12 +93,11 @@
__u32 attribs;
attribs = G_STRUCT_MEMBER(__u32, top, info->off);
- if (_attribs_valid(top, info) == -1)
- {
-#ifdef SHOW_INVALID_VALUES
- *retval = g_string_new("");
- g_string_sprintf(*retval, "%u", attribs);
-#endif
+ if (_attribs_valid(top, info) == -1) {
+ if (!ctxt.hide_invalids) {
+ *retval = g_string_new("");
+ g_string_sprintf(*retval, "%u", attribs);
+ }
return -1;
}
@@ -182,12 +183,11 @@
__s32 val = 0;
val = G_STRUCT_MEMBER(__s32, top, info->off);
- if (_bool_valid(top, info) == -1)
- {
-#ifdef SHOW_INVALID_VALUES
- *retval = g_string_new("");
- g_string_sprintf(*retval, "%d", val);
-#endif
+ if (_bool_valid(top, info) == -1) {
+ if (!ctxt.hide_invalids) {
+ *retval = g_string_new("");
+ g_string_sprintf(*retval, "%d", val);
+ }
return -1;
}
*retval = g_string_new("");
@@ -217,12 +217,11 @@
__u8 val = 0;
val = G_STRUCT_MEMBER(__u8, top, info->off);
- if (_bool_valid(top, info) == -1)
- {
-#ifdef SHOW_INVALID_VALUES
- *retval = g_string_new("");
- g_string_sprintf(*retval, "%u", val);
-#endif
+ if (_bool_valid(top, info) == -1) {
+ if (!ctxt.hide_invalids) {
+ *retval = g_string_new("");
+ g_string_sprintf(*retval, "%u", val);
+ }
return -1;
}
*retval = g_string_new("");
@@ -289,10 +288,11 @@
return 0;
}
-#ifdef SHOW_INVALID_VALUES
- *retval = g_string_new("");
- g_string_sprintf(*retval, "%llu", csize);
-#endif
+ if (!ctxt.hide_invalids) {
+ *retval = g_string_new("");
+ g_string_sprintf(*retval, "%llu", csize);
+ }
+
return -1;
}
@@ -331,12 +331,11 @@
char *t, *t2;
sec = G_STRUCT_MEMBER(__u64, top, info->off);
- if (_date_valid(top, info) == -1)
- {
-#ifdef SHOW_INVALID_VALUES
- *retval = g_string_new("");
- g_string_sprintf(*retval, "%llu", sec);
-#endif
+ if (_date_valid(top, info) == -1) {
+ if (!ctxt.hide_invalids) {
+ *retval = g_string_new("");
+ g_string_sprintf(*retval, "%llu", sec);
+ }
return -1;
}
*retval = g_string_new("");
@@ -408,12 +407,11 @@
{
__u8 flag;
flag = G_STRUCT_MEMBER(__u8, top, info->off);
- if (_dirflag_valid(top, info) == -1)
- {
-#ifdef SHOW_INVALID_VALUES
- *retval = g_string_new("");
- g_string_sprintf(*retval, "%u", flag);
-#endif
+ if (_dirflag_valid(top, info) == -1) {
+ if (!ctxt.hide_invalids) {
+ *retval = g_string_new("");
+ g_string_sprintf(*retval, "%u", flag);
+ }
return -1;
}
*retval = g_string_new("");
@@ -462,10 +460,10 @@
arr = G_STRUCT_MEMBER_P(top, info->off);
if (_dirindex_valid(top, info) == -1) {
-#ifdef SHOW_INVALID_VALUES
- *retval = g_string_new("");
- g_string_sprintf(*retval, "[%u, ...]", arr[0]);
-#endif
+ if (!ctxt.hide_invalids) {
+ *retval = g_string_new("");
+ g_string_sprintf(*retval, "[%u, ...]", arr[0]);
+ }
return -1;
}
@@ -490,24 +488,28 @@
int _string_to_dirindex_u8(char *newval, void *top, typeinfo *info)
{
int ret = -1;
- char **arr;
- __u8 index[256];
+ char **arr = NULL;
+ __u8 newind[256];
int i;
+ __u8 *oldind;
+ int tmp;
- memset(&(index[0]), 0, 256);
- arr = g_strsplit(newval, ":", 0);
+ oldind = G_STRUCT_MEMBER_P(top, info->off);
+ arr = g_strsplit(newval, " ", 0);
- for (i=0; i<256; i++)
- {
- int tmp;
- if (arr[i]==NULL)
+ memcpy(newind, oldind, sizeof(newind));
+
+ for (i = 0; i < info->array_size && arr[i] != NULL; i++) {
+ if (!arr[i])
break;
- tmp = atoi(arr[i]);
- if (tmp<0 || tmp>255)
+ tmp = atoi(arr[i]);
+ if (tmp < 0 || tmp > 255)
goto bail;
- index[i] = (__u8)tmp;
+ newind[i] = (__u8)tmp;
}
- memcpy(G_STRUCT_MEMBER(__u8 *, top, info->off), index, 256);
+
+ memcpy(oldind, newind, 256);
+
ret = 0;
bail:
@@ -517,7 +519,7 @@
char * _get_dirindex_helptext(typeinfo *info)
{
- return strdup("a string like 5:7:1:2:4:255:... with each index between 0 and 255");
+ return strdup("a string like 5 7 1 2 4 255 ... with each index between 0 and 255");
}
@@ -531,12 +533,11 @@
{
__s8 idx;
idx = G_STRUCT_MEMBER(__s8, top, info->off);
- if (_dirnodeindex_valid(top, info) == -1)
- {
-#ifdef SHOW_INVALID_VALUES
- *retval = g_string_new("");
- g_string_sprintf(*retval, "%d", idx);
-#endif
+ if (_dirnodeindex_valid(top, info) == -1) {
+ if (!ctxt.hide_invalids) {
+ *retval = g_string_new("");
+ g_string_sprintf(*retval, "%d", idx);
+ }
return -1;
}
*retval = g_string_new("");
@@ -612,12 +613,11 @@
{
__s64 ptr;
ptr = G_STRUCT_MEMBER(__s64, top, info->off);
- if (_diskptr_valid(top, info) == -1)
- {
-#ifdef SHOW_INVALID_VALUES
- *retval = g_string_new("");
- g_string_sprintf(*retval, "%u.%u", HILO(ptr));
-#endif
+ if (_diskptr_valid(top, info) == -1) {
+ if (!ctxt.hide_invalids) {
+ *retval = g_string_new("");
+ g_string_sprintf(*retval, "%u.%u", HILO(ptr));
+ }
return -1;
}
*retval = g_string_new("");
@@ -632,12 +632,19 @@
{
__s64 ptr;
char *bad;
+ char *p;
if (strcasecmp(newval, "INVALID_NODE_POINTER")==0)
ptr = INVALID_NODE_POINTER;
- else
- {
- ptr = strtoll(newval, &bad, 10);
+ else {
+ p = strchr(newval, '.');
+ if (!p)
+ ptr = strtoll(newval, &bad, 10);
+ else {
+ *p = '\0';
+ ptr = ((__s64) strtol(newval, &bad, 10)) << 32;
+ ptr |= strtol(++p, &bad, 10);
+ }
if (bad==newval || ptr<-1)
return -1;
}
@@ -675,12 +682,11 @@
__u32 type;
type = G_STRUCT_MEMBER(__u32, top, info->off);
- if (_extenttype_valid(top, info) == -1)
- {
-#ifdef SHOW_INVALID_VALUES
- *retval = g_string_new("");
- g_string_sprintf(*retval, "%u", type);
-#endif
+ if (_extenttype_valid(top, info) == -1) {
+ if (!ctxt.hide_invalids) {
+ *retval = g_string_new("");
+ g_string_sprintf(*retval, "%u", type);
+ }
return -1;
}
@@ -735,12 +741,11 @@
__u32 flag;
flag = G_STRUCT_MEMBER(__u32, top, info->off);
- if (_fileflag_valid(top, info) == -1)
- {
-#ifdef SHOW_INVALID_VALUES
- *retval = g_string_new("");
- g_string_sprintf(*retval, "%u", flag);
-#endif
+ if (_fileflag_valid(top, info) == -1) {
+ if (!ctxt.hide_invalids) {
+ *retval = g_string_new("");
+ g_string_sprintf(*retval, "%u", flag);
+ }
return -1;
}
@@ -863,12 +868,11 @@
*retval = g_string_new("");
id = G_STRUCT_MEMBER(__u32, top, info->off);
- if (_gid_valid(top, info) == -1)
- {
-#ifdef SHOW_INVALID_VALUES
- *retval = g_string_new("");
- g_string_sprintf(*retval, "%u", id);
-#endif
+ if (_gid_valid(top, info) == -1) {
+ if (!ctxt.hide_invalids) {
+ *retval = g_string_new("");
+ g_string_sprintf(*retval, "%u", id);
+ }
return -1;
}
gr = getgrgid(id);
@@ -923,12 +927,11 @@
*retval = g_string_new("");
id = G_STRUCT_MEMBER(__u32, top, info->off);
- if (_uid_valid(top, info) == -1)
- {
-#ifdef SHOW_INVALID_VALUES
- *retval = g_string_new("");
- g_string_sprintf(*retval, "%u", id);
-#endif
+ if (_uid_valid(top, info) == -1) {
+ if (!ctxt.hide_invalids) {
+ *retval = g_string_new("");
+ g_string_sprintf(*retval, "%u", id);
+ }
return -1;
}
pw = getpwuid(id);
@@ -977,12 +980,11 @@
__u8 lvl;
lvl = G_STRUCT_MEMBER(__u8, top, info->off);
- if (_locklevel_valid(top, info) == -1)
- {
-#ifdef SHOW_INVALID_VALUES
- *retval = g_string_new("");
- g_string_sprintf(*retval, "%u", lvl);
-#endif
+ if (_locklevel_valid(top, info) == -1) {
+ if (!ctxt.hide_invalids) {
+ *retval = g_string_new("");
+ g_string_sprintf(*retval, "%u", lvl);
+ }
return -1;
}
@@ -1048,12 +1050,11 @@
bm = G_STRUCT_MEMBER(__u64, top, info->off);
- if (_nodebitmap_valid(top, info) == -1)
- {
-#ifdef SHOW_INVALID_VALUES
- *retval = g_string_new("");
- g_string_sprintf(*retval, "%llu", bm);
-#endif
+ if (_nodebitmap_valid(top, info) == -1) {
+ if (!ctxt.hide_invalids) {
+ *retval = g_string_new("");
+ g_string_sprintf(*retval, "%llu", bm);
+ }
return -1;
}
@@ -1107,12 +1108,11 @@
__u32 num;
num = G_STRUCT_MEMBER(__u32, top, info->off);
- if (_nodenum_valid(top, info) == -1)
- {
-#ifdef SHOW_INVALID_VALUES
- *retval = g_string_new("");
- g_string_sprintf(*retval, "%u", num);
-#endif
+ if (_nodenum_valid(top, info) == -1) {
+ if (!ctxt.hide_invalids) {
+ *retval = g_string_new("");
+ g_string_sprintf(*retval, "%u", num);
+ }
return -1;
}
@@ -1134,8 +1134,10 @@
num = OCFS_INVALID_NODE_NUM;
else
num = strtoul(newval, &bad, 10);
- if (bad == newval || num<0 || num>31)
+ if (bad == newval)
return -1;
+ if (num != OCFS_INVALID_NODE_NUM && num >= OCFS_MAXIMUM_NODES)
+ return -1;
G_STRUCT_MEMBER(__u32, top, info->off) = num;
return 0;
}
@@ -1145,12 +1147,11 @@
__s32 num;
num = G_STRUCT_MEMBER(__s32, top, info->off);
- if (_nodenum_valid(top, info) == -1)
- {
-#ifdef SHOW_INVALID_VALUES
- *retval = g_string_new("");
- g_string_sprintf(*retval, "%d", num);
-#endif
+ if (_nodenum_valid(top, info) == -1) {
+ if (!ctxt.hide_invalids) {
+ *retval = g_string_new("");
+ g_string_sprintf(*retval, "%d", num);
+ }
return -1;
}
@@ -1194,12 +1195,11 @@
__u32 mode;
mode = G_STRUCT_MEMBER(__u32, top, info->off);
- if (_perms_valid(top, info) == -1)
- {
-#ifdef SHOW_INVALID_VALUES
- *retval = g_string_new("");
- g_string_sprintf(*retval, "%u", mode);
-#endif
+ if (_perms_valid(top, info) == -1) {
+ if (!ctxt.hide_invalids) {
+ *retval = g_string_new("");
+ g_string_sprintf(*retval, "%u", mode);
+ }
return -1;
}
@@ -1288,12 +1288,11 @@
{
__u32 sync;
sync = G_STRUCT_MEMBER(__u32, top, info->off);
- if (_syncflag_valid(top, info) == -1)
- {
-#ifdef SHOW_INVALID_VALUES
- *retval = g_string_new("");
- g_string_sprintf(*retval, "%u", sync);
-#endif
+ if (_syncflag_valid(top, info) == -1) {
+ if (!ctxt.hide_invalids) {
+ *retval = g_string_new("");
+ g_string_sprintf(*retval, "%u", sync);
+ }
return -1;
}
@@ -1346,12 +1345,11 @@
{
__u8 sync;
sync = G_STRUCT_MEMBER(__u8, top, info->off);
- if (_syncflag_valid(top, info) == -1)
- {
-#ifdef SHOW_INVALID_VALUES
- *retval = g_string_new("");
- g_string_sprintf(*retval, "%u", sync);
-#endif
+ if (_syncflag_valid(top, info) == -1) {
+ if (!ctxt.hide_invalids) {
+ *retval = g_string_new("");
+ g_string_sprintf(*retval, "%u", sync);
+ }
return -1;
}
@@ -1410,6 +1408,17 @@
// CHAR ARRAY: __u8[]
int _char_array_valid(void *top, typeinfo *info)
{
+ int i;
+ __u8 *arr;
+
+ arr = G_STRUCT_MEMBER_P(top, info->off);
+ for (i = 0; i < info->array_size; i++) {
+ if (arr[i] == '\0')
+ break;
+ if (!isprint(arr[i]))
+ return -1;
+ }
+
return 0;
}
@@ -1421,12 +1430,11 @@
if (info->array_size <= 0)
return -1;
arr = G_STRUCT_MEMBER_P(top, info->off);
- if (_char_array_valid(top, info) == -1)
- {
-#ifdef SHOW_INVALID_VALUES
- *retval = g_string_new("");
- g_string_sprintf(*retval, "[ %u, ... ]", arr[0]);
-#endif
+ if (_char_array_valid(top, info) == -1) {
+ if (!ctxt.hide_invalids) {
+ *retval = g_string_new("");
+ g_string_sprintf(*retval, "[ %u, ... ]", arr[0]);
+ }
return -1;
}
@@ -1479,12 +1487,11 @@
if (info->array_size <= 0)
return -1;
arr = G_STRUCT_MEMBER_P(top, info->off);
- if (_char_array_valid(top, info) == -1)
- {
-#ifdef SHOW_INVALID_VALUES
- *retval = g_string_new("");
- g_string_sprintf(*retval, "[ %X, ... ]", arr[0]);
-#endif
+ if (_hex_array_valid(top, info) == -1) {
+ if (!ctxt.hide_invalids) {
+ *retval = g_string_new("");
+ g_string_sprintf(*retval, "[ %X, ... ]", arr[0]);
+ }
return -1;
}
@@ -1609,12 +1616,11 @@
__s32 num;
num = G_STRUCT_MEMBER(__s32, top, info->off);
- if (_number_range_valid(top, info) == -1)
- {
-#ifdef SHOW_INVALID_VALUES
- *retval = g_string_new("");
- g_string_sprintf(*retval, "%d", num);
-#endif
+ if (_number_range_valid(top, info) == -1) {
+ if (!ctxt.hide_invalids) {
+ *retval = g_string_new("");
+ g_string_sprintf(*retval, "%d", num);
+ }
return -1;
}
*retval = g_string_new("");
@@ -1642,12 +1648,11 @@
__u8 num;
num = G_STRUCT_MEMBER(__u8, top, info->off);
- if (_number_range_valid(top, info) == -1)
- {
-#ifdef SHOW_INVALID_VALUES
- *retval = g_string_new("");
- g_string_sprintf(*retval, "%u", num);
-#endif
+ if (_number_range_valid(top, info) == -1) {
+ if (!ctxt.hide_invalids) {
+ *retval = g_string_new("");
+ g_string_sprintf(*retval, "%u", num);
+ }
return -1;
}
@@ -1677,12 +1682,11 @@
__u16 num;
num = G_STRUCT_MEMBER(__u16, top, info->off);
- if (_number_range_valid(top, info) == -1)
- {
-#ifdef SHOW_INVALID_VALUES
- *retval = g_string_new("");
- g_string_sprintf(*retval, "%u", num);
-#endif
+ if (_number_range_valid(top, info) == -1) {
+ if (!ctxt.hide_invalids) {
+ *retval = g_string_new("");
+ g_string_sprintf(*retval, "%u", num);
+ }
return -1;
}
@@ -1712,12 +1716,11 @@
__u32 num;
num = G_STRUCT_MEMBER(__u32, top, info->off);
- if (_number_range_valid(top, info) == -1)
- {
-#ifdef SHOW_INVALID_VALUES
- *retval = g_string_new("");
- g_string_sprintf(*retval, "%u", num);
-#endif
+ if (_number_range_valid(top, info) == -1) {
+ if (!ctxt.hide_invalids) {
+ *retval = g_string_new("");
+ g_string_sprintf(*retval, "%u", num);
+ }
return -1;
}
@@ -1746,12 +1749,11 @@
__u64 num;
num = G_STRUCT_MEMBER(__u64, top, info->off);
- if (_number_range_valid(top, info) == -1)
- {
-#ifdef SHOW_INVALID_VALUES
- *retval = g_string_new("");
- g_string_sprintf(*retval, "%llu", num);
-#endif
+ if (_number_range_valid(top, info) == -1) {
+ if (!ctxt.hide_invalids) {
+ *retval = g_string_new("");
+ g_string_sprintf(*retval, "%llu", num);
+ }
return -1;
}
*retval = g_string_new("");
@@ -1837,8 +1839,7 @@
return 0;
fail:
-#ifdef SHOW_INVALID_VALUES
- {
+ if (!ctxt.hide_invalids) {
int j;
for (j=0; j<info->array_size; j++)
{
@@ -1846,44 +1847,44 @@
g_string_append(*retval, ":");
g_string_sprintfa(*retval, "%u", arr[j]);
}
- }
-#else
- g_string_free(*retval, true);
-#endif
+ } else
+ g_string_free(*retval, true);
return -1;
}
int _string_to_voteflag_array_u8(char *newval, void *top, typeinfo *info)
{
- __u8 *flag;
+ __u8 *oldflag;
int ret = -1, i;
char **arr;
+ __u8 newflag[OCFS_MAXIMUM_NODES];
if (info->array_size <= 0)
return -1;
- flag = G_STRUCT_MEMBER(__u8 *, top, info->off);
+ oldflag = G_STRUCT_MEMBER_P(top, info->off);
arr = g_strsplit(newval, " ", 0);
-
- for (i=0; i<info->array_size && arr[i]!=NULL; i++)
- {
- flag[i] = 0;
+
+ memcpy(newflag, oldflag, sizeof(newflag));
+
+ for (i = 0; i < info->array_size && arr[i] != NULL; i++) {
if (strcasecmp(arr[i], "vote")==0)
- flag[i] |= FLAG_VOTE_NODE;
+ newflag[i] = FLAG_VOTE_NODE;
else if (strcasecmp(arr[i], "updated")==0)
- flag[i] |= FLAG_VOTE_OIN_UPDATED;
+ newflag[i] = FLAG_VOTE_OIN_UPDATED;
else if (strcasecmp(arr[i], "inuse")==0)
- flag[i] |= FLAG_VOTE_OIN_ALREADY_INUSE;
+ newflag[i] = FLAG_VOTE_OIN_ALREADY_INUSE;
else if (strcasecmp(arr[i], "retry")==0)
- flag[i] |= FLAG_VOTE_UPDATE_RETRY;
+ newflag[i] = FLAG_VOTE_UPDATE_RETRY;
else if (strcasecmp(arr[i], "delete")==0)
- flag[i] |= FLAG_VOTE_FILE_DEL;
+ newflag[i] = FLAG_VOTE_FILE_DEL;
else if (strcasecmp(arr[i], "none")==0 || atoi(arr[i])==0)
- flag[i] = 0;
+ newflag[i] = 0;
else
goto bail;
+ }
+ memcpy(oldflag, newflag, sizeof(newflag));
- }
ret = 0;
bail:
g_strfreev(arr);
Modified: trunk/fsck/fsck.c
===================================================================
--- trunk/fsck/fsck.c 2004-10-07 20:55:26 UTC (rev 219)
+++ trunk/fsck/fsck.c 2004-10-14 23:58:42 UTC (rev 220)
@@ -47,13 +47,18 @@
ocfsck_context ctxt;
extern void version(char *progname);
+#if 0
int edit_structure(ocfs_disk_structure *s, char *buf, int idx, int *changed, char *option);
+int confirm_changes(__u64 off, ocfs_disk_structure *s, char *buf, int idx, GHashTable *bad);
+#endif
char *usage_str =
"usage: fsck.ocfs [OPTIONS] device\n"
+" -H Hide invalid values\n"
" -n No hearbeat check\n"
" -w Writeable\n"
-" -V Version\n"
+" -W Show Warnings\n"
+" -V Show Version\n"
" -v Verbose\n"
" -q Quiet";
@@ -73,6 +78,8 @@
ctxt.modify_all = false;
ctxt.quiet = false;
ctxt.dev_is_file = false;
+ ctxt.show_warnings = false;
+ ctxt.hide_invalids = false;
if (argc < 2) {
usage();
@@ -81,15 +88,21 @@
while (1) {
off = 0;
- c = getopt(argc, argv, "wnVvmqf?");
+ c = getopt(argc, argv, "HwWnVvmqf?");
if (c == -1)
break;
switch (c) {
+ case 'H':
+ ctxt.hide_invalids = true;
+ break;
case 'w':
ctxt.write_changes = true;
break;
+ case 'W':
+ ctxt.show_warnings = true;
+ break;
case 'n':
ctxt.no_hb_chk = true;
break;
@@ -129,6 +142,7 @@
return ret;
} /* parse_fsck_cmdline */
+#if 0
/*
* edit_structure()
*
@@ -257,7 +271,55 @@
return ret;
} /* edit_structure */
+/*
+ * confirm_changes()
+ *
+ */
+int confirm_changes(__u64 off, ocfs_disk_structure *s, char *buf, int idx, GHashTable *bad)
+{
+ int ret = -1;
+ char *yesno, *loc;
+ int fd = ctxt.fd;
+ yesno = malloc(USER_INPUT_MAX);
+ if (!yesno) {
+ LOG_INTERNAL();
+ goto bail;
+ }
+
+ if (s->output(buf, idx, bad, stdout)==-1) {
+ //fprintf(stderr, "at least one bad field found\n");
+ }
+
+ printf("\n\nDo you really want to write your changes out? : ");
+
+ if (fgets(yesno, USER_INPUT_MAX, stdin) == NULL) {
+ ret = -1;
+ goto bail;
+ }
+
+ if ((loc = rindex(yesno, '\n')) != NULL)
+ *loc = '\0';
+
+ if (strcasecmp(yesno, "yes")==0 || strcasecmp(yesno, "y")==0) {
+ if ((ret = s->write(fd, buf, off, idx)) == -1) {
+ LOG_INTERNAL();
+ goto bail;
+ }
+ else {
+ GHashTable *tmp = NULL;
+ ret = s->verify(fd, buf, off, idx, &tmp);
+ if (tmp != NULL)
+ g_hash_table_destroy(tmp);
+ }
+ }
+
+bail:
+ safefree(yesno);
+ return ret;
+} /* confirm_changes */
+#endif
+
/*
* fsck_initialize()
*
Modified: trunk/fsck/fsck.h
===================================================================
--- trunk/fsck/fsck.h 2004-10-07 20:55:26 UTC (rev 219)
+++ trunk/fsck/fsck.h 2004-10-14 23:58:42 UTC (rev 220)
@@ -68,7 +68,7 @@
#define MAX_SYSTEM_FILES (CLEANUP_FILE_BASE_ID + OCFS_MAXIMUM_NODES) /* 193? */
#define DIR_NODE_SIZE (1024 * 128)
#define IS_INVALID_FIELD_NUM(c,n) ((n) >= (c)->num_members || (n) < 0)
-#define USER_INPUT_MAX 1024
+#define USER_INPUT_MAX 2048
#define BITS_PER_BYTE 8
#define VOL_BITMAP_BYTES (1024 * 1024)
@@ -163,8 +163,6 @@
void handle_signal(int sig);
void init_global_context(void);
int parse_fsck_cmdline(int argc, char **argv);
-int confirm_changes(__u64 off, ocfs_disk_structure *s, char *buf, int idx,
- GHashTable *bad);
int read_print_struct(ocfs_disk_structure *s, char *buf, __u64 off, int idx,
GHashTable **bad);
void *mem_alloc(int len);
@@ -257,6 +255,9 @@
bool quiet;
bool no_hb_chk;
bool dev_is_file;
+ bool show_warnings;
+ bool hide_invalids;
+ ocfs_disk_structure *disk_struct;
ocfs_vol_disk_hdr *hdr;
__u8 *vol_bm;
__u8 *dir_bm[OCFS_MAXIMUM_NODES];
Modified: trunk/fsck/utils.c
===================================================================
--- trunk/fsck/utils.c 2004-10-07 20:55:26 UTC (rev 219)
+++ trunk/fsck/utils.c 2004-10-14 23:58:42 UTC (rev 220)
@@ -74,55 +74,6 @@
debug_exclude = atoi(tmp);
}
-
-/*
- * confirm_changes()
- *
- */
-int confirm_changes(__u64 off, ocfs_disk_structure *s, char *buf, int idx, GHashTable *bad)
-{
- int ret = -1;
- char *yesno, *loc;
- int fd = ctxt.fd;
-
- yesno = malloc(USER_INPUT_MAX);
- if (!yesno) {
- LOG_INTERNAL();
- goto bail;
- }
-
- if (s->output(buf, idx, bad, stdout)==-1) {
- //fprintf(stderr, "at least one bad field found\n");
- }
-
- printf("\n\nDo you really want to write your changes out? : ");
-
- if (fgets(yesno, USER_INPUT_MAX, stdin) == NULL) {
- ret = -1;
- goto bail;
- }
-
- if ((loc = rindex(yesno, '\n')) != NULL)
- *loc = '\0';
-
- if (strcasecmp(yesno, "yes")==0 || strcasecmp(yesno, "y")==0) {
- if ((ret = s->write(fd, buf, off, idx)) == -1) {
- LOG_INTERNAL();
- goto bail;
- }
- else {
- GHashTable *tmp = NULL;
- ret = s->verify(fd, buf, off, idx, &tmp);
- if (tmp != NULL)
- g_hash_table_destroy(tmp);
- }
- }
-
-bail:
- safefree(yesno);
- return ret;
-} /* confirm_changes */
-
static char *saved_block = NULL;
/*
* read_print_struct()
@@ -647,7 +598,7 @@
if (!bits->len)
goto bail;
- LOG_WARNING("Global bitmap has unset bits");
+ LOG_ERROR("Global bitmap has unset bits");
print_bit_ranges(bits, "unset", bitmap);
for (i = 0; i < bits->len; ++i) {
@@ -725,10 +676,9 @@
find_unset_bits(vol_bm, "global");
-//#ifdef STILL_DEBUGGING
/* cross check... ensure no bit in the global bitmap is set */
- find_set_bits(vol_bm, "global");
-//#endif
+ if (ctxt.show_warnings)
+ find_set_bits(vol_bm, "global");
ret = 0;
bail:
@@ -1617,8 +1567,8 @@
num_del = largest_off - dirnode->num_ent_used + 1;
- if (!num_del)
- goto bail;
+// if (!num_del)
+// goto bail;
fe = (ocfs_file_entry *) (FIRST_FILE_ENTRY (dirnode));
Modified: trunk/fsck/verify.c
===================================================================
--- trunk/fsck/verify.c 2004-10-07 20:55:26 UTC (rev 219)
+++ trunk/fsck/verify.c 2004-10-14 23:58:42 UTC (rev 220)
@@ -3,7 +3,7 @@
*
* verification checks for ocfs file system check utility
*
- * Copyright (C) 2003 Oracle. All rights reserved.
+ * Copyright (C) 2003, 2004 Oracle. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
@@ -82,7 +82,8 @@
cl = lay->kind->cls;
*bad = g_hash_table_new(g_direct_hash, g_direct_equal);
- if (check_outside_bounds(buf, sizeof(ocfs_node_config_hdr)) == -1)
+ if (ctxt.show_warnings &&
+ check_outside_bounds(buf, sizeof(ocfs_node_config_hdr)) == -1)
LOG_WARNING("nonzero bytes after the disk structure");
ret = verify_disk_lock (fd, buf, offset, idx, bad);
@@ -122,7 +123,8 @@
cl = lay->kind->cls;
*bad = g_hash_table_new(g_direct_hash, g_direct_equal);
- if (check_outside_bounds(buf, sizeof(ocfs_disk_node_config_info)) == -1)
+ if (ctxt.show_warnings &&
+ check_outside_bounds(buf, sizeof(ocfs_disk_node_config_info)) == -1)
LOG_WARNING("nonzero bytes after the disk structure");
ret = verify_disk_lock (fd, buf, offset, idx, bad);
@@ -424,7 +426,8 @@
cl = &ocfs_dir_node_class;
*bad = g_hash_table_new(g_direct_hash, g_direct_equal);
- if (check_outside_bounds(buf, sizeof(ocfs_dir_node)) == -1)
+ if (ctxt.show_warnings &&
+ check_outside_bounds(buf, sizeof(ocfs_dir_node)) == -1)
LOG_WARNING("nonzero bytes after the disk structure");
/* ocfs_disk_lock disk_lock; */
@@ -494,7 +497,8 @@
cl = &ocfs_file_entry_class;
*bad = g_hash_table_new(g_direct_hash, g_direct_equal);
- if (check_outside_bounds(buf, sizeof(ocfs_file_entry)) == -1)
+ if (ctxt.show_warnings &&
+ check_outside_bounds(buf, sizeof(ocfs_file_entry)) == -1)
LOG_WARNING("nonzero bytes after the disk structure");
/* ocfs_disk_lock disk_lock; */
@@ -753,7 +757,8 @@
cl = lay->kind->cls;
*bad = g_hash_table_new(g_direct_hash, g_direct_equal);
- if (check_outside_bounds(buf, sizeof(ocfs_vol_disk_hdr)) == -1) {
+ if (ctxt.show_warnings &&
+ check_outside_bounds(buf, sizeof(ocfs_vol_disk_hdr)) == -1) {
LOG_WARNING("nonzero bytes after the disk header structure");
}
@@ -942,7 +947,8 @@
lbl = (ocfs_vol_label *)buf;
- if (check_outside_bounds(buf, sizeof(ocfs_vol_label)) == -1) {
+ if (ctxt.show_warnings &&
+ check_outside_bounds(buf, sizeof(ocfs_vol_label)) == -1) {
LOG_WARNING("nonzero bytes after the volume label structure");
}
More information about the Ocfs-tools-commits
mailing list