libgphoto2 (libgphoto2): libgphoto2/gphoto2-filesys.c File Reference

- Main Page
- Data Structures
- Files
- Directories
- Related Pages

- File List
- Globals

# gphoto2-filesys.c File Reference

`#include "config.h"`
`#include <gphoto2/gphoto2-filesys.h>`
`#include <stdlib.h>`
`#include <string.h>`
`#include <stdio.h>`
`#include <unistd.h>`
`#include <gphoto2/gphoto2-result.h>`
`#include <gphoto2/gphoto2-file.h>`
`#include <gphoto2/gphoto2-port-log.h>`
`#include <gphoto2/gphoto2-setting.h>`
`#include <limits.h>`

## Data Structures
struct | _CameraFilesystemFile
struct | CameraFilesystemFolder
struct | _CameraFilesystem
## Defines
#define | textdomain(String) (String)
#define | gettext(String) (String)
#define | dgettext(Domain, Message) (Message)
#define | dcgettext(Domain, Message, Type) (Message)
#define | bindtextdomain(Domain, Directory) (Domain)
#define | _(String) (String)
#define | N_(String) (String)
#define | GP_MODULE "libgphoto2"
#define | PATH_MAX 4096
#define | PICTURES_TO_KEEP 2
#define | MIN(a, b) (((a) < (b)) ? (a) : (b))
#define | CHECK_NULL(r) {if (!(r)) return (GP_ERROR_BAD_PARAMETERS);}
#define | CR(result) {int r = (result); if (r < 0) return (r);}
#define | CHECK_MEM(m) {if (!(m)) return (GP_ERROR_NO_MEMORY);}
#define | CL(result, list)
#define | CU(result, file)
#define | CC(context)
#define | CA(f, c)
#define | CBO(bufsize, string_len, msg)
## Typedefs
typedef _CameraFilesystemFile | CameraFilesystemFile
## Functions
int | gp_filesystem_reset (CameraFilesystem *fs)
int | gp_filesystem_new (CameraFilesystem **fs)
int | gp_filesystem_free (CameraFilesystem *fs)
int | gp_filesystem_append (CameraFilesystem *fs, const char *folder, const char *filename, GPContext *context)
int | gp_filesystem_dump (CameraFilesystem *fs)
int | gp_filesystem_delete_all (CameraFilesystem *fs, const char *folder, GPContext *context)
int | gp_filesystem_list_files (CameraFilesystem *fs, const char *folder, CameraList *list, GPContext *context)
int | gp_filesystem_list_folders (CameraFilesystem *fs, const char *folder, CameraList *list, GPContext *context)
int | gp_filesystem_count (CameraFilesystem *fs, const char *folder, GPContext *context)
int | gp_filesystem_delete_file (CameraFilesystem *fs, const char *folder, const char *filename, GPContext *context)
int | gp_filesystem_delete_file_noop (CameraFilesystem *fs, const char *folder, const char *filename, GPContext *context)
in given @folder.
Return value: a gphoto2 error code
int | gp_filesystem_make_dir (CameraFilesystem *fs, const char *folder, const char *name, GPContext *context)
int | gp_filesystem_remove_dir (CameraFilesystem *fs, const char *folder, const char *name, GPContext *context)
int | gp_filesystem_put_file (CameraFilesystem *fs, const char *folder, CameraFile *file, GPContext *context)
int | gp_filesystem_name (CameraFilesystem *fs, const char *folder, int filenumber, const char **filename, GPContext *context)
int | gp_filesystem_number (CameraFilesystem *fs, const char *folder, const char *filename, GPContext *context)
int | gp_filesystem_get_folder (CameraFilesystem *fs, const char *filename, const char **folder, GPContext *context)
int | gp_filesystem_set_list_funcs (CameraFilesystem *fs, CameraFilesystemListFunc file_list_func, CameraFilesystemListFunc folder_list_func, void *data)
int | gp_filesystem_set_file_funcs (CameraFilesystem *fs, CameraFilesystemGetFileFunc get_file_func, CameraFilesystemDeleteFileFunc del_file_func, void *data)
int | gp_filesystem_set_folder_funcs (CameraFilesystem *fs, CameraFilesystemPutFileFunc put_file_func, CameraFilesystemDeleteAllFunc delete_all_func, CameraFilesystemDirFunc make_dir_func, CameraFilesystemDirFunc remove_dir_func, void *data)
int | gp_filesystem_get_file (CameraFilesystem *fs, const char *folder, const char *filename, CameraFileType type, CameraFile *file, GPContext *context)
int | gp_filesystem_set_info_funcs (CameraFilesystem *fs, CameraFilesystemGetInfoFunc get_info_func, CameraFilesystemSetInfoFunc set_info_func, void *data)
int | gp_filesystem_set_funcs (CameraFilesystem *fs, CameraFilesystemFuncs *funcs, void *data)
int | gp_filesystem_get_info (CameraFilesystem *fs, const char *folder, const char *filename, CameraFileInfo *info, GPContext *context)
int | gp_filesystem_set_file_noop (CameraFilesystem *fs, const char *folder, CameraFile *file, GPContext *context)
int | gp_filesystem_set_info_noop (CameraFilesystem *fs, const char *folder, CameraFileInfo info, GPContext *context)
int | gp_filesystem_set_info (CameraFilesystem *fs, const char *folder, const char *filename, CameraFileInfo info, GPContext *context)

