CHDK_DE Vorschauversion  Trunk Rev. 5573
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
file_shelter.c-Dateireferenz
#include "camera_info.h"
#include "gui.h"
#include "gui_draw.h"
#include "meminfo.h"
#include "module_load.h"
#include "simple_module.h"
#include "clock.h"
#include "console.h"
#include "conf.h"
#include "sd_card.h"
#include "cachebit.h"
#include "gui_mbox.h"
#include "keyboard.h"
#include "stdlib.h"
+ Include-Abhängigkeitsdiagramm für file_shelter.c:

gehe zum Quellcode dieser Datei

Datenstrukturen

struct  fs_dirent
 
struct  fs_fheader
 

Makrodefinitionen

#define FSCRC_CALC   1
 
#define MAX_PATH_LEN   100
 
#define FMAGIC   0x004c4946
 
#define DMAGIC   0x00524944
 

Aufzählungen

enum  rstatus { RS_OK = 0, RS_NAMELONG, RS_CRC, RS_FERR }
 

Funktionen

int basic_module_init ()
 
int _run ()
 
int _module_can_unload ()
 
int _module_exit_alt ()
 
unsigned long crc32_for_byte (unsigned long r)
 
void crc32 (const void *data, unsigned long n_bytes, unsigned long *crc)
 
int read_file_f (char *fn, void *buf, int size)
 
int read_file_o (char *fn, void *buf, int size)
 
int compute_file_crc_f (char *fn, void *buf, int size, int bufsize, unsigned long *crc)
 
int compute_file_crc_o (char *fn, void *buf, int size, int bufsize, unsigned long *crc)
 
int write_file_f (char *fn, void *buf, int size)
 
int write_file_o (char *fn, void *buf, int size)
 
int read_file (char *fn, void *buf, int size)
 
int write_file (char *fn, void *buf, int size)
 
int compute_file_crc (char *fn, void *buf, int size, int bufsize, unsigned long *crc)
 
int strcasecmp (const char *s1, const char *s2)
 
long mkdir_if_not_exist (const char *dirname)
 
static int is_parent (const char *name)
 
static int is_current (const char *name)
 
static int fs_readdir (DIR *d, fs_dirent *de, const char *path)
 
static void process_dir (const char *parent, const char *name, int nested, void(*file_process)(const char *path, const char *file, fs_dirent *de), void(*dir_process)(const char *path, fs_dirent *de))
 
unsigned wordpad (unsigned u)
 
int is_valid_stptr (void *p)
 
int iswhitelisted (const char *name)
 
int get_next_object (unsigned long magic, void **currptr)
 
char * get_object_name (void *p)
 
char * get_object_data (void *p)
 
void fproc_totalsize (const char *path, const char *file, fs_dirent *de)
 
void dproc_count (const char *path, fs_dirent *de)
 
void dproc_store (const char *path, fs_dirent *de)
 
void fproc_store (const char *path, const char *file, fs_dirent *de)
 
void alloc_storage ()
 
int restore (const char *dest, int test)
 
int can_boot_from_fat32 ()
 
void gui_fileshelter_menu_kbd_process ()
 
int gui_fileshelter_kbd_process ()
 
void gui_fileshelter_draw ()
 

Variablen

static int running = 0
 
static char osdbuf [128]
 
libsimple_sym _librun
 
ModuleInfo _module_info
 
static int use_open_rather_than_fopen = 1
 
const char * rsshumanL []
 
const char * wl1 [] = {"DISKBOOT.BIN", "PS.FIR", "PS.FI2", 0}
 
static void * whitelist = 0
 
static unsigned storageneed = 0
 
static unsigned filecount = 0
 
static unsigned failcount = 0
 
static unsigned dircount = 0
 
static unsigned tfilecount = 0
 
static unsigned tdircount = 0
 
static unsigned fileprocd = 0
 
static unsigned dirprocd = 0
 
static void * starea = 0
 
static unsigned stmax = 0
 
static void * tmpbuf = 0
 
const unsigned tmpsiz = 32768
 
static void * storptr = 0
 
static unsigned long stcrc = 0
 
char * help1 []
 
char * help_partwarn = "Do NOT format, card will lose partitions!"
 
char * help_bootwarn = "Card will lose autoboot if formatted!"
 
gui_handler GUI_MODE_FILESHELTER
 
static unsigned int cardsize
 
static int canfat32boot
 
static int partcount
 
static int noformatyet
 
static int fileshelter_mode = 0
 
static unsigned disph = 0
 
static unsigned dispw = 0
 
static unsigned helph = 0
 
static unsigned restore_status
 
static unsigned scrolly
 
static int fileshelter_redraw
 
gui_handlerfileshelter_old_guimode
 

Makro-Dokumentation

#define DMAGIC   0x00524944

Definiert in Zeile 429 der Datei file_shelter.c.

#define FMAGIC   0x004c4946

Definiert in Zeile 428 der Datei file_shelter.c.

