paul@181 | 1 | /* |
paul@181 | 2 | * File metadata abstractions. |
paul@181 | 3 | * |
paul@648 | 4 | * Copyright (C) 2019, 2022, 2024 Paul Boddie <paul@boddie.org.uk> |
paul@181 | 5 | * |
paul@181 | 6 | * This program is free software; you can redistribute it and/or |
paul@181 | 7 | * modify it under the terms of the GNU General Public License as |
paul@181 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@181 | 9 | * the License, or (at your option) any later version. |
paul@181 | 10 | * |
paul@181 | 11 | * This program is distributed in the hope that it will be useful, |
paul@181 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@181 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@181 | 14 | * GNU General Public License for more details. |
paul@181 | 15 | * |
paul@181 | 16 | * You should have received a copy of the GNU General Public License |
paul@181 | 17 | * along with this program; if not, write to the Free Software |
paul@181 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@181 | 19 | * Boston, MA 02110-1301, USA |
paul@181 | 20 | */ |
paul@181 | 21 | |
paul@181 | 22 | #pragma once |
paul@181 | 23 | |
paul@269 | 24 | #include <sys/stat.h> |
paul@269 | 25 | |
paul@181 | 26 | #include <systypes/base.h> |
paul@181 | 27 | #include <systypes/timespec.h> |
paul@181 | 28 | |
paul@181 | 29 | EXTERN_C_BEGIN |
paul@181 | 30 | |
paul@181 | 31 | /* File metadata abstraction. */ |
paul@181 | 32 | |
paul@181 | 33 | typedef struct |
paul@181 | 34 | { |
paul@181 | 35 | sys_dev_t st_dev; |
paul@181 | 36 | sys_ino_t st_ino; |
paul@181 | 37 | sys_mode_t st_mode; |
paul@181 | 38 | sys_nlink_t st_nlink; |
paul@181 | 39 | sys_uid_t st_uid; |
paul@181 | 40 | sys_gid_t st_gid; |
paul@181 | 41 | sys_dev_t st_rdev; |
paul@181 | 42 | sys_off_t st_size; |
paul@181 | 43 | struct sys_timespec st_atim; |
paul@181 | 44 | struct sys_timespec st_mtim; |
paul@181 | 45 | struct sys_timespec st_ctim; |
paul@181 | 46 | sys_blksize_t st_blksize; |
paul@181 | 47 | sys_blkcnt_t st_blocks; |
paul@181 | 48 | |
paul@181 | 49 | } sys_stat_t; |
paul@181 | 50 | |
paul@648 | 51 | /* Macros to be used in different C library environments. */ |
paul@648 | 52 | |
paul@648 | 53 | #define COPY_STAT(s1, s2) \ |
paul@650 | 54 | ( \ |
paul@650 | 55 | s1->st_dev = s2->st_dev, \ |
paul@650 | 56 | s1->st_ino = s2->st_ino, \ |
paul@650 | 57 | s1->st_mode = s2->st_mode, \ |
paul@650 | 58 | s1->st_nlink = s2->st_nlink, \ |
paul@650 | 59 | s1->st_uid = s2->st_uid, \ |
paul@650 | 60 | s1->st_gid = s2->st_gid, \ |
paul@650 | 61 | s1->st_rdev = s2->st_rdev, \ |
paul@650 | 62 | s1->st_size = s2->st_size, \ |
paul@650 | 63 | s1->st_atim.tv_sec = s2->st_atim.tv_sec, \ |
paul@650 | 64 | s1->st_atim.tv_nsec = s2->st_atim.tv_nsec, \ |
paul@650 | 65 | s1->st_mtim.tv_sec = s2->st_mtim.tv_sec, \ |
paul@650 | 66 | s1->st_mtim.tv_nsec = s2->st_mtim.tv_nsec, \ |
paul@650 | 67 | s1->st_ctim.tv_sec = s2->st_ctim.tv_sec, \ |
paul@650 | 68 | s1->st_ctim.tv_nsec = s2->st_ctim.tv_nsec, \ |
paul@650 | 69 | s1->st_blksize = s2->st_blksize, \ |
paul@650 | 70 | s1->st_blocks = s2->st_blocks \ |
paul@650 | 71 | ); |
paul@648 | 72 | |
paul@648 | 73 | /* Functions to be implemented in different C library environments. */ |
paul@648 | 74 | |
paul@269 | 75 | void systypes_copy_from_sys_stat(struct stat *st, sys_stat_t *sst); |
paul@269 | 76 | |
paul@269 | 77 | void systypes_copy_to_sys_stat(struct stat *st, sys_stat_t *sst); |
paul@269 | 78 | |
paul@181 | 79 | EXTERN_C_END |
paul@269 | 80 | |
paul@269 | 81 | /* vim: tabstop=4 expandtab shiftwidth=4 |
paul@269 | 82 | */ |