Beispiel #1
0
/**
 * main - Begin here
 *
 * Start from here.
 *
 * Return:  0  Success, the program worked
 *	    1  Error, something went wrong
 */
int main(int argc, char **argv)
{
	unsigned long mnt_flags = 0;
	int result = 0;
	ntfs_volume *vol;

	ntfs_log_set_handler(ntfs_log_handler_outerr);

	if (!parse_options(argc, argv))
		return 1;

	utils_set_locale();

	if (!opts.label)
		opts.noaction++;

	vol = utils_mount_volume(opts.device,
			(opts.noaction ? MS_RDONLY : 0) |
			(opts.force ? MS_RECOVER : 0));
	if (!vol)
		return 1;

	if (opts.label)
		result = change_label(vol, mnt_flags, opts.label, opts.force);
	else
		result = print_label(vol, mnt_flags);

	ntfs_umount(vol, FALSE);
	return result;
}
Beispiel #2
0
int main(int argc, char *argv[])
{
	printf("TFAT version 01\n");
	printf("Copyright (C) 2015 Parham Alvani ([email protected])\n");
	printf("TFAT comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n");
	printf("This is free software, and you are welcome to redistribute it\n");
	printf("under certain conditions; type `show c' for details.\n");
	printf("\n");

	char *command;
	char prompt[MAX_BUFF];

	change_current_path("-");
	change_label("NOTHING");

	while (true) {
		sprintf(prompt, "%s@TFAT {%s} [%s] $ ", getlogin(), label,
			current_path);
		command = readline(prompt);
		if (command && *command)
			add_history(command);
		command_dispatcher(command);
		free(command);
	}
}
Beispiel #3
0
/**
 * main - Begin here
 *
 * Start from here.
 *
 * Return:  0  Success, the program worked
 *	    1  Error, something went wrong
 */