#define FSCRC_CALC   1

Definiert in Zeile 14 der Datei file_shelter.c.

#define MAX_PATH_LEN   100

Definiert in Zeile 16 der Datei file_shelter.c.

Dokumentation der Aufzählungstypen

enum rstatus
Aufzählungswerte
RS_OK 
RS_NAMELONG 
RS_CRC 
RS_FERR 

Definiert in Zeile 431 der Datei file_shelter.c.

431  {
432  RS_OK = 0,
433  RS_NAMELONG,
434  RS_CRC,
435  RS_FERR,
436 };

Dokumentation der Funktionen

int _module_can_unload ( )

Definiert in Zeile 36 der Datei file_shelter.c.

37 {
38  return (running==0);
39 }
int _module_exit_alt ( )

Definiert in Zeile 41 der Datei file_shelter.c.

42 {
43  //running = 0;
44  return 0;
45 }
int _run ( )

Definiert in Zeile 29 der Datei file_shelter.c.

30 {
32 
33  return 0;
34 }
void alloc_storage ( )

Definiert in Zeile 629 der Datei file_shelter.c.

630 {
631  const char *exmemtypes[] = {"EXMEM_FIRMUP", "EXMEM_FAMODE", 0};
632  const unsigned cushion = 128; // extra data to allocate (for eventual cached use)
633  unsigned n, i;
634  exmem_alloc_info ai;
635  storageneed += sizeof(fs_fheader); // for the last entry
636  storageneed += tmpsiz; // for temp buffer
637  starea = 0;
638  i = 0;
639  while (exmemtypes[i]) {
640  for (n=0; n<exmem_type_count; n++) {
641  if (strncmp(exmemtypes[i],get_exmem_type_name(n),strlen(exmemtypes[i]))==0) {
642  get_exmem_type_status(n, &ai);
643  if (!ai.len) {
644  starea = exmem_alloc_uncached(n, storageneed+cushion, 0);
645  get_exmem_type_status(n, &ai);
646  if (ai.len-cushion < storageneed) {
647  starea = 0;
649  char buf[64];
650  sprintf(buf,"%s need %x got %x",exmemtypes[i],storageneed,ai.len);
651  console_add_line(buf);
652  }
653 #if 1
654  else {
655  char buf[64];
656  sprintf(buf,"%s adr %x",exmemtypes[i],starea);
657  console_add_line(buf);
658  }
659 #endif
660  }
661  break;
662  }
663  }
664  if (starea) {
665  starea += cushion/2; // leave a safety border on both start and end of allocation
667  tmpbuf = starea + stmax;
668  storptr = starea;
669  break;
670  }
671  i++;
672  }
673 }
int basic_module_init ( )
int can_boot_from_fat32 ( )

Definiert in Zeile 803 der Datei file_shelter.c.

804 {
805  if (conf.platformid > 0x3222) { // r47+
806  return 1;
807  }
808  return 0;
809 }
int compute_file_crc ( char *  fn,
void *  buf,
int  size,
int  bufsize,
unsigned long *  crc 
)

Definiert in Zeile 254 der Datei file_shelter.c.

255 {
257  return compute_file_crc_o(fn, buf, size, bufsize, crc);
258  }
259  return compute_file_crc_f(fn, buf, size, bufsize, crc);
260 }
int compute_file_crc_f ( char *  fn,
void *  buf,
int  size,
int  bufsize,
unsigned long *  crc 
)

Definiert in Zeile 142 der Datei file_shelter.c.

143 {
144  int ret = 0;
145  if (!fn || !buf || !crc || !bufsize) {
146  return -1;
147  }
148  FILE *fd = fopen(fn, "r+b");
149  if (fd) {
150  long chunk = bufsize<size?bufsize:size;
151  while (1) {
152  long r = fread(buf, 1, chunk, fd);
153  if (r != chunk) {
154  if (r != size) {
155  ret = 1;
156  break;
157  }
158  }
159  crc32(buf, r, crc);
160  size -= r;
161  if (size <= 0) {
162  break;
163  }
164  }
165  fclose(fd);
166  }
167  return ret;
168 }
int compute_file_crc_o ( char *  fn,
void *  buf,
int  size,
int  bufsize,
unsigned long *  crc 
)

Definiert in Zeile 170 der Datei file_shelter.c.

171 {
172  int ret = 0;
173  if (!fn || !buf || !crc || !bufsize) {
174  return -1;
175  }
176  int fd = open(fn, O_RDONLY, 0777);
177  if (fd >= 0) {
178  long chunk = bufsize<size?bufsize:size;
179  while (1) {
180  long r = read(fd, buf, chunk);
181  if (r != chunk) {
182  if (r != size) {
183  ret = 1;
184  break;
185  }
186  }
187  crc32(buf, r, crc);
188  size -= r;
189  if (size <= 0) {
190  break;
191  }
192  }
193  close(fd);
194  }
195  return ret;
196 }
void crc32 ( const void *  data,
unsigned long  n_bytes,
unsigned long *  crc 
)

