gphoto2-filesys.h 15 KB

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