More work on the FAT driver, more messy, but more complete
authorJohn Hodge <[email protected]>
Sun, 28 Mar 2010 12:25:55 +0000 (20:25 +0800)
committerJohn Hodge <[email protected]>
Sun, 28 Mar 2010 12:25:55 +0000 (20:25 +0800)
- Also did some documentation changes to the tVFS_Node structure

Kernel/include/errno.h
Kernel/include/vfs.h
Modules/Filesystems/FAT/fat.c
Modules/Filesystems/FAT/fs_fat.h

index 8bf83d8..0b796c0 100644 (file)
@@ -1,16 +1,20 @@
 /*
- * AcessOS Microkernel Version
+ * Acess2
  * errno.h
  */
 #ifndef _ERRNO_H
 #define _ERRNO_H
 
-enum eErrorNums {
+enum eErrorNums
+{
        EOK,
        ENOSYS,
        EINVAL,
        ENOMEM,
-       EACCES
+       EACCES,
+       ENOTFOUND,
+       EREADONLY,
+       ENOTIMPL
 };
 
 #endif
index b75710f..a782104 100644 (file)
@@ -87,11 +87,19 @@ typedef struct sVFS_Node
         * \}
         */
        
+       /**
+        * \name Node State
+        * \brief Stores the misc information about the node
+        * \{
+        */
         int    ReferenceCount; //!< Number of times the node is used
        
        Uint64  Size;   //!< File Size
        
        Uint32  Flags;  //!< File Flags
+       /**
+        * \}
+        */
        
        /**
         * \name Times
@@ -219,7 +227,7 @@ typedef struct sVFS_Node
         * \param Node  Pointer to this node
         * \param OldName       Name of the item to move/delete
         * \param NewName       New name (or NULL if unlinking is wanted)
-        * \return Boolean Success
+        * \return Zero on Success, non-zero on error (see errno.h)
         */
         int    (*Relink)(struct sVFS_Node *Node, char *OldName, char *NewName);
         
index 92aa431..9a3c79e 100644 (file)
@@ -592,13 +592,22 @@ Uint64 FAT_Read(tVFS_Node *Node, Uint64 offset, Uint64 length, void *buffer)
                return length;\r
        }\r
        \r
+       #if 0\r
+       if( FAT_int_GetAddress(Node, offset, &addr) )\r
+       {\r
+               Log_Warning("FAT", "Offset is past end of cluster chain mark");\r
+               LEAVE('i', 0);\r
+               return 0;\r
+       }\r
+       #endif\r
+       \r
        preSkip = offset / bpc;\r
        \r
        //Skip previous clusters\r
        for(i=preSkip;i--;)     {\r
                cluster = FAT_int_GetFatValue(disk, cluster);\r
                if(cluster == -1) {\r
-                       Warning("FAT_Read - Offset is past end of cluster chain mark");\r
+                       Log_Warning("FAT", "Offset is past end of cluster chain mark");\r
                        LEAVE('i', 0);\r
                        return 0;\r
                }\r
@@ -956,6 +965,11 @@ int FAT_int_WriteDirEntry(tVFS_Node *Node, int ID, fat_filetable *Entry)
 }\r
 \r
 #if USE_LFN\r