Definiert in Zeile 89 der Datei file_shelter.c.

89  {
90  static unsigned long ct[0x100] = {0};
91  unsigned long i;
92  if (!ct[0]) {
93  for (i = 0; i < 0x100; i++) {
94  ct[i] = crc32_for_byte(i);
95  }
96  }
97  for (i = 0; i < n_bytes; i++) {
98  *crc = ct[(unsigned char)*crc ^ ((unsigned char*)data)[i]] ^ *crc >> 8;
99  }
100 }
unsigned long crc32_for_byte ( unsigned long  r)

Definiert in Zeile 81 der Datei file_shelter.c.

81  {
82  unsigned long j;
83  for (j = 0; j < 8; j++) {
84  r = (r & 1? 0: (unsigned long)0xEDB88320) ^ r >> 1;
85  }
86  return r ^ (unsigned long)0xFF000000;
87 }
void dproc_count ( const char *  path,
fs_dirent de 
)

Definiert in Zeile 574 der Datei file_shelter.c.

575 {
576  if (whitelist && !iswhitelisted(path)) return;
577  storageneed += wordpad(strlen(path) + 1);
578  storageneed += sizeof(fs_fheader);
579  dircount += 1;
580 }
void dproc_store ( const char *  path,
fs_dirent de 
)

Definiert in Zeile 583 der Datei file_shelter.c.

584 {
585  if (whitelist && !iswhitelisted(path)) return;
586  fs_fheader *fh = storptr;
587  fh->magic = DMAGIC;
588  fh->size = 0;
589  fh->mtime = de->mtime;
590  fh->nlen = strlen(path) + 1;
591  fh->crc = 0;
592  storptr += sizeof(fs_fheader);
593  strcpy(storptr, path);
594  storptr += wordpad(fh->nlen);
595  dirprocd++;
596 }
void fproc_store ( const char *  path,
const char *  file,
fs_dirent de 
)

Definiert in Zeile 599 der Datei file_shelter.c.

600 {
601  if (whitelist && !iswhitelisted(file)) return;
602  fs_fheader *fh = storptr;
603  fh->magic = FMAGIC;
604  fh->size = de->size;
605  fh->mtime = de->mtime;
606  fh->nlen = strlen(path) + 1 + strlen(file) + 1;
607  fh->crc = 0;
608  storptr += sizeof(fs_fheader);
609  sprintf(storptr, "%s%s%s", path, path[strlen(path)-1]=='/'?"":"/", file);
610  char *name = storptr;
611  storptr += wordpad(fh->nlen);
612 
613  if ( read_file(name, storptr, fh->size) ) {
614  failcount++;
615  storptr -= sizeof(fs_fheader);
616  storptr -= wordpad(fh->nlen);
617  console_add_line(file);
618  }
619  else {
620  crc32(storptr, fh->size, &fh->crc); // fh->crc is set to zero prior to this
621  storptr += wordpad(fh->size);
622  fileprocd++;
623  }
624 }
void fproc_totalsize ( const char *  path,
const char *  file,
fs_dirent de 
)

Definiert in Zeile 564 der Datei file_shelter.c.

565 {
566  if (whitelist && !iswhitelisted(file)) return;
567  storageneed += wordpad(de->size);
568  storageneed += wordpad(strlen(path) + 1 + strlen(file) + 1);
569  storageneed += sizeof(fs_fheader);
570  filecount += 1;
571 }
static int fs_readdir ( DIR d,
fs_dirent de,
const char *  path 
)
static

Definiert in Zeile 313 der Datei file_shelter.c.

314 {
315  char pbuf[MAX_PATH_LEN];
316 
317  de->de = readdir(d);
318  de->size = 0;
319  de->mtime = 0;
320  de->deleted = 0;
321  de->isparent = 0;
322  de->iscurrent = 0;
323  de->isdir = 0;
324  de->isvalid = 0;
325  de->ishidden = 0;
326 
327  if (de->de)
328  {
329  if (de->de->d_name[0] == 0xE5)
330  {
331  de->deleted = 1;
332  }
333  else
334  {
335  de->isparent = is_parent(de->de->d_name);
336  de->iscurrent = is_current(de->de->d_name);
337 
338  sprintf(pbuf, "%s%s%s", path, path[strlen(path)-1]=='/'?"":"/", de->de->d_name);
339  struct stat st;
340  if (de->isparent || de->iscurrent)
341  {
342  de->isdir = 1;
343  de->isvalid = 1;
344  }
345  else if (stat(pbuf, &st) == 0)
346  {
347  de->size = st.st_size;
348  de->mtime = st.st_mtime;
349  de->isvalid = 1;
350  de->isdir = ((st.st_attrib & DOS_ATTR_DIRECTORY) != 0);
351  de->ishidden = ((st.st_attrib & DOS_ATTR_HIDDEN) != 0);
352  }
353  }
354 
355  return 1;
356  }
357 
358  return 0;
359 }
int get_next_object ( unsigned long  magic,
void **  currptr 
)

