+ char pool_name[MAX_NAME_LENGTH]; /* pool name */
+ char pool_type[MAX_NAME_LENGTH]; /* pool type */
+
+ /* Device wait times ***FIXME*** look at durations */
+ char BadVolName[MAX_NAME_LENGTH]; /* Last wrong Volume mounted */
+ bool poll; /* set to poll Volume */
+ int min_wait;
+ int max_wait;
+ int max_num_wait;
+ int wait_sec;
+ int rem_wait_sec;
+ int num_wait;
+
+ btime_t last_timer; /* used by read/write/seek to get stats (usec) */
+ btime_t last_tick; /* contains last read/write time (usec) */
+
+ btime_t DevReadTime;
+ btime_t DevWriteTime;
+ uint64_t DevWriteBytes;
+ uint64_t DevReadBytes;
+
+ /* Methods */
+ btime_t get_timer_count(); /* return the last timer interval (ms) */
+
+ int has_cap(int cap) const { return capabilities & cap; }
+ void clear_cap(int cap) { capabilities &= ~cap; }
+ void set_cap(int cap) { capabilities |= cap; }
+ int is_autochanger() const { return capabilities & CAP_AUTOCHANGER; }
+ int requires_mount() const { return capabilities & CAP_REQMOUNT; }
+ int is_removable() const { return capabilities & CAP_REM; }
+ int is_tape() const { return dev_type == B_TAPE_DEV; }
+ int is_file() const { return dev_type == B_FILE_DEV; }
+ int is_fifo() const { return dev_type == B_FIFO_DEV; }
+ int is_dvd() const { return dev_type == B_DVD_DEV; }
+ int is_prog() const { return dev_type == B_PROG_DEV; }
+ int is_open() const { return m_fd >= 0; }
+ int is_offline() const { return state & ST_OFFLINE; }
+ int is_labeled() const { return state & ST_LABEL; }
+ int is_mounted() const { return state & ST_MOUNTED; }
+ int is_part_spooled() const { return state & ST_PART_SPOOLED; }
+ int have_media() const { return state & ST_MEDIA; }
+ int is_short_block() const { return state & ST_SHORT; }
+ int is_busy() const { return (state & ST_READ) || num_writers || reserved_device; }
+ int at_eof() const { return state & ST_EOF; }
+ int at_eot() const { return state & ST_EOT; }
+ int at_weot() const { return state & ST_WEOT; }
+ int can_append() const { return state & ST_APPEND; }
+ int is_freespace_ok() const { return state & ST_FREESPACE_OK; }
+ /*
+ * can_write() is meant for checking at the end of a job to see
+ * if we still have a tape (perhaps not if at end of tape
+ * and the job is canceled).
+ */
+ int can_write() const { return is_open() && can_append() &&
+ is_labeled() && !at_weot(); }
+ int can_read() const { return state & ST_READ; }
+ bool can_steal_lock() const { return m_blocked &&
+ (m_blocked == BST_UNMOUNTED ||
+ m_blocked == BST_WAITING_FOR_SYSOP ||
+ m_blocked == BST_UNMOUNTED_WAITING_FOR_SYSOP); };
+ bool waiting_for_mount() const { return
+ (m_blocked == BST_UNMOUNTED ||
+ m_blocked == BST_WAITING_FOR_SYSOP ||
+ m_blocked == BST_UNMOUNTED_WAITING_FOR_SYSOP); };
+ const char *strerror() const;
+ const char *archive_name() const;
+ const char *name() const;
+ const char *print_name() const; /* Name for display purposes */
+ void set_ateof(); /* in dev.c */
+ void set_ateot(); /* in dev.c */
+ void set_eot() { state |= ST_EOT; };
+ void set_eof() { state |= ST_EOF; };
+ void set_append() { state |= ST_APPEND; };
+ void set_labeled() { state |= ST_LABEL; };
+ inline void set_read() { state |= ST_READ; };
+ void set_offline() { state |= ST_OFFLINE; };
+ void set_mounted() { state |= ST_MOUNTED; };
+ void set_media() { state |= ST_MEDIA; };
+ void set_short_block() { state |= ST_SHORT; };
+ void set_freespace_ok() { state |= ST_FREESPACE_OK; }
+ void set_part_spooled(int val) { if (val) state |= ST_PART_SPOOLED; \
+ else state &= ~ST_PART_SPOOLED;
+ };
+ void set_mounted(int val) { if (val) state |= ST_MOUNTED; \
+ else state &= ~ST_MOUNTED; };
+ void clear_append() { state &= ~ST_APPEND; };
+ void clear_read() { state &= ~ST_READ; };
+ void clear_labeled() { state &= ~ST_LABEL; };
+ void clear_offline() { state &= ~ST_OFFLINE; };
+ void clear_eot() { state &= ~ST_EOT; };
+ void clear_eof() { state &= ~ST_EOF; };
+ void clear_opened() { m_fd = -1; };
+ void clear_mounted() { state &= ~ST_MOUNTED; };
+ void clear_media() { state &= ~ST_MEDIA; };
+ void clear_short_block() { state &= ~ST_SHORT; };
+ void clear_freespace_ok() { state &= ~ST_FREESPACE_OK; };
+ char *bstrerror(void) { return errmsg; };
+ char *print_errmsg() { return errmsg; };
+
+#ifdef SD_DEBUG_LOCK
+ void _r_dlock(const char *, int); /* in device.c */
+ void _r_dunlock(const char *, int); /* in device.c */
+ void _dlock(const char *, int); /* in device.c */
+ void _dunlock(const char *, int); /* in device.c */
+#else
+ void r_dlock(); /* in device.c */
+ void r_dunlock() { dunlock(); }
+ void dlock() { P(m_mutex); }
+ void dunlock() { V(m_mutex); }
+#endif
+
+ void clear_volhdr(); /* in dev.c */
+ void block(int why); /* in dev.c */
+ void unblock(bool locked=false); /* in dev.c */
+ void close(); /* in dev.c */
+ void close_part(DCR *dcr); /* in dev.c */
+ bool truncate(DCR *dcr); /* in dev.c */
+ int open(DCR *dcr, int mode); /* in dev.c */
+ void term(void); /* in dev.c */
+ ssize_t read(void *buf, size_t len); /* in dev.c */
+ ssize_t write(const void *buf, size_t len); /* in dev.c */
+ bool rewind(DCR *dcr); /* in dev.c */
+ bool mount(int timeout); /* in dev.c */
+ bool unmount(int timeout); /* in dev.c */
+ void edit_mount_codes(POOL_MEM &omsg, const char *imsg); /* in dev.c */
+ bool offline_or_rewind(); /* in dev.c */
+ bool offline(); /* in dev.c */
+ bool bsf(int count); /* in dev.c */
+ bool eod(DCR *dcr); /* in dev.c */
+ bool fsr(int num); /* in dev.c */
+ bool fsf(int num); /* in dev.c */
+ bool bsr(int num); /* in dev.c */
+ bool weof(int num); /* in dev.c */
+ void lock_door(); /* in dev.c */
+ void unlock_door(); /* in dev.c */
+ int32_t get_os_tape_file(); /* in dev.c */
+ bool scan_dir_for_volume(DCR *dcr); /* in scan.c */
+ bool reposition(DCR *dcr, uint32_t rfile, uint32_t rblock); /* in dev.c */
+ void clrerror(int func); /* in dev.c */
+ boffset_t lseek(DCR *dcr, boffset_t offset, int whence); /* in dev.c */
+ bool update_pos(DCR *dcr); /* in dev.c */
+ bool update_freespace(); /* in dvd.c */
+
+ void set_blocked(int block) { m_blocked = block; };
+ int blocked() const { return m_blocked; };
+ uint32_t get_file() const { return file; };
+ uint32_t get_block() const { return block_num; };
+ const char *print_blocked() const; /* in dev.c */
+ bool is_blocked() const { return m_blocked != BST_NOT_BLOCKED; };
+ int fd() const { return m_fd; };
+
+private:
+ bool do_mount(int mount, int timeout); /* in dev.c */
+ void set_mode(int omode); /* in dev.c */
+ void open_tape_device(DCR *dcr, int omode); /* in dev.c */
+ void open_file_device(DCR *dcr, int omode); /* in dev.c */
+ void open_dvd_device(DCR *dcr, int omode); /* in dev.c */
+};
+
+inline const char *DEVICE::strerror() const { return errmsg; }
+inline const char *DEVICE::archive_name() const { return dev_name; }
+inline const char *DEVICE::print_name() const { return prt_name; }
+
+/*
+ * Device Context (or Control) Record.
+ * There is one of these records for each Job that is using
+ * the device. Items in this record are "local" to the Job and
+ * do not affect other Jobs. Note, a job can have multiple
+ * DCRs open, each pointing to a different device.
+ */
+class DCR {
+public:
+ dlink dev_link; /* link to attach to dev */
+ JCR *jcr; /* pointer to JCR */
+ DEVICE *dev; /* pointer to device */
+ DEVRES *device; /* pointer to device resource */
+ DEV_BLOCK *block; /* pointer to block */
+ DEV_RECORD *rec; /* pointer to record */
+ pthread_t tid; /* Thread running this dcr */
+ int spool_fd; /* fd if spooling */
+ bool spool_data; /* set to spool data */
+ bool spooling; /* set when actually spooling */
+ bool despooling; /* set when despooling */
+ bool despool_wait; /* waiting for despooling */
+ bool dev_locked; /* set if dev already locked */
+ bool NewVol; /* set if new Volume mounted */
+ bool WroteVol; /* set if Volume written */
+ bool NewFile; /* set when EOF written */
+ bool reserved_device; /* set if reserve done */
+ bool any_volume; /* Any OK for dir_find_next... */
+ bool attached_to_dev; /* set when attached to dev */
+ uint32_t VolFirstIndex; /* First file index this Volume */
+ uint32_t VolLastIndex; /* Last file index this Volume */
+ uint32_t FileIndex; /* Current File Index */
+ uint32_t EndFile; /* End file written */
+ uint32_t StartFile; /* Start write file */
+ uint32_t StartBlock; /* Start write block */
+ uint32_t EndBlock; /* Ending block written */
+ int64_t job_spool_size; /* Current job spool size */
+ int64_t max_job_spool_size; /* Max job spool size */
+ char VolumeName[MAX_NAME_LENGTH]; /* Volume name */
+ char pool_name[MAX_NAME_LENGTH]; /* pool name */
+ char pool_type[MAX_NAME_LENGTH]; /* pool type */
+ char media_type[MAX_NAME_LENGTH]; /* media type */
+ char dev_name[MAX_NAME_LENGTH]; /* dev name */
+ int Copy; /* identical copy number */
+ int Stripe; /* RAIT stripe */
+ VOLUME_CAT_INFO VolCatInfo; /* Catalog info for desired volume */
+};
+
+/*
+ * Volume reservation class -- see reserve.c
+ */
+class VOLRES {
+public:
+ dlink link;
+ char *vol_name;
+ DEVICE *dev;