refactor: rename vlnk to hlnk in hisolnk tool
Rename vlnk.c→hlnk.c, vlnk.h→hlnk.h. Update crc32.c and main_linux.c references. The file format concept changes from 'Ventoy Link' to 'Hiperiso Link' throughout. hisolnk tool builds successfully (19K).
This commit is contained in:
+1
-1
@@ -21,7 +21,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "vlnk.h"
|
||||
#include "hlnk.h"
|
||||
|
||||
static uint32_t crc32c_table [256];
|
||||
|
||||
|
||||
@@ -2,43 +2,43 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "vlnk.h"
|
||||
#include "hlnk.h"
|
||||
|
||||
int hiperiso_create_vlnk(uint32_t disksig, uint64_t partoffset, const char *path, hiperiso_vlnk *vlnk)
|
||||
int hiperiso_create_hlnk(uint32_t disksig, uint64_t partoffset, const char *path, hiperiso_hlnk *hlnk)
|
||||
{
|
||||
uint32_t crc;
|
||||
hiperiso_guid guid = HIPERISO_GUID;
|
||||
|
||||
memcpy(&(vlnk->guid), &guid, sizeof(hiperiso_guid));
|
||||
vlnk->disk_signature = disksig;
|
||||
vlnk->part_offset = partoffset;
|
||||
memcpy(&(hlnk->guid), &guid, sizeof(hiperiso_guid));
|
||||
hlnk->disk_signature = disksig;
|
||||
hlnk->part_offset = partoffset;
|
||||
|
||||
#ifdef WIN32
|
||||
strcpy_s(vlnk->filepath, sizeof(vlnk->filepath) - 1, path);
|
||||
strcpy_s(hlnk->filepath, sizeof(hlnk->filepath) - 1, path);
|
||||
#else
|
||||
strncpy(vlnk->filepath, path, sizeof(vlnk->filepath) - 1);
|
||||
strncpy(hlnk->filepath, path, sizeof(hlnk->filepath) - 1);
|
||||
#endif
|
||||
|
||||
crc = hiperiso_getcrc32c(0, vlnk, sizeof(hiperiso_vlnk));
|
||||
vlnk->crc32 = crc;
|
||||
crc = hiperiso_getcrc32c(0, hlnk, sizeof(hiperiso_hlnk));
|
||||
hlnk->crc32 = crc;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int CheckVlnkData(hiperiso_vlnk *vlnk)
|
||||
int CheckHlnkData(hiperiso_hlnk *hlnk)
|
||||
{
|
||||
uint32_t readcrc, calccrc;
|
||||
hiperiso_guid guid = HIPERISO_GUID;
|
||||
|
||||
if (memcmp(&vlnk->guid, &guid, sizeof(guid)))
|
||||
if (memcmp(&hlnk->guid, &guid, sizeof(guid)))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
readcrc = vlnk->crc32;
|
||||
vlnk->crc32 = 0;
|
||||
calccrc = hiperiso_getcrc32c(0, vlnk, sizeof(hiperiso_vlnk));
|
||||
readcrc = hlnk->crc32;
|
||||
hlnk->crc32 = 0;
|
||||
calccrc = hiperiso_getcrc32c(0, hlnk, sizeof(hiperiso_hlnk));
|
||||
|
||||
if (readcrc != calccrc)
|
||||
{
|
||||
@@ -1,10 +1,10 @@
|
||||
|
||||
#ifndef __VLNK_H__
|
||||
#define __VLNK_H__
|
||||
#ifndef __HLNK_H__
|
||||
#define __HLNK_H__
|
||||
|
||||
#define VLNK_FILE_LEN 32768
|
||||
#define HLNK_FILE_LEN 32768
|
||||
|
||||
#define VLNK_NAME_MAX 384
|
||||
#define HLNK_NAME_MAX 384
|
||||
|
||||
#define HIPERISO_GUID { 0x77772020, 0x2e77, 0x6576, { 0x6e, 0x74, 0x6f, 0x79, 0x2e, 0x6e, 0x65, 0x74 }}
|
||||
|
||||
@@ -18,20 +18,20 @@ typedef struct hiperiso_guid
|
||||
uint8_t data4[8];
|
||||
}hiperiso_guid;
|
||||
|
||||
typedef struct hiperiso_vlnk
|
||||
typedef struct hiperiso_hlnk
|
||||
{
|
||||
hiperiso_guid guid; // HIPERISO_GUID
|
||||
uint32_t crc32; // crc32
|
||||
uint32_t disk_signature;
|
||||
uint64_t part_offset; // in bytes
|
||||
char filepath[VLNK_NAME_MAX];
|
||||
char filepath[HLNK_NAME_MAX];
|
||||
uint8_t reserverd[96];
|
||||
}hiperiso_vlnk;
|
||||
}hiperiso_hlnk;
|
||||
#pragma pack()
|
||||
|
||||
uint32_t hiperiso_getcrc32c (uint32_t crc, const void *buf, int size);
|
||||
int hiperiso_create_vlnk(uint32_t disksig, uint64_t partoffset, const char *path, hiperiso_vlnk *vlnk);
|
||||
int CheckVlnkData(hiperiso_vlnk *vlnk);
|
||||
int hiperiso_create_hlnk(uint32_t disksig, uint64_t partoffset, const char *path, hiperiso_hlnk *hlnk);
|
||||
int CheckHlnkData(hiperiso_hlnk *hlnk);
|
||||
int IsSupportedImgSuffix(char *suffix);
|
||||
|
||||
#endif
|
||||
+34
-34
@@ -10,7 +10,7 @@
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "vlnk.h"
|
||||
#include "hlnk.h"
|
||||
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 4096
|
||||
@@ -21,7 +21,7 @@
|
||||
static int verbose = 0;
|
||||
#define debug(fmt, args...) if(verbose) printf(fmt, ##args)
|
||||
|
||||
static uint8_t g_vlnk_buf[VLNK_FILE_LEN];
|
||||
static uint8_t g_hlnk_buf[HLNK_FILE_LEN];
|
||||
|
||||
static int64_t get_file_size(char *file)
|
||||
{
|
||||
@@ -173,13 +173,13 @@ static uint64_t get_part_offset(char *partname)
|
||||
return offset;
|
||||
}
|
||||
|
||||
static int create_vlnk(char *infile, char *diskname, uint64_t partoff, char *outfile)
|
||||
static int create_hlnk(char *infile, char *diskname, uint64_t partoff, char *outfile)
|
||||
{
|
||||
FILE *fp;
|
||||
int len;
|
||||
uint32_t sig = 0;
|
||||
|
||||
debug("create vlnk\n");
|
||||
debug("create hlnk\n");
|
||||
|
||||
if (infile[0] == 0 || outfile[0] == 0 || diskname[0] == 0 || partoff == 0)
|
||||
{
|
||||
@@ -188,9 +188,9 @@ static int create_vlnk(char *infile, char *diskname, uint64_t partoff, char *out
|
||||
}
|
||||
|
||||
len = (int)strlen(infile);
|
||||
if (len >= VLNK_NAME_MAX)
|
||||
if (len >= HLNK_NAME_MAX)
|
||||
{
|
||||
printf("File name length %d is too long for vlnk!\n", len);
|
||||
printf("File name length %d is too long for hlnk!\n", len);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -207,9 +207,9 @@ static int create_vlnk(char *infile, char *diskname, uint64_t partoff, char *out
|
||||
return 1;
|
||||
}
|
||||
|
||||
memset(g_vlnk_buf, 0, sizeof(g_vlnk_buf));
|
||||
hiperiso_create_vlnk(sig, partoff, infile, (hiperiso_vlnk *)g_vlnk_buf);
|
||||
fwrite(g_vlnk_buf, 1, VLNK_FILE_LEN, fp);
|
||||
memset(g_hlnk_buf, 0, sizeof(g_hlnk_buf));
|
||||
hiperiso_create_hlnk(sig, partoff, infile, (hiperiso_hlnk *)g_hlnk_buf);
|
||||
fwrite(g_hlnk_buf, 1, HLNK_FILE_LEN, fp);
|
||||
fclose(fp);
|
||||
|
||||
return 0;
|
||||
@@ -252,7 +252,7 @@ static int get_mount_point(char *partname, char *mntpoint)
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int parse_vlnk(char *infile)
|
||||
static int parse_hlnk(char *infile)
|
||||
{
|
||||
int i;
|
||||
int fd;
|
||||
@@ -262,9 +262,9 @@ static int parse_vlnk(char *infile)
|
||||
char partname[128] = {0};
|
||||
char partpath[256] = {0};
|
||||
char mntpoint[PATH_MAX];
|
||||
hiperiso_vlnk vlnk;
|
||||
hiperiso_hlnk hlnk;
|
||||
|
||||
debug("parse vlnk\n");
|
||||
debug("parse hlnk\n");
|
||||
|
||||
if (infile[0] == 0)
|
||||
{
|
||||
@@ -279,18 +279,18 @@ static int parse_vlnk(char *infile)
|
||||
return 1;
|
||||
}
|
||||
|
||||
memset(&vlnk, 0, sizeof(vlnk));
|
||||
read(fd, &vlnk, sizeof(vlnk));
|
||||
memset(&hlnk, 0, sizeof(hlnk));
|
||||
read(fd, &hlnk, sizeof(hlnk));
|
||||
close(fd);
|
||||
|
||||
debug("disk_signature:%08X\n", vlnk.disk_signature);
|
||||
debug("file path:<%s>\n", vlnk.filepath);
|
||||
debug("part offset: %llu\n", (unsigned long long)vlnk.part_offset);
|
||||
debug("disk_signature:%08X\n", hlnk.disk_signature);
|
||||
debug("file path:<%s>\n", hlnk.filepath);
|
||||
debug("part offset: %llu\n", (unsigned long long)hlnk.part_offset);
|
||||
|
||||
cnt = find_disk_by_sig((uint8_t *)&(vlnk.disk_signature), diskname);
|
||||
cnt = find_disk_by_sig((uint8_t *)&(hlnk.disk_signature), diskname);
|
||||
if (cnt != 1)
|
||||
{
|
||||
printf("Disk in vlnk not found!\n");
|
||||
printf("Disk in hlnk not found!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -312,7 +312,7 @@ static int parse_vlnk(char *infile)
|
||||
snprintf(partname, sizeof(partname) - 1, "%s%d", diskname, i);
|
||||
}
|
||||
|
||||
if (get_part_offset(partname) == vlnk.part_offset)
|
||||
if (get_part_offset(partname) == hlnk.part_offset)
|
||||
{
|
||||
debug("Find correct partition </dev/%s>\n", partname);
|
||||
break;
|
||||
@@ -321,7 +321,7 @@ static int parse_vlnk(char *infile)
|
||||
|
||||
if (i > 128)
|
||||
{
|
||||
printf("Partition in vlnk not found!");
|
||||
printf("Partition in hlnk not found!");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -333,8 +333,8 @@ static int parse_vlnk(char *infile)
|
||||
}
|
||||
debug("moutpoint of %s is <%s>\n", partpath, mntpoint);
|
||||
|
||||
strcat(mntpoint, vlnk.filepath);
|
||||
printf("Vlnk Point: %s\n", mntpoint);
|
||||
strcat(mntpoint, hlnk.filepath);
|
||||
printf("Hlnk Point: %s\n", mntpoint);
|
||||
if (access(mntpoint, F_OK) >= 0)
|
||||
{
|
||||
printf("File Exist: YES\n");
|
||||
@@ -347,13 +347,13 @@ static int parse_vlnk(char *infile)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int check_vlnk(char *infile)
|
||||
static int check_hlnk(char *infile)
|
||||
{
|
||||
int fd;
|
||||
int64_t size;
|
||||
hiperiso_vlnk vlnk;
|
||||
hiperiso_hlnk hlnk;
|
||||
|
||||
debug("check vlnk\n");
|
||||
debug("check hlnk\n");
|
||||
|
||||
if (infile[0] == 0)
|
||||
{
|
||||
@@ -362,9 +362,9 @@ static int check_vlnk(char *infile)
|
||||
}
|
||||
|
||||
size = get_file_size(infile);
|
||||
if (size != VLNK_FILE_LEN)
|
||||
if (size != HLNK_FILE_LEN)
|
||||
{
|
||||
debug("file size %lld is not a vlnk file size\n", (long long)size);
|
||||
debug("file size %lld is not a hlnk file size\n", (long long)size);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -375,11 +375,11 @@ static int check_vlnk(char *infile)
|
||||
return 1;
|
||||
}
|
||||
|
||||
memset(&vlnk, 0, sizeof(vlnk));
|
||||
read(fd, &vlnk, sizeof(vlnk));
|
||||
memset(&hlnk, 0, sizeof(hlnk));
|
||||
read(fd, &hlnk, sizeof(hlnk));
|
||||
close(fd);
|
||||
|
||||
if (CheckVlnkData(&vlnk))
|
||||
if (CheckHlnkData(&hlnk))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -438,15 +438,15 @@ int main(int argc, char **argv)
|
||||
|
||||
if (cmd == 1)
|
||||
{
|
||||
return create_vlnk(infile, diskname, partoff, outfile);
|
||||
return create_hlnk(infile, diskname, partoff, outfile);
|
||||
}
|
||||
else if (cmd == 2)
|
||||
{
|
||||
return parse_vlnk(infile);
|
||||
return parse_hlnk(infile);
|
||||
}
|
||||
else if (cmd == 3)
|
||||
{
|
||||
return check_vlnk(infile);
|
||||
return check_hlnk(infile);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user