Definiert in Zeile 514 der Datei file_shelter.c.

515 {
516  char *p = *currptr;
517  if (!is_valid_stptr(p)) {
518  return 0;
519  }
520  fs_fheader *fh = (void*)p;
521  while (fh->magic==FMAGIC || fh->magic==DMAGIC) {
522  p += sizeof(fs_fheader) + wordpad(fh->nlen) + wordpad(fh->size);
523  if (!is_valid_stptr(p)) {
524  break;
525  }
526  fh = (void*)p;
527  if (!magic || fh->magic == magic) {
528  *currptr = (void*)p;
529  return 1;
530  }
531  }
532  return 0;
533 }
char* get_object_data ( void *  p)

Definiert in Zeile 550 der Datei file_shelter.c.

551 {
552  if (!is_valid_stptr(p)) {
553  return 0;
554  }
555  fs_fheader *fh = p;
556  p += sizeof(fs_fheader) + wordpad(fh->nlen);
557  if (!is_valid_stptr(p) || !is_valid_stptr(p+fh->size)) {
558  return 0;
559  }
560  return (char*)p;
561 }
char* get_object_name ( void *  p)

Definiert in Zeile 536 der Datei file_shelter.c.

537 {
538  if (!is_valid_stptr(p)) {
539  return 0;
540  }
541  fs_fheader *fh = p;
542  p += sizeof(fs_fheader);
543  if (!is_valid_stptr(p) || !is_valid_stptr(p+fh->nlen)) {
544  return 0;
545  }
546  return (char*)p;
547 }
void gui_fileshelter_draw ( )

Definiert in Zeile 1008 der Datei file_shelter.c.

