static int del_entry(direntry_t *entry, MainParam_t *mp) { Arg_t *arg=(Arg_t *) mp->arg; if(got_signal) return ERROR_ONE; if(entry->entry == -3) { fprintf(stderr, "Cannot remove root directory\n"); return ERROR_ONE; } if (arg->verbose) { fprintf(stderr,"Removing "); fprintPwd(stderr, entry,0); fputc('\n', stderr); } if (entry->dir.attr & (ATTR_READONLY | ATTR_SYSTEM)) { char tmp[4*MAX_VNAMELEN+1]; wchar_to_native(entry->name,tmp,MAX_VNAMELEN); if (ask_confirmation("%s: \"%s\" is read only, erase anyway (y/n) ? ", progname, tmp)) return ERROR_ONE; } if (fatFreeWithDirentry(entry)) return ERROR_ONE; wipeEntry(entry); return GOT_ONE; }
static __inline__ clash_action get_slots(Stream_t *Dir, dos_name_t *dosname, char *longname, struct scan_state *ssp, ClashHandling_t *ch) { int error; clash_action ret; int match_pos=0; direntry_t entry; int isprimary; int no_overwrite; int reason; int pessimisticShortRename; doscp_t *cp = GET_DOSCONVERT(Dir); pessimisticShortRename = (ch->action[0] == NAMEMATCH_AUTORENAME); entry.Dir = Dir; no_overwrite = 1; if((is_reserved(longname,1)) || longname[strspn(longname,". ")] == '\0'){ reason = RESERVED; isprimary = 1; } else if(contains_illegals(longname,long_illegals,1024)) { reason = ILLEGALS; isprimary = 1; } else if(is_reserved(dosname->base,0)) { reason = RESERVED; ch->use_longname = 1; isprimary = 0; } else if(contains_illegals(dosname->base,short_illegals,11)) { reason = ILLEGALS; ch->use_longname = 1; isprimary = 0; } else { reason = EXISTS; switch (lookupForInsert(Dir, &entry, dosname, longname, ssp, ch->ignore_entry, ch->source_entry, pessimisticShortRename && ch->use_longname, ch->use_longname)) { case -1: return NAMEMATCH_ERROR; case 0: return NAMEMATCH_SKIP; /* Single-file error error or skip request */ case 5: return NAMEMATCH_GREW; /* Grew directory, try again */ case 6: return NAMEMATCH_SUCCESS; /* Success */ } match_pos = -2; if (ssp->longmatch > -1) { /* Primary Long Name Match */ #ifdef debug fprintf(stderr, "Got longmatch=%d for name %s.\n", longmatch, longname); #endif match_pos = ssp->longmatch; isprimary = 1; } else if ((ch->use_longname & 1) && (ssp->shortmatch != -1)) { /* Secondary Short Name Match */ #ifdef debug fprintf(stderr, "Got secondary short name match for name %s.\n", longname); #endif match_pos = ssp->shortmatch; isprimary = 0; } else if (ssp->shortmatch >= 0) { /* Primary Short Name Match */ #ifdef debug fprintf(stderr, "Got primary short name match for name %s.\n", longname); #endif match_pos = ssp->shortmatch; isprimary = 1; } else return NAMEMATCH_RENAME; if(match_pos > -1) { entry.entry = match_pos; dir_read(&entry, &error); if (error) return NAMEMATCH_ERROR; /* if we can't overwrite, don't propose it */ no_overwrite = (match_pos == ch->source || IS_DIR(&entry)); } } ret = process_namematch(cp, dosname, longname, isprimary, ch, no_overwrite, reason); if (ret == NAMEMATCH_OVERWRITE && match_pos > -1){ if((entry.dir.attr & 0x5) && (ask_confirmation("file is read only, overwrite anyway (y/n) ? "))) return NAMEMATCH_RENAME; /* Free up the file to be overwritten */ if(fatFreeWithDirentry(&entry)) return NAMEMATCH_ERROR; #if 0 if(isprimary && match_pos - ssp->match_free + 1 >= ssp->size_needed){ /* reuse old entry and old short name for overwrite */ ssp->free_start = match_pos - ssp->size_needed + 1; ssp->free_size = ssp->size_needed; ssp->slot = match_pos; ssp->got_slots = 1; strncpy(dosname, dir.name, 3); strncpy(dosname + 8, dir.ext, 3); return ret; } else #endif { wipeEntry(&entry); return NAMEMATCH_RENAME; } } return ret; }