## Detailed Description

gp_filesystem_get_file: : a CameraFilesystem : the folder in which the file can be found : the name of the file to download : the type of the file

: a GPContext

Downloads the file called from the using the get_file_func if such a function has been previously supplied. If the file has been previously downloaded, the file is retrieved from cache.

Return value: a gphoto2 error code.

## Define Documentation

#define CA | ( | f,
|  | c |  | ) |

Value:

    {                                                                       \
            if ((f)[0] != '/') {                                            \
                    gp_context_error ((c),                                  \
                            _("The path '%s' is not absolute."), (f));      \
                    return (GP_ERROR_PATH_NOT_ABSOLUTE);                    \
            }                                                               \
    }

#define CBO | ( | bufsize,
|  | string_len,
|  | msg |  | ) |

Value:

    if (bufsize <= string_len) { \
                    GP_DEBUG ("%s: strlen(...) = %d " \
                            ">= sizeof(buffer) = %d", \
                            msg, (int)string_len, (int)bufsize \
                    ); \
                    gp_context_error (context, "preventing buffer overflow"); \
                    return GP_ERROR; \
            }

check for buffer overflow

#define CC | ( | context |  | ) |

Value:

    {                                                                       \
            if (gp_context_cancel (context) == GP_CONTEXT_FEEDBACK_CANCEL)  \
                    return GP_ERROR_CANCEL;                                 \
    }

#define CL | ( | result,
|  | list |  | ) |

Value:

    {                                       \
            int r = (result);               \
                                            \
             if (r < 0) {                   \
                    gp_list_free (list);    \
                    return (r);             \
            }                               \
    }

#define CU | ( | result,
|  | file |  | ) |

Value:

    {                                       \
            int r = (result);               \
                                            \
            if (r < 0) {                    \
                    gp_file_unref (file);   \
                    return (r);             \
            }                               \
    }

## Function Documentation

int gp_filesystem_append | ( | CameraFilesystem * | fs,
|  | const char * | folder,
|  | const char * | filename,
|  | GPContext * | context |
| ) |  |  |

gp_filesystem_append: : a CameraFilesystem : the folder where to put the file in : filename of the file : a GPContext

Tells the that there is a file called in folder called . Usually, camera drivers will call this function after capturing an image in order to tell the about the new file. A front-end should not use this function.

Return value: a gphoto2 error code.

int gp_filesystem_count | ( | CameraFilesystem * | fs,
|  | const char * | folder,
|  | GPContext * | context |
| ) |  |  |

gp_filesystem_count: : a CameraFilesystem : a folder in which to count the files : a GPContext

Counts the files in the .

Return value: The number of files in the or a gphoto2 error code.

int gp_filesystem_delete_all | ( | CameraFilesystem * | fs,
|  | const char * | folder,
|  | GPContext * | context |
| ) |  |  |

gp_filesystem_delete_all : a CameraFilesystem : the folder in which to delete all files : a GPContext

