void grab_and_apply_magick(const char *file, const char *output, int socketfd, int raw) { uint32_t len = strlen(output); char *pixels = ipc_single_command(socketfd, IPC_SWAY_GET_PIXELS, output, &len); uint32_t *u32pixels = (uint32_t *)(pixels + 1); uint32_t width = u32pixels[0]; uint32_t height = u32pixels[1]; len -= 9; pixels += 9; if (width == 0 || height == 0) { sway_abort("Unknown output %s.", output); } if (raw) { fwrite(pixels, 1, len, stdout); fflush(stdout); free(pixels - 9); return; } const char *fmt = "convert -depth 8 -size %dx%d+0 rgba:- -flip %s"; char *cmd = malloc(strlen(fmt) - 6 /*args*/ + numlen(width) + numlen(height) + strlen(file) + 1); sprintf(cmd, fmt, width, height, file); FILE *f = popen(cmd, "w"); fwrite(pixels, 1, len, f); fflush(f); fclose(f); free(pixels - 9); free(cmd); }
int main(){ //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); int n = 1111111111, i, count=0; int a[numlen(n)]; getArrayValues(a, n); for(i=0; i<numlen(n)-1; i++) if(dton(a[i], a[i+1]) < 27) count++; //printf("%d ", dton(a[i], a[i+1])); printf("%d\n", count); return 0; }
void solve() { bool neg = false; if (sum < 0) { neg = true; sum = -sum; } int g = gcd(sum, n); int p = sum / g; int q = n / g; if (q == 1) { if (neg) printf("- "); printf("%d\n", p); return; } int a, b, c; if (p > q) { a = p/q; b = p%q; c = q; } else { a = 0; b = p; c = q; } int la = numlen(a); int lb = numlen(b); int lc = numlen(c); int ib = (neg ? 2 : 0) + la; int ic = (neg ? 2 : 0) + la; if (lc > lb) ib += lc - lb; // first line pchar(ib, ' '); printf("%d\n", b); // second line if (neg) printf("- "); if (a != 0) printf("%d", a); pchar(lc, '-'); putchar('\n'); // third line pchar(ic, ' '); printf("%d\n", c); }
/** * Simulates all Fullness Sensors * * Formula: */ static void SimulateFullness(bool set) { if(set) { int snr = singlerandom(countTrie(FullnessTable)); char name[9+numlen((unsigned)snr)]; snprintf(name, sizeof(char)*(9+numlen((unsigned)snr)), "%s%d", "Fullness", snr); Sensor*const sensor = (findinTrie(FullnessTable,name)); bSensor*const bsensor = (bSensor*)sensor; bool*p=malloc(sizeof*p); if(!p) { Log(LOGT_SERVER, LOGL_SERIOUS_ERROR, "Out of memory!"); return; } // Set current value in history queue *p = bsensor->value; sensor->delta = AutoQadd(sensor->delta, p); // Get new value and set as current value bsensor->value = true; PushS(sensor); } else { Sensor*const sensor = checkFullnessValues(FullnessTable); if(sensor) { bSensor*const bsensor = (bSensor*)sensor; bool*p=malloc(sizeof*p); if(!p) { Log(LOGT_SERVER, LOGL_SERIOUS_ERROR, "Out of memory!"); return; } // Set current value in history queue *p = bsensor->value; sensor->delta = AutoQadd(sensor->delta, p); // Get new value and set as current value bsensor->value = false; PushS(sensor); } } }
void getArrayValues(int * p, int n){ int i = numlen(n)-1; while(n){ p[i--] = n%10; n/=10; } }
char *ft_itoa_base(int n, int base) { char *str; int len; long nb; len = numlen(n, base); nb = (long)n; str = ft_strnew(len); if (!str) return (NULL); str[len--] = '\0'; if (nb < 0) { str[0] = '-'; nb *= -1; } str[len--] = (nb % base) + '0'; while (nb >= base) { nb /= base; str[len--] = (nb % base) + '0'; } return (str); }
unsigned long long int * num_to_digits(unsigned long long int fnum){ unsigned long long int a[1000], i=numlen(fnum)-1; while(fnum){ a[i--] = fnum%10; fnum/=10; } return a; }
ssize_t http_make_200_response_header(ssize_t content_length, char *output) { #define RESP_200_CONLEN "HTTP/1.1 200 OK\r\nContent-Length: " if(output) { return sprintf(output, RESP_200_CONLEN "%ld\r\n", content_length); } else { return sizeof(RESP_200_CONLEN "\r\n") - 1 + numlen(content_length); } }
/** * Generates all Integer Sensors */ static void geniSensors( char const*const type, const int amount, int const start, int const lbound, int const ubound, char const*const lalarm, char const*const ualarm, bool const lboundcross, bool const uboundcross) { // generate the requested amount int i; for(i=0;i<amount;i++) { // generate a generic name const unsigned int namelen=1+strlen(type)+numlen((unsigned)i); char name[namelen]; snprintf(name, sizeof(char)*namelen, "%s%d", type, i); // valid? if(namelen>SENSOR_HNAMELEN) { Log(LOGT_SERVER, LOGL_ERROR, "Name %s too long! (skipping rest of this batch)", name); break; } // make one { Sensor*const s=(Sensor*)makeiSensor(name, type, start, lbound, ubound, lalarm, ualarm, lboundcross, uboundcross); if(!s) { Log(LOGT_SERVER, LOGL_ERROR, "Out of memory!"); break; } // register them with the databases if(registerSensor(s)) { Log(LOGT_SERVER, LOGL_ERROR, "Cannot register %s", s->name); free(s); continue; } // set in log that all sensors of the group are generated if(i==(amount-1)) { Log(LOGT_SERVER, LOGL_DEBUG, "Generated %d %s %s %s", (i+1), s->type==binarysensor?"binary":"integer", s->unit, "Sensors"); } } } }
/* * Calculate the proper extent table format based on first * set of extents */ static void calc_print_format( struct fiemap *fiemap, __u64 blocksize, int *foff_w, int *boff_w, int *tot_w, int *flg_w) { int i; char lbuf[32]; char bbuf[32]; __u64 logical; __u64 block; __u64 len; struct fiemap_extent *extent; for (i = 0; i < fiemap->fm_mapped_extents; i++) { extent = &fiemap->fm_extents[i]; logical = extent->fe_logical / blocksize; len = extent->fe_length / blocksize; block = extent->fe_physical / blocksize; snprintf(lbuf, sizeof(lbuf), "[%llu..%llu]", logical, logical + len - 1); snprintf(bbuf, sizeof(bbuf), "%llu..%llu", block, block + len - 1); *foff_w = max(*foff_w, strlen(lbuf)); *boff_w = max(*boff_w, strlen(bbuf)); *tot_w = max(*tot_w, numlen(len, 10)); *flg_w = max(*flg_w, numlen(extent->fe_flags, 16)); if (extent->fe_flags & FIEMAP_EXTENT_LAST) break; } }
struct cmd_results *cmd_bar(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "bar", EXPECTED_AT_LEAST, 1))) { return error; } if (config->reading && strcmp("{", argv[0]) != 0) { return cmd_results_new(CMD_INVALID, "bar", "Expected '{' at start of bar config definition."); } if (!config->reading) { if (argc > 1) { if (strcasecmp("mode", argv[0]) == 0) { return bar_cmd_mode(argc-1, argv + 1); } if (strcasecmp("hidden_state", argv[0]) == 0) { return bar_cmd_hidden_state(argc-1, argv + 1); } } return cmd_results_new(CMD_FAILURE, "bar", "Can only be used in config file."); } // Create new bar with default values struct bar_config *bar = default_bar_config(); // set bar id int i; for (i = 0; i < config->bars->length; ++i) { if (bar == config->bars->items[i]) { const int len = 5 + numlen(i); // "bar-" + i + \0 bar->id = malloc(len * sizeof(char)); snprintf(bar->id, len, "bar-%d", i); break; } } // Set current bar config->current_bar = bar; sway_log(L_DEBUG, "Configuring bar %s", bar->id); return cmd_results_new(CMD_BLOCK_BAR, NULL, NULL); }
u8 showui(mutable_string out, ulen max, u64 number) { if (max < 2) { // one for null terminator and one for output character panic_static("showint buffer is too short"); } else if (number == 0) { *out++ = '0'; *out = '\0'; return 1; } // TODO: optimize this so that we don't have to do the same divisions twice u8 needed = numlen(number); if (max < needed + 1) { panic_static("showint buffer is too short"); } string orig = out; out += needed; *out = '\0'; while (number > 0) { *--out = (number % 10) + '0'; number /= 10; } assert(out == orig); return needed; }
void grab_and_apply_movie_magic(const char *file, const char *output, int socketfd, int raw, int framerate) { if (raw) { sway_log(L_ERROR, "Raw capture data is not yet supported. Proceeding with ffmpeg normally."); } uint32_t len = strlen(output); char *pixels = ipc_single_command(socketfd, IPC_SWAY_GET_PIXELS, output, &len); uint32_t *u32pixels = (uint32_t *)(pixels + 1); uint32_t width = u32pixels[0]; uint32_t height = u32pixels[1]; pixels += 9; if (width == 0 || height == 0) { sway_abort("Unknown output %s.", output); } const char *fmt = "ffmpeg -f rawvideo -framerate %d " "-video_size %dx%d -pixel_format argb " "-i pipe:0 -r %d -vf vflip %s"; char *cmd = malloc(strlen(fmt) - 8 /*args*/ + numlen(width) + numlen(height) + numlen(framerate) * 2 + strlen(file) + 1); sprintf(cmd, fmt, framerate, width, height, framerate, file); long ns = (long)(1000000000 * (1.0 / framerate)); struct timespec start, finish, ts; ts.tv_sec = 0; FILE *f = popen(cmd, "w"); fwrite(pixels, 1, len, f); free(pixels - 9); int sleep = 0; while (sleep != -1) { clock_gettime(CLOCK_MONOTONIC, &start); len = strlen(output); pixels = ipc_single_command(socketfd, IPC_SWAY_GET_PIXELS, output, &len); pixels += 9; len -= 9; fwrite(pixels, 1, len, f); free(pixels - 9); clock_gettime(CLOCK_MONOTONIC, &finish); ts.tv_nsec = ns; double fts = (double)finish.tv_sec + 1.0e-9*finish.tv_nsec; double sts = (double)start.tv_sec + 1.0e-9*start.tv_nsec; long diff = (fts - sts) * 1000000000; ts.tv_nsec = ns - diff; if (ts.tv_nsec < 0) { ts.tv_nsec = 0; } sleep = nanosleep(&ts, NULL); } fflush(f); fclose(f); free(cmd); }
/** * Load all Sensors and read their * preferences from the ini file */ int LoadSensors(void) { //load the iniparser on the sensor path dictionary*ini=iniparser_load(sensorinipath()); if(!ini) return EXIT_FAILURE; // just to be sure //SetupSensors(); if(!iniparser_find_entry(ini, "sensor")) { Log(LOGT_SERVER, LOGL_ERROR, "File %s does not contain sensor config section", sensorinipath()); goto exit_failure; } if(!iniparser_find_entry(ini, "sensor:typecount")) { Log(LOGT_SERVER, LOGL_ERROR, "No sensor typecount present"); goto exit_failure; } { int typecount = iniparser_getint(ini, "sensor:typecount", 0); interval = iniparser_getint(ini, "sensor:interval", 1); // user requested to turn off sensors. if(typecount<1)goto exit_success; for(;typecount;typecount--) { const unsigned int idstringlen=12+numlen((unsigned)typecount); const unsigned int namelen=idstringlen+4; const unsigned int amountlen=idstringlen+5; const unsigned int typelen=idstringlen+4; char idstring[idstringlen]; char name[namelen]; char amount[amountlen]; char typeq[typelen]; sensortype stype=integersensor; snprintf(idstring, sizeof(char)*idstringlen, "sensor:type%d", typecount); snprintf(name, sizeof(char)*namelen, "%s%s", idstring, "name"); snprintf(amount, sizeof(char)*amountlen, "%s%s", idstring, "count"); if(!iniparser_find_entry(ini, name)||!iniparser_find_entry(ini, amount)) { Log(LOGT_SERVER, LOGL_WARNING, "Skipping incomplete %s definition", idstring); continue; } snprintf(typeq, sizeof(char)*typelen, "%s%s", idstring, "type"); { char const*const typea = iniparser_getstring(ini, typeq, "integer"); if(!strcmp(typea, "binary")) { stype=binarysensor; } else if(!strcmp(typea, "integer")){;/*fallthrough*/;} else { Log(LOGT_SERVER, LOGL_WARNING, "Unrecognised type %s, falling back on integer"); } if(stype==binarysensor) { const unsigned int alarmlen=idstringlen+5; char alarmq[alarmlen]; snprintf(alarmq, sizeof(char)*alarmlen, "%s%s", idstring, "alarm"); genbSensors( iniparser_getstring(ini, name, "genericb"), iniparser_getint(ini, amount, 0), iniparser_getstring(ini, alarmq, "Alarm!")); } else if(stype==integersensor) { const unsigned int startlen=idstringlen+5; const unsigned int alarmlen=idstringlen+6; const unsigned int boundlen=idstringlen+6; const unsigned int boundcrosslen=idstringlen+11; signed int min, max; char startq[startlen]; char lalarmq[alarmlen]; char ualarmq[alarmlen]; char lboundq[boundlen]; char uboundq[boundlen]; char lboundcrossq[boundcrosslen]; char uboundcrossq[boundcrosslen]; snprintf(startq, sizeof(char)*startlen, "%s%s", idstring, "start"); snprintf(lalarmq, sizeof(char)*alarmlen, "%s%s", idstring, "lalarm"); snprintf(ualarmq, sizeof(char)*alarmlen, "%s%s", idstring, "ualarm"); snprintf(lboundq, sizeof(char)*boundlen, "%s%s", idstring, "lbound"); snprintf(uboundq, sizeof(char)*boundlen, "%s%s", idstring, "ubound"); snprintf(lboundcrossq, sizeof(char)*boundcrosslen, "%s%s", idstring, "lboundcross"); snprintf(uboundcrossq, sizeof(char)*boundcrosslen, "%s%s", idstring, "uboundcross"); min = iniparser_getint(ini, lboundq, INT_MIN); max = iniparser_getint(ini, uboundq, INT_MAX); geniSensors( iniparser_getstring(ini, name, "generici"), iniparser_getint(ini, amount, 0), iniparser_getint(ini, startq, ((min+max)/2)), min, max, iniparser_getstring(ini, lalarmq, "lower bound Alarm!"), iniparser_getstring(ini, ualarmq, "upper bound Alarm!"), iniparser_getboolean(ini, lboundcrossq, true), iniparser_getboolean(ini, uboundcrossq, true)); } else { Log(LOGT_SERVER, LOGL_ERROR, "Unknown sensor type %d from %s", stype, typea); } } } } exit_success: iniparser_freedict(ini); return EXIT_SUCCESS; exit_failure: iniparser_freedict(ini); return EXIT_FAILURE; }
int main(){ //variable declaration unsigned long long int a, b, * adigits, * bdigits, temp=0, i, j, k, l, x, z, n, alength, blength, sum[100][1000], result[1000], rtp, * r2; scanf("%lld %lld", &a, &b); unsigned long long int ttemp; //length and numtoDigits alength = numlen(a); blength = numlen(b); adigits = num_to_digits(a); bdigits = num_to_digits(b); printf("alen = %d\nblen = %d\n", alength, blength); for(i=0; i<alength; i++) printf("%d ", adigits[i]);printf("\n"); for(i=0; i<alength; i++) printf("%d ", bdigits[i]);printf("\n"); //middle k=0, n = alength*blength; for(i=blength-1; i>=0; i--, k++){ l=0; for(z=0; z<k; z++) sum[k][l++]=0; rtp=0; for(j=alength-1; j>=0; j--){ temp = bdigits[i] * adigits[j] + rtp; if(!j && (temp > 9)){ x=0; while(temp){ sum[k][l++] = temp%10; temp/=10; } break; } if(j && (temp<10)){ sum[k][l++] = temp; rtp=0; }else{ r2 = num_to_digits(temp); sum[k][l++] = r2[1]; rtp = r2[0]; } } for(;z<n; z++) sum[k][l++]=0; for(z=0; z<n/2; z++){ temp = sum[k][z]; sum[k][z] = sum[k][n-1-z]; sum[k][n-1-z] = temp; } } z=n-1, rtp=0; for(i=n-1; i>=0; i--){ temp=0; for(j=0; j<blength; j++){ temp+=sum[j][i]+rtp; rtp=0; } if(!i && (temp > 9)){ x=0; while(temp){ result[z--] = temp%10; temp/=10; } break; } if((temp<10)){ result[z--] = temp; rtp=0; }else{ r2 = num_to_digits(temp); result[z--] = r2[1]; rtp = r2[0]; } } i=0; while(!result[i++]) continue; i--, ttemp=0; while(i<n){ printf("%d", result[i]); ttemp=ttemp*10+result[i++]; } printf("\n\n"); printf("%lld\n%d", ttemp, numlen(ttemp)); return 0; }
int bmap_f( int argc, char **argv) { struct fsxattr fsx; struct getbmapx *map; struct xfs_fsop_geom fsgeo; int map_size; int loop = 0; int flg = 0; int aflag = 0; int lflag = 0; int nflag = 0; int pflag = 0; int vflag = 0; int is_rt = 0; int bmv_iflags = 0; /* flags for XFS_IOC_GETBMAPX */ int i = 0; int c; int egcnt; while ((c = getopt(argc, argv, "adln:pv")) != EOF) { switch (c) { case 'a': /* Attribute fork. */ bmv_iflags |= BMV_IF_ATTRFORK; aflag = 1; break; case 'l': /* list number of blocks with each extent */ lflag = 1; break; case 'n': /* number of extents specified */ nflag = atoi(optarg); break; case 'd': /* do not recall possibly offline DMAPI files */ bmv_iflags |= BMV_IF_NO_DMAPI_READ; break; case 'p': /* report unwritten preallocated blocks */ pflag = 1; bmv_iflags |= BMV_IF_PREALLOC; break; case 'v': /* Verbose output */ vflag++; break; default: return command_usage(&bmap_cmd); } } if (aflag) bmv_iflags &= ~(BMV_IF_PREALLOC|BMV_IF_NO_DMAPI_READ); if (vflag) { c = xfsctl(file->name, file->fd, XFS_IOC_FSGEOMETRY_V1, &fsgeo); if (c < 0) { fprintf(stderr, _("%s: can't get geometry [\"%s\"]: %s\n"), progname, file->name, strerror(errno)); exitcode = 1; return 0; } c = xfsctl(file->name, file->fd, XFS_IOC_FSGETXATTR, &fsx); if (c < 0) { fprintf(stderr, _("%s: cannot read attrs on \"%s\": %s\n"), progname, file->name, strerror(errno)); exitcode = 1; return 0; } if (fsx.fsx_xflags == XFS_XFLAG_REALTIME) { /* * ag info not applicable to rt, continue * without ag output. */ is_rt = 1; } } map_size = nflag ? nflag+2 : 32; /* initial guess - 32 */ map = malloc(map_size*sizeof(*map)); if (map == NULL) { fprintf(stderr, _("%s: malloc of %d bytes failed.\n"), progname, (int)(map_size * sizeof(*map))); exitcode = 1; return 0; } /* Try the xfsctl(XFS_IOC_GETBMAPX) for the number of extents specified * by nflag, or the initial guess number of extents (32). * * If there are more extents than we guessed, use xfsctl * (XFS_IOC_FSGETXATTR[A]) to get the extent count, realloc some more * space based on this count, and try again. * * If the initial FGETBMAPX attempt returns EINVAL, this may mean * that we tried the FGETBMAPX on a zero length file. If we get * EINVAL, check the length with fstat() and return "no extents" * if the length == 0. * * Why not do the xfsctl(XFS_IOC_FSGETXATTR[A]) first? Two reasons: * (1) The extent count may be wrong for a file with delayed * allocation blocks. The XFS_IOC_GETBMAPX forces the real * allocation and fixes up the extent count. * (2) For XFS_IOC_GETBMAP[X] on a DMAPI file that has been moved * offline by a DMAPI application (e.g., DMF) the * XFS_IOC_FSGETXATTR only reflects the extents actually online. * Doing XFS_IOC_GETBMAPX call first forces that data blocks online * and then everything proceeds normally (see PV #545725). * * If you don't want this behavior on a DMAPI offline file, * try the "-d" option which sets the BMV_IF_NO_DMAPI_READ * iflag for XFS_IOC_GETBMAPX. */ do { /* loop a miximum of two times */ memset(map, 0, sizeof(*map)); /* zero header */ map->bmv_length = -1; map->bmv_count = map_size; map->bmv_iflags = bmv_iflags; i = xfsctl(file->name, file->fd, XFS_IOC_GETBMAPX, map); if (i < 0) { if ( errno == EINVAL && !aflag && filesize() == 0) { break; } else { fprintf(stderr, _("%s: xfsctl(XFS_IOC_GETBMAPX)" " iflags=0x%x [\"%s\"]: %s\n"), progname, map->bmv_iflags, file->name, strerror(errno)); free(map); exitcode = 1; return 0; } } if (nflag) break; if (map->bmv_entries < map->bmv_count-1) break; /* Get number of extents from xfsctl XFS_IOC_FSGETXATTR[A] * syscall. */ i = xfsctl(file->name, file->fd, aflag ? XFS_IOC_FSGETXATTRA : XFS_IOC_FSGETXATTR, &fsx); if (i < 0) { fprintf(stderr, "%s: xfsctl(XFS_IOC_FSGETXATTR%s) " "[\"%s\"]: %s\n", progname, aflag ? "A" : "", file->name, strerror(errno)); free(map); exitcode = 1; return 0; } if (2 * fsx.fsx_nextents > map_size) { map_size = 2 * fsx.fsx_nextents + 1; map = realloc(map, map_size*sizeof(*map)); if (map == NULL) { fprintf(stderr, _("%s: cannot realloc %d bytes\n"), progname, (int)(map_size*sizeof(*map))); exitcode = 1; return 0; } } } while (++loop < 2); if (!nflag) { if (map->bmv_entries <= 0) { printf(_("%s: no extents\n"), file->name); free(map); return 0; } } egcnt = nflag ? min(nflag, map->bmv_entries) : map->bmv_entries; printf("%s:\n", file->name); if (!vflag) { for (i = 0; i < egcnt; i++) { printf("\t%d: [%lld..%lld]: ", i, (long long) map[i + 1].bmv_offset, (long long)(map[i + 1].bmv_offset + map[i + 1].bmv_length - 1LL)); if (map[i + 1].bmv_block == -1) printf(_("hole")); else { printf("%lld..%lld", (long long) map[i + 1].bmv_block, (long long)(map[i + 1].bmv_block + map[i + 1].bmv_length - 1LL)); } if (lflag) printf(_(" %lld blocks\n"), (long long)map[i+1].bmv_length); else printf("\n"); } } else { /* * Verbose mode displays: * extent: [startoffset..endoffset]: startblock..endblock \ * ag# (agoffset..agendoffset) totalbbs */ #define MINRANGE_WIDTH 16 #define MINAG_WIDTH 2 #define MINTOT_WIDTH 5 #define NFLG 5 /* count of flags */ #define FLG_NULL 000000 /* Null flag */ #define FLG_PRE 010000 /* Unwritten extent */ #define FLG_BSU 001000 /* Not on begin of stripe unit */ #define FLG_ESU 000100 /* Not on end of stripe unit */ #define FLG_BSW 000010 /* Not on begin of stripe width */ #define FLG_ESW 000001 /* Not on end of stripe width */ int agno; off64_t agoff, bbperag; int foff_w, boff_w, aoff_w, tot_w, agno_w; char rbuf[32], bbuf[32], abuf[32]; int sunit, swidth; foff_w = boff_w = aoff_w = MINRANGE_WIDTH; tot_w = MINTOT_WIDTH; if (is_rt) sunit = swidth = bbperag = 0; else { bbperag = (off64_t)fsgeo.agblocks * (off64_t)fsgeo.blocksize / BBSIZE; sunit = (fsgeo.sunit * fsgeo.blocksize) / BBSIZE; swidth = (fsgeo.swidth * fsgeo.blocksize) / BBSIZE; } flg = sunit | pflag; /* * Go through the extents and figure out the width * needed for all columns. */ for (i = 0; i < egcnt; i++) { snprintf(rbuf, sizeof(rbuf), "[%lld..%lld]:", (long long) map[i + 1].bmv_offset, (long long)(map[i + 1].bmv_offset + map[i + 1].bmv_length - 1LL)); if (map[i + 1].bmv_oflags & BMV_OF_PREALLOC) flg = 1; if (map[i + 1].bmv_block == -1) { foff_w = max(foff_w, strlen(rbuf)); tot_w = max(tot_w, numlen(map[i+1].bmv_length)); } else { snprintf(bbuf, sizeof(bbuf), "%lld..%lld", (long long) map[i + 1].bmv_block, (long long)(map[i + 1].bmv_block + map[i + 1].bmv_length - 1LL)); boff_w = max(boff_w, strlen(bbuf)); if (!is_rt) { agno = map[i + 1].bmv_block / bbperag; agoff = map[i + 1].bmv_block - (agno * bbperag); snprintf(abuf, sizeof(abuf), "(%lld..%lld)", (long long)agoff, (long long)(agoff + map[i + 1].bmv_length - 1LL)); aoff_w = max(aoff_w, strlen(abuf)); } else aoff_w = 0; foff_w = max(foff_w, strlen(rbuf)); tot_w = max(tot_w, numlen(map[i+1].bmv_length)); } } agno_w = is_rt ? 0 : max(MINAG_WIDTH, numlen(fsgeo.agcount)); printf("%4s: %-*s %-*s %*s %-*s %*s%s\n", _("EXT"), foff_w, _("FILE-OFFSET"), boff_w, is_rt ? _("RT-BLOCK-RANGE") : _("BLOCK-RANGE"), agno_w, is_rt ? "" : _("AG"), aoff_w, is_rt ? "" : _("AG-OFFSET"), tot_w, _("TOTAL"), flg ? _(" FLAGS") : ""); for (i = 0; i < egcnt; i++) { flg = FLG_NULL; if (map[i + 1].bmv_oflags & BMV_OF_PREALLOC) { flg |= FLG_PRE; } /* * If striping enabled, determine if extent starts/ends * on a stripe unit boundary. */ if (sunit) { if (map[i + 1].bmv_block % sunit != 0) { flg |= FLG_BSU; } if (((map[i + 1].bmv_block + map[i + 1].bmv_length ) % sunit ) != 0) { flg |= FLG_ESU; } if (map[i + 1].bmv_block % swidth != 0) { flg |= FLG_BSW; } if (((map[i + 1].bmv_block + map[i + 1].bmv_length ) % swidth ) != 0) { flg |= FLG_ESW; } } snprintf(rbuf, sizeof(rbuf), "[%lld..%lld]:", (long long) map[i + 1].bmv_offset, (long long)(map[i + 1].bmv_offset + map[i + 1].bmv_length - 1LL)); if (map[i + 1].bmv_block == -1) { printf("%4d: %-*s %-*s %*s %-*s %*lld\n", i, foff_w, rbuf, boff_w, _("hole"), agno_w, "", aoff_w, "", tot_w, (long long)map[i+1].bmv_length); } else { snprintf(bbuf, sizeof(bbuf), "%lld..%lld", (long long) map[i + 1].bmv_block, (long long)(map[i + 1].bmv_block + map[i + 1].bmv_length - 1LL)); printf("%4d: %-*s %-*s", i, foff_w, rbuf, boff_w, bbuf); if (!is_rt) { agno = map[i + 1].bmv_block / bbperag; agoff = map[i + 1].bmv_block - (agno * bbperag); snprintf(abuf, sizeof(abuf), "(%lld..%lld)", (long long)agoff, (long long)(agoff + map[i + 1].bmv_length - 1LL)); printf(" %*d %-*s", agno_w, agno, aoff_w, abuf); } else printf(" "); printf(" %*lld", tot_w, (long long)map[i+1].bmv_length); if (flg == FLG_NULL && !pflag) { printf("\n"); } else { printf(" %-*.*o\n", NFLG, NFLG, flg); } } } if ((flg || pflag) && vflag > 1) { printf(_(" FLAG Values:\n")); printf(_(" %*.*o Unwritten preallocated extent\n"), NFLG+1, NFLG+1, FLG_PRE); printf(_(" %*.*o Doesn't begin on stripe unit\n"), NFLG+1, NFLG+1, FLG_BSU); printf(_(" %*.*o Doesn't end on stripe unit\n"), NFLG+1, NFLG+1, FLG_ESU); printf(_(" %*.*o Doesn't begin on stripe width\n"), NFLG+1, NFLG+1, FLG_BSW); printf(_(" %*.*o Doesn't end on stripe width\n"), NFLG+1, NFLG+1, FLG_ESW); } } free(map); return 0; }
static uint32_t enclen(uint32_t outlen, uint32_t saltlen, uint32_t t_cost, uint32_t m_cost, uint32_t lanes) { return strlen("$argon2x$m=,t=,p=$$") + numlen(t_cost) + numlen(m_cost) + numlen(lanes) + b64len(saltlen) + b64len(outlen); }