summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2009-05-05 13:05:49 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2009-05-05 13:05:49 +0200
commit8a36ff31fdfeee2ddbb3004f9157de7c3dbb42e4 (patch)
treea44bbacaa305814b550918f3eb8a39beaae65dc1
parent7dde9f483c155f9c69180ce20abef78fdae87d7d (diff)
move autoset_unit() to a separate file
-rw-r--r--src/Makefile.am4
-rw-r--r--src/autoset.c44
-rw-r--r--src/autoset.h23
-rw-r--r--src/chgtypen.c1
-rw-r--r--src/geometry.c1
-rw-r--r--src/hdaccess.c40
-rw-r--r--src/hdaccess.h1
-rw-r--r--src/intrfn.c9
-rw-r--r--src/tdisksel.c1
-rw-r--r--src/testdisk.c4
10 files changed, 94 insertions, 34 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 32d101f..0369b16 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -13,8 +13,8 @@ endif
sbin_PROGRAMS = testdisk photorec $(QPHOTOREC)
EXTRA_PROGRAMS = fidentify
-base_C = common.c crc.c ewf.c fnctdsk.c hdaccess.c hdcache.c hdwin32.c hidden.c hpa_dco.c intrf.c log.c log_part.c misc.c msdos.c parti386.c partgpt.c partmac.c partsun.c partnone.c partxbox.c io_redir.c ntfs_io.c ntfs_utl.c partauto.c sudo.c unicode.c win32.c
-base_H = alignio.h common.h crc.h ewf.h fnctdsk.h hdaccess.h hdwin32.h hidden.h guid_cmp.h guid_cpy.h hdcache.h hpa_dco.h intrf.h lang.h log.h log_part.h misc.h types.h io_redir.h msdos.h ntfs_utl.h parti386.h partgpt.h partmac.h partsun.h partxbox.h partauto.h sudo.h unicode.h win32.h
+base_C = autoset.c common.c crc.c ewf.c fnctdsk.c hdaccess.c hdcache.c hdwin32.c hidden.c hpa_dco.c intrf.c log.c log_part.c misc.c msdos.c parti386.c partgpt.c partmac.c partsun.c partnone.c partxbox.c io_redir.c ntfs_io.c ntfs_utl.c partauto.c sudo.c unicode.c win32.c
+base_H = alignio.h autoset.h common.h crc.h ewf.h fnctdsk.h hdaccess.h hdwin32.h hidden.h guid_cmp.h guid_cpy.h hdcache.h hpa_dco.h intrf.h lang.h log.h log_part.h misc.h types.h io_redir.h msdos.h ntfs_utl.h parti386.h partgpt.h partmac.h partsun.h partxbox.h partauto.h sudo.h unicode.h win32.h
fs_C = analyse.c bfs.c bsd.c cramfs.c exfat.c fat.c fatx.c ext2.c jfs.c hfs.c hfsp.c hpfs.c luks.c lvm.c md.c netware.c ntfs.c rfs.c savehdr.c sun.c swap.c sysv.c ufs.c xfs.c
fs_H = analyse.h bfs.h bsd.h cramfs.h exfat.h fat.h fatx.h ext2.h jfs_superblock.h jfs.h hfs.h hfsp.h hpfs.h luks.h lvm.h md.h netware.h ntfs.h rfs.h savehdr.h sun.h swap.h sysv.h ufs.h xfs.h
diff --git a/src/autoset.c b/src/autoset.c
new file mode 100644
index 0000000..e12ea7e
--- /dev/null
+++ b/src/autoset.c
@@ -0,0 +1,44 @@
+/*
+
+ File: autoset.c
+
+ Copyright (C) 2009 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 <stdio.h>
+#include "types.h"
+#include "common.h"
+#include "autoset.h"
+
+extern const arch_fnct_t arch_gpt;
+extern const arch_fnct_t arch_mac;
+
+void autoset_unit(disk_t *disk)
+{
+ if(disk==NULL)
+ return ;
+ if(
+ disk->arch==&arch_mac ||
+ disk->arch==&arch_gpt ||
+ (disk->geom.heads_per_cylinder==1 && disk->geom.sectors_per_head==1))
+ disk->unit=UNIT_SECTOR;
+ else
+ disk->unit=UNIT_CHS;
+}
diff --git a/src/autoset.h b/src/autoset.h
new file mode 100644
index 0000000..8f9e150
--- /dev/null
+++ b/src/autoset.h
@@ -0,0 +1,23 @@
+/*
+
+ File: autoset.h
+
+ Copyright (C) 2009 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.
+
+ */
+void autoset_unit(disk_t *disk_car);
+
diff --git a/src/chgtypen.c b/src/chgtypen.c
index b28d68e..6c4f013 100644
--- a/src/chgtypen.c
+++ b/src/chgtypen.c
@@ -43,6 +43,7 @@
#include "guid_cpy.h"
#include "partgpt.h"
#include "hdaccess.h"
+#include "autoset.h"
extern const arch_fnct_t arch_gpt;
extern const arch_fnct_t arch_i386;
diff --git a/src/geometry.c b/src/geometry.c
index 4193c78..4900729 100644
--- a/src/geometry.c
+++ b/src/geometry.c
@@ -40,6 +40,7 @@
#include "log.h"
#include "hdaccess.h"
#include "geometry.h"
+#include "autoset.h"
static inline void set_cylinders_from_size_up(disk_t *disk_car)
{
diff --git a/src/hdaccess.c b/src/hdaccess.c
index 61519e7..305b2f0 100644
--- a/src/hdaccess.c
+++ b/src/hdaccess.c
@@ -108,9 +108,6 @@
#include "alignio.h"
#include "hpa_dco.h"
-extern const arch_fnct_t arch_gpt;
-extern const arch_fnct_t arch_mac;
-
struct info_file_struct
{
int handle;
@@ -792,21 +789,24 @@ static char* strip_name(char* str)
/* This function reads the /sys entry named "file" for device "disk_car". */
static char * read_device_sysfs_file (const disk_t *disk_car, const char *file)
{
- FILE *f;
- char name_buf[128];
- char buf[256];
+ FILE *f;
+ char name_buf[128];
+ char buf[256];
- snprintf (name_buf, 127, "/sys/block/%s/device/%s",
- basename (disk_car->device), file);
+ snprintf (name_buf, 127, "/sys/block/%s/device/%s",
+ basename (disk_car->device), file);
- if ((f = fopen (name_buf, "r")) == NULL)
- return NULL;
+ if ((f = fopen (name_buf, "r")) == NULL)
+ return NULL;
- if (fgets (buf, 255, f) == NULL)
- return NULL;
+ if (fgets (buf, 255, f) == NULL)
+ {
+ fclose (f);
+ return NULL;
+ }
- fclose (f);
- return strip_name (buf);
+ fclose (f);
+ return strip_name (buf);
}
#endif
@@ -1540,18 +1540,6 @@ void hd_update_all_geometry(const list_disk_t * list_disk, const int allow_parti
hd_update_geometry(element_disk->disk,allow_partial_last_cylinder,verbose);
}
-void autoset_unit(disk_t *disk_car)
-{
- if(disk_car==NULL)
- return ;
- if(disk_car->arch==&arch_mac ||
- disk_car->arch==&arch_gpt ||
- (disk_car->geom.heads_per_cylinder==1 && disk_car->geom.sectors_per_head==1))
- disk_car->unit=UNIT_SECTOR;
- else
- disk_car->unit=UNIT_CHS;
-}
-
void init_disk(disk_t *disk)
{
disk->autodetect=0;
diff --git a/src/hdaccess.h b/src/hdaccess.h
index fd7a8dc..31851d5 100644
--- a/src/hdaccess.h
+++ b/src/hdaccess.h
@@ -28,7 +28,6 @@ void hd_update_geometry(disk_t *disk_car, const int allow_partial_last_cylinder,
void hd_update_all_geometry(const list_disk_t * list_disk, const int allow_partial_last_cylinder, const int verbose);
list_disk_t *hd_parse(list_disk_t *list_disk, const int verbose, const arch_fnct_t *arch, const int testdisk_mode);
disk_t *file_test_availability(const char *device, const int verbose, const arch_fnct_t *arch, const int testdisk_mode);
-void autoset_unit(disk_t *disk_car);
void update_disk_car_fields(disk_t *disk_car);
void init_disk(disk_t *disk);
int generic_clean(disk_t *disk_car);
diff --git a/src/intrfn.c b/src/intrfn.c
index d42ad84..6250339 100644
--- a/src/intrfn.c
+++ b/src/intrfn.c
@@ -63,6 +63,7 @@
#include "dir.h"
#include "log.h"
#include "hdaccess.h"
+#include "autoset.h"
extern const arch_fnct_t arch_i386;
extern const arch_fnct_t arch_gpt;
@@ -491,9 +492,7 @@ void dump_ncurses(const void *nom_dump, unsigned int lng)
void dump(WINDOW *window, const void *nom_dump,unsigned int lng)
{
- unsigned int i,j;
unsigned int nbr_line;
- unsigned char car;
unsigned int pos=0;
int done=0;
unsigned int menu=2; /* default : quit */
@@ -515,6 +514,8 @@ void dump(WINDOW *window, const void *nom_dump,unsigned int lng)
/* On pourrait utiliser wscrl */
do
{
+ unsigned char car;
+ unsigned int i,j;
for (i=pos; (i<nbr_line)&&((i-pos)<DUMP_MAX_LINES); i++)
{
wmove(window,DUMP_Y+i-pos,DUMP_X);
@@ -600,7 +601,6 @@ void dump(WINDOW *window, const void *nom_dump,unsigned int lng)
void dump2(WINDOW *window, const void *dump_1, const void *dump_2, const unsigned int lng)
{
- unsigned int i,j;
unsigned int nbr_line;
unsigned int pos=0;
int done=0;
@@ -621,6 +621,7 @@ void dump2(WINDOW *window, const void *dump_1, const void *dump_2, const unsigne
}
do
{
+ unsigned int i,j;
for (i=pos; (i<nbr_line)&&((i-pos)<DUMP_MAX_LINES); i++)
{
wmove(window,DUMP_Y+i-pos,DUMP_X);
@@ -764,7 +765,6 @@ int screen_buffer_display(WINDOW *window, const char *options_org, const struct
#define INTER_MAX_LINES (INTER_ANALYSE_MENU_Y-INTER_ANALYSE_Y-2)
int screen_buffer_display_ext(WINDOW *window, const char *options_org, const struct MenuItem *menuItems, unsigned int *menu)
{
- int i;
int first_line_to_display=0;
int current_line=0;
int done=0;
@@ -785,6 +785,7 @@ int screen_buffer_display_ext(WINDOW *window, const char *options_org, const str
/* curses interface */
do
{
+ int i;
int key;
wmove(window, INTER_ANALYSE_Y-1, INTER_ANALYSE_X+4);
wclrtoeol(window);
diff --git a/src/tdisksel.c b/src/tdisksel.c
index 940a2a1..40755de 100644
--- a/src/tdisksel.c
+++ b/src/tdisksel.c
@@ -48,6 +48,7 @@
#include "hiddenn.h"
#include "nodisk.h"
#include "chgtypen.h"
+#include "autoset.h"
#ifdef HAVE_NCURSES
#define NBR_DISK_MAX (LINES-6-8)
diff --git a/src/testdisk.c b/src/testdisk.c
index 7cf40c6..bde56a2 100644
--- a/src/testdisk.c
+++ b/src/testdisk.c
@@ -64,6 +64,7 @@
#include "misc.h"
#include "tdisksel.h"
#include "tlog.h"
+#include "autoset.h"
extern const arch_fnct_t arch_i386;
extern const arch_fnct_t arch_mac;
@@ -164,7 +165,8 @@ int main( int argc, char **argv )
else if((strcmp(argv[i],"/direct")==0) || (strcmp(argv[i],"-direct")==0))
testdisk_mode|=TESTDISK_O_DIRECT;
else if((strcmp(argv[i],"/help")==0) || (strcmp(argv[i],"-help")==0) || (strcmp(argv[i],"--help")==0) ||
- (strcmp(argv[i],"/h")==0) || (strcmp(argv[i],"-h")==0))
+ (strcmp(argv[i],"/h")==0) || (strcmp(argv[i],"-h")==0) ||
+ (strcmp(argv[i],"/?")==0) || (strcmp(argv[i],"-?")==0))
help=1;
else if((strcmp(argv[i],"/version")==0) || (strcmp(argv[i],"-version")==0) || (strcmp(argv[i],"--version")==0) ||
(strcmp(argv[i],"/v")==0) || (strcmp(argv[i],"-v")==0))