1
0
Fork 0
mirror of https://gitlab.com/bztsrc/bootboot.git synced 2023-02-13 20:54:32 -05:00
bztsrc--bootboot/mkbootimg/cpio.c

62 lines
2.4 KiB
C
Raw Normal View History

2020-06-18 05:17:49 -04:00
/*
* mkbootimg/cpio.c
*
2021-01-15 15:07:25 -05:00
* Copyright (C) 2017 - 2021 bzt (bztsrc@gitlab)
2020-06-18 05:17:49 -04:00
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* This file is part of the BOOTBOOT Protocol package.
* @brief CPIO initrd driver
*
*/
#include "main.h"
2020-06-19 23:00:46 -04:00
void cpio_open(gpt_t *gpt_entry)
2020-06-18 05:17:49 -04:00
{
if(gpt_entry) { fprintf(stderr,"mkbootimg: partition #%d %s cpio.\r\n", fs_no, lang[ERR_INITRDTYPE]); exit(1); }
2020-06-18 05:17:49 -04:00
}
void cpio_add(struct stat *st, char *name, unsigned char *content, int size)
{
unsigned char *end;
int n = strlen(name);
2020-06-19 23:00:46 -04:00
if(!S_ISREG(st->st_mode) && !S_ISDIR(st->st_mode) && !S_ISLNK(st->st_mode)) return;
2020-06-18 05:17:49 -04:00
fs_base = realloc(fs_base, fs_len + 76 + n + 1 + size);
2020-06-19 23:00:46 -04:00
if(!fs_base) { fprintf(stderr,"mkbootimg: %s\r\n", lang[ERR_MEM]); exit(1); }
2020-06-18 05:17:49 -04:00
end = fs_base + fs_len;
end += sprintf((char*)end, "070707000000000000%06o00000000000000000000000000000000000%06o%011o%s",
st->st_mode & 0777777,n+1,size,name);
*end++ = 0;
if(content && size) memcpy(end, content, size);
fs_len += 76 + n + 1 + size;
}
void cpio_close()
{
char *end;
fs_base = realloc(fs_base, fs_len + 76 + 11 + 512);
2020-06-19 23:00:46 -04:00
if(!fs_base) { fprintf(stderr,"mkbootimg: %s\r\n", lang[ERR_MEM]); exit(1); }
2020-06-18 05:17:49 -04:00
end = (char*)fs_base + fs_len;
memset(end, 0, 76 + 11 + 512);
end += sprintf(end, "07070700000000000000000000000000000000000010000000000000000%06o%011oTRAILER!!!",11,0);
fs_len = ((fs_len + 88 + 511) & ~511);
}