Blame contrib/libudfread/src/udfread.h

Packit 5e46da
/*
Packit 5e46da
 * This file is part of libudfread
Packit 5e46da
 * Copyright (C) 2014-2015 VLC authors and VideoLAN
Packit 5e46da
 *
Packit 5e46da
 * Authors: Petri Hintukainen <phintuka@users.sourceforge.net>
Packit 5e46da
 *
Packit 5e46da
 * This library is free software; you can redistribute it and/or
Packit 5e46da
 * modify it under the terms of the GNU Lesser General Public
Packit 5e46da
 * License as published by the Free Software Foundation; either
Packit 5e46da
 * version 2.1 of the License, or (at your option) any later version.
Packit 5e46da
 *
Packit 5e46da
 * This library is distributed in the hope that it will be useful,
Packit 5e46da
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 5e46da
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 5e46da
 * Lesser General Public License for more details.
Packit 5e46da
 *
Packit 5e46da
 * You should have received a copy of the GNU Lesser General Public
Packit 5e46da
 * License along with this library. If not, see
Packit 5e46da
 * <http://www.gnu.org/licenses/>.
Packit 5e46da
 */
Packit 5e46da
Packit 5e46da
#ifndef UDFREAD_H_
Packit 5e46da
#define UDFREAD_H_
Packit 5e46da
Packit 5e46da
#ifdef __cplusplus
Packit 5e46da
extern "C" {
Packit 5e46da
#endif
Packit 5e46da
Packit 5e46da
#include <stdint.h>    /* *int_t */
Packit 5e46da
#include <sys/types.h> /* *size_t */
Packit 5e46da
Packit 5e46da
/**
Packit 5e46da
 * @file udfread/udfread.h
Packit 5e46da
 * external API header
Packit 5e46da
 */
Packit 5e46da
Packit 5e46da
Packit 5e46da
/*
Packit 5e46da
 * UDF volume access
Packit 5e46da
 */
Packit 5e46da
Packit 5e46da
/* opaque handle for UDF volume */
Packit 5e46da
typedef struct udfread udfread;
Packit 5e46da
Packit 5e46da
struct udfread_block_input;
Packit 5e46da
Packit 5e46da
/**
Packit 5e46da
 *  Initialize UDF reader
Packit 5e46da
 *
Packit 5e46da
 * @return allocated udfread object, NULL if error
Packit 5e46da
 */
Packit 5e46da
udfread *udfread_init (void);
Packit 5e46da
Packit 5e46da
/**
Packit 5e46da
 *  Open UDF image
Packit 5e46da
 *
Packit 5e46da
 * @param p  udfread object
Packit 5e46da
 * @param input  UDF image access functions
Packit 5e46da
 * @return 0 on success, < 0 on error
Packit 5e46da
 */
Packit 5e46da
int udfread_open_input (udfread *, struct udfread_block_input *input);
Packit 5e46da
Packit 5e46da
/**
Packit 5e46da
 *  Open UDF image
Packit 5e46da
 *
Packit 5e46da
 * @param p  udfread object
Packit 5e46da
 * @param path  path to device or image file
Packit 5e46da
 * @return 0 on success, < 0 on error
Packit 5e46da
 */
Packit 5e46da
int udfread_open (udfread *, const char *path);
Packit 5e46da
Packit 5e46da
/**
Packit 5e46da
 *  Close UDF image
Packit 5e46da
 *
Packit 5e46da
 * @param p  udfread object
Packit 5e46da
 */
Packit 5e46da
void udfread_close (udfread *);
Packit 5e46da
Packit 5e46da
/**
Packit 5e46da
 *  Get UDF Volume Identifier
Packit 5e46da
 *
Packit 5e46da
 * @param p  udfread object
Packit 5e46da
 * @return Volume ID as null-terminated UTF-8 string, NULL if error
Packit 5e46da
 */
Packit 5e46da
const char *udfread_get_volume_id (udfread *);
Packit 5e46da
Packit 5e46da
/**
Packit 5e46da
 *  Get UDF Volume Set Identifier
Packit 5e46da
 *
Packit 5e46da
 * @param p  udfread object
Packit 5e46da
 * @param buffer buffer to receive volume set id
Packit 5e46da
 * @param size buffer size
Packit 5e46da
 * @return Volume set id size, 0 if error
Packit 5e46da
 */
Packit 5e46da
size_t udfread_get_volume_set_id (udfread *, void *buffer, size_t size);
Packit 5e46da
Packit 5e46da
Packit 5e46da
/*
Packit 5e46da
 * Directory access
Packit 5e46da
 */
Packit 5e46da
Packit 5e46da
/* File types for d_type */
Packit 5e46da
enum {
Packit 5e46da
    UDF_DT_UNKNOWN = 0,
Packit 5e46da
    UDF_DT_DIR,
Packit 5e46da
    UDF_DT_REG,
Packit 5e46da
};
Packit 5e46da
Packit 5e46da
/* Directory stream entry */
Packit 5e46da
struct udfread_dirent {
Packit 5e46da
    unsigned int  d_type;    /* UDF_DT_* */
Packit 5e46da
    const char   *d_name;    /* UTF-8 */
Packit 5e46da
};
Packit 5e46da
Packit 5e46da
/* opaque handle for directory stream */
Packit 5e46da
typedef struct udfread_dir UDFDIR;
Packit 5e46da
Packit 5e46da
/**
Packit 5e46da
 *  Open directory stream
Packit 5e46da
 *
Packit 5e46da
 * @param p  udfread object
Packit 5e46da
 * @param path  path to the directory
Packit 5e46da
 * @return directory stream on the directory, or NULL if it could not be opened.
Packit 5e46da
 */
Packit 5e46da
UDFDIR *udfread_opendir (udfread *, const char *path);
Packit 5e46da
Packit 5e46da
/**
Packit 5e46da
 *  Read directory stream
Packit 5e46da
 *
Packit 5e46da
 *  Read a directory entry from directory stream. Return a pointer to
Packit 5e46da
 *  udfread_dirent struct describing the entry, or NULL for EOF or error.
Packit 5e46da
 *
Packit 5e46da
 * @param p  directory stream
Packit 5e46da
 * @param entry  storege space for directory entry
Packit 5e46da
 * @return next directory stream entry, or NULL if EOF or error.
Packit 5e46da
 */
Packit 5e46da
struct udfread_dirent *udfread_readdir (UDFDIR *, struct udfread_dirent *entry);
Packit 5e46da
Packit 5e46da
/**
Packit 5e46da
 *  Rewind directory stream
Packit 5e46da
 *
Packit 5e46da
 *  Rewind directory stream to the beginning of the directory.
Packit 5e46da
 *
Packit 5e46da
 * @param p  directory stream
Packit 5e46da
 */
Packit 5e46da
void udfread_rewinddir (UDFDIR *);
Packit 5e46da
Packit 5e46da
/**
Packit 5e46da
 *  Close directory stream
Packit 5e46da
 *
Packit 5e46da
 * @param p  directory stream
Packit 5e46da
 */
Packit 5e46da
void udfread_closedir (UDFDIR *);
Packit 5e46da
Packit 5e46da
Packit 5e46da
/*
Packit 5e46da
 * File access
Packit 5e46da
 */
Packit 5e46da
Packit 5e46da
/**
Packit 5e46da
 * The length of one Logical Block
Packit 5e46da
 */
Packit 5e46da
Packit 5e46da
#ifndef UDF_BLOCK_SIZE
Packit 5e46da
#  define UDF_BLOCK_SIZE  2048
Packit 5e46da
#endif
Packit 5e46da
Packit 5e46da
/* opaque handle for open file */
Packit 5e46da
typedef struct udfread_file UDFFILE;
Packit 5e46da
Packit 5e46da
/**
Packit 5e46da
 *  Open a file
Packit 5e46da
 *
Packit 5e46da
 *  Allowed separator chars are \ and /.
Packit 5e46da
 *  Path to the file is always absolute (relative to disc image root).
Packit 5e46da
 *  Path may begin with single separator char.
Packit 5e46da
 *  Path may not contain "." or ".." directory components.
Packit 5e46da
 *
Packit 5e46da
 * @param p  udfread object
Packit 5e46da
 * @param path  path to the file
Packit 5e46da
 * @return file object, or NULL if it could not be opened.
Packit 5e46da
 */
Packit 5e46da
UDFFILE *udfread_file_open (udfread *, const char *path);
Packit 5e46da
Packit 5e46da
/**
Packit 5e46da
 *  Close file object
Packit 5e46da
 *
Packit 5e46da
 * @param p  file object
Packit 5e46da
 */
Packit 5e46da
void udfread_file_close (UDFFILE *);
Packit 5e46da
Packit 5e46da
/**
Packit 5e46da
 *  Get file size
Packit 5e46da
 *
Packit 5e46da
 * @param p  file object
Packit 5e46da
 * @return file size, -1 on error
Packit 5e46da
 */
Packit 5e46da
int64_t udfread_file_size (UDFFILE *);
Packit 5e46da
Packit 5e46da
/*
Packit 5e46da
 * Block access
Packit 5e46da
 */
Packit 5e46da
Packit 5e46da
/**
Packit 5e46da
 *  Get file block address
Packit 5e46da
 *
Packit 5e46da
 *  Convert file block number to absolute block address.
Packit 5e46da
 *
Packit 5e46da
 * @param p  file object
Packit 5e46da
 * @param file_block  file block number
Packit 5e46da
 * @return absolute block address, 0 on error
Packit 5e46da
 */
Packit 5e46da
uint32_t udfread_file_lba (UDFFILE *, uint32_t file_block);
Packit 5e46da
Packit 5e46da
/**
Packit 5e46da
 *  Read blocks from a file
Packit 5e46da
 *
Packit 5e46da
 * @param p  file object
Packit 5e46da
 * @param buf  buffer for data
Packit 5e46da
 * @param file_block  file block number
Packit 5e46da
 * @param num_blocks  number of blocks to read
Packit 5e46da
 * @return number of blocks read, 0 on error
Packit 5e46da
 */
Packit 5e46da
uint32_t udfread_read_blocks (UDFFILE *, void *buf, uint32_t file_block, uint32_t num_blocks, int flags);
Packit 5e46da
Packit 5e46da
Packit 5e46da
/*
Packit 5e46da
 * Byte streams
Packit 5e46da
 */
Packit 5e46da
Packit 5e46da
enum {
Packit 5e46da
    UDF_SEEK_SET = 0,
Packit 5e46da
    UDF_SEEK_CUR = 1,
Packit 5e46da
    UDF_SEEK_END = 2,
Packit 5e46da
};
Packit 5e46da
Packit 5e46da
/**
Packit 5e46da
 *  Read bytes from a file
Packit 5e46da
 *
Packit 5e46da
 *  Reads the given number of bytes from the file and increment the
Packit 5e46da
 *  current read position by number of bytes read.
Packit 5e46da
 *
Packit 5e46da
 * @param p  file object
Packit 5e46da
 * @param buf  buffer for data
Packit 5e46da
 * @param bytes  number of bytes to read
Packit 5e46da
 * @return number of bytes read, 0 on EOF, -1 on error
Packit 5e46da
 */
Packit 5e46da
ssize_t udfread_file_read (UDFFILE *, void *buf, size_t bytes);
Packit 5e46da
Packit 5e46da
/**
Packit 5e46da
 *  Get current read position of a file
Packit 5e46da
 *
Packit 5e46da
 * @param p  file object
Packit 5e46da
 * @return current read position of the file, -1 on error
Packit 5e46da
 */
Packit 5e46da
int64_t udfread_file_tell (UDFFILE *);
Packit 5e46da
Packit 5e46da
/**
Packit 5e46da
 *  Set read position of a file
Packit 5e46da
 *
Packit 5e46da
 *  New read position is calculated from offset according to the directive whence as follows:
Packit 5e46da
 *    UDF_SEEK_SET  The offset is set to offset bytes.
Packit 5e46da
 *    UDF_SEEK_CUR  The offset is set to its current location plus offset bytes.
Packit 5e46da
 *    UDF_SEEK_END  The offset is set to the size of the file plus offset bytes.
Packit 5e46da
 *
Packit 5e46da
 * @param p  file object
Packit 5e46da
 * @param pos  byte offset
Packit 5e46da
 * @param whence  directive
Packit 5e46da
 * @return current read position of the file, -1 on error
Packit 5e46da
 */
Packit 5e46da
int64_t udfread_file_seek (UDFFILE *, int64_t pos, int whence);
Packit 5e46da
Packit 5e46da
Packit 5e46da
#ifdef __cplusplus
Packit 5e46da
} /* extern "C" */
Packit 5e46da
#endif
Packit 5e46da
Packit 5e46da
#endif /* UDFREAD_H_ */