int main(int argc, char **argv)
{
	unsigned long mnt_flags = 0;
	int result = 0;
	ntfs_volume *vol;

	ntfs_log_set_handler(ntfs_log_handler_outerr);

	result = parse_options(argc, argv);
	if (result >= 0)
		return (result);

	result = 0;
	utils_set_locale();

	if ((opts.label || opts.new_serial)
	    && !opts.noaction
	    && !opts.force
	    && !ntfs_check_if_mounted(opts.device, &mnt_flags)
	    && (mnt_flags & NTFS_MF_MOUNTED)) {
		ntfs_log_error("Cannot make changes to a mounted device\n");
		result = 1;
		goto abort;
	}

	if (!opts.label && !opts.new_serial)
		opts.noaction++;

	vol = utils_mount_volume(opts.device,
			(opts.noaction ? NTFS_MNT_RDONLY : 0) |
			(opts.force ? NTFS_MNT_RECOVER : 0));
	if (!vol)
		return 1;

	if (opts.new_serial) {
		result = set_new_serial(vol);
		if (result)
			goto unmount;
	} else {
		if (opts.verbose)
			result = print_serial(vol);
	}
	if (opts.label)
		result = change_label(vol, opts.label);
	else
		result = print_label(vol, mnt_flags);

unmount :
	ntfs_umount(vol, FALSE);
abort :
		/* "result" may be a negative reply of a library function */
	return (result ? 1 : 0);
}
Beispiel #4
0
int main (int argc, char ** argv)
{
	if (argc == 2)
	     print_label(argv[1]);
	else if (argc == 3)
	     change_label(argv[1], argv[2]);
	else {
	     fprintf(stderr, _("Usage: e2label device [newlabel]\n"));
	     exit(1);
	}
	return 0;
}
Beispiel #5
0
int ad_set(int argc, char **argv, AFPObj *obj)
{
    int c, firstarg;
    afpvol_t vol;
    struct stat st;
    int adflags = 0;
    struct adouble ad;

    while ((c = getopt(argc, argv, ":l:t:c:f:a:")) != -1) {
        switch(c) {
        case 'l':
            new_label = strdup(optarg);
            break;
        case 't':
            new_type = strdup(optarg);
            break;
        case 'c':
            new_creator = strdup(optarg);
            break;
        case 'f':
            new_flags = strdup(optarg);
            break;
        case 'a':
            new_attributes = strdup(optarg);
            break;
        case ':':
        case '?':
            usage_set();
            return -1;
            break;
        }

    }

    if (argc <= optind)
        exit(1);

    cnid_init();

    openvol(obj, argv[optind], &vol);
    if (vol.vol->v_path == NULL)
        exit(1);

    if (stat(argv[optind], &st) != 0) {
        perror("stat");
        exit(1);
    }

    if (S_ISDIR(st.st_mode))
        adflags = ADFLAGS_DIR;

    ad_init(&ad, vol.vol);

    if (ad_open(&ad, argv[optind], adflags | ADFLAGS_HF | ADFLAGS_CREATE | ADFLAGS_RDWR, 0666) < 0)
        goto exit;

    if (new_label)
        change_label(argv[optind], &vol, &st, &ad, new_label);
    if (new_type)
        change_type(argv[optind], &vol, &st, &ad, new_type);
    if (new_creator)
        change_creator(argv[optind], &vol, &st, &ad, new_creator);
    if (new_flags)
        change_flags(argv[optind], &vol, &st, &ad, new_flags);
    if (new_attributes)
        change_attributes(argv[optind], &vol, &st, &ad, new_attributes);

    ad_flush(&ad);
    ad_close(&ad, ADFLAGS_HF);

exit:
    closevol(&vol);

    return 0;
}
static MRI *
edit_hippocampus(MRI *mri_in_labeled, MRI *mri_T1, MRI *mri_out_labeled) {
  int   width, height, depth, x, y, z, nchanged, dleft, label,
  dright, dpos, dant, dup, ddown, i, left, dgray, dhippo, dwhite, olabel ;
  MRI   *mri_tmp ;

  nchanged = 0 ;

  width = mri_T1->width ;
  height = mri_T1->height ;
  depth = mri_T1->depth ;

  mri_out_labeled = MRIcopy(mri_in_labeled, mri_out_labeled) ;

  /* change all gm within 2 mm of ventricle to wm */
  for (z = 0 ; z < depth ; z++) {
    for (y = 0 ; y < height ; y++) {
      for (x = 0 ; x < width ; x++) {
        if (x == Gx && y == Gy && z == Gz)
          DiagBreak() ;
        label = MRIvox(mri_out_labeled, x, y, z) ;
        if (IS_GM(label) == 0)
          continue ;
        left = label == Left_Cerebral_Cortex ;
        olabel = left ? Left_Lateral_Ventricle : Right_Lateral_Ventricle;
        if (MRIneighborsInWindow(mri_out_labeled, x, y, z, 5, olabel) >= 1) {
          nchanged++ ;
          MRIvox(mri_out_labeled, x, y, z) = left ? Left_Cerebral_White_Matter : Right_Cerebral_White_Matter;
        }
      }
    }
  }

  mri_tmp = MRIcopy(mri_out_labeled, NULL) ;

  /* change gray to hippocampus based on wm */
  for (i = 0 ; i < 3 ; i++) {
    for (z = 0 ; z < depth ; z++) {
      for (y = 0 ; y < height ; y++) {
        for (x = 0 ; x < width ; x++) {
          if (x == Gx && y == Gy && z == Gz)
            DiagBreak() ;
          label = MRIvox(mri_tmp, x, y, z) ;
          if (x == 160 && y == 127 && z == 118)
            DiagBreak() ;

          left = 0 ;
          switch (label) {
          case Left_Cerebral_White_Matter:
            left = 1 ;
          case Right_Cerebral_White_Matter:
            dgray = distance_to_label(mri_out_labeled,
                                      left ? Left_Cerebral_Cortex :
                                      Right_Cerebral_Cortex,
                                      x,y,z,0,1,0,3);

            dwhite = distance_to_label(mri_out_labeled,
                                       left ? Left_Cerebral_White_Matter :
                                       Right_Cerebral_White_Matter,
                                       x,y,z,0,-1,0,1);

            dhippo = distance_to_label(mri_out_labeled,
                                       left ? Left_Hippocampus :
                                       Right_Hippocampus,
                                       x,y,z,0,-1,0,3);
            /* change bright hippocampus that borders white matter to white matter */
            if (dgray <= 2 && dwhite <= 1 && dhippo <= 3) {
              mle_label(mri_T1, mri_tmp, x, y, z, 9,
                        left ? Left_Cerebral_Cortex : Right_Cerebral_Cortex,
                        left ? Left_Cerebral_White_Matter : Right_Cerebral_White_Matter) ;
            }
          case Left_Hippocampus:
            left = 1 ;
          case Right_Hippocampus:
            dgray = distance_to_label(mri_out_labeled,
                                      left ? Left_Cerebral_Cortex :
                                      Right_Cerebral_Cortex,
                                      x,y,z,0,1,0,3);

            dwhite = distance_to_label(mri_out_labeled,
                                       left ? Left_Cerebral_White_Matter :
                                       Right_Cerebral_White_Matter,
                                       x,y,z,0,1,0,1);

            dhippo = distance_to_label(mri_out_labeled,
                                       left ? Left_Hippocampus :
                                       Right_Hippocampus,
                                       x,y,z,0,-1,0,1);
            /* change bright hippocampus that borders white matter to white matter */
            if (dgray <= 3 && dwhite <= 1 && dhippo <= 1) {
              change_label(mri_T1, mri_tmp, x, y, z, 9, left) ;
            }
            break ;
          case Unknown: {
            int dhippo, dl, dr, dgray, dwhite ;

            if (x == 160 && y == 129 && z == 121)
              DiagBreak() ;

            /*
             if the current label is unknown, and there is white matter above
             and hippocampus above and gray matter below, change to gray matter.
            */
            dl = distance_to_label(mri_out_labeled,
                                   Left_Hippocampus,
                                   x,y,z,0,-1,0,4);
            dr = distance_to_label(mri_out_labeled,
                                   Right_Hippocampus,
                                   x,y,z,0,-1,0,4);
            if (dl > 4 && dr > 4) /* could be inferior to inf-lat-ven also */
            {
              dl = distance_to_label(mri_out_labeled,
                                     Left_Inf_Lat_Vent,
                                     x,y,z,0,-1,0,4);
              dr = distance_to_label(mri_out_labeled,
                                     Right_Inf_Lat_Vent,
                                     x,y,z,0,-1,0,4);
            }

            if (dl < dr) {
              left = 1 ;
              dhippo = dl ;
              dgray = distance_to_label(mri_out_labeled,
                                        Left_Cerebral_Cortex,
                                        x,y,z,0,1,0,2);
              dwhite = distance_to_label(mri_out_labeled,
                                         Left_Cerebral_White_Matter,
                                         x,y,z,0,-1,0,2);
            } else {
              left = 0 ;
              dhippo = dr ;
              dwhite = distance_to_label(mri_out_labeled,
                                         Right_Cerebral_White_Matter,
                                         x,y,z,0,-1,0,2);
              dgray = distance_to_label(mri_out_labeled,
                                        Right_Cerebral_Cortex,
                                        x,y,z,0,1,0,2);
            }
            if (dhippo <= 4 && dwhite <= 2 && dgray <= 2) {
              MRIvox(mri_tmp, x, y, z) =
                left ? Left_Cerebral_Cortex : Right_Cerebral_Cortex ;
              nchanged++ ;
              continue ;
            }

            break ;
          }
          case Left_Cerebral_Cortex:
            left = 1 ;
          case Right_Cerebral_Cortex:
            dup = distance_to_label(mri_out_labeled,
                                    left ?  Left_Hippocampus :
                                    Right_Hippocampus,x,y,z,0,-1,0,2);
            if (dup <= 1) {
              label = left ?
                      Left_Cerebral_White_Matter : Right_Cerebral_White_Matter;
              MRIvox(mri_tmp, x, y, z) = label ;
              nchanged++ ;
              continue ;
            }

            /*
              if the current label is gray, and there is white matter below
              and hippocampus above, change to hippocampus.
            */
            ddown = distance_to_label(mri_out_labeled,
                                      left ? Left_Cerebral_White_Matter :
                                      Right_Cerebral_White_Matter,
                                      x,y,z,0,1,0,3);
            dup = distance_to_label(mri_out_labeled,
                                    left ?  Left_Hippocampus :
                                    Right_Hippocampus,x,y,z,0,-1,0,2);
            if (dup <= 2 && ddown <= 2) {
              change_label(mri_T1, mri_tmp, x, y, z, 9, left) ;
              nchanged++ ;
              continue ;
            }

            /*
              if the current label is gray, and there is white matter above
              and hippocampus below, change to hippocampus.
            */
            ddown = distance_to_label(mri_out_labeled,
                                      left ? Left_Hippocampus :
                                      Right_Hippocampus,
                                      x,y,z,0,1,0,3);
            dup = distance_to_label(mri_out_labeled,
                                    left ?  Left_Cerebral_White_Matter :
                                    Right_Cerebral_White_Matter,
                                    x,y,z,0,-1,0,2);
            if (dup <= 2 && ddown <= 2) {
              change_label(mri_T1, mri_tmp, x, y, z, 9, left) ;
              nchanged++ ;
              continue ;
            }

            ddown = distance_to_label(mri_out_labeled,
                                      left ? Left_Hippocampus :
                                      Right_Hippocampus,
                                      x,y,z,0,1,0,3);
            dup = distance_to_label(mri_out_labeled,
                                    left ?  Left_Hippocampus :
                                    Right_Hippocampus,
                                    x,y,z,0,-1,0,2);
            if (dup <= 2 && ddown <= 2) {
              change_label(mri_T1, mri_tmp, x, y, z, 9, left) ;
              nchanged++ ;
              continue ;
            }

            dleft = distance_to_label(mri_out_labeled, left ?
                                      Left_Cerebral_White_Matter :
                                      Right_Cerebral_White_Matter,
                                      x,y,z,-1,0,0,3);
            dright = distance_to_label(mri_out_labeled, left ?
                                       Left_Cerebral_White_Matter :
                                       Right_Cerebral_White_Matter,
                                       x,y,z,1,0,0,3);
            dup = distance_to_label(mri_out_labeled,
                                    left ?  Left_Hippocampus :
                                    Right_Hippocampus,x,y,z,0,-1,0,2);
            if (dleft <= 2 && dright <= 2 && dup <= 1) {
              label = left ?
                      Left_Cerebral_White_Matter : Right_Cerebral_White_Matter;
              MRIvox(mri_tmp, x, y, z) = label ;
              nchanged++ ;
              continue ;
            }
            dright = distance_to_label(mri_out_labeled, left ?
                                       Left_Cerebral_White_Matter :
                                       Right_Cerebral_White_Matter,
                                       x,y,z,1,0,0,3);
            dleft = distance_to_label(mri_out_labeled, left ?
                                      Left_Hippocampus :
                                      Right_Hippocampus,
                                      x,y,z,-1,0,0,3);
            if (dleft <= 1 && dright <= 1) {
              change_label(mri_T1, mri_tmp, x, y, z, 9, left) ;
              nchanged++ ;
              continue ;
            }

            dleft = distance_to_label(mri_out_labeled, left ?
                                      Left_Cerebral_White_Matter :
                                      Right_Cerebral_White_Matter,
                                      x,y,z,-1,0,0,3);
            dright = distance_to_label(mri_out_labeled, left ?
                                       Left_Hippocampus :
                                       Right_Hippocampus,
                                       x,y,z,1,0,0,3);
            if (dleft <= 1 && dright <= 1) {
              change_label(mri_T1, mri_tmp, x, y, z, 9, left) ;
              nchanged++ ;
              continue ;
            }

            dright = distance_to_label(mri_out_labeled, left ?
                                       Left_Hippocampus :
                                       Right_Hippocampus,
                                       x,y,z,1,0,0,3);
            dleft = distance_to_label(mri_out_labeled, left ?
                                      Left_Hippocampus :
                                      Right_Hippocampus,
                                      x,y,z,-1,0,0,3);
            if (dleft <= 1 && dright <= 1) {
              label = left ?
                      Left_Hippocampus : Right_Hippocampus;
              MRIvox(mri_tmp, x, y, z) = label ;
              nchanged++ ;
              continue ;
            }

            dpos = distance_to_label(mri_out_labeled,
                                     Right_Cerebral_White_Matter,x,y,z,0,0,-1,3);
            dant = distance_to_label(mri_out_labeled,
                                     Right_Cerebral_White_Matter,x,y,z,0,0,1,3);


            /* if the current label is gray and the is white matter directly above,
              and hippocampus within 3 mm, then change label to MLE of either gray or
              white
            */

            if (x == 156 && y == 128 && z == 115)
              DiagBreak() ;
            dgray = distance_to_label(mri_out_labeled,
                                      left ? Left_Cerebral_Cortex :
                                      Right_Cerebral_Cortex,
                                      x,y,z,0,1,0,1);

            dwhite = distance_to_label(mri_out_labeled,
                                       left ? Left_Cerebral_White_Matter :
                                       Right_Cerebral_White_Matter,
                                       x,y,z,0,-1,0,1);

            dhippo = distance_to_label(mri_out_labeled,
                                       left ? Left_Hippocampus :
                                       Right_Hippocampus,
                                       x,y,z,0,-1,0,3);
            /* change bright hippocampus that borders white matter to white matter */
            if (dgray <= 1 && dwhite <= 1 && dhippo <= 3) {
              mle_label(mri_T1, mri_tmp, x, y, z, 9,
                        left ? Left_Cerebral_Cortex : Right_Cerebral_Cortex,
                        left ? Left_Cerebral_White_Matter : Right_Cerebral_White_Matter) ;
            }
            break ;
          default:
            break ;
          }
        }
      }
    }
    MRIcopy(mri_tmp, mri_out_labeled) ;
  }

  /* make gray matter that is superior to hippocampus into hippocampus */
  for (z = 0 ; z < depth ; z++) {
    for (y = 0 ; y < height ; y++) {
      for (x = 0 ; x < width ; x++) {
        int yi ;

        if (x == Gx && y == Gy && z == Gz)
          DiagBreak() ;
        label = MRIvox(mri_out_labeled, x, y, z) ;
        if (!IS_HIPPO(label))
          continue ;
        left = label == Left_Hippocampus ;

        /* search for first non-hippocampal voxel */
        for (yi = y-1 ; yi >= 0 ; yi--) {
          label = MRIvox(mri_out_labeled, x, yi, z) ;
          if (!IS_HIPPO(label))
            break ;
        }
        i = 0 ;
        while (IS_GM(label) && yi >= 0) {
          nchanged++ ;
          MRIvox(mri_out_labeled, x, yi, z) = left ? Left_Hippocampus : Right_Hippocampus;
          yi-- ;
          label = MRIvox(mri_out_labeled, x, yi, z) ;
          if (++i >= 4)
            break ;  /* don't let it go too far */
        }

      }
    }
  }


  /* go through and change wm labels that have hippo both above and below them to hippo */
  for (z = 0 ; z < depth ; z++) {
    for (y = 0 ; y < height ; y++) {
      for (x = 0 ; x < width ; x++) {
        if (x == Gx && y == Gy && z == Gz)
          DiagBreak() ;
        label = MRIvox(mri_tmp, x, y, z) ;
        if (x == 160 && y == 127 && z == 118)
          DiagBreak() ;

        if (!IS_WM(label))
          continue ;
        left = label == Left_Cerebral_White_Matter ;
        if (IS_HIPPO(MRIvox(mri_out_labeled, x, mri_out_labeled->yi[y-1], z)) &&
            IS_HIPPO(MRIvox(mri_out_labeled, x, mri_out_labeled->yi[y+1], z))) {
          nchanged++ ;
          MRIvox(mri_out_labeled, x, y, z) = left ? Left_Hippocampus : Right_Hippocampus;
        }
      }
    }
  }

  MRIfree(&mri_tmp) ;
  printf("%d hippocampal voxels changed.\n", nchanged) ;
  return(mri_out_labeled) ;
}