Deletes all files in the given from the . If the has not been supplied with a delete_all_func, it tries to delete the files one by one using the delete_file_func. If that function has not been supplied neither, an error is returned.

Return value: a gphoto2 error code.

int gp_filesystem_delete_file | ( | CameraFilesystem * | fs,
|  | const char * | folder,
|  | const char * | filename,
|  | GPContext * | context |
| ) |  |  |

gp_filesystem_delete_file: : a CameraFilesystem : a folder in which to delete the file : the name of the file to delete : a GPContext

If a delete_file_func has been supplied to the , this function will be called and, if this function returns without error, the file will be removed from the .

Return value: a gphoto2 error code.

int gp_filesystem_free | ( | CameraFilesystem * | fs | ) |

gp_filesystem_free: : a CameraFilesystem

Frees the CameraFilesystem

Return value: a gphoto2 error code.

int gp_filesystem_get_folder | ( | CameraFilesystem * | fs,
|  | const char * | filename,
|  | const char ** | folder,
|  | GPContext * | context |
| ) |  |  |

gp_filesystem_get_folder: : a CameraFilesystem : the name of the file to search in the : : a GPContext

Searches a file called in the and returns the first occurrency. This functionality is needed for camera drivers that cannot figure out where a file gets created after capturing an image although the name of the image is known. Usually, those drivers will call gp_filesystem_reset in order to tell the that something has changed and then gp_filesystem_get_folder in order to find the file.

Return value: a gphoto2 error code.

int gp_filesystem_get_info | ( | CameraFilesystem * | fs,
|  | const char * | folder,
|  | const char * | filename,
|  | CameraFileInfo * | info,
|  | GPContext * | context |
| ) |  |  |

gp_filesystem_get_info: : a CameraFilesystem : : : : a GPContext

Return value: a gphoto2 error code.

int gp_filesystem_list_files | ( | CameraFilesystem * | fs,
|  | const char * | folder,
|  | CameraList * | list,
|  | GPContext * | context |
| ) |  |  |

gp_filesystem_list_files: : a CameraFilesystem : a folder of which a file list should be generated : a CameraList where to put the list of files into : a GPContext

