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

62 lines
2.3 KiB
C
Raw Normal View History

2020-06-18 05:17:49 -04:00
/*
2020-06-19 23:00:46 -04:00
* mkbootimg/jamesm.c
2020-06-18 05:17:49 -04:00
*
* Copyright (C) 2017 - 2020 bzt (bztsrc@gitlab)
*
* 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.
2020-06-19 23:00:46 -04:00
* @brief Driver for James Molloy's initrd
2020-06-18 05:17:49 -04:00
*
*/
#include "main.h"
2020-06-19 23:00:46 -04:00
void jamesm_open(gpt_t *gpt_entry)
2020-06-18 05:17:49 -04:00
{
2020-06-19 23:00:46 -04:00
(void)gpt_entry;
fs_len = 4 + 64 * 73;
fs_base = realloc(fs_base, fs_len);
if(!fs_base) { fprintf(stderr,"mkbootimg: %s\r\n", lang[ERR_MEM]); exit(1); }
memset(fs_base, 0, fs_len);
2020-06-18 05:17:49 -04:00
}
2020-06-19 23:00:46 -04:00
void jamesm_add(struct stat *st, char *name, unsigned char *content, int size)
2020-06-18 05:17:49 -04:00
{
2020-06-19 23:00:46 -04:00
unsigned char *end;
if(!S_ISREG(st->st_mode) || !content || !size) return;
fs_base = realloc(fs_base, fs_len + size);
if(!fs_base) { fprintf(stderr,"mkbootimg: %s\r\n", lang[ERR_MEM]); exit(1); }
/* this format is specified to hold maximum 64 files... */
if(fs_base[0] > 63) { fprintf(stderr,"mkbootimg: %s\r\n", lang[ERR_TOOMANY]); exit(1); }
end = fs_base + fs_len;
memcpy(end, content, size);
fs_base[4 + fs_base[0]*73] = 0xBF;
strncpy((char*)&fs_base[5 + fs_base[0]*73], name, 63);
memcpy(&fs_base[69 + fs_base[0]*73], &fs_len, 4);
memcpy(&fs_base[73 + fs_base[0]*73], &size, 4);
fs_base[0]++;
fs_len += size;
2020-06-18 05:17:49 -04:00
}
2020-06-19 23:00:46 -04:00
void jamesm_close()
2020-06-18 05:17:49 -04:00
{
}