From 4fb452d23ff31d31059a77d4b06a3915e7d3ff0d Mon Sep 17 00:00:00 2001 From: Mauricio Date: Wed, 25 Mar 2026 22:02:46 -0600 Subject: [PATCH 1/2] chore: add config files added .clang-format, .editorconfig and .gitignore entries --- .clang-format | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++ .editorconfig | 12 ++++++++ .gitignore | 12 ++++++++ 3 files changed, 100 insertions(+) create mode 100644 .clang-format create mode 100644 .editorconfig diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..5f14553d --- /dev/null +++ b/.clang-format @@ -0,0 +1,76 @@ +# .clang-format for LTFS (Linear Tape File System) +# Derived from the LTFS C Language Coding Style Guide. +# +# NOTE: Several guide rules cannot be enforced by clang-format and must be +# observed manually or via other tooling: +# - Naming conventions (snake_case, capital enumerator entries, etc.) +# - Positive logic naming for boolean parameters +# - Doxygen comment content and placement +# - sizeof(variable) preferred over sizeof(type) +# - Include guard presence in headers +# - File preamble / copyright block +# - C++-style comments (//) restricted to logic comment-out only +# - Magic editor lines (vim/emacs modelines) +--- +Language: C +ColumnLimit: 120 +IndentWidth: 2 +UseTab: Always +TabWidth: 2 +ReflowComments: false +BreakBeforeBraces: Custom +BraceWrapping: + AfterCaseLabel: false + AfterClass: true + AfterControlStatement: false + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterStruct: true + AfterUnion: true + AfterExternBlock: true + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: false +AllowShortIfStatementsOnASingleLine: WithoutElse +AllowShortLoopsOnASingleLine: false +AllowShortBlocksOnASingleLine: Never +AllowShortFunctionsOnASingleLine: None +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceAfterCStyleCast: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +IndentCaseLabels: true +IndentCaseBlocks: false +AlwaysBreakAfterReturnType: None +AlignAfterOpenBracket: Align +BinPackParameters: false +BinPackArguments: false +PointerAlignment: Right +ReferenceAlignment: Right +IndentPPDirectives: AfterHash +AlignConsecutiveAssignments: + Enabled: false +AlignConsecutiveDeclarations: + Enabled: false +AlignEscapedNewlines: Left +AlignOperands: Align +AlignTrailingComments: + Kind: Always + OverEmptyLines: 1 +CompactNamespaces: false +IncludeBlocks: Preserve +SortIncludes: CaseSensitive +MaxEmptyLinesToKeep: 1 +KeepEmptyLinesAtTheStartOfBlocks: false +SpacesBeforeTrailingComments: 2 +Cpp11BracedListStyle: false +InsertTrailingCommas: None diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..1992a16f --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +indent_style = space +indent_size = 2 +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[{Makefile,*.mk,*.am}] +indent_style = tab +indent_size = 4 diff --git a/.gitignore b/.gitignore index 0711b11e..823e5f31 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ build-aux/ m4/ config.h.in configure + # Files generated by ./configure config.h config.log @@ -15,6 +16,7 @@ stamp-h1 .deps/ Makefile ltfs.pc + # Files generated by make *.o *.a @@ -23,8 +25,10 @@ ltfs.pc .libs/ messages/.lib .dirstamp + # Files created by OS .DS_Store + # Files for development GPATH GRTAGS @@ -32,3 +36,11 @@ GTAGS TAGS tags *~ + +# Files generated by user IDE/text editor +.cache +.zed +.vscode +.claude +.idea +compile_commands.json From 8202112b22421b8c6c32a44175674ef1b44594f1 Mon Sep 17 00:00:00 2001 From: Mauricio Date: Wed, 25 Mar 2026 22:06:00 -0600 Subject: [PATCH 2/2] chore: apply format --- src/iosched/cache_manager.c | 78 +- src/iosched/cache_manager.h | 2 + src/iosched/fcfs.c | 47 +- src/iosched/unified.c | 570 +++-- src/kmi/flatfile.c | 64 +- src/kmi/key_format_ltfs.c | 119 +- src/kmi/key_format_ltfs.h | 2 + src/kmi/simple.c | 80 +- src/libltfs/arch/arch_info.c | 43 +- src/libltfs/arch/errormap.c | 769 +++--- src/libltfs/arch/filename_handling.c | 67 +- src/libltfs/arch/osx/osx_string.c | 35 +- src/libltfs/arch/time_internal.c | 103 +- src/libltfs/arch/time_internal.h | 1 + src/libltfs/arch/uuid_internal.c | 3 +- src/libltfs/base64.c | 33 +- src/libltfs/config_file.c | 247 +- src/libltfs/dcache.c | 152 +- src/libltfs/fs.c | 357 ++- src/libltfs/index_criteria.c | 179 +- src/libltfs/index_criteria.h | 4 +- src/libltfs/iosched.c | 48 +- src/libltfs/kmi.c | 43 +- src/libltfs/label.c | 28 +- src/libltfs/ltfs.c | 934 +++---- src/libltfs/ltfs_fsops.c | 717 +++--- src/libltfs/ltfs_fsops.h | 4 + src/libltfs/ltfs_fsops_raw.c | 226 +- src/libltfs/ltfs_internal.c | 425 ++-- src/libltfs/ltfs_locking_old.h | 1 + src/libltfs/ltfs_thread.c | 11 +- src/libltfs/ltfslogging.c | 147 +- src/libltfs/ltfssnmp.c | 94 +- src/libltfs/ltfstrace.c | 251 +- src/libltfs/pathname.c | 169 +- src/libltfs/periodic_sync.c | 41 +- src/libltfs/plugin.c | 88 +- src/libltfs/tape.c | 992 ++++---- src/libltfs/xattr.c | 637 +++-- src/libltfs/xml_reader.c | 111 +- src/libltfs/xml_reader_libltfs.c | 443 ++-- src/libltfs/xml_writer.c | 79 +- src/libltfs/xml_writer_libltfs.c | 261 +- src/ltfs_fuse.c | 299 +-- src/main.c | 413 ++- src/tape_drivers/crc32c_crc.c | 141 +- src/tape_drivers/freebsd/cam/cam_cmn.c | 357 ++- src/tape_drivers/freebsd/cam/cam_tc.c | 1917 +++++++------- .../generic/file/filedebug_conf_tc.c | 114 +- src/tape_drivers/generic/file/filedebug_tc.c | 1158 ++++----- src/tape_drivers/generic/itdtimg/itdtimg_tc.c | 976 ++++---- src/tape_drivers/hp_tape.c | 569 ++--- src/tape_drivers/ibm_tape.c | 1525 ++++++------ .../linux/lin_tape/lin_tape_ibmtape.c | 2147 ++++++++-------- src/tape_drivers/linux/sg/sg_scsi_tape.c | 178 +- src/tape_drivers/linux/sg/sg_tape.c | 2214 ++++++++--------- .../netbsd/scsipi-ibmtape/scsipi_ibmtape.c | 1907 +++++++------- .../netbsd/scsipi-ibmtape/scsipi_scsi_tape.c | 202 +- src/tape_drivers/open_factor.c | 48 +- src/tape_drivers/osx/iokit/iokit_scsi.c | 120 +- src/tape_drivers/osx/iokit/iokit_service.c | 96 +- src/tape_drivers/osx/iokit/iokit_tape.c | 1737 ++++++------- src/tape_drivers/quantum_tape.c | 379 ++- src/tape_drivers/reed_solomon_crc.c | 89 +- src/tape_drivers/vendor_compat.c | 449 ++-- src/utils/ltfsck.c | 663 ++--- src/utils/mkltfs.c | 286 +-- 67 files changed, 12571 insertions(+), 14118 deletions(-) diff --git a/src/iosched/cache_manager.c b/src/iosched/cache_manager.c index a09288d6..d8bbc715 100644 --- a/src/iosched/cache_manager.c +++ b/src/iosched/cache_manager.c @@ -46,8 +46,8 @@ ** ************************************************************************************* */ -#include "libltfs/ltfs.h" #include "cache_manager.h" +#include "libltfs/ltfs.h" /** * cache_pool structure. @@ -62,11 +62,12 @@ * have been allocated through this cache pool; it doesn't necessarily say how * many available objects are in the pool. */ -struct cache_pool { - size_t object_size; /**< The size of each object in this pool */ - size_t initial_capacity; /**< Low water mark. Defines the initial capacity of the pool */ - size_t max_capacity; /**< High water mark. Defines the maximum capacity of the pool */ - size_t current_capacity; /**< How many objects are currently allocated */ +struct cache_pool +{ + size_t object_size; /**< The size of each object in this pool */ + size_t initial_capacity; /**< Low water mark. Defines the initial capacity of the pool */ + size_t max_capacity; /**< High water mark. Defines the maximum capacity of the pool */ + size_t current_capacity; /**< How many objects are currently allocated */ TAILQ_HEAD(objects_struct, cache_object) pool; /**< Pool of cached objects */ }; @@ -74,11 +75,12 @@ struct cache_pool { * cache_object structure. * Holds objects of size @object_size, as stored in the cache_pool structure. */ -struct cache_object { - uint32_t refcount; /**< Reference count */ - ltfs_mutex_t lock; /**< Lock to protect access to the refcount */ - void *data; /**< Cached data. Must be the first element in the structure */ - struct cache_pool *pool; /**< Backpointer to the cache pool this object is part of */ +struct cache_object +{ + uint32_t refcount; /**< Reference count */ + ltfs_mutex_t lock; /**< Lock to protect access to the refcount */ + void *data; /**< Cached data. Must be the first element in the structure */ + struct cache_pool *pool; /**< Backpointer to the cache pool this object is part of */ TAILQ_ENTRY(cache_object) list; /**< Pointers to next and previous cache objects */ }; @@ -92,12 +94,13 @@ struct cache_object *_cache_manager_create_object(struct cache_pool *pool) { int ret; struct cache_object *object = calloc(1, sizeof(struct cache_object)); - if (! object) { + if (!object) { ltfsmsg(LTFS_ERR, 10001E, "cache manager: object"); return NULL; } - object->data = calloc(1, pool->object_size + LTFS_CRC_SIZE); /* Allocate extra 4-bytes for SCSI logical block protection */ - if (! object->data) { + object->data = + calloc(1, pool->object_size + LTFS_CRC_SIZE); /* Allocate extra 4-bytes for SCSI logical block protection */ + if (!object->data) { ltfsmsg(LTFS_ERR, 10001E, "cache manager: object data"); free(object); return NULL; @@ -127,8 +130,8 @@ void *cache_manager_init(size_t object_size, size_t initial_capacity, size_t max struct cache_pool *pool; size_t i; - pool = (struct cache_pool *) calloc(1, sizeof (struct cache_pool)); - if (! pool) { + pool = (struct cache_pool *)calloc(1, sizeof(struct cache_pool)); + if (!pool) { ltfsmsg(LTFS_ERR, 10001E, "cache manager: pool"); return NULL; } @@ -138,16 +141,16 @@ void *cache_manager_init(size_t object_size, size_t initial_capacity, size_t max pool->current_capacity = initial_capacity; TAILQ_INIT(&pool->pool); - for (i=0; ipool, list, aux) { + TAILQ_FOREACH_SAFE(object, &pool->pool, list, aux) + { TAILQ_REMOVE(&pool->pool, object, list); ltfs_mutex_destroy(&object->lock); - if (object->data) - free(object->data); + if (object->data) free(object->data); free(object); } @@ -181,10 +184,10 @@ void cache_manager_destroy(void *cache) */ bool cache_manager_has_room(void *cache) { - struct cache_pool *pool = (struct cache_pool *) cache; + struct cache_pool *pool = (struct cache_pool *)cache; CHECK_ARG_NULL(pool, false); - return ! (TAILQ_EMPTY(&pool->pool) && pool->current_capacity == pool->max_capacity); + return !(TAILQ_EMPTY(&pool->pool) && pool->current_capacity == pool->max_capacity); } /** @@ -202,14 +205,15 @@ void *cache_manager_allocate_object(void *cache) { size_t i, new_size = 0; struct cache_object *object, *last_object = NULL; - struct cache_pool *pool = (struct cache_pool *) cache; + struct cache_pool *pool = (struct cache_pool *)cache; CHECK_ARG_NULL(pool, NULL); - TAILQ_FOREACH(object, &pool->pool, list) { + TAILQ_FOREACH(object, &pool->pool, list) + { /* Return the first available object */ TAILQ_REMOVE(&pool->pool, object, list); object->refcount = 1; - return (void *) object; + return (void *)object; } /* @@ -229,9 +233,9 @@ void *cache_manager_allocate_object(void *cache) /* Expand until the maximum capacity */ new_size = pool->max_capacity; - for (i=pool->current_capacity; icurrent_capacity; i < new_size; ++i) { struct cache_object *object = _cache_manager_create_object(pool); - if (! object) { + if (!object) { /* Luckily we might have increased the size of the cache by a few entries.. */ ltfsmsg(LTFS_WARN, 11115W); break; @@ -240,7 +244,7 @@ void *cache_manager_allocate_object(void *cache) pool->current_capacity++; } - if (! last_object) { + if (!last_object) { /* If we couldn't grow the cache any further return failure */ ltfsmsg(LTFS_ERR, 11116E); return NULL; @@ -258,7 +262,7 @@ void *cache_manager_allocate_object(void *cache) */ void *cache_manager_get_object(void *cache_object) { - struct cache_object *object = (struct cache_object *) cache_object; + struct cache_object *object = (struct cache_object *)cache_object; CHECK_ARG_NULL(cache_object, NULL); @@ -276,8 +280,8 @@ void *cache_manager_get_object(void *cache_object) void cache_manager_free_object(void *cache_object, size_t count) { struct cache_pool *pool; - struct cache_object *object = (struct cache_object *) cache_object; - if (! object) { + struct cache_object *object = (struct cache_object *)cache_object; + if (!object) { ltfsmsg(LTFS_WARN, 10006W, "object", __FUNCTION__); return; } @@ -316,7 +320,7 @@ void cache_manager_free_object(void *cache_object, size_t count) */ void *cache_manager_get_object_data(void *cache_object) { - struct cache_object *object = (struct cache_object *) cache_object; + struct cache_object *object = (struct cache_object *)cache_object; CHECK_ARG_NULL(object, NULL); return object->data; } @@ -328,7 +332,7 @@ void *cache_manager_get_object_data(void *cache_object) */ size_t cache_manager_get_object_size(void *cache_object) { - struct cache_object *object = (struct cache_object *) cache_object; + struct cache_object *object = (struct cache_object *)cache_object; CHECK_ARG_NULL(object, 0); return object->pool->object_size; } diff --git a/src/iosched/cache_manager.h b/src/iosched/cache_manager.h index a82f1e21..2e0a539b 100644 --- a/src/iosched/cache_manager.h +++ b/src/iosched/cache_manager.h @@ -48,6 +48,8 @@ */ #ifndef __cache_manager_h #define __cache_manager_h +#include +#include void *cache_manager_init(size_t object_size, size_t initial_capacity, size_t max_capacity); void cache_manager_destroy(void *cache); diff --git a/src/iosched/fcfs.c b/src/iosched/fcfs.c index 23a7b2d4..eaf10d71 100644 --- a/src/iosched/fcfs.c +++ b/src/iosched/fcfs.c @@ -47,17 +47,18 @@ ************************************************************************************* */ +#include "libltfs/iosched_ops.h" #include "libltfs/ltfs.h" #include "libltfs/ltfs_fsops_raw.h" #include "ltfs_copyright.h" -#include "libltfs/iosched_ops.h" -volatile char *copyright = LTFS_COPYRIGHT_0"\n"LTFS_COPYRIGHT_1"\n"LTFS_COPYRIGHT_2"\n" \ - LTFS_COPYRIGHT_3"\n"LTFS_COPYRIGHT_4"\n"LTFS_COPYRIGHT_5"\n"; +volatile char *copyright = LTFS_COPYRIGHT_0 "\n" LTFS_COPYRIGHT_1 "\n" LTFS_COPYRIGHT_2 "\n" LTFS_COPYRIGHT_3 + "\n" LTFS_COPYRIGHT_4 "\n" LTFS_COPYRIGHT_5 "\n"; -struct fcfs_data { - ltfs_mutex_t sched_lock; /**< Serializes read and write access */ - struct ltfs_volume *vol; /**< A reference to the LTFS volume structure */ +struct fcfs_data +{ + ltfs_mutex_t sched_lock; /**< Serializes read and write access */ + struct ltfs_volume *vol; /**< A reference to the LTFS volume structure */ }; /** @@ -69,7 +70,7 @@ void *fcfs_init(struct ltfs_volume *vol) { int ret; struct fcfs_data *priv = calloc(1, sizeof(struct fcfs_data)); - if (! priv) { + if (!priv) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return NULL; } @@ -91,7 +92,7 @@ void *fcfs_init(struct ltfs_volume *vol) */ int fcfs_destroy(void *iosched_handle) { - struct fcfs_data *priv = (struct fcfs_data *) iosched_handle; + struct fcfs_data *priv = (struct fcfs_data *)iosched_handle; CHECK_ARG_NULL(iosched_handle, -LTFS_NULL_ARG); ltfs_mutex_destroy(&priv->sched_lock); @@ -110,7 +111,7 @@ int fcfs_destroy(void *iosched_handle) */ int fcfs_open(const char *path, bool open_write, struct dentry **dentry, void *iosched_handle) { - struct fcfs_data *priv = (struct fcfs_data *) iosched_handle; + struct fcfs_data *priv = (struct fcfs_data *)iosched_handle; CHECK_ARG_NULL(path, -LTFS_NULL_ARG); CHECK_ARG_NULL(dentry, -LTFS_NULL_ARG); @@ -147,7 +148,7 @@ int fcfs_close(struct dentry *d, bool flush, void *iosched_handle) */ ssize_t fcfs_read(struct dentry *d, char *buf, size_t size, off_t offset, void *iosched_handle) { - struct fcfs_data *priv = (struct fcfs_data *) iosched_handle; + struct fcfs_data *priv = (struct fcfs_data *)iosched_handle; CHECK_ARG_NULL(d, -LTFS_NULL_ARG); CHECK_ARG_NULL(buf, -LTFS_NULL_ARG); @@ -167,10 +168,10 @@ ssize_t fcfs_read(struct dentry *d, char *buf, size_t size, off_t offset, void * * @param iosched_handle the I/O scheduler handle * @return the number of bytes enqueued for writing or a negative value on error */ -ssize_t fcfs_write(struct dentry *d, const char *buf, size_t size, off_t offset, - bool isupdatetime, void *iosched_handle) +ssize_t +fcfs_write(struct dentry *d, const char *buf, size_t size, off_t offset, bool isupdatetime, void *iosched_handle) { - struct fcfs_data *priv = (struct fcfs_data *) iosched_handle; + struct fcfs_data *priv = (struct fcfs_data *)iosched_handle; CHECK_ARG_NULL(d, -LTFS_NULL_ARG); CHECK_ARG_NULL(buf, -LTFS_NULL_ARG); @@ -189,7 +190,7 @@ ssize_t fcfs_write(struct dentry *d, const char *buf, size_t size, off_t offset, */ int fcfs_flush(struct dentry *d, bool closeflag, void *iosched_handle) { - (void) closeflag; + (void)closeflag; CHECK_ARG_NULL(d, -LTFS_NULL_ARG); CHECK_ARG_NULL(iosched_handle, -LTFS_NULL_ARG); @@ -199,7 +200,7 @@ int fcfs_flush(struct dentry *d, bool closeflag, void *iosched_handle) int fcfs_truncate(struct dentry *d, off_t length, void *iosched_handle) { - struct fcfs_data *priv = (struct fcfs_data *) iosched_handle; + struct fcfs_data *priv = (struct fcfs_data *)iosched_handle; CHECK_ARG_NULL(d, -LTFS_NULL_ARG); CHECK_ARG_NULL(iosched_handle, -LTFS_NULL_ARG); @@ -251,14 +252,14 @@ int fcfs_set_profiler(char *work_dir, bool enable, void *iosched_handle) } struct iosched_ops fcfs_ops = { - .init = fcfs_init, - .destroy = fcfs_destroy, - .open = fcfs_open, - .close = fcfs_close, - .read = fcfs_read, - .write = fcfs_write, - .flush = fcfs_flush, - .truncate = fcfs_truncate, + .init = fcfs_init, + .destroy = fcfs_destroy, + .open = fcfs_open, + .close = fcfs_close, + .read = fcfs_read, + .write = fcfs_write, + .flush = fcfs_flush, + .truncate = fcfs_truncate, .get_filesize = fcfs_get_filesize, .update_data_placement = fcfs_update_data_placement, .set_profiler = fcfs_set_profiler, diff --git a/src/iosched/unified.c b/src/iosched/unified.c index f492e12f..2e03a77d 100644 --- a/src/iosched/unified.c +++ b/src/iosched/unified.c @@ -55,13 +55,13 @@ ************************************************************************************* */ -#include "libltfs/ltfs.h" -#include "libltfs/tape.h" -#include "libltfs/ltfs_fsops_raw.h" +#include "cache_manager.h" +#include "libltfs/arch/time_internal.h" #include "libltfs/index_criteria.h" #include "libltfs/iosched_ops.h" -#include "libltfs/arch/time_internal.h" -#include "cache_manager.h" +#include "libltfs/ltfs.h" +#include "libltfs/ltfs_fsops_raw.h" +#include "libltfs/tape.h" /** * Maximum number of requests targeting the Index Partition to keep before flushing @@ -72,42 +72,46 @@ /** * Each outstanding write request is in one of the following states. */ -enum request_state { - REQUEST_PARTIAL, /**< Partially filled request, will not normally be written until full */ - REQUEST_DP, /**< Full request, ready to be written to the medium */ - REQUEST_IP /**< A request already written to the DP, waiting to be written to the IP */ +enum request_state +{ + REQUEST_PARTIAL, /**< Partially filled request, will not normally be written until full */ + REQUEST_DP, /**< Full request, ready to be written to the medium */ + REQUEST_IP /**< A request already written to the DP, waiting to be written to the IP */ }; /** * A read request. These are used internally by unified_read to queue up read requests and issue * them after releasing the dentry's iosched_lock. */ -struct read_request { +struct read_request +{ TAILQ_ENTRY(read_request) list; /**< Pointers for linked list of requests */ - uint64_t offset; /**< File offset for the read request */ - char *buf; /**< Buffer which will receive data */ - size_t count; /**< Number of bytes to read */ + uint64_t offset; /**< File offset for the read request */ + char *buf; /**< Buffer which will receive data */ + size_t count; /**< Number of bytes to read */ }; /** * A write request. */ -struct write_request { +struct write_request +{ TAILQ_ENTRY(write_request) list; /**< Pointers for linked list of requests */ - uint64_t offset; /**< Starting file offset for this request */ - size_t count; /**< Current request length, always <= cache block size */ - void *write_cache; /**< Cache block containing this request's data */ - enum request_state state; /**< Current state of the request */ + uint64_t offset; /**< Starting file offset for this request */ + size_t count; /**< Current request length, always <= cache block size */ + void *write_cache; /**< Cache block containing this request's data */ + enum request_state state; /**< Current state of the request */ }; /** * Per-dentry private data structure. It records a list of outstanding write requests * and associated data. */ -struct dentry_priv { - struct dentry *dentry; /**< Dentry associated with this request list */ - ltfs_mutex_t io_lock; /**< Lock controlling file I/O to this dentry */ - uint64_t file_size; /**< Real file size, including outstanding write requests */ +struct dentry_priv +{ + struct dentry *dentry; /**< Dentry associated with this request list */ + ltfs_mutex_t io_lock; /**< Lock controlling file I/O to this dentry */ + uint64_t file_size; /**< Real file size, including outstanding write requests */ /** * Index partition write flag. This is set if the file's name and size match the volume's @@ -159,7 +163,8 @@ struct dentry_priv { /** * Main scheduler data structure. Each scheduler instance has exactly one of these. */ -struct unified_data { +struct unified_data +{ /** * Global scheduler lock. Any thread working on scheduler data structures must take this lock * for read. Taking this lock for write will stop all other scheduler activity, which @@ -176,10 +181,10 @@ struct unified_data { * while holding this lock. */ ltfs_thread_mutex_t cache_lock; - ltfs_thread_cond_t cache_cond; /**< Signal this variable when a cache block becomes available */ - uint32_t cache_requests; /**< Number of threads waiting for a cache block */ - size_t cache_size; /**< Size of each cache block */ - size_t cache_blocks; /**< Maximum cache block count */ + ltfs_thread_cond_t cache_cond; /**< Signal this variable when a cache block becomes available */ + uint32_t cache_requests; /**< Number of threads waiting for a cache block */ + size_t cache_size; /**< Size of each cache block */ + size_t cache_blocks; /**< Maximum cache block count */ /** * dentry_priv queue lock. @@ -188,14 +193,14 @@ struct unified_data { * while holding this lock. */ ltfs_thread_mutex_t queue_lock; - ltfs_thread_cond_t queue_cond; /**< Signal this variable when the dentry_priv lists are modified */ + ltfs_thread_cond_t queue_cond; /**< Signal this variable when the dentry_priv lists are modified */ /* Lists of dentry_priv structures. Note that each dentry_priv may be in more than one of * these lists. */ TAILQ_HEAD(workingset_struct, dentry_priv) working_set; /**< Files with partial requests */ - TAILQ_HEAD(writequeue_struct, dentry_priv) dp_queue; /**< Files with full (DP) requests */ - TAILQ_HEAD(indexqueue_struct, dentry_priv) ip_queue; /**< Files with IP requests */ - TAILQ_HEAD(extqueue_struct, dentry_priv) ext_queue; /**< Files with dirty IP extents */ + TAILQ_HEAD(writequeue_struct, dentry_priv) dp_queue; /**< Files with full (DP) requests */ + TAILQ_HEAD(indexqueue_struct, dentry_priv) ip_queue; /**< Files with IP requests */ + TAILQ_HEAD(extqueue_struct, dentry_priv) ext_queue; /**< Files with dirty IP extents */ /* Queue lengths. These variables count the number of dentry_privs in each queue, not the * number of requests in each state. @@ -207,50 +212,61 @@ struct unified_data { /* Counters for various types of requests. * NOTE: these variables count write_requests, not dentry_priv structures, so they * DO NOT equal the lengths of the working_set/dp_queue/ip_queue lists! */ - uint32_t ws_request_count; /**< Number of requests in REQUEST_PARTIAL state */ - uint32_t dp_request_count; /**< Number of requests in REQUEST_DP state which will NOT change to IP state */ - uint32_t ip_request_count; /**< Number of requests in REQUEST_IP state */ + uint32_t ws_request_count; /**< Number of requests in REQUEST_PARTIAL state */ + uint32_t dp_request_count; /**< Number of requests in REQUEST_DP state which will NOT change to IP state */ + uint32_t ip_request_count; /**< Number of requests in REQUEST_IP state */ ltfs_thread_t writer_thread; /**< Background writer thread ID */ - bool writer_keepalive; /**< Used to terminate the background writer thread */ - void *pool; /**< Handle to the cache manager */ - struct ltfs_volume *vol; /**< Each scheduler instance is associated with a single LTFS volume */ + bool writer_keepalive; /**< Used to terminate the background writer thread */ + void *pool; /**< Handle to the cache manager */ + struct ltfs_volume *vol; /**< Each scheduler instance is associated with a single LTFS volume */ ltfs_mutex_t proflock; - FILE* profiler; /**< The file pointer for profiler */ + FILE *profiler; /**< The file pointer for profiler */ }; - /* Prototypes */ -int _unified_get_dentry_priv(struct dentry *d, struct dentry_priv **dentry_priv, - struct unified_data *priv); +int _unified_get_dentry_priv(struct dentry *d, struct dentry_priv **dentry_priv, struct unified_data *priv); ltfs_thread_return _unified_writer_thread(void *iosched_handle); void _unified_process_queue(enum request_state queue, struct unified_data *priv); void _unified_process_index_queue(struct unified_data *priv); void _unified_process_data_queue(enum request_state queue, struct unified_data *priv); void _unified_free_request(struct write_request *req, struct unified_data *priv); -void _unified_update_alt_extentlist(struct extent_info *newext, struct dentry_priv *dpr, - struct unified_data *priv); +void _unified_update_alt_extentlist(struct extent_info *newext, struct dentry_priv *dpr, struct unified_data *priv); void _unified_clear_alt_extentlist(bool save, struct dentry_priv *dpr, struct unified_data *priv); -int _unified_update_queue_membership(bool add, bool all, enum request_state queue, - struct dentry_priv *dentry_priv, struct unified_data *priv); +int _unified_update_queue_membership( + bool add, bool all, enum request_state queue, struct dentry_priv *dentry_priv, struct unified_data *priv); int _unified_cache_alloc(void **cache, struct dentry *d, struct unified_data *priv); void _unified_cache_free(void *cache, size_t count, struct unified_data *priv); -ssize_t _unified_insert_new_request(const char *buf, off_t offset, size_t count, void **cache, - bool ip_state, struct write_request *req, struct dentry *d, struct unified_data *priv); -size_t _unified_update_request(const char *buf, off_t offset, size_t size, - struct dentry_priv *dpr, struct write_request *req, struct unified_data *priv); -int _unified_merge_requests(struct write_request *dest, struct write_request *src, - void **spare_cache, struct dentry_priv *dpr, struct unified_data *priv); +ssize_t _unified_insert_new_request(const char *buf, + off_t offset, + size_t count, + void **cache, + bool ip_state, + struct write_request *req, + struct dentry *d, + struct unified_data *priv); +size_t _unified_update_request(const char *buf, + off_t offset, + size_t size, + struct dentry_priv *dpr, + struct write_request *req, + struct unified_data *priv); +int _unified_merge_requests(struct write_request *dest, + struct write_request *src, + void **spare_cache, + struct dentry_priv *dpr, + struct unified_data *priv); int _unified_flush_unlocked(struct dentry *d, struct unified_data *priv); int _unified_flush_all(struct unified_data *priv); -void _unified_free_dentry_priv_conditional(struct dentry *d, uint32_t target_handles, - struct unified_data *priv); +void _unified_free_dentry_priv_conditional(struct dentry *d, uint32_t target_handles, struct unified_data *priv); void _unified_free_dentry_priv(struct dentry *d, struct unified_data *priv); void _unified_set_write_ip(struct dentry_priv *dpr, struct unified_data *priv); void _unified_unset_write_ip(struct dentry_priv *dpr, struct unified_data *priv); -void _unified_handle_write_error(ssize_t write_ret, struct write_request *req, - struct dentry_priv *dpr, struct unified_data *priv); +void _unified_handle_write_error(ssize_t write_ret, + struct write_request *req, + struct dentry_priv *dpr, + struct unified_data *priv); int _unified_get_write_error(struct dentry_priv *dpr); int _unified_write_index_after_perm(int write_ret, struct unified_data *priv); @@ -271,8 +287,8 @@ void *unified_init(struct ltfs_volume *vol) pool_size = (ltfs_min_cache_size(vol) * 1024LL * 1024LL) / cache_size; max_pool_size = (ltfs_max_cache_size(vol) * 1024LL * 1024LL) / cache_size; - priv = (struct unified_data *) calloc(1, sizeof(struct unified_data)); - if (! priv) { + priv = (struct unified_data *)calloc(1, sizeof(struct unified_data)); + if (!priv) { ltfsmsg(LTFS_ERR, 10001E, "unified_init: scheduler private data"); return NULL; } @@ -281,7 +297,7 @@ void *unified_init(struct ltfs_volume *vol) priv->cache_size = cache_size; priv->cache_blocks = max_pool_size; priv->pool = cache_manager_init(cache_size, pool_size, max_pool_size); - if (! priv->pool) { + if (!priv->pool) { /* Cannot initialize scheduler: failed to initialize cache manager */ ltfsmsg(LTFS_ERR, 13005E); free(priv); @@ -376,7 +392,7 @@ void *unified_init(struct ltfs_volume *vol) */ int unified_destroy(void *iosched_handle) { - struct unified_data *priv = (struct unified_data *) iosched_handle; + struct unified_data *priv = (struct unified_data *)iosched_handle; struct dentry_priv *dpr, *aux; CHECK_ARG_NULL(iosched_handle, -LTFS_NULL_ARG); @@ -391,9 +407,9 @@ int unified_destroy(void *iosched_handle) ltfs_thread_join(priv->writer_thread); /* Push IP extents to libltfs and free remaining dentry_priv structures */ - if (! TAILQ_EMPTY(&priv->ext_queue)) { + if (!TAILQ_EMPTY(&priv->ext_queue)) { TAILQ_FOREACH_SAFE(dpr, &priv->ext_queue, ext_queue, aux) - _unified_free_dentry_priv(dpr->dentry, priv); + _unified_free_dentry_priv(dpr->dentry, priv); } /* Free data structures */ @@ -457,8 +473,7 @@ int unified_close(struct dentry *d, bool flush, void *iosched_handle) acquireread_mrsw(&priv->lock); ltfs_mutex_lock(&d->iosched_lock); - if (flush) - ret = _unified_flush_unlocked(d, priv); + if (flush) ret = _unified_flush_unlocked(d, priv); write_error = _unified_get_write_error(d->iosched_priv); _unified_free_dentry_priv_conditional(d, 3, priv); ltfs_mutex_unlock(&d->iosched_lock); @@ -510,13 +525,12 @@ ssize_t unified_read(struct dentry *d, char *buf, size_t size, off_t offset, voi acquireread_mrsw(&priv->lock); ret = ltfs_get_volume_lock(false, priv->vol); - if (ret < 0) - goto out; + if (ret < 0) goto out; releaseread_mrsw(&priv->vol->lock); ltfs_mutex_lock(&d->iosched_lock); dpr = d->iosched_priv; - if (! dpr) { + if (!dpr) { ltfs_mutex_unlock(&d->iosched_lock); ret = ltfs_fsraw_read(d, buf, size, offset, priv->vol); goto out; @@ -533,16 +547,16 @@ ssize_t unified_read(struct dentry *d, char *buf, size_t size, off_t offset, voi /* Check for cached write data, queueing up read requests for any holes in the write * request queue. */ - TAILQ_FOREACH(req, &dpr->requests, list) { + TAILQ_FOREACH(req, &dpr->requests, list) + { /* Need to get more bytes before looking at this request? */ if ((uint64_t)offset < req->offset) { to_read = req->offset - offset; - if (to_read > size) - to_read = size; + if (to_read > size) to_read = size; /* Queue up a tape read */ rreq = malloc(sizeof(struct read_request)); - if (! rreq) { + if (!rreq) { ltfsmsg(LTFS_ERR, 10001E, "unified_read: read request"); ltfs_mutex_unlock(&d->iosched_lock); ret = -LTFS_NO_MEMORY; @@ -558,15 +572,13 @@ ssize_t unified_read(struct dentry *d, char *buf, size_t size, off_t offset, voi size -= to_read; /* Are we done? */ - if (size == 0) - break; + if (size == 0) break; } /* Use some bytes from this request? */ if ((uint64_t)offset < req->offset + req->count) { to_read = req->offset + req->count - offset; - if (to_read > size) - to_read = size; + if (to_read > size) to_read = size; cache_obj = cache_manager_get_object_data(req->write_cache); memcpy(buf, &cache_obj[offset - req->offset], to_read); buf += to_read; @@ -575,23 +587,23 @@ ssize_t unified_read(struct dentry *d, char *buf, size_t size, off_t offset, voi size -= to_read; /* Are we done? */ - if (size == 0) - break; + if (size == 0) break; } } /* Issue any queued reads down to libltfs */ - if (! TAILQ_EMPTY(&requests)) { + if (!TAILQ_EMPTY(&requests)) { ltfs_mutex_lock(&dpr->io_lock); ltfs_mutex_unlock(&d->iosched_lock); have_io_lock = true; - TAILQ_FOREACH_SAFE(rreq, &requests, list, rreq_aux) { + TAILQ_FOREACH_SAFE(rreq, &requests, list, rreq_aux) + { to_read = rreq->count; nread = 0; /* Read from tape */ - if (! past_eof) { + if (!past_eof) { nread = ltfs_fsraw_read(d, rreq->buf, to_read, rreq->offset, priv->vol); if (nread < 0) { ltfs_mutex_unlock(&dpr->io_lock); @@ -609,8 +621,7 @@ ssize_t unified_read(struct dentry *d, char *buf, size_t size, off_t offset, voi * write request. If libltfs didn't return rreq->count bytes, then that outstanding * write is past libltfs' EOF. In that case, the file will eventually be truncated * out, so fill any unused portion of this read request with zeros. */ - if (to_read > 0) - memset(rreq->buf + nread, 0, to_read); + if (to_read > 0) memset(rreq->buf + nread, 0, to_read); free(rreq); } @@ -620,7 +631,7 @@ ssize_t unified_read(struct dentry *d, char *buf, size_t size, off_t offset, voi * before or within the file offset range covered by the request list. Still need to * handle the part of the read request that lies past the end of the request list. */ if (size > 0) { - if (! have_io_lock) { + if (!have_io_lock) { ltfs_mutex_lock(&dpr->io_lock); ltfs_mutex_unlock(&d->iosched_lock); } @@ -658,8 +669,8 @@ ssize_t unified_read(struct dentry *d, char *buf, size_t size, off_t offset, voi * this function is a bug. In the future, the scheduler write interface may change to * return 0 on success. */ -ssize_t unified_write(struct dentry *d, const char *buf, size_t size, off_t offset, - bool isupdatetime, void *iosched_handle) +ssize_t +unified_write(struct dentry *d, const char *buf, size_t size, off_t offset, bool isupdatetime, void *iosched_handle) { ssize_t ret = 0; struct unified_data *priv = iosched_handle; @@ -678,8 +689,7 @@ ssize_t unified_write(struct dentry *d, const char *buf, size_t size, off_t offs CHECK_ARG_NULL(iosched_handle, -LTFS_NULL_ARG); ltfs_profiler_add_entry(priv->profiler, &priv->proflock, IOSCHED_REQ_ENTER(REQ_IOS_WRITE)); - if (size == 0) - return 0; + if (size == 0) return 0; acquireread_mrsw(&priv->lock); ret = ltfs_get_volume_lock(false, priv->vol); @@ -712,7 +722,7 @@ ssize_t unified_write(struct dentry *d, const char *buf, size_t size, off_t offs } /* Disallow writes if the medium is read-only */ - if (! checked_readonly) { + if (!checked_readonly) { ret = ltfs_get_tape_readonly(priv->vol); if (ret < 0) { ltfs_mutex_unlock(&d->iosched_lock); @@ -726,8 +736,8 @@ ssize_t unified_write(struct dentry *d, const char *buf, size_t size, off_t offs /* Update data placement based on file size */ { const int readonly = ltfs_get_partition_readonly(ltfs_ip_id(priv->vol), priv->vol); - if (dpr->write_ip && ((offset + size) > index_criteria_get_max_filesize(priv->vol) || - readonly == -LTFS_NO_SPACE || readonly == -LTFS_LESS_SPACE)) + if (dpr->write_ip && ((offset + size) > index_criteria_get_max_filesize(priv->vol) || readonly == -LTFS_NO_SPACE || + readonly == -LTFS_LESS_SPACE)) _unified_unset_write_ip(dpr, priv); } @@ -745,8 +755,7 @@ ssize_t unified_write(struct dentry *d, const char *buf, size_t size, off_t offs * This makes sequential writes O(1). */ if (offset >= last_offset) { /* Try to append data to an existing request buffer */ - if (req && req->count < priv->cache_size && offset == last_offset && - req->state != REQUEST_IP) { + if (req && req->count < priv->cache_size && offset == last_offset && req->state != REQUEST_IP) { copy_count = _unified_update_request(buf, offset, size, dpr, req, priv); buf += copy_count; offset += copy_count; @@ -755,8 +764,7 @@ ssize_t unified_write(struct dentry *d, const char *buf, size_t size, off_t offs /* Append new request(s) to the end of the queue */ while (size > 0) { - ret = _unified_insert_new_request(buf, offset, size, &spare_cache, false, - NULL, d, priv); + ret = _unified_insert_new_request(buf, offset, size, &spare_cache, false, NULL, d, priv); if (ret < 0) goto out; else if (ret == 0) @@ -771,13 +779,13 @@ ssize_t unified_write(struct dentry *d, const char *buf, size_t size, off_t offs /* Not a simple append; need to traverse the request list */ prev_req = NULL; - TAILQ_FOREACH_SAFE(req, &dpr->requests, list, aux) { + TAILQ_FOREACH_SAFE(req, &dpr->requests, list, aux) + { /* Skip this request the new write belongs farther down the queue */ - if ((uint64_t)offset > req->offset + req->count) - continue; + if ((uint64_t)offset > req->offset + req->count) continue; /* Insert request(s) before the current one */ -do_insert_before: + do_insert_before: while (size > 0 && (uint64_t)offset < req->offset) { ret = _unified_insert_new_request(buf, offset, size, &spare_cache, false, req, d, priv); if (ret < 0) @@ -794,8 +802,7 @@ ssize_t unified_write(struct dentry *d, const char *buf, size_t size, off_t offs /* Merge the current request into the previous one. Resolve any overlap between * the requests using bytes from the previous request. */ did_merge = _unified_merge_requests(prev_req, req, &spare_cache, dpr, priv); - if (did_merge == 2) - continue; /* req was freed */ + if (did_merge == 2) continue; /* req was freed */ /* Handle overlaps between the new write and the current request. If the current request * is targeted at the DP, update it with new bytes. If the current request is targeted @@ -808,8 +815,9 @@ ssize_t unified_write(struct dentry *d, const char *buf, size_t size, off_t offs goto do_insert_before; } - if (req->state != REQUEST_IP && ((uint64_t)offset < req->offset + req->count || - ((uint64_t)offset == req->offset + req->count && req->count < priv->cache_size))) { + if (req->state != REQUEST_IP && + ((uint64_t)offset < req->offset + req->count || + ((uint64_t)offset == req->offset + req->count && req->count < priv->cache_size))) { /* Update this request with bytes from the new write */ did_merge = true; /* Force another iteration, merge check might be needed */ copy_count = _unified_update_request(buf, offset, size, dpr, req, priv); @@ -841,8 +849,13 @@ ssize_t unified_write(struct dentry *d, const char *buf, size_t size, off_t offs /* Split */ copy_offset = (offset - req->offset) + size; ret = _unified_insert_new_request(req_cache + copy_offset, - req->offset + copy_offset, req->count - copy_offset, - &spare_cache, true, aux, d, priv); + req->offset + copy_offset, + req->count - copy_offset, + &spare_cache, + true, + aux, + d, + priv); if (ret < 0) goto out; else if (ret == 0) @@ -856,12 +869,10 @@ ssize_t unified_write(struct dentry *d, const char *buf, size_t size, off_t offs prev_req = req; - if (size == 0 && ! did_merge) - goto out; + if (size == 0 && !did_merge) goto out; } - if (size > 0) - goto do_append; + if (size > 0) goto do_append; out: if (ret >= 0) { @@ -869,19 +880,18 @@ ssize_t unified_write(struct dentry *d, const char *buf, size_t size, off_t offs /* It's undesirable to fail the write here, as we have no way to roll back the cache * to its previous state. There's no harm in ignoring revalidation errors at this point. */ if (err == 0) { - if (isupdatetime) { - acquirewrite_mrsw(&d->meta_lock); - get_current_timespec(&d->modify_time); - d->change_time = d->modify_time; - releasewrite_mrsw(&d->meta_lock); - } + if (isupdatetime) { + acquirewrite_mrsw(&d->meta_lock); + get_current_timespec(&d->modify_time); + d->change_time = d->modify_time; + releasewrite_mrsw(&d->meta_lock); + } /* Don't set index dirty flag here. Will be set later by ltfs_fsraw_add_extent. */ releaseread_mrsw(&priv->vol->lock); } } ltfs_mutex_unlock(&d->iosched_lock); - if (spare_cache) - _unified_cache_free(spare_cache, 0, priv); + if (spare_cache) _unified_cache_free(spare_cache, 0, priv); releaseread_mrsw(&priv->lock); ltfs_profiler_add_entry(priv->profiler, &priv->proflock, IOSCHED_REQ_EXIT(REQ_IOS_WRITE)); return (ret < 0) ? ret : (ssize_t)original_size; @@ -950,8 +960,9 @@ int unified_truncate(struct dentry *d, off_t length, void *iosched_handle) dpr = d->iosched_priv; if (dpr) { if ((uint64_t)length < dpr->file_size) { - if (! TAILQ_EMPTY(&dpr->requests)) { - TAILQ_FOREACH_REVERSE_SAFE(req, &dpr->requests, req_struct, list, aux) { + if (!TAILQ_EMPTY(&dpr->requests)) { + TAILQ_FOREACH_REVERSE_SAFE(req, &dpr->requests, req_struct, list, aux) + { if (req->offset >= (uint64_t)length) { TAILQ_REMOVE(&dpr->requests, req, list); _unified_update_queue_membership(false, false, req->state, dpr, priv); @@ -963,8 +974,9 @@ int unified_truncate(struct dentry *d, off_t length, void *iosched_handle) } } - if (! TAILQ_EMPTY(&dpr->alt_extentlist)) { - TAILQ_FOREACH_SAFE(ext, &dpr->alt_extentlist, list, ext_aux) { + if (!TAILQ_EMPTY(&dpr->alt_extentlist)) { + TAILQ_FOREACH_SAFE(ext, &dpr->alt_extentlist, list, ext_aux) + { if (ext->fileoffset >= (uint64_t)length) { TAILQ_REMOVE(&dpr->alt_extentlist, ext, list); free(ext); @@ -985,11 +997,9 @@ int unified_truncate(struct dentry *d, off_t length, void *iosched_handle) /* Only reset write_ip if the new size is 0 (complete rewrite) to avoid interleaving * DP and IP extents in a single file. */ - if (! dpr->write_ip && max_filesize > 0 && length == 0 - && matches_name_criteria && ! deleted) + if (!dpr->write_ip && max_filesize > 0 && length == 0 && matches_name_criteria && !deleted) _unified_set_write_ip(dpr, priv); - else if (dpr->write_ip - && (dpr->file_size > max_filesize || ! matches_name_criteria || deleted)) + else if (dpr->write_ip && (dpr->file_size > max_filesize || !matches_name_criteria || deleted)) _unified_unset_write_ip(dpr, priv); /* Tell libltfs about the truncate request */ @@ -1001,8 +1011,7 @@ int unified_truncate(struct dentry *d, off_t length, void *iosched_handle) ltfs_mutex_unlock(&d->iosched_lock); releaseread_mrsw(&priv->lock); - if (! dpr) - ret = ltfs_fsraw_truncate(d, length, priv->vol); + if (!dpr) ret = ltfs_fsraw_truncate(d, length, priv->vol); ltfs_profiler_add_entry(priv->profiler, &priv->proflock, IOSCHED_REQ_EXIT(REQ_IOS_TRUNCATE)); return ret; @@ -1028,14 +1037,13 @@ uint64_t unified_get_filesize(struct dentry *d, void *iosched_handle) /* Try to get the file size from the dentry_priv */ acquireread_mrsw(&priv->lock); ltfs_mutex_lock(&d->iosched_lock); - dentry_priv = (struct dentry_priv *) d->iosched_priv; - if (dentry_priv) - size = dentry_priv->file_size; + dentry_priv = (struct dentry_priv *)d->iosched_priv; + if (dentry_priv) size = dentry_priv->file_size; ltfs_mutex_unlock(&d->iosched_lock); releaseread_mrsw(&priv->lock); /* If there was no dentry_priv, return file size as stored in the dentry structure */ - if (! dentry_priv) { + if (!dentry_priv) { acquireread_mrsw(&d->meta_lock); size = d->size; releaseread_mrsw(&d->meta_lock); @@ -1058,7 +1066,7 @@ uint64_t unified_get_filesize(struct dentry *d, void *iosched_handle) */ int unified_update_data_placement(struct dentry *d, void *iosched_handle) { - struct unified_data *priv = (struct unified_data *) iosched_handle; + struct unified_data *priv = (struct unified_data *)iosched_handle; struct dentry_priv *dpr; uint64_t filesize, max_filesize; bool matches_name_criteria, deleted; @@ -1071,8 +1079,7 @@ int unified_update_data_placement(struct dentry *d, void *iosched_handle) ltfs_mutex_lock(&d->iosched_lock); dpr = d->iosched_priv; - if (! dpr) - goto out; + if (!dpr) goto out; filesize = dpr->file_size; max_filesize = index_criteria_get_max_filesize(priv->vol); @@ -1082,10 +1089,9 @@ int unified_update_data_placement(struct dentry *d, void *iosched_handle) deleted = d->deleted; releaseread_mrsw(&d->meta_lock); - if (! dpr->write_ip && max_filesize > 0 && filesize <= max_filesize && matches_name_criteria - && ! deleted) + if (!dpr->write_ip && max_filesize > 0 && filesize <= max_filesize && matches_name_criteria && !deleted) _unified_set_write_ip(dpr, priv); - else if (dpr->write_ip && (filesize > max_filesize || ! matches_name_criteria || deleted)) + else if (dpr->write_ip && (filesize > max_filesize || !matches_name_criteria || deleted)) _unified_unset_write_ip(dpr, priv); out: @@ -1106,7 +1112,7 @@ int unified_update_data_placement(struct dentry *d, void *iosched_handle) */ ltfs_thread_return _unified_writer_thread(void *iosched_handle) { - struct unified_data *priv = (struct unified_data *) iosched_handle; + struct unified_data *priv = (struct unified_data *)iosched_handle; while (true) { ltfs_thread_mutex_lock(&priv->queue_lock); @@ -1115,7 +1121,7 @@ ltfs_thread_return _unified_writer_thread(void *iosched_handle) ltfs_thread_cond_wait(&priv->queue_cond, &priv->queue_lock); ltfs_profiler_add_entry(priv->profiler, &priv->proflock, IOSCHED_REQ_ENTER(REQ_IOS_IOSCHED)); - if (! priv->writer_keepalive) { + if (!priv->writer_keepalive) { ltfs_thread_mutex_unlock(&priv->queue_lock); _unified_flush_all(priv); _unified_process_queue(REQUEST_IP, priv); @@ -1146,13 +1152,12 @@ ltfs_thread_return _unified_writer_thread(void *iosched_handle) void _unified_process_queue(enum request_state queue, struct unified_data *priv) { - if (! priv) { + if (!priv) { ltfsmsg(LTFS_ERR, 10005E, "priv", __FUNCTION__); return; } - if (queue == REQUEST_IP) - /* Process Index Partition queue */ + if (queue == REQUEST_IP) /* Process Index Partition queue */ _unified_process_index_queue(priv); else /* Process Data Partition / Working Set queue */ @@ -1169,23 +1174,24 @@ void _unified_process_index_queue(struct unified_data *priv) partition_id = ltfs_ip_id(priv->vol); acquirewrite_mrsw(&priv->lock); - TAILQ_FOREACH_SAFE(dentry_priv, &priv->ip_queue, ip_queue, dpr_aux) { + TAILQ_FOREACH_SAFE(dentry_priv, &priv->ip_queue, ip_queue, dpr_aux) + { /* Remove dentry_priv from the IP queue, process its IP requests, * then free it if the request list is empty. */ _unified_update_queue_membership(false, true, REQUEST_IP, dentry_priv, priv); - TAILQ_FOREACH_SAFE(req, &dentry_priv->requests, list, req_aux) { + TAILQ_FOREACH_SAFE(req, &dentry_priv->requests, list, req_aux) + { if (req->state == REQUEST_IP) { char *cache_obj = cache_manager_get_object_data(req->write_cache); struct extent_info *extent = calloc(1, sizeof(struct extent_info)); - if (! extent) { + if (!extent) { ltfsmsg(LTFS_ERR, 10001E, "_unified_process_index_queue: extent"); _unified_handle_write_error(-ENOMEM, req, dentry_priv, priv); break; } - ret = ltfs_fsraw_write_data(partition_id, cache_obj, req->count, 1, - &extent->start.block, priv->vol); + ret = ltfs_fsraw_write_data(partition_id, cache_obj, req->count, 1, &extent->start.block, priv->vol); if (ret < 0) { /* Index partition writer: failed to write data to the tape (%d) */ ltfsmsg(LTFS_WARN, 13013W, (int)ret); @@ -1229,16 +1235,16 @@ void _unified_process_data_queue(enum request_state queue, struct unified_data * * Process only the 'count' entries that are known to be in the queue. * This is needed to guarantee a limited runtime. */ - for (i=0; iqueue_lock); - if (! TAILQ_EMPTY(dq)) + if (!TAILQ_EMPTY(dq)) dentry_priv = TAILQ_FIRST(dq); - else if (queue == REQUEST_PARTIAL && ! TAILQ_EMPTY(ws)) + else if (queue == REQUEST_PARTIAL && !TAILQ_EMPTY(ws)) dentry_priv = TAILQ_FIRST(ws); else { ltfs_thread_mutex_unlock(&priv->queue_lock); @@ -1247,7 +1253,7 @@ void _unified_process_data_queue(enum request_state queue, struct unified_data * dentry = dentry_priv->dentry; ltfs_thread_mutex_unlock(&priv->queue_lock); - if (! dentry) { + if (!dentry) { /* Invalid backpointer to the dentry in the dentry_priv structure */ /* Note: this can only happen if there is a bug elsewhere. */ ltfsmsg(LTFS_ERR, 13011E); @@ -1256,7 +1262,7 @@ void _unified_process_data_queue(enum request_state queue, struct unified_data * ltfs_mutex_lock(&dentry->iosched_lock); dentry_priv = dentry->iosched_priv; - if (! dentry_priv) { + if (!dentry_priv) { /* Someone else took care of this dentry */ ltfs_mutex_unlock(&dentry->iosched_lock); continue; @@ -1264,22 +1270,20 @@ void _unified_process_data_queue(enum request_state queue, struct unified_data * /* Remove dentry_priv from the DP queue, also from the working set if requested */ _unified_update_queue_membership(false, true, queue, dentry_priv, priv); - if (queue == REQUEST_PARTIAL) - _unified_update_queue_membership(false, true, REQUEST_DP, dentry_priv, priv); + if (queue == REQUEST_PARTIAL) _unified_update_queue_membership(false, true, REQUEST_DP, dentry_priv, priv); /* Move entries to be processed into a private list */ TAILQ_INIT(&local_req_list); ltfs_mutex_lock(&dentry_priv->io_lock); - TAILQ_FOREACH_SAFE(req, &dentry_priv->requests, list, req_aux) { + TAILQ_FOREACH_SAFE(req, &dentry_priv->requests, list, req_aux) + { if (req->state == REQUEST_IP) { - _unified_merge_requests(TAILQ_PREV(req, req_struct, list), req, NULL, - dentry_priv, priv); + _unified_merge_requests(TAILQ_PREV(req, req_struct, list), req, NULL, dentry_priv, priv); } else if (req->state == REQUEST_DP || queue == REQUEST_PARTIAL) { if (dentry_priv->write_ip) { char *cache_obj = cache_manager_get_object_data(req->write_cache); - ret = ltfs_fsraw_write(dentry, cache_obj, req->count, req->offset, - partition_id, false, priv->vol); + ret = ltfs_fsraw_write(dentry, cache_obj, req->count, req->offset, partition_id, false, priv->vol); if (ret < 0) { /* Data partition writer: failed to write data to the tape (%d) */ ltfsmsg(LTFS_WARN, 13014W, (int)ret); @@ -1288,10 +1292,8 @@ void _unified_process_data_queue(enum request_state queue, struct unified_data * break; } else { req->state = REQUEST_IP; - _unified_update_queue_membership(true, false, REQUEST_IP, - dentry_priv, priv); - _unified_merge_requests(TAILQ_PREV(req, req_struct, list), req, NULL, - dentry_priv, priv); + _unified_update_queue_membership(true, false, REQUEST_IP, dentry_priv, priv); + _unified_merge_requests(TAILQ_PREV(req, req_struct, list), req, NULL, dentry_priv, priv); } } else { @@ -1306,11 +1308,11 @@ void _unified_process_data_queue(enum request_state queue, struct unified_data * ltfs_mutex_unlock(&dentry->iosched_lock); /* Send requests to tape */ - if (! TAILQ_EMPTY(&local_req_list)) { - TAILQ_FOREACH_SAFE(req, &local_req_list, list, req_aux) { + if (!TAILQ_EMPTY(&local_req_list)) { + TAILQ_FOREACH_SAFE(req, &local_req_list, list, req_aux) + { char *cache_obj = cache_manager_get_object_data(req->write_cache); - ret = ltfs_fsraw_write(dentry, cache_obj, req->count, req->offset, - partition_id, false, priv->vol); + ret = ltfs_fsraw_write(dentry, cache_obj, req->count, req->offset, partition_id, false, priv->vol); if (ret < 0) { /* Data partition writer: failed to write data to the tape (%d) */ ltfsmsg(LTFS_WARN, 13014W, (int)ret); @@ -1323,7 +1325,7 @@ void _unified_process_data_queue(enum request_state queue, struct unified_data * } /* If there are requests left, then a write error (ret) occurred */ - if (! TAILQ_EMPTY(&local_req_list)) { + if (!TAILQ_EMPTY(&local_req_list)) { ltfs_mutex_unlock(&dentry_priv->io_lock); ltfs_mutex_lock(&dentry->iosched_lock); if (dentry->iosched_priv) { @@ -1334,15 +1336,15 @@ void _unified_process_data_queue(enum request_state queue, struct unified_data * dentry_priv = NULL; ltfs_mutex_unlock(&dentry->iosched_lock); - TAILQ_FOREACH_SAFE(req, &local_req_list, list, req_aux) { + TAILQ_FOREACH_SAFE(req, &local_req_list, list, req_aux) + { TAILQ_REMOVE(&local_req_list, req, list); _unified_free_request(req, priv); } } } - if (dentry_priv) - ltfs_mutex_unlock(&dentry_priv->io_lock); + if (dentry_priv) ltfs_mutex_unlock(&dentry_priv->io_lock); } releaseread_mrsw(&priv->lock); @@ -1359,8 +1361,7 @@ void _unified_process_data_queue(enum request_state queue, struct unified_data * * @return 0 on success or a negative value on error. This function always succeeds * if alloc is false. */ -int _unified_get_dentry_priv(struct dentry *d, struct dentry_priv **dentry_priv, - struct unified_data *priv) +int _unified_get_dentry_priv(struct dentry *d, struct dentry_priv **dentry_priv, struct unified_data *priv) { int ret; size_t max_filesize; @@ -1372,7 +1373,7 @@ int _unified_get_dentry_priv(struct dentry *d, struct dentry_priv **dentry_priv, } dpr = calloc(1, sizeof(struct dentry_priv)); - if (! dpr) { + if (!dpr) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } @@ -1403,8 +1404,7 @@ int _unified_get_dentry_priv(struct dentry *d, struct dentry_priv **dentry_priv, dpr->write_ip = d->matches_name_criteria; releaseread_mrsw(&d->meta_lock); max_filesize = index_criteria_get_max_filesize(priv->vol); - if (max_filesize == 0 || dpr->file_size > max_filesize) - dpr->write_ip = false; + if (max_filesize == 0 || dpr->file_size > max_filesize) dpr->write_ip = false; d->iosched_priv = dpr; ltfs_fsraw_get_dentry(d, priv->vol); @@ -1420,8 +1420,7 @@ int _unified_get_dentry_priv(struct dentry *d, struct dentry_priv **dentry_priv, * @param dpr Dentry_priv to modify. * @param priv I/O scheduler private data. */ -void _unified_update_alt_extentlist(struct extent_info *newext, struct dentry_priv *dpr, - struct unified_data *priv) +void _unified_update_alt_extentlist(struct extent_info *newext, struct dentry_priv *dpr, struct unified_data *priv) { bool newext_used = false, free_newext = false; uint64_t newext_fileoffset_end, entry_fileoffset_end, fileoffset_diff; @@ -1442,10 +1441,11 @@ void _unified_update_alt_extentlist(struct extent_info *newext, struct dentry_pr blocksize = priv->vol->label->blocksize; newext_fileoffset_end = newext->fileoffset + newext->bytecount; - TAILQ_FOREACH_SAFE(entry, &dpr->alt_extentlist, list, aux) { + TAILQ_FOREACH_SAFE(entry, &dpr->alt_extentlist, list, aux) + { entry_fileoffset_end = entry->fileoffset + entry->bytecount; - if (! newext_used && newext->fileoffset <= entry->fileoffset) { + if (!newext_used && newext->fileoffset <= entry->fileoffset) { TAILQ_INSERT_BEFORE(entry, newext, list); newext_used = true; } @@ -1458,8 +1458,7 @@ void _unified_update_alt_extentlist(struct extent_info *newext, struct dentry_pr entry_byteoffset_end = entry->byteoffset + entry->bytecount; entry_blockcount = entry_byteoffset_end / blocksize; if (newext->byteoffset == 0 && /* NOTE: assuming all extents are in the IP */ - entry_byteoffset_end % blocksize == 0 && - entry->start.block + entry_blockcount == newext->start.block) { + entry_byteoffset_end % blocksize == 0 && entry->start.block + entry_blockcount == newext->start.block) { /* Append newext's bytes to this extent */ entry->bytecount += newext->bytecount; newext_used = true; @@ -1499,11 +1498,9 @@ void _unified_update_alt_extentlist(struct extent_info *newext, struct dentry_pr } } - if (! newext_used) - TAILQ_INSERT_TAIL(&dpr->alt_extentlist, newext, list); + if (!newext_used) TAILQ_INSERT_TAIL(&dpr->alt_extentlist, newext, list); - if (free_newext) - free(newext); + if (free_newext) free(newext); } /** @@ -1517,17 +1514,18 @@ void _unified_clear_alt_extentlist(bool save, struct dentry_priv *dpr, struct un int ret; struct extent_info *ext, *aux; - if (! TAILQ_EMPTY(&dpr->alt_extentlist)) { + if (!TAILQ_EMPTY(&dpr->alt_extentlist)) { if (save) { - TAILQ_FOREACH_SAFE(ext, &dpr->alt_extentlist, list, aux) { + TAILQ_FOREACH_SAFE(ext, &dpr->alt_extentlist, list, aux) + { TAILQ_REMOVE(&dpr->alt_extentlist, ext, list); ret = ltfs_fsraw_add_extent(dpr->dentry, ext, false, priv->vol); - if (ret < 0) - ltfsmsg(LTFS_WARN, 13021W, ret); + if (ret < 0) ltfsmsg(LTFS_WARN, 13021W, ret); free(ext); } } else { - TAILQ_FOREACH_SAFE(ext, &dpr->alt_extentlist, list, aux) { + TAILQ_FOREACH_SAFE(ext, &dpr->alt_extentlist, list, aux) + { TAILQ_REMOVE(&dpr->alt_extentlist, ext, list); free(ext); } @@ -1551,8 +1549,8 @@ void _unified_clear_alt_extentlist(bool save, struct dentry_priv *dpr, struct un * @param priv Handle to the I/O scheduler data. * @return 0 on success or a negative value on error. */ -int _unified_update_queue_membership(bool add, bool all, enum request_state queue, - struct dentry_priv *dentry_priv, struct unified_data *priv) +int _unified_update_queue_membership( + bool add, bool all, enum request_state queue, struct dentry_priv *dentry_priv, struct unified_data *priv) { int ret = 0; @@ -1564,7 +1562,7 @@ int _unified_update_queue_membership(bool add, bool all, enum request_state queu switch (queue) { case REQUEST_PARTIAL: if (add) { - if (! dentry_priv->in_working_set) { + if (!dentry_priv->in_working_set) { TAILQ_INSERT_TAIL(&priv->working_set, dentry_priv, working_set); ++priv->ws_count; } @@ -1587,14 +1585,13 @@ int _unified_update_queue_membership(bool add, bool all, enum request_state queu case REQUEST_DP: if (add) { - if (! dentry_priv->in_dp_queue) { + if (!dentry_priv->in_dp_queue) { TAILQ_INSERT_TAIL(&priv->dp_queue, dentry_priv, dp_queue); ++priv->dp_count; /* Tell background thread a write request is ready */ ltfs_thread_cond_signal(&priv->queue_cond); } - if (! dentry_priv->write_ip) - ++priv->dp_request_count; + if (!dentry_priv->write_ip) ++priv->dp_request_count; ++dentry_priv->in_dp_queue; ltfs_profiler_add_entry(priv->profiler, &priv->proflock, IOSCHED_REQ_EVENT(REQ_IOS_ENQUEUE_DP)); } else { @@ -1603,12 +1600,10 @@ int _unified_update_queue_membership(bool add, bool all, enum request_state queu --priv->dp_count; } if (all) { - if (! dentry_priv->write_ip) - priv->dp_request_count -= dentry_priv->in_dp_queue; + if (!dentry_priv->write_ip) priv->dp_request_count -= dentry_priv->in_dp_queue; dentry_priv->in_dp_queue = 0; } else if (dentry_priv->in_dp_queue) { - if (! dentry_priv->write_ip) - --priv->dp_request_count; + if (!dentry_priv->write_ip) --priv->dp_request_count; --dentry_priv->in_dp_queue; } } @@ -1616,7 +1611,7 @@ int _unified_update_queue_membership(bool add, bool all, enum request_state queu case REQUEST_IP: if (add) { - if (! dentry_priv->in_ip_queue) { + if (!dentry_priv->in_ip_queue) { TAILQ_INSERT_TAIL(&priv->ip_queue, dentry_priv, ip_queue); ++priv->ip_count; } @@ -1656,8 +1651,7 @@ int _unified_update_queue_membership(bool add, bool all, enum request_state queu */ void _unified_free_request(struct write_request *req, struct unified_data *priv) { - if (req->write_cache) - _unified_cache_free(req->write_cache, req->count, priv); + if (req->write_cache) _unified_cache_free(req->write_cache, req->count, priv); free(req); } @@ -1703,7 +1697,7 @@ int _unified_cache_alloc(void **cache, struct dentry *d, struct unified_data *pr ++priv->cache_requests; ltfs_thread_mutex_unlock(&priv->queue_lock); releaseread_mrsw(&priv->lock); - while (! (*cache)) { + while (!(*cache)) { ltfs_thread_cond_wait(&priv->cache_cond, &priv->cache_lock); *cache = cache_manager_allocate_object(priv->pool); } @@ -1737,15 +1731,21 @@ int _unified_cache_alloc(void **cache, struct dentry *d, struct unified_data *pr * or a negative value on error. d->iosched_lock is released if the function returns 0; * all locks are released on error. */ -ssize_t _unified_insert_new_request(const char *buf, off_t offset, size_t count, void **cache, - bool ip_state, struct write_request *req, struct dentry *d, struct unified_data *priv) +ssize_t _unified_insert_new_request(const char *buf, + off_t offset, + size_t count, + void **cache, + bool ip_state, + struct write_request *req, + struct dentry *d, + struct unified_data *priv) { int ret; struct dentry_priv *dpr = d->iosched_priv; struct write_request *new_req = NULL; size_t copy_count; - if (! (*cache)) { + if (!(*cache)) { ret = _unified_cache_alloc(cache, d, priv); if (ret < 0) { ltfsmsg(LTFS_ERR, 13017E, (int)ret); @@ -1759,13 +1759,12 @@ ssize_t _unified_insert_new_request(const char *buf, off_t offset, size_t count, /* Copy data to the spare cache block */ copy_count = count; - if (copy_count > priv->cache_size) - copy_count = priv->cache_size; + if (copy_count > priv->cache_size) copy_count = priv->cache_size; memcpy(cache_manager_get_object_data(*cache), buf, copy_count); /* Store new write request */ - new_req = (struct write_request*)calloc(1, sizeof(struct write_request)); - if (! new_req) { + new_req = (struct write_request *)calloc(1, sizeof(struct write_request)); + if (!new_req) { ltfsmsg(LTFS_ERR, 13018E); _unified_cache_free(*cache, 0, priv); ltfs_mutex_unlock(&d->iosched_lock); @@ -1787,8 +1786,7 @@ ssize_t _unified_insert_new_request(const char *buf, off_t offset, size_t count, _unified_update_queue_membership(true, false, new_req->state, dpr, priv); /* Update file size */ - if (new_req->offset + new_req->count > dpr->file_size) - dpr->file_size = new_req->offset + new_req->count; + if (new_req->offset + new_req->count > dpr->file_size) dpr->file_size = new_req->offset + new_req->count; return (ssize_t)count; } @@ -1808,30 +1806,32 @@ ssize_t _unified_insert_new_request(const char *buf, off_t offset, size_t count, * @return Number of bytes written to req->write_cache from the beginning of buf. * This function does not fail. */ -size_t _unified_update_request(const char *buf, off_t offset, size_t size, - struct dentry_priv *dpr, struct write_request *req, struct unified_data *priv) +size_t _unified_update_request(const char *buf, + off_t offset, + size_t size, + struct dentry_priv *dpr, + struct write_request *req, + struct unified_data *priv) { size_t copy_offset; /* Offset into req->write_cache */ size_t copy_count; char *req_cache; struct write_request *w_req; - if (size == 0) - return 0; + if (size == 0) return 0; req_cache = cache_manager_get_object_data(req->write_cache); copy_offset = offset - req->offset; copy_count = (req->offset + priv->cache_size) - offset; - if (copy_count > size) - copy_count = size; + if (copy_count > size) copy_count = size; memcpy(req_cache + copy_offset, buf, copy_count); - if (copy_offset + copy_count > req->count) - req->count = copy_offset + copy_count; + if (copy_offset + copy_count > req->count) req->count = copy_offset + copy_count; if (req->state == REQUEST_PARTIAL && req->count == priv->cache_size) { - TAILQ_FOREACH(w_req, &dpr->requests, list) { + TAILQ_FOREACH(w_req, &dpr->requests, list) + { if (w_req->state == REQUEST_PARTIAL && w_req->offset <= (uint64_t)offset) { _unified_update_queue_membership(false, false, REQUEST_PARTIAL, dpr, priv); w_req->state = REQUEST_DP; @@ -1841,8 +1841,7 @@ size_t _unified_update_request(const char *buf, off_t offset, size_t size, } /* Update file size */ - if (req->offset + req->count > dpr->file_size) - dpr->file_size = req->offset + req->count; + if (req->offset + req->count > dpr->file_size) dpr->file_size = req->offset + req->count; return copy_count; } @@ -1861,15 +1860,17 @@ size_t _unified_update_request(const char *buf, off_t offset, size_t size, * @param priv I/O scheduler private data. * @return 2 if src was freed, 1 if it was modified, 0 otherwise. */ -int _unified_merge_requests(struct write_request *dest, struct write_request *src, - void **spare_cache, struct dentry_priv *dpr, struct unified_data *priv) +int _unified_merge_requests(struct write_request *dest, + struct write_request *src, + void **spare_cache, + struct dentry_priv *dpr, + struct unified_data *priv) { int ret = 0; char *src_cache; size_t copy_offset, copy_count; - if (! dest || src->offset > dest->offset + dest->count) - return 0; + if (!dest || src->offset > dest->offset + dest->count) return 0; src_cache = cache_manager_get_object_data(src->write_cache); copy_offset = (dest->offset + dest->count) - src->offset; @@ -1880,8 +1881,8 @@ int _unified_merge_requests(struct write_request *dest, struct write_request *sr if (dest->state != src->state && (dest->state == REQUEST_IP || src->state == REQUEST_IP)) copy_count = 0; else if (dest->count < priv->cache_size && src->count > copy_offset) - copy_count = _unified_update_request(src_cache + copy_offset, - src->offset + copy_offset, src->count - copy_offset, dpr, dest, priv); + copy_count = _unified_update_request( + src_cache + copy_offset, src->offset + copy_offset, src->count - copy_offset, dpr, dest, priv); else copy_count = 0; @@ -1902,7 +1903,7 @@ int _unified_merge_requests(struct write_request *dest, struct write_request *sr ret = 2; TAILQ_REMOVE(&dpr->requests, src, list); _unified_update_queue_membership(false, false, src->state, dpr, priv); - if (! spare_cache || *spare_cache) + if (!spare_cache || *spare_cache) _unified_free_request(src, priv); else { *spare_cache = src->write_cache; @@ -1936,16 +1937,13 @@ int _unified_flush_unlocked(struct dentry *d, struct unified_data *priv) dp_id = ltfs_dp_id(priv->vol); dpr = d->iosched_priv; - if (! dpr) - return 0; + if (!dpr) return 0; /* Check for previous write errors */ ret = _unified_get_write_error(dpr); - if (ret < 0) - return ret; + if (ret < 0) return ret; - if (TAILQ_EMPTY(&dpr->requests)) - return 0; + if (TAILQ_EMPTY(&dpr->requests)) return 0; /* Remove dpr from the DP queue and working set */ _unified_update_queue_membership(false, true, REQUEST_DP, dpr, priv); @@ -1953,7 +1951,8 @@ int _unified_flush_unlocked(struct dentry *d, struct unified_data *priv) ltfs_mutex_lock(&dpr->io_lock); - TAILQ_FOREACH_SAFE(req, &dpr->requests, list, aux) { + TAILQ_FOREACH_SAFE(req, &dpr->requests, list, aux) + { if (req->state == REQUEST_IP) _unified_merge_requests(TAILQ_PREV(req, req_struct, list), req, NULL, dpr, priv); else { @@ -1996,8 +1995,9 @@ int _unified_flush_all(struct unified_data *priv) acquirewrite_mrsw(&priv->lock); - if (! TAILQ_EMPTY(&priv->dp_queue)) { - TAILQ_FOREACH_SAFE(dpr, &priv->dp_queue, dp_queue, aux) { + if (!TAILQ_EMPTY(&priv->dp_queue)) { + TAILQ_FOREACH_SAFE(dpr, &priv->dp_queue, dp_queue, aux) + { ret = _unified_flush_unlocked(dpr->dentry, priv); if (ret < 0) { ltfsmsg(LTFS_ERR, 13020E, dpr->dentry->platform_safe_name, ret); @@ -2007,8 +2007,9 @@ int _unified_flush_all(struct unified_data *priv) } } - if (! TAILQ_EMPTY(&priv->working_set)) { - TAILQ_FOREACH_SAFE(dpr, &priv->working_set, working_set, aux) { + if (!TAILQ_EMPTY(&priv->working_set)) { + TAILQ_FOREACH_SAFE(dpr, &priv->working_set, working_set, aux) + { ret = _unified_flush_unlocked(dpr->dentry, priv); if (ret < 0) { ltfsmsg(LTFS_ERR, 13020E, dpr->dentry->platform_safe_name, ret); @@ -2033,8 +2034,7 @@ int _unified_flush_all(struct unified_data *priv) * @param target_handles Only free the dentry_priv if the dentry has this many handles or fewer. * @param priv I/O scheduler private data. */ -void _unified_free_dentry_priv_conditional(struct dentry *d, uint32_t target_handles, - struct unified_data *priv) +void _unified_free_dentry_priv_conditional(struct dentry *d, uint32_t target_handles, struct unified_data *priv) { uint32_t numhandles; struct dentry_priv *dpr; @@ -2044,8 +2044,7 @@ void _unified_free_dentry_priv_conditional(struct dentry *d, uint32_t target_han releaseread_mrsw(&d->meta_lock); dpr = d->iosched_priv; - if (dpr && numhandles <= target_handles && TAILQ_EMPTY(&dpr->requests) && - TAILQ_EMPTY(&dpr->alt_extentlist)) { + if (dpr && numhandles <= target_handles && TAILQ_EMPTY(&dpr->requests) && TAILQ_EMPTY(&dpr->alt_extentlist)) { /* Take I/O lock first. The background thread could be processing this dentry */ ltfs_mutex_lock(&dpr->io_lock); ltfs_mutex_unlock(&dpr->io_lock); @@ -2070,19 +2069,16 @@ void _unified_free_dentry_priv(struct dentry *d, struct unified_data *priv) { struct dentry_priv *dpr = d->iosched_priv; - if (! dpr) - return; + if (!dpr) return; - if (! TAILQ_EMPTY(&dpr->requests)) - ltfsmsg(LTFS_WARN, 13022W); + if (!TAILQ_EMPTY(&dpr->requests)) ltfsmsg(LTFS_WARN, 13022W); /* Wait for background thread to finish flushing requests */ ltfs_mutex_lock(&dpr->io_lock); ltfs_mutex_unlock(&dpr->io_lock); /* Sent alt_extentlist to libltfs */ - if (dpr->write_ip && ! TAILQ_EMPTY(&dpr->alt_extentlist)) - _unified_clear_alt_extentlist(true, dpr, priv); + if (dpr->write_ip && !TAILQ_EMPTY(&dpr->alt_extentlist)) _unified_clear_alt_extentlist(true, dpr, priv); ltfs_mutex_destroy(&dpr->write_error_lock); ltfs_mutex_destroy(&dpr->io_lock); @@ -2127,7 +2123,8 @@ void _unified_unset_write_ip(struct dentry_priv *dpr, struct unified_data *priv) /* Remove dentry_priv from the ip_queue */ if (dpr->in_ip_queue) { - TAILQ_FOREACH_SAFE(req, &dpr->requests, list, req_aux) { + TAILQ_FOREACH_SAFE(req, &dpr->requests, list, req_aux) + { if (req->state == REQUEST_IP) { TAILQ_REMOVE(&dpr->requests, req, list); _unified_free_request(req, priv); @@ -2147,8 +2144,7 @@ void _unified_unset_write_ip(struct dentry_priv *dpr, struct unified_data *priv) } /* Clear the alt_extentlist */ - if (! TAILQ_EMPTY(&dpr->alt_extentlist)) - _unified_clear_alt_extentlist(false, dpr, priv); + if (!TAILQ_EMPTY(&dpr->alt_extentlist)) _unified_clear_alt_extentlist(false, dpr, priv); } /** @@ -2167,8 +2163,10 @@ void _unified_unset_write_ip(struct dentry_priv *dpr, struct unified_data *priv) * @param priv I/O scheduler data. * @return true if the error was fatal, false otherwise. */ -void _unified_handle_write_error(ssize_t write_ret, struct write_request *failed_req, - struct dentry_priv *dpr, struct unified_data *priv) +void _unified_handle_write_error(ssize_t write_ret, + struct write_request *failed_req, + struct dentry_priv *dpr, + struct unified_data *priv) { struct write_request *req, *aux; bool clear_dp = false, clear_ip = false; @@ -2177,10 +2175,9 @@ void _unified_handle_write_error(ssize_t write_ret, struct write_request *failed * an out of space error. That is not a hard failure, as the data is known to be on the DP * at that point. Other IP errors are worth reporting because they may affect LTFS' ability * to make the volume consistent. */ - if (! (failed_req->state == REQUEST_IP && (write_ret == -LTFS_NO_SPACE || write_ret == -LTFS_LESS_SPACE))) { + if (!(failed_req->state == REQUEST_IP && (write_ret == -LTFS_NO_SPACE || write_ret == -LTFS_LESS_SPACE))) { ltfs_mutex_lock(&dpr->write_error_lock); - if (dpr->write_error == 0) - dpr->write_error = write_ret; + if (dpr->write_error == 0) dpr->write_error = write_ret; ltfs_mutex_unlock(&dpr->write_error_lock); } @@ -2190,13 +2187,13 @@ void _unified_handle_write_error(ssize_t write_ret, struct write_request *failed if (failed_req->state == REQUEST_IP) { clear_ip = true; if ((write_ret != -LTFS_NO_SPACE && write_ret != -LTFS_LESS_SPACE) || - ltfs_get_partition_readonly(ltfs_dp_id(priv->vol), priv->vol) < 0) { + ltfs_get_partition_readonly(ltfs_dp_id(priv->vol), priv->vol) < 0) { clear_dp = true; } } else { clear_dp = true; if ((write_ret != -LTFS_NO_SPACE && write_ret != -LTFS_LESS_SPACE) || - ltfs_get_partition_readonly(ltfs_ip_id(priv->vol), priv->vol) < 0) { + ltfs_get_partition_readonly(ltfs_ip_id(priv->vol), priv->vol) < 0) { clear_ip = true; } } @@ -2207,14 +2204,14 @@ void _unified_handle_write_error(ssize_t write_ret, struct write_request *failed releaseread_mrsw(&dpr->dentry->meta_lock); /* Remove requests from the selected partitions */ - if (! TAILQ_EMPTY(&dpr->requests)) { + if (!TAILQ_EMPTY(&dpr->requests)) { if (clear_dp) { _unified_update_queue_membership(false, true, REQUEST_DP, dpr, priv); _unified_update_queue_membership(false, true, REQUEST_PARTIAL, dpr, priv); } - if (clear_ip) - _unified_update_queue_membership(false, true, REQUEST_IP, dpr, priv); - TAILQ_FOREACH_SAFE(req, &dpr->requests, list, aux) { + if (clear_ip) _unified_update_queue_membership(false, true, REQUEST_IP, dpr, priv); + TAILQ_FOREACH_SAFE(req, &dpr->requests, list, aux) + { if ((req->state == REQUEST_IP && clear_ip) || (req->state != REQUEST_IP && clear_dp)) { TAILQ_REMOVE(&dpr->requests, req, list); _unified_free_request(req, priv); @@ -2260,8 +2257,7 @@ int _unified_write_index_after_perm(int write_ret, struct unified_data *priv) ltfsmsg(LTFS_INFO, 13024I, write_ret); ret = tape_set_cart_volume_lock_status(priv->vol, PWE_MAM_DP); - if (ret < 0) - ltfsmsg(LTFS_ERR, 13026E, "update MAM", ret); + if (ret < 0) ltfsmsg(LTFS_ERR, 13026E, "update MAM", ret); blocksize = ltfs_get_blocksize(priv->vol); @@ -2279,8 +2275,11 @@ int _unified_write_index_after_perm(int write_ret, struct unified_data *priv) } if (last_index_pos > err_pos.block) { - ltfsmsg(LTFS_INFO, 13027I, (int)err_pos.partition, - (unsigned long long)err_pos.block, (unsigned long long)last_index_pos); + ltfsmsg(LTFS_INFO, + 13027I, + (int)err_pos.partition, + (unsigned long long)err_pos.block, + (unsigned long long)last_index_pos); err_pos.block = last_index_pos + 1; } @@ -2307,33 +2306,30 @@ int unified_set_profiler(char *work_dir, bool enable, void *iosched_handle) { int rc = 0; char *path; - FILE * p = NULL; + FILE *p = NULL; struct timer_info timerinfo; struct unified_data *priv = iosched_handle; if (enable) { - if (priv->profiler) - return 0; + if (priv->profiler) return 0; - if(!work_dir) - return -LTFS_BAD_ARG; + if (!work_dir) return -LTFS_BAD_ARG; - rc = asprintf(&path, "%s/%s%s%s", work_dir, IOSCHED_PROFILER_BASE, - priv->vol->label->vol_uuid, PROFILER_EXTENSION); + rc = asprintf(&path, "%s/%s%s%s", work_dir, IOSCHED_PROFILER_BASE, priv->vol->label->vol_uuid, PROFILER_EXTENSION); if (rc < 0) { ltfsmsg(LTFS_ERR, 10001E, __FILE__); return -LTFS_NO_MEMORY; } - arch_fopen(path, PROFILER_FILE_MODE,p); + arch_fopen(path, PROFILER_FILE_MODE, p); free(path); - if (! p) + if (!p) rc = -LTFS_FILE_ERR; else { get_timer_info(&timerinfo); - fwrite((void*)&timerinfo, sizeof(timerinfo), 1, p); + fwrite((void *)&timerinfo, sizeof(timerinfo), 1, p); priv->profiler = p; rc = 0; } @@ -2348,14 +2344,14 @@ int unified_set_profiler(char *work_dir, bool enable, void *iosched_handle) } struct iosched_ops unified_ops = { - .init = unified_init, - .destroy = unified_destroy, - .open = unified_open, - .close = unified_close, - .read = unified_read, - .write = unified_write, - .flush = unified_flush, - .truncate = unified_truncate, + .init = unified_init, + .destroy = unified_destroy, + .open = unified_open, + .close = unified_close, + .read = unified_read, + .write = unified_write, + .flush = unified_flush, + .truncate = unified_truncate, .get_filesize = unified_get_filesize, .update_data_placement = unified_update_data_placement, .set_profiler = unified_set_profiler, diff --git a/src/kmi/flatfile.c b/src/kmi/flatfile.c index 8c6d5bdc..62b1e43a 100644 --- a/src/kmi/flatfile.c +++ b/src/kmi/flatfile.c @@ -47,32 +47,31 @@ ************************************************************************************* */ -#include -#include #include "libltfs/kmi_ops.h" #include "libltfs/ltfs_fuse_version.h" +#include +#include #include "key_format_ltfs.h" #include #ifdef mingw_PLATFORM -#include "arch/win/win_util.h" +# include "arch/win/win_util.h" #endif -struct kmi_flatfile_options_data { - unsigned char *dk_list; /**< DK and DKi pairs' list */ +struct kmi_flatfile_options_data +{ + unsigned char *dk_list; /**< DK and DKi pairs' list */ unsigned char *dki_for_format; /**< DKi to get DK for formatting a volume */ }; static struct kmi_flatfile_options_data priv; -#define KMI_FLATFILE_OPT(templ,offset,value) { templ, offsetof(struct kmi_flatfile_options_data, offset), value } +#define KMI_FLATFILE_OPT(templ, offset, value) { templ, offsetof(struct kmi_flatfile_options_data, offset), value } -static struct fuse_opt kmi_flatfile_options[] = { - KMI_FLATFILE_OPT("kmi_dk_list=%s", dk_list, 0), - KMI_FLATFILE_OPT("kmi_dki_for_format=%s", dki_for_format, 0), - FUSE_OPT_END -}; +static struct fuse_opt kmi_flatfile_options[] = { KMI_FLATFILE_OPT("kmi_dk_list=%s", dk_list, 0), + KMI_FLATFILE_OPT("kmi_dki_for_format=%s", dki_for_format, 0), + FUSE_OPT_END }; /** * Convert original dk_list to dk_list on simple plug-in format @@ -80,25 +79,26 @@ static struct fuse_opt kmi_flatfile_options[] = { * @dk_list dk_list on simple plug-in format * @return 0 on success or a negative value on error. */ -static int convert_option(const unsigned char * const path, unsigned char **dk_list) +static int convert_option(const unsigned char *const path, unsigned char **dk_list) { CHECK_ARG_NULL(dk_list, -LTFS_NULL_ARG); - struct { - const char * const name; + struct + { + const char *const name; const unsigned char separetor; } tag[2] = { { "DK=", '/' }, { "DKi=", ':' } }; int ret = 0; int dk_list_length = 1; /* for '\0' at the end of string */ int dk_list_offset = 0; *dk_list = calloc(dk_list_length, sizeof(unsigned char)); - if (! *dk_list) { + if (!*dk_list) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } - FILE *fp = fopen((const char *) path, "r"); - if (! fp) { + FILE *fp = fopen((const char *)path, "r"); + if (!fp) { ret = -errno; ltfsmsg(LTFS_ERR, 15553E, path, ret); return ret; @@ -108,9 +108,8 @@ static int convert_option(const unsigned char * const path, unsigned char **dk_l unsigned int num_of_lines = 0; /* number of lines which has a valid info */ for (num_of_lines = 0; fgets(buf, sizeof(buf), fp); ++num_of_lines) { const int i = num_of_lines % 2; - if (! strncmp(buf, tag[i].name, strlen(tag[i].name)) && strlen(buf) >= strlen(tag[i].name)) { - if (buf[strlen(buf) - 1] == '\n') - buf[strlen(buf) - 1] = '\0'; + if (!strncmp(buf, tag[i].name, strlen(tag[i].name)) && strlen(buf) >= strlen(tag[i].name)) { + if (buf[strlen(buf) - 1] == '\n') buf[strlen(buf) - 1] = '\0'; if (num_of_lines == 0) dk_list_length += strlen(buf) - strlen(tag[i].name); @@ -118,7 +117,7 @@ static int convert_option(const unsigned char * const path, unsigned char **dk_l dk_list_length += SEPARATOR_LENGTH + strlen(buf) - strlen(tag[i].name); void *new_dk_list = realloc(*dk_list, dk_list_length); - if (! new_dk_list) { + if (!new_dk_list) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); fclose(fp); return -LTFS_NO_MEMORY; @@ -159,11 +158,10 @@ static int convert_option(const unsigned char * const path, unsigned char **dk_l */ void *flatfile_init(struct ltfs_volume *vol) { - void* km; + void *km; km = key_format_ltfs_init(vol); - if (km) - ltfsmsg(LTFS_DEBUG, 15550D); + if (km) ltfsmsg(LTFS_DEBUG, 15550D); return km; } @@ -173,7 +171,7 @@ void *flatfile_init(struct ltfs_volume *vol) * @param kmi_handle the key manager interface handle * @return 0 on success or a negative value on error. */ -int flatfile_destroy(void * const kmi_handle) +int flatfile_destroy(void *const kmi_handle) { int ret; @@ -190,7 +188,7 @@ int flatfile_destroy(void * const kmi_handle) * @param kmi_handle the key manager interface handle * @return 0 on success or a negative value on error. */ -int flatfile_get_key(unsigned char **keyalias, unsigned char **key, void * const kmi_handle) +int flatfile_get_key(unsigned char **keyalias, unsigned char **key, void *const kmi_handle) { static unsigned char *dk_list = NULL; /* dk_list on simple plug-in format */ @@ -207,7 +205,7 @@ int flatfile_get_key(unsigned char **keyalias, unsigned char **key, void * const const int ret = key_format_ltfs_get_key(keyalias, key, kmi_handle, dk_list, priv.dki_for_format); -/* + /* * Cache DK and DKi for revalidation at tape drive POR * if (dk_list) { * free(dk_list); @@ -240,7 +238,7 @@ static int null_parser(void *priv, const char *arg, int key, struct fuse_args *o */ int flatfile_parse_opts(void *opt_args) { - struct fuse_args *args = (struct fuse_args *) opt_args; + struct fuse_args *args = (struct fuse_args *)opt_args; int ret; #ifdef mingw_PLATFORM @@ -262,11 +260,11 @@ int flatfile_parse_opts(void *opt_args) } struct kmi_ops flatfile_ops = { - .init = flatfile_init, - .destroy = flatfile_destroy, - .get_key = flatfile_get_key, + .init = flatfile_init, + .destroy = flatfile_destroy, + .get_key = flatfile_get_key, .help_message = flatfile_help_message, - .parse_opts = flatfile_parse_opts, + .parse_opts = flatfile_parse_opts, }; struct kmi_ops *kmi_get_ops(void) @@ -278,7 +276,7 @@ struct kmi_ops *kmi_get_ops(void) extern char kmi_flatfile_dat[]; #endif -const char *kmi_get_message_bundle_name(void ** const message_data) +const char *kmi_get_message_bundle_name(void **const message_data) { #ifndef mingw_PLATFORM *message_data = kmi_flatfile_dat; diff --git a/src/kmi/key_format_ltfs.c b/src/kmi/key_format_ltfs.c index e91b35ab..61b4062e 100644 --- a/src/kmi/key_format_ltfs.c +++ b/src/kmi/key_format_ltfs.c @@ -48,18 +48,19 @@ */ #ifdef mingw_PLATFORM -#include "arch/win/win_util.h" +# include "arch/win/win_util.h" #endif -#include "libltfs/ltfs.h" -#include "libltfs/base64.h" #include "key_format_ltfs.h" +#include "libltfs/base64.h" +#include "libltfs/ltfs.h" #ifndef mingw_PLATFORM -#include -#include +# include +# include #endif -enum kfl_state { +enum kfl_state +{ KFL_UNINITIALIZED, KFL_INITIALIZED, KFL_SET, @@ -69,9 +70,10 @@ enum kfl_state { static enum kfl_state state = KFL_UNINITIALIZED; -struct key_format_ltfs_data { - struct ltfs_volume *vol; /**< A reference to the LTFS volume structure */ - void *data; /**< encryption key list */ +struct key_format_ltfs_data +{ + struct ltfs_volume *vol; /**< A reference to the LTFS volume structure */ + void *data; /**< encryption key list */ }; /** @@ -79,12 +81,12 @@ struct key_format_ltfs_data { * @param key key on LTFS specific format * @return 0 on success or a negative value on error. */ -static int is_key(const unsigned char * const key) +static int is_key(const unsigned char *const key) { int i; for (i = 0; i < (DK_LENGTH * 8 + 5) / 6; ++i) { - if (! isalnum(*(key + i)) && *(key + i) != '+' && *(key + i) != '/') { + if (!isalnum(*(key + i)) && *(key + i) != '+' && *(key + i) != '/') { #ifdef KMI_SIMPLE ltfsmsg(LTFS_ERR, 15502E, __FUNCTION__, "DK"); #else @@ -112,12 +114,12 @@ static int is_key(const unsigned char * const key) * @param keyalias key-alias on LTFS specific format * @return 0 on success or a negative value on error. */ -static int is_keyalias(const unsigned char * const keyalias) +static int is_keyalias(const unsigned char *const keyalias) { int i; for (i = 0; i < DKI_ASCII_LENGTH; ++i) { - if (! isprint(*(keyalias + i))) { + if (!isprint(*(keyalias + i))) { #ifdef KMI_SIMPLE ltfsmsg(LTFS_ERR, 15502E, __FUNCTION__, "DKi ascii"); #else @@ -127,7 +129,7 @@ static int is_keyalias(const unsigned char * const keyalias) } } for (; i < DKI_ASCII_LENGTH + (DKI_LENGTH - DKI_ASCII_LENGTH) * 2; ++i) { - if (! isxdigit(*(keyalias + i))) { + if (!isxdigit(*(keyalias + i))) { #ifdef KMI_SIMPLE ltfsmsg(LTFS_ERR, 15502E, __FUNCTION__, "DKi binary"); #else @@ -145,9 +147,9 @@ static int is_keyalias(const unsigned char * const keyalias) * @param dk_list DK and DKi pairs' list on LTFS specific format. * @return the number of DK and DKi pairs on success or a negative value on error. */ -static int get_num_of_keys(const unsigned char * const dk_list) +static int get_num_of_keys(const unsigned char *const dk_list) { - const size_t length = strlen((const char *) dk_list); + const size_t length = strlen((const char *)dk_list); const size_t key_length = ((DK_LENGTH * 8 + 5) / 6 + 3) / 4 * 4; const size_t keyalias_length = DKI_ASCII_LENGTH + (DKI_LENGTH - DKI_ASCII_LENGTH) * 2; int num_of_keys = 0; @@ -157,8 +159,7 @@ static int get_num_of_keys(const unsigned char * const dk_list) if (key_length + SEPARATOR_LENGTH + keyalias_length <= length) { unsigned int i = 0; do { - if (num_of_keys) - i += SEPARATOR_LENGTH; /* skip DK and DKi pair's separator '/'. */ + if (num_of_keys) i += SEPARATOR_LENGTH; /* skip DK and DKi pair's separator '/'. */ int ret = is_key(dk_list + i); if (ret < 0) { @@ -190,14 +191,13 @@ static int get_num_of_keys(const unsigned char * const dk_list) } i += keyalias_length; ++num_of_keys; - } while (i + SEPARATOR_LENGTH + key_length + SEPARATOR_LENGTH + keyalias_length <= length && - *(dk_list + i) == '/'); + } while (i + SEPARATOR_LENGTH + key_length + SEPARATOR_LENGTH + keyalias_length <= length && *(dk_list + i) == '/'); if (i != length) { #ifdef KMI_SIMPLE - ltfsmsg(LTFS_ERR, 15502E, __FUNCTION__, "Invalid length of kmi_dk_list."); + ltfsmsg(LTFS_ERR, 15502E, __FUNCTION__, "Invalid length of kmi_dk_list."); #else - ltfsmsg(LTFS_ERR, 15562E, __FUNCTION__, "Invalid length of kmi_dk_list."); + ltfsmsg(LTFS_ERR, 15562E, __FUNCTION__, "Invalid length of kmi_dk_list."); #endif return -LTFS_BAD_ARG; } @@ -206,15 +206,13 @@ static int get_num_of_keys(const unsigned char * const dk_list) return num_of_keys; } -static size_t convert_key(const unsigned char * const enc, unsigned char * const key) +static size_t convert_key(const unsigned char *const enc, unsigned char *const key) { unsigned char *dec = NULL; size_t size = base64_decode(enc, ((DK_LENGTH * 8 + 5) / 6 + 3) / 4 * 4, &dec); - if (size == DK_LENGTH) - memcpy(key, dec, DK_LENGTH); - if (size) - free(dec); + if (size == DK_LENGTH) memcpy(key, dec, DK_LENGTH); + if (size) free(dec); return size; } @@ -225,16 +223,16 @@ static size_t convert_key(const unsigned char * const enc, unsigned char * const * @param bin key-alias on binary format * @return 0 on success or a negative value on error. */ -static void convert_keyalias(const unsigned char * const ascii_and_hex, unsigned char * const bin) +static void convert_keyalias(const unsigned char *const ascii_and_hex, unsigned char *const bin) { memcpy(bin, ascii_and_hex, DKI_ASCII_LENGTH); int i = 0; for (i = 0; i < DKI_LENGTH - DKI_ASCII_LENGTH; ++i) { - unsigned char tmp[3] = {0}; + unsigned char tmp[3] = { 0 }; tmp[0] = *(ascii_and_hex + DKI_ASCII_LENGTH + i * 2); tmp[1] = *(ascii_and_hex + DKI_ASCII_LENGTH + i * 2 + 1); - *(bin + DKI_ASCII_LENGTH + i) = strtoul((char *) tmp, NULL, 0x10); + *(bin + DKI_ASCII_LENGTH + i) = strtoul((char *)tmp, NULL, 0x10); } } @@ -254,23 +252,23 @@ void *key_format_ltfs_init(struct ltfs_volume *vol) * and KFL_DESTROYED because the process keep running after a user eject a cartridge. */ if (state != KFL_UNINITIALIZED) { -#ifdef KMI_SIMPLE +# ifdef KMI_SIMPLE ltfsmsg(LTFS_ERR, 15505E, state, KFL_UNINITIALIZED, __FUNCTION__); -#else +# else ltfsmsg(LTFS_ERR, 15565E, state, KFL_UNINITIALIZED, __FUNCTION__); -#endif +# endif return NULL; } #endif struct key_format_ltfs_data *priv = calloc(1, sizeof(struct key_format_ltfs_data)); - if (! priv) { + if (!priv) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return NULL; } priv->vol = vol; priv->data = calloc(1, sizeof(struct key_format_ltfs)); - if (! priv->data) { + if (!priv->data) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return NULL; } @@ -286,9 +284,9 @@ void *key_format_ltfs_init(struct ltfs_volume *vol) * @id message id for destroying key manager interface plug-in * @return 0 on success or a negative value on error. */ -int key_format_ltfs_destroy(void * const kmi_handle) +int key_format_ltfs_destroy(void *const kmi_handle) { - struct key_format_ltfs_data *priv = (struct key_format_ltfs_data *) kmi_handle; + struct key_format_ltfs_data *priv = (struct key_format_ltfs_data *)kmi_handle; CHECK_ARG_NULL(kmi_handle, -LTFS_NULL_ARG); free(priv->data); @@ -304,10 +302,10 @@ int key_format_ltfs_destroy(void * const kmi_handle) * @param data output of DK and DKi list * @return 0 on success or a negative value on error. */ -static int set_dk_list(const unsigned char * const dk_list, void **data) +static int set_dk_list(const unsigned char *const dk_list, void **data) { int num_of_keys = 0; - struct key_format_ltfs **priv = (struct key_format_ltfs **) data; + struct key_format_ltfs **priv = (struct key_format_ltfs **)data; CHECK_ARG_NULL(data, -LTFS_NULL_ARG); CHECK_ARG_NULL(*data, -LTFS_NULL_ARG); @@ -323,13 +321,12 @@ static int set_dk_list(const unsigned char * const dk_list, void **data) if (dk_list) { num_of_keys = get_num_of_keys(dk_list); - if (num_of_keys < 0) - return num_of_keys; + if (num_of_keys < 0) return num_of_keys; } if (num_of_keys) { (*priv)->dk_list = calloc(num_of_keys, sizeof(struct key)); - if (! (*priv)->dk_list) { + if (!(*priv)->dk_list) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } @@ -356,9 +353,9 @@ static int set_dk_list(const unsigned char * const dk_list, void **data) * @param data DK and DKi which are parsed from LTFS specific format * @return 0 on success or a negative value on error. */ -static int get_key(unsigned char **keyalias, unsigned char **key, void *data, unsigned char * const dki_for_format) +static int get_key(unsigned char **keyalias, unsigned char **key, void *data, unsigned char *const dki_for_format) { - struct key_format_ltfs *priv = (struct key_format_ltfs *) data; + struct key_format_ltfs *priv = (struct key_format_ltfs *)data; CHECK_ARG_NULL(keyalias, -LTFS_NULL_ARG); CHECK_ARG_NULL(key, -LTFS_NULL_ARG); @@ -366,11 +363,10 @@ static int get_key(unsigned char **keyalias, unsigned char **key, void *data, un *key = NULL; if (priv) { - if (! *keyalias) { - if (! dki_for_format) - return 0; /* This is not an error path but a normal pass. Make a non-encrypted cartridge. */ + if (!*keyalias) { + if (!dki_for_format) return 0; /* This is not an error path but a normal pass. Make a non-encrypted cartridge. */ *keyalias = calloc(DKI_LENGTH, sizeof(char)); - if (! *keyalias) { + if (!*keyalias) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } @@ -379,9 +375,9 @@ static int get_key(unsigned char **keyalias, unsigned char **key, void *data, un int i; for (i = 0; i < priv->num_of_keys; ++i) { - if (! memcmp(*keyalias, (priv->dk_list + i)->dki, DKI_LENGTH)) { + if (!memcmp(*keyalias, (priv->dk_list + i)->dki, DKI_LENGTH)) { *key = calloc(DK_LENGTH, sizeof(char)); - if (! *key) { + if (!*key) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } @@ -389,7 +385,7 @@ static int get_key(unsigned char **keyalias, unsigned char **key, void *data, un break; } } - if (! *key) { + if (!*key) { #ifdef KMI_SIMPLE ltfsmsg(LTFS_ERR, 15503E); #else @@ -409,7 +405,7 @@ static int get_key(unsigned char **keyalias, unsigned char **key, void *data, un */ static int clear(void **data) { - struct key_format_ltfs **priv = (struct key_format_ltfs **) data; + struct key_format_ltfs **priv = (struct key_format_ltfs **)data; CHECK_ARG_NULL(data, -LTFS_NULL_ARG); @@ -421,8 +417,7 @@ static int clear(void **data) } (*priv)->num_of_keys = 0; /* clear num_of_keys after clearing dk_list */ } - if (state == KFL_SET) - state = KFL_CLEARED; + if (state == KFL_SET) state = KFL_CLEARED; return 0; } @@ -435,18 +430,20 @@ static int clear(void **data) * @param dki_for_format data key identifier to format a cartridge * @return 0 on success or a negative value on error. */ -int key_format_ltfs_get_key(unsigned char **keyalias, unsigned char **key, void * const kmi_handle, - unsigned char * const dk_list, unsigned char * const dki_for_format) +int key_format_ltfs_get_key(unsigned char **keyalias, + unsigned char **key, + void *const kmi_handle, + unsigned char *const dk_list, + unsigned char *const dki_for_format) { - - struct key_format_ltfs_data *priv = (struct key_format_ltfs_data *) kmi_handle; + struct key_format_ltfs_data *priv = (struct key_format_ltfs_data *)kmi_handle; CHECK_ARG_NULL(kmi_handle, -LTFS_NULL_ARG); int ret = set_dk_list(dk_list, &priv->data); if (ret < 0) { #ifdef KMI_SIMPLE - ltfsmsg(LTFS_ERR, 15506E); + ltfsmsg(LTFS_ERR, 15506E); #else - ltfsmsg(LTFS_ERR, 15566E); + ltfsmsg(LTFS_ERR, 15566E); #endif return ret; } @@ -457,7 +454,7 @@ int key_format_ltfs_get_key(unsigned char **keyalias, unsigned char **key, void #else ltfsmsg(LTFS_ERR, 15567E); #endif - (void) clear(&priv->data); + (void)clear(&priv->data); return ret; } diff --git a/src/kmi/key_format_ltfs.h b/src/kmi/key_format_ltfs.h index 82a0c2f4..c1e86f89 100644 --- a/src/kmi/key_format_ltfs.h +++ b/src/kmi/key_format_ltfs.h @@ -49,6 +49,8 @@ #ifndef __key_format_ltfs_h #define __key_format_ltfs_h +#include +#include "libltfs/ltfs.h" #define DK_LENGTH 32 #define DKI_LENGTH 12 diff --git a/src/kmi/simple.c b/src/kmi/simple.c index 41c83cf9..855b47c4 100644 --- a/src/kmi/simple.c +++ b/src/kmi/simple.c @@ -47,35 +47,34 @@ ************************************************************************************* */ +#include "key_format_ltfs.h" #include "libltfs/kmi_ops.h" #include "libltfs/ltfs_fuse_version.h" -#include "key_format_ltfs.h" #include #ifdef mingw_PLATFORM -#include "arch/win/win_util.h" +# include "arch/win/win_util.h" #endif -struct kmi_simple_options_data { - unsigned char *dk; /**< Data key */ - unsigned char *dki; /**< Data key identifier */ - unsigned char *dk_for_format; /**< Data key for formatting a volume */ +struct kmi_simple_options_data +{ + unsigned char *dk; /**< Data key */ + unsigned char *dki; /**< Data key identifier */ + unsigned char *dk_for_format; /**< Data key for formatting a volume */ unsigned char *dki_for_format; /**< Data key identifier for formatting a volume */ - unsigned char *dk_list; /**< DK and DKi pairs' list */ + unsigned char *dk_list; /**< DK and DKi pairs' list */ }; static struct kmi_simple_options_data priv; -#define KMI_SIMPLE_OPT(templ,offset,value) { templ, offsetof(struct kmi_simple_options_data, offset), value } +#define KMI_SIMPLE_OPT(templ, offset, value) { templ, offsetof(struct kmi_simple_options_data, offset), value } -static struct fuse_opt kmi_simple_options[] = { - KMI_SIMPLE_OPT("kmi_dk=%s", dk, 0), - KMI_SIMPLE_OPT("kmi_dki=%s", dki, 0), - KMI_SIMPLE_OPT("kmi_dk_for_format=%s", dk_for_format, 0), - KMI_SIMPLE_OPT("kmi_dki_for_format=%s", dki_for_format, 0), - KMI_SIMPLE_OPT("kmi_dk_list=%s", dk_list, 0), - FUSE_OPT_END -}; +static struct fuse_opt kmi_simple_options[] = { KMI_SIMPLE_OPT("kmi_dk=%s", dk, 0), + KMI_SIMPLE_OPT("kmi_dki=%s", dki, 0), + KMI_SIMPLE_OPT("kmi_dk_for_format=%s", dk_for_format, 0), + KMI_SIMPLE_OPT("kmi_dki_for_format=%s", dki_for_format, 0), + KMI_SIMPLE_OPT("kmi_dk_list=%s", dk_list, 0), + FUSE_OPT_END }; /** * Initialize the simple key manager interface plugin. @@ -84,11 +83,10 @@ static struct fuse_opt kmi_simple_options[] = { */ void *simple_init(struct ltfs_volume *vol) { - void* km; + void *km; km = key_format_ltfs_init(vol); - if (km) - ltfsmsg(LTFS_DEBUG, 15500D); + if (km) ltfsmsg(LTFS_DEBUG, 15500D); return km; } @@ -98,7 +96,7 @@ void *simple_init(struct ltfs_volume *vol) * @param kmi_handle the key manager interface handle * @return 0 on success or a negative value on error. */ -int simple_destroy(void * const kmi_handle) +int simple_destroy(void *const kmi_handle) { int ret; @@ -115,7 +113,7 @@ int simple_destroy(void * const kmi_handle) * @param kmi_handle the key manager interface handle * @return 0 on success or a negative value on error. */ -int simple_get_key(unsigned char **keyalias, unsigned char **key, void * const kmi_handle) +int simple_get_key(unsigned char **keyalias, unsigned char **key, void *const kmi_handle) { return key_format_ltfs_get_key(keyalias, key, kmi_handle, priv.dk_list, priv.dki_for_format); } @@ -143,7 +141,7 @@ static int null_parser(void *priv, const char *arg, int key, struct fuse_args *o */ int simple_parse_opts(void *opt_args) { - struct fuse_args *args = (struct fuse_args *) opt_args; + struct fuse_args *args = (struct fuse_args *)opt_args; int ret; #ifdef mingw_PLATFORM @@ -173,51 +171,51 @@ int simple_parse_opts(void *opt_args) } if (priv.dk != NULL && priv.dki != NULL && priv.dk_for_format != NULL && priv.dki_for_format != NULL) { - if ((strcmp((char *) priv.dk, (char *) priv.dk_for_format) == 0) ^ (strcmp((char *) priv.dki, (char *) priv.dki_for_format) == 0)) { + if ((strcmp((char *)priv.dk, (char *)priv.dk_for_format) == 0) ^ + (strcmp((char *)priv.dki, (char *)priv.dki_for_format) == 0)) { ltfsmsg(LTFS_ERR, 15504E, 1); return -1; } } - struct { + struct + { unsigned char *dk; unsigned char *dki; } key[] = { { priv.dk, priv.dki }, { priv.dk_for_format, priv.dki_for_format } }; for (unsigned int i = 0; i < sizeof(key) / sizeof(key[0]); ++i) { - if (key[i].dk == NULL) - continue; + if (key[i].dk == NULL) continue; - const size_t original_dk_list_len = (priv.dk_list ? strlen((char *) priv.dk_list) : 0); - const size_t dk_list_len = (priv.dk_list ? strlen((char *) priv.dk_list) + strlen("/") : 0) - + strlen((char *) key[i].dk) + strlen(":") + strlen((char *) key[i].dki) + 1; + const size_t original_dk_list_len = (priv.dk_list ? strlen((char *)priv.dk_list) : 0); + const size_t dk_list_len = (priv.dk_list ? strlen((char *)priv.dk_list) + strlen("/") : 0) + + strlen((char *)key[i].dk) + strlen(":") + strlen((char *)key[i].dki) + 1; if (priv.dk_list) - priv.dk_list = (unsigned char*)realloc(priv.dk_list, dk_list_len); + priv.dk_list = (unsigned char *)realloc(priv.dk_list, dk_list_len); else - priv.dk_list = (unsigned char*)calloc(dk_list_len, sizeof(unsigned char)); + priv.dk_list = (unsigned char *)calloc(dk_list_len, sizeof(unsigned char)); if (priv.dk_list == NULL) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } *(priv.dk_list + original_dk_list_len) = '\0'; - if (original_dk_list_len) - arch_strcat((char *) priv.dk_list, dk_list_len, "/"); - arch_strcat((char *) priv.dk_list, dk_list_len,(char *) key[i].dk); - arch_strcat((char *) priv.dk_list, dk_list_len, ":"); - arch_strcat((char *) priv.dk_list, dk_list_len,(char *) key[i].dki); + if (original_dk_list_len) arch_strcat((char *)priv.dk_list, dk_list_len, "/"); + arch_strcat((char *)priv.dk_list, dk_list_len, (char *)key[i].dk); + arch_strcat((char *)priv.dk_list, dk_list_len, ":"); + arch_strcat((char *)priv.dk_list, dk_list_len, (char *)key[i].dki); } return 0; } struct kmi_ops simple_ops = { - .init = simple_init, - .destroy = simple_destroy, - .get_key = simple_get_key, + .init = simple_init, + .destroy = simple_destroy, + .get_key = simple_get_key, .help_message = simple_help_message, - .parse_opts = simple_parse_opts, + .parse_opts = simple_parse_opts, }; struct kmi_ops *kmi_get_ops(void) @@ -229,7 +227,7 @@ struct kmi_ops *kmi_get_ops(void) extern char kmi_simple_dat[]; #endif -const char *kmi_get_message_bundle_name(void ** const message_data) +const char *kmi_get_message_bundle_name(void **const message_data) { #ifndef mingw_PLATFORM *message_data = kmi_simple_dat; diff --git a/src/libltfs/arch/arch_info.c b/src/libltfs/arch/arch_info.c index dec5f225..bb746133 100644 --- a/src/libltfs/arch/arch_info.c +++ b/src/libltfs/arch/arch_info.c @@ -49,12 +49,12 @@ #include "libltfs/ltfs.h" #ifdef HAVE_SYS_SYSCTL_H -#include +# include #endif -#include +#include #include +#include #include -#include void show_runtime_system_info(void) #if defined(__linux__) @@ -68,31 +68,29 @@ void show_runtime_system_info(void) char *path, *tmp; fd = open("/proc/version", O_RDONLY); - if( fd == -1) { + if (fd == -1) { ltfsmsg(LTFS_WARN, 17086W); } else { memset(kernel_version, 0, sizeof(kernel_version)); read(fd, kernel_version, sizeof(kernel_version)); - if((tmp = strchr(kernel_version, '\n')) != NULL) - *tmp = '\0'; + if ((tmp = strchr(kernel_version, '\n')) != NULL) *tmp = '\0'; - if(stat("/proc/sys/kernel/vsyscall64", &stat_vm64) != -1 && S_ISREG(stat_vm64.st_mode)) { -#if defined(__i386__) || defined(__x86_64__) + if (stat("/proc/sys/kernel/vsyscall64", &stat_vm64) != -1 && S_ISREG(stat_vm64.st_mode)) { +# if defined(__i386__) || defined(__x86_64__) strcat(kernel_version, " x86_64"); -#elif defined(__ppc__) || defined(__ppc64__) +# elif defined(__ppc__) || defined(__ppc64__) strcat(kernel_version, " ppc64"); -#else +# else strcat(kernel_version, " unknown"); -#endif - } - else { -#if defined(__i386__) || defined(__x86_64__) +# endif + } else { +# if defined(__i386__) || defined(__x86_64__) strcat(kernel_version, " i386"); -#elif defined(__ppc__) || defined(__ppc64__) +# elif defined(__ppc__) || defined(__ppc64__) strcat(kernel_version, " ppc"); -#else +# else strcat(kernel_version, " unknown"); -#endif +# endif } ltfsmsg(LTFS_INFO, 17087I, kernel_version); close(fd); @@ -100,9 +98,9 @@ void show_runtime_system_info(void) dir = opendir("/etc"); if (dir) { - while( (dent = readdir(dir)) != NULL) { - if(strlen(dent->d_name) > strlen("-release") && - !strcmp(&(dent->d_name[strlen(dent->d_name) - strlen("-release")]), "-release")) { + while ((dent = readdir(dir)) != NULL) { + if (strlen(dent->d_name) > strlen("-release") && + !strcmp(&(dent->d_name[strlen(dent->d_name) - strlen("-release")]), "-release")) { path = calloc(1, strlen(dent->d_name) + strlen("/etc/") + 1); if (!path) { /* Memory allocation failed */ @@ -113,14 +111,13 @@ void show_runtime_system_info(void) strcat(path, "/etc/"); strcat(path, dent->d_name); fd = open(path, O_RDONLY); - if( fd == -1) { + if (fd == -1) { ltfsmsg(LTFS_WARN, 17088W); } else { if (fstat(fd, &stat_rel) != -1 && S_ISREG(stat_rel.st_mode)) { memset(destribution, 0, sizeof(destribution)); read(fd, destribution, sizeof(destribution)); - if((tmp = strchr(destribution, '\n')) != NULL) - *tmp = '\0'; + if ((tmp = strchr(destribution, '\n')) != NULL) *tmp = '\0'; ltfsmsg(LTFS_INFO, 17089I, destribution); } diff --git a/src/libltfs/arch/errormap.c b/src/libltfs/arch/errormap.c index 8fa6adf5..fae0acd4 100644 --- a/src/libltfs/arch/errormap.c +++ b/src/libltfs/arch/errormap.c @@ -48,27 +48,28 @@ */ #ifdef mingw_PLATFORM -#include "arch/win/win_util.h" +# include "arch/win/win_util.h" #endif #ifdef __FreeBSD__ -#include "libltfs/arch/freebsd/errno.h" +# include "libltfs/arch/freebsd/errno.h" #endif -#include #include +#include -#include "libltfs/ltfslogging.h" +#include "libltfs/arch/errormap.h" #include "libltfs/ltfs_error.h" +#include "libltfs/ltfslogging.h" #include "libltfs/uthash.h" -#include "libltfs/arch/errormap.h" /* Use the Bernstein hash function, which has the best lookup performance for this * data set on amd64. */ #undef HASH_FCN #define HASH_FCN HASH_BER -struct error_map { +struct error_map +{ int ltfs_error; char *msd_id; int general_error; @@ -82,399 +83,397 @@ static struct error_map *fuse_errormap = NULL; * This should be kept in sync with libltfs/ltfs_error.h. * TODO: define the corresponding error mapping for Windows. */ -static struct error_map fuse_error_list[] = { - { LTFS_NULL_ARG, "I1000E", EINVAL}, - { LTFS_NO_MEMORY, "I1001E", ENOMEM}, - { LTFS_MUTEX_INVALID, "I1002E", EINVAL}, - { LTFS_MUTEX_UNLOCKED, "I1003E", EINVAL}, - { LTFS_BAD_DEVICE_DATA, "I1004E", EINVAL}, - { LTFS_BAD_PARTNUM, "I1005E", EINVAL}, - { LTFS_LIBXML2_FAILURE, "I1006E", EINVAL}, - { LTFS_DEVICE_UNREADY, "I1007E", EAGAIN}, +static struct error_map fuse_error_list[] = { { LTFS_NULL_ARG, "I1000E", EINVAL }, + { LTFS_NO_MEMORY, "I1001E", ENOMEM }, + { LTFS_MUTEX_INVALID, "I1002E", EINVAL }, + { LTFS_MUTEX_UNLOCKED, "I1003E", EINVAL }, + { LTFS_BAD_DEVICE_DATA, "I1004E", EINVAL }, + { LTFS_BAD_PARTNUM, "I1005E", EINVAL }, + { LTFS_LIBXML2_FAILURE, "I1006E", EINVAL }, + { LTFS_DEVICE_UNREADY, "I1007E", EAGAIN }, #ifdef ENOMEDIUM - { LTFS_NO_MEDIUM, "I1008E", ENOMEDIUM}, + { LTFS_NO_MEDIUM, "I1008E", ENOMEDIUM }, #else - { LTFS_NO_MEDIUM, "I1008E", EAGAIN}, + { LTFS_NO_MEDIUM, "I1008E", EAGAIN }, #endif /* ENOMEDIUM */ - { LTFS_LARGE_BLOCKSIZE, "I1009E", EINVAL}, - { LTFS_BAD_LOCATE, "I1010E", EIO}, - { LTFS_NOT_PARTITIONED, "I1011E", EINVAL}, - { LTFS_LABEL_INVALID, "I1012E", EINVAL}, - { LTFS_LABEL_MISMATCH, "I1013E", EINVAL}, - { LTFS_INDEX_INVALID, "I1014E", EINVAL}, - { LTFS_INCONSISTENT, "I1015E", EINVAL}, - { LTFS_UNSUPPORTED_MEDIUM, "I1016E", EINVAL}, - { LTFS_GENERATION_MISMATCH, "I1017E", EINVAL}, - { LTFS_MAM_CACHE_INVALID, "I1018E", EINVAL}, - { LTFS_INDEX_CACHE_INVALID, "I1019E", EINVAL}, - { LTFS_POLICY_EMPTY_RULE, "I1020E", EINVAL}, - { LTFS_MUTEX_INIT, "I1021E", EINVAL}, - { LTFS_BAD_ARG, "I1022E", EINVAL}, - { LTFS_NAMETOOLONG, "I1023E", ENAMETOOLONG}, - { LTFS_NO_DENTRY, "I1024E", ENOENT}, - { LTFS_INVALID_PATH, "I1025E", EINVAL}, - { LTFS_INVALID_SRC_PATH, "I1026E", ENOENT}, - { LTFS_DENTRY_EXISTS, "I1027E", EEXIST}, - { LTFS_DIRNOTEMPTY, "I1028E", ENOTEMPTY}, - { LTFS_UNLINKROOT, "I1029E", EBUSY}, - { LTFS_DIRMOVE, "I1030E", EIO}, - { LTFS_RENAMELOOP, "I1031E", EINVAL}, - { LTFS_SMALL_BLOCK, "I1032E", EIO}, - { LTFS_ISDIRECTORY, "I1033E", EINVAL}, - { LTFS_EOD_MISSING_MEDIUM, "I1034E", EINVAL}, - { LTFS_BOTH_EOD_MISSING, "I1035E", EIO}, - { LTFS_UNEXPECTED_VALUE, "I1036E", EIO}, - { LTFS_UNSUPPORTED, "I1037E", EIO}, - { LTFS_LABEL_POSSIBLE_VALID, "I1038E", EIO}, - { LTFS_CLOSE_FS_IF, "I1039E", EIDRM}, + { LTFS_LARGE_BLOCKSIZE, "I1009E", EINVAL }, + { LTFS_BAD_LOCATE, "I1010E", EIO }, + { LTFS_NOT_PARTITIONED, "I1011E", EINVAL }, + { LTFS_LABEL_INVALID, "I1012E", EINVAL }, + { LTFS_LABEL_MISMATCH, "I1013E", EINVAL }, + { LTFS_INDEX_INVALID, "I1014E", EINVAL }, + { LTFS_INCONSISTENT, "I1015E", EINVAL }, + { LTFS_UNSUPPORTED_MEDIUM, "I1016E", EINVAL }, + { LTFS_GENERATION_MISMATCH, "I1017E", EINVAL }, + { LTFS_MAM_CACHE_INVALID, "I1018E", EINVAL }, + { LTFS_INDEX_CACHE_INVALID, "I1019E", EINVAL }, + { LTFS_POLICY_EMPTY_RULE, "I1020E", EINVAL }, + { LTFS_MUTEX_INIT, "I1021E", EINVAL }, + { LTFS_BAD_ARG, "I1022E", EINVAL }, + { LTFS_NAMETOOLONG, "I1023E", ENAMETOOLONG }, + { LTFS_NO_DENTRY, "I1024E", ENOENT }, + { LTFS_INVALID_PATH, "I1025E", EINVAL }, + { LTFS_INVALID_SRC_PATH, "I1026E", ENOENT }, + { LTFS_DENTRY_EXISTS, "I1027E", EEXIST }, + { LTFS_DIRNOTEMPTY, "I1028E", ENOTEMPTY }, + { LTFS_UNLINKROOT, "I1029E", EBUSY }, + { LTFS_DIRMOVE, "I1030E", EIO }, + { LTFS_RENAMELOOP, "I1031E", EINVAL }, + { LTFS_SMALL_BLOCK, "I1032E", EIO }, + { LTFS_ISDIRECTORY, "I1033E", EINVAL }, + { LTFS_EOD_MISSING_MEDIUM, "I1034E", EINVAL }, + { LTFS_BOTH_EOD_MISSING, "I1035E", EIO }, + { LTFS_UNEXPECTED_VALUE, "I1036E", EIO }, + { LTFS_UNSUPPORTED, "I1037E", EIO }, + { LTFS_LABEL_POSSIBLE_VALID, "I1038E", EIO }, + { LTFS_CLOSE_FS_IF, "I1039E", EIDRM }, #ifdef ENOATTR - { LTFS_NO_XATTR, "I1040E", ENOATTR}, + { LTFS_NO_XATTR, "I1040E", ENOATTR }, #else - { LTFS_NO_XATTR, "I1040E", ENODATA}, + { LTFS_NO_XATTR, "I1040E", ENODATA }, #endif /* ENOATTR */ - { LTFS_SIG_HANDLER_ERR, "I1041E", EINVAL}, - { LTFS_INTERRUPTED, "I1042E", ECANCELED}, - { LTFS_UNSUPPORTED_INDEX_VERSION,"I1043E", EINVAL}, - { LTFS_ICU_ERROR, "I1044E", EINVAL}, - { LTFS_PLUGIN_LOAD, "I1045E", EINVAL}, - { LTFS_PLUGIN_UNLOAD, "I1046E", EINVAL}, - { LTFS_RDONLY_XATTR, "I1047E", EACCES}, - { LTFS_XATTR_EXISTS, "I1048E", EEXIST}, - { LTFS_SMALL_BUFFER, "I1049E", ERANGE}, - { LTFS_RDONLY_VOLUME, "I1050E", EROFS}, - { LTFS_NO_SPACE, "I1051E", ENOSPC}, - { LTFS_LARGE_XATTR, "I1052E", ENOSPC}, - { LTFS_NO_INDEX, "I1053E", ENODATA}, - { LTFS_XATTR_NAMESPACE, "I1054E", EOPNOTSUPP}, - { LTFS_CONFIG_INVALID, "I1055E", EINVAL}, - { LTFS_PLUGIN_INCOMPLETE, "I1056E", EINVAL}, - { LTFS_NO_PLUGIN, "I1057E", ENOENT}, - { LTFS_POLICY_INVALID, "I1058E", EINVAL}, - { LTFS_ISFILE, "I1059E", ENOTDIR}, - { LTFS_UNRESOLVED_VOLUME, "I1060E", EBUSY}, - { LTFS_POLICY_IMMUTABLE, "I1061E", EPERM}, - { LTFS_SMALL_BLOCKSIZE, "I1062E", EINVAL}, - { LTFS_BARCODE_LENGTH, "I1063E", EINVAL}, - { LTFS_BARCODE_INVALID, "I1064E", EINVAL}, - { LTFS_RESOURCE_SHORTAGE, "I1065E", EBUSY}, - { LTFS_DEVICE_FENCED, "I1066E", EAGAIN}, - { LTFS_REVAL_RUNNING, "I1067E", EAGAIN}, - { LTFS_REVAL_FAILED, "I1068E", EFAULT}, - { LTFS_SLOT_FULL, "I1069E", EFAULT}, - { LTFS_SLOT_SHORTAGE, "I1070E", EFAULT}, - { LTFS_CHANGER_ERROR, "I1071E", EIO}, - { LTFS_UNEXPECTED_TAPE, "I1072E", EINVAL}, - { LTFS_NO_HOMESLOT, "I1073E", EINVAL}, - { LTFS_MOVE_ACTIVE_CART, "I1074E", ECANCELED}, - { LTFS_NO_IE_SLOT, "I1075E", ECANCELED}, - { LTFS_INVALID_SLOT, "I1076E", EINVAL}, - { LTFS_UNSUPPORTED_CART, "I1077E", EINVAL}, - { LTFS_CART_STUCKED, "I1078E", EIO}, - { LTFS_OP_NOT_ALLOWED, "I1079E", EINVAL}, - { LTFS_OP_TO_DUP, "I1080E", EINVAL}, - { LTFS_OP_TO_NON_SUP, "I1081E", EINVAL}, - { LTFS_OP_TO_INACC, "I1082E", EINVAL}, - { LTFS_OP_TO_UNFMT, "I1083E", EINVAL}, - { LTFS_OP_TO_INV, "I1084E", EINVAL}, - { LTFS_OP_TO_ERR, "I1085E", EINVAL}, - { LTFS_OP_TO_CRIT, "I1086E", EINVAL}, - { LTFS_OP_TO_CLN, "I1087E", EINVAL}, - { LTFS_OP_TO_RO, "I1088E", EINVAL}, - { LTFS_ALREADY_FS_INC, "I1089E", EINVAL}, - { LTFS_NOT_IN_FS, "I1090E", EINVAL}, - { LTFS_FS_CART_TO_IE, "I1091E", EINVAL}, - { LTFS_OP_TO_UNKN, "I1092E", EINVAL}, - { LTFS_DRV_LOCKED, "I1093E", EINVAL}, - { LTFS_DRV_ALRDY_ADDED, "I1094E", EINVAL}, - { LTFS_FORCE_INVENTORY, "I1095E", EIO}, - { LTFS_INVENTORY_FAILED, "I1096E", EFAULT}, - { LTFS_RESTART_OPERATION, "I1097E", EIO}, - { LTFS_NO_TARGET_DRIVE, "I1098E", EINVAL}, - { LTFS_NO_DCACHE_FSTYPE, "I1099E", EINVAL}, - { LTFS_IMAGE_EXISTED, "I1100E", EINVAL}, - { LTFS_IMAGE_MOUNTED, "I1101E", EIO}, - { LTFS_IMAGE_NOT_MOUNTED, "I1102E", EIO}, - { LTFS_MTAB_NOREGULAR, "I1103E", EIO}, - { LTFS_MTAB_OPEN, "I1104E", EIO}, - { LTFS_MTAB_LOCK, "I1105E", EIO}, - { LTFS_MTAB_SEEK, "I1106E", EIO}, - { LTFS_MTAB_UPDATE, "I1107E", EIO}, - { LTFS_MTAB_FLUSH, "I1108E", EIO}, - { LTFS_MTAB_UNLOCK, "I1109E", EIO}, - { LTFS_MTAB_CLOSE, "I1110E", EIO}, - { LTFS_MTAB_COPY, "I1111E", EIO}, - { LTFS_MTAB_TEMP_OPEN, "I1112E", EIO}, - { LTFS_MTAB_TEMP_SEEK, "I1113E", EIO}, - { LTFS_DCACHE_CREATION_FAIL, "I1114E", EIO}, - { LTFS_DCACHE_UNSUPPORTED, "I1115E", EINVAL}, - { LTFS_DCACHE_EXTRA_SPACE, "I1116E", EINVAL}, - { LTFS_KEY_NOT_FOUND, "I1117E", EINVAL}, - { LTFS_INVALID_SEQUENCE, "I1118E", EINVAL}, - { LTFS_RDONLY_ROOT, "I1119E", EACCES}, - { LTFS_SYMLINK_CONFLICT, "I1120E", EIO}, - { LTFS_NETWORK_INIT_FAIL, "I1121E", EINVAL}, - { LTFS_DRIVE_SHORTAGE, "I1122E", ENODEV}, - { LTFS_INVALID_VOLSER, "I1123E", EINVAL}, - { LTFS_LESS_SPACE, "I1124E", ENOSPC}, - { LTFS_WRITE_PROTECT, "I1125E", EROFS}, - { LTFS_WRITE_ERROR, "I1126E", EROFS}, - { LTFS_UNEXPECTED_BARCODE, "I1127E", EIO}, - { LTFS_STRING_CONVERSION, "I1128E", EINVAL}, - { LTFS_SESSION_INIT_FAIL, "I1129E", EIO}, - { LTFS_MESSAGE_INVALID, "I1130E", EINVAL}, - { LTFS_PASSWORD_INVALID, "I1131E", EPERM}, - { LTFS_NOT_AUTHENTICATERD, "I1132E", EINVAL}, - { LTFS_WORM_DEEP_RECOVERY, "I1133E", EINVAL}, - { LTFS_WORM_ROLLBACK, "I1134E", EINVAL}, - { LTFS_NONWORM_SALVAGE, "I1135E", EINVAL}, - { LTFS_FORMATTED, "I1136E", EPERM}, - { LTFS_RULES_WORM, "I1137E", EINVAL}, - { LTFS_BAD_BLOCKSIZE, "I1138E", EINVAL}, - { LTFS_BAD_VOLNAME, "I1139E", EINVAL}, - { LTFS_BAD_RULES, "I1140E", EINVAL}, - { LTFS_GEN_NEEDED, "I1141E", EINVAL}, - { LTFS_BAD_GENERATION, "I1142E", EINVAL}, - { LTFS_NO_ROLLBACK_TARGET, "I1143E", EINVAL}, - { LTFS_MANY_INDEXES, "I1144E", EINVAL}, - { LTFS_SALVAGE_NOT_NEEDED, "I1145E", EINVAL}, - { LTFS_WORM_ENABLED, "I1146E", EACCES}, - { LTFS_OUTSTANDING_REFS, "I1147E", EBUSY}, - { LTFS_REBUILD_IN_PROGRESS, "I1148E", EBUSY}, - { LTFS_MULTIPLE_START, "I1149E", EINVAL}, - { LTFS_CARTRIDGE_NOT_FOUND, "I1150E", EINVAL}, - { LTFS_CACHE_LOCK_ERR, "I1151E", EIO}, - { LTFS_CACHE_UNLOCK_ERR, "I1152E", EIO}, - { LTFS_CREPO_FILE_ERR, "I1153E", EIO}, - { LTFS_CREPO_READ_ERR, "I1154E", EIO}, - { LTFS_CREPO_WRITE_ERR, "I1155E", EIO}, - { LTFS_CREPO_INVALID_OP, "I1156E", EINVAL}, - { LTFS_FILE_ERR, "I1157E", EIO}, - { LTFS_CARTRIDGE_IN_USE, "I1158E", EBUSY}, - { LTFS_NO_LOCK_ENTRY, "I1159E", ENOENT}, - { LTFS_MOUNT_ERR, "I1160E", EIO}, - { LTFS_NO_DEVICE, "I1161E", ENODEV}, - { LTFS_XATTR_ERR, "I1162E", EIO}, - { LTFS_FTW_ERR, "I1163E", EIO}, - { LTFS_TIME_ERR, "I1164E", EIO}, - { LTFS_NOT_BLOCK_DEVICE, "I1165E", ENOTBLK}, - { LTFS_QUOTA_EXCEEDED, "I1166E", EDQUOT}, - { LTFS_TOO_MANY_OPEN_FILES, "I1167E", ENFILE}, - { LTFS_LINKDIR_EXISTS, "I1168E", EEXIST}, - { LTFS_NO_DMAP_ENTRY, "I1169E", ENOENT}, - { LTFS_RECOVERABLE_FILE_ERR, "I1170E", EAGAIN}, - { LTFS_NO_DCACHE_SPC, "I1171E", ENOSPC}, - { LTFS_POS_SUSPECT_BOP, "I1172E", EIO}, - /* Unused 1175 - 1179 */ - { LTFS_CACHE_IO, "I1180E", EIO }, - { LTFS_CACHE_DISCARDED, "I1181E", ENOENT }, - { LTFS_LONG_WRITE_LOCK, "I1182E", EAGAIN }, - { LTFS_INCOMPATIBLE_CACHE, "I1183E", EINVAL }, - { LTFS_DCACHE_NOT_INITIALIZED, "I1184E", EIO }, - { LTFS_CONFIG_FILE_WLOCKED, "I1185E", EINVAL }, - { LTFS_CREATE_QUEUE, "I1186E", EIO }, - { LTFS_FORK_ERROR, "I1187E", EIO }, - { LTFS_NOACK, "I1188E", EIO }, - { LTFS_NODE_DETECT_FAIL, "I1189E", EIO }, - { LTFS_INVALID_MESSAGE, "I1190E", EIO }, - { LTFS_NODE_DEGATE_FAIL, "I1191E", EIO }, - { LTFS_CLUSTER_MRSW_FAIL, "I1192E", EIO }, - { LTFS_CART_NOT_MOUNTED, "I1193E", EBUSY}, - { LTFS_RDONLY_DEN_DRV, "I1194E", EINVAL}, - { LTFS_NEED_DRIVE_SELECTION, "I1195E", EINVAL}, - { LTFS_MUTEX_ALREADY_LOCKED, "I1196E", EINVAL}, - { LTFS_TAPE_UNDER_PROCESS, "I1197E", EBUSY}, - { LTFS_TAPE_REMOVED, "I1198E", EIDRM}, - { LTFS_NEED_MOVE, "I1199E", EINVAL}, - { LTFS_NEED_START_OVER, "I1200E", EINVAL}, - { LTFS_LOCATE_ERROR, "I1201E", EIO}, - { LTFS_STATS_DB_OPEN, "I1202E", EIO}, - { LTFS_NO_TRAIL_FM, "I1203E", EINVAL}, - { LTFS_SAFENAME_FAIL, "I1204E", EINVAL}, - { LTFS_SYNC_FAIL_ON_DP, "I1205E", EIO}, - { LTFS_XML_READ_FAIL, "I5000E", EINVAL}, - { LTFS_XML_CONST_FAIL, "I5001E", EINVAL}, - { LTFS_XML_WRONG_NODE, "I5002E", EINVAL}, - { LTFS_XML_UNEXPECTED_EOF, "I5003E", EINVAL}, - { LTFS_XML_EMPTY_UNKNOWN, "I5004E", EINVAL}, - { LTFS_XML_EMPTY, "I5005E", EINVAL}, - { LTFS_XML_SKIP_FAIL, "I5006E", EINVAL}, - { LTFS_XML_NO_REQUIRED_TAG, "I5007E", EINVAL}, - { LTFS_XML_DUPLICATED_TAG, "I5008E", EINVAL}, - { LTFS_XML_OPEN_TAG, "I5009E", EINVAL}, - { LTFS_XML_SAVE_FAIL, "I5010E", EINVAL}, - { LTFS_XML_WRONG_TOPTAG, "I5011E", EINVAL}, - { LTFS_XML_WRONG_ENCODING, "I5012E", EINVAL}, - { LTFS_XML_TOP_ATTR_FAIL, "I5013E", EINVAL}, - { LTFS_XML_WRONG_UUID, "I5014E", EINVAL}, - { LTFS_XML_WRONG_GEN, "I5015E", EINVAL}, - { LTFS_XML_WRONG_UTIME, "I5016E", EINVAL}, - { LTFS_XML_WRONG_LOC, "I5017E", EINVAL}, - { LTFS_XML_WRONG_LOC_PREV, "I5018E", EINVAL}, - { LTFS_XML_WRONG_PA, "I5019E", EINVAL}, - { LTFS_XML_WRONG_POLICY, "I5020E", EINVAL}, - { LTFS_XML_TOO_LONG_COMMENT, "I5021E", EINVAL}, - { LTFS_XML_WRONG_NEXT, "I5022E", EINVAL}, - { LTFS_XML_WRONG_RO_DIR, "I5023E", EINVAL}, - { LTFS_XML_WRONG_MTIME_DIR, "I5024E", EINVAL}, - { LTFS_XML_WRONG_CRTIME_DIR, "I5025E", EINVAL}, - { LTFS_XML_WRONG_ATIME_DIR, "I5026E", EINVAL}, - { LTFS_XML_WRONG_CTIME_DIR, "I5027E", EINVAL}, - { LTFS_XML_WRONG_BTIME_DIR, "I5028E", EINVAL}, - { LTFS_XML_XATTR_TYPE, "I5029E", EINVAL}, - { LTFS_XML_XATTR_SIZE, "I5030E", EINVAL}, - { LTFS_XML_WRONG_UID, "I5031E", EINVAL}, - { LTFS_XML_INVALID_UID, "I5032E", EINVAL}, - { LTFS_XML_WRONG_RO_F, "I5033E", EINVAL}, - { LTFS_XML_WRONG_MTIME_F, "I5034E", EINVAL}, - { LTFS_XML_WRONG_CRTIME_F, "I5035E", EINVAL}, - { LTFS_XML_WRONG_ATIME_F, "I5036E", EINVAL}, - { LTFS_XML_WRONG_CTIME_F, "I5037E", EINVAL}, - { LTFS_XML_WRONG_BTIME_F, "I5038E", EINVAL}, - { LTFS_XML_WRONG_SIZE, "I5039E", EINVAL}, - { LTFS_XML_WRONG_PART, "I5040E", EINVAL}, - { LTFS_XML_WRONG_START_BLK, "I5041E", EINVAL}, - { LTFS_XML_WRONG_OFFSET, "I5042E", EINVAL}, - { LTFS_XML_WRONG_BYTE_CNT, "I5043E", EINVAL}, - { LTFS_XML_WRONG_FILE_OFST, "I5044E", EINVAL}, - { LTFS_XML_EXT_OVERLAP, "I5045E", EINVAL}, - { LTFS_XML_EXT_TOO_LONG, "I5046E", EINVAL}, - { LTFS_XML_WRONG_FTIME_L, "I5047E", EINVAL}, - { LTFS_XML_WRONG_PART_MAP, "I5048E", EINVAL}, - { LTFS_XML_WRONG_BLOCKSIZE, "I5049E", EINVAL}, - { LTFS_XML_WRONG_COMP, "I5050E", EINVAL}, - { EDEV_NO_SENSE, "D0000E", EIO}, - { EDEV_OVERRUN, "D0002E", EIO}, - { EDEV_UNDERRUN, "D0003E", ENODATA}, - { EDEV_FILEMARK_DETECTED, "D0004E", EIO}, - { EDEV_EARLY_WARNING, "D0005E", EIO}, - { EDEV_BOP_DETECTED, "D0006E", EIO}, - { EDEV_PROG_EARLY_WARNING, "D0007E", EIO}, - { EDEV_CLEANING_CART, "D0008E", EINVAL}, - { EDEV_VOLTAG_NOT_READABLE, "D0009E", EINVAL}, - { EDEV_LOCATION_NOT_PRESENT, "D0010E", EINVAL}, - { EDEV_MEDIA_PRESENSE_UNKNOWN, "D0011E", EINVAL}, - { EDEV_SLOT_UNKNOWN_STATE, "D0012E", EINVAL}, - { EDEV_DRIVE_NOT_PRESENT, "D0013E", EINVAL}, - { EDEV_RECORD_NOT_FOUND, "D0014E", ESPIPE}, - { EDEV_INSUFFICIENT_TIME, "D0015E", EIO}, + { LTFS_SIG_HANDLER_ERR, "I1041E", EINVAL }, + { LTFS_INTERRUPTED, "I1042E", ECANCELED }, + { LTFS_UNSUPPORTED_INDEX_VERSION, "I1043E", EINVAL }, + { LTFS_ICU_ERROR, "I1044E", EINVAL }, + { LTFS_PLUGIN_LOAD, "I1045E", EINVAL }, + { LTFS_PLUGIN_UNLOAD, "I1046E", EINVAL }, + { LTFS_RDONLY_XATTR, "I1047E", EACCES }, + { LTFS_XATTR_EXISTS, "I1048E", EEXIST }, + { LTFS_SMALL_BUFFER, "I1049E", ERANGE }, + { LTFS_RDONLY_VOLUME, "I1050E", EROFS }, + { LTFS_NO_SPACE, "I1051E", ENOSPC }, + { LTFS_LARGE_XATTR, "I1052E", ENOSPC }, + { LTFS_NO_INDEX, "I1053E", ENODATA }, + { LTFS_XATTR_NAMESPACE, "I1054E", EOPNOTSUPP }, + { LTFS_CONFIG_INVALID, "I1055E", EINVAL }, + { LTFS_PLUGIN_INCOMPLETE, "I1056E", EINVAL }, + { LTFS_NO_PLUGIN, "I1057E", ENOENT }, + { LTFS_POLICY_INVALID, "I1058E", EINVAL }, + { LTFS_ISFILE, "I1059E", ENOTDIR }, + { LTFS_UNRESOLVED_VOLUME, "I1060E", EBUSY }, + { LTFS_POLICY_IMMUTABLE, "I1061E", EPERM }, + { LTFS_SMALL_BLOCKSIZE, "I1062E", EINVAL }, + { LTFS_BARCODE_LENGTH, "I1063E", EINVAL }, + { LTFS_BARCODE_INVALID, "I1064E", EINVAL }, + { LTFS_RESOURCE_SHORTAGE, "I1065E", EBUSY }, + { LTFS_DEVICE_FENCED, "I1066E", EAGAIN }, + { LTFS_REVAL_RUNNING, "I1067E", EAGAIN }, + { LTFS_REVAL_FAILED, "I1068E", EFAULT }, + { LTFS_SLOT_FULL, "I1069E", EFAULT }, + { LTFS_SLOT_SHORTAGE, "I1070E", EFAULT }, + { LTFS_CHANGER_ERROR, "I1071E", EIO }, + { LTFS_UNEXPECTED_TAPE, "I1072E", EINVAL }, + { LTFS_NO_HOMESLOT, "I1073E", EINVAL }, + { LTFS_MOVE_ACTIVE_CART, "I1074E", ECANCELED }, + { LTFS_NO_IE_SLOT, "I1075E", ECANCELED }, + { LTFS_INVALID_SLOT, "I1076E", EINVAL }, + { LTFS_UNSUPPORTED_CART, "I1077E", EINVAL }, + { LTFS_CART_STUCKED, "I1078E", EIO }, + { LTFS_OP_NOT_ALLOWED, "I1079E", EINVAL }, + { LTFS_OP_TO_DUP, "I1080E", EINVAL }, + { LTFS_OP_TO_NON_SUP, "I1081E", EINVAL }, + { LTFS_OP_TO_INACC, "I1082E", EINVAL }, + { LTFS_OP_TO_UNFMT, "I1083E", EINVAL }, + { LTFS_OP_TO_INV, "I1084E", EINVAL }, + { LTFS_OP_TO_ERR, "I1085E", EINVAL }, + { LTFS_OP_TO_CRIT, "I1086E", EINVAL }, + { LTFS_OP_TO_CLN, "I1087E", EINVAL }, + { LTFS_OP_TO_RO, "I1088E", EINVAL }, + { LTFS_ALREADY_FS_INC, "I1089E", EINVAL }, + { LTFS_NOT_IN_FS, "I1090E", EINVAL }, + { LTFS_FS_CART_TO_IE, "I1091E", EINVAL }, + { LTFS_OP_TO_UNKN, "I1092E", EINVAL }, + { LTFS_DRV_LOCKED, "I1093E", EINVAL }, + { LTFS_DRV_ALRDY_ADDED, "I1094E", EINVAL }, + { LTFS_FORCE_INVENTORY, "I1095E", EIO }, + { LTFS_INVENTORY_FAILED, "I1096E", EFAULT }, + { LTFS_RESTART_OPERATION, "I1097E", EIO }, + { LTFS_NO_TARGET_DRIVE, "I1098E", EINVAL }, + { LTFS_NO_DCACHE_FSTYPE, "I1099E", EINVAL }, + { LTFS_IMAGE_EXISTED, "I1100E", EINVAL }, + { LTFS_IMAGE_MOUNTED, "I1101E", EIO }, + { LTFS_IMAGE_NOT_MOUNTED, "I1102E", EIO }, + { LTFS_MTAB_NOREGULAR, "I1103E", EIO }, + { LTFS_MTAB_OPEN, "I1104E", EIO }, + { LTFS_MTAB_LOCK, "I1105E", EIO }, + { LTFS_MTAB_SEEK, "I1106E", EIO }, + { LTFS_MTAB_UPDATE, "I1107E", EIO }, + { LTFS_MTAB_FLUSH, "I1108E", EIO }, + { LTFS_MTAB_UNLOCK, "I1109E", EIO }, + { LTFS_MTAB_CLOSE, "I1110E", EIO }, + { LTFS_MTAB_COPY, "I1111E", EIO }, + { LTFS_MTAB_TEMP_OPEN, "I1112E", EIO }, + { LTFS_MTAB_TEMP_SEEK, "I1113E", EIO }, + { LTFS_DCACHE_CREATION_FAIL, "I1114E", EIO }, + { LTFS_DCACHE_UNSUPPORTED, "I1115E", EINVAL }, + { LTFS_DCACHE_EXTRA_SPACE, "I1116E", EINVAL }, + { LTFS_KEY_NOT_FOUND, "I1117E", EINVAL }, + { LTFS_INVALID_SEQUENCE, "I1118E", EINVAL }, + { LTFS_RDONLY_ROOT, "I1119E", EACCES }, + { LTFS_SYMLINK_CONFLICT, "I1120E", EIO }, + { LTFS_NETWORK_INIT_FAIL, "I1121E", EINVAL }, + { LTFS_DRIVE_SHORTAGE, "I1122E", ENODEV }, + { LTFS_INVALID_VOLSER, "I1123E", EINVAL }, + { LTFS_LESS_SPACE, "I1124E", ENOSPC }, + { LTFS_WRITE_PROTECT, "I1125E", EROFS }, + { LTFS_WRITE_ERROR, "I1126E", EROFS }, + { LTFS_UNEXPECTED_BARCODE, "I1127E", EIO }, + { LTFS_STRING_CONVERSION, "I1128E", EINVAL }, + { LTFS_SESSION_INIT_FAIL, "I1129E", EIO }, + { LTFS_MESSAGE_INVALID, "I1130E", EINVAL }, + { LTFS_PASSWORD_INVALID, "I1131E", EPERM }, + { LTFS_NOT_AUTHENTICATERD, "I1132E", EINVAL }, + { LTFS_WORM_DEEP_RECOVERY, "I1133E", EINVAL }, + { LTFS_WORM_ROLLBACK, "I1134E", EINVAL }, + { LTFS_NONWORM_SALVAGE, "I1135E", EINVAL }, + { LTFS_FORMATTED, "I1136E", EPERM }, + { LTFS_RULES_WORM, "I1137E", EINVAL }, + { LTFS_BAD_BLOCKSIZE, "I1138E", EINVAL }, + { LTFS_BAD_VOLNAME, "I1139E", EINVAL }, + { LTFS_BAD_RULES, "I1140E", EINVAL }, + { LTFS_GEN_NEEDED, "I1141E", EINVAL }, + { LTFS_BAD_GENERATION, "I1142E", EINVAL }, + { LTFS_NO_ROLLBACK_TARGET, "I1143E", EINVAL }, + { LTFS_MANY_INDEXES, "I1144E", EINVAL }, + { LTFS_SALVAGE_NOT_NEEDED, "I1145E", EINVAL }, + { LTFS_WORM_ENABLED, "I1146E", EACCES }, + { LTFS_OUTSTANDING_REFS, "I1147E", EBUSY }, + { LTFS_REBUILD_IN_PROGRESS, "I1148E", EBUSY }, + { LTFS_MULTIPLE_START, "I1149E", EINVAL }, + { LTFS_CARTRIDGE_NOT_FOUND, "I1150E", EINVAL }, + { LTFS_CACHE_LOCK_ERR, "I1151E", EIO }, + { LTFS_CACHE_UNLOCK_ERR, "I1152E", EIO }, + { LTFS_CREPO_FILE_ERR, "I1153E", EIO }, + { LTFS_CREPO_READ_ERR, "I1154E", EIO }, + { LTFS_CREPO_WRITE_ERR, "I1155E", EIO }, + { LTFS_CREPO_INVALID_OP, "I1156E", EINVAL }, + { LTFS_FILE_ERR, "I1157E", EIO }, + { LTFS_CARTRIDGE_IN_USE, "I1158E", EBUSY }, + { LTFS_NO_LOCK_ENTRY, "I1159E", ENOENT }, + { LTFS_MOUNT_ERR, "I1160E", EIO }, + { LTFS_NO_DEVICE, "I1161E", ENODEV }, + { LTFS_XATTR_ERR, "I1162E", EIO }, + { LTFS_FTW_ERR, "I1163E", EIO }, + { LTFS_TIME_ERR, "I1164E", EIO }, + { LTFS_NOT_BLOCK_DEVICE, "I1165E", ENOTBLK }, + { LTFS_QUOTA_EXCEEDED, "I1166E", EDQUOT }, + { LTFS_TOO_MANY_OPEN_FILES, "I1167E", ENFILE }, + { LTFS_LINKDIR_EXISTS, "I1168E", EEXIST }, + { LTFS_NO_DMAP_ENTRY, "I1169E", ENOENT }, + { LTFS_RECOVERABLE_FILE_ERR, "I1170E", EAGAIN }, + { LTFS_NO_DCACHE_SPC, "I1171E", ENOSPC }, + { LTFS_POS_SUSPECT_BOP, "I1172E", EIO }, + /* Unused 1175 - 1179 */ + { LTFS_CACHE_IO, "I1180E", EIO }, + { LTFS_CACHE_DISCARDED, "I1181E", ENOENT }, + { LTFS_LONG_WRITE_LOCK, "I1182E", EAGAIN }, + { LTFS_INCOMPATIBLE_CACHE, "I1183E", EINVAL }, + { LTFS_DCACHE_NOT_INITIALIZED, "I1184E", EIO }, + { LTFS_CONFIG_FILE_WLOCKED, "I1185E", EINVAL }, + { LTFS_CREATE_QUEUE, "I1186E", EIO }, + { LTFS_FORK_ERROR, "I1187E", EIO }, + { LTFS_NOACK, "I1188E", EIO }, + { LTFS_NODE_DETECT_FAIL, "I1189E", EIO }, + { LTFS_INVALID_MESSAGE, "I1190E", EIO }, + { LTFS_NODE_DEGATE_FAIL, "I1191E", EIO }, + { LTFS_CLUSTER_MRSW_FAIL, "I1192E", EIO }, + { LTFS_CART_NOT_MOUNTED, "I1193E", EBUSY }, + { LTFS_RDONLY_DEN_DRV, "I1194E", EINVAL }, + { LTFS_NEED_DRIVE_SELECTION, "I1195E", EINVAL }, + { LTFS_MUTEX_ALREADY_LOCKED, "I1196E", EINVAL }, + { LTFS_TAPE_UNDER_PROCESS, "I1197E", EBUSY }, + { LTFS_TAPE_REMOVED, "I1198E", EIDRM }, + { LTFS_NEED_MOVE, "I1199E", EINVAL }, + { LTFS_NEED_START_OVER, "I1200E", EINVAL }, + { LTFS_LOCATE_ERROR, "I1201E", EIO }, + { LTFS_STATS_DB_OPEN, "I1202E", EIO }, + { LTFS_NO_TRAIL_FM, "I1203E", EINVAL }, + { LTFS_SAFENAME_FAIL, "I1204E", EINVAL }, + { LTFS_SYNC_FAIL_ON_DP, "I1205E", EIO }, + { LTFS_XML_READ_FAIL, "I5000E", EINVAL }, + { LTFS_XML_CONST_FAIL, "I5001E", EINVAL }, + { LTFS_XML_WRONG_NODE, "I5002E", EINVAL }, + { LTFS_XML_UNEXPECTED_EOF, "I5003E", EINVAL }, + { LTFS_XML_EMPTY_UNKNOWN, "I5004E", EINVAL }, + { LTFS_XML_EMPTY, "I5005E", EINVAL }, + { LTFS_XML_SKIP_FAIL, "I5006E", EINVAL }, + { LTFS_XML_NO_REQUIRED_TAG, "I5007E", EINVAL }, + { LTFS_XML_DUPLICATED_TAG, "I5008E", EINVAL }, + { LTFS_XML_OPEN_TAG, "I5009E", EINVAL }, + { LTFS_XML_SAVE_FAIL, "I5010E", EINVAL }, + { LTFS_XML_WRONG_TOPTAG, "I5011E", EINVAL }, + { LTFS_XML_WRONG_ENCODING, "I5012E", EINVAL }, + { LTFS_XML_TOP_ATTR_FAIL, "I5013E", EINVAL }, + { LTFS_XML_WRONG_UUID, "I5014E", EINVAL }, + { LTFS_XML_WRONG_GEN, "I5015E", EINVAL }, + { LTFS_XML_WRONG_UTIME, "I5016E", EINVAL }, + { LTFS_XML_WRONG_LOC, "I5017E", EINVAL }, + { LTFS_XML_WRONG_LOC_PREV, "I5018E", EINVAL }, + { LTFS_XML_WRONG_PA, "I5019E", EINVAL }, + { LTFS_XML_WRONG_POLICY, "I5020E", EINVAL }, + { LTFS_XML_TOO_LONG_COMMENT, "I5021E", EINVAL }, + { LTFS_XML_WRONG_NEXT, "I5022E", EINVAL }, + { LTFS_XML_WRONG_RO_DIR, "I5023E", EINVAL }, + { LTFS_XML_WRONG_MTIME_DIR, "I5024E", EINVAL }, + { LTFS_XML_WRONG_CRTIME_DIR, "I5025E", EINVAL }, + { LTFS_XML_WRONG_ATIME_DIR, "I5026E", EINVAL }, + { LTFS_XML_WRONG_CTIME_DIR, "I5027E", EINVAL }, + { LTFS_XML_WRONG_BTIME_DIR, "I5028E", EINVAL }, + { LTFS_XML_XATTR_TYPE, "I5029E", EINVAL }, + { LTFS_XML_XATTR_SIZE, "I5030E", EINVAL }, + { LTFS_XML_WRONG_UID, "I5031E", EINVAL }, + { LTFS_XML_INVALID_UID, "I5032E", EINVAL }, + { LTFS_XML_WRONG_RO_F, "I5033E", EINVAL }, + { LTFS_XML_WRONG_MTIME_F, "I5034E", EINVAL }, + { LTFS_XML_WRONG_CRTIME_F, "I5035E", EINVAL }, + { LTFS_XML_WRONG_ATIME_F, "I5036E", EINVAL }, + { LTFS_XML_WRONG_CTIME_F, "I5037E", EINVAL }, + { LTFS_XML_WRONG_BTIME_F, "I5038E", EINVAL }, + { LTFS_XML_WRONG_SIZE, "I5039E", EINVAL }, + { LTFS_XML_WRONG_PART, "I5040E", EINVAL }, + { LTFS_XML_WRONG_START_BLK, "I5041E", EINVAL }, + { LTFS_XML_WRONG_OFFSET, "I5042E", EINVAL }, + { LTFS_XML_WRONG_BYTE_CNT, "I5043E", EINVAL }, + { LTFS_XML_WRONG_FILE_OFST, "I5044E", EINVAL }, + { LTFS_XML_EXT_OVERLAP, "I5045E", EINVAL }, + { LTFS_XML_EXT_TOO_LONG, "I5046E", EINVAL }, + { LTFS_XML_WRONG_FTIME_L, "I5047E", EINVAL }, + { LTFS_XML_WRONG_PART_MAP, "I5048E", EINVAL }, + { LTFS_XML_WRONG_BLOCKSIZE, "I5049E", EINVAL }, + { LTFS_XML_WRONG_COMP, "I5050E", EINVAL }, + { EDEV_NO_SENSE, "D0000E", EIO }, + { EDEV_OVERRUN, "D0002E", EIO }, + { EDEV_UNDERRUN, "D0003E", ENODATA }, + { EDEV_FILEMARK_DETECTED, "D0004E", EIO }, + { EDEV_EARLY_WARNING, "D0005E", EIO }, + { EDEV_BOP_DETECTED, "D0006E", EIO }, + { EDEV_PROG_EARLY_WARNING, "D0007E", EIO }, + { EDEV_CLEANING_CART, "D0008E", EINVAL }, + { EDEV_VOLTAG_NOT_READABLE, "D0009E", EINVAL }, + { EDEV_LOCATION_NOT_PRESENT, "D0010E", EINVAL }, + { EDEV_MEDIA_PRESENSE_UNKNOWN, "D0011E", EINVAL }, + { EDEV_SLOT_UNKNOWN_STATE, "D0012E", EINVAL }, + { EDEV_DRIVE_NOT_PRESENT, "D0013E", EINVAL }, + { EDEV_RECORD_NOT_FOUND, "D0014E", ESPIPE }, + { EDEV_INSUFFICIENT_TIME, "D0015E", EIO }, #ifdef EUCLEAN - { EDEV_CLEANING_REQUIRED, "D0098E", EUCLEAN}, + { EDEV_CLEANING_REQUIRED, "D0098E", EUCLEAN }, #else - { EDEV_CLEANING_REQUIRED, "D0098E", EAGAIN}, + { EDEV_CLEANING_REQUIRED, "D0098E", EAGAIN }, #endif - { EDEV_RECOVERED_ERROR, "D0100E", EIO}, - { EDEV_MODE_PARAMETER_ROUNDED, "D0101E", EIO}, - { EDEV_DEGRADED_MEDIA, "D0198E", EIO}, - { EDEV_NOT_READY, "D0200E", EAGAIN}, - { EDEV_NOT_REPORTABLE, "D0201E", EAGAIN}, - { EDEV_BECOMING_READY, "D0202E", EAGAIN}, - { EDEV_NEED_INITIALIZE, "D0203E", EIO}, - { EDEV_MANUAL_INTERVENTION, "D0204E", EAGAIN}, - { EDEV_OPERATION_IN_PROGRESS, "D0205E", EAGAIN}, - { EDEV_OFFLINE, "D0206E", EAGAIN}, - { EDEV_DOOR_OPEN, "D0207E", EAGAIN}, - { EDEV_OVER_TEMPERATURE, "D0208E", EAGAIN}, + { EDEV_RECOVERED_ERROR, "D0100E", EIO }, + { EDEV_MODE_PARAMETER_ROUNDED, "D0101E", EIO }, + { EDEV_DEGRADED_MEDIA, "D0198E", EIO }, + { EDEV_NOT_READY, "D0200E", EAGAIN }, + { EDEV_NOT_REPORTABLE, "D0201E", EAGAIN }, + { EDEV_BECOMING_READY, "D0202E", EAGAIN }, + { EDEV_NEED_INITIALIZE, "D0203E", EIO }, + { EDEV_MANUAL_INTERVENTION, "D0204E", EAGAIN }, + { EDEV_OPERATION_IN_PROGRESS, "D0205E", EAGAIN }, + { EDEV_OFFLINE, "D0206E", EAGAIN }, + { EDEV_DOOR_OPEN, "D0207E", EAGAIN }, + { EDEV_OVER_TEMPERATURE, "D0208E", EAGAIN }, #ifdef ENOMEDIUM - { EDEV_NO_MEDIUM, "D0209E", ENOMEDIUM}, + { EDEV_NO_MEDIUM, "D0209E", ENOMEDIUM }, #else - { EDEV_NO_MEDIUM, "D0209E", EAGAIN}, + { EDEV_NO_MEDIUM, "D0209E", EAGAIN }, #endif /* ENOMEDIUM */ - { EDEV_NOT_SELF_CONFIGURED_YET, "D0210E", EAGAIN}, - { EDEV_PARAMETER_VALUE_REJECTED, "D0211E", EINVAL}, - { EDEV_CLEANING_IN_PROGRESS, "D0297E", EAGAIN}, - { EDEV_IE_OPEN, "D0298E", EAGAIN}, - { EDEV_MEDIUM_ERROR, "D0300E", EIO}, - { EDEV_RW_PERM, "D0301E", EIO}, - { EDEV_CM_PERM, "D0302E", EIO}, - { EDEV_MEDIUM_FORMAT_ERROR, "D0303E", EIO}, - { EDEV_MEDIUM_FORMAT_CORRUPTED, "D0304E", EIO}, - { EDEV_INTEGRITY_CHECK, "D0305E", EILSEQ}, - { EDEV_LOAD_UNLOAD_ERROR, "D0306E", EIO}, - { EDEV_CLEANING_FALIURE, "D0307E", EIO}, - { EDEV_READ_PERM, "D0308E", EIO}, - { EDEV_WRITE_PERM, "D0309E", EIO}, - { EDEV_HARDWARE_ERROR, "D0400E", EIO}, - { EDEV_LBP_WRITE_ERROR, "D0401E", EIO}, - { EDEV_LBP_READ_ERROR, "D0402E", EIO}, - { EDEV_NO_CONNECTION, "D0403E", EIO}, - { EDEV_ILLEGAL_REQUEST, "D0500E", EILSEQ}, - { EDEV_INVALID_FIELD_CDB, "D0501E", EILSEQ}, - { EDEV_DEST_FULL, "D0502E", EIO}, - { EDEV_SRC_EMPTY, "D0503E", EIO}, - { EDEV_MAGAZINE_INACCESSIBLE, "D0504E", EIO}, - { EDEV_INVALID_ADDRESS, "D0505E", EIDRM}, - { EDEV_MEDIUM_LOCKED, "D0506E", EIO}, - { EDEV_UNIT_ATTENTION, "D0600E", EIO}, - { EDEV_MEDIUM_MAY_BE_CHANGED, "D0601E", EIO}, - { EDEV_IE_ACCESSED, "D0602E", EIO}, - { EDEV_POR_OR_BUS_RESET, "D0603E", EIO}, - { EDEV_CONFIGURE_CHANGED, "D0604E", EIO}, - { EDEV_COMMAND_CLEARED, "D0605E", EIO}, - { EDEV_MEDIUM_REMOVAL_REQ, "D0606E", EIO}, - { EDEV_MEDIA_REMOVAL_PREV, "D0607E", EIO}, - { EDEV_DOOR_CLOSED, "D0608E", EIO}, - { EDEV_TIME_STAMP_CHANGED, "D0609E", EIO}, - { EDEV_RESERVATION_PREEMPTED, "D0610E", EIO}, - { EDEV_RESERVATION_RELEASED, "D0611E", EIO}, - { EDEV_REGISTRATION_PREEMPTED, "D0612E", EIO}, - { EDEV_DATA_PROTECT, "D0700E", EIO}, - { EDEV_WRITE_PROTECTED, "D0701E", EIO}, - { EDEV_WRITE_PROTECTED_WORM, "D0702E", EIO}, - { EDEV_WRITE_PROTECTED_OPERATOR, "D0703E", EIO}, - { EDEV_BLANK_CHECK, "D0800E", EIO}, - { EDEV_EOD_DETECTED, "D0801E", ESPIPE}, - { EDEV_EOD_NOT_FOUND, "D0802E", ESPIPE}, - { EDEV_ABORTED_COMMAND, "D1100E", EIO}, - { EDEV_OVERLAPPED, "D1101E", EIO}, - { EDEV_TIMEOUT, "D1102E", ETIMEDOUT}, - { EDEV_ABORT_WAIT_READY, "D1103E", EIO}, - { EDEV_OVERFLOW, "D1300E", EIO}, - { EDEV_CRYPTO_ERROR, "D1600E", EIO}, - { EDEV_KEY_SERVICE_ERROR, "D1601E", EIO}, - { EDEV_KEY_CHANGE_DETECTED, "D1602E", EIO}, - { EDEV_KEY_REQUIRED, "D1603E", EIO}, - { EDEV_INTERNAL_ERROR, "D1700E", EIO}, - { EDEV_DRIVER_ERROR, "D1701E", EIO}, - { EDEV_HOST_ERROR, "D1702E", EIO}, - { EDEV_TARGET_ERROR, "D1703E", EIO}, - { EDEV_DRIVER_ERROR, "D1701E", EIO}, - { EDEV_NO_MEMORY, "D1704E", EIO}, - { EDEV_UNSUPPORTED_FUNCTION, "D1705E", EIO}, - { EDEV_PARAMETER_NOT_FOUND, "D1706E", EIO}, - { EDEV_CANNOT_GET_SENSE, "D1707E", EIO}, - { EDEV_INVALID_ARG, "D1708E", EINVAL}, - { EDEV_DUMP_EIO, "D1709E", EIO}, - { EDEV_UNKNOWN, "D9998E", EIO}, - { EDEV_VENDOR_UNIQUE, "D9999E", EIO}, - { EDEV_DEVICE_BUSY, "D1710E", EAGAIN}, - { EDEV_DEVICE_UNOPENABLE, "D1711E", EIO}, - { EDEV_DEVICE_UNSUPPORTABLE, "D1712E", EOPNOTSUPP}, - { EDEV_INVALID_LICENSE, "D1713E", EOPNOTSUPP}, - { EDEV_UNSUPPORTED_FIRMWARE, "D1714E", EOPNOTSUPP}, - { EDEV_UNSUPPORETD_COMMAND, "D1715E", EOPNOTSUPP}, - { EDEV_LENGTH_MISMATCH, "D1716E", EINVAL}, - { EDEV_BUFFER_OVERFLOW, "D1717E", EINVAL}, - { EDEV_DRIVES_MISMATCH, "D1718E", EINVAL}, - { EDEV_RESERVATION_CONFLICT, "D1719E", EIO}, - { EDEV_CONNECTION_LOST, "D1720E", EIO}, - { EDEV_NO_RESERVATION_HOLDER, "D1721E", EIO}, - { EDEV_NEED_FAILOVER, "D1722E", EIO}, - { EDEV_REAL_POWER_ON_RESET, "D1723E", EIO}, - { EDEV_BUFFER_ALLOCATE_ERROR, "D1724E", EIO}, - { EDEV_RETRY, "D1725E", EIO}, - { -1, NULL, 0 } -}; + { EDEV_NOT_SELF_CONFIGURED_YET, "D0210E", EAGAIN }, + { EDEV_PARAMETER_VALUE_REJECTED, "D0211E", EINVAL }, + { EDEV_CLEANING_IN_PROGRESS, "D0297E", EAGAIN }, + { EDEV_IE_OPEN, "D0298E", EAGAIN }, + { EDEV_MEDIUM_ERROR, "D0300E", EIO }, + { EDEV_RW_PERM, "D0301E", EIO }, + { EDEV_CM_PERM, "D0302E", EIO }, + { EDEV_MEDIUM_FORMAT_ERROR, "D0303E", EIO }, + { EDEV_MEDIUM_FORMAT_CORRUPTED, "D0304E", EIO }, + { EDEV_INTEGRITY_CHECK, "D0305E", EILSEQ }, + { EDEV_LOAD_UNLOAD_ERROR, "D0306E", EIO }, + { EDEV_CLEANING_FALIURE, "D0307E", EIO }, + { EDEV_READ_PERM, "D0308E", EIO }, + { EDEV_WRITE_PERM, "D0309E", EIO }, + { EDEV_HARDWARE_ERROR, "D0400E", EIO }, + { EDEV_LBP_WRITE_ERROR, "D0401E", EIO }, + { EDEV_LBP_READ_ERROR, "D0402E", EIO }, + { EDEV_NO_CONNECTION, "D0403E", EIO }, + { EDEV_ILLEGAL_REQUEST, "D0500E", EILSEQ }, + { EDEV_INVALID_FIELD_CDB, "D0501E", EILSEQ }, + { EDEV_DEST_FULL, "D0502E", EIO }, + { EDEV_SRC_EMPTY, "D0503E", EIO }, + { EDEV_MAGAZINE_INACCESSIBLE, "D0504E", EIO }, + { EDEV_INVALID_ADDRESS, "D0505E", EIDRM }, + { EDEV_MEDIUM_LOCKED, "D0506E", EIO }, + { EDEV_UNIT_ATTENTION, "D0600E", EIO }, + { EDEV_MEDIUM_MAY_BE_CHANGED, "D0601E", EIO }, + { EDEV_IE_ACCESSED, "D0602E", EIO }, + { EDEV_POR_OR_BUS_RESET, "D0603E", EIO }, + { EDEV_CONFIGURE_CHANGED, "D0604E", EIO }, + { EDEV_COMMAND_CLEARED, "D0605E", EIO }, + { EDEV_MEDIUM_REMOVAL_REQ, "D0606E", EIO }, + { EDEV_MEDIA_REMOVAL_PREV, "D0607E", EIO }, + { EDEV_DOOR_CLOSED, "D0608E", EIO }, + { EDEV_TIME_STAMP_CHANGED, "D0609E", EIO }, + { EDEV_RESERVATION_PREEMPTED, "D0610E", EIO }, + { EDEV_RESERVATION_RELEASED, "D0611E", EIO }, + { EDEV_REGISTRATION_PREEMPTED, "D0612E", EIO }, + { EDEV_DATA_PROTECT, "D0700E", EIO }, + { EDEV_WRITE_PROTECTED, "D0701E", EIO }, + { EDEV_WRITE_PROTECTED_WORM, "D0702E", EIO }, + { EDEV_WRITE_PROTECTED_OPERATOR, "D0703E", EIO }, + { EDEV_BLANK_CHECK, "D0800E", EIO }, + { EDEV_EOD_DETECTED, "D0801E", ESPIPE }, + { EDEV_EOD_NOT_FOUND, "D0802E", ESPIPE }, + { EDEV_ABORTED_COMMAND, "D1100E", EIO }, + { EDEV_OVERLAPPED, "D1101E", EIO }, + { EDEV_TIMEOUT, "D1102E", ETIMEDOUT }, + { EDEV_ABORT_WAIT_READY, "D1103E", EIO }, + { EDEV_OVERFLOW, "D1300E", EIO }, + { EDEV_CRYPTO_ERROR, "D1600E", EIO }, + { EDEV_KEY_SERVICE_ERROR, "D1601E", EIO }, + { EDEV_KEY_CHANGE_DETECTED, "D1602E", EIO }, + { EDEV_KEY_REQUIRED, "D1603E", EIO }, + { EDEV_INTERNAL_ERROR, "D1700E", EIO }, + { EDEV_DRIVER_ERROR, "D1701E", EIO }, + { EDEV_HOST_ERROR, "D1702E", EIO }, + { EDEV_TARGET_ERROR, "D1703E", EIO }, + { EDEV_DRIVER_ERROR, "D1701E", EIO }, + { EDEV_NO_MEMORY, "D1704E", EIO }, + { EDEV_UNSUPPORTED_FUNCTION, "D1705E", EIO }, + { EDEV_PARAMETER_NOT_FOUND, "D1706E", EIO }, + { EDEV_CANNOT_GET_SENSE, "D1707E", EIO }, + { EDEV_INVALID_ARG, "D1708E", EINVAL }, + { EDEV_DUMP_EIO, "D1709E", EIO }, + { EDEV_UNKNOWN, "D9998E", EIO }, + { EDEV_VENDOR_UNIQUE, "D9999E", EIO }, + { EDEV_DEVICE_BUSY, "D1710E", EAGAIN }, + { EDEV_DEVICE_UNOPENABLE, "D1711E", EIO }, + { EDEV_DEVICE_UNSUPPORTABLE, "D1712E", EOPNOTSUPP }, + { EDEV_INVALID_LICENSE, "D1713E", EOPNOTSUPP }, + { EDEV_UNSUPPORTED_FIRMWARE, "D1714E", EOPNOTSUPP }, + { EDEV_UNSUPPORETD_COMMAND, "D1715E", EOPNOTSUPP }, + { EDEV_LENGTH_MISMATCH, "D1716E", EINVAL }, + { EDEV_BUFFER_OVERFLOW, "D1717E", EINVAL }, + { EDEV_DRIVES_MISMATCH, "D1718E", EINVAL }, + { EDEV_RESERVATION_CONFLICT, "D1719E", EIO }, + { EDEV_CONNECTION_LOST, "D1720E", EIO }, + { EDEV_NO_RESERVATION_HOLDER, "D1721E", EIO }, + { EDEV_NEED_FAILOVER, "D1722E", EIO }, + { EDEV_REAL_POWER_ON_RESET, "D1723E", EIO }, + { EDEV_BUFFER_ALLOCATE_ERROR, "D1724E", EIO }, + { EDEV_RETRY, "D1725E", EIO }, + { -1, NULL, 0 } }; int errormap_init() { struct error_map *err; HASH_ADD_INT(fuse_errormap, ltfs_error, fuse_error_list); - if (! fuse_errormap) { + if (!fuse_errormap) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } - for (err=fuse_error_list+1; err->ltfs_error!=-1; ++err) + for (err = fuse_error_list + 1; err->ltfs_error != -1; ++err) HASH_ADD_INT(fuse_errormap, ltfs_error, err); return 0; @@ -490,27 +489,23 @@ int errormap_fuse_error(int val) struct error_map *out; val = -val; - if (val < LTFS_ERR_MIN) - return -val; + if (val < LTFS_ERR_MIN) return -val; HASH_FIND_INT(fuse_errormap, &val, out); - if (out) - return -out->general_error; + if (out) return -out->general_error; return -EIO; } -char* errormap_msg_id(int val) +char *errormap_msg_id(int val) { struct error_map *out; val = -val; - if (val < LTFS_ERR_MIN) - return NULL; + if (val < LTFS_ERR_MIN) return NULL; HASH_FIND_INT(fuse_errormap, &val, out); - if (out) - return out->msd_id; + if (out) return out->msd_id; return NULL; } diff --git a/src/libltfs/arch/filename_handling.c b/src/libltfs/arch/filename_handling.c index e61257b9..dfd1069e 100644 --- a/src/libltfs/arch/filename_handling.c +++ b/src/libltfs/arch/filename_handling.c @@ -47,13 +47,13 @@ ************************************************************************************* */ +#include "libltfs/arch/filename_handling.h" #include "libltfs/fs.h" #include "libltfs/pathname.h" -#include "libltfs/arch/filename_handling.h" #if defined(mingw_PLATFORM) -bool _replace_invalid_chars(char * file_name, bool * dosdev); -char * _generate_target_file_name(const char *prefix, const char *extension, int suffix, bool dosdev); +bool _replace_invalid_chars(char *file_name, bool *dosdev); +char *_generate_target_file_name(const char *prefix, const char *extension, int suffix, bool dosdev); int _utf8_strlen(const char *s); int _utf8_strcpy(char *t, const char *s, int n); #endif @@ -65,35 +65,33 @@ int _utf8_strcpy(char *t, const char *s, int n); * if TRUE. otherwise the name is skipped withour updating * platform_safe_name field. */ -void update_platform_safe_name(struct dentry* dentry, bool handle_invalid_char, struct ltfs_index *idx) +void update_platform_safe_name(struct dentry *dentry, bool handle_invalid_char, struct ltfs_index *idx) { #if defined(mingw_PLATFORM) bool dosdev = false; int suffix = 0; - char source_file_name[LTFS_FILENAME_MAX*4+1]; + char source_file_name[LTFS_FILENAME_MAX * 4 + 1]; char *source_file_name_prefix, *source_file_name_extension; char *target_file_name; - struct dentry* d = NULL; + struct dentry *d = NULL; int ret; dentry->platform_safe_name = NULL; arch_strcpy_auto(source_file_name, dentry->name.name); if (_replace_invalid_chars(source_file_name, &dosdev)) { - if (! handle_invalid_char) - return; + if (!handle_invalid_char) return; suffix++; } /* Split source file name to prefix and extension */ - if (! dosdev) { + if (!dosdev) { source_file_name_prefix = source_file_name; source_file_name_extension = strrchr(source_file_name, '.'); /* If '.' is at the beginning of file name, then all of file name is recognized as prefix, not extension. */ - if (source_file_name_extension == source_file_name_prefix) - source_file_name_extension = NULL; + if (source_file_name_extension == source_file_name_prefix) source_file_name_extension = NULL; } else { source_file_name_prefix = source_file_name; source_file_name_extension = strchr(source_file_name, '.'); @@ -107,7 +105,7 @@ void update_platform_safe_name(struct dentry* dentry, bool handle_invalid_char, while (1) { target_file_name = _generate_target_file_name(source_file_name_prefix, source_file_name_extension, suffix, dosdev); - if (! target_file_name) + if (!target_file_name) break; else { if (dentry->parent) { @@ -117,7 +115,7 @@ void update_platform_safe_name(struct dentry* dentry, bool handle_invalid_char, break; } } - if (! dentry->parent || ! d ) { + if (!dentry->parent || !d) { dentry->platform_safe_name = target_file_name; break; } else { @@ -157,35 +155,31 @@ int ltfs_compare_names(const char *name1, const char *name2, int *result) * name includes reserved dos device name. * @param file_name file_name to be checked */ -bool _replace_invalid_chars(char * file_name, bool * dosdev) +bool _replace_invalid_chars(char *file_name, bool *dosdev) { bool to_be_changed = false; - static char invalid_chars[] = "\\:*?\"<>|" ; - static char *dosdev_list[] = { "CON", "PRN", "AUX", "CLOCK$", "NUL", "COM0", - "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", - "COM7", "COM8", "COM9", "LPT0", "LPT1", "LPT2", - "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", - "LPT9", NULL }; + static char invalid_chars[] = "\\:*?\"<>|"; + static char *dosdev_list[] = { "CON", "PRN", "AUX", "CLOCK$", "NUL", "COM0", "COM1", "COM2", "COM3", + "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "LPT0", "LPT1", "LPT2", + "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9", NULL }; int i; *dosdev = false; for (i = 0; dosdev_list[i]; i++) { - if ( strcasestr(file_name, dosdev_list[i]) == file_name && - (file_name[strlen(dosdev_list[i])] == '\0' ||file_name[strlen(dosdev_list[i])] == '.') ) { + if (strcasestr(file_name, dosdev_list[i]) == file_name && + (file_name[strlen(dosdev_list[i])] == '\0' || file_name[strlen(dosdev_list[i])] == '.')) { *dosdev = true; to_be_changed = true; } } - for (i = 0; ; i++) { + for (i = 0;; i++) { if (file_name[i]) { - if (file_name[i] >= 0x01 && file_name[i] <= 0x1F || - strchr(invalid_chars, file_name[i])) { + if (file_name[i] >= 0x01 && file_name[i] <= 0x1F || strchr(invalid_chars, file_name[i])) { file_name[i] = '_'; to_be_changed = true; } - } - else + } else break; } @@ -197,26 +191,26 @@ bool _replace_invalid_chars(char * file_name, bool * dosdev) * extension, and suffix. * @param file_name file_name to be checked */ -char * _generate_target_file_name(const char *prefix, const char *extension, int suffix, bool dosdev) +char *_generate_target_file_name(const char *prefix, const char *extension, int suffix, bool dosdev) { char *target; - char suffix_string[LTFS_FILENAME_MAX*4+1]; - char trimmed_name[LTFS_FILENAME_MAX*4+1]; + char suffix_string[LTFS_FILENAME_MAX * 4 + 1]; + char trimmed_name[LTFS_FILENAME_MAX * 4 + 1]; int prefix_length, extension_length, suffix_length, ret; ret = -1; target = NULL; if (suffix) { - arch_sprintf_auto( suffix_string, "~%d", suffix ); + arch_sprintf_auto(suffix_string, "~%d", suffix); - prefix_length = prefix ? _utf8_strlen(prefix) : 0; + prefix_length = prefix ? _utf8_strlen(prefix) : 0; extension_length = extension ? _utf8_strlen(extension) : 0; - suffix_length = _utf8_strlen(suffix_string); + suffix_length = _utf8_strlen(suffix_string); if (prefix_length + extension_length + suffix_length > LTFS_FILENAME_MAX) { /* Need to trim source file name to add suffix */ - if (! dosdev && prefix_length > suffix_length) { + if (!dosdev && prefix_length > suffix_length) { /* Prefix is to be trimmed. */ _utf8_strcpy(trimmed_name, prefix, prefix_length - suffix_length); if (extension) @@ -260,8 +254,7 @@ int _utf8_strlen(const char *s) CHECK_ARG_NULL(s, -LTFS_NULL_ARG); while (*s) { - if (! (*s & 0x80) || (*s & 0xC0) == 0xC0) - ++ret; + if (!(*s & 0x80) || (*s & 0xC0) == 0xC0) ++ret; ++s; } return ret; @@ -281,7 +274,7 @@ int _utf8_strcpy(char *t, const char *s, int n) CHECK_ARG_NULL(s, -LTFS_NULL_ARG); while (*s) { - if (! (*s & 0x80) || (*s & 0xC0) == 0xC0) { + if (!(*s & 0x80) || (*s & 0xC0) == 0xC0) { ++ret; if (ret > n) { *t = 0x00; diff --git a/src/libltfs/arch/osx/osx_string.c b/src/libltfs/arch/osx/osx_string.c index 6001b3f4..9c65d591 100644 --- a/src/libltfs/arch/osx/osx_string.c +++ b/src/libltfs/arch/osx/osx_string.c @@ -49,29 +49,30 @@ #ifdef __APPLE__ -#include "osx_string.h" +# include "osx_string.h" -size_t strnlen(const char *s, size_t maxlen) { - const char *null_pos = memchr(s, '\0', maxlen); +size_t strnlen(const char *s, size_t maxlen) +{ + const char *null_pos = memchr(s, '\0', maxlen); - if (null_pos) { - return null_pos - s; - } else { - return maxlen; - } + if (null_pos) { + return null_pos - s; + } else { + return maxlen; + } } -char *strndup(const char *s, size_t maxlen) { +char *strndup(const char *s, size_t maxlen) +{ + size_t length = strnlen(s, maxlen); + char *destination = malloc(length + 1); - size_t length = strnlen(s, maxlen); - char *destination = malloc(length + 1); + if (destination == NULL) { + return NULL; + } - if(destination == NULL) { - return NULL; - } - - destination[length] = '\0'; - return memcpy(destination, s, length); + destination[length] = '\0'; + return memcpy(destination, s, length); } #endif /* __APPLE__ */ diff --git a/src/libltfs/arch/time_internal.c b/src/libltfs/arch/time_internal.c index e47ab2db..55ef5c6e 100644 --- a/src/libltfs/arch/time_internal.c +++ b/src/libltfs/arch/time_internal.c @@ -50,11 +50,11 @@ #ifndef time_internal_c_ #define time_internal_c_ +#include "libltfs/arch/time_internal.h" +#include "libltfs/ltfslogging.h" +#include #include #include -#include -#include "libltfs/ltfslogging.h" -#include "libltfs/arch/time_internal.h" #ifdef __APPLE__ /* @@ -62,15 +62,15 @@ * It is specified by compile option of Makefile.osx because autoconf architecture is * not used under OSX. */ -#define SIZEOF_TIME_T (8) +# define SIZEOF_TIME_T (8) #else -#include "config.h" +# include "config.h" #endif #ifndef mingw_PLATFORM -#if ! ((SIZEOF_TIME_T == 4) || (SIZEOF_TIME_T == 8)) - #error time_t width is not 4 or 8 -#endif +# if !((SIZEOF_TIME_T == 4) || (SIZEOF_TIME_T == 8)) +# error time_t width is not 4 or 8 +# endif #endif ltfs_time_t ltfs_timegm(struct tm *t) @@ -80,19 +80,15 @@ ltfs_time_t ltfs_timegm(struct tm *t) ltfs_time_t ret; tmp = (t->tm_mon - 13) / 12; - rel = 86400LL * ((1461 * (t->tm_year + 6700 + tmp)) / 4 - + (367 * (t->tm_mon - 1 - 12 * tmp)) / 12 - - (3 * ((t->tm_year + 6800 + tmp) / 100)) / 4 - + t->tm_mday - 2472663) - + 3600 * t->tm_hour + 60 * t->tm_min + t->tm_sec; + rel = 86400LL * ((1461 * (t->tm_year + 6700 + tmp)) / 4 + (367 * (t->tm_mon - 1 - 12 * tmp)) / 12 - + (3 * ((t->tm_year + 6800 + tmp) / 100)) / 4 + t->tm_mday - 2472663) + + 3600 * t->tm_hour + 60 * t->tm_min + t->tm_sec; if (sizeof(time_t) == 4) { if (rel > LONG_MAX) - ltfsmsg(LTFS_WARN, 17172W, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday - , t->tm_hour, t->tm_min, t->tm_sec); + ltfsmsg(LTFS_WARN, 17172W, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec); if (rel < LONG_MIN) - ltfsmsg(LTFS_WARN, 17173W, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday - , t->tm_hour, t->tm_min, t->tm_sec); + ltfsmsg(LTFS_WARN, 17173W, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec); } ret = rel; @@ -100,22 +96,22 @@ ltfs_time_t ltfs_timegm(struct tm *t) } #ifdef __APPLE__ -#include -#include -#include -#include -#include +# include +# include +# include +# include +# include -void __get_time(_time_stamp_t* t) +void __get_time(_time_stamp_t *t) { - *t = mach_absolute_time(); + *t = mach_absolute_time(); } int get_timer_info(struct timer_info *ti) { mach_timebase_info_data_t timebase; - (void) mach_timebase_info(&timebase); + (void)mach_timebase_info(&timebase); ti->type = TIMER_TYPE_OSX; ti->base = ((uint64_t)timebase.denom << 32) + timebase.numer; @@ -123,33 +119,33 @@ int get_timer_info(struct timer_info *ti) return 0; } -int get_osx_current_timespec(struct ltfs_timespec* now) { +int get_osx_current_timespec(struct ltfs_timespec *now) +{ int ret = -1; kern_return_t kernel_return; - clock_serv_t clock; + clock_serv_t clock; mach_timespec_t time; kernel_return = host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &clock); if (KERN_SUCCESS == kernel_return) { kernel_return = clock_get_time(clock, &time); if (KERN_SUCCESS == kernel_return) { - now->tv_sec = time.tv_sec; + now->tv_sec = time.tv_sec; now->tv_nsec = time.tv_nsec; ret = 0; } - } + } if (ret != 0) { errno = EINVAL; ret = -1; } - if (ret < 0) - ltfsmsg(LTFS_ERR, 11110E, ret); + if (ret < 0) ltfsmsg(LTFS_ERR, 11110E, ret); return ret; } #elif defined(mingw_PLATFORM) #else -int get_unix_current_timespec(struct ltfs_timespec* now) +int get_unix_current_timespec(struct ltfs_timespec *now) { struct timespec ts; int ret = clock_gettime(CLOCK_REALTIME, &ts); @@ -166,12 +162,11 @@ struct tm *get_unix_localtime(const ltfs_time_t *timep) int ltfs_get_days_of_year(int64_t nYear) { - int nDays = ((nYear % 400) == 0 || (((nYear % 100) != 0) && ((nYear % 4) == 0))) ? - 366 : 365; + int nDays = ((nYear % 400) == 0 || (((nYear % 100) != 0) && ((nYear % 4) == 0))) ? 366 : 365; return nDays; } -int ltfs_get_mday_from_yday(int64_t nYear, int nYday, int* pnMonth) +int ltfs_get_mday_from_yday(int64_t nYear, int nYday, int *pnMonth) { int i = 0; int nMday = nYday; @@ -202,46 +197,43 @@ int ltfs_get_mday_from_yday(int64_t nYear, int nYday, int* pnMonth) struct tm *ltfs_gmtime(const ltfs_time_t *timep, struct tm *result) { int n; - int64_t nSrcTime = *timep; + int64_t nSrcTime = *timep; int64_t nYears = 0; int64_t nYday = 0; int nDaysOfYear = 0; // cyclic periods in terms leap years - int64_t nDays4Y = 1461; // 4 years = (365 days ) * 4 + 1 - int64_t nDays100Y = 36524; // 100 years = ( 4 years) * 25 - 1 - int64_t nDays400Y = 146097; // 400 years = (100 years) * 4 + 1 + int64_t nDays4Y = 1461; // 4 years = (365 days ) * 4 + 1 + int64_t nDays100Y = 36524; // 100 years = ( 4 years) * 25 - 1 + int64_t nDays400Y = 146097; // 400 years = (100 years) * 4 + 1 int64_t n400Y, n100Y, n4Y, n1Y; memset(result, 0, sizeof(struct tm)); n = nSrcTime % 60; // n = seconds - nSrcTime /= 60; // nSrcTime is in minutes + nSrcTime /= 60; // nSrcTime is in minutes if (0 <= n) { - result->tm_sec = n; - } - else { - result->tm_sec = n + 60; + result->tm_sec = n; + } else { + result->tm_sec = n + 60; nSrcTime--; } n = nSrcTime % 60; // n = minutes - nSrcTime /= 60; // nSrcTime is in hours + nSrcTime /= 60; // nSrcTime is in hours if (0 <= n) { - result->tm_min = n; - } - else { - result->tm_min = n + 60; + result->tm_min = n; + } else { + result->tm_min = n + 60; nSrcTime--; } n = nSrcTime % 24; // n = hours - nSrcTime /= 24; // nSrcTime is in days + nSrcTime /= 24; // nSrcTime is in days if (0 <= n) { - result->tm_hour = n; - } - else { - result->tm_hour = n + 24; + result->tm_hour = n; + } else { + result->tm_hour = n + 24; nSrcTime--; } @@ -292,8 +284,7 @@ struct tm *ltfs_gmtime(const ltfs_time_t *timep, struct tm *result) if (nDaysOfYear <= nYday) { nYears++; nYday -= nDaysOfYear; - } - else if (nYday < 0) { + } else if (nYday < 0) { nDaysOfYear = ltfs_get_days_of_year((--nYears) + 2000); nYday += nDaysOfYear; } diff --git a/src/libltfs/arch/time_internal.h b/src/libltfs/arch/time_internal.h index baabb1d0..1841c377 100644 --- a/src/libltfs/arch/time_internal.h +++ b/src/libltfs/arch/time_internal.h @@ -49,6 +49,7 @@ #ifndef time_internal_h_ #define time_internal_h_ +#include #ifdef __cplusplus extern "C" { diff --git a/src/libltfs/arch/uuid_internal.c b/src/libltfs/arch/uuid_internal.c index d5b15a8c..c84c006c 100644 --- a/src/libltfs/arch/uuid_internal.c +++ b/src/libltfs/arch/uuid_internal.c @@ -49,7 +49,7 @@ #ifndef mingw_PLATFORM -#include +# include void gen_uuid_unix(char *uuid_str) { @@ -59,4 +59,3 @@ void gen_uuid_unix(char *uuid_str) } #endif - diff --git a/src/libltfs/base64.c b/src/libltfs/base64.c index 42cdf571..3f34a245 100644 --- a/src/libltfs/base64.c +++ b/src/libltfs/base64.c @@ -47,10 +47,10 @@ ************************************************************************************* */ -#include -#include -#include "libltfs/ltfslogging.h" #include "base64.h" +#include "libltfs/ltfslogging.h" +#include +#include static const char *base64_enc = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; @@ -84,19 +84,18 @@ size_t base64_decode(const unsigned char *enc, size_t nbytes_in, unsigned char * } /* prepare the decode map */ - memset(base64_dec,UCHAR_MAX,256); - for (i=0; i<64; ++i) + memset(base64_dec, UCHAR_MAX, 256); + for (i = 0; i < 64; ++i) base64_dec[(size_t)base64_enc[i]] = i; /* check for out-of-place '=' and invalid characters */ nequal = 0; nbytes_real = nbytes_in; - for (i=0; i> 4; if (cur_quad[2] != UCHAR_MAX) { - (*dec)[out_pos+1] = (cur_quad[1] & 0xF) << 4; - (*dec)[out_pos+1] |= (cur_quad[2] & 0x3C) >> 2; + (*dec)[out_pos + 1] = (cur_quad[1] & 0xF) << 4; + (*dec)[out_pos + 1] |= (cur_quad[2] & 0x3C) >> 2; if (cur_quad[3] != UCHAR_MAX) { - (*dec)[out_pos+2] = (cur_quad[2] & 0x3) << 6; - (*dec)[out_pos+2] |= cur_quad[3]; + (*dec)[out_pos + 2] = (cur_quad[2] & 0x3) << 6; + (*dec)[out_pos + 2] |= cur_quad[3]; } } out_pos += 3; @@ -144,4 +142,3 @@ size_t base64_decode(const unsigned char *enc, size_t nbytes_in, unsigned char * return nout; } - diff --git a/src/libltfs/config_file.c b/src/libltfs/config_file.c index 37274216..24a3c3d2 100644 --- a/src/libltfs/config_file.c +++ b/src/libltfs/config_file.c @@ -56,40 +56,42 @@ */ #ifdef mingw_PLATFORM -#include "arch/win/win_util.h" +# include "arch/win/win_util.h" #endif -#include -#include #include +#include #include +#include #include -#include #include +#include +#include "config_file.h" #include "libltfs/arch/ltfs_arch_ops.h" -#include "libltfs/ltfslogging.h" #include "libltfs/ltfs_error.h" -#include "config_file.h" - +#include "libltfs/ltfslogging.h" -struct plugin_entry { +struct plugin_entry +{ TAILQ_ENTRY(plugin_entry) list; char *type; char *name; char *library; }; -struct option_entry { +struct option_entry +{ TAILQ_ENTRY(option_entry) list; char *type; char *option; }; -struct config_file { - TAILQ_HEAD(plugin_struct, plugin_entry) plugins; /**< Available plugins */ +struct config_file +{ + TAILQ_HEAD(plugin_struct, plugin_entry) plugins; /**< Available plugins */ TAILQ_HEAD(default_struct, plugin_entry) default_plugins; /**< Default plugins */ - TAILQ_HEAD(mount_struct, option_entry) mount_options; /**< Mount options */ + TAILQ_HEAD(mount_struct, option_entry) mount_options; /**< Mount options */ }; int _config_file_parse(const char *path, bool ignore_error, struct config_file *config); @@ -101,18 +103,16 @@ int _config_file_parse_plugin(char *saveptr, struct config_file *config); int _config_file_remove_plugin(char *saveptr, struct config_file *config); int _config_file_parse_option(const char *line, char *saveptr, struct option_entry **out); - int config_file_load(const char *path, struct config_file **config) { int ret; CHECK_ARG_NULL(config, -LTFS_NULL_ARG); - if (! path) - path = LTFS_CONFIG_FILE; + if (!path) path = LTFS_CONFIG_FILE; *config = calloc(1, sizeof(struct config_file)); - if (! (*config)) { + if (!(*config)) { ltfsmsg(LTFS_ERR, 10001E, "config_file_load: config structure"); return -LTFS_NO_MEMORY; } @@ -121,8 +121,7 @@ int config_file_load(const char *path, struct config_file **config) TAILQ_INIT(&(*config)->mount_options); ret = _config_file_parse(path, false, *config); - if (ret < 0) - goto out; + if (ret < 0) goto out; ret = _config_file_validate(*config); @@ -140,19 +139,22 @@ void config_file_free(struct config_file *config) struct option_entry *opt_entry, *opt_aux; if (config) { - TAILQ_FOREACH_SAFE(plug_entry, &config->plugins, list, plug_aux) { + TAILQ_FOREACH_SAFE(plug_entry, &config->plugins, list, plug_aux) + { free(plug_entry->type); free(plug_entry->name); free(plug_entry->library); free(plug_entry); } - TAILQ_FOREACH_SAFE(plug_entry, &config->default_plugins, list, plug_aux) { + TAILQ_FOREACH_SAFE(plug_entry, &config->default_plugins, list, plug_aux) + { free(plug_entry->type); free(plug_entry->name); /* plug_entry->library is always NULL */ free(plug_entry); } - TAILQ_FOREACH_SAFE(opt_entry, &config->mount_options, list, opt_aux) { + TAILQ_FOREACH_SAFE(opt_entry, &config->mount_options, list, opt_aux) + { free(opt_entry->type); free(opt_entry->option); free(opt_entry); @@ -168,9 +170,9 @@ const char *config_file_get_default_plugin(const char *type, struct config_file CHECK_ARG_NULL(type, NULL); CHECK_ARG_NULL(config, NULL); - TAILQ_FOREACH(entry, &config->default_plugins, list) { - if (! strcmp(entry->type, type)) - return entry->name; + TAILQ_FOREACH(entry, &config->default_plugins, list) + { + if (!strcmp(entry->type, type)) return entry->name; } return NULL; @@ -184,9 +186,9 @@ const char *config_file_get_lib(const char *type, const char *name, struct confi CHECK_ARG_NULL(name, NULL); CHECK_ARG_NULL(config, NULL); - TAILQ_FOREACH(entry, &config->plugins, list) { - if (! strcmp(entry->type, type) && ! strcmp(entry->name, name)) - return entry->library; + TAILQ_FOREACH(entry, &config->plugins, list) + { + if (!strcmp(entry->type, type) && !strcmp(entry->name, name)) return entry->library; } ltfsmsg(LTFS_ERR, 11267E, type, name); @@ -201,21 +203,21 @@ char **config_file_get_plugins(const char *type, struct config_file *config) struct plugin_entry *entry; TAILQ_FOREACH(entry, &config->plugins, list) - if (! strcmp(entry->type, type)) - ++count; + if (!strcmp(entry->type, type)) ++count; list = calloc(count + 1, sizeof(char *)); - if (! list) { + if (!list) { ltfsmsg(LTFS_ERR, 10001E, "config_file_get_plugins: pointer list"); return NULL; } - TAILQ_FOREACH(entry, &config->plugins, list) { - if (! strcmp(entry->type, type)) { + TAILQ_FOREACH(entry, &config->plugins, list) + { + if (!strcmp(entry->type, type)) { list[pos] = arch_strdup(entry->name); - if (! list[pos]) { + if (!list[pos]) { ltfsmsg(LTFS_ERR, 10001E, "config_file_get_plugins: list entry"); - for (count=0; countmount_options, list) - if (! strcmp(entry->type, type)) - ++count; + if (!strcmp(entry->type, type)) ++count; list = calloc(count + 1, sizeof(char *)); - if (! list) { + if (!list) { ltfsmsg(LTFS_ERR, 10001E, "config_file_get_options: pointer list"); return NULL; } - TAILQ_FOREACH(entry, &config->mount_options, list) { - if (! strcmp(entry->type, type)) { + TAILQ_FOREACH(entry, &config->mount_options, list) + { + if (!strcmp(entry->type, type)) { list[pos] = arch_strdup(entry->option); - if (! list[pos]) { + if (!list[pos]) { ltfsmsg(LTFS_ERR, 10001E, "config_file_get_options: list entry"); goto out_free; } @@ -257,7 +259,7 @@ char **config_file_get_options(const char *type, struct config_file *config) return list; out_free: - for (count=0; count line && - (*(strip_pos - 1) == ' ' || *(strip_pos - 1) == '\t' || - *(strip_pos - 1) == '\r' || *(strip_pos - 1) == '\n')) - --strip_pos; + if (!strip_pos) strip_pos = line + strlen(line); + while (strip_pos > line && (*(strip_pos - 1) == ' ' || *(strip_pos - 1) == '\t' || *(strip_pos - 1) == '\r' || + *(strip_pos - 1) == '\n')) + --strip_pos; *strip_pos = '\0'; saveline = arch_strdup(line); - if (! saveline) { + if (!saveline) { ltfsmsg(LTFS_ERR, 10001E, "_config_file_parse: saveline"); ret = -LTFS_NO_MEMORY; goto out; @@ -315,50 +315,42 @@ int _config_file_parse(const char *path, bool ignore_error, struct config_file * /* Parse the configuration directive */ tok = strtok_r(line, " \t\r\n", &saveptr); if (tok) { - if (! strcmp(tok, "plugin")) { + if (!strcmp(tok, "plugin")) { ret = _config_file_parse_plugin(saveptr, config); - if (ret < 0) - goto out; + if (ret < 0) goto out; - } else if (! strcmp(tok, "default")) { + } else if (!strcmp(tok, "default")) { ret = _config_file_parse_default(saveptr, config); - if (ret < 0) - goto out; + if (ret < 0) goto out; - } else if (! strcmp(tok, "option")) { + } else if (!strcmp(tok, "option")) { offset = tok - line + strlen(tok) + 1; ret = _config_file_parse_option(&saveline[offset], saveptr, &ol); - if (ret < 0) - goto out; + if (ret < 0) goto out; TAILQ_INSERT_TAIL(&config->mount_options, ol, list); - } else if (! strcmp(tok, "include")) { + } else if (!strcmp(tok, "include")) { ret = _config_file_parse_name("include", "include file", saveptr, &include_file); - if (ret < 0) - goto out; + if (ret < 0) goto out; ret = _config_file_parse(include_file, false, config); free(include_file); include_file = NULL; - if (ret < 0) - goto out; + if (ret < 0) goto out; - } else if (! strcmp(tok, "include_noerror")) { + } else if (!strcmp(tok, "include_noerror")) { ret = _config_file_parse_name("include", "include file", saveptr, &include_file); - if (ret < 0) - goto out; + if (ret < 0) goto out; ret = _config_file_parse(include_file, true, config); free(include_file); include_file = NULL; - } else if (! strcmp(tok, "-default")) { + } else if (!strcmp(tok, "-default")) { ret = _config_file_remove_default(saveptr, config); - if (ret < 0) - goto out; + if (ret < 0) goto out; - } else if (! strcmp(tok, "-plugin")) { + } else if (!strcmp(tok, "-plugin")) { ret = _config_file_remove_plugin(saveptr, config); - if (ret < 0) - goto out; + if (ret < 0) goto out; } else ltfsmsg(LTFS_WARN, 11276W, tok); @@ -371,8 +363,7 @@ int _config_file_parse(const char *path, bool ignore_error, struct config_file * ret = 0; out: - if (saveline) - free(saveline); + if (saveline) free(saveline); fclose(conf_file); return ret; } @@ -390,22 +381,23 @@ int _config_file_validate(struct config_file *config) /* Validate plugin configuration. For each configured plugin, return an error if the configured * default plugin is not in the list of known plugins. */ - TAILQ_FOREACH(de, &config->default_plugins, list) { + TAILQ_FOREACH(de, &config->default_plugins, list) + { found = false; - TAILQ_FOREACH(pe, &config->plugins, list) { - if (! strcmp(de->type, pe->type) && ! strcmp(de->name, pe->name)) - found = true; + TAILQ_FOREACH(pe, &config->plugins, list) + { + if (!strcmp(de->type, pe->type) && !strcmp(de->name, pe->name)) found = true; } - if (! found && strcmp(de->name, "none")) { + if (!found && strcmp(de->name, "none")) { ltfsmsg(LTFS_ERR, 11280E, de->type, de->name); return -LTFS_CONFIG_INVALID; } } /* Emit a warning if plugin library does not exist. */ - TAILQ_FOREACH(pe, &config->plugins, list) { - if (stat(pe->library, &st) < 0) - ltfsmsg(LTFS_WARN, 11277W, pe->type, pe->name, pe->library); + TAILQ_FOREACH(pe, &config->plugins, list) + { + if (stat(pe->library, &st) < 0) ltfsmsg(LTFS_WARN, 11277W, pe->type, pe->name, pe->library); } return 0; @@ -435,12 +427,12 @@ int _config_file_parse_name(const char *directive, const char *name_desc, char * #else tok = strtok_r(NULL, " \t\r\n", &saveptr); #endif - if (! tok) { + if (!tok) { ltfsmsg(LTFS_ERR, 11273E, directive, name_desc); return -LTFS_CONFIG_INVALID; } *out = arch_strdup(tok); - if (! (*out)) { + if (!(*out)) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } @@ -471,27 +463,27 @@ int _config_file_parse_default(char *saveptr, struct config_file *config) /* Read the plugin type */ tok = strtok_r(NULL, " \t\r\n", &saveptr); - if (! tok) { + if (!tok) { ltfsmsg(LTFS_ERR, 11265E); return -LTFS_CONFIG_INVALID; } type = arch_strdup(tok); - if (! type) { + if (!type) { ltfsmsg(LTFS_ERR, 10001E, "_config_file_parse_default: plugin type"); return -LTFS_NO_MEMORY; } /* Read the plugin name */ tok = strtok_r(NULL, " \t\r\n", &saveptr); - if (! tok) { + if (!tok) { ltfsmsg(LTFS_ERR, 11265E); free(type); return -LTFS_CONFIG_INVALID; } name = arch_strdup(tok); - if (! name) { + if (!name) { ltfsmsg(LTFS_ERR, 10001E, "_config_file_parse_default: plugin name"); free(type); return -LTFS_NO_MEMORY; @@ -507,8 +499,9 @@ int _config_file_parse_default(char *saveptr, struct config_file *config) } /* Store the default */ - TAILQ_FOREACH(entry, &config->default_plugins, list) { - if (! strcmp(entry->type, type)) { + TAILQ_FOREACH(entry, &config->default_plugins, list) + { + if (!strcmp(entry->type, type)) { free(entry->name); entry->name = name; free(entry->type); @@ -518,7 +511,7 @@ int _config_file_parse_default(char *saveptr, struct config_file *config) } if (!found) { entry = calloc(1, sizeof(struct plugin_entry)); - if (! entry) { + if (!entry) { ltfsmsg(LTFS_ERR, 10001E, "_config_file_parse_default: plugin entry"); free(name); free(type); @@ -547,13 +540,13 @@ int _config_file_remove_default(char *saveptr, struct config_file *config) /* Read the plugin type */ tok = strtok_r(NULL, " \t\r\n", &saveptr); - if (! tok) { + if (!tok) { ltfsmsg(LTFS_ERR, 11270E); return -LTFS_CONFIG_INVALID; } type = arch_strdup(tok); - if (! type) { + if (!type) { ltfsmsg(LTFS_ERR, 10001E, "_config_file_remove_default: plugin type"); return -LTFS_NO_MEMORY; } @@ -567,8 +560,9 @@ int _config_file_remove_default(char *saveptr, struct config_file *config) } /* Remove the specified default value */ - TAILQ_FOREACH_SAFE(pl, &config->default_plugins, list, aux) { - if (! strcmp(pl->type, type)) { + TAILQ_FOREACH_SAFE(pl, &config->default_plugins, list, aux) + { + if (!strcmp(pl->type, type)) { TAILQ_REMOVE(&config->default_plugins, pl, list); free(pl->type); free(pl->name); @@ -602,14 +596,14 @@ int _config_file_parse_plugin(char *saveptr, struct config_file *config) /* Get the plugin type */ tok = strtok_r(NULL, " \t\r\n", &saveptr); - if (! tok) { + if (!tok) { ltfsmsg(LTFS_ERR, 11275E); ret = -LTFS_CONFIG_INVALID; goto out_free; } type = arch_strdup(tok); - if (! type) { + if (!type) { ltfsmsg(LTFS_ERR, 10001E, "_config_file_parse_plugin: plugin type"); ret = -LTFS_NO_MEMORY; goto out_free; @@ -617,14 +611,14 @@ int _config_file_parse_plugin(char *saveptr, struct config_file *config) /* Get the driver name */ tok = strtok_r(NULL, " \t\r\n", &saveptr); - if (! tok) { + if (!tok) { ltfsmsg(LTFS_ERR, 11275E); ret = -LTFS_CONFIG_INVALID; goto out_free; } name = arch_strdup(tok); - if (! name) { + if (!name) { ltfsmsg(LTFS_ERR, 10001E, "_config_file_parse_plugin: plugin name"); ret = -LTFS_NO_MEMORY; goto out_free; @@ -632,21 +626,22 @@ int _config_file_parse_plugin(char *saveptr, struct config_file *config) /* Get the driver path */ tok = strtok_r(NULL, "\r\n", &saveptr); - if (! tok) { + if (!tok) { ltfsmsg(LTFS_ERR, 11275E); ret = -LTFS_CONFIG_INVALID; goto out_free; } library = arch_strdup(tok); - if (! library) { + if (!library) { ltfsmsg(LTFS_ERR, 10001E, "_config_file_parse_plugin: plugin path"); ret = -LTFS_NO_MEMORY; goto out_free; } - TAILQ_FOREACH(entry, &config->plugins, list) { - if (! strcmp(entry->type, type) && ! strcmp(entry->name, name)) { + TAILQ_FOREACH(entry, &config->plugins, list) + { + if (!strcmp(entry->type, type) && !strcmp(entry->name, name)) { free(type); free(name); free(entry->library); @@ -656,7 +651,7 @@ int _config_file_parse_plugin(char *saveptr, struct config_file *config) } if (!found) { entry = calloc(1, sizeof(struct plugin_entry)); - if (! entry) { + if (!entry) { ltfsmsg(LTFS_ERR, 10001E, "_config_file_parse_plugin: plugin entry"); ret = -LTFS_NO_MEMORY; goto out_free; @@ -670,12 +665,9 @@ int _config_file_parse_plugin(char *saveptr, struct config_file *config) return 0; out_free: - if (type) - free(type); - if (name) - free(name); - if (library) - free(library); + if (type) free(type); + if (name) free(name); + if (library) free(library); return ret; } @@ -694,27 +686,27 @@ int _config_file_remove_plugin(char *saveptr, struct config_file *config) /* Read the plugin type */ tok = strtok_r(NULL, " \t\r\n", &saveptr); - if (! tok) { + if (!tok) { ltfsmsg(LTFS_ERR, 11309E); return -LTFS_CONFIG_INVALID; } type = arch_strdup(tok); - if (! type) { + if (!type) { ltfsmsg(LTFS_ERR, 10001E, "_config_file_remove_plugin: plugin type"); return -LTFS_NO_MEMORY; } /* Read the plugin name */ tok = strtok_r(NULL, " \t\r\n", &saveptr); - if (! tok) { + if (!tok) { ltfsmsg(LTFS_ERR, 11309E); free(type); return -LTFS_CONFIG_INVALID; } name = arch_strdup(tok); - if (! name) { + if (!name) { ltfsmsg(LTFS_ERR, 10001E, "_config_file_remove_plugin: plugin name"); free(type); return -LTFS_NO_MEMORY; @@ -730,8 +722,9 @@ int _config_file_remove_plugin(char *saveptr, struct config_file *config) } /* Remove the specified plugin value */ - TAILQ_FOREACH_SAFE(pl, &config->plugins, list, aux) { - if (! strcmp(pl->type, type) && ! strcmp(pl->name, name)) { + TAILQ_FOREACH_SAFE(pl, &config->plugins, list, aux) + { + if (!strcmp(pl->type, type) && !strcmp(pl->name, name)) { TAILQ_REMOVE(&config->plugins, pl, list); free(pl->type); free(pl->name); @@ -766,7 +759,7 @@ int _config_file_parse_option(const char *line, char *saveptr, struct option_ent /* Read the option type */ tok = strtok_r(NULL, " \t\r\n", &saveptr); - if (! tok) { + if (!tok) { /* Cannot parse configuration file: \'option\' directive must be followed * by a option type and LTFS mount option */ ltfsmsg(LTFS_ERR, 11272E); @@ -775,23 +768,23 @@ int _config_file_parse_option(const char *line, char *saveptr, struct option_ent start = tok; type = arch_strdup(tok); - if (! type) { + if (!type) { ltfsmsg(LTFS_ERR, 10001E, "_config_file_parse_mount_option: option"); return -LTFS_NO_MEMORY; } - if (! strcmp(type, "adminservice")) + if (!strcmp(type, "adminservice")) is_admin_service = true; - else if (! strcmp(type, "dcache")) + else if (!strcmp(type, "dcache")) is_dcache = true; - else if (! strcmp(type, "startup")) + else if (!strcmp(type, "startup")) is_startup = true; - else if (! strcmp(type, "snmp")) + else if (!strcmp(type, "snmp")) is_snmp = true; /* Read the option */ tok = strtok_r(NULL, " \t\r\n", &saveptr); - if (! tok) { + if (!tok) { /* Cannot parse configuration file: \'option\' directive must be followed * by a LTFS mount option */ ltfsmsg(LTFS_ERR, 11272E); @@ -799,10 +792,10 @@ int _config_file_parse_option(const char *line, char *saveptr, struct option_ent return -LTFS_CONFIG_INVALID; } - if (is_admin_service || is_dcache || is_startup || line[tok-start] == '-' || is_snmp) - ret = asprintf(&option, "%s", &line[tok-start]); + if (is_admin_service || is_dcache || is_startup || line[tok - start] == '-' || is_snmp) + ret = asprintf(&option, "%s", &line[tok - start]); else - ret = asprintf(&option, "-o%s", &line[tok-start]); + ret = asprintf(&option, "-o%s", &line[tok - start]); if (ret < 0) { ltfsmsg(LTFS_ERR, 10001E, "_config_file_parse_mount_option: option"); free(type); @@ -810,7 +803,7 @@ int _config_file_parse_option(const char *line, char *saveptr, struct option_ent } *out = calloc(1, sizeof(struct option_entry)); - if (! (*out)) { + if (!(*out)) { ltfsmsg(LTFS_ERR, 10001E, "_config_file_parse_plugin: plugin structure"); free(type); free(option); diff --git a/src/libltfs/dcache.c b/src/libltfs/dcache.c index c759bae5..cf29f77d 100644 --- a/src/libltfs/dcache.c +++ b/src/libltfs/dcache.c @@ -50,11 +50,12 @@ #include "dcache.h" -struct dcache_priv { - void *dlopen_handle; /**< Handle returned from dlopen */ - struct libltfs_plugin *plugin; /**< Reference to the plugin */ - struct dcache_ops *ops; /**< Dentry cache manager operations */ - void *backend_handle; /**< Backend private data */ +struct dcache_priv +{ + void *dlopen_handle; /**< Handle returned from dlopen */ + struct libltfs_plugin *plugin; /**< Reference to the plugin */ + struct dcache_ops *ops; /**< Dentry cache manager operations */ + void *backend_handle; /**< Backend private data */ }; /** @@ -65,8 +66,7 @@ struct dcache_priv { * structure. On failure a negative value is returned. */ -int dcache_init(struct libltfs_plugin *plugin, const struct dcache_options *options, - struct ltfs_volume *vol) +int dcache_init(struct libltfs_plugin *plugin, const struct dcache_options *options, struct ltfs_volume *vol) { struct dcache_priv *priv; unsigned int i; @@ -75,7 +75,7 @@ int dcache_init(struct libltfs_plugin *plugin, const struct dcache_options *opti CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); priv = calloc(1, sizeof(struct dcache_priv)); - if (! priv) { + if (!priv) { ltfsmsg(LTFS_ERR, 10001E, "dcache_init: private data"); return -LTFS_NO_MEMORY; } @@ -84,7 +84,7 @@ int dcache_init(struct libltfs_plugin *plugin, const struct dcache_options *opti priv->ops = plugin->ops; /* Verify that backend implements all required operations */ - for (i=0; iops))[i] == NULL) { /* Dentry cache backend does not implement all required methods */ ltfsmsg(LTFS_ERR, 13004E); @@ -94,7 +94,7 @@ int dcache_init(struct libltfs_plugin *plugin, const struct dcache_options *opti } priv->backend_handle = priv->ops->init(options, vol); - if (! priv->backend_handle) { + if (!priv->backend_handle) { free(priv); return -1; } @@ -116,7 +116,7 @@ int dcache_init(struct libltfs_plugin *plugin, const struct dcache_options *opti */ int dcache_destroy(struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; int ret; CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); @@ -149,33 +149,33 @@ int dcache_parse_options(const char **options, struct dcache_options **out) *out = NULL; opt = calloc(1, sizeof(struct dcache_options)); - if (! opt) { + if (!opt) { ltfsmsg(LTFS_ERR, 10001E, "dcache_parse_options: opt"); return -ENOMEM; } - for (i=0; options[i]; ++i) { + for (i = 0; options[i]; ++i) { line = arch_strdup(options[i]); - if (! line) { + if (!line) { ltfsmsg(LTFS_ERR, 10001E, "dcache_parse_options: line"); ret = -ENOMEM; goto out_free; } char *contextVal = NULL; option = arch_strtok(line, " \t", contextVal); - if (! option) { + if (!option) { /* Failed to parse LTFS dcache configuration rules: invalid option '%s' */ ltfsmsg(LTFS_ERR, 17170E, options[i]); ret = -EINVAL; goto out_free; } - if (! strcmp(option, "enabled")) { + if (!strcmp(option, "enabled")) { opt->enabled = true; free(line); line = NULL; continue; - } else if (! strcmp(option, "disabled")) { + } else if (!strcmp(option, "disabled")) { opt->enabled = false; free(line); line = NULL; @@ -183,14 +183,14 @@ int dcache_parse_options(const char **options, struct dcache_options **out) } value = arch_strtok(NULL, " \t", contextVal); - if (! value) { + if (!value) { /* Failed to parse LTFS dcache configuration rules: invalid option '%s' */ ltfsmsg(LTFS_ERR, 17170E, options[i]); ret = -EINVAL; goto out_free; } - if (! strcmp(option, "minsize")) { + if (!strcmp(option, "minsize")) { opt->minsize = atoi(value); if (opt->minsize <= 0) { /* Failed to parse LTFS dcache configuration rules: invalid value '%d' for option '%s' */ @@ -198,7 +198,7 @@ int dcache_parse_options(const char **options, struct dcache_options **out) ret = -EINVAL; goto out_free; } - } else if (! strcmp(option, "maxsize")) { + } else if (!strcmp(option, "maxsize")) { opt->maxsize = atoi(value); if (opt->maxsize <= 0) { /* Failed to parse LTFS dcache configuration rules: invalid value '%d' for option '%s' */ @@ -220,10 +220,8 @@ int dcache_parse_options(const char **options, struct dcache_options **out) *out = opt; out_free: - if (ret != 0 && opt) - dcache_free_options(&opt); - if (line) - free(line); + if (ret != 0 && opt) dcache_free_options(&opt); + if (line) free(line); return ret; } @@ -246,7 +244,7 @@ void dcache_free_options(struct dcache_options **options) */ bool dcache_initialized(struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; bool assigned = false; CHECK_ARG_NULL(vol, false); @@ -268,7 +266,7 @@ bool dcache_initialized(struct ltfs_volume *vol) */ int dcache_mkcache(const char *name, struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(name, -LTFS_NULL_ARG); CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); @@ -287,7 +285,7 @@ int dcache_mkcache(const char *name, struct ltfs_volume *vol) */ int dcache_rmcache(const char *name, struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(name, -LTFS_NULL_ARG); CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); @@ -308,7 +306,7 @@ int dcache_rmcache(const char *name, struct ltfs_volume *vol) */ int dcache_cache_exists(const char *name, bool *exists, struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(name, -LTFS_NULL_ARG); CHECK_ARG_NULL(exists, -LTFS_NULL_ARG); @@ -328,7 +326,7 @@ int dcache_cache_exists(const char *name, bool *exists, struct ltfs_volume *vol) */ int dcache_set_workdir(const char *workdir, bool clean, struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(workdir, -LTFS_NULL_ARG); CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); @@ -347,7 +345,7 @@ int dcache_set_workdir(const char *workdir, bool clean, struct ltfs_volume *vol) */ int dcache_get_workdir(char **workdir, struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(workdir, -LTFS_NULL_ARG); CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); @@ -366,7 +364,7 @@ int dcache_get_workdir(char **workdir, struct ltfs_volume *vol) */ int dcache_assign_name(const char *name, struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(name, -LTFS_NULL_ARG); CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); @@ -385,7 +383,7 @@ int dcache_assign_name(const char *name, struct ltfs_volume *vol) */ int dcache_unassign_name(struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); CHECK_ARG_NULL(vol->index, -LTFS_NULL_ARG); @@ -403,7 +401,7 @@ int dcache_unassign_name(struct ltfs_volume *vol) */ int dcache_wipe_dentry_tree(struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); CHECK_ARG_NULL(vol->index->root, -LTFS_NULL_ARG); @@ -422,9 +420,9 @@ int dcache_wipe_dentry_tree(struct ltfs_volume *vol) * @param vol LTFS volume of the cartridge. Must have been initialized with dcache_init(). * @return 0 to indicate success or a negative value on error. */ -int dcache_get_vol_uuid(const char *work_dir, const char *barcode, char **uuid, struct ltfs_volume *vol) +int dcache_get_vol_uuid(const char *work_dir, const char *barcode, char **uuid, struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(uuid, -LTFS_NULL_ARG); CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); @@ -443,7 +441,7 @@ int dcache_get_vol_uuid(const char *work_dir, const char *barcode, char **uuid, */ int dcache_set_vol_uuid(char *uuid, struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(uuid, -LTFS_NULL_ARG); CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); @@ -464,7 +462,7 @@ int dcache_set_vol_uuid(char *uuid, struct ltfs_volume *vol) */ int dcache_get_generation(const char *work_dir, const char *barcode, unsigned int *gen, struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(gen, -LTFS_NULL_ARG); CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); @@ -483,7 +481,7 @@ int dcache_get_generation(const char *work_dir, const char *barcode, unsigned in */ int dcache_set_generation(unsigned int gen, struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); CHECK_ARG_NULL(priv, -LTFS_NULL_ARG); @@ -503,7 +501,7 @@ int dcache_set_generation(unsigned int gen, struct ltfs_volume *vol) */ int dcache_get_dirty(const char *work_dir, const char *barcode, bool *dirty, struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(dirty, -LTFS_NULL_ARG); CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); @@ -523,7 +521,7 @@ int dcache_get_dirty(const char *work_dir, const char *barcode, bool *dirty, str */ int dcache_set_dirty(bool dirty, struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); CHECK_ARG_NULL(priv, -LTFS_NULL_ARG); @@ -540,7 +538,7 @@ int dcache_set_dirty(bool dirty, struct ltfs_volume *vol) */ int dcache_diskimage_create(struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); CHECK_ARG_NULL(priv, -LTFS_NULL_ARG); @@ -557,7 +555,7 @@ int dcache_diskimage_create(struct ltfs_volume *vol) */ int dcache_diskimage_remove(struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); CHECK_ARG_NULL(priv, -LTFS_NULL_ARG); @@ -574,7 +572,7 @@ int dcache_diskimage_remove(struct ltfs_volume *vol) */ int dcache_diskimage_mount(struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); CHECK_ARG_NULL(priv, -LTFS_NULL_ARG); @@ -591,7 +589,7 @@ int dcache_diskimage_mount(struct ltfs_volume *vol) */ int dcache_diskimage_unmount(struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); CHECK_ARG_NULL(priv, -LTFS_NULL_ARG); @@ -603,7 +601,7 @@ int dcache_diskimage_unmount(struct ltfs_volume *vol) bool dcache_diskimage_is_full(struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); CHECK_ARG_NULL(priv, -LTFS_NULL_ARG); @@ -615,7 +613,7 @@ bool dcache_diskimage_is_full(struct ltfs_volume *vol) int dcache_get_advisory_lock(const char *name, struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(name, -LTFS_NULL_ARG); CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); @@ -628,7 +626,7 @@ int dcache_get_advisory_lock(const char *name, struct ltfs_volume *vol) int dcache_put_advisory_lock(const char *name, struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(name, -LTFS_NULL_ARG); CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); @@ -641,7 +639,7 @@ int dcache_put_advisory_lock(const char *name, struct ltfs_volume *vol) int dcache_open(const char *path, struct dentry **d, struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(path, -LTFS_NULL_ARG); CHECK_ARG_NULL(d, -LTFS_NULL_ARG); @@ -655,7 +653,7 @@ int dcache_open(const char *path, struct dentry **d, struct ltfs_volume *vol) int dcache_close(struct dentry *d, bool lock_meta, bool descend, struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(d, -LTFS_NULL_ARG); CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); @@ -668,7 +666,7 @@ int dcache_close(struct dentry *d, bool lock_meta, bool descend, struct ltfs_vol int dcache_create(const char *path, struct dentry *d, struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(path, -LTFS_NULL_ARG); CHECK_ARG_NULL(d, -LTFS_NULL_ARG); @@ -682,7 +680,7 @@ int dcache_create(const char *path, struct dentry *d, struct ltfs_volume *vol) int dcache_unlink(const char *path, struct dentry *d, struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(path, -LTFS_NULL_ARG); CHECK_ARG_NULL(d, -LTFS_NULL_ARG); @@ -694,10 +692,9 @@ int dcache_unlink(const char *path, struct dentry *d, struct ltfs_volume *vol) return priv->ops->unlink(path, d, priv->backend_handle); } -int dcache_rename(const char *oldpath, const char *newpath, struct dentry **old_dentry, - struct ltfs_volume *vol) +int dcache_rename(const char *oldpath, const char *newpath, struct dentry **old_dentry, struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(oldpath, -LTFS_NULL_ARG); CHECK_ARG_NULL(newpath, -LTFS_NULL_ARG); @@ -712,14 +709,14 @@ int dcache_rename(const char *oldpath, const char *newpath, struct dentry **old_ int dcache_flush(struct dentry *d, enum dcache_flush_flags flags, struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); CHECK_ARG_NULL(priv, -LTFS_NULL_ARG); CHECK_ARG_NULL(priv->ops, -LTFS_NULL_ARG); CHECK_ARG_NULL(priv->ops->flush, -LTFS_NULL_ARG); - if (! d) { + if (!d) { /* The I/O scheduler handles NULL dentries in a special case. We just need to ignore them. */ return 0; } @@ -728,7 +725,7 @@ int dcache_flush(struct dentry *d, enum dcache_flush_flags flags, struct ltfs_vo int dcache_readdir(struct dentry *d, bool dentries, void ***result, struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(d, -LTFS_NULL_ARG); CHECK_ARG_NULL(result, -LTFS_NULL_ARG); @@ -740,9 +737,9 @@ int dcache_readdir(struct dentry *d, bool dentries, void ***result, struct ltfs_ return priv->ops->readdir(d, dentries, result, priv->backend_handle); } -int dcache_read_direntry(struct dentry *d, struct ltfs_direntry *dirent, unsigned long index, struct ltfs_volume *vol) +int dcache_read_direntry(struct dentry *d, struct ltfs_direntry *dirent, unsigned long index, struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(d, -LTFS_NULL_ARG); CHECK_ARG_NULL(dirent, -LTFS_NULL_ARG); @@ -756,7 +753,7 @@ int dcache_read_direntry(struct dentry *d, struct ltfs_direntry *dirent, unsigne int dcache_get_dentry(struct dentry *d, struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(d, -LTFS_NULL_ARG); CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); @@ -769,7 +766,7 @@ int dcache_get_dentry(struct dentry *d, struct ltfs_volume *vol) int dcache_put_dentry(struct dentry *d, struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(d, -LTFS_NULL_ARG); CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); @@ -780,10 +777,10 @@ int dcache_put_dentry(struct dentry *d, struct ltfs_volume *vol) return priv->ops->put_dentry(d, priv->backend_handle); } -int dcache_openat(const char *parent_path, struct dentry *parent, const char *name, - struct dentry **result, struct ltfs_volume *vol) +int dcache_openat( + const char *parent_path, struct dentry *parent, const char *name, struct dentry **result, struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(parent_path, -LTFS_NULL_ARG); CHECK_ARG_NULL(parent, -LTFS_NULL_ARG); @@ -797,10 +794,15 @@ int dcache_openat(const char *parent_path, struct dentry *parent, const char *na return priv->ops->openat(parent_path, parent, name, result, priv->backend_handle); } -int dcache_setxattr(const char *path, struct dentry *d, const char *xattr, const char *value, - size_t size, int flags, struct ltfs_volume *vol) +int dcache_setxattr(const char *path, + struct dentry *d, + const char *xattr, + const char *value, + size_t size, + int flags, + struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(path, -LTFS_NULL_ARG); CHECK_ARG_NULL(d, -LTFS_NULL_ARG); @@ -814,10 +816,9 @@ int dcache_setxattr(const char *path, struct dentry *d, const char *xattr, const return priv->ops->setxattr(path, d, xattr, value, size, flags, priv->backend_handle); } -int dcache_removexattr(const char *path, struct dentry *d, const char *xattr, - struct ltfs_volume *vol) +int dcache_removexattr(const char *path, struct dentry *d, const char *xattr, struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(path, -LTFS_NULL_ARG); CHECK_ARG_NULL(d, -LTFS_NULL_ARG); @@ -830,10 +831,9 @@ int dcache_removexattr(const char *path, struct dentry *d, const char *xattr, return priv->ops->removexattr(path, d, xattr, priv->backend_handle); } -int dcache_listxattr(const char *path, struct dentry *d, char *list, size_t size, - struct ltfs_volume *vol) +int dcache_listxattr(const char *path, struct dentry *d, char *list, size_t size, struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(path, -LTFS_NULL_ARG); CHECK_ARG_NULL(d, -LTFS_NULL_ARG); @@ -845,10 +845,10 @@ int dcache_listxattr(const char *path, struct dentry *d, char *list, size_t size return priv->ops->listxattr(path, d, list, size, priv->backend_handle); } -int dcache_getxattr(const char *path, struct dentry *d, const char *name, - void *value, size_t size, struct ltfs_volume *vol) +int dcache_getxattr( + const char *path, struct dentry *d, const char *name, void *value, size_t size, struct ltfs_volume *vol) { - struct dcache_priv *priv = (struct dcache_priv *) vol ? vol->dcache_handle : NULL; + struct dcache_priv *priv = (struct dcache_priv *)vol ? vol->dcache_handle : NULL; CHECK_ARG_NULL(path, -LTFS_NULL_ARG); CHECK_ARG_NULL(d, -LTFS_NULL_ARG); diff --git a/src/libltfs/fs.c b/src/libltfs/fs.c index 790438d5..6c9df666 100644 --- a/src/libltfs/fs.c +++ b/src/libltfs/fs.c @@ -52,61 +52,66 @@ */ #ifdef mingw_PLATFORM -#include "arch/win/win_util.h" +# include "arch/win/win_util.h" #else -#include +# include #endif - #include -#include "libltfs/ltfslogging.h" -#include "pathname.h" #include "arch/filename_handling.h" #include "dcache.h" #include "fs.h" +#include "libltfs/ltfslogging.h" +#include "pathname.h" -#define TRUNCATE_STRING(end) do { if ((end)) *(end) = '\0'; } while(0) -#define RESTORE_STRING(end) do { if ((end)) *(end) = '/'; } while(0) +#define TRUNCATE_STRING(end) \ + do { \ + if ((end)) *(end) = '\0'; \ + } while (0) +#define RESTORE_STRING(end) \ + do { \ + if ((end)) *(end) = '/'; \ + } while (0) int fs_hash_sort_by_uid(struct name_list *a, struct name_list *b) { return (a->uid - b->uid); } -static char* generate_hash_key_name(const char *src_str, int *rc) +static char *generate_hash_key_name(const char *src_str, int *rc) { char *key_name = NULL; #ifdef mingw_PLATFORM UChar *uchar_name; - *rc = pathname_prepare_caseless(src_str, &uchar_name, true); // malloc is called in this function + *rc = pathname_prepare_caseless(src_str, &uchar_name, true); // malloc is called in this function if (*rc == 0) { - *rc = _pathname_utf16_to_utf8_icu(uchar_name, &key_name); // malloc is called in this funcation + *rc = _pathname_utf16_to_utf8_icu(uchar_name, &key_name); // malloc is called in this funcation } if (*rc != 0) { key_name = NULL; - } else{ + } else { arch_safe_free(uchar_name); - } + } #else key_name = arch_strdup(src_str); - if (key_name){ + if (key_name) { *rc = 0; - }else{ + } else { *rc = -LTFS_NO_MEMORY; - } + } #endif return key_name; } -struct name_list* fs_add_key_to_hash_table(struct name_list *list, struct dentry *add_entry, int *rc) +struct name_list *fs_add_key_to_hash_table(struct name_list *list, struct dentry *add_entry, int *rc) { struct name_list *new_list = NULL; - new_list = (struct name_list *) malloc(sizeof(struct name_list)); + new_list = (struct name_list *)malloc(sizeof(struct name_list)); if (!new_list) { ltfsmsg(LTFS_ERR, 10001E, "fs_add_key_to_hash_table: new list"); *rc = -LTFS_NO_MEMORY; @@ -115,7 +120,7 @@ struct name_list* fs_add_key_to_hash_table(struct name_list *list, struct dentry new_list->name = generate_hash_key_name(add_entry->platform_safe_name, rc); - if (*rc == 0 && new_list->name != NULL) { + if (*rc == 0 && new_list->name != NULL) { errno = 0; new_list->d = add_entry; new_list->uid = add_entry->uid; @@ -129,7 +134,7 @@ struct name_list* fs_add_key_to_hash_table(struct name_list *list, struct dentry return list; } -struct name_list* fs_find_key_from_hash_table(struct name_list *list, const char *name, int *rc) +struct name_list *fs_find_key_from_hash_table(struct name_list *list, const char *name, int *rc) { struct name_list *result; char *key_name; @@ -137,8 +142,7 @@ struct name_list* fs_find_key_from_hash_table(struct name_list *list, const char key_name = generate_hash_key_name(name, rc); if (key_name != NULL) { HASH_FIND_STR(list, key_name, result); - } - else { + } else { result = NULL; } @@ -183,8 +187,7 @@ int fs_init_inode(void) int ret; ret = ltfs_mutex_init(&inode_mutex); - if (ret) - ltfsmsg(LTFS_ERR, 10002E, ret); + if (ret) ltfsmsg(LTFS_ERR, 10002E, ret); return ret; } @@ -200,9 +203,9 @@ bool fs_is_percent_encode_required(const char *name) if (name) { len = strlen(name); - for (i=0; i=0 && name[i]<=0x1F && name[i]!=0x09 && name[i]!=0x0A && name[i]!=0x0D)) { + for (i = 0; i < len; i++) { + if (name[i] == 0x3A || + (name[i] >= 0 && name[i] <= 0x1F && name[i] != 0x09 && name[i] != 0x0A && name[i] != 0x0D)) { need_encode = true; break; } @@ -217,8 +220,7 @@ bool fs_is_percent_encode_required(const char *name) */ void fs_clear_nametype(struct ltfs_name *name) { - if (name->name) - free(name->name); + if (name->name) free(name->name); name->percent_encode = false; name->name = NULL; @@ -250,14 +252,19 @@ void fs_set_nametype(struct ltfs_name *name, char *str) * @return the new allocated object, or NULL on failure. If a previous entry has been already * allocated for this object, a pointer to that object is returned instead. */ -struct dentry * fs_allocate_dentry(struct dentry *parent, const char *name, const char *platform_safe_name, - bool isdir, bool readonly, bool allocate_uid, struct ltfs_index *idx) +struct dentry *fs_allocate_dentry(struct dentry *parent, + const char *name, + const char *platform_safe_name, + bool isdir, + bool readonly, + bool allocate_uid, + struct ltfs_index *idx) { int ret; struct dentry *d = NULL; - d = (struct dentry *) malloc(sizeof(struct dentry)); - if (! d) { + d = (struct dentry *)malloc(sizeof(struct dentry)); + if (!d) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return NULL; } @@ -270,24 +277,20 @@ struct dentry * fs_allocate_dentry(struct dentry *parent, const char *name, cons } else if (name && !platform_safe_name) { d->name.name = arch_strdup(name); update_platform_safe_name(d, false, idx); - if (! d->name.name || ! d->platform_safe_name) { + if (!d->name.name || !d->platform_safe_name) { ltfsmsg(LTFS_ERR, 10001E, "fs_allocate_dentry: name"); - if (d->name.name) - free(d->name.name); - if (d->platform_safe_name) - free(d->platform_safe_name); + if (d->name.name) free(d->name.name); + if (d->platform_safe_name) free(d->platform_safe_name); free(d); return NULL; } - } else if(!name && platform_safe_name) { + } else if (!name && platform_safe_name) { d->name.name = arch_strdup(platform_safe_name); d->platform_safe_name = arch_strdup(platform_safe_name); - if (! d->name.name || ! d->platform_safe_name) { + if (!d->name.name || !d->platform_safe_name) { ltfsmsg(LTFS_ERR, 10001E, "fs_allocate_dentry: name"); - if (d->name.name) - free(d->name.name); - if (d->platform_safe_name) - free(d->platform_safe_name); + if (d->name.name) free(d->name.name); + if (d->platform_safe_name) free(d->platform_safe_name); free(d); return NULL; } @@ -296,12 +299,10 @@ struct dentry * fs_allocate_dentry(struct dentry *parent, const char *name, cons be NULL. The codes below are just in case. */ d->name.name = arch_strdup(name); d->platform_safe_name = arch_strdup(platform_safe_name); - if (! d->name.name || ! d->platform_safe_name) { + if (!d->name.name || !d->platform_safe_name) { ltfsmsg(LTFS_ERR, 10001E, "fs_allocate_dentry: name"); - if (d->name.name) - free(d->name.name); - if (d->platform_safe_name) - free(d->platform_safe_name); + if (d->name.name) free(d->name.name); + if (d->platform_safe_name) free(d->platform_safe_name); free(d); return NULL; } @@ -312,8 +313,7 @@ struct dentry * fs_allocate_dentry(struct dentry *parent, const char *name, cons d->link_count = 0; d->name.percent_encode = fs_is_percent_encode_required(d->name.name); - if (isdir) - ++d->link_count; + if (isdir) ++d->link_count; ltfs_mutex_lock(&inode_mutex); d->ino = ++inode_number; ltfs_mutex_unlock(&inode_mutex); @@ -323,20 +323,16 @@ struct dentry * fs_allocate_dentry(struct dentry *parent, const char *name, cons d->uid = 1; /* When allocating root directory, use default UID */ if (d->uid == 0) { /* UID allocation failed because the UID space overflowed. Refuse to create a new file. */ - if (d->name.name) - free(d->name.name); - if (d->platform_safe_name) - free(d->platform_safe_name); + if (d->name.name) free(d->name.name); + if (d->platform_safe_name) free(d->platform_safe_name); free(d); return NULL; } ret = init_mrsw(&d->contents_lock); if (ret < 0) { ltfsmsg(LTFS_ERR, 10002E, ret); - if (d->name.name) - free(d->name.name); - if (d->platform_safe_name) - free(d->platform_safe_name); + if (d->name.name) free(d->name.name); + if (d->platform_safe_name) free(d->platform_safe_name); free(d); return NULL; } @@ -344,14 +340,12 @@ struct dentry * fs_allocate_dentry(struct dentry *parent, const char *name, cons if (ret < 0) { ltfsmsg(LTFS_ERR, 10002E, ret); destroy_mrsw(&d->contents_lock); - if (d->name.name) - free(d->name.name); - if (d->platform_safe_name) - free(d->platform_safe_name); + if (d->name.name) free(d->name.name); + if (d->platform_safe_name) free(d->platform_safe_name); free(d); return NULL; } - d->child_list=NULL; + d->child_list = NULL; TAILQ_INIT(&d->extentlist); TAILQ_INIT(&d->xattrlist); @@ -360,10 +354,8 @@ struct dentry * fs_allocate_dentry(struct dentry *parent, const char *name, cons ltfsmsg(LTFS_ERR, 10002E, ret); destroy_mrsw(&d->contents_lock); destroy_mrsw(&d->meta_lock); - if (d->name.name) - free(d->name.name); - if (d->platform_safe_name) - free(d->platform_safe_name); + if (d->name.name) free(d->name.name); + if (d->platform_safe_name) free(d->platform_safe_name); free(d); return NULL; } @@ -380,10 +372,8 @@ struct dentry * fs_allocate_dentry(struct dentry *parent, const char *name, cons ltfsmsg(LTFS_ERR, 11319E, "fs_allocate_dentry", ret); releasewrite_mrsw(&parent->meta_lock); releasewrite_mrsw(&parent->contents_lock); - if (d->name.name) - free(d->name.name); - if (d->platform_safe_name) - free(d->platform_safe_name); + if (d->name.name) free(d->name.name); + if (d->platform_safe_name) free(d->platform_safe_name); free(d); return NULL; } @@ -391,12 +381,10 @@ struct dentry * fs_allocate_dentry(struct dentry *parent, const char *name, cons /* The volume initialization assumes that the parent data has been set before */ d->vol = parent->vol; d->link_count++; - if (isdir) - parent->link_count++; + if (isdir) parent->link_count++; releasewrite_mrsw(&parent->meta_lock); releasewrite_mrsw(&parent->contents_lock); - if (! isdir) - fs_increment_file_count(idx); + if (!isdir) fs_increment_file_count(idx); } return d; @@ -415,8 +403,7 @@ uint64_t fs_allocate_uid(struct ltfs_index *idx) uid = 0; else { uid = ++idx->uid_number; - if (uid == 0) - ltfsmsg(LTFS_WARN, 11307W, idx->vol_uuid); + if (uid == 0) ltfsmsg(LTFS_WARN, 11307W, idx->vol_uuid); } ltfs_mutex_unlock(&idx->dirty_lock); @@ -436,23 +423,22 @@ int fs_dentry_lookup(struct dentry *dentry, char **name) *name = NULL; d = dentry; - for (names=0; d != NULL; ++names) + for (names = 0; d != NULL; ++names) d = d->parent; - dentry_names = (char **) calloc(names+1, sizeof(char *)); - if (! dentry_names) { + dentry_names = (char **)calloc(names + 1, sizeof(char *)); + if (!dentry_names) { ltfsmsg(LTFS_ERR, 10001E, "fs_dentry_lookup: dentry_names"); return -LTFS_NO_MEMORY; } d = dentry; parent = d->parent; - for (i=names-1; i>=0; --i) { - if (parent) - acquireread_mrsw(&parent->contents_lock); + for (i = names - 1; i >= 0; --i) { + if (parent) acquireread_mrsw(&parent->contents_lock); - lookup_name = (const char *) d->platform_safe_name; - if (! lookup_name) { + lookup_name = (const char *)d->platform_safe_name; + if (!lookup_name) { if (d->deleted || d->parent) { ret = -LTFS_NO_DENTRY; goto out; @@ -460,45 +446,40 @@ int fs_dentry_lookup(struct dentry *dentry, char **name) lookup_name = "/"; } dentry_names[i] = arch_strdup(lookup_name); - if (! dentry_names[i]) { + if (!dentry_names[i]) { ltfsmsg(LTFS_ERR, 10001E, "fs_dentry_lookup: dentry_names member"); goto out; } namelen += strlen(lookup_name); - if (parent) - releaseread_mrsw(&parent->contents_lock); + if (parent) releaseread_mrsw(&parent->contents_lock); d = parent; - if (! d) - break; + if (!d) break; parent = d->parent; } - size_t tmp_len = ((namelen + names)* sizeof(char)); - tmp_name = (char*)calloc(namelen + names, sizeof(char)); - if (! tmp_name) { + size_t tmp_len = ((namelen + names) * sizeof(char)); + tmp_name = (char *)calloc(namelen + names, sizeof(char)); + if (!tmp_name) { ltfsmsg(LTFS_ERR, 10001E, "fs_dentry_lookup: tmp_name"); ret = -LTFS_NO_MEMORY; goto out; } - for (namelen=0, i=0; i 0 && i < names-1) - arch_strcat(tmp_name, tmp_len, "/"); + for (namelen = 0, i = 0; i < names; ++i) { + arch_strcat(tmp_name, tmp_len, dentry_names[i]); + if (i > 0 && i < names - 1) arch_strcat(tmp_name, tmp_len, "/"); } ret = 0; *name = tmp_name; out: - if (ret != 0 && tmp_name) - free(tmp_name); + if (ret != 0 && tmp_name) free(tmp_name); if (dentry_names) { /* BEAM: constant condition - dentry_names has always non-zero value here. */ while (--names >= 0) - if (dentry_names[names]) - free(dentry_names[names]); + if (dentry_names[names]) free(dentry_names[names]); free(dentry_names); } return ret; @@ -515,16 +496,14 @@ int fs_directory_lookup(struct dentry *basedir, const char *name, struct dentry *dentry = NULL; - if (pathname_strlen(name) > LTFS_FILENAME_MAX) - return -LTFS_NAMETOOLONG; + if (pathname_strlen(name) > LTFS_FILENAME_MAX) return -LTFS_NAMETOOLONG; - if (HASH_COUNT(basedir->child_list) == 0) - return 0; + if (HASH_COUNT(basedir->child_list) == 0) return 0; namelist = fs_find_key_from_hash_table(basedir->child_list, name, &rc); if (rc != 0) { /* Can only happen in a case-insensitive environment (Windows) */ - ltfsmsg(LTFS_ERR, 11320E, "fs_directory_lookup", rc); + ltfsmsg(LTFS_ERR, 11320E, "fs_directory_lookup", rc); return rc; } @@ -551,7 +530,7 @@ int fs_path_lookup(const char *path, int flags, struct dentry **dentry, struct l CHECK_ARG_NULL(idx, -LTFS_NULL_ARG); tmp_path = arch_strdup(path); - if (! tmp_path) { + if (!tmp_path) { ltfsmsg(LTFS_ERR, 10001E, "fs_path_lookup: tmp_path"); return -LTFS_NO_MEMORY; } @@ -563,7 +542,7 @@ int fs_path_lookup(const char *path, int flags, struct dentry **dentry, struct l releasewrite_mrsw(&idx->root->meta_lock); /* Did the caller ask for the root dentry? */ - if (*path == '\0' || ! strcmp(path, "/")) { + if (*path == '\0' || !strcmp(path, "/")) { d = idx->root; goto out; } @@ -574,29 +553,26 @@ int fs_path_lookup(const char *path, int flags, struct dentry **dentry, struct l while (end) { end = strstr(start, "/"); - if (end) - *end = '\0'; + if (end) *end = '\0'; - if (! end && (flags & LOCK_PARENT_CONTENTS_W)) + if (!end && (flags & LOCK_PARENT_CONTENTS_W)) acquirewrite_mrsw(&d->contents_lock); else acquireread_mrsw(&d->contents_lock); - if (parent) - releaseread_mrsw(&parent->contents_lock); + if (parent) releaseread_mrsw(&parent->contents_lock); parent = d; d = NULL; ret = fs_directory_lookup(parent, start, &d); - if (ret < 0 || ! d) { - if (! end && (flags & LOCK_PARENT_CONTENTS_W)) + if (ret < 0 || !d) { + if (!end && (flags & LOCK_PARENT_CONTENTS_W)) releasewrite_mrsw(&parent->contents_lock); else releaseread_mrsw(&parent->contents_lock); fs_release_dentry(parent); - if (ret == 0) - ret = -LTFS_NO_DENTRY; + if (ret == 0) ret = -LTFS_NO_DENTRY; goto out; } @@ -604,19 +580,16 @@ int fs_path_lookup(const char *path, int flags, struct dentry **dentry, struct l * Since we know 'parent' has a child (d), it's guaranteed that parent is still linked * into the file system tree. Therefore, fs_release_dentry is just a fancy way of * decrementing the handle count... so do that. */ - if (end || ! (flags & (LOCK_PARENT_CONTENTS_W | LOCK_PARENT_CONTENTS_R - | LOCK_PARENT_META_W | LOCK_PARENT_META_R))) { + if (end || !(flags & (LOCK_PARENT_CONTENTS_W | LOCK_PARENT_CONTENTS_R | LOCK_PARENT_META_W | LOCK_PARENT_META_R))) { acquirewrite_mrsw(&parent->meta_lock); --parent->numhandles; releasewrite_mrsw(&parent->meta_lock); } - if (end) - start = end + 1; + if (end) start = end + 1; } - if (! (flags & (LOCK_PARENT_CONTENTS_W | LOCK_PARENT_CONTENTS_R))) - releaseread_mrsw(&parent->contents_lock); + if (!(flags & (LOCK_PARENT_CONTENTS_W | LOCK_PARENT_CONTENTS_R))) releaseread_mrsw(&parent->contents_lock); out: free(tmp_path); @@ -648,7 +621,7 @@ int fs_path_lookup(const char *path, int flags, struct dentry **dentry, struct l void fs_split_path(char *path, char **filename, size_t len) { char *ptr; - for (ptr=&path[len-1]; ptr>=path; --ptr) { + for (ptr = &path[len - 1]; ptr >= path; --ptr) { if (*ptr == '/') { *ptr = '\0'; *filename = ptr + 1; @@ -675,14 +648,13 @@ void _fs_dispose_dentry_contents(struct dentry *dentry, bool unlock, bool gc) if (HASH_COUNT(dentry->child_list) != 0) { struct name_list *child, *aux; - HASH_ITER(hh, dentry->child_list, child, aux) { - + HASH_ITER(hh, dentry->child_list, child, aux) + { /* Remove child from the tree first */ HASH_DEL(dentry->child_list, child); - if (child->d->parent) - child->d->parent = NULL; + if (child->d->parent) child->d->parent = NULL; - if (! gc) { + if (!gc) { if (child->d->numhandles != 1) { /* Unable to delete dentry '%s': it still has outstanding references */ name = child->d->platform_safe_name ? child->d->platform_safe_name : "(null)"; @@ -710,7 +682,7 @@ void _fs_dispose_dentry_contents(struct dentry *dentry, bool unlock, bool gc) } if (dentry->tag_count > 0) { - for (i=0; itag_count; ++i) + for (i = 0; i < dentry->tag_count; ++i) free(dentry->preserved_tags[i]); free(dentry->preserved_tags); } @@ -718,22 +690,22 @@ void _fs_dispose_dentry_contents(struct dentry *dentry, bool unlock, bool gc) free(dentry->iosched_priv); dentry->iosched_priv = NULL; } - if (! TAILQ_EMPTY(&dentry->extentlist)) { + if (!TAILQ_EMPTY(&dentry->extentlist)) { TAILQ_FOREACH_SAFE(ext_entry, &dentry->extentlist, list, ext_aux) - free(ext_entry); + free(ext_entry); } - if (! TAILQ_EMPTY(&dentry->xattrlist)) { - TAILQ_FOREACH_SAFE(xattr_entry, &dentry->xattrlist, list, xattr_aux) { + if (!TAILQ_EMPTY(&dentry->xattrlist)) { + TAILQ_FOREACH_SAFE(xattr_entry, &dentry->xattrlist, list, xattr_aux) + { free(xattr_entry->key.name); - if (xattr_entry->value) - free(xattr_entry->value); + if (xattr_entry->value) free(xattr_entry->value); free(xattr_entry); } } if (dentry->parent) { namelist = fs_find_key_from_hash_table(dentry->parent->child_list, dentry->platform_safe_name, &rc); if (rc != 0) { - ltfsmsg(LTFS_ERR, 11320E, "_fs_dispose_dentry_contents", rc); + ltfsmsg(LTFS_ERR, 11320E, "_fs_dispose_dentry_contents", rc); } if (namelist) { HASH_DEL(dentry->parent->child_list, namelist); @@ -750,8 +722,7 @@ void _fs_dispose_dentry_contents(struct dentry *dentry, bool unlock, bool gc) free(dentry->platform_safe_name); dentry->platform_safe_name = NULL; } - if (unlock) - releasewrite_mrsw(&dentry->meta_lock); + if (unlock) releasewrite_mrsw(&dentry->meta_lock); destroy_mrsw(&dentry->contents_lock); destroy_mrsw(&dentry->meta_lock); ltfs_mutex_destroy(&dentry->iosched_lock); @@ -765,7 +736,7 @@ void _fs_dispose_dentry_contents(struct dentry *dentry, bool unlock, bool gc) void fs_release_dentry(struct dentry *d) { - if (! d) { + if (!d) { ltfsmsg(LTFS_WARN, 10006W, "dentry", __FUNCTION__); return; } @@ -788,13 +759,14 @@ void fs_release_dentry_unlocked(struct dentry *d) void fs_gc_dentry(struct dentry *d) { acquirewrite_mrsw(&d->meta_lock); - if (d->numhandles == 0 && ! d->out_of_sync) + if (d->numhandles == 0 && !d->out_of_sync) _fs_dispose_dentry_contents(d, true, true); else { releasewrite_mrsw(&d->meta_lock); if (HASH_COUNT(d->child_list) != 0) { struct name_list *child, *aux; - HASH_ITER(hh, d->child_list, child, aux) { + HASH_ITER(hh, d->child_list, child, aux) + { fs_gc_dentry(child->d); } } @@ -809,13 +781,17 @@ void fs_gc_dentry(struct dentry *d) * if TRUE. otherwise the name is skipped withour updating * platform_safe_name field. */ -static struct name_list* fs_update_platform_safe_names_and_hash_table(struct dentry* basedir, struct ltfs_index *idx, struct name_list *list, bool handle_dup_name, bool handle_invalid_char) +static struct name_list *fs_update_platform_safe_names_and_hash_table(struct dentry *basedir, + struct ltfs_index *idx, + struct name_list *list, + bool handle_dup_name, + bool handle_invalid_char) { struct name_list *same_name, *list_ptr, *list_tmp; int rc; - HASH_ITER(hh, list, list_ptr, list_tmp) { - + HASH_ITER(hh, list, list_ptr, list_tmp) + { if (!handle_dup_name) { same_name = fs_find_key_from_hash_table(basedir->child_list, list_ptr->name, &rc); if (rc != 0) { @@ -849,18 +825,19 @@ static struct name_list* fs_update_platform_safe_names_and_hash_table(struct den return list; } -int fs_update_platform_safe_names(struct dentry* basedir, struct ltfs_index *idx, struct name_list *list) +int fs_update_platform_safe_names(struct dentry *basedir, struct ltfs_index *idx, struct name_list *list) { struct name_list *list_ptr, *list_tmp; int ret = 0; list = fs_update_platform_safe_names_and_hash_table(basedir, idx, list, false, false); // normal loop - list = fs_update_platform_safe_names_and_hash_table(basedir, idx, list, true, false); // add dup name - list = fs_update_platform_safe_names_and_hash_table(basedir, idx, list, true, true); // add invalid char + list = fs_update_platform_safe_names_and_hash_table(basedir, idx, list, true, false); // add dup name + list = fs_update_platform_safe_names_and_hash_table(basedir, idx, list, true, true); // add invalid char /* clear list table */ - if (HASH_COUNT(list)!=0) { // this situation should not occur. Just for fail-safe. - HASH_ITER(hh, list, list_ptr, list_tmp) { + if (HASH_COUNT(list) != 0) { // this situation should not occur. Just for fail-safe. + HASH_ITER(hh, list, list_ptr, list_tmp) + { HASH_DEL(list, list_ptr); free(list_ptr); } @@ -883,8 +860,7 @@ bool fs_is_predecessor(struct dentry *d1, struct dentry *d2) struct dentry *d = d2; if (d1 && d2) { while (d) { - if (d == d1) - return true; + if (d == d1) return true; d = d->parent; } } @@ -901,10 +877,10 @@ uint64_t fs_get_used_blocks(struct dentry *d) uint64_t used = 0; struct extent_info *extent; - TAILQ_FOREACH(extent, &d->extentlist, list) { + TAILQ_FOREACH(extent, &d->extentlist, list) + { used += ((extent->byteoffset + extent->bytecount) / d->vol->label->blocksize); - if ((extent->byteoffset + extent->bytecount) % d->vol->label->blocksize) - used++; + if ((extent->byteoffset + extent->bytecount) % d->vol->label->blocksize) used++; } return used; @@ -921,32 +897,44 @@ void _fs_dump_dentry(struct dentry *ptr, int spaces) struct xattr_info *xattr; struct extent_info *extent; - for (i=0; iname.name, ptr->isdir?"/":"", ptr->numhandles, - (unsigned long long)ptr->size, (unsigned long long)ptr->realsize, - ptr->readonly, (long long int) ptr->creation_time.tv_sec, (long long int) ptr->change_time.tv_sec, - (long long int) ptr->modify_time.tv_sec, (long long int) ptr->access_time.tv_sec, - ptr->deleted ? " (deleted)" : ""); + ptr->name.name, + ptr->isdir ? "/" : "", + ptr->numhandles, + (unsigned long long)ptr->size, + (unsigned long long)ptr->realsize, + ptr->readonly, + (long long int)ptr->creation_time.tv_sec, + (long long int)ptr->change_time.tv_sec, + (long long int)ptr->modify_time.tv_sec, + (long long int)ptr->access_time.tv_sec, + ptr->deleted ? " (deleted)" : ""); /* Extent data */ - TAILQ_FOREACH(extent, &ptr->extentlist, list) { + TAILQ_FOREACH(extent, &ptr->extentlist, list) + { int tab = spaces + strlen(ptr->name.name) + (ptr->isdir ? 1 : 0); - for (i=0; istart.partition, extent->start.block, - extent->byteoffset, extent->bytecount, extent->fileoffset); + printf("{extent %d: partition=%d, startblock=%" PRIu64 ", blockoffset=%u, length=%" PRIu64 ", fileoffset=%" PRIu64 + "}\n", + n++, + extent->start.partition, + extent->start.block, + extent->byteoffset, + extent->bytecount, + extent->fileoffset); } /* Extended attributes data */ - TAILQ_FOREACH(xattr, &ptr->xattrlist, list) { + TAILQ_FOREACH(xattr, &ptr->xattrlist, list) + { int tab = spaces + strlen(ptr->name.name) + (ptr->isdir ? 1 : 0); - for (i=0; ikey.name, (int)xattr->size, xattr->value, xattr->size); + printf("{xattr key=%s, value=%.*s, size=%zu}\n", xattr->key.name, (int)xattr->size, xattr->value, xattr->size); } } @@ -960,11 +948,11 @@ void _fs_dump_tree(struct dentry *root, int spaces) struct dentry *ptr; struct name_list *namelist, *tmp; - HASH_ITER(hh, root->child_list, namelist, tmp) { + HASH_ITER(hh, root->child_list, namelist, tmp) + { ptr = namelist->d; _fs_dump_dentry(ptr, spaces); - if (ptr->isdir) - _fs_dump_tree(ptr, spaces+3); + if (ptr->isdir) _fs_dump_tree(ptr, spaces + 3); } } @@ -977,24 +965,29 @@ void fs_dump_tree(struct dentry *root) int i; struct xattr_info *xattr; - if (! root->isdir) { + if (!root->isdir) { _fs_dump_dentry(root, 0); return; } /* Dentry data */ - printf("%s [%d] {size=%"PRIu64", readonly=%d, creation=%lld, change=%lld, modify=%lld, access=%lld}\n", - root->name.name, root->numhandles, root->size, root->readonly, - (long long int) root->creation_time.tv_sec, (long long int) root->change_time.tv_sec, - (long long int) root->modify_time.tv_sec, (long long int) root->access_time.tv_sec); + printf("%s [%d] {size=%" PRIu64 ", readonly=%d, creation=%lld, change=%lld, modify=%lld, access=%lld}\n", + root->name.name, + root->numhandles, + root->size, + root->readonly, + (long long int)root->creation_time.tv_sec, + (long long int)root->change_time.tv_sec, + (long long int)root->modify_time.tv_sec, + (long long int)root->access_time.tv_sec); /* Extended attributes data */ - TAILQ_FOREACH(xattr, &root->xattrlist, list) { + TAILQ_FOREACH(xattr, &root->xattrlist, list) + { int tab = strlen(root->name.name) + (root->isdir ? 1 : 0); - for (i=0; ikey.name, (int)xattr->size, xattr->value, xattr->size); + printf("{xattr key=%s, value=%.*s, size=%zu}\n", xattr->key.name, (int)xattr->size, xattr->value, xattr->size); } return _fs_dump_tree(root, 3); diff --git a/src/libltfs/index_criteria.c b/src/libltfs/index_criteria.c index 5fdca63b..58c5ceab 100644 --- a/src/libltfs/index_criteria.c +++ b/src/libltfs/index_criteria.c @@ -48,25 +48,25 @@ */ #ifdef __APPLE_MAKEFILE__ -#include -#include +# include +# include #else -#include -#include +# include +# include #endif - #ifdef mingw_PLATFORM -#include "arch/win/win_util.h" +# include "arch/win/win_util.h" #endif -#include "ltfs.h" -#include "libltfs/ltfslogging.h" -#include "libltfs/fs.h" #include "index_criteria.h" +#include "libltfs/fs.h" +#include "libltfs/ltfslogging.h" +#include "ltfs.h" #include "pathname.h" -typedef struct ustack { +typedef struct ustack +{ int32_t cr_bnd[3]; int32_t fi_bnd[3]; struct ustack *next; @@ -74,8 +74,7 @@ typedef struct ustack { /* Forward declaration of private functions */ int _prepare_glob_cache(struct index_criteria *ic); -int _matches_name_criteria_caseless(const UChar *criteria, int32_t cr_len, - const UChar *filename, int32_t fi_len); +int _matches_name_criteria_caseless(const UChar *criteria, int32_t cr_len, const UChar *filename, int32_t fi_len); void _next_char(const UChar *str, UBreakIterator *it, int32_t *pos); int _char_compare(const UChar *str1, int32_t *pos1, const UChar *str2, int32_t *pos2); void _destroy_ustack(filename_ustack_t **stack); @@ -96,7 +95,7 @@ bool index_criteria_contains_invalid_options(const char *str) bool error = true; int i; - if (! str) + if (!str) return !error; else if (strlen(str) < 5) { ltfsmsg(LTFS_ERR, 11146E, str); @@ -104,28 +103,27 @@ bool index_criteria_contains_invalid_options(const char *str) } /* Check the beginning of the string */ - for (valid_option = false, i=0; options[i]; ++i) - if (! strncmp(options[i], str, strlen(options[i]))) { + for (valid_option = false, i = 0; options[i]; ++i) + if (!strncmp(options[i], str, strlen(options[i]))) { valid_option = true; break; } - if (! valid_option) { + if (!valid_option) { ltfsmsg(LTFS_ERR, 11146E, str); return error; } /* Check which options come after each separator */ while (true) { - ptr = strstr(ptr+1, "/"); - if (! ptr) - break; - for (valid_option = false, i=0; options[i]; ++i) - if (!strncmp(options[i], ptr+1, strlen(options[i]))) { + ptr = strstr(ptr + 1, "/"); + if (!ptr) break; + for (valid_option = false, i = 0; options[i]; ++i) + if (!strncmp(options[i], ptr + 1, strlen(options[i]))) { valid_option = true; break; } - if (! valid_option) { - ltfsmsg(LTFS_ERR, 11146E, ptr+1); + if (!valid_option) { + ltfsmsg(LTFS_ERR, 11146E, ptr + 1); return error; } } @@ -141,16 +139,14 @@ bool index_criteria_contains_invalid_options(const char *str) * @param error output flag if a syntax error was found while parsing the options * @return true on success or false if the option could not be found */ -bool index_criteria_find_option(const char *str, const char *substr, - const char **start, const char **end, bool *error) +bool index_criteria_find_option(const char *str, const char *substr, const char **start, const char **end, bool *error) { const char *str_start = NULL, *str_end = NULL; const char *next_start = NULL, *next_end = NULL; int substr_len = strlen(substr); bool next_error, found = false; - if (strlen(str) < 5) - return false; + if (strlen(str) < 5) return false; if (!strncmp(str, substr, substr_len)) { /* Match at the start of the string */ @@ -159,23 +155,21 @@ bool index_criteria_find_option(const char *str, const char *substr, /* Need to walk the string to find the first valid match */ str_start = str + 1; found = false; - while (! found) { + while (!found) { str_start = strcasestr(str_start, substr); - if (! str_start) + if (!str_start) break; - else if (*(str_start-1) == '/') + else if (*(str_start - 1) == '/') found = true; else ++str_start; } - if (! found) - return false; + if (!found) return false; } /* Find end of option */ - for (str_end=str_start; *str_end; ++str_end) { - if (*str_end == '/') - break; + for (str_end = str_start; *str_end; ++str_end) { + if (*str_end == '/') break; } if (index_criteria_find_option(str_end, substr, &next_start, &next_end, &next_error) == true) { @@ -185,7 +179,7 @@ bool index_criteria_find_option(const char *str, const char *substr, } *start = str_start; - *end = str_end; + *end = str_end; *error = false; return true; } @@ -203,7 +197,7 @@ int index_criteria_parse_size(const char *criteria, size_t len, struct index_cri size_t sizelen = 0; char *rule = NULL, last, *ptr; int lenrule = (sizeof(char) * (int)(len + 1)); - rule = (char*)calloc(lenrule,sizeof(char)); + rule = (char *)calloc(lenrule, sizeof(char)); if (rule == NULL) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; @@ -217,13 +211,13 @@ int index_criteria_parse_size(const char *criteria, size_t len, struct index_cri snprintf(rule, len - sizelen, "%s", param); - for (ptr=&rule[0]; *ptr; ptr++) { - if (isalpha(*ptr) && *(ptr+1) && isalpha(*(ptr+1))) { + for (ptr = &rule[0]; *ptr; ptr++) { + if (isalpha(*ptr) && *(ptr + 1) && isalpha(*(ptr + 1))) { ltfsmsg(LTFS_ERR, 11148E); return -LTFS_POLICY_INVALID; } } - last = (rule[strlen(rule)-1]); + last = (rule[strlen(rule) - 1]); if (isalpha(last)) { if (last == 'k' || last == 'K') @@ -237,7 +231,7 @@ int index_criteria_parse_size(const char *criteria, size_t len, struct index_cri arch_safe_free(rule); return -LTFS_POLICY_INVALID; } - rule[strlen(rule)-1] = '\0'; + rule[strlen(rule) - 1] = '\0'; } if (strlen(rule) == 0) { @@ -264,9 +258,8 @@ int index_criteria_parse_size(const char *criteria, size_t len, struct index_cri int index_criteria_parse_name(const char *criteria, size_t len, struct index_criteria *ic) { char *delim, *rule, *rulebuf = NULL; - rulebuf = (char*)malloc(sizeof(char) * (len + 1)); - if (rulebuf == NULL) - { + rulebuf = (char *)malloc(sizeof(char) * (len + 1)); + if (rulebuf == NULL) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } @@ -283,9 +276,9 @@ int index_criteria_parse_name(const char *criteria, size_t len, struct index_cri arch_safe_free(rulebuf); return -LTFS_POLICY_EMPTY_RULE; } - for (delim=rule+6; *delim; delim++) { + for (delim = rule + 6; *delim; delim++) { if (*delim == ':') { - if (*(delim-1) == ':' || *(delim+1) == '\0') { + if (*(delim - 1) == ':' || *(delim + 1) == '\0') { ltfsmsg(LTFS_ERR, 11305E, rule); arch_safe_free(rulebuf); return -LTFS_POLICY_EMPTY_RULE; @@ -294,8 +287,8 @@ int index_criteria_parse_name(const char *criteria, size_t len, struct index_cri } } - ic->glob_patterns = calloc(num_names+1, sizeof(struct ltfs_name)); - if (! ic->glob_patterns) { + ic->glob_patterns = calloc(num_names + 1, sizeof(struct ltfs_name)); + if (!ic->glob_patterns) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); arch_safe_free(rulebuf); return -LTFS_NO_MEMORY; @@ -303,20 +296,20 @@ int index_criteria_parse_name(const char *criteria, size_t len, struct index_cri rule_ptr = ic->glob_patterns; /* Assign rules to the glob_patterns[] array */ - rule = rule+5; + rule = rule + 5; for (delim = rule; *delim; delim++) { if (*delim == ':') { *delim = '\0'; rule_ptr->percent_encode = fs_is_percent_encode_required(rule); rule_ptr->name = arch_strdup(rule); rule_ptr++; - rule = delim+1; + rule = delim + 1; } else if (*delim == '/') { *delim = '\0'; rule_ptr->percent_encode = fs_is_percent_encode_required(rule); rule_ptr->name = arch_strdup(rule); rule_ptr++; - } else if (*(delim+1) == '\0') { + } else if (*(delim + 1) == '\0') { rule_ptr->percent_encode = fs_is_percent_encode_required(rule); rule_ptr->name = arch_strdup(rule); rule_ptr++; @@ -361,7 +354,7 @@ int index_criteria_parse(const char *filterrules, struct ltfs_volume *vol) int ret = 0; CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); - if (! filterrules) { + if (!filterrules) { vol->index->index_criteria.have_criteria = false; return 0; } @@ -378,7 +371,7 @@ int index_criteria_parse(const char *filterrules, struct ltfs_volume *vol) /* Process name= criteria */ if (index_criteria_find_option(filterrules, "name=", &start, &end, &error)) { - ret = index_criteria_parse_name(start, end-start+1, ic); + ret = index_criteria_parse_name(start, end - start + 1, ic); if (ret < 0) { ltfsmsg(LTFS_ERR, 11153E, ret); return ret; @@ -392,7 +385,7 @@ int index_criteria_parse(const char *filterrules, struct ltfs_volume *vol) /* Process size= criteria */ ic->max_filesize_criteria = 0; if (index_criteria_find_option(filterrules, "size=", &start, &end, &error)) { - ret = index_criteria_parse_size(start, end-start+1, ic); + ret = index_criteria_parse_size(start, end - start + 1, ic); if (ret < 0) { ltfsmsg(LTFS_ERR, 11155E, ret); return ret; @@ -445,8 +438,8 @@ int index_criteria_dup_rules(struct index_criteria *dest_ic, struct index_criter while (src_ic->glob_patterns[counter].name) counter++; - dest_ic->glob_patterns = calloc(counter+1, sizeof(struct ltfs_name)); - if (! dest_ic->glob_patterns) { + dest_ic->glob_patterns = calloc(counter + 1, sizeof(struct ltfs_name)); + if (!dest_ic->glob_patterns) { ltfsmsg(LTFS_ERR, 10001E, "index_criteria_dup_rules: glob pattern array"); return -LTFS_NO_MEMORY; } @@ -457,7 +450,7 @@ int index_criteria_dup_rules(struct index_criteria *dest_ic, struct index_criter for (i = 0; i < counter; ++i) { dst_gp->percent_encode = src_gp->percent_encode; dst_gp->name = arch_strdup(src_gp->name); - if (! dst_gp->name) { + if (!dst_gp->name) { ltfsmsg(LTFS_ERR, 10001E, "index_criteria_dup_rules: glob pattern"); while (--i >= 0) { --dst_gp; @@ -480,10 +473,10 @@ int index_criteria_dup_rules(struct index_criteria *dest_ic, struct index_criter */ void index_criteria_free(struct index_criteria *ic) { - if (! ic) { + if (!ic) { ltfsmsg(LTFS_WARN, 10006W, "ic", __FUNCTION__); return; - } else if (! ic->have_criteria) + } else if (!ic->have_criteria) return; if (ic->glob_patterns) { @@ -541,12 +534,11 @@ const char **index_criteria_get_glob_patterns(struct ltfs_volume *vol) ic = &vol->index->index_criteria; if (ic->have_criteria) - return (const char **) ic->glob_patterns; + return (const char **)ic->glob_patterns; else return NULL; /* if no policy specified, don't store anything on the index partition */ } - /** * Returns true if a given file name matches the criteria set in the index file or false if not. * @@ -568,15 +560,15 @@ bool index_criteria_match(struct dentry *d, struct ltfs_volume *vol) CHECK_ARG_NULL(d, false); ic = &vol->index->index_criteria; - if (! ic->have_criteria || ic->max_filesize_criteria == 0) { + if (!ic->have_criteria || ic->max_filesize_criteria == 0) { /* Disable writing to the index partition if not bound by a maximum cache size */ return false; - } else if (! ic->glob_patterns) { + } else if (!ic->glob_patterns) { /* Criteria is set on file size only */ return true; } - if (! ic->glob_cache) { + if (!ic->glob_cache) { ret = _prepare_glob_cache(ic); if (ret < 0) { ltfsmsg(LTFS_ERR, 11158E, ret); @@ -593,7 +585,7 @@ bool index_criteria_match(struct dentry *d, struct ltfs_volume *vol) } dname_len = u_strlen(dname); - for (i=0; glob_cache[i]; ++i) { + for (i = 0; glob_cache[i]; ++i) { glob_len = u_strlen(glob_cache[i]); match = _matches_name_criteria_caseless(glob_cache[i], glob_len, dname, dname_len); if (match > 0) { @@ -630,11 +622,11 @@ int _prepare_glob_cache(struct index_criteria *ic) ++num_patterns; ic->glob_cache = calloc(num_patterns + 1, sizeof(UChar *)); - if (! ic->glob_cache) { + if (!ic->glob_cache) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } - for (i=0; ic->glob_patterns[i].name; ++i) { + for (i = 0; ic->glob_patterns[i].name; ++i) { ret = pathname_prepare_caseless(ic->glob_patterns[i].name, &ic->glob_cache[i], false); if (ret < 0) { ltfsmsg(LTFS_ERR, 11160E, ret); @@ -650,12 +642,11 @@ int _prepare_glob_cache(struct index_criteria *ic) * filename globbing ("*" and "?" are supported), and it is performed by grapheme cluster * rather than by code point. */ -int _matches_name_criteria_caseless(const UChar *criteria, int32_t cr_len, - const UChar *filename, int32_t fi_len) +int _matches_name_criteria_caseless(const UChar *criteria, int32_t cr_len, const UChar *filename, int32_t fi_len) { UBreakIterator *ub_criteria, *ub_filename; UErrorCode err = U_ZERO_ERROR; - int32_t cr_bnd[3] = {0, 0, 0}, fi_bnd[3] = {0, 0, 0}; + int32_t cr_bnd[3] = { 0, 0, 0 }, fi_bnd[3] = { 0, 0, 0 }; filename_ustack_t *stack = NULL, *element; bool acceptany, have_asterisk; int match; @@ -688,7 +679,6 @@ int _matches_name_criteria_caseless(const UChar *criteria, int32_t cr_len, have_asterisk = false; for (;;) { while (cr_bnd[0] != cr_bnd[1]) { - /* Consume sequential asterisks. */ while (criteria[cr_bnd[0]] == 0x2a && cr_bnd[2] == 1) { _next_char(criteria, ub_criteria, cr_bnd); @@ -702,8 +692,7 @@ int _matches_name_criteria_caseless(const UChar *criteria, int32_t cr_len, /* If we got this far, the file name is done and the pattern doesn't end with * an asterisk. No match. */ - if (fi_bnd[0] == fi_bnd[1]) - break; + if (fi_bnd[0] == fi_bnd[1]) break; /* Question mark: accept any character. */ if (criteria[cr_bnd[0]] == 0x3f && cr_bnd[2] == 1) @@ -713,16 +702,16 @@ int _matches_name_criteria_caseless(const UChar *criteria, int32_t cr_len, /* Try to consume a file name character. */ if (have_asterisk) { - if (acceptany || ! _char_compare(criteria, cr_bnd, filename, fi_bnd)) { + if (acceptany || !_char_compare(criteria, cr_bnd, filename, fi_bnd)) { /* Push this position onto the stack and consume the character. */ - element = (filename_ustack_t *) calloc(1, sizeof(filename_ustack_t)); - if (! element) { + element = (filename_ustack_t *)calloc(1, sizeof(filename_ustack_t)); + if (!element) { ltfsmsg(LTFS_ERR, 10001E, "_matches_name_criteria_caseless: filename stack"); match = 0; goto out; } - memcpy(element->cr_bnd, cr_bnd, 3*sizeof(int32_t)); - memcpy(element->fi_bnd, fi_bnd, 3*sizeof(int32_t)); + memcpy(element->cr_bnd, cr_bnd, 3 * sizeof(int32_t)); + memcpy(element->fi_bnd, fi_bnd, 3 * sizeof(int32_t)); _push_ustack(&stack, element); _next_char(criteria, ub_criteria, cr_bnd); _next_char(filename, ub_filename, fi_bnd); @@ -731,7 +720,7 @@ int _matches_name_criteria_caseless(const UChar *criteria, int32_t cr_len, /* This character must be subsumed by the asterisk. */ _next_char(filename, ub_filename, fi_bnd); } - } else if (acceptany || ! _char_compare(criteria, cr_bnd, filename, fi_bnd)) { + } else if (acceptany || !_char_compare(criteria, cr_bnd, filename, fi_bnd)) { _next_char(criteria, ub_criteria, cr_bnd); _next_char(filename, ub_filename, fi_bnd); } else { @@ -741,8 +730,8 @@ int _matches_name_criteria_caseless(const UChar *criteria, int32_t cr_len, goto out; } else { element = _pop_ustack(&stack); - memcpy(cr_bnd, element->cr_bnd, 3*sizeof(int32_t)); - memcpy(fi_bnd, element->fi_bnd, 3*sizeof(int32_t)); + memcpy(cr_bnd, element->cr_bnd, 3 * sizeof(int32_t)); + memcpy(fi_bnd, element->fi_bnd, 3 * sizeof(int32_t)); free(element); ubrk_following(ub_criteria, cr_bnd[0]); ubrk_following(ub_filename, fi_bnd[0]); @@ -762,8 +751,8 @@ int _matches_name_criteria_caseless(const UChar *criteria, int32_t cr_len, } else { /* Pop an element off the stack. */ element = _pop_ustack(&stack); - memcpy(cr_bnd, element->cr_bnd, 3*sizeof(int32_t)); - memcpy(fi_bnd, element->fi_bnd, 3*sizeof(int32_t)); + memcpy(cr_bnd, element->cr_bnd, 3 * sizeof(int32_t)); + memcpy(fi_bnd, element->fi_bnd, 3 * sizeof(int32_t)); free(element); ubrk_following(ub_criteria, cr_bnd[0]); ubrk_following(ub_filename, fi_bnd[0]); @@ -788,7 +777,7 @@ void _next_char(const UChar *str, UBreakIterator *it, int32_t *pos) pos[1] = ubrk_next(it); if (pos[1] == -1) { pos[1] = pos[0]; - while(str[pos[1]] != 0) + while (str[pos[1]] != 0) ++pos[1]; } pos[2] = pos[1] - pos[0]; @@ -800,14 +789,12 @@ void _next_char(const UChar *str, UBreakIterator *it, int32_t *pos) int _char_compare(const UChar *str1, int32_t *pos1, const UChar *str2, int32_t *pos2) { const UChar *c1, *c1_end, *c2; - if (pos1[2] != pos2[2]) - return 1; + if (pos1[2] != pos2[2]) return 1; c1 = str1 + pos1[0]; c1_end = str1 + pos1[1]; c2 = str2 + pos2[0]; while (c1 < c1_end) { - if (*c1 != *c2) - return 1; + if (*c1 != *c2) return 1; ++c1; ++c2; } @@ -817,8 +804,7 @@ int _char_compare(const UChar *str1, int32_t *pos1, const UChar *str2, int32_t * void _destroy_ustack(filename_ustack_t **stack) { filename_ustack_t *ptr, *next; - if (! stack) - return; + if (!stack) return; ptr = *stack; while (ptr) { next = ptr->next; @@ -829,11 +815,11 @@ void _destroy_ustack(filename_ustack_t **stack) int _push_ustack(filename_ustack_t **stack, filename_ustack_t *element) { - if (! stack) { + if (!stack) { ltfsmsg(LTFS_ERR, 11164E); return -1; } - if (! *stack) + if (!*stack) *stack = element; else (*stack)->next = element; @@ -844,13 +830,13 @@ int _push_ustack(filename_ustack_t **stack, filename_ustack_t *element) filename_ustack_t *_pop_ustack(filename_ustack_t **stack) { filename_ustack_t *prev = NULL, *top; - if (! stack) { + if (!stack) { ltfsmsg(LTFS_ERR, 11165E); return NULL; } - for (top=*stack; top->next; top=top->next) + for (top = *stack; top->next; top = top->next) prev = top; - if (! prev) { + if (!prev) { /* Removing base */ *stack = NULL; return top; @@ -861,7 +847,6 @@ filename_ustack_t *_pop_ustack(filename_ustack_t **stack) bool _ustack_empty(filename_ustack_t *stack) { - if (! stack) - return true; + if (!stack) return true; return false; } diff --git a/src/libltfs/index_criteria.h b/src/libltfs/index_criteria.h index 5b72f657..dca8f205 100644 --- a/src/libltfs/index_criteria.h +++ b/src/libltfs/index_criteria.h @@ -38,7 +38,7 @@ ** ** FILE NAME: index_criteria.h ** -** DESCRIPTION: Header file for the routines that deal with the index partition +** DESCRIPTION: Header file for the routines that deal with the index partition ** criteria. ** ** AUTHOR: Lucas C. Villa Real @@ -49,6 +49,8 @@ */ #ifndef __index_criteria_h #define __index_criteria_h +#include +#include "ltfs.h" #ifdef __cplusplus extern "C" { diff --git a/src/libltfs/iosched.c b/src/libltfs/iosched.c index a2abcd30..f1b29c71 100644 --- a/src/libltfs/iosched.c +++ b/src/libltfs/iosched.c @@ -50,15 +50,16 @@ ** ************************************************************************************* */ -#include "ltfs_fuse.h" -#include "ltfs.h" #include "iosched.h" +#include "ltfs.h" +#include "ltfs_fuse.h" -struct iosched_priv { - void *dlopen_handle; /**< Handle returned from dlopen */ +struct iosched_priv +{ + void *dlopen_handle; /**< Handle returned from dlopen */ struct libltfs_plugin *plugin; /**< Reference to the plugin */ - struct iosched_ops *ops; /**< I/O scheduler operations */ - void *backend_handle; /**< Backend private data */ + struct iosched_ops *ops; /**< I/O scheduler operations */ + void *backend_handle; /**< Backend private data */ }; /** @@ -77,7 +78,7 @@ int iosched_init(struct libltfs_plugin *plugin, struct ltfs_volume *vol) CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); priv = calloc(1, sizeof(struct iosched_priv)); - if (! priv) { + if (!priv) { ltfsmsg(LTFS_ERR, 10001E, "iosched_init: private data"); return -LTFS_NO_MEMORY; } @@ -86,7 +87,7 @@ int iosched_init(struct libltfs_plugin *plugin, struct ltfs_volume *vol) priv->ops = plugin->ops; /* Verify that backend implements all required operations */ - for (i=0; iops))[i] == NULL) { ltfsmsg(LTFS_ERR, 13003E); free(priv); @@ -95,7 +96,7 @@ int iosched_init(struct libltfs_plugin *plugin, struct ltfs_volume *vol) } priv->backend_handle = priv->ops->init(vol); - if (! priv->backend_handle) { + if (!priv->backend_handle) { free(priv); return -1; } @@ -111,7 +112,7 @@ int iosched_init(struct libltfs_plugin *plugin, struct ltfs_volume *vol) */ int iosched_destroy(struct ltfs_volume *vol) { - struct iosched_priv *priv = (struct iosched_priv *) vol ? vol->iosched_handle : NULL; + struct iosched_priv *priv = (struct iosched_priv *)vol ? vol->iosched_handle : NULL; int ret; CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); @@ -136,7 +137,7 @@ int iosched_destroy(struct ltfs_volume *vol) */ int iosched_open(const char *path, bool open_write, struct dentry **dentry, struct ltfs_volume *vol) { - struct iosched_priv *priv = (struct iosched_priv *) vol ? vol->iosched_handle : NULL; + struct iosched_priv *priv = (struct iosched_priv *)vol ? vol->iosched_handle : NULL; int ret; CHECK_ARG_NULL(path, -LTFS_NULL_ARG); @@ -159,7 +160,7 @@ int iosched_open(const char *path, bool open_write, struct dentry **dentry, stru */ int iosched_close(struct dentry *d, bool flush, struct ltfs_volume *vol) { - struct iosched_priv *priv = (struct iosched_priv *) vol ? vol->iosched_handle : NULL; + struct iosched_priv *priv = (struct iosched_priv *)vol ? vol->iosched_handle : NULL; int ret; CHECK_ARG_NULL(d, -LTFS_NULL_ARG); @@ -195,7 +196,7 @@ bool iosched_initialized(struct ltfs_volume *vol) ssize_t iosched_read(struct dentry *d, char *buf, size_t size, off_t offset, struct ltfs_volume *vol) { ssize_t ret; - struct iosched_priv *priv = (struct iosched_priv *) vol ? vol->iosched_handle : NULL; + struct iosched_priv *priv = (struct iosched_priv *)vol ? vol->iosched_handle : NULL; CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); CHECK_ARG_NULL(priv, -LTFS_NULL_ARG); @@ -217,11 +218,11 @@ ssize_t iosched_read(struct dentry *d, char *buf, size_t size, off_t offset, str * @param vol LTFS volume * @return 0 on success or a negative value on error. */ -ssize_t iosched_write(struct dentry *d, const char *buf, size_t size, off_t offset, - bool isupdatetime, struct ltfs_volume *vol) +ssize_t +iosched_write(struct dentry *d, const char *buf, size_t size, off_t offset, bool isupdatetime, struct ltfs_volume *vol) { ssize_t ret; - struct iosched_priv *priv = (struct iosched_priv *) vol ? vol->iosched_handle : NULL; + struct iosched_priv *priv = (struct iosched_priv *)vol ? vol->iosched_handle : NULL; CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); CHECK_ARG_NULL(priv, -LTFS_NULL_ARG); @@ -230,8 +231,7 @@ ssize_t iosched_write(struct dentry *d, const char *buf, size_t size, off_t offs CHECK_ARG_NULL(d, -LTFS_NULL_ARG); ret = priv->ops->write(d, buf, size, offset, isupdatetime, priv->backend_handle); - if (ret > 0 && (size_t) ret > size) - ret = size; + if (ret > 0 && (size_t)ret > size) ret = size; return ret; } @@ -246,7 +246,7 @@ ssize_t iosched_write(struct dentry *d, const char *buf, size_t size, off_t offs int iosched_flush(struct dentry *d, bool closeflag, struct ltfs_volume *vol) { int ret; - struct iosched_priv *priv = (struct iosched_priv *) vol ? vol->iosched_handle : NULL; + struct iosched_priv *priv = (struct iosched_priv *)vol ? vol->iosched_handle : NULL; CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); CHECK_ARG_NULL(priv, -LTFS_NULL_ARG); @@ -267,7 +267,7 @@ int iosched_flush(struct dentry *d, bool closeflag, struct ltfs_volume *vol) int iosched_truncate(struct dentry *d, off_t length, struct ltfs_volume *vol) { int ret; - struct iosched_priv *priv = (struct iosched_priv *) vol ? vol->iosched_handle : NULL; + struct iosched_priv *priv = (struct iosched_priv *)vol ? vol->iosched_handle : NULL; CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); CHECK_ARG_NULL(priv, -LTFS_NULL_ARG); @@ -290,7 +290,7 @@ int iosched_truncate(struct dentry *d, off_t length, struct ltfs_volume *vol) uint64_t iosched_get_filesize(struct dentry *d, struct ltfs_volume *vol) { uint64_t ret; - struct iosched_priv *priv = (struct iosched_priv *) vol ? vol->iosched_handle : NULL; + struct iosched_priv *priv = (struct iosched_priv *)vol ? vol->iosched_handle : NULL; CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); CHECK_ARG_NULL(priv, -LTFS_NULL_ARG); @@ -311,7 +311,7 @@ uint64_t iosched_get_filesize(struct dentry *d, struct ltfs_volume *vol) int iosched_update_data_placement(struct dentry *d, struct ltfs_volume *vol) { int ret; - struct iosched_priv *priv = (struct iosched_priv *) vol ? vol->iosched_handle : NULL; + struct iosched_priv *priv = (struct iosched_priv *)vol ? vol->iosched_handle : NULL; CHECK_ARG_NULL(d, -LTFS_NULL_ARG); CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); @@ -330,10 +330,10 @@ int iosched_update_data_placement(struct dentry *d, struct ltfs_volume *vol) * @param vol LTFS volume * @return 0 on succe ss or a negative value on error */ -int iosched_set_profiler(char* work_dir, bool enable, struct ltfs_volume *vol) +int iosched_set_profiler(char *work_dir, bool enable, struct ltfs_volume *vol) { int ret = 0; - struct iosched_priv *priv = (struct iosched_priv *) vol ? vol->iosched_handle : NULL; + struct iosched_priv *priv = (struct iosched_priv *)vol ? vol->iosched_handle : NULL; CHECK_ARG_NULL(work_dir, -LTFS_NULL_ARG); CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); diff --git a/src/libltfs/kmi.c b/src/libltfs/kmi.c index 02343cdb..9299bf6c 100644 --- a/src/libltfs/kmi.c +++ b/src/libltfs/kmi.c @@ -47,14 +47,15 @@ ************************************************************************************* */ -#include "ltfs_fuse.h" #include "kmi.h" +#include "ltfs_fuse.h" -struct kmi_priv { - void *dlopen_handle; /**< Handle returned from dlopen */ +struct kmi_priv +{ + void *dlopen_handle; /**< Handle returned from dlopen */ struct libltfs_plugin *plugin; /**< Reference to the plugin */ - struct kmi_ops *ops; /**< Key manager interface operations */ - void *backend_handle; /**< Backend private data */ + struct kmi_ops *ops; /**< Key manager interface operations */ + void *backend_handle; /**< Backend private data */ }; /** @@ -64,7 +65,7 @@ struct kmi_priv { * @return on success, 0 is returned and the key manager interface handle is stored in the ltfs_volume * structure. On failure a negative value is returned. */ -int kmi_init(struct libltfs_plugin * const plugin, struct ltfs_volume * const vol) +int kmi_init(struct libltfs_plugin *const plugin, struct ltfs_volume *const vol) { unsigned int i; struct kmi_priv *priv; @@ -73,7 +74,7 @@ int kmi_init(struct libltfs_plugin * const plugin, struct ltfs_volume * const vo CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); priv = calloc(1, sizeof(struct kmi_priv)); - if (! priv) { + if (!priv) { ltfsmsg(LTFS_ERR, 10001E, "kmi_init: private data"); return -LTFS_NO_MEMORY; } @@ -82,7 +83,7 @@ int kmi_init(struct libltfs_plugin * const plugin, struct ltfs_volume * const vo priv->ops = plugin->ops; /* Verify that backend implements all required operations */ - for (i=0; iops))[i] == NULL) { ltfsmsg(LTFS_ERR, 17174E); free(priv); @@ -91,7 +92,7 @@ int kmi_init(struct libltfs_plugin * const plugin, struct ltfs_volume * const vo } priv->backend_handle = priv->ops->init(vol); - if (! priv->backend_handle) { + if (!priv->backend_handle) { free(priv); return -1; } @@ -105,9 +106,9 @@ int kmi_init(struct libltfs_plugin * const plugin, struct ltfs_volume * const vo * @param vol LTFS volume * @return 0 on success or a negative value on error. */ -int kmi_destroy(struct ltfs_volume * const vol) +int kmi_destroy(struct ltfs_volume *const vol) { - struct kmi_priv *priv = (struct kmi_priv *) vol ? vol->kmi_handle : NULL; + struct kmi_priv *priv = (struct kmi_priv *)vol ? vol->kmi_handle : NULL; int ret; CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); @@ -127,7 +128,7 @@ int kmi_destroy(struct ltfs_volume * const vol) * @param vol LTFS volume * @return true to indicate that the key manager interface has been initialized or false if not */ -bool kmi_initialized(const struct ltfs_volume * const vol) +bool kmi_initialized(const struct ltfs_volume *const vol) { CHECK_ARG_NULL(vol, false); return vol->kmi_handle; @@ -140,9 +141,9 @@ bool kmi_initialized(const struct ltfs_volume * const vol) * @param kmi_handle Key manager interface handle * @return 0 on success or a negative value on error. */ -int kmi_get_key(unsigned char **keyalias, unsigned char **key, void * const kmi_handle) +int kmi_get_key(unsigned char **keyalias, unsigned char **key, void *const kmi_handle) { - struct kmi_priv *priv = (struct kmi_priv *) kmi_handle; + struct kmi_priv *priv = (struct kmi_priv *)kmi_handle; CHECK_ARG_NULL(keyalias, -LTFS_NULL_ARG); CHECK_ARG_NULL(key, -LTFS_NULL_ARG); @@ -157,24 +158,23 @@ int kmi_get_key(unsigned char **keyalias, unsigned char **key, void * const kmi_ * Print the backend's LTFS help message. * @param ops key manager interface operations for the backend */ -int kmi_print_help_message(const struct kmi_ops * const ops) +int kmi_print_help_message(const struct kmi_ops *const ops) { int ret = 0; - if (! ops) { + if (!ops) { ltfsmsg(LTFS_WARN, 10006W, "ops", __FUNCTION__); return -LTFS_NULL_ARG; } - if (ops->help_message) - ret = ops->help_message(); + if (ops->help_message) ret = ops->help_message(); return ret; } -int kmi_parse_opts(void * const kmi_handle, void *opt_args) +int kmi_parse_opts(void *const kmi_handle, void *opt_args) { - struct kmi_priv *priv = (struct kmi_priv *) kmi_handle; + struct kmi_priv *priv = (struct kmi_priv *)kmi_handle; int ret; CHECK_ARG_NULL(priv, -LTFS_NULL_ARG); @@ -183,8 +183,7 @@ int kmi_parse_opts(void * const kmi_handle, void *opt_args) CHECK_ARG_NULL(priv->ops->parse_opts, -LTFS_NULL_ARG); ret = priv->ops->parse_opts(opt_args); - if (ret < 0) - /* Cannot parse backend options: backend call failed (%d) */ + if (ret < 0) /* Cannot parse backend options: backend call failed (%d) */ ltfsmsg(LTFS_ERR, 12040E, ret); return ret; diff --git a/src/libltfs/label.c b/src/libltfs/label.c index fc849f1d..6d628eaf 100644 --- a/src/libltfs/label.c +++ b/src/libltfs/label.c @@ -80,8 +80,7 @@ int label_alloc(struct ltfs_label **label) void label_free(struct ltfs_label **label) { if (label && *label) { - if ((*label)->creator) - free((*label)->creator); + if ((*label)->creator) free((*label)->creator); free(*label); *label = NULL; } @@ -109,7 +108,7 @@ int label_compare(struct ltfs_label *label1, struct ltfs_label *label2) return -LTFS_LABEL_MISMATCH; } else if (label1->format_time.tv_sec != label2->format_time.tv_sec || - label1->format_time.tv_nsec != label2->format_time.tv_nsec) { + label1->format_time.tv_nsec != label2->format_time.tv_nsec) { ltfsmsg(LTFS_ERR, 11184E); return -LTFS_LABEL_MISMATCH; @@ -121,8 +120,7 @@ int label_compare(struct ltfs_label *label1, struct ltfs_label *label2) ltfsmsg(LTFS_ERR, 11186E); return -LTFS_LABEL_MISMATCH; - } else if (! ltfs_is_valid_partid(label1->partid_dp) || - ! ltfs_is_valid_partid(label1->partid_ip)) { + } else if (!ltfs_is_valid_partid(label1->partid_dp) || !ltfs_is_valid_partid(label1->partid_ip)) { ltfsmsg(LTFS_ERR, 11187E); return -LTFS_LABEL_MISMATCH; @@ -130,15 +128,12 @@ int label_compare(struct ltfs_label *label1, struct ltfs_label *label2) ltfsmsg(LTFS_ERR, 11188E); return -LTFS_LABEL_MISMATCH; - } else if (label2->partid_dp != label1->partid_dp || - label2->partid_ip != label1->partid_ip) { + } else if (label2->partid_dp != label1->partid_dp || label2->partid_ip != label1->partid_ip) { ltfsmsg(LTFS_ERR, 11189E); return -LTFS_LABEL_MISMATCH; - } else if ((label1->this_partition != label1->partid_dp && - label1->this_partition != label1->partid_ip) || - (label2->this_partition != label1->partid_dp && - label2->this_partition != label1->partid_ip)) { + } else if ((label1->this_partition != label1->partid_dp && label1->this_partition != label1->partid_ip) || + (label2->this_partition != label1->partid_dp && label2->this_partition != label1->partid_ip)) { ltfsmsg(LTFS_ERR, 11190E); return -LTFS_LABEL_MISMATCH; @@ -174,13 +169,12 @@ int label_compare(struct ltfs_label *label1, struct ltfs_label *label2) void label_make_ansi_label(struct ltfs_volume *vol, char *label, size_t size) { size_t barcode_len; - memset(label,' ',size); - memcpy(label,"VOL1",4); + memset(label, ' ', size); + memcpy(label, "VOL1", 4); barcode_len = strlen(vol->label->barcode); - if (barcode_len > 0) - memcpy(label+4, vol->label->barcode, barcode_len > 6 ? 6 : barcode_len); + if (barcode_len > 0) memcpy(label + 4, vol->label->barcode, barcode_len > 6 ? 6 : barcode_len); label[10] = 'L'; - memcpy(label+24,"LTFS",4); + memcpy(label + 24, "LTFS", 4); /* TODO: fill "owner identifier" field? */ - label[size-1] = '4'; + label[size - 1] = '4'; } diff --git a/src/libltfs/ltfs.c b/src/libltfs/ltfs.c index c0c624b3..471a5b0d 100644 --- a/src/libltfs/ltfs.c +++ b/src/libltfs/ltfs.c @@ -57,35 +57,35 @@ #include "arch/uuid_internal.h" +#include "arch/filename_handling.h" +#include "arch/time_internal.h" +#include "arch/version.h" +#include "dcache.h" #include "fs.h" -#include "ltfs.h" -#include "ltfs_internal.h" +#include "index_criteria.h" +#include "iosched.h" +#include "kmi.h" +#include "label.h" +#include "libltfs/arch/errormap.h" #include "libltfs/ltfslogging.h" +#include "ltfs.h" #include "ltfs_copyright.h" +#include "ltfs_internal.h" +#include "pathname.h" #include "tape.h" #include "tape_ops.h" -#include "pathname.h" -#include "arch/time_internal.h" -#include "index_criteria.h" #include "xattr.h" #include "xml_libltfs.h" -#include "label.h" -#include "arch/version.h" -#include "arch/filename_handling.h" -#include "libltfs/arch/errormap.h" -#include "iosched.h" -#include "dcache.h" -#include "kmi.h" #ifndef MIN -#define MIN(a, b) ((a) < (b) ? (a) : (b)) +# define MIN(a, b) ((a) < (b) ? (a) : (b)) #endif #ifdef mingw_PLATFORM static #endif -volatile char *copyright = LTFS_COPYRIGHT_0"\n"LTFS_COPYRIGHT_1"\n"LTFS_COPYRIGHT_2"\n" \ - LTFS_COPYRIGHT_3"\n"LTFS_COPYRIGHT_4"\n"LTFS_COPYRIGHT_5"\n"; + volatile char *copyright = LTFS_COPYRIGHT_0 "\n" LTFS_COPYRIGHT_1 "\n" LTFS_COPYRIGHT_2 "\n" LTFS_COPYRIGHT_3 + "\n" LTFS_COPYRIGHT_4 "\n" LTFS_COPYRIGHT_5 "\n"; /** \file * The typical use case for this library is as follows. @@ -113,14 +113,14 @@ const char *ltfs_format_version() return LTFS_INDEX_VERSION_STR; } -static inline char* _get_barcode(struct ltfs_volume *vol) +static inline char *_get_barcode(struct ltfs_volume *vol) { char *barcode = NULL; if (vol->label->barcode[0] != ' ') barcode = vol->label->barcode; else - barcode = LTFS_NO_BARCODE; + barcode = LTFS_NO_BARCODE; return barcode; } @@ -163,8 +163,7 @@ int ltfs_fs_init(void) int ret; ret = fs_init_inode(); - if (ret < 0) - ltfsmsg(LTFS_ERR, 17232E, ret); + if (ret < 0) ltfsmsg(LTFS_ERR, 17232E, ret); return ret; } @@ -250,8 +249,7 @@ int ltfs_unset_extra_signal_handler(void) int ret = 0; rc = signal(SIGCONT, SIG_DFL); - if (rc == SIG_ERR) - ret = -LTFS_SIG_HANDLER_ERR; + if (rc == SIG_ERR) ret = -LTFS_SIG_HANDLER_ERR; return ret; } @@ -264,7 +262,7 @@ int ltfs_unset_extra_signal_handler(void) int ltfs_set_signal_handlers(void) #ifdef mingw_PLATFORM { - return 0; + return 0; } #else { @@ -274,19 +272,18 @@ int ltfs_set_signal_handlers(void) /* Terminate by CTRL-C */ ret = signal(SIGINT, _ltfs_terminate); - if(ret == SIG_ERR) - return -LTFS_SIG_HANDLER_ERR; + if (ret == SIG_ERR) return -LTFS_SIG_HANDLER_ERR; /* Terminate by disconnecting terminal */ ret = signal(SIGHUP, _ltfs_terminate); - if(ret == SIG_ERR) { + if (ret == SIG_ERR) { signal(SIGINT, SIG_DFL); return -LTFS_SIG_HANDLER_ERR; } /* Terminate by CTRL-\ */ ret = signal(SIGQUIT, _ltfs_terminate); - if(ret == SIG_ERR) { + if (ret == SIG_ERR) { signal(SIGINT, SIG_DFL); signal(SIGHUP, SIG_DFL); return -LTFS_SIG_HANDLER_ERR; @@ -294,7 +291,7 @@ int ltfs_set_signal_handlers(void) /* Terminate by default signal of kill command */ ret = signal(SIGTERM, _ltfs_terminate); - if(ret == SIG_ERR) { + if (ret == SIG_ERR) { signal(SIGINT, SIG_DFL); signal(SIGHUP, SIG_DFL); signal(SIGQUIT, SIG_DFL); @@ -312,7 +309,7 @@ int ltfs_set_signal_handlers(void) int ltfs_unset_signal_handlers(void) #ifdef mingw_PLATFORM { - return 0; + return 0; } #else { @@ -320,20 +317,16 @@ int ltfs_unset_signal_handlers(void) int ret = 0; rc = signal(SIGINT, SIG_DFL); - if (rc == SIG_ERR) - ret = -LTFS_SIG_HANDLER_ERR; + if (rc == SIG_ERR) ret = -LTFS_SIG_HANDLER_ERR; rc = signal(SIGHUP, SIG_DFL); - if (rc == SIG_ERR) - ret = -LTFS_SIG_HANDLER_ERR; + if (rc == SIG_ERR) ret = -LTFS_SIG_HANDLER_ERR; rc = signal(SIGQUIT, SIG_DFL); - if (rc == SIG_ERR) - ret = -LTFS_SIG_HANDLER_ERR; + if (rc == SIG_ERR) ret = -LTFS_SIG_HANDLER_ERR; rc = signal(SIGTERM, SIG_DFL); - if (rc == SIG_ERR) - ret = -LTFS_SIG_HANDLER_ERR; + if (rc == SIG_ERR) ret = -LTFS_SIG_HANDLER_ERR; return ret; } @@ -418,8 +411,7 @@ int ltfs_volume_alloc(const char *execname, struct ltfs_volume **volume) } if (execname) { - ret = asprintf(&newvol->creator, CREATOR_STRING_FORMAT, - "IBM LTFS", PACKAGE_VERSION, PLATFORM, execname); + ret = asprintf(&newvol->creator, CREATOR_STRING_FORMAT, "IBM LTFS", PACKAGE_VERSION, PLATFORM, execname); if (ret < 0) { /* Memory allocation failed */ ltfsmsg(LTFS_ERR, 10001E, "ltfs_volume_alloc, creator string"); @@ -459,19 +451,13 @@ void _ltfs_volume_free(bool force, struct ltfs_volume **volume) if (volume && *volume) { label_free(&(*volume)->label); _ltfs_index_free(force, &(*volume)->index); - if ((*volume)->device) - tape_device_free(&(*volume)->device, (*volume)->kmi_handle, false); - - if ((*volume)->last_block) - free((*volume)->last_block); - if ((*volume)->creator) - free((*volume)->creator); - if ((*volume)->mountpoint) - free((*volume)->mountpoint); - if ((*volume)->t_attr) - free((*volume)->t_attr); - if ((*volume)->index_cache_path) - free((*volume)->index_cache_path); + if ((*volume)->device) tape_device_free(&(*volume)->device, (*volume)->kmi_handle, false); + + if ((*volume)->last_block) free((*volume)->last_block); + if ((*volume)->creator) free((*volume)->creator); + if ((*volume)->mountpoint) free((*volume)->mountpoint); + if ((*volume)->t_attr) free((*volume)->t_attr); + if ((*volume)->index_cache_path) free((*volume)->index_cache_path); destroy_mrsw(&(*volume)->lock); ltfs_thread_mutex_destroy(&(*volume)->reval_lock); ltfs_thread_cond_destroy(&(*volume)->reval_cond); @@ -507,8 +493,7 @@ int ltfs_device_open(const char *devname, struct tape_ops *ops, struct ltfs_volu CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); ret = tape_device_open(vol->device, devname, ops, vol->kmi_handle); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = tape_get_max_blocksize(vol->device, &block_size); if (ret < 0) { @@ -535,14 +520,12 @@ int ltfs_device_reopen(const char *devname, struct ltfs_volume *vol) */ void ltfs_device_close(struct ltfs_volume *vol) { - if (vol) - tape_device_close(vol->device, vol->kmi_handle, false); + if (vol) tape_device_close(vol->device, vol->kmi_handle, false); } void ltfs_device_close_skip_append_only_mode(struct ltfs_volume *vol) { - if (vol) - _tape_device_close(vol->device, vol->kmi_handle, true, false); + if (vol) _tape_device_close(vol->device, vol->kmi_handle, true, false); } /** @@ -558,14 +541,12 @@ int ltfs_setup_device(struct ltfs_volume *vol) /* Check a cartrige is loaded or at lock position and suppress unnessesary senses before issueing mode select in follwing part */ ret = tape_is_cartridge_loadable(vol->device); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* Set Programmable Early Warning Space so that half of Index partition space is reserved for index file. */ ret = tape_set_pews(vol->device, vol->set_pew); - if (ret < 0) - return ret; + if (ret < 0) return ret; if (vol->append_only_mode) { ltfsmsg(LTFS_INFO, 17157I, "to append-only mode"); @@ -574,8 +555,7 @@ int ltfs_setup_device(struct ltfs_volume *vol) /* Check write mode and reset to write-anywhere mode if required. */ ltfsmsg(LTFS_INFO, 17157I, "to write-anywhere mode"); ret = tape_get_append_only_mode_setting(vol->device, &enabled); - if (ret < 0) - return ret; + if (ret < 0) return ret; if (enabled) { ltfsmsg(LTFS_INFO, 17157I, "from append-only mode to write-anywhere mode"); ret = tape_enable_append_only_mode(vol->device, false); @@ -599,8 +579,7 @@ int ltfs_test_unit_ready(struct ltfs_volume *vol) start: ret = ltfs_get_volume_lock(false, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = tape_device_lock(vol->device); if (ret == -LTFS_DEVICE_FENCED) { ret = ltfs_wait_revalidation(vol); @@ -619,8 +598,7 @@ int ltfs_test_unit_ready(struct ltfs_volume *vol) tape_start_fence(vol->device); tape_device_unlock(vol->device); ret = ltfs_revalidate(false, vol); - if (ret == 0) - goto start; + if (ret == 0) goto start; } else if (IS_UNEXPECTED_MOVE(ret)) { vol->reval = -LTFS_REVAL_FAILED; tape_device_unlock(vol->device); @@ -629,8 +607,7 @@ int ltfs_test_unit_ready(struct ltfs_volume *vol) /* Users generally don't care what kind of backend error occurred, only that * the device is not ready. This is needed to ensure that FUSE operations * return EBUSY when getting device readiness fails. */ - if (ret <= -EDEV_ERR_MIN) - ret = -LTFS_DEVICE_UNREADY; + if (ret <= -EDEV_ERR_MIN) ret = -LTFS_DEVICE_UNREADY; tape_device_unlock(vol->device); releaseread_mrsw(&vol->lock); } @@ -695,21 +672,18 @@ int ltfs_capacity_data(struct device_capacity *cap, struct ltfs_volume *vol) start: ret = ltfs_get_volume_lock(false, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = ltfs_capacity_data_unlocked(cap, vol); if (ret == -LTFS_DEVICE_FENCED) { ret = ltfs_wait_revalidation(vol); - if (ret == 0) - goto start; + if (ret == 0) goto start; } else if (NEED_REVAL(ret)) { ret = ltfs_revalidate(false, vol); - if (ret == 0) - goto start; + if (ret == 0) goto start; } else if (IS_UNEXPECTED_MOVE(ret)) { vol->reval = -LTFS_REVAL_FAILED; releaseread_mrsw(&vol->lock); - }else + } else releaseread_mrsw(&vol->lock); return ret; } @@ -842,17 +816,14 @@ int ltfs_get_tape_alert(uint64_t *tape_alert, struct ltfs_volume *vol) start: ret = ltfs_get_volume_lock(false, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = ltfs_get_tape_alert_unlocked(tape_alert, vol); if (ret == -LTFS_DEVICE_FENCED) { ret = ltfs_wait_revalidation(vol); - if (ret == 0) - goto start; + if (ret == 0) goto start; } else if (NEED_REVAL(ret)) { ret = ltfs_revalidate(false, vol); - if (ret == 0) - goto start; + if (ret == 0) goto start; } else if (IS_UNEXPECTED_MOVE(ret)) { vol->reval = -LTFS_REVAL_FAILED; releaseread_mrsw(&vol->lock); @@ -960,10 +931,10 @@ int ltfs_get_params_unlocked(struct device_param *params, struct ltfs_volume *vo vol->reval = -LTFS_REVAL_FAILED; if (!ret) { - params->max_blksize = tc_params.max_blksize; - params->cart_type = tc_params.cart_type; - params->density = tc_params.density; - params->write_protected = tc_params.write_protect; + params->max_blksize = tc_params.max_blksize; + params->cart_type = tc_params.cart_type; + params->density = tc_params.density; + params->write_protected = tc_params.write_protect; /* TODO: Following field shall be implemented in the future */ //params->is_encrypted = tc_params.is_encrypted; //params->is_worm = tc_params.is_worm; @@ -1087,17 +1058,15 @@ unsigned long ltfs_get_blocksize(struct ltfs_volume *vol) CHECK_ARG_NULL(vol, 0); ret = ltfs_get_volume_lock(false, vol); - if (ret < 0) - return 0; - if (! vol->label) { + if (ret < 0) return 0; + if (!vol->label) { releaseread_mrsw(&vol->lock); return LTFS_DEFAULT_BLOCKSIZE; } blocksize = vol->label->blocksize; releaseread_mrsw(&vol->lock); - if (!blocksize) - blocksize = LTFS_DEFAULT_BLOCKSIZE; + if (!blocksize) blocksize = LTFS_DEFAULT_BLOCKSIZE; return blocksize; } @@ -1110,9 +1079,8 @@ bool ltfs_get_compression(struct ltfs_volume *vol) CHECK_ARG_NULL(vol, false); ret = ltfs_get_volume_lock(false, vol); - if (ret < 0) - return false; - if (! vol->label) { + if (ret < 0) return false; + if (!vol->label) { releaseread_mrsw(&vol->lock); return false; } @@ -1130,9 +1098,8 @@ struct ltfs_timespec ltfs_get_format_time(struct ltfs_volume *vol) CHECK_ARG_NULL(vol, ret); err = ltfs_get_volume_lock(false, vol); - if (err < 0) - return ret; - if (! vol->label) { + if (err < 0) return ret; + if (!vol->label) { releaseread_mrsw(&vol->lock); return ret; } @@ -1152,9 +1119,8 @@ uint64_t ltfs_get_file_count(struct ltfs_volume *vol) int err; CHECK_ARG_NULL(vol, 0); err = ltfs_get_volume_lock(false, vol); - if (err < 0) - return 0; - if (! vol->index) { + if (err < 0) return 0; + if (!vol->index) { releaseread_mrsw(&vol->lock); return 0; } @@ -1176,8 +1142,7 @@ uint64_t ltfs_get_valid_block_count(struct ltfs_volume *vol) int err; err = ltfs_get_volume_lock(false, vol); - if (err < 0) - return 0; + if (err < 0) return 0; ret = ltfs_get_valid_block_count_unlocked(vol); releaseread_mrsw(&vol->lock); @@ -1195,8 +1160,7 @@ uint64_t ltfs_get_valid_block_count_unlocked(struct ltfs_volume *vol) uint64_t ret; CHECK_ARG_NULL(vol, 0); - if (! vol->index) - return 0; + if (!vol->index) return 0; ltfs_mutex_lock(&vol->index->dirty_lock); ret = vol->index->valid_blocks; @@ -1216,8 +1180,7 @@ int ltfs_update_valid_block_count(struct ltfs_volume *vol, int64_t c) int ret; ret = ltfs_get_volume_lock(false, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = ltfs_update_valid_block_count_unlocked(vol, c); releaseread_mrsw(&vol->lock); @@ -1249,8 +1212,7 @@ unsigned int ltfs_get_index_generation(struct ltfs_volume *vol) int err; CHECK_ARG_NULL(vol, 0); err = ltfs_get_volume_lock(false, vol); - if (err < 0) - return 0; + if (err < 0) return 0; ret = vol->index->generation; releaseread_mrsw(&vol->lock); return ret; @@ -1263,8 +1225,7 @@ struct ltfs_timespec ltfs_get_index_time(struct ltfs_volume *vol) memset(&ret, 0, sizeof(ret)); CHECK_ARG_NULL(vol, ret); err = ltfs_get_volume_lock(false, vol); - if (err < 0) - return ret; + if (err < 0) return ret; ret = vol->index->mod_time; releaseread_mrsw(&vol->lock); return ret; @@ -1277,8 +1238,7 @@ struct tape_offset ltfs_get_index_selfpointer(struct ltfs_volume *vol) memset(&ret, 0, sizeof(ret)); CHECK_ARG_NULL(vol, ret); err = ltfs_get_volume_lock(false, vol); - if (err < 0) - return ret; + if (err < 0) return ret; ret = vol->index->selfptr; releaseread_mrsw(&vol->lock); return ret; @@ -1291,8 +1251,7 @@ struct tape_offset ltfs_get_index_backpointer(struct ltfs_volume *vol) memset(&ret, 0, sizeof(ret)); CHECK_ARG_NULL(vol, ret); err = ltfs_get_volume_lock(false, vol); - if (err < 0) - return ret; + if (err < 0) return ret; ret = vol->index->backptr; releaseread_mrsw(&vol->lock); return ret; @@ -1307,11 +1266,10 @@ int ltfs_get_index_commit_message(char **msg, struct ltfs_volume *vol) CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); err = ltfs_get_volume_lock(false, vol); - if (err < 0) - return err; + if (err < 0) return err; if (vol->index->commit_message) { ret = arch_strdup(vol->index->commit_message); - if (! ret) { + if (!ret) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); releaseread_mrsw(&vol->lock); return -LTFS_NO_MEMORY; @@ -1332,11 +1290,10 @@ int ltfs_get_index_creator(char **msg, struct ltfs_volume *vol) CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); err = ltfs_get_volume_lock(false, vol); - if (err < 0) - return err; + if (err < 0) return err; if (vol->index->creator) { ret = arch_strdup(vol->index->creator); - if (! ret) { + if (!ret) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); releaseread_mrsw(&vol->lock); return -LTFS_NO_MEMORY; @@ -1357,11 +1314,10 @@ int ltfs_get_volume_name(char **msg, struct ltfs_volume *vol) CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); err = ltfs_get_volume_lock(false, vol); - if (err < 0) - return err; + if (err < 0) return err; if (vol->index->volume_name.name) { ret = arch_strdup(vol->index->volume_name.name); - if (! ret) { + if (!ret) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); releaseread_mrsw(&vol->lock); return -LTFS_NO_MEMORY; @@ -1380,8 +1336,7 @@ int ltfs_get_index_version(struct ltfs_volume *vol) CHECK_ARG_NULL(vol, 0); ret = ltfs_get_volume_lock(false, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; ltfs_mutex_lock(&vol->index->dirty_lock); ret = vol->index->version; ltfs_mutex_unlock(&vol->index->dirty_lock); @@ -1400,8 +1355,7 @@ int ltfs_get_index_version(struct ltfs_volume *vol) const struct index_criteria *ltfs_get_index_criteria(struct ltfs_volume *vol) { CHECK_ARG_NULL(vol, NULL); - if (vol->index) - return &vol->index->index_criteria; + if (vol->index) return &vol->index->index_criteria; return NULL; } @@ -1475,8 +1429,7 @@ int ltfs_start_mount(bool trial, struct ltfs_volume *vol) ltfsmsg(LTFS_ERR, 17167E, ret); return ret; } else if (cap.max_p0 == 0 || cap.max_p1 == 0) { - if (! trial) - ltfsmsg(LTFS_ERR, 17168E); + if (!trial) ltfsmsg(LTFS_ERR, 17168E); return -LTFS_NOT_PARTITIONED; } @@ -1511,16 +1464,16 @@ int ltfs_start_mount(bool trial, struct ltfs_volume *vol) return 0; } -static inline int _ltfs_search_index_wp(bool recover_symlink, bool can_skip_ip, - struct tc_position *seekpos, struct ltfs_volume *vol) +static inline int +_ltfs_search_index_wp(bool recover_symlink, bool can_skip_ip, struct tc_position *seekpos, struct ltfs_volume *vol) { int ret = 0; tape_block_t end_pos, index_end_pos; bool fm_after, blocks_after; ltfsmsg(LTFS_INFO, 17284I, "IP"); - ret = ltfs_seek_index(vol->label->partid_ip, &end_pos, &index_end_pos, &fm_after, - &blocks_after, recover_symlink, vol); + ret = + ltfs_seek_index(vol->label->partid_ip, &end_pos, &index_end_pos, &fm_after, &blocks_after, recover_symlink, vol); if (ret) { if (can_skip_ip) { ltfsmsg(LTFS_INFO, 17289I); @@ -1533,17 +1486,20 @@ static inline int _ltfs_search_index_wp(bool recover_symlink, bool can_skip_ip, } ltfsmsg(LTFS_INFO, 17284I, "DP"); - ret = ltfs_seek_index(vol->label->partid_dp, &end_pos, &index_end_pos, &fm_after, - &blocks_after, recover_symlink, vol); + ret = + ltfs_seek_index(vol->label->partid_dp, &end_pos, &index_end_pos, &fm_after, &blocks_after, recover_symlink, vol); if (ret < 0) { ltfsmsg(LTFS_ERR, 17285E, "DP", ret); return -LTFS_INDEX_INVALID; } /* Use the latest index on the tape */ - ltfsmsg(LTFS_INFO, 17288I, - (unsigned long long)vol->ip_coh.count, (unsigned long long)vol->ip_coh.set_id, - (unsigned long long)vol->dp_coh.count, (unsigned long long)vol->dp_coh.set_id); + ltfsmsg(LTFS_INFO, + 17288I, + (unsigned long long)vol->ip_coh.count, + (unsigned long long)vol->ip_coh.set_id, + (unsigned long long)vol->dp_coh.count, + (unsigned long long)vol->dp_coh.set_id); if (vol->ip_coh.count > vol->dp_coh.count) { seekpos->partition = ltfs_part_id2num(vol->label->partid_ip, vol); @@ -1568,8 +1524,12 @@ static inline int _ltfs_search_index_wp(bool recover_symlink, bool can_skip_ip, * @param vol the volume to load * @return 0 on success or a negative value on error. */ -int ltfs_mount(bool force_full, bool deep_recovery, bool recover_extra, bool recover_symlink, - unsigned short gen, struct ltfs_volume *vol) +int ltfs_mount(bool force_full, + bool deep_recovery, + bool recover_extra, + bool recover_symlink, + unsigned short gen, + struct ltfs_volume *vol) { int ret = 0; uint64_t volume_change_ref; @@ -1607,7 +1567,7 @@ int ltfs_mount(bool force_full, bool deep_recovery, bool recover_extra, bool rec tape_get_cart_volume_lock_status(vol->device, &vollock); tape_get_worm_status(vol->device, &vol->device->is_worm); - if ( strcmp("true", tape_get_media_encrypted(vol->device)) ) { + if (strcmp("true", tape_get_media_encrypted(vol->device))) { vol->device->is_encrypted = false; } else vol->device->is_encrypted = true; @@ -1616,22 +1576,19 @@ int ltfs_mount(bool force_full, bool deep_recovery, bool recover_extra, bool rec INTERRUPTED_GOTO(ret, out_unlock); ret = ltfs_check_eod_status(vol); if (!vol->skip_eod_check && !is_worm_recovery_mount && !IS_SINGLE_WRITE_PERM(vollock)) { - if (ret < 0) - goto out_unlock; + if (ret < 0) goto out_unlock; } /* read MAM parameters. */ INTERRUPTED_GOTO(ret, out_unlock); - ret = tape_get_cart_coherency(vol->device, ltfs_part_id2num(vol->label->partid_ip, vol), - &vol->ip_coh); + ret = tape_get_cart_coherency(vol->device, ltfs_part_id2num(vol->label->partid_ip, vol), &vol->ip_coh); if (ret != 0 || strcmp(vol->ip_coh.uuid, vol->label->vol_uuid)) { /* MAM parameter for index partition invalid */ ltfsmsg(LTFS_WARN, 11016W); memset(&vol->ip_coh, 0, sizeof(struct tc_coherency)); } - ret = tape_get_cart_coherency(vol->device, ltfs_part_id2num(vol->label->partid_dp, vol), - &vol->dp_coh); + ret = tape_get_cart_coherency(vol->device, ltfs_part_id2num(vol->label->partid_dp, vol), &vol->dp_coh); if (ret != 0 || strcmp(vol->dp_coh.uuid, vol->label->vol_uuid)) { /* attribute was invalid */ /* MAM parameter for data partition invalid */ ltfsmsg(LTFS_WARN, 11017W); @@ -1648,8 +1605,7 @@ int ltfs_mount(bool force_full, bool deep_recovery, bool recover_extra, bool rec /* Don't trust version 0 MAM parameters. LTFS versions up to 1.0.1 have * a bug that writes incorrect data to one partition's MAM parameter. */ - if (vol->ip_coh.version == 0 || vol->dp_coh.version == 0) - force_full = true; + if (vol->ip_coh.version == 0 || vol->dp_coh.version == 0) force_full = true; ltfsmsg(LTFS_DEBUG, 11018D); /* Done reading MAM parameters */ ltfsmsg(LTFS_DEBUG, 11019D); /* Checking volume consistency... */ @@ -1679,10 +1635,14 @@ int ltfs_mount(bool force_full, bool deep_recovery, bool recover_extra, bool rec break; } - ltfsmsg(LTFS_INFO, 11333I, vl_print, - (unsigned long long)vol->ip_coh.count, (unsigned long long)vol->ip_coh.volume_change_ref, - (unsigned long long)vol->dp_coh.count, (unsigned long long)vol->dp_coh.volume_change_ref, - (unsigned long long)volume_change_ref); + ltfsmsg(LTFS_INFO, + 11333I, + vl_print, + (unsigned long long)vol->ip_coh.count, + (unsigned long long)vol->ip_coh.volume_change_ref, + (unsigned long long)vol->dp_coh.count, + (unsigned long long)vol->dp_coh.volume_change_ref, + (unsigned long long)volume_change_ref); ltfs_mutex_lock(&vol->device->read_only_flag_mutex); vol->device->write_error = true; @@ -1704,14 +1664,14 @@ int ltfs_mount(bool force_full, bool deep_recovery, bool recover_extra, bool rec * This would happen when the drive returns an error against acquiring the VCR * while write error handling. */ - ltfsmsg(LTFS_INFO, 17283I, - (unsigned long long)vol->dp_coh.volume_change_ref, - (unsigned long long)volume_change_ref); + ltfsmsg(LTFS_INFO, + 17283I, + (unsigned long long)vol->dp_coh.volume_change_ref, + (unsigned long long)volume_change_ref); /* Index of IP could be corrupted. So set skip flag to true */ ret = _ltfs_search_index_wp(recover_symlink, true, &seekpos, vol); - if (ret < 0) - goto out_unlock; + if (ret < 0) goto out_unlock; } else { ltfsmsg(LTFS_INFO, 17286I, "DP", (unsigned long long)volume_change_ref); @@ -1734,9 +1694,10 @@ int ltfs_mount(bool force_full, bool deep_recovery, bool recover_extra, bool rec * This would happen when the drive returns an error against acquiring the VCR * while write error handling. */ - ltfsmsg(LTFS_INFO, 17283I, - (unsigned long long)vol->dp_coh.volume_change_ref, - (unsigned long long)volume_change_ref); + ltfsmsg(LTFS_INFO, + 17283I, + (unsigned long long)vol->dp_coh.volume_change_ref, + (unsigned long long)volume_change_ref); if (vollock == PWE_MAM_BOTH) { /* Index of IP could be corrupted (because of double write perm). So set skip flag to true */ @@ -1745,8 +1706,7 @@ int ltfs_mount(bool force_full, bool deep_recovery, bool recover_extra, bool rec /* Index of DP could be corrupted. So set skip flag to false */ ret = _ltfs_search_index_wp(recover_symlink, false, &seekpos, vol); } - if (ret < 0) - goto out_unlock; + if (ret < 0) goto out_unlock; } else { ltfsmsg(LTFS_INFO, 17286I, "IP", (unsigned long long)volume_change_ref); @@ -1755,12 +1715,9 @@ int ltfs_mount(bool force_full, bool deep_recovery, bool recover_extra, bool rec } } - if (vol->label->part_num2id[seekpos.partition] == vol->label->partid_ip) - read_ip = true; + if (vol->label->part_num2id[seekpos.partition] == vol->label->partid_ip) read_ip = true; - ltfsmsg(LTFS_INFO, 17287I, - vol->label->part_num2id[seekpos.partition], - (unsigned long long)seekpos.block); + ltfsmsg(LTFS_INFO, 17287I, vol->label->part_num2id[seekpos.partition], (unsigned long long)seekpos.block); ret = tape_seek(vol->device, &seekpos); if (ret == -EDEV_EOD_DETECTED) { @@ -1792,9 +1749,8 @@ int ltfs_mount(bool force_full, bool deep_recovery, bool recover_extra, bool rec vol->mount_type = MOUNT_ERR_TAPE; } } - } else if (! force_full && volume_change_ref > 0 - && volume_change_ref == vol->ip_coh.volume_change_ref - && volume_change_ref == vol->dp_coh.volume_change_ref) { + } else if (!force_full && volume_change_ref > 0 && volume_change_ref == vol->ip_coh.volume_change_ref && + volume_change_ref == vol->dp_coh.volume_change_ref) { if (vol->ip_coh.count < vol->dp_coh.count) { seekpos.partition = ltfs_part_id2num(vol->label->partid_dp, vol); seekpos.block = vol->dp_coh.set_id; @@ -1821,8 +1777,7 @@ int ltfs_mount(bool force_full, bool deep_recovery, bool recover_extra, bool rec INTERRUPTED_GOTO(ret, out_unlock); ltfsmsg(LTFS_INFO, 11022I); ret = ltfs_write_index(vol->label->partid_ip, SYNC_RECOVERY, vol); - if (ret < 0) - goto out_unlock; + if (ret < 0) goto out_unlock; } } else { seekpos.partition = ltfs_part_id2num(vol->label->partid_ip, vol); @@ -1867,19 +1822,16 @@ int ltfs_mount(bool force_full, bool deep_recovery, bool recover_extra, bool rec /* Make roll back mount if necessary */ INTERRUPTED_GOTO(ret, out_unlock); - if(gen != 0 && gen != vol->index->generation) { - if(is_worm_recovery_mount){ + if (gen != 0 && gen != vol->index->generation) { + if (is_worm_recovery_mount) { ret = ltfs_traverse_index_no_eod(vol, ltfs_ip_id(vol), gen, NULL, NULL, NULL); - if(ret < 0) - ret = ltfs_traverse_index_no_eod(vol, ltfs_dp_id(vol), gen, NULL, NULL, NULL); - } else if(vol->traverse_mode == TRAVERSE_FORWARD){ + if (ret < 0) ret = ltfs_traverse_index_no_eod(vol, ltfs_dp_id(vol), gen, NULL, NULL, NULL); + } else if (vol->traverse_mode == TRAVERSE_FORWARD) { ret = ltfs_traverse_index_forward(vol, ltfs_ip_id(vol), gen, NULL, NULL, NULL); - if(ret < 0) - ret = ltfs_traverse_index_forward(vol, ltfs_dp_id(vol), gen, NULL, NULL, NULL); + if (ret < 0) ret = ltfs_traverse_index_forward(vol, ltfs_dp_id(vol), gen, NULL, NULL, NULL); } else { ret = ltfs_traverse_index_backward(vol, ltfs_ip_id(vol), gen, NULL, NULL, NULL); - if(ret < 0) - ret = ltfs_traverse_index_backward(vol, ltfs_dp_id(vol), gen, NULL, NULL, NULL); + if (ret < 0) ret = ltfs_traverse_index_backward(vol, ltfs_dp_id(vol), gen, NULL, NULL, NULL); } if (ret < 0) { ltfsmsg(LTFS_ERR, 17079E, gen); @@ -1902,8 +1854,7 @@ int ltfs_mount(bool force_full, bool deep_recovery, bool recover_extra, bool rec } /* Issue a warning if the UID space is exhausted: new create/mkdir requests will be rejected */ - if (vol->index->uid_number == 0) - ltfsmsg(LTFS_WARN, 11307W, vol->label->vol_uuid); + if (vol->index->uid_number == 0) ltfsmsg(LTFS_WARN, 11307W, vol->label->vol_uuid); /* Clear the commit message so it doesn't carry over from the previous session */ /* TODO: is this the right place to clear the commit message? */ @@ -1917,12 +1868,11 @@ int ltfs_mount(bool force_full, bool deep_recovery, bool recover_extra, bool rec vol->dp_index_file_end = true; /* load tape attribute from Cartridge Memory*/ - if (!vol->t_attr) - ret = ltfs_load_all_attributes(vol); + if (!vol->t_attr) ret = ltfs_load_all_attributes(vol); if (vol->t_attr->vollock != vol->index->vollock) { /* Handle write permed cartridge otherwise trust index */ - switch(vol->t_attr->vollock) { + switch (vol->t_attr->vollock) { case PWE_MAM: case PWE_MAM_DP: case PWE_MAM_IP: @@ -1939,14 +1889,15 @@ int ltfs_mount(bool force_full, bool deep_recovery, bool recover_extra, bool rec barcode = _get_barcode(vol); - ltfsmsg(LTFS_INFO, 11031I, - barcode, - (unsigned long long)vol->index->generation, - vol->index->selfptr.partition, - (unsigned long long)vol->index->selfptr.block, - vol->index->backptr.partition, - (unsigned long long)vol->index->backptr.block, - tape_get_serialnumber(vol->device)); + ltfsmsg(LTFS_INFO, + 11031I, + barcode, + (unsigned long long)vol->index->generation, + vol->index->selfptr.partition, + (unsigned long long)vol->index->selfptr.block, + vol->index->backptr.partition, + (unsigned long long)vol->index->backptr.block, + tape_get_serialnumber(vol->device)); out_unlock: if (index && vol->index) @@ -1954,8 +1905,7 @@ int ltfs_mount(bool force_full, bool deep_recovery, bool recover_extra, bool rec else if (index && !vol->index) vol->index = index; - if (ret < 0 && vol->index) - ltfs_index_free(&vol->index); + if (ret < 0 && vol->index) ltfs_index_free(&vol->index); return ret; } @@ -1970,8 +1920,8 @@ int ltfs_load_all_attributes(struct ltfs_volume *vol) if (!vol->t_attr) { /* load tape attribute from Cartridge Memory*/ - vol->t_attr = (struct tape_attr *) calloc(1, sizeof(struct tape_attr)); - if (! vol->t_attr) { + vol->t_attr = (struct tape_attr *)calloc(1, sizeof(struct tape_attr)); + if (!vol->t_attr) { ltfsmsg(LTFS_ERR, 10001E, "ltfs_load_all_attribute: vol->t_attr"); ret = -LTFS_NO_MEMORY; } else @@ -1992,19 +1942,15 @@ void ltfs_set_index_dirty(bool locking, bool atime, struct ltfs_index *idx) { bool was_dirty; if (idx) { - if (locking) - ltfs_mutex_lock(&idx->dirty_lock); + if (locking) ltfs_mutex_lock(&idx->dirty_lock); was_dirty = idx->dirty; if (atime) idx->atime_dirty = true; else idx->dirty = true; - if (! atime || (atime && idx->use_atime)) - idx->version = LTFS_INDEX_VERSION; - if (!was_dirty && idx->dirty && dcache_initialized(idx->root->vol)) - dcache_set_dirty(true, idx->root->vol); - if (locking) - ltfs_mutex_unlock(&idx->dirty_lock); + if (!atime || (atime && idx->use_atime)) idx->version = LTFS_INDEX_VERSION; + if (!was_dirty && idx->dirty && dcache_initialized(idx->root->vol)) dcache_set_dirty(true, idx->root->vol); + if (locking) ltfs_mutex_unlock(&idx->dirty_lock); if (!was_dirty && idx->dirty) { ltfsmsg(LTFS_INFO, 11337I, true, _get_barcode(idx->root->vol), idx->root->vol); @@ -2026,10 +1972,8 @@ void ltfs_unset_index_dirty(bool update_version, struct ltfs_index *idx) was_dirty = idx->dirty; idx->dirty = false; idx->atime_dirty = false; - if (was_dirty && dcache_initialized(idx->root->vol)) - dcache_set_dirty(false, idx->root->vol); - if (update_version) - idx->version = LTFS_INDEX_VERSION; + if (was_dirty && dcache_initialized(idx->root->vol)) dcache_set_dirty(false, idx->root->vol); + if (update_version) idx->version = LTFS_INDEX_VERSION; ltfs_mutex_unlock(&idx->dirty_lock); if (was_dirty && !idx->dirty) { @@ -2060,9 +2004,8 @@ int ltfs_unmount(char *reason, struct ltfs_volume *vol) if (!ret) { ret = tape_get_cart_volume_lock_status(vol->device, &vollock); - if (vol->mount_type == MOUNT_NORMAL && - (ltfs_is_dirty(vol) || vol->index->selfptr.partition != ltfs_ip_id(vol)) && - (vollock != PWE_MAM_IP && vollock != PWE_MAM_BOTH)) { + if (vol->mount_type == MOUNT_NORMAL && (ltfs_is_dirty(vol) || vol->index->selfptr.partition != ltfs_ip_id(vol)) && + (vollock != PWE_MAM_IP && vollock != PWE_MAM_BOTH)) { ret = ltfs_write_index(ltfs_ip_id(vol), reason, vol); if (NEED_REVAL(ret)) { ret = ltfs_revalidate(true, vol); @@ -2079,8 +2022,7 @@ int ltfs_unmount(char *reason, struct ltfs_volume *vol) return ret; } } else if (ret < 0) { - if (IS_UNEXPECTED_MOVE(ret)) - vol->reval = -LTFS_REVAL_FAILED; + if (IS_UNEXPECTED_MOVE(ret)) vol->reval = -LTFS_REVAL_FAILED; ltfsmsg(LTFS_ERR, 11033E); /* could not unmount, failed to write Index */ releasewrite_mrsw(&vol->lock); return ret; @@ -2252,8 +2194,7 @@ int ltfs_get_tape_readonly(struct ltfs_volume *vol) CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); ret = tape_read_only(vol->device, ltfs_part_id2num(ltfs_ip_id(vol), vol)); - if (! ret || ret == -LTFS_LESS_SPACE) - ret = tape_read_only(vol->device, ltfs_part_id2num(ltfs_dp_id(vol), vol)); + if (!ret || ret == -LTFS_LESS_SPACE) ret = tape_read_only(vol->device, ltfs_part_id2num(ltfs_dp_id(vol), vol)); if (!ret) { switch (vol->lock_status) { @@ -2310,8 +2251,7 @@ void ltfs_use_atime(bool use_atime, struct ltfs_volume *vol) int ret; if (vol) { ret = ltfs_get_volume_lock(true, vol); - if (ret < 0) - return; + if (ret < 0) return; vol->index->use_atime = use_atime; releasewrite_mrsw(&vol->lock); } @@ -2327,8 +2267,7 @@ void ltfs_set_work_dir(const char *dir, struct ltfs_volume *vol) int ret; if (vol) { ret = ltfs_get_volume_lock(true, vol); - if (ret < 0) - return; + if (ret < 0) return; vol->work_directory = dir; releasewrite_mrsw(&vol->lock); } @@ -2341,8 +2280,7 @@ void ltfs_set_work_dir(const char *dir, struct ltfs_volume *vol) */ void ltfs_set_eod_check(bool use, struct ltfs_volume *vol) { - if (vol) - vol->skip_eod_check = ! use; + if (vol) vol->skip_eod_check = !use; } /** @@ -2356,8 +2294,7 @@ void ltfs_set_traverse_mode(int mode, struct ltfs_volume *vol) ltfsmsg(LTFS_WARN, 11310W, mode); return; } - if (vol) - vol->traverse_mode = mode; + if (vol) vol->traverse_mode = mode; } /** @@ -2377,13 +2314,12 @@ int ltfs_override_policy(const char *rules, bool permanent, struct ltfs_volume * CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); if (vol->index) { - if (! vol->index->criteria_allow_update && ! permanent) + if (!vol->index->criteria_allow_update && !permanent) ret = -LTFS_POLICY_IMMUTABLE; else { ret = index_criteria_parse(rules, vol); if (ret == 0 && permanent) { - ret = index_criteria_dup_rules(&vol->index->original_criteria, - &vol->index->index_criteria); + ret = index_criteria_dup_rules(&vol->index->original_criteria, &vol->index->index_criteria); } } } @@ -2468,10 +2404,9 @@ int ltfs_write_index(char partition, char *reason, struct ltfs_volume *vol) /* Check read-only status. Ignore the out-of-space condition, as this should not * prevent writing an Index. */ ret = ltfs_get_partition_readonly(ltfs_ip_id(vol), vol); - if (! ret || ret == -LTFS_NO_SPACE || ret == -LTFS_LESS_SPACE) + if (!ret || ret == -LTFS_NO_SPACE || ret == -LTFS_LESS_SPACE) ret = ltfs_get_partition_readonly(ltfs_dp_id(vol), vol); - if (ret < 0 && ret != -LTFS_NO_SPACE && ret != -LTFS_LESS_SPACE) - return ret; + if (ret < 0 && ret != -LTFS_NO_SPACE && ret != -LTFS_LESS_SPACE) return ret; } /* There is no need to grab the tape device lock here. All other multithreaded users @@ -2479,11 +2414,8 @@ int ltfs_write_index(char partition, char *reason, struct ltfs_volume *vol) * executes with an exclusive lock on the volume. */ /* write to data partition first if required */ - if (partition == ltfs_ip_id(vol) && - ! write_perm && - (! vol->dp_index_file_end || - (vol->ip_index_file_end && vol->index->selfptr.partition == ltfs_ip_id(vol)))) { - + if (partition == ltfs_ip_id(vol) && !write_perm && + (!vol->dp_index_file_end || (vol->ip_index_file_end && vol->index->selfptr.partition == ltfs_ip_id(vol)))) { /* Surpress on-disk index cache write on the recursive call */ cache_path_save = vol->index_cache_path; vol->index_cache_path = NULL; @@ -2584,7 +2516,7 @@ int ltfs_write_index(char partition, char *reason, struct ltfs_volume *vol) /* Write the Index. */ if ((partition == ltfs_ip_id(vol)) && !vol->ip_index_file_end) { - ret = tape_write_filemark(vol->device, 0, true, true, false); // Flush data before writing FM + ret = tape_write_filemark(vol->device, 0, true, true, false); // Flush data before writing FM if (ret < 0) { ltfsmsg(LTFS_ERR, 11326E, ret); if (generation_inc) { @@ -2594,15 +2526,19 @@ int ltfs_write_index(char partition, char *reason, struct ltfs_volume *vol) vol->index->backptr = old_backptr; vol->index->selfptr = old_selfptr; - if (IS_WRITE_PERM(-ret)) - update_vollock = true; + if (IS_WRITE_PERM(-ret)) update_vollock = true; goto out_write_perm; } } - ltfsmsg(LTFS_INFO, 17235I, bc_print, partition, reason, - (unsigned long long)vol->index->file_count, tape_get_serialnumber(vol->device)); + ltfsmsg(LTFS_INFO, + 17235I, + bc_print, + partition, + reason, + (unsigned long long)vol->index->file_count, + tape_get_serialnumber(vol->device)); ret = tape_write_filemark(vol->device, 1, true, true, true); // immediate WFM if (ret < 0) { @@ -2614,8 +2550,7 @@ int ltfs_write_index(char partition, char *reason, struct ltfs_volume *vol) vol->index->backptr = old_backptr; vol->index->selfptr = old_selfptr; - if (IS_WRITE_PERM(-ret)) - update_vollock = true; + if (IS_WRITE_PERM(-ret)) update_vollock = true; goto out_write_perm; } @@ -2631,8 +2566,7 @@ int ltfs_write_index(char partition, char *reason, struct ltfs_volume *vol) vol->index->backptr = old_backptr; vol->index->selfptr = old_selfptr; - if (IS_WRITE_PERM(-ret)) - update_vollock = true; + if (IS_WRITE_PERM(-ret)) update_vollock = true; goto out_write_perm; } @@ -2647,17 +2581,17 @@ int ltfs_write_index(char partition, char *reason, struct ltfs_volume *vol) * ignore failures when updating MAM parameters. */ ltfs_update_cart_coherency(vol); - ltfsmsg(LTFS_INFO, 17236I, - bc_print, - (unsigned long long)vol->index->generation, - vol->index->selfptr.partition, - (unsigned long long)vol->index->selfptr.block, - tape_get_serialnumber(vol->device)); + ltfsmsg(LTFS_INFO, + 17236I, + bc_print, + (unsigned long long)vol->index->generation, + vol->index->selfptr.partition, + (unsigned long long)vol->index->selfptr.block, + tape_get_serialnumber(vol->device)); /* update append position */ if (partition == ltfs_ip_id(vol)) { - tape_set_ip_append_position(vol->device, ltfs_part_id2num(partition, vol), - vol->index->selfptr.block - 1); + tape_set_ip_append_position(vol->device, ltfs_part_id2num(partition, vol), vol->index->selfptr.block - 1); } if (dcache_initialized(vol)) { @@ -2689,8 +2623,7 @@ int ltfs_write_index(char partition, char *reason, struct ltfs_volume *vol) if (new_volstat) { ret_mam = tape_set_cart_volume_lock_status(vol, new_volstat); - if (ret_mam) - ret = ret_mam; + if (ret_mam) ret = ret_mam; } } @@ -2705,7 +2638,7 @@ int ltfs_write_index(char partition, char *reason, struct ltfs_volume *vol) * @param vol LTFS volume * @return 0 on success or a negative value on error */ -int ltfs_save_index_to_disk(const char *work_dir, char * reason, bool need_gen, struct ltfs_volume *vol) +int ltfs_save_index_to_disk(const char *work_dir, char *reason, bool need_gen, struct ltfs_volume *vol) { char *path; int ret; @@ -2734,9 +2667,7 @@ int ltfs_save_index_to_disk(const char *work_dir, char * reason, bool need_gen, return -ENOMEM; } - - ltfsmsg(LTFS_INFO, 17235I, _get_barcode(vol), 'Z', "Volume Cache", - (unsigned long long)vol->index->file_count, path); + ltfsmsg(LTFS_INFO, 17235I, _get_barcode(vol), 'Z', "Volume Cache", (unsigned long long)vol->index->file_count, path); ret = xml_schema_to_file(path, vol->index->creator, reason, vol->index); if (ret < 0) { @@ -2752,12 +2683,13 @@ int ltfs_save_index_to_disk(const char *work_dir, char * reason, bool need_gen, ltfsmsg(LTFS_ERR, 17184E, errno); } - ltfsmsg(LTFS_INFO, 17236I, - _get_barcode(vol), - (unsigned long long)vol->index->generation, - 'Z', - (unsigned long long)vol->index->selfptr.block, - path); + ltfsmsg(LTFS_INFO, + 17236I, + _get_barcode(vol), + (unsigned long long)vol->index->generation, + 'Z', + (unsigned long long)vol->index->selfptr.block, + path); free(path); return ret; @@ -2771,7 +2703,7 @@ int ltfs_save_index_to_disk(const char *work_dir, char * reason, bool need_gen, */ char ltfs_dp_id(struct ltfs_volume *vol) { - if (! vol || ! vol->label) { + if (!vol || !vol->label) { ltfsmsg(LTFS_WARN, 11090W); return 0; } @@ -2786,7 +2718,7 @@ char ltfs_dp_id(struct ltfs_volume *vol) */ char ltfs_ip_id(struct ltfs_volume *vol) { - if (! vol || ! vol->label) { + if (!vol || !vol->label) { ltfsmsg(LTFS_WARN, 11091W); return 0; } @@ -2815,8 +2747,7 @@ const char *ltfs_get_barcode(struct ltfs_volume *vol) int ltfs_set_blocksize(unsigned long blocksize, struct ltfs_volume *vol) { CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); - if (blocksize < LTFS_MIN_BLOCKSIZE) - return -LTFS_SMALL_BLOCKSIZE; + if (blocksize < LTFS_MIN_BLOCKSIZE) return -LTFS_SMALL_BLOCKSIZE; vol->label->blocksize = blocksize; return 0; } @@ -2844,11 +2775,9 @@ int ltfs_set_barcode(const char *barcode, struct ltfs_volume *vol) CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); if (barcode && strlen(barcode) > 0) { - if (strlen(barcode) != 6) - return -LTFS_BARCODE_LENGTH; + if (strlen(barcode) != 6) return -LTFS_BARCODE_LENGTH; while (*tmp) { - if ((*tmp < '0' || *tmp > '9') && (*tmp < 'A' || *tmp > 'Z')) - return -LTFS_BARCODE_INVALID; + if ((*tmp < '0' || *tmp > '9') && (*tmp < 'A' || *tmp > 'Z')) return -LTFS_BARCODE_INVALID; ++tmp; } arch_strcpy_auto(vol->label->barcode, barcode); @@ -2873,10 +2802,9 @@ int ltfs_set_volume_name(const char *volname, struct ltfs_volume *vol) if (volname) { ret = pathname_validate_file(volname); - if (ret < 0) - return ret; + if (ret < 0) return ret; name_dup = arch_strdup(volname); - if (! name_dup) { + if (!name_dup) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } @@ -2884,8 +2812,7 @@ int ltfs_set_volume_name(const char *volname, struct ltfs_volume *vol) ret = ltfs_get_volume_lock(false, vol); if (ret < 0) { - if (name_dup) - free(name_dup); + if (name_dup) free(name_dup); return ret; } ltfs_mutex_lock(&vol->index->dirty_lock); @@ -2911,10 +2838,8 @@ int ltfs_set_volume_name(const char *volname, struct ltfs_volume *vol) int ltfs_set_partition_map(char dp, char ip, int dp_num, int ip_num, struct ltfs_volume *vol) { CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); - if (dp_num == ip_num || (dp_num != 0 && dp_num != 1) || (ip_num != 0 && ip_num != 1)) - return -LTFS_BAD_PARTNUM; - if (dp < 'a' || dp > 'z' || ip < 'a' || ip > 'z' || dp == ip) - return -LTFS_BAD_PARTNUM; + if (dp_num == ip_num || (dp_num != 0 && dp_num != 1) || (ip_num != 0 && ip_num != 1)) return -LTFS_BAD_PARTNUM; + if (dp < 'a' || dp > 'z' || ip < 'a' || ip > 'z' || dp == ip) return -LTFS_BAD_PARTNUM; vol->label->partid_ip = ip; vol->label->partid_dp = dp; vol->label->part_num2id[dp_num] = dp; @@ -2977,7 +2902,7 @@ int ltfs_write_label(tape_partition_t partition, struct ltfs_volume *vol) /* write XML label */ xml_buf = xml_make_label(vol->creator, partition, vol->label); - if (! xml_buf) { + if (!xml_buf) { ltfsmsg(LTFS_ERR, 11105E); return -LTFS_NO_MEMORY; /* TODO: this is the most likely error, but not the only possible one */ } @@ -3033,7 +2958,7 @@ int ltfs_format_tape(struct ltfs_volume *vol, int density_code, bool destructive /* Sanitize write protected tape */ ret = ltfs_get_partition_readonly(ltfs_ip_id(vol), vol); - if (! ret || ret == -LTFS_NO_SPACE || ret == -LTFS_LESS_SPACE || ret == -LTFS_RDONLY_DEN_DRV) + if (!ret || ret == -LTFS_NO_SPACE || ret == -LTFS_LESS_SPACE || ret == -LTFS_RDONLY_DEN_DRV) ret = ltfs_get_partition_readonly(ltfs_dp_id(vol), vol); if (ret < 0 && ret != -LTFS_NO_SPACE && ret != -LTFS_LESS_SPACE && ret != -LTFS_RDONLY_DEN_DRV) { ltfsmsg(LTFS_ERR, 11095E); @@ -3067,12 +2992,11 @@ int ltfs_format_tape(struct ltfs_volume *vol, int density_code, bool destructive } /* Set up the label: generate UUID and format time */ - ltfs_gen_uuid((vol->label->vol_uuid),sizeof(vol->label->vol_uuid)); + ltfs_gen_uuid((vol->label->vol_uuid), sizeof(vol->label->vol_uuid)); get_current_timespec(&vol->label->format_time); /* Duplicate creator */ - if (vol->label->creator) - free(vol->label->creator); + if (vol->label->creator) free(vol->label->creator); vol->label->creator = arch_strdup(vol->creator); if (!vol->label->creator) { @@ -3137,8 +3061,7 @@ int ltfs_format_tape(struct ltfs_volume *vol, int density_code, bool destructive INTERRUPTED_RETURN(); ltfsmsg(LTFS_INFO, 11100I, vol->label->partid_dp); ret = ltfs_write_label(ltfs_part_id2num(vol->label->partid_dp, vol), vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; ltfsmsg(LTFS_INFO, 11278I, vol->label->partid_dp); /* "Writing Index to ..." */ ret = ltfs_write_index(vol->label->partid_dp, SYNC_FORMAT, vol); if (ret < 0) { @@ -3150,8 +3073,7 @@ int ltfs_format_tape(struct ltfs_volume *vol, int density_code, bool destructive INTERRUPTED_RETURN(); ltfsmsg(LTFS_INFO, 11100I, vol->label->partid_ip); ret = ltfs_write_label(ltfs_part_id2num(vol->label->partid_ip, vol), vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; ltfsmsg(LTFS_INFO, 11278I, vol->label->partid_ip); /* "Writing Index to ..." */ ret = ltfs_write_index(vol->label->partid_ip, SYNC_FORMAT, vol); if (ret < 0) { @@ -3189,8 +3111,7 @@ int ltfs_unformat_tape(struct ltfs_volume *vol, bool long_wipe, bool destructive } ret = ltfs_get_partition_readonly(ltfs_ip_id(vol), vol); - if (! ret || ret == -LTFS_NO_SPACE || ret == -LTFS_LESS_SPACE) - ret = ltfs_get_partition_readonly(ltfs_dp_id(vol), vol); + if (!ret || ret == -LTFS_NO_SPACE || ret == -LTFS_LESS_SPACE) ret = ltfs_get_partition_readonly(ltfs_dp_id(vol), vol); if (ret < 0 && ret != -LTFS_NO_SPACE && ret != -LTFS_LESS_SPACE) { ltfsmsg(LTFS_ERR, 11095E); return ret; @@ -3201,8 +3122,7 @@ int ltfs_unformat_tape(struct ltfs_volume *vol, bool long_wipe, bool destructive if (destructive) { ltfsmsg(LTFS_INFO, 17291I); ret = tape_unformat_hard(vol->device); - } - else { + } else { ltfsmsg(LTFS_INFO, 17071I); ret = tape_unformat(vol->device); } @@ -3272,10 +3192,8 @@ int ltfs_get_volume_lock(bool exclusive, struct ltfs_volume *vol) ret = vol->reval; ltfs_thread_mutex_unlock(&vol->reval_lock); - if (ret < 0) - release_mrsw(&vol->lock); - if (ret == -LTFS_REVAL_RUNNING) - goto start; + if (ret < 0) release_mrsw(&vol->lock); + if (ret == -LTFS_REVAL_RUNNING) goto start; return ret; } @@ -3285,50 +3203,62 @@ int _ltfs_revalidate_mam(struct ltfs_volume *vol) struct tc_coherency coh0, coh1; ret = tape_get_cart_coherency(vol->device, 0, &coh0); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = tape_get_cart_coherency(vol->device, 1, &coh1); - if (ret < 0) - return ret; - - ltfsmsg(LTFS_DEBUG, 17166D, "coh0", - (unsigned long long)coh0.volume_change_ref, (unsigned long long)coh0.count, (unsigned long long)coh0.set_id, - coh0.version, coh0.uuid, vol->label->part_num2id[0]); - ltfsmsg(LTFS_DEBUG, 17166D, "coh1", - (unsigned long long)coh1.volume_change_ref, (unsigned long long)coh1.count, (unsigned long long)coh1.set_id, - coh1.version, coh1.uuid, vol->label->part_num2id[0]); - ltfsmsg(LTFS_DEBUG, 17166D, "IP", - (unsigned long long)vol->ip_coh.volume_change_ref, (unsigned long long)vol->ip_coh.count, (unsigned long long)vol->ip_coh.set_id, - vol->ip_coh.version, vol->ip_coh.uuid, vol->label->partid_ip); - ltfsmsg(LTFS_DEBUG, 17166D, "DP", - (unsigned long long)vol->dp_coh.volume_change_ref, (unsigned long long)vol->dp_coh.count, (unsigned long long)vol->dp_coh.set_id, - vol->dp_coh.version, vol->dp_coh.uuid, vol->label->partid_dp); + if (ret < 0) return ret; + + ltfsmsg(LTFS_DEBUG, + 17166D, + "coh0", + (unsigned long long)coh0.volume_change_ref, + (unsigned long long)coh0.count, + (unsigned long long)coh0.set_id, + coh0.version, + coh0.uuid, + vol->label->part_num2id[0]); + ltfsmsg(LTFS_DEBUG, + 17166D, + "coh1", + (unsigned long long)coh1.volume_change_ref, + (unsigned long long)coh1.count, + (unsigned long long)coh1.set_id, + coh1.version, + coh1.uuid, + vol->label->part_num2id[0]); + ltfsmsg(LTFS_DEBUG, + 17166D, + "IP", + (unsigned long long)vol->ip_coh.volume_change_ref, + (unsigned long long)vol->ip_coh.count, + (unsigned long long)vol->ip_coh.set_id, + vol->ip_coh.version, + vol->ip_coh.uuid, + vol->label->partid_ip); + ltfsmsg(LTFS_DEBUG, + 17166D, + "DP", + (unsigned long long)vol->dp_coh.volume_change_ref, + (unsigned long long)vol->dp_coh.count, + (unsigned long long)vol->dp_coh.set_id, + vol->dp_coh.version, + vol->dp_coh.uuid, + vol->label->partid_dp); if (vol->label->part_num2id[0] == vol->label->partid_dp) { - if (coh0.volume_change_ref != vol->dp_coh.volume_change_ref - || coh0.count != vol->dp_coh.count - || coh0.set_id != vol->dp_coh.set_id - || strcmp(coh0.uuid, vol->dp_coh.uuid) - || coh0.version != vol->dp_coh.version) + if (coh0.volume_change_ref != vol->dp_coh.volume_change_ref || coh0.count != vol->dp_coh.count || + coh0.set_id != vol->dp_coh.set_id || strcmp(coh0.uuid, vol->dp_coh.uuid) || coh0.version != vol->dp_coh.version) return -LTFS_REVAL_FAILED; - else if (coh1.volume_change_ref != vol->ip_coh.volume_change_ref - || coh1.count != vol->ip_coh.count - || coh1.set_id != vol->ip_coh.set_id - || strcmp(coh1.uuid, vol->ip_coh.uuid) - || coh1.version != vol->ip_coh.version) + else if (coh1.volume_change_ref != vol->ip_coh.volume_change_ref || coh1.count != vol->ip_coh.count || + coh1.set_id != vol->ip_coh.set_id || strcmp(coh1.uuid, vol->ip_coh.uuid) || + coh1.version != vol->ip_coh.version) return -LTFS_REVAL_FAILED; } else { - if (coh0.volume_change_ref != vol->ip_coh.volume_change_ref - || coh0.count != vol->ip_coh.count - || coh0.set_id != vol->ip_coh.set_id - || strcmp(coh0.uuid, vol->ip_coh.uuid) - || coh0.version != vol->ip_coh.version) + if (coh0.volume_change_ref != vol->ip_coh.volume_change_ref || coh0.count != vol->ip_coh.count || + coh0.set_id != vol->ip_coh.set_id || strcmp(coh0.uuid, vol->ip_coh.uuid) || coh0.version != vol->ip_coh.version) return -LTFS_REVAL_FAILED; - else if (coh1.volume_change_ref != vol->dp_coh.volume_change_ref - || coh1.count != vol->dp_coh.count - || coh1.set_id != vol->dp_coh.set_id - || strcmp(coh1.uuid, vol->dp_coh.uuid) - || coh1.version != vol->dp_coh.version) + else if (coh1.volume_change_ref != vol->dp_coh.volume_change_ref || coh1.count != vol->dp_coh.count || + coh1.set_id != vol->dp_coh.set_id || strcmp(coh1.uuid, vol->dp_coh.uuid) || + coh1.version != vol->dp_coh.version) return -LTFS_REVAL_FAILED; } @@ -3361,7 +3291,7 @@ int ltfs_revalidate(bool have_write_lock, struct ltfs_volume *vol) vol->reval = -LTFS_REVAL_RUNNING; ltfs_thread_mutex_unlock(&vol->reval_lock); - if (! have_write_lock) { + if (!have_write_lock) { release_mrsw(&vol->lock); acquirewrite_mrsw(&vol->lock); } @@ -3372,20 +3302,17 @@ int ltfs_revalidate(bool have_write_lock, struct ltfs_volume *vol) /* Set up mode pages */ ret = ltfs_setup_device(vol); - if (ret < 0) - goto out; + if (ret < 0) goto out; /* Invalidate device information cache and re-reserve the device */ vol->device->device_reserved = false; vol->device->medium_locked = false; ret = tape_reserve_device(vol->device); - if (ret < 0) - goto out; + if (ret < 0) goto out; /* Re-read labels */ ret = label_alloc(&vol->label); - if (ret < 0) - goto out; + if (ret < 0) goto out; /* This function issue load and refresh the current position */ ret = ltfs_start_mount(false, vol); @@ -3402,27 +3329,22 @@ int ltfs_revalidate(bool have_write_lock, struct ltfs_volume *vol) ret = label_compare(old_label, vol->label); label_free(&vol->label); vol->label = old_label; - if (ret < 0) - goto out; + if (ret < 0) goto out; /* Check EOD status and MAM parameters */ ret = ltfs_check_eod_status(vol); - if (ret < 0) - goto out; + if (ret < 0) goto out; ret = _ltfs_revalidate_mam(vol); - if (ret < 0) - goto out; + if (ret < 0) goto out; /* Find DP EOD */ dp_num = ltfs_part_id2num(ltfs_dp_id(vol), vol); ret = tape_seek_eod(vol->device, dp_num); vol->device->append_pos[dp_num] = append_pos[dp_num]; - if (ret < 0) - goto out; + if (ret < 0) goto out; ret = tape_get_position(vol->device, &eod_pos); - if (ret < 0) - goto out; - if (! vol->dp_index_file_end && vol->device->append_pos[dp_num] == 0) { + if (ret < 0) goto out; + if (!vol->dp_index_file_end && vol->device->append_pos[dp_num] == 0) { /* No way to validate the DP. This shouldn't happen anyway */ ret = -LTFS_REVAL_FAILED; goto out; @@ -3431,11 +3353,9 @@ int ltfs_revalidate(bool have_write_lock, struct ltfs_volume *vol) /* Check for DP index */ if (vol->dp_index_file_end) { ret = tape_spacefm(vol->device, -1); - if (ret < 0) - goto out; + if (ret < 0) goto out; ret = tape_get_position(vol->device, &pos); - if (ret < 0) - goto out; + if (ret < 0) goto out; if (pos.block != eod_pos.block - 1) { /* Partition does not end in a file mark */ ret = -LTFS_REVAL_FAILED; @@ -3443,21 +3363,16 @@ int ltfs_revalidate(bool have_write_lock, struct ltfs_volume *vol) } ret = tape_spacefm(vol->device, -1); - if (ret < 0) - goto out; + if (ret < 0) goto out; ret = tape_spacefm(vol->device, 1); - if (ret < 0) - goto out; + if (ret < 0) goto out; ret = tape_get_position(vol->device, &pos); - if (ret < 0) - goto out; - if (vol->index->selfptr.partition == ltfs_dp_id(vol) && - vol->index->selfptr.block != pos.block) { + if (ret < 0) goto out; + if (vol->index->selfptr.partition == ltfs_dp_id(vol) && vol->index->selfptr.block != pos.block) { ret = -LTFS_REVAL_FAILED; goto out; - } else if (vol->index->selfptr.partition != ltfs_dp_id(vol) && - vol->index->backptr.partition == ltfs_dp_id(vol) && - vol->index->backptr.block != pos.block) { + } else if (vol->index->selfptr.partition != ltfs_dp_id(vol) && vol->index->backptr.partition == ltfs_dp_id(vol) && + vol->index->backptr.block != pos.block) { ret = -LTFS_REVAL_FAILED; goto out; } @@ -3475,14 +3390,12 @@ int ltfs_revalidate(bool have_write_lock, struct ltfs_volume *vol) /* Find IP EOD */ ip_num = ltfs_part_id2num(ltfs_ip_id(vol), vol); ret = tape_seek_eod(vol->device, ip_num); - if (ret < 0) - goto out; + if (ret < 0) goto out; vol->device->append_pos[ip_num] = append_pos[ip_num]; ret = tape_get_position(vol->device, &eod_pos); - if (ret < 0) - goto out; + if (ret < 0) goto out; - if (! vol->ip_index_file_end && vol->device->append_pos[ip_num] == 0) { + if (!vol->ip_index_file_end && vol->device->append_pos[ip_num] == 0) { /* No way to validate the IP. This shouldn't happen anyway */ ret = -LTFS_REVAL_FAILED; goto out; @@ -3491,11 +3404,9 @@ int ltfs_revalidate(bool have_write_lock, struct ltfs_volume *vol) /* Check for IP index */ if (vol->ip_index_file_end) { ret = tape_spacefm(vol->device, -1); - if (ret < 0) - goto out; + if (ret < 0) goto out; ret = tape_get_position(vol->device, &pos); - if (ret < 0) - goto out; + if (ret < 0) goto out; if (pos.block != eod_pos.block - 1) { /* Partition does not end in a file mark */ ret = -LTFS_REVAL_FAILED; @@ -3503,23 +3414,18 @@ int ltfs_revalidate(bool have_write_lock, struct ltfs_volume *vol) } ret = tape_spacefm(vol->device, -1); - if (ret < 0) - goto out; + if (ret < 0) goto out; ret = tape_spacefm(vol->device, 1); - if (ret < 0) - goto out; + if (ret < 0) goto out; ret = tape_get_position(vol->device, &pos); - if (ret < 0) - goto out; - if (vol->index->selfptr.partition == ltfs_ip_id(vol) && - vol->index->selfptr.block != pos.block) { + if (ret < 0) goto out; + if (vol->index->selfptr.partition == ltfs_ip_id(vol) && vol->index->selfptr.block != pos.block) { ret = -LTFS_REVAL_FAILED; goto out; } } else { ret = tape_get_position(vol->device, &pos); - if (ret < 0) - goto out; + if (ret < 0) goto out; } /* Check IP append position */ @@ -3570,13 +3476,11 @@ int ltfs_sync_index(char *reason, bool index_locking, struct ltfs_volume *vol) start: ret = ltfs_get_partition_readonly(ltfs_dp_id(vol), vol); - if (ret < 0 && ret != -LTFS_LESS_SPACE) - return ret; + if (ret < 0 && ret != -LTFS_LESS_SPACE) return ret; if (index_locking) { ret = ltfs_get_volume_lock(false, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; } ltfs_mutex_lock(&vol->index->dirty_lock); @@ -3585,8 +3489,7 @@ int ltfs_sync_index(char *reason, bool index_locking, struct ltfs_volume *vol) dp_index_file_end = vol->dp_index_file_end; ip_index_file_end = vol->ip_index_file_end; - if (index_locking) - releaseread_mrsw(&vol->lock); + if (index_locking) releaseread_mrsw(&vol->lock); if (dirty) { bc_print = _get_barcode(vol); @@ -3598,14 +3501,13 @@ int ltfs_sync_index(char *reason, bool index_locking, struct ltfs_volume *vol) /* If the DP ends in an index and the IP doesn't, then we're most likely positioned * at the end of the IP, and writing an index there is allowed without first putting * down a DP index. */ - if (dp_index_file_end && ! ip_index_file_end) + if (dp_index_file_end && !ip_index_file_end) partition = ltfs_ip_id(vol); else /* Otherwise, it's faster to write an index to the DP. */ partition = ltfs_dp_id(vol); if (index_locking) { ret = ltfs_get_volume_lock(true, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; } /* @@ -3618,8 +3520,7 @@ int ltfs_sync_index(char *reason, bool index_locking, struct ltfs_volume *vol) ret = tape_device_lock(vol->device); if (ret < 0) { ltfsmsg(LTFS_ERR, 12010E, __FUNCTION__); - if (index_locking) - releasewrite_mrsw(&vol->lock); + if (index_locking) releasewrite_mrsw(&vol->lock); return ret; } ret = ltfs_write_index(partition, reason, vol); @@ -3649,17 +3550,14 @@ int ltfs_sync_index(char *reason, bool index_locking, struct ltfs_volume *vol) } tape_device_unlock(vol->device); - if (IS_UNEXPECTED_MOVE(ret)) - vol->reval = -LTFS_REVAL_FAILED; + if (IS_UNEXPECTED_MOVE(ret)) vol->reval = -LTFS_REVAL_FAILED; if (index_locking && NEED_REVAL(ret)) { ret = ltfs_revalidate(true, vol); - if (ret == 0) - goto start; + if (ret == 0) goto start; } else if (index_locking) releasewrite_mrsw(&vol->lock); - if (ret) - ltfsmsg(LTFS_ERR, 17069E); + if (ret) ltfsmsg(LTFS_ERR, 17069E); ltfsmsg(LTFS_INFO, 17070I, bc_print, ret, vol->device->serial_number); } else { @@ -3680,8 +3578,8 @@ int ltfs_sync_index(char *reason, bool index_locking, struct ltfs_volume *vol) * @param priv private data for call back function * @return 0 on success or a negative value on error */ -int ltfs_traverse_index_no_eod(struct ltfs_volume *vol, char partition, unsigned int gen, - f_index_found func, void **list, void* priv) +int ltfs_traverse_index_no_eod( + struct ltfs_volume *vol, char partition, unsigned int gen, f_index_found func, void **list, void *priv) { int ret, func_ret; @@ -3700,19 +3598,17 @@ int ltfs_traverse_index_no_eod(struct ltfs_volume *vol, char partition, unsigned return ret; } else if (ret == -LTFS_UNSUPPORTED_INDEX_VERSION) { ret = tape_spacefm(vol->device, 1); - if (ret < 0) - return ret; + if (ret < 0) return ret; vol->index->generation = -1; vol->index->selfptr.block = vol->device->position.block - 1; - vol->index->selfptr.partition = - vol->label->part_num2id[vol->device->position.partition]; + vol->index->selfptr.partition = vol->label->part_num2id[vol->device->position.partition]; } ltfsmsg(LTFS_DEBUG, 17080D, 'N', vol->index->generation, partition); if (func) { func_ret = (*func)(vol, gen, list, priv); - if(func_ret < 0) { + if (func_ret < 0) { ltfsmsg(LTFS_ERR, 17081E, 'N', func_ret, partition); return func_ret; } else if (func_ret > 0) /* Break if call back function returns positive value */ @@ -3720,8 +3616,7 @@ int ltfs_traverse_index_no_eod(struct ltfs_volume *vol, char partition, unsigned } INTERRUPTED_RETURN(); - if(vol->index->generation != (unsigned int)-1 && gen != 0 && vol->index->generation >= gen) - break; + if (vol->index->generation != (unsigned int)-1 && gen != 0 && vol->index->generation >= gen) break; ret = tape_locate_next_index(vol->device); if (ret < 0) { @@ -3730,8 +3625,8 @@ int ltfs_traverse_index_no_eod(struct ltfs_volume *vol, char partition, unsigned } } - if(gen != 0) { - if(vol->index->generation != gen) { + if (gen != 0) { + if (vol->index->generation != gen) { ltfsmsg(LTFS_DEBUG, 17078D, 'N', gen, partition); return -LTFS_NO_INDEX; } else { @@ -3753,8 +3648,8 @@ int ltfs_traverse_index_no_eod(struct ltfs_volume *vol, char partition, unsigned * @param priv private data for call back function * @return 0 on success or a negative value on error */ -int ltfs_traverse_index_forward(struct ltfs_volume *vol, char partition, unsigned int gen, - f_index_found func, void **list, void* priv) +int ltfs_traverse_index_forward( + struct ltfs_volume *vol, char partition, unsigned int gen, f_index_found func, void **list, void *priv) { int ret, func_ret; struct tape_offset last_index; @@ -3783,18 +3678,16 @@ int ltfs_traverse_index_forward(struct ltfs_volume *vol, char partition, unsigne return ret; } else if (ret == -LTFS_UNSUPPORTED_INDEX_VERSION) { ret = tape_spacefm(vol->device, 1); - if (ret < 0) - return ret; + if (ret < 0) return ret; vol->index->generation = -1; vol->index->selfptr.block = vol->device->position.block - 1; - vol->index->selfptr.partition = - vol->label->part_num2id[vol->device->position.partition]; + vol->index->selfptr.partition = vol->label->part_num2id[vol->device->position.partition]; } ltfsmsg(LTFS_DEBUG, 17080D, 'F', vol->index->generation, partition); if (func) { func_ret = (*func)(vol, gen, list, priv); - if(func_ret < 0) { + if (func_ret < 0) { ltfsmsg(LTFS_ERR, 17081E, 'F', func_ret, partition); return func_ret; } else if (func_ret > 0) /* Break if call back function returns positive value */ @@ -3802,8 +3695,7 @@ int ltfs_traverse_index_forward(struct ltfs_volume *vol, char partition, unsigne } INTERRUPTED_RETURN(); - if(vol->index->generation != (unsigned int)-1 && gen != 0 && vol->index->generation >= gen) - break; + if (vol->index->generation != (unsigned int)-1 && gen != 0 && vol->index->generation >= gen) break; if (last_index.block > vol->device->position.block) { ret = tape_locate_next_index(vol->device); @@ -3814,8 +3706,8 @@ int ltfs_traverse_index_forward(struct ltfs_volume *vol, char partition, unsigne } } - if(gen != 0) { - if(vol->index->generation != gen) { + if (gen != 0) { + if (vol->index->generation != gen) { ltfsmsg(LTFS_DEBUG, 17078D, 'F', gen, partition); return -LTFS_NO_INDEX; } else { @@ -3836,8 +3728,8 @@ int ltfs_traverse_index_forward(struct ltfs_volume *vol, char partition, unsigne * @param list this pointer is specified as 3rd arguments of call back function * @return 0 on success or a negative value on error */ -int ltfs_traverse_index_backward(struct ltfs_volume *vol, char partition, unsigned int gen, - f_index_found func, void **list, void* priv) +int ltfs_traverse_index_backward( + struct ltfs_volume *vol, char partition, unsigned int gen, f_index_found func, void **list, void *priv) { int ret, func_ret; @@ -3848,8 +3740,7 @@ int ltfs_traverse_index_backward(struct ltfs_volume *vol, char partition, unsign } while (1) { - if (4 >= vol->device->position.block) - break; + if (4 >= vol->device->position.block) break; ltfs_index_free(&vol->index); ltfs_index_alloc(&vol->index, vol); @@ -3859,19 +3750,17 @@ int ltfs_traverse_index_backward(struct ltfs_volume *vol, char partition, unsign return ret; } else if (ret == -LTFS_UNSUPPORTED_INDEX_VERSION) { ret = tape_spacefm(vol->device, 1); - if (ret < 0) - return ret; + if (ret < 0) return ret; vol->index->generation = -1; vol->index->selfptr.block = vol->device->position.block - 1; - vol->index->selfptr.partition = - vol->label->part_num2id[vol->device->position.partition]; + vol->index->selfptr.partition = vol->label->part_num2id[vol->device->position.partition]; } ltfsmsg(LTFS_DEBUG, 17080D, 'B', vol->index->generation, partition); if (func) { func_ret = (*func)(vol, gen, list, priv); - if(func_ret < 0) { + if (func_ret < 0) { ltfsmsg(LTFS_ERR, 17081E, 'B', func_ret, partition); return func_ret; } else if (func_ret > 0) /* Break if call back function returns positive value */ @@ -3879,8 +3768,7 @@ int ltfs_traverse_index_backward(struct ltfs_volume *vol, char partition, unsign } INTERRUPTED_RETURN(); - if(vol->index->generation != (unsigned int)-1 && gen != 0 && vol->index->generation <= gen) - break; + if (vol->index->generation != (unsigned int)-1 && gen != 0 && vol->index->generation <= gen) break; ret = tape_locate_previous_index(vol->device); if (ret < 0) { @@ -3889,8 +3777,8 @@ int ltfs_traverse_index_backward(struct ltfs_volume *vol, char partition, unsign } } - if(gen != 0) { - if(vol->index->generation != gen) { + if (gen != 0) { + if (vol->index->generation != gen) { ltfsmsg(LTFS_DEBUG, 17078D, 'B', gen, partition); return -LTFS_NO_INDEX; } else { @@ -3916,23 +3804,21 @@ int ltfs_check_eod_status(struct ltfs_volume *vol) int eod_status_ip, eod_status_dp; bool is_worm; - eod_status_ip = tape_check_eod_status(vol->device, - ltfs_part_id2num(vol->label->partid_ip, vol)); + eod_status_ip = tape_check_eod_status(vol->device, ltfs_part_id2num(vol->label->partid_ip, vol)); eod_status_dp = tape_check_eod_status(vol->device, ltfs_part_id2num(vol->label->partid_dp, vol)); - if(eod_status_ip == EOD_UNKNOWN || eod_status_dp == EOD_UNKNOWN) { + if (eod_status_ip == EOD_UNKNOWN || eod_status_dp == EOD_UNKNOWN) { /* Backend cannnot support EOD status check, print warning */ ltfsmsg(LTFS_WARN, 17145W); ltfsmsg(LTFS_INFO, 17147I); - } else if(eod_status_ip == EOD_MISSING || eod_status_dp == EOD_MISSING) { + } else if (eod_status_ip == EOD_MISSING || eod_status_dp == EOD_MISSING) { ret = tape_get_worm_status(vol->device, &is_worm); /* EOD is missing in both or one of partitions, print message and exit */ - if(eod_status_ip == EOD_MISSING && eod_status_dp == EOD_MISSING) { + if (eod_status_ip == EOD_MISSING && eod_status_dp == EOD_MISSING) { ltfsmsg(LTFS_ERR, 17142E); if (is_worm) { ltfsmsg(LTFS_ERR, 17207E); - } - else { + } else { ltfsmsg(LTFS_ERR, 17148E); } ret = -LTFS_BOTH_EOD_MISSING; @@ -3940,8 +3826,7 @@ int ltfs_check_eod_status(struct ltfs_volume *vol) ltfsmsg(LTFS_ERR, 17146E, "IP", ltfs_part_id2num(vol->label->partid_ip, vol)); if (is_worm) { ltfsmsg(LTFS_ERR, 17207E); - } - else { + } else { ltfsmsg(LTFS_ERR, 17148E); } ret = -LTFS_EOD_MISSING_MEDIUM; @@ -3949,8 +3834,7 @@ int ltfs_check_eod_status(struct ltfs_volume *vol) ltfsmsg(LTFS_ERR, 17146E, "DP", ltfs_part_id2num(vol->label->partid_dp, vol)); if (is_worm) { ltfsmsg(LTFS_ERR, 17207E); - } - else { + } else { ltfsmsg(LTFS_ERR, 17148E); } ret = -LTFS_EOD_MISSING_MEDIUM; @@ -3982,24 +3866,21 @@ static int _ltfs_detect_final_rec_dp(struct ltfs_volume *vol, struct tc_position /* Read the final index of IP */ INTERRUPTED_RETURN(); ltfsmsg(LTFS_INFO, 17114I); - ret = ltfs_seek_index(vol->label->partid_ip, &end_pos, &index_end_pos, - &fm_after, &blocks_after, false, vol); + ret = ltfs_seek_index(vol->label->partid_ip, &end_pos, &index_end_pos, &fm_after, &blocks_after, false, vol); if (ret < 0) { ltfsmsg(LTFS_ERR, 17115E); return ret; } /* Compare self pointer and a pointer in MAM */ - if (vol->index->generation == ip_coh_gen && - vol->index->generation == dp_coh_gen) { + if (vol->index->generation == ip_coh_gen && vol->index->generation == dp_coh_gen) { /* * MAM points Index partition, Locate to the back pointer of IP and * read the index pointed to the back pointer */ seekpos.block = vol->index->backptr.block; seekpos.partition = ltfs_part_id2num(vol->index->backptr.partition, vol); - } else if (dp_coh_gen == ip_coh_gen && - vol->index->generation != ip_coh_gen) { + } else if (dp_coh_gen == ip_coh_gen && vol->index->generation != ip_coh_gen) { /* * MAM points Data partition, Locate to the position pointed to MAM and * read the index @@ -4007,10 +3888,7 @@ static int _ltfs_detect_final_rec_dp(struct ltfs_volume *vol, struct tc_position seekpos.block = vol->ip_coh.set_id; seekpos.partition = ltfs_part_id2num(vol->label->partid_dp, vol); } else { - ltfsmsg(LTFS_ERR, 17123E, - vol->index->generation, - ip_coh_gen, - dp_coh_gen); + ltfsmsg(LTFS_ERR, 17123E, vol->index->generation, ip_coh_gen, dp_coh_gen); return -LTFS_UNEXPECTED_VALUE; } @@ -4018,7 +3896,7 @@ static int _ltfs_detect_final_rec_dp(struct ltfs_volume *vol, struct tc_position ltfsmsg(LTFS_INFO, 17118I, "DP", (unsigned long long)seekpos.partition, (unsigned long long)seekpos.block); ret = tape_seek(vol->device, &seekpos); if (ret < 0) { - ltfsmsg(LTFS_ERR, 17119E, "DP", ret); + ltfsmsg(LTFS_ERR, 17119E, "DP", ret); return ret; } @@ -4026,7 +3904,7 @@ static int _ltfs_detect_final_rec_dp(struct ltfs_volume *vol, struct tc_position ltfsmsg(LTFS_INFO, 17120I, "DP", (unsigned long long)seekpos.partition, (unsigned long long)seekpos.block); ret = ltfs_read_index(0, false, vol); if (ret < 0) { - ltfsmsg(LTFS_ERR, 17121E, "DP", ret); + ltfsmsg(LTFS_ERR, 17121E, "DP", ret); return ret; } @@ -4051,8 +3929,7 @@ int _ltfs_detect_final_rec_ip(struct ltfs_volume *vol, struct tc_position *pos) the final index of DP */ INTERRUPTED_RETURN(); ltfsmsg(LTFS_INFO, 17116I); - ret = ltfs_seek_index(vol->label->partid_dp, &end_pos, &index_end_pos, - &fm_after, &blocks_after, false, vol); + ret = ltfs_seek_index(vol->label->partid_dp, &end_pos, &index_end_pos, &fm_after, &blocks_after, false, vol); if (ret < 0) { ltfsmsg(LTFS_ERR, 17117E); return ret; @@ -4065,8 +3942,8 @@ int _ltfs_detect_final_rec_ip(struct ltfs_volume *vol, struct tc_position *pos) seekpos.partition = ltfs_part_id2num(vol->label->partid_ip, vol); ltfsmsg(LTFS_INFO, 17124I, "IP", (unsigned long long)seekpos.partition, (unsigned long long)seekpos.block); ret = tape_seek(vol->device, &seekpos); - if (ret < 0){ - ltfsmsg(LTFS_ERR, 17125E, "DP", ret); + if (ret < 0) { + ltfsmsg(LTFS_ERR, 17125E, "DP", ret); return ret; } @@ -4092,24 +3969,24 @@ int ltfs_recover_eod(struct ltfs_volume *vol) INTERRUPTED_RETURN(); eod_status_ip = tape_check_eod_status(vol->device, ltfs_part_id2num(vol->label->partid_ip, vol)); eod_status_dp = tape_check_eod_status(vol->device, ltfs_part_id2num(vol->label->partid_dp, vol)); - if(eod_status_ip == EOD_UNKNOWN || eod_status_dp == EOD_UNKNOWN) { + if (eod_status_ip == EOD_UNKNOWN || eod_status_dp == EOD_UNKNOWN) { /* Backend cannnot support EOD status check */ ltfsmsg(LTFS_ERR, 17140E); return -LTFS_UNSUPPORTED; - } else if(eod_status_ip == EOD_GOOD && eod_status_dp == EOD_GOOD) { + } else if (eod_status_ip == EOD_GOOD && eod_status_dp == EOD_GOOD) { /* Both EODs are good, no need to perform EOD recovery */ ltfsmsg(LTFS_INFO, 17141I); return 0; - } else if(eod_status_ip == EOD_MISSING && eod_status_dp == EOD_MISSING) { + } else if (eod_status_ip == EOD_MISSING && eod_status_dp == EOD_MISSING) { /* Both EODs are missing, Unrecoverable */ ltfsmsg(LTFS_ERR, 17142E); return -LTFS_UNSUPPORTED; - } else if(eod_status_ip == EOD_GOOD && eod_status_dp == EOD_MISSING) { + } else if (eod_status_ip == EOD_GOOD && eod_status_dp == EOD_MISSING) { /* EOD of DP is missing */ ltfsmsg(LTFS_INFO, 17143I, "DP", ltfs_part_id2num(vol->label->partid_dp, vol)); no_eod_part_id = vol->label->partid_dp; (void)ltfs_part_id2num(vol->label->partid_dp, vol); - } else if(eod_status_ip == EOD_MISSING && eod_status_dp == EOD_GOOD) { + } else if (eod_status_ip == EOD_MISSING && eod_status_dp == EOD_GOOD) { /* EOD of IP is missing */ ltfsmsg(LTFS_INFO, 17143I, "IP", ltfs_part_id2num(vol->label->partid_ip, vol)); no_eod_part_id = vol->label->partid_ip; @@ -4122,26 +3999,23 @@ int ltfs_recover_eod(struct ltfs_volume *vol) /* Check version field in MAM */ INTERRUPTED_RETURN(); - ret = tape_get_cart_coherency(vol->device, ltfs_part_id2num(vol->label->partid_ip, vol), - &vol->ip_coh); + ret = tape_get_cart_coherency(vol->device, ltfs_part_id2num(vol->label->partid_ip, vol), &vol->ip_coh); if (ret < 0) { ltfsmsg(LTFS_ERR, 17144E, "IP"); return ret; } - ret = tape_get_cart_coherency(vol->device, ltfs_part_id2num(vol->label->partid_dp, vol), - &vol->dp_coh); + ret = tape_get_cart_coherency(vol->device, ltfs_part_id2num(vol->label->partid_dp, vol), &vol->dp_coh); if (ret < 0) { ltfsmsg(LTFS_ERR, 17144E, "DP"); return ret; } - if(vol->ip_coh.version == 0 && vol->dp_coh.version == 0){ + if (vol->ip_coh.version == 0 && vol->dp_coh.version == 0) { /* MAM is written by PGA1 or earlier */ ltfsmsg(LTFS_INFO, 17110I); need_verify = true; - } else if (vol->ip_coh.version >= 1 && vol->dp_coh.version >= 1 && - vol->ip_coh.version == vol->dp_coh.version){ + } else if (vol->ip_coh.version >= 1 && vol->dp_coh.version >= 1 && vol->ip_coh.version == vol->dp_coh.version) { /* MAM is written by PGA2 or later (includes version2) */ ltfsmsg(LTFS_INFO, 17111I); need_verify = false; @@ -4153,13 +4027,13 @@ int ltfs_recover_eod(struct ltfs_volume *vol) /* Go to final unmount point */ INTERRUPTED_RETURN(); - if(need_verify) { + if (need_verify) { /* MAM points the partition which has EOD */ - if(no_eod_part_id == vol->label->partid_dp) { + if (no_eod_part_id == vol->label->partid_dp) { /* Go to the end of final index of corrupted data partition */ ltfsmsg(LTFS_INFO, 17112I); ret = _ltfs_detect_final_rec_dp(vol, &seekpos); - } else if(no_eod_part_id == vol->label->partid_ip) { + } else if (no_eod_part_id == vol->label->partid_ip) { /* Go to the end of final record of corrupted index partition */ ltfsmsg(LTFS_INFO, 17112I); ret = _ltfs_detect_final_rec_ip(vol, &seekpos); @@ -4174,16 +4048,18 @@ int ltfs_recover_eod(struct ltfs_volume *vol) } } else { /* Go to the end of final index of corrupted partition */ - if(no_eod_part_id == vol->label->partid_ip) { + if (no_eod_part_id == vol->label->partid_ip) { /* * In index partition, Index will be overwritten. * Locate to before the index in IP */ - seekpos.block = vol->ip_coh.set_id - 1; - seekpos.partition = ltfs_part_id2num(vol->label->partid_ip, vol);; - } else if(no_eod_part_id == vol->label->partid_dp) { + seekpos.block = vol->ip_coh.set_id - 1; + seekpos.partition = ltfs_part_id2num(vol->label->partid_ip, vol); + ; + } else if (no_eod_part_id == vol->label->partid_dp) { seekpos.block = vol->dp_coh.set_id; - seekpos.partition = ltfs_part_id2num(vol->label->partid_dp, vol);; + seekpos.partition = ltfs_part_id2num(vol->label->partid_dp, vol); + ; } else { ltfsmsg(LTFS_ERR, 17108E, no_eod_part_id, no_eod_part_id); return -LTFS_UNEXPECTED_VALUE; @@ -4192,24 +4068,22 @@ int ltfs_recover_eod(struct ltfs_volume *vol) /* Locate to target and read index */ ret = tape_seek(vol->device, &seekpos); - if (ret < 0) - return ret; + if (ret < 0) return ret; - if(no_eod_part_id == vol->label->partid_dp) { + if (no_eod_part_id == vol->label->partid_dp) { /* * In index partition, Index will be overwritten. * Read an index only current partition is DP. */ ret = ltfs_read_index(0, false, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; } } /* Recover EOD status */ INTERRUPTED_RETURN(); ret = tape_recover_eod_status(vol->device, vol->kmi_handle); - if(ret < 0) { + if (ret < 0) { ltfsmsg(LTFS_ERR, 17137E, ret); return ret; } @@ -4230,13 +4104,12 @@ int ltfs_release_medium(struct ltfs_volume *vol) bool loaded = false; /* Check cartridge is already loaded not not */ - for(i = 0; i < 3&& ret < 0; i++) { + for (i = 0; i < 3 && ret < 0; i++) { ret = tape_test_unit_ready(vol->device); } loaded = (ret == 0); - if(loaded) - tape_unload_tape(false, vol->device); + if (loaded) tape_unload_tape(false, vol->device); return 0; } @@ -4254,8 +4127,8 @@ int ltfs_release_medium(struct ltfs_volume *vol) * @param size buffer size * @return page length on success or a negative value on error */ -int ltfs_logpage(const uint8_t page, const uint8_t subpage, unsigned char *buf, - const size_t size, struct ltfs_volume *vol) +int ltfs_logpage( + const uint8_t page, const uint8_t subpage, unsigned char *buf, const size_t size, struct ltfs_volume *vol) { int ret = -EDEV_UNKNOWN; @@ -4280,8 +4153,7 @@ int ltfs_logpage(const uint8_t page, const uint8_t subpage, unsigned char *buf, * @param size buffer size * @return MAM length on success or a negative value on error */ -int ltfs_mam(const tape_partition_t part, unsigned char *buf, - const size_t size, struct ltfs_volume *vol) +int ltfs_mam(const tape_partition_t part, unsigned char *buf, const size_t size, struct ltfs_volume *vol) { int ret = -EDEV_UNKNOWN; @@ -4346,14 +4218,14 @@ void ltfs_recover_eod_simple(struct ltfs_volume *vol) */ int ltfs_print_device_list(struct tape_ops *ops) { - struct tc_drive_info* buf = NULL; + struct tc_drive_info *buf = NULL; int i, count = 0, info_count = 0, c = 0, ret = 0; /* Get device count */ count = tape_get_device_list(ops, NULL, 0); if (count) { buf = (struct tc_drive_info *)calloc(count * 2, sizeof(struct tc_drive_info)); - if (! buf) { + if (!buf) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); ret = -LTFS_NO_MEMORY; return ret; @@ -4365,16 +4237,20 @@ int ltfs_print_device_list(struct tape_ops *ops) ltfsresult(17073I); c = MIN(info_count, (count * 2)); for (i = 0; i < c; i++) { - if (buf[i].name[0] && buf[i].vendor[0] && - buf[i].model[0] && buf[i].serial_number[0] && - buf[i].product_name[0]) { - + if (buf[i].name[0] && buf[i].vendor[0] && buf[i].model[0] && buf[i].serial_number[0] && buf[i].product_name[0]) { if (buf[i].lun == -1) { - ltfsresult(17074I, buf[i].name, - buf[i].vendor, buf[i].model, buf[i].serial_number, buf[i].product_name); + ltfsresult(17074I, buf[i].name, buf[i].vendor, buf[i].model, buf[i].serial_number, buf[i].product_name); } else { - ltfsresult(17098I, buf[i].name, buf[i].host, buf[i].channel, buf[i].target, buf[i].lun, - buf[i].vendor, buf[i].model, buf[i].serial_number, buf[i].product_name); + ltfsresult(17098I, + buf[i].name, + buf[i].host, + buf[i].channel, + buf[i].target, + buf[i].lun, + buf[i].vendor, + buf[i].model, + buf[i].serial_number, + buf[i].product_name); } } } @@ -4408,34 +4284,32 @@ int ltfs_profiler_set(uint64_t source, struct ltfs_volume *vol) if (vol->iosched_handle) { if (source & PROF_IOSCHED) { - ret = iosched_set_profiler((char*)vol->work_directory, true, vol); + ret = iosched_set_profiler((char *)vol->work_directory, true, vol); } else { - ret = iosched_set_profiler((char*)vol->work_directory, false, vol); + ret = iosched_set_profiler((char *)vol->work_directory, false, vol); } - if (ret) - ret_save = ret; + if (ret) ret_save = ret; } if (vol->device) { if (source & PROF_DRIVER) { - ret = tape_set_profiler(vol->device, (char*)vol->work_directory, true); + ret = tape_set_profiler(vol->device, (char *)vol->work_directory, true); } else { - ret = tape_set_profiler(vol->device, (char*)vol->work_directory, false); + ret = tape_set_profiler(vol->device, (char *)vol->work_directory, false); } } - if (!ret && ret_save) - ret = ret_save; + if (!ret && ret_save) ret = ret_save; return ret; } static int _ltfs_write_rao_file(char *file_path_org, unsigned char *buf, size_t len) { - int ret = -EDEV_UNKNOWN; + int ret = -EDEV_UNKNOWN; char *path; - int fd = -1; + int fd = -1; ssize_t size = 0; ret = asprintf(&path, "%s%s", file_path_org, LTFS_OUT_FILE_EXTENSION); @@ -4443,10 +4317,8 @@ static int _ltfs_write_rao_file(char *file_path_org, unsigned char *buf, size_t ltfsmsg(LTFS_ERR, 10001E, __FILE__); return -LTFS_NO_MEMORY; } - - arch_open(&fd, path, - O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, - SHARE_FLAG_DENYRW, PERMISSION_READWRITE); + + arch_open(&fd, path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, SHARE_FLAG_DENYRW, PERMISSION_READWRITE); if (fd < 0) { ltfsmsg(LTFS_INFO, 17276I, path, errno); free(path); @@ -4475,12 +4347,11 @@ static int _ltfs_write_rao_file(char *file_path_org, unsigned char *buf, size_t return ret; } -static int _ltfs_read_rao_file(char *file_path, unsigned char *buf, - size_t len, uint32_t *in_size) +static int _ltfs_read_rao_file(char *file_path, unsigned char *buf, size_t len, uint32_t *in_size) { - int ret = -EDEV_UNKNOWN; + int ret = -EDEV_UNKNOWN; char *path; - int fd = -1; + int fd = -1; struct stat sbuf; ssize_t size = 0; @@ -4489,7 +4360,7 @@ static int _ltfs_read_rao_file(char *file_path, unsigned char *buf, ltfsmsg(LTFS_ERR, 10001E, __FILE__); return -LTFS_NO_MEMORY; } - arch_open(&fd, path, O_RDONLY | O_BINARY, SHARE_FLAG_DENYWR, PERMISSION_READ); + arch_open(&fd, path, O_RDONLY | O_BINARY, SHARE_FLAG_DENYWR, PERMISSION_READ); if (fd < 0) { ltfsmsg(LTFS_INFO, 17279I, path, errno); free(path); @@ -4509,7 +4380,8 @@ static int _ltfs_read_rao_file(char *file_path, unsigned char *buf, ltfsmsg(LTFS_INFO, 17281I, path, errno); ret = -errno; goto out; - } if (size != (ssize_t)sbuf.st_size) { + } + if (size != (ssize_t)sbuf.st_size) { ltfsmsg(LTFS_INFO, 17282I, path, size, (ssize_t)sbuf.st_size); ret = LTFS_FILE_ERR; goto out; diff --git a/src/libltfs/ltfs_fsops.c b/src/libltfs/ltfs_fsops.c index 7b2aa4d4..297eedc7 100644 --- a/src/libltfs/ltfs_fsops.c +++ b/src/libltfs/ltfs_fsops.c @@ -55,21 +55,21 @@ ************************************************************************************* */ -#include "ltfs.h" -#include "ltfs_internal.h" #include "ltfs_fsops.h" -#include "ltfs_fsops_raw.h" +#include "arch/time_internal.h" +#include "dcache.h" #include "fs.h" +#include "index_criteria.h" #include "iosched.h" +#include "ltfs.h" +#include "ltfs_fsops_raw.h" +#include "ltfs_internal.h" +#include "pathname.h" +#include "stdbool.h" #include "tape.h" #include "xattr.h" -#include "dcache.h" -#include "pathname.h" -#include "index_criteria.h" -#include "arch/time_internal.h" -int ltfs_fsops_open(const char *path, bool open_write, bool use_iosched, struct dentry **d, - struct ltfs_volume *vol) +int ltfs_fsops_open(const char *path, bool open_write, bool use_iosched, struct dentry **d, struct ltfs_volume *vol) { int ret; char *path_norm; @@ -80,8 +80,7 @@ int ltfs_fsops_open(const char *path, bool open_write, bool use_iosched, struct if (open_write) { ret = ltfs_get_tape_readonly(vol); - if (ret < 0 && ret != -LTFS_LESS_SPACE) - return ret; + if (ret < 0 && ret != -LTFS_LESS_SPACE) return ret; } /* Validate and normalize the path */ @@ -98,36 +97,37 @@ int ltfs_fsops_open(const char *path, bool open_write, bool use_iosched, struct else ret = ltfs_fsraw_open(path_norm, open_write, d, vol); - if ( ret==0 ){ - if ( open_write && (**d).isslink ) { + if (ret == 0) { + if (open_write && (**d).isslink) { ltfs_fsops_close(*d, false, open_write, use_iosched, vol); - ret=-LTFS_RDONLY_VOLUME; - } - else - vol->file_open_count ++; + ret = -LTFS_RDONLY_VOLUME; + } else + vol->file_open_count++; } free(path_norm); return ret; } -int ltfs_fsops_open_combo(const char *path, bool open_write, bool use_iosched, - struct dentry **d, bool *is_readonly, - bool isopendir, struct ltfs_volume *vol) +int ltfs_fsops_open_combo(const char *path, + bool open_write, + bool use_iosched, + struct dentry **d, + bool *is_readonly, + bool isopendir, + struct ltfs_volume *vol) { int ret; char *path_norm; struct dentry *dtmp; - CHECK_ARG_NULL(path, -LTFS_NULL_ARG); CHECK_ARG_NULL(d, -LTFS_NULL_ARG); CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); if (open_write) { ret = ltfs_get_tape_readonly(vol); - if (ret < 0 && ret != -LTFS_LESS_SPACE) - return ret; + if (ret < 0 && ret != -LTFS_LESS_SPACE) return ret; } /* Validate and normalize the path */ @@ -140,21 +140,19 @@ int ltfs_fsops_open_combo(const char *path, bool open_write, bool use_iosched, } ret = ltfs_get_volume_lock(false, vol); - if (ret < 0) - goto out_open_combo; + if (ret < 0) goto out_open_combo; if (dcache_initialized(vol)) ret = dcache_open(path_norm, &dtmp, vol); else ret = fs_path_lookup(path_norm, 0, &dtmp, vol->index); - if (ret<0) { + if (ret < 0) { releaseread_mrsw(&vol->lock); goto out_open_combo; } - if ( (isopendir && !dtmp->isdir) || (!isopendir && dtmp->isdir) ) - ret = -LTFS_NO_DENTRY; + if ((isopendir && !dtmp->isdir) || (!isopendir && dtmp->isdir)) ret = -LTFS_NO_DENTRY; if (dcache_initialized(vol)) dcache_close(dtmp, true, true, vol); @@ -162,16 +160,14 @@ int ltfs_fsops_open_combo(const char *path, bool open_write, bool use_iosched, fs_release_dentry(dtmp); releaseread_mrsw(&vol->lock); - if (ret<0) - goto out_open_combo; + if (ret < 0) goto out_open_combo; if (use_iosched && iosched_initialized(vol)) ret = iosched_open(path_norm, open_write, d, vol); else ret = ltfs_fsraw_open(path_norm, open_write, d, vol); - if (*d && ret == 0) - *is_readonly = (*d)->readonly; + if (*d && ret == 0) *is_readonly = (*d)->readonly; out_open_combo: free(path_norm); @@ -193,22 +189,18 @@ int ltfs_fsops_close(struct dentry *d, bool dirty, bool open_write, bool use_ios d->need_update_time = false; } - if (dirty && dcache_initialized(vol)) - dcache_flush(d, FLUSH_ALL, vol); + if (dirty && dcache_initialized(vol)) dcache_flush(d, FLUSH_ALL, vol); - if (open_write) - ret_u = ltfs_fsops_update_used_blocks(d, vol); + if (open_write) ret_u = ltfs_fsops_update_used_blocks(d, vol); - if (use_iosched && ! d->isdir && iosched_initialized(vol)) + if (use_iosched && !d->isdir && iosched_initialized(vol)) ret = iosched_close(d, dirty, vol); else ret = ltfs_fsraw_close(d); - if ( !ret && ret_u) - ret = ret_u; + if (!ret && ret_u) ret = ret_u; - if (ret == 0 && vol->file_open_count > 0) - vol->file_open_count --; + if (ret == 0 && vol->file_open_count > 0) vol->file_open_count--; return ret; } @@ -235,8 +227,8 @@ int ltfs_fsops_update_used_blocks(struct dentry *d, struct ltfs_volume *vol) return ret; } -int ltfs_fsops_create(const char *path, bool isdir, bool readonly, bool overwrite, struct dentry **dentry, - struct ltfs_volume *vol) +int ltfs_fsops_create( + const char *path, bool isdir, bool readonly, bool overwrite, struct dentry **dentry, struct ltfs_volume *vol) { int ret; char *path_norm, *filename, *dentry_path = NULL; @@ -248,8 +240,7 @@ int ltfs_fsops_create(const char *path, bool isdir, bool readonly, bool overwrit /* Make sure the device is online and writable */ ret = ltfs_get_tape_readonly(vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = ltfs_test_unit_ready(vol); if (ret < 0) { ltfsmsg(LTFS_ERR, 11047E); @@ -259,8 +250,7 @@ int ltfs_fsops_create(const char *path, bool isdir, bool readonly, bool overwrit /* Validate and normalize the path */ ret = pathname_format(path, &path_norm, true, true); if (ret < 0) { - if (ret != -LTFS_INVALID_PATH) - ltfsmsg(LTFS_ERR, 11048E, ret); + if (ret != -LTFS_INVALID_PATH) ltfsmsg(LTFS_ERR, 11048E, ret); return ret; } @@ -283,8 +273,7 @@ int ltfs_fsops_create(const char *path, bool isdir, bool readonly, bool overwrit /* Lookup the parent dentry. On success, parent->contents_lock will be held in write mode */ ret = fs_path_lookup(path_norm, LOCK_DENTRY_CONTENTS_W, &parent, vol->index); if (ret < 0) { - if (ret != -LTFS_NO_DENTRY && ret != -LTFS_NAMETOOLONG) - ltfsmsg(LTFS_ERR, 11049E, ret); + if (ret != -LTFS_NO_DENTRY && ret != -LTFS_NAMETOOLONG) ltfsmsg(LTFS_ERR, 11049E, ret); goto out_free; } @@ -293,7 +282,7 @@ int ltfs_fsops_create(const char *path, bool isdir, bool readonly, bool overwrit ret = -LTFS_WORM_ENABLED; goto out_dispose; } - if (parent->is_appendonly && overwrite) { + if (parent->is_appendonly && overwrite) { ltfsmsg(LTFS_ERR, 17237E, "create: overwrite under appendonly dir"); ret = -LTFS_WORM_ENABLED; goto out_dispose; @@ -303,8 +292,7 @@ int ltfs_fsops_create(const char *path, bool isdir, bool readonly, bool overwrit ret = fs_directory_lookup(parent, filename, &d); if (ret < 0) { - if (ret != -LTFS_NAMETOOLONG) - ltfsmsg(LTFS_ERR, 11049E, ret); + if (ret != -LTFS_NAMETOOLONG) ltfsmsg(LTFS_ERR, 11049E, ret); goto out_dispose; } else if (d) { releasewrite_mrsw(&parent->contents_lock); @@ -319,7 +307,7 @@ int ltfs_fsops_create(const char *path, bool isdir, bool readonly, bool overwrit /* Allocate and set up the dentry */ d = fs_allocate_dentry(NULL, NULL, filename, isdir, readonly, true, vol->index); - if (! d) { + if (!d) { ltfsmsg(LTFS_ERR, 11167E); ret = -LTFS_NO_MEMORY; goto out_dispose; @@ -338,8 +326,7 @@ int ltfs_fsops_create(const char *path, bool isdir, bool readonly, bool overwrit parent->change_time = d->creation_time; /* Decide whether to write to IP */ - if (! isdir && index_criteria_get_max_filesize(vol)) - d->matches_name_criteria = index_criteria_match(d, vol); + if (!isdir && index_criteria_get_max_filesize(vol)) d->matches_name_criteria = index_criteria_match(d, vol); /* Set up reference counters and pointers */ d->vol = vol; @@ -348,10 +335,9 @@ int ltfs_fsops_create(const char *path, bool isdir, bool readonly, bool overwrit ++d->numhandles; /* Block end */ - if (isdir) - ++parent->link_count; + if (isdir) ++parent->link_count; - d->child_list=NULL; + d->child_list = NULL; d->parent->child_list = fs_add_key_to_hash_table(d->parent->child_list, d, &ret); if (ret != 0) { ltfsmsg(LTFS_ERR, 11319E, "ltfs_fsops_create", ret); @@ -364,12 +350,11 @@ int ltfs_fsops_create(const char *path, bool isdir, bool readonly, bool overwrit releasewrite_mrsw(&parent->meta_lock); ltfs_mutex_lock(&vol->index->dirty_lock); - if (! isdir) - ++vol->index->file_count; + if (!isdir) ++vol->index->file_count; ltfs_set_index_dirty(false, false, vol->index); d->dirty = true; ltfs_mutex_unlock(&vol->index->dirty_lock); - vol->file_open_count ++; + vol->file_open_count++; *dentry = d; ret = 0; @@ -399,8 +384,7 @@ int ltfs_fsops_create(const char *path, bool isdir, bool readonly, bool overwrit out_free: releaseread_mrsw(&vol->lock); - if (dentry_path) - free(dentry_path); + if (dentry_path) free(dentry_path); free(path_norm); return ret; } @@ -420,8 +404,7 @@ int ltfs_fsops_unlink(const char *path, ltfs_file_id *id, struct ltfs_volume *vo /* Make sure the device is online and writable */ ret = ltfs_get_tape_readonly(vol); - if (ret < 0 && ret != -LTFS_LESS_SPACE) - return ret; + if (ret < 0 && ret != -LTFS_LESS_SPACE) return ret; ret = ltfs_test_unit_ready(vol); if (ret < 0) { ltfsmsg(LTFS_ERR, 11050E); @@ -452,8 +435,7 @@ int ltfs_fsops_unlink(const char *path, ltfs_file_id *id, struct ltfs_volume *vo /* Find the dentry */ ret = fs_path_lookup(path_norm, LOCK_PARENT_CONTENTS_W, &d, vol->index); if (ret < 0) { - if (ret != -LTFS_NO_DENTRY && ret != -LTFS_NAMETOOLONG) - ltfsmsg(LTFS_ERR, 11052E, ret); + if (ret != -LTFS_NO_DENTRY && ret != -LTFS_NAMETOOLONG) ltfsmsg(LTFS_ERR, 11052E, ret); releaseread_mrsw(&vol->lock); free(path_norm); return ret; @@ -475,11 +457,9 @@ int ltfs_fsops_unlink(const char *path, ltfs_file_id *id, struct ltfs_volume *vo if (d->isdir) { ret = 0; acquireread_mrsw(&d->contents_lock); - if (HASH_COUNT(d->child_list) != 0) - ret = -LTFS_DIRNOTEMPTY; + if (HASH_COUNT(d->child_list) != 0) ret = -LTFS_DIRNOTEMPTY; releaseread_mrsw(&d->contents_lock); - if (ret < 0) - goto out; + if (ret < 0) goto out; } acquirewrite_mrsw(&parent->meta_lock); @@ -505,8 +485,7 @@ int ltfs_fsops_unlink(const char *path, ltfs_file_id *id, struct ltfs_volume *vo HASH_DEL(parent->child_list, namelist); free(namelist->name); free(namelist); - } - else { + } else { ltfsmsg(LTFS_ERR, 11320E, "ltfs_fsops_unlink", ret); releasewrite_mrsw(&d->meta_lock); goto out; @@ -516,14 +495,12 @@ int ltfs_fsops_unlink(const char *path, ltfs_file_id *id, struct ltfs_volume *vo d->deleted = true; d->parent = NULL; --d->link_count; - if (d->isdir) - --parent->link_count; + if (d->isdir) --parent->link_count; --d->numhandles; releasewrite_mrsw(&d->meta_lock); ltfs_mutex_lock(&vol->index->dirty_lock); - if (! d->isdir) - --vol->index->file_count; + if (!d->isdir) --vol->index->file_count; ltfs_set_index_dirty(false, false, vol->index); ltfs_mutex_unlock(&vol->index->dirty_lock); @@ -535,8 +512,7 @@ int ltfs_fsops_unlink(const char *path, ltfs_file_id *id, struct ltfs_volume *vo releaseread_mrsw(&vol->lock); - if (ret == 0 && iosched_initialized(vol)) - iosched_update_data_placement(d, vol); + if (ret == 0 && iosched_initialized(vol)) iosched_update_data_placement(d, vol); free(path_norm); fs_release_dentry(d); @@ -564,8 +540,7 @@ int ltfs_fsops_rename(const char *from, const char *to, ltfs_file_id *id, struct /* Make sure the device is online and writable */ ret = ltfs_get_tape_readonly(vol); - if (ret < 0 && ret != -LTFS_LESS_SPACE) - return ret; + if (ret < 0 && ret != -LTFS_LESS_SPACE) return ret; ret = ltfs_test_unit_ready(vol); if (ret < 0) { ltfsmsg(LTFS_ERR, 11053E); @@ -582,15 +557,14 @@ int ltfs_fsops_rename(const char *from, const char *to, ltfs_file_id *id, struct } ret = pathname_format(to, &to_norm, true, true); if (ret < 0) { - if (ret != -LTFS_INVALID_PATH) - ltfsmsg(LTFS_ERR, 11055E, ret); + if (ret != -LTFS_INVALID_PATH) ltfsmsg(LTFS_ERR, 11055E, ret); goto out_free; } if (dcache_initialized(vol)) { from_norm_copy = arch_strdup(from_norm); to_norm_copy = arch_strdup(to_norm); - if (! from_norm_copy || ! to_norm_copy) { + if (!from_norm_copy || !to_norm_copy) { ltfsmsg(LTFS_ERR, 10001E, "ltfs_fsops_rename: file name copy"); ret = -LTFS_NO_MEMORY; goto out_free; @@ -604,43 +578,39 @@ int ltfs_fsops_rename(const char *from, const char *to, ltfs_file_id *id, struct /* Allocate memory for new file name */ to_filename_copy = arch_strdup(to_filename); to_filename_copy2 = arch_strdup(to_filename); - if (! to_filename_copy || ! to_filename_copy2) { + if (!to_filename_copy || !to_filename_copy2) { ltfsmsg(LTFS_ERR, 10001E, "ltfs_fsops_rename: file name copy"); ret = -LTFS_NO_MEMORY; goto out_free; } ret = ltfs_get_volume_lock(false, vol); - if (ret < 0) - goto out_free; + if (ret < 0) goto out_free; ltfs_mutex_lock(&vol->index->rename_lock); if (dcache_initialized(vol)) { /* Rename the cached files */ ret = dcache_rename(from_norm_copy, to_norm_copy, &fromdentry, vol); - if (ret == 0) - ltfs_set_index_dirty(true, false, vol->index); + if (ret == 0) ltfs_set_index_dirty(true, false, vol->index); goto out_release; } /* Look up directories and lock them */ ret = fs_path_lookup(from_norm, 0, &fromdir, vol->index); if (ret < 0) { - if (ret != -LTFS_NO_DENTRY && ret != -LTFS_NAMETOOLONG) - ltfsmsg(LTFS_ERR, 11056E, ret); + if (ret != -LTFS_NO_DENTRY && ret != -LTFS_NAMETOOLONG) ltfsmsg(LTFS_ERR, 11056E, ret); goto out_release; } ret = fs_path_lookup(to_norm, 0, &todir, vol->index); if (ret < 0) { - if (ret != -LTFS_NO_DENTRY && ret != -LTFS_NAMETOOLONG) - ltfsmsg(LTFS_ERR, 11057E, ret); + if (ret != -LTFS_NO_DENTRY && ret != -LTFS_NAMETOOLONG) ltfsmsg(LTFS_ERR, 11057E, ret); /* fromdir meta_lock is needed because the exit code calls fs_release_dentry_unlocked */ acquirewrite_mrsw(&fromdir->meta_lock); goto out_release; } - if (fromdir->is_appendonly || fromdir->is_immutable ) { + if (fromdir->is_appendonly || fromdir->is_immutable) { ltfsmsg(LTFS_ERR, 17237E, "rename: parent is WORM"); ret = -LTFS_WORM_ENABLED; acquirewrite_mrsw(&fromdir->meta_lock); @@ -664,17 +634,14 @@ int ltfs_fsops_rename(const char *from, const char *to, ltfs_file_id *id, struct acquirewrite_mrsw(&fromdir->meta_lock); } if (ret < 0) { - if (ret != -LTFS_NAMETOOLONG) - ltfsmsg(LTFS_ERR, 11057E, ret); + if (ret != -LTFS_NAMETOOLONG) ltfsmsg(LTFS_ERR, 11057E, ret); goto out_unlock; } ret = fs_directory_lookup(fromdir, from_filename, &fromdentry); - if (ret < 0 || ! fromdentry) { - if (ret < 0 && ret != -LTFS_NAMETOOLONG) - ltfsmsg(LTFS_ERR, 11056E, ret); - if (! fromdentry) - ret = -LTFS_NO_DENTRY; + if (ret < 0 || !fromdentry) { + if (ret < 0 && ret != -LTFS_NAMETOOLONG) ltfsmsg(LTFS_ERR, 11056E, ret); + if (!fromdentry) ret = -LTFS_NO_DENTRY; if (todentry) { if (todentry == fromdir) --todentry->numhandles; @@ -691,18 +658,16 @@ int ltfs_fsops_rename(const char *from, const char *to, ltfs_file_id *id, struct acquirewrite_mrsw(&todir->contents_lock); acquirewrite_mrsw(&todir->meta_lock); if (ret < 0) { - if (ret != -LTFS_NAMETOOLONG) - ltfsmsg(LTFS_ERR, 11056E, ret); + if (ret != -LTFS_NAMETOOLONG) ltfsmsg(LTFS_ERR, 11056E, ret); goto out_unlock; - } else if (! fromdentry) { + } else if (!fromdentry) { ret = -LTFS_NO_DENTRY; goto out_unlock; } ret = fs_directory_lookup(todir, to_filename, &todentry); if (ret < 0) { - if (ret != -LTFS_NAMETOOLONG) - ltfsmsg(LTFS_ERR, 11057E, ret); + if (ret != -LTFS_NAMETOOLONG) ltfsmsg(LTFS_ERR, 11057E, ret); if (fromdentry) { /* BEAM: constant condition - fromdentry has always non-zero value here. */ if (fromdentry == todir) --fromdentry->numhandles; @@ -723,8 +688,7 @@ int ltfs_fsops_rename(const char *from, const char *to, ltfs_file_id *id, struct ret = -LTFS_RENAMELOOP; else if (todentry && (todentry == fromdir || fs_is_predecessor(todentry, fromdir))) { ret = fromdentry->isdir ? -LTFS_DIRNOTEMPTY : -LTFS_ISFILE; - if (fromdentry->isdir) - ret = -LTFS_DIRNOTEMPTY; + if (fromdentry->isdir) ret = -LTFS_DIRNOTEMPTY; } if (ret < 0) { /* Need to release fromdentry and todentry. This is slightly tricky because if we get @@ -753,8 +717,7 @@ int ltfs_fsops_rename(const char *from, const char *to, ltfs_file_id *id, struct if (fromdentry->isdir && fromdir != todir) { ltfsmsg(LTFS_INFO, 11259I); ret = -LTFS_DIRMOVE; - if (todentry && fromdentry != todentry) - fs_release_dentry(todentry); + if (todentry && fromdentry != todentry) fs_release_dentry(todentry); fs_release_dentry(fromdentry); goto out_unlock; } @@ -765,11 +728,10 @@ int ltfs_fsops_rename(const char *from, const char *to, ltfs_file_id *id, struct ret = -LTFS_WORM_ENABLED; fs_release_dentry(fromdentry); goto out_unlock; - } - else if (todentry && (todentry->is_immutable || todentry->is_appendonly)) { + } else if (todentry && (todentry->is_immutable || todentry->is_appendonly)) { ltfsmsg(LTFS_ERR, 17237E, "rename: target entry is WORM"); ret = -LTFS_WORM_ENABLED; - fs_release_dentry(fromdentry); // fromdentry != todentry befause fromdentry is not immutable/appendonly + fs_release_dentry(fromdentry); // fromdentry != todentry befause fromdentry is not immutable/appendonly fs_release_dentry(todentry); goto out_unlock; } @@ -780,8 +742,7 @@ int ltfs_fsops_rename(const char *from, const char *to, ltfs_file_id *id, struct if (todentry->isdir) { ret = 0; acquireread_mrsw(&todentry->contents_lock); - if (HASH_COUNT(todentry->child_list) != 0) - ret = -LTFS_DIRNOTEMPTY; + if (HASH_COUNT(todentry->child_list) != 0) ret = -LTFS_DIRNOTEMPTY; releaseread_mrsw(&todentry->contents_lock); if (ret < 0) { fs_release_dentry(fromdentry); @@ -790,8 +751,7 @@ int ltfs_fsops_rename(const char *from, const char *to, ltfs_file_id *id, struct } } acquirewrite_mrsw(&todentry->meta_lock); - if (todentry->isdir) - --todir->link_count; + if (todentry->isdir) --todir->link_count; --todentry->numhandles; --todentry->link_count; todentry->parent = NULL; @@ -802,14 +762,12 @@ int ltfs_fsops_rename(const char *from, const char *to, ltfs_file_id *id, struct HASH_DEL(todir->child_list, namelist); free(namelist->name); free(namelist); - } - else { + } else { ltfsmsg(LTFS_ERR, 11320E, "ltfs_fsops_rename", ret); releasewrite_mrsw(&todentry->meta_lock); goto out_unlock; } - if (! todir->isdir) - fs_decrement_file_count(vol->index); + if (!todir->isdir) fs_decrement_file_count(vol->index); fs_release_dentry_unlocked(todentry); todentry = NULL; } else if (todentry) { @@ -826,18 +784,15 @@ int ltfs_fsops_rename(const char *from, const char *to, ltfs_file_id *id, struct HASH_DEL(fromdir->child_list, namelist); free(namelist->name); free(namelist); - } - else { + } else { ltfsmsg(LTFS_ERR, 11320E, "ltfs_fsops_rename", ret); releasewrite_mrsw(&fromdentry->meta_lock); goto out_unlock; } - if (fromdentry->isdir) - --fromdir->link_count; + if (fromdentry->isdir) --fromdir->link_count; - if (fromdentry->isdir) - ++todir->link_count; + if (fromdentry->isdir) ++todir->link_count; /* Update times */ get_current_timespec(&newtime); @@ -849,10 +804,8 @@ int ltfs_fsops_rename(const char *from, const char *to, ltfs_file_id *id, struct /* Update fromdentry */ fromdentry->parent = todir; - if (fromdentry->name.name) - free(fromdentry->name.name); - if (fromdentry->platform_safe_name) - free(fromdentry->platform_safe_name); + if (fromdentry->name.name) free(fromdentry->name.name); + if (fromdentry->platform_safe_name) free(fromdentry->platform_safe_name); fromdentry->name.name = to_filename_copy; fromdentry->name.percent_encode = fs_is_percent_encode_required(fromdentry->name.name); fromdentry->platform_safe_name = to_filename_copy2; @@ -868,26 +821,23 @@ int ltfs_fsops_rename(const char *from, const char *to, ltfs_file_id *id, struct fromdentry->dirty = true; - if (! iosched_initialized(vol)) + if (!iosched_initialized(vol)) fs_release_dentry_unlocked(fromdentry); else releasewrite_mrsw(&fromdentry->meta_lock); ltfs_set_index_dirty(true, false, vol->index); - ret = 0; out_unlock: /* Release contents locks. The meta_locks are released by fs_release_dentry_unlocked. */ releasewrite_mrsw(&fromdir->contents_lock); - if (fromdir != todir) - releasewrite_mrsw(&todir->contents_lock); + if (fromdir != todir) releasewrite_mrsw(&todir->contents_lock); out_release: - if (! dcache_initialized(vol)) { - if (fromdir) - fs_release_dentry_unlocked(fromdir); + if (!dcache_initialized(vol)) { + if (fromdir) fs_release_dentry_unlocked(fromdir); if (todir) { if (todir == fromdir) fs_release_dentry(todir); @@ -911,19 +861,13 @@ int ltfs_fsops_rename(const char *from, const char *to, ltfs_file_id *id, struct } out_free: - if (from_norm) - free(from_norm); - if (to_norm) - free(to_norm); - if (from_norm_copy) - free(from_norm_copy); - if (to_norm_copy) - free(to_norm_copy); + if (from_norm) free(from_norm); + if (to_norm) free(to_norm); + if (from_norm_copy) free(from_norm_copy); + if (to_norm_copy) free(to_norm_copy); if (ret < 0 || dcache_initialized(vol)) { - if (to_filename_copy) - free(to_filename_copy); - if (to_filename_copy2) - free(to_filename_copy2); + if (to_filename_copy) free(to_filename_copy); + if (to_filename_copy2) free(to_filename_copy2); } return ret; @@ -938,11 +882,10 @@ int ltfs_fsops_getattr(struct dentry *d, struct dentry_attr *attr, struct ltfs_v CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); ret = ltfs_get_volume_lock(false, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; acquireread_mrsw(&d->meta_lock); - if(d->isslink) + if (d->isslink) attr->size = strlen(d->target.name); else attr->size = d->size; @@ -963,8 +906,7 @@ int ltfs_fsops_getattr(struct dentry *d, struct dentry_attr *attr, struct ltfs_v releaseread_mrsw(&d->meta_lock); releaseread_mrsw(&vol->lock); - if (! d->isdir && !d->isslink && iosched_initialized(vol)) - attr->size = iosched_get_filesize(d, vol); + if (!d->isdir && !d->isslink && iosched_initialized(vol)) attr->size = iosched_get_filesize(d, vol); return 0; } @@ -981,8 +923,7 @@ int ltfs_fsops_getattr_path(const char *path, struct dentry_attr *attr, ltfs_fil CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); ret = ltfs_fsops_open(path, false, false, &d, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = ltfs_fsops_getattr(d, attr, vol); id->uid = d->uid; @@ -992,8 +933,13 @@ int ltfs_fsops_getattr_path(const char *path, struct dentry_attr *attr, ltfs_fil return ret; } -int ltfs_fsops_setxattr(const char *path, const char *name, const char *value, size_t size, - int flags, ltfs_file_id *id, struct ltfs_volume *vol) +int ltfs_fsops_setxattr(const char *path, + const char *name, + const char *value, + size_t size, + int flags, + ltfs_file_id *id, + struct ltfs_volume *vol) { int ret; struct dentry *d; @@ -1014,8 +960,7 @@ int ltfs_fsops_setxattr(const char *path, const char *name, const char *value, s return -LTFS_LARGE_XATTR; /* this is the error returned by ext3 when the xattr is too large */ ret = ltfs_get_tape_readonly(vol); - if (ret < 0 && ret != -LTFS_LESS_SPACE && strcmp(name, "user.ltfs.volumeLockState")) - return ret; + if (ret < 0 && ret != -LTFS_LESS_SPACE && strcmp(name, "user.ltfs.volumeLockState")) return ret; ret = ltfs_test_unit_ready(vol); if (ret < 0) { @@ -1036,13 +981,12 @@ int ltfs_fsops_setxattr(const char *path, const char *name, const char *value, s } ret = pathname_format(name, &new_name, true, false); if (ret < 0) { - if (ret != -LTFS_INVALID_PATH && ret != -LTFS_NAMETOOLONG) - ltfsmsg(LTFS_ERR, 11119E, ret); + if (ret != -LTFS_INVALID_PATH && ret != -LTFS_NAMETOOLONG) ltfsmsg(LTFS_ERR, 11119E, ret); goto out_free; } new_name_strip = xattr_strip_name(new_name); - if (! new_name_strip) { + if (!new_name_strip) { /* Namespace is not supported (Linux) */ ret = -LTFS_XATTR_NAMESPACE; goto out_free; @@ -1057,7 +1001,7 @@ int ltfs_fsops_setxattr(const char *path, const char *name, const char *value, s /* Special case: if we are syncing the volume, flush the scheduler buffers * before taking locks. */ start: - if (! strcmp(new_name_strip, "ltfs.sync") && ! strcmp(path, "/")) { + if (!strcmp(new_name_strip, "ltfs.sync") && !strcmp(path, "/")) { ret = ltfs_fsops_flush(NULL, false, vol); if (ret < 0) { ltfsmsg(LTFS_ERR, 11325E, ret); @@ -1069,8 +1013,7 @@ int ltfs_fsops_setxattr(const char *path, const char *name, const char *value, s ret = ltfs_get_volume_lock(false, vol); write_lock = false; } - if (ret < 0) - goto out_free; + if (ret < 0) goto out_free; if (dcache_initialized(vol)) ret = dcache_open(new_path, &d, vol); @@ -1107,23 +1050,20 @@ int ltfs_fsops_setxattr(const char *path, const char *name, const char *value, s } if (NEED_REVAL(ret)) { ret = ltfs_revalidate(write_lock, vol); - if (ret == 0) - goto start; + if (ret == 0) goto start; } else if (IS_UNEXPECTED_MOVE(ret)) { vol->reval = -LTFS_REVAL_FAILED; release_mrsw(&vol->lock); } else release_mrsw(&vol->lock); out_free: - if (new_name) - free(new_name); - if (new_path) - free(new_path); + if (new_name) free(new_name); + if (new_path) free(new_path); return ret; } -int ltfs_fsops_getxattr(const char *path, const char *name, char *value, size_t size, - ltfs_file_id *id, struct ltfs_volume *vol) +int ltfs_fsops_getxattr( + const char *path, const char *name, char *value, size_t size, ltfs_file_id *id, struct ltfs_volume *vol) { int ret; struct dentry *d; @@ -1136,7 +1076,7 @@ int ltfs_fsops_getxattr(const char *path, const char *name, char *value, size_t CHECK_ARG_NULL(path, -LTFS_NULL_ARG); CHECK_ARG_NULL(name, -LTFS_NULL_ARG); CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); - if (size > 0 && ! value) { + if (size > 0 && !value) { ltfsmsg(LTFS_ERR, 11123E); return -LTFS_BAD_ARG; } @@ -1153,12 +1093,11 @@ int ltfs_fsops_getxattr(const char *path, const char *name, char *value, size_t } ret = pathname_format(name, &new_name, true, false); if (ret < 0) { - if (ret != -LTFS_INVALID_PATH && ret != -LTFS_NAMETOOLONG) - ltfsmsg(LTFS_ERR, 11125E, ret); + if (ret != -LTFS_INVALID_PATH && ret != -LTFS_NAMETOOLONG) ltfsmsg(LTFS_ERR, 11125E, ret); goto out_free; } new_name_strip = xattr_strip_name(new_name); - if (! new_name_strip) { + if (!new_name_strip) { /* Namespace is not supported (Linux) */ ret = -LTFS_NO_XATTR; goto out_free; @@ -1173,8 +1112,7 @@ int ltfs_fsops_getxattr(const char *path, const char *name, char *value, size_t /* Grab locks and find the dentry. */ start: ret = ltfs_get_volume_lock(false, vol); - if (ret < 0) - goto out_free; + if (ret < 0) goto out_free; if (dcache_initialized(vol)) ret = dcache_open(new_path, &d, vol); @@ -1197,15 +1135,12 @@ int ltfs_fsops_getxattr(const char *path, const char *name, char *value, size_t ret = xattr_get(d, new_name_strip, value, size, vol); fs_release_dentry(d); } - if (ret == -LTFS_RESTART_OPERATION) - goto start; + if (ret == -LTFS_RESTART_OPERATION) goto start; releaseread_mrsw(&vol->lock); out_free: - if (new_path) - free(new_path); - if (new_name) - free(new_name); + if (new_path) free(new_path); + if (new_name) free(new_name); return ret; } @@ -1220,7 +1155,7 @@ int ltfs_fsops_listxattr(const char *path, char *list, size_t size, ltfs_file_id CHECK_ARG_NULL(path, -LTFS_NULL_ARG); CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); - if (size > 0 && ! list) { + if (size > 0 && !list) { ltfsmsg(LTFS_ERR, 11130E); return -LTFS_BAD_ARG; } @@ -1284,8 +1219,7 @@ int ltfs_fsops_removexattr(const char *path, const char *name, ltfs_file_id *id, CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); ret = ltfs_get_tape_readonly(vol); - if (ret < 0 && ret != -LTFS_LESS_SPACE) - return ret; + if (ret < 0 && ret != -LTFS_LESS_SPACE) return ret; ret = ltfs_test_unit_ready(vol); if (ret < 0) { /* Cannot remove extended attribute: device is not ready */ @@ -1305,12 +1239,11 @@ int ltfs_fsops_removexattr(const char *path, const char *name, ltfs_file_id *id, } ret = pathname_format(name, &new_name, true, false); if (ret < 0) { - if (ret != -LTFS_INVALID_PATH && ret != -LTFS_NAMETOOLONG) - ltfsmsg(LTFS_ERR, 11137E, ret); + if (ret != -LTFS_INVALID_PATH && ret != -LTFS_NAMETOOLONG) ltfsmsg(LTFS_ERR, 11137E, ret); goto out_free; } new_name_strip = xattr_strip_name(new_name); - if (! new_name_strip) { + if (!new_name_strip) { /* Namespace is not supported (Linux) */ ret = -LTFS_NO_XATTR; goto out_free; @@ -1324,16 +1257,14 @@ int ltfs_fsops_removexattr(const char *path, const char *name, ltfs_file_id *id, /* Grab locks and find the dentry. */ ret = ltfs_get_volume_lock(false, vol); - if (ret < 0) - goto out_free; + if (ret < 0) goto out_free; if (dcache_initialized(vol)) ret = dcache_open(new_path, &d, vol); else ret = fs_path_lookup(new_path, 0, &d, vol->index); if (ret < 0) { - if (ret != -LTFS_NO_DENTRY && ret != -LTFS_NAMETOOLONG) - ltfsmsg(LTFS_ERR, 11139E, ret); + if (ret != -LTFS_NO_DENTRY && ret != -LTFS_NAMETOOLONG) ltfsmsg(LTFS_ERR, 11139E, ret); releaseread_mrsw(&vol->lock); goto out_free; } @@ -1343,23 +1274,19 @@ int ltfs_fsops_removexattr(const char *path, const char *name, ltfs_file_id *id, ret = xattr_remove(d, new_name_strip, vol); if (dcache_initialized(vol)) { - if (ret == 0) - ret = dcache_removexattr(new_path, d, new_name_strip, vol); + if (ret == 0) ret = dcache_removexattr(new_path, d, new_name_strip, vol); dcache_close(d, true, true, vol); } else fs_release_dentry(d); releaseread_mrsw(&vol->lock); out_free: - if (new_path) - free(new_path); - if (new_name) - free(new_name); + if (new_path) free(new_path); + if (new_name) free(new_name); return ret; } -int ltfs_fsops_readdir(struct dentry *d, void *buf, ltfs_dir_filler filler, void *filler_priv, - struct ltfs_volume *vol) +int ltfs_fsops_readdir(struct dentry *d, void *buf, ltfs_dir_filler filler, void *filler_priv, struct ltfs_volume *vol) { int ret = 0; struct name_list *entry, *tmp; @@ -1368,35 +1295,32 @@ int ltfs_fsops_readdir(struct dentry *d, void *buf, ltfs_dir_filler filler, void CHECK_ARG_NULL(filler, -LTFS_NULL_ARG); CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); - if (! d->isdir) - return -LTFS_ISFILE; + if (!d->isdir) return -LTFS_ISFILE; ret = ltfs_get_volume_lock(false, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; acquireread_mrsw(&d->contents_lock); if (dcache_initialized(vol)) { int i; char **namelist = NULL; - ret = dcache_readdir(d, false, (void ***) &namelist, vol); + ret = dcache_readdir(d, false, (void ***)&namelist, vol); if (ret == 0 && namelist) { - for (i=0; namelist[i]; ++i) { + for (i = 0; namelist[i]; ++i) { ret = filler(buf, namelist[i], filler_priv); - if (ret < 0) - break; + if (ret < 0) break; } - for (i=0; namelist[i]; ++i) + for (i = 0; namelist[i]; ++i) free(namelist[i]); free(namelist); } } else { if (HASH_COUNT(d->child_list) != 0) { HASH_SORT(d->child_list, fs_hash_sort_by_uid); - HASH_ITER(hh, d->child_list, entry, tmp) { + HASH_ITER(hh, d->child_list, entry, tmp) + { ret = filler(buf, entry->d->platform_safe_name, filler_priv); - if (ret < 0) - break; + if (ret < 0) break; } } } @@ -1414,8 +1338,8 @@ int ltfs_fsops_readdir(struct dentry *d, void *buf, ltfs_dir_filler filler, void return ret; } -int _ltfs_fsops_read_direntry(struct dentry *d, struct ltfs_direntry *dirent, - unsigned long index, bool root, struct ltfs_volume *vol) +int _ltfs_fsops_read_direntry( + struct dentry *d, struct ltfs_direntry *dirent, unsigned long index, bool root, struct ltfs_volume *vol) { unsigned long i = 0; struct dentry *target = NULL; @@ -1426,7 +1350,7 @@ int _ltfs_fsops_read_direntry(struct dentry *d, struct ltfs_direntry *dirent, acquireread_mrsw(&d->contents_lock); - if ( ! d->isdir ) { + if (!d->isdir) { releaseread_mrsw(&d->contents_lock); return -LTFS_ISFILE; } @@ -1435,23 +1359,23 @@ int _ltfs_fsops_read_direntry(struct dentry *d, struct ltfs_direntry *dirent, dirent->platform_safe_name = NULL; /* Handle the current directory and the parent directory */ - if( (! root) || d->parent ) { + if ((!root) || d->parent) { switch (index) { - case 0: /* Return current dir */ - dirent->name = "."; - dirent->platform_safe_name = "."; - target = d; - i = index; - break; - case 1: - dirent->name = ".."; - dirent->platform_safe_name = ".."; - target = d->parent; - i = index; - break; - default: - i = 2; - break; + case 0: /* Return current dir */ + dirent->name = "."; + dirent->platform_safe_name = "."; + target = d; + i = index; + break; + case 1: + dirent->name = ".."; + dirent->platform_safe_name = ".."; + target = d->parent; + i = index; + break; + default: + i = 2; + break; } } @@ -1462,33 +1386,32 @@ int _ltfs_fsops_read_direntry(struct dentry *d, struct ltfs_direntry *dirent, if (target) { acquireread_mrsw(&target->meta_lock); dirent->creation_time = target->creation_time; - dirent->access_time = target->access_time; - dirent->modify_time = target->modify_time; - dirent->change_time = target->change_time; - dirent->isdir = target->isdir; - dirent->readonly = target->readonly; - dirent->isslink = target->isslink; - dirent->realsize = target->realsize; - dirent->size = target->size; - if (! dirent->platform_safe_name ) { - dirent->name = target->name.name; + dirent->access_time = target->access_time; + dirent->modify_time = target->modify_time; + dirent->change_time = target->change_time; + dirent->isdir = target->isdir; + dirent->readonly = target->readonly; + dirent->isslink = target->isslink; + dirent->realsize = target->realsize; + dirent->size = target->size; + if (!dirent->platform_safe_name) { + dirent->name = target->name.name; dirent->platform_safe_name = target->platform_safe_name; } releaseread_mrsw(&target->meta_lock); - } - else { + } else { ret = dcache_read_direntry(d, dirent, index, vol); } return ret; - } - else { + } else { /* Search target dentry from directory entry */ - if (! target) { - if(HASH_COUNT(d->child_list) != 0) { - HASH_ITER(hh, d->child_list, entry, tmp) { - if(entry->d->deleted) continue; - if(!entry->d->platform_safe_name) continue; - if(i == index) { + if (!target) { + if (HASH_COUNT(d->child_list) != 0) { + HASH_ITER(hh, d->child_list, entry, tmp) + { + if (entry->d->deleted) continue; + if (!entry->d->platform_safe_name) continue; + if (i == index) { target = entry->d; break; } @@ -1499,22 +1422,21 @@ int _ltfs_fsops_read_direntry(struct dentry *d, struct ltfs_direntry *dirent, releaseread_mrsw(&d->contents_lock); /* Cannot find the target dentry*/ - if(i != index || ! target ) - return -LTFS_NO_DENTRY; + if (i != index || !target) return -LTFS_NO_DENTRY; /* Set target dentry information to the buffer */ acquireread_mrsw(&target->meta_lock); dirent->creation_time = target->creation_time; - dirent->access_time = target->access_time; - dirent->modify_time = target->modify_time; - dirent->change_time = target->change_time; - dirent->isdir = target->isdir; - dirent->readonly = target->readonly; - dirent->isslink = target->isslink; - dirent->realsize = target->realsize; - dirent->size = target->size; - if (! dirent->platform_safe_name ) { - dirent->name = target->name.name; + dirent->access_time = target->access_time; + dirent->modify_time = target->modify_time; + dirent->change_time = target->change_time; + dirent->isdir = target->isdir; + dirent->readonly = target->readonly; + dirent->isslink = target->isslink; + dirent->realsize = target->realsize; + dirent->size = target->size; + if (!dirent->platform_safe_name) { + dirent->name = target->name.name; dirent->platform_safe_name = target->platform_safe_name; } releaseread_mrsw(&target->meta_lock); @@ -1522,14 +1444,18 @@ int _ltfs_fsops_read_direntry(struct dentry *d, struct ltfs_direntry *dirent, return 0; } -int ltfs_fsops_read_direntry(struct dentry *d, struct ltfs_direntry *dirent, unsigned long index, - struct ltfs_volume *vol) +int ltfs_fsops_read_direntry(struct dentry *d, + struct ltfs_direntry *dirent, + unsigned long index, + struct ltfs_volume *vol) { return _ltfs_fsops_read_direntry(d, dirent, index, true, vol); } -int ltfs_fsops_read_direntry_noroot(struct dentry *d, struct ltfs_direntry *dirent, - unsigned long index, struct ltfs_volume *vol) +int ltfs_fsops_read_direntry_noroot(struct dentry *d, + struct ltfs_direntry *dirent, + unsigned long index, + struct ltfs_volume *vol) { return _ltfs_fsops_read_direntry(d, dirent, index, false, vol); } @@ -1544,8 +1470,7 @@ int ltfs_fsops_utimens(struct dentry *d, const struct ltfs_timespec ts[2], struc /* Make sure the device is online and writable */ ret = ltfs_get_tape_readonly(vol); - if (ret < 0 && ret != -LTFS_LESS_SPACE) - return ret; + if (ret < 0 && ret != -LTFS_LESS_SPACE) return ret; ret = ltfs_test_unit_ready(vol); if (ret < 0) { ltfsmsg(LTFS_ERR, 11045E); @@ -1553,16 +1478,19 @@ int ltfs_fsops_utimens(struct dentry *d, const struct ltfs_timespec ts[2], struc } ret = ltfs_get_volume_lock(false, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; acquirewrite_mrsw(&d->meta_lock); if (d->access_time.tv_sec != ts[0].tv_sec || d->access_time.tv_nsec != ts[0].tv_nsec) { d->access_time = ts[0]; ret = normalize_ltfs_time(&d->access_time); if (ret == LTFS_TIME_OUT_OF_RANGE) - ltfsmsg(LTFS_WARN, 17217W, "atime", - d->platform_safe_name, (unsigned long long)d->uid, (unsigned long long)ts[0].tv_sec); + ltfsmsg(LTFS_WARN, + 17217W, + "atime", + d->platform_safe_name, + (unsigned long long)d->uid, + (unsigned long long)ts[0].tv_sec); get_current_timespec(&d->change_time); ltfs_set_index_dirty(true, true, vol->index); d->dirty = true; @@ -1571,14 +1499,17 @@ int ltfs_fsops_utimens(struct dentry *d, const struct ltfs_timespec ts[2], struc d->modify_time = ts[1]; ret = normalize_ltfs_time(&d->modify_time); if (ret == LTFS_TIME_OUT_OF_RANGE) - ltfsmsg(LTFS_WARN, 17217W, "mtime", - d->platform_safe_name, (unsigned long long)d->uid, (unsigned long long)ts[1].tv_sec); + ltfsmsg(LTFS_WARN, + 17217W, + "mtime", + d->platform_safe_name, + (unsigned long long)d->uid, + (unsigned long long)ts[1].tv_sec); get_current_timespec(&d->change_time); ltfs_set_index_dirty(true, false, vol->index); d->dirty = true; } - if (dcache_initialized(vol)) - dcache_flush(d, FLUSH_METADATA, vol); + if (dcache_initialized(vol)) dcache_flush(d, FLUSH_METADATA, vol); releasewrite_mrsw(&d->meta_lock); releaseread_mrsw(&vol->lock); @@ -1586,7 +1517,10 @@ int ltfs_fsops_utimens(struct dentry *d, const struct ltfs_timespec ts[2], struc return 0; } -int ltfs_fsops_utimens_path(const char *path, const struct ltfs_timespec ts[2], ltfs_file_id *id, struct ltfs_volume *vol) +int ltfs_fsops_utimens_path(const char *path, + const struct ltfs_timespec ts[2], + ltfs_file_id *id, + struct ltfs_volume *vol) { int ret; struct dentry *d; @@ -1598,8 +1532,7 @@ int ltfs_fsops_utimens_path(const char *path, const struct ltfs_timespec ts[2], CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); ret = ltfs_fsops_open(path, false, false, &d, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = ltfs_fsops_utimens(d, ts, vol); id->uid = d->uid; @@ -1612,7 +1545,7 @@ int ltfs_fsops_utimens_path(const char *path, const struct ltfs_timespec ts[2], int ltfs_fsops_utimens_all(struct dentry *d, const struct ltfs_timespec ts[4], struct ltfs_volume *vol) { int ret; - bool isctime=false; + bool isctime = false; CHECK_ARG_NULL(d, -LTFS_NULL_ARG); CHECK_ARG_NULL(ts, -LTFS_NULL_ARG); @@ -1620,8 +1553,7 @@ int ltfs_fsops_utimens_all(struct dentry *d, const struct ltfs_timespec ts[4], s /* Make sure the device is online and writable */ ret = ltfs_get_tape_readonly(vol); - if (ret < 0 && ret != -LTFS_LESS_SPACE) - return ret; + if (ret < 0 && ret != -LTFS_LESS_SPACE) return ret; ret = ltfs_test_unit_ready(vol); if (ret < 0) { ltfsmsg(LTFS_ERR, 11045E); @@ -1629,8 +1561,7 @@ int ltfs_fsops_utimens_all(struct dentry *d, const struct ltfs_timespec ts[4], s } ret = ltfs_get_volume_lock(false, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; acquirewrite_mrsw(&d->meta_lock); @@ -1638,9 +1569,13 @@ int ltfs_fsops_utimens_all(struct dentry *d, const struct ltfs_timespec ts[4], s d->change_time = ts[3]; ret = normalize_ltfs_time(&d->change_time); if (ret == LTFS_TIME_OUT_OF_RANGE) - ltfsmsg(LTFS_WARN, 17217W, "ctime", - d->platform_safe_name, (unsigned long long)d->uid, (unsigned long long)ts[3].tv_sec); - isctime=true; + ltfsmsg(LTFS_WARN, + 17217W, + "ctime", + d->platform_safe_name, + (unsigned long long)d->uid, + (unsigned long long)ts[3].tv_sec); + isctime = true; ltfs_set_index_dirty(true, false, vol->index); d->dirty = true; } @@ -1648,9 +1583,13 @@ int ltfs_fsops_utimens_all(struct dentry *d, const struct ltfs_timespec ts[4], s d->access_time = ts[0]; ret = normalize_ltfs_time(&d->access_time); if (ret == LTFS_TIME_OUT_OF_RANGE) - ltfsmsg(LTFS_WARN, 17217W, "atime", - d->platform_safe_name, (unsigned long long)d->uid, (unsigned long long)ts[0].tv_sec); - if(!isctime) get_current_timespec(&d->change_time); + ltfsmsg(LTFS_WARN, + 17217W, + "atime", + d->platform_safe_name, + (unsigned long long)d->uid, + (unsigned long long)ts[0].tv_sec); + if (!isctime) get_current_timespec(&d->change_time); ltfs_set_index_dirty(true, true, vol->index); d->dirty = true; } @@ -1658,9 +1597,13 @@ int ltfs_fsops_utimens_all(struct dentry *d, const struct ltfs_timespec ts[4], s d->modify_time = ts[1]; ret = normalize_ltfs_time(&d->modify_time); if (ret == LTFS_TIME_OUT_OF_RANGE) - ltfsmsg(LTFS_WARN, 17217W, "mtime", - d->platform_safe_name, (unsigned long long)d->uid, (unsigned long long)ts[1].tv_sec); - if(!isctime) get_current_timespec(&d->change_time); + ltfsmsg(LTFS_WARN, + 17217W, + "mtime", + d->platform_safe_name, + (unsigned long long)d->uid, + (unsigned long long)ts[1].tv_sec); + if (!isctime) get_current_timespec(&d->change_time); ltfs_set_index_dirty(true, false, vol->index); d->dirty = true; } @@ -1668,15 +1611,18 @@ int ltfs_fsops_utimens_all(struct dentry *d, const struct ltfs_timespec ts[4], s d->creation_time = ts[2]; ret = normalize_ltfs_time(&d->creation_time); if (ret == LTFS_TIME_OUT_OF_RANGE) - ltfsmsg(LTFS_WARN, 17217W, "creation_time", - d->platform_safe_name, (unsigned long long)d->uid, (unsigned long long)ts[2].tv_sec); - if(!isctime) get_current_timespec(&d->change_time); + ltfsmsg(LTFS_WARN, + 17217W, + "creation_time", + d->platform_safe_name, + (unsigned long long)d->uid, + (unsigned long long)ts[2].tv_sec); + if (!isctime) get_current_timespec(&d->change_time); ltfs_set_index_dirty(true, false, vol->index); d->dirty = true; } - if (dcache_initialized(vol)) - dcache_flush(d, FLUSH_METADATA, vol); + if (dcache_initialized(vol)) dcache_flush(d, FLUSH_METADATA, vol); releasewrite_mrsw(&d->meta_lock); releaseread_mrsw(&vol->lock); @@ -1684,7 +1630,6 @@ int ltfs_fsops_utimens_all(struct dentry *d, const struct ltfs_timespec ts[4], s return 0; } - int ltfs_fsops_set_readonly(struct dentry *d, bool readonly, struct ltfs_volume *vol) { int ret; @@ -1694,8 +1639,7 @@ int ltfs_fsops_set_readonly(struct dentry *d, bool readonly, struct ltfs_volume /* Make sure the device is online and writable */ ret = ltfs_get_tape_readonly(vol); - if (ret < 0 && ret != -LTFS_LESS_SPACE) - return ret; + if (ret < 0 && ret != -LTFS_LESS_SPACE) return ret; ret = ltfs_test_unit_ready(vol); if (ret < 0) { ltfsmsg(LTFS_ERR, 11046E); @@ -1703,15 +1647,13 @@ int ltfs_fsops_set_readonly(struct dentry *d, bool readonly, struct ltfs_volume } ret = ltfs_get_volume_lock(false, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; acquirewrite_mrsw(&d->meta_lock); if (readonly != d->readonly) { d->readonly = readonly; get_current_timespec(&d->change_time); ltfs_set_index_dirty(true, false, vol->index); - if (dcache_initialized(vol)) - dcache_flush(d, FLUSH_METADATA, vol); + if (dcache_initialized(vol)) dcache_flush(d, FLUSH_METADATA, vol); } releasewrite_mrsw(&d->meta_lock); releaseread_mrsw(&vol->lock); @@ -1731,8 +1673,7 @@ int ltfs_fsops_set_readonly_path(const char *path, bool readonly, ltfs_file_id * CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); ret = ltfs_fsops_open(path, false, false, &d, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; if (d->is_appendonly || d->is_immutable) { ltfsmsg(LTFS_ERR, 17237E, "chmod"); @@ -1747,18 +1688,17 @@ int ltfs_fsops_set_readonly_path(const char *path, bool readonly, ltfs_file_id * return ret; } -int ltfs_fsops_write(struct dentry *d, const char *buf, size_t count, off_t offset, - bool isupdatetime, struct ltfs_volume *vol) +int ltfs_fsops_write( + struct dentry *d, const char *buf, size_t count, off_t offset, bool isupdatetime, struct ltfs_volume *vol) { ssize_t ret; CHECK_ARG_NULL(d, -LTFS_NULL_ARG); CHECK_ARG_NULL(buf, -LTFS_NULL_ARG); CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); - if (d->isdir) - return -LTFS_ISDIRECTORY; + if (d->isdir) return -LTFS_ISDIRECTORY; - if (d->is_immutable || (d->is_appendonly && (uint64_t) offset != d->size)) { + if (d->is_immutable || (d->is_appendonly && (uint64_t)offset != d->size)) { ltfsmsg(LTFS_ERR, 17237E, "write"); return -LTFS_WORM_ENABLED; } @@ -1770,14 +1710,13 @@ int ltfs_fsops_write(struct dentry *d, const char *buf, size_t count, off_t offs if (iosched_initialized(vol)) { ret = iosched_write(d, buf, count, offset, isupdatetime, vol); - if (!isupdatetime && ret>=0) - d->need_update_time = true; + if (!isupdatetime && ret >= 0) d->need_update_time = true; } else { if (isupdatetime) ret = ltfs_fsraw_write(d, buf, count, offset, ltfs_dp_id(vol), true, vol); else { ret = ltfs_fsraw_write(d, buf, count, offset, ltfs_dp_id(vol), false, vol); - if (ret>=0) d->need_update_time = true; + if (ret >= 0) d->need_update_time = true; } } @@ -1787,16 +1726,14 @@ int ltfs_fsops_write(struct dentry *d, const char *buf, size_t count, off_t offs return 0; } -ssize_t ltfs_fsops_read(struct dentry *d, char *buf, size_t count, off_t offset, - struct ltfs_volume *vol) +ssize_t ltfs_fsops_read(struct dentry *d, char *buf, size_t count, off_t offset, struct ltfs_volume *vol) { ssize_t ret; CHECK_ARG_NULL(d, -LTFS_NULL_ARG); CHECK_ARG_NULL(buf, -LTFS_NULL_ARG); CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); - if (d->isdir) - return -LTFS_ISDIRECTORY; + if (d->isdir) return -LTFS_ISDIRECTORY; if (iosched_initialized(vol)) ret = iosched_read(d, buf, count, offset, vol); @@ -1819,8 +1756,7 @@ int ltfs_fsops_truncate(struct dentry *d, off_t length, struct ltfs_volume *vol) return -LTFS_ISDIRECTORY; ret = ltfs_get_tape_readonly(vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; if (d->is_immutable || d->is_appendonly) { ltfsmsg(LTFS_ERR, 17237E, "truncate"); @@ -1838,8 +1774,7 @@ int ltfs_fsops_truncate(struct dentry *d, off_t length, struct ltfs_volume *vol) else ret = ltfs_fsraw_truncate(d, length, vol); - if (ret == 0 && dcache_initialized(vol)) - dcache_flush(d, (FLUSH_EXTENT_LIST | FLUSH_METADATA), vol); + if (ret == 0 && dcache_initialized(vol)) dcache_flush(d, (FLUSH_EXTENT_LIST | FLUSH_METADATA), vol); ret = ltfs_fsops_update_used_blocks(d, vol); @@ -1858,8 +1793,7 @@ int ltfs_fsops_truncate_path(const char *path, off_t length, ltfs_file_id *id, s CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); ret = ltfs_fsops_open(path, true, false, &d, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = ltfs_fsops_truncate(d, length, vol); id->uid = d->uid; @@ -1873,26 +1807,23 @@ int ltfs_fsops_flush(struct dentry *d, bool closeflag, struct ltfs_volume *vol) int ret = 0; CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); - if (d && d->isdir) - return -LTFS_ISDIRECTORY; + if (d && d->isdir) return -LTFS_ISDIRECTORY; /* Don't need to check for read-only or unit ready here; the I/O scheduler will check for * those conditions if it wants to know about them. */ - if (iosched_initialized(vol)) - ret = iosched_flush(d, closeflag, vol); + if (iosched_initialized(vol)) ret = iosched_flush(d, closeflag, vol); - if (dcache_initialized(vol)) - dcache_flush(d, FLUSH_ALL, vol); + if (dcache_initialized(vol)) dcache_flush(d, FLUSH_ALL, vol); return ret; } -int ltfs_fsops_symlink_path(const char* to, const char* from, ltfs_file_id *id, struct ltfs_volume *vol) +int ltfs_fsops_symlink_path(const char *to, const char *from, ltfs_file_id *id, struct ltfs_volume *vol) { struct dentry *d; - bool use_iosche=false; - int ret=0, ret2=0; + bool use_iosche = false; + int ret = 0, ret2 = 0; char *value; size_t size; @@ -1901,14 +1832,13 @@ int ltfs_fsops_symlink_path(const char* to, const char* from, ltfs_file_id *id, CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); - if ( iosched_initialized(vol) ) use_iosche=true; + if (iosched_initialized(vol)) use_iosche = true; ltfsmsg(LTFS_DEBUG, 11322D, from, to); /* Create a node */ ret = ltfs_fsops_create(from, false, true, false, &d, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; id->uid = d->uid; id->ino = d->ino; @@ -1917,21 +1847,19 @@ int ltfs_fsops_symlink_path(const char* to, const char* from, ltfs_file_id *id, d->isslink = true; /* Set mount point length in EA (LiveLink support mode only) */ - if ( ( strncmp( to, vol->mountpoint, vol->mountpoint_len )==0 ) && - ( to[vol->mountpoint_len]=='/' ) ) - ret = asprintf( &value, "%d", (int) vol->mountpoint_len ); + if ((strncmp(to, vol->mountpoint, vol->mountpoint_len) == 0) && (to[vol->mountpoint_len] == '/')) + ret = asprintf(&value, "%d", (int)vol->mountpoint_len); else - ret = asprintf( &value, "0" ); - if ( ret < 0 ) - return -LTFS_NO_MEMORY; + ret = asprintf(&value, "0"); + if (ret < 0) return -LTFS_NO_MEMORY; size = strlen(value); ltfsmsg(LTFS_DEBUG, 11323D, value); - ret = xattr_set_mountpoint_length( d, value, size ); + ret = xattr_set_mountpoint_length(d, value, size); free(value); ret2 = ltfs_fsops_close(d, true, true, use_iosche, vol); - if ( ret==0 && ret2<0 ) { + if (ret == 0 && ret2 < 0) { ret = ret2; } @@ -1941,86 +1869,83 @@ int ltfs_fsops_symlink_path(const char* to, const char* from, ltfs_file_id *id, int ltfs_fsops_readlink_path(const char *path, char *buf, size_t size, ltfs_file_id *id, struct ltfs_volume *vol) { struct dentry *d; - bool use_iosche=false; - int ret=0; + bool use_iosche = false; + int ret = 0; char value[32]; - int num1,num2; + int num1, num2; id->uid = 0; id->ino = 0; CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); - if ( iosched_initialized(vol) ) use_iosche=true; + if (iosched_initialized(vol)) use_iosche = true; /* Open the file */ ret = ltfs_fsops_open(path, false, use_iosche, &d, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; id->uid = d->uid; id->ino = d->ino; - if ( size < strlen(d->target.name) + 1 ) { + if (size < strlen(d->target.name) + 1) { return -LTFS_SMALL_BUFFER; } arch_strncpy_auto(buf, d->target.name, size); - if ( vol->livelink ) { - memset( value, 0, sizeof(value)); + if (vol->livelink) { + memset(value, 0, sizeof(value)); ret = xattr_get(d, LTFS_LIVELINK_EA_NAME, value, sizeof(value), vol); - if ( ret > 0 ) { + if (ret > 0) { ltfsmsg(LTFS_DEBUG, 11323D, value); ret = arch_sscanf(value, "%d:%d", &num1, &num2); - if ( ( ret == 1 ) && ( num1 != 0 ) ){ - memset( buf, 0, size); + if ((ret == 1) && (num1 != 0)) { + memset(buf, 0, size); #ifndef mingw_PLATFORM - if ( size < strlen(d->target.name) - num1 + vol->mountpoint_len + 1 ){ + if (size < strlen(d->target.name) - num1 + vol->mountpoint_len + 1) { return -LTFS_SMALL_BUFFER; } strcpy(buf, vol->mountpoint); #endif - arch_strcat(buf,size, d->target.name + num1); + arch_strcat(buf, size, d->target.name + num1); ltfsmsg(LTFS_DEBUG, 11324D, d->target.name, buf); } } } ret = ltfs_fsops_close(d, false, false, use_iosche, vol); - if (ret < 0) - return ret; - + if (ret < 0) return ret; return 0; /* Shall be return 0, if success */ } -int ltfs_fsops_target_absolute_path(const char* link, const char* target, char* buf, size_t size ) +int ltfs_fsops_target_absolute_path(const char *link, const char *target, char *buf, size_t size) { char *work_buf, *target_buf, *temp_buf, *token, *next_token; /* work buffers for string */ - int len=0, len2=0; /* work variables for string length */ + int len = 0, len2 = 0; /* work variables for string length */ CHECK_ARG_NULL(link, -LTFS_NULL_ARG); CHECK_ARG_NULL(target, -LTFS_NULL_ARG); /* need to set message and return code */ - if (link[0]!='/') { + if (link[0] != '/') { return -LTFS_BAD_ARG; } /* Check input target string is already absolute path or not */ len2 = strlen(target); - if ( (target[0]=='/') && !strstr(target,"./" ) ) { - if ( size < (size_t)len2+1) { + if ((target[0] == '/') && !strstr(target, "./")) { + if (size < (size_t)len2 + 1) { return -LTFS_SMALL_BUFFER; } - arch_strcpy(buf,len2, target); + arch_strcpy(buf, len2, target); return 0; } - len=strlen(link); + len = strlen(link); int work_buf_len = len + len2 + 1; work_buf = malloc(work_buf_len); - if (!work_buf) { + if (!work_buf) { ltfsmsg(LTFS_ERR, 10001E, "ltfs_fsops_target_absolute_path: work_buf"); return -LTFS_NO_MEMORY; } @@ -2032,45 +1957,44 @@ int ltfs_fsops_target_absolute_path(const char* link, const char* target, char* return -LTFS_NO_MEMORY; } - if (target[0]=='/') { - temp_buf = strstr(target, "/."); /* get "/../ccc/target.txt" of "/aaa/../ccc/target.txt" */ + if (target[0] == '/') { + temp_buf = strstr(target, "/."); /* get "/../ccc/target.txt" of "/aaa/../ccc/target.txt" */ arch_strcpy(target_buf, target_buf_len, temp_buf + 1); /* copy "../ccc/target.txt" */ len = strlen(target_buf) + 1; len = len2 - len; - arch_strncpy(work_buf, target, work_buf_len,len); /* copy "/aaa" */ + arch_strncpy(work_buf, target, work_buf_len, len); /* copy "/aaa" */ } else { arch_strcpy(work_buf, work_buf_len, link); arch_strcpy(target_buf, target_buf_len, target); /* Split link file name then get current directory */ temp_buf = strrchr(work_buf, '/'); /* get "/link.txt" from "/aaa/bbb/link.txt" */ - len -= strlen(temp_buf); /* length of "/aaa/bbb" */ + len -= strlen(temp_buf); /* length of "/aaa/bbb" */ } char *contextVal = NULL; /* Split target path directory then modify current directory with target path information */ - token = arch_strtok(target_buf, "/", contextVal); /* get ".." from "../ccc/target.txt" */ + token = arch_strtok(target_buf, "/", contextVal); /* get ".." from "../ccc/target.txt" */ while (token) { - next_token = arch_strtok(NULL, "/", contextVal); /* if next_token is NULL then token is filename */ - if (!next_token) - break; + next_token = arch_strtok(NULL, "/", contextVal); /* if next_token is NULL then token is filename */ + if (!next_token) break; if (strcmp(token, "..") == 0) { - work_buf[len] = '\0'; /* "/aaa/bbb\0link.txt" */ - temp_buf = strrchr(work_buf, '/' ); /* get "/bbb" */ + work_buf[len] = '\0'; /* "/aaa/bbb\0link.txt" */ + temp_buf = strrchr(work_buf, '/'); /* get "/bbb" */ if (!temp_buf) { - *buf = '\0'; /* out of ltfs range */ + *buf = '\0'; /* out of ltfs range */ return 0; } - len -= strlen(temp_buf); /* length of "/aaa" */ - } else if (strcmp(token, "." )) { /* have directory name */ - work_buf[len] = '/'; /* put '/ 'as "/aaa/" */ - arch_strncpy(work_buf+len+1, token, work_buf_len, strlen(token) ); /* "/aaa/ccc\0" */ + len -= strlen(temp_buf); /* length of "/aaa" */ + } else if (strcmp(token, ".")) { /* have directory name */ + work_buf[len] = '/'; /* put '/ 'as "/aaa/" */ + arch_strncpy(work_buf + len + 1, token, work_buf_len, strlen(token)); /* "/aaa/ccc\0" */ len = strlen(work_buf); } token = next_token; } - work_buf[len] = '/'; /* put '/ 'as "/aaa/ccc/" */ - if(token){ - arch_strncpy(work_buf+len+1, token, work_buf_len, strlen(token)); /* "/aaa/ccc/target.txt\0" */ + work_buf[len] = '/'; /* put '/ 'as "/aaa/ccc/" */ + if (token) { + arch_strncpy(work_buf + len + 1, token, work_buf_len, strlen(token)); /* "/aaa/ccc/target.txt\0" */ } if (size < strlen(work_buf) + 1) { free(work_buf); @@ -2078,7 +2002,7 @@ int ltfs_fsops_target_absolute_path(const char* link, const char* target, char* return -LTFS_SMALL_BUFFER; } - arch_strcpy(buf,size, work_buf); + arch_strcpy(buf, size, work_buf); free(work_buf); free(target_buf); return 0; @@ -2089,8 +2013,7 @@ int ltfs_fsops_volume_sync(char *reason, struct ltfs_volume *vol) int ret; ret = ltfs_fsops_flush(NULL, false, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = ltfs_sync_index(reason, true, vol); diff --git a/src/libltfs/ltfs_fsops.h b/src/libltfs/ltfs_fsops.h index cfdea5f3..4f0cc723 100644 --- a/src/libltfs/ltfs_fsops.h +++ b/src/libltfs/ltfs_fsops.h @@ -54,6 +54,10 @@ #ifndef ltfs_fsops_h__ #define ltfs_fsops_h__ +#include "ltfs.h" +#include +#include +#include #ifdef __cplusplus extern "C" { diff --git a/src/libltfs/ltfs_fsops_raw.c b/src/libltfs/ltfs_fsops_raw.c index de61fa12..6a31ed1a 100644 --- a/src/libltfs/ltfs_fsops_raw.c +++ b/src/libltfs/ltfs_fsops_raw.c @@ -51,13 +51,13 @@ ************************************************************************************* */ -#include "ltfs.h" -#include "ltfs_internal.h" +#include "arch/time_internal.h" +#include "dcache.h" #include "fs.h" #include "index_criteria.h" -#include "arch/time_internal.h" +#include "ltfs.h" +#include "ltfs_internal.h" #include "tape.h" -#include "dcache.h" int ltfs_fsraw_open(const char *path, bool open_write, struct dentry **d, struct ltfs_volume *vol) { @@ -69,8 +69,7 @@ int ltfs_fsraw_open(const char *path, bool open_write, struct dentry **d, struct CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); ret = ltfs_get_volume_lock(false, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; if (dcache_initialized(vol)) ret = dcache_open(path, &dtmp, vol); @@ -78,16 +77,15 @@ int ltfs_fsraw_open(const char *path, bool open_write, struct dentry **d, struct ret = fs_path_lookup(path, 0, &dtmp, vol->index); if (ret < 0) { /* Print message only if the error code is an unexpected one */ - if (ret != -LTFS_NO_DENTRY && ret != -LTFS_NAMETOOLONG) - ltfsmsg(LTFS_ERR, 11040E, ret); + if (ret != -LTFS_NO_DENTRY && ret != -LTFS_NAMETOOLONG) ltfsmsg(LTFS_ERR, 11040E, ret); releaseread_mrsw(&vol->lock); return ret; } - if (open_write && ! dtmp->isdir) { + if (open_write && !dtmp->isdir) { uint64_t max_filesize = index_criteria_get_max_filesize(vol); acquirewrite_mrsw(&dtmp->meta_lock); - if (! dtmp->matches_name_criteria && max_filesize > 0 && dtmp->size <= max_filesize) + if (!dtmp->matches_name_criteria && max_filesize > 0 && dtmp->size <= max_filesize) dtmp->matches_name_criteria = index_criteria_match(dtmp, vol); releasewrite_mrsw(&dtmp->meta_lock); } @@ -113,8 +111,12 @@ int ltfs_fsraw_close(struct dentry *d) * to a read lock on exit. * It takes the tape device lock internally, so the caller must not hold any dentry meta lock. */ -int _ltfs_fsraw_write_data_unlocked(char partition, const char *buf, size_t count, uint64_t repetitions, - tape_block_t *startblock, struct ltfs_volume *vol) +int _ltfs_fsraw_write_data_unlocked(char partition, + const char *buf, + size_t count, + uint64_t repetitions, + tape_block_t *startblock, + struct ltfs_volume *vol) { int ret; uint64_t blocksize, rep_count; @@ -179,8 +181,7 @@ int _ltfs_fsraw_write_data_unlocked(char partition, const char *buf, size_t coun vol->ip_index_file_end = false; else { /* partition == ltfs_dp_id(vol) */ vol->dp_index_file_end = false; - if (!vol->first_locate.tv_sec && !vol->first_locate.tv_nsec) - is_first_dp_locate = true; + if (!vol->first_locate.tv_sec && !vol->first_locate.tv_nsec) is_first_dp_locate = true; } /* Write lock on the volume is not needed past this point */ @@ -210,8 +211,7 @@ int _ltfs_fsraw_write_data_unlocked(char partition, const char *buf, size_t coun } /* Tell the caller about the first block written */ - if (startblock) - *startblock = start.block; + if (startblock) *startblock = start.block; /* write blocks to tape */ for (rep_count = 0; rep_count < repetitions; ++rep_count) { @@ -239,8 +239,12 @@ int _ltfs_fsraw_write_data_unlocked(char partition, const char *buf, size_t coun return ret; } -int ltfs_fsraw_write_data(char partition, const char *buf, size_t count, uint64_t repetitions, - tape_block_t *startblock, struct ltfs_volume *vol) +int ltfs_fsraw_write_data(char partition, + const char *buf, + size_t count, + uint64_t repetitions, + tape_block_t *startblock, + struct ltfs_volume *vol) { int ret; @@ -249,14 +253,11 @@ int ltfs_fsraw_write_data(char partition, const char *buf, size_t count, uint64_ start: ret = ltfs_get_volume_lock(true, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = _ltfs_fsraw_write_data_unlocked(partition, buf, count, repetitions, startblock, vol); if (ret == -LTFS_DEVICE_FENCED || NEED_REVAL(ret)) { - ret = (ret == -LTFS_DEVICE_FENCED) ? - ltfs_wait_revalidation(vol) : ltfs_revalidate(false, vol); - if (ret == 0) - goto start; + ret = (ret == -LTFS_DEVICE_FENCED) ? ltfs_wait_revalidation(vol) : ltfs_revalidate(false, vol); + if (ret == 0) goto start; } else if (IS_UNEXPECTED_MOVE(ret)) { vol->reval = -LTFS_REVAL_FAILED; releaseread_mrsw(&vol->lock); @@ -269,8 +270,10 @@ int ltfs_fsraw_write_data(char partition, const char *buf, size_t count, uint64_ * Non-locking version of ltfs_fsraw_add_extent. * The caller should hold a read lock on vol->lock and a write lock on d->contents_lock. */ -int _ltfs_fsraw_add_extent_unlocked(struct dentry *d, struct extent_info *ext, bool update_time, - struct ltfs_volume *vol) +int _ltfs_fsraw_add_extent_unlocked(struct dentry *d, + struct extent_info *ext, + bool update_time, + struct ltfs_volume *vol) { struct extent_info *entry, *preventry; struct extent_info *ext_copy, *splitentry; @@ -285,15 +288,16 @@ int _ltfs_fsraw_add_extent_unlocked(struct dentry *d, struct extent_info *ext, b /* Copy the input extent now to avoid failing after the extent list has already been updated */ ext_copy = malloc(sizeof(struct extent_info)); - if (! ext_copy) { + if (!ext_copy) { ltfsmsg(LTFS_ERR, 10001E, "ltfs_append_extent_unlocked: extent copy"); return -LTFS_NO_MEMORY; } *ext_copy = *ext; /* Update the extent list */ - if (! TAILQ_EMPTY(&d->extentlist)) { - TAILQ_FOREACH_REVERSE_SAFE(entry, &d->extentlist, extent_struct, list, preventry) { + if (!TAILQ_EMPTY(&d->extentlist)) { + TAILQ_FOREACH_REVERSE_SAFE(entry, &d->extentlist, extent_struct, list, preventry) + { entry_fileoffset_end = entry->fileoffset + entry->bytecount; entry_byteoffset_end = entry->byteoffset + entry->bytecount; entry_blockcount = entry_byteoffset_end / blocksize; @@ -318,8 +322,7 @@ int _ltfs_fsraw_add_extent_unlocked(struct dentry *d, struct extent_info *ext, b entry_byteoffset_end = entry->byteoffset + entry->bytecount; entry_blockcount = entry_byteoffset_end / blocksize; } - } else if (ext->fileoffset > entry->fileoffset && - ext->fileoffset < entry_fileoffset_end) { + } else if (ext->fileoffset > entry->fileoffset && ext->fileoffset < entry_fileoffset_end) { if (ext_fileoffset_end >= entry_fileoffset_end) { /* Truncate entry from its end */ entry->bytecount = ext->fileoffset - entry->fileoffset; @@ -330,7 +333,7 @@ int _ltfs_fsraw_add_extent_unlocked(struct dentry *d, struct extent_info *ext, b } else { /* Split entry */ splitentry = malloc(sizeof(struct extent_info)); - if (! splitentry) { + if (!splitentry) { ltfsmsg(LTFS_ERR, 10001E, "ltfs_append_extent_unlocked: splitentry"); free(ext_copy); return -LTFS_NO_MEMORY; @@ -340,8 +343,7 @@ int _ltfs_fsraw_add_extent_unlocked(struct dentry *d, struct extent_info *ext, b fileoffset_diff = ext_fileoffset_end - entry->fileoffset; entry_byteoffset_mod = fileoffset_diff + entry->byteoffset; splitentry->start.partition = entry->start.partition; - splitentry->start.block = entry->start.block + - (entry_byteoffset_mod / blocksize); + splitentry->start.block = entry->start.block + (entry_byteoffset_mod / blocksize); splitentry->byteoffset = entry_byteoffset_mod % blocksize; splitentry->bytecount = entry->bytecount - fileoffset_diff; splitentry->fileoffset = ext_fileoffset_end; @@ -356,11 +358,9 @@ int _ltfs_fsraw_add_extent_unlocked(struct dentry *d, struct extent_info *ext, b } /* Process ext's contents by appending to entry or inserting ext after entry */ - if (entry && ext->fileoffset == entry_fileoffset_end && - entry->start.partition == ext->start.partition && - entry_byteoffset_end % blocksize == 0 && - entry->start.block + entry_blockcount == ext->start.block && - ext->byteoffset == 0) { + if (entry && ext->fileoffset == entry_fileoffset_end && entry->start.partition == ext->start.partition && + entry_byteoffset_end % blocksize == 0 && entry->start.block + entry_blockcount == ext->start.block && + ext->byteoffset == 0) { /* Add ext's bytes to entry */ entry->bytecount += ext->bytecount; realsize_new += ext->bytecount; @@ -377,7 +377,7 @@ int _ltfs_fsraw_add_extent_unlocked(struct dentry *d, struct extent_info *ext, b } } - if (! ext_used) { + if (!ext_used) { TAILQ_INSERT_HEAD(&d->extentlist, ext_copy, list); realsize_new += ext->bytecount; } else if (free_ext) @@ -385,8 +385,7 @@ int _ltfs_fsraw_add_extent_unlocked(struct dentry *d, struct extent_info *ext, b /* Update file size and times */ acquirewrite_mrsw(&d->meta_lock); - if (ext_fileoffset_end > d->size) - d->size = ext_fileoffset_end; + if (ext_fileoffset_end > d->size) d->size = ext_fileoffset_end; d->realsize = realsize_new; if (update_time) { get_current_timespec(&d->modify_time); @@ -406,8 +405,7 @@ int _ltfs_fsraw_add_extent_unlocked(struct dentry *d, struct extent_info *ext, b return 0; } -int ltfs_fsraw_add_extent(struct dentry *d, struct extent_info *ext, bool update_time, - struct ltfs_volume *vol) +int ltfs_fsraw_add_extent(struct dentry *d, struct extent_info *ext, bool update_time, struct ltfs_volume *vol) { int ret; @@ -418,51 +416,50 @@ int ltfs_fsraw_add_extent(struct dentry *d, struct extent_info *ext, bool update /* This function is not called until blocks are already on the tape, so the * out of space condition is not a problem. */ ret = ltfs_get_partition_readonly(ltfs_ip_id(vol), vol); - if (ret < 0 && ret != -LTFS_NO_SPACE && ret != -LTFS_LESS_SPACE) - return ret; + if (ret < 0 && ret != -LTFS_NO_SPACE && ret != -LTFS_LESS_SPACE) return ret; ret = ltfs_get_partition_readonly(ltfs_dp_id(vol), vol); - if (ret < 0 && ret != -LTFS_NO_SPACE && ret != -LTFS_LESS_SPACE) - return ret; + if (ret < 0 && ret != -LTFS_NO_SPACE && ret != -LTFS_LESS_SPACE) return ret; ret = ltfs_get_volume_lock(false, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; acquirewrite_mrsw(&d->contents_lock); ret = _ltfs_fsraw_add_extent_unlocked(d, ext, update_time, vol); releasewrite_mrsw(&d->contents_lock); - if (dcache_initialized(vol)) - ret = dcache_flush(d, FLUSH_EXTENT_LIST, vol); + if (dcache_initialized(vol)) ret = dcache_flush(d, FLUSH_EXTENT_LIST, vol); releaseread_mrsw(&vol->lock); return ret; } -int ltfs_fsraw_cleanup_extent(struct dentry *d, struct tc_position err_pos, unsigned long blocksize, struct ltfs_volume *vol) +int ltfs_fsraw_cleanup_extent(struct dentry *d, + struct tc_position err_pos, + unsigned long blocksize, + struct ltfs_volume *vol) { int ret = 0; - struct name_list *entry, *tmp; + struct name_list *entry, *tmp; struct extent_info *ext, *preventry; - struct tc_position extent_last = {0, 0, UINT32_MAX, false, false}; + struct tc_position extent_last = { 0, 0, UINT32_MAX, false, false }; if (HASH_COUNT(d->child_list) != 0) { - HASH_ITER(hh, d->child_list, entry, tmp) { + HASH_ITER(hh, d->child_list, entry, tmp) + { if (entry->d->isdir) { ret = ltfs_fsraw_cleanup_extent(entry->d, err_pos, blocksize, vol); - } - else { - TAILQ_FOREACH_REVERSE_SAFE(ext, &entry->d->extentlist, extent_struct, list, preventry) { + } else { + TAILQ_FOREACH_REVERSE_SAFE(ext, &entry->d->extentlist, extent_struct, list, preventry) + { if (ext->start.block && ext->bytecount) { extent_last.partition = ltfs_part_id2num(ext->start.partition, vol); /* Calculate the last block of this extent */ extent_last.block = ext->start.block + (ext->bytecount / blocksize); - if ( (ext->bytecount % blocksize) == 0 ) - extent_last.block--; + if ((ext->bytecount % blocksize) == 0) extent_last.block--; } else { extent_last.partition = UINT32_MAX; - extent_last.block = 0; + extent_last.block = 0; } /* @@ -470,22 +467,23 @@ int ltfs_fsraw_cleanup_extent(struct dentry *d, struct tc_position err_pos, unsi * but not transferred to the medium. * It means position (err_pos-1) is the last block on the medium. */ - if ( extent_last.partition == err_pos.partition && err_pos.block <= extent_last.block ) { - - ltfsmsg(LTFS_INFO, 11334I, entry->name, (unsigned long long)ext->start.block, (unsigned long long)ext->bytecount); + if (extent_last.partition == err_pos.partition && err_pos.block <= extent_last.block) { + ltfsmsg(LTFS_INFO, + 11334I, + entry->name, + (unsigned long long)ext->start.block, + (unsigned long long)ext->bytecount); ret = ltfs_get_volume_lock(false, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; acquirewrite_mrsw(&d->contents_lock); - entry->d->size -= ext->bytecount; + entry->d->size -= ext->bytecount; TAILQ_REMOVE(&entry->d->extentlist, ext, list); free(ext); releasewrite_mrsw(&d->contents_lock); - if (dcache_initialized(vol)) - ret = dcache_flush(d, FLUSH_EXTENT_LIST, vol); + if (dcache_initialized(vol)) ret = dcache_flush(d, FLUSH_EXTENT_LIST, vol); releaseread_mrsw(&vol->lock); } @@ -496,8 +494,13 @@ int ltfs_fsraw_cleanup_extent(struct dentry *d, struct tc_position err_pos, unsi return ret; } -int ltfs_fsraw_write(struct dentry *d, const char *buf, size_t count, off_t offset, char partition, - bool update_time, struct ltfs_volume *vol) +int ltfs_fsraw_write(struct dentry *d, + const char *buf, + size_t count, + off_t offset, + char partition, + bool update_time, + struct ltfs_volume *vol) { int ret; struct extent_info tmpext; @@ -512,14 +515,11 @@ int ltfs_fsraw_write(struct dentry *d, const char *buf, size_t count, off_t offs /* Take locks and write data to the medium */ start: ret = ltfs_get_volume_lock(true, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = _ltfs_fsraw_write_data_unlocked(partition, buf, count, 1, &logical_start.block, vol); if (ret == -LTFS_DEVICE_FENCED || NEED_REVAL(ret)) { - ret = (ret == -LTFS_DEVICE_FENCED) ? - ltfs_wait_revalidation(vol) : ltfs_revalidate(false, vol); - if (ret == 0) - goto start; + ret = (ret == -LTFS_DEVICE_FENCED) ? ltfs_wait_revalidation(vol) : ltfs_revalidate(false, vol); + if (ret == 0) goto start; return ret; } else if (IS_UNEXPECTED_MOVE(ret)) { vol->reval = -LTFS_REVAL_FAILED; @@ -545,8 +545,7 @@ int ltfs_fsraw_write(struct dentry *d, const char *buf, size_t count, off_t offs return ret; } -ssize_t ltfs_fsraw_read(struct dentry *d, char *buf, size_t count, off_t offset, - struct ltfs_volume *vol) +ssize_t ltfs_fsraw_read(struct dentry *d, char *buf, size_t count, off_t offset, struct ltfs_volume *vol) { int ret; uint64_t next_off, last_off; @@ -566,15 +565,13 @@ ssize_t ltfs_fsraw_read(struct dentry *d, char *buf, size_t count, off_t offset, CHECK_ARG_NULL(d, -LTFS_NULL_ARG); CHECK_ARG_NULL(buf, -LTFS_NULL_ARG); - if (count == 0) - return 0; + if (count == 0) return 0; /* Lock the index, dentry and device */ start: read_count = 0; ret = ltfs_get_volume_lock(false, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; acquireread_mrsw(&d->contents_lock); ret = tape_device_lock(vol->device); if (ret == -LTFS_DEVICE_FENCED) { @@ -592,9 +589,9 @@ ssize_t ltfs_fsraw_read(struct dentry *d, char *buf, size_t count, off_t offset, } /* allocate the last block cache if necessary */ - if (! vol->last_block) { + if (!vol->last_block) { vol->last_block = malloc(vol->label->blocksize); - if (! vol->last_block) { + if (!vol->last_block) { ltfsmsg(LTFS_ERR, 10001E, "ltfs_fsraw_read: block cache"); ret = -LTFS_NO_MEMORY; goto out_unlock; @@ -605,9 +602,9 @@ ssize_t ltfs_fsraw_read(struct dentry *d, char *buf, size_t count, off_t offset, next_off = (uint64_t)offset; last_off = (uint64_t)offset + count; - TAILQ_FOREACH(entry, &d->extentlist, list) { - if (read_count == count) - break; + TAILQ_FOREACH(entry, &d->extentlist, list) + { + if (read_count == count) break; entry_fileoffset_end = entry->fileoffset + entry->bytecount; @@ -634,17 +631,14 @@ ssize_t ltfs_fsraw_read(struct dentry *d, char *buf, size_t count, off_t offset, /* Compute target position */ seekpos.partition = ltfs_part_id2num(entry->start.partition, vol); - seekpos.block = entry->start.block + - (next_off - entry->fileoffset + entry->byteoffset) / blocksize; + seekpos.block = entry->start.block + (next_off - entry->fileoffset + entry->byteoffset) / blocksize; /* Seek if required */ if ((curpos.partition != seekpos.partition || curpos.block != seekpos.block) && - ! (curpos.partition == seekpos.partition && curpos.block == seekpos.block + 1 && - entry->start.partition == vol->last_pos.partition && - seekpos.block == vol->last_pos.block)) { - + !(curpos.partition == seekpos.partition && curpos.block == seekpos.block + 1 && + entry->start.partition == vol->last_pos.partition && seekpos.block == vol->last_pos.block)) { if (!vol->first_locate.tv_sec && !vol->first_locate.tv_nsec && - (seekpos.partition == (uint32_t)ltfs_dp_id(vol))) { + (seekpos.partition == (uint32_t)ltfs_dp_id(vol))) { get_current_timespec(&ts_start); is_first_dp_locate = true; vol->first_locate.tv_sec = UINT64_MAX; @@ -663,19 +657,16 @@ ssize_t ltfs_fsraw_read(struct dentry *d, char *buf, size_t count, off_t offset, } /* Read from the extent until end of extent or output buffer full */ - firstbyte = entry->fileoffset - entry->byteoffset + - (seekpos.block - entry->start.block) * blocksize; + firstbyte = entry->fileoffset - entry->byteoffset + (seekpos.block - entry->start.block) * blocksize; lastbyte = firstbyte; while (entry_fileoffset_end > next_off && read_count < count) { lastbyte += blocksize; - if (entry_fileoffset_end < lastbyte) - lastbyte = entry_fileoffset_end; + if (entry_fileoffset_end < lastbyte) lastbyte = entry_fileoffset_end; blockbytes = lastbyte - firstbyte; /* Read this block into a temp buffer or return the existing contents */ - if (entry->start.partition == vol->last_pos.partition && - seekpos.block == vol->last_pos.block && - (seekpos.partition == curpos.partition && seekpos.block + 1 == curpos.block)) { + if (entry->start.partition == vol->last_pos.partition && seekpos.block == vol->last_pos.block && + (seekpos.partition == curpos.partition && seekpos.block + 1 == curpos.block)) { if (vol->last_size < blockbytes) { ltfsmsg(LTFS_ERR, 11087E, (unsigned int)blockbytes, vol->last_size); ret = -LTFS_SMALL_BLOCK; @@ -684,17 +675,15 @@ ssize_t ltfs_fsraw_read(struct dentry *d, char *buf, size_t count, off_t offset, } else { if (blocksize == blockbytes) - nread = tape_read(vol->device, vol->last_block, blocksize, false, - vol->kmi_handle); + nread = tape_read(vol->device, vol->last_block, blocksize, false, vol->kmi_handle); else - nread = tape_read(vol->device, vol->last_block, blocksize, true, - vol->kmi_handle); + nread = tape_read(vol->device, vol->last_block, blocksize, true, vol->kmi_handle); if (nread < 0) { ret = nread; ltfsmsg(LTFS_ERR, 11088E, ret); goto out_unlock; - } else if ((size_t) nread < blockbytes) { + } else if ((size_t)nread < blockbytes) { ltfsmsg(LTFS_ERR, 11089E, (unsigned int)blockbytes, (unsigned int)nread); ret = -LTFS_SMALL_BLOCK; goto out_unlock; @@ -738,8 +727,7 @@ ssize_t ltfs_fsraw_read(struct dentry *d, char *buf, size_t count, off_t offset, tape_start_fence(vol->device); tape_device_unlock(vol->device); ret = ltfs_revalidate(false, vol); - if (ret == 0) - goto start; + if (ret == 0) goto start; } else if (IS_UNEXPECTED_MOVE(ret)) { vol->reval = -LTFS_REVAL_FAILED; tape_device_unlock(vol->device); @@ -749,8 +737,7 @@ ssize_t ltfs_fsraw_read(struct dentry *d, char *buf, size_t count, off_t offset, releaseread_mrsw(&vol->lock); } - if (ret < 0) - return ret; + if (ret < 0) return ret; return read_count; } @@ -764,15 +751,15 @@ int ltfs_fsraw_truncate(struct dentry *d, off_t length, struct ltfs_volume *vol) CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); ret = ltfs_get_volume_lock(false, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; acquirewrite_mrsw(&d->contents_lock); new_realsize = d->realsize; /* Truncate the extent list if necessary */ - if (ulength < d->size && ! TAILQ_EMPTY(&d->extentlist)) { - TAILQ_FOREACH_REVERSE_SAFE(entry, &d->extentlist, extent_struct, list, preventry) { + if (ulength < d->size && !TAILQ_EMPTY(&d->extentlist)) { + TAILQ_FOREACH_REVERSE_SAFE(entry, &d->extentlist, extent_struct, list, preventry) + { entry_fileoffset_last = entry->fileoffset + entry->bytecount; if (entry->fileoffset >= ulength || ulength == 0) { /* This extent is full past the new EOF */ @@ -812,8 +799,7 @@ struct dentry *ltfs_fsraw_get_dentry(struct dentry *d, struct ltfs_volume *vol) CHECK_ARG_NULL(vol, NULL); ret = ltfs_get_volume_lock(false, vol); - if (ret < 0) - return NULL; + if (ret < 0) return NULL; if (dcache_initialized(vol)) { dcache_get_dentry(d, vol); } else { @@ -827,10 +813,10 @@ struct dentry *ltfs_fsraw_get_dentry(struct dentry *d, struct ltfs_volume *vol) void ltfs_fsraw_put_dentry(struct dentry *d, struct ltfs_volume *vol) { - if (! d) { + if (!d) { ltfsmsg(LTFS_WARN, 10006W, "d", __FUNCTION__); return; - } else if (! vol) { + } else if (!vol) { ltfsmsg(LTFS_WARN, 10006W, "vol", __FUNCTION__); return; } diff --git a/src/libltfs/ltfs_internal.c b/src/libltfs/ltfs_internal.c index 6059a0fc..7e327851 100644 --- a/src/libltfs/ltfs_internal.c +++ b/src/libltfs/ltfs_internal.c @@ -47,20 +47,20 @@ ************************************************************************************* */ -#include "ltfs.h" #include "ltfs_internal.h" -#include "libltfs/ltfslogging.h" -#include "tape.h" -#include "fs.h" -#include "xml_libltfs.h" -#include "label.h" +#include "arch/time_internal.h" #include "dcache.h" +#include "fs.h" #include "index_criteria.h" -#include "arch/time_internal.h" -#include "libltfs/arch/osx/osx_string.h" #include "iosched.h" +#include "label.h" +#include "libltfs/arch/osx/osx_string.h" +#include "libltfs/ltfslogging.h" +#include "ltfs.h" #include "ltfs_fsops.h" +#include "tape.h" #include "xattr.h" +#include "xml_libltfs.h" /** * Allocate an empty LTFS index. @@ -111,7 +111,7 @@ int ltfs_index_alloc(struct ltfs_index **index, struct ltfs_volume *vol) newindex->version = LTFS_INDEX_VERSION; newindex->root = fs_allocate_dentry(NULL, "/", NULL, true, false, false, newindex); - if (! newindex->root) { + if (!newindex->root) { ltfsmsg(LTFS_ERR, 11168E); ltfs_index_free(&newindex); return -LTFS_NO_MEMORY; @@ -130,8 +130,7 @@ void _ltfs_index_free(bool force, struct ltfs_index **index) { size_t i; - if (! index || ! *index) - return; + if (!index || !*index) return; ltfs_mutex_lock(&(*index)->refcount_lock); (*index)->refcount--; @@ -139,26 +138,21 @@ void _ltfs_index_free(bool force, struct ltfs_index **index) ltfs_mutex_unlock(&(*index)->refcount_lock); ltfs_mutex_destroy(&(*index)->refcount_lock); - if ((*index)->root) - fs_release_dentry((*index)->root); + if ((*index)->root) fs_release_dentry((*index)->root); ltfs_mutex_destroy(&(*index)->dirty_lock); ltfs_mutex_destroy(&(*index)->rename_lock); if ((*index)->tag_count > 0) { - for (i=0; i<(*index)->tag_count; ++i) + for (i = 0; i < (*index)->tag_count; ++i) free((*index)->preserved_tags[i]); free((*index)->preserved_tags); } index_criteria_free(&((*index)->original_criteria)); index_criteria_free(&((*index)->index_criteria)); - if ((*index)->commit_message) - free((*index)->commit_message); - if ((*index)->volume_name.name) - free((*index)->volume_name.name); - if ((*index)->creator) - free((*index)->creator); - if ((*index)->symerr_count > 0) - free((*index)->symlink_conflict); + if ((*index)->commit_message) free((*index)->commit_message); + if ((*index)->volume_name.name) free((*index)->volume_name.name); + if ((*index)->creator) free((*index)->creator); + if ((*index)->symerr_count > 0) free((*index)->symlink_conflict); free(*index); *index = NULL; } else @@ -190,28 +184,24 @@ int ltfs_read_labels(bool trial, struct ltfs_volume *vol) ret = ltfs_read_one_label(0, label0, vol); if (ret < 0) { - if (! trial || ret != -LTFS_LABEL_INVALID) - ltfsmsg(LTFS_ERR, 11170E, ret); + if (!trial || ret != -LTFS_LABEL_INVALID) ltfsmsg(LTFS_ERR, 11170E, ret); goto out_free; } ret = ltfs_read_one_label(1, label1, vol); if (ret < 0) { - if (! trial || ret != -LTFS_LABEL_INVALID) - ltfsmsg(LTFS_ERR, 11171E, ret); + if (!trial || ret != -LTFS_LABEL_INVALID) ltfsmsg(LTFS_ERR, 11171E, ret); goto out_free; } /* Check labels for consistency */ ret = label_compare(label0, label1); if (ret < 0) { - if (! trial || ret != -LTFS_LABEL_MISMATCH) - ltfsmsg(LTFS_ERR, 11172E, ret); + if (!trial || ret != -LTFS_LABEL_MISMATCH) ltfsmsg(LTFS_ERR, 11172E, ret); goto out_free; } /* Clear label */ - if (vol->label->creator) - free(vol->label->creator); + if (vol->label->creator) free(vol->label->creator); /* Store label data in the supplied volume */ vol->label->creator = label0->creator; @@ -230,10 +220,8 @@ int ltfs_read_labels(bool trial, struct ltfs_volume *vol) vol->label->version = label0->version; out_free: - if (label0) - label_free(&label0); - if (label1) - label_free(&label1); + if (label0) label_free(&label0); + if (label1) label_free(&label1); return ret; } @@ -244,8 +232,7 @@ int ltfs_read_labels(bool trial, struct ltfs_volume *vol) * @param label structure to populate with label contents * @param vol LTFS volume */ -int ltfs_read_one_label(tape_partition_t partition, struct ltfs_label *label, - struct ltfs_volume *vol) +int ltfs_read_one_label(tape_partition_t partition, struct ltfs_label *label, struct ltfs_volume *vol) { int ret; char *buf = NULL; @@ -282,8 +269,7 @@ int ltfs_read_one_label(tape_partition_t partition, struct ltfs_label *label, /* Simple heuristic to detect an unpartitioned tape: seeking to partition 1 fails. * Note that the seek may fail for other reasons, which can't currently be distinguished * by looking at the backend return codes. */ - if (ret <= -LTFS_ERR_MIN && partition == 1) - ret = -LTFS_NOT_PARTITIONED; + if (ret <= -LTFS_ERR_MIN && partition == 1) ret = -LTFS_NOT_PARTITIONED; goto out_free; } @@ -306,11 +292,11 @@ int ltfs_read_one_label(tape_partition_t partition, struct ltfs_label *label, too_long = true; } - memcpy(label->barcode, buf+4, 6); + memcpy(label->barcode, buf + 4, 6); label->barcode[6] = 0x00; /* check for LTFS signature */ - memcpy(ansi_sig, buf+24, 4); + memcpy(ansi_sig, buf + 24, 4); ansi_sig[4] = '\0'; if (strcmp(ansi_sig, "LTFS")) { ltfsmsg(LTFS_ERR, 11176E); @@ -372,8 +358,7 @@ int ltfs_read_one_label(tape_partition_t partition, struct ltfs_label *label, out_free: free(buf); - if (ret && too_long && ansi_valid) - return -LTFS_LABEL_POSSIBLE_VALID; + if (ret && too_long && ansi_valid) return -LTFS_LABEL_POSSIBLE_VALID; return ret; } @@ -411,9 +396,9 @@ int ltfs_read_index(uint64_t eod_pos, bool recover_symlink, struct ltfs_volume * /* Parse and validate the schema */ ret = xml_schema_from_tape(eod_pos, vol); - if ( vol->index->symerr_count ) { - if ( recover_symlink ) { - ret_sym = ltfs_split_symlink( vol ); + if (vol->index->symerr_count) { + if (recover_symlink) { + ret_sym = ltfs_split_symlink(vol); if (ret_sym < 0) { ret = ret_sym; } else if (ret == -LTFS_SYMLINK_CONFLICT) { @@ -422,7 +407,7 @@ int ltfs_read_index(uint64_t eod_pos, bool recover_symlink, struct ltfs_volume * } else { ltfsmsg(LTFS_ERR, 11321E); } - free( vol->index->symlink_conflict ); + free(vol->index->symlink_conflict); vol->index->symerr_count = 0; } @@ -440,20 +425,18 @@ int ltfs_read_index(uint64_t eod_pos, bool recover_symlink, struct ltfs_volume * /* check self pointer */ if (vol->index->selfptr.partition != vol->label->part_num2id[pos.partition] || - vol->index->selfptr.block != pos.block) { + vol->index->selfptr.block != pos.block) { ltfsmsg(LTFS_WARN, 11196W); return -LTFS_INDEX_INVALID; } /* basic back pointer checks */ - if (vol->index->backptr.partition != 0 && - vol->index->backptr.partition != vol->label->partid_dp) { + if (vol->index->backptr.partition != 0 && vol->index->backptr.partition != vol->label->partid_dp) { ltfsmsg(LTFS_ERR, 11197E); return -LTFS_INDEX_INVALID; - } else if (vol->index->backptr.partition == vol->index->selfptr.partition && - vol->index->selfptr.block != 5 && - vol->index->backptr.block != vol->index->selfptr.block && - vol->index->backptr.block >= vol->index->selfptr.block - 2 ) { + } else if (vol->index->backptr.partition == vol->index->selfptr.partition && vol->index->selfptr.block != 5 && + vol->index->backptr.block != vol->index->selfptr.block && + vol->index->backptr.block >= vol->index->selfptr.block - 2) { ltfsmsg(LTFS_ERR, 11197E); return -LTFS_INDEX_INVALID; } else if (vol->index->backptr.partition != 0 && vol->index->backptr.block < 5) { @@ -482,12 +465,12 @@ bool ltfs_is_valid_partid(char id) } #define check_err(cmd, msgid, label) \ - do { \ - ret = (cmd); \ - if (ret < 0) { \ + do { \ + ret = (cmd); \ + if (ret < 0) { \ ltfsmsg(LTFS_ERR, msgid, ret); \ - goto label; \ - } \ + goto label; \ + } \ } while (0) /** @@ -502,8 +485,13 @@ bool ltfs_is_valid_partid(char id) * @param vol LTFS volume * @return 0 on success, 1 if no index was found, or a negative value on error. */ -int ltfs_seek_index(char partition, tape_block_t *eod_pos, tape_block_t *index_end_pos, - bool *fm_after, bool *blocks_after, bool recover_symlink, struct ltfs_volume *vol) +int ltfs_seek_index(char partition, + tape_block_t *eod_pos, + tape_block_t *index_end_pos, + bool *fm_after, + bool *blocks_after, + bool recover_symlink, + struct ltfs_volume *vol) { int ret; struct tc_position eod, pos; @@ -531,7 +519,7 @@ int ltfs_seek_index(char partition, tape_block_t *eod_pos, tape_block_t *index_e } else if (pos.block == eod.block - 1) check_err(tape_spacefm(vol->device, -1), 11201E, out); - while (! have_index) { + while (!have_index) { /* did we reach the end of the partition label? */ check_err(tape_get_position(vol->device, &pos), 11200E, out); if (pos.block == 3) { @@ -555,8 +543,7 @@ int ltfs_seek_index(char partition, tape_block_t *eod_pos, tape_block_t *index_e break; /* Keep seeking index when ignoring wring version index */ case -LTFS_UNSUPPORTED_INDEX_VERSION: - if (vol->ignore_wrong_version) - keep_seeking = true; + if (vol->ignore_wrong_version) keep_seeking = true; break; /* Otherwise keep seeking index */ default: @@ -574,7 +561,7 @@ int ltfs_seek_index(char partition, tape_block_t *eod_pos, tape_block_t *index_e *fm_after = (ret == 0); check_err(tape_get_position(vol->device, &pos), 11200E, out); *index_end_pos = pos.block; - *blocks_after = ! (pos.block == eod.block); + *blocks_after = !(pos.block == eod.block); } else { /* Unexpected return codes */ /* TODO: Need to add a message */ @@ -609,8 +596,7 @@ int ltfs_seek_index(char partition, tape_block_t *eod_pos, tape_block_t *index_e * @param vol LTFS volume. The label field must be populated with a block size and partition map. * @return 0 on success or a negative value on error. */ -int _ltfs_check_extents(struct dentry *d, tape_block_t ip_eod, tape_block_t dp_eod, - struct ltfs_volume *vol) +int _ltfs_check_extents(struct dentry *d, tape_block_t ip_eod, tape_block_t dp_eod, struct ltfs_volume *vol) { int ret; struct extent_info *ext; @@ -618,20 +604,20 @@ int _ltfs_check_extents(struct dentry *d, tape_block_t ip_eod, tape_block_t dp_e struct name_list *list, *tmp; if (d->isdir && HASH_COUNT(d->child_list) != 0) { - HASH_ITER(hh, d->child_list, list, tmp) { + HASH_ITER(hh, d->child_list, list, tmp) + { ret = _ltfs_check_extents(list->d, ip_eod, dp_eod, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; } - } else if (! TAILQ_EMPTY(&d->extentlist)) { - TAILQ_FOREACH(ext, &d->extentlist, list) { + } else if (!TAILQ_EMPTY(&d->extentlist)) { + TAILQ_FOREACH(ext, &d->extentlist, list) + { ext_lastblock = ext->start.block + ext->bytecount / vol->label->blocksize; ext_lastblock += (ext->bytecount % vol->label->blocksize > 0) ? 1 : 0; - if (ext->start.block < 4) - return -LTFS_INDEX_INVALID; + if (ext->start.block < 4) return -LTFS_INDEX_INVALID; if ((ext->start.partition == vol->label->partid_ip && ext_lastblock >= ip_eod) || - (ext->start.partition == vol->label->partid_dp && ext_lastblock >= dp_eod)) + (ext->start.partition == vol->label->partid_dp && ext_lastblock >= dp_eod)) return -LTFS_INDEX_INVALID; } } @@ -652,14 +638,13 @@ int _ltfs_check_extents(struct dentry *d, tape_block_t ip_eod, tape_block_t dp_e * @return 0 if IP index file is newer, 1 if DP index file is newer, 2 if both index files * are NULL, or a negative value on error. */ -int _ltfs_check_pointers(struct ltfs_index *ip_index, struct ltfs_index *dp_index, - struct ltfs_volume *vol) +int _ltfs_check_pointers(struct ltfs_index *ip_index, struct ltfs_index *dp_index, struct ltfs_volume *vol) { int ret; tape_block_t ip_backptr, dp_backptr; struct tc_position seekpos; - if (! ip_index) { + if (!ip_index) { if (dp_index) { /* DP index file is newer */ return 1; @@ -669,7 +654,7 @@ int _ltfs_check_pointers(struct ltfs_index *ip_index, struct ltfs_index *dp_inde } } - if (! dp_index) { + if (!dp_index) { if (ip_index->backptr.partition != 0) { /* IP backpointer to nonexistent DP index file */ ltfsmsg(LTFS_ERR, 11205E); @@ -679,19 +664,17 @@ int _ltfs_check_pointers(struct ltfs_index *ip_index, struct ltfs_index *dp_inde return 0; } - /* have both index files */ + /* have both index files */ } else { - if (ip_index->generation >= dp_index->generation && - ip_index->backptr.partition == dp_index->selfptr.partition && - ip_index->backptr.block == dp_index->selfptr.block) { + if (ip_index->generation >= dp_index->generation && ip_index->backptr.partition == dp_index->selfptr.partition && + ip_index->backptr.block == dp_index->selfptr.block) { /* IP index file is newer */ return 0; } else if (ip_index->generation > dp_index->generation) { /* IP backpointer doesn't match DP index file */ ltfsmsg(LTFS_ERR, 11206E); return -LTFS_INDEX_INVALID; - } else if (ip_index->generation == dp_index->generation && - ip_index->backptr.partition == 0) { + } else if (ip_index->generation == dp_index->generation && ip_index->backptr.partition == 0) { /* DP index file is newer */ return 1; } else { @@ -702,14 +685,11 @@ int _ltfs_check_pointers(struct ltfs_index *ip_index, struct ltfs_index *dp_inde if (dp_backptr > ip_backptr) { seekpos.block = dp_backptr; ret = tape_seek(vol->device, &seekpos); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = ltfs_read_index(0, false, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; dp_backptr = vol->index->backptr.block; - if (ip_index->backptr.partition == 0 && - vol->index->generation < ip_index->generation) { + if (ip_index->backptr.partition == 0 && vol->index->generation < ip_index->generation) { /* IP index file is missing its back pointer */ ltfsmsg(LTFS_ERR, 11207E); ltfs_index_free(&vol->index); @@ -723,20 +703,21 @@ int _ltfs_check_pointers(struct ltfs_index *ip_index, struct ltfs_index *dp_inde } } -void _ltfs_last_ref(struct dentry *d, tape_block_t *dp_last, tape_block_t *ip_last, - struct ltfs_volume *vol) +void _ltfs_last_ref(struct dentry *d, tape_block_t *dp_last, tape_block_t *ip_last, struct ltfs_volume *vol) { struct extent_info *ext; tape_block_t ext_lastblock; struct name_list *list, *tmp; if (d->isdir && HASH_COUNT(d->child_list) != 0) { - HASH_ITER(hh, d->child_list, list, tmp) { + HASH_ITER(hh, d->child_list, list, tmp) + { _ltfs_last_ref(list->d, dp_last, ip_last, vol); } - } else if (! TAILQ_EMPTY(&d->extentlist)) { - TAILQ_FOREACH(ext, &d->extentlist, list) { + } else if (!TAILQ_EMPTY(&d->extentlist)) { + TAILQ_FOREACH(ext, &d->extentlist, list) + { ext_lastblock = ext->start.block + ext->bytecount / vol->label->blocksize; ext_lastblock += (ext->bytecount % vol->label->blocksize > 0) ? 1 : 0; if (ext->start.partition == vol->label->partid_ip && ext_lastblock > *ip_last) @@ -753,8 +734,7 @@ void _ltfs_last_ref(struct dentry *d, tape_block_t *dp_last, tape_block_t *ip_la * where the extent starts. * @return 0 on success or a negative value on error. */ -int _ltfs_populate_lost_found(char partition, tape_block_t part_lastref, - tape_block_t part_eod, struct ltfs_volume *vol) +int _ltfs_populate_lost_found(char partition, tape_block_t part_lastref, tape_block_t part_eod, struct ltfs_volume *vol) { int err, ret = 0; char *buf; @@ -771,19 +751,18 @@ int _ltfs_populate_lost_found(char partition, tape_block_t part_lastref, if (dcache_enabled) { err = dcache_open("/", &root, vol); - if (err < 0) - return ret; + if (err < 0) return ret; err = dcache_openat("/", root, LTFS_LOSTANDFOUND_DIR, &lf_dir, vol); if (err < 0) { dcache_close(root, true, true, vol); return err; - } else if (! lf_dir) { + } else if (!lf_dir) { err = dcache_create(LTFS_LOSTANDFOUND_DIR, root, vol); if (err < 0) { dcache_close(root, true, true, vol); return err; } - err = dcache_open("/"LTFS_LOSTANDFOUND_DIR, &lf_dir, vol); + err = dcache_open("/" LTFS_LOSTANDFOUND_DIR, &lf_dir, vol); if (err < 0) { dcache_close(root, true, true, vol); return err; @@ -792,11 +771,10 @@ int _ltfs_populate_lost_found(char partition, tape_block_t part_lastref, lfdir_descend = true; } } else { - ret = fs_path_lookup("/"LTFS_LOSTANDFOUND_DIR, 0, &lf_dir, vol->index); + ret = fs_path_lookup("/" LTFS_LOSTANDFOUND_DIR, 0, &lf_dir, vol->index); if (ret == -LTFS_NO_DENTRY) { - lf_dir = fs_allocate_dentry(vol->index->root, LTFS_LOSTANDFOUND_DIR, NULL, true, false, true, - vol->index); - if (! lf_dir) { + lf_dir = fs_allocate_dentry(vol->index->root, LTFS_LOSTANDFOUND_DIR, NULL, true, false, true, vol->index); + if (!lf_dir) { ltfsmsg(LTFS_ERR, 11209E); return -LTFS_NO_MEMORY; } @@ -816,7 +794,7 @@ int _ltfs_populate_lost_found(char partition, tape_block_t part_lastref, } buf = malloc(vol->label->blocksize + LTFS_CRC_SIZE); - if (! buf) { + if (!buf) { ltfsmsg(LTFS_ERR, 10001E, "_ltfs_populate_lost_found: buffer"); if (dcache_enabled) dcache_close(lf_dir, true, lfdir_descend, vol); @@ -843,8 +821,12 @@ int _ltfs_populate_lost_found(char partition, tape_block_t part_lastref, ltfsmsg(LTFS_WARN, 11210W, (unsigned long)seekpos.partition); } else { /* generate a descriptive-but-probably-not-helpful filename */ - ret = asprintf(&fname_path, "/%s/partition%"PRIu32"_block%"PRIu64"_%zdbytes", - LTFS_LOSTANDFOUND_DIR, seekpos.partition, seekpos.block, nr); + ret = asprintf(&fname_path, + "/%s/partition%" PRIu32 "_block%" PRIu64 "_%zdbytes", + LTFS_LOSTANDFOUND_DIR, + seekpos.partition, + seekpos.block, + nr); if (ret < 0) { ltfsmsg(LTFS_ERR, 10001E, "_ltfs_populate_lost_found: file name"); ret = -LTFS_NO_MEMORY; @@ -853,12 +835,9 @@ int _ltfs_populate_lost_found(char partition, tape_block_t part_lastref, fname = strstr(&fname_path[1], "/") + 1; /* create a file containing this extent */ - ret = dcache_enabled ? - dcache_open(fname_path, &file, vol) : - fs_directory_lookup(lf_dir, fname, &file); - if (ret < 0) - goto out_free; - if (! file) { + ret = dcache_enabled ? dcache_open(fname_path, &file, vol) : fs_directory_lookup(lf_dir, fname, &file); + if (ret < 0) goto out_free; + if (!file) { if (dcache_enabled) { ret = dcache_create(fname, lf_dir, vol); if (ret < 0) { @@ -875,7 +854,7 @@ int _ltfs_populate_lost_found(char partition, tape_block_t part_lastref, } else { file = fs_allocate_dentry(lf_dir, fname, NULL, false, true, true, vol->index); free(fname_path); - if (! file) { + if (!file) { /* Cannot populate lost and found directory: failed to allocate file data */ ltfsmsg(LTFS_ERR, 11211E); ret = -LTFS_NO_MEMORY; @@ -884,7 +863,7 @@ int _ltfs_populate_lost_found(char partition, tape_block_t part_lastref, } ext = calloc(1, sizeof(struct extent_info)); - if (! ext) { + if (!ext) { ltfsmsg(LTFS_ERR, 10001E, "_ltfs_populate_lost_found: extent"); ret = -LTFS_NO_MEMORY; goto out_free; @@ -892,8 +871,7 @@ int _ltfs_populate_lost_found(char partition, tape_block_t part_lastref, acquirewrite_mrsw(&file->contents_lock); acquirewrite_mrsw(&file->meta_lock); - if (! dcache_enabled) - ++file->numhandles; + if (!dcache_enabled) ++file->numhandles; get_current_timespec(&file->creation_time); file->modify_time = file->creation_time; file->access_time = file->creation_time; @@ -936,10 +914,8 @@ int _ltfs_populate_lost_found(char partition, tape_block_t part_lastref, out_free: if (dcache_enabled) { - if (root) - dcache_close(root, true, true, vol); - if (lf_dir) - dcache_close(lf_dir, true, lfdir_descend, vol); + if (root) dcache_close(root, true, true, vol); + if (lf_dir) dcache_close(lf_dir, true, lfdir_descend, vol); } else fs_release_dentry(lf_dir); free(buf); @@ -950,8 +926,11 @@ int _ltfs_populate_lost_found(char partition, tape_block_t part_lastref, * Recover extra (unreferenced) blocks from the tape by creating a "lost and found" directory * with one file for each extra extent found at the end of each partition. */ -int _ltfs_make_lost_found(tape_block_t ip_eod, tape_block_t dp_eod, - tape_block_t ip_endofidx, tape_block_t dp_endofidx, struct ltfs_volume *vol) +int _ltfs_make_lost_found(tape_block_t ip_eod, + tape_block_t dp_eod, + tape_block_t ip_endofidx, + tape_block_t dp_endofidx, + struct ltfs_volume *vol) { int ret; tape_block_t lastblock_d = 0, lastblock_i = 0; @@ -965,8 +944,7 @@ int _ltfs_make_lost_found(tape_block_t ip_eod, tape_block_t dp_eod, ret = _ltfs_populate_lost_found(ltfs_ip_id(vol), lastblock_i + 1, ip_eod, vol); else ret = _ltfs_populate_lost_found(ltfs_ip_id(vol), ip_endofidx, ip_eod, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; } if (dp_endofidx < dp_eod) { @@ -974,8 +952,7 @@ int _ltfs_make_lost_found(tape_block_t ip_eod, tape_block_t dp_eod, ret = _ltfs_populate_lost_found(ltfs_dp_id(vol), lastblock_d + 1, dp_eod, vol); else ret = _ltfs_populate_lost_found(ltfs_dp_id(vol), dp_endofidx, dp_eod, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; } ltfs_set_index_dirty(true, false, vol->index); @@ -1013,7 +990,8 @@ int ltfs_check_medium(bool fix, bool deep, bool recover_extra, bool recover_syml tape_block_t dp_eod, ip_eod, dp_endofidx = 0, ip_endofidx = 0; tape_block_t lastblock_d = 0, lastblock_i = 0; tape_partition_t ip_num, dp_num; - struct ltfs_index *dp_index = NULL, *ip_index = NULL;; + struct ltfs_index *dp_index = NULL, *ip_index = NULL; + ; CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); @@ -1021,16 +999,20 @@ int ltfs_check_medium(bool fix, bool deep, bool recover_extra, bool recover_syml dp_num = ltfs_part_id2num(ltfs_dp_id(vol), vol); /* look for index files */ - check_err(ltfs_seek_index(vol->label->partid_ip, &ip_eod, &ip_endofidx, &ip_fm_after, - &ip_blocks_after, recover_symlink, vol), 11214E, out_unlock); + check_err(ltfs_seek_index( + vol->label->partid_ip, &ip_eod, &ip_endofidx, &ip_fm_after, &ip_blocks_after, recover_symlink, vol), + 11214E, + out_unlock); ip_have_index = (ret == 0); if (ip_have_index) { ip_index = vol->index; vol->index = NULL; } - check_err(ltfs_seek_index(vol->label->partid_dp, &dp_eod, &dp_endofidx, &dp_fm_after, - &dp_blocks_after, recover_symlink, vol), 11213E, out_unlock); + check_err(ltfs_seek_index( + vol->label->partid_dp, &dp_eod, &dp_endofidx, &dp_fm_after, &dp_blocks_after, recover_symlink, vol), + 11213E, + out_unlock); dp_have_index = (ret == 0); if (dp_have_index) { dp_index = vol->index; @@ -1038,26 +1020,24 @@ int ltfs_check_medium(bool fix, bool deep, bool recover_extra, bool recover_syml } /* TODO: print more detailed diagnostic data here */ - if (! ip_have_index && ! dp_have_index) { + if (!ip_have_index && !dp_have_index) { ltfsmsg(LTFS_ERR, 11253E); ret = -LTFS_NO_INDEX; goto out_unlock; } - if (! ip_have_index) - ltfsmsg(LTFS_INFO, 11257I); - if (! dp_have_index) - ltfsmsg(LTFS_INFO, 11258I); + if (!ip_have_index) ltfsmsg(LTFS_INFO, 11257I); + if (!dp_have_index) ltfsmsg(LTFS_INFO, 11258I); /* fill in missing file marks if necessary */ - if (dp_have_index && ! dp_blocks_after && ! dp_fm_after) { + if (dp_have_index && !dp_blocks_after && !dp_fm_after) { ltfsmsg(LTFS_INFO, 11255I); check_err(tape_seek_eod(vol->device, dp_num), 11215E, out_unlock); check_err(tape_write_filemark(vol->device, 1, true, true, false), 11217E, out_unlock); dp_fm_after = true; ++dp_eod; } - if (ip_have_index && ! ip_blocks_after && ! ip_fm_after) { + if (ip_have_index && !ip_blocks_after && !ip_fm_after) { ltfsmsg(LTFS_INFO, 11256I); check_err(tape_seek_eod(vol->device, ip_num), 11216E, out_unlock); check_err(tape_write_filemark(vol->device, 1, true, true, false), 11218E, out_unlock); @@ -1065,11 +1045,10 @@ int ltfs_check_medium(bool fix, bool deep, bool recover_extra, bool recover_syml ++ip_eod; } - extra_blocks = - (dp_have_index && dp_blocks_after) || (! dp_have_index && dp_eod != 4) || - (ip_have_index && ip_blocks_after) || (! ip_have_index && ip_eod != 4); + extra_blocks = (dp_have_index && dp_blocks_after) || (!dp_have_index && dp_eod != 4) || + (ip_have_index && ip_blocks_after) || (!ip_have_index && ip_eod != 4); - if (! deep && extra_blocks) { + if (!deep && extra_blocks) { ltfsmsg(LTFS_ERR, 11220E); ret = -LTFS_INCONSISTENT; goto out_unlock; @@ -1078,7 +1057,7 @@ int ltfs_check_medium(bool fix, bool deep, bool recover_extra, bool recover_syml /* Verify sanity of back/self pointers and Decide which index file to use. */ check_err(_ltfs_check_pointers(ip_index, dp_index, vol), 11219E, out_unlock); - if (! dp_have_index && ! ip_have_index) { + if (!dp_have_index && !ip_have_index) { /* no index file on the tape. set up an empty index. */ ltfs_index_free(&dp_index); ltfs_index_free(&ip_index); @@ -1093,7 +1072,7 @@ int ltfs_check_medium(bool fix, bool deep, bool recover_extra, bool recover_syml ltfs_set_index_dirty(true, false, vol->index); ret = 0; - } else if (! ip_have_index || ! dp_have_index) { + } else if (!ip_have_index || !dp_have_index) { /* one partition is empty. check extent list for bad references. */ if (ip_have_index) ret = _ltfs_check_extents(ip_index->root, ip_eod, dp_eod, vol); @@ -1118,13 +1097,11 @@ int ltfs_check_medium(bool fix, bool deep, bool recover_extra, bool recover_syml } ret = 0; } - if (ret < 0) - goto out_unlock; + if (ret < 0) goto out_unlock; /* Set append position for index partition. */ - if (ip_have_index && ! ip_blocks_after) { - check_err(tape_set_append_position(vol->device, ip_num, ip_index->selfptr.block - 1), - 11222E, out_unlock); + if (ip_have_index && !ip_blocks_after) { + check_err(tape_set_append_position(vol->device, ip_num, ip_index->selfptr.block - 1), 11222E, out_unlock); } /* Recover extra blocks or schedule them to be erased. */ @@ -1143,14 +1120,12 @@ int ltfs_check_medium(bool fix, bool deep, bool recover_extra, bool recover_syml if (ip_have_index && ip_blocks_after) { if (lastblock_i >= ip_endofidx && lastblock_i < ip_eod) { ltfsmsg(LTFS_INFO, 11226I); - check_err(tape_set_append_position(vol->device, ip_num, lastblock_i), - 11229E, out_unlock); + check_err(tape_set_append_position(vol->device, ip_num, lastblock_i), 11229E, out_unlock); } else if (lastblock_i < ip_endofidx) { ltfsmsg(LTFS_INFO, 11226I); - check_err(tape_set_append_position(vol->device, ip_num, - ip_index->selfptr.block - 1), 11229E, out_unlock); + check_err(tape_set_append_position(vol->device, ip_num, ip_index->selfptr.block - 1), 11229E, out_unlock); } - } else if (! ip_have_index && ip_eod > 4) { + } else if (!ip_have_index && ip_eod > 4) { ltfsmsg(LTFS_INFO, 11226I); check_err(tape_set_append_position(vol->device, ip_num, 4), 11229E, out_unlock); } @@ -1159,7 +1134,7 @@ int ltfs_check_medium(bool fix, bool deep, bool recover_extra, bool recover_syml if (dp_have_index && dp_blocks_after) { ltfsmsg(LTFS_INFO, 11227I, (unsigned long long)dp_eod); check_err(tape_set_append_position(vol->device, dp_num, dp_eod), 11228E, out_unlock); - } else if (! dp_have_index && dp_eod > 4) { + } else if (!dp_have_index && dp_eod > 4) { ltfsmsg(LTFS_INFO, 11227I, (unsigned long long)dp_eod); check_err(tape_set_append_position(vol->device, dp_num, dp_eod), 11228E, out_unlock); } @@ -1168,10 +1143,8 @@ int ltfs_check_medium(bool fix, bool deep, bool recover_extra, bool recover_syml ltfs_set_index_dirty(true, false, vol->index); } - if (ip_have_index && ! ip_blocks_after) - vol->ip_index_file_end = true; - if (dp_have_index && ! dp_blocks_after) - vol->dp_index_file_end = true; + if (ip_have_index && !ip_blocks_after) vol->ip_index_file_end = true; + if (dp_have_index && !dp_blocks_after) vol->dp_index_file_end = true; /* If necessary, restore consistency by writing index files. */ if (vol->index->dirty) { @@ -1184,13 +1157,17 @@ int ltfs_check_medium(bool fix, bool deep, bool recover_extra, bool recover_syml _ltfs_last_ref(vol->index->root, &lastblock_d, &lastblock_i, vol); if (vol->device->append_pos[dp_num] != 0) { if (lastblock_d > vol->device->append_pos[dp_num]) { - ltfsmsg(LTFS_ERR, 11329E, (unsigned long long)lastblock_d, (unsigned long long)vol->device->append_pos[dp_num], dp_num); + ltfsmsg(LTFS_ERR, + 11329E, + (unsigned long long)lastblock_d, + (unsigned long long)vol->device->append_pos[dp_num], + dp_num); ret = -LTFS_INDEX_INVALID; goto out_unlock; } } /* write to data partition if it doesn't end in an index file */ - if (! dp_have_index || dp_blocks_after) { + if (!dp_have_index || dp_blocks_after) { ltfsmsg(LTFS_INFO, 17259I, "DP", vol->index->selfptr.partition, (unsigned long long)vol->index->selfptr.block); ret = ltfs_write_index(vol->label->partid_dp, SYNC_RECOVERY, vol); } @@ -1210,10 +1187,8 @@ int ltfs_check_medium(bool fix, bool deep, bool recover_extra, bool recover_syml } out_unlock: - if (ip_have_index && vol->index != ip_index) - ltfs_index_free(&ip_index); - if (dp_have_index && vol->index != dp_index) - ltfs_index_free(&dp_index); + if (ip_have_index && vol->index != ip_index) ltfs_index_free(&ip_index); + if (dp_have_index && vol->index != dp_index) ltfs_index_free(&dp_index); return ret; } @@ -1227,8 +1202,7 @@ int ltfs_update_cart_coherency(struct ltfs_volume *vol) tape_get_volume_change_reference(vol->device, ¤t_vcr); /* If the VCR is invalid, can't use MAM parameters */ - if (current_vcr == 0 || current_vcr == 0xffffffffffffffff) - return 0; + if (current_vcr == 0 || current_vcr == 0xffffffffffffffff) return 0; if (vol->ip_index_file_end) { if (vol->index->selfptr.partition == ltfs_ip_id(vol)) { @@ -1237,10 +1211,8 @@ int ltfs_update_cart_coherency(struct ltfs_volume *vol) } vol->ip_coh.version = 1; /* From PGA2 */ vol->ip_coh.volume_change_ref = current_vcr; - if (vol->ip_coh.uuid[0] == '\0') - arch_strcpy_auto(vol->ip_coh.uuid, vol->label->vol_uuid); - tape_set_cart_coherency(vol->device, ltfs_part_id2num(ltfs_ip_id(vol), vol), - &vol->ip_coh); + if (vol->ip_coh.uuid[0] == '\0') arch_strcpy_auto(vol->ip_coh.uuid, vol->label->vol_uuid); + tape_set_cart_coherency(vol->device, ltfs_part_id2num(ltfs_ip_id(vol), vol), &vol->ip_coh); } if (vol->dp_index_file_end) { @@ -1250,10 +1222,8 @@ int ltfs_update_cart_coherency(struct ltfs_volume *vol) } vol->dp_coh.version = 1; /* From PGA2 */ vol->dp_coh.volume_change_ref = current_vcr; - if (vol->dp_coh.uuid[0] == '\0') - arch_strcpy_auto(vol->dp_coh.uuid, vol->label->vol_uuid); - tape_set_cart_coherency(vol->device, ltfs_part_id2num(ltfs_dp_id(vol), vol), - &vol->dp_coh); + if (vol->dp_coh.uuid[0] == '\0') arch_strcpy_auto(vol->dp_coh.uuid, vol->label->vol_uuid); + tape_set_cart_coherency(vol->device, ltfs_part_id2num(ltfs_dp_id(vol), vol), &vol->dp_coh); } return 0; @@ -1274,11 +1244,10 @@ int ltfs_write_index_conditional(char partition, struct ltfs_volume *vol) CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); - if (partition == ltfs_ip_id(vol) && ! vol->ip_index_file_end) + if (partition == ltfs_ip_id(vol) && !vol->ip_index_file_end) ret = ltfs_write_index(partition, SYNC_CASCHE_PRESSURE, vol); else if (partition == ltfs_dp_id(vol) && - (! vol->dp_index_file_end || - (vol->ip_index_file_end && vol->index->selfptr.partition == ltfs_ip_id(vol)))) + (!vol->dp_index_file_end || (vol->ip_index_file_end && vol->index->selfptr.partition == ltfs_ip_id(vol)))) ret = ltfs_write_index(partition, SYNC_CASCHE_PRESSURE, vol); return ret; @@ -1288,103 +1257,95 @@ int ltfs_split_symlink(struct ltfs_volume *vol) { size_t i, size; struct dentry *d, *workd; - int ret=0; + int ret = 0; char *name, *lfdir, *path, *tok, *next_tok; - bool basedir=true, use_iosche=false; + bool basedir = true, use_iosche = false; char value[32]; ltfs_file_id id; - if ( iosched_initialized(vol) ) use_iosche=true; + if (iosched_initialized(vol)) use_iosche = true; /* check lost_and_found directory and make if it doesn't exist */ - int pathsize = asprintf( &lfdir, "/%s", LTFS_LOSTANDFOUND_DIR ); + int pathsize = asprintf(&lfdir, "/%s", LTFS_LOSTANDFOUND_DIR); ret = fs_path_lookup(lfdir, 0, &workd, vol->index); - if ( ret==-LTFS_NO_DENTRY ) { - ret = ltfs_fsops_create( lfdir, true, false, false, &workd, vol); - if ( ret<0 ) { + if (ret == -LTFS_NO_DENTRY) { + ret = ltfs_fsops_create(lfdir, true, false, false, &workd, vol); + if (ret < 0) { free(lfdir); return ret; } else { - basedir=false; + basedir = false; } - } else if ( ret<0 ) { + } else if (ret < 0) { free(lfdir); return ret; } - ret = ltfs_fsops_close( workd, true, true, use_iosche, vol); - path=arch_strdup(lfdir); + ret = ltfs_fsops_close(workd, true, true, use_iosche, vol); + path = arch_strdup(lfdir); /* loop for conflicted files */ - for( i=0; i<(vol->index->symerr_count); i++ ){ - d = *(vol->index->symlink_conflict+i); + for (i = 0; i < (vol->index->symerr_count); i++) { + d = *(vol->index->symlink_conflict + i); ret = fs_dentry_lookup(d, &name); - if (ret<0) goto out_func; + if (ret < 0) goto out_func; char *contextVal = NULL; - tok = arch_strtok( name+1, "/", contextVal); - next_tok = arch_strtok( NULL, "/" , contextVal); + tok = arch_strtok(name + 1, "/", contextVal); + next_tok = arch_strtok(NULL, "/", contextVal); /* check directory path and make if it doesn't exist */ - while( next_tok ){ - asprintf( &path, "%s/%s", path, tok ); - if ( basedir ) { + while (next_tok) { + asprintf(&path, "%s/%s", path, tok); + if (basedir) { ret = fs_path_lookup(path, 0, &workd, vol->index); - if ( ret==-LTFS_NO_DENTRY ) - basedir=false; - else if ( ret<0 ) + if (ret == -LTFS_NO_DENTRY) + basedir = false; + else if (ret < 0) goto err_out_func; } - if( !basedir ) { - ret = ltfs_fsops_create( path, true, false, false, &workd, vol); - if ( ret<0 ) - goto err_out_func; - + if (!basedir) { + ret = ltfs_fsops_create(path, true, false, false, &workd, vol); + if (ret < 0) goto err_out_func; } - ret = ltfs_fsops_close( workd, true, true, use_iosche, vol); + ret = ltfs_fsops_close(workd, true, true, use_iosche, vol); tok = next_tok; - next_tok = arch_strtok( NULL, "/", contextVal); + next_tok = arch_strtok(NULL, "/", contextVal); } /* Make filename with path in lost_and_found */ - asprintf( &path, "%s/%s", path, tok); + asprintf(&path, "%s/%s", path, tok); ret = fs_path_lookup(path, 0, &workd, vol->index); - if ( ret == 0 ) { + if (ret == 0) { /* delete same name old symlink */ - ret = ltfs_fsops_unlink( path, &id, vol); - if (ret<0) - goto err_out_func; - } else if ( ret != -LTFS_NO_DENTRY ) + ret = ltfs_fsops_unlink(path, &id, vol); + if (ret < 0) goto err_out_func; + } else if (ret != -LTFS_NO_DENTRY) goto err_out_func; - ret = ltfs_fsops_symlink_path( (const char*)d->target.name, (const char*)path, &id, vol ); - if (ret<0) - goto err_out_func; + ret = ltfs_fsops_symlink_path((const char *)d->target.name, (const char *)path, &id, vol); + if (ret < 0) goto err_out_func; /* get old file's EA info then store it in the new file*/ - memset( value, 0, sizeof(value)); + memset(value, 0, sizeof(value)); ret = xattr_get(d, LTFS_LIVELINK_EA_NAME, value, sizeof(value), vol); - if (ret>0) { + if (ret > 0) { size = ret; ret = fs_path_lookup(path, 0, &workd, vol->index); - if (ret<0) - goto err_out_func; - ret = xattr_set_mountpoint_length( workd, value, size ); - if (ret<0) - goto err_out_func; + if (ret < 0) goto err_out_func; + ret = xattr_set_mountpoint_length(workd, value, size); + if (ret < 0) goto err_out_func; ret = xattr_do_remove(d, LTFS_LIVELINK_EA_NAME, true, vol); - if (ret<0) - goto err_out_func; - ret = ltfs_fsops_close( workd, true, true, use_iosche, vol); - if (ret<0) - goto err_out_func; + if (ret < 0) goto err_out_func; + ret = ltfs_fsops_close(workd, true, true, use_iosche, vol); + if (ret < 0) goto err_out_func; } d->isslink = false; free(d->target.name); free(name); - arch_strcpy(path, pathsize,lfdir); - basedir=true; + arch_strcpy(path, pathsize, lfdir); + basedir = true; } goto out_func; diff --git a/src/libltfs/ltfs_locking_old.h b/src/libltfs/ltfs_locking_old.h index 3e785d60..babcdb8d 100644 --- a/src/libltfs/ltfs_locking_old.h +++ b/src/libltfs/ltfs_locking_old.h @@ -54,6 +54,7 @@ #ifndef __LTFS_LOCKING_OLD_H__ #define __LTFS_LOCKING_OLD_H__ +#include "ltfslogging.h" #ifdef __cplusplus extern "C" { diff --git a/src/libltfs/ltfs_thread.c b/src/libltfs/ltfs_thread.c index cd386780..e23bff72 100644 --- a/src/libltfs/ltfs_thread.c +++ b/src/libltfs/ltfs_thread.c @@ -49,8 +49,8 @@ #ifdef __APPLE__ -#include -#include +# include +# include uint32_t ltfs_get_thread_id(void) { @@ -63,8 +63,8 @@ uint32_t ltfs_get_thread_id(void) #elif defined(__FreeBSD__) -#include -#include +# include +# include uint32_t ltfs_get_thread_id(void) { @@ -77,7 +77,7 @@ uint32_t ltfs_get_thread_id(void) #elif defined(__NetBSD__) -#include +# include uint32_t ltfs_get_thread_id(void) { @@ -88,5 +88,4 @@ uint32_t ltfs_get_thread_id(void) return tid; } - #endif diff --git a/src/libltfs/ltfslogging.c b/src/libltfs/ltfslogging.c index 091e83ca..4c9949ef 100644 --- a/src/libltfs/ltfslogging.c +++ b/src/libltfs/ltfslogging.c @@ -46,75 +46,76 @@ */ #ifdef mingw_PLATFORM -#include "arch/win/win_util.h" -#include +# include "arch/win/win_util.h" +# include #endif -#include +#include #include +#include #include -#include #ifndef mingw_PLATFORM -#include +# include #endif #ifdef __APPLE_MAKEFILE__ -#include -#include -#include -#include -#include +# include +# include +# include +# include +# include #else -#include -#include -#include -#include -#include -#include +# include +# include +# include +# include +# include +# include #endif #ifdef mingw_PLATFORM -#include -#include -#include -#include -#include "arch/win/winlog.h" +# include "arch/win/winlog.h" +# include +# include +# include +# include #else -#include -#include +# include +# include #endif -#include "libltfs/ltfslogging.h" -#include "libltfs/ltfs_thread.h" -#include "libltfs/ltfs_locking.h" #include "libltfs/ltfs_error.h" -#include "queue.h" +#include "libltfs/ltfs_locking.h" +#include "libltfs/ltfs_thread.h" +#include "libltfs/ltfslogging.h" #include "ltfssnmp.h" +#include "queue.h" /* Some hard-coded message bits. */ -#define MSG_PREFIX_POSIX_TID "%016llx LTFS%s " -#define MSG_PREFIX_TID "%lx LTFS%s " -#define MSG_PREFIX "LTFS%s " -#define MSG_FALLBACK "(could not generate message)" +#define MSG_PREFIX_POSIX_TID "%016llx LTFS%s " +#define MSG_PREFIX_TID "%lx LTFS%s " +#define MSG_PREFIX "LTFS%s " +#define MSG_FALLBACK "(could not generate message)" -#define OUTPUT_BUF_SIZE 4096 /* Output buffer size, should be big enough to hold any message. */ +#define OUTPUT_BUF_SIZE 4096 /* Output buffer size, should be big enough to hold any message. */ -struct plugin_bundle { +struct plugin_bundle +{ TAILQ_ENTRY(plugin_bundle) list; - int32_t start_id; /**< First message ID allocated to this plugin */ - int32_t end_id; /**< Last message ID allocated to this plugin */ - UResourceBundle *bundle_root; /**< Root resource bundle for this plugin */ - UResourceBundle *bundle_messages; /**< Resource bundle containing this plugin's messages */ + int32_t start_id; /**< First message ID allocated to this plugin */ + int32_t end_id; /**< Last message ID allocated to this plugin */ + UResourceBundle *bundle_root; /**< Root resource bundle for this plugin */ + UResourceBundle *bundle_messages; /**< Resource bundle containing this plugin's messages */ }; /* Syslog levels corresponding to the LTFS logging levels defined in libltfs/ltfslogging.h. */ static int syslog_levels[] = { - LOG_ERR, /* LTFS_ERR */ - LOG_WARNING, /* LTFS_WARN */ - LOG_INFO, /* LTFS_INFO */ - LOG_DEBUG, /* LTFS_DEBUG */ - LOG_DEBUG, /* LTFS_DEBUG1 */ - LOG_DEBUG, /* LTFS_DEBUG2 */ - LOG_DEBUG, /* LTFS_DEBUG3 */ - LOG_DEBUG, /* LTFS_TRACE */ + LOG_ERR, /* LTFS_ERR */ + LOG_WARNING, /* LTFS_WARN */ + LOG_INFO, /* LTFS_INFO */ + LOG_DEBUG, /* LTFS_DEBUG */ + LOG_DEBUG, /* LTFS_DEBUG1 */ + LOG_DEBUG, /* LTFS_DEBUG2 */ + LOG_DEBUG, /* LTFS_DEBUG3 */ + LOG_DEBUG, /* LTFS_TRACE */ }; #ifdef mingw_PLATFORM @@ -122,9 +123,9 @@ char *libltfs_dat; char *internal_error_dat; char *tape_common_dat; #else -U_CFUNC char libltfs_dat[]; /* U_CFUNC is an ICU synonym for extern. */ +U_CFUNC char libltfs_dat[]; /* U_CFUNC is an ICU synonym for extern. */ U_CFUNC char internal_error_dat[]; /* U_CFUNC is an ICU synonym for extern. */ -U_CFUNC char tape_common_dat[]; /* U_CFUNC is an ICU synonym for extern. */ +U_CFUNC char tape_common_dat[]; /* U_CFUNC is an ICU synonym for extern. */ #endif static bool libltfs_dat_init = false; @@ -190,7 +191,7 @@ int ltfsprintf_init(int log_level, bool use_syslog, bool print_thread_id) } /* Load the libltfs message bundle and the primary message set */ - ret = ltfsprintf_load_plugin("internal_error", internal_error_dat, (void**)&pl); + ret = ltfsprintf_load_plugin("internal_error", internal_error_dat, (void **)&pl); if (ret < 0) { fprintf(stderr, "LTFS11293E Cannot load messages for internal error (%d)\n", ret); ltfsprintf_finish(); @@ -216,7 +217,6 @@ int ltfsprintf_init(int log_level, bool use_syslog, bool print_thread_id) /* Shut down the logging and error reporting framework. */ void ltfsprintf_finish() { - libltfs_dat_init = false; if (bundle_fallback) { @@ -224,7 +224,7 @@ void ltfsprintf_finish() bundle_fallback = NULL; } while (1) { - if (! TAILQ_EMPTY(&plugin_bundles)) + if (!TAILQ_EMPTY(&plugin_bundles)) ltfsprintf_unload_plugin(TAILQ_LAST(&plugin_bundles, message_struct)); else break; @@ -250,18 +250,15 @@ int ltfsprintf_set_log_level(int log_level) if (log_level < LTFS_ERR) { fprintf(stderr, "LTFS11318W Unknown log level (%d), forced the level to (%d)\n", log_level, LTFS_ERR); log_level = LTFS_ERR; - } - else if (log_level > LTFS_TRACE) { + } else if (log_level > LTFS_TRACE) { fprintf(stderr, "LTFS11318W Unknown log level (%d), forced the level to (%d)\n", log_level, LTFS_TRACE); log_level = LTFS_TRACE; - } - else { + } else { ltfs_log_level = log_level; } return 0; } - int ltfsprintf_load_plugin(const char *bundle_name, void *bundle_data, void **messages) { UErrorCode err = U_ZERO_ERROR; @@ -283,7 +280,7 @@ int ltfsprintf_load_plugin(const char *bundle_name, void *bundle_data, void **me #endif pl = calloc(1, sizeof(struct plugin_bundle)); - if (! pl) { + if (!pl) { if (libltfs_dat_init) ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); else @@ -318,7 +315,8 @@ int ltfsprintf_load_plugin(const char *bundle_name, void *bundle_data, void **me if (libltfs_dat_init) ltfsmsg(LTFS_ERR, 11282E, err); else - fprintf(stderr, "LTFS11282E Cannot load messages: failed to determine first message ID (ures_getByKey: %d)\n", err); + fprintf( + stderr, "LTFS11282E Cannot load messages: failed to determine first message ID (ures_getByKey: %d)\n", err); ures_close(pl->bundle_messages); ures_close(pl->bundle_root); free(pl); @@ -392,23 +390,22 @@ int ltfsmsg_internal(bool print_id, int level, char **msg_out, const char *_id, * hence we need to remove quotes first. */ idlen = strlen(_id); - if (idlen > sizeof(id) - 1) - goto internal_error; + if (idlen > sizeof(id) - 1) goto internal_error; if (idlen > 1 && _id[0] == '"' && _id[idlen - 1] == '"') { arch_strncpy_auto(id, _id + 1, idlen - 2); id[idlen - 2] = '\0'; - } - else { + } else { arch_strcpy_auto(id, _id); } id_val = atol(id); /* Check loaded plugins for the message, most recently loaded first */ - if (! TAILQ_EMPTY(&plugin_bundles)) { + if (!TAILQ_EMPTY(&plugin_bundles)) { ltfs_mutex_lock(&output_lock); - TAILQ_FOREACH(entry, &plugin_bundles, list) { + TAILQ_FOREACH(entry, &plugin_bundles, list) + { if (entry->start_id <= id_val && id_val <= entry->end_id) { err = U_ZERO_ERROR; format_uc = ures_getStringByKey(entry->bundle_messages, id, &format_len, &err); @@ -421,8 +418,7 @@ int ltfsmsg_internal(bool print_id, int level, char **msg_out, const char *_id, } else if (id[0] == 'I' || id[0] == 'D') { err = U_ZERO_ERROR; format_uc = ures_getStringByKey(entry->bundle_messages, id, &format_len, &err); - if (U_SUCCESS(err)) - break; + if (U_SUCCESS(err)) break; format_uc = NULL; } } @@ -431,10 +427,9 @@ int ltfsmsg_internal(bool print_id, int level, char **msg_out, const char *_id, } /* Try to get a fallback message if we didn't find the real message */ - if (! format_uc) { + if (!format_uc) { format_uc = ures_getStringByKey(bundle_fallback, "notfound", &format_len, &err); - if (U_FAILURE(err)) - goto internal_error; + if (U_FAILURE(err)) goto internal_error; } /* Format and print the message string. */ @@ -443,8 +438,7 @@ int ltfsmsg_internal(bool print_id, int level, char **msg_out, const char *_id, prefix_len = print_id ? arch_sprintf_auto(output_buf, MSG_PREFIX_TID, (unsigned long)ltfs_get_thread_id(), id) : 0; else prefix_len = print_id ? arch_sprintf_auto(output_buf, MSG_PREFIX, id) : 0; - ucnv_fromUChars(output_conv, output_buf + prefix_len, OUTPUT_BUF_SIZE - prefix_len - 1, - format_uc, format_len, &err); + ucnv_fromUChars(output_conv, output_buf + prefix_len, OUTPUT_BUF_SIZE - prefix_len - 1, format_uc, format_len, &err); if (err == U_BUFFER_OVERFLOW_ERROR) { err = U_ZERO_ERROR; format_uc = ures_getStringByKey(bundle_fallback, "overflow", &format_len, &err); @@ -453,22 +447,19 @@ int ltfsmsg_internal(bool print_id, int level, char **msg_out, const char *_id, goto internal_error; } - ucnv_fromUChars(output_conv, output_buf + prefix_len, OUTPUT_BUF_SIZE - prefix_len - 1, - format_uc, format_len, &err); + ucnv_fromUChars( + output_conv, output_buf + prefix_len, OUTPUT_BUF_SIZE - prefix_len - 1, format_uc, format_len, &err); if (U_FAILURE(err)) { ltfs_mutex_unlock(&output_lock); goto internal_error; } - } - else if (U_FAILURE(err)) { + } else if (U_FAILURE(err)) { ltfs_mutex_unlock(&output_lock); goto internal_error; } #ifdef mingw_PLATFORM - if (level <= ltfs_syslog_level - || level <= ltfs_log_level - || level == (LTFS_TRACE + 1)) // For "Help" messages + if (level <= ltfs_syslog_level || level <= ltfs_log_level || level == (LTFS_TRACE + 1)) // For "Help" messages { va_start(argp, _id); vsyslog2(level, output_buf, argp); @@ -508,7 +499,7 @@ int ltfsmsg_internal(bool print_id, int level, char **msg_out, const char *_id, arch_vsprintf(msg_buf, sizeof(msg_buf), output_buf, argp); va_end(argp); pos = strstr(msg_buf, " "); - send_ltfsInfoTrap(pos+1); + send_ltfsInfoTrap(pos + 1); } } #endif diff --git a/src/libltfs/ltfssnmp.c b/src/libltfs/ltfssnmp.c index d8677107..58bf82b2 100644 --- a/src/libltfs/ltfssnmp.c +++ b/src/libltfs/ltfssnmp.c @@ -46,8 +46,8 @@ ** ************************************************************************************* */ -#include #include +#include #include "ltfssnmp.h" @@ -55,15 +55,16 @@ #define TABLE_FILE_MODE "rb" #ifdef ENABLE_SNMP -#define DEFAULT_DEFFILE LTFS_BASE_DIR "/share/snmp/LtfsSnmpTrapDef.txt" +# define DEFAULT_DEFFILE LTFS_BASE_DIR "/share/snmp/LtfsSnmpTrapDef.txt" static const oid snmptrap_oid[] = { 1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0 }; #else -#define DEFAULT_DEFFILE LTFS_BASE_DIR "LtfsSnmpTrapDef.txt" +# define DEFAULT_DEFFILE LTFS_BASE_DIR "LtfsSnmpTrapDef.txt" #endif bool ltfs_snmp_enabled = false; -struct trap_entry { +struct trap_entry +{ TAILQ_ENTRY(trap_entry) list; char *id; }; @@ -78,19 +79,17 @@ int read_trap_def_file(char *deffile) { int ret = 0; char line[65536]; - char *trapfile=DEFAULT_DEFFILE; + char *trapfile = DEFAULT_DEFFILE; char *strip_pos, *tok, *saveptr; struct trap_entry *entry; FILE *fp = NULL; TAILQ_INIT(&trap_entries); - if (deffile != NULL) - trapfile = deffile; - + if (deffile != NULL) trapfile = deffile; arch_fopen(trapfile, TABLE_FILE_MODE, fp); - if (! fp) { + if (!fp) { ret = -errno; ltfsmsg(LTFS_ERR, 11268E, trapfile, ret); return ret; @@ -98,7 +97,7 @@ int read_trap_def_file(char *deffile) /* Parse the traf definition file */ if (!ret) { - while(fgets(line, 65536, fp) != NULL) { + while (fgets(line, 65536, fp) != NULL) { if (strlen(line) == 65535) { ltfsmsg(LTFS_ERR, 11269E); ret = -LTFS_CONFIG_INVALID; @@ -106,19 +105,17 @@ int read_trap_def_file(char *deffile) } /* Ignore comments and trailing whitespace */ strip_pos = strstr(line, "#"); - if (! strip_pos) - strip_pos = line + strlen(line); + if (!strip_pos) strip_pos = line + strlen(line); - while (strip_pos > line && - (*(strip_pos - 1) == ' ' || *(strip_pos - 1) == '\t' || - *(strip_pos - 1) == '\r' || *(strip_pos - 1) == '\n')) + while (strip_pos > line && (*(strip_pos - 1) == ' ' || *(strip_pos - 1) == '\t' || *(strip_pos - 1) == '\r' || + *(strip_pos - 1) == '\n')) --strip_pos; *strip_pos = '\0'; tok = strtok_r(line, " \t\r\n", &saveptr); if (tok) { - entry = (struct trap_entry *) calloc(1, sizeof(struct trap_entry)); - if (! entry) { + entry = (struct trap_entry *)calloc(1, sizeof(struct trap_entry)); + if (!entry) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } @@ -134,12 +131,11 @@ int read_trap_def_file(char *deffile) bool is_snmp_trapid(const char *id) { struct trap_entry *entry = NULL; - if (id == NULL) - return false; + if (id == NULL) return false; - TAILQ_FOREACH(entry, &trap_entries, list) { - if (! strcmp(entry->id, id)) - return true; + TAILQ_FOREACH(entry, &trap_entries, list) + { + if (!strcmp(entry->id, id)) return true; } return false; } @@ -160,7 +156,7 @@ int ltfs_snmp_finish() { struct trap_entry *entry = NULL; TAILQ_FOREACH(entry, &trap_entries, list) - free(entry->id); + free(entry->id); #ifdef ENABLE_SNMP send_ltfsStopTrap(); snmp_shutdown(AGENT); @@ -176,10 +172,11 @@ int send_ltfsStartTrap(void) /* Set the snmpTrapOid.0 value */ snmp_varlist_add_variable(&var_list, - snmptrap_oid, OID_LENGTH(snmptrap_oid), - ASN_OBJECT_ID, - (const u_char *)ltfsStartTrap_oid, - sizeof(ltfsStartTrap_oid)); + snmptrap_oid, + OID_LENGTH(snmptrap_oid), + ASN_OBJECT_ID, + (const u_char *)ltfsStartTrap_oid, + sizeof(ltfsStartTrap_oid)); /* Send the trap to the list of configured destinations and clean up */ send_v2trap(var_list); @@ -198,10 +195,11 @@ int send_ltfsStopTrap(void) /* Set the snmpTrapOid.0 value */ snmp_varlist_add_variable(&var_list, - snmptrap_oid, OID_LENGTH(snmptrap_oid), - ASN_OBJECT_ID, - (const u_char *)ltfsStopTrap_oid, - sizeof(ltfsStopTrap_oid)); + snmptrap_oid, + OID_LENGTH(snmptrap_oid), + ASN_OBJECT_ID, + (const u_char *)ltfsStopTrap_oid, + sizeof(ltfsStopTrap_oid)); /* Send the trap to the list of configured destinations and clean up */ send_v2trap(var_list); @@ -221,18 +219,15 @@ int send_ltfsInfoTrap(char *str) /* Set the snmpTrapOid.0 value */ snmp_varlist_add_variable(&var_list, - snmptrap_oid, OID_LENGTH(snmptrap_oid), - ASN_OBJECT_ID, - (const u_char *)ltfsInfoTrap_oid, - sizeof(ltfsInfoTrap_oid)); + snmptrap_oid, + OID_LENGTH(snmptrap_oid), + ASN_OBJECT_ID, + (const u_char *)ltfsInfoTrap_oid, + sizeof(ltfsInfoTrap_oid)); /* Add any objects from the trap definition */ - snmp_varlist_add_variable(&var_list, - ltfsTrapInfo_oid, - OID_LENGTH(ltfsTrapInfo_oid), - ASN_OCTET_STR, - (const u_char *)str, - strlen(str)); + snmp_varlist_add_variable( + &var_list, ltfsTrapInfo_oid, OID_LENGTH(ltfsTrapInfo_oid), ASN_OCTET_STR, (const u_char *)str, strlen(str)); /* Send the trap to the list of configured destinations and clean up */ send_v2trap(var_list); @@ -252,18 +247,15 @@ int send_ltfsErrorTrap(char *str) /* Set the snmpTrapOid.0 value */ snmp_varlist_add_variable(&var_list, - snmptrap_oid, OID_LENGTH(snmptrap_oid), - ASN_OBJECT_ID, - (const u_char *)ltfsErrorTrap_oid, - sizeof(ltfsErrorTrap_oid)); + snmptrap_oid, + OID_LENGTH(snmptrap_oid), + ASN_OBJECT_ID, + (const u_char *)ltfsErrorTrap_oid, + sizeof(ltfsErrorTrap_oid)); /* Add any objects from the trap definition */ - snmp_varlist_add_variable(&var_list, - ltfsTrapInfo_oid, - OID_LENGTH(ltfsTrapInfo_oid), - ASN_OCTET_STR, - (const u_char *)str, - strlen(str)); + snmp_varlist_add_variable( + &var_list, ltfsTrapInfo_oid, OID_LENGTH(ltfsTrapInfo_oid), ASN_OCTET_STR, (const u_char *)str, strlen(str)); /* Send the trap to the list of configured destinations and clean up */ send_v2trap(var_list); diff --git a/src/libltfs/ltfstrace.c b/src/libltfs/ltfstrace.c index 9bf3a1ed..1f2d3994 100644 --- a/src/libltfs/ltfstrace.c +++ b/src/libltfs/ltfstrace.c @@ -98,15 +98,16 @@ */ #define LTFS_TRACE_SIGNATURE "LTFS_TRC" #pragma pack(push, 1) -struct trace_header { - char signature[9]; /**< Signature for LTFS trace */ - uint32_t header_size; /**< Size of trace header */ - uint32_t req_header_offset; /**< Request trace header offset */ - uint32_t fn_header_offset; /**< Function trace header offset */ +struct trace_header +{ + char signature[9]; /**< Signature for LTFS trace */ + uint32_t header_size; /**< Size of trace header */ + uint32_t req_header_offset; /**< Request trace header offset */ + uint32_t fn_header_offset; /**< Function trace header offset */ unsigned short endian_signature; /**< Endian signagure : 0x1234 or 0x3412 */ - struct timer_info timerinfo; /**< Timer info to reconstruct time stamp in post process */ - uint32_t trace_size; /**< Whole size of trace (all headers and bodies) */ - uint32_t crc; /**< CRC (reserved for future use) */ + struct timer_info timerinfo; /**< Timer info to reconstruct time stamp in post process */ + uint32_t trace_size; /**< Whole size of trace (all headers and bodies) */ + uint32_t crc; /**< CRC (reserved for future use) */ }; #pragma pack(pop) @@ -114,14 +115,16 @@ struct trace_header { * Definitions for LTFS Request header information */ #pragma pack(push, 1) -struct request_header { - uint32_t header_size; /**< Size of request header */ - uint32_t num_of_req_trace; /**< Number of request trace descriptrs (always 1) */ - struct request_trace_descriptor { - uint32_t size_of_entry; /**< Size of entry */ - uint32_t num_of_entry; /**< Number of entry */ - } req_t_desc; /**< Request header descriptor */ - uint32_t crc; /**< CRC (reserved for future use) */ +struct request_header +{ + uint32_t header_size; /**< Size of request header */ + uint32_t num_of_req_trace; /**< Number of request trace descriptrs (always 1) */ + struct request_trace_descriptor + { + uint32_t size_of_entry; /**< Size of entry */ + uint32_t num_of_entry; /**< Number of entry */ + } req_t_desc; /**< Request header descriptor */ + uint32_t crc; /**< CRC (reserved for future use) */ }; #pragma pack(pop) @@ -129,15 +132,17 @@ struct request_header { * Definitions for LTFS function trace header */ #pragma pack(push, 1) -struct function_trace_header { - uint32_t header_size; /**< Size of function trace header */ - uint32_t num_of_fn_trace; /**< Number of function trace */ - struct function_trace_descriptor { - uint32_t type; /**< Function trace type (admin or filesystem) */ - uint32_t size_of_entry; /**< Size of function trace entry */ +struct function_trace_header +{ + uint32_t header_size; /**< Size of function trace header */ + uint32_t num_of_fn_trace; /**< Number of function trace */ + struct function_trace_descriptor + { + uint32_t type; /**< Function trace type (admin or filesystem) */ + uint32_t size_of_entry; /**< Size of function trace entry */ uint32_t num_of_entry; /**< Number of function trace entries */ } *req_t_desc; - uint32_t crc; /**< CRC (reserved for future use) */ + uint32_t crc; /**< CRC (reserved for future use) */ }; #pragma pack(pop) @@ -145,7 +150,8 @@ struct function_trace_header { * Definitions for LTFS function trace data */ #pragma pack(push, 1) -struct function_entry { +struct function_entry +{ uint64_t time; uint64_t function; uint64_t info1; @@ -158,69 +164,74 @@ struct function_entry { /* * "Filesystem" Function Trace Data structure */ -#define FS_FN_TRACE_SIZE (1 * 1024 * 1024) /* 1MB */ -#define FS_FN_TRACE_ENTRIES (FS_FN_TRACE_SIZE / FN_TRACE_ENTRY_SIZE) - -struct filesystem_function_trace { - MultiReaderSingleWriter trace_lock; /**< Lock for trace data */ - uint32_t max_index; - uint32_t cur_index; - struct function_entry entries[FS_FN_TRACE_ENTRIES]; +#define FS_FN_TRACE_SIZE (1 * 1024 * 1024) /* 1MB */ +#define FS_FN_TRACE_ENTRIES (FS_FN_TRACE_SIZE / FN_TRACE_ENTRY_SIZE) + +struct filesystem_function_trace +{ + MultiReaderSingleWriter trace_lock; /**< Lock for trace data */ + uint32_t max_index; + uint32_t cur_index; + struct function_entry entries[FS_FN_TRACE_ENTRIES]; }; -struct filesystem_trace_list { - uint32_t tid; +struct filesystem_trace_list +{ + uint32_t tid; struct filesystem_function_trace *fn_entry; - UT_hash_handle hh; + UT_hash_handle hh; }; /* * "Admin" Function Trace Data structure */ -#define ADMIN_FN_TRACE_ENTRIES 256 -#define ADMIN_FN_TRACE_SIZE (ADMIN_FN_TRACE_ENTRIES * FN_TRACE_ENTRY_SIZE) -struct admin_function_trace { - MultiReaderSingleWriter trace_lock; /**< Lock for trace data */ - uint32_t max_index; - uint32_t cur_index; - struct function_entry entries[ADMIN_FN_TRACE_ENTRIES]; +#define ADMIN_FN_TRACE_ENTRIES 256 +#define ADMIN_FN_TRACE_SIZE (ADMIN_FN_TRACE_ENTRIES * FN_TRACE_ENTRY_SIZE) +struct admin_function_trace +{ + MultiReaderSingleWriter trace_lock; /**< Lock for trace data */ + uint32_t max_index; + uint32_t cur_index; + struct function_entry entries[ADMIN_FN_TRACE_ENTRIES]; }; -struct admin_trace_list { - uint32_t tid; - struct admin_function_trace *fn_entry; - UT_hash_handle hh; +struct admin_trace_list +{ + uint32_t tid; + struct admin_function_trace *fn_entry; + UT_hash_handle hh; }; /* * Definitions for Tail Q of Admin function trace */ #define MAX_ADMIN_COMP_NUM 512 -struct admin_completed_function_trace { +struct admin_completed_function_trace +{ TAILQ_ENTRY(admin_completed_function_trace) list; - uint32_t tid; - struct admin_function_trace *fn_entry; - MultiReaderSingleWriter trace_lock; + uint32_t tid; + struct admin_function_trace *fn_entry; + MultiReaderSingleWriter trace_lock; }; /* * Definitions for LTFS Profiler */ -struct trace_header *trc_header = NULL; -struct request_header *req_header = NULL; -struct function_trace_header *fn_trc_header = NULL; +struct trace_header *trc_header = NULL; +struct request_header *req_header = NULL; +struct function_trace_header *fn_trc_header = NULL; -struct request_trace *req_trace = NULL; -struct filesystem_trace_list *fs_tr_list = NULL; -struct admin_trace_list *admin_tr_list = NULL; +struct request_trace *req_trace = NULL; +struct filesystem_trace_list *fs_tr_list = NULL; +struct admin_trace_list *admin_tr_list = NULL; TAILQ_HEAD(admin_completed, admin_completed_function_trace); -struct admin_completed *acomp = NULL; +struct admin_completed *acomp = NULL; -_time_stamp_t start_offset; -struct ltfs_timespec start; -struct timer_info timerinfo; -bool trace_enable = true; +_time_stamp_t start_offset; +struct ltfs_timespec start; +struct timer_info timerinfo; +bool trace_enable = true; static int ltfs_request_trace_init(void) { @@ -263,27 +274,26 @@ static void ltfs_request_trace_destroy(void) static int ltfs_fn_trace_init(void) { - acomp = (struct admin_completed *) calloc (1, sizeof(struct admin_completed)); + acomp = (struct admin_completed *)calloc(1, sizeof(struct admin_completed)); TAILQ_INIT(acomp); return 0; } int ltfs_fn_trace_start(FUNCTION_TRACE_TYPE type, uint32_t tid) { - if (trace_enable == false) - return 0; + if (trace_enable == false) return 0; if (type == FILESYSTEM) { struct filesystem_trace_list *item = NULL; struct filesystem_function_trace *tr_data = NULL; - item = (struct filesystem_trace_list *) calloc(1, sizeof(struct filesystem_trace_list)); + item = (struct filesystem_trace_list *)calloc(1, sizeof(struct filesystem_trace_list)); if (!item) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } item->tid = tid; - tr_data = (struct filesystem_function_trace *) calloc(1, sizeof(struct filesystem_function_trace)); + tr_data = (struct filesystem_function_trace *)calloc(1, sizeof(struct filesystem_function_trace)); if (!tr_data) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; @@ -296,14 +306,14 @@ int ltfs_fn_trace_start(FUNCTION_TRACE_TYPE type, uint32_t tid) } else if (type == ADMIN) { struct admin_trace_list *item = NULL; struct admin_function_trace *tr_data = NULL; - item = (struct admin_trace_list *) calloc(1, sizeof(struct admin_trace_list)); + item = (struct admin_trace_list *)calloc(1, sizeof(struct admin_trace_list)); if (!item) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } item->tid = tid; - tr_data = (struct admin_function_trace *) calloc(1, sizeof(struct admin_function_trace)); + tr_data = (struct admin_function_trace *)calloc(1, sizeof(struct admin_function_trace)); if (!tr_data) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; @@ -322,13 +332,12 @@ void ltfs_admin_function_trace_completed(uint32_t tid) struct admin_completed_function_trace *tailq_item; uint32_t num_of_comp_adm = 0; - if (trace_enable == false) - return; + if (trace_enable == false) return; HASH_FIND_INT(admin_tr_list, &tid, item); if (item != NULL) { - TAILQ_FOREACH (tailq_item, acomp, list) - num_of_comp_adm++; + TAILQ_FOREACH(tailq_item, acomp, list) + num_of_comp_adm++; if (num_of_comp_adm > MAX_ADMIN_COMP_NUM) { /* Remove first tailq entry */ @@ -337,13 +346,13 @@ void ltfs_admin_function_trace_completed(uint32_t tid) free(tailq_item->fn_entry); free(tailq_item); } - tailq_item = (struct admin_completed_function_trace *) calloc(1, sizeof(struct admin_completed_function_trace)); + tailq_item = (struct admin_completed_function_trace *)calloc(1, sizeof(struct admin_completed_function_trace)); acquirewrite_mrsw(&tailq_item->trace_lock); struct admin_function_trace *ptr = NULL; - ptr = (struct admin_function_trace *) calloc(1, sizeof(struct admin_function_trace)); + ptr = (struct admin_function_trace *)calloc(1, sizeof(struct admin_function_trace)); ptr->cur_index = item->fn_entry->cur_index; - for (unsigned int j=0; jcur_index; j++) { + for (unsigned int j = 0; j < ptr->cur_index; j++) { ptr->entries[j].time = item->fn_entry->entries[j].time; ptr->entries[j].function = item->fn_entry->entries[j].function; ptr->entries[j].info1 = item->fn_entry->entries[j].info1; @@ -364,7 +373,8 @@ static void ltfs_function_trace_destroy(void) { if (fs_tr_list) { struct filesystem_trace_list *fsitem, *tmp; - HASH_ITER(hh, fs_tr_list, fsitem, tmp) { + HASH_ITER(hh, fs_tr_list, fsitem, tmp) + { destroy_mrsw(&fsitem->fn_entry->trace_lock); free(fsitem->fn_entry); free(fsitem); @@ -373,7 +383,8 @@ static void ltfs_function_trace_destroy(void) } if (admin_tr_list) { struct admin_trace_list *aditem, *tmp; - HASH_ITER(hh, admin_tr_list, aditem, tmp) { + HASH_ITER(hh, admin_tr_list, aditem, tmp) + { destroy_mrsw(&aditem->fn_entry->trace_lock); free(aditem->fn_entry); free(aditem); @@ -382,7 +393,8 @@ static void ltfs_function_trace_destroy(void) } if (acomp) { struct admin_completed_function_trace *tailq_item, *tmp; - TAILQ_FOREACH_SAFE(tailq_item, acomp, list, tmp) { + TAILQ_FOREACH_SAFE(tailq_item, acomp, list, tmp) + { destroy_mrsw(&tailq_item->trace_lock); free(tailq_item->fn_entry); free(tailq_item); @@ -398,8 +410,7 @@ void ltfs_function_trace(uint64_t func, uint64_t info1, uint64_t info2) uint32_t tid; uint64_t time; - if (trace_enable == false) - return; + if (trace_enable == false) return; time = get_time_stamp(&start_offset); tid = ltfs_get_thread_id(); @@ -442,11 +453,9 @@ int ltfs_request_profiler_start(const char *work_dir) int ret; char *path; - if (req_trace->profiler) - return 0; + if (req_trace->profiler) return 0; - if(!work_dir) - return -LTFS_BAD_ARG; + if (!work_dir) return -LTFS_BAD_ARG; ret = asprintf(&path, "%s/%s", work_dir, REQ_PROFILER_FILE); if (ret < 0) { @@ -458,10 +467,10 @@ int ltfs_request_profiler_start(const char *work_dir) free(path); - if (! req_trace->profiler) + if (!req_trace->profiler) ret = -LTFS_FILE_ERR; else { - fwrite((void*)&timerinfo, sizeof(timerinfo), 1, req_trace->profiler); + fwrite((void *)&timerinfo, sizeof(timerinfo), 1, req_trace->profiler); ret = 0; } @@ -519,8 +528,7 @@ int ltfs_trace_init(void) { int ret = 0; - if (trace_enable == false) - return ret; + if (trace_enable == false) return ret; /* Store launch time */ get_current_timespec(&start); @@ -541,7 +549,7 @@ int ltfs_trace_init(void) return ret; } -int ltfs_trace_get_offset(char** val) +int ltfs_trace_get_offset(char **val) { #ifdef __APPLE__ return asprintf(val, "%llu", start_offset); @@ -561,10 +569,10 @@ void ltfs_trace_destroy(void) ltfs_function_trace_destroy(); free(trc_header); - trc_header = NULL; + trc_header = NULL; free(req_header); - req_header = NULL; + req_header = NULL; free(fn_trc_header); fn_trc_header = NULL; @@ -579,8 +587,7 @@ int ltfs_dump(char *fname, const char *work_dir) const unsigned int max_arguments = 32; const char *args[max_arguments]; - if(!work_dir) - return -LTFS_BAD_ARG; + if (!work_dir) return -LTFS_BAD_ARG; ret = asprintf(&path, "%s/%s", work_dir, fname); if (ret < 0) { @@ -597,14 +604,14 @@ int ltfs_dump(char *fname, const char *work_dir) fork_pid = fork(); if (fork_pid < 0) { ltfsmsg(LTFS_ERR, 17233E); - } else if (fork_pid == 0) { + } else if (fork_pid == 0) { args[num_args++] = "/usr/bin/gcore"; args[num_args++] = "-o"; args[num_args++] = path; args[num_args++] = pid; args[num_args++] = NULL; - execv(args[0], (char **) args); + execv(args[0], (char **)args); exit(errno); } else { waitpid(fork_pid, &status, 0); @@ -619,11 +626,9 @@ int ltfs_trace_dump(char *fname, const char *work_dir) int ret = 0, fd; char *path; - if(trace_enable == false) - return 0; + if (trace_enable == false) return 0; - if(!work_dir) - return -LTFS_BAD_ARG; + if (!work_dir) return -LTFS_BAD_ARG; ret = asprintf(&path, "%s/%s", work_dir, fname); if (ret < 0) { @@ -632,14 +637,12 @@ int ltfs_trace_dump(char *fname, const char *work_dir) } /* Open file */ - arch_open(&fd, path,O_WRONLY | O_CREAT | O_TRUNC, SHARE_FLAG_DENYRW, PERMISSION_READWRITE); - if(fd < 0) - return -errno; + arch_open(&fd, path, O_WRONLY | O_CREAT | O_TRUNC, SHARE_FLAG_DENYRW, PERMISSION_READWRITE); + if (fd < 0) return -errno; free(path); - if (req_trace) - { + if (req_trace) { uint32_t num_of_fn_trace = 0, num_of_fs_fn_trace = 0, num_of_adm_fn_trace = 0, n = 0; struct admin_completed_function_trace *tailq_item; struct filesystem_trace_list *fsitem; @@ -648,35 +651,36 @@ int ltfs_trace_dump(char *fname, const char *work_dir) /* Calculate the number of function traces */ num_of_fs_fn_trace += HASH_COUNT(fs_tr_list); num_of_adm_fn_trace += HASH_COUNT(admin_tr_list); - TAILQ_FOREACH (tailq_item, acomp, list) - num_of_adm_fn_trace++; + TAILQ_FOREACH(tailq_item, acomp, list) + num_of_adm_fn_trace++; num_of_fn_trace = num_of_fs_fn_trace + num_of_adm_fn_trace; fn_trc_header->num_of_fn_trace = num_of_fn_trace; fn_trc_header->header_size = 8 + 12 * num_of_fn_trace; fn_trc_header->req_t_desc = - (struct function_trace_descriptor *) calloc(num_of_fn_trace, sizeof(struct function_trace_descriptor)); + (struct function_trace_descriptor *)calloc(num_of_fn_trace, sizeof(struct function_trace_descriptor)); if (!fn_trc_header->req_t_desc) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } - for (fsitem=fs_tr_list; fsitem != NULL; fsitem=fsitem->hh.next) { + for (fsitem = fs_tr_list; fsitem != NULL; fsitem = fsitem->hh.next) { fn_trc_header->req_t_desc[n].type = FILESYSTEM; fn_trc_header->req_t_desc[n].size_of_entry = FS_FN_TRACE_SIZE; acquireread_mrsw(&fsitem->fn_entry->trace_lock); fn_trc_header->req_t_desc[n++].num_of_entry = fsitem->fn_entry->cur_index; releaseread_mrsw(&fsitem->fn_entry->trace_lock); } - for (admitem=admin_tr_list; admitem != NULL; admitem=admitem->hh.next) { + for (admitem = admin_tr_list; admitem != NULL; admitem = admitem->hh.next) { fn_trc_header->req_t_desc[n].type = ADMIN; fn_trc_header->req_t_desc[n].size_of_entry = ADMIN_FN_TRACE_SIZE; acquireread_mrsw(&admitem->fn_entry->trace_lock); fn_trc_header->req_t_desc[n++].num_of_entry = admitem->fn_entry->cur_index; releaseread_mrsw(&admitem->fn_entry->trace_lock); } - TAILQ_FOREACH (tailq_item, acomp, list) { + TAILQ_FOREACH(tailq_item, acomp, list) + { fn_trc_header->req_t_desc[n].type = ADMIN_COMPLETED; fn_trc_header->req_t_desc[n].size_of_entry = ADMIN_FN_TRACE_SIZE; acquireread_mrsw(&tailq_item->fn_entry->trace_lock); @@ -687,11 +691,10 @@ int ltfs_trace_dump(char *fname, const char *work_dir) /* Set header information */ req_header->req_t_desc.num_of_entry = req_trace->cur_index; req_header->req_t_desc.size_of_entry = REQ_TRACE_SIZE; - trc_header->trace_size = - req_header->req_t_desc.size_of_entry + /* Request trace */ - (num_of_fs_fn_trace * FS_FN_TRACE_SIZE) + /* Function trace (filesystem) */ - (num_of_adm_fn_trace * ADMIN_FN_TRACE_SIZE) + /* Function trace (admin) */ - trc_header->header_size + req_header->header_size + fn_trc_header->header_size; + trc_header->trace_size = req_header->req_t_desc.size_of_entry + /* Request trace */ + (num_of_fs_fn_trace * FS_FN_TRACE_SIZE) + /* Function trace (filesystem) */ + (num_of_adm_fn_trace * ADMIN_FN_TRACE_SIZE) + /* Function trace (admin) */ + trc_header->header_size + req_header->header_size + fn_trc_header->header_size; /* Write headers */ (void)arch_write(fd, trc_header, sizeof(struct trace_header)); @@ -705,24 +708,25 @@ int ltfs_trace_dump(char *fname, const char *work_dir) /* Write function trace header */ (void)arch_write(fd, &fn_trc_header->header_size, sizeof(uint32_t)); (void)arch_write(fd, &fn_trc_header->num_of_fn_trace, sizeof(uint32_t)); - for (unsigned int i=0; ireq_t_desc[i], sizeof(struct function_trace_descriptor)); (void)arch_write(fd, &fn_trc_header->crc, sizeof(uint32_t)); free(fn_trc_header->req_t_desc); fn_trc_header->req_t_desc = NULL; /* Write function trace data */ - for (fsitem=fs_tr_list; fsitem != NULL; fsitem=fsitem->hh.next) { + for (fsitem = fs_tr_list; fsitem != NULL; fsitem = fsitem->hh.next) { acquireread_mrsw(&fsitem->fn_entry->trace_lock); (void)arch_write(fd, fsitem->fn_entry->entries, FS_FN_TRACE_SIZE); releaseread_mrsw(&fsitem->fn_entry->trace_lock); } - for (admitem=admin_tr_list; admitem != NULL; admitem=admitem->hh.next) { + for (admitem = admin_tr_list; admitem != NULL; admitem = admitem->hh.next) { acquireread_mrsw(&admitem->fn_entry->trace_lock); (void)arch_write(fd, admitem->fn_entry->entries, ADMIN_FN_TRACE_SIZE); releaseread_mrsw(&admitem->fn_entry->trace_lock); } - TAILQ_FOREACH (tailq_item, acomp, list) { + TAILQ_FOREACH(tailq_item, acomp, list) + { acquireread_mrsw(&tailq_item->fn_entry->trace_lock); (void)arch_write(fd, tailq_item->fn_entry->entries, ADMIN_FN_TRACE_SIZE); releaseread_mrsw(&tailq_item->fn_entry->trace_lock); @@ -738,13 +742,13 @@ int ltfs_get_trace_status(char **val) int ret = 0; char *trstat = NULL; - ret = asprintf(&trstat, "%s", (trace_enable == true) ? "on" : "off" ); + ret = asprintf(&trstat, "%s", (trace_enable == true) ? "on" : "off"); if (ret < 0) { ltfsmsg(LTFS_ERR, 10001E, __FILE__); return -LTFS_NO_MEMORY; } *val = arch_strdup(trstat); - if (! (*val)) { + if (!(*val)) { ltfsmsg(LTFS_ERR, 10001E, __FILE__); return -LTFS_NO_MEMORY; } @@ -756,12 +760,11 @@ int ltfs_set_trace_status(char *mode) { int ret = 0; - if (! strcmp(mode, "on")) { + if (!strcmp(mode, "on")) { trace_enable = true; ltfs_trace_init(); } else { - if (trace_enable == true) - ltfs_trace_destroy(); + if (trace_enable == true) ltfs_trace_destroy(); trace_enable = false; } return ret; diff --git a/src/libltfs/pathname.c b/src/libltfs/pathname.c index 19abc321..f2c538d3 100644 --- a/src/libltfs/pathname.c +++ b/src/libltfs/pathname.c @@ -47,36 +47,36 @@ ************************************************************************************* */ +#include +#include #include #include -#include -#include #ifdef __APPLE_MAKEFILE__ -#include -#include -#include -#include -#ifdef ICU6x -#include +# include +# include +# include +# include +# ifdef ICU6x +# include +# else +# include +# endif #else -#include -#endif -#else -#include -#include -#include -#include -#ifdef ICU6x -#include -#else -#include -#endif +# include +# include +# include +# include +# ifdef ICU6x +# include +# else +# include +# endif #endif +#include "libltfs/ltfslogging.h" #include "ltfs.h" #include "pathname.h" -#include "libltfs/ltfslogging.h" int _pathname_is_utf8(const char *name, size_t size); int _pathname_validate(const char *name, bool allow_slash); @@ -95,7 +95,6 @@ int _pathname_system_to_utf16_icu(const char *src, UChar **dest); int _pathname_utf8_to_system_icu(const char *src, char **dest); int _pathname_normalize_utf8_nfd_icu(const char *src, char **dest); - /** * Convert a path name in the system locale to the canonical LTFS form (UTF-8, NFC). * @param name file, directory, or xattr name to format @@ -149,8 +148,8 @@ int pathname_caseless_match(const char *name1, const char *name2, int *result) CHECK_ARG_NULL(name1, -LTFS_NULL_ARG); CHECK_ARG_NULL(name2, -LTFS_NULL_ARG); - if (! (ret=pathname_prepare_caseless(name1, &dname1, true))) { - if (! (ret=pathname_prepare_caseless(name2, &dname2, true))) { + if (!(ret = pathname_prepare_caseless(name1, &dname1, true))) { + if (!(ret = pathname_prepare_caseless(name2, &dname2, true))) { *result = u_strcmp(dname1, dname2); free(dname2); } @@ -178,8 +177,7 @@ int pathname_prepare_caseless(const char *name, UChar **new_name, bool use_nfc) /* Convert to ICU's internal UTF-16 representation. */ ret = _pathname_utf8_to_utf16_icu(name, &icu_name); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* Figure out whether an initial NFD mapping is needed. This is the case if the string * contains U+0345 or a code point whose canonical decomposition contains U+0345. @@ -197,19 +195,15 @@ int pathname_prepare_caseless(const char *name, UChar **new_name, bool use_nfc) /* Convert to NFD if needed, then case fold the name. */ if (need_initial_nfd) { ret = _pathname_normalize_nfd_icu(icu_name, &icu_nfd); - if (icu_name != icu_nfd) - free(icu_name); - if (ret < 0) - return ret; + if (icu_name != icu_nfd) free(icu_name); + if (ret < 0) return ret; ret = _pathname_foldcase_icu(icu_nfd, &icu_fold); free(icu_nfd); - if (ret < 0) - return ret; + if (ret < 0) return ret; } else { ret = _pathname_foldcase_icu(icu_name, &icu_fold); free(icu_name); - if (ret < 0) - return ret; + if (ret < 0) return ret; } /* Perform the final normalization mapping to the output. */ @@ -217,10 +211,8 @@ int pathname_prepare_caseless(const char *name, UChar **new_name, bool use_nfc) ret = _pathname_normalize_nfc_icu(icu_fold, new_name); else ret = _pathname_normalize_nfd_icu(icu_fold, new_name); - if (icu_fold != *new_name) - free(icu_fold); - if (ret < 0) - return ret; + if (icu_fold != *new_name) free(icu_fold); + if (ret < 0) return ret; return 0; } @@ -254,8 +246,7 @@ int pathname_validate_file(const char *name) CHECK_ARG_NULL(name, -LTFS_NULL_ARG); namelen = pathname_strlen(name); - if (namelen < 0) - return namelen; + if (namelen < 0) return namelen; if (namelen > LTFS_FILENAME_MAX) { return -LTFS_NAMETOOLONG; } @@ -275,8 +266,7 @@ int pathname_validate_target(const char *name) CHECK_ARG_NULL(name, -LTFS_NULL_ARG); namelen = pathname_strlen(name); - if (namelen < 0) - return namelen; + if (namelen < 0) return namelen; ret = _pathname_validate(name, true); return ret; } @@ -316,22 +306,19 @@ int pathname_validate_xattr_value(const char *name, size_t size) return 1; /* Check for characters disallowed in XML. */ - while (i < (ssize_t) size) { - U8_NEXT(name, i, (int32_t) size, c); + while (i < (ssize_t)size) { + U8_NEXT(name, i, (int32_t)size, c); if (c < 0) { ltfsmsg(LTFS_ERR, 11234E); return -LTFS_ICU_ERROR; } - if (_chars_valid_in_xml(c) == 0) - return 1; + if (_chars_valid_in_xml(c) == 0) return 1; } return 0; } - - /* Private pathname functions are not traced. This is because (a) tracing their inner workings * is not expected to be interesting, and (b) tracing them produces large amounts of output, * obscuring more interesting traces. @@ -340,8 +327,6 @@ int pathname_validate_xattr_value(const char *name, size_t size) * the private functions is unlikely to yield any useful debugging information. */ - - /** * Count the code points in a null-terminated UTF-8 string. * Note: this function assumes the input string is well-formed UTF-8! @@ -355,8 +340,7 @@ int pathname_strlen(const char *name) CHECK_ARG_NULL(name, -LTFS_NULL_ARG); while (*tmp) { - if (! (*tmp & 0x80) || (*tmp & 0xC0) == 0xC0) - ++ret; + if (!(*tmp & 0x80) || (*tmp & 0xC0) == 0xC0) ++ret; ++tmp; } return ret; @@ -376,7 +360,7 @@ int pathname_truncate(char *name, size_t size) CHECK_ARG_NULL(name, -LTFS_NULL_ARG); while (*tmp) { - if (! (*tmp & 0x80) || (*tmp & 0xC0) == 0xC0) { + if (!(*tmp & 0x80) || (*tmp & 0xC0) == 0xC0) { if (len++ == size) { *tmp = '\0'; break; @@ -425,8 +409,7 @@ int _pathname_validate(const char *name, bool allow_slash) return -LTFS_ICU_ERROR; } - if (_pathname_valid_in_xml(c) == 0 || (! allow_slash && c == '/')) - return -LTFS_INVALID_PATH; + if (_pathname_valid_in_xml(c) == 0 || (!allow_slash && c == '/')) return -LTFS_INVALID_PATH; } return 0; @@ -447,8 +430,8 @@ int _pathname_valid_in_xml(UChar32 c) int _chars_valid_in_xml(UChar32 c) { - if ((c >= 0 && c <= 0x1f && c != 0x09 && c != 0x0a && c != 0x0d) || - (c >= 0xd800 && c <= 0xdfff) || c == 0xfffe || c == 0xffff) + if ((c >= 0 && c <= 0x1f && c != 0x09 && c != 0x0a && c != 0x0d) || (c >= 0xd800 && c <= 0xdfff) || c == 0xfffe || + c == 0xffff) return 0; else return 1; @@ -470,25 +453,21 @@ int _pathname_format_icu(const char *src, char **dest, bool validate, bool allow /* convert to UTF-16 for normalization with ICU */ ret = _pathname_system_to_utf16_icu(src, &utf16_name); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* normalize */ ret = _pathname_normalize_nfc_icu(utf16_name, &utf16_name_norm); - if (utf16_name != utf16_name_norm) - free(utf16_name); - if (ret < 0) - return ret; + if (utf16_name != utf16_name_norm) free(utf16_name); + if (ret < 0) return ret; /* convert to UTF-8 */ ret = _pathname_utf16_to_utf8_icu(utf16_name_norm, dest); free(utf16_name_norm); - if (ret < 0) - return ret; + if (ret < 0) return ret; if (validate) { /* check length of the name unless it's supposed to be a path */ - if (! allow_slash) { + if (!allow_slash) { ret = pathname_strlen(*dest); if (ret < 0) { free(*dest); @@ -530,14 +509,11 @@ int _pathname_normalize_utf8_nfd_icu(const char *src, char **dest) int ret; ret = _pathname_utf8_to_utf16_icu(src, &icu_str); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = _pathname_normalize_nfd_icu(icu_str, &icu_str_norm); - if (icu_str != icu_str_norm) - free(icu_str); - if (ret < 0) - return ret; + if (icu_str != icu_str_norm) free(icu_str); + if (ret < 0) return ret; ret = _pathname_utf16_to_utf8_icu(icu_str_norm, dest); free(icu_str_norm); @@ -555,8 +531,7 @@ int _pathname_check_utf8_icu(const char *src, size_t size) UErrorCode err = U_ZERO_ERROR; u_strFromUTF8(NULL, 0, NULL, src, (int32_t)size, &err); - if (U_FAILURE(err) && err != U_BUFFER_OVERFLOW_ERROR) - return 1; + if (U_FAILURE(err) && err != U_BUFFER_OVERFLOW_ERROR) return 1; return 0; } @@ -573,13 +548,11 @@ int _pathname_foldcase_utf8_icu(const char *src, char **dest) int ret; ret = _pathname_utf8_to_utf16_icu(src, &icu_str); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = _pathname_foldcase_icu(icu_str, &icu_str_fold); free(icu_str); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = _pathname_utf16_to_utf8_icu(icu_str_fold, dest); free(icu_str_fold); @@ -598,14 +571,11 @@ int _pathname_normalize_utf8_icu(const char *src, char **dest) int ret; ret = _pathname_utf8_to_utf16_icu(src, &icu_str); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = _pathname_normalize_nfc_icu(icu_str, &icu_str_norm); - if (icu_str != icu_str_norm) - free(icu_str); - if (ret < 0) - return ret; + if (icu_str != icu_str_norm) free(icu_str); + if (ret < 0) return ret; ret = _pathname_utf16_to_utf8_icu(icu_str_norm, dest); free(icu_str_norm); @@ -632,7 +602,7 @@ int _pathname_foldcase_icu(const UChar *src, UChar **dest) err = U_ZERO_ERROR; *dest = malloc((destlen + 1) * sizeof(UChar)); - if (! *dest) { + if (!*dest) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } @@ -657,9 +627,9 @@ static inline void *_unorm_handle(bool nfc, UErrorCode *err) { #ifdef ICU6x *err = U_ZERO_ERROR; - return (void *) unorm2_getInstance(NULL, "nfc", nfc ? UNORM2_COMPOSE : UNORM2_DECOMPOSE, err); + return (void *)unorm2_getInstance(NULL, "nfc", nfc ? UNORM2_COMPOSE : UNORM2_DECOMPOSE, err); #else - return nfc ? (void *) 0xff : NULL; + return nfc ? (void *)0xff : NULL; #endif } @@ -667,7 +637,7 @@ static inline UNormalizationCheckResult _unorm_quickCheck(void *handle, const UC { *err = U_ZERO_ERROR; #ifdef ICU6x - const UNormalizer2 *n2 = (const UNormalizer2 *) handle; + const UNormalizer2 *n2 = (const UNormalizer2 *)handle; return unorm2_quickCheck(n2, src, -1, err); #else bool nfc = handle != NULL; @@ -679,7 +649,7 @@ static inline int32_t _unorm_normalize(void *handle, const UChar *src, UChar **d { *err = U_ZERO_ERROR; #ifdef ICU6x - const UNormalizer2 *n2 = (const UNormalizer2 *) handle; + const UNormalizer2 *n2 = (const UNormalizer2 *)handle; return unorm2_normalize(n2, src, -1, dest ? *dest : NULL, len, err); #else bool nfc = handle != NULL; @@ -703,7 +673,7 @@ int _pathname_normalize_nfc_icu(const UChar *src, UChar **dest) int32_t destlen; if (_unorm_quickCheck(handle, src, dest, &err) == UNORM_YES) { - *dest = (UChar *) src; + *dest = (UChar *)src; return 0; } @@ -714,7 +684,7 @@ int _pathname_normalize_nfc_icu(const UChar *src, UChar **dest) } *dest = malloc((destlen + 1) * sizeof(UChar)); - if (! *dest) { + if (!*dest) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } @@ -780,7 +750,7 @@ int _pathname_normalize_nfd_icu(const UChar *src, UChar **dest) int32_t destlen; if (_unorm_quickCheck(handle, src, dest, &err) == UNORM_YES) { - *dest = (UChar *) src; + *dest = (UChar *)src; return 0; } @@ -791,7 +761,7 @@ int _pathname_normalize_nfd_icu(const UChar *src, UChar **dest) } *dest = malloc((destlen + 1) * sizeof(UChar)); - if (! *dest) { + if (!*dest) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } @@ -827,7 +797,7 @@ int _pathname_utf8_to_utf16_icu(const char *src, UChar **dest) err = U_ZERO_ERROR; *dest = malloc((destlen + 1) * sizeof(UChar)); - if (! *dest) { + if (!*dest) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } @@ -864,7 +834,7 @@ int _pathname_utf16_to_utf8_icu(const UChar *src, char **dest) err = U_ZERO_ERROR; *dest = malloc(destlen + 1); - if (! *dest) { + if (!*dest) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } @@ -917,7 +887,7 @@ int _pathname_system_to_utf16_icu(const char *src, UChar **dest) err = U_ZERO_ERROR; *dest = malloc((destlen + 1) * sizeof(UChar)); - if (! *dest) { + if (!*dest) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); ucnv_close(syslocale); return -LTFS_NO_MEMORY; @@ -951,10 +921,9 @@ int _pathname_utf8_to_system_icu(const char *src, char **dest) /* If current locale is UTF-8, no conversion needed */ syslocale = ucnv_getDefaultName(); - if (! strcmp(syslocale, "UTF-8")) { + if (!strcmp(syslocale, "UTF-8")) { *dest = arch_strdup(src); - if (! *dest) - return -LTFS_NO_MEMORY; + if (!*dest) return -LTFS_NO_MEMORY; return 0; } @@ -967,7 +936,7 @@ int _pathname_utf8_to_system_icu(const char *src, char **dest) err = U_ZERO_ERROR; *dest = malloc(destlen + 1); - if (! *dest) { + if (!*dest) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } diff --git a/src/libltfs/periodic_sync.c b/src/libltfs/periodic_sync.c index f0ac14e4..6a41e05d 100644 --- a/src/libltfs/periodic_sync.c +++ b/src/libltfs/periodic_sync.c @@ -50,8 +50,9 @@ #include "ltfs_fsops.h" #ifdef mingw_PLATFORM -#include -int gettimeofday(struct timeval* tv, struct timezone* tz) { +# include +int gettimeofday(struct timeval *tv, struct timezone *tz) +{ LARGE_INTEGER freq, count; QueryPerformanceFrequency(&freq); QueryPerformanceCounter(&count); @@ -59,20 +60,21 @@ int gettimeofday(struct timeval* tv, struct timezone* tz) { tv->tv_sec = count.QuadPart / freq.QuadPart; tv->tv_usec = (count.QuadPart % freq.QuadPart) * 1000000 / freq.QuadPart; - return 0; // success + return 0; // success } #endif /** * Periodic sync scheduler private data structure. */ -struct periodic_sync_data { - ltfs_thread_cond_t periodic_sync_thread_cond; /**< Used to wake up the periodic sync thread */ - ltfs_thread_mutex_t periodic_sync_thread_mutex; /**< Used to handle the periodic sync thread */ - ltfs_thread_t periodic_sync_thread_id; /**< Thread id of the periodic sync thread */ - bool keepalive; /**< Used to terminate the background thread */ - int period_sec; /**< Period between sync (sec) */ - struct ltfs_volume *vol; /**< A reference to the LTFS volume structure */ +struct periodic_sync_data +{ + ltfs_thread_cond_t periodic_sync_thread_cond; /**< Used to wake up the periodic sync thread */ + ltfs_thread_mutex_t periodic_sync_thread_mutex; /**< Used to handle the periodic sync thread */ + ltfs_thread_t periodic_sync_thread_id; /**< Thread id of the periodic sync thread */ + bool keepalive; /**< Used to terminate the background thread */ + int period_sec; /**< Period between sync (sec) */ + struct ltfs_volume *vol; /**< A reference to the LTFS volume structure */ }; /** @@ -80,24 +82,21 @@ struct periodic_sync_data { * @param data Periodic sync private data * @return NULL. */ -#define FUSE_REQ_ENTER(r) REQ_NUMBER(REQ_STAT_ENTER, REQ_FUSE, r) -#define FUSE_REQ_EXIT(r) REQ_NUMBER(REQ_STAT_EXIT, REQ_FUSE, r) +#define FUSE_REQ_ENTER(r) REQ_NUMBER(REQ_STAT_ENTER, REQ_FUSE, r) +#define FUSE_REQ_EXIT(r) REQ_NUMBER(REQ_STAT_EXIT, REQ_FUSE, r) -#define REQ_SYNC fffe +#define REQ_SYNC fffe -ltfs_thread_return periodic_sync_thread(void* data) +ltfs_thread_return periodic_sync_thread(void *data) { - struct periodic_sync_data *priv = (struct periodic_sync_data *) data; + struct periodic_sync_data *priv = (struct periodic_sync_data *)data; struct timeval now; int ret; ltfs_thread_mutex_lock(&priv->periodic_sync_thread_mutex); while (priv->keepalive && gettimeofday(&now, NULL) == 0) { - ltfs_thread_cond_timedwait(&priv->periodic_sync_thread_cond, - &priv->periodic_sync_thread_mutex, - priv->period_sec); - if (! priv->keepalive) - break; + ltfs_thread_cond_timedwait(&priv->periodic_sync_thread_cond, &priv->periodic_sync_thread_mutex, priv->period_sec); + if (!priv->keepalive) break; ltfs_request_trace(FUSE_REQ_ENTER(REQ_SYNC), 0, 0); @@ -157,7 +156,7 @@ int periodic_sync_thread_init(int sec, struct ltfs_volume *vol) CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); priv = calloc(1, sizeof(struct periodic_sync_data)); - if (! priv) { + if (!priv) { ltfsmsg(LTFS_ERR, 10001E, "periodic_sync_thread_init: periodic sync data"); return -LTFS_NO_MEMORY; } diff --git a/src/libltfs/plugin.c b/src/libltfs/plugin.c index aa0722d9..56d6691c 100644 --- a/src/libltfs/plugin.c +++ b/src/libltfs/plugin.c @@ -52,24 +52,23 @@ */ #ifdef mingw_PLATFORM -#include "arch/win/win_util.h" +# include "arch/win/win_util.h" #endif #include #include #ifndef mingw_PLATFORM -#include +# include #endif #include +#include "config_file.h" +#include "kmi.h" #include "libltfs/ltfs_error.h" #include "libltfs/ltfslogging.h" -#include "config_file.h" #include "plugin.h" #include "tape.h" -#include "kmi.h" -int plugin_load(struct libltfs_plugin *pl, const char *type, const char *name, - struct config_file *config) +int plugin_load(struct libltfs_plugin *pl, const char *type, const char *name, struct config_file *config) { int ret; const char *lib_path, *message_bundle_name; @@ -85,21 +84,21 @@ int plugin_load(struct libltfs_plugin *pl, const char *type, const char *name, memset(pl, 0, sizeof(*pl)); lib_path = config_file_get_lib(type, name, config); - if (! lib_path) { + if (!lib_path) { ltfsmsg(LTFS_ERR, 11260E, name); return -LTFS_NO_PLUGIN; } pl->lib_handle = dlopen(lib_path, RTLD_NOW); - if (! pl->lib_handle) { -#ifdef _MSC_VER + if (!pl->lib_handle) { +#ifdef _MSC_VER char *err = dlerror(); - ltfsmsg(LTFS_ERR, 11261E,err); + ltfsmsg(LTFS_ERR, 11261E, err); free(err); #else ltfsmsg(LTFS_ERR, 11261E, dlerror()); -#endif // _MSC_VER +#endif // _MSC_VER return -LTFS_PLUGIN_LOAD; } @@ -107,58 +106,58 @@ int plugin_load(struct libltfs_plugin *pl, const char *type, const char *name, ltfsmsg(LTFS_INFO, 17085I, name, type); /* Make sure the plugin knows how to describe its supported operations */ - if (! strcmp(type, "iosched")) + if (!strcmp(type, "iosched")) get_ops = dlsym(pl->lib_handle, "iosched_get_ops"); - else if (! strcmp(type, "tape")) + else if (!strcmp(type, "tape")) get_ops = dlsym(pl->lib_handle, "tape_dev_get_ops"); - else if (! strcmp(type, "changer")) + else if (!strcmp(type, "changer")) get_ops = dlsym(pl->lib_handle, "changer_get_ops"); - else if (! strcmp(type, "dcache")) + else if (!strcmp(type, "dcache")) get_ops = dlsym(pl->lib_handle, "dcache_get_ops"); - else if (! strcmp(type, "kmi")) + else if (!strcmp(type, "kmi")) get_ops = dlsym(pl->lib_handle, "kmi_get_ops"); - else if (! strcmp(type, "crepos")) + else if (!strcmp(type, "crepos")) get_ops = dlsym(pl->lib_handle, "crepos_get_ops"); /* config_file_get_lib already verified that "type" contains one of the values above */ - if (! get_ops) { -#ifdef _MSC_VER + if (!get_ops) { +#ifdef _MSC_VER char *err = dlerror(); ltfsmsg(LTFS_ERR, 11263E, err); free(err); #else ltfsmsg(LTFS_ERR, 11263E, dlerror()); -#endif // _MSC_VER +#endif // _MSC_VER dlclose(pl->lib_handle); pl->lib_handle = NULL; return -LTFS_PLUGIN_LOAD; } /* Make sure the plugin knows how to describe its message bundle (if any) */ - if (! strcmp(type, "iosched")) + if (!strcmp(type, "iosched")) get_messages = dlsym(pl->lib_handle, "iosched_get_message_bundle_name"); - else if (! strcmp(type, "tape")) + else if (!strcmp(type, "tape")) get_messages = dlsym(pl->lib_handle, "tape_dev_get_message_bundle_name"); - else if (! strcmp(type, "changer")) + else if (!strcmp(type, "changer")) get_messages = dlsym(pl->lib_handle, "changer_get_message_bundle_name"); - else if (! strcmp(type, "dcache")) + else if (!strcmp(type, "dcache")) get_messages = dlsym(pl->lib_handle, "dcache_get_message_bundle_name"); - else if (! strcmp(type, "kmi")) + else if (!strcmp(type, "kmi")) get_messages = dlsym(pl->lib_handle, "kmi_get_message_bundle_name"); - else if (! strcmp(type, "crepos")) + else if (!strcmp(type, "crepos")) get_messages = dlsym(pl->lib_handle, "crepos_get_message_bundle_name"); /* config_file_get_lib already verified that "type" contains one of the values above */ - if (! get_messages) { -#ifdef _MSC_VER + if (!get_messages) { +#ifdef _MSC_VER char *err = dlerror(); ltfsmsg(LTFS_ERR, 11284E, err); free(err); #else ltfsmsg(LTFS_ERR, 11263E, dlerror()); -#endif // _MSC_VER +#endif // _MSC_VER dlclose(pl->lib_handle); pl->lib_handle = NULL; return -LTFS_PLUGIN_LOAD; @@ -166,7 +165,7 @@ int plugin_load(struct libltfs_plugin *pl, const char *type, const char *name, /* Ask the plugin what operations and messages it provides */ pl->ops = get_ops(); - if (! pl->ops) { + if (!pl->ops) { ltfsmsg(LTFS_ERR, 11264E); dlclose(pl->lib_handle); pl->lib_handle = NULL; @@ -187,21 +186,20 @@ int plugin_load(struct libltfs_plugin *pl, const char *type, const char *name, int plugin_unload(struct libltfs_plugin *pl) { - if (! pl || ! pl->lib_handle) - return 0; + if (!pl || !pl->lib_handle) return 0; ltfsprintf_unload_plugin(pl->messages); #ifndef VALGRIND_FRIENDLY /* Valgrind cannot resolve function name after closing shared library */ if (dlclose(pl->lib_handle)) { -#ifdef _MSC_VER +# ifdef _MSC_VER char *err = dlerror(); ltfsmsg(LTFS_ERR, 11262E, err); free(err); -#else +# else ltfsmsg(LTFS_ERR, 11262E, dlerror()); -#endif // _MSC_VER +# endif // _MSC_VER return -LTFS_PLUGIN_UNLOAD; } #endif @@ -217,41 +215,39 @@ int plugin_unload(struct libltfs_plugin *pl) * @param ops tape operations for the backend * @param type Plugin type, must be "iosched", "kmi" or "driver" */ -static void print_help_message(const char *progname, void *ops, const char * const type) +static void print_help_message(const char *progname, void *ops, const char *const type) { - if (! ops) { + if (!ops) { ltfsmsg(LTFS_WARN, 10006W, "ops", __FUNCTION__); return; } - if (! strcmp(type, "kmi")) { + if (!strcmp(type, "kmi")) { int ret = kmi_print_help_message(ops); if (ret < 0) { ltfsmsg(LTFS_ERR, 11316E); } - } else if (! strcmp(type, "tape")) + } else if (!strcmp(type, "tape")) tape_print_help_message(progname, ops); else ltfsmsg(LTFS_ERR, 11317E, type); } -void plugin_usage(const char* progname, const char *type, struct config_file *config) +void plugin_usage(const char *progname, const char *type, struct config_file *config) { - struct libltfs_plugin pl = {0}; + struct libltfs_plugin pl = { 0 }; char **backends; int ret, i; backends = config_file_get_plugins(type, config); - if (! backends) { - if (! strcmp(type, "driver")) - ltfsresult(14403I); /* -o devname= */ + if (!backends) { + if (!strcmp(type, "driver")) ltfsresult(14403I); /* -o devname= */ return; } for (i = 0; backends[i] != NULL; ++i) { ret = plugin_load(&pl, type, backends[i], config); - if (ret < 0) - continue; + if (ret < 0) continue; print_help_message(progname, pl.ops, type); plugin_unload(&pl); } diff --git a/src/libltfs/tape.c b/src/libltfs/tape.c index f971cb79..4e6e05ae 100644 --- a/src/libltfs/tape.c +++ b/src/libltfs/tape.c @@ -56,35 +56,34 @@ */ #ifdef mingw_PLATFORM -#include "arch/win/win_util.h" +# include "arch/win/win_util.h" #endif -#include -#include #include - +#include +#include #ifdef __APPLE_MAKEFILE__ -#include -#include +# include +# include #else -#include -#include +# include +# include #endif - +#include "kmi.h" +#include "ltfs_endian.h" #include "ltfs_error.h" #include "tape.h" #include "tape_ops.h" -#include "ltfs_endian.h" -#include "kmi.h" #include "xattr.h" #include "tape_drivers/tape_drivers.h" -enum partition_status { - PART_WRITABLE = 0, /* Device is writable */ - PART_LESS_SPACE, /* Programmable early warning is reported. */ - PART_NO_SPACE /* Early warning is reported. */ +enum partition_status +{ + PART_WRITABLE = 0, /* Device is writable */ + PART_LESS_SPACE, /* Programmable early warning is reported. */ + PART_NO_SPACE /* Early warning is reported. */ }; static bool is_key_set = false; /* If the value is true, set_key() was called with a valid key. */ @@ -96,16 +95,16 @@ static bool is_key_set = false; /* If the value is true, set_key() was called wi extern bool ltfs_is_interrupted(void); #ifdef INTERRUPTED_RETURN -#undef INTERRUPTED_RETURN +# undef INTERRUPTED_RETURN #endif -#define INTERRUPTED_RETURN() \ - do{ \ - if (ltfs_is_interrupted()) { \ - ltfsmsg(LTFS_INFO, 17159I); \ - free(buf); \ - return -LTFS_INTERRUPTED; \ - } \ - }while (0) +#define INTERRUPTED_RETURN() \ + do { \ + if (ltfs_is_interrupted()) { \ + ltfsmsg(LTFS_INFO, 17159I); \ + free(buf); \ + return -LTFS_INTERRUPTED; \ + } \ + } while (0) /** * Allocate space for a tape device. @@ -117,7 +116,7 @@ int tape_device_alloc(struct device_data **device) int ret; struct device_data *newdev = calloc(1, sizeof(struct device_data)); - if (! newdev) { + if (!newdev) { ltfsmsg(LTFS_ERR, 10001E, "tape_device_alloc: device data"); return -LTFS_NO_MEMORY; } @@ -150,11 +149,10 @@ int tape_device_alloc(struct device_data **device) * Free a tape device structure, closing its associated device if necessary. * @param device device to close, set to NULL on success */ -void tape_device_free(struct device_data **device, void * const kmi_handle, bool force) +void tape_device_free(struct device_data **device, void *const kmi_handle, bool force) { if (device && (*device)) { - if ((*device)->backend_data) - tape_device_close(*device, kmi_handle, force); + if ((*device)->backend_data) tape_device_close(*device, kmi_handle, force); ltfs_mutex_destroy(&(*device)->backend_mutex); ltfs_mutex_destroy(&(*device)->read_only_flag_mutex); free(*device); @@ -174,8 +172,7 @@ const char *tape_default_device_name(struct tape_ops *ops) CHECK_ARG_NULL(ops, NULL); - if (ops->default_device_name) - devname = ops->default_device_name(); + if (ops->default_device_name) devname = ops->default_device_name(); return devname; } @@ -186,8 +183,7 @@ const char *tape_default_device_name(struct tape_ops *ops) * @param ops tape operations for the backend * @return 0 on success or a negative value on error. */ -int tape_device_open(struct device_data *device, const char *devname, struct tape_ops *ops, - void * const kmi_handle) +int tape_device_open(struct device_data *device, const char *devname, struct tape_ops *ops, void *const kmi_handle) { unsigned int i; int ret, reserve_tries = 0; @@ -197,15 +193,14 @@ int tape_device_open(struct device_data *device, const char *devname, struct tap CHECK_ARG_NULL(ops, -LTFS_NULL_ARG); /* Validate the tape operations structure. */ - for (i=0; ibackend) - device->backend = ops; + if (!device->backend) device->backend = ops; ret = device->backend->open(devname, &device->backend_data); if (ret < 0) { @@ -218,8 +213,7 @@ int tape_device_open(struct device_data *device, const char *devname, struct tap while (ret < 0 && reserve_tries < 3) { ++reserve_tries; ret = tape_reserve_device(device); - if (ret < 0) - sleep(1); + if (ret < 0) sleep(1); } if (ret < 0) { /* Cannot open device: failed to reserve the device (%d) */ @@ -236,8 +230,7 @@ int tape_device_open(struct device_data *device, const char *devname, struct tap out_free: if (ret) { - if (device->serial_number) - free(device->serial_number); + if (device->serial_number) free(device->serial_number); device->backend_data = NULL; device->backend = NULL; } @@ -274,25 +267,21 @@ int tape_device_reopen(struct device_data *device, const char *devname) * @param kmi_handle handle to the encryption key management I/F * @param skip_aom_setting skip append only mode setting */ -void _tape_device_close(struct device_data *device, void * const kmi_handle, - bool skip_aom_setting, bool force_release) +void _tape_device_close(struct device_data *device, void *const kmi_handle, bool skip_aom_setting, bool force_release) { - if (! device) { + if (!device) { ltfsmsg(LTFS_WARN, 10006W, "device", __FUNCTION__); return; } tape_clear_key(device, kmi_handle); tape_allow_medium_removal(device, force_release); - if (!skip_aom_setting) - tape_enable_append_only_mode(device, false); + if (!skip_aom_setting) tape_enable_append_only_mode(device, false); tape_release_device(device); - if (device->backend && device->backend_data) - device->backend->close(device->backend_data); + if (device->backend && device->backend_data) device->backend->close(device->backend_data); - if (device->serial_number) - free(device->serial_number); + if (device->serial_number) free(device->serial_number); device->backend_data = NULL; device->backend = NULL; @@ -307,13 +296,12 @@ void _tape_device_close(struct device_data *device, void * const kmi_handle, */ void tape_device_close_raw(struct device_data *device) { - if (! device) { + if (!device) { ltfsmsg(LTFS_WARN, 10006W, "device", __FUNCTION__); return; } - if (device->backend && device->backend_data) - device->backend->close_raw(device->backend_data); + if (device->backend && device->backend_data) device->backend->close_raw(device->backend_data); device->backend_data = NULL; device->backend = NULL; @@ -368,7 +356,7 @@ int tape_get_info(struct device_data *dev, struct tc_drive_info *info) * @param dev the device to load * @return 0 on success or a negative value on error. */ -int tape_load_tape(struct device_data *dev, void * const kmi_handle, bool force) +int tape_load_tape(struct device_data *dev, void *const kmi_handle, bool force) { int ret; struct tc_drive_param param; @@ -383,8 +371,7 @@ int tape_load_tape(struct device_data *dev, void * const kmi_handle, bool force) if (!force) { ret = tape_is_cartridge_loadable(dev); - if (ret < 0) - return ret; + if (ret < 0) return ret; } do { @@ -392,9 +379,8 @@ int tape_load_tape(struct device_data *dev, void * const kmi_handle, bool force) if (ret == -EDEV_NO_MEDIUM) { ltfsmsg(LTFS_ERR, 12016E); return -LTFS_NO_MEDIUM; - } else if (ret < 0 && ! NEED_REVAL(ret)) { - if (ret == -EDEV_MEDIUM_FORMAT_ERROR) - ret = -LTFS_UNSUPPORTED_MEDIUM; + } else if (ret < 0 && !NEED_REVAL(ret)) { + if (ret == -EDEV_MEDIUM_FORMAT_ERROR) ret = -LTFS_UNSUPPORTED_MEDIUM; return ret; } } while (NEED_REVAL(ret)); @@ -432,8 +418,7 @@ int tape_load_tape(struct device_data *dev, void * const kmi_handle, bool force) } ret = tape_clear_key(dev, kmi_handle); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* Get remaining capacity of the tape */ ret = tape_get_capacity(dev, &cap); @@ -463,8 +448,7 @@ int tape_load_tape(struct device_data *dev, void * const kmi_handle, bool force) /* TODO: Need to handle logical write protect here */ dev->write_protected = 0; - if (param.write_protect) - dev->write_protected = param.write_protect; + if (param.write_protect) dev->write_protected = param.write_protect; dev->write_error = false; if (cap.max_p0 && cap.max_p1 && !cap.remaining_p0) @@ -507,7 +491,7 @@ int tape_unload_tape(bool keep_on_drive, struct device_data *dev) ret = tape_rewind(dev); } while (NEED_REVAL(ret)); - if (! keep_on_drive) { + if (!keep_on_drive) { do { ret = dev->backend->unload(dev->backend_data, &dev->position); if (ret == -EDEV_CLEANING_REQUIRED) { @@ -602,7 +586,7 @@ int tape_reserve_device(struct device_data *dev) CHECK_ARG_NULL(dev->backend, -LTFS_NULL_ARG); ret = 0; - if (! dev->device_reserved) { + if (!dev->device_reserved) { do { ltfsmsg(LTFS_DEBUG, 12023D); ret = dev->backend->reserve_unit(dev->backend_data); @@ -624,10 +608,10 @@ void tape_release_device(struct device_data *dev) { int ret; - if (! dev) { + if (!dev) { ltfsmsg(LTFS_WARN, 10006W, "dev", __FUNCTION__); return; - } else if (! dev->backend) { + } else if (!dev->backend) { ltfsmsg(LTFS_WARN, 10006W, "dev->backend", __FUNCTION__); return; } @@ -654,7 +638,7 @@ int tape_prevent_medium_removal(struct device_data *dev) CHECK_ARG_NULL(dev->backend, -LTFS_NULL_ARG); ret = 0; - if (! dev->medium_locked) { + if (!dev->medium_locked) { do { ltfsmsg(LTFS_DEBUG, 12026D); ret = dev->backend->prevent_medium_removal(dev->backend_data); @@ -676,10 +660,10 @@ void tape_allow_medium_removal(struct device_data *dev, bool force_release) { int ret; - if (! dev) { + if (!dev) { ltfsmsg(LTFS_WARN, 10006W, "dev", __FUNCTION__); return; - } else if (! dev->backend) { + } else if (!dev->backend) { ltfsmsg(LTFS_WARN, 10006W, "dev->backend", __FUNCTION__); return; } @@ -746,8 +730,7 @@ int tape_get_capacity(struct device_data *dev, struct tc_remaining_cap *cap) CHECK_ARG_NULL(dev->backend, -LTFS_NULL_ARG); ret = dev->backend->remaining_capacity(dev->backend_data, cap); - if (ret < 0) - ltfsmsg(LTFS_ERR, 12030E, ret); + if (ret < 0) ltfsmsg(LTFS_ERR, 12030E, ret); return ret; } @@ -765,8 +748,7 @@ int tape_set_compression(struct device_data *dev, bool use_compression) CHECK_ARG_NULL(dev->backend, -LTFS_NULL_ARG); ret = dev->backend->set_compression(dev->backend_data, use_compression, &dev->position); - if (ret < 0) - ltfsmsg(LTFS_ERR, 12031E, ret); + if (ret < 0) ltfsmsg(LTFS_ERR, 12031E, ret); return ret; } @@ -800,8 +782,7 @@ int tape_set_ip_append_position(struct device_data *dev, tape_partition_t prt, t if (ret == 0 && is_worm) { ret = tape_set_append_position(dev, prt, 0); - } - else { + } else { ret = tape_set_append_position(dev, prt, block); } @@ -846,8 +827,7 @@ int tape_seek_append_position(struct device_data *dev, tape_partition_t prt, boo ltfs_mutex_unlock(&dev->append_pos_mutex); /* Goto EOD with locate command with really big positon, because space command cannot specify partition. */ - if (new_pos.block == 0) - new_pos.block = TAPE_BLOCK_MAX; + if (new_pos.block == 0) new_pos.block = TAPE_BLOCK_MAX; ret = tape_seek(dev, &new_pos); if (ret < 0) { ltfsmsg(LTFS_ERR, 12033E, ret); @@ -860,8 +840,7 @@ int tape_seek_append_position(struct device_data *dev, tape_partition_t prt, boo ret = dev->backend->allow_overwrite(dev->backend_data, dev->position); ltfs_mutex_lock(&dev->append_pos_mutex); - if (dev->append_pos[prt] == 0) - dev->append_pos[prt] = dev->position.block; + if (dev->append_pos[prt] == 0) dev->append_pos[prt] = dev->position.block; ltfs_mutex_unlock(&dev->append_pos_mutex); return ret; @@ -882,8 +861,7 @@ int tape_get_params(struct device_data *dev, struct tc_drive_param *param) CHECK_ARG_NULL(param, -LTFS_NULL_ARG); ret = dev->backend->get_parameters(dev->backend_data, param); - if (ret < 0) - ltfsmsg(LTFS_ERR, 12034E, ret); + if (ret < 0) ltfsmsg(LTFS_ERR, 12034E, ret); return ret; } @@ -904,8 +882,7 @@ int tape_get_max_blocksize(struct device_data *dev, unsigned int *size) *size = 0; ret = tape_get_params(dev, ¶m); - if (!ret) - *size = param.max_blksize; + if (!ret) *size = param.max_blksize; return ret; } @@ -948,8 +925,7 @@ int tape_read_only(struct device_data *dev, tape_partition_t partition) ltfs_mutex_unlock(&dev->read_only_flag_mutex); if (!ret) { - if (dev->backend->is_readonly(dev->backend_data)) - ret = -LTFS_RDONLY_DEN_DRV; + if (dev->backend->is_readonly(dev->backend_data)) ret = -LTFS_RDONLY_DEN_DRV; } return ret; @@ -983,8 +959,7 @@ int tape_rewind(struct device_data *dev) CHECK_ARG_NULL(dev->backend, -LTFS_NULL_ARG); ret = dev->backend->rewind(dev->backend_data, &dev->position); - if (ret < 0) - ltfsmsg(LTFS_ERR, 12035E, ret); + if (ret < 0) ltfsmsg(LTFS_ERR, 12035E, ret); return ret; } @@ -1004,15 +979,15 @@ int tape_seek(struct device_data *dev, struct tc_position *pos) CHECK_ARG_NULL(pos, -LTFS_NULL_ARG); CHECK_ARG_NULL(dev->backend, -LTFS_NULL_ARG); - if ((pos->partition == 0 && pos->block == 0) || pos->partition != dev->position.partition || pos->block != dev->position.block) { + if ((pos->partition == 0 && pos->block == 0) || pos->partition != dev->position.partition || + pos->block != dev->position.block) { /* Explicitly seek to (0,0) to detect known upper generation tape */ ret = dev->backend->locate(dev->backend_data, *pos, &dev->position); if (ret < 0) ltfsmsg(LTFS_ERR, 12037E, ret); else { ltfs_mutex_lock(&dev->read_only_flag_mutex); - if (dev->position.early_warning) - dev->partition_space[dev->position.partition] = PART_NO_SPACE; + if (dev->position.early_warning) dev->partition_space[dev->position.partition] = PART_NO_SPACE; if (dev->partition_space[dev->position.partition] != PART_NO_SPACE && dev->position.programmable_early_warning) dev->partition_space[dev->position.partition] = PART_LESS_SPACE; ltfs_mutex_unlock(&dev->read_only_flag_mutex); @@ -1029,7 +1004,7 @@ int tape_seek(struct device_data *dev, struct tc_position *pos) } if (ret == 0 && (dev->position.partition != pos->partition || - (pos->block != TAPE_BLOCK_MAX && pos->block != dev->position.block))) { + (pos->block != TAPE_BLOCK_MAX && pos->block != dev->position.block))) { ltfsmsg(LTFS_ERR, 12036E); ret = -LTFS_BAD_LOCATE; } @@ -1077,8 +1052,7 @@ int tape_seek_eod(struct device_data *dev, tape_partition_t partition) } ltfs_mutex_lock(&dev->read_only_flag_mutex); - if (dev->position.early_warning) - dev->partition_space[dev->position.partition] = PART_NO_SPACE; + if (dev->position.early_warning) dev->partition_space[dev->position.partition] = PART_NO_SPACE; if (dev->partition_space[dev->position.partition] != PART_NO_SPACE && dev->position.programmable_early_warning) dev->partition_space[dev->position.partition] = PART_LESS_SPACE; ltfs_mutex_unlock(&dev->read_only_flag_mutex); @@ -1143,11 +1117,12 @@ int tape_get_first_untransfered_position(struct device_data *dev, struct tc_posi return ret; } - ltfsmsg(LTFS_INFO, 17292I, - (unsigned long long)dev->position.partition, - (unsigned long long)dev->position.block, - (unsigned long long)pos->partition, - (unsigned long long)pos->block); + ltfsmsg(LTFS_INFO, + 17292I, + (unsigned long long)dev->position.partition, + (unsigned long long)dev->position.block, + (unsigned long long)pos->partition, + (unsigned long long)pos->block); return 0; } @@ -1170,8 +1145,7 @@ int tape_spacefm(struct device_data *dev, int count) else ret = dev->backend->space(dev->backend_data, -count, TC_SPACE_FM_B, &dev->position); - if (ret < 0) - ltfsmsg(LTFS_ERR, 12041E, ret); + if (ret < 0) ltfsmsg(LTFS_ERR, 12041E, ret); return ret; } @@ -1193,7 +1167,7 @@ ssize_t tape_write(struct device_data *dev, const char *buf, size_t count, bool CHECK_ARG_NULL(dev, -LTFS_NULL_ARG); CHECK_ARG_NULL(buf, -LTFS_NULL_ARG); - if (! dev->backend || ! dev->backend_data) { + if (!dev->backend || !dev->backend_data) { ltfsmsg(LTFS_ERR, 12042E); return -LTFS_NULL_ARG; } @@ -1217,13 +1191,12 @@ ssize_t tape_write(struct device_data *dev, const char *buf, size_t count, bool ret = -LTFS_LARGE_BLOCKSIZE; } ltfs_mutex_unlock(&dev->read_only_flag_mutex); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = dev->backend->write(dev->backend_data, buf, count, &dev->position); if (ret < 0) { /* If a "real" write error occurs, refuse any additional writes */ - if (! NEED_REVAL(ret)) { + if (!NEED_REVAL(ret)) { ltfsmsg(LTFS_ERR, 12045E, (int)ret); ltfs_mutex_lock(&dev->read_only_flag_mutex); dev->write_error = true; @@ -1234,18 +1207,16 @@ ssize_t tape_write(struct device_data *dev, const char *buf, size_t count, bool ltfs_mutex_lock(&dev->read_only_flag_mutex); dev->partition_space[dev->position.partition] = PART_NO_SPACE; ltfs_mutex_unlock(&dev->read_only_flag_mutex); - if (! ignore_nospc) - count = -LTFS_NO_SPACE; + if (!ignore_nospc) count = -LTFS_NO_SPACE; } else if (dev->position.programmable_early_warning) { ltfs_mutex_lock(&dev->read_only_flag_mutex); dev->partition_space[dev->position.partition] = PART_LESS_SPACE; ltfs_mutex_unlock(&dev->read_only_flag_mutex); - if (! ignore_less) - count = -LTFS_LESS_SPACE; + if (!ignore_less) count = -LTFS_LESS_SPACE; } if (ltfs_caught_sigcont()) { - // Unset flag to avoid checking it again if it is not needed + // Unset flag to avoid checking it again if it is not needed ltfs_sigcont_set(false); ret_for_current_position = tape_get_position_from_drive(dev, ¤t_position); @@ -1284,7 +1255,7 @@ int tape_write_filemark(struct device_data *dev, uint8_t count, bool ignore_less int ret; CHECK_ARG_NULL(dev, -LTFS_NULL_ARG); - if (! dev->backend || ! dev->backend_data) { + if (!dev->backend || !dev->backend_data) { ltfsmsg(LTFS_ERR, 12046E); return -LTFS_NULL_ARG; } @@ -1300,13 +1271,12 @@ int tape_write_filemark(struct device_data *dev, uint8_t count, bool ignore_less else if (dev->partition_space[dev->position.partition] == PART_LESS_SPACE && !ignore_less) ret = -LTFS_LESS_SPACE; ltfs_mutex_unlock(&dev->read_only_flag_mutex); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = dev->backend->writefm(dev->backend_data, count, &dev->position, immed); if (ret < 0) { /* If a "real" write error occurs, refuse all further writes */ - if (! NEED_REVAL(ret)) { + if (!NEED_REVAL(ret)) { ltfsmsg(LTFS_ERR, 12047E, ret); ltfs_mutex_lock(&dev->read_only_flag_mutex); dev->write_error = true; @@ -1317,14 +1287,12 @@ int tape_write_filemark(struct device_data *dev, uint8_t count, bool ignore_less ltfs_mutex_lock(&dev->read_only_flag_mutex); dev->partition_space[dev->position.partition] = PART_NO_SPACE; ltfs_mutex_unlock(&dev->read_only_flag_mutex); - if (! ignore_nospc) - ret = -LTFS_NO_SPACE; + if (!ignore_nospc) ret = -LTFS_NO_SPACE; } else if (dev->position.programmable_early_warning) { ltfs_mutex_lock(&dev->read_only_flag_mutex); dev->partition_space[dev->position.partition] = PART_LESS_SPACE; ltfs_mutex_unlock(&dev->read_only_flag_mutex); - if (! ignore_less) - ret = -LTFS_LESS_SPACE; + if (!ignore_less) ret = -LTFS_LESS_SPACE; } ltfs_mutex_lock(&dev->append_pos_mutex); @@ -1343,14 +1311,13 @@ int tape_write_filemark(struct device_data *dev, uint8_t count, bool ignore_less * @param kmi_handle key manager interface handle for getting a key of a key-alias * @return number of bytes read, or a negative value on error. */ -ssize_t tape_read(struct device_data *dev, char *buf, size_t count, const bool unusual_size, - void * const kmi_handle) +ssize_t tape_read(struct device_data *dev, char *buf, size_t count, const bool unusual_size, void *const kmi_handle) { ssize_t ret; CHECK_ARG_NULL(dev, -LTFS_NULL_ARG); CHECK_ARG_NULL(buf, -LTFS_NULL_ARG); - if (! dev->backend || ! dev->backend_data) { + if (!dev->backend || !dev->backend_data) { ltfsmsg(LTFS_ERR, 12048E); return -LTFS_BAD_DEVICE_DATA; } @@ -1372,7 +1339,7 @@ ssize_t tape_read(struct device_data *dev, char *buf, size_t count, const bool u ltfsmsg(LTFS_ERR, 17176E, tmp); break; } - if (! key) { + if (!key) { ltfsmsg(LTFS_ERR, 17177E); break; } @@ -1384,13 +1351,11 @@ ssize_t tape_read(struct device_data *dev, char *buf, size_t count, const bool u /* try to read using the suitable data key */ ret = dev->backend->read(dev->backend_data, buf, count, &dev->position, unusual_size); - } while(0); + } while (0); } - if (ret == -EDEV_CRYPTO_ERROR || ret == -EDEV_KEY_REQUIRED) - ltfsmsg(LTFS_WARN, 17192W); - if (ret < 0) - ltfsmsg(LTFS_ERR, 12049E, (int)ret); + if (ret == -EDEV_CRYPTO_ERROR || ret == -EDEV_KEY_REQUIRED) ltfsmsg(LTFS_WARN, 17192W); + if (ret < 0) ltfsmsg(LTFS_ERR, 12049E, (int)ret); return ret; } @@ -1407,8 +1372,7 @@ int tape_erase(struct device_data *dev, bool long_erase) CHECK_ARG_NULL(dev, -LTFS_NULL_ARG); ret = dev->backend->erase(dev->backend_data, &dev->position, long_erase); - if (ret < 0) - ltfsmsg(LTFS_ERR, 17149E, ret); + if (ret < 0) ltfsmsg(LTFS_ERR, 17149E, ret); return ret; } @@ -1455,11 +1419,11 @@ int tape_reset_capacity(struct device_data *dev) static int tape_update_density(struct device_data *dev, int density_code) { int ret; - unsigned char mp_read_write_ctrl[TC_MP_READ_WRITE_CTRL_SIZE] = {0}; + unsigned char mp_read_write_ctrl[TC_MP_READ_WRITE_CTRL_SIZE] = { 0 }; /* Issue Mode Sense (MP x25) */ - ret = dev->backend->modesense(dev->backend_data, TC_MP_READ_WRITE_CTRL, TC_MP_PC_CURRENT, 0x00, - mp_read_write_ctrl, TC_MP_READ_WRITE_CTRL_SIZE); + ret = dev->backend->modesense( + dev->backend_data, TC_MP_READ_WRITE_CTRL, TC_MP_PC_CURRENT, 0x00, mp_read_write_ctrl, TC_MP_READ_WRITE_CTRL_SIZE); if (ret < 0) { ltfsmsg(LTFS_ERR, 17239E, "modesense", ret); return ret; @@ -1492,7 +1456,7 @@ static int tape_update_density(struct device_data *dev, int density_code) int tape_format(struct device_data *dev, tape_partition_t index_part, int density_code, bool hard) { int ret; - unsigned char mp_medium_partition[TC_MP_MEDIUM_PARTITION_SIZE+4]; + unsigned char mp_medium_partition[TC_MP_MEDIUM_PARTITION_SIZE + 4]; int page_length = TC_MP_MEDIUM_PARTITION_SIZE; TC_FORMAT_TYPE format_type = TC_FORMAT_PARTITION; @@ -1510,9 +1474,13 @@ int tape_format(struct device_data *dev, tape_partition_t index_part, int densit } /* Issue Mode Sense (MP x11) */ - memset(mp_medium_partition, 0, TC_MP_MEDIUM_PARTITION_SIZE+4); - ret = dev->backend->modesense(dev->backend_data, TC_MP_MEDIUM_PARTITION, TC_MP_PC_CURRENT, 0x00, - mp_medium_partition, TC_MP_MEDIUM_PARTITION_SIZE); + memset(mp_medium_partition, 0, TC_MP_MEDIUM_PARTITION_SIZE + 4); + ret = dev->backend->modesense(dev->backend_data, + TC_MP_MEDIUM_PARTITION, + TC_MP_PC_CURRENT, + 0x00, + mp_medium_partition, + TC_MP_MEDIUM_PARTITION_SIZE); if (ret < 0) { ltfsmsg(LTFS_ERR, 12051E, ret); return ret; @@ -1531,12 +1499,13 @@ int tape_format(struct device_data *dev, tape_partition_t index_part, int densit } /* Set appropriate values to the page and Issue Mode Select */ - mp_medium_partition[0] = 0x00; - mp_medium_partition[1] = 0x00; + mp_medium_partition[0] = 0x00; + mp_medium_partition[1] = 0x00; if (index_part == UINT32_MAX) { - mp_medium_partition[19] = 0x00; /* No additional partition, means one-partitioned */ - mp_medium_partition[20] = 0x20 | (mp_medium_partition[20] & 0x1F); /* Set FDP=0, SDP=0, IDP=1 ==> FIXED DATA PARTITION */ + mp_medium_partition[19] = 0x00; /* No additional partition, means one-partitioned */ + mp_medium_partition[20] = + 0x20 | (mp_medium_partition[20] & 0x1F); /* Set FDP=0, SDP=0, IDP=1 ==> FIXED DATA PARTITION */ mp_medium_partition[22] = 0x08; @@ -1548,24 +1517,24 @@ int tape_format(struct device_data *dev, tape_partition_t index_part, int densit if (index_part == 1) { mp_medium_partition[19] = 0x01; mp_medium_partition[20] = 0x20 | (mp_medium_partition[20] & 0x1F); /* Set FDP=0, SDP=0, IDP=1 ==> User Setting */ - mp_medium_partition[22] = 0x09; /* Set partition unit as gigabytes (10^9) */ + mp_medium_partition[22] = 0x09; /* Set partition unit as gigabytes (10^9) */ - mp_medium_partition[24] = 0xFF; /* Set Partition0 Capacity */ + mp_medium_partition[24] = 0xFF; /* Set Partition0 Capacity */ mp_medium_partition[25] = 0xFF; /* Set Partition1 Capacity to 1GB, This value will round up to minimum partition size in FCR3175-r2 */ /* This field meaning will be chnaged in FCR3175-r3. In r3 n of "minumim partition size * n" should be specified. */ /* If set this parameter to 1, we can support both specs. */ /* In r2, this value is rounded up to minimum partition size. In r3, this value is the correct value.*/ mp_medium_partition[26] = 0x00; /* Set Partition1 Capacity */ - mp_medium_partition[27] = 1; /* will round up to minimum partition size */ + mp_medium_partition[27] = 1; /* will round up to minimum partition size */ } else { mp_medium_partition[19] = 0x01; mp_medium_partition[20] = 0x20 | (mp_medium_partition[20] & 0x1F); /* Set FDP=0, SDP=0, IDP=1 ==> User Setting */ - mp_medium_partition[22] = 0x09; /* Set partition unit as gigabytes (10^9) */ + mp_medium_partition[22] = 0x09; /* Set partition unit as gigabytes (10^9) */ - mp_medium_partition[24] = 0x00; /* Set Partition0 Capacity */ - mp_medium_partition[25] = 1; /* will round up to minimum partition size */ - mp_medium_partition[26] = 0xFF; /* Set Partition1 Capacity */ + mp_medium_partition[24] = 0x00; /* Set Partition0 Capacity */ + mp_medium_partition[25] = 1; /* will round up to minimum partition size */ + mp_medium_partition[26] = 0xFF; /* Set Partition1 Capacity */ mp_medium_partition[27] = 0xFF; } } @@ -1574,15 +1543,10 @@ int tape_format(struct device_data *dev, tape_partition_t index_part, int densit page_length += (mp_medium_partition[17] - 0x0A); } - ret = dev->backend->modeselect( - dev->backend_data, - mp_medium_partition, - page_length - ); + ret = dev->backend->modeselect(dev->backend_data, mp_medium_partition, page_length); /* Issue Format Medium (Make partitioned medium) */ - if (hard) - format_type = TC_FORMAT_DEST_PART; + if (hard) format_type = TC_FORMAT_DEST_PART; ret = dev->backend->format(dev->backend_data, format_type, NULL, NULL, NULL); if (ret < 0) { @@ -1668,15 +1632,11 @@ int tape_get_volume_change_reference(struct device_data *dev, uint64_t *volume_c CHECK_ARG_NULL(dev, -LTFS_NULL_ARG); CHECK_ARG_NULL(dev->backend, -LTFS_NULL_ARG); - ret = dev->backend->read_attribute(dev->backend_data, 0, - TC_MAM_PAGE_VCR, - vcr_data, - sizeof(vcr_data)); + ret = dev->backend->read_attribute(dev->backend_data, 0, TC_MAM_PAGE_VCR, vcr_data, sizeof(vcr_data)); if (ret == 0) { *volume_change_ref = (uint64_t)ltfs_betou32(vcr_data + 5); - if (*volume_change_ref == UINT32_MAX) - *volume_change_ref = UINT64_MAX; /* maintain "unusable VCR" state correctly */ + if (*volume_change_ref == UINT32_MAX) *volume_change_ref = UINT64_MAX; /* maintain "unusable VCR" state correctly */ } else { ltfsmsg(LTFS_WARN, 12056W, ret); *volume_change_ref = UINT64_MAX; /* disallow use of VCR */ @@ -1690,8 +1650,7 @@ int tape_get_volume_change_reference(struct device_data *dev, uint64_t *volume_c * @param dev device to format * @return 0 on success or a negative value on error */ -int tape_get_cart_coherency(struct device_data *dev, const tape_partition_t part, - struct tc_coherency *coh) +int tape_get_cart_coherency(struct device_data *dev, const tape_partition_t part, struct tc_coherency *coh) { int ret; unsigned char coh_data[TC_MAM_PAGE_COHERENCY_SIZE + TC_MAM_PAGE_HEADER_SIZE]; @@ -1699,15 +1658,12 @@ int tape_get_cart_coherency(struct device_data *dev, const tape_partition_t part CHECK_ARG_NULL(dev, -LTFS_NULL_ARG); CHECK_ARG_NULL(dev->backend, -LTFS_NULL_ARG); - ret = dev->backend->read_attribute(dev->backend_data, part, - TC_MAM_PAGE_COHERENCY, - coh_data, - sizeof(coh_data)); + ret = dev->backend->read_attribute(dev->backend_data, part, TC_MAM_PAGE_COHERENCY, coh_data, sizeof(coh_data)); if (ret == 0) { - uint16_t id = ltfs_betou16(coh_data); + uint16_t id = ltfs_betou16(coh_data); uint16_t len = ltfs_betou16(coh_data + 3); - uint8_t vcr_size = coh_data[5]; + uint8_t vcr_size = coh_data[5]; if (id != TC_MAM_PAGE_COHERENCY) { ltfsmsg(LTFS_WARN, 12058W, id); @@ -1763,8 +1719,7 @@ int tape_get_cart_coherency(struct device_data *dev, const tape_partition_t part * @param dev device to format * @return 0 on success or a negative value on error */ -int tape_set_cart_coherency(struct device_data *dev, const tape_partition_t part, - struct tc_coherency *coh) +int tape_set_cart_coherency(struct device_data *dev, const tape_partition_t part, struct tc_coherency *coh) { int ret; unsigned char coh_data[TC_MAM_PAGE_COHERENCY_SIZE + TC_MAM_PAGE_HEADER_SIZE]; @@ -1773,17 +1728,17 @@ int tape_set_cart_coherency(struct device_data *dev, const tape_partition_t part CHECK_ARG_NULL(dev->backend, -LTFS_NULL_ARG); ltfs_u16tobe(coh_data, TC_MAM_PAGE_COHERENCY); - coh_data[2] = 0; + coh_data[2] = 0; ltfs_u16tobe(coh_data + 3, TC_MAM_PAGE_COHERENCY_SIZE); - coh_data[5] = 0x08; /* Size of Volume Change Reference Value (VCR)*/ + coh_data[5] = 0x08; /* Size of Volume Change Reference Value (VCR)*/ ltfs_u64tobe(coh_data + 6, coh->volume_change_ref); - ltfs_u64tobe(coh_data + 14, coh->count); /* VOLUME COHERENCY COUNT */ + ltfs_u64tobe(coh_data + 14, coh->count); /* VOLUME COHERENCY COUNT */ ltfs_u64tobe(coh_data + 22, coh->set_id); /* VOLUME COHERENCY SET IDENTIFIER */ /* APPLICATION CLIENT SPECIFIC INFORMATION LENGTH */ - coh_data[30] = 0; /* Size of APPLICATION CLIENT SPECIFIC INFORMATION (Byte 1) */ + coh_data[30] = 0; /* Size of APPLICATION CLIENT SPECIFIC INFORMATION (Byte 1) */ coh_data[31] = 43; /* Size of APPLICATION CLIENT SPECIFIC INFORMATION (Byte 0) */ /* Size of the buffer to insert 'LTFS' needs to be size of 5 for the 4 letters and the null terminator*/ - arch_strncpy((char *)coh_data + 32,"LTFS", 5, 4); + arch_strncpy((char *)coh_data + 32, "LTFS", 5, 4); memcpy(coh_data + 37, coh->uuid, 37); /* Version field @@ -1793,8 +1748,7 @@ int tape_set_cart_coherency(struct device_data *dev, const tape_partition_t part coh_data[74] = coh->version; /* version field should be specified before calling this function */ ret = dev->backend->write_attribute(dev->backend_data, part, coh_data, sizeof(coh_data)); - if (ret < 0) - ltfsmsg(LTFS_WARN, 12063W, ret); + if (ret < 0) ltfsmsg(LTFS_WARN, 12063W, ret); return ret; } @@ -1807,10 +1761,10 @@ int tape_get_cart_volume_lock_status(struct device_data *dev, int *status) CHECK_ARG_NULL(status, -LTFS_NULL_ARG); ret = dev->backend->read_attribute(dev->backend_data, - 0, /* partition */ - TC_MAM_LOCKED_MAM, - attr_data, - sizeof(attr_data)); + 0, /* partition */ + TC_MAM_LOCKED_MAM, + attr_data, + sizeof(attr_data)); if (ret == 0) { uint16_t id = ltfs_betou16(attr_data); @@ -1883,18 +1837,17 @@ int tape_get_media_pool_info(struct ltfs_volume *vol, char **media_name, char ** { int i, len = 0, add_start = 0; bool is_add_info = false; - char *name=NULL, *info=NULL; + char *name = NULL, *info = NULL; CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); vol->t_attr->media_pool[TC_MAM_MEDIA_POOL_SIZE] = '\0'; /* Add a sentinel */ len = strlen(vol->t_attr->media_pool); - if (len == 0) - return -1; + if (len == 0) return -1; - if (vol->t_attr->media_pool[len-1] == ']') { - for (i=0; it_attr->media_pool[len - 1] == ']') { + for (i = 0; i < len - 1; i++) { if (vol->t_attr->media_pool[i] == '[') { if (is_add_info) { /* double [ situation. */ @@ -1914,22 +1867,19 @@ int tape_get_media_pool_info(struct ltfs_volume *vol, char **media_name, char ** } if (is_add_info) { - if (add_start !=0) { + if (add_start != 0) { name = strndup(vol->t_attr->media_pool, add_start); } - info = arch_strdup(&(vol->t_attr->media_pool[add_start+1])); + info = arch_strdup(&(vol->t_attr->media_pool[add_start + 1])); len = strlen(info); - info[len-1] = '\0'; - } - else { + info[len - 1] = '\0'; + } else { name = arch_strdup(vol->t_attr->media_pool); } - if (name) - *media_name = name; + if (name) *media_name = name; - if (info) - *add_info = info; + if (info) *add_info = info; return 0; } @@ -2004,17 +1954,17 @@ int tape_check_eod_status(struct device_data *dev, const tape_partition_t part) CHECK_ARG_NULL(dev, -LTFS_NULL_ARG); ret = dev->backend->get_eod_status(dev->backend_data, part); - switch(ret) { - case -EDEV_UNSUPPORTED_FUNCTION: - ret = EOD_UNKNOWN; - break; - case EOD_GOOD: - case EOD_MISSING: - case EOD_UNKNOWN: - break; - default: - ret = EOD_UNKNOWN; - break; + switch (ret) { + case -EDEV_UNSUPPORTED_FUNCTION: + ret = EOD_UNKNOWN; + break; + case EOD_GOOD: + case EOD_MISSING: + case EOD_UNKNOWN: + break; + default: + ret = EOD_UNKNOWN; + break; } return ret; @@ -2025,7 +1975,7 @@ int tape_check_eod_status(struct device_data *dev, const tape_partition_t part) * @param dev device to format * @return 0 on success or a negative value on error */ -int tape_recover_eod_status(struct device_data *dev, void * const kmi_handle) +int tape_recover_eod_status(struct device_data *dev, void *const kmi_handle) { int ret; char *buf; @@ -2042,7 +1992,7 @@ int tape_recover_eod_status(struct device_data *dev, void * const kmi_handle) } buf = calloc(1, recover_block_size + LTFS_CRC_SIZE); - if (! buf) { + if (!buf) { ltfsmsg(LTFS_ERR, 10001E, "tape_recover_eod_status: data buffer"); return -LTFS_NO_MEMORY; } @@ -2050,16 +2000,15 @@ int tape_recover_eod_status(struct device_data *dev, void * const kmi_handle) /* Read forward by hitting read perm (actual EOD), or EOD */ ltfsmsg(LTFS_INFO, 17127I); ret = 0; - while ( ret >= 0) { + while (ret >= 0) { INTERRUPTED_RETURN(); ret = tape_read(dev, buf, (size_t)recover_block_size, true, kmi_handle); - if(ret == -EDEV_EOD_DETECTED) { + if (ret == -EDEV_EOD_DETECTED) { ltfsmsg(LTFS_INFO, 17169I); } else if (ret == -EDEV_READ_PERM) ltfsmsg(LTFS_INFO, 17130I); else { - if(ret < 0) - ltfsmsg(LTFS_WARN, 17129W); + if (ret < 0) ltfsmsg(LTFS_WARN, 17129W); } } free(buf); @@ -2129,13 +2078,12 @@ int tape_get_device_list(struct tape_ops *ops, struct tc_drive_info *buf, int co */ void tape_print_help_message(const char *progname, struct tape_ops *ops) { - if (! ops) { + if (!ops) { ltfsmsg(LTFS_WARN, 10006W, "ops", __FUNCTION__); return; } - if (ops->help_message) - ops->help_message(progname); + if (ops->help_message) ops->help_message(progname); } int tape_parse_opts(struct device_data *dev, void *opt_args) @@ -2147,8 +2095,7 @@ int tape_parse_opts(struct device_data *dev, void *opt_args) CHECK_ARG_NULL(dev->backend, -LTFS_NULL_ARG); ret = dev->backend->parse_opts(dev->backend_data, opt_args); - if (ret < 0) - /* Cannot parse backend options: backend call failed (%d) */ + if (ret < 0) /* Cannot parse backend options: backend call failed (%d) */ ltfsmsg(LTFS_ERR, 12040E, ret); return ret; @@ -2157,14 +2104,13 @@ int tape_parse_opts(struct device_data *dev, void *opt_args) int tape_parse_library_backend_opts(void *opts, void *opt_args) { int rc; - struct tape_ops *backend = (struct tape_ops *) opts; + struct tape_ops *backend = (struct tape_ops *)opts; CHECK_ARG_NULL(opts, -LTFS_NULL_ARG); CHECK_ARG_NULL(opt_args, -LTFS_NULL_ARG); rc = backend->parse_opts(NULL, opt_args); - if (rc < 0) - /* Cannot parse backend options: backend call failed (%d) */ + if (rc < 0) /* Cannot parse backend options: backend call failed (%d) */ ltfsmsg(LTFS_ERR, 12040E, rc); return rc; @@ -2251,8 +2197,7 @@ int tape_locate_previous_index(struct device_data *dev) CHECK_ARG_NULL(dev->backend_data, -LTFS_NULL_ARG); ret = tape_spacefm(dev, -4); - if (! ret) - ret = tape_spacefm(dev, 1); + if (!ret) ret = tape_spacefm(dev, 1); return ret; } @@ -2273,8 +2218,7 @@ int tape_locate_first_index(struct device_data *dev, tape_partition_t partition) CHECK_ARG_NULL(dev->backend_data, -LTFS_NULL_ARG); ret = tape_seek(dev, &seekpos); - if (! ret) - ret = tape_spacefm(dev, 1); + if (!ret) ret = tape_spacefm(dev, 1); return ret; } @@ -2294,12 +2238,10 @@ int tape_locate_last_index(struct device_data *dev, tape_partition_t partition) CHECK_ARG_NULL(dev->backend_data, -LTFS_NULL_ARG); ret = tape_seek_eod(dev, partition); - if(ret) - return ret; + if (ret) return ret; ret = tape_spacefm(dev, -2); - if(!ret) - ret = tape_spacefm(dev, 1); + if (!ret) ret = tape_spacefm(dev, 1); return ret; } @@ -2430,17 +2372,16 @@ int tape_set_pews(struct device_data *dev, bool set_value) if (set_value) { /* set PEW to half of capacity of index partition */ half_of_max_p0 = cap.max_p0 / 2; - pews = (uint16_t) (half_of_max_p0 < max_pews ? half_of_max_p0 : max_pews); - } - else { + pews = (uint16_t)(half_of_max_p0 < max_pews ? half_of_max_p0 : max_pews); + } else { /* clear PEW value */ pews = 0; } /* Issue Mode Sense (MP x10.01) */ memset(mp_dev_config_ext, 0, TC_MP_DEV_CONFIG_EXT_SIZE); - ret = dev->backend->modesense(dev->backend_data, TC_MP_DEV_CONFIG_EXT, TC_MP_PC_CURRENT, 0x01, - mp_dev_config_ext, TC_MP_DEV_CONFIG_EXT_SIZE); + ret = dev->backend->modesense( + dev->backend_data, TC_MP_DEV_CONFIG_EXT, TC_MP_PC_CURRENT, 0x01, mp_dev_config_ext, TC_MP_DEV_CONFIG_EXT_SIZE); if (ret < 0) { ltfsmsg(LTFS_ERR, 17102E, ret); return ret; @@ -2452,15 +2393,14 @@ int tape_set_pews(struct device_data *dev, bool set_value) } /* Set appropriate values to the page and Issue Mode Select */ - mp_dev_config_ext[0] = 0x00; - mp_dev_config_ext[1] = 0x00; + mp_dev_config_ext[0] = 0x00; + mp_dev_config_ext[1] = 0x00; mp_dev_config_ext[16] &= 0x7F; - mp_dev_config_ext[22] = (uint8_t)(pews >> 8 & 0xFF); - mp_dev_config_ext[23] = (uint8_t)(pews & 0xFF); + mp_dev_config_ext[22] = (uint8_t)(pews >> 8 & 0xFF); + mp_dev_config_ext[23] = (uint8_t)(pews & 0xFF); ret = dev->backend->modeselect(dev->backend_data, mp_dev_config_ext, TC_MP_DEV_CONFIG_EXT_SIZE); - if (ret < 0) - ltfsmsg(LTFS_ERR, 17103E, ret); + if (ret < 0) ltfsmsg(LTFS_ERR, 17103E, ret); return 0; } @@ -2482,8 +2422,8 @@ int tape_get_pews(struct device_data *dev, uint16_t *pews) /* Issue Mode Sense (MP x10.01) */ memset(mp_dev_config_ext, 0, TC_MP_DEV_CONFIG_EXT_SIZE); - ret = dev->backend->modesense(dev->backend_data, TC_MP_DEV_CONFIG_EXT, TC_MP_PC_CURRENT, 0x01, - mp_dev_config_ext, TC_MP_DEV_CONFIG_EXT_SIZE); + ret = dev->backend->modesense( + dev->backend_data, TC_MP_DEV_CONFIG_EXT, TC_MP_PC_CURRENT, 0x01, mp_dev_config_ext, TC_MP_DEV_CONFIG_EXT_SIZE); if (ret < 0) { ltfsmsg(LTFS_ERR, 17104E, ret); return ret; @@ -2529,8 +2469,8 @@ int tape_enable_append_only_mode(struct device_data *dev, bool enable) /* Issue Mode Sense (MP x10.01) */ memset(mp_dev_config_ext, 0, TC_MP_DEV_CONFIG_EXT_SIZE); - ret = dev->backend->modesense(dev->backend_data, TC_MP_DEV_CONFIG_EXT, TC_MP_PC_CURRENT, 0x01, - mp_dev_config_ext, TC_MP_DEV_CONFIG_EXT_SIZE); + ret = dev->backend->modesense( + dev->backend_data, TC_MP_DEV_CONFIG_EXT, TC_MP_PC_CURRENT, 0x01, mp_dev_config_ext, TC_MP_DEV_CONFIG_EXT_SIZE); if (ret < 0) { ltfsmsg(LTFS_ERR, 17154E, ret); return ret; @@ -2543,7 +2483,7 @@ int tape_enable_append_only_mode(struct device_data *dev, bool enable) /* If cartridge is loaded and append-only mode is to be disabled, the cartridge has to be unloaded before sending mode select. */ - if (loaded && !enable && (mp_dev_config_ext[21]& 0xF0) == 0x10) { + if (loaded && !enable && (mp_dev_config_ext[21] & 0xF0) == 0x10) { ret = dev->backend->unload(dev->backend_data, &dev->position); if (ret == -EDEV_CLEANING_REQUIRED) { /* Ignore cleaning sense */ @@ -2559,8 +2499,7 @@ int tape_enable_append_only_mode(struct device_data *dev, bool enable) /* If cartridge is loaded and and append-only mode is to be enabled, the current position has to be a BOP */ ret = dev->backend->load(dev->backend_data, &dev->position); - if (ret == -EDEV_MEDIUM_FORMAT_ERROR) - ret = -LTFS_UNSUPPORTED_MEDIUM; + if (ret == -EDEV_MEDIUM_FORMAT_ERROR) ret = -LTFS_UNSUPPORTED_MEDIUM; if (ret < 0) { ltfsmsg(LTFS_ERR, 17152E, "BOP", ret); return ret; @@ -2568,8 +2507,8 @@ int tape_enable_append_only_mode(struct device_data *dev, bool enable) } /* Set appropriate values to the page and Issue Mode Select */ - mp_dev_config_ext[0] = 0x00; - mp_dev_config_ext[1] = 0x00; + mp_dev_config_ext[0] = 0x00; + mp_dev_config_ext[1] = 0x00; mp_dev_config_ext[16] &= 0x7F; mp_dev_config_ext[21] &= 0x0F; mp_dev_config_ext[21] |= enable ? 0x10 : 0x00; @@ -2620,8 +2559,8 @@ int tape_get_append_only_mode_setting(struct device_data *dev, bool *enabled) /* Issue Mode Sense (MP x10.01) */ memset(mp_dev_config_ext, 0, TC_MP_DEV_CONFIG_EXT_SIZE); - ret = dev->backend->modesense(dev->backend_data, TC_MP_DEV_CONFIG_EXT, TC_MP_PC_CURRENT, 0x01, - mp_dev_config_ext, TC_MP_DEV_CONFIG_EXT_SIZE); + ret = dev->backend->modesense( + dev->backend_data, TC_MP_DEV_CONFIG_EXT, TC_MP_PC_CURRENT, 0x01, mp_dev_config_ext, TC_MP_DEV_CONFIG_EXT_SIZE); if (ret < 0) { ltfsmsg(LTFS_ERR, 17156E, ret); return ret; @@ -2649,29 +2588,29 @@ int tape_is_cartridge_loadable(struct device_data *dev) CHECK_ARG_NULL(dev, -LTFS_NULL_ARG); - for(i = 0; i < 300 && ret < 0; i++) { + for (i = 0; i < 300 && ret < 0; i++) { ret = _tape_test_unit_ready(dev); switch (ret) { - case DEVICE_GOOD: - case -EDEV_NEED_INITIALIZE: - ret = DEVICE_GOOD; - goto out; - break; - case -EDEV_NO_MEDIUM: - ret = -LTFS_NO_MEDIUM; - goto out; - break; - case -EDEV_BECOMING_READY: - case -EDEV_NOT_SELF_CONFIGURED_YET: - sleep(1); - break; - case -EDEV_MEDIUM_MAY_BE_CHANGED: - case -EDEV_POR_OR_BUS_RESET: - case -EDEV_CONFIGURE_CHANGED: - break; - default: - goto out; - break; + case DEVICE_GOOD: + case -EDEV_NEED_INITIALIZE: + ret = DEVICE_GOOD; + goto out; + break; + case -EDEV_NO_MEDIUM: + ret = -LTFS_NO_MEDIUM; + goto out; + break; + case -EDEV_BECOMING_READY: + case -EDEV_NOT_SELF_CONFIGURED_YET: + sleep(1); + break; + case -EDEV_MEDIUM_MAY_BE_CHANGED: + case -EDEV_POR_OR_BUS_RESET: + case -EDEV_CONFIGURE_CHANGED: + break; + default: + goto out; + break; } } @@ -2679,8 +2618,8 @@ int tape_is_cartridge_loadable(struct device_data *dev) return ret; } -int tape_logsense(struct device_data *dev, const uint8_t page, const uint8_t subpage, - unsigned char *buf, const size_t size) +int tape_logsense( + struct device_data *dev, const uint8_t page, const uint8_t subpage, unsigned char *buf, const size_t size) { int ret = -EDEV_UNKNOWN; @@ -2696,7 +2635,7 @@ int tape_logsense(struct device_data *dev, const uint8_t page, const uint8_t sub * @param device handle to tape device * @return 0 on success or a negative value on error */ -int tape_wait_device_ready(struct device_data *dev, void * const kmi_handle) +int tape_wait_device_ready(struct device_data *dev, void *const kmi_handle) { CHECK_ARG_NULL(dev, -LTFS_NULL_ARG); @@ -2704,26 +2643,26 @@ int tape_wait_device_ready(struct device_data *dev, void * const kmi_handle) bool print_message = false; make_ready: - for(i = 0; i < 3 && ret < 0; i++) { + for (i = 0; i < 3 && ret < 0; i++) { ret = _tape_test_unit_ready(dev); if (ret == -EDEV_NEED_INITIALIZE || ret == -EDEV_BECOMING_READY) { if (!print_message) { switch (ret) { - case -EDEV_NEED_INITIALIZE: - ltfsmsg(LTFS_INFO, 17189I, ret); - break; - case -EDEV_BECOMING_READY: - ltfsmsg(LTFS_INFO, 17189I, ret); - print_message = true; - break; - default: - ltfsmsg(LTFS_ERR, 17187E, ret); - break; + case -EDEV_NEED_INITIALIZE: + ltfsmsg(LTFS_INFO, 17189I, ret); + break; + case -EDEV_BECOMING_READY: + ltfsmsg(LTFS_INFO, 17189I, ret); + print_message = true; + break; + default: + ltfsmsg(LTFS_ERR, 17187E, ret); + break; } } uint64_t tape_alert = 0; if (0 <= tape_get_tape_alert(dev, &tape_alert)) { - const uint64_t cleaning_media = 0x0000000000000400LL; /* 000Bh */ + const uint64_t cleaning_media = 0x0000000000000400LL; /* 000Bh */ const uint64_t expired_cleaning_tape = 0x0000000000020000LL; /* 0016h */ const uint64_t invalid_cleaning_tape = 0x0000000000040000LL; /* 0017h */ const uint64_t any_cleaning_media = cleaning_media | expired_cleaning_tape | invalid_cleaning_tape; @@ -2744,12 +2683,11 @@ int tape_wait_device_ready(struct device_data *dev, void * const kmi_handle) return ret; } - for(i = 0; i < 30 && ret < 0; i++) { + for (i = 0; i < 30 && ret < 0; i++) { ret = _tape_test_unit_ready(dev); - if (ret != -EDEV_BECOMING_READY) - ltfsmsg(LTFS_INFO, 17188I, ret); - if (ret == DEVICE_GOOD || ret == -EDEV_NO_MEDIUM || ret == -EDEV_DRIVER_ERROR || - IS_MEDIUM_ERROR(-ret) || IS_HARDWARE_ERROR(-ret) ) + if (ret != -EDEV_BECOMING_READY) ltfsmsg(LTFS_INFO, 17188I, ret); + if (ret == DEVICE_GOOD || ret == -EDEV_NO_MEDIUM || ret == -EDEV_DRIVER_ERROR || IS_MEDIUM_ERROR(-ret) || + IS_HARDWARE_ERROR(-ret)) break; sleep(1); } @@ -2769,11 +2707,10 @@ int tape_set_key(struct device_data *dev, const unsigned char *keyalias, const u CHECK_ARG_NULL(dev, -LTFS_NULL_ARG); /* allow null keyalias and null key */ - struct tc_position pos = {0}; + struct tc_position pos = { 0 }; if (key) { const int ret = dev->backend->readpos(dev->backend_data, &pos); - if (ret < 0) - return ret; + if (ret < 0) return ret; is_key_set = true; } @@ -2806,10 +2743,9 @@ int tape_set_key(struct device_data *dev, const unsigned char *keyalias, const u * @param kmi_handle handle to key manager interface * @return 0 on success or a negative value on error */ -int tape_clear_key(struct device_data *device, void * const kmi_handle) +int tape_clear_key(struct device_data *device, void *const kmi_handle) { - if (kmi_handle || is_key_set) - return tape_set_key(device, NULL, NULL); + if (kmi_handle || is_key_set) return tape_set_key(device, NULL, NULL); return 0; } @@ -2835,17 +2771,16 @@ int tape_takedump_drive(struct device_data *dev, bool nonforced_dump) return dev->backend->takedump_drive(dev->backend_data, nonforced_dump); } -#define CRYPTO_STATUS (24) +#define CRYPTO_STATUS (24) #define MEDIUM_SUPPORT_CRYPTO (0x01) -char* tape_get_media_encrypted(struct device_data *dev) +char *tape_get_media_encrypted(struct device_data *dev) { - unsigned char buf[TC_MP_READ_WRITE_CTRL_SIZE] = {0}; + unsigned char buf[TC_MP_READ_WRITE_CTRL_SIZE] = { 0 }; int ret = -EDEV_UNKNOWN; char *encrypted = NULL; - ret = dev->backend->modesense(dev->backend_data, TC_MP_READ_WRITE_CTRL, TC_MP_PC_CURRENT, - 0, buf, sizeof(buf)); + ret = dev->backend->modesense(dev->backend_data, TC_MP_READ_WRITE_CTRL, TC_MP_PC_CURRENT, 0, buf, sizeof(buf)); if (ret < 0) encrypted = "unknown"; else @@ -2854,17 +2789,16 @@ char* tape_get_media_encrypted(struct device_data *dev) return encrypted; } -#define CRYPTO_CONTROL (20) -#define CRYPTO_STATE_MASK (0x03) +#define CRYPTO_CONTROL (20) +#define CRYPTO_STATE_MASK (0x03) char *tape_get_drive_encryption_state(struct device_data *dev) { - unsigned char buf[TC_MP_READ_WRITE_CTRL_SIZE] = {0}; + unsigned char buf[TC_MP_READ_WRITE_CTRL_SIZE] = { 0 }; int ret = -EDEV_UNKNOWN; char *state = NULL; - ret = dev->backend->modesense(dev->backend_data, TC_MP_READ_WRITE_CTRL, TC_MP_PC_CURRENT, - 0, buf, sizeof(buf)); + ret = dev->backend->modesense(dev->backend_data, TC_MP_READ_WRITE_CTRL, TC_MP_PC_CURRENT, 0, buf, sizeof(buf)); if (ret < 0) state = "unknown"; else { @@ -2889,14 +2823,13 @@ char *tape_get_drive_encryption_state(struct device_data *dev) char *tape_get_drive_encryption_method(struct device_data *dev) { - unsigned char buf[TC_MP_READ_WRITE_CTRL_SIZE] = {0}; + unsigned char buf[TC_MP_READ_WRITE_CTRL_SIZE] = { 0 }; int ret = -EDEV_UNKNOWN; unsigned char encryption_method = 0; char *method = NULL; - ret = dev->backend->modesense(dev->backend_data, TC_MP_READ_WRITE_CTRL, TC_MP_PC_CURRENT, - 0, buf, sizeof(buf)); - if (ret< 0) + ret = dev->backend->modesense(dev->backend_data, TC_MP_READ_WRITE_CTRL, TC_MP_PC_CURRENT, 0, buf, sizeof(buf)); + if (ret < 0) method = "Unknown"; else { encryption_method = buf[16 + 27]; @@ -2907,7 +2840,7 @@ char *tape_get_drive_encryption_method(struct device_data *dev) break; case 0x10: method = "System Managed"; - break; + break; case 0x1F: method = "Controller Managed"; break; @@ -2952,7 +2885,7 @@ void parse_vol(char *str, int start_len, int end_len) str[end_len] = '\0'; - return ; + return; } /** @@ -2970,10 +2903,9 @@ int u_get_truncate_size(const char *name, int name_len, int max_size) /* check whether string is utf8 */ u_strFromUTF8(NULL, 0, NULL, name, (int32_t)name_len, &err); - if (U_FAILURE(err) && err != U_BUFFER_OVERFLOW_ERROR) - return -LTFS_ICU_ERROR; + if (U_FAILURE(err) && err != U_BUFFER_OVERFLOW_ERROR) return -LTFS_ICU_ERROR; - while (size < (int32_t) max_size) { + while (size < (int32_t)max_size) { re_size = size; U8_NEXT(name, size, (int32_t)max_size, c); } @@ -3009,21 +2941,22 @@ void set_tape_attribute(struct ltfs_volume *vol, struct tape_attr *t_attr) arch_strncpy_auto(t_attr->app_name, PACKAGE_NAME, TC_MAM_APP_NAME_SIZE); parse_vol(t_attr->app_name, strlen(PACKAGE_NAME), TC_MAM_APP_NAME_SIZE); - /* APPLICATION VERSION set */ arch_strncpy_auto(t_attr->app_ver, PACKAGE_VERSION, TC_MAM_APP_VERSION_SIZE); parse_vol(t_attr->app_ver, strlen(PACKAGE_VERSION), TC_MAM_APP_VERSION_SIZE); /* USER MEDIUM LABEL set */ memset(t_attr->medium_label, '\0', TC_MAM_USER_MEDIUM_LABEL_SIZE + 1); - if ( vol->index->volume_name.name ) { + if (vol->index->volume_name.name) { len_volname = strlen(vol->index->volume_name.name); - if ( len_volname > TC_MAM_USER_MEDIUM_LABEL_SIZE - 1) { - ltfsmsg(LTFS_DEBUG, 17229D, "USER MEDIUM TEXT LABEL", - vol->index->volume_name.name, TC_MAM_USER_MEDIUM_LABEL_SIZE - 1); + if (len_volname > TC_MAM_USER_MEDIUM_LABEL_SIZE - 1) { + ltfsmsg(LTFS_DEBUG, + 17229D, + "USER MEDIUM TEXT LABEL", + vol->index->volume_name.name, + TC_MAM_USER_MEDIUM_LABEL_SIZE - 1); len_volname = u_get_truncate_size(vol->index->volume_name.name, len_volname, TC_MAM_USER_MEDIUM_LABEL_SIZE); - if (len_volname == -LTFS_ICU_ERROR) - len_volname = TC_MAM_USER_MEDIUM_LABEL_SIZE - 1; + if (len_volname == -LTFS_ICU_ERROR) len_volname = TC_MAM_USER_MEDIUM_LABEL_SIZE - 1; } arch_strncpy(t_attr->medium_label, vol->index->volume_name.name, sizeof(t_attr->medium_label), len_volname); } @@ -3032,8 +2965,8 @@ void set_tape_attribute(struct ltfs_volume *vol, struct tape_attr *t_attr) t_attr->tli = TEXT_LOCALIZATION_IDENTIFIER_UTF8; /* BARCODE set */ - if ( vol->label->barcode[0] ) { - if ( strlen(vol->label->barcode) > TC_MAM_BARCODE_SIZE) + if (vol->label->barcode[0]) { + if (strlen(vol->label->barcode) > TC_MAM_BARCODE_SIZE) ltfsmsg(LTFS_WARN, 17203W, "BARCODE", vol->label->barcode, TC_MAM_BARCODE_SIZE); arch_strncpy_auto(t_attr->barcode, vol->label->barcode, TC_MAM_BARCODE_SIZE); parse_vol(t_attr->barcode, strlen(vol->label->barcode), TC_MAM_BARCODE_SIZE); @@ -3075,45 +3008,45 @@ int tape_set_attribute_to_cm(struct device_data *dev, struct tape_attr *t_attr, CHECK_ARG_NULL(t_attr, -LTFS_NULL_ARG); switch (type) { - case TC_MAM_APP_VENDER: - attr_size = TC_MAM_APP_VENDER_SIZE; - format = ASCII_FORMAT; - break; - case TC_MAM_APP_NAME: - attr_size = TC_MAM_APP_NAME_SIZE; - format = ASCII_FORMAT; - break; - case TC_MAM_APP_VERSION: - attr_size = TC_MAM_APP_VERSION_SIZE; - format = ASCII_FORMAT; - break; - case TC_MAM_USER_MEDIUM_LABEL: - attr_size = TC_MAM_USER_MEDIUM_LABEL_SIZE; - format = TEXT_FORMAT; - break; - case TC_MAM_TEXT_LOCALIZATION_IDENTIFIER: - attr_size = TC_MAM_TEXT_LOCALIZATION_IDENTIFIER_SIZE; - format = BINARY_FORMAT; - break; - case TC_MAM_BARCODE: - attr_size = TC_MAM_BARCODE_SIZE; - format = ASCII_FORMAT; - break; - case TC_MAM_APP_FORMAT_VERSION: - attr_size = TC_MAM_APP_FORMAT_VERSION_SIZE; - format = ASCII_FORMAT; - break; - case TC_MAM_LOCKED_MAM: - attr_size = TC_MAM_LOCKED_MAM_SIZE; - format = BINARY_FORMAT; - break; - case TC_MAM_MEDIA_POOL: - attr_size = TC_MAM_MEDIA_POOL_SIZE; - format = TEXT_FORMAT; - break; - default: - ltfsmsg(LTFS_WARN, 17204W, type, "tape_set_attribute_to_cm"); - return -1; + case TC_MAM_APP_VENDER: + attr_size = TC_MAM_APP_VENDER_SIZE; + format = ASCII_FORMAT; + break; + case TC_MAM_APP_NAME: + attr_size = TC_MAM_APP_NAME_SIZE; + format = ASCII_FORMAT; + break; + case TC_MAM_APP_VERSION: + attr_size = TC_MAM_APP_VERSION_SIZE; + format = ASCII_FORMAT; + break; + case TC_MAM_USER_MEDIUM_LABEL: + attr_size = TC_MAM_USER_MEDIUM_LABEL_SIZE; + format = TEXT_FORMAT; + break; + case TC_MAM_TEXT_LOCALIZATION_IDENTIFIER: + attr_size = TC_MAM_TEXT_LOCALIZATION_IDENTIFIER_SIZE; + format = BINARY_FORMAT; + break; + case TC_MAM_BARCODE: + attr_size = TC_MAM_BARCODE_SIZE; + format = ASCII_FORMAT; + break; + case TC_MAM_APP_FORMAT_VERSION: + attr_size = TC_MAM_APP_FORMAT_VERSION_SIZE; + format = ASCII_FORMAT; + break; + case TC_MAM_LOCKED_MAM: + attr_size = TC_MAM_LOCKED_MAM_SIZE; + format = BINARY_FORMAT; + break; + case TC_MAM_MEDIA_POOL: + attr_size = TC_MAM_MEDIA_POOL_SIZE; + format = TEXT_FORMAT; + break; + default: + ltfsmsg(LTFS_WARN, 17204W, type, "tape_set_attribute_to_cm"); + return -1; } /* we reserve the size of the attribute + the MAM header size since the buffer will contain both */ @@ -3121,65 +3054,65 @@ int tape_set_attribute_to_cm(struct device_data *dev, struct tape_attr *t_attr, if (!attr_data) { return -LTFS_NO_MEMORY; } - + /* fill the MAM header information */ - ltfs_u16tobe(attr_data, type); /* set attribute type */ - attr_data[2] = format; /* set data format type */ - ltfs_u16tobe(attr_data + 3, attr_size); /* set data size */ + ltfs_u16tobe(attr_data, type); /* set attribute type */ + attr_data[2] = format; /* set data format type */ + ltfs_u16tobe(attr_data + 3, attr_size); /* set data size */ /* data becomes the remaining space after TC_MAM_PAGE_HEADER_SIZE to start writing in, that is the reason why we add it here to the buffer address */ data = attr_data + TC_MAM_PAGE_HEADER_SIZE; /* set attribute data */ switch (type) { - case TC_MAM_APP_VENDER: - len = strnlen(t_attr->vender, attr_size); - memcpy(data, t_attr->vender, len); - break; - - case TC_MAM_APP_NAME: - len = strnlen(t_attr->app_name, attr_size); - memcpy(data, t_attr->app_name, len); - break; - - case TC_MAM_APP_VERSION: - len = strnlen(t_attr->app_ver, attr_size); - memcpy(data, t_attr->app_ver, len); - break; - - case TC_MAM_USER_MEDIUM_LABEL: - len = strnlen(t_attr->medium_label, attr_size); - memcpy(data, t_attr->medium_label, len); - break; - - case TC_MAM_TEXT_LOCALIZATION_IDENTIFIER: - data[0] = t_attr->tli; - break; - - case TC_MAM_BARCODE: - len = strnlen(t_attr->barcode, attr_size); - memcpy(data, t_attr->barcode, len); - break; - - case TC_MAM_APP_FORMAT_VERSION: - len = strnlen(t_attr->app_format_ver, attr_size); - memcpy(data, t_attr->app_format_ver, len); - break; - - case TC_MAM_LOCKED_MAM: - data[0] = t_attr->vollock; - break; - - case TC_MAM_MEDIA_POOL: - len = strnlen(t_attr->media_pool, attr_size); - memcpy(data, t_attr->media_pool, len); - break; + case TC_MAM_APP_VENDER: + len = strnlen(t_attr->vender, attr_size); + memcpy(data, t_attr->vender, len); + break; + + case TC_MAM_APP_NAME: + len = strnlen(t_attr->app_name, attr_size); + memcpy(data, t_attr->app_name, len); + break; + + case TC_MAM_APP_VERSION: + len = strnlen(t_attr->app_ver, attr_size); + memcpy(data, t_attr->app_ver, len); + break; + + case TC_MAM_USER_MEDIUM_LABEL: + len = strnlen(t_attr->medium_label, attr_size); + memcpy(data, t_attr->medium_label, len); + break; + + case TC_MAM_TEXT_LOCALIZATION_IDENTIFIER: + data[0] = t_attr->tli; + break; + + case TC_MAM_BARCODE: + len = strnlen(t_attr->barcode, attr_size); + memcpy(data, t_attr->barcode, len); + break; + + case TC_MAM_APP_FORMAT_VERSION: + len = strnlen(t_attr->app_format_ver, attr_size); + memcpy(data, t_attr->app_format_ver, len); + break; + + case TC_MAM_LOCKED_MAM: + data[0] = t_attr->vollock; + break; + + case TC_MAM_MEDIA_POOL: + len = strnlen(t_attr->media_pool, attr_size); + memcpy(data, t_attr->media_pool, len); + break; } ret = dev->backend->write_attribute(dev->backend_data, - 0, /* partition */ - attr_data, - attr_size + TC_MAM_PAGE_HEADER_SIZE); + 0, /* partition */ + attr_data, + attr_size + TC_MAM_PAGE_HEADER_SIZE); if (ret < 0) { ltfsmsg(LTFS_ERR, 17205E, type, "tape_set_attribute_to_cm"); @@ -3203,51 +3136,41 @@ int tape_format_attribute_to_cm(struct device_data *dev, struct tape_attr *t_att /* APPLICATION VENDOR set */ ret = ret_save = tape_set_attribute_to_cm(dev, t_attr, TC_MAM_APP_VENDER); - if (ret < 0) - ret_save = ret; + if (ret < 0) ret_save = ret; - /* APPRICATION NAME set */ + /* APPRICATION NAME set */ ret = tape_set_attribute_to_cm(dev, t_attr, TC_MAM_APP_NAME); - if (ret < 0) - ret_save = ret; + if (ret < 0) ret_save = ret; /* APPLICATION VERSION set */ ret = tape_set_attribute_to_cm(dev, t_attr, TC_MAM_APP_VERSION); - if (ret < 0) - ret_save = ret; + if (ret < 0) ret_save = ret; /* USER MEDIUM LABEL set */ ret = tape_set_attribute_to_cm(dev, t_attr, TC_MAM_USER_MEDIUM_LABEL); - if (ret < 0) - ret_save = ret; + if (ret < 0) ret_save = ret; /* TEXT LOCALIZATION IDENTIFIER set */ ret = tape_set_attribute_to_cm(dev, t_attr, TC_MAM_TEXT_LOCALIZATION_IDENTIFIER); - if (ret < 0) - ret_save = ret; + if (ret < 0) ret_save = ret; /* BARCODE set */ ret = tape_set_attribute_to_cm(dev, t_attr, TC_MAM_BARCODE); - if (ret < 0) - ret_save = ret; + if (ret < 0) ret_save = ret; /* APPLICATION FORMAT VERSION set */ ret = tape_set_attribute_to_cm(dev, t_attr, TC_MAM_APP_FORMAT_VERSION); - if (ret < 0) - ret_save = ret; + if (ret < 0) ret_save = ret; /* VOLUME LOCKED set */ ret = tape_set_attribute_to_cm(dev, t_attr, TC_MAM_LOCKED_MAM); - if (ret < 0) - ret_save = ret; + if (ret < 0) ret_save = ret; /* MEDIA POOL set */ ret = tape_set_attribute_to_cm(dev, t_attr, TC_MAM_MEDIA_POOL); - if (ret < 0) - ret_save = ret; + if (ret < 0) ret_save = ret; - if (!ret && ret_save) - ret = ret_save; + if (!ret && ret_save) ret = ret_save; return ret; } @@ -3269,49 +3192,49 @@ int tape_get_attribute_from_cm(struct device_data *dev, struct tape_attr *t_attr CHECK_ARG_NULL(t_attr, -LTFS_NULL_ARG); switch (type) { - case TC_MAM_APP_VENDER: - attr_len = TC_MAM_APP_VENDER_SIZE; - break; - case TC_MAM_APP_NAME: - attr_len = TC_MAM_APP_NAME_SIZE; - break; - case TC_MAM_APP_VERSION: - attr_len = TC_MAM_APP_VERSION_SIZE; - break; - case TC_MAM_USER_MEDIUM_LABEL: - attr_len = TC_MAM_USER_MEDIUM_LABEL_SIZE; - break; - case TC_MAM_TEXT_LOCALIZATION_IDENTIFIER: - attr_len = TC_MAM_TEXT_LOCALIZATION_IDENTIFIER_SIZE; - break; - case TC_MAM_BARCODE: - attr_len = TC_MAM_BARCODE_SIZE; - break; - case TC_MAM_APP_FORMAT_VERSION: - attr_len = TC_MAM_APP_FORMAT_VERSION_SIZE; - break; - case TC_MAM_LOCKED_MAM: - attr_len = TC_MAM_LOCKED_MAM_SIZE; - break; - case TC_MAM_MEDIA_POOL: - attr_len = TC_MAM_MEDIA_POOL_SIZE; - break; - default: - ltfsmsg(LTFS_WARN, 17204W, type, "tape_get_attribute_from_cm"); - return -LTFS_BAD_ARG; - break; + case TC_MAM_APP_VENDER: + attr_len = TC_MAM_APP_VENDER_SIZE; + break; + case TC_MAM_APP_NAME: + attr_len = TC_MAM_APP_NAME_SIZE; + break; + case TC_MAM_APP_VERSION: + attr_len = TC_MAM_APP_VERSION_SIZE; + break; + case TC_MAM_USER_MEDIUM_LABEL: + attr_len = TC_MAM_USER_MEDIUM_LABEL_SIZE; + break; + case TC_MAM_TEXT_LOCALIZATION_IDENTIFIER: + attr_len = TC_MAM_TEXT_LOCALIZATION_IDENTIFIER_SIZE; + break; + case TC_MAM_BARCODE: + attr_len = TC_MAM_BARCODE_SIZE; + break; + case TC_MAM_APP_FORMAT_VERSION: + attr_len = TC_MAM_APP_FORMAT_VERSION_SIZE; + break; + case TC_MAM_LOCKED_MAM: + attr_len = TC_MAM_LOCKED_MAM_SIZE; + break; + case TC_MAM_MEDIA_POOL: + attr_len = TC_MAM_MEDIA_POOL_SIZE; + break; + default: + ltfsmsg(LTFS_WARN, 17204W, type, "tape_get_attribute_from_cm"); + return -LTFS_BAD_ARG; + break; } int attr_size = sizeof(char) * (attr_len + TC_MAM_PAGE_HEADER_SIZE); - attr_data = (unsigned char*)malloc(attr_size); + attr_data = (unsigned char *)malloc(attr_size); if (!attr_data) { return -LTFS_NO_MEMORY; } ret = dev->backend->read_attribute(dev->backend_data, - 0, /* partition */ - type, - attr_data, - attr_size); + 0, /* partition */ + type, + attr_data, + attr_size); if (ret == 0) { uint16_t id = ltfs_betou16(attr_data); @@ -3381,48 +3304,39 @@ void tape_load_all_attribute_from_cm(struct device_data *dev, struct tape_attr * /* get APPLICATION VENDER */ ret = tape_get_attribute_from_cm(dev, t_attr, TC_MAM_APP_VENDER); - if (ret < 0) - t_attr->vender[0] = '\0'; + if (ret < 0) t_attr->vender[0] = '\0'; /* get APPLICATION NAME */ ret = tape_get_attribute_from_cm(dev, t_attr, TC_MAM_APP_NAME); - if (ret < 0) - t_attr->app_name[0] = '\0'; + if (ret < 0) t_attr->app_name[0] = '\0'; /* get APPLICATION VERSION */ ret = tape_get_attribute_from_cm(dev, t_attr, TC_MAM_APP_VERSION); - if (ret < 0) - t_attr->app_ver[0] = '\0'; + if (ret < 0) t_attr->app_ver[0] = '\0'; /* get USER MEDIUM TEXT LABEL */ ret = tape_get_attribute_from_cm(dev, t_attr, TC_MAM_USER_MEDIUM_LABEL); - if (ret < 0) - t_attr->medium_label[0] = '\0'; + if (ret < 0) t_attr->medium_label[0] = '\0'; /* get TEXT LOCALIZATION IDENTIFIER */ ret = tape_get_attribute_from_cm(dev, t_attr, TC_MAM_TEXT_LOCALIZATION_IDENTIFIER); - if (ret < 0) - t_attr->tli = '\0'; + if (ret < 0) t_attr->tli = '\0'; /* get BARCODE */ ret = tape_get_attribute_from_cm(dev, t_attr, TC_MAM_BARCODE); - if (ret < 0) - t_attr->barcode[0] = '\0'; + if (ret < 0) t_attr->barcode[0] = '\0'; /* get APPLICATION FORMAT VERSION */ ret = tape_get_attribute_from_cm(dev, t_attr, TC_MAM_APP_FORMAT_VERSION); - if (ret < 0) - t_attr->app_format_ver[0] = '\0'; + if (ret < 0) t_attr->app_format_ver[0] = '\0'; /* get VOLUME LOCKED */ ret = tape_get_attribute_from_cm(dev, t_attr, TC_MAM_LOCKED_MAM); - if (ret < 0) - t_attr->vollock = '\0'; + if (ret < 0) t_attr->vollock = '\0'; /* get MEDIA POOL */ ret = tape_get_attribute_from_cm(dev, t_attr, TC_MAM_MEDIA_POOL); - if (ret < 0) - t_attr->media_pool[0] = '\0'; + if (ret < 0) t_attr->media_pool[0] = '\0'; ltfsmsg(LTFS_INFO, 17227I, "Vendor", t_attr->vender); ltfsmsg(LTFS_INFO, 17227I, "Application Name", t_attr->app_name); @@ -3453,73 +3367,74 @@ int update_tape_attribute(struct ltfs_volume *vol, const char *new_value, int ty CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); /* type check */ - if (type != TC_MAM_USER_MEDIUM_LABEL && type != TC_MAM_BARCODE - && type != TC_MAM_LOCKED_MAM && type != TC_MAM_MEDIA_POOL) { + if (type != TC_MAM_USER_MEDIUM_LABEL && type != TC_MAM_BARCODE && type != TC_MAM_LOCKED_MAM && + type != TC_MAM_MEDIA_POOL) { ltfsmsg(LTFS_WARN, 17204W, type, "update_tape_attribute"); return -1; } - if (!vol->t_attr) - return -1; + if (!vol->t_attr) return -1; /* Attribute size check */ - if ( type == TC_MAM_USER_MEDIUM_LABEL ) { - if ( size > TC_MAM_USER_MEDIUM_LABEL_SIZE - 1) { - ltfsmsg(LTFS_DEBUG, 17229D, "USER MEDIUM TEXT LABEL", - vol->index->volume_name.name, TC_MAM_USER_MEDIUM_LABEL_SIZE - 1); + if (type == TC_MAM_USER_MEDIUM_LABEL) { + if (size > TC_MAM_USER_MEDIUM_LABEL_SIZE - 1) { + ltfsmsg(LTFS_DEBUG, + 17229D, + "USER MEDIUM TEXT LABEL", + vol->index->volume_name.name, + TC_MAM_USER_MEDIUM_LABEL_SIZE - 1); size = u_get_truncate_size(vol->index->volume_name.name, size, TC_MAM_USER_MEDIUM_LABEL_SIZE); - if (size == -LTFS_ICU_ERROR) - size = TC_MAM_USER_MEDIUM_LABEL_SIZE - 1; + if (size == -LTFS_ICU_ERROR) size = TC_MAM_USER_MEDIUM_LABEL_SIZE - 1; } pre_attr = arch_strdup(vol->t_attr->medium_label); - if (! pre_attr) { + if (!pre_attr) { ltfsmsg(LTFS_ERR, 10001E, "update_tape_attribute: pre_attr"); - ret = -ENOMEM; - return ret; + ret = -ENOMEM; + return ret; } memset(vol->t_attr->medium_label, '\0', TC_MAM_USER_MEDIUM_LABEL_SIZE + 1); - if ( new_value ) { + if (new_value) { arch_strncpy_auto(vol->t_attr->medium_label, new_value, size); } } else if (type == TC_MAM_BARCODE) { - if ( size > TC_MAM_BARCODE_SIZE) { + if (size > TC_MAM_BARCODE_SIZE) { ltfsmsg(LTFS_WARN, 17226W, "BARCODE", TC_MAM_BARCODE_SIZE); return -LTFS_LARGE_XATTR; } pre_attr = arch_strdup(vol->t_attr->barcode); - if (! pre_attr) { - ltfsmsg(LTFS_ERR, 10001E, "update_tape_attribute: pre_attr"); - ret = -ENOMEM; - return ret; + if (!pre_attr) { + ltfsmsg(LTFS_ERR, 10001E, "update_tape_attribute: pre_attr"); + ret = -ENOMEM; + return ret; } memset(vol->t_attr->barcode, '\0', TC_MAM_BARCODE_SIZE + 1); - if ( new_value ) { + if (new_value) { arch_strncpy_auto(vol->t_attr->barcode, new_value, size); } parse_vol(vol->t_attr->barcode, strlen(new_value), TC_MAM_BARCODE_SIZE); } else if (type == TC_MAM_LOCKED_MAM) { - if ( size > TC_MAM_LOCKED_MAM_SIZE) { + if (size > TC_MAM_LOCKED_MAM_SIZE) { ltfsmsg(LTFS_WARN, 17226W, "VOLLOCK", TC_MAM_LOCKED_MAM_SIZE); return -LTFS_LARGE_XATTR; } - if ( new_value ) { + if (new_value) { vol->t_attr->vollock = new_value[0]; } } else if (type == TC_MAM_MEDIA_POOL) { - if ( size > TC_MAM_MEDIA_POOL_SIZE) { + if (size > TC_MAM_MEDIA_POOL_SIZE) { ltfsmsg(LTFS_WARN, 17226W, "MEDIAPOOL", TC_MAM_MEDIA_POOL_SIZE); return -LTFS_LARGE_XATTR; } memset(vol->t_attr->media_pool, '\0', TC_MAM_MEDIA_POOL_SIZE + 1); - if ( new_value ) { + if (new_value) { arch_strncpy_auto(vol->t_attr->media_pool, new_value, size); } } ret = tape_set_attribute_to_cm(vol->device, vol->t_attr, type); if (ret < 0) { - if ( type == TC_MAM_USER_MEDIUM_LABEL ) { + if (type == TC_MAM_USER_MEDIUM_LABEL) { memset(vol->t_attr->medium_label, '\0', TC_MAM_USER_MEDIUM_LABEL_SIZE + 1); arch_strcpy_auto(vol->t_attr->medium_label, pre_attr); } else if (type == TC_MAM_BARCODE) { @@ -3528,8 +3443,7 @@ int update_tape_attribute(struct ltfs_volume *vol, const char *new_value, int ty } } - if (pre_attr) - free(pre_attr); + if (pre_attr) free(pre_attr); return ret; } @@ -3551,33 +3465,27 @@ int read_tape_attribute(struct ltfs_volume *vol, char **val, const char *name) CHECK_ARG_NULL(name, -LTFS_NULL_ARG); /* EA name check */ - if ( strcmp(name, "ltfs.mamBarcode") && strcmp(name, "ltfs.mamApplicationVendor") - && strcmp(name, "ltfs.mamApplicationVersion") && strcmp(name, "ltfs.mamApplicationFormatVersion") ) { + if (strcmp(name, "ltfs.mamBarcode") && strcmp(name, "ltfs.mamApplicationVendor") && + strcmp(name, "ltfs.mamApplicationVersion") && strcmp(name, "ltfs.mamApplicationFormatVersion")) { return -LTFS_UNEXPECTED_VALUE; } - if (!vol->t_attr) - return 0; + if (!vol->t_attr) return 0; - if (! strcmp(name, "ltfs.mamBarcode")) { - if (vol->t_attr->barcode[0] == '\0') - return 0; + if (!strcmp(name, "ltfs.mamBarcode")) { + if (vol->t_attr->barcode[0] == '\0') return 0; *val = arch_strdup(vol->t_attr->barcode); - } else if (! strcmp(name, "ltfs.mamApplicationVendor")) { - if (vol->t_attr->barcode[0] == '\0') - return 0; + } else if (!strcmp(name, "ltfs.mamApplicationVendor")) { + if (vol->t_attr->barcode[0] == '\0') return 0; *val = arch_strdup(vol->t_attr->vender); - } else if (! strcmp(name, "ltfs.mamApplicationVersion")) { - if (vol->t_attr->barcode[0] == '\0') - return 0; + } else if (!strcmp(name, "ltfs.mamApplicationVersion")) { + if (vol->t_attr->barcode[0] == '\0') return 0; *val = arch_strdup(vol->t_attr->app_ver); - } else if (! strcmp(name, "ltfs.mamApplicationFormatVersion")) { - if (vol->t_attr->barcode[0] == '\0') - return 0; + } else if (!strcmp(name, "ltfs.mamApplicationFormatVersion")) { + if (vol->t_attr->barcode[0] == '\0') return 0; *val = arch_strdup(vol->t_attr->app_format_ver); } else if (!strncmp(name, "ltfs.mediaPool", sizeof("ltfs.mediaPool"))) { - if (vol->t_attr->media_pool[0] == '\0') - return 0; + if (vol->t_attr->media_pool[0] == '\0') return 0; *val = arch_strdup(vol->t_attr->media_pool); } @@ -3597,8 +3505,7 @@ int read_tape_attribute(struct ltfs_volume *vol, char **val, const char *name) * @param size length of the buffer * @return attr length on success or a negative value on error. */ -int tape_read_attr(struct device_data *dev, const tape_partition_t part, - unsigned char *buf, const size_t size) +int tape_read_attr(struct device_data *dev, const tape_partition_t part, unsigned char *buf, const size_t size) { int ret; unsigned char *inner_buf = NULL; @@ -3608,13 +3515,9 @@ int tape_read_attr(struct device_data *dev, const tape_partition_t part, CHECK_ARG_NULL(dev->backend, -LTFS_NULL_ARG); inner_buf = calloc(1, MAXMAM_SIZE); /* Assume max length of MAM is 0xFFFF */ - if (!inner_buf) - return -LTFS_NO_MEMORY; + if (!inner_buf) return -LTFS_NO_MEMORY; - ret = dev->backend->read_attribute(dev->backend_data, part, - 0, - inner_buf, - MAXMAM_SIZE); + ret = dev->backend->read_attribute(dev->backend_data, part, 0, inner_buf, MAXMAM_SIZE); if (!ret) { len = ((int)inner_buf[2] << 8) + (int)inner_buf[3] + 4; @@ -3640,16 +3543,14 @@ int tape_read_attr(struct device_data *dev, const tape_partition_t part, * @return MEDIUM_ like MEDIUM_PERFECT_MATCH prefix enumerator on success, * negative value on error */ -int tape_is_mountable(struct device_data *dev, char *barcode, - unsigned char cart_type, unsigned char density) +int tape_is_mountable(struct device_data *dev, char *barcode, unsigned char cart_type, unsigned char density) { int ret = MEDIUM_CANNOT_ACCESS; CHECK_ARG_NULL(dev, -LTFS_NULL_ARG); CHECK_ARG_NULL(dev->backend, -LTFS_NULL_ARG); - ret = (*(dev->backend->is_mountable))(dev->backend_data, barcode, - cart_type, density); + ret = (*(dev->backend->is_mountable))(dev->backend_data, barcode, cart_type, density); return ret; } @@ -3669,8 +3570,7 @@ int tape_is_reformattable(struct device_data *dev, unsigned char cart_type, unsi CHECK_ARG_NULL(dev, -LTFS_NULL_ARG); CHECK_ARG_NULL(dev->backend, -LTFS_NULL_ARG); - ret = (*(dev->backend->is_mountable))(dev->backend_data, NULL, - cart_type, density); + ret = (*(dev->backend->is_mountable))(dev->backend_data, NULL, cart_type, density); return ret; } @@ -3705,7 +3605,7 @@ int tape_rao_request(struct device_data *dev, struct rao_mod *rao) /* run GRAO */ ret = dev->backend->grao(dev->backend_data, rao->in_buf, rao->in_size); if (ret < 0) { - ltfsmsg(LTFS_INFO, 17275I, "GRAO", ret); //GRAO command returns error + ltfsmsg(LTFS_INFO, 17275I, "GRAO", ret); //GRAO command returns error return ret; } diff --git a/src/libltfs/xattr.c b/src/libltfs/xattr.c index 0cd89575..54cfbffe 100644 --- a/src/libltfs/xattr.c +++ b/src/libltfs/xattr.c @@ -56,25 +56,25 @@ */ #ifdef mingw_PLATFORM -#include "arch/win/win_util.h" +# include "arch/win/win_util.h" #endif -#include "ltfs.h" -#include "ltfs_fsops.h" #include "xattr.h" +#include "arch/time_internal.h" #include "fs.h" -#include "xml_libltfs.h" +#include "ltfs.h" +#include "ltfs_fsops.h" +#include "ltfs_internal.h" #include "pathname.h" #include "tape.h" -#include "ltfs_internal.h" -#include "arch/time_internal.h" +#include "xml_libltfs.h" /* Helper functions for formatting virtual EA output */ -static int _xattr_get_cartridge_health(cartridge_health_info *h, int64_t *val, char **outval, - const char *msg, struct ltfs_volume *vol) +static int _xattr_get_cartridge_health( + cartridge_health_info *h, int64_t *val, char **outval, const char *msg, struct ltfs_volume *vol) { int ret = ltfs_get_cartridge_health(h, vol); if (ret == 0) { - ret = asprintf(outval, "%"PRId64, *val); + ret = asprintf(outval, "%" PRId64, *val); if (ret < 0) { ltfsmsg(LTFS_ERR, 10001E, msg); *outval = NULL; @@ -85,19 +85,19 @@ static int _xattr_get_cartridge_health(cartridge_health_info *h, int64_t *val, c return ret; } -static int _xattr_get_cartridge_health_u64(cartridge_health_info *h, uint64_t *val, char **outval, - const char *msg, struct ltfs_volume *vol) +static int _xattr_get_cartridge_health_u64( + cartridge_health_info *h, uint64_t *val, char **outval, const char *msg, struct ltfs_volume *vol) { int ret = ltfs_get_cartridge_health(h, vol); if (ret == 0 && (int64_t)(*val) != UNSUPPORTED_CARTRIDGE_HEALTH) { - ret = asprintf(outval, "%"PRIu64, *val); + ret = asprintf(outval, "%" PRIu64, *val); if (ret < 0) { ltfsmsg(LTFS_ERR, 10001E, msg); *outval = NULL; ret = -LTFS_NO_MEMORY; } } else if (ret == 0) { - ret = asprintf(outval, "%"PRId64, UNSUPPORTED_CARTRIDGE_HEALTH); + ret = asprintf(outval, "%" PRId64, UNSUPPORTED_CARTRIDGE_HEALTH); if (ret < 0) { ltfsmsg(LTFS_ERR, 10001E, msg); *outval = NULL; @@ -108,8 +108,8 @@ static int _xattr_get_cartridge_health_u64(cartridge_health_info *h, uint64_t *v return ret; } -static int _xattr_get_cartridge_capacity(struct device_capacity *cap, unsigned long *val, - char **outval, const char *msg, struct ltfs_volume *vol) +static int _xattr_get_cartridge_capacity( + struct device_capacity *cap, unsigned long *val, char **outval, const char *msg, struct ltfs_volume *vol) { double scale = vol->label->blocksize / 1048576.0; int ret = ltfs_capacity_data_unlocked(cap, vol); @@ -130,7 +130,7 @@ static int _xattr_get_time(struct ltfs_timespec *val, char **outval, const char int ret; ret = xml_format_time(*val, outval); - if (! (*outval)) { + if (!(*outval)) { ltfsmsg(LTFS_ERR, 11145E, msg); return -LTFS_NO_MEMORY; } @@ -138,8 +138,7 @@ static int _xattr_get_time(struct ltfs_timespec *val, char **outval, const char return ret; } -static int _xattr_get_dentry_time(struct dentry *d, struct ltfs_timespec *val, char **outval, - const char *msg) +static int _xattr_get_dentry_time(struct dentry *d, struct ltfs_timespec *val, char **outval, const char *msg) { int ret; acquireread_mrsw(&d->meta_lock); @@ -150,7 +149,7 @@ static int _xattr_get_dentry_time(struct dentry *d, struct ltfs_timespec *val, c static int _xattr_get_tapepos(struct tape_offset *val, char **outval, const char *msg) { - int ret = asprintf(outval, "%c:%"PRIu64, val->partition, val->block); + int ret = asprintf(outval, "%c:%" PRIu64, val->partition, val->block); if (ret < 0) { ltfsmsg(LTFS_ERR, 10001E, msg); return -LTFS_NO_MEMORY; @@ -173,12 +172,12 @@ static int _xattr_get_version(int version, char **outval, const char *msg) int ret; if (version == 10000) { *outval = arch_strdup("1.0"); - if (! (*outval)) { + if (!(*outval)) { ltfsmsg(LTFS_ERR, 10001E, msg); return -LTFS_NO_MEMORY; } } else { - ret = asprintf(outval, "%d.%d.%d", version/10000, (version % 10000)/100, version % 100); + ret = asprintf(outval, "%d.%d.%d", version / 10000, (version % 10000) / 100, version % 100); if (ret < 0) { ltfsmsg(LTFS_ERR, 10001E, msg); return -LTFS_NO_MEMORY; @@ -187,15 +186,19 @@ static int _xattr_get_version(int version, char **outval, const char *msg) return 0; } -static int _xattr_set_time(struct dentry *d, struct ltfs_timespec *out, const char *value, - size_t size, const char *msg, struct ltfs_volume *vol) +static int _xattr_set_time(struct dentry *d, + struct ltfs_timespec *out, + const char *value, + size_t size, + const char *msg, + struct ltfs_volume *vol) { int ret; struct ltfs_timespec t; char *value_null_terminated; value_null_terminated = malloc(size + 1); - if (! value_null_terminated) { + if (!value_null_terminated) { ltfsmsg(LTFS_ERR, 10001E, msg); return -LTFS_NO_MEMORY; } @@ -204,8 +207,7 @@ static int _xattr_set_time(struct dentry *d, struct ltfs_timespec *out, const ch ret = xml_parse_time(false, value_null_terminated, &t); free(value_null_terminated); - if (ret < 0) - return -LTFS_BAD_ARG; + if (ret < 0) return -LTFS_BAD_ARG; acquirewrite_mrsw(&d->meta_lock); *out = t; @@ -221,14 +223,12 @@ static int _xattr_get_vendorunique_xattr(char **outval, const char *msg, struct int ret; ret = ltfs_get_vendorunique_xattr(msg, outval, vol); - if (ret != 0) - *outval = NULL; + if (ret != 0) *outval = NULL; return ret; } -static int _xattr_set_vendorunique_xattr(const char *name, const char *value, size_t size, - struct ltfs_volume *vol) +static int _xattr_set_vendorunique_xattr(const char *name, const char *value, size_t size, struct ltfs_volume *vol) { int ret; @@ -265,11 +265,8 @@ static inline bool _xattr_is_worm_ea(const char *name) */ static inline bool _xattr_is_stored_vea(const char *name) { - if (strcmp(name, "ltfs.spannedFileOffset") && - strcmp(name, "ltfs.mediaPool.name") && - strcasestr(name, "ltfs.permissions.") != name && - strcasestr(name, "ltfs.hash.") != name) - { + if (strcmp(name, "ltfs.spannedFileOffset") && strcmp(name, "ltfs.mediaPool.name") && + strcasestr(name, "ltfs.permissions.") != name && strcasestr(name, "ltfs.hash.") != name) { return false; } @@ -291,8 +288,9 @@ static int _xattr_seek(struct xattr_info **out, struct dentry *d, const char *na struct xattr_info *entry; *out = NULL; - TAILQ_FOREACH(entry, &d->xattrlist, list) { - if (! strcmp(entry->key.name, name)) { + TAILQ_FOREACH(entry, &d->xattrlist, list) + { + if (!strcmp(entry->key.name, name)) { *out = entry; break; } @@ -315,8 +313,7 @@ static int _xattr_seek(struct xattr_info **out, struct dentry *d, const char *na static int _xattr_lock_dentry(const char *name, bool modify, struct dentry *d, struct ltfs_volume *vol) { /* EAs that read the extent list need to take the contents_lock */ - if (! strcmp(name, "ltfs.startblock") - || ! strcmp(name, "ltfs.partition")) { + if (!strcmp(name, "ltfs.startblock") || !strcmp(name, "ltfs.partition")) { acquireread_mrsw(&d->contents_lock); } @@ -335,8 +332,7 @@ static int _xattr_lock_dentry(const char *name, bool modify, struct dentry *d, s static void _xattr_unlock_dentry(const char *name, bool modify, struct dentry *d, struct ltfs_volume *vol) { /* EAs that read the extent list need to take the contents_lock */ - if (! strcmp(name, "ltfs.startblock") - || ! strcmp(name, "ltfs.partition")) { + if (!strcmp(name, "ltfs.startblock") || !strcmp(name, "ltfs.partition")) { releaseread_mrsw(&d->contents_lock); } } @@ -356,7 +352,7 @@ static int _xattr_list_physicals(struct dentry *d, char *list, size_t size) int prefixlen = 0, namelen; int ret = 0, nbytes = 0; -#if ((!defined (__APPLE__)) && (!defined (mingw_PLATFORM))) +#if ((!defined(__APPLE__)) && (!defined(mingw_PLATFORM))) ret = pathname_unformat("user.", &prefix); if (ret < 0) { ltfsmsg(LTFS_ERR, 11141E, ret); @@ -365,14 +361,15 @@ static int _xattr_list_physicals(struct dentry *d, char *list, size_t size) prefixlen = strlen(prefix); #endif /* (!defined (__APPLE__)) && (!defined (mingw_PLATFORM)) */ - TAILQ_FOREACH(entry, &d->xattrlist, list) { + TAILQ_FOREACH(entry, &d->xattrlist, list) + { ret = pathname_unformat(entry->key.name, &new_name); if (ret < 0) { ltfsmsg(LTFS_ERR, 11142E, ret); goto out; } - if(strncmp(new_name, LTFS_LIVELINK_EA_NAME, strlen(LTFS_LIVELINK_EA_NAME) + 1)) { + if (strncmp(new_name, LTFS_LIVELINK_EA_NAME, strlen(LTFS_LIVELINK_EA_NAME) + 1)) { namelen = strlen(new_name); nbytes += prefixlen + namelen + 1; @@ -387,11 +384,10 @@ static int _xattr_list_physicals(struct dentry *d, char *list, size_t size) } out: -#if ((!defined (__APPLE__)) && (!defined (mingw_PLATFORM))) +#if ((!defined(__APPLE__)) && (!defined(mingw_PLATFORM))) free(prefix); #endif /* (!defined (__APPLE__)) && (!defined (mingw_PLATFORM)) */ - if (ret < 0) - return ret; + if (ret < 0) return ret; return nbytes; } @@ -405,25 +401,14 @@ static int _xattr_list_physicals(struct dentry *d, char *list, size_t size) static bool _xattr_is_virtual(struct dentry *d, const char *name, struct ltfs_volume *vol) { /* xattrs on all dentries */ - if (! strcmp(name, "ltfs.createTime") - || ! strcmp(name, "ltfs.modifyTime") - || ! strcmp(name, "ltfs.accessTime") - || ! strcmp(name, "ltfs.changeTime") - || ! strcmp(name, "ltfs.backupTime") - || ! strcmp(name, "ltfs.fileUID") - || ! strcmp(name, "ltfs.volumeUUID") - || ! strcmp(name, "ltfs.volumeName") - || ! strcmp(name, "ltfs.driveCaptureDump") - || ! strcmp(name, "ltfs.softwareVersion") - || ! strcmp(name, "ltfs.softwareFormatSpec") - || ! strcmp(name, "ltfs.softwareVendor") - || ! strcmp(name, "ltfs.softwareProduct") - || ! strcmp(name, "ltfs.mamBarcode") - || ! strcmp(name, "ltfs.mamApplicationVendor") - || ! strcmp(name, "ltfs.mamApplicationVersion") - || ! strcmp(name, "ltfs.mamApplicationFormatVersion") - || ! strcmp(name, "ltfs.volumeLockState") - ) + if (!strcmp(name, "ltfs.createTime") || !strcmp(name, "ltfs.modifyTime") || !strcmp(name, "ltfs.accessTime") || + !strcmp(name, "ltfs.changeTime") || !strcmp(name, "ltfs.backupTime") || !strcmp(name, "ltfs.fileUID") || + !strcmp(name, "ltfs.volumeUUID") || !strcmp(name, "ltfs.volumeName") || !strcmp(name, "ltfs.driveCaptureDump") || + !strcmp(name, "ltfs.softwareVersion") || !strcmp(name, "ltfs.softwareFormatSpec") || + !strcmp(name, "ltfs.softwareVendor") || !strcmp(name, "ltfs.softwareProduct") || + !strcmp(name, "ltfs.mamBarcode") || !strcmp(name, "ltfs.mamApplicationVendor") || + !strcmp(name, "ltfs.mamApplicationVersion") || !strcmp(name, "ltfs.mamApplicationFormatVersion") || + !strcmp(name, "ltfs.volumeLockState")) return true; if (_xattr_is_worm_ea(name)) { @@ -432,67 +417,41 @@ static bool _xattr_is_virtual(struct dentry *d, const char *name, struct ltfs_vo } /* xattrs on files */ - if (! d->isdir) { - if (! TAILQ_EMPTY(&d->extentlist) - && (! strcmp(name, "ltfs.partition") || ! strcmp(name, "ltfs.startblock"))) + if (!d->isdir) { + if (!TAILQ_EMPTY(&d->extentlist) && (!strcmp(name, "ltfs.partition") || !strcmp(name, "ltfs.startblock"))) return true; } /* xattrs on the root dentry */ if (d == vol->index->root) { - if (vol->index->index_criteria.have_criteria && ! strcmp(name, "ltfs.policyMaxFileSize")) - return true; - if (! strcmp(name, "ltfs.commitMessage") - || ! strcmp(name, "ltfs.indexVersion") - || ! strcmp(name, "ltfs.labelVersion") - || ! strcmp(name, "ltfs.sync") - || ! strcmp(name, "ltfs.indexGeneration") - || ! strcmp(name, "ltfs.indexTime") - || ! strcmp(name, "ltfs.policyExists") - || ! strcmp(name, "ltfs.policyAllowUpdate") - || ! strcmp(name, "ltfs.volumeFormatTime") - || ! strcmp(name, "ltfs.volumeBlocksize") - || ! strcmp(name, "ltfs.volumeCompression") - || ! strcmp(name, "ltfs.indexLocation") - || ! strcmp(name, "ltfs.indexPrevious") - || ! strcmp(name, "ltfs.indexCreator") - || ! strcmp(name, "ltfs.labelCreator") - || ! strcmp(name, "ltfs.partitionMap") - || ! strcmp(name, "ltfs.volumeSerial") - || ! strcmp(name, "ltfs.mediaLoads") - || ! strcmp(name, "ltfs.mediaRecoveredWriteErrors") - || ! strcmp(name, "ltfs.mediaPermanentWriteErrors") - || ! strcmp(name, "ltfs.mediaRecoveredReadErrors") - || ! strcmp(name, "ltfs.mediaPermanentReadErrors") - || ! strcmp(name, "ltfs.mediaPreviousPermanentWriteErrors") - || ! strcmp(name, "ltfs.mediaPreviousPermanentReadErrors") - || ! strcmp(name, "ltfs.mediaBeginningMediumPasses") - || ! strcmp(name, "ltfs.mediaMiddleMediumPasses") - || ! strcmp(name, "ltfs.mediaEfficiency") - || ! strcmp(name, "ltfs.mediaStorageAlert") - || ! strcmp(name, "ltfs.mediaDatasetsWritten") - || ! strcmp(name, "ltfs.mediaDatasetsRead") - || ! strcmp(name, "ltfs.mediaMBWritten") - || ! strcmp(name, "ltfs.mediaMBRead") - || ! strcmp(name, "ltfs.mediaDataPartitionTotalCapacity") - || ! strcmp(name, "ltfs.mediaDataPartitionAvailableSpace") - || ! strcmp(name, "ltfs.mediaIndexPartitionTotalCapacity") - || ! strcmp(name, "ltfs.mediaIndexPartitionAvailableSpace") - || ! strcmp(name, "ltfs.mediaEncrypted") - || ! strcmp(name, "ltfs.mediaPool.additionalInfo") - || ! strcmp(name, "ltfs.driveEncryptionState") - || ! strcmp(name, "ltfs.driveEncryptionMethod") - /* Vendor specific EAs */ - || ! strcmp(name, "ltfs.vendor.IBM.referencedBlocks") - || ! strcmp(name, "ltfs.vendor.IBM.trace") - || ! strcmp(name, "ltfs.vendor.IBM.totalBlocks") - || ! strcmp(name, "ltfs.vendor.IBM.cartridgeMountNode") - || ! strcmp(name, "ltfs.vendor.IBM.logLevel") - || ! strcmp(name, "ltfs.vendor.IBM.syslogLevel") - || ! strcmp(name, "ltfs.vendor.IBM.rao") - || ! strcmp(name, "ltfs.vendor.IBM.logPage") - || ! strcmp(name, "ltfs.vendor.IBM.mediaMAM") - || ! strncmp(name, "ltfs.vendor", strlen("ltfs.vendor"))) + if (vol->index->index_criteria.have_criteria && !strcmp(name, "ltfs.policyMaxFileSize")) return true; + if (!strcmp(name, "ltfs.commitMessage") || !strcmp(name, "ltfs.indexVersion") || + !strcmp(name, "ltfs.labelVersion") || !strcmp(name, "ltfs.sync") || !strcmp(name, "ltfs.indexGeneration") || + !strcmp(name, "ltfs.indexTime") || !strcmp(name, "ltfs.policyExists") || + !strcmp(name, "ltfs.policyAllowUpdate") || !strcmp(name, "ltfs.volumeFormatTime") || + !strcmp(name, "ltfs.volumeBlocksize") || !strcmp(name, "ltfs.volumeCompression") || + !strcmp(name, "ltfs.indexLocation") || !strcmp(name, "ltfs.indexPrevious") || + !strcmp(name, "ltfs.indexCreator") || !strcmp(name, "ltfs.labelCreator") || + !strcmp(name, "ltfs.partitionMap") || !strcmp(name, "ltfs.volumeSerial") || !strcmp(name, "ltfs.mediaLoads") || + !strcmp(name, "ltfs.mediaRecoveredWriteErrors") || !strcmp(name, "ltfs.mediaPermanentWriteErrors") || + !strcmp(name, "ltfs.mediaRecoveredReadErrors") || !strcmp(name, "ltfs.mediaPermanentReadErrors") || + !strcmp(name, "ltfs.mediaPreviousPermanentWriteErrors") || + !strcmp(name, "ltfs.mediaPreviousPermanentReadErrors") || !strcmp(name, "ltfs.mediaBeginningMediumPasses") || + !strcmp(name, "ltfs.mediaMiddleMediumPasses") || !strcmp(name, "ltfs.mediaEfficiency") || + !strcmp(name, "ltfs.mediaStorageAlert") || !strcmp(name, "ltfs.mediaDatasetsWritten") || + !strcmp(name, "ltfs.mediaDatasetsRead") || !strcmp(name, "ltfs.mediaMBWritten") || + !strcmp(name, "ltfs.mediaMBRead") || !strcmp(name, "ltfs.mediaDataPartitionTotalCapacity") || + !strcmp(name, "ltfs.mediaDataPartitionAvailableSpace") || + !strcmp(name, "ltfs.mediaIndexPartitionTotalCapacity") || + !strcmp(name, "ltfs.mediaIndexPartitionAvailableSpace") || !strcmp(name, "ltfs.mediaEncrypted") || + !strcmp(name, "ltfs.mediaPool.additionalInfo") || !strcmp(name, "ltfs.driveEncryptionState") || + !strcmp(name, "ltfs.driveEncryptionMethod") + /* Vendor specific EAs */ + || !strcmp(name, "ltfs.vendor.IBM.referencedBlocks") || !strcmp(name, "ltfs.vendor.IBM.trace") || + !strcmp(name, "ltfs.vendor.IBM.totalBlocks") || !strcmp(name, "ltfs.vendor.IBM.cartridgeMountNode") || + !strcmp(name, "ltfs.vendor.IBM.logLevel") || !strcmp(name, "ltfs.vendor.IBM.syslogLevel") || + !strcmp(name, "ltfs.vendor.IBM.rao") || !strcmp(name, "ltfs.vendor.IBM.logPage") || + !strcmp(name, "ltfs.vendor.IBM.mediaMAM") || !strncmp(name, "ltfs.vendor", strlen("ltfs.vendor"))) return true; } @@ -510,132 +469,131 @@ static bool _xattr_is_virtual(struct dentry *d, const char *name, struct ltfs_vo * -LTFS_NO_XATTR if no such readable virtual xattr exists, * -LTFS_RDONLY_XATTR for write-only virtual EAs, or another negative value on error. */ -static int _xattr_get_virtual(struct dentry *d, char *buf, size_t buf_size, const char *name, - struct ltfs_volume *vol) +static int _xattr_get_virtual(struct dentry *d, char *buf, size_t buf_size, const char *name, struct ltfs_volume *vol) { int ret = -LTFS_NO_XATTR; char *val = NULL; struct index_criteria *ic = &vol->index->index_criteria; cartridge_health_info h = { - .mounts = UNSUPPORTED_CARTRIDGE_HEALTH, - .written_ds = UNSUPPORTED_CARTRIDGE_HEALTH, - .write_temps = UNSUPPORTED_CARTRIDGE_HEALTH, - .write_perms = UNSUPPORTED_CARTRIDGE_HEALTH, - .read_ds = UNSUPPORTED_CARTRIDGE_HEALTH, - .read_temps = UNSUPPORTED_CARTRIDGE_HEALTH, - .read_perms = UNSUPPORTED_CARTRIDGE_HEALTH, + .mounts = UNSUPPORTED_CARTRIDGE_HEALTH, + .written_ds = UNSUPPORTED_CARTRIDGE_HEALTH, + .write_temps = UNSUPPORTED_CARTRIDGE_HEALTH, + .write_perms = UNSUPPORTED_CARTRIDGE_HEALTH, + .read_ds = UNSUPPORTED_CARTRIDGE_HEALTH, + .read_temps = UNSUPPORTED_CARTRIDGE_HEALTH, + .read_perms = UNSUPPORTED_CARTRIDGE_HEALTH, .write_perms_prev = UNSUPPORTED_CARTRIDGE_HEALTH, - .read_perms_prev = UNSUPPORTED_CARTRIDGE_HEALTH, - .written_mbytes = UNSUPPORTED_CARTRIDGE_HEALTH, - .read_mbytes = UNSUPPORTED_CARTRIDGE_HEALTH, - .passes_begin = UNSUPPORTED_CARTRIDGE_HEALTH, - .passes_middle = UNSUPPORTED_CARTRIDGE_HEALTH, - .tape_efficiency = UNSUPPORTED_CARTRIDGE_HEALTH, + .read_perms_prev = UNSUPPORTED_CARTRIDGE_HEALTH, + .written_mbytes = UNSUPPORTED_CARTRIDGE_HEALTH, + .read_mbytes = UNSUPPORTED_CARTRIDGE_HEALTH, + .passes_begin = UNSUPPORTED_CARTRIDGE_HEALTH, + .passes_middle = UNSUPPORTED_CARTRIDGE_HEALTH, + .tape_efficiency = UNSUPPORTED_CARTRIDGE_HEALTH, }; uint64_t tape_alert = 0; uint64_t append_pos = 0; struct device_capacity cap; /* EAs on all dentries */ - if (! strcmp(name, "ltfs.createTime")) { + if (!strcmp(name, "ltfs.createTime")) { ret = _xattr_get_dentry_time(d, &d->creation_time, &val, name); if (ret == LTFS_TIME_OUT_OF_RANGE) { ltfsmsg(LTFS_WARN, 17222W, name, d->name.name, (unsigned long long)d->uid, (long long)d->creation_time.tv_sec); ret = 0; } - } else if (! strcmp(name, "ltfs.modifyTime")) { + } else if (!strcmp(name, "ltfs.modifyTime")) { ret = _xattr_get_dentry_time(d, &d->modify_time, &val, name); if (ret == LTFS_TIME_OUT_OF_RANGE) { ltfsmsg(LTFS_WARN, 17222W, name, d->name.name, (unsigned long long)d->uid, (long long)d->modify_time.tv_sec); ret = 0; } - } else if (! strcmp(name, "ltfs.accessTime")) { + } else if (!strcmp(name, "ltfs.accessTime")) { ret = _xattr_get_dentry_time(d, &d->access_time, &val, name); if (ret == LTFS_TIME_OUT_OF_RANGE) { ltfsmsg(LTFS_WARN, 17222W, name, d->name.name, (unsigned long long)d->uid, (long long)d->access_time.tv_sec); ret = 0; } - } else if (! strcmp(name, "ltfs.changeTime")) { + } else if (!strcmp(name, "ltfs.changeTime")) { ret = _xattr_get_dentry_time(d, &d->change_time, &val, name); if (ret == LTFS_TIME_OUT_OF_RANGE) { ltfsmsg(LTFS_WARN, 17222W, name, d->name.name, (unsigned long long)d->uid, (long long)d->change_time.tv_sec); ret = 0; } - } else if (! strcmp(name, "ltfs.backupTime")) { + } else if (!strcmp(name, "ltfs.backupTime")) { ret = _xattr_get_dentry_time(d, &d->backup_time, &val, name); if (ret == LTFS_TIME_OUT_OF_RANGE) { ltfsmsg(LTFS_WARN, 17222W, name, d->name.name, (unsigned long long)d->uid, (long long)d->backup_time.tv_sec); ret = 0; } - } else if (! strcmp(name, "ltfs.driveCaptureDump")) { + } else if (!strcmp(name, "ltfs.driveCaptureDump")) { ret = tape_takedump_drive(vol->device, true); - } else if (! strcmp(name, "ltfs.fileUID")) { + } else if (!strcmp(name, "ltfs.fileUID")) { ret = xattr_get_u64(d->uid, &val, name); - } else if (! strcmp(name, "ltfs.volumeUUID")) { + } else if (!strcmp(name, "ltfs.volumeUUID")) { ret = xattr_get_string(vol->label->vol_uuid, &val, name); - } else if (! strcmp(name, "ltfs.volumeName")) { + } else if (!strcmp(name, "ltfs.volumeName")) { ltfs_mutex_lock(&vol->index->dirty_lock); ret = xattr_get_string(vol->index->volume_name.name, &val, name); ltfs_mutex_unlock(&vol->index->dirty_lock); - } else if (! strcmp(name, "ltfs.softwareVersion")) { + } else if (!strcmp(name, "ltfs.softwareVersion")) { ret = xattr_get_string(PACKAGE_VERSION, &val, name); - } else if (! strcmp(name, "ltfs.softwareFormatSpec")) { + } else if (!strcmp(name, "ltfs.softwareFormatSpec")) { ret = xattr_get_string(LTFS_INDEX_VERSION_STR, &val, name); - } else if (! strcmp(name, "ltfs.softwareVendor")) { + } else if (!strcmp(name, "ltfs.softwareVendor")) { ret = xattr_get_string(LTFS_VENDOR_NAME, &val, name); - } else if (! strcmp(name, "ltfs.softwareProduct")) { - if ( strncmp( PACKAGE_VERSION, "1", 1 )==0 ) + } else if (!strcmp(name, "ltfs.softwareProduct")) { + if (strncmp(PACKAGE_VERSION, "1", 1) == 0) ret = xattr_get_string("LTFS SDE", &val, name); - else if ( strncmp( PACKAGE_VERSION, "2", 1 )==0 ) + else if (strncmp(PACKAGE_VERSION, "2", 1) == 0) ret = xattr_get_string("LTFS LE", &val, name); else ret = -LTFS_NO_XATTR; - } else if (! strcmp(name, "ltfs.vendor.IBM.logLevel")) { + } else if (!strcmp(name, "ltfs.vendor.IBM.logLevel")) { ret = asprintf(&val, "%d", ltfs_log_level); if (ret < 0) { ltfsmsg(LTFS_ERR, 10001E, name); val = NULL; ret = -LTFS_NO_MEMORY; } - } else if (! strcmp(name, "ltfs.vendor.IBM.syslogLevel")) { + } else if (!strcmp(name, "ltfs.vendor.IBM.syslogLevel")) { ret = asprintf(&val, "%d", ltfs_syslog_level); if (ret < 0) { ltfsmsg(LTFS_ERR, 10001E, name); val = NULL; ret = -LTFS_NO_MEMORY; } - } else if (! strcmp(name, "ltfs.vendor.IBM.profiler")) { + } else if (!strcmp(name, "ltfs.vendor.IBM.profiler")) { ret = ltfs_trace_get_offset(&val); if (ret < 0) { ltfsmsg(LTFS_ERR, 10001E, name); val = NULL; ret = -LTFS_NO_MEMORY; } - } else if (! strcmp(name, "ltfs.mamBarcode")) { - ret = read_tape_attribute (vol, &val, name); + } else if (!strcmp(name, "ltfs.mamBarcode")) { + ret = read_tape_attribute(vol, &val, name); if (ret < 0) { ltfsmsg(LTFS_DEBUG, 17198D, TC_MAM_BARCODE, "_xattr_get_virtual"); val = NULL; } - } else if (! strcmp(name, "ltfs.mamApplicationVendor")) { - ret = read_tape_attribute (vol, &val, name); + } else if (!strcmp(name, "ltfs.mamApplicationVendor")) { + ret = read_tape_attribute(vol, &val, name); if (ret < 0) { ltfsmsg(LTFS_DEBUG, 17198D, TC_MAM_APP_VENDER, "_xattr_get_virtual"); val = NULL; } - } else if (! strcmp(name, "ltfs.mamApplicationVersion")) { - ret = read_tape_attribute (vol, &val, name); + } else if (!strcmp(name, "ltfs.mamApplicationVersion")) { + ret = read_tape_attribute(vol, &val, name); if (ret < 0) { ltfsmsg(LTFS_DEBUG, 17198D, TC_MAM_APP_VERSION, "_xattr_get_virtual"); val = NULL; } - } else if (! strcmp(name, "ltfs.mamApplicationFormatVersion")) { - ret = read_tape_attribute (vol, &val, name); + } else if (!strcmp(name, "ltfs.mamApplicationFormatVersion")) { + ret = read_tape_attribute(vol, &val, name); if (ret < 0) { ltfsmsg(LTFS_DEBUG, 17198D, TC_MAM_APP_FORMAT_VERSION, "_xattr_get_virtual"); val = NULL; } - } else if (! strcmp(name, "ltfs.volumeLockState")) { + } else if (!strcmp(name, "ltfs.volumeLockState")) { if (vol->device) { unsigned int lock = 0; switch (vol->lock_status) { @@ -672,159 +630,159 @@ static int _xattr_get_virtual(struct dentry *d, char *buf, size_t buf_size, cons } /* EAs on non-empty files */ - if (ret == -LTFS_NO_XATTR && ! d->isdir && ! TAILQ_EMPTY(&d->extentlist)) { - if (! strcmp(name, "ltfs.partition")) { + if (ret == -LTFS_NO_XATTR && !d->isdir && !TAILQ_EMPTY(&d->extentlist)) { + if (!strcmp(name, "ltfs.partition")) { ret = 0; val = malloc(2 * sizeof(char)); - if (! val) { + if (!val) { ltfsmsg(LTFS_ERR, 10001E, name); ret = -LTFS_NO_MEMORY; } else { val[0] = TAILQ_FIRST(&d->extentlist)->start.partition; val[1] = '\0'; } - } else if (! strcmp(name, "ltfs.startblock")) { + } else if (!strcmp(name, "ltfs.startblock")) { ret = xattr_get_u64(TAILQ_FIRST(&d->extentlist)->start.block, &val, name); } } /* EAs on root dentry */ if (ret == -LTFS_NO_XATTR && d == vol->index->root) { - if (! strcmp(name, "ltfs.commitMessage")) { + if (!strcmp(name, "ltfs.commitMessage")) { ltfs_mutex_lock(&vol->index->dirty_lock); ret = xattr_get_string(vol->index->commit_message, &val, name); ltfs_mutex_unlock(&vol->index->dirty_lock); - } else if (! strcmp(name, "ltfs.volumeSerial")) { + } else if (!strcmp(name, "ltfs.volumeSerial")) { ret = xattr_get_string(vol->label->barcode, &val, name); - } else if (! strcmp(name, "ltfs.volumeFormatTime")) { + } else if (!strcmp(name, "ltfs.volumeFormatTime")) { ret = _xattr_get_time(&vol->label->format_time, &val, name); if (ret == LTFS_TIME_OUT_OF_RANGE) { - ltfsmsg(LTFS_WARN, 17222W, name, "root", (unsigned long long)0, (unsigned long long)vol->label->format_time.tv_sec); + ltfsmsg( + LTFS_WARN, 17222W, name, "root", (unsigned long long)0, (unsigned long long)vol->label->format_time.tv_sec); ret = 0; } - } else if (! strcmp(name, "ltfs.volumeBlocksize")) { + } else if (!strcmp(name, "ltfs.volumeBlocksize")) { ret = xattr_get_u64(vol->label->blocksize, &val, name); - } else if (! strcmp(name, "ltfs.indexGeneration")) { + } else if (!strcmp(name, "ltfs.indexGeneration")) { ret = xattr_get_u64(vol->index->generation, &val, name); - } else if (! strcmp(name, "ltfs.indexTime")) { + } else if (!strcmp(name, "ltfs.indexTime")) { ret = _xattr_get_time(&vol->index->mod_time, &val, name); if (ret == LTFS_TIME_OUT_OF_RANGE) { - ltfsmsg(LTFS_WARN, 17222W, name, "root", (unsigned long long)0, (unsigned long long)vol->label->format_time.tv_sec); + ltfsmsg( + LTFS_WARN, 17222W, name, "root", (unsigned long long)0, (unsigned long long)vol->label->format_time.tv_sec); ret = 0; } - } else if (! strcmp(name, "ltfs.policyExists")) { + } else if (!strcmp(name, "ltfs.policyExists")) { ret = xattr_get_string(ic->have_criteria ? "true" : "false", &val, name); - } else if (! strcmp(name, "ltfs.policyAllowUpdate")) { - ret = xattr_get_string(vol->index->criteria_allow_update ? "true" : "false", - &val, name); - } else if (! strcmp(name, "ltfs.policyMaxFileSize") && ic->have_criteria) { + } else if (!strcmp(name, "ltfs.policyAllowUpdate")) { + ret = xattr_get_string(vol->index->criteria_allow_update ? "true" : "false", &val, name); + } else if (!strcmp(name, "ltfs.policyMaxFileSize") && ic->have_criteria) { ret = xattr_get_u64(ic->max_filesize_criteria, &val, name); - } else if (! strcmp(name, "ltfs.volumeCompression")) { + } else if (!strcmp(name, "ltfs.volumeCompression")) { ret = xattr_get_string(vol->label->enable_compression ? "true" : "false", &val, name); - } else if (! strcmp(name, "ltfs.indexLocation")) { + } else if (!strcmp(name, "ltfs.indexLocation")) { ret = _xattr_get_tapepos(&vol->index->selfptr, &val, name); - } else if (! strcmp(name, "ltfs.indexPrevious")) { + } else if (!strcmp(name, "ltfs.indexPrevious")) { ret = _xattr_get_tapepos(&vol->index->backptr, &val, name); - } else if (! strcmp(name, "ltfs.indexCreator")) { + } else if (!strcmp(name, "ltfs.indexCreator")) { ret = xattr_get_string(vol->index->creator, &val, name); - } else if (! strcmp(name, "ltfs.labelCreator")) { + } else if (!strcmp(name, "ltfs.labelCreator")) { ret = xattr_get_string(vol->label->creator, &val, name); - } else if (! strcmp(name, "ltfs.indexVersion")) { + } else if (!strcmp(name, "ltfs.indexVersion")) { ltfs_mutex_lock(&vol->index->dirty_lock); ret = _xattr_get_version(vol->index->version, &val, name); ltfs_mutex_unlock(&vol->index->dirty_lock); - } else if (! strcmp(name, "ltfs.labelVersion")) { + } else if (!strcmp(name, "ltfs.labelVersion")) { ret = _xattr_get_version(vol->label->version, &val, name); - } else if (! strcmp(name, "ltfs.partitionMap")) { + } else if (!strcmp(name, "ltfs.partitionMap")) { ret = _xattr_get_partmap(vol->label, &val, name); - } else if (! strcmp(name, "ltfs.mediaLoads")) { + } else if (!strcmp(name, "ltfs.mediaLoads")) { ret = _xattr_get_cartridge_health(&h, &h.mounts, &val, name, vol); - } else if (! strcmp(name, "ltfs.mediaRecoveredWriteErrors")) { + } else if (!strcmp(name, "ltfs.mediaRecoveredWriteErrors")) { ret = _xattr_get_cartridge_health(&h, &h.write_temps, &val, name, vol); - } else if (! strcmp(name, "ltfs.mediaPermanentWriteErrors")) { + } else if (!strcmp(name, "ltfs.mediaPermanentWriteErrors")) { ret = _xattr_get_cartridge_health(&h, &h.write_perms, &val, name, vol); - } else if (! strcmp(name, "ltfs.mediaRecoveredReadErrors")) { + } else if (!strcmp(name, "ltfs.mediaRecoveredReadErrors")) { ret = _xattr_get_cartridge_health(&h, &h.read_temps, &val, name, vol); - } else if (! strcmp(name, "ltfs.mediaPermanentReadErrors")) { + } else if (!strcmp(name, "ltfs.mediaPermanentReadErrors")) { ret = _xattr_get_cartridge_health(&h, &h.read_perms, &val, name, vol); - } else if (! strcmp(name, "ltfs.mediaPreviousPermanentWriteErrors")) { + } else if (!strcmp(name, "ltfs.mediaPreviousPermanentWriteErrors")) { ret = _xattr_get_cartridge_health(&h, &h.write_perms_prev, &val, name, vol); - } else if (! strcmp(name, "ltfs.mediaPreviousPermanentReadErrors")) { + } else if (!strcmp(name, "ltfs.mediaPreviousPermanentReadErrors")) { ret = _xattr_get_cartridge_health(&h, &h.read_perms_prev, &val, name, vol); - } else if (! strcmp(name, "ltfs.mediaBeginningMediumPasses")) { + } else if (!strcmp(name, "ltfs.mediaBeginningMediumPasses")) { ret = _xattr_get_cartridge_health(&h, &h.passes_begin, &val, name, vol); - } else if (! strcmp(name, "ltfs.mediaMiddleMediumPasses")) { + } else if (!strcmp(name, "ltfs.mediaMiddleMediumPasses")) { ret = _xattr_get_cartridge_health(&h, &h.passes_middle, &val, name, vol); - } else if (! strcmp(name, "ltfs.mediaEfficiency")) { + } else if (!strcmp(name, "ltfs.mediaEfficiency")) { ret = _xattr_get_cartridge_health(&h, &h.tape_efficiency, &val, name, vol); - } else if (! strcmp(name, "ltfs.mediaDatasetsWritten")) { + } else if (!strcmp(name, "ltfs.mediaDatasetsWritten")) { ret = _xattr_get_cartridge_health_u64(&h, &h.written_ds, &val, name, vol); - } else if (! strcmp(name, "ltfs.mediaDatasetsRead")) { + } else if (!strcmp(name, "ltfs.mediaDatasetsRead")) { ret = _xattr_get_cartridge_health_u64(&h, &h.read_ds, &val, name, vol); - } else if (! strcmp(name, "ltfs.mediaMBWritten")) { + } else if (!strcmp(name, "ltfs.mediaMBWritten")) { ret = _xattr_get_cartridge_health_u64(&h, &h.written_mbytes, &val, name, vol); - } else if (! strcmp(name, "ltfs.mediaMBRead")) { + } else if (!strcmp(name, "ltfs.mediaMBRead")) { ret = _xattr_get_cartridge_health_u64(&h, &h.read_mbytes, &val, name, vol); - } else if (! strcmp(name, "ltfs.mediaStorageAlert")) { + } else if (!strcmp(name, "ltfs.mediaStorageAlert")) { ret = ltfs_get_tape_alert_unlocked(&tape_alert, vol); if (ret < 0) val = NULL; else { - ret = asprintf(&val, "0x%016"PRIx64, tape_alert); + ret = asprintf(&val, "0x%016" PRIx64, tape_alert); if (ret < 0) { ltfsmsg(LTFS_ERR, 10001E, name); val = NULL; ret = -LTFS_NO_MEMORY; } } - } else if (! strcmp(name, "ltfs.mediaDataPartitionTotalCapacity")) { + } else if (!strcmp(name, "ltfs.mediaDataPartitionTotalCapacity")) { ret = _xattr_get_cartridge_capacity(&cap, &cap.total_dp, &val, name, vol); - } else if (! strcmp(name, "ltfs.mediaDataPartitionAvailableSpace")) { + } else if (!strcmp(name, "ltfs.mediaDataPartitionAvailableSpace")) { ret = _xattr_get_cartridge_capacity(&cap, &cap.remaining_dp, &val, name, vol); - } else if (! strcmp(name, "ltfs.mediaIndexPartitionTotalCapacity")) { + } else if (!strcmp(name, "ltfs.mediaIndexPartitionTotalCapacity")) { ret = _xattr_get_cartridge_capacity(&cap, &cap.total_ip, &val, name, vol); - } else if (! strcmp(name, "ltfs.mediaIndexPartitionAvailableSpace")) { + } else if (!strcmp(name, "ltfs.mediaIndexPartitionAvailableSpace")) { ret = _xattr_get_cartridge_capacity(&cap, &cap.remaining_ip, &val, name, vol); - } else if (! strcmp(name, "ltfs.mediaEncrypted")) { + } else if (!strcmp(name, "ltfs.mediaEncrypted")) { ret = xattr_get_string(tape_get_media_encrypted(vol->device), &val, name); - } else if (! strcmp(name, "ltfs.mediaPool.additionalInfo")) { - char *tmp=NULL; + } else if (!strcmp(name, "ltfs.mediaPool.additionalInfo")) { + char *tmp = NULL; ret = tape_get_media_pool_info(vol, &tmp, &val); - if (ret < 0 || !val) - ret = -LTFS_NO_XATTR; - } else if (! strcmp(name, "ltfs.driveEncryptionState")) { + if (ret < 0 || !val) ret = -LTFS_NO_XATTR; + } else if (!strcmp(name, "ltfs.driveEncryptionState")) { ret = xattr_get_string(tape_get_drive_encryption_state(vol->device), &val, name); - } else if (! strcmp(name, "ltfs.driveEncryptionMethod")) { + } else if (!strcmp(name, "ltfs.driveEncryptionMethod")) { ret = xattr_get_string(tape_get_drive_encryption_method(vol->device), &val, name); - } else if (! strcmp(name, "ltfs.vendor.IBM.referencedBlocks")) { + } else if (!strcmp(name, "ltfs.vendor.IBM.referencedBlocks")) { ret = xattr_get_u64(ltfs_get_valid_block_count_unlocked(vol), &val, name); - } else if (! strcmp(name, "ltfs.vendor.IBM.trace")) { + } else if (!strcmp(name, "ltfs.vendor.IBM.trace")) { ret = ltfs_get_trace_status(&val); - } else if (! strcmp(name, "ltfs.vendor.IBM.totalBlocks")) { + } else if (!strcmp(name, "ltfs.vendor.IBM.totalBlocks")) { ret = ltfs_get_append_position(&append_pos, vol); if (ret < 0) val = NULL; else ret = xattr_get_u64(append_pos, &val, name); - } else if (! strcmp(name, "ltfs.vendor.IBM.cartridgeMountNode")) { + } else if (!strcmp(name, "ltfs.vendor.IBM.cartridgeMountNode")) { ret = asprintf(&val, "localhost"); if (ret < 0) { ltfsmsg(LTFS_ERR, 10001E, name); val = NULL; ret = -LTFS_NO_MEMORY; } - } else if ( (!strncmp(name, "ltfs.vendor.IBM.logPage.", strlen("ltfs.vendor.IBM.logPage."))) && - (strlen(name) == strlen("ltfs.vendor.IBM.logPage.XX.XX")) ) { - char page_str[3] = {0x00, 0x00, 0x00}; - char subpage_str[3] = {0x00, 0x00, 0x00}; + } else if ((!strncmp(name, "ltfs.vendor.IBM.logPage.", strlen("ltfs.vendor.IBM.logPage."))) && + (strlen(name) == strlen("ltfs.vendor.IBM.logPage.XX.XX"))) { + char page_str[3] = { 0x00, 0x00, 0x00 }; + char subpage_str[3] = { 0x00, 0x00, 0x00 }; - uint8_t page = 0xFF; + uint8_t page = 0xFF; uint8_t subpage = 0xFF; char *endptr = NULL; - page_str[0] = name[24]; - page_str[1] = name[25]; + page_str[0] = name[24]; + page_str[1] = name[25]; subpage_str[0] = name[27]; subpage_str[1] = name[28]; @@ -836,9 +794,9 @@ static int _xattr_get_virtual(struct dentry *d, char *buf, size_t buf_size, cons ret = ltfs_logpage(page, subpage, (unsigned char *)buf, buf_size, vol); - } else if ( (!strncmp(name, "ltfs.vendor.IBM.mediaMAM.", strlen("ltfs.vendor.IBM.mediaMAM."))) && - (strlen(name) == strlen("ltfs.vendor.IBM.mediaMAM.XX")) ) { - char part_str[3] = {0x00, 0x00, 0x00}; + } else if ((!strncmp(name, "ltfs.vendor.IBM.mediaMAM.", strlen("ltfs.vendor.IBM.mediaMAM."))) && + (strlen(name) == strlen("ltfs.vendor.IBM.mediaMAM.XX"))) { + char part_str[3] = { 0x00, 0x00, 0x00 }; tape_partition_t part = 0; char *endptr = NULL; @@ -849,7 +807,8 @@ static int _xattr_get_virtual(struct dentry *d, char *buf, size_t buf_size, cons if (!strncmp(part_str, "IP", sizeof(part_str))) { part = ltfs_part_id2num(vol->label->partid_ip, vol); } else if (!strncmp(part_str, "DP", sizeof(part_str))) { - part = ltfs_part_id2num(vol->label->partid_dp, vol);; + part = ltfs_part_id2num(vol->label->partid_dp, vol); + ; } else { part = (uint8_t)(strtoul(part_str, &endptr, 16)); if (*endptr) return -LTFS_NO_XATTR; @@ -859,11 +818,11 @@ static int _xattr_get_virtual(struct dentry *d, char *buf, size_t buf_size, cons ret = ltfs_mam(part, (unsigned char *)buf, buf_size, vol); - } else if (! strncmp(name, "ltfs.vendor", strlen("ltfs.vendor"))) { - if (! strncmp(name + strlen("ltfs.vendor."), LTFS_VENDOR_NAME, strlen(LTFS_VENDOR_NAME))) { + } else if (!strncmp(name, "ltfs.vendor", strlen("ltfs.vendor"))) { + if (!strncmp(name + strlen("ltfs.vendor."), LTFS_VENDOR_NAME, strlen(LTFS_VENDOR_NAME))) { ret = _xattr_get_vendorunique_xattr(&val, name, vol); } - } else if (! strcmp(name, "ltfs.sync")) { + } else if (!strcmp(name, "ltfs.sync")) { ret = ltfs_sync_index(SYNC_EA, false, vol); } } @@ -893,14 +852,14 @@ static int _xattr_get_virtual(struct dentry *d, char *buf, size_t buf_size, cons * @return 0 on success, -LTFS_NO_XATTR if the xattr is not a settable virtual xattr, * or another negative value on error. */ -static int _xattr_set_virtual(struct dentry *d, const char *name, const char *value, - size_t size, struct ltfs_volume *vol) +static int +_xattr_set_virtual(struct dentry *d, const char *name, const char *value, size_t size, struct ltfs_volume *vol) { int ret = 0; - if (! strcmp(name, "ltfs.sync") && d == vol->index->root) + if (!strcmp(name, "ltfs.sync") && d == vol->index->root) ret = ltfs_sync_index(SYNC_EA, false, vol); - else if (! strcmp(name, "ltfs.commitMessage") && d == vol->index->root) { + else if (!strcmp(name, "ltfs.commitMessage") && d == vol->index->root) { char *value_null_terminated, *new_value; if (size > INDEX_MAX_COMMENT_LEN) { @@ -909,7 +868,7 @@ static int _xattr_set_virtual(struct dentry *d, const char *name, const char *va } ltfs_mutex_lock(&vol->index->dirty_lock); - if (! value || ! size) { + if (!value || !size) { /* Clear the current comment field */ if (vol->index->commit_message) { free(vol->index->commit_message); @@ -917,7 +876,7 @@ static int _xattr_set_virtual(struct dentry *d, const char *name, const char *va } } else { value_null_terminated = malloc(size + 1); - if (! value_null_terminated) { + if (!value_null_terminated) { ltfsmsg(LTFS_ERR, 10001E, "_xattr_set_virtual: commit_message"); ltfs_mutex_unlock(&vol->index->dirty_lock); return -LTFS_NO_MEMORY; @@ -934,28 +893,27 @@ static int _xattr_set_virtual(struct dentry *d, const char *name, const char *va ret = 0; /* Update the commit message in the index */ - if (vol->index->commit_message) - free(vol->index->commit_message); + if (vol->index->commit_message) free(vol->index->commit_message); vol->index->commit_message = new_value; } ltfs_set_index_dirty(false, false, vol->index); ltfs_mutex_unlock(&vol->index->dirty_lock); - } else if (! strcmp(name, "ltfs.volumeName") && d == vol->index->root) { + } else if (!strcmp(name, "ltfs.volumeName") && d == vol->index->root) { char *value_null_terminated, *new_value; ltfs_mutex_lock(&vol->index->dirty_lock); - if (! value || ! size) { + if (!value || !size) { fs_clear_nametype(&vol->index->volume_name); /* Clear tape attribute(TC_MAM_USER_MEDIUM_LABEL) */ - ret = update_tape_attribute (vol, NULL, TC_MAM_USER_MEDIUM_LABEL, 0); - if ( ret < 0 ) { + ret = update_tape_attribute(vol, NULL, TC_MAM_USER_MEDIUM_LABEL, 0); + if (ret < 0) { ltfsmsg(LTFS_WARN, 17199W, TC_MAM_USER_MEDIUM_LABEL, "_xattr_set_virtual"); } } else { value_null_terminated = malloc(size + 1); - if (! value_null_terminated) { + if (!value_null_terminated) { ltfsmsg(LTFS_ERR, 10001E, "_xattr_set_virtual: volume name"); ltfs_mutex_unlock(&vol->index->dirty_lock); return -LTFS_NO_MEMORY; @@ -976,8 +934,8 @@ static int _xattr_set_virtual(struct dentry *d, const char *name, const char *va fs_set_nametype(&vol->index->volume_name, new_value); /* Update tape attribute(TC_MAM_USER_MEDIUM_LABEL) */ - ret = update_tape_attribute (vol, new_value, TC_MAM_USER_MEDIUM_LABEL, size); - if ( ret < 0 ) { + ret = update_tape_attribute(vol, new_value, TC_MAM_USER_MEDIUM_LABEL, size); + if (ret < 0) { ltfsmsg(LTFS_WARN, 17199W, TC_MAM_USER_MEDIUM_LABEL, "_xattr_set_virtual"); return ret; } @@ -986,147 +944,147 @@ static int _xattr_set_virtual(struct dentry *d, const char *name, const char *va ltfs_set_index_dirty(false, false, vol->index); ltfs_mutex_unlock(&vol->index->dirty_lock); - } else if (! strcmp(name, "ltfs.createTime")) { + } else if (!strcmp(name, "ltfs.createTime")) { ret = _xattr_set_time(d, &d->creation_time, value, size, name, vol); if (ret == LTFS_TIME_OUT_OF_RANGE) { ltfsmsg(LTFS_WARN, 17221W, name, d->name.name, (unsigned long long)d->uid, value); ret = 0; } - } else if (! strcmp(name, "ltfs.modifyTime")) { + } else if (!strcmp(name, "ltfs.modifyTime")) { get_current_timespec(&d->change_time); ret = _xattr_set_time(d, &d->modify_time, value, size, name, vol); if (ret == LTFS_TIME_OUT_OF_RANGE) { ltfsmsg(LTFS_WARN, 17221W, name, d->name.name, (unsigned long long)d->uid, value); ret = 0; } - } else if (! strcmp(name, "ltfs.changeTime")) { + } else if (!strcmp(name, "ltfs.changeTime")) { ret = _xattr_set_time(d, &d->change_time, value, size, name, vol); if (ret == LTFS_TIME_OUT_OF_RANGE) { ltfsmsg(LTFS_WARN, 17221W, name, d->name.name, (unsigned long long)d->uid, value); ret = 0; } - } else if (! strcmp(name, "ltfs.accessTime")) { + } else if (!strcmp(name, "ltfs.accessTime")) { ret = _xattr_set_time(d, &d->access_time, value, size, name, vol); if (ret == LTFS_TIME_OUT_OF_RANGE) { ltfsmsg(LTFS_WARN, 17221W, name, d->name.name, (unsigned long long)d->uid, value); ret = 0; } - } else if (! strcmp(name, "ltfs.backupTime")) { + } else if (!strcmp(name, "ltfs.backupTime")) { ret = _xattr_set_time(d, &d->backup_time, value, size, name, vol); if (ret == LTFS_TIME_OUT_OF_RANGE) { ltfsmsg(LTFS_WARN, 17221W, name, d->name.name, (unsigned long long)d->uid, value); ret = 0; } - } else if (! strcmp(name, "ltfs.driveCaptureDump")) { + } else if (!strcmp(name, "ltfs.driveCaptureDump")) { ret = tape_takedump_drive(vol->device, true); - } else if (! strcmp(name, "ltfs.mediaStorageAlert")) { + } else if (!strcmp(name, "ltfs.mediaStorageAlert")) { uint64_t tape_alert = 0; char *invalid_start, *v; v = strndup(value, size); - if (! v) { + if (!v) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } /* ltfs.mediaStorageAlert shall be specified by hexadecimal text */ tape_alert = strtoull(v, &invalid_start, 16); - if( (*invalid_start == '\0') && v ) + if ((*invalid_start == '\0') && v) ret = ltfs_clear_tape_alert(tape_alert, vol); else ret = -LTFS_STRING_CONVERSION; free(v); - } else if (! strcmp(name, "ltfs.vendor.IBM.logLevel")) { + } else if (!strcmp(name, "ltfs.vendor.IBM.logLevel")) { int level = 0; char *invalid_start, *v; v = strndup(value, size); - if (! v) { + if (!v) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } /* ltfs.vendor.IBM.logLevel shall be specified by hexadecimal text */ level = strtoul(v, &invalid_start, 0); - if( (*invalid_start == '\0') && v ) { + if ((*invalid_start == '\0') && v) { ret = 0; ltfs_set_log_level(level); } else ret = -LTFS_STRING_CONVERSION; free(v); - } else if (! strcmp(name, "ltfs.vendor.IBM.syslogLevel")) { + } else if (!strcmp(name, "ltfs.vendor.IBM.syslogLevel")) { int level = 0; char *invalid_start, *v; v = strndup(value, size); - if (! v) { + if (!v) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } /* ltfs.vendor.IBM.syslogLevel shall be specified by hexadecimal text */ level = strtoul(v, &invalid_start, 0); - if( (*invalid_start == '\0') && v ) { + if ((*invalid_start == '\0') && v) { ret = 0; ltfs_set_syslog_level(level); } else ret = -LTFS_STRING_CONVERSION; free(v); - } else if (! strcmp(name, "ltfs.vendor.IBM.rao")) { + } else if (!strcmp(name, "ltfs.vendor.IBM.rao")) { char *v; v = strndup(value, size); - if (! v) { + if (!v) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } if (strlen(v) > PATH_MAX) return -LTFS_LARGE_XATTR; /* file path size check */ ret = ltfs_get_rao_list(v, vol); free(v); - } else if (! strcmp(name, "ltfs.vendor.IBM.trace")) { + } else if (!strcmp(name, "ltfs.vendor.IBM.trace")) { char *v; v = strndup(value, size); - if (! v) { + if (!v) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } ret = ltfs_set_trace_status(v); free(v); - } else if (! strcmp(name, "ltfs.vendor.IBM.dump")) { + } else if (!strcmp(name, "ltfs.vendor.IBM.dump")) { char *v; v = strndup(value, size); - if (! v) { + if (!v) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } ret = ltfs_dump(v, vol->work_directory); free(v); - } else if (! strcmp(name, "ltfs.vendor.IBM.dumpTrace")) { + } else if (!strcmp(name, "ltfs.vendor.IBM.dumpTrace")) { char *v; v = strndup(value, size); - if (! v) { + if (!v) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } ret = ltfs_trace_dump(v, vol->work_directory); free(v); - } else if (! strcmp(name, "ltfs.vendor.IBM.profiler")) { + } else if (!strcmp(name, "ltfs.vendor.IBM.profiler")) { uint64_t source = 0; char *invalid_start, *v; v = strndup(value, size); - if (! v) { + if (!v) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } source = strtoull(v, &invalid_start, 0); - if( (*invalid_start == '\0') && v ) { + if ((*invalid_start == '\0') && v) { /* Set request profiler */ if (source & PROF_REQ) ret = ltfs_request_profiler_start(vol->work_directory); @@ -1137,28 +1095,28 @@ static int _xattr_set_virtual(struct dentry *d, const char *name, const char *va } else ret = -LTFS_STRING_CONVERSION; free(v); - } else if (! strncmp(name, "ltfs.vendor", strlen("ltfs.vendor"))) { - if (! strncmp(name + strlen("ltfs.vendor."), LTFS_VENDOR_NAME, strlen(LTFS_VENDOR_NAME))) { - ret = _xattr_set_vendorunique_xattr(name, value, size, vol); - } - } else if (! strcmp(name, "ltfs.mamBarcode")) { - ret = update_tape_attribute (vol, value, TC_MAM_BARCODE, size); - if ( ret < 0 ) { + } else if (!strncmp(name, "ltfs.vendor", strlen("ltfs.vendor"))) { + if (!strncmp(name + strlen("ltfs.vendor."), LTFS_VENDOR_NAME, strlen(LTFS_VENDOR_NAME))) { + ret = _xattr_set_vendorunique_xattr(name, value, size, vol); + } + } else if (!strcmp(name, "ltfs.mamBarcode")) { + ret = update_tape_attribute(vol, value, TC_MAM_BARCODE, size); + if (ret < 0) { ltfsmsg(LTFS_WARN, 17199W, TC_MAM_USER_MEDIUM_LABEL, "_xattr_set_virtual"); return ret; } - } else if (! strcmp(name, "ltfs.volumeLockState")) { + } else if (!strcmp(name, "ltfs.volumeLockState")) { unsigned int lock = 0; char *invalid_start, *v; v = strndup(value, size); - if (! v) { + if (!v) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } lock = strtoull(v, &invalid_start, 0); - if( (*invalid_start == '\0') && v ) { + if ((*invalid_start == '\0') && v) { mam_lockval new = UNLOCKED_MAM; char status_mam[TC_MAM_LOCKED_MAM_SIZE]; @@ -1200,8 +1158,8 @@ static int _xattr_set_virtual(struct dentry *d, const char *name, const char *va status_mam[0] = new; /* update MAM attribute */ - ret = update_tape_attribute(vol, status_mam, TC_MAM_LOCKED_MAM, TC_MAM_LOCKED_MAM_SIZE); - if ( ret < 0 ) { + ret = update_tape_attribute(vol, status_mam, TC_MAM_LOCKED_MAM, TC_MAM_LOCKED_MAM_SIZE); + if (ret < 0) { ltfsmsg(LTFS_WARN, 17199W, TC_MAM_LOCKED_MAM, "_xattr_set_virtual"); return ret; } @@ -1223,7 +1181,7 @@ static int _xattr_set_virtual(struct dentry *d, const char *name, const char *va ret = -LTFS_STRING_CONVERSION; free(v); - } else if (! strcmp(name, "ltfs.mediaPool.additionalInfo")) { + } else if (!strcmp(name, "ltfs.mediaPool.additionalInfo")) { ret = tape_set_media_pool_info(vol, value, size, false); } else ret = -LTFS_NO_XATTR; @@ -1244,7 +1202,7 @@ static int _xattr_remove_virtual(struct dentry *d, const char *name, struct ltfs { int ret = 0; - if (! strcmp(name, "ltfs.commitMessage") && d == vol->index->root) { + if (!strcmp(name, "ltfs.commitMessage") && d == vol->index->root) { ltfs_mutex_lock(&vol->index->dirty_lock); if (vol->index->commit_message) { free(vol->index->commit_message); @@ -1252,15 +1210,15 @@ static int _xattr_remove_virtual(struct dentry *d, const char *name, struct ltfs ltfs_set_index_dirty(false, false, vol->index); } ltfs_mutex_unlock(&vol->index->dirty_lock); - } else if (! strcmp(name, "ltfs.volumeName") && d == vol->index->root) { + } else if (!strcmp(name, "ltfs.volumeName") && d == vol->index->root) { ltfs_mutex_lock(&vol->index->dirty_lock); if (vol->index->volume_name.name) { fs_clear_nametype(&vol->index->volume_name); ltfs_set_index_dirty(false, false, vol->index); } /* Clear tape attribute(TC_MAM_USER_MEDIUM_LABEL) */ - ret = update_tape_attribute (vol, NULL, TC_MAM_USER_MEDIUM_LABEL, 0); - if ( ret < 0 ) { + ret = update_tape_attribute(vol, NULL, TC_MAM_USER_MEDIUM_LABEL, 0); + if (ret < 0) { ltfsmsg(LTFS_WARN, 17199W, TC_MAM_USER_MEDIUM_LABEL, "_xattr_set_virtual"); } ltfs_mutex_unlock(&vol->index->dirty_lock); @@ -1274,10 +1232,9 @@ static int _xattr_remove_virtual(struct dentry *d, const char *name, struct ltfs int xattr_get_string(const char *val, char **outval, const char *msg) { - if (! val) - return 0; + if (!val) return 0; *outval = arch_strdup(val); - if (! (*outval)) { + if (!(*outval)) { ltfsmsg(LTFS_ERR, 10001E, msg); return -LTFS_NO_MEMORY; } @@ -1286,7 +1243,7 @@ int xattr_get_string(const char *val, char **outval, const char *msg) int xattr_get_u64(uint64_t val, char **outval, const char *msg) { - int ret = asprintf(outval, "%"PRIu64, val); + int ret = asprintf(outval, "%" PRIu64, val); if (ret < 0) { ltfsmsg(LTFS_ERR, 10001E, msg); *outval = NULL; @@ -1295,8 +1252,7 @@ int xattr_get_u64(uint64_t val, char **outval, const char *msg) return ret; } -int xattr_do_set(struct dentry *d, const char *name, const char *value, size_t size, - struct xattr_info *xattr) +int xattr_do_set(struct dentry *d, const char *name, const char *value, size_t size, struct xattr_info *xattr) { int ret = 0; @@ -1307,13 +1263,13 @@ int xattr_do_set(struct dentry *d, const char *name, const char *value, size_t s xattr->value = NULL; } } else { - xattr = (struct xattr_info *) calloc(1, sizeof(struct xattr_info)); - if (! xattr) { + xattr = (struct xattr_info *)calloc(1, sizeof(struct xattr_info)); + if (!xattr) { ltfsmsg(LTFS_ERR, 10001E, "xattr_do_set: xattr"); return -LTFS_NO_MEMORY; } xattr->key.name = arch_strdup(name); - if (! xattr->key.name) { + if (!xattr->key.name) { ltfsmsg(LTFS_ERR, 10001E, "xattr_do_set: xattr key"); ret = -LTFS_NO_MEMORY; goto out_free; @@ -1326,7 +1282,7 @@ int xattr_do_set(struct dentry *d, const char *name, const char *value, size_t s xattr->size = size; if (size > 0) { xattr->value = (char *)malloc(size); - if (! xattr->value) { + if (!xattr->value) { ltfsmsg(LTFS_ERR, 10001E, "xattr_do_set: xattr value"); ret = -LTFS_NO_MEMORY; goto out_remove; @@ -1338,8 +1294,7 @@ int xattr_do_set(struct dentry *d, const char *name, const char *value, size_t s out_remove: TAILQ_REMOVE(&d->xattrlist, xattr, list); out_free: - if (xattr->key.name) - free(xattr->key.name); + if (xattr->key.name) free(xattr->key.name); free(xattr); return ret; } @@ -1354,15 +1309,14 @@ int xattr_do_set(struct dentry *d, const char *name, const char *value, size_t s * exist, or 0 to ignore any existing value. * @return 0 on success or a negative value on error. */ -int xattr_set(struct dentry *d, const char *name, const char *value, size_t size, - int flags, struct ltfs_volume *vol) +int xattr_set(struct dentry *d, const char *name, const char *value, size_t size, int flags, struct ltfs_volume *vol) { struct xattr_info *xattr; bool replace, create; int ret; bool is_worm_cart = false; bool disable_worm_ea = false; - char *new_value="1"; + char *new_value = "1"; bool write_idx = false; CHECK_ARG_NULL(d, -LTFS_NULL_ARG); @@ -1376,8 +1330,7 @@ int xattr_set(struct dentry *d, const char *name, const char *value, size_t size create = flags & XATTR_CREATE; ret = _xattr_lock_dentry(name, true, d, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = tape_get_worm_status(vol->device, &is_worm_cart); if (ret < 0) { @@ -1386,8 +1339,8 @@ int xattr_set(struct dentry *d, const char *name, const char *value, size_t size goto out_unlock; } - if ((is_worm_cart && (d->is_immutable || (d->is_appendonly && strcmp(name, "ltfs.vendor.IBM.immutable")))) - || (!is_worm_cart && (d->is_immutable || d->is_appendonly) && !_xattr_is_worm_ea(name))) { + if ((is_worm_cart && (d->is_immutable || (d->is_appendonly && strcmp(name, "ltfs.vendor.IBM.immutable")))) || + (!is_worm_cart && (d->is_immutable || d->is_appendonly) && !_xattr_is_worm_ea(name))) { /* EA cannot be set in case of immutable/appendonly */ ltfsmsg(LTFS_ERR, 17237E, "set xattr: WORM entry"); ret = -LTFS_RDONLY_XATTR; @@ -1397,8 +1350,7 @@ int xattr_set(struct dentry *d, const char *name, const char *value, size_t size /* Check if this is a user-writeable virtual xattr */ if (_xattr_is_virtual(d, name, vol)) { ret = _xattr_set_virtual(d, name, value, size, vol); - if (ret == -LTFS_NO_XATTR) - ret = -LTFS_RDONLY_XATTR; + if (ret == -LTFS_NO_XATTR) ret = -LTFS_RDONLY_XATTR; goto out_unlock; } @@ -1422,7 +1374,7 @@ int xattr_set(struct dentry *d, const char *name, const char *value, size_t size releasewrite_mrsw(&d->meta_lock); ret = -LTFS_XATTR_EXISTS; goto out_unlock; - } else if (replace && ! xattr) { + } else if (replace && !xattr) { releasewrite_mrsw(&d->meta_lock); ret = -LTFS_NO_XATTR; goto out_unlock; @@ -1463,8 +1415,7 @@ int xattr_set(struct dentry *d, const char *name, const char *value, size_t size if (!strcmp(name, "ltfs.vendor.IBM.immutable")) { d->is_immutable = !disable_worm_ea; ltfsmsg(LTFS_INFO, 17238I, "immutable", d->is_immutable, d->name.name); - } - else if (!strcmp(name, "ltfs.vendor.IBM.appendonly")) { + } else if (!strcmp(name, "ltfs.vendor.IBM.appendonly")) { d->is_appendonly = !disable_worm_ea; ltfsmsg(LTFS_INFO, 17238I, "appendonly", d->is_appendonly, d->name.name); } @@ -1496,8 +1447,7 @@ int xattr_set(struct dentry *d, const char *name, const char *value, size_t size * number of bytes in the xattr value. returns a negative value on error. If the * operation needs to be restarted, then -LTFS_RESTART_OPERATION is returned instead. */ -int xattr_get(struct dentry *d, const char *name, char *value, size_t size, - struct ltfs_volume *vol) +int xattr_get(struct dentry *d, const char *name, char *value, size_t size, struct ltfs_volume *vol) { struct xattr_info *xattr = NULL; int ret; @@ -1505,14 +1455,13 @@ int xattr_get(struct dentry *d, const char *name, char *value, size_t size, CHECK_ARG_NULL(d, -LTFS_NULL_ARG); CHECK_ARG_NULL(name, -LTFS_NULL_ARG); CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); - if (size > 0 && ! value) { + if (size > 0 && !value) { ltfsmsg(LTFS_ERR, 11123E); return -LTFS_BAD_ARG; } ret = _xattr_lock_dentry(name, false, d, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* Try to get a virtual xattr first. */ if (_xattr_is_virtual(d, name, vol)) { @@ -1529,10 +1478,9 @@ int xattr_get(struct dentry *d, const char *name, char *value, size_t size, vol->reval = -LTFS_REVAL_FAILED; _xattr_unlock_dentry(name, false, d, vol); return ret; - }else if (ret != -LTFS_NO_XATTR) { + } else if (ret != -LTFS_NO_XATTR) { /* if ltfs.sync is specified, don't print any message */ - if (ret < 0 && ret != -LTFS_RDONLY_XATTR) - ltfsmsg(LTFS_ERR, 11128E, ret); + if (ret < 0 && ret != -LTFS_RDONLY_XATTR) ltfsmsg(LTFS_ERR, 11128E, ret); goto out_unlock; } } @@ -1549,7 +1497,7 @@ int xattr_get(struct dentry *d, const char *name, char *value, size_t size, /* Generate output. */ ret = 0; - if (! xattr) { + if (!xattr) { /* There's no such extended attribute */ ret = -LTFS_NO_XATTR; } else if (size && xattr->size > size) { @@ -1585,7 +1533,7 @@ int xattr_list(struct dentry *d, char *list, size_t size, struct ltfs_volume *vo CHECK_ARG_NULL(d, -LTFS_NULL_ARG); CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); - if (size > 0 && ! list) { + if (size > 0 && !list) { ltfsmsg(LTFS_ERR, 11130E); return -LTFS_BAD_ARG; } @@ -1593,8 +1541,7 @@ int xattr_list(struct dentry *d, char *list, size_t size, struct ltfs_volume *vo acquireread_mrsw(&d->meta_lock); /* Fill the buffer with only real xattrs. */ - if (size) - memset(list, 0, size); + if (size) memset(list, 0, size); ret = _xattr_list_physicals(d, list, size); if (ret < 0) { @@ -1612,13 +1559,11 @@ int xattr_list(struct dentry *d, char *list, size_t size, struct ltfs_volume *vo */ /* Was the buffer large enough? */ - if (size && (size_t)nbytes > size) - ret = -LTFS_SMALL_BUFFER; + if (size && (size_t)nbytes > size) ret = -LTFS_SMALL_BUFFER; out: releaseread_mrsw(&d->meta_lock); - if (ret < 0) - return ret; + if (ret < 0) return ret; return nbytes; } @@ -1643,12 +1588,12 @@ int xattr_do_remove(struct dentry *d, const char *name, bool force, struct ltfs_ ltfsmsg(LTFS_ERR, 11140E, ret); releasewrite_mrsw(&d->meta_lock); return ret; - } else if (! xattr) { + } else if (!xattr) { releasewrite_mrsw(&d->meta_lock); return -LTFS_NO_XATTR; } - if (! force) { + if (!force) { /* If this xattr is in the reserved namespace, the user can't remove it. */ /* TODO: in the future, there could be user-removable reserved xattrs. */ if (strcasestr(name, "ltfs") == name && !_xattr_is_stored_vea(name) && !_xattr_is_worm_ea(name)) { @@ -1663,8 +1608,7 @@ int xattr_do_remove(struct dentry *d, const char *name, bool force, struct ltfs_ releasewrite_mrsw(&d->meta_lock); free(xattr->key.name); - if (xattr->value) - free(xattr->value); + if (xattr->value) free(xattr->value); free(xattr); return 0; @@ -1687,8 +1631,7 @@ int xattr_remove(struct dentry *d, const char *name, struct ltfs_volume *vol) CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); ret = _xattr_lock_dentry(name, true, d, vol); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = tape_get_worm_status(vol->device, &is_worm_cart); if (ret < 0) { @@ -1697,8 +1640,7 @@ int xattr_remove(struct dentry *d, const char *name, struct ltfs_volume *vol) goto out_dunlk; } - if ((d->is_immutable || d->is_appendonly) - && (is_worm_cart || !_xattr_is_worm_ea(name))) { + if ((d->is_immutable || d->is_appendonly) && (is_worm_cart || !_xattr_is_worm_ea(name))) { /* EA cannot be removed in case of immutable/appendonly */ ltfsmsg(LTFS_ERR, 17237E, "remove xattr: WORM entry"); ret = -LTFS_RDONLY_XATTR; @@ -1708,20 +1650,17 @@ int xattr_remove(struct dentry *d, const char *name, struct ltfs_volume *vol) /* If this xattr is virtual, try the virtual removal function. */ if (_xattr_is_virtual(d, name, vol)) { ret = _xattr_remove_virtual(d, name, vol); - if (ret == -LTFS_NO_XATTR) - ret = -LTFS_RDONLY_XATTR; /* non-removable virtual xattr */ + if (ret == -LTFS_NO_XATTR) ret = -LTFS_RDONLY_XATTR; /* non-removable virtual xattr */ goto out_dunlk; } ret = xattr_do_remove(d, name, false, vol); - if (ret < 0) - goto out_dunlk; + if (ret < 0) goto out_dunlk; if (!strcmp(name, "ltfs.vendor.IBM.immutable")) { d->is_immutable = false; ltfsmsg(LTFS_INFO, 17238I, "immutable", d->is_immutable, d->name.name); - } - else if (!strcmp(name, "ltfs.vendor.IBM.appendonly")) { + } else if (!strcmp(name, "ltfs.vendor.IBM.appendonly")) { d->is_appendonly = false; ltfsmsg(LTFS_INFO, 17238I, "appendonly", d->is_appendonly, d->name.name); } @@ -1744,7 +1683,7 @@ int xattr_remove(struct dentry *d, const char *name, struct ltfs_volume *vol) */ const char *xattr_strip_name(const char *name) { -#if (defined (__APPLE__) || defined (mingw_PLATFORM)) +#if (defined(__APPLE__) || defined(mingw_PLATFORM)) return name; #else if (strstr(name, "user.") == name) @@ -1761,12 +1700,12 @@ const char *xattr_strip_name(const char *name) * @param vol LTFS volume * @return 0 on success or a negative value on error */ -int xattr_set_mountpoint_length(struct dentry *d, const char* value, size_t size ) +int xattr_set_mountpoint_length(struct dentry *d, const char *value, size_t size) { #ifdef POSIXLINK_ONLY return 0; #else - int ret=0; + int ret = 0; struct xattr_info *xattr; CHECK_ARG_NULL(d, -LTFS_NULL_ARG); diff --git a/src/libltfs/xml_reader.c b/src/libltfs/xml_reader.c index c9ddbb4a..d881d5ef 100644 --- a/src/libltfs/xml_reader.c +++ b/src/libltfs/xml_reader.c @@ -51,14 +51,14 @@ ************************************************************************************* */ -#include "ltfs.h" -#include "xml_libltfs.h" -#include "fs.h" -#include "tape.h" +#include "arch/time_internal.h" #include "base64.h" -#include "pathname.h" +#include "fs.h" #include "index_criteria.h" -#include "arch/time_internal.h" +#include "ltfs.h" +#include "pathname.h" +#include "tape.h" +#include "xml_libltfs.h" /** * Read a text node, returning the buffer provided by libxml2. @@ -72,8 +72,7 @@ int xml_scan_text(xmlTextReaderPtr reader, const char **value) { int type; - if (xml_reader_read(reader) < 0) - return -LTFS_XML_READ_FAIL; + if (xml_reader_read(reader) < 0) return -LTFS_XML_READ_FAIL; type = xmlTextReaderNodeType(reader); if (type == XML_ELEMENT_DECL) @@ -105,14 +104,12 @@ int xml_scan_text(xmlTextReaderPtr reader, const char **value) * end of the containing tag. * @return 0 on success or a negative value on error */ -int xml_next_tag(xmlTextReaderPtr reader, const char *containing_name, - const char **name, int *type) +int xml_next_tag(xmlTextReaderPtr reader, const char *containing_name, const char **name, int *type) { int ret; do { ret = xml_reader_read(reader); - if (ret < 0) - return ret; + if (ret < 0) return ret; *name = (const char *)xmlTextReaderConstName(reader); *type = xmlTextReaderNodeType(reader); } while (strcmp(*name, containing_name) && (*type) != XML_ELEMENT_NODE); @@ -136,7 +133,7 @@ int xml_skip_tag(xmlTextReaderPtr reader) } check_empty(); - while (! empty && (type != XML_ELEMENT_DECL || depth > start_depth)) { + while (!empty && (type != XML_ELEMENT_DECL || depth > start_depth)) { ret = xmlTextReaderRead(reader); if (ret < 0) { ltfsmsg(LTFS_ERR, 17093E); @@ -186,17 +183,17 @@ int xml_save_tag(xmlTextReaderPtr reader, size_t *tag_count, unsigned char ***ta /* NOTE: caller must do xmlFreeDoc(xmlTextReaderCurrentDoc(reader)) when parsing is * finished, as this call modifies the behavior of xmlFreeTextReader. */ doc = xmlTextReaderCurrentDoc(reader); - if (! doc) { + if (!doc) { ltfsmsg(LTFS_ERR, 17200E, "xmlTextReaderCurrentDoc"); return -1; } node = xmlTextReaderExpand(reader); - if (! node) { + if (!node) { ltfsmsg(LTFS_ERR, 17200E, "xmlTextReaderExpand"); return -1; } buf = xmlBufferCreate(); - if (! buf) { + if (!buf) { ltfsmsg(LTFS_ERR, 17200E, "xmlBufferCreate"); return -1; } @@ -208,7 +205,7 @@ int xml_save_tag(xmlTextReaderPtr reader, size_t *tag_count, unsigned char ***ta } bufsize = xmlBufferLength(buf); tag_value = malloc(bufsize + 1); - if (! tag_value) { + if (!tag_value) { xmlBufferFree(buf); ltfsmsg(LTFS_ERR, 10001E, "_xml_save_tag: tag value"); return -1; @@ -219,19 +216,19 @@ int xml_save_tag(xmlTextReaderPtr reader, size_t *tag_count, unsigned char ***ta #else tag_value = xmlTextReaderReadOuterXml(reader); - if (! tag_value) { + if (!tag_value) { ltfsmsg(LTFS_ERR, 17091E); return -1; } #endif /* __APPLE__ */ t = realloc(*tag_list, c * sizeof(unsigned char *)); - if (! t) { + if (!t) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); free(tag_value); return -1; } - t[c-1] = tag_value; + t[c - 1] = tag_value; *tag_count = c; *tag_list = t; @@ -275,25 +272,23 @@ int xml_parse_uuid(char *out_val, const char *val) ltfsmsg(LTFS_ERR, 17029E, val); return -1; } - arch_strcpy(out_val,(strlen(val) + 1), val); + arch_strcpy(out_val, (strlen(val) + 1), val); - for (i=0; i<36; ++i) { + for (i = 0; i < 36; ++i) { if (i == 8 || i == 13 || i == 18 || i == 23) { if (val[i] != '-') { ltfsmsg(LTFS_ERR, 17029E, val); return -1; } } else { - if ((val[i] < '0' || val[i] > '9') && (val[i] < 'a' || val[i] > 'f') && - (val[i] < 'A' || val[i] > 'F')) { + if ((val[i] < '0' || val[i] > '9') && (val[i] < 'a' || val[i] > 'f') && (val[i] < 'A' || val[i] > 'F')) { ltfsmsg(LTFS_ERR, 17029E, val); return -1; } } /* convert to lower-case */ - if (val[i] >= 'A' && val[i] <= 'F') - out_val[i] += 32; + if (val[i] >= 'A' && val[i] <= 'F') out_val[i] += 32; } return 0; @@ -375,12 +370,10 @@ int xml_parse_ll(long long *out_val, const char *val) CHECK_ARG_NULL(val, -LTFS_NULL_ARG); vallen = strlen(val); - if (vallen == 0) - return -1; + if (vallen == 0) return -1; *out_val = strtoll(val, &invalid_start, 10); - if(*invalid_start != '\0') - return -1; + if (*invalid_start != '\0') return -1; return 0; } @@ -401,12 +394,10 @@ int xml_parse_ull(unsigned long long *out_val, const char *val) CHECK_ARG_NULL(val, -LTFS_NULL_ARG); vallen = strlen(val); - if (vallen == 0) - return -1; + if (vallen == 0) return -1; *out_val = strtoull(val, &invalid_start, 10); - if(*invalid_start != '\0') - return -1; + if (*invalid_start != '\0') return -1; return 0; } @@ -427,12 +418,10 @@ int xml_parse_xll(unsigned long long *out_val, const char *val) CHECK_ARG_NULL(val, -LTFS_NULL_ARG); vallen = strlen(val); - if (vallen == 0) - return -1; + if (vallen == 0) return -1; *out_val = strtoull(val, &invalid_start, 16); - if(*invalid_start != '\0') - return -1; + if (*invalid_start != '\0') return -1; return 0; } @@ -448,9 +437,9 @@ int xml_parse_bool(bool *out_val, const char *value) CHECK_ARG_NULL(out_val, -LTFS_NULL_ARG); CHECK_ARG_NULL(value, -LTFS_NULL_ARG); - if (! strcmp(value, "true") || ! strcmp(value, "1")) + if (!strcmp(value, "true") || !strcmp(value, "1")) *out_val = true; - else if (! strcmp(value, "false") || ! strcmp(value, "0")) + else if (!strcmp(value, "false") || !strcmp(value, "0")) *out_val = false; else { ltfsmsg(LTFS_ERR, 17032E, value); @@ -473,13 +462,17 @@ int xml_parse_time(bool msg, const char *fmt_time, struct ltfs_timespec *rawtime CHECK_ARG_NULL(fmt_time, -LTFS_NULL_ARG); CHECK_ARG_NULL(rawtime, -LTFS_NULL_ARG); - ret = arch_sscanf(fmt_time, "%d-%2d-%2dT%2d:%2d:%2d.%9ldZ", - &tm.tm_year, &tm.tm_mon, &tm.tm_mday, - &tm.tm_hour, &tm.tm_min, &tm.tm_sec, - &rawtime->tv_nsec); - if( ret != 7 ) { - if (msg) - ltfsmsg(LTFS_ERR, 17034E, fmt_time, ret); + ret = arch_sscanf(fmt_time, + "%d-%2d-%2dT%2d:%2d:%2d.%9ldZ", + &tm.tm_year, + &tm.tm_mon, + &tm.tm_mday, + &tm.tm_hour, + &tm.tm_min, + &tm.tm_sec, + &rawtime->tv_nsec); + if (ret != 7) { + if (msg) ltfsmsg(LTFS_ERR, 17034E, fmt_time, ret); return -1; } @@ -509,11 +502,10 @@ int xml_input_tape_read_callback(void *context, char *buffer, int len) char *buf2; int bytes_saved, bytes_remaining, ret_sp; - if (len == 0) - return 0; + if (len == 0) return 0; /* Try to fill the whole buffer from cache. If that fails, try to read from tape. */ - if (len <= (int32_t) ctx->buf_used) { + if (len <= (int32_t)ctx->buf_used) { memcpy(buffer, ctx->buf + ctx->buf_start, len); ctx->buf_used -= len; if (ctx->buf_used > 0) @@ -532,23 +524,20 @@ int xml_input_tape_read_callback(void *context, char *buffer, int len) while (bytes_remaining > 0) { /* If we've reached EOD, we're at the end of the Index. */ - if (ctx->eod_pos > 0 && ctx->current_pos == ctx->eod_pos) - return bytes_saved; + if (ctx->eod_pos > 0 && ctx->current_pos == ctx->eod_pos) return bytes_saved; /* If we've exhausted a small block, we're at the end of the Index. */ - if (ctx->saw_small_block) - return bytes_saved; + if (ctx->saw_small_block) return bytes_saved; /* Try to read a block into the buffer. */ - nread = tape_read(ctx->vol->device, ctx->buf, ctx->buf_size, false, - ctx->vol->kmi_handle); + nread = tape_read(ctx->vol->device, ctx->buf, ctx->buf_size, false, ctx->vol->kmi_handle); ++ctx->current_pos; if (nread < 0) { /* We know we're not at EOD, so read errors are unexpected. */ ltfsmsg(LTFS_ERR, 17039E, (int)nread); ctx->err_code = nread; return -1; - } else if ((size_t) nread < ctx->buf_size) { + } else if ((size_t)nread < ctx->buf_size) { /* Caught a small read. If this is a file mark, position before it. If * it's a record, look for a file mark following it. */ ctx->saw_small_block = true; @@ -560,8 +549,7 @@ int xml_input_tape_read_callback(void *context, char *buffer, int len) ctx->err_code = ret_sp; return -1; } - } else if (ctx->eod_pos == 0 || - (ctx->eod_pos > 0 && ctx->current_pos < ctx->eod_pos)) { + } else if (ctx->eod_pos == 0 || (ctx->eod_pos > 0 && ctx->current_pos < ctx->eod_pos)) { /* Look for a trailing file mark. */ buf2 = malloc(ctx->vol->label->blocksize); if (!buf2) { @@ -569,10 +557,9 @@ int xml_input_tape_read_callback(void *context, char *buffer, int len) ctx->err_code = -LTFS_NO_MEMORY; return -1; } - nr2 = tape_read(ctx->vol->device, buf2, ctx->vol->label->blocksize, false, - ctx->vol->kmi_handle); + nr2 = tape_read(ctx->vol->device, buf2, ctx->vol->label->blocksize, false, ctx->vol->kmi_handle); free(buf2); - errno = 0; /* Clear errno because some OSs set errno in free() */ + errno = 0; /* Clear errno because some OSs set errno in free() */ if (nr2 < 0) { /* Still not at EOD, so read errors are cause for alarm. */ ltfsmsg(LTFS_ERR, 17041E, (int)nr2); ctx->err_code = nr2; diff --git a/src/libltfs/xml_reader_libltfs.c b/src/libltfs/xml_reader_libltfs.c index 6a23e3fa..683d451f 100644 --- a/src/libltfs/xml_reader_libltfs.c +++ b/src/libltfs/xml_reader_libltfs.c @@ -55,22 +55,22 @@ ************************************************************************************* */ -#include #include +#include -#include "ltfs.h" -#include "xml_libltfs.h" -#include "fs.h" -#include "tape.h" +#include "arch/time_internal.h" #include "base64.h" -#include "pathname.h" +#include "fs.h" #include "index_criteria.h" -#include "arch/time_internal.h" +#include "ltfs.h" +#include "pathname.h" +#include "tape.h" +#include "xml_libltfs.h" /* LTFS index version checks */ -#define IDX_VERSION_SPARSE MAKE_LTFS_VERSION(2,0,0) -#define IDX_VERSION_BACKUPTIME MAKE_LTFS_VERSION(2,0,0) -#define IDX_VERSION_UID MAKE_LTFS_VERSION(2,0,0) +#define IDX_VERSION_SPARSE MAKE_LTFS_VERSION(2, 0, 0) +#define IDX_VERSION_BACKUPTIME MAKE_LTFS_VERSION(2, 0, 0) +#define IDX_VERSION_UID MAKE_LTFS_VERSION(2, 0, 0) /************************************************************************************** * Local Functions @@ -109,7 +109,7 @@ static int decode_entry_name(char **new_name, const char *name) if (encoded) { buf_decode[0] = name[i]; - buf_decode[1] = name[i+1]; + buf_decode[1] = name[i + 1]; tmp_name[j] = (int)strtol(buf_decode, NULL, 16); encoded = false; @@ -124,13 +124,13 @@ static int decode_entry_name(char **new_name, const char *name) */ if (tmp_name[j] == '/' || tmp_name[j] == 0x1f || tmp_name[j] == 0x00) { tmp_name[j] = '%'; - tmp_name[j+1] = buf_decode[0]; - tmp_name[j+2] = buf_decode[1]; - j+=2; + tmp_name[j + 1] = buf_decode[0]; + tmp_name[j + 2] = buf_decode[1]; + j += 2; ltfsmsg(LTFS_INFO, 17256I, name); } - i+=2; + i += 2; } else { tmp_name[j] = name[i]; i++; @@ -229,7 +229,7 @@ static int _xml_parse_nametype_allow_zero_length(xmlTextReaderPtr reader, struct get_tag_text_allow_zero_length(); if (!strlen(value)) { - n->name = NULL; + n->name = NULL; n->percent_encode = false; return 0; } @@ -296,26 +296,23 @@ static int _xml_parse_version(const char *version_str, int *version_int) CHECK_ARG_NULL(version_int, -LTFS_NULL_ARG); /* Legacy index version 1.0 */ - if (! strcmp(version_str, "1.0")) { - *version_int = MAKE_LTFS_VERSION(1,0,0); + if (!strcmp(version_str, "1.0")) { + *version_int = MAKE_LTFS_VERSION(1, 0, 0); return 0; } tmp = version_str; while (*tmp && *tmp >= '0' && *tmp <= '9') ++tmp; - if (tmp == version_str || *tmp != '.') - return -LTFS_BAD_ARG; + if (tmp == version_str || *tmp != '.') return -LTFS_BAD_ARG; y_str = ++tmp; while (*tmp && *tmp >= '0' && *tmp <= '9') ++tmp; - if (tmp == y_str || *tmp != '.') - return -LTFS_BAD_ARG; + if (tmp == y_str || *tmp != '.') return -LTFS_BAD_ARG; z_str = ++tmp; while (*tmp && *tmp >= '0' && *tmp <= '9') ++tmp; - if (tmp == z_str || *tmp != '\0') - return -LTFS_BAD_ARG; + if (tmp == z_str || *tmp != '\0') return -LTFS_BAD_ARG; *version_int = MAKE_LTFS_VERSION(atoi(version_str), atoi(y_str), atoi(z_str)); return 0; @@ -324,16 +321,15 @@ static int _xml_parse_version(const char *version_str, int *version_int) /** * Start parsing an XML stream by checking the encoding and version. */ -static int _xml_parser_init(xmlTextReaderPtr reader, const char *top_name, int *idx_version, - int min_version, int max_version) +static int +_xml_parser_init(xmlTextReaderPtr reader, const char *top_name, int *idx_version, int min_version, int max_version) { const char *name, *encoding; char *value; int type, ver, ret; ret = xml_next_tag(reader, "", &name, &type); - if (ret < 0) - return ret; + if (ret < 0) return ret; if (strcmp(name, top_name)) { ltfsmsg(LTFS_ERR, 17017E, name); @@ -342,14 +338,14 @@ static int _xml_parser_init(xmlTextReaderPtr reader, const char *top_name, int * /* reject this XML file if it isn't UTF-8 */ encoding = (const char *)xmlTextReaderConstEncoding(reader); - if (! encoding || strcmp(encoding, "UTF-8")) { + if (!encoding || strcmp(encoding, "UTF-8")) { ltfsmsg(LTFS_ERR, 17018E, encoding); return -LTFS_XML_WRONG_ENCODING; } /* check the version attribute of the top-level tag */ value = (char *)xmlTextReaderGetAttribute(reader, BAD_CAST "version"); - if (! value) { + if (!value) { ltfsmsg(LTFS_ERR, 17019E); return -LTFS_XML_TOP_ATTR_FAIL; } @@ -383,11 +379,10 @@ static int _xml_parse_label_location(xmlTextReaderPtr reader, struct ltfs_label while (true) { get_next_tag(); - if (! strcmp(name, "partition")) { + if (!strcmp(name, "partition")) { check_required_tag(0); get_tag_text(); - if (_xml_parse_partition(value) < 0) - return -1; + if (_xml_parse_partition(value) < 0) return -1; label->this_partition = value[0]; check_tag_end("partition"); @@ -412,19 +407,17 @@ static int _xml_parse_partition_map(xmlTextReaderPtr reader, struct ltfs_label * while (true) { get_next_tag(); - if (! strcmp(name, "index")) { + if (!strcmp(name, "index")) { check_required_tag(0); get_tag_text(); - if (_xml_parse_partition(value) < 0) - return -1; + if (_xml_parse_partition(value) < 0) return -1; label->partid_ip = value[0]; check_tag_end("index"); - } else if (! strcmp(name, "data")) { + } else if (!strcmp(name, "data")) { check_required_tag(1); get_tag_text(); - if (_xml_parse_partition(value) < 0) - return -1; + if (_xml_parse_partition(value) < 0) return -1; label->partid_dp = value[0]; check_tag_end("data"); @@ -446,28 +439,25 @@ static int _xml_parse_label(xmlTextReaderPtr reader, struct ltfs_label *label) declare_tracking_arrays_no_opt(7); /* start the parser: find top-level "label" tag, check version and encoding */ - ret = _xml_parser_init(reader, parent_tag, &label->version, - LTFS_LABEL_VERSION_MIN, LTFS_LABEL_VERSION_MAX); - if (ret < 0) - return ret; + ret = _xml_parser_init(reader, parent_tag, &label->version, LTFS_LABEL_VERSION_MIN, LTFS_LABEL_VERSION_MAX); + if (ret < 0) return ret; /* parse label contents */ while (true) { get_next_tag(); - if (! strcmp(name, "creator")) { + if (!strcmp(name, "creator")) { check_required_tag(0); get_tag_text(); - if (label->creator) - free(label->creator); + if (label->creator) free(label->creator); label->creator = arch_strdup(value); - if (! label->creator) { + if (!label->creator) { ltfsmsg(LTFS_ERR, 10001E, name); return -LTFS_NO_MEMORY; } check_tag_end("creator"); - } else if (! strcmp(name, "formattime")) { + } else if (!strcmp(name, "formattime")) { check_required_tag(1); get_tag_text(); ret = xml_parse_time(true, value, &label->format_time); @@ -478,7 +468,7 @@ static int _xml_parse_label(xmlTextReaderPtr reader, struct ltfs_label *label) ltfsmsg(LTFS_WARN, 17218W, "formattime", value); check_tag_end("formattime"); - } else if (! strcmp(name, "volumeuuid")) { + } else if (!strcmp(name, "volumeuuid")) { check_required_tag(2); get_tag_text(); if (xml_parse_uuid(label->vol_uuid, value) < 0) { @@ -487,7 +477,7 @@ static int _xml_parse_label(xmlTextReaderPtr reader, struct ltfs_label *label) } check_tag_end("volumeuuid"); - } else if (! strcmp(name, "location")) { + } else if (!strcmp(name, "location")) { check_required_tag(3); assert_not_empty(); if (_xml_parse_label_location(reader, label) < 0) { @@ -495,7 +485,7 @@ static int _xml_parse_label(xmlTextReaderPtr reader, struct ltfs_label *label) return -LTFS_XML_WRONG_LOC; } - } else if (! strcmp(name, "partitions")) { + } else if (!strcmp(name, "partitions")) { check_required_tag(4); assert_not_empty(); if (_xml_parse_partition_map(reader, label) < 0) { @@ -503,7 +493,7 @@ static int _xml_parse_label(xmlTextReaderPtr reader, struct ltfs_label *label) return -LTFS_XML_WRONG_PART_MAP; } - } else if (! strcmp(name, "blocksize")) { + } else if (!strcmp(name, "blocksize")) { check_required_tag(5); get_tag_text(); if (xml_parse_ull(&value_int, value) < 0 || value_int == 0) { @@ -513,7 +503,7 @@ static int _xml_parse_label(xmlTextReaderPtr reader, struct ltfs_label *label) label->blocksize = value_int; check_tag_end("blocksize"); - } else if (! strcmp(name, "compression")) { + } else if (!strcmp(name, "compression")) { check_required_tag(6); get_tag_text(); if (xml_parse_bool(&label->enable_compression, value) < 0) { @@ -552,7 +542,7 @@ static int _xml_parse_ip_criteria(xmlTextReaderPtr reader, struct ltfs_index *id while (true) { get_next_tag(); - if (! strcmp(name, "size")) { + if (!strcmp(name, "size")) { check_required_tag(0); get_tag_text(); if (xml_parse_ull(&value_int, value) < 0) { @@ -562,16 +552,13 @@ static int _xml_parse_ip_criteria(xmlTextReaderPtr reader, struct ltfs_index *id idx->original_criteria.max_filesize_criteria = value_int; check_tag_end("size"); - } else if (! strcmp(name, "name")) { - + } else if (!strcmp(name, "name")) { ++num_patterns; /* quite inefficient, but the number of patterns should be small. */ - idx->original_criteria.glob_patterns = realloc(idx->original_criteria.glob_patterns, - (num_patterns + 1) * sizeof(struct ltfs_name)); + idx->original_criteria.glob_patterns = + realloc(idx->original_criteria.glob_patterns, (num_patterns + 1) * sizeof(struct ltfs_name)); - if (_xml_parse_nametype(reader, - &idx->original_criteria.glob_patterns[num_patterns - 1], - false) < 0) { + if (_xml_parse_nametype(reader, &idx->original_criteria.glob_patterns[num_patterns - 1], false) < 0) { --num_patterns; } @@ -607,12 +594,11 @@ static int _xml_parse_policy(xmlTextReaderPtr reader, struct ltfs_index *idx) while (true) { get_next_tag(); - if (! strcmp(name, "indexpartitioncriteria")) { + if (!strcmp(name, "indexpartitioncriteria")) { check_required_tag(0); assert_not_empty(); ret = _xml_parse_ip_criteria(reader, idx); - if (ret < 0) - return ret; + if (ret < 0) return ret; } else ignore_unrecognized_tag(); @@ -641,7 +627,7 @@ static int _xml_parse_one_extent(xmlTextReaderPtr reader, int idx_version, struc while (true) { get_next_tag(); - if (! strcmp(name, "partition")) { + if (!strcmp(name, "partition")) { check_required_tag(0); get_tag_text(); if (_xml_parse_partition(value) < 0) { @@ -651,7 +637,7 @@ static int _xml_parse_one_extent(xmlTextReaderPtr reader, int idx_version, struc xt->start.partition = value[0]; check_tag_end("partition"); - } else if (! strcmp(name, "startblock")) { + } else if (!strcmp(name, "startblock")) { check_required_tag(1); get_tag_text(); if (xml_parse_ull(&value_int, value) < 0) { @@ -661,7 +647,7 @@ static int _xml_parse_one_extent(xmlTextReaderPtr reader, int idx_version, struc xt->start.block = value_int; check_tag_end("startblock"); - } else if (! strcmp(name, "byteoffset")) { + } else if (!strcmp(name, "byteoffset")) { check_required_tag(2); get_tag_text(); if (xml_parse_ull(&value_int, value) < 0) { @@ -671,7 +657,7 @@ static int _xml_parse_one_extent(xmlTextReaderPtr reader, int idx_version, struc xt->byteoffset = value_int; check_tag_end("byteoffset"); - } else if (! strcmp(name, "bytecount")) { + } else if (!strcmp(name, "bytecount")) { check_required_tag(3); get_tag_text(); if (xml_parse_ull(&value_int, value) < 0) { @@ -681,7 +667,7 @@ static int _xml_parse_one_extent(xmlTextReaderPtr reader, int idx_version, struc xt->bytecount = value_int; check_tag_end("bytecount"); - } else if (idx_version >= IDX_VERSION_SPARSE && ! strcmp(name, "fileoffset")) { + } else if (idx_version >= IDX_VERSION_SPARSE && !strcmp(name, "fileoffset")) { check_required_tag(4); get_tag_text(); if (xml_parse_ull(&value_int, value) < 0) { @@ -714,7 +700,8 @@ static int _xml_parse_one_extent(xmlTextReaderPtr reader, int idx_version, struc TAILQ_INSERT_TAIL(&d->extentlist, xt, list); else { bool xt_used = false; - TAILQ_FOREACH_REVERSE(xt_last, &d->extentlist, extent_struct, list) { + TAILQ_FOREACH_REVERSE(xt_last, &d->extentlist, extent_struct, list) + { if (xt_last->fileoffset + xt_last->bytecount <= xt->fileoffset) { TAILQ_INSERT_AFTER(&d->extentlist, xt_last, xt, list); xt_used = true; @@ -726,16 +713,14 @@ static int _xml_parse_one_extent(xmlTextReaderPtr reader, int idx_version, struc return -LTFS_XML_EXT_OVERLAP; } } - if (! xt_used) - TAILQ_INSERT_HEAD(&d->extentlist, xt, list); + if (!xt_used) TAILQ_INSERT_HEAD(&d->extentlist, xt, list); } d->realsize += xt->bytecount; if (d->vol) { d->used_blocks += ((xt->byteoffset + xt->bytecount) / d->vol->label->blocksize); - if ((xt->byteoffset + xt->bytecount) % d->vol->label->blocksize) - d->used_blocks++; + if ((xt->byteoffset + xt->bytecount) % d->vol->label->blocksize) d->used_blocks++; } return 0; @@ -752,11 +737,10 @@ static int _xml_parse_extents(xmlTextReaderPtr reader, int idx_version, struct d while (true) { get_next_tag(); - if (! strcmp(name, "extent")) { + if (!strcmp(name, "extent")) { assert_not_empty(); ret = _xml_parse_one_extent(reader, idx_version, d); - if (ret < 0) - return ret; + if (ret < 0) return ret; } else ignore_unrecognized_tag(); @@ -777,7 +761,7 @@ static int _xml_parse_one_xattr(xmlTextReaderPtr reader, struct dentry *d) declare_tracking_arrays_no_opt(2); xattr = calloc(1, sizeof(struct xattr_info)); - if (! xattr) { + if (!xattr) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } @@ -785,7 +769,7 @@ static int _xml_parse_one_xattr(xmlTextReaderPtr reader, struct dentry *d) while (true) { get_next_tag(); - if (! strcmp(name, "key")) { + if (!strcmp(name, "key")) { check_required_tag(0); /* Allow slash in xattr key */ @@ -798,7 +782,7 @@ static int _xml_parse_one_xattr(xmlTextReaderPtr reader, struct dentry *d) check_tag_end("key"); - } else if (! strcmp(name, "value")) { + } else if (!strcmp(name, "value")) { check_required_tag(1); xattr_type = (char *)xmlTextReaderGetAttribute(reader, BAD_CAST "type"); @@ -818,9 +802,9 @@ static int _xml_parse_one_xattr(xmlTextReaderPtr reader, struct dentry *d) return ret; } - if (! xattr_type || ! strcmp(xattr_type, "text")) { + if (!xattr_type || !strcmp(xattr_type, "text")) { xattr->value = arch_strdup(value); - if (! xattr->value) { + if (!xattr->value) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); free(xattr->key.name); free(xattr); @@ -828,8 +812,7 @@ static int _xml_parse_one_xattr(xmlTextReaderPtr reader, struct dentry *d) } xattr->size = strlen(value); } else { /* base64 */ - xattr->size = base64_decode((const unsigned char *)value, strlen(value), - (unsigned char **)(&xattr->value)); + xattr->size = base64_decode((const unsigned char *)value, strlen(value), (unsigned char **)(&xattr->value)); if (xattr->size == 0) { ltfsmsg(LTFS_ERR, 17028E); free(xattr->key.name); @@ -837,8 +820,7 @@ static int _xml_parse_one_xattr(xmlTextReaderPtr reader, struct dentry *d) return -LTFS_XML_XATTR_SIZE; } } - if (strlen(value) > 0) - check_tag_end("value"); + if (strlen(value) > 0) check_tag_end("value"); } else { xattr->value = NULL; xattr->size = 0; @@ -854,10 +836,10 @@ static int _xml_parse_one_xattr(xmlTextReaderPtr reader, struct dentry *d) if (xattr) { TAILQ_INSERT_TAIL(&d->xattrlist, xattr, list); - if (!strcmp(xattr->key.name, "ltfs.vendor.IBM.immutable") && !strcmp(xattr->value, "1") ) { + if (!strcmp(xattr->key.name, "ltfs.vendor.IBM.immutable") && !strcmp(xattr->value, "1")) { d->is_immutable = true; } - if (!strcmp(xattr->key.name, "ltfs.vendor.IBM.appendonly") && !strcmp(xattr->value, "1") ) { + if (!strcmp(xattr->key.name, "ltfs.vendor.IBM.appendonly") && !strcmp(xattr->value, "1")) { d->is_appendonly = true; } } @@ -876,11 +858,10 @@ static int _xml_parse_xattrs(xmlTextReaderPtr reader, struct dentry *d) while (true) { get_next_tag(); - if (! strcmp(name, "xattr")) { + if (!strcmp(name, "xattr")) { assert_not_empty(); ret = _xml_parse_one_xattr(reader, d); - if (ret < 0) - return ret; + if (ret < 0) return ret; } else ignore_unrecognized_tag(); @@ -909,19 +890,17 @@ static int _xml_parse_tapepos(xmlTextReaderPtr reader, const char *tag, struct t while (true) { get_next_tag(); - if (! strcmp(name, "partition")) { + if (!strcmp(name, "partition")) { check_required_tag(0); get_tag_text(); - if (_xml_parse_partition(value) < 0) - return -1; + if (_xml_parse_partition(value) < 0) return -1; pos->partition = value[0]; check_tag_end("partition"); - } else if (! strcmp(name, "startblock")) { + } else if (!strcmp(name, "startblock")) { check_required_tag(1); get_tag_text(); - if (xml_parse_ull(&value_int, value) < 0) - return -1; + if (xml_parse_ull(&value_int, value) < 0) return -1; pos->block = value_int; check_tag_end("startblock"); @@ -936,17 +915,17 @@ static int _xml_parse_tapepos(xmlTextReaderPtr reader, const char *tag, struct t /** * Save conflict of symlink, the node which has both symlink and extent */ -static int _xml_save_symlink_conflict( struct ltfs_index *idx, struct dentry *d) +static int _xml_save_symlink_conflict(struct ltfs_index *idx, struct dentry *d) { size_t c = idx->symerr_count + 1; struct dentry **err_d; - err_d = realloc( idx->symlink_conflict, c * sizeof(size_t)); - if (! err_d) { + err_d = realloc(idx->symlink_conflict, c * sizeof(size_t)); + if (!err_d) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } - err_d[c-1] = d; + err_d[c - 1] = d; idx->symlink_conflict = err_d; idx->symerr_count = c; @@ -957,18 +936,18 @@ static int _xml_save_symlink_conflict( struct ltfs_index *idx, struct dentry *d) /** * Parse a file into the given directory. */ -static int _xml_parse_file(xmlTextReaderPtr reader, struct ltfs_index *idx, struct dentry *dir, - struct name_list *filename) +static int +_xml_parse_file(xmlTextReaderPtr reader, struct ltfs_index *idx, struct dentry *dir, struct name_list *filename) { unsigned long long value_int; struct dentry *file; struct extent_info *xt_last; declare_parser_vars("file"); declare_tracking_arrays(9, 4); - bool symlink_flag=false, extent_flag=false, openforwrite=false; + bool symlink_flag = false, extent_flag = false, openforwrite = false; file = fs_allocate_dentry(dir, NULL, NULL, false, false, false, idx); - if (! file) { + if (!file) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } @@ -976,7 +955,7 @@ static int _xml_parse_file(xmlTextReaderPtr reader, struct ltfs_index *idx, stru while (true) { get_next_tag(); - if (! strcmp(name, "name")) { + if (!strcmp(name, "name")) { check_required_tag(0); ret = _xml_parse_nametype(reader, &file->name, false); @@ -1059,7 +1038,7 @@ static int _xml_parse_file(xmlTextReaderPtr reader, struct ltfs_index *idx, stru if (empty == 0) { ret = _xml_parse_xattrs(reader, file); - if(ret < 0) { + if (ret < 0) { ltfsmsg(LTFS_ERR, 17270E, "extendedattributes", file->name.name); return ret; } @@ -1070,13 +1049,14 @@ static int _xml_parse_file(xmlTextReaderPtr reader, struct ltfs_index *idx, stru check_empty(); if (empty == 0) { ret = _xml_parse_extents(reader, idx->version, file); - if(ret < 0) { + if (ret < 0) { ltfsmsg(LTFS_ERR, 17270E, "extentinfo", file->name.name); return ret; } - } else extent_flag = true; + } else + extent_flag = true; - } else if (!strcmp(name, "symlink")) { + } else if (!strcmp(name, "symlink")) { check_optional_tag(2); ret = _xml_parse_nametype(reader, &file->target, true); @@ -1097,12 +1077,11 @@ static int _xml_parse_file(xmlTextReaderPtr reader, struct ltfs_index *idx, stru if (xml_parse_bool(&openforwrite, value) < 0) { ltfsmsg(LTFS_WARN, 17252W, value, "openforwrite", (unsigned long long)file->uid); } else { - if (openforwrite) - ltfsmsg(LTFS_INFO, 17251I, file->name.name, (unsigned long long)file->uid); + if (openforwrite) ltfsmsg(LTFS_INFO, 17251I, file->name.name, (unsigned long long)file->uid); } check_tag_end("openforwrite"); - } else if (idx->version >= IDX_VERSION_UID && ! strcmp(name, UID_TAGNAME)) { + } else if (idx->version >= IDX_VERSION_UID && !strcmp(name, UID_TAGNAME)) { check_required_tag(7); get_tag_text(); if (xml_parse_ull(&value_int, value) < 0) { @@ -1110,14 +1089,13 @@ static int _xml_parse_file(xmlTextReaderPtr reader, struct ltfs_index *idx, stru return -LTFS_XML_WRONG_UID; } file->uid = value_int; - if (file->uid > idx->uid_number) - idx->uid_number = file->uid; - filename->uid = file->uid; + if (file->uid > idx->uid_number) idx->uid_number = file->uid; + filename->uid = file->uid; check_tag_end(UID_TAGNAME); - } else if (! strcmp(name, UID_TAGNAME)) { + } else if (!strcmp(name, UID_TAGNAME)) { ignore_unrecognized_tag(); - } else if (idx->version >= IDX_VERSION_BACKUPTIME && ! strcmp(name, BACKUPTIME_TAGNAME)) { + } else if (idx->version >= IDX_VERSION_BACKUPTIME && !strcmp(name, BACKUPTIME_TAGNAME)) { check_required_tag(8); get_tag_text(); ret = xml_parse_time(true, value, &file->backup_time); @@ -1128,7 +1106,7 @@ static int _xml_parse_file(xmlTextReaderPtr reader, struct ltfs_index *idx, stru ltfsmsg(LTFS_WARN, 17220W, "backuptime", file->name.name, (unsigned long long)file->uid, value); check_tag_end(BACKUPTIME_TAGNAME); - } else if (! strcmp(name, BACKUPTIME_TAGNAME)) { + } else if (!strcmp(name, BACKUPTIME_TAGNAME)) { ignore_unrecognized_tag(); } else @@ -1139,9 +1117,8 @@ static int _xml_parse_file(xmlTextReaderPtr reader, struct ltfs_index *idx, stru if (idx->version < IDX_VERSION_UID) { check_required_tag(7); file->uid = fs_allocate_uid(idx); - if (file->uid > idx->uid_number) - idx->uid_number = file->uid; - filename->uid = file->uid; + if (file->uid > idx->uid_number) idx->uid_number = file->uid; + filename->uid = file->uid; } /* For old index versions, set backup time equal to creation time */ @@ -1153,7 +1130,7 @@ static int _xml_parse_file(xmlTextReaderPtr reader, struct ltfs_index *idx, stru check_required_tags(); /* check that file size is not shorter than the extent list */ - if (! TAILQ_EMPTY(&file->extentlist)) { + if (!TAILQ_EMPTY(&file->extentlist)) { xt_last = TAILQ_LAST(&file->extentlist, extent_struct); if (xt_last->fileoffset + xt_last->bytecount > file->size) { ltfsmsg(LTFS_ERR, 17026E); @@ -1167,7 +1144,7 @@ static int _xml_parse_file(xmlTextReaderPtr reader, struct ltfs_index *idx, stru return -LTFS_XML_WRONG_UID; } - if ( symlink_flag && extent_flag ) { + if (symlink_flag && extent_flag) { ltfsmsg(LTFS_ERR, 17180E, file->name.name); ret = _xml_save_symlink_conflict(idx, file); if (ret < 0) { @@ -1183,9 +1160,11 @@ static int _xml_parse_file(xmlTextReaderPtr reader, struct ltfs_index *idx, stru * Parse a dir into the given directory. */ -static int _xml_parse_dirtree(xmlTextReaderPtr reader, struct dentry *parent, - struct ltfs_index *idx, struct ltfs_volume *vol, - struct name_list *dirname); /* Forward reference */ +static int _xml_parse_dirtree(xmlTextReaderPtr reader, + struct dentry *parent, + struct ltfs_index *idx, + struct ltfs_volume *vol, + struct name_list *dirname); /* Forward reference */ static int _xml_parse_dir_contents(xmlTextReaderPtr reader, struct dentry *dir, struct ltfs_index *idx) { @@ -1199,7 +1178,7 @@ static int _xml_parse_dir_contents(xmlTextReaderPtr reader, struct dentry *dir, while (true) { get_next_tag(); - if (! strcmp(name, "file")) { + if (!strcmp(name, "file")) { assert_not_empty(); entry_name = (struct name_list *)malloc(sizeof(struct name_list)); if (!entry_name) { @@ -1212,7 +1191,7 @@ static int _xml_parse_dir_contents(xmlTextReaderPtr reader, struct dentry *dir, return ret; } - } else if (! strcmp(name, "directory")) { + } else if (!strcmp(name, "directory")) { assert_not_empty(); entry_name = (struct name_list *)malloc(sizeof(struct name_list)); if (!entry_name) { @@ -1236,7 +1215,8 @@ static int _xml_parse_dir_contents(xmlTextReaderPtr reader, struct dentry *dir, if (errno == ENOMEM) { struct name_list *list_ptr, *list_tmp; - HASH_ITER(hh, list, list_ptr, list_tmp) { + HASH_ITER(hh, list, list_ptr, list_tmp) + { HASH_DEL(list, list_ptr); free(list_ptr); } @@ -1274,9 +1254,11 @@ static int _xml_parse_dir_contents(xmlTextReaderPtr reader, struct dentry *dir, * @param vol LTFS volume to which the index belongs. May be NULL. * @return 0 on success or a negative value on error */ -static int _xml_parse_dirtree(xmlTextReaderPtr reader, struct dentry *parent, - struct ltfs_index *idx, struct ltfs_volume *vol, - struct name_list *dirname) +static int _xml_parse_dirtree(xmlTextReaderPtr reader, + struct dentry *parent, + struct ltfs_index *idx, + struct ltfs_volume *vol, + struct name_list *dirname) { unsigned long long value_int; struct dentry *dir; @@ -1284,16 +1266,16 @@ static int _xml_parse_dirtree(xmlTextReaderPtr reader, struct dentry *parent, declare_parser_vars("directory"); declare_tracking_arrays(9, 1); - if (! parent && idx->root) { + if (!parent && idx->root) { dir = idx->root; dir->vol = vol; } else { dir = fs_allocate_dentry(parent, NULL, NULL, true, false, false, idx); - if (! dir) { + if (!dir) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } - if (! parent) { + if (!parent) { idx->root = dir; dir->vol = vol; ++dir->link_count; @@ -1332,8 +1314,7 @@ static int _xml_parse_dirtree(xmlTextReaderPtr reader, struct dentry *parent, return ret; } - if (idx->volume_name.name) - check_tag_end("name"); + if (idx->volume_name.name) check_tag_end("name"); } } @@ -1399,8 +1380,7 @@ static int _xml_parse_dirtree(xmlTextReaderPtr reader, struct dentry *parent, check_empty(); if (empty == 0) { ret = _xml_parse_dir_contents(reader, dir, idx); - if (ret < 0) - return ret; + if (ret < 0) return ret; } } else if (!strcmp(name, "extendedattributes")) { @@ -1408,13 +1388,13 @@ static int _xml_parse_dirtree(xmlTextReaderPtr reader, struct dentry *parent, check_empty(); if (empty == 0) { ret = _xml_parse_xattrs(reader, dir); - if(ret < 0) { + if (ret < 0) { ltfsmsg(LTFS_ERR, 17272E, "extendedattributes", dir->name.name); return ret; } } - } else if (idx->version >= IDX_VERSION_UID && ! strcmp(name, UID_TAGNAME)) { + } else if (idx->version >= IDX_VERSION_UID && !strcmp(name, UID_TAGNAME)) { check_required_tag(7); get_tag_text(); if (xml_parse_ull(&value_int, value) < 0) { @@ -1422,16 +1402,15 @@ static int _xml_parse_dirtree(xmlTextReaderPtr reader, struct dentry *parent, return -LTFS_XML_WRONG_UID; } dir->uid = value_int; - if (dir->uid > idx->uid_number) - idx->uid_number = dir->uid; + if (dir->uid > idx->uid_number) idx->uid_number = dir->uid; if (parent) { - dirname->uid = dir->uid; + dirname->uid = dir->uid; } check_tag_end(UID_TAGNAME); - } else if (! strcmp(name, UID_TAGNAME)) { + } else if (!strcmp(name, UID_TAGNAME)) { ignore_unrecognized_tag(); - } else if (idx->version >= IDX_VERSION_BACKUPTIME && ! strcmp(name, BACKUPTIME_TAGNAME)) { + } else if (idx->version >= IDX_VERSION_BACKUPTIME && !strcmp(name, BACKUPTIME_TAGNAME)) { check_required_tag(8); get_tag_text(); ret = xml_parse_time(true, value, &dir->backup_time); @@ -1442,7 +1421,7 @@ static int _xml_parse_dirtree(xmlTextReaderPtr reader, struct dentry *parent, ltfsmsg(LTFS_WARN, 17220W, "backuptime", dir->name.name, (unsigned long long)dir->uid, value); check_tag_end(BACKUPTIME_TAGNAME); - } else if (! strcmp(name, BACKUPTIME_TAGNAME)) { + } else if (!strcmp(name, BACKUPTIME_TAGNAME)) { ignore_unrecognized_tag(); } else @@ -1454,9 +1433,8 @@ static int _xml_parse_dirtree(xmlTextReaderPtr reader, struct dentry *parent, check_required_tag(7); if (parent) { dir->uid = fs_allocate_uid(idx); - if (dir->uid > idx->uid_number) - idx->uid_number = dir->uid; - dirname->uid = dir->uid; + if (dir->uid > idx->uid_number) idx->uid_number = dir->uid; + dirname->uid = dir->uid; } /* root directory already got assigned UID 1 by fs_allocate_dentry */ } @@ -1474,7 +1452,7 @@ static int _xml_parse_dirtree(xmlTextReaderPtr reader, struct dentry *parent, if (parent && dir->uid == 1) { ltfsmsg(LTFS_ERR, 17101E, dir->name.name); return -LTFS_XML_INVALID_UID; - } else if (! parent && dir->uid != 1) { + } else if (!parent && dir->uid != 1) { ltfsmsg(LTFS_ERR, 17100E); return -LTFS_XML_INVALID_UID; } else if (dir->uid == 0) { @@ -1500,29 +1478,30 @@ static int _xml_parse_schema(xmlTextReaderPtr reader, struct ltfs_index *idx, st declare_tracking_arrays(8, 4); /* start the parser: find top-level "index" tag, check version and encoding */ - ret = _xml_parser_init(reader, parent_tag, &idx->version, - LTFS_INDEX_VERSION_MIN, LTFS_INDEX_VERSION_MAX); - if (ret < 0) - return ret; + ret = _xml_parser_init(reader, parent_tag, &idx->version, LTFS_INDEX_VERSION_MIN, LTFS_INDEX_VERSION_MAX); + if (ret < 0) return ret; if (idx->version < LTFS_INDEX_VERSION) - ltfsmsg(LTFS_WARN, 17095W, - LTFS_INDEX_VERSION_STR, - LTFS_FORMAT_MAJOR(idx->version), - LTFS_FORMAT_MINOR(idx->version), - LTFS_FORMAT_REVISION(idx->version)); + ltfsmsg(LTFS_WARN, + 17095W, + LTFS_INDEX_VERSION_STR, + LTFS_FORMAT_MAJOR(idx->version), + LTFS_FORMAT_MINOR(idx->version), + LTFS_FORMAT_REVISION(idx->version)); else if (idx->version / 100 > LTFS_INDEX_VERSION / 100) - ltfsmsg(LTFS_WARN, 17096W, - LTFS_INDEX_VERSION_STR, - LTFS_FORMAT_MAJOR(idx->version), - LTFS_FORMAT_MINOR(idx->version), - LTFS_FORMAT_REVISION(idx->version)); + ltfsmsg(LTFS_WARN, + 17096W, + LTFS_INDEX_VERSION_STR, + LTFS_FORMAT_MAJOR(idx->version), + LTFS_FORMAT_MINOR(idx->version), + LTFS_FORMAT_REVISION(idx->version)); else if (idx->version > LTFS_INDEX_VERSION) - ltfsmsg(LTFS_WARN, 17234W, - LTFS_INDEX_VERSION_STR, - LTFS_FORMAT_MAJOR(idx->version), - LTFS_FORMAT_MINOR(idx->version), - LTFS_FORMAT_REVISION(idx->version)); + ltfsmsg(LTFS_WARN, + 17234W, + LTFS_INDEX_VERSION_STR, + LTFS_FORMAT_MAJOR(idx->version), + LTFS_FORMAT_MINOR(idx->version), + LTFS_FORMAT_REVISION(idx->version)); if (idx->commit_message) { free(idx->commit_message); @@ -1533,11 +1512,10 @@ static int _xml_parse_schema(xmlTextReaderPtr reader, struct ltfs_index *idx, st while (true) { get_next_tag(); - if (! strcmp(name, "creator")) { + if (!strcmp(name, "creator")) { check_required_tag(0); get_tag_text(); - if (idx->creator) - free(idx->creator); + if (idx->creator) free(idx->creator); idx->creator = arch_strdup(value); if (!idx->creator) { ltfsmsg(LTFS_ERR, 10001E, name); @@ -1545,14 +1523,13 @@ static int _xml_parse_schema(xmlTextReaderPtr reader, struct ltfs_index *idx, st } check_tag_end("creator"); - } else if (! strcmp(name, "volumeuuid")) { + } else if (!strcmp(name, "volumeuuid")) { check_required_tag(1); get_tag_text(); - if (xml_parse_uuid(idx->vol_uuid, value) < 0) - return -LTFS_XML_WRONG_UUID; + if (xml_parse_uuid(idx->vol_uuid, value) < 0) return -LTFS_XML_WRONG_UUID; check_tag_end("volumeuuid"); - } else if (! strcmp(name, "generationnumber")) { + } else if (!strcmp(name, "generationnumber")) { check_required_tag(2); get_tag_text(); if (xml_parse_ull(&value_int, value) < 0) { @@ -1562,7 +1539,7 @@ static int _xml_parse_schema(xmlTextReaderPtr reader, struct ltfs_index *idx, st idx->generation = value_int; check_tag_end("generationnumber"); - } else if (! strcmp(name, "updatetime")) { + } else if (!strcmp(name, "updatetime")) { check_required_tag(3); get_tag_text(); ret = xml_parse_time(true, value, &idx->mod_time); @@ -1573,41 +1550,35 @@ static int _xml_parse_schema(xmlTextReaderPtr reader, struct ltfs_index *idx, st check_tag_end("updatetime"); - } else if (! strcmp(name, "location")) { + } else if (!strcmp(name, "location")) { check_required_tag(4); assert_not_empty(); - if (_xml_parse_tapepos(reader, "location", &idx->selfptr) < 0) - return -LTFS_XML_WRONG_LOC; + if (_xml_parse_tapepos(reader, "location", &idx->selfptr) < 0) return -LTFS_XML_WRONG_LOC; - } else if (! strcmp(name, "allowpolicyupdate")) { + } else if (!strcmp(name, "allowpolicyupdate")) { check_required_tag(5); get_tag_text(); - if (xml_parse_bool(&idx->criteria_allow_update, value) < 0) - return -LTFS_XML_WRONG_PA; + if (xml_parse_bool(&idx->criteria_allow_update, value) < 0) return -LTFS_XML_WRONG_PA; check_tag_end("allowpolicyupdate"); - } else if (! strcmp(name, "directory")) { + } else if (!strcmp(name, "directory")) { check_required_tag(6); assert_not_empty(); ret = _xml_parse_dirtree(reader, NULL, idx, vol, NULL); - if (ret < 0) - return ret; + if (ret < 0) return ret; - } - else if (!strcmp(name, "previousgenerationlocation")) { + } else if (!strcmp(name, "previousgenerationlocation")) { check_optional_tag(0); assert_not_empty(); - if (_xml_parse_tapepos(reader, "previousgenerationlocation", &idx->backptr) < 0) - return -LTFS_XML_WRONG_LOC_PREV; + if (_xml_parse_tapepos(reader, "previousgenerationlocation", &idx->backptr) < 0) return -LTFS_XML_WRONG_LOC_PREV; - } else if (! strcmp(name, "dataplacementpolicy")) { + } else if (!strcmp(name, "dataplacementpolicy")) { check_optional_tag(1); assert_not_empty(); ret = _xml_parse_policy(reader, idx); - if (ret < 0) - return ret; + if (ret < 0) return ret; - } else if (! strcmp(name, "comment")) { + } else if (!strcmp(name, "comment")) { check_optional_tag(2); get_tag_text(); if (strlen(value) > INDEX_MAX_COMMENT_LEN) { @@ -1621,7 +1592,7 @@ static int _xml_parse_schema(xmlTextReaderPtr reader, struct ltfs_index *idx, st } check_tag_end("comment"); - } else if (! strcmp(name, "volumelockstate")) { + } else if (!strcmp(name, "volumelockstate")) { check_optional_tag(3); get_tag_text(); @@ -1634,16 +1605,14 @@ static int _xml_parse_schema(xmlTextReaderPtr reader, struct ltfs_index *idx, st } check_tag_end("volumelockstate"); - } else if (idx->version >= IDX_VERSION_UID && ! strcmp(name, NEXTUID_TAGNAME)) { + } else if (idx->version >= IDX_VERSION_UID && !strcmp(name, NEXTUID_TAGNAME)) { check_required_tag(7); get_tag_text(); - if (xml_parse_ull(&value_int, value) < 0) - return -LTFS_XML_WRONG_NEXT; - if (value_int > idx->uid_number) - idx->uid_number = value_int; + if (xml_parse_ull(&value_int, value) < 0) return -LTFS_XML_WRONG_NEXT; + if (value_int > idx->uid_number) idx->uid_number = value_int; check_tag_end(NEXTUID_TAGNAME); - } else if (! strcmp(name, NEXTUID_TAGNAME)) { + } else if (!strcmp(name, NEXTUID_TAGNAME)) { ignore_unrecognized_tag(); } else @@ -1653,12 +1622,11 @@ static int _xml_parse_schema(xmlTextReaderPtr reader, struct ltfs_index *idx, st /* For older index versions, assume we handle UIDs correctly. * The idx->uid_number field is automatically initialized to 1, so it will be set correctly * once all files and directories are parsed. */ - if (idx->version < IDX_VERSION_UID) - check_required_tag(7); + if (idx->version < IDX_VERSION_UID) check_required_tag(7); check_required_tags(); - if ( idx->symerr_count != 0 ) { + if (idx->symerr_count != 0) { return -LTFS_SYMLINK_CONFLICT; } @@ -1674,11 +1642,10 @@ static int _xml_parse_symlink_target(xmlTextReaderPtr reader, int idx_version, s while (true) { get_next_tag(); - if (! strcmp(name, "target")) { + if (!strcmp(name, "target")) { d->isslink = true; ret = _xml_parse_nametype(reader, &d->target, true); - if (ret < 0) - return ret; + if (ret < 0) return ret; } else ignore_unrecognized_tag(); } @@ -1697,7 +1664,7 @@ static int _xml_symlinkinfo_from_file(const char *filename, struct dentry *d) CHECK_ARG_NULL(d, -LTFS_NULL_ARG); reader = xmlReaderForFile(filename, NULL, XML_PARSE_NOERROR | XML_PARSE_NOWARNING); - if (! reader) { + if (!reader) { ltfsmsg(LTFS_ERR, 17011E, filename); return -1; } @@ -1709,7 +1676,7 @@ static int _xml_symlinkinfo_from_file(const char *filename, struct dentry *d) while (true) { get_next_tag(); - if (! strcmp(name, "symlink")) { + if (!strcmp(name, "symlink")) { ret = _xml_parse_symlink_target(reader, IDX_VERSION_SPARSE, d); if (ret < 0) { /* XML parser: failed to read extent list from file (%d) */ @@ -1719,8 +1686,7 @@ static int _xml_symlinkinfo_from_file(const char *filename, struct dentry *d) break; } - if (doc) - xmlFreeDoc(doc); + if (doc) xmlFreeDoc(doc); xmlFreeTextReader(reader); return ret; @@ -1745,7 +1711,7 @@ static int _xml_extentlist_from_file(const char *filename, struct dentry *d) CHECK_ARG_NULL(d, -LTFS_NULL_ARG); reader = xmlReaderForFile(filename, NULL, XML_PARSE_NOERROR | XML_PARSE_NOWARNING); - if (! reader) { + if (!reader) { ltfsmsg(LTFS_ERR, 17011E, filename); return -1; } @@ -1755,9 +1721,10 @@ static int _xml_extentlist_from_file(const char *filename, struct dentry *d) * xmlDocFree call is required to free all memory. */ doc = xmlTextReaderCurrentDoc(reader); - while (true) { /* BEAM: loop doesn't iterate - Because get_next_tag() macro uses "break", at most once loop is needed here. */ + while ( + true) { /* BEAM: loop doesn't iterate - Because get_next_tag() macro uses "break", at most once loop is needed here. */ get_next_tag(); - if (! strcmp(name, "extentinfo")) { + if (!strcmp(name, "extentinfo")) { ret = _xml_parse_extents(reader, IDX_VERSION_SPARSE, d); if (ret < 0) { /* XML parser: failed to read extent list from file (%d) */ @@ -1767,8 +1734,7 @@ static int _xml_extentlist_from_file(const char *filename, struct dentry *d) break; } - if (doc) - xmlFreeDoc(doc); + if (doc) xmlFreeDoc(doc); xmlFreeTextReader(reader); return ret; @@ -1787,14 +1753,13 @@ int xml_label_from_file(const char *filename, struct ltfs_label *label) CHECK_ARG_NULL(label, -LTFS_NULL_ARG); reader = xmlReaderForFile(filename, NULL, XML_PARSE_NOERROR | XML_PARSE_NOWARNING); - if (! reader) { + if (!reader) { ltfsmsg(LTFS_ERR, 17007E, filename); return -1; } ret = _xml_parse_label(reader, label); - if (ret < 0) - ltfsmsg(LTFS_ERR, 17008E, filename); + if (ret < 0) ltfsmsg(LTFS_ERR, 17008E, filename); xmlFreeTextReader(reader); return ret; @@ -1809,7 +1774,7 @@ int xml_label_from_mem(const char *buf, int buf_size, struct ltfs_label *label) CHECK_ARG_NULL(label, -LTFS_NULL_ARG); reader = xmlReaderForMemory(buf, buf_size, NULL, NULL, XML_PARSE_NOERROR | XML_PARSE_NOWARNING); - if (! reader) { + if (!reader) { ltfsmsg(LTFS_ERR, 17009E); return -LTFS_LIBXML2_FAILURE; } @@ -1843,7 +1808,7 @@ int xml_schema_from_file(const char *filename, struct ltfs_index *idx, struct lt CHECK_ARG_NULL(idx, -LTFS_NULL_ARG); reader = xmlReaderForFile(filename, NULL, XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_HUGE); - if (! reader) { + if (!reader) { ltfsmsg(LTFS_ERR, 17011E, filename); return -LTFS_FILE_ERR; } @@ -1853,16 +1818,13 @@ int xml_schema_from_file(const char *filename, struct ltfs_index *idx, struct lt * xmlDocFree call is required to free all memory. */ doc = xmlTextReaderCurrentDoc(reader); ret = _xml_parse_schema(reader, idx, vol); - if (ret < 0) - ltfsmsg(LTFS_ERR, 17012E, filename, ret); - if (doc) - xmlFreeDoc(doc); + if (ret < 0) ltfsmsg(LTFS_ERR, 17012E, filename, ret); + if (doc) xmlFreeDoc(doc); xmlFreeTextReader(reader); #ifdef DEBUG /* dump the tree if it isn't too large */ - if (ret == 0 && idx->file_count < 1000) - fs_dump_tree(idx->root); + if (ret == 0 && idx->file_count < 1000) fs_dump_tree(idx->root); #endif return ret; @@ -1898,12 +1860,12 @@ int xml_schema_from_tape(uint64_t eod_pos, struct ltfs_volume *vol) /* Create output callback context data structure. */ ctx = malloc(sizeof(struct xml_input_tape)); - if (! ctx) { + if (!ctx) { ltfsmsg(LTFS_ERR, 10001E, "xml_schema_from_tape: ctx"); return -LTFS_NO_MEMORY; } ctx->buf = malloc(vol->label->blocksize + LTFS_CRC_SIZE); - if (! ctx->buf) { + if (!ctx->buf) { ltfsmsg(LTFS_ERR, 10001E, "xml_schema_from_tape: ctx->buf"); free(ctx); return -LTFS_NO_MEMORY; @@ -1919,10 +1881,9 @@ int xml_schema_from_tape(uint64_t eod_pos, struct ltfs_volume *vol) ctx->buf_used = 0; /* Create input buffer pointer. */ - read_buf = xmlParserInputBufferCreateIO(xml_input_tape_read_callback, - xml_input_tape_close_callback, - ctx, XML_CHAR_ENCODING_NONE); - if (! read_buf) { + read_buf = xmlParserInputBufferCreateIO( + xml_input_tape_read_callback, xml_input_tape_close_callback, ctx, XML_CHAR_ENCODING_NONE); + if (!read_buf) { ltfsmsg(LTFS_ERR, 17014E); free(ctx->buf); free(ctx); @@ -1931,7 +1892,7 @@ int xml_schema_from_tape(uint64_t eod_pos, struct ltfs_volume *vol) /* Create XML reader. */ reader = xmlNewTextReader(read_buf, NULL); - if (! reader) { + if (!reader) { ltfsmsg(LTFS_ERR, 17015E); xmlFreeParserInputBuffer(read_buf); free(ctx->buf); @@ -1971,14 +1932,13 @@ int xml_schema_from_tape(uint64_t eod_pos, struct ltfs_volume *vol) ret = -LTFS_INDEX_INVALID; } } else if (ret == 0) { - if(!ctx->saw_file_mark) { + if (!ctx->saw_file_mark) { /* Return positive value intentionally, for recovering later */ ret = LTFS_NO_TRAIL_FM; } } - if (doc) - xmlFreeDoc(doc); + if (doc) xmlFreeDoc(doc); xmlFreeTextReader(reader); xmlFreeParserInputBuffer(read_buf); @@ -1987,8 +1947,7 @@ int xml_schema_from_tape(uint64_t eod_pos, struct ltfs_volume *vol) #ifdef DEBUG /* dump the tree if it isn't too large */ - if (ret >= 0 && vol->index->file_count < 1000) - fs_dump_tree(vol->index->root); + if (ret >= 0 && vol->index->file_count < 1000) fs_dump_tree(vol->index->root); #endif return ret; @@ -2009,7 +1968,7 @@ int xml_extent_symlink_info_from_file(const char *filename, struct dentry *d) ret = _xml_extentlist_from_file(filename, d); - if (d->realsize==0) { + if (d->realsize == 0) { ret = _xml_symlinkinfo_from_file(filename, d); } diff --git a/src/libltfs/xml_writer.c b/src/libltfs/xml_writer.c index 1f2944d4..c2bd6746 100644 --- a/src/libltfs/xml_writer.c +++ b/src/libltfs/xml_writer.c @@ -54,18 +54,18 @@ #include #include +#include "arch/time_internal.h" +#include "fs.h" #include "libltfs/arch/ltfs_arch_ops.h" #include "ltfs.h" -#include "xml.h" -#include "fs.h" -#include "tape.h" #include "pathname.h" -#include "arch/time_internal.h" +#include "tape.h" +#include "xml.h" /** * Format a raw timespec structure for the XML file. */ -int xml_format_time(struct ltfs_timespec t, char** out) +int xml_format_time(struct ltfs_timespec t, char **out) { char *timebuf; struct tm tm, *gmt; @@ -77,7 +77,7 @@ int xml_format_time(struct ltfs_timespec t, char** out) sec = t.tv_sec; gmt = ltfs_gmtime(&sec, &tm); - if (! gmt) { + if (!gmt) { ltfsmsg(LTFS_ERR, 17056E); return -1; } @@ -87,8 +87,16 @@ int xml_format_time(struct ltfs_timespec t, char** out) ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -1; } - arch_sprintf(timebuf, (31*sizeof(char)), "%04d-%02d-%02dT%02d:%02d:%02d.%09ldZ", tm.tm_year + 1900, tm.tm_mon + 1, - tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, t.tv_nsec); + arch_sprintf(timebuf, + (31 * sizeof(char)), + "%04d-%02d-%02dT%02d:%02d:%02d.%09ldZ", + tm.tm_year + 1900, + tm.tm_mon + 1, + tm.tm_mday, + tm.tm_hour, + tm.tm_min, + tm.tm_sec, + t.tv_nsec); *out = timebuf; return noramized; @@ -102,14 +110,12 @@ int xml_output_tape_write_callback(void *context, const char *buffer, int len) { ssize_t ret; struct xml_output_tape *ctx = context; - uint32_t copy_count; /* number of bytes of "buffer" to write immediately */ + uint32_t copy_count; /* number of bytes of "buffer" to write immediately */ uint32_t bytes_remaining; /* number of input bytes waiting to be handled */ - if (len == 0) - return 0; + if (len == 0) return 0; - if (ctx->err_code || ctx->errno_fd) - return -1; + if (ctx->err_code || ctx->errno_fd) return -1; if (ctx->buf_used + len < ctx->buf_size) { memcpy(ctx->buf + ctx->buf_used, buffer, len); @@ -138,8 +144,7 @@ int xml_output_tape_write_callback(void *context, const char *buffer, int len) ctx->buf_used = 0; bytes_remaining -= copy_count; } while (bytes_remaining > ctx->buf_size); - if (bytes_remaining > 0) - memcpy(ctx->buf, buffer + (len - bytes_remaining), bytes_remaining); + if (bytes_remaining > 0) memcpy(ctx->buf, buffer + (len - bytes_remaining), bytes_remaining); ctx->buf_used = bytes_remaining; } @@ -162,8 +167,7 @@ int xml_output_tape_close_callback(void *context) ctx->err_code = ret_t; ret = -1; } else { - if (ctx->fd >= 0) - ret_d = arch_write(ctx->fd, ctx->buf, ctx->buf_used); + if (ctx->fd >= 0) ret_d = arch_write(ctx->fd, ctx->buf, ctx->buf_used); if (ret_d < 0) { ltfsmsg(LTFS_ERR, 17245E, (int)errno); ctx->errno_fd = -LTFS_CACHE_IO; @@ -225,10 +229,11 @@ int xml_output_fd_close_callback(void *context) #define COPY_BUF_SIZE (512 * KB) #ifdef _WIN32 -#include -#include +# include +# include -int ftruncate(int fd, off_t length) { +int ftruncate(int fd, off_t length) +{ HANDLE hFile = (HANDLE)_get_osfhandle(fd); if (hFile == INVALID_HANDLE_VALUE) { return -1; @@ -250,7 +255,6 @@ int ftruncate(int fd, off_t length) { #endif - static int _copy_file_contents(int dest, int src) { int ret = 0; @@ -264,14 +268,14 @@ static int _copy_file_contents(int dest, int src) } ret = lseek(src, 0, SEEK_SET); - if (ret < 0){ + if (ret < 0) { ltfsmsg(LTFS_ERR, 17246E, "source seek", errno); free(buf); return -LTFS_CACHE_IO; } ret = lseek(dest, 0, SEEK_SET); - if (ret < 0){ + if (ret < 0) { ltfsmsg(LTFS_ERR, 17246E, "destination seek", errno); free(buf); return -LTFS_CACHE_IO; @@ -306,13 +310,13 @@ static int _copy_file_contents(int dest, int src) } ret = lseek(src, 0, SEEK_SET); - if (ret < 0){ + if (ret < 0) { ltfsmsg(LTFS_ERR, 17246E, "source seek (P)", errno); return -LTFS_CACHE_IO; } ret = lseek(dest, 0, SEEK_SET); - if (ret < 0){ + if (ret < 0) { ltfsmsg(LTFS_ERR, 17246E, "destination seek (P)", errno); return -LTFS_CACHE_IO; } @@ -326,9 +330,9 @@ static int _copy_file_contents(int dest, int src) * @param write true if write lock * @param bk backup fd to revert */ -const struct timespec lock_wait = {0, 100000000}; /* 100ms */ -const struct timespec lock_zero = {0, 0}; -#define LOCK_RETRIES (12000) /* 100ms x 12,000 = 1200sec = 20 min */ +const struct timespec lock_wait = { 0, 100000000 }; /* 100ms */ +const struct timespec lock_zero = { 0, 0 }; +#define LOCK_RETRIES (12000) /* 100ms x 12,000 = 1200sec = 20 min */ int xml_acquire_file_lock(const char *file, int *fd, int *bk_fd, bool is_write) { int ret = -LTFS_CACHE_IO; @@ -342,7 +346,7 @@ int xml_acquire_file_lock(const char *file, int *fd, int *bk_fd, bool is_write) *fd = *bk_fd = -1; /* Open specified file to lock */ - arch_open(fd,file,O_RDWR | O_CREAT | O_BINARY, SHARE_FLAG_DENYRW, PERMISSION_READWRITE); + arch_open(fd, file, O_RDWR | O_CREAT | O_BINARY, SHARE_FLAG_DENYRW, PERMISSION_READWRITE); if (*fd < 0) { /* Failed to open the advisory lock '%s' (%d) */ errno_save = errno; @@ -352,8 +356,8 @@ int xml_acquire_file_lock(const char *file, int *fd, int *bk_fd, bool is_write) #ifndef mingw_PLATFORM /* There isn't flock in windows */ int retry_count = 0; - struct timespec next_wait = lock_wait; - struct timespec remaining = {0, 0}; + struct timespec next_wait = lock_wait; + struct timespec remaining = { 0, 0 }; retry: /* Acquire lock */ @@ -410,14 +414,13 @@ int xml_acquire_file_lock(const char *file, int *fd, int *bk_fd, bool is_write) /* Create backup file if required */ if (bk_fd) { asprintf(&backup_file, "%s.%s", file, "bk"); - if (!backup_file){ + if (!backup_file) { ltfsmsg(LTFS_ERR, 10001E, "xml_acquire_file_lock: backup name"); arch_close(*fd); *fd = -1; goto out; } - arch_open(bk_fd,backup_file, - O_RDWR | O_CREAT | O_BINARY | O_TRUNC,SHARE_FLAG_DENYRW, PERMISSION_READWRITE); + arch_open(bk_fd, backup_file, O_RDWR | O_CREAT | O_BINARY | O_TRUNC, SHARE_FLAG_DENYRW, PERMISSION_READWRITE); if (*bk_fd < 0) { ltfsmsg(LTFS_ERR, 17246E, "backup file creation", errno); errno_save = errno; @@ -451,7 +454,7 @@ int xml_acquire_file_lock(const char *file, int *fd, int *bk_fd, bool is_write) } ret = ftruncate(*fd, 0); - if (ret < 0){ + if (ret < 0) { ltfsmsg(LTFS_ERR, 17246E, "truncate", errno); errno_save = errno; arch_close(*fd); @@ -464,7 +467,7 @@ int xml_acquire_file_lock(const char *file, int *fd, int *bk_fd, bool is_write) ret = 0; out: - errno = errno_save; + errno = errno_save; return ret; } @@ -508,10 +511,10 @@ int xml_release_file_lock(const char *file, int fd, int bk_fd, bool revert) if (fd >= 0) arch_close(fd); if (bk_fd >= 0) arch_close(bk_fd); - errno = errno_save; + errno = errno_save; asprintf(&backup_file, "%s.%s", file, "bk"); - if (!backup_file){ + if (!backup_file) { ltfsmsg(LTFS_ERR, 10001E, "xml_release_file_lock: backup name"); ret = -LTFS_NO_MEMORY; } else { diff --git a/src/libltfs/xml_writer_libltfs.c b/src/libltfs/xml_writer_libltfs.c index 7b1ae2be..18a43fcb 100644 --- a/src/libltfs/xml_writer_libltfs.c +++ b/src/libltfs/xml_writer_libltfs.c @@ -55,20 +55,20 @@ ************************************************************************************* */ -#include "ltfs.h" -#include "xml_libltfs.h" +#include "arch/time_internal.h" #include "fs.h" -#include "tape.h" +#include "ltfs.h" #include "pathname.h" -#include "arch/time_internal.h" +#include "tape.h" +#include "xml_libltfs.h" #ifdef mingw_PLATFORM -#include "unicode/umachine.h" -#include "unicode/utf8.h" +# include "unicode/umachine.h" +# include "unicode/utf8.h" #endif /* Structure to control EE's file offset cache and sync file list */ struct ltfsee_cache { - FILE* fp; /* File pointer */ + FILE *fp; /* File pointer */ uint64_t count; /* File count to write */ }; @@ -79,17 +79,18 @@ struct ltfsee_cache static int encode_entry_name(char **new_name, const char *name) { int len; - UChar32 c=0; + UChar32 c = 0; /* Printable ASCII characters * !\"#$&`'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; * * In this encoding, only `:` and `%` is encoded in this printable character set */ - static char plain_chars[] = "!\"#$&`'()*+,-./0123456789;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; + static char plain_chars[] = + "!\"#$&`'()*+,-./0123456789;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; char *tmp_name; char buf_encode[3]; - int i=0, count=0, prev=0, j=0; + int i = 0, count = 0, prev = 0, j = 0; CHECK_ARG_NULL(name, -LTFS_NULL_ARG); @@ -109,7 +110,7 @@ static int encode_entry_name(char **new_name, const char *name) return -LTFS_ICU_ERROR; } - if (strchr(plain_chars, name[prev])) { + if (strchr(plain_chars, name[prev])) { // encode is not needed. tmp_name[j] = name[prev]; j++; @@ -117,10 +118,10 @@ static int encode_entry_name(char **new_name, const char *name) } while (count < i - prev) { - arch_sprintf_auto(buf_encode, "%02X", name[prev+count] & 0xFF); + arch_sprintf_auto(buf_encode, "%02X", name[prev + count] & 0xFF); tmp_name[j] = '%'; - tmp_name[j+1] = buf_encode[0]; - tmp_name[j+2] = buf_encode[1]; + tmp_name[j + 1] = buf_encode[0]; + tmp_name[j + 2] = buf_encode[1]; j += 3; count++; } @@ -224,9 +225,10 @@ static int _xml_write_xattr(xmlTextWriterPtr writer, const struct dentry *file) int ret; struct xattr_info *xattr; - if (! TAILQ_EMPTY(&file->xattrlist)) { + if (!TAILQ_EMPTY(&file->xattrlist)) { xml_mktag(xmlTextWriterStartElement(writer, BAD_CAST "extendedattributes"), -1); - TAILQ_FOREACH(xattr, &file->xattrlist, list) { + TAILQ_FOREACH(xattr, &file->xattrlist, list) + { xml_mktag(xmlTextWriterStartElement(writer, BAD_CAST "xattr"), -1); xml_mktag(_xml_write_nametype(writer, "key", &xattr->key), -1); @@ -238,14 +240,12 @@ static int _xml_write_xattr(xmlTextWriterPtr writer, const struct dentry *file) return -1; } else if (ret > 0) { xml_mktag(xmlTextWriterStartElement(writer, BAD_CAST "value"), -1); - xml_mktag( - xmlTextWriterWriteAttribute(writer, BAD_CAST "type", BAD_CAST "base64"), - -1); + xml_mktag(xmlTextWriterWriteAttribute(writer, BAD_CAST "type", BAD_CAST "base64"), -1); xml_mktag(xmlTextWriterWriteBase64(writer, xattr->value, 0, xattr->size), -1); xml_mktag(xmlTextWriterEndElement(writer), -1); } else { - xml_mktag(xmlTextWriterWriteFormatElement( - writer, BAD_CAST "value", "%.*s", (int)xattr->size, xattr->value), -1); + xml_mktag(xmlTextWriterWriteFormatElement(writer, BAD_CAST "value", "%.*s", (int)xattr->size, xattr->value), + -1); } } else { /* write empty value tag */ xml_mktag(xmlTextWriterStartElement(writer, BAD_CAST "value"), -1); @@ -265,7 +265,10 @@ static int _xml_write_xattr(xmlTextWriterPtr writer, const struct dentry *file) * @param file the file to write * @return 0 on success or -1 on failure */ -static int _xml_write_file(xmlTextWriterPtr writer, struct dentry *file, struct ltfsee_cache* offset_c, struct ltfsee_cache* sync_list) +static int _xml_write_file(xmlTextWriterPtr writer, + struct dentry *file, + struct ltfsee_cache *offset_c, + struct ltfsee_cache *sync_list) { struct extent_info *extent; bool write_offset = false; @@ -281,40 +284,33 @@ static int _xml_write_file(xmlTextWriterPtr writer, struct dentry *file, struct xml_mktag(_xml_write_nametype(writer, "name", &file->name), -1); - xml_mktag(xmlTextWriterWriteFormatElement( - writer, BAD_CAST "length", "%"PRIu64, file->size), -1); - xml_mktag(xmlTextWriterWriteElement( - writer, BAD_CAST "readonly", BAD_CAST (file->readonly ? "true" : "false")), -1); + xml_mktag(xmlTextWriterWriteFormatElement(writer, BAD_CAST "length", "%" PRIu64, file->size), -1); + xml_mktag(xmlTextWriterWriteElement(writer, BAD_CAST "readonly", BAD_CAST(file->readonly ? "true" : "false")), -1); xml_mktag(_xml_write_dentry_times(writer, file), -1); - xml_mktag(xmlTextWriterWriteFormatElement( - writer, BAD_CAST UID_TAGNAME, "%"PRIu64, file->uid), -1); + xml_mktag(xmlTextWriterWriteFormatElement(writer, BAD_CAST UID_TAGNAME, "%" PRIu64, file->uid), -1); /* write extended attributes */ xml_mktag(_xml_write_xattr(writer, file), -1); /* write extents */ - if (file->isslink) { + if (file->isslink) { xml_mktag(_xml_write_nametype(writer, "symlink", &file->target), -1); - } else if (! TAILQ_EMPTY(&file->extentlist)) { + } else if (!TAILQ_EMPTY(&file->extentlist)) { xml_mktag(xmlTextWriterStartElement(writer, BAD_CAST "extentinfo"), -1); - TAILQ_FOREACH(extent, &file->extentlist, list) { + TAILQ_FOREACH(extent, &file->extentlist, list) + { /* Write file offset cache */ - if (offset_c->fp && ! write_offset) { - fprintf(offset_c->fp, "%s,%"PRIu64",%"PRIu64"\n", file->name.name, extent->start.block, file->used_blocks); + if (offset_c->fp && !write_offset) { + fprintf(offset_c->fp, "%s,%" PRIu64 ",%" PRIu64 "\n", file->name.name, extent->start.block, file->used_blocks); write_offset = true; offset_c->count++; } xml_mktag(xmlTextWriterStartElement(writer, BAD_CAST "extent"), -1); - xml_mktag(xmlTextWriterWriteFormatElement( - writer, BAD_CAST "fileoffset", "%"PRIu64, extent->fileoffset), -1); - xml_mktag(xmlTextWriterWriteFormatElement( - writer, BAD_CAST "partition", "%c", extent->start.partition), -1); - xml_mktag(xmlTextWriterWriteFormatElement( - writer, BAD_CAST "startblock", "%"PRIu64, extent->start.block), -1); - xml_mktag(xmlTextWriterWriteFormatElement( - writer, BAD_CAST "byteoffset", "%"PRIu32, extent->byteoffset), -1); - xml_mktag(xmlTextWriterWriteFormatElement( - writer, BAD_CAST "bytecount", "%"PRIu64, extent->bytecount), -1); + xml_mktag(xmlTextWriterWriteFormatElement(writer, BAD_CAST "fileoffset", "%" PRIu64, extent->fileoffset), -1); + xml_mktag(xmlTextWriterWriteFormatElement(writer, BAD_CAST "partition", "%c", extent->start.partition), -1); + xml_mktag(xmlTextWriterWriteFormatElement(writer, BAD_CAST "startblock", "%" PRIu64, extent->start.block), -1); + xml_mktag(xmlTextWriterWriteFormatElement(writer, BAD_CAST "byteoffset", "%" PRIu32, extent->byteoffset), -1); + xml_mktag(xmlTextWriterWriteFormatElement(writer, BAD_CAST "bytecount", "%" PRIu64, extent->bytecount), -1); xml_mktag(xmlTextWriterEndElement(writer), -1); } xml_mktag(xmlTextWriterEndElement(writer), -1); @@ -328,7 +324,7 @@ static int _xml_write_file(xmlTextWriterPtr writer, struct dentry *file, struct /* Save unrecognized tags */ if (file->tag_count > 0) { - for (i=0; itag_count; ++i) { + for (i = 0; i < file->tag_count; ++i) { if (xmlTextWriterWriteRaw(writer, file->preserved_tags[i]) < 0) { ltfsmsg(LTFS_ERR, 17092E, __FUNCTION__); return -1; @@ -340,7 +336,7 @@ static int _xml_write_file(xmlTextWriterPtr writer, struct dentry *file, struct /* Write dirty file list */ if (sync_list->fp && file->dirty) { - fprintf(sync_list->fp, "%s,%"PRIu64"\n", file->name.name, file->size); + fprintf(sync_list->fp, "%s,%" PRIu64 "\n", file->name.name, file->size); file->dirty = false; sync_list->count++; } @@ -357,8 +353,11 @@ static int _xml_write_file(xmlTextWriterPtr writer, struct dentry *file, struct * @param sync_list file pointer to write sync file list * @return 0 on success or negative on failure */ -static int _xml_write_dirtree(xmlTextWriterPtr writer, struct dentry *dir, - const struct ltfs_index *idx, struct ltfsee_cache* offset_c, struct ltfsee_cache* sync_list) +static int _xml_write_dirtree(xmlTextWriterPtr writer, + struct dentry *dir, + const struct ltfs_index *idx, + struct ltfsee_cache *offset_c, + struct ltfsee_cache *sync_list) { size_t i; char *offset_name, *sync_name; @@ -366,14 +365,13 @@ static int _xml_write_dirtree(xmlTextWriterPtr writer, struct dentry *dir, struct name_list *list_ptr, *list_tmp; int ret; - if (!dir) - return 0; /* nothing to do */ + if (!dir) return 0; /* nothing to do */ /* write standard attributes */ xml_mktag(xmlTextWriterStartElement(writer, BAD_CAST "directory"), -1); if (dir == idx->root) { if (idx->volume_name.name) { - xml_mktag(_xml_write_nametype(writer, "name", (struct ltfs_name*)(&idx->volume_name)), -1); + xml_mktag(_xml_write_nametype(writer, "name", (struct ltfs_name *)(&idx->volume_name)), -1); } else { xml_mktag(xmlTextWriterStartElement(writer, BAD_CAST "name"), -1); xml_mktag(xmlTextWriterEndElement(writer), -1); @@ -381,11 +379,9 @@ static int _xml_write_dirtree(xmlTextWriterPtr writer, struct dentry *dir, } else xml_mktag(_xml_write_nametype(writer, "name", &dir->name), -1); - xml_mktag(xmlTextWriterWriteElement( - writer, BAD_CAST "readonly", BAD_CAST (dir->readonly ? "true" : "false")), -1); + xml_mktag(xmlTextWriterWriteElement(writer, BAD_CAST "readonly", BAD_CAST(dir->readonly ? "true" : "false")), -1); xml_mktag(_xml_write_dentry_times(writer, dir), -1); - xml_mktag(xmlTextWriterWriteFormatElement( - writer, BAD_CAST UID_TAGNAME, "%"PRIu64, dir->uid), -1); + xml_mktag(xmlTextWriterWriteFormatElement(writer, BAD_CAST UID_TAGNAME, "%" PRIu64, dir->uid), -1); /* write extended attributes */ xml_mktag(_xml_write_xattr(writer, dir), -1); @@ -395,16 +391,15 @@ static int _xml_write_dirtree(xmlTextWriterPtr writer, struct dentry *dir, /* Sort dentries by UID before generating xml */ HASH_SORT(dir->child_list, fs_hash_sort_by_uid); - HASH_ITER(hh, dir->child_list, list_ptr, list_tmp) { + HASH_ITER(hh, dir->child_list, list_ptr, list_tmp) + { if (list_ptr->d->isdir) { - if (list_ptr->d->vol->index_cache_path && !strcmp(list_ptr->d->name.name, ".LTFSEE_DATA")) { ret = asprintf(&offset_name, "%s.%s", list_ptr->d->vol->index_cache_path, "offsetcache.new"); if (ret > 0) { arch_fopen(offset_name, "w", offset->fp); free(offset_name); - if (!offset->fp) - ltfsmsg(LTFS_WARN, 17248W, "offset cache", list_ptr->d->vol->index_cache_path); + if (!offset->fp) ltfsmsg(LTFS_WARN, 17248W, "offset cache", list_ptr->d->vol->index_cache_path); } else ltfsmsg(LTFS_WARN, 17247W, "offset cache", list_ptr->d->vol->index_cache_path); @@ -412,8 +407,7 @@ static int _xml_write_dirtree(xmlTextWriterPtr writer, struct dentry *dir, if (ret > 0) { arch_fopen(sync_name, "w", sync->fp); free(sync_name); - if (!sync->fp) - ltfsmsg(LTFS_WARN, 17248W, "sync list", list_ptr->d->vol->index_cache_path); + if (!sync->fp) ltfsmsg(LTFS_WARN, 17248W, "sync list", list_ptr->d->vol->index_cache_path); } else ltfsmsg(LTFS_WARN, 17247W, "sync list", list_ptr->d->vol->index_cache_path); } @@ -441,7 +435,7 @@ static int _xml_write_dirtree(xmlTextWriterPtr writer, struct dentry *dir, /* Save unrecognized tags */ if (dir->tag_count > 0) { - for (i=0; itag_count; ++i) { + for (i = 0; i < dir->tag_count; ++i) { if (xmlTextWriterWriteRaw(writer, dir->preserved_tags[i]) < 0) { ltfsmsg(LTFS_ERR, 17092E, __FUNCTION__); return -1; @@ -463,15 +457,14 @@ static int _xml_write_dirtree(xmlTextWriterPtr writer, struct dentry *dir, * @param pos position on tape where the schema will be written * @return 0 on success, negative on failure */ -static int _xml_write_schema(xmlTextWriterPtr writer, const char *creator, - const struct ltfs_index *idx) +static int _xml_write_schema(xmlTextWriterPtr writer, const char *creator, const struct ltfs_index *idx) { int ret; size_t i; char *update_time; struct ltfs_name *name_criteria; - struct ltfsee_cache offset = {NULL, 0}; /* Cache structure for file offset cache */ - struct ltfsee_cache list = {NULL, 0}; /* Cache structure for sync list */ + struct ltfsee_cache offset = { NULL, 0 }; /* Cache structure for file offset cache */ + struct ltfsee_cache list = { NULL, 0 }; /* Cache structure for sync list */ ret = xml_format_time(idx->mod_time, &update_time); if (!update_time) @@ -496,38 +489,33 @@ static int _xml_write_schema(xmlTextWriterPtr writer, const char *creator, /* write index properties */ xml_mktag(xmlTextWriterStartElement(writer, BAD_CAST "ltfsindex"), -1); - xml_mktag(xmlTextWriterWriteAttribute(writer, BAD_CAST "version", - BAD_CAST LTFS_INDEX_VERSION_STR), -1); + xml_mktag(xmlTextWriterWriteAttribute(writer, BAD_CAST "version", BAD_CAST LTFS_INDEX_VERSION_STR), -1); xml_mktag(xmlTextWriterWriteElement(writer, BAD_CAST "creator", BAD_CAST creator), -1); if (idx->commit_message && strlen(idx->commit_message)) { - xml_mktag(xmlTextWriterWriteFormatElement(writer, BAD_CAST "comment", - "%s", BAD_CAST (idx->commit_message)), -1); + xml_mktag(xmlTextWriterWriteFormatElement(writer, BAD_CAST "comment", "%s", BAD_CAST(idx->commit_message)), -1); } xml_mktag(xmlTextWriterWriteElement(writer, BAD_CAST "volumeuuid", BAD_CAST idx->vol_uuid), -1); - xml_mktag(xmlTextWriterWriteFormatElement( - writer, BAD_CAST "generationnumber", "%u", idx->generation), -1); + xml_mktag(xmlTextWriterWriteFormatElement(writer, BAD_CAST "generationnumber", "%u", idx->generation), -1); xml_mktag(xmlTextWriterWriteElement(writer, BAD_CAST "updatetime", BAD_CAST update_time), -1); xml_mktag(xmlTextWriterStartElement(writer, BAD_CAST "location"), -1); - xml_mktag(xmlTextWriterWriteFormatElement( - writer, BAD_CAST "partition", "%c", idx->selfptr.partition), -1); - xml_mktag(xmlTextWriterWriteFormatElement( - writer, BAD_CAST "startblock", "%"PRIu64, idx->selfptr.block), -1); + xml_mktag(xmlTextWriterWriteFormatElement(writer, BAD_CAST "partition", "%c", idx->selfptr.partition), -1); + xml_mktag(xmlTextWriterWriteFormatElement(writer, BAD_CAST "startblock", "%" PRIu64, idx->selfptr.block), -1); xml_mktag(xmlTextWriterEndElement(writer), -1); if (idx->backptr.block) { xml_mktag(xmlTextWriterStartElement(writer, BAD_CAST "previousgenerationlocation"), -1); - xml_mktag(xmlTextWriterWriteFormatElement( - writer, BAD_CAST "partition", "%c", idx->backptr.partition), -1); - xml_mktag(xmlTextWriterWriteFormatElement( - writer, BAD_CAST "startblock", "%"PRIu64, idx->backptr.block), -1); + xml_mktag(xmlTextWriterWriteFormatElement(writer, BAD_CAST "partition", "%c", idx->backptr.partition), -1); + xml_mktag(xmlTextWriterWriteFormatElement(writer, BAD_CAST "startblock", "%" PRIu64, idx->backptr.block), -1); xml_mktag(xmlTextWriterEndElement(writer), -1); } - xml_mktag(xmlTextWriterWriteElement(writer, BAD_CAST "allowpolicyupdate", - BAD_CAST (idx->criteria_allow_update ? "true" : "false")), -1); + xml_mktag(xmlTextWriterWriteElement( + writer, BAD_CAST "allowpolicyupdate", BAD_CAST(idx->criteria_allow_update ? "true" : "false")), + -1); if (idx->original_criteria.have_criteria) { xml_mktag(xmlTextWriterStartElement(writer, BAD_CAST "dataplacementpolicy"), -1); xml_mktag(xmlTextWriterStartElement(writer, BAD_CAST "indexpartitioncriteria"), -1); - xml_mktag(xmlTextWriterWriteFormatElement(writer, BAD_CAST "size", "%"PRIu64, - idx->original_criteria.max_filesize_criteria), -1); + xml_mktag(xmlTextWriterWriteFormatElement( + writer, BAD_CAST "size", "%" PRIu64, idx->original_criteria.max_filesize_criteria), + -1); if (idx->original_criteria.glob_patterns) { name_criteria = idx->original_criteria.glob_patterns; while (name_criteria && name_criteria->name) { @@ -538,8 +526,7 @@ static int _xml_write_schema(xmlTextWriterPtr writer, const char *creator, xml_mktag(xmlTextWriterEndElement(writer), -1); xml_mktag(xmlTextWriterEndElement(writer), -1); } - xml_mktag(xmlTextWriterWriteFormatElement( - writer, BAD_CAST NEXTUID_TAGNAME, "%"PRIu64, idx->uid_number), -1); + xml_mktag(xmlTextWriterWriteFormatElement(writer, BAD_CAST NEXTUID_TAGNAME, "%" PRIu64, idx->uid_number), -1); { char *value = NULL; @@ -556,21 +543,18 @@ static int _xml_write_schema(xmlTextWriterPtr writer, const char *creator, break; } - if (value) - xml_mktag(xmlTextWriterWriteElement(writer, BAD_CAST "volumelockstate", BAD_CAST value), -1); + if (value) xml_mktag(xmlTextWriterWriteElement(writer, BAD_CAST "volumelockstate", BAD_CAST value), -1); free(value); } xml_mktag(_xml_write_dirtree(writer, idx->root, idx, &offset, &list), -1); - if (offset.count) - ltfsmsg(LTFS_INFO, 17249I, (unsigned long long)offset.count); - if (list.count) - ltfsmsg(LTFS_INFO, 17250I, (unsigned long long)list.count); + if (offset.count) ltfsmsg(LTFS_INFO, 17249I, (unsigned long long)offset.count); + if (list.count) ltfsmsg(LTFS_INFO, 17250I, (unsigned long long)list.count); /* Save unrecognized tags */ if (idx->tag_count > 0) { - for (i=0; itag_count; ++i) { + for (i = 0; i < idx->tag_count; ++i) { if (xmlTextWriterWriteRaw(writer, idx->preserved_tags[i]) < 0) { ltfsmsg(LTFS_ERR, 17092E, __FUNCTION__); return -1; @@ -599,8 +583,7 @@ static int _xml_write_schema(xmlTextWriterPtr writer, const char *creator, * @param label data structure containing format parameters * @return buffer containing the label, which the caller should free using xmlBufferFree */ -xmlBufferPtr xml_make_label(const char *creator, tape_partition_t partition, - const struct ltfs_label *label) +xmlBufferPtr xml_make_label(const char *creator, tape_partition_t partition, const struct ltfs_label *label) { int ret; char *fmt_time; @@ -633,8 +616,7 @@ xmlBufferPtr xml_make_label(const char *creator, tape_partition_t partition, /* write tags */ xml_mktag(xmlTextWriterStartElement(writer, BAD_CAST "ltfslabel"), NULL); - xml_mktag(xmlTextWriterWriteAttribute(writer, BAD_CAST "version", - BAD_CAST LTFS_LABEL_VERSION_STR), NULL); + xml_mktag(xmlTextWriterWriteAttribute(writer, BAD_CAST "version", BAD_CAST LTFS_LABEL_VERSION_STR), NULL); xml_mktag(xmlTextWriterWriteElement(writer, BAD_CAST "creator", BAD_CAST creator), NULL); ret = xml_format_time(label->format_time, &fmt_time); @@ -646,23 +628,18 @@ xmlBufferPtr xml_make_label(const char *creator, tape_partition_t partition, xml_mktag(xmlTextWriterWriteElement(writer, BAD_CAST "formattime", BAD_CAST fmt_time), NULL); free(fmt_time); - xml_mktag(xmlTextWriterWriteElement( - writer, BAD_CAST "volumeuuid", BAD_CAST label->vol_uuid), NULL); - xml_mktag(xmlTextWriterStartElement(writer, BAD_CAST "location"), NULL); - xml_mktag(xmlTextWriterWriteFormatElement( - writer, BAD_CAST "partition", "%c", label->part_num2id[partition]), NULL); + xml_mktag(xmlTextWriterWriteElement(writer, BAD_CAST "volumeuuid", BAD_CAST label->vol_uuid), NULL); + xml_mktag(xmlTextWriterStartElement(writer, BAD_CAST "location"), NULL); + xml_mktag(xmlTextWriterWriteFormatElement(writer, BAD_CAST "partition", "%c", label->part_num2id[partition]), NULL); xml_mktag(xmlTextWriterEndElement(writer), NULL); xml_mktag(xmlTextWriterStartElement(writer, BAD_CAST "partitions"), NULL); - xml_mktag(xmlTextWriterWriteFormatElement( - writer, BAD_CAST "index", "%c", label->partid_ip), NULL); - xml_mktag(xmlTextWriterWriteFormatElement( - writer, BAD_CAST "data", "%c", label->partid_dp), NULL); + xml_mktag(xmlTextWriterWriteFormatElement(writer, BAD_CAST "index", "%c", label->partid_ip), NULL); + xml_mktag(xmlTextWriterWriteFormatElement(writer, BAD_CAST "data", "%c", label->partid_dp), NULL); xml_mktag(xmlTextWriterEndElement(writer), NULL); - xml_mktag(xmlTextWriterWriteFormatElement( - writer, BAD_CAST "blocksize", "%ld", label->blocksize), NULL); - xml_mktag(xmlTextWriterWriteElement( - writer, BAD_CAST "compression", BAD_CAST (label->enable_compression ? "true" : "false")), - NULL); + xml_mktag(xmlTextWriterWriteFormatElement(writer, BAD_CAST "blocksize", "%ld", label->blocksize), NULL); + xml_mktag( + xmlTextWriterWriteElement(writer, BAD_CAST "compression", BAD_CAST(label->enable_compression ? "true" : "false")), + NULL); xml_mktag(xmlTextWriterEndElement(writer), NULL); ret = xmlTextWriterEndDocument(writer); @@ -709,7 +686,7 @@ xmlBufferPtr xml_make_schema(const char *creator, const struct ltfs_index *idx) return buf; } -static int _commit_offset_caches(const char* path, const struct ltfs_index *idx) +static int _commit_offset_caches(const char *path, const struct ltfs_index *idx) { int ret = 0, fd = -1; char *offset_name = NULL, *sync_name = NULL; @@ -729,8 +706,7 @@ static int _commit_offset_caches(const char* path, const struct ltfs_index *idx) arch_close(fd); fd = -1; } else { - if (errno != ENOENT) - ltfsmsg(LTFS_INFO, 17255I, offset_name, errno); + if (errno != ENOENT) ltfsmsg(LTFS_INFO, 17255I, offset_name, errno); } free(offset_name); } @@ -743,14 +719,13 @@ static int _commit_offset_caches(const char* path, const struct ltfs_index *idx) if (ret > 0) { arch_unlink(sync_name); rename(sync_new, sync_name); - arch_open(&fd,sync_name, O_RDWR | O_BINARY, SHARE_FLAG_DENYRW , PERMISSION_READWRITE); + arch_open(&fd, sync_name, O_RDWR | O_BINARY, SHARE_FLAG_DENYRW, PERMISSION_READWRITE); if (fd >= 0) { fsync(fd); arch_close(fd); fd = -1; } else { - if (errno != ENOENT) - ltfsmsg(LTFS_INFO, 17255I, sync_name, errno); + if (errno != ENOENT) ltfsmsg(LTFS_INFO, 17255I, sync_name, errno); } free(sync_name); } @@ -767,8 +742,7 @@ static int _commit_offset_caches(const char* path, const struct ltfs_index *idx) * @param priv ltfs private data * @return 0 on success or a negative value on error. */ -int xml_schema_to_file(const char *filename, const char *creator, - const char *reason, const struct ltfs_index *idx) +int xml_schema_to_file(const char *filename, const char *creator, const char *reason, const struct ltfs_index *idx) { xmlTextWriterPtr writer; int ret; @@ -779,13 +753,13 @@ int xml_schema_to_file(const char *filename, const char *creator, CHECK_ARG_NULL(filename, -LTFS_NULL_ARG); writer = xmlNewTextWriterFilename(filename, 0); - if (! writer) { + if (!writer) { ltfsmsg(LTFS_ERR, 17051E, filename); return -1; } if (reason) - asprintf(&alt_creator, "%s - %s", creator , reason); + asprintf(&alt_creator, "%s - %s", creator, reason); else alt_creator = arch_strdup(creator); @@ -827,35 +801,31 @@ int xml_schema_to_tape(char *reason, struct ltfs_volume *vol) /* Create output callback context data structure. */ out_ctx = calloc(1, sizeof(struct xml_output_tape)); - if (! out_ctx) { + if (!out_ctx) { ltfsmsg(LTFS_ERR, 10001E, "xml_schema_to_tape: output context"); return -LTFS_NO_MEMORY; } out_ctx->buf = malloc(vol->label->blocksize + LTFS_CRC_SIZE); - if (! out_ctx->buf) { + if (!out_ctx->buf) { ltfsmsg(LTFS_ERR, 10001E, "xml_schema_to_tape: output buffer"); free(out_ctx); return -LTFS_NO_MEMORY; } - out_ctx->fd = -1; + out_ctx->fd = -1; out_ctx->errno_fd = 0; - if (vol->index_cache_path) - xml_acquire_file_lock(vol->index_cache_path, &out_ctx->fd, &bk, true); + if (vol->index_cache_path) xml_acquire_file_lock(vol->index_cache_path, &out_ctx->fd, &bk, true); out_ctx->buf_size = vol->label->blocksize; out_ctx->buf_used = 0; - out_ctx->device = vol->device; + out_ctx->device = vol->device; out_ctx->err_code = 0; /* Create output buffer pointer. */ - write_buf = xmlOutputBufferCreateIO(xml_output_tape_write_callback, - xml_output_tape_close_callback, - out_ctx, NULL); - if (! write_buf) { + write_buf = xmlOutputBufferCreateIO(xml_output_tape_write_callback, xml_output_tape_close_callback, out_ctx, NULL); + if (!write_buf) { ltfsmsg(LTFS_ERR, 17053E); - if (out_ctx->fd >= 0) - xml_release_file_lock(vol->index_cache_path, out_ctx->fd, bk, false); + if (out_ctx->fd >= 0) xml_release_file_lock(vol->index_cache_path, out_ctx->fd, bk, false); free(out_ctx->buf); free(out_ctx); return -LTFS_LIBXML2_FAILURE; @@ -863,10 +833,9 @@ int xml_schema_to_tape(char *reason, struct ltfs_volume *vol) /* Create XML writer. */ writer = xmlNewTextWriter(write_buf); - if (! writer) { + if (!writer) { ltfsmsg(LTFS_ERR, 17054E); - if (out_ctx->fd >= 0) - xml_release_file_lock(vol->index_cache_path, out_ctx->fd, bk, false); + if (out_ctx->fd >= 0) xml_release_file_lock(vol->index_cache_path, out_ctx->fd, bk, false); xmlOutputBufferClose(write_buf); free(out_ctx->buf); free(out_ctx); @@ -885,11 +854,12 @@ int xml_schema_to_tape(char *reason, struct ltfs_volume *vol) if (out_ctx->err_code || out_ctx->errno_fd) { /* Error happens while writing down the index on tape */ - if (out_ctx->err_code) ret = out_ctx->err_code; - else if (out_ctx->errno_fd) ret = out_ctx->errno_fd; + if (out_ctx->err_code) + ret = out_ctx->err_code; + else if (out_ctx->errno_fd) + ret = out_ctx->errno_fd; - if (out_ctx->fd >= 0) - xml_release_file_lock(vol->index_cache_path, out_ctx->fd, bk, true); + if (out_ctx->fd >= 0) xml_release_file_lock(vol->index_cache_path, out_ctx->fd, bk, true); } else { /* New index is successfully sent to the internal buffer of tape drive */ immed = (strcmp(reason, SYNC_FORMAT) == 0); /* Use immediate write FM only at format */ @@ -899,22 +869,19 @@ int xml_schema_to_tape(char *reason, struct ltfs_volume *vol) * All buffered data, new index and following FM is written on tape correctly. * It's time to unveil the offset cache and sync cache to other programs. */ - if (vol->index_cache_path) - _commit_offset_caches(vol->index_cache_path, vol->index); + if (vol->index_cache_path) _commit_offset_caches(vol->index_cache_path, vol->index); } else { ltfsmsg(LTFS_ERR, 11084E, ret); } - if (out_ctx->fd >= 0) - xml_release_file_lock(vol->index_cache_path, out_ctx->fd, bk, false); + if (out_ctx->fd >= 0) xml_release_file_lock(vol->index_cache_path, out_ctx->fd, bk, false); } /* Update the creator string */ - if (! vol->index->creator || strcmp(vol->creator, vol->index->creator)) { - if (vol->index->creator) - free(vol->index->creator); + if (!vol->index->creator || strcmp(vol->creator, vol->index->creator)) { + if (vol->index->creator) free(vol->index->creator); vol->index->creator = arch_strdup(vol->creator); - if (! vol->index->creator) { + if (!vol->index->creator) { ltfsmsg(LTFS_ERR, 10001E, "xml_schema_to_tape: new creator string"); ret = -LTFS_NO_MEMORY; } diff --git a/src/ltfs_fuse.c b/src/ltfs_fuse.c index db4d3a5c..4819dda9 100644 --- a/src/ltfs_fuse.c +++ b/src/ltfs_fuse.c @@ -55,40 +55,40 @@ ************************************************************************************* */ #include "ltfs_fuse.h" -#include "libltfs/ltfs_fsops.h" +#include "libltfs/arch/errormap.h" +#include "libltfs/arch/time_internal.h" #include "libltfs/iosched.h" +#include "libltfs/kmi.h" +#include "libltfs/ltfs_fsops.h" #include "libltfs/pathname.h" -#include "libltfs/xattr.h" #include "libltfs/periodic_sync.h" -#include "libltfs/arch/time_internal.h" -#include "libltfs/arch/errormap.h" -#include "libltfs/kmi.h" +#include "libltfs/xattr.h" #ifdef mingw_PLATFORM -#include "libltfs/arch/win/win_util.h" +# include "libltfs/arch/win/win_util.h" #endif #if (__WORDSIZE == 64) -#define FILEHANDLE_TO_STRUCT(fh) ((struct ltfs_file_handle *)(uint64_t)(fh)) -#define STRUCT_TO_FILEHANDLE(de) ((uint64_t)(de)) +# define FILEHANDLE_TO_STRUCT(fh) ((struct ltfs_file_handle *)(uint64_t)(fh)) +# define STRUCT_TO_FILEHANDLE(de) ((uint64_t)(de)) #else -#define FILEHANDLE_TO_STRUCT(fh) ((struct ltfs_file_handle *)(uint32_t)(fh)) -#define STRUCT_TO_FILEHANDLE(de) ((uint64_t)(uint32_t)(de)) +# define FILEHANDLE_TO_STRUCT(fh) ((struct ltfs_file_handle *)(uint32_t)(fh)) +# define STRUCT_TO_FILEHANDLE(de) ((uint64_t)(uint32_t)(de)) #endif #ifdef mingw_PLATFORM static struct fuse_context *context; -#define fuse_get_context() context +# define fuse_get_context() context #endif -#define FUSE_REQ_ENTER(r) REQ_NUMBER(REQ_STAT_ENTER, REQ_FUSE, r) -#define FUSE_REQ_EXIT(r) REQ_NUMBER(REQ_STAT_EXIT, REQ_FUSE, r) +#define FUSE_REQ_ENTER(r) REQ_NUMBER(REQ_STAT_ENTER, REQ_FUSE, r) +#define FUSE_REQ_EXIT(r) REQ_NUMBER(REQ_STAT_EXIT, REQ_FUSE, r) struct ltfs_file_handle *_new_ltfs_file_handle(struct file_info *fi) { int ret; struct ltfs_file_handle *file = calloc(1, sizeof(struct ltfs_file_handle)); - if (! file) { + if (!file) { ltfsmsg(LTFS_ERR, 10001E, "file structure"); return NULL; } @@ -115,7 +115,7 @@ static struct file_info *_new_file_info(const char *path) { int ret; struct file_info *fi = calloc(1, sizeof(struct file_info)); - if (! fi) { + if (!fi) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return NULL; } @@ -127,7 +127,7 @@ static struct file_info *_new_file_info(const char *path) } if (path) { fi->path = strdup(path); - if (! fi->path) { + if (!fi->path) { ltfsmsg(LTFS_ERR, 10001E, "_new_file_info: path"); ltfs_mutex_destroy(&fi->lock); free(fi); @@ -141,8 +141,7 @@ static struct file_info *_new_file_info(const char *path) static void _free_file_info(struct file_info *fi) { if (fi) { - if (fi->path) - free(fi->path); + if (fi->path) free(fi->path); ltfs_mutex_destroy(&fi->lock); free(fi); } @@ -161,17 +160,15 @@ static void _free_file_info(struct file_info *fi) * @param priv LTFS private data. * @return File handle information, or NULL if memory allocation failed or if 'priv' is NULL. */ -static struct file_info *_file_open(const char *path, void *d, struct file_info *spare, - struct ltfs_fuse_data *priv) +static struct file_info *_file_open(const char *path, void *d, struct file_info *spare, struct ltfs_fuse_data *priv) { struct file_info *fi = NULL; CHECK_ARG_NULL(priv, NULL); ltfs_mutex_lock(&priv->file_table_lock); - if (priv->file_table) - HASH_FIND_PTR(priv->file_table, &d, fi); - if (! fi) { + if (priv->file_table) HASH_FIND_PTR(priv->file_table, &d, fi); + if (!fi) { fi = spare ? spare : _new_file_info(path); - if (! fi) { + if (!fi) { ltfs_mutex_unlock(&priv->file_table_lock); return NULL; } @@ -203,8 +200,7 @@ static void _file_close(struct file_info *fi, struct ltfs_fuse_data *priv) } ltfs_mutex_unlock(&fi->lock); ltfs_mutex_unlock(&priv->file_table_lock); - if (do_free) - _free_file_info(fi); + if (do_free) _free_file_info(fi); } } @@ -218,8 +214,7 @@ const char *_dentry_name(const char *path, struct file_info *fi) return "(unnamed)"; } -static void _ltfs_fuse_attr_to_stat(struct stat *stbuf, struct dentry_attr *attr, - struct ltfs_fuse_data *priv) +static void _ltfs_fuse_attr_to_stat(struct stat *stbuf, struct dentry_attr *attr, struct ltfs_fuse_data *priv) { stbuf->st_dev = LTFS_SUPER_MAGIC; stbuf->st_ino = attr->uid; @@ -227,7 +222,7 @@ static void _ltfs_fuse_attr_to_stat(struct stat *stbuf, struct dentry_attr *attr stbuf->st_mode = S_IFLNK | 0777; } else { stbuf->st_mode = ((attr->isdir ? S_IFDIR : S_IFREG) | (attr->readonly ? 0555 : 0777)) & - (attr->isdir ? priv->dir_mode : priv->file_mode); + (attr->isdir ? priv->dir_mode : priv->file_mode); } stbuf->st_nlink = attr->nlink; stbuf->st_rdev = 0; /* no special files on LTFS volumes */ @@ -246,9 +241,9 @@ static void _ltfs_fuse_attr_to_stat(struct stat *stbuf, struct dentry_attr *attr stbuf->st_atimespec = timespec_from_ltfs_timespec(&attr->access_time); stbuf->st_mtimespec = timespec_from_ltfs_timespec(&attr->modify_time); stbuf->st_ctimespec = timespec_from_ltfs_timespec(&attr->change_time); - #ifdef _DARWIN_USE_64_BIT_INODE +# ifdef _DARWIN_USE_64_BIT_INODE stbuf->st_birthtimespec = timespec_from_ltfs_timespec(&attr->create_time); - #endif +# endif #else stbuf->st_atim = timespec_from_ltfs_timespec(&attr->access_time); stbuf->st_mtim = timespec_from_ltfs_timespec(&attr->modify_time); @@ -269,11 +264,9 @@ int ltfs_fuse_fgetattr(const char *path, struct stat *stbuf, struct fuse_file_in ret = ltfs_fsops_getattr(file->file_info->dentry_handle, &attr, priv->data); - if (ret == 0) - _ltfs_fuse_attr_to_stat(stbuf, &attr, priv); + if (ret == 0) _ltfs_fuse_attr_to_stat(stbuf, &attr, priv); - ltfs_request_trace(FUSE_REQ_EXIT(REQ_FGETATTR), ret, - ((struct dentry *)(file->file_info->dentry_handle))->uid); + ltfs_request_trace(FUSE_REQ_EXIT(REQ_FGETATTR), ret, ((struct dentry *)(file->file_info->dentry_handle))->uid); return errormap_fuse_error(ret); } @@ -291,15 +284,13 @@ int ltfs_fuse_getattr(const char *path, struct stat *stbuf) ret = ltfs_fsops_getattr_path(path, &attr, &id, priv->data); - if (ret == 0) - _ltfs_fuse_attr_to_stat(stbuf, &attr, priv); + if (ret == 0) _ltfs_fuse_attr_to_stat(stbuf, &attr, priv); ltfs_request_trace(FUSE_REQ_EXIT(REQ_GETATTR), ret, id.uid); return errormap_fuse_error(ret); } - int ltfs_fuse_access(const char *path, int mode) { ltfs_request_trace(FUSE_REQ_ENTER(REQ_ACCESS), 0, 0); @@ -325,11 +316,11 @@ int ltfs_fuse_statfs(const char *path, struct statvfs *buf) return errormap_fuse_error(ret); } - stats->f_blocks = blockstat.total_dp; /* Total tape capacity */ - stats->f_bfree = blockstat.remaining_dp; /* Remaining tape capacity */ - stats->f_bavail = stats->f_bfree; /* Blocks available for normal user (ignored) */ + stats->f_blocks = blockstat.total_dp; /* Total tape capacity */ + stats->f_bfree = blockstat.remaining_dp; /* Remaining tape capacity */ + stats->f_bavail = stats->f_bfree; /* Blocks available for normal user (ignored) */ -#ifdef __APPLE__ +# ifdef __APPLE__ stats->f_files = UINT_MAX; stats->f_ffree = UINT_MAX - ltfs_get_file_count(priv->data); memcpy(buf, stats, sizeof(struct statvfs)); @@ -338,13 +329,13 @@ int ltfs_fuse_statfs(const char *path, struct statvfs *buf) * Need to adjust the block counts so they're in units of the reported f_frsize. */ double scale = ltfs_get_blocksize(priv->data) / (double)stats->f_frsize; buf->f_blocks *= scale; - buf->f_bfree *= scale; + buf->f_bfree *= scale; buf->f_bavail *= scale; -#else +# else stats->f_files = UINT64_MAX; stats->f_ffree = UINT64_MAX - ltfs_get_file_count(priv->data); memcpy(buf, stats, sizeof(struct statvfs)); -#endif /* __APPLE__ */ +# endif /* __APPLE__ */ ltfs_request_trace(FUSE_REQ_EXIT(REQ_STATFS), 0, 0); @@ -381,11 +372,9 @@ int ltfs_fuse_open(const char *path, struct fuse_file_info *fi) /* Get file information and create a file handle */ file_info = _file_open(path, dentry_handle, NULL, priv); - if (file_info) - file = _new_ltfs_file_handle(file_info); - if (! file_info || ! file) { - if (file_info) - _file_close(file_info, priv); + if (file_info) file = _new_ltfs_file_handle(file_info); + if (!file_info || !file) { + if (file_info) _file_close(file_info, priv); ltfs_fsops_close(dentry_handle, false, open_write, true, priv->data); ltfs_request_trace(FUSE_REQ_EXIT(REQ_OPEN), -ENOMEM, 0); return -ENOMEM; @@ -394,29 +383,27 @@ int ltfs_fuse_open(const char *path, struct fuse_file_info *fi) fi->fh = STRUCT_TO_FILEHANDLE(file); #ifdef __APPLE__ - /* Comment from MacFUSE author about direct_io on OSX: + /* Comment from MacFUSE author about direct_io on OSX: * direct_io is a rather abnormal mode of operation from Mac OS X's * standpoint. Unless your file system requires this mode, I wouldn't * recommend using this option. */ - fi->direct_io = 0; - fi->keep_cache = 0; + fi->direct_io = 0; + fi->keep_cache = 0; #else -#if FUSE_VERSION <= 27 +# if FUSE_VERSION <= 27 /* for FUSE <= 2.7, set direct_io when opening for write */ - if (((fi->flags & O_WRONLY) == O_WRONLY) || ((fi->flags & O_RDWR) == O_RDWR)) - fi->direct_io = 1; + if (((fi->flags & O_WRONLY) == O_WRONLY) || ((fi->flags & O_RDWR) == O_RDWR)) fi->direct_io = 1; fi->keep_cache = 0; -#else +# else /* cannot set keep cache if any process has the file open with direct_io set! so only * set it on newer FUSE versions, where we don't use direct_io. */ fi->direct_io = 0; fi->keep_cache = 1; -#endif +# endif #endif - ltfs_request_trace(FUSE_REQ_EXIT(REQ_OPEN), 0, - ((struct dentry *)(file->file_info->dentry_handle))->uid); + ltfs_request_trace(FUSE_REQ_EXIT(REQ_OPEN), 0, ((struct dentry *)(file->file_info->dentry_handle))->uid); return 0; } @@ -447,8 +434,7 @@ int ltfs_fuse_release(const char *path, struct fuse_file_info *fi) open_write = (((fi->flags & O_WRONLY) == O_WRONLY) || ((fi->flags & O_RDWR) == O_RDWR)); ret = ltfs_fsops_close(file->file_info->dentry_handle, dirty, open_write, true, priv->data); - if (write_index) - ltfs_sync_index(SYNC_CLOSE, true, priv->data); + if (write_index) ltfs_sync_index(SYNC_CLOSE, true, priv->data); _file_close(file->file_info, priv); _free_ltfs_file_handle(file); @@ -474,8 +460,7 @@ int ltfs_fuse_opendir(const char *path, struct fuse_file_info *fi) open_write = (((fi->flags & O_WRONLY) == O_WRONLY) || ((fi->flags & O_RDWR) == O_RDWR)); /* Open the file */ - ret = ltfs_fsops_open(path, open_write, false, (struct dentry **)&dentry_handle, - priv->data); + ret = ltfs_fsops_open(path, open_write, false, (struct dentry **)&dentry_handle, priv->data); if (ret < 0) { ltfs_request_trace(FUSE_REQ_EXIT(REQ_OPENDIR), ret, 0); return errormap_fuse_error(ret); @@ -483,11 +468,9 @@ int ltfs_fuse_opendir(const char *path, struct fuse_file_info *fi) /* Get file information and create a file handle */ file_info = _file_open(path, dentry_handle, NULL, priv); - if (file_info) - file = _new_ltfs_file_handle(file_info); - if (! file_info || ! file) { - if (file_info) - _file_close(file_info, priv); + if (file_info) file = _new_ltfs_file_handle(file_info); + if (!file_info || !file) { + if (file_info) _file_close(file_info, priv); ltfs_fsops_close(dentry_handle, false, false, false, priv->data); ltfs_request_trace(FUSE_REQ_EXIT(REQ_OPENDIR), -ENOMEM, 0); return -ENOMEM; @@ -495,8 +478,7 @@ int ltfs_fuse_opendir(const char *path, struct fuse_file_info *fi) fi->fh = STRUCT_TO_FILEHANDLE(file); - ltfs_request_trace(FUSE_REQ_EXIT(REQ_OPENDIR), 0, - ((struct dentry *)(file->file_info->dentry_handle))->uid); + ltfs_request_trace(FUSE_REQ_EXIT(REQ_OPENDIR), 0, ((struct dentry *)(file->file_info->dentry_handle))->uid); return 0; } @@ -531,8 +513,7 @@ int ltfs_fuse_fsyncdir(const char *path, int flags, struct fuse_file_info *fi) return 0; } -static int _ltfs_fuse_do_flush(struct ltfs_file_handle *file, struct ltfs_fuse_data *priv, - const char *caller) +static int _ltfs_fuse_do_flush(struct ltfs_file_handle *file, struct ltfs_fuse_data *priv, const char *caller) { bool dirty; int ret = 0; @@ -608,8 +589,7 @@ int ltfs_fuse_utimens(const char *path, const struct timespec ts[2]) ltfs_request_trace(FUSE_REQ_EXIT(REQ_UTIMENS), ret, id.uid); - if (ret) - ltfsmsg(LTFS_ERR, 10020E, "utimens", path, 0, 0); + if (ret) ltfsmsg(LTFS_ERR, 10020E, "utimens", path, 0, 0); return errormap_fuse_error(ret); } @@ -632,8 +612,7 @@ int ltfs_fuse_chmod(const char *path, mode_t mode) ltfs_request_trace(FUSE_REQ_EXIT(REQ_CHMOD), ret, id.uid); - if (ret) - ltfsmsg(LTFS_ERR, 10020E, "chmod", path, mode, 0); + if (ret) ltfsmsg(LTFS_ERR, 10020E, "chmod", path, mode, 0); return errormap_fuse_error(ret); } @@ -663,22 +642,23 @@ int ltfs_fuse_create(const char *path, mode_t mode, struct fuse_file_info *fi) ltfsmsg(LTFS_DEBUG, 14040D, path); - readonly = ! (mode & priv->file_mode & 0222); + readonly = !(mode & priv->file_mode & 0222); /* Allocate file handle and information */ file = _new_ltfs_file_handle(NULL); - if (! file) { + if (!file) { ltfs_request_trace(FUSE_REQ_EXIT(REQ_CREATE), -ENOMEM, 0); return -ENOMEM; } file_info = _new_file_info(path); - if (! file_info) { + if (!file_info) { _free_ltfs_file_handle(file); ltfs_request_trace(FUSE_REQ_EXIT(REQ_CREATE), -ENOMEM, 1); return -ENOMEM; } - overwrite = ((!(fi->flags & O_RDONLY) && !(fi->flags & O_APPEND) && !(fi->flags & O_NONBLOCK)) || (fi->flags & O_TRUNC)); + overwrite = + ((!(fi->flags & O_RDONLY) && !(fi->flags & O_APPEND) && !(fi->flags & O_NONBLOCK)) || (fi->flags & O_TRUNC)); /* Create the file */ ret = ltfs_fsops_create(path, false, readonly, overwrite, (struct dentry **)&dentry_handle, priv->data); @@ -691,35 +671,33 @@ int ltfs_fuse_create(const char *path, mode_t mode, struct fuse_file_info *fi) /* Save handle */ new_file_info = _file_open(path, dentry_handle, file_info, priv); - if (file_info != new_file_info) - _free_file_info(file_info); + if (file_info != new_file_info) _free_file_info(file_info); file->file_info = new_file_info; fi->fh = STRUCT_TO_FILEHANDLE(file); #ifdef __APPLE__ - /* Comment from MacFUSE author about direct_io on OSX: + /* Comment from MacFUSE author about direct_io on OSX: * direct_io is a rather abnormal mode of operation from Mac OS X's * standpoint. Unless your file system requires this mode, I wouldn't * recommend using this option. */ - fi->direct_io = 0; - fi->keep_cache = 0; + fi->direct_io = 0; + fi->keep_cache = 0; #else -#if FUSE_VERSION <= 27 +# if FUSE_VERSION <= 27 /* for FUSE <= 2.7, set direct_io when creating */ fi->direct_io = 1; fi->keep_cache = 0; -#else +# else /* cannot set keep cache if any process has the file open with direct_io set! so only * set it on newer FUSE versions, where we don't use direct_io. */ fi->direct_io = 0; fi->keep_cache = 1; -#endif +# endif #endif - ltfs_request_trace(FUSE_REQ_EXIT(REQ_CREATE), 0, - ((struct dentry *)(file->file_info->dentry_handle))->uid); + ltfs_request_trace(FUSE_REQ_EXIT(REQ_CREATE), 0, ((struct dentry *)(file->file_info->dentry_handle))->uid); return 0; } @@ -771,12 +749,11 @@ int ltfs_fuse_ftruncate(const char *path, off_t length, struct fuse_file_info *f ltfs_request_trace(FUSE_REQ_ENTER(REQ_FTRUNCATE), (uint64_t)length, 0); - ltfsmsg(LTFS_DEBUG, 14043D, _dentry_name(path, file->file_info), (long long) length); + ltfsmsg(LTFS_DEBUG, 14043D, _dentry_name(path, file->file_info), (long long)length); ret = ltfs_fsops_truncate(file->file_info->dentry_handle, length, priv->data); - ltfs_request_trace(FUSE_REQ_EXIT(REQ_FTRUNCATE), ret, - ((struct dentry *)(file->file_info->dentry_handle))->uid); + ltfs_request_trace(FUSE_REQ_EXIT(REQ_FTRUNCATE), ret, ((struct dentry *)(file->file_info->dentry_handle))->uid); return errormap_fuse_error(ret); } @@ -810,7 +787,7 @@ int ltfs_fuse_rmdir(const char *path) ret = ltfs_fsops_unlink(path, &id, priv->data); - ltfs_request_trace(FUSE_REQ_EXIT(REQ_RMDIR), ret, id.uid); + ltfs_request_trace(FUSE_REQ_EXIT(REQ_RMDIR), ret, id.uid); return errormap_fuse_error(ret); } @@ -859,13 +836,11 @@ int _ltfs_fuse_filldir(void *buf, const char *name, void *priv) #endif free(new_name); - if (ret) - return -ENOBUFS; + if (ret) return -ENOBUFS; return 0; } -int ltfs_fuse_readdir(const char *path, void *buf, fuse_fill_dir_t filler, - off_t offset, struct fuse_file_info *fi) +int ltfs_fuse_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) { struct ltfs_fuse_data *priv = fuse_get_context()->private_data; struct ltfs_file_handle *file = FILEHANDLE_TO_STRUCT(fi->fh); @@ -875,7 +850,7 @@ int ltfs_fuse_readdir(const char *path, void *buf, fuse_fill_dir_t filler, ltfsmsg(LTFS_DEBUG, 14047D, _dentry_name(path, file->file_info)); - if (filler(buf, ".", NULL, 0)) { + if (filler(buf, ".", NULL, 0)) { /* No buffer space */ ltfsmsg(LTFS_DEBUG, 14026D); return -ENOBUFS; @@ -886,11 +861,9 @@ int ltfs_fuse_readdir(const char *path, void *buf, fuse_fill_dir_t filler, return -ENOBUFS; } - ret = ltfs_fsops_readdir(file->file_info->dentry_handle, buf, _ltfs_fuse_filldir, - filler, priv->data); + ret = ltfs_fsops_readdir(file->file_info->dentry_handle, buf, _ltfs_fuse_filldir, filler, priv->data); - ltfs_request_trace(FUSE_REQ_EXIT(REQ_READDIR), ret, - ((struct dentry *)(file->file_info->dentry_handle))->uid); + ltfs_request_trace(FUSE_REQ_EXIT(REQ_READDIR), ret, ((struct dentry *)(file->file_info->dentry_handle))->uid); return errormap_fuse_error(ret); } @@ -916,13 +889,13 @@ int ltfs_fuse_write(const char *path, const char *buf, size_t size, off_t offset file->file_info->write_index = true; ltfs_mutex_unlock(&file->file_info->lock); - ltfs_request_trace(FUSE_REQ_EXIT(REQ_WRITE), (uint64_t)size, - ((struct dentry *)(file->file_info->dentry_handle))->uid); + ltfs_request_trace( + FUSE_REQ_EXIT(REQ_WRITE), (uint64_t)size, ((struct dentry *)(file->file_info->dentry_handle))->uid); return size; } else { - ltfs_request_trace(FUSE_REQ_EXIT(REQ_WRITE), (uint64_t)ret, - ((struct dentry *)(file->file_info->dentry_handle))->uid); + ltfs_request_trace( + FUSE_REQ_EXIT(REQ_WRITE), (uint64_t)ret, ((struct dentry *)(file->file_info->dentry_handle))->uid); return errormap_fuse_error(ret); } } @@ -939,18 +912,15 @@ int ltfs_fuse_read(const char *path, char *buf, size_t size, off_t offset, struc ret = ltfs_fsops_read(file->file_info->dentry_handle, buf, size, offset, priv->data); - ltfs_request_trace(FUSE_REQ_EXIT(REQ_READ), (uint64_t)ret, - ((struct dentry *)(file->file_info->dentry_handle))->uid); + ltfs_request_trace(FUSE_REQ_EXIT(REQ_READ), (uint64_t)ret, ((struct dentry *)(file->file_info->dentry_handle))->uid); return errormap_fuse_error(ret); } #ifdef __APPLE__ -int ltfs_fuse_setxattr(const char *path, const char *name, const char *value, size_t size, - int flags, uint32_t position) +int ltfs_fuse_setxattr(const char *path, const char *name, const char *value, size_t size, int flags, uint32_t position) #else -int ltfs_fuse_setxattr(const char *path, const char *name, const char *value, size_t size, - int flags) +int ltfs_fuse_setxattr(const char *path, const char *name, const char *value, size_t size, int flags) #endif /* __APPLE__ */ { struct ltfs_fuse_data *priv = fuse_get_context()->private_data; @@ -982,8 +952,7 @@ int ltfs_fuse_setxattr(const char *path, const char *name, const char *value, si } #ifdef __APPLE__ -int ltfs_fuse_getxattr(const char *path, const char *name, char *value, size_t size, - uint32_t position) +int ltfs_fuse_getxattr(const char *path, const char *name, char *value, size_t size, uint32_t position) #else int ltfs_fuse_getxattr(const char *path, const char *name, char *value, size_t size) #endif /* __APPLE__ */ @@ -1061,7 +1030,7 @@ int ltfs_fuse_removexattr(const char *path, const char *name) * Mount the filesystem. This function assumes a volume has been * allocated and ltfs_mount has been called; it just does some secondary setup. */ -void * ltfs_fuse_mount(struct fuse_conn_info *conn) +void *ltfs_fuse_mount(struct fuse_conn_info *conn) { struct ltfs_fuse_data *priv = fuse_get_context()->private_data; struct statvfs *stats = &priv->fs_stats; @@ -1095,7 +1064,7 @@ void * ltfs_fuse_mount(struct fuse_conn_info *conn) /* Filesystem fragment size. Linux allows any f_frsize, whereas OS X (with MacFUSE) expects * a power of 2 between 512 and 131072. */ -#ifdef __APPLE__ +# ifdef __APPLE__ int nshift; if (stats->f_bsize > 131072) @@ -1110,29 +1079,27 @@ void * ltfs_fuse_mount(struct fuse_conn_info *conn) ++nshift; } stats->f_frsize = 1 << nshift; - if (stats->f_frsize < stats->f_bsize) - stats->f_frsize <<= 1; + if (stats->f_frsize < stats->f_bsize) stats->f_frsize <<= 1; } /* Having f_bsize different from f_frsize should technically be okay, but it * seems that many (most?) programs don't understand the difference. So the only * way to get consistent space usage results is to make them the same. */ stats->f_bsize = stats->f_frsize; -#else +# else stats->f_frsize = stats->f_bsize; -#endif /* __APPLE__ */ +# endif /* __APPLE__ */ - stats->f_favail = 0; /* Ignored by FUSE */ - stats->f_flag = 0; /* Ignored by FUSE */ - stats->f_fsid = LTFS_SUPER_MAGIC; /* Ignored by FUSE */ + stats->f_favail = 0; /* Ignored by FUSE */ + stats->f_flag = 0; /* Ignored by FUSE */ + stats->f_fsid = LTFS_SUPER_MAGIC; /* Ignored by FUSE */ stats->f_namemax = LTFS_FILENAME_MAX; ltfsmsg(LTFS_INFO, 14029I); #endif /* mingw_PLATFORM */ /* Kick timer thread for sync by time */ - if (priv->sync_type == LTFS_SYNC_TIME) - periodic_sync_thread_init(priv->sync_time, priv->data); + if (priv->sync_type == LTFS_SYNC_TIME) periodic_sync_thread_init(priv->sync_time, priv->data); ltfs_request_trace(FUSE_REQ_EXIT(REQ_MOUNT), (uint64_t)priv, 0); @@ -1149,8 +1116,7 @@ void ltfs_fuse_umount(void *userdata) ltfs_request_trace(FUSE_REQ_ENTER(REQ_UNMOUNT), 0, 0); - if (periodic_sync_thread_initialized(priv->data)) - periodic_sync_thread_destroy(priv->data); + if (periodic_sync_thread_initialized(priv->data)) periodic_sync_thread_destroy(priv->data); /* * Destroy the I/O scheduler, if one has been specified by the user. @@ -1158,21 +1124,18 @@ void ltfs_fuse_umount(void *userdata) * is destroyed individually for each mounted volume. */ ltfs_fsops_flush(NULL, true, priv->data); - if (iosched_initialized(priv->data)) - iosched_destroy(priv->data); + if (iosched_initialized(priv->data)) iosched_destroy(priv->data); - if (kmi_initialized(priv->data)) - kmi_destroy(priv->data); + if (kmi_initialized(priv->data)) kmi_destroy(priv->data); ltfs_unmount(SYNC_UNMOUNT, priv->data); - if (priv->capture_index) - ltfs_save_index_to_disk(priv->work_directory, SYNC_UNMOUNT, false, priv->data); + if (priv->capture_index) ltfs_save_index_to_disk(priv->work_directory, SYNC_UNMOUNT, false, priv->data); ltfs_request_trace(FUSE_REQ_EXIT(REQ_UNMOUNT), 0, 0); } -int ltfs_fuse_symlink(const char* to, const char* from) +int ltfs_fuse_symlink(const char *to, const char *from) { struct ltfs_fuse_data *priv = fuse_get_context()->private_data; ltfs_file_id id; @@ -1187,7 +1150,7 @@ int ltfs_fuse_symlink(const char* to, const char* from) return errormap_fuse_error(ret); } -int ltfs_fuse_readlink(const char* path, char* buf, size_t size) +int ltfs_fuse_readlink(const char *path, char *buf, size_t size) { struct ltfs_fuse_data *priv = fuse_get_context()->private_data; ltfs_file_id id; @@ -1203,38 +1166,38 @@ int ltfs_fuse_readlink(const char* path, char* buf, size_t size) } struct fuse_operations ltfs_ops = { - .init = ltfs_fuse_mount, - .destroy = ltfs_fuse_umount, - .getattr = ltfs_fuse_getattr, - .fgetattr = ltfs_fuse_fgetattr, - .access = ltfs_fuse_access, - .statfs = ltfs_fuse_statfs, - .open = ltfs_fuse_open, - .release = ltfs_fuse_release, - .fsync = ltfs_fuse_fsync, - .flush = ltfs_fuse_flush, - .utimens = ltfs_fuse_utimens, - .chmod = ltfs_fuse_chmod, - .chown = ltfs_fuse_chown, - .create = ltfs_fuse_create, - .truncate = ltfs_fuse_truncate, - .ftruncate = ltfs_fuse_ftruncate, - .unlink = ltfs_fuse_unlink, - .rename = ltfs_fuse_rename, - .mkdir = ltfs_fuse_mkdir, - .rmdir = ltfs_fuse_rmdir, - .opendir = ltfs_fuse_opendir, - .readdir = ltfs_fuse_readdir, - .releasedir = ltfs_fuse_releasedir, - .fsyncdir = ltfs_fuse_fsyncdir, - .write = ltfs_fuse_write, - .read = ltfs_fuse_read, - .setxattr = ltfs_fuse_setxattr, - .getxattr = ltfs_fuse_getxattr, - .listxattr = ltfs_fuse_listxattr, + .init = ltfs_fuse_mount, + .destroy = ltfs_fuse_umount, + .getattr = ltfs_fuse_getattr, + .fgetattr = ltfs_fuse_fgetattr, + .access = ltfs_fuse_access, + .statfs = ltfs_fuse_statfs, + .open = ltfs_fuse_open, + .release = ltfs_fuse_release, + .fsync = ltfs_fuse_fsync, + .flush = ltfs_fuse_flush, + .utimens = ltfs_fuse_utimens, + .chmod = ltfs_fuse_chmod, + .chown = ltfs_fuse_chown, + .create = ltfs_fuse_create, + .truncate = ltfs_fuse_truncate, + .ftruncate = ltfs_fuse_ftruncate, + .unlink = ltfs_fuse_unlink, + .rename = ltfs_fuse_rename, + .mkdir = ltfs_fuse_mkdir, + .rmdir = ltfs_fuse_rmdir, + .opendir = ltfs_fuse_opendir, + .readdir = ltfs_fuse_readdir, + .releasedir = ltfs_fuse_releasedir, + .fsyncdir = ltfs_fuse_fsyncdir, + .write = ltfs_fuse_write, + .read = ltfs_fuse_read, + .setxattr = ltfs_fuse_setxattr, + .getxattr = ltfs_fuse_getxattr, + .listxattr = ltfs_fuse_listxattr, .removexattr = ltfs_fuse_removexattr, - .symlink = ltfs_fuse_symlink, - .readlink = ltfs_fuse_readlink, + .symlink = ltfs_fuse_symlink, + .readlink = ltfs_fuse_readlink, #if FUSE_VERSION >= 28 .flag_nullpath_ok = 1, #endif diff --git a/src/main.c b/src/main.c index 533ec70d..22d1a10a 100644 --- a/src/main.c +++ b/src/main.c @@ -54,23 +54,23 @@ ** ************************************************************************************* */ -#include #include -#include #include +#include +#include -#include "ltfs_fuse.h" -#include "libltfs/ltfs.h" -#include "ltfs_copyright.h" -#include "libltfs/pathname.h" -#include "libltfs/plugin.h" #include "libltfs/dcache.h" #include "libltfs/index_criteria.h" -#include "libltfs/ltfssnmp.h" #include "libltfs/kmi.h" +#include "libltfs/ltfs.h" +#include "libltfs/ltfssnmp.h" +#include "libltfs/pathname.h" +#include "libltfs/plugin.h" #include "libltfs/tape.h" +#include "ltfs_copyright.h" +#include "ltfs_fuse.h" -volatile char *copyright = LTFS_COPYRIGHT_0"\n"LTFS_COPYRIGHT_1"\n"LTFS_COPYRIGHT_2"\n"; +volatile char *copyright = LTFS_COPYRIGHT_0 "\n" LTFS_COPYRIGHT_1 "\n" LTFS_COPYRIGHT_2 "\n"; /* Defined in src/ltfs.c */ extern struct fuse_operations ltfs_ops; @@ -80,102 +80,99 @@ extern char bin_ltfs_dat[]; /** * Command line parsing */ -enum { +enum +{ KEY_HELP, KEY_VERSION, KEY_VERBOSE, KEY_ADVANCED_HELP, }; -#define LTFS_OPT(templ,offset,value) { templ, offsetof(struct ltfs_fuse_data, offset), value } -#define LTFS_OPT_KEY(templ, key) { templ, -1U, key } +#define LTFS_OPT(templ, offset, value) { templ, offsetof(struct ltfs_fuse_data, offset), value } +#define LTFS_OPT_KEY(templ, key) { templ, -1U, key } /* Forward declarations */ int single_drive_main(struct fuse_args *args, struct ltfs_fuse_data *priv); -static struct fuse_opt ltfs_options_pass1[] = { - LTFS_OPT("config_file=%s", config_file, 0), - LTFS_OPT_KEY("-a", KEY_ADVANCED_HELP), - FUSE_OPT_KEY("-h", KEY_HELP), - FUSE_OPT_KEY("--help", KEY_HELP), - FUSE_OPT_KEY("-V", KEY_VERSION), - FUSE_OPT_KEY("--version", KEY_VERSION), - FUSE_OPT_END -}; - -static struct fuse_opt ltfs_options[] = { - LTFS_OPT("devname=%s", devname, 0), - LTFS_OPT("work_directory=%s", work_directory, 0), - LTFS_OPT("atime", atime, 1), - LTFS_OPT("noatime", atime, 0), - LTFS_OPT("tape_backend=%s", tape_backend_name, 0), - LTFS_OPT("iosched_backend=%s", iosched_backend_name, 0), - LTFS_OPT("kmi_backend=%s", kmi_backend_name, 0), - LTFS_OPT("umask=%s", force_umask, 0), - LTFS_OPT("fmask=%s", force_fmask, 0), - LTFS_OPT("dmask=%s", force_dmask, 0), - LTFS_OPT("uid=%s", force_uid, 0), - LTFS_OPT("gid=%s", force_gid, 0), - LTFS_OPT("min_pool_size=%s", force_min_pool, 0), - LTFS_OPT("max_pool_size=%s", force_max_pool, 0), - LTFS_OPT("rules=%s", index_rules, 0), - LTFS_OPT("quiet", verbose, LTFS_WARN), - LTFS_OPT("trace", verbose, LTFS_DEBUG), - LTFS_OPT("syslogtrace", verbose, LTFS_DEBUG * 100 + LTFS_DEBUG), - LTFS_OPT("fulltrace", verbose, LTFS_TRACE), - LTFS_OPT("verbose=%d", verbose, 0), - LTFS_OPT("eject", eject, 1), - LTFS_OPT("noeject", eject, 0), - LTFS_OPT("sync_type=%s", sync_type_str, 0), - LTFS_OPT("force_mount_no_eod", skip_eod_check, 1), - LTFS_OPT("device_list", device_list, 1), - LTFS_OPT("rollback_mount=%s", rollback_str, 0), - LTFS_OPT("release_device", release_device, 1), - LTFS_OPT("allow_other", allow_other, 1), - LTFS_OPT("noallow_other", allow_other, 0), - LTFS_OPT("capture_index", capture_index, 1), - LTFS_OPT("symlink_type=%s", symlink_str, 0), - LTFS_OPT("scsi_append_only_mode=%s", str_append_only_mode, 0), - LTFS_OPT_KEY("-a", KEY_ADVANCED_HELP), - FUSE_OPT_KEY("-h", KEY_HELP), - FUSE_OPT_KEY("--help", KEY_HELP), - FUSE_OPT_KEY("-V", KEY_VERSION), - FUSE_OPT_KEY("--version", KEY_VERSION), - FUSE_OPT_END -}; +static struct fuse_opt ltfs_options_pass1[] = { LTFS_OPT("config_file=%s", config_file, 0), + LTFS_OPT_KEY("-a", KEY_ADVANCED_HELP), + FUSE_OPT_KEY("-h", KEY_HELP), + FUSE_OPT_KEY("--help", KEY_HELP), + FUSE_OPT_KEY("-V", KEY_VERSION), + FUSE_OPT_KEY("--version", KEY_VERSION), + FUSE_OPT_END }; + +static struct fuse_opt ltfs_options[] = { LTFS_OPT("devname=%s", devname, 0), + LTFS_OPT("work_directory=%s", work_directory, 0), + LTFS_OPT("atime", atime, 1), + LTFS_OPT("noatime", atime, 0), + LTFS_OPT("tape_backend=%s", tape_backend_name, 0), + LTFS_OPT("iosched_backend=%s", iosched_backend_name, 0), + LTFS_OPT("kmi_backend=%s", kmi_backend_name, 0), + LTFS_OPT("umask=%s", force_umask, 0), + LTFS_OPT("fmask=%s", force_fmask, 0), + LTFS_OPT("dmask=%s", force_dmask, 0), + LTFS_OPT("uid=%s", force_uid, 0), + LTFS_OPT("gid=%s", force_gid, 0), + LTFS_OPT("min_pool_size=%s", force_min_pool, 0), + LTFS_OPT("max_pool_size=%s", force_max_pool, 0), + LTFS_OPT("rules=%s", index_rules, 0), + LTFS_OPT("quiet", verbose, LTFS_WARN), + LTFS_OPT("trace", verbose, LTFS_DEBUG), + LTFS_OPT("syslogtrace", verbose, LTFS_DEBUG * 100 + LTFS_DEBUG), + LTFS_OPT("fulltrace", verbose, LTFS_TRACE), + LTFS_OPT("verbose=%d", verbose, 0), + LTFS_OPT("eject", eject, 1), + LTFS_OPT("noeject", eject, 0), + LTFS_OPT("sync_type=%s", sync_type_str, 0), + LTFS_OPT("force_mount_no_eod", skip_eod_check, 1), + LTFS_OPT("device_list", device_list, 1), + LTFS_OPT("rollback_mount=%s", rollback_str, 0), + LTFS_OPT("release_device", release_device, 1), + LTFS_OPT("allow_other", allow_other, 1), + LTFS_OPT("noallow_other", allow_other, 0), + LTFS_OPT("capture_index", capture_index, 1), + LTFS_OPT("symlink_type=%s", symlink_str, 0), + LTFS_OPT("scsi_append_only_mode=%s", str_append_only_mode, 0), + LTFS_OPT_KEY("-a", KEY_ADVANCED_HELP), + FUSE_OPT_KEY("-h", KEY_HELP), + FUSE_OPT_KEY("--help", KEY_HELP), + FUSE_OPT_KEY("-V", KEY_VERSION), + FUSE_OPT_KEY("--version", KEY_VERSION), + FUSE_OPT_END }; void single_drive_advanced_usage(const char *default_driver, struct ltfs_fuse_data *priv) { - ltfsresult(14401I); /* LTFS options: */ - ltfsresult(14413I, LTFS_CONFIG_FILE); /* -o config_file= */ - ltfsresult(14404I, LTFS_DEFAULT_WORK_DIR); /* -o work_directory= */ - ltfsresult(14414I); /* -o atime */ - ltfsresult(14440I); /* -o noatime */ - ltfsresult(14415I, default_driver); /* -o tape_backend= */ + ltfsresult(14401I); /* LTFS options: */ + ltfsresult(14413I, LTFS_CONFIG_FILE); /* -o config_file= */ + ltfsresult(14404I, LTFS_DEFAULT_WORK_DIR); /* -o work_directory= */ + ltfsresult(14414I); /* -o atime */ + ltfsresult(14440I); /* -o noatime */ + ltfsresult(14415I, default_driver); /* -o tape_backend= */ ltfsresult(14416I, config_file_get_default_plugin("iosched", priv->config)); /* -o iosched_backend= */ - ltfsresult(14455I, config_file_get_default_plugin("kmi", priv->config)); /* -o kmi_backend= */ - ltfsresult(14417I); /* -o umask= */ - ltfsresult(14418I); /* -o fmask= */ - ltfsresult(14419I); /* -o dmask= */ - ltfsresult(14420I, LTFS_MIN_CACHE_SIZE_DEFAULT); /* -o min_pool_size= */ - ltfsresult(14421I, LTFS_MAX_CACHE_SIZE_DEFAULT); /* -o max_pool_size= */ - ltfsresult(14422I); /* -o rules= */ - ltfsresult(14423I); /* -o quiet */ - ltfsresult(14405I); /* -o trace */ - ltfsresult(14467I); /* -o syslogtrace */ - ltfsresult(14424I); /* -o fulltrace */ - ltfsresult(14441I, LTFS_INFO); /* -o verbose= */ - ltfsresult(14425I); /* -o eject */ - ltfsresult(14439I); /* -o noeject */ - ltfsresult(14427I, LONG_MAX / 60); /* -o sync_type=type */ - ltfsresult(14443I); /* -o force_mount_no_eod */ - ltfsresult(14436I); /* -o device_list */ - ltfsresult(14437I); /* -o rollback_mount */ - ltfsresult(14448I); /* -o release_device */ - ltfsresult(14456I); /* -o capture_index */ - ltfsresult(14463I); /* -o scsi_append_only_mode= */ - ltfsresult(14406I); /* -a */ - /* TODO: future use for WORM */ + ltfsresult(14455I, config_file_get_default_plugin("kmi", priv->config)); /* -o kmi_backend= */ + ltfsresult(14417I); /* -o umask= */ + ltfsresult(14418I); /* -o fmask= */ + ltfsresult(14419I); /* -o dmask= */ + ltfsresult(14420I, LTFS_MIN_CACHE_SIZE_DEFAULT); /* -o min_pool_size= */ + ltfsresult(14421I, LTFS_MAX_CACHE_SIZE_DEFAULT); /* -o max_pool_size= */ + ltfsresult(14422I); /* -o rules= */ + ltfsresult(14423I); /* -o quiet */ + ltfsresult(14405I); /* -o trace */ + ltfsresult(14467I); /* -o syslogtrace */ + ltfsresult(14424I); /* -o fulltrace */ + ltfsresult(14441I, LTFS_INFO); /* -o verbose= */ + ltfsresult(14425I); /* -o eject */ + ltfsresult(14439I); /* -o noeject */ + ltfsresult(14427I, LONG_MAX / 60); /* -o sync_type=type */ + ltfsresult(14443I); /* -o force_mount_no_eod */ + ltfsresult(14436I); /* -o device_list */ + ltfsresult(14437I); /* -o rollback_mount */ + ltfsresult(14448I); /* -o release_device */ + ltfsresult(14456I); /* -o capture_index */ + ltfsresult(14463I); /* -o scsi_append_only_mode= */ + ltfsresult(14406I); /* -a */ + /* TODO: future use for WORM */ /* set worm rollback flag and rollback_str by this option */ /* ltfsresult(14468I); */ /* -o rollback_mount_no_eod */ } @@ -186,43 +183,40 @@ void usage(char *progname, struct ltfs_fuse_data *priv) const char *default_driver = config_file_get_default_plugin("tape", priv->config); const char *default_device = NULL; - if (! priv->advanced_help) { - if (! priv->tape_backend_name) - priv->tape_backend_name = default_driver; + if (!priv->advanced_help) { + if (!priv->tape_backend_name) priv->tape_backend_name = default_driver; ret = plugin_load(&priv->tape_plugin, "tape", priv->tape_backend_name, priv->config); - if (ret == 0) - default_device = ltfs_default_device_name(priv->tape_plugin.ops); + if (ret == 0) default_device = ltfs_default_device_name(priv->tape_plugin.ops); - ltfsresult(14400I, progname); /* usage: %s mountpoint [options] */ + ltfsresult(14400I, progname); /* usage: %s mountpoint [options] */ fprintf(stderr, "\n"); - ltfsresult(14401I); /* LTFS options: */ + ltfsresult(14401I); /* LTFS options: */ if (default_device) - ltfsresult(14402I, default_device); /* -o devname= */ + ltfsresult(14402I, default_device); /* -o devname= */ else - ltfsresult(14403I); /* -o devname= */ - ltfsresult(14404I, LTFS_DEFAULT_WORK_DIR); /* -o work_directory= */ - ltfsresult(14405I); /* -o trace */ - ltfsresult(14425I); /* -o eject */ - ltfsresult(14427I, LONG_MAX / 60); /* -o sync_type=type */ - ltfsresult(14443I); /* -o force_mount_no_eod */ - ltfsresult(14436I); /* -o device_list */ - ltfsresult(14437I); /* -o rollback_mount */ - ltfsresult(14448I); /* -o release_device */ - ltfsresult(14461I); /* -o symlink_type=type */ - ltfsresult(14406I); /* -a */ - ltfsresult(14407I); /* -V, --version */ - ltfsresult(14408I); /* -h, --help */ + ltfsresult(14403I); /* -o devname= */ + ltfsresult(14404I, LTFS_DEFAULT_WORK_DIR); /* -o work_directory= */ + ltfsresult(14405I); /* -o trace */ + ltfsresult(14425I); /* -o eject */ + ltfsresult(14427I, LONG_MAX / 60); /* -o sync_type=type */ + ltfsresult(14443I); /* -o force_mount_no_eod */ + ltfsresult(14436I); /* -o device_list */ + ltfsresult(14437I); /* -o rollback_mount */ + ltfsresult(14448I); /* -o release_device */ + ltfsresult(14461I); /* -o symlink_type=type */ + ltfsresult(14406I); /* -a */ + ltfsresult(14407I); /* -V, --version */ + ltfsresult(14408I); /* -h, --help */ fprintf(stderr, "\n"); - ltfsresult(14409I); /* FUSE options: */ - ltfsresult(14410I); /* -o umask=M */ - ltfsresult(14411I); /* -o uid=N */ - ltfsresult(14412I); /* -o gid=N */ + ltfsresult(14409I); /* FUSE options: */ + ltfsresult(14410I); /* -o umask=M */ + ltfsresult(14411I); /* -o uid=N */ + ltfsresult(14412I); /* -o gid=N */ fprintf(stderr, "\n"); fprintf(stderr, "\n"); - if (ret == 0) - plugin_unload(&priv->tape_plugin); + if (ret == 0) plugin_unload(&priv->tape_plugin); } else { fprintf(stderr, "\n"); single_drive_advanced_usage(default_driver, priv); @@ -234,11 +228,8 @@ void usage(char *progname, struct ltfs_fuse_data *priv) mode_t parse_mode(char *input) { - if (! input || strlen(input) != 3) - return (mode_t)-1; - if (input[0] < '0' || input[0] > '7' || - input[1] < '0' || input[1] > '7' || - input[2] < '0' || input[2] > '7') + if (!input || strlen(input) != 3) return (mode_t)-1; + if (input[0] < '0' || input[0] > '7' || input[1] < '0' || input[1] > '7' || input[2] < '0' || input[2] > '7') return (mode_t)-1; return ((input[0] - '0') << 6) | ((input[1] - '0') << 3) | (input[2] - '0'); } @@ -247,13 +238,10 @@ uid_t parse_uid(const char *input) { const char *i; struct passwd *pw = getpwnam(input); - if (pw) - return pw->pw_uid; - if (input[0] == '\0') - return (uid_t)-1; - for (i=input; *i; ++i) - if (*i < '0' || *i > '9') - return (uid_t)-1; + if (pw) return pw->pw_uid; + if (input[0] == '\0') return (uid_t)-1; + for (i = input; *i; ++i) + if (*i < '0' || *i > '9') return (uid_t)-1; return strtoul(input, NULL, 10); } @@ -261,24 +249,19 @@ gid_t parse_gid(const char *input) { const char *i; struct group *gr = getgrnam(input); - if (gr) - return gr->gr_gid; - if (input[0] == '\0') - return (gid_t)-1; - for (i=input; *i; ++i) - if (*i < '0' || *i > '9') - return (gid_t)-1; + if (gr) return gr->gr_gid; + if (input[0] == '\0') return (gid_t)-1; + for (i = input; *i; ++i) + if (*i < '0' || *i > '9') return (gid_t)-1; return strtoul(input, NULL, 10); } size_t parse_size_t(const char *input) { const char *i; - if (input[0] == '\0') - return 0; - for (i=input; *i; i++) - if (*i < '0' || *i > '9') - return 0; + if (input[0] == '\0') return 0; + for (i = input; *i; i++) + if (*i < '0' || *i > '9') return 0; return strtoull(input, NULL, 10); } @@ -361,7 +344,7 @@ int permissions_setup(struct ltfs_fuse_data *priv) free(priv->force_dmask); } -/* Uncomment to apply the current umask to the default permissions, as vfat does. + /* Uncomment to apply the current umask to the default permissions, as vfat does. mode = umask(0); umask(mode); if (! priv->force_umask && ! priv->force_fmask) @@ -375,12 +358,12 @@ int permissions_setup(struct ltfs_fuse_data *priv) int ltfs_parse_options(void *priv_data, const char *arg, int key, struct fuse_args *outargs) { - struct ltfs_fuse_data *priv = (struct ltfs_fuse_data *) priv_data; + struct ltfs_fuse_data *priv = (struct ltfs_fuse_data *)priv_data; const char *fuse_options[] = { "-f", "-d", "-s", NULL }; bool valid_fuse_option = false; int i; - switch(key) { + switch (key) { case KEY_VERSION: ltfsresult(14058I, PACKAGE_NAME, PACKAGE_VERSION); ltfsresult(14058I, "LTFS Format Specification", LTFS_INDEX_VERSION_STR); @@ -391,14 +374,14 @@ int ltfs_parse_options(void *priv_data, const char *arg, int key, struct fuse_ar /* fall through */ case FUSE_OPT_KEY_OPT: case FUSE_OPT_KEY_NONOPT: - for (i=0; arg && fuse_options[i]; ++i) { - if (! strcmp(arg, fuse_options[i])) { + for (i = 0; arg && fuse_options[i]; ++i) { + if (!strcmp(arg, fuse_options[i])) { valid_fuse_option = true; break; } } - if (! priv->advanced_help) { - if (! valid_fuse_option && key == FUSE_OPT_KEY_OPT && arg && arg[0] == '-') { + if (!priv->advanced_help) { + if (!valid_fuse_option && key == FUSE_OPT_KEY_OPT && arg && arg[0] == '-') { /* invalid option */ ltfsmsg(LTFS_ERR, 9010E, arg); } else @@ -407,10 +390,9 @@ int ltfs_parse_options(void *priv_data, const char *arg, int key, struct fuse_ar /* fall through */ case KEY_HELP: default: - if (! priv->first_parsing_pass) { + if (!priv->first_parsing_pass) { fuse_opt_add_arg(outargs, "-h"); - if (priv->advanced_help) - fuse_main(outargs->argc, outargs->argv, <fs_ops, NULL); + if (priv->advanced_help) fuse_main(outargs->argc, outargs->argv, <fs_ops, NULL); usage(outargs->argv[0], priv); exit(key == KEY_HELP ? 0 : 1); } @@ -421,27 +403,24 @@ int ltfs_parse_options(void *priv_data, const char *arg, int key, struct fuse_ar int mkdir_p(const char *path, mode_t mode) { - char *ptr, buf[strlen(path)+1]; + char *ptr, buf[strlen(path) + 1]; struct stat statbuf; int ret; sprintf(buf, "%s", path); ret = stat(path, &statbuf); - if (ret == 0) - return 0; + if (ret == 0) return 0; - for (ptr=(buf[0] == '/') ? &buf[1] : buf; *ptr; ++ptr) { + for (ptr = (buf[0] == '/') ? &buf[1] : buf; *ptr; ++ptr) { bool last = ptr[1] == '\0'; - if (*ptr == '/') - *ptr = '\0'; + if (*ptr == '/') *ptr = '\0'; if (*ptr == '\0' || last) { ret = mkdir(buf, mode); if (ret && errno != EEXIST) { ltfsmsg(LTFS_ERR, 9014E, path, strerror(errno)); return 1; } - if (! last) - *(ptr++) = '/'; + if (!last) *(ptr++) = '/'; } } return 0; @@ -460,7 +439,7 @@ static int create_workdir(struct ltfs_fuse_data *priv) ltfsmsg(LTFS_ERR, 14004E, ret); return ret; } - } else if (! S_ISDIR(statbuf.st_mode)) { + } else if (!S_ISDIR(statbuf.st_mode)) { /* Path exists but is not a directory */ ltfsmsg(LTFS_ERR, 14005E, priv->work_directory); return -ENOTDIR; @@ -545,8 +524,7 @@ static int show_device_list(struct ltfs_fuse_data *priv) int ret; /* Load tape backend */ - if (priv->tape_backend_name == NULL) - priv->tape_backend_name = config_file_get_default_plugin("tape", priv->config); + if (priv->tape_backend_name == NULL) priv->tape_backend_name = config_file_get_default_plugin("tape", priv->config); ret = plugin_load(&priv->tape_plugin, "tape", priv->tape_backend_name, priv->config); if (ret < 0) { ltfsmsg(LTFS_ERR, 14054E, ret); @@ -566,7 +544,7 @@ int main(int argc, char **argv) { int ret, i, cmd_args_len; struct fuse_args args = FUSE_ARGS_INIT(argc, argv); - struct ltfs_fuse_data *priv = (struct ltfs_fuse_data *) calloc(1, sizeof(struct ltfs_fuse_data)); + struct ltfs_fuse_data *priv = (struct ltfs_fuse_data *)calloc(1, sizeof(struct ltfs_fuse_data)); char *lang, **mount_options, **snmp_options, *cmd_args; void *message_handle; @@ -576,8 +554,10 @@ int main(int argc, char **argv) /* Check for LANG variable and set it to en_US.UTF-8 if it is unset. */ lang = getenv("LANG"); - if (! lang) { - fprintf(stderr, "LTFS9015W Setting the locale to 'en_US.UTF-8'. If this is wrong, please set the LANG environment variable before starting ltfs.\n"); + if (!lang) { + fprintf(stderr, + "LTFS9015W Setting the locale to 'en_US.UTF-8'. If this is wrong, please set the LANG environment variable " + "before starting ltfs.\n"); ret = setenv("LANG", "en_US.UTF-8", 1); if (ret) { fprintf(stderr, "LTFS9016E Cannot set the LANG environment variable\n"); @@ -601,7 +581,7 @@ int main(int argc, char **argv) return 1; } - if (! priv) { + if (!priv) { ltfsmsg(LTFS_ERR, 10001E, "main: private data"); return 1; } @@ -625,11 +605,11 @@ int main(int argc, char **argv) snmp_options = config_file_get_options("snmp", priv->config); if (snmp_options) { priv->snmp_enabled = false; - for (i=0; snmp_options[i]; ++i) { - if (! strcmp(snmp_options[i], "enabled")) + for (i = 0; snmp_options[i]; ++i) { + if (!strcmp(snmp_options[i], "enabled")) priv->snmp_enabled = true; - else if (! strncmp(snmp_options[i], "deffile ", 8)) { - ret = asprintf(&priv->snmp_deffile, "%s", snmp_options[i]+8); + else if (!strncmp(snmp_options[i], "deffile ", 8)) { + ret = asprintf(&priv->snmp_deffile, "%s", snmp_options[i] + 8); if (ret < 0) { ltfsmsg(LTFS_ERR, 10001E, "library_main: snmp_deffile"); priv->snmp_enabled = false; @@ -638,17 +618,15 @@ int main(int argc, char **argv) } free(snmp_options[i]); } - if (priv->snmp_enabled) - ltfs_snmp_init(priv->snmp_deffile); + if (priv->snmp_enabled) ltfs_snmp_init(priv->snmp_deffile); free(snmp_options); } /* Bring in extra mount options set in the config file */ mount_options = config_file_get_options("single-drive", priv->config); - if (! mount_options) - return 1; - for (i=0; mount_options[i]; ++i) { - ret = fuse_opt_insert_arg(&args, i+1, mount_options[i]); + if (!mount_options) return 1; + for (i = 0; mount_options[i]; ++i) { + ret = fuse_opt_insert_arg(&args, i + 1, mount_options[i]); if (ret < 0) { /* Could not enable FUSE option */ ltfsmsg(LTFS_ERR, 14001E, mount_options[i], ret); @@ -667,8 +645,7 @@ int main(int argc, char **argv) } /* Set the logging level */ - if (priv->verbose > 100) - ltfs_set_syslog_level(priv->verbose / 100); + if (priv->verbose > 100) ltfs_set_syslog_level(priv->verbose / 100); ltfs_set_log_level(priv->verbose % 100); /* LTFS starting */ @@ -676,7 +653,7 @@ int main(int argc, char **argv) ltfsmsg(LTFS_INFO, 14058I, "LTFS Format Specification", LTFS_INDEX_VERSION_STR); /* Show command line arguments */ - for (i = 0, cmd_args_len = 0 ; i < argc; i++) { + for (i = 0, cmd_args_len = 0; i < argc; i++) { cmd_args_len += strlen(argv[i]) + 1; } cmd_args = calloc(1, cmd_args_len + 1); @@ -709,11 +686,10 @@ int main(int argc, char **argv) /* Validate sync option */ ret = validate_sync_option(priv); - if (ret != 0) - return 1; /* Error message was already displayed */ + if (ret != 0) return 1; /* Error message was already displayed */ /* Print the active sync mode */ - switch(priv->sync_type) { + switch (priv->sync_type) { case LTFS_SYNC_TIME: ltfsmsg(LTFS_INFO, 14063I, "time", priv->sync_time); break; @@ -763,11 +739,11 @@ int main(int argc, char **argv) } #ifdef __APPLE__ - /* Change MacFUSE timeout from 60 secs to 3100 secs (41mins) */ - /* 3100 secs comes from the timeout value of locate/space, it is the most longest timeout value */ - /* in the commands used by LTFS. Actually the timeout value of locate/space is 2500 secs, */ - /* we set the MacFUSE as the timeout value of locate/space + 10 mins. Because MacFUSE timeout */ - /* should come after the drive command timeout. */ + /* Change MacFUSE timeout from 60 secs to 3100 secs (41mins) */ + /* 3100 secs comes from the timeout value of locate/space, it is the most longest timeout value */ + /* in the commands used by LTFS. Actually the timeout value of locate/space is 2500 secs, */ + /* we set the MacFUSE as the timeout value of locate/space + 10 mins. Because MacFUSE timeout */ + /* should come after the drive command timeout. */ fuse_opt_add_arg(&args, "-odaemon_timeout=3100"); if (ret < 0) { /* Could not enable FUSE option */ @@ -817,14 +793,10 @@ int main(int argc, char **argv) } if (priv->iosched_backend_name == NULL) priv->iosched_backend_name = config_file_get_default_plugin("iosched", priv->config); - if (priv->iosched_backend_name && strcmp(priv->iosched_backend_name, "none") == 0) - priv->iosched_backend_name = NULL; - if (priv->kmi_backend_name == NULL) - priv->kmi_backend_name = config_file_get_default_plugin("kmi", priv->config); - if (priv->kmi_backend_name && strcmp(priv->kmi_backend_name, "none") == 0) - priv->kmi_backend_name = NULL; - if (priv->work_directory == NULL || ! strcmp(priv->work_directory, "")) - priv->work_directory = LTFS_DEFAULT_WORK_DIR; + if (priv->iosched_backend_name && strcmp(priv->iosched_backend_name, "none") == 0) priv->iosched_backend_name = NULL; + if (priv->kmi_backend_name == NULL) priv->kmi_backend_name = config_file_get_default_plugin("kmi", priv->config); + if (priv->kmi_backend_name && strcmp(priv->kmi_backend_name, "none") == 0) priv->kmi_backend_name = NULL; + if (priv->work_directory == NULL || !strcmp(priv->work_directory, "")) priv->work_directory = LTFS_DEFAULT_WORK_DIR; if (priv->force_min_pool) { priv->min_pool_size = parse_size_t(priv->force_min_pool); if (priv->min_pool_size == 0) { @@ -849,8 +821,7 @@ int main(int argc, char **argv) /* Make sure work directory exists */ ret = create_workdir(priv); - if (ret < 0) - return 1; + if (ret < 0) return 1; /* Load plugins */ ret = plugin_load(&priv->tape_plugin, "tape", priv->tape_backend_name, priv->config); @@ -859,16 +830,14 @@ int main(int argc, char **argv) return 1; } if (priv->iosched_backend_name) { - ret = plugin_load(&priv->iosched_plugin, "iosched", priv->iosched_backend_name, - priv->config); + ret = plugin_load(&priv->iosched_plugin, "iosched", priv->iosched_backend_name, priv->config); if (ret < 0) { ltfsmsg(LTFS_ERR, 14055E, ret); return 1; } } if (priv->kmi_backend_name) { - ret = plugin_load(&priv->kmi_plugin, "kmi", priv->kmi_backend_name, - priv->config); + ret = plugin_load(&priv->kmi_plugin, "kmi", priv->kmi_backend_name, priv->config); if (ret < 0) { ltfsmsg(LTFS_ERR, 14057E, ret); return 1; @@ -876,9 +845,9 @@ int main(int argc, char **argv) } /* Make sure we have a device name */ - if (! priv->devname) { + if (!priv->devname) { priv->devname = ltfs_default_device_name(priv->tape_plugin.ops); - if (! priv->devname) { + if (!priv->devname) { /* The backend \'%s\' does not have a default device */ ltfsmsg(LTFS_ERR, 14009E, priv->tape_backend_name); return 1; @@ -887,8 +856,7 @@ int main(int argc, char **argv) /* Initialize filesystem component in libltfs */ ret = ltfs_fs_init(); - if (ret) - return 1; + if (ret) return 1; /* Invoke the single drive main operations */ ret = ltfs_mutex_init(&priv->file_table_lock); @@ -900,14 +868,11 @@ int main(int argc, char **argv) ret = single_drive_main(&args, priv); /* Send a trap of LTFS termination */ - if (priv->snmp_enabled) - ltfs_snmp_finish(); + if (priv->snmp_enabled) ltfs_snmp_finish(); /* Unload plugins */ - if (priv->iosched_backend_name) - plugin_unload(&priv->iosched_plugin); - if (priv->kmi_backend_name) - plugin_unload(&priv->kmi_plugin); + if (priv->iosched_backend_name) plugin_unload(&priv->iosched_plugin); + if (priv->kmi_backend_name) plugin_unload(&priv->kmi_plugin); plugin_unload(&priv->tape_plugin); /* Free data structures */ @@ -930,7 +895,7 @@ int single_drive_main(struct fuse_args *args, struct ltfs_fuse_data *priv) char *opt_volname = NULL; #endif char *mountpoint = NULL; - struct fuse_args tmpa=FUSE_ARGS_INIT(0, NULL); + struct fuse_args tmpa = FUSE_ARGS_INIT(0, NULL); int i; bool is_worm = false, is_ro = false; @@ -945,7 +910,7 @@ int single_drive_main(struct fuse_args *args, struct ltfs_fuse_data *priv) if (priv->rollback_str) { errno = 0; priv->rollback_gen = strtoul(priv->rollback_str, &invalid_start, 0); - if( (*invalid_start != '\0') || priv->rollback_gen == 0 ) { + if ((*invalid_start != '\0') || priv->rollback_gen == 0) { ltfsmsg(LTFS_ERR, 14091E, priv->rollback_str); return 1; } @@ -1037,8 +1002,7 @@ int single_drive_main(struct fuse_args *args, struct ltfs_fuse_data *priv) return 1; } - if (tape_clear_key(priv->data->device, priv->data->kmi_handle) < 0) - return 1; + if (tape_clear_key(priv->data->device, priv->data->kmi_handle) < 0) return 1; } /* Setup tape drive */ @@ -1061,7 +1025,7 @@ int single_drive_main(struct fuse_args *args, struct ltfs_fuse_data *priv) if (priv->skip_eod_check) { ltfsmsg(LTFS_INFO, 14076I); ltfsmsg(LTFS_INFO, 14077I); - ltfs_set_eod_check(! priv->skip_eod_check, priv->data); + ltfs_set_eod_check(!priv->skip_eod_check, priv->data); } /* Validate symbolic link type */ @@ -1154,7 +1118,7 @@ int single_drive_main(struct fuse_args *args, struct ltfs_fuse_data *priv) /* The index partition is in early warning zone. To be mounted read-only */ ltfsmsg(LTFS_INFO, 14073I); break; - default: /* 0 or -LTFS_LESS_SPACE */ + default: /* 0 or -LTFS_LESS_SPACE */ /* The data partition may be in early warning zone. To be mounted read-only */ ltfsmsg(LTFS_INFO, 14074I); break; @@ -1220,10 +1184,10 @@ int single_drive_main(struct fuse_args *args, struct ltfs_fuse_data *priv) #endif /* Get and store mount point */ - for ( i=0; iargc; i++) { + for (i = 0; i < args->argc; i++) { fuse_opt_add_arg(&tmpa, args->argv[i]); } - ret = fuse_parse_cmdline( &tmpa, &mountpoint, NULL, NULL); + ret = fuse_parse_cmdline(&tmpa, &mountpoint, NULL, NULL); fuse_opt_free_args(&tmpa); if (ret < 0 || mountpoint == NULL) { ltfsmsg(LTFS_ERR, 14094E, ret); @@ -1234,8 +1198,7 @@ int single_drive_main(struct fuse_args *args, struct ltfs_fuse_data *priv) priv->data->mountpoint_len = strlen(mountpoint); /* Send a trap of LTFS start */ - if (priv->snmp_enabled) - send_ltfsStartTrap(); + if (priv->snmp_enabled) send_ltfsStartTrap(); /* now we can safely call FUSE */ ltfsmsg(LTFS_INFO, 14111I); @@ -1257,13 +1220,11 @@ int single_drive_main(struct fuse_args *args, struct ltfs_fuse_data *priv) return 1; } - if (priv->eject) - ltfs_eject_tape(false, priv->data); + if (priv->eject) ltfs_eject_tape(false, priv->data); /* close the volume */ #ifdef __APPLE__ - if (opt_volname) - free(opt_volname); + if (opt_volname) free(opt_volname); #endif ltfs_device_close(priv->data); ltfs_volume_free(&priv->data); diff --git a/src/tape_drivers/crc32c_crc.c b/src/tape_drivers/crc32c_crc.c index 0029fafa..336f3856 100644 --- a/src/tape_drivers/crc32c_crc.c +++ b/src/tape_drivers/crc32c_crc.c @@ -59,85 +59,68 @@ #define __crc32c_crc_c #include -#include #include +#include #if defined(__SSE42__) && (defined(__i386__) || defined(__x86_64__)) -#include -#include -#ifdef __i386__ -#define CALC_SIZE (4) -#else -#define CALC_SIZE (8) -#endif +# include +# include +# ifdef __i386__ +# define CALC_SIZE (4) +# else +# define CALC_SIZE (8) +# endif #endif #include "libltfs/ltfslogging.h" - static bool is_sse4_2_supported(void) { #if defined(__SSE42__) && (defined(__i386__) || defined(__x86_64__)) unsigned int eax, ebx, ecx, edx; -#ifdef __APPLE__ +# ifdef __APPLE__ __get_cpuid(1, &eax, &ebx, &ecx, &edx); -#else +# else __cpuid(1, eax, ebx, ecx, edx); -#endif - return ecx & 0x00080000; // SSE4.2 +# endif + return ecx & 0x00080000; // SSE4.2 #else return false; #endif } -static const uint32_t crc32c_table[256] = -{ - 0x00000000,0xF26B8303,0xE13B70F7,0x1350F3F4,0xC79A971F,0x35F1141C, - 0x26A1E7E8,0xD4CA64EB,0x8AD958CF,0x78B2DBCC,0x6BE22838,0x9989AB3B, - 0x4D43CFD0,0xBF284CD3,0xAC78BF27,0x5E133C24,0x105EC76F,0xE235446C, - 0xF165B798,0x030E349B,0xD7C45070,0x25AFD373,0x36FF2087,0xC494A384, - 0x9A879FA0,0x68EC1CA3,0x7BBCEF57,0x89D76C54,0x5D1D08BF,0xAF768BBC, - 0xBC267848,0x4E4DFB4B,0x20BD8EDE,0xD2D60DDD,0xC186FE29,0x33ED7D2A, - 0xE72719C1,0x154C9AC2,0x061C6936,0xF477EA35,0xAA64D611,0x580F5512, - 0x4B5FA6E6,0xB93425E5,0x6DFE410E,0x9F95C20D,0x8CC531F9,0x7EAEB2FA, - 0x30E349B1,0xC288CAB2,0xD1D83946,0x23B3BA45,0xF779DEAE,0x05125DAD, - 0x1642AE59,0xE4292D5A,0xBA3A117E,0x4851927D,0x5B016189,0xA96AE28A, - 0x7DA08661,0x8FCB0562,0x9C9BF696,0x6EF07595,0x417B1DBC,0xB3109EBF, - 0xA0406D4B,0x522BEE48,0x86E18AA3,0x748A09A0,0x67DAFA54,0x95B17957, - 0xCBA24573,0x39C9C670,0x2A993584,0xD8F2B687,0x0C38D26C,0xFE53516F, - 0xED03A29B,0x1F682198,0x5125DAD3,0xA34E59D0,0xB01EAA24,0x42752927, - 0x96BF4DCC,0x64D4CECF,0x77843D3B,0x85EFBE38,0xDBFC821C,0x2997011F, - 0x3AC7F2EB,0xC8AC71E8,0x1C661503,0xEE0D9600,0xFD5D65F4,0x0F36E6F7, - 0x61C69362,0x93AD1061,0x80FDE395,0x72966096,0xA65C047D,0x5437877E, - 0x4767748A,0xB50CF789,0xEB1FCBAD,0x197448AE,0x0A24BB5A,0xF84F3859, - 0x2C855CB2,0xDEEEDFB1,0xCDBE2C45,0x3FD5AF46,0x7198540D,0x83F3D70E, - 0x90A324FA,0x62C8A7F9,0xB602C312,0x44694011,0x5739B3E5,0xA55230E6, - 0xFB410CC2,0x092A8FC1,0x1A7A7C35,0xE811FF36,0x3CDB9BDD,0xCEB018DE, - 0xDDE0EB2A,0x2F8B6829,0x82F63B78,0x709DB87B,0x63CD4B8F,0x91A6C88C, - 0x456CAC67,0xB7072F64,0xA457DC90,0x563C5F93,0x082F63B7,0xFA44E0B4, - 0xE9141340,0x1B7F9043,0xCFB5F4A8,0x3DDE77AB,0x2E8E845F,0xDCE5075C, - 0x92A8FC17,0x60C37F14,0x73938CE0,0x81F80FE3,0x55326B08,0xA759E80B, - 0xB4091BFF,0x466298FC,0x1871A4D8,0xEA1A27DB,0xF94AD42F,0x0B21572C, - 0xDFEB33C7,0x2D80B0C4,0x3ED04330,0xCCBBC033,0xA24BB5A6,0x502036A5, - 0x4370C551,0xB11B4652,0x65D122B9,0x97BAA1BA,0x84EA524E,0x7681D14D, - 0x2892ED69,0xDAF96E6A,0xC9A99D9E,0x3BC21E9D,0xEF087A76,0x1D63F975, - 0x0E330A81,0xFC588982,0xB21572C9,0x407EF1CA,0x532E023E,0xA145813D, - 0x758FE5D6,0x87E466D5,0x94B49521,0x66DF1622,0x38CC2A06,0xCAA7A905, - 0xD9F75AF1,0x2B9CD9F2,0xFF56BD19,0x0D3D3E1A,0x1E6DCDEE,0xEC064EED, - 0xC38D26C4,0x31E6A5C7,0x22B65633,0xD0DDD530,0x0417B1DB,0xF67C32D8, - 0xE52CC12C,0x1747422F,0x49547E0B,0xBB3FFD08,0xA86F0EFC,0x5A048DFF, - 0x8ECEE914,0x7CA56A17,0x6FF599E3,0x9D9E1AE0,0xD3D3E1AB,0x21B862A8, - 0x32E8915C,0xC083125F,0x144976B4,0xE622F5B7,0xF5720643,0x07198540, - 0x590AB964,0xAB613A67,0xB831C993,0x4A5A4A90,0x9E902E7B,0x6CFBAD78, - 0x7FAB5E8C,0x8DC0DD8F,0xE330A81A,0x115B2B19,0x020BD8ED,0xF0605BEE, - 0x24AA3F05,0xD6C1BC06,0xC5914FF2,0x37FACCF1,0x69E9F0D5,0x9B8273D6, - 0x88D28022,0x7AB90321,0xAE7367CA,0x5C18E4C9,0x4F48173D,0xBD23943E, - 0xF36E6F75,0x0105EC76,0x12551F82,0xE03E9C81,0x34F4F86A,0xC69F7B69, - 0xD5CF889D,0x27A40B9E,0x79B737BA,0x8BDCB4B9,0x988C474D,0x6AE7C44E, - 0xBE2DA0A5,0x4C4623A6,0x5F16D052,0xAD7D5351 +static const uint32_t crc32c_table[256] = { + 0x00000000, 0xF26B8303, 0xE13B70F7, 0x1350F3F4, 0xC79A971F, 0x35F1141C, 0x26A1E7E8, 0xD4CA64EB, 0x8AD958CF, + 0x78B2DBCC, 0x6BE22838, 0x9989AB3B, 0x4D43CFD0, 0xBF284CD3, 0xAC78BF27, 0x5E133C24, 0x105EC76F, 0xE235446C, + 0xF165B798, 0x030E349B, 0xD7C45070, 0x25AFD373, 0x36FF2087, 0xC494A384, 0x9A879FA0, 0x68EC1CA3, 0x7BBCEF57, + 0x89D76C54, 0x5D1D08BF, 0xAF768BBC, 0xBC267848, 0x4E4DFB4B, 0x20BD8EDE, 0xD2D60DDD, 0xC186FE29, 0x33ED7D2A, + 0xE72719C1, 0x154C9AC2, 0x061C6936, 0xF477EA35, 0xAA64D611, 0x580F5512, 0x4B5FA6E6, 0xB93425E5, 0x6DFE410E, + 0x9F95C20D, 0x8CC531F9, 0x7EAEB2FA, 0x30E349B1, 0xC288CAB2, 0xD1D83946, 0x23B3BA45, 0xF779DEAE, 0x05125DAD, + 0x1642AE59, 0xE4292D5A, 0xBA3A117E, 0x4851927D, 0x5B016189, 0xA96AE28A, 0x7DA08661, 0x8FCB0562, 0x9C9BF696, + 0x6EF07595, 0x417B1DBC, 0xB3109EBF, 0xA0406D4B, 0x522BEE48, 0x86E18AA3, 0x748A09A0, 0x67DAFA54, 0x95B17957, + 0xCBA24573, 0x39C9C670, 0x2A993584, 0xD8F2B687, 0x0C38D26C, 0xFE53516F, 0xED03A29B, 0x1F682198, 0x5125DAD3, + 0xA34E59D0, 0xB01EAA24, 0x42752927, 0x96BF4DCC, 0x64D4CECF, 0x77843D3B, 0x85EFBE38, 0xDBFC821C, 0x2997011F, + 0x3AC7F2EB, 0xC8AC71E8, 0x1C661503, 0xEE0D9600, 0xFD5D65F4, 0x0F36E6F7, 0x61C69362, 0x93AD1061, 0x80FDE395, + 0x72966096, 0xA65C047D, 0x5437877E, 0x4767748A, 0xB50CF789, 0xEB1FCBAD, 0x197448AE, 0x0A24BB5A, 0xF84F3859, + 0x2C855CB2, 0xDEEEDFB1, 0xCDBE2C45, 0x3FD5AF46, 0x7198540D, 0x83F3D70E, 0x90A324FA, 0x62C8A7F9, 0xB602C312, + 0x44694011, 0x5739B3E5, 0xA55230E6, 0xFB410CC2, 0x092A8FC1, 0x1A7A7C35, 0xE811FF36, 0x3CDB9BDD, 0xCEB018DE, + 0xDDE0EB2A, 0x2F8B6829, 0x82F63B78, 0x709DB87B, 0x63CD4B8F, 0x91A6C88C, 0x456CAC67, 0xB7072F64, 0xA457DC90, + 0x563C5F93, 0x082F63B7, 0xFA44E0B4, 0xE9141340, 0x1B7F9043, 0xCFB5F4A8, 0x3DDE77AB, 0x2E8E845F, 0xDCE5075C, + 0x92A8FC17, 0x60C37F14, 0x73938CE0, 0x81F80FE3, 0x55326B08, 0xA759E80B, 0xB4091BFF, 0x466298FC, 0x1871A4D8, + 0xEA1A27DB, 0xF94AD42F, 0x0B21572C, 0xDFEB33C7, 0x2D80B0C4, 0x3ED04330, 0xCCBBC033, 0xA24BB5A6, 0x502036A5, + 0x4370C551, 0xB11B4652, 0x65D122B9, 0x97BAA1BA, 0x84EA524E, 0x7681D14D, 0x2892ED69, 0xDAF96E6A, 0xC9A99D9E, + 0x3BC21E9D, 0xEF087A76, 0x1D63F975, 0x0E330A81, 0xFC588982, 0xB21572C9, 0x407EF1CA, 0x532E023E, 0xA145813D, + 0x758FE5D6, 0x87E466D5, 0x94B49521, 0x66DF1622, 0x38CC2A06, 0xCAA7A905, 0xD9F75AF1, 0x2B9CD9F2, 0xFF56BD19, + 0x0D3D3E1A, 0x1E6DCDEE, 0xEC064EED, 0xC38D26C4, 0x31E6A5C7, 0x22B65633, 0xD0DDD530, 0x0417B1DB, 0xF67C32D8, + 0xE52CC12C, 0x1747422F, 0x49547E0B, 0xBB3FFD08, 0xA86F0EFC, 0x5A048DFF, 0x8ECEE914, 0x7CA56A17, 0x6FF599E3, + 0x9D9E1AE0, 0xD3D3E1AB, 0x21B862A8, 0x32E8915C, 0xC083125F, 0x144976B4, 0xE622F5B7, 0xF5720643, 0x07198540, + 0x590AB964, 0xAB613A67, 0xB831C993, 0x4A5A4A90, 0x9E902E7B, 0x6CFBAD78, 0x7FAB5E8C, 0x8DC0DD8F, 0xE330A81A, + 0x115B2B19, 0x020BD8ED, 0xF0605BEE, 0x24AA3F05, 0xD6C1BC06, 0xC5914FF2, 0x37FACCF1, 0x69E9F0D5, 0x9B8273D6, + 0x88D28022, 0x7AB90321, 0xAE7367CA, 0x5C18E4C9, 0x4F48173D, 0xBD23943E, 0xF36E6F75, 0x0105EC76, 0x12551F82, + 0xE03E9C81, 0x34F4F86A, 0xC69F7B69, 0xD5CF889D, 0x27A40B9E, 0x79B737BA, 0x8BDCB4B9, 0x988C474D, 0x6AE7C44E, + 0xBE2DA0A5, 0x4C4623A6, 0x5F16D052, 0xAD7D5351 }; - static inline void crc32c_calc(const unsigned char in, uint32_t *reg) { *reg = (*reg >> 8) ^ crc32c_table[in ^ (*reg & 0xff)]; @@ -151,16 +134,16 @@ static uint32_t memcpy_crc32c(void *dest, const void *src, size_t n) if (is_sse4_2_supported()) { #if defined(__SSE42__) && (defined(__i386__) || defined(__x86_64__)) -#ifdef __i386__ +# ifdef __i386__ unsigned int reg_native; -#else +# else unsigned long long reg_native; -#endif +# endif memcpy(dest_cur, src_cur, n); i = 0; - for(i = 0; (i < n) && ((size_t)src_cur % CALC_SIZE > 0); i++){ + for (i = 0; (i < n) && ((size_t)src_cur % CALC_SIZE > 0); i++) { /* Calculate CRC */ reg = _mm_crc32_u8(reg, *src_cur); @@ -170,13 +153,13 @@ static uint32_t memcpy_crc32c(void *dest, const void *src, size_t n) reg_native = reg; - for(; i + CALC_SIZE - 1 < n; i+=CALC_SIZE){ + for (; i + CALC_SIZE - 1 < n; i += CALC_SIZE) { /* Calculate CRC */ -#ifdef __i386__ +# ifdef __i386__ reg_native = _mm_crc32_u32(reg_native, *(unsigned int *)src_cur); -#else +# else reg_native = _mm_crc32_u64(reg_native, *(unsigned long long *)src_cur); -#endif +# endif /* Increment pointers */ src_cur += CALC_SIZE; @@ -184,7 +167,7 @@ static uint32_t memcpy_crc32c(void *dest, const void *src, size_t n) reg = reg_native; - for(; i < n; i++){ + for (; i < n; i++) { /* Calculate CRC */ reg = _mm_crc32_u8(reg, *src_cur); @@ -193,7 +176,7 @@ static uint32_t memcpy_crc32c(void *dest, const void *src, size_t n) } #endif } else { - for(i = 0; i < n; i++){ + for (i = 0; i < n; i++) { /* Inject CRC value to the end of the destination buffer */ *dest_cur = *src_cur; @@ -217,13 +200,13 @@ static uint32_t crc32c(void *buf, size_t n) if (is_sse4_2_supported()) { #if defined(__SSE42__) && (defined(__i386__) || defined(__x86_64__)) -#ifdef __i386__ +# ifdef __i386__ unsigned int reg_native; -#else +# else unsigned long long reg_native; -#endif +# endif - for(i = 0; (i < n) && ((size_t)buf_cur % CALC_SIZE > 0); i++){ + for (i = 0; (i < n) && ((size_t)buf_cur % CALC_SIZE > 0); i++) { /* Calculate CRC */ reg = _mm_crc32_u8(reg, *buf_cur); buf_cur++; @@ -231,26 +214,26 @@ static uint32_t crc32c(void *buf, size_t n) reg_native = reg; - for(; i + CALC_SIZE - 1 < n; i+=CALC_SIZE){ + for (; i + CALC_SIZE - 1 < n; i += CALC_SIZE) { /* Calculate CRC */ -#ifdef __i386__ +# ifdef __i386__ reg_native = _mm_crc32_u32(reg_native, *(unsigned int *)buf_cur); -#else +# else reg_native = _mm_crc32_u64(reg_native, *(unsigned long long *)buf_cur); -#endif +# endif buf_cur += CALC_SIZE; } reg = reg_native; - for(; i < n; i++){ + for (; i < n; i++) { /* Calculate CRC */ reg = _mm_crc32_u8(reg, *buf_cur); buf_cur++; } #endif } else { - for(i = 0; i < n; i++){ + for (i = 0; i < n; i++) { /* Calculate CRC */ crc32c_calc(*buf_cur, ®); buf_cur++; diff --git a/src/tape_drivers/freebsd/cam/cam_cmn.c b/src/tape_drivers/freebsd/cam/cam_cmn.c index 6fef2b8e..092fc132 100644 --- a/src/tape_drivers/freebsd/cam/cam_cmn.c +++ b/src/tape_drivers/freebsd/cam/cam_cmn.c @@ -52,19 +52,18 @@ ************************************************************************************* */ - -#include -#include -#include -#include -#include -#include +#include "cam_cmn.h" +#include "libltfs/ltfslogging.h" #include "ltfs_copyright.h" #include "vendor_compat.h" -#include "libltfs/ltfslogging.h" -#include "cam_cmn.h" +#include +#include +#include +#include +#include +#include -volatile char *copyright = LTFS_COPYRIGHT_0"\n"LTFS_COPYRIGHT_1"\n"LTFS_COPYRIGHT_2"\n"; +volatile char *copyright = LTFS_COPYRIGHT_0 "\n" LTFS_COPYRIGHT_1 "\n" LTFS_COPYRIGHT_2 "\n"; extern struct error_table *standard_table; extern struct error_table *vendor_table; @@ -77,11 +76,14 @@ int camtape_sense2rc(void *device, struct scsi_sense_data *sense, int sense_len) int error_code, sense_key, asc, ascq; int rc; - scsi_extract_sense_len(sense, sense_len, &error_code, &sense_key, &asc, &ascq, - /*show_errors*/ 1); - sense_concat = ((sense_key & 0xff) << 16) | - ((asc & 0xff) << 8) | - (ascq & 0xff); + scsi_extract_sense_len(sense, + sense_len, + &error_code, + &sense_key, + &asc, + &ascq, + /*show_errors*/ 1); + sense_concat = ((sense_key & 0xff) << 16) | ((asc & 0xff) << 8) | (ascq & 0xff); /* * If the asc and/or ascq are 0xff (i.e. -1), it will return an error that the * sense code is vendor unique. Those are the first fields (before the sense key) @@ -93,8 +95,7 @@ int camtape_sense2rc(void *device, struct scsi_sense_data *sense, int sense_len) rc = _sense2errcode(sense_concat, vendor_table, NULL, MASK_WITH_SENSE_KEY); } - if (rc == -EDEV_UNKNOWN && ((sense_concat & 0xFF0000) == 0x040000) ) - rc = -EDEV_HARDWARE_ERROR; + if (rc == -EDEV_UNKNOWN && ((sense_concat & 0xFF0000) == 0x040000)) rc = -EDEV_HARDWARE_ERROR; return rc; } @@ -109,56 +110,54 @@ int camtape_ccb2rc(struct camtape_data *softc, union ccb *ccb) int rc; switch (ccb->ccb_h.status & CAM_STATUS_MASK) { - case CAM_REQ_CMP: - rc = DEVICE_GOOD; - break; - case CAM_SCSI_STATUS_ERROR: { - switch (ccb->csio.scsi_status) { - case SCSI_STATUS_OK: - /* This shouldn't happen, but just in case... */ + case CAM_REQ_CMP: rc = DEVICE_GOOD; break; - case SCSI_STATUS_CHECK_COND: - if (ccb->ccb_h.status & CAM_AUTOSNS_VALID) - rc = camtape_sense2rc(softc, &ccb->csio.sense_data, ccb->csio.sense_len - - ccb->csio.sense_resid); - else - rc = -EDEV_TARGET_ERROR; + case CAM_SCSI_STATUS_ERROR: { + switch (ccb->csio.scsi_status) { + case SCSI_STATUS_OK: + /* This shouldn't happen, but just in case... */ + rc = DEVICE_GOOD; + break; + case SCSI_STATUS_CHECK_COND: + if (ccb->ccb_h.status & CAM_AUTOSNS_VALID) + rc = camtape_sense2rc(softc, &ccb->csio.sense_data, ccb->csio.sense_len - ccb->csio.sense_resid); + else + rc = -EDEV_TARGET_ERROR; + break; + case SCSI_STATUS_BUSY: + case SCSI_STATUS_QUEUE_FULL: + rc = -EDEV_DEVICE_BUSY; + break; + case SCSI_STATUS_RESERV_CONFLICT: + default: + rc = -EDEV_TARGET_ERROR; + break; + } + break; + } + case CAM_REQ_INVALID: + rc = -EDEV_INVALID_ARG; + break; + case CAM_SEL_TIMEOUT: + case CAM_DEV_NOT_THERE: + rc = -EDEV_DEVICE_UNOPENABLE; + break; + case CAM_REQ_ABORTED: + rc = -EDEV_ABORTED_COMMAND; break; - case SCSI_STATUS_BUSY: - case SCSI_STATUS_QUEUE_FULL: - rc = -EDEV_DEVICE_BUSY; + case CAM_CMD_TIMEOUT: + rc = -EDEV_TIMEOUT; break; - case SCSI_STATUS_RESERV_CONFLICT: default: - rc = -EDEV_TARGET_ERROR; + rc = -EDEV_HOST_ERROR; break; - } - break; - } - case CAM_REQ_INVALID: - rc = -EDEV_INVALID_ARG; - break; - case CAM_SEL_TIMEOUT: - case CAM_DEV_NOT_THERE: - rc = -EDEV_DEVICE_UNOPENABLE; - break; - case CAM_REQ_ABORTED: - rc = -EDEV_ABORTED_COMMAND; - break; - case CAM_CMD_TIMEOUT: - rc = -EDEV_TIMEOUT; - break; - default: - rc = -EDEV_HOST_ERROR; - break; } return rc; } -int camtape_ioctlrc2err(void *device, int fd, struct scsi_sense_data *sense_data, - int control_cmd, char **msg) +int camtape_ioctlrc2err(void *device, int fd, struct scsi_sense_data *sense_data, int control_cmd, char **msg) { union mterrstat errstat; int rc, rc_sense; @@ -172,12 +171,10 @@ int camtape_ioctlrc2err(void *device, int fd, struct scsi_sense_data *sense_data if (control_cmd == 0) { sense_data_len = sizeof(errstat.scsi_errstat.io_sense); - memcpy(sense_data, &errstat.scsi_errstat.io_sense, - MIN(sizeof(*sense_data), sense_data_len)); + memcpy(sense_data, &errstat.scsi_errstat.io_sense, MIN(sizeof(*sense_data), sense_data_len)); } else { sense_data_len = sizeof(errstat.scsi_errstat.ctl_sense); - memcpy(sense_data, &errstat.scsi_errstat.ctl_sense, - MIN(sizeof(*sense_data), sense_data_len)); + memcpy(sense_data, &errstat.scsi_errstat.ctl_sense, MIN(sizeof(*sense_data), sense_data_len)); } /* @@ -194,8 +191,7 @@ int camtape_ioctlrc2err(void *device, int fd, struct scsi_sense_data *sense_data } else { int error_code, sense_key, asc, ascq; - scsi_extract_sense_len(sense_data, sense_data_len, &error_code, &sense_key, &asc, - &ascq, /*show_errors*/ 1); + scsi_extract_sense_len(sense_data, sense_data_len, &error_code, &sense_key, &asc, &ascq, /*show_errors*/ 1); ltfsmsg(LTFS_DEBUG, 31206D, sense_key, asc, ascq); /* * XXX KDM we should figure out a better way to extract these vendor specific bits. @@ -215,8 +211,7 @@ int camtape_ioctlrc2err(void *device, int fd, struct scsi_sense_data *sense_data } } else { ltfsmsg(LTFS_INFO, 31212I, rc_sense); - if (msg) - *msg = strdup("Cannot get sense information"); + if (msg) *msg = strdup("Cannot get sense information"); rc = -EDEV_CANNOT_GET_SENSE; } @@ -240,8 +235,7 @@ int _camtape_inquiry_page(void *device, unsigned char page, struct tc_inq_page * uint8_t *data_ptr = NULL; int timeout; - if (!inq) - return -EDEV_INVALID_ARG; + if (!inq) return -EDEV_INVALID_ARG; ccb = cam_getccb(softc->cd); if (ccb == NULL) { @@ -249,8 +243,7 @@ int _camtape_inquiry_page(void *device, unsigned char page, struct tc_inq_page * goto bailout; } - memset(&(&ccb->ccb_h)[1], 0, - sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr)); + memset(&(&ccb->ccb_h)[1], 0, sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr)); data_ptr = malloc(sizeof(*inq)); if (data_ptr == NULL) { @@ -268,33 +261,30 @@ int _camtape_inquiry_page(void *device, unsigned char page, struct tc_inq_page * ltfsmsg(LTFS_DEBUG, 31393D, "inquiry", page, softc->drive_serial); scsi_inquiry(&ccb->csio, - /*retries*/ 1, - /*cbfcnp*/ NULL, - /*tag_action*/ MSG_SIMPLE_Q_TAG, - /*inq_buf*/ data_ptr, - /*inq_len*/ sizeof(*inq), - /*evpd*/ 1, - /*page_code*/ page, - /*sense_len*/ SSD_FULL_SIZE, - /*timeout*/ timeout); + /*retries*/ 1, + /*cbfcnp*/ NULL, + /*tag_action*/ MSG_SIMPLE_Q_TAG, + /*inq_buf*/ data_ptr, + /*inq_len*/ sizeof(*inq), + /*evpd*/ 1, + /*page_code*/ page, + /*sense_len*/ SSD_FULL_SIZE, + /*timeout*/ timeout); ccb->ccb_h.flags |= CAM_DEV_QFRZDIS | CAM_PASS_ERR_RECOVER; rc = camtape_send_ccb(softc, ccb, &msg); if (rc != DEVICE_GOOD) { - if(error_handle) - camtape_process_errors(device, rc, msg, "inquiry", true); + if (error_handle) camtape_process_errors(device, rc, msg, "inquiry", true); } else { memcpy(inq->data, data_ptr, sizeof(inq->data)); } bailout: - if (ccb != NULL) - cam_freeccb(ccb); + if (ccb != NULL) cam_freeccb(ccb); - if (data_ptr != NULL) - free(data_ptr); + if (data_ptr != NULL) free(data_ptr); return rc; } @@ -319,7 +309,7 @@ int camtape_inquiry(void *device, struct tc_inq *inq) { int rc = DEVICE_GOOD; struct scsi_inquiry_data *inq_data; - struct camtape_data *softc= (struct camtape_data *)device; + struct camtape_data *softc = (struct camtape_data *)device; int vendor_length; ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_INQUIRY)); @@ -339,11 +329,9 @@ int camtape_inquiry(void *device, struct tc_inq *inq) inq->revision[4] = '\0'; vendor_length = 20; - if (IS_ENTERPRISE(softc->drive_type)) - vendor_length = 18; + if (IS_ENTERPRISE(softc->drive_type)) vendor_length = 18; - strncpy((char *)inq->vendor, (char *)inq_data->vendor_specific0, - vendor_length); + strncpy((char *)inq->vendor, (char *)inq_data->vendor_specific0, vendor_length); inq->vendor[vendor_length] = '\0'; bailout: @@ -359,8 +347,7 @@ int camtape_inquiry(void *device, struct tc_inq *inq) * @param valid_sense_len length of sense data returned, this may be longer than alloc_sense_len * @return 0 for success, negative number for failure */ -int camtape_request_sense(void *device, struct scsi_sense_data *sense, int alloc_sense_len, - int *valid_sense_len) +int camtape_request_sense(void *device, struct scsi_sense_data *sense, int alloc_sense_len, int *valid_sense_len) { int rc = DEVICE_GOOD; char *msg; @@ -377,13 +364,13 @@ int camtape_request_sense(void *device, struct scsi_sense_data *sense, int alloc memset(&sense_data, 0, sizeof(sense_data)); scsi_request_sense(&ccb->csio, - /*retries*/ 0, - /*cbfcnp*/ NULL, - /*data_ptr*/ &sense_data, - /*dxfer_len*/ sizeof(sense_data), - /*tag_action*/ MSG_SIMPLE_Q_TAG, - /*sense_len*/ SSD_FULL_SIZE, - /*timeout*/ 90000); + /*retries*/ 0, + /*cbfcnp*/ NULL, + /*data_ptr*/ &sense_data, + /*dxfer_len*/ sizeof(sense_data), + /*tag_action*/ MSG_SIMPLE_Q_TAG, + /*sense_len*/ SSD_FULL_SIZE, + /*timeout*/ 90000); ccb->ccb_h.flags |= CAM_DEV_QFRZDIS; @@ -394,13 +381,11 @@ int camtape_request_sense(void *device, struct scsi_sense_data *sense, int alloc memcpy(sense, &sense_data, MIN(alloc_sense_len, *valid_sense_len)); } bailout: - if (ccb != NULL) - cam_freeccb(ccb); + if (ccb != NULL) cam_freeccb(ccb); return rc; } - /** * Test Unit Ready * @param device a pointer to the camtape backend @@ -417,8 +402,7 @@ int camtape_test_unit_ready(void *device) union ccb *ccb = NULL; ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_TUR)); - ltfsmsg(LTFS_DEBUG3, 31392D, "test unit ready", - softc->drive_serial); + ltfsmsg(LTFS_DEBUG3, 31392D, "test unit ready", softc->drive_serial); timeout = camtape_get_timeout(softc->timeouts, TEST_UNIT_READY); if (timeout < 0) { @@ -432,15 +416,14 @@ int camtape_test_unit_ready(void *device) goto bailout; } - memset(&(&ccb->ccb_h)[1], 0, - sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr)); + memset(&(&ccb->ccb_h)[1], 0, sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr)); scsi_test_unit_ready(&ccb->csio, - /*retries*/ 1, - /*cbfcnp*/ NULL, - /*tag_action*/ MSG_SIMPLE_Q_TAG, - /*sense_len*/ SSD_FULL_SIZE, - /*timeout*/ timeout * 1000); + /*retries*/ 1, + /*cbfcnp*/ NULL, + /*tag_action*/ MSG_SIMPLE_Q_TAG, + /*sense_len*/ SSD_FULL_SIZE, + /*timeout*/ timeout * 1000); /* * XXX KDM enabling error recovery here, so the retry count will work. @@ -452,31 +435,29 @@ int camtape_test_unit_ready(void *device) if (rc != DEVICE_GOOD) { switch (rc) { - case -EDEV_NEED_INITIALIZE: - case -EDEV_CONFIGURE_CHANGED: - case -EDEV_OPERATION_IN_PROGRESS: - print_message = false; - /* Fall through */ - case -EDEV_NO_MEDIUM: - case -EDEV_BECOMING_READY: - case -EDEV_MEDIUM_MAY_BE_CHANGED: - case -EDEV_NOT_READY: - case -EDEV_NOT_REPORTABLE: - case -EDEV_MEDIUM_REMOVAL_REQ: - case -EDEV_CLEANING_IN_PROGRESS: - take_dump = false; - break; - default: - break; + case -EDEV_NEED_INITIALIZE: + case -EDEV_CONFIGURE_CHANGED: + case -EDEV_OPERATION_IN_PROGRESS: + print_message = false; + /* Fall through */ + case -EDEV_NO_MEDIUM: + case -EDEV_BECOMING_READY: + case -EDEV_MEDIUM_MAY_BE_CHANGED: + case -EDEV_NOT_READY: + case -EDEV_NOT_REPORTABLE: + case -EDEV_MEDIUM_REMOVAL_REQ: + case -EDEV_CLEANING_IN_PROGRESS: + take_dump = false; + break; + default: + break; } - if (print_message) - camtape_process_errors(device, rc, msg, "test unit ready", take_dump); + if (print_message) camtape_process_errors(device, rc, msg, "test unit ready", take_dump); } bailout: - if (ccb != NULL) - cam_freeccb(ccb); + if (ccb != NULL) cam_freeccb(ccb); ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_TUR)); return rc; @@ -532,8 +513,7 @@ int camtape_release_unit(void *device) * @param type * @return 0 on success or negative value on error */ -int camtape_readbuffer(struct camtape_data *softc, int id, unsigned char *buf, size_t offset, - size_t len, int type) +int camtape_readbuffer(struct camtape_data *softc, int id, unsigned char *buf, size_t offset, size_t len, int type) { char *msg; int rc = DEVICE_GOOD; @@ -549,8 +529,7 @@ int camtape_readbuffer(struct camtape_data *softc, int id, unsigned char *buf, s } /* cam_getccb cleans up the header, caller has to zero the payload */ - memset(&(&ccb->ccb_h)[1], 0, - sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr)); + memset(&(&ccb->ccb_h)[1], 0, sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr)); timeout = camtape_get_timeout(softc->timeouts, READ_BUFFER); if (timeout < 0) { @@ -559,27 +538,25 @@ int camtape_readbuffer(struct camtape_data *softc, int id, unsigned char *buf, s } scsi_read_buffer(&ccb->csio, - /*retries*/ 1, - /*cbfcnp*/ NULL, - /*tag_action*/ MSG_SIMPLE_Q_TAG, - /*mode*/ type, - /*buffer_id*/ id, - /*offset*/ offset, - /*data_ptr*/ buf, - /*allocation_length*/ len, - /*sense_len*/ SSD_FULL_SIZE, - /*timeout*/ timeout); + /*retries*/ 1, + /*cbfcnp*/ NULL, + /*tag_action*/ MSG_SIMPLE_Q_TAG, + /*mode*/ type, + /*buffer_id*/ id, + /*offset*/ offset, + /*data_ptr*/ buf, + /*allocation_length*/ len, + /*sense_len*/ SSD_FULL_SIZE, + /*timeout*/ timeout); ccb->ccb_h.flags |= CAM_DEV_QFRZDIS | CAM_PASS_ERR_RECOVER; rc = camtape_send_ccb(softc, ccb, &msg); - if (rc != DEVICE_GOOD) - camtape_process_errors(softc, rc, msg, "read buffer", false); + if (rc != DEVICE_GOOD) camtape_process_errors(softc, rc, msg, "read buffer", false); bailout: - if (ccb != NULL) - cam_freeccb(ccb); + if (ccb != NULL) cam_freeccb(ccb); return rc; } @@ -590,7 +567,7 @@ int camtape_readbuffer(struct camtape_data *softc, int id, unsigned char *buf, s * @param fname a file name of dump * @return 0 on success or negative value on error */ -#define DUMP_HEADER_SIZE (4) +#define DUMP_HEADER_SIZE (4) #define DUMP_TRANSFER_SIZE (512 * KB) int camtape_getdump_drive(void *device, const char *fname) @@ -624,7 +601,7 @@ int camtape_getdump_drive(void *device, const char *fname) /* Get buffer capacity */ camtape_readbuffer(device, buf_id, cap_buf, 0, sizeof(cap_buf), 0x03); - data_length = (cap_buf[1] << 16) + (cap_buf[2] << 8) + (int) cap_buf[3]; + data_length = (cap_buf[1] << 16) + (cap_buf[2] << 8) + (int)cap_buf[3]; /* Open dump file for write only */ dumpfd = open(fname, O_WRONLY | O_CREAT | O_TRUNC, 0666); @@ -638,8 +615,7 @@ int camtape_getdump_drive(void *device, const char *fname) /* get the total number of transfers */ num_transfers = data_length / transfer_size; excess_transfer = data_length % transfer_size; - if (excess_transfer) - num_transfers += 1; + if (excess_transfer) num_transfers += 1; /* Total dump data length is %lld. Total number of transfers is %d. */ ltfsmsg(LTFS_DEBUG, 31280D, data_length); @@ -689,7 +665,7 @@ int camtape_getdump_drive(void *device, const char *fname) /* update offset and num_transfers, free buffer */ buf_offset += transfer_size; num_transfers -= 1; - } /* end of while(num_transfers) */ + } /* end of while(num_transfers) */ free(dump_buf); close(dumpfd); @@ -722,11 +698,11 @@ int camtape_forcedump_drive(struct camtape_data *softc) memset(buf, 0, sizeof(buf)); /* Prepare payload */ - buf[0] = 0x80; /* page code */ + buf[0] = 0x80; /* page code */ buf[2] = 0x00; - buf[3] = 0x04; /* page length */ + buf[3] = 0x04; /* page length */ buf[4] = 0x01; - buf[5] = 0x60; /* diagnostic id */ + buf[5] = 0x60; /* diagnostic id */ timeout = camtape_get_timeout(softc->timeouts, SEND_DIAGNOSTIC); if (timeout < 0) { @@ -734,29 +710,27 @@ int camtape_forcedump_drive(struct camtape_data *softc) goto bailout; } scsi_send_diagnostic(&ccb->csio, - /*retries*/ 1, - /*cbfcnp*/ NULL, - /*tag_action*/ MSG_SIMPLE_Q_TAG, - /*unit_offline*/ 0, - /*device_offline*/ 0, - /*self_test*/ 0, - /*page_format*/ 1, - /*self_test_code*/ SSD_SELF_TEST_CODE_NONE, - /*data_ptr*/ buf, - /*param_list_length*/ sizeof(buf), - /*sense_len*/ SSD_FULL_SIZE, - /*timeout*/ timeout); + /*retries*/ 1, + /*cbfcnp*/ NULL, + /*tag_action*/ MSG_SIMPLE_Q_TAG, + /*unit_offline*/ 0, + /*device_offline*/ 0, + /*self_test*/ 0, + /*page_format*/ 1, + /*self_test_code*/ SSD_SELF_TEST_CODE_NONE, + /*data_ptr*/ buf, + /*param_list_length*/ sizeof(buf), + /*sense_len*/ SSD_FULL_SIZE, + /*timeout*/ timeout); ccb->ccb_h.flags |= CAM_DEV_QFRZDIS | CAM_PASS_ERR_RECOVER; rc = camtape_send_ccb(softc, ccb, &msg); - if (rc != DEVICE_GOOD) - camtape_process_errors(softc, rc, msg, "force dump", false); + if (rc != DEVICE_GOOD) camtape_process_errors(softc, rc, msg, "force dump", false); bailout: - if (ccb != NULL) - cam_freeccb(ccb); + if (ccb != NULL) cam_freeccb(ccb); return rc; } @@ -775,15 +749,21 @@ int camtape_takedump_drive(void *device, bool nonforced_dump) struct camtape_data *softc = (struct camtape_data *)device; unsigned char *serial = softc->drive_serial; - if (softc->vendor != VENDOR_IBM) - return 0; + if (softc->vendor != VENDOR_IBM) return 0; ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_TAKEDUMPDRV)); /* Make base filename */ time(&now); tm_now = localtime(&now); - sprintf(fname_base, "/tmp/ltfs_%s_%d_%02d%02d_%02d%02d%02d", serial, tm_now->tm_year + 1900, - tm_now->tm_mon + 1, tm_now->tm_mday, tm_now->tm_hour, tm_now->tm_min, tm_now->tm_sec); + sprintf(fname_base, + "/tmp/ltfs_%s_%d_%02d%02d_%02d%02d%02d", + serial, + tm_now->tm_year + 1900, + tm_now->tm_mon + 1, + tm_now->tm_mday, + tm_now->tm_hour, + tm_now->tm_min, + tm_now->tm_sec); if (nonforced_dump) { strcpy(fname, fname_base); @@ -813,14 +793,14 @@ int camtape_takedump_drive(void *device, bool nonforced_dump) */ int camtape_get_serialnumber(void *device, char **result) { - struct camtape_data *softc = (struct camtape_data *) device; + struct camtape_data *softc = (struct camtape_data *)device; CHECK_ARG_NULL(device, -LTFS_NULL_ARG); CHECK_ARG_NULL(result, -LTFS_NULL_ARG); ltfs_profiler_add_entry(softc->profiler, NULL, CHANGER_REQ_ENTER(REQ_TC_GETSER)); - *result = strdup((const char *) softc->drive_serial); - if (! *result) { + *result = strdup((const char *)softc->drive_serial); + if (!*result) { ltfsmsg(LTFS_ERR, 10001E, "camtape_get_serialnumber: result"); ltfs_profiler_add_entry(softc->profiler, NULL, CHANGER_REQ_EXIT(REQ_TC_GETSER)); return -EDEV_NO_MEMORY; @@ -839,14 +819,14 @@ int camtape_get_serialnumber(void *device, char **result) */ int camtape_get_info(void *device, struct tc_drive_info *info) { - struct camtape_data *softc = (struct camtape_data *) device; + struct camtape_data *softc = (struct camtape_data *)device; snprintf(info->name, TAPE_DEVNAME_LEN_MAX + 1, "%s", softc->devname); snprintf(info->serial_number, TAPE_SERIAL_LEN_MAX + 1, "%s", softc->drive_serial); - info->host = 0; + info->host = 0; info->channel = 0; - info->target = 0; - info->lun = -1; + info->target = 0; + info->lun = -1; return 0; } @@ -867,13 +847,10 @@ int camtape_set_profiler(void *device, char *work_dir, bool enable) struct camtape_data *softc = (struct camtape_data *)device; if (enable) { - if (softc->profiler) - return 0; - if (!work_dir) - return -LTFS_BAD_ARG; + if (softc->profiler) return 0; + if (!work_dir) return -LTFS_BAD_ARG; - rc = asprintf(&path, "%s/%s%s%s", work_dir, DRIVER_PROFILER_BASE, - softc->drive_serial, PROFILER_EXTENSION); + rc = asprintf(&path, "%s/%s%s%s", work_dir, DRIVER_PROFILER_BASE, softc->drive_serial, PROFILER_EXTENSION); if (rc < 0) { ltfsmsg(LTFS_ERR, 10001E, __FILE__); return -LTFS_NO_MEMORY; @@ -883,11 +860,11 @@ int camtape_set_profiler(void *device, char *work_dir, bool enable) free(path); - if (! p) + if (!p) rc = -LTFS_FILE_ERR; else { get_timer_info(&timerinfo); - fwrite((void*)&timerinfo, sizeof(timerinfo), 1, p); + fwrite((void *)&timerinfo, sizeof(timerinfo), 1, p); softc->profiler = p; rc = 0; } diff --git a/src/tape_drivers/freebsd/cam/cam_tc.c b/src/tape_drivers/freebsd/cam/cam_tc.c index 377af2ed..9831f9f9 100644 --- a/src/tape_drivers/freebsd/cam/cam_tc.c +++ b/src/tape_drivers/freebsd/cam/cam_tc.c @@ -54,24 +54,24 @@ #define __camtape_tc_c -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include #include +#include +#include +#include +#include #include #include +#include +#include +#include +#include +#include +#include +#include -#include "libltfs/ltfs_fuse_version.h" #include "libltfs/arch/time_internal.h" +#include "libltfs/ltfs_fuse_version.h" #include #include "libltfs/ltfslogging.h" @@ -81,8 +81,8 @@ #define TAPE_BACKEND /* Use static vriable definition in tape_drivers.h */ #include "cam_cmn.h" -#include "reed_solomon_crc.h" #include "crc32c_crc.h" +#include "reed_solomon_crc.h" /* * Prototypes for opening the SA (Sequential Access) and pass (Pass Through) @@ -90,7 +90,7 @@ */ int open_sa_pass(struct camtape_data *softc, const char *saDeviceName); -int open_sa_device(struct camtape_data *softc, const char* saDeviceName); +int open_sa_device(struct camtape_data *softc, const char *saDeviceName); void close_sa_device(struct camtape_data *softc); void close_cd_pass_device(struct camtape_data *softc); @@ -108,14 +108,14 @@ const char *camtape_default_changer_device = "/dev/ch0"; /* * Definitions */ -#define LOG_PAGE_HEADER_SIZE (4) +#define LOG_PAGE_HEADER_SIZE (4) #define LOG_PAGE_PARAMSIZE_OFFSET (3) -#define LOG_PAGE_PARAM_OFFSET (4) +#define LOG_PAGE_PARAM_OFFSET (4) #define LINUX_MAX_BLOCK_SIZE (1 * MB) -#define LTFS_CRC_LEN 4 +#define LTFS_CRC_LEN 4 #ifndef MIN -#define MIN(a, b) ((a) < (b) ? (a) : (b)) +# define MIN(a, b) ((a) < (b) ? (a) : (b)) #endif #define CRC32C_CRC (0x02) @@ -132,9 +132,13 @@ struct error_table *vendor_table; */ int camtape_readpos(void *device, struct tc_position *pos); int camtape_rewind(void *device, struct tc_position *pos); -int camtape_modesense(void *device, const uint8_t page, const TC_MP_PC_TYPE pc, const uint8_t subpage, - unsigned char *buf, const size_t size); -int camtape_set_key(void *device, const unsigned char * const keyalias, const unsigned char * const key); +int camtape_modesense(void *device, + const uint8_t page, + const TC_MP_PC_TYPE pc, + const uint8_t subpage, + unsigned char *buf, + const size_t size); +int camtape_set_key(void *device, const unsigned char *const keyalias, const unsigned char *const key); int camtape_set_lbp(void *device, bool enable); /* @@ -150,8 +154,8 @@ int camtape_set_lbp(void *device, bool enable); * @param bufsize size of the buffer * @return 0 on success or negative value on error */ -int parse_logPage(const unsigned char *logdata, const uint16_t param, int *param_size, - unsigned char *buf, const size_t bufsize) +int parse_logPage( + const unsigned char *logdata, const uint16_t param, int *param_size, unsigned char *buf, const size_t bufsize) { uint16_t page_len, param_code, param_len; long i; @@ -161,15 +165,14 @@ int parse_logPage(const unsigned char *logdata, const uint16_t param, int *param while (i < page_len) { param_code = ltfs_betou16(logdata + i); - param_len = (uint16_t) logdata[i + LOG_PAGE_PARAMSIZE_OFFSET]; + param_len = (uint16_t)logdata[i + LOG_PAGE_PARAMSIZE_OFFSET]; if (param_code == param) { *param_size = param_len; if (bufsize < param_len) { ltfsmsg(LTFS_INFO, 31218I, bufsize, i + LOG_PAGE_PARAM_OFFSET); memcpy(buf, &logdata[i + LOG_PAGE_PARAM_OFFSET], bufsize); return -2; - } - else { + } else { memcpy(buf, &logdata[i + LOG_PAGE_PARAM_OFFSET], param_len); return 0; } @@ -185,15 +188,12 @@ int parse_logPage(const unsigned char *logdata, const uint16_t param, int *param * @param devname device name of the LTO tape driver * @return a pointer to the camtape backend on success or NULL on error */ -#define CAMTAPE_OPT(templ,offset,value) { templ, offsetof(struct camtape_global_data, offset), value } +#define CAMTAPE_OPT(templ, offset, value) { templ, offsetof(struct camtape_global_data, offset), value } static struct fuse_opt camtape_global_opts[] = { - CAMTAPE_OPT("autodump", disable_auto_dump, 0), - CAMTAPE_OPT("noautodump", disable_auto_dump, 1), - CAMTAPE_OPT("scsi_lbprotect=%s", str_crc_checking, 0), - CAMTAPE_OPT("strict_drive", strict_drive, 1), - CAMTAPE_OPT("nostrict_drive", strict_drive, 0), - FUSE_OPT_END + CAMTAPE_OPT("autodump", disable_auto_dump, 0), CAMTAPE_OPT("noautodump", disable_auto_dump, 1), + CAMTAPE_OPT("scsi_lbprotect=%s", str_crc_checking, 0), CAMTAPE_OPT("strict_drive", strict_drive, 1), + CAMTAPE_OPT("nostrict_drive", strict_drive, 0), FUSE_OPT_END }; int null_parser(void *device, const char *arg, int key, struct fuse_args *outargs) @@ -203,7 +203,7 @@ int null_parser(void *device, const char *arg, int key, struct fuse_args *outarg int camtape_parse_opts(void *device, void *opt_args) { - struct fuse_args *args = (struct fuse_args *) opt_args; + struct fuse_args *args = (struct fuse_args *)opt_args; struct camtape_data *softc = (struct camtape_data *)device; int ret; @@ -260,7 +260,7 @@ int camtape_open(const char *devname, void **handle) ltfsmsg(LTFS_INFO, 31223I, devname); softc = calloc(1, sizeof(struct camtape_data)); - if (! softc) { + if (!softc) { ltfsmsg(LTFS_ERR, 10001E, "camtape_open: device private data"); return -EDEV_NO_MEMORY; } @@ -271,21 +271,19 @@ int camtape_open(const char *devname, void **handle) return ret; } - cam_strvis((uint8_t *)product, (uint8_t *)softc->cd->inq_data.product, - sizeof(softc->cd->inq_data.product), sizeof(product)); - cam_strvis((uint8_t *)vendor, (uint8_t *)softc->cd->inq_data.vendor, - sizeof(softc->cd->inq_data.vendor), sizeof(vendor)); + cam_strvis( + (uint8_t *)product, (uint8_t *)softc->cd->inq_data.product, sizeof(softc->cd->inq_data.product), sizeof(product)); + cam_strvis( + (uint8_t *)vendor, (uint8_t *)softc->cd->inq_data.vendor, sizeof(softc->cd->inq_data.vendor), sizeof(vendor)); ltfsmsg(LTFS_INFO, 31228I, product); ltfsmsg(LTFS_INFO, 31229I, vendor); /* Check the drive is supportable */ softc->vendor = get_vendor_id(vendor); struct supported_device **cur = get_supported_devs(softc->vendor); - while(*cur) { - if ((! strncmp((char*)softc->cd->inq_data.vendor, (*cur)->vendor_id, - strlen((*cur)->vendor_id)) ) && - (! strncmp((char*)softc->cd->inq_data.product, (*cur)->product_id, - strlen((*cur)->product_id)) ) ) { + while (*cur) { + if ((!strncmp((char *)softc->cd->inq_data.vendor, (*cur)->vendor_id, strlen((*cur)->vendor_id))) && + (!strncmp((char *)softc->cd->inq_data.product, (*cur)->product_id, strlen((*cur)->product_id)))) { drive_type = (*cur)->drive_type; break; } @@ -298,8 +296,7 @@ int camtape_open(const char *devname, void **handle) /* Setup vendor specific parameters */ init_error_table(softc->vendor, &standard_table, &vendor_table); init_timeout(softc->vendor, &softc->timeouts, softc->drive_type); - if (!softc->timeouts) - ibm_tape_init_timeout(&softc->timeouts, softc->drive_type); + if (!softc->timeouts) ibm_tape_init_timeout(&softc->timeouts, softc->drive_type); } else { ltfsmsg(LTFS_INFO, 31230I, softc->cd->inq_data.product); close(softc->fd_sa); @@ -313,7 +310,7 @@ int camtape_open(const char *devname, void **handle) memcpy(softc->drive_serial, softc->cd->serial_num, softc->cd->serial_num_len); ltfsmsg(LTFS_INFO, 31232I, softc->cd->inq_data.revision); - if (! drive_has_supported_fw(softc->vendor, softc->drive_type, (uint8_t *)softc->cd->inq_data.revision)) { + if (!drive_has_supported_fw(softc->vendor, softc->drive_type, (uint8_t *)softc->cd->inq_data.revision)) { ltfsmsg(LTFS_INFO, 31230I, "firmware", softc->cd->inq_data.revision); close(softc->fd_sa); close_cd_pass_device(softc); @@ -326,12 +323,12 @@ int camtape_open(const char *devname, void **handle) softc->loaded = false; /* Assume tape is not loaded until a successful load call. */ - softc->clear_by_pc = false; + softc->clear_by_pc = false; softc->force_writeperm = DEFAULT_WRITEPERM; - softc->force_readperm = DEFAULT_READPERM; + softc->force_readperm = DEFAULT_READPERM; softc->force_errortype = DEFAULT_ERRORTYPE; - *handle = (void *) softc; + *handle = (void *)softc; return DEVICE_GOOD; } @@ -354,12 +351,11 @@ int camtape_reopen(const char *name, void *vstate) */ int camtape_close(void *device) { - struct camtape_data *softc = (struct camtape_data *) device; + struct camtape_data *softc = (struct camtape_data *)device; struct tc_position pos; ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_CLOSE)); - if (softc->loaded) - camtape_rewind(device, &pos); + if (softc->loaded) camtape_rewind(device, &pos); camtape_set_lbp(device, false); @@ -387,7 +383,7 @@ int camtape_close(void *device) */ int camtape_close_raw(void *device) { - struct camtape_data *softc = (struct camtape_data *) device; + struct camtape_data *softc = (struct camtape_data *)device; ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_CLOSERAW)); close(softc->fd_sa); @@ -422,7 +418,7 @@ int _mt_command(void *device, int cmd, char *cmd_name, int param, char **msg) { struct camtape_data *softc = device; int fd = softc->fd_sa; - struct mtop mt = {.mt_op = cmd,.mt_count = param }; + struct mtop mt = { .mt_op = cmd, .mt_count = param }; struct scsi_sense_data sense_data; int rc; @@ -436,8 +432,7 @@ int _mt_command(void *device, int cmd, char *cmd_name, int param, char **msg) goto start; } ltfsmsg(LTFS_INFO, 31208I, cmd_name, cmd, rc, errno, softc->drive_serial); - } - else { + } else { *msg = NULL; rc = DEVICE_GOOD; } @@ -454,15 +449,14 @@ int _mt_command(void *device, int cmd, char *cmd_name, int param, char **msg) * @param unusual_size a flag specified unusual size or not * @return read length on success or a negative value on error */ -int camtape_read(void *device, char *buf, size_t count, struct tc_position *pos, - const bool unusual_size) +int camtape_read(void *device, char *buf, size_t count, struct tc_position *pos, const bool unusual_size) { ssize_t len = -1, read_len; int rc; bool silion = unusual_size; char *msg = NULL; - struct camtape_data *softc = (struct camtape_data *) device; - int fd = softc->fd_sa; + struct camtape_data *softc = (struct camtape_data *)device; + int fd = softc->fd_sa; size_t datacount = count; /* @@ -493,83 +487,74 @@ int camtape_read(void *device, char *buf, size_t count, struct tc_position *pos, uint8_t stream_bits; /* XXX KDM need to pass back valid length of sense data */ - rc = camtape_ioctlrc2err(softc, fd , &sense_data, /*control_cmd*/ 0, &msg); + rc = camtape_ioctlrc2err(softc, fd, &sense_data, /*control_cmd*/ 0, &msg); - if (scsi_get_stream_info(&sense_data, sizeof(sense_data), &softc->cd->inq_data, - &stream_bits) != 0) { + if (scsi_get_stream_info(&sense_data, sizeof(sense_data), &softc->cd->inq_data, &stream_bits) != 0) { stream_bits = 0; } switch (rc) { - case -EDEV_NO_SENSE: - if (stream_bits & SSD_FILEMARK) { - /* Filemark Detected */ - ltfsmsg(LTFS_DEBUG, 31236D); - rc = DEVICE_GOOD; - pos->block++; - pos->filemarks++; - len = 0; - } - else if (stream_bits & SSD_ILI) { - /* Illegal Length */ - int64_t diff_len; - uint64_t unsigned_diff_len; - - /* XXX KDM need to get the real length of the sense data */ - if (scsi_get_sense_info(&sense_data, sizeof(sense_data), SSD_DESC_INFO, - &unsigned_diff_len, &diff_len) != 0) { - - /* XXX KDM what do we do if there is no info field? */ - diff_len = 0; - } + case -EDEV_NO_SENSE: + if (stream_bits & SSD_FILEMARK) { + /* Filemark Detected */ + ltfsmsg(LTFS_DEBUG, 31236D); + rc = DEVICE_GOOD; + pos->block++; + pos->filemarks++; + len = 0; + } else if (stream_bits & SSD_ILI) { + /* Illegal Length */ + int64_t diff_len; + uint64_t unsigned_diff_len; + + /* XXX KDM need to get the real length of the sense data */ + if (scsi_get_sense_info(&sense_data, sizeof(sense_data), SSD_DESC_INFO, &unsigned_diff_len, &diff_len) != 0) { + /* XXX KDM what do we do if there is no info field? */ + diff_len = 0; + } - if (diff_len < 0) { - ltfsmsg(LTFS_INFO, 31237I, diff_len, count - diff_len); // "Detect overrun condition" + if (diff_len < 0) { + ltfsmsg(LTFS_INFO, 31237I, diff_len, count - diff_len); // "Detect overrun condition" + rc = -EDEV_OVERRUN; + } else { + ltfsmsg(LTFS_DEBUG, 31238D, diff_len, count - diff_len); // "Detect underrun condition" + len = count - diff_len; + rc = DEVICE_GOOD; + pos->block++; + } + } else if (errno == EOVERFLOW) { + ltfsmsg(LTFS_INFO, 31237I, count - read_len, read_len); // "Detect overrun condition" rc = -EDEV_OVERRUN; - } - else { - ltfsmsg(LTFS_DEBUG, 31238D, diff_len, count - diff_len); // "Detect underrun condition" - len = count - diff_len; + } else if ((size_t)read_len < count) { + ltfsmsg(LTFS_DEBUG, 31238D, count - read_len, read_len); // "Detect underrun condition" + len = read_len; rc = DEVICE_GOOD; pos->block++; } - } - else if (errno == EOVERFLOW) { - ltfsmsg(LTFS_INFO, 31237I, count - read_len, read_len); // "Detect overrun condition" - rc = -EDEV_OVERRUN; - } - else if ((size_t)read_len < count) { - ltfsmsg(LTFS_DEBUG, 31238D, count - read_len, read_len); // "Detect underrun condition" - len = read_len; + break; + case -EDEV_FILEMARK_DETECTED: + ltfsmsg(LTFS_DEBUG, 31236D); rc = DEVICE_GOOD; pos->block++; - } - break; - case -EDEV_FILEMARK_DETECTED: - ltfsmsg(LTFS_DEBUG, 31236D); - rc = DEVICE_GOOD; - pos->block++; - pos->filemarks++; - len = 0; - break; + pos->filemarks++; + len = 0; + break; } if (rc != DEVICE_GOOD) { - if ((rc != -EDEV_CRYPTO_ERROR && rc != -EDEV_KEY_REQUIRED) || ((struct camtape_data *) device)->is_data_key_set) { - ltfsmsg(LTFS_INFO, 31208I, "READ", count, rc, errno, ((struct camtape_data *) device)->drive_serial); + if ((rc != -EDEV_CRYPTO_ERROR && rc != -EDEV_KEY_REQUIRED) || ((struct camtape_data *)device)->is_data_key_set) { + ltfsmsg(LTFS_INFO, 31208I, "READ", count, rc, errno, ((struct camtape_data *)device)->drive_serial); camtape_process_errors(device, rc, msg, "read", true); } len = rc; } - } - else { + } else { len = silion ? read_len : (ssize_t)datacount; pos->block++; } - if(global_data.crc_checking && len > 4) { - if (softc->f_crc_check) - len = softc->f_crc_check(buf, len - 4); + if (global_data.crc_checking && len > 4) { + if (softc->f_crc_check) len = softc->f_crc_check(buf, len - 4); if (len < 0) { ltfsmsg(LTFS_ERR, 31239E); len = -EDEV_LBP_READ_ERROR; @@ -599,9 +584,9 @@ int camtape_write(void *device, const char *buf, size_t count, struct tc_positio struct scsi_sense_data sense_data; int write_retry_done = 0; - struct camtape_data *softc = (struct camtape_data *) device; - int fd = softc->fd_sa; - size_t datacount = count; + struct camtape_data *softc = (struct camtape_data *)device; + int fd = softc->fd_sa; + size_t datacount = count; /* * TODO: Check count is smaller than max of SSIZE_MAX @@ -610,18 +595,18 @@ int camtape_write(void *device, const char *buf, size_t count, struct tc_positio */ ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_WRITE)); - ltfsmsg(LTFS_DEBUG, 31395D, "write", count, ((struct camtape_data *) device)->drive_serial); + ltfsmsg(LTFS_DEBUG, 31395D, "write", count, ((struct camtape_data *)device)->drive_serial); - if ( softc->force_writeperm ) { + if (softc->force_writeperm) { softc->write_counter++; - if ( softc->write_counter > softc->force_writeperm ) { + if (softc->write_counter > softc->force_writeperm) { ltfsmsg(LTFS_INFO, 31234I, "write"); ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_WRITE)); if (softc->force_errortype) return -EDEV_NO_SENSE; else return -EDEV_WRITE_PERM; - } else if ( softc->write_counter > (softc->force_writeperm - THRESHOLD_FORCE_WRITE_NO_WRITE)) { + } else if (softc->write_counter > (softc->force_writeperm - THRESHOLD_FORCE_WRITE_NO_WRITE)) { ltfsmsg(LTFS_INFO, 31235I); pos->block++; ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_WRITE)); @@ -630,9 +615,8 @@ int camtape_write(void *device, const char *buf, size_t count, struct tc_positio } /* Invoke _ioctl to Write */ - if(global_data.crc_checking) { - if (softc->f_crc_enc) - softc->f_crc_enc((void *)buf, count); + if (global_data.crc_checking) { + if (softc->f_crc_enc) softc->f_crc_enc((void *)buf, count); datacount = count + 4; } @@ -658,7 +642,7 @@ int camtape_write(void *device, const char *buf, size_t count, struct tc_positio * the write path, we do a blocking allocation that will sleep until it has memory. * So, the only failures we'll see here are failures that come from the tape drive. */ - rc = camtape_ioctlrc2err(softc, fd , &sense_data, /*control_cmd*/ 0, &msg); + rc = camtape_ioctlrc2err(softc, fd, &sense_data, /*control_cmd*/ 0, &msg); } else { /* * Short write. This means that we hit early warning. Grab the position to see @@ -670,14 +654,12 @@ int camtape_write(void *device, const char *buf, size_t count, struct tc_positio write_retry_done = 1; goto retry_write; } else - rc = camtape_ioctlrc2err(softc, fd , &sense_data, /*control_cmd*/ 0, &msg); + rc = camtape_ioctlrc2err(softc, fd, &sense_data, /*control_cmd*/ 0, &msg); } - if (rc != DEVICE_GOOD) - camtape_process_errors(device, rc, msg, "write", true); + if (rc != DEVICE_GOOD) camtape_process_errors(device, rc, msg, "write", true); - if (rc == -EDEV_LBP_WRITE_ERROR) - ltfsmsg(LTFS_ERR, 31247E); + if (rc == -EDEV_LBP_WRITE_ERROR) ltfsmsg(LTFS_ERR, 31247E); } else { rc = DEVICE_GOOD; pos->block++; @@ -702,7 +684,7 @@ int camtape_writefm(void *device, size_t count, struct tc_position *pos, bool im char *msg = NULL; size_t written_count; tape_filemarks_t cur_fm = pos->filemarks; - struct camtape_data *softc = (struct camtape_data *) device; + struct camtape_data *softc = (struct camtape_data *)device; ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_WRITEFM)); ltfsmsg(LTFS_DEBUG, 31396D, "writefm", count, softc->drive_serial); @@ -714,35 +696,35 @@ int camtape_writefm(void *device, size_t count, struct tc_position *pos, bool im if (rc != DEVICE_GOOD) { switch (rc) { - case -EDEV_EARLY_WARNING: - ltfsmsg(LTFS_WARN, 31245W, "writefm"); - rc = DEVICE_GOOD; - pos->early_warning = true; - break; - case -EDEV_PROG_EARLY_WARNING: - ltfsmsg(LTFS_WARN, 31246W, "writefm"); - rc = DEVICE_GOOD; - pos->programmable_early_warning = true; - break; - case -EDEV_CONFIGURE_CHANGED: - written_count = pos->filemarks - cur_fm; - if (count != written_count) { - /* need to write fm again */ - count = count - written_count; - cur_fm = pos->filemarks; - goto start_wfm; - } - break; - default: - if (pos->early_warning) { + case -EDEV_EARLY_WARNING: ltfsmsg(LTFS_WARN, 31245W, "writefm"); rc = DEVICE_GOOD; - } - if (pos->programmable_early_warning) { + pos->early_warning = true; + break; + case -EDEV_PROG_EARLY_WARNING: ltfsmsg(LTFS_WARN, 31246W, "writefm"); rc = DEVICE_GOOD; - } - break; + pos->programmable_early_warning = true; + break; + case -EDEV_CONFIGURE_CHANGED: + written_count = pos->filemarks - cur_fm; + if (count != written_count) { + /* need to write fm again */ + count = count - written_count; + cur_fm = pos->filemarks; + goto start_wfm; + } + break; + default: + if (pos->early_warning) { + ltfsmsg(LTFS_WARN, 31245W, "writefm"); + rc = DEVICE_GOOD; + } + if (pos->programmable_early_warning) { + ltfsmsg(LTFS_WARN, 31246W, "writefm"); + rc = DEVICE_GOOD; + } + break; } if (rc != DEVICE_GOOD) { @@ -785,9 +767,9 @@ int camtape_rewind(void *device, struct tc_position *pos) camtape_process_errors(device, rc, msg, "rewind", true); } - softc->clear_by_pc = false; + softc->clear_by_pc = false; softc->force_writeperm = DEFAULT_WRITEPERM; - softc->force_readperm = DEFAULT_READPERM; + softc->force_readperm = DEFAULT_READPERM; softc->write_counter = 0; softc->read_counter = 0; @@ -811,8 +793,12 @@ int camtape_locate(void *device, struct tc_position dest, struct tc_position *po struct mtlocate mtl; ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_LOCATE)); - ltfsmsg(LTFS_DEBUG, 31397D, "locate", (unsigned long long)dest.partition, - (unsigned long long)dest.block, softc->drive_serial); + ltfsmsg(LTFS_DEBUG, + 31397D, + "locate", + (unsigned long long)dest.partition, + (unsigned long long)dest.block, + softc->drive_serial); memset(&mtl, 0, sizeof(mtl)); @@ -824,11 +810,11 @@ int camtape_locate(void *device, struct tc_position dest, struct tc_position *po mtl.flags |= MT_LOCATE_FLAG_CHANGE_PART; if (softc->clear_by_pc) { - softc->clear_by_pc = false; + softc->clear_by_pc = false; softc->force_writeperm = DEFAULT_WRITEPERM; - softc->force_readperm = DEFAULT_READPERM; + softc->force_readperm = DEFAULT_READPERM; softc->write_counter = 0; - softc->read_counter = 0; + softc->read_counter = 0; } } @@ -845,8 +831,7 @@ int camtape_locate(void *device, struct tc_position dest, struct tc_position *po rc = DEVICE_GOOD; } - if (rc != DEVICE_GOOD) - camtape_process_errors(device, rc, msg, "locate", true); + if (rc != DEVICE_GOOD) camtape_process_errors(device, rc, msg, "locate", true); } camtape_readpos(device, pos); @@ -878,23 +863,19 @@ int camtape_space(void *device, size_t count, TC_SPACE_TYPE type, struct tc_posi count = 0; break; case TC_SPACE_FM_F: - ltfsmsg(LTFS_DEBUG, 31394D, "space forward file marks", (unsigned long long)count, - softc->drive_serial); + ltfsmsg(LTFS_DEBUG, 31394D, "space forward file marks", (unsigned long long)count, softc->drive_serial); cmd = MTFSF; break; case TC_SPACE_FM_B: - ltfsmsg(LTFS_DEBUG, 31394D, "space back file marks", (unsigned long long)count, - softc->drive_serial); + ltfsmsg(LTFS_DEBUG, 31394D, "space back file marks", (unsigned long long)count, softc->drive_serial); cmd = MTBSF; break; case TC_SPACE_F: - ltfsmsg(LTFS_DEBUG, 31394D, "space forward records", (unsigned long long)count, - softc->drive_serial); + ltfsmsg(LTFS_DEBUG, 31394D, "space forward records", (unsigned long long)count, softc->drive_serial); cmd = MTFSR; break; case TC_SPACE_B: - ltfsmsg(LTFS_DEBUG, 31394D, "space back records", (unsigned long long)count, - softc->drive_serial); + ltfsmsg(LTFS_DEBUG, 31394D, "space back records", (unsigned long long)count, softc->drive_serial); cmd = MTBSR; break; default: @@ -936,8 +917,7 @@ int camtape_long_erase(void *device) goto bailout; } - memset(&(&ccb->ccb_h)[1], 0, - sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr)); + memset(&(&ccb->ccb_h)[1], 0, sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr)); timeout = camtape_get_timeout(softc->timeouts, ERASE); if (timeout < 0) { @@ -946,24 +926,22 @@ int camtape_long_erase(void *device) } scsi_erase(&ccb->csio, - /*retries*/ 1, - /*cbfcnp*/ NULL, - /*tag_action*/ MSG_SIMPLE_Q_TAG, - /*immediate*/ 1, - /*long_erase*/ 1, - /*sense_len*/ SSD_FULL_SIZE, - /*timeout*/ timeout); + /*retries*/ 1, + /*cbfcnp*/ NULL, + /*tag_action*/ MSG_SIMPLE_Q_TAG, + /*immediate*/ 1, + /*long_erase*/ 1, + /*sense_len*/ SSD_FULL_SIZE, + /*timeout*/ timeout); ccb->ccb_h.flags |= CAM_DEV_QFRZDIS | CAM_PASS_ERR_RECOVER; rc = camtape_send_ccb(softc, ccb, &msg); - if (rc != DEVICE_GOOD) - camtape_process_errors(softc, rc, msg, "long erase", true); + if (rc != DEVICE_GOOD) camtape_process_errors(softc, rc, msg, "long erase", true); bailout: - if (ccb != NULL) - cam_freeccb(ccb); + if (ccb != NULL) cam_freeccb(ccb); return rc; } @@ -995,8 +973,7 @@ int camtape_erase(void *device, struct tc_position *pos, bool long_erase) rc = camtape_long_erase(device); } - if (rc != -EDEV_OPERATION_IN_PROGRESS) - goto bailout; + if (rc != -EDEV_OPERATION_IN_PROGRESS) goto bailout; while (true) { struct scsi_sense_data sense_data; @@ -1004,12 +981,11 @@ int camtape_erase(void *device, struct tc_position *pos, bool long_erase) memset(&sense_data, 0, sizeof(sense_data)); rc = camtape_request_sense(device, &sense_data, sizeof(sense_data), &fill_len); - if (rc != -EDEV_OPERATION_IN_PROGRESS) - goto bailout; + if (rc != -EDEV_OPERATION_IN_PROGRESS) goto bailout; if (IS_ENTERPRISE(softc->drive_type)) { get_current_timespec(&ts_now); - ltfsmsg(LTFS_INFO, 31251I, (ts_now.tv_sec - ts_start.tv_sec)/60); + ltfsmsg(LTFS_INFO, 31251I, (ts_now.tv_sec - ts_start.tv_sec) / 60); } else { struct scsi_sense_sks_progress prog; @@ -1020,7 +996,7 @@ int camtape_erase(void *device, struct tc_position *pos, bool long_erase) progress = scsi_2btoul(prog.progress); - ltfsmsg(LTFS_INFO, 31252I, progress*100/0xFFFF); + ltfsmsg(LTFS_INFO, 31252I, progress * 100 / 0xFFFF); } else { rc = 0; goto bailout; @@ -1057,42 +1033,38 @@ int _camtape_load_unload(void *device, bool load, struct tc_position *pos) int rc; char *msg = NULL; bool take_dump = true; - struct camtape_data *softc = ((struct camtape_data *) device); + struct camtape_data *softc = ((struct camtape_data *)device); if (load) { rc = _mt_command(device, MTLOAD, "LOAD", 0, &msg); - } - else { + } else { rc = _mt_command(device, MTOFFL, "UNLOAD", 0, &msg); } if (rc != DEVICE_GOOD) { switch (rc) { - case -EDEV_LOAD_UNLOAD_ERROR: - if (softc->loadfailed) { + case -EDEV_LOAD_UNLOAD_ERROR: + if (softc->loadfailed) { + take_dump = false; + } else { + softc->loadfailed = true; + } + break; + case -EDEV_NO_MEDIUM: + case -EDEV_BECOMING_READY: + case -EDEV_MEDIUM_MAY_BE_CHANGED: take_dump = false; - } - else { - softc->loadfailed = true; - } - break; - case -EDEV_NO_MEDIUM: - case -EDEV_BECOMING_READY: - case -EDEV_MEDIUM_MAY_BE_CHANGED: - take_dump = false; - break; - default: - break; + break; + default: + break; } camtape_readpos(device, pos); camtape_process_errors(device, rc, msg, "load unload", take_dump); - } - else { + } else { if (load) { camtape_readpos(device, pos); softc->tape_alert = 0; - } - else { + } else { pos->partition = 0; pos->block = 0; softc->tape_alert = 0; @@ -1128,9 +1100,9 @@ int camtape_load(void *device, struct tc_position *pos) softc->loaded = true; softc->is_worm = false; - softc->clear_by_pc = false; + softc->clear_by_pc = false; softc->force_writeperm = DEFAULT_WRITEPERM; - softc->force_readperm = DEFAULT_READPERM; + softc->force_readperm = DEFAULT_READPERM; softc->write_counter = 0; softc->read_counter = 0; softc->cart_type = buf[2]; @@ -1138,8 +1110,7 @@ int camtape_load(void *device, struct tc_position *pos) if (softc->vendor == VENDOR_HP) { softc->cart_type = assume_cart_type(softc->density_code); - if (buf[2] == 0x01) - softc->is_worm = true; + if (buf[2] == 0x01) softc->is_worm = true; } else { softc->cart_type = buf[2]; } @@ -1151,8 +1122,7 @@ int camtape_load(void *device, struct tc_position *pos) } rc = is_supported_tape(softc->cart_type, softc->density_code, &(softc->is_worm)); - if(rc == -LTFS_UNSUPPORTED_MEDIUM) - ltfsmsg(LTFS_INFO, 31255I, softc->cart_type, softc->density_code); + if (rc == -LTFS_UNSUPPORTED_MEDIUM) ltfsmsg(LTFS_INFO, 31255I, softc->cart_type, softc->density_code); ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_LOAD)); @@ -1175,7 +1145,7 @@ int camtape_unload(void *device, struct tc_position *pos) rc = _camtape_load_unload(device, false, pos); - softc->clear_by_pc = false; + softc->clear_by_pc = false; softc->force_writeperm = DEFAULT_WRITEPERM; softc->force_readperm = DEFAULT_READPERM; softc->write_counter = 0; @@ -1225,14 +1195,14 @@ static int camtape_get_next_block_to_xfer(void *device, struct tc_position *pos) * XXX KDM should we do any retries here? Doing retries potentially hides sense data. */ scsi_read_position_10(&ccb->csio, - /*retries*/ 0, - /*cbfcnp*/ NULL, - /*tag_action*/ MSG_SIMPLE_Q_TAG, - /*service_action*/ SA_RPOS_EXTENDED_FORM, - /*data_ptr*/ (uint8_t *)&ext_data, - /*length*/ sizeof(ext_data), - /*sense_len*/ SSD_FULL_SIZE, - /*timeout*/ timeout); + /*retries*/ 0, + /*cbfcnp*/ NULL, + /*tag_action*/ MSG_SIMPLE_Q_TAG, + /*service_action*/ SA_RPOS_EXTENDED_FORM, + /*data_ptr*/ (uint8_t *)&ext_data, + /*length*/ sizeof(ext_data), + /*sense_len*/ SSD_FULL_SIZE, + /*timeout*/ timeout); ccb->ccb_h.flags |= CAM_DEV_QFRZDIS; rc = camtape_send_ccb(softc, ccb, &msg); @@ -1242,21 +1212,18 @@ static int camtape_get_next_block_to_xfer(void *device, struct tc_position *pos) else { pos->partition = ext_data.partition; pos->block = scsi_8btou64(ext_data.last_object) - ltfsmsg(LTFS_DEBUG, 30398D, "next-block-to-xfer", - (unsigned long long) pos->block, 0, 0, softc->drive_serial); + ltfsmsg(LTFS_DEBUG, 30398D, "next-block-to-xfer", (unsigned long long)pos->block, 0, 0, softc->drive_serial); } bailout: - if (ccb != NULL) - cam_freeccb(ccb); + if (ccb != NULL) cam_freeccb(ccb); ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_READPOS)); return rc; } -static int camtape_load_attr(struct mt_status_data *mtinfo, xmlDocPtr doc, xmlAttr *attr, - int level, char **msg) +static int camtape_load_attr(struct mt_status_data *mtinfo, xmlDocPtr doc, xmlAttr *attr, int level, char **msg) { struct mt_status_entry *entry; xmlAttr *xattr = NULL; @@ -1307,8 +1274,7 @@ static int camtape_load_attr(struct mt_status_data *mtinfo, xmlDocPtr doc, xmlAt STAILQ_INSERT_TAIL(&entry->nv_list, nv, links); need_free = 0; } - if (need_free != 0) - xmlFree(str); + if (need_free != 0) xmlFree(str); } } bailout: @@ -1316,8 +1282,7 @@ static int camtape_load_attr(struct mt_status_data *mtinfo, xmlDocPtr doc, xmlAt return (retval); } -static int camtape_load_elements(struct mt_status_data *mtinfo, xmlDocPtr doc, xmlNode *node, - int level, char **msg) +static int camtape_load_elements(struct mt_status_data *mtinfo, xmlDocPtr doc, xmlNode *node, int level, char **msg) { struct mt_status_entry *entry; xmlNode *xnode = NULL; @@ -1328,8 +1293,7 @@ static int camtape_load_elements(struct mt_status_data *mtinfo, xmlDocPtr doc, x if (xnode->type == XML_ELEMENT_NODE) { mtinfo->level++; - if ((u_int)mtinfo->level > sizeof(mtinfo->cur_entry) / - sizeof(mtinfo->cur_entry[0])) { + if ((u_int)mtinfo->level > sizeof(mtinfo->cur_entry) / sizeof(mtinfo->cur_entry[0])) { *msg = strdup("Too many nesting levels"); retval = -EDEV_INVALID_ARG; goto bailout; @@ -1349,42 +1313,36 @@ static int camtape_load_elements(struct mt_status_data *mtinfo, xmlDocPtr doc, x if (mtinfo->cur_entry[mtinfo->level - 1] == NULL) { STAILQ_INSERT_TAIL(&mtinfo->entries, entry, links); } else { - STAILQ_INSERT_TAIL( - &mtinfo->cur_entry[mtinfo->level - 1]->child_entries, - entry, links); + STAILQ_INSERT_TAIL(&mtinfo->cur_entry[mtinfo->level - 1]->child_entries, entry, links); entry->parent = mtinfo->cur_entry[mtinfo->level - 1]; } } else if (xnode->type == XML_TEXT_NODE) { char *str; - str = (char *)xmlNodeListGetString(doc, xnode, 1); - if (xmlIsBlankNode(xnode) != 0) - continue; + if (xmlIsBlankNode(xnode) != 0) continue; entry = mtinfo->cur_entry[mtinfo->level]; entry->value = str; switch (entry->var_type) { - case MT_TYPE_INT: - entry->value_signed = strtoll(str, NULL, 0); - break; - case MT_TYPE_UINT: - entry->value_unsigned = strtoull(str, NULL, 0); - break; - default: - break; + case MT_TYPE_INT: + entry->value_signed = strtoll(str, NULL, 0); + break; + case MT_TYPE_UINT: + entry->value_unsigned = strtoull(str, NULL, 0); + break; + default: + break; } } if (xnode->properties != NULL) { retval = camtape_load_attr(mtinfo, doc, xnode->properties, level, msg); - if (retval != DEVICE_GOOD) - goto bailout; + if (retval != DEVICE_GOOD) goto bailout; } retval = camtape_load_elements(mtinfo, doc, xnode->children, level + 1, msg); - if (retval != DEVICE_GOOD) - goto bailout; + if (retval != DEVICE_GOOD) goto bailout; if (created_element != 0) { mtinfo->cur_entry[mtinfo->level] = NULL; @@ -1396,8 +1354,7 @@ static int camtape_load_elements(struct mt_status_data *mtinfo, xmlDocPtr doc, x return (retval); } -int camtape_get_mtinfo(struct camtape_data *softc, struct mt_status_data *mtinfo, int params, - char **msg) +int camtape_get_mtinfo(struct camtape_data *softc, struct mt_status_data *mtinfo, int params, char **msg) { struct mtextget extget; int alloc_size = 32768; @@ -1422,8 +1379,7 @@ int camtape_get_mtinfo(struct camtape_data *softc, struct mt_status_data *mtinfo if (ioctl(softc->fd_sa, (params != 0) ? MTIOCPARAMGET : MTIOCEXTGET, &extget) == -1) { char tmpstr[512]; - snprintf(tmpstr, sizeof(tmpstr), "ioctl error from sa(4) driver: %s", - strerror(errno)); + snprintf(tmpstr, sizeof(tmpstr), "ioctl error from sa(4) driver: %s", strerror(errno)); *msg = strdup(tmpstr); retval = -errno; goto bailout; @@ -1442,8 +1398,7 @@ int camtape_get_mtinfo(struct camtape_data *softc, struct mt_status_data *mtinfo char tmpstr[512]; retval = -EDEV_DRIVER_ERROR; - snprintf(tmpstr, sizeof(tmpstr), "Error getting status data from sa(4) driver: status = %d", - extget.status); + snprintf(tmpstr, sizeof(tmpstr), "Error getting status data from sa(4) driver: status = %d", extget.status); *msg = strdup(tmpstr); goto bailout; } @@ -1478,12 +1433,9 @@ int camtape_get_mtinfo(struct camtape_data *softc, struct mt_status_data *mtinfo bailout: - if (xml_str != NULL) - free(xml_str); - if (doc != NULL) - xmlFreeDoc(doc); - if (ctx != NULL) - xmlFreeParserCtxt(ctx); + if (xml_str != NULL) free(xml_str); + if (doc != NULL) xmlFreeDoc(doc); + if (ctx != NULL) xmlFreeParserCtxt(ctx); return (retval); } @@ -1495,37 +1447,39 @@ int camtape_free_mtinfo(struct camtape_data *softc, struct mt_status_data *mtinf return (DEVICE_GOOD); } -typedef enum { - MT_REPORTED_FILENO = 0, - MT_REPORTED_BLKNO = 1, - MT_PARTITION = 2, - MT_BOP = 3, - MT_EOP = 4, - MT_BPEW = 5 +typedef enum +{ + MT_REPORTED_FILENO = 0, + MT_REPORTED_BLKNO = 1, + MT_PARTITION = 2, + MT_BOP = 3, + MT_EOP = 4, + MT_BPEW = 5 } camtape_status_index; -struct camtape_status_item { +struct camtape_status_item +{ const char *name; struct mt_status_entry *entry; -} req_status_items[] = { - {"reported_fileno", NULL }, - {"reported_blkno", NULL }, - {"partition", NULL }, - {"bop", NULL }, - {"eop", NULL }, - {"bpew", NULL} -}; -#define CT_NUM_STATUS_ITEMS (sizeof(req_status_items)/sizeof(req_status_items[0])) - -int camtape_getstatus(struct camtape_data *softc, struct mt_status_data *mtinfo, - struct camtape_status_item *status_items, int num_status_items, char **msg) +} req_status_items[] = { { "reported_fileno", NULL }, + { "reported_blkno", NULL }, + { "partition", NULL }, + { "bop", NULL }, + { "eop", NULL }, + { "bpew", NULL } }; +#define CT_NUM_STATUS_ITEMS (sizeof(req_status_items) / sizeof(req_status_items[0])) + +int camtape_getstatus(struct camtape_data *softc, + struct mt_status_data *mtinfo, + struct camtape_status_item *status_items, + int num_status_items, + char **msg) { int retval = DEVICE_GOOD; int i; retval = camtape_get_mtinfo(softc, mtinfo, /*params*/ 0, msg); - if (retval != DEVICE_GOOD) - goto bailout; + if (retval != DEVICE_GOOD) goto bailout; for (i = 0; i < num_status_items; i++) { char *name; @@ -1585,9 +1539,13 @@ int camtape_readpos(void *device, struct tc_position *pos) pos->block = status_items[MT_REPORTED_BLKNO].entry->value_signed; pos->filemarks = status_items[MT_REPORTED_FILENO].entry->value_signed; - ltfsmsg(LTFS_DEBUG, 31398D, "readpos", (unsigned long long)pos->partition, - (unsigned long long)pos->block, (unsigned long long)pos->filemarks, - softc->drive_serial); + ltfsmsg(LTFS_DEBUG, + 31398D, + "readpos", + (unsigned long long)pos->partition, + (unsigned long long)pos->block, + (unsigned long long)pos->filemarks, + softc->drive_serial); bailout: camtape_free_mtinfo(softc, &mtinfo); @@ -1606,7 +1564,8 @@ int camtape_readpos(void *device, struct tc_position *pos) * @param vol_mam_uuid Volume UUID, unused by libtlfs (HPE extension) * @return 0 on success or a negative value on error */ -int camtape_format(void *device, TC_FORMAT_TYPE format, const char *vol_name, const char *barcode_name, const char *vol_mam_uuid) +int camtape_format( + void *device, TC_FORMAT_TYPE format, const char *vol_name, const char *barcode_name, const char *vol_mam_uuid) { int rc, aux_rc; char *msg = NULL; @@ -1618,7 +1577,7 @@ int camtape_format(void *device, TC_FORMAT_TYPE format, const char *vol_name, co ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_FORMAT)); ltfsmsg(LTFS_DEBUG, 31392D, "format", softc->drive_serial); - if ((unsigned char) format >= (unsigned char) TC_FORMAT_MAX) { + if ((unsigned char)format >= (unsigned char)TC_FORMAT_MAX) { ltfsmsg(LTFS_INFO, 31256I, format); ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_FORMAT)); return -1; @@ -1630,8 +1589,7 @@ int camtape_format(void *device, TC_FORMAT_TYPE format, const char *vol_name, co goto bailout; } - memset(&(&ccb->ccb_h)[1], 0, - sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr)); + memset(&(&ccb->ccb_h)[1], 0, sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr)); timeout = camtape_get_timeout(softc->timeouts, FORMAT_MEDIUM); if (timeout < 0) { @@ -1640,15 +1598,15 @@ int camtape_format(void *device, TC_FORMAT_TYPE format, const char *vol_name, co } scsi_format_medium(&ccb->csio, - /*retries*/ 1, - /*cbfcnp*/ NULL, - /*tag_action*/ MSG_SIMPLE_Q_TAG, - /*byte1*/ 0, - /*byte2*/ format, - /*data_ptr*/ NULL, - /*dxfer_len*/ 0, - /*sense_len*/ SSD_FULL_SIZE, - /*timeout*/ timeout); + /*retries*/ 1, + /*cbfcnp*/ NULL, + /*tag_action*/ MSG_SIMPLE_Q_TAG, + /*byte1*/ 0, + /*byte2*/ format, + /*data_ptr*/ NULL, + /*dxfer_len*/ 0, + /*sense_len*/ SSD_FULL_SIZE, + /*timeout*/ timeout); ccb->ccb_h.flags |= CAM_DEV_QFRZDIS | CAM_PASS_ERR_RECOVER; @@ -1665,8 +1623,7 @@ int camtape_format(void *device, TC_FORMAT_TYPE format, const char *vol_name, co softc->density_code = buf[8]; } bailout: - if (ccb != NULL) - cam_freeccb(ccb); + if (ccb != NULL) cam_freeccb(ccb); ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_FORMAT)); return rc; @@ -1682,8 +1639,7 @@ int camtape_format(void *device, TC_FORMAT_TYPE format, const char *vol_name, co */ #define MAX_UINT16 (0x0000FFFF) -int camtape_logsense(void *device, const uint8_t page, const uint8_t subpage, - unsigned char *buf, const size_t size) +int camtape_logsense(void *device, const uint8_t page, const uint8_t subpage, unsigned char *buf, const size_t size) { int rc = DEVICE_GOOD; char *msg = NULL; @@ -1697,12 +1653,10 @@ int camtape_logsense(void *device, const uint8_t page, const uint8_t subpage, unsigned char *inner_buf = NULL; ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_LOGSENSE)); - ltfsmsg(LTFS_DEBUG3, 31397D, "logsense", - (unsigned long long)page, (unsigned long long)subpage, softc->drive_serial); + ltfsmsg(LTFS_DEBUG3, 31397D, "logsense", (unsigned long long)page, (unsigned long long)subpage, softc->drive_serial); inner_buf = calloc(1, MAXLP_SIZE); /* Assume max length of LP is 0xFFFF */ - if (!inner_buf) - return -LTFS_NO_MEMORY; + if (!inner_buf) return -LTFS_NO_MEMORY; ccb = cam_getccb(softc->cd); if (ccb == NULL) { @@ -1710,8 +1664,7 @@ int camtape_logsense(void *device, const uint8_t page, const uint8_t subpage, goto bailout; } - memset(&(&ccb->ccb_h)[1], 0, - sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr)); + memset(&(&ccb->ccb_h)[1], 0, sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr)); timeout = camtape_get_timeout(softc->timeouts, LOG_SENSE); if (timeout < 0) { @@ -1720,18 +1673,18 @@ int camtape_logsense(void *device, const uint8_t page, const uint8_t subpage, } scsi_log_sense(&ccb->csio, - /*retries*/ 1, - /*cbfcnp*/ NULL, - /*tag_action*/ MSG_SIMPLE_Q_TAG, - /*page_code*/ page, - /*page*/ SLS_PAGE_CTRL_CUMULATIVE, - /*save_pages*/ 0, - /*ppc*/ 0, - /*paramptr*/ 0, - /*param_buf*/ inner_buf, - /*param_len*/ MAXLP_SIZE, - /*sense_len*/ SSD_FULL_SIZE, - /*timeout*/ timeout); + /*retries*/ 1, + /*cbfcnp*/ NULL, + /*tag_action*/ MSG_SIMPLE_Q_TAG, + /*page_code*/ page, + /*page*/ SLS_PAGE_CTRL_CUMULATIVE, + /*save_pages*/ 0, + /*ppc*/ 0, + /*paramptr*/ 0, + /*param_buf*/ inner_buf, + /*param_len*/ MAXLP_SIZE, + /*sense_len*/ SSD_FULL_SIZE, + /*timeout*/ timeout); /* * XXX KDM need to add subpage to the log sense fill function. */ @@ -1756,11 +1709,9 @@ int camtape_logsense(void *device, const uint8_t page, const uint8_t subpage, } bailout: - if (inner_buf != NULL) - free(inner_buf); + if (inner_buf != NULL) free(inner_buf); - if (ccb != NULL) - cam_freeccb(ccb); + if (ccb != NULL) cam_freeccb(ccb); ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_LOGSENSE)); @@ -1790,9 +1741,8 @@ int camtape_remaining_capacity(void *device, struct tc_remaining_cap *cap) return rc; } - for(i = TAPECAP_REMAIN_0; i < TAPECAP_SIZE; i++) { - if (parse_logPage(logdata, (uint16_t) i, ¶m_size, buf, sizeof(buf)) - || param_size != sizeof(uint32_t)) { + for (i = TAPECAP_REMAIN_0; i < TAPECAP_SIZE; i++) { + if (parse_logPage(logdata, (uint16_t)i, ¶m_size, buf, sizeof(buf)) || param_size != sizeof(uint32_t)) { ltfsmsg(LTFS_INFO, 31258I); ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_REMAINCAP)); return -EDEV_NO_MEMORY; @@ -1801,27 +1751,26 @@ int camtape_remaining_capacity(void *device, struct tc_remaining_cap *cap) logcap = ltfs_betou32(buf); switch (i) { - case TAPECAP_REMAIN_0: - cap->remaining_p0 = logcap; - break; - case TAPECAP_REMAIN_1: - cap->remaining_p1 = logcap; - break; - case TAPECAP_MAX_0: - cap->max_p0 = logcap; - break; - case TAPECAP_MAX_1: - cap->max_p1 = logcap; - break; - default: - ltfsmsg(LTFS_INFO, 31259I, i); - ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_REMAINCAP)); - return -EDEV_INVALID_ARG; - break; + case TAPECAP_REMAIN_0: + cap->remaining_p0 = logcap; + break; + case TAPECAP_REMAIN_1: + cap->remaining_p1 = logcap; + break; + case TAPECAP_MAX_0: + cap->max_p0 = logcap; + break; + case TAPECAP_MAX_1: + cap->max_p1 = logcap; + break; + default: + ltfsmsg(LTFS_INFO, 31259I, i); + ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_REMAINCAP)); + return -EDEV_INVALID_ARG; + break; } } - } - else { + } else { /* Issue LogPage 0x17 */ rc = camtape_logsense(device, LOG_VOLUMESTATS, (uint8_t)0, logdata, LOGSENSEPAGE); if (rc < 0) { @@ -1869,15 +1818,22 @@ int camtape_remaining_capacity(void *device, struct tc_remaining_cap *cap) cap->remaining_p1 = (cap->remaining_p1 * 1000 * 1000) >> 20; } - ltfsmsg(LTFS_DEBUG3, 31397D, "capacity part0", (unsigned long long)cap->remaining_p0, - (unsigned long long)cap->max_p0, softc->drive_serial); - ltfsmsg(LTFS_DEBUG3, 31397D, "capacity part1", (unsigned long long)cap->remaining_p1, - (unsigned long long)cap->max_p1, softc->drive_serial); + ltfsmsg(LTFS_DEBUG3, + 31397D, + "capacity part0", + (unsigned long long)cap->remaining_p0, + (unsigned long long)cap->max_p0, + softc->drive_serial); + ltfsmsg(LTFS_DEBUG3, + 31397D, + "capacity part1", + (unsigned long long)cap->remaining_p1, + (unsigned long long)cap->max_p1, + softc->drive_serial); return 0; } - /** * Get mode data * @param device a pointer to the camtape backend @@ -1887,8 +1843,12 @@ int camtape_remaining_capacity(void *device, struct tc_remaining_cap *cap) * @param size length of buf * @return 0 on success or a negative value on error */ -int camtape_modesense(void *device, const uint8_t page, const TC_MP_PC_TYPE pc, const uint8_t subpage, - unsigned char *buf, const size_t size) +int camtape_modesense(void *device, + const uint8_t page, + const TC_MP_PC_TYPE pc, + const uint8_t subpage, + unsigned char *buf, + const size_t size) { int rc; char *msg = NULL; @@ -1905,8 +1865,7 @@ int camtape_modesense(void *device, const uint8_t page, const TC_MP_PC_TYPE pc, goto bailout; } - memset(&(&ccb->ccb_h)[1], 0, - sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr)); + memset(&(&ccb->ccb_h)[1], 0, sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr)); timeout = camtape_get_timeout(softc->timeouts, MODE_SENSE_10); if (timeout < 0) { @@ -1915,17 +1874,17 @@ int camtape_modesense(void *device, const uint8_t page, const TC_MP_PC_TYPE pc, } scsi_mode_sense_len(&ccb->csio, - /*retries*/ 1, - /*cbfcnp*/ NULL, - /*tag_action*/ MSG_SIMPLE_Q_TAG, - /*dbd*/ 0, - /*page_code*/ pc, - /*page*/ page, - /*param_buf*/ buf, - /*param_len*/ MIN(MAX_UINT16, size), - /*minimum_cmd_size*/ 10, - /*sense_len*/ SSD_FULL_SIZE, - /*timeout*/ timeout); + /*retries*/ 1, + /*cbfcnp*/ NULL, + /*tag_action*/ MSG_SIMPLE_Q_TAG, + /*dbd*/ 0, + /*page_code*/ pc, + /*page*/ page, + /*param_buf*/ buf, + /*param_len*/ MIN(MAX_UINT16, size), + /*minimum_cmd_size*/ 10, + /*sense_len*/ SSD_FULL_SIZE, + /*timeout*/ timeout); /* * XXX KDM need a version of scsi_mode_sense() that allows setting the subpage. The offset * is the same in the 6 and 10 byte versions, so we can just set the same byte here. @@ -1936,12 +1895,10 @@ int camtape_modesense(void *device, const uint8_t page, const TC_MP_PC_TYPE pc, rc = camtape_send_ccb(softc, ccb, &msg); - if (rc != DEVICE_GOOD) - camtape_process_errors(softc, rc, msg, "modesense", true); + if (rc != DEVICE_GOOD) camtape_process_errors(softc, rc, msg, "modesense", true); bailout: - if (ccb != NULL) - cam_freeccb(ccb); + if (ccb != NULL) cam_freeccb(ccb); ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_MODESENSE)); return rc; @@ -1971,8 +1928,7 @@ int camtape_modeselect(void *device, unsigned char *buf, const size_t size) goto bailout; } - memset(&(&ccb->ccb_h)[1], 0, - sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr)); + memset(&(&ccb->ccb_h)[1], 0, sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr)); timeout = camtape_get_timeout(softc->timeouts, MODE_SELECT_10); if (timeout < 0) { @@ -1981,31 +1937,28 @@ int camtape_modeselect(void *device, unsigned char *buf, const size_t size) } scsi_mode_select_len(&ccb->csio, - /*retries*/ 1, - /*cbfcnp*/ NULL, - /*tag_action*/ MSG_SIMPLE_Q_TAG, - /*scsi_page_fmt*/ 0, - /*save_pages*/ 0, - /*param_buf*/ buf, - /*param_len*/ size, - /*minimum_cmd_len*/ 10, - /*sense_len*/ SSD_FULL_SIZE, - /*timeout*/ timeout); + /*retries*/ 1, + /*cbfcnp*/ NULL, + /*tag_action*/ MSG_SIMPLE_Q_TAG, + /*scsi_page_fmt*/ 0, + /*save_pages*/ 0, + /*param_buf*/ buf, + /*param_len*/ size, + /*minimum_cmd_len*/ 10, + /*sense_len*/ SSD_FULL_SIZE, + /*timeout*/ timeout); ccb->ccb_h.flags |= CAM_DEV_QFRZDIS | CAM_PASS_ERR_RECOVER; rc = camtape_send_ccb(softc, ccb, &msg); if (rc != DEVICE_GOOD) { - if (rc == -EDEV_MODE_PARAMETER_ROUNDED) - rc = DEVICE_GOOD; + if (rc == -EDEV_MODE_PARAMETER_ROUNDED) rc = DEVICE_GOOD; - if (rc != DEVICE_GOOD) - camtape_process_errors(device, rc, msg, "modeselect", true); + if (rc != DEVICE_GOOD) camtape_process_errors(device, rc, msg, "modeselect", true); } bailout: - if (ccb != NULL) - cam_freeccb(ccb); + if (ccb != NULL) cam_freeccb(ccb); ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_MODESELECT)); return rc; @@ -2061,12 +2014,12 @@ int camtape_allow_medium_removal(void *device) * @param size length of the buffer * @return 0 on success or a negative value on error */ -int camtape_read_attribute(void *device, const tape_partition_t part, const uint16_t id, - unsigned char *buf, const size_t size) +int camtape_read_attribute( + void *device, const tape_partition_t part, const uint16_t id, unsigned char *buf, const size_t size) { int rc = DEVICE_GOOD; char *msg = NULL; - bool take_dump= true; + bool take_dump = true; int timeout; struct camtape_data *softc = (struct camtape_data *)device; struct scsi_read_attribute_values *attr_header = NULL; @@ -2074,12 +2027,10 @@ int camtape_read_attribute(void *device, const tape_partition_t part, const uint union ccb *ccb = NULL; /* TODO: Need to return data with header when size is MAXMAM_SIZE */ - if (size == MAXMAM_SIZE) - return -LTFS_NO_XATTR; + if (size == MAXMAM_SIZE) return -LTFS_NO_XATTR; ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_READATTR)); - ltfsmsg(LTFS_DEBUG3, 31397D, "readattr", (unsigned long long)part, - (unsigned long long)id, softc->drive_serial); + ltfsmsg(LTFS_DEBUG3, 31397D, "readattr", (unsigned long long)part, (unsigned long long)id, softc->drive_serial); ccb = cam_getccb(softc->cd); if (ccb == NULL) { @@ -2087,8 +2038,7 @@ int camtape_read_attribute(void *device, const tape_partition_t part, const uint goto bailout; } - memset(&(&ccb->ccb_h)[1], 0, - sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr)); + memset(&(&ccb->ccb_h)[1], 0, sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr)); /* * The function interface only includes enough space for the attribute, and doesn't include @@ -2108,51 +2058,41 @@ int camtape_read_attribute(void *device, const tape_partition_t part, const uint } scsi_read_attribute(&ccb->csio, - /*retries*/ 1, - /*cbfcnp*/ NULL, - /*tag_action*/ MSG_SIMPLE_Q_TAG, - /*service_action*/ SRA_SA_ATTR_VALUES, - /*element*/ 0, - /*elem_type*/ 0, - /*logical_volume*/ 0, - /*partition*/ part, - /*first_attribute*/ id, - /*cache*/ 0, - /*data_ptr*/ (uint8_t *)attr_header, - /*length*/ attr_size, - /*sense_len*/ SSD_FULL_SIZE, - /*timeout*/ timeout); + /*retries*/ 1, + /*cbfcnp*/ NULL, + /*tag_action*/ MSG_SIMPLE_Q_TAG, + /*service_action*/ SRA_SA_ATTR_VALUES, + /*element*/ 0, + /*elem_type*/ 0, + /*logical_volume*/ 0, + /*partition*/ part, + /*first_attribute*/ id, + /*cache*/ 0, + /*data_ptr*/ (uint8_t *)attr_header, + /*length*/ attr_size, + /*sense_len*/ SSD_FULL_SIZE, + /*timeout*/ timeout); ccb->ccb_h.flags |= CAM_DEV_QFRZDIS | CAM_PASS_ERR_RECOVER; rc = camtape_send_ccb(softc, ccb, &msg); if (rc != DEVICE_GOOD) { - if ( rc == -EDEV_INVALID_FIELD_CDB ) - take_dump = false; + if (rc == -EDEV_INVALID_FIELD_CDB) take_dump = false; camtape_process_errors(device, rc, msg, "readattr", take_dump); - if (rc < 0 && - id != TC_MAM_PAGE_COHERENCY && - id != TC_MAM_APP_VENDER && - id != TC_MAM_APP_NAME && - id != TC_MAM_APP_VERSION && - id != TC_MAM_USER_MEDIUM_LABEL && - id != TC_MAM_TEXT_LOCALIZATION_IDENTIFIER && - id != TC_MAM_BARCODE && - id != TC_MAM_APP_FORMAT_VERSION) + if (rc < 0 && id != TC_MAM_PAGE_COHERENCY && id != TC_MAM_APP_VENDER && id != TC_MAM_APP_NAME && + id != TC_MAM_APP_VERSION && id != TC_MAM_USER_MEDIUM_LABEL && id != TC_MAM_TEXT_LOCALIZATION_IDENTIFIER && + id != TC_MAM_BARCODE && id != TC_MAM_APP_FORMAT_VERSION) ltfsmsg(LTFS_INFO, 31260I, rc); } else { - memcpy(buf, &attr_header[1], size); } bailout: - if (ccb != NULL) - cam_freeccb(ccb); - if (attr_header != NULL) - free(attr_header); + if (ccb != NULL) cam_freeccb(ccb); + if (attr_header != NULL) free(attr_header); ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_READATTR)); return rc; @@ -2168,8 +2108,7 @@ int camtape_read_attribute(void *device, const tape_partition_t part, const uint * @param size length of the attribute buffer * @return 0 on success or a negative value on error */ -int camtape_write_attribute(void *device, const tape_partition_t part, const unsigned char *buf, - const size_t size) +int camtape_write_attribute(void *device, const tape_partition_t part, const unsigned char *buf, const size_t size) { int rc = DEVICE_GOOD; char *msg = NULL; @@ -2180,8 +2119,7 @@ int camtape_write_attribute(void *device, const tape_partition_t part, const uns union ccb *ccb = NULL; ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_WRITEATTR)); - ltfsmsg(LTFS_DEBUG3, 31394D, "writeattr", (unsigned long long)part, - softc->drive_serial); + ltfsmsg(LTFS_DEBUG3, 31394D, "writeattr", (unsigned long long)part, softc->drive_serial); ccb = cam_getccb(softc->cd); if (ccb == NULL) { @@ -2189,8 +2127,7 @@ int camtape_write_attribute(void *device, const tape_partition_t part, const uns goto bailout; } - memset(&(&ccb->ccb_h)[1], 0, - sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr)); + memset(&(&ccb->ccb_h)[1], 0, sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr)); /* * The function interface only includes enough space for the attribute, and doesn't include @@ -2214,30 +2151,27 @@ int camtape_write_attribute(void *device, const tape_partition_t part, const uns } scsi_write_attribute(&ccb->csio, - /*retries*/ 1, - /*cbfcnp*/ NULL, - /*tag_action*/ MSG_SIMPLE_Q_TAG, - /*element*/ 0, - /*logical_volume*/ 0, - /*partition*/ part, - /*wtc*/ 1, - /*data_ptr*/ (uint8_t *)attr_header, - /*length*/ attr_size, - /*sense_len*/ SSD_FULL_SIZE, - /*timeout*/ timeout); + /*retries*/ 1, + /*cbfcnp*/ NULL, + /*tag_action*/ MSG_SIMPLE_Q_TAG, + /*element*/ 0, + /*logical_volume*/ 0, + /*partition*/ part, + /*wtc*/ 1, + /*data_ptr*/ (uint8_t *)attr_header, + /*length*/ attr_size, + /*sense_len*/ SSD_FULL_SIZE, + /*timeout*/ timeout); ccb->ccb_h.flags |= CAM_DEV_QFRZDIS | CAM_PASS_ERR_RECOVER; rc = camtape_send_ccb(softc, ccb, &msg); - if (rc != DEVICE_GOOD) - camtape_process_errors(device, rc, msg, "writeattr", true); + if (rc != DEVICE_GOOD) camtape_process_errors(device, rc, msg, "writeattr", true); bailout: - if (ccb != NULL) - cam_freeccb(ccb); - if (attr_header != NULL) - free(attr_header); + if (ccb != NULL) cam_freeccb(ccb); + if (attr_header != NULL) free(attr_header); ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_WRITEATTR)); return rc; @@ -2253,8 +2187,12 @@ int camtape_allow_overwrite(void *device, const struct tc_position pos) union ccb *ccb; ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_ALLOWOVERW)); - ltfsmsg(LTFS_DEBUG, 31397D, "allow overwrite", (unsigned long long)pos.partition, - (unsigned long long)pos.block, softc->drive_serial); + ltfsmsg(LTFS_DEBUG, + 31397D, + "allow overwrite", + (unsigned long long)pos.partition, + (unsigned long long)pos.block, + softc->drive_serial); ccb = cam_getccb(softc->cd); if (ccb == NULL) { @@ -2262,8 +2200,7 @@ int camtape_allow_overwrite(void *device, const struct tc_position pos) goto bailout; } - memset(&(&ccb->ccb_h)[1], 0, - sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr)); + memset(&(&ccb->ccb_h)[1], 0, sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr)); timeout = camtape_get_timeout(softc->timeouts, ALLOW_OVERWRITE); if (timeout < 0) { @@ -2274,14 +2211,14 @@ int camtape_allow_overwrite(void *device, const struct tc_position pos) memset(&append_pos, 0, sizeof(append_pos)); scsi_allow_overwrite(&ccb->csio, - /*retries*/ 1, - /*cbfcnp*/ NULL, - /*tag_action*/ MSG_SIMPLE_Q_TAG, - /*allow_overwrite*/ SAO_ALLOW_OVERWRITE_CUR_POS, - /*partition*/ pos.partition, - /*logical_id*/ pos.block, - /*sense_len*/ SSD_FULL_SIZE, - /*timeout*/ timeout); + /*retries*/ 1, + /*cbfcnp*/ NULL, + /*tag_action*/ MSG_SIMPLE_Q_TAG, + /*allow_overwrite*/ SAO_ALLOW_OVERWRITE_CUR_POS, + /*partition*/ pos.partition, + /*logical_id*/ pos.block, + /*sense_len*/ SSD_FULL_SIZE, + /*timeout*/ timeout); ccb->ccb_h.flags |= CAM_DEV_QFRZDIS | CAM_PASS_ERR_RECOVER; @@ -2293,13 +2230,11 @@ int camtape_allow_overwrite(void *device, const struct tc_position pos) rc = DEVICE_GOOD; } - if (rc != DEVICE_GOOD) - camtape_process_errors(device, rc, msg, "allow overwrite", true); + if (rc != DEVICE_GOOD) camtape_process_errors(device, rc, msg, "allow overwrite", true); } bailout: - if (ccb != NULL) - cam_freeccb(ccb); + if (ccb != NULL) cam_freeccb(ccb); ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_ALLOWOVERW)); return rc; @@ -2345,7 +2280,7 @@ int camtape_set_compression(void *device, const bool enable_compression, struct buf[0] = 0x00; buf[1] = 0x00; - if(enable_compression) + if (enable_compression) buf[18] |= 0x80; /* Set DCE field*/ else buf[18] &= 0x7F; /* Unset DCE field*/ @@ -2380,13 +2315,12 @@ int camtape_set_default(void *device) return rc; } - buf[0] = 0x00; - buf[1] = 0x00; + buf[0] = 0x00; + buf[1] = 0x00; buf[24] = 0x0C; rc = camtape_modeselect(device, buf, sizeof(buf)); - if (rc != DEVICE_GOOD) - goto bailout; + if (rc != DEVICE_GOOD) goto bailout; } /* set SILI bit */ @@ -2421,8 +2355,7 @@ int camtape_set_default(void *device) rc = DEVICE_GOOD; } - if (rc != DEVICE_GOOD) - goto bailout; + if (rc != DEVICE_GOOD) goto bailout; ltfsmsg(LTFS_DEBUG, 31392D, __FUNCTION__, "Setting EOT model to 1FM"); @@ -2454,31 +2387,23 @@ int camtape_set_default(void *device) * @return 0 on success or a negative value on error */ -#define LOG_TAPE_ALERT (0x2E) -#define LOG_PERFORMANCE (0x37) -#define LOG_PERFORMANCE_CAPACITY_SUB (0x64) // Scope(7-6): Mount Values - // Level(5-4): Return Advanced Counters - // Group(3-0): Capacity +#define LOG_TAPE_ALERT (0x2E) +#define LOG_PERFORMANCE (0x37) +#define LOG_PERFORMANCE_CAPACITY_SUB \ + (0x64) // Scope(7-6): Mount Values \ + // Level(5-4): Return Advanced Counters \ + // Group(3-0): Capacity static uint16_t volstats[] = { - VOLSTATS_MOUNTS, - VOLSTATS_WRITTEN_DS, - VOLSTATS_WRITE_TEMPS, - VOLSTATS_WRITE_PERMS, - VOLSTATS_READ_DS, - VOLSTATS_READ_TEMPS, - VOLSTATS_READ_PERMS, - VOLSTATS_WRITE_PERMS_PREV, - VOLSTATS_READ_PERMS_PREV, - VOLSTATS_WRITE_MB, - VOLSTATS_READ_MB, - VOLSTATS_PASSES_BEGIN, - VOLSTATS_PASSES_MIDDLE, + VOLSTATS_MOUNTS, VOLSTATS_WRITTEN_DS, VOLSTATS_WRITE_TEMPS, VOLSTATS_WRITE_PERMS, VOLSTATS_READ_DS, + VOLSTATS_READ_TEMPS, VOLSTATS_READ_PERMS, VOLSTATS_WRITE_PERMS_PREV, VOLSTATS_READ_PERMS_PREV, VOLSTATS_WRITE_MB, + VOLSTATS_READ_MB, VOLSTATS_PASSES_BEGIN, VOLSTATS_PASSES_MIDDLE, }; -enum { - PERF_CART_CONDITION = 0x0001, /* < Media Efficiency */ - PERF_ACTIVE_CQ_LOSS_W = 0x7113, /* < Active CQ loss Write */ +enum +{ + PERF_CART_CONDITION = 0x0001, /* < Media Efficiency */ + PERF_ACTIVE_CQ_LOSS_W = 0x7113, /* < Active CQ loss Write */ }; static uint16_t perfstats[] = { @@ -2497,127 +2422,128 @@ int camtape_get_cartridge_health(void *device, struct tc_cartridge_health *cart_ ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_GETCARTHLTH)); /* Issue LogPage 0x37 */ - cart_health->tape_efficiency = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->tape_efficiency = UNSUPPORTED_CARTRIDGE_HEALTH; rc = camtape_logsense(device, LOG_PERFORMANCE, (uint8_t)0, logdata, LOGSENSEPAGE); if (rc < 0) ltfsmsg(LTFS_INFO, 31261I, LOG_PERFORMANCE, rc, "get cart health"); else { - for(i = 0; i < (int)((sizeof(perfstats)/sizeof(perfstats[0]))); i++) { /* BEAM: loop doesn't iterate - Use loop for future enhancement. */ + for (i = 0; i < (int)((sizeof(perfstats) / sizeof(perfstats[0]))); + i++) { /* BEAM: loop doesn't iterate - Use loop for future enhancement. */ if (parse_logPage(logdata, perfstats[i], ¶m_size, buf, 16)) { ltfsmsg(LTFS_INFO, 31262I, LOG_PERFORMANCE, "get cart health"); } else { - switch(param_size) { - case sizeof(uint8_t): - loghlt = (uint64_t)(buf[0]); - break; - case sizeof(uint16_t): - loghlt = (uint64_t)ltfs_betou16(buf); - break; - case sizeof(uint32_t): - loghlt = (uint32_t)ltfs_betou32(buf); - break; - case sizeof(uint64_t): - loghlt = ltfs_betou64(buf); - break; - default: - loghlt = UNSUPPORTED_CARTRIDGE_HEALTH; - break; + switch (param_size) { + case sizeof(uint8_t): + loghlt = (uint64_t)(buf[0]); + break; + case sizeof(uint16_t): + loghlt = (uint64_t)ltfs_betou16(buf); + break; + case sizeof(uint32_t): + loghlt = (uint32_t)ltfs_betou32(buf); + break; + case sizeof(uint64_t): + loghlt = ltfs_betou64(buf); + break; + default: + loghlt = UNSUPPORTED_CARTRIDGE_HEALTH; + break; } - switch(perfstats[i]) { - case PERF_CART_CONDITION: - cart_health->tape_efficiency = loghlt; - break; - default: - break; + switch (perfstats[i]) { + case PERF_CART_CONDITION: + cart_health->tape_efficiency = loghlt; + break; + default: + break; } } } } /* Issue LogPage 0x17 */ - cart_health->mounts = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->written_ds = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->write_temps = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->write_perms = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_ds = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_temps = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_perms = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->mounts = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->written_ds = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->write_temps = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->write_perms = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_ds = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_temps = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_perms = UNSUPPORTED_CARTRIDGE_HEALTH; cart_health->write_perms_prev = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_perms_prev = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->written_mbytes = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_mbytes = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->passes_begin = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->passes_middle = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_perms_prev = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->written_mbytes = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_mbytes = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->passes_begin = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->passes_middle = UNSUPPORTED_CARTRIDGE_HEALTH; rc = camtape_logsense(device, LOG_VOLUMESTATS, (uint8_t)0, logdata, LOGSENSEPAGE); if (rc < 0) ltfsmsg(LTFS_INFO, 31261I, LOG_VOLUMESTATS, rc, "get cart health"); else { - for(i = 0; i < (int)((sizeof(volstats)/sizeof(volstats[0]))); i++) { + for (i = 0; i < (int)((sizeof(volstats) / sizeof(volstats[0]))); i++) { if (parse_logPage(logdata, volstats[i], ¶m_size, buf, 16)) { ltfsmsg(LTFS_INFO, 31262I, LOG_VOLUMESTATS, "get cart health"); } else { - switch(param_size) { - case sizeof(uint8_t): - loghlt = (uint64_t)(buf[0]); - break; - case sizeof(uint16_t): - loghlt = (uint64_t)ltfs_betou16(buf); - break; - case sizeof(uint32_t): - loghlt = (uint32_t)ltfs_betou32(buf); - break; - case sizeof(uint64_t): - loghlt = ltfs_betou64(buf); - break; - default: - loghlt = UNSUPPORTED_CARTRIDGE_HEALTH; - break; + switch (param_size) { + case sizeof(uint8_t): + loghlt = (uint64_t)(buf[0]); + break; + case sizeof(uint16_t): + loghlt = (uint64_t)ltfs_betou16(buf); + break; + case sizeof(uint32_t): + loghlt = (uint32_t)ltfs_betou32(buf); + break; + case sizeof(uint64_t): + loghlt = ltfs_betou64(buf); + break; + default: + loghlt = UNSUPPORTED_CARTRIDGE_HEALTH; + break; } - switch(volstats[i]) { - case VOLSTATS_MOUNTS: - cart_health->mounts = loghlt; - break; - case VOLSTATS_WRITTEN_DS: - cart_health->written_ds = loghlt; - break; - case VOLSTATS_WRITE_TEMPS: - cart_health->write_temps = loghlt; - break; - case VOLSTATS_WRITE_PERMS: - cart_health->write_perms = loghlt; - break; - case VOLSTATS_READ_DS: - cart_health->read_ds = loghlt; - break; - case VOLSTATS_READ_TEMPS: - cart_health->read_temps = loghlt; - break; - case VOLSTATS_READ_PERMS: - cart_health->read_perms = loghlt; - break; - case VOLSTATS_WRITE_PERMS_PREV: - cart_health->write_perms_prev = loghlt; - break; - case VOLSTATS_READ_PERMS_PREV: - cart_health->read_perms_prev = loghlt; - break; - case VOLSTATS_WRITE_MB: - cart_health->written_mbytes = loghlt; - break; - case VOLSTATS_READ_MB: - cart_health->read_mbytes = loghlt; - break; - case VOLSTATS_PASSES_BEGIN: - cart_health->passes_begin = loghlt; - break; - case VOLSTATS_PASSES_MIDDLE: - cart_health->passes_middle = loghlt; - break; - default: - break; + switch (volstats[i]) { + case VOLSTATS_MOUNTS: + cart_health->mounts = loghlt; + break; + case VOLSTATS_WRITTEN_DS: + cart_health->written_ds = loghlt; + break; + case VOLSTATS_WRITE_TEMPS: + cart_health->write_temps = loghlt; + break; + case VOLSTATS_WRITE_PERMS: + cart_health->write_perms = loghlt; + break; + case VOLSTATS_READ_DS: + cart_health->read_ds = loghlt; + break; + case VOLSTATS_READ_TEMPS: + cart_health->read_temps = loghlt; + break; + case VOLSTATS_READ_PERMS: + cart_health->read_perms = loghlt; + break; + case VOLSTATS_WRITE_PERMS_PREV: + cart_health->write_perms_prev = loghlt; + break; + case VOLSTATS_READ_PERMS_PREV: + cart_health->read_perms_prev = loghlt; + break; + case VOLSTATS_WRITE_MB: + cart_health->written_mbytes = loghlt; + break; + case VOLSTATS_READ_MB: + cart_health->read_mbytes = loghlt; + break; + case VOLSTATS_PASSES_BEGIN: + cart_health->passes_begin = loghlt; + break; + case VOLSTATS_PASSES_MIDDLE: + cart_health->passes_middle = loghlt; + break; + default: + break; } } } @@ -2642,7 +2568,7 @@ int camtape_get_tape_alert(void *device, uint64_t *tape_alert) int param_size, i; int rc; uint64_t ta; - struct camtape_data *softc = (struct camtape_data *) device; + struct camtape_data *softc = (struct camtape_data *)device; ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_GETTAPEALT)); /* Issue LogPage 0x2E */ @@ -2652,15 +2578,13 @@ int camtape_get_tape_alert(void *device, uint64_t *tape_alert) ltfsmsg(LTFS_INFO, 31261I, LOG_TAPE_ALERT, rc, "get tape alert"); else { rc = 0; - for(i = 1; i <= 64; i++) { - if (parse_logPage(logdata, (uint16_t) i, ¶m_size, buf, 16) - || param_size != sizeof(uint8_t)) { + for (i = 1; i <= 64; i++) { + if (parse_logPage(logdata, (uint16_t)i, ¶m_size, buf, 16) || param_size != sizeof(uint8_t)) { ltfsmsg(LTFS_INFO, 31262I, LOG_TAPE_ALERT, "get tape alert"); ta = 0; } - if(buf[0]) - ta += (uint64_t)(1) << (i - 1); + if (buf[0]) ta += (uint64_t)(1) << (i - 1); } } @@ -2679,28 +2603,26 @@ int camtape_get_tape_alert(void *device, uint64_t *tape_alert) */ int camtape_clear_tape_alert(void *device, uint64_t tape_alert) { - struct camtape_data *softc = (struct camtape_data *) device; + struct camtape_data *softc = (struct camtape_data *)device; ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_CLRTAPEALT)); softc->tape_alert &= ~tape_alert; ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_CLRTAPEALT)); return 0; } -typedef enum { - MT_MAXIO = 0, - MT_CPI_MAXIO = 1, - MT_MAX_BLK = 2, - MT_MAX_EFF_IO_SIZE = 3, +typedef enum +{ + MT_MAXIO = 0, + MT_CPI_MAXIO = 1, + MT_MAX_BLK = 2, + MT_MAX_EFF_IO_SIZE = 3, } camtape_block_index; struct camtape_status_item req_block_items[] = { - {"maxio", NULL }, - {"cpi_maxio", NULL }, - {"max_blk", NULL }, - {"max_effective_iosize", NULL } + { "maxio", NULL }, { "cpi_maxio", NULL }, { "max_blk", NULL }, { "max_effective_iosize", NULL } }; -#define CT_NUM_BLOCK_ITEMS (sizeof(req_block_items)/sizeof(req_block_items[0])) +#define CT_NUM_BLOCK_ITEMS (sizeof(req_block_items) / sizeof(req_block_items[0])) /** * Get drive parameter @@ -2799,12 +2721,11 @@ int camtape_get_parameters(void *device, struct tc_drive_param *params) return rc; } - if ( (buf[3] & 0x80) ) - params->write_protect |= VOL_PHYSICAL_WP; + if ((buf[3] & 0x80)) params->write_protect |= VOL_PHYSICAL_WP; } params->cart_type = softc->cart_type; - params->density = softc->density_code; + params->density = softc->density_code; /* TODO: Following field shall be implemented in the future */ /* params->is_worm = softc->is_worm; @@ -2883,110 +2804,114 @@ int camtape_get_device_list(struct tc_drive_info *buf, int count) ccb.cdm.pattern_buf_len = sizeof(patterns); ccb.cdm.patterns = patterns; patterns[0].type = DEV_MATCH_PERIPH; - snprintf(patterns[0].pattern.periph_pattern.periph_name, - sizeof(patterns[0].pattern.periph_pattern.periph_name), "sa"); + snprintf( + patterns[0].pattern.periph_pattern.periph_name, sizeof(patterns[0].pattern.periph_pattern.periph_name), "sa"); patterns[0].pattern.periph_pattern.flags = PERIPH_MATCH_NAME; patterns[1].type = DEV_MATCH_DEVICE; patterns[1].pattern.device_pattern.flags = DEV_MATCH_INQUIRY; patterns[1].pattern.device_pattern.data.inq_pat.type = T_SEQUENTIAL; patterns[1].pattern.device_pattern.data.inq_pat.media_type = SIP_MEDIA_REMOVABLE; snprintf(patterns[1].pattern.device_pattern.data.inq_pat.vendor, - sizeof(patterns[1].pattern.device_pattern.data.inq_pat.vendor), "*"); + sizeof(patterns[1].pattern.device_pattern.data.inq_pat.vendor), + "*"); snprintf(patterns[1].pattern.device_pattern.data.inq_pat.product, - sizeof(patterns[1].pattern.device_pattern.data.inq_pat.product), "*"); + sizeof(patterns[1].pattern.device_pattern.data.inq_pat.product), + "*"); snprintf(patterns[1].pattern.device_pattern.data.inq_pat.revision, - sizeof(patterns[1].pattern.device_pattern.data.inq_pat.revision), "*"); + sizeof(patterns[1].pattern.device_pattern.data.inq_pat.revision), + "*"); buf_index = 0; do { - if (ioctl(fd, CAMIOCOMMAND, &ccb) == -1) - err(1, "error sending CAMIOCOMMAND ioctl to %s", - XPT_DEVICE); + if (ioctl(fd, CAMIOCOMMAND, &ccb) == -1) err(1, "error sending CAMIOCOMMAND ioctl to %s", XPT_DEVICE); - if ((ccb.ccb_h.status != CAM_REQ_CMP) - || ((ccb.cdm.status != CAM_DEV_MATCH_LAST) - && (ccb.cdm.status != CAM_DEV_MATCH_MORE))) - errx(1, "got CAM error %#x, CDM error %d\n", - ccb.ccb_h.status, ccb.cdm.status); + if ((ccb.ccb_h.status != CAM_REQ_CMP) || + ((ccb.cdm.status != CAM_DEV_MATCH_LAST) && (ccb.cdm.status != CAM_DEV_MATCH_MORE))) + errx(1, "got CAM error %#x, CDM error %d\n", ccb.ccb_h.status, ccb.cdm.status); for (i = 0; i < ccb.cdm.num_matches; i++) { switch (ccb.cdm.matches[i].type) { - case DEV_MATCH_DEVICE: { - struct device_match_result *dev_result; - uint8_t vendor[16], product[48], revision[16]; - - dev_result = &ccb.cdm.matches[i].result.device_result; - - if ((dev_result->protocol == PROTO_SCSI) && (buf != NULL)) { - cam_strvis(vendor, (const uint8_t *)dev_result->inq_data.vendor, - sizeof(dev_result->inq_data.vendor), sizeof(vendor)); - cam_strvis(product, (const uint8_t *) dev_result->inq_data.product, - sizeof(dev_result->inq_data.product), sizeof(product)); - cam_strvis(revision, (const uint8_t *)dev_result->inq_data.revision, - sizeof(dev_result->inq_data.revision), sizeof(revision)); - snprintf(buf[buf_index].vendor, sizeof(buf[buf_index].vendor), "%s", vendor); - snprintf(buf[buf_index].model, sizeof(buf[buf_index].model), "%s", product); - snprintf(buf[buf_index].product_name, sizeof(buf[buf_index].product_name), "%s", - generate_product_name((const char *)product)); - buf[buf_index].host = 0; - buf[buf_index].channel = 0; - buf[buf_index].target = 0; - buf[buf_index].lun = -1; - } else { - /* + case DEV_MATCH_DEVICE: { + struct device_match_result *dev_result; + uint8_t vendor[16], product[48], revision[16]; + + dev_result = &ccb.cdm.matches[i].result.device_result; + + if ((dev_result->protocol == PROTO_SCSI) && (buf != NULL)) { + cam_strvis(vendor, + (const uint8_t *)dev_result->inq_data.vendor, + sizeof(dev_result->inq_data.vendor), + sizeof(vendor)); + cam_strvis(product, + (const uint8_t *)dev_result->inq_data.product, + sizeof(dev_result->inq_data.product), + sizeof(product)); + cam_strvis(revision, + (const uint8_t *)dev_result->inq_data.revision, + sizeof(dev_result->inq_data.revision), + sizeof(revision)); + snprintf(buf[buf_index].vendor, sizeof(buf[buf_index].vendor), "%s", vendor); + snprintf(buf[buf_index].model, sizeof(buf[buf_index].model), "%s", product); + snprintf(buf[buf_index].product_name, + sizeof(buf[buf_index].product_name), + "%s", + generate_product_name((const char *)product)); + buf[buf_index].host = 0; + buf[buf_index].channel = 0; + buf[buf_index].target = 0; + buf[buf_index].lun = -1; + } else { + /* * XXX KDM what now? We have a tape device that isn't SCSI?? */ + } + break; } - break; - } - case DEV_MATCH_PERIPH: { - struct periph_match_result *periph_result; - - periph_result = - &ccb.cdm.matches[i].result.periph_result; - - if (buf != NULL) { - struct cam_device *dev; - - dev = cam_open_spec_device( - periph_result->periph_name, - periph_result->unit_number, O_RDWR, NULL); - if (dev == NULL) { - err(1, "unable to open passthrough " - "device for %s%d", - periph_result->periph_name, - periph_result->unit_number); + case DEV_MATCH_PERIPH: { + struct periph_match_result *periph_result; + + periph_result = &ccb.cdm.matches[i].result.periph_result; + + if (buf != NULL) { + struct cam_device *dev; + + dev = cam_open_spec_device(periph_result->periph_name, periph_result->unit_number, O_RDWR, NULL); + if (dev == NULL) { + err(1, + "unable to open passthrough " + "device for %s%d", + periph_result->periph_name, + periph_result->unit_number); + } + dev->serial_num[dev->serial_num_len] = '\0'; + snprintf(buf[buf_index].serial_number, sizeof(buf[buf_index].serial_number), "%s", dev->serial_num); + snprintf(buf[buf_index].name, + sizeof(buf[buf_index].name), + "%s%d", + periph_result->periph_name, + periph_result->unit_number); + buf[buf_index].host = 0; + buf[buf_index].channel = 0; + buf[buf_index].target = 0; + buf[buf_index].lun = -1; + cam_close_device(dev); } - dev->serial_num[dev->serial_num_len] = '\0'; - snprintf(buf[buf_index].serial_number, sizeof(buf[buf_index].serial_number), - "%s", dev->serial_num); - snprintf(buf[buf_index].name, sizeof(buf[buf_index].name), "%s%d", - periph_result->periph_name, periph_result->unit_number); - buf[buf_index].host = 0; - buf[buf_index].channel = 0; - buf[buf_index].target = 0; - buf[buf_index].lun = -1; - cam_close_device(dev); + buf_index++; + if (buf != NULL && buf_index >= count) goto bailout; + break; } - buf_index++; - if (buf != NULL && buf_index >= count) - goto bailout; - break; - } - default: - break; + default: + break; } } - } while ((ccb.ccb_h.status == CAM_REQ_CMP) - && (ccb.cdm.status == CAM_DEV_MATCH_MORE)); + } while ((ccb.ccb_h.status == CAM_REQ_CMP) && (ccb.cdm.status == CAM_DEV_MATCH_MORE)); bailout: close(fd); - if (ccb.cdm.matches != NULL) - free(ccb.cdm.matches); + if (ccb.cdm.matches != NULL) free(ccb.cdm.matches); return buf_index; } @@ -3023,10 +2948,10 @@ int camtape_setcap(void *device, uint16_t proportion) return DEVICE_GOOD; } - buf[0] = 0x00; - buf[1] = 0x00; + buf[0] = 0x00; + buf[1] = 0x00; buf[27] |= 0x01; - buf[28] = 0x00; + buf[28] = 0x00; rc = camtape_modeselect(device, buf, sizeof(buf)); } else { @@ -3038,8 +2963,7 @@ int camtape_setcap(void *device, uint16_t proportion) goto bailout; } - memset(&(&ccb->ccb_h)[1], 0, - sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr)); + memset(&(&ccb->ccb_h)[1], 0, sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr)); timeout = camtape_get_timeout(softc->timeouts, SET_CAPACITY); if (timeout < 0) { @@ -3048,13 +2972,13 @@ int camtape_setcap(void *device, uint16_t proportion) } scsi_set_capacity(&ccb->csio, - /*retries*/ 1, - /*cbfcnp*/ NULL, - /*tag_action*/ MSG_SIMPLE_Q_TAG, - /*byte1*/ 0, - /*proportion*/ proportion, - /*sense_len*/ SSD_FULL_SIZE, - /*timeout*/ timeout); + /*retries*/ 1, + /*cbfcnp*/ NULL, + /*tag_action*/ MSG_SIMPLE_Q_TAG, + /*byte1*/ 0, + /*proportion*/ proportion, + /*sense_len*/ SSD_FULL_SIZE, + /*timeout*/ timeout); ccb->ccb_h.flags |= CAM_DEV_QFRZDIS | CAM_PASS_ERR_RECOVER; @@ -3066,8 +2990,7 @@ int camtape_setcap(void *device, uint16_t proportion) } bailout: - if (ccb != NULL) - cam_freeccb(ccb); + if (ccb != NULL) cam_freeccb(ccb); ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_SETCAP)); return rc; } @@ -3078,9 +3001,9 @@ int camtape_setcap(void *device, uint16_t proportion) * @param part Partition to read the parameter from. * @return enum eod_status or UNSUPPORTED_FUNCTION if not supported. */ -#define LOG_VOL_STATISTICS (0x17) -#define LOG_VOL_USED_CAPACITY (0x203) -#define LOG_VOL_PART_HEADER_SIZE (4) +#define LOG_VOL_STATISTICS (0x17) +#define LOG_VOL_USED_CAPACITY (0x203) +#define LOG_VOL_PART_HEADER_SIZE (4) int camtape_get_eod_status(void *device, int part) { @@ -3091,10 +3014,10 @@ int camtape_get_eod_status(void *device, int part) struct camtape_data *softc = (struct camtape_data *)device; unsigned char logdata[LOGSENSEPAGE]; - unsigned char buf[16] = {0}; + unsigned char buf[16] = { 0 }; int param_size, rc; unsigned int i; - uint32_t part_cap[2] = {EOD_UNKNOWN, EOD_UNKNOWN}; + uint32_t part_cap[2] = { EOD_UNKNOWN, EOD_UNKNOWN }; ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_GETEODSTAT)); /* Issue LogPage 0x17 */ @@ -3106,8 +3029,8 @@ int camtape_get_eod_status(void *device, int part) } /* Parse Approximate used native capacity of partitions (0x203)*/ - if (parse_logPage(logdata, (uint16_t)LOG_VOL_USED_CAPACITY, ¶m_size, buf, sizeof(buf)) - || (param_size != sizeof(buf) ) ) { + if (parse_logPage(logdata, (uint16_t)LOG_VOL_USED_CAPACITY, ¶m_size, buf, sizeof(buf)) || + (param_size != sizeof(buf))) { ltfsmsg(LTFS_WARN, 31265W); ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_GETEODSTAT)); return EOD_UNKNOWN; @@ -3119,13 +3042,11 @@ int camtape_get_eod_status(void *device, int part) uint16_t part_buf; len = buf[i]; - part_buf = (uint16_t)(buf[i + 2] << 8) + (uint16_t) buf[i + 3]; + part_buf = (uint16_t)(buf[i + 2] << 8) + (uint16_t)buf[i + 3]; /* actual length - 1 is stored into len */ - if ( (len - LOG_VOL_PART_HEADER_SIZE + 1) == sizeof(uint32_t) && part_buf < 2) { - part_cap[part_buf] = ((uint32_t) buf[i + 4] << 24) + - ((uint32_t) buf[i + 5] << 16) + - ((uint32_t) buf[i + 6] << 8) + - (uint32_t) buf[i + 7]; + if ((len - LOG_VOL_PART_HEADER_SIZE + 1) == sizeof(uint32_t) && part_buf < 2) { + part_cap[part_buf] = ((uint32_t)buf[i + 4] << 24) + ((uint32_t)buf[i + 5] << 16) + ((uint32_t)buf[i + 6] << 8) + + (uint32_t)buf[i + 7]; } else ltfsmsg(LTFS_WARN, 31266W, i, part_buf, len); @@ -3133,7 +3054,7 @@ int camtape_get_eod_status(void *device, int part) } /* Create return value */ - if(part_cap[part] == 0xFFFFFFFF) + if (part_cap[part] == 0xFFFFFFFF) rc = EOD_MISSING; else rc = EOD_GOOD; @@ -3151,7 +3072,7 @@ int camtape_get_eod_status(void *device, int part) */ int camtape_get_xattr(void *device, const char *name, char **buf) { - struct camtape_data *softc = (struct camtape_data *) device; + struct camtape_data *softc = (struct camtape_data *)device; unsigned char logdata[LOGSENSEPAGE]; unsigned char logbuf[16]; int param_size; @@ -3160,15 +3081,14 @@ int camtape_get_xattr(void *device, const char *name, char **buf) struct ltfs_timespec now; ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_GETXATTR)); - if (! strcmp(name, "ltfs.vendor.IBM.mediaCQsLossRate")) { + if (!strcmp(name, "ltfs.vendor.IBM.mediaCQsLossRate")) { rc = DEVICE_GOOD; /* If first fetch or cache value is too old and valuie is dirty, refetch value */ get_current_timespec(&now); - if ( softc->fetch_sec_acq_loss_w == 0 || - ((softc->fetch_sec_acq_loss_w + 60 < now.tv_sec) && softc->dirty_acq_loss_w)) { - rc = camtape_logsense(device, LOG_PERFORMANCE, LOG_PERFORMANCE_CAPACITY_SUB, - logdata, LOGSENSEPAGE); + if (softc->fetch_sec_acq_loss_w == 0 || + ((softc->fetch_sec_acq_loss_w + 60 < now.tv_sec) && softc->dirty_acq_loss_w)) { + rc = camtape_logsense(device, LOG_PERFORMANCE, LOG_PERFORMANCE_CAPACITY_SUB, logdata, LOGSENSEPAGE); if (rc < 0) ltfsmsg(LTFS_INFO, 31261I, LOG_PERFORMANCE, rc, "get xattr"); else { @@ -3177,30 +3097,29 @@ int camtape_get_xattr(void *device, const char *name, char **buf) ltfsmsg(LTFS_INFO, 31262I, LOG_PERFORMANCE, "get xattr"); rc = -LTFS_NO_XATTR; } else { - switch(param_size) { - case sizeof(uint32_t): - value32 = (uint32_t)ltfs_betou32(logbuf); - softc->acq_loss_w = (float)value32 / 65536.0; - softc->fetch_sec_acq_loss_w = now.tv_sec; - softc->dirty_acq_loss_w = false; - break; - default: - ltfsmsg(LTFS_INFO, 31267I, param_size); - rc = -LTFS_NO_XATTR; - break; + switch (param_size) { + case sizeof(uint32_t): + value32 = (uint32_t)ltfs_betou32(logbuf); + softc->acq_loss_w = (float)value32 / 65536.0; + softc->fetch_sec_acq_loss_w = now.tv_sec; + softc->dirty_acq_loss_w = false; + break; + default: + ltfsmsg(LTFS_INFO, 31267I, param_size); + rc = -LTFS_NO_XATTR; + break; } } } } - if(rc == DEVICE_GOOD) { + if (rc == DEVICE_GOOD) { /* The buf allocated here shall be freed in xattr_get_virtual() */ rc = asprintf(buf, "%2.2f", softc->acq_loss_w); if (rc < 0) { rc = -LTFS_NO_MEMORY; ltfsmsg(LTFS_INFO, 31268I, "getting active CQ loss write"); - } - else + } else rc = DEVICE_GOOD; } else softc->fetch_sec_acq_loss_w = 0; @@ -3224,14 +3143,12 @@ int camtape_set_xattr(void *device, const char *name, const char *buf, size_t si char *null_terminated; struct camtape_data *softc = (struct camtape_data *)device; - - if (!size) - return -LTFS_BAD_ARG; + if (!size) return -LTFS_BAD_ARG; ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_SETXATTR)); null_terminated = malloc(size + 1); - if (! null_terminated) { + if (!null_terminated) { ltfsmsg(LTFS_ERR, 10001E, "lin_tape_ibmtape_set_xattr: null_term"); ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_SETXATTR)); return -LTFS_NO_MEMORY; @@ -3239,15 +3156,15 @@ int camtape_set_xattr(void *device, const char *name, const char *buf, size_t si memcpy(null_terminated, buf, size); null_terminated[size] = '\0'; - if (! strcmp(name, "ltfs.vendor.IBM.forceErrorWrite")) { + if (!strcmp(name, "ltfs.vendor.IBM.forceErrorWrite")) { softc->force_writeperm = strtoull(null_terminated, NULL, 0); if (softc->force_writeperm && softc->force_writeperm < THRESHOLD_FORCE_WRITE_NO_WRITE) softc->force_writeperm = THRESHOLD_FORCE_WRITE_NO_WRITE; rc = DEVICE_GOOD; - } else if (! strcmp(name, "ltfs.vendor.IBM.forceErrorType")) { + } else if (!strcmp(name, "ltfs.vendor.IBM.forceErrorType")) { softc->force_errortype = strtol(null_terminated, NULL, 0); rc = DEVICE_GOOD; - } else if (! strcmp(name, "ltfs.vendor.IBM.forceErrorRead")) { + } else if (!strcmp(name, "ltfs.vendor.IBM.forceErrorRead")) { softc->force_readperm = strtoull(null_terminated, NULL, 0); softc->read_counter = 0; rc = DEVICE_GOOD; @@ -3276,19 +3193,19 @@ char *camtape_enc_state_to_str(camtape_encryption_state encryption_state) char *state = NULL; switch (encryption_state) { - case CT_ENC_STATE_OFF: - state = "Off"; - break; - case CT_ENC_STATE_ON: - state = "On"; - break; - case CT_ENC_STATE_NA: - state = "N/A"; - break; - case CT_ENC_STATE_UNKNOWN: - default: - state = "Unknown"; - break; + case CT_ENC_STATE_OFF: + state = "Off"; + break; + case CT_ENC_STATE_ON: + state = "On"; + break; + case CT_ENC_STATE_NA: + state = "N/A"; + break; + case CT_ENC_STATE_UNKNOWN: + default: + state = "Unknown"; + break; } return (state); @@ -3299,39 +3216,38 @@ char *camtape_enc_method_to_str(camtape_encryption_method encryption_method) char *method = NULL; switch (encryption_method) { - case CT_ENC_METHOD_NONE: - method = "None"; - break; - case CT_ENC_METHOD_SYSTEM: - method = "System"; - break; - case CT_ENC_METHOD_CONTROLLER: - method = "Controller"; - break; - case CT_ENC_METHOD_APPLICATION: - method = "Application"; - break; - case CT_ENC_METHOD_LIBRARY: - method = "Library"; - break; - case CT_ENC_METHOD_INTERNAL: - method = "Internal"; - break; - case CT_ENC_METHOD_CUSTOM: - method = "Custom"; - break; - default: - method = "Unknown"; - break; + case CT_ENC_METHOD_NONE: + method = "None"; + break; + case CT_ENC_METHOD_SYSTEM: + method = "System"; + break; + case CT_ENC_METHOD_CONTROLLER: + method = "Controller"; + break; + case CT_ENC_METHOD_APPLICATION: + method = "Application"; + break; + case CT_ENC_METHOD_LIBRARY: + method = "Library"; + break; + case CT_ENC_METHOD_INTERNAL: + method = "Internal"; + break; + case CT_ENC_METHOD_CUSTOM: + method = "Custom"; + break; + default: + method = "Unknown"; + break; } return (method); } -static void ltfsmsg_encryption_state(const struct camtape_encryption_status * const es, - const bool set) +static void ltfsmsg_encryption_state(const struct camtape_encryption_status *const es, const bool set) { - char s[128] = {'\0'}; + char s[128] = { '\0' }; char *method = NULL; char *state = NULL; @@ -3339,14 +3255,22 @@ static void ltfsmsg_encryption_state(const struct camtape_encryption_status * co state = camtape_enc_state_to_str(es->encryption_state); - sprintf(s, "Capable = %d, Method = %s(%d), State = %s(%d)", es->encryption_capable, - method, es->encryption_method, state, es->encryption_state); + sprintf(s, + "Capable = %d, Method = %s(%d), State = %s(%d)", + es->encryption_capable, + method, + es->encryption_method, + state, + es->encryption_state); ltfsmsg(LTFS_DEBUG, 31392D, set ? "set encryption state:" : "get encryption state:", s); } -static int camtape_get_encryption_state(void *device, struct camtape_encryption_status * const p, - uint8_t *rwc_mode_buf, size_t rwc_buf_len, size_t *rwc_fill_len) +static int camtape_get_encryption_state(void *device, + struct camtape_encryption_status *const p, + uint8_t *rwc_mode_buf, + size_t rwc_buf_len, + size_t *rwc_fill_len) { int rc = DEVICE_GOOD; struct camtape_encryption_status es; @@ -3373,8 +3297,7 @@ static int camtape_get_encryption_state(void *device, struct camtape_encryption_ * also always assumes that the function issues a 10 byte mode sense. */ rc = camtape_modesense(device, CT_ISE_PAGE_CODE, TC_MP_PC_CURRENT, 0x00, buf, buf_size); - if (rc != DEVICE_GOOD) - goto bailout; + if (rc != DEVICE_GOOD) goto bailout; mode_hdr = (struct scsi_mode_header_10 *)buf; ise_page = (struct camtape_ibm_initiator_spec_ext_page *)find_mode_page_10(mode_hdr); @@ -3398,8 +3321,7 @@ static int camtape_get_encryption_state(void *device, struct camtape_encryption_ rc = camtape_modesense(device, CT_RWC_PAGE_CODE, TC_MP_PC_CURRENT, 0x00, buf, buf_size); - if (rc != DEVICE_GOOD) - goto bailout; + if (rc != DEVICE_GOOD) goto bailout; /* * Give the caller a copy of the buffer if he requested it. @@ -3422,33 +3344,32 @@ static int camtape_get_encryption_state(void *device, struct camtape_encryption_ */ es.encryption_method = rwc_page->encryption_method; switch (rwc_page->encryption_method) { - case CT_RWC_ENC_METHOD_NONE: - es.encryption_state = CT_ENC_STATE_OFF; - break; - case CT_RWC_ENC_METHOD_SYSTEM: - es.encryption_state = rwc_page->encryption_state & CT_RWC_ENCRYPTION_STATE_MASK; - break; - case CT_RWC_ENC_METHOD_APPLICATION: - es.encryption_state = rwc_page->encryption_state & CT_RWC_ENCRYPTION_STATE_MASK; - break; - case CT_RWC_ENC_METHOD_LIBRARY: - case CT_RWC_ENC_METHOD_CUSTOM: - case CT_RWC_ENC_METHOD_INTERNAL: - case CT_RWC_ENC_METHOD_CONTROLLER: - es.encryption_state = CT_ENC_STATE_NA; - break; - default: - es.encryption_method = CT_ENC_METHOD_UNKNOWN; - es.encryption_state = CT_ENC_STATE_NA; - break; + case CT_RWC_ENC_METHOD_NONE: + es.encryption_state = CT_ENC_STATE_OFF; + break; + case CT_RWC_ENC_METHOD_SYSTEM: + es.encryption_state = rwc_page->encryption_state & CT_RWC_ENCRYPTION_STATE_MASK; + break; + case CT_RWC_ENC_METHOD_APPLICATION: + es.encryption_state = rwc_page->encryption_state & CT_RWC_ENCRYPTION_STATE_MASK; + break; + case CT_RWC_ENC_METHOD_LIBRARY: + case CT_RWC_ENC_METHOD_CUSTOM: + case CT_RWC_ENC_METHOD_INTERNAL: + case CT_RWC_ENC_METHOD_CONTROLLER: + es.encryption_state = CT_ENC_STATE_NA; + break; + default: + es.encryption_method = CT_ENC_METHOD_UNKNOWN; + es.encryption_state = CT_ENC_STATE_NA; + break; } bailout: ltfsmsg_encryption_state(&es, false); - if (rc != DEVICE_GOOD) - camtape_process_errors(device, rc, msg, "get encryption state", true); + if (rc != DEVICE_GOOD) camtape_process_errors(device, rc, msg, "get encryption state", true); if (p != NULL) { if (rc == DEVICE_GOOD) @@ -3457,14 +3378,12 @@ static int camtape_get_encryption_state(void *device, struct camtape_encryption_ memset(p, 0, sizeof(es)); } - if (buf != NULL) - free(buf); + if (buf != NULL) free(buf); return rc; } -static int camtape_set_encryption_state(struct camtape_data *softc, - camtape_encryption_state encryption_state) +static int camtape_set_encryption_state(struct camtape_data *softc, camtape_encryption_state encryption_state) { int rc = DEVICE_GOOD; struct camtape_encryption_status es; @@ -3482,8 +3401,7 @@ static int camtape_set_encryption_state(struct camtape_data *softc, memset(buf, 0, buf_size); rc = camtape_get_encryption_state(softc, &es, buf, buf_size, &buf_fill_len); - if (rc != DEVICE_GOOD) - goto bailout; + if (rc != DEVICE_GOOD) goto bailout; if (es.encryption_capable == CT_ENC_NOT_CAPABLE) { rc = -EDEV_INVALID_ARG; @@ -3517,19 +3435,29 @@ static int camtape_set_encryption_state(struct camtape_data *softc, ltfsmsg_encryption_state(&es, true); } - if (buf != NULL) - free(buf); + if (buf != NULL) free(buf); return rc; } -static void ltfsmsg_keyalias(const char * const title, const unsigned char * const keyalias) +static void ltfsmsg_keyalias(const char *const title, const unsigned char *const keyalias) { - char s[128] = {'\0'}; + char s[128] = { '\0' }; if (keyalias) - sprintf(s, "keyalias = %c%c%c%02X%02X%02X%02X%02X%02X%02X%02X%02X", keyalias[0], - keyalias[1], keyalias[2], keyalias[3], keyalias[4], keyalias[5], keyalias[6], - keyalias[7], keyalias[8], keyalias[9], keyalias[10], keyalias[11]); + sprintf(s, + "keyalias = %c%c%c%02X%02X%02X%02X%02X%02X%02X%02X%02X", + keyalias[0], + keyalias[1], + keyalias[2], + keyalias[3], + keyalias[4], + keyalias[5], + keyalias[6], + keyalias[7], + keyalias[8], + keyalias[9], + keyalias[10], + keyalias[11]); else sprintf(s, "keyalias: NULL"); @@ -3541,11 +3469,11 @@ static void ltfsmsg_keyalias(const char * const title, const unsigned char * con */ static bool is_ame(struct camtape_data *softc) { - unsigned char buf[TC_MP_READ_WRITE_CTRL_SIZE] = {0}; + unsigned char buf[TC_MP_READ_WRITE_CTRL_SIZE] = { 0 }; const int rc = camtape_modesense(softc, TC_MP_READ_WRITE_CTRL, TC_MP_PC_CURRENT, 0, buf, sizeof(buf)); if (rc != 0) { - char message[100] = {0}; + char message[100] = { 0 }; sprintf(message, "failed to get MP %02Xh (%d)", TC_MP_READ_WRITE_CTRL, rc); ltfsmsg(LTFS_DEBUG, 31392D, __FUNCTION__, message); @@ -3553,7 +3481,7 @@ static bool is_ame(struct camtape_data *softc) } else { struct scsi_mode_header_10 *mode_hdr; struct camtape_ibm_rw_control_page *rwc_page; - char message[100] = {0}; + char message[100] = { 0 }; char *method = NULL; mode_hdr = (struct scsi_mode_header_10 *)buf; @@ -3573,7 +3501,6 @@ static bool is_ame(struct camtape_data *softc) static int is_encryption_capable(struct camtape_data *softc) { - /* * XXX KDM why does this only support encryption, or at least Application Managed Encryption, * on LTO drives and not on TS drives? @@ -3583,8 +3510,7 @@ static int is_encryption_capable(struct camtape_data *softc) return -EDEV_INTERNAL_ERROR; } - if (! is_ame(softc)) - return -EDEV_INTERNAL_ERROR; + if (!is_ame(softc)) return -EDEV_INTERNAL_ERROR; return DEVICE_GOOD; } @@ -3595,7 +3521,9 @@ static int is_encryption_capable(struct camtape_data *softc) * functionality. The only obvious parameters are the key and key alias/key index. */ static void camtape_fill_enc_subpage(struct camtape_ibm_enc_param_subpage *enc_sp, - int key_index_set, const uint8_t *key, const uint8_t *key_index) + int key_index_set, + const uint8_t *key, + const uint8_t *key_index) { int subpage_length; @@ -3627,22 +3555,21 @@ static void camtape_fill_enc_subpage(struct camtape_ibm_enc_param_subpage *enc_s enc_sp->byte124 = CT_ENC_PARAM_BYTE_124_VALUE; if (key_index_set != 0) { enc_sp->ki_or_not.ki_is_set.byte127 = CT_ENC_PARAM_BYTE127_KI_VALUE; - memcpy(enc_sp->ki_or_not.ki_is_set.key_index, key_index, - sizeof(enc_sp->ki_or_not.ki_is_set.key_index)); + memcpy(enc_sp->ki_or_not.ki_is_set.key_index, key_index, sizeof(enc_sp->ki_or_not.ki_is_set.key_index)); enc_sp->ki_or_not.ki_is_set.byte144 = CT_ENC_PARAM_BYTE144_KI_VALUE; } else { enc_sp->ki_or_not.ki_not_set.byte132 = CT_ENC_PARAM_BYTE132_NO_KI_VALUE; } } -int camtape_set_key(void *device, const unsigned char * const keyalias, const unsigned char * const key) +int camtape_set_key(void *device, const unsigned char *const keyalias, const unsigned char *const key) { struct camtape_data *softc = (struct camtape_data *)device; camtape_encryption_state encryption_state = CT_ENC_STATE_OFF; struct scsi_mode_header_10 *mode_hdr; struct camtape_ibm_enc_param_subpage *enc_sp; - const char * const title = "set key:"; - struct data_key dk = {{0}}; + const char *const title = "set key:"; + struct data_key dk = { { 0 } }; uint8_t *buf = NULL; size_t bufsize = MAX_UINT16; char *msg = NULL; @@ -3680,11 +3607,10 @@ int camtape_set_key(void *device, const unsigned char * const keyalias, const un ltfsmsg_keyalias(title, keyalias); - rc = camtape_modesense(device, CT_ENC_PARAM_SUBPAGE_PAGE_CODE, TC_MP_PC_CURRENT, - CT_ENC_PARAM_SUBPAGE_CODE, buf, bufsize); + rc = camtape_modesense( + device, CT_ENC_PARAM_SUBPAGE_PAGE_CODE, TC_MP_PC_CURRENT, CT_ENC_PARAM_SUBPAGE_CODE, buf, bufsize); - if (rc != DEVICE_GOOD) - goto bailout; + if (rc != DEVICE_GOOD) goto bailout; mode_hdr = (struct scsi_mode_header_10 *)buf; enc_sp = (struct camtape_ibm_enc_param_subpage *)find_mode_page_10(mode_hdr); @@ -3696,38 +3622,35 @@ int camtape_set_key(void *device, const unsigned char * const keyalias, const un rc = camtape_modeselect(device, buf, bufsize); bailout: - if (rc != DEVICE_GOOD) - camtape_process_errors(device, rc, msg, "set data key", true); + if (rc != DEVICE_GOOD) camtape_process_errors(device, rc, msg, "set data key", true); - if (buf != NULL) - free(buf); + if (buf != NULL) free(buf); ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_SETKEY)); return rc; } -static void show_hex_dump(const char * const title, const unsigned char * const buf, const uint size) +static void show_hex_dump(const char *const title, const unsigned char *const buf, const uint size) { /* * " 1 2 3 4 5 6 7 8" * "12345678901234567890123456789012345678901234567890123456789012345678901234567890" * "xxxxxx 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF\n" < 100 */ - char * const s = calloc((size / 0x10 + 1) * 100, sizeof(char)); + char *const s = calloc((size / 0x10 + 1) * 100, sizeof(char)); char *p = s; uint i = 0; int j = 0; int k = 0; - if (p == NULL) - return; + if (p == NULL) return; for (i = 0; i < size; ++i) { if (i % 0x10 == 0) { if (i) { for (j = 0x10; 0 < j; --j) { - p += sprintf(p, "%c", isprint(buf[i-j]) ? buf[i-j] : '.'); + p += sprintf(p, "%c", isprint(buf[i - j]) ? buf[i - j] : '.'); } } p += sprintf(p, "\n%06X ", i); @@ -3738,7 +3661,7 @@ static void show_hex_dump(const char * const title, const unsigned char * const p += sprintf(p, " %s", (i + k) % 8 == 7 ? " " : ""); } for (j = 0x10 - k; 0 < j; --j) { - p += sprintf(p, "%c", isprint(buf[i-j]) ? buf[i-j] : '.'); + p += sprintf(p, "%c", isprint(buf[i - j]) ? buf[i - j] : '.'); } ltfsmsg(LTFS_DEBUG, 31392D, title, s); @@ -3784,13 +3707,12 @@ int camtape_get_keyalias(void *device, unsigned char **keyalias) /* This is not * 2nd loop: Get full data in the page. */ for (i = 0; i < 2; ++i) { - /* Prepare Data Buffer */ if (buf != NULL) { free(buf); buf = NULL; } - buf = (uint8_t *) calloc(buffer_length, sizeof(uint8_t)); + buf = (uint8_t *)calloc(buffer_length, sizeof(uint8_t)); if (buf == NULL) { ltfsmsg(LTFS_ERR, 10001E, "camtape_get_keyalias: data buffer"); rc = -EDEV_NO_MEMORY; @@ -3798,16 +3720,16 @@ int camtape_get_keyalias(void *device, unsigned char **keyalias) /* This is not } scsi_security_protocol_in(&ccb->csio, - /*retries*/ 1, - /*cbfcnp*/ NULL, - /*tag_action*/ MSG_SIMPLE_Q_TAG, - /*security_protocol*/ SPI_PROT_TAPE_DATA_ENC, - /*sps*/ TDE_NEXT_BLOCK_ENC_STATUS_PAGE, - /*byte4*/ 0, - /*data_ptr*/ buf, - /*dxfer_len*/ buffer_length, - /*sense_len*/ SSD_FULL_SIZE, - /*timeout*/ timeout); + /*retries*/ 1, + /*cbfcnp*/ NULL, + /*tag_action*/ MSG_SIMPLE_Q_TAG, + /*security_protocol*/ SPI_PROT_TAPE_DATA_ENC, + /*sps*/ TDE_NEXT_BLOCK_ENC_STATUS_PAGE, + /*byte4*/ 0, + /*data_ptr*/ buf, + /*dxfer_len*/ buffer_length, + /*sense_len*/ SSD_FULL_SIZE, + /*timeout*/ timeout); ccb->ccb_h.flags |= CAM_DEV_QFRZDIS | CAM_PASS_ERR_RECOVER; @@ -3825,62 +3747,58 @@ int camtape_get_keyalias(void *device, unsigned char **keyalias) /* This is not enc_status = status_page->status & TDE_NBES_ENC_STATUS_MASK; switch (enc_status) { - case TDE_NBES_ENC_ALG_NOT_SUPPORTED: - case TDE_NBES_ENC_SUPPORTED_ALG: - case TDE_NBES_ENC_NO_KEY: { - struct tde_data_enc_desc *desc; - uint8_t *next_desc; + case TDE_NBES_ENC_ALG_NOT_SUPPORTED: + case TDE_NBES_ENC_SUPPORTED_ALG: + case TDE_NBES_ENC_NO_KEY: { + struct tde_data_enc_desc *desc; + uint8_t *next_desc; - for (desc = (struct tde_data_enc_desc *)&status_page[1]; - ((((uint8_t *)desc - buf) + 4) <= buffer_length); - desc = (struct tde_data_enc_desc *)next_desc) { - uint32_t key_length; + for (desc = (struct tde_data_enc_desc *)&status_page[1]; ((((uint8_t *)desc - buf) + 4) <= buffer_length); + desc = (struct tde_data_enc_desc *)next_desc) { + uint32_t key_length; - next_desc = (uint8_t *)desc; - key_length = scsi_2btoul(desc->key_desc_length); - next_desc += key_length + __offsetof(struct tde_data_enc_desc, key_desc); + next_desc = (uint8_t *)desc; + key_length = scsi_2btoul(desc->key_desc_length); + next_desc += key_length + __offsetof(struct tde_data_enc_desc, key_desc); - /* + /* * We're looking for the Authenticated Key-Associated Data descriptor. */ - if (desc->key_desc_type != TDE_KEY_DESC_A_KAD) - continue; + if (desc->key_desc_type != TDE_KEY_DESC_A_KAD) continue; - /* + /* * Make sure that we aren't going off the end of the buffer. */ - if ((next_desc - buf) > buffer_length) - break; + if ((next_desc - buf) > buffer_length) break; - /* + /* * Copy the key into the softc and let the caller know we got it. */ - memcpy(softc->dki, desc->key_desc, MIN(key_length, sizeof(softc->dki))); - *keyalias = softc->dki; + memcpy(softc->dki, desc->key_desc, MIN(key_length, sizeof(softc->dki))); + *keyalias = softc->dki; + break; + } break; } - break; - } - default: - break; + default: + break; } - const char * const title = "get key-alias:"; + const char *const title = "get key-alias:"; ltfsmsg_keyalias(title, softc->dki); bailout: - if (ccb != NULL) - cam_freeccb(ccb); - if (buf != NULL) - free(buf); + if (ccb != NULL) cam_freeccb(ccb); + if (buf != NULL) free(buf); ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_GETKEYALIAS)); return rc; } -typedef enum { +typedef enum +{ CT_PP_LBP_R, CT_PP_LBP_W, CT_PP_RBDP, @@ -3888,21 +3806,18 @@ typedef enum { CT_PP_PROT_METHOD } ct_protect_param; -struct ct_protect_info { +struct ct_protect_info +{ const char *name; struct mt_status_entry *entry; uint32_t value; } ct_protect_list[] = { - { "lbp_r", NULL, 0 }, - { "lbp_w", NULL, 0 }, - { "rbdp", NULL, 0 }, - { "pi_length", NULL, 0 }, - { "prot_method", NULL, 0 } + { "lbp_r", NULL, 0 }, { "lbp_w", NULL, 0 }, { "rbdp", NULL, 0 }, { "pi_length", NULL, 0 }, { "prot_method", NULL, 0 } }; -#define CT_NUM_PROTECT_PARAMS (sizeof(ct_protect_list)/sizeof(ct_protect_list[0])) -#define TC_MP_INIT_EXT_LBP_RS (0x40) -#define TC_MP_INIT_EXT_LBP_CRC32C (0x20) +#define CT_NUM_PROTECT_PARAMS (sizeof(ct_protect_list) / sizeof(ct_protect_list[0])) +#define TC_MP_INIT_EXT_LBP_RS (0x40) +#define TC_MP_INIT_EXT_LBP_CRC32C (0x20) int camtape_set_lbp(void *device, bool enable) { @@ -3923,8 +3838,7 @@ int camtape_set_lbp(void *device, bool enable) /* Check logical block protection capability */ rc = camtape_modesense(device, TC_MP_INIT_EXT, TC_MP_PC_CURRENT, 0x00, buf, sizeof(buf)); - if (rc < 0) - return rc; + if (rc < 0) return rc; if (buf[0x12] & TC_MP_INIT_EXT_LBP_CRC32C) lbp_method = CRC32C_CRC; @@ -3936,8 +3850,7 @@ int camtape_set_lbp(void *device, bool enable) */ memset(&mtinfo, 0, sizeof(mtinfo)); rc = camtape_get_mtinfo(softc, &mtinfo, /*params*/ 1, &msg); - if (rc != DEVICE_GOOD) - goto bailout; + if (rc != DEVICE_GOOD) goto bailout; /* * Check to see whether protection is supported. @@ -4003,8 +3916,7 @@ int camtape_set_lbp(void *device, bool enable) goto bailout; } protect_list[i].entry = entry; - snprintf(params[i].value_name, sizeof(params[i].value_name), "%s.%s", MT_PROTECTION_NAME, - protect_list[i].name); + snprintf(params[i].value_name, sizeof(params[i].value_name), "%s.%s", MT_PROTECTION_NAME, protect_list[i].name); params[i].value_type = MT_PARAM_SET_UNSIGNED; params[i].value_len = sizeof(protect_list[i].value); params[i].value.value_unsigned = protect_list[i].value; @@ -4017,8 +3929,11 @@ int camtape_set_lbp(void *device, bool enable) if (ioctl(softc->fd_sa, MTIOCSETLIST, ¶m_list) == -1) { char tmpstr[512]; - snprintf(tmpstr, sizeof(tmpstr), "Error returned from MTIOCSETLIST ioctl to set " - "protection parameters: %s", strerror(errno)); + snprintf(tmpstr, + sizeof(tmpstr), + "Error returned from MTIOCSETLIST ioctl to set " + "protection parameters: %s", + strerror(errno)); msg = strdup(tmpstr); rc = -errno; camtape_process_errors(device, rc, msg, "get lbp", true); @@ -4035,18 +3950,18 @@ int camtape_set_lbp(void *device, bool enable) if (enable) { switch (lbp_method) { - case CRC32C_CRC: - softc->f_crc_enc = crc32c_enc; - softc->f_crc_check = crc32c_check; - break; - case REED_SOLOMON_CRC: - softc->f_crc_enc = rs_gf256_enc; - softc->f_crc_check = rs_gf256_check; - break; - default: - softc->f_crc_enc = NULL; - softc->f_crc_check = NULL; - break; + case CRC32C_CRC: + softc->f_crc_enc = crc32c_enc; + softc->f_crc_check = crc32c_check; + break; + case REED_SOLOMON_CRC: + softc->f_crc_enc = rs_gf256_enc; + softc->f_crc_check = rs_gf256_check; + break; + default: + softc->f_crc_enc = NULL; + softc->f_crc_check = NULL; + break; } ltfsmsg(LTFS_INFO, 31271I); } else { @@ -4059,19 +3974,14 @@ int camtape_set_lbp(void *device, bool enable) return rc; } -int camtape_is_mountable(void *device, const char *barcode, const unsigned char cart_type, - const unsigned char density) +int camtape_is_mountable(void *device, const char *barcode, const unsigned char cart_type, const unsigned char density) { int ret; struct camtape_data *softc = (struct camtape_data *)device; ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_ISMOUNTABLE)); - ret = ibm_tape_is_mountable(softc->drive_type, - barcode, - cart_type, - density, - global_data.strict_drive); + ret = ibm_tape_is_mountable(softc->drive_type, barcode, cart_type, density, global_data.strict_drive); ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_ISMOUNTABLE)); @@ -4083,11 +3993,7 @@ bool camtape_is_readonly(void *device) int ret; struct camtape_data *softc = (struct camtape_data *)device; - ret = ibm_tape_is_mountable(softc->drive_type, - NULL, - softc->cart_type, - softc->density_code, - global_data.strict_drive); + ret = ibm_tape_is_mountable(softc->drive_type, NULL, softc->cart_type, softc->density_code, global_data.strict_drive); if (ret == MEDIUM_READONLY) return true; @@ -4099,13 +4005,12 @@ bool camtape_is_readonly(void *device) int camtape_get_worm_status(void *device, bool *is_worm) { int rc = 0; - struct camtape_data *softc = (struct camtape_data *) device; + struct camtape_data *softc = (struct camtape_data *)device; ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_GETWORMSTAT)); if (softc->loaded) { *is_worm = softc->is_worm; - } - else { + } else { ltfsmsg(LTFS_INFO, 31289I); *is_worm = false; rc = -1; @@ -4115,65 +4020,63 @@ int camtape_get_worm_status(void *device, bool *is_worm) return rc; } -struct tape_ops camtape_drive_handler = { - .open = camtape_open, - .reopen = camtape_reopen, - .close = camtape_close, - .close_raw = camtape_close_raw, - .is_connected = camtape_is_connected, - .inquiry = camtape_inquiry, - .inquiry_page = camtape_inquiry_page, - .test_unit_ready = camtape_test_unit_ready, - .read = camtape_read, - .write = camtape_write, - .writefm = camtape_writefm, - .rewind = camtape_rewind, - .locate = camtape_locate, - .space = camtape_space, - .erase = camtape_erase, - .load = camtape_load, - .unload = camtape_unload, - .readpos = camtape_readpos, - .setcap = camtape_setcap, - .format = camtape_format, - .remaining_capacity = camtape_remaining_capacity, - .logsense = camtape_logsense, - .modesense = camtape_modesense, - .modeselect = camtape_modeselect, - .reserve_unit = camtape_reserve_unit, - .release_unit = camtape_release_unit, - .prevent_medium_removal = camtape_prevent_medium_removal, - .allow_medium_removal = camtape_allow_medium_removal, - .write_attribute = camtape_write_attribute, - .read_attribute = camtape_read_attribute, - .allow_overwrite = camtape_allow_overwrite, - .grao = camtape_grao, - .rrao = camtape_rrao, - // May be command combination - .set_compression = camtape_set_compression, - .set_default = camtape_set_default, - .get_cartridge_health = camtape_get_cartridge_health, - .get_tape_alert = camtape_get_tape_alert, - .clear_tape_alert = camtape_clear_tape_alert, - .get_xattr = camtape_get_xattr, - .set_xattr = camtape_set_xattr, - .get_parameters = camtape_get_parameters, - .get_eod_status = camtape_get_eod_status, - .get_device_list = camtape_get_device_list, - .help_message = camtape_help_message, - .parse_opts = camtape_parse_opts, - .default_device_name = camtape_default_device_name, - .set_key = camtape_set_key, - .get_keyalias = camtape_get_keyalias, - .takedump_drive = camtape_takedump_drive, - .is_mountable = camtape_is_mountable, - .get_worm_status = camtape_get_worm_status, - .get_serialnumber = camtape_get_serialnumber, - .get_info = camtape_get_info, - .set_profiler = camtape_set_profiler, - .get_next_block_to_xfer = camtape_get_next_block_to_xfer, - .is_readonly = camtape_is_readonly -}; +struct tape_ops camtape_drive_handler = { .open = camtape_open, + .reopen = camtape_reopen, + .close = camtape_close, + .close_raw = camtape_close_raw, + .is_connected = camtape_is_connected, + .inquiry = camtape_inquiry, + .inquiry_page = camtape_inquiry_page, + .test_unit_ready = camtape_test_unit_ready, + .read = camtape_read, + .write = camtape_write, + .writefm = camtape_writefm, + .rewind = camtape_rewind, + .locate = camtape_locate, + .space = camtape_space, + .erase = camtape_erase, + .load = camtape_load, + .unload = camtape_unload, + .readpos = camtape_readpos, + .setcap = camtape_setcap, + .format = camtape_format, + .remaining_capacity = camtape_remaining_capacity, + .logsense = camtape_logsense, + .modesense = camtape_modesense, + .modeselect = camtape_modeselect, + .reserve_unit = camtape_reserve_unit, + .release_unit = camtape_release_unit, + .prevent_medium_removal = camtape_prevent_medium_removal, + .allow_medium_removal = camtape_allow_medium_removal, + .write_attribute = camtape_write_attribute, + .read_attribute = camtape_read_attribute, + .allow_overwrite = camtape_allow_overwrite, + .grao = camtape_grao, + .rrao = camtape_rrao, + // May be command combination + .set_compression = camtape_set_compression, + .set_default = camtape_set_default, + .get_cartridge_health = camtape_get_cartridge_health, + .get_tape_alert = camtape_get_tape_alert, + .clear_tape_alert = camtape_clear_tape_alert, + .get_xattr = camtape_get_xattr, + .set_xattr = camtape_set_xattr, + .get_parameters = camtape_get_parameters, + .get_eod_status = camtape_get_eod_status, + .get_device_list = camtape_get_device_list, + .help_message = camtape_help_message, + .parse_opts = camtape_parse_opts, + .default_device_name = camtape_default_device_name, + .set_key = camtape_set_key, + .get_keyalias = camtape_get_keyalias, + .takedump_drive = camtape_takedump_drive, + .is_mountable = camtape_is_mountable, + .get_worm_status = camtape_get_worm_status, + .get_serialnumber = camtape_get_serialnumber, + .get_info = camtape_get_info, + .set_profiler = camtape_set_profiler, + .get_next_block_to_xfer = camtape_get_next_block_to_xfer, + .is_readonly = camtape_is_readonly }; struct tape_ops *tape_dev_get_ops(void) { @@ -4213,7 +4116,7 @@ int open_sa_pass(struct camtape_data *softc, const char *saDeviceName) return -EDEV_DEVICE_UNOPENABLE; } - char passDeviceName[MAXPATHLEN+1]; + char passDeviceName[MAXPATHLEN + 1]; snprintf(passDeviceName, MAXPATHLEN, "/dev/%s%d", cd_pass->device_name, cd_pass->dev_unit_num); ret = open_sa_device(softc, saDeviceName); @@ -4228,7 +4131,7 @@ int open_sa_pass(struct camtape_data *softc, const char *saDeviceName) return 0; } -int open_sa_device(struct camtape_data *softc, const char* saDeviceName) +int open_sa_device(struct camtape_data *softc, const char *saDeviceName) { int ret = 0; diff --git a/src/tape_drivers/generic/file/filedebug_conf_tc.c b/src/tape_drivers/generic/file/filedebug_conf_tc.c index 7abb4ed7..fdc26f24 100644 --- a/src/tape_drivers/generic/file/filedebug_conf_tc.c +++ b/src/tape_drivers/generic/file/filedebug_conf_tc.c @@ -72,27 +72,21 @@ static int _filedebug_tc_write_schema(xmlTextWriterPtr writer, const struct file xml_mktag(xmlTextWriterStartElement(writer, BAD_CAST "filedebug_cartridge_config"), -1); - xml_mktag(xmlTextWriterWriteFormatElement(writer, - BAD_CAST "dummy_io", - "%s", conf->dummy_io ? "true" : "false"), -1); + xml_mktag(xmlTextWriterWriteFormatElement(writer, BAD_CAST "dummy_io", "%s", conf->dummy_io ? "true" : "false"), -1); - xml_mktag(xmlTextWriterWriteFormatElement(writer, - BAD_CAST "emulate_readonly", - "%s", conf->emulate_readonly ? "true" : "false"), -1); + xml_mktag(xmlTextWriterWriteFormatElement( + writer, BAD_CAST "emulate_readonly", "%s", conf->emulate_readonly ? "true" : "false"), + -1); - xml_mktag(xmlTextWriterWriteFormatElement(writer, - BAD_CAST "capacity_mb", - "%"PRIu64, conf->capacity_mb), -1); + xml_mktag(xmlTextWriterWriteFormatElement(writer, BAD_CAST "capacity_mb", "%" PRIu64, conf->capacity_mb), -1); - xml_mktag(xmlTextWriterWriteFormatElement(writer, - BAD_CAST "cart_type", - "%s", ibm_tape_assume_cart_name(conf->cart_type)), -1); + xml_mktag( + xmlTextWriterWriteFormatElement(writer, BAD_CAST "cart_type", "%s", ibm_tape_assume_cart_name(conf->cart_type)), + -1); - xml_mktag(xmlTextWriterWriteFormatElement(writer, - BAD_CAST "density_code", - "%x", conf->density_code), -1); + xml_mktag(xmlTextWriterWriteFormatElement(writer, BAD_CAST "density_code", "%x", conf->density_code), -1); - switch(conf->delay_mode) { + switch (conf->delay_mode) { case DELAY_CALC: xml_mktag(xmlTextWriterWriteFormatElement(writer, BAD_CAST "delay_mode", "Calculate"), -1); break; @@ -104,26 +98,17 @@ static int _filedebug_tc_write_schema(xmlTextWriterPtr writer, const struct file break; } - xml_mktag(xmlTextWriterWriteFormatElement(writer, - BAD_CAST "wraps", - "%"PRIu64, conf->wraps), -1); + xml_mktag(xmlTextWriterWriteFormatElement(writer, BAD_CAST "wraps", "%" PRIu64, conf->wraps), -1); - xml_mktag(xmlTextWriterWriteFormatElement(writer, - BAD_CAST "eot_to_bot_sec", - "%"PRIu64, conf->eot_to_bot_sec), -1); + xml_mktag(xmlTextWriterWriteFormatElement(writer, BAD_CAST "eot_to_bot_sec", "%" PRIu64, conf->eot_to_bot_sec), -1); - xml_mktag(xmlTextWriterWriteFormatElement(writer, - BAD_CAST "change_direction_us", - "%"PRIu64, conf->change_direction_us), -1); + xml_mktag( + xmlTextWriterWriteFormatElement(writer, BAD_CAST "change_direction_us", "%" PRIu64, conf->change_direction_us), + -1); - xml_mktag(xmlTextWriterWriteFormatElement(writer, - BAD_CAST "change_track_us", - "%"PRIu64, conf->change_track_us), -1); - - xml_mktag(xmlTextWriterWriteFormatElement(writer, - BAD_CAST "threading_sec", - "%"PRIu64, conf->threading_sec), -1); + xml_mktag(xmlTextWriterWriteFormatElement(writer, BAD_CAST "change_track_us", "%" PRIu64, conf->change_track_us), -1); + xml_mktag(xmlTextWriterWriteFormatElement(writer, BAD_CAST "threading_sec", "%" PRIu64, conf->threading_sec), -1); xml_mktag(xmlTextWriterEndElement(writer), -1); @@ -143,7 +128,7 @@ int filedebug_conf_tc_write_xml(char *filename, const struct filedebug_conf_tc * /* Create XML writer. */ writer = xmlNewTextWriterFilename(filename, 0); - if (! writer) { + if (!writer) { ltfsmsg(LTFS_ERR, 30152E); return -1; } @@ -166,8 +151,7 @@ static int _filedebug_parser_init(xmlTextReaderPtr reader, const char *top_name) const char *name, *encoding; int type; - if (xml_next_tag(reader, "", &name, &type) < 0) - return -1; + if (xml_next_tag(reader, "", &name, &type) < 0) return -1; if (strcmp(name, top_name)) { ltfsmsg(LTFS_ERR, 30155E, name); return -1; @@ -175,7 +159,7 @@ static int _filedebug_parser_init(xmlTextReaderPtr reader, const char *top_name) /* reject this XML file if it isn't UTF-8 */ encoding = (const char *)xmlTextReaderConstEncoding(reader); - if (! encoding || strcmp(encoding, "UTF-8")) { + if (!encoding || strcmp(encoding, "UTF-8")) { ltfsmsg(LTFS_ERR, 30156E, encoding); return -1; } @@ -191,30 +175,26 @@ static int _filedebug_tc_parse_schema(xmlTextReaderPtr reader, struct filedebug_ /* start the parser: find top-level "index" tag, check version and encoding */ ret = _filedebug_parser_init(reader, parent_tag); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse index file contents */ while (true) { get_next_tag(); - if (! strcmp(name, "dummy_io")) { + if (!strcmp(name, "dummy_io")) { get_tag_text(); - if (xml_parse_bool(&conf->dummy_io, value) < 0) - return -1; + if (xml_parse_bool(&conf->dummy_io, value) < 0) return -1; check_tag_end("dummy_io"); - } else if (! strcmp(name, "emulate_readonly")) { + } else if (!strcmp(name, "emulate_readonly")) { get_tag_text(); - if (xml_parse_bool(&conf->emulate_readonly, value) < 0) - return -1; + if (xml_parse_bool(&conf->emulate_readonly, value) < 0) return -1; check_tag_end("emulate_readonly"); - } else if (! strcmp(name, "capacity_mb")) { + } else if (!strcmp(name, "capacity_mb")) { get_tag_text(); - if (xml_parse_ull(&value_ll, value) < 0) - return -1; + if (xml_parse_ull(&value_ll, value) < 0) return -1; if (value_ll > 0) conf->capacity_mb = value_ll; @@ -223,20 +203,19 @@ static int _filedebug_tc_parse_schema(xmlTextReaderPtr reader, struct filedebug_ check_tag_end("capacity_mb"); - } else if (! strcmp(name, "cart_type")) { + } else if (!strcmp(name, "cart_type")) { get_tag_text(); conf->cart_type = ibm_tape_assume_cart_type(value); check_tag_end("cart_type"); - } else if (! strcmp(name, "density_code")) { + } else if (!strcmp(name, "density_code")) { get_tag_text(); - if (xml_parse_xll(&value_ll, value) < 0) - return -1; + if (xml_parse_xll(&value_ll, value) < 0) return -1; conf->density_code = (char)value_ll; check_tag_end("density_code"); - } else if (! strcmp(name, "delay_mode")) { + } else if (!strcmp(name, "delay_mode")) { get_tag_text(); if (!strcmp(value, "Calculate")) conf->delay_mode = DELAY_CALC; @@ -247,61 +226,55 @@ static int _filedebug_tc_parse_schema(xmlTextReaderPtr reader, struct filedebug_ check_tag_end("delay_mode"); - } else if (! strcmp(name, "wraps")) { + } else if (!strcmp(name, "wraps")) { get_tag_text(); - if (xml_parse_ull(&value_ll, value) < 0) - return -1; + if (xml_parse_ull(&value_ll, value) < 0) return -1; if (value_ll > 0) conf->wraps = value_ll; else conf->wraps = DEFAULT_WRAPS; - } else if (! strcmp(name, "eot_to_bot_sec")) { + } else if (!strcmp(name, "eot_to_bot_sec")) { get_tag_text(); - if (xml_parse_ull(&value_ll, value) < 0) - return -1; + if (xml_parse_ull(&value_ll, value) < 0) return -1; if (value_ll > 0) conf->eot_to_bot_sec = value_ll; else conf->eot_to_bot_sec = DEFAULT_EOT_TO_BOT; - } else if (! strcmp(name, "change_direction_us")) { + } else if (!strcmp(name, "change_direction_us")) { get_tag_text(); - if (xml_parse_ull(&value_ll, value) < 0) - return -1; + if (xml_parse_ull(&value_ll, value) < 0) return -1; if (value_ll > 0) conf->change_direction_us = value_ll; else conf->change_direction_us = DEFAULT_CHANGE_DIRECTION; - } else if (! strcmp(name, "change_track_us")) { + } else if (!strcmp(name, "change_track_us")) { get_tag_text(); - if (xml_parse_ull(&value_ll, value) < 0) - return -1; + if (xml_parse_ull(&value_ll, value) < 0) return -1; if (value_ll > 0) conf->change_track_us = value_ll; else conf->change_track_us = DEFAULT_CHANGE_TRACK; - } else if (! strcmp(name, "threading_sec")) { + } else if (!strcmp(name, "threading_sec")) { get_tag_text(); - if (xml_parse_ull(&value_ll, value) < 0) - return -1; + if (xml_parse_ull(&value_ll, value) < 0) return -1; if (value_ll > 0) conf->threading_sec = value_ll; else conf->threading_sec = DEFAULT_CHANGE_TRACK; - } } @@ -315,7 +288,7 @@ int filedebug_conf_tc_read_xml(char *filename, struct filedebug_conf_tc *conf) xmlDocPtr doc; reader = xmlReaderForFile(filename, NULL, XML_PARSE_NOERROR | XML_PARSE_NOWARNING); - if (! reader) { + if (!reader) { ltfsmsg(LTFS_ERR, 30157E); return -1; } @@ -328,8 +301,7 @@ int filedebug_conf_tc_read_xml(char *filename, struct filedebug_conf_tc *conf) if (ret < 0) { ltfsmsg(LTFS_ERR, 30158E); } - if (doc) - xmlFreeDoc(doc); + if (doc) xmlFreeDoc(doc); xmlFreeTextReader(reader); return ret; diff --git a/src/tape_drivers/generic/file/filedebug_tc.c b/src/tape_drivers/generic/file/filedebug_tc.c index 615517f0..fcbfc4ab 100644 --- a/src/tape_drivers/generic/file/filedebug_tc.c +++ b/src/tape_drivers/generic/file/filedebug_tc.c @@ -51,41 +51,42 @@ ************************************************************************************* */ #ifdef mingw_PLATFORM -#include "arch/win/win_util.h" +# include "arch/win/win_util.h" #else -#include +# include #endif -#include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include +#include +#include #include +#include +#include +#include +#include +#include +#include -#include #include "libltfs/arch/ltfs_arch_ops.h" +#include #ifdef _WIN32 -char *my_basename(char *path) { +char *my_basename(char *path) +{ char *base = strrchr(path, '\\'); return base ? base + 1 : path; } -char *my_dirname(char *path) { +char *my_dirname(char *path) +{ static char buffer[256]; arch_strcpy_auto(buffer, path); char *last_slash = strrchr(buffer, '\\'); if (last_slash) { *last_slash = '\0'; - } - else { + } else { arch_strcpy_auto(buffer, "."); } return buffer; @@ -97,11 +98,11 @@ char *my_dirname(char *path) { #include "libltfs/ltfs_fuse_version.h" #include -#include "ltfs_copyright.h" -#include "libltfs/ltfslogging.h" #include "libltfs/ltfs_endian.h" -#include "libltfs/tape_ops.h" #include "libltfs/ltfs_error.h" +#include "libltfs/ltfslogging.h" +#include "libltfs/tape_ops.h" +#include "ltfs_copyright.h" #include "tape_drivers/tape_drivers.h" #include "tape_drivers/vendor_compat.h" @@ -109,10 +110,9 @@ char *my_dirname(char *path) { #include "filedebug_conf_tc.h" #ifdef _MSC_VER -volatile char *copyright = LTFS_COPYRIGHT_0"\n"LTFS_COPYRIGHT_1"\n"LTFS_COPYRIGHT_2"\n" \ -LTFS_COPYRIGHT_3"\n"LTFS_COPYRIGHT_4"\n"LTFS_COPYRIGHT_5"\n"; -#endif // !_MSC_VER - +volatile char *copyright = LTFS_COPYRIGHT_0 "\n" LTFS_COPYRIGHT_1 "\n" LTFS_COPYRIGHT_2 "\n" LTFS_COPYRIGHT_3 + "\n" LTFS_COPYRIGHT_4 "\n" LTFS_COPYRIGHT_5 "\n"; +#endif // !_MSC_VER /* Default directory where the emulated tape contents go to */ #ifdef mingw_PLATFORM @@ -122,71 +122,73 @@ const char *filedebug_default_device = "/tmp/ltfs/tape"; #endif #define MAX_PARTITIONS 2 -#define KB (1024) -#define MB (KB * 1024) -#define GB (MB * 1024) +#define KB (1024) +#define MB (KB * 1024) +#define GB (MB * 1024) #define FILE_DEBUG_MAX_BLOCK_SIZE (4 * MB) /* O_BINARY is defined only in MinGW */ #ifndef O_BINARY -#define O_BINARY 0 +# define O_BINARY 0 #endif -#define MISSING_EOD (0xFFFFFFFFFFFFFFFFLL) -#define CARTRIDGE_CONFIG "filedebug_tc_conf.xml" +#define MISSING_EOD (0xFFFFFFFFFFFFFFFFLL) +#define CARTRIDGE_CONFIG "filedebug_tc_conf.xml" /* For drive link feature */ #ifdef mingw_PLATFORM -#define DRIVE_LIST_DIR "ltfs" +# define DRIVE_LIST_DIR "ltfs" #else -#define DRIVE_LIST_DIR "/tmp" +# define DRIVE_LIST_DIR "/tmp" #endif -#define NANOSECONDS(x) ((x) * 1000000000) -#define MICROSECONDS(x) ((x) * 1000000) +#define NANOSECONDS(x) ((x) * 1000000000) +#define MICROSECONDS(x) ((x) * 1000000) /** * Emulator-specific data structures, used in lieu of a file descriptor */ -struct filedebug_data { - int fd; /**< File descriptor to contain the pointer to directory where blocks reside */ - char *dirbase; /**< Base directory for searcing directoty from the pointer */ - char *dirname; /**< Directory where blocks reside */ - bool device_reserved; /**< True when the device has been successfully reserved */ - bool medium_locked; /**< True when preventing medium removal by the user */ - bool null_backend; /**< True when runiing on null backend_mode */ - struct tc_position current_position; /**< Current tape position (partition, block) */ - uint32_t max_block_size; /**< Maximum block size, in bytes */ - bool ready; /**< Is the "tape" loaded? */ - bool is_readonly; /**< Is read-only tape loaded? */ - bool is_worm; /**< Is WORM tape loaded ? */ - bool unsupported_tape; /**< Is supported tape in this drive ? */ - bool unsupported_format; /**< Is supported format in this drive ? */ - uint64_t last_block[MAX_PARTITIONS]; /**< Last positions for all partitions */ - uint64_t eod[MAX_PARTITIONS]; /**< Append positions (1 + last block) for all partitions */ - int partitions; /**< Number of available partitions */ - uint64_t write_pass_prev; /**< Previous write Pass */ - uint64_t write_pass; /**< Current write Pass of LTO drive for consistency check*/ - struct timespec accumulated_delay; /**< How much time has been spent doing seeks */ - unsigned p0_warning; /**< Nonzero to provide early warning on partition 0 */ - unsigned p1_warning; /**< Nonzero to provide early warning on partition 1 */ - unsigned p0_p_warning; /**< Nonzero to provide programmable early warning on partition 0 */ - unsigned p1_p_warning; /**< Nonzero to provide programmable early warning on partition 1 */ - bool clear_by_pc; /**< clear pseudo write perm by partition change */ - uint64_t force_writeperm; /**< pseudo write perm threshold */ - uint64_t force_readperm; /**< pseudo read perm threashold */ - uint64_t write_counter; /**< write call counter for pseudo write perm */ - uint64_t read_counter; /**< read call counter for pseudo write perm */ - int force_errortype; /**< 0 is R/W Perm, otherwise no sense */ - int drive_type; /**< drive type defined by ltfs */ - char *serial_number; /**< Serial number of this dummy tape device */ - struct tc_drive_info info; /**< Device informaton (DUMMY) */ - char *product_id; /**< Product ID of this dummy tape device */ - struct filedebug_conf_tc conf; /**< Bahavior option for this instance */ +struct filedebug_data +{ + int fd; /**< File descriptor to contain the pointer to directory where blocks reside */ + char *dirbase; /**< Base directory for searcing directoty from the pointer */ + char *dirname; /**< Directory where blocks reside */ + bool device_reserved; /**< True when the device has been successfully reserved */ + bool medium_locked; /**< True when preventing medium removal by the user */ + bool null_backend; /**< True when runiing on null backend_mode */ + struct tc_position current_position; /**< Current tape position (partition, block) */ + uint32_t max_block_size; /**< Maximum block size, in bytes */ + bool ready; /**< Is the "tape" loaded? */ + bool is_readonly; /**< Is read-only tape loaded? */ + bool is_worm; /**< Is WORM tape loaded ? */ + bool unsupported_tape; /**< Is supported tape in this drive ? */ + bool unsupported_format; /**< Is supported format in this drive ? */ + uint64_t last_block[MAX_PARTITIONS]; /**< Last positions for all partitions */ + uint64_t eod[MAX_PARTITIONS]; /**< Append positions (1 + last block) for all partitions */ + int partitions; /**< Number of available partitions */ + uint64_t write_pass_prev; /**< Previous write Pass */ + uint64_t write_pass; /**< Current write Pass of LTO drive for consistency check*/ + struct timespec accumulated_delay; /**< How much time has been spent doing seeks */ + unsigned p0_warning; /**< Nonzero to provide early warning on partition 0 */ + unsigned p1_warning; /**< Nonzero to provide early warning on partition 1 */ + unsigned p0_p_warning; /**< Nonzero to provide programmable early warning on partition 0 */ + unsigned p1_p_warning; /**< Nonzero to provide programmable early warning on partition 1 */ + bool clear_by_pc; /**< clear pseudo write perm by partition change */ + uint64_t force_writeperm; /**< pseudo write perm threshold */ + uint64_t force_readperm; /**< pseudo read perm threashold */ + uint64_t write_counter; /**< write call counter for pseudo write perm */ + uint64_t read_counter; /**< read call counter for pseudo write perm */ + int force_errortype; /**< 0 is R/W Perm, otherwise no sense */ + int drive_type; /**< drive type defined by ltfs */ + char *serial_number; /**< Serial number of this dummy tape device */ + struct tc_drive_info info; /**< Device informaton (DUMMY) */ + char *product_id; /**< Product ID of this dummy tape device */ + struct filedebug_conf_tc conf; /**< Bahavior option for this instance */ }; -struct filedebug_global_data { - unsigned strict_drive; /**< Is bar code length checked strictly? */ +struct filedebug_global_data +{ + unsigned strict_drive; /**< Is bar code length checked strictly? */ }; struct filedebug_global_data global_data; @@ -194,9 +196,9 @@ struct filedebug_global_data global_data; /* record suffixes for data block, filemark, EOD indicator */ long original_pid = 0; static const char *rec_suffixes = "RFE"; -#define SUFFIX_RECORD (0) +#define SUFFIX_RECORD (0) #define SUFFIX_FILEMARK (1) -#define SUFFIX_EOD (2) +#define SUFFIX_EOD (2) /* Forward reference */ int filedebug_get_device_list(struct tc_drive_info *buf, int count); @@ -206,24 +208,22 @@ int filedebug_search_eod(struct filedebug_data *state, int partition); int _filedebug_write_eod(struct filedebug_data *state); int _filedebug_check_file(const char *fname); char *_filedebug_make_current_filename(const struct filedebug_data *state, char type); -char *_filedebug_make_filename(const struct filedebug_data *state, - int part, uint64_t pos, char type); +char *_filedebug_make_filename(const struct filedebug_data *state, int part, uint64_t pos, char type); char *_filedebug_make_attrname(const struct filedebug_data *state, int part, int id); int _filedebug_remove_current_record(const struct filedebug_data *state); -int _filedebug_remove_record(const struct filedebug_data *state, - int partition, uint64_t blknum); +int _filedebug_remove_record(const struct filedebug_data *state, int partition, uint64_t blknum); int _filedebug_space_fm(struct filedebug_data *state, uint64_t count, bool back); int _filedebug_space_rec(struct filedebug_data *state, uint64_t count, bool back); int _get_wp(struct filedebug_data *state, uint64_t *wp); int _set_wp(struct filedebug_data *state, uint64_t wp); /* Command-line options recognized by this module */ -#define FILEDEBUG_OPT(templ,offset,value) { templ, offsetof(struct filedebug_global_data, offset), value } +#define FILEDEBUG_OPT(templ, offset, value) { templ, offsetof(struct filedebug_global_data, offset), value } static inline uint64_t calc_p0_cap(struct filedebug_data *state) { /* 5% of total capacity */ - return (state->conf.capacity_mb * 5 /100); + return (state->conf.capacity_mb * 5 / 100); } static inline uint64_t calc_p0_remaining(struct filedebug_data *state) @@ -243,11 +243,9 @@ static inline uint64_t calc_p1_remaining(struct filedebug_data *state) return (calc_p1_cap(state) - state->eod[1] / 2); } -static struct fuse_opt filedebug_opts[] = { - FILEDEBUG_OPT("strict_drive", strict_drive, 1), - FILEDEBUG_OPT("nostrict_drive", strict_drive, 0), - FUSE_OPT_END -}; +static struct fuse_opt filedebug_opts[] = { FILEDEBUG_OPT("strict_drive", strict_drive, 1), + FILEDEBUG_OPT("nostrict_drive", strict_drive, 0), + FUSE_OPT_END }; int null_parser(void *state, const char *arg, int key, struct fuse_args *outargs) { @@ -256,30 +254,27 @@ int null_parser(void *state, const char *arg, int key, struct fuse_args *outargs int filedebug_parse_opts(void *device, void *opt_args) { - struct filedebug_data *state = (struct filedebug_data *) device; - struct fuse_args *args = (struct fuse_args *) opt_args; + struct filedebug_data *state = (struct filedebug_data *)device; + struct fuse_args *args = (struct fuse_args *)opt_args; int ret; /* fuse_opt_parse can handle a NULL device parameter just fine */ ret = fuse_opt_parse(args, state, filedebug_opts, null_parser); - if (ret < 0) - return ret; + if (ret < 0) return ret; return 0; } static void emulate_threading_wait(struct filedebug_data *state) { - if (!state->conf.delay_mode) - return; + if (!state->conf.delay_mode) return; struct timespec t; - t.tv_sec = state->conf.threading_sec; + t.tv_sec = state->conf.threading_sec; t.tv_nsec = 0; /* TODO: Need to handle interrupted sleep */ - if (state->conf.delay_mode == DELAY_EMULATE) - nanosleep(&t, NULL); + if (state->conf.delay_mode == DELAY_EMULATE) nanosleep(&t, NULL); state->accumulated_delay.tv_sec += t.tv_sec; state->accumulated_delay.tv_nsec += t.tv_nsec; @@ -296,28 +291,25 @@ static inline uint64_t calc_wrap(struct filedebug_data *state, struct tc_positio uint64_t wrap = pos->block / blocks_per_wrap; /* 2 wraps for partition 0, 2 guard wraps, other wraps are for partition 1 */ - if (pos->partition) - wrap += 4; + if (pos->partition) wrap += 4; return wrap; } static void emulate_seek_wait(struct filedebug_data *state, struct tc_position *dest) { - if (!state->conf.delay_mode) - return; + if (!state->conf.delay_mode) return; uint64_t blocks_per_wrap = (state->conf.capacity_mb / state->conf.wraps) * 2; uint64_t current_wrap = calc_wrap(state, &state->current_position); - uint64_t current_dist_from_bot = current_wrap % 2 == 0 ? - state->current_position.block % blocks_per_wrap : - blocks_per_wrap - (state->current_position.block % blocks_per_wrap); + uint64_t current_dist_from_bot = current_wrap % 2 == 0 + ? state->current_position.block % blocks_per_wrap + : blocks_per_wrap - (state->current_position.block % blocks_per_wrap); uint64_t target_wrap = calc_wrap(state, dest); - uint64_t target_dist_from_bot = target_wrap % 2 == 0 ? - dest->block % blocks_per_wrap : - blocks_per_wrap - (dest->block % blocks_per_wrap); + uint64_t target_dist_from_bot = + target_wrap % 2 == 0 ? dest->block % blocks_per_wrap : blocks_per_wrap - (dest->block % blocks_per_wrap); uint64_t distance; if (target_dist_from_bot > current_dist_from_bot) @@ -325,7 +317,7 @@ static void emulate_seek_wait(struct filedebug_data *state, struct tc_position * else distance = current_dist_from_bot - target_dist_from_bot; - float cost = ((float) state->conf.eot_to_bot_sec / blocks_per_wrap) * (distance-1.0); + float cost = ((float)state->conf.eot_to_bot_sec / blocks_per_wrap) * (distance - 1.0); time_t delay_us = 0; if (dest->partition != state->current_position.partition) { @@ -355,12 +347,11 @@ static void emulate_seek_wait(struct filedebug_data *state, struct tc_position * if (delay_us) { struct timespec t; - t.tv_sec = (delay_us / MICROSECONDS(1)); + t.tv_sec = (delay_us / MICROSECONDS(1)); t.tv_nsec = (delay_us % MICROSECONDS(1)) * 1000; /* TODO: Need to handle interrupted sleep */ - if (state->conf.delay_mode == DELAY_EMULATE) - nanosleep(&t, NULL); + if (state->conf.delay_mode == DELAY_EMULATE) nanosleep(&t, NULL); state->accumulated_delay.tv_sec += t.tv_sec; state->accumulated_delay.tv_nsec += t.tv_nsec; @@ -375,9 +366,9 @@ static void emulate_load_wait(struct filedebug_data *state) { struct tc_position dest; - dest.block = 0; - dest.filemarks = 0; - dest.partition = 0; + dest.block = 0; + dest.filemarks = 0; + dest.partition = 0; dest.early_warning = false; dest.programmable_early_warning = false; @@ -388,9 +379,9 @@ static void emulate_rewind_wait(struct filedebug_data *state) { struct tc_position dest; - dest.block = 0; - dest.filemarks = 0; - dest.partition = state->current_position.partition; + dest.block = 0; + dest.filemarks = 0; + dest.partition = state->current_position.partition; dest.early_warning = false; dest.programmable_early_warning = false; @@ -402,7 +393,8 @@ void filedebug_help_message(const char *progname) ltfsresult(30199I, filedebug_default_device); } #ifdef mingw_PLATFORM -char *dirname(char *path) { +char *dirname(char *path) +{ if (!path || !*path) { return "."; } @@ -416,20 +408,19 @@ char *dirname(char *path) { // Find the last directory separator char *last_sep = strrchr(copy, '\\'); if (!last_sep) { - last_sep = strrchr(copy, '/'); // Handle forward slashes + last_sep = strrchr(copy, '/'); // Handle forward slashes } if (!last_sep) { free(copy); - return "."; // No separator found, return current directory + return "."; // No separator found, return current directory } // Remove the trailing component if (last_sep == copy) { // Root directory case (e.g., "/") copy[1] = '\0'; - } - else { + } else { *last_sep = '\0'; } @@ -455,7 +446,7 @@ int filedebug_open(const char *name, void **handle) CHECK_ARG_NULL(handle, -LTFS_NULL_ARG); *handle = NULL; - state = (struct filedebug_data *)calloc(1,sizeof(struct filedebug_data)); + state = (struct filedebug_data *)calloc(1, sizeof(struct filedebug_data)); if (!state) { ltfsmsg(LTFS_ERR, 10001E, "filedebug_open: private data"); return -EDEV_NO_MEMORY; @@ -476,7 +467,7 @@ int filedebug_open(const char *name, void **handle) devs = filedebug_get_device_list(NULL, 0); if (devs) { buf = (struct tc_drive_info *)calloc(devs * 2, sizeof(struct tc_drive_info)); - if (! buf) { + if (!buf) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } @@ -484,7 +475,7 @@ int filedebug_open(const char *name, void **handle) } for (i = 0; i < info_devs; i++) { - if (! strncmp(buf[i].serial_number, name, TAPE_SERIAL_LEN_MAX) ) { + if (!strncmp(buf[i].serial_number, name, TAPE_SERIAL_LEN_MAX)) { devname = arch_strdup(buf[i].name); if (!devname) { ltfsmsg(LTFS_ERR, 10001E, "sg_ibmtape_open: devname"); @@ -502,8 +493,7 @@ int filedebug_open(const char *name, void **handle) } /* Run on file mode */ - if (devname == NULL) - devname = arch_strdup(name); + if (devname == NULL) devname = arch_strdup(name); ltfsmsg(LTFS_INFO, 30001I, devname); arch_open(&(state->fd), devname, O_RDWR | O_BINARY, SHARE_FLAG_DENYWR, PERMISSION_READWRITE); @@ -513,16 +503,15 @@ int filedebug_open(const char *name, void **handle) } /* Parse pid and serial from filename */ - cur = (char*)devname; + cur = (char *)devname; cur += strlen(devname) - 1; for (i = 0; i < (int)strlen(devname); i++) { - if (*cur == '.') - pid = cur + 1; + if (*cur == '.') pid = cur + 1; if (*cur == '_') { ser = cur + 1; break; } - cur --; + cur--; } if (pid && ser) { @@ -536,7 +525,7 @@ int filedebug_open(const char *name, void **handle) for (i = 0; i < (int)strlen(state->serial_number); i++) { if (state->serial_number[i] == '.') { state->serial_number[i] = '\0'; - state->product_id = &(state->serial_number[i+1]); + state->product_id = &(state->serial_number[i + 1]); break; } } @@ -554,7 +543,7 @@ int filedebug_open(const char *name, void **handle) that may then be overwritten by subsequent calls to dirname(). */ p = dirname(tmp); int len = (strlen(p) + 1) * sizeof(char); - state->dirbase = (char*)calloc(strlen(p) + 1, sizeof(char)); + state->dirbase = (char *)calloc(strlen(p) + 1, sizeof(char)); if (!state->dirbase) { ltfsmsg(LTFS_ERR, 10001E, "filedebug_open: dirbase"); free(state); @@ -567,34 +556,34 @@ int filedebug_open(const char *name, void **handle) devname = NULL; } - state->ready = false; + state->ready = false; state->max_block_size = 16 * MB; /* Set default option value */ - state->conf.dummy_io = false; + state->conf.dummy_io = false; state->conf.emulate_readonly = false; - state->conf.capacity_mb = DEFAULT_CAPACITY_MB; - state->conf.cart_type = TC_MP_LTO5D_CART; - state->conf.density_code = 0x58; + state->conf.capacity_mb = DEFAULT_CAPACITY_MB; + state->conf.cart_type = TC_MP_LTO5D_CART; + state->conf.density_code = 0x58; /* Initial setting of force perm */ - state->clear_by_pc = false; + state->clear_by_pc = false; state->force_writeperm = DEFAULT_WRITEPERM; - state->force_readperm = DEFAULT_READPERM; + state->force_readperm = DEFAULT_READPERM; state->force_readperm = DEFAULT_READPERM; state->force_errortype = DEFAULT_ERRORTYPE; - state->conf.delay_mode = DELAY_NONE; - state->conf.wraps = DEFAULT_WRAPS; - state->conf.eot_to_bot_sec = DEFAULT_EOT_TO_BOT; + state->conf.delay_mode = DELAY_NONE; + state->conf.wraps = DEFAULT_WRAPS; + state->conf.eot_to_bot_sec = DEFAULT_EOT_TO_BOT; state->conf.change_direction_us = DEFAULT_CHANGE_DIRECTION; - state->conf.change_track_us = DEFAULT_CHANGE_TRACK; + state->conf.change_track_us = DEFAULT_CHANGE_TRACK; /* Set drive type if it is provided */ struct supported_device **d_cur = ibm_supported_drives; - while(*d_cur) { - if((! strncmp(IBM_VENDOR_ID, (*d_cur)->vendor_id, strlen((*d_cur)->vendor_id)) ) && - (! strncmp(state->product_id, (*d_cur)->product_id, strlen((*d_cur)->product_id)) ) ) { + while (*d_cur) { + if ((!strncmp(IBM_VENDOR_ID, (*d_cur)->vendor_id, strlen((*d_cur)->vendor_id))) && + (!strncmp(state->product_id, (*d_cur)->product_id, strlen((*d_cur)->product_id)))) { state->drive_type = (*d_cur)->drive_type; break; } @@ -608,12 +597,12 @@ int filedebug_open(const char *name, void **handle) snprintf(state->info.product_rev, PRODUCT_REV_LENGTH + 1, "%s", "REVS"); snprintf(state->info.product_name, PRODUCT_NAME_LENGTH + 1, "[%s]", state->product_id); - state->info.host = 0; + state->info.host = 0; state->info.channel = 0; - state->info.target = 0; - state->info.lun = -1; + state->info.target = 0; + state->info.lun = -1; - *handle = (void *) state; + *handle = (void *)state; return 0; } @@ -635,14 +624,10 @@ int filedebug_close(void *device) } if (state) { - if (state->fd > 0) - arch_close(state->fd); - if (state->dirbase) - free(state->dirbase); - if (state->dirname) - free(state->dirname); - if (state->serial_number) - free(state->serial_number); + if (state->fd > 0) arch_close(state->fd); + if (state->dirbase) free(state->dirbase); + if (state->dirname) free(state->dirname); + if (state->serial_number) free(state->serial_number); free(state); } @@ -678,13 +663,11 @@ int filedebug_inquiry_page(void *device, unsigned char page, struct tc_inq_page int filedebug_test_unit_ready(void *device) { struct filedebug_data *state = (struct filedebug_data *)device; - if (!state->ready) - return -EDEV_NEED_INITIALIZE; + if (!state->ready) return -EDEV_NEED_INITIALIZE; return DEVICE_GOOD; } -int filedebug_read(void *device, char *buf, size_t count, struct tc_position *pos, - const bool unusual_size) +int filedebug_read(void *device, char *buf, size_t count, struct tc_position *pos, const bool unusual_size) { struct filedebug_data *state = (struct filedebug_data *)device; char *fname; @@ -693,9 +676,12 @@ int filedebug_read(void *device, char *buf, size_t count, struct tc_position *po ssize_t bytes_read; int fd; - ltfsmsg(LTFS_DEBUG, 30005D, (unsigned int)count, state->current_position.partition, - (unsigned long long)state->current_position.block, - (unsigned long long)state->current_position.filemarks); + ltfsmsg(LTFS_DEBUG, + 30005D, + (unsigned int)count, + state->current_position.partition, + (unsigned long long)state->current_position.block, + (unsigned long long)state->current_position.filemarks); if (!state->ready) { ltfsmsg(LTFS_ERR, 30006E); @@ -724,10 +710,7 @@ int filedebug_read(void *device, char *buf, size_t count, struct tc_position *po return -EDEV_EOD_DETECTED; } - if (state->conf.dummy_io && - state->current_position.partition && - state->current_position.block > 6) { - + if (state->conf.dummy_io && state->current_position.partition && state->current_position.block > 6) { /* * Dummy I/O mode * No actual data is written to partition1 (DP), hence we can simply @@ -740,8 +723,7 @@ int filedebug_read(void *device, char *buf, size_t count, struct tc_position *po } else { fname = _filedebug_make_current_filename(state, rec_suffixes[SUFFIX_EOD]); - if (!fname) - return -EDEV_NO_MEMORY; + if (!fname) return -EDEV_NO_MEMORY; fname_len = strlen(fname); ret = _filedebug_check_file(fname); @@ -825,9 +807,12 @@ int filedebug_write(void *device, const char *buf, size_t count, struct tc_posit int fd; ssize_t written; - ltfsmsg(LTFS_DEBUG, 30016D, (unsigned int)count, state->current_position.partition, - (unsigned long long)state->current_position.block, - (unsigned long long)state->current_position.filemarks); + ltfsmsg(LTFS_DEBUG, + 30016D, + (unsigned int)count, + state->current_position.partition, + (unsigned long long)state->current_position.block, + (unsigned long long)state->current_position.filemarks); if (!state->ready) { ltfsmsg(LTFS_ERR, 30017E); @@ -846,7 +831,7 @@ int filedebug_write(void *device, const char *buf, size_t count, struct tc_posit if (state->conf.emulate_readonly) ret = -EDEV_WRITE_PROTECTED; /* Emulate 07/2700 */ else - ret = -EDEV_DATA_PROTECT; /* Emulate 07/3005 */ + ret = -EDEV_DATA_PROTECT; /* Emulate 07/3005 */ ltfsmsg(LTFS_INFO, 30085I, ret, state->serial_number); @@ -861,7 +846,7 @@ int filedebug_write(void *device, const char *buf, size_t count, struct tc_posit /* TODO: It is nicer if we have a append only mode support */ - if (! buf && count > 0) { + if (!buf && count > 0) { ltfsmsg(LTFS_ERR, 30018E); ret = -EDEV_INVALID_ARG; return ret; @@ -870,15 +855,15 @@ int filedebug_write(void *device, const char *buf, size_t count, struct tc_posit return ret; } - if ( state->force_writeperm ) { + if (state->force_writeperm) { state->write_counter++; - if ( state->write_counter > state->force_writeperm ) { + if (state->write_counter > state->force_writeperm) { ltfsmsg(LTFS_ERR, 30007E, "write"); if (state->force_errortype) return -EDEV_NO_SENSE; else return -EDEV_WRITE_PERM; - } else if ( state->write_counter > (state->force_writeperm - THRESHOLD_FORCE_WRITE_NO_WRITE) ) { + } else if (state->write_counter > (state->force_writeperm - THRESHOLD_FORCE_WRITE_NO_WRITE)) { ltfsmsg(LTFS_INFO, 30019I); ++state->current_position.block; pos->block = state->current_position.block; @@ -892,10 +877,7 @@ int filedebug_write(void *device, const char *buf, size_t count, struct tc_posit return ret; } - if (state->conf.dummy_io && - state->current_position.partition && - state->current_position.block > 6) { - + if (state->conf.dummy_io && state->current_position.partition && state->current_position.block > 6) { /* * Dummy I/O mode * Do not write any data on partition1 (DP) @@ -915,7 +897,7 @@ int filedebug_write(void *device, const char *buf, size_t count, struct tc_posit } /* Increment Write Pass for consistency check */ - if(state->write_pass_prev == state->write_pass){ + if (state->write_pass_prev == state->write_pass) { ret = _set_wp(device, ++(state->write_pass)); if (ret < 0) { ltfsmsg(LTFS_ERR, 30022E, ret); @@ -963,19 +945,18 @@ int filedebug_write(void *device, const char *buf, size_t count, struct tc_posit } ret = written; - if (state->p0_warning && state->current_position.partition == 0 && - state->current_position.block >= state->p0_warning) + if (state->p0_warning && state->current_position.partition == 0 && state->current_position.block >= state->p0_warning) pos->early_warning = true; else if (state->p1_warning && state->current_position.partition == 1 && - state->current_position.block >= state->p1_warning) + state->current_position.block >= state->p1_warning) pos->early_warning = true; /* Programmable early warning is set only when position moves into programmable early warning zone in write() method. */ if (state->p0_p_warning && state->current_position.partition == 0 && - state->current_position.block == state->p0_p_warning) + state->current_position.block == state->p0_p_warning) pos->programmable_early_warning = true; else if (state->p1_p_warning && state->current_position.partition == 1 && - state->current_position.block == state->p1_p_warning) + state->current_position.block == state->p1_p_warning) pos->programmable_early_warning = true; return ret; } @@ -988,9 +969,12 @@ int filedebug_writefm(void *device, size_t count, struct tc_position *pos, bool int fd; size_t i; - ltfsmsg(LTFS_DEBUG, 30028D, (unsigned int)count, state->current_position.partition, - (unsigned long long)state->current_position.block, - (unsigned long long)state->current_position.filemarks); + ltfsmsg(LTFS_DEBUG, + 30028D, + (unsigned int)count, + state->current_position.partition, + (unsigned long long)state->current_position.block, + (unsigned long long)state->current_position.filemarks); if (!state->ready) { ltfsmsg(LTFS_ERR, 30029E); @@ -1003,16 +987,13 @@ int filedebug_writefm(void *device, size_t count, struct tc_position *pos, bool return DEVICE_GOOD; } - if (state->conf.dummy_io && - state->current_position.partition && - state->current_position.block > 6) { - + if (state->conf.dummy_io && state->current_position.partition && state->current_position.block > 6) { /* * Dummy I/O mode * Do not write any data on partition1 (DP) */ - for (i=0; icurrent_position.block; ++state->current_position.filemarks; pos->block = state->current_position.block; @@ -1023,7 +1004,7 @@ int filedebug_writefm(void *device, size_t count, struct tc_position *pos, bool } else { /* Increment Write Pass for consistency check */ - if(state->write_pass_prev == state->write_pass){ + if (state->write_pass_prev == state->write_pass) { ret = _set_wp(device, ++(state->write_pass)); if (ret < 0) { ltfsmsg(LTFS_ERR, 30030E, ret); @@ -1031,7 +1012,7 @@ int filedebug_writefm(void *device, size_t count, struct tc_position *pos, bool } } - for (i=0; icurrent_position.block; @@ -1074,17 +1053,16 @@ int filedebug_writefm(void *device, size_t count, struct tc_position *pos, bool } } - if (state->p0_warning && state->current_position.partition == 0 && - state->current_position.block >= state->p0_warning) + if (state->p0_warning && state->current_position.partition == 0 && state->current_position.block >= state->p0_warning) pos->early_warning = true; else if (state->p1_warning && state->current_position.partition == 1 && - state->current_position.block >= state->p1_warning) + state->current_position.block >= state->p1_warning) pos->early_warning = true; if (state->p0_p_warning && state->current_position.partition == 0 && - state->current_position.block >= state->p0_p_warning) + state->current_position.block >= state->p0_p_warning) pos->programmable_early_warning = true; else if (state->p1_p_warning && state->current_position.partition == 1 && - state->current_position.block >= state->p1_p_warning) + state->current_position.block >= state->p1_p_warning) pos->programmable_early_warning = true; return ret; } @@ -1106,13 +1084,13 @@ int filedebug_rewind(void *device, struct tc_position *pos) emulate_rewind_wait(state); /* Does rewinding reset the partition? */ - state->current_position.block = 0; + state->current_position.block = 0; state->current_position.filemarks = 0; - state->clear_by_pc = false; - state->force_writeperm = DEFAULT_WRITEPERM; - state->force_readperm = DEFAULT_READPERM; - state->write_counter = 0; - state->read_counter = 0; + state->clear_by_pc = false; + state->force_writeperm = DEFAULT_WRITEPERM; + state->force_readperm = DEFAULT_READPERM; + state->write_counter = 0; + state->read_counter = 0; pos->block = state->current_position.block; pos->filemarks = 0; pos->early_warning = false; @@ -1126,10 +1104,9 @@ int filedebug_locate(void *device, struct tc_position dest, struct tc_position * int ret = 0; struct filedebug_data *state = (struct filedebug_data *)device; tape_filemarks_t count_fm = 0; - tape_block_t i; + tape_block_t i; - ltfsmsg(LTFS_DEBUG, 30197D, "locate", (unsigned long long)dest.partition, - (unsigned long long)dest.block); + ltfsmsg(LTFS_DEBUG, 30197D, "locate", (unsigned long long)dest.partition, (unsigned long long)dest.block); if (!state->ready) { ltfsmsg(LTFS_ERR, 30037E); @@ -1151,9 +1128,9 @@ int filedebug_locate(void *device, struct tc_position dest, struct tc_position * if (state->current_position.partition != dest.partition) { if (state->clear_by_pc) { - state->clear_by_pc = false; + state->clear_by_pc = false; state->force_writeperm = DEFAULT_WRITEPERM; - state->force_readperm = DEFAULT_READPERM; + state->force_readperm = DEFAULT_READPERM; state->force_errortype = DEFAULT_ERRORTYPE; } } @@ -1161,21 +1138,19 @@ int filedebug_locate(void *device, struct tc_position dest, struct tc_position * emulate_seek_wait(state, &dest); state->current_position.partition = dest.partition; - if (state->eod[dest.partition] == MISSING_EOD && - state->last_block[dest.partition] < dest.block) - state->current_position.block = state->last_block[dest.partition] + 1; + if (state->eod[dest.partition] == MISSING_EOD && state->last_block[dest.partition] < dest.block) + state->current_position.block = state->last_block[dest.partition] + 1; else if (state->eod[dest.partition] < dest.block) state->current_position.block = state->eod[dest.partition]; else state->current_position.block = dest.block; pos->partition = state->current_position.partition; - pos->block = state->current_position.block; + pos->block = state->current_position.block; - for(i = 0; i < state->current_position.block; ++i) { + for (i = 0; i < state->current_position.block; ++i) { char *fname; - fname = _filedebug_make_filename(state, state->current_position.partition, - i, rec_suffixes[SUFFIX_FILEMARK]); + fname = _filedebug_make_filename(state, state->current_position.partition, i, rec_suffixes[SUFFIX_FILEMARK]); if (!fname) { ltfsmsg(LTFS_ERR, 30039E); ret = -EDEV_NO_MEMORY; @@ -1183,8 +1158,7 @@ int filedebug_locate(void *device, struct tc_position dest, struct tc_position * } ret = _filedebug_check_file(fname); - if (ret == 1) - ++count_fm; + if (ret == 1) ++count_fm; free(fname); } @@ -1192,17 +1166,16 @@ int filedebug_locate(void *device, struct tc_position dest, struct tc_position * state->current_position.filemarks = count_fm; pos->filemarks = state->current_position.filemarks; - if (state->p0_warning && state->current_position.partition == 0 && - state->current_position.block >= state->p0_warning) + if (state->p0_warning && state->current_position.partition == 0 && state->current_position.block >= state->p0_warning) pos->early_warning = true; else if (state->p1_warning && state->current_position.partition == 1 && - state->current_position.block >= state->p1_warning) + state->current_position.block >= state->p1_warning) pos->early_warning = true; if (state->p0_p_warning && state->current_position.partition == 0 && - state->current_position.block >= state->p0_p_warning) + state->current_position.block >= state->p0_p_warning) pos->programmable_early_warning = true; else if (state->p1_p_warning && state->current_position.partition == 1 && - state->current_position.block >= state->p1_p_warning) + state->current_position.block >= state->p1_p_warning) pos->programmable_early_warning = true; return ret; } @@ -1213,7 +1186,7 @@ int filedebug_space(void *device, size_t count, TC_SPACE_TYPE type, struct tc_po struct filedebug_data *state = (struct filedebug_data *)device; int ret_fm; tape_filemarks_t count_fm = 0; - tape_block_t i; + tape_block_t i; if (!state->ready) { ltfsmsg(LTFS_ERR, 30040E); @@ -1228,65 +1201,59 @@ int filedebug_space(void *device, size_t count, TC_SPACE_TYPE type, struct tc_po } switch (type) { - case TC_SPACE_EOD: - ltfsmsg(LTFS_DEBUG, 30195D, "space to EOD"); - state->current_position.block = state->eod[state->current_position.partition]; - if (state->current_position.block == MISSING_EOD) { - ret = -EDEV_RW_PERM; - return ret; - } - else - ret = 0; - break; - case TC_SPACE_FM_F: - ltfsmsg(LTFS_DEBUG, 30196D, "space forward file marks", (unsigned long long)count); - if (state->current_position.block == MISSING_EOD) { - ret = -EDEV_RW_PERM; - return ret; - } - else - ret = _filedebug_space_fm(state, count, false); - break; - case TC_SPACE_FM_B: - ltfsmsg(LTFS_DEBUG, 30196D, "space back file marks", (unsigned long long)count); - if (state->current_position.block == MISSING_EOD) { - ret = -EDEV_RW_PERM; - return ret; - } - else - ret = _filedebug_space_fm(state, count, true); - break; - case TC_SPACE_F: - ltfsmsg(LTFS_DEBUG, 30196D, "space forward records", (unsigned long long)count); - if (state->current_position.block == MISSING_EOD) { - ret = -EDEV_RW_PERM; - return ret; - } - else - ret = _filedebug_space_rec(state, count, false); - break; - case TC_SPACE_B: - ltfsmsg(LTFS_DEBUG, 30196D, "space back records", (unsigned long long)count); - if (state->current_position.block == MISSING_EOD) { - ret = -EDEV_RW_PERM; + case TC_SPACE_EOD: + ltfsmsg(LTFS_DEBUG, 30195D, "space to EOD"); + state->current_position.block = state->eod[state->current_position.partition]; + if (state->current_position.block == MISSING_EOD) { + ret = -EDEV_RW_PERM; + return ret; + } else + ret = 0; + break; + case TC_SPACE_FM_F: + ltfsmsg(LTFS_DEBUG, 30196D, "space forward file marks", (unsigned long long)count); + if (state->current_position.block == MISSING_EOD) { + ret = -EDEV_RW_PERM; + return ret; + } else + ret = _filedebug_space_fm(state, count, false); + break; + case TC_SPACE_FM_B: + ltfsmsg(LTFS_DEBUG, 30196D, "space back file marks", (unsigned long long)count); + if (state->current_position.block == MISSING_EOD) { + ret = -EDEV_RW_PERM; + return ret; + } else + ret = _filedebug_space_fm(state, count, true); + break; + case TC_SPACE_F: + ltfsmsg(LTFS_DEBUG, 30196D, "space forward records", (unsigned long long)count); + if (state->current_position.block == MISSING_EOD) { + ret = -EDEV_RW_PERM; + return ret; + } else + ret = _filedebug_space_rec(state, count, false); + break; + case TC_SPACE_B: + ltfsmsg(LTFS_DEBUG, 30196D, "space back records", (unsigned long long)count); + if (state->current_position.block == MISSING_EOD) { + ret = -EDEV_RW_PERM; + return ret; + } else + ret = _filedebug_space_rec(state, count, true); + break; + default: + ltfsmsg(LTFS_ERR, 30041E); + ret = -EDEV_INVALID_ARG; return ret; - } - else - ret = _filedebug_space_rec(state, count, true); - break; - default: - ltfsmsg(LTFS_ERR, 30041E); - ret = -EDEV_INVALID_ARG; - return ret; } pos->block = state->current_position.block; - for(i = 0; i < state->current_position.block; ++i) { + for (i = 0; i < state->current_position.block; ++i) { char *fname; - fname = _filedebug_make_filename(state, state->current_position.partition, - i, rec_suffixes[SUFFIX_FILEMARK]); + fname = _filedebug_make_filename(state, state->current_position.partition, i, rec_suffixes[SUFFIX_FILEMARK]); if (!fname) { ltfsmsg(LTFS_ERR, 30042E); ret = -EDEV_NO_MEMORY; @@ -1294,25 +1261,23 @@ int filedebug_space(void *device, size_t count, TC_SPACE_TYPE type, struct tc_po } ret_fm = _filedebug_check_file(fname); - if (ret_fm == 1) - ++count_fm; + if (ret_fm == 1) ++count_fm; free(fname); } state->current_position.filemarks = count_fm; pos->filemarks = state->current_position.filemarks; - if (state->p0_warning && state->current_position.partition == 0 && - state->current_position.block >= state->p0_warning) + if (state->p0_warning && state->current_position.partition == 0 && state->current_position.block >= state->p0_warning) pos->early_warning = true; else if (state->p1_warning && state->current_position.partition == 1 && - state->current_position.block >= state->p1_warning) + state->current_position.block >= state->p1_warning) pos->early_warning = true; if (state->p0_p_warning && state->current_position.partition == 0 && - state->current_position.block >= state->p0_p_warning) + state->current_position.block >= state->p0_p_warning) pos->programmable_early_warning = true; else if (state->p1_p_warning && state->current_position.partition == 1 && - state->current_position.block >= state->p1_p_warning) + state->current_position.block >= state->p1_p_warning) pos->programmable_early_warning = true; return ret; } @@ -1333,7 +1298,7 @@ int filedebug_erase(void *device, struct tc_position *pos, bool long_erase) } ltfsmsg(LTFS_DEBUG, 30044D, (unsigned long)state->current_position.partition); - pos->block = state->current_position.block; + pos->block = state->current_position.block; pos->filemarks = state->current_position.filemarks; ret = _filedebug_write_eod(state); @@ -1421,97 +1386,95 @@ static inline int _sanitize_tape(struct filedebug_data *state) ret = -EDEV_MEDIUM_FORMAT_ERROR; break; } - } - else if (gen == DRIVE_GEN_JAG4) { + } else if (gen == DRIVE_GEN_JAG4) { switch (state->conf.cart_type) { - case TC_MP_JB: - case TC_MP_JC: - case TC_MP_JK: - state->is_worm = false; - break; - case TC_MP_JX: - case TC_MP_JY: - state->is_worm = true; - break; - default: - ltfsmsg(LTFS_INFO, 30086I, "TS1140", state->conf.cart_type); - state->is_worm = false; - state->unsupported_tape = true; - ret = -EDEV_MEDIUM_FORMAT_ERROR; - break; + case TC_MP_JB: + case TC_MP_JC: + case TC_MP_JK: + state->is_worm = false; + break; + case TC_MP_JX: + case TC_MP_JY: + state->is_worm = true; + break; + default: + ltfsmsg(LTFS_INFO, 30086I, "TS1140", state->conf.cart_type); + state->is_worm = false; + state->unsupported_tape = true; + ret = -EDEV_MEDIUM_FORMAT_ERROR; + break; } } else if (gen == DRIVE_GEN_JAG5A) { switch (state->conf.cart_type) { - case TC_MP_JC: - case TC_MP_JK: - case TC_MP_JD: - case TC_MP_JL: - state->is_worm = false; - break; - case TC_MP_JY: - case TC_MP_JZ: - state->is_worm = true; - break; - default: - ltfsmsg(LTFS_INFO, 30086I, "TS1150", state->conf.cart_type); - state->is_worm = false; - state->unsupported_tape = true; - ret = -EDEV_MEDIUM_FORMAT_ERROR; - break; + case TC_MP_JC: + case TC_MP_JK: + case TC_MP_JD: + case TC_MP_JL: + state->is_worm = false; + break; + case TC_MP_JY: + case TC_MP_JZ: + state->is_worm = true; + break; + default: + ltfsmsg(LTFS_INFO, 30086I, "TS1150", state->conf.cart_type); + state->is_worm = false; + state->unsupported_tape = true; + ret = -EDEV_MEDIUM_FORMAT_ERROR; + break; } } else if (gen == DRIVE_GEN_JAG6) { switch (state->conf.cart_type) { - case TC_MP_JC: - case TC_MP_JK: - case TC_MP_JD: - case TC_MP_JL: - state->is_worm = false; - break; - case TC_MP_JY: - case TC_MP_JZ: - state->is_worm = true; - break; - default: - ltfsmsg(LTFS_INFO, 30086I, "TS1155", state->conf.cart_type); - state->is_worm = false; - state->unsupported_tape = true; - ret = -EDEV_MEDIUM_FORMAT_ERROR; - break; + case TC_MP_JC: + case TC_MP_JK: + case TC_MP_JD: + case TC_MP_JL: + state->is_worm = false; + break; + case TC_MP_JY: + case TC_MP_JZ: + state->is_worm = true; + break; + default: + ltfsmsg(LTFS_INFO, 30086I, "TS1155", state->conf.cart_type); + state->is_worm = false; + state->unsupported_tape = true; + ret = -EDEV_MEDIUM_FORMAT_ERROR; + break; } } else if (gen == DRIVE_GEN_JAG7) { switch (state->conf.cart_type) { - case TC_MP_JC: - case TC_MP_JK: - case TC_MP_JD: - case TC_MP_JL: - case TC_MP_JE: - case TC_MP_JM: - state->is_worm = false; - break; - case TC_MP_JY: - case TC_MP_JZ: - case TC_MP_JV: - state->is_worm = true; - break; - default: - ltfsmsg(LTFS_INFO, 30086I, "TS1160", state->conf.cart_type); - state->is_worm = false; - state->unsupported_tape = true; - ret = -EDEV_MEDIUM_FORMAT_ERROR; - break; + case TC_MP_JC: + case TC_MP_JK: + case TC_MP_JD: + case TC_MP_JL: + case TC_MP_JE: + case TC_MP_JM: + state->is_worm = false; + break; + case TC_MP_JY: + case TC_MP_JZ: + case TC_MP_JV: + state->is_worm = true; + break; + default: + ltfsmsg(LTFS_INFO, 30086I, "TS1160", state->conf.cart_type); + state->is_worm = false; + state->unsupported_tape = true; + ret = -EDEV_MEDIUM_FORMAT_ERROR; + break; } - } - else if (gen == DRIVE_GEN_JAG7) { + } else if (gen == DRIVE_GEN_JAG7) { switch (state->conf.cart_type) { - case TC_MP_JF: - state->is_worm = false; - break; - default: - ltfsmsg(LTFS_INFO, 30086I, "TS1170", state->conf.cart_type); - state->is_worm = false; - state->unsupported_tape = true; - ret = -EDEV_MEDIUM_FORMAT_ERROR; - break; + case TC_MP_JF: + state->is_worm = false; + break; + default: + ltfsmsg(LTFS_INFO, 30086I, "TS1170", state->conf.cart_type); + state->is_worm = false; + state->unsupported_tape = true; + ret = -EDEV_MEDIUM_FORMAT_ERROR; + break; } } else { ltfsmsg(LTFS_INFO, 30086I, "Unexpected Drive", state->conf.cart_type); @@ -1537,21 +1500,20 @@ int filedebug_load(void *device, struct tc_position *pos) if (state->ready) { emulate_load_wait(state); state->current_position.partition = 0; - state->current_position.block = 0; + state->current_position.block = 0; state->current_position.filemarks = 0; - state->clear_by_pc = false; - state->force_writeperm = DEFAULT_WRITEPERM; - state->force_readperm = DEFAULT_READPERM; - state->write_counter = 0; - state->read_counter = 0; + state->clear_by_pc = false; + state->force_writeperm = DEFAULT_WRITEPERM; + state->force_readperm = DEFAULT_READPERM; + state->write_counter = 0; + state->read_counter = 0; return DEVICE_GOOD; /* already loaded the tape */ } if (state->fd > 0) { memset(buf, 0, sizeof(buf)); ret = lseek(state->fd, 0, SEEK_SET); - if (ret < 0) - return -EDEV_HARDWARE_ERROR; + if (ret < 0) return -EDEV_HARDWARE_ERROR; ret = arch_read(state->fd, buf, sizeof(buf)); if (ret != sizeof(buf)) { @@ -1561,15 +1523,14 @@ int filedebug_load(void *device, struct tc_position *pos) dirlink = buf; - if(dirlink[strlen(dirlink) - 1] == '\n') - dirlink[strlen(dirlink) - 1] = '\0'; + if (dirlink[strlen(dirlink) - 1] == '\n') dirlink[strlen(dirlink) - 1] = '\0'; - if(!strcmp(dirlink, "empty")) { + if (!strcmp(dirlink, "empty")) { ltfsmsg(LTFS_INFO, 30046I, ""); return -EDEV_NO_MEDIUM; } - if(state->dirname) { + if (state->dirname) { free(state->dirname); state->dirname = NULL; } @@ -1591,14 +1552,14 @@ int filedebug_load(void *device, struct tc_position *pos) ltfsmsg(LTFS_INFO, 30048I, state->dirname); /* Load configuration of cartridge */ - ret = asprintf(&config_file, "%s/%s", state->dirname, CARTRIDGE_CONFIG ); + ret = asprintf(&config_file, "%s/%s", state->dirname, CARTRIDGE_CONFIG); if (ret < 0) { ltfsmsg(LTFS_ERR, 30049E, ret); return -EDEV_INTERNAL_ERROR; } ret = stat(config_file, &d); - if (! ret && S_ISDIR(d.st_mode)) { + if (!ret && S_ISDIR(d.st_mode)) { ltfsmsg(LTFS_ERR, 30050E, ret); free(config_file); return -EDEV_INTERNAL_ERROR; @@ -1606,7 +1567,7 @@ int filedebug_load(void *device, struct tc_position *pos) if (ret < 0 && errno == ENOENT) filedebug_conf_tc_write_xml(config_file, &state->conf); - else if (! ret) + else if (!ret) filedebug_conf_tc_read_xml(config_file, &state->conf); else { ltfsmsg(LTFS_ERR, 30051E, ret); @@ -1617,7 +1578,7 @@ int filedebug_load(void *device, struct tc_position *pos) free(config_file); state->ready = true; - state->unsupported_tape = false; + state->unsupported_tape = false; state->unsupported_format = false; /* Sanitize by cartridge type and configure WORM emulation flag */ @@ -1627,12 +1588,8 @@ int filedebug_load(void *device, struct tc_position *pos) } /* Configure internal read_only flag */ - ret = ibm_tape_is_mountable( state->drive_type, - NULL, - state->conf.cart_type, - state->conf.density_code, - false); - switch(ret) { + ret = ibm_tape_is_mountable(state->drive_type, NULL, state->conf.cart_type, state->conf.density_code, false); + switch (ret) { case MEDIUM_PERFECT_MATCH: case MEDIUM_WRITABLE: if (state->conf.emulate_readonly) @@ -1646,8 +1603,7 @@ int filedebug_load(void *device, struct tc_position *pos) case MEDIUM_CANNOT_ACCESS: ltfsmsg(LTFS_INFO, 30088I, state->drive_type, state->conf.density_code); state->unsupported_format = true; - if (IS_LTO(state->drive_type)) - return -EDEV_MEDIUM_FORMAT_ERROR; + if (IS_LTO(state->drive_type)) return -EDEV_MEDIUM_FORMAT_ERROR; break; case MEDIUM_UNKNOWN: case MEDIUM_PROBABLY_WRITABLE: @@ -1657,7 +1613,7 @@ int filedebug_load(void *device, struct tc_position *pos) break; } - for (i=0; iconf.dummy_io) - _filedebug_remove_record(state, 1, state->eod[1]); + if (state->conf.dummy_io) _filedebug_remove_record(state, 1, state->eod[1]); state->current_position.partition = 0; - state->current_position.block = 0; + state->current_position.block = 0; state->current_position.filemarks = 0; if (state->eod[1] == 0) state->partitions = 1; @@ -1677,11 +1632,11 @@ int filedebug_load(void *device, struct tc_position *pos) state->partitions = MAX_PARTITIONS; pos->partition = state->current_position.partition; - pos->block = state->current_position.block; + pos->block = state->current_position.block; pos->filemarks = state->current_position.filemarks; wp = 0; - if(_get_wp(device, &wp) != 0) { + if (_get_wp(device, &wp) != 0) { ltfsmsg(LTFS_ERR, 30053E); return -EDEV_INTERNAL_ERROR; } @@ -1725,20 +1680,20 @@ int filedebug_unload(void *device, struct tc_position *pos) state->ready = false; state->current_position.partition = 0; - state->current_position.block = 0; + state->current_position.block = 0; state->current_position.filemarks = 0; - state->clear_by_pc = false; - state->force_writeperm = DEFAULT_WRITEPERM; - state->force_readperm = DEFAULT_READPERM; - state->write_counter = 0; - state->read_counter = 0; + state->clear_by_pc = false; + state->force_writeperm = DEFAULT_WRITEPERM; + state->force_readperm = DEFAULT_READPERM; + state->write_counter = 0; + state->read_counter = 0; pos->partition = state->current_position.partition; - pos->block = state->current_position.block; + pos->block = state->current_position.block; pos->filemarks = state->current_position.filemarks; /* Save configuration of cartridge */ - ret = asprintf(&config_file, "%s/%s", state->dirname, CARTRIDGE_CONFIG ); + ret = asprintf(&config_file, "%s/%s", state->dirname, CARTRIDGE_CONFIG); if (ret < 0) { ltfsmsg(LTFS_ERR, 30049E, ret); return -EDEV_INTERNAL_ERROR; @@ -1746,8 +1701,7 @@ int filedebug_unload(void *device, struct tc_position *pos) filedebug_conf_tc_write_xml(config_file, &state->conf); - if (config_file) - free(config_file); + if (config_file) free(config_file); emulate_threading_wait(state); @@ -1764,12 +1718,15 @@ int filedebug_readpos(void *device, struct tc_position *pos) } pos->partition = state->current_position.partition; - pos->block = state->current_position.block; + pos->block = state->current_position.block; pos->filemarks = state->current_position.filemarks; - ltfsmsg(LTFS_DEBUG, 30198D, "readpos", (unsigned long long)state->current_position.partition, - (unsigned long long)state->current_position.block, - (unsigned long long)state->current_position.filemarks); + ltfsmsg(LTFS_DEBUG, + 30198D, + "readpos", + (unsigned long long)state->current_position.partition, + (unsigned long long)state->current_position.block, + (unsigned long long)state->current_position.filemarks); return DEVICE_GOOD; } @@ -1778,9 +1735,7 @@ int filedebug_setcap(void *device, uint16_t proportion) struct filedebug_data *state = (struct filedebug_data *)device; struct tc_position pos; - if(state->current_position.partition != 0 || - state->current_position.block != 0) - { + if (state->current_position.partition != 0 || state->current_position.block != 0) { ltfsmsg(LTFS_ERR, 30055E); return -EDEV_ILLEGAL_REQUEST; } @@ -1798,23 +1753,22 @@ int filedebug_setcap(void *device, uint16_t proportion) return DEVICE_GOOD; } -int filedebug_format(void *device, TC_FORMAT_TYPE format, const char *vol_name, const char *barcode_name, const char *vol_mam_uuid) +int filedebug_format( + void *device, TC_FORMAT_TYPE format, const char *vol_name, const char *barcode_name, const char *vol_mam_uuid) { struct filedebug_data *state = (struct filedebug_data *)device; struct tc_position pos; int ret = 0; - if(state->current_position.partition != 0 || - state->current_position.block != 0) - { + if (state->current_position.partition != 0 || state->current_position.block != 0) { ltfsmsg(LTFS_ERR, 30056E); return -EDEV_ILLEGAL_REQUEST; } /* Emulate WORM */ - if (state->is_worm && - (state->eod[0] != 0 || state->eod[1] != 0) ) { - return -EDEV_WRITE_PROTECTED_WORM;; + if (state->is_worm && (state->eod[0] != 0 || state->eod[1] != 0)) { + return -EDEV_WRITE_PROTECTED_WORM; + ; } /* Emulate read-only tape and write protected tape */ @@ -1822,14 +1776,14 @@ int filedebug_format(void *device, TC_FORMAT_TYPE format, const char *vol_name, if (state->conf.emulate_readonly) ret = -EDEV_WRITE_PROTECTED; /* Emulate 07/2700 */ else - ret = -EDEV_DATA_PROTECT; /* Emulate 07/3005 */ + ret = -EDEV_DATA_PROTECT; /* Emulate 07/3005 */ ltfsmsg(LTFS_INFO, 30085I, ret, state->serial_number); return ret; } - switch(format){ + switch (format) { case TC_FORMAT_DEFAULT: state->partitions = 1; break; @@ -1876,15 +1830,15 @@ int filedebug_remaining_capacity(void *device, struct tc_remaining_cap *cap) return DEVICE_GOOD; } - if(state->partitions == 2) { - cap->max_p0 = calc_p0_cap(state); + if (state->partitions == 2) { + cap->max_p0 = calc_p0_cap(state); cap->remaining_p0 = calc_p0_remaining(state); - cap->max_p1 = calc_p1_cap(state); + cap->max_p1 = calc_p1_cap(state); cap->remaining_p1 = calc_p1_remaining(state); } else { - cap->max_p0 = state->conf.capacity_mb; + cap->max_p0 = state->conf.capacity_mb; cap->remaining_p0 = 0; - cap->max_p1 = 0; + cap->max_p1 = 0; cap->remaining_p1 = 0; } @@ -1893,20 +1847,20 @@ int filedebug_remaining_capacity(void *device, struct tc_remaining_cap *cap) int filedebug_get_cartridge_health(void *device, struct tc_cartridge_health *cart_health) { - cart_health->mounts = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->written_ds = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->write_temps = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->write_perms = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_ds = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_temps = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_perms = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->mounts = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->written_ds = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->write_temps = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->write_perms = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_ds = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_temps = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_perms = UNSUPPORTED_CARTRIDGE_HEALTH; cart_health->write_perms_prev = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_perms_prev = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->written_mbytes = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_mbytes = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->passes_begin = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->passes_middle = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->tape_efficiency = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_perms_prev = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->written_mbytes = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_mbytes = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->passes_begin = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->passes_middle = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->tape_efficiency = UNSUPPORTED_CARTRIDGE_HEALTH; return DEVICE_GOOD; } @@ -1924,13 +1878,11 @@ int filedebug_clear_tape_alert(void *device, uint64_t tape_alert) int filedebug_get_xattr(void *device, const char *name, char **buf) { - struct filedebug_data *state = (struct filedebug_data *) device; + struct filedebug_data *state = (struct filedebug_data *)device; int ret = -LTFS_NO_XATTR; if (!strcmp(name, "ltfs.vendor.IBM.seekLatency")) { - ret = asprintf(buf, "%lds%ldns", - state->accumulated_delay.tv_sec, - state->accumulated_delay.tv_nsec); + ret = asprintf(buf, "%lds%ldns", state->accumulated_delay.tv_sec, state->accumulated_delay.tv_nsec); if (ret < 0) { ltfsmsg(LTFS_ERR, 10001E, "get_xattr buffer"); ret = -LTFS_NO_MEMORY; @@ -1943,45 +1895,44 @@ int filedebug_get_xattr(void *device, const char *name, char **buf) int filedebug_set_xattr(void *device, const char *name, const char *buf, size_t size) { - struct filedebug_data *state = (struct filedebug_data *) device; + struct filedebug_data *state = (struct filedebug_data *)device; int ret = -LTFS_NO_XATTR; uint64_t attr_val; char *null_terminated; int64_t perm_count = 0; - if (!size) - return -LTFS_BAD_ARG; + if (!size) return -LTFS_BAD_ARG; null_terminated = calloc(1, size + 1); - if (! null_terminated) { + if (!null_terminated) { ltfsmsg(LTFS_ERR, 10001E, "ibmtape_set_xattr: null_term"); return -LTFS_NO_MEMORY; } memcpy(null_terminated, buf, size); - if (! strcmp(name, "ltfs.vendor.IBM.forceErrorWrite")) { + if (!strcmp(name, "ltfs.vendor.IBM.forceErrorWrite")) { perm_count = strtoll(null_terminated, NULL, 0); if (perm_count < 0) { state->force_writeperm = -perm_count; - state->clear_by_pc = true; + state->clear_by_pc = true; } else { state->force_writeperm = perm_count; - state->clear_by_pc = false; + state->clear_by_pc = false; } state->write_counter = 0; ret = DEVICE_GOOD; - } else if (! strcmp(name, "ltfs.vendor.IBM.forceErrorType")) { + } else if (!strcmp(name, "ltfs.vendor.IBM.forceErrorType")) { state->force_errortype = strtol(null_terminated, NULL, 0); ret = DEVICE_GOOD; - } else if (! strcmp(name, "ltfs.vendor.IBM.forceErrorRead")) { + } else if (!strcmp(name, "ltfs.vendor.IBM.forceErrorRead")) { perm_count = strtoll(null_terminated, NULL, 0); if (perm_count < 0) { state->force_readperm = -perm_count; - state->clear_by_pc = true; + state->clear_by_pc = true; } else { state->force_readperm = perm_count; - state->clear_by_pc = false; + state->clear_by_pc = false; } state->read_counter = 0; ret = DEVICE_GOOD; @@ -2007,7 +1958,12 @@ int filedebug_logsense(void *device, const uint8_t page, const uint8_t subpage, return -EDEV_UNSUPPORTED_FUNCTION; } -int filedebug_modesense(void *device, const uint8_t page, const TC_MP_PC_TYPE pc, const uint8_t subpage, unsigned char *buf, const size_t size) +int filedebug_modesense(void *device, + const uint8_t page, + const TC_MP_PC_TYPE pc, + const uint8_t subpage, + unsigned char *buf, + const size_t size) { uint16_t pews = 0; struct filedebug_data *state = (struct filedebug_data *)device; @@ -2025,7 +1981,7 @@ int filedebug_modesense(void *device, const uint8_t page, const TC_MP_PC_TYPE pc pews = calc_p0_cap(state) / 2; buf[17] = subpage; buf[22] = (uint8_t)(pews >> 8 & 0xFF); - buf[23] = (uint8_t)(pews & 0xFF); + buf[23] = (uint8_t)(pews & 0xFF); } return DEVICE_GOOD; @@ -2043,12 +1999,8 @@ int filedebug_modeselect(void *device, unsigned char *buf, const size_t size) /* TODO: Create a function to update state for read-only handling */ /* Recalculate read-only condition */ state->unsupported_format = false; - ret = ibm_tape_is_mountable( state->drive_type, - NULL, - state->conf.cart_type, - state->conf.density_code, - false); - switch(ret) { + ret = ibm_tape_is_mountable(state->drive_type, NULL, state->conf.cart_type, state->conf.density_code, false); + switch (ret) { case MEDIUM_PERFECT_MATCH: case MEDIUM_WRITABLE: if (state->conf.emulate_readonly) @@ -2062,8 +2014,7 @@ int filedebug_modeselect(void *device, unsigned char *buf, const size_t size) case MEDIUM_CANNOT_ACCESS: ltfsmsg(LTFS_INFO, 30088I, state->drive_type, state->conf.density_code); state->unsupported_format = true; - if (IS_LTO(state->drive_type)) - return -EDEV_MEDIUM_FORMAT_ERROR; + if (IS_LTO(state->drive_type)) return -EDEV_MEDIUM_FORMAT_ERROR; break; case MEDIUM_UNKNOWN: case MEDIUM_PROBABLY_WRITABLE: @@ -2117,8 +2068,8 @@ int filedebug_allow_medium_removal(void *device) return DEVICE_GOOD; } -int filedebug_read_attribute(void *device, const tape_partition_t part, const uint16_t id - , unsigned char *buf, const size_t size) +int filedebug_read_attribute( + void *device, const tape_partition_t part, const uint16_t id, unsigned char *buf, const size_t size) { struct filedebug_data *state = (struct filedebug_data *)device; char *fname; @@ -2129,8 +2080,7 @@ int filedebug_read_attribute(void *device, const tape_partition_t part, const ui /* Open attribute record */ fname = _filedebug_make_attrname(state, part, id); - if (!fname) - return -EDEV_NO_MEMORY; + if (!fname) return -EDEV_NO_MEMORY; arch_open(&fd, fname, O_RDONLY | O_BINARY, SHARE_FLAG_DENYNO, PERMISSION_READ); free(fname); if (fd < 0) { @@ -2154,8 +2104,7 @@ int filedebug_read_attribute(void *device, const tape_partition_t part, const ui return DEVICE_GOOD; } -int filedebug_write_attribute(void *device, const tape_partition_t part - , const unsigned char *buf, const size_t size) +int filedebug_write_attribute(void *device, const tape_partition_t part, const unsigned char *buf, const size_t size) { struct filedebug_data *state = (struct filedebug_data *)device; char *fname; @@ -2164,8 +2113,7 @@ int filedebug_write_attribute(void *device, const tape_partition_t part uint16_t id, attr_size; size_t i = 0; - while(size > i) - { + while (size > i) { id = ltfs_betou16(buf + i); attr_size = ltfs_betou16(buf + (i + 3)); @@ -2177,10 +2125,7 @@ int filedebug_write_attribute(void *device, const tape_partition_t part ltfsmsg(LTFS_ERR, 30064E); return -EDEV_NO_MEMORY; } - arch_open(&fd, fname, - O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, - SHARE_FLAG_DENYRW, PERMISSION_READWRITE); - + arch_open(&fd, fname, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, SHARE_FLAG_DENYRW, PERMISSION_READWRITE); free(fname); if (fd < 0) { @@ -2230,7 +2175,7 @@ int filedebug_get_eod_status(void *device, int partition) { struct filedebug_data *state = (struct filedebug_data *)device; - if(state->eod[partition] == MISSING_EOD) + if (state->eod[partition] == MISSING_EOD) return EOD_MISSING; else return EOD_GOOD; @@ -2257,14 +2202,13 @@ int filedebug_get_parameters(void *device, struct tc_drive_param *params) { struct filedebug_data *state = (struct filedebug_data *)device; - params->max_blksize = FILE_DEBUG_MAX_BLOCK_SIZE; + params->max_blksize = FILE_DEBUG_MAX_BLOCK_SIZE; - params->cart_type = state->conf.cart_type; - params->density = state->conf.density_code; + params->cart_type = state->conf.cart_type; + params->density = state->conf.density_code; - params->write_protect = 0; - if ( state->conf.emulate_readonly ) - params->write_protect |= VOL_PHYSICAL_WP; + params->write_protect = 0; + if (state->conf.emulate_readonly) params->write_protect |= VOL_PHYSICAL_WP; /* TODO: Following field shall be implemented in the future */ //params->is_encrypted = false; @@ -2296,7 +2240,7 @@ int filedebug_search_eod(struct filedebug_data *state, int partition) struct dirent *entry; state->current_position.partition = partition; - state->current_position.block = 0; + state->current_position.block = 0; /* loop until an EOD mark is found or no record is found */ while ((f[0] || f[1]) && !f[2]) { @@ -2323,18 +2267,18 @@ int filedebug_search_eod(struct filedebug_data *state, int partition) } --state->current_position.block; - if(!f[2] && state->current_position.block != 0) { + if (!f[2] && state->current_position.block != 0) { state->last_block[state->current_position.partition] = state->current_position.block; state->eod[state->current_position.partition] = MISSING_EOD; if (state->conf.dummy_io) { dp = opendir(state->dirname); - if (! dp) { + if (!dp) { ltfsmsg(LTFS_ERR, 30004E, state->dirname); return 0; } while ((entry = readdir(dp))) { - if ( entry->d_name[strlen(entry->d_name) - 1] == 'E') { + if (entry->d_name[strlen(entry->d_name) - 1] == 'E') { entry->d_name[strlen(entry->d_name) - 2] = '\0'; entry->d_name[1] = '\0'; p = atoi(entry->d_name); @@ -2378,8 +2322,7 @@ int _filedebug_write_eod(struct filedebug_data *state) uint64_t i; bool remove_extra_rec = true; - if(state->eod[state->current_position.partition] == MISSING_EOD) - remove_extra_rec = false; + if (state->eod[state->current_position.partition] == MISSING_EOD) remove_extra_rec = false; /* remove any existing record at this position */ ret = _filedebug_remove_current_record(state); @@ -2394,20 +2337,16 @@ int _filedebug_write_eod(struct filedebug_data *state) ltfsmsg(LTFS_ERR, 30072E); return -EDEV_NO_MEMORY; } - arch_open(&fd, fname, - O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, - SHARE_FLAG_DENYRW - , PERMISSION_READWRITE - ); + arch_open(&fd, fname, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, SHARE_FLAG_DENYRW, PERMISSION_READWRITE); free(fname); if (fd < 0 || arch_close(fd) < 0) { ltfsmsg(LTFS_ERR, 30073E, errno); return -EDEV_RW_PERM; } - if(remove_extra_rec) { + if (remove_extra_rec) { /* remove records following this position */ - for (i=state->current_position.block+1; i<=state->eod[state->current_position.partition]; ++i) { + for (i = state->current_position.block + 1; i <= state->eod[state->current_position.partition]; ++i) { ret = _filedebug_remove_record(state, state->current_position.partition, i); if (ret < 0) { ltfsmsg(LTFS_ERR, 30074E, ret); @@ -2426,17 +2365,14 @@ int _filedebug_write_eod(struct filedebug_data *state) */ int _filedebug_remove_current_record(const struct filedebug_data *state) { - return _filedebug_remove_record(state - , state->current_position.partition - , state->current_position.block); + return _filedebug_remove_record(state, state->current_position.partition, state->current_position.block); } /** * Delete the file associated with a given tape position. * @return 1 on successful delete, 0 if no file found, negative on error. */ -int _filedebug_remove_record(const struct filedebug_data *state, - int partition, uint64_t blknum) +int _filedebug_remove_record(const struct filedebug_data *state, int partition, uint64_t blknum) { char *fname; size_t fname_len; @@ -2494,10 +2430,7 @@ int _filedebug_check_file(const char *fname) */ char *_filedebug_make_current_filename(const struct filedebug_data *state, char type) { - return _filedebug_make_filename(state - , state->current_position.partition - , state->current_position.block - , type); + return _filedebug_make_filename(state, state->current_position.partition, state->current_position.block, type); } /** @@ -2505,12 +2438,11 @@ char *_filedebug_make_current_filename(const struct filedebug_data *state, char * Returns a string on success or NULL on failure. The caller is responsible for freeing * the returned memory. Failure probably means asprintf couldn't allocate memory. */ -char *_filedebug_make_filename(const struct filedebug_data *state, - int part, uint64_t pos, char type) +char *_filedebug_make_filename(const struct filedebug_data *state, int part, uint64_t pos, char type) { char *fname; int ret; - ret = asprintf(&fname, "%s/%d_%"PRIu64"_%c", state->dirname, part, pos, type); + ret = asprintf(&fname, "%s/%d_%" PRIu64 "_%c", state->dirname, part, pos, type); if (ret < 0) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return NULL; @@ -2549,21 +2481,17 @@ int _filedebug_space_fm(struct filedebug_data *state, uint64_t count, bool back) uint64_t fm_count = 0; int ret; - if (count == 0) - return DEVICE_GOOD; + if (count == 0) return DEVICE_GOOD; - if (back && state->current_position.block > 0) - --state->current_position.block; + if (back && state->current_position.block > 0) --state->current_position.block; while (1) { - if (!back && - state->current_position.block == state->eod[state->current_position.partition]) { + if (!back && state->current_position.block == state->eod[state->current_position.partition]) { ltfsmsg(LTFS_ERR, 30077E); return -EDEV_EOD_DETECTED; } - if (!back && - state->current_position.block == state->last_block[state->current_position.partition] + 1) { + if (!back && state->current_position.block == state->last_block[state->current_position.partition] + 1) { return -EDEV_RW_PERM; } @@ -2580,8 +2508,7 @@ int _filedebug_space_fm(struct filedebug_data *state, uint64_t count, bool back) } else if (ret > 0) { ++fm_count; if (fm_count == count) { - if (!back) - ++state->current_position.block; + if (!back) ++state->current_position.block; return DEVICE_GOOD; } } @@ -2615,31 +2542,25 @@ int _filedebug_space_rec(struct filedebug_data *state, uint64_t count, bool back uint64_t rec_count = 0; int ret; - if (count == 0) - return DEVICE_GOOD; + if (count == 0) return DEVICE_GOOD; while (1) { - if (!back && - state->current_position.block == state->eod[state->current_position.partition]) { + if (!back && state->current_position.block == state->eod[state->current_position.partition]) { return -EDEV_EOD_DETECTED; } - if (!back && - state->current_position.block == state->last_block[state->current_position.partition] + 1) { + if (!back && state->current_position.block == state->last_block[state->current_position.partition] + 1) { return -EDEV_RW_PERM; } /* check for filemark */ fname = _filedebug_make_current_filename(state, rec_suffixes[SUFFIX_FILEMARK]); - if (!fname) - return -EDEV_NO_MEMORY; + if (!fname) return -EDEV_NO_MEMORY; ret = _filedebug_check_file(fname); free(fname); - if (ret < 0) - return ret; + if (ret < 0) return ret; if (ret > 0 && (!back || rec_count > 0)) { - if (!back) - ++state->current_position.block; + if (!back) ++state->current_position.block; return -EDEV_RW_PERM; } @@ -2667,9 +2588,8 @@ int _get_wp(struct filedebug_data *device, uint64_t *wp) memset(wp_data, 0, sizeof(wp_data)); *wp = 0; - ret = filedebug_read_attribute(device, 0, TC_MAM_PAGE_VCR - , wp_data, sizeof(wp_data)); - if(ret == 0) + ret = filedebug_read_attribute(device, 0, TC_MAM_PAGE_VCR, wp_data, sizeof(wp_data)); + if (ret == 0) *wp = ltfs_betou32(wp_data + 5); else ret = _set_wp(device, (uint64_t)1); @@ -2705,10 +2625,10 @@ int filedebug_get_device_list(struct tc_drive_info *buf, int count) DIR *dp; struct dirent *entry; int deventries = 0; - char *ser= NULL, *pid = NULL, *tmp; + char *ser = NULL, *pid = NULL, *tmp; int i; - if (! original_pid) { + if (!original_pid) { original_pid = (long)arch_getpid(); } @@ -2725,26 +2645,24 @@ int filedebug_get_device_list(struct tc_drive_info *buf, int count) return 0; } else { devdir = fgets(line, sizeof(line), infile); - if(devdir[strlen(devdir) - 1] == '\n') - devdir[strlen(devdir) - 1] = '\0'; + if (devdir[strlen(devdir) - 1] == '\n') devdir[strlen(devdir) - 1] = '\0'; fclose(infile); free(filename); } ltfsmsg(LTFS_INFO, 30083I, devdir); dp = opendir(devdir); - if (! dp) { + if (!dp) { ltfsmsg(LTFS_ERR, 30004E, devdir); return 0; } while ((entry = readdir(dp))) { - if (strncmp(entry->d_name, DRIVE_FILE_PREFIX, strlen(DRIVE_FILE_PREFIX))) - continue; + if (strncmp(entry->d_name, DRIVE_FILE_PREFIX, strlen(DRIVE_FILE_PREFIX))) continue; if (buf && deventries < count) { tmp = arch_strdup(entry->d_name); - if (! *tmp) { + if (!*tmp) { ltfsmsg(LTFS_ERR, 10001E, "filedebug_get_device_list"); return -ENOMEM; } @@ -2767,13 +2685,17 @@ int filedebug_get_device_list(struct tc_drive_info *buf, int count) snprintf(buf[deventries].serial_number, TAPE_SERIAL_LEN_MAX, "%s", ser); snprintf(buf[deventries].product_name, PRODUCT_NAME_LENGTH, "[%s]", pid); - buf[deventries].host = 0; + buf[deventries].host = 0; buf[deventries].channel = 0; - buf[deventries].target = 0; - buf[deventries].lun = -1; + buf[deventries].target = 0; + buf[deventries].lun = -1; - ltfsmsg(LTFS_DEBUG, 30084D, buf[deventries].name, buf[deventries].vendor, - buf[deventries].model, buf[deventries].serial_number); + ltfsmsg(LTFS_DEBUG, + 30084D, + buf[deventries].name, + buf[deventries].vendor, + buf[deventries].model, + buf[deventries].serial_number); free(tmp); } @@ -2802,17 +2724,15 @@ int filedebug_takedump_drive(void *device, bool nonforced_dump) return DEVICE_GOOD; } -int filedebug_is_mountable(void *device, const char *barcode, const unsigned char cart_type, - const unsigned char density) +int filedebug_is_mountable(void *device, + const char *barcode, + const unsigned char cart_type, + const unsigned char density) { int ret; struct filedebug_data *state = (struct filedebug_data *)device; - ret = ibm_tape_is_mountable( state->drive_type, - barcode, - cart_type, - density, - global_data.strict_drive); + ret = ibm_tape_is_mountable(state->drive_type, barcode, cart_type, density, global_data.strict_drive); return ret; } @@ -2822,11 +2742,8 @@ bool filedebug_is_readonly(void *device) int ret; struct filedebug_data *state = (struct filedebug_data *)device; - ret = ibm_tape_is_mountable( state->drive_type, - NULL, - state->conf.cart_type, - state->conf.density_code, - global_data.strict_drive); + ret = ibm_tape_is_mountable( + state->drive_type, NULL, state->conf.cart_type, state->conf.density_code, global_data.strict_drive); if (ret == MEDIUM_READONLY) return true; @@ -2850,12 +2767,11 @@ int filedebug_get_serialnumber(void *device, char **result) CHECK_ARG_NULL(result, -LTFS_NULL_ARG); if (state->serial_number) - *result = arch_strdup((const char*)state->serial_number); + *result = arch_strdup((const char *)state->serial_number); else *result = arch_strdup("DUMMY"); - if (! *result) - return -EDEV_NO_MEMORY; + if (!*result) return -EDEV_NO_MEMORY; return DEVICE_GOOD; } @@ -2880,68 +2796,68 @@ int filedebug_get_next_block_to_xfer(void *device, struct tc_position *pos) struct filedebug_data *state = (struct filedebug_data *)device; pos->partition = state->current_position.partition; - pos->block = state->current_position.block - THRESHOLD_FORCE_WRITE_NO_WRITE; + pos->block = state->current_position.block - THRESHOLD_FORCE_WRITE_NO_WRITE; return 0; } struct tape_ops filedebug_handler = { - .open = filedebug_open, - .reopen = filedebug_reopen, - .close = filedebug_close, - .close_raw = filedebug_close_raw, - .is_connected = filedebug_is_connected, - .inquiry = filedebug_inquiry, - .inquiry_page = filedebug_inquiry_page, - .test_unit_ready = filedebug_test_unit_ready, - .read = filedebug_read, - .write = filedebug_write, - .writefm = filedebug_writefm, - .rewind = filedebug_rewind, - .locate = filedebug_locate, - .space = filedebug_space, - .erase = filedebug_erase, - .load = filedebug_load, - .unload = filedebug_unload, - .readpos = filedebug_readpos, - .setcap = filedebug_setcap, - .format = filedebug_format, - .remaining_capacity = filedebug_remaining_capacity, - .logsense = filedebug_logsense, - .modesense = filedebug_modesense, - .modeselect = filedebug_modeselect, - .reserve_unit = filedebug_reserve_unit, - .release_unit = filedebug_release_unit, + .open = filedebug_open, + .reopen = filedebug_reopen, + .close = filedebug_close, + .close_raw = filedebug_close_raw, + .is_connected = filedebug_is_connected, + .inquiry = filedebug_inquiry, + .inquiry_page = filedebug_inquiry_page, + .test_unit_ready = filedebug_test_unit_ready, + .read = filedebug_read, + .write = filedebug_write, + .writefm = filedebug_writefm, + .rewind = filedebug_rewind, + .locate = filedebug_locate, + .space = filedebug_space, + .erase = filedebug_erase, + .load = filedebug_load, + .unload = filedebug_unload, + .readpos = filedebug_readpos, + .setcap = filedebug_setcap, + .format = filedebug_format, + .remaining_capacity = filedebug_remaining_capacity, + .logsense = filedebug_logsense, + .modesense = filedebug_modesense, + .modeselect = filedebug_modeselect, + .reserve_unit = filedebug_reserve_unit, + .release_unit = filedebug_release_unit, .prevent_medium_removal = filedebug_prevent_medium_removal, - .allow_medium_removal = filedebug_allow_medium_removal, - .write_attribute = filedebug_write_attribute, - .read_attribute = filedebug_read_attribute, - .allow_overwrite = filedebug_allow_overwrite, - .grao = filedebug_grao, - .rrao = filedebug_rrao, - .set_compression = filedebug_set_compression, - .set_default = filedebug_set_default, - .get_cartridge_health = filedebug_get_cartridge_health, - .get_tape_alert = filedebug_get_tape_alert, - .clear_tape_alert = filedebug_clear_tape_alert, - .get_xattr = filedebug_get_xattr, - .set_xattr = filedebug_set_xattr, - .get_parameters = filedebug_get_parameters, - .get_eod_status = filedebug_get_eod_status, - .get_device_list = filedebug_get_device_list, - .help_message = filedebug_help_message, - .parse_opts = filedebug_parse_opts, - .default_device_name = filedebug_default_device_name, - .set_key = filedebug_set_key, - .get_keyalias = filedebug_get_keyalias, - .takedump_drive = filedebug_takedump_drive, - .is_mountable = filedebug_is_mountable, - .get_worm_status = filedebug_get_worm_status, - .get_serialnumber = filedebug_get_serialnumber, - .get_info = filedebug_get_info, - .set_profiler = filedebug_set_profiler, + .allow_medium_removal = filedebug_allow_medium_removal, + .write_attribute = filedebug_write_attribute, + .read_attribute = filedebug_read_attribute, + .allow_overwrite = filedebug_allow_overwrite, + .grao = filedebug_grao, + .rrao = filedebug_rrao, + .set_compression = filedebug_set_compression, + .set_default = filedebug_set_default, + .get_cartridge_health = filedebug_get_cartridge_health, + .get_tape_alert = filedebug_get_tape_alert, + .clear_tape_alert = filedebug_clear_tape_alert, + .get_xattr = filedebug_get_xattr, + .set_xattr = filedebug_set_xattr, + .get_parameters = filedebug_get_parameters, + .get_eod_status = filedebug_get_eod_status, + .get_device_list = filedebug_get_device_list, + .help_message = filedebug_help_message, + .parse_opts = filedebug_parse_opts, + .default_device_name = filedebug_default_device_name, + .set_key = filedebug_set_key, + .get_keyalias = filedebug_get_keyalias, + .takedump_drive = filedebug_takedump_drive, + .is_mountable = filedebug_is_mountable, + .get_worm_status = filedebug_get_worm_status, + .get_serialnumber = filedebug_get_serialnumber, + .get_info = filedebug_get_info, + .set_profiler = filedebug_set_profiler, .get_next_block_to_xfer = filedebug_get_next_block_to_xfer, - .is_readonly = filedebug_is_readonly, + .is_readonly = filedebug_is_readonly, }; struct tape_ops *tape_dev_get_ops(void) diff --git a/src/tape_drivers/generic/itdtimg/itdtimg_tc.c b/src/tape_drivers/generic/itdtimg/itdtimg_tc.c index ac6d97a6..b5084444 100644 --- a/src/tape_drivers/generic/itdtimg/itdtimg_tc.c +++ b/src/tape_drivers/generic/itdtimg/itdtimg_tc.c @@ -51,107 +51,102 @@ ************************************************************************************* */ #ifdef mingw_PLATFORM -#include "libltfs/arch/win/win_util.h" +# include "libltfs/arch/win/win_util.h" #endif -#include -#include -#include -#include -#include -#include -#include -#include +#include #include -#include -#include +#include +#include #include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include "libltfs/ltfs_fuse_version.h" #include -#include "ltfs_copyright.h" -#include "libltfs/ltfslogging.h" #include "libltfs/ltfs.h" #include "libltfs/ltfs_endian.h" -#include "libltfs/tape_ops.h" #include "libltfs/ltfs_error.h" +#include "libltfs/ltfslogging.h" +#include "libltfs/tape_ops.h" +#include "ltfs_copyright.h" -volatile char *copyright = LTFS_COPYRIGHT_0"\n"LTFS_COPYRIGHT_1"\n"LTFS_COPYRIGHT_2"\n" \ - LTFS_COPYRIGHT_3"\n"LTFS_COPYRIGHT_4"\n"LTFS_COPYRIGHT_5"\n"; +volatile char *copyright = LTFS_COPYRIGHT_0 "\n" LTFS_COPYRIGHT_1 "\n" LTFS_COPYRIGHT_2 "\n" LTFS_COPYRIGHT_3 + "\n" LTFS_COPYRIGHT_4 "\n" LTFS_COPYRIGHT_5 "\n"; /* Default directory where the emulated tape contents go to */ const char *itdtimage_default_device = "tape.img"; #define DEBUG 0 #define MAX_PARTITIONS 2 -#define KB (1024) -#define MB (KB * 1024) -#define GB (MB * 1024) +#define KB (1024) +#define MB (KB * 1024) +#define GB (MB * 1024) #define FILE_DEBUG_MAX_BLOCK_SIZE (4 * MB) #define XML_MIN_DATA_SIZE 1024 /* O_BINARY is defined only in MinGW */ #ifndef O_BINARY -#define O_BINARY 0 +# define O_BINARY 0 #endif #define MISSING_EOD (0xFFFFFFFFFFFFFFFFLL) /* For drive link feature */ #ifdef mingw_PLATFORM -#define DRIVE_LIST_DIR "ltfs" +# define DRIVE_LIST_DIR "ltfs" #else -#define DRIVE_LIST_DIR "/tmp" +# define DRIVE_LIST_DIR "/tmp" #endif /** * Emulator-specific data structures, used in lieu of a file descriptor */ -const int itdtimage_attributes[] = { 0x9, - 0x800, - 0x801, - 0x802, - 0x803, - 0x805, - 0x806, - 0x80b, - 0x80c}; - -struct itdtimage_runlist { - long long count_rec; /**< Record Count */ - long long length_rec; /**< Length of the record */ - long long pos_tape; /**< Tape position */ - long long offset_img; /**< Offset of the image */ +const int itdtimage_attributes[] = { 0x9, 0x800, 0x801, 0x802, 0x803, 0x805, 0x806, 0x80b, 0x80c }; + +struct itdtimage_runlist +{ + long long count_rec; /**< Record Count */ + long long length_rec; /**< Length of the record */ + long long pos_tape; /**< Tape position */ + long long offset_img; /**< Offset of the image */ }; -struct itdtimage_attrlist { +struct itdtimage_attrlist +{ unsigned char partition; - short attr_id; - short length; - long long offset_img; + short attr_id; + short length; + long long offset_img; }; -struct itdtimage_data { - bool device_reserved; /**< True when the device has been successfully reserved */ - bool medium_locked; /**< True when preventing medium removal by the user */ +struct itdtimage_data +{ + bool device_reserved; /**< True when the device has been successfully reserved */ + bool medium_locked; /**< True when preventing medium removal by the user */ struct tc_position current_position; /**< Current tape position (partition, block) */ - uint32_t max_block_size; /**< Maximum block size, in bytes */ - char *filename; /**< File contains the pointer to directory where blocks reside */ - bool ready; /**< Is the "tape" loaded? */ + uint32_t max_block_size; /**< Maximum block size, in bytes */ + char *filename; /**< File contains the pointer to directory where blocks reside */ + bool ready; /**< Is the "tape" loaded? */ uint64_t last_block[MAX_PARTITIONS]; /**< Last positions for all partitions */ - uint64_t eod[MAX_PARTITIONS]; /**< Append positions (1 + last block) for all partitions */ + uint64_t eod[MAX_PARTITIONS]; /**< Append positions (1 + last block) for all partitions */ - uint64_t write_pass_prev; /**< Previous write Pass */ - uint64_t write_pass; /**< Current write Pass of LTO drive for consistency check*/ + uint64_t write_pass_prev; /**< Previous write Pass */ + uint64_t write_pass; /**< Current write Pass of LTO drive for consistency check*/ int rll_count; struct itdtimage_runlist *runlist; int attr_count; struct itdtimage_attrlist *attr_info; FILE *img_file; - int partitions; /**< Number of available partitions */ + int partitions; /**< Number of available partitions */ unsigned long long part1_img_offset; unsigned long long part_unit_size; unsigned long long part0_size; @@ -160,20 +155,20 @@ struct itdtimage_data { char version; unsigned long long byte_count; unsigned long long density_code; - char *serial_number; /**< Serial number of this dummy tape device */ + char *serial_number; /**< Serial number of this dummy tape device */ }; /* local prototypes */ int _itdtimage_write_eod(struct itdtimage_data *state); int _itdtimage_remove_current_record(const struct itdtimage_data *state); -int _itdtimage_remove_record(const struct itdtimage_data *state,int partition, uint64_t blknum); +int _itdtimage_remove_record(const struct itdtimage_data *state, int partition, uint64_t blknum); int _itdtimage_space_fm(struct itdtimage_data *state, uint64_t count, bool back); int _itdtimage_space_rec(struct itdtimage_data *state, uint64_t count, bool back); long long _itdtimage_getattr_offest(const struct itdtimage_data *state, int part, int id); long long _itdtimage_getattr_len(const struct itdtimage_data *state, int part, int id); -long long _itdtimage_getrec_offset(const struct itdtimage_data *state,int part, uint64_t pos); -long long _itdtimage_getrec_len(const struct itdtimage_data *state,int part, uint64_t pos); +long long _itdtimage_getrec_offset(const struct itdtimage_data *state, int part, uint64_t pos); +long long _itdtimage_getrec_len(const struct itdtimage_data *state, int part, uint64_t pos); int _itdtimage_free(struct itdtimage_data *state); char *memstr(const char *s, const char *find, size_t slen); @@ -183,9 +178,7 @@ unsigned long long _get_file_size(FILE *fStream); unsigned long long _seek_file(FILE *file, unsigned long long position); /* Command-line options recognized by this module */ -static struct fuse_opt filedebug_opts[] = { - FUSE_OPT_END -}; +static struct fuse_opt filedebug_opts[] = { FUSE_OPT_END }; int null_parser(void *priv, const char *arg, int key, struct fuse_args *outargs) { @@ -194,13 +187,12 @@ int null_parser(void *priv, const char *arg, int key, struct fuse_args *outargs) int itdtimage_parse_opts(void *vstate, void *opt_args) { - struct itdtimage_data *state = (struct itdtimage_data *) vstate; - struct fuse_args *args = (struct fuse_args *) opt_args; + struct itdtimage_data *state = (struct itdtimage_data *)vstate; + struct fuse_args *args = (struct fuse_args *)opt_args; int ret; /* fuse_opt_parse can handle a NULL device parameter just fine */ ret = fuse_opt_parse(args, state, filedebug_opts, null_parser); - if (ret < 0) - return ret; + if (ret < 0) return ret; return 0; } @@ -226,7 +218,7 @@ int itdtimage_open(const char *name, void **handle) CHECK_ARG_NULL(handle, -LTFS_NULL_ARG); *handle = NULL; - state = (struct itdtimage_data *)calloc(1,sizeof(struct itdtimage_data)); + state = (struct itdtimage_data *)calloc(1, sizeof(struct itdtimage_data)); if (!state) { ltfsmsg(LTFS_ERR, 10001E, "itdtimage_open: private data"); return -EDEV_NO_MEMORY; @@ -238,13 +230,13 @@ int itdtimage_open(const char *name, void **handle) * open image file */ state->img_file = fopen(name, "r"); - if ( !state->img_file ) { + if (!state->img_file) { ltfsmsg(LTFS_ERR, 31001E, name, "fopen", (unsigned long long)errno); _itdtimage_free(state); return -EDEV_DEVICE_UNOPENABLE; } state->filename = arch_strdup(name); - if ( !state->filename ) { + if (!state->filename) { ltfsmsg(LTFS_ERR, 10001E, "itdtimage_open: filename"); _itdtimage_free(state); return -EDEV_NO_MEMORY; @@ -252,10 +244,9 @@ int itdtimage_open(const char *name, void **handle) /* seek to end of image file */ length = _get_file_size(state->img_file); - if ( length < XML_MIN_DATA_SIZE) - read_length = length; - if (_seek_file(state->img_file, length-read_length)!=0){ - ltfsmsg(LTFS_ERR, 31002E, (long long)length-read_length, state->filename, (unsigned long long)errno); + if (length < XML_MIN_DATA_SIZE) read_length = length; + if (_seek_file(state->img_file, length - read_length) != 0) { + ltfsmsg(LTFS_ERR, 31002E, (long long)length - read_length, state->filename, (unsigned long long)errno); _itdtimage_free(state); return -EDEV_HARDWARE_ERROR; } @@ -264,44 +255,46 @@ int itdtimage_open(const char *name, void **handle) * letzte 2K aus image file auslese * allocate memory: */ - buffer = calloc (1,read_length); - if (buffer==NULL){ + buffer = calloc(1, read_length); + if (buffer == NULL) { // add debug message _itdtimage_free(state); return -EDEV_NO_MEMORY; } /* read data as a block */ - bytes_read = fread(buffer,1,read_length,state->img_file); - if (bytes_read!=read_length){ + bytes_read = fread(buffer, 1, read_length, state->img_file); + if (bytes_read != read_length) { _itdtimage_free(state); free(buffer); return -EDEV_HARDWARE_ERROR; } /* XML tags and values read from the end of the image file */ - state->rll_count = _read_XML_tag_value(buffer,bytes_read, "rllCount"); - state->partitions = _read_XML_tag_value(buffer,bytes_read, "partitionCount"); - state->part_unit_size = _read_XML_tag_value(buffer,bytes_read, "partitionUnitSize"); - state->part0_size = _read_XML_tag_value(buffer,bytes_read, "partitionSize_0"); - state->part1_size = _read_XML_tag_value(buffer,bytes_read, "partitionSize_1"); - state->vcilength = _read_XML_tag_value(buffer,bytes_read, "vcilength"); - state->version = _read_XML_tag_value(buffer,bytes_read, "version"); - state->byte_count = _read_XML_tag_value(buffer,bytes_read, "byteCount"); - state->density_code = _read_XML_tag_value(buffer,bytes_read, "densityCode"); - - if ( ! state->rll_count ){ - ltfsmsg(LTFS_ERR, 31001E, state->filename, "Meta Info [rll_count] is not valid", (unsigned long long)state->rll_count); + state->rll_count = _read_XML_tag_value(buffer, bytes_read, "rllCount"); + state->partitions = _read_XML_tag_value(buffer, bytes_read, "partitionCount"); + state->part_unit_size = _read_XML_tag_value(buffer, bytes_read, "partitionUnitSize"); + state->part0_size = _read_XML_tag_value(buffer, bytes_read, "partitionSize_0"); + state->part1_size = _read_XML_tag_value(buffer, bytes_read, "partitionSize_1"); + state->vcilength = _read_XML_tag_value(buffer, bytes_read, "vcilength"); + state->version = _read_XML_tag_value(buffer, bytes_read, "version"); + state->byte_count = _read_XML_tag_value(buffer, bytes_read, "byteCount"); + state->density_code = _read_XML_tag_value(buffer, bytes_read, "densityCode"); + + if (!state->rll_count) { + ltfsmsg( + LTFS_ERR, 31001E, state->filename, "Meta Info [rll_count] is not valid", (unsigned long long)state->rll_count); _itdtimage_free(state); free(buffer); return -EDEV_DEVICE_UNOPENABLE; } - if ( state->version < 2 ){ - ltfsmsg(LTFS_ERR, 31001E, state->filename, "Unsupported ITDT Image file version", (unsigned long long)state->version); + if (state->version < 2) { + ltfsmsg( + LTFS_ERR, 31001E, state->filename, "Unsupported ITDT Image file version", (unsigned long long)state->version); _itdtimage_free(state); free(buffer); return -EDEV_DEVICE_UNOPENABLE; } - if ( ! state->byte_count ){ + if (!state->byte_count) { ltfsmsg(LTFS_ERR, 31001E, state->filename, "Meta Info [byte_count] is not valid", state->byte_count); _itdtimage_free(state); free(buffer); @@ -309,60 +302,60 @@ int itdtimage_open(const char *name, void **handle) } /* allocate memory for rllList */ - state->runlist = (struct itdtimage_runlist*)malloc(state->rll_count * sizeof(struct itdtimage_runlist)); - if (state->runlist==NULL){ + state->runlist = (struct itdtimage_runlist *)malloc(state->rll_count * sizeof(struct itdtimage_runlist)); + if (state->runlist == NULL) { _itdtimage_free(state); free(buffer); return -EDEV_NO_MEMORY; } - state->attr_count=0; - for (int partition=0; partition<2; partition++) { - for (j = 0; j < (int)(sizeof(itdtimage_attributes)/sizeof(int)); j++) { + state->attr_count = 0; + for (int partition = 0; partition < 2; partition++) { + for (j = 0; j < (int)(sizeof(itdtimage_attributes) / sizeof(int)); j++) { int attr = itdtimage_attributes[j]; char attrTag[50]; char *stringValue; - sprintf(attrTag,"attr_%d_%x",partition,attr); - if ((stringValue=_read_XML_tag(buffer,read_length,attrTag))!=NULL) { + sprintf(attrTag, "attr_%d_%x", partition, attr); + if ((stringValue = _read_XML_tag(buffer, read_length, attrTag)) != NULL) { free(stringValue); state->attr_count++; } } } - if (state->attr_count==0){ + if (state->attr_count == 0) { ltfsmsg(LTFS_ERR, 31001E, state->filename, "Meta Info [attr_] is not valid", (unsigned long long)state->attr_count); _itdtimage_free(state); free(buffer); return -EDEV_DEVICE_UNOPENABLE; } - state->attr_info = (struct itdtimage_attrlist*)malloc(state->attr_count*sizeof(struct itdtimage_attrlist)); - if (state->attr_info==NULL){ + state->attr_info = (struct itdtimage_attrlist *)malloc(state->attr_count * sizeof(struct itdtimage_attrlist)); + if (state->attr_info == NULL) { _itdtimage_free(state); free(buffer); return -EDEV_NO_MEMORY; } index = 0; - for (partition = 0; partition < 2; partition++) { - for (j = 0; j < (int)(sizeof(itdtimage_attributes)/sizeof(int)); j++) { + for (partition = 0; partition < 2; partition++) { + for (j = 0; j < (int)(sizeof(itdtimage_attributes) / sizeof(int)); j++) { char attrTag[50]; - int attr=itdtimage_attributes[j]; + int attr = itdtimage_attributes[j]; char *stringValue; - sprintf(attrTag,"attr_%d_%x",partition,attr); - if ((stringValue=_read_XML_tag(buffer,read_length,attrTag))!=NULL){ + sprintf(attrTag, "attr_%d_%x", partition, attr); + if ((stringValue = _read_XML_tag(buffer, read_length, attrTag)) != NULL) { long long offset, length; sscanf(stringValue, "%lld,%lld", &offset, &length); - state->attr_info[index].attr_id=attr; - state->attr_info[index].partition=partition; - state->attr_info[index].length=length; - state->attr_info[index].offset_img=offset; + state->attr_info[index].attr_id = attr; + state->attr_info[index].partition = partition; + state->attr_info[index].length = length; + state->attr_info[index].offset_img = offset; index++; } } } /* fill rllList with data from image file */ - if ( _seek_file(state->img_file, state->byte_count) ) { + if (_seek_file(state->img_file, state->byte_count)) { ltfsmsg(LTFS_ERR, 31002E, (long long)state->byte_count, state->filename, (unsigned long long)errno); _itdtimage_free(state); free(buffer); @@ -370,43 +363,40 @@ int itdtimage_open(const char *name, void **handle) } offset = num_rec = 0; - currentPartition=0; + currentPartition = 0; for (i = 0; i < MAX_PARTITIONS; i++) state->eod[currentPartition] = MISSING_EOD; for (i = 0; i < state->rll_count; i++) { - int index=0; + int index = 0; long long xferSize = 0; long long count = 0; - memset(buffer,0,sizeof(read_length)); + memset(buffer, 0, sizeof(read_length)); do { - bytes_read =fread(buffer+index,1,1,state->img_file); + bytes_read = fread(buffer + index, 1, 1, state->img_file); index++; - }while ((bytes_read==1) && (buffer[index-1]!=0xa)); + } while ((bytes_read == 1) && (buffer[index - 1] != 0xa)); sscanf(buffer, "%lld,%lld", &xferSize, &count); - state->runlist[i].length_rec=xferSize; - state->runlist[i].count_rec=count; - state->runlist[i].offset_img=offset; - state->runlist[i].pos_tape=num_rec; - if(count>0) - num_rec += count; - - if(xferSize > 0) - offset += xferSize*count; - else - if (xferSize == -1){ - state->eod[currentPartition]=num_rec-1; - num_rec = 0; - currentPartition++; - /* Add marker for end of partition 0 */ - if(state->part1_img_offset == 0) - state->part1_img_offset = i+1; - } + state->runlist[i].length_rec = xferSize; + state->runlist[i].count_rec = count; + state->runlist[i].offset_img = offset; + state->runlist[i].pos_tape = num_rec; + if (count > 0) num_rec += count; + + if (xferSize > 0) + offset += xferSize * count; + else if (xferSize == -1) { + state->eod[currentPartition] = num_rec - 1; + num_rec = 0; + currentPartition++; + /* Add marker for end of partition 0 */ + if (state->part1_img_offset == 0) state->part1_img_offset = i + 1; + } } state->ready = false; state->max_block_size = 16 * MB; - *handle = (void *) state; + *handle = (void *)state; free(buffer); return 0; } @@ -428,14 +418,10 @@ int itdtimage_close(void *vstate) int _itdtimage_free(struct itdtimage_data *state) { if (state) { - if (state->filename) - free(state->filename); - if (state->runlist) - free(state->runlist); - if (state->attr_info) - free(state->attr_info); - if (state->img_file) - fclose(state->img_file); + if (state->filename) free(state->filename); + if (state->runlist) free(state->runlist); + if (state->attr_info) free(state->attr_info); + if (state->img_file) fclose(state->img_file); free(state); } return 0; @@ -466,22 +452,23 @@ int itdtimage_inquiry_page(void *vstate, unsigned char page, struct tc_inq_page int itdtimage_test_unit_ready(void *vstate) { struct itdtimage_data *state = (struct itdtimage_data *)vstate; - if (!state->ready) - return -EDEV_NEED_INITIALIZE; + if (!state->ready) return -EDEV_NEED_INITIALIZE; return DEVICE_GOOD; } -int itdtimage_read(void *vstate, char *buf, size_t count, struct tc_position *pos, - const bool unusual_size) +int itdtimage_read(void *vstate, char *buf, size_t count, struct tc_position *pos, const bool unusual_size) { struct itdtimage_data *state = (struct itdtimage_data *)vstate; int ret; long long offset; size_t length_rec; - ltfsmsg(LTFS_DEBUG, 31004D, (unsigned long long)count, state->current_position.partition, - (unsigned long long)state->current_position.block, - (unsigned long long)state->current_position.filemarks); + ltfsmsg(LTFS_DEBUG, + 31004D, + (unsigned long long)count, + state->current_position.partition, + (unsigned long long)state->current_position.block, + (unsigned long long)state->current_position.filemarks); if (!state->ready) { ltfsmsg(LTFS_ERR, 31005E); @@ -494,15 +481,14 @@ int itdtimage_read(void *vstate, char *buf, size_t count, struct tc_position *po } offset = _itdtimage_getrec_offset(state, state->current_position.partition, state->current_position.block); - if (offset==-1){ + if (offset == -1) { return -EDEV_HARDWARE_ERROR; } length_rec = _itdtimage_getrec_len(state, state->current_position.partition, state->current_position.block); - if (count < length_rec) - length_rec=count; - if ( _seek_file(state->img_file, offset) ){ - ltfsmsg(LTFS_ERR, 31002E , (long long)length_rec, state->filename, offset); + if (count < length_rec) length_rec = count; + if (_seek_file(state->img_file, offset)) { + ltfsmsg(LTFS_ERR, 31002E, (long long)length_rec, state->filename, offset); return -EDEV_HARDWARE_ERROR; } @@ -547,8 +533,7 @@ int itdtimage_locate(void *vstate, struct tc_position dest, struct tc_position * tape_filemarks_t count_fm = 0; int i; - ltfsmsg(LTFS_DEBUG, 31197D, "locate", (unsigned long long)dest.partition, - (unsigned long long)dest.block); + ltfsmsg(LTFS_DEBUG, 31197D, "locate", (unsigned long long)dest.partition, (unsigned long long)dest.block); if (!state->ready) { ltfsmsg(LTFS_ERR, 31007E); @@ -562,21 +547,18 @@ int itdtimage_locate(void *vstate, struct tc_position dest, struct tc_position * } state->current_position.partition = dest.partition; - if (state->eod[dest.partition] == MISSING_EOD && - state->last_block[dest.partition] < dest.block) + if (state->eod[dest.partition] == MISSING_EOD && state->last_block[dest.partition] < dest.block) state->current_position.block = state->last_block[dest.partition] + 1; else if (state->eod[dest.partition] < dest.block) state->current_position.block = state->eod[dest.partition]; else state->current_position.block = dest.block; pos->partition = state->current_position.partition; - pos->block = state->current_position.block; + pos->block = state->current_position.block; - for(i = 0; i < state->rll_count; i++) { - if ( state->runlist[i].pos_tape >= (long long)state->current_position.block ) - break; - if ( ! state->runlist[i].length_rec ) - count_fm++; + for (i = 0; i < state->rll_count; i++) { + if (state->runlist[i].pos_tape >= (long long)state->current_position.block) break; + if (!state->runlist[i].length_rec) count_fm++; } rc = 0; state->current_position.filemarks = count_fm; @@ -595,71 +577,70 @@ int itdtimage_space(void *vstate, size_t count, TC_SPACE_TYPE type, struct tc_po return rc; } - switch(type) { - case TC_SPACE_EOD: - ltfsmsg(LTFS_DEBUG, 31195D, "space to EOD"); - state->current_position.block = state->eod[state->current_position.partition]; - if(state->current_position.block == MISSING_EOD) { - rc = -EDEV_RW_PERM; - return rc; - } else - rc = 0; - break; - case TC_SPACE_FM_F: - ltfsmsg(LTFS_DEBUG, 31196D, "space forward file marks", (unsigned long long)count); - if(state->current_position.block == MISSING_EOD) { - rc = -EDEV_RW_PERM; - return rc; - } else - rc = _itdtimage_space_fm(state, count, false); - break; - case TC_SPACE_FM_B: - ltfsmsg(LTFS_DEBUG, 31196D, "space back file marks", (unsigned long long)count); - if(state->current_position.block == MISSING_EOD) { - rc = -EDEV_RW_PERM; - return rc; - } else - rc = _itdtimage_space_fm(state, count, true); - break; - case TC_SPACE_F: - ltfsmsg(LTFS_DEBUG, 31196D, "space forward records", (unsigned long long)count); - if(state->current_position.block == MISSING_EOD) { - rc = -EDEV_RW_PERM; - return rc; - } else - rc = _itdtimage_space_rec(state, count, false); - break; - case TC_SPACE_B: - ltfsmsg(LTFS_DEBUG, 31196D, "space back records", (unsigned long long)count); - if(state->current_position.block == MISSING_EOD) { - rc = -EDEV_RW_PERM; + switch (type) { + case TC_SPACE_EOD: + ltfsmsg(LTFS_DEBUG, 31195D, "space to EOD"); + state->current_position.block = state->eod[state->current_position.partition]; + if (state->current_position.block == MISSING_EOD) { + rc = -EDEV_RW_PERM; + return rc; + } else + rc = 0; + break; + case TC_SPACE_FM_F: + ltfsmsg(LTFS_DEBUG, 31196D, "space forward file marks", (unsigned long long)count); + if (state->current_position.block == MISSING_EOD) { + rc = -EDEV_RW_PERM; + return rc; + } else + rc = _itdtimage_space_fm(state, count, false); + break; + case TC_SPACE_FM_B: + ltfsmsg(LTFS_DEBUG, 31196D, "space back file marks", (unsigned long long)count); + if (state->current_position.block == MISSING_EOD) { + rc = -EDEV_RW_PERM; + return rc; + } else + rc = _itdtimage_space_fm(state, count, true); + break; + case TC_SPACE_F: + ltfsmsg(LTFS_DEBUG, 31196D, "space forward records", (unsigned long long)count); + if (state->current_position.block == MISSING_EOD) { + rc = -EDEV_RW_PERM; + return rc; + } else + rc = _itdtimage_space_rec(state, count, false); + break; + case TC_SPACE_B: + ltfsmsg(LTFS_DEBUG, 31196D, "space back records", (unsigned long long)count); + if (state->current_position.block == MISSING_EOD) { + rc = -EDEV_RW_PERM; + return rc; + } else + rc = _itdtimage_space_rec(state, count, true); + break; + default: + ltfsmsg(LTFS_ERR, 31010E); + rc = -EDEV_INVALID_ARG; return rc; - } else - rc = _itdtimage_space_rec(state, count, true); - break; - default: - ltfsmsg(LTFS_ERR, 31010E); - rc = -EDEV_INVALID_ARG; - return rc; } pos->block = state->current_position.block; - for(int i = 0; i < (int)state->rll_count; i++) { - if (state->runlist[i].pos_tape>=(long long)state->current_position.block) - break; - if (state->runlist[i].length_rec==0) - count_fm++; + for (int i = 0; i < (int)state->rll_count; i++) { + if (state->runlist[i].pos_tape >= (long long)state->current_position.block) break; + if (state->runlist[i].length_rec == 0) count_fm++; } state->current_position.filemarks = count_fm; pos->filemarks = state->current_position.filemarks; - ltfsmsg(LTFS_DEBUG, 31011D, - (unsigned long long)state->current_position.partition, - (unsigned long long)state->current_position.block, - (unsigned long long)state->current_position.filemarks, - (int)state->device_reserved, - (int)state->medium_locked, - (int)state->ready); + ltfsmsg(LTFS_DEBUG, + 31011D, + (unsigned long long)state->current_position.partition, + (unsigned long long)state->current_position.block, + (unsigned long long)state->current_position.filemarks, + (int)state->device_reserved, + (int)state->medium_locked, + (int)state->ready); return rc; } @@ -680,7 +661,7 @@ int itdtimage_erase(void *vstate, struct tc_position *pos, bool long_erase) } ltfsmsg(LTFS_DEBUG, 31022D, (unsigned long)state->current_position.partition); - pos->block = state->current_position.block; + pos->block = state->current_position.block; pos->filemarks = state->current_position.filemarks; ret = _itdtimage_write_eod(state); @@ -691,17 +672,16 @@ int itdtimage_load(void *vstate, struct tc_position *pos) { struct itdtimage_data *state = (struct itdtimage_data *)vstate; - if (state->ready) - return DEVICE_GOOD; /* already loaded the tape */ + if (state->ready) return DEVICE_GOOD; /* already loaded the tape */ state->ready = true; state->current_position.partition = 0; - state->current_position.block = 0; + state->current_position.block = 0; state->current_position.filemarks = 0; state->partitions = MAX_PARTITIONS; state->write_pass_prev = 0; state->write_pass = 0; pos->partition = state->current_position.partition; - pos->block = state->current_position.block; + pos->block = state->current_position.block; pos->filemarks = state->current_position.filemarks; return DEVICE_GOOD; } @@ -711,10 +691,10 @@ int itdtimage_unload(void *vstate, struct tc_position *pos) struct itdtimage_data *state = (struct itdtimage_data *)vstate; state->ready = false; state->current_position.partition = 0; - state->current_position.block = 0; + state->current_position.block = 0; state->current_position.filemarks = 0; pos->partition = state->current_position.partition; - pos->block = state->current_position.block; + pos->block = state->current_position.block; pos->filemarks = state->current_position.filemarks; return DEVICE_GOOD; } @@ -732,9 +712,12 @@ int itdtimage_readpos(void *vstate, struct tc_position *pos) pos->block = state->current_position.block; pos->filemarks = state->current_position.filemarks; - ltfsmsg(LTFS_DEBUG, 31198D, "readpos", (unsigned long long)state->current_position.partition, - (unsigned long long)state->current_position.block, - (unsigned long long)state->current_position.filemarks); + ltfsmsg(LTFS_DEBUG, + 31198D, + "readpos", + (unsigned long long)state->current_position.partition, + (unsigned long long)state->current_position.block, + (unsigned long long)state->current_position.filemarks); return DEVICE_GOOD; } @@ -743,9 +726,7 @@ int itdtimage_setcap(void *vstate, uint16_t proportion) struct itdtimage_data *state = (struct itdtimage_data *)vstate; struct tc_position pos; - if(state->current_position.partition != 0 || - state->current_position.block != 0) - { + if (state->current_position.partition != 0 || state->current_position.block != 0) { ltfsmsg(LTFS_ERR, 31013E); return -EDEV_ILLEGAL_REQUEST; } @@ -763,29 +744,28 @@ int itdtimage_setcap(void *vstate, uint16_t proportion) return DEVICE_GOOD; } -int itdtimage_format(void *vstate, TC_FORMAT_TYPE format, const char *vol_name, const char *barcode_name, const char *vol_mam_uuid) +int itdtimage_format( + void *vstate, TC_FORMAT_TYPE format, const char *vol_name, const char *barcode_name, const char *vol_mam_uuid) { struct itdtimage_data *state = (struct itdtimage_data *)vstate; struct tc_position pos; - if(state->current_position.partition != 0 || - state->current_position.block != 0) - { + if (state->current_position.partition != 0 || state->current_position.block != 0) { ltfsmsg(LTFS_ERR, 31014E); return -EDEV_ILLEGAL_REQUEST; } - switch(format){ - case TC_FORMAT_DEFAULT: - state->partitions = 1; - break; - case TC_FORMAT_PARTITION: - case TC_FORMAT_DEST_PART: - state->partitions = 2; - break; - default: - ltfsmsg(LTFS_ERR, 31015E); - return -EDEV_INVALID_ARG; + switch (format) { + case TC_FORMAT_DEFAULT: + state->partitions = 1; + break; + case TC_FORMAT_PARTITION: + case TC_FORMAT_DEST_PART: + state->partitions = 2; + break; + default: + ltfsmsg(LTFS_ERR, 31015E); + return -EDEV_INVALID_ARG; } /* erase all partitions */ @@ -806,33 +786,33 @@ int itdtimage_remaining_capacity(void *vstate, struct tc_remaining_cap *cap) return DEVICE_GOOD; } cap->remaining_p0 = 6UL * (GB / MB); - cap->max_p0 = 6UL * (GB / MB); - if(state->partitions == 2) { + cap->max_p0 = 6UL * (GB / MB); + if (state->partitions == 2) { cap->remaining_p1 = 6UL * (GB / MB); - cap->max_p1 = 6UL * (GB / MB); + cap->max_p1 = 6UL * (GB / MB); } else { cap->remaining_p1 = 0; - cap->max_p1 = 0; + cap->max_p1 = 0; } return DEVICE_GOOD; } int itdtimage_get_cartridge_health(void *device, struct tc_cartridge_health *cart_health) { - cart_health->mounts = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->written_ds = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->write_temps = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->write_perms = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_ds = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_temps = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_perms = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->mounts = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->written_ds = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->write_temps = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->write_perms = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_ds = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_temps = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_perms = UNSUPPORTED_CARTRIDGE_HEALTH; cart_health->write_perms_prev = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_perms_prev = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->written_mbytes = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_mbytes = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->passes_begin = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->passes_middle = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->tape_efficiency = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_perms_prev = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->written_mbytes = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_mbytes = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->passes_begin = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->passes_middle = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->tape_efficiency = UNSUPPORTED_CARTRIDGE_HEALTH; return DEVICE_GOOD; } @@ -863,7 +843,12 @@ int itdtimage_logsense(void *device, const uint8_t page, const uint8_t subpage, return -EDEV_UNSUPPORTED_FUNCTION; } -int itdtimage_modesense(void *device, const uint8_t page, const TC_MP_PC_TYPE pc, const uint8_t subpage, unsigned char *buf, const size_t size) +int itdtimage_modesense(void *device, + const uint8_t page, + const TC_MP_PC_TYPE pc, + const uint8_t subpage, + unsigned char *buf, + const size_t size) { /* Only clear buffer */ memset(buf, 0, size); @@ -908,13 +893,14 @@ int itdtimage_prevent_medium_removal(void *vstate) int itdtimage_allow_medium_removal(void *vstate) { struct itdtimage_data *state = (struct itdtimage_data *)vstate; - ltfsmsg(LTFS_DEBUG, 31011D, - (unsigned long long)state->current_position.partition, - (unsigned long long)state->current_position.block, - (unsigned long long)state->current_position.filemarks, - (int)state->device_reserved, - (int)state->medium_locked, - (int)state->ready); + ltfsmsg(LTFS_DEBUG, + 31011D, + (unsigned long long)state->current_position.partition, + (unsigned long long)state->current_position.block, + (unsigned long long)state->current_position.filemarks, + (int)state->device_reserved, + (int)state->medium_locked, + (int)state->ready); if (!state->ready) { ltfsmsg(LTFS_ERR, 31019E); return -EDEV_NOT_READY; @@ -923,26 +909,26 @@ int itdtimage_allow_medium_removal(void *vstate) return DEVICE_GOOD; } -int itdtimage_read_attribute(void *vstate, const tape_partition_t part, const uint16_t id - , unsigned char *buf, const size_t size) +int itdtimage_read_attribute( + void *vstate, const tape_partition_t part, const uint16_t id, unsigned char *buf, const size_t size) { struct itdtimage_data *state = (struct itdtimage_data *)vstate; - long long offset=_itdtimage_getattr_offest(state,part,id); + long long offset = _itdtimage_getattr_offest(state, part, id); size_t data2ReadFromFile = size; - size_t attrLength=_itdtimage_getattr_len(state,part,id); + size_t attrLength = _itdtimage_getattr_len(state, part, id); - ltfsmsg(LTFS_DEBUG, 31020D , part , id ); + ltfsmsg(LTFS_DEBUG, 31020D, part, id); /* Open attribute record */ - if (offset == -1){ + if (offset == -1) { return -EDEV_CM_PERM; } - if (attrLength < size){ + if (attrLength < size) { data2ReadFromFile = attrLength; } - if (_seek_file(state->img_file, offset)!=0){ + if (_seek_file(state->img_file, offset) != 0) { ltfsmsg(LTFS_ERR, 31002E, (long long)attrLength, state->filename, offset); return -EDEV_HARDWARE_ERROR; } @@ -951,8 +937,7 @@ int itdtimage_read_attribute(void *vstate, const tape_partition_t part, const ui return DEVICE_GOOD; } -int itdtimage_write_attribute(void *vstate, const tape_partition_t part - , const unsigned char *buf, const size_t size) +int itdtimage_write_attribute(void *vstate, const tape_partition_t part, const unsigned char *buf, const size_t size) { return -EDEV_CM_PERM; } @@ -983,7 +968,7 @@ int itdtimage_rrao(void *device, unsigned char *buf, const uint32_t len, size_t int itdtimage_get_eod_status(void *vstate, int partition) { struct itdtimage_data *state = (struct itdtimage_data *)vstate; - if(state->eod[partition] == MISSING_EOD) + if (state->eod[partition] == MISSING_EOD) return EOD_MISSING; else return EOD_GOOD; @@ -1032,19 +1017,17 @@ int _itdtimage_write_eod(struct itdtimage_data *state) */ int _itdtimage_remove_current_record(const struct itdtimage_data *state) { - return _itdtimage_remove_record(state - , state->current_position.partition - , state->current_position.block); + return _itdtimage_remove_record(state, state->current_position.partition, state->current_position.block); } /** * Delete the file associated with a given tape position. * @return 1 on successful delete, 0 if no file found, negative on error. */ -int _itdtimage_remove_record(const struct itdtimage_data *state, - int partition, uint64_t blknum) +int _itdtimage_remove_record(const struct itdtimage_data *state, int partition, uint64_t blknum) { - return -EDEV_WRITE_PROTECTED;; + return -EDEV_WRITE_PROTECTED; + ; } /** * Make filename for a record. @@ -1052,25 +1035,23 @@ int _itdtimage_remove_record(const struct itdtimage_data *state, * the returned memory. Failure probably means asprintf couldn't allocate memory. */ -long long _itdtimage_getRllIndex4PartitionAndPos(const struct itdtimage_data *state, - int part, uint64_t pos) +long long _itdtimage_getRllIndex4PartitionAndPos(const struct itdtimage_data *state, int part, uint64_t pos) { long start = 0; - long end = state->rll_count-1; + long end = state->rll_count - 1; long middle; - if(part == 1) - start =state->part1_img_offset; + if (part == 1) + start = state->part1_img_offset; else - end = state->part1_img_offset-1; - while (start <= end){ + end = state->part1_img_offset - 1; + while (start <= end) { middle = start + ((end - start) / 2); - if( ((long long)pos >= state->runlist[middle].pos_tape) - && ((long long)pos < state->runlist[middle].pos_tape+state->runlist[middle].count_rec)){ + if (((long long)pos >= state->runlist[middle].pos_tape) && + ((long long)pos < state->runlist[middle].pos_tape + state->runlist[middle].count_rec)) { return middle; - } - else { - if ( (state->runlist[middle].pos_tape+state->runlist[middle].count_rec) > (long long)pos ) + } else { + if ((state->runlist[middle].pos_tape + state->runlist[middle].count_rec) > (long long)pos) end = middle - 1; else start = middle + 1; @@ -1080,13 +1061,12 @@ long long _itdtimage_getRllIndex4PartitionAndPos(const struct itdtimage_data *st return -1; } -long long _itdtimage_getrec_offset(const struct itdtimage_data *state, - int part, uint64_t pos) +long long _itdtimage_getrec_offset(const struct itdtimage_data *state, int part, uint64_t pos) { long long temp, ret; long long cur = _itdtimage_getRllIndex4PartitionAndPos(state, part, pos); - if (cur != -1){ + if (cur != -1) { temp = pos - state->runlist[cur].pos_tape; ret = state->runlist[cur].offset_img + state->runlist[cur].length_rec * temp; return ret; @@ -1095,11 +1075,10 @@ long long _itdtimage_getrec_offset(const struct itdtimage_data *state, return -1; } -long long _itdtimage_getrec_len(const struct itdtimage_data *state, - int part, uint64_t pos) +long long _itdtimage_getrec_len(const struct itdtimage_data *state, int part, uint64_t pos) { - long long cur = _itdtimage_getRllIndex4PartitionAndPos(state,part,pos); - if (cur != -1){ + long long cur = _itdtimage_getRllIndex4PartitionAndPos(state, part, pos); + if (cur != -1) { return state->runlist[cur].length_rec; } return -1; @@ -1114,8 +1093,8 @@ long long _itdtimage_getattr_offest(const struct itdtimage_data *state, int part { int i; - for(i = 0; i < state->attr_count; i++) { - if( (state->attr_info[i].attr_id == id) && (state->attr_info[i].partition == part) ) + for (i = 0; i < state->attr_count; i++) { + if ((state->attr_info[i].attr_id == id) && (state->attr_info[i].partition == part)) return state->attr_info[i].offset_img; } @@ -1126,15 +1105,14 @@ long long _itdtimage_getattr_len(const struct itdtimage_data *state, int part, i { int i; - for( i = 0; i < state->attr_count; i++) { - if( (state->attr_info[i].attr_id==id) && (state->attr_info[i].partition==part) ) + for (i = 0; i < state->attr_count; i++) { + if ((state->attr_info[i].attr_id == id) && (state->attr_info[i].partition == part)) return state->attr_info[i].length; } return -1; } - /** * Space over filemarks. Position immediately after the FM if spacing forwards, or * immediately before it if spacing backwards. @@ -1150,56 +1128,56 @@ int _itdtimage_space_fm(struct itdtimage_data *state, uint64_t count, bool back) long cur = -1; uint64_t filemarkCount = 0; - ltfsmsg(LTFS_DEBUG, 31004D, (unsigned long long)count, state->current_position.partition, - (unsigned long long)state->current_position.block, - (unsigned long long)state->current_position.filemarks); + ltfsmsg(LTFS_DEBUG, + 31004D, + (unsigned long long)count, + state->current_position.partition, + (unsigned long long)state->current_position.block, + (unsigned long long)state->current_position.filemarks); - if (count == 0) - return DEVICE_GOOD; + if (count == 0) return DEVICE_GOOD; - if( state->current_position.partition == 1 ) + if (state->current_position.partition == 1) start = state->part1_img_offset; else - end = state->part1_img_offset-1; + end = state->part1_img_offset - 1; - if ( back && (state->current_position.block > 0) ) - --state->current_position.block; + if (back && (state->current_position.block > 0)) --state->current_position.block; cur = _itdtimage_getRllIndex4PartitionAndPos(state, state->current_position.partition, state->current_position.block); - if (cur == -1){ + if (cur == -1) { return -EDEV_RW_PERM; } - if ( back ) { - if (state->current_position.block == 0) - return -EDEV_BOP_DETECTED; - if (state->runlist[cur].length_rec == 0 && - state->runlist[cur].count_rec > 1){ + if (back) { + if (state->current_position.block == 0) return -EDEV_BOP_DETECTED; + if (state->runlist[cur].length_rec == 0 && state->runlist[cur].count_rec > 1) { /* check for filemark entry */ - filemarkCount = (state->runlist[cur].count_rec-1) + state->current_position.block - state->runlist[cur].pos_tape; + filemarkCount = + (state->runlist[cur].count_rec - 1) + state->current_position.block - state->runlist[cur].pos_tape; if (filemarkCount >= count) { - state->current_position.block-=count; + state->current_position.block -= count; return DEVICE_GOOD; } } /* not in current rll entry check previous onces */ cur--; - while ( cur >= start ){ - if (state->runlist[cur].length_rec==0){ - if (filemarkCount+state->runlist[cur].count_rec >= count){ - state->current_position.block = state->runlist[cur].pos_tape + (state->runlist[cur].count_rec - filemarkCount) + 1; + while (cur >= start) { + if (state->runlist[cur].length_rec == 0) { + if (filemarkCount + state->runlist[cur].count_rec >= count) { + state->current_position.block = + state->runlist[cur].pos_tape + (state->runlist[cur].count_rec - filemarkCount) + 1; return DEVICE_GOOD; - } - else - filemarkCount+=state->runlist[cur].count_rec; + } else + filemarkCount += state->runlist[cur].count_rec; } cur--; } return -EDEV_BOP_DETECTED; } else { - if (state->runlist[cur].length_rec == 0){ + if (state->runlist[cur].length_rec == 0) { /* check for filemark entry */ - filemarkCount = state->runlist[cur].pos_tape + state->runlist[cur].count_rec-state->current_position.block; + filemarkCount = state->runlist[cur].pos_tape + state->runlist[cur].count_rec - state->current_position.block; if (filemarkCount >= count) { state->current_position.block += count; return DEVICE_GOOD; @@ -1207,15 +1185,14 @@ int _itdtimage_space_fm(struct itdtimage_data *state, uint64_t count, bool back) } /* not in current rll entry check next onces */ cur++; - while ( cur <= end ){ - if (state->runlist[cur].length_rec == 0){ - if (filemarkCount+state->runlist[cur].count_rec >= count){ - state->current_position.block = state->runlist[cur].pos_tape + (state->runlist[cur].count_rec - filemarkCount); + while (cur <= end) { + if (state->runlist[cur].length_rec == 0) { + if (filemarkCount + state->runlist[cur].count_rec >= count) { + state->current_position.block = + state->runlist[cur].pos_tape + (state->runlist[cur].count_rec - filemarkCount); return DEVICE_GOOD; - } - else + } else filemarkCount += state->runlist[cur].count_rec; - } cur++; } @@ -1242,30 +1219,26 @@ int _itdtimage_space_rec(struct itdtimage_data *state, uint64_t count, bool back long cur = -1; uint64_t count_rec = 0; - if (count == 0) - return DEVICE_GOOD; + if (count == 0) return DEVICE_GOOD; - if(state->current_position.partition==1) + if (state->current_position.partition == 1) start = state->part1_img_offset; else end = state->part1_img_offset - 1; - if ( back && state->current_position.block > 0 ) - --state->current_position.block; - cur = _itdtimage_getRllIndex4PartitionAndPos(state,state->current_position.partition, state->current_position.block); - if (cur == -1){ + if (back && state->current_position.block > 0) --state->current_position.block; + cur = _itdtimage_getRllIndex4PartitionAndPos(state, state->current_position.partition, state->current_position.block); + if (cur == -1) { return -EDEV_RW_PERM; } - if ( back ){ - if (state->current_position.block == 0) - return -EDEV_BOP_DETECTED; + if (back) { + if (state->current_position.block == 0) return -EDEV_BOP_DETECTED; /* 0 = filemark, -1 = end of partition */ - if ( state->runlist[cur].length_rec > 0 && - state->runlist[cur].count_rec > 1) { + if (state->runlist[cur].length_rec > 0 && state->runlist[cur].count_rec > 1) { /* check for filemark entry */ - count_rec = state->runlist[cur].pos_tape + state->runlist[cur].count_rec-state->current_position.block; + count_rec = state->runlist[cur].pos_tape + state->runlist[cur].count_rec - state->current_position.block; if (count_rec >= count) { state->current_position.block -= count; return DEVICE_GOOD; @@ -1274,46 +1247,41 @@ int _itdtimage_space_rec(struct itdtimage_data *state, uint64_t count, bool back /* not in current rll entry check previous onces */ cur--; - while ( cur >= start ){ - if ( state->runlist[cur].length_rec > 0 ) { - if ( count_rec+state->runlist[cur].count_rec >= count ){ - state->current_position.block = state->runlist[cur].pos_tape + (state->runlist[cur].count_rec-count_rec) + 1; + while (cur >= start) { + if (state->runlist[cur].length_rec > 0) { + if (count_rec + state->runlist[cur].count_rec >= count) { + state->current_position.block = + state->runlist[cur].pos_tape + (state->runlist[cur].count_rec - count_rec) + 1; return DEVICE_GOOD; - } - else + } else count_rec += state->runlist[cur].count_rec; - } - else if (state->runlist[cur].length_rec ==0 ){ + } else if (state->runlist[cur].length_rec == 0) { /* filemark */ - state->current_position.block=state->runlist[cur].pos_tape+state->runlist[cur].count_rec; + state->current_position.block = state->runlist[cur].pos_tape + state->runlist[cur].count_rec; return DEVICE_GOOD; } cur--; } return -EDEV_BOP_DETECTED; - } - else { - if ( state->runlist[cur].length_rec > 0 && - state->runlist[cur].count_rec > 1) { + } else { + if (state->runlist[cur].length_rec > 0 && state->runlist[cur].count_rec > 1) { /* check for filemark entry */ - count_rec=state->runlist[cur].pos_tape+state->runlist[cur].count_rec-state->current_position.block; + count_rec = state->runlist[cur].pos_tape + state->runlist[cur].count_rec - state->current_position.block; if (count_rec >= count) { - state->current_position.block+=count; + state->current_position.block += count; return DEVICE_GOOD; } } /* not in current rll entry check next onces */ cur++; - while (cur <= end){ + while (cur <= end) { if (state->runlist[cur].length_rec == 0) { - if (count_rec+state->runlist[cur].count_rec>=count) { - state->current_position.block = state->runlist[cur].pos_tape + (state->runlist[cur].count_rec-count_rec); + if (count_rec + state->runlist[cur].count_rec >= count) { + state->current_position.block = state->runlist[cur].pos_tape + (state->runlist[cur].count_rec - count_rec); return DEVICE_GOOD; - } - else + } else count_rec += state->runlist[cur].count_rec; - } - else if (state->runlist[cur].length_rec == 0){ + } else if (state->runlist[cur].length_rec == 0) { state->current_position.block = state->runlist[cur].pos_tape; return DEVICE_GOOD; } @@ -1351,29 +1319,32 @@ int itdtimage_get_device_list(struct tc_drive_info *buf, int count) return 0; } else { devdir = fgets(line, sizeof(line), infile); - if(devdir[strlen(devdir) - 1] == '\n') - devdir[strlen(devdir) - 1] = '\0'; + if (devdir[strlen(devdir) - 1] == '\n') devdir[strlen(devdir) - 1] = '\0'; fclose(infile); free(filename); } ltfsmsg(LTFS_INFO, 31028I, devdir); dp = opendir(devdir); - if (! dp) { + if (!dp) { ltfsmsg(LTFS_ERR, 31029E, devdir); return 0; } while ((entry = readdir(dp))) { - if (strncmp(entry->d_name, DRIVE_FILE_PREFIX, strlen(DRIVE_FILE_PREFIX))) - continue; + if (strncmp(entry->d_name, DRIVE_FILE_PREFIX, strlen(DRIVE_FILE_PREFIX))) continue; if (buf && deventries < count) { snprintf(buf[deventries].name, TAPE_DEVNAME_LEN_MAX, "%s/%s", devdir, entry->d_name); arch_strncpy_auto(buf[deventries].vendor, "DUMMY", TAPE_VENDOR_NAME_LEN_MAX); arch_strncpy_auto(buf[deventries].model, "DUMMYDEV", TAPE_MODEL_NAME_LEN_MAX); - arch_strncpy_auto(buf[deventries].serial_number, &(entry->d_name[strlen(DRIVE_FILE_PREFIX)]), TAPE_SERIAL_LEN_MAX); - ltfsmsg(LTFS_DEBUG, 31030D, buf[deventries].name, buf[deventries].vendor, - buf[deventries].model, buf[deventries].serial_number); + arch_strncpy_auto( + buf[deventries].serial_number, &(entry->d_name[strlen(DRIVE_FILE_PREFIX)]), TAPE_SERIAL_LEN_MAX); + ltfsmsg(LTFS_DEBUG, + 31030D, + buf[deventries].name, + buf[deventries].vendor, + buf[deventries].model, + buf[deventries].serial_number); } deventries++; @@ -1400,8 +1371,10 @@ int itdtimage_takedump_drive(void *device, bool capture_unforced) return DEVICE_GOOD; } -int itdtimage_is_mountable(void *device, const char *barcode, const unsigned char cart_type, - const unsigned char density) +int itdtimage_is_mountable(void *device, + const char *barcode, + const unsigned char cart_type, + const unsigned char density) { /* Do nothing */ return MEDIUM_PERFECT_MATCH; @@ -1427,12 +1400,11 @@ int itdtimage_get_serialnumber(void *vstate, char **result) CHECK_ARG_NULL(result, -LTFS_NULL_ARG); if (state->serial_number) - *result = arch_strdup((const char *) state->serial_number); + *result = arch_strdup((const char *)state->serial_number); else *result = arch_strdup("DUMMY"); - if (! *result) - return -EDEV_NO_MEMORY; + if (!*result) return -EDEV_NO_MEMORY; return DEVICE_GOOD; } @@ -1443,10 +1415,10 @@ int itdtimage_get_info(void *device, struct tc_drive_info *info) * Return dummy data. * This logic is enough only for single drive supported code. */ - info->host = 0; + info->host = 0; info->channel = 0; - info->target = 0; - info->lun = -1; + info->target = 0; + info->lun = -1; return 0; } @@ -1460,7 +1432,8 @@ int itdtimage_set_profiler(void *device, char *work_dir, bool enable) int itdtimage_get_next_block_to_xfer(void *device, struct tc_position *pos) { /* This backend never accept write command */ - return -EDEV_WRITE_PROTECTED;; + return -EDEV_WRITE_PROTECTED; + ; } /* Local functions */ @@ -1469,15 +1442,14 @@ char *memstr(const char *s, const char *find, size_t slen) char *p; size_t len; - if ( !s || slen == 0 ) /* nothing todo */ + if (!s || slen == 0) /* nothing todo */ return NULL; len = strlen(find); - if (*find == '\0') - return (char*) s; + if (*find == '\0') return (char *)s; - for (p = (char*) s; p < (s + slen-len); p++) { - if (memcmp(p, find, len) == 0){ + for (p = (char *)s; p < (s + slen - len); p++) { + if (memcmp(p, find, len) == 0) { return p; } } @@ -1487,36 +1459,36 @@ char *memstr(const char *s, const char *find, size_t slen) char *_read_XML_tag(char *buf, int buf_len, char *needle) { - char *sptr; /* start of substring */ - char *eptr; /* end of substring */ + char *sptr; /* start of substring */ + char *eptr; /* end of substring */ char *ret_str; char tag_end[100]; char tag_start[100]; int length; - if(buf==NULL ) { + if (buf == NULL) { return NULL; } - sprintf(tag_end,"",needle); - sprintf(tag_start,"<%s>",needle); + sprintf(tag_end, "", needle); + sprintf(tag_start, "<%s>", needle); sptr = NULL; sptr = memstr(buf, tag_start, buf_len); - if(sptr==NULL ) { + if (sptr == NULL) { return NULL; } sptr = sptr + strlen(tag_start); - eptr = memstr(sptr, tag_end, buf_len - (sptr-buf)); - if(eptr==NULL ) { + eptr = memstr(sptr, tag_end, buf_len - (sptr - buf)); + if (eptr == NULL) { return NULL; } length = eptr - sptr; - ret_str = (char*)calloc(1, length + 1); - if (ret_str){ + ret_str = (char *)calloc(1, length + 1); + if (ret_str) { memcpy(ret_str, sptr, length); - ret_str[length]=0; + ret_str[length] = 0; } return ret_str; @@ -1527,9 +1499,8 @@ unsigned long long _read_XML_tag_value(char *buf, int buf_len, char *needle) char *val; unsigned long long ret = (unsigned long long)-1; - val =_read_XML_tag(buf, buf_len, needle); - if ( !val ) - return 0; + val = _read_XML_tag(buf, buf_len, needle); + if (!val) return 0; ret = strtoull(val, NULL, 10); free(val); @@ -1539,133 +1510,132 @@ unsigned long long _read_XML_tag_value(char *buf, int buf_len, char *needle) unsigned long long _get_file_size(FILE *fStream) { - unsigned long long ret=0; + unsigned long long ret = 0; #ifdef mingw_PLATFORM _LARGE_INTEGER p; osHANDLE handle; int fd = fileno(fStream); - handle = (void*) _get_osfhandle(fd); + handle = (void *)_get_osfhandle(fd); - if(!GetFileSizeEx(handle, &p)){ - ret=0; + if (!GetFileSizeEx(handle, &p)) { + ret = 0; } else { - ret=p.HighPart; - ret=ret << 32; - ret|=p.LowPart; + ret = p.HighPart; + ret = ret << 32; + ret |= p.LowPart; } #else -#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) +# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) long long tmp = fseeko(fStream, 0LL, SEEK_END); - if(tmp != -1){ + if (tmp != -1) { ret = ftello(fStream); } -#else +# else long long tmp = fseeko64(fStream, 0LL, SEEK_END); - if(tmp != -1){ + if (tmp != -1) { ret = ftello64(fStream); } -#endif +# endif #endif return ret; } unsigned long long _seek_file(FILE *file, unsigned long long position) { - unsigned long long ret=0; + unsigned long long ret = 0; #ifdef mingw_PLATFORM - if(position > 0){ + if (position > 0) { _LARGE_INTEGER p; - p.HighPart=position>>32; - p.LowPart=position & 0xFFFFFFFFL; - if(position==0){ - p.HighPart=0; - p.LowPart=0; + p.HighPart = position >> 32; + p.LowPart = position & 0xFFFFFFFFL; + if (position == 0) { + p.HighPart = 0; + p.LowPart = 0; } int fd = fileno(fStream); - osHANDLE handle = (void*) _get_osfhandle(fd); - if(!SetFilePointerEx(handle, p, NULL, FILE_BEGIN)){ + osHANDLE handle = (void *)_get_osfhandle(fd); + if (!SetFilePointerEx(handle, p, NULL, FILE_BEGIN)) { //printf("Error in _seek_file()\n"); - ret=0; - }else - ret=position; + ret = 0; + } else + ret = position; - if(position==0){ + if (position == 0) { _LARGE_INTEGER curr; SetFilePointerEx(handle, p, &curr, FILE_BEGIN); cout << "***Current Pos is " << curr.QuadPart << endl; } - }else + } else file->Seek(position, wxFromStart); #else -#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) +# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) long long tmp = fseeko(file, position, SEEK_SET); -#else +# else long long tmp = fseeko64(file, position, SEEK_SET); -#endif - if(tmp != -1) - ret = tmp; +# endif + if (tmp != -1) ret = tmp; #endif return ret; } struct tape_ops itdtimage_handler = { - .open = itdtimage_open, - .reopen = itdtimage_reopen, - .close = itdtimage_close, - .close_raw = itdtimage_close_raw, - .is_connected = itdtimage_is_connected, - .inquiry = itdtimage_inquiry, - .inquiry_page = itdtimage_inquiry_page, - .test_unit_ready = itdtimage_test_unit_ready, - .read = itdtimage_read, - .write = itdtimage_write, - .writefm = itdtimage_writefm, - .rewind = itdtimage_rewind, - .locate = itdtimage_locate, - .space = itdtimage_space, - .erase = itdtimage_erase, - .load = itdtimage_load, - .unload = itdtimage_unload, - .readpos = itdtimage_readpos, - .setcap = itdtimage_setcap, - .format = itdtimage_format, - .remaining_capacity = itdtimage_remaining_capacity, - .logsense = itdtimage_logsense, - .modesense = itdtimage_modesense, - .modeselect = itdtimage_modeselect, - .reserve_unit = itdtimage_reserve_unit, - .release_unit = itdtimage_release_unit, + .open = itdtimage_open, + .reopen = itdtimage_reopen, + .close = itdtimage_close, + .close_raw = itdtimage_close_raw, + .is_connected = itdtimage_is_connected, + .inquiry = itdtimage_inquiry, + .inquiry_page = itdtimage_inquiry_page, + .test_unit_ready = itdtimage_test_unit_ready, + .read = itdtimage_read, + .write = itdtimage_write, + .writefm = itdtimage_writefm, + .rewind = itdtimage_rewind, + .locate = itdtimage_locate, + .space = itdtimage_space, + .erase = itdtimage_erase, + .load = itdtimage_load, + .unload = itdtimage_unload, + .readpos = itdtimage_readpos, + .setcap = itdtimage_setcap, + .format = itdtimage_format, + .remaining_capacity = itdtimage_remaining_capacity, + .logsense = itdtimage_logsense, + .modesense = itdtimage_modesense, + .modeselect = itdtimage_modeselect, + .reserve_unit = itdtimage_reserve_unit, + .release_unit = itdtimage_release_unit, .prevent_medium_removal = itdtimage_prevent_medium_removal, - .allow_medium_removal = itdtimage_allow_medium_removal, - .write_attribute = itdtimage_write_attribute, - .read_attribute = itdtimage_read_attribute, - .allow_overwrite = itdtimage_allow_overwrite, - .grao = itdtimage_grao, - .rrao = itdtimage_rrao, - .set_compression = itdtimage_set_compression, - .set_default = itdtimage_set_default, - .get_cartridge_health = itdtimage_get_cartridge_health, - .get_tape_alert = itdtimage_get_tape_alert, - .clear_tape_alert = itdtimage_clear_tape_alert, - .get_xattr = itdtimage_get_xattr, - .set_xattr = itdtimage_set_xattr, - .get_parameters = itdtimage_get_parameters, - .get_eod_status = itdtimage_get_eod_status, - .get_device_list = itdtimage_get_device_list, - .help_message = itdtimage_help_message, - .parse_opts = itdtimage_parse_opts, - .default_device_name = itdtimage_default_device_name, - .set_key = itdtimage_set_key, - .get_keyalias = itdtimage_get_keyalias, - .takedump_drive = itdtimage_takedump_drive, - .is_mountable = itdtimage_is_mountable, - .get_worm_status = itdtimage_get_worm_status, - .get_serialnumber = itdtimage_get_serialnumber, - .get_info = itdtimage_get_info, - .set_profiler = itdtimage_set_profiler, + .allow_medium_removal = itdtimage_allow_medium_removal, + .write_attribute = itdtimage_write_attribute, + .read_attribute = itdtimage_read_attribute, + .allow_overwrite = itdtimage_allow_overwrite, + .grao = itdtimage_grao, + .rrao = itdtimage_rrao, + .set_compression = itdtimage_set_compression, + .set_default = itdtimage_set_default, + .get_cartridge_health = itdtimage_get_cartridge_health, + .get_tape_alert = itdtimage_get_tape_alert, + .clear_tape_alert = itdtimage_clear_tape_alert, + .get_xattr = itdtimage_get_xattr, + .set_xattr = itdtimage_set_xattr, + .get_parameters = itdtimage_get_parameters, + .get_eod_status = itdtimage_get_eod_status, + .get_device_list = itdtimage_get_device_list, + .help_message = itdtimage_help_message, + .parse_opts = itdtimage_parse_opts, + .default_device_name = itdtimage_default_device_name, + .set_key = itdtimage_set_key, + .get_keyalias = itdtimage_get_keyalias, + .takedump_drive = itdtimage_takedump_drive, + .is_mountable = itdtimage_is_mountable, + .get_worm_status = itdtimage_get_worm_status, + .get_serialnumber = itdtimage_get_serialnumber, + .get_info = itdtimage_get_info, + .set_profiler = itdtimage_set_profiler, .get_next_block_to_xfer = itdtimage_get_next_block_to_xfer, - .is_readonly = itdtimage_is_readonly, + .is_readonly = itdtimage_is_readonly, }; struct tape_ops *tape_dev_get_ops(void) diff --git a/src/tape_drivers/hp_tape.c b/src/tape_drivers/hp_tape.c index 35fd6002..0a0466ec 100644 --- a/src/tape_drivers/hp_tape.c +++ b/src/tape_drivers/hp_tape.c @@ -47,355 +47,328 @@ ************************************************************************************* */ #ifndef mingw_PLATFORM -#if defined (__FreeBSD__) || defined(__NetBSD__) -#include -#include -#include -#endif /* __FreeBSD__ */ -#include -#include -#include +# if defined(__FreeBSD__) || defined(__NetBSD__) +# include +# include +# include +# endif /* __FreeBSD__ */ +# include +# include +# include -#define LOOP_BACK_DEVICE "lo" +# define LOOP_BACK_DEVICE "lo" #endif #include "tape_drivers/hp_tape.h" #include "libltfs/ltfs_endian.h" struct supported_device *hp_supported_drives[] = { - TAPEDRIVE( HP_VENDOR_ID, "Ultrium 5-SCSI", DRIVE_LTO5, "[Ultrium 5-SCSI]" ), /* HP Ultrium Gen 5 */ - TAPEDRIVE( HP_VENDOR_ID, "Ultrium 6-SCSI", DRIVE_LTO6, "[Ultrium 6-SCSI]" ), /* HP Ultrium Gen 6 */ - TAPEDRIVE( HP_VENDOR_ID, "Ultrium 7-SCSI", DRIVE_LTO7, "[Ultrium 7-SCSI]" ), /* HP Ultrium Gen 7 */ - TAPEDRIVE( HPE_VENDOR_ID, "Ultrium 8-SCSI", DRIVE_LTO8, "[Ultrium 8-SCSI]" ), /* HPE Ultrium Gen 8 */ - /* End of supported_devices */ - NULL + TAPEDRIVE(HP_VENDOR_ID, "Ultrium 5-SCSI", DRIVE_LTO5, "[Ultrium 5-SCSI]"), /* HP Ultrium Gen 5 */ + TAPEDRIVE(HP_VENDOR_ID, "Ultrium 6-SCSI", DRIVE_LTO6, "[Ultrium 6-SCSI]"), /* HP Ultrium Gen 6 */ + TAPEDRIVE(HP_VENDOR_ID, "Ultrium 7-SCSI", DRIVE_LTO7, "[Ultrium 7-SCSI]"), /* HP Ultrium Gen 7 */ + TAPEDRIVE(HPE_VENDOR_ID, "Ultrium 8-SCSI", DRIVE_LTO8, "[Ultrium 8-SCSI]"), /* HPE Ultrium Gen 8 */ + /* End of supported_devices */ + NULL }; /* HP/HPE LTO tape drive vendor unique sense table */ struct error_table hp_tape_errors[] = { /* Sense Key 0 (No Sense) */ - {0x008282, -EDEV_CLEANING_REQUIRED, "HPE LTO - Cleaning Required"}, - {0x008283, -EDEV_HARDWARE_ERROR, "HPE LTO - Bad microcode detected"}, + { 0x008282, -EDEV_CLEANING_REQUIRED, "HPE LTO - Cleaning Required" }, + { 0x008283, -EDEV_HARDWARE_ERROR, "HPE LTO - Bad microcode detected" }, /* END MARK*/ - {0xFFFFFF, -EDEV_UNKNOWN, "Unknown Error code"}, + { 0xFFFFFF, -EDEV_UNKNOWN, "Unknown Error code" }, }; #define DEFAULT_TIMEOUT (60) -struct _timeout_tape{ - int op_code; /**< SCSI op code */ - int timeout; /**< SCSI timeout */ +struct _timeout_tape +{ + int op_code; /**< SCSI op code */ + int timeout; /**< SCSI timeout */ }; /* Base timeout value for LTO */ -static struct _timeout_tape timeout_lto[] = { - { CHANGE_DEFINITION, -1 }, - { XCOPY, -1 }, - { INQUIRY, 60 }, - { LOG_SELECT, 60 }, - { LOG_SENSE, 60 }, - { MODE_SELECT6, 60 }, - { MODE_SELECT10, 60 }, - { MODE_SENSE6, 60 }, - { MODE_SENSE10, 60 }, - { PERSISTENT_RESERVE_IN, 60 }, - { PERSISTENT_RESERVE_OUT, 60 }, - { READ_ATTRIBUTE, 60 }, - { RECEIVE_DIAGNOSTIC_RESULTS, 60 }, - { RELEASE_UNIT6, 60 }, - { RELEASE_UNIT10, 60 }, - { REPORT_LUNS, 60 }, - { REQUEST_SENSE, 60 }, - { RESERVE_UNIT6, 60 }, - { RESERVE_UNIT10, 60 }, - { SPIN, 60 }, - { SPOUT, 60 }, - { TEST_UNIT_READY, 60 }, - { WRITE_ATTRIBUTE, 60 }, - { ALLOW_OVERWRITE, 60 }, - { DISPLAY_MESSAGE, -1 }, - { PREVENT_ALLOW_MEDIUM_REMOVAL, 60 }, - { READ_BLOCK_LIMITS, 60 }, - { READ_DYNAMIC_RUNTIME_ATTRIBUTE, 60 }, - { READ_POSITION, 60 }, - { READ_REVERSE, -1 }, - { RECOVER_BUFFERED_DATA, -1 }, - { REPORT_DENSITY_SUPPORT, 60 }, - { STRING_SEARCH, -1 }, - { WRITE_DYNAMIC_RUNTIME_ATTRIBUTE, 60 }, - {-1, -1} -}; +static struct _timeout_tape timeout_lto[] = { { CHANGE_DEFINITION, -1 }, + { XCOPY, -1 }, + { INQUIRY, 60 }, + { LOG_SELECT, 60 }, + { LOG_SENSE, 60 }, + { MODE_SELECT6, 60 }, + { MODE_SELECT10, 60 }, + { MODE_SENSE6, 60 }, + { MODE_SENSE10, 60 }, + { PERSISTENT_RESERVE_IN, 60 }, + { PERSISTENT_RESERVE_OUT, 60 }, + { READ_ATTRIBUTE, 60 }, + { RECEIVE_DIAGNOSTIC_RESULTS, 60 }, + { RELEASE_UNIT6, 60 }, + { RELEASE_UNIT10, 60 }, + { REPORT_LUNS, 60 }, + { REQUEST_SENSE, 60 }, + { RESERVE_UNIT6, 60 }, + { RESERVE_UNIT10, 60 }, + { SPIN, 60 }, + { SPOUT, 60 }, + { TEST_UNIT_READY, 60 }, + { WRITE_ATTRIBUTE, 60 }, + { ALLOW_OVERWRITE, 60 }, + { DISPLAY_MESSAGE, -1 }, + { PREVENT_ALLOW_MEDIUM_REMOVAL, 60 }, + { READ_BLOCK_LIMITS, 60 }, + { READ_DYNAMIC_RUNTIME_ATTRIBUTE, 60 }, + { READ_POSITION, 60 }, + { READ_REVERSE, -1 }, + { RECOVER_BUFFERED_DATA, -1 }, + { REPORT_DENSITY_SUPPORT, 60 }, + { STRING_SEARCH, -1 }, + { WRITE_DYNAMIC_RUNTIME_ATTRIBUTE, 60 }, + { -1, -1 } }; -static struct _timeout_tape timeout_lto5[] = { - { ERASE, 18000 }, - { FORMAT_MEDIUM, 1560 }, - { LOAD_UNLOAD, 600 }, - { LOCATE10, 1200 }, - { LOCATE16, 1200 }, - { READ, 1200 }, - { READ_BUFFER, 60 }, - { REWIND, 600 }, - { SEND_DIAGNOSTIC, 600 }, - { SET_CAPACITY, 780 }, - { SPACE6, 1200 }, - { SPACE16, 1200 }, - { VERIFY, 18000 }, - { WRITE, 300 }, - { WRITE_BUFFER, 60 }, - { WRITE_FILEMARKS6, 300 }, - {-1, -1} -}; +static struct _timeout_tape timeout_lto5[] = { { ERASE, 18000 }, + { FORMAT_MEDIUM, 1560 }, + { LOAD_UNLOAD, 600 }, + { LOCATE10, 1200 }, + { LOCATE16, 1200 }, + { READ, 1200 }, + { READ_BUFFER, 60 }, + { REWIND, 600 }, + { SEND_DIAGNOSTIC, 600 }, + { SET_CAPACITY, 780 }, + { SPACE6, 1200 }, + { SPACE16, 1200 }, + { VERIFY, 18000 }, + { WRITE, 300 }, + { WRITE_BUFFER, 60 }, + { WRITE_FILEMARKS6, 300 }, + { -1, -1 } }; -static struct _timeout_tape timeout_lto6[] = { - { ERASE, 18000 }, - { FORMAT_MEDIUM, 1560 }, - { LOAD_UNLOAD, 600 }, - { LOCATE10, 1200 }, - { LOCATE16, 1200 }, - { READ, 1200 }, - { READ_BUFFER, 60 }, - { REWIND, 600 }, - { SEND_DIAGNOSTIC, 600 }, - { SET_CAPACITY, 780 }, - { SPACE6, 1200 }, - { SPACE16, 1200 }, - { VERIFY, 18000 }, - { WRITE, 300 }, - { WRITE_BUFFER, 60 }, - { WRITE_FILEMARKS6, 300 }, - {-1, -1} -}; +static struct _timeout_tape timeout_lto6[] = { { ERASE, 18000 }, + { FORMAT_MEDIUM, 1560 }, + { LOAD_UNLOAD, 600 }, + { LOCATE10, 1200 }, + { LOCATE16, 1200 }, + { READ, 1200 }, + { READ_BUFFER, 60 }, + { REWIND, 600 }, + { SEND_DIAGNOSTIC, 600 }, + { SET_CAPACITY, 780 }, + { SPACE6, 1200 }, + { SPACE16, 1200 }, + { VERIFY, 18000 }, + { WRITE, 300 }, + { WRITE_BUFFER, 60 }, + { WRITE_FILEMARKS6, 300 }, + { -1, -1 } }; -static struct _timeout_tape timeout_lto7[] = { - { ERASE, 29400 }, - { FORMAT_MEDIUM, 3000 }, - { LOAD_UNLOAD, 1020 }, - { LOCATE10, 2700 }, - { LOCATE16, 2700 }, - { READ, 1920 }, - { READ_BUFFER, 480 }, - { REWIND, 780 }, - { SEND_DIAGNOSTIC, 1980 }, - { SET_CAPACITY, 780 }, - { SPACE6, 2700 }, - { SPACE16, 2700 }, - { VERIFY, 28860 }, - { WRITE, 1920 }, - { WRITE_BUFFER, 540 }, - { WRITE_FILEMARKS6, 1920 }, - {-1, -1} -}; +static struct _timeout_tape timeout_lto7[] = { { ERASE, 29400 }, + { FORMAT_MEDIUM, 3000 }, + { LOAD_UNLOAD, 1020 }, + { LOCATE10, 2700 }, + { LOCATE16, 2700 }, + { READ, 1920 }, + { READ_BUFFER, 480 }, + { REWIND, 780 }, + { SEND_DIAGNOSTIC, 1980 }, + { SET_CAPACITY, 780 }, + { SPACE6, 2700 }, + { SPACE16, 2700 }, + { VERIFY, 28860 }, + { WRITE, 1920 }, + { WRITE_BUFFER, 540 }, + { WRITE_FILEMARKS6, 1920 }, + { -1, -1 } }; -static struct _timeout_tape timeout_lto8[] = { - { ERASE, 53040 }, - { FORMAT_MEDIUM, 3000 }, - { LOAD_UNLOAD, 840 }, - { LOCATE10, 2940 }, - { LOCATE16, 2940 }, - { READ, 2340 }, - { READ_BUFFER, 480 }, - { REWIND, 660 }, - { SEND_DIAGNOSTIC, 1980 }, - { SET_CAPACITY, 780 }, - { SPACE6, 2940 }, - { SPACE16, 2940 }, - { VERIFY, 53040 }, - { WRITE, 1680 }, - { WRITE_BUFFER, 540 }, - { WRITE_FILEMARKS6, 1680 }, - {-1, -1} -}; +static struct _timeout_tape timeout_lto8[] = { { ERASE, 53040 }, + { FORMAT_MEDIUM, 3000 }, + { LOAD_UNLOAD, 840 }, + { LOCATE10, 2940 }, + { LOCATE16, 2940 }, + { READ, 2340 }, + { READ_BUFFER, 480 }, + { REWIND, 660 }, + { SEND_DIAGNOSTIC, 1980 }, + { SET_CAPACITY, 780 }, + { SPACE6, 2940 }, + { SPACE16, 2940 }, + { VERIFY, 53040 }, + { WRITE, 1680 }, + { WRITE_BUFFER, 540 }, + { WRITE_FILEMARKS6, 1680 }, + { -1, -1 } }; -static struct _timeout_tape timeout_lto9[] = { - { ERASE, 53040 }, - { FORMAT_MEDIUM, 3000 }, - { LOAD_UNLOAD, 840 }, - { LOCATE10, 2940 }, - { LOCATE16, 2940 }, - { READ, 2340 }, - { READ_BUFFER, 480 }, - { REWIND, 660 }, - { SEND_DIAGNOSTIC, 1980 }, - { SET_CAPACITY, 780 }, - { SPACE6, 2940 }, - { SPACE16, 2940 }, - { VERIFY, 53040 }, - { WRITE, 1680 }, - { WRITE_BUFFER, 540 }, - { WRITE_FILEMARKS6, 1680 }, - {-1, -1} -}; +static struct _timeout_tape timeout_lto9[] = { { ERASE, 53040 }, + { FORMAT_MEDIUM, 3000 }, + { LOAD_UNLOAD, 840 }, + { LOCATE10, 2940 }, + { LOCATE16, 2940 }, + { READ, 2340 }, + { READ_BUFFER, 480 }, + { REWIND, 660 }, + { SEND_DIAGNOSTIC, 1980 }, + { SET_CAPACITY, 780 }, + { SPACE6, 2940 }, + { SPACE16, 2940 }, + { VERIFY, 53040 }, + { WRITE, 1680 }, + { WRITE_BUFFER, 540 }, + { WRITE_FILEMARKS6, 1680 }, + { -1, -1 } }; -static struct _timeout_tape timeout_lto10[] = { - { ERASE, 16320 }, - { FORMAT_MEDIUM, 3180 }, - { LOAD_UNLOAD, 780 }, - { LOCATE10, 2940 }, - { LOCATE16, 2940 }, - { READ, 2340 }, - { READ_BUFFER, 480 }, - { REWIND, 600 }, - { SEND_DIAGNOSTIC, 1980 }, - { SET_CAPACITY, 780 }, - { SPACE6, 2940 }, - { SPACE16, 2940 }, - { VERIFY, 104880 }, - { WRITE, 1500 }, - { WRITE_BUFFER, 540 }, - { WRITE_FILEMARKS6, 1620 }, - {-1, -1} -}; +static struct _timeout_tape timeout_lto10[] = { { ERASE, 16320 }, + { FORMAT_MEDIUM, 3180 }, + { LOAD_UNLOAD, 780 }, + { LOCATE10, 2940 }, + { LOCATE16, 2940 }, + { READ, 2340 }, + { READ_BUFFER, 480 }, + { REWIND, 600 }, + { SEND_DIAGNOSTIC, 1980 }, + { SET_CAPACITY, 780 }, + { SPACE6, 2940 }, + { SPACE16, 2940 }, + { VERIFY, 104880 }, + { WRITE, 1500 }, + { WRITE_BUFFER, 540 }, + { WRITE_FILEMARKS6, 1620 }, + { -1, -1 } }; -static struct _timeout_tape timeout_lto5_hh[] = { - { ERASE, 18000 }, - { FORMAT_MEDIUM, 1560 }, - { LOAD_UNLOAD, 600 }, - { LOCATE10, 1200 }, - { LOCATE16, 1200 }, - { READ, 1200 }, - { READ_BUFFER, 60 }, - { REWIND, 600 }, - { SEND_DIAGNOSTIC, 600 }, - { SET_CAPACITY, 780 }, - { SPACE6, 1200 }, - { SPACE16, 1200 }, - { VERIFY, 18000 }, - { WRITE, 300 }, - { WRITE_BUFFER, 60 }, - { WRITE_FILEMARKS6, 300 }, - {-1, -1} -}; +static struct _timeout_tape timeout_lto5_hh[] = { { ERASE, 18000 }, + { FORMAT_MEDIUM, 1560 }, + { LOAD_UNLOAD, 600 }, + { LOCATE10, 1200 }, + { LOCATE16, 1200 }, + { READ, 1200 }, + { READ_BUFFER, 60 }, + { REWIND, 600 }, + { SEND_DIAGNOSTIC, 600 }, + { SET_CAPACITY, 780 }, + { SPACE6, 1200 }, + { SPACE16, 1200 }, + { VERIFY, 18000 }, + { WRITE, 300 }, + { WRITE_BUFFER, 60 }, + { WRITE_FILEMARKS6, 300 }, + { -1, -1 } }; -static struct _timeout_tape timeout_lto6_hh[] = { - { ERASE, 18000 }, - { FORMAT_MEDIUM, 1560 }, - { LOAD_UNLOAD, 600 }, - { LOCATE10, 1200 }, - { LOCATE16, 1200 }, - { READ, 1200 }, - { READ_BUFFER, 60 }, - { REWIND, 600 }, - { SEND_DIAGNOSTIC, 600 }, - { SET_CAPACITY, 780 }, - { SPACE6, 1200 }, - { SPACE16, 1200 }, - { VERIFY, 18000 }, - { WRITE, 300 }, - { WRITE_BUFFER, 60 }, - { WRITE_FILEMARKS6, 300 }, - {-1, -1} -}; +static struct _timeout_tape timeout_lto6_hh[] = { { ERASE, 18000 }, + { FORMAT_MEDIUM, 1560 }, + { LOAD_UNLOAD, 600 }, + { LOCATE10, 1200 }, + { LOCATE16, 1200 }, + { READ, 1200 }, + { READ_BUFFER, 60 }, + { REWIND, 600 }, + { SEND_DIAGNOSTIC, 600 }, + { SET_CAPACITY, 780 }, + { SPACE6, 1200 }, + { SPACE16, 1200 }, + { VERIFY, 18000 }, + { WRITE, 300 }, + { WRITE_BUFFER, 60 }, + { WRITE_FILEMARKS6, 300 }, + { -1, -1 } }; -static struct _timeout_tape timeout_lto7_hh[] = { - { ERASE, 29400 }, - { FORMAT_MEDIUM, 3000 }, - { LOAD_UNLOAD, 1020 }, - { LOCATE10, 2700 }, - { LOCATE16, 2700 }, - { READ, 1920 }, - { READ_BUFFER, 480 }, - { REWIND, 780 }, - { SEND_DIAGNOSTIC, 1980 }, - { SET_CAPACITY, 780 }, - { SPACE6, 2700 }, - { SPACE16, 2700 }, - { VERIFY, 28860 }, - { WRITE, 1920 }, - { WRITE_BUFFER, 540 }, - { WRITE_FILEMARKS6, 1920 }, - {-1, -1} -}; +static struct _timeout_tape timeout_lto7_hh[] = { { ERASE, 29400 }, + { FORMAT_MEDIUM, 3000 }, + { LOAD_UNLOAD, 1020 }, + { LOCATE10, 2700 }, + { LOCATE16, 2700 }, + { READ, 1920 }, + { READ_BUFFER, 480 }, + { REWIND, 780 }, + { SEND_DIAGNOSTIC, 1980 }, + { SET_CAPACITY, 780 }, + { SPACE6, 2700 }, + { SPACE16, 2700 }, + { VERIFY, 28860 }, + { WRITE, 1920 }, + { WRITE_BUFFER, 540 }, + { WRITE_FILEMARKS6, 1920 }, + { -1, -1 } }; -static struct _timeout_tape timeout_lto8_hh[] = { - { ERASE, 53040 }, - { FORMAT_MEDIUM, 3000 }, - { LOAD_UNLOAD, 840 }, - { LOCATE10, 2940 }, - { LOCATE16, 2940 }, - { READ, 2340 }, - { READ_BUFFER, 480 }, - { REWIND, 660 }, - { SEND_DIAGNOSTIC, 1980 }, - { SET_CAPACITY, 780 }, - { SPACE6, 2940 }, - { SPACE16, 2940 }, - { VERIFY, 53040 }, - { WRITE, 1680 }, - { WRITE_BUFFER, 540 }, - { WRITE_FILEMARKS6, 1680 }, - {-1, -1} -}; +static struct _timeout_tape timeout_lto8_hh[] = { { ERASE, 53040 }, + { FORMAT_MEDIUM, 3000 }, + { LOAD_UNLOAD, 840 }, + { LOCATE10, 2940 }, + { LOCATE16, 2940 }, + { READ, 2340 }, + { READ_BUFFER, 480 }, + { REWIND, 660 }, + { SEND_DIAGNOSTIC, 1980 }, + { SET_CAPACITY, 780 }, + { SPACE6, 2940 }, + { SPACE16, 2940 }, + { VERIFY, 53040 }, + { WRITE, 1680 }, + { WRITE_BUFFER, 540 }, + { WRITE_FILEMARKS6, 1680 }, + { -1, -1 } }; -static struct _timeout_tape timeout_lto9_hh[] = { - { ERASE, 53040 }, - { FORMAT_MEDIUM, 3000 }, - { LOAD_UNLOAD, 840 }, - { LOCATE10, 2940 }, - { LOCATE16, 2940 }, - { READ, 2340 }, - { READ_BUFFER, 480 }, - { REWIND, 660 }, - { SEND_DIAGNOSTIC, 1980 }, - { SET_CAPACITY, 780 }, - { SPACE6, 2940 }, - { SPACE16, 2940 }, - { VERIFY, 53040 }, - { WRITE, 1680 }, - { WRITE_BUFFER, 540 }, - { WRITE_FILEMARKS6, 1680 }, - {-1, -1} -}; +static struct _timeout_tape timeout_lto9_hh[] = { { ERASE, 53040 }, + { FORMAT_MEDIUM, 3000 }, + { LOAD_UNLOAD, 840 }, + { LOCATE10, 2940 }, + { LOCATE16, 2940 }, + { READ, 2340 }, + { READ_BUFFER, 480 }, + { REWIND, 660 }, + { SEND_DIAGNOSTIC, 1980 }, + { SET_CAPACITY, 780 }, + { SPACE6, 2940 }, + { SPACE16, 2940 }, + { VERIFY, 53040 }, + { WRITE, 1680 }, + { WRITE_BUFFER, 540 }, + { WRITE_FILEMARKS6, 1680 }, + { -1, -1 } }; -static struct _timeout_tape timeout_lto10_hh[] = { - { ERASE, 166370 }, - { FORMAT_MEDIUM, 3240 }, - { LOAD_UNLOAD, 960 }, - { LOCATE10, 3940 }, - { LOCATE16, 3940 }, - { READ, 2340 }, - { READ_BUFFER, 480 }, - { REWIND, 600 }, - { SEND_DIAGNOSTIC, 2040 }, - { SET_CAPACITY, 960 }, - { SPACE6, 3940 }, - { SPACE16, 3940 }, - { VERIFY, 63300 }, - { WRITE, 1560 }, - { WRITE_BUFFER, 540 }, - { WRITE_FILEMARKS6, 1680 }, - {-1, -1} -}; +static struct _timeout_tape timeout_lto10_hh[] = { { ERASE, 166370 }, + { FORMAT_MEDIUM, 3240 }, + { LOAD_UNLOAD, 960 }, + { LOCATE10, 3940 }, + { LOCATE16, 3940 }, + { READ, 2340 }, + { READ_BUFFER, 480 }, + { REWIND, 600 }, + { SEND_DIAGNOSTIC, 2040 }, + { SET_CAPACITY, 960 }, + { SPACE6, 3940 }, + { SPACE16, 3940 }, + { VERIFY, 63300 }, + { WRITE, 1560 }, + { WRITE_BUFFER, 540 }, + { WRITE_FILEMARKS6, 1680 }, + { -1, -1 } }; -static int _create_table_tape(struct timeout_tape **result, - struct _timeout_tape* base, - struct _timeout_tape* override) +static int _create_table_tape(struct timeout_tape **result, struct _timeout_tape *base, struct _timeout_tape *override) { - struct _timeout_tape* cur; - struct timeout_tape* entry; + struct _timeout_tape *cur; + struct timeout_tape *entry; struct timeout_tape *out = NULL; entry = malloc(sizeof(struct timeout_tape)); - entry->op_code = override->op_code; + entry->op_code = override->op_code; entry->timeout = override->timeout; HASH_ADD_INT(*result, op_code, entry); - if (! *result) { + if (!*result) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } - for ( cur = override; cur->op_code != -1; ++cur) { + for (cur = override; cur->op_code != -1; ++cur) { entry = malloc(sizeof(struct timeout_tape)); - entry->op_code = cur->op_code; + entry->op_code = cur->op_code; entry->timeout = cur->timeout; HASH_ADD_INT(*result, op_code, entry); } - for ( cur = base; cur->op_code != -1; ++cur) { + for (cur = base; cur->op_code != -1; ++cur) { out = NULL; HASH_FIND_INT(*result, &cur->op_code, out); if (!out) { entry = malloc(sizeof(struct timeout_tape)); - entry->op_code = cur->op_code; + entry->op_code = cur->op_code; entry->timeout = cur->timeout; HASH_ADD_INT(*result, op_code, entry); } @@ -404,7 +377,7 @@ static int _create_table_tape(struct timeout_tape **result, return 0; } -int hp_tape_init_timeout(struct timeout_tape** table, int type) +int hp_tape_init_timeout(struct timeout_tape **table, int type) { int ret = 0; diff --git a/src/tape_drivers/ibm_tape.c b/src/tape_drivers/ibm_tape.c index 21c12e1d..ab4a9eab 100644 --- a/src/tape_drivers/ibm_tape.c +++ b/src/tape_drivers/ibm_tape.c @@ -48,16 +48,16 @@ */ #ifndef mingw_PLATFORM -#if defined (__FreeBSD__) || defined(__NetBSD__) -#include -#include -#include -#endif /* __FreeBSD__ */ -#include -#include -#include - -#define LOOP_BACK_DEVICE "lo" +# if defined(__FreeBSD__) || defined(__NetBSD__) +# include +# include +# include +# endif /* __FreeBSD__ */ +# include +# include +# include + +# define LOOP_BACK_DEVICE "lo" #endif #include "tape_drivers/ibm_tape.h" @@ -65,860 +65,740 @@ DRIVE_DENSITY_SUPPORT_MAP jaguar_drive_density[] = { /* TS1170 */ - { DRIVE_GEN_JAG7, TC_MP_JF, TC_DC_JAG7, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG7, TC_MP_JF, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, + { DRIVE_GEN_JAG7, TC_MP_JF, TC_DC_JAG7, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG7, TC_MP_JF, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, /* TS1160 */ - { DRIVE_GEN_JAG6, TC_MP_JE, TC_DC_JAG6, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG6, TC_MP_JE, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, - { DRIVE_GEN_JAG6, TC_MP_JV, TC_DC_JAG6, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG6, TC_MP_JV, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, - { DRIVE_GEN_JAG6, TC_MP_JM, TC_DC_JAG6, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG6, TC_MP_JM, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, - { DRIVE_GEN_JAG6, TC_MP_JD, TC_DC_JAG5A, MEDIUM_WRITABLE }, - { DRIVE_GEN_JAG6, TC_MP_JD, TC_DC_JAG5, MEDIUM_WRITABLE }, - { DRIVE_GEN_JAG6, TC_MP_JD, TC_DC_UNKNOWN, MEDIUM_WRITABLE }, - { DRIVE_GEN_JAG6, TC_MP_JL, TC_DC_JAG5A, MEDIUM_WRITABLE }, - { DRIVE_GEN_JAG6, TC_MP_JL, TC_DC_JAG5, MEDIUM_WRITABLE }, - { DRIVE_GEN_JAG6, TC_MP_JL, TC_DC_UNKNOWN, MEDIUM_WRITABLE }, - { DRIVE_GEN_JAG6, TC_MP_JZ, TC_DC_JAG5A, MEDIUM_WRITABLE }, - { DRIVE_GEN_JAG6, TC_MP_JZ, TC_DC_JAG5, MEDIUM_WRITABLE }, - { DRIVE_GEN_JAG6, TC_MP_JZ, TC_DC_UNKNOWN, MEDIUM_WRITABLE }, - { DRIVE_GEN_JAG6, TC_MP_JC, TC_DC_JAG5, MEDIUM_WRITABLE }, - { DRIVE_GEN_JAG6, TC_MP_JC, TC_DC_JAG4, MEDIUM_READONLY }, - { DRIVE_GEN_JAG6, TC_MP_JC, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, - { DRIVE_GEN_JAG6, TC_MP_JK, TC_DC_JAG5, MEDIUM_WRITABLE }, - { DRIVE_GEN_JAG6, TC_MP_JK, TC_DC_JAG4, MEDIUM_READONLY }, - { DRIVE_GEN_JAG6, TC_MP_JK, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, - { DRIVE_GEN_JAG6, TC_MP_JY, TC_DC_JAG5, MEDIUM_WRITABLE }, - { DRIVE_GEN_JAG6, TC_MP_JY, TC_DC_JAG4, MEDIUM_READONLY }, - { DRIVE_GEN_JAG6, TC_MP_JY, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, + { DRIVE_GEN_JAG6, TC_MP_JE, TC_DC_JAG6, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG6, TC_MP_JE, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, + { DRIVE_GEN_JAG6, TC_MP_JV, TC_DC_JAG6, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG6, TC_MP_JV, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, + { DRIVE_GEN_JAG6, TC_MP_JM, TC_DC_JAG6, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG6, TC_MP_JM, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, + { DRIVE_GEN_JAG6, TC_MP_JD, TC_DC_JAG5A, MEDIUM_WRITABLE }, + { DRIVE_GEN_JAG6, TC_MP_JD, TC_DC_JAG5, MEDIUM_WRITABLE }, + { DRIVE_GEN_JAG6, TC_MP_JD, TC_DC_UNKNOWN, MEDIUM_WRITABLE }, + { DRIVE_GEN_JAG6, TC_MP_JL, TC_DC_JAG5A, MEDIUM_WRITABLE }, + { DRIVE_GEN_JAG6, TC_MP_JL, TC_DC_JAG5, MEDIUM_WRITABLE }, + { DRIVE_GEN_JAG6, TC_MP_JL, TC_DC_UNKNOWN, MEDIUM_WRITABLE }, + { DRIVE_GEN_JAG6, TC_MP_JZ, TC_DC_JAG5A, MEDIUM_WRITABLE }, + { DRIVE_GEN_JAG6, TC_MP_JZ, TC_DC_JAG5, MEDIUM_WRITABLE }, + { DRIVE_GEN_JAG6, TC_MP_JZ, TC_DC_UNKNOWN, MEDIUM_WRITABLE }, + { DRIVE_GEN_JAG6, TC_MP_JC, TC_DC_JAG5, MEDIUM_WRITABLE }, + { DRIVE_GEN_JAG6, TC_MP_JC, TC_DC_JAG4, MEDIUM_READONLY }, + { DRIVE_GEN_JAG6, TC_MP_JC, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, + { DRIVE_GEN_JAG6, TC_MP_JK, TC_DC_JAG5, MEDIUM_WRITABLE }, + { DRIVE_GEN_JAG6, TC_MP_JK, TC_DC_JAG4, MEDIUM_READONLY }, + { DRIVE_GEN_JAG6, TC_MP_JK, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, + { DRIVE_GEN_JAG6, TC_MP_JY, TC_DC_JAG5, MEDIUM_WRITABLE }, + { DRIVE_GEN_JAG6, TC_MP_JY, TC_DC_JAG4, MEDIUM_READONLY }, + { DRIVE_GEN_JAG6, TC_MP_JY, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, /* TS1155 */ - { DRIVE_GEN_JAG5A, TC_MP_JD, TC_DC_JAG5A, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG5A, TC_MP_JD, TC_DC_JAG5, MEDIUM_WRITABLE }, + { DRIVE_GEN_JAG5A, TC_MP_JD, TC_DC_JAG5A, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG5A, TC_MP_JD, TC_DC_JAG5, MEDIUM_WRITABLE }, { DRIVE_GEN_JAG5A, TC_MP_JD, TC_DC_UNKNOWN, MEDIUM_WRITABLE }, - { DRIVE_GEN_JAG5A, TC_MP_JL, TC_DC_JAG5A, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG5A, TC_MP_JL, TC_DC_JAG5, MEDIUM_WRITABLE }, + { DRIVE_GEN_JAG5A, TC_MP_JL, TC_DC_JAG5A, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG5A, TC_MP_JL, TC_DC_JAG5, MEDIUM_WRITABLE }, { DRIVE_GEN_JAG5A, TC_MP_JL, TC_DC_UNKNOWN, MEDIUM_WRITABLE }, - { DRIVE_GEN_JAG5A, TC_MP_JZ, TC_DC_JAG5A, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG5A, TC_MP_JZ, TC_DC_JAG5, MEDIUM_WRITABLE }, + { DRIVE_GEN_JAG5A, TC_MP_JZ, TC_DC_JAG5A, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG5A, TC_MP_JZ, TC_DC_JAG5, MEDIUM_WRITABLE }, { DRIVE_GEN_JAG5A, TC_MP_JZ, TC_DC_UNKNOWN, MEDIUM_WRITABLE }, - { DRIVE_GEN_JAG5A, TC_MP_JC, TC_DC_JAG5, MEDIUM_WRITABLE }, - { DRIVE_GEN_JAG5A, TC_MP_JC, TC_DC_JAG4, MEDIUM_READONLY }, + { DRIVE_GEN_JAG5A, TC_MP_JC, TC_DC_JAG5, MEDIUM_WRITABLE }, + { DRIVE_GEN_JAG5A, TC_MP_JC, TC_DC_JAG4, MEDIUM_READONLY }, { DRIVE_GEN_JAG5A, TC_MP_JC, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, - { DRIVE_GEN_JAG5A, TC_MP_JK, TC_DC_JAG5, MEDIUM_WRITABLE }, - { DRIVE_GEN_JAG5A, TC_MP_JK, TC_DC_JAG4, MEDIUM_READONLY }, + { DRIVE_GEN_JAG5A, TC_MP_JK, TC_DC_JAG5, MEDIUM_WRITABLE }, + { DRIVE_GEN_JAG5A, TC_MP_JK, TC_DC_JAG4, MEDIUM_READONLY }, { DRIVE_GEN_JAG5A, TC_MP_JK, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, - { DRIVE_GEN_JAG5A, TC_MP_JY, TC_DC_JAG5, MEDIUM_WRITABLE }, - { DRIVE_GEN_JAG5A, TC_MP_JY, TC_DC_JAG4, MEDIUM_READONLY }, + { DRIVE_GEN_JAG5A, TC_MP_JY, TC_DC_JAG5, MEDIUM_WRITABLE }, + { DRIVE_GEN_JAG5A, TC_MP_JY, TC_DC_JAG4, MEDIUM_READONLY }, { DRIVE_GEN_JAG5A, TC_MP_JY, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, /* TS1150 */ - { DRIVE_GEN_JAG5, TC_MP_JD, TC_DC_JAG5, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG5, TC_MP_JD, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, - { DRIVE_GEN_JAG5, TC_MP_JL, TC_DC_JAG5, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG5, TC_MP_JL, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, - { DRIVE_GEN_JAG5, TC_MP_JZ, TC_DC_JAG5, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG5, TC_MP_JZ, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, - { DRIVE_GEN_JAG5, TC_MP_JC, TC_DC_JAG5, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG5, TC_MP_JC, TC_DC_JAG4, MEDIUM_WRITABLE }, - { DRIVE_GEN_JAG5, TC_MP_JC, TC_DC_UNKNOWN, MEDIUM_WRITABLE }, - { DRIVE_GEN_JAG5, TC_MP_JK, TC_DC_JAG5, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG5, TC_MP_JK, TC_DC_JAG4, MEDIUM_WRITABLE }, - { DRIVE_GEN_JAG5, TC_MP_JK, TC_DC_UNKNOWN, MEDIUM_WRITABLE }, - { DRIVE_GEN_JAG5, TC_MP_JY, TC_DC_JAG5, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG5, TC_MP_JY, TC_DC_JAG4, MEDIUM_WRITABLE }, - { DRIVE_GEN_JAG5, TC_MP_JY, TC_DC_UNKNOWN, MEDIUM_WRITABLE }, + { DRIVE_GEN_JAG5, TC_MP_JD, TC_DC_JAG5, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG5, TC_MP_JD, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, + { DRIVE_GEN_JAG5, TC_MP_JL, TC_DC_JAG5, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG5, TC_MP_JL, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, + { DRIVE_GEN_JAG5, TC_MP_JZ, TC_DC_JAG5, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG5, TC_MP_JZ, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, + { DRIVE_GEN_JAG5, TC_MP_JC, TC_DC_JAG5, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG5, TC_MP_JC, TC_DC_JAG4, MEDIUM_WRITABLE }, + { DRIVE_GEN_JAG5, TC_MP_JC, TC_DC_UNKNOWN, MEDIUM_WRITABLE }, + { DRIVE_GEN_JAG5, TC_MP_JK, TC_DC_JAG5, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG5, TC_MP_JK, TC_DC_JAG4, MEDIUM_WRITABLE }, + { DRIVE_GEN_JAG5, TC_MP_JK, TC_DC_UNKNOWN, MEDIUM_WRITABLE }, + { DRIVE_GEN_JAG5, TC_MP_JY, TC_DC_JAG5, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG5, TC_MP_JY, TC_DC_JAG4, MEDIUM_WRITABLE }, + { DRIVE_GEN_JAG5, TC_MP_JY, TC_DC_UNKNOWN, MEDIUM_WRITABLE }, /* TS1140 */ - { DRIVE_GEN_JAG4, TC_MP_JC, TC_DC_JAG4, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG4, TC_MP_JC, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, - { DRIVE_GEN_JAG4, TC_MP_JK, TC_DC_JAG4, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG4, TC_MP_JK, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, - { DRIVE_GEN_JAG4, TC_MP_JY, TC_DC_JAG4, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG4, TC_MP_JY, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, - { DRIVE_GEN_JAG4, TC_MP_JB, TC_DC_JAG4, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG4, TC_MP_JB, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, - { DRIVE_GEN_JAG4, TC_MP_JX, TC_DC_JAG4, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG4, TC_MP_JX, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, + { DRIVE_GEN_JAG4, TC_MP_JC, TC_DC_JAG4, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG4, TC_MP_JC, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, + { DRIVE_GEN_JAG4, TC_MP_JK, TC_DC_JAG4, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG4, TC_MP_JK, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, + { DRIVE_GEN_JAG4, TC_MP_JY, TC_DC_JAG4, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG4, TC_MP_JY, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, + { DRIVE_GEN_JAG4, TC_MP_JB, TC_DC_JAG4, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG4, TC_MP_JB, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, + { DRIVE_GEN_JAG4, TC_MP_JX, TC_DC_JAG4, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG4, TC_MP_JX, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, }; DRIVE_DENSITY_SUPPORT_MAP jaguar_drive_density_strict[] = { /* TS1170 */ - { DRIVE_GEN_JAG7, TC_MP_JF, TC_DC_JAG7, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG7, TC_MP_JF, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, + { DRIVE_GEN_JAG7, TC_MP_JF, TC_DC_JAG7, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG7, TC_MP_JF, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, /* TS1160 */ - { DRIVE_GEN_JAG6, TC_MP_JE, TC_DC_JAG6, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG6, TC_MP_JE, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, - { DRIVE_GEN_JAG6, TC_MP_JV, TC_DC_JAG6, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG6, TC_MP_JV, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, - { DRIVE_GEN_JAG6, TC_MP_JM, TC_DC_JAG6, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG6, TC_MP_JM, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, + { DRIVE_GEN_JAG6, TC_MP_JE, TC_DC_JAG6, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG6, TC_MP_JE, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, + { DRIVE_GEN_JAG6, TC_MP_JV, TC_DC_JAG6, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG6, TC_MP_JV, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, + { DRIVE_GEN_JAG6, TC_MP_JM, TC_DC_JAG6, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG6, TC_MP_JM, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, /* TS1155 */ - { DRIVE_GEN_JAG5A, TC_MP_JD, TC_DC_JAG5A, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG5A, TC_MP_JD, TC_DC_JAG5A, MEDIUM_PERFECT_MATCH }, { DRIVE_GEN_JAG5A, TC_MP_JD, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, - { DRIVE_GEN_JAG5A, TC_MP_JL, TC_DC_JAG5A, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG5A, TC_MP_JL, TC_DC_JAG5A, MEDIUM_PERFECT_MATCH }, { DRIVE_GEN_JAG5A, TC_MP_JL, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, - { DRIVE_GEN_JAG5A, TC_MP_JZ, TC_DC_JAG5A, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG5A, TC_MP_JZ, TC_DC_JAG5A, MEDIUM_PERFECT_MATCH }, { DRIVE_GEN_JAG5A, TC_MP_JZ, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, /* TS1150 */ - { DRIVE_GEN_JAG5, TC_MP_JD, TC_DC_JAG5, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG5, TC_MP_JD, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, - { DRIVE_GEN_JAG5, TC_MP_JL, TC_DC_JAG5, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG5, TC_MP_JL, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, - { DRIVE_GEN_JAG5, TC_MP_JZ, TC_DC_JAG5, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG5, TC_MP_JZ, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, - { DRIVE_GEN_JAG5, TC_MP_JC, TC_DC_JAG5, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG5, TC_MP_JC, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, - { DRIVE_GEN_JAG5, TC_MP_JK, TC_DC_JAG5, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG5, TC_MP_JK, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, - { DRIVE_GEN_JAG5, TC_MP_JY, TC_DC_JAG5, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG5, TC_MP_JY, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, + { DRIVE_GEN_JAG5, TC_MP_JD, TC_DC_JAG5, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG5, TC_MP_JD, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, + { DRIVE_GEN_JAG5, TC_MP_JL, TC_DC_JAG5, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG5, TC_MP_JL, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, + { DRIVE_GEN_JAG5, TC_MP_JZ, TC_DC_JAG5, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG5, TC_MP_JZ, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, + { DRIVE_GEN_JAG5, TC_MP_JC, TC_DC_JAG5, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG5, TC_MP_JC, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, + { DRIVE_GEN_JAG5, TC_MP_JK, TC_DC_JAG5, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG5, TC_MP_JK, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, + { DRIVE_GEN_JAG5, TC_MP_JY, TC_DC_JAG5, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG5, TC_MP_JY, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, /* TS1140 */ - { DRIVE_GEN_JAG4, TC_MP_JC, TC_DC_JAG4, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG4, TC_MP_JC, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, - { DRIVE_GEN_JAG4, TC_MP_JK, TC_DC_JAG4, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG4, TC_MP_JK, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, - { DRIVE_GEN_JAG4, TC_MP_JY, TC_DC_JAG4, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG4, TC_MP_JY, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, - { DRIVE_GEN_JAG4, TC_MP_JB, TC_DC_JAG4, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG4, TC_MP_JB, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, - { DRIVE_GEN_JAG4, TC_MP_JX, TC_DC_JAG4, MEDIUM_PERFECT_MATCH }, - { DRIVE_GEN_JAG4, TC_MP_JX, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, + { DRIVE_GEN_JAG4, TC_MP_JC, TC_DC_JAG4, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG4, TC_MP_JC, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, + { DRIVE_GEN_JAG4, TC_MP_JK, TC_DC_JAG4, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG4, TC_MP_JK, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, + { DRIVE_GEN_JAG4, TC_MP_JY, TC_DC_JAG4, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG4, TC_MP_JY, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, + { DRIVE_GEN_JAG4, TC_MP_JB, TC_DC_JAG4, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG4, TC_MP_JB, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, + { DRIVE_GEN_JAG4, TC_MP_JX, TC_DC_JAG4, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_JAG4, TC_MP_JX, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, }; DRIVE_DENSITY_SUPPORT_MAP lto_drive_density[] = { /* LTO10 */ - { DRIVE_GEN_LTO10, TC_MP_LTO10D_CART, TC_DC_LTO10, MEDIUM_PERFECT_MATCH}, - { DRIVE_GEN_LTO10, TC_MP_LTOP10D_CART, TC_DC_LTOP10, MEDIUM_PERFECT_MATCH}, - { DRIVE_GEN_LTO10, TC_MP_LTO10D_CART, TC_DC_UNKNOWN, MEDIUM_PERFECT_MATCH}, - { DRIVE_GEN_LTO10, TC_MP_LTOP10D_CART, TC_DC_UNKNOWN, MEDIUM_PERFECT_MATCH}, + { DRIVE_GEN_LTO10, TC_MP_LTO10D_CART, TC_DC_LTO10, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_LTO10, TC_MP_LTOP10D_CART, TC_DC_LTOP10, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_LTO10, TC_MP_LTO10D_CART, TC_DC_UNKNOWN, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_LTO10, TC_MP_LTOP10D_CART, TC_DC_UNKNOWN, MEDIUM_PERFECT_MATCH }, /* LTO9 */ - { DRIVE_GEN_LTO9, TC_MP_LTO9D_CART, TC_DC_LTO9, MEDIUM_PERFECT_MATCH}, - { DRIVE_GEN_LTO9, TC_MP_LTO9D_CART, TC_DC_UNKNOWN, MEDIUM_PERFECT_MATCH}, - { DRIVE_GEN_LTO9, TC_MP_LTO8D_CART, TC_DC_LTO8, MEDIUM_WRITABLE}, - { DRIVE_GEN_LTO9, TC_MP_LTO8D_CART, TC_DC_UNKNOWN, MEDIUM_WRITABLE}, + { DRIVE_GEN_LTO9, TC_MP_LTO9D_CART, TC_DC_LTO9, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_LTO9, TC_MP_LTO9D_CART, TC_DC_UNKNOWN, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_LTO9, TC_MP_LTO8D_CART, TC_DC_LTO8, MEDIUM_WRITABLE }, + { DRIVE_GEN_LTO9, TC_MP_LTO8D_CART, TC_DC_UNKNOWN, MEDIUM_WRITABLE }, /* LTO8 */ - { DRIVE_GEN_LTO8, TC_MP_LTO8D_CART, TC_DC_LTO8, MEDIUM_PERFECT_MATCH}, - { DRIVE_GEN_LTO8, TC_MP_LTO7D_CART, TC_DC_LTOM8, MEDIUM_PERFECT_MATCH}, - { DRIVE_GEN_LTO8, TC_MP_LTO8D_CART, TC_DC_UNKNOWN, MEDIUM_PERFECT_MATCH}, - { DRIVE_GEN_LTO8, TC_MP_LTO7D_CART, TC_DC_LTO7, MEDIUM_WRITABLE}, - { DRIVE_GEN_LTO8, TC_MP_LTO7D_CART, TC_DC_UNKNOWN, MEDIUM_WRITABLE}, + { DRIVE_GEN_LTO8, TC_MP_LTO8D_CART, TC_DC_LTO8, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_LTO8, TC_MP_LTO7D_CART, TC_DC_LTOM8, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_LTO8, TC_MP_LTO8D_CART, TC_DC_UNKNOWN, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_LTO8, TC_MP_LTO7D_CART, TC_DC_LTO7, MEDIUM_WRITABLE }, + { DRIVE_GEN_LTO8, TC_MP_LTO7D_CART, TC_DC_UNKNOWN, MEDIUM_WRITABLE }, /* LTO7 */ - { DRIVE_GEN_LTO7, TC_MP_LTO7D_CART, TC_DC_LTO7, MEDIUM_PERFECT_MATCH}, - { DRIVE_GEN_LTO7, TC_MP_LTO7D_CART, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE}, - { DRIVE_GEN_LTO7, TC_MP_LTO6D_CART, TC_DC_LTO6, MEDIUM_WRITABLE}, - { DRIVE_GEN_LTO7, TC_MP_LTO6D_CART, TC_DC_UNKNOWN, MEDIUM_WRITABLE}, - { DRIVE_GEN_LTO7, TC_MP_LTO5D_CART, TC_DC_LTO5, MEDIUM_READONLY}, - { DRIVE_GEN_LTO7, TC_MP_LTO5D_CART, TC_DC_UNKNOWN, MEDIUM_READONLY}, + { DRIVE_GEN_LTO7, TC_MP_LTO7D_CART, TC_DC_LTO7, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_LTO7, TC_MP_LTO7D_CART, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, + { DRIVE_GEN_LTO7, TC_MP_LTO6D_CART, TC_DC_LTO6, MEDIUM_WRITABLE }, + { DRIVE_GEN_LTO7, TC_MP_LTO6D_CART, TC_DC_UNKNOWN, MEDIUM_WRITABLE }, + { DRIVE_GEN_LTO7, TC_MP_LTO5D_CART, TC_DC_LTO5, MEDIUM_READONLY }, + { DRIVE_GEN_LTO7, TC_MP_LTO5D_CART, TC_DC_UNKNOWN, MEDIUM_READONLY }, /* LTO6 */ - { DRIVE_GEN_LTO6, TC_MP_LTO6D_CART, TC_DC_LTO6, MEDIUM_PERFECT_MATCH}, - { DRIVE_GEN_LTO6, TC_MP_LTO6D_CART, TC_DC_UNKNOWN, MEDIUM_PERFECT_MATCH}, - { DRIVE_GEN_LTO6, TC_MP_LTO5D_CART, TC_DC_LTO5, MEDIUM_WRITABLE}, - { DRIVE_GEN_LTO6, TC_MP_LTO5D_CART, TC_DC_UNKNOWN, MEDIUM_WRITABLE}, + { DRIVE_GEN_LTO6, TC_MP_LTO6D_CART, TC_DC_LTO6, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_LTO6, TC_MP_LTO6D_CART, TC_DC_UNKNOWN, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_LTO6, TC_MP_LTO5D_CART, TC_DC_LTO5, MEDIUM_WRITABLE }, + { DRIVE_GEN_LTO6, TC_MP_LTO5D_CART, TC_DC_UNKNOWN, MEDIUM_WRITABLE }, /* LTO5 */ - { DRIVE_GEN_LTO5, TC_MP_LTO5D_CART, TC_DC_LTO5, MEDIUM_PERFECT_MATCH}, - { DRIVE_GEN_LTO5, TC_MP_LTO5D_CART, TC_DC_UNKNOWN, MEDIUM_PERFECT_MATCH}, + { DRIVE_GEN_LTO5, TC_MP_LTO5D_CART, TC_DC_LTO5, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_LTO5, TC_MP_LTO5D_CART, TC_DC_UNKNOWN, MEDIUM_PERFECT_MATCH }, }; DRIVE_DENSITY_SUPPORT_MAP lto_drive_density_strict[] = { /* LTO10 */ - { DRIVE_GEN_LTO10, TC_MP_LTO10D_CART, TC_DC_LTO10, MEDIUM_PERFECT_MATCH}, - { DRIVE_GEN_LTO10, TC_MP_LTOP10D_CART, TC_DC_LTOP10, MEDIUM_PERFECT_MATCH}, - { DRIVE_GEN_LTO10, TC_MP_LTO10D_CART, TC_DC_UNKNOWN, MEDIUM_PERFECT_MATCH}, - { DRIVE_GEN_LTO10, TC_MP_LTOP10D_CART, TC_DC_UNKNOWN, MEDIUM_PERFECT_MATCH}, + { DRIVE_GEN_LTO10, TC_MP_LTO10D_CART, TC_DC_LTO10, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_LTO10, TC_MP_LTOP10D_CART, TC_DC_LTOP10, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_LTO10, TC_MP_LTO10D_CART, TC_DC_UNKNOWN, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_LTO10, TC_MP_LTOP10D_CART, TC_DC_UNKNOWN, MEDIUM_PERFECT_MATCH }, /* LTO9 */ - { DRIVE_GEN_LTO9, TC_MP_LTO9D_CART, TC_DC_LTO9, MEDIUM_PERFECT_MATCH}, - { DRIVE_GEN_LTO9, TC_MP_LTO9D_CART, TC_DC_UNKNOWN, MEDIUM_PERFECT_MATCH}, + { DRIVE_GEN_LTO9, TC_MP_LTO9D_CART, TC_DC_LTO9, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_LTO9, TC_MP_LTO9D_CART, TC_DC_UNKNOWN, MEDIUM_PERFECT_MATCH }, /* LTO8 */ - { DRIVE_GEN_LTO8, TC_MP_LTO8D_CART, TC_DC_LTO8, MEDIUM_PERFECT_MATCH}, - { DRIVE_GEN_LTO8, TC_MP_LTO8D_CART, TC_DC_LTOM8, MEDIUM_PERFECT_MATCH}, - { DRIVE_GEN_LTO8, TC_MP_LTO8D_CART, TC_DC_UNKNOWN, MEDIUM_PERFECT_MATCH}, + { DRIVE_GEN_LTO8, TC_MP_LTO8D_CART, TC_DC_LTO8, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_LTO8, TC_MP_LTO8D_CART, TC_DC_LTOM8, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_LTO8, TC_MP_LTO8D_CART, TC_DC_UNKNOWN, MEDIUM_PERFECT_MATCH }, /* LTO7 */ - { DRIVE_GEN_LTO7, TC_MP_LTO7D_CART, TC_DC_LTO7, MEDIUM_PERFECT_MATCH}, - { DRIVE_GEN_LTO7, TC_MP_LTO7D_CART, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE}, + { DRIVE_GEN_LTO7, TC_MP_LTO7D_CART, TC_DC_LTO7, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_LTO7, TC_MP_LTO7D_CART, TC_DC_UNKNOWN, MEDIUM_PROBABLY_WRITABLE }, /* LTO6 */ - { DRIVE_GEN_LTO6, TC_MP_LTO6D_CART, TC_DC_LTO6, MEDIUM_PERFECT_MATCH}, - { DRIVE_GEN_LTO6, TC_MP_LTO6D_CART, TC_DC_UNKNOWN, MEDIUM_PERFECT_MATCH}, + { DRIVE_GEN_LTO6, TC_MP_LTO6D_CART, TC_DC_LTO6, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_LTO6, TC_MP_LTO6D_CART, TC_DC_UNKNOWN, MEDIUM_PERFECT_MATCH }, /* LTO5 */ - { DRIVE_GEN_LTO5, TC_MP_LTO5D_CART, TC_DC_LTO5, MEDIUM_PERFECT_MATCH}, - { DRIVE_GEN_LTO5, TC_MP_LTO5D_CART, TC_DC_UNKNOWN, MEDIUM_PERFECT_MATCH}, + { DRIVE_GEN_LTO5, TC_MP_LTO5D_CART, TC_DC_LTO5, MEDIUM_PERFECT_MATCH }, + { DRIVE_GEN_LTO5, TC_MP_LTO5D_CART, TC_DC_UNKNOWN, MEDIUM_PERFECT_MATCH }, }; const unsigned char supported_cart[] = { - TC_MP_LTOP10D_CART, - TC_MP_LTO10D_CART, - TC_MP_LTO9D_CART, - TC_MP_LTO8D_CART, - TC_MP_LTO7D_CART, - TC_MP_LTO6D_CART, - TC_MP_LTO5D_CART, - TC_MP_JB, - TC_MP_JC, - TC_MP_JD, - TC_MP_JK, - TC_MP_JY, - TC_MP_JL, - TC_MP_JZ, - TC_MP_JE, - TC_MP_JV, - TC_MP_JM, - TC_MP_JF, + TC_MP_LTOP10D_CART, TC_MP_LTO10D_CART, TC_MP_LTO9D_CART, TC_MP_LTO8D_CART, TC_MP_LTO7D_CART, TC_MP_LTO6D_CART, + TC_MP_LTO5D_CART, TC_MP_JB, TC_MP_JC, TC_MP_JD, TC_MP_JK, TC_MP_JY, + TC_MP_JL, TC_MP_JZ, TC_MP_JE, TC_MP_JV, TC_MP_JM, TC_MP_JF, }; const unsigned char supported_density[] = { - TC_DC_JAG7E, - TC_DC_JAG6E, - TC_DC_JAG5AE, - TC_DC_JAG5E, - TC_DC_JAG4E, - TC_DC_JAG7, - TC_DC_JAG6, - TC_DC_JAG5A, - TC_DC_JAG5, - TC_DC_JAG4, - TC_DC_LTOP10, - TC_DC_LTO10, - TC_DC_LTO9, - TC_DC_LTO8, - TC_DC_LTOM8, - TC_DC_LTO7, - TC_DC_LTO6, - TC_DC_LTO5, + TC_DC_JAG7E, TC_DC_JAG6E, TC_DC_JAG5AE, TC_DC_JAG5E, TC_DC_JAG4E, TC_DC_JAG7, TC_DC_JAG6, TC_DC_JAG5A, TC_DC_JAG5, + TC_DC_JAG4, TC_DC_LTOP10, TC_DC_LTO10, TC_DC_LTO9, TC_DC_LTO8, TC_DC_LTOM8, TC_DC_LTO7, TC_DC_LTO6, TC_DC_LTO5, }; -int num_jaguar_drive_density = sizeof(jaguar_drive_density) / sizeof(DRIVE_DENSITY_SUPPORT_MAP); +int num_jaguar_drive_density = sizeof(jaguar_drive_density) / sizeof(DRIVE_DENSITY_SUPPORT_MAP); int num_jaguar_drive_density_strict = sizeof(jaguar_drive_density_strict) / sizeof(DRIVE_DENSITY_SUPPORT_MAP); -int num_lto_drive_density = sizeof(lto_drive_density) / sizeof(DRIVE_DENSITY_SUPPORT_MAP); -int num_lto_drive_density_strict = sizeof(lto_drive_density_strict) / sizeof(DRIVE_DENSITY_SUPPORT_MAP); -int num_supported_cart = sizeof(supported_cart)/sizeof(supported_cart[0]); -int num_supported_density = sizeof(supported_density)/sizeof(supported_density[0]); +int num_lto_drive_density = sizeof(lto_drive_density) / sizeof(DRIVE_DENSITY_SUPPORT_MAP); +int num_lto_drive_density_strict = sizeof(lto_drive_density_strict) / sizeof(DRIVE_DENSITY_SUPPORT_MAP); +int num_supported_cart = sizeof(supported_cart) / sizeof(supported_cart[0]); +int num_supported_density = sizeof(supported_density) / sizeof(supported_density[0]); struct supported_device *ibm_supported_drives[] = { - TAPEDRIVE( IBM_VENDOR_ID, "ULTRIUM-TD5", DRIVE_LTO5, "[ULTRIUM-TD5]" ), /* IBM Ultrium Gen 5 */ - TAPEDRIVE( IBM_VENDOR_ID, "ULT3580-TD5", DRIVE_LTO5, "[ULT3580-TD5]" ), /* IBM Ultrium Gen 5 */ - TAPEDRIVE( IBM_VENDOR_ID, "ULTRIUM-HH5", DRIVE_LTO5_HH, "[ULTRIUM-HH5]" ), /* IBM Ultrium Gen 5 Half-High */ - TAPEDRIVE( IBM_VENDOR_ID, "ULT3580-HH5", DRIVE_LTO5_HH, "[ULT3580-HH5]" ), /* IBM Ultrium Gen 5 Half-High */ - TAPEDRIVE( IBM_VENDOR_ID, "HH LTO Gen 5", DRIVE_LTO5_HH, "[HH LTO Gen 5]" ), /* IBM Ultrium Gen 5 Half-High */ - TAPEDRIVE( IBM_VENDOR_ID, "ULTRIUM-TD6", DRIVE_LTO6, "[ULTRIUM-TD6]" ), /* IBM Ultrium Gen 6 */ - TAPEDRIVE( IBM_VENDOR_ID, "ULT3580-TD6", DRIVE_LTO6, "[ULT3580-TD6]" ), /* IBM Ultrium Gen 6 */ - TAPEDRIVE( IBM_VENDOR_ID, "ULTRIUM-HH6", DRIVE_LTO6_HH, "[ULTRIUM-HH6]" ), /* IBM Ultrium Gen 6 Half-High */ - TAPEDRIVE( IBM_VENDOR_ID, "ULT3580-HH6", DRIVE_LTO6_HH, "[ULT3580-HH6]" ), /* IBM Ultrium Gen 6 Half-High */ - TAPEDRIVE( IBM_VENDOR_ID, "HH LTO Gen 6", DRIVE_LTO6_HH, "[HH LTO Gen 6]" ), /* IBM Ultrium Gen 6 Half-High */ - TAPEDRIVE( IBM_VENDOR_ID, "ULTRIUM-TD7", DRIVE_LTO7, "[ULTRIUM-TD7]" ), /* IBM Ultrium Gen 7 */ - TAPEDRIVE( IBM_VENDOR_ID, "ULT3580-TD7", DRIVE_LTO7, "[ULT3580-TD7]" ), /* IBM Ultrium Gen 7 */ - TAPEDRIVE( IBM_VENDOR_ID, "ULTRIUM-HH7", DRIVE_LTO7_HH, "[ULTRIUM-HH7]" ), /* IBM Ultrium Gen 7 Half-High */ - TAPEDRIVE( IBM_VENDOR_ID, "ULT3580-HH7", DRIVE_LTO7_HH, "[ULT3580-HH7]" ), /* IBM Ultrium Gen 7 Half-High */ - TAPEDRIVE( IBM_VENDOR_ID, "HH LTO Gen 7", DRIVE_LTO7_HH, "[HH LTO Gen 7]" ), /* IBM Ultrium Gen 7 Half-High */ - TAPEDRIVE( IBM_VENDOR_ID, "ULTRIUM-TD8", DRIVE_LTO8, "[ULTRIUM-TD8]" ), /* IBM Ultrium Gen 8 */ - TAPEDRIVE( IBM_VENDOR_ID, "ULT3580-TD8", DRIVE_LTO8, "[ULT3580-TD8]" ), /* IBM Ultrium Gen 8 */ - TAPEDRIVE( IBM_VENDOR_ID, "ULTRIUM-HH8", DRIVE_LTO8_HH, "[ULTRIUM-HH8]" ), /* IBM Ultrium Gen 8 Half-High */ - TAPEDRIVE( IBM_VENDOR_ID, "ULT3580-HH8", DRIVE_LTO8_HH, "[ULT3580-HH8]" ), /* IBM Ultrium Gen 8 Half-High */ - TAPEDRIVE( IBM_VENDOR_ID, "HH LTO Gen 8", DRIVE_LTO8_HH, "[HH LTO Gen 8]" ), /* IBM Ultrium Gen 8 Half-High */ - TAPEDRIVE( IBM_VENDOR_ID, "ULTRIUM-TD9", DRIVE_LTO9, "[ULTRIUM-TD9]" ), /* IBM Ultrium Gen 9 */ - TAPEDRIVE( IBM_VENDOR_ID, "ULT3580-TD9", DRIVE_LTO9, "[ULT3580-TD9]" ), /* IBM Ultrium Gen 9 */ - TAPEDRIVE( IBM_VENDOR_ID, "ULTRIUM-HH9", DRIVE_LTO9_HH, "[ULTRIUM-HH9]" ), /* IBM Ultrium Gen 9 Half-High */ - TAPEDRIVE( IBM_VENDOR_ID, "ULT3580-HH9", DRIVE_LTO9_HH, "[ULT3580-HH9]" ), /* IBM Ultrium Gen 9 Half-High */ - TAPEDRIVE( IBM_VENDOR_ID, "HH LTO Gen 9", DRIVE_LTO9_HH, "[HH LTO Gen 9]" ), /* IBM Ultrium Gen 9 Half-High */ - TAPEDRIVE( IBM_VENDOR_ID, "ULTRIUM-TDA", DRIVE_LTO10, "[ULTRIUM-TDA]" ), /* IBM Ultrium Gen A */ - TAPEDRIVE( IBM_VENDOR_ID, "ULT3580-TDA", DRIVE_LTO10, "[ULT3580-TDA]"), /* IBM Ultrium Gen A */ - TAPEDRIVE( IBM_VENDOR_ID, "ULTRIUM-HHA", DRIVE_LTO10_HH,"[ULTRIUM-HHA]"), /* IBM Ultrium Gen A Half-High */ - TAPEDRIVE( IBM_VENDOR_ID, "ULT3580-HHA", DRIVE_LTO10_HH,"[ULT3580-HHA]"), /* IBM Ultrium Gen A Half-High */ - TAPEDRIVE( IBM_VENDOR_ID, "03592E07", DRIVE_TS1140, "[03592E07]" ), /* IBM TS1140 */ - TAPEDRIVE( IBM_VENDOR_ID, "03592E08", DRIVE_TS1150, "[03592E08]" ), /* IBM TS1150 */ - TAPEDRIVE( IBM_VENDOR_ID, "0359255F", DRIVE_TS1155, "[0359255F]" ), /* IBM TS1155 */ - TAPEDRIVE( IBM_VENDOR_ID, "0359255E", DRIVE_TS1155, "[0359255E]" ), /* IBM TS1155 */ - TAPEDRIVE( IBM_VENDOR_ID, "0359260F", DRIVE_TS1160, "[0359260F]" ), /* IBM TS1160 */ - TAPEDRIVE( IBM_VENDOR_ID, "0359260E", DRIVE_TS1160, "[0359260E]" ), /* IBM TS1160 */ - TAPEDRIVE( IBM_VENDOR_ID, "0359260S", DRIVE_TS1160, "[0359260S]" ), /* IBM TS1160 */ - TAPEDRIVE( IBM_VENDOR_ID, "0359270F", DRIVE_TS1170, "[0359270F]" ), /* IBM TS1170 */ - TAPEDRIVE( IBM_VENDOR_ID, "0359270S", DRIVE_TS1170, "[0359270S]" ), /* IBM TS1170 */ - /* End of supported_devices */ - NULL + TAPEDRIVE(IBM_VENDOR_ID, "ULTRIUM-TD5", DRIVE_LTO5, "[ULTRIUM-TD5]"), /* IBM Ultrium Gen 5 */ + TAPEDRIVE(IBM_VENDOR_ID, "ULT3580-TD5", DRIVE_LTO5, "[ULT3580-TD5]"), /* IBM Ultrium Gen 5 */ + TAPEDRIVE(IBM_VENDOR_ID, "ULTRIUM-HH5", DRIVE_LTO5_HH, "[ULTRIUM-HH5]"), /* IBM Ultrium Gen 5 Half-High */ + TAPEDRIVE(IBM_VENDOR_ID, "ULT3580-HH5", DRIVE_LTO5_HH, "[ULT3580-HH5]"), /* IBM Ultrium Gen 5 Half-High */ + TAPEDRIVE(IBM_VENDOR_ID, "HH LTO Gen 5", DRIVE_LTO5_HH, "[HH LTO Gen 5]"), /* IBM Ultrium Gen 5 Half-High */ + TAPEDRIVE(IBM_VENDOR_ID, "ULTRIUM-TD6", DRIVE_LTO6, "[ULTRIUM-TD6]"), /* IBM Ultrium Gen 6 */ + TAPEDRIVE(IBM_VENDOR_ID, "ULT3580-TD6", DRIVE_LTO6, "[ULT3580-TD6]"), /* IBM Ultrium Gen 6 */ + TAPEDRIVE(IBM_VENDOR_ID, "ULTRIUM-HH6", DRIVE_LTO6_HH, "[ULTRIUM-HH6]"), /* IBM Ultrium Gen 6 Half-High */ + TAPEDRIVE(IBM_VENDOR_ID, "ULT3580-HH6", DRIVE_LTO6_HH, "[ULT3580-HH6]"), /* IBM Ultrium Gen 6 Half-High */ + TAPEDRIVE(IBM_VENDOR_ID, "HH LTO Gen 6", DRIVE_LTO6_HH, "[HH LTO Gen 6]"), /* IBM Ultrium Gen 6 Half-High */ + TAPEDRIVE(IBM_VENDOR_ID, "ULTRIUM-TD7", DRIVE_LTO7, "[ULTRIUM-TD7]"), /* IBM Ultrium Gen 7 */ + TAPEDRIVE(IBM_VENDOR_ID, "ULT3580-TD7", DRIVE_LTO7, "[ULT3580-TD7]"), /* IBM Ultrium Gen 7 */ + TAPEDRIVE(IBM_VENDOR_ID, "ULTRIUM-HH7", DRIVE_LTO7_HH, "[ULTRIUM-HH7]"), /* IBM Ultrium Gen 7 Half-High */ + TAPEDRIVE(IBM_VENDOR_ID, "ULT3580-HH7", DRIVE_LTO7_HH, "[ULT3580-HH7]"), /* IBM Ultrium Gen 7 Half-High */ + TAPEDRIVE(IBM_VENDOR_ID, "HH LTO Gen 7", DRIVE_LTO7_HH, "[HH LTO Gen 7]"), /* IBM Ultrium Gen 7 Half-High */ + TAPEDRIVE(IBM_VENDOR_ID, "ULTRIUM-TD8", DRIVE_LTO8, "[ULTRIUM-TD8]"), /* IBM Ultrium Gen 8 */ + TAPEDRIVE(IBM_VENDOR_ID, "ULT3580-TD8", DRIVE_LTO8, "[ULT3580-TD8]"), /* IBM Ultrium Gen 8 */ + TAPEDRIVE(IBM_VENDOR_ID, "ULTRIUM-HH8", DRIVE_LTO8_HH, "[ULTRIUM-HH8]"), /* IBM Ultrium Gen 8 Half-High */ + TAPEDRIVE(IBM_VENDOR_ID, "ULT3580-HH8", DRIVE_LTO8_HH, "[ULT3580-HH8]"), /* IBM Ultrium Gen 8 Half-High */ + TAPEDRIVE(IBM_VENDOR_ID, "HH LTO Gen 8", DRIVE_LTO8_HH, "[HH LTO Gen 8]"), /* IBM Ultrium Gen 8 Half-High */ + TAPEDRIVE(IBM_VENDOR_ID, "ULTRIUM-TD9", DRIVE_LTO9, "[ULTRIUM-TD9]"), /* IBM Ultrium Gen 9 */ + TAPEDRIVE(IBM_VENDOR_ID, "ULT3580-TD9", DRIVE_LTO9, "[ULT3580-TD9]"), /* IBM Ultrium Gen 9 */ + TAPEDRIVE(IBM_VENDOR_ID, "ULTRIUM-HH9", DRIVE_LTO9_HH, "[ULTRIUM-HH9]"), /* IBM Ultrium Gen 9 Half-High */ + TAPEDRIVE(IBM_VENDOR_ID, "ULT3580-HH9", DRIVE_LTO9_HH, "[ULT3580-HH9]"), /* IBM Ultrium Gen 9 Half-High */ + TAPEDRIVE(IBM_VENDOR_ID, "HH LTO Gen 9", DRIVE_LTO9_HH, "[HH LTO Gen 9]"), /* IBM Ultrium Gen 9 Half-High */ + TAPEDRIVE(IBM_VENDOR_ID, "ULTRIUM-TDA", DRIVE_LTO10, "[ULTRIUM-TDA]"), /* IBM Ultrium Gen A */ + TAPEDRIVE(IBM_VENDOR_ID, "ULT3580-TDA", DRIVE_LTO10, "[ULT3580-TDA]"), /* IBM Ultrium Gen A */ + TAPEDRIVE(IBM_VENDOR_ID, "ULTRIUM-HHA", DRIVE_LTO10_HH, "[ULTRIUM-HHA]"), /* IBM Ultrium Gen A Half-High */ + TAPEDRIVE(IBM_VENDOR_ID, "ULT3580-HHA", DRIVE_LTO10_HH, "[ULT3580-HHA]"), /* IBM Ultrium Gen A Half-High */ + TAPEDRIVE(IBM_VENDOR_ID, "03592E07", DRIVE_TS1140, "[03592E07]"), /* IBM TS1140 */ + TAPEDRIVE(IBM_VENDOR_ID, "03592E08", DRIVE_TS1150, "[03592E08]"), /* IBM TS1150 */ + TAPEDRIVE(IBM_VENDOR_ID, "0359255F", DRIVE_TS1155, "[0359255F]"), /* IBM TS1155 */ + TAPEDRIVE(IBM_VENDOR_ID, "0359255E", DRIVE_TS1155, "[0359255E]"), /* IBM TS1155 */ + TAPEDRIVE(IBM_VENDOR_ID, "0359260F", DRIVE_TS1160, "[0359260F]"), /* IBM TS1160 */ + TAPEDRIVE(IBM_VENDOR_ID, "0359260E", DRIVE_TS1160, "[0359260E]"), /* IBM TS1160 */ + TAPEDRIVE(IBM_VENDOR_ID, "0359260S", DRIVE_TS1160, "[0359260S]"), /* IBM TS1160 */ + TAPEDRIVE(IBM_VENDOR_ID, "0359270F", DRIVE_TS1170, "[0359270F]"), /* IBM TS1170 */ + TAPEDRIVE(IBM_VENDOR_ID, "0359270S", DRIVE_TS1170, "[0359270S]"), /* IBM TS1170 */ + /* End of supported_devices */ + NULL }; struct supported_device *usb_supported_drives[] = { - TAPEDRIVE( IBM_VENDOR_ID, "ULT3580-TD5", DRIVE_LTO5, "[ULT3580-TD5]" ), /* IBM Ultrium Gen 5 */ - TAPEDRIVE( IBM_VENDOR_ID, "ULTRIUM-HH5", DRIVE_LTO5_HH, "[ULTRIUM-HH5]" ), /* IBM Ultrium Gen 5 Half-High */ - TAPEDRIVE( IBM_VENDOR_ID, "ULT3580-HH5", DRIVE_LTO5_HH, "[ULT3580-HH5]" ), /* IBM Ultrium Gen 5 Half-High */ - TAPEDRIVE( IBM_VENDOR_ID, "ULT3580-TD6", DRIVE_LTO6, "[ULT3580-TD6]" ), /* IBM Ultrium Gen 6 */ - TAPEDRIVE( IBM_VENDOR_ID, "ULTRIUM-HH6", DRIVE_LTO6_HH, "[ULTRIUM-HH6]" ), /* IBM Ultrium Gen 6 Half-High */ - TAPEDRIVE( IBM_VENDOR_ID, "ULT3580-HH6", DRIVE_LTO6_HH, "[ULT3580-HH6]" ), /* IBM Ultrium Gen 6 Half-High */ - TAPEDRIVE( IBM_VENDOR_ID, "ULT3580-TD7", DRIVE_LTO7, "[ULT3580-TD7]" ), /* IBM Ultrium Gen 7 */ - TAPEDRIVE( IBM_VENDOR_ID, "ULTRIUM-HH7", DRIVE_LTO7_HH, "[ULTRIUM-HH7]" ), /* IBM Ultrium Gen 7 Half-High */ - TAPEDRIVE( IBM_VENDOR_ID, "ULT3580-HH7", DRIVE_LTO7_HH, "[ULT3580-HH7]" ), /* IBM Ultrium Gen 7 Half-High */ - TAPEDRIVE( IBM_VENDOR_ID, "ULT3580-TD8", DRIVE_LTO8, "[ULT3580-TD8]" ), /* IBM Ultrium Gen 8 */ - TAPEDRIVE( IBM_VENDOR_ID, "ULTRIUM-HH8", DRIVE_LTO8_HH, "[ULTRIUM-HH8]" ), /* IBM Ultrium Gen 8 Half-High */ - TAPEDRIVE( IBM_VENDOR_ID, "ULT3580-HH8", DRIVE_LTO8_HH, "[ULT3580-HH8]" ), /* IBM Ultrium Gen 8 Half-High */ - TAPEDRIVE( IBM_VENDOR_ID, "ULT3580-TD9", DRIVE_LTO9, "[ULT3580-TD9]" ), /* IBM Ultrium Gen 9 */ - TAPEDRIVE( IBM_VENDOR_ID, "ULTRIUM-HH9", DRIVE_LTO9_HH, "[ULTRIUM-HH9]" ), /* IBM Ultrium Gen 9 Half-High */ - TAPEDRIVE( IBM_VENDOR_ID, "ULT3580-HH9", DRIVE_LTO9_HH, "[ULT3580-HH9]" ), /* IBM Ultrium Gen 9 Half-High */ - TAPEDRIVE( IBM_VENDOR_ID, "ULT3580-TDA", DRIVE_LTO10, "[ULT3580-TDA]"), /* IBM Ultrium Gen A */ - TAPEDRIVE( IBM_VENDOR_ID, "ULTRIUM-HHA", DRIVE_LTO10_HH,"[ULTRIUM-HHA]" ), /* IBM Ultrium Gen A */ - TAPEDRIVE( IBM_VENDOR_ID, "ULT3580-HHA", DRIVE_LTO10_HH,"[ULT3580-HHA]" ), /* IBM Ultrium Gen A Half-High */ - /* End of supported_devices */ - NULL + TAPEDRIVE(IBM_VENDOR_ID, "ULT3580-TD5", DRIVE_LTO5, "[ULT3580-TD5]"), /* IBM Ultrium Gen 5 */ + TAPEDRIVE(IBM_VENDOR_ID, "ULTRIUM-HH5", DRIVE_LTO5_HH, "[ULTRIUM-HH5]"), /* IBM Ultrium Gen 5 Half-High */ + TAPEDRIVE(IBM_VENDOR_ID, "ULT3580-HH5", DRIVE_LTO5_HH, "[ULT3580-HH5]"), /* IBM Ultrium Gen 5 Half-High */ + TAPEDRIVE(IBM_VENDOR_ID, "ULT3580-TD6", DRIVE_LTO6, "[ULT3580-TD6]"), /* IBM Ultrium Gen 6 */ + TAPEDRIVE(IBM_VENDOR_ID, "ULTRIUM-HH6", DRIVE_LTO6_HH, "[ULTRIUM-HH6]"), /* IBM Ultrium Gen 6 Half-High */ + TAPEDRIVE(IBM_VENDOR_ID, "ULT3580-HH6", DRIVE_LTO6_HH, "[ULT3580-HH6]"), /* IBM Ultrium Gen 6 Half-High */ + TAPEDRIVE(IBM_VENDOR_ID, "ULT3580-TD7", DRIVE_LTO7, "[ULT3580-TD7]"), /* IBM Ultrium Gen 7 */ + TAPEDRIVE(IBM_VENDOR_ID, "ULTRIUM-HH7", DRIVE_LTO7_HH, "[ULTRIUM-HH7]"), /* IBM Ultrium Gen 7 Half-High */ + TAPEDRIVE(IBM_VENDOR_ID, "ULT3580-HH7", DRIVE_LTO7_HH, "[ULT3580-HH7]"), /* IBM Ultrium Gen 7 Half-High */ + TAPEDRIVE(IBM_VENDOR_ID, "ULT3580-TD8", DRIVE_LTO8, "[ULT3580-TD8]"), /* IBM Ultrium Gen 8 */ + TAPEDRIVE(IBM_VENDOR_ID, "ULTRIUM-HH8", DRIVE_LTO8_HH, "[ULTRIUM-HH8]"), /* IBM Ultrium Gen 8 Half-High */ + TAPEDRIVE(IBM_VENDOR_ID, "ULT3580-HH8", DRIVE_LTO8_HH, "[ULT3580-HH8]"), /* IBM Ultrium Gen 8 Half-High */ + TAPEDRIVE(IBM_VENDOR_ID, "ULT3580-TD9", DRIVE_LTO9, "[ULT3580-TD9]"), /* IBM Ultrium Gen 9 */ + TAPEDRIVE(IBM_VENDOR_ID, "ULTRIUM-HH9", DRIVE_LTO9_HH, "[ULTRIUM-HH9]"), /* IBM Ultrium Gen 9 Half-High */ + TAPEDRIVE(IBM_VENDOR_ID, "ULT3580-HH9", DRIVE_LTO9_HH, "[ULT3580-HH9]"), /* IBM Ultrium Gen 9 Half-High */ + TAPEDRIVE(IBM_VENDOR_ID, "ULT3580-TDA", DRIVE_LTO10, "[ULT3580-TDA]"), /* IBM Ultrium Gen A */ + TAPEDRIVE(IBM_VENDOR_ID, "ULTRIUM-HHA", DRIVE_LTO10_HH, "[ULTRIUM-HHA]"), /* IBM Ultrium Gen A */ + TAPEDRIVE(IBM_VENDOR_ID, "ULT3580-HHA", DRIVE_LTO10_HH, "[ULT3580-HHA]"), /* IBM Ultrium Gen A Half-High */ + /* End of supported_devices */ + NULL }; /* IBM LTO tape drive vendor unique sense table */ struct error_table ibm_tape_errors[] = { /* Sense Key 0 (No Sense) */ - {0x008282, -EDEV_CLEANING_REQUIRED, "IBM LTO - Cleaning Required"}, + { 0x008282, -EDEV_CLEANING_REQUIRED, "IBM LTO - Cleaning Required" }, /* Sense Key 1 (Recoverd Error) */ - {0x018252, -EDEV_DEGRADED_MEDIA, "IBM LTO - Degraded Media"}, - {0x018383, -EDEV_RECOVERED_ERROR, "Drive Has Been Cleaned"}, - {0x018500, -EDEV_RECOVERED_ERROR, "Search Match List Limit (warning)"}, - {0x018501, -EDEV_RECOVERED_ERROR, "Search Snoop Match Found"}, + { 0x018252, -EDEV_DEGRADED_MEDIA, "IBM LTO - Degraded Media" }, + { 0x018383, -EDEV_RECOVERED_ERROR, "Drive Has Been Cleaned" }, + { 0x018500, -EDEV_RECOVERED_ERROR, "Search Match List Limit (warning)" }, + { 0x018501, -EDEV_RECOVERED_ERROR, "Search Snoop Match Found" }, /* Sense Key 3 (Medium Error) */ - {0x038500, -EDEV_DATA_PROTECT, "Write Protected Because of Tape or Drive Failure"}, - {0x038501, -EDEV_DATA_PROTECT, "Write Protected Because of Tape Failure"}, - {0x038502, -EDEV_DATA_PROTECT, "Write Protected Because of Drive Failure"}, + { 0x038500, -EDEV_DATA_PROTECT, "Write Protected Because of Tape or Drive Failure" }, + { 0x038501, -EDEV_DATA_PROTECT, "Write Protected Because of Tape Failure" }, + { 0x038502, -EDEV_DATA_PROTECT, "Write Protected Because of Drive Failure" }, /* Sense Key 5 (Illegal Request) */ - {0x058000, -EDEV_ILLEGAL_REQUEST, "CU Mode, Vendor-Unique"}, - {0x058283, -EDEV_ILLEGAL_REQUEST, "Bad Microcode Detected"}, - {0x058503, -EDEV_ILLEGAL_REQUEST, "Write Protected Because of Current Tape Position"}, - {0x05A301, -EDEV_ILLEGAL_REQUEST, "OEM Vendor-Specific"}, + { 0x058000, -EDEV_ILLEGAL_REQUEST, "CU Mode, Vendor-Unique" }, + { 0x058283, -EDEV_ILLEGAL_REQUEST, "Bad Microcode Detected" }, + { 0x058503, -EDEV_ILLEGAL_REQUEST, "Write Protected Because of Current Tape Position" }, + { 0x05A301, -EDEV_ILLEGAL_REQUEST, "OEM Vendor-Specific" }, /* Sense Key 6 (Unit Attention) */ - {0x065DFF, -EDEV_UNIT_ATTENTION, "Failure Prediction False"}, - {0x068283, -EDEV_UNIT_ATTENTION, "Drive Has Been Cleaned (older versions of microcode)"}, - {0x068500, -EDEV_UNIT_ATTENTION, "Search Match List Limit (alert)"}, + { 0x065DFF, -EDEV_UNIT_ATTENTION, "Failure Prediction False" }, + { 0x068283, -EDEV_UNIT_ATTENTION, "Drive Has Been Cleaned (older versions of microcode)" }, + { 0x068500, -EDEV_UNIT_ATTENTION, "Search Match List Limit (alert)" }, /* Crypto Related Sense Code */ - {0x00EF13, -EDEV_CRYPTO_ERROR, "Encryption - Key Translate"}, - {0x03EE60, -EDEV_CRYPTO_ERROR, "Encryption - Proxy Command Error"}, - {0x03EED0, -EDEV_CRYPTO_ERROR, "Encryption - Data Read Decryption Failure"}, - {0x03EED1, -EDEV_CRYPTO_ERROR, "Encryption - Data Read after Write Decryption Failure"}, - {0x03EEE0, -EDEV_CRYPTO_ERROR, "Encryption - Key Translation Failure"}, - {0x03EEE1, -EDEV_CRYPTO_ERROR, "Encryption - Key Translation Ambiguous"}, - {0x03EEF0, -EDEV_CRYPTO_ERROR, "Encryption - Decryption Fenced (Read)"}, - {0x03EEF1, -EDEV_CRYPTO_ERROR, "Encryption - Encryption Fenced (Write)"}, - {0x044780, -EDEV_HARDWARE_ERROR, "IBM LTO - Read Internal CRC Error"}, - {0x044781, -EDEV_HARDWARE_ERROR, "IBM LTO - Write Internal CRC Error"}, - {0x04EE0E, -EDEV_KEY_SERVICE_ERROR, "Encryption - Key Service Timeout"}, /* LTO5, Jag4 and earlier */ - {0x04EE0F, -EDEV_KEY_SERVICE_ERROR, "Encryption - Key Service Failure"}, /* LTO5, Jag4 and earlier */ - {0x05EE00, -EDEV_CRYPTO_ERROR, "Encryption - Key Service Not Enabled"}, - {0x05EE01, -EDEV_CRYPTO_ERROR, "Encryption - Key Service Not Configured"}, - {0x05EE02, -EDEV_CRYPTO_ERROR, "Encryption - Key Service Not Available"}, - {0x05EE0D, -EDEV_CRYPTO_ERROR, "Encryption - Message Content Error"}, - {0x05EE10, -EDEV_CRYPTO_ERROR, "Encryption - Key Required"}, - {0x05EE20, -EDEV_CRYPTO_ERROR, "Encryption - Key Count Exceeded"}, - {0x05EE21, -EDEV_CRYPTO_ERROR, "Encryption - Key Alias Exceeded"}, - {0x05EE22, -EDEV_CRYPTO_ERROR, "Encryption - Key Reserved"}, - {0x05EE23, -EDEV_CRYPTO_ERROR, "Encryption - Key Conflict"}, - {0x05EE24, -EDEV_CRYPTO_ERROR, "Encryption - Key Method Change"}, - {0x05EE25, -EDEV_CRYPTO_ERROR, "Encryption - Key Format Not Supported"}, - {0x05EE26, -EDEV_CRYPTO_ERROR, "Encryption - Unauthorized Request - dAK"}, - {0x05EE27, -EDEV_CRYPTO_ERROR, "Encryption - Unauthorized Request - dSK"}, - {0x05EE28, -EDEV_CRYPTO_ERROR, "Encryption - Unauthorized Request - eAK"}, - {0x05EE29, -EDEV_CRYPTO_ERROR, "Encryption - Authentication Failure"}, - {0x05EE2A, -EDEV_CRYPTO_ERROR, "Encryption - Invalid RDKi"}, - {0x05EE2B, -EDEV_CRYPTO_ERROR, "Encryption - Key Incorrect"}, - {0x05EE2C, -EDEV_CRYPTO_ERROR, "Encryption - Key Wrapping Failure"}, - {0x05EE2D, -EDEV_CRYPTO_ERROR, "Encryption - Sequencing Failure"}, - {0x05EE2E, -EDEV_CRYPTO_ERROR, "Encryption - Unsupported Type"}, - {0x05EE2F, -EDEV_CRYPTO_ERROR, "Encryption - New Key Encrypted Write Pending"}, - {0x05EE30, -EDEV_CRYPTO_ERROR, "Encryption - Prohibited Request"}, - {0x05EE31, -EDEV_CRYPTO_ERROR, "Encryption - Key Unknown"}, - {0x05EE32, -EDEV_CRYPTO_ERROR, "Encryption - Unauthorized Request - dCERT"}, - {0x05EE42, -EDEV_CRYPTO_ERROR, "Encryption - EKM Challenge Pending"}, - {0x05EEE2, -EDEV_CRYPTO_ERROR, "Encryption - Key Translation Disallowed"}, - {0x05EEFF, -EDEV_CRYPTO_ERROR, "Encryption - Security Prohibited Function"}, - {0x05EF01, -EDEV_CRYPTO_ERROR, "Encryption - Key Service Not Configured"}, - {0x06EE11, -EDEV_CRYPTO_ERROR, "Encryption - Key Generation"}, - {0x06EE12, -EDEV_KEY_CHANGE_DETECTED, "Encryption - Key Change Detected"}, - {0x06EE13, -EDEV_CRYPTO_ERROR, "Encryption - Key Translation"}, - {0x06EE18, -EDEV_KEY_CHANGE_DETECTED, "Encryption - Changed (Read)"}, - {0x06EE19, -EDEV_KEY_CHANGE_DETECTED, "Encryption - Changed (Write)"}, - {0x06EE40, -EDEV_CRYPTO_ERROR, "Encryption - EKM Identifier Changed"}, - {0x06EE41, -EDEV_CRYPTO_ERROR, "Encryption - EKM Challenge Changed"}, - {0x06EE50, -EDEV_CRYPTO_ERROR, "Encryption - Initiator Identifier Changed"}, - {0x06EE51, -EDEV_CRYPTO_ERROR, "Encryption - Initiator Response Changed"}, - {0x06EF01, -EDEV_CRYPTO_ERROR, "Encryption - Key Service Not Configured"}, - {0x06EF10, -EDEV_CRYPTO_ERROR, "Encryption - Key Required"}, - {0x06EF11, -EDEV_CRYPTO_ERROR, "Encryption - Key Generation"}, - {0x06EF13, -EDEV_CRYPTO_ERROR, "Encryption - Key Translation"}, - {0x06EF1A, -EDEV_CRYPTO_ERROR, "Encryption - Key Optional (i.e., chose encryption enabled/disabled)"}, - {0x07EE0E, -EDEV_KEY_SERVICE_ERROR, "Encryption - Key Service Timeout"}, /* LTO6, Jag5 and later */ - {0x07EE0F, -EDEV_KEY_SERVICE_ERROR, "Encryption - Key Service Failure"}, /* LTO6, Jag5 and later */ - {0x07EF10, -EDEV_KEY_REQUIRED, "Encryption - Key Required"}, - {0x07EF11, -EDEV_CRYPTO_ERROR, "Encryption - Key Generation"}, - {0x07EF13, -EDEV_CRYPTO_ERROR, "Encryption - Key Translate"}, - {0x07EF1A, -EDEV_CRYPTO_ERROR, "Encryption - Key Optional"}, - {0x07EF31, -EDEV_CRYPTO_ERROR, "Encryption - Key Unknown"}, - {0x07EFC0, -EDEV_CRYPTO_ERROR, "Encryption - No Operation"}, + { 0x00EF13, -EDEV_CRYPTO_ERROR, "Encryption - Key Translate" }, + { 0x03EE60, -EDEV_CRYPTO_ERROR, "Encryption - Proxy Command Error" }, + { 0x03EED0, -EDEV_CRYPTO_ERROR, "Encryption - Data Read Decryption Failure" }, + { 0x03EED1, -EDEV_CRYPTO_ERROR, "Encryption - Data Read after Write Decryption Failure" }, + { 0x03EEE0, -EDEV_CRYPTO_ERROR, "Encryption - Key Translation Failure" }, + { 0x03EEE1, -EDEV_CRYPTO_ERROR, "Encryption - Key Translation Ambiguous" }, + { 0x03EEF0, -EDEV_CRYPTO_ERROR, "Encryption - Decryption Fenced (Read)" }, + { 0x03EEF1, -EDEV_CRYPTO_ERROR, "Encryption - Encryption Fenced (Write)" }, + { 0x044780, -EDEV_HARDWARE_ERROR, "IBM LTO - Read Internal CRC Error" }, + { 0x044781, -EDEV_HARDWARE_ERROR, "IBM LTO - Write Internal CRC Error" }, + { 0x04EE0E, -EDEV_KEY_SERVICE_ERROR, "Encryption - Key Service Timeout" }, /* LTO5, Jag4 and earlier */ + { 0x04EE0F, -EDEV_KEY_SERVICE_ERROR, "Encryption - Key Service Failure" }, /* LTO5, Jag4 and earlier */ + { 0x05EE00, -EDEV_CRYPTO_ERROR, "Encryption - Key Service Not Enabled" }, + { 0x05EE01, -EDEV_CRYPTO_ERROR, "Encryption - Key Service Not Configured" }, + { 0x05EE02, -EDEV_CRYPTO_ERROR, "Encryption - Key Service Not Available" }, + { 0x05EE0D, -EDEV_CRYPTO_ERROR, "Encryption - Message Content Error" }, + { 0x05EE10, -EDEV_CRYPTO_ERROR, "Encryption - Key Required" }, + { 0x05EE20, -EDEV_CRYPTO_ERROR, "Encryption - Key Count Exceeded" }, + { 0x05EE21, -EDEV_CRYPTO_ERROR, "Encryption - Key Alias Exceeded" }, + { 0x05EE22, -EDEV_CRYPTO_ERROR, "Encryption - Key Reserved" }, + { 0x05EE23, -EDEV_CRYPTO_ERROR, "Encryption - Key Conflict" }, + { 0x05EE24, -EDEV_CRYPTO_ERROR, "Encryption - Key Method Change" }, + { 0x05EE25, -EDEV_CRYPTO_ERROR, "Encryption - Key Format Not Supported" }, + { 0x05EE26, -EDEV_CRYPTO_ERROR, "Encryption - Unauthorized Request - dAK" }, + { 0x05EE27, -EDEV_CRYPTO_ERROR, "Encryption - Unauthorized Request - dSK" }, + { 0x05EE28, -EDEV_CRYPTO_ERROR, "Encryption - Unauthorized Request - eAK" }, + { 0x05EE29, -EDEV_CRYPTO_ERROR, "Encryption - Authentication Failure" }, + { 0x05EE2A, -EDEV_CRYPTO_ERROR, "Encryption - Invalid RDKi" }, + { 0x05EE2B, -EDEV_CRYPTO_ERROR, "Encryption - Key Incorrect" }, + { 0x05EE2C, -EDEV_CRYPTO_ERROR, "Encryption - Key Wrapping Failure" }, + { 0x05EE2D, -EDEV_CRYPTO_ERROR, "Encryption - Sequencing Failure" }, + { 0x05EE2E, -EDEV_CRYPTO_ERROR, "Encryption - Unsupported Type" }, + { 0x05EE2F, -EDEV_CRYPTO_ERROR, "Encryption - New Key Encrypted Write Pending" }, + { 0x05EE30, -EDEV_CRYPTO_ERROR, "Encryption - Prohibited Request" }, + { 0x05EE31, -EDEV_CRYPTO_ERROR, "Encryption - Key Unknown" }, + { 0x05EE32, -EDEV_CRYPTO_ERROR, "Encryption - Unauthorized Request - dCERT" }, + { 0x05EE42, -EDEV_CRYPTO_ERROR, "Encryption - EKM Challenge Pending" }, + { 0x05EEE2, -EDEV_CRYPTO_ERROR, "Encryption - Key Translation Disallowed" }, + { 0x05EEFF, -EDEV_CRYPTO_ERROR, "Encryption - Security Prohibited Function" }, + { 0x05EF01, -EDEV_CRYPTO_ERROR, "Encryption - Key Service Not Configured" }, + { 0x06EE11, -EDEV_CRYPTO_ERROR, "Encryption - Key Generation" }, + { 0x06EE12, -EDEV_KEY_CHANGE_DETECTED, "Encryption - Key Change Detected" }, + { 0x06EE13, -EDEV_CRYPTO_ERROR, "Encryption - Key Translation" }, + { 0x06EE18, -EDEV_KEY_CHANGE_DETECTED, "Encryption - Changed (Read)" }, + { 0x06EE19, -EDEV_KEY_CHANGE_DETECTED, "Encryption - Changed (Write)" }, + { 0x06EE40, -EDEV_CRYPTO_ERROR, "Encryption - EKM Identifier Changed" }, + { 0x06EE41, -EDEV_CRYPTO_ERROR, "Encryption - EKM Challenge Changed" }, + { 0x06EE50, -EDEV_CRYPTO_ERROR, "Encryption - Initiator Identifier Changed" }, + { 0x06EE51, -EDEV_CRYPTO_ERROR, "Encryption - Initiator Response Changed" }, + { 0x06EF01, -EDEV_CRYPTO_ERROR, "Encryption - Key Service Not Configured" }, + { 0x06EF10, -EDEV_CRYPTO_ERROR, "Encryption - Key Required" }, + { 0x06EF11, -EDEV_CRYPTO_ERROR, "Encryption - Key Generation" }, + { 0x06EF13, -EDEV_CRYPTO_ERROR, "Encryption - Key Translation" }, + { 0x06EF1A, -EDEV_CRYPTO_ERROR, "Encryption - Key Optional (i.e., chose encryption enabled/disabled)" }, + { 0x07EE0E, -EDEV_KEY_SERVICE_ERROR, "Encryption - Key Service Timeout" }, /* LTO6, Jag5 and later */ + { 0x07EE0F, -EDEV_KEY_SERVICE_ERROR, "Encryption - Key Service Failure" }, /* LTO6, Jag5 and later */ + { 0x07EF10, -EDEV_KEY_REQUIRED, "Encryption - Key Required" }, + { 0x07EF11, -EDEV_CRYPTO_ERROR, "Encryption - Key Generation" }, + { 0x07EF13, -EDEV_CRYPTO_ERROR, "Encryption - Key Translate" }, + { 0x07EF1A, -EDEV_CRYPTO_ERROR, "Encryption - Key Optional" }, + { 0x07EF31, -EDEV_CRYPTO_ERROR, "Encryption - Key Unknown" }, + { 0x07EFC0, -EDEV_CRYPTO_ERROR, "Encryption - No Operation" }, /* END MARK*/ - {0xFFFFFF, -EDEV_UNKNOWN, "Unknown Error code"}, + { 0xFFFFFF, -EDEV_UNKNOWN, "Unknown Error code" }, }; /* TODO: Choose best HASH functions defined into UThash ! */ //#undef HASH_FCN //#define HASH_FCN HASH_BER -struct _timeout_tape{ - int op_code; /**< SCSI op code */ - int timeout; /**< SCSI timeout */ +struct _timeout_tape +{ + int op_code; /**< SCSI op code */ + int timeout; /**< SCSI timeout */ }; /* Base timeout value for LTO */ -static struct _timeout_tape timeout_lto[] = { - { CHANGE_DEFINITION, -1 }, - { XCOPY, -1 }, - { INQUIRY, 60 }, - { LOG_SELECT, 60 }, - { LOG_SENSE, 60 }, - { MODE_SELECT6, 60 }, - { MODE_SELECT10, 60 }, - { MODE_SENSE6, 60 }, - { MODE_SENSE10, 60 }, - { PERSISTENT_RESERVE_IN, 60 }, - { PERSISTENT_RESERVE_OUT, 60 }, - { READ_ATTRIBUTE, 60 }, - { RECEIVE_DIAGNOSTIC_RESULTS, 60 }, - { RELEASE_UNIT6, 60 }, - { RELEASE_UNIT10, 60 }, - { REPORT_LUNS, 60 }, - { REQUEST_SENSE, 60 }, - { RESERVE_UNIT6, 60 }, - { RESERVE_UNIT10, 60 }, - { SPIN, 60 }, - { SPOUT, 60 }, - { TEST_UNIT_READY, 60 }, - { WRITE_ATTRIBUTE, 60 }, - { ALLOW_OVERWRITE, 60 }, - { DISPLAY_MESSAGE, -1 }, - { PREVENT_ALLOW_MEDIUM_REMOVAL, 60 }, - { READ_BLOCK_LIMITS, 60 }, - { READ_DYNAMIC_RUNTIME_ATTRIBUTE, 60 }, - { READ_POSITION, 60 }, - { READ_REVERSE, -1 }, - { RECOVER_BUFFERED_DATA, -1 }, - { REPORT_DENSITY_SUPPORT, 60 }, - { STRING_SEARCH, -1 }, - { WRITE_DYNAMIC_RUNTIME_ATTRIBUTE, 60 }, - {-1, -1} -}; - -static struct _timeout_tape timeout_lto5[] = { - { ERASE, 16380 }, - { FORMAT_MEDIUM, 1560 }, - { LOAD_UNLOAD, 780 }, - { LOCATE10, 2040 }, - { LOCATE16, 2040 }, - { READ, 1500 }, - { READ_BUFFER, 480 }, - { REWIND, 600 }, - { SEND_DIAGNOSTIC, 2100 }, - { SET_CAPACITY, 780 }, - { SPACE6, 2040 }, - { SPACE16, 2040 }, - { VERIFY, 16920 }, - { WRITE, 1500 }, - { WRITE_BUFFER, 540 }, - { WRITE_FILEMARKS6, 1620 }, - {-1, -1} -}; - -static struct _timeout_tape timeout_lto6[] = { - { ERASE, 24600 }, - { FORMAT_MEDIUM, 3000 }, - { LOAD_UNLOAD, 780 }, - { LOCATE10, 2940 }, - { LOCATE16, 2940 }, - { READ, 1500 }, - { READ_BUFFER, 480 }, - { REWIND, 600 }, - { SEND_DIAGNOSTIC, 2100 }, - { SET_CAPACITY, 780 }, - { SPACE6, 2040 }, - { SPACE16, 2040 }, - { VERIFY, 25200 }, - { WRITE, 1500 }, - { WRITE_BUFFER, 540 }, - { WRITE_FILEMARKS6, 1620 }, - {-1, -1} -}; - -static struct _timeout_tape timeout_lto7[] = { - { ERASE, 27540 }, - { FORMAT_MEDIUM, 3000 }, - { LOAD_UNLOAD, 960 }, - { LOCATE10, 2880 }, - { LOCATE16, 2880 }, - { READ, 2280 }, - { READ_BUFFER, 480 }, - { REWIND, 600 }, - { SEND_DIAGNOSTIC, 1980 }, - { SET_CAPACITY, 780 }, - { SPACE6, 2880 }, - { SPACE16, 2880 }, - { VERIFY, 28860 }, - { WRITE, 1500 }, - { WRITE_BUFFER, 540 }, - { WRITE_FILEMARKS6, 1620 }, - {-1, -1} -}; - -static struct _timeout_tape timeout_lto8[] = { - { ERASE, 54896 }, - { FORMAT_MEDIUM, 3000 }, - { LOAD_UNLOAD, 960 }, - { LOCATE10, 2880 }, - { LOCATE16, 2880 }, - { READ, 2280 }, - { READ_BUFFER, 480 }, - { REWIND, 600 }, - { SEND_DIAGNOSTIC, 1980 }, - { SET_CAPACITY, 780 }, - { SPACE6, 2880 }, - { SPACE16, 2880 }, - { VERIFY, 47700 }, - { WRITE, 1500 }, - { WRITE_BUFFER, 540 }, - { WRITE_FILEMARKS6, 1620 }, - {-1, -1} -}; - -static struct _timeout_tape timeout_lto9[] = { - { ERASE, 74341 }, - { FORMAT_MEDIUM, 3000 }, - { LOAD_UNLOAD, 960 }, - { LOCATE10, 2940 }, - { LOCATE16, 2940 }, - { READ, 2340 }, - { READ_BUFFER, 480 }, - { REWIND, 600 }, - { SEND_DIAGNOSTIC, 1980 }, - { SET_CAPACITY, 780 }, - { SPACE6, 2940 }, - { SPACE16, 2940 }, - { VERIFY, 63300 }, - { WRITE, 1500 }, - { WRITE_BUFFER, 540 }, - { WRITE_FILEMARKS6, 1620 }, - {-1, -1} -}; - -static struct _timeout_tape timeout_lto10[] = { - { ERASE, 16320 }, - { FORMAT_MEDIUM, 3180 }, - { LOAD_UNLOAD, 780 }, - { LOCATE10, 2940 }, - { LOCATE16, 2940 }, - { READ, 2340 }, - { READ_BUFFER, 480 }, - { REWIND, 600 }, - { SEND_DIAGNOSTIC, 1980 }, - { SET_CAPACITY, 780 }, - { SPACE6, 2940 }, - { SPACE16, 2940 }, - { VERIFY, 104880 }, - { WRITE, 1500 }, - { WRITE_BUFFER, 540 }, - { WRITE_FILEMARKS6, 1620 }, - {-1, -1} -}; - -static struct _timeout_tape timeout_lto5_hh[] = { - { ERASE, 19200 }, - { FORMAT_MEDIUM, 1980 }, - { LOAD_UNLOAD, 1020 }, - { LOCATE10, 2700 }, - { LOCATE16, 2700 }, - { READ, 1920 }, - { READ_BUFFER, 660 }, - { REWIND, 780 }, - { SEND_DIAGNOSTIC, 3120 }, - { SET_CAPACITY, 960 }, - { SPACE6, 2700 }, - { SPACE16, 2700 }, - { VERIFY, 19980 }, - { WRITE, 1920 }, - { WRITE_BUFFER, 720 }, - { WRITE_FILEMARKS6, 1740 }, - {-1, -1} -}; - -static struct _timeout_tape timeout_lto6_hh[] = { - { ERASE, 29400 }, - { FORMAT_MEDIUM, 3840 }, - { LOAD_UNLOAD, 1020 }, - { LOCATE10, 2700 }, - { LOCATE16, 2700 }, - { READ, 1920 }, - { READ_BUFFER, 660 }, - { REWIND, 780 }, - { SEND_DIAGNOSTIC, 3120 }, - { SET_CAPACITY, 960 }, - { SPACE6, 2700 }, - { SPACE16, 2700 }, - { VERIFY, 30000 }, - { WRITE, 1920 }, - { WRITE_BUFFER, 720 }, - { WRITE_FILEMARKS6, 1740 }, - {-1, -1} -}; - -static struct _timeout_tape timeout_lto7_hh[] = { - { ERASE, 27540 }, - { FORMAT_MEDIUM, 3240 }, - { LOAD_UNLOAD, 960 }, - { LOCATE10, 2940 }, - { LOCATE16, 2940 }, - { READ, 2340 }, - { READ_BUFFER, 480 }, - { REWIND, 600 }, - { SEND_DIAGNOSTIC, 2040 }, - { SET_CAPACITY, 960 }, - { SPACE6, 2940 }, - { SPACE16, 2940 }, - { VERIFY, 28860 }, - { WRITE, 1560 }, - { WRITE_BUFFER, 540 }, - { WRITE_FILEMARKS6, 1680 }, - {-1, -1} -}; - -static struct _timeout_tape timeout_lto8_hh[] = { - { ERASE, 121448 }, - { FORMAT_MEDIUM, 3240 }, - { LOAD_UNLOAD, 960 }, - { LOCATE10, 2940 }, - { LOCATE16, 2940 }, - { READ, 2340 }, - { READ_BUFFER, 480 }, - { REWIND, 600 }, - { SEND_DIAGNOSTIC, 2040 }, - { SET_CAPACITY, 960 }, - { SPACE6, 2940 }, - { SPACE16, 2940 }, - { VERIFY, 54360 }, - { WRITE, 1560 }, - { WRITE_BUFFER, 540 }, - { WRITE_FILEMARKS6, 1680 }, - {-1, -1} -}; - -static struct _timeout_tape timeout_lto9_hh[] = { - { ERASE, 166370 }, - { FORMAT_MEDIUM, 3240 }, - { LOAD_UNLOAD, 960 }, - { LOCATE10, 2940 }, - { LOCATE16, 2940 }, - { READ, 2340 }, - { READ_BUFFER, 480 }, - { REWIND, 600 }, - { SEND_DIAGNOSTIC, 2040 }, - { SET_CAPACITY, 960 }, - { SPACE6, 2940 }, - { SPACE16, 2940 }, - { VERIFY, 63300 }, - { WRITE, 1560 }, - { WRITE_BUFFER, 540 }, - { WRITE_FILEMARKS6, 1680 }, - {-1, -1} -}; - -static struct _timeout_tape timeout_lto10_hh[] = { - { ERASE, 166370 }, - { FORMAT_MEDIUM, 3240 }, - { LOAD_UNLOAD, 960 }, - { LOCATE10, 3940 }, - { LOCATE16, 3940 }, - { READ, 2340 }, - { READ_BUFFER, 480 }, - { REWIND, 600 }, - { SEND_DIAGNOSTIC, 2040 }, - { SET_CAPACITY, 960 }, - { SPACE6, 3940 }, - { SPACE16, 3940 }, - { VERIFY, 63300 }, - { WRITE, 1560 }, - { WRITE_BUFFER, 540 }, - { WRITE_FILEMARKS6, 1680 }, - {-1, -1} -}; - -static struct _timeout_tape timeout_11x0[] = { - { CHANGE_DEFINITION, 30 }, - { INQUIRY, 30 }, - { LOG_SELECT, 30 }, - { LOG_SENSE, 30 }, - { MODE_SELECT6, 300 }, /* For scale change */ - { MODE_SELECT10, 300 }, /* For scale change */ - { MODE_SENSE6, 30 }, - { MODE_SENSE10, 30 }, - { PERSISTENT_RESERVE_IN, 30 }, - { PERSISTENT_RESERVE_OUT, 900 }, - { READ_ATTRIBUTE, 30 }, - { RECEIVE_DIAGNOSTIC_RESULTS, 60 }, - { RELEASE_UNIT6, 60 }, - { RELEASE_UNIT10, 60 }, - { REPORT_LUNS, 60 }, - { REQUEST_SENSE, 60 }, - { RESERVE_UNIT6, 60 }, - { RESERVE_UNIT10, 60 }, - { SPIN, 300 }, - { SPOUT, 300 }, - { TEST_UNIT_READY, 30 }, - { WRITE_ATTRIBUTE, 30 }, - { ALLOW_OVERWRITE, 30 }, - { DISPLAY_MESSAGE, 30 }, - { PREVENT_ALLOW_MEDIUM_REMOVAL, 30 }, - { READ_BLOCK_LIMITS, 30 }, - { READ_DYNAMIC_RUNTIME_ATTRIBUTE, 30 }, - { READ_POSITION, 30 }, - { READ_REVERSE, 1080 }, - { RECOVER_BUFFERED_DATA, 60 }, - { REPORT_DENSITY_SUPPORT, 30 }, - { SET_CAPACITY, -1 }, - { STRING_SEARCH, -1 }, - { WRITE_DYNAMIC_RUNTIME_ATTRIBUTE, 30 }, - {-1, -1} -}; +static struct _timeout_tape timeout_lto[] = { { CHANGE_DEFINITION, -1 }, + { XCOPY, -1 }, + { INQUIRY, 60 }, + { LOG_SELECT, 60 }, + { LOG_SENSE, 60 }, + { MODE_SELECT6, 60 }, + { MODE_SELECT10, 60 }, + { MODE_SENSE6, 60 }, + { MODE_SENSE10, 60 }, + { PERSISTENT_RESERVE_IN, 60 }, + { PERSISTENT_RESERVE_OUT, 60 }, + { READ_ATTRIBUTE, 60 }, + { RECEIVE_DIAGNOSTIC_RESULTS, 60 }, + { RELEASE_UNIT6, 60 }, + { RELEASE_UNIT10, 60 }, + { REPORT_LUNS, 60 }, + { REQUEST_SENSE, 60 }, + { RESERVE_UNIT6, 60 }, + { RESERVE_UNIT10, 60 }, + { SPIN, 60 }, + { SPOUT, 60 }, + { TEST_UNIT_READY, 60 }, + { WRITE_ATTRIBUTE, 60 }, + { ALLOW_OVERWRITE, 60 }, + { DISPLAY_MESSAGE, -1 }, + { PREVENT_ALLOW_MEDIUM_REMOVAL, 60 }, + { READ_BLOCK_LIMITS, 60 }, + { READ_DYNAMIC_RUNTIME_ATTRIBUTE, 60 }, + { READ_POSITION, 60 }, + { READ_REVERSE, -1 }, + { RECOVER_BUFFERED_DATA, -1 }, + { REPORT_DENSITY_SUPPORT, 60 }, + { STRING_SEARCH, -1 }, + { WRITE_DYNAMIC_RUNTIME_ATTRIBUTE, 60 }, + { -1, -1 } }; + +static struct _timeout_tape timeout_lto5[] = { { ERASE, 16380 }, + { FORMAT_MEDIUM, 1560 }, + { LOAD_UNLOAD, 780 }, + { LOCATE10, 2040 }, + { LOCATE16, 2040 }, + { READ, 1500 }, + { READ_BUFFER, 480 }, + { REWIND, 600 }, + { SEND_DIAGNOSTIC, 2100 }, + { SET_CAPACITY, 780 }, + { SPACE6, 2040 }, + { SPACE16, 2040 }, + { VERIFY, 16920 }, + { WRITE, 1500 }, + { WRITE_BUFFER, 540 }, + { WRITE_FILEMARKS6, 1620 }, + { -1, -1 } }; + +static struct _timeout_tape timeout_lto6[] = { { ERASE, 24600 }, + { FORMAT_MEDIUM, 3000 }, + { LOAD_UNLOAD, 780 }, + { LOCATE10, 2940 }, + { LOCATE16, 2940 }, + { READ, 1500 }, + { READ_BUFFER, 480 }, + { REWIND, 600 }, + { SEND_DIAGNOSTIC, 2100 }, + { SET_CAPACITY, 780 }, + { SPACE6, 2040 }, + { SPACE16, 2040 }, + { VERIFY, 25200 }, + { WRITE, 1500 }, + { WRITE_BUFFER, 540 }, + { WRITE_FILEMARKS6, 1620 }, + { -1, -1 } }; + +static struct _timeout_tape timeout_lto7[] = { { ERASE, 27540 }, + { FORMAT_MEDIUM, 3000 }, + { LOAD_UNLOAD, 960 }, + { LOCATE10, 2880 }, + { LOCATE16, 2880 }, + { READ, 2280 }, + { READ_BUFFER, 480 }, + { REWIND, 600 }, + { SEND_DIAGNOSTIC, 1980 }, + { SET_CAPACITY, 780 }, + { SPACE6, 2880 }, + { SPACE16, 2880 }, + { VERIFY, 28860 }, + { WRITE, 1500 }, + { WRITE_BUFFER, 540 }, + { WRITE_FILEMARKS6, 1620 }, + { -1, -1 } }; + +static struct _timeout_tape timeout_lto8[] = { { ERASE, 54896 }, + { FORMAT_MEDIUM, 3000 }, + { LOAD_UNLOAD, 960 }, + { LOCATE10, 2880 }, + { LOCATE16, 2880 }, + { READ, 2280 }, + { READ_BUFFER, 480 }, + { REWIND, 600 }, + { SEND_DIAGNOSTIC, 1980 }, + { SET_CAPACITY, 780 }, + { SPACE6, 2880 }, + { SPACE16, 2880 }, + { VERIFY, 47700 }, + { WRITE, 1500 }, + { WRITE_BUFFER, 540 }, + { WRITE_FILEMARKS6, 1620 }, + { -1, -1 } }; + +static struct _timeout_tape timeout_lto9[] = { { ERASE, 74341 }, + { FORMAT_MEDIUM, 3000 }, + { LOAD_UNLOAD, 960 }, + { LOCATE10, 2940 }, + { LOCATE16, 2940 }, + { READ, 2340 }, + { READ_BUFFER, 480 }, + { REWIND, 600 }, + { SEND_DIAGNOSTIC, 1980 }, + { SET_CAPACITY, 780 }, + { SPACE6, 2940 }, + { SPACE16, 2940 }, + { VERIFY, 63300 }, + { WRITE, 1500 }, + { WRITE_BUFFER, 540 }, + { WRITE_FILEMARKS6, 1620 }, + { -1, -1 } }; + +static struct _timeout_tape timeout_lto10[] = { { ERASE, 16320 }, + { FORMAT_MEDIUM, 3180 }, + { LOAD_UNLOAD, 780 }, + { LOCATE10, 2940 }, + { LOCATE16, 2940 }, + { READ, 2340 }, + { READ_BUFFER, 480 }, + { REWIND, 600 }, + { SEND_DIAGNOSTIC, 1980 }, + { SET_CAPACITY, 780 }, + { SPACE6, 2940 }, + { SPACE16, 2940 }, + { VERIFY, 104880 }, + { WRITE, 1500 }, + { WRITE_BUFFER, 540 }, + { WRITE_FILEMARKS6, 1620 }, + { -1, -1 } }; + +static struct _timeout_tape timeout_lto5_hh[] = { { ERASE, 19200 }, + { FORMAT_MEDIUM, 1980 }, + { LOAD_UNLOAD, 1020 }, + { LOCATE10, 2700 }, + { LOCATE16, 2700 }, + { READ, 1920 }, + { READ_BUFFER, 660 }, + { REWIND, 780 }, + { SEND_DIAGNOSTIC, 3120 }, + { SET_CAPACITY, 960 }, + { SPACE6, 2700 }, + { SPACE16, 2700 }, + { VERIFY, 19980 }, + { WRITE, 1920 }, + { WRITE_BUFFER, 720 }, + { WRITE_FILEMARKS6, 1740 }, + { -1, -1 } }; + +static struct _timeout_tape timeout_lto6_hh[] = { { ERASE, 29400 }, + { FORMAT_MEDIUM, 3840 }, + { LOAD_UNLOAD, 1020 }, + { LOCATE10, 2700 }, + { LOCATE16, 2700 }, + { READ, 1920 }, + { READ_BUFFER, 660 }, + { REWIND, 780 }, + { SEND_DIAGNOSTIC, 3120 }, + { SET_CAPACITY, 960 }, + { SPACE6, 2700 }, + { SPACE16, 2700 }, + { VERIFY, 30000 }, + { WRITE, 1920 }, + { WRITE_BUFFER, 720 }, + { WRITE_FILEMARKS6, 1740 }, + { -1, -1 } }; + +static struct _timeout_tape timeout_lto7_hh[] = { { ERASE, 27540 }, + { FORMAT_MEDIUM, 3240 }, + { LOAD_UNLOAD, 960 }, + { LOCATE10, 2940 }, + { LOCATE16, 2940 }, + { READ, 2340 }, + { READ_BUFFER, 480 }, + { REWIND, 600 }, + { SEND_DIAGNOSTIC, 2040 }, + { SET_CAPACITY, 960 }, + { SPACE6, 2940 }, + { SPACE16, 2940 }, + { VERIFY, 28860 }, + { WRITE, 1560 }, + { WRITE_BUFFER, 540 }, + { WRITE_FILEMARKS6, 1680 }, + { -1, -1 } }; + +static struct _timeout_tape timeout_lto8_hh[] = { { ERASE, 121448 }, + { FORMAT_MEDIUM, 3240 }, + { LOAD_UNLOAD, 960 }, + { LOCATE10, 2940 }, + { LOCATE16, 2940 }, + { READ, 2340 }, + { READ_BUFFER, 480 }, + { REWIND, 600 }, + { SEND_DIAGNOSTIC, 2040 }, + { SET_CAPACITY, 960 }, + { SPACE6, 2940 }, + { SPACE16, 2940 }, + { VERIFY, 54360 }, + { WRITE, 1560 }, + { WRITE_BUFFER, 540 }, + { WRITE_FILEMARKS6, 1680 }, + { -1, -1 } }; + +static struct _timeout_tape timeout_lto9_hh[] = { { ERASE, 166370 }, + { FORMAT_MEDIUM, 3240 }, + { LOAD_UNLOAD, 960 }, + { LOCATE10, 2940 }, + { LOCATE16, 2940 }, + { READ, 2340 }, + { READ_BUFFER, 480 }, + { REWIND, 600 }, + { SEND_DIAGNOSTIC, 2040 }, + { SET_CAPACITY, 960 }, + { SPACE6, 2940 }, + { SPACE16, 2940 }, + { VERIFY, 63300 }, + { WRITE, 1560 }, + { WRITE_BUFFER, 540 }, + { WRITE_FILEMARKS6, 1680 }, + { -1, -1 } }; + +static struct _timeout_tape timeout_lto10_hh[] = { { ERASE, 166370 }, + { FORMAT_MEDIUM, 3240 }, + { LOAD_UNLOAD, 960 }, + { LOCATE10, 3940 }, + { LOCATE16, 3940 }, + { READ, 2340 }, + { READ_BUFFER, 480 }, + { REWIND, 600 }, + { SEND_DIAGNOSTIC, 2040 }, + { SET_CAPACITY, 960 }, + { SPACE6, 3940 }, + { SPACE16, 3940 }, + { VERIFY, 63300 }, + { WRITE, 1560 }, + { WRITE_BUFFER, 540 }, + { WRITE_FILEMARKS6, 1680 }, + { -1, -1 } }; + +static struct _timeout_tape timeout_11x0[] = { { CHANGE_DEFINITION, 30 }, + { INQUIRY, 30 }, + { LOG_SELECT, 30 }, + { LOG_SENSE, 30 }, + { MODE_SELECT6, 300 }, /* For scale change */ + { MODE_SELECT10, 300 }, /* For scale change */ + { MODE_SENSE6, 30 }, + { MODE_SENSE10, 30 }, + { PERSISTENT_RESERVE_IN, 30 }, + { PERSISTENT_RESERVE_OUT, 900 }, + { READ_ATTRIBUTE, 30 }, + { RECEIVE_DIAGNOSTIC_RESULTS, 60 }, + { RELEASE_UNIT6, 60 }, + { RELEASE_UNIT10, 60 }, + { REPORT_LUNS, 60 }, + { REQUEST_SENSE, 60 }, + { RESERVE_UNIT6, 60 }, + { RESERVE_UNIT10, 60 }, + { SPIN, 300 }, + { SPOUT, 300 }, + { TEST_UNIT_READY, 30 }, + { WRITE_ATTRIBUTE, 30 }, + { ALLOW_OVERWRITE, 30 }, + { DISPLAY_MESSAGE, 30 }, + { PREVENT_ALLOW_MEDIUM_REMOVAL, 30 }, + { READ_BLOCK_LIMITS, 30 }, + { READ_DYNAMIC_RUNTIME_ATTRIBUTE, 30 }, + { READ_POSITION, 30 }, + { READ_REVERSE, 1080 }, + { RECOVER_BUFFERED_DATA, 60 }, + { REPORT_DENSITY_SUPPORT, 30 }, + { SET_CAPACITY, -1 }, + { STRING_SEARCH, -1 }, + { WRITE_DYNAMIC_RUNTIME_ATTRIBUTE, 30 }, + { -1, -1 } }; static struct _timeout_tape timeout_1140[] = { - { XCOPY, -1 }, - { ERASE, 36900 }, - { FORMAT_MEDIUM, 3000 }, - { LOAD_UNLOAD, 720 }, - { LOCATE10, 2000 }, - { LOCATE16, 2000 }, - { READ, 2100 }, - { READ_BUFFER, 300 }, - { REWIND, 480 }, - { SEND_DIAGNOSTIC, 2100 }, - { SPACE6, 2000 }, - { SPACE16, 2000 }, - { VERIFY, 38100 }, - { WRITE, 1200 }, - { WRITE_BUFFER, 540 }, - { WRITE_FILEMARKS6, 1100 }, - {-1, -1} + { XCOPY, -1 }, { ERASE, 36900 }, { FORMAT_MEDIUM, 3000 }, { LOAD_UNLOAD, 720 }, + { LOCATE10, 2000 }, { LOCATE16, 2000 }, { READ, 2100 }, { READ_BUFFER, 300 }, + { REWIND, 480 }, { SEND_DIAGNOSTIC, 2100 }, { SPACE6, 2000 }, { SPACE16, 2000 }, + { VERIFY, 38100 }, { WRITE, 1200 }, { WRITE_BUFFER, 540 }, { WRITE_FILEMARKS6, 1100 }, + { -1, -1 } }; static struct _timeout_tape timeout_1150[] = { - { XCOPY, 18000 }, - { ERASE, 45800 }, - { FORMAT_MEDIUM, 3100 }, - { LOAD_UNLOAD, 900 }, - { LOCATE10, 2300 }, - { LOCATE16, 2300 }, - { READ, 2400 }, - { READ_BUFFER, 480 }, - { REWIND, 560 }, - { SEND_DIAGNOSTIC, 2100 }, - { SPACE6, 2300 }, - { SPACE16, 2300 }, - { VERIFY, 46700 }, - { WRITE, 1500 }, - { WRITE_BUFFER, 540 }, - { WRITE_FILEMARKS6, 1400 }, - {-1, -1} + { XCOPY, 18000 }, { ERASE, 45800 }, { FORMAT_MEDIUM, 3100 }, { LOAD_UNLOAD, 900 }, + { LOCATE10, 2300 }, { LOCATE16, 2300 }, { READ, 2400 }, { READ_BUFFER, 480 }, + { REWIND, 560 }, { SEND_DIAGNOSTIC, 2100 }, { SPACE6, 2300 }, { SPACE16, 2300 }, + { VERIFY, 46700 }, { WRITE, 1500 }, { WRITE_BUFFER, 540 }, { WRITE_FILEMARKS6, 1400 }, + { -1, -1 } }; static struct _timeout_tape timeout_1155[] = { - { XCOPY, 68900 }, - { ERASE, 68000 }, - { FORMAT_MEDIUM, 3100 }, - { LOAD_UNLOAD, 900 }, - { LOCATE10, 2300 }, - { LOCATE16, 2300 }, - { READ, 2400 }, - { READ_BUFFER, 480 }, - { REWIND, 560 }, - { SEND_DIAGNOSTIC, 2100 }, - { SPACE6, 2300 }, - { SPACE16, 2300 }, - { VERIFY, 68900 }, - { WRITE, 1500 }, - { WRITE_BUFFER, 540 }, - { WRITE_FILEMARKS6, 1400 }, - {-1, -1} + { XCOPY, 68900 }, { ERASE, 68000 }, { FORMAT_MEDIUM, 3100 }, { LOAD_UNLOAD, 900 }, + { LOCATE10, 2300 }, { LOCATE16, 2300 }, { READ, 2400 }, { READ_BUFFER, 480 }, + { REWIND, 560 }, { SEND_DIAGNOSTIC, 2100 }, { SPACE6, 2300 }, { SPACE16, 2300 }, + { VERIFY, 68900 }, { WRITE, 1500 }, { WRITE_BUFFER, 540 }, { WRITE_FILEMARKS6, 1400 }, + { -1, -1 } }; static struct _timeout_tape timeout_1160[] = { - { XCOPY, 68900 }, - { ERASE, 64860 }, - { FORMAT_MEDIUM, 3060 }, - { LOAD_UNLOAD, 900 }, - { LOCATE10, 2280 }, - { LOCATE16, 2280 }, - { READ, 2340 }, - { READ_BUFFER, 480 }, - { REWIND, 600 }, - { SEND_DIAGNOSTIC, 2100 }, - { SPACE6, 2380 }, - { SPACE16, 2380 }, - { VERIFY, 65820 }, - { WRITE, 1440 }, - { WRITE_BUFFER, 530 }, - { WRITE_FILEMARKS6, 1380 }, - {-1, -1} + { XCOPY, 68900 }, { ERASE, 64860 }, { FORMAT_MEDIUM, 3060 }, { LOAD_UNLOAD, 900 }, + { LOCATE10, 2280 }, { LOCATE16, 2280 }, { READ, 2340 }, { READ_BUFFER, 480 }, + { REWIND, 600 }, { SEND_DIAGNOSTIC, 2100 }, { SPACE6, 2380 }, { SPACE16, 2380 }, + { VERIFY, 65820 }, { WRITE, 1440 }, { WRITE_BUFFER, 530 }, { WRITE_FILEMARKS6, 1380 }, + { -1, -1 } }; static struct _timeout_tape timeout_1170[] = { - { XCOPY, 176820 }, - { ERASE, 175900 }, - { FORMAT_MEDIUM, 3120 }, - { LOAD_UNLOAD, 900 }, - { LOCATE10, 2280 }, - { LOCATE16, 2240 }, - { READ, 2340 }, - { READ_BUFFER, 480 }, - { REWIND, 600 }, - { SEND_DIAGNOSTIC, 2280 }, - { SPACE6, 2280 }, - { SPACE16, 2240 }, - { VERIFY, 176820 }, - { WRITE, 1440 }, - { WRITE_BUFFER, 540 }, - { WRITE_FILEMARKS6, 1380 }, - {-1, -1} + { XCOPY, 176820 }, { ERASE, 175900 }, { FORMAT_MEDIUM, 3120 }, { LOAD_UNLOAD, 900 }, + { LOCATE10, 2280 }, { LOCATE16, 2240 }, { READ, 2340 }, { READ_BUFFER, 480 }, + { REWIND, 600 }, { SEND_DIAGNOSTIC, 2280 }, { SPACE6, 2280 }, { SPACE16, 2240 }, + { VERIFY, 176820 }, { WRITE, 1440 }, { WRITE_BUFFER, 540 }, { WRITE_FILEMARKS6, 1380 }, + { -1, -1 } }; -static int _create_table_tape(struct timeout_tape **result, - struct _timeout_tape* base, - struct _timeout_tape* override) +static int _create_table_tape(struct timeout_tape **result, struct _timeout_tape *base, struct _timeout_tape *override) { - struct _timeout_tape* cur; - struct timeout_tape* entry; + struct _timeout_tape *cur; + struct timeout_tape *entry; struct timeout_tape *out = NULL; entry = malloc(sizeof(struct timeout_tape)); - entry->op_code = override->op_code; + entry->op_code = override->op_code; entry->timeout = override->timeout; HASH_ADD_INT(*result, op_code, entry); - if (! *result) { + if (!*result) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } - for ( cur = override; cur->op_code != -1; ++cur) { + for (cur = override; cur->op_code != -1; ++cur) { entry = malloc(sizeof(struct timeout_tape)); - entry->op_code = cur->op_code; + entry->op_code = cur->op_code; entry->timeout = cur->timeout; HASH_ADD_INT(*result, op_code, entry); } - for ( cur = base; cur->op_code != -1; ++cur) { + for (cur = base; cur->op_code != -1; ++cur) { out = NULL; HASH_FIND_INT(*result, &cur->op_code, out); if (!out) { entry = malloc(sizeof(struct timeout_tape)); - entry->op_code = cur->op_code; + entry->op_code = cur->op_code; entry->timeout = cur->timeout; HASH_ADD_INT(*result, op_code, entry); } @@ -927,7 +807,7 @@ static int _create_table_tape(struct timeout_tape **result, return 0; } -int ibm_tape_init_timeout(struct timeout_tape** table, int type) +int ibm_tape_init_timeout(struct timeout_tape **table, int type) { int ret = 0; @@ -1071,8 +951,7 @@ static inline unsigned char _assume_cartridge_type(char product, char btype) default: break; } - } - else if (product == 'P') { + } else if (product == 'P') { switch (btype) { case 'A': ctype = TC_MP_LTOP10D_CART; @@ -1085,21 +964,19 @@ static inline unsigned char _assume_cartridge_type(char product, char btype) return ctype; } -unsigned char ibm_tape_assume_cart_type(const char* type_name) +unsigned char ibm_tape_assume_cart_type(const char *type_name) { unsigned char c_type = 0; - if (strlen(type_name) < 2) - return TC_MP_LTO5D_CART; + if (strlen(type_name) < 2) return TC_MP_LTO5D_CART; c_type = _assume_cartridge_type(type_name[0], type_name[1]); - if (!c_type) - c_type = TC_MP_LTO5D_CART; + if (!c_type) c_type = TC_MP_LTO5D_CART; return c_type; } -char* ibm_tape_assume_cart_name(unsigned char type) +char *ibm_tape_assume_cart_name(unsigned char type) { char *name = NULL; @@ -1170,16 +1047,16 @@ char* ibm_tape_assume_cart_name(unsigned char type) } static inline int _is_mountable(const int drive_type, - const char *barcode, - const unsigned char cart_type, - const unsigned char density_code, - const bool strict) + const char *barcode, + const unsigned char cart_type, + const unsigned char density_code, + const bool strict) { int drive_generation = DRIVE_FAMILY_GEN(drive_type); - char product = 0x00; /* Product type on barcode */ - char btype = 0x00; /* Cartridge type on barcode */ + char product = 0x00; /* Product type on barcode */ + char btype = 0x00; /* Cartridge type on barcode */ unsigned char ctype = cart_type; /* Cartridge type in CM */ - unsigned char dcode = 0; /* Density code in CM */ + unsigned char dcode = 0; /* Density code in CM */ DRIVE_DENSITY_SUPPORT_MAP *table = NULL; int num_table = 0, i; int ret = MEDIUM_CANNOT_ACCESS; @@ -1220,20 +1097,16 @@ static inline int _is_mountable(const int drive_type, } /* Assume cartridge type from barcode */ - if (ctype == 0) - ctype = _assume_cartridge_type(product, btype); + if (ctype == 0) ctype = _assume_cartridge_type(product, btype); /* Special case, assume M8 as TC_DC_M8 when density code is not fetched yet */ if (density_code == 0x00) { - if (product == 'M' && btype == '8') - dcode = TC_DC_LTOM8; + if (product == 'M' && btype == '8') dcode = TC_DC_LTOM8; } for (i = 0; i < num_table; i++) { - if ( (table->drive_generation == drive_generation) && - (table->cartridge_type == ctype) && - (table->density_code == dcode) ) - { + if ((table->drive_generation == drive_generation) && (table->cartridge_type == ctype) && + (table->density_code == dcode)) { ret = table->access; break; } @@ -1244,10 +1117,10 @@ static inline int _is_mountable(const int drive_type, } int ibm_tape_is_mountable(const int drive_type, - const char *barcode, - const unsigned char cart_type, - const unsigned char density_code, - const bool strict) + const char *barcode, + const unsigned char cart_type, + const unsigned char density_code, + const bool strict) { int ret = MEDIUM_CANNOT_ACCESS; @@ -1283,7 +1156,7 @@ int ibm_tape_genkey(unsigned char *key) #ifdef mingw_PLATFORM memset(key, 0x00, KEYLEN); *key = KEY_PREFIX_HOST; - arch_strncpy(key + 1, "WNLTFS", KEYLEN - 1,KEYLEN-2); + arch_strncpy(key + 1, "WNLTFS", KEYLEN - 1, KEYLEN - 2); #else unsigned char host[KEYLEN]; @@ -1303,11 +1176,9 @@ int ibm_tape_genkey(unsigned char *key) if (!getifaddrs(&ifaddr)) { for (ifa = ifaddr, n = 0; ifa != NULL; ifa = ifa->ifa_next, n++) { - if (ifa->ifa_addr == NULL) - continue; + if (ifa->ifa_addr == NULL) continue; - if (!strncmp(ifa->ifa_name, LOOP_BACK_DEVICE, 2)) - continue; + if (!strncmp(ifa->ifa_name, LOOP_BACK_DEVICE, 2)) continue; family = ifa->ifa_addr->sa_family; @@ -1352,7 +1223,7 @@ int ibm_tape_genkey(unsigned char *key) /* Return host name based key */ *key = KEY_PREFIX_HOST; - memcpy(key + 1, host, KEYLEN -1); + memcpy(key + 1, host, KEYLEN - 1); #endif return 0; @@ -1363,26 +1234,46 @@ int ibm_tape_parsekey(unsigned char *key, struct reservation_info *r) r->key_type = key[0]; switch (r->key_type) { case KEY_PREFIX_IPV6: - snprintf(r->hint, sizeof(r->hint), - "IPv6 (last 7 bytes): xx%02x:%02x%02x:%02x%02x:%02x%02x", - key[1], key[2], key[3], key[4], key[5], key[6], key[7]); + snprintf(r->hint, + sizeof(r->hint), + "IPv6 (last 7 bytes): xx%02x:%02x%02x:%02x%02x:%02x%02x", + key[1], + key[2], + key[3], + key[4], + key[5], + key[6], + key[7]); break; case KEY_PREFIX_HOST: - snprintf(r->hint, sizeof(r->hint), - "HOSTNAME (first 7 bytes): %c%c%c%c%c%c%c", - key[1], key[2], key[3], key[4], key[5], key[6], key[7]); + snprintf(r->hint, + sizeof(r->hint), + "HOSTNAME (first 7 bytes): %c%c%c%c%c%c%c", + key[1], + key[2], + key[3], + key[4], + key[5], + key[6], + key[7]); break; case KEY_PREFIX_IPV4: if (!key[1] && !key[2] && !key[3]) { - snprintf(r->hint, sizeof(r->hint), - "IPv4: %d.%d.%d.%d", - key[4], key[5], key[6], key[7]); + snprintf(r->hint, sizeof(r->hint), "IPv4: %d.%d.%d.%d", key[4], key[5], key[6], key[7]); break; - } // else fall through + } // else fall through default: - snprintf(r->hint, sizeof(r->hint), - "KEY: x%02x%02x%02x%02x%02x%02x%02x%02x", - key[0], key[1], key[2], key[3], key[4], key[5], key[6], key[7]); + snprintf(r->hint, + sizeof(r->hint), + "KEY: x%02x%02x%02x%02x%02x%02x%02x%02x", + key[0], + key[1], + key[2], + key[3], + key[4], + key[5], + key[6], + key[7]); } memcpy(r->wwid, key + 32, sizeof(r->wwid)); @@ -1390,42 +1281,42 @@ int ibm_tape_parsekey(unsigned char *key, struct reservation_info *r) return 0; } -bool ibm_tape_is_supported_firmware(int drive_type, const unsigned char * const revision) +bool ibm_tape_is_supported_firmware(int drive_type, const unsigned char *const revision) { bool supported = true; const uint32_t rev = ltfs_betou32(revision); switch (drive_type) { - case DRIVE_LTO5: - case DRIVE_LTO5_HH: - if (rev < ltfs_betou32(base_firmware_level_lto5)) { - ltfsmsg(LTFS_WARN, 39812W, base_firmware_level_lto5); - ltfsmsg(LTFS_WARN, 39813W); - supported = false; - } - break; - case DRIVE_LTO8: - case DRIVE_LTO8_HH: - if (rev < ltfs_betou32(base_firmware_level_lto8)) { - ltfsmsg(LTFS_WARN, 39812W, base_firmware_level_lto8); - supported = false; - } - break; - case DRIVE_TS1140: - if (rev < ltfs_betou32(base_firmware_level_ts1140)) { - ltfsmsg(LTFS_WARN, 39812W, base_firmware_level_ts1140); - supported = false; - } - break; - case DRIVE_LTO6: - case DRIVE_LTO6_HH: - case DRIVE_LTO7: - case DRIVE_LTO7_HH: - case DRIVE_TS1150: - case DRIVE_TS1160: - case DRIVE_TS1170: - default: - break; + case DRIVE_LTO5: + case DRIVE_LTO5_HH: + if (rev < ltfs_betou32(base_firmware_level_lto5)) { + ltfsmsg(LTFS_WARN, 39812W, base_firmware_level_lto5); + ltfsmsg(LTFS_WARN, 39813W); + supported = false; + } + break; + case DRIVE_LTO8: + case DRIVE_LTO8_HH: + if (rev < ltfs_betou32(base_firmware_level_lto8)) { + ltfsmsg(LTFS_WARN, 39812W, base_firmware_level_lto8); + supported = false; + } + break; + case DRIVE_TS1140: + if (rev < ltfs_betou32(base_firmware_level_ts1140)) { + ltfsmsg(LTFS_WARN, 39812W, base_firmware_level_ts1140); + supported = false; + } + break; + case DRIVE_LTO6: + case DRIVE_LTO6_HH: + case DRIVE_LTO7: + case DRIVE_LTO7_HH: + case DRIVE_TS1150: + case DRIVE_TS1160: + case DRIVE_TS1170: + default: + break; } return supported; diff --git a/src/tape_drivers/linux/lin_tape/lin_tape_ibmtape.c b/src/tape_drivers/linux/lin_tape/lin_tape_ibmtape.c index f8c1448c..fb95801f 100644 --- a/src/tape_drivers/linux/lin_tape/lin_tape_ibmtape.c +++ b/src/tape_drivers/linux/lin_tape/lin_tape_ibmtape.c @@ -47,24 +47,23 @@ ************************************************************************************* */ -#include -#include -#include -#include -#include +#include #include #include +#include +#include #include +#include +#include +#include +#include #include -#include -#include #include "ltfs_copyright.h" +#include "libltfs/arch/time_internal.h" #include "libltfs/ltfs_endian.h" #include "libltfs/ltfs_fuse_version.h" -#include "libltfs/arch/time_internal.h" -#include "libltfs/arch/time_internal.h" #include @@ -77,59 +76,61 @@ #undef MAXSENSE #include "IBM_tape.h" -#include "reed_solomon_crc.h" #include "crc32c_crc.h" +#include "reed_solomon_crc.h" -struct lin_tape_ibmtape { - int fd; /**< file descriptor of the device */ - bool loaded; /**< Is cartridge loaded? */ - bool loadfailed; /**< Is load/unload failed? */ - unsigned char drive_serial[255]; /**< serial number of device */ - int drive_type; /**< drive type */ - char *devname; /**< device name */ - long fetch_sec_acq_loss_w; /**< Sec to fetch Active CQs loss write */ - bool dirty_acq_loss_w; /**< Is Active CQs loss write dirty */ - float acq_loss_w; /**< Active CQs loss write */ - uint64_t tape_alert; /**< Latched tape alert flag */ - bool is_data_key_set; /**< Is a valid data key set? */ - unsigned char dki[12]; /**< key-alias */ - bool clear_by_pc; /**< clear pseudo write perm by partition change */ - uint64_t force_writeperm; /**< pseudo write perm threshold */ - uint64_t force_readperm; /**< pseudo read perm threashold */ - uint64_t write_counter; /**< write call counter for pseudo write perm */ - uint64_t read_counter; /**< read call counter for pseudo write perm */ - int force_errortype; /**< 0 is R/W Perm, otherwise no sense */ - bool is_worm; /**< Is worm cartridge loaded? */ - unsigned char cart_type; /**< Cartridge type in CM */ - unsigned char density_code; /**< Density code */ - crc_enc f_crc_enc; /**< Pointer to CRC encode function */ - crc_check f_crc_check; /**< Pointer to CRC encode function */ - struct timeout_tape *timeouts; /**< Timeout table */ - struct tc_drive_info info; /**< Drive information */ - FILE* profiler; /**< The file pointer for profiler */ +struct lin_tape_ibmtape +{ + int fd; /**< file descriptor of the device */ + bool loaded; /**< Is cartridge loaded? */ + bool loadfailed; /**< Is load/unload failed? */ + unsigned char drive_serial[255]; /**< serial number of device */ + int drive_type; /**< drive type */ + char *devname; /**< device name */ + long fetch_sec_acq_loss_w; /**< Sec to fetch Active CQs loss write */ + bool dirty_acq_loss_w; /**< Is Active CQs loss write dirty */ + float acq_loss_w; /**< Active CQs loss write */ + uint64_t tape_alert; /**< Latched tape alert flag */ + bool is_data_key_set; /**< Is a valid data key set? */ + unsigned char dki[12]; /**< key-alias */ + bool clear_by_pc; /**< clear pseudo write perm by partition change */ + uint64_t force_writeperm; /**< pseudo write perm threshold */ + uint64_t force_readperm; /**< pseudo read perm threashold */ + uint64_t write_counter; /**< write call counter for pseudo write perm */ + uint64_t read_counter; /**< read call counter for pseudo write perm */ + int force_errortype; /**< 0 is R/W Perm, otherwise no sense */ + bool is_worm; /**< Is worm cartridge loaded? */ + unsigned char cart_type; /**< Cartridge type in CM */ + unsigned char density_code; /**< Density code */ + crc_enc f_crc_enc; /**< Pointer to CRC encode function */ + crc_check f_crc_check; /**< Pointer to CRC encode function */ + struct timeout_tape *timeouts; /**< Timeout table */ + struct tc_drive_info info; /**< Drive information */ + FILE *profiler; /**< The file pointer for profiler */ }; -struct lin_tape_ibmtape_global_data { - unsigned disable_auto_dump; /**< Is auto dump disabled? */ - char *str_crc_checking; /**< option string for crc_checking */ - unsigned crc_checking; /**< Is crc checking enabled? */ - unsigned strict_drive; /**< Is bar code length checked strictly? */ +struct lin_tape_ibmtape_global_data +{ + unsigned disable_auto_dump; /**< Is auto dump disabled? */ + char *str_crc_checking; /**< option string for crc_checking */ + unsigned crc_checking; /**< Is crc checking enabled? */ + unsigned strict_drive; /**< Is bar code length checked strictly? */ }; /* * Default tape device */ const char *lin_tape_ibmtape_default_device = "/dev/IBMtape0"; -volatile char *copyright = LTFS_COPYRIGHT_0"\n"LTFS_COPYRIGHT_1"\n"LTFS_COPYRIGHT_2"\n"; +volatile char *copyright = LTFS_COPYRIGHT_0 "\n" LTFS_COPYRIGHT_1 "\n" LTFS_COPYRIGHT_2 "\n"; /* * Definitions */ #define DMP_DIR "/tmp" -#define LOG_PAGE_HEADER_SIZE (4) +#define LOG_PAGE_HEADER_SIZE (4) #define LOG_PAGE_PARAMSIZE_OFFSET (3) -#define LOG_PAGE_PARAM_OFFSET (4) +#define LOG_PAGE_PARAM_OFFSET (4) #define LINUX_MAX_BLOCK_SIZE (1 * MB) #define MIN(a, b) ((a) < (b) ? (a) : (b)) @@ -141,49 +142,52 @@ volatile char *copyright = LTFS_COPYRIGHT_0"\n"LTFS_COPYRIGHT_1"\n"LTFS_COPYRIGH #define MAX_WRITE_RETRY (100) -#define DEFAULT_WRITEPERM (0) -#define DEFAULT_READPERM (0) -#define DEFAULT_ERRORTYPE (0) - -enum scsi_status { - SCSI_GOOD = 0x00, - SCSI_CHECK_CONDITION = 0x01, - SCSI_CONDITION_GOOD = 0x02, - SCSI_BUSY = 0x04, - SCSI_INTERMEDIATE_GOOD = 0x08, - SCSI_INTERMEDIATE_C_GOOD = 0x0a, +#define DEFAULT_WRITEPERM (0) +#define DEFAULT_READPERM (0) +#define DEFAULT_ERRORTYPE (0) + +enum scsi_status +{ + SCSI_GOOD = 0x00, + SCSI_CHECK_CONDITION = 0x01, + SCSI_CONDITION_GOOD = 0x02, + SCSI_BUSY = 0x04, + SCSI_INTERMEDIATE_GOOD = 0x08, + SCSI_INTERMEDIATE_C_GOOD = 0x0a, SCSI_RESERVATION_CONFRICT = 0x0c, }; -enum host_status { - HOST_GOOD = 0x00, +enum host_status +{ + HOST_GOOD = 0x00, HOST_NO_CONNECT = 0x01, - HOST_BUS_BUSY = 0x02, - HOST_TIME_OUT = 0x03, + HOST_BUS_BUSY = 0x02, + HOST_TIME_OUT = 0x03, HOST_BAD_TARGET = 0x04, - HOST_ABORT = 0x05, - HOST_PARITY = 0x06, - HOST_ERROR = 0x07, - HOST_RESET = 0x08, - HOST_BAD_INTR = 0x09, + HOST_ABORT = 0x05, + HOST_PARITY = 0x06, + HOST_ERROR = 0x07, + HOST_RESET = 0x08, + HOST_BAD_INTR = 0x09, }; -enum driver_status { - DRIVER_GOOD = 0x00, - DRIVER_BUSY = 0x01, - DRIVER_SOFT = 0x02, - DRIVER_MEDIA = 0x03, - DRIVER_ERROR = 0x04, - DRIVER_INVALID = 0x05, - DRIVER_TIMEOUT = 0x06, - DRIVER_HARD = 0x07, - DRIVER_SENSE = 0x08, - SUGGEST_RETRY = 0x10, - SUGGEST_ABORT = 0x20, - SUGGEST_REMAP = 0x30, - SUGGEST_DIE = 0x40, - SUGGEST_SENSE = 0x80, - SUGGEST_IS_OK = 0xff, +enum driver_status +{ + DRIVER_GOOD = 0x00, + DRIVER_BUSY = 0x01, + DRIVER_SOFT = 0x02, + DRIVER_MEDIA = 0x03, + DRIVER_ERROR = 0x04, + DRIVER_INVALID = 0x05, + DRIVER_TIMEOUT = 0x06, + DRIVER_HARD = 0x07, + DRIVER_SENSE = 0x08, + SUGGEST_RETRY = 0x10, + SUGGEST_ABORT = 0x20, + SUGGEST_REMAP = 0x30, + SUGGEST_DIE = 0x40, + SUGGEST_SENSE = 0x80, + SUGGEST_IS_OK = 0xff, }; /* @@ -197,14 +201,10 @@ struct error_table *vendor_table; * Macros */ #if 0 -#define _ioctl(fd,x...) ( \ - fprintf(stderr, "[%s::%d]<@%s> Performing ioctl(%d, " ##x ")", __FILE__, __LINE__, __FUNCTION__, fd), \ - ioctl(fd, x) \ - ) +# define _ioctl(fd, x...) \ + (fprintf(stderr, "[%s::%d]<@%s> Performing ioctl(%d, "##x ")", __FILE__, __LINE__, __FUNCTION__, fd), ioctl(fd, x)) #else -#define _ioctl(fd,x...) ( \ - ioctl(fd, x) \ - ) +# define _ioctl(fd, x...) (ioctl(fd, x)) #endif /* @@ -212,9 +212,13 @@ struct error_table *vendor_table; */ int lin_tape_ibmtape_readpos(void *device, struct tc_position *pos); int lin_tape_ibmtape_rewind(void *device, struct tc_position *pos); -int lin_tape_ibmtape_modesense(void *device, const uint8_t page, const TC_MP_PC_TYPE pc, const uint8_t subpage, - unsigned char *buf, const size_t size); -int lin_tape_ibmtape_set_key(void *device, const unsigned char * const keyalias, const unsigned char * const key); +int lin_tape_ibmtape_modesense(void *device, + const uint8_t page, + const TC_MP_PC_TYPE pc, + const uint8_t subpage, + unsigned char *buf, + const size_t size); +int lin_tape_ibmtape_set_key(void *device, const unsigned char *const keyalias, const unsigned char *const key); int lin_tape_ibmtape_set_lbp(void *device, bool enable); int lin_tape_ibmtape_takedump_drive(void *device, bool nonforced_dump); int lin_tape_ibmtape_get_device_list(struct tc_drive_info *buf, int count); @@ -237,7 +241,7 @@ static inline void lin_tape_ibmtape_get_dump(void *device, bool nonforced_dump) static inline int _lin_tape_ibmtape_get_sense(void *device, struct sioc_pass_through *spt_org) { - int fd = *((int *) device); + int fd = *((int *)device); struct request_sense sense_data; int rc, i; @@ -245,31 +249,30 @@ static inline int _lin_tape_ibmtape_get_sense(void *device, struct sioc_pass_thr rc = _ioctl(fd, SIOC_REQSENSE, &sense_data); if (rc == 0) { spt_org->sense_length = sense_data.addlen + 7; - spt_org->sense[0] = (sense_data.valid << 7) | (sense_data.err_code & 0x7F); - spt_org->sense[1] = sense_data.segnum; - spt_org->sense[2] = (sense_data.fm << 7) | (sense_data.eom << 6) | (sense_data.ili << 5) | - (sense_data.resvd1 << 4) | (sense_data.key & 0x0F); - spt_org->sense[3] = (sense_data.info >> 24) & 0xFF; - spt_org->sense[4] = (sense_data.info >> 16) & 0xFF; - spt_org->sense[5] = (sense_data.info >> 8) & 0xFF; - spt_org->sense[6] = (sense_data.info & 0xFF); - spt_org->sense[7] = sense_data.addlen; - spt_org->sense[8] = (sense_data.cmdinfo >> 24) & 0xFF; - spt_org->sense[9] = (sense_data.cmdinfo >> 16) & 0xFF; + spt_org->sense[0] = (sense_data.valid << 7) | (sense_data.err_code & 0x7F); + spt_org->sense[1] = sense_data.segnum; + spt_org->sense[2] = (sense_data.fm << 7) | (sense_data.eom << 6) | (sense_data.ili << 5) | + (sense_data.resvd1 << 4) | (sense_data.key & 0x0F); + spt_org->sense[3] = (sense_data.info >> 24) & 0xFF; + spt_org->sense[4] = (sense_data.info >> 16) & 0xFF; + spt_org->sense[5] = (sense_data.info >> 8) & 0xFF; + spt_org->sense[6] = (sense_data.info & 0xFF); + spt_org->sense[7] = sense_data.addlen; + spt_org->sense[8] = (sense_data.cmdinfo >> 24) & 0xFF; + spt_org->sense[9] = (sense_data.cmdinfo >> 16) & 0xFF; spt_org->sense[10] = (sense_data.cmdinfo >> 8) & 0xFF; spt_org->sense[11] = (sense_data.cmdinfo & 0xFF); spt_org->sense[12] = sense_data.asc; spt_org->sense[13] = sense_data.ascq; spt_org->sense[14] = sense_data.fru; spt_org->sense[15] = (sense_data.sksv << 7) | (sense_data.cd << 6) | (sense_data.resvd2 << 4) | - (sense_data.bpv << 3) | (sense_data.sim & 0x07); + (sense_data.bpv << 3) | (sense_data.sim & 0x07); spt_org->sense[16] = sense_data.field[0]; spt_org->sense[17] = sense_data.field[1]; - for(i = 0; i < 109; ++i) + for (i = 0; i < 109; ++i) spt_org->sense[18 + i] = sense_data.vendor[i]; - } - else { + } else { rc = -EDEV_INTERNAL_ERROR; ltfsmsg(LTFS_INFO, 30412I, rc); } @@ -286,35 +289,48 @@ static inline int _lin_tape_ibmtape_get_sense(void *device, struct sioc_pass_thr */ static inline int _sioc_paththrough(void *device, struct sioc_pass_through *spt) { - int fd = ((struct lin_tape_ibmtape *) device)->fd; + int fd = ((struct lin_tape_ibmtape *)device)->fd; int ret; ret = _ioctl(fd, SIOC_PASS_THROUGH, spt); if (ret == -1) { - ltfsmsg(LTFS_INFO, 30400I, errno, ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg(LTFS_INFO, 30400I, errno, ((struct lin_tape_ibmtape *)device)->drive_serial); ret = -3; } /* check returned status */ if (spt->target_status || spt->msg_status || spt->host_status || spt->driver_status) { if (!spt->sense_length) { - ltfsmsg(LTFS_DEBUG, 30401D, spt->target_status, - spt->msg_status, spt->host_status, spt->driver_status, - ((struct lin_tape_ibmtape *) device)->drive_serial); - if(spt->driver_status & (DRIVER_SENSE | SUGGEST_SENSE)) - _lin_tape_ibmtape_get_sense(device, spt); + ltfsmsg(LTFS_DEBUG, + 30401D, + spt->target_status, + spt->msg_status, + spt->host_status, + spt->driver_status, + ((struct lin_tape_ibmtape *)device)->drive_serial); + if (spt->driver_status & (DRIVER_SENSE | SUGGEST_SENSE)) _lin_tape_ibmtape_get_sense(device, spt); } if (spt->sense_length) { ltfsmsg(LTFS_DEBUG, 30402D, spt->sense[2] & 0x0F, spt->sense[12], spt->sense[13]); - ltfsmsg(LTFS_DEBUG, 30403D, spt->sense[45], spt->sense[46], spt->sense[47], spt->sense[48], - ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg(LTFS_DEBUG, + 30403D, + spt->sense[45], + spt->sense[46], + spt->sense[47], + spt->sense[48], + ((struct lin_tape_ibmtape *)device)->drive_serial); ret = -1; } else { ltfsmsg(LTFS_INFO, 30404I); - ltfsmsg(LTFS_INFO, 30405I, spt->target_status, spt->msg_status, - spt->host_status, spt->driver_status, ((struct lin_tape_ibmtape *) device)->drive_serial); - if(spt->target_status) + ltfsmsg(LTFS_INFO, + 30405I, + spt->target_status, + spt->msg_status, + spt->host_status, + spt->driver_status, + ((struct lin_tape_ibmtape *)device)->drive_serial); + if (spt->target_status) ret = EDEV_TARGET_ERROR; else if (spt->host_status) ret = EDEV_HOST_ERROR; @@ -323,11 +339,15 @@ static inline int _sioc_paththrough(void *device, struct sioc_pass_through *spt) else ret = -2; } - } else if(ret == -3 && errno == EIO && - (spt->cdb[0] == 0x0A || spt->cdb[0] == 0x10)) { /* EIO against write and writefm command */ - ltfsmsg(LTFS_DEBUG, 30401D, spt->target_status, - spt->msg_status, spt->host_status, spt->driver_status, - ((struct lin_tape_ibmtape *) device)->drive_serial); + } else if (ret == -3 && errno == EIO && + (spt->cdb[0] == 0x0A || spt->cdb[0] == 0x10)) { /* EIO against write and writefm command */ + ltfsmsg(LTFS_DEBUG, + 30401D, + spt->target_status, + spt->msg_status, + spt->host_status, + spt->driver_status, + ((struct lin_tape_ibmtape *)device)->drive_serial); /* * When the issued command is write or writefm command and hit @@ -339,14 +359,24 @@ static inline int _sioc_paththrough(void *device, struct sioc_pass_through *spt) if (spt->sense_length) { ltfsmsg(LTFS_DEBUG, 30402D, spt->sense[2] & 0x0F, spt->sense[12], spt->sense[13]); - ltfsmsg(LTFS_DEBUG, 30403D, spt->sense[45], spt->sense[46], spt->sense[47], spt->sense[48], - ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg(LTFS_DEBUG, + 30403D, + spt->sense[45], + spt->sense[46], + spt->sense[47], + spt->sense[48], + ((struct lin_tape_ibmtape *)device)->drive_serial); ret = -1; } else { ltfsmsg(LTFS_INFO, 30404I); - ltfsmsg(LTFS_INFO, 30405I, spt->target_status, spt->msg_status, - spt->host_status, spt->driver_status, ((struct lin_tape_ibmtape *) device)->drive_serial); - if(spt->target_status) + ltfsmsg(LTFS_INFO, + 30405I, + spt->target_status, + spt->msg_status, + spt->host_status, + spt->driver_status, + ((struct lin_tape_ibmtape *)device)->drive_serial); + if (spt->target_status) ret = EDEV_TARGET_ERROR; else if (spt->host_status) ret = EDEV_HOST_ERROR; @@ -370,13 +400,12 @@ static inline int _sioc_sense2errno(struct sioc_pass_through *spt, char **msg) int rc = -EDEV_UNKNOWN; uint32_t sense = 0; - sense += (uint32_t) (spt->sense[2] & 0x0F) << 16; - sense += (uint32_t) spt->sense[12] << 8; - sense += (uint32_t) spt->sense[13]; + sense += (uint32_t)(spt->sense[2] & 0x0F) << 16; + sense += (uint32_t)spt->sense[12] << 8; + sense += (uint32_t)spt->sense[13]; rc = _sense2errorcode(sense, standard_table, msg, MASK_WITH_SENSE_KEY); - if (rc == -EDEV_VENDOR_UNIQUE) - rc = _sense2errorcode(sense, vendor_table, msg, MASK_WITH_SENSE_KEY); + if (rc == -EDEV_VENDOR_UNIQUE) rc = _sense2errorcode(sense, vendor_table, msg, MASK_WITH_SENSE_KEY); return rc; } @@ -393,32 +422,27 @@ static inline int sioc_paththrough(void *device, struct sioc_pass_through *spt, int sioc_rc, rc; sioc_rc = _sioc_paththrough(device, spt); - if (sioc_rc == 0){ - if (msg) - *msg = "Command successed"; + if (sioc_rc == 0) { + if (msg) *msg = "Command successed"; rc = DEVICE_GOOD; } else if (sioc_rc == -1 && spt->sense_length) { rc = _sioc_sense2errno(spt, msg); } else if (sioc_rc == -1) { /* Program Error (unexpected condition) */ - if (msg) - *msg = "Program Error (Unexpected condition)"; + if (msg) *msg = "Program Error (Unexpected condition)"; rc = -EDEV_INTERNAL_ERROR; } else if (sioc_rc == -2) { /* Cannot get sense info */ - if (msg) - *msg = "Cannot get sense information"; + if (msg) *msg = "Cannot get sense information"; rc = -EDEV_CANNOT_GET_SENSE; } else if (sioc_rc == -3) { /* Error occures within ioctl */ - if (msg) - *msg = "Driver error"; + if (msg) *msg = "Driver error"; rc = -EDEV_DRIVER_ERROR; } else { /* Program Error (unexpected condition) */ - if (msg) - *msg = "Program Error (Unexpected return code)"; - rc = -EDEV_INTERNAL_ERROR; + if (msg) *msg = "Program Error (Unexpected return code)"; + rc = -EDEV_INTERNAL_ERROR; } return rc; @@ -436,18 +460,21 @@ static inline int lin_tape_ibmtape_ioctlrc2err(void *device, int fd, struct requ if (!sense_data->err_code) { ltfsmsg(LTFS_DEBUG, 30409D); - if (msg) - *msg = "Driver Error"; + if (msg) *msg = "Driver Error"; rc = -EDEV_DRIVER_ERROR; - } - else { + } else { ltfsmsg(LTFS_DEBUG, 30406D, sense_data->key, sense_data->asc, sense_data->ascq); - ltfsmsg(LTFS_DEBUG, 30407D, sense_data->vendor[27], sense_data->vendor[28], sense_data->vendor[29], sense_data->vendor[30], - ((struct lin_tape_ibmtape *) device)->drive_serial); - - sense += (uint32_t) sense_data->key << 16; - sense += (uint32_t) sense_data->asc << 8; - sense += (uint32_t) sense_data->ascq; + ltfsmsg(LTFS_DEBUG, + 30407D, + sense_data->vendor[27], + sense_data->vendor[28], + sense_data->vendor[29], + sense_data->vendor[30], + ((struct lin_tape_ibmtape *)device)->drive_serial); + + sense += (uint32_t)sense_data->key << 16; + sense += (uint32_t)sense_data->asc << 8; + sense += (uint32_t)sense_data->ascq; rc = _sense2errorcode(sense, standard_table, msg, MASK_WITH_SENSE_KEY); @@ -455,11 +482,9 @@ static inline int lin_tape_ibmtape_ioctlrc2err(void *device, int fd, struct requ rc = _sense2errorcode(sense, vendor_table, msg, MASK_WITH_SENSE_KEY); } } - } - else { + } else { ltfsmsg(LTFS_INFO, 30412I, rc_sense); - if (msg) - *msg = "Cannot get sense information"; + if (msg) *msg = "Cannot get sense information"; rc = -EDEV_CANNOT_GET_SENSE; } @@ -470,21 +495,21 @@ static inline int lin_tape_ibmtape_ioctlrc2err(void *device, int fd, struct requ static inline bool is_expected_error(int cmd, void *param, int rc) { switch (cmd) { - case SIOC_TEST_UNIT_READY: - if (rc == -EDEV_NEED_INITIALIZE || rc == -EDEV_CONFIGURE_CHANGED) { - return true; - } - break; - case STIOC_LOCATE_16: - if (((struct set_tape_position *)param)->logical_id == TAPE_BLOCK_MAX && rc == -EDEV_EOD_DETECTED) { - return true; - } - break; - case STIOC_SET_ACTIVE_PARTITION: - if (((struct set_active_partition *)param)->logical_block_id == TAPE_BLOCK_MAX && rc == -EDEV_EOD_DETECTED) { - return true; - } - break; + case SIOC_TEST_UNIT_READY: + if (rc == -EDEV_NEED_INITIALIZE || rc == -EDEV_CONFIGURE_CHANGED) { + return true; + } + break; + case STIOC_LOCATE_16: + if (((struct set_tape_position *)param)->logical_id == TAPE_BLOCK_MAX && rc == -EDEV_EOD_DETECTED) { + return true; + } + break; + case STIOC_SET_ACTIVE_PARTITION: + if (((struct set_active_partition *)param)->logical_block_id == TAPE_BLOCK_MAX && rc == -EDEV_EOD_DETECTED) { + return true; + } + break; } return false; @@ -492,7 +517,7 @@ static inline bool is_expected_error(int cmd, void *param, int rc) static inline int _sioc_stioc_command(void *device, int cmd, char *cmd_name, void *param, char **msg) { - int fd = *((int *) device); + int fd = *((int *)device); int rc; struct request_sense sense_data; @@ -509,12 +534,10 @@ static inline int _sioc_stioc_command(void *device, int cmd, char *cmd_name, voi if (is_expected_error(cmd, param, rc)) { ltfsmsg(LTFS_DEBUG, 30410D, cmd_name, cmd, rc); + } else { + ltfsmsg(LTFS_INFO, 30408I, cmd_name, cmd, rc, errno, ((struct lin_tape_ibmtape *)device)->drive_serial); } - else { - ltfsmsg(LTFS_INFO, 30408I, cmd_name, cmd, rc, errno, ((struct lin_tape_ibmtape *) device)->drive_serial); - } - } - else { + } else { *msg = "Command succeeded"; rc = DEVICE_GOOD; } @@ -542,8 +565,7 @@ static inline bool is_dump_required_error(void *device, int ret, bool *nonforced rc = _sioc_stioc_command(device, SIOC_LOG_SENSE10_PAGE, "LOGSENSE", &log_page, &msg); ans = (rc == DEVICE_GOOD); - } - else if (err >= EDEV_NOT_READY && err < EDEV_INTERNAL_ERROR) { + } else if (err >= EDEV_NOT_READY && err < EDEV_INTERNAL_ERROR) { ans = TRUE; } @@ -557,16 +579,14 @@ static inline void lin_tape_ibmtape_process_errors(void *device, int rc, char *m struct lin_tape_ibmtape *priv = device; bool nonforced_dump = false; - if(msg != NULL) + if (msg != NULL) ltfsmsg(LTFS_INFO, 30413I, cmd, msg, rc, priv->drive_serial); else ltfsmsg(LTFS_ERR, 30414E, cmd, rc, priv->drive_serial); if (device) { - priv = (struct lin_tape_ibmtape *) device; - if ( take_dump && - !global_data.disable_auto_dump && - is_dump_required_error(device, rc, &nonforced_dump) ) + priv = (struct lin_tape_ibmtape *)device; + if (take_dump && !global_data.disable_auto_dump && is_dump_required_error(device, rc, &nonforced_dump)) lin_tape_ibmtape_get_dump(device, nonforced_dump); } } @@ -590,8 +610,7 @@ int lin_tape_ibmtape_check_lin_tape_version(void) ltfsmsg(LTFS_WARN, 30415W); } else { read(fd_version, lin_tape_version, sizeof(lin_tape_version)); - if ((tmp = strchr(lin_tape_version, '\n')) != NULL) - *tmp = '\0'; + if ((tmp = strchr(lin_tape_version, '\n')) != NULL) *tmp = '\0'; ltfsmsg(LTFS_INFO, 30416I, lin_tape_version); close(fd_version); } @@ -599,10 +618,9 @@ int lin_tape_ibmtape_check_lin_tape_version(void) (void)sscanf(base_lin_tape_version, "%d.%d.%d", &version_base[0], &version_base[1], &version_base[2]); digit = sscanf(lin_tape_version, "%d.%d.%d", &version_num[0], &version_num[1], &version_num[2]); - if (digit != 3 - || (version_num[0] < version_base[0]) - || (version_num[0] == version_base[0] && version_num[1] < version_base[1]) - || (version_num[0] == version_base[0] && version_num[1] == version_base[1] && version_num[2] < version_base[2])) { + if (digit != 3 || (version_num[0] < version_base[0]) || + (version_num[0] == version_base[0] && version_num[1] < version_base[1]) || + (version_num[0] == version_base[0] && version_num[1] == version_base[1] && version_num[2] < version_base[2])) { ltfsmsg(LTFS_ERR, 30417E); return -EDEV_DRIVER_ERROR; } @@ -621,34 +639,32 @@ int lin_tape_ibmtape_test_unit_ready(void *device) char *msg; int rc; bool take_dump = true, print_message = true; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_TUR)); - ltfsmsg(LTFS_DEBUG3, 30592D, "test unit ready", - ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg(LTFS_DEBUG3, 30592D, "test unit ready", ((struct lin_tape_ibmtape *)device)->drive_serial); rc = _sioc_stioc_command(device, SIOC_TEST_UNIT_READY, "TEST UNIT READY", NULL, &msg); if (rc != DEVICE_GOOD) { switch (rc) { - case -EDEV_NEED_INITIALIZE: - case -EDEV_CONFIGURE_CHANGED: - print_message = false; - /* Fall through */ - case -EDEV_NO_MEDIUM: - case -EDEV_BECOMING_READY: - case -EDEV_MEDIUM_MAY_BE_CHANGED: - case -EDEV_NOT_READY: - case -EDEV_NOT_REPORTABLE: - case -EDEV_MEDIUM_REMOVAL_REQ: - case -EDEV_CLEANING_IN_PROGRESS: - take_dump = false; - break; - default: - break; + case -EDEV_NEED_INITIALIZE: + case -EDEV_CONFIGURE_CHANGED: + print_message = false; + /* Fall through */ + case -EDEV_NO_MEDIUM: + case -EDEV_BECOMING_READY: + case -EDEV_MEDIUM_MAY_BE_CHANGED: + case -EDEV_NOT_READY: + case -EDEV_NOT_REPORTABLE: + case -EDEV_MEDIUM_REMOVAL_REQ: + case -EDEV_CLEANING_IN_PROGRESS: + take_dump = false; + break; + default: + break; } - if (print_message) - lin_tape_ibmtape_process_errors(device, rc, msg, "test unit ready", take_dump); + if (print_message) lin_tape_ibmtape_process_errors(device, rc, msg, "test unit ready", take_dump); } ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_TUR)); @@ -665,15 +681,14 @@ int lin_tape_ibmtape_reserve_unit(void *device) { int rc; char *msg; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_RESERVEUNIT)); - ltfsmsg(LTFS_DEBUG, 30592D, "reserve unit (6)", ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg(LTFS_DEBUG, 30592D, "reserve unit (6)", ((struct lin_tape_ibmtape *)device)->drive_serial); rc = _sioc_stioc_command(device, SIOC_RESERVE, "RESERVE", NULL, &msg); - if (rc != DEVICE_GOOD) - lin_tape_ibmtape_process_errors(device, rc, msg, "reserve unit(6)", true); + if (rc != DEVICE_GOOD) lin_tape_ibmtape_process_errors(device, rc, msg, "reserve unit(6)", true); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_RESERVEUNIT)); return rc; @@ -690,24 +705,23 @@ int lin_tape_ibmtape_release_unit(void *device) int rc; char *msg; bool take_dump = true, print_message = true; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_RELEASEUNIT)); - ltfsmsg(LTFS_DEBUG, 30592D, "release unit (6)", ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg(LTFS_DEBUG, 30592D, "release unit (6)", ((struct lin_tape_ibmtape *)device)->drive_serial); /* Invoke _ioctl to Release Unit */ rc = _sioc_stioc_command(device, SIOC_RELEASE, "RELEASE", NULL, &msg); if (rc != DEVICE_GOOD) { switch (rc) { - case -EDEV_POR_OR_BUS_RESET: - take_dump = false; - break; - default: - break; + case -EDEV_POR_OR_BUS_RESET: + take_dump = false; + break; + default: + break; } - if (print_message) - lin_tape_ibmtape_process_errors(device, rc, msg, "release unit(6)", take_dump); + if (print_message) lin_tape_ibmtape_process_errors(device, rc, msg, "release unit(6)", take_dump); } ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_RELEASEUNIT)); @@ -723,14 +737,14 @@ int lin_tape_ibmtape_release_unit(void *device) */ int lin_tape_ibmtape_get_serialnumber(void *device, char **result) { - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; CHECK_ARG_NULL(device, -LTFS_NULL_ARG); CHECK_ARG_NULL(result, -LTFS_NULL_ARG); ltfs_profiler_add_entry(priv->profiler, NULL, CHANGER_REQ_ENTER(REQ_TC_GETSER)); - *result = strdup((const char *) priv->drive_serial); - if (! *result) { + *result = strdup((const char *)priv->drive_serial); + if (!*result) { ltfsmsg(LTFS_ERR, 10001E, "lin_tape_ibmtape_get_serialnumber: result"); ltfs_profiler_add_entry(priv->profiler, NULL, CHANGER_REQ_EXIT(REQ_TC_GETSER)); return -EDEV_NO_MEMORY; @@ -749,7 +763,7 @@ int lin_tape_ibmtape_get_serialnumber(void *device, char **result) */ int lin_tape_ibmtape_get_info(void *device, struct tc_drive_info *info) { - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape*)device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; memcpy(info, &priv->info, sizeof(struct tc_drive_info)); @@ -769,17 +783,14 @@ int lin_tape_ibmtape_set_profiler(void *device, char *work_dir, bool enable) char *path; FILE *p; struct timer_info timerinfo; - struct lin_tape_ibmtape *priv = ((struct lin_tape_ibmtape *) device); + struct lin_tape_ibmtape *priv = ((struct lin_tape_ibmtape *)device); if (enable) { - if (priv->profiler) - return 0; + if (priv->profiler) return 0; - if(!work_dir) - return -LTFS_BAD_ARG; + if (!work_dir) return -LTFS_BAD_ARG; - rc = asprintf(&path, "%s/%s%s%s", work_dir, DRIVER_PROFILER_BASE, - priv->drive_serial, PROFILER_EXTENSION); + rc = asprintf(&path, "%s/%s%s%s", work_dir, DRIVER_PROFILER_BASE, priv->drive_serial, PROFILER_EXTENSION); if (rc < 0) { ltfsmsg(LTFS_ERR, 10001E, __FILE__); return -LTFS_NO_MEMORY; @@ -789,11 +800,11 @@ int lin_tape_ibmtape_set_profiler(void *device, char *work_dir, bool enable) free(path); - if (! p) + if (!p) rc = -LTFS_FILE_ERR; else { get_timer_info(&timerinfo); - fwrite((void*)&timerinfo, sizeof(timerinfo), 1, p); + fwrite((void *)&timerinfo, sizeof(timerinfo), 1, p); priv->profiler = p; rc = 0; } @@ -816,8 +827,8 @@ int lin_tape_ibmtape_set_profiler(void *device, char *work_dir, bool enable) * @param bufsize size of the buffer * @return 0 on success or negative value on error */ -int parse_logPage(const unsigned char *logdata, const uint16_t param, int *param_size, - unsigned char *buf, const size_t bufsize) +int parse_logPage( + const unsigned char *logdata, const uint16_t param, int *param_size, unsigned char *buf, const size_t bufsize) { uint16_t page_len, param_code, param_len; long i; @@ -827,15 +838,14 @@ int parse_logPage(const unsigned char *logdata, const uint16_t param, int *param while (i < page_len) { param_code = ltfs_betou16(logdata + i); - param_len = (uint16_t) logdata[i + LOG_PAGE_PARAMSIZE_OFFSET]; + param_len = (uint16_t)logdata[i + LOG_PAGE_PARAMSIZE_OFFSET]; if (param_code == param) { *param_size = param_len; if (bufsize < param_len) { ltfsmsg(LTFS_INFO, 30418I, bufsize, i + LOG_PAGE_PARAM_OFFSET); memcpy(buf, &logdata[i + LOG_PAGE_PARAM_OFFSET], bufsize); return -2; - } - else { + } else { memcpy(buf, &logdata[i + LOG_PAGE_PARAM_OFFSET], param_len); return 0; } @@ -851,16 +861,16 @@ int parse_logPage(const unsigned char *logdata, const uint16_t param, int *param * @param devname device name of the LTO tape driver * @return a pointer to the ibmtape backend on success or NULL on error */ -#define LIN_TAPE_IBMTAPE_OPT(templ,offset,value) { templ, offsetof(struct lin_tape_ibmtape_global_data, offset), value } - -static struct fuse_opt lin_tape_ibmtape_global_opts[] = { - LIN_TAPE_IBMTAPE_OPT("autodump", disable_auto_dump, 0), - LIN_TAPE_IBMTAPE_OPT("noautodump", disable_auto_dump, 1), - LIN_TAPE_IBMTAPE_OPT("scsi_lbprotect=%s", str_crc_checking, 0), - LIN_TAPE_IBMTAPE_OPT("strict_drive", strict_drive, 1), - LIN_TAPE_IBMTAPE_OPT("nostrict_drive", strict_drive, 0), - FUSE_OPT_END -}; +#define LIN_TAPE_IBMTAPE_OPT(templ, offset, value) \ + { templ, offsetof(struct lin_tape_ibmtape_global_data, offset), value } + +static struct fuse_opt lin_tape_ibmtape_global_opts[] = { LIN_TAPE_IBMTAPE_OPT("autodump", disable_auto_dump, 0), + LIN_TAPE_IBMTAPE_OPT("noautodump", disable_auto_dump, 1), + LIN_TAPE_IBMTAPE_OPT( + "scsi_lbprotect=%s", str_crc_checking, 0), + LIN_TAPE_IBMTAPE_OPT("strict_drive", strict_drive, 1), + LIN_TAPE_IBMTAPE_OPT("nostrict_drive", strict_drive, 0), + FUSE_OPT_END }; int null_parser(void *priv, const char *arg, int key, struct fuse_args *outargs) { @@ -869,7 +879,7 @@ int null_parser(void *priv, const char *arg, int key, struct fuse_args *outargs) int lin_tape_ibmtape_parse_opts(void *device, void *opt_args) { - struct fuse_args *args = (struct fuse_args *) opt_args; + struct fuse_args *args = (struct fuse_args *)opt_args; int ret; /* fuse_opt_parse can handle a NULL device parameter just fine */ @@ -908,10 +918,9 @@ int _lin_tape_ibmtape_inquiry_page(void *device, unsigned char page, struct tc_i int rc; struct inquiry_page inq_page; - if (!inq) - return -EDEV_INVALID_ARG; + if (!inq) return -EDEV_INVALID_ARG; - ltfsmsg(LTFS_DEBUG, 30593D, "inquiry", page, ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg(LTFS_DEBUG, 30593D, "inquiry", page, ((struct lin_tape_ibmtape *)device)->drive_serial); /* init value */ memset(inq_page.data, 0, sizeof(inq_page.data)); @@ -920,8 +929,7 @@ int _lin_tape_ibmtape_inquiry_page(void *device, unsigned char page, struct tc_i rc = _sioc_stioc_command(device, SIOC_INQUIRY_PAGE, "INQUIRY PAGE", &inq_page, &msg); if (rc != DEVICE_GOOD) { - if(error_handle) - lin_tape_ibmtape_process_errors(device, rc, msg, "inquiry", true); + if (error_handle) lin_tape_ibmtape_process_errors(device, rc, msg, "inquiry", true); } else { memcpy(inq->data, inq_page.data, MAX_INQ_LEN); } @@ -932,7 +940,7 @@ int _lin_tape_ibmtape_inquiry_page(void *device, unsigned char page, struct tc_i int lin_tape_ibmtape_inquiry_page(void *device, unsigned char page, struct tc_inq_page *inq) { int ret = 0; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_INQUIRYPAGE)); ret = _lin_tape_ibmtape_inquiry_page(device, page, inq, true); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_INQUIRYPAGE)); @@ -950,14 +958,14 @@ int lin_tape_ibmtape_inquiry(void *device, struct tc_inq *inq) int rc; struct inquiry_data inq_data; int vendor_length; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_INQUIRY)); memset(&inq_data, 0, sizeof(struct inquiry_data)); rc = _sioc_stioc_command(device, SIOC_INQUIRY, "INQUIRY", &inq_data, &msg); - if(rc == DEVICE_GOOD) { + if (rc == DEVICE_GOOD) { inq->devicetype = inq_data.type; inq->cmdque = inq_data.cmdque; strncpy((char *)inq->vid, (char *)inq_data.vid, 8); @@ -1001,7 +1009,7 @@ int lin_tape_ibmtape_open(const char *devname, void **handle) CHECK_ARG_NULL(handle, -LTFS_NULL_ARG); *handle = NULL; - ret = lin_tape_ibmtape_check_lin_tape_version(); + ret = lin_tape_ibmtape_check_lin_tape_version(); if (ret != DEVICE_GOOD) { return ret; } @@ -1009,7 +1017,7 @@ int lin_tape_ibmtape_open(const char *devname, void **handle) ltfsmsg(LTFS_INFO, 30423I, devname); priv = calloc(1, sizeof(struct lin_tape_ibmtape)); - if (! priv) { + if (!priv) { ltfsmsg(LTFS_ERR, 10001E, "lin_tape_ibmtape_open: device private data"); return -EDEV_NO_MEMORY; } @@ -1023,7 +1031,7 @@ int lin_tape_ibmtape_open(const char *devname, void **handle) devs = lin_tape_ibmtape_get_device_list(NULL, 0); if (devs) { buf = (struct tc_drive_info *)calloc(devs * 2, sizeof(struct tc_drive_info)); - if (! buf) { + if (!buf) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } @@ -1031,7 +1039,7 @@ int lin_tape_ibmtape_open(const char *devname, void **handle) } for (i = 0; i < info_devs; i++) { - if (! strncmp(buf[i].serial_number, devname, TAPE_SERIAL_LEN_MAX) ) { + if (!strncmp(buf[i].serial_number, devname, TAPE_SERIAL_LEN_MAX)) { devfile = strdup(buf[i].name); if (!devfile) { ltfsmsg(LTFS_ERR, 10001E, "lin_tape_ibmtape_open: devname"); @@ -1085,9 +1093,9 @@ int lin_tape_ibmtape_open(const char *devname, void **handle) /* Check the drive is supportable */ struct supported_device **cur = ibm_supported_drives; - while(*cur) { - if((! strncmp((char*)inq_data.vid, (*cur)->vendor_id, strlen((*cur)->vendor_id)) ) && - (! strncmp((char*)inq_data.pid, (*cur)->product_id, strlen((*cur)->product_id)) ) ) { + while (*cur) { + if ((!strncmp((char *)inq_data.vid, (*cur)->vendor_id, strlen((*cur)->vendor_id))) && + (!strncmp((char *)inq_data.pid, (*cur)->product_id, strlen((*cur)->product_id)))) { drive_type = (*cur)->drive_type; break; } @@ -1099,7 +1107,7 @@ int lin_tape_ibmtape_open(const char *devname, void **handle) /* Setup IBM tape specific parameters */ standard_table = standard_tape_errors; - vendor_table = ibm_tape_errors; + vendor_table = ibm_tape_errors; /* Set specific timeout value based on drive type */ ibm_tape_init_timeout(&priv->timeouts, priv->drive_type); @@ -1125,13 +1133,12 @@ int lin_tape_ibmtape_open(const char *devname, void **handle) /* Set drive serial number to private data to put it to the dump file name */ memset(priv->drive_serial, 0, sizeof(priv->drive_serial)); for (int i = 4; i < (int)sizeof(inq_page_data.data) - 1; i++) { - if (inq_page_data.data[i] == ' ' || inq_page_data.data[i] == '\0') - break; + if (inq_page_data.data[i] == ' ' || inq_page_data.data[i] == '\0') break; priv->drive_serial[i - 4] = inq_page_data.data[i]; } ltfsmsg(LTFS_INFO, 30432I, inq_data.revision); - if (! ibm_tape_is_supported_firmware(priv->drive_type, (unsigned char*)inq_data.revision)) { + if (!ibm_tape_is_supported_firmware(priv->drive_type, (unsigned char *)inq_data.revision)) { ltfsmsg(LTFS_INFO, 30430I, "firmware"); close(priv->fd); free(priv); @@ -1144,9 +1151,9 @@ int lin_tape_ibmtape_open(const char *devname, void **handle) priv->loaded = false; /* Assume tape is not loaded until a successful load call. */ priv->devname = strdup(devname); - priv->clear_by_pc = false; + priv->clear_by_pc = false; priv->force_writeperm = DEFAULT_WRITEPERM; - priv->force_readperm = DEFAULT_READPERM; + priv->force_readperm = DEFAULT_READPERM; priv->force_errortype = DEFAULT_ERRORTYPE; snprintf(priv->info.name, TAPE_DEVNAME_LEN_MAX + 1, "%s", devfile); @@ -1155,14 +1162,14 @@ int lin_tape_ibmtape_open(const char *devname, void **handle) snprintf(priv->info.serial_number, TAPE_SERIAL_LEN_MAX + 1, "%s", priv->drive_serial); snprintf(priv->info.product_rev, PRODUCT_REV_LENGTH + 1, "%s", inq_data.revision); snprintf(priv->info.product_name, PRODUCT_NAME_LENGTH + 1, "%s", generate_product_name((char *)inq_data.pid)); - priv->info.host = 0; + priv->info.host = 0; priv->info.channel = 0; - priv->info.target = 0; - priv->info.lun = -1; + priv->info.target = 0; + priv->info.lun = -1; free(devfile); - *handle = (void *) priv; + *handle = (void *)priv; return DEVICE_GOOD; } @@ -1186,17 +1193,15 @@ int lin_tape_ibmtape_reopen(const char *name, void *vstate) */ int lin_tape_ibmtape_close(void *device) { - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; struct tc_position pos; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_CLOSE)); - if (priv->loaded) - lin_tape_ibmtape_rewind(device, &pos); + if (priv->loaded) lin_tape_ibmtape_rewind(device, &pos); lin_tape_ibmtape_set_lbp(device, false); - if (priv->devname) - free(priv->devname); + if (priv->devname) free(priv->devname); close(priv->fd); @@ -1221,7 +1226,7 @@ int lin_tape_ibmtape_close(void *device) */ int lin_tape_ibmtape_close_raw(void *device) { - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_CLOSERAW)); close(priv->fd); @@ -1252,8 +1257,8 @@ int lin_tape_ibmtape_is_connected(const char *devname) int _mt_command(void *device, int cmd, char *cmd_name, int param, char **msg) { - int fd = *((int *) device); - struct mtop mt = {.mt_op = cmd,.mt_count = param }; + int fd = *((int *)device); + struct mtop mt = { .mt_op = cmd, .mt_count = param }; struct request_sense sense_data; int rc; @@ -1266,9 +1271,8 @@ int _mt_command(void *device, int cmd, char *cmd_name, int param, char **msg) ltfsmsg(LTFS_DEBUG, 30411D, cmd_name, cmd, rc); goto start; } - ltfsmsg(LTFS_INFO, 30408I, cmd_name, cmd, rc, errno, ((struct lin_tape_ibmtape *) device)->drive_serial); - } - else { + ltfsmsg(LTFS_INFO, 30408I, cmd_name, cmd, rc, errno, ((struct lin_tape_ibmtape *)device)->drive_serial); + } else { *msg = "Command succeeded"; rc = DEVICE_GOOD; } @@ -1278,8 +1282,8 @@ int _mt_command(void *device, int cmd, char *cmd_name, int param, char **msg) int _st_command(void *device, int cmd, char *cmd_name, int param, char **msg) { - int fd = *((int *) device); - struct stop st = {.st_op = cmd, .st_count = param}; + int fd = *((int *)device); + struct stop st = { .st_op = cmd, .st_count = param }; struct request_sense sense_data; int rc; @@ -1292,9 +1296,8 @@ int _st_command(void *device, int cmd, char *cmd_name, int param, char **msg) ltfsmsg(LTFS_DEBUG, 30411D, cmd_name, cmd, rc); goto start; } - ltfsmsg(LTFS_INFO, 30408I, cmd_name, cmd, rc, errno, ((struct lin_tape_ibmtape *) device)->drive_serial); - } - else { + ltfsmsg(LTFS_INFO, 30408I, cmd_name, cmd, rc, errno, ((struct lin_tape_ibmtape *)device)->drive_serial); + } else { *msg = "Command succeeded"; rc = DEVICE_GOOD; } @@ -1311,15 +1314,14 @@ int _st_command(void *device, int cmd, char *cmd_name, int param, char **msg) * @param unusual_size a flag specified unusual size or not * @return read length on success or a negative value on error */ -int lin_tape_ibmtape_read(void *device, char *buf, size_t count, struct tc_position *pos, - const bool unusual_size) +int lin_tape_ibmtape_read(void *device, char *buf, size_t count, struct tc_position *pos, const bool unusual_size) { ssize_t len = -1, read_len; int rc; bool silion = unusual_size; char *msg; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; - int fd = priv->fd; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; + int fd = priv->fd; size_t datacount = count; /* @@ -1329,7 +1331,7 @@ int lin_tape_ibmtape_read(void *device, char *buf, size_t count, struct tc_posit */ ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_READ)); - ltfsmsg(LTFS_DEBUG3, 30595D, "read", count, ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg(LTFS_DEBUG3, 30595D, "read", count, ((struct lin_tape_ibmtape *)device)->drive_serial); if (priv->force_readperm) { priv->read_counter++; @@ -1343,82 +1345,76 @@ int lin_tape_ibmtape_read(void *device, char *buf, size_t count, struct tc_posit } } - if(global_data.crc_checking) { + if (global_data.crc_checking) { datacount = count + 4; /* Never fall into this block, fail safe to adjust record length*/ - if (datacount > LINUX_MAX_BLOCK_SIZE) - datacount = LINUX_MAX_BLOCK_SIZE; + if (datacount > LINUX_MAX_BLOCK_SIZE) datacount = LINUX_MAX_BLOCK_SIZE; } read_len = read(fd, buf, datacount); if ((!silion && (size_t)read_len != datacount) || (read_len <= 0)) { struct request_sense sense_data; - rc = lin_tape_ibmtape_ioctlrc2err(device, fd , &sense_data, &msg); + rc = lin_tape_ibmtape_ioctlrc2err(device, fd, &sense_data, &msg); switch (rc) { - case -EDEV_NO_SENSE: - if (sense_data.fm) { - /* Filemark Detected */ - ltfsmsg(LTFS_DEBUG, 30436D); - rc = DEVICE_GOOD; - pos->block++; - pos->filemarks++; - len = 0; - } - else if (sense_data.ili) { - /* Illegal Length */ - int32_t diff_len; - - diff_len = (int32_t)sense_data.info; - - if (diff_len < 0) { - ltfsmsg(LTFS_INFO, 30437I, diff_len, (int)count - diff_len); // "Detect overrun condition" + case -EDEV_NO_SENSE: + if (sense_data.fm) { + /* Filemark Detected */ + ltfsmsg(LTFS_DEBUG, 30436D); + rc = DEVICE_GOOD; + pos->block++; + pos->filemarks++; + len = 0; + } else if (sense_data.ili) { + /* Illegal Length */ + int32_t diff_len; + + diff_len = (int32_t)sense_data.info; + + if (diff_len < 0) { + ltfsmsg(LTFS_INFO, 30437I, diff_len, (int)count - diff_len); // "Detect overrun condition" + rc = -EDEV_OVERRUN; + } else { + ltfsmsg(LTFS_DEBUG, 30438D, diff_len, (int)count - diff_len); // "Detect underrun condition" + len = count - diff_len; + rc = DEVICE_GOOD; + pos->block++; + } + } else if (errno == EOVERFLOW) { + ltfsmsg(LTFS_INFO, 30437I, (int)(count - read_len), (int)read_len); // "Detect overrun condition" rc = -EDEV_OVERRUN; - } - else { - ltfsmsg(LTFS_DEBUG, 30438D, diff_len, (int)count - diff_len); // "Detect underrun condition" - len = count - diff_len; + } else if ((size_t)read_len < count) { + ltfsmsg(LTFS_DEBUG, 30438D, (int)(count - read_len), (int)read_len); // "Detect underrun condition" + len = read_len; rc = DEVICE_GOOD; pos->block++; } - } - else if (errno == EOVERFLOW) { - ltfsmsg(LTFS_INFO, 30437I, (int)(count - read_len), (int)read_len); // "Detect overrun condition" - rc = -EDEV_OVERRUN; - } - else if ((size_t)read_len < count) { - ltfsmsg(LTFS_DEBUG, 30438D, (int)(count - read_len), (int)read_len); // "Detect underrun condition" - len = read_len; + break; + case -EDEV_FILEMARK_DETECTED: + ltfsmsg(LTFS_DEBUG, 30436D); rc = DEVICE_GOOD; pos->block++; - } - break; - case -EDEV_FILEMARK_DETECTED: - ltfsmsg(LTFS_DEBUG, 30436D); - rc = DEVICE_GOOD; - pos->block++; - pos->filemarks++; - len = 0; - break; + pos->filemarks++; + len = 0; + break; } if (rc != DEVICE_GOOD) { - if ((rc != -EDEV_CRYPTO_ERROR && rc != -EDEV_KEY_REQUIRED) || ((struct lin_tape_ibmtape *) device)->is_data_key_set) { - ltfsmsg(LTFS_INFO, 30408I, "READ", (int)count, rc, errno, ((struct lin_tape_ibmtape *) device)->drive_serial); + if ((rc != -EDEV_CRYPTO_ERROR && rc != -EDEV_KEY_REQUIRED) || + ((struct lin_tape_ibmtape *)device)->is_data_key_set) { + ltfsmsg(LTFS_INFO, 30408I, "READ", (int)count, rc, errno, ((struct lin_tape_ibmtape *)device)->drive_serial); lin_tape_ibmtape_process_errors(device, rc, msg, "read", true); } len = rc; } - } - else { + } else { len = silion ? read_len : (ssize_t)datacount; pos->block++; } - if(global_data.crc_checking && len > 4) { - if (priv->f_crc_check) - len = priv->f_crc_check(buf, len - 4); + if (global_data.crc_checking && len > 4) { + if (priv->f_crc_check) len = priv->f_crc_check(buf, len - 4); if (len < 0) { ltfsmsg(LTFS_ERR, 30439E); len = -EDEV_LBP_READ_ERROR; @@ -1433,39 +1429,50 @@ int lin_tape_ibmtape_read(void *device, char *buf, size_t count, struct tc_posit static inline int _handle_block_allocation_failure(void *device, struct tc_position *pos, int *retry) { - int ret = 0; - struct tc_position tmp_pos = {0, 0}; - - /* Sleep 3 secs to wait garbage correction in kernel side and retry */ - ltfsmsg(LTFS_WARN, 30440W, ++(*retry)); - sleep(3); - - ret = lin_tape_ibmtape_readpos(device, &tmp_pos); - if (ret == DEVICE_GOOD && pos->partition == tmp_pos.partition) { - if (pos->block == tmp_pos.block) { - /* No record was written on the tape */ - ltfsmsg(LTFS_INFO, 30441I, (unsigned int)tmp_pos.partition, (unsigned long long)tmp_pos.block); - ret = WRITE_RETRY; - } else if (pos->block == tmp_pos.block - 1) { - /* The record was written on the tape */ - ltfsmsg(LTFS_INFO, 30442I, - (unsigned int)pos->partition, (unsigned long long)pos->block, - (unsigned int)tmp_pos.partition, (unsigned long long)tmp_pos.block); - ret = DEVICE_GOOD; - pos->block++; - } else { - /* Unexpected position */ - ltfsmsg(LTFS_WARN, 30443W, ret, - (unsigned int)pos->partition, (unsigned long long)pos->block, - (unsigned int)tmp_pos.partition, (unsigned long long)tmp_pos.block); - ret = -EDEV_NO_MEMORY; - } - } else - ltfsmsg(LTFS_WARN, 30444W, ret, - (unsigned int)pos->partition, (unsigned long long)pos->block, - (unsigned int)tmp_pos.partition, (unsigned long long)tmp_pos.block); - - return ret; + int ret = 0; + struct tc_position tmp_pos = { 0, 0 }; + + /* Sleep 3 secs to wait garbage correction in kernel side and retry */ + ltfsmsg(LTFS_WARN, 30440W, ++(*retry)); + sleep(3); + + ret = lin_tape_ibmtape_readpos(device, &tmp_pos); + if (ret == DEVICE_GOOD && pos->partition == tmp_pos.partition) { + if (pos->block == tmp_pos.block) { + /* No record was written on the tape */ + ltfsmsg(LTFS_INFO, 30441I, (unsigned int)tmp_pos.partition, (unsigned long long)tmp_pos.block); + ret = WRITE_RETRY; + } else if (pos->block == tmp_pos.block - 1) { + /* The record was written on the tape */ + ltfsmsg(LTFS_INFO, + 30442I, + (unsigned int)pos->partition, + (unsigned long long)pos->block, + (unsigned int)tmp_pos.partition, + (unsigned long long)tmp_pos.block); + ret = DEVICE_GOOD; + pos->block++; + } else { + /* Unexpected position */ + ltfsmsg(LTFS_WARN, + 30443W, + ret, + (unsigned int)pos->partition, + (unsigned long long)pos->block, + (unsigned int)tmp_pos.partition, + (unsigned long long)tmp_pos.block); + ret = -EDEV_NO_MEMORY; + } + } else + ltfsmsg(LTFS_WARN, + 30444W, + ret, + (unsigned int)pos->partition, + (unsigned long long)pos->block, + (unsigned int)tmp_pos.partition, + (unsigned long long)tmp_pos.block); + + return ret; } /** @@ -1486,8 +1493,8 @@ int lin_tape_ibmtape_write(void *device, const char *buf, size_t count, struct t ssize_t written; char *msg = ""; struct request_sense sense_data; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; - int fd = priv->fd, retry = 0, current_errno; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; + int fd = priv->fd, retry = 0, current_errno; size_t datacount = count; /* @@ -1497,18 +1504,18 @@ int lin_tape_ibmtape_write(void *device, const char *buf, size_t count, struct t */ ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_WRITE)); - ltfsmsg(LTFS_DEBUG3, 30595D, "write", count, ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg(LTFS_DEBUG3, 30595D, "write", count, ((struct lin_tape_ibmtape *)device)->drive_serial); - if ( priv->force_writeperm ) { + if (priv->force_writeperm) { priv->write_counter++; - if ( priv->write_counter > priv->force_writeperm ) { + if (priv->write_counter > priv->force_writeperm) { ltfsmsg(LTFS_INFO, 30434I, "write"); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_WRITE)); if (priv->force_errortype) return -EDEV_NO_SENSE; else return -EDEV_WRITE_PERM; - } else if ( priv->write_counter > (priv->force_writeperm - THRESHOLD_FORCE_WRITE_NO_WRITE) ) { + } else if (priv->write_counter > (priv->force_writeperm - THRESHOLD_FORCE_WRITE_NO_WRITE)) { ltfsmsg(LTFS_INFO, 30435I); pos->block++; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_WRITE)); @@ -1518,16 +1525,16 @@ int lin_tape_ibmtape_write(void *device, const char *buf, size_t count, struct t errno = 0; /* Invoke _ioctl to Write */ - if(global_data.crc_checking) { - if (priv->f_crc_enc) - priv->f_crc_enc((void *)buf, count); + if (global_data.crc_checking) { + if (priv->f_crc_enc) priv->f_crc_enc((void *)buf, count); datacount = count + 4; } write_start: written = write(fd, buf, datacount); if ((size_t)written != datacount || errno == ENOSPC) { - ltfsmsg(LTFS_INFO, 30408I, "WRITE", (int)count, (int)written, errno, ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg( + LTFS_INFO, 30408I, "WRITE", (int)count, (int)written, errno, ((struct lin_tape_ibmtape *)device)->drive_serial); if (errno == ENOSPC) { lin_tape_ibmtape_readpos(device, pos); @@ -1546,25 +1553,25 @@ int lin_tape_ibmtape_write(void *device, const char *buf, size_t count, struct t } } else { current_errno = errno; - rc = lin_tape_ibmtape_ioctlrc2err(device, fd , &sense_data, &msg); + rc = lin_tape_ibmtape_ioctlrc2err(device, fd, &sense_data, &msg); switch (rc) { - case -EDEV_EARLY_WARNING: - ltfsmsg(LTFS_WARN, 30445W, "write"); - rc = DEVICE_GOOD; - lin_tape_ibmtape_readpos(device, pos); - pos->early_warning = true; - break; - case -EDEV_PROG_EARLY_WARNING: - ltfsmsg(LTFS_WARN, 30446W, "write"); - rc = DEVICE_GOOD; - lin_tape_ibmtape_readpos(device, pos); - pos->programmable_early_warning = true; - break; + case -EDEV_EARLY_WARNING: + ltfsmsg(LTFS_WARN, 30445W, "write"); + rc = DEVICE_GOOD; + lin_tape_ibmtape_readpos(device, pos); + pos->early_warning = true; + break; + case -EDEV_PROG_EARLY_WARNING: + ltfsmsg(LTFS_WARN, 30446W, "write"); + rc = DEVICE_GOOD; + lin_tape_ibmtape_readpos(device, pos); + pos->programmable_early_warning = true; + break; } - if (retry < MAX_WRITE_RETRY - && ((current_errno == EIO && rc == -EDEV_NO_SENSE ) || (rc == -EDEV_CONFIGURE_CHANGED) || (rc == -EDEV_TIME_STAMP_CHANGED))) { + if (retry < MAX_WRITE_RETRY && ((current_errno == EIO && rc == -EDEV_NO_SENSE) || + (rc == -EDEV_CONFIGURE_CHANGED) || (rc == -EDEV_TIME_STAMP_CHANGED))) { rc = _handle_block_allocation_failure(device, pos, &retry); if (rc == WRITE_RETRY) { errno = 0; @@ -1573,17 +1580,15 @@ int lin_tape_ibmtape_write(void *device, const char *buf, size_t count, struct t } } - if (rc != DEVICE_GOOD) - lin_tape_ibmtape_process_errors(device, rc, msg, "write", true); + if (rc != DEVICE_GOOD) lin_tape_ibmtape_process_errors(device, rc, msg, "write", true); - if (rc == -EDEV_LBP_WRITE_ERROR) - ltfsmsg(LTFS_ERR, 30447E); + if (rc == -EDEV_LBP_WRITE_ERROR) ltfsmsg(LTFS_ERR, 30447E); } else { rc = DEVICE_GOOD; pos->block++; } - ((struct lin_tape_ibmtape *) device)->dirty_acq_loss_w = true; + ((struct lin_tape_ibmtape *)device)->dirty_acq_loss_w = true; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_WRITE)); return rc; @@ -1603,49 +1608,48 @@ int lin_tape_ibmtape_writefm(void *device, size_t count, struct tc_position *pos char *msg; size_t written_count; tape_filemarks_t cur_fm = pos->filemarks; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_WRITEFM)); - ltfsmsg(LTFS_DEBUG, 30596D, "writefm", count, ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg(LTFS_DEBUG, 30596D, "writefm", count, ((struct lin_tape_ibmtape *)device)->drive_serial); start_wfm: errno = 0; - rc = _mt_command(device, (immed? MTWEOFI : MTWEOF), "WRITE FM", count, &msg); + rc = _mt_command(device, (immed ? MTWEOFI : MTWEOF), "WRITE FM", count, &msg); lin_tape_ibmtape_readpos(device, pos); if (rc != DEVICE_GOOD) { switch (rc) { - case -EDEV_EARLY_WARNING: - ltfsmsg(LTFS_WARN, 30445W, "writefm"); - rc = DEVICE_GOOD; - pos->early_warning = true; - break; - case -EDEV_PROG_EARLY_WARNING: - ltfsmsg(LTFS_WARN, 30446W, "writefm"); - rc = DEVICE_GOOD; - pos->programmable_early_warning = true; - break; - case -EDEV_CONFIGURE_CHANGED: - written_count = pos->filemarks - cur_fm; - if (count != written_count) { - /* need to write fm again */ - count = count - written_count; - cur_fm = pos->filemarks; - goto start_wfm; - } - else - rc = DEVICE_GOOD; - break; - default: - if (pos->early_warning) { + case -EDEV_EARLY_WARNING: ltfsmsg(LTFS_WARN, 30445W, "writefm"); rc = DEVICE_GOOD; - } - if (pos->programmable_early_warning) { + pos->early_warning = true; + break; + case -EDEV_PROG_EARLY_WARNING: ltfsmsg(LTFS_WARN, 30446W, "writefm"); rc = DEVICE_GOOD; - } - break; + pos->programmable_early_warning = true; + break; + case -EDEV_CONFIGURE_CHANGED: + written_count = pos->filemarks - cur_fm; + if (count != written_count) { + /* need to write fm again */ + count = count - written_count; + cur_fm = pos->filemarks; + goto start_wfm; + } else + rc = DEVICE_GOOD; + break; + default: + if (pos->early_warning) { + ltfsmsg(LTFS_WARN, 30445W, "writefm"); + rc = DEVICE_GOOD; + } + if (pos->programmable_early_warning) { + ltfsmsg(LTFS_WARN, 30446W, "writefm"); + rc = DEVICE_GOOD; + } + break; } if (rc != DEVICE_GOOD) { @@ -1676,10 +1680,10 @@ int lin_tape_ibmtape_rewind(void *device, struct tc_position *pos) { int rc; char *msg; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_REWIND)); - ltfsmsg(LTFS_DEBUG, 30592D, "rewind", ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg(LTFS_DEBUG, 30592D, "rewind", ((struct lin_tape_ibmtape *)device)->drive_serial); rc = _mt_command(device, MTREW, "REWIND", 0, &msg); lin_tape_ibmtape_readpos(device, pos); @@ -1688,11 +1692,11 @@ int lin_tape_ibmtape_rewind(void *device, struct tc_position *pos) lin_tape_ibmtape_process_errors(device, rc, msg, "rewind", true); } - priv->clear_by_pc = false; + priv->clear_by_pc = false; priv->force_writeperm = DEFAULT_WRITEPERM; - priv->force_readperm = DEFAULT_READPERM; + priv->force_readperm = DEFAULT_READPERM; priv->write_counter = 0; - priv->read_counter = 0; + priv->read_counter = 0; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_REWIND)); return rc; @@ -1711,11 +1715,15 @@ int lin_tape_ibmtape_locate(void *device, struct tc_position dest, struct tc_pos char *msg; struct set_active_partition set_part; struct set_tape_position setpos; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_LOCATE)); - ltfsmsg(LTFS_DEBUG, 30597D, "locate", (unsigned long long)dest.partition, - (unsigned long long)dest.block, ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg(LTFS_DEBUG, + 30597D, + "locate", + (unsigned long long)dest.partition, + (unsigned long long)dest.block, + ((struct lin_tape_ibmtape *)device)->drive_serial); if (pos->partition != dest.partition) { memset(&set_part, 0, sizeof(struct set_active_partition)); @@ -1723,11 +1731,11 @@ int lin_tape_ibmtape_locate(void *device, struct tc_position dest, struct tc_pos set_part.logical_block_id = dest.block; if (priv->clear_by_pc) { - priv->clear_by_pc = false; + priv->clear_by_pc = false; priv->force_writeperm = DEFAULT_WRITEPERM; - priv->force_readperm = DEFAULT_READPERM; + priv->force_readperm = DEFAULT_READPERM; priv->write_counter = 0; - priv->read_counter = 0; + priv->read_counter = 0; } rc = _sioc_stioc_command(device, STIOC_SET_ACTIVE_PARTITION, "LOCATE(PART)", &set_part, &msg); @@ -1745,8 +1753,7 @@ int lin_tape_ibmtape_locate(void *device, struct tc_position dest, struct tc_pos rc = DEVICE_GOOD; } - if (rc != DEVICE_GOOD) - lin_tape_ibmtape_process_errors(device, rc, msg, "locate", true); + if (rc != DEVICE_GOOD) lin_tape_ibmtape_process_errors(device, rc, msg, "locate", true); } lin_tape_ibmtape_readpos(device, pos); @@ -1768,33 +1775,45 @@ int lin_tape_ibmtape_space(void *device, size_t count, TC_SPACE_TYPE type, struc int cmd; int rc; char *msg; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_SPACE)); switch (type) { case TC_SPACE_EOD: - ltfsmsg(LTFS_DEBUG, 30592D, "space to EOD", ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg(LTFS_DEBUG, 30592D, "space to EOD", ((struct lin_tape_ibmtape *)device)->drive_serial); cmd = MTEOM; count = 0; break; case TC_SPACE_FM_F: - ltfsmsg(LTFS_DEBUG, 30594D, "space forward file marks", (unsigned long long)count, - ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg(LTFS_DEBUG, + 30594D, + "space forward file marks", + (unsigned long long)count, + ((struct lin_tape_ibmtape *)device)->drive_serial); cmd = MTFSF; break; case TC_SPACE_FM_B: - ltfsmsg(LTFS_DEBUG, 30594D, "space back file marks", (unsigned long long)count, - ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg(LTFS_DEBUG, + 30594D, + "space back file marks", + (unsigned long long)count, + ((struct lin_tape_ibmtape *)device)->drive_serial); cmd = MTBSF; break; case TC_SPACE_F: - ltfsmsg(LTFS_DEBUG, 30594D, "space forward records", (unsigned long long)count, - ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg(LTFS_DEBUG, + 30594D, + "space forward records", + (unsigned long long)count, + ((struct lin_tape_ibmtape *)device)->drive_serial); cmd = MTFSR; break; case TC_SPACE_B: - ltfsmsg(LTFS_DEBUG, 30594D, "space back records", (unsigned long long)count, - ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg(LTFS_DEBUG, + 30594D, + "space back records", + (unsigned long long)count, + ((struct lin_tape_ibmtape *)device)->drive_serial); cmd = MTBSR; break; default: @@ -1829,7 +1848,7 @@ int lin_tape_ibmtape_long_erase(void *device) unsigned char cdb[6]; unsigned char sense[MAXSENSE]; char *msg; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; memset(&spt, 0, sizeof(spt)); memset(cdb, 0, sizeof(cdb)); @@ -1842,13 +1861,12 @@ int lin_tape_ibmtape_long_erase(void *device) /* Prepare CDB */ spt.cmd_length = sizeof(cdb); spt.cdb = cdb; - spt.cdb[0] = 0x19; /* SCSI erase code */ - spt.cdb[1] = 0x03; /* set long bit and immed bit */ + spt.cdb[0] = 0x19; /* SCSI erase code */ + spt.cdb[1] = 0x03; /* set long bit and immed bit */ spt.data_direction = SCSI_DATA_NONE; spt.timeout = ibm_tape_get_timeout(priv->timeouts, spt.cdb[0]); - if (spt.timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (spt.timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Prepare sense buffer */ spt.sense_length = sizeof(sense); @@ -1856,8 +1874,7 @@ int lin_tape_ibmtape_long_erase(void *device) /* Invoke _ioctl to send a page */ rc = sioc_paththrough(device, &spt, &msg); - if (rc != DEVICE_GOOD) - lin_tape_ibmtape_process_errors(device, rc, msg, "long erase", true); + if (rc != DEVICE_GOOD) lin_tape_ibmtape_process_errors(device, rc, msg, "long erase", true); return rc; } @@ -1873,15 +1890,15 @@ int lin_tape_ibmtape_erase(void *device, struct tc_position *pos, bool long_eras { int rc; char *msg; - int fd = *((int *) device); + int fd = *((int *)device); struct request_sense sense_data; int progress; struct ltfs_timespec ts_start, ts_now; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_ERASE)); if (long_erase) { - ltfsmsg(LTFS_DEBUG, 30592D, "long erase", ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg(LTFS_DEBUG, 30592D, "long erase", ((struct lin_tape_ibmtape *)device)->drive_serial); get_current_timespec(&ts_start); rc = lin_tape_ibmtape_long_erase(device); @@ -1891,30 +1908,27 @@ int lin_tape_ibmtape_erase(void *device, struct tc_position *pos, bool long_eras } while (true) { - rc = lin_tape_ibmtape_ioctlrc2err(device, fd , &sense_data, &msg); + rc = lin_tape_ibmtape_ioctlrc2err(device, fd, &sense_data, &msg); if (rc != -EDEV_OPERATION_IN_PROGRESS) { /* Erase operation is NOT in progress */ - if (rc == -EDEV_NO_SENSE) - rc = DEVICE_GOOD; + if (rc == -EDEV_NO_SENSE) rc = DEVICE_GOOD; break; } if (IS_ENTERPRISE(priv->drive_type)) { get_current_timespec(&ts_now); - ltfsmsg(LTFS_INFO, 30451I, (int)(ts_now.tv_sec - ts_start.tv_sec)/60); - } - else { - progress = (int)(sense_data.field[0] & 0xFF)<<8; + ltfsmsg(LTFS_INFO, 30451I, (int)(ts_now.tv_sec - ts_start.tv_sec) / 60); + } else { + progress = (int)(sense_data.field[0] & 0xFF) << 8; progress += (int)(sense_data.field[1] & 0xFF); - ltfsmsg(LTFS_INFO, 30452I, progress*100/0xFFFF); + ltfsmsg(LTFS_INFO, 30452I, progress * 100 / 0xFFFF); } sleep(60); } - } - else { - ltfsmsg(LTFS_DEBUG, 30592D, "erase", ((struct lin_tape_ibmtape *) device)->drive_serial); + } else { + ltfsmsg(LTFS_DEBUG, 30592D, "erase", ((struct lin_tape_ibmtape *)device)->drive_serial); rc = _st_command(device, STERASE, "ERASE", 1, &msg); // param=1 means invoking short erase. } @@ -1939,42 +1953,38 @@ int _lin_tape_ibmtape_load_unload(void *device, bool load, struct tc_position *p int rc; char *msg; bool take_dump = true; - struct lin_tape_ibmtape *priv = ((struct lin_tape_ibmtape *) device); + struct lin_tape_ibmtape *priv = ((struct lin_tape_ibmtape *)device); if (load) { rc = _mt_command(device, MTLOAD, "LOAD", 0, &msg); - } - else { + } else { rc = _mt_command(device, MTUNLOAD, "UNLOAD", 0, &msg); } if (rc != DEVICE_GOOD) { switch (rc) { - case -EDEV_LOAD_UNLOAD_ERROR: - if (priv->loadfailed) { + case -EDEV_LOAD_UNLOAD_ERROR: + if (priv->loadfailed) { + take_dump = false; + } else { + priv->loadfailed = true; + } + break; + case -EDEV_NO_MEDIUM: + case -EDEV_BECOMING_READY: + case -EDEV_MEDIUM_MAY_BE_CHANGED: take_dump = false; - } - else { - priv->loadfailed = true; - } - break; - case -EDEV_NO_MEDIUM: - case -EDEV_BECOMING_READY: - case -EDEV_MEDIUM_MAY_BE_CHANGED: - take_dump = false; - break; - default: - break; + break; + default: + break; } lin_tape_ibmtape_readpos(device, pos); lin_tape_ibmtape_process_errors(device, rc, msg, "load unload", take_dump); - } - else { + } else { if (load) { lin_tape_ibmtape_readpos(device, pos); priv->tape_alert = 0; - } - else { + } else { pos->partition = 0; pos->block = 0; priv->tape_alert = 0; @@ -1989,7 +1999,7 @@ int lin_tape_ibmtape_load(void *device, struct tc_position *pos) { int rc; unsigned char buf[TC_MP_SUPPORTEDPAGE_SIZE]; - struct lin_tape_ibmtape *priv = ((struct lin_tape_ibmtape *) device); + struct lin_tape_ibmtape *priv = ((struct lin_tape_ibmtape *)device); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_LOAD)); ltfsmsg(LTFS_DEBUG, 30592D, "load", priv->drive_serial); @@ -2009,14 +2019,14 @@ int lin_tape_ibmtape_load(void *device, struct tc_position *pos) return rc; } - priv->loaded = true; - priv->is_worm = false; + priv->loaded = true; + priv->is_worm = false; - priv->clear_by_pc = false; + priv->clear_by_pc = false; priv->force_writeperm = DEFAULT_WRITEPERM; - priv->force_readperm = DEFAULT_READPERM; + priv->force_readperm = DEFAULT_READPERM; priv->write_counter = 0; - priv->read_counter = 0; + priv->read_counter = 0; priv->cart_type = buf[2]; priv->density_code = buf[8]; @@ -2027,8 +2037,7 @@ int lin_tape_ibmtape_load(void *device, struct tc_position *pos) } rc = ibm_tape_is_supported_tape(priv->cart_type, priv->density_code, &(priv->is_worm)); - if(rc == -LTFS_UNSUPPORTED_MEDIUM) - ltfsmsg(LTFS_INFO, 30455I, priv->cart_type, priv->density_code); + if (rc == -LTFS_UNSUPPORTED_MEDIUM) ltfsmsg(LTFS_INFO, 30455I, priv->cart_type, priv->density_code); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_LOAD)); return rc; @@ -2043,18 +2052,18 @@ int lin_tape_ibmtape_load(void *device, struct tc_position *pos) int lin_tape_ibmtape_unload(void *device, struct tc_position *pos) { int rc; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_UNLOAD)); - ltfsmsg(LTFS_DEBUG, 30592D, "unload", ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg(LTFS_DEBUG, 30592D, "unload", ((struct lin_tape_ibmtape *)device)->drive_serial); rc = _lin_tape_ibmtape_load_unload(device, false, pos); - priv->clear_by_pc = false; + priv->clear_by_pc = false; priv->force_writeperm = DEFAULT_WRITEPERM; - priv->force_readperm = DEFAULT_READPERM; + priv->force_readperm = DEFAULT_READPERM; priv->write_counter = 0; - priv->read_counter = 0; + priv->read_counter = 0; if (rc < 0) { ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_UNLOAD)); @@ -2072,7 +2081,7 @@ int lin_tape_ibmtape_get_next_block_to_xfer(void *device, struct tc_position *po int rc; char *msg; struct read_tape_position rp; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_READPOS)); memset(&rp, 0, sizeof(struct read_tape_position)); @@ -2084,8 +2093,7 @@ int lin_tape_ibmtape_get_next_block_to_xfer(void *device, struct tc_position *po if (rc == DEVICE_GOOD) { pos->partition = rp.rp_data.rp_extended.active_partition; pos->block = ltfs_betou64(rp.rp_data.rp_extended.last_logical_obj_position); - } - else { + } else { lin_tape_ibmtape_process_errors(device, rc, msg, "get block in buf", true); } @@ -2104,7 +2112,7 @@ int lin_tape_ibmtape_readpos(void *device, struct tc_position *pos) int rc; char *msg; struct read_tape_position rp; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_READPOS)); memset(&rp, 0, sizeof(struct read_tape_position)); @@ -2114,17 +2122,20 @@ int lin_tape_ibmtape_readpos(void *device, struct tc_position *pos) rc = _sioc_stioc_command(device, STIOC_READ_POSITION_EX, "READPOS", &rp, &msg); if (rc == DEVICE_GOOD) { - pos->early_warning = rp.rp_data.rp_long.eop? true : false; - pos->programmable_early_warning = rp.rp_data.rp_long.bpew? true : false; + pos->early_warning = rp.rp_data.rp_long.eop ? true : false; + pos->programmable_early_warning = rp.rp_data.rp_long.bpew ? true : false; pos->partition = rp.rp_data.rp_long.active_partition; pos->block = ltfs_betou64(rp.rp_data.rp_long.logical_obj_number); pos->filemarks = ltfs_betou64(rp.rp_data.rp_long.logical_file_id); - ltfsmsg(LTFS_DEBUG, 30598D, "readpos", (unsigned long long)pos->partition, - (unsigned long long)pos->block, (unsigned long long)pos->filemarks, - ((struct lin_tape_ibmtape *) device)->drive_serial); - } - else { + ltfsmsg(LTFS_DEBUG, + 30598D, + "readpos", + (unsigned long long)pos->partition, + (unsigned long long)pos->block, + (unsigned long long)pos->filemarks, + ((struct lin_tape_ibmtape *)device)->drive_serial); + } else { lin_tape_ibmtape_process_errors(device, rc, msg, "readpos", true); } @@ -2141,7 +2152,8 @@ int lin_tape_ibmtape_readpos(void *device, struct tc_position *pos) * @param vol_mam_uuid Volume UUID, unused by libtlfs (HPE extension) * @return 0 on success or a negative value on error */ -int lin_tape_ibmtape_format(void *device, TC_FORMAT_TYPE format, const char *vol_name, const char *barcode_name, const char *vol_mam_uuid) +int lin_tape_ibmtape_format( + void *device, TC_FORMAT_TYPE format, const char *vol_name, const char *barcode_name, const char *vol_mam_uuid) { struct sioc_pass_through spt; int rc, aux_rc; @@ -2149,12 +2161,12 @@ int lin_tape_ibmtape_format(void *device, TC_FORMAT_TYPE format, const char *vol unsigned char sense[MAXSENSE]; unsigned char buf[TC_MP_SUPPORTEDPAGE_SIZE]; char *msg; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_FORMAT)); - ltfsmsg(LTFS_DEBUG, 30592D, "format", ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg(LTFS_DEBUG, 30592D, "format", ((struct lin_tape_ibmtape *)device)->drive_serial); - if ((unsigned char) format >= (unsigned char) TC_FORMAT_MAX) { + if ((unsigned char)format >= (unsigned char)TC_FORMAT_MAX) { ltfsmsg(LTFS_INFO, 30456I, format); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_FORMAT)); return -1; @@ -2171,13 +2183,12 @@ int lin_tape_ibmtape_format(void *device, TC_FORMAT_TYPE format, const char *vol /* Prepare CDB */ spt.cmd_length = sizeof(cdb); spt.cdb = cdb; - spt.cdb[0] = 0x04; /* SCSI medium format code */ - spt.cdb[2] = (unsigned char) format; + spt.cdb[0] = 0x04; /* SCSI medium format code */ + spt.cdb[2] = (unsigned char)format; spt.data_direction = SCSI_DATA_NONE; spt.timeout = ibm_tape_get_timeout(priv->timeouts, spt.cdb[0]); - if (spt.timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (spt.timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Prepare sense buffer */ spt.sense_length = sizeof(sense); @@ -2185,8 +2196,7 @@ int lin_tape_ibmtape_format(void *device, TC_FORMAT_TYPE format, const char *vol /* Invoke _ioctl to send a page */ rc = sioc_paththrough(device, &spt, &msg); - if (rc != DEVICE_GOOD) - lin_tape_ibmtape_process_errors(device, rc, msg, "format", true); + if (rc != DEVICE_GOOD) lin_tape_ibmtape_process_errors(device, rc, msg, "format", true); /* Check Cartridge type */ aux_rc = lin_tape_ibmtape_modesense(device, TC_MP_SUPPORTEDPAGE, TC_MP_PC_CURRENT, 0x00, buf, sizeof(buf)); @@ -2209,17 +2219,21 @@ int lin_tape_ibmtape_format(void *device, TC_FORMAT_TYPE format, const char *vol */ #define MAX_UINT16 (0x0000FFFF) -int lin_tape_ibmtape_logsense(void *device, const uint8_t page, const uint8_t subpage, - unsigned char *buf, const size_t size) +int lin_tape_ibmtape_logsense( + void *device, const uint8_t page, const uint8_t subpage, unsigned char *buf, const size_t size) { int rc; char *msg; struct log_sense10_page log_page; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_LOGSENSE)); - ltfsmsg(LTFS_DEBUG3, 30597D, "logsense", (unsigned long long)page, (unsigned long long)subpage, - ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg(LTFS_DEBUG3, + 30597D, + "logsense", + (unsigned long long)page, + (unsigned long long)subpage, + ((struct lin_tape_ibmtape *)device)->drive_serial); log_page.page_code = page; log_page.subpage_code = subpage; @@ -2257,7 +2271,7 @@ int lin_tape_ibmtape_remaining_capacity(void *device, struct tc_remaining_cap *c int offset; uint32_t logcap; int rc; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_REMAINCAP)); if (IS_LTO(priv->drive_type) && (DRIVE_GEN(priv->drive_type) == 0x05)) { @@ -2269,9 +2283,8 @@ int lin_tape_ibmtape_remaining_capacity(void *device, struct tc_remaining_cap *c return rc; } - for(i = TAPECAP_REMAIN_0; i < TAPECAP_SIZE; i++) { - if (parse_logPage(logdata, (uint16_t) i, ¶m_size, buf, sizeof(buf)) - || param_size != sizeof(uint32_t)) { + for (i = TAPECAP_REMAIN_0; i < TAPECAP_SIZE; i++) { + if (parse_logPage(logdata, (uint16_t)i, ¶m_size, buf, sizeof(buf)) || param_size != sizeof(uint32_t)) { ltfsmsg(LTFS_INFO, 30458I); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_REMAINCAP)); return -EDEV_NO_MEMORY; @@ -2280,27 +2293,26 @@ int lin_tape_ibmtape_remaining_capacity(void *device, struct tc_remaining_cap *c logcap = ltfs_betou32(buf); switch (i) { - case TAPECAP_REMAIN_0: - cap->remaining_p0 = logcap; - break; - case TAPECAP_REMAIN_1: - cap->remaining_p1 = logcap; - break; - case TAPECAP_MAX_0: - cap->max_p0 = logcap; - break; - case TAPECAP_MAX_1: - cap->max_p1 = logcap; - break; - default: - ltfsmsg(LTFS_INFO, 30459I, i); - ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_REMAINCAP)); - return -EDEV_INVALID_ARG; - break; + case TAPECAP_REMAIN_0: + cap->remaining_p0 = logcap; + break; + case TAPECAP_REMAIN_1: + cap->remaining_p1 = logcap; + break; + case TAPECAP_MAX_0: + cap->max_p0 = logcap; + break; + case TAPECAP_MAX_1: + cap->max_p1 = logcap; + break; + default: + ltfsmsg(LTFS_INFO, 30459I, i); + ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_REMAINCAP)); + return -EDEV_INVALID_ARG; + break; } } - } - else { + } else { /* Issue LogPage 0x17 */ rc = lin_tape_ibmtape_logsense(device, LOG_VOLUMESTATS, (uint8_t)0, logdata, LOGSENSEPAGE); if (rc) { @@ -2348,16 +2360,23 @@ int lin_tape_ibmtape_remaining_capacity(void *device, struct tc_remaining_cap *c cap->remaining_p1 = (cap->remaining_p1 * 1000 * 1000) >> 20; } - ltfsmsg(LTFS_DEBUG3, 30597D, "capacity part0", (unsigned long long)cap->remaining_p0, - (unsigned long long)cap->max_p0, ((struct lin_tape_ibmtape *) device)->drive_serial); - ltfsmsg(LTFS_DEBUG3, 30597D, "capacity part1", (unsigned long long)cap->remaining_p1, - (unsigned long long)cap->max_p1, ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg(LTFS_DEBUG3, + 30597D, + "capacity part0", + (unsigned long long)cap->remaining_p0, + (unsigned long long)cap->max_p0, + ((struct lin_tape_ibmtape *)device)->drive_serial); + ltfsmsg(LTFS_DEBUG3, + 30597D, + "capacity part1", + (unsigned long long)cap->remaining_p1, + (unsigned long long)cap->max_p1, + ((struct lin_tape_ibmtape *)device)->drive_serial); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_REMAINCAP)); return 0; } - /** * Get mode data * @param device a pointer to the ibmtape backend @@ -2367,18 +2386,22 @@ int lin_tape_ibmtape_remaining_capacity(void *device, struct tc_remaining_cap *c * @param size length of buf * @return 0 on success or a negative value on error */ -int lin_tape_ibmtape_modesense(void *device, const uint8_t page, const TC_MP_PC_TYPE pc, const uint8_t subpage, - unsigned char *buf, const size_t size) +int lin_tape_ibmtape_modesense(void *device, + const uint8_t page, + const TC_MP_PC_TYPE pc, + const uint8_t subpage, + unsigned char *buf, + const size_t size) { struct sioc_pass_through spt; int rc; unsigned char cdb[10]; unsigned char sense[MAXSENSE]; char *msg; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_MODESENSE)); - ltfsmsg(LTFS_DEBUG3, 30593D, "modesense", page, ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg(LTFS_DEBUG3, 30593D, "modesense", page, ((struct lin_tape_ibmtape *)device)->drive_serial); memset(&spt, 0, sizeof(spt)); memset(cdb, 0, sizeof(cdb)); @@ -2394,15 +2417,14 @@ int lin_tape_ibmtape_modesense(void *device, const uint8_t page, const TC_MP_PC_ /* Prepare CDB */ spt.cmd_length = sizeof(cdb); spt.cdb = cdb; - spt.cdb[0] = 0x5a; /* SCSI mode sense code */ + spt.cdb[0] = 0x5a; /* SCSI mode sense code */ spt.cdb[2] = pc | page; spt.cdb[3] = subpage; ltfs_u16tobe(spt.cdb + 7, spt.buffer_length); spt.data_direction = SCSI_DATA_IN; spt.timeout = ibm_tape_get_timeout(priv->timeouts, spt.cdb[0]); - if (spt.timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (spt.timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Prepare sense buffer */ spt.sense_length = sizeof(sense); @@ -2410,8 +2432,7 @@ int lin_tape_ibmtape_modesense(void *device, const uint8_t page, const TC_MP_PC_ /* Invoke _ioctl to modesense */ rc = sioc_paththrough(device, &spt, &msg); - if (rc != DEVICE_GOOD) - lin_tape_ibmtape_process_errors(device, rc, msg, "modesense", true); + if (rc != DEVICE_GOOD) lin_tape_ibmtape_process_errors(device, rc, msg, "modesense", true); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_MODESENSE)); return rc; @@ -2431,10 +2452,10 @@ int lin_tape_ibmtape_modeselect(void *device, unsigned char *buf, const size_t s unsigned char cdb[10]; unsigned char sense[MAXSENSE]; char *msg; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_MODESELECT)); - ltfsmsg(LTFS_DEBUG3, 30592D, "modeselect", ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg(LTFS_DEBUG3, 30592D, "modeselect", ((struct lin_tape_ibmtape *)device)->drive_serial); memset(&spt, 0, sizeof(spt)); memset(cdb, 0, sizeof(cdb)); @@ -2447,13 +2468,12 @@ int lin_tape_ibmtape_modeselect(void *device, unsigned char *buf, const size_t s /* Prepare CDB */ spt.cmd_length = sizeof(cdb); spt.cdb = cdb; - spt.cdb[0] = 0x55; /* SCSI mode select code */ + spt.cdb[0] = 0x55; /* SCSI mode select code */ ltfs_u16tobe(spt.cdb + 7, spt.buffer_length); spt.data_direction = SCSI_DATA_OUT; spt.timeout = ibm_tape_get_timeout(priv->timeouts, spt.cdb[0]); - if (spt.timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (spt.timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Prepare sense buffer */ spt.sense_length = sizeof(sense); @@ -2462,11 +2482,9 @@ int lin_tape_ibmtape_modeselect(void *device, unsigned char *buf, const size_t s /* Invoke _ioctl to modeselect */ rc = sioc_paththrough(device, &spt, &msg); if (rc != DEVICE_GOOD) { - if (rc == -EDEV_MODE_PARAMETER_ROUNDED) - rc = DEVICE_GOOD; + if (rc == -EDEV_MODE_PARAMETER_ROUNDED) rc = DEVICE_GOOD; - if (rc != DEVICE_GOOD) - lin_tape_ibmtape_process_errors(device, rc, msg, "modeselect", true); + if (rc != DEVICE_GOOD) lin_tape_ibmtape_process_errors(device, rc, msg, "modeselect", true); } ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_MODESELECT)); @@ -2482,10 +2500,10 @@ int lin_tape_ibmtape_prevent_medium_removal(void *device) { int rc; char *msg; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_PREVENTM)); - ltfsmsg(LTFS_DEBUG, 30592D, "prevent medium removal", ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg(LTFS_DEBUG, 30592D, "prevent medium removal", ((struct lin_tape_ibmtape *)device)->drive_serial); rc = _sioc_stioc_command(device, STIOC_PREVENT_MEDIUM_REMOVAL, "PREVENT MED REMOVAL", NULL, &msg); @@ -2506,10 +2524,10 @@ int lin_tape_ibmtape_allow_medium_removal(void *device) { int rc; char *msg; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_ALLOWMREM)); - ltfsmsg(LTFS_DEBUG, 30592D, "allow medium removal", ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg(LTFS_DEBUG, 30592D, "allow medium removal", ((struct lin_tape_ibmtape *)device)->drive_serial); rc = _sioc_stioc_command(device, STIOC_ALLOW_MEDIUM_REMOVAL, "ALLOW MED REMOVAL", NULL, &msg); @@ -2530,20 +2548,24 @@ int lin_tape_ibmtape_allow_medium_removal(void *device) * @param size length of the buffer * @return 0 on success or a negative value on error */ -int lin_tape_ibmtape_read_attribute(void *device, const tape_partition_t part, const uint16_t id, - unsigned char *buf, const size_t size) +int lin_tape_ibmtape_read_attribute( + void *device, const tape_partition_t part, const uint16_t id, unsigned char *buf, const size_t size) { struct sioc_pass_through spt; int rc; unsigned char cdb[16]; unsigned char sense[MAXSENSE]; char *msg; - bool take_dump= true; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + bool take_dump = true; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_READATTR)); - ltfsmsg(LTFS_DEBUG3, 30597D, "readattr", (unsigned long long)part, - (unsigned long long)id, ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg(LTFS_DEBUG3, + 30597D, + "readattr", + (unsigned long long)part, + (unsigned long long)id, + ((struct lin_tape_ibmtape *)device)->drive_serial); memset(&spt, 0, sizeof(spt)); memset(cdb, 0, sizeof(cdb)); @@ -2565,16 +2587,15 @@ int lin_tape_ibmtape_read_attribute(void *device, const tape_partition_t part, c /* Prepare CDB */ spt.cmd_length = sizeof(cdb); spt.cdb = cdb; - spt.cdb[0] = 0x8C; /* 0x8C SCSI read Attribute code */ - spt.cdb[1] = 0x00; /* Service Action 0x00: VALUE */ + spt.cdb[0] = 0x8C; /* 0x8C SCSI read Attribute code */ + spt.cdb[1] = 0x00; /* Service Action 0x00: VALUE */ spt.cdb[7] = part; ltfs_u16tobe(spt.cdb + 8, id); ltfs_u32tobe(spt.cdb + 10, spt.buffer_length); spt.data_direction = SCSI_DATA_IN; spt.timeout = ibm_tape_get_timeout(priv->timeouts, spt.cdb[0]); - if (spt.timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (spt.timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Prepare sense buffer */ spt.sense_length = sizeof(sense); @@ -2583,20 +2604,13 @@ int lin_tape_ibmtape_read_attribute(void *device, const tape_partition_t part, c /* Invoke _ioctl to Read Attribute */ rc = sioc_paththrough(device, &spt, &msg); if (rc != DEVICE_GOOD) { - if ( rc == -EDEV_INVALID_FIELD_CDB ) - take_dump = false; + if (rc == -EDEV_INVALID_FIELD_CDB) take_dump = false; lin_tape_ibmtape_process_errors(device, rc, msg, "readattr", take_dump); - if (rc < 0 && - id != TC_MAM_PAGE_COHERENCY && - id != TC_MAM_APP_VENDER && - id != TC_MAM_APP_NAME && - id != TC_MAM_APP_VERSION && - id != TC_MAM_USER_MEDIUM_LABEL && - id != TC_MAM_TEXT_LOCALIZATION_IDENTIFIER && - id != TC_MAM_BARCODE && - id != TC_MAM_APP_FORMAT_VERSION) + if (rc < 0 && id != TC_MAM_PAGE_COHERENCY && id != TC_MAM_APP_VENDER && id != TC_MAM_APP_NAME && + id != TC_MAM_APP_VERSION && id != TC_MAM_USER_MEDIUM_LABEL && id != TC_MAM_TEXT_LOCALIZATION_IDENTIFIER && + id != TC_MAM_BARCODE && id != TC_MAM_APP_FORMAT_VERSION) ltfsmsg(LTFS_INFO, 30460I, rc); } else { if (size == MAXMAM_SIZE) { @@ -2623,19 +2637,21 @@ int lin_tape_ibmtape_read_attribute(void *device, const tape_partition_t part, c * @param size length of the buffer * @return 0 on success or a negative value on error */ -int lin_tape_ibmtape_write_attribute(void *device, const tape_partition_t part, const unsigned char *buf, - const size_t size) +int lin_tape_ibmtape_write_attribute(void *device, + const tape_partition_t part, + const unsigned char *buf, + const size_t size) { struct sioc_pass_through spt; int rc; unsigned char cdb[16]; unsigned char sense[MAXSENSE]; char *msg; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_WRITEATTR)); - ltfsmsg(LTFS_DEBUG3, 30594D, "writeattr", (unsigned long long)part, - ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg( + LTFS_DEBUG3, 30594D, "writeattr", (unsigned long long)part, ((struct lin_tape_ibmtape *)device)->drive_serial); memset(&spt, 0, sizeof(spt)); memset(cdb, 0, sizeof(cdb)); @@ -2655,15 +2671,14 @@ int lin_tape_ibmtape_write_attribute(void *device, const tape_partition_t part, /* Prepare CDB */ spt.cmd_length = sizeof(cdb); spt.cdb = cdb; - spt.cdb[0] = 0x8D; /* SCSI Write Attribute code */ - spt.cdb[1] = 0x01; /* Write through bit on */ + spt.cdb[0] = 0x8D; /* SCSI Write Attribute code */ + spt.cdb[1] = 0x01; /* Write through bit on */ spt.cdb[7] = part; ltfs_u32tobe(spt.cdb + 10, spt.buffer_length); spt.data_direction = SCSI_DATA_OUT; spt.timeout = ibm_tape_get_timeout(priv->timeouts, spt.cdb[0]); - if (spt.timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (spt.timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Prepare sense buffer */ spt.sense_length = sizeof(sense); @@ -2671,8 +2686,7 @@ int lin_tape_ibmtape_write_attribute(void *device, const tape_partition_t part, /* Invoke _ioctl to Write Attribute */ rc = sioc_paththrough(device, &spt, &msg); - if (rc != DEVICE_GOOD) - lin_tape_ibmtape_process_errors(device, rc, msg, "writeattr", true); + if (rc != DEVICE_GOOD) lin_tape_ibmtape_process_errors(device, rc, msg, "writeattr", true); free(spt.buffer); @@ -2685,11 +2699,15 @@ int lin_tape_ibmtape_allow_overwrite(void *device, const struct tc_position pos) int rc; char *msg; struct allow_data_overwrite append_pos; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_ALLOWOVERW)); - ltfsmsg(LTFS_DEBUG, 30597D, "allow overwrite", (unsigned long long)pos.partition, - (unsigned long long)pos.block, ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg(LTFS_DEBUG, + 30597D, + "allow overwrite", + (unsigned long long)pos.partition, + (unsigned long long)pos.block, + ((struct lin_tape_ibmtape *)device)->drive_serial); memset(&append_pos, 0, sizeof(append_pos)); @@ -2704,8 +2722,7 @@ int lin_tape_ibmtape_allow_overwrite(void *device, const struct tc_position pos) rc = DEVICE_GOOD; } - if (rc != DEVICE_GOOD) - lin_tape_ibmtape_process_errors(device, rc, msg, "allow overwrite", true); + if (rc != DEVICE_GOOD) lin_tape_ibmtape_process_errors(device, rc, msg, "allow overwrite", true); } ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_ALLOWOVERW)); @@ -2741,7 +2758,7 @@ int lin_tape_ibmtape_set_compression(void *device, const bool enable_compression { int rc; unsigned char buf[TC_MP_COMPRESSION_SIZE]; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_SETCOMPRS)); rc = lin_tape_ibmtape_modesense(device, TC_MP_COMPRESSION, TC_MP_PC_CURRENT, 0, buf, sizeof(buf)); @@ -2752,7 +2769,7 @@ int lin_tape_ibmtape_set_compression(void *device, const bool enable_compression buf[0] = 0x00; buf[1] = 0x00; - if(enable_compression) + if (enable_compression) buf[18] |= 0x80; /* Set DCE field*/ else buf[18] &= 0x7F; /* Unset DCE field*/ @@ -2776,7 +2793,7 @@ int lin_tape_ibmtape_set_default(void *device) struct stchgp_s param; struct eot_warn eot; int retry; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_SETDEFAULT)); /* Disable Read across EOD on 3592 drive */ @@ -2788,8 +2805,8 @@ int lin_tape_ibmtape_set_default(void *device) return rc; } - buf[0] = 0x00; - buf[1] = 0x00; + buf[0] = 0x00; + buf[1] = 0x00; buf[24] = 0x0C; rc = lin_tape_ibmtape_modeselect(device, buf, sizeof(buf)); @@ -2813,8 +2830,7 @@ int lin_tape_ibmtape_set_default(void *device) param.read_sili_bit = true; rc = _sioc_stioc_command(device, STIOCSETP, "SET PARAM", ¶m, &msg); - if (rc == DEVICE_GOOD || retry > 10) - break; + if (rc == DEVICE_GOOD || retry > 10) break; /* In case of STIOCSETP error, reopen the device and retry */ close(priv->fd); @@ -2829,7 +2845,7 @@ int lin_tape_ibmtape_set_default(void *device) } ltfsmsg(LTFS_WARN, 30426W, priv->devname); } - retry ++; + retry++; } if (rc != DEVICE_GOOD) { @@ -2880,31 +2896,23 @@ int lin_tape_ibmtape_set_default(void *device) * @return 0 on success or a negative value on error */ -#define LOG_TAPE_ALERT (0x2E) -#define LOG_PERFORMANCE (0x37) -#define LOG_PERFORMANCE_CAPACITY_SUB (0x64) // Scope(7-6): Mount Values - // Level(5-4): Return Advanced Counters - // Group(3-0): Capacity +#define LOG_TAPE_ALERT (0x2E) +#define LOG_PERFORMANCE (0x37) +#define LOG_PERFORMANCE_CAPACITY_SUB \ + (0x64) // Scope(7-6): Mount Values \ + // Level(5-4): Return Advanced Counters \ + // Group(3-0): Capacity static uint16_t volstats[] = { - VOLSTATS_MOUNTS, - VOLSTATS_WRITTEN_DS, - VOLSTATS_WRITE_TEMPS, - VOLSTATS_WRITE_PERMS, - VOLSTATS_READ_DS, - VOLSTATS_READ_TEMPS, - VOLSTATS_READ_PERMS, - VOLSTATS_WRITE_PERMS_PREV, - VOLSTATS_READ_PERMS_PREV, - VOLSTATS_WRITE_MB, - VOLSTATS_READ_MB, - VOLSTATS_PASSES_BEGIN, - VOLSTATS_PASSES_MIDDLE, + VOLSTATS_MOUNTS, VOLSTATS_WRITTEN_DS, VOLSTATS_WRITE_TEMPS, VOLSTATS_WRITE_PERMS, VOLSTATS_READ_DS, + VOLSTATS_READ_TEMPS, VOLSTATS_READ_PERMS, VOLSTATS_WRITE_PERMS_PREV, VOLSTATS_READ_PERMS_PREV, VOLSTATS_WRITE_MB, + VOLSTATS_READ_MB, VOLSTATS_PASSES_BEGIN, VOLSTATS_PASSES_MIDDLE, }; -enum { - PERF_CART_CONDITION = 0x0001, /* < Media Efficiency */ - PERF_ACTIVE_CQ_LOSS_W = 0x7113, /* < Active CQ loss Write */ +enum +{ + PERF_CART_CONDITION = 0x0001, /* < Media Efficiency */ + PERF_ACTIVE_CQ_LOSS_W = 0x7113, /* < Active CQ loss Write */ }; static uint16_t perfstats[] = { @@ -2913,7 +2921,7 @@ static uint16_t perfstats[] = { int lin_tape_ibmtape_get_cartridge_health(void *device, struct tc_cartridge_health *cart_health) { - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; unsigned char logdata[LOGSENSEPAGE]; unsigned char buf[16]; @@ -2924,127 +2932,128 @@ int lin_tape_ibmtape_get_cartridge_health(void *device, struct tc_cartridge_heal ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_GETCARTHLTH)); /* Issue LogPage 0x37 */ - cart_health->tape_efficiency = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->tape_efficiency = UNSUPPORTED_CARTRIDGE_HEALTH; rc = lin_tape_ibmtape_logsense(device, LOG_PERFORMANCE, (uint8_t)0, logdata, LOGSENSEPAGE); if (rc) ltfsmsg(LTFS_INFO, 30461I, LOG_PERFORMANCE, rc, "get cart health"); else { - for(i = 0; i < (int)((sizeof(perfstats)/sizeof(perfstats[0]))); i++) { /* BEAM: loop doesn't iterate - Use loop for future enhancement. */ + for (i = 0; i < (int)((sizeof(perfstats) / sizeof(perfstats[0]))); + i++) { /* BEAM: loop doesn't iterate - Use loop for future enhancement. */ if (parse_logPage(logdata, perfstats[i], ¶m_size, buf, 16)) { ltfsmsg(LTFS_INFO, 30462I, LOG_PERFORMANCE, "get cart health"); } else { - switch(param_size) { - case sizeof(uint8_t): - loghlt = (uint64_t)(buf[0]); - break; - case sizeof(uint16_t): - loghlt = (uint64_t)ltfs_betou16(buf); - break; - case sizeof(uint32_t): - loghlt = (uint32_t)ltfs_betou32(buf); - break; - case sizeof(uint64_t): - loghlt = ltfs_betou64(buf); - break; - default: - loghlt = UNSUPPORTED_CARTRIDGE_HEALTH; - break; + switch (param_size) { + case sizeof(uint8_t): + loghlt = (uint64_t)(buf[0]); + break; + case sizeof(uint16_t): + loghlt = (uint64_t)ltfs_betou16(buf); + break; + case sizeof(uint32_t): + loghlt = (uint32_t)ltfs_betou32(buf); + break; + case sizeof(uint64_t): + loghlt = ltfs_betou64(buf); + break; + default: + loghlt = UNSUPPORTED_CARTRIDGE_HEALTH; + break; } - switch(perfstats[i]) { - case PERF_CART_CONDITION: - cart_health->tape_efficiency = loghlt; - break; - default: - break; + switch (perfstats[i]) { + case PERF_CART_CONDITION: + cart_health->tape_efficiency = loghlt; + break; + default: + break; } } } } /* Issue LogPage 0x17 */ - cart_health->mounts = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->written_ds = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->write_temps = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->write_perms = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_ds = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_temps = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_perms = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->mounts = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->written_ds = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->write_temps = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->write_perms = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_ds = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_temps = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_perms = UNSUPPORTED_CARTRIDGE_HEALTH; cart_health->write_perms_prev = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_perms_prev = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->written_mbytes = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_mbytes = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->passes_begin = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->passes_middle = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_perms_prev = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->written_mbytes = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_mbytes = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->passes_begin = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->passes_middle = UNSUPPORTED_CARTRIDGE_HEALTH; rc = lin_tape_ibmtape_logsense(device, LOG_VOLUMESTATS, (uint8_t)0, logdata, LOGSENSEPAGE); if (rc) ltfsmsg(LTFS_INFO, 30461I, LOG_VOLUMESTATS, rc, "get cart health"); else { - for(i = 0; i < (int)((sizeof(volstats)/sizeof(volstats[0]))); i++) { + for (i = 0; i < (int)((sizeof(volstats) / sizeof(volstats[0]))); i++) { if (parse_logPage(logdata, volstats[i], ¶m_size, buf, 16)) { ltfsmsg(LTFS_INFO, 30462I, LOG_VOLUMESTATS, "get cart health"); } else { - switch(param_size) { - case sizeof(uint8_t): - loghlt = (uint64_t)(buf[0]); - break; - case sizeof(uint16_t): - loghlt = (uint64_t)ltfs_betou16(buf); - break; - case sizeof(uint32_t): - loghlt = (uint32_t)ltfs_betou32(buf); - break; - case sizeof(uint64_t): - loghlt = ltfs_betou64(buf); - break; - default: - loghlt = UNSUPPORTED_CARTRIDGE_HEALTH; - break; + switch (param_size) { + case sizeof(uint8_t): + loghlt = (uint64_t)(buf[0]); + break; + case sizeof(uint16_t): + loghlt = (uint64_t)ltfs_betou16(buf); + break; + case sizeof(uint32_t): + loghlt = (uint32_t)ltfs_betou32(buf); + break; + case sizeof(uint64_t): + loghlt = ltfs_betou64(buf); + break; + default: + loghlt = UNSUPPORTED_CARTRIDGE_HEALTH; + break; } - switch(volstats[i]) { - case VOLSTATS_MOUNTS: - cart_health->mounts = loghlt; - break; - case VOLSTATS_WRITTEN_DS: - cart_health->written_ds = loghlt; - break; - case VOLSTATS_WRITE_TEMPS: - cart_health->write_temps = loghlt; - break; - case VOLSTATS_WRITE_PERMS: - cart_health->write_perms = loghlt; - break; - case VOLSTATS_READ_DS: - cart_health->read_ds = loghlt; - break; - case VOLSTATS_READ_TEMPS: - cart_health->read_temps = loghlt; - break; - case VOLSTATS_READ_PERMS: - cart_health->read_perms = loghlt; - break; - case VOLSTATS_WRITE_PERMS_PREV: - cart_health->write_perms_prev = loghlt; - break; - case VOLSTATS_READ_PERMS_PREV: - cart_health->read_perms_prev = loghlt; - break; - case VOLSTATS_WRITE_MB: - cart_health->written_mbytes = loghlt; - break; - case VOLSTATS_READ_MB: - cart_health->read_mbytes = loghlt; - break; - case VOLSTATS_PASSES_BEGIN: - cart_health->passes_begin = loghlt; - break; - case VOLSTATS_PASSES_MIDDLE: - cart_health->passes_middle = loghlt; - break; - default: - break; + switch (volstats[i]) { + case VOLSTATS_MOUNTS: + cart_health->mounts = loghlt; + break; + case VOLSTATS_WRITTEN_DS: + cart_health->written_ds = loghlt; + break; + case VOLSTATS_WRITE_TEMPS: + cart_health->write_temps = loghlt; + break; + case VOLSTATS_WRITE_PERMS: + cart_health->write_perms = loghlt; + break; + case VOLSTATS_READ_DS: + cart_health->read_ds = loghlt; + break; + case VOLSTATS_READ_TEMPS: + cart_health->read_temps = loghlt; + break; + case VOLSTATS_READ_PERMS: + cart_health->read_perms = loghlt; + break; + case VOLSTATS_WRITE_PERMS_PREV: + cart_health->write_perms_prev = loghlt; + break; + case VOLSTATS_READ_PERMS_PREV: + cart_health->read_perms_prev = loghlt; + break; + case VOLSTATS_WRITE_MB: + cart_health->written_mbytes = loghlt; + break; + case VOLSTATS_READ_MB: + cart_health->read_mbytes = loghlt; + break; + case VOLSTATS_PASSES_BEGIN: + cart_health->passes_begin = loghlt; + break; + case VOLSTATS_PASSES_MIDDLE: + cart_health->passes_middle = loghlt; + break; + default: + break; } } } @@ -3069,7 +3078,7 @@ int lin_tape_ibmtape_get_tape_alert(void *device, uint64_t *tape_alert) int param_size, i; int rc; uint64_t ta; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_GETTAPEALT)); /* Issue LogPage 0x2E */ @@ -3078,15 +3087,13 @@ int lin_tape_ibmtape_get_tape_alert(void *device, uint64_t *tape_alert) if (rc) ltfsmsg(LTFS_INFO, 30461I, LOG_TAPE_ALERT, rc, "get tape alert"); else { - for(i = 1; i <= 64; i++) { - if (parse_logPage(logdata, (uint16_t) i, ¶m_size, buf, 16) - || param_size != sizeof(uint8_t)) { + for (i = 1; i <= 64; i++) { + if (parse_logPage(logdata, (uint16_t)i, ¶m_size, buf, 16) || param_size != sizeof(uint8_t)) { ltfsmsg(LTFS_INFO, 30462I, LOG_TAPE_ALERT, "get tape alert"); ta = 0; } - if(buf[0]) - ta += (uint64_t)(1) << (i - 1); + if (buf[0]) ta += (uint64_t)(1) << (i - 1); } } @@ -3105,7 +3112,7 @@ int lin_tape_ibmtape_get_tape_alert(void *device, uint64_t *tape_alert) */ int lin_tape_ibmtape_clear_tape_alert(void *device, uint64_t tape_alert) { - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_CLRTAPEALT)); priv->tape_alert &= ~tape_alert; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_CLRTAPEALT)); @@ -3118,7 +3125,7 @@ int lin_tape_ibmtape_clear_tape_alert(void *device, uint64_t tape_alert) * @param drive_param pointer to the drive parameter infomation. This function will update this value. * @return 0 on success or a negative value on error */ - uint32_t _lin_tape_ibmtape_get_block_limits(void *device) +uint32_t _lin_tape_ibmtape_get_block_limits(void *device) { struct sioc_pass_through spt; int rc; @@ -3127,9 +3134,9 @@ int lin_tape_ibmtape_clear_tape_alert(void *device, uint64_t tape_alert) unsigned char sense[MAXSENSE]; char *msg; uint32_t length = 0; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; - ltfsmsg(LTFS_DEBUG, 30592D, "read block limits", ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg(LTFS_DEBUG, 30592D, "read block limits", ((struct lin_tape_ibmtape *)device)->drive_serial); memset(&spt, 0, sizeof(spt)); memset(cdb, 0, sizeof(cdb)); @@ -3143,12 +3150,11 @@ int lin_tape_ibmtape_clear_tape_alert(void *device, uint64_t tape_alert) /* Prepare CDB (Never issue long erase) */ spt.cmd_length = sizeof(cdb); spt.cdb = cdb; - spt.cdb[0] = 0x05; /* SCSI read block limits code */ + spt.cdb[0] = 0x05; /* SCSI read block limits code */ spt.data_direction = SCSI_DATA_IN; spt.timeout = ibm_tape_get_timeout(priv->timeouts, spt.cdb[0]); - if (spt.timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (spt.timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Prepare sense buffer */ spt.sense_length = sizeof(sense); @@ -3160,8 +3166,7 @@ int lin_tape_ibmtape_clear_tape_alert(void *device, uint64_t tape_alert) lin_tape_ibmtape_process_errors(device, rc, msg, "read block limits", true); else { length = (buf[1] << 16) + (buf[2] << 8) + (buf[3] & 0xFF); - if(length > 1 * MB) - length = 1 * MB; + if (length > 1 * MB) length = 1 * MB; } return length; @@ -3171,16 +3176,16 @@ int lin_tape_ibmtape_get_parameters(void *device, struct tc_drive_param *params) { int rc; unsigned char buf[TC_MP_MEDIUM_SENSE_SIZE]; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_GETPARAM)); memset(params, 0x00, sizeof(struct tc_drive_param)); if (global_data.crc_checking) - params->max_blksize = MIN(_lin_tape_ibmtape_get_block_limits(device), LINUX_MAX_BLOCK_SIZE - 4); + params->max_blksize = MIN(_lin_tape_ibmtape_get_block_limits(device), LINUX_MAX_BLOCK_SIZE - 4); else - params->max_blksize = MIN(_lin_tape_ibmtape_get_block_limits(device), LINUX_MAX_BLOCK_SIZE); + params->max_blksize = MIN(_lin_tape_ibmtape_get_block_limits(device), LINUX_MAX_BLOCK_SIZE); if (priv->loaded) { params->write_protect = 0; @@ -3208,12 +3213,11 @@ int lin_tape_ibmtape_get_parameters(void *device, struct tc_drive_param *params) return rc; } - if ( (buf[3] & 0x80) ) - params->write_protect |= VOL_PHYSICAL_WP; + if ((buf[3] & 0x80)) params->write_protect |= VOL_PHYSICAL_WP; } params->cart_type = priv->cart_type; - params->density = priv->density_code; + params->density = priv->density_code; /* TODO: Following field shall be implemented in the future */ /* @@ -3260,7 +3264,7 @@ static const char *generate_product_name(const char *product_id) int lin_tape_ibmtape_get_device_list(struct tc_drive_info *buf, int count) { FILE *list; - int i = 0, n, dev; + int i = 0, n, dev; char line[1024]; char *name, *model, *sn, *cur; @@ -3274,19 +3278,21 @@ int lin_tape_ibmtape_get_device_list(struct tc_drive_info *buf, int count) while (fgets(line, sizeof(line), list) != NULL) { cur = line; cur = strtok(cur, " "); - if(! cur ) continue; + if (!cur) continue; name = cur; cur += strlen(cur) + 1; - while(*cur == ' ') cur++; + while (*cur == ' ') + cur++; cur = strtok(cur, " "); - if(! cur ) continue; + if (!cur) continue; model = cur; cur += strlen(cur) + 1; - while(*cur == ' ') cur++; + while (*cur == ' ') + cur++; cur = strtok(cur, " "); - if(! cur ) continue; + if (!cur) continue; sn = cur; n = sscanf(name, "%d", &dev); @@ -3297,10 +3303,10 @@ int lin_tape_ibmtape_get_device_list(struct tc_drive_info *buf, int count) snprintf(buf[i].model, TAPE_MODEL_NAME_LEN_MAX, "%s", model); snprintf(buf[i].serial_number, TAPE_SERIAL_LEN_MAX, "%s", sn); snprintf(buf[i].product_name, PRODUCT_NAME_LENGTH, "%s", generate_product_name(model)); - buf[i].host = 0; + buf[i].host = 0; buf[i].channel = 0; - buf[i].target = 0; - buf[i].lun = -1; + buf[i].target = 0; + buf[i].lun = -1; } i++; } @@ -3325,7 +3331,7 @@ int lin_tape_ibmtape_setcap(void *device, uint16_t proportion) unsigned char sense[MAXSENSE]; char *msg; unsigned char buf[TC_MP_MEDIUM_SENSE_SIZE]; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_SETCAP)); if (IS_ENTERPRISE(priv->drive_type)) { @@ -3347,14 +3353,13 @@ int lin_tape_ibmtape_setcap(void *device, uint16_t proportion) return rc; } - buf[0] = 0x00; - buf[1] = 0x00; + buf[0] = 0x00; + buf[1] = 0x00; buf[27] |= 0x01; - buf[28] = 0x00; + buf[28] = 0x00; rc = lin_tape_ibmtape_modeselect(device, buf, sizeof(buf)); } else { - memset(&spt, 0, sizeof(spt)); memset(cdb, 0, sizeof(cdb)); memset(sense, 0, sizeof(sense)); @@ -3366,14 +3371,13 @@ int lin_tape_ibmtape_setcap(void *device, uint16_t proportion) /* Prepare CDB */ spt.cmd_length = sizeof(cdb); spt.cdb = cdb; - spt.cdb[0] = 0x0B; /* SCSI medium set capacity code */ - spt.cdb[3] = (unsigned char) (proportion >> 8); - spt.cdb[4] = (unsigned char) (proportion & 0xFF); + spt.cdb[0] = 0x0B; /* SCSI medium set capacity code */ + spt.cdb[3] = (unsigned char)(proportion >> 8); + spt.cdb[4] = (unsigned char)(proportion & 0xFF); spt.data_direction = SCSI_DATA_NONE; spt.timeout = ibm_tape_get_timeout(priv->timeouts, spt.cdb[0]); - if (spt.timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (spt.timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Prepare sense buffer */ spt.sense_length = sizeof(sense); @@ -3381,8 +3385,7 @@ int lin_tape_ibmtape_setcap(void *device, uint16_t proportion) /* Invoke _ioctl to send a page */ rc = sioc_paththrough(device, &spt, &msg); - if (rc != DEVICE_GOOD) - lin_tape_ibmtape_process_errors(device, rc, msg, "setcap", true); + if (rc != DEVICE_GOOD) lin_tape_ibmtape_process_errors(device, rc, msg, "setcap", true); } ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_SETCAP)); @@ -3395,9 +3398,9 @@ int lin_tape_ibmtape_setcap(void *device, uint16_t proportion) * @param part Partition to read the parameter from. * @return enum eod_status or UNSUPPORTED_FUNCTION if not supported. */ -#define LOG_VOL_STATISTICS (0x17) -#define LOG_VOL_USED_CAPACITY (0x203) -#define LOG_VOL_PART_HEADER_SIZE (4) +#define LOG_VOL_STATISTICS (0x17) +#define LOG_VOL_USED_CAPACITY (0x203) +#define LOG_VOL_PART_HEADER_SIZE (4) int lin_tape_ibmtape_get_eod_status(void *device, int part) { @@ -3407,11 +3410,11 @@ int lin_tape_ibmtape_get_eod_status(void *device, int part) */ unsigned char logdata[LOGSENSEPAGE]; - unsigned char buf[16] = {0}; + unsigned char buf[16] = { 0 }; int param_size, rc; unsigned int i; - uint32_t part_cap[2] = {EOD_UNKNOWN, EOD_UNKNOWN}; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + uint32_t part_cap[2] = { EOD_UNKNOWN, EOD_UNKNOWN }; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_GETEODSTAT)); /* Issue LogPage 0x17 */ @@ -3423,8 +3426,8 @@ int lin_tape_ibmtape_get_eod_status(void *device, int part) } /* Parse Approximate used native capacity of partitions (0x203)*/ - if (parse_logPage(logdata, (uint16_t)LOG_VOL_USED_CAPACITY, ¶m_size, buf, sizeof(buf)) - || (param_size != sizeof(buf) ) ) { + if (parse_logPage(logdata, (uint16_t)LOG_VOL_USED_CAPACITY, ¶m_size, buf, sizeof(buf)) || + (param_size != sizeof(buf))) { ltfsmsg(LTFS_WARN, 30465W); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_GETEODSTAT)); return EOD_UNKNOWN; @@ -3436,13 +3439,11 @@ int lin_tape_ibmtape_get_eod_status(void *device, int part) uint16_t part_buf; len = buf[i]; - part_buf = (uint16_t)(buf[i + 2] << 8) + (uint16_t) buf[i + 3]; + part_buf = (uint16_t)(buf[i + 2] << 8) + (uint16_t)buf[i + 3]; /* actual length - 1 is stored into len */ - if ( (len - LOG_VOL_PART_HEADER_SIZE + 1) == sizeof(uint32_t) && part_buf < 2) { - part_cap[part_buf] = ((uint32_t) buf[i + 4] << 24) + - ((uint32_t) buf[i + 5] << 16) + - ((uint32_t) buf[i + 6] << 8) + - (uint32_t) buf[i + 7]; + if ((len - LOG_VOL_PART_HEADER_SIZE + 1) == sizeof(uint32_t) && part_buf < 2) { + part_cap[part_buf] = ((uint32_t)buf[i + 4] << 24) + ((uint32_t)buf[i + 5] << 16) + ((uint32_t)buf[i + 6] << 8) + + (uint32_t)buf[i + 7]; } else ltfsmsg(LTFS_WARN, 30466W, i, part_buf, len); @@ -3450,7 +3451,7 @@ int lin_tape_ibmtape_get_eod_status(void *device, int part) } /* Create return value */ - if(part_cap[part] == 0xFFFFFFFF) + if (part_cap[part] == 0xFFFFFFFF) rc = EOD_MISSING; else rc = EOD_GOOD; @@ -3474,18 +3475,16 @@ int lin_tape_ibmtape_get_xattr(void *device, const char *name, char **buf) int rc = -LTFS_NO_XATTR; uint32_t value32; struct ltfs_timespec now; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_GETXATTR)); - if (! strcmp(name, "ltfs.vendor.IBM.mediaCQsLossRate")) { + if (!strcmp(name, "ltfs.vendor.IBM.mediaCQsLossRate")) { rc = DEVICE_GOOD; /* If first fetch or cache value is too old and valuie is dirty, refetch value */ get_current_timespec(&now); - if ( priv->fetch_sec_acq_loss_w == 0 || - ((priv->fetch_sec_acq_loss_w + 60 < now.tv_sec) && priv->dirty_acq_loss_w)) { - rc = lin_tape_ibmtape_logsense(device, LOG_PERFORMANCE, LOG_PERFORMANCE_CAPACITY_SUB, - logdata, LOGSENSEPAGE); + if (priv->fetch_sec_acq_loss_w == 0 || ((priv->fetch_sec_acq_loss_w + 60 < now.tv_sec) && priv->dirty_acq_loss_w)) { + rc = lin_tape_ibmtape_logsense(device, LOG_PERFORMANCE, LOG_PERFORMANCE_CAPACITY_SUB, logdata, LOGSENSEPAGE); if (rc) ltfsmsg(LTFS_INFO, 30461I, LOG_PERFORMANCE, rc, "get xattr"); else { @@ -3493,30 +3492,29 @@ int lin_tape_ibmtape_get_xattr(void *device, const char *name, char **buf) ltfsmsg(LTFS_INFO, 30462I, LOG_PERFORMANCE, "get xattr"); rc = -LTFS_NO_XATTR; } else { - switch(param_size) { - case sizeof(uint32_t): - value32 = (uint32_t)ltfs_betou32(logbuf); - priv->acq_loss_w = (float)value32 / 65536.0; - priv->fetch_sec_acq_loss_w = now.tv_sec; - priv->dirty_acq_loss_w = false; - break; - default: - ltfsmsg(LTFS_INFO, 30467I, param_size); - rc = -LTFS_NO_XATTR; - break; + switch (param_size) { + case sizeof(uint32_t): + value32 = (uint32_t)ltfs_betou32(logbuf); + priv->acq_loss_w = (float)value32 / 65536.0; + priv->fetch_sec_acq_loss_w = now.tv_sec; + priv->dirty_acq_loss_w = false; + break; + default: + ltfsmsg(LTFS_INFO, 30467I, param_size); + rc = -LTFS_NO_XATTR; + break; } } } } - if(rc == DEVICE_GOOD) { + if (rc == DEVICE_GOOD) { /* The buf allocated here shall be freed in xattr_get_virtual() */ rc = asprintf(buf, "%2.2f", priv->acq_loss_w); if (rc < 0) { rc = -LTFS_NO_MEMORY; ltfsmsg(LTFS_INFO, 30468I, "getting active CQ loss write"); - } - else + } else rc = DEVICE_GOOD; } else priv->fetch_sec_acq_loss_w = 0; @@ -3538,16 +3536,15 @@ int lin_tape_ibmtape_set_xattr(void *device, const char *name, const char *buf, { int rc = -LTFS_NO_XATTR; char *null_terminated; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; int64_t perm_count = 0; - if (!size) - return -LTFS_BAD_ARG; + if (!size) return -LTFS_BAD_ARG; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_SETXATTR)); null_terminated = malloc(size + 1); - if (! null_terminated) { + if (!null_terminated) { ltfsmsg(LTFS_ERR, 10001E, "lin_tape_ibmtape_set_xattr: null_term"); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_SETXATTR)); return -LTFS_NO_MEMORY; @@ -3555,30 +3552,30 @@ int lin_tape_ibmtape_set_xattr(void *device, const char *name, const char *buf, memcpy(null_terminated, buf, size); null_terminated[size] = '\0'; - if (! strcmp(name, "ltfs.vendor.IBM.forceErrorWrite")) { + if (!strcmp(name, "ltfs.vendor.IBM.forceErrorWrite")) { perm_count = strtoll(null_terminated, NULL, 0); if (perm_count < 0) { priv->force_writeperm = -perm_count; - priv->clear_by_pc = true; + priv->clear_by_pc = true; } else { priv->force_writeperm = perm_count; - priv->clear_by_pc = false; + priv->clear_by_pc = false; } if (priv->force_writeperm && priv->force_writeperm < THRESHOLD_FORCE_WRITE_NO_WRITE) priv->force_writeperm = THRESHOLD_FORCE_WRITE_NO_WRITE; priv->write_counter = 0; rc = DEVICE_GOOD; - } else if (! strcmp(name, "ltfs.vendor.IBM.forceErrorType")) { + } else if (!strcmp(name, "ltfs.vendor.IBM.forceErrorType")) { priv->force_errortype = strtol(null_terminated, NULL, 0); rc = DEVICE_GOOD; - } else if (! strcmp(name, "ltfs.vendor.IBM.forceErrorRead")) { + } else if (!strcmp(name, "ltfs.vendor.IBM.forceErrorRead")) { perm_count = strtoll(null_terminated, NULL, 0); if (perm_count < 0) { priv->force_readperm = -perm_count; - priv->clear_by_pc = true; + priv->clear_by_pc = true; } else { priv->force_readperm = perm_count; - priv->clear_by_pc = false; + priv->clear_by_pc = false; } priv->read_counter = 0; rc = DEVICE_GOOD; @@ -3603,14 +3600,25 @@ const char *lin_tape_ibmtape_default_device_name(void) return devname; } -static void ltfsmsg_keyalias(const char * const title, const unsigned char * const keyalias) +static void ltfsmsg_keyalias(const char *const title, const unsigned char *const keyalias) { - char s[128] = {'\0'}; + char s[128] = { '\0' }; if (keyalias) - sprintf(s, "keyalias = %c%c%c%02X%02X%02X%02X%02X%02X%02X%02X%02X", keyalias[0], - keyalias[1], keyalias[2], keyalias[3], keyalias[4], keyalias[5], keyalias[6], - keyalias[7], keyalias[8], keyalias[9], keyalias[10], keyalias[11]); + sprintf(s, + "keyalias = %c%c%c%02X%02X%02X%02X%02X%02X%02X%02X%02X", + keyalias[0], + keyalias[1], + keyalias[2], + keyalias[3], + keyalias[4], + keyalias[5], + keyalias[6], + keyalias[7], + keyalias[8], + keyalias[9], + keyalias[10], + keyalias[11]); else sprintf(s, "keyalias: NULL"); @@ -3619,44 +3627,44 @@ static void ltfsmsg_keyalias(const char * const title, const unsigned char * con static bool is_ame(void *device) { - unsigned char buf[TC_MP_READ_WRITE_CTRL_SIZE] = {0}; + unsigned char buf[TC_MP_READ_WRITE_CTRL_SIZE] = { 0 }; const int rc = lin_tape_ibmtape_modesense(device, TC_MP_READ_WRITE_CTRL, TC_MP_PC_CURRENT, 0, buf, sizeof(buf)); if (rc != 0) { - char message[100] = {0}; + char message[100] = { 0 }; sprintf(message, "failed to get MP %02Xh (%d)", TC_MP_READ_WRITE_CTRL, rc); ltfsmsg(LTFS_DEBUG, 30592D, __FUNCTION__, message); return false; /* Consider that the encryption method is not AME */ } else { const unsigned char encryption_method = buf[16 + 27]; - char message[100] = {0}; + char message[100] = { 0 }; char *method = NULL; switch (encryption_method) { - case 0x00: - method = "None"; - break; - case 0x10: - method = "System"; - break; - case 0x1F: - method = "Controller"; - break; - case 0x50: - method = "Application"; - break; - case 0x60: - method = "Library"; - break; - case 0x70: - method = "Internal"; - break; - case 0xFF: - method = "Custom"; - break; - default: - method = "Unknown"; - break; + case 0x00: + method = "None"; + break; + case 0x10: + method = "System"; + break; + case 0x1F: + method = "Controller"; + break; + case 0x50: + method = "Application"; + break; + case 0x60: + method = "Library"; + break; + case 0x70: + method = "Internal"; + break; + case 0xFF: + method = "Custom"; + break; + default: + method = "Unknown"; + break; } sprintf(message, "Encryption Method is %s (0x%02X)", method, encryption_method); ltfsmsg(LTFS_DEBUG, 30592D, __FUNCTION__, message); @@ -3670,15 +3678,14 @@ static bool is_ame(void *device) static int is_encryption_capable(void *device) { - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; if (IS_ENTERPRISE(priv->drive_type)) { ltfsmsg(LTFS_ERR, 30470E, priv->drive_type); return -EDEV_INTERNAL_ERROR; } - if (! is_ame(device)) - return -EDEV_INTERNAL_ERROR; + if (!is_ame(device)) return -EDEV_INTERNAL_ERROR; return DEVICE_GOOD; } @@ -3693,13 +3700,13 @@ static int is_encryption_capable(void *device) */ int lin_tape_ibmtape_security_protocol_out(void *device, const uint16_t sps, unsigned char *buf, const size_t size) { - struct sioc_pass_through spt = {0}; - unsigned char cdb[12] = {0}; - unsigned char sense[MAXSENSE] = {0}; + struct sioc_pass_through spt = { 0 }; + unsigned char cdb[12] = { 0 }; + unsigned char sense[MAXSENSE] = { 0 }; char *msg = NULL; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; - ltfsmsg(LTFS_DEBUG, 30592D, "Security Protocol Out (SPOUT)", ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg(LTFS_DEBUG, 30592D, "Security Protocol Out (SPOUT)", ((struct lin_tape_ibmtape *)device)->drive_serial); /* Prepare Data Buffer */ spt.buffer_length = size; @@ -3708,15 +3715,14 @@ int lin_tape_ibmtape_security_protocol_out(void *device, const uint16_t sps, uns /* Prepare CDB */ spt.cmd_length = sizeof(cdb); spt.cdb = cdb; - spt.cdb[0] = 0xB5; /* SCSI SECURITY PROTOCOL OUT */ - spt.cdb[1] = 0x20; /* Tape Data Encryption security protocol */ + spt.cdb[0] = 0xB5; /* SCSI SECURITY PROTOCOL OUT */ + spt.cdb[1] = 0x20; /* Tape Data Encryption security protocol */ ltfs_u16tobe(spt.cdb + 2, sps); /* SECURITY PROTOCOL SPECIFIC */ ltfs_u32tobe(spt.cdb + 6, spt.buffer_length); spt.data_direction = SCSI_DATA_OUT; spt.timeout = ibm_tape_get_timeout(priv->timeouts, spt.cdb[0]); - if (spt.timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (spt.timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Prepare sense buffer */ spt.sense_length = sizeof(sense); @@ -3731,7 +3737,7 @@ int lin_tape_ibmtape_security_protocol_out(void *device, const uint16_t sps, uns return rc; } -int lin_tape_ibmtape_set_key(void *device, const unsigned char * const keyalias, const unsigned char * const key) +int lin_tape_ibmtape_set_key(void *device, const unsigned char *const keyalias, const unsigned char *const key) { /* * Encryption Decryption Key DKi keyalias @@ -3739,7 +3745,7 @@ int lin_tape_ibmtape_set_key(void *device, const unsigned char * const keyalias, * 0h Disable 0h Disable Prohibited Prohibited NULL * 2h Encrypt 3h Mixed Mandatory Optional !NULL */ - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_SETKEY)); @@ -3753,15 +3759,14 @@ int lin_tape_ibmtape_set_key(void *device, const unsigned char * const keyalias, const size_t size = keyalias ? 20 + DK_LENGTH + 4 + DKI_LENGTH : 20; unsigned char *buffer = calloc(size, sizeof(unsigned char)); - if (! buffer) { + if (!buffer) { rc = -ENOMEM; goto out; } - unsigned char buf[TC_MP_READ_WRITE_CTRL_SIZE] = {0}; + unsigned char buf[TC_MP_READ_WRITE_CTRL_SIZE] = { 0 }; rc = lin_tape_ibmtape_modesense(device, TC_MP_READ_WRITE_CTRL, TC_MP_PC_CURRENT, 0, buf, sizeof(buf)); - if (rc != DEVICE_GOOD) - goto free; + if (rc != DEVICE_GOOD) goto free; ltfs_u16tobe(buffer + 0, sps); ltfs_u16tobe(buffer + 2, size - 4); @@ -3777,38 +3782,44 @@ int lin_tape_ibmtape_set_key(void *device, const unsigned char * const keyalias, * CKORL: 0b Clear key on reservation loss (CKORL) bit */ buffer[5] = 0x00; - enum { DISABLE = 0, EXTERNAL = 1, ENCRYPT = 2 }; + enum + { + DISABLE = 0, + EXTERNAL = 1, + ENCRYPT = 2 + }; buffer[6] = keyalias ? ENCRYPT : DISABLE; /* ENCRYPTION MODE */ - enum { /* DISABLE = 0, */ RAW = 1, DECRYPT = 2, MIXED = 3 }; - buffer[7] = keyalias ? MIXED : DISABLE; /* DECRYPTION MODE */ - buffer[8] = 1; /* ALGORITHM INDEX */ - buffer[9] = 0; /* LOGICAL BLOCK ENCRYPTION KEY FORMAT: plain-text key */ - buffer[10] = 0; /* KAD FORMAT: Unspecified */ + enum + { /* DISABLE = 0, */ RAW = 1, + DECRYPT = 2, + MIXED = 3 }; + buffer[7] = keyalias ? MIXED : DISABLE; /* DECRYPTION MODE */ + buffer[8] = 1; /* ALGORITHM INDEX */ + buffer[9] = 0; /* LOGICAL BLOCK ENCRYPTION KEY FORMAT: plain-text key */ + buffer[10] = 0; /* KAD FORMAT: Unspecified */ ltfs_u16tobe(buffer + 18, keyalias ? DK_LENGTH : 0x00); /* LOGICAL BLOCK ENCRYPTION KEY LENGTH */ if (keyalias) { - if (! key) { + if (!key) { rc = -EINVAL; goto free; } memcpy(buffer + 20, key, DK_LENGTH); /* LOGICAL BLOCK ENCRYPTION KEY */ - buffer[20 + DK_LENGTH] = 0x01; /* KEY DESCRIPTOR TYPE: 01h DKi (Data Key Identifier) */ + buffer[20 + DK_LENGTH] = 0x01; /* KEY DESCRIPTOR TYPE: 01h DKi (Data Key Identifier) */ ltfs_u16tobe(buffer + 20 + DK_LENGTH + 2, DKI_LENGTH); memcpy(buffer + 20 + 0x20 + 4, keyalias, DKI_LENGTH); } - const char * const title = "set key:"; + const char *const title = "set key:"; ltfsmsg_keyalias(title, keyalias); rc = lin_tape_ibmtape_security_protocol_out(device, sps, buffer, size); - if (rc != DEVICE_GOOD) - goto free; + if (rc != DEVICE_GOOD) goto free; - ((struct lin_tape_ibmtape *) device)->is_data_key_set = keyalias != NULL; + ((struct lin_tape_ibmtape *)device)->is_data_key_set = keyalias != NULL; memset(buf, 0, sizeof(buf)); rc = lin_tape_ibmtape_modesense(device, TC_MP_READ_WRITE_CTRL, TC_MP_PC_CURRENT, 0, buf, sizeof(buf)); - if (rc != DEVICE_GOOD) - goto free; + if (rc != DEVICE_GOOD) goto free; free: free(buffer); @@ -3818,27 +3829,26 @@ int lin_tape_ibmtape_set_key(void *device, const unsigned char * const keyalias, return rc; } -static void show_hex_dump(const char * const title, const unsigned char * const buf, const uint size) +static void show_hex_dump(const char *const title, const unsigned char *const buf, const uint size) { /* * " 1 2 3 4 5 6 7 8" * "12345678901234567890123456789012345678901234567890123456789012345678901234567890" * "xxxxxx 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF\n" < 100 */ - char * const s = calloc((size / 0x10 + 1) * 100, sizeof(char)); + char *const s = calloc((size / 0x10 + 1) * 100, sizeof(char)); char *p = s; uint i = 0; int j = 0; int k = 0; - if (p == NULL) - return; + if (p == NULL) return; for (i = 0; i < size; ++i) { if (i % 0x10 == 0) { if (i) { for (j = 0x10; 0 < j; --j) { - p += sprintf(p, "%c", isprint(buf[i-j]) ? buf[i-j] : '.'); + p += sprintf(p, "%c", isprint(buf[i - j]) ? buf[i - j] : '.'); } } p += sprintf(p, "\n%06X ", i); @@ -3849,7 +3859,7 @@ static void show_hex_dump(const char * const title, const unsigned char * const p += sprintf(p, " %s", (i + k) % 8 == 7 ? " " : ""); } for (j = 0x10 - k; 0 < j; --j) { - p += sprintf(p, "%c", isprint(buf[i-j]) ? buf[i-j] : '.'); + p += sprintf(p, "%c", isprint(buf[i - j]) ? buf[i - j] : '.'); } ltfsmsg(LTFS_DEBUG, 30592D, title, s); @@ -3858,7 +3868,7 @@ static void show_hex_dump(const char * const title, const unsigned char * const int lin_tape_ibmtape_get_keyalias(void *device, unsigned char **keyalias) /* This is not IBM method but T10 method. */ { int i; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_GETKEYALIAS)); @@ -3871,7 +3881,7 @@ int lin_tape_ibmtape_get_keyalias(void *device, unsigned char **keyalias) /* Thi static const int page_header_length = 4; struct sioc_pass_through spt = { .buffer_length = page_header_length }; - memset(((struct lin_tape_ibmtape*) device)->dki, 0, sizeof(((struct lin_tape_ibmtape*) device)->dki)); + memset(((struct lin_tape_ibmtape *)device)->dki, 0, sizeof(((struct lin_tape_ibmtape *)device)->dki)); *keyalias = NULL; /* @@ -3881,7 +3891,7 @@ int lin_tape_ibmtape_get_keyalias(void *device, unsigned char **keyalias) /* Thi for (i = 0; i < 2; ++i) { /* Prepare Data Buffer */ free(spt.buffer); - spt.buffer = (unsigned char*) calloc(spt.buffer_length, sizeof(unsigned char)); + spt.buffer = (unsigned char *)calloc(spt.buffer_length, sizeof(unsigned char)); if (spt.buffer == NULL) { ltfsmsg(LTFS_ERR, 10001E, "lin_tape_ibmtape_get_keyalias: data buffer"); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_GETKEYALIAS)); @@ -3889,21 +3899,20 @@ int lin_tape_ibmtape_get_keyalias(void *device, unsigned char **keyalias) /* Thi } /* Prepare CDB */ - unsigned char cdb[12] = {0}; + unsigned char cdb[12] = { 0 }; spt.cmd_length = sizeof(cdb); spt.cdb = cdb; - spt.cdb[0] = 0xA2; /* operation code: SECURITY PROTOCOL IN */ - spt.cdb[1] = 0x20; /* security protocol */ - spt.cdb[3] = 0x21; /* security protocol specific: Next Block Encryption Status page */ + spt.cdb[0] = 0xA2; /* operation code: SECURITY PROTOCOL IN */ + spt.cdb[1] = 0x20; /* security protocol */ + spt.cdb[3] = 0x21; /* security protocol specific: Next Block Encryption Status page */ ltfs_u32tobe(spt.cdb + 6, spt.buffer_length); /* allocation length */ spt.data_direction = SCSI_DATA_IN; spt.timeout = ibm_tape_get_timeout(priv->timeouts, spt.cdb[0]); - if (spt.timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (spt.timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Prepare sense buffer */ - unsigned char sense[MAXSENSE] = {0}; + unsigned char sense[MAXSENSE] = { 0 }; spt.sense_length = sizeof(sense); spt.sense = sense; @@ -3924,44 +3933,46 @@ int lin_tape_ibmtape_get_keyalias(void *device, unsigned char **keyalias) /* Thi } const unsigned char encryption_status = spt.buffer[12] & 0xF; - enum { - ENC_STAT_INCAPABLE = 0, - ENC_STAT_NOT_YET_BEEN_READ = 1, - ENC_STAT_NOT_A_LOGICAL_BLOCK = 2, - ENC_STAT_NOT_ENCRYPTED = 3, + enum + { + ENC_STAT_INCAPABLE = 0, + ENC_STAT_NOT_YET_BEEN_READ = 1, + ENC_STAT_NOT_A_LOGICAL_BLOCK = 2, + ENC_STAT_NOT_ENCRYPTED = 3, ENC_STAT_ENCRYPTED_BY_UNSUPPORTED_ALGORITHM = 4, - ENC_STAT_ENCRYPTED_BY_SUPPORTED_ALGORITHM = 5, - ENC_STAT_ENCRYPTED_BY_OTHER_KEY = 6, + ENC_STAT_ENCRYPTED_BY_SUPPORTED_ALGORITHM = 5, + ENC_STAT_ENCRYPTED_BY_OTHER_KEY = 6, ENC_STAT_RESERVED, /* 7h-Fh */ }; if (encryption_status == ENC_STAT_ENCRYPTED_BY_UNSUPPORTED_ALGORITHM || - encryption_status == ENC_STAT_ENCRYPTED_BY_SUPPORTED_ALGORITHM || - encryption_status == ENC_STAT_ENCRYPTED_BY_OTHER_KEY) { + encryption_status == ENC_STAT_ENCRYPTED_BY_SUPPORTED_ALGORITHM || + encryption_status == ENC_STAT_ENCRYPTED_BY_OTHER_KEY) { uint offset = 16; /* offset of key descriptor */ while (offset + 4 <= spt.buffer_length && spt.buffer[offset] != 1) { offset += ltfs_betou16(spt.buffer + offset + 2) + 4; } if (offset + 4 <= spt.buffer_length && spt.buffer[offset] == 1) { - const uint dki_length = ((int) spt.buffer[offset + 2]) << 8 | spt.buffer[offset + 3]; + const uint dki_length = ((int)spt.buffer[offset + 2]) << 8 | spt.buffer[offset + 3]; if (offset + 4 + dki_length <= spt.buffer_length) { - int n = dki_length < sizeof(((struct lin_tape_ibmtape*) device)->dki) ? dki_length : - sizeof(((struct lin_tape_ibmtape*) device)->dki); - memcpy(((struct lin_tape_ibmtape*) device)->dki, &spt.buffer[offset + 4], n); - *keyalias = ((struct lin_tape_ibmtape*) device)->dki; + int n = dki_length < sizeof(((struct lin_tape_ibmtape *)device)->dki) + ? dki_length + : sizeof(((struct lin_tape_ibmtape *)device)->dki); + memcpy(((struct lin_tape_ibmtape *)device)->dki, &spt.buffer[offset + 4], n); + *keyalias = ((struct lin_tape_ibmtape *)device)->dki; } } } - const char * const title = "get key-alias:"; - ltfsmsg_keyalias(title, ((struct lin_tape_ibmtape*) device)->dki); + const char *const title = "get key-alias:"; + ltfsmsg_keyalias(title, ((struct lin_tape_ibmtape *)device)->dki); free(spt.buffer); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_GETKEYALIAS)); return rc; } -#define TC_MP_INIT_EXT_LBP_RS (0x40) -#define TC_MP_INIT_EXT_LBP_CRC32C (0x20) +#define TC_MP_INIT_EXT_LBP_RS (0x40) +#define TC_MP_INIT_EXT_LBP_CRC32C (0x20) int lin_tape_ibmtape_set_lbp(void *device, bool enable) { @@ -3970,14 +3981,13 @@ int lin_tape_ibmtape_set_lbp(void *device, bool enable) unsigned char lbp_method = LBP_DISABLE; unsigned char buf[TC_MP_INIT_EXT_SIZE]; int rc = DEVICE_GOOD; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; memset(buf, 0, sizeof(buf)); /* Check logical block protection capability */ rc = lin_tape_ibmtape_modesense(device, TC_MP_INIT_EXT, TC_MP_PC_CURRENT, 0x00, buf, sizeof(buf)); - if (rc < 0) - return rc; + if (rc < 0) return rc; if (buf[0x12] & TC_MP_INIT_EXT_LBP_CRC32C) lbp_method = CRC32C_CRC; @@ -3995,10 +4005,10 @@ int lin_tape_ibmtape_set_lbp(void *device, bool enable) } if (enable && lbp.lbp_capable) { - lbp.lbp_method = lbp_method; + lbp.lbp_method = lbp_method; lbp.lbp_info_length = 4; - lbp.lbp_w = 1; - lbp.lbp_r = 1; + lbp.lbp_w = 1; + lbp.lbp_r = 1; } else lbp.lbp_method = LBP_DISABLE; @@ -4010,22 +4020,22 @@ int lin_tape_ibmtape_set_lbp(void *device, bool enable) if (enable && lbp.lbp_capable) { switch (lbp_method) { - case CRC32C_CRC: - priv->f_crc_enc = crc32c_enc; - priv->f_crc_check = crc32c_check; - break; - case REED_SOLOMON_CRC: - priv->f_crc_enc = rs_gf256_enc; - priv->f_crc_check = rs_gf256_check; - break; - default: - priv->f_crc_enc = NULL; - priv->f_crc_check = NULL; - break; + case CRC32C_CRC: + priv->f_crc_enc = crc32c_enc; + priv->f_crc_check = crc32c_check; + break; + case REED_SOLOMON_CRC: + priv->f_crc_enc = rs_gf256_enc; + priv->f_crc_check = rs_gf256_check; + break; + default: + priv->f_crc_enc = NULL; + priv->f_crc_check = NULL; + break; } ltfsmsg(LTFS_INFO, 30471I); } else { - priv->f_crc_enc = NULL; + priv->f_crc_enc = NULL; priv->f_crc_check = NULL; ltfsmsg(LTFS_INFO, 30472I); } @@ -4033,19 +4043,17 @@ int lin_tape_ibmtape_set_lbp(void *device, bool enable) return rc; } -int lin_tape_ibmtape_is_mountable(void *device, const char *barcode, const unsigned char cart_type, - const unsigned char density) +int lin_tape_ibmtape_is_mountable(void *device, + const char *barcode, + const unsigned char cart_type, + const unsigned char density) { int ret; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_ISMOUNTABLE)); - ret = ibm_tape_is_mountable( priv->drive_type, - barcode, - cart_type, - density, - global_data.strict_drive); + ret = ibm_tape_is_mountable(priv->drive_type, barcode, cart_type, density, global_data.strict_drive); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_ISMOUNTABLE)); @@ -4057,11 +4065,7 @@ bool lin_tape_ibmtape_is_readonly(void *device) int ret; struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; - ret = ibm_tape_is_mountable( priv->drive_type, - NULL, - priv->cart_type, - priv->density_code, - global_data.strict_drive); + ret = ibm_tape_is_mountable(priv->drive_type, NULL, priv->cart_type, priv->density_code, global_data.strict_drive); if (ret == MEDIUM_READONLY) return true; @@ -4079,17 +4083,16 @@ bool lin_tape_ibmtape_is_readonly(void *device) * @param type * @return 0 on success or negative value on error */ -int lin_tape_ibmtape_readbuffer(void *device, int id, unsigned char *buf, size_t offset, size_t len, - int type) +int lin_tape_ibmtape_readbuffer(void *device, int id, unsigned char *buf, size_t offset, size_t len, int type) { struct sioc_pass_through spt; unsigned char cdb[10]; unsigned char sense[MAXSENSE]; char *msg; int rc; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; - ltfsmsg(LTFS_DEBUG, 30593D, "read buffer", id, ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg(LTFS_DEBUG, 30593D, "read buffer", id, ((struct lin_tape_ibmtape *)device)->drive_serial); memset(&spt, 0, sizeof(spt)); memset(cdb, 0, sizeof(cdb)); @@ -4097,27 +4100,26 @@ int lin_tape_ibmtape_readbuffer(void *device, int id, unsigned char *buf, size_t /* Prepare Data Buffer */ spt.buffer_length = len; - spt.buffer = (unsigned char *) buf; + spt.buffer = (unsigned char *)buf; memset(spt.buffer, 0, spt.buffer_length); /* Prepare CDB */ spt.cmd_length = sizeof(cdb); spt.cdb = cdb; - spt.cdb[0] = 0x3c; /* SCSI ReadBuffer(10) Code */ + spt.cdb[0] = 0x3c; /* SCSI ReadBuffer(10) Code */ spt.cdb[1] = type; spt.cdb[2] = id; - spt.cdb[3] = (unsigned char) (offset >> 16); - spt.cdb[4] = (unsigned char) (offset >> 8); - spt.cdb[5] = (unsigned char) (offset & 0xFF); - spt.cdb[6] = (unsigned char) (len >> 16); - spt.cdb[7] = (unsigned char) (len >> 8); - spt.cdb[8] = (unsigned char) (len & 0xFF); + spt.cdb[3] = (unsigned char)(offset >> 16); + spt.cdb[4] = (unsigned char)(offset >> 8); + spt.cdb[5] = (unsigned char)(offset & 0xFF); + spt.cdb[6] = (unsigned char)(len >> 16); + spt.cdb[7] = (unsigned char)(len >> 8); + spt.cdb[8] = (unsigned char)(len & 0xFF); spt.data_direction = SCSI_DATA_IN; spt.timeout = ibm_tape_get_timeout(priv->timeouts, spt.cdb[0]); - if (spt.timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (spt.timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Prepare sense buffer */ spt.sense_length = sizeof(sense); @@ -4125,8 +4127,7 @@ int lin_tape_ibmtape_readbuffer(void *device, int id, unsigned char *buf, size_t /* Invoke SCSI command and check error */ rc = sioc_paththrough(device, &spt, &msg); - if (rc != DEVICE_GOOD) - lin_tape_ibmtape_process_errors(device, rc, msg, "read buffer", false); + if (rc != DEVICE_GOOD) lin_tape_ibmtape_process_errors(device, rc, msg, "read buffer", false); return rc; } @@ -4137,7 +4138,7 @@ int lin_tape_ibmtape_readbuffer(void *device, int id, unsigned char *buf, size_t * @param fname a file name of dump * @return 0 on success or negative value on error */ -#define DUMP_HEADER_SIZE (4) +#define DUMP_HEADER_SIZE (4) #define DUMP_TRANSFER_SIZE (512 * KB) int lin_tape_ibmtape_getdump_drive(void *device, const char *fname) @@ -4150,7 +4151,7 @@ int lin_tape_ibmtape_getdump_drive(void *device, const char *fname) int buf_id; unsigned char cap_buf[DUMP_HEADER_SIZE]; unsigned char *dump_buf; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfsmsg(LTFS_INFO, 30478I, fname); @@ -4171,7 +4172,7 @@ int lin_tape_ibmtape_getdump_drive(void *device, const char *fname) /* Get buffer capacity */ lin_tape_ibmtape_readbuffer(device, buf_id, cap_buf, 0, sizeof(cap_buf), 0x03); - data_length = (cap_buf[1] << 16) + (cap_buf[2] << 8) + (int) cap_buf[3]; + data_length = (cap_buf[1] << 16) + (cap_buf[2] << 8) + (int)cap_buf[3]; /* Open dump file for write only */ dumpfd = open(fname, O_WRONLY | O_CREAT | O_TRUNC, 0666); @@ -4185,8 +4186,7 @@ int lin_tape_ibmtape_getdump_drive(void *device, const char *fname) /* get the total number of transfers */ num_transfers = data_length / transfer_size; excess_transfer = data_length % transfer_size; - if (excess_transfer) - num_transfers += 1; + if (excess_transfer) num_transfers += 1; /* Total dump data length is %lld. Total number of transfers is %d. */ ltfsmsg(LTFS_DEBUG, 30480D, data_length); @@ -4237,7 +4237,7 @@ int lin_tape_ibmtape_getdump_drive(void *device, const char *fname) buf_offset += transfer_size; num_transfers -= 1; - } /* end of while(num_transfers) */ + } /* end of while(num_transfers) */ free(dump_buf); close(dumpfd); @@ -4259,9 +4259,9 @@ int lin_tape_ibmtape_forcedump_drive(void *device) unsigned char sense[MAXSENSE]; int rc; char *msg; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; - ltfsmsg(LTFS_DEBUG, 30593D, "force dump", 0, ((struct lin_tape_ibmtape *) device)->drive_serial); + ltfsmsg(LTFS_DEBUG, 30593D, "force dump", 0, ((struct lin_tape_ibmtape *)device)->drive_serial); memset(&spt, 0, sizeof(spt)); memset(cdb, 0, sizeof(cdb)); @@ -4275,23 +4275,22 @@ int lin_tape_ibmtape_forcedump_drive(void *device) /* Prepare CDB */ spt.cmd_length = sizeof(cdb); spt.cdb = cdb; - spt.cdb[0] = 0x1d; /* SCSI Send Diag Code */ - spt.cdb[1] = 0x10; /* PF bit is set to 1 */ + spt.cdb[0] = 0x1d; /* SCSI Send Diag Code */ + spt.cdb[1] = 0x10; /* PF bit is set to 1 */ spt.cdb[3] = 0x00; - spt.cdb[4] = 0x08; /* parameter length is 0x0008 */ + spt.cdb[4] = 0x08; /* parameter length is 0x0008 */ /* Prepare payload */ - spt.buffer[0] = 0x80; /* page code */ + spt.buffer[0] = 0x80; /* page code */ spt.buffer[2] = 0x00; - spt.buffer[3] = 0x04; /* page length */ + spt.buffer[3] = 0x04; /* page length */ spt.buffer[4] = 0x01; - spt.buffer[5] = 0x60; /* diagnostic id */ + spt.buffer[5] = 0x60; /* diagnostic id */ spt.data_direction = SCSI_DATA_OUT; spt.timeout = ibm_tape_get_timeout(priv->timeouts, spt.cdb[0]); - if (spt.timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (spt.timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Prepare sense buffer */ spt.sense_length = sizeof(sense); @@ -4299,8 +4298,7 @@ int lin_tape_ibmtape_forcedump_drive(void *device) /* Invoke SCSI command and check error */ rc = sioc_paththrough(device, &spt, &msg); - if (rc != DEVICE_GOOD) - lin_tape_ibmtape_process_errors(device, rc, msg, "force dump", false); + if (rc != DEVICE_GOOD) lin_tape_ibmtape_process_errors(device, rc, msg, "force dump", false); return rc; } @@ -4316,16 +4314,23 @@ int lin_tape_ibmtape_takedump_drive(void *device, bool nonforced_dump) char fname[1024]; time_t now; struct tm *tm_now; - unsigned char *serial = ((struct lin_tape_ibmtape *) device)->drive_serial; - struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *) device; + unsigned char *serial = ((struct lin_tape_ibmtape *)device)->drive_serial; + struct lin_tape_ibmtape *priv = (struct lin_tape_ibmtape *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_TAKEDUMPDRV)); /* Make base filename */ time(&now); tm_now = localtime(&now); - sprintf(fname_base, DMP_DIR "/ltfs_%s_%d_%02d%02d_%02d%02d%02d", serial, tm_now->tm_year + 1900, - tm_now->tm_mon + 1, tm_now->tm_mday, tm_now->tm_hour, tm_now->tm_min, tm_now->tm_sec); + sprintf(fname_base, + DMP_DIR "/ltfs_%s_%d_%02d%02d_%02d%02d%02d", + serial, + tm_now->tm_year + 1900, + tm_now->tm_mon + 1, + tm_now->tm_mday, + tm_now->tm_hour, + tm_now->tm_min, + tm_now->tm_sec); if (nonforced_dump) { strcpy(fname, fname_base); @@ -4349,7 +4354,7 @@ int lin_tape_ibmtape_takedump_drive(void *device, bool nonforced_dump) int lin_tape_ibmtape_get_worm_status(void *device, bool *is_worm) { int rc = 0; - struct lin_tape_ibmtape *priv = ((struct lin_tape_ibmtape *) device); + struct lin_tape_ibmtape *priv = ((struct lin_tape_ibmtape *)device); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_GETWORMSTAT)); if (priv->loaded) { @@ -4365,63 +4370,63 @@ int lin_tape_ibmtape_get_worm_status(void *device, bool *is_worm) } struct tape_ops lin_tape_ibmtape_drive_handler = { - .open = lin_tape_ibmtape_open, - .reopen = lin_tape_ibmtape_reopen, - .close = lin_tape_ibmtape_close, - .close_raw = lin_tape_ibmtape_close_raw, - .is_connected = lin_tape_ibmtape_is_connected, - .inquiry = lin_tape_ibmtape_inquiry, - .inquiry_page = lin_tape_ibmtape_inquiry_page, - .test_unit_ready = lin_tape_ibmtape_test_unit_ready, - .read = lin_tape_ibmtape_read, - .write = lin_tape_ibmtape_write, - .writefm = lin_tape_ibmtape_writefm, - .rewind = lin_tape_ibmtape_rewind, - .locate = lin_tape_ibmtape_locate, - .space = lin_tape_ibmtape_space, - .erase = lin_tape_ibmtape_erase, - .load = lin_tape_ibmtape_load, - .unload = lin_tape_ibmtape_unload, - .readpos = lin_tape_ibmtape_readpos, - .setcap = lin_tape_ibmtape_setcap, - .format = lin_tape_ibmtape_format, - .remaining_capacity = lin_tape_ibmtape_remaining_capacity, - .logsense = lin_tape_ibmtape_logsense, - .modesense = lin_tape_ibmtape_modesense, - .modeselect = lin_tape_ibmtape_modeselect, - .reserve_unit = lin_tape_ibmtape_reserve_unit, - .release_unit = lin_tape_ibmtape_release_unit, + .open = lin_tape_ibmtape_open, + .reopen = lin_tape_ibmtape_reopen, + .close = lin_tape_ibmtape_close, + .close_raw = lin_tape_ibmtape_close_raw, + .is_connected = lin_tape_ibmtape_is_connected, + .inquiry = lin_tape_ibmtape_inquiry, + .inquiry_page = lin_tape_ibmtape_inquiry_page, + .test_unit_ready = lin_tape_ibmtape_test_unit_ready, + .read = lin_tape_ibmtape_read, + .write = lin_tape_ibmtape_write, + .writefm = lin_tape_ibmtape_writefm, + .rewind = lin_tape_ibmtape_rewind, + .locate = lin_tape_ibmtape_locate, + .space = lin_tape_ibmtape_space, + .erase = lin_tape_ibmtape_erase, + .load = lin_tape_ibmtape_load, + .unload = lin_tape_ibmtape_unload, + .readpos = lin_tape_ibmtape_readpos, + .setcap = lin_tape_ibmtape_setcap, + .format = lin_tape_ibmtape_format, + .remaining_capacity = lin_tape_ibmtape_remaining_capacity, + .logsense = lin_tape_ibmtape_logsense, + .modesense = lin_tape_ibmtape_modesense, + .modeselect = lin_tape_ibmtape_modeselect, + .reserve_unit = lin_tape_ibmtape_reserve_unit, + .release_unit = lin_tape_ibmtape_release_unit, .prevent_medium_removal = lin_tape_ibmtape_prevent_medium_removal, - .allow_medium_removal = lin_tape_ibmtape_allow_medium_removal, - .write_attribute = lin_tape_ibmtape_write_attribute, - .read_attribute = lin_tape_ibmtape_read_attribute, - .allow_overwrite = lin_tape_ibmtape_allow_overwrite, - .grao = lin_tape_ibmtape_grao, - .rrao = lin_tape_ibmtape_rrao, + .allow_medium_removal = lin_tape_ibmtape_allow_medium_removal, + .write_attribute = lin_tape_ibmtape_write_attribute, + .read_attribute = lin_tape_ibmtape_read_attribute, + .allow_overwrite = lin_tape_ibmtape_allow_overwrite, + .grao = lin_tape_ibmtape_grao, + .rrao = lin_tape_ibmtape_rrao, // May be command combination - .set_compression = lin_tape_ibmtape_set_compression, - .set_default = lin_tape_ibmtape_set_default, - .get_cartridge_health = lin_tape_ibmtape_get_cartridge_health, - .get_tape_alert = lin_tape_ibmtape_get_tape_alert, - .clear_tape_alert = lin_tape_ibmtape_clear_tape_alert, - .get_xattr = lin_tape_ibmtape_get_xattr, - .set_xattr = lin_tape_ibmtape_set_xattr, - .get_parameters = lin_tape_ibmtape_get_parameters, - .get_eod_status = lin_tape_ibmtape_get_eod_status, - .get_device_list = lin_tape_ibmtape_get_device_list, - .help_message = lin_tape_ibmtape_help_message, - .parse_opts = lin_tape_ibmtape_parse_opts, - .default_device_name = lin_tape_ibmtape_default_device_name, - .set_key = lin_tape_ibmtape_set_key, - .get_keyalias = lin_tape_ibmtape_get_keyalias, - .takedump_drive = lin_tape_ibmtape_takedump_drive, - .is_mountable = lin_tape_ibmtape_is_mountable, - .get_worm_status = lin_tape_ibmtape_get_worm_status, - .get_serialnumber = lin_tape_ibmtape_get_serialnumber, - .get_info = lin_tape_ibmtape_get_info, - .set_profiler = lin_tape_ibmtape_set_profiler, + .set_compression = lin_tape_ibmtape_set_compression, + .set_default = lin_tape_ibmtape_set_default, + .get_cartridge_health = lin_tape_ibmtape_get_cartridge_health, + .get_tape_alert = lin_tape_ibmtape_get_tape_alert, + .clear_tape_alert = lin_tape_ibmtape_clear_tape_alert, + .get_xattr = lin_tape_ibmtape_get_xattr, + .set_xattr = lin_tape_ibmtape_set_xattr, + .get_parameters = lin_tape_ibmtape_get_parameters, + .get_eod_status = lin_tape_ibmtape_get_eod_status, + .get_device_list = lin_tape_ibmtape_get_device_list, + .help_message = lin_tape_ibmtape_help_message, + .parse_opts = lin_tape_ibmtape_parse_opts, + .default_device_name = lin_tape_ibmtape_default_device_name, + .set_key = lin_tape_ibmtape_set_key, + .get_keyalias = lin_tape_ibmtape_get_keyalias, + .takedump_drive = lin_tape_ibmtape_takedump_drive, + .is_mountable = lin_tape_ibmtape_is_mountable, + .get_worm_status = lin_tape_ibmtape_get_worm_status, + .get_serialnumber = lin_tape_ibmtape_get_serialnumber, + .get_info = lin_tape_ibmtape_get_info, + .set_profiler = lin_tape_ibmtape_set_profiler, .get_next_block_to_xfer = lin_tape_ibmtape_get_next_block_to_xfer, - .is_readonly = lin_tape_ibmtape_is_readonly, + .is_readonly = lin_tape_ibmtape_is_readonly, }; struct tape_ops *tape_dev_get_ops(void) diff --git a/src/tape_drivers/linux/sg/sg_scsi_tape.c b/src/tape_drivers/linux/sg/sg_scsi_tape.c index 310c50ae..729f0410 100644 --- a/src/tape_drivers/linux/sg/sg_scsi_tape.c +++ b/src/tape_drivers/linux/sg/sg_scsi_tape.c @@ -51,8 +51,8 @@ #include #include -#include "libltfs/ltfs_error.h" #include "libltfs/ltfs_endian.h" +#include "libltfs/ltfs_error.h" #include "libltfs/ltfslogging.h" #include "tape_drivers/vendor_compat.h" @@ -70,23 +70,21 @@ static int sg_sense2errno(sg_io_hdr_t *req, uint32_t *s, char **msg) unsigned char *sense = req->sbp; uint32_t sense_value = 0; - unsigned char sk = (*(sense + 2)) & 0x0F; - unsigned char asc = *(sense + 12); + unsigned char sk = (*(sense + 2)) & 0x0F; + unsigned char asc = *(sense + 12); unsigned char ascq = *(sense + 13); - sense_value += (uint32_t) sk << 16; - sense_value += (uint32_t) asc << 8; - sense_value += (uint32_t) ascq; + sense_value += (uint32_t)sk << 16; + sense_value += (uint32_t)asc << 8; + sense_value += (uint32_t)ascq; *s = sense_value; rc = _sense2errorcode(sense_value, standard_table, msg, MASK_WITH_SENSE_KEY); /* NOTE: error table must be changed in library edition */ - if (rc == -EDEV_VENDOR_UNIQUE) - rc = _sense2errorcode(sense_value, vendor_table, msg, MASK_WITH_SENSE_KEY); + if (rc == -EDEV_VENDOR_UNIQUE) rc = _sense2errorcode(sense_value, vendor_table, msg, MASK_WITH_SENSE_KEY); - if (rc == -EDEV_UNKNOWN && ((sense_value & 0xFF0000) == 0x040000) ) - rc = -EDEV_HARDWARE_ERROR; + if (rc == -EDEV_UNKNOWN && ((sense_value & 0xFF0000) == 0x040000)) rc = -EDEV_HARDWARE_ERROR; if (rc == -EDEV_UNKNOWN) { ltfsmsg(LTFS_INFO, 30287I, sense_value); @@ -95,52 +93,42 @@ static int sg_sense2errno(sg_io_hdr_t *req, uint32_t *s, char **msg) return rc; } -static bool is_expected_error(struct sg_tape *device, uint8_t *cdb, int32_t rc ) +static bool is_expected_error(struct sg_tape *device, uint8_t *cdb, int32_t rc) { - int cmd = (cdb[0]&0xFF); + int cmd = (cdb[0] & 0xFF); uint64_t destination; uint64_t cdb_dest[8]; int i; switch (cmd) { case TEST_UNIT_READY: - if (rc == -EDEV_NEED_INITIALIZE || rc == -EDEV_CONFIGURE_CHANGED) - return true; + if (rc == -EDEV_NEED_INITIALIZE || rc == -EDEV_CONFIGURE_CHANGED) return true; break; case READ: - if (rc == -EDEV_FILEMARK_DETECTED || rc == -EDEV_NO_SENSE || rc == -EDEV_CLEANING_REQUIRED) - return true; - if ((rc == -EDEV_CRYPTO_ERROR || rc == -EDEV_KEY_REQUIRED) && !device->is_data_key_set) - return true; + if (rc == -EDEV_FILEMARK_DETECTED || rc == -EDEV_NO_SENSE || rc == -EDEV_CLEANING_REQUIRED) return true; + if ((rc == -EDEV_CRYPTO_ERROR || rc == -EDEV_KEY_REQUIRED) && !device->is_data_key_set) return true; break; case WRITE: - if (rc == -EDEV_EARLY_WARNING || rc == -EDEV_PROG_EARLY_WARNING || rc == -EDEV_CLEANING_REQUIRED) - return true; + if (rc == -EDEV_EARLY_WARNING || rc == -EDEV_PROG_EARLY_WARNING || rc == -EDEV_CLEANING_REQUIRED) return true; break; case WRITE_FILEMARKS6: - if (rc == -EDEV_EARLY_WARNING || rc == -EDEV_PROG_EARLY_WARNING || rc == -EDEV_CLEANING_REQUIRED) - return true; + if (rc == -EDEV_EARLY_WARNING || rc == -EDEV_PROG_EARLY_WARNING || rc == -EDEV_CLEANING_REQUIRED) return true; break; case LOAD_UNLOAD: - if ((cdb[4] & 0x01) == 0) // Unload - if (rc == -EDEV_CLEANING_REQUIRED) - return true; + if ((cdb[4] & 0x01) == 0) // Unload + if (rc == -EDEV_CLEANING_REQUIRED) return true; break; case MODE_SELECT10: - if (rc == -EDEV_MODE_PARAMETER_ROUNDED) - return true; + if (rc == -EDEV_MODE_PARAMETER_ROUNDED) return true; break; case LOCATE16: - for (i=0; i<8; i++) - cdb_dest[i] = (uint64_t)cdb[i+4] & 0xff; + for (i = 0; i < 8; i++) + cdb_dest[i] = (uint64_t)cdb[i + 4] & 0xff; - destination = (cdb_dest[0] << 56) + (cdb_dest[1] << 48) - + (cdb_dest[2] << 40) + (cdb_dest[3] << 32) - + (cdb_dest[4] << 24) + (cdb_dest[5] << 16) - + (cdb_dest[6] << 8) + cdb_dest[7]; + destination = (cdb_dest[0] << 56) + (cdb_dest[1] << 48) + (cdb_dest[2] << 40) + (cdb_dest[3] << 32) + + (cdb_dest[4] << 24) + (cdb_dest[5] << 16) + (cdb_dest[6] << 8) + cdb_dest[7]; - if (destination == TAPE_BLOCK_MAX && rc == -EDEV_EOD_DETECTED) - return true; + if (destination == TAPE_BLOCK_MAX && rc == -EDEV_EOD_DETECTED) return true; break; } @@ -148,41 +136,41 @@ static bool is_expected_error(struct sg_tape *device, uint8_t *cdb, int32_t rc ) } /* Global functions */ -#define HOST_OK (0x00) -#define HOST_NO_CONNECT (0x01) -#define HOST_BUS_BUSY (0x02) -#define HOST_TIME_OUT (0x03) -#define HOST_BAD_TARGET (0x04) -#define HOST_ABORT (0x05) -#define HOST_PARITY (0x06) -#define HOST_ERROR (0x07) -#define HOST_RESET (0x08) -#define HOST_BAD_INTR (0x09) +#define HOST_OK (0x00) +#define HOST_NO_CONNECT (0x01) +#define HOST_BUS_BUSY (0x02) +#define HOST_TIME_OUT (0x03) +#define HOST_BAD_TARGET (0x04) +#define HOST_ABORT (0x05) +#define HOST_PARITY (0x06) +#define HOST_ERROR (0x07) +#define HOST_RESET (0x08) +#define HOST_BAD_INTR (0x09) #define HOST_PASSTHROUGH (0x0a) -#define HOST_SOFT_ERROR (0x0b) -#define HOST_IMM_RETRY (0x0c) -#define HOST_REQUEUE (0x0d) -#define HOST_TRANS_DISR (0x0e) -#define HOST_TRANS_FAIL (0x0f) +#define HOST_SOFT_ERROR (0x0b) +#define HOST_IMM_RETRY (0x0c) +#define HOST_REQUEUE (0x0d) +#define HOST_TRANS_DISR (0x0e) +#define HOST_TRANS_FAIL (0x0f) #define HOST_TARGET_FAIL (0x10) -#define HOST_NEXUS_FAIL (0x11) - -#define DRIVER_OK (0x00) -#define DRIVER_BUSY (0x01) -#define DRIVER_SOFT (0x02) -#define DRIVER_MEDIA (0x03) -#define DRIVER_ERROR (0x04) -#define DRIVER_INVALID (0x05) -#define DRIVER_TIMEOUT (0x06) -#define DRIVER_HARD (0x07) -#define DRIVER_SENSE (0x08) - -#define NO_SUGGESTION (0x00) -#define SUGGEST_RETRY (0x10) -#define SUGGEST_ABORT (0x20) -#define SUGGEST_REMAP (0x30) -#define SUGGEST_DIE (0x40) -#define SUGGEST_SENSE (0x80) +#define HOST_NEXUS_FAIL (0x11) + +#define DRIVER_OK (0x00) +#define DRIVER_BUSY (0x01) +#define DRIVER_SOFT (0x02) +#define DRIVER_MEDIA (0x03) +#define DRIVER_ERROR (0x04) +#define DRIVER_INVALID (0x05) +#define DRIVER_TIMEOUT (0x06) +#define DRIVER_HARD (0x07) +#define DRIVER_SENSE (0x08) + +#define NO_SUGGESTION (0x00) +#define SUGGEST_RETRY (0x10) +#define SUGGEST_ABORT (0x20) +#define SUGGEST_REMAP (0x30) +#define SUGGEST_DIE (0x40) +#define SUGGEST_SENSE (0x80) int sg_issue_cdb_command(struct sg_tape *device, sg_io_hdr_t *req, char **msg) { @@ -195,8 +183,7 @@ int sg_issue_cdb_command(struct sg_tape *device, sg_io_hdr_t *req, char **msg) CHECK_ARG_NULL(req, -LTFS_NULL_ARG); CHECK_ARG_NULL(msg, -LTFS_NULL_ARG); - if (device->fd < 0) - return -EDEV_NO_CONNECTION; + if (device->fd < 0) return -EDEV_NO_CONNECTION; start: ret = ioctl(device->fd, SG_IO, req); @@ -294,13 +281,12 @@ int sg_issue_cdb_command(struct sg_tape *device, sg_io_hdr_t *req, char **msg) break; } - if (ret) - return ret; + if (ret) return ret; } if (req->driver_status) { d_suggest = req->driver_status & 0xF0; - d_status = req->driver_status & 0x0F; + d_status = req->driver_status & 0x0F; switch (d_status) { case DRIVER_OK: @@ -342,24 +328,20 @@ int sg_issue_cdb_command(struct sg_tape *device, sg_io_hdr_t *req, char **msg) ret = -EDEV_DRIVER_ERROR; break; case SUGGEST_SENSE: - if (masked_status != SCSI_CHECK_CONDITION) - masked_status = SCSI_CHECK_CONDITION; + if (masked_status != SCSI_CHECK_CONDITION) masked_status = SCSI_CHECK_CONDITION; break; case SUGGEST_ABORT: case SUGGEST_REMAP: case SUGGEST_DIE: default: - if (!ret) - ret = -EDEV_DRIVER_ERROR; + if (!ret) ret = -EDEV_DRIVER_ERROR; break; } - if (ret) - return ret; + if (ret) return ret; } - if (masked_status != SCSI_CHECK_CONDITION) - masked_status = req->masked_status; + if (masked_status != SCSI_CHECK_CONDITION) masked_status = req->masked_status; switch (masked_status) { case SCSI_GOOD: @@ -414,8 +396,7 @@ static int _inquiry_low(struct sg_tape *device, uint8_t page, unsigned char *buf // Zero out the CDB and the result buffer ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(sense, 0, sizeof(sense)); @@ -423,21 +404,20 @@ static int _inquiry_low(struct sg_tape *device, uint8_t page, unsigned char *buf /* Build CDB */ cdb[0] = INQUIRY; - if(page) - cdb[1] = 0x01; + if (page) cdb[1] = 0x01; cdb[2] = page; ltfs_u16tobe(cdb + 3, size); /* Build request */ req.dxfer_direction = SCSI_FROM_TARGET_TO_INITIATOR; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.dxfer_len = size; - req.dxferp = buf; - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(10); - req.usr_ptr = (void *)cmd_desc; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.dxfer_len = size; + req.dxferp = buf; + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(10); + req.usr_ptr = (void *)cmd_desc; ret = sg_issue_cdb_command(device, &req, &msg); @@ -452,7 +432,7 @@ int sg_get_drive_identifier(struct sg_tape *device, scsi_device_identifier *id_d CHECK_ARG_NULL(id_data, -LTFS_NULL_ARG); ret = _inquiry_low(device, 0, inquiry_buf, MAX_INQ_LEN); - if( ret < 0 ) { + if (ret < 0) { ltfsmsg(LTFS_INFO, 30206I, ret); return ret; } @@ -464,17 +444,17 @@ int sg_get_drive_identifier(struct sg_tape *device, scsi_device_identifier *id_d return -EDEV_DEVICE_UNSUPPORTABLE; } - strncpy(id_data->vendor_id, (char*)(&(inquiry_buf[8])), VENDOR_ID_LENGTH); - strncpy(id_data->product_id, (char*)(&(inquiry_buf[16])), PRODUCT_ID_LENGTH); - strncpy(id_data->product_rev, (char*)(&(inquiry_buf[32])), PRODUCT_REV_LENGTH); + strncpy(id_data->vendor_id, (char *)(&(inquiry_buf[8])), VENDOR_ID_LENGTH); + strncpy(id_data->product_id, (char *)(&(inquiry_buf[16])), PRODUCT_ID_LENGTH); + strncpy(id_data->product_rev, (char *)(&(inquiry_buf[32])), PRODUCT_REV_LENGTH); ret = _inquiry_low(device, 0x80, inquiry_buf, MAX_INQ_LEN); - if( ret < 0 ) { + if (ret < 0) { ltfsmsg(LTFS_INFO, 30206I, ret); return ret; } - strncpy(id_data->unit_serial, (char*)(&(inquiry_buf[4])), inquiry_buf[3]); + strncpy(id_data->unit_serial, (char *)(&(inquiry_buf[4])), inquiry_buf[3]); return 0; } diff --git a/src/tape_drivers/linux/sg/sg_tape.c b/src/tape_drivers/linux/sg/sg_tape.c index 19f2beb8..7b91b215 100644 --- a/src/tape_drivers/linux/sg/sg_tape.c +++ b/src/tape_drivers/linux/sg/sg_tape.c @@ -47,25 +47,25 @@ ************************************************************************************* */ +#include #include #include #include -#include -#include #include +#include -#include "ltfs_copyright.h" -#include "libltfs/ltfslogging.h" +#include "kmi/key_format_ltfs.h" +#include "libltfs/arch/time_internal.h" #include "libltfs/fs.h" #include "libltfs/ltfs_endian.h" -#include "libltfs/arch/time_internal.h" -#include "kmi/key_format_ltfs.h" +#include "libltfs/ltfslogging.h" +#include "ltfs_copyright.h" /* Common header of backend */ -#include "reed_solomon_crc.h" #include "crc32c_crc.h" -#include "vendor_compat.h" #include "open_factor.h" +#include "reed_solomon_crc.h" +#include "vendor_compat.h" /* iokit functions */ #include "sg_scsi_tape.h" @@ -76,14 +76,15 @@ #include "libltfs/ltfs_fuse_version.h" #include -volatile char *copyright = LTFS_COPYRIGHT_0"\n"LTFS_COPYRIGHT_1"\n"LTFS_COPYRIGHT_2"\n" \ - LTFS_COPYRIGHT_3"\n"LTFS_COPYRIGHT_4"\n"LTFS_COPYRIGHT_5"\n"; +volatile char *copyright = LTFS_COPYRIGHT_0 "\n" LTFS_COPYRIGHT_1 "\n" LTFS_COPYRIGHT_2 "\n" LTFS_COPYRIGHT_3 + "\n" LTFS_COPYRIGHT_4 "\n" LTFS_COPYRIGHT_5 "\n"; -struct open_order { +struct open_order +{ char *devname; - int openfactor; - int host; - int channel; + int openfactor; + int host; + int channel; }; /* Default device name */ @@ -93,15 +94,15 @@ const char *default_device = "0"; struct sg_global_data global_data; /* Definitions */ -#define LOG_PAGE_HEADER_SIZE (4) +#define LOG_PAGE_HEADER_SIZE (4) #define LOG_PAGE_PARAMSIZE_OFFSET (3) -#define LOG_PAGE_PARAM_OFFSET (4) +#define LOG_PAGE_PARAM_OFFSET (4) #define SG_MAX_BLOCK_SIZE (1 * MB) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define TU_DEFAULT_TIMEOUT (60) -#define MAX_RETRY (100) +#define MAX_RETRY (100) #define MAX_TAKE_DUMP_ATTEMPTS (10) @@ -110,30 +111,31 @@ int sg_readpos(void *device, struct tc_position *pos); int sg_locate(void *device, struct tc_position dest, struct tc_position *pos); int sg_space(void *device, size_t count, TC_SPACE_TYPE type, struct tc_position *pos); int sg_logsense(void *device, const uint8_t page, const uint8_t subpage, unsigned char *buf, const size_t size); -int sg_modesense(void *device, const unsigned char page, const TC_MP_PC_TYPE pc, - const unsigned char subpage, unsigned char *buf, const size_t size); +int sg_modesense(void *device, + const unsigned char page, + const TC_MP_PC_TYPE pc, + const unsigned char subpage, + unsigned char *buf, + const size_t size); int sg_modeselect(void *device, unsigned char *buf, const size_t size); static const char *_generate_product_name(const char *product_id); /* Local functions */ -static inline int _parse_logPage(const unsigned char *logdata, - const uint16_t param, uint32_t *param_size, - unsigned char *buf, const size_t bufsize) +static inline int _parse_logPage( + const unsigned char *logdata, const uint16_t param, uint32_t *param_size, unsigned char *buf, const size_t bufsize) { const uint16_t page_len = ((uint16_t)logdata[2] << 8) | (uint16_t)logdata[3]; uint16_t param_code, param_len; uint32_t i = LOG_PAGE_HEADER_SIZE; uint32_t ret = -EDEV_INTERNAL_ERROR; - while(i < page_len) - { - param_code = ((uint16_t)logdata[i] << 8) | (uint16_t)logdata[i+1]; - param_len = (uint16_t)logdata[i + LOG_PAGE_PARAMSIZE_OFFSET]; + while (i < page_len) { + param_code = ((uint16_t)logdata[i] << 8) | (uint16_t)logdata[i + 1]; + param_len = (uint16_t)logdata[i + LOG_PAGE_PARAMSIZE_OFFSET]; - if (param_code == param) - { + if (param_code == param) { *param_size = param_len; - if(bufsize < param_len){ + if (bufsize < param_len) { memcpy(buf, &logdata[i + LOG_PAGE_PARAM_OFFSET], bufsize); ret = -EDEV_INTERNAL_ERROR; break; @@ -158,16 +160,12 @@ static inline int _parse_logPage(const unsigned char *logdata, * @return a pointer to the iokit backend on success or NULL on error */ -#define sg_opt(templ,offset,value) \ - { templ, offsetof(struct sg_global_data, offset), value } +#define sg_opt(templ, offset, value) { templ, offsetof(struct sg_global_data, offset), value } static struct fuse_opt sg_global_opts[] = { - sg_opt("scsi_lbprotect=%s", str_crc_checking, 0), - sg_opt("strict_drive", strict_drive, 1), - sg_opt("nostrict_drive", strict_drive, 0), - sg_opt("autodump", disable_auto_dump, 0), - sg_opt("noautodump", disable_auto_dump, 1), - FUSE_OPT_END + sg_opt("scsi_lbprotect=%s", str_crc_checking, 0), sg_opt("strict_drive", strict_drive, 1), + sg_opt("nostrict_drive", strict_drive, 0), sg_opt("autodump", disable_auto_dump, 0), + sg_opt("noautodump", disable_auto_dump, 1), FUSE_OPT_END }; static int null_parser(void *priv, const char *arg, int key, struct fuse_args *outargs) @@ -175,17 +173,17 @@ static int null_parser(void *priv, const char *arg, int key, struct fuse_args *o return 1; } -#define LBP_DISABLE (0x00) -#define REED_SOLOMON_CRC (0x01) -#define CRC32C_CRC (0x02) +#define LBP_DISABLE (0x00) +#define REED_SOLOMON_CRC (0x01) +#define CRC32C_CRC (0x02) -#define TC_MP_INIT_EXT_LBP_RS (0x40) -#define TC_MP_INIT_EXT_LBP_CRC32C (0x20) +#define TC_MP_INIT_EXT_LBP_RS (0x40) +#define TC_MP_INIT_EXT_LBP_CRC32C (0x20) static int _set_lbp(void *device, bool enable) { int ret = -EDEV_UNKNOWN; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; unsigned char buf[TC_MP_SUB_DP_CTRL_SIZE]; unsigned char buf_ext[TC_MP_INIT_EXT_SIZE]; @@ -194,8 +192,7 @@ static int _set_lbp(void *device, bool enable) /* Check logical block protection capability */ if (IS_ENTERPRISE(priv->drive_type)) { ret = sg_modesense(device, TC_MP_INIT_EXT, TC_MP_PC_CURRENT, 0x00, buf_ext, sizeof(buf_ext)); - if (ret < 0) - return ret; + if (ret < 0) return ret; if (buf_ext[0x12] & TC_MP_INIT_EXT_LBP_CRC32C) lbp_method = CRC32C_CRC; @@ -215,13 +212,11 @@ static int _set_lbp(void *device, bool enable) /* set logical block protection */ ltfsmsg(LTFS_DEBUG, 30393D, "LBP Enable", enable, ""); ltfsmsg(LTFS_DEBUG, 30393D, "LBP Method", lbp_method, ""); - ret = sg_modesense(device, TC_MP_CTRL, TC_MP_PC_CURRENT, - TC_MP_SUB_DP_CTRL, buf, sizeof(buf)); - if (ret < 0) - return ret; + ret = sg_modesense(device, TC_MP_CTRL, TC_MP_PC_CURRENT, TC_MP_SUB_DP_CTRL, buf, sizeof(buf)); + if (ret < 0) return ret; - buf[0] = 0x00; - buf[1] = 0x00; + buf[0] = 0x00; + buf[1] = 0x00; if (enable) { buf[20] = lbp_method; buf[21] = 0x04; @@ -246,13 +241,13 @@ static int _set_lbp(void *device, bool enable) priv->f_crc_check = rs_gf256_check; break; default: - priv->f_crc_enc = NULL; + priv->f_crc_enc = NULL; priv->f_crc_check = NULL; break; } ltfsmsg(LTFS_INFO, 30251I); } else { - priv->f_crc_enc = NULL; + priv->f_crc_enc = NULL; priv->f_crc_check = NULL; ltfsmsg(LTFS_INFO, 30252I); } @@ -275,7 +270,7 @@ static bool is_dump_required(struct sg_data *priv, int ret, bool *capture_unforc return ans; } -#define DUMP_HEADER_SIZE (4) +#define DUMP_HEADER_SIZE (4) #define DUMP_TRANSFER_SIZE (512 * KB) static int _cdb_read_buffer(void *device, int id, unsigned char *buf, size_t offset, size_t len, int type); @@ -285,20 +280,20 @@ static int _get_dump(struct sg_data *priv, char *fname) { int ret = 0; - long long data_length, buf_offset; - int dumpfd = -1; - int transfer_size, num_transfers, excess_transfer; - int i, bytes; - unsigned char cap_buf[DUMP_HEADER_SIZE]; - unsigned char *dump_buf; - int buf_id; + long long data_length, buf_offset; + int dumpfd = -1; + int transfer_size, num_transfers, excess_transfer; + int i, bytes; + unsigned char cap_buf[DUMP_HEADER_SIZE]; + unsigned char *dump_buf; + int buf_id; ltfsmsg(LTFS_INFO, 30253I, fname); /* Set transfer size */ transfer_size = DUMP_TRANSFER_SIZE; dump_buf = calloc(1, DUMP_TRANSFER_SIZE); - if(!dump_buf){ + if (!dump_buf) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -EDEV_NO_MEMORY; } @@ -315,18 +310,17 @@ static int _get_dump(struct sg_data *priv, char *fname) data_length = (cap_buf[1] << 16) + (cap_buf[2] << 8) + (int)cap_buf[3]; /* Open dump file for write only*/ - dumpfd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666); - if(dumpfd < 0){ + dumpfd = open(fname, O_WRONLY | O_CREAT | O_TRUNC, 0666); + if (dumpfd < 0) { ltfsmsg(LTFS_WARN, 30254W, errno); free(dump_buf); return -2; } /* get the total number of transfers */ - num_transfers = data_length / transfer_size; + num_transfers = data_length / transfer_size; excess_transfer = data_length % transfer_size; - if(excess_transfer) - num_transfers += 1; + if (excess_transfer) num_transfers += 1; /* Total dump data length is %lld. Total number of transfers is %d. */ ltfsmsg(LTFS_DEBUG, 30255D, data_length); @@ -336,14 +330,13 @@ static int _get_dump(struct sg_data *priv, char *fname) buf_offset = 0; i = 0; ltfsmsg(LTFS_DEBUG, 30257D); - while(num_transfers) - { + while (num_transfers) { int length; i++; /* Allocation Length is transfer_size or excess_transfer*/ - if(excess_transfer && num_transfers == 1) + if (excess_transfer && num_transfers == 1) length = excess_transfer; else length = transfer_size; @@ -358,16 +351,14 @@ static int _get_dump(struct sg_data *priv, char *fname) /* write buffer data into dump file */ bytes = write(dumpfd, dump_buf, length); - if(bytes == -1) - { + if (bytes == -1) { ltfsmsg(LTFS_WARN, 30259W, ret); free(dump_buf); close(dumpfd); return -1; } - if(bytes != length) - { + if (bytes != length) { ltfsmsg(LTFS_WARN, 30260W, bytes, length); free(dump_buf); close(dumpfd); @@ -388,9 +379,9 @@ static int _get_dump(struct sg_data *priv, char *fname) static int _take_dump(struct sg_data *priv, bool capture_unforced) { - char fname_base[1024]; - char fname[1024]; - time_t now; + char fname_base[1024]; + char fname[1024]; + time_t now; struct tm *tm_now; /* To check if the function became recursive */ @@ -400,8 +391,7 @@ static int _take_dump(struct sg_data *priv, bool capture_unforced) } priv->recursive_counter++; - if (priv->vendor != VENDOR_IBM) - return 0; + if (priv->vendor != VENDOR_IBM) return 0; /* Following logic is for IBM tape drives */ @@ -410,14 +400,15 @@ static int _take_dump(struct sg_data *priv, bool capture_unforced) /* Make base filename */ time(&now); tm_now = localtime(&now); - sprintf(fname_base, "/tmp/ltfs_%s_%d_%02d%02d_%02d%02d%02d" - , priv->drive_serial - , tm_now->tm_year+1900 - , tm_now->tm_mon+1 - , tm_now->tm_mday - , tm_now->tm_hour - , tm_now->tm_min - , tm_now->tm_sec); + sprintf(fname_base, + "/tmp/ltfs_%s_%d_%02d%02d_%02d%02d%02d", + priv->drive_serial, + tm_now->tm_year + 1900, + tm_now->tm_mon + 1, + tm_now->tm_mday, + tm_now->tm_hour, + tm_now->tm_min, + tm_now->tm_sec); if (capture_unforced) { ltfsmsg(LTFS_INFO, 30261I); @@ -500,17 +491,17 @@ static int _raw_open(struct sg_data *priv) priv->vendor = get_vendor_id(id_data.vendor_id); struct supported_device **cur = get_supported_devs(priv->vendor); - while(*cur) { - if((! strncmp(id_data.vendor_id, (*cur)->vendor_id, strlen((*cur)->vendor_id)) ) && - (! strncmp(id_data.product_id, (*cur)->product_id, strlen((*cur)->product_id)) ) ) { + while (*cur) { + if ((!strncmp(id_data.vendor_id, (*cur)->vendor_id, strlen((*cur)->vendor_id))) && + (!strncmp(id_data.product_id, (*cur)->product_id, strlen((*cur)->product_id)))) { drive_type = (*cur)->drive_type; break; } cur++; } - if(drive_type > 0) { - if (!drive_has_supported_fw(priv->vendor, drive_type, (unsigned char*)id_data.product_rev)) { + if (drive_type > 0) { + if (!drive_has_supported_fw(priv->vendor, drive_type, (unsigned char *)id_data.product_rev)) { close(priv->dev.fd); priv->dev.fd = -1; return -EDEV_UNSUPPORTED_FIRMWARE; @@ -535,11 +526,11 @@ static int _raw_open(struct sg_data *priv) strncpy(priv->drive_serial, id_data.unit_serial, sizeof(priv->drive_serial) - 1); /* Get SCSI ID */ - if (! ioctl(priv->dev.fd, SG_GET_SCSI_ID, &scsi_id)) { - priv->info.host = scsi_id.host_no; + if (!ioctl(priv->dev.fd, SG_GET_SCSI_ID, &scsi_id)) { + priv->info.host = scsi_id.host_no; priv->info.channel = scsi_id.channel; - priv->info.target = scsi_id.scsi_id; - priv->info.lun = scsi_id.lun; + priv->info.target = scsi_id.scsi_id; + priv->info.lun = scsi_id.lun; ltfsmsg(LTFS_INFO, 30250I, scsi_id.host_no, scsi_id.channel, scsi_id.scsi_id, scsi_id.lun, priv->devname); } else { ltfsmsg(LTFS_INFO, 30250I, 0, 0, 0, -1, priv->devname); @@ -550,12 +541,12 @@ static int _raw_open(struct sg_data *priv) ltfsmsg(LTFS_INFO, 30214I, id_data.product_rev); ltfsmsg(LTFS_INFO, 30215I, priv->drive_serial); - strncpy(priv->info.name, priv->devname, TAPE_DEVNAME_LEN_MAX + 1); - strncpy(priv->info.vendor, id_data.vendor_id, TAPE_VENDOR_NAME_LEN_MAX + 1); - strncpy(priv->info.model, id_data.product_id, TAPE_MODEL_NAME_LEN_MAX + 1); + strncpy(priv->info.name, priv->devname, TAPE_DEVNAME_LEN_MAX + 1); + strncpy(priv->info.vendor, id_data.vendor_id, TAPE_VENDOR_NAME_LEN_MAX + 1); + strncpy(priv->info.model, id_data.product_id, TAPE_MODEL_NAME_LEN_MAX + 1); strncpy(priv->info.serial_number, id_data.unit_serial, TAPE_SERIAL_LEN_MAX + 1); - strncpy(priv->info.product_rev, id_data.product_rev, PRODUCT_REV_LENGTH + 1); - strncpy(priv->info.product_name, _generate_product_name(id_data.product_id), PRODUCT_NAME_LENGTH + 1); + strncpy(priv->info.product_rev, id_data.product_rev, PRODUCT_REV_LENGTH + 1); + strncpy(priv->info.product_name, _generate_product_name(id_data.product_id), PRODUCT_NAME_LENGTH + 1); return 0; } @@ -563,7 +554,7 @@ static int _raw_open(struct sg_data *priv) int _raw_tur(const int fd) { int ret = -EDEV_UNKNOWN; - struct sg_tape dev = {fd, false}; + struct sg_tape dev = { fd, false }; sg_io_hdr_t req; unsigned char cdb[CDB6_LEN]; @@ -574,8 +565,7 @@ int _raw_tur(const int fd) /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(sense, 0, sizeof(sense)); @@ -586,12 +576,12 @@ int _raw_tur(const int fd) /* Build request */ req.dxfer_direction = SCSI_NO_DATA_TRANSFER; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; ret = sg_issue_cdb_command(&dev, &req, &msg); if (ret < 0) { @@ -664,9 +654,7 @@ int sg_get_device_list(struct tc_drive_info *buf, int count); int sg_reserve(void *device); static int _register_key(void *device, unsigned char *key); static int _fetch_reservation_key(void *device, struct reservation_info *r); -static int _cdb_pro(void *device, - enum pro_action action, enum pro_type type, - unsigned char *key, unsigned char *sakey); +static int _cdb_pro(void *device, enum pro_action action, enum pro_type type, unsigned char *key, unsigned char *sakey); static int _create_open_order(struct tc_drive_info *buf, struct open_order *order, const char *serial, int n) { @@ -674,15 +662,15 @@ static int _create_open_order(struct tc_drive_info *buf, struct open_order *orde int count = 0; for (i = 0; i < n; i++) { - if (! strncmp(buf[i].serial_number, serial, TAPE_SERIAL_LEN_MAX) ) { + if (!strncmp(buf[i].serial_number, serial, TAPE_SERIAL_LEN_MAX)) { order[count].devname = strdup(buf[i].name); if (!order[count].devname) { ltfsmsg(LTFS_ERR, 10001E, "sg_open: order"); return -EDEV_NO_MEMORY; } order[count].openfactor = get_openfactor(buf[i].host, buf[i].channel); - order[count].host = buf[i].host; - order[count].channel = buf[i].channel; + order[count].host = buf[i].host; + order[count].channel = buf[i].channel; count++; } } @@ -722,35 +710,33 @@ static void _order_free(struct open_order **order, int n) static int _reconnect_device(void *device) { int ret = -EDEV_UNKNOWN, f_ret; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; int i, devs = 0, info_devs = 0, count = 0; struct tc_drive_info *buf = NULL; struct open_order *order = NULL; struct reservation_info r_info; /* Close disconnected file descriptor */ - if (priv->dev.fd >= 0) - close(priv->dev.fd); + if (priv->dev.fd >= 0) close(priv->dev.fd); priv->dev.fd = -1; - if (priv->devname) - free(priv->devname); + if (priv->devname) free(priv->devname); priv->devname = NULL; priv->info.name[0] = '\0'; decrement_openfactor(priv->info.host, priv->info.channel); - priv->info.host = 0; + priv->info.host = 0; priv->info.channel = 0; - priv->info.target = 0; - priv->info.lun = -1; + priv->info.target = 0; + priv->info.lun = -1; /* Search another device files which has same serial number */ devs = sg_get_device_list(NULL, 0); if (devs) { buf = (struct tc_drive_info *)calloc(devs * 2, sizeof(struct tc_drive_info)); order = (struct open_order *)calloc(devs * 2, sizeof(struct open_order)); - if ( (!buf) || (!order) ) { + if ((!buf) || (!order)) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } @@ -787,8 +773,7 @@ static int _reconnect_device(void *device) return -EDEV_NO_MEMORY; } ret = _raw_open(priv); - if (!ret) - break; + if (!ret) break; } _order_free(&order, count); @@ -824,8 +809,7 @@ static int _reconnect_device(void *device) /* Select another path, recover reservation */ ltfsmsg(LTFS_INFO, 30269I, priv->drive_serial); _register_key(priv, priv->key); - ret = _cdb_pro(device, PRO_ACT_PREEMPT_ABORT, PRO_TYPE_EXCLUSIVE, - priv->key, priv->key); + ret = _cdb_pro(device, PRO_ACT_PREEMPT_ABORT, PRO_TYPE_EXCLUSIVE, priv->key, priv->key); if (!ret) { ltfsmsg(LTFS_INFO, 30272I, priv->drive_serial); _clear_por(priv); @@ -845,8 +829,7 @@ static int _reconnect_device(void *device) /* Select another path, recover reservation */ ltfsmsg(LTFS_INFO, 30269I, priv->drive_serial); _register_key(priv, priv->key); - ret = _cdb_pro(device, PRO_ACT_PREEMPT_ABORT, PRO_TYPE_EXCLUSIVE, - priv->key, priv->key); + ret = _cdb_pro(device, PRO_ACT_PREEMPT_ABORT, PRO_TYPE_EXCLUSIVE, priv->key, priv->key); if (!ret) { ltfsmsg(LTFS_INFO, 30272I, priv->drive_serial); _clear_por(priv); @@ -863,7 +846,7 @@ static int _reconnect_device(void *device) if (!ret) { ltfsmsg(LTFS_INFO, 30272I, priv->drive_serial); _clear_por(priv); - ret = -EDEV_REAL_POWER_ON_RESET; + ret = -EDEV_REAL_POWER_ON_RESET; } } else { /* Select same path */ @@ -882,8 +865,7 @@ static int _process_errors(struct sg_data *priv, int ret, char *msg, char *cmd, int ret_fo = 0; /* Error code while reconnecting process */ bool unforced_dump; - if (ret == -EDEV_NO_CONNECTION) - return ret; + if (ret == -EDEV_NO_CONNECTION) return ret; if (print) { if (msg != NULL) { @@ -902,8 +884,7 @@ static int _process_errors(struct sg_data *priv, int ret, char *msg, char *cmd, } if (priv && !ret_fo) { - if (print && take_dump && !global_data.disable_auto_dump - && is_dump_required(priv, ret, &unforced_dump)) { + if (print && take_dump && !global_data.disable_auto_dump && is_dump_required(priv, ret, &unforced_dump)) { (void)_take_dump(priv, unforced_dump); } } @@ -915,7 +896,7 @@ static int _cdb_read_buffer(void *device, int id, unsigned char *buf, size_t off { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; sg_io_hdr_t req; unsigned char cdb[CDB10_LEN]; @@ -928,8 +909,7 @@ static int _cdb_read_buffer(void *device, int id, unsigned char *buf, size_t off /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(sense, 0, sizeof(sense)); @@ -939,32 +919,30 @@ static int _cdb_read_buffer(void *device, int id, unsigned char *buf, size_t off cdb[1] = type; cdb[2] = id; cdb[3] = (unsigned char)(offset >> 16) & 0xFF; - cdb[4] = (unsigned char)(offset >> 8) & 0xFF; - cdb[5] = (unsigned char) offset & 0xFF; - cdb[6] = (unsigned char)(len >> 16) & 0xFF; - cdb[7] = (unsigned char)(len >> 8) & 0xFF; - cdb[8] = (unsigned char) len & 0xFF; + cdb[4] = (unsigned char)(offset >> 8) & 0xFF; + cdb[5] = (unsigned char)offset & 0xFF; + cdb[6] = (unsigned char)(len >> 16) & 0xFF; + cdb[7] = (unsigned char)(len >> 8) & 0xFF; + cdb[8] = (unsigned char)len & 0xFF; timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_TARGET_TO_INITIATOR; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.dxfer_len = len; - req.dxferp = buf; - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.dxfer_len = len; + req.dxferp = buf; + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; ret = sg_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } return ret; @@ -988,8 +966,7 @@ static int _cdb_force_dump(struct sg_data *priv) /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(sense, 0, sizeof(sense)); @@ -1008,25 +985,23 @@ static int _cdb_force_dump(struct sg_data *priv) buf[5] = 0x60; /* Diag ID */ timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_INITIATOR_TO_TARGET; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.dxfer_len = SENDDIAG_BUF_LEN; - req.dxferp = buf; - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.dxfer_len = SENDDIAG_BUF_LEN; + req.dxferp = buf; + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; ret = sg_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { ret_ep = _process_errors(priv, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } return ret; @@ -1036,7 +1011,7 @@ static int _cdb_pri(void *device, unsigned char *buf, int size) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; sg_io_hdr_t req; unsigned char cdb[CDB10_LEN]; @@ -1047,8 +1022,7 @@ static int _cdb_pri(void *device, unsigned char *buf, int size) /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(buf, 0, size); @@ -1058,29 +1032,27 @@ static int _cdb_pri(void *device, unsigned char *buf, int size) cdb[0] = PERSISTENT_RESERVE_IN; cdb[1] = 0x03; /* Full Info */ cdb[6] = (unsigned char)(size >> 16) & 0xFF; - cdb[7] = (unsigned char)(size >> 8) & 0xFF; - cdb[8] = (unsigned char) size & 0xFF; + cdb[7] = (unsigned char)(size >> 8) & 0xFF; + cdb[8] = (unsigned char)size & 0xFF; timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_TARGET_TO_INITIATOR; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.dxfer_len = size; - req.dxferp = buf; - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.dxfer_len = size; + req.dxferp = buf; + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; ret = sg_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } return ret; @@ -1125,7 +1097,6 @@ static int _fetch_reservation_key(void *device, struct reservation_info *r) addlen = ltfs_betou32(cur + 20); offset += (PRI_FULL_LEN_BASE + addlen); } - } /* Print holder information here */ @@ -1142,13 +1113,11 @@ static int _fetch_reservation_key(void *device, struct reservation_info *r) return ret; } -static int _cdb_pro(void *device, - enum pro_action action, enum pro_type type, - unsigned char *key, unsigned char *sakey) +static int _cdb_pro(void *device, enum pro_action action, enum pro_type type, unsigned char *key, unsigned char *sakey) { int ret = -EDEV_UNKNOWN, f_ret; int ret_ep = DEVICE_GOOD; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; sg_io_hdr_t req; unsigned char cdb[CDB10_LEN]; @@ -1162,8 +1131,7 @@ static int _cdb_pro(void *device, /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(buf, 0, sizeof(buf)); @@ -1176,46 +1144,49 @@ static int _cdb_pro(void *device, cdb[8] = PRO_BUF_LEN; /* parameter length */ /* Build parameter list, clear key when key is NULL */ - if (key) - memcpy(buf, key, KEYLEN); + if (key) memcpy(buf, key, KEYLEN); - if (sakey) - memcpy(buf + 8, sakey, KEYLEN); + if (sakey) memcpy(buf + 8, sakey, KEYLEN); timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_INITIATOR_TO_TARGET; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.dxfer_len = PRO_BUF_LEN; - req.dxferp = buf; - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.dxfer_len = PRO_BUF_LEN; + req.dxferp = buf; + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; ret = sg_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { if (ret == -EDEV_RESERVATION_CONFLICT && action == PRO_ACT_RESERVE) { /* Read reservation information and print */ memset(&r_info, 0x00, sizeof(r_info)); f_ret = _fetch_reservation_key(device, &r_info); if (!f_ret) { ltfsmsg(LTFS_WARN, 30266W, r_info.hint, priv->drive_serial); - ltfsmsg(LTFS_WARN, 30267W, - r_info.wwid[0], r_info.wwid[1], r_info.wwid[2], r_info.wwid[3], - r_info.wwid[6], r_info.wwid[5], r_info.wwid[6], r_info.wwid[7], - priv->drive_serial); + ltfsmsg(LTFS_WARN, + 30267W, + r_info.wwid[0], + r_info.wwid[1], + r_info.wwid[2], + r_info.wwid[3], + r_info.wwid[6], + r_info.wwid[5], + r_info.wwid[6], + r_info.wwid[7], + priv->drive_serial); } else { ltfsmsg(LTFS_WARN, 30266W, "unknown host (reserve command)", priv->drive_serial); } } else { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } } @@ -1227,12 +1198,9 @@ static int _register_key(void *device, unsigned char *key) int ret = -EDEV_UNKNOWN; start: - ret = _cdb_pro(device, PRO_ACT_REGISTER_IGNORE, PRO_TYPE_NONE, - NULL, key); + ret = _cdb_pro(device, PRO_ACT_REGISTER_IGNORE, PRO_TYPE_NONE, NULL, key); - if (ret == -EDEV_RESERVATION_PREEMPTED || - ret == -EDEV_RESERVATION_RELEASED || - ret == -EDEV_REGISTRATION_PREEMPTED ) + if (ret == -EDEV_RESERVATION_PREEMPTED || ret == -EDEV_RESERVATION_RELEASED || ret == -EDEV_REGISTRATION_PREEMPTED) goto start; return ret; @@ -1240,11 +1208,11 @@ static int _register_key(void *device, unsigned char *key) /** SCSI command handling of REPORT SUPPORTED OPERATION CODES */ -static int _cdb_rsoc(void* device, unsigned char *buf, uint32_t len) +static int _cdb_rsoc(void *device, unsigned char *buf, uint32_t len) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; sg_io_hdr_t req; unsigned char cdb[CDB12_LEN]; @@ -1255,8 +1223,7 @@ static int _cdb_rsoc(void* device, unsigned char *buf, uint32_t len) /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(buf, 0, len); @@ -1264,26 +1231,25 @@ static int _cdb_rsoc(void* device, unsigned char *buf, uint32_t len) /* Build CDB */ cdb[0] = MAINTENANCE_IN; - cdb[1] = 0x0C; /* REPORT SUPPORTED OPERATION CODES */ - cdb[2] = 0x80; /* Fetch all commands with RCTD */ + cdb[1] = 0x0C; /* REPORT SUPPORTED OPERATION CODES */ + cdb[2] = 0x80; /* Fetch all commands with RCTD */ ltfs_u32tobe(cdb + 6, len); /* allocation length */ /* Build request */ req.dxfer_direction = SCSI_FROM_TARGET_TO_INITIATOR; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.dxfer_len = len; - req.dxferp = buf; - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.dxfer_len = len; + req.dxferp = buf; + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; ret = sg_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } return ret; @@ -1311,7 +1277,7 @@ int sg_open(const char *devname, void **handle) ltfsmsg(LTFS_INFO, 30209I, devname); priv = calloc(1, sizeof(struct sg_data)); - if(!priv) { + if (!priv) { ltfsmsg(LTFS_ERR, 10001E, "sg_open: device private data"); return -EDEV_NO_MEMORY; } @@ -1329,9 +1295,9 @@ int sg_open(const char *devname, void **handle) ltfsmsg(LTFS_INFO, 30288I, devname); devs = sg_get_device_list(NULL, 0); if (devs) { - buf = (struct tc_drive_info *)calloc(devs * 2, sizeof(struct tc_drive_info)); + buf = (struct tc_drive_info *)calloc(devs * 2, sizeof(struct tc_drive_info)); order = (struct open_order *)calloc(devs * 2, sizeof(struct open_order)); - if ( (!buf) || (!order) ) { + if ((!buf) || (!order)) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } @@ -1405,8 +1371,7 @@ int sg_open(const char *devname, void **handle) * If it can be reserved successfully, this drive was reserved with same device file * on the previous session. If not, another instance is already reseerved. */ - ret = _cdb_pro(priv, PRO_ACT_RESERVE, PRO_TYPE_EXCLUSIVE, - priv->key, NULL); + ret = _cdb_pro(priv, PRO_ACT_RESERVE, PRO_TYPE_EXCLUSIVE, priv->key, NULL); if (!ret) { ltfsmsg(LTFS_INFO, 30291I, priv->devname); priv->is_reserved = true; @@ -1426,12 +1391,10 @@ int sg_open(const char *devname, void **handle) _order_free(&order, count); - if (ret < 0) - goto free; + if (ret < 0) goto free; } else { ret = _raw_open(priv); - if (ret < 0) - goto free; + if (ret < 0) goto free; } /* Configure reserved buffer to avoid ENOMEM if possible */ @@ -1457,8 +1420,7 @@ int sg_open(const char *devname, void **handle) if (!ret && rsoc_len < RSOC_BUF_SIZE) { ltfsmsg(LTFS_INFO, 30294I, "RSOC"); ret = init_timeout_rsoc(&priv->timeouts, rsoc_buf, rsoc_len); - if (!priv->timeouts) - ibm_tape_init_timeout(&priv->timeouts, priv->drive_type); + if (!priv->timeouts) ibm_tape_init_timeout(&priv->timeouts, priv->drive_type); } if (ret < 0) { @@ -1494,9 +1456,9 @@ int sg_open(const char *devname, void **handle) _register_key(priv, priv->key); /* Initial setting of force perm */ - priv->clear_by_pc = false; + priv->clear_by_pc = false; priv->force_writeperm = DEFAULT_WRITEPERM; - priv->force_readperm = DEFAULT_READPERM; + priv->force_readperm = DEFAULT_READPERM; priv->force_errortype = DEFAULT_ERRORTYPE; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_OPEN)); @@ -1506,8 +1468,7 @@ int sg_open(const char *devname, void **handle) free: ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_OPEN)); - if (priv->devname) - free(priv->devname); + if (priv->devname) free(priv->devname); free(priv); return ret; } @@ -1521,7 +1482,7 @@ int sg_reopen(const char *devname, void *device) int sg_close(void *device) { int ret = -EDEV_UNKNOWN; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_CLOSE)); @@ -1541,8 +1502,7 @@ int sg_close(void *device) priv->profiler = NULL; } - if (priv->devname) - free(priv->devname); + if (priv->devname) free(priv->devname); free(device); @@ -1552,7 +1512,7 @@ int sg_close(void *device) int sg_close_raw(void *device) { int ret = 0; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_CLOSERAW)); @@ -1580,7 +1540,7 @@ int sg_inquiry_page(void *device, unsigned char page, struct tc_inq_page *inq) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; sg_io_hdr_t req; unsigned char cdb[CDB6_LEN]; @@ -1594,39 +1554,35 @@ int sg_inquiry_page(void *device, unsigned char page, struct tc_inq_page *inq) /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(sense, 0, sizeof(sense)); /* Build CDB */ cdb[0] = INQUIRY; - if(page) - cdb[1] = 0x01; + if (page) cdb[1] = 0x01; cdb[2] = page; ltfs_u16tobe(cdb + 3, sizeof(inq->data)); timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_TARGET_TO_INITIATOR; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.dxfer_len = sizeof(inq->data); - req.dxferp = inq->data; - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.dxfer_len = sizeof(inq->data); + req.dxferp = inq->data; + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; ret = sg_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_INQUIRYPAGE)); @@ -1638,17 +1594,16 @@ int sg_inquiry(void *device, struct tc_inq *inq) { int ret = -EDEV_UNKNOWN; int vendor_length = 0; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; struct tc_inq_page inq_page; ret = sg_inquiry_page(device, 0x00, &inq_page); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(inq, 0, sizeof(struct tc_inq)); - strncpy((char*)inq->vid, (char*)inq_page.data + 8, VENDOR_ID_LENGTH); - strncpy((char*)inq->pid, (char*)inq_page.data + 16, PRODUCT_ID_LENGTH); - strncpy((char*)inq->revision, (char*)inq_page.data + 32, PRODUCT_REV_LENGTH); + strncpy((char *)inq->vid, (char *)inq_page.data + 8, VENDOR_ID_LENGTH); + strncpy((char *)inq->pid, (char *)inq_page.data + 16, PRODUCT_ID_LENGTH); + strncpy((char *)inq->revision, (char *)inq_page.data + 32, PRODUCT_REV_LENGTH); inq->devicetype = priv->drive_type; @@ -1657,7 +1612,7 @@ int sg_inquiry(void *device, struct tc_inq *inq) else vendor_length = 20; - strncpy((char*)inq->vendor, (char*)inq_page.data + 36, vendor_length); + strncpy((char *)inq->vendor, (char *)inq_page.data + 36, vendor_length); inq->vendor[vendor_length] = '\0'; return ret; @@ -1667,7 +1622,7 @@ int sg_test_unit_ready(void *device) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; sg_io_hdr_t req; unsigned char cdb[CDB6_LEN]; @@ -1681,8 +1636,7 @@ int sg_test_unit_ready(void *device) /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(sense, 0, sizeof(sense)); @@ -1690,20 +1644,19 @@ int sg_test_unit_ready(void *device) /* Build CDB */ cdb[0] = TEST_UNIT_READY; timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_NO_DATA_TRANSFER; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; ret = sg_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { bool print_msg = false, take_dump = false; switch (ret) { @@ -1725,8 +1678,7 @@ int sg_test_unit_ready(void *device) } ret_ep = _process_errors(device, ret, msg, cmd_desc, print_msg, take_dump); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_TUR)); @@ -1738,7 +1690,7 @@ static int _cdb_read(void *device, char *buf, size_t size, bool sili) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; sg_io_hdr_t req; unsigned char cdb[CDB6_LEN]; @@ -1750,38 +1702,35 @@ static int _cdb_read(void *device, char *buf, size_t size, bool sili) /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(sense, 0, sizeof(sense)); /* Build CDB */ cdb[0] = READ; - if(sili && priv->use_sili) - cdb[1] = 0x02; + if (sili && priv->use_sili) cdb[1] = 0x02; cdb[2] = (size >> 16) & 0xFF; - cdb[3] = (size >> 8) & 0xFF; - cdb[4] = size & 0xFF; + cdb[3] = (size >> 8) & 0xFF; + cdb[4] = size & 0xFF; timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_TARGET_TO_INITIATOR; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.dxfer_len = size; - req.dxferp = (unsigned char*)buf; - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; - req.flags = SG_FLAG_DIRECT_IO; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.dxfer_len = size; + req.dxferp = (unsigned char *)buf; + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; + req.flags = SG_FLAG_DIRECT_IO; ret = sg_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { int32_t diff_len = 0; unsigned char *sense = req.sbp; @@ -1798,10 +1747,10 @@ static int _cdb_read(void *device, char *buf, size_t size, bool sili) * In this case, LTFS will trust SCSI sense. */ if (diff_len < 0) { - ltfsmsg(LTFS_INFO, 30820I, diff_len, size - diff_len); // "Detect overrun condition" + ltfsmsg(LTFS_INFO, 30820I, diff_len, size - diff_len); // "Detect overrun condition" ret = -EDEV_OVERRUN; } else { - ltfsmsg(LTFS_DEBUG, 30821D, diff_len, size - diff_len); // "Detect underrun condition" + ltfsmsg(LTFS_DEBUG, 30821D, diff_len, size - diff_len); // "Detect underrun condition" length = size - diff_len; ret = DEVICE_GOOD; } @@ -1861,11 +1810,10 @@ static int _cdb_read(void *device, char *buf, size_t size, bool sili) return length; } -static inline int _handle_block_allocation_failure(void *device, struct tc_position *pos, - int *retry, char *op) +static inline int _handle_block_allocation_failure(void *device, struct tc_position *pos, int *retry, char *op) { int ret = 0; - struct tc_position tmp_pos = {0, 0}; + struct tc_position tmp_pos = { 0, 0 }; /* Sleep 3 secs to wait garbage correction in kernel side and retry */ ltfsmsg(LTFS_WARN, 30277W, ++(*retry)); @@ -1875,14 +1823,17 @@ static inline int _handle_block_allocation_failure(void *device, struct tc_posit if (ret == DEVICE_GOOD && pos->partition == tmp_pos.partition) { if (pos->block == tmp_pos.block) { /* Command is not reached to the drive */ - ltfsmsg(LTFS_INFO, 30278I, op, - (unsigned int)tmp_pos.partition, (unsigned long long)tmp_pos.block); + ltfsmsg(LTFS_INFO, 30278I, op, (unsigned int)tmp_pos.partition, (unsigned long long)tmp_pos.block); ret = -EDEV_RETRY; } else if (pos->block == tmp_pos.block - 1) { /* The drive received the command */ - ltfsmsg(LTFS_INFO, 30279I, op, - (unsigned int)pos->partition, (unsigned long long)pos->block, - (unsigned int)tmp_pos.partition, (unsigned long long)tmp_pos.block); + ltfsmsg(LTFS_INFO, + 30279I, + op, + (unsigned int)pos->partition, + (unsigned long long)pos->block, + (unsigned int)tmp_pos.partition, + (unsigned long long)tmp_pos.block); ret = sg_space(device, 1, TC_SPACE_B, pos); if (!ret) { ret = sg_readpos(device, &tmp_pos); @@ -1891,42 +1842,65 @@ static inline int _handle_block_allocation_failure(void *device, struct tc_posit ret = -EDEV_RETRY; } else if (!ret) { /* Skip back was successfully done, but not a expected position */ - ltfsmsg(LTFS_WARN, 30282W, op, - (unsigned int)pos->partition, (unsigned long long)pos->block, - (unsigned int)tmp_pos.partition, (unsigned long long)tmp_pos.block); + ltfsmsg(LTFS_WARN, + 30282W, + op, + (unsigned int)pos->partition, + (unsigned long long)pos->block, + (unsigned int)tmp_pos.partition, + (unsigned long long)tmp_pos.block); ret = -LTFS_BAD_LOCATE; } else { - ltfsmsg(LTFS_WARN, 30281W, op, ret, - (unsigned int)pos->partition, (unsigned long long)pos->block, - (unsigned int)tmp_pos.partition, (unsigned long long)tmp_pos.block); + ltfsmsg(LTFS_WARN, + 30281W, + op, + ret, + (unsigned int)pos->partition, + (unsigned long long)pos->block, + (unsigned int)tmp_pos.partition, + (unsigned long long)tmp_pos.block); } } else { - ltfsmsg(LTFS_WARN, 30283W, op, ret, - (unsigned int)pos->partition, (unsigned long long)pos->block, - (unsigned int)tmp_pos.partition, (unsigned long long)tmp_pos.block); + ltfsmsg(LTFS_WARN, + 30283W, + op, + ret, + (unsigned int)pos->partition, + (unsigned long long)pos->block, + (unsigned int)tmp_pos.partition, + (unsigned long long)tmp_pos.block); } } else { /* Unexpected position */ - ltfsmsg(LTFS_WARN, 30280W, op, ret, - (unsigned int)pos->partition, (unsigned long long)pos->block, - (unsigned int)tmp_pos.partition, (unsigned long long)tmp_pos.block); + ltfsmsg(LTFS_WARN, + 30280W, + op, + ret, + (unsigned int)pos->partition, + (unsigned long long)pos->block, + (unsigned int)tmp_pos.partition, + (unsigned long long)tmp_pos.block); ret = -EDEV_BUFFER_ALLOCATE_ERROR; } } else - ltfsmsg(LTFS_WARN, 30281W, op, ret, - (unsigned int)pos->partition, (unsigned long long)pos->block, - (unsigned int)tmp_pos.partition, (unsigned long long)tmp_pos.block); + ltfsmsg(LTFS_WARN, + 30281W, + op, + ret, + (unsigned int)pos->partition, + (unsigned long long)pos->block, + (unsigned int)tmp_pos.partition, + (unsigned long long)tmp_pos.block); return ret; } -int sg_read(void *device, char *buf, size_t size, - struct tc_position *pos, const bool unusual_size) +int sg_read(void *device, char *buf, size_t size, struct tc_position *pos, const bool unusual_size) { int32_t ret = -EDEV_UNKNOWN; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; size_t datacount = size; - struct tc_position pos_retry = {0, 0}; + struct tc_position pos_retry = { 0, 0 }; int retry_count = 0; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_READ)); @@ -1944,11 +1918,10 @@ int sg_read(void *device, char *buf, size_t size, } } - if(global_data.crc_checking) { + if (global_data.crc_checking) { datacount = size + 4; /* Never fall into this block, fail safe to adjust record length*/ - if (datacount > SG_MAX_BLOCK_SIZE) - datacount = SG_MAX_BLOCK_SIZE; + if (datacount > SG_MAX_BLOCK_SIZE) datacount = SG_MAX_BLOCK_SIZE; } start_read: @@ -1961,14 +1934,14 @@ int sg_read(void *device, char *buf, size_t size, return ret; } pos_retry.partition = pos->partition; - pos_retry.block = pos->block; + pos_retry.block = pos->block; ret = sg_locate(device, pos_retry, pos); if (ret) { ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_READ)); return ret; } goto start_read; - } else if ( !(pos->block) && unusual_size && (unsigned int)ret == size) { + } else if (!(pos->block) && unusual_size && (unsigned int)ret == size) { /* * Try to read again without sili bit, because some I/F doesn't support SILION read correctly * like USB connected LTO drive. @@ -1985,21 +1958,18 @@ int sg_read(void *device, char *buf, size_t size, ret = _cdb_read(device, buf, datacount, unusual_size); } else if (ret == -EDEV_BUFFER_ALLOCATE_ERROR && retry_count < MAX_RETRY) { ret = _handle_block_allocation_failure(device, pos, &retry_count, "read"); - if (ret == -EDEV_RETRY) - goto start_read; + if (ret == -EDEV_RETRY) goto start_read; } - if(ret == -EDEV_FILEMARK_DETECTED) - { + if (ret == -EDEV_FILEMARK_DETECTED) { pos->filemarks++; ret = DEVICE_GOOD; } - if(ret >= 0) { + if (ret >= 0) { pos->block++; - if(global_data.crc_checking && ret > 4) { - if (priv->f_crc_check) - ret = priv->f_crc_check(buf, ret - 4); + if (global_data.crc_checking && ret > 4) { + if (priv->f_crc_check) ret = priv->f_crc_check(buf, ret - 4); if (ret < 0) { ltfsmsg(LTFS_ERR, 30221E); _take_dump(priv, false); @@ -2016,7 +1986,7 @@ static int _cdb_write(void *device, uint8_t *buf, size_t size, bool *ew, bool *p { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; sg_io_hdr_t req; unsigned char cdb[CDB6_LEN]; @@ -2027,8 +1997,7 @@ static int _cdb_write(void *device, uint8_t *buf, size_t size, bool *ew, bool *p /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(sense, 0, sizeof(sense)); @@ -2037,30 +2006,29 @@ static int _cdb_write(void *device, uint8_t *buf, size_t size, bool *ew, bool *p cdb[0] = WRITE; cdb[1] = 0x00; /* Always variable in LTFS */ cdb[2] = (size >> 16) & 0xFF; - cdb[3] = (size >> 8) & 0xFF; - cdb[4] = size & 0xFF; + cdb[3] = (size >> 8) & 0xFF; + cdb[4] = size & 0xFF; timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_INITIATOR_TO_TARGET; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.dxfer_len = size; - req.dxferp = (unsigned char*)buf; - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; - req.flags = SG_FLAG_DIRECT_IO; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.dxfer_len = size; + req.dxferp = (unsigned char *)buf; + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; + req.flags = SG_FLAG_DIRECT_IO; *ew = false; *pew = false; ret = sg_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { switch (ret) { case -EDEV_EARLY_WARNING: ltfsmsg(LTFS_WARN, 30222W, "write"); @@ -2083,8 +2051,7 @@ static int _cdb_write(void *device, uint8_t *buf, size_t size, bool *ew, bool *p if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } } @@ -2095,7 +2062,7 @@ int sg_write(void *device, const char *buf, size_t count, struct tc_position *po { int ret, ret_fo; bool ew = false, pew = false; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; struct tc_position cur_pos; size_t datacount = count; int retry_count = 0; @@ -2104,16 +2071,16 @@ int sg_write(void *device, const char *buf, size_t count, struct tc_position *po ltfsmsg(LTFS_DEBUG3, 30395D, "write", count, priv->drive_serial); - if ( priv->force_writeperm ) { + if (priv->force_writeperm) { priv->write_counter++; - if ( priv->write_counter > priv->force_writeperm ) { + if (priv->write_counter > priv->force_writeperm) { ltfsmsg(LTFS_INFO, 30274I, "write"); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_WRITE)); if (priv->force_errortype) return -EDEV_NO_SENSE; else return -EDEV_WRITE_PERM; - } else if ( priv->write_counter > (priv->force_writeperm - THRESHOLD_FORCE_WRITE_NO_WRITE) ) { + } else if (priv->write_counter > (priv->force_writeperm - THRESHOLD_FORCE_WRITE_NO_WRITE)) { ltfsmsg(LTFS_INFO, 30275I); pos->block++; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_WRITE)); @@ -2121,9 +2088,8 @@ int sg_write(void *device, const char *buf, size_t count, struct tc_position *po } } - if(global_data.crc_checking) { - if (priv->f_crc_enc) - priv->f_crc_enc((void *)buf, count); + if (global_data.crc_checking) { + if (priv->f_crc_enc) priv->f_crc_enc((void *)buf, count); datacount = count + 4; } @@ -2136,8 +2102,7 @@ int sg_write(void *device, const char *buf, size_t count, struct tc_position *po } else if (ret == -EDEV_NEED_FAILOVER) { ret_fo = sg_readpos(device, &cur_pos); if (!ret_fo) { - if (pos->partition == cur_pos.partition - && pos->block + 1 == cur_pos.block) { + if (pos->partition == cur_pos.partition && pos->block + 1 == cur_pos.block) { pos->block++; pos->early_warning = cur_pos.early_warning; pos->programmable_early_warning = cur_pos.programmable_early_warning; @@ -2147,8 +2112,7 @@ int sg_write(void *device, const char *buf, size_t count, struct tc_position *po } } else if (ret == -EDEV_BUFFER_ALLOCATE_ERROR && retry_count < MAX_RETRY) { ret = _handle_block_allocation_failure(device, pos, &retry_count, "write"); - if (ret == -EDEV_RETRY) - goto start_write; + if (ret == -EDEV_RETRY) goto start_write; } ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_WRITE)); @@ -2160,7 +2124,7 @@ int sg_writefm(void *device, size_t count, struct tc_position *pos, bool immed) { int ret = -EDEV_UNKNOWN, ret_fo; int ret_ep = DEVICE_GOOD; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; sg_io_hdr_t req; unsigned char cdb[CDB6_LEN]; @@ -2177,35 +2141,32 @@ int sg_writefm(void *device, size_t count, struct tc_position *pos, bool immed) /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(sense, 0, sizeof(sense)); /* Build CDB */ cdb[0] = WRITE_FILEMARKS6; - if (immed) - cdb[1] = 0x01; + if (immed) cdb[1] = 0x01; cdb[2] = (count >> 16) & 0xFF; - cdb[3] = (count >> 8) & 0xFF; - cdb[4] = count & 0xFF; + cdb[3] = (count >> 8) & 0xFF; + cdb[4] = count & 0xFF; timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_NO_DATA_TRANSFER; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; ret = sg_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { switch (ret) { case -EDEV_EARLY_WARNING: ltfsmsg(LTFS_WARN, 30222W, "write filemarks"); @@ -2228,24 +2189,20 @@ int sg_writefm(void *device, size_t count, struct tc_position *pos, bool immed) if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } } - if(ret == DEVICE_GOOD) { + if (ret == DEVICE_GOOD) { ret = sg_readpos(device, pos); - if(ret == DEVICE_GOOD) { - if (ew && !pos->early_warning) - pos->early_warning = ew; - if (pew && !pos->programmable_early_warning) - pos->programmable_early_warning = pew; + if (ret == DEVICE_GOOD) { + if (ew && !pos->early_warning) pos->early_warning = ew; + if (pew && !pos->programmable_early_warning) pos->programmable_early_warning = pew; } } else if (ret == -EDEV_NEED_FAILOVER) { ret_fo = sg_readpos(device, &cur_pos); if (!ret_fo) { - if (pos->partition == cur_pos.partition - && pos->block + count == cur_pos.block) { + if (pos->partition == cur_pos.partition && pos->block + count == cur_pos.block) { pos->block++; pos->early_warning = cur_pos.early_warning; pos->programmable_early_warning = cur_pos.programmable_early_warning; @@ -2264,7 +2221,7 @@ int sg_rewind(void *device, struct tc_position *pos) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; sg_io_hdr_t req; unsigned char cdb[CDB6_LEN]; @@ -2278,8 +2235,7 @@ int sg_rewind(void *device, struct tc_position *pos) /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(sense, 0, sizeof(sense)); @@ -2288,39 +2244,37 @@ int sg_rewind(void *device, struct tc_position *pos) cdb[0] = REWIND; timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_NO_DATA_TRANSFER; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; ret = sg_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } - if(ret == DEVICE_GOOD) { + if (ret == DEVICE_GOOD) { /* Clear force perm setting */ - priv->clear_by_pc = false; + priv->clear_by_pc = false; priv->force_writeperm = DEFAULT_WRITEPERM; - priv->force_readperm = DEFAULT_READPERM; - priv->write_counter = 0; - priv->read_counter = 0; + priv->force_readperm = DEFAULT_READPERM; + priv->write_counter = 0; + priv->read_counter = 0; ret = sg_readpos(device, pos); - if(ret == DEVICE_GOOD) { - if(pos->early_warning) + if (ret == DEVICE_GOOD) { + if (pos->early_warning) ltfsmsg(LTFS_WARN, 30222W, "rewind"); - else if(pos->programmable_early_warning) + else if (pos->programmable_early_warning) ltfsmsg(LTFS_WARN, 30223W, "rewind"); } } @@ -2335,7 +2289,7 @@ int sg_locate(void *device, struct tc_position dest, struct tc_position *pos) int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; int ret_rp = DEVICE_GOOD; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; sg_io_hdr_t req; unsigned char cdb[CDB16_LEN]; @@ -2346,72 +2300,69 @@ int sg_locate(void *device, struct tc_position dest, struct tc_position *pos) bool pc = false; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_LOCATE)); - ltfsmsg(LTFS_DEBUG, 30397D, "locate", - (unsigned long long)dest.partition, - (unsigned long long)dest.block, - priv->drive_serial); + ltfsmsg(LTFS_DEBUG, + 30397D, + "locate", + (unsigned long long)dest.partition, + (unsigned long long)dest.block, + priv->drive_serial); if (pos->partition != dest.partition) { if (priv->clear_by_pc) { /* Clear force perm setting */ - priv->clear_by_pc = false; + priv->clear_by_pc = false; priv->force_writeperm = DEFAULT_WRITEPERM; - priv->force_readperm = DEFAULT_READPERM; - priv->write_counter = 0; - priv->read_counter = 0; + priv->force_readperm = DEFAULT_READPERM; + priv->write_counter = 0; + priv->read_counter = 0; } pc = true; } /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(sense, 0, sizeof(sense)); /* Build CDB */ - cdb[0] = LOCATE16; - if (pc) - cdb[1] = 0x02; /* Set Change partition(CP) flag */ - cdb[3] = (unsigned char)(dest.partition & 0xff); + cdb[0] = LOCATE16; + if (pc) cdb[1] = 0x02; /* Set Change partition(CP) flag */ + cdb[3] = (unsigned char)(dest.partition & 0xff); ltfs_u64tobe(cdb + 4, dest.block); timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_NO_DATA_TRANSFER; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; ret = sg_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { if (dest.block == TAPE_BLOCK_MAX && ret == -EDEV_EOD_DETECTED) { ltfsmsg(LTFS_DEBUG, 30224D, "Locate"); ret = DEVICE_GOOD; } else { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } } ret_rp = sg_readpos(device, pos); if (ret_rp == DEVICE_GOOD) { - if(pos->early_warning) + if (pos->early_warning) ltfsmsg(LTFS_WARN, 30222W, "locate"); - else if(pos->programmable_early_warning) + else if (pos->programmable_early_warning) ltfsmsg(LTFS_WARN, 30223W, "locate"); } else { - if (!ret) - ret = ret_rp; + if (!ret) ret = ret_rp; } ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_LOCATE)); @@ -2423,7 +2374,7 @@ int sg_space(void *device, size_t count, TC_SPACE_TYPE type, struct tc_position { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; sg_io_hdr_t req; unsigned char cdb[CDB16_LEN]; @@ -2436,34 +2387,30 @@ int sg_space(void *device, size_t count, TC_SPACE_TYPE type, struct tc_position /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(sense, 0, sizeof(sense)); /* Build CDB */ cdb[0] = SPACE16; - switch(type) { + switch (type) { case TC_SPACE_EOD: ltfsmsg(LTFS_DEBUG, 30392D, "space to EOD", priv->drive_serial); cdb[1] = 0x03; break; case TC_SPACE_FM_F: - ltfsmsg(LTFS_DEBUG, 30396D, "space forward file marks", (unsigned long long)count, - priv->drive_serial); + ltfsmsg(LTFS_DEBUG, 30396D, "space forward file marks", (unsigned long long)count, priv->drive_serial); cdb[1] = 0x01; ltfs_u64tobe(cdb + 4, count); break; case TC_SPACE_FM_B: - ltfsmsg(LTFS_DEBUG, 30396D, "space back file marks", (unsigned long long)count, - priv->drive_serial); + ltfsmsg(LTFS_DEBUG, 30396D, "space back file marks", (unsigned long long)count, priv->drive_serial); cdb[1] = 0x01; ltfs_u64tobe(cdb + 4, -count); break; case TC_SPACE_F: - ltfsmsg(LTFS_DEBUG, 30396D, "space forward records", (unsigned long long)count, - priv->drive_serial); + ltfsmsg(LTFS_DEBUG, 30396D, "space forward records", (unsigned long long)count, priv->drive_serial); cdb[1] = 0x00; ltfs_u64tobe(cdb + 4, count); break; @@ -2479,33 +2426,30 @@ int sg_space(void *device, size_t count, TC_SPACE_TYPE type, struct tc_position } timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_NO_DATA_TRANSFER; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; ret = sg_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { /* TODO: Need to confirm additional operation is required or not */ ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } - if(ret == DEVICE_GOOD) - ret = sg_readpos(device, pos); + if (ret == DEVICE_GOOD) ret = sg_readpos(device, pos); - if(ret == DEVICE_GOOD) { - if(pos->early_warning) + if (ret == DEVICE_GOOD) { + if (pos->early_warning) ltfsmsg(LTFS_WARN, 30222W, "space"); - else if(pos->programmable_early_warning) + else if (pos->programmable_early_warning) ltfsmsg(LTFS_WARN, 30223W, "space"); } @@ -2518,7 +2462,7 @@ static int _cdb_request_sense(void *device, unsigned char *buf, unsigned char si { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; sg_io_hdr_t req; unsigned char cdb[CDB6_LEN]; @@ -2529,8 +2473,7 @@ static int _cdb_request_sense(void *device, unsigned char *buf, unsigned char si /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(sense, 0, sizeof(sense)); @@ -2540,25 +2483,23 @@ static int _cdb_request_sense(void *device, unsigned char *buf, unsigned char si cdb[4] = (unsigned char)size; timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_TARGET_TO_INITIATOR; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.dxfer_len = size; - req.dxferp = buf; - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.dxfer_len = size; + req.dxferp = buf; + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; ret = sg_issue_cdb_command(&priv->dev, &req, &msg); if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } return ret; @@ -2568,7 +2509,7 @@ int sg_erase(void *device, struct tc_position *pos, bool long_erase) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; sg_io_hdr_t req; unsigned char cdb[CDB6_LEN]; @@ -2588,44 +2529,41 @@ int sg_erase(void *device, struct tc_position *pos, bool long_erase) /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(sense, 0, sizeof(sense)); /* Build CDB */ cdb[0] = ERASE; - if (long_erase) - cdb[1] = 0x03; + if (long_erase) cdb[1] = 0x03; timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_NO_DATA_TRANSFER; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; ret = sg_issue_cdb_command(&priv->dev, &req, &msg); if (long_erase) { unsigned char sense_buf[MAXSENSE]; - uint32_t sense_data; - uint32_t progress; + uint32_t sense_data; + uint32_t progress; while (ret == DEVICE_GOOD) { memset(sense_buf, 0, sizeof(sense_buf)); - ret= _cdb_request_sense(device, sense_buf, sizeof(sense_buf)); + ret = _cdb_request_sense(device, sense_buf, sizeof(sense_buf)); - sense_data = ((uint32_t) sense_buf[2] & 0x0F) << 16; - sense_data += ((uint32_t) sense_buf[12] & 0xFF) << 8; - sense_data += ((uint32_t) sense_buf[13] & 0xFF); + sense_data = ((uint32_t)sense_buf[2] & 0x0F) << 16; + sense_data += ((uint32_t)sense_buf[12] & 0xFF) << 8; + sense_data += ((uint32_t)sense_buf[13] & 0xFF); if (sense_data != 0x000016 && sense_data != 0x000018) { /* Erase operation is NOT in progress */ @@ -2634,21 +2572,20 @@ int sg_erase(void *device, struct tc_position *pos, bool long_erase) if (IS_ENTERPRISE(priv->drive_type)) { get_current_timespec(&ts_now); - ltfsmsg(LTFS_INFO, 30226I, (int)(ts_now.tv_sec - ts_start.tv_sec)/60); + ltfsmsg(LTFS_INFO, 30226I, (int)(ts_now.tv_sec - ts_start.tv_sec) / 60); } else { - progress = ((uint32_t) sense_buf[16] & 0xFF) << 8; - progress += ((uint32_t) sense_buf[17] & 0xFF); - ltfsmsg(LTFS_INFO, 30227I, (progress*100/0xFFFF)); + progress = ((uint32_t)sense_buf[16] & 0xFF) << 8; + progress += ((uint32_t)sense_buf[17] & 0xFF); + ltfsmsg(LTFS_INFO, 30227I, (progress * 100 / 0xFFFF)); } sleep(60); } } - if (ret < 0){ + if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_ERASE)); @@ -2660,7 +2597,7 @@ static int _cdb_load_unload(void *device, bool load) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; sg_io_hdr_t req; unsigned char cdb[CDB6_LEN]; @@ -2671,38 +2608,34 @@ static int _cdb_load_unload(void *device, bool load) /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(sense, 0, sizeof(sense)); /* Build CDB */ cdb[0] = LOAD_UNLOAD; - if (load) - cdb[4] = 0x01; + if (load) cdb[4] = 0x01; timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_NO_DATA_TRANSFER; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; ret = sg_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { if (ret == -EDEV_MEDIUM_MAY_BE_CHANGED) { ret = DEVICE_GOOD; } else { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } } @@ -2712,7 +2645,7 @@ static int _cdb_load_unload(void *device, bool load) int sg_load(void *device, struct tc_position *pos) { int ret = -EDEV_UNKNOWN; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; unsigned char buf[TC_MP_SUPPORTEDPAGE_SIZE]; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_LOAD)); @@ -2721,21 +2654,21 @@ int sg_load(void *device, struct tc_position *pos) ret = _cdb_load_unload(device, true); /* Clear force perm setting */ - priv->clear_by_pc = false; + priv->clear_by_pc = false; priv->force_writeperm = DEFAULT_WRITEPERM; - priv->force_readperm = DEFAULT_READPERM; - priv->write_counter = 0; - priv->read_counter = 0; + priv->force_readperm = DEFAULT_READPERM; + priv->write_counter = 0; + priv->read_counter = 0; sg_readpos(device, pos); if (ret < 0) { ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_LOAD)); return ret; } else { - if(ret == DEVICE_GOOD) { - if(pos->early_warning) + if (ret == DEVICE_GOOD) { + if (pos->early_warning) ltfsmsg(LTFS_WARN, 30222W, "load"); - else if(pos->programmable_early_warning) + else if (pos->programmable_early_warning) ltfsmsg(LTFS_WARN, 30223W, "load"); } @@ -2755,8 +2688,7 @@ int sg_load(void *device, struct tc_position *pos) if (priv->vendor == VENDOR_HP) { priv->cart_type = assume_cart_type(priv->density_code); - if (buf[2] == 0x01) - priv->is_worm = true; + if (buf[2] == 0x01) priv->is_worm = true; } else { priv->cart_type = buf[2]; } @@ -2768,8 +2700,7 @@ int sg_load(void *device, struct tc_position *pos) } ret = is_supported_tape(priv->cart_type, priv->density_code, &(priv->is_worm)); - if(ret == -LTFS_UNSUPPORTED_MEDIUM) - ltfsmsg(LTFS_INFO, 30228I, priv->cart_type, priv->density_code); + if (ret == -LTFS_UNSUPPORTED_MEDIUM) ltfsmsg(LTFS_INFO, 30228I, priv->cart_type, priv->density_code); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_LOAD)); @@ -2779,7 +2710,7 @@ int sg_load(void *device, struct tc_position *pos) int sg_unload(void *device, struct tc_position *pos) { int ret = -EDEV_UNKNOWN; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_UNLOAD)); ltfsmsg(LTFS_DEBUG, 30392D, "unload", priv->drive_serial); @@ -2787,11 +2718,11 @@ int sg_unload(void *device, struct tc_position *pos) ret = _cdb_load_unload(device, false); /* Clear force perm setting */ - priv->clear_by_pc = false; + priv->clear_by_pc = false; priv->force_writeperm = DEFAULT_WRITEPERM; - priv->force_readperm = DEFAULT_READPERM; - priv->write_counter = 0; - priv->read_counter = 0; + priv->force_readperm = DEFAULT_READPERM; + priv->write_counter = 0; + priv->read_counter = 0; if (ret < 0) { sg_readpos(device, pos); @@ -2799,12 +2730,12 @@ int sg_unload(void *device, struct tc_position *pos) return ret; } - priv->loaded = false; - priv->cart_type = 0; + priv->loaded = false; + priv->cart_type = 0; priv->density_code = 0; - priv->tape_alert = 0; - pos->partition = 0; - pos->block = 0; + priv->tape_alert = 0; + pos->partition = 0; + pos->block = 0; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_UNLOAD)); @@ -2815,7 +2746,7 @@ int sg_readpos(void *device, struct tc_position *pos) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; sg_io_hdr_t req; unsigned char cdb[CDB10_LEN]; @@ -2829,8 +2760,7 @@ int sg_readpos(void *device, struct tc_position *pos) /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(sense, 0, sizeof(sense)); @@ -2840,35 +2770,37 @@ int sg_readpos(void *device, struct tc_position *pos) cdb[1] = 0x06; /* Long Format */ timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_TARGET_TO_INITIATOR; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.dxfer_len = sizeof(buf); - req.dxferp = buf; - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.dxfer_len = sizeof(buf); + req.dxferp = buf; + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; ret = sg_issue_cdb_command(&priv->dev, &req, &msg); if (ret == DEVICE_GOOD) { pos->partition = ltfs_betou32(buf + 4); - pos->block = ltfs_betou64(buf + 8); + pos->block = ltfs_betou64(buf + 8); pos->filemarks = ltfs_betou64(buf + 16); pos->early_warning = buf[0] & 0x40; pos->programmable_early_warning = buf[0] & 0x01; - ltfsmsg(LTFS_DEBUG, 30398D, "readpos", (unsigned long long)pos->partition, - (unsigned long long)pos->block, (unsigned long long)pos->filemarks, - priv->drive_serial); + ltfsmsg(LTFS_DEBUG, + 30398D, + "readpos", + (unsigned long long)pos->partition, + (unsigned long long)pos->block, + (unsigned long long)pos->filemarks, + priv->drive_serial); } else { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_READPOS)); @@ -2880,7 +2812,7 @@ int sg_setcap(void *device, uint16_t proportion) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; sg_io_hdr_t req; unsigned char cdb[CDB6_LEN]; @@ -2908,17 +2840,16 @@ int sg_setcap(void *device, uint16_t proportion) return ret; } - buf[0] = 0x00; - buf[1] = 0x00; + buf[0] = 0x00; + buf[1] = 0x00; buf[27] |= 0x01; - buf[28] = 0x00; + buf[28] = 0x00; ret = sg_modeselect(device, buf, sizeof(buf)); } else { /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(sense, 0, sizeof(sense)); @@ -2928,23 +2859,21 @@ int sg_setcap(void *device, uint16_t proportion) ltfs_u16tobe(cdb + 3, proportion); timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_NO_DATA_TRANSFER; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; ret = sg_issue_cdb_command(&priv->dev, &req, &msg); if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } } @@ -2953,11 +2882,12 @@ int sg_setcap(void *device, uint16_t proportion) return ret; } -int sg_format(void *device, TC_FORMAT_TYPE format, const char *vol_name, const char *barcode_name, const char *vol_mam_uuid) +int sg_format( + void *device, TC_FORMAT_TYPE format, const char *vol_name, const char *barcode_name, const char *vol_mam_uuid) { int ret = -EDEV_UNKNOWN, aux_ret; int ret_ep = DEVICE_GOOD; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; unsigned char buf[TC_MP_SUPPORTEDPAGE_SIZE]; sg_io_hdr_t req; @@ -2972,8 +2902,7 @@ int sg_format(void *device, TC_FORMAT_TYPE format, const char *vol_name, const c /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(sense, 0, sizeof(sense)); @@ -2983,23 +2912,21 @@ int sg_format(void *device, TC_FORMAT_TYPE format, const char *vol_name, const c cdb[2] = format; timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_NO_DATA_TRANSFER; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; ret = sg_issue_cdb_command(&priv->dev, &req, &msg); if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } /* Check Cartridge type */ @@ -3017,9 +2944,9 @@ int sg_format(void *device, TC_FORMAT_TYPE format, const char *vol_name, const c int sg_remaining_capacity(void *device, struct tc_remaining_cap *cap) { int ret = -EDEV_UNKNOWN; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; - unsigned char buffer[LOGSENSEPAGE]; /* Buffer for logsense */ + unsigned char buffer[LOGSENSEPAGE]; /* Buffer for logsense */ unsigned char buf[LOG_TAPECAPACITY_SIZE]; /* Buffer for parsing logsense data */ uint32_t param_size; int32_t i; @@ -3034,17 +2961,14 @@ int sg_remaining_capacity(void *device, struct tc_remaining_cap *cap) if (IS_LTO(priv->drive_type) && (DRIVE_GEN(priv->drive_type) == 0x05)) { /* Use LogPage 0x31 */ ret = sg_logsense(device, (uint8_t)LOG_TAPECAPACITY, (uint8_t)0, (void *)buffer, LOGSENSEPAGE); - if(ret < 0) - { + if (ret < 0) { ltfsmsg(LTFS_INFO, 30229I, LOG_VOLUMESTATS, ret); goto out; } - for( i = TAPECAP_REMAIN_0; i < TAPECAP_SIZE; i++) - { + for (i = TAPECAP_REMAIN_0; i < TAPECAP_SIZE; i++) { ret = _parse_logPage(buffer, (uint16_t)i, ¶m_size, buf, sizeof(buf)); - if(ret < 0 || param_size != sizeof(uint32_t)) - { + if (ret < 0 || param_size != sizeof(uint32_t)) { ltfsmsg(LTFS_INFO, 30230I, i, param_size); ret = -EDEV_INTERNAL_ERROR; goto out; @@ -3052,8 +2976,7 @@ int sg_remaining_capacity(void *device, struct tc_remaining_cap *cap) logcap = ltfs_betou32(buf); - switch(i) - { + switch (i) { case TAPECAP_REMAIN_0: cap->remaining_p0 = logcap; break; @@ -3075,13 +2998,14 @@ int sg_remaining_capacity(void *device, struct tc_remaining_cap *cap) } if (global_data.capacity_offset) { - if (cap->remaining_p1 < global_data.capacity_offset) - cap_offset = cap->remaining_p1; - - ltfsmsg(LTFS_INFO, 30276I, 1, - (unsigned long long)cap->remaining_p1, - (unsigned long long)global_data.capacity_offset, - priv->drive_serial); + if (cap->remaining_p1 < global_data.capacity_offset) cap_offset = cap->remaining_p1; + + ltfsmsg(LTFS_INFO, + 30276I, + 1, + (unsigned long long)cap->remaining_p1, + (unsigned long long)global_data.capacity_offset, + priv->drive_serial); cap->remaining_p1 -= cap_offset; } @@ -3089,8 +3013,7 @@ int sg_remaining_capacity(void *device, struct tc_remaining_cap *cap) } else { /* Use LogPage 0x17 */ ret = sg_logsense(device, LOG_VOLUMESTATS, (uint8_t)0, (void *)buffer, LOGSENSEPAGE); - if(ret < 0) - { + if (ret < 0) { ltfsmsg(LTFS_INFO, 30229I, LOG_VOLUMESTATS, ret); goto out; } @@ -3128,13 +3051,14 @@ int sg_remaining_capacity(void *device, struct tc_remaining_cap *cap) } if (global_data.capacity_offset) { - if (cap->remaining_p1 < global_data.capacity_offset) - cap_offset = cap->remaining_p1; - - ltfsmsg(LTFS_INFO, 30276I, 1, - (unsigned long long)cap->remaining_p1, - (unsigned long long)global_data.capacity_offset, - priv->drive_serial); + if (cap->remaining_p1 < global_data.capacity_offset) cap_offset = cap->remaining_p1; + + ltfsmsg(LTFS_INFO, + 30276I, + 1, + (unsigned long long)cap->remaining_p1, + (unsigned long long)global_data.capacity_offset, + priv->drive_serial); cap->remaining_p1 -= cap_offset; } @@ -3147,22 +3071,29 @@ int sg_remaining_capacity(void *device, struct tc_remaining_cap *cap) ret = DEVICE_GOOD; } - ltfsmsg(LTFS_DEBUG3, 30397D, "capacity part0", (unsigned long long)cap->remaining_p0, - (unsigned long long)cap->max_p0, priv->drive_serial); - ltfsmsg(LTFS_DEBUG3, 30397D, "capacity part1", (unsigned long long)cap->remaining_p1, - (unsigned long long)cap->max_p1, priv->drive_serial); + ltfsmsg(LTFS_DEBUG3, + 30397D, + "capacity part0", + (unsigned long long)cap->remaining_p0, + (unsigned long long)cap->max_p0, + priv->drive_serial); + ltfsmsg(LTFS_DEBUG3, + 30397D, + "capacity part1", + (unsigned long long)cap->remaining_p1, + (unsigned long long)cap->max_p1, + priv->drive_serial); out: ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_REMAINCAP)); return ret; } -int sg_logsense(void *device, const uint8_t page, const uint8_t subpage, - unsigned char *buf, const size_t size) +int sg_logsense(void *device, const uint8_t page, const uint8_t subpage, unsigned char *buf, const size_t size) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; sg_io_hdr_t req; unsigned char cdb[CDB10_LEN]; @@ -3175,12 +3106,10 @@ int sg_logsense(void *device, const uint8_t page, const uint8_t subpage, unsigned char *inner_buf = NULL; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_LOGSENSE)); - ltfsmsg(LTFS_DEBUG3, 30397D, "logsense", - (unsigned long long)page, (unsigned long long)subpage, priv->drive_serial); + ltfsmsg(LTFS_DEBUG3, 30397D, "logsense", (unsigned long long)page, (unsigned long long)subpage, priv->drive_serial); inner_buf = calloc(1, MAXLP_SIZE); /* Assume max length of LP is 0xFFFF */ - if (!inner_buf) - return -LTFS_NO_MEMORY; + if (!inner_buf) return -LTFS_NO_MEMORY; /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); @@ -3206,20 +3135,19 @@ int sg_logsense(void *device, const uint8_t page, const uint8_t subpage, /* Build request */ req.dxfer_direction = SCSI_FROM_TARGET_TO_INITIATOR; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.dxfer_len = MAXLP_SIZE; - req.dxferp = inner_buf; - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.dxfer_len = MAXLP_SIZE; + req.dxferp = inner_buf; + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; ret = sg_issue_cdb_command(&priv->dev, &req, &msg); if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } else { len = ((int)inner_buf[2] << 8) + (int)inner_buf[3] + 4; @@ -3231,18 +3159,22 @@ int sg_logsense(void *device, const uint8_t page, const uint8_t subpage, ret = len; } - free (inner_buf); + free(inner_buf); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_LOGSENSE)); return ret; } -int sg_modesense(void *device, const unsigned char page, const TC_MP_PC_TYPE pc, - const unsigned char subpage, unsigned char *buf, const size_t size) +int sg_modesense(void *device, + const unsigned char page, + const TC_MP_PC_TYPE pc, + const unsigned char subpage, + unsigned char *buf, + const size_t size) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; sg_io_hdr_t req; unsigned char cdb[CDB10_LEN]; @@ -3256,8 +3188,7 @@ int sg_modesense(void *device, const unsigned char page, const TC_MP_PC_TYPE pc, /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(sense, 0, sizeof(sense)); @@ -3269,25 +3200,23 @@ int sg_modesense(void *device, const unsigned char page, const TC_MP_PC_TYPE pc, ltfs_u16tobe(cdb + 7, size); timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_TARGET_TO_INITIATOR; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.dxfer_len = size; - req.dxferp = buf; - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.dxfer_len = size; + req.dxferp = buf; + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; ret = sg_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } else { ret = size - req.resid; } @@ -3301,7 +3230,7 @@ int sg_modeselect(void *device, unsigned char *buf, const size_t size) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; sg_io_hdr_t req; unsigned char cdb[CDB10_LEN]; @@ -3315,8 +3244,7 @@ int sg_modeselect(void *device, unsigned char *buf, const size_t size) /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(sense, 0, sizeof(sense)); @@ -3327,25 +3255,23 @@ int sg_modeselect(void *device, unsigned char *buf, const size_t size) ltfs_u16tobe(cdb + 7, size); timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_INITIATOR_TO_TARGET; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.dxfer_len = size; - req.dxferp = buf; - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.dxfer_len = size; + req.dxferp = buf; + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; ret = sg_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_MODESELECT)); @@ -3356,29 +3282,24 @@ int sg_modeselect(void *device, unsigned char *buf, const size_t size) int sg_reserve(void *device) { int ret = -EDEV_UNKNOWN, count = 0; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_RESERVEUNIT)); ltfsmsg(LTFS_DEBUG, 30392D, "reserve (PRO)", priv->drive_serial); start: - ret = _cdb_pro(device, PRO_ACT_RESERVE, PRO_TYPE_EXCLUSIVE, - priv->key, NULL); + ret = _cdb_pro(device, PRO_ACT_RESERVE, PRO_TYPE_EXCLUSIVE, priv->key, NULL); /* Retry if reservation is preempted */ - if ( !count && - ( ret == -EDEV_RESERVATION_PREEMPTED || - ret == -EDEV_REGISTRATION_PREEMPTED || - ret == -EDEV_RESERVATION_CONFLICT) - ) { + if (!count && (ret == -EDEV_RESERVATION_PREEMPTED || ret == -EDEV_REGISTRATION_PREEMPTED || + ret == -EDEV_RESERVATION_CONFLICT)) { ltfsmsg(LTFS_INFO, 30268I, priv->drive_serial); _register_key(device, priv->key); count++; goto start; } - if (!ret) - priv->is_reserved = true; + if (!ret) priv->is_reserved = true; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_RESERVEUNIT)); @@ -3388,18 +3309,16 @@ int sg_reserve(void *device) int sg_release(void *device) { int ret = -EDEV_UNKNOWN; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_RELEASEUNIT)); ltfsmsg(LTFS_DEBUG, 30392D, "release (PRO)", priv->drive_serial); /* Issue release command even if no reservation is made */ - ret = _cdb_pro(device, PRO_ACT_RELEASE, PRO_TYPE_EXCLUSIVE, - priv->key, NULL); + ret = _cdb_pro(device, PRO_ACT_RELEASE, PRO_TYPE_EXCLUSIVE, priv->key, NULL); - if (!ret) - priv->is_reserved = false; + if (!ret) priv->is_reserved = false; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_RELEASEUNIT)); @@ -3410,7 +3329,7 @@ static int _cdb_prevent_allow_medium_removal(void *device, bool prevent) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; sg_io_hdr_t req; unsigned char cdb[CDB6_LEN]; @@ -3421,35 +3340,31 @@ static int _cdb_prevent_allow_medium_removal(void *device, bool prevent) /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(sense, 0, sizeof(sense)); /* Build CDB */ cdb[0] = PREVENT_ALLOW_MEDIUM_REMOVAL; - if (prevent) - cdb[4] = 0x01; + if (prevent) cdb[4] = 0x01; timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_NO_DATA_TRANSFER; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; ret = sg_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } if (!ret) { @@ -3465,7 +3380,7 @@ static int _cdb_prevent_allow_medium_removal(void *device, bool prevent) int sg_prevent_medium_removal(void *device) { int ret = -EDEV_UNKNOWN; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_PREVENTM)); ltfsmsg(LTFS_DEBUG, 30392D, "prevent medium removal", priv->drive_serial); @@ -3478,7 +3393,7 @@ int sg_prevent_medium_removal(void *device) int sg_allow_medium_removal(void *device) { int ret = -EDEV_UNKNOWN; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_ALLOWMREM)); ltfsmsg(LTFS_DEBUG, 30392D, "allow medium removal", priv->drive_serial); @@ -3488,12 +3403,11 @@ int sg_allow_medium_removal(void *device) return ret; } -int sg_write_attribute(void *device, const tape_partition_t part, - const unsigned char *buf, const size_t size) +int sg_write_attribute(void *device, const tape_partition_t part, const unsigned char *buf, const size_t size) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; sg_io_hdr_t req; unsigned char cdb[CDB16_LEN]; @@ -3503,8 +3417,7 @@ int sg_write_attribute(void *device, const tape_partition_t part, char *msg = NULL; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_WRITEATTR)); - ltfsmsg(LTFS_DEBUG3, 30396D, "writeattr", (unsigned long long)part, - priv->drive_serial); + ltfsmsg(LTFS_DEBUG3, 30396D, "writeattr", (unsigned long long)part, priv->drive_serial); /* Prepare the buffer to transfer */ uint32_t len = size + 4; @@ -3519,8 +3432,7 @@ int sg_write_attribute(void *device, const tape_partition_t part, /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(sense, 0, sizeof(sense)); @@ -3539,20 +3451,19 @@ int sg_write_attribute(void *device, const tape_partition_t part, /* Build request */ req.dxfer_direction = SCSI_FROM_INITIATOR_TO_TARGET; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.dxfer_len = len; - req.dxferp = buffer; - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.dxfer_len = len; + req.dxferp = buffer; + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; ret = sg_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } free(buffer); @@ -3562,12 +3473,12 @@ int sg_write_attribute(void *device, const tape_partition_t part, return ret; } -int sg_read_attribute(void *device, const tape_partition_t part, - const uint16_t id, unsigned char *buf, const size_t size) +int sg_read_attribute( + void *device, const tape_partition_t part, const uint16_t id, unsigned char *buf, const size_t size) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; sg_io_hdr_t req; unsigned char cdb[CDB16_LEN]; @@ -3594,8 +3505,7 @@ int sg_read_attribute(void *device, const tape_partition_t part, /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(sense, 0, sizeof(sense)); @@ -3608,39 +3518,31 @@ int sg_read_attribute(void *device, const tape_partition_t part, ltfs_u32tobe(cdb + 10, len); timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_TARGET_TO_INITIATOR; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.dxfer_len = len; - req.dxferp = buffer; - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.dxfer_len = len; + req.dxferp = buffer; + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; ret = sg_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { bool tape_dump = true; - if (ret == -EDEV_INVALID_FIELD_CDB) - tape_dump = false; + if (ret == -EDEV_INVALID_FIELD_CDB) tape_dump = false; ret_ep = _process_errors(device, ret, msg, cmd_desc, true, tape_dump); - if (ret_ep < 0) - ret = ret_ep; - - if (id != TC_MAM_PAGE_COHERENCY && - id != TC_MAM_APP_VENDER && - id != TC_MAM_APP_NAME && - id != TC_MAM_APP_VERSION && - id != TC_MAM_USER_MEDIUM_LABEL && - id != TC_MAM_TEXT_LOCALIZATION_IDENTIFIER && - id != TC_MAM_BARCODE && - id != TC_MAM_APP_FORMAT_VERSION) + if (ret_ep < 0) ret = ret_ep; + + if (id != TC_MAM_PAGE_COHERENCY && id != TC_MAM_APP_VENDER && id != TC_MAM_APP_NAME && id != TC_MAM_APP_VERSION && + id != TC_MAM_USER_MEDIUM_LABEL && id != TC_MAM_TEXT_LOCALIZATION_IDENTIFIER && id != TC_MAM_BARCODE && + id != TC_MAM_APP_FORMAT_VERSION) ltfsmsg(LTFS_INFO, 30233I, ret); } else { if (size == MAXMAM_SIZE) { @@ -3661,7 +3563,7 @@ int sg_allow_overwrite(void *device, const struct tc_position pos) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; sg_io_hdr_t req; unsigned char cdb[CDB16_LEN]; @@ -3671,12 +3573,16 @@ int sg_allow_overwrite(void *device, const struct tc_position pos) char *msg = NULL; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_ALLOWOVERW)); - ltfsmsg(LTFS_DEBUG, 30397D, "allow overwrite", (unsigned long long)pos.partition, (unsigned long long)pos.block, priv->drive_serial); + ltfsmsg(LTFS_DEBUG, + 30397D, + "allow overwrite", + (unsigned long long)pos.partition, + (unsigned long long)pos.block, + priv->drive_serial); /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(sense, 0, sizeof(sense)); @@ -3688,27 +3594,25 @@ int sg_allow_overwrite(void *device, const struct tc_position pos) ltfs_u64tobe(cdb + 4, pos.block); timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_NO_DATA_TRANSFER; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; ret = sg_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { if (pos.block == TAPE_BLOCK_MAX && ret == -EDEV_EOD_DETECTED) { ltfsmsg(LTFS_DEBUG, 30224D, "Allow Overwrite"); ret = DEVICE_GOOD; } else { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } } @@ -3720,7 +3624,7 @@ int sg_allow_overwrite(void *device, const struct tc_position pos) int sg_set_compression(void *device, const bool enable_compression, struct tc_position *pos) { int ret = -EDEV_UNKNOWN; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; unsigned char buf[TC_MP_COMPRESSION_SIZE]; @@ -3728,13 +3632,12 @@ int sg_set_compression(void *device, const bool enable_compression, struct tc_po /* Capture compression setting */ ret = sg_modesense(device, TC_MP_COMPRESSION, TC_MP_PC_CURRENT, 0x00, buf, sizeof(buf)); - if (ret < 0) - return ret; + if (ret < 0) return ret; - buf[0] = 0x00; - buf[1] = 0x00; + buf[0] = 0x00; + buf[1] = 0x00; - if(enable_compression) + if (enable_compression) buf[18] = buf[18] | 0x80; else buf[18] = buf[18] & 0x7E; @@ -3749,7 +3652,7 @@ int sg_set_compression(void *device, const bool enable_compression, struct tc_po int sg_set_default(void *device) { int ret = -EDEV_UNKNOWN; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; priv->use_sili = true; @@ -3765,8 +3668,8 @@ int sg_set_default(void *device) return ret; } - buf[0] = 0x00; - buf[1] = 0x00; + buf[0] = 0x00; + buf[1] = 0x00; buf[24] = 0x0C; ret = sg_modeselect(device, buf, sizeof(buf)); @@ -3799,8 +3702,8 @@ int sg_set_default(void *device) * @return 0 on success or a negative value on error */ -#define LOG_TAPE_ALERT (0x2E) -#define LOG_PERFORMANCE (0x37) +#define LOG_TAPE_ALERT (0x2E) +#define LOG_PERFORMANCE (0x37) #define LOG_PERFORMANCE_CAPACITY_SUB (0x64) // Scope(7-6): Mount Values @@ -3808,24 +3711,15 @@ int sg_set_default(void *device) // Group(3-0): Capacity static uint16_t volstats[] = { - VOLSTATS_MOUNTS, - VOLSTATS_WRITTEN_DS, - VOLSTATS_WRITE_TEMPS, - VOLSTATS_WRITE_PERMS, - VOLSTATS_READ_DS, - VOLSTATS_READ_TEMPS, - VOLSTATS_READ_PERMS, - VOLSTATS_WRITE_PERMS_PREV, - VOLSTATS_READ_PERMS_PREV, - VOLSTATS_WRITE_MB, - VOLSTATS_READ_MB, - VOLSTATS_PASSES_BEGIN, - VOLSTATS_PASSES_MIDDLE, + VOLSTATS_MOUNTS, VOLSTATS_WRITTEN_DS, VOLSTATS_WRITE_TEMPS, VOLSTATS_WRITE_PERMS, VOLSTATS_READ_DS, + VOLSTATS_READ_TEMPS, VOLSTATS_READ_PERMS, VOLSTATS_WRITE_PERMS_PREV, VOLSTATS_READ_PERMS_PREV, VOLSTATS_WRITE_MB, + VOLSTATS_READ_MB, VOLSTATS_PASSES_BEGIN, VOLSTATS_PASSES_MIDDLE, }; -enum { - PERF_CART_CONDITION = 0x0001, /* < Media Efficiency */ - PERF_ACTIVE_CQ_LOSS_W = 0x7113, /* < Active CQ loss Write */ +enum +{ + PERF_CART_CONDITION = 0x0001, /* < Media Efficiency */ + PERF_ACTIVE_CQ_LOSS_W = 0x7113, /* < Active CQ loss Write */ }; static uint16_t perfstats[] = { @@ -3835,7 +3729,7 @@ static uint16_t perfstats[] = { int sg_get_cartridge_health(void *device, struct tc_cartridge_health *cart_health) { int ret = -EDEV_UNKNOWN; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; unsigned char logdata[LOGSENSEPAGE]; unsigned char buf[16]; @@ -3846,16 +3740,16 @@ int sg_get_cartridge_health(void *device, struct tc_cartridge_health *cart_healt ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_GETCARTHLTH)); /* Issue LogPage 0x37 */ - cart_health->tape_efficiency = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->tape_efficiency = UNSUPPORTED_CARTRIDGE_HEALTH; ret = sg_logsense(device, LOG_PERFORMANCE, (uint8_t)0, logdata, LOGSENSEPAGE); if (ret < 0) ltfsmsg(LTFS_INFO, 30234I, LOG_PERFORMANCE, ret, "get cart health"); else { - for(i = 0; i < (int)((sizeof(perfstats)/sizeof(perfstats[0]))); i++) { + for (i = 0; i < (int)((sizeof(perfstats) / sizeof(perfstats[0]))); i++) { if (_parse_logPage(logdata, perfstats[i], ¶m_size, buf, 16)) { ltfsmsg(LTFS_INFO, 30235I, LOG_PERFORMANCE, "get cart health"); } else { - switch(param_size) { + switch (param_size) { case sizeof(uint8_t): loghlt = (uint64_t)(buf[0]); break; @@ -3863,21 +3757,19 @@ int sg_get_cartridge_health(void *device, struct tc_cartridge_health *cart_healt loghlt = ((uint64_t)buf[0] << 8) + (uint64_t)buf[1]; break; case sizeof(uint32_t): - loghlt = ((uint64_t)buf[0] << 24) + ((uint64_t)buf[1] << 16) - + ((uint64_t)buf[2] << 8) + (uint64_t)buf[3]; + loghlt = ((uint64_t)buf[0] << 24) + ((uint64_t)buf[1] << 16) + ((uint64_t)buf[2] << 8) + (uint64_t)buf[3]; break; case sizeof(uint64_t): - loghlt = ((uint64_t)buf[0] << 56) + ((uint64_t)buf[1] << 48) - + ((uint64_t)buf[2] << 40) + ((uint64_t)buf[3] << 32) - + ((uint64_t)buf[4] << 24) + ((uint64_t)buf[5] << 16) - + ((uint64_t)buf[6] << 8) + (uint64_t)buf[7]; + loghlt = ((uint64_t)buf[0] << 56) + ((uint64_t)buf[1] << 48) + ((uint64_t)buf[2] << 40) + + ((uint64_t)buf[3] << 32) + ((uint64_t)buf[4] << 24) + ((uint64_t)buf[5] << 16) + + ((uint64_t)buf[6] << 8) + (uint64_t)buf[7]; break; default: loghlt = UNSUPPORTED_CARTRIDGE_HEALTH; break; } - switch(perfstats[i]) { + switch (perfstats[i]) { case PERF_CART_CONDITION: cart_health->tape_efficiency = loghlt; break; @@ -3889,28 +3781,28 @@ int sg_get_cartridge_health(void *device, struct tc_cartridge_health *cart_healt } /* Issue LogPage 0x17 */ - cart_health->mounts = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->written_ds = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->write_temps = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->write_perms = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_ds = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_temps = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_perms = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->mounts = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->written_ds = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->write_temps = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->write_perms = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_ds = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_temps = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_perms = UNSUPPORTED_CARTRIDGE_HEALTH; cart_health->write_perms_prev = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_perms_prev = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->written_mbytes = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_mbytes = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->passes_begin = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->passes_middle = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_perms_prev = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->written_mbytes = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_mbytes = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->passes_begin = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->passes_middle = UNSUPPORTED_CARTRIDGE_HEALTH; ret = sg_logsense(device, LOG_VOLUMESTATS, (uint8_t)0, logdata, LOGSENSEPAGE); if (ret < 0) ltfsmsg(LTFS_INFO, 30234I, LOG_VOLUMESTATS, ret, "get cart health"); else { - for(i = 0; i < (int)((sizeof(volstats)/sizeof(volstats[0]))); i++) { + for (i = 0; i < (int)((sizeof(volstats) / sizeof(volstats[0]))); i++) { if (_parse_logPage(logdata, volstats[i], ¶m_size, buf, 16)) { ltfsmsg(LTFS_INFO, 30235I, LOG_VOLUMESTATS, "get cart health"); } else { - switch(param_size) { + switch (param_size) { case sizeof(uint8_t): loghlt = (uint64_t)(buf[0]); break; @@ -3918,21 +3810,19 @@ int sg_get_cartridge_health(void *device, struct tc_cartridge_health *cart_healt loghlt = ((uint64_t)buf[0] << 8) + (uint64_t)buf[1]; break; case sizeof(uint32_t): - loghlt = ((uint64_t)buf[0] << 24) + ((uint64_t)buf[1] << 16) - + ((uint64_t)buf[2] << 8) + (uint64_t)buf[3]; + loghlt = ((uint64_t)buf[0] << 24) + ((uint64_t)buf[1] << 16) + ((uint64_t)buf[2] << 8) + (uint64_t)buf[3]; break; case sizeof(uint64_t): - loghlt = ((uint64_t)buf[0] << 56) + ((uint64_t)buf[1] << 48) - + ((uint64_t)buf[2] << 40) + ((uint64_t)buf[3] << 32) - + ((uint64_t)buf[4] << 24) + ((uint64_t)buf[5] << 16) - + ((uint64_t)buf[6] << 8) + (uint64_t)buf[7]; + loghlt = ((uint64_t)buf[0] << 56) + ((uint64_t)buf[1] << 48) + ((uint64_t)buf[2] << 40) + + ((uint64_t)buf[3] << 32) + ((uint64_t)buf[4] << 24) + ((uint64_t)buf[5] << 16) + + ((uint64_t)buf[6] << 8) + (uint64_t)buf[7]; break; default: loghlt = UNSUPPORTED_CARTRIDGE_HEALTH; break; } - switch(volstats[i]) { + switch (volstats[i]) { case VOLSTATS_MOUNTS: cart_health->mounts = loghlt; break; @@ -3986,7 +3876,7 @@ int sg_get_cartridge_health(void *device, struct tc_cartridge_health *cart_healt int sg_get_tape_alert(void *device, uint64_t *tape_alert) { int ret = -EDEV_UNKNOWN; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; unsigned char logdata[LOGSENSEPAGE]; unsigned char buf[16]; @@ -4003,15 +3893,13 @@ int sg_get_tape_alert(void *device, uint64_t *tape_alert) ltfsmsg(LTFS_INFO, 30234I, LOG_TAPE_ALERT, ret, "get tape alert"); else { ret = 0; - for(i = 1; i <= 64; i++) { - if (_parse_logPage(logdata, (uint16_t) i, ¶m_size, buf, 16) - || param_size != sizeof(uint8_t)) { + for (i = 1; i <= 64; i++) { + if (_parse_logPage(logdata, (uint16_t)i, ¶m_size, buf, 16) || param_size != sizeof(uint8_t)) { ltfsmsg(LTFS_INFO, 30235I, LOG_VOLUMESTATS, "get tape alert"); ta = 0; } - if(buf[0]) - ta += (uint64_t)(1) << (i - 1); + if (buf[0]) ta += (uint64_t)(1) << (i - 1); } } @@ -4024,7 +3912,7 @@ int sg_get_tape_alert(void *device, uint64_t *tape_alert) int sg_clear_tape_alert(void *device, uint64_t tape_alert) { - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_CLRTAPEALT)); priv->tape_alert &= ~tape_alert; @@ -4035,7 +3923,7 @@ int sg_clear_tape_alert(void *device, uint64_t tape_alert) int sg_get_xattr(void *device, const char *name, char **buf) { int ret = -LTFS_NO_XATTR; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; unsigned char logdata[LOGSENSEPAGE]; unsigned char logbuf[16]; @@ -4046,25 +3934,21 @@ int sg_get_xattr(void *device, const char *name, char **buf) ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_GETXATTR)); - if (!strcmp(name, "ltfs.vendor.IBM.mediaCQsLossRate")) - { + if (!strcmp(name, "ltfs.vendor.IBM.mediaCQsLossRate")) { ret = DEVICE_GOOD; /* If first fetch or cache value is too old and value is dirty, refresh value. */ get_current_timespec(&now); - if (priv->fetch_sec_acq_loss_w == 0 || - ((priv->fetch_sec_acq_loss_w + 60 < now.tv_sec) && priv->dirty_acq_loss_w)) - { + if (priv->fetch_sec_acq_loss_w == 0 || ((priv->fetch_sec_acq_loss_w + 60 < now.tv_sec) && priv->dirty_acq_loss_w)) { ret = sg_logsense(device, LOG_PERFORMANCE, LOG_PERFORMANCE_CAPACITY_SUB, logdata, LOGSENSEPAGE); if (ret < 0) { ltfsmsg(LTFS_INFO, 30234I, LOG_PERFORMANCE, ret, "get xattr"); } else { ret = 0; if (_parse_logPage(logdata, PERF_ACTIVE_CQ_LOSS_W, ¶m_size, logbuf, 16)) { - ltfsmsg(LTFS_INFO, 30235I, LOG_PERFORMANCE, "get xattr"); + ltfsmsg(LTFS_INFO, 30235I, LOG_PERFORMANCE, "get xattr"); ret = -LTFS_NO_XATTR; - } - else { + } else { switch (param_size) { case sizeof(uint32_t): value32 = (uint32_t)ltfs_betou32(logbuf); @@ -4103,16 +3987,15 @@ int sg_set_xattr(void *device, const char *name, const char *buf, size_t size) { int ret = -LTFS_NO_XATTR; char *null_terminated; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; int64_t perm_count = 0; - if (!size) - return -LTFS_BAD_ARG; + if (!size) return -LTFS_BAD_ARG; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_SETXATTR)); null_terminated = malloc(size + 1); - if (! null_terminated) { + if (!null_terminated) { ltfsmsg(LTFS_ERR, 10001E, "sg_set_xattr: null_term"); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_SETXATTR)); return -LTFS_NO_MEMORY; @@ -4120,34 +4003,34 @@ int sg_set_xattr(void *device, const char *name, const char *buf, size_t size) memcpy(null_terminated, buf, size); null_terminated[size] = '\0'; - if (! strcmp(name, "ltfs.vendor.IBM.forceErrorWrite")) { + if (!strcmp(name, "ltfs.vendor.IBM.forceErrorWrite")) { perm_count = strtoll(null_terminated, NULL, 0); if (perm_count < 0) { priv->force_writeperm = -perm_count; - priv->clear_by_pc = true; + priv->clear_by_pc = true; } else { priv->force_writeperm = perm_count; - priv->clear_by_pc = false; + priv->clear_by_pc = false; } if (priv->force_writeperm && priv->force_writeperm < THRESHOLD_FORCE_WRITE_NO_WRITE) priv->force_writeperm = THRESHOLD_FORCE_WRITE_NO_WRITE; priv->write_counter = 0; ret = DEVICE_GOOD; - } else if (! strcmp(name, "ltfs.vendor.IBM.forceErrorType")) { + } else if (!strcmp(name, "ltfs.vendor.IBM.forceErrorType")) { priv->force_errortype = strtol(null_terminated, NULL, 0); ret = DEVICE_GOOD; - } else if (! strcmp(name, "ltfs.vendor.IBM.forceErrorRead")) { + } else if (!strcmp(name, "ltfs.vendor.IBM.forceErrorRead")) { perm_count = strtoll(null_terminated, NULL, 0); if (perm_count < 0) { priv->force_readperm = -perm_count; - priv->clear_by_pc = true; + priv->clear_by_pc = true; } else { priv->force_readperm = perm_count; - priv->clear_by_pc = false; + priv->clear_by_pc = false; } priv->read_counter = 0; ret = DEVICE_GOOD; - } else if (! strcmp(name, "ltfs.vendor.IBM.capOffset")) { + } else if (!strcmp(name, "ltfs.vendor.IBM.capOffset")) { global_data.capacity_offset = strtoul(null_terminated, NULL, 0); ret = DEVICE_GOOD; } @@ -4159,10 +4042,11 @@ int sg_set_xattr(void *device, const char *name, const char *buf, size_t size) #define BLOCKLEN_DATA_SIZE 6 -static int _cdb_read_block_limits(void *device) { +static int _cdb_read_block_limits(void *device) +{ int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; sg_io_hdr_t req; unsigned char cdb[CDB6_LEN]; @@ -4177,8 +4061,7 @@ static int _cdb_read_block_limits(void *device) { /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(sense, 0, sizeof(sense)); @@ -4187,29 +4070,27 @@ static int _cdb_read_block_limits(void *device) { cdb[0] = READ_BLOCK_LIMITS; timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_TARGET_TO_INITIATOR; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.dxfer_len = sizeof(buf); - req.dxferp = buf; - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.dxfer_len = sizeof(buf); + req.dxferp = buf; + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; ret = sg_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } else { - ret = ((unsigned int) buf[1] & 0xFF) << 16; - ret += ((unsigned int) buf[2] & 0xFF) << 8; - ret += ((unsigned int) buf[3] & 0xFF); + ret = ((unsigned int)buf[1] & 0xFF) << 16; + ret += ((unsigned int)buf[2] & 0xFF) << 8; + ret += ((unsigned int)buf[3] & 0xFF); } return ret; @@ -4218,21 +4099,20 @@ static int _cdb_read_block_limits(void *device) { int sg_get_parameters(void *device, struct tc_drive_param *params) { int ret = -EDEV_UNKNOWN; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_GETPARAM)); if (priv->loaded) { params->cart_type = priv->cart_type; - params->density = priv->density_code; + params->density = priv->density_code; params->write_protect = 0; if (IS_ENTERPRISE(priv->drive_type)) { unsigned char buf[TC_MP_MEDIUM_SENSE_SIZE]; ret = sg_modesense(device, TC_MP_MEDIUM_SENSE, TC_MP_PC_CURRENT, 0, buf, sizeof(buf)); - if (ret < 0) - goto out; + if (ret < 0) goto out; char wp_flag = buf[26]; @@ -4256,8 +4136,7 @@ int sg_get_parameters(void *device, struct tc_drive_param *params) unsigned char buf[MODE_DEVICE_CONFIG_SIZE]; ret = sg_modesense(device, MODE_DEVICE_CONFIG, TC_MP_PC_CURRENT, 0, buf, sizeof(buf)); - if (ret < 0) - goto out; + if (ret < 0) goto out; if (buf[3] & 0x80) { params->write_protect |= VOL_PHYSICAL_WP; @@ -4273,7 +4152,7 @@ int sg_get_parameters(void *device, struct tc_drive_param *params) } } else { params->cart_type = priv->cart_type; - params->density = priv->density_code; + params->density = priv->density_code; } if (global_data.crc_checking) @@ -4288,14 +4167,14 @@ int sg_get_parameters(void *device, struct tc_drive_param *params) return ret; } -#define LOG_VOL_STATISTICS (0x17) -#define LOG_VOL_USED_CAPACITY (0x203) -#define LOG_VOL_PART_HEADER_SIZE (4) +#define LOG_VOL_STATISTICS (0x17) +#define LOG_VOL_USED_CAPACITY (0x203) +#define LOG_VOL_PART_HEADER_SIZE (4) int sg_get_eod_status(void *device, int part) { int ret = -EDEV_UNKNOWN; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; /* * This feature requires new tape drive firmware @@ -4305,7 +4184,7 @@ int sg_get_eod_status(void *device, int part) unsigned char buf[16]; unsigned int i; uint32_t param_size; - uint32_t part_cap[2] = {EOD_UNKNOWN, EOD_UNKNOWN}; + uint32_t part_cap[2] = { EOD_UNKNOWN, EOD_UNKNOWN }; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_GETEODSTAT)); @@ -4318,8 +4197,8 @@ int sg_get_eod_status(void *device, int part) } /* Parse Approximate used native capacity of partitions (0x203)*/ - if (_parse_logPage(logdata, (uint16_t)VOLSTATS_PART_USED_CAP, ¶m_size, buf, sizeof(buf)) - || (param_size != sizeof(buf) ) ) { + if (_parse_logPage(logdata, (uint16_t)VOLSTATS_PART_USED_CAP, ¶m_size, buf, sizeof(buf)) || + (param_size != sizeof(buf))) { ltfsmsg(LTFS_WARN, 30238W); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_GETEODSTAT)); return EOD_UNKNOWN; @@ -4331,13 +4210,11 @@ int sg_get_eod_status(void *device, int part) uint16_t part_buf; len = buf[i]; - part_buf = (uint16_t)(buf[i + 2] << 8) + (uint16_t) buf[i + 3]; + part_buf = (uint16_t)(buf[i + 2] << 8) + (uint16_t)buf[i + 3]; /* actual length - 1 is stored into len */ - if ( (len - LOG_VOL_PART_HEADER_SIZE + 1) == sizeof(uint32_t) && part_buf < 2) { - part_cap[part_buf] = ((uint32_t) buf[i + 4] << 24) + - ((uint32_t) buf[i + 5] << 16) + - ((uint32_t) buf[i + 6] << 8) + - (uint32_t) buf[i + 7]; + if ((len - LOG_VOL_PART_HEADER_SIZE + 1) == sizeof(uint32_t) && part_buf < 2) { + part_cap[part_buf] = ((uint32_t)buf[i + 4] << 24) + ((uint32_t)buf[i + 5] << 16) + ((uint32_t)buf[i + 6] << 8) + + (uint32_t)buf[i + 7]; } else ltfsmsg(LTFS_WARN, 30239W, i, part_buf, len); @@ -4345,7 +4222,7 @@ int sg_get_eod_status(void *device, int part) } /* Create return value */ - if(part_cap[part] == 0xFFFFFFFF) + if (part_cap[part] == 0xFFFFFFFF) ret = EOD_MISSING; else ret = EOD_GOOD; @@ -4360,16 +4237,14 @@ static const char *_generate_product_name(const char *product_id) int i = 0; for (i = 0; ibm_supported_drives[i]; ++i) { - if (strncmp(ibm_supported_drives[i]->product_id, product_id, - strlen(ibm_supported_drives[i]->product_id)) == 0) { + if (strncmp(ibm_supported_drives[i]->product_id, product_id, strlen(ibm_supported_drives[i]->product_id)) == 0) { product_name = ibm_supported_drives[i]->product_name; break; } } for (i = 0; hp_supported_drives[i]; ++i) { - if (strncmp(hp_supported_drives[i]->product_id, product_id, - strlen(hp_supported_drives[i]->product_id)) == 0) { + if (strncmp(hp_supported_drives[i]->product_id, product_id, strlen(hp_supported_drives[i]->product_id)) == 0) { product_name = hp_supported_drives[i]->product_name; break; } @@ -4400,14 +4275,12 @@ int sg_get_device_list(struct tc_drive_info *buf, int count) dev.is_data_key_set = false; while ((entry = readdir(dp)) != NULL) { - if (strncmp(entry->d_name, "sg", strlen("sg"))) - continue; + if (strncmp(entry->d_name, "sg", strlen("sg"))) continue; sprintf(devname, "/dev/%s", entry->d_name); dev.fd = open(devname, O_RDONLY | O_NONBLOCK); - if (dev.fd < 0) - continue; + if (dev.fd < 0) continue; /* Get the device back to blocking mode */ flags = fcntl(dev.fd, F_GETFL, 0); @@ -4432,20 +4305,19 @@ int sg_get_device_list(struct tc_drive_info *buf, int count) } if (found < count && buf) { - strncpy(buf[found].name, devname, TAPE_DEVNAME_LEN_MAX + 1); - strncpy(buf[found].vendor, identifier.vendor_id, TAPE_VENDOR_NAME_LEN_MAX + 1); - strncpy(buf[found].model, identifier.product_id, TAPE_MODEL_NAME_LEN_MAX + 1); + strncpy(buf[found].name, devname, TAPE_DEVNAME_LEN_MAX + 1); + strncpy(buf[found].vendor, identifier.vendor_id, TAPE_VENDOR_NAME_LEN_MAX + 1); + strncpy(buf[found].model, identifier.product_id, TAPE_MODEL_NAME_LEN_MAX + 1); strncpy(buf[found].serial_number, identifier.unit_serial, TAPE_SERIAL_LEN_MAX + 1); - strncpy(buf[found].product_rev, identifier.product_rev, PRODUCT_REV_LENGTH + 1); - strncpy(buf[found].product_name, _generate_product_name(identifier.product_id), PRODUCT_NAME_LENGTH + 1); + strncpy(buf[found].product_rev, identifier.product_rev, PRODUCT_REV_LENGTH + 1); + strncpy(buf[found].product_name, _generate_product_name(identifier.product_id), PRODUCT_NAME_LENGTH + 1); - if (! ioctl(dev.fd, SG_GET_SCSI_ID, &scsi_id)) { - buf[found].host = scsi_id.host_no; + if (!ioctl(dev.fd, SG_GET_SCSI_ID, &scsi_id)) { + buf[found].host = scsi_id.host_no; buf[found].channel = scsi_id.channel; - buf[found].target = scsi_id.scsi_id; - buf[found].lun = scsi_id.lun; + buf[found].target = scsi_id.scsi_id; + buf[found].lun = scsi_id.lun; } - } found++; @@ -4465,7 +4337,7 @@ void sg_help_message(const char *progname) int sg_parse_opts(void *device, void *opt_args) { - struct fuse_args *args = (struct fuse_args *) opt_args; + struct fuse_args *args = (struct fuse_args *)opt_args; int ret; /* fuse_opt_parse can handle a NULL device parameter just fine */ @@ -4497,11 +4369,11 @@ const char *sg_default_device_name(void) return devname; } -static int _cdb_spin(void *device, const uint16_t sps, unsigned char **buffer, size_t * const size) +static int _cdb_spin(void *device, const uint16_t sps, unsigned char **buffer, size_t *const size) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; sg_io_hdr_t req; unsigned char cdb[CDB12_LEN]; @@ -4513,14 +4385,13 @@ static int _cdb_spin(void *device, const uint16_t sps, unsigned char **buffer, s /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(sense, 0, sizeof(sense)); *buffer = calloc(len, sizeof(unsigned char)); - if (! *buffer) { + if (!*buffer) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -EDEV_NO_MEMORY; } @@ -4532,25 +4403,23 @@ static int _cdb_spin(void *device, const uint16_t sps, unsigned char **buffer, s ltfs_u32tobe(cdb + 6, len); timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_TARGET_TO_INITIATOR; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.dxfer_len = len; - req.dxferp = *buffer; - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.dxfer_len = len; + req.dxferp = *buffer; + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; ret = sg_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } *size = ltfs_betou16((*buffer) + 2); @@ -4558,12 +4427,11 @@ static int _cdb_spin(void *device, const uint16_t sps, unsigned char **buffer, s return ret; } -int _cdb_spout(void *device, const uint16_t sps, - unsigned char* const buffer, const size_t size) +int _cdb_spout(void *device, const uint16_t sps, unsigned char *const buffer, const size_t size) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; sg_io_hdr_t req; unsigned char cdb[CDB12_LEN]; @@ -4574,8 +4442,7 @@ int _cdb_spout(void *device, const uint16_t sps, /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(sense, 0, sizeof(sense)); @@ -4587,38 +4454,47 @@ int _cdb_spout(void *device, const uint16_t sps, ltfs_u32tobe(cdb + 6, size); timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_INITIATOR_TO_TARGET; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.dxfer_len = size; - req.dxferp = buffer; - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.dxfer_len = size; + req.dxferp = buffer; + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; ret = sg_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } return ret; } -static void ltfsmsg_keyalias(const char * const title, const unsigned char * const keyalias) +static void ltfsmsg_keyalias(const char *const title, const unsigned char *const keyalias) { - char s[128] = {'\0'}; + char s[128] = { '\0' }; if (keyalias) - sprintf(s, "keyalias = %c%c%c%02X%02X%02X%02X%02X%02X%02X%02X%02X", keyalias[0], - keyalias[1], keyalias[2], keyalias[3], keyalias[4], keyalias[5], keyalias[6], - keyalias[7], keyalias[8], keyalias[9], keyalias[10], keyalias[11]); + sprintf(s, + "keyalias = %c%c%c%02X%02X%02X%02X%02X%02X%02X%02X%02X", + keyalias[0], + keyalias[1], + keyalias[2], + keyalias[3], + keyalias[4], + keyalias[5], + keyalias[6], + keyalias[7], + keyalias[8], + keyalias[9], + keyalias[10], + keyalias[11]); else sprintf(s, "keyalias: NULL"); @@ -4627,18 +4503,18 @@ static void ltfsmsg_keyalias(const char * const title, const unsigned char * con static bool is_ame(void *device) { - unsigned char buf[TC_MP_READ_WRITE_CTRL_SIZE] = {0}; + unsigned char buf[TC_MP_READ_WRITE_CTRL_SIZE] = { 0 }; const int ret = sg_modesense(device, TC_MP_READ_WRITE_CTRL, TC_MP_PC_CURRENT, 0, buf, sizeof(buf)); if (ret != 0) { - char message[100] = {0}; + char message[100] = { 0 }; sprintf(message, "failed to get MP %02Xh (%d)", TC_MP_READ_WRITE_CTRL, ret); ltfsmsg(LTFS_DEBUG, 30392D, __FUNCTION__, message); return false; /* Consider that the encryption method is not AME */ } else { const unsigned char encryption_method = buf[16 + 27]; - char message[100] = {0}; + char message[100] = { 0 }; char *method = NULL; switch (encryption_method) { case 0x00: @@ -4678,15 +4554,14 @@ static bool is_ame(void *device) static int is_encryption_capable(void *device) { - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; if (IS_LTO(priv->drive_type)) { ltfsmsg(LTFS_ERR, 30243E, priv->drive_type); return -EDEV_INTERNAL_ERROR; } - if (! is_ame(device)) - return -EDEV_INTERNAL_ERROR; + if (!is_ame(device)) return -EDEV_INTERNAL_ERROR; return DEVICE_GOOD; } @@ -4694,7 +4569,7 @@ static int is_encryption_capable(void *device) int sg_set_key(void *device, const unsigned char *keyalias, const unsigned char *key) { int ret = -EDEV_UNKNOWN; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; /* * Encryption Decryption Key DKi keyalias @@ -4712,16 +4587,15 @@ int sg_set_key(void *device, const unsigned char *keyalias, const unsigned char const uint16_t sps = 0x10; const size_t size = keyalias ? 20 + DK_LENGTH + 4 + DKI_LENGTH : 20; uint8_t *buffer = calloc(size, sizeof(uint8_t)); - if (! buffer) { + if (!buffer) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); ret = -EDEV_NO_MEMORY; goto out; } - unsigned char buf[TC_MP_READ_WRITE_CTRL_SIZE] = {0}; + unsigned char buf[TC_MP_READ_WRITE_CTRL_SIZE] = { 0 }; ret = sg_modesense(device, TC_MP_READ_WRITE_CTRL, TC_MP_PC_CURRENT, 0, buf, sizeof(buf)); - if (ret != DEVICE_GOOD) - goto out; + if (ret != DEVICE_GOOD) goto out; ltfs_u16tobe(buffer + 0, sps); ltfs_u16tobe(buffer + 2, size - 4); @@ -4737,38 +4611,44 @@ int sg_set_key(void *device, const unsigned char *keyalias, const unsigned char * CKORL: 0b Clear key on reservation loss (CKORL) bit */ buffer[5] = 0x00; - enum { DISABLE = 0, EXTERNAL = 1, ENCRYPT = 2 }; + enum + { + DISABLE = 0, + EXTERNAL = 1, + ENCRYPT = 2 + }; buffer[6] = keyalias ? ENCRYPT : DISABLE; /* ENCRYPTION MODE */ - enum { /* DISABLE = 0, */ RAW = 1, DECRYPT = 2, MIXED = 3 }; - buffer[7] = keyalias ? MIXED : DISABLE; /* DECRYPTION MODE */ - buffer[8] = 1; /* ALGORITHM INDEX */ - buffer[9] = 0; /* LOGICAL BLOCK ENCRYPTION KEY FORMAT: plain-text key */ - buffer[10] = 0; /* KAD FORMAT: Unspecified */ + enum + { /* DISABLE = 0, */ RAW = 1, + DECRYPT = 2, + MIXED = 3 }; + buffer[7] = keyalias ? MIXED : DISABLE; /* DECRYPTION MODE */ + buffer[8] = 1; /* ALGORITHM INDEX */ + buffer[9] = 0; /* LOGICAL BLOCK ENCRYPTION KEY FORMAT: plain-text key */ + buffer[10] = 0; /* KAD FORMAT: Unspecified */ ltfs_u16tobe(buffer + 18, keyalias ? DK_LENGTH : 0x00); /* LOGICAL BLOCK ENCRYPTION KEY LENGTH */ if (keyalias) { - if (! key) { + if (!key) { ret = -EINVAL; goto free; } memcpy(buffer + 20, key, DK_LENGTH); /* LOGICAL BLOCK ENCRYPTION KEY */ - buffer[20 + DK_LENGTH] = 0x01; /* KEY DESCRIPTOR TYPE: 01h DKi (Data Key Identifier) */ + buffer[20 + DK_LENGTH] = 0x01; /* KEY DESCRIPTOR TYPE: 01h DKi (Data Key Identifier) */ ltfs_u16tobe(buffer + 20 + DK_LENGTH + 2, DKI_LENGTH); memcpy(buffer + 20 + 0x20 + 4, keyalias, DKI_LENGTH); } - const char * const title = "set key:"; + const char *const title = "set key:"; ltfsmsg_keyalias(title, keyalias); ret = _cdb_spout(device, sps, buffer, size); - if (ret != DEVICE_GOOD) - goto free; + if (ret != DEVICE_GOOD) goto free; priv->dev.is_data_key_set = keyalias != NULL; memset(buf, 0, sizeof(buf)); ret = sg_modesense(device, TC_MP_READ_WRITE_CTRL, TC_MP_PC_CURRENT, 0, buf, sizeof(buf)); - if (ret != DEVICE_GOOD) - goto out; + if (ret != DEVICE_GOOD) goto out; free: free(buffer); @@ -4778,27 +4658,26 @@ int sg_set_key(void *device, const unsigned char *keyalias, const unsigned char return ret; } -static void show_hex_dump(const char * const title, const uint8_t * const buf, const size_t size) +static void show_hex_dump(const char *const title, const uint8_t *const buf, const size_t size) { /* * " 1 2 3 4 5 6 7 8" * "12345678901234567890123456789012345678901234567890123456789012345678901234567890" * "xxxxxx 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF\n" < 100 */ - char * const s = calloc((size / 0x10 + 1) * 100, sizeof(char)); + char *const s = calloc((size / 0x10 + 1) * 100, sizeof(char)); char *p = s; uint i = 0; int j = 0; int k = 0; - if (p == NULL) - return; + if (p == NULL) return; for (i = 0; i < size; ++i) { if (i % 0x10 == 0) { if (i) { for (j = 0x10; 0 < j; --j) { - p += sprintf(p, "%c", isprint(buf[i-j]) ? buf[i-j] : '.'); + p += sprintf(p, "%c", isprint(buf[i - j]) ? buf[i - j] : '.'); } } p += sprintf(p, "\n%06X ", i); @@ -4809,7 +4688,7 @@ static void show_hex_dump(const char * const title, const uint8_t * const buf, c p += sprintf(p, " %s", (i + k) % 8 == 7 ? " " : ""); } for (j = 0x10 - k; 0 < j; --j) { - p += sprintf(p, "%c", isprint(buf[i-j]) ? buf[i-j] : '.'); + p += sprintf(p, "%c", isprint(buf[i - j]) ? buf[i - j] : '.'); } ltfsmsg(LTFS_DEBUG, 30392D, title, s); @@ -4818,7 +4697,7 @@ static void show_hex_dump(const char * const title, const uint8_t * const buf, c int sg_get_keyalias(void *device, unsigned char **keyalias) { int ret = -EDEV_UNKNOWN; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_GETKEYALIAS)); ret = is_encryption_capable(device); @@ -4842,32 +4721,32 @@ int sg_get_keyalias(void *device, unsigned char **keyalias) for (i = 0; i < 2; ++i) { free(buffer); ret = _cdb_spin(device, sps, &buffer, &size); - if (ret != DEVICE_GOOD) - goto free; + if (ret != DEVICE_GOOD) goto free; } show_hex_dump("SPIN:", buffer, size + 4); const unsigned char encryption_status = buffer[12] & 0xF; - enum { - ENC_STAT_INCAPABLE = 0, - ENC_STAT_NOT_YET_BEEN_READ = 1, - ENC_STAT_NOT_A_LOGICAL_BLOCK = 2, - ENC_STAT_NOT_ENCRYPTED = 3, + enum + { + ENC_STAT_INCAPABLE = 0, + ENC_STAT_NOT_YET_BEEN_READ = 1, + ENC_STAT_NOT_A_LOGICAL_BLOCK = 2, + ENC_STAT_NOT_ENCRYPTED = 3, ENC_STAT_ENCRYPTED_BY_UNSUPPORTED_ALGORITHM = 4, - ENC_STAT_ENCRYPTED_BY_SUPPORTED_ALGORITHM = 5, - ENC_STAT_ENCRYPTED_BY_OTHER_KEY = 6, + ENC_STAT_ENCRYPTED_BY_SUPPORTED_ALGORITHM = 5, + ENC_STAT_ENCRYPTED_BY_OTHER_KEY = 6, ENC_STAT_RESERVED, /* 7h-Fh */ }; if (encryption_status == ENC_STAT_ENCRYPTED_BY_UNSUPPORTED_ALGORITHM || - encryption_status == ENC_STAT_ENCRYPTED_BY_SUPPORTED_ALGORITHM || - encryption_status == ENC_STAT_ENCRYPTED_BY_OTHER_KEY) { + encryption_status == ENC_STAT_ENCRYPTED_BY_SUPPORTED_ALGORITHM || + encryption_status == ENC_STAT_ENCRYPTED_BY_OTHER_KEY) { uint offset = 16; /* offset of key descriptor */ while (offset <= size && buffer[offset] != 1) { offset += ltfs_betou16(buffer + offset + 2) + 4; } if (offset <= size && buffer[offset] == 1) { - const uint dki_length = ((int) buffer[offset + 2]) << 8 | buffer[offset + 3]; + const uint dki_length = ((int)buffer[offset + 2]) << 8 | buffer[offset + 3]; if (offset + dki_length <= size) { int n = dki_length < sizeof(priv->dki) ? dki_length : sizeof(priv->dki); memcpy(priv->dki, &buffer[offset + 4], n); @@ -4876,7 +4755,7 @@ int sg_get_keyalias(void *device, unsigned char **keyalias) } } - const char * const title = "get key-alias:"; + const char *const title = "get key-alias:"; ltfsmsg_keyalias(title, priv->dki); free: @@ -4887,7 +4766,7 @@ int sg_get_keyalias(void *device, unsigned char **keyalias) int sg_takedump_drive(void *device, bool capture_unforced) { - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_TAKEDUMPDRV)); _take_dump(priv, capture_unforced); @@ -4896,19 +4775,14 @@ int sg_takedump_drive(void *device, bool capture_unforced) return 0; } -int sg_is_mountable(void *device, const char *barcode, const unsigned char cart_type, - const unsigned char density) +int sg_is_mountable(void *device, const char *barcode, const unsigned char cart_type, const unsigned char density) { int ret; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_ISMOUNTABLE)); - ret = ibm_tape_is_mountable( priv->drive_type, - barcode, - cart_type, - density, - global_data.strict_drive); + ret = ibm_tape_is_mountable(priv->drive_type, barcode, cart_type, density, global_data.strict_drive); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_ISMOUNTABLE)); @@ -4918,13 +4792,9 @@ int sg_is_mountable(void *device, const char *barcode, const unsigned char cart_ bool sg_is_readonly(void *device) { int ret; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; - ret = ibm_tape_is_mountable( priv->drive_type, - NULL, - priv->cart_type, - priv->density_code, - global_data.strict_drive); + ret = ibm_tape_is_mountable(priv->drive_type, NULL, priv->cart_type, priv->density_code, global_data.strict_drive); if (ret == MEDIUM_READONLY) return true; @@ -4935,7 +4805,7 @@ bool sg_is_readonly(void *device) int sg_get_worm_status(void *device, bool *is_worm) { int rc = 0; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_GETWORMSTAT)); if (priv->loaded) { @@ -4952,15 +4822,15 @@ int sg_get_worm_status(void *device, bool *is_worm) int sg_get_serialnumber(void *device, char **result) { - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; CHECK_ARG_NULL(device, -LTFS_NULL_ARG); CHECK_ARG_NULL(result, -LTFS_NULL_ARG); ltfs_profiler_add_entry(priv->profiler, NULL, CHANGER_REQ_ENTER(REQ_TC_GETSER)); - *result = strdup((const char *) priv->drive_serial); - if (! *result) { + *result = strdup((const char *)priv->drive_serial); + if (!*result) { ltfsmsg(LTFS_ERR, 10001E, "sg_get_serialnumber: result"); ltfs_profiler_add_entry(priv->profiler, NULL, CHANGER_REQ_EXIT(REQ_TC_GETSER)); return -EDEV_NO_MEMORY; @@ -4973,7 +4843,7 @@ int sg_get_serialnumber(void *device, char **result) int sg_get_info(void *device, struct tc_drive_info *info) { - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; memcpy(info, &priv->info, sizeof(struct tc_drive_info)); @@ -4983,21 +4853,18 @@ int sg_get_info(void *device, struct tc_drive_info *info) int sg_set_profiler(void *device, char *work_dir, bool enable) { int rc = 0; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; char *path; FILE *p; struct timer_info timerinfo; if (enable) { - if (priv->profiler) - return 0; + if (priv->profiler) return 0; - if(!work_dir) - return -LTFS_BAD_ARG; + if (!work_dir) return -LTFS_BAD_ARG; - rc = asprintf(&path, "%s/%s%s%s", work_dir, DRIVER_PROFILER_BASE, - "DUMMY", PROFILER_EXTENSION); + rc = asprintf(&path, "%s/%s%s%s", work_dir, DRIVER_PROFILER_BASE, "DUMMY", PROFILER_EXTENSION); if (rc < 0) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -EDEV_NO_MEMORY; @@ -5007,11 +4874,11 @@ int sg_set_profiler(void *device, char *work_dir, bool enable) free(path); - if (! p) + if (!p) rc = -LTFS_FILE_ERR; else { get_timer_info(&timerinfo); - fwrite((void*)&timerinfo, sizeof(timerinfo), 1, p); + fwrite((void *)&timerinfo, sizeof(timerinfo), 1, p); priv->profiler = p; rc = 0; } @@ -5029,7 +4896,7 @@ int sg_get_next_block_to_xfer(void *device, struct tc_position *pos) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; sg_io_hdr_t req; unsigned char cdb[CDB10_LEN]; @@ -5045,43 +4912,45 @@ int sg_get_next_block_to_xfer(void *device, struct tc_position *pos) /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(sense, 0, sizeof(sense)); /* Build CDB */ cdb[0] = READ_POSITION; - cdb[1] = 0x08; /* Extended Format */ + cdb[1] = 0x08; /* Extended Format */ ltfs_u16tobe(cdb + 7, sizeof(buf)); /* allocation length */ timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_TARGET_TO_INITIATOR; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.dxfer_len = sizeof(buf); - req.dxferp = buf; - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.dxfer_len = sizeof(buf); + req.dxferp = buf; + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; ret = sg_issue_cdb_command(&priv->dev, &req, &msg); if (ret == DEVICE_GOOD) { pos->partition = (tape_partition_t)buf[1]; - pos->block = ltfs_betou64(buf + 16); - - ltfsmsg(LTFS_DEBUG, 30398D, "next-block-to-xfer", - (unsigned long long)pos->partition, (unsigned long long)pos->block, (unsigned long long)0, priv->drive_serial); + pos->block = ltfs_betou64(buf + 16); + + ltfsmsg(LTFS_DEBUG, + 30398D, + "next-block-to-xfer", + (unsigned long long)pos->partition, + (unsigned long long)pos->block, + (unsigned long long)0, + priv->drive_serial); } else { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_READPOS)); @@ -5094,7 +4963,7 @@ int sg_grao(void *device, unsigned char *buf, const uint32_t len) int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; sg_io_hdr_t req; unsigned char cdb[CDB12_LEN]; unsigned char sense[MAXSENSE]; @@ -5103,9 +4972,9 @@ int sg_grao(void *device, unsigned char *buf, const uint32_t len) char *msg = NULL; if (IS_LTO(priv->drive_type)) { - if ( DRIVE_GEN(priv->drive_type) == 0x05 || DRIVE_GEN(priv->drive_type) == 0x06 || - DRIVE_GEN(priv->drive_type) == 0x07 || DRIVE_GEN(priv->drive_type) == 0x08 || - DRIVE_GEN(priv->drive_type) == DRIVE_LTO9_HH ) { + if (DRIVE_GEN(priv->drive_type) == 0x05 || DRIVE_GEN(priv->drive_type) == 0x06 || + DRIVE_GEN(priv->drive_type) == 0x07 || DRIVE_GEN(priv->drive_type) == 0x08 || + DRIVE_GEN(priv->drive_type) == DRIVE_LTO9_HH) { /* LTO5-LTO8 and LTO9-HH don't support RAO commands */ return -EDEV_UNSUPPORETD_COMMAND; } @@ -5113,39 +4982,36 @@ int sg_grao(void *device, unsigned char *buf, const uint32_t len) /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(sense, 0, sizeof(sense)); /* Build CDB */ - cdb[0] = MAINTENANCE_OUT; /* op_code */ - cdb[1] = 0x1D; /* service action */ - cdb[2] = 0x2; /* PROCESS, reorder UDS on */ + cdb[0] = MAINTENANCE_OUT; /* op_code */ + cdb[1] = 0x1D; /* service action */ + cdb[2] = 0x2; /* PROCESS, reorder UDS on */ cdb[3] = LTFS_GEOMETORY_OFF; /* UDS_TYPE */ - ltfs_u32tobe(cdb + 6, len); /* parameter list len starts from 6 byte, adding len to cbc 6-9 */ + ltfs_u32tobe(cdb + 6, len); /* parameter list len starts from 6 byte, adding len to cbc 6-9 */ timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_INITIATOR_TO_TARGET; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.dxfer_len = len; - req.dxferp = buf; - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.dxfer_len = len; + req.dxferp = buf; + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; ret = sg_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } return ret; @@ -5156,7 +5022,7 @@ int sg_rrao(void *device, unsigned char *buf, const uint32_t len, size_t *out_si int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct sg_data *priv = (struct sg_data*)device; + struct sg_data *priv = (struct sg_data *)device; sg_io_hdr_t req; unsigned char sense[MAXSENSE]; unsigned char cdb[CDB12_LEN]; @@ -5167,8 +5033,8 @@ int sg_rrao(void *device, unsigned char *buf, const uint32_t len, size_t *out_si *out_size = 0; if (IS_LTO(priv->drive_type)) { - if ( DRIVE_GEN(priv->drive_type) == 0x05 || DRIVE_GEN(priv->drive_type) == 0x06 || - DRIVE_GEN(priv->drive_type) == 0x07 || DRIVE_GEN(priv->drive_type) == 0x08 ) { + if (DRIVE_GEN(priv->drive_type) == 0x05 || DRIVE_GEN(priv->drive_type) == 0x06 || + DRIVE_GEN(priv->drive_type) == 0x07 || DRIVE_GEN(priv->drive_type) == 0x08) { /* LTO6-LTO8 don't support RAO commands */ return -EDEV_UNSUPPORETD_COMMAND; } @@ -5176,14 +5042,13 @@ int sg_rrao(void *device, unsigned char *buf, const uint32_t len, size_t *out_si /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(sense, 0, sizeof(sense)); /* Build CDB */ cdb[0] = MAINTENANCE_IN; - cdb[1] = 0x1D; /* Do not set UDS_LIMITS (0x80) */ + cdb[1] = 0x1D; /* Do not set UDS_LIMITS (0x80) */ ltfs_u32tobe(cdb + 6, len); cdb[10] = LTFS_GEOMETORY_OFF; /* UDS_TYPE */ @@ -5194,20 +5059,19 @@ int sg_rrao(void *device, unsigned char *buf, const uint32_t len, size_t *out_si /* Build request */ req.dxfer_direction = SCSI_FROM_TARGET_TO_INITIATOR; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(sense); - req.dxfer_len = len; - req.dxferp = buf; - req.cmdp = cdb; - req.sbp = sense; - req.timeout = SGConversion(timeout); - req.usr_ptr = (void *)cmd_desc; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(sense); + req.dxfer_len = len; + req.dxferp = buf; + req.cmdp = cdb; + req.sbp = sense; + req.timeout = SGConversion(timeout); + req.usr_ptr = (void *)cmd_desc; ret = sg_issue_cdb_command(&priv->dev, &req, &msg); if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } if (!ret) { @@ -5219,73 +5083,71 @@ int sg_rrao(void *device, unsigned char *buf, const uint32_t len, size_t *out_si } struct tape_ops sg_handler = { - .open = sg_open, - .reopen = sg_reopen, - .close = sg_close, - .close_raw = sg_close_raw, - .is_connected = sg_is_connected, - .inquiry = sg_inquiry, - .inquiry_page = sg_inquiry_page, - .test_unit_ready = sg_test_unit_ready, - .read = sg_read, - .write = sg_write, - .writefm = sg_writefm, - .rewind = sg_rewind, - .locate = sg_locate, - .space = sg_space, - .erase = sg_erase, - .load = sg_load, - .unload = sg_unload, - .readpos = sg_readpos, - .setcap = sg_setcap, - .format = sg_format, - .remaining_capacity = sg_remaining_capacity, - .logsense = sg_logsense, - .modesense = sg_modesense, - .modeselect = sg_modeselect, - .reserve_unit = sg_reserve, - .release_unit = sg_release, + .open = sg_open, + .reopen = sg_reopen, + .close = sg_close, + .close_raw = sg_close_raw, + .is_connected = sg_is_connected, + .inquiry = sg_inquiry, + .inquiry_page = sg_inquiry_page, + .test_unit_ready = sg_test_unit_ready, + .read = sg_read, + .write = sg_write, + .writefm = sg_writefm, + .rewind = sg_rewind, + .locate = sg_locate, + .space = sg_space, + .erase = sg_erase, + .load = sg_load, + .unload = sg_unload, + .readpos = sg_readpos, + .setcap = sg_setcap, + .format = sg_format, + .remaining_capacity = sg_remaining_capacity, + .logsense = sg_logsense, + .modesense = sg_modesense, + .modeselect = sg_modeselect, + .reserve_unit = sg_reserve, + .release_unit = sg_release, .prevent_medium_removal = sg_prevent_medium_removal, - .allow_medium_removal = sg_allow_medium_removal, - .write_attribute = sg_write_attribute, - .read_attribute = sg_read_attribute, - .allow_overwrite = sg_allow_overwrite, - .grao = sg_grao, - .rrao = sg_rrao, + .allow_medium_removal = sg_allow_medium_removal, + .write_attribute = sg_write_attribute, + .read_attribute = sg_read_attribute, + .allow_overwrite = sg_allow_overwrite, + .grao = sg_grao, + .rrao = sg_rrao, // May be command combination - .set_compression = sg_set_compression, - .set_default = sg_set_default, - .get_cartridge_health = sg_get_cartridge_health, - .get_tape_alert = sg_get_tape_alert, - .clear_tape_alert = sg_clear_tape_alert, - .get_xattr = sg_get_xattr, - .set_xattr = sg_set_xattr, - .get_parameters = sg_get_parameters, - .get_eod_status = sg_get_eod_status, - .get_device_list = sg_get_device_list, - .help_message = sg_help_message, - .parse_opts = sg_parse_opts, - .default_device_name = sg_default_device_name, - .set_key = sg_set_key, - .get_keyalias = sg_get_keyalias, - .takedump_drive = sg_takedump_drive, - .is_mountable = sg_is_mountable, - .get_worm_status = sg_get_worm_status, - .get_serialnumber = sg_get_serialnumber, - .get_info = sg_get_info, - .set_profiler = sg_set_profiler, + .set_compression = sg_set_compression, + .set_default = sg_set_default, + .get_cartridge_health = sg_get_cartridge_health, + .get_tape_alert = sg_get_tape_alert, + .clear_tape_alert = sg_clear_tape_alert, + .get_xattr = sg_get_xattr, + .set_xattr = sg_set_xattr, + .get_parameters = sg_get_parameters, + .get_eod_status = sg_get_eod_status, + .get_device_list = sg_get_device_list, + .help_message = sg_help_message, + .parse_opts = sg_parse_opts, + .default_device_name = sg_default_device_name, + .set_key = sg_set_key, + .get_keyalias = sg_get_keyalias, + .takedump_drive = sg_takedump_drive, + .is_mountable = sg_is_mountable, + .get_worm_status = sg_get_worm_status, + .get_serialnumber = sg_get_serialnumber, + .get_info = sg_get_info, + .set_profiler = sg_set_profiler, .get_next_block_to_xfer = sg_get_next_block_to_xfer, - .is_readonly = sg_is_readonly, + .is_readonly = sg_is_readonly, }; struct tape_ops *tape_dev_get_ops(void) { init_openfactor(); - if (!standard_table) - standard_table = standard_tape_errors; - if (!vendor_table) - vendor_table = ibm_tape_errors; + if (!standard_table) standard_table = standard_tape_errors; + if (!vendor_table) vendor_table = ibm_tape_errors; return &sg_handler; } diff --git a/src/tape_drivers/netbsd/scsipi-ibmtape/scsipi_ibmtape.c b/src/tape_drivers/netbsd/scsipi-ibmtape/scsipi_ibmtape.c index 0ea8df55..8b0792c2 100644 --- a/src/tape_drivers/netbsd/scsipi-ibmtape/scsipi_ibmtape.c +++ b/src/tape_drivers/netbsd/scsipi-ibmtape/scsipi_ibmtape.c @@ -47,23 +47,23 @@ ************************************************************************************* */ +#include #include #include #include -#include -#include #include +#include -#include "ltfs_copyright.h" -#include "libltfs/ltfslogging.h" +#include "kmi/key_format_ltfs.h" +#include "libltfs/arch/time_internal.h" #include "libltfs/fs.h" #include "libltfs/ltfs_endian.h" -#include "libltfs/arch/time_internal.h" -#include "kmi/key_format_ltfs.h" +#include "libltfs/ltfslogging.h" +#include "ltfs_copyright.h" /* Common header of backend */ -#include "reed_solomon_crc.h" #include "crc32c_crc.h" +#include "reed_solomon_crc.h" #include "vendor_compat.h" /* SCSI command handling functions */ @@ -75,8 +75,8 @@ #include "libltfs/ltfs_fuse_version.h" #include -volatile char *copyright = LTFS_COPYRIGHT_0"\n"LTFS_COPYRIGHT_1"\n"LTFS_COPYRIGHT_2"\n" \ - LTFS_COPYRIGHT_3"\n"LTFS_COPYRIGHT_4"\n"LTFS_COPYRIGHT_5"\n"; +volatile char *copyright = LTFS_COPYRIGHT_0 "\n" LTFS_COPYRIGHT_1 "\n" LTFS_COPYRIGHT_2 "\n" LTFS_COPYRIGHT_3 + "\n" LTFS_COPYRIGHT_4 "\n" LTFS_COPYRIGHT_5 "\n"; /* Default device name */ const char *default_device = "0"; @@ -85,33 +85,36 @@ const char *default_device = "0"; struct scsipi_ibmtape_global_data global_data; /* Definitions */ -#define LOG_PAGE_HEADER_SIZE (4) +#define LOG_PAGE_HEADER_SIZE (4) #define LOG_PAGE_PARAMSIZE_OFFSET (3) -#define LOG_PAGE_PARAM_OFFSET (4) +#define LOG_PAGE_PARAM_OFFSET (4) #define SG_MAX_BLOCK_SIZE (64 * 1024) #ifndef MIN -#define MIN(a, b) ((a) < (b) ? (a) : (b)) +# define MIN(a, b) ((a) < (b) ? (a) : (b)) #endif #define TU_DEFAULT_TIMEOUT (60) -#define MAX_RETRY (100) +#define MAX_RETRY (100) /* Forward references (For keep function order to struct tape_ops) */ int scsipi_ibmtape_readpos(void *device, struct tc_position *pos); int scsipi_ibmtape_locate(void *device, struct tc_position dest, struct tc_position *pos); int scsipi_ibmtape_space(void *device, size_t count, TC_SPACE_TYPE type, struct tc_position *pos); -int scsipi_ibmtape_logsense(void *device, const uint8_t page, const uint8_t subpage, - unsigned char *buf, const size_t size); -int scsipi_ibmtape_modesense(void *device, const unsigned char page, const TC_MP_PC_TYPE pc, - const unsigned char subpage, unsigned char *buf, const size_t size); +int scsipi_ibmtape_logsense( + void *device, const uint8_t page, const uint8_t subpage, unsigned char *buf, const size_t size); +int scsipi_ibmtape_modesense(void *device, + const unsigned char page, + const TC_MP_PC_TYPE pc, + const unsigned char subpage, + unsigned char *buf, + const size_t size); int scsipi_ibmtape_modeselect(void *device, unsigned char *buf, const size_t size); static const char *_generate_product_name(const char *product_id); /* Local functions */ -static inline int _parse_logPage(const unsigned char *logdata, - const uint16_t param, uint32_t *param_size, - unsigned char *buf, const size_t bufsize) +static inline int _parse_logPage( + const unsigned char *logdata, const uint16_t param, uint32_t *param_size, unsigned char *buf, const size_t bufsize) { uint16_t page_len, param_code, param_len; uint32_t i; @@ -120,15 +123,13 @@ static inline int _parse_logPage(const unsigned char *logdata, page_len = ((uint16_t)logdata[2] << 8) + (uint16_t)logdata[3]; i = LOG_PAGE_HEADER_SIZE; - while(i < page_len) - { - param_code = ((uint16_t)logdata[i] << 8) + (uint16_t)logdata[i+1]; - param_len = (uint16_t)logdata[i + LOG_PAGE_PARAMSIZE_OFFSET]; + while (i < page_len) { + param_code = ((uint16_t)logdata[i] << 8) + (uint16_t)logdata[i + 1]; + param_len = (uint16_t)logdata[i + LOG_PAGE_PARAMSIZE_OFFSET]; - if(param_code == param) - { + if (param_code == param) { *param_size = param_len; - if(bufsize < param_len){ + if (bufsize < param_len) { memcpy(buf, &logdata[i + LOG_PAGE_PARAM_OFFSET], bufsize); ret = -EDEV_INTERNAL_ERROR; break; @@ -152,16 +153,12 @@ static inline int _parse_logPage(const unsigned char *logdata, * @return a pointer to the backend on success or NULL on error */ -#define scsipi_ibmtape_opt(templ,offset,value) \ - { templ, offsetof(struct scsipi_ibmtape_global_data, offset), value } +#define scsipi_ibmtape_opt(templ, offset, value) { templ, offsetof(struct scsipi_ibmtape_global_data, offset), value } static struct fuse_opt scsipi_ibmtape_global_opts[] = { - scsipi_ibmtape_opt("scsi_lbprotect=%s", str_crc_checking, 0), - scsipi_ibmtape_opt("strict_drive", strict_drive, 1), - scsipi_ibmtape_opt("nostrict_drive", strict_drive, 0), - scsipi_ibmtape_opt("autodump", disable_auto_dump, 0), - scsipi_ibmtape_opt("noautodump", disable_auto_dump, 1), - FUSE_OPT_END + scsipi_ibmtape_opt("scsi_lbprotect=%s", str_crc_checking, 0), scsipi_ibmtape_opt("strict_drive", strict_drive, 1), + scsipi_ibmtape_opt("nostrict_drive", strict_drive, 0), scsipi_ibmtape_opt("autodump", disable_auto_dump, 0), + scsipi_ibmtape_opt("noautodump", disable_auto_dump, 1), FUSE_OPT_END }; static int null_parser(void *priv, const char *arg, int key, struct fuse_args *outargs) @@ -169,17 +166,17 @@ static int null_parser(void *priv, const char *arg, int key, struct fuse_args *o return 1; } -#define LBP_DISABLE (0x00) -#define REED_SOLOMON_CRC (0x01) -#define CRC32C_CRC (0x02) +#define LBP_DISABLE (0x00) +#define REED_SOLOMON_CRC (0x01) +#define CRC32C_CRC (0x02) -#define TC_MP_INIT_EXT_LBP_RS (0x40) -#define TC_MP_INIT_EXT_LBP_CRC32C (0x20) +#define TC_MP_INIT_EXT_LBP_RS (0x40) +#define TC_MP_INIT_EXT_LBP_CRC32C (0x20) static int _set_lbp(void *device, bool enable) { int ret = -EDEV_UNKNOWN; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; unsigned char buf[TC_MP_SUB_DP_CTRL_SIZE]; unsigned char buf_ext[TC_MP_INIT_EXT_SIZE]; @@ -188,8 +185,7 @@ static int _set_lbp(void *device, bool enable) /* Check logical block protection capability */ if (IS_ENTERPRISE(priv->drive_type)) { ret = scsipi_ibmtape_modesense(device, TC_MP_INIT_EXT, TC_MP_PC_CURRENT, 0x00, buf_ext, sizeof(buf_ext)); - if (ret < 0) - return ret; + if (ret < 0) return ret; if (buf_ext[0x12] & TC_MP_INIT_EXT_LBP_CRC32C) lbp_method = CRC32C_CRC; @@ -209,13 +205,11 @@ static int _set_lbp(void *device, bool enable) /* set logical block protection */ ltfsmsg(LTFS_DEBUG, 30393D, "LBP Enable", enable, ""); ltfsmsg(LTFS_DEBUG, 30393D, "LBP Method", lbp_method, ""); - ret = scsipi_ibmtape_modesense(device, TC_MP_CTRL, TC_MP_PC_CURRENT, - TC_MP_SUB_DP_CTRL, buf, sizeof(buf)); - if (ret < 0) - return ret; + ret = scsipi_ibmtape_modesense(device, TC_MP_CTRL, TC_MP_PC_CURRENT, TC_MP_SUB_DP_CTRL, buf, sizeof(buf)); + if (ret < 0) return ret; - buf[0] = 0x00; - buf[1] = 0x00; + buf[0] = 0x00; + buf[1] = 0x00; if (enable) { buf[20] = lbp_method; buf[21] = 0x04; @@ -240,13 +234,13 @@ static int _set_lbp(void *device, bool enable) priv->f_crc_check = rs_gf256_check; break; default: - priv->f_crc_enc = NULL; + priv->f_crc_enc = NULL; priv->f_crc_check = NULL; break; } ltfsmsg(LTFS_INFO, 30251I); } else { - priv->f_crc_enc = NULL; + priv->f_crc_enc = NULL; priv->f_crc_check = NULL; ltfsmsg(LTFS_INFO, 30252I); } @@ -269,7 +263,7 @@ static bool is_dump_required(struct scsipi_ibmtape_data *priv, int ret, bool *ca return ans; } -#define DUMP_HEADER_SIZE (4) +#define DUMP_HEADER_SIZE (4) #define DUMP_TRANSFER_SIZE (512 * KB) static int _cdb_read_buffer(void *device, int id, unsigned char *buf, size_t offset, size_t len, int type); @@ -279,20 +273,20 @@ static int _get_dump(struct scsipi_ibmtape_data *priv, char *fname) { int ret = 0; - long long data_length, buf_offset; - int dumpfd = -1; - int transfer_size, num_transfers, excess_transfer; - int i, bytes; - unsigned char cap_buf[DUMP_HEADER_SIZE]; - unsigned char *dump_buf; - int buf_id; + long long data_length, buf_offset; + int dumpfd = -1; + int transfer_size, num_transfers, excess_transfer; + int i, bytes; + unsigned char cap_buf[DUMP_HEADER_SIZE]; + unsigned char *dump_buf; + int buf_id; ltfsmsg(LTFS_INFO, 30253I, fname); /* Set transfer size */ transfer_size = DUMP_TRANSFER_SIZE; dump_buf = calloc(1, DUMP_TRANSFER_SIZE); - if(!dump_buf){ + if (!dump_buf) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -EDEV_NO_MEMORY; } @@ -309,18 +303,17 @@ static int _get_dump(struct scsipi_ibmtape_data *priv, char *fname) data_length = (cap_buf[1] << 16) + (cap_buf[2] << 8) + (int)cap_buf[3]; /* Open dump file for write only*/ - dumpfd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666); - if(dumpfd < 0){ + dumpfd = open(fname, O_WRONLY | O_CREAT | O_TRUNC, 0666); + if (dumpfd < 0) { ltfsmsg(LTFS_WARN, 30254W, errno); free(dump_buf); return -2; } /* get the total number of transfers */ - num_transfers = data_length / transfer_size; + num_transfers = data_length / transfer_size; excess_transfer = data_length % transfer_size; - if(excess_transfer) - num_transfers += 1; + if (excess_transfer) num_transfers += 1; /* Total dump data length is %lld. Total number of transfers is %d. */ ltfsmsg(LTFS_DEBUG, 30255D, data_length); @@ -330,14 +323,13 @@ static int _get_dump(struct scsipi_ibmtape_data *priv, char *fname) buf_offset = 0; i = 0; ltfsmsg(LTFS_DEBUG, 30257D); - while(num_transfers) - { + while (num_transfers) { int length; i++; /* Allocation Length is transfer_size or excess_transfer*/ - if(excess_transfer && num_transfers == 1) + if (excess_transfer && num_transfers == 1) length = excess_transfer; else length = transfer_size; @@ -352,16 +344,14 @@ static int _get_dump(struct scsipi_ibmtape_data *priv, char *fname) /* write buffer data into dump file */ bytes = write(dumpfd, dump_buf, length); - if(bytes == -1) - { + if (bytes == -1) { ltfsmsg(LTFS_WARN, 30259W, ret); free(dump_buf); close(dumpfd); return -1; } - if(bytes != length) - { + if (bytes != length) { ltfsmsg(LTFS_WARN, 30260W, bytes, length); free(dump_buf); close(dumpfd); @@ -382,9 +372,9 @@ static int _get_dump(struct scsipi_ibmtape_data *priv, char *fname) static int _take_dump(struct scsipi_ibmtape_data *priv, bool capture_unforced) { - char fname_base[1024]; - char fname[1024]; - time_t now; + char fname_base[1024]; + char fname[1024]; + time_t now; struct tm *tm_now; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_TAKEDUMPDRV)); @@ -392,14 +382,15 @@ static int _take_dump(struct scsipi_ibmtape_data *priv, bool capture_unforced) /* Make base filename */ time(&now); tm_now = localtime(&now); - sprintf(fname_base, "/tmp/ltfs_%s_%d_%02d%02d_%02d%02d%02d" - , priv->drive_serial - , tm_now->tm_year+1900 - , tm_now->tm_mon+1 - , tm_now->tm_mday - , tm_now->tm_hour - , tm_now->tm_min - , tm_now->tm_sec); + sprintf(fname_base, + "/tmp/ltfs_%s_%d_%02d%02d_%02d%02d%02d", + priv->drive_serial, + tm_now->tm_year + 1900, + tm_now->tm_mon + 1, + tm_now->tm_mday, + tm_now->tm_hour, + tm_now->tm_min, + tm_now->tm_sec); if (capture_unforced) { ltfsmsg(LTFS_INFO, 30261I); @@ -476,17 +467,17 @@ static int _raw_open(struct scsipi_ibmtape_data *priv) } struct supported_device **cur = ibm_supported_drives; - while(*cur) { - if((! strncmp(id_data.vendor_id, (*cur)->vendor_id, strlen((*cur)->vendor_id)) ) && - (! strncmp(id_data.product_id, (*cur)->product_id, strlen((*cur)->product_id)) ) ) { + while (*cur) { + if ((!strncmp(id_data.vendor_id, (*cur)->vendor_id, strlen((*cur)->vendor_id))) && + (!strncmp(id_data.product_id, (*cur)->product_id, strlen((*cur)->product_id)))) { drive_type = (*cur)->drive_type; break; } cur++; } - if(drive_type > 0) { - if (!ibm_tape_is_supported_firmware(drive_type, (unsigned char*)id_data.product_rev)) { + if (drive_type > 0) { + if (!ibm_tape_is_supported_firmware(drive_type, (unsigned char *)id_data.product_rev)) { close(priv->dev.fd); priv->dev.fd = -1; return -EDEV_UNSUPPORTED_FIRMWARE; @@ -522,10 +513,10 @@ static int _raw_open(struct scsipi_ibmtape_data *priv) snprintf(priv->info.product_rev, PRODUCT_REV_LENGTH + 1, "%s", id_data.product_rev); snprintf(priv->info.product_name, PRODUCT_NAME_LENGTH + 1, "%s", _generate_product_name(id_data.product_id)); - priv->info.host = 0; + priv->info.host = 0; priv->info.channel = 0; - priv->info.target = 0; - priv->info.lun = -1; + priv->info.target = 0; + priv->info.lun = -1; return 0; } @@ -533,7 +524,7 @@ static int _raw_open(struct scsipi_ibmtape_data *priv) int _raw_tur(const int fd) { int ret = -EDEV_UNKNOWN; - struct scsipi_tape dev = {fd, false}; + struct scsipi_tape dev = { fd, false }; scsireq_t req; unsigned char cdb[CDB6_LEN]; @@ -543,8 +534,7 @@ int _raw_tur(const int fd) /* Zero out the CDB and the result buffer */ ret = init_scsireq(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); @@ -553,10 +543,10 @@ int _raw_tur(const int fd) timeout = TU_DEFAULT_TIMEOUT; /* Build request */ - req.flags = 0; - req.cmdlen = sizeof(cdb); + req.flags = 0; + req.cmdlen = sizeof(cdb); memcpy(req.cmd, cdb, sizeof(cdb)); - req.timeout = SGConversion(timeout); + req.timeout = SGConversion(timeout); ret = scsipi_issue_cdb_command(&dev, &req, cmd_desc, &msg); if (ret < 0) { @@ -596,32 +586,28 @@ int scsipi_ibmtape_get_device_list(struct tc_drive_info *buf, int count); int scsipi_ibmtape_reserve(void *device); static int _register_key(void *device, unsigned char *key); static int _fetch_reservation_key(void *device, struct reservation_info *r); -static int _cdb_pro(void *device, - enum pro_action action, enum pro_type type, - unsigned char *key, unsigned char *sakey); +static int _cdb_pro(void *device, enum pro_action action, enum pro_type type, unsigned char *key, unsigned char *sakey); static int _reconnect_device(void *device) { int ret = -EDEV_UNKNOWN, f_ret; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; int i, devs = 0, info_devs = 0; struct tc_drive_info *buf = NULL; struct reservation_info r_info; /* Close disconnected file descriptor */ - if (priv->dev.fd >= 0) - close(priv->dev.fd); + if (priv->dev.fd >= 0) close(priv->dev.fd); priv->dev.fd = -1; - if (priv->devname) - free(priv->devname); + if (priv->devname) free(priv->devname); priv->devname = NULL; /* Search another device files which has same serial number */ devs = scsipi_ibmtape_get_device_list(NULL, 0); if (devs) { buf = (struct tc_drive_info *)calloc(devs * 2, sizeof(struct tc_drive_info)); - if (! buf) { + if (!buf) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } @@ -629,7 +615,7 @@ static int _reconnect_device(void *device) } for (i = 0; i < info_devs; i++) { - if (! strncmp(buf[i].serial_number, priv->drive_serial, TAPE_SERIAL_LEN_MAX) ) { + if (!strncmp(buf[i].serial_number, priv->drive_serial, TAPE_SERIAL_LEN_MAX)) { priv->devname = strdup(buf[i].name); break; } @@ -660,8 +646,7 @@ static int _reconnect_device(void *device) /* Select another path, recover reservation */ ltfsmsg(LTFS_INFO, 30269I, priv->drive_serial); _register_key(priv, priv->key); - ret = _cdb_pro(device, PRO_ACT_PREEMPT_ABORT, PRO_TYPE_EXCLUSIVE, - priv->key, priv->key); + ret = _cdb_pro(device, PRO_ACT_PREEMPT_ABORT, PRO_TYPE_EXCLUSIVE, priv->key, priv->key); if (!ret) { ltfsmsg(LTFS_INFO, 30272I, priv->drive_serial); _clear_por(priv); @@ -715,8 +700,7 @@ static int _process_errors(struct scsipi_ibmtape_data *priv, int ret, char *msg, } if (priv && !ret_fo) { - if (print && take_dump && !global_data.disable_auto_dump - && is_dump_required(priv, ret, &unforced_dump)) { + if (print && take_dump && !global_data.disable_auto_dump && is_dump_required(priv, ret, &unforced_dump)) { (void)_take_dump(priv, unforced_dump); } } @@ -728,7 +712,7 @@ static int _cdb_read_buffer(void *device, int id, unsigned char *buf, size_t off { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; scsireq_t req; unsigned char cdb[CDB10_LEN]; @@ -740,8 +724,7 @@ static int _cdb_read_buffer(void *device, int id, unsigned char *buf, size_t off /* Zero out the CDB and the result buffer */ ret = init_scsireq(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); @@ -750,29 +733,27 @@ static int _cdb_read_buffer(void *device, int id, unsigned char *buf, size_t off cdb[1] = type; cdb[2] = id; cdb[3] = (unsigned char)(offset >> 16) & 0xFF; - cdb[4] = (unsigned char)(offset >> 8) & 0xFF; - cdb[5] = (unsigned char) offset & 0xFF; - cdb[6] = (unsigned char)(len >> 16) & 0xFF; - cdb[7] = (unsigned char)(len >> 8) & 0xFF; - cdb[8] = (unsigned char) len & 0xFF; + cdb[4] = (unsigned char)(offset >> 8) & 0xFF; + cdb[5] = (unsigned char)offset & 0xFF; + cdb[6] = (unsigned char)(len >> 16) & 0xFF; + cdb[7] = (unsigned char)(len >> 8) & 0xFF; + cdb[8] = (unsigned char)len & 0xFF; timeout = ibm_tape_get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ - req.flags = SCCMD_READ; - req.cmdlen = sizeof(cdb); - req.datalen = len; - req.databuf = buf; + req.flags = SCCMD_READ; + req.cmdlen = sizeof(cdb); + req.datalen = len; + req.databuf = buf; memcpy(req.cmd, cdb, sizeof(cdb)); - req.timeout = SGConversion(timeout); + req.timeout = SGConversion(timeout); ret = scsipi_issue_cdb_command(&priv->dev, &req, cmd_desc, &msg); - if (ret < 0){ + if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } return ret; @@ -795,8 +776,7 @@ static int _cdb_force_dump(struct scsipi_ibmtape_data *priv) /* Zero out the CDB and the result buffer */ ret = init_scsireq(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(buf, 0, sizeof(buf)); @@ -814,22 +794,20 @@ static int _cdb_force_dump(struct scsipi_ibmtape_data *priv) buf[5] = 0x60; /* Diag ID */ timeout = ibm_tape_get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ - req.flags = SCCMD_WRITE; - req.cmdlen = sizeof(cdb); - req.datalen = SENDDIAG_BUF_LEN; - req.databuf = buf; + req.flags = SCCMD_WRITE; + req.cmdlen = sizeof(cdb); + req.datalen = SENDDIAG_BUF_LEN; + req.databuf = buf; memcpy(req.cmd, cdb, sizeof(cdb)); - req.timeout = SGConversion(timeout); + req.timeout = SGConversion(timeout); ret = scsipi_issue_cdb_command(&priv->dev, &req, cmd_desc, &msg); - if (ret < 0){ + if (ret < 0) { ret_ep = _process_errors(priv, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } return ret; @@ -839,7 +817,7 @@ static int _cdb_pri(void *device, unsigned char *buf, int size) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; scsireq_t req; unsigned char cdb[CDB10_LEN]; @@ -849,8 +827,7 @@ static int _cdb_pri(void *device, unsigned char *buf, int size) /* Zero out the CDB and the result buffer */ ret = init_scsireq(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(buf, 0, size); @@ -859,26 +836,24 @@ static int _cdb_pri(void *device, unsigned char *buf, int size) cdb[0] = PERSISTENT_RESERVE_IN; cdb[1] = 0x03; /* Full Info */ cdb[6] = (unsigned char)(size >> 16) & 0xFF; - cdb[7] = (unsigned char)(size >> 8) & 0xFF; - cdb[8] = (unsigned char) size & 0xFF; + cdb[7] = (unsigned char)(size >> 8) & 0xFF; + cdb[8] = (unsigned char)size & 0xFF; timeout = ibm_tape_get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ - req.flags = SCCMD_READ; - req.cmdlen = sizeof(cdb); - req.datalen = size; - req.databuf = buf; + req.flags = SCCMD_READ; + req.cmdlen = sizeof(cdb); + req.datalen = size; + req.databuf = buf; memcpy(req.cmd, cdb, sizeof(cdb)); - req.timeout = SGConversion(timeout); + req.timeout = SGConversion(timeout); ret = scsipi_issue_cdb_command(&priv->dev, &req, cmd_desc, &msg); - if (ret < 0){ + if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } return ret; @@ -923,7 +898,6 @@ static int _fetch_reservation_key(void *device, struct reservation_info *r) addlen = ltfs_betou32(cur + 20); offset += (PRI_FULL_LEN_BASE + addlen); } - } /* Print holder information here */ @@ -940,13 +914,11 @@ static int _fetch_reservation_key(void *device, struct reservation_info *r) return ret; } -static int _cdb_pro(void *device, - enum pro_action action, enum pro_type type, - unsigned char *key, unsigned char *sakey) +static int _cdb_pro(void *device, enum pro_action action, enum pro_type type, unsigned char *key, unsigned char *sakey) { int ret = -EDEV_UNKNOWN, f_ret; int ret_ep = DEVICE_GOOD; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; scsireq_t req; unsigned char cdb[CDB10_LEN]; @@ -959,8 +931,7 @@ static int _cdb_pro(void *device, /* Zero out the CDB and the result buffer */ ret = init_scsireq(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(buf, 0, sizeof(buf)); @@ -972,43 +943,46 @@ static int _cdb_pro(void *device, cdb[8] = PRO_BUF_LEN; /* parameter length */ /* Build parameter list, clear key when key is NULL */ - if (key) - memcpy(buf, key, KEYLEN); + if (key) memcpy(buf, key, KEYLEN); - if (sakey) - memcpy(buf + 8, sakey, KEYLEN); + if (sakey) memcpy(buf + 8, sakey, KEYLEN); timeout = ibm_tape_get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ - req.flags = SCCMD_WRITE; - req.cmdlen = sizeof(cdb); - req.datalen = PRO_BUF_LEN; - req.databuf = buf; + req.flags = SCCMD_WRITE; + req.cmdlen = sizeof(cdb); + req.datalen = PRO_BUF_LEN; + req.databuf = buf; memcpy(req.cmd, cdb, sizeof(cdb)); - req.timeout = SGConversion(timeout); + req.timeout = SGConversion(timeout); ret = scsipi_issue_cdb_command(&priv->dev, &req, cmd_desc, &msg); - if (ret < 0){ + if (ret < 0) { if (ret == -EDEV_RESERVATION_CONFLICT && action == PRO_ACT_RESERVE) { /* Read reservation information and print */ memset(&r_info, 0x00, sizeof(r_info)); f_ret = _fetch_reservation_key(device, &r_info); if (!f_ret) { ltfsmsg(LTFS_WARN, 30266W, r_info.hint, priv->drive_serial); - ltfsmsg(LTFS_WARN, 30267W, - r_info.wwid[0], r_info.wwid[1], r_info.wwid[2], r_info.wwid[3], - r_info.wwid[6], r_info.wwid[5], r_info.wwid[6], r_info.wwid[7], - priv->drive_serial); + ltfsmsg(LTFS_WARN, + 30267W, + r_info.wwid[0], + r_info.wwid[1], + r_info.wwid[2], + r_info.wwid[3], + r_info.wwid[6], + r_info.wwid[5], + r_info.wwid[6], + r_info.wwid[7], + priv->drive_serial); } else { ltfsmsg(LTFS_WARN, 30266W, "unknown host (reserve command)", priv->drive_serial); } } else { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } } @@ -1020,12 +994,9 @@ static int _register_key(void *device, unsigned char *key) int ret = -EDEV_UNKNOWN; start: - ret = _cdb_pro(device, PRO_ACT_REGISTER_IGNORE, PRO_TYPE_NONE, - NULL, key); + ret = _cdb_pro(device, PRO_ACT_REGISTER_IGNORE, PRO_TYPE_NONE, NULL, key); - if (ret == -EDEV_RESERVATION_PREEMPTED || - ret == -EDEV_RESERVATION_RELEASED || - ret == -EDEV_REGISTRATION_PREEMPTED ) + if (ret == -EDEV_RESERVATION_PREEMPTED || ret == -EDEV_RESERVATION_RELEASED || ret == -EDEV_REGISTRATION_PREEMPTED) goto start; return ret; @@ -1046,7 +1017,7 @@ int scsipi_ibmtape_open(const char *devname, void **handle) ltfsmsg(LTFS_INFO, 30209I, devname); priv = calloc(1, sizeof(struct scsipi_ibmtape_data)); - if(!priv) { + if (!priv) { ltfsmsg(LTFS_ERR, 10001E, "scsipi_ibmtape_open: device private data"); return -EDEV_NO_MEMORY; } @@ -1061,12 +1032,11 @@ int scsipi_ibmtape_open(const char *devname, void **handle) ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_OPEN)); ret = _raw_open(priv); - if (ret < 0) - goto free; + if (ret < 0) goto free; /* Setup IBM tape specific parameters */ standard_table = standard_tape_errors; - vendor_table = ibm_tape_errors; + vendor_table = ibm_tape_errors; ibm_tape_init_timeout(&priv->timeouts, priv->drive_type); /* Issue TURs to clear POR sense */ @@ -1077,9 +1047,9 @@ int scsipi_ibmtape_open(const char *devname, void **handle) _register_key(priv, priv->key); /* Initial setting of force perm */ - priv->clear_by_pc = false; + priv->clear_by_pc = false; priv->force_writeperm = DEFAULT_WRITEPERM; - priv->force_readperm = DEFAULT_READPERM; + priv->force_readperm = DEFAULT_READPERM; priv->force_errortype = DEFAULT_ERRORTYPE; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_OPEN)); @@ -1089,8 +1059,7 @@ int scsipi_ibmtape_open(const char *devname, void **handle) return ret; free: - if (priv->devname) - free(priv->devname); + if (priv->devname) free(priv->devname); free(priv); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_OPEN)); return ret; @@ -1105,7 +1074,7 @@ int scsipi_ibmtape_reopen(const char *devname, void *device) int scsipi_ibmtape_close(void *device) { int ret = -EDEV_UNKNOWN; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_CLOSE)); @@ -1123,8 +1092,7 @@ int scsipi_ibmtape_close(void *device) priv->profiler = NULL; } - if (priv->devname) - free(priv->devname); + if (priv->devname) free(priv->devname); free(device); @@ -1134,7 +1102,7 @@ int scsipi_ibmtape_close(void *device) int scsipi_ibmtape_close_raw(void *device) { int ret = 0; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_CLOSERAW)); @@ -1162,7 +1130,7 @@ int scsipi_ibmtape_inquiry_page(void *device, unsigned char page, struct tc_inq_ { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; scsireq_t req; unsigned char cdb[CDB6_LEN]; @@ -1175,35 +1143,31 @@ int scsipi_ibmtape_inquiry_page(void *device, unsigned char page, struct tc_inq_ /* Zero out the CDB and the result buffer */ ret = init_scsireq(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); /* Build CDB */ cdb[0] = INQUIRY; - if(page) - cdb[1] = 0x01; + if (page) cdb[1] = 0x01; cdb[2] = page; ltfs_u16tobe(cdb + 3, sizeof(inq->data)); timeout = ibm_tape_get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ - req.flags = SCCMD_READ; - req.cmdlen = sizeof(cdb); - req.datalen = sizeof(inq->data); - req.databuf = inq->data; + req.flags = SCCMD_READ; + req.cmdlen = sizeof(cdb); + req.datalen = sizeof(inq->data); + req.databuf = inq->data; memcpy(req.cmd, cdb, sizeof(cdb)); - req.timeout = SGConversion(timeout); + req.timeout = SGConversion(timeout); ret = scsipi_issue_cdb_command(&priv->dev, &req, cmd_desc, &msg); - if (ret < 0){ + if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_INQUIRYPAGE)); @@ -1215,17 +1179,16 @@ int scsipi_ibmtape_inquiry(void *device, struct tc_inq *inq) { int ret = -EDEV_UNKNOWN; int vendor_length = 0; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; struct tc_inq_page inq_page; ret = scsipi_ibmtape_inquiry_page(device, 0x00, &inq_page); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(inq, 0, sizeof(struct tc_inq)); - strncpy((char*)inq->vid, (char*)inq_page.data + 8, VENDOR_ID_LENGTH); - strncpy((char*)inq->pid, (char*)inq_page.data + 16, PRODUCT_ID_LENGTH); - strncpy((char*)inq->revision, (char*)inq_page.data + 32, PRODUCT_REV_LENGTH); + strncpy((char *)inq->vid, (char *)inq_page.data + 8, VENDOR_ID_LENGTH); + strncpy((char *)inq->pid, (char *)inq_page.data + 16, PRODUCT_ID_LENGTH); + strncpy((char *)inq->revision, (char *)inq_page.data + 32, PRODUCT_REV_LENGTH); inq->devicetype = priv->drive_type; @@ -1234,7 +1197,7 @@ int scsipi_ibmtape_inquiry(void *device, struct tc_inq *inq) else vendor_length = 20; - strncpy((char*)inq->vendor, (char*)inq_page.data + 36, vendor_length); + strncpy((char *)inq->vendor, (char *)inq_page.data + 36, vendor_length); inq->vendor[vendor_length] = '\0'; return ret; @@ -1244,7 +1207,7 @@ int scsipi_ibmtape_test_unit_ready(void *device) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; scsireq_t req; unsigned char cdb[CDB6_LEN]; @@ -1257,8 +1220,7 @@ int scsipi_ibmtape_test_unit_ready(void *device) /* Zero out the CDB and the result buffer */ ret = init_scsireq(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); @@ -1266,17 +1228,16 @@ int scsipi_ibmtape_test_unit_ready(void *device) cdb[0] = TEST_UNIT_READY; timeout = ibm_tape_get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ - req.flags = 0; - req.cmdlen = sizeof(cdb); + req.flags = 0; + req.cmdlen = sizeof(cdb); memcpy(req.cmd, cdb, sizeof(cdb)); - req.timeout = SGConversion(timeout); + req.timeout = SGConversion(timeout); ret = scsipi_issue_cdb_command(&priv->dev, &req, cmd_desc, &msg); - if (ret < 0){ + if (ret < 0) { bool print_msg = false, take_dump = false; switch (ret) { @@ -1298,8 +1259,7 @@ int scsipi_ibmtape_test_unit_ready(void *device) } ret_ep = _process_errors(device, ret, msg, cmd_desc, print_msg, take_dump); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_TUR)); @@ -1311,7 +1271,7 @@ static int _cdb_read(void *device, char *buf, size_t size, bool sili) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; scsireq_t req; unsigned char cdb[CDB6_LEN]; @@ -1322,33 +1282,30 @@ static int _cdb_read(void *device, char *buf, size_t size, bool sili) /* Zero out the CDB and the result buffer */ ret = init_scsireq(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); /* Build CDB */ cdb[0] = READ; - if(sili && priv->use_sili) - cdb[1] = 0x02; + if (sili && priv->use_sili) cdb[1] = 0x02; cdb[2] = (size >> 16) & 0xFF; - cdb[3] = (size >> 8) & 0xFF; - cdb[4] = size & 0xFF; + cdb[3] = (size >> 8) & 0xFF; + cdb[4] = size & 0xFF; timeout = ibm_tape_get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ - req.flags = SCCMD_READ; - req.cmdlen = sizeof(cdb); - req.datalen = size; - req.databuf = (unsigned char*)buf; + req.flags = SCCMD_READ; + req.cmdlen = sizeof(cdb); + req.datalen = size; + req.databuf = (unsigned char *)buf; memcpy(req.cmd, cdb, sizeof(cdb)); - req.timeout = SGConversion(timeout); + req.timeout = SGConversion(timeout); ret = scsipi_issue_cdb_command(&priv->dev, &req, cmd_desc, &msg); - if (ret < 0){ + if (ret < 0) { int32_t diff_len = 0; unsigned char *sense = req.sense; @@ -1366,15 +1323,15 @@ static int _cdb_read(void *device, char *buf, size_t size, bool sili) * In this case, LTFS will trust SCSI sense. */ if (diff_len < 0) { - ltfsmsg(LTFS_INFO, 30820I, diff_len, size - diff_len); // "Detect overrun condition" + ltfsmsg(LTFS_INFO, 30820I, diff_len, size - diff_len); // "Detect overrun condition" ret = -EDEV_OVERRUN; } else { - ltfsmsg(LTFS_DEBUG, 30821D, diff_len, size - diff_len); // "Detect underrun condition" + ltfsmsg(LTFS_DEBUG, 30821D, diff_len, size - diff_len); // "Detect underrun condition" length = size - diff_len; ret = DEVICE_GOOD; } #else - ltfsmsg(LTFS_WARN, 30216W, req.datalen , resid, diff_len); + ltfsmsg(LTFS_WARN, 30216W, req.datalen, resid, diff_len); return -EDEV_LENGTH_MISMATCH; #endif } else { @@ -1419,17 +1376,16 @@ static int _cdb_read(void *device, char *buf, size_t size, bool sili) } } else { /* check condition is not set so we have a good read and can trust the length value */ - length = req.datalen ; + length = req.datalen; } return length; } -static inline int _handle_block_allocation_failure(void *device, struct tc_position *pos, - int *retry, char *op) +static inline int _handle_block_allocation_failure(void *device, struct tc_position *pos, int *retry, char *op) { int ret = 0; - struct tc_position tmp_pos = {0, 0}; + struct tc_position tmp_pos = { 0, 0 }; /* Sleep 3 secs to wait garbage correction in kernel side and retry */ ltfsmsg(LTFS_WARN, 30277W, ++(*retry)); @@ -1439,14 +1395,17 @@ static inline int _handle_block_allocation_failure(void *device, struct tc_posit if (ret == DEVICE_GOOD && pos->partition == tmp_pos.partition) { if (pos->block == tmp_pos.block) { /* Command is not reached to the drive */ - ltfsmsg(LTFS_INFO, 30278I, op, - (unsigned int)tmp_pos.partition, (unsigned long long)tmp_pos.block); + ltfsmsg(LTFS_INFO, 30278I, op, (unsigned int)tmp_pos.partition, (unsigned long long)tmp_pos.block); ret = -EDEV_RETRY; } else if (pos->block == tmp_pos.block - 1) { /* The drive received the command */ - ltfsmsg(LTFS_INFO, 30279I, op, - (unsigned int)pos->partition, (unsigned long long)pos->block, - (unsigned int)tmp_pos.partition, (unsigned long long)tmp_pos.block); + ltfsmsg(LTFS_INFO, + 30279I, + op, + (unsigned int)pos->partition, + (unsigned long long)pos->block, + (unsigned int)tmp_pos.partition, + (unsigned long long)tmp_pos.block); ret = scsipi_ibmtape_space(device, 1, TC_SPACE_B, pos); if (!ret) { ret = scsipi_ibmtape_readpos(device, &tmp_pos); @@ -1455,42 +1414,65 @@ static inline int _handle_block_allocation_failure(void *device, struct tc_posit ret = -EDEV_RETRY; } else if (!ret) { /* Skip back was successfully done, but not a expected position */ - ltfsmsg(LTFS_WARN, 30282W, op, - (unsigned int)pos->partition, (unsigned long long)pos->block, - (unsigned int)tmp_pos.partition, (unsigned long long)tmp_pos.block); + ltfsmsg(LTFS_WARN, + 30282W, + op, + (unsigned int)pos->partition, + (unsigned long long)pos->block, + (unsigned int)tmp_pos.partition, + (unsigned long long)tmp_pos.block); ret = -LTFS_BAD_LOCATE; } else { - ltfsmsg(LTFS_WARN, 30281W, op, ret, - (unsigned int)pos->partition, (unsigned long long)pos->block, - (unsigned int)tmp_pos.partition, (unsigned long long)tmp_pos.block); + ltfsmsg(LTFS_WARN, + 30281W, + op, + ret, + (unsigned int)pos->partition, + (unsigned long long)pos->block, + (unsigned int)tmp_pos.partition, + (unsigned long long)tmp_pos.block); } } else { - ltfsmsg(LTFS_WARN, 30283W, op, ret, - (unsigned int)pos->partition, (unsigned long long)pos->block, - (unsigned int)tmp_pos.partition, (unsigned long long)tmp_pos.block); + ltfsmsg(LTFS_WARN, + 30283W, + op, + ret, + (unsigned int)pos->partition, + (unsigned long long)pos->block, + (unsigned int)tmp_pos.partition, + (unsigned long long)tmp_pos.block); } } else { /* Unexpected position */ - ltfsmsg(LTFS_WARN, 30280W, op, ret, - (unsigned int)pos->partition, (unsigned long long)pos->block, - (unsigned int)tmp_pos.partition, (unsigned long long)tmp_pos.block); + ltfsmsg(LTFS_WARN, + 30280W, + op, + ret, + (unsigned int)pos->partition, + (unsigned long long)pos->block, + (unsigned int)tmp_pos.partition, + (unsigned long long)tmp_pos.block); ret = -EDEV_BUFFER_ALLOCATE_ERROR; } } else - ltfsmsg(LTFS_WARN, 30281W, op, ret, - (unsigned int)pos->partition, (unsigned long long)pos->block, - (unsigned int)tmp_pos.partition, (unsigned long long)tmp_pos.block); + ltfsmsg(LTFS_WARN, + 30281W, + op, + ret, + (unsigned int)pos->partition, + (unsigned long long)pos->block, + (unsigned int)tmp_pos.partition, + (unsigned long long)tmp_pos.block); return ret; } -int scsipi_ibmtape_read(void *device, char *buf, size_t size, - struct tc_position *pos, const bool unusual_size) +int scsipi_ibmtape_read(void *device, char *buf, size_t size, struct tc_position *pos, const bool unusual_size) { int32_t ret = -EDEV_UNKNOWN; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; size_t datacount = size; - struct tc_position pos_retry = {0, 0}; + struct tc_position pos_retry = { 0, 0 }; int retry_count = 0; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_READ)); @@ -1508,11 +1490,10 @@ int scsipi_ibmtape_read(void *device, char *buf, size_t size, } } - if(global_data.crc_checking) { + if (global_data.crc_checking) { datacount = size + 4; /* Never fall into this block, fail safe to adjust record length*/ - if (datacount > SG_MAX_BLOCK_SIZE) - datacount = SG_MAX_BLOCK_SIZE; + if (datacount > SG_MAX_BLOCK_SIZE) datacount = SG_MAX_BLOCK_SIZE; } start_read: @@ -1525,14 +1506,14 @@ int scsipi_ibmtape_read(void *device, char *buf, size_t size, return ret; } pos_retry.partition = pos->partition; - pos_retry.block = pos->block; + pos_retry.block = pos->block; ret = scsipi_ibmtape_locate(device, pos_retry, pos); if (ret) { ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_READ)); return ret; } goto start_read; - } else if ( !(pos->block) && unusual_size && (unsigned int)ret == size) { + } else if (!(pos->block) && unusual_size && (unsigned int)ret == size) { /* * Try to read again without sili bit, because some I/F doesn't support SILION read correctly * like USB connected LTO drive. @@ -1549,21 +1530,18 @@ int scsipi_ibmtape_read(void *device, char *buf, size_t size, ret = _cdb_read(device, buf, datacount, unusual_size); } else if (ret == -EDEV_BUFFER_ALLOCATE_ERROR && retry_count < MAX_RETRY) { ret = _handle_block_allocation_failure(device, pos, &retry_count, "read"); - if (ret == -EDEV_RETRY) - goto start_read; + if (ret == -EDEV_RETRY) goto start_read; } - if(ret == -EDEV_FILEMARK_DETECTED) - { + if (ret == -EDEV_FILEMARK_DETECTED) { pos->filemarks++; ret = DEVICE_GOOD; } - if(ret >= 0) { + if (ret >= 0) { pos->block++; - if(global_data.crc_checking && ret > 4) { - if (priv->f_crc_check) - ret = priv->f_crc_check(buf, ret - 4); + if (global_data.crc_checking && ret > 4) { + if (priv->f_crc_check) ret = priv->f_crc_check(buf, ret - 4); if (ret < 0) { ltfsmsg(LTFS_ERR, 30221E); _take_dump(priv, false); @@ -1580,7 +1558,7 @@ static int _cdb_write(void *device, uint8_t *buf, size_t size, bool *ew, bool *p { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; scsireq_t req; unsigned char cdb[CDB6_LEN]; @@ -1590,8 +1568,7 @@ static int _cdb_write(void *device, uint8_t *buf, size_t size, bool *ew, bool *p /* Zero out the CDB and the result buffer */ ret = init_scsireq(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); @@ -1599,26 +1576,25 @@ static int _cdb_write(void *device, uint8_t *buf, size_t size, bool *ew, bool *p cdb[0] = WRITE; cdb[1] = 0x00; /* Always variable in LTFS */ cdb[2] = (size >> 16) & 0xFF; - cdb[3] = (size >> 8) & 0xFF; - cdb[4] = size & 0xFF; + cdb[3] = (size >> 8) & 0xFF; + cdb[4] = size & 0xFF; timeout = ibm_tape_get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ - req.flags = SCCMD_WRITE; - req.cmdlen = sizeof(cdb); - req.datalen = size; - req.databuf = (unsigned char*)buf; + req.flags = SCCMD_WRITE; + req.cmdlen = sizeof(cdb); + req.datalen = size; + req.databuf = (unsigned char *)buf; memcpy(req.cmd, cdb, sizeof(cdb)); - req.timeout = SGConversion(timeout); + req.timeout = SGConversion(timeout); *ew = false; *pew = false; ret = scsipi_issue_cdb_command(&priv->dev, &req, cmd_desc, &msg); - if (ret < 0){ + if (ret < 0) { switch (ret) { case -EDEV_EARLY_WARNING: ltfsmsg(LTFS_WARN, 30222W, "write"); @@ -1641,8 +1617,7 @@ static int _cdb_write(void *device, uint8_t *buf, size_t size, bool *ew, bool *p if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } } @@ -1653,7 +1628,7 @@ int scsipi_ibmtape_write(void *device, const char *buf, size_t count, struct tc_ { int ret, ret_fo; bool ew = false, pew = false; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; struct tc_position cur_pos; size_t datacount = count; int retry_count = 0; @@ -1662,16 +1637,16 @@ int scsipi_ibmtape_write(void *device, const char *buf, size_t count, struct tc_ ltfsmsg(LTFS_DEBUG3, 30395D, "write", count, priv->drive_serial); - if ( priv->force_writeperm ) { + if (priv->force_writeperm) { priv->write_counter++; - if ( priv->write_counter > priv->force_writeperm ) { + if (priv->write_counter > priv->force_writeperm) { ltfsmsg(LTFS_INFO, 30274I, "write"); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_WRITE)); if (priv->force_errortype) return -EDEV_NO_SENSE; else return -EDEV_WRITE_PERM; - } else if ( priv->write_counter > (priv->force_writeperm - THRESHOLD_FORCE_WRITE_NO_WRITE) ) { + } else if (priv->write_counter > (priv->force_writeperm - THRESHOLD_FORCE_WRITE_NO_WRITE)) { ltfsmsg(LTFS_INFO, 30275I); pos->block++; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_WRITE)); @@ -1679,9 +1654,8 @@ int scsipi_ibmtape_write(void *device, const char *buf, size_t count, struct tc_ } } - if(global_data.crc_checking) { - if (priv->f_crc_enc) - priv->f_crc_enc((void *)buf, count); + if (global_data.crc_checking) { + if (priv->f_crc_enc) priv->f_crc_enc((void *)buf, count); datacount = count + 4; } @@ -1694,8 +1668,7 @@ int scsipi_ibmtape_write(void *device, const char *buf, size_t count, struct tc_ } else if (ret == -EDEV_NEED_FAILOVER) { ret_fo = scsipi_ibmtape_readpos(device, &cur_pos); if (!ret_fo) { - if (pos->partition == cur_pos.partition - && pos->block + 1 == cur_pos.block) { + if (pos->partition == cur_pos.partition && pos->block + 1 == cur_pos.block) { pos->block++; pos->early_warning = cur_pos.early_warning; pos->programmable_early_warning = cur_pos.programmable_early_warning; @@ -1705,8 +1678,7 @@ int scsipi_ibmtape_write(void *device, const char *buf, size_t count, struct tc_ } } else if (ret == -EDEV_BUFFER_ALLOCATE_ERROR && retry_count < MAX_RETRY) { ret = _handle_block_allocation_failure(device, pos, &retry_count, "write"); - if (ret == -EDEV_RETRY) - goto start_write; + if (ret == -EDEV_RETRY) goto start_write; } ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_WRITE)); @@ -1718,7 +1690,7 @@ int scsipi_ibmtape_writefm(void *device, size_t count, struct tc_position *pos, { int ret = -EDEV_UNKNOWN, ret_fo; int ret_ep = DEVICE_GOOD; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; scsireq_t req; unsigned char cdb[CDB6_LEN]; @@ -1734,31 +1706,28 @@ int scsipi_ibmtape_writefm(void *device, size_t count, struct tc_position *pos, /* Zero out the CDB and the result buffer */ ret = init_scsireq(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); /* Build CDB */ cdb[0] = WRITE_FILEMARKS6; - if (immed) - cdb[1] = 0x01; + if (immed) cdb[1] = 0x01; cdb[2] = (count >> 16) & 0xFF; - cdb[3] = (count >> 8) & 0xFF; - cdb[4] = count & 0xFF; + cdb[3] = (count >> 8) & 0xFF; + cdb[4] = count & 0xFF; timeout = ibm_tape_get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ - req.flags = 0; - req.cmdlen = sizeof(cdb); + req.flags = 0; + req.cmdlen = sizeof(cdb); memcpy(req.cmd, cdb, sizeof(cdb)); - req.timeout = SGConversion(timeout); + req.timeout = SGConversion(timeout); ret = scsipi_issue_cdb_command(&priv->dev, &req, cmd_desc, &msg); - if (ret < 0){ + if (ret < 0) { switch (ret) { case -EDEV_EARLY_WARNING: ltfsmsg(LTFS_WARN, 30222W, "write filemarks"); @@ -1781,24 +1750,20 @@ int scsipi_ibmtape_writefm(void *device, size_t count, struct tc_position *pos, if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } } - if(ret == DEVICE_GOOD) { + if (ret == DEVICE_GOOD) { ret = scsipi_ibmtape_readpos(device, pos); - if(ret == DEVICE_GOOD) { - if (ew && !pos->early_warning) - pos->early_warning = ew; - if (pew && !pos->programmable_early_warning) - pos->programmable_early_warning = pew; + if (ret == DEVICE_GOOD) { + if (ew && !pos->early_warning) pos->early_warning = ew; + if (pew && !pos->programmable_early_warning) pos->programmable_early_warning = pew; } } else if (ret == -EDEV_NEED_FAILOVER) { ret_fo = scsipi_ibmtape_readpos(device, &cur_pos); if (!ret_fo) { - if (pos->partition == cur_pos.partition - && pos->block + count == cur_pos.block) { + if (pos->partition == cur_pos.partition && pos->block + count == cur_pos.block) { pos->block++; pos->early_warning = cur_pos.early_warning; pos->programmable_early_warning = cur_pos.programmable_early_warning; @@ -1817,7 +1782,7 @@ int scsipi_ibmtape_rewind(void *device, struct tc_position *pos) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; scsireq_t req; unsigned char cdb[CDB6_LEN]; @@ -1830,8 +1795,7 @@ int scsipi_ibmtape_rewind(void *device, struct tc_position *pos) /* Zero out the CDB and the result buffer */ ret = init_scsireq(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); @@ -1839,36 +1803,34 @@ int scsipi_ibmtape_rewind(void *device, struct tc_position *pos) cdb[0] = REWIND; timeout = ibm_tape_get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ - req.flags = 0; - req.cmdlen = sizeof(cdb); + req.flags = 0; + req.cmdlen = sizeof(cdb); memcpy(req.cmd, cdb, sizeof(cdb)); - req.timeout = SGConversion(timeout); + req.timeout = SGConversion(timeout); ret = scsipi_issue_cdb_command(&priv->dev, &req, cmd_desc, &msg); - if (ret < 0){ + if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } - if(ret == DEVICE_GOOD) { + if (ret == DEVICE_GOOD) { /* Clear force perm setting */ - priv->clear_by_pc = false; + priv->clear_by_pc = false; priv->force_writeperm = DEFAULT_WRITEPERM; - priv->force_readperm = DEFAULT_READPERM; - priv->write_counter = 0; - priv->read_counter = 0; + priv->force_readperm = DEFAULT_READPERM; + priv->write_counter = 0; + priv->read_counter = 0; ret = scsipi_ibmtape_readpos(device, pos); - if(ret == DEVICE_GOOD) { - if(pos->early_warning) + if (ret == DEVICE_GOOD) { + if (pos->early_warning) ltfsmsg(LTFS_WARN, 30222W, "rewind"); - else if(pos->programmable_early_warning) + else if (pos->programmable_early_warning) ltfsmsg(LTFS_WARN, 30223W, "rewind"); } } @@ -1883,7 +1845,7 @@ int scsipi_ibmtape_locate(void *device, struct tc_position dest, struct tc_posit int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; int ret_rp = DEVICE_GOOD; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; scsireq_t req; unsigned char cdb[CDB16_LEN]; @@ -1893,68 +1855,65 @@ int scsipi_ibmtape_locate(void *device, struct tc_position dest, struct tc_posit bool pc = false; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_LOCATE)); - ltfsmsg(LTFS_DEBUG, 30397D, "locate", - (unsigned long long)dest.partition, - (unsigned long long)dest.block, - priv->drive_serial); + ltfsmsg(LTFS_DEBUG, + 30397D, + "locate", + (unsigned long long)dest.partition, + (unsigned long long)dest.block, + priv->drive_serial); if (pos->partition != dest.partition) { if (priv->clear_by_pc) { /* Clear force perm setting */ - priv->clear_by_pc = false; + priv->clear_by_pc = false; priv->force_writeperm = DEFAULT_WRITEPERM; - priv->force_readperm = DEFAULT_READPERM; - priv->write_counter = 0; - priv->read_counter = 0; + priv->force_readperm = DEFAULT_READPERM; + priv->write_counter = 0; + priv->read_counter = 0; } pc = true; } /* Zero out the CDB and the result buffer */ ret = init_scsireq(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); /* Build CDB */ - cdb[0] = LOCATE16; - if (pc) - cdb[1] = 0x02; /* Set Change partition(CP) flag */ - cdb[3] = (unsigned char)(dest.partition & 0xff); + cdb[0] = LOCATE16; + if (pc) cdb[1] = 0x02; /* Set Change partition(CP) flag */ + cdb[3] = (unsigned char)(dest.partition & 0xff); ltfs_u64tobe(cdb + 4, dest.block); timeout = ibm_tape_get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ - req.flags = 0; - req.cmdlen = sizeof(cdb); + req.flags = 0; + req.cmdlen = sizeof(cdb); memcpy(req.cmd, cdb, sizeof(cdb)); - req.timeout = SGConversion(timeout); + req.timeout = SGConversion(timeout); ret = scsipi_issue_cdb_command(&priv->dev, &req, cmd_desc, &msg); - if (ret < 0){ + if (ret < 0) { if (dest.block == TAPE_BLOCK_MAX && ret == -EDEV_EOD_DETECTED) { ltfsmsg(LTFS_DEBUG, 30224D, "Locate"); ret = DEVICE_GOOD; } else { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } } ret_rp = scsipi_ibmtape_readpos(device, pos); if (ret_rp == DEVICE_GOOD) { - if(pos->early_warning) + if (pos->early_warning) ltfsmsg(LTFS_WARN, 30222W, "locate"); - else if(pos->programmable_early_warning) + else if (pos->programmable_early_warning) ltfsmsg(LTFS_WARN, 30223W, "locate"); } else { - if (!ret) - ret = ret_rp; + if (!ret) ret = ret_rp; } ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_LOCATE)); @@ -1966,7 +1925,7 @@ int scsipi_ibmtape_space(void *device, size_t count, TC_SPACE_TYPE type, struct { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; scsireq_t req; unsigned char cdb[CDB16_LEN]; @@ -1978,33 +1937,29 @@ int scsipi_ibmtape_space(void *device, size_t count, TC_SPACE_TYPE type, struct /* Zero out the CDB and the result buffer */ ret = init_scsireq(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); /* Build CDB */ cdb[0] = SPACE16; - switch(type) { + switch (type) { case TC_SPACE_EOD: ltfsmsg(LTFS_DEBUG, 30392D, "space to EOD", priv->drive_serial); cdb[1] = 0x03; break; case TC_SPACE_FM_F: - ltfsmsg(LTFS_DEBUG, 30396D, "space forward file marks", (unsigned long long)count, - priv->drive_serial); + ltfsmsg(LTFS_DEBUG, 30396D, "space forward file marks", (unsigned long long)count, priv->drive_serial); cdb[1] = 0x01; ltfs_u64tobe(cdb + 4, count); break; case TC_SPACE_FM_B: - ltfsmsg(LTFS_DEBUG, 30396D, "space back file marks", (unsigned long long)count, - priv->drive_serial); + ltfsmsg(LTFS_DEBUG, 30396D, "space back file marks", (unsigned long long)count, priv->drive_serial); cdb[1] = 0x01; ltfs_u64tobe(cdb + 4, -count); break; case TC_SPACE_F: - ltfsmsg(LTFS_DEBUG, 30396D, "space forward records", (unsigned long long)count, - priv->drive_serial); + ltfsmsg(LTFS_DEBUG, 30396D, "space forward records", (unsigned long long)count, priv->drive_serial); cdb[1] = 0x00; ltfs_u64tobe(cdb + 4, count); break; @@ -2020,30 +1975,27 @@ int scsipi_ibmtape_space(void *device, size_t count, TC_SPACE_TYPE type, struct } timeout = ibm_tape_get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ - req.flags = 0; - req.cmdlen = sizeof(cdb); + req.flags = 0; + req.cmdlen = sizeof(cdb); memcpy(req.cmd, cdb, sizeof(cdb)); - req.timeout = SGConversion(timeout); + req.timeout = SGConversion(timeout); ret = scsipi_issue_cdb_command(&priv->dev, &req, cmd_desc, &msg); - if (ret < 0){ + if (ret < 0) { /* TODO: Need to confirm additional operation is required or not */ ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } - if(ret == DEVICE_GOOD) - ret = scsipi_ibmtape_readpos(device, pos); + if (ret == DEVICE_GOOD) ret = scsipi_ibmtape_readpos(device, pos); - if(ret == DEVICE_GOOD) { - if(pos->early_warning) + if (ret == DEVICE_GOOD) { + if (pos->early_warning) ltfsmsg(LTFS_WARN, 30222W, "space"); - else if(pos->programmable_early_warning) + else if (pos->programmable_early_warning) ltfsmsg(LTFS_WARN, 30223W, "space"); } @@ -2056,7 +2008,7 @@ static int _cdb_request_sense(void *device, unsigned char *buf, unsigned char si { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; scsireq_t req; unsigned char cdb[CDB6_LEN]; @@ -2066,8 +2018,7 @@ static int _cdb_request_sense(void *device, unsigned char *buf, unsigned char si /* Zero out the CDB and the result buffer */ ret = init_scsireq(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); @@ -2076,22 +2027,20 @@ static int _cdb_request_sense(void *device, unsigned char *buf, unsigned char si cdb[4] = (unsigned char)size; timeout = ibm_tape_get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ - req.flags = SCCMD_READ; - req.cmdlen = sizeof(cdb); - req.datalen = size; - req.databuf = buf; + req.flags = SCCMD_READ; + req.cmdlen = sizeof(cdb); + req.datalen = size; + req.databuf = buf; memcpy(req.cmd, cdb, sizeof(cdb)); - req.timeout = SGConversion(timeout); + req.timeout = SGConversion(timeout); ret = scsipi_issue_cdb_command(&priv->dev, &req, cmd_desc, &msg); if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } return ret; @@ -2101,7 +2050,7 @@ int scsipi_ibmtape_erase(void *device, struct tc_position *pos, bool long_erase) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; scsireq_t req; unsigned char cdb[CDB6_LEN]; @@ -2120,40 +2069,37 @@ int scsipi_ibmtape_erase(void *device, struct tc_position *pos, bool long_erase) /* Zero out the CDB and the result buffer */ ret = init_scsireq(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); /* Build CDB */ cdb[0] = ERASE; - if (long_erase) - cdb[1] = 0x03; + if (long_erase) cdb[1] = 0x03; timeout = ibm_tape_get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ - req.flags = 0; - req.cmdlen = sizeof(cdb); + req.flags = 0; + req.cmdlen = sizeof(cdb); memcpy(req.cmd, cdb, sizeof(cdb)); - req.timeout = SGConversion(timeout); + req.timeout = SGConversion(timeout); ret = scsipi_issue_cdb_command(&priv->dev, &req, cmd_desc, &msg); if (long_erase) { unsigned char sense_buf[MAXSENSE]; - uint32_t sense_data; - uint32_t progress; + uint32_t sense_data; + uint32_t progress; while (ret == DEVICE_GOOD) { memset(sense_buf, 0, sizeof(sense_buf)); - ret= _cdb_request_sense(device, sense_buf, sizeof(sense_buf)); + ret = _cdb_request_sense(device, sense_buf, sizeof(sense_buf)); - sense_data = ((uint32_t) sense_buf[2] & 0x0F) << 16; - sense_data += ((uint32_t) sense_buf[12] & 0xFF) << 8; - sense_data += ((uint32_t) sense_buf[13] & 0xFF); + sense_data = ((uint32_t)sense_buf[2] & 0x0F) << 16; + sense_data += ((uint32_t)sense_buf[12] & 0xFF) << 8; + sense_data += ((uint32_t)sense_buf[13] & 0xFF); if (sense_data != 0x000016 && sense_data != 0x000018) { /* Erase operation is NOT in progress */ @@ -2162,21 +2108,20 @@ int scsipi_ibmtape_erase(void *device, struct tc_position *pos, bool long_erase) if (IS_ENTERPRISE(priv->drive_type)) { get_current_timespec(&ts_now); - ltfsmsg(LTFS_INFO, 30226I, (int)(ts_now.tv_sec - ts_start.tv_sec)/60); + ltfsmsg(LTFS_INFO, 30226I, (int)(ts_now.tv_sec - ts_start.tv_sec) / 60); } else { - progress = ((uint32_t) sense_buf[16] & 0xFF) << 8; - progress += ((uint32_t) sense_buf[17] & 0xFF); - ltfsmsg(LTFS_INFO, 30227I, (progress*100/0xFFFF)); + progress = ((uint32_t)sense_buf[16] & 0xFF) << 8; + progress += ((uint32_t)sense_buf[17] & 0xFF); + ltfsmsg(LTFS_INFO, 30227I, (progress * 100 / 0xFFFF)); } sleep(60); } } - if (ret < 0){ + if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_ERASE)); @@ -2188,7 +2133,7 @@ static int _cdb_load_unload(void *device, bool load) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; scsireq_t req; unsigned char cdb[CDB6_LEN]; @@ -2198,49 +2143,44 @@ static int _cdb_load_unload(void *device, bool load) /* Zero out the CDB and the result buffer */ ret = init_scsireq(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); /* Build CDB */ cdb[0] = LOAD_UNLOAD; - if (load) - cdb[4] = 0x01; + if (load) cdb[4] = 0x01; timeout = ibm_tape_get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ - req.flags = 0; - req.cmdlen = sizeof(cdb); + req.flags = 0; + req.cmdlen = sizeof(cdb); memcpy(req.cmd, cdb, sizeof(cdb)); - req.timeout = SGConversion(timeout); + req.timeout = SGConversion(timeout); ret = scsipi_issue_cdb_command(&priv->dev, &req, cmd_desc, &msg); - if (ret < 0){ + if (ret < 0) { if (ret == -EDEV_MEDIUM_MAY_BE_CHANGED) { ret = DEVICE_GOOD; } else { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } } return ret; } - #ifndef TC_MP_MEDIUM_CONFIGURATION -#define TC_MP_MEDIUM_CONFIGURATION (0x1D) // ModePage 0x1D (Mediat type) -#define TC_MP_MEDIUM_CONFIGURATION_SIZE (64) +# define TC_MP_MEDIUM_CONFIGURATION (0x1D) // ModePage 0x1D (Mediat type) +# define TC_MP_MEDIUM_CONFIGURATION_SIZE (64) #endif static int scsipi_ibmtape_medium_configuration(void *device) { int ret; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; unsigned char buf[TC_MP_MEDIUM_CONFIGURATION_SIZE]; ret = scsipi_ibmtape_modesense(device, TC_MP_MEDIUM_CONFIGURATION, TC_MP_PC_CURRENT, 0, buf, sizeof(buf)); @@ -2250,32 +2190,31 @@ static int scsipi_ibmtape_medium_configuration(void *device) priv->density_code = buf[8]; priv->is_worm = buf[18] & 0x01; - switch(priv->density_code) { - case TC_DC_LTO5: - priv->cart_type = TC_MP_LTO5D_CART; - break; - case TC_DC_LTO6: - priv->cart_type = TC_MP_LTO6D_CART; - break; - case TC_DC_LTO7: - priv->cart_type = TC_MP_LTO7D_CART; - break; - case TC_DC_LTOM8: - case TC_DC_LTO8: - priv->cart_type = TC_MP_LTO8D_CART; - break; - default: - break; + switch (priv->density_code) { + case TC_DC_LTO5: + priv->cart_type = TC_MP_LTO5D_CART; + break; + case TC_DC_LTO6: + priv->cart_type = TC_MP_LTO6D_CART; + break; + case TC_DC_LTO7: + priv->cart_type = TC_MP_LTO7D_CART; + break; + case TC_DC_LTOM8: + case TC_DC_LTO8: + priv->cart_type = TC_MP_LTO8D_CART; + break; + default: + break; } return 0; } - int scsipi_ibmtape_load(void *device, struct tc_position *pos) { int ret = -EDEV_UNKNOWN; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; unsigned char buf[TC_MP_SUPPORTEDPAGE_SIZE]; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_LOAD)); @@ -2284,21 +2223,21 @@ int scsipi_ibmtape_load(void *device, struct tc_position *pos) ret = _cdb_load_unload(device, true); /* Clear force perm setting */ - priv->clear_by_pc = false; + priv->clear_by_pc = false; priv->force_writeperm = DEFAULT_WRITEPERM; - priv->force_readperm = DEFAULT_READPERM; - priv->write_counter = 0; - priv->read_counter = 0; + priv->force_readperm = DEFAULT_READPERM; + priv->write_counter = 0; + priv->read_counter = 0; scsipi_ibmtape_readpos(device, pos); if (ret < 0) { ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_LOAD)); return ret; } else { - if(ret == DEVICE_GOOD) { - if(pos->early_warning) + if (ret == DEVICE_GOOD) { + if (pos->early_warning) ltfsmsg(LTFS_WARN, 30222W, "load"); - else if(pos->programmable_early_warning) + else if (pos->programmable_early_warning) ltfsmsg(LTFS_WARN, 30223W, "load"); } @@ -2317,8 +2256,7 @@ int scsipi_ibmtape_load(void *device, struct tc_position *pos) priv->cart_type = buf[2]; priv->density_code = buf[8]; - if (priv->cart_type == 0x00) - (void)scsipi_ibmtape_medium_configuration(device); + if (priv->cart_type == 0x00) (void)scsipi_ibmtape_medium_configuration(device); if (priv->cart_type == 0x00) { ltfsmsg(LTFS_WARN, 30265W); @@ -2327,8 +2265,7 @@ int scsipi_ibmtape_load(void *device, struct tc_position *pos) } ret = ibm_tape_is_supported_tape(priv->cart_type, priv->density_code, &(priv->is_worm)); - if(ret == -LTFS_UNSUPPORTED_MEDIUM) - ltfsmsg(LTFS_INFO, 30228I, priv->cart_type, priv->density_code); + if (ret == -LTFS_UNSUPPORTED_MEDIUM) ltfsmsg(LTFS_INFO, 30228I, priv->cart_type, priv->density_code); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_LOAD)); @@ -2338,7 +2275,7 @@ int scsipi_ibmtape_load(void *device, struct tc_position *pos) int scsipi_ibmtape_unload(void *device, struct tc_position *pos) { int ret = -EDEV_UNKNOWN; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_UNLOAD)); ltfsmsg(LTFS_DEBUG, 30392D, "unload", priv->drive_serial); @@ -2346,11 +2283,11 @@ int scsipi_ibmtape_unload(void *device, struct tc_position *pos) ret = _cdb_load_unload(device, false); /* Clear force perm setting */ - priv->clear_by_pc = false; + priv->clear_by_pc = false; priv->force_writeperm = DEFAULT_WRITEPERM; - priv->force_readperm = DEFAULT_READPERM; - priv->write_counter = 0; - priv->read_counter = 0; + priv->force_readperm = DEFAULT_READPERM; + priv->write_counter = 0; + priv->read_counter = 0; if (ret < 0) { scsipi_ibmtape_readpos(device, pos); @@ -2358,12 +2295,12 @@ int scsipi_ibmtape_unload(void *device, struct tc_position *pos) return ret; } - priv->loaded = false; - priv->cart_type = 0; + priv->loaded = false; + priv->cart_type = 0; priv->density_code = 0; - priv->tape_alert = 0; - pos->partition = 0; - pos->block = 0; + priv->tape_alert = 0; + pos->partition = 0; + pos->block = 0; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_UNLOAD)); @@ -2374,7 +2311,7 @@ int scsipi_ibmtape_readpos(void *device, struct tc_position *pos) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; scsireq_t req; unsigned char cdb[CDB10_LEN]; @@ -2387,8 +2324,7 @@ int scsipi_ibmtape_readpos(void *device, struct tc_position *pos) /* Zero out the CDB and the result buffer */ ret = init_scsireq(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); @@ -2397,32 +2333,34 @@ int scsipi_ibmtape_readpos(void *device, struct tc_position *pos) cdb[1] = 0x08; /* Long Format */ timeout = ibm_tape_get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ - req.flags = SCCMD_READ; - req.cmdlen = sizeof(cdb); - req.datalen = sizeof(buf); - req.databuf = buf; + req.flags = SCCMD_READ; + req.cmdlen = sizeof(cdb); + req.datalen = sizeof(buf); + req.databuf = buf; memcpy(req.cmd, cdb, sizeof(cdb)); - req.timeout = SGConversion(timeout); + req.timeout = SGConversion(timeout); ret = scsipi_issue_cdb_command(&priv->dev, &req, cmd_desc, &msg); if (ret == DEVICE_GOOD) { pos->partition = ltfs_betou32(buf + 4); - pos->block = ltfs_betou64(buf + 8); + pos->block = ltfs_betou64(buf + 8); pos->filemarks = ltfs_betou64(buf + 16); pos->early_warning = buf[0] & 0x40; pos->programmable_early_warning = buf[0] & 0x01; - ltfsmsg(LTFS_DEBUG, 30398D, "readpos", (unsigned long long)pos->partition, - (unsigned long long)pos->block, (unsigned long long)pos->filemarks, - priv->drive_serial); + ltfsmsg(LTFS_DEBUG, + 30398D, + "readpos", + (unsigned long long)pos->partition, + (unsigned long long)pos->block, + (unsigned long long)pos->filemarks, + priv->drive_serial); } else { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_READPOS)); @@ -2434,7 +2372,7 @@ int scsipi_ibmtape_setcap(void *device, uint16_t proportion) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; scsireq_t req; unsigned char cdb[CDB6_LEN]; @@ -2461,17 +2399,16 @@ int scsipi_ibmtape_setcap(void *device, uint16_t proportion) return ret; } - buf[0] = 0x00; - buf[1] = 0x00; + buf[0] = 0x00; + buf[1] = 0x00; buf[27] |= 0x01; - buf[28] = 0x00; + buf[28] = 0x00; ret = scsipi_ibmtape_modeselect(device, buf, sizeof(buf)); } else { /* Zero out the CDB and the result buffer */ ret = init_scsireq(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); @@ -2480,20 +2417,18 @@ int scsipi_ibmtape_setcap(void *device, uint16_t proportion) ltfs_u16tobe(cdb + 3, proportion); timeout = ibm_tape_get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ - req.flags = 0; - req.cmdlen = sizeof(cdb); + req.flags = 0; + req.cmdlen = sizeof(cdb); memcpy(req.cmd, cdb, sizeof(cdb)); - req.timeout = SGConversion(timeout); + req.timeout = SGConversion(timeout); ret = scsipi_issue_cdb_command(&priv->dev, &req, cmd_desc, &msg); if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } } @@ -2502,11 +2437,12 @@ int scsipi_ibmtape_setcap(void *device, uint16_t proportion) return ret; } -int scsipi_ibmtape_format(void *device, TC_FORMAT_TYPE format, const char *vol_name, const char *barcode_name, const char *vol_mam_uuid) +int scsipi_ibmtape_format( + void *device, TC_FORMAT_TYPE format, const char *vol_name, const char *barcode_name, const char *vol_mam_uuid) { int ret = -EDEV_UNKNOWN, aux_ret; int ret_ep = DEVICE_GOOD; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; unsigned char buf[TC_MP_SUPPORTEDPAGE_SIZE]; scsireq_t req; @@ -2520,8 +2456,7 @@ int scsipi_ibmtape_format(void *device, TC_FORMAT_TYPE format, const char *vol_n /* Zero out the CDB and the result buffer */ ret = init_scsireq(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); @@ -2530,20 +2465,18 @@ int scsipi_ibmtape_format(void *device, TC_FORMAT_TYPE format, const char *vol_n cdb[2] = format; timeout = ibm_tape_get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ - req.flags = 0; - req.cmdlen = sizeof(cdb); + req.flags = 0; + req.cmdlen = sizeof(cdb); memcpy(req.cmd, cdb, sizeof(cdb)); - req.timeout = SGConversion(timeout); + req.timeout = SGConversion(timeout); ret = scsipi_issue_cdb_command(&priv->dev, &req, cmd_desc, &msg); if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } /* Check Cartridge type */ @@ -2561,9 +2494,9 @@ int scsipi_ibmtape_format(void *device, TC_FORMAT_TYPE format, const char *vol_n int scsipi_ibmtape_remaining_capacity(void *device, struct tc_remaining_cap *cap) { int ret = -EDEV_UNKNOWN; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; - unsigned char buffer[LOGSENSEPAGE]; /* Buffer for logsense */ + unsigned char buffer[LOGSENSEPAGE]; /* Buffer for logsense */ unsigned char buf[LOG_TAPECAPACITY_SIZE]; /* Buffer for parsing logsense data */ uint32_t param_size; int32_t i; @@ -2578,17 +2511,14 @@ int scsipi_ibmtape_remaining_capacity(void *device, struct tc_remaining_cap *cap if (IS_LTO(priv->drive_type) && (DRIVE_GEN(priv->drive_type) == 0x05)) { /* Use LogPage 0x31 */ ret = scsipi_ibmtape_logsense(device, (uint8_t)LOG_TAPECAPACITY, (uint8_t)0, (void *)buffer, LOGSENSEPAGE); - if(ret < 0) - { + if (ret < 0) { ltfsmsg(LTFS_INFO, 30229I, LOG_VOLUMESTATS, ret); goto out; } - for( i = TAPECAP_REMAIN_0; i < TAPECAP_SIZE; i++) - { + for (i = TAPECAP_REMAIN_0; i < TAPECAP_SIZE; i++) { ret = _parse_logPage(buffer, (uint16_t)i, ¶m_size, buf, sizeof(buf)); - if(ret < 0 || param_size != sizeof(uint32_t)) - { + if (ret < 0 || param_size != sizeof(uint32_t)) { ltfsmsg(LTFS_INFO, 30230I, i, param_size); ret = -EDEV_INTERNAL_ERROR; goto out; @@ -2596,8 +2526,7 @@ int scsipi_ibmtape_remaining_capacity(void *device, struct tc_remaining_cap *cap logcap = ltfs_betou32(buf); - switch(i) - { + switch (i) { case TAPECAP_REMAIN_0: cap->remaining_p0 = logcap; break; @@ -2619,13 +2548,14 @@ int scsipi_ibmtape_remaining_capacity(void *device, struct tc_remaining_cap *cap } if (global_data.capacity_offset) { - if (cap->remaining_p1 < global_data.capacity_offset) - cap_offset = cap->remaining_p1; - - ltfsmsg(LTFS_INFO, 30276I, 1, - (unsigned long long)cap->remaining_p1, - (unsigned long long)global_data.capacity_offset, - priv->drive_serial); + if (cap->remaining_p1 < global_data.capacity_offset) cap_offset = cap->remaining_p1; + + ltfsmsg(LTFS_INFO, + 30276I, + 1, + (unsigned long long)cap->remaining_p1, + (unsigned long long)global_data.capacity_offset, + priv->drive_serial); cap->remaining_p1 -= cap_offset; } @@ -2633,8 +2563,7 @@ int scsipi_ibmtape_remaining_capacity(void *device, struct tc_remaining_cap *cap } else { /* Use LogPage 0x17 */ ret = scsipi_ibmtape_logsense(device, LOG_VOLUMESTATS, (uint8_t)0, (void *)buffer, LOGSENSEPAGE); - if(ret < 0) - { + if (ret < 0) { ltfsmsg(LTFS_INFO, 30229I, LOG_VOLUMESTATS, ret); goto out; } @@ -2672,13 +2601,14 @@ int scsipi_ibmtape_remaining_capacity(void *device, struct tc_remaining_cap *cap } if (global_data.capacity_offset) { - if (cap->remaining_p1 < global_data.capacity_offset) - cap_offset = cap->remaining_p1; - - ltfsmsg(LTFS_INFO, 30276I, 1, - (unsigned long long)cap->remaining_p1, - (unsigned long long)global_data.capacity_offset, - priv->drive_serial); + if (cap->remaining_p1 < global_data.capacity_offset) cap_offset = cap->remaining_p1; + + ltfsmsg(LTFS_INFO, + 30276I, + 1, + (unsigned long long)cap->remaining_p1, + (unsigned long long)global_data.capacity_offset, + priv->drive_serial); cap->remaining_p1 -= cap_offset; } @@ -2691,22 +2621,30 @@ int scsipi_ibmtape_remaining_capacity(void *device, struct tc_remaining_cap *cap ret = DEVICE_GOOD; } - ltfsmsg(LTFS_DEBUG3, 30397D, "capacity part0", (unsigned long long)cap->remaining_p0, - (unsigned long long)cap->max_p0, priv->drive_serial); - ltfsmsg(LTFS_DEBUG3, 30397D, "capacity part1", (unsigned long long)cap->remaining_p1, - (unsigned long long)cap->max_p1, priv->drive_serial); + ltfsmsg(LTFS_DEBUG3, + 30397D, + "capacity part0", + (unsigned long long)cap->remaining_p0, + (unsigned long long)cap->max_p0, + priv->drive_serial); + ltfsmsg(LTFS_DEBUG3, + 30397D, + "capacity part1", + (unsigned long long)cap->remaining_p1, + (unsigned long long)cap->max_p1, + priv->drive_serial); out: ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_REMAINCAP)); return ret; } -int scsipi_ibmtape_logsense(void *device, const uint8_t page, const uint8_t subpage, - unsigned char *buf, const size_t size) +int scsipi_ibmtape_logsense( + void *device, const uint8_t page, const uint8_t subpage, unsigned char *buf, const size_t size) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; scsireq_t req; unsigned char cdb[CDB10_LEN]; @@ -2721,13 +2659,11 @@ int scsipi_ibmtape_logsense(void *device, const uint8_t page, const uint8_t subp ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_LOGSENSE)); inner_buf = calloc(1, MAXLP_SIZE); /* Assume max length of LP is 0xFFFF */ - if (!inner_buf) - return -LTFS_NO_MEMORY; + if (!inner_buf) return -LTFS_NO_MEMORY; /* Zero out the CDB and the result buffer */ ret = init_scsireq(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); @@ -2738,22 +2674,20 @@ int scsipi_ibmtape_logsense(void *device, const uint8_t page, const uint8_t subp ltfs_u16tobe(cdb + 7, MAXLP_SIZE); timeout = ibm_tape_get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ - req.flags = SCCMD_READ; - req.cmdlen = sizeof(cdb); - req.datalen = size; - req.databuf = buf; + req.flags = SCCMD_READ; + req.cmdlen = sizeof(cdb); + req.datalen = size; + req.databuf = buf; memcpy(req.cmd, cdb, sizeof(cdb)); - req.timeout = SGConversion(timeout); + req.timeout = SGConversion(timeout); ret = scsipi_issue_cdb_command(&priv->dev, &req, cmd_desc, &msg); - if (ret < 0){ + if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } else { len = ((int)inner_buf[2] << 8) + (int)inner_buf[3] + 4; @@ -2765,18 +2699,22 @@ int scsipi_ibmtape_logsense(void *device, const uint8_t page, const uint8_t subp ret = len; } - free (inner_buf); + free(inner_buf); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_LOGSENSE)); return ret; } -int scsipi_ibmtape_modesense(void *device, const unsigned char page, const TC_MP_PC_TYPE pc, - const unsigned char subpage, unsigned char *buf, const size_t size) +int scsipi_ibmtape_modesense(void *device, + const unsigned char page, + const TC_MP_PC_TYPE pc, + const unsigned char subpage, + unsigned char *buf, + const size_t size) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; scsireq_t req; unsigned char cdb[CDB10_LEN]; @@ -2789,8 +2727,7 @@ int scsipi_ibmtape_modesense(void *device, const unsigned char page, const TC_MP /* Zero out the CDB and the result buffer */ ret = init_scsireq(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); @@ -2801,22 +2738,20 @@ int scsipi_ibmtape_modesense(void *device, const unsigned char page, const TC_MP ltfs_u16tobe(cdb + 7, size); timeout = ibm_tape_get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ - req.flags = SCCMD_READ; - req.cmdlen = sizeof(cdb); - req.datalen = size; - req.databuf = buf; + req.flags = SCCMD_READ; + req.cmdlen = sizeof(cdb); + req.datalen = size; + req.databuf = buf; memcpy(req.cmd, cdb, sizeof(cdb)); - req.timeout = SGConversion(timeout); + req.timeout = SGConversion(timeout); ret = scsipi_issue_cdb_command(&priv->dev, &req, cmd_desc, &msg); - if (ret < 0){ + if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_MODESENSE)); @@ -2828,7 +2763,7 @@ int scsipi_ibmtape_modeselect(void *device, unsigned char *buf, const size_t siz { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; scsireq_t req; unsigned char cdb[CDB10_LEN]; @@ -2841,8 +2776,7 @@ int scsipi_ibmtape_modeselect(void *device, unsigned char *buf, const size_t siz /* Zero out the CDB and the result buffer */ ret = init_scsireq(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); @@ -2851,22 +2785,20 @@ int scsipi_ibmtape_modeselect(void *device, unsigned char *buf, const size_t siz ltfs_u16tobe(cdb + 7, size); timeout = ibm_tape_get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ - req.flags = SCCMD_WRITE; - req.cmdlen = sizeof(cdb); - req.datalen = size; - req.databuf = buf; + req.flags = SCCMD_WRITE; + req.cmdlen = sizeof(cdb); + req.datalen = size; + req.databuf = buf; memcpy(req.cmd, cdb, sizeof(cdb)); - req.timeout = SGConversion(timeout); + req.timeout = SGConversion(timeout); ret = scsipi_issue_cdb_command(&priv->dev, &req, cmd_desc, &msg); - if (ret < 0){ + if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_MODESELECT)); @@ -2877,29 +2809,24 @@ int scsipi_ibmtape_modeselect(void *device, unsigned char *buf, const size_t siz int scsipi_ibmtape_reserve(void *device) { int ret = -EDEV_UNKNOWN, count = 0; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_RESERVEUNIT)); ltfsmsg(LTFS_DEBUG, 30392D, "reserve (PRO)", priv->drive_serial); start: - ret = _cdb_pro(device, PRO_ACT_RESERVE, PRO_TYPE_EXCLUSIVE, - priv->key, NULL); + ret = _cdb_pro(device, PRO_ACT_RESERVE, PRO_TYPE_EXCLUSIVE, priv->key, NULL); /* Retry if reservation is preempted */ - if ( !count && - ( ret == -EDEV_RESERVATION_PREEMPTED || - ret == -EDEV_REGISTRATION_PREEMPTED || - ret == -EDEV_RESERVATION_CONFLICT) - ) { + if (!count && (ret == -EDEV_RESERVATION_PREEMPTED || ret == -EDEV_REGISTRATION_PREEMPTED || + ret == -EDEV_RESERVATION_CONFLICT)) { ltfsmsg(LTFS_INFO, 30268I, priv->drive_serial); _register_key(device, priv->key); count++; goto start; } - if (!ret) - priv->is_reserved = true; + if (!ret) priv->is_reserved = true; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_RESERVEUNIT)); @@ -2909,18 +2836,16 @@ int scsipi_ibmtape_reserve(void *device) int scsipi_ibmtape_release(void *device) { int ret = -EDEV_UNKNOWN; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_RELEASEUNIT)); ltfsmsg(LTFS_DEBUG, 30392D, "release (PRO)", priv->drive_serial); /* Issue release command even if no reservation is made */ - ret = _cdb_pro(device, PRO_ACT_RELEASE, PRO_TYPE_EXCLUSIVE, - priv->key, NULL); + ret = _cdb_pro(device, PRO_ACT_RELEASE, PRO_TYPE_EXCLUSIVE, priv->key, NULL); - if (!ret) - priv->is_reserved = false; + if (!ret) priv->is_reserved = false; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_RELEASEUNIT)); @@ -2931,7 +2856,7 @@ static int _cdb_prevent_allow_medium_removal(void *device, bool prevent) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; scsireq_t req; unsigned char cdb[CDB6_LEN]; @@ -2941,31 +2866,27 @@ static int _cdb_prevent_allow_medium_removal(void *device, bool prevent) /* Zero out the CDB and the result buffer */ ret = init_scsireq(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); /* Build CDB */ cdb[0] = PREVENT_ALLOW_MEDIUM_REMOVAL; - if (prevent) - cdb[4] = 0x01; + if (prevent) cdb[4] = 0x01; timeout = ibm_tape_get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ - req.flags = 0; - req.cmdlen = sizeof(cdb); + req.flags = 0; + req.cmdlen = sizeof(cdb); memcpy(req.cmd, cdb, sizeof(cdb)); - req.timeout = SGConversion(timeout); + req.timeout = SGConversion(timeout); ret = scsipi_issue_cdb_command(&priv->dev, &req, cmd_desc, &msg); - if (ret < 0){ + if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } if (!ret) { @@ -2981,7 +2902,7 @@ static int _cdb_prevent_allow_medium_removal(void *device, bool prevent) int scsipi_ibmtape_prevent_medium_removal(void *device) { int ret = -EDEV_UNKNOWN; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_PREVENTM)); ltfsmsg(LTFS_DEBUG, 30392D, "prevent medium removal", priv->drive_serial); @@ -2994,7 +2915,7 @@ int scsipi_ibmtape_prevent_medium_removal(void *device) int scsipi_ibmtape_allow_medium_removal(void *device) { int ret = -EDEV_UNKNOWN; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_ALLOWMREM)); ltfsmsg(LTFS_DEBUG, 30392D, "allow medium removal", priv->drive_serial); @@ -3004,12 +2925,14 @@ int scsipi_ibmtape_allow_medium_removal(void *device) return ret; } -int scsipi_ibmtape_write_attribute(void *device, const tape_partition_t part, - const unsigned char *buf, const size_t size) +int scsipi_ibmtape_write_attribute(void *device, + const tape_partition_t part, + const unsigned char *buf, + const size_t size) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; scsireq_t req; unsigned char cdb[CDB16_LEN]; @@ -3018,8 +2941,7 @@ int scsipi_ibmtape_write_attribute(void *device, const tape_partition_t part, char *msg = NULL; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_WRITEATTR)); - ltfsmsg(LTFS_DEBUG3, 30396D, "writeattr", (unsigned long long)part, - priv->drive_serial); + ltfsmsg(LTFS_DEBUG3, 30396D, "writeattr", (unsigned long long)part, priv->drive_serial); /* Prepare the buffer to transfer */ uint32_t len = size + 4; @@ -3034,8 +2956,7 @@ int scsipi_ibmtape_write_attribute(void *device, const tape_partition_t part, /* Zero out the CDB and the result buffer */ ret = init_scsireq(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); @@ -3052,18 +2973,17 @@ int scsipi_ibmtape_write_attribute(void *device, const tape_partition_t part, } /* Build request */ - req.flags = SCCMD_WRITE; - req.cmdlen = sizeof(cdb); - req.datalen = len; - req.databuf = buffer; + req.flags = SCCMD_WRITE; + req.cmdlen = sizeof(cdb); + req.datalen = len; + req.databuf = buffer; memcpy(req.cmd, cdb, sizeof(cdb)); - req.timeout = SGConversion(timeout); + req.timeout = SGConversion(timeout); ret = scsipi_issue_cdb_command(&priv->dev, &req, cmd_desc, &msg); - if (ret < 0){ + if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } free(buffer); @@ -3073,12 +2993,12 @@ int scsipi_ibmtape_write_attribute(void *device, const tape_partition_t part, return ret; } -int scsipi_ibmtape_read_attribute(void *device, const tape_partition_t part, - const uint16_t id, unsigned char *buf, const size_t size) +int scsipi_ibmtape_read_attribute( + void *device, const tape_partition_t part, const uint16_t id, unsigned char *buf, const size_t size) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; scsireq_t req; unsigned char cdb[CDB16_LEN]; @@ -3104,8 +3024,7 @@ int scsipi_ibmtape_read_attribute(void *device, const tape_partition_t part, /* Zero out the CDB and the result buffer */ ret = init_scsireq(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); @@ -3117,36 +3036,28 @@ int scsipi_ibmtape_read_attribute(void *device, const tape_partition_t part, ltfs_u32tobe(cdb + 10, len); timeout = ibm_tape_get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ - req.flags = SCCMD_READ; - req.cmdlen = sizeof(cdb); - req.datalen = len; - req.databuf = buffer; + req.flags = SCCMD_READ; + req.cmdlen = sizeof(cdb); + req.datalen = len; + req.databuf = buffer; memcpy(req.cmd, cdb, sizeof(cdb)); - req.timeout = SGConversion(timeout); + req.timeout = SGConversion(timeout); ret = scsipi_issue_cdb_command(&priv->dev, &req, cmd_desc, &msg); - if (ret < 0){ + if (ret < 0) { bool tape_dump = true; - if (ret == -EDEV_INVALID_FIELD_CDB) - tape_dump = false; + if (ret == -EDEV_INVALID_FIELD_CDB) tape_dump = false; ret_ep = _process_errors(device, ret, msg, cmd_desc, true, tape_dump); - if (ret_ep < 0) - ret = ret_ep; - - if (id != TC_MAM_PAGE_COHERENCY && - id != TC_MAM_APP_VENDER && - id != TC_MAM_APP_NAME && - id != TC_MAM_APP_VERSION && - id != TC_MAM_USER_MEDIUM_LABEL && - id != TC_MAM_TEXT_LOCALIZATION_IDENTIFIER && - id != TC_MAM_BARCODE && - id != TC_MAM_APP_FORMAT_VERSION) + if (ret_ep < 0) ret = ret_ep; + + if (id != TC_MAM_PAGE_COHERENCY && id != TC_MAM_APP_VENDER && id != TC_MAM_APP_NAME && id != TC_MAM_APP_VERSION && + id != TC_MAM_USER_MEDIUM_LABEL && id != TC_MAM_TEXT_LOCALIZATION_IDENTIFIER && id != TC_MAM_BARCODE && + id != TC_MAM_APP_FORMAT_VERSION) ltfsmsg(LTFS_INFO, 30233I, ret); } else { if (size == MAXMAM_SIZE) { @@ -3167,7 +3078,7 @@ int scsipi_ibmtape_allow_overwrite(void *device, const struct tc_position pos) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; scsireq_t req; unsigned char cdb[CDB16_LEN]; @@ -3176,12 +3087,16 @@ int scsipi_ibmtape_allow_overwrite(void *device, const struct tc_position pos) char *msg = NULL; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_ALLOWOVERW)); - ltfsmsg(LTFS_DEBUG, 30397D, "allow overwrite", (unsigned long long)pos.partition, (unsigned long long)pos.block, priv->drive_serial); + ltfsmsg(LTFS_DEBUG, + 30397D, + "allow overwrite", + (unsigned long long)pos.partition, + (unsigned long long)pos.block, + priv->drive_serial); /* Zero out the CDB and the result buffer */ ret = init_scsireq(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); @@ -3192,24 +3107,22 @@ int scsipi_ibmtape_allow_overwrite(void *device, const struct tc_position pos) ltfs_u64tobe(cdb + 4, pos.block); timeout = ibm_tape_get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ - req.flags = 0; - req.cmdlen = sizeof(cdb); + req.flags = 0; + req.cmdlen = sizeof(cdb); memcpy(req.cmd, cdb, sizeof(cdb)); - req.timeout = SGConversion(timeout); + req.timeout = SGConversion(timeout); ret = scsipi_issue_cdb_command(&priv->dev, &req, cmd_desc, &msg); - if (ret < 0){ + if (ret < 0) { if (pos.block == TAPE_BLOCK_MAX && ret == -EDEV_EOD_DETECTED) { ltfsmsg(LTFS_DEBUG, 30224D, "Allow Overwrite"); ret = DEVICE_GOOD; } else { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } } @@ -3239,7 +3152,7 @@ int scsipi_ibmtape_rrao(void *device, unsigned char *buf, const uint32_t len, si int scsipi_ibmtape_set_compression(void *device, const bool enable_compression, struct tc_position *pos) { int ret = -EDEV_UNKNOWN; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; unsigned char buf[TC_MP_COMPRESSION_SIZE]; @@ -3247,13 +3160,12 @@ int scsipi_ibmtape_set_compression(void *device, const bool enable_compression, /* Capture compression setting */ ret = scsipi_ibmtape_modesense(device, TC_MP_COMPRESSION, TC_MP_PC_CURRENT, 0x00, buf, sizeof(buf)); - if (ret < 0) - return ret; + if (ret < 0) return ret; - buf[0] = 0x00; - buf[1] = 0x00; + buf[0] = 0x00; + buf[1] = 0x00; - if(enable_compression) + if (enable_compression) buf[18] = buf[18] | 0x80; else buf[18] = buf[18] & 0x7E; @@ -3268,7 +3180,7 @@ int scsipi_ibmtape_set_compression(void *device, const bool enable_compression, int scsipi_ibmtape_set_default(void *device) { int ret = -EDEV_UNKNOWN; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; priv->use_sili = true; @@ -3284,8 +3196,8 @@ int scsipi_ibmtape_set_default(void *device) return ret; } - buf[0] = 0x00; - buf[1] = 0x00; + buf[0] = 0x00; + buf[1] = 0x00; buf[24] = 0x0C; ret = scsipi_ibmtape_modeselect(device, buf, sizeof(buf)); @@ -3314,8 +3226,8 @@ int scsipi_ibmtape_set_default(void *device) * @return 0 on success or a negative value on error */ -#define LOG_TAPE_ALERT (0x2E) -#define LOG_PERFORMANCE (0x37) +#define LOG_TAPE_ALERT (0x2E) +#define LOG_PERFORMANCE (0x37) #define LOG_PERFORMANCE_CAPACITY_SUB (0x64) // Scope(7-6): Mount Values @@ -3323,24 +3235,15 @@ int scsipi_ibmtape_set_default(void *device) // Group(3-0): Capacity static uint16_t volstats[] = { - VOLSTATS_MOUNTS, - VOLSTATS_WRITTEN_DS, - VOLSTATS_WRITE_TEMPS, - VOLSTATS_WRITE_PERMS, - VOLSTATS_READ_DS, - VOLSTATS_READ_TEMPS, - VOLSTATS_READ_PERMS, - VOLSTATS_WRITE_PERMS_PREV, - VOLSTATS_READ_PERMS_PREV, - VOLSTATS_WRITE_MB, - VOLSTATS_READ_MB, - VOLSTATS_PASSES_BEGIN, - VOLSTATS_PASSES_MIDDLE, + VOLSTATS_MOUNTS, VOLSTATS_WRITTEN_DS, VOLSTATS_WRITE_TEMPS, VOLSTATS_WRITE_PERMS, VOLSTATS_READ_DS, + VOLSTATS_READ_TEMPS, VOLSTATS_READ_PERMS, VOLSTATS_WRITE_PERMS_PREV, VOLSTATS_READ_PERMS_PREV, VOLSTATS_WRITE_MB, + VOLSTATS_READ_MB, VOLSTATS_PASSES_BEGIN, VOLSTATS_PASSES_MIDDLE, }; -enum { - PERF_CART_CONDITION = 0x0001, /* < Media Efficiency */ - PERF_ACTIVE_CQ_LOSS_W = 0x7113, /* < Active CQ loss Write */ +enum +{ + PERF_CART_CONDITION = 0x0001, /* < Media Efficiency */ + PERF_ACTIVE_CQ_LOSS_W = 0x7113, /* < Active CQ loss Write */ }; static uint16_t perfstats[] = { @@ -3350,7 +3253,7 @@ static uint16_t perfstats[] = { int scsipi_ibmtape_get_cartridge_health(void *device, struct tc_cartridge_health *cart_health) { int ret = -EDEV_UNKNOWN; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; unsigned char logdata[LOGSENSEPAGE]; unsigned char buf[16]; @@ -3361,16 +3264,16 @@ int scsipi_ibmtape_get_cartridge_health(void *device, struct tc_cartridge_health ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_GETCARTHLTH)); /* Issue LogPage 0x37 */ - cart_health->tape_efficiency = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->tape_efficiency = UNSUPPORTED_CARTRIDGE_HEALTH; ret = scsipi_ibmtape_logsense(device, LOG_PERFORMANCE, (uint8_t)0, logdata, LOGSENSEPAGE); if (ret < 0) ltfsmsg(LTFS_INFO, 30234I, LOG_PERFORMANCE, ret, "get cart health"); else { - for(i = 0; i < (int)((sizeof(perfstats)/sizeof(perfstats[0]))); i++) { + for (i = 0; i < (int)((sizeof(perfstats) / sizeof(perfstats[0]))); i++) { if (_parse_logPage(logdata, perfstats[i], ¶m_size, buf, 16)) { ltfsmsg(LTFS_INFO, 30235I, LOG_PERFORMANCE, "get cart health"); } else { - switch(param_size) { + switch (param_size) { case sizeof(uint8_t): loghlt = (uint64_t)(buf[0]); break; @@ -3378,21 +3281,19 @@ int scsipi_ibmtape_get_cartridge_health(void *device, struct tc_cartridge_health loghlt = ((uint64_t)buf[0] << 8) + (uint64_t)buf[1]; break; case sizeof(uint32_t): - loghlt = ((uint64_t)buf[0] << 24) + ((uint64_t)buf[1] << 16) - + ((uint64_t)buf[2] << 8) + (uint64_t)buf[3]; + loghlt = ((uint64_t)buf[0] << 24) + ((uint64_t)buf[1] << 16) + ((uint64_t)buf[2] << 8) + (uint64_t)buf[3]; break; case sizeof(uint64_t): - loghlt = ((uint64_t)buf[0] << 56) + ((uint64_t)buf[1] << 48) - + ((uint64_t)buf[2] << 40) + ((uint64_t)buf[3] << 32) - + ((uint64_t)buf[4] << 24) + ((uint64_t)buf[5] << 16) - + ((uint64_t)buf[6] << 8) + (uint64_t)buf[7]; + loghlt = ((uint64_t)buf[0] << 56) + ((uint64_t)buf[1] << 48) + ((uint64_t)buf[2] << 40) + + ((uint64_t)buf[3] << 32) + ((uint64_t)buf[4] << 24) + ((uint64_t)buf[5] << 16) + + ((uint64_t)buf[6] << 8) + (uint64_t)buf[7]; break; default: loghlt = UNSUPPORTED_CARTRIDGE_HEALTH; break; } - switch(perfstats[i]) { + switch (perfstats[i]) { case PERF_CART_CONDITION: cart_health->tape_efficiency = loghlt; break; @@ -3404,29 +3305,29 @@ int scsipi_ibmtape_get_cartridge_health(void *device, struct tc_cartridge_health } /* Issue LogPage 0x17 */ - cart_health->mounts = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->written_ds = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->write_temps = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->write_perms = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_ds = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_temps = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_perms = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->mounts = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->written_ds = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->write_temps = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->write_perms = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_ds = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_temps = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_perms = UNSUPPORTED_CARTRIDGE_HEALTH; cart_health->write_perms_prev = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_perms_prev = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->written_mbytes = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_mbytes = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->passes_begin = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->passes_middle = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_perms_prev = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->written_mbytes = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_mbytes = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->passes_begin = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->passes_middle = UNSUPPORTED_CARTRIDGE_HEALTH; ret = scsipi_ibmtape_logsense(device, LOG_VOLUMESTATS, (uint8_t)0, logdata, LOGSENSEPAGE); if (ret < 0) ltfsmsg(LTFS_INFO, 30234I, LOG_VOLUMESTATS, ret, "get cart health"); else { - for(i = 0; i < (int)((sizeof(volstats)/sizeof(volstats[0]))); i++) { + for (i = 0; i < (int)((sizeof(volstats) / sizeof(volstats[0]))); i++) { if (_parse_logPage(logdata, volstats[i], ¶m_size, buf, 16)) { ltfsmsg(LTFS_INFO, 30235I, LOG_VOLUMESTATS, "get cart health"); } else { - switch(param_size) { + switch (param_size) { case sizeof(uint8_t): loghlt = (uint64_t)(buf[0]); break; @@ -3434,21 +3335,19 @@ int scsipi_ibmtape_get_cartridge_health(void *device, struct tc_cartridge_health loghlt = ((uint64_t)buf[0] << 8) + (uint64_t)buf[1]; break; case sizeof(uint32_t): - loghlt = ((uint64_t)buf[0] << 24) + ((uint64_t)buf[1] << 16) - + ((uint64_t)buf[2] << 8) + (uint64_t)buf[3]; + loghlt = ((uint64_t)buf[0] << 24) + ((uint64_t)buf[1] << 16) + ((uint64_t)buf[2] << 8) + (uint64_t)buf[3]; break; case sizeof(uint64_t): - loghlt = ((uint64_t)buf[0] << 56) + ((uint64_t)buf[1] << 48) - + ((uint64_t)buf[2] << 40) + ((uint64_t)buf[3] << 32) - + ((uint64_t)buf[4] << 24) + ((uint64_t)buf[5] << 16) - + ((uint64_t)buf[6] << 8) + (uint64_t)buf[7]; + loghlt = ((uint64_t)buf[0] << 56) + ((uint64_t)buf[1] << 48) + ((uint64_t)buf[2] << 40) + + ((uint64_t)buf[3] << 32) + ((uint64_t)buf[4] << 24) + ((uint64_t)buf[5] << 16) + + ((uint64_t)buf[6] << 8) + (uint64_t)buf[7]; break; default: loghlt = UNSUPPORTED_CARTRIDGE_HEALTH; break; } - switch(volstats[i]) { + switch (volstats[i]) { case VOLSTATS_MOUNTS: cart_health->mounts = loghlt; break; @@ -3502,7 +3401,7 @@ int scsipi_ibmtape_get_cartridge_health(void *device, struct tc_cartridge_health int scsipi_ibmtape_get_tape_alert(void *device, uint64_t *tape_alert) { int ret = -EDEV_UNKNOWN; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; unsigned char logdata[LOGSENSEPAGE]; unsigned char buf[16]; @@ -3519,15 +3418,13 @@ int scsipi_ibmtape_get_tape_alert(void *device, uint64_t *tape_alert) ltfsmsg(LTFS_INFO, 30234I, LOG_TAPE_ALERT, ret, "get tape alert"); else { ret = 0; - for(i = 1; i <= 64; i++) { - if (_parse_logPage(logdata, (uint16_t) i, ¶m_size, buf, 16) - || param_size != sizeof(uint8_t)) { + for (i = 1; i <= 64; i++) { + if (_parse_logPage(logdata, (uint16_t)i, ¶m_size, buf, 16) || param_size != sizeof(uint8_t)) { ltfsmsg(LTFS_INFO, 30235I, LOG_VOLUMESTATS, "get tape alert"); ta = 0; } - if(buf[0]) - ta += (uint64_t)(1) << (i - 1); + if (buf[0]) ta += (uint64_t)(1) << (i - 1); } } @@ -3540,7 +3437,7 @@ int scsipi_ibmtape_get_tape_alert(void *device, uint64_t *tape_alert) int scsipi_ibmtape_clear_tape_alert(void *device, uint64_t tape_alert) { - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_CLRTAPEALT)); priv->tape_alert &= ~tape_alert; @@ -3551,7 +3448,7 @@ int scsipi_ibmtape_clear_tape_alert(void *device, uint64_t tape_alert) int scsipi_ibmtape_get_xattr(void *device, const char *name, char **buf) { int ret = -LTFS_NO_XATTR; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; unsigned char logdata[LOGSENSEPAGE]; unsigned char logbuf[16]; @@ -3562,15 +3459,12 @@ int scsipi_ibmtape_get_xattr(void *device, const char *name, char **buf) ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_GETXATTR)); - if (!strcmp(name, "ltfs.vendor.IBM.mediaCQsLossRate")) - { + if (!strcmp(name, "ltfs.vendor.IBM.mediaCQsLossRate")) { ret = DEVICE_GOOD; /* If first fetch or cache value is too old and value is dirty, refresh value. */ get_current_timespec(&now); - if (priv->fetch_sec_acq_loss_w == 0 || - ((priv->fetch_sec_acq_loss_w + 60 < now.tv_sec) && priv->dirty_acq_loss_w)) - { + if (priv->fetch_sec_acq_loss_w == 0 || ((priv->fetch_sec_acq_loss_w + 60 < now.tv_sec) && priv->dirty_acq_loss_w)) { ret = scsipi_ibmtape_logsense(device, LOG_PERFORMANCE, LOG_PERFORMANCE_CAPACITY_SUB, logdata, LOGSENSEPAGE); if (ret < 0) { @@ -3578,10 +3472,9 @@ int scsipi_ibmtape_get_xattr(void *device, const char *name, char **buf) } else { ret = 0; if (_parse_logPage(logdata, PERF_ACTIVE_CQ_LOSS_W, ¶m_size, logbuf, 16)) { - ltfsmsg(LTFS_INFO, 30235I, LOG_PERFORMANCE, "get xattr"); + ltfsmsg(LTFS_INFO, 30235I, LOG_PERFORMANCE, "get xattr"); ret = -LTFS_NO_XATTR; - } - else { + } else { switch (param_size) { case sizeof(uint32_t): value32 = (uint32_t)ltfs_betou32(logbuf); @@ -3620,16 +3513,15 @@ int scsipi_ibmtape_set_xattr(void *device, const char *name, const char *buf, si { int ret = -LTFS_NO_XATTR; char *null_terminated; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; int64_t perm_count = 0; - if (!size) - return -LTFS_BAD_ARG; + if (!size) return -LTFS_BAD_ARG; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_SETXATTR)); null_terminated = malloc(size + 1); - if (! null_terminated) { + if (!null_terminated) { ltfsmsg(LTFS_ERR, 10001E, "scsipi_ibmtape_set_xattr: null_term"); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_SETXATTR)); return -LTFS_NO_MEMORY; @@ -3637,34 +3529,34 @@ int scsipi_ibmtape_set_xattr(void *device, const char *name, const char *buf, si memcpy(null_terminated, buf, size); null_terminated[size] = '\0'; - if (! strcmp(name, "ltfs.vendor.IBM.forceErrorWrite")) { + if (!strcmp(name, "ltfs.vendor.IBM.forceErrorWrite")) { perm_count = strtoll(null_terminated, NULL, 0); if (perm_count < 0) { priv->force_writeperm = -perm_count; - priv->clear_by_pc = true; + priv->clear_by_pc = true; } else { priv->force_writeperm = perm_count; - priv->clear_by_pc = false; + priv->clear_by_pc = false; } if (priv->force_writeperm && priv->force_writeperm < THRESHOLD_FORCE_WRITE_NO_WRITE) priv->force_writeperm = THRESHOLD_FORCE_WRITE_NO_WRITE; priv->write_counter = 0; ret = DEVICE_GOOD; - } else if (! strcmp(name, "ltfs.vendor.IBM.forceErrorType")) { + } else if (!strcmp(name, "ltfs.vendor.IBM.forceErrorType")) { priv->force_errortype = strtol(null_terminated, NULL, 0); ret = DEVICE_GOOD; - } else if (! strcmp(name, "ltfs.vendor.IBM.forceErrorRead")) { + } else if (!strcmp(name, "ltfs.vendor.IBM.forceErrorRead")) { perm_count = strtoll(null_terminated, NULL, 0); if (perm_count < 0) { priv->force_readperm = -perm_count; - priv->clear_by_pc = true; + priv->clear_by_pc = true; } else { priv->force_readperm = perm_count; - priv->clear_by_pc = false; + priv->clear_by_pc = false; } priv->read_counter = 0; ret = DEVICE_GOOD; - } else if (! strcmp(name, "ltfs.vendor.IBM.capOffset")) { + } else if (!strcmp(name, "ltfs.vendor.IBM.capOffset")) { global_data.capacity_offset = strtoul(null_terminated, NULL, 0); ret = DEVICE_GOOD; } @@ -3676,10 +3568,11 @@ int scsipi_ibmtape_set_xattr(void *device, const char *name, const char *buf, si #define BLOCKLEN_DATA_SIZE 6 -static int _cdb_read_block_limits(void *device) { +static int _cdb_read_block_limits(void *device) +{ int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; scsireq_t req; unsigned char cdb[CDB6_LEN]; @@ -3693,8 +3586,7 @@ static int _cdb_read_block_limits(void *device) { /* Zero out the CDB and the result buffer */ ret = init_scsireq(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); @@ -3702,26 +3594,24 @@ static int _cdb_read_block_limits(void *device) { cdb[0] = READ_BLOCK_LIMITS; timeout = ibm_tape_get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ - req.flags = SCCMD_READ; - req.cmdlen = sizeof(cdb); - req.datalen = sizeof(buf); - req.databuf = buf; + req.flags = SCCMD_READ; + req.cmdlen = sizeof(cdb); + req.datalen = sizeof(buf); + req.databuf = buf; memcpy(req.cmd, cdb, sizeof(cdb)); - req.timeout = SGConversion(timeout); + req.timeout = SGConversion(timeout); ret = scsipi_issue_cdb_command(&priv->dev, &req, cmd_desc, &msg); - if (ret < 0){ + if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } else { - ret = ((unsigned int) buf[1] & 0xFF) << 16; - ret += ((unsigned int) buf[2] & 0xFF) << 8; - ret += ((unsigned int) buf[3] & 0xFF); + ret = ((unsigned int)buf[1] & 0xFF) << 16; + ret += ((unsigned int)buf[2] & 0xFF) << 8; + ret += ((unsigned int)buf[3] & 0xFF); } return ret; @@ -3730,21 +3620,20 @@ static int _cdb_read_block_limits(void *device) { int scsipi_ibmtape_get_parameters(void *device, struct tc_drive_param *params) { int ret = -EDEV_UNKNOWN; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_GETPARAM)); if (priv->loaded) { params->cart_type = priv->cart_type; - params->density = priv->density_code; + params->density = priv->density_code; params->write_protect = 0; if (IS_ENTERPRISE(priv->drive_type)) { unsigned char buf[TC_MP_MEDIUM_SENSE_SIZE]; ret = scsipi_ibmtape_modesense(device, TC_MP_MEDIUM_SENSE, TC_MP_PC_CURRENT, 0, buf, sizeof(buf)); - if (ret < 0) - goto out; + if (ret < 0) goto out; char wp_flag = buf[26]; @@ -3768,8 +3657,7 @@ int scsipi_ibmtape_get_parameters(void *device, struct tc_drive_param *params) unsigned char buf[MODE_DEVICE_CONFIG_SIZE]; ret = scsipi_ibmtape_modesense(device, MODE_DEVICE_CONFIG, TC_MP_PC_CURRENT, 0, buf, sizeof(buf)); - if (ret < 0) - goto out; + if (ret < 0) goto out; if (buf[3] & 0x80) { params->write_protect |= VOL_PHYSICAL_WP; @@ -3785,7 +3673,7 @@ int scsipi_ibmtape_get_parameters(void *device, struct tc_drive_param *params) } } else { params->cart_type = priv->cart_type; - params->density = priv->density_code; + params->density = priv->density_code; } if (global_data.crc_checking) @@ -3800,14 +3688,14 @@ int scsipi_ibmtape_get_parameters(void *device, struct tc_drive_param *params) return ret; } -#define LOG_VOL_STATISTICS (0x17) -#define LOG_VOL_USED_CAPACITY (0x203) -#define LOG_VOL_PART_HEADER_SIZE (4) +#define LOG_VOL_STATISTICS (0x17) +#define LOG_VOL_USED_CAPACITY (0x203) +#define LOG_VOL_PART_HEADER_SIZE (4) int scsipi_ibmtape_get_eod_status(void *device, int part) { int ret = -EDEV_UNKNOWN; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; /* * This feature requires new tape drive firmware @@ -3817,7 +3705,7 @@ int scsipi_ibmtape_get_eod_status(void *device, int part) unsigned char buf[16]; unsigned int i; uint32_t param_size; - uint32_t part_cap[2] = {EOD_UNKNOWN, EOD_UNKNOWN}; + uint32_t part_cap[2] = { EOD_UNKNOWN, EOD_UNKNOWN }; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_GETEODSTAT)); @@ -3830,8 +3718,8 @@ int scsipi_ibmtape_get_eod_status(void *device, int part) } /* Parse Approximate used native capacity of partitions (0x203)*/ - if (_parse_logPage(logdata, (uint16_t)VOLSTATS_PART_USED_CAP, ¶m_size, buf, sizeof(buf)) - || (param_size != sizeof(buf) ) ) { + if (_parse_logPage(logdata, (uint16_t)VOLSTATS_PART_USED_CAP, ¶m_size, buf, sizeof(buf)) || + (param_size != sizeof(buf))) { ltfsmsg(LTFS_WARN, 30238W); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_GETEODSTAT)); return EOD_UNKNOWN; @@ -3843,13 +3731,11 @@ int scsipi_ibmtape_get_eod_status(void *device, int part) uint16_t part_buf; len = buf[i]; - part_buf = (uint16_t)(buf[i + 2] << 8) + (uint16_t) buf[i + 3]; + part_buf = (uint16_t)(buf[i + 2] << 8) + (uint16_t)buf[i + 3]; /* actual length - 1 is stored into len */ - if ( (len - LOG_VOL_PART_HEADER_SIZE + 1) == sizeof(uint32_t) && part_buf < 2) { - part_cap[part_buf] = ((uint32_t) buf[i + 4] << 24) + - ((uint32_t) buf[i + 5] << 16) + - ((uint32_t) buf[i + 6] << 8) + - (uint32_t) buf[i + 7]; + if ((len - LOG_VOL_PART_HEADER_SIZE + 1) == sizeof(uint32_t) && part_buf < 2) { + part_cap[part_buf] = ((uint32_t)buf[i + 4] << 24) + ((uint32_t)buf[i + 5] << 16) + ((uint32_t)buf[i + 6] << 8) + + (uint32_t)buf[i + 7]; } else ltfsmsg(LTFS_WARN, 30239W, i, part_buf, len); @@ -3857,7 +3743,7 @@ int scsipi_ibmtape_get_eod_status(void *device, int part) } /* Create return value */ - if(part_cap[part] == 0xFFFFFFFF) + if (part_cap[part] == 0xFFFFFFFF) ret = EOD_MISSING; else ret = EOD_GOOD; @@ -3872,8 +3758,7 @@ static const char *_generate_product_name(const char *product_id) int i = 0; for (i = 0; ibm_supported_drives[i]; ++i) { - if (strncmp(ibm_supported_drives[i]->product_id, product_id, - strlen(ibm_supported_drives[i]->product_id)) == 0) { + if (strncmp(ibm_supported_drives[i]->product_id, product_id, strlen(ibm_supported_drives[i]->product_id)) == 0) { product_name = ibm_supported_drives[i]->product_name; break; } @@ -3903,14 +3788,12 @@ int scsipi_ibmtape_get_device_list(struct tc_drive_info *buf, int count) dev.is_data_key_set = false; while ((entry = readdir(dp)) != NULL) { - if (strncmp(entry->d_name, "nst", strlen("nst"))) - continue; + if (strncmp(entry->d_name, "nst", strlen("nst"))) continue; sprintf(devname, "/dev/%s", entry->d_name); dev.fd = open(devname, O_RDONLY | O_NONBLOCK); - if (dev.fd < 0) - continue; + if (dev.fd < 0) continue; /* Get the device back to blocking mode */ flags = fcntl(dev.fd, F_GETFL, 0); @@ -3940,10 +3823,10 @@ int scsipi_ibmtape_get_device_list(struct tc_drive_info *buf, int count) snprintf(buf[found].model, TAPE_MODEL_NAME_LEN_MAX + 1, "%s", identifier.product_id); snprintf(buf[found].serial_number, TAPE_SERIAL_LEN_MAX + 1, "%s", identifier.unit_serial); snprintf(buf[found].product_name, PRODUCT_NAME_LENGTH + 1, "%s", _generate_product_name(identifier.product_id)); - buf[found].host = 0; + buf[found].host = 0; buf[found].channel = 0; - buf[found].target = 0; - buf[found].lun = -1; + buf[found].target = 0; + buf[found].lun = -1; } found++; @@ -3963,7 +3846,7 @@ void scsipi_ibmtape_help_message(const char *progname) int scsipi_ibmtape_parse_opts(void *device, void *opt_args) { - struct fuse_args *args = (struct fuse_args *) opt_args; + struct fuse_args *args = (struct fuse_args *)opt_args; int ret; /* fuse_opt_parse can handle a NULL device parameter just fine */ @@ -3995,11 +3878,11 @@ const char *scsipi_ibmtape_default_device_name(void) return devname; } -static int _cdb_spin(void *device, const uint16_t sps, unsigned char **buffer, size_t * const size) +static int _cdb_spin(void *device, const uint16_t sps, unsigned char **buffer, size_t *const size) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; scsireq_t req; unsigned char cdb[CDB12_LEN]; @@ -4010,13 +3893,12 @@ static int _cdb_spin(void *device, const uint16_t sps, unsigned char **buffer, s /* Zero out the CDB and the result buffer */ ret = init_scsireq(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); *buffer = calloc(len, sizeof(unsigned char)); - if (! *buffer) { + if (!*buffer) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -EDEV_NO_MEMORY; } @@ -4028,22 +3910,20 @@ static int _cdb_spin(void *device, const uint16_t sps, unsigned char **buffer, s ltfs_u32tobe(cdb + 6, len); timeout = ibm_tape_get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ - req.flags = SCCMD_READ; - req.cmdlen = sizeof(cdb); - req.datalen = len; - req.databuf = *buffer; + req.flags = SCCMD_READ; + req.cmdlen = sizeof(cdb); + req.datalen = len; + req.databuf = *buffer; memcpy(req.cmd, cdb, sizeof(cdb)); - req.timeout = SGConversion(timeout); + req.timeout = SGConversion(timeout); ret = scsipi_issue_cdb_command(&priv->dev, &req, cmd_desc, &msg); - if (ret < 0){ + if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } *size = ltfs_betou16((*buffer) + 2); @@ -4051,12 +3931,11 @@ static int _cdb_spin(void *device, const uint16_t sps, unsigned char **buffer, s return ret; } -int _cdb_spout(void *device, const uint16_t sps, - unsigned char* const buffer, const size_t size) +int _cdb_spout(void *device, const uint16_t sps, unsigned char *const buffer, const size_t size) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; scsireq_t req; unsigned char cdb[CDB12_LEN]; @@ -4066,8 +3945,7 @@ int _cdb_spout(void *device, const uint16_t sps, /* Zero out the CDB and the result buffer */ ret = init_scsireq(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); @@ -4078,35 +3956,44 @@ int _cdb_spout(void *device, const uint16_t sps, ltfs_u32tobe(cdb + 6, size); timeout = ibm_tape_get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ - req.flags = SCCMD_WRITE; - req.cmdlen = sizeof(cdb); - req.datalen = size; - req.databuf = buffer; + req.flags = SCCMD_WRITE; + req.cmdlen = sizeof(cdb); + req.datalen = size; + req.databuf = buffer; memcpy(req.cmd, cdb, sizeof(cdb)); - req.timeout = SGConversion(timeout); + req.timeout = SGConversion(timeout); ret = scsipi_issue_cdb_command(&priv->dev, &req, cmd_desc, &msg); - if (ret < 0){ + if (ret < 0) { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } return ret; } -static void ltfsmscsipi_keyalias(const char * const title, const unsigned char * const keyalias) +static void ltfsmscsipi_keyalias(const char *const title, const unsigned char *const keyalias) { - char s[128] = {'\0'}; + char s[128] = { '\0' }; if (keyalias) - sprintf(s, "keyalias = %c%c%c%02X%02X%02X%02X%02X%02X%02X%02X%02X", keyalias[0], - keyalias[1], keyalias[2], keyalias[3], keyalias[4], keyalias[5], keyalias[6], - keyalias[7], keyalias[8], keyalias[9], keyalias[10], keyalias[11]); + sprintf(s, + "keyalias = %c%c%c%02X%02X%02X%02X%02X%02X%02X%02X%02X", + keyalias[0], + keyalias[1], + keyalias[2], + keyalias[3], + keyalias[4], + keyalias[5], + keyalias[6], + keyalias[7], + keyalias[8], + keyalias[9], + keyalias[10], + keyalias[11]); else sprintf(s, "keyalias: NULL"); @@ -4115,18 +4002,18 @@ static void ltfsmscsipi_keyalias(const char * const title, const unsigned char * static bool is_ame(void *device) { - unsigned char buf[TC_MP_READ_WRITE_CTRL_SIZE] = {0}; + unsigned char buf[TC_MP_READ_WRITE_CTRL_SIZE] = { 0 }; const int ret = scsipi_ibmtape_modesense(device, TC_MP_READ_WRITE_CTRL, TC_MP_PC_CURRENT, 0, buf, sizeof(buf)); if (ret != 0) { - char message[100] = {0}; + char message[100] = { 0 }; sprintf(message, "failed to get MP %02Xh (%d)", TC_MP_READ_WRITE_CTRL, ret); ltfsmsg(LTFS_DEBUG, 30392D, __FUNCTION__, message); return false; /* Consider that the encryption method is not AME */ } else { const unsigned char encryption_method = buf[16 + 27]; - char message[100] = {0}; + char message[100] = { 0 }; char *method = NULL; switch (encryption_method) { case 0x00: @@ -4166,15 +4053,14 @@ static bool is_ame(void *device) static int is_encryption_capable(void *device) { - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; if (IS_LTO(priv->drive_type)) { ltfsmsg(LTFS_ERR, 30243E, priv->drive_type); return -EDEV_INTERNAL_ERROR; } - if (! is_ame(device)) - return -EDEV_INTERNAL_ERROR; + if (!is_ame(device)) return -EDEV_INTERNAL_ERROR; return DEVICE_GOOD; } @@ -4182,7 +4068,7 @@ static int is_encryption_capable(void *device) int scsipi_ibmtape_set_key(void *device, const unsigned char *keyalias, const unsigned char *key) { int ret = -EDEV_UNKNOWN; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; /* * Encryption Decryption Key DKi keyalias @@ -4200,16 +4086,15 @@ int scsipi_ibmtape_set_key(void *device, const unsigned char *keyalias, const un const uint16_t sps = 0x10; const size_t size = keyalias ? 20 + DK_LENGTH + 4 + DKI_LENGTH : 20; uint8_t *buffer = calloc(size, sizeof(uint8_t)); - if (! buffer) { + if (!buffer) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); ret = -EDEV_NO_MEMORY; goto out; } - unsigned char buf[TC_MP_READ_WRITE_CTRL_SIZE] = {0}; + unsigned char buf[TC_MP_READ_WRITE_CTRL_SIZE] = { 0 }; ret = scsipi_ibmtape_modesense(device, TC_MP_READ_WRITE_CTRL, TC_MP_PC_CURRENT, 0, buf, sizeof(buf)); - if (ret != DEVICE_GOOD) - goto out; + if (ret != DEVICE_GOOD) goto out; ltfs_u16tobe(buffer + 0, sps); ltfs_u16tobe(buffer + 2, size - 4); @@ -4225,38 +4110,44 @@ int scsipi_ibmtape_set_key(void *device, const unsigned char *keyalias, const un * CKORL: 0b Clear key on reservation loss (CKORL) bit */ buffer[5] = 0x00; - enum { DISABLE = 0, EXTERNAL = 1, ENCRYPT = 2 }; + enum + { + DISABLE = 0, + EXTERNAL = 1, + ENCRYPT = 2 + }; buffer[6] = keyalias ? ENCRYPT : DISABLE; /* ENCRYPTION MODE */ - enum { /* DISABLE = 0, */ RAW = 1, DECRYPT = 2, MIXED = 3 }; - buffer[7] = keyalias ? MIXED : DISABLE; /* DECRYPTION MODE */ - buffer[8] = 1; /* ALGORITHM INDEX */ - buffer[9] = 0; /* LOGICAL BLOCK ENCRYPTION KEY FORMAT: plain-text key */ - buffer[10] = 0; /* KAD FORMAT: Unspecified */ + enum + { /* DISABLE = 0, */ RAW = 1, + DECRYPT = 2, + MIXED = 3 }; + buffer[7] = keyalias ? MIXED : DISABLE; /* DECRYPTION MODE */ + buffer[8] = 1; /* ALGORITHM INDEX */ + buffer[9] = 0; /* LOGICAL BLOCK ENCRYPTION KEY FORMAT: plain-text key */ + buffer[10] = 0; /* KAD FORMAT: Unspecified */ ltfs_u16tobe(buffer + 18, keyalias ? DK_LENGTH : 0x00); /* LOGICAL BLOCK ENCRYPTION KEY LENGTH */ if (keyalias) { - if (! key) { + if (!key) { ret = -EINVAL; goto free; } memcpy(buffer + 20, key, DK_LENGTH); /* LOGICAL BLOCK ENCRYPTION KEY */ - buffer[20 + DK_LENGTH] = 0x01; /* KEY DESCRIPTOR TYPE: 01h DKi (Data Key Identifier) */ + buffer[20 + DK_LENGTH] = 0x01; /* KEY DESCRIPTOR TYPE: 01h DKi (Data Key Identifier) */ ltfs_u16tobe(buffer + 20 + DK_LENGTH + 2, DKI_LENGTH); memcpy(buffer + 20 + 0x20 + 4, keyalias, DKI_LENGTH); } - const char * const title = "set key:"; + const char *const title = "set key:"; ltfsmscsipi_keyalias(title, keyalias); ret = _cdb_spout(device, sps, buffer, size); - if (ret != DEVICE_GOOD) - goto free; + if (ret != DEVICE_GOOD) goto free; priv->dev.is_data_key_set = keyalias != NULL; memset(buf, 0, sizeof(buf)); ret = scsipi_ibmtape_modesense(device, TC_MP_READ_WRITE_CTRL, TC_MP_PC_CURRENT, 0, buf, sizeof(buf)); - if (ret != DEVICE_GOOD) - goto out; + if (ret != DEVICE_GOOD) goto out; free: free(buffer); @@ -4266,27 +4157,26 @@ int scsipi_ibmtape_set_key(void *device, const unsigned char *keyalias, const un return ret; } -static void show_hex_dump(const char * const title, const uint8_t * const buf, const size_t size) +static void show_hex_dump(const char *const title, const uint8_t *const buf, const size_t size) { /* * " 1 2 3 4 5 6 7 8" * "12345678901234567890123456789012345678901234567890123456789012345678901234567890" * "xxxxxx 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF\n" < 100 */ - char * const s = calloc((size / 0x10 + 1) * 100, sizeof(char)); + char *const s = calloc((size / 0x10 + 1) * 100, sizeof(char)); char *p = s; uint i = 0; int j = 0; int k = 0; - if (p == NULL) - return; + if (p == NULL) return; for (i = 0; i < size; ++i) { if (i % 0x10 == 0) { if (i) { for (j = 0x10; 0 < j; --j) { - p += sprintf(p, "%c", isprint(buf[i-j]) ? buf[i-j] : '.'); + p += sprintf(p, "%c", isprint(buf[i - j]) ? buf[i - j] : '.'); } } p += sprintf(p, "\n%06X ", i); @@ -4297,7 +4187,7 @@ static void show_hex_dump(const char * const title, const uint8_t * const buf, c p += sprintf(p, " %s", (i + k) % 8 == 7 ? " " : ""); } for (j = 0x10 - k; 0 < j; --j) { - p += sprintf(p, "%c", isprint(buf[i-j]) ? buf[i-j] : '.'); + p += sprintf(p, "%c", isprint(buf[i - j]) ? buf[i - j] : '.'); } ltfsmsg(LTFS_DEBUG, 30392D, title, s); @@ -4306,7 +4196,7 @@ static void show_hex_dump(const char * const title, const uint8_t * const buf, c int scsipi_ibmtape_get_keyalias(void *device, unsigned char **keyalias) { int ret = -EDEV_UNKNOWN; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_GETKEYALIAS)); ret = is_encryption_capable(device); @@ -4330,32 +4220,32 @@ int scsipi_ibmtape_get_keyalias(void *device, unsigned char **keyalias) for (i = 0; i < 2; ++i) { free(buffer); ret = _cdb_spin(device, sps, &buffer, &size); - if (ret != DEVICE_GOOD) - goto free; + if (ret != DEVICE_GOOD) goto free; } show_hex_dump("SPIN:", buffer, size + 4); const unsigned char encryption_status = buffer[12] & 0xF; - enum { - ENC_STAT_INCAPABLE = 0, - ENC_STAT_NOT_YET_BEEN_READ = 1, - ENC_STAT_NOT_A_LOGICAL_BLOCK = 2, - ENC_STAT_NOT_ENCRYPTED = 3, + enum + { + ENC_STAT_INCAPABLE = 0, + ENC_STAT_NOT_YET_BEEN_READ = 1, + ENC_STAT_NOT_A_LOGICAL_BLOCK = 2, + ENC_STAT_NOT_ENCRYPTED = 3, ENC_STAT_ENCRYPTED_BY_UNSUPPORTED_ALGORITHM = 4, - ENC_STAT_ENCRYPTED_BY_SUPPORTED_ALGORITHM = 5, - ENC_STAT_ENCRYPTED_BY_OTHER_KEY = 6, + ENC_STAT_ENCRYPTED_BY_SUPPORTED_ALGORITHM = 5, + ENC_STAT_ENCRYPTED_BY_OTHER_KEY = 6, ENC_STAT_RESERVED, /* 7h-Fh */ }; if (encryption_status == ENC_STAT_ENCRYPTED_BY_UNSUPPORTED_ALGORITHM || - encryption_status == ENC_STAT_ENCRYPTED_BY_SUPPORTED_ALGORITHM || - encryption_status == ENC_STAT_ENCRYPTED_BY_OTHER_KEY) { + encryption_status == ENC_STAT_ENCRYPTED_BY_SUPPORTED_ALGORITHM || + encryption_status == ENC_STAT_ENCRYPTED_BY_OTHER_KEY) { uint offset = 16; /* offset of key descriptor */ while (offset <= size && buffer[offset] != 1) { offset += ltfs_betou16(buffer + offset + 2) + 4; } if (offset <= size && buffer[offset] == 1) { - const uint dki_length = ((int) buffer[offset + 2]) << 8 | buffer[offset + 3]; + const uint dki_length = ((int)buffer[offset + 2]) << 8 | buffer[offset + 3]; if (offset + dki_length <= size) { int n = dki_length < sizeof(priv->dki) ? dki_length : sizeof(priv->dki); memcpy(priv->dki, &buffer[offset + 4], n); @@ -4364,7 +4254,7 @@ int scsipi_ibmtape_get_keyalias(void *device, unsigned char **keyalias) } } - const char * const title = "get key-alias:"; + const char *const title = "get key-alias:"; ltfsmscsipi_keyalias(title, priv->dki); free: @@ -4375,7 +4265,7 @@ int scsipi_ibmtape_get_keyalias(void *device, unsigned char **keyalias) int scsipi_ibmtape_takedump_drive(void *device, bool capture_unforced) { - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_TAKEDUMPDRV)); _take_dump(priv, capture_unforced); @@ -4384,19 +4274,17 @@ int scsipi_ibmtape_takedump_drive(void *device, bool capture_unforced) return 0; } -int scsipi_ibmtape_is_mountable(void *device, const char *barcode, const unsigned char cart_type, - const unsigned char density) +int scsipi_ibmtape_is_mountable(void *device, + const char *barcode, + const unsigned char cart_type, + const unsigned char density) { int ret; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_ISMOUNTABLE)); - ret = ibm_tape_is_mountable( priv->drive_type, - barcode, - cart_type, - density, - global_data.strict_drive); + ret = ibm_tape_is_mountable(priv->drive_type, barcode, cart_type, density, global_data.strict_drive); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_ISMOUNTABLE)); @@ -4406,13 +4294,9 @@ int scsipi_ibmtape_is_mountable(void *device, const char *barcode, const unsigne bool scsipi_ibmtape_is_readonly(void *device) { int ret; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; - ret = ibm_tape_is_mountable( priv->drive_type, - NULL, - priv->cart_type, - priv->density_code, - global_data.strict_drive); + ret = ibm_tape_is_mountable(priv->drive_type, NULL, priv->cart_type, priv->density_code, global_data.strict_drive); if (ret == MEDIUM_READONLY) return true; @@ -4422,7 +4306,7 @@ bool scsipi_ibmtape_is_readonly(void *device) int scsipi_ibmtape_get_worm_status(void *device, bool *is_worm) { - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_GETWORMSTAT)); *is_worm = false; @@ -4432,15 +4316,15 @@ int scsipi_ibmtape_get_worm_status(void *device, bool *is_worm) int scsipi_ibmtape_get_serialnumber(void *device, char **result) { - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; CHECK_ARG_NULL(device, -LTFS_NULL_ARG); CHECK_ARG_NULL(result, -LTFS_NULL_ARG); ltfs_profiler_add_entry(priv->profiler, NULL, CHANGER_REQ_ENTER(REQ_TC_GETSER)); - *result = strdup((const char *) priv->drive_serial); - if (! *result) { + *result = strdup((const char *)priv->drive_serial); + if (!*result) { ltfsmsg(LTFS_ERR, 10001E, "scsipi_ibmtape_get_serialnumber: result"); ltfs_profiler_add_entry(priv->profiler, NULL, CHANGER_REQ_EXIT(REQ_TC_GETSER)); return -EDEV_NO_MEMORY; @@ -4453,7 +4337,7 @@ int scsipi_ibmtape_get_serialnumber(void *device, char **result) int scsipi_ibmtape_get_info(void *device, struct tc_drive_info *info) { - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; memcpy(info, &priv->info, sizeof(struct tc_drive_info)); @@ -4463,21 +4347,18 @@ int scsipi_ibmtape_get_info(void *device, struct tc_drive_info *info) int scsipi_ibmtape_set_profiler(void *device, char *work_dir, bool enable) { int rc = 0; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; char *path; FILE *p; struct timer_info timerinfo; if (enable) { - if (priv->profiler) - return 0; + if (priv->profiler) return 0; - if(!work_dir) - return -LTFS_BAD_ARG; + if (!work_dir) return -LTFS_BAD_ARG; - rc = asprintf(&path, "%s/%s%s%s", work_dir, DRIVER_PROFILER_BASE, - "DUMMY", PROFILER_EXTENSION); + rc = asprintf(&path, "%s/%s%s%s", work_dir, DRIVER_PROFILER_BASE, "DUMMY", PROFILER_EXTENSION); if (rc < 0) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -EDEV_NO_MEMORY; @@ -4487,11 +4368,11 @@ int scsipi_ibmtape_set_profiler(void *device, char *work_dir, bool enable) free(path); - if (! p) + if (!p) rc = -LTFS_FILE_ERR; else { get_timer_info(&timerinfo); - fwrite((void*)&timerinfo, sizeof(timerinfo), 1, p); + fwrite((void *)&timerinfo, sizeof(timerinfo), 1, p); priv->profiler = p; rc = 0; } @@ -4509,7 +4390,7 @@ int scsipi_ibmtape_get_next_block_to_xfer(void *device, struct tc_position *pos) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; - struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data*)device; + struct scsipi_ibmtape_data *priv = (struct scsipi_ibmtape_data *)device; scsireq_t req; unsigned char cdb[CDB10_LEN]; @@ -4524,39 +4405,41 @@ int scsipi_ibmtape_get_next_block_to_xfer(void *device, struct tc_position *pos) /* Zero out the CDB and the result buffer */ ret = init_scsireq(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); /* Build CDB */ cdb[0] = READ_POSITION; - cdb[1] = 0x08; /* Extended Format */ + cdb[1] = 0x08; /* Extended Format */ ltfs_u16tobe(cdb + 7, sizeof(buf)); /* allocation length */ timeout = ibm_tape_get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ - req.flags = SCCMD_READ; - req.cmdlen = sizeof(cdb); - req.datalen = sizeof(buf); - req.databuf = buf; + req.flags = SCCMD_READ; + req.cmdlen = sizeof(cdb); + req.datalen = sizeof(buf); + req.databuf = buf; memcpy(req.cmd, cdb, sizeof(cdb)); - req.timeout = SGConversion(timeout); + req.timeout = SGConversion(timeout); ret = scsipi_issue_cdb_command(&priv->dev, &req, cmd_desc, &msg); if (ret == DEVICE_GOOD) { pos->partition = (tape_partition_t)buf[1]; - pos->block = ltfs_betou64(buf + 16); - - ltfsmsg(LTFS_DEBUG, 30398D, "next-block-to-xfer", - (unsigned long long)pos->partition, (unsigned long long)pos->block, (unsigned long long)0, priv->drive_serial); + pos->block = ltfs_betou64(buf + 16); + + ltfsmsg(LTFS_DEBUG, + 30398D, + "next-block-to-xfer", + (unsigned long long)pos->partition, + (unsigned long long)pos->block, + (unsigned long long)0, + priv->drive_serial); } else { ret_ep = _process_errors(device, ret, msg, cmd_desc, true, true); - if (ret_ep < 0) - ret = ret_ep; + if (ret_ep < 0) ret = ret_ep; } ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_READPOS)); @@ -4565,63 +4448,63 @@ int scsipi_ibmtape_get_next_block_to_xfer(void *device, struct tc_position *pos) } struct tape_ops scsipi_ibmtape_handler = { - .open = scsipi_ibmtape_open, - .reopen = scsipi_ibmtape_reopen, - .close = scsipi_ibmtape_close, - .close_raw = scsipi_ibmtape_close_raw, - .is_connected = scsipi_ibmtape_is_connected, - .inquiry = scsipi_ibmtape_inquiry, - .inquiry_page = scsipi_ibmtape_inquiry_page, - .test_unit_ready = scsipi_ibmtape_test_unit_ready, - .read = scsipi_ibmtape_read, - .write = scsipi_ibmtape_write, - .writefm = scsipi_ibmtape_writefm, - .rewind = scsipi_ibmtape_rewind, - .locate = scsipi_ibmtape_locate, - .space = scsipi_ibmtape_space, - .erase = scsipi_ibmtape_erase, - .load = scsipi_ibmtape_load, - .unload = scsipi_ibmtape_unload, - .readpos = scsipi_ibmtape_readpos, - .setcap = scsipi_ibmtape_setcap, - .format = scsipi_ibmtape_format, - .remaining_capacity = scsipi_ibmtape_remaining_capacity, - .logsense = scsipi_ibmtape_logsense, - .modesense = scsipi_ibmtape_modesense, - .modeselect = scsipi_ibmtape_modeselect, - .reserve_unit = scsipi_ibmtape_reserve, - .release_unit = scsipi_ibmtape_release, + .open = scsipi_ibmtape_open, + .reopen = scsipi_ibmtape_reopen, + .close = scsipi_ibmtape_close, + .close_raw = scsipi_ibmtape_close_raw, + .is_connected = scsipi_ibmtape_is_connected, + .inquiry = scsipi_ibmtape_inquiry, + .inquiry_page = scsipi_ibmtape_inquiry_page, + .test_unit_ready = scsipi_ibmtape_test_unit_ready, + .read = scsipi_ibmtape_read, + .write = scsipi_ibmtape_write, + .writefm = scsipi_ibmtape_writefm, + .rewind = scsipi_ibmtape_rewind, + .locate = scsipi_ibmtape_locate, + .space = scsipi_ibmtape_space, + .erase = scsipi_ibmtape_erase, + .load = scsipi_ibmtape_load, + .unload = scsipi_ibmtape_unload, + .readpos = scsipi_ibmtape_readpos, + .setcap = scsipi_ibmtape_setcap, + .format = scsipi_ibmtape_format, + .remaining_capacity = scsipi_ibmtape_remaining_capacity, + .logsense = scsipi_ibmtape_logsense, + .modesense = scsipi_ibmtape_modesense, + .modeselect = scsipi_ibmtape_modeselect, + .reserve_unit = scsipi_ibmtape_reserve, + .release_unit = scsipi_ibmtape_release, .prevent_medium_removal = scsipi_ibmtape_prevent_medium_removal, - .allow_medium_removal = scsipi_ibmtape_allow_medium_removal, - .write_attribute = scsipi_ibmtape_write_attribute, - .read_attribute = scsipi_ibmtape_read_attribute, - .allow_overwrite = scsipi_ibmtape_allow_overwrite, - .grao = scsipi_ibmtape_grao, - .rrao = scsipi_ibmtape_rrao, + .allow_medium_removal = scsipi_ibmtape_allow_medium_removal, + .write_attribute = scsipi_ibmtape_write_attribute, + .read_attribute = scsipi_ibmtape_read_attribute, + .allow_overwrite = scsipi_ibmtape_allow_overwrite, + .grao = scsipi_ibmtape_grao, + .rrao = scsipi_ibmtape_rrao, // May be command combination - .set_compression = scsipi_ibmtape_set_compression, - .set_default = scsipi_ibmtape_set_default, - .get_cartridge_health = scsipi_ibmtape_get_cartridge_health, - .get_tape_alert = scsipi_ibmtape_get_tape_alert, - .clear_tape_alert = scsipi_ibmtape_clear_tape_alert, - .get_xattr = scsipi_ibmtape_get_xattr, - .set_xattr = scsipi_ibmtape_set_xattr, - .get_parameters = scsipi_ibmtape_get_parameters, - .get_eod_status = scsipi_ibmtape_get_eod_status, - .get_device_list = scsipi_ibmtape_get_device_list, - .help_message = scsipi_ibmtape_help_message, - .parse_opts = scsipi_ibmtape_parse_opts, - .default_device_name = scsipi_ibmtape_default_device_name, - .set_key = scsipi_ibmtape_set_key, - .get_keyalias = scsipi_ibmtape_get_keyalias, - .takedump_drive = scsipi_ibmtape_takedump_drive, - .is_mountable = scsipi_ibmtape_is_mountable, - .get_worm_status = scsipi_ibmtape_get_worm_status, - .get_serialnumber = scsipi_ibmtape_get_serialnumber, - .get_info = scsipi_ibmtape_get_info, - .set_profiler = scsipi_ibmtape_set_profiler, + .set_compression = scsipi_ibmtape_set_compression, + .set_default = scsipi_ibmtape_set_default, + .get_cartridge_health = scsipi_ibmtape_get_cartridge_health, + .get_tape_alert = scsipi_ibmtape_get_tape_alert, + .clear_tape_alert = scsipi_ibmtape_clear_tape_alert, + .get_xattr = scsipi_ibmtape_get_xattr, + .set_xattr = scsipi_ibmtape_set_xattr, + .get_parameters = scsipi_ibmtape_get_parameters, + .get_eod_status = scsipi_ibmtape_get_eod_status, + .get_device_list = scsipi_ibmtape_get_device_list, + .help_message = scsipi_ibmtape_help_message, + .parse_opts = scsipi_ibmtape_parse_opts, + .default_device_name = scsipi_ibmtape_default_device_name, + .set_key = scsipi_ibmtape_set_key, + .get_keyalias = scsipi_ibmtape_get_keyalias, + .takedump_drive = scsipi_ibmtape_takedump_drive, + .is_mountable = scsipi_ibmtape_is_mountable, + .get_worm_status = scsipi_ibmtape_get_worm_status, + .get_serialnumber = scsipi_ibmtape_get_serialnumber, + .get_info = scsipi_ibmtape_get_info, + .set_profiler = scsipi_ibmtape_set_profiler, .get_next_block_to_xfer = scsipi_ibmtape_get_next_block_to_xfer, - .is_readonly = scsipi_ibmtape_is_readonly, + .is_readonly = scsipi_ibmtape_is_readonly, }; struct tape_ops *tape_dev_get_ops(void) diff --git a/src/tape_drivers/netbsd/scsipi-ibmtape/scsipi_scsi_tape.c b/src/tape_drivers/netbsd/scsipi-ibmtape/scsipi_scsi_tape.c index b9aa68f7..8b395e68 100644 --- a/src/tape_drivers/netbsd/scsipi-ibmtape/scsipi_scsi_tape.c +++ b/src/tape_drivers/netbsd/scsipi-ibmtape/scsipi_scsi_tape.c @@ -51,8 +51,8 @@ #include #include -#include "libltfs/ltfs_error.h" #include "libltfs/ltfs_endian.h" +#include "libltfs/ltfs_error.h" #include "libltfs/ltfslogging.h" #include "tape_drivers/vendor_compat.h" @@ -70,73 +70,61 @@ static int scsipi_sense2errno(scsireq_t *req, uint32_t *s, char **msg) unsigned char *sense = req->sense; uint32_t sense_value = 0; - unsigned char sk = (*(sense + 2)) & 0x0F; - unsigned char asc = *(sense + 12); + unsigned char sk = (*(sense + 2)) & 0x0F; + unsigned char asc = *(sense + 12); unsigned char ascq = *(sense + 13); - sense_value += (uint32_t) sk << 16; - sense_value += (uint32_t) asc << 8; - sense_value += (uint32_t) ascq; + sense_value += (uint32_t)sk << 16; + sense_value += (uint32_t)asc << 8; + sense_value += (uint32_t)ascq; *s = sense_value; rc = _sense2errorcode(sense_value, standard_table, msg, MASK_WITH_SENSE_KEY); /* NOTE: error table must be changed in library edition */ - if (rc == -EDEV_VENDOR_UNIQUE) - rc = _sense2errorcode(sense_value, vendor_table, msg, MASK_WITH_SENSE_KEY); + if (rc == -EDEV_VENDOR_UNIQUE) rc = _sense2errorcode(sense_value, vendor_table, msg, MASK_WITH_SENSE_KEY); - if (rc == -EDEV_UNKNOWN && ((sense_value & 0xFF0000) == 0x040000) ) - rc = -EDEV_HARDWARE_ERROR; + if (rc == -EDEV_UNKNOWN && ((sense_value & 0xFF0000) == 0x040000)) rc = -EDEV_HARDWARE_ERROR; return rc; } -static bool is_expected_error(struct scsipi_tape *device, uint8_t *cdb, int32_t rc ) +static bool is_expected_error(struct scsipi_tape *device, uint8_t *cdb, int32_t rc) { - int cmd = (cdb[0]&0xFF); + int cmd = (cdb[0] & 0xFF); uint64_t destination; uint64_t cdb_dest[8]; int i; switch (cmd) { case TEST_UNIT_READY: - if (rc == -EDEV_NEED_INITIALIZE || rc == -EDEV_CONFIGURE_CHANGED) - return true; + if (rc == -EDEV_NEED_INITIALIZE || rc == -EDEV_CONFIGURE_CHANGED) return true; break; case READ: - if (rc == -EDEV_FILEMARK_DETECTED || rc == -EDEV_NO_SENSE || rc == -EDEV_CLEANING_REQUIRED) - return true; - if ((rc == -EDEV_CRYPTO_ERROR || rc == -EDEV_KEY_REQUIRED) && !device->is_data_key_set) - return true; + if (rc == -EDEV_FILEMARK_DETECTED || rc == -EDEV_NO_SENSE || rc == -EDEV_CLEANING_REQUIRED) return true; + if ((rc == -EDEV_CRYPTO_ERROR || rc == -EDEV_KEY_REQUIRED) && !device->is_data_key_set) return true; break; case WRITE: - if (rc == -EDEV_EARLY_WARNING || rc == -EDEV_PROG_EARLY_WARNING || rc == -EDEV_CLEANING_REQUIRED) - return true; + if (rc == -EDEV_EARLY_WARNING || rc == -EDEV_PROG_EARLY_WARNING || rc == -EDEV_CLEANING_REQUIRED) return true; break; case WRITE_FILEMARKS6: - if (rc == -EDEV_EARLY_WARNING || rc == -EDEV_PROG_EARLY_WARNING || rc == -EDEV_CLEANING_REQUIRED) - return true; + if (rc == -EDEV_EARLY_WARNING || rc == -EDEV_PROG_EARLY_WARNING || rc == -EDEV_CLEANING_REQUIRED) return true; break; case LOAD_UNLOAD: - if ((cdb[4] & 0x01) == 0) // Unload - if (rc == -EDEV_CLEANING_REQUIRED) - return true; + if ((cdb[4] & 0x01) == 0) // Unload + if (rc == -EDEV_CLEANING_REQUIRED) return true; break; case MODE_SELECT10: - if (rc == -EDEV_MODE_PARAMETER_ROUNDED) - return true; + if (rc == -EDEV_MODE_PARAMETER_ROUNDED) return true; break; case LOCATE16: - for (i=0; i<8; i++) - cdb_dest[i] = (uint64_t)cdb[i+4] & 0xff; + for (i = 0; i < 8; i++) + cdb_dest[i] = (uint64_t)cdb[i + 4] & 0xff; - destination = (cdb_dest[0] << 56) + (cdb_dest[1] << 48) - + (cdb_dest[2] << 40) + (cdb_dest[3] << 32) - + (cdb_dest[4] << 24) + (cdb_dest[5] << 16) - + (cdb_dest[6] << 8) + cdb_dest[7]; + destination = (cdb_dest[0] << 56) + (cdb_dest[1] << 48) + (cdb_dest[2] << 40) + (cdb_dest[3] << 32) + + (cdb_dest[4] << 24) + (cdb_dest[5] << 16) + (cdb_dest[6] << 8) + cdb_dest[7]; - if (destination == TAPE_BLOCK_MAX && rc == -EDEV_EOD_DETECTED) - return true; + if (destination == TAPE_BLOCK_MAX && rc == -EDEV_EOD_DETECTED) return true; break; } @@ -144,44 +132,43 @@ static bool is_expected_error(struct scsipi_tape *device, uint8_t *cdb, int32_t } /* Global functions */ -#define HOST_OK (0x00) -#define HOST_NO_CONNECT (0x01) -#define HOST_BUS_BUSY (0x02) -#define HOST_TIME_OUT (0x03) -#define HOST_BAD_TARGET (0x04) -#define HOST_ABORT (0x05) -#define HOST_PARITY (0x06) -#define HOST_ERROR (0x07) -#define HOST_RESET (0x08) -#define HOST_BAD_INTR (0x09) +#define HOST_OK (0x00) +#define HOST_NO_CONNECT (0x01) +#define HOST_BUS_BUSY (0x02) +#define HOST_TIME_OUT (0x03) +#define HOST_BAD_TARGET (0x04) +#define HOST_ABORT (0x05) +#define HOST_PARITY (0x06) +#define HOST_ERROR (0x07) +#define HOST_RESET (0x08) +#define HOST_BAD_INTR (0x09) #define HOST_PASSTHROUGH (0x0a) -#define HOST_SOFT_ERROR (0x0b) -#define HOST_IMM_RETRY (0x0c) -#define HOST_REQUEUE (0x0d) -#define HOST_TRANS_DISR (0x0e) -#define HOST_TRANS_FAIL (0x0f) +#define HOST_SOFT_ERROR (0x0b) +#define HOST_IMM_RETRY (0x0c) +#define HOST_REQUEUE (0x0d) +#define HOST_TRANS_DISR (0x0e) +#define HOST_TRANS_FAIL (0x0f) #define HOST_TARGET_FAIL (0x10) -#define HOST_NEXUS_FAIL (0x11) - -#define DRIVER_OK (0x00) -#define DRIVER_BUSY (0x01) -#define DRIVER_SOFT (0x02) -#define DRIVER_MEDIA (0x03) -#define DRIVER_ERROR (0x04) -#define DRIVER_INVALID (0x05) -#define DRIVER_TIMEOUT (0x06) -#define DRIVER_HARD (0x07) -#define DRIVER_SENSE (0x08) - -#define NO_SUGGESTION (0x00) -#define SUGGEST_RETRY (0x10) -#define SUGGEST_ABORT (0x20) -#define SUGGEST_REMAP (0x30) -#define SUGGEST_DIE (0x40) -#define SUGGEST_SENSE (0x80) - -int scsipi_issue_cdb_command(struct scsipi_tape *device, scsireq_t *req, - char *desc, char **msg) +#define HOST_NEXUS_FAIL (0x11) + +#define DRIVER_OK (0x00) +#define DRIVER_BUSY (0x01) +#define DRIVER_SOFT (0x02) +#define DRIVER_MEDIA (0x03) +#define DRIVER_ERROR (0x04) +#define DRIVER_INVALID (0x05) +#define DRIVER_TIMEOUT (0x06) +#define DRIVER_HARD (0x07) +#define DRIVER_SENSE (0x08) + +#define NO_SUGGESTION (0x00) +#define SUGGEST_RETRY (0x10) +#define SUGGEST_ABORT (0x20) +#define SUGGEST_REMAP (0x30) +#define SUGGEST_DIE (0x40) +#define SUGGEST_SENSE (0x80) + +int scsipi_issue_cdb_command(struct scsipi_tape *device, scsireq_t *req, char *desc, char **msg) { int status = 0; int ret = -1; @@ -189,7 +176,7 @@ int scsipi_issue_cdb_command(struct scsipi_tape *device, scsireq_t *req, CHECK_ARG_NULL(req, -LTFS_NULL_ARG); CHECK_ARG_NULL(msg, -LTFS_NULL_ARG); - status = ioctl (device->fd, SCIOCCOMMAND, req); + status = ioctl(device->fd, SCIOCCOMMAND, req); /* * the command requested was not accepted by the driver @@ -204,29 +191,29 @@ int scsipi_issue_cdb_command(struct scsipi_tape *device, scsireq_t *req, assert(status == 0); switch (req->retsts) { - case SCCMD_BUSY: /* Unit didn't respond to selection */ - if (msg) *msg = "Bus stayed busy through timeout period"; - ret = -EDEV_DEVICE_BUSY; - goto out; - break; + case SCCMD_BUSY: /* Unit didn't respond to selection */ + if (msg) *msg = "Bus stayed busy through timeout period"; + ret = -EDEV_DEVICE_BUSY; + goto out; + break; - case SCCMD_TIMEOUT: /* Unit timed out */ - if (msg) *msg = "Timeout on the driver"; - ret = -EDEV_TIMEOUT; - goto out; - break; + case SCCMD_TIMEOUT: /* Unit timed out */ + if (msg) *msg = "Timeout on the driver"; + ret = -EDEV_TIMEOUT; + goto out; + break; - case SCCMD_SENSE: /* FALLTHROUGH */ - case SCCMD_OK: /* Good drive status */ - ret = 0; - break; + case SCCMD_SENSE: /* FALLTHROUGH */ + case SCCMD_OK: /* Good drive status */ + ret = 0; + break; - default: - ltfsmsg(LTFS_INFO, 30244I, req->status, req->retsts); - if (msg) *msg = "Busy on the driver"; - ret = -EDEV_DRIVER_ERROR; - goto out; - break; + default: + ltfsmsg(LTFS_INFO, 30244I, req->status, req->retsts); + if (msg) *msg = "Busy on the driver"; + ret = -EDEV_DRIVER_ERROR; + goto out; + break; } assert(req->retsts == SCCMD_OK || req->retsts == SCCMD_SENSE); @@ -252,7 +239,6 @@ int scsipi_issue_cdb_command(struct scsipi_tape *device, scsireq_t *req, return ret; } - static int _inquiry_low(struct scsipi_tape *device, uint8_t page, unsigned char *buf, size_t size) { int ret = -EDEV_UNKNOWN; @@ -264,26 +250,24 @@ static int _inquiry_low(struct scsipi_tape *device, uint8_t page, unsigned char // Zero out the CDB and the result buffer ret = init_scsireq(&req); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(cdb, 0, sizeof(cdb)); memset(buf, 0, size); /* Build CDB */ cdb[0] = INQUIRY; - if(page) - cdb[1] = 0x01; + if (page) cdb[1] = 0x01; cdb[2] = page; ltfs_u16tobe(cdb + 3, size); /* Build request */ - req.flags = SCCMD_READ; - req.cmdlen = sizeof(cdb); - req.datalen = size; - req.databuf = buf; - memcpy(req.cmd, cdb, sizeof(cdb)); - req.timeout = SGConversion(10); + req.flags = SCCMD_READ; + req.cmdlen = sizeof(cdb); + req.datalen = size; + req.databuf = buf; + memcpy(req.cmd, cdb, sizeof(cdb)); + req.timeout = SGConversion(10); ret = scsipi_issue_cdb_command(device, &req, cmd_desc, &msg); @@ -298,7 +282,7 @@ int scsipi_get_drive_identifier(struct scsipi_tape *device, scsi_device_identifi CHECK_ARG_NULL(id_data, -LTFS_NULL_ARG); ret = _inquiry_low(device, 0, inquiry_buf, MAX_INQ_LEN); - if( ret < 0 ) { + if (ret < 0) { ltfsmsg(LTFS_INFO, 30206I, ret); return ret; } @@ -310,17 +294,17 @@ int scsipi_get_drive_identifier(struct scsipi_tape *device, scsi_device_identifi return -EDEV_DEVICE_UNSUPPORTABLE; } - strncpy(id_data->vendor_id, (char*)(&(inquiry_buf[8])), VENDOR_ID_LENGTH); - strncpy(id_data->product_id, (char*)(&(inquiry_buf[16])), PRODUCT_ID_LENGTH); - strncpy(id_data->product_rev, (char*)(&(inquiry_buf[32])), PRODUCT_REV_LENGTH); + strncpy(id_data->vendor_id, (char *)(&(inquiry_buf[8])), VENDOR_ID_LENGTH); + strncpy(id_data->product_id, (char *)(&(inquiry_buf[16])), PRODUCT_ID_LENGTH); + strncpy(id_data->product_rev, (char *)(&(inquiry_buf[32])), PRODUCT_REV_LENGTH); ret = _inquiry_low(device, 0x80, inquiry_buf, MAX_INQ_LEN); - if( ret < 0 ) { + if (ret < 0) { ltfsmsg(LTFS_INFO, 30206I, ret); return ret; } - strncpy(id_data->unit_serial, (char*)(&(inquiry_buf[4])), inquiry_buf[3]); + strncpy(id_data->unit_serial, (char *)(&(inquiry_buf[4])), inquiry_buf[3]); return 0; } diff --git a/src/tape_drivers/open_factor.c b/src/tape_drivers/open_factor.c index 9610ba42..0e96c257 100644 --- a/src/tape_drivers/open_factor.c +++ b/src/tape_drivers/open_factor.c @@ -48,29 +48,31 @@ */ #ifdef DEBUG -#include -#define ltfsmsg(a, b, c) +# include +# define ltfsmsg(a, b, c) #endif #include #include -#include "libltfs/ltfslogging.h" #include "libltfs/ltfs_locking.h" +#include "libltfs/ltfslogging.h" #include "libltfs/uthash.h" #include "tape_drivers/open_factor.h" -struct openfactor_channel { - int channel; /* ID of the channel */ - int count; /* Open count through this channel */ +struct openfactor_channel +{ + int channel; /* ID of the channel */ + int count; /* Open count through this channel */ UT_hash_handle hh; /* Hash handle */ }; -struct openfactor_host { - int host; /* ID of the host (HBA) */ - int count; /* Open count through this host */ +struct openfactor_host +{ + int host; /* ID of the host (HBA) */ + int count; /* Open count through this host */ struct openfactor_channel *channel; /* Link to the corresponded channel table */ - UT_hash_handle hh; /* Hash handle */ + UT_hash_handle hh; /* Hash handle */ }; static struct openfactor_host *openfactor_table = NULL; /* The open factor table */ @@ -83,13 +85,15 @@ void init_openfactor(void) void destroy_openfactor(void) { - struct openfactor_host *he = NULL, *tmph; /* Pointer to host entry */ + struct openfactor_host *he = NULL, *tmph; /* Pointer to host entry */ struct openfactor_channel *ce = NULL, *tmpc; /* Pointer to channel entry */ - HASH_ITER(hh, openfactor_table, he, tmph) { + HASH_ITER(hh, openfactor_table, he, tmph) + { HASH_DEL(openfactor_table, he); - HASH_ITER(hh, he->channel, ce, tmpc) { + HASH_ITER(hh, he->channel, ce, tmpc) + { HASH_DEL(he->channel, ce); free(ce); } @@ -102,7 +106,7 @@ void destroy_openfactor(void) void increment_openfactor(int host, int channel) { - struct openfactor_host *he = NULL; /* Pointer to host entry */ + struct openfactor_host *he = NULL; /* Pointer to host entry */ struct openfactor_channel *ce = NULL; /* Pointer to channel entry */ ltfs_mutex_lock(&table_lock); @@ -120,7 +124,7 @@ void increment_openfactor(int host, int channel) } ce->channel = channel; - ce->count = 1; + ce->count = 1; HASH_ADD_INT(he->channel, channel, ce); he->count++; @@ -146,11 +150,11 @@ void increment_openfactor(int host, int channel) return; } - he->host = host; - he->count = 1; + he->host = host; + he->count = 1; ce->channel = channel; - ce->count = 1; + ce->count = 1; HASH_ADD_INT(he->channel, channel, ce); HASH_ADD_INT(openfactor_table, host, he); } @@ -160,7 +164,7 @@ void increment_openfactor(int host, int channel) void decrement_openfactor(int host, int channel) { - struct openfactor_host *he = NULL; /* Pointer to host entry */ + struct openfactor_host *he = NULL; /* Pointer to host entry */ struct openfactor_channel *ce = NULL; /* Pointer to channel entry */ ltfs_mutex_lock(&table_lock); @@ -179,7 +183,7 @@ void decrement_openfactor(int host, int channel) int get_openfactor(int host, int channel) { - struct openfactor_host *he = NULL; /* Pointer to host entry */ + struct openfactor_host *he = NULL; /* Pointer to host entry */ struct openfactor_channel *ce = NULL; /* Pointer to channel entry */ int ret = 0; @@ -188,8 +192,7 @@ int get_openfactor(int host, int channel) HASH_FIND_INT(openfactor_table, &host, he); if (he) { HASH_FIND_INT(he->channel, &channel, ce); - if (ce) - ret = ((he->count << 16) | ce->count); + if (ce) ret = ((he->count << 16) | ce->count); } ltfs_mutex_unlock(&table_lock); @@ -226,7 +229,6 @@ int main(int argc, char **argv) increment_openfactor(1, 0); increment_openfactor(1, 0); - for (int i = 0; i < 2; i++) { for (int j = 0; j < 4; j++) { printf("(%d, %d) = %x\n", i, j, get_openfactor(i, j)); diff --git a/src/tape_drivers/osx/iokit/iokit_scsi.c b/src/tape_drivers/osx/iokit/iokit_scsi.c index d806c784..b93709e3 100644 --- a/src/tape_drivers/osx/iokit/iokit_scsi.c +++ b/src/tape_drivers/osx/iokit/iokit_scsi.c @@ -55,19 +55,19 @@ #include -#include #include +#include #include #include -#include #include +#include #include -#include "iokit_service.h" #include "iokit_scsi.h" +#include "iokit_service.h" -#include "libltfs/ltfs_error.h" #include "libltfs/ltfs_endian.h" +#include "libltfs/ltfs_error.h" #include "libltfs/ltfslogging.h" #include "tape_drivers/vendor_compat.h" @@ -80,72 +80,60 @@ struct error_table *vendor_table = NULL; static int iokit_sense2errno(struct iokit_scsi_request *req, uint32_t *s, char **msg) { SCSI_Sense_Data *sense = &req->sense_buffer; - uint32_t sense_value = 0; - int rc = -EDEV_UNKNOWN; + uint32_t sense_value = 0; + int rc = -EDEV_UNKNOWN; - sense_value += (uint32_t) ((sense->SENSE_KEY & kSENSE_KEY_Mask) & 0x0F) << 16; - sense_value += (uint32_t) (sense->ADDITIONAL_SENSE_CODE) << 8; - sense_value += (uint32_t) sense->ADDITIONAL_SENSE_CODE_QUALIFIER; + sense_value += (uint32_t)((sense->SENSE_KEY & kSENSE_KEY_Mask) & 0x0F) << 16; + sense_value += (uint32_t)(sense->ADDITIONAL_SENSE_CODE) << 8; + sense_value += (uint32_t)sense->ADDITIONAL_SENSE_CODE_QUALIFIER; *s = sense_value; rc = _sense2errorcode(sense_value, standard_table, msg, MASK_WITH_SENSE_KEY); /* NOTE: error table must be changed in library edition */ - if (rc == -EDEV_VENDOR_UNIQUE) - rc = _sense2errorcode(sense_value, vendor_table, msg, MASK_WITH_SENSE_KEY); + if (rc == -EDEV_VENDOR_UNIQUE) rc = _sense2errorcode(sense_value, vendor_table, msg, MASK_WITH_SENSE_KEY); - if (rc == -EDEV_UNKNOWN && ((sense_value & 0xFF0000) == 0x040000) ) - rc = -EDEV_HARDWARE_ERROR; + if (rc == -EDEV_UNKNOWN && ((sense_value & 0xFF0000) == 0x040000)) rc = -EDEV_HARDWARE_ERROR; return rc; } -static bool is_expected_error(struct iokit_device *device, uint8_t *cdb, int32_t rc ) +static bool is_expected_error(struct iokit_device *device, uint8_t *cdb, int32_t rc) { - int cmd = (cdb[0]&0xFF); + int cmd = (cdb[0] & 0xFF); uint64_t destination; uint64_t cdb_dest[8]; int i; switch (cmd) { case TEST_UNIT_READY: - if (rc == -EDEV_NEED_INITIALIZE || rc == -EDEV_CONFIGURE_CHANGED) - return true; + if (rc == -EDEV_NEED_INITIALIZE || rc == -EDEV_CONFIGURE_CHANGED) return true; break; case READ: - if (rc == -EDEV_FILEMARK_DETECTED || rc == -EDEV_NO_SENSE || rc == -EDEV_CLEANING_REQUIRED) - return true; - if ((rc == -EDEV_CRYPTO_ERROR || rc == -EDEV_KEY_REQUIRED) && !device->is_data_key_set) - return true; + if (rc == -EDEV_FILEMARK_DETECTED || rc == -EDEV_NO_SENSE || rc == -EDEV_CLEANING_REQUIRED) return true; + if ((rc == -EDEV_CRYPTO_ERROR || rc == -EDEV_KEY_REQUIRED) && !device->is_data_key_set) return true; break; case WRITE: - if (rc == -EDEV_EARLY_WARNING || rc == -EDEV_PROG_EARLY_WARNING || rc == -EDEV_CLEANING_REQUIRED) - return true; + if (rc == -EDEV_EARLY_WARNING || rc == -EDEV_PROG_EARLY_WARNING || rc == -EDEV_CLEANING_REQUIRED) return true; break; case WRITE_FILEMARKS6: - if (rc == -EDEV_EARLY_WARNING || rc == -EDEV_PROG_EARLY_WARNING || rc == -EDEV_CLEANING_REQUIRED) - return true; + if (rc == -EDEV_EARLY_WARNING || rc == -EDEV_PROG_EARLY_WARNING || rc == -EDEV_CLEANING_REQUIRED) return true; break; case LOAD_UNLOAD: - if ((cdb[4] & 0x01) == 0) // Unload - if (rc == -EDEV_CLEANING_REQUIRED) - return true; + if ((cdb[4] & 0x01) == 0) // Unload + if (rc == -EDEV_CLEANING_REQUIRED) return true; break; case MODE_SELECT10: - if (rc == -EDEV_MODE_PARAMETER_ROUNDED) - return true; + if (rc == -EDEV_MODE_PARAMETER_ROUNDED) return true; break; case LOCATE16: - for (i=0; i<8; i++) - cdb_dest[i] = (uint64_t)cdb[i+4] & 0xff; + for (i = 0; i < 8; i++) + cdb_dest[i] = (uint64_t)cdb[i + 4] & 0xff; - destination = (cdb_dest[0] << 56) + (cdb_dest[1] << 48) - + (cdb_dest[2] << 40) + (cdb_dest[3] << 32) - + (cdb_dest[4] << 24) + (cdb_dest[5] << 16) - + (cdb_dest[6] << 8) + cdb_dest[7]; + destination = (cdb_dest[0] << 56) + (cdb_dest[1] << 48) + (cdb_dest[2] << 40) + (cdb_dest[3] << 32) + + (cdb_dest[4] << 24) + (cdb_dest[5] << 16) + (cdb_dest[6] << 8) + cdb_dest[7]; - if (destination == TAPE_BLOCK_MAX && rc == -EDEV_EOD_DETECTED) - return true; + if (destination == TAPE_BLOCK_MAX && rc == -EDEV_EOD_DETECTED) return true; break; } @@ -153,11 +141,10 @@ static bool is_expected_error(struct iokit_device *device, uint8_t *cdb, int32_t } /* Global functions */ -int iokit_issue_cdb_command(struct iokit_device *device, - struct iokit_scsi_request *req, - char **msg) +int iokit_issue_cdb_command(struct iokit_device *device, struct iokit_scsi_request *req, char **msg) { - int ret = -EDEV_INTERNAL_ERROR;; + int ret = -EDEV_INTERNAL_ERROR; + ; //char sense_string[SIZE_OF_SENSE_STRING] = ""; IOReturn kernelReturn = kIOReturnSuccess; @@ -168,14 +155,14 @@ int iokit_issue_cdb_command(struct iokit_device *device, CHECK_ARG_NULL(device->scsiTaskInterface, -LTFS_NULL_ARG); ret = iokit_allocate_scsitask(device); - if(ret != 0) { + if (ret != 0) { return ret; } - if( (req->dxferp) && (req->dxfer_len > 0) ) { + if ((req->dxferp) && (req->dxfer_len > 0)) { // Allocate a virtual range for the buffer. If we had more than 1 scatter-gather entry, // we would allocate more than 1 IOVirtualRange. - range = (IOVirtualRange *) malloc(sizeof(IOVirtualRange)); + range = (IOVirtualRange *)malloc(sizeof(IOVirtualRange)); if (range == NULL) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); ret = -EDEV_NO_MEMORY; @@ -183,12 +170,12 @@ int iokit_issue_cdb_command(struct iokit_device *device, } // Set up the range. The address is just the buffer's address. The length is our request size. - range->address = (IOVirtualAddress) req->dxferp; + range->address = (IOVirtualAddress)req->dxferp; range->length = req->dxfer_len; // Set the scatter-gather entry in the task. - kernelReturn = (*device->task)->SetScatterGatherEntries(device->task, range, 1, - req->dxfer_len, req->dxfer_direction); + kernelReturn = + (*device->task)->SetScatterGatherEntries(device->task, range, 1, req->dxfer_len, req->dxfer_direction); if (kernelReturn != kIOReturnSuccess) { ltfsmsg(LTFS_INFO, 30800I, *req->cmdp, kernelReturn); ret = -EDEV_INTERNAL_ERROR; @@ -212,8 +199,7 @@ int iokit_issue_cdb_command(struct iokit_device *device, goto free; } - kernelReturn = (*device->task)->ExecuteTaskSync(device->task, &req->sense_buffer, - &req->status, &transfer_count); + kernelReturn = (*device->task)->ExecuteTaskSync(device->task, &req->sense_buffer, &req->status, &transfer_count); if (kernelReturn != kIOReturnSuccess) { ltfsmsg(LTFS_INFO, 30803I, *req->cmdp, kernelReturn); ret = -EDEV_INTERNAL_ERROR; @@ -221,7 +207,7 @@ int iokit_issue_cdb_command(struct iokit_device *device, } req->actual_xfered = transfer_count; - req->resid = req->dxfer_len - transfer_count; + req->resid = req->dxfer_len - transfer_count; switch (req->status) { case kSCSITaskStatus_GOOD: @@ -290,29 +276,27 @@ static int _inquiry_low(struct iokit_device *device, uint8_t page, unsigned char /* Build CDB */ cdb[0] = INQUIRY; - if(page) - cdb[1] = 0x01; + if (page) cdb[1] = 0x01; cdb[2] = page; ltfs_u16tobe(cdb + 3, size); /* Build request */ req.dxfer_direction = SCSI_FROM_TARGET_TO_INITIATOR; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.dxfer_len = size; - req.dxferp = buf; - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.dxfer_len = size; + req.dxferp = buf; + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(10); - req.desc = cmd_desc; + req.timeout = IOKitConversion(10); + req.desc = cmd_desc; ret = iokit_issue_cdb_command(device, &req, &msg); return ret; } -int iokit_get_drive_identifier(struct iokit_device *device, - scsi_device_identifier *id_data) +int iokit_get_drive_identifier(struct iokit_device *device, scsi_device_identifier *id_data) { int ret; unsigned char inquiry_buf[MAX_INQ_LEN]; @@ -321,24 +305,24 @@ int iokit_get_drive_identifier(struct iokit_device *device, CHECK_ARG_NULL(id_data, -LTFS_NULL_ARG); ret = _inquiry_low(device, 0, inquiry_buf, MAX_INQ_LEN); - if( ret < 0 ) { + if (ret < 0) { ltfsmsg(LTFS_INFO, 30809I, ret); return ret; } memset(id_data, 0, sizeof(scsi_device_identifier)); - strncpy(id_data->vendor_id, (char*)(&(inquiry_buf[8])), VENDOR_ID_LENGTH); - strncpy(id_data->product_id, (char*)(&(inquiry_buf[16])), PRODUCT_ID_LENGTH); - strncpy(id_data->product_rev, (char*)(&(inquiry_buf[32])), PRODUCT_REV_LENGTH); + strncpy(id_data->vendor_id, (char *)(&(inquiry_buf[8])), VENDOR_ID_LENGTH); + strncpy(id_data->product_id, (char *)(&(inquiry_buf[16])), PRODUCT_ID_LENGTH); + strncpy(id_data->product_rev, (char *)(&(inquiry_buf[32])), PRODUCT_REV_LENGTH); ret = _inquiry_low(device, 0x80, inquiry_buf, MAX_INQ_LEN); - if( ret < 0 ) { + if (ret < 0) { ltfsmsg(LTFS_INFO, 30809I, ret); return ret; } - strncpy(id_data->unit_serial, (char*)(&(inquiry_buf[4])), inquiry_buf[3]); + strncpy(id_data->unit_serial, (char *)(&(inquiry_buf[4])), inquiry_buf[3]); return 0; } diff --git a/src/tape_drivers/osx/iokit/iokit_service.c b/src/tape_drivers/osx/iokit/iokit_service.c index 6967db52..dc0ee6bb 100644 --- a/src/tape_drivers/osx/iokit/iokit_service.c +++ b/src/tape_drivers/osx/iokit/iokit_service.c @@ -53,12 +53,12 @@ #include -#include #include +#include #include #include -#include #include +#include #include #include "iokit_service.h" @@ -82,30 +82,30 @@ static int _get_device_count(CFMutableDictionaryRef *matchingDict) // Search I/O Registry for matching devices kernelResult = IOServiceGetMatchingServices(masterPort, *matchingDict, &serviceIterator); - if( (serviceIterator == IO_OBJECT_NULL) || (IOIteratorNext(serviceIterator) == 0) ) { + if ((serviceIterator == IO_OBJECT_NULL) || (IOIteratorNext(serviceIterator) == 0)) { count = -101; return count; } - if(serviceIterator && kernelResult == kIOReturnSuccess) { + if (serviceIterator && kernelResult == kIOReturnSuccess) { io_service_t scsiDevice = IO_OBJECT_NULL; count = 0; IOIteratorReset(serviceIterator); - if(! IOIteratorIsValid(serviceIterator)) { + if (!IOIteratorIsValid(serviceIterator)) { count = -102; return count; } // Count devices matching service class - while( (scsiDevice = IOIteratorNext(serviceIterator)) ) { + while ((scsiDevice = IOIteratorNext(serviceIterator))) { count++; } IOIteratorReset(serviceIterator); - while( (scsiDevice = IOIteratorNext(serviceIterator)) ) { - kernelResult = IOObjectRelease(scsiDevice); // Done with SCSI object from I/O Registry. + while ((scsiDevice = IOIteratorNext(serviceIterator))) { + kernelResult = IOObjectRelease(scsiDevice); // Done with SCSI object from I/O Registry. } } @@ -130,29 +130,29 @@ static int _find_device(struct iokit_device *device, int device_number, CFMutabl // Search I/O Registry for matching devices kernelResult = IOServiceGetMatchingServices(device->masterPort, *matchingDict, &serviceIterator); - if( (serviceIterator == IO_OBJECT_NULL) || (IOIteratorNext(serviceIterator) == 0) ) { + if ((serviceIterator == IO_OBJECT_NULL) || (IOIteratorNext(serviceIterator) == 0)) { /* TODO: Replace to better logic*/ ret = -101; return ret; } - if(serviceIterator && kernelResult == kIOReturnSuccess) { + if (serviceIterator && kernelResult == kIOReturnSuccess) { io_service_t scsiDevice = IO_OBJECT_NULL; int count = 0; IOIteratorReset(serviceIterator); // Select N'th tape drive based on driveNumber value - while( (scsiDevice = IOIteratorNext(serviceIterator)) ) { - if(count == device_number) { + while ((scsiDevice = IOIteratorNext(serviceIterator))) { + if (count == device_number) { break; } else { - kernelResult = IOObjectRelease(scsiDevice); // Done with SCSI object from I/O Registry. + kernelResult = IOObjectRelease(scsiDevice); // Done with SCSI object from I/O Registry. count++; } } - if(scsiDevice == IO_OBJECT_NULL) { + if (scsiDevice == IO_OBJECT_NULL) { /* TODO: Replace to better logic*/ ret = -1; return ret; @@ -163,16 +163,13 @@ static int _find_device(struct iokit_device *device, int device_number, CFMutabl // Create DeviceInterface and store in lto_osx_data struct. assert(device->ioservice != IO_OBJECT_NULL); - IOCFPlugInInterface **plugin_interface = NULL; - SCSITaskDeviceInterface **task_device_interface = NULL; - HRESULT plugin_query_result = S_OK; + IOCFPlugInInterface **plugin_interface = NULL; + SCSITaskDeviceInterface **task_device_interface = NULL; + HRESULT plugin_query_result = S_OK; SInt32 score = 0; - kernelResult = IOCreatePlugInInterfaceForService(device->ioservice, - kIOSCSITaskDeviceUserClientTypeID, - kIOCFPlugInInterfaceID, - &plugin_interface, - &score); + kernelResult = IOCreatePlugInInterfaceForService( + device->ioservice, kIOSCSITaskDeviceUserClientTypeID, kIOCFPlugInInterfaceID, &plugin_interface, &score); if (kernelResult != kIOReturnSuccess) { /* TODO: Replace to better logic*/ ret = -1; @@ -180,9 +177,10 @@ static int _find_device(struct iokit_device *device, int device_number, CFMutabl } else { // Query the base plugin interface for an instance of the specific SCSI device interface // object. - plugin_query_result = (*plugin_interface)->QueryInterface(plugin_interface, - CFUUIDGetUUIDBytes(kIOSCSITaskDeviceInterfaceID), - (LPVOID *) &task_device_interface); + plugin_query_result = (*plugin_interface) + ->QueryInterface(plugin_interface, + CFUUIDGetUUIDBytes(kIOSCSITaskDeviceInterfaceID), + (LPVOID *)&task_device_interface); if (plugin_query_result != S_OK) { /* TODO: Replace to better logic*/ @@ -201,34 +199,33 @@ static int _find_device(struct iokit_device *device, int device_number, CFMutabl return ret; } - static void _create_matching_dictionary_for_device_class(CFMutableDictionaryRef *matchingDict, - SInt32 peripheralDeviceType ) + SInt32 peripheralDeviceType) { CFMutableDictionaryRef subDictionary; assert(matchingDict != NULL); // Create the matching dictionaries... - *matchingDict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, - &kCFTypeDictionaryValueCallBacks); - if(*matchingDict != NULL) { + *matchingDict = CFDictionaryCreateMutable( + kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); + if (*matchingDict != NULL) { // Create a sub-dictionary to hold the required device patterns. - subDictionary = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, - &kCFTypeDictionaryValueCallBacks); + subDictionary = CFDictionaryCreateMutable( + kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); if (subDictionary != NULL) { // Set the "SCSITaskDeviceCategory" key so that we match // devices that understand SCSI commands. - CFDictionarySetValue(subDictionary, CFSTR(kIOPropertySCSITaskDeviceCategory), - CFSTR(kIOPropertySCSITaskUserClientDevice)); + CFDictionarySetValue( + subDictionary, CFSTR(kIOPropertySCSITaskDeviceCategory), CFSTR(kIOPropertySCSITaskUserClientDevice)); // Set the "PeripheralDeviceType" key so that we match // sequential storage (tape) devices. SInt32 deviceTypeNumber = peripheralDeviceType; CFNumberRef deviceTypeRef = NULL; deviceTypeRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &deviceTypeNumber); CFDictionarySetValue(subDictionary, CFSTR(kIOPropertySCSIPeripheralDeviceType), deviceTypeRef); - CFRelease (deviceTypeRef); + CFRelease(deviceTypeRef); } // Add the sub-dictionary pattern to the main dictionary with the key "IOPropertyMatch" to @@ -239,13 +236,11 @@ static void _create_matching_dictionary_for_device_class(CFMutableDictionaryRef } } - static void _create_matching_dictionary_for_ssc(CFMutableDictionaryRef *matchingDict) { _create_matching_dictionary_for_device_class(matchingDict, kINQUIRY_PERIPHERAL_TYPE_SequentialAccessSSCDevice); } - static void _create_matching_dictionary_for_smc(CFMutableDictionaryRef *matchingDict) { _create_matching_dictionary_for_device_class(matchingDict, kINQUIRY_PERIPHERAL_TYPE_MediumChangerSMCDevice); @@ -253,10 +248,9 @@ static void _create_matching_dictionary_for_smc(CFMutableDictionaryRef *matching static void _release_scsitask(struct iokit_device *device) { - if(device != NULL) { + if (device != NULL) { // Release IOKit task interface - if(device->scsiTaskInterface != NULL) - (*device->scsiTaskInterface)->Release(device->scsiTaskInterface); + if (device->scsiTaskInterface != NULL) (*device->scsiTaskInterface)->Release(device->scsiTaskInterface); } } @@ -309,12 +303,12 @@ int iokit_release_exclusive_access(struct iokit_device *device) int iokit_allocate_scsitask(struct iokit_device *device) { - if(device == NULL) { + if (device == NULL) { /* TODO: Replace to better logic */ return -100; } - if(device->task == NULL) { + if (device->task == NULL) { // Create a SCSI task for the device. This task will be re-used for all future SCSI operations. device->task = (*device->scsiTaskInterface)->CreateSCSITask(device->scsiTaskInterface); @@ -329,10 +323,9 @@ int iokit_allocate_scsitask(struct iokit_device *device) void iokit_release_scsitask(struct iokit_device *device) { - if(device != NULL) { + if (device != NULL) { // Release IOKit task interface - if(device->scsiTaskInterface != NULL) - (*device->scsiTaskInterface)->Release(device->scsiTaskInterface); + if (device->scsiTaskInterface != NULL) (*device->scsiTaskInterface)->Release(device->scsiTaskInterface); } } @@ -347,7 +340,6 @@ int iokit_get_ssc_device_count(void) return count; } - int iokit_get_smc_device_count(void) { int count = -1; @@ -359,7 +351,6 @@ int iokit_get_smc_device_count(void) return count; } - int iokit_find_ssc_device(struct iokit_device *device, int drive_number) { int ret = -1; @@ -370,7 +361,6 @@ int iokit_find_ssc_device(struct iokit_device *device, int drive_number) return ret; } - int iokit_find_smc_device(struct iokit_device *device, int changer_number) { int ret = -1; @@ -381,28 +371,26 @@ int iokit_find_smc_device(struct iokit_device *device, int changer_number) return ret; } - int iokit_free_device(struct iokit_device *device) { int ret = 0; kern_return_t kernelResult; - if(device == NULL) - return ret; + if (device == NULL) return ret; _release_scsitask(device); // Release PlugInInterface - if(device->plugInInterface != NULL) { + if (device->plugInInterface != NULL) { kernelResult = IODestroyPlugInInterface(device->plugInInterface); - if(kernelResult != kIOReturnSuccess) { + if (kernelResult != kIOReturnSuccess) { ret = -100; } } // Release SCSI object from I/O Registry. kernelResult = IOObjectRelease(device->ioservice); - if(kernelResult != kIOReturnSuccess) { + if (kernelResult != kIOReturnSuccess) { ret = -101; } diff --git a/src/tape_drivers/osx/iokit/iokit_tape.c b/src/tape_drivers/osx/iokit/iokit_tape.c index 76f14628..19b984a5 100644 --- a/src/tape_drivers/osx/iokit/iokit_tape.c +++ b/src/tape_drivers/osx/iokit/iokit_tape.c @@ -56,24 +56,24 @@ #include #include -#include "ltfs_copyright.h" -#include "libltfs/ltfslogging.h" +#include "kmi/key_format_ltfs.h" +#include "libltfs/arch/time_internal.h" #include "libltfs/fs.h" #include "libltfs/ltfs_endian.h" -#include "libltfs/arch/time_internal.h" -#include "kmi/key_format_ltfs.h" +#include "libltfs/ltfslogging.h" +#include "ltfs_copyright.h" /* Common header of backend */ -#include "reed_solomon_crc.h" #include "crc32c_crc.h" +#include "reed_solomon_crc.h" #include "vendor_compat.h" /* iokit functions */ #ifdef VERSION -#undef VERSION // Undef VERSION because it is conflicted into the header in IOKit +# undef VERSION // Undef VERSION because it is conflicted into the header in IOKit #endif -#include "iokit_service.h" #include "iokit_scsi.h" +#include "iokit_service.h" /* Definitions of this backend*/ #include "iokit_tape.h" @@ -81,8 +81,8 @@ #include "libltfs/ltfs_fuse_version.h" #include -volatile char *copyright = LTFS_COPYRIGHT_0"\n"LTFS_COPYRIGHT_1"\n"LTFS_COPYRIGHT_2"\n" \ - LTFS_COPYRIGHT_3"\n"LTFS_COPYRIGHT_4"\n"LTFS_COPYRIGHT_5"\n"; +volatile char *copyright = LTFS_COPYRIGHT_0 "\n" LTFS_COPYRIGHT_1 "\n" LTFS_COPYRIGHT_2 "\n" LTFS_COPYRIGHT_3 + "\n" LTFS_COPYRIGHT_4 "\n" LTFS_COPYRIGHT_5 "\n"; // Default device name const char *default_device = "0"; @@ -91,30 +91,32 @@ const char *default_device = "0"; struct iokit_global_data global_data; // Definitions -#define LOG_PAGE_HEADER_SIZE (4) +#define LOG_PAGE_HEADER_SIZE (4) #define LOG_PAGE_PARAMSIZE_OFFSET (3) -#define LOG_PAGE_PARAM_OFFSET (4) +#define LOG_PAGE_PARAM_OFFSET (4) #define IOKIT_MAX_BLOCK_SIZE (1 * MB) #ifndef MIN -#define MIN(a, b) ((a) < (b) ? (a) : (b)) +# define MIN(a, b) ((a) < (b) ? (a) : (b)) #endif /* Forward references (For keep function order to struct tape_ops) */ int iokit_readpos(void *device, struct tc_position *pos); int iokit_locate(void *device, struct tc_position dest, struct tc_position *pos); -int iokit_logsense(void *device, const uint8_t page, const uint8_t subpage, - unsigned char *buf, const size_t size); -int iokit_modesense(void *device, const unsigned char page, const TC_MP_PC_TYPE pc, - const unsigned char subpage, unsigned char *buf, const size_t size); +int iokit_logsense(void *device, const uint8_t page, const uint8_t subpage, unsigned char *buf, const size_t size); +int iokit_modesense(void *device, + const unsigned char page, + const TC_MP_PC_TYPE pc, + const unsigned char subpage, + unsigned char *buf, + const size_t size); int iokit_modeselect(void *device, unsigned char *buf, const size_t size); static const char *_generate_product_name(const char *product_id); /* Local functions */ -static inline int _parse_logPage(const unsigned char *logdata, - const uint16_t param, uint32_t *param_size, - unsigned char *buf, const size_t bufsize) +static inline int _parse_logPage( + const unsigned char *logdata, const uint16_t param, uint32_t *param_size, unsigned char *buf, const size_t bufsize) { uint16_t page_len, param_code, param_len; uint32_t i; @@ -123,15 +125,13 @@ static inline int _parse_logPage(const unsigned char *logdata, page_len = ((uint16_t)logdata[2] << 8) + (uint16_t)logdata[3]; i = LOG_PAGE_HEADER_SIZE; - while(i < page_len) - { - param_code = ((uint16_t)logdata[i] << 8) + (uint16_t)logdata[i+1]; - param_len = (uint16_t)logdata[i + LOG_PAGE_PARAMSIZE_OFFSET]; + while (i < page_len) { + param_code = ((uint16_t)logdata[i] << 8) + (uint16_t)logdata[i + 1]; + param_len = (uint16_t)logdata[i + LOG_PAGE_PARAMSIZE_OFFSET]; - if(param_code == param) - { + if (param_code == param) { *param_size = param_len; - if(bufsize < param_len){ + if (bufsize < param_len) { memcpy(buf, &logdata[i + LOG_PAGE_PARAM_OFFSET], bufsize); ret = -EDEV_INTERNAL_ERROR; break; @@ -155,16 +155,12 @@ static inline int _parse_logPage(const unsigned char *logdata, * @return a pointer to the iokit backend on success or NULL on error */ -#define iokit_opt(templ,offset,value) \ - { templ, offsetof(struct iokit_global_data, offset), value } +#define iokit_opt(templ, offset, value) { templ, offsetof(struct iokit_global_data, offset), value } static struct fuse_opt iokit_global_opts[] = { - iokit_opt("scsi_lbprotect=%s", str_crc_checking, 0), - iokit_opt("strict_drive", strict_drive, 1), - iokit_opt("nostrict_drive", strict_drive, 0), - iokit_opt("autodump", disable_auto_dump, 0), - iokit_opt("noautodump", disable_auto_dump, 1), - FUSE_OPT_END + iokit_opt("scsi_lbprotect=%s", str_crc_checking, 0), iokit_opt("strict_drive", strict_drive, 1), + iokit_opt("nostrict_drive", strict_drive, 0), iokit_opt("autodump", disable_auto_dump, 0), + iokit_opt("noautodump", disable_auto_dump, 1), FUSE_OPT_END }; static int null_parser(void *priv, const char *arg, int key, struct fuse_args *outargs) @@ -172,17 +168,17 @@ static int null_parser(void *priv, const char *arg, int key, struct fuse_args *o return 1; } -#define LBP_DISABLE (0x00) -#define REED_SOLOMON_CRC (0x01) -#define CRC32C_CRC (0x02) +#define LBP_DISABLE (0x00) +#define REED_SOLOMON_CRC (0x01) +#define CRC32C_CRC (0x02) -#define TC_MP_INIT_EXT_LBP_RS (0x40) -#define TC_MP_INIT_EXT_LBP_CRC32C (0x20) +#define TC_MP_INIT_EXT_LBP_RS (0x40) +#define TC_MP_INIT_EXT_LBP_CRC32C (0x20) static int _set_lbp(void *device, bool enable) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; unsigned char buf[TC_MP_SUB_DP_CTRL_SIZE]; unsigned char buf_ext[TC_MP_INIT_EXT_SIZE]; @@ -191,8 +187,7 @@ static int _set_lbp(void *device, bool enable) /* Check logical block protection capability */ if (IS_ENTERPRISE(priv->drive_type)) { ret = iokit_modesense(device, TC_MP_INIT_EXT, TC_MP_PC_CURRENT, 0x00, buf_ext, sizeof(buf_ext)); - if (ret < 0) - return ret; + if (ret < 0) return ret; if (buf_ext[0x12] & TC_MP_INIT_EXT_LBP_CRC32C) lbp_method = CRC32C_CRC; @@ -212,13 +207,11 @@ static int _set_lbp(void *device, bool enable) /* set logical block protection */ ltfsmsg(LTFS_DEBUG, 30993D, "LBP Enable", enable, ""); ltfsmsg(LTFS_DEBUG, 30993D, "LBP Method", lbp_method, ""); - ret = iokit_modesense(device, TC_MP_CTRL, TC_MP_PC_CURRENT, - TC_MP_SUB_DP_CTRL, buf, sizeof(buf)); - if (ret < 0) - return ret; + ret = iokit_modesense(device, TC_MP_CTRL, TC_MP_PC_CURRENT, TC_MP_SUB_DP_CTRL, buf, sizeof(buf)); + if (ret < 0) return ret; - buf[0] = 0x00; - buf[1] = 0x00; + buf[0] = 0x00; + buf[1] = 0x00; if (enable) { buf[20] = lbp_method; buf[21] = 0x04; @@ -243,13 +236,13 @@ static int _set_lbp(void *device, bool enable) priv->f_crc_check = rs_gf256_check; break; default: - priv->f_crc_enc = NULL; + priv->f_crc_enc = NULL; priv->f_crc_check = NULL; break; } ltfsmsg(LTFS_INFO, 30853I); } else { - priv->f_crc_enc = NULL; + priv->f_crc_enc = NULL; priv->f_crc_check = NULL; ltfsmsg(LTFS_INFO, 30854I); } @@ -272,7 +265,7 @@ static bool is_dump_required(struct iokit_data *priv, int ret, bool *capture_unf return ans; } -#define DUMP_HEADER_SIZE (4) +#define DUMP_HEADER_SIZE (4) #define DUMP_TRANSFER_SIZE (512 * KB) static int _cdb_read_buffer(void *device, int id, unsigned char *buf, size_t offset, size_t len, int type); @@ -282,20 +275,20 @@ static int _get_dump(struct iokit_data *priv, char *fname) { int ret = 0; - long long data_length, buf_offset; - int dumpfd = -1; - int transfer_size, num_transfers, excess_transfer; - int i, bytes; - unsigned char cap_buf[DUMP_HEADER_SIZE]; - unsigned char *dump_buf; - int buf_id; + long long data_length, buf_offset; + int dumpfd = -1; + int transfer_size, num_transfers, excess_transfer; + int i, bytes; + unsigned char cap_buf[DUMP_HEADER_SIZE]; + unsigned char *dump_buf; + int buf_id; ltfsmsg(LTFS_INFO, 30855I, fname); /* Set transfer size */ transfer_size = DUMP_TRANSFER_SIZE; dump_buf = calloc(1, DUMP_TRANSFER_SIZE); - if(!dump_buf){ + if (!dump_buf) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -EDEV_NO_MEMORY; } @@ -312,18 +305,17 @@ static int _get_dump(struct iokit_data *priv, char *fname) data_length = (cap_buf[1] << 16) + (cap_buf[2] << 8) + (int)cap_buf[3]; /* Open dump file for write only*/ - dumpfd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666); - if(dumpfd < 0){ + dumpfd = open(fname, O_WRONLY | O_CREAT | O_TRUNC, 0666); + if (dumpfd < 0) { ltfsmsg(LTFS_WARN, 30856W, errno); free(dump_buf); return -2; } /* get the total number of transfers */ - num_transfers = data_length / transfer_size; + num_transfers = data_length / transfer_size; excess_transfer = data_length % transfer_size; - if(excess_transfer) - num_transfers += 1; + if (excess_transfer) num_transfers += 1; /* Total dump data length is %lld. Total number of transfers is %d. */ ltfsmsg(LTFS_DEBUG, 30857D, data_length); @@ -333,14 +325,13 @@ static int _get_dump(struct iokit_data *priv, char *fname) buf_offset = 0; i = 0; ltfsmsg(LTFS_DEBUG, 30859D); - while(num_transfers) - { + while (num_transfers) { int length; i++; /* Allocation Length is transfer_size or excess_transfer*/ - if(excess_transfer && num_transfers == 1) + if (excess_transfer && num_transfers == 1) length = excess_transfer; else length = transfer_size; @@ -355,16 +346,14 @@ static int _get_dump(struct iokit_data *priv, char *fname) /* write buffer data into dump file */ bytes = write(dumpfd, dump_buf, length); - if(bytes == -1) - { + if (bytes == -1) { ltfsmsg(LTFS_WARN, 30861W, ret); free(dump_buf); close(dumpfd); return -1; } - if(bytes != length) - { + if (bytes != length) { ltfsmsg(LTFS_WARN, 30862W, bytes, length); free(dump_buf); close(dumpfd); @@ -385,13 +374,12 @@ static int _get_dump(struct iokit_data *priv, char *fname) static int _take_dump(struct iokit_data *priv, bool capture_unforced) { - char fname_base[1024]; - char fname[1024]; - time_t now; + char fname_base[1024]; + char fname[1024]; + time_t now; struct tm *tm_now; - if (priv->vendor != VENDOR_IBM) - return 0; + if (priv->vendor != VENDOR_IBM) return 0; /* Following logic is for IBM tape drives */ @@ -400,14 +388,15 @@ static int _take_dump(struct iokit_data *priv, bool capture_unforced) /* Make base filename */ time(&now); tm_now = localtime(&now); - sprintf(fname_base, "/tmp/ltfs_%s_%d_%02d%02d_%02d%02d%02d" - , priv->drive_serial - , tm_now->tm_year+1900 - , tm_now->tm_mon+1 - , tm_now->tm_mday - , tm_now->tm_hour - , tm_now->tm_min - , tm_now->tm_sec); + sprintf(fname_base, + "/tmp/ltfs_%s_%d_%02d%02d_%02d%02d%02d", + priv->drive_serial, + tm_now->tm_year + 1900, + tm_now->tm_mon + 1, + tm_now->tm_mday, + tm_now->tm_hour, + tm_now->tm_min, + tm_now->tm_sec); if (capture_unforced) { ltfsmsg(LTFS_INFO, 30863I); @@ -438,8 +427,7 @@ static void _process_errors(struct iokit_data *priv, int ret, char *msg, char *c } if (priv) { - if (take_dump && !global_data.disable_auto_dump - && is_dump_required(priv, ret, &unforced_dump)) { + if (take_dump && !global_data.disable_auto_dump && is_dump_required(priv, ret, &unforced_dump)) { (void)_take_dump(priv, unforced_dump); } } @@ -448,7 +436,7 @@ static void _process_errors(struct iokit_data *priv, int ret, char *msg, char *c static int _cdb_read_buffer(void *device, int id, unsigned char *buf, size_t offset, size_t len, int type) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; struct iokit_scsi_request req; unsigned char cdb[CDB10_LEN]; @@ -467,29 +455,28 @@ static int _cdb_read_buffer(void *device, int id, unsigned char *buf, size_t off cdb[1] = type; cdb[2] = id; cdb[3] = (unsigned char)(offset >> 16) & 0xFF; - cdb[4] = (unsigned char)(offset >> 8) & 0xFF; - cdb[5] = (unsigned char) offset & 0xFF; - cdb[6] = (unsigned char)(len >> 16) & 0xFF; - cdb[7] = (unsigned char)(len >> 8) & 0xFF; - cdb[8] = (unsigned char) len & 0xFF; + cdb[4] = (unsigned char)(offset >> 8) & 0xFF; + cdb[5] = (unsigned char)offset & 0xFF; + cdb[6] = (unsigned char)(len >> 16) & 0xFF; + cdb[7] = (unsigned char)(len >> 8) & 0xFF; + cdb[8] = (unsigned char)len & 0xFF; timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_TARGET_TO_INITIATOR; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.dxfer_len = len; - req.dxferp = buf; - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.dxfer_len = len; + req.dxferp = buf; + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(timeout); - req.desc = cmd_desc; + req.timeout = IOKitConversion(timeout); + req.desc = cmd_desc; ret = iokit_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { _process_errors(device, ret, msg, cmd_desc, true); } @@ -528,22 +515,21 @@ static int _cdb_force_dump(struct iokit_data *priv) buf[5] = 0x60; /* Diag ID */ timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_INITIATOR_TO_TARGET; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.dxfer_len = SENDDIAG_BUF_LEN; - req.dxferp = buf; - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.dxfer_len = SENDDIAG_BUF_LEN; + req.dxferp = buf; + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(timeout); - req.desc = cmd_desc; + req.timeout = IOKitConversion(timeout); + req.desc = cmd_desc; ret = iokit_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { _process_errors(priv, ret, msg, cmd_desc, true); } @@ -553,7 +539,7 @@ static int _cdb_force_dump(struct iokit_data *priv) static int _cdb_pri(void *device, unsigned char *buf, int size) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; struct iokit_scsi_request req; unsigned char cdb[CDB10_LEN]; @@ -568,26 +554,25 @@ static int _cdb_pri(void *device, unsigned char *buf, int size) cdb[0] = PERSISTENT_RESERVE_IN; cdb[1] = 0x03; /* Full Info */ cdb[6] = (unsigned char)(size >> 16) & 0xFF; - cdb[7] = (unsigned char)(size >> 8) & 0xFF; - cdb[8] = (unsigned char) size & 0xFF; + cdb[7] = (unsigned char)(size >> 8) & 0xFF; + cdb[8] = (unsigned char)size & 0xFF; timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_TARGET_TO_INITIATOR; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.dxfer_len = size; - req.dxferp = buf; - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.dxfer_len = size; + req.dxferp = buf; + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(timeout); - req.desc = cmd_desc; + req.timeout = IOKitConversion(timeout); + req.desc = cmd_desc; ret = iokit_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { _process_errors(device, ret, msg, cmd_desc, true); } @@ -633,7 +618,6 @@ static int _fetch_reservation_key(void *device, struct reservation_info *r) addlen = ltfs_betou32(cur + 20); offset += (PRI_FULL_LEN_BASE + addlen); } - } /* Print holder information here */ @@ -648,12 +632,10 @@ static int _fetch_reservation_key(void *device, struct reservation_info *r) return ret; } -static int _cdb_pro(void *device, - enum pro_action action, enum pro_type type, - unsigned char *key, unsigned char *sakey) +static int _cdb_pro(void *device, enum pro_action action, enum pro_type type, unsigned char *key, unsigned char *sakey) { int ret = -EDEV_UNKNOWN, f_ret; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; struct iokit_scsi_request req; unsigned char cdb[CDB10_LEN]; @@ -674,39 +656,43 @@ static int _cdb_pro(void *device, cdb[8] = PRO_BUF_LEN; /* parameter length */ /* Build parameter list, clear key when key is NULL */ - if (key) - memcpy(buf, key, KEYLEN); + if (key) memcpy(buf, key, KEYLEN); - if (sakey) - memcpy(buf + 8, sakey, KEYLEN); + if (sakey) memcpy(buf + 8, sakey, KEYLEN); timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_INITIATOR_TO_TARGET; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.dxfer_len = PRO_BUF_LEN; - req.dxferp = buf; - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.dxfer_len = PRO_BUF_LEN; + req.dxferp = buf; + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(timeout); - req.desc = cmd_desc; + req.timeout = IOKitConversion(timeout); + req.desc = cmd_desc; ret = iokit_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { if (ret == -EDEV_RESERVATION_CONFLICT && action == PRO_ACT_RESERVE) { /* Read reservation information and print */ memset(&r_info, 0x00, sizeof(r_info)); f_ret = _fetch_reservation_key(device, &r_info); if (!f_ret) { ltfsmsg(LTFS_WARN, 30869W, r_info.hint, priv->drive_serial); - ltfsmsg(LTFS_WARN, 30867W, - r_info.wwid[0], r_info.wwid[1], r_info.wwid[2], r_info.wwid[3], - r_info.wwid[6], r_info.wwid[5], r_info.wwid[6], r_info.wwid[7], - priv->drive_serial); + ltfsmsg(LTFS_WARN, + 30867W, + r_info.wwid[0], + r_info.wwid[1], + r_info.wwid[2], + r_info.wwid[3], + r_info.wwid[6], + r_info.wwid[5], + r_info.wwid[6], + r_info.wwid[7], + priv->drive_serial); } else { ltfsmsg(LTFS_WARN, 30869W, "unknown host (reserve command)", priv->drive_serial); } @@ -723,12 +709,9 @@ static int _register_key(void *device, unsigned char *key) int ret = -EDEV_UNKNOWN; start: - ret = _cdb_pro(device, PRO_ACT_REGISTER_IGNORE, PRO_TYPE_NONE, - NULL, key); + ret = _cdb_pro(device, PRO_ACT_REGISTER_IGNORE, PRO_TYPE_NONE, NULL, key); - if (ret == -EDEV_RESERVATION_PREEMPTED || - ret == -EDEV_RESERVATION_RELEASED || - ret == -EDEV_REGISTRATION_PREEMPTED ) + if (ret == -EDEV_RESERVATION_PREEMPTED || ret == -EDEV_RESERVATION_RELEASED || ret == -EDEV_REGISTRATION_PREEMPTED) goto start; return ret; @@ -736,10 +719,10 @@ static int _register_key(void *device, unsigned char *key) /** SCSI command handling of REPORT SUPPORTED OPERATION CODES */ -static int _cdb_rsoc(void* device, unsigned char *buf, uint32_t len) +static int _cdb_rsoc(void *device, unsigned char *buf, uint32_t len) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; struct iokit_scsi_request req; unsigned char cdb[CDB12_LEN]; @@ -756,23 +739,23 @@ static int _cdb_rsoc(void* device, unsigned char *buf, uint32_t len) /* Build CDB */ cdb[0] = MAINTENANCE_IN; - cdb[1] = 0x0C; /* REPORT SUPPORTED OPERATION CODES */ - cdb[2] = 0x80; /* Fetch all commands with RCTD */ + cdb[1] = 0x0C; /* REPORT SUPPORTED OPERATION CODES */ + cdb[2] = 0x80; /* Fetch all commands with RCTD */ ltfs_u32tobe(cdb + 6, len); /* allocation length */ /* Build request */ req.dxfer_direction = SCSI_FROM_TARGET_TO_INITIATOR; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.dxfer_len = len; - req.dxferp = buf; - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.dxfer_len = len; + req.dxferp = buf; + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(timeout); - req.desc = cmd_desc; + req.timeout = IOKitConversion(timeout); + req.desc = cmd_desc; ret = iokit_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { _process_errors(device, ret, msg, cmd_desc, true); } @@ -782,9 +765,9 @@ static int _cdb_rsoc(void* device, unsigned char *buf, uint32_t len) /* Global functions */ int iokit_open(const char *devname, void **handle) { - char *end; - int drive_type = DRIVE_UNSUPPORTED; - int ret = -1, count = 0, i; + char *end; + int drive_type = DRIVE_UNSUPPORTED; + int ret = -1, count = 0, i; int32_t drive_number; struct iokit_data *priv; @@ -796,7 +779,7 @@ int iokit_open(const char *devname, void **handle) ltfsmsg(LTFS_INFO, 30810I, devname); priv = calloc(1, sizeof(struct iokit_data)); - if(!priv) { + if (!priv) { ltfsmsg(LTFS_ERR, 10001E, "iokit_open: private data"); return -EDEV_NO_MEMORY; } @@ -812,13 +795,13 @@ int iokit_open(const char *devname, void **handle) errno = 0; drive_number = strtoul(devname, &end, 10); - if(errno || (*end != '\0') || drive_number > 256) { + if (errno || (*end != '\0') || drive_number > 256) { /* Find the drive by serial number */ bool found = false; count = iokit_get_ssc_device_count(); for (i = 0; i < count; i++) { ret = iokit_find_ssc_device(&priv->dev, i); - if(!ret) { + if (!ret) { ret = iokit_get_drive_identifier(&priv->dev, &id_data); if (!ret) { if (!strncmp(devname, id_data.unit_serial, strlen(devname))) { @@ -838,7 +821,7 @@ int iokit_open(const char *devname, void **handle) } } else { ret = iokit_find_ssc_device(&priv->dev, drive_number); - if(ret < 0) { + if (ret < 0) { ret = -EDEV_DEVICE_UNOPENABLE; goto free; } @@ -846,11 +829,10 @@ int iokit_open(const char *devname, void **handle) } ret = iokit_obtain_exclusive_access(&priv->dev); - if(ret < 0) - goto free; + if (ret < 0) goto free; ret = iokit_get_drive_identifier(&priv->dev, &id_data); - if(ret < 0) { + if (ret < 0) { ltfsmsg(LTFS_INFO, 30812I, devname); goto free; } @@ -861,17 +843,17 @@ int iokit_open(const char *devname, void **handle) /* Check the drive is supportable */ struct supported_device **cur = get_supported_devs(priv->vendor); - while(cur && *cur) { - if((! strncmp(id_data.vendor_id, (*cur)->vendor_id, strlen((*cur)->vendor_id)) ) && - (! strncmp(id_data.product_id, (*cur)->product_id, strlen((*cur)->product_id)) ) ) { + while (cur && *cur) { + if ((!strncmp(id_data.vendor_id, (*cur)->vendor_id, strlen((*cur)->vendor_id))) && + (!strncmp(id_data.product_id, (*cur)->product_id, strlen((*cur)->product_id)))) { drive_type = (*cur)->drive_type; break; } cur++; } - if(drive_type > 0) { - if (!drive_has_supported_fw(priv->vendor, drive_type, (unsigned char*)id_data.product_rev)) { + if (drive_type > 0) { + if (!drive_has_supported_fw(priv->vendor, drive_type, (unsigned char *)id_data.product_rev)) { iokit_release_exclusive_access(&priv->dev); ret = -EDEV_UNSUPPORTED_FIRMWARE; goto free; @@ -896,10 +878,10 @@ int iokit_open(const char *devname, void **handle) snprintf(priv->info.serial_number, TAPE_SERIAL_LEN_MAX + 1, "%s", priv->drive_serial); snprintf(priv->info.product_rev, PRODUCT_REV_LENGTH + 1, "%s", id_data.product_rev); snprintf(priv->info.product_name, PRODUCT_NAME_LENGTH + 1, "%s", _generate_product_name(id_data.product_id)); - priv->info.host = 0; + priv->info.host = 0; priv->info.channel = 0; - priv->info.target = 0; - priv->info.lun = -1; + priv->info.target = 0; + priv->info.lun = -1; /* Setup error table sense to ltfs error code */ init_error_table(priv->vendor, &standard_table, &vendor_table); @@ -945,9 +927,9 @@ int iokit_open(const char *devname, void **handle) _register_key(priv, priv->key); /* Initial setting of force perm */ - priv->clear_by_pc = false; + priv->clear_by_pc = false; priv->force_writeperm = DEFAULT_WRITEPERM; - priv->force_readperm = DEFAULT_READPERM; + priv->force_readperm = DEFAULT_READPERM; priv->force_errortype = DEFAULT_ERRORTYPE; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_OPEN)); @@ -957,8 +939,7 @@ int iokit_open(const char *devname, void **handle) return ret; free: - if (priv->devname) - free(priv->devname); + if (priv->devname) free(priv->devname); free(priv); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_OPEN)); return ret; @@ -966,12 +947,12 @@ int iokit_open(const char *devname, void **handle) int iokit_reopen(const char *devname, void *device) { - int drive_type = DRIVE_UNSUPPORTED; - int ret = -EDEV_UNKNOWN; + int drive_type = DRIVE_UNSUPPORTED; + int ret = -EDEV_UNKNOWN; CHECK_ARG_NULL(device, -LTFS_NULL_ARG); - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; scsi_device_identifier id_data; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_REOPEN)); @@ -979,20 +960,20 @@ int iokit_reopen(const char *devname, void *device) ltfsmsg(LTFS_INFO, 30818I, devname); ret = iokit_find_ssc_device(&priv->dev, priv->drive_number); - if(ret < 0){ + if (ret < 0) { ret = -EDEV_DEVICE_UNOPENABLE; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_REOPEN)); return ret; } ret = iokit_obtain_exclusive_access(&priv->dev); - if(ret < 0) { + if (ret < 0) { ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_REOPEN)); return ret; } ret = iokit_get_drive_identifier(&priv->dev, &id_data); - if(ret < 0) { + if (ret < 0) { ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_REOPEN)); return ret; } @@ -1000,17 +981,17 @@ int iokit_reopen(const char *devname, void *device) /* Check the drive is supportable */ struct supported_device **cur = ibm_supported_drives; - while(*cur) { - if((! strncmp(id_data.vendor_id, (*cur)->vendor_id, strlen((*cur)->vendor_id)) ) && - (! strncmp(id_data.product_id, (*cur)->product_id, strlen((*cur)->product_id)) ) ) { + while (*cur) { + if ((!strncmp(id_data.vendor_id, (*cur)->vendor_id, strlen((*cur)->vendor_id))) && + (!strncmp(id_data.product_id, (*cur)->product_id, strlen((*cur)->product_id)))) { drive_type = (*cur)->drive_type; break; } cur++; } - if(drive_type > 0) { - if (!ibm_tape_is_supported_firmware(drive_type, (unsigned char*)id_data.product_rev)) { + if (drive_type > 0) { + if (!ibm_tape_is_supported_firmware(drive_type, (unsigned char *)id_data.product_rev)) { iokit_release_exclusive_access(&priv->dev); ret = -EDEV_UNSUPPORTED_FIRMWARE; } else @@ -1028,15 +1009,14 @@ int iokit_reopen(const char *devname, void *device) int iokit_close(void *device) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_CLOSE)); _set_lbp(device, false); _register_key(device, NULL); - if(priv->dev.exclusive_lock) - ret = iokit_release_exclusive_access(&priv->dev); + if (priv->dev.exclusive_lock) ret = iokit_release_exclusive_access(&priv->dev); ret = iokit_free_device(&priv->dev); @@ -1049,8 +1029,7 @@ int iokit_close(void *device) priv->profiler = NULL; } - if (priv->devname) - free(priv->devname); + if (priv->devname) free(priv->devname); free(device); @@ -1060,7 +1039,7 @@ int iokit_close(void *device) int iokit_close_raw(void *device) { int ret = 0; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; /* This operation is called only after resource is forked. */ /* On OSX environment, this operation is not required */ @@ -1085,7 +1064,7 @@ int iokit_is_connected(const char *devname) int iokit_inquiry_page(void *device, unsigned char page, struct tc_inq_page *inq) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; struct iokit_scsi_request req; unsigned char cdb[CDB6_LEN]; @@ -1102,28 +1081,26 @@ int iokit_inquiry_page(void *device, unsigned char page, struct tc_inq_page *inq /* Build CDB */ cdb[0] = INQUIRY; - if(page) - cdb[1] = 0x01; + if (page) cdb[1] = 0x01; cdb[2] = page; ltfs_u16tobe(cdb + 3, sizeof(inq->data)); timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_TARGET_TO_INITIATOR; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.dxfer_len = sizeof(inq->data); - req.dxferp = inq->data; - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.dxfer_len = sizeof(inq->data); + req.dxferp = inq->data; + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(timeout); - req.desc = cmd_desc; + req.timeout = IOKitConversion(timeout); + req.desc = cmd_desc; ret = iokit_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { _process_errors(device, ret, msg, cmd_desc, true); } @@ -1136,17 +1113,16 @@ int iokit_inquiry(void *device, struct tc_inq *inq) { int ret = -EDEV_UNKNOWN; int vendor_length = 0; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; struct tc_inq_page inq_page; ret = iokit_inquiry_page(device, 0x00, &inq_page); - if (ret < 0) - return ret; + if (ret < 0) return ret; memset(inq, 0, sizeof(struct tc_inq)); - strncpy((char*)inq->vid, (char*)inq_page.data + 8, VENDOR_ID_LENGTH); - strncpy((char*)inq->pid, (char*)inq_page.data + 16, PRODUCT_ID_LENGTH); - strncpy((char*)inq->revision, (char*)inq_page.data + 32, PRODUCT_REV_LENGTH); + strncpy((char *)inq->vid, (char *)inq_page.data + 8, VENDOR_ID_LENGTH); + strncpy((char *)inq->pid, (char *)inq_page.data + 16, PRODUCT_ID_LENGTH); + strncpy((char *)inq->revision, (char *)inq_page.data + 32, PRODUCT_REV_LENGTH); inq->devicetype = priv->drive_type; @@ -1155,7 +1131,7 @@ int iokit_inquiry(void *device, struct tc_inq *inq) else vendor_length = 20; - strncpy((char*)inq->vendor, (char*)inq_page.data + 36, vendor_length); + strncpy((char *)inq->vendor, (char *)inq_page.data + 36, vendor_length); inq->vendor[vendor_length] = '\0'; return ret; @@ -1164,7 +1140,7 @@ int iokit_inquiry(void *device, struct tc_inq *inq) int iokit_test_unit_ready(void *device) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; struct iokit_scsi_request req; unsigned char cdb[CDB6_LEN]; @@ -1183,20 +1159,19 @@ int iokit_test_unit_ready(void *device) cdb[0] = TEST_UNIT_READY; timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_NO_DATA_TRANSFER; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(timeout); - req.desc = cmd_desc; + req.timeout = IOKitConversion(timeout); + req.desc = cmd_desc; ret = iokit_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { bool print_msg = false, take_dump = false; switch (ret) { @@ -1230,7 +1205,7 @@ int iokit_test_unit_ready(void *device) static int _cdb_read(void *device, char *buf, size_t size, boolean_t sili) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; struct iokit_scsi_request req; unsigned char cdb[CDB6_LEN]; @@ -1244,29 +1219,27 @@ static int _cdb_read(void *device, char *buf, size_t size, boolean_t sili) memset(&req, 0, sizeof(struct iokit_scsi_request)); cdb[0] = READ; - if(sili && priv->use_sili) - cdb[1] = 0x02; + if (sili && priv->use_sili) cdb[1] = 0x02; cdb[2] = (size >> 16) & 0xFF; - cdb[3] = (size >> 8) & 0xFF; - cdb[4] = size & 0xFF; + cdb[3] = (size >> 8) & 0xFF; + cdb[4] = size & 0xFF; timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_TARGET_TO_INITIATOR; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.dxfer_len = size; - req.dxferp = (unsigned char*)buf; - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.dxfer_len = size; + req.dxferp = (unsigned char *)buf; + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(timeout); - req.desc = cmd_desc; + req.timeout = IOKitConversion(timeout); + req.desc = cmd_desc; ret = iokit_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { int32_t diff_len = 0; SCSI_Sense_Data *sense_data = (SCSI_Sense_Data *)(&req.sense_buffer); @@ -1274,10 +1247,8 @@ static int _cdb_read(void *device, char *buf, size_t size, boolean_t sili) case DEVICE_GOOD: case -EDEV_NO_SENSE: if (sense_data->SENSE_KEY & kSENSE_ILI_Set) { - diff_len = ((int32_t)sense_data->INFORMATION_1 << 24) + - ((int32_t)sense_data->INFORMATION_2 << 16) + - ((int32_t)sense_data->INFORMATION_3 << 8) + - ((int32_t)sense_data->INFORMATION_4); + diff_len = ((int32_t)sense_data->INFORMATION_1 << 24) + ((int32_t)sense_data->INFORMATION_2 << 16) + + ((int32_t)sense_data->INFORMATION_3 << 8) + ((int32_t)sense_data->INFORMATION_4); if (!req.actual_xfered || diff_len != req.resid) { #if SUPPORT_BUGGY_IFS @@ -1287,10 +1258,10 @@ static int _cdb_read(void *device, char *buf, size_t size, boolean_t sili) * In this case, LTFS will trust SCSI sense. */ if (diff_len < 0) { - ltfsmsg(LTFS_INFO, 30820I, diff_len, (int)(size - diff_len)); // "Detect overrun condition" + ltfsmsg(LTFS_INFO, 30820I, diff_len, (int)(size - diff_len)); // "Detect overrun condition" ret = -EDEV_OVERRUN; } else { - ltfsmsg(LTFS_DEBUG, 30821D, diff_len, (int)(size - diff_len)); // "Detect underrun condition" + ltfsmsg(LTFS_DEBUG, 30821D, diff_len, (int)(size - diff_len)); // "Detect underrun condition" length = size - diff_len; ret = DEVICE_GOOD; } @@ -1300,10 +1271,10 @@ static int _cdb_read(void *device, char *buf, size_t size, boolean_t sili) #endif } else { if (diff_len < 0) { - ltfsmsg(LTFS_INFO, 30820I, diff_len, (int)(size - diff_len)); // "Detect overrun condition" + ltfsmsg(LTFS_INFO, 30820I, diff_len, (int)(size - diff_len)); // "Detect overrun condition" ret = -EDEV_OVERRUN; } else { - ltfsmsg(LTFS_DEBUG, 30821D, diff_len, (int)(size - diff_len)); // "Detect underrun condition" + ltfsmsg(LTFS_DEBUG, 30821D, diff_len, (int)(size - diff_len)); // "Detect underrun condition" length = size - diff_len; ret = DEVICE_GOOD; } @@ -1339,13 +1310,12 @@ static int _cdb_read(void *device, char *buf, size_t size, boolean_t sili) return length; } -int iokit_read(void *device, char *buf, size_t size, - struct tc_position *pos, const bool unusual_size) +int iokit_read(void *device, char *buf, size_t size, struct tc_position *pos, const bool unusual_size) { int32_t ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; size_t datacount = size; - struct tc_position pos_retry = {0, 0}; + struct tc_position pos_retry = { 0, 0 }; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_READ)); ltfsmsg(LTFS_DEBUG3, 30995D, "read", size, priv->drive_serial); @@ -1365,8 +1335,7 @@ int iokit_read(void *device, char *buf, size_t size, if (global_data.crc_checking) { datacount = size + 4; /* Never fall into this block, fail safe to adjust record length*/ - if (datacount > IOKIT_MAX_BLOCK_SIZE) - datacount = IOKIT_MAX_BLOCK_SIZE; + if (datacount > IOKIT_MAX_BLOCK_SIZE) datacount = IOKIT_MAX_BLOCK_SIZE; } read_retry: @@ -1379,15 +1348,14 @@ int iokit_read(void *device, char *buf, size_t size, return ret; } pos_retry.partition = pos->partition; - pos_retry.block = pos->block; + pos_retry.block = pos->block; ret = iokit_locate(device, pos_retry, pos); if (ret) { ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_READ)); return ret; } goto read_retry; - } else if ( !(pos->block) && unusual_size && - (ret == (int32_t)size || ret == -EDEV_FILEMARK_DETECTED) ) { + } else if (!(pos->block) && unusual_size && (ret == (int32_t)size || ret == -EDEV_FILEMARK_DETECTED)) { /* * Try to read again without sili bit, because some I/F doesn't support SILION read correctly * like @@ -1415,8 +1383,7 @@ int iokit_read(void *device, char *buf, size_t size, if (ret >= 0) { pos->block++; if (global_data.crc_checking && ret > 4) { - if (priv->f_crc_check) - ret = priv->f_crc_check(buf, ret - 4); + if (priv->f_crc_check) ret = priv->f_crc_check(buf, ret - 4); if (ret < 0) { ltfsmsg(LTFS_ERR, 30824E); _take_dump(priv, false); @@ -1432,7 +1399,7 @@ int iokit_read(void *device, char *buf, size_t size, static int _cdb_write(void *device, uint8_t *buf, size_t size, bool *ew, bool *pew) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; struct iokit_scsi_request req; unsigned char cdb[CDB6_LEN]; @@ -1447,29 +1414,28 @@ static int _cdb_write(void *device, uint8_t *buf, size_t size, bool *ew, bool *p cdb[0] = WRITE; cdb[1] = 0x00; /* Always variable in LTFS */ cdb[2] = (size >> 16) & 0xFF; - cdb[3] = (size >> 8) & 0xFF; - cdb[4] = size & 0xFF; + cdb[3] = (size >> 8) & 0xFF; + cdb[4] = size & 0xFF; timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_INITIATOR_TO_TARGET; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.dxfer_len = size; - req.dxferp = (unsigned char*)buf; - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.dxfer_len = size; + req.dxferp = (unsigned char *)buf; + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(timeout); - req.desc = cmd_desc; + req.timeout = IOKitConversion(timeout); + req.desc = cmd_desc; *ew = false; *pew = false; ret = iokit_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { switch (ret) { case -EDEV_EARLY_WARNING: ltfsmsg(LTFS_WARN, 30825W, "write"); @@ -1502,23 +1468,23 @@ int iokit_write(void *device, const char *buf, size_t count, struct tc_position { int ret; bool ew = false, pew = false; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; size_t datacount = count; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_WRITE)); ltfsmsg(LTFS_DEBUG3, 30995D, "write", count, priv->drive_serial); - if ( priv->force_writeperm ) { + if (priv->force_writeperm) { priv->write_counter++; - if ( priv->write_counter > priv->force_writeperm ) { + if (priv->write_counter > priv->force_writeperm) { ltfsmsg(LTFS_INFO, 30846I, "write"); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_WRITE)); if (priv->force_errortype) return -EDEV_NO_SENSE; else return -EDEV_WRITE_PERM; - } else if ( priv->write_counter > (priv->force_writeperm - THRESHOLD_FORCE_WRITE_NO_WRITE) ) { + } else if (priv->write_counter > (priv->force_writeperm - THRESHOLD_FORCE_WRITE_NO_WRITE)) { ltfsmsg(LTFS_INFO, 30847I); pos->block++; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_WRITE)); @@ -1526,14 +1492,13 @@ int iokit_write(void *device, const char *buf, size_t count, struct tc_position } } - if(global_data.crc_checking) { - if (priv->f_crc_enc) - priv->f_crc_enc((void *)buf, count); + if (global_data.crc_checking) { + if (priv->f_crc_enc) priv->f_crc_enc((void *)buf, count); datacount = count + 4; } ret = _cdb_write(device, (uint8_t *)buf, datacount, &ew, &pew); - if(ret == DEVICE_GOOD) { + if (ret == DEVICE_GOOD) { pos->block++; pos->early_warning = ew; pos->programmable_early_warning = pew; @@ -1547,7 +1512,7 @@ int iokit_write(void *device, const char *buf, size_t count, struct tc_position int iokit_writefm(void *device, size_t count, struct tc_position *pos, bool immed) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; struct iokit_scsi_request req; unsigned char cdb[CDB6_LEN]; @@ -1565,27 +1530,25 @@ int iokit_writefm(void *device, size_t count, struct tc_position *pos, bool imme memset(&req, 0, sizeof(struct iokit_scsi_request)); cdb[0] = WRITE_FILEMARKS6; - if (immed) - cdb[1] = 0x01; + if (immed) cdb[1] = 0x01; cdb[2] = (count >> 16) & 0xFF; - cdb[3] = (count >> 8) & 0xFF; - cdb[4] = count & 0xFF; + cdb[3] = (count >> 8) & 0xFF; + cdb[4] = count & 0xFF; timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_NO_DATA_TRANSFER; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(timeout); - req.desc = cmd_desc; + req.timeout = IOKitConversion(timeout); + req.desc = cmd_desc; ret = iokit_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { switch (ret) { case -EDEV_EARLY_WARNING: ltfsmsg(LTFS_WARN, 30825W, "write filemarks"); @@ -1611,13 +1574,11 @@ int iokit_writefm(void *device, size_t count, struct tc_position *pos, bool imme } } - if(ret == DEVICE_GOOD) { + if (ret == DEVICE_GOOD) { ret = iokit_readpos(device, pos); - if(ret == DEVICE_GOOD) { - if (ew && !pos->early_warning) - pos->early_warning = ew; - if (pew && !pos->programmable_early_warning) - pos->programmable_early_warning = pew; + if (ret == DEVICE_GOOD) { + if (ew && !pos->early_warning) pos->early_warning = ew; + if (pew && !pos->programmable_early_warning) pos->programmable_early_warning = pew; } } @@ -1629,7 +1590,7 @@ int iokit_writefm(void *device, size_t count, struct tc_position *pos, bool imme int iokit_rewind(void *device, struct tc_position *pos) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; struct iokit_scsi_request req; unsigned char cdb[CDB6_LEN]; @@ -1647,37 +1608,36 @@ int iokit_rewind(void *device, struct tc_position *pos) cdb[0] = REWIND; timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_NO_DATA_TRANSFER; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(timeout); - req.desc = cmd_desc; + req.timeout = IOKitConversion(timeout); + req.desc = cmd_desc; ret = iokit_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { _process_errors(device, ret, msg, cmd_desc, true); } - if(ret == DEVICE_GOOD) { + if (ret == DEVICE_GOOD) { /* Clear force perm setting */ - priv->clear_by_pc = false; + priv->clear_by_pc = false; priv->force_writeperm = DEFAULT_WRITEPERM; - priv->force_readperm = DEFAULT_READPERM; - priv->write_counter = 0; - priv->read_counter = 0; + priv->force_readperm = DEFAULT_READPERM; + priv->write_counter = 0; + priv->read_counter = 0; ret = iokit_readpos(device, pos); - if(ret == DEVICE_GOOD) { - if(pos->early_warning) + if (ret == DEVICE_GOOD) { + if (pos->early_warning) ltfsmsg(LTFS_WARN, 30825W, "rewind"); - else if(pos->programmable_early_warning) + else if (pos->programmable_early_warning) ltfsmsg(LTFS_WARN, 30826W, "rewind"); } } @@ -1691,7 +1651,7 @@ int iokit_locate(void *device, struct tc_position dest, struct tc_position *pos) { int ret = -EDEV_UNKNOWN; int ret_rp = DEVICE_GOOD; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; struct iokit_scsi_request req; unsigned char cdb[CDB16_LEN]; @@ -1706,11 +1666,11 @@ int iokit_locate(void *device, struct tc_position dest, struct tc_position *pos) if (pos->partition != dest.partition) { if (priv->clear_by_pc) { /* Clear force perm setting */ - priv->clear_by_pc = false; + priv->clear_by_pc = false; priv->force_writeperm = DEFAULT_WRITEPERM; - priv->force_readperm = DEFAULT_READPERM; - priv->write_counter = 0; - priv->read_counter = 0; + priv->force_readperm = DEFAULT_READPERM; + priv->write_counter = 0; + priv->read_counter = 0; } pc = true; } @@ -1719,27 +1679,25 @@ int iokit_locate(void *device, struct tc_position dest, struct tc_position *pos) memset(cdb, 0, sizeof(cdb)); memset(&req, 0, sizeof(struct iokit_scsi_request)); - cdb[0] = LOCATE16; - if (pc) - cdb[1] = 0x02; /* Set Change partition(CP) flag */ - cdb[3] = (unsigned char)(dest.partition & 0xff); + cdb[0] = LOCATE16; + if (pc) cdb[1] = 0x02; /* Set Change partition(CP) flag */ + cdb[3] = (unsigned char)(dest.partition & 0xff); ltfs_u64tobe(cdb + 4, dest.block); timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_NO_DATA_TRANSFER; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(timeout); - req.desc = cmd_desc; + req.timeout = IOKitConversion(timeout); + req.desc = cmd_desc; ret = iokit_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { if (dest.block == TAPE_BLOCK_MAX && ret == -EDEV_EOD_DETECTED) { ltfsmsg(LTFS_DEBUG, 30827D, "Locate"); ret = DEVICE_GOOD; @@ -1749,14 +1707,13 @@ int iokit_locate(void *device, struct tc_position dest, struct tc_position *pos) } ret_rp = iokit_readpos(device, pos); - if(ret_rp == DEVICE_GOOD) { - if(pos->early_warning) + if (ret_rp == DEVICE_GOOD) { + if (pos->early_warning) ltfsmsg(LTFS_WARN, 30825W, "locate"); - else if(pos->programmable_early_warning) + else if (pos->programmable_early_warning) ltfsmsg(LTFS_WARN, 30826W, "locate"); } else { - if (!ret) - ret = ret_rp; + if (!ret) ret = ret_rp; } ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_LOCATE)); @@ -1767,7 +1724,7 @@ int iokit_locate(void *device, struct tc_position dest, struct tc_position *pos) int iokit_space(void *device, size_t count, TC_SPACE_TYPE type, struct tc_position *pos) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; struct iokit_scsi_request req; unsigned char cdb[CDB16_LEN]; @@ -1777,32 +1734,28 @@ int iokit_space(void *device, size_t count, TC_SPACE_TYPE type, struct tc_positi ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_SPACE)); - /* Zero out the CDB and the result buffer */ memset(cdb, 0, sizeof(cdb)); memset(&req, 0, sizeof(struct iokit_scsi_request)); cdb[0] = SPACE16; - switch(type) { + switch (type) { case TC_SPACE_EOD: ltfsmsg(LTFS_DEBUG, 30992D, "space to EOD", priv->drive_serial); cdb[1] = 0x03; break; case TC_SPACE_FM_F: - ltfsmsg(LTFS_DEBUG, 30996D, "space forward file marks", (unsigned long long)count, - priv->drive_serial); + ltfsmsg(LTFS_DEBUG, 30996D, "space forward file marks", (unsigned long long)count, priv->drive_serial); cdb[1] = 0x01; ltfs_u64tobe(cdb + 4, count); break; case TC_SPACE_FM_B: - ltfsmsg(LTFS_DEBUG, 30996D, "space back file marks", (unsigned long long)count, - priv->drive_serial); + ltfsmsg(LTFS_DEBUG, 30996D, "space back file marks", (unsigned long long)count, priv->drive_serial); cdb[1] = 0x01; ltfs_u64tobe(cdb + 4, -count); break; case TC_SPACE_F: - ltfsmsg(LTFS_DEBUG, 30996D, "space forward records", (unsigned long long)count, - priv->drive_serial); + ltfsmsg(LTFS_DEBUG, 30996D, "space forward records", (unsigned long long)count, priv->drive_serial); cdb[1] = 0x00; ltfs_u64tobe(cdb + 4, count); break; @@ -1818,30 +1771,28 @@ int iokit_space(void *device, size_t count, TC_SPACE_TYPE type, struct tc_positi } timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_NO_DATA_TRANSFER; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(timeout); - req.desc = cmd_desc; + req.timeout = IOKitConversion(timeout); + req.desc = cmd_desc; ret = iokit_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { _process_errors(device, ret, msg, cmd_desc, true); } - if(ret == DEVICE_GOOD) - ret = iokit_readpos(device, pos); + if (ret == DEVICE_GOOD) ret = iokit_readpos(device, pos); - if(ret == DEVICE_GOOD) { - if(pos->early_warning) + if (ret == DEVICE_GOOD) { + if (pos->early_warning) ltfsmsg(LTFS_WARN, 30825W, "space"); - else if(pos->programmable_early_warning) + else if (pos->programmable_early_warning) ltfsmsg(LTFS_WARN, 30826W, "space"); } @@ -1853,7 +1804,7 @@ int iokit_space(void *device, size_t count, TC_SPACE_TYPE type, struct tc_positi static int _cdb_request_sense(void *device, unsigned char *buf, unsigned char size) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; struct iokit_scsi_request req; unsigned char cdb[CDB6_LEN]; @@ -1869,19 +1820,18 @@ static int _cdb_request_sense(void *device, unsigned char *buf, unsigned char si cdb[4] = (unsigned char)size; timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_TARGET_TO_INITIATOR; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.dxfer_len = size; - req.dxferp = buf; - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.dxfer_len = size; + req.dxferp = buf; + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(timeout); - req.desc = cmd_desc; + req.timeout = IOKitConversion(timeout); + req.desc = cmd_desc; ret = iokit_issue_cdb_command(&priv->dev, &req, &msg); if (ret < 0) { @@ -1894,7 +1844,7 @@ static int _cdb_request_sense(void *device, unsigned char *buf, unsigned char si int iokit_erase(void *device, struct tc_position *pos, bool long_erase) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; struct iokit_scsi_request req; unsigned char cdb[CDB6_LEN]; @@ -1916,36 +1866,34 @@ int iokit_erase(void *device, struct tc_position *pos, bool long_erase) memset(&req, 0, sizeof(struct iokit_scsi_request)); cdb[0] = ERASE; - if (long_erase) - cdb[1] = 0x03; + if (long_erase) cdb[1] = 0x03; timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_NO_DATA_TRANSFER; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(timeout); - req.desc = cmd_desc; + req.timeout = IOKitConversion(timeout); + req.desc = cmd_desc; ret = iokit_issue_cdb_command(&priv->dev, &req, &msg); if (long_erase) { unsigned char sense_buf[sizeof(SCSI_Sense_Data)]; - uint32_t sense_data; - uint32_t progress; + uint32_t sense_data; + uint32_t progress; while (ret == DEVICE_GOOD) { memset(sense_buf, 0, sizeof(sense_buf)); - ret= _cdb_request_sense(device, sense_buf, sizeof(sense_buf)); + ret = _cdb_request_sense(device, sense_buf, sizeof(sense_buf)); - sense_data = ((uint32_t) sense_buf[2] & 0x0F) << 16; - sense_data += ((uint32_t) sense_buf[12] & 0xFF) << 8; - sense_data += ((uint32_t) sense_buf[13] & 0xFF); + sense_data = ((uint32_t)sense_buf[2] & 0x0F) << 16; + sense_data += ((uint32_t)sense_buf[12] & 0xFF) << 8; + sense_data += ((uint32_t)sense_buf[13] & 0xFF); if (sense_data != 0x000016 && sense_data != 0x000018) { /* Erase operation is NOT in progress */ @@ -1954,18 +1902,18 @@ int iokit_erase(void *device, struct tc_position *pos, bool long_erase) if (IS_ENTERPRISE(priv->drive_type)) { get_current_timespec(&ts_now); - ltfsmsg(LTFS_INFO, 30829I, (int)((ts_now.tv_sec - ts_start.tv_sec)/60)); + ltfsmsg(LTFS_INFO, 30829I, (int)((ts_now.tv_sec - ts_start.tv_sec) / 60)); } else { - progress = ((uint32_t) sense_buf[16] & 0xFF) << 8; - progress += ((uint32_t) sense_buf[17] & 0xFF); - ltfsmsg(LTFS_INFO, 30830I, (progress*100/0xFFFF)); + progress = ((uint32_t)sense_buf[16] & 0xFF) << 8; + progress += ((uint32_t)sense_buf[17] & 0xFF); + ltfsmsg(LTFS_INFO, 30830I, (progress * 100 / 0xFFFF)); } sleep(60); } } - if (ret < 0){ + if (ret < 0) { _process_errors(device, ret, msg, cmd_desc, true); } @@ -1977,7 +1925,7 @@ int iokit_erase(void *device, struct tc_position *pos, bool long_erase) static int _cdb_load_unload(void *device, bool load) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; struct iokit_scsi_request req; unsigned char cdb[CDB6_LEN]; @@ -1990,32 +1938,30 @@ static int _cdb_load_unload(void *device, bool load) memset(&req, 0, sizeof(struct iokit_scsi_request)); cdb[0] = LOAD_UNLOAD; - if (load) - cdb[4] = 0x01; + if (load) cdb[4] = 0x01; timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_NO_DATA_TRANSFER; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(timeout); - req.desc = cmd_desc; + req.timeout = IOKitConversion(timeout); + req.desc = cmd_desc; ret = iokit_issue_cdb_command(&priv->dev, &req, &msg); /* Clear force perm setting */ - priv->clear_by_pc = false; + priv->clear_by_pc = false; priv->force_writeperm = DEFAULT_WRITEPERM; - priv->force_readperm = DEFAULT_READPERM; - priv->write_counter = 0; - priv->read_counter = 0; + priv->force_readperm = DEFAULT_READPERM; + priv->write_counter = 0; + priv->read_counter = 0; - if (ret < 0){ + if (ret < 0) { _process_errors(device, ret, msg, cmd_desc, true); } @@ -2025,7 +1971,7 @@ static int _cdb_load_unload(void *device, bool load) int iokit_load(void *device, struct tc_position *pos) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; unsigned char buf[TC_MP_SUPPORTEDPAGE_SIZE]; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_LOAD)); @@ -2034,21 +1980,21 @@ int iokit_load(void *device, struct tc_position *pos) ret = _cdb_load_unload(device, true); /* Clear force perm setting */ - priv->clear_by_pc = false; + priv->clear_by_pc = false; priv->force_writeperm = DEFAULT_WRITEPERM; - priv->force_readperm = DEFAULT_READPERM; - priv->write_counter = 0; - priv->read_counter = 0; + priv->force_readperm = DEFAULT_READPERM; + priv->write_counter = 0; + priv->read_counter = 0; iokit_readpos(device, pos); if (ret < 0) { ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_LOAD)); return ret; } else { - if(ret == DEVICE_GOOD) { - if(pos->early_warning) + if (ret == DEVICE_GOOD) { + if (pos->early_warning) ltfsmsg(LTFS_WARN, 30825W, "load"); - else if(pos->programmable_early_warning) + else if (pos->programmable_early_warning) ltfsmsg(LTFS_WARN, 30826W, "load"); } @@ -2068,15 +2014,13 @@ int iokit_load(void *device, struct tc_position *pos) if (priv->vendor == VENDOR_HP) { priv->cart_type = assume_cart_type(priv->density_code); - if (buf[2] == 0x01) - priv->is_worm = true; + if (buf[2] == 0x01) priv->is_worm = true; } else { priv->cart_type = buf[2]; } ret = is_supported_tape(priv->cart_type, priv->density_code, &(priv->is_worm)); - if(ret == -LTFS_UNSUPPORTED_MEDIUM) - ltfsmsg(LTFS_INFO, 30831I, priv->cart_type, priv->density_code); + if (ret == -LTFS_UNSUPPORTED_MEDIUM) ltfsmsg(LTFS_INFO, 30831I, priv->cart_type, priv->density_code); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_LOAD)); @@ -2086,7 +2030,7 @@ int iokit_load(void *device, struct tc_position *pos) int iokit_unload(void *device, struct tc_position *pos) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_UNLOAD)); ltfsmsg(LTFS_DEBUG, 30992D, "unload", priv->drive_serial); @@ -2098,12 +2042,12 @@ int iokit_unload(void *device, struct tc_position *pos) return ret; } - priv->loaded = false; - priv->cart_type = 0; + priv->loaded = false; + priv->cart_type = 0; priv->density_code = 0; - priv->tape_alert = 0; - pos->partition = 0; - pos->block = 0; + priv->tape_alert = 0; + pos->partition = 0; + pos->block = 0; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_UNLOAD)); @@ -2113,7 +2057,7 @@ int iokit_unload(void *device, struct tc_position *pos) int iokit_readpos(void *device, struct tc_position *pos) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; struct iokit_scsi_request req; unsigned char cdb[CDB10_LEN]; @@ -2132,31 +2076,34 @@ int iokit_readpos(void *device, struct tc_position *pos) cdb[1] = 0x06; /* Long Format */ timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_TARGET_TO_INITIATOR; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.dxfer_len = sizeof(buf); - req.dxferp = buf; - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.dxfer_len = sizeof(buf); + req.dxferp = buf; + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(timeout); - req.desc = cmd_desc; + req.timeout = IOKitConversion(timeout); + req.desc = cmd_desc; ret = iokit_issue_cdb_command(&priv->dev, &req, &msg); if (ret == DEVICE_GOOD) { pos->partition = ltfs_betou32(buf + 4); - pos->block = ltfs_betou64(buf + 8); + pos->block = ltfs_betou64(buf + 8); pos->filemarks = ltfs_betou64(buf + 16); pos->early_warning = buf[0] & 0x40; pos->programmable_early_warning = buf[0] & 0x01; - ltfsmsg(LTFS_DEBUG, 30998D, "readpos", (unsigned long long)pos->partition, - (unsigned long long)pos->block, (unsigned long long)pos->filemarks, - priv->drive_serial); + ltfsmsg(LTFS_DEBUG, + 30998D, + "readpos", + (unsigned long long)pos->partition, + (unsigned long long)pos->block, + (unsigned long long)pos->filemarks, + priv->drive_serial); } else { _process_errors(device, ret, msg, cmd_desc, true); } @@ -2169,7 +2116,7 @@ int iokit_readpos(void *device, struct tc_position *pos) int iokit_setcap(void *device, uint16_t proportion) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; struct iokit_scsi_request req; unsigned char cdb[CDB6_LEN]; @@ -2196,10 +2143,10 @@ int iokit_setcap(void *device, uint16_t proportion) return ret; } - buf[0] = 0x00; - buf[1] = 0x00; + buf[0] = 0x00; + buf[1] = 0x00; buf[27] |= 0x01; - buf[28] = 0x00; + buf[28] = 0x00; ret = iokit_modeselect(device, buf, sizeof(buf)); } else { @@ -2211,17 +2158,16 @@ int iokit_setcap(void *device, uint16_t proportion) ltfs_u16tobe(cdb + 3, proportion); timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_NO_DATA_TRANSFER; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(timeout); - req.desc = cmd_desc; + req.timeout = IOKitConversion(timeout); + req.desc = cmd_desc; ret = iokit_issue_cdb_command(&priv->dev, &req, &msg); if (ret < 0) { @@ -2234,10 +2180,11 @@ int iokit_setcap(void *device, uint16_t proportion) return ret; } -int iokit_format(void *device, TC_FORMAT_TYPE format, const char *vol_name, const char *barcode_name, const char *vol_mam_uuid) +int iokit_format( + void *device, TC_FORMAT_TYPE format, const char *vol_name, const char *barcode_name, const char *vol_mam_uuid) { int ret = -EDEV_UNKNOWN, aux_ret; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; unsigned char buf[TC_MP_SUPPORTEDPAGE_SIZE]; struct iokit_scsi_request req; @@ -2257,17 +2204,16 @@ int iokit_format(void *device, TC_FORMAT_TYPE format, const char *vol_name, cons cdb[2] = format; timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_NO_DATA_TRANSFER; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(timeout); - req.desc = cmd_desc; + req.timeout = IOKitConversion(timeout); + req.desc = cmd_desc; ret = iokit_issue_cdb_command(&priv->dev, &req, &msg); if (ret < 0) { @@ -2289,9 +2235,9 @@ int iokit_format(void *device, TC_FORMAT_TYPE format, const char *vol_name, cons int iokit_remaining_capacity(void *device, struct tc_remaining_cap *cap) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; - unsigned char buffer[LOGSENSEPAGE]; /* Buffer for logsense */ + unsigned char buffer[LOGSENSEPAGE]; /* Buffer for logsense */ unsigned char buf[LOG_TAPECAPACITY_SIZE]; /* Buffer for parsing logsense data */ uint32_t param_size; int32_t i; @@ -2305,17 +2251,14 @@ int iokit_remaining_capacity(void *device, struct tc_remaining_cap *cap) if (IS_LTO(priv->drive_type) && (DRIVE_GEN(priv->drive_type) == 0x05)) { /* Use LogPage 0x31 */ ret = iokit_logsense(device, (uint8_t)LOG_TAPECAPACITY, (uint8_t)0, (void *)buffer, LOGSENSEPAGE); - if(ret < 0) - { + if (ret < 0) { ltfsmsg(LTFS_INFO, 30832I, LOG_VOLUMESTATS, ret); goto out; } - for( i = TAPECAP_REMAIN_0; i < TAPECAP_SIZE; i++) - { + for (i = TAPECAP_REMAIN_0; i < TAPECAP_SIZE; i++) { ret = _parse_logPage(buffer, (uint16_t)i, ¶m_size, buf, sizeof(buf)); - if(ret < 0 || param_size != sizeof(uint32_t)) - { + if (ret < 0 || param_size != sizeof(uint32_t)) { ltfsmsg(LTFS_INFO, 30833I, i, param_size); ret = -EDEV_INTERNAL_ERROR; goto out; @@ -2323,8 +2266,7 @@ int iokit_remaining_capacity(void *device, struct tc_remaining_cap *cap) logcap = ltfs_betou32(buf); - switch(i) - { + switch (i) { case TAPECAP_REMAIN_0: cap->remaining_p0 = logcap; break; @@ -2348,7 +2290,7 @@ int iokit_remaining_capacity(void *device, struct tc_remaining_cap *cap) } else { /* Use LogPage 0x17 */ ret = iokit_logsense(device, LOG_VOLUMESTATS, (uint8_t)0, (void *)buffer, LOGSENSEPAGE); - if(ret < 0) { + if (ret < 0) { ltfsmsg(LTFS_INFO, 30832I, LOG_VOLUMESTATS, ret); goto out; } @@ -2394,21 +2336,28 @@ int iokit_remaining_capacity(void *device, struct tc_remaining_cap *cap) ret = DEVICE_GOOD; } - ltfsmsg(LTFS_DEBUG3, 30997D, "capacity part0", (unsigned long long)cap->remaining_p0, - (unsigned long long)cap->max_p0, priv->drive_serial); - ltfsmsg(LTFS_DEBUG3, 30997D, "capacity part1", (unsigned long long)cap->remaining_p1, - (unsigned long long)cap->max_p1, priv->drive_serial); + ltfsmsg(LTFS_DEBUG3, + 30997D, + "capacity part0", + (unsigned long long)cap->remaining_p0, + (unsigned long long)cap->max_p0, + priv->drive_serial); + ltfsmsg(LTFS_DEBUG3, + 30997D, + "capacity part1", + (unsigned long long)cap->remaining_p1, + (unsigned long long)cap->max_p1, + priv->drive_serial); out: ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_REMAINCAP)); return ret; } -int iokit_logsense(void *device, const uint8_t page, const uint8_t subpage, - unsigned char *buf, const size_t size) +int iokit_logsense(void *device, const uint8_t page, const uint8_t subpage, unsigned char *buf, const size_t size) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; struct iokit_scsi_request req; unsigned char cdb[CDB10_LEN]; @@ -2420,12 +2369,10 @@ int iokit_logsense(void *device, const uint8_t page, const uint8_t subpage, unsigned char *inner_buf = NULL; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_LOGSENSE)); - ltfsmsg(LTFS_DEBUG3, 30997D, "logsense", - (unsigned long long)page, (unsigned long long)subpage, priv->drive_serial); + ltfsmsg(LTFS_DEBUG3, 30997D, "logsense", (unsigned long long)page, (unsigned long long)subpage, priv->drive_serial); inner_buf = calloc(1, MAXLP_SIZE); /* Assume max length of LP is 0xFFFF */ - if (!inner_buf) - return -LTFS_NO_MEMORY; + if (!inner_buf) return -LTFS_NO_MEMORY; /* Zero out the CDB and the result buffer */ memset(cdb, 0, sizeof(cdb)); @@ -2445,17 +2392,17 @@ int iokit_logsense(void *device, const uint8_t page, const uint8_t subpage, /* Build request */ req.dxfer_direction = SCSI_FROM_TARGET_TO_INITIATOR; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.dxfer_len = MAXLP_SIZE; - req.dxferp = inner_buf; - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.dxfer_len = MAXLP_SIZE; + req.dxferp = inner_buf; + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(timeout); - req.desc = cmd_desc; + req.timeout = IOKitConversion(timeout); + req.desc = cmd_desc; ret = iokit_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { _process_errors(device, ret, msg, cmd_desc, true); } else { len = ((int)inner_buf[2] << 8) + (int)inner_buf[3] + 4; @@ -2468,17 +2415,21 @@ int iokit_logsense(void *device, const uint8_t page, const uint8_t subpage, ret = len; } - free (inner_buf); + free(inner_buf); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_LOGSENSE)); return ret; } -int iokit_modesense(void *device, const unsigned char page, const TC_MP_PC_TYPE pc, - const unsigned char subpage, unsigned char *buf, const size_t size) +int iokit_modesense(void *device, + const unsigned char page, + const TC_MP_PC_TYPE pc, + const unsigned char subpage, + unsigned char *buf, + const size_t size) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; struct iokit_scsi_request req; unsigned char cdb[CDB10_LEN]; @@ -2500,22 +2451,21 @@ int iokit_modesense(void *device, const unsigned char page, const TC_MP_PC_TYPE ltfs_u16tobe(cdb + 7, size); timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_TARGET_TO_INITIATOR; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.dxfer_len = size; - req.dxferp = buf; - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.dxfer_len = size; + req.dxferp = buf; + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(timeout); - req.desc = cmd_desc; + req.timeout = IOKitConversion(timeout); + req.desc = cmd_desc; ret = iokit_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { _process_errors(device, ret, msg, cmd_desc, true); } else { ret = req.actual_xfered; @@ -2529,7 +2479,7 @@ int iokit_modesense(void *device, const unsigned char page, const TC_MP_PC_TYPE int iokit_modeselect(void *device, unsigned char *buf, const size_t size) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; struct iokit_scsi_request req; unsigned char cdb[CDB10_LEN]; @@ -2550,22 +2500,21 @@ int iokit_modeselect(void *device, unsigned char *buf, const size_t size) ltfs_u16tobe(cdb + 7, size); timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_INITIATOR_TO_TARGET; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.dxfer_len = size; - req.dxferp = buf; - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.dxfer_len = size; + req.dxferp = buf; + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(timeout); - req.desc = cmd_desc; + req.timeout = IOKitConversion(timeout); + req.desc = cmd_desc; ret = iokit_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { _process_errors(device, ret, msg, cmd_desc, true); } @@ -2577,7 +2526,7 @@ int iokit_modeselect(void *device, unsigned char *buf, const size_t size) int iokit_reserve(void *device) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; #ifdef USE_RESERVE6 struct iokit_scsi_request req; @@ -2597,20 +2546,19 @@ int iokit_reserve(void *device) cdb[0] = RESERVE_UNIT6; timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_NO_DATA_TRANSFER; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(timeout); - req.desc = cmd_desc; + req.timeout = IOKitConversion(timeout); + req.desc = cmd_desc; ret = iokit_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { _process_errors(device, ret, msg, cmd_desc, true); } @@ -2624,15 +2572,11 @@ int iokit_reserve(void *device) ltfsmsg(LTFS_DEBUG, 30992D, "reserve (PRO)", priv->drive_serial); start: - ret = _cdb_pro(device, PRO_ACT_RESERVE, PRO_TYPE_EXCLUSIVE, - priv->key, NULL); + ret = _cdb_pro(device, PRO_ACT_RESERVE, PRO_TYPE_EXCLUSIVE, priv->key, NULL); /* Retry if reservation is preempted */ - if ( !count && - ( ret == -EDEV_RESERVATION_PREEMPTED || - ret == -EDEV_REGISTRATION_PREEMPTED || - ret == -EDEV_RESERVATION_CONFLICT) - ) { + if (!count && (ret == -EDEV_RESERVATION_PREEMPTED || ret == -EDEV_REGISTRATION_PREEMPTED || + ret == -EDEV_RESERVATION_CONFLICT)) { ltfsmsg(LTFS_INFO, 30868I, priv->drive_serial); _register_key(device, priv->key); count++; @@ -2649,7 +2593,7 @@ int iokit_reserve(void *device) int iokit_release(void *device) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; #ifdef USE_RESERVE6 struct iokit_scsi_request req; @@ -2669,20 +2613,19 @@ int iokit_release(void *device) cdb[0] = RELEASE_UNIT6; timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_NO_DATA_TRANSFER; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(timeout); - req.desc = cmd_desc; + req.timeout = IOKitConversion(timeout); + req.desc = cmd_desc; ret = iokit_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { _process_errors(device, ret, msg, cmd_desc, true); } @@ -2693,8 +2636,7 @@ int iokit_release(void *device) ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_RELEASEUNIT)); ltfsmsg(LTFS_DEBUG, 30992D, "release (PRO)", priv->drive_serial); - ret = _cdb_pro(device, PRO_ACT_RELEASE, PRO_TYPE_EXCLUSIVE, - priv->key, NULL); + ret = _cdb_pro(device, PRO_ACT_RELEASE, PRO_TYPE_EXCLUSIVE, priv->key, NULL); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_RELEASEUNIT)); @@ -2706,7 +2648,7 @@ int iokit_release(void *device) static int _cdb_prevent_allow_medium_removal(void *device, bool prevent) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; struct iokit_scsi_request req; unsigned char cdb[CDB6_LEN]; @@ -2719,24 +2661,22 @@ static int _cdb_prevent_allow_medium_removal(void *device, bool prevent) memset(&req, 0, sizeof(struct iokit_scsi_request)); cdb[0] = PREVENT_ALLOW_MEDIUM_REMOVAL; - if (prevent) - cdb[4] = 0x01; + if (prevent) cdb[4] = 0x01; timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_NO_DATA_TRANSFER; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(timeout); - req.desc = cmd_desc; + req.timeout = IOKitConversion(timeout); + req.desc = cmd_desc; ret = iokit_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { _process_errors(device, ret, msg, cmd_desc, true); } @@ -2746,7 +2686,7 @@ static int _cdb_prevent_allow_medium_removal(void *device, bool prevent) int iokit_prevent_medium_removal(void *device) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_PREVENTM)); ltfsmsg(LTFS_DEBUG, 30992D, "prevent medium removal", priv->drive_serial); @@ -2759,7 +2699,7 @@ int iokit_prevent_medium_removal(void *device) int iokit_allow_medium_removal(void *device) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_ALLOWMREM)); ltfsmsg(LTFS_DEBUG, 30992D, "allow medium removal", priv->drive_serial); @@ -2769,11 +2709,10 @@ int iokit_allow_medium_removal(void *device) return ret; } -int iokit_write_attribute(void *device, const tape_partition_t part, - const unsigned char *buf, const size_t size) +int iokit_write_attribute(void *device, const tape_partition_t part, const unsigned char *buf, const size_t size) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; struct iokit_scsi_request req; unsigned char cdb[CDB16_LEN]; @@ -2782,8 +2721,7 @@ int iokit_write_attribute(void *device, const tape_partition_t part, char *msg = NULL; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_WRITEATTR)); - ltfsmsg(LTFS_DEBUG3, 30996D, "writeattr", (unsigned long long)part, - priv->drive_serial); + ltfsmsg(LTFS_DEBUG3, 30996D, "writeattr", (unsigned long long)part, priv->drive_serial); /* Prepare the buffer to transfer */ uint32_t len = size + 4; @@ -2814,17 +2752,17 @@ int iokit_write_attribute(void *device, const tape_partition_t part, /* Build request */ req.dxfer_direction = SCSI_FROM_INITIATOR_TO_TARGET; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.dxfer_len = len; - req.dxferp = buffer; - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.dxfer_len = len; + req.dxferp = buffer; + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(timeout); - req.desc = cmd_desc; + req.timeout = IOKitConversion(timeout); + req.desc = cmd_desc; ret = iokit_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { _process_errors(device, ret, msg, cmd_desc, true); } @@ -2835,11 +2773,11 @@ int iokit_write_attribute(void *device, const tape_partition_t part, return ret; } -int iokit_read_attribute(void *device, const tape_partition_t part, - const uint16_t id, unsigned char *buf, const size_t size) +int iokit_read_attribute( + void *device, const tape_partition_t part, const uint16_t id, unsigned char *buf, const size_t size) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; struct iokit_scsi_request req; unsigned char cdb[CDB16_LEN]; @@ -2875,37 +2813,30 @@ int iokit_read_attribute(void *device, const tape_partition_t part, ltfs_u32tobe(cdb + 10, len); timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_TARGET_TO_INITIATOR; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.dxfer_len = len; - req.dxferp = buffer; - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.dxfer_len = len; + req.dxferp = buffer; + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(timeout); - req.desc = cmd_desc; + req.timeout = IOKitConversion(timeout); + req.desc = cmd_desc; ret = iokit_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { bool tape_dump = true; - if (ret == -EDEV_INVALID_FIELD_CDB) - tape_dump = false; + if (ret == -EDEV_INVALID_FIELD_CDB) tape_dump = false; _process_errors(device, ret, msg, cmd_desc, tape_dump); - if (id != TC_MAM_PAGE_COHERENCY && - id != TC_MAM_APP_VENDER && - id != TC_MAM_APP_NAME && - id != TC_MAM_APP_VERSION && - id != TC_MAM_USER_MEDIUM_LABEL && - id != TC_MAM_TEXT_LOCALIZATION_IDENTIFIER && - id != TC_MAM_BARCODE && - id != TC_MAM_APP_FORMAT_VERSION) + if (id != TC_MAM_PAGE_COHERENCY && id != TC_MAM_APP_VENDER && id != TC_MAM_APP_NAME && id != TC_MAM_APP_VERSION && + id != TC_MAM_USER_MEDIUM_LABEL && id != TC_MAM_TEXT_LOCALIZATION_IDENTIFIER && id != TC_MAM_BARCODE && + id != TC_MAM_APP_FORMAT_VERSION) ltfsmsg(LTFS_INFO, 30836I, ret); } else { if (size == MAXMAM_SIZE) { @@ -2925,7 +2856,7 @@ int iokit_read_attribute(void *device, const tape_partition_t part, int iokit_allow_overwrite(void *device, const struct tc_position pos) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; struct iokit_scsi_request req; unsigned char cdb[CDB16_LEN]; @@ -2946,20 +2877,19 @@ int iokit_allow_overwrite(void *device, const struct tc_position pos) ltfs_u64tobe(cdb + 4, pos.block); timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_NO_DATA_TRANSFER; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(timeout); - req.desc = cmd_desc; + req.timeout = IOKitConversion(timeout); + req.desc = cmd_desc; ret = iokit_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { if (pos.block == TAPE_BLOCK_MAX && ret == -EDEV_EOD_DETECTED) { ltfsmsg(LTFS_DEBUG, 30827D, "Allow Overwrite"); ret = DEVICE_GOOD; @@ -2994,7 +2924,7 @@ int iokit_rrao(void *device, unsigned char *buf, const uint32_t len, size_t *out int iokit_set_compression(void *device, const bool enable_compression, struct tc_position *pos) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; unsigned char buf[TC_MP_COMPRESSION_SIZE]; @@ -3002,13 +2932,12 @@ int iokit_set_compression(void *device, const bool enable_compression, struct tc /* Capture compression setting */ ret = iokit_modesense(device, TC_MP_COMPRESSION, TC_MP_PC_CURRENT, 0x00, buf, sizeof(buf)); - if (ret < 0) - return ret; + if (ret < 0) return ret; - buf[0] = 0x00; - buf[1] = 0x00; + buf[0] = 0x00; + buf[1] = 0x00; - if(enable_compression) + if (enable_compression) buf[18] = buf[18] | 0x80; else buf[18] = buf[18] & 0x7E; @@ -3023,7 +2952,7 @@ int iokit_set_compression(void *device, const bool enable_compression, struct tc int iokit_set_default(void *device) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; priv->use_sili = true; @@ -3039,8 +2968,8 @@ int iokit_set_default(void *device) return ret; } - buf[0] = 0x00; - buf[1] = 0x00; + buf[0] = 0x00; + buf[1] = 0x00; buf[24] = 0x0C; ret = iokit_modeselect(device, buf, sizeof(buf)); @@ -3073,31 +3002,22 @@ int iokit_set_default(void *device) * @return 0 on success or a negative value on error */ -#define LOG_TAPE_ALERT (0x2E) -#define LOG_PERFORMANCE (0x37) +#define LOG_TAPE_ALERT (0x2E) +#define LOG_PERFORMANCE (0x37) -#define LOG_PERFORMANCE_CAPACITY_SUB (0x64) // Scope(7-6): Mount Values +#define LOG_PERFORMANCE_CAPACITY_SUB (0x64) // Scope(7-6): Mount Values // Level(5-4): Return Advanced Counters // Group(3-0): Capacity static uint16_t volstats[] = { - VOLSTATS_MOUNTS, - VOLSTATS_WRITTEN_DS, - VOLSTATS_WRITE_TEMPS, - VOLSTATS_WRITE_PERMS, - VOLSTATS_READ_DS, - VOLSTATS_READ_TEMPS, - VOLSTATS_READ_PERMS, - VOLSTATS_WRITE_PERMS_PREV, - VOLSTATS_READ_PERMS_PREV, - VOLSTATS_WRITE_MB, - VOLSTATS_READ_MB, - VOLSTATS_PASSES_BEGIN, - VOLSTATS_PASSES_MIDDLE, + VOLSTATS_MOUNTS, VOLSTATS_WRITTEN_DS, VOLSTATS_WRITE_TEMPS, VOLSTATS_WRITE_PERMS, VOLSTATS_READ_DS, + VOLSTATS_READ_TEMPS, VOLSTATS_READ_PERMS, VOLSTATS_WRITE_PERMS_PREV, VOLSTATS_READ_PERMS_PREV, VOLSTATS_WRITE_MB, + VOLSTATS_READ_MB, VOLSTATS_PASSES_BEGIN, VOLSTATS_PASSES_MIDDLE, }; -enum { - PERF_CART_CONDITION = 0x0001, /* < Media Efficiency */ - PERF_ACTIVE_CQ_LOSS_W = 0x7113, /* < Active CQ loss Write */ +enum +{ + PERF_CART_CONDITION = 0x0001, /* < Media Efficiency */ + PERF_ACTIVE_CQ_LOSS_W = 0x7113, /* < Active CQ loss Write */ }; static uint16_t perfstats[] = { @@ -3107,7 +3027,7 @@ static uint16_t perfstats[] = { int iokit_get_cartridge_health(void *device, struct tc_cartridge_health *cart_health) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; unsigned char logdata[LOGSENSEPAGE]; unsigned char buf[16]; @@ -3118,16 +3038,16 @@ int iokit_get_cartridge_health(void *device, struct tc_cartridge_health *cart_he ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_GETCARTHLTH)); /* Issue LogPage 0x37 */ - cart_health->tape_efficiency = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->tape_efficiency = UNSUPPORTED_CARTRIDGE_HEALTH; ret = iokit_logsense(device, LOG_PERFORMANCE, (uint8_t)0, logdata, LOGSENSEPAGE); if (ret < 0) ltfsmsg(LTFS_INFO, 30837I, LOG_PERFORMANCE, ret, "get cart health"); else { - for(i = 0; i < (int)((sizeof(perfstats)/sizeof(perfstats[0]))); i++) { + for (i = 0; i < (int)((sizeof(perfstats) / sizeof(perfstats[0]))); i++) { if (_parse_logPage(logdata, perfstats[i], ¶m_size, buf, 16)) { ltfsmsg(LTFS_INFO, 30838I, LOG_PERFORMANCE, "get cart health"); } else { - switch(param_size) { + switch (param_size) { case sizeof(uint8_t): loghlt = (uint64_t)(buf[0]); break; @@ -3135,21 +3055,19 @@ int iokit_get_cartridge_health(void *device, struct tc_cartridge_health *cart_he loghlt = ((uint64_t)buf[0] << 8) + (uint64_t)buf[1]; break; case sizeof(uint32_t): - loghlt = ((uint64_t)buf[0] << 24) + ((uint64_t)buf[1] << 16) - + ((uint64_t)buf[2] << 8) + (uint64_t)buf[3]; + loghlt = ((uint64_t)buf[0] << 24) + ((uint64_t)buf[1] << 16) + ((uint64_t)buf[2] << 8) + (uint64_t)buf[3]; break; case sizeof(uint64_t): - loghlt = ((uint64_t)buf[0] << 56) + ((uint64_t)buf[1] << 48) - + ((uint64_t)buf[2] << 40) + ((uint64_t)buf[3] << 32) - + ((uint64_t)buf[4] << 24) + ((uint64_t)buf[5] << 16) - + ((uint64_t)buf[6] << 8) + (uint64_t)buf[7]; + loghlt = ((uint64_t)buf[0] << 56) + ((uint64_t)buf[1] << 48) + ((uint64_t)buf[2] << 40) + + ((uint64_t)buf[3] << 32) + ((uint64_t)buf[4] << 24) + ((uint64_t)buf[5] << 16) + + ((uint64_t)buf[6] << 8) + (uint64_t)buf[7]; break; default: loghlt = UNSUPPORTED_CARTRIDGE_HEALTH; break; } - switch(perfstats[i]) { + switch (perfstats[i]) { case PERF_CART_CONDITION: cart_health->tape_efficiency = loghlt; break; @@ -3161,28 +3079,28 @@ int iokit_get_cartridge_health(void *device, struct tc_cartridge_health *cart_he } /* Issue LogPage 0x17 */ - cart_health->mounts = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->written_ds = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->write_temps = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->write_perms = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_ds = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_temps = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_perms = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->mounts = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->written_ds = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->write_temps = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->write_perms = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_ds = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_temps = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_perms = UNSUPPORTED_CARTRIDGE_HEALTH; cart_health->write_perms_prev = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_perms_prev = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->written_mbytes = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->read_mbytes = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->passes_begin = UNSUPPORTED_CARTRIDGE_HEALTH; - cart_health->passes_middle = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_perms_prev = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->written_mbytes = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->read_mbytes = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->passes_begin = UNSUPPORTED_CARTRIDGE_HEALTH; + cart_health->passes_middle = UNSUPPORTED_CARTRIDGE_HEALTH; ret = iokit_logsense(device, LOG_VOLUMESTATS, (uint8_t)0, logdata, LOGSENSEPAGE); if (ret < 0) ltfsmsg(LTFS_INFO, 30837I, LOG_VOLUMESTATS, ret, "get cart health"); else { - for(i = 0; i < (int)((sizeof(volstats)/sizeof(volstats[0]))); i++) { + for (i = 0; i < (int)((sizeof(volstats) / sizeof(volstats[0]))); i++) { if (_parse_logPage(logdata, volstats[i], ¶m_size, buf, 16)) { ltfsmsg(LTFS_INFO, 30838I, LOG_VOLUMESTATS, "get cart health"); } else { - switch(param_size) { + switch (param_size) { case sizeof(uint8_t): loghlt = (uint64_t)(buf[0]); break; @@ -3190,21 +3108,19 @@ int iokit_get_cartridge_health(void *device, struct tc_cartridge_health *cart_he loghlt = ((uint64_t)buf[0] << 8) + (uint64_t)buf[1]; break; case sizeof(uint32_t): - loghlt = ((uint64_t)buf[0] << 24) + ((uint64_t)buf[1] << 16) - + ((uint64_t)buf[2] << 8) + (uint64_t)buf[3]; + loghlt = ((uint64_t)buf[0] << 24) + ((uint64_t)buf[1] << 16) + ((uint64_t)buf[2] << 8) + (uint64_t)buf[3]; break; case sizeof(uint64_t): - loghlt = ((uint64_t)buf[0] << 56) + ((uint64_t)buf[1] << 48) - + ((uint64_t)buf[2] << 40) + ((uint64_t)buf[3] << 32) - + ((uint64_t)buf[4] << 24) + ((uint64_t)buf[5] << 16) - + ((uint64_t)buf[6] << 8) + (uint64_t)buf[7]; + loghlt = ((uint64_t)buf[0] << 56) + ((uint64_t)buf[1] << 48) + ((uint64_t)buf[2] << 40) + + ((uint64_t)buf[3] << 32) + ((uint64_t)buf[4] << 24) + ((uint64_t)buf[5] << 16) + + ((uint64_t)buf[6] << 8) + (uint64_t)buf[7]; break; default: loghlt = UNSUPPORTED_CARTRIDGE_HEALTH; break; } - switch(volstats[i]) { + switch (volstats[i]) { case VOLSTATS_MOUNTS: cart_health->mounts = loghlt; break; @@ -3258,7 +3174,7 @@ int iokit_get_cartridge_health(void *device, struct tc_cartridge_health *cart_he int iokit_get_tape_alert(void *device, uint64_t *tape_alert) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; unsigned char logdata[LOGSENSEPAGE]; unsigned char buf[16]; @@ -3275,15 +3191,13 @@ int iokit_get_tape_alert(void *device, uint64_t *tape_alert) ltfsmsg(LTFS_INFO, 30837I, LOG_TAPE_ALERT, ret, "get tape alert"); else { ret = 0; - for(i = 1; i <= 64; i++) { - if (_parse_logPage(logdata, (uint16_t) i, ¶m_size, buf, 16) - || param_size != sizeof(uint8_t)) { + for (i = 1; i <= 64; i++) { + if (_parse_logPage(logdata, (uint16_t)i, ¶m_size, buf, 16) || param_size != sizeof(uint8_t)) { ltfsmsg(LTFS_INFO, 30838I, LOG_VOLUMESTATS, "get tape alert"); ta = 0; } - if(buf[0]) - ta += (uint64_t)(1) << (i - 1); + if (buf[0]) ta += (uint64_t)(1) << (i - 1); } } @@ -3296,7 +3210,7 @@ int iokit_get_tape_alert(void *device, uint64_t *tape_alert) int iokit_clear_tape_alert(void *device, uint64_t tape_alert) { - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_CLRTAPEALT)); priv->tape_alert &= ~tape_alert; @@ -3307,7 +3221,7 @@ int iokit_clear_tape_alert(void *device, uint64_t tape_alert) int iokit_get_xattr(void *device, const char *name, char **buf) { int ret = -LTFS_NO_XATTR; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; unsigned char logdata[LOGSENSEPAGE]; unsigned char logbuf[16]; @@ -3318,25 +3232,21 @@ int iokit_get_xattr(void *device, const char *name, char **buf) ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_GETXATTR)); - if (!strcmp(name, "ltfs.vendor.IBM.mediaCQsLossRate")) - { + if (!strcmp(name, "ltfs.vendor.IBM.mediaCQsLossRate")) { ret = DEVICE_GOOD; /* If first fetch or cache value is too old and value is dirty, refresh value. */ get_current_timespec(&now); - if (priv->fetch_sec_acq_loss_w == 0 || - ((priv->fetch_sec_acq_loss_w + 60 < now.tv_sec) && priv->dirty_acq_loss_w)) - { + if (priv->fetch_sec_acq_loss_w == 0 || ((priv->fetch_sec_acq_loss_w + 60 < now.tv_sec) && priv->dirty_acq_loss_w)) { ret = iokit_logsense(device, LOG_PERFORMANCE, LOG_PERFORMANCE_CAPACITY_SUB, logdata, LOGSENSEPAGE); if (ret < 0) { ltfsmsg(LTFS_INFO, 30837I, LOG_PERFORMANCE, ret, "get xattr"); } else { ret = 0; if (_parse_logPage(logdata, PERF_ACTIVE_CQ_LOSS_W, ¶m_size, logbuf, 16)) { - ltfsmsg(LTFS_INFO, 30838I, LOG_PERFORMANCE, "get xattr"); + ltfsmsg(LTFS_INFO, 30838I, LOG_PERFORMANCE, "get xattr"); ret = -LTFS_NO_XATTR; - } - else { + } else { switch (param_size) { case sizeof(uint32_t): value32 = (uint32_t)ltfs_betou32(logbuf); @@ -3375,16 +3285,15 @@ int iokit_set_xattr(void *device, const char *name, const char *buf, size_t size { int ret = -LTFS_NO_XATTR; char *null_terminated; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; int64_t wp_count = 0; - if (!size) - return -LTFS_BAD_ARG; + if (!size) return -LTFS_BAD_ARG; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_SETXATTR)); null_terminated = malloc(size + 1); - if (! null_terminated) { + if (!null_terminated) { ltfsmsg(LTFS_ERR, 10001E, "iokit_set_xattr: null_term"); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_SETXATTR)); return -LTFS_NO_MEMORY; @@ -3392,19 +3301,19 @@ int iokit_set_xattr(void *device, const char *name, const char *buf, size_t size memcpy(null_terminated, buf, size); null_terminated[size] = '\0'; - if (! strcmp(name, "ltfs.vendor.IBM.forceErrorWrite")) { + if (!strcmp(name, "ltfs.vendor.IBM.forceErrorWrite")) { wp_count = strtoll(null_terminated, NULL, 0); if (wp_count < 0) { priv->force_writeperm = -wp_count; - priv->clear_by_pc = true; + priv->clear_by_pc = true; } if (priv->force_writeperm && priv->force_writeperm < THRESHOLD_FORCE_WRITE_NO_WRITE) priv->force_writeperm = THRESHOLD_FORCE_WRITE_NO_WRITE; ret = DEVICE_GOOD; - } else if (! strcmp(name, "ltfs.vendor.IBM.forceErrorType")) { + } else if (!strcmp(name, "ltfs.vendor.IBM.forceErrorType")) { priv->force_errortype = strtol(null_terminated, NULL, 0); ret = DEVICE_GOOD; - } else if (! strcmp(name, "ltfs.vendor.IBM.forceErrorRead")) { + } else if (!strcmp(name, "ltfs.vendor.IBM.forceErrorRead")) { priv->force_readperm = strtoull(null_terminated, NULL, 0); priv->read_counter = 0; ret = DEVICE_GOOD; @@ -3417,9 +3326,10 @@ int iokit_set_xattr(void *device, const char *name, const char *buf, size_t size #define BLOCKLEN_DATA_SIZE 6 -static int _cdb_read_block_limits(void *device) { +static int _cdb_read_block_limits(void *device) +{ int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; struct iokit_scsi_request req; unsigned char cdb[CDB6_LEN]; @@ -3439,27 +3349,26 @@ static int _cdb_read_block_limits(void *device) { cdb[0] = READ_BLOCK_LIMITS; timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_TARGET_TO_INITIATOR; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.dxfer_len = sizeof(buf); - req.dxferp = buf; - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.dxfer_len = sizeof(buf); + req.dxferp = buf; + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(timeout); - req.desc = cmd_desc; + req.timeout = IOKitConversion(timeout); + req.desc = cmd_desc; ret = iokit_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { _process_errors(device, ret, msg, cmd_desc, true); } else { - ret = ((unsigned int) buf[1] & 0xFF) << 16; - ret += ((unsigned int) buf[2] & 0xFF) << 8; - ret += ((unsigned int) buf[3] & 0xFF); + ret = ((unsigned int)buf[1] & 0xFF) << 16; + ret += ((unsigned int)buf[2] & 0xFF) << 8; + ret += ((unsigned int)buf[3] & 0xFF); } return ret; @@ -3468,20 +3377,19 @@ static int _cdb_read_block_limits(void *device) { int iokit_get_parameters(void *device, struct tc_drive_param *params) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_GETPARAM)); if (priv->loaded) { params->cart_type = priv->cart_type; - params->density = priv->density_code; + params->density = priv->density_code; if (IS_ENTERPRISE(priv->drive_type)) { unsigned char buf[TC_MP_MEDIUM_SENSE_SIZE]; ret = iokit_modesense(device, TC_MP_MEDIUM_SENSE, TC_MP_PC_CURRENT, 0, buf, sizeof(buf)); - if (ret < 0) - goto out; + if (ret < 0) goto out; char wp_flag = buf[26]; @@ -3505,8 +3413,7 @@ int iokit_get_parameters(void *device, struct tc_drive_param *params) unsigned char buf[MODE_DEVICE_CONFIG_SIZE]; ret = iokit_modesense(device, MODE_DEVICE_CONFIG, TC_MP_PC_CURRENT, 0, buf, sizeof(buf)); - if (ret < 0) - goto out; + if (ret < 0) goto out; if (buf[3] & 0x80) { params->write_protect |= VOL_PHYSICAL_WP; @@ -3522,7 +3429,7 @@ int iokit_get_parameters(void *device, struct tc_drive_param *params) } } else { params->cart_type = priv->cart_type; - params->density = priv->density_code; + params->density = priv->density_code; } if (global_data.crc_checking) @@ -3537,14 +3444,14 @@ int iokit_get_parameters(void *device, struct tc_drive_param *params) return ret; } -#define LOG_VOL_STATISTICS (0x17) -#define LOG_VOL_USED_CAPACITY (0x203) -#define LOG_VOL_PART_HEADER_SIZE (4) +#define LOG_VOL_STATISTICS (0x17) +#define LOG_VOL_USED_CAPACITY (0x203) +#define LOG_VOL_PART_HEADER_SIZE (4) int iokit_get_eod_status(void *device, int part) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; /* * This feature requires new tape drive firmware @@ -3554,7 +3461,7 @@ int iokit_get_eod_status(void *device, int part) unsigned char buf[16]; unsigned int i; uint32_t param_size; - uint32_t part_cap[2] = {EOD_UNKNOWN, EOD_UNKNOWN}; + uint32_t part_cap[2] = { EOD_UNKNOWN, EOD_UNKNOWN }; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_GETEODSTAT)); @@ -3567,8 +3474,8 @@ int iokit_get_eod_status(void *device, int part) } /* Parse Approximate used native capacity of partitions (0x203)*/ - if (_parse_logPage(logdata, (uint16_t)VOLSTATS_PART_USED_CAP, ¶m_size, buf, sizeof(buf)) - || (param_size != sizeof(buf) ) ) { + if (_parse_logPage(logdata, (uint16_t)VOLSTATS_PART_USED_CAP, ¶m_size, buf, sizeof(buf)) || + (param_size != sizeof(buf))) { ltfsmsg(LTFS_WARN, 30841W); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_GETEODSTAT)); return EOD_UNKNOWN; @@ -3580,13 +3487,11 @@ int iokit_get_eod_status(void *device, int part) uint16_t part_buf; len = buf[i]; - part_buf = (uint16_t)(buf[i + 2] << 8) + (uint16_t) buf[i + 3]; + part_buf = (uint16_t)(buf[i + 2] << 8) + (uint16_t)buf[i + 3]; /* actual length - 1 is stored into len */ - if ( (len - LOG_VOL_PART_HEADER_SIZE + 1) == sizeof(uint32_t) && part_buf < 2) { - part_cap[part_buf] = ((uint32_t) buf[i + 4] << 24) + - ((uint32_t) buf[i + 5] << 16) + - ((uint32_t) buf[i + 6] << 8) + - (uint32_t) buf[i + 7]; + if ((len - LOG_VOL_PART_HEADER_SIZE + 1) == sizeof(uint32_t) && part_buf < 2) { + part_cap[part_buf] = ((uint32_t)buf[i + 4] << 24) + ((uint32_t)buf[i + 5] << 16) + ((uint32_t)buf[i + 6] << 8) + + (uint32_t)buf[i + 7]; } else ltfsmsg(LTFS_WARN, 30842W, i, part_buf, len); @@ -3594,7 +3499,7 @@ int iokit_get_eod_status(void *device, int part) } /* Create return value */ - if(part_cap[part] == 0xFFFFFFFF) + if (part_cap[part] == 0xFFFFFFFF) ret = EOD_MISSING; else ret = EOD_GOOD; @@ -3609,16 +3514,14 @@ static const char *_generate_product_name(const char *product_id) int i = 0; for (i = 0; ibm_supported_drives[i]; ++i) { - if (strncmp(ibm_supported_drives[i]->product_id, product_id, - strlen(ibm_supported_drives[i]->product_id)) == 0) { + if (strncmp(ibm_supported_drives[i]->product_id, product_id, strlen(ibm_supported_drives[i]->product_id)) == 0) { product_name = ibm_supported_drives[i]->product_name; break; } } for (i = 0; hp_supported_drives[i]; ++i) { - if (strncmp(hp_supported_drives[i]->product_id, product_id, - strlen(hp_supported_drives[i]->product_id)) == 0) { + if (strncmp(hp_supported_drives[i]->product_id, product_id, strlen(hp_supported_drives[i]->product_id)) == 0) { product_name = hp_supported_drives[i]->product_name; break; } @@ -3634,19 +3537,18 @@ int iokit_get_device_list(struct tc_drive_info *buf, int count) int32_t devs = iokit_get_ssc_device_count(); int drive_type; scsi_device_identifier identifier; - struct iokit_device *iokit_device; // Pointer to device status structure + struct iokit_device *iokit_device; // Pointer to device status structure iokit_device = malloc(sizeof(struct iokit_device)); - if(iokit_device == NULL) { + if (iokit_device == NULL) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -EDEV_NO_MEMORY; } memset(iokit_device, 0, sizeof(struct iokit_device)); - if( devs > 0 ) { + if (devs > 0) { for (i = 0; i < devs; i++) { - if(iokit_find_ssc_device(iokit_device, i) != 0) - { + if (iokit_find_ssc_device(iokit_device, i) != 0) { ret = -EDEV_DEVICE_UNOPENABLE; continue; } @@ -3658,12 +3560,12 @@ int iokit_get_device_list(struct tc_drive_info *buf, int count) snprintf(buf[i].model, TAPE_MODEL_NAME_LEN_MAX, "%s", identifier.product_id); snprintf(buf[i].serial_number, TAPE_SERIAL_LEN_MAX, "%s", identifier.unit_serial); snprintf(buf[i].product_name, PRODUCT_NAME_LENGTH, "%s", _generate_product_name(identifier.product_id)); - buf[i].host = 0; + buf[i].host = 0; buf[i].channel = 0; - buf[i].target = 0; - buf[i].lun = -1; + buf[i].target = 0; + buf[i].lun = -1; } - found ++; + found++; } ret = iokit_free_device(iokit_device); } @@ -3679,7 +3581,7 @@ void iokit_help_message(const char *progname) int iokit_parse_opts(void *device, void *opt_args) { - struct fuse_args *args = (struct fuse_args *) opt_args; + struct fuse_args *args = (struct fuse_args *)opt_args; int ret; CHECK_ARG_NULL(device, -LTFS_NULL_ARG); @@ -3712,10 +3614,10 @@ const char *iokit_default_device_name(void) return devname; } -static int _cdb_spin(void *device, const uint16_t sps, unsigned char **buffer, size_t * const size) +static int _cdb_spin(void *device, const uint16_t sps, unsigned char **buffer, size_t *const size) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; struct iokit_scsi_request req; unsigned char cdb[CDB12_LEN]; @@ -3729,7 +3631,7 @@ static int _cdb_spin(void *device, const uint16_t sps, unsigned char **buffer, s memset(&req, 0, sizeof(struct iokit_scsi_request)); *buffer = calloc(len, sizeof(unsigned char)); - if (! *buffer) { + if (!*buffer) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -EDEV_NO_MEMORY; } @@ -3741,22 +3643,21 @@ static int _cdb_spin(void *device, const uint16_t sps, unsigned char **buffer, s ltfs_u32tobe(cdb + 6, len); timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_TARGET_TO_INITIATOR; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.dxfer_len = len; - req.dxferp = *buffer; - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.dxfer_len = len; + req.dxferp = *buffer; + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(timeout); - req.desc = cmd_desc; + req.timeout = IOKitConversion(timeout); + req.desc = cmd_desc; ret = iokit_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { _process_errors(device, ret, msg, cmd_desc, true); } @@ -3765,11 +3666,10 @@ static int _cdb_spin(void *device, const uint16_t sps, unsigned char **buffer, s return ret; } -int _cdb_spout(void *device, const uint16_t sps, - unsigned char* const buffer, const size_t size) +int _cdb_spout(void *device, const uint16_t sps, unsigned char *const buffer, const size_t size) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; struct iokit_scsi_request req; unsigned char cdb[CDB12_LEN]; @@ -3788,36 +3688,46 @@ int _cdb_spout(void *device, const uint16_t sps, ltfs_u32tobe(cdb + 6, size); timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_INITIATOR_TO_TARGET; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.dxfer_len = size; - req.dxferp = buffer; - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.dxfer_len = size; + req.dxferp = buffer; + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(timeout); - req.desc = cmd_desc; + req.timeout = IOKitConversion(timeout); + req.desc = cmd_desc; ret = iokit_issue_cdb_command(&priv->dev, &req, &msg); - if (ret < 0){ + if (ret < 0) { _process_errors(device, ret, msg, cmd_desc, true); } return ret; } -static void ltfsmsg_keyalias(const char * const title, const unsigned char * const keyalias) +static void ltfsmsg_keyalias(const char *const title, const unsigned char *const keyalias) { - char s[128] = {'\0'}; + char s[128] = { '\0' }; if (keyalias) - sprintf(s, "keyalias = %c%c%c%02X%02X%02X%02X%02X%02X%02X%02X%02X", keyalias[0], - keyalias[1], keyalias[2], keyalias[3], keyalias[4], keyalias[5], keyalias[6], - keyalias[7], keyalias[8], keyalias[9], keyalias[10], keyalias[11]); + sprintf(s, + "keyalias = %c%c%c%02X%02X%02X%02X%02X%02X%02X%02X%02X", + keyalias[0], + keyalias[1], + keyalias[2], + keyalias[3], + keyalias[4], + keyalias[5], + keyalias[6], + keyalias[7], + keyalias[8], + keyalias[9], + keyalias[10], + keyalias[11]); else sprintf(s, "keyalias: NULL"); @@ -3826,18 +3736,18 @@ static void ltfsmsg_keyalias(const char * const title, const unsigned char * con static bool is_ame(void *device) { - unsigned char buf[TC_MP_READ_WRITE_CTRL_SIZE] = {0}; + unsigned char buf[TC_MP_READ_WRITE_CTRL_SIZE] = { 0 }; const int ret = iokit_modesense(device, TC_MP_READ_WRITE_CTRL, TC_MP_PC_CURRENT, 0, buf, sizeof(buf)); if (ret != 0) { - char message[100] = {0}; + char message[100] = { 0 }; sprintf(message, "failed to get MP %02Xh (%d)", TC_MP_READ_WRITE_CTRL, ret); ltfsmsg(LTFS_DEBUG, 30992D, __FUNCTION__, message); return false; /* Consider that the encryption method is not AME */ } else { const unsigned char encryption_method = buf[16 + 27]; - char message[100] = {0}; + char message[100] = { 0 }; char *method = NULL; switch (encryption_method) { case 0x00: @@ -3877,15 +3787,14 @@ static bool is_ame(void *device) static int is_encryption_capable(void *device) { - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; if (IS_LTO(priv->drive_type)) { ltfsmsg(LTFS_ERR, 30845E, priv->drive_type); return -EDEV_INTERNAL_ERROR; } - if (! is_ame(device)) - return -EDEV_INTERNAL_ERROR; + if (!is_ame(device)) return -EDEV_INTERNAL_ERROR; return DEVICE_GOOD; } @@ -3893,7 +3802,7 @@ static int is_encryption_capable(void *device) int iokit_set_key(void *device, const unsigned char *keyalias, const unsigned char *key) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; /* * Encryption Decryption Key DKi keyalias @@ -3911,16 +3820,15 @@ int iokit_set_key(void *device, const unsigned char *keyalias, const unsigned ch const uint16_t sps = 0x10; const size_t size = keyalias ? 20 + DK_LENGTH + 4 + DKI_LENGTH : 20; uint8_t *buffer = calloc(size, sizeof(uint8_t)); - if (! buffer) { + if (!buffer) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); ret = -EDEV_NO_MEMORY; goto out; } - unsigned char buf[TC_MP_READ_WRITE_CTRL_SIZE] = {0}; + unsigned char buf[TC_MP_READ_WRITE_CTRL_SIZE] = { 0 }; ret = iokit_modesense(device, TC_MP_READ_WRITE_CTRL, TC_MP_PC_CURRENT, 0, buf, sizeof(buf)); - if (ret != DEVICE_GOOD) - goto out; + if (ret != DEVICE_GOOD) goto out; ltfs_u16tobe(buffer + 0, sps); ltfs_u16tobe(buffer + 2, size - 4); @@ -3936,38 +3844,44 @@ int iokit_set_key(void *device, const unsigned char *keyalias, const unsigned ch * CKORL: 0b Clear key on reservation loss (CKORL) bit */ buffer[5] = 0x00; - enum { DISABLE = 0, EXTERNAL = 1, ENCRYPT = 2 }; + enum + { + DISABLE = 0, + EXTERNAL = 1, + ENCRYPT = 2 + }; buffer[6] = keyalias ? ENCRYPT : DISABLE; /* ENCRYPTION MODE */ - enum { /* DISABLE = 0, */ RAW = 1, DECRYPT = 2, MIXED = 3 }; - buffer[7] = keyalias ? MIXED : DISABLE; /* DECRYPTION MODE */ - buffer[8] = 1; /* ALGORITHM INDEX */ - buffer[9] = 0; /* LOGICAL BLOCK ENCRYPTION KEY FORMAT: plain-text key */ - buffer[10] = 0; /* KAD FORMAT: Unspecified */ + enum + { /* DISABLE = 0, */ RAW = 1, + DECRYPT = 2, + MIXED = 3 }; + buffer[7] = keyalias ? MIXED : DISABLE; /* DECRYPTION MODE */ + buffer[8] = 1; /* ALGORITHM INDEX */ + buffer[9] = 0; /* LOGICAL BLOCK ENCRYPTION KEY FORMAT: plain-text key */ + buffer[10] = 0; /* KAD FORMAT: Unspecified */ ltfs_u16tobe(buffer + 18, keyalias ? DK_LENGTH : 0x00); /* LOGICAL BLOCK ENCRYPTION KEY LENGTH */ if (keyalias) { - if (! key) { + if (!key) { ret = -EINVAL; goto free; } memcpy(buffer + 20, key, DK_LENGTH); /* LOGICAL BLOCK ENCRYPTION KEY */ - buffer[20 + DK_LENGTH] = 0x01; /* KEY DESCRIPTOR TYPE: 01h DKi (Data Key Identifier) */ + buffer[20 + DK_LENGTH] = 0x01; /* KEY DESCRIPTOR TYPE: 01h DKi (Data Key Identifier) */ ltfs_u16tobe(buffer + 20 + DK_LENGTH + 2, DKI_LENGTH); memcpy(buffer + 20 + 0x20 + 4, keyalias, DKI_LENGTH); } - const char * const title = "set key:"; + const char *const title = "set key:"; ltfsmsg_keyalias(title, keyalias); ret = _cdb_spout(device, sps, buffer, size); - if (ret != DEVICE_GOOD) - goto free; + if (ret != DEVICE_GOOD) goto free; priv->dev.is_data_key_set = keyalias != NULL; memset(buf, 0, sizeof(buf)); ret = iokit_modesense(device, TC_MP_READ_WRITE_CTRL, TC_MP_PC_CURRENT, 0, buf, sizeof(buf)); - if (ret != DEVICE_GOOD) - goto out; + if (ret != DEVICE_GOOD) goto out; free: free(buffer); @@ -3977,27 +3891,26 @@ int iokit_set_key(void *device, const unsigned char *keyalias, const unsigned ch return ret; } -static void show_hex_dump(const char * const title, const uint8_t * const buf, const size_t size) +static void show_hex_dump(const char *const title, const uint8_t *const buf, const size_t size) { /* * " 1 2 3 4 5 6 7 8" * "12345678901234567890123456789012345678901234567890123456789012345678901234567890" * "xxxxxx 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF\n" < 100 */ - char * const s = calloc((size / 0x10 + 1) * 100, sizeof(char)); + char *const s = calloc((size / 0x10 + 1) * 100, sizeof(char)); char *p = s; uint i = 0; int j = 0; int k = 0; - if (p == NULL) - return; + if (p == NULL) return; for (i = 0; i < size; ++i) { if (i % 0x10 == 0) { if (i) { for (j = 0x10; 0 < j; --j) { - p += sprintf(p, "%c", isprint(buf[i-j]) ? buf[i-j] : '.'); + p += sprintf(p, "%c", isprint(buf[i - j]) ? buf[i - j] : '.'); } } p += sprintf(p, "\n%06X ", i); @@ -4008,7 +3921,7 @@ static void show_hex_dump(const char * const title, const uint8_t * const buf, c p += sprintf(p, " %s", (i + k) % 8 == 7 ? " " : ""); } for (j = 0x10 - k; 0 < j; --j) { - p += sprintf(p, "%c", isprint(buf[i-j]) ? buf[i-j] : '.'); + p += sprintf(p, "%c", isprint(buf[i - j]) ? buf[i - j] : '.'); } ltfsmsg(LTFS_DEBUG, 30992D, title, s); @@ -4017,7 +3930,7 @@ static void show_hex_dump(const char * const title, const uint8_t * const buf, c int iokit_get_keyalias(void *device, unsigned char **keyalias) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_GETKEYALIAS)); ret = is_encryption_capable(device); @@ -4041,32 +3954,32 @@ int iokit_get_keyalias(void *device, unsigned char **keyalias) for (i = 0; i < 2; ++i) { free(buffer); ret = _cdb_spin(device, sps, &buffer, &size); - if (ret != DEVICE_GOOD) - goto free; + if (ret != DEVICE_GOOD) goto free; } show_hex_dump("SPIN:", buffer, size + 4); const unsigned char encryption_status = buffer[12] & 0xF; - enum { - ENC_STAT_INCAPABLE = 0, - ENC_STAT_NOT_YET_BEEN_READ = 1, - ENC_STAT_NOT_A_LOGICAL_BLOCK = 2, - ENC_STAT_NOT_ENCRYPTED = 3, + enum + { + ENC_STAT_INCAPABLE = 0, + ENC_STAT_NOT_YET_BEEN_READ = 1, + ENC_STAT_NOT_A_LOGICAL_BLOCK = 2, + ENC_STAT_NOT_ENCRYPTED = 3, ENC_STAT_ENCRYPTED_BY_UNSUPPORTED_ALGORITHM = 4, - ENC_STAT_ENCRYPTED_BY_SUPPORTED_ALGORITHM = 5, - ENC_STAT_ENCRYPTED_BY_OTHER_KEY = 6, + ENC_STAT_ENCRYPTED_BY_SUPPORTED_ALGORITHM = 5, + ENC_STAT_ENCRYPTED_BY_OTHER_KEY = 6, ENC_STAT_RESERVED, /* 7h-Fh */ }; if (encryption_status == ENC_STAT_ENCRYPTED_BY_UNSUPPORTED_ALGORITHM || - encryption_status == ENC_STAT_ENCRYPTED_BY_SUPPORTED_ALGORITHM || - encryption_status == ENC_STAT_ENCRYPTED_BY_OTHER_KEY) { + encryption_status == ENC_STAT_ENCRYPTED_BY_SUPPORTED_ALGORITHM || + encryption_status == ENC_STAT_ENCRYPTED_BY_OTHER_KEY) { uint offset = 16; /* offset of key descriptor */ while (offset <= size && buffer[offset] != 1) { offset += ltfs_betou16(buffer + offset + 2) + 4; } if (offset <= size && buffer[offset] == 1) { - const uint dki_length = ((int) buffer[offset + 2]) << 8 | buffer[offset + 3]; + const uint dki_length = ((int)buffer[offset + 2]) << 8 | buffer[offset + 3]; if (offset + dki_length <= size) { int n = dki_length < sizeof(priv->dki) ? dki_length : sizeof(priv->dki); memcpy(priv->dki, &buffer[offset + 4], n); @@ -4075,7 +3988,7 @@ int iokit_get_keyalias(void *device, unsigned char **keyalias) } } - const char * const title = "get key-alias:"; + const char *const title = "get key-alias:"; ltfsmsg_keyalias(title, priv->dki); free: @@ -4087,7 +4000,7 @@ int iokit_get_keyalias(void *device, unsigned char **keyalias) int iokit_takedump_drive(void *device, bool capture_unforced) { - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_TAKEDUMPDRV)); _take_dump(priv, capture_unforced); @@ -4096,19 +4009,14 @@ int iokit_takedump_drive(void *device, bool capture_unforced) return 0; } -int iokit_is_mountable(void *device, const char *barcode, const unsigned char cart_type, - const unsigned char density) +int iokit_is_mountable(void *device, const char *barcode, const unsigned char cart_type, const unsigned char density) { int ret; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_ISMOUNTABLE)); - ret = ibm_tape_is_mountable( priv->drive_type, - barcode, - cart_type, - density, - global_data.strict_drive); + ret = ibm_tape_is_mountable(priv->drive_type, barcode, cart_type, density, global_data.strict_drive); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_ISMOUNTABLE)); @@ -4118,13 +4026,9 @@ int iokit_is_mountable(void *device, const char *barcode, const unsigned char ca bool iokit_is_readonly(void *device) { int ret; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; - ret = ibm_tape_is_mountable( priv->drive_type, - NULL, - priv->cart_type, - priv->density_code, - global_data.strict_drive); + ret = ibm_tape_is_mountable(priv->drive_type, NULL, priv->cart_type, priv->density_code, global_data.strict_drive); if (ret == MEDIUM_READONLY) return true; @@ -4135,7 +4039,7 @@ bool iokit_is_readonly(void *device) int iokit_get_worm_status(void *device, bool *is_worm) { int rc = 0; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_GETWORMSTAT)); if (priv->loaded) { @@ -4152,15 +4056,15 @@ int iokit_get_worm_status(void *device, bool *is_worm) int iokit_get_serialnumber(void *device, char **result) { - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; CHECK_ARG_NULL(device, -LTFS_NULL_ARG); CHECK_ARG_NULL(result, -LTFS_NULL_ARG); ltfs_profiler_add_entry(priv->profiler, NULL, CHANGER_REQ_ENTER(REQ_TC_GETSER)); - *result = strdup((const char *) priv->drive_serial); - if (! *result) { + *result = strdup((const char *)priv->drive_serial); + if (!*result) { ltfsmsg(LTFS_ERR, 10001E, "iokit_get_serialnumber: result"); ltfs_profiler_add_entry(priv->profiler, NULL, CHANGER_REQ_EXIT(REQ_TC_GETSER)); return -EDEV_NO_MEMORY; @@ -4173,7 +4077,7 @@ int iokit_get_serialnumber(void *device, char **result) int iokit_get_info(void *device, struct tc_drive_info *info) { - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; memcpy(info, &priv->info, sizeof(struct tc_drive_info)); @@ -4183,21 +4087,18 @@ int iokit_get_info(void *device, struct tc_drive_info *info) int iokit_set_profiler(void *device, char *work_dir, bool enable) { int rc = 0; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; char *path; FILE *p; struct timer_info timerinfo; if (enable) { - if (priv->profiler) - return 0; + if (priv->profiler) return 0; - if(!work_dir) - return -LTFS_BAD_ARG; + if (!work_dir) return -LTFS_BAD_ARG; - rc = asprintf(&path, "%s/%s%s%s", work_dir, DRIVER_PROFILER_BASE, - "DUMMY", PROFILER_EXTENSION); + rc = asprintf(&path, "%s/%s%s%s", work_dir, DRIVER_PROFILER_BASE, "DUMMY", PROFILER_EXTENSION); if (rc < 0) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -EDEV_NO_MEMORY; @@ -4207,11 +4108,11 @@ int iokit_set_profiler(void *device, char *work_dir, bool enable) free(path); - if (! p) + if (!p) rc = -LTFS_FILE_ERR; else { get_timer_info(&timerinfo); - fwrite((void*)&timerinfo, sizeof(timerinfo), 1, p); + fwrite((void *)&timerinfo, sizeof(timerinfo), 1, p); priv->profiler = p; rc = 0; } @@ -4228,7 +4129,7 @@ int iokit_set_profiler(void *device, char *work_dir, bool enable) int iokit_get_next_block_to_xfer(void *device, struct tc_position *pos) { int ret = -EDEV_UNKNOWN; - struct iokit_data *priv = (struct iokit_data*)device; + struct iokit_data *priv = (struct iokit_data *)device; struct iokit_scsi_request req; unsigned char cdb[CDB10_LEN]; @@ -4247,31 +4148,35 @@ int iokit_get_next_block_to_xfer(void *device, struct tc_position *pos) /* Build CDB */ cdb[0] = READ_POSITION; - cdb[1] = 0x08; /* Extended Format */ + cdb[1] = 0x08; /* Extended Format */ ltfs_u16tobe(cdb + 7, sizeof(buf)); /* allocation length */ timeout = get_timeout(priv->timeouts, cdb[0]); - if (timeout < 0) - return -EDEV_UNSUPPORETD_COMMAND; + if (timeout < 0) return -EDEV_UNSUPPORETD_COMMAND; /* Build request */ req.dxfer_direction = SCSI_FROM_TARGET_TO_INITIATOR; - req.cmd_len = sizeof(cdb); - req.mx_sb_len = sizeof(SCSI_Sense_Data); - req.dxfer_len = sizeof(buf); - req.dxferp = buf; - req.cmdp = cdb; + req.cmd_len = sizeof(cdb); + req.mx_sb_len = sizeof(SCSI_Sense_Data); + req.dxfer_len = sizeof(buf); + req.dxferp = buf; + req.cmdp = cdb; memset(&req.sense_buffer, 0, req.mx_sb_len); - req.timeout = IOKitConversion(timeout); - req.desc = cmd_desc; + req.timeout = IOKitConversion(timeout); + req.desc = cmd_desc; ret = iokit_issue_cdb_command(&priv->dev, &req, &msg); if (ret == DEVICE_GOOD) { pos->partition = (tape_partition_t)buf[1]; - pos->block = ltfs_betou64(buf + 16); - - ltfsmsg(LTFS_DEBUG, 30998D, "next-block-to-xfer", - (unsigned long long)pos->partition, (unsigned long long)pos->block, (unsigned long long)0, priv->drive_serial); + pos->block = ltfs_betou64(buf + 16); + + ltfsmsg(LTFS_DEBUG, + 30998D, + "next-block-to-xfer", + (unsigned long long)pos->partition, + (unsigned long long)pos->block, + (unsigned long long)0, + priv->drive_serial); } else { _process_errors(device, ret, msg, cmd_desc, true); } @@ -4282,71 +4187,69 @@ int iokit_get_next_block_to_xfer(void *device, struct tc_position *pos) } struct tape_ops iokit_handler = { - .open = iokit_open, - .reopen = iokit_reopen, - .close = iokit_close, - .close_raw = iokit_close_raw, - .is_connected = iokit_is_connected, - .inquiry = iokit_inquiry, - .inquiry_page = iokit_inquiry_page, - .test_unit_ready = iokit_test_unit_ready, - .read = iokit_read, - .write = iokit_write, - .writefm = iokit_writefm, - .rewind = iokit_rewind, - .locate = iokit_locate, - .space = iokit_space, - .erase = iokit_erase, - .load = iokit_load, - .unload = iokit_unload, - .readpos = iokit_readpos, - .setcap = iokit_setcap, - .format = iokit_format, - .remaining_capacity = iokit_remaining_capacity, - .logsense = iokit_logsense, - .modesense = iokit_modesense, - .modeselect = iokit_modeselect, - .reserve_unit = iokit_reserve, - .release_unit = iokit_release, + .open = iokit_open, + .reopen = iokit_reopen, + .close = iokit_close, + .close_raw = iokit_close_raw, + .is_connected = iokit_is_connected, + .inquiry = iokit_inquiry, + .inquiry_page = iokit_inquiry_page, + .test_unit_ready = iokit_test_unit_ready, + .read = iokit_read, + .write = iokit_write, + .writefm = iokit_writefm, + .rewind = iokit_rewind, + .locate = iokit_locate, + .space = iokit_space, + .erase = iokit_erase, + .load = iokit_load, + .unload = iokit_unload, + .readpos = iokit_readpos, + .setcap = iokit_setcap, + .format = iokit_format, + .remaining_capacity = iokit_remaining_capacity, + .logsense = iokit_logsense, + .modesense = iokit_modesense, + .modeselect = iokit_modeselect, + .reserve_unit = iokit_reserve, + .release_unit = iokit_release, .prevent_medium_removal = iokit_prevent_medium_removal, - .allow_medium_removal = iokit_allow_medium_removal, - .write_attribute = iokit_write_attribute, - .read_attribute = iokit_read_attribute, - .allow_overwrite = iokit_allow_overwrite, - .grao = iokit_grao, - .rrao = iokit_rrao, + .allow_medium_removal = iokit_allow_medium_removal, + .write_attribute = iokit_write_attribute, + .read_attribute = iokit_read_attribute, + .allow_overwrite = iokit_allow_overwrite, + .grao = iokit_grao, + .rrao = iokit_rrao, // May be command combination - .set_compression = iokit_set_compression, - .set_default = iokit_set_default, - .get_cartridge_health = iokit_get_cartridge_health, - .get_tape_alert = iokit_get_tape_alert, - .clear_tape_alert = iokit_clear_tape_alert, - .get_xattr = iokit_get_xattr, - .set_xattr = iokit_set_xattr, - .get_parameters = iokit_get_parameters, - .get_eod_status = iokit_get_eod_status, - .get_device_list = iokit_get_device_list, - .help_message = iokit_help_message, - .parse_opts = iokit_parse_opts, - .default_device_name = iokit_default_device_name, - .set_key = iokit_set_key, - .get_keyalias = iokit_get_keyalias, - .takedump_drive = iokit_takedump_drive, - .is_mountable = iokit_is_mountable, - .get_worm_status = iokit_get_worm_status, - .get_serialnumber = iokit_get_serialnumber, - .get_info = iokit_get_info, - .set_profiler = iokit_set_profiler, + .set_compression = iokit_set_compression, + .set_default = iokit_set_default, + .get_cartridge_health = iokit_get_cartridge_health, + .get_tape_alert = iokit_get_tape_alert, + .clear_tape_alert = iokit_clear_tape_alert, + .get_xattr = iokit_get_xattr, + .set_xattr = iokit_set_xattr, + .get_parameters = iokit_get_parameters, + .get_eod_status = iokit_get_eod_status, + .get_device_list = iokit_get_device_list, + .help_message = iokit_help_message, + .parse_opts = iokit_parse_opts, + .default_device_name = iokit_default_device_name, + .set_key = iokit_set_key, + .get_keyalias = iokit_get_keyalias, + .takedump_drive = iokit_takedump_drive, + .is_mountable = iokit_is_mountable, + .get_worm_status = iokit_get_worm_status, + .get_serialnumber = iokit_get_serialnumber, + .get_info = iokit_get_info, + .set_profiler = iokit_set_profiler, .get_next_block_to_xfer = iokit_get_next_block_to_xfer, - .is_readonly = iokit_is_readonly, + .is_readonly = iokit_is_readonly, }; struct tape_ops *tape_dev_get_ops(void) { - if (!standard_table) - standard_table = standard_tape_errors; - if (!vendor_table) - vendor_table = ibm_tape_errors; + if (!standard_table) standard_table = standard_tape_errors; + if (!vendor_table) vendor_table = ibm_tape_errors; return &iokit_handler; } diff --git a/src/tape_drivers/quantum_tape.c b/src/tape_drivers/quantum_tape.c index a5c477dd..0ac82f79 100644 --- a/src/tape_drivers/quantum_tape.c +++ b/src/tape_drivers/quantum_tape.c @@ -47,26 +47,26 @@ ************************************************************************************* */ #ifndef mingw_PLATFORM -#if defined (__FreeBSD__) || defined(__NetBSD__) -#include -#include -#include -#endif /* __FreeBSD__ */ -#include -#include -#include +# if defined(__FreeBSD__) || defined(__NetBSD__) +# include +# include +# include +# endif /* __FreeBSD__ */ +# include +# include +# include -#define LOOP_BACK_DEVICE "lo" +# define LOOP_BACK_DEVICE "lo" #endif #include "tape_drivers/quantum_tape.h" #include "libltfs/ltfs_endian.h" struct supported_device *quantum_supported_drives[] = { - TAPEDRIVE( QUANTUM_VENDOR_ID, "ULTRIUM-HH5", DRIVE_LTO5_HH, "[ULTRIUM-HH5]" ), /* QUANTUM Ultrium Gen 5 Half-High */ - TAPEDRIVE( QUANTUM_VENDOR_ID, "ULTRIUM-HH6", DRIVE_LTO6_HH, "[ULTRIUM-HH6]" ), /* QUANTUM Ultrium Gen 6 Half-High */ - TAPEDRIVE( QUANTUM_VENDOR_ID, "ULTRIUM-HH7", DRIVE_LTO7_HH, "[ULTRIUM-HH7]" ), /* QUANTUM Ultrium Gen 7 Half-High */ - TAPEDRIVE( QUANTUM_VENDOR_ID, "ULTRIUM-HH8", DRIVE_LTO8_HH, "[ULTRIUM-HH8]" ), /* QUANTUM Ultrium Gen 8 Half-High */ + TAPEDRIVE(QUANTUM_VENDOR_ID, "ULTRIUM-HH5", DRIVE_LTO5_HH, "[ULTRIUM-HH5]"), /* QUANTUM Ultrium Gen 5 Half-High */ + TAPEDRIVE(QUANTUM_VENDOR_ID, "ULTRIUM-HH6", DRIVE_LTO6_HH, "[ULTRIUM-HH6]"), /* QUANTUM Ultrium Gen 6 Half-High */ + TAPEDRIVE(QUANTUM_VENDOR_ID, "ULTRIUM-HH7", DRIVE_LTO7_HH, "[ULTRIUM-HH7]"), /* QUANTUM Ultrium Gen 7 Half-High */ + TAPEDRIVE(QUANTUM_VENDOR_ID, "ULTRIUM-HH8", DRIVE_LTO8_HH, "[ULTRIUM-HH8]"), /* QUANTUM Ultrium Gen 8 Half-High */ /* End of supported_devices */ NULL }; @@ -74,228 +74,213 @@ struct supported_device *quantum_supported_drives[] = { /* Quantum LTO tape drive vendor unique sense table */ struct error_table quantum_tape_errors[] = { /* Sense Key 0 (No Sense) */ - {0x008282, -EDEV_CLEANING_REQUIRED, "QUANTUM LTO - Cleaning Required"}, + { 0x008282, -EDEV_CLEANING_REQUIRED, "QUANTUM LTO - Cleaning Required" }, /* Sense Key 1 (Recoverd Error) */ - {0x018252, -EDEV_DEGRADED_MEDIA, "QUANTUM LTO - Degraded Media"}, - {0x018383, -EDEV_RECOVERED_ERROR, "Drive Has Been Cleaned"}, - {0x018500, -EDEV_RECOVERED_ERROR, "Search Match List Limit (warning)"}, - {0x018501, -EDEV_RECOVERED_ERROR, "Search Snoop Match Found"}, + { 0x018252, -EDEV_DEGRADED_MEDIA, "QUANTUM LTO - Degraded Media" }, + { 0x018383, -EDEV_RECOVERED_ERROR, "Drive Has Been Cleaned" }, + { 0x018500, -EDEV_RECOVERED_ERROR, "Search Match List Limit (warning)" }, + { 0x018501, -EDEV_RECOVERED_ERROR, "Search Snoop Match Found" }, /* Sense Key 3 (Medium Error) */ - {0x038500, -EDEV_DATA_PROTECT, "Write Protected Because of Tape or Drive Failure"}, - {0x038501, -EDEV_DATA_PROTECT, "Write Protected Because of Tape Failure"}, - {0x038502, -EDEV_DATA_PROTECT, "Write Protected Because of Drive Failure"}, + { 0x038500, -EDEV_DATA_PROTECT, "Write Protected Because of Tape or Drive Failure" }, + { 0x038501, -EDEV_DATA_PROTECT, "Write Protected Because of Tape Failure" }, + { 0x038502, -EDEV_DATA_PROTECT, "Write Protected Because of Drive Failure" }, /* Sense Key 5 (Illegal Request) */ - {0x058000, -EDEV_ILLEGAL_REQUEST, "CU Mode, Vendor-Unique"}, - {0x058283, -EDEV_ILLEGAL_REQUEST, "Bad Microcode Detected"}, - {0x058503, -EDEV_ILLEGAL_REQUEST, "Write Protected Because of Current Tape Position"}, - {0x05A301, -EDEV_ILLEGAL_REQUEST, "OEM Vendor-Specific"}, + { 0x058000, -EDEV_ILLEGAL_REQUEST, "CU Mode, Vendor-Unique" }, + { 0x058283, -EDEV_ILLEGAL_REQUEST, "Bad Microcode Detected" }, + { 0x058503, -EDEV_ILLEGAL_REQUEST, "Write Protected Because of Current Tape Position" }, + { 0x05A301, -EDEV_ILLEGAL_REQUEST, "OEM Vendor-Specific" }, /* Sense Key 6 (Unit Attention) */ - {0x065DFF, -EDEV_UNIT_ATTENTION, "Failure Prediction False"}, - {0x068283, -EDEV_UNIT_ATTENTION, "Drive Has Been Cleaned (older versions of microcode)"}, - {0x068500, -EDEV_UNIT_ATTENTION, "Search Match List Limit (alert)"}, + { 0x065DFF, -EDEV_UNIT_ATTENTION, "Failure Prediction False" }, + { 0x068283, -EDEV_UNIT_ATTENTION, "Drive Has Been Cleaned (older versions of microcode)" }, + { 0x068500, -EDEV_UNIT_ATTENTION, "Search Match List Limit (alert)" }, /* Crypto Related Sense Code */ - {0x044780, -EDEV_HARDWARE_ERROR, "QUANTUM LTO - Read Internal CRC Error"}, - {0x044781, -EDEV_HARDWARE_ERROR, "QUANTUM LTO - Write Internal CRC Error"}, + { 0x044780, -EDEV_HARDWARE_ERROR, "QUANTUM LTO - Read Internal CRC Error" }, + { 0x044781, -EDEV_HARDWARE_ERROR, "QUANTUM LTO - Write Internal CRC Error" }, /* END MARK*/ - {0xFFFFFF, -EDEV_UNKNOWN, "Unknown Error code"}, + { 0xFFFFFF, -EDEV_UNKNOWN, "Unknown Error code" }, }; #define DEFAULT_TIMEOUT (60) -struct _timeout_tape{ - int op_code; /**< SCSI op code */ - int timeout; /**< SCSI timeout */ +struct _timeout_tape +{ + int op_code; /**< SCSI op code */ + int timeout; /**< SCSI timeout */ }; /* Base timeout value for LTO */ -static struct _timeout_tape timeout_lto[] = { - { CHANGE_DEFINITION, -1 }, - { XCOPY, -1 }, - { INQUIRY, 60 }, - { LOG_SELECT, 60 }, - { LOG_SENSE, 60 }, - { MODE_SELECT6, 60 }, - { MODE_SELECT10, 60 }, - { MODE_SENSE6, 60 }, - { MODE_SENSE10, 60 }, - { PERSISTENT_RESERVE_IN, 60 }, - { PERSISTENT_RESERVE_OUT, 60 }, - { READ_ATTRIBUTE, 60 }, - { RECEIVE_DIAGNOSTIC_RESULTS, 60 }, - { RELEASE_UNIT6, 60 }, - { RELEASE_UNIT10, 60 }, - { REPORT_LUNS, 60 }, - { REQUEST_SENSE, 60 }, - { RESERVE_UNIT6, 60 }, - { RESERVE_UNIT10, 60 }, - { SPIN, 60 }, - { SPOUT, 60 }, - { TEST_UNIT_READY, 60 }, - { WRITE_ATTRIBUTE, 60 }, - { ALLOW_OVERWRITE, 60 }, - { DISPLAY_MESSAGE, -1 }, - { PREVENT_ALLOW_MEDIUM_REMOVAL, 60 }, - { READ_BLOCK_LIMITS, 60 }, - { READ_DYNAMIC_RUNTIME_ATTRIBUTE, 60 }, - { READ_POSITION, 60 }, - { READ_REVERSE, -1 }, - { RECOVER_BUFFERED_DATA, -1 }, - { REPORT_DENSITY_SUPPORT, 60 }, - { STRING_SEARCH, -1 }, - { WRITE_DYNAMIC_RUNTIME_ATTRIBUTE, 60 }, - {-1, -1} -}; +static struct _timeout_tape timeout_lto[] = { { CHANGE_DEFINITION, -1 }, + { XCOPY, -1 }, + { INQUIRY, 60 }, + { LOG_SELECT, 60 }, + { LOG_SENSE, 60 }, + { MODE_SELECT6, 60 }, + { MODE_SELECT10, 60 }, + { MODE_SENSE6, 60 }, + { MODE_SENSE10, 60 }, + { PERSISTENT_RESERVE_IN, 60 }, + { PERSISTENT_RESERVE_OUT, 60 }, + { READ_ATTRIBUTE, 60 }, + { RECEIVE_DIAGNOSTIC_RESULTS, 60 }, + { RELEASE_UNIT6, 60 }, + { RELEASE_UNIT10, 60 }, + { REPORT_LUNS, 60 }, + { REQUEST_SENSE, 60 }, + { RESERVE_UNIT6, 60 }, + { RESERVE_UNIT10, 60 }, + { SPIN, 60 }, + { SPOUT, 60 }, + { TEST_UNIT_READY, 60 }, + { WRITE_ATTRIBUTE, 60 }, + { ALLOW_OVERWRITE, 60 }, + { DISPLAY_MESSAGE, -1 }, + { PREVENT_ALLOW_MEDIUM_REMOVAL, 60 }, + { READ_BLOCK_LIMITS, 60 }, + { READ_DYNAMIC_RUNTIME_ATTRIBUTE, 60 }, + { READ_POSITION, 60 }, + { READ_REVERSE, -1 }, + { RECOVER_BUFFERED_DATA, -1 }, + { REPORT_DENSITY_SUPPORT, 60 }, + { STRING_SEARCH, -1 }, + { WRITE_DYNAMIC_RUNTIME_ATTRIBUTE, 60 }, + { -1, -1 } }; -static struct _timeout_tape timeout_lto5_hh[] = { - { ERASE, 19200 }, - { FORMAT_MEDIUM, 1980 }, - { LOAD_UNLOAD, 1020 }, - { LOCATE10, 2700 }, - { LOCATE16, 2700 }, - { READ, 1920 }, - { READ_BUFFER, 660 }, - { REWIND, 780 }, - { SEND_DIAGNOSTIC, 3120 }, - { SET_CAPACITY, 960 }, - { SPACE6, 2700 }, - { SPACE16, 2700 }, - { VERIFY, 19980 }, - { WRITE, 1920 }, - { WRITE_BUFFER, 720 }, - { WRITE_FILEMARKS6, 1740 }, - {-1, -1} -}; +static struct _timeout_tape timeout_lto5_hh[] = { { ERASE, 19200 }, + { FORMAT_MEDIUM, 1980 }, + { LOAD_UNLOAD, 1020 }, + { LOCATE10, 2700 }, + { LOCATE16, 2700 }, + { READ, 1920 }, + { READ_BUFFER, 660 }, + { REWIND, 780 }, + { SEND_DIAGNOSTIC, 3120 }, + { SET_CAPACITY, 960 }, + { SPACE6, 2700 }, + { SPACE16, 2700 }, + { VERIFY, 19980 }, + { WRITE, 1920 }, + { WRITE_BUFFER, 720 }, + { WRITE_FILEMARKS6, 1740 }, + { -1, -1 } }; -static struct _timeout_tape timeout_lto6_hh[] = { - { ERASE, 29400 }, - { FORMAT_MEDIUM, 3840 }, - { LOAD_UNLOAD, 1020 }, - { LOCATE10, 2700 }, - { LOCATE16, 2700 }, - { READ, 1920 }, - { READ_BUFFER, 660 }, - { REWIND, 780 }, - { SEND_DIAGNOSTIC, 3120 }, - { SET_CAPACITY, 960 }, - { SPACE6, 2700 }, - { SPACE16, 2700 }, - { VERIFY, 30000 }, - { WRITE, 1920 }, - { WRITE_BUFFER, 720 }, - { WRITE_FILEMARKS6, 1740 }, - {-1, -1} -}; +static struct _timeout_tape timeout_lto6_hh[] = { { ERASE, 29400 }, + { FORMAT_MEDIUM, 3840 }, + { LOAD_UNLOAD, 1020 }, + { LOCATE10, 2700 }, + { LOCATE16, 2700 }, + { READ, 1920 }, + { READ_BUFFER, 660 }, + { REWIND, 780 }, + { SEND_DIAGNOSTIC, 3120 }, + { SET_CAPACITY, 960 }, + { SPACE6, 2700 }, + { SPACE16, 2700 }, + { VERIFY, 30000 }, + { WRITE, 1920 }, + { WRITE_BUFFER, 720 }, + { WRITE_FILEMARKS6, 1740 }, + { -1, -1 } }; -static struct _timeout_tape timeout_lto7_hh[] = { - { ERASE, 27540 }, - { FORMAT_MEDIUM, 3240 }, - { LOAD_UNLOAD, 840 }, - { LOCATE10, 2940 }, - { LOCATE16, 2940 }, - { READ, 2340 }, - { READ_BUFFER, 480 }, - { REWIND, 660 }, - { SEND_DIAGNOSTIC, 2040 }, - { SET_CAPACITY, 960 }, - { SPACE6, 2940 }, - { SPACE16, 2940 }, - { VERIFY, 28860 }, - { WRITE, 1560 }, - { WRITE_BUFFER, 540 }, - { WRITE_FILEMARKS6, 1680 }, - {-1, -1} -}; +static struct _timeout_tape timeout_lto7_hh[] = { { ERASE, 27540 }, + { FORMAT_MEDIUM, 3240 }, + { LOAD_UNLOAD, 840 }, + { LOCATE10, 2940 }, + { LOCATE16, 2940 }, + { READ, 2340 }, + { READ_BUFFER, 480 }, + { REWIND, 660 }, + { SEND_DIAGNOSTIC, 2040 }, + { SET_CAPACITY, 960 }, + { SPACE6, 2940 }, + { SPACE16, 2940 }, + { VERIFY, 28860 }, + { WRITE, 1560 }, + { WRITE_BUFFER, 540 }, + { WRITE_FILEMARKS6, 1680 }, + { -1, -1 } }; -static struct _timeout_tape timeout_lto8_hh[] = { - { ERASE, 46380 }, - { FORMAT_MEDIUM, 3240 }, - { LOAD_UNLOAD, 840 }, - { LOCATE10, 2940 }, - { LOCATE16, 2940 }, - { READ, 2340 }, - { READ_BUFFER, 480 }, - { REWIND, 660 }, - { SEND_DIAGNOSTIC, 2040 }, - { SET_CAPACITY, 960 }, - { SPACE6, 2940 }, - { SPACE16, 2940 }, - { VERIFY, 47700 }, - { WRITE, 1560 }, - { WRITE_BUFFER, 540 }, - { WRITE_FILEMARKS6, 1680 }, - {-1, -1} -}; +static struct _timeout_tape timeout_lto8_hh[] = { { ERASE, 46380 }, + { FORMAT_MEDIUM, 3240 }, + { LOAD_UNLOAD, 840 }, + { LOCATE10, 2940 }, + { LOCATE16, 2940 }, + { READ, 2340 }, + { READ_BUFFER, 480 }, + { REWIND, 660 }, + { SEND_DIAGNOSTIC, 2040 }, + { SET_CAPACITY, 960 }, + { SPACE6, 2940 }, + { SPACE16, 2940 }, + { VERIFY, 47700 }, + { WRITE, 1560 }, + { WRITE_BUFFER, 540 }, + { WRITE_FILEMARKS6, 1680 }, + { -1, -1 } }; -static struct _timeout_tape timeout_lto9_hh[] = { - { ERASE, 46380 }, - { FORMAT_MEDIUM, 3240 }, - { LOAD_UNLOAD, 840 }, - { LOCATE10, 2940 }, - { LOCATE16, 2940 }, - { READ, 2340 }, - { READ_BUFFER, 480 }, - { REWIND, 660 }, - { SEND_DIAGNOSTIC, 2040 }, - { SET_CAPACITY, 960 }, - { SPACE6, 2940 }, - { SPACE16, 2940 }, - { VERIFY, 47700 }, - { WRITE, 1560 }, - { WRITE_BUFFER, 540 }, - { WRITE_FILEMARKS6, 1680 }, - {-1, -1} -}; +static struct _timeout_tape timeout_lto9_hh[] = { { ERASE, 46380 }, + { FORMAT_MEDIUM, 3240 }, + { LOAD_UNLOAD, 840 }, + { LOCATE10, 2940 }, + { LOCATE16, 2940 }, + { READ, 2340 }, + { READ_BUFFER, 480 }, + { REWIND, 660 }, + { SEND_DIAGNOSTIC, 2040 }, + { SET_CAPACITY, 960 }, + { SPACE6, 2940 }, + { SPACE16, 2940 }, + { VERIFY, 47700 }, + { WRITE, 1560 }, + { WRITE_BUFFER, 540 }, + { WRITE_FILEMARKS6, 1680 }, + { -1, -1 } }; -static struct _timeout_tape timeout_lto10_hh[] = { - { ERASE, 166370 }, - { FORMAT_MEDIUM, 3240 }, - { LOAD_UNLOAD, 960 }, - { LOCATE10, 3940 }, - { LOCATE16, 3940 }, - { READ, 2340 }, - { READ_BUFFER, 480 }, - { REWIND, 600 }, - { SEND_DIAGNOSTIC, 2040 }, - { SET_CAPACITY, 960 }, - { SPACE6, 3940 }, - { SPACE16, 3940 }, - { VERIFY, 63300 }, - { WRITE, 1560 }, - { WRITE_BUFFER, 540 }, - { WRITE_FILEMARKS6, 1680 }, - {-1, -1} -}; +static struct _timeout_tape timeout_lto10_hh[] = { { ERASE, 166370 }, + { FORMAT_MEDIUM, 3240 }, + { LOAD_UNLOAD, 960 }, + { LOCATE10, 3940 }, + { LOCATE16, 3940 }, + { READ, 2340 }, + { READ_BUFFER, 480 }, + { REWIND, 600 }, + { SEND_DIAGNOSTIC, 2040 }, + { SET_CAPACITY, 960 }, + { SPACE6, 3940 }, + { SPACE16, 3940 }, + { VERIFY, 63300 }, + { WRITE, 1560 }, + { WRITE_BUFFER, 540 }, + { WRITE_FILEMARKS6, 1680 }, + { -1, -1 } }; -static int _create_table_tape(struct timeout_tape **result, - struct _timeout_tape* base, - struct _timeout_tape* override) +static int _create_table_tape(struct timeout_tape **result, struct _timeout_tape *base, struct _timeout_tape *override) { - struct _timeout_tape* cur; - struct timeout_tape* entry; + struct _timeout_tape *cur; + struct timeout_tape *entry; struct timeout_tape *out = NULL; entry = malloc(sizeof(struct timeout_tape)); - entry->op_code = override->op_code; + entry->op_code = override->op_code; entry->timeout = override->timeout; HASH_ADD_INT(*result, op_code, entry); - if (! *result) { + if (!*result) { ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__); return -LTFS_NO_MEMORY; } - for ( cur = override; cur->op_code != -1; ++cur) { + for (cur = override; cur->op_code != -1; ++cur) { entry = malloc(sizeof(struct timeout_tape)); - entry->op_code = cur->op_code; + entry->op_code = cur->op_code; entry->timeout = cur->timeout; HASH_ADD_INT(*result, op_code, entry); } - for ( cur = base; cur->op_code != -1; ++cur) { + for (cur = base; cur->op_code != -1; ++cur) { out = NULL; HASH_FIND_INT(*result, &cur->op_code, out); if (!out) { entry = malloc(sizeof(struct timeout_tape)); - entry->op_code = cur->op_code; + entry->op_code = cur->op_code; entry->timeout = cur->timeout; HASH_ADD_INT(*result, op_code, entry); } @@ -304,7 +289,7 @@ static int _create_table_tape(struct timeout_tape **result, return 0; } -int quantum_tape_init_timeout(struct timeout_tape** table, int type) +int quantum_tape_init_timeout(struct timeout_tape **table, int type) { int ret = 0; diff --git a/src/tape_drivers/reed_solomon_crc.c b/src/tape_drivers/reed_solomon_crc.c index 80e6029c..774244a6 100644 --- a/src/tape_drivers/reed_solomon_crc.c +++ b/src/tape_drivers/reed_solomon_crc.c @@ -52,54 +52,39 @@ #include #include -#include "libltfs/ltfslogging.h" #include "libltfs/ltfs_endian.h" +#include "libltfs/ltfslogging.h" -static const uint32_t rs_gf256_table[256] = -{ - 0x00000000,0x38CF3801,0x70837002,0x484C4803,0xE01BE004,0xD8D4D805, - 0x90989006,0xA857A807,0xDD36DD08,0xE5F9E509,0xADB5AD0A,0x957A950B, - 0x3D2D3D0C,0x05E2050D,0x4DAE4D0E,0x7561750F,0xA76CA710,0x9FA39F11, - 0xD7EFD712,0xEF20EF13,0x47774714,0x7FB87F15,0x37F43716,0x0F3B0F17, - 0x7A5A7A18,0x42954219,0x0AD90A1A,0x3216321B,0x9A419A1C,0xA28EA21D, - 0xEAC2EA1E,0xD20DD21F,0x53D85320,0x6B176B21,0x235B2322,0x1B941B23, - 0xB3C3B324,0x8B0C8B25,0xC340C326,0xFB8FFB27,0x8EEE8E28,0xB621B629, - 0xFE6DFE2A,0xC6A2C62B,0x6EF56E2C,0x563A562D,0x1E761E2E,0x26B9262F, - 0xF4B4F430,0xCC7BCC31,0x84378432,0xBCF8BC33,0x14AF1434,0x2C602C35, - 0x642C6436,0x5CE35C37,0x29822938,0x114D1139,0x5901593A,0x61CE613B, - 0xC999C93C,0xF156F13D,0xB91AB93E,0x81D5813F,0xA6ADA640,0x9E629E41, - 0xD62ED642,0xEEE1EE43,0x46B64644,0x7E797E45,0x36353646,0x0EFA0E47, - 0x7B9B7B48,0x43544349,0x0B180B4A,0x33D7334B,0x9B809B4C,0xA34FA34D, - 0xEB03EB4E,0xD3CCD34F,0x01C10150,0x390E3951,0x71427152,0x498D4953, - 0xE1DAE154,0xD915D955,0x91599156,0xA996A957,0xDCF7DC58,0xE438E459, - 0xAC74AC5A,0x94BB945B,0x3CEC3C5C,0x0423045D,0x4C6F4C5E,0x74A0745F, - 0xF575F560,0xCDBACD61,0x85F68562,0xBD39BD63,0x156E1564,0x2DA12D65, - 0x65ED6566,0x5D225D67,0x28432868,0x108C1069,0x58C0586A,0x600F606B, - 0xC858C86C,0xF097F06D,0xB8DBB86E,0x8014806F,0x52195270,0x6AD66A71, - 0x229A2272,0x1A551A73,0xB202B274,0x8ACD8A75,0xC281C276,0xFA4EFA77, - 0x8F2F8F78,0xB7E0B779,0xFFACFF7A,0xC763C77B,0x6F346F7C,0x57FB577D, - 0x1FB71F7E,0x2778277F,0x51475180,0x69886981,0x21C42182,0x190B1983, - 0xB15CB184,0x89938985,0xC1DFC186,0xF910F987,0x8C718C88,0xB4BEB489, - 0xFCF2FC8A,0xC43DC48B,0x6C6A6C8C,0x54A5548D,0x1CE91C8E,0x2426248F, - 0xF62BF690,0xCEE4CE91,0x86A88692,0xBE67BE93,0x16301694,0x2EFF2E95, - 0x66B36696,0x5E7C5E97,0x2B1D2B98,0x13D21399,0x5B9E5B9A,0x6351639B, - 0xCB06CB9C,0xF3C9F39D,0xBB85BB9E,0x834A839F,0x029F02A0,0x3A503AA1, - 0x721C72A2,0x4AD34AA3,0xE284E2A4,0xDA4BDAA5,0x920792A6,0xAAC8AAA7, - 0xDFA9DFA8,0xE766E7A9,0xAF2AAFAA,0x97E597AB,0x3FB23FAC,0x077D07AD, - 0x4F314FAE,0x77FE77AF,0xA5F3A5B0,0x9D3C9DB1,0xD570D5B2,0xEDBFEDB3, - 0x45E845B4,0x7D277DB5,0x356B35B6,0x0DA40DB7,0x78C578B8,0x400A40B9, - 0x084608BA,0x308930BB,0x98DE98BC,0xA011A0BD,0xE85DE8BE,0xD092D0BF, - 0xF7EAF7C0,0xCF25CFC1,0x876987C2,0xBFA6BFC3,0x17F117C4,0x2F3E2FC5, - 0x677267C6,0x5FBD5FC7,0x2ADC2AC8,0x121312C9,0x5A5F5ACA,0x629062CB, - 0xCAC7CACC,0xF208F2CD,0xBA44BACE,0x828B82CF,0x508650D0,0x684968D1, - 0x200520D2,0x18CA18D3,0xB09DB0D4,0x885288D5,0xC01EC0D6,0xF8D1F8D7, - 0x8DB08DD8,0xB57FB5D9,0xFD33FDDA,0xC5FCC5DB,0x6DAB6DDC,0x556455DD, - 0x1D281DDE,0x25E725DF,0xA432A4E0,0x9CFD9CE1,0xD4B1D4E2,0xEC7EECE3, - 0x442944E4,0x7CE67CE5,0x34AA34E6,0x0C650CE7,0x790479E8,0x41CB41E9, - 0x098709EA,0x314831EB,0x991F99EC,0xA1D0A1ED,0xE99CE9EE,0xD153D1EF, - 0x035E03F0,0x3B913BF1,0x73DD73F2,0x4B124BF3,0xE345E3F4,0xDB8ADBF5, - 0x93C693F6,0xAB09ABF7,0xDE68DEF8,0xE6A7E6F9,0xAEEBAEFA,0x962496FB, - 0x3E733EFC,0x06BC06FD,0x4EF04EFE,0x763F76FF +static const uint32_t rs_gf256_table[256] = { + 0x00000000, 0x38CF3801, 0x70837002, 0x484C4803, 0xE01BE004, 0xD8D4D805, 0x90989006, 0xA857A807, 0xDD36DD08, + 0xE5F9E509, 0xADB5AD0A, 0x957A950B, 0x3D2D3D0C, 0x05E2050D, 0x4DAE4D0E, 0x7561750F, 0xA76CA710, 0x9FA39F11, + 0xD7EFD712, 0xEF20EF13, 0x47774714, 0x7FB87F15, 0x37F43716, 0x0F3B0F17, 0x7A5A7A18, 0x42954219, 0x0AD90A1A, + 0x3216321B, 0x9A419A1C, 0xA28EA21D, 0xEAC2EA1E, 0xD20DD21F, 0x53D85320, 0x6B176B21, 0x235B2322, 0x1B941B23, + 0xB3C3B324, 0x8B0C8B25, 0xC340C326, 0xFB8FFB27, 0x8EEE8E28, 0xB621B629, 0xFE6DFE2A, 0xC6A2C62B, 0x6EF56E2C, + 0x563A562D, 0x1E761E2E, 0x26B9262F, 0xF4B4F430, 0xCC7BCC31, 0x84378432, 0xBCF8BC33, 0x14AF1434, 0x2C602C35, + 0x642C6436, 0x5CE35C37, 0x29822938, 0x114D1139, 0x5901593A, 0x61CE613B, 0xC999C93C, 0xF156F13D, 0xB91AB93E, + 0x81D5813F, 0xA6ADA640, 0x9E629E41, 0xD62ED642, 0xEEE1EE43, 0x46B64644, 0x7E797E45, 0x36353646, 0x0EFA0E47, + 0x7B9B7B48, 0x43544349, 0x0B180B4A, 0x33D7334B, 0x9B809B4C, 0xA34FA34D, 0xEB03EB4E, 0xD3CCD34F, 0x01C10150, + 0x390E3951, 0x71427152, 0x498D4953, 0xE1DAE154, 0xD915D955, 0x91599156, 0xA996A957, 0xDCF7DC58, 0xE438E459, + 0xAC74AC5A, 0x94BB945B, 0x3CEC3C5C, 0x0423045D, 0x4C6F4C5E, 0x74A0745F, 0xF575F560, 0xCDBACD61, 0x85F68562, + 0xBD39BD63, 0x156E1564, 0x2DA12D65, 0x65ED6566, 0x5D225D67, 0x28432868, 0x108C1069, 0x58C0586A, 0x600F606B, + 0xC858C86C, 0xF097F06D, 0xB8DBB86E, 0x8014806F, 0x52195270, 0x6AD66A71, 0x229A2272, 0x1A551A73, 0xB202B274, + 0x8ACD8A75, 0xC281C276, 0xFA4EFA77, 0x8F2F8F78, 0xB7E0B779, 0xFFACFF7A, 0xC763C77B, 0x6F346F7C, 0x57FB577D, + 0x1FB71F7E, 0x2778277F, 0x51475180, 0x69886981, 0x21C42182, 0x190B1983, 0xB15CB184, 0x89938985, 0xC1DFC186, + 0xF910F987, 0x8C718C88, 0xB4BEB489, 0xFCF2FC8A, 0xC43DC48B, 0x6C6A6C8C, 0x54A5548D, 0x1CE91C8E, 0x2426248F, + 0xF62BF690, 0xCEE4CE91, 0x86A88692, 0xBE67BE93, 0x16301694, 0x2EFF2E95, 0x66B36696, 0x5E7C5E97, 0x2B1D2B98, + 0x13D21399, 0x5B9E5B9A, 0x6351639B, 0xCB06CB9C, 0xF3C9F39D, 0xBB85BB9E, 0x834A839F, 0x029F02A0, 0x3A503AA1, + 0x721C72A2, 0x4AD34AA3, 0xE284E2A4, 0xDA4BDAA5, 0x920792A6, 0xAAC8AAA7, 0xDFA9DFA8, 0xE766E7A9, 0xAF2AAFAA, + 0x97E597AB, 0x3FB23FAC, 0x077D07AD, 0x4F314FAE, 0x77FE77AF, 0xA5F3A5B0, 0x9D3C9DB1, 0xD570D5B2, 0xEDBFEDB3, + 0x45E845B4, 0x7D277DB5, 0x356B35B6, 0x0DA40DB7, 0x78C578B8, 0x400A40B9, 0x084608BA, 0x308930BB, 0x98DE98BC, + 0xA011A0BD, 0xE85DE8BE, 0xD092D0BF, 0xF7EAF7C0, 0xCF25CFC1, 0x876987C2, 0xBFA6BFC3, 0x17F117C4, 0x2F3E2FC5, + 0x677267C6, 0x5FBD5FC7, 0x2ADC2AC8, 0x121312C9, 0x5A5F5ACA, 0x629062CB, 0xCAC7CACC, 0xF208F2CD, 0xBA44BACE, + 0x828B82CF, 0x508650D0, 0x684968D1, 0x200520D2, 0x18CA18D3, 0xB09DB0D4, 0x885288D5, 0xC01EC0D6, 0xF8D1F8D7, + 0x8DB08DD8, 0xB57FB5D9, 0xFD33FDDA, 0xC5FCC5DB, 0x6DAB6DDC, 0x556455DD, 0x1D281DDE, 0x25E725DF, 0xA432A4E0, + 0x9CFD9CE1, 0xD4B1D4E2, 0xEC7EECE3, 0x442944E4, 0x7CE67CE5, 0x34AA34E6, 0x0C650CE7, 0x790479E8, 0x41CB41E9, + 0x098709EA, 0x314831EB, 0x991F99EC, 0xA1D0A1ED, 0xE99CE9EE, 0xD153D1EF, 0x035E03F0, 0x3B913BF1, 0x73DD73F2, + 0x4B124BF3, 0xE345E3F4, 0xDB8ADBF5, 0x93C693F6, 0xAB09ABF7, 0xDE68DEF8, 0xE6A7E6F9, 0xAEEBAEFA, 0x962496FB, + 0x3E733EFC, 0x06BC06FD, 0x4EF04EFE, 0x763F76FF }; static inline void enc4(const unsigned char in, uint32_t *reg) @@ -113,7 +98,7 @@ void *memcpy_rs_gf256_enc(void *dest, const void *src, size_t n) uint32_t reg = 0; size_t i; - for(i = 0; i < n; i++){ + for (i = 0; i < n; i++) { /* Inject CRC value to the end of the destination buffer */ *dest_cur = *src_cur; @@ -139,7 +124,7 @@ void rs_gf256_enc(void *buf, size_t n) uint32_t reg = 0; size_t i; - for(i = 0; i < n; i++){ + for (i = 0; i < n; i++) { /* Calculate CRC */ enc4(*buf_cur, ®); buf_cur++; @@ -158,7 +143,7 @@ int memcpy_rs_gf256_check(void *dest, const void *src, size_t n) uint32_t reg = 0, crc; size_t i; - for(i = 0; i < n; i++){ + for (i = 0; i < n; i++) { /* Inject CRC value to the end of the destination buffer */ *dest_cur = *src_cur; @@ -172,7 +157,7 @@ int memcpy_rs_gf256_check(void *dest, const void *src, size_t n) /* Check CRC value in the end of the source buffer */ crc = ltfs_betou32(src_cur); - if(crc != reg) { + if (crc != reg) { ltfsmsg(LTFS_ERR, 39803E, (int)n, reg, crc); return -1; } @@ -187,7 +172,7 @@ int rs_gf256_check(void *buf, size_t n) uint32_t reg = 0, crc; size_t i; - for(i = 0; i < n; i++){ + for (i = 0; i < n; i++) { /* Calculate CRC */ enc4(*buf_cur, ®); buf_cur++; @@ -195,7 +180,7 @@ int rs_gf256_check(void *buf, size_t n) /* Check CRC value in the end of the buffer */ crc = ltfs_betou32(buf_cur); - if(crc != reg) { + if (crc != reg) { ltfsmsg(LTFS_ERR, 39803E, (int)n, reg, crc); return -1; } diff --git a/src/tape_drivers/vendor_compat.c b/src/tape_drivers/vendor_compat.c index 0df8941f..a9b7df5a 100644 --- a/src/tape_drivers/vendor_compat.c +++ b/src/tape_drivers/vendor_compat.c @@ -47,241 +47,241 @@ ************************************************************************************* */ -#include "tape_drivers/ibm_tape.h" +#include "libltfs/ltfs_endian.h" #include "tape_drivers/hp_tape.h" +#include "tape_drivers/ibm_tape.h" #include "tape_drivers/quantum_tape.h" -#include "libltfs/ltfs_endian.h" #define DEFAULT_TIMEOUT (60) /* Standard SCSI sense table */ struct error_table standard_tape_errors[] = { /* Sense Key 0 (No Sense) */ - {0x000000, -EDEV_NO_SENSE, "No Additional Sense Information"}, - {0x000001, -EDEV_FILEMARK_DETECTED, "Filemark Detected"}, - {0x000002, -EDEV_EARLY_WARNING, "End-of-Partition/Medium Detected (Early Warning)"}, - {0x000004, -EDEV_BOP_DETECTED, "Beginning-of-Partition/Medium Detected"}, - {0x000007, -EDEV_PROG_EARLY_WARNING, "End-of-Partition/Medium Detected (Programable Early Warning)"}, - {0x000016, -EDEV_OPERATION_IN_PROGRESS, "Operation in Progress"}, - {0x000017, -EDEV_CLEANING_REQUIRED, "Cleaning Required"}, - {0x000018, -EDEV_OPERATION_IN_PROGRESS, "Erase Operation in Progress"}, - {0x001401, -EDEV_RECORD_NOT_FOUND, "Record Not Found (String Search)"}, - {0x002E00, -EDEV_INSUFFICIENT_TIME, "Insufficient Time For Operation (String Search)"}, - {0x003003, -EDEV_CLEANING_CART, "Cleaning tape installed"}, + { 0x000000, -EDEV_NO_SENSE, "No Additional Sense Information" }, + { 0x000001, -EDEV_FILEMARK_DETECTED, "Filemark Detected" }, + { 0x000002, -EDEV_EARLY_WARNING, "End-of-Partition/Medium Detected (Early Warning)" }, + { 0x000004, -EDEV_BOP_DETECTED, "Beginning-of-Partition/Medium Detected" }, + { 0x000007, -EDEV_PROG_EARLY_WARNING, "End-of-Partition/Medium Detected (Programable Early Warning)" }, + { 0x000016, -EDEV_OPERATION_IN_PROGRESS, "Operation in Progress" }, + { 0x000017, -EDEV_CLEANING_REQUIRED, "Cleaning Required" }, + { 0x000018, -EDEV_OPERATION_IN_PROGRESS, "Erase Operation in Progress" }, + { 0x001401, -EDEV_RECORD_NOT_FOUND, "Record Not Found (String Search)" }, + { 0x002E00, -EDEV_INSUFFICIENT_TIME, "Insufficient Time For Operation (String Search)" }, + { 0x003003, -EDEV_CLEANING_CART, "Cleaning tape installed" }, /* Sense Key 1 (Recovered Error) */ - {0x010000, -EDEV_RECOVERED_ERROR, "No Additional Sense Information"}, - {0x010017, -EDEV_CLEANING_REQUIRED, "Drive Needs Cleaning"}, - {0x010A00, -EDEV_RECOVERED_ERROR, "Error log overflow"}, - {0x010C00, -EDEV_RECOVERED_ERROR, "Write Error: A write error occurred, but was recovered."}, - {0x011100, -EDEV_RECOVERED_ERROR, "Read Error: A read error occurred, but was recovered."}, - {0x011701, -EDEV_RECOVERED_ERROR, "Recovered Data with Retries"}, - {0x011800, -EDEV_RECOVERED_ERROR, "Recovered Data with Error Correction Applied"}, - {0x013700, -EDEV_MODE_PARAMETER_ROUNDED, "Mode Parameters Rounded"}, - {0x014700, -EDEV_RECOVERED_ERROR, "SCSI parity error"}, - {0x015B02, -EDEV_RECOVERED_ERROR, "Log counter at maximum"}, - {0x015D00, -EDEV_RECOVERED_ERROR, "Failure Prediction Threshold Exceeded"}, - {0x015DFF, -EDEV_RECOVERED_ERROR, "Failure Prediction Threshold Exceeded (FALSE)"}, - {0x01EF13, -EDEV_RECOVERED_ERROR, "Encryption - Key Translate"}, + { 0x010000, -EDEV_RECOVERED_ERROR, "No Additional Sense Information" }, + { 0x010017, -EDEV_CLEANING_REQUIRED, "Drive Needs Cleaning" }, + { 0x010A00, -EDEV_RECOVERED_ERROR, "Error log overflow" }, + { 0x010C00, -EDEV_RECOVERED_ERROR, "Write Error: A write error occurred, but was recovered." }, + { 0x011100, -EDEV_RECOVERED_ERROR, "Read Error: A read error occurred, but was recovered." }, + { 0x011701, -EDEV_RECOVERED_ERROR, "Recovered Data with Retries" }, + { 0x011800, -EDEV_RECOVERED_ERROR, "Recovered Data with Error Correction Applied" }, + { 0x013700, -EDEV_MODE_PARAMETER_ROUNDED, "Mode Parameters Rounded" }, + { 0x014700, -EDEV_RECOVERED_ERROR, "SCSI parity error" }, + { 0x015B02, -EDEV_RECOVERED_ERROR, "Log counter at maximum" }, + { 0x015D00, -EDEV_RECOVERED_ERROR, "Failure Prediction Threshold Exceeded" }, + { 0x015DFF, -EDEV_RECOVERED_ERROR, "Failure Prediction Threshold Exceeded (FALSE)" }, + { 0x01EF13, -EDEV_RECOVERED_ERROR, "Encryption - Key Translate" }, /* Sense Key 2 (Not Ready) */ - {0x020017, -EDEV_CLEANING_IN_PROGRESS, "Drive cleaning requested"}, - {0x020400, -EDEV_NOT_REPORTABLE, "Logical Unit Not Ready, Cause Not Reportable"}, - {0x020401, -EDEV_BECOMING_READY, "Logical Unit Is in Process of Becoming Ready"}, - {0x020402, -EDEV_NEED_INITIALIZE, "Initializing Command Required"}, - {0x020403, -EDEV_NO_MEDIUM, "Logical Unit Not Ready, Manual Intervention Required"}, - {0x020404, -EDEV_OPERATION_IN_PROGRESS, "Logical Unit Not Ready, Format in Progress"}, - {0x020407, -EDEV_OPERATION_IN_PROGRESS, "Operation in progress"}, - {0x020412, -EDEV_OFFLINE, "Logical Unit Not Ready, Offline"}, - {0x020413, -EDEV_OPERATION_IN_PROGRESS, "Logical Unit Not Ready, SA Creation in Progress"}, - {0x020B01, -EDEV_OVER_TEMPERATURE, "Warning - Specified Temperature Exceeded"}, - {0x023003, -EDEV_CLEANING_IN_PROGRESS, "Cleaning Cartridge Installed"}, - {0x023007, -EDEV_NOT_READY, "Cleaning Failure"}, - {0x023A00, -EDEV_NO_MEDIUM, "Medium Not Present"}, - {0x023A02, -EDEV_IE_OPEN, "Medium Not Present - Tray Open"}, - {0x023A04, -EDEV_NO_MEDIUM, "Not Ready - Medium Auxiliary Memory Accessible"}, - {0x023B12, -EDEV_DOOR_OPEN, "Magazine removed"}, - {0x023E00, -EDEV_NOT_SELF_CONFIGURED_YET, "Logical Unit Has Not Self-configured"}, - {0x025300, -EDEV_LOAD_UNLOAD_ERROR, "Media Load or Eject Failed"}, - {0x027411, -EDEV_PARAMETER_VALUE_REJECTED, "SA Creation Parameter Value Rejected"}, + { 0x020017, -EDEV_CLEANING_IN_PROGRESS, "Drive cleaning requested" }, + { 0x020400, -EDEV_NOT_REPORTABLE, "Logical Unit Not Ready, Cause Not Reportable" }, + { 0x020401, -EDEV_BECOMING_READY, "Logical Unit Is in Process of Becoming Ready" }, + { 0x020402, -EDEV_NEED_INITIALIZE, "Initializing Command Required" }, + { 0x020403, -EDEV_NO_MEDIUM, "Logical Unit Not Ready, Manual Intervention Required" }, + { 0x020404, -EDEV_OPERATION_IN_PROGRESS, "Logical Unit Not Ready, Format in Progress" }, + { 0x020407, -EDEV_OPERATION_IN_PROGRESS, "Operation in progress" }, + { 0x020412, -EDEV_OFFLINE, "Logical Unit Not Ready, Offline" }, + { 0x020413, -EDEV_OPERATION_IN_PROGRESS, "Logical Unit Not Ready, SA Creation in Progress" }, + { 0x020B01, -EDEV_OVER_TEMPERATURE, "Warning - Specified Temperature Exceeded" }, + { 0x023003, -EDEV_CLEANING_IN_PROGRESS, "Cleaning Cartridge Installed" }, + { 0x023007, -EDEV_NOT_READY, "Cleaning Failure" }, + { 0x023A00, -EDEV_NO_MEDIUM, "Medium Not Present" }, + { 0x023A02, -EDEV_IE_OPEN, "Medium Not Present - Tray Open" }, + { 0x023A04, -EDEV_NO_MEDIUM, "Not Ready - Medium Auxiliary Memory Accessible" }, + { 0x023B12, -EDEV_DOOR_OPEN, "Magazine removed" }, + { 0x023E00, -EDEV_NOT_SELF_CONFIGURED_YET, "Logical Unit Has Not Self-configured" }, + { 0x025300, -EDEV_LOAD_UNLOAD_ERROR, "Media Load or Eject Failed" }, + { 0x027411, -EDEV_PARAMETER_VALUE_REJECTED, "SA Creation Parameter Value Rejected" }, /* Sense Key 3 (Medium Error) */ - {0x030302, -EDEV_WRITE_PERM, "Excessive Write Errors"}, - {0x030410, -EDEV_CM_PERM, "Logical Unit Not Ready, Auxiliary Memory Not Accessible"}, - {0x030900, -EDEV_RW_PERM, "Track Following Error (Servo)"}, - {0x030C00, -EDEV_WRITE_PERM, "Write Error"}, - {0x031100, -EDEV_READ_PERM, "Unrecovered Read Error"}, - {0x031101, -EDEV_READ_PERM, "Read Retries Exhausted"}, - {0x031108, -EDEV_READ_PERM, "Incomplete Block Read"}, - {0x031112, -EDEV_CM_PERM, "Auxiliary Memory Read Error"}, - {0x031400, -EDEV_RW_PERM, "Recorded Entity Not Found"}, - {0x031401, -EDEV_RW_PERM, "Record Not Found"}, - {0x031402, -EDEV_RW_PERM, "Filemark or Setmark Not Found"}, - {0x031403, -EDEV_RW_PERM, "End-of-Data Not Found"}, - {0x031404, -EDEV_MEDIUM_ERROR, "Block Sequence Error"}, - {0x033000, -EDEV_MEDIUM_FORMAT_ERROR, "Incompatible Medium Installed"}, - {0x033001, -EDEV_MEDIUM_FORMAT_ERROR, "Cannot Read Medium, Unknown Format"}, - {0x033002, -EDEV_MEDIUM_FORMAT_ERROR, "Cannot Read Medium, Incompatible Format"}, - {0x033003, -EDEV_MEDIUM_FORMAT_ERROR, "Cleaning tape installed"}, - {0x033007, -EDEV_CLEANING_FALIURE, "Cleaning failure"}, - {0x03300D, -EDEV_MEDIUM_ERROR, "Medium Error/WORM Medium"}, - {0x033100, -EDEV_MEDIUM_FORMAT_CORRUPTED, "Medium Format Corrupted"}, - {0x033101, -EDEV_MEDIUM_ERROR, "Format Command Failed"}, - {0x033300, -EDEV_MEDIUM_ERROR, "Tape Length Error"}, - {0x033B00, -EDEV_RW_PERM, "Sequential Positioning Error"}, - {0x035000, -EDEV_RW_PERM, "Write Append Error"}, - {0x035100, -EDEV_MEDIUM_ERROR, "Erase Failure"}, - {0x035200, -EDEV_RW_PERM, "Cartridge Fault"}, - {0x035300, -EDEV_LOAD_UNLOAD_ERROR, "Media Load or Eject Failed"}, - {0x035304, -EDEV_LOAD_UNLOAD_ERROR, "Medium Thread or Unthread Failure"}, + { 0x030302, -EDEV_WRITE_PERM, "Excessive Write Errors" }, + { 0x030410, -EDEV_CM_PERM, "Logical Unit Not Ready, Auxiliary Memory Not Accessible" }, + { 0x030900, -EDEV_RW_PERM, "Track Following Error (Servo)" }, + { 0x030C00, -EDEV_WRITE_PERM, "Write Error" }, + { 0x031100, -EDEV_READ_PERM, "Unrecovered Read Error" }, + { 0x031101, -EDEV_READ_PERM, "Read Retries Exhausted" }, + { 0x031108, -EDEV_READ_PERM, "Incomplete Block Read" }, + { 0x031112, -EDEV_CM_PERM, "Auxiliary Memory Read Error" }, + { 0x031400, -EDEV_RW_PERM, "Recorded Entity Not Found" }, + { 0x031401, -EDEV_RW_PERM, "Record Not Found" }, + { 0x031402, -EDEV_RW_PERM, "Filemark or Setmark Not Found" }, + { 0x031403, -EDEV_RW_PERM, "End-of-Data Not Found" }, + { 0x031404, -EDEV_MEDIUM_ERROR, "Block Sequence Error" }, + { 0x033000, -EDEV_MEDIUM_FORMAT_ERROR, "Incompatible Medium Installed" }, + { 0x033001, -EDEV_MEDIUM_FORMAT_ERROR, "Cannot Read Medium, Unknown Format" }, + { 0x033002, -EDEV_MEDIUM_FORMAT_ERROR, "Cannot Read Medium, Incompatible Format" }, + { 0x033003, -EDEV_MEDIUM_FORMAT_ERROR, "Cleaning tape installed" }, + { 0x033007, -EDEV_CLEANING_FALIURE, "Cleaning failure" }, + { 0x03300D, -EDEV_MEDIUM_ERROR, "Medium Error/WORM Medium" }, + { 0x033100, -EDEV_MEDIUM_FORMAT_CORRUPTED, "Medium Format Corrupted" }, + { 0x033101, -EDEV_MEDIUM_ERROR, "Format Command Failed" }, + { 0x033300, -EDEV_MEDIUM_ERROR, "Tape Length Error" }, + { 0x033B00, -EDEV_RW_PERM, "Sequential Positioning Error" }, + { 0x035000, -EDEV_RW_PERM, "Write Append Error" }, + { 0x035100, -EDEV_MEDIUM_ERROR, "Erase Failure" }, + { 0x035200, -EDEV_RW_PERM, "Cartridge Fault" }, + { 0x035300, -EDEV_LOAD_UNLOAD_ERROR, "Media Load or Eject Failed" }, + { 0x035304, -EDEV_LOAD_UNLOAD_ERROR, "Medium Thread or Unthread Failure" }, /* Sense Key 4 (Hardware or Firmware Error) */ - {0x040302, -EDEV_HARDWARE_ERROR, "Open Writer Failure"}, - {0x040403, -EDEV_HARDWARE_ERROR, "Manual Intervention Required"}, - {0x040801, -EDEV_HARDWARE_ERROR, "Logical Unit Communication Failure"}, - {0x040900, -EDEV_HARDWARE_ERROR, "Track Following Error"}, - {0x041001, -EDEV_LBP_WRITE_ERROR, "Logical Block Guard Check Failed"}, - {0x041004, -EDEV_HARDWARE_ERROR, "Logical Block Protection Error On Recover Buffered Data"}, - {0x041501, -EDEV_HARDWARE_ERROR, "Machanical Position Error"}, - {0x043B00, -EDEV_HARDWARE_ERROR, "Sequential Positioning Error"}, - {0x043B08, -EDEV_HARDWARE_ERROR, "Reposition Error"}, - {0x043B0D, -EDEV_HARDWARE_ERROR, "Medium Destination Element Full"}, - {0x043B0E, -EDEV_HARDWARE_ERROR, "Medium Source Element Empty"}, - {0x043F0F, -EDEV_HARDWARE_ERROR, "Echo buffer overwritten"}, - {0x044000, -EDEV_HARDWARE_ERROR, "Diagnostic Failure"}, - {0x044100, -EDEV_HARDWARE_ERROR, "Data Path Failure"}, - {0x044400, -EDEV_HARDWARE_ERROR, "Internal Target Failure"}, - {0x044C00, -EDEV_HARDWARE_ERROR, "Logical Unit Failed Self-Configuration"}, - {0x045100, -EDEV_HARDWARE_ERROR, "Erase Failure"}, - {0x045200, -EDEV_HARDWARE_ERROR, "Cartridge Fault"}, - {0x045300, -EDEV_HARDWARE_ERROR, "Media Load or Eject Failed"}, - {0x045301, -EDEV_HARDWARE_ERROR, "A drive did not unload a cartridge."}, - {0x045304, -EDEV_HARDWARE_ERROR, "Medium Thread or Unthread Failure"}, + { 0x040302, -EDEV_HARDWARE_ERROR, "Open Writer Failure" }, + { 0x040403, -EDEV_HARDWARE_ERROR, "Manual Intervention Required" }, + { 0x040801, -EDEV_HARDWARE_ERROR, "Logical Unit Communication Failure" }, + { 0x040900, -EDEV_HARDWARE_ERROR, "Track Following Error" }, + { 0x041001, -EDEV_LBP_WRITE_ERROR, "Logical Block Guard Check Failed" }, + { 0x041004, -EDEV_HARDWARE_ERROR, "Logical Block Protection Error On Recover Buffered Data" }, + { 0x041501, -EDEV_HARDWARE_ERROR, "Machanical Position Error" }, + { 0x043B00, -EDEV_HARDWARE_ERROR, "Sequential Positioning Error" }, + { 0x043B08, -EDEV_HARDWARE_ERROR, "Reposition Error" }, + { 0x043B0D, -EDEV_HARDWARE_ERROR, "Medium Destination Element Full" }, + { 0x043B0E, -EDEV_HARDWARE_ERROR, "Medium Source Element Empty" }, + { 0x043F0F, -EDEV_HARDWARE_ERROR, "Echo buffer overwritten" }, + { 0x044000, -EDEV_HARDWARE_ERROR, "Diagnostic Failure" }, + { 0x044100, -EDEV_HARDWARE_ERROR, "Data Path Failure" }, + { 0x044400, -EDEV_HARDWARE_ERROR, "Internal Target Failure" }, + { 0x044C00, -EDEV_HARDWARE_ERROR, "Logical Unit Failed Self-Configuration" }, + { 0x045100, -EDEV_HARDWARE_ERROR, "Erase Failure" }, + { 0x045200, -EDEV_HARDWARE_ERROR, "Cartridge Fault" }, + { 0x045300, -EDEV_HARDWARE_ERROR, "Media Load or Eject Failed" }, + { 0x045301, -EDEV_HARDWARE_ERROR, "A drive did not unload a cartridge." }, + { 0x045304, -EDEV_HARDWARE_ERROR, "Medium Thread or Unthread Failure" }, /* Sense Key 5 (Illegal Request) */ - {0x050E03, -EDEV_ILLEGAL_REQUEST, "Invalid Field in Command Information Unit (e.g., FCP_DL error)"}, - {0x051A00, -EDEV_ILLEGAL_REQUEST, "Parameter List Length Error"}, - {0x052000, -EDEV_ILLEGAL_REQUEST, "Invalid Command Operation Code"}, - {0x05200C, -EDEV_ILLEGAL_REQUEST, "Illegal Command When Not In Append-Only Mode"}, - {0x052101, -EDEV_INVALID_ADDRESS, "Invalid Element Address"}, - {0x052400, -EDEV_INVALID_FIELD_CDB, "Invalid Field in CDB"}, - {0x052500, -EDEV_ILLEGAL_REQUEST, "Logical Unit Not Supported"}, - {0x052600, -EDEV_ILLEGAL_REQUEST, "Invalid Field in Parameter List"}, - {0x052601, -EDEV_ILLEGAL_REQUEST, "Parameter list error: parameter not supported"}, - {0x052602, -EDEV_ILLEGAL_REQUEST, "Parameter value invalid"}, - {0x052603, -EDEV_ILLEGAL_REQUEST, "Threshold Parameters Not Supported"}, - {0x052604, -EDEV_ILLEGAL_REQUEST, "Invalid release of persistent reservation"}, - {0x052611, -EDEV_ILLEGAL_REQUEST, "Encryption - Incomplete Key-Associate Data Set"}, - {0x052612, -EDEV_ILLEGAL_REQUEST, "Vendor Specific Key Reference Not Found"}, - {0x052690, -EDEV_ILLEGAL_REQUEST, "Wrong firmware image, does not fit boot code"}, - {0x052691, -EDEV_ILLEGAL_REQUEST, "Wrong personality firmware image"}, - {0x052693, -EDEV_ILLEGAL_REQUEST, "Wrong firmware image, checksum error"}, - {0x052904, -EDEV_ILLEGAL_REQUEST, "Device Internal Reset"}, - {0x052C00, -EDEV_ILLEGAL_REQUEST, "Command Sequence Error"}, - {0x052C0B, -EDEV_ILLEGAL_REQUEST, "Not Reserved"}, - {0x053000, -EDEV_ILLEGAL_REQUEST, "Incompatible Medium Installed"}, - {0x053005, -EDEV_ILLEGAL_REQUEST, "Cannot Write Medium - Incompatible Format"}, - {0x053900, -EDEV_ILLEGAL_REQUEST, "Saving Parameters Not Supported"}, - {0x053B00, -EDEV_ILLEGAL_REQUEST, "Sequential Positioning Error"}, - {0x053B0C, -EDEV_ILLEGAL_REQUEST, "Position Past Beginning of Medium"}, - {0x053B0D, -EDEV_DEST_FULL, "Medium Destination Element Full"}, - {0x053B0E, -EDEV_SRC_EMPTY, "Medium Source Element Empty"}, - {0x053B11, -EDEV_MAGAZINE_INACCESSIBLE, "Medium magazine not accessible"}, - {0x053B12, -EDEV_MAGAZINE_INACCESSIBLE, "Media magazine not installed."}, - {0x053D00, -EDEV_ILLEGAL_REQUEST, "Invalid Bits in Identify Message"}, - {0x054900, -EDEV_ILLEGAL_REQUEST, "Invalid Message Error"}, - {0x055301, -EDEV_MEDIUM_LOCKED, "A drive did not unload a cartridge."}, - {0x055302, -EDEV_MEDIUM_LOCKED, "Medium Removal Prevented"}, - {0x055303, -EDEV_MEDIUM_LOCKED, "Drive media removal prevented state set"}, - {0x055508, -EDEV_ILLEGAL_REQUEST, "Maximum Number of Supplemental Decryption Keys Exceeded"}, - {0x055B03, -EDEV_ILLEGAL_REQUEST, "Log List Codes Exhausted"}, - {0x057408, -EDEV_ILLEGAL_REQUEST, "Digital Signature Validation Failure"}, - {0x05740C, -EDEV_ILLEGAL_REQUEST, "Unable to Decrypt Parameter List"}, - {0x057410, -EDEV_ILLEGAL_REQUEST, "SA Creation Parameter Value Invalid"}, - {0x057411, -EDEV_ILLEGAL_REQUEST, "SA Creation Parameter Value Rejected"}, - {0x057412, -EDEV_ILLEGAL_REQUEST, "Invalid SA Usage"}, - {0x057430, -EDEV_ILLEGAL_REQUEST, "SA Creation Parameter not Supported"}, + { 0x050E03, -EDEV_ILLEGAL_REQUEST, "Invalid Field in Command Information Unit (e.g., FCP_DL error)" }, + { 0x051A00, -EDEV_ILLEGAL_REQUEST, "Parameter List Length Error" }, + { 0x052000, -EDEV_ILLEGAL_REQUEST, "Invalid Command Operation Code" }, + { 0x05200C, -EDEV_ILLEGAL_REQUEST, "Illegal Command When Not In Append-Only Mode" }, + { 0x052101, -EDEV_INVALID_ADDRESS, "Invalid Element Address" }, + { 0x052400, -EDEV_INVALID_FIELD_CDB, "Invalid Field in CDB" }, + { 0x052500, -EDEV_ILLEGAL_REQUEST, "Logical Unit Not Supported" }, + { 0x052600, -EDEV_ILLEGAL_REQUEST, "Invalid Field in Parameter List" }, + { 0x052601, -EDEV_ILLEGAL_REQUEST, "Parameter list error: parameter not supported" }, + { 0x052602, -EDEV_ILLEGAL_REQUEST, "Parameter value invalid" }, + { 0x052603, -EDEV_ILLEGAL_REQUEST, "Threshold Parameters Not Supported" }, + { 0x052604, -EDEV_ILLEGAL_REQUEST, "Invalid release of persistent reservation" }, + { 0x052611, -EDEV_ILLEGAL_REQUEST, "Encryption - Incomplete Key-Associate Data Set" }, + { 0x052612, -EDEV_ILLEGAL_REQUEST, "Vendor Specific Key Reference Not Found" }, + { 0x052690, -EDEV_ILLEGAL_REQUEST, "Wrong firmware image, does not fit boot code" }, + { 0x052691, -EDEV_ILLEGAL_REQUEST, "Wrong personality firmware image" }, + { 0x052693, -EDEV_ILLEGAL_REQUEST, "Wrong firmware image, checksum error" }, + { 0x052904, -EDEV_ILLEGAL_REQUEST, "Device Internal Reset" }, + { 0x052C00, -EDEV_ILLEGAL_REQUEST, "Command Sequence Error" }, + { 0x052C0B, -EDEV_ILLEGAL_REQUEST, "Not Reserved" }, + { 0x053000, -EDEV_ILLEGAL_REQUEST, "Incompatible Medium Installed" }, + { 0x053005, -EDEV_ILLEGAL_REQUEST, "Cannot Write Medium - Incompatible Format" }, + { 0x053900, -EDEV_ILLEGAL_REQUEST, "Saving Parameters Not Supported" }, + { 0x053B00, -EDEV_ILLEGAL_REQUEST, "Sequential Positioning Error" }, + { 0x053B0C, -EDEV_ILLEGAL_REQUEST, "Position Past Beginning of Medium" }, + { 0x053B0D, -EDEV_DEST_FULL, "Medium Destination Element Full" }, + { 0x053B0E, -EDEV_SRC_EMPTY, "Medium Source Element Empty" }, + { 0x053B11, -EDEV_MAGAZINE_INACCESSIBLE, "Medium magazine not accessible" }, + { 0x053B12, -EDEV_MAGAZINE_INACCESSIBLE, "Media magazine not installed." }, + { 0x053D00, -EDEV_ILLEGAL_REQUEST, "Invalid Bits in Identify Message" }, + { 0x054900, -EDEV_ILLEGAL_REQUEST, "Invalid Message Error" }, + { 0x055301, -EDEV_MEDIUM_LOCKED, "A drive did not unload a cartridge." }, + { 0x055302, -EDEV_MEDIUM_LOCKED, "Medium Removal Prevented" }, + { 0x055303, -EDEV_MEDIUM_LOCKED, "Drive media removal prevented state set" }, + { 0x055508, -EDEV_ILLEGAL_REQUEST, "Maximum Number of Supplemental Decryption Keys Exceeded" }, + { 0x055B03, -EDEV_ILLEGAL_REQUEST, "Log List Codes Exhausted" }, + { 0x057408, -EDEV_ILLEGAL_REQUEST, "Digital Signature Validation Failure" }, + { 0x05740C, -EDEV_ILLEGAL_REQUEST, "Unable to Decrypt Parameter List" }, + { 0x057410, -EDEV_ILLEGAL_REQUEST, "SA Creation Parameter Value Invalid" }, + { 0x057411, -EDEV_ILLEGAL_REQUEST, "SA Creation Parameter Value Rejected" }, + { 0x057412, -EDEV_ILLEGAL_REQUEST, "Invalid SA Usage" }, + { 0x057430, -EDEV_ILLEGAL_REQUEST, "SA Creation Parameter not Supported" }, /* Sense Key 6 (Unit Attention) */ - {0x060002, -EDEV_EARLY_WARNING, "End-of-Partition/Medium Detected, Early Warning"}, - {0x062800, -EDEV_MEDIUM_MAY_BE_CHANGED, "Not Ready to Ready Transition, Medium May Have Changed"}, - {0x062801, -EDEV_IE_ACCESSED, "Import or Export Element Accessed"}, - {0x062900, -EDEV_POR_OR_BUS_RESET, "Power On, Reset, or Bus Device Reset Occurred"}, - {0x062901, -EDEV_POR_OR_BUS_RESET, "Power on occurred"}, - {0x062902, -EDEV_POR_OR_BUS_RESET, "SCSI Bus reset occurred"}, - {0x062903, -EDEV_POR_OR_BUS_RESET, "Internal reset occurred"}, - {0x062904, -EDEV_POR_OR_BUS_RESET, "Internal reset occurred"}, - {0x062905, -EDEV_UNIT_ATTENTION, "Transceiver Mode Changed To Single-ended"}, - {0x062906, -EDEV_UNIT_ATTENTION, "Transceiver Mode Changed To LVD"}, - {0x062A01, -EDEV_CONFIGURE_CHANGED, "Mode Parameters Changed"}, - {0x062A02, -EDEV_CONFIGURE_CHANGED, "Mode Parameters Changed"}, - {0x062A03, -EDEV_RESERVATION_PREEMPTED, "Reservations preempted"}, - {0x062A04, -EDEV_RESERVATION_RELEASED, "Reservations released"}, - {0x062A05, -EDEV_REGISTRATION_PREEMPTED, "Registrations preempted"}, - {0x062A10, -EDEV_TIME_STAMP_CHANGED, "Time stamp changed"}, - {0x062A11, -EDEV_CRYPTO_ERROR, "Encryption - Data Encryption Parameters Changed by Another I_T Nexus"}, - {0x062A12, -EDEV_CRYPTO_ERROR, "Encryption - Data Encryption Parameters Changed by Vendor Specific Event"}, - {0x062A14, -EDEV_UNIT_ATTENTION, "SA Creation Capabilities Data Has Changed"}, - {0x062F00, -EDEV_COMMAND_CLEARED, "Commands Cleared by Another Initiator"}, - {0x063000, -EDEV_MEDIUM_ERROR, "Incompatible Medium Installed"}, - {0x063B12, -EDEV_DOOR_CLOSED, "Medium magazine removed"}, - {0x063B13, -EDEV_DOOR_CLOSED, "Medium magazine inserted"}, - {0x063F01, -EDEV_CONFIGURE_CHANGED, "Microcode Has Been Changed"}, - {0x063F02, -EDEV_CONFIGURE_CHANGED, "Changed Operating Definition"}, - {0x063F03, -EDEV_CONFIGURE_CHANGED, "Inquiry Data Has Changed"}, - {0x063F05, -EDEV_CONFIGURE_CHANGED, "Device Identifier Changed"}, - {0x063F0E, -EDEV_CONFIGURE_CHANGED, "Reported LUNs Data Has Changed"}, - {0x065302, -EDEV_MEDIA_REMOVAL_PREV, "Media removal prevented"}, - {0x065A01, -EDEV_MEDIUM_REMOVAL_REQ, "Operator Medium Removal Request"}, + { 0x060002, -EDEV_EARLY_WARNING, "End-of-Partition/Medium Detected, Early Warning" }, + { 0x062800, -EDEV_MEDIUM_MAY_BE_CHANGED, "Not Ready to Ready Transition, Medium May Have Changed" }, + { 0x062801, -EDEV_IE_ACCESSED, "Import or Export Element Accessed" }, + { 0x062900, -EDEV_POR_OR_BUS_RESET, "Power On, Reset, or Bus Device Reset Occurred" }, + { 0x062901, -EDEV_POR_OR_BUS_RESET, "Power on occurred" }, + { 0x062902, -EDEV_POR_OR_BUS_RESET, "SCSI Bus reset occurred" }, + { 0x062903, -EDEV_POR_OR_BUS_RESET, "Internal reset occurred" }, + { 0x062904, -EDEV_POR_OR_BUS_RESET, "Internal reset occurred" }, + { 0x062905, -EDEV_UNIT_ATTENTION, "Transceiver Mode Changed To Single-ended" }, + { 0x062906, -EDEV_UNIT_ATTENTION, "Transceiver Mode Changed To LVD" }, + { 0x062A01, -EDEV_CONFIGURE_CHANGED, "Mode Parameters Changed" }, + { 0x062A02, -EDEV_CONFIGURE_CHANGED, "Mode Parameters Changed" }, + { 0x062A03, -EDEV_RESERVATION_PREEMPTED, "Reservations preempted" }, + { 0x062A04, -EDEV_RESERVATION_RELEASED, "Reservations released" }, + { 0x062A05, -EDEV_REGISTRATION_PREEMPTED, "Registrations preempted" }, + { 0x062A10, -EDEV_TIME_STAMP_CHANGED, "Time stamp changed" }, + { 0x062A11, -EDEV_CRYPTO_ERROR, "Encryption - Data Encryption Parameters Changed by Another I_T Nexus" }, + { 0x062A12, -EDEV_CRYPTO_ERROR, "Encryption - Data Encryption Parameters Changed by Vendor Specific Event" }, + { 0x062A14, -EDEV_UNIT_ATTENTION, "SA Creation Capabilities Data Has Changed" }, + { 0x062F00, -EDEV_COMMAND_CLEARED, "Commands Cleared by Another Initiator" }, + { 0x063000, -EDEV_MEDIUM_ERROR, "Incompatible Medium Installed" }, + { 0x063B12, -EDEV_DOOR_CLOSED, "Medium magazine removed" }, + { 0x063B13, -EDEV_DOOR_CLOSED, "Medium magazine inserted" }, + { 0x063F01, -EDEV_CONFIGURE_CHANGED, "Microcode Has Been Changed" }, + { 0x063F02, -EDEV_CONFIGURE_CHANGED, "Changed Operating Definition" }, + { 0x063F03, -EDEV_CONFIGURE_CHANGED, "Inquiry Data Has Changed" }, + { 0x063F05, -EDEV_CONFIGURE_CHANGED, "Device Identifier Changed" }, + { 0x063F0E, -EDEV_CONFIGURE_CHANGED, "Reported LUNs Data Has Changed" }, + { 0x065302, -EDEV_MEDIA_REMOVAL_PREV, "Media removal prevented" }, + { 0x065A01, -EDEV_MEDIUM_REMOVAL_REQ, "Operator Medium Removal Request" }, /* Sense Key 7 (Data Protect) */ - {0x072610, -EDEV_CRYPTO_ERROR, "Encryption - Data Decryption Key Fail Limit"}, - {0x072700, -EDEV_WRITE_PROTECTED, "Write Protected"}, - {0x072A13, -EDEV_CRYPTO_ERROR, "Encryption - Data Encryption Key Instance Counter Has Changed"}, - {0x073005, -EDEV_DATA_PROTECT, "Cannot Write Medium, Incompatible Format"}, - {0x073000, -EDEV_WRITE_PROTECTED_WORM, "Data Protect/WORM Medium"}, - {0x07300C, -EDEV_WRITE_PROTECTED_WORM, "Data Protect/WORM Medium - Overwrite Attempted"}, - {0x07300D, -EDEV_WRITE_PROTECTED_WORM, "Data Protect/WORM Medium - Integrity Check"}, - {0x075001, -EDEV_WRITE_PROTECTED_WORM, "Write Append Position Error (WORM)"}, - {0x075200, -EDEV_DATA_PROTECT, "Cartridge Fault"}, - {0x075A02, -EDEV_WRITE_PROTECTED_OPERATOR, "Data Protect/Operator - Overwrite Attempted"}, - {0x077400, -EDEV_WRITE_PROTECTED_WORM, "Security Error"}, - {0x077401, -EDEV_CRYPTO_ERROR, "Encryption - Unable to Decrypt Data"}, - {0x077402, -EDEV_CRYPTO_ERROR, "Encryption - Unencrypted Data Encountered While Decrypting"}, - {0x077403, -EDEV_CRYPTO_ERROR, "Encryption - Incorrect Data Encryption Key"}, - {0x077404, -EDEV_CRYPTO_ERROR, "Encryption - Cryptographic Integrity Validation Failed"}, - {0x077405, -EDEV_CRYPTO_ERROR, "Encryption - Error Decrypting Data"}, + { 0x072610, -EDEV_CRYPTO_ERROR, "Encryption - Data Decryption Key Fail Limit" }, + { 0x072700, -EDEV_WRITE_PROTECTED, "Write Protected" }, + { 0x072A13, -EDEV_CRYPTO_ERROR, "Encryption - Data Encryption Key Instance Counter Has Changed" }, + { 0x073005, -EDEV_DATA_PROTECT, "Cannot Write Medium, Incompatible Format" }, + { 0x073000, -EDEV_WRITE_PROTECTED_WORM, "Data Protect/WORM Medium" }, + { 0x07300C, -EDEV_WRITE_PROTECTED_WORM, "Data Protect/WORM Medium - Overwrite Attempted" }, + { 0x07300D, -EDEV_WRITE_PROTECTED_WORM, "Data Protect/WORM Medium - Integrity Check" }, + { 0x075001, -EDEV_WRITE_PROTECTED_WORM, "Write Append Position Error (WORM)" }, + { 0x075200, -EDEV_DATA_PROTECT, "Cartridge Fault" }, + { 0x075A02, -EDEV_WRITE_PROTECTED_OPERATOR, "Data Protect/Operator - Overwrite Attempted" }, + { 0x077400, -EDEV_WRITE_PROTECTED_WORM, "Security Error" }, + { 0x077401, -EDEV_CRYPTO_ERROR, "Encryption - Unable to Decrypt Data" }, + { 0x077402, -EDEV_CRYPTO_ERROR, "Encryption - Unencrypted Data Encountered While Decrypting" }, + { 0x077403, -EDEV_CRYPTO_ERROR, "Encryption - Incorrect Data Encryption Key" }, + { 0x077404, -EDEV_CRYPTO_ERROR, "Encryption - Cryptographic Integrity Validation Failed" }, + { 0x077405, -EDEV_CRYPTO_ERROR, "Encryption - Error Decrypting Data" }, /* Sense Key 8 (Blank Check) */ - {0x080005, -EDEV_EOD_DETECTED, "End-of-Data (EOD) Detected"}, - {0x081401, -EDEV_RECORD_NOT_FOUND, "Record Not Found, Void Tape"}, - {0x081403, -EDEV_EOD_NOT_FOUND, "End-of-Data (EOD) not found"}, - {0x080B01, -EDEV_OVER_TEMPERATURE, "The drive detected an overtemperature condition."}, + { 0x080005, -EDEV_EOD_DETECTED, "End-of-Data (EOD) Detected" }, + { 0x081401, -EDEV_RECORD_NOT_FOUND, "Record Not Found, Void Tape" }, + { 0x081403, -EDEV_EOD_NOT_FOUND, "End-of-Data (EOD) not found" }, + { 0x080B01, -EDEV_OVER_TEMPERATURE, "The drive detected an overtemperature condition." }, /* Sense Key B (Aborted Command) */ - {0x0B0E01, -EDEV_ABORTED_COMMAND, "Information Unit Too Short"}, - {0x0B1400, -EDEV_ABORTED_COMMAND, "Recorded Entity Not Found"}, - {0x0B1401, -EDEV_ABORTED_COMMAND, "Record Not Found"}, - {0x0B1402, -EDEV_ABORTED_COMMAND, "Filemark or Setmark Not Found"}, - {0x0B1B00, -EDEV_ABORTED_COMMAND, "Synchronous Data Transfer Error"}, - {0x0B3D00, -EDEV_ABORTED_COMMAND, "Invalid Bits in Identify Message"}, - {0x0B3F0F, -EDEV_ABORTED_COMMAND, "Echo Buffer Overwritten"}, - {0x0B4100, -EDEV_ABORTED_COMMAND, "LDI command Failure"}, - {0x0B4300, -EDEV_ABORTED_COMMAND, "Message Error"}, - {0x0B4400, -EDEV_ABORTED_COMMAND, "Internal Target Failure"}, - {0x0B4500, -EDEV_ABORTED_COMMAND, "Select/Reselect Failure"}, - {0x0B4700, -EDEV_ABORTED_COMMAND, "SCSI Parity Error"}, - {0x0B4703, -EDEV_ABORTED_COMMAND, "Information Unit iuCRC Error Detected"}, - {0x0B4800, -EDEV_ABORTED_COMMAND, "Initiator Detected Error Message Received"}, - {0x0B4900, -EDEV_ABORTED_COMMAND, "Invalid Message Error"}, - {0x0B4A00, -EDEV_ABORTED_COMMAND, "Command Phase Error"}, - {0x0B4B00, -EDEV_ABORTED_COMMAND, "Data Phase Error"}, - {0x0B4B02, -EDEV_ABORTED_COMMAND, "Too Much Write Data"}, - {0x0B4B03, -EDEV_ABORTED_COMMAND, "ACK/NAK Timeout"}, - {0x0B4B04, -EDEV_ABORTED_COMMAND, "NAK Received"}, - {0x0B4B05, -EDEV_ABORTED_COMMAND, "Data Offset Error"}, - {0x0B4B06, -EDEV_TIMEOUT, "Initiator Response Timeout"}, - {0x0B4E00, -EDEV_OVERLAPPED, "Overlapped Commands"}, - {0x0B0801, -EDEV_ABORTED_COMMAND, "LU Communication - Timeout"}, + { 0x0B0E01, -EDEV_ABORTED_COMMAND, "Information Unit Too Short" }, + { 0x0B1400, -EDEV_ABORTED_COMMAND, "Recorded Entity Not Found" }, + { 0x0B1401, -EDEV_ABORTED_COMMAND, "Record Not Found" }, + { 0x0B1402, -EDEV_ABORTED_COMMAND, "Filemark or Setmark Not Found" }, + { 0x0B1B00, -EDEV_ABORTED_COMMAND, "Synchronous Data Transfer Error" }, + { 0x0B3D00, -EDEV_ABORTED_COMMAND, "Invalid Bits in Identify Message" }, + { 0x0B3F0F, -EDEV_ABORTED_COMMAND, "Echo Buffer Overwritten" }, + { 0x0B4100, -EDEV_ABORTED_COMMAND, "LDI command Failure" }, + { 0x0B4300, -EDEV_ABORTED_COMMAND, "Message Error" }, + { 0x0B4400, -EDEV_ABORTED_COMMAND, "Internal Target Failure" }, + { 0x0B4500, -EDEV_ABORTED_COMMAND, "Select/Reselect Failure" }, + { 0x0B4700, -EDEV_ABORTED_COMMAND, "SCSI Parity Error" }, + { 0x0B4703, -EDEV_ABORTED_COMMAND, "Information Unit iuCRC Error Detected" }, + { 0x0B4800, -EDEV_ABORTED_COMMAND, "Initiator Detected Error Message Received" }, + { 0x0B4900, -EDEV_ABORTED_COMMAND, "Invalid Message Error" }, + { 0x0B4A00, -EDEV_ABORTED_COMMAND, "Command Phase Error" }, + { 0x0B4B00, -EDEV_ABORTED_COMMAND, "Data Phase Error" }, + { 0x0B4B02, -EDEV_ABORTED_COMMAND, "Too Much Write Data" }, + { 0x0B4B03, -EDEV_ABORTED_COMMAND, "ACK/NAK Timeout" }, + { 0x0B4B04, -EDEV_ABORTED_COMMAND, "NAK Received" }, + { 0x0B4B05, -EDEV_ABORTED_COMMAND, "Data Offset Error" }, + { 0x0B4B06, -EDEV_TIMEOUT, "Initiator Response Timeout" }, + { 0x0B4E00, -EDEV_OVERLAPPED, "Overlapped Commands" }, + { 0x0B0801, -EDEV_ABORTED_COMMAND, "LU Communication - Timeout" }, /* Sense Key D (Volume Overflow) */ - {0x0D0002, -EDEV_OVERFLOW, "End-of-Partition/Medium Detected"}, + { 0x0D0002, -EDEV_OVERFLOW, "End-of-Partition/Medium Detected" }, /* END MARK*/ - {0xFFFFFF, -EDEV_UNKNOWN, "Unknown Error code"}, + { 0xFFFFFF, -EDEV_UNKNOWN, "Unknown Error code" }, }; -int get_vendor_id(char* vendor) +int get_vendor_id(char *vendor) { if (!strncmp(vendor, IBM_VENDOR_ID, strlen(IBM_VENDOR_ID))) return VENDOR_IBM; @@ -314,7 +314,7 @@ struct supported_device **get_supported_devs(int vendor) return cur; } -bool drive_has_supported_fw(int vendor, int drive_type, const unsigned char * const revision) +bool drive_has_supported_fw(int vendor, int drive_type, const unsigned char *const revision) { bool ret = false; @@ -372,8 +372,8 @@ int is_supported_tape(unsigned char type, unsigned char density, bool *is_worm) int ret = -LTFS_UNSUPPORTED_MEDIUM, i; for (i = 0; i < num_supported_cart; ++i) { - if(type == supported_cart[i]) { - if(IS_WORM_MEDIUM(type)) { + if (type == supported_cart[i]) { + if (IS_WORM_MEDIUM(type)) { /* Detect WORM cartridge */ ltfsmsg(LTFS_DEBUG, 39809D); *is_worm = true; @@ -386,7 +386,7 @@ int is_supported_tape(unsigned char type, unsigned char density, bool *is_worm) if (!ret) { ret = -LTFS_UNSUPPORTED_MEDIUM; for (i = 0; i < num_supported_density; ++i) { - if(density == supported_density[i]) { + if (density == supported_density[i]) { ret = 0; break; } @@ -396,9 +396,7 @@ int is_supported_tape(unsigned char type, unsigned char density, bool *is_worm) return ret; } -void init_error_table(int vendor, - struct error_table **standard_table, - struct error_table **vendor_table) +void init_error_table(int vendor, struct error_table **standard_table, struct error_table **vendor_table) { *standard_table = standard_tape_errors; @@ -437,7 +435,7 @@ int init_timeout(int vendor, struct timeout_tape **table, int type) int init_timeout_rsoc(struct timeout_tape **table, unsigned char *buf, uint32_t len) { int entries = len / RSOC_ENT_SIZE; - int modulo = len % RSOC_ENT_SIZE; + int modulo = len % RSOC_ENT_SIZE; int i = 0, offset = 0; int op_code, timeout; struct timeout_tape *entry, *out = NULL; @@ -450,7 +448,7 @@ int init_timeout_rsoc(struct timeout_tape **table, unsigned char *buf, uint32_t HASH_CLEAR(hh, *table); for (i = 0; i < entries; i++) { - offset = RSOC_HEADER_SIZE + (RSOC_ENT_SIZE * i); + offset = RSOC_HEADER_SIZE + (RSOC_ENT_SIZE * i); op_code = (int)(*((unsigned char *)(buf + offset))); timeout = (int)(ltfs_betou32(buf + offset + RSOC_RECOM_TO_OFFSET)); @@ -467,17 +465,18 @@ int init_timeout_rsoc(struct timeout_tape **table, unsigned char *buf, uint32_t return 0; } -void destroy_timeout(struct timeout_tape** table) +void destroy_timeout(struct timeout_tape **table) { struct timeout_tape *entry, *tmp; - HASH_ITER(hh, *table, entry, tmp) { + HASH_ITER(hh, *table, entry, tmp) + { HASH_DEL(*table, entry); free(entry); } } -int get_timeout(struct timeout_tape* table, int op_code) +int get_timeout(struct timeout_tape *table, int op_code) { struct timeout_tape *out = NULL; diff --git a/src/utils/ltfsck.c b/src/utils/ltfsck.c index fb1e4250..258180c9 100644 --- a/src/utils/ltfsck.c +++ b/src/utils/ltfsck.c @@ -48,11 +48,11 @@ */ #ifdef mingw_PLATFORM -#include "arch/win/win_util.h" +# include "arch/win/win_util.h" #else -#include -#include -#include +# include +# include +# include #endif /* mingw_PLATFORM */ #include @@ -60,22 +60,22 @@ #include "libltfs/ltfs_fuse_version.h" #include -#include "libltfs/ltfs_internal.h" +#include "libltfs/arch/time_internal.h" +#include "libltfs/kmi.h" #include "libltfs/ltfs.h" -#include "ltfs_copyright.h" +#include "libltfs/ltfs_internal.h" #include "libltfs/plugin.h" #include "libltfs/tape.h" -#include "libltfs/arch/time_internal.h" -#include "libltfs/kmi.h" +#include "ltfs_copyright.h" #ifdef mingw_PLATFORM -static +static #endif -volatile char *copyright = LTFS_COPYRIGHT_0"\n"LTFS_COPYRIGHT_1"\n"LTFS_COPYRIGHT_2"\n" \ -LTFS_COPYRIGHT_3"\n"LTFS_COPYRIGHT_4"\n"LTFS_COPYRIGHT_5"\n"; + volatile char *copyright = LTFS_COPYRIGHT_0 "\n" LTFS_COPYRIGHT_1 "\n" LTFS_COPYRIGHT_2 "\n" LTFS_COPYRIGHT_3 + "\n" LTFS_COPYRIGHT_4 "\n" LTFS_COPYRIGHT_5 "\n"; #ifdef __APPLE__ -#include "libltfs/arch/osx/osx_string.h" +# include "libltfs/arch/osx/osx_string.h" #endif #ifdef mingw_PLATFORM @@ -85,7 +85,8 @@ extern char bin_ltfsck_dat[]; #endif /**< Operation mode */ -enum { +enum +{ MODE_CHECK, MODE_VERIFY, MODE_ROLLBACK, @@ -93,48 +94,50 @@ enum { }; /**< Search mode for index */ -enum { +enum +{ SEARCH_NONE, SEARCH_BY_GEN, }; -struct other_check_opts { +struct other_check_opts +{ struct config_file *config; /**< Configurate data read from the global LTFS config file. */ - char *devname; /**< Device to format */ - char *backend_path; /**< Path to tape backend shared library */ - char *kmi_backend_name; /**< Name or path to the key manager interface backend library */ - int op_mode; /**< Operation mode */ - int search_mode; /**< Search mode for index */ - char *str_gen; /**< Rollback point specified by command line (generation)*/ - unsigned int point_gen; /**< Rollback point (generation) */ - bool erase_history; /**< overwrite existing data at rollback */ - bool recover_blocks; /**< Recover unreferenced blocks at the ends of the partitions? */ - bool deep_recovery; /**< Recover EOD missing cartridge? */ - int verbosity; /**< Print extra messages? */ - char *prg_name; /**< Program name */ - bool quiet; /**< Suppress information messages */ - bool trace; /**< Generate debug output */ - bool syslogtrace; /**< Generate debug output to stderr and syslog*/ - bool fulltrace; /**< Trace function calls */ - int traverse_mode; /**< Traverse strategy for listing index */ - bool full_index_info; /**< Print full index infomation in list mode */ - bool capture_index; /**< Capture index in list mode */ - bool salvage_points; /**< List rollback points from no-EOD cartridge? */ + char *devname; /**< Device to format */ + char *backend_path; /**< Path to tape backend shared library */ + char *kmi_backend_name; /**< Name or path to the key manager interface backend library */ + int op_mode; /**< Operation mode */ + int search_mode; /**< Search mode for index */ + char *str_gen; /**< Rollback point specified by command line (generation)*/ + unsigned int point_gen; /**< Rollback point (generation) */ + bool erase_history; /**< overwrite existing data at rollback */ + bool recover_blocks; /**< Recover unreferenced blocks at the ends of the partitions? */ + bool deep_recovery; /**< Recover EOD missing cartridge? */ + int verbosity; /**< Print extra messages? */ + char *prg_name; /**< Program name */ + bool quiet; /**< Suppress information messages */ + bool trace; /**< Generate debug output */ + bool syslogtrace; /**< Generate debug output to stderr and syslog*/ + bool fulltrace; /**< Trace function calls */ + int traverse_mode; /**< Traverse strategy for listing index */ + bool full_index_info; /**< Print full index infomation in list mode */ + bool capture_index; /**< Capture index in list mode */ + bool salvage_points; /**< List rollback points from no-EOD cartridge? */ }; struct index_info { - unsigned int generation; /**< Generation number written to tape */ - tape_position position; /**< tape position of the index including partition */ - struct ltfs_timespec mod_time; /**< time of last modification */ - struct tape_offset selfptr; /**< self-pointer (where this index was recovered from tape) */ - struct tape_offset backptr; /**< back pointer (to prior generation on data partition) */ - char *commit_message; /**< commit message */ - struct index_info *next; /**< link to the next entry */ - int version; /**< version number of XML */ - char *creator; /**< creator string */ - char *volume_name; /**< volume name */ - bool criteria_allow_update; /**< criteria mutable? */ + unsigned int generation; /**< Generation number written to tape */ + tape_position position; /**< tape position of the index including partition */ + struct ltfs_timespec mod_time; /**< time of last modification */ + struct tape_offset selfptr; /**< self-pointer (where this index was recovered from tape) */ + struct tape_offset backptr; /**< back pointer (to prior generation on data partition) */ + char *commit_message; /**< commit message */ + struct index_info *next; /**< link to the next entry */ + int version; /**< version number of XML */ + char *creator; /**< creator string */ + char *volume_name; /**< volume name */ + bool criteria_allow_update; /**< criteria mutable? */ const struct index_criteria *criteria; /**< index criteria */ }; @@ -147,10 +150,10 @@ struct partition_info struct rollback_info { - struct ltfs_index *current; + struct ltfs_index *current; struct tape_offset current_pos; - struct ltfs_index *target; - struct index_info *target_info; + struct ltfs_index *target; + struct index_info *target_info; }; /* Forward declarations */ @@ -164,65 +167,64 @@ void print_criteria_info(struct ltfs_volume *vol); /* Command line options */ static const char *short_options = "i:e:g:v:rnfzlmjkqtxhpoV"; -static struct option long_options[] = { - {"config", 1, 0, 'i'}, - {"backend", 1, 0, 'e'}, - {"generation", 1, 0, 'g'}, - {"traverse", 1, 0, 'v'}, - {"kmi-backend", 1, 0, '-'}, - {"capture-index", 0, 0, '+'}, - {"rollback" , 0, 0, 'r'}, - {"no-rollback" , 0, 0, 'n'}, - {"full-recovery" , 0, 0, 'f'}, - {"deep-recovery" , 0, 0, 'z'}, - {"list-rollback-points", 0, 0, 'l'}, - {"salvage-rollback-points", 0, 0, 0}, - {"full-index-info" , 0, 0, 'm'}, - {"erase-history", 0, 0, 'j'}, - {"keep-history", 0, 0, 'k'}, - {"quiet", 0, 0, 'q'}, - {"trace", 0, 0, 't'}, - {"syslogtrace", 0, 0, '!'}, - {"fulltrace", 0, 0, 'x'}, - {"help", 0, 0, 'h'}, - {"advanced-help", 0, 0, 'p'}, - {"version", 0, 0, 'V' }, - {0, 0, 0, 0} -}; +static struct option long_options[] = { { "config", 1, 0, 'i' }, + { "backend", 1, 0, 'e' }, + { "generation", 1, 0, 'g' }, + { "traverse", 1, 0, 'v' }, + { "kmi-backend", 1, 0, '-' }, + { "capture-index", 0, 0, '+' }, + { "rollback", 0, 0, 'r' }, + { "no-rollback", 0, 0, 'n' }, + { "full-recovery", 0, 0, 'f' }, + { "deep-recovery", 0, 0, 'z' }, + { "list-rollback-points", 0, 0, 'l' }, + { "salvage-rollback-points", 0, 0, 0 }, + { "full-index-info", 0, 0, 'm' }, + { "erase-history", 0, 0, 'j' }, + { "keep-history", 0, 0, 'k' }, + { "quiet", 0, 0, 'q' }, + { "trace", 0, 0, 't' }, + { "syslogtrace", 0, 0, '!' }, + { "fulltrace", 0, 0, 'x' }, + { "help", 0, 0, 'h' }, + { "advanced-help", 0, 0, 'p' }, + { "version", 0, 0, 'V' }, + { 0, 0, 0, 0 } }; #ifdef mingw_PLATFORM static #endif -void show_usage(char *appname, struct config_file *config, bool full) + void + show_usage(char *appname, struct config_file *config, bool full) { - ltfsresult(16400I, appname); /* Usage: %s [options] filesys */ + ltfsresult(16400I, appname); /* Usage: %s [options] filesys */ fprintf(stderr, "\n"); - ltfsresult(16401I); /* filesys Device file for the tape drive */ + ltfsresult(16401I); /* filesys Device file for the tape drive */ fprintf(stderr, "\n"); - ltfsresult(16402I); /* Available options are: */ - ltfsresult(16403I); /* -g, --generation */ - ltfsresult(16404I); /* -r, --rollback */ - ltfsresult(16405I); /* -n, --no-rollback */ + ltfsresult(16402I); /* Available options are: */ + ltfsresult(16403I); /* -g, --generation */ + ltfsresult(16404I); /* -r, --rollback */ + ltfsresult(16405I); /* -n, --no-rollback */ ltfsresult(16406I, LTFS_LOSTANDFOUND_DIR); /* -f, --full-recovery */ - ltfsresult(16421I); /* -z --deep-recovery */ - ltfsresult(16407I); /* -l, --list-rollback-points */ - ltfsresult(16422I); /* -m, --full-index-info */ - ltfsresult(16420I); /* -v, --traverse */ - ltfsresult(16408I); /* -j, --erase-history */ - ltfsresult(16409I); /* -k, --keep-history */ - ltfsresult(16410I); /* -q, --quiet */ - ltfsresult(16411I); /* -t, --trace */ - ltfsresult(16425I); /* --syslogtrace */ - ltfsresult(16426I); /* -V --version */ - ltfsresult(16412I); /* -h, --help */ - ltfsresult(16413I); /* -p, --advanced-help */ + ltfsresult(16421I); /* -z --deep-recovery */ + ltfsresult(16407I); /* -l, --list-rollback-points */ + ltfsresult(16422I); /* -m, --full-index-info */ + ltfsresult(16420I); /* -v, --traverse */ + ltfsresult(16408I); /* -j, --erase-history */ + ltfsresult(16409I); /* -k, --keep-history */ + ltfsresult(16410I); /* -q, --quiet */ + ltfsresult(16411I); /* -t, --trace */ + ltfsresult(16425I); /* --syslogtrace */ + ltfsresult(16426I); /* -V --version */ + ltfsresult(16412I); /* -h, --help */ + ltfsresult(16413I); /* -p, --advanced-help */ if (full) { - ltfsresult(16414I, LTFS_CONFIG_FILE); /* -i, --config= */ - ltfsresult(16415I); /* -e, --backend= */ - ltfsresult(16423I); /* --kmi-backend= */ - ltfsresult(16416I); /* -x, --fulltrace */ - ltfsresult(16424I); /* --capture-index */ - ltfsresult(16427I); /* --salvage-rollback-points */ + ltfsresult(16414I, LTFS_CONFIG_FILE); /* -i, --config= */ + ltfsresult(16415I); /* -e, --backend= */ + ltfsresult(16423I); /* --kmi-backend= */ + ltfsresult(16416I); /* -x, --fulltrace */ + ltfsresult(16424I); /* --capture-index */ + ltfsresult(16427I); /* --salvage-rollback-points */ fprintf(stderr, "\n"); plugin_usage(appname, "driver", config); fprintf(stderr, "\n"); @@ -242,21 +244,23 @@ int main(int argc, char **argv) int fuse_argc = argc; char **fuse_argv = calloc(fuse_argc, sizeof(char *)); - if (! fuse_argv) { + if (!fuse_argv) { return LTFSCK_OPERATIONAL_ERROR; } for (i = 0; i < fuse_argc; ++i) { fuse_argv[i] = arch_strdup(argv[i]); - if (! fuse_argv[i]) { + if (!fuse_argv[i]) { return LTFSCK_OPERATIONAL_ERROR; } } struct fuse_args args = FUSE_ARGS_INIT(fuse_argc, fuse_argv); /* Check for LANG variable and set it to en_US.UTF-8 if it is unset. */ - arch_getenv(lang,"LANG"); - if (! lang) { - fprintf(stderr, "LTFS9015W Setting the locale to 'en_US.UTF-8'. If this is wrong, please set the LANG environment variable before starting ltfsck.\n"); + arch_getenv(lang, "LANG"); + if (!lang) { + fprintf(stderr, + "LTFS9015W Setting the locale to 'en_US.UTF-8'. If this is wrong, please set the LANG environment variable " + "before starting ltfsck.\n"); ret = setenv("LANG", "en_US.UTF-8", 1); if (ret) { fprintf(stderr, "LTFS9016E Cannot set the LANG environment variable\n"); @@ -300,8 +304,7 @@ int main(int argc, char **argv) while (true) { int option_index = 0; int c = getopt_long(argc, argv, short_options, long_options, &option_index); - if (c == -1) - break; + if (c == -1) break; if (c == 'i') { config_file = arch_strdup(optarg); break; @@ -320,10 +323,8 @@ int main(int argc, char **argv) int num_of_o = 0; while (true) { int option_index = 0; - int c = getopt_long(argc, argv, short_options, - long_options, &option_index); - if (c == -1) - break; + int c = getopt_long(argc, argv, short_options, long_options, &option_index); + if (c == -1) break; switch (c) { case 0: @@ -338,15 +339,14 @@ int main(int argc, char **argv) opt.backend_path = arch_strdup(optarg); break; case 'g': - if(opt.op_mode == MODE_CHECK) - opt.op_mode = MODE_VERIFY; + if (opt.op_mode == MODE_CHECK) opt.op_mode = MODE_VERIFY; opt.search_mode = SEARCH_BY_GEN; opt.str_gen = arch_strdup(optarg); break; case 'v': - if ( strcmp(optarg, "forward") == 0) + if (strcmp(optarg, "forward") == 0) opt.traverse_mode = TRAVERSE_FORWARD; - else if ( strcmp(optarg, "backward") == 0) + else if (strcmp(optarg, "backward") == 0) opt.traverse_mode = TRAVERSE_BACKWARD; else opt.traverse_mode = TRAVERSE_UNKNOWN; @@ -368,7 +368,7 @@ int main(int argc, char **argv) opt.recover_blocks = true; break; case 'z': - opt.deep_recovery = true; + opt.deep_recovery = true; break; case 'l': opt.op_mode = MODE_LIST_POINT; @@ -416,23 +416,22 @@ int main(int argc, char **argv) } /* Pick up default backend if one wasn't specified before */ - if (! opt.backend_path) { + if (!opt.backend_path) { const char *default_backend = config_file_get_default_plugin("tape", opt.config); - if (! default_backend) { + if (!default_backend) { ltfsmsg(LTFS_ERR, 10009E); return LTFSCK_OPERATIONAL_ERROR; } opt.backend_path = arch_strdup(default_backend); } - if (! opt.kmi_backend_name) { + if (!opt.kmi_backend_name) { const char *default_backend = config_file_get_default_plugin("kmi", opt.config); if (default_backend) opt.kmi_backend_name = arch_strdup(default_backend); else opt.kmi_backend_name = arch_strdup("none"); } - if (opt.kmi_backend_name && strcmp(opt.kmi_backend_name, "none") == 0) - opt.kmi_backend_name = NULL; + if (opt.kmi_backend_name && strcmp(opt.kmi_backend_name, "none") == 0) opt.kmi_backend_name = NULL; /* Set the logging level */ if (opt.quiet && (opt.trace || opt.fulltrace)) { @@ -462,7 +461,7 @@ int main(int argc, char **argv) ltfsmsg(LTFS_INFO, 16000I, PACKAGE_NAME, PACKAGE_VERSION, log_level); /* Show command line arguments */ - for (i = 0, cmd_args_len = 0 ; i < argc; i++) { + for (i = 0, cmd_args_len = 0; i < argc; i++) { cmd_args_len += strlen(argv[i]) + 1; } cmd_args = calloc(1, cmd_args_len + 1); @@ -493,8 +492,7 @@ int main(int argc, char **argv) return LTFSCK_OPERATIONAL_ERROR; } - if(argv[optind + num_of_o]) - opt.devname = arch_strdup(argv[optind + num_of_o]); + if (argv[optind + num_of_o]) opt.devname = arch_strdup(argv[optind + num_of_o]); opt.prg_name = arch_strdup(argv[0]); @@ -505,8 +503,7 @@ int main(int argc, char **argv) } ret = ltfs_fs_init(); - if (ret) - return LTFSCK_OPERATIONAL_ERROR; + if (ret) return LTFSCK_OPERATIONAL_ERROR; ret = ltfsck(vol, &opt, &args); @@ -524,7 +521,7 @@ int ltfsck(struct ltfs_volume *vol, struct other_check_opts *opt, void *args) { int ret, ret_close; struct libltfs_plugin backend; /* tape driver backend */ - struct libltfs_plugin kmi; /* key manager interface backend */ + struct libltfs_plugin kmi; /* key manager interface backend */ /* load the backend, open the tape device, and load a tape */ ret = plugin_load(&backend, "tape", opt->backend_path, opt->config); @@ -564,8 +561,7 @@ int ltfsck(struct ltfs_volume *vol, struct other_check_opts *opt, void *args) } ret = tape_clear_key(vol->device, vol->kmi_handle); - if (ret < 0) - goto out_unload_backend; + if (ret < 0) goto out_unload_backend; } { int i = 0; @@ -595,48 +591,47 @@ int ltfsck(struct ltfs_volume *vol, struct other_check_opts *opt, void *args) } switch (opt->op_mode) { - case MODE_CHECK: - ltfsmsg(LTFS_INFO, 16014I, opt->devname); - opt->full_index_info = false; - ret = check_ltfs_volume(vol, opt); - break; - case MODE_ROLLBACK: - ltfsmsg(LTFS_INFO, 16015I, opt->devname); - opt->full_index_info = false; - switch(opt->search_mode) { - case SEARCH_BY_GEN: - ret = rollback(vol, opt); + case MODE_CHECK: + ltfsmsg(LTFS_INFO, 16014I, opt->devname); + opt->full_index_info = false; + ret = check_ltfs_volume(vol, opt); break; - default: - ltfsmsg(LTFS_ERR, 16016E); - ret = LTFSCK_USAGE_SYNTAX_ERROR; + case MODE_ROLLBACK: + ltfsmsg(LTFS_INFO, 16015I, opt->devname); + opt->full_index_info = false; + switch (opt->search_mode) { + case SEARCH_BY_GEN: + ret = rollback(vol, opt); + break; + default: + ltfsmsg(LTFS_ERR, 16016E); + ret = LTFSCK_USAGE_SYNTAX_ERROR; + break; + } break; - } - break; - case MODE_VERIFY: - ltfsmsg(LTFS_INFO, 16017I, opt->devname); - opt->full_index_info = false; - switch(opt->search_mode) { - case SEARCH_BY_GEN: - ret = rollback(vol, opt); - if (ret == LTFSCK_CORRECTED) - ret = LTFSCK_NO_ERRORS; + case MODE_VERIFY: + ltfsmsg(LTFS_INFO, 16017I, opt->devname); + opt->full_index_info = false; + switch (opt->search_mode) { + case SEARCH_BY_GEN: + ret = rollback(vol, opt); + if (ret == LTFSCK_CORRECTED) ret = LTFSCK_NO_ERRORS; + break; + default: + ltfsmsg(LTFS_ERR, 16016E); + show_usage(opt->prg_name, opt->config, false); + ret = LTFSCK_USAGE_SYNTAX_ERROR; + break; + } + break; + case MODE_LIST_POINT: + ltfsmsg(LTFS_INFO, 16018I, opt->devname); + ret = list_rollback_points(vol, opt); break; default: - ltfsmsg(LTFS_ERR, 16016E); - show_usage(opt->prg_name, opt->config, false); + ltfsmsg(LTFS_ERR, 16019E); ret = LTFSCK_USAGE_SYNTAX_ERROR; break; - } - break; - case MODE_LIST_POINT: - ltfsmsg(LTFS_INFO, 16018I, opt->devname); - ret = list_rollback_points(vol, opt); - break; - default: - ltfsmsg(LTFS_ERR, 16019E); - ret = LTFSCK_USAGE_SYNTAX_ERROR; - break; } /* close the tape device and unload the backend */ @@ -705,7 +700,7 @@ int check_ltfs_volume(struct ltfs_volume *vol, struct other_check_opts *opt) ret = ltfs_mount(true, true, opt->recover_blocks, true, 0, vol); if (ret < 0) { - if(ret == -LTFS_BOTH_EOD_MISSING && opt->deep_recovery) { + if (ret == -LTFS_BOTH_EOD_MISSING && opt->deep_recovery) { /* CM corrupted? try -o force_mount_no_eod */ ltfsmsg(LTFS_ERR, 16093E); ltfsmsg(LTFS_ERR, 16094E); @@ -723,11 +718,11 @@ int check_ltfs_volume(struct ltfs_volume *vol, struct other_check_opts *opt) } } -struct index_info* _add_list(struct index_info *new, struct index_info *list) +struct index_info *_add_list(struct index_info *new, struct index_info *list) { struct index_info *ret, *cur; - if(!(list)) { + if (!(list)) { ret = new; } else { cur = list; @@ -735,9 +730,8 @@ struct index_info* _add_list(struct index_info *new, struct index_info *list) new->next = cur; ret = new; } else { - while(cur->next != NULL) { - if(cur->next->generation > new-> generation) - break; + while (cur->next != NULL) { + if (cur->next->generation > new->generation) break; cur = cur->next; } new->next = cur->next; @@ -770,12 +764,9 @@ void destroy_index_array(struct index_info *list) while (cur) { next = cur->next; - if (cur->commit_message) - free(cur->commit_message); - if (cur->creator) - free(cur->creator); - if (cur->volume_name) - free(cur->volume_name); + if (cur->commit_message) free(cur->commit_message); + if (cur->creator) free(cur->creator); + if (cur->volume_name) free(cur->volume_name); free(cur); cur = next; } @@ -783,7 +774,7 @@ void destroy_index_array(struct index_info *list) return; } -struct index_info * _make_new_index(struct ltfs_volume *vol) +struct index_info *_make_new_index(struct ltfs_volume *vol) { int ret; struct index_info *new; @@ -795,10 +786,10 @@ struct index_info * _make_new_index(struct ltfs_volume *vol) } new->next = NULL; - new->generation = ltfs_get_index_generation(vol); - new->mod_time = ltfs_get_index_time(vol); - new->selfptr = ltfs_get_index_selfpointer(vol); - new->backptr = ltfs_get_index_backpointer(vol); + new->generation = ltfs_get_index_generation(vol); + new->mod_time = ltfs_get_index_time(vol); + new->selfptr = ltfs_get_index_selfpointer(vol); + new->backptr = ltfs_get_index_backpointer(vol); new->criteria = ltfs_get_index_criteria(vol); new->criteria_allow_update = ltfs_get_criteria_allow_update(vol); @@ -828,16 +819,16 @@ void _print_index_header(bool full_info) printf("Time zone: %s\n", get_local_timezone()); printf("Generation: Date Time SelfPtr->BackPtr (Part, Pos)\n"); if (strcmp(get_local_timezone(), TIMEZONE_UTC) != 0) { - printf(" (UTC Date UTC Time) \n"); + printf(" (UTC Date UTC Time) \n"); } #else printf("Generation: Date Time Zone SelfPtr->BackPtr (Part, Pos)\n"); printf(" (UTC Date UTC Time UTC) \n"); #endif - if(full_info) { - printf(" LTFS Format Version, Creator\n"); - printf(" Volume name\n"); - printf(" Placement Policy: [Overwrite] size_threshold pattern\n"); + if (full_info) { + printf(" LTFS Format Version, Creator\n"); + printf(" Volume name\n"); + printf(" Placement Policy: [Overwrite] size_threshold pattern\n"); } printf(" Commit Message \n"); printf("-------------------------------------------------------------------------------\n"); @@ -848,59 +839,99 @@ void _print_index(struct ltfs_volume *vol, struct index_info *list, struct other struct tm *t_st; int i; - if(!opt) - return; + if (!opt) return; t_st = get_localtime(&list->mod_time.tv_sec); - if (list->generation == (unsigned int)-1){ - printf("%s: %04d-%02d-%02d %02d:%02d:%02d.%09ld %s (%d, %"PRIu64")->(\?\?, \?\?)\n", - " WRONG VER", 0, 0, 0, - 0, 0, 0, (unsigned long) 0, "---", - ltfs_part_id2num(list->selfptr.partition, vol), list->selfptr.block); - } else if(list->backptr.partition == 0 && - list->backptr.block == 0) { - printf("%10d: %04d-%02d-%02d %02d:%02d:%02d.%09ld %s (%d, %"PRIu64") <>\n", - list->generation, t_st->tm_year+1900, t_st->tm_mon+1, t_st->tm_mday, + if (list->generation == (unsigned int)-1) { + printf("%s: %04d-%02d-%02d %02d:%02d:%02d.%09ld %s (%d, %" PRIu64 ")->(\?\?, \?\?)\n", + " WRONG VER", + 0, + 0, + 0, + 0, + 0, + 0, + (unsigned long)0, + "---", + ltfs_part_id2num(list->selfptr.partition, vol), + list->selfptr.block); + } else if (list->backptr.partition == 0 && list->backptr.block == 0) { + printf("%10d: %04d-%02d-%02d %02d:%02d:%02d.%09ld %s (%d, %" PRIu64 ") <>\n", + list->generation, + t_st->tm_year + 1900, + t_st->tm_mon + 1, + t_st->tm_mday, #ifdef mingw_PLATFORM - t_st->tm_hour, t_st->tm_min, t_st->tm_sec, list->mod_time.tv_nsec, " ", + t_st->tm_hour, + t_st->tm_min, + t_st->tm_sec, + list->mod_time.tv_nsec, + " ", #else - t_st->tm_hour, t_st->tm_min, t_st->tm_sec, list->mod_time.tv_nsec, t_st->tm_zone, + t_st->tm_hour, + t_st->tm_min, + t_st->tm_sec, + list->mod_time.tv_nsec, + t_st->tm_zone, #endif - ltfs_part_id2num(list->selfptr.partition, vol), list->selfptr.block); + ltfs_part_id2num(list->selfptr.partition, vol), + list->selfptr.block); } else { - printf("%10d: %04d-%02d-%02d %02d:%02d:%02d.%09ld %s (%d, %"PRIu64")->(%d, %"PRIu64")\n", - list->generation, t_st->tm_year+1900, t_st->tm_mon+1, t_st->tm_mday, + printf("%10d: %04d-%02d-%02d %02d:%02d:%02d.%09ld %s (%d, %" PRIu64 ")->(%d, %" PRIu64 ")\n", + list->generation, + t_st->tm_year + 1900, + t_st->tm_mon + 1, + t_st->tm_mday, #ifdef mingw_PLATFORM - t_st->tm_hour, t_st->tm_min, t_st->tm_sec, list->mod_time.tv_nsec, " ", + t_st->tm_hour, + t_st->tm_min, + t_st->tm_sec, + list->mod_time.tv_nsec, + " ", #else - t_st->tm_hour, t_st->tm_min, t_st->tm_sec, list->mod_time.tv_nsec, t_st->tm_zone, + t_st->tm_hour, + t_st->tm_min, + t_st->tm_sec, + list->mod_time.tv_nsec, + t_st->tm_zone, #endif - ltfs_part_id2num(list->selfptr.partition, vol), list->selfptr.block, - ltfs_part_id2num(list->backptr.partition, vol), list->backptr.block); + ltfs_part_id2num(list->selfptr.partition, vol), + list->selfptr.block, + ltfs_part_id2num(list->backptr.partition, vol), + list->backptr.block); } /* Print UTC time */ if (list->generation == (unsigned int)-1) { - printf(" (%04d-%02d-%02d %02d:%02d:%02d.%09ld %s)\n", - 0, 0, 0, - 0, 0, 0, (unsigned long) 0, "---"); + printf(" (%04d-%02d-%02d %02d:%02d:%02d.%09ld %s)\n", 0, 0, 0, 0, 0, 0, (unsigned long)0, "---"); #ifdef mingw_PLATFORM - } else if(strcmp(get_local_timezone(), TIMEZONE_UTC) != 0) { + } else if (strcmp(get_local_timezone(), TIMEZONE_UTC) != 0) { t_st = get_gmtime(&list->mod_time.tv_sec); printf(" (%04d-%02d-%02d %02d:%02d:%02d.%09ld)\n", - t_st->tm_year+1900, t_st->tm_mon+1, t_st->tm_mday, - t_st->tm_hour, t_st->tm_min, t_st->tm_sec, list->mod_time.tv_nsec); + t_st->tm_year + 1900, + t_st->tm_mon + 1, + t_st->tm_mday, + t_st->tm_hour, + t_st->tm_min, + t_st->tm_sec, + list->mod_time.tv_nsec); #else - }else if(strcmp(t_st->tm_zone, "UTC") != 0) { + } else if (strcmp(t_st->tm_zone, "UTC") != 0) { const char *tz = getenv("TZ"); setenv("TZ", "", 1); tzset(); t_st = get_localtime(&list->mod_time.tv_sec); printf(" (%04d-%02d-%02d %02d:%02d:%02d.%09ld %s)\n", - t_st->tm_year+1900, t_st->tm_mon+1, t_st->tm_mday, - t_st->tm_hour, t_st->tm_min, t_st->tm_sec, list->mod_time.tv_nsec, t_st->tm_zone); - if(tz) + t_st->tm_year + 1900, + t_st->tm_mon + 1, + t_st->tm_mday, + t_st->tm_hour, + t_st->tm_min, + t_st->tm_sec, + list->mod_time.tv_nsec, + t_st->tm_zone); + if (tz) setenv("TZ", tz, 1); else unsetenv("TZ"); @@ -910,23 +941,24 @@ void _print_index(struct ltfs_volume *vol, struct index_info *list, struct other if (opt->full_index_info) { printf(" %d.%d.%d, \"%s\"\n", - list->version / 10000, (list->version / 100) % 100, list->version % 100, - list->creator); + list->version / 10000, + (list->version / 100) % 100, + list->version % 100, + list->creator); - if(list->volume_name) + if (list->volume_name) printf(" %s\n", list->volume_name); else printf(" No Volume Name\n"); - if(list->criteria && list->criteria->have_criteria) { + if (list->criteria && list->criteria->have_criteria) { printf(" [%s] ", list->criteria_allow_update ? " Allowed " : "Not allowed"); printf("%llu ", (long long unsigned int)list->criteria->max_filesize_criteria); - if(list->criteria->glob_patterns) { + if (list->criteria->glob_patterns) { i = 0; - while(1) { - if(list->criteria->glob_patterns[i].name == NULL) - break; + while (1) { + if (list->criteria->glob_patterns[i].name == NULL) break; printf("%s ", list->criteria->glob_patterns[i].name); i++; } @@ -936,18 +968,17 @@ void _print_index(struct ltfs_volume *vol, struct index_info *list, struct other printf(" No criteria\n"); } - if(list->commit_message) + if (list->commit_message) printf(" %s\n", list->commit_message); else printf(" No commit message\n"); - if (opt->capture_index) - ltfs_save_index_to_disk(".", NULL, true, vol); + if (opt->capture_index) ltfs_save_index_to_disk(".", NULL, true, vol); return; } -int print_a_index_noheader(struct ltfs_volume *vol, unsigned int target, void **list, void * priv) +int print_a_index_noheader(struct ltfs_volume *vol, unsigned int target, void **list, void *priv) { struct index_info *new; struct other_check_opts *opt = priv; @@ -955,8 +986,7 @@ int print_a_index_noheader(struct ltfs_volume *vol, unsigned int target, void ** CHECK_ARG_NULL(priv, LTFSCK_OPERATIONAL_ERROR); new = _make_new_index(vol); - if (!new) - return -ENOMEM; + if (!new) return -ENOMEM; _print_index(vol, new, opt); @@ -974,7 +1004,7 @@ void print_index_array(struct ltfs_volume *vol, struct index_info *list, void *o while (cur) { _print_index(vol, cur, opt); - cur = cur-> next; + cur = cur->next; } return; @@ -991,19 +1021,22 @@ void print_volume_info(struct ltfs_volume *vol) format_time = ltfs_get_format_time(vol); t_st = get_localtime(&(format_time.tv_sec)); - ltfsmsg(LTFS_INFO, 16026I, - t_st->tm_year+1900, t_st->tm_mon+1, t_st->tm_mday, - t_st->tm_hour, t_st->tm_min, t_st->tm_sec, format_time.tv_nsec, - t_st->tm_zone); + ltfsmsg(LTFS_INFO, + 16026I, + t_st->tm_year + 1900, + t_st->tm_mon + 1, + t_st->tm_mday, + t_st->tm_hour, + t_st->tm_min, + t_st->tm_sec, + format_time.tv_nsec, + t_st->tm_zone); ltfsmsg(LTFS_INFO, 16027I, ltfs_get_blocksize(vol)); ltfsmsg(LTFS_INFO, 16028I, ltfs_get_compression(vol) ? "Enabled" : "Disabled"); - ltfsmsg(LTFS_INFO, 16029I, - ltfs_ip_id(vol), ltfs_part_id2num(ltfs_ip_id(vol), vol)); - ltfsmsg(LTFS_INFO, 16030I, - ltfs_dp_id(vol), ltfs_part_id2num(ltfs_dp_id(vol), vol)); - if (ltfs_log_level >= LTFS_INFO) - fprintf(stderr, "\n"); + ltfsmsg(LTFS_INFO, 16029I, ltfs_ip_id(vol), ltfs_part_id2num(ltfs_ip_id(vol), vol)); + ltfsmsg(LTFS_INFO, 16030I, ltfs_dp_id(vol), ltfs_part_id2num(ltfs_dp_id(vol), vol)); + if (ltfs_log_level >= LTFS_INFO) fprintf(stderr, "\n"); return; } @@ -1014,24 +1047,21 @@ void print_criteria_info(struct ltfs_volume *vol) bool update = ltfs_get_criteria_allow_update(vol); const struct index_criteria *ic = ltfs_get_index_criteria(vol); - if(ic->have_criteria) { + if (ic->have_criteria) { ltfsmsg(LTFS_INFO, 16031I); - ltfsmsg(LTFS_INFO, 16032I, - (unsigned long long)ic->max_filesize_criteria); + ltfsmsg(LTFS_INFO, 16032I, (unsigned long long)ic->max_filesize_criteria); - if(ic->glob_patterns) { + if (ic->glob_patterns) { i = 0; - while(1) { - if(ic->glob_patterns[i].name == NULL) - break; + while (1) { + if (ic->glob_patterns[i].name == NULL) break; ltfsmsg(LTFS_INFO, 16033I, ic->glob_patterns[i].name); i++; } } ltfsmsg(LTFS_INFO, 16034I, update ? "Allowed" : "Not allowed"); - if (ltfs_log_level >= LTFS_INFO) - fprintf(stderr, "\n"); + if (ltfs_log_level >= LTFS_INFO) fprintf(stderr, "\n"); } return; @@ -1047,10 +1077,9 @@ int search_index_by_gen(struct ltfs_volume *vol, unsigned int target, void **lis return -LTFS_UNSUPPORTED_INDEX_VERSION; } - if(target == ltfs_get_index_generation(vol)) { + if (target == ltfs_get_index_generation(vol)) { new = _make_new_index(vol); - if (!new) - return -ENOMEM; + if (!new) return -ENOMEM; *list = _add_list(new, *list); return 1; /* return 1 to stop searcing */ @@ -1102,8 +1131,7 @@ int _erase_history(struct ltfs_volume *vol, struct other_check_opts *opt, struct pos.block = position->block; ret = tape_seek(vol->device, &pos); - if (ret < 0) - return LTFSCK_OPERATIONAL_ERROR; + if (ret < 0) return LTFSCK_OPERATIONAL_ERROR; ltfsmsg(LTFS_DEBUG, 16050D); ret = tape_spacefm(vol->device, 1); @@ -1132,13 +1160,11 @@ int _rollback_ip(struct ltfs_volume *vol, struct other_check_opts *opt, struct t { int ret; - if (position) - ltfsmsg(LTFS_DEBUG, 16046D, "IP", (int)position->partition, (unsigned long long)position->block); + if (position) ltfsmsg(LTFS_DEBUG, 16046D, "IP", (int)position->partition, (unsigned long long)position->block); - if(opt->erase_history && position) { + if (opt->erase_history && position) { ret = _erase_history(vol, opt, position); - if (ret != LTFSCK_NO_ERRORS) - ltfsmsg(LTFS_ERR, 16059E, ret); + if (ret != LTFSCK_NO_ERRORS) ltfsmsg(LTFS_ERR, 16059E, ret); } else { ret = ltfs_write_index(ltfs_ip_id(vol), SYNC_ROLLBACK, vol); if (ret < 0) { @@ -1156,10 +1182,9 @@ int _rollback_dp(struct ltfs_volume *vol, struct other_check_opts *opt, struct t ltfsmsg(LTFS_DEBUG, 16046D, "DP", (int)position->partition, (unsigned long long)position->block); - if(opt->erase_history && position) { + if (opt->erase_history && position) { ret = _erase_history(vol, opt, position); - if (ret != LTFSCK_NO_ERRORS) - ltfsmsg(LTFS_ERR, 16055E, ret); + if (ret != LTFSCK_NO_ERRORS) ltfsmsg(LTFS_ERR, 16055E, ret); } else { ret = ltfs_write_index(ltfs_dp_id(vol), SYNC_ROLLBACK, vol); if (ret < 0) { @@ -1183,22 +1208,21 @@ int _rollback(struct ltfs_volume *vol, struct other_check_opts *opt, struct roll if (opt->op_mode == MODE_ROLLBACK) { ret = ltfs_get_partition_readonly(ltfs_ip_id(vol), vol); - if (! ret || ret == -LTFS_NO_SPACE || ret == -LTFS_LESS_SPACE) + if (!ret || ret == -LTFS_NO_SPACE || ret == -LTFS_LESS_SPACE) ret = ltfs_get_partition_readonly(ltfs_dp_id(vol), vol); - if (ret < 0 && ret != -LTFS_NO_SPACE && ret != -LTFS_LESS_SPACE) { /* Try to roll back even in low space condition. */ + if (ret < 0 && ret != -LTFS_NO_SPACE && + ret != -LTFS_LESS_SPACE) { /* Try to roll back even in low space condition. */ ltfsmsg(LTFS_ERR, 16057E); return LTFSCK_OPERATIONAL_ERROR; } /* Set target index and append position */ vol->index = rb->target; - if (! opt->erase_history) - vol->index->generation = rb->current->generation; + if (!opt->erase_history) vol->index->generation = rb->current->generation; ltfs_set_index_dirty(true, false, vol->index); /* no need to call set_ip_append_position becuase WORM cart cannot be rollbacked */ - ret = tape_set_append_position( - vol->device, ltfs_part_id2num(ltfs_ip_id(vol), vol), rb->current_pos.block - 1); + ret = tape_set_append_position(vol->device, ltfs_part_id2num(ltfs_ip_id(vol), vol), rb->current_pos.block - 1); if (ret < 0) { ltfsmsg(LTFS_ERR, 16079E, ret); return LTFSCK_OPERATIONAL_ERROR; @@ -1208,26 +1232,22 @@ int _rollback(struct ltfs_volume *vol, struct other_check_opts *opt, struct roll /* Recover from an index on index partition */ ltfsmsg(LTFS_INFO, 16058I); ret = _rollback_dp(vol, opt, &(rb->target->backptr)); - if (ret != LTFSCK_NO_ERRORS) - return ret; + if (ret != LTFSCK_NO_ERRORS) return ret; ret = _rollback_ip(vol, opt, &(rb->target->selfptr)); - if (ret != LTFSCK_NO_ERRORS) - return ret; + if (ret != LTFSCK_NO_ERRORS) return ret; } else if (rb->target_info->selfptr.partition == ltfs_dp_id(vol)) { /* Recover from an index on data partition */ ltfsmsg(LTFS_INFO, 16062I); ret = _rollback_dp(vol, opt, &rb->target->selfptr); - if (ret != LTFSCK_NO_ERRORS) - return ret; + if (ret != LTFSCK_NO_ERRORS) return ret; ret = _rollback_ip(vol, opt, NULL); - if (ret != LTFSCK_NO_ERRORS) - return ret; + if (ret != LTFSCK_NO_ERRORS) return ret; } else { ltfsmsg(LTFS_ERR, 16061E, rb->target->selfptr.partition); return LTFSCK_OPERATIONAL_ERROR; } } - } else { + } else { ltfsmsg(LTFS_ERR, 16068E, index_num); print_index_array(vol, rb->target_info, opt); return LTFSCK_OPERATIONAL_ERROR; @@ -1239,14 +1259,14 @@ int _rollback(struct ltfs_volume *vol, struct other_check_opts *opt, struct roll int rollback(struct ltfs_volume *vol, struct other_check_opts *opt) { int ret; - struct rollback_info r; + struct rollback_info r; bool is_worm; memset(&r, 0, sizeof(struct rollback_info)); /* Load tape and read labels */ ret = load_tape(vol); - if (ret != LTFSCK_NO_ERRORS) { + if (ret != LTFSCK_NO_ERRORS) { ltfsmsg(LTFS_ERR, 16070E, ret); return ret; } @@ -1264,17 +1284,19 @@ int rollback(struct ltfs_volume *vol, struct other_check_opts *opt) /* Attempt to mount a medium to confirm the consistency */ ret = ltfs_mount(false, false, false, false, 0, vol); if (ret < 0) { - if(ret == -LTFS_BOTH_EOD_MISSING) + if (ret == -LTFS_BOTH_EOD_MISSING) ltfsmsg(LTFS_ERR, 16097E); else ltfsmsg(LTFS_ERR, 16087E); return LTFSCK_UNCORRECTED; - } - else { + } else { r.current = vol->index; r.current_pos = ltfs_get_index_selfpointer(vol); - ltfsmsg(LTFS_DEBUG, 16081D, ltfs_get_index_generation(vol), - (int)r.current_pos.partition, (unsigned long long)r.current_pos.block); + ltfsmsg(LTFS_DEBUG, + 16081D, + ltfs_get_index_generation(vol), + (int)r.current_pos.partition, + (unsigned long long)r.current_pos.block); ltfs_unmount(SYNC_ROLLBACK, vol); vol->index = NULL; } @@ -1286,28 +1308,29 @@ int rollback(struct ltfs_volume *vol, struct other_check_opts *opt) } /* Find target index */ - ret = ltfs_traverse_index_backward(vol, ltfs_ip_id(vol), opt->point_gen, - search_index_by_gen, (void *)(&(r.target_info)), (void *)opt); + ret = ltfs_traverse_index_backward( + vol, ltfs_ip_id(vol), opt->point_gen, search_index_by_gen, (void *)(&(r.target_info)), (void *)opt); if (ret == -LTFS_NO_INDEX) { if (opt->erase_history) { - ret = ltfs_traverse_index_forward(vol, ltfs_dp_id(vol), opt->point_gen, - search_index_by_gen, (void *)(&(r.target_info)), (void *)opt); + ret = ltfs_traverse_index_forward( + vol, ltfs_dp_id(vol), opt->point_gen, search_index_by_gen, (void *)(&(r.target_info)), (void *)opt); if (ret == -LTFS_NO_INDEX) { ltfsmsg(LTFS_ERR, 16072E, ret); return LTFSCK_OPERATIONAL_ERROR; } else if (ret < 0) { ltfsmsg(LTFS_ERR, 16072E, ret); - return LTFSCK_OPERATIONAL_ERROR;; + return LTFSCK_OPERATIONAL_ERROR; + ; } } else { - ret = ltfs_traverse_index_backward(vol, ltfs_dp_id(vol), opt->point_gen, - search_index_by_gen, (void *)(&(r.target_info)), (void *)opt); - if (ret != LTFSCK_NO_ERRORS) { + ret = ltfs_traverse_index_backward( + vol, ltfs_dp_id(vol), opt->point_gen, search_index_by_gen, (void *)(&(r.target_info)), (void *)opt); + if (ret != LTFSCK_NO_ERRORS) { ltfsmsg(LTFS_ERR, 16072E, ret); return LTFSCK_OPERATIONAL_ERROR; } } - } else if ( ret < 0) { + } else if (ret < 0) { ltfsmsg(LTFS_ERR, 16071E, ret); return ret; } @@ -1318,9 +1341,10 @@ int rollback(struct ltfs_volume *vol, struct other_check_opts *opt) struct tape_offset selfptr = ltfs_get_index_selfpointer(vol); ltfsmsg(LTFS_INFO, 16082I); ret = ltfs_get_partition_readonly(ltfs_ip_id(vol), vol); - if (! ret || ret == -LTFS_NO_SPACE || ret == -LTFS_LESS_SPACE) + if (!ret || ret == -LTFS_NO_SPACE || ret == -LTFS_LESS_SPACE) ret = ltfs_get_partition_readonly(ltfs_dp_id(vol), vol); - if (ret < 0 && ret != -LTFS_NO_SPACE && ret != -LTFS_LESS_SPACE) { /* Try to roll back even in low space condition. */ + if (ret < 0 && ret != -LTFS_NO_SPACE && + ret != -LTFS_LESS_SPACE) { /* Try to roll back even in low space condition. */ ltfsmsg(LTFS_ERR, 16057E); return LTFSCK_OPERATIONAL_ERROR; } @@ -1339,7 +1363,7 @@ int rollback(struct ltfs_volume *vol, struct other_check_opts *opt) } /* Check consistency after roll back and recovery if nessesary */ - if(ret == 0) { + if (ret == 0) { ret = ltfs_mount(true, true, false, false, 0, vol); if (ret < 0) { ltfsmsg(LTFS_ERR, 16021E); @@ -1362,7 +1386,7 @@ int list_rollback_points_normal(struct ltfs_volume *vol, struct other_check_opts /* Load tape and read labels */ ret = load_tape(vol); - if (ret != LTFSCK_NO_ERRORS) { + if (ret != LTFSCK_NO_ERRORS) { ltfsmsg(LTFS_ERR, 16074E, ret); return ret; } @@ -1370,7 +1394,7 @@ int list_rollback_points_normal(struct ltfs_volume *vol, struct other_check_opts /* Attempt to mount a medium to confirm the consistency */ ret = ltfs_mount(false, false, false, false, 0, vol); if (ret < 0) { - if(ret == -LTFS_BOTH_EOD_MISSING) + if (ret == -LTFS_BOTH_EOD_MISSING) ltfsmsg(LTFS_WARN, 16096W); else { ltfsmsg(LTFS_ERR, 16087E); @@ -1381,25 +1405,21 @@ int list_rollback_points_normal(struct ltfs_volume *vol, struct other_check_opts _print_index_header(opt->full_index_info); /* read index from the index partition */ - if(opt->traverse_mode == TRAVERSE_FORWARD) - ret = ltfs_traverse_index_forward(vol, ltfs_ip_id(vol), opt->point_gen, - print_a_index_noheader, NULL, (void *)opt); + if (opt->traverse_mode == TRAVERSE_FORWARD) + ret = ltfs_traverse_index_forward(vol, ltfs_ip_id(vol), opt->point_gen, print_a_index_noheader, NULL, (void *)opt); else - ret = ltfs_traverse_index_backward(vol, ltfs_ip_id(vol), opt->point_gen, - print_a_index_noheader, NULL, (void *)opt); - if (ret != LTFSCK_NO_ERRORS) { + ret = ltfs_traverse_index_backward(vol, ltfs_ip_id(vol), opt->point_gen, print_a_index_noheader, NULL, (void *)opt); + if (ret != LTFSCK_NO_ERRORS) { ltfsmsg(LTFS_ERR, 16075E, ret); return ret; } /* read index from the data partition */ - if(opt->traverse_mode == TRAVERSE_FORWARD) - ret = ltfs_traverse_index_forward(vol, ltfs_dp_id(vol), opt->point_gen, - print_a_index_noheader, NULL, (void *)opt); + if (opt->traverse_mode == TRAVERSE_FORWARD) + ret = ltfs_traverse_index_forward(vol, ltfs_dp_id(vol), opt->point_gen, print_a_index_noheader, NULL, (void *)opt); else - ret = ltfs_traverse_index_backward(vol, ltfs_dp_id(vol), opt->point_gen, - print_a_index_noheader, NULL, (void *)opt); - if (ret != LTFSCK_NO_ERRORS) { + ret = ltfs_traverse_index_backward(vol, ltfs_dp_id(vol), opt->point_gen, print_a_index_noheader, NULL, (void *)opt); + if (ret != LTFSCK_NO_ERRORS) { ltfsmsg(LTFS_ERR, 16076E, ret); } @@ -1413,7 +1433,7 @@ int list_rollback_points_no_eod(struct ltfs_volume *vol, struct other_check_opts /* Load tape and read labels */ ret = load_tape(vol); - if (ret != LTFSCK_NO_ERRORS) { + if (ret != LTFSCK_NO_ERRORS) { ltfsmsg(LTFS_ERR, 16074E, ret); return ret; } @@ -1433,9 +1453,8 @@ int list_rollback_points_no_eod(struct ltfs_volume *vol, struct other_check_opts /* Read index from the data partition */ /* We don't need to read IP because index in DP is always newer (or same) than IP in case of WORM */ - ret = ltfs_traverse_index_no_eod(vol, ltfs_dp_id(vol), opt->point_gen, - print_a_index_noheader, NULL, (void *)opt); - if (ret != LTFSCK_NO_ERRORS) { + ret = ltfs_traverse_index_no_eod(vol, ltfs_dp_id(vol), opt->point_gen, print_a_index_noheader, NULL, (void *)opt); + if (ret != LTFSCK_NO_ERRORS) { ltfsmsg(LTFS_ERR, 16076E, ret); } @@ -1448,8 +1467,7 @@ int list_rollback_points(struct ltfs_volume *vol, struct other_check_opts *opt) if (opt->salvage_points) { ret = list_rollback_points_no_eod(vol, opt); - } - else { + } else { ret = list_rollback_points_normal(vol, opt); } @@ -1458,7 +1476,7 @@ int list_rollback_points(struct ltfs_volume *vol, struct other_check_opts *opt) int _ltfsck_validate_options(struct other_check_opts *opt) { - if(opt->op_mode == MODE_VERIFY || opt->op_mode == MODE_ROLLBACK) { + if (opt->op_mode == MODE_VERIFY || opt->op_mode == MODE_ROLLBACK) { if (!opt->str_gen) { ltfsmsg(LTFS_ERR, 16003E); return LTFSCK_USAGE_SYNTAX_ERROR; @@ -1472,7 +1490,7 @@ int _ltfsck_validate_options(struct other_check_opts *opt) char *invalid_start; errno = 0; opt->point_gen = strtoul(opt->str_gen, &invalid_start, 0); - if( (*invalid_start == '\0') && opt->str_gen ) + if ((*invalid_start == '\0') && opt->str_gen) ltfsmsg(LTFS_INFO, 16006I, opt->point_gen); else { ltfsmsg(LTFS_ERR, 16005E, opt->str_gen); @@ -1487,8 +1505,8 @@ int _ltfsck_validate_options(struct other_check_opts *opt) return LTFSCK_USAGE_SYNTAX_ERROR; } - if(opt->op_mode == MODE_LIST_POINT) { - if ( opt->traverse_mode == TRAVERSE_FORWARD ) + if (opt->op_mode == MODE_LIST_POINT) { + if (opt->traverse_mode == TRAVERSE_FORWARD) ltfsmsg(LTFS_INFO, 16083I); else if (opt->traverse_mode == TRAVERSE_BACKWARD) ltfsmsg(LTFS_INFO, 16084I); @@ -1501,7 +1519,7 @@ int _ltfsck_validate_options(struct other_check_opts *opt) char *invalid_start; errno = 0; opt->point_gen = strtoul(opt->str_gen, &invalid_start, 0); - if( (*invalid_start == '\0') && opt->str_gen ) + if ((*invalid_start == '\0') && opt->str_gen) ltfsmsg(LTFS_INFO, 16006I, opt->point_gen); else { ltfsmsg(LTFS_ERR, 16005E, opt->str_gen); @@ -1510,7 +1528,6 @@ int _ltfsck_validate_options(struct other_check_opts *opt) opt->op_mode = MODE_VERIFY; } } - } if (!opt->devname) { diff --git a/src/utils/mkltfs.c b/src/utils/mkltfs.c index 9ad02890..cb8f50b9 100644 --- a/src/utils/mkltfs.c +++ b/src/utils/mkltfs.c @@ -52,31 +52,30 @@ */ #ifdef mingw_PLATFORM -#include "arch/win/win_util.h" +# include "arch/win/win_util.h" #else -#include +# include #endif /* mingw_PLATFORM */ - -#include "libltfs/ltfs_fuse_version.h" -#include -#include -#include "libltfs/ltfs.h" -#include "ltfs_copyright.h" #include "libltfs/index_criteria.h" +#include "libltfs/kmi.h" +#include "libltfs/ltfs.h" +#include "libltfs/ltfs_fuse_version.h" #include "libltfs/pathname.h" #include "libltfs/plugin.h" -#include "libltfs/kmi.h" #include "libltfs/tape.h" +#include "ltfs_copyright.h" +#include +#include #ifdef mingw_PLATFORM static #endif -volatile char *copyright = LTFS_COPYRIGHT_0"\n"LTFS_COPYRIGHT_1"\n"LTFS_COPYRIGHT_2"\n" \ - LTFS_COPYRIGHT_3"\n"LTFS_COPYRIGHT_4"\n"LTFS_COPYRIGHT_5"\n"; + volatile char *copyright = LTFS_COPYRIGHT_0 "\n" LTFS_COPYRIGHT_1 "\n" LTFS_COPYRIGHT_2 "\n" LTFS_COPYRIGHT_3 + "\n" LTFS_COPYRIGHT_4 "\n" LTFS_COPYRIGHT_5 "\n"; #ifdef __APPLE__ -#include "libltfs/arch/osx/osx_string.h" +# include "libltfs/arch/osx/osx_string.h" #endif #define INDEX_PART_ID 'a' @@ -90,66 +89,65 @@ char *bin_mkltfs_dat; extern char bin_mkltfs_dat[]; #endif -struct other_format_opts { +struct other_format_opts +{ struct config_file *config; /**< Configuration data read from the global LTFS config file */ - char *devname; /**< Device to format */ - char *backend_path; /**< Path to tape backend shared library */ - char *kmi_backend_name; /**< Name or path to the key manager interface backend library */ - char *volume_name; /**< Human-readable volume name */ - char *filterrules; /**< Rules for files that should go to the index partition */ - char *barcode; /**< 6-character cartridge barcode number */ - unsigned long blocksize; /**< Nominal tape block size */ - bool enable_compression; /**< Use compression on the tape? */ - bool allow_update; /**< Allow overriding index rules at mount time? */ - bool keep_capacity; /**< Reset tape capacity? */ - bool unformat; /**< Unformat medium? */ - bool force; /**< Force to format */ - bool quiet; /**< Quiet mode indicator */ - bool trace; /**< Debug mode indicator */ - bool syslogtrace; /**< Generate debug output to stderr and syslog*/ - bool fulltrace; /**< Full trace mode indicator */ - bool long_wipe; /**< Clean up whole tape by long erase? */ - bool destructive; /**< Use destructive FORMAT_MEDIUM or not */ + char *devname; /**< Device to format */ + char *backend_path; /**< Path to tape backend shared library */ + char *kmi_backend_name; /**< Name or path to the key manager interface backend library */ + char *volume_name; /**< Human-readable volume name */ + char *filterrules; /**< Rules for files that should go to the index partition */ + char *barcode; /**< 6-character cartridge barcode number */ + unsigned long blocksize; /**< Nominal tape block size */ + bool enable_compression; /**< Use compression on the tape? */ + bool allow_update; /**< Allow overriding index rules at mount time? */ + bool keep_capacity; /**< Reset tape capacity? */ + bool unformat; /**< Unformat medium? */ + bool force; /**< Force to format */ + bool quiet; /**< Quiet mode indicator */ + bool trace; /**< Debug mode indicator */ + bool syslogtrace; /**< Generate debug output to stderr and syslog*/ + bool fulltrace; /**< Full trace mode indicator */ + bool long_wipe; /**< Clean up whole tape by long erase? */ + bool destructive; /**< Use destructive FORMAT_MEDIUM or not */ }; /* Forward declarations */ int format_tape(struct ltfs_volume *vol, struct other_format_opts *opt, void *args); int unformat_tape(struct ltfs_volume *vol, struct other_format_opts *opt, void *args); -int _mkltfs_validate_options(char *prg_name, struct ltfs_volume *vol, - struct other_format_opts *opt); +int _mkltfs_validate_options(char *prg_name, struct ltfs_volume *vol, struct other_format_opts *opt); /* Command line options */ static const char *short_options = "i:e:d:b:s:n:r:cokwfqtxhpV"; -static struct option long_options[] = { - {"config", 1, 0, 'i'}, - {"backend", 1, 0, 'e'}, - {"device", 1, 0, 'd'}, - {"blocksize", 1, 0, 'b'}, - {"tape-serial", 1, 0, 's'}, - {"volume-name", 1, 0, 'n'}, - {"rules", 1, 0, 'r'}, - {"kmi-backend", 1, 0, '-'}, - {"no-compression", 0, 0, 'c'}, - {"no-override", 0, 0, ' '}, - {"keep-capacity", 0, 0, 'k'}, - {"wipe", 0, 0, 'w'}, - {"long-wipe", 0, 0, '+'}, - {"destructive", 0, 0, '&'}, - {"force", 0, 0, 'f'}, - {"quiet", 0, 0, 'q'}, - {"trace", 0, 0, 't'}, - {"syslogtrace", 0, 0, '!'}, - {"fulltrace", 0, 0, 'x'}, - {"help", 0, 0, 'h'}, - {"advanced-help", 0, 0, 'p'}, - {"version", 0, 0, 'V'}, - {0, 0, 0, 0} -}; +static struct option long_options[] = { { "config", 1, 0, 'i' }, + { "backend", 1, 0, 'e' }, + { "device", 1, 0, 'd' }, + { "blocksize", 1, 0, 'b' }, + { "tape-serial", 1, 0, 's' }, + { "volume-name", 1, 0, 'n' }, + { "rules", 1, 0, 'r' }, + { "kmi-backend", 1, 0, '-' }, + { "no-compression", 0, 0, 'c' }, + { "no-override", 0, 0, ' ' }, + { "keep-capacity", 0, 0, 'k' }, + { "wipe", 0, 0, 'w' }, + { "long-wipe", 0, 0, '+' }, + { "destructive", 0, 0, '&' }, + { "force", 0, 0, 'f' }, + { "quiet", 0, 0, 'q' }, + { "trace", 0, 0, 't' }, + { "syslogtrace", 0, 0, '!' }, + { "fulltrace", 0, 0, 'x' }, + { "help", 0, 0, 'h' }, + { "advanced-help", 0, 0, 'p' }, + { "version", 0, 0, 'V' }, + { 0, 0, 0, 0 } }; #ifdef mingw_PLATFORM static #endif -void show_usage(char *appname, struct config_file *config, bool full) + void + show_usage(char *appname, struct config_file *config, bool full) { struct libltfs_plugin backend; const char *default_backend; @@ -161,36 +159,35 @@ void show_usage(char *appname, struct config_file *config, bool full) plugin_unload(&backend); } - if (! devname) - devname = arch_strdup(""); + if (!devname) devname = arch_strdup(""); fprintf(stderr, "\n"); - ltfsresult(15400I, appname); /* Usage: %s */ + ltfsresult(15400I, appname); /* Usage: %s */ fprintf(stderr, "\n"); - ltfsresult(15401I); /* Available options are: */ - ltfsresult(15402I); /* -d, --device= */ - ltfsresult(15420I); /* -f, --force */ - ltfsresult(15403I); /* -s, --tape-serial= */ - ltfsresult(15404I); /* -n, --volume-name */ - ltfsresult(15405I); /* -r, --rules= */ - ltfsresult(15406I); /* --no-override */ - ltfsresult(15418I); /* -w, --wipe */ - ltfsresult(15407I); /* -q, --quiet */ - ltfsresult(15408I); /* -t, --trace */ - ltfsresult(15422I); /* --syslogtrace */ - ltfsresult(15423I); /* -V, --version */ - ltfsresult(15409I); /* -h, --help */ - ltfsresult(15412I); /* -p, --advanced-help */ + ltfsresult(15401I); /* Available options are: */ + ltfsresult(15402I); /* -d, --device= */ + ltfsresult(15420I); /* -f, --force */ + ltfsresult(15403I); /* -s, --tape-serial= */ + ltfsresult(15404I); /* -n, --volume-name */ + ltfsresult(15405I); /* -r, --rules= */ + ltfsresult(15406I); /* --no-override */ + ltfsresult(15418I); /* -w, --wipe */ + ltfsresult(15407I); /* -q, --quiet */ + ltfsresult(15408I); /* -t, --trace */ + ltfsresult(15422I); /* --syslogtrace */ + ltfsresult(15423I); /* -V, --version */ + ltfsresult(15409I); /* -h, --help */ + ltfsresult(15412I); /* -p, --advanced-help */ if (full) { - ltfsresult(15413I, LTFS_CONFIG_FILE); /* -i, --config= */ - ltfsresult(15414I, default_backend); /* -e, --backend */ + ltfsresult(15413I, LTFS_CONFIG_FILE); /* -i, --config= */ + ltfsresult(15414I, default_backend); /* -e, --backend */ ltfsresult(15421I, config_file_get_default_plugin("kmi", config)); /* --kmi-backend */ - ltfsresult(15415I, LTFS_DEFAULT_BLOCKSIZE); /* -b, --blocksize */ - ltfsresult(15416I); /* -c, --no-compression */ - ltfsresult(15419I); /* -k, --keep-capacity */ - ltfsresult(15417I); /* -x, --fulltrace */ - ltfsresult(15424I); /* --long-wipe */ - ltfsresult(15425I); /* --destructive */ + ltfsresult(15415I, LTFS_DEFAULT_BLOCKSIZE); /* -b, --blocksize */ + ltfsresult(15416I); /* -c, --no-compression */ + ltfsresult(15419I); /* -k, --keep-capacity */ + ltfsresult(15417I); /* -x, --fulltrace */ + ltfsresult(15424I); /* --long-wipe */ + ltfsresult(15425I); /* --destructive */ fprintf(stderr, "\n"); plugin_usage(appname, "driver", config); fprintf(stderr, "\n"); @@ -198,7 +195,7 @@ void show_usage(char *appname, struct config_file *config, bool full) } fprintf(stderr, "\n"); - ltfsresult(15410I); /* Usage example: */ + ltfsresult(15410I); /* Usage example: */ ltfsresult(15411I, appname, devname, "size=100K"); /* %s --device=%s --rules="%s" */ ltfsresult(15411I, appname, devname, "size=1M/name=*.jpg"); ltfsresult(15411I, appname, devname, "size=1M/name=*.jpg:*.png"); @@ -206,7 +203,6 @@ void show_usage(char *appname, struct config_file *config, bool full) free(devname); } - /* Operation */ int main(int argc, char **argv) { @@ -218,21 +214,23 @@ int main(int argc, char **argv) void *message_handle; int fuse_argc = argc; char **fuse_argv = calloc(fuse_argc, sizeof(char *)); - if (! fuse_argv) { + if (!fuse_argv) { return MKLTFS_OPERATIONAL_ERROR; } for (i = 0; i < fuse_argc; ++i) { fuse_argv[i] = arch_strdup(argv[i]); - if (! fuse_argv[i]) { + if (!fuse_argv[i]) { return MKLTFS_OPERATIONAL_ERROR; } } struct fuse_args args = FUSE_ARGS_INIT(fuse_argc, fuse_argv); /* Check for LANG variable and set it to en_US.UTF-8 if it is unset. */ - arch_getenv(lang,"LANG"); - if (! lang) { - fprintf(stderr, "LTFS9015W Setting the locale to 'en_US.UTF-8'. If this is wrong, please set the LANG environment variable before starting mkltfs.\n"); + arch_getenv(lang, "LANG"); + if (!lang) { + fprintf(stderr, + "LTFS9015W Setting the locale to 'en_US.UTF-8'. If this is wrong, please set the LANG environment variable " + "before starting mkltfs.\n"); ret = setenv("LANG", "en_US.UTF-8", 1); if (ret) { fprintf(stderr, "LTFS9016E Cannot set the LANG environment variable\n"); @@ -279,8 +277,7 @@ int main(int argc, char **argv) while (true) { int option_index = 0; int c = getopt_long(argc, argv, short_options, long_options, &option_index); - if (c == -1) - break; + if (c == -1) break; if (c == 'i') { config_file = arch_strdup(optarg); break; @@ -300,8 +297,7 @@ int main(int argc, char **argv) while (true) { int option_index = 0; int c = getopt_long(argc, argv, short_options, long_options, &option_index); - if (c == -1) - break; + if (c == -1) break; switch (c) { case 'i': @@ -389,23 +385,22 @@ int main(int argc, char **argv) } /* Pick up default backend if one wasn't specified before */ - if (! opt.backend_path) { + if (!opt.backend_path) { const char *default_backend = config_file_get_default_plugin("tape", opt.config); - if (! default_backend) { + if (!default_backend) { ltfsmsg(LTFS_ERR, 10009E); return MKLTFS_OPERATIONAL_ERROR; } opt.backend_path = arch_strdup(default_backend); } - if (! opt.kmi_backend_name) { + if (!opt.kmi_backend_name) { const char *default_backend = config_file_get_default_plugin("kmi", opt.config); if (default_backend) opt.kmi_backend_name = arch_strdup(default_backend); else opt.kmi_backend_name = arch_strdup("none"); } - if (opt.kmi_backend_name && strcmp(opt.kmi_backend_name, "none") == 0) - opt.kmi_backend_name = NULL; + if (opt.kmi_backend_name && strcmp(opt.kmi_backend_name, "none") == 0) opt.kmi_backend_name = NULL; /* Set the logging level */ if (opt.quiet && (opt.trace || opt.fulltrace)) { @@ -435,7 +430,7 @@ int main(int argc, char **argv) ltfsmsg(LTFS_INFO, 15000I, PACKAGE_NAME, PACKAGE_VERSION, log_level); /* Show command line arguments */ - for (i = 0, cmd_args_len = 0 ; i < argc; i++) { + for (i = 0, cmd_args_len = 0; i < argc; i++) { cmd_args_len += strlen(argv[i]) + 1; } cmd_args = calloc(1, cmd_args_len + 1); @@ -444,9 +439,9 @@ int main(int argc, char **argv) ltfsmsg(LTFS_ERR, 10001E, "mkltfs (arguments)"); return MKLTFS_OPERATIONAL_ERROR; } - arch_strcat(cmd_args, cmd_args_len,argv[0]); + arch_strcat(cmd_args, cmd_args_len, argv[0]); for (i = 1; i < argc; i++) { - arch_strcat(cmd_args, cmd_args_len," "); + arch_strcat(cmd_args, cmd_args_len, " "); arch_strcat(cmd_args, cmd_args_len, argv[i]); } ltfsmsg(LTFS_INFO, 15041I, cmd_args); @@ -468,8 +463,7 @@ int main(int argc, char **argv) ret = ltfs_set_blocksize(opt.blocksize, newvol); if (ret < 0) { - if (ret == -LTFS_SMALL_BLOCKSIZE) - ltfsmsg(LTFS_ERR, 15028E, LTFS_MIN_BLOCKSIZE); + if (ret == -LTFS_SMALL_BLOCKSIZE) ltfsmsg(LTFS_ERR, 15028E, LTFS_MIN_BLOCKSIZE); show_usage(argv[0], opt.config, false); return MKLTFS_OPERATIONAL_ERROR; } @@ -491,21 +485,19 @@ int main(int argc, char **argv) } ret = ltfs_fs_init(); - if (ret) - return LTFSCK_OPERATIONAL_ERROR;; + if (ret) return LTFSCK_OPERATIONAL_ERROR; + ; ltfsmsg(LTFS_INFO, 15003I, opt.devname); ltfsmsg(LTFS_INFO, 15004I, opt.blocksize); ltfsmsg(LTFS_INFO, 15005I, opt.filterrules ? opt.filterrules : "None"); - if (! opt.quiet) - fprintf(stderr, "\n"); + if (!opt.quiet) fprintf(stderr, "\n"); - if(opt.unformat) + if (opt.unformat) ret = unformat_tape(newvol, &opt, &args); else ret = format_tape(newvol, &opt, &args); - arch_safe_free(opt.backend_path); arch_safe_free(opt.kmi_backend_name); arch_safe_free(opt.devname); @@ -521,13 +513,12 @@ int format_tape(struct ltfs_volume *vol, struct other_format_opts *opt, void *ar int ret = MKLTFS_OPERATIONAL_ERROR; struct device_capacity cap; struct libltfs_plugin backend; /* tape driver backend */ - struct libltfs_plugin kmi; /* key manager interface backend */ + struct libltfs_plugin kmi; /* key manager interface backend */ struct ltfs_volume *dummy_vol; bool is_worm; ret = ltfs_set_volume_name(opt->volume_name, vol); - if (ret < 0) - return MKLTFS_OPERATIONAL_ERROR; + if (ret < 0) return MKLTFS_OPERATIONAL_ERROR; ret = ltfs_reset_capacity(!opt->keep_capacity, vol); if (ret < 0) { return MKLTFS_OPERATIONAL_ERROR; @@ -572,8 +563,7 @@ int format_tape(struct ltfs_volume *vol, struct other_format_opts *opt, void *ar } ret = tape_clear_key(vol->device, vol->kmi_handle); - if (ret < 0) - goto out_unload_backend; + if (ret < 0) goto out_unload_backend; } { @@ -610,7 +600,7 @@ int format_tape(struct ltfs_volume *vol, struct other_format_opts *opt, void *ar ltfs_set_partition_map(DATA_PART_ID, INDEX_PART_ID, DATA_PART_NUM, INDEX_PART_NUM, vol); /* Check target medium state */ - if (! opt->force) { + if (!opt->force) { ltfsmsg(LTFS_INFO, 15049I, "mount"); ret = ltfs_volume_alloc("mkltfs", &dummy_vol); if (ret < 0) { @@ -626,8 +616,7 @@ int format_tape(struct ltfs_volume *vol, struct other_format_opts *opt, void *ar if (ret == 0) { ltfsmsg(LTFS_ERR, 15047E, ret); ltfsmsg(LTFS_INFO, 15048I); - } - else if (ret == -EDEV_KEY_REQUIRED) { + } else if (ret == -EDEV_KEY_REQUIRED) { ltfsmsg(LTFS_ERR, 15056E); ltfsmsg(LTFS_INFO, 15057I); } @@ -636,8 +625,7 @@ int format_tape(struct ltfs_volume *vol, struct other_format_opts *opt, void *ar goto out_close; } ltfs_volume_free(&dummy_vol); - } - else { + } else { ltfsmsg(LTFS_INFO, 15049I, "load"); ret = tape_load_tape(vol->device, vol->kmi_handle, false); if (ret < 0) { @@ -657,7 +645,7 @@ int format_tape(struct ltfs_volume *vol, struct other_format_opts *opt, void *ar } /* Set up index data: filter rules */ - ret = index_criteria_set_allow_update(is_worm? false : opt->allow_update, vol); + ret = index_criteria_set_allow_update(is_worm ? false : opt->allow_update, vol); if (ret < 0) { ltfsmsg(LTFS_ERR, 15014E, ret); ret = MKLTFS_OPERATIONAL_ERROR; @@ -687,10 +675,10 @@ int format_tape(struct ltfs_volume *vol, struct other_format_opts *opt, void *ar if (ret == -LTFS_INTERRUPTED) { ltfsmsg(LTFS_ERR, 15045E); ret = MKLTFS_CANCELED_BY_USER; - }else if (ret == -EDEV_WRITE_PROTECTED_WORM) { + } else if (ret == -EDEV_WRITE_PROTECTED_WORM) { ltfsmsg(LTFS_ERR, 15061E); ret = MKLTFS_USAGE_SYNTAX_ERROR; - }else { + } else { ltfsmsg(LTFS_ERR, 15012E); if (ret == -LTFS_WRITE_PROTECT || ret == -LTFS_WRITE_ERROR) ret = MKLTFS_USAGE_SYNTAX_ERROR; @@ -700,18 +688,18 @@ int format_tape(struct ltfs_volume *vol, struct other_format_opts *opt, void *ar goto out_close; } ltfsmsg(LTFS_INFO, 15013I, ltfs_get_volume_uuid(vol)); - if (! opt->quiet) - fprintf(stderr, "\n"); + if (!opt->quiet) fprintf(stderr, "\n"); /* Print volume capacity as GB (10^9 Bytes - SI) */ memset(&cap, 0, sizeof(cap)); ltfs_capacity_data(&cap, vol); - ltfsmsg(LTFS_INFO, 15019I, (unsigned long long)(((cap.total_dp * (opt->blocksize / 1048576.0) - * (1024 * 1024)) + 500000000) - / 1000 / 1000 / 1000)); + ltfsmsg(LTFS_INFO, + 15019I, + (unsigned long long)(((cap.total_dp * (opt->blocksize / 1048576.0) * (1024 * 1024)) + 500000000) / 1000 / + 1000 / 1000)); - vol->t_attr = (struct tape_attr *) calloc(1, sizeof(struct tape_attr)); - if (! vol->t_attr) { + vol->t_attr = (struct tape_attr *)calloc(1, sizeof(struct tape_attr)); + if (!vol->t_attr) { ltfsmsg(LTFS_ERR, 10001E, "format_tape: vol->t_attr"); goto out_close; } @@ -734,23 +722,19 @@ int format_tape(struct ltfs_volume *vol, struct other_format_opts *opt, void *ar ltfs_device_close(vol); ltfs_volume_free(&vol); ltfs_unset_signal_handlers(); - if (ret == MKLTFS_NO_ERRORS) - ltfsmsg(LTFS_DEBUG, 15022D); + if (ret == MKLTFS_NO_ERRORS) ltfsmsg(LTFS_DEBUG, 15022D); out_unload_backend: if (ret == MKLTFS_NO_ERRORS) { ret = plugin_unload(&backend); - if (ret < 0) - ltfsmsg(LTFS_WARN, 15021W); + if (ret < 0) ltfsmsg(LTFS_WARN, 15021W); if (opt->kmi_backend_name) { ret = plugin_unload(&kmi); - if (ret < 0) - ltfsmsg(LTFS_WARN, 15051W); + if (ret < 0) ltfsmsg(LTFS_WARN, 15051W); } ret = MKLTFS_NO_ERRORS; } else { plugin_unload(&backend); - if (opt->kmi_backend_name) - plugin_unload(&kmi); + if (opt->kmi_backend_name) plugin_unload(&kmi); } if (ret == MKLTFS_NO_ERRORS) @@ -765,7 +749,7 @@ int unformat_tape(struct ltfs_volume *vol, struct other_format_opts *opt, void * { int ret = MKLTFS_OPERATIONAL_ERROR; struct libltfs_plugin backend; /* tape driver backend */ - struct libltfs_plugin kmi; /* key manager interface backend */ + struct libltfs_plugin kmi; /* key manager interface backend */ /* load the backend, open the tape device, and load a tape */ ltfsmsg(LTFS_DEBUG, 15006D); @@ -801,8 +785,7 @@ int unformat_tape(struct ltfs_volume *vol, struct other_format_opts *opt, void * } ret = tape_clear_key(vol->device, vol->kmi_handle); - if (ret < 0) - goto out_unload_backend; + if (ret < 0) goto out_unload_backend; } { int i = 0; @@ -832,10 +815,10 @@ int unformat_tape(struct ltfs_volume *vol, struct other_format_opts *opt, void * if (ret == -LTFS_INTERRUPTED) { ltfsmsg(LTFS_ERR, 15046E); ret = MKLTFS_CANCELED_BY_USER; - }else if (ret == -EDEV_WRITE_PROTECTED_WORM) { + } else if (ret == -EDEV_WRITE_PROTECTED_WORM) { ltfsmsg(LTFS_ERR, 15062E); ret = MKLTFS_USAGE_SYNTAX_ERROR; - }else { + } else { ltfsmsg(LTFS_ERR, 15038E); ret = MKLTFS_OPERATIONAL_ERROR; } @@ -851,23 +834,19 @@ int unformat_tape(struct ltfs_volume *vol, struct other_format_opts *opt, void * ltfs_device_close(vol); ltfs_volume_free(&vol); ltfs_unset_signal_handlers(); - if (ret == MKLTFS_UNFORMATTED) - ltfsmsg(LTFS_DEBUG, 15022D); + if (ret == MKLTFS_UNFORMATTED) ltfsmsg(LTFS_DEBUG, 15022D); out_unload_backend: if (ret == MKLTFS_UNFORMATTED) { ret = plugin_unload(&backend); - if (ret < 0) - ltfsmsg(LTFS_WARN, 15021W); + if (ret < 0) ltfsmsg(LTFS_WARN, 15021W); if (opt->kmi_backend_name) { ret = plugin_unload(&kmi); - if (ret < 0) - ltfsmsg(LTFS_WARN, 15051W); + if (ret < 0) ltfsmsg(LTFS_WARN, 15051W); } ret = MKLTFS_UNFORMATTED; } else { plugin_unload(&backend); - if (opt->kmi_backend_name) - plugin_unload(&kmi); + if (opt->kmi_backend_name) plugin_unload(&kmi); } if (ret == MKLTFS_UNFORMATTED) @@ -878,8 +857,7 @@ int unformat_tape(struct ltfs_volume *vol, struct other_format_opts *opt, void * return ret; } -int _mkltfs_validate_options(char *prg_name, struct ltfs_volume *vol, - struct other_format_opts *opt) +int _mkltfs_validate_options(char *prg_name, struct ltfs_volume *vol, struct other_format_opts *opt) { int ret; char *tmp;