1 /******************************* LICENCE ************************************** 2 * Any code in this file may be redistributed or modified under the terms of 3 * the GNU General Public Licence as published by the Free Software 4 * Foundation; version 2 of the licence. 5 ****************************** END LICENCE ***********************************/ 6 7 /****************************************************************************** 8 * Author: 9 * Andrew Smith, http://littlesvr.ca/misc/contactandrew.php 10 * 11 * Contributors: 12 * 13 ******************************************************************************/ 14 15 /********************************* PURPOSE ************************************ 16 * bk.h 17 * This header file is the public interface to bkisofs. 18 ******************************** END PURPOSE *********************************/ 19 20 #ifndef bk_h 21 #define bk_h 22 23 #ifdef __cplusplus 24 extern "C" 25 { 26 #endif 27 28 #include <stdbool.h> 29 #include <unistd.h> 30 #include <stdlib.h> 31 #include <sys/types.h> 32 #include <limits.h> 33 #include <sys/time.h> 34 #include <stdio.h> 35 36 #include "bkError.h" 37 38 #ifdef WINDOWS_BUILD 39 /* on windows i can't get an off_t to be 64 bits */ 40 typedef long long bk_off_t; 41 #define bk_lseek _lseeki64 42 typedef struct _stati64 BkStatStruct; 43 #else 44 typedef off_t bk_off_t; 45 #define bk_lseek lseek 46 typedef struct stat BkStatStruct; 47 #endif 48 49 /* can be |ed */ 50 #define FNTYPE_9660 1 51 #define FNTYPE_ROCKRIDGE 2 52 #define FNTYPE_JOLIET 4 53 54 /* many library functions rely on this being at least 256 */ 55 #define NCHARS_FILE_ID_MAX_STORE 256 56 57 /* maximum length of the target of a symbolic link 58 * !! this is used for both the number of characters in the path and the number 59 * of bytes in the SL record, that should probably be fixed */ 60 #define NCHARS_SYMLINK_TARGET_MAX 251 61 62 /* maximum number of bytes to read from a file for comparing it quickly 63 * with others (is it likely to be a hard link or not) */ 64 #define MAX_NBYTES_HARDLINK_HEAD 32 65 66 /* options for VolInfo.bootMediaType */ 67 #define BOOT_MEDIA_NONE 0 68 #define BOOT_MEDIA_NO_EMULATION 1 69 #define BOOT_MEDIA_1_2_FLOPPY 2 /* 1228800 byte floppy disk image */ 70 #define BOOT_MEDIA_1_44_FLOPPY 3 /* 1474560 byte floppy disk image */ 71 #define BOOT_MEDIA_2_88_FLOPPY 4 /* 2949120 byte floppy disk image */ 72 #define BOOT_MEDIA_HARD_DISK 5 73 74 #define READ_WRITE_BUFFER_SIZE 102400 75 76 /* warning message string lengths in VolInfo */ 77 #define BK_WARNING_MAX_LEN 512 78 79 #define IS_DIR(posix) ((posix & 0770000) == 0040000) 80 #define IS_REG_FILE(posix) ((posix & 0770000) == 0100000) 81 #define IS_SYMLINK(posix) ((posix & 0770000) == 0120000) 82 83 #define BK_BASE_PTR(item) ((BkFileBase*)(item)) 84 #define BK_DIR_PTR(item) ((BkDir*)(item)) 85 #define BK_FILE_PTR(item) ((BkFile*)(item)) 86 #define BK_SYMLINK_PTR(item) ((BkSymLink*)(item)) 87 88 /******************************************************************************* 89 * BkFileBase 90 * Linked list node. 91 * All files, directories, links need this. */ 92 typedef struct BkFileBase 93 { 94 char original9660name[15]; /* 8.3 + ";1" max */ 95 char name[NCHARS_FILE_ID_MAX_STORE]; /* '\0' terminated */ 96 unsigned posixFileMode; /* file type and permissions */ 97 98 struct BkFileBase* next; 99 100 } BkFileBase; 101 102 /******************************************************************************* 103 * BkDir 104 * Linked list node. 105 * Information about a directory and it's contents. */ 106 typedef struct BkDir 107 { 108 BkFileBase base; /* intended to be accessed using a cast */ 109 110 BkFileBase* children; /* child directories, files, etc. */ 111 112 } BkDir; 113 114 /******************************************************************************* 115 * BkHardLink 116 * Linked list node. 117 * Information about a hard link (where to find a certain file). 118 * This is for internal use but is defined here because BkFile references it. 119 * You don't need to use this structure, please ignore it. */ 120 typedef struct BkHardLink 121 { 122 bool onImage; 123 bk_off_t position; /* if on image */ 124 char* pathAndName; /* if on filesystem, full path + filename 125 * is to be freed whenever the BkHardLink is freed */ 126 unsigned size; /* size of the file being pointed to */ 127 int headSize; 128 unsigned char head[MAX_NBYTES_HARDLINK_HEAD]; 129 bool alreadyCounted; /* for estimateIsoSize() */ 130 131 unsigned extentNumberWrittenTo; /* only set once one file is written */ 132 133 struct BkHardLink* next; 134 135 } BkHardLink; 136 137 /******************************************************************************* 138 * BkFile 139 * Linked list node. 140 * Information about a file, whether on the image or on the filesystem. */ 141 typedef struct BkFile 142 { 143 BkFileBase base; /* intended to be accessed using a cast */ 144 145 unsigned size; /* in bytes, don't need bk_off_t because it's stored 146 * in a 32bit unsigned int on the iso */ 147 BkHardLink* location; /* basically a copy of the following variables */ 148 bool onImage; 149 bk_off_t position; /* if on image, in bytes */ 150 char* pathAndName; /* if on filesystem, full path + filename 151 * is to be freed whenever the File is freed */ 152 153 } BkFile; 154 155 /******************************************************************************* 156 * BkSymLink 157 * Linked list node. 158 * Information about a symbolic link. */ 159 typedef struct BkSymLink 160 { 161 BkFileBase base; /* intended to be accessed using a cast */ 162 163 char target[NCHARS_SYMLINK_TARGET_MAX]; 164 165 } BkSymLink; 166 167 /******************************************************************************* 168 * VolInfo 169 * Information about a volume (one image). 170 * Strings are '\0' terminated. */ 171 typedef struct VolInfo 172 { 173 /* private bk use */ 174 unsigned filenameTypes; 175 bk_off_t pRootDrOffset; /* primary (9660 and maybe rockridge) */ 176 bk_off_t sRootDrOffset; /* secondary (joliet), 0 if does not exist */ 177 bk_off_t bootRecordSectorNumberOffset; 178 int imageForReading; 179 ino_t imageForReadingInode; /* to know which file was open for reading 180 * (filename is not reliable) */ 181 const BkFile* bootRecordOnImage; /* if visible, pointer to the file in the 182 * directory tree */ 183 char warningMessage[BK_WARNING_MAX_LEN]; 184 bool rootRead; /* did i read the root record inside volume descriptor? */ 185 bool stopOperation; /* cancel current opertion */ 186 int imageForWriting; 187 void(*progressFunction)(struct VolInfo*); 188 void(*writeProgressFunction)(struct VolInfo*, double); 189 struct timeval lastTimeCalledProgress; 190 bk_off_t estimatedIsoSize; 191 BkHardLink* fileLocations; /* list of where to find regular files */ 192 char readWriteBuffer[READ_WRITE_BUFFER_SIZE]; 193 char readWriteBuffer2[READ_WRITE_BUFFER_SIZE]; 194 195 /* public use, read only */ 196 time_t creationTime; 197 BkDir dirTree; 198 unsigned char bootMediaType; 199 unsigned bootRecordSize; /* in bytes */ 200 bool bootRecordIsOnImage; /* unused if visible (flag below) */ 201 bk_off_t bootRecordOffset; /* if on image */ 202 char* bootRecordPathAndName; /* if on filesystem */ 203 bool bootRecordIsVisible; /* whether boot record is a visible file 204 * on the image */ 205 bool scanForDuplicateFiles; /* whether to check every file for uniqueness 206 * to decide is it a hard link or not */ 207 208 /* public use, read/write */ 209 char volId[33]; 210 char publisher[129]; 211 char dataPreparer[129]; 212 unsigned posixFileDefaults; /* for extracting */ 213 unsigned posixDirDefaults; /* for extracting or creating on iso */ 214 bool(*warningCbk)(const char*); 215 bool followSymLinks; /* whether to stat the link itself rather 216 * than the file it's pointing to */ 217 218 } VolInfo; 219 220 /* public bkisofs functions */ 221 222 /* adding */ 223 int bk_add_boot_record(VolInfo* volInfo, const char* srcPathAndName, 224 int bootMediaType); 225 int bk_add(VolInfo* volInfo, const char* srcPathAndName, 226 const char* destPathStr, void(*progressFunction)(VolInfo*)); 227 int bk_add_as(VolInfo* volInfo, const char* srcPathAndName, 228 const char* destPathStr, const char* nameToUse, 229 void(*progressFunction)(VolInfo*)); 230 int bk_create_dir(VolInfo* volInfo, const char* destPathStr, 231 const char* newDirName); 232 233 /* deleting */ 234 void bk_delete_boot_record(VolInfo* volInfo); 235 int bk_delete(VolInfo* volInfo, const char* pathAndName); 236 237 /* extracting */ 238 int bk_extract_boot_record(VolInfo* volInfo, const char* destPathAndName, 239 unsigned destFilePerms); 240 int bk_extract(VolInfo* volInfo, const char* srcPathAndName, 241 const char* destDir, bool keepPermissions, 242 void(*progressFunction)(VolInfo*)); 243 int bk_extract_as(VolInfo* volInfo, const char* srcPathAndName, 244 const char* destDir, const char* nameToUse, 245 bool keepPermissions, void(*progressFunction)(VolInfo*)); 246 247 /* getters */ 248 bk_off_t bk_estimate_iso_size(const VolInfo* volInfo, int filenameTypes); 249 time_t bk_get_creation_time(const VolInfo* volInfo); 250 int bk_get_dir_from_string(const VolInfo* volInfo, const char* pathStr, 251 BkDir** dirFoundPtr); 252 int bk_get_permissions(VolInfo* volInfo, const char* pathAndName, 253 mode_t* permissions); 254 const char* bk_get_publisher(const VolInfo* volInfo); 255 const char* bk_get_volume_name(const VolInfo* volInfo); 256 const char* bk_get_error_string(int errorId); 257 258 /* setters */ 259 void bk_cancel_operation(VolInfo* volInfo); 260 void bk_destroy_vol_info(VolInfo* volInfo); 261 int bk_init_vol_info(VolInfo* volInfo, bool scanForDuplicateFiles); 262 int bk_rename(VolInfo* volInfo, const char* srcPathAndName, 263 const char* newName); 264 int bk_set_boot_file(VolInfo* volInfo, const char* srcPathAndName); 265 void bk_set_follow_symlinks(VolInfo* volInfo, bool doFollow); 266 int bk_set_permissions(VolInfo* volInfo, const char* pathAndName, 267 mode_t permissions); 268 int bk_set_publisher(VolInfo* volInfo, const char* publisher); 269 int bk_set_vol_name(VolInfo* volInfo, const char* volName); 270 271 /* reading */ 272 int bk_open_image(VolInfo* volInfo, const char* filename); 273 int bk_read_dir_tree(VolInfo* volInfo, int filenameType, 274 bool keepPosixPermissions, 275 void(*progressFunction)(VolInfo*)); 276 int bk_read_vol_info(VolInfo* volInfo); 277 278 /* writing */ 279 int bk_write_image(const char* newImagePathAndName, VolInfo* volInfo, 280 time_t creationTime, int filenameTypes, 281 void(*progressFunction)(VolInfo*, double)); 282 283 #ifdef __cplusplus 284 } 285 #endif 286 287 #endif 288