mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-13 18:17:39 -04:00
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
6 changed files with 16 additions and 28 deletions
|
@ -1123,9 +1123,11 @@ file_error:
|
||||||
return rc;
|
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;
|
int rc, open1rc = -1;
|
||||||
struct filestr_base pathstr;
|
struct filestr_base pathstr;
|
||||||
|
@ -1133,25 +1135,22 @@ int utime(const char *path, const struct utimbuf* times)
|
||||||
|
|
||||||
file_internal_lock_WRITER();
|
file_internal_lock_WRITER();
|
||||||
|
|
||||||
if (!times)
|
|
||||||
FILE_ERROR(EINVAL, -1);
|
|
||||||
|
|
||||||
open1rc = open_stream_internal(path, FF_ANYTYPE | FF_PARENTINFO,
|
open1rc = open_stream_internal(path, FF_ANYTYPE | FF_PARENTINFO,
|
||||||
&pathstr, &pathinfo);
|
&pathstr, &pathinfo);
|
||||||
if (open1rc <= 0)
|
if (open1rc <= 0)
|
||||||
{
|
{
|
||||||
DEBUGF("Failed opening path: %d\n", open1rc);
|
DEBUGF("Failed opening path: %d\n", open1rc);
|
||||||
if (open1rc == 0)
|
if (open1rc == 0)
|
||||||
FILE_ERROR(ENOENT, -2);
|
FILE_ERROR(ENOENT, -1);
|
||||||
else
|
else
|
||||||
FILE_ERROR(ERRNO, open1rc * 10 - 1);
|
FILE_ERROR(ERRNO, open1rc * 10 - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = fat_utime(&pathinfo.parentinfo.fatfile, pathstr.fatstr.fatfilep,
|
rc = fat_modtime(&pathinfo.parentinfo.fatfile, pathstr.fatstr.fatfilep,
|
||||||
times);
|
modtime);
|
||||||
if (rc < 0)
|
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);
|
FILE_ERROR(ERRNO, rc * 10 - 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1162,8 +1161,6 @@ file_error:
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Extensions **/
|
|
||||||
|
|
||||||
/* get the binary size of a file (in bytes) */
|
/* get the binary size of a file (in bytes) */
|
||||||
off_t filesize(int fildes)
|
off_t filesize(int fildes)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2276,8 +2276,8 @@ fat_error:
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fat_utime(struct fat_file *parent, struct fat_file *file,
|
int fat_modtime(struct fat_file *parent, struct fat_file *file,
|
||||||
const struct utimbuf *times)
|
time_t modtime)
|
||||||
{
|
{
|
||||||
struct bpb * const fat_bpb = FAT_BPB(parent->volume);
|
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 date;
|
||||||
uint16_t time;
|
uint16_t time;
|
||||||
dostime_localtime(times->modtime, &date, &time);
|
dostime_localtime(modtime, &date, &time);
|
||||||
|
|
||||||
ent->wrttime = htole16(time);
|
ent->wrttime = htole16(time);
|
||||||
ent->wrtdate = htole16(date);
|
ent->wrtdate = htole16(date);
|
||||||
|
|
|
@ -23,9 +23,6 @@
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#if defined(__PCTOOL__) || defined(SIMULATOR) || ((CONFIG_PLATFORM & PLATFORM_HOSTED) == PLATFORM_HOSTED)
|
|
||||||
#include <utime.h>
|
|
||||||
#endif
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "system.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_remove(struct fat_file *file, enum fat_remove_op what);
|
||||||
int fat_rename(struct fat_file *parent, struct fat_file *file,
|
int fat_rename(struct fat_file *parent, struct fat_file *file,
|
||||||
const unsigned char *newname);
|
const unsigned char *newname);
|
||||||
int fat_utime(struct fat_file *parent, struct fat_file *file,
|
int fat_modtime(struct fat_file *parent, struct fat_file *file,
|
||||||
const struct utimbuf *utimes);
|
time_t modtime);
|
||||||
|
|
||||||
/** File stream functions **/
|
/** File stream functions **/
|
||||||
int fat_closewrite(struct fat_filestr *filestr, uint32_t size,
|
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
|
#ifndef rename
|
||||||
#define rename FS_PREFIX(rename)
|
#define rename FS_PREFIX(rename)
|
||||||
#endif
|
#endif
|
||||||
#ifndef utime
|
#ifndef modtime
|
||||||
#define utime FS_PREFIX(utime)
|
#define modtime FS_PREFIX(modtime)
|
||||||
#endif
|
#endif
|
||||||
#ifndef filesize
|
#ifndef filesize
|
||||||
#define filesize FS_PREFIX(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);
|
ssize_t write(int fildes, const void *buf, size_t nbyte);
|
||||||
int remove(const char *path);
|
int remove(const char *path);
|
||||||
int rename(const char *old, const char *new);
|
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);
|
off_t filesize(int fildes);
|
||||||
int fsamefile(int fildes1, int fildes2);
|
int fsamefile(int fildes1, int fildes2);
|
||||||
int relate(const char *path1, const char *path2);
|
int relate(const char *path1, const char *path2);
|
||||||
|
|
|
@ -28,12 +28,6 @@ struct tm
|
||||||
#if !defined(_TIME_T_DEFINED) && !defined(_TIME_T_DECLARED)
|
#if !defined(_TIME_T_DEFINED) && !defined(_TIME_T_DECLARED)
|
||||||
typedef long time_t;
|
typedef long time_t;
|
||||||
|
|
||||||
struct utimbuf
|
|
||||||
{
|
|
||||||
time_t actime;
|
|
||||||
time_t modtime;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* this define below is used by the mingw headers to prevent duplicate
|
/* this define below is used by the mingw headers to prevent duplicate
|
||||||
typedefs */
|
typedefs */
|
||||||
#define _TIME_T_DEFINED
|
#define _TIME_T_DEFINED
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue