universal7885: parts: Fix the mkswap method

Change-Id: Ic078b1d2e5692036699ffc112fc62c932823265c
Signed-off-by: roynatech2544 <whiteshell2544@naver.com>
This commit is contained in:
roynatech2544 2022-05-23 19:33:05 +09:00
commit 1ce9146e89
No known key found for this signature in database
GPG key ID: 50ABF73F0D19445D
2 changed files with 12 additions and 7 deletions

View file

@ -32,7 +32,7 @@ Return<void> SwapOnData::setSwapSize(int32_t size) {
}
Return<void> SwapOnData::setSwapOn() {
mkfile(mSwapSize * 1024 * 1024 * 10, SWAP_PATH);
mkfile(mSwapSize * 10, SWAP_PATH);
mkswap(SWAP_PATH);
swapon(SWAP_PATH.c_str(), (10 << SWAP_FLAG_PRIO_SHIFT) & SWAP_FLAG_PRIO_MASK);
return Void();

View file

@ -1,12 +1,14 @@
#include <cstring>
#include <errno.h>
#include <cerrno>
#include <fcntl.h>
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <sys/stat.h>
#include <sys/swap.h>
#include <sys/types.h>
#include <unistd.h>
#include <fstream>
#include <vector>
/* XXX This needs to be obtained from kernel headers. See b/9336527 */
struct linux_swap_header {
char bootbits[1024]; /* Space for disklabel etc. */
@ -19,10 +21,13 @@ struct linux_swap_header {
u_int32_t badpages[1];
};
void mkfile(int filesize, std::string name){
FILE *fp = fopen(name.c_str(), "we");
fseek(fp, filesize , SEEK_SET);
fputc('\0', fp);
fclose(fp);
std::vector<char> empty(1024, 0);
std::ofstream ofs(name, std::ios::binary | std::ios::out);
for(int i = 0; i < 1024 * filesize; i++)
{
ofs.write(&empty[0], empty.size());
}
}
#define MAGIC_SWAP_HEADER "SWAPSPACE2"
#define MAGIC_SWAP_HEADER_LEN 10