Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7b444f08 authored by Jerry Zhang's avatar Jerry Zhang
Browse files

libsparse: Add .clang-format and reformat to google3 style

Bug: 78793464
Test: compiles
Change-Id: I8e44ba77195a12fc2bac7d4276bbc4aa95149b31
parent 5a755077
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
../.clang-format-2
 No newline at end of file
+93 −95
Original line number Diff line number Diff line
@@ -25,8 +25,8 @@
#include <unistd.h>

#include <sparse/sparse.h>
#include "sparse_file.h"
#include "backed_block.h"
#include "sparse_file.h"

#ifndef O_BINARY
#define O_BINARY 0
@@ -40,13 +40,11 @@
#define off64_t off_t
#endif

void usage()
{
void usage() {
  fprintf(stderr, "Usage: append2simg <output> <input>\n");
}

int main(int argc, char *argv[])
{
int main(int argc, char* argv[]) {
  int output;
  int output_block;
  char* output_path;
+302 −327
Original line number Diff line number Diff line
@@ -52,46 +52,38 @@ struct backed_block_list {
  unsigned int block_size;
};

struct backed_block *backed_block_iter_new(struct backed_block_list *bbl)
{
struct backed_block* backed_block_iter_new(struct backed_block_list* bbl) {
  return bbl->data_blocks;
}

struct backed_block *backed_block_iter_next(struct backed_block *bb)
{
struct backed_block* backed_block_iter_next(struct backed_block* bb) {
  return bb->next;
}

unsigned int backed_block_len(struct backed_block *bb)
{
unsigned int backed_block_len(struct backed_block* bb) {
  return bb->len;
}

unsigned int backed_block_block(struct backed_block *bb)
{
unsigned int backed_block_block(struct backed_block* bb) {
  return bb->block;
}

void *backed_block_data(struct backed_block *bb)
{
void* backed_block_data(struct backed_block* bb) {
  assert(bb->type == BACKED_BLOCK_DATA);
  return bb->data.data;
}

const char *backed_block_filename(struct backed_block *bb)
{
const char* backed_block_filename(struct backed_block* bb) {
  assert(bb->type == BACKED_BLOCK_FILE);
  return bb->file.filename;
}

int backed_block_fd(struct backed_block *bb)
{
int backed_block_fd(struct backed_block* bb) {
  assert(bb->type == BACKED_BLOCK_FD);
  return bb->fd.fd;
}

int64_t backed_block_file_offset(struct backed_block *bb)
{
int64_t backed_block_file_offset(struct backed_block* bb) {
  assert(bb->type == BACKED_BLOCK_FILE || bb->type == BACKED_BLOCK_FD);
  if (bb->type == BACKED_BLOCK_FILE) {
    return bb->file.offset;
@@ -100,19 +92,16 @@ int64_t backed_block_file_offset(struct backed_block *bb)
  }
}

uint32_t backed_block_fill_val(struct backed_block *bb)
{
uint32_t backed_block_fill_val(struct backed_block* bb) {
  assert(bb->type == BACKED_BLOCK_FILL);
  return bb->fill.val;
}

enum backed_block_type backed_block_type(struct backed_block *bb)
{
enum backed_block_type backed_block_type(struct backed_block* bb) {
  return bb->type;
}

void backed_block_destroy(struct backed_block *bb)
{
void backed_block_destroy(struct backed_block* bb) {
  if (bb->type == BACKED_BLOCK_FILE) {
    free(bb->file.filename);
  }
@@ -120,16 +109,14 @@ void backed_block_destroy(struct backed_block *bb)
  free(bb);
}

struct backed_block_list *backed_block_list_new(unsigned int block_size)
{
	struct backed_block_list *b = reinterpret_cast<backed_block_list*>(
            calloc(sizeof(struct backed_block_list), 1));
struct backed_block_list* backed_block_list_new(unsigned int block_size) {
  struct backed_block_list* b =
      reinterpret_cast<backed_block_list*>(calloc(sizeof(struct backed_block_list), 1));
  b->block_size = block_size;
  return b;
}

void backed_block_list_destroy(struct backed_block_list *bbl)
{
void backed_block_list_destroy(struct backed_block_list* bbl) {
  if (bbl->data_blocks) {
    struct backed_block* bb = bbl->data_blocks;
    while (bb) {
@@ -142,10 +129,8 @@ void backed_block_list_destroy(struct backed_block_list *bbl)
  free(bbl);
}

void backed_block_list_move(struct backed_block_list *from,
		struct backed_block_list *to, struct backed_block *start,
		struct backed_block *end)
{
void backed_block_list_move(struct backed_block_list* from, struct backed_block_list* to,
                            struct backed_block* start, struct backed_block* end) {
  struct backed_block* bb;

  if (start == NULL) {
@@ -189,9 +174,7 @@ void backed_block_list_move(struct backed_block_list *from,
}

/* may free b */
static int merge_bb(struct backed_block_list *bbl,
		struct backed_block *a, struct backed_block *b)
{
static int merge_bb(struct backed_block_list* bbl, struct backed_block* a, struct backed_block* b) {
  unsigned int block_len;

  /* Block doesn't exist (possible if one block is the last block) */
@@ -223,14 +206,12 @@ static int merge_bb(struct backed_block_list *bbl,
      break;
    case BACKED_BLOCK_FILE:
      /* Already make sure b->type is BACKED_BLOCK_FILE */
		if (strcmp(a->file.filename, b->file.filename) ||
				a->file.offset + a->len != b->file.offset) {
      if (strcmp(a->file.filename, b->file.filename) || a->file.offset + a->len != b->file.offset) {
        return -EINVAL;
      }
      break;
    case BACKED_BLOCK_FD:
		if (a->fd.fd != b->fd.fd ||
				a->fd.offset + a->len != b->fd.offset) {
      if (a->fd.fd != b->fd.fd || a->fd.offset + a->len != b->fd.offset) {
        return -EINVAL;
      }
      break;
@@ -246,8 +227,7 @@ static int merge_bb(struct backed_block_list *bbl,
  return 0;
}

static int queue_bb(struct backed_block_list *bbl, struct backed_block *new_bb)
{
static int queue_bb(struct backed_block_list* bbl, struct backed_block* new_bb) {
  struct backed_block* bb;

  if (bbl->data_blocks == NULL) {
@@ -290,9 +270,8 @@ static int queue_bb(struct backed_block_list *bbl, struct backed_block *new_bb)
}

/* Queues a fill block of memory to be written to the specified data blocks */
int backed_block_add_fill(struct backed_block_list *bbl, unsigned int fill_val,
		unsigned int len, unsigned int block)
{
int backed_block_add_fill(struct backed_block_list* bbl, unsigned int fill_val, unsigned int len,
                          unsigned int block) {
  struct backed_block* bb = reinterpret_cast<backed_block*>(calloc(1, sizeof(struct backed_block)));
  if (bb == NULL) {
    return -ENOMEM;
@@ -308,9 +287,8 @@ int backed_block_add_fill(struct backed_block_list *bbl, unsigned int fill_val,
}

/* Queues a block of memory to be written to the specified data blocks */
int backed_block_add_data(struct backed_block_list *bbl, void *data,
		unsigned int len, unsigned int block)
{
int backed_block_add_data(struct backed_block_list* bbl, void* data, unsigned int len,
                          unsigned int block) {
  struct backed_block* bb = reinterpret_cast<backed_block*>(calloc(1, sizeof(struct backed_block)));
  if (bb == NULL) {
    return -ENOMEM;
@@ -326,9 +304,8 @@ int backed_block_add_data(struct backed_block_list *bbl, void *data,
}

/* Queues a chunk of a file on disk to be written to the specified data blocks */
int backed_block_add_file(struct backed_block_list *bbl, const char *filename,
		int64_t offset, unsigned int len, unsigned int block)
{
int backed_block_add_file(struct backed_block_list* bbl, const char* filename, int64_t offset,
                          unsigned int len, unsigned int block) {
  struct backed_block* bb = reinterpret_cast<backed_block*>(calloc(1, sizeof(struct backed_block)));
  if (bb == NULL) {
    return -ENOMEM;
@@ -345,9 +322,8 @@ int backed_block_add_file(struct backed_block_list *bbl, const char *filename,
}

/* Queues a chunk of a fd to be written to the specified data blocks */
int backed_block_add_fd(struct backed_block_list *bbl, int fd, int64_t offset,
		unsigned int len, unsigned int block)
{
int backed_block_add_fd(struct backed_block_list* bbl, int fd, int64_t offset, unsigned int len,
                        unsigned int block) {
  struct backed_block* bb = reinterpret_cast<backed_block*>(calloc(1, sizeof(struct backed_block)));
  if (bb == NULL) {
    return -ENOMEM;
@@ -364,8 +340,7 @@ int backed_block_add_fd(struct backed_block_list *bbl, int fd, int64_t offset,
}

int backed_block_split(struct backed_block_list* bbl, struct backed_block* bb,
		unsigned int max_len)
{
                       unsigned int max_len) {
  struct backed_block* new_bb;

  max_len = ALIGN_DOWN(max_len, bbl->block_size);
+33 −35
Original line number Diff line number Diff line
@@ -29,14 +29,14 @@ enum backed_block_type {
  BACKED_BLOCK_FILL,
};

int backed_block_add_data(struct backed_block_list *bbl, void *data,
int backed_block_add_data(struct backed_block_list* bbl, void* data, unsigned int len,
                          unsigned int block);
int backed_block_add_fill(struct backed_block_list* bbl, unsigned int fill_val, unsigned int len,
                          unsigned int block);
int backed_block_add_file(struct backed_block_list* bbl, const char* filename, int64_t offset,
                          unsigned int len, unsigned int block);
int backed_block_add_fill(struct backed_block_list *bbl, unsigned int fill_val,
		unsigned int len, unsigned int block);
int backed_block_add_file(struct backed_block_list *bbl, const char *filename,
		int64_t offset, unsigned int len, unsigned int block);
int backed_block_add_fd(struct backed_block_list *bbl, int fd,
		int64_t offset, unsigned int len, unsigned int block);
int backed_block_add_fd(struct backed_block_list* bbl, int fd, int64_t offset, unsigned int len,
                        unsigned int block);

struct backed_block* backed_block_iter_new(struct backed_block_list* bbl);
struct backed_block* backed_block_iter_next(struct backed_block* bb);
@@ -48,8 +48,7 @@ int backed_block_fd(struct backed_block *bb);
int64_t backed_block_file_offset(struct backed_block* bb);
uint32_t backed_block_fill_val(struct backed_block* bb);
enum backed_block_type backed_block_type(struct backed_block* bb);
int backed_block_split(struct backed_block_list *bbl, struct backed_block *bb,
		unsigned int max_len);
int backed_block_split(struct backed_block_list* bbl, struct backed_block* bb, unsigned int max_len);

struct backed_block* backed_block_iter_new(struct backed_block_list* bbl);
struct backed_block* backed_block_iter_next(struct backed_block* bb);
@@ -57,8 +56,7 @@ struct backed_block *backed_block_iter_next(struct backed_block *bb);
struct backed_block_list* backed_block_list_new(unsigned int block_size);
void backed_block_list_destroy(struct backed_block_list* bbl);

void backed_block_list_move(struct backed_block_list *from,
		struct backed_block_list *to, struct backed_block *start,
		struct backed_block *end);
void backed_block_list_move(struct backed_block_list* from, struct backed_block_list* to,
                            struct backed_block* start, struct backed_block* end);

#endif
+70 −73
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
@@ -38,13 +37,11 @@
#define off64_t off_t
#endif

void usage()
{
void usage() {
  fprintf(stderr, "Usage: img2simg <raw_image_file> <sparse_image_file> [<block_size>]\n");
}

int main(int argc, char *argv[])
{
int main(int argc, char* argv[]) {
  int in;
  int out;
  int ret;
Loading