2 * hl_fstat.c -- provide _fstat().
4 * Copyright (c) 2024 Synopsys Inc.
6 * The authors hereby grant permission to use, copy, modify, distribute,
7 * and license this software and its documentation for any purpose, provided
8 * that existing copyright notices are retained in all copies and that this
9 * notice is included verbatim in any distributions. No written agreement,
10 * license, or royalty fee is required for any of the authorized uses.
11 * Modifications to this software may be copyrighted by their authors
12 * and need not follow the licensing terms described here, provided that
13 * the new terms are clearly indicated on the first page of each file where
22 #include <sys/types.h>
25 #include "hl_toolchain.h"
28 /* Hostlink IO version of struct stat. */
30 uint32_t hl_dev
; /* ID of device containing file. */
31 uint16_t hl_ino
; /* inode number. */
32 uint16_t hl_mode
; /* File type and access mode. */
33 int16_t hl_nlink
; /* Number of hard links. */
34 int16_t hl_uid
; /* Owner's UID. */
35 int16_t hl_gid
; /* Owner's GID. */
36 uint8_t hl_pad
[2]; /* Padding to match simulator struct. */
37 uint32_t hl_rdev
; /* Device ID (if special file). */
38 int32_t hl_size
; /* Size in bytes. */
39 int32_t hl_atime
; /* Access time. */
40 int32_t hl_mtime
; /* Modification time. */
41 int32_t hl_ctime
; /* Creation time. */
44 /* Map Hostlink version of stat struct into newlib's one. */
45 static __always_inline
void
46 _hl_fstat_map (const struct _hl_stat
*hl_stat
, struct stat
*stat
)
48 stat
->st_dev
= hl_stat
->hl_dev
;
49 stat
->st_ino
= hl_stat
->hl_ino
;
50 stat
->st_mode
= hl_stat
->hl_mode
;
51 stat
->st_nlink
= hl_stat
->hl_nlink
;
52 stat
->st_uid
= hl_stat
->hl_uid
;
53 stat
->st_gid
= hl_stat
->hl_gid
;
54 stat
->st_rdev
= hl_stat
->hl_rdev
;
55 stat
->st_size
= hl_stat
->hl_size
;
56 stat
->st_atime
= hl_stat
->hl_atime
;
57 stat
->st_mtime
= hl_stat
->hl_mtime
;
58 stat
->st_ctime
= hl_stat
->hl_ctime
;
61 /* Get host file info. Implements HL_GNUIO_EXT_FSTAT. */
62 static __always_inline
int
63 _hl_fstat (int fd
, struct stat
*buf
)
65 struct _hl_stat hl_stat
;
69 /* Special version of hostlink - retuned values are passed
72 host_errno
= _user_hostlink (HL_GNUIO_EXT_VENDOR_ID
, HL_GNUIO_EXT_FSTAT
,
84 _hl_fstat_map (&hl_stat
, buf
);
92 _fstat (int fd
, struct stat
*buf
)
94 return _hl_fstat (fd
, buf
);