1009 {
1010  static int selfupdate = 0;
1011  static int warnshown = 0;
1012 
1013  int fredraw = fileshelter_redraw;
1014  fileshelter_redraw = 0;
1015 
1016  if (fredraw || selfupdate) {
1017 
1018  if (fredraw == 2)
1019  {
1021  draw_string(camera_screen.disp_left, 0, "CHDK backup & restore utility", MAKE_COLOR(COLOR_WHITE, COLOR_BLACK));
1022  draw_string(camera_screen.disp_left, FONT_HEIGHT, !starea?"SET-backup MENU-exit \x18\x19-help":noformatyet?"SET-check MENU-exit \x18\x19-help":"SET-restore MENU-exit \x18\x19-help", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
1023 
1024 #if 0
1025  if (fileshelter_mode) { // meant to be temporary
1027  }
1028  else {
1030  }
1031 #endif
1032 
1033  fredraw = 4;
1034  selfupdate = 0;
1035  }
1036  if (fredraw == 3)
1037  {
1039  if (tfilecount || tdircount) {
1040  sprintf(osdbuf, "Not restored: %u files, %u dirs", tfilecount, tdircount);
1041  if (sizeof(osdbuf)>dispw) osdbuf[dispw] = 0;
1043  }
1044  unsigned rssl = restore_status & 0xff;
1045  char *hrsm = "???";
1046  if (rssl < sizeof(rsshumanL)/sizeof(char*)) {
1047  hrsm = (char*)rsshumanL[rssl];
1048  }
1049  sprintf(osdbuf, restore_status?"Restore status: %08x":"Restore status:", restore_status);
1051  sprintf(osdbuf, "%s", hrsm);
1053  selfupdate = 0;
1054  }
1055  if (fredraw == 10)
1056  {
1058  if (tfilecount || tdircount) {
1059  sprintf(osdbuf, "Failed: %u files, %u dirs", tfilecount, tdircount);
1060  if (sizeof(osdbuf)>dispw) osdbuf[dispw] = 0;
1062  }
1063  unsigned rssl = restore_status & 0xff;
1064  char *hrsm = "???";
1065  if (rssl < sizeof(rsshumanL)/sizeof(char*)) {
1066  hrsm = (char*)rsshumanL[rssl];
1067  }
1068  sprintf(osdbuf, restore_status?"Test status: %08x":"Test status:", restore_status);
1070  sprintf(osdbuf, "%s", hrsm);
1072  selfupdate = 0;
1073  }
1074  if (fredraw == 1)
1075  {
1077  sprintf(osdbuf, "%u files, %u dirs, total %u bytes", filecount, dircount, storageneed);
1079  if (starea && !failcount) {
1081  }
1082  else if (failcount) {
1083  sprintf(osdbuf, "Backup failed to store %u file(s)", failcount);
1085  draw_string(camera_screen.disp_left, 4*FONT_HEIGHT, "See CHDK console for filename(s)", MAKE_COLOR(COLOR_BLACK, COLOR_YELLOW));
1086  }
1087  else if (!starea) {
1088  draw_string(camera_screen.disp_left, 3*FONT_HEIGHT, "Backup failed - insufficient memory", MAKE_COLOR(COLOR_BLACK, COLOR_RED));
1089  }
1090  else {
1092  }
1093  selfupdate = 0;
1094  }
1095  if (fredraw == 4)
1096  {
1098  unsigned y;
1099  for (y=0; y<helph; y++) {
1100  if (scrolly+y < sizeof(help1)/sizeof(char*)) {
1102  }
1103  }
1104  if (!warnshown) {
1105  warnshown = 1;
1106  fredraw = 9;
1107  }
1108  selfupdate = 0;
1109  }
1110  if (fredraw == 5)
1111  {
1114  selfupdate = 5;
1115  }
1116  if (fredraw == 11)
1117  {
1120  selfupdate = 5;
1121  }
1122  if (fredraw == 6)
1123  {
1126  selfupdate = 6;
1127  }
1128  if (fredraw == 7)
1129  {
1132  selfupdate = 7;
1133  }
1134  if (fredraw == 8)
1135  {
1138  selfupdate = 6;
1139  }
1140  if (fredraw == 9)
1141  {
1143 
1144  // draw card related warnings if any
1145  if (canfat32boot && cardsize>32*1024*1024) {
1147  }
1148  else if (!canfat32boot && cardsize>2*1024*1024) {
1150  }
1151  if (partcount > 1) {
1153  }
1154 
1155  }
1156 
1157  if (selfupdate == 5) {
1158  static unsigned fc=0,dc=0;
1159  if ((tfilecount!=fc) || (tdircount!=dc)) {
1160  sprintf(osdbuf, "Remaining: %u files, %u dirs ", tfilecount, tdircount);
1161  if (sizeof(osdbuf)>dispw) osdbuf[dispw] = 0;
1163  }
1164  fc = tfilecount;
1165  dc = tdircount;
1166  }
1167  else if (selfupdate == 6) {
1168  static int phase = 0;
1169  const char *pc = "/-\\|";
1171  phase++;
1172  }
1173  else if (selfupdate == 7) {
1174  static unsigned fc=0,dc=0;
1175  if ((fileprocd!=fc) || (dirprocd!=dc)) {
1176  sprintf(osdbuf, "Remaining: %u files, %u dirs ", filecount-fileprocd, dircount-dirprocd);
1177  if (sizeof(osdbuf)>dispw) osdbuf[dispw] = 0;
1179  }
1180  fc = fileprocd;
1181  dc = dirprocd;
1182  }
1183 
1184  }
1185 
1186 }
int gui_fileshelter_kbd_process ( )

Definiert in Zeile 870 der Datei file_shelter.c.

871 {
872  switch (kbd_get_autoclicked_key())
873  {
874  case KEY_SET:
875  if (starea) {
876  if (stat("A/CHDK",0) != 0) {
877  // CHDK dir not found, assuming formatted card
878  unsigned long crc = 0;
881  fileshelter_redraw = 8;
882  msleep(100); // give the display a chance to update
883  crc32(starea, stmax, &crc);
884  if (crc == stcrc) {
885  fileshelter_redraw = 5;
886  restore_status = restore("A",0);
887  fileshelter_redraw = 3;
888  }
889  else {
890  restore_status = 4;
891  fileshelter_redraw = 3;
892  }
893  }
894  else {
895  // CHDK dir present, doing a test run only
896  unsigned long crc = 0;
899  fileshelter_redraw = 8;
900  msleep(100); // give the display a chance to update
901  crc32(starea, stmax, &crc);
902  if (crc == stcrc) {
903  fileshelter_redraw = 11;
904  restore_status = restore("A",1);
905  fileshelter_redraw = 10;
906  }
907  else {
908  restore_status = 4;
909  fileshelter_redraw = 10;
910  }
911  }
912  }
913  else {
914  fileshelter_redraw = 6;
915  storageneed = 0;
916  filecount = 0;
917  dircount = 0;
918  whitelist = wl1;
920  whitelist = 0;
921  process_dir("A/CHDK", 0, 999, fproc_totalsize, dproc_count);
922  alloc_storage();
923  if (starea) {
924  fileshelter_redraw = 7;
925  failcount = 0;
926  fileprocd = 0;
927  dirprocd = 0;
928  whitelist = wl1;
929  process_dir("A/", 0, 0, fproc_store, dproc_store);
930  whitelist = 0;
931  process_dir("A/CHDK", 0, 999, fproc_store, dproc_store);
932  fs_fheader *fh = storptr;
933  fh->magic = 0;
934  stcrc = 0;
935  crc32(starea, stmax, &stcrc);
936  }
937  fileshelter_redraw = 1;
938  }
939  break;
940  case KEY_DOWN:
941  if (scrolly < sizeof(help1)/sizeof(char*)-1) {
942  scrolly++;
943  }
944  else {
945  scrolly = 0;
946  }
947  fileshelter_redraw = 4;
948  break;
949  case KEY_UP:
950  if (scrolly > 0) {
951  scrolly--;
952  }
953  else {
954  scrolly = sizeof(help1)/sizeof(char*)-1;
955  }
956  fileshelter_redraw = 4;
957  break;
958  case KEY_SHOOT_HALF:
960 #if 0
961  if (fileshelter_mode) {
963  }
964  else {
966  }
967 #endif
968  fileshelter_redraw = 2;
969  break;
970  }
971  return 0;
972 }
void gui_fileshelter_menu_kbd_process ( )

Definiert in Zeile 999 der Datei file_shelter.c.

1000 {
1001  if (!starea) {
1002  running = 0;
1003  }
1004 
1006 }
static int is_current ( const char *  name)
static

Definiert in Zeile 308 der Datei file_shelter.c.

308 { return (strcmp(name, ".") == 0); }
static int is_parent ( const char *  name)
static

Definiert in Zeile 307 der Datei file_shelter.c.

307 { return (strcmp(name, "..") == 0); }
int is_valid_stptr ( void *  p)

Definiert in Zeile 484 der Datei file_shelter.c.

485 {
486  if (p>starea+stmax-sizeof(fs_fheader) || p<starea) {
487  return 0;
488  }
489  return 1;
490 }
int iswhitelisted ( const char *  name)

Definiert in Zeile 495 der Datei file_shelter.c.

496 {
497  if (whitelist == 0) {
498  return 1;
499  }
500  char **wl = whitelist;
501  char *s = *wl;
502  while (s) {
503  if (strcasecmp(name, s) == 0) {
504  return 1;
505  }
506  s = *(++wl);
507  }
508  return 0;
509 }
long mkdir_if_not_exist ( const char *  dirname)

Definiert in Zeile 283 der Datei file_shelter.c.

284 {
285  // Check if directory exists and create it if it does not.
286  if (stat(dirname,0) != 0) return mkdir(dirname);
287  return 0; // Success
288 }
static void process_dir ( const char *  parent,
const char *  name,
int  nested,
void(*)(const char *path, const char *file, fs_dirent *de)  file_process,
void(*)(const char *path, fs_dirent *de)  dir_process 
)
static

Definiert in Zeile 365 der Datei file_shelter.c.

366 {
367  DIR *d;
368  fs_dirent de;
369 
370  // Get full name
371  char *path;
372  if (name)
373  {
374  path = malloc(strlen(parent) + strlen(name) + 2);
375  sprintf(path, "%s%s%s", parent, parent[strlen(parent)-1]=='/'?"":"/", name);
376  }
377  else
378  {
379  path = (char*)parent;
380  }
381 
382  // Open directory
384 
385  if (d)
386  {
387  // let caller get the dir name first
388  if (dir_process)
389  dir_process(path, &de);
390 
391  // Process contents
392  while (fs_readdir(d, &de, path))
393  {
394  if (!de.deleted)
395  {
396  // Sub directory? Process recursively (but only 'nested' level deep)
397  if (de.isdir)
398  {
399  if (!de.isparent && !de.iscurrent && nested)
400  process_dir(path, de.de->d_name, nested-1, file_process, dir_process);
401  }
402  else if (file_process)
403  {
404  file_process(path, de.de->d_name, &de);
405  }
406  }
407  }
408  closedir(d);
409 
410  }
411 
412  if (name)
413  free(path);
414 }
int read_file ( char *  fn,
void *  buf,
int  size 
)

Definiert in Zeile 234 der Datei file_shelter.c.

235 {
237  return read_file_o(fn, buf, size);
238  }
239  return read_file_f(fn, buf, size);
240 }
int read_file_f ( char *  fn,
void *  buf,
int  size 
)

