paul@181 | 1 | /* |
paul@181 | 2 | * Filesystem image access functions. |
paul@181 | 3 | * |
paul@236 | 4 | * Copyright (C) 2019, 2021, 2022 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 | #ifndef __IMAGE_H__ |
paul@181 | 23 | #define __IMAGE_H__ |
paul@181 | 24 | |
paul@181 | 25 | #include <ext2fs/ext2fs.h> |
paul@226 | 26 | #include <sys/stat.h> |
paul@181 | 27 | |
paul@181 | 28 | #ifdef __cplusplus |
paul@181 | 29 | extern "C" { |
paul@181 | 30 | #endif |
paul@181 | 31 | |
paul@243 | 32 | /* Filesystem operations. */ |
paul@243 | 33 | |
paul@249 | 34 | errcode_t image_access_by_path(ext2_filsys fs, const char *path, |
paul@249 | 35 | errcode_t (*op)(ext2_filsys, ext2_ino_t), |
paul@249 | 36 | ext2_ino_t *ino); |
paul@249 | 37 | |
paul@181 | 38 | errcode_t image_create_file(ext2_filsys fs, ext2_ino_t ino_target, |
paul@181 | 39 | const char *basename, __u16 mode, |
paul@181 | 40 | __u16 uid, __u16 gid, ext2_ino_t *ino_file); |
paul@181 | 41 | |
paul@249 | 42 | errcode_t image_dir_empty_by_inode(ext2_filsys fs, ext2_ino_t ino); |
paul@249 | 43 | |
paul@249 | 44 | errcode_t image_dir_empty_by_path(ext2_filsys fs, const char *path, |
paul@249 | 45 | ext2_ino_t *ino); |
paul@249 | 46 | |
paul@249 | 47 | errcode_t image_dir_get_parent(ext2_filsys fs, ext2_ino_t ino, |
paul@249 | 48 | ext2_ino_t *ino_parent); |
paul@249 | 49 | |
paul@236 | 50 | int image_file_type(int mode); |
paul@236 | 51 | |
paul@257 | 52 | errcode_t image_find_by_path(ext2_filsys fs, const char *path, ext2_ino_t *ino); |
paul@181 | 53 | |
paul@257 | 54 | errcode_t image_resolve_by_path(ext2_filsys fs, const char **path, |
paul@257 | 55 | ext2_ino_t *ino); |
paul@257 | 56 | |
paul@257 | 57 | errcode_t image_resolve_next(ext2_filsys fs, ext2_ino_t ino_dir, |
paul@257 | 58 | const char **basename, char *buf, ext2_ino_t *ino); |
paul@181 | 59 | |
paul@181 | 60 | errcode_t image_find_file(ext2_filsys fs, const char *dirname, |
paul@181 | 61 | const char *basename, ext2_ino_t *ino); |
paul@181 | 62 | |
paul@257 | 63 | errcode_t image_inode(ext2_filsys fs, const char *path, |
paul@181 | 64 | struct ext2_inode *inode); |
paul@181 | 65 | |
paul@253 | 66 | errcode_t image_inode_refcount_update(ext2_filsys fs, ext2_ino_t ino, |
paul@253 | 67 | int change); |
paul@249 | 68 | |
paul@226 | 69 | errcode_t image_list_dir(ext2_filsys fs, const char *path, |
paul@226 | 70 | int (*proc)(struct ext2_dir_entry *, int, int, char *, |
paul@226 | 71 | void *), |
paul@226 | 72 | void *data); |
paul@226 | 73 | |
paul@181 | 74 | errcode_t image_make_dir(ext2_filsys fs, ext2_ino_t ino_dir, |
paul@181 | 75 | const char *basename, __u16 mode, |
paul@181 | 76 | __u16 uid, __u16 gid, ext2_ino_t *ino); |
paul@181 | 77 | |
paul@181 | 78 | errcode_t image_make_next_dir(ext2_filsys fs, ext2_ino_t ino_dir, |
paul@181 | 79 | const char **basename, __u16 mode, __u16 uid, |
paul@181 | 80 | __u16 gid, ext2_ino_t *ino); |
paul@181 | 81 | |
paul@257 | 82 | errcode_t image_make_dirs(ext2_filsys fs, const char **path, |
paul@181 | 83 | ext2_ino_t ino_dir, __u16 mode, __u16 uid, |
paul@181 | 84 | __u16 gid); |
paul@181 | 85 | |
paul@235 | 86 | errcode_t image_remove_by_inode(ext2_filsys fs, ext2_ino_t ino); |
paul@235 | 87 | |
paul@249 | 88 | errcode_t image_remove_by_path(ext2_filsys fs, const char *path, |
paul@249 | 89 | ext2_ino_t *ino); |
paul@248 | 90 | |
paul@236 | 91 | errcode_t image_rename(ext2_filsys fs, ext2_ino_t source, |
paul@236 | 92 | ext2_ino_t source_parent, const char *source_basename, |
paul@236 | 93 | ext2_ino_t target_parent, const char *target_basename); |
paul@236 | 94 | |
paul@181 | 95 | void image_set_metadata(struct ext2_inode *inode, int clean, __u16 mode, |
paul@181 | 96 | __u16 uid, __u16 gid); |
paul@181 | 97 | |
paul@181 | 98 | errcode_t image_stat_inode(ext2_filsys fs, ext2_ino_t ino, struct stat *st); |
paul@181 | 99 | |
paul@231 | 100 | errcode_t image_unlink_by_name(ext2_filsys fs, ext2_ino_t ino_parent, |
paul@231 | 101 | const char *basename); |
paul@231 | 102 | |
paul@243 | 103 | errcode_t image_unlink_by_path(ext2_filsys fs, const char *path); |
paul@243 | 104 | |
paul@231 | 105 | errcode_t image_unlink_by_inode(ext2_filsys fs, ext2_ino_t ino_parent, |
paul@231 | 106 | ext2_ino_t ino); |
paul@231 | 107 | |
paul@243 | 108 | /* Presence and type tests. */ |
paul@243 | 109 | |
paul@258 | 110 | int image_exists(ext2_filsys fs, const char *path); |
paul@243 | 111 | |
paul@258 | 112 | int image_isdir_by_inode(ext2_filsys fs, ext2_ino_t ino); |
paul@181 | 113 | |
paul@258 | 114 | int image_isdir_by_path(ext2_filsys fs, const char *path); |
paul@181 | 115 | |
paul@258 | 116 | int image_isfile_by_inode(ext2_filsys fs, ext2_ino_t ino); |
paul@181 | 117 | |
paul@258 | 118 | int image_isfile_by_path(ext2_filsys fs, const char *path); |
paul@255 | 119 | |
paul@181 | 120 | #ifdef __cplusplus |
paul@181 | 121 | } |
paul@181 | 122 | #endif |
paul@181 | 123 | |
paul@181 | 124 | |
paul@181 | 125 | #endif /* __IMAGE_H__ */ |
paul@249 | 126 | |
paul@249 | 127 | /* vim: tabstop=4 expandtab shiftwidth=4 |
paul@249 | 128 | */ |