+// I should probably more tightly associate the LFN cache with the node\r
+// somehow, maybe by adding a field to tVFS_Node before locking it\r
+// Maybe .Cache or something like that (something that is free'd by the\r
+// Inode_UncacheNode function)\r
+       \r
 /**\r
  * \fn char *FAT_int_GetLFN(tVFS_Node *node)\r
  * \brief Return pointer to LFN cache entry\r
@@ -1151,7 +1165,7 @@ tVFS_Node *FAT_FindDir(tVFS_Node *Node, char *name)
                }\r
                \r
                //Check if the files are free\r
-               if(fileinfo[i&0xF].name[0] == '\0')     break;          //Free and last\r
+               if(fileinfo[i&0xF].name[0] == '\0')     break;  // Free and last\r
                if(fileinfo[i&0xF].name[0] == '\xE5')   continue;       //Free\r
                \r
                \r
@@ -1235,26 +1249,34 @@ int FAT_Relink(tVFS_Node *Node, char *OldName, char *NewName)
 {\r
        tVFS_Node       *child;\r
        fat_filetable   ft = {0};\r
-       Uint32  cluster;\r
-        int    ofs;\r
+        int    ret;\r
        \r
        child = FAT_FindDir(Node, OldName);\r
-       if(!child)      return 0;\r
+       if(!child)      return ENOTFOUND;\r
        \r
        // Delete?\r
        if( NewName == NULL )\r
        {\r
                child->ImplInt |= FAT_FLAG_DELETE;      // Mark for deletion on close\r
-               cluster = Node->Inode & 0xFFFFFFFF;\r
-               ofs = child->ImplInt & 0xFFFF;\r
+               \r
+               // Delete from the directory\r
                ft.name[0] = '\xE9';\r
+               FAT_int_WriteDirEntry(Node, child->ImplInt & 0xFFFF, &ft);\r
+               \r
+               // Return success\r
+               ret = EOK;\r
        }\r
        // Rename\r
        else\r
        {\r
+               Log_Warning("FAT", "Renaming no yet supported %p ('%s' => '%s')",\r
+                       Node, OldName, NewName);\r
+               ret = ENOTIMPL;\r
        }\r
        \r
-       return 0;\r
+       // Close child\r
+       child->Close( child );\r
+       return ret;\r
 }\r
 \r
 /**\r
@@ -1266,16 +1288,23 @@ void FAT_CloseFile(tVFS_Node *Node)
        tFAT_VolInfo    *disk = Node->ImplPtr;\r
        if(Node == NULL)        return ;\r
        \r
-       if( Node->ImplInt & FAT_FLAG_DIRTY ) {\r
-               #if 0\r
-               // Write back\r
-               FAT_int_UpdateDirEntry(\r
-                       Node->Inode >> 32, Node->ImplInt & 0xFFFF,\r
-                       Node\r
-                       );\r
-               #endif\r
+       // Update the node if it's dirty (don't bother if it's marked for\r
+       // deletion)\r
+       if( Node->ImplInt & FAT_FLAG_DIRTY && !(Node->ImplInt & FAT_FLAG_DELETE) )\r
+       {\r
+               tFAT_VolInfo    buf[16];\r
+               tFAT_VolInfo    *ft = &buf[ (Node->ImplInt & 0xFFFF) % 16 ];\r
+               \r
+               FAT_int_ReadDirSector(Node, (Node->ImplInt & 0xFFFF)/16, buf);\r
+               ft->size = Node->Size;\r
+               // TODO: update adate, mtime, mdate\r
+               FAT_int_WriteDirEntry(Node, Node->ImplInt & 0xFFFF, ft);\r
+               \r
+               Node->ImplInt &= ~FAT_FLAG_DIRTY;\r
        }\r
        \r
+       // TODO: Make this more thread safe somehow, probably by moving the\r
+       // Inode_UncacheNode higher up and saving the cluster value somewhere\r
        if( Node->ReferenceCount == 1 )\r
        {\r
                // Delete LFN Cache\r
index 84eee1d..072e2bf 100644 (file)
@@ -66,7 +66,7 @@ struct fat_filetable_s {
        Uint8   ctimems;        //!< 10ths of a second ranging from 0-199 (2 seconds)\r
        Uint16  ctime;  //!< Creation Time\r
        Uint16  cdate;  //!< Creation Date\r
-       Uint16  adate;  //!< Accessed Data. No Time feild though\r
+       Uint16  adate;  //!< Accessed Date. No Time feild though\r
        Uint16  clusterHi;      //!< High Cluster. 0 for FAT12 and FAT16\r
        Uint16  mtime;  //!< Last Modified Time\r
        Uint16  mdate;  //!< Last Modified Date\r

UCC git Repository :: git.ucc.asn.au