From: Piotr R. K. <pio...@ge...> - 2019-02-05 13:12:31
|
Hi Tom, We have changed humanize_number() name in MooseFS sources in order not to collide with NetBSD :) Best, Piotr Piotr Robert Konopelko | m: +48 601 476 440 | e: pio...@mo... <mailto:pio...@mo...> Business & Technical Support Manager MooseFS Client Support Team WWW <http://moosefs.com/> | GitHub <https://github.com/moosefs/moosefs> | Twitter <https://twitter.com/moosefs> | Facebook <https://www.facebook.com/moosefs> | LinkedIn <https://www.linkedin.com/company/moosefs> > On 20 Jan 2019, at 6:59 PM, Tom Ivar Helbekkmo via moosefs-users <moo...@li...> wrote: > > I run MooseFS on NetBSD, and while the new mfsmetadirinfo is a nice > addition, it doesn't compile cleanly for me out of the box. The reason > is that NetBSD, like the other BSDs, has a humanize_number() already, so > when you create your own function by that name, there's a collision. > > You haven't observed this on FreeBSD, because they want you to link with > libutil, and #include <libutil.h> in your source code, to get access to > this function. In NetBSD, it's in the standard C library, and stdlib.h. > > Our humanize_number() originated in NetBSD, but has been adopted by the > other BSDs, and is also available on Linux, where you link with libbsd, > and #include <bsd/stdlib.h>, to get access to it. It works exactly the > same way on all these systems. > > I'm appending the change I've made locally - if you'd like to do > something similar in the official distribution, to avoid maintaining > your own humanize_number() in the future, you might apply this, or > something like it, with the addition of #ifdef bits to add the right > #include directives for your supported operating systems. > > Alternatively, if you'd rather keep your own implementation, consider > this a polite request to change its name so it doesn't clash with the > existing humanize_number() function... ;) > > My local modification: > > diff --git a/mfsmetatools/mfsmetadirinfo.c b/mfsmetatools/mfsmetadirinfo.c > index 66cffe5..672e186 100644 > --- a/mfsmetatools/mfsmetadirinfo.c > +++ b/mfsmetatools/mfsmetadirinfo.c > @@ -14,68 +14,22 @@ > //static uint8_t humode=0; > //static uint8_t numbermode=0; > > +// For the humanized representation of numbers, decide how many > +// digits will be used before moving to the next scale factor. > +// The value 4 here means you'll get up to "9999 MiB" before it > +// changes to "10 GiB", while 3 jumps from "999 MiB" to "1 GiB". > +// The magic '3' in the calculation below is for a space, a > +// scaling letter, and a terminating 0 byte for the result. > +#define HUMAN_DIGITS 4 > +#define HUMAN_SUFFIX "iB" > +#define HUMAN_LENGTH (HUMAN_DIGITS+3+strlen(HUMAN_SUFFIX)) > + > enum { > STATUS_OK = 0, > STATUS_ENOENT = 1, > STATUS_ANY = 2 > }; > > -#define PHN_USESI 0x01 > -#define PHN_USEIEC 0x00 > -char* humanize_number(uint64_t number,uint8_t flags) { > - static char numbuf[6]; // [ "xxx" , "xx" , "x" , "x.x" ] + ["" , "X" , "Xi"] > - uint64_t divisor; > - uint16_t b; > - uint8_t i; > - uint8_t scale; > - > - if (flags & PHN_USESI) { > - divisor = 1000; > - } else { > - divisor = 1024; > - } > - if (number>(UINT64_MAX/100)) { > - number /= divisor; > - number *= 100; > - scale = 1; > - } else { > - number *= 100; > - scale = 0; > - } > - while (number>=99950) { > - number /= divisor; > - scale+=1; > - } > - i=0; > - if (number<995 && scale>0) { > - b = ((uint32_t)number + 5) / 10; > - numbuf[i++]=(b/10)+'0'; > - numbuf[i++]='.'; > - numbuf[i++]=(b%10)+'0'; > - } else { > - b = ((uint32_t)number + 50) / 100; > - if (b>=100) { > - numbuf[i++]=(b/100)+'0'; > - b%=100; > - } > - if (b>=10 || i>0) { > - numbuf[i++]=(b/10)+'0'; > - b%=10; > - } > - numbuf[i++]=b+'0'; > - } > - if (scale>0) { > - if (flags&PHN_USESI) { > - numbuf[i++]="-kMGTPE"[scale]; > - } else { > - numbuf[i++]="-KMGTPE"[scale]; > - numbuf[i++]='i'; > - } > - } > - numbuf[i++]='\0'; > - return numbuf; > -} > - > typedef struct _metasection { > off_t offset; > uint64_t length; > @@ -633,6 +587,7 @@ int calc_dirinfos(FILE *fd) { > > void print_result_plain(FILE *ofd) { > dirinfostate *dis; > + char numbuf[16]; > fprintf(ofd,"------------------------------\n"); > for (dis = dishead ; dis!=NULL ; dis=dis->next) { > fprintf(ofd,"path: %s\n",dis->path); > @@ -643,11 +598,16 @@ void print_result_plain(FILE *ofd) { > fprintf(ofd,"chunks: %"PRIu64"\n",liset_card(dis->chunk_liset)); > fprintf(ofd," keep chunks: %"PRIu64"\n",dis->s.kchunks); > fprintf(ofd," arch chunks: %"PRIu64"\n",dis->s.achunks); > - fprintf(ofd,"length: %"PRIu64" = %5sB\n",dis->s.length,humanize_number(dis->s.length,PHN_USEIEC)); > - fprintf(ofd,"size: %"PRIu64" = %5sB\n",dis->s.size,humanize_number(dis->s.size,PHN_USEIEC)); > - fprintf(ofd,"keep size: %"PRIu64" = %5sB\n",dis->s.keeprsize,humanize_number(dis->s.keeprsize,PHN_USEIEC)); > - fprintf(ofd,"arch size: %"PRIu64" = %5sB\n",dis->s.archrsize,humanize_number(dis->s.archrsize,PHN_USEIEC)); > - fprintf(ofd,"real size: %"PRIu64" = %5sB\n",dis->s.rsize,humanize_number(dis->s.rsize,PHN_USEIEC)); > + humanize_number(numbuf,HUMAN_LENGTH,dis->s.length,HUMAN_SUFFIX,HN_AUTOSCALE,0); > + fprintf(ofd,"length: %"PRIu64" = %s\n",dis->s.length,numbuf); > + humanize_number(numbuf,HUMAN_LENGTH,dis->s.size,HUMAN_SUFFIX,HN_AUTOSCALE,0); > + fprintf(ofd,"size: %"PRIu64" = %s\n",dis->s.size,numbuf); > + humanize_number(numbuf,HUMAN_LENGTH,dis->s.keeprsize,HUMAN_SUFFIX,HN_AUTOSCALE,0); > + fprintf(ofd,"keep size: %"PRIu64" = %s\n",dis->s.keeprsize,numbuf); > + humanize_number(numbuf,HUMAN_LENGTH,dis->s.archrsize,HUMAN_SUFFIX,HN_AUTOSCALE,0); > + fprintf(ofd,"arch size: %"PRIu64" = %s\n",dis->s.archrsize,numbuf); > + humanize_number(numbuf,HUMAN_LENGTH,dis->s.rsize,HUMAN_SUFFIX,HN_AUTOSCALE,0); > + fprintf(ofd,"real size: %"PRIu64" = %s\n",dis->s.rsize,numbuf); > } else { > fprintf(ofd,"path not found !!!\n"); > } > > -tih > -- > Most people who graduate with CS degrees don't understand the significance > of Lisp. Lisp is the most important idea in computer science. --Alan Kay > _________________________________________ > moosefs-users mailing list > moo...@li... > https://lists.sourceforge.net/lists/listinfo/moosefs-users |