Definiert in Zeile 108 der Datei file_shelter.c.

109 {
110  int ret = -1;
111  FILE *fd = fopen(fn, "r+b");
112  if (fd) {
113  ret = fread(buf, 1, size, fd);
114  fclose(fd);
115  if (ret == size) {
116  ret = 0;
117  }
118  else {
119  ret = 1;
120  }
121  }
122  return ret;
123 }
int read_file_o ( char *  fn,
void *  buf,
int  size 
)

Definiert in Zeile 125 der Datei file_shelter.c.

126 {
127  int ret = -1;
128  int fd = open(fn, O_RDONLY, 0777);
129  if (fd >= 0) {
130  ret = read(fd, buf, size);
131  close(fd);
132  if (ret == size) {
133  ret = 0;
134  }
135  else {
136  ret = 1;
137  }
138  }
139  return ret;
140 }
int restore ( const char *  dest,
int  test 
)

Definiert in Zeile 678 der Datei file_shelter.c.

679 {
680  char buf[256];
681  int ret = 0;
682  if (!starea) {
683  return 1;
684  }
685  if (!test && strlen(dest)>2) mkdir_if_not_exist(dest);
686  storptr = starea;
687  if (!is_valid_stptr(storptr)) {
688  return 2;
689  }
690  fs_fheader *fh = storptr;
691  while (1) {
692  if (fh->magic==DMAGIC) {
693  char *lastdir = get_object_name(storptr);
694  lastdir += 2; // chop off A/
695  if (strlen(dest)+1+strlen(lastdir) > 255) {
696  fh->status = RS_NAMELONG;
697  ret |= 0x40000000;
698  if (!get_next_object(0, &storptr)) {
699  break;
700  }
701  continue;
702  }
703  sprintf(buf,"%s/%s",dest,lastdir);
704  if (!test) {
705  ret |= mkdir_if_not_exist(buf)?0x20000000:0;
706  if (stat(buf,0) == 0) {
707  tdircount--;
708  }
709  }
710  else {
711  msleep(10);
712  tdircount--;
713  }
714  }
715  else if (fh->magic==FMAGIC) {
716  if (strlen(dest)+1+fh->nlen-2 > 255) {
717  fh->status = RS_NAMELONG;
718  ret |= 0x40000000;
719  if (!get_next_object(0, &storptr)) {
720  break;
721  }
722  continue;
723  }
724  unsigned long crc = 0;
725  char *fn = get_object_name(storptr);
726  if (fn) {
727  fn +=2; // chop off A/
728  }
729  else {
730  return ret + 3;
731  }
732  char *fd = get_object_data(storptr);
733  if (fd) {
734  crc32(fd, fh->size, &crc); // crc is set to zero prior to this
735  if (crc != fh->crc) {
736  fh->status = RS_CRC;
737  ret |= 0x10000000;
738  if (!get_next_object(0, &storptr)) {
739  break;
740  }
741  continue;
742  }
743  }
744  sprintf(buf,"%s/%s",dest,fn);
745  if (!test) {
746 
747  if ( write_file(buf, fd, fh->size) ) {
748  console_add_line(fn);
749  fh->status = RS_FERR;
750  ret |= 0x08000000;
751  }
752  else {
753 #if (FSCRC_CALC == 1)
754  crc = 0;
755  if ( compute_file_crc(buf, tmpbuf, fh->size, tmpsiz, &crc) ) {
756  console_add_line(fn);
757  fh->status = RS_FERR;
758  ret |= 0x04000000;
759  }
760  else {
761  if ( fh->crc != crc) {
762  console_add_line(fn);
763  fh->status = RS_FERR;
764  ret |= 0x02000000;
765  }
766  else {
767  struct utimbuf t;
768  t.actime = t.modtime = fh->mtime;
769  utime(buf, &t);
770  tfilecount--;
771  }
772  }
773 #else // (FSCRC_CALC != 1)
774  struct utimbuf t;
775  t.actime = t.modtime = fh->mtime;
776  utime(buf, &t);
777  tfilecount--;
778 #endif
779  }
780 
781  }
782  else {
783  msleep(10);
784  tfilecount--;
785  }
786  }
787  else {
788  break;
789  }
790 
791  // advance pointer, error out if impossible
792  if (!get_next_object(0, &storptr)) {
793  ret += 4;
794  break;
795  }
796  fh = storptr;
797  }
798  return ret;
799 }
int strcasecmp ( const char *  s1,
const char *  s2 
)

Definiert in Zeile 266 der Datei file_shelter.c.

267 {
268  const unsigned char *p1 = (const unsigned char *) s1;
269  const unsigned char *p2 = (const unsigned char *) s2;
270  int result;
271  if (p1 == p2)
272  return 0;
273  while ((result = tolower(*p1) - tolower(*p2++)) == 0)
274  if (*p1++ == '\0')
275  break;
276  return result;
277 }
unsigned wordpad ( unsigned  u)

Definiert in Zeile 478 der Datei file_shelter.c.

479 {
480  return (u + 3) & 0xfffffffc;
481 }
int write_file ( char *  fn,
void *  buf,
int  size 
)

Definiert in Zeile 244 der Datei file_shelter.c.

245 {
247  return write_file_o(fn, buf, size);
248  }
249  return write_file_f(fn, buf, size);
250 }
int write_file_f ( char *  fn,
void *  buf,
int  size 
)

Definiert in Zeile 198 der Datei file_shelter.c.

199 {
200  int ret = -1;
201  FILE *fd = fopen(fn, "w+b");
202  if (fd) {
203  ret = fwrite(buf, 1, size, fd);
204  fclose(fd);
205  if (ret == size) {
206  ret = 0;
207  }
208  else {
209  ret = 1;
210  }
211  }
212  return ret;
213 }
int write_file_o ( char *  fn,
void *  buf,
int  size 
)

Definiert in Zeile 215 der Datei file_shelter.c.