Lists the files in using either cached values or (if there aren't any) the file_list_func which (hopefully) has been previously supplied.

Return value: a gphoto2 error code.

int gp_filesystem_list_folders | ( | CameraFilesystem * | fs,
|  | const char * | folder,
|  | CameraList * | list,
|  | GPContext * | context |
| ) |  |  |

gp_filesystem_list_folders: : a CameraFilesystem : a folder : a CameraList where subfolders should be listed : a GPContext

Generates a list of subfolders of the supplied either using cached values (if there are any) or the folder_list_func if it has been supplied previously. If not, it is assumed that only a root folder exists (which is the case for many cameras).

Return value: a gphoto2 error code.

int gp_filesystem_name | ( | CameraFilesystem * | fs,
|  | const char * | folder,
|  | int | filenumber,
|  | const char ** | filename,
|  | GPContext * | context |
| ) |  |  |

gp_filesystem_name: : a CameraFilesystem : the folder where to look up the file with the : the number of the file : : a GPContext

Looks up the of file with given in given . See gp_filesystem_number for exactly the opposite functionality.

Return value: a gphoto2 error code.

int gp_filesystem_new | ( | CameraFilesystem ** | fs | ) |

gp_filesystem_new: : a pointer to a CameraFilesystem

Creates a new empty CameraFilesystem

Return value: a gphoto2 error code.

int gp_filesystem_number | ( | CameraFilesystem * | fs,
|  | const char * | folder,
|  | const char * | filename,
|  | GPContext * | context |
| ) |  |  |

gp_filesystem_number: : a CameraFilesystem : the folder where to look for file called : the file to look for : a GPContext

Looks for a file called in the given . See gp_filesystem_name for exactly the opposite functionality.

Return value: a gphoto2 error code.

int gp_filesystem_reset | ( | CameraFilesystem * | fs | ) |

gp_filesystem_reset: : a CameraFilesystem

Resets the filesystem. All cached information including the folder tree will get lost and will be queried again on demand.

Return value: a gphoto2 error code.

int gp_filesystem_set_file_funcs | ( | CameraFilesystem * | fs,
|  | CameraFilesystemGetFileFunc | get_file_func,
|  | CameraFilesystemDeleteFileFunc | del_file_func,
|  | void * | data |
| ) |  |  |

gp_filesystem_set_file_funcs: : a CameraFilesystem : the function downloading files : the function deleting files :

Tells the which functions to use for file download or file deletion. Typically, a camera driver would call this function on initialization. A function can be NULL indicating that this functionality is not supported. For example, if a camera does not support file deletion, you would supply NULL for del_file_func.

Return value: a gphoto2 error code.

int gp_filesystem_set_folder_funcs | ( | CameraFilesystem * | fs,
|  | CameraFilesystemPutFileFunc | put_file_func,
|  | CameraFilesystemDeleteAllFunc | delete_all_func,
|  | CameraFilesystemDirFunc | make_dir_func,
|  | CameraFilesystemDirFunc | remove_dir_func,
|  | void * | data |
| ) |  |  |

gp_filesystem_set_folder_funcs: : a CameraFilesystem : function used to upload files : function used to delete all files in a folder : function used to create a new directory : function used to remove an existing directory : a data object that will passed to all called functions

Tells the filesystem which functions to call for file upload, deletion of all files in a given folder, creation or removal of a folder. Typically, a camera driver would call this function on initialization. If one functionality is not supported, NULL can be supplied. If you don't call this function, the will assume that neither of these features is supported.

The will try to compensate missing functionality with the delete_file_func if such a function has been supplied.

Return value: a gphoto2 error code.

int gp_filesystem_set_funcs | ( | CameraFilesystem * | fs,
|  | CameraFilesystemFuncs * | funcs,
|  | void * | data |
| ) |  |  |

gp_filesystem_set_funcs: : a CameraFilesystem : pointer to a struct of filesystem functions :

Tells the filesystem which functions to call for camera/filesystem specific functions.

Return value: a gphoto2 error code.

int gp_filesystem_set_info | ( | CameraFilesystem * | fs,
|  | const char * | folder,
|  | const char * | filename,
|  | CameraFileInfo | info,
|  | GPContext * | context |
| ) |  |  |

gp_filesystem_set_info: : a CameraFilesystem : : : : a GPContext

Return value: a gphoto2 error code.

int gp_filesystem_set_info_funcs | ( | CameraFilesystem * | fs,
|  | CameraFilesystemGetInfoFunc | get_info_func,
|  | CameraFilesystemSetInfoFunc | set_info_func,
|  | void * | data |
| ) |  |  |

gp_filesystem_set_info_funcs: : a CameraFilesystem : the function to retrieve file information : the function to set file information :

Tells the filesystem which functions to call when file information about a file should be retrieved or set. Typically, this function will get called by the camera driver on initialization.

Return value: a gphoto2 error code.

int gp_filesystem_set_info_noop | ( | CameraFilesystem * | fs,
|  | const char * | folder,
|  | CameraFileInfo | info,
|  | GPContext * | context |
| ) |  |  |

gp_filesystem_set_info_noop: : a CameraFilesystem : : : a GPContext

In contrast to gp_filesystem_set_info, gp_filesystem_set_info_noop will only change the file information in the . Typically, camera drivers will use this function in case they get file information "for free" on gp_camera_capture or gp_camera_folder_list_files.

Return value: a gphoto2 error code

int gp_filesystem_set_list_funcs | ( | CameraFilesystem * | fs,
|  | CameraFilesystemListFunc | file_list_func,
|  | CameraFilesystemListFunc | folder_list_func,
|  | void * | data |
| ) |  |  |

gp_filesystem_set_list_funcs: : a CameraFilesystem : the function that will return listings of files : the function that will return listings of folders :

Tells the which functions to use to retrieve listings of folders and/or files. Typically, a camera driver would call this function on initialization. Each function can be NULL indicating that this functionality is not supported. For example, many cameras don't support folders. In this case, you would supply NULL for folder_list_func. Then, the assumes that there is only a root folder.

Return value: a gphoto2 error code.