コード例 #1
0
ファイル: srchdir.c プロジェクト: CivilPol/sdcboot
int SearchDirectory(RDWRHandle handle, char* dir, CLUSTER* fatcluster,
                    struct DirectoryPosition* pos,
                    int    func(RDWRHandle handle,
                                struct DirectoryPosition* pos,
                                struct DirectoryEntry* entry))
{
    int i, j;
    struct PipeStruct pipe, *ppipe = &pipe;

    char filename[8], extension[3];

    pipe.found      = FALSE;
    pipe.filename   = filename;
    pipe.extension  = extension;
    pipe.error      = FALSE;
    pipe.func       = func;

    memset(filename, ' ', 8);
    for (i = 0; i < 8; i++)
        if ((dir[i] == '.') || (dir[i] == '\0'))
           break;
        else
           filename[i] = dir[i];

    memset(extension, ' ', 3);

    for (j = 0; j < 3; j++)
        if (dir[i+j] == '.')
           continue;
        else if (dir[i+j] == '\0')
           break;
        else
           extension[j] = dir[i];

    if (IsRootDirPosition(handle, pos))
    {
       if (!TraverseRootDir(handle, DirSearcher,
                            (void**) &ppipe, TRUE)) return FALSE;
       return pipe.found;
    }
    else
    {
       if (!TraverseSubdir(handle, *fatcluster, DirSearcher,
                           (void**) &ppipe, TRUE)) return FALSE;

       return pipe.found;
    }
}
コード例 #2
0
ファイル: filessum.c プロジェクト: FDOS/chkdsk
static BOOL DirSizeGetter(RDWRHandle handle, struct DirectoryPosition* pos,
                          void** structure)
{
   BOOL InRoot;
   unsigned long **dirsize = (unsigned long**) structure;
   unsigned char sectorspercluster;
   CLUSTER label;

   pos = pos, handle = handle;
    
   /* Check for loops in the directory structure */ 
   InRoot = IsRootDirPosition(handle, pos);
   if (InRoot == -1) return FAIL;

   if (!InRoot && (pos->offset == 0))
   {
      sectorspercluster = GetSectorsPerCluster(handle);
      if (!sectorspercluster) return FAIL;

      if ((pos->sector % sectorspercluster) == 0) 
      {
         label = DataSectorToCluster(handle, pos->sector);
         if (!label) return FAIL;
         
         if (GetBitfieldBit(fatmap, label))
         {
            return FALSE;
         }
         SetBitfieldBit(fatmap, label);
      }
   }
    
   **dirsize += sizeof(struct DirectoryEntry);

   return TRUE;
}
コード例 #3
0
ファイル: invchar.c プロジェクト: FDOS/chkdsk
BOOL CheckEntryForInvalidChars(RDWRHandle handle,                   
                               struct DirectoryPosition* pos, 
                               struct DirectoryEntry* direct, 
                               char* filename,
                               BOOL fixit)
{
    int i;
    BOOL invalidname = FALSE;
    BOOL InRoot;
    struct DirectoryEntry entry;
    
    memcpy(&entry, direct, sizeof(struct DirectoryEntry));
    
    if (((entry.attribute & FA_LABEL) == 0) && /* Not checking volume labels */
        !IsDeletedLabel(entry))   
    {        
        if (IsPreviousDir(entry) || /* .. */
            IsCurrentDir(entry))    /* .  */              
        {
           /* See wether the given directory entry is in the root directory */
           InRoot = IsRootDirPosition(handle, pos);
           if (InRoot == FAIL) return FAIL;   
           
           /* All the '.' and '..' entries must be directories */
           if (((entry.attribute & FA_DIREC) == 0) || (InRoot))
           {
              if (IsCurrentDir(entry))
              {  
                 if (InRoot)
                 {
                    ShowFileNameViolation(handle, "",  
                                          "The root directory contains an '.' entry");   
                 }
                 else
                 {
                    ShowParentViolation(handle, filename,  
                                        "%s contains an '.' entry that is not a directory");
                 }
                 memcpy(entry.filename, "DOT     ", 8); 
              }
              else
              {
                 if (InRoot)
                 {
                    ShowFileNameViolation(handle, "",  
                                          "The root directory contains an '..' entry");                     
                 }   
                 else 
                 {
                    ShowParentViolation(handle, filename,  
                                        "%s contains an '..' entry that is not a directory");
                 }
                  
                 memcpy(entry.filename, "DOTDOT     ", 8);    
              }   
             
              if (fixit)
              {         
                 memcpy(entry.extension, "   ", 3);
                 if (!RenameFile(handle, pos, &entry, DirCluster)) /* Write the changes to disk */
                    return FAIL;          
              }
          
              return FALSE;          
           }

           /* Check wether you realy have '.' and '..' */
           if (IsCurrentDir(entry))
           {                             
              if ((memcmp(entry.filename, ".       ", 8) != 0) ||
                  (memcmp(entry.extension, "   ", 3) != 0))
              {
                 ShowFileNameViolation(handle, filename,  
                                       "%s contains invalid char(s)");  
                 if (fixit)
                 {                          
                    memcpy(entry.filename, ".       ", 8);
                    memcpy(entry.extension, "   ", 3);
                    if (!RenameFile(handle, pos, &entry, DirCluster)) /* Write the changes to disk */
                       return FAIL;                        
                 }
              }
           }           
           
           if (IsPreviousDir(entry))
           {                             
              if ((memcmp(entry.filename, "..      ", 8) != 0) ||
                  (memcmp(entry.extension, "   ", 3) != 0))
              {
                 ShowFileNameViolation(handle, filename,  
                                       "%s contains invalid char(s)");     
                 if (fixit)
                 {
                    memcpy(entry.filename, "..      ", 8);
                    memcpy(entry.extension, "   ", 3);
                    if (!RenameFile(handle, pos, &entry, DirCluster)) /* Write the changes to disk */
                       return FAIL;                    
                 }
              }
           }
        }
        else
        {
          if (entry.filename[0] == ' ')
          {
             invalidname = TRUE;
             entry.filename[0] = 'A';
          }

          /* file name */
          for (i = 0; i < 8; i++)
          {
              if ((strchr(INVALIDSFNCHARS, entry.filename[i]))                ||
                  (((unsigned char)(entry.filename[i]) < 0x20) && (entry.filename[i] != 0x05)) ||
                  (islower(entry.filename[i])))
              {
                 entry.filename[i] = 'A';
                 invalidname = TRUE;
              }
          }

          /* extension */
          for (i = 0; i < 3; i++)
          {
              if ((strchr(INVALIDSFNCHARS, entry.extension[i]))               ||
                  (((unsigned char)(entry.extension[i]) < 0x20) &&
                                                (entry.extension[i] != 0x05)) ||
                 (islower(entry.extension[i])))           
              {
                 entry.extension[i] = 'A';
                 invalidname = TRUE;
              }
          }

          if (invalidname)
          {
             ShowFileNameViolation(handle, filename,  
                                   "%s contains invalid char(s)");
      
             if (fixit)
             {         
                if (!RenameFile(handle, pos, &entry, DirCluster)) /* Write the changes to disk */
                   return FAIL;          
             }
          
             return FALSE;
          }
        }
    }
       
    return TRUE;
}