216 {
217  int ret = -1;
218  int fd = open(fn, O_WRONLY|O_CREAT|O_TRUNC, 0777);
219  if (fd >= 0) {
220  ret = write(fd, buf, size);
221  close(fd);
222  if (ret == size) {
223  ret = 0;
224  }
225  else {
226  ret = 1;
227  }
228  }
229  return ret;
230 }

Variablen-Dokumentation

libsimple_sym _librun
Initialisierung:

Definiert in Zeile 49 der Datei file_shelter.c.

ModuleInfo _module_info
Initialisierung:

Definiert in Zeile 56 der Datei file_shelter.c.

int canfat32boot
static

Definiert in Zeile 859 der Datei file_shelter.c.

unsigned int cardsize
static

Definiert in Zeile 858 der Datei file_shelter.c.

unsigned dircount = 0
static

Definiert in Zeile 466 der Datei file_shelter.c.

unsigned dirprocd = 0
static

Definiert in Zeile 470 der Datei file_shelter.c.

unsigned disph = 0
static

Definiert in Zeile 864 der Datei file_shelter.c.

unsigned dispw = 0
static

Definiert in Zeile 864 der Datei file_shelter.c.

unsigned failcount = 0
static

Definiert in Zeile 465 der Datei file_shelter.c.

unsigned filecount = 0
static

Definiert in Zeile 464 der Datei file_shelter.c.

unsigned fileprocd = 0
static

Definiert in Zeile 469 der Datei file_shelter.c.

int fileshelter_mode = 0
static

Definiert in Zeile 863 der Datei file_shelter.c.

gui_handler* fileshelter_old_guimode

Definiert in Zeile 868 der Datei file_shelter.c.

int fileshelter_redraw
static

Definiert in Zeile 867 der Datei file_shelter.c.

gui_handler GUI_MODE_FILESHELTER
char* help1[]
Initialisierung:
= {
"Utility for temporarily storing CHDK",
"system files in RAM, allowing to format",
"card via Canon menu.",
"Usage:",
"1. Start this utility, press SET to backup",
"2. Leave the utility, format card in Canon",
" menu. Do NOT switch off the camera.",
"3. Start this utility again, press SET",
"4. Make card bootable via CHDK menu",
"5. Restart camera before starting to shoot",
"IMPORTANT",
"Do not format card if you get errors.",
"Only the following files are stored:",
"- Everything in CHDK directory.",
"- DISKBOOT.BIN, PS.FIR, PS.FI2",
"WARNING",
"Excessive amount of data in CHDK direcory",
"may cause a crash while making backup!",
"Do not use this on mission critical files!",
}

Definiert in Zeile 813 der Datei file_shelter.c.

char* help_bootwarn = "Card will lose autoboot if formatted!"

Definiert in Zeile 840 der Datei file_shelter.c.

char* help_partwarn = "Do NOT format, card will lose partitions!"

Definiert in Zeile 839 der Datei file_shelter.c.

unsigned helph = 0
static

Definiert in Zeile 864 der Datei file_shelter.c.

int noformatyet
static

Definiert in Zeile 861 der Datei file_shelter.c.

char osdbuf[128]
static

Definiert in Zeile 21 der Datei file_shelter.c.

int partcount
static

Definiert in Zeile 860 der Datei file_shelter.c.

unsigned restore_status
static

Definiert in Zeile 865 der Datei file_shelter.c.

const char* rsshumanL[]
Initialisierung:
= {
"OK",
"Files not backed up",
"Stored files corrupted",
"Stored files corrupted",
"Storage area corrupted",
"A/CHDK exists, aborting",
}

Definiert in Zeile 439 der Datei file_shelter.c.

int running = 0
static

Definiert in Zeile 20 der Datei file_shelter.c.

unsigned scrolly
static

Definiert in Zeile 866 der Datei file_shelter.c.

void* starea = 0
static

Definiert in Zeile 471 der Datei file_shelter.c.

unsigned long stcrc = 0
static

Definiert in Zeile 476 der Datei file_shelter.c.

unsigned stmax = 0
static

Definiert in Zeile 472 der Datei file_shelter.c.

unsigned storageneed = 0
static

Definiert in Zeile 463 der Datei file_shelter.c.

void* storptr = 0
static

Definiert in Zeile 475 der Datei file_shelter.c.

unsigned tdircount = 0
static

Definiert in Zeile 468 der Datei file_shelter.c.

unsigned tfilecount = 0
static

Definiert in Zeile 467 der Datei file_shelter.c.

void* tmpbuf = 0
static

Definiert in Zeile 473 der Datei file_shelter.c.

const unsigned tmpsiz = 32768

Definiert in Zeile 474 der Datei file_shelter.c.

int use_open_rather_than_fopen = 1
static

Definiert in Zeile 106 der Datei file_shelter.c.

void* whitelist = 0
static

Definiert in Zeile 462 der Datei file_shelter.c.

const char* wl1[] = {"DISKBOOT.BIN", "PS.FIR", "PS.FI2", 0}

Definiert in Zeile 461 der Datei file_shelter.c.