file/fat: rework utime function as modtime extension
This eliminates the dependence on a special struct since we were only using the modtime anyway. But it no longer fits any known standard APIs so I have converted it to our own extension instead. This can still be adapted to existing hosted APIs if the need arises. Change-Id: Ic8800698ddfd3a1a48b7cf921c0d0f865302d034
This commit is contained in:
parent
a0f1236e88
commit
a9f36efa62
|
@ -1123,9 +1123,11 @@ file_error:
|
|||
return rc;
|
||||
}
|
||||
|
||||
int utime(const char *path, const struct utimbuf* times)
|
||||
/** Extensions **/
|
||||
|
||||
int modtime(const char *path, time_t modtime)
|
||||
{
|
||||
DEBUGF("utime(path=\"%s\",times->modtime=%u)\n", path, times->modtime);
|
||||
DEBUGF("modtime(path=\"%s\",modtime=%d)\n", path, (int) modtime);
|
||||
|
||||
int rc, open1rc = -1;
|
||||
struct filestr_base pathstr;
|
||||
|
@ -1133,25 +1135,22 @@ int utime(const char *path, const struct utimbuf* times)
|
|||
|
||||
file_internal_lock_WRITER();
|
||||
|
||||
if (!times)
|
||||
FILE_ERROR(EINVAL, -1);
|
||||
|
||||
open1rc = open_stream_internal(path, FF_ANYTYPE | FF_PARENTINFO,
|
||||
&pathstr, &pathinfo);
|
||||
if (open1rc <= 0)
|
||||
{
|
||||
DEBUGF("Failed opening path: %d\n", open1rc);
|
||||
if (open1rc == 0)
|
||||
FILE_ERROR(ENOENT, -2);
|
||||
FILE_ERROR(ENOENT, -1);
|
||||
else
|
||||
FILE_ERROR(ERRNO, open1rc * 10 - 1);
|
||||
}
|
||||
|
||||
rc = fat_utime(&pathinfo.parentinfo.fatfile, pathstr.fatstr.fatfilep,
|
||||
times);
|
||||
rc = fat_modtime(&pathinfo.parentinfo.fatfile, pathstr.fatstr.fatfilep,
|
||||
modtime);
|
||||
if (rc < 0)
|
||||
{
|
||||
DEBUGF("I/O error during utime: %d\n", rc);
|
||||
DEBUGF("I/O error during modtime: %d\n", rc);
|
||||
FILE_ERROR(ERRNO, rc * 10 - 2);
|
||||
}
|
||||
|
||||
|
@ -1162,8 +1161,6 @@ file_error:
|
|||
return rc;
|
||||
}
|
||||
|
||||
/** Extensions **/
|
||||
|
||||
/* get the binary size of a file (in bytes) */
|
||||
off_t filesize(int fildes)
|
||||
{
|
||||
|
|
|
@ -2276,8 +2276,8 @@ fat_error:
|
|||
return rc;
|
||||
}
|
||||
|
||||
int fat_utime(struct fat_file *parent, struct fat_file *file,
|
||||
const struct utimbuf *times)
|
||||
int fat_modtime(struct fat_file *parent, struct fat_file *file,
|
||||
time_t modtime)
|
||||
{
|
||||
struct bpb * const fat_bpb = FAT_BPB(parent->volume);
|
||||
|
||||
|
@ -2297,7 +2297,7 @@ int fat_utime(struct fat_file *parent, struct fat_file *file,
|
|||
|
||||
uint16_t date;
|
||||
uint16_t time;
|
||||
dostime_localtime(times->modtime, &date, &time);
|
||||
dostime_localtime(modtime, &date, &time);
|
||||
|
||||
ent->wrttime = htole16(time);
|
||||
ent->wrtdate = htole16(date);
|
||||
|
|
|
@ -23,9 +23,6 @@
|
|||
|
||||
#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
#if defined(__PCTOOL__) || defined(SIMULATOR) || ((CONFIG_PLATFORM & PLATFORM_HOSTED) == PLATFORM_HOSTED)
|
||||
#include <utime.h>
|
||||
#endif
|
||||
#include <time.h>
|
||||
#include "config.h"
|
||||
#include "system.h"
|
||||
|
@ -143,8 +140,8 @@ enum fat_remove_op /* what should fat_remove(), remove? */
|
|||
int fat_remove(struct fat_file *file, enum fat_remove_op what);
|
||||
int fat_rename(struct fat_file *parent, struct fat_file *file,
|
||||
const unsigned char *newname);
|
||||
int fat_utime(struct fat_file *parent, struct fat_file *file,
|
||||
const struct utimbuf *utimes);
|
||||
int fat_modtime(struct fat_file *parent, struct fat_file *file,
|
||||
time_t modtime);
|
||||
|
||||
/** File stream functions **/
|
||||
int fat_closewrite(struct fat_filestr *filestr, uint32_t size,
|
||||
|
|
|
@ -85,8 +85,8 @@ int fdprintf(int fildes, const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3);
|
|||
#ifndef rename
|
||||
#define rename FS_PREFIX(rename)
|
||||
#endif
|
||||
#ifndef utime
|
||||
#define utime FS_PREFIX(utime)
|
||||
#ifndef modtime
|
||||
#define modtime FS_PREFIX(modtime)
|
||||
#endif
|
||||
#ifndef filesize
|
||||
#define filesize FS_PREFIX(filesize)
|
||||
|
|
|
@ -55,7 +55,7 @@ ssize_t read(int fildes, void *buf, size_t nbyte);
|
|||
ssize_t write(int fildes, const void *buf, size_t nbyte);
|
||||
int remove(const char *path);
|
||||
int rename(const char *old, const char *new);
|
||||
int utime(const char *path, const struct utimbuf* times);
|
||||
int modtime(const char *path, time_t modtime);
|
||||
off_t filesize(int fildes);
|
||||
int fsamefile(int fildes1, int fildes2);
|
||||
int relate(const char *path1, const char *path2);
|
||||
|
|
|
@ -28,12 +28,6 @@ struct tm
|
|||
#if !defined(_TIME_T_DEFINED) && !defined(_TIME_T_DECLARED)
|
||||
typedef long time_t;
|
||||
|
||||
struct utimbuf
|
||||
{
|
||||
time_t actime;
|
||||
time_t modtime;
|
||||
};
|
||||
|
||||
/* this define below is used by the mingw headers to prevent duplicate
|
||||
typedefs */
|
||||
#define _TIME_T_DEFINED
|
||||
|
|
Loading…
Reference in New Issue