summaryrefslogtreecommitdiffstats
path: root/src/diskacc.c
blob: 90b708810aec2f813bff84e6d0eae61adc2a1ce8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*

    File: diskacc.c

    Copyright (C) 2008 Christophe GRENIER <grenier@cgsecurity.org>
  
    This software is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
  
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
  
    You should have received a copy of the GNU General Public License along
    with this program; if not, write the Free Software Foundation, Inc., 51
    Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

 */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
 
#include <stdarg.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include <ctype.h>
#ifdef HAVE_TIME_H
#include <time.h>
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#include "types.h"
#include "common.h"
#include "lang.h"
#include "intrf.h"
#ifdef HAVE_NCURSES
#include "intrfn.h"
#else
#include <stdio.h>
#endif
#include "intrface.h"
#include "godmode.h"
#include "fnctdsk.h"
#include "testdisk.h"
#include "adv.h"
#include "analyse.h"
#include "chgtype.h"
#include "edit.h"
#include "savehdr.h"
#include "dirpart.h"
#include "fat.h"
#include "partauto.h"
#include "log.h"
#include "guid_cmp.h"
#include "hdaccess.h"
#include "io_redir.h"
#include "diskacc.h"

#ifdef HAVE_NCURSES
static int interface_check_disk_access_ncurses(disk_t *disk_car)
{
  static const struct MenuItem menuDiskAccess[]=
  {
    { 'C', "Continue", "Continue even if write access isn't available"},
    { 'Q', "Quit", "Return to disk selection"},
    { 0,NULL,NULL}
  };
  unsigned int menu=0;
  int car;
  int line=9;
  aff_copy(stdscr);
  wmove(stdscr,4,0);
  wprintw(stdscr,"%s\n",disk_car->description_short(disk_car));
  wmove(stdscr,6,0);
  wprintw(stdscr,"Write access for this media is not available.");
  wmove(stdscr,7,0);
  wprintw(stdscr,"TestDisk won't be able to modify it.");
#ifdef DJGPP
#elif defined(__CYGWIN__) || defined(__MINGW32__)
  wmove(stdscr,line++,0);
  wprintw(stdscr,"- You may need to be administrator to have write access.\n");
  wmove(stdscr,line++,0);
  wprintw(stdscr,"Under Vista, select TestDisk, right-click and choose \"Run as administrator\".\n");
#elif defined HAVE_GETEUID
  if(geteuid()!=0)
  {
    wmove(stdscr,line++,0);
    wprintw(stdscr,"- You may need to be root to have write access.\n");
#if defined(__APPLE__)
    wmove(stdscr,line++,0);
    wprintw(stdscr,"Use the sudo command to launch TestDisk.\n");
#endif
    wmove(stdscr,line++,0);
    wprintw(stdscr,"- Check the OS permission for this file or device.\n");
  }
#endif
#if defined(__APPLE__)
  wmove(stdscr,line++,0);
  wprintw(stdscr,"- No partition from this disk must be mounted:\n");
  wmove(stdscr,line++,0);
  wprintw(stdscr,"Open the Disk Utility (In Finder -> Application -> Utility folder)\n");
  wmove(stdscr,line++,0);
  wprintw(stdscr,"and press Umount button for each volume from this disk\n");
#endif
  wmove(stdscr,line++,0);
  wprintw(stdscr,"- This media may be physically write-protected, check the jumpers.\n");
  car= wmenuSelect_ext(stdscr, 24, INTER_MAIN_Y, INTER_MAIN_X, menuDiskAccess, 10,
      "CQ", MENU_VERT | MENU_VERT_WARN | MENU_BUTTON, &menu,NULL);
  if(car=='c' || car=='C')
    return 0;
  return 1;
}
#endif

int interface_check_disk_access(disk_t *disk_car, char **current_cmd)
{
  if((disk_car->access_mode&TESTDISK_O_RDWR)==TESTDISK_O_RDWR)
    return 0;
  if(*current_cmd!=NULL)
    return 0;
  log_warning("Media is opened in read-only.\n");
  log_flush();
#ifdef HAVE_NCURSES
  return interface_check_disk_access_ncurses(disk_car);
#else
  return 0;
#endif
}