add FAT_setAttr, expose FAT_setAttr/FAT_getAttr and add defines for DOS attributes

This commit is contained in:
Dave Murphy 2012-05-13 00:24:58 +01:00
parent 8829ebdbdb
commit f6ff332c5c
2 changed files with 62 additions and 2 deletions

View File

@ -99,6 +99,21 @@ Get Volume Label
*/
extern void fatGetVolumeLabel (const char* name, char *label);
// File attributes
#define ATTR_ARCHIVE 0x20 // Archive
#define ATTR_DIRECTORY 0x10 // Directory
#define ATTR_VOLUME 0x08 // Volume
#define ATTR_SYSTEM 0x04 // System
#define ATTR_HIDDEN 0x02 // Hidden
#define ATTR_READONLY 0x01 // Read only
/*
Methods to modify DOS File Attributes
*/
int FAT_getAttr(const char *file);
int FAT_setAttr(const char *file, int attr );
#ifdef __cplusplus
}
#endif

View File

@ -69,8 +69,53 @@ int FAT_getAttr(const char *file) {
}
int FAT_setAttr(const char *file, int attr) {
DIR_ENTRY dirEntry;
if (!_FAT_findEntry(file,&dirEntry)) return -1;
// Defines...
DIR_ENTRY_POSITION entryEnd;
PARTITION *partition = NULL;
DIR_ENTRY* dirEntry = NULL;
// Get Partition
partition = _FAT_partition_getPartitionFromPath( file );
// Check Partition
if( !partition )
return -1;
// Move the path pointer to the start of the actual path
if (strchr (file, ':') != NULL)
file = strchr (file, ':') + 1;
if (strchr (file, ':') != NULL)
return -1;
// Get DIR_ENTRY
if( !_FAT_directory_entryFromPath (partition, dirEntry, file, NULL) )
return -1;
// Get Entry-End
entryEnd = dirEntry->dataEnd;
// Lock Partition
_FAT_lock(&partition->lock);
// Write Data
_FAT_cache_writePartialSector (
partition->cache // Cache to write
, &attr // Value to be written
, _FAT_fat_clusterToSector( partition , entryEnd.cluster ) + entryEnd.sector // cluster
, entryEnd.offset * DIR_ENTRY_DATA_SIZE + DIR_ENTRY_attributes // offset
, 1 // Size in bytes
);
// Flush any sectors in the disc cache
if ( !_FAT_cache_flush( partition->cache ) ) {
_FAT_unlock(&partition->lock); // Unlock Partition
return -1;
}
// Unlock Partition
_FAT_unlock(&partition->lock);
return 0;
}