1 /* $NetBSD$ */ 2 3 /* 4 * File "udf_discop.h" is part of the UDFclient toolkit. 5 * File $Id: udf_discop.h,v 1.30 2011/02/01 20:43:41 reinoud Exp $ $Name: $ 6 * 7 * Copyright (c) 2003, 2004, 2005, 2006, 2011 8 * Reinoud Zandijk <reinoud@netbsd.org> 9 * All rights reserved. 10 * 11 * The UDFclient toolkit is distributed under the Clarified Artistic Licence. 12 * A copy of the licence is included in the distribution as 13 * `LICENCE.clearified.artistic' and a copy of the licence can also be 14 * requested at the GNU foundantion's website. 15 * 16 * Visit the UDFclient toolkit homepage http://www.13thmonkey.org/udftoolkit/ 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * 29 */ 30 31 32 #ifndef _UDF_DISCOP_H_ 33 #define _UDF_DISCOP_H_ 34 35 36 #include <pthread.h> 37 #include "defs.h" 38 #include "uscsilib.h" 39 #include "queue.h" 40 41 /* setup constants */ 42 #define UDF_DISCOP_BSWAP 1 43 44 /* Implementation constants */ 45 #define MAX_SESSIONS 100 46 #define CD_SECTOR_SIZE 2048 47 #define DISC_SECTOR_SIZE 512 48 49 50 /* State and driver constants */ 51 #define DISC_STATE_EMPTY 0 /* nothing on the disc */ 52 #define DISC_STATE_INCOMPLETE 1 /* can be appended */ 53 #define DISC_STATE_FULL 2 /* no appending possible */ 54 #define DISC_STATE_NOT_SERIAL 3 /* not serial */ 55 56 #define SESSION_STATE_EMPTY 0 /* still empty */ 57 #define SESSION_STATE_INCOMPLETE 1 /* session is open */ 58 #define SESSION_STATE_CLOSED 2 /* we need a new session */ 59 #define SESSION_STATE_COMPLETE 3 /* no appending possible */ 60 61 #define UDF_DEVDRV_CLASS 0xFF 62 #define UDF_DEVDRV_CLASS_FILE 0x00 63 #define UDF_DEVDRV_CLASS_DISC 0x01 64 #define UDF_DEVDRV_CLASS_CD 0x02 65 #define UDF_DEVDRV_CLASS_DVD 0x04 66 #define UDF_DEVDRV_CLASS_MO 0x08 67 #define UDF_DEVDRV_CLASS_BD 0x10 68 69 70 /* will go? */ 71 struct udf_session; 72 73 74 /* 75 * The complete disc, all cd sessions and how to access the drive 76 */ 77 struct udf_discinfo { 78 struct uscsi_dev *dev; /* uscsi device associated */ 79 80 int scsi_device_type; /* in case of SCSI */ 81 int mmc_profile; /* in case of SCSI */ 82 int devdrv_class; 83 84 int sequential; /* media is sequential writable only */ 85 int recordable; /* media is record-able; i.e. not static */ 86 int erasable; /* drive can erase sectors */ 87 int blankable; /* media can be blanked by the drive */ 88 int formattable; /* media can be formatted by the drive */ 89 int rewritable; /* media can be rewritten */ 90 int mrw; /* media is identified as being MRW formatted */ 91 int packet; /* media is using packet recording */ 92 int strict_overwrite; /* media can only be written a packet at a time */ 93 int blockingnr; /* blocking size for ECC/modification */ 94 95 int sector_size; /* sector size in bytes */ 96 int alt_sector_size; /* if non zero, override normal sectorsize */ 97 int link_size; /* link size lossage when having underruns */ 98 int disc_state; /* empty - incomplete - full - not_serial */ 99 int last_session_state; /* empty - incomplete - closed - complete */ 100 101 /* flags that alter udf_discop's behaviour */ 102 int udf_recording; /* flags if a recording is initialised */ 103 int bswap_sectors; /* swap all bytes in a sector */ 104 105 /* statistics */ 106 int am_writing; 107 uint64_t sectors_read; 108 uint64_t sectors_written; 109 uint32_t switchings; 110 111 /* sessions */ 112 int num_sessions; 113 int num_udf_sessions; 114 int session_is_UDF[MAX_SESSIONS]; 115 int session_quirks[MAX_SESSIONS]; 116 117 off_t session_start [MAX_SESSIONS]; 118 off_t session_end [MAX_SESSIONS]; 119 120 uint32_t next_writable [MAX_SESSIONS]; 121 uint32_t free_blocks [MAX_SESSIONS]; 122 uint32_t packet_size [MAX_SESSIONS]; 123 124 STAILQ_HEAD(udf_sessions, udf_session) sessions; 125 126 SLIST_ENTRY(udf_discinfo) next_disc; 127 }; 128 129 130 /* exported functions */ 131 extern int udf_open_disc(char *dev_name, int discop_flags, struct udf_discinfo **discptr); 132 extern int udf_close_disc(struct udf_discinfo *disc); 133 134 extern int udf_discinfo_get_type(struct udf_discinfo *disc); 135 extern int udf_discinfo_check_disc_ready(struct udf_discinfo *disc); 136 extern int udf_discinfo_is_cd_or_dvd(struct udf_discinfo *disc); 137 extern int udf_discinfo_set_recording_parameters(struct udf_discinfo *discinfo, int testwriting); 138 extern int udf_discinfo_alter_perception(struct udf_discinfo *disc, uint32_t sec_size, uint32_t num_sectors); 139 extern int udf_discinfo_finish_writing(struct udf_discinfo *discinfo); 140 extern int udf_discinfo_reserve_track_in_logic_units(struct udf_discinfo *discinfo, uint32_t logic_units); 141 extern int udf_discinfo_close_track(struct udf_discinfo *discinfo, uint16_t trackno); 142 extern int udf_discinfo_repair_track(struct udf_discinfo *discinfo, uint16_t trackno); 143 144 extern int udf_read_physical_sectors(struct udf_discinfo *disc, off_t sector, uint32_t num_sectors, char *what, uint8_t *result); 145 extern int udf_write_physical_sectors(struct udf_discinfo *disc, off_t sector, uint32_t num_sectors, char *what, uint8_t *source); 146 147 #endif /* _UDF_DISCOP_H_ */ 148 149