1 /** \file 2 * \brief Filesystem related operations and declarations. 3 * 4 * \author Copyright 2000 Scott Fritzinger 5 * \author Copyright 2008-2009 Marcus Meissner 6 * 7 * \note 8 * Contributions: 9 * Lutz Mueller <lutz@users.sf.net> (2001) 10 * 11 * \note 12 * This library is free software; you can redistribute it and/or 13 * modify it under the terms of the GNU Lesser General Public 14 * License as published by the Free Software Foundation; either 15 * version 2 of the License, or (at your option) any later version. 16 * 17 * \note 18 * This library is distributed in the hope that it will be useful, 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 * Lesser General Public License for more details. 22 * 23 * \note 24 * You should have received a copy of the GNU Lesser General Public 25 * License along with this library; if not, write to the 26 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 27 * Boston, MA 02110-1301 USA 28 */ 29 30 #ifndef __GPHOTO2_FILESYS_H__ 31 #define __GPHOTO2_FILESYS_H__ 32 33 #include <time.h> 34 #include <stdint.h> 35 36 #include <gphoto2/gphoto2-context.h> 37 #include <gphoto2/gphoto2-list.h> 38 #include <gphoto2/gphoto2-file.h> 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif /* __cplusplus */ 43 44 /** 45 * \brief Bitmask on what fields are set in the CameraFileInfo structure. 46 * 47 * Bitmask to mark up which fields are set in the CameraFileInfo 48 * structure. The other fields might be uninitialized. 49 * If you set information via gp_camera_file_set_info() you 50 * need to set those flags. If you retrieve information via 51 * gp_camera_file_get_info() you need to check those flags. 52 * They are separate for both "normal" and "preview" parts 53 * and are mostly image related. 54 */ 55 typedef enum { 56 GP_FILE_INFO_NONE = 0, /**< \brief No fields set. */ 57 GP_FILE_INFO_TYPE = 1 << 0, /**< \brief The MIME type is set. */ 58 GP_FILE_INFO_SIZE = 1 << 2, /**< \brief The filesize is set. */ 59 GP_FILE_INFO_WIDTH = 1 << 3, /**< \brief The width is set. */ 60 GP_FILE_INFO_HEIGHT = 1 << 4, /**< \brief The height is set. */ 61 GP_FILE_INFO_PERMISSIONS = 1 << 5, /**< \brief The access permissions are set. */ 62 GP_FILE_INFO_STATUS = 1 << 6, /**< \brief The status is set (downloaded). */ 63 GP_FILE_INFO_MTIME = 1 << 7, /**< \brief The modification time is set. */ 64 GP_FILE_INFO_ALL = 0xFF /**< \brief All possible fields set. Internal. */ 65 } CameraFileInfoFields; 66 67 /** 68 * \brief Bitmask containing the file permission flags. 69 * 70 * Possible flag values of the permission entry in the file information. 71 */ 72 typedef enum { 73 GP_FILE_PERM_NONE = 0, /**< \brief No permissions. */ 74 GP_FILE_PERM_READ = 1 << 0, /**< \brief Read permissions. */ 75 GP_FILE_PERM_DELETE = 1 << 1, /**< \brief Write permissions */ 76 GP_FILE_PERM_ALL = 0xFF /**< \brief Internal. */ 77 } CameraFilePermissions; 78 79 /** 80 * \brief Possible status values. 81 * 82 * Bitmask of possible stati. Currently only download is supported. 83 */ 84 typedef enum { 85 GP_FILE_STATUS_NOT_DOWNLOADED, /**< File is not downloaded. */ 86 GP_FILE_STATUS_DOWNLOADED /**< File is already downloaded. */ 87 } CameraFileStatus; 88 89 /** 90 * \brief File information of a regular file. 91 * 92 * Contains information a regular file with fields being 93 * set depending on the bitmask in the fields member. 94 */ 95 typedef struct _CameraFileInfoFile { 96 CameraFileInfoFields fields; /**< \brief Bitmask containing the set members. */ 97 CameraFileStatus status; /**< \brief Status of the file. */ 98 uint64_t size; /**< \brief Size of the file. */ 99 char type[64]; /**< \brief MIME type of the file. */ 100 uint32_t width; /**< \brief Height of the file. */ 101 uint32_t height; /**< \brief Width of the file. */ 102 CameraFilePermissions permissions;/**< \brief Permissions of the file. */ 103 time_t mtime; /**< \brief Modification time of the file. */ 104 } CameraFileInfoFile; 105 106 /** 107 * \brief File information of a preview file. 108 * 109 * Contains information of a preview file with fields being 110 * set depending on the bitmask in the fields member. 111 */ 112 typedef struct _CameraFileInfoPreview { 113 CameraFileInfoFields fields; /**< \brief Bitmask containing the set members. */ 114 CameraFileStatus status; /**< \brief Status of the preview. */ 115 uint64_t size; /**< \brief Size of the preview. */ 116 char type[64]; /**< \brief MIME type of the preview. */ 117 118 uint32_t width; /**< \brief Width of the preview. */ 119 uint32_t height; /**< \brief Height of the preview. */ 120 } CameraFileInfoPreview; 121 122 /** 123 * \brief File information of an audio file. 124 * 125 * Contains information of an audio file with fields being 126 * set depending on the bitmask in the fields member. 127 */ 128 typedef struct _CameraFileInfoAudio { 129 CameraFileInfoFields fields; /**< \brief Bitmask containing the set members. */ 130 CameraFileStatus status; /**< \brief Status of the preview file. */ 131 uint64_t size; /**< \brief Size of the audio file. */ 132 char type[64]; /**< \brief MIME type of the audio file. */ 133 } CameraFileInfoAudio; 134 135 /** 136 * \brief File information structure. 137 * 138 * Contains the normal, preview and audio file information structures 139 * for a specific file. 140 */ 141 typedef struct _CameraFileInfo { 142 CameraFileInfoPreview preview; 143 CameraFileInfoFile file; 144 CameraFileInfoAudio audio; 145 } CameraFileInfo; 146 147 /** 148 * \brief Storage information flags. 149 * 150 * Bitmask to specify which entries of the filesystem 151 * storage information is set. 152 */ 153 typedef enum { 154 GP_STORAGEINFO_BASE = (1<<0), /**< \brief The base directory. 155 * Usually / if just 1 storage is attached. 156 */ 157 GP_STORAGEINFO_LABEL = (1<<1), /**< \brief Label of the filesystem. 158 * Could also be a DOS label. 159 */ 160 GP_STORAGEINFO_DESCRIPTION = (1<<2), /**< \brief More verbose description. */ 161 GP_STORAGEINFO_ACCESS = (1<<3), /**< \brief Access permissions. */ 162 GP_STORAGEINFO_STORAGETYPE = (1<<4), /**< \brief Hardware type. */ 163 GP_STORAGEINFO_FILESYSTEMTYPE = (1<<5), /**< \brief Filesystem type. */ 164 GP_STORAGEINFO_MAXCAPACITY = (1<<6), /**< \brief Maximum capacity in kbytes */ 165 GP_STORAGEINFO_FREESPACEKBYTES = (1<<7), /**< \brief Free space in kbytes. */ 166 GP_STORAGEINFO_FREESPACEIMAGES = (1<<8) /**< \brief Free space in images. */ 167 } CameraStorageInfoFields; 168 169 /** 170 * \brief Hardware storage types. 171 * 172 * Type of hardware this storage is on. The types and values 173 * are the same as the PTP standard uses (PTP_ST_xxx). 174 */ 175 typedef enum { 176 GP_STORAGEINFO_ST_UNKNOWN = 0, /**< \brief Unknown storage type. */ 177 GP_STORAGEINFO_ST_FIXED_ROM = 1, /**< \brief A fixed ROM storage. */ 178 GP_STORAGEINFO_ST_REMOVABLE_ROM = 2, /**< \brief A removable ROM storage. */ 179 GP_STORAGEINFO_ST_FIXED_RAM = 3, /**< \brief A fixed RAM storage. (e.g. SDRAM) */ 180 GP_STORAGEINFO_ST_REMOVABLE_RAM = 4 /**< \brief A removable RAM storage. (any kind of cards etc) */ 181 } CameraStorageType; 182 183 /** 184 * \brief Storage access modes. 185 * 186 * The modes we can access the storage with. Uses the same 187 * types and values as the PTP standard (PTP_AC_xxx). 188 */ 189 typedef enum { 190 GP_STORAGEINFO_AC_READWRITE = 0, /**< \brief Storage is Read / Write. */ 191 GP_STORAGEINFO_AC_READONLY = 1, /**< \brief Storage is Ready Only. */ 192 GP_STORAGEINFO_AC_READONLY_WITH_DELETE = 2 /**< \brief Storage is Ready Only, but allows Delete.*/ 193 } CameraStorageAccessType; 194 195 /** 196 * \brief Filesystem hierarchy types. 197 * 198 * The type of the filesystem hierarchy the devices uses. 199 * Same types and values as the PTP standard defines (PTP_FST_xxx). 200 */ 201 typedef enum { 202 GP_STORAGEINFO_FST_UNDEFINED = 0, /**< \brief Undefined or unknown filesystem hierarchy. */ 203 GP_STORAGEINFO_FST_GENERICFLAT = 1, /**< \brief Generic flat storage (all in 1 directory). */ 204 GP_STORAGEINFO_FST_GENERICHIERARCHICAL = 2, /**< \brief Generic tree hierarchy. */ 205 GP_STORAGEINFO_FST_DCF = 3 /**< \brief DCIM style storage. */ 206 } CameraStorageFilesystemType; 207 208 /** 209 * \brief Storage information structue. 210 * 211 * This structure contains the information of a specific camera storage. 212 * Only the members as specified by the \a fields member are valid. 213 */ 214 typedef struct _CameraStorageInformation { 215 CameraStorageInfoFields fields; /**< \brief Bitmask of struct members that are specified. */ 216 char basedir[256]; /**< \brief Basedirectory of the storage. Will be "/" if just 1 storage on the camera. */ 217 char label[256]; /**< \brief Label of the storage. Similar to DOS label. */ 218 char description[256];/**< \brief Description of the storage. */ 219 CameraStorageType type; /**< \brief Hardware type of the storage. */ 220 CameraStorageFilesystemType fstype; /**< \brief Hierarchy type of the filesystem. */ 221 CameraStorageAccessType access; /**< \brief Access permissions. */ 222 uint64_t capacitykbytes; /**< \brief Total capacity in kbytes. */ 223 uint64_t freekbytes; /**< \brief Free space in kbytes. */ 224 uint64_t freeimages; /**< \brief Free space in images (guessed by camera). */ 225 } CameraStorageInformation; 226 227 /** 228 * \brief Filesystem structure, only exposed to camera drivers. 229 * 230 * Internal structure, contents not exposed to frontends. Camera 231 * drivers get these passed to filesystem related functions and 232 * are supposed to use it only via the accessor functions. 233 */ 234 typedef struct _CameraFilesystem CameraFilesystem; 235 236 int gp_filesystem_new (CameraFilesystem **fs); 237 int gp_filesystem_free (CameraFilesystem *fs); 238 239 /* Manual editing */ 240 int gp_filesystem_append (CameraFilesystem *fs, const char *folder, 241 const char *filename, GPContext *context); 242 int gp_filesystem_set_info_noop (CameraFilesystem *fs, 243 const char *folder, const char *filename, 244 CameraFileInfo info, GPContext *context); 245 int gp_filesystem_set_file_noop (CameraFilesystem *fs, 246 const char *folder, const char *filename, 247 CameraFileType type, 248 CameraFile *file, GPContext *context); 249 int gp_filesystem_delete_file_noop (CameraFilesystem *fs, const char *folder, 250 const char *filename, GPContext *context); 251 int gp_filesystem_reset (CameraFilesystem *fs); 252 253 /* Information retrieval */ 254 int gp_filesystem_count (CameraFilesystem *fs, const char *folder, 255 GPContext *context); 256 int gp_filesystem_name (CameraFilesystem *fs, const char *folder, 257 int filenumber, const char **filename, 258 GPContext *context); 259 int gp_filesystem_get_folder (CameraFilesystem *fs, const char *filename, 260 char **folder, GPContext *context); 261 int gp_filesystem_number (CameraFilesystem *fs, const char *folder, 262 const char *filename, GPContext *context); 263 264 /* Listings */ 265 typedef int (*CameraFilesystemListFunc) (CameraFilesystem *fs, 266 const char *folder, CameraList *list, 267 void *data, GPContext *context); 268 int gp_filesystem_list_files (CameraFilesystem *fs, const char *folder, 269 CameraList *list, GPContext *context); 270 int gp_filesystem_list_folders (CameraFilesystem *fs, const char *folder, 271 CameraList *list, GPContext *context); 272 273 /* File information */ 274 typedef int (*CameraFilesystemSetInfoFunc) (CameraFilesystem *fs, 275 const char *folder, 276 const char *filename, 277 CameraFileInfo info, void *data, 278 GPContext *context); 279 typedef int (*CameraFilesystemGetInfoFunc) (CameraFilesystem *fs, 280 const char *folder, 281 const char *filename, 282 CameraFileInfo *info, void *data, 283 GPContext *context); 284 int gp_filesystem_get_info (CameraFilesystem *fs, const char *folder, 285 const char *filename, CameraFileInfo *info, 286 GPContext *context); 287 int gp_filesystem_set_info (CameraFilesystem *fs, const char *folder, 288 const char *filename, CameraFileInfo info, 289 GPContext *context); 290 291 /* Files */ 292 typedef int (*CameraFilesystemGetFileFunc) (CameraFilesystem *fs, 293 const char *folder, 294 const char *filename, 295 CameraFileType type, 296 CameraFile *file, void *data, 297 GPContext *context); 298 typedef int (*CameraFilesystemReadFileFunc) (CameraFilesystem *fs, 299 const char *folder, 300 const char *filename, 301 CameraFileType type, 302 uint64_t offset, 303 char *buf, 304 uint64_t *size, 305 void *data, 306 GPContext *context); 307 typedef int (*CameraFilesystemDeleteFileFunc) (CameraFilesystem *fs, 308 const char *folder, 309 const char *filename, 310 void *data, GPContext *context); 311 int gp_filesystem_get_file (CameraFilesystem *fs, const char *folder, 312 const char *filename, CameraFileType type, 313 CameraFile *file, GPContext *context); 314 int gp_filesystem_read_file (CameraFilesystem *fs, const char *folder, 315 const char *filename, CameraFileType type, 316 uint64_t offset, char *buf, uint64_t *size, 317 GPContext *context); 318 int gp_filesystem_delete_file (CameraFilesystem *fs, const char *folder, 319 const char *filename, GPContext *context); 320 321 /* Folders */ 322 typedef int (*CameraFilesystemPutFileFunc) (CameraFilesystem *fs, 323 const char *folder, 324 const char *filename, 325 CameraFileType type, 326 CameraFile *file, 327 void *data, 328 GPContext *context); 329 typedef int (*CameraFilesystemDeleteAllFunc) (CameraFilesystem *fs, 330 const char *folder, void *data, 331 GPContext *context); 332 typedef int (*CameraFilesystemDirFunc) (CameraFilesystem *fs, 333 const char *folder, 334 const char *name, void *data, 335 GPContext *context); 336 337 typedef int (*CameraFilesystemStorageInfoFunc) (CameraFilesystem *fs, 338 CameraStorageInformation **, 339 int *nrofstorageinformations, 340 void *data, GPContext *context); 341 342 int gp_filesystem_get_storageinfo (CameraFilesystem *fs, 343 CameraStorageInformation **, 344 int *nrofstorageinformations, 345 GPContext *context); 346 347 typedef struct _CameraFilesystemFuncs CameraFilesystemFuncs; 348 struct _CameraFilesystemFuncs { 349 CameraFilesystemListFunc file_list_func; 350 CameraFilesystemListFunc folder_list_func; 351 CameraFilesystemPutFileFunc put_file_func; 352 CameraFilesystemDeleteAllFunc delete_all_func; 353 CameraFilesystemGetInfoFunc get_info_func; 354 CameraFilesystemSetInfoFunc set_info_func; 355 CameraFilesystemDirFunc make_dir_func; 356 CameraFilesystemDirFunc remove_dir_func; 357 CameraFilesystemGetFileFunc get_file_func; 358 CameraFilesystemReadFileFunc read_file_func; 359 CameraFilesystemDeleteFileFunc del_file_func; 360 CameraFilesystemStorageInfoFunc storage_info_func; 361 362 /* for later use. Remove one if you add a new function */ 363 void *unused[31]; 364 }; 365 int gp_filesystem_set_funcs (CameraFilesystem *fs, 366 CameraFilesystemFuncs *funcs, 367 void *data); 368 int gp_filesystem_put_file (CameraFilesystem *fs, const char *folder, const char *filename, 369 CameraFileType type, CameraFile *file, GPContext *context); 370 int gp_filesystem_delete_all (CameraFilesystem *fs, const char *folder, 371 GPContext *context); 372 int gp_filesystem_make_dir (CameraFilesystem *fs, const char *folder, 373 const char *name, GPContext *context); 374 int gp_filesystem_remove_dir (CameraFilesystem *fs, const char *folder, 375 const char *name, GPContext *context); 376 377 /* For debugging */ 378 int gp_filesystem_dump (CameraFilesystem *fs); 379 380 #ifdef __cplusplus 381 } 382 #endif /* __cplusplus */ 383 384 #endif /* __GPHOTO2_FILESYS_H__ */ 385