Skip to content

Commit

Permalink
Formatted code using clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
AKuHAK committed Jan 3, 2021
1 parent 923e9e0 commit 3e04e5c
Show file tree
Hide file tree
Showing 101 changed files with 46,988 additions and 15,702 deletions.
79 changes: 79 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
Language: Cpp
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: true
AfterControlStatement: false
AfterEnum: false
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: true
BeforeCatch: false
BeforeElse: false
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: true
ColumnLimit: 0
CommentPragmas: '^ (IWYU pragma:|NOLINT)'
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ForEachMacros: []
IndentCaseLabels: true
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 3
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: false
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 4
UseTab: Never
144 changes: 65 additions & 79 deletions aligned.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,108 +30,94 @@

struct aligned_type
{
osal_handle_t in;
char /*@owned@*/ *unaligned;
char /*@dependent@*/ *buffer;
u_int32_t sector_size, buffer_size, data_length;
u_int64_t offset;
osal_handle_t in;
char /*@owned@*/ *unaligned;
char /*@dependent@*/ *buffer;
u_int32_t sector_size, buffer_size, data_length;
u_int64_t offset;
};


/**************************************************************/
aligned_t*
al_alloc (osal_handle_t in,
u_int32_t sector_size,
u_int32_t buffer_size_in_sectors)
aligned_t *
al_alloc(osal_handle_t in,
u_int32_t sector_size,
u_int32_t buffer_size_in_sectors)
{
aligned_t *al = osal_alloc (sizeof (aligned_t));
if (al != NULL)
{
memset (al, 0, sizeof (aligned_t));
al->buffer_size = sector_size * buffer_size_in_sectors;
al->unaligned = osal_alloc (al->buffer_size + sector_size);
if (al->unaligned != NULL)
{
al->in = in;
/* FIX: 64-bit OS compatibility (not to trim ptr to 32-bit) */
al->buffer = (void*) (((unsigned long) al->unaligned + sector_size - 1)
& ~((unsigned long) sector_size - 1));
assert (al->buffer >= al->unaligned);
al->sector_size = sector_size;
al->offset = (u_int64_t) -1;
}
else
{
osal_free (al);
al = NULL;
}
aligned_t *al = osal_alloc(sizeof(aligned_t));
if (al != NULL) {
memset(al, 0, sizeof(aligned_t));
al->buffer_size = sector_size * buffer_size_in_sectors;
al->unaligned = osal_alloc(al->buffer_size + sector_size);
if (al->unaligned != NULL) {
al->in = in;
/* FIX: 64-bit OS compatibility (not to trim ptr to 32-bit) */
al->buffer = (void *)(((unsigned long)al->unaligned + sector_size - 1) & ~((unsigned long)sector_size - 1));
assert(al->buffer >= al->unaligned);
al->sector_size = sector_size;
al->offset = (u_int64_t)-1;
} else {
osal_free(al);
al = NULL;
}
}
return (al);
return (al);
}


/**************************************************************/
void
al_free (aligned_t *al)
void al_free(aligned_t *al)
{
if (al != NULL)
{
osal_free (al->unaligned);
osal_free (al);
if (al != NULL) {
osal_free(al->unaligned);
osal_free(al);
}
}


/**************************************************************/
int
al_read (aligned_t *al,
u_int64_t offset,
const char **data,
u_int32_t bytes,
u_int32_t *data_length)
int al_read(aligned_t *al,
u_int64_t offset,
const char **data,
u_int32_t bytes,
u_int32_t *data_length)
{
int result = OSAL_OK;
int result = OSAL_OK;

/* check if buffer contains all requested data */
if (al->offset <= offset && offset + bytes <= al->offset + al->data_length)
{ /* return data from the buffer */
*data = al->buffer + (offset - al->offset);
*data_length = bytes;
}
else
{ /* buffer does not contains all or any of the requested data */
u_int64_t aligned_offset = offset & ~((u_int64_t) al->sector_size - 1);
u_int32_t correction = 0;
assert (aligned_offset <= offset);
/* check if buffer contains all requested data */
if (al->offset <= offset && offset + bytes <= al->offset + al->data_length) { /* return data from the buffer */
*data = al->buffer + (offset - al->offset);
*data_length = bytes;
} else { /* buffer does not contains all or any of the requested data */
u_int64_t aligned_offset = offset & ~((u_int64_t)al->sector_size - 1);
u_int32_t correction = 0;
assert(aligned_offset <= offset);

/* check whether cache contains some usable data */
if (al->offset <= aligned_offset &&
aligned_offset < al->offset + al->data_length)
{ /* arrange data inside the cache and correct the offset */
u_int32_t usable_data_offs = (u_int32_t) (aligned_offset - al->offset);
u_int32_t usable_data_len = (u_int32_t) (al->offset + al->data_length - aligned_offset);
memmove (al->buffer, al->buffer + usable_data_offs, usable_data_len);
correction = usable_data_len;
}
/* check whether cache contains some usable data */
if (al->offset <= aligned_offset &&
aligned_offset < al->offset + al->data_length) { /* arrange data inside the cache and correct the offset */
u_int32_t usable_data_offs = (u_int32_t)(aligned_offset - al->offset);
u_int32_t usable_data_len = (u_int32_t)(al->offset + al->data_length - aligned_offset);
memmove(al->buffer, al->buffer + usable_data_offs, usable_data_len);
correction = usable_data_len;
}

result = osal_seek (al->in, aligned_offset + correction);
if (result == OSAL_OK)
{
result = osal_read (al->in, al->buffer + correction,
al->buffer_size - correction, &al->data_length);
al->data_length += correction;
result = osal_seek(al->in, aligned_offset + correction);
if (result == OSAL_OK) {
result = osal_read(al->in, al->buffer + correction,
al->buffer_size - correction, &al->data_length);
al->data_length += correction;
#if 0
printf ("osal_read (%d, %luKB, %d, -> %d) = %d\n",
al->in, (long) (aligned_offset / 1024), al->buffer_size, al->data_length, result);
#endif
}
if (result == OSAL_OK)
{ /* success */
u_int32_t skip = (u_int32_t) (offset - aligned_offset);
al->offset = aligned_offset;
*data = al->buffer + skip;
*data_length = bytes > al->data_length - skip ? al->data_length - skip : bytes;
}
}
if (result == OSAL_OK) { /* success */
u_int32_t skip = (u_int32_t)(offset - aligned_offset);
al->offset = aligned_offset;
*data = al->buffer + skip;
*data_length = bytes > al->data_length - skip ? al->data_length - skip : bytes;
}
}
return (result);
return (result);
}
24 changes: 11 additions & 13 deletions aligned.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#if !defined (_ALIGNED_H)
#if !defined(_ALIGNED_H)
#define _ALIGNED_H

#include "config.h"
Expand All @@ -38,20 +38,18 @@ C_START
*/
typedef struct aligned_type aligned_t;

aligned_t*
al_alloc (osal_handle_t in,
u_int32_t sector_size, /* device sector size - each file I/O should be aligned */
u_int32_t buffer_size_in_sectors); /* 32 is good enough */
aligned_t *
al_alloc(osal_handle_t in,
u_int32_t sector_size, /* device sector size - each file I/O should be aligned */
u_int32_t buffer_size_in_sectors); /* 32 is good enough */

int
al_read (aligned_t *al,
u_int64_t offset,
const char **data, /* internal buffer, managed by aligned I/O */
u_int32_t dest_size,
u_int32_t *length);
int al_read(aligned_t *al,
u_int64_t offset,
const char **data, /* internal buffer, managed by aligned I/O */
u_int32_t dest_size,
u_int32_t *length);

void
al_free (aligned_t *al);
void al_free(aligned_t *al);

C_END

Expand Down
Loading

0 comments on commit 3e04e5c

Please sign in to comment.