/* * Check and potentially fix certain fields in the super block. */ static void fixup_superblock(void) { /* * Kernel looks for FS_OPTTIME, and assumes that if that's not * what's there, it must be FS_OPTSPACE, so not fixing does not * require setting iscorrupt. */ if (sblock.fs_optim != FS_OPTTIME && sblock.fs_optim != FS_OPTSPACE) { pfatal("UNDEFINED OPTIMIZATION IN SUPERBLOCK"); if (reply("SET TO DEFAULT") == 1) { sblock.fs_optim = FS_OPTTIME; sbdirty(); } } if ((sblock.fs_minfree < 0 || sblock.fs_minfree > 99)) { pfatal("IMPOSSIBLE MINFREE=%d IN SUPERBLOCK", sblock.fs_minfree); if (reply("SET TO DEFAULT") == 1) { sblock.fs_minfree = 10; sbdirty(); } else if (sblock.fs_minfree < 0) { /* * Kernel uses minfree without verification, * and a negative value would do bad things. */ iscorrupt = 1; } } }
/* Simulate a "/usr/bin/find . -print" */ void find(char *dirname) { DIR *fd; struct dirent *d; if ((fd = opendir(dirname)) == NULL) pfatal("opendir"); while ((d = readdir(fd))) { char fullname[MAXPATHLEN]; struct stat statbuf; if (strcmp(".", d->d_name) == 0) continue; if (strcmp("..", d->d_name) == 0) continue; snprintf(fullname, MAXPATHLEN-1, "%s/%s", dirname, d->d_name); if (lstat(fullname, &statbuf) != 0) pfatal("lstat"); printf(" %s\n", fullname); if (S_ISDIR(statbuf.st_mode)) find(fullname); } closedir(fd); }
static array_t array_read (const char *filename) { FILE *fd; array_t a; int size; int i, s; fd = fopen (filename, "r"); if (!fd) pfatal ("Lecture tableau, ouverture du fichier"); s = fscanf (fd, "%d\n", &size); if (s !=1) pfatal ("Lecture tableau, taille du tableau"); a = array_alloc (size); for (i=0 ; i<a.size ; i++) { s = fscanf (fd, "%e\n", a.val+i); if (s != 1) pfatal ("Lecture tableau, manque de valeur"); } s = fclose (fd); if (s) pfatal ("Lecture tableau, fermeture fichier"); return a; }
/* * Calculate a prototype superblock based on information in the disk label. * When done the cgsblock macro can be calculated and the fs_ncg field * can be used. Do NOT attempt to use other macros without verifying that * their needed information is available! */ static int calcsb(char *dev, int devfd, struct fs *fs) { struct disklabel *lp; struct partition *pp; char *cp; int i, nspf; cp = strchr(dev, '\0') - 1; if (cp == (char *)-1 || ((*cp < 'a' || *cp > 'h') && !isdigit(*cp))) { pfatal("%s: CANNOT FIGURE OUT FILE SYSTEM PARTITION\n", dev); return (0); } lp = getdisklabel(dev, devfd); if (isdigit(*cp)) pp = &lp->d_partitions[0]; else pp = &lp->d_partitions[*cp - 'a']; if (pp->p_fstype != FS_BSDFFS) { pfatal("%s: NOT LABELED AS A BSD FILE SYSTEM (%s)\n", dev, pp->p_fstype < FSMAXTYPES ? fstypenames[pp->p_fstype] : "unknown"); return (0); } if (pp->p_fsize == 0 || pp->p_frag == 0 || pp->p_cpg == 0 || pp->p_size == 0) { pfatal("%s: %s: type %s fsize %d, frag %d, cpg %d, size %d\n", dev, "INCOMPLETE LABEL", fstypenames[pp->p_fstype], pp->p_fsize, pp->p_frag, pp->p_cpg, pp->p_size); return (0); } memset(fs, 0, sizeof(struct fs)); fs->fs_fsize = pp->p_fsize; fs->fs_frag = pp->p_frag; fs->fs_size = pp->p_size; fs->fs_sblkno = roundup( howmany(lp->d_bbsize + lp->d_sbsize, fs->fs_fsize), fs->fs_frag); nspf = fs->fs_fsize / lp->d_secsize; for (fs->fs_fsbtodb = 0, i = nspf; i > 1; i >>= 1) fs->fs_fsbtodb++; dev_bsize = lp->d_secsize; if (fs->fs_magic == FS_UFS2_MAGIC) { fs->fs_fpg = pp->p_cpg; fs->fs_ncg = howmany(fs->fs_size, fs->fs_fpg); } else /* if (fs->fs_magic == FS_UFS1_MAGIC) */ { fs->fs_old_cpg = pp->p_cpg; fs->fs_old_cgmask = 0xffffffff; for (i = lp->d_ntracks; i > 1; i >>= 1) fs->fs_old_cgmask <<= 1; if (!POWEROF2(lp->d_ntracks)) fs->fs_old_cgmask <<= 1; fs->fs_old_cgoffset = roundup(howmany(lp->d_nsectors, nspf), fs->fs_frag); fs->fs_fpg = (fs->fs_old_cpg * lp->d_secpercyl) / nspf; fs->fs_ncg = howmany(fs->fs_size / lp->d_secpercyl, fs->fs_old_cpg); } return (1); }
void flush(int fd, struct bufarea *bp) { int i, j; if (!bp->b_dirty) return; bp->b_dirty = 0; if (fswritefd < 0) { pfatal("WRITING IN READ_ONLY MODE.\n"); return; } if (bp->b_errs != 0) pfatal("WRITING %sZERO'ED BLOCK %lld TO DISK\n", (bp->b_errs == bp->b_size / dev_bsize) ? "" : "PARTIALLY ", (long long)bp->b_bno); bp->b_errs = 0; blwrite(fd, bp->b_un.b_buf, bp->b_bno, (long)bp->b_size); if (bp != &sblk) return; for (i = 0, j = 0; i < sblock.fs_cssize; i += sblock.fs_bsize, j++) { blwrite(fswritefd, (char *)sblock.fs_csp + i, fsbtodb(&sblock, sblock.fs_csaddr + j * sblock.fs_frag), sblock.fs_cssize - i < sblock.fs_bsize ? sblock.fs_cssize - i : sblock.fs_bsize); } }
void fileerror(ino_t cwd, ino_t ino, const char *errmesg) { char pathbuf[MAXPATHLEN + 1]; struct uvnode *vp; pwarn("%s ", errmesg); pinode(ino); printf("\n"); pwarn("PARENT=%lld\n", (long long)cwd); getpathname(pathbuf, sizeof(pathbuf), cwd, ino); if (ino < ULFS_ROOTINO || ino >= maxino) { pfatal("NAME=%s\n", pathbuf); return; } vp = vget(fs, ino); if (vp == NULL) pfatal("INO is NULL\n"); else { if (ftypeok(VTOD(vp))) pfatal("%s=%s\n", (lfs_dino_getmode(fs, VTOI(vp)->i_din) & LFS_IFMT) == LFS_IFDIR ? "DIR" : "FILE", pathbuf); else pfatal("NAME=%s\n", pathbuf); } }
/******************************************************************************* * Labeling ******************************************************************************/ void dolabel(mdl_t *mdl) { // First, load the model provided by the user. This is mandatory to // label new datas ;-) if (mdl->opt->model == NULL) fatal("you must specify a model"); info("* Load model\n"); FILE *file = fopen(mdl->opt->model, "r"); if (file == NULL) pfatal("cannot open input model file"); mdl_load(mdl, file); // Open input and output files FILE *fin = stdin, *fout = stdout; if (mdl->opt->input != NULL) { fin = fopen(mdl->opt->input, "r"); if (fin == NULL) pfatal("cannot open input data file"); } if (mdl->opt->output != NULL) { fout = fopen(mdl->opt->output, "w"); if (fout == NULL) pfatal("cannot open output data file"); } // Do the labelling info("* Label sequences\n"); tag_label(mdl, fin, fout); info("* Done\n"); // And close files if (mdl->opt->input != NULL) fclose(fin); if (mdl->opt->output != NULL) fclose(fout); }
u_long findsrc(u_long dest) { struct sockaddr_in sinsrc, sindest; int s, size; if ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) pfatal("socket error"); memset(&sinsrc, 0, sizeof(struct sockaddr_in)); memset(&sindest, 0, sizeof(struct sockaddr_in)); sindest.sin_family = AF_INET; sindest.sin_addr.s_addr = dest; sindest.sin_port = htons(53); /* can be anything but zero */ if (connect(s, (struct sockaddr *)&sindest, sizeof(sindest)) < 0) pfatal("connect"); size = sizeof(sinsrc); if (getsockname(s, (struct sockaddr *)&sinsrc, &size) < 0) pfatal("getsockname"); close(s); debug("Determined source address of %s to reach %s\n", iptos(sinsrc.sin_addr.s_addr), iptos(dest)); return sinsrc.sin_addr.s_addr; }
void copy_file (char const *from, char const *to, struct stat *tost, int to_flags, mode_t mode, bool to_dir_known_to_exist) { int tofd; if (debug & 4) say ("Copying %s %s to %s\n", S_ISLNK (mode) ? "symbolic link" : "file", quotearg_n (0, from), quotearg_n (1, to)); if (S_ISLNK (mode)) { char *buffer = xmalloc (PATH_MAX); if (readlink (from, buffer, PATH_MAX) < 0) pfatal ("Can't read %s %s", "symbolic link", from); if (symlink (buffer, to) != 0) pfatal ("Can't create %s %s", "symbolic link", to); if (tost && lstat (to, tost) != 0) pfatal ("Can't get file attributes of %s %s", "symbolic link", to); free (buffer); } else { assert (S_ISREG (mode)); tofd = create_file (to, O_WRONLY | O_BINARY | to_flags, mode, to_dir_known_to_exist); copy_to_fd (from, tofd); if (tost && fstat (tofd, tost) != 0) pfatal ("Can't get file attributes of %s %s", "file", to); if (close (tofd) != 0) write_fatal (); } }
/* * Open the patch file at the beginning of time. */ void open_patch_file(const char *filename) { struct stat filestat; int nr, nw; if (filename == NULL || *filename == '\0' || strEQ(filename, "-")) { pfp = fopen(TMPPATNAME, "w"); if (pfp == NULL) pfatal("can't create %s", TMPPATNAME); while ((nr = fread(buf, 1, buf_size, stdin)) > 0) { nw = fwrite(buf, 1, nr, pfp); if (nr != nw) pfatal("write error to %s", TMPPATNAME); } if (ferror(pfp) || fclose(pfp)) pfatal("can't write %s", TMPPATNAME); filename = TMPPATNAME; } pfp = fopen(filename, "r"); if (pfp == NULL) pfatal("patch file %s not found", filename); fstat(fileno(pfp), &filestat); p_filesize = filestat.st_size; next_intuit_at(0L, 1L); /* start at the beginning */ set_hunkmax(); }
/* * Fetch a line from the input file, \n terminated, not necessarily \0. */ char * ifetch(LINENUM line, int whichbuf) { if (line < 1 || line > input_lines) { if (warn_on_invalid_line) { say("No such line %ld in input file, ignoring\n", line); warn_on_invalid_line = false; } return NULL; } if (using_plan_a) return i_ptr[line]; else { LINENUM offline = line % lines_per_buf; LINENUM baseline = line - offline; if (tiline[0] == baseline) whichbuf = 0; else if (tiline[1] == baseline) whichbuf = 1; else { tiline[whichbuf] = baseline; if (lseek(tifd, (off_t) (baseline / lines_per_buf * tibuflen), SEEK_SET) < 0) pfatal("cannot seek in the temporary input file"); if (read(tifd, tibuf[whichbuf], tibuflen) != (ssize_t) tibuflen) pfatal("error reading tmp file %s", TMPINNAME); } return tibuf[whichbuf] + (tireclen * offline); } }
/* check if (arg) is a valid wordlist file */ void parser_wordlist(char *arg) { struct stat wrd_stat; #ifdef HAVE_LIBMAGIC const char *target_mime = "text/plain;"; #endif if(arg == NULL) fatal("called with NULL argument."); else if(globals.options.dict == false) fatal("dictionary features OFF. unable to parse wordlist."); else if( stat(arg,&wrd_stat) ) // if can't get file stats pfatal(arg); else if( S_ISREG(wrd_stat.st_mode) == 0 ) // if isn't a regular file fatal_long("\"%s\" is not a regular file.",arg); else if( access(arg,R_OK)) pfatal(arg); else { #ifdef HAVE_LIBMAGIC if(strncmp(get_mime(arg),target_mime,strlen(target_mime)+1) != 0) report(warning,"\"%s\" is not a \"%s\" file.",arg,target_mime); #endif if((globals.wordlist = (const char *) get_full_path(arg)) == NULL) fatal("unable to resolve full path for wordlist."); } return; }
/* * It would be nice to use some of the infrastructure in network.c, * but ServerNetInit only sets up UDP sockets. Maybe when we revisit * and refactor... */ static void net_init(void) { struct sockaddr_in name; if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) pfatal("Could not allocate socket"); name.sin_family = AF_INET; name.sin_addr.s_addr = clientif.s_addr; name.sin_port = htons(portnum); if (bind(sock, (struct sockaddr *)&name, sizeof(name)) < 0) { /* * We reproduce ServerNetInit behavior here: if we cannot * bind to the indicated port we exit with a special status * so that the master server which invoked us can pick * another. */ perror("Binding to socket"); close(sock); exit(EADDRINUSE); } if (listen(sock, 128) < 0) { close(sock); pfatal("Could not listen on socket"); } }
/******************************************************************************* * Dumping ******************************************************************************/ static void dodump(mdl_t *mdl) { // Load input model file info("* Load model\n"); FILE *fin = stdin; if (mdl->opt->input != NULL) { fin = fopen(mdl->opt->input, "r"); if (fin == NULL) pfatal("cannot open input data file"); } mdl_load(mdl, fin); if (mdl->opt->input != NULL) fclose(fin); // Open output file FILE *fout = stdout; if (mdl->opt->output != NULL) { fout = fopen(mdl->opt->output, "w"); if (fout == NULL) pfatal("cannot open output data file"); } // Dump model info("* Dump model\n"); const uint32_t Y = mdl->nlbl; const uint64_t O = mdl->nobs; const qrk_t *Qlbl = mdl->reader->lbl; const qrk_t *Qobs = mdl->reader->obs; char fmt[16]; sprintf(fmt, "%%.%df\n", mdl->opt->prec); for (uint64_t o = 0; o < O; o++) { const char *obs = qrk_id2str(Qobs, o); bool empty = true; if (mdl->kind[o] & 1) { const double *w = mdl->theta + mdl->uoff[o]; for (uint32_t y = 0; y < Y; y++) { if (!mdl->opt->all && w[y] == 0.0) continue; const char *ly = qrk_id2str(Qlbl, y); fprintf(fout, "%s\t#\t%s\t", obs, ly); fprintf(fout, fmt, w[y]); empty = false; } } if (mdl->kind[o] & 2) { const double *w = mdl->theta + mdl->boff[o]; for (uint32_t d = 0; d < Y * Y; d++) { if (!mdl->opt->all && w[d] == 0.0) continue; const char *ly = qrk_id2str(Qlbl, d % Y); const char *lyp = qrk_id2str(Qlbl, d / Y); fprintf(fout, "%s\t%s\t%s\t", obs, lyp, ly); fprintf(fout, fmt, w[d]); empty = false; } } if (!empty) fprintf(fout, "\n"); } if (mdl->opt->output != NULL) fclose(fout); }
void load_conf(struct opts *opts) { FILE *f; struct conf_entry *conf, *e; char *conf_file = opts->conf_file; if (!opts->conf_file) conf_file = DEFAULT_CONF_FILE; f = fopen (conf_file, "r"); if (!f) { if (opts->conf_file) { pfatal ("can't open conf file '%s'", opts->conf_file); } else { pinfo ("can't open conf file '%s'", conf_file); return; } } conf = conf_parse (f); if (!conf) pfatal ("can't parse config file"); for (e = conf; e; e = e->next) { if (!strcmp (e->key, "max-tries") && e->value) { opts->max_tries = atoi (e->value); } else if (!strcmp (e->key, "min-steady-state-interval") && e->value) { opts->min_steady_state_interval = atoi (e->value); } else if (!strcmp (e->key, "wait-between-tries") && e->value) { opts->wait_between_tries = atoi (e->value); } else if (!strcmp (e->key, "subprocess-tries") && e->value) { opts->subprocess_tries = atoi (e->value); } else if (!strcmp (e->key, "subprocess-wait-between-tries") && e->value) { opts->subprocess_wait_between_tries = atoi (e->value); } else if (!strcmp (e->key, "steady-state-interval") && e->value) { opts->steady_state_interval = atoi (e->value); } else if (!strcmp (e->key, "base-path") && e->value) { opts->base_path = strdup (e->value); if (!opts->base_path) fatal ("out of memory for base path"); } else if (!strcmp (e->key, "should-sync-hwclock")) { opts->should_sync_hwclock = e->value ? !strcmp(e->value, "yes") : 1; } else if (!strcmp (e->key, "should-load-disk")) { opts->should_load_disk = e->value ? !strcmp(e->value, "yes") : 1; } else if (!strcmp (e->key, "should-save-disk")) { opts->should_save_disk = e->value ? !strcmp(e->value, "yes") : 1; } else if (!strcmp (e->key, "should-netlink")) { opts->should_netlink = e->value ? !strcmp(e->value, "yes") : 1; } else if (!strcmp (e->key, "dry-run")) { opts->dry_run = e->value ? !strcmp(e->value, "yes") : 1; } else if (!strcmp (e->key, "jitter") && e->value) { opts->jitter = atoi (e->value); } else if (!strcmp (e->key, "verbose")) { verbose = e->value ? !strcmp(e->value, "yes") : 1; } else if (!strcmp (e->key, "source")) { e = parse_source(opts, e); } } }
void route(const char * gw) { int ret; struct uinet_socket * so; struct rt_msghdr * rtm; struct uinet_sockaddr * sa; struct uinet_sockaddr_in * sin; char buf[4096]; errno = 0; ret = uinet_socreate(uinet_instance_default(), UINET_PF_ROUTE, &so, UINET_SOCK_RAW, 0); if (ret) { errno = ret; pfatal("uinet_socreate"); } memset(buf, 0, sizeof(buf)); rtm = (struct rt_msghdr *)buf; rtm->rtm_version = RTM_VERSION; rtm->rtm_type = RTM_ADD; rtm->rtm_flags = RTF_GATEWAY; rtm->rtm_addrs = RTA_DST | RTA_GATEWAY | RTA_NETMASK; rtm->rtm_pid = getpid(); rtm->rtm_seq = 1234; sa = (struct uinet_sockaddr *)(rtm + 1); sin = (struct uinet_sockaddr_in *)(sa); sin->sin_len = sizeof(struct uinet_sockaddr_in); sin->sin_family = AF_INET; sin->sin_addr.s_addr = inet_addr("0.0.0.0"); sa = (struct uinet_sockaddr *)((unsigned char *)(sa) + ROUNDUP(sa->sa_len)); sin = (struct uinet_sockaddr_in *)(sa); sin->sin_len = sizeof(struct uinet_sockaddr_in); sin->sin_family = AF_INET; sin->sin_addr.s_addr = inet_addr(gw); sa = (struct uinet_sockaddr *)((unsigned char *)(sa) + ROUNDUP(sa->sa_len)); sin = (struct uinet_sockaddr_in *)(sa); sin->sin_len = 0; sin->sin_family = AF_INET; sa = (struct uinet_sockaddr *)((unsigned char *)(sa) + ROUNDUP(sa->sa_len)); rtm->rtm_msglen = (char *)sa - buf; errno = socket_write(so, buf, rtm->rtm_msglen); if (errno) pfatal("socket_write"); /* probably should loop through reply messages and see whether the setting of the route succeeded; right now we just assume it worked. */ return; }
/* check if (arg) is a vlid output file */ void parser_outfile(char *arg) { struct stat out_stat; struct statvfs disk_stat; char *path=NULL; FILE *fout; if(arg == NULL) fatal("called with NULL argument."); else if(stat(arg,&out_stat) == 0) { if(S_ISREG(out_stat.st_mode)) { if((path = get_full_path(arg)) != NULL) { if(access(path,W_OK) == 0) { if(statvfs(path,&disk_stat) == 0) { if((disk_stat.f_bsize * disk_stat.f_bavail) > MIN_FREE_SPACE ) { argcpy(&(globals.outfile),path,strlen(path)+1); } else fatal_long("we need at least %lu free bytes for writing some output.",MIN_FREE_SPACE); } else pfatal(path); } else pfatal(path); } else fatal("unable to find full path for outfile."); } else fatal_long("file \"%s\" isn't a regular file.",arg); } else if(errno == ENOENT) { if((fout = fopen(arg,"w+")) != NULL) { fclose(fout); parser_outfile(arg); // restart } else pfatal(arg); } else pfatal(arg); if(path!=NULL) free((void *) path); return; }
/* * We need this because regular seek does not work in text mode */ void text_mode_fseek(FILE *stream, file_offset offset, int ptrname) { /* We do not support SEEK_CUR, SEEK_END etc in text mode */ assert(ptrname == SEEK_SET); if (fseek (stream, 0, SEEK_SET) != 0) pfatal ("fseek"); while (ftell(stream) != offset) { if (getc(stream) == EOF) pfatal ("fseek"); } }
/* qrk_load: * Load a list of key from the given file and add them to the map. Each lines * of the file is taken as a single key and mapped to the next available id if * not already present. If all keys are single lines and the given map is * initilay empty, this will load a map exactly as saved by qrk_save. */ void qrk_load(qrk_t *qrk, FILE *file) { uint64_t cnt = 0; if (fscanf(file, "#qrk#%"SCNu64"\n", &cnt) != 1) { if (ferror(file) != 0) pfatal("cannot read from file"); pfatal("invalid format"); } for (uint64_t n = 0; n < cnt; ++n) { char *str = ns_readstr(file); qrk_str2id(qrk, str); free(str); } }
int get_raw_fd() { int fd, ret, one; fd = socket(PF_INET, SOCK_RAW, IPPROTO_ICMP); if (fd < 0) pfatal("socket"); one = 1; ret = setsockopt(fd, IPPROTO_IP, IP_HDRINCL, &one, sizeof(one)); if (ret < 0) pfatal("setsockopt"); return fd; }
/* Get FILENAME from version control system CS. The file already exists if EXISTS. Only readonly access is needed if READONLY. Use the command GETBUF to actually get the named file. Store the resulting file status into *FILESTAT. Return true if successful. */ bool version_get (char const *filename, char const *cs, bool exists, bool readonly, char const *getbuf, struct stat *filestat) { if (patch_get < 0) { ask ("Get file %s from %s%s? [y] ", quotearg (filename), cs, readonly ? "" : " with lock"); if (*buf == 'n') return 0; } if (dry_run) { if (! exists) fatal ("can't do dry run on nonexistent version-controlled file %s; invoke '%s' and try again", quotearg (filename), getbuf); } else { if (verbosity == VERBOSE) say ("Getting file %s from %s%s...\n", quotearg (filename), cs, readonly ? "" : " with lock"); if (systemic (getbuf) != 0) fatal ("Can't get file %s from %s", quotearg (filename), cs); if (stat (filename, filestat) != 0) pfatal ("%s", quotearg (filename)); } return 1; }
int reply(char *question) { int persevere; char c; if (preen) pfatal("INTERNAL ERROR: GOT TO reply()"); persevere = !strcmp(question, "CONTINUE"); printf("\n"); if (!persevere && (nflag || fswritefd < 0)) { printf("%s? no\n\n", question); return (0); } if (yflag || (persevere && nflag)) { printf("%s? yes\n\n", question); return (1); } do { printf("%s? [yn] ", question); (void) fflush(stdout); c = getc(stdin); while (c != '\n' && getc(stdin) != '\n') if (feof(stdin)) return (0); } while (c != 'y' && c != 'Y' && c != 'n' && c != 'N'); printf("\n"); if (c == 'y' || c == 'Y') return (1); return (0); }
/* Create FILE with OPEN_FLAGS, and with MODE adjusted so that we can read and write the file and that the file is not executable. Return the file descriptor. */ int create_file (char const *file, int open_flags, mode_t mode, bool to_dir_known_to_exist) { int try_makedirs_errno = to_dir_known_to_exist ? 0 : ENOENT; int fd; mode |= S_IRUSR | S_IWUSR; mode &= ~ (S_IXUSR | S_IXGRP | S_IXOTH); do { if (! (O_CREAT && O_TRUNC)) close (creat (file, mode)); fd = open (file, O_CREAT | O_TRUNC | open_flags, mode); if (fd < 0) { char *f; if (errno != try_makedirs_errno) pfatal ("Can't create file %s", quotearg (file)); f = xstrdup (file); makedirs (f); free (f); try_makedirs_errno = 0; } } while (fd < 0); return fd; }
/* * Compare the original cylinder group inode and block bitmaps with the * updated cylinder group inode and block bitmaps. Free inodes and blocks * that have been added. Complain if any previously freed inodes blocks * are now allocated. */ void update_maps( struct cg *oldcg, /* cylinder group of claimed allocations */ struct cg *newcg, /* cylinder group of determined allocations */ int usesysctl) /* 1 => use sysctl interface to update maps */ { int inomapsize, excessdirs; struct fs *fs = &sblock; inomapsize = howmany(fs->fs_ipg, CHAR_BIT); excessdirs = oldcg->cg_cs.cs_ndir - newcg->cg_cs.cs_ndir; if (excessdirs < 0) { pfatal("LOST %d DIRECTORIES\n", -excessdirs); excessdirs = 0; } if (excessdirs > 0) check_maps(cg_inosused(newcg), cg_inosused(oldcg), inomapsize, oldcg->cg_cgx * (ufs2_daddr_t)fs->fs_ipg, "DIR", freedirs, 0, excessdirs, usesysctl); check_maps(cg_inosused(newcg), cg_inosused(oldcg), inomapsize, oldcg->cg_cgx * (ufs2_daddr_t)fs->fs_ipg, "FILE", freefiles, excessdirs, fs->fs_ipg, usesysctl); check_maps(cg_blksfree(oldcg), cg_blksfree(newcg), howmany(fs->fs_fpg, CHAR_BIT), oldcg->cg_cgx * (ufs2_daddr_t)fs->fs_fpg, "FRAG", freeblks, 0, fs->fs_fpg, usesysctl); }
char * loadTGA(char * loc, int * x, int *y, short * bpp) { //Loads the TGA data from file (deylen - 02/06/2009) int size; char * data; unsigned short w, h; FILE * f; if (!(f = fopen(loc, "rb"))) loadTGAFail(loc); fseek(f, 12, SEEK_SET); if (fread(&w, 2, 1, f) != 1) loadTGAFail(loc); if (fread(&h, 2, 1, f) != 1) loadTGAFail(loc); if (fread(bpp, 1, 1, f) != 1) loadTGAFail(loc); fseek(f, 18, SEEK_SET); *x = w; *y = h; *bpp /= 8; size = (*x) * (*y) * (*bpp); data = newStr(size); if (fread(data, sizeof(unsigned char), size, f) < size) { free(data); pfatal("Could not read all of data from file. Make sure you have saved the Image without RLE compression\n"); } fclose(f); return data; }
void adjust(struct inodesc *idesc, short lcnt) { struct ext2fs_dinode *dp; dp = ginode(idesc->id_number); if (fs2h16(dp->e2di_nlink) == lcnt) { if (linkup(idesc->id_number, (ino_t)0) == 0) clri(idesc, "UNREF", 0); } else { pwarn("LINK COUNT %s", (lfdir == idesc->id_number) ? lfname : ((fs2h16(dp->e2di_mode) & IFMT) == IFDIR ? "DIR" : "FILE")); pinode(idesc->id_number); printf(" COUNT %d SHOULD BE %d", fs2h16(dp->e2di_nlink), fs2h16(dp->e2di_nlink) - lcnt); if (preen) { if (lcnt < 0) { printf("\n"); pfatal("LINK COUNT INCREASING"); } printf(" (ADJUSTED)\n"); } if (preen || reply("ADJUST") == 1) { dp->e2di_nlink = h2fs16(fs2h16(dp->e2di_nlink) - lcnt); inodirty(); } } }
void blkerror(ino_t ino, const char *type, daddr_t blk) { pfatal("%lld %s I=%llu", (long long) blk, type, (unsigned long long)ino); printf("\n"); if (exitonfail) exit(1); switch (statemap[ino]) { case FSTATE: statemap[ino] = FCLEAR; return; case DSTATE: statemap[ino] = DCLEAR; return; case FCLEAR: case DCLEAR: return; default: err(EEXIT, "BAD STATE %d TO BLKERR\n", statemap[ino]); /* NOTREACHED */ } }
void blkerror(ufs1_ino_t ino, char *type, ufs_daddr_t blk) { pfatal("%d %s I=%u", blk, type, ino); printf("\n"); switch (inoinfo(ino)->ino_state) { case FSTATE: inoinfo(ino)->ino_state = FCLEAR; return; case DSTATE: inoinfo(ino)->ino_state = DCLEAR; return; case FCLEAR: case DCLEAR: return; default: errx(EEXIT, "BAD STATE %d TO BLKERR", inoinfo(ino)->ino_state); /* NOTREACHED */ } }
void blkerror(ino_t ino, const char *type, ufs2_daddr_t blk) { pfatal("%jd %s I=%ju", (intmax_t)blk, type, (uintmax_t)ino); printf("\n"); switch (inoinfo(ino)->ino_state) { case FSTATE: case FZLINK: inoinfo(ino)->ino_state = FCLEAR; return; case DSTATE: case DZLINK: inoinfo(ino)->ino_state = DCLEAR; return; case FCLEAR: case DCLEAR: return; default: errx(EEXIT, "BAD STATE %d TO BLKERR", inoinfo(ino)->ino_state); /* NOTREACHED */ } }
int32_t reply(char *question) { char line[80]; if (preen) pfatal(gettext("INTERNAL ERROR: GOT TO reply()")); (void) printf("\n%s? ", question); if (nflag || fswritefd < 0) { (void) printf(gettext(" no\n\n")); iscorrupt = 1; /* known to be corrupt */ return (0); } if (yflag) { (void) printf(gettext(" yes\n\n")); return (1); } if (getaline(stdin, line, sizeof (line)) == EOF) errexit("\n"); (void) printf("\n"); if (line[0] == 'y' || line[0] == 'Y') return (1); else { iscorrupt = 1; /* known to be corrupt */ return (0); } }