* [PATCH v3, 07/16] xfsprogs: metadump: use pointers in generate_obfuscated_name()
@ 2011-02-18 21:21 Alex Elder
2011-02-24 1:47 ` Dave Chinner
0 siblings, 1 reply; 3+ messages in thread
From: Alex Elder @ 2011-02-18 21:21 UTC (permalink / raw)
To: xfs
Switch from using array references to using pointers to refer to the
pathname characters as they get generated. Also limit the scope of
a few automatic variables.
Signed-off-by: Alex Elder <aelder@sgi.com>
The only update since the last post version is the addition of an
ASSERT() in the loop generating the last 5 bytes.
---
db/metadump.c | 35 +++++++++++++++++++----------------
1 file changed, 19 insertions(+), 16 deletions(-)
Index: b/db/metadump.c
===================================================================
--- a/db/metadump.c
+++ b/db/metadump.c
@@ -437,11 +437,8 @@ generate_obfuscated_name(
{
xfs_dahash_t hash;
name_ent_t *p;
- int i;
int dup;
- xfs_dahash_t newhash;
uchar_t newname[NAME_MAX];
- uchar_t *newp = &newname[0];
/*
* Our obfuscation algorithm requires at least 5-character
@@ -472,7 +469,12 @@ generate_obfuscated_name(
hash = libxfs_da_hashname(name, namelen);
do {
- uchar_t high_bit;
+ int i;
+ xfs_dahash_t newhash = 0;
+ uchar_t *newp = &newname[0];
+ uchar_t *first;
+ uchar_t high_bit;
+ int shift;
dup = 0;
@@ -482,10 +484,10 @@ generate_obfuscated_name(
* characters. Accumulate its new hash value as we
* go.
*/
- newhash = 0;
for (i = 0; i < namelen - 5; i++) {
- newp[i] = random_filename_char();
- newhash = newp[i] ^ rol32(newhash, 7);
+ *newp = random_filename_char();
+ newhash = *newp ^ rol32(newhash, 7);
+ newp++;
}
/*
@@ -500,16 +502,17 @@ generate_obfuscated_name(
*/
newhash = rol32(newhash, 3) ^ hash;
+ first = newp;
high_bit = 0;
- for (i = 5; i > 0; i--) {
- int shift = (i - 1) * 7;
-
- newp[namelen - i] = ((newhash >> shift) & 0x7f) ^ high_bit;
- if (is_invalid_char(newp[namelen - i])) {
- newp[namelen - i] ^= 1;
+ for (shift = 28; shift >= 0; shift -= 7) {
+ *newp = (newhash >> shift & 0x7f) ^ high_bit;
+ if (is_invalid_char(*newp)) {
+ *newp ^= 1;
high_bit = 0x80;
} else
high_bit = 0;
+ ASSERT(!is_invalid_char(*newp));
+ newp++;
}
/*
@@ -522,15 +525,15 @@ generate_obfuscated_name(
* worry about it becoming invalid as a result.
*/
if (high_bit) {
- newp[namelen - 5] ^= 0x10;
- ASSERT(!is_invalid_char(newp[namelen - 5]));
+ *first ^= 0x10;
+ ASSERT(!is_invalid_char(*first));
}
ASSERT(libxfs_da_hashname(newname, namelen) == hash);
for (p = nametable[hash % NAME_TABLE_SIZE]; p; p = p->next) {
if (p->hash == hash && p->namelen == namelen &&
- memcmp(p->name, newname, namelen) == 0){
+ !memcmp(p->name, newname, namelen)) {
dup = 1;
break;
}
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v3, 07/16] xfsprogs: metadump: use pointers in generate_obfuscated_name()
2011-02-18 21:21 [PATCH v3, 07/16] xfsprogs: metadump: use pointers in generate_obfuscated_name() Alex Elder
@ 2011-02-24 1:47 ` Dave Chinner
2011-02-25 18:13 ` [PATCH v4, " Alex Elder
0 siblings, 1 reply; 3+ messages in thread
From: Dave Chinner @ 2011-02-24 1:47 UTC (permalink / raw)
To: Alex Elder; +Cc: xfs
On Fri, Feb 18, 2011 at 03:21:01PM -0600, Alex Elder wrote:
> Switch from using array references to using pointers to refer to the
> pathname characters as they get generated. Also limit the scope of
> a few automatic variables.
>
> Signed-off-by: Alex Elder <aelder@sgi.com>
>
> The only update since the last post version is the addition of an
> ASSERT() in the loop generating the last 5 bytes.
One small comment below, otherwise:
Reviewed-by: Dave Chinner <dchinner@redhat.com>
> @@ -500,16 +502,17 @@ generate_obfuscated_name(
> */
> newhash = rol32(newhash, 3) ^ hash;
>
> + first = newp;
> high_bit = 0;
> - for (i = 5; i > 0; i--) {
> - int shift = (i - 1) * 7;
> -
> - newp[namelen - i] = ((newhash >> shift) & 0x7f) ^ high_bit;
> - if (is_invalid_char(newp[namelen - i])) {
> - newp[namelen - i] ^= 1;
> + for (shift = 28; shift >= 0; shift -= 7) {
> + *newp = (newhash >> shift & 0x7f) ^ high_bit;
I'd prefer not to have to refer to my C bible to remind myself what
the precedence of ">>" vs "&" is, so perhaps leaving the second set
of () in this statement would be a good idea.
Cheers,
Dave.
--
Dave Chinner
david@fromorbit.com
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH v4, 07/16] xfsprogs: metadump: use pointers in generate_obfuscated_name()
2011-02-24 1:47 ` Dave Chinner
@ 2011-02-25 18:13 ` Alex Elder
0 siblings, 0 replies; 3+ messages in thread
From: Alex Elder @ 2011-02-25 18:13 UTC (permalink / raw)
To: Dave Chinner; +Cc: xfs
. . .
> One small comment below, otherwise:
>
> Reviewed-by: Dave Chinner <dchinner@redhat.com>
>
> > @@ -500,16 +502,17 @@ generate_obfuscated_name(
> > */
> > newhash = rol32(newhash, 3) ^ hash;
> >
> > + first = newp;
> > high_bit = 0;
> > - for (i = 5; i > 0; i--) {
> > - int shift = (i - 1) * 7;
> > -
> > - newp[namelen - i] = ((newhash >> shift) & 0x7f) ^ high_bit;
> > - if (is_invalid_char(newp[namelen - i])) {
> > - newp[namelen - i] ^= 1;
> > + for (shift = 28; shift >= 0; shift -= 7) {
> > + *newp = (newhash >> shift & 0x7f) ^ high_bit;
>
> I'd prefer not to have to refer to my C bible to remind myself what
> the precedence of ">>" vs "&" is, so perhaps leaving the second set
> of () in this statement would be a good idea.
Done.
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-02-25 18:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-18 21:21 [PATCH v3, 07/16] xfsprogs: metadump: use pointers in generate_obfuscated_name() Alex Elder
2011-02-24 1:47 ` Dave Chinner
2011-02-25 18:13 ` [PATCH v4, " Alex Elder
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox