[En-Nut-Discussion] RENAME Routine
ennut at thezachariasgroup.com
ennut at thezachariasgroup.com
Mon Jul 2 18:52:55 CEST 2007
I wrote a RENAME routine for the PHAT File system. I needed one for
the SDCARD.
I placed it at the end of nut\fs\pathops.c and added a reference to
it in nut\include\sys\stat.h on my system. There may be a better place for it.
I do not have developer status so if someone with developer status
wants to add this code, great. It would be nice to see it in a future version.
I thought I would share it.
Thanks!
Zack
/*!
* \brief Rename a file. Include file is nut\include\sys\stat.h
*
* \param pcOldName The name of a registered device, followed by a
colon and a filename.
* \param pcNewName The name of a registered device, followed by a
colon and a filename.
*
* \return 0 for success or -1 to indicate an error.
*/
int rename(CONST char *pcOldName, CONST char *pcNewName)
{
NUTDEVICE *dev;
char cOldDeviceName[9];
char cNewDeviceName[9];
u_char nidx;
char *nptr;
int iReturnCode = -1;
FSCP_RENAME fsFileRename; // Structure used for renaming files.
// Extract Old File's device name.
nptr = (char *)pcOldName;
for (nidx = 0; *nptr && *nptr != ':' && nidx < 8; nidx++, nptr++)
{
cOldDeviceName[nidx] = *nptr;
}
cOldDeviceName[nidx] = 0;
if (*nptr++ == ':') // Make sure a colon follows the Device Name
{
fsFileRename.par_old = nptr; // Assign the Old File's name to
the File Rename structure
// Extract New device name.
nptr = (char *)pcNewName;
for (nidx = 0; *nptr && *nptr != ':' && nidx < 8; nidx++, nptr++)
{
cNewDeviceName[nidx] = *nptr;
}
cNewDeviceName[nidx] = 0;
if (*nptr++ == ':') // Make sure a colon follows the Device Name
{
fsFileRename.par_new = nptr; // Assign the New File's name to
the File Rename structure
if (stricmp(cNewDeviceName, cOldDeviceName) == 0) // Make sure
both device names are the same
{
if ((dev = NutDeviceLookup(cOldDeviceName)) == 0) // Get
device structure of registered device.
{
errno = ENOENT;
}
else
{
iReturnCode = (*dev->dev_ioctl)(dev, FS_RENAME,
(void*)&fsFileRename);
}
}
}
}
return iReturnCode;
}
More information about the En-Nut-Discussion
mailing list