Dataset Viewer
Auto-converted to Parquet
id
int64
4
16.3M
file_name
stringlengths
3
68
file_path
stringlengths
14
181
content
stringlengths
39
9.06M
size
int64
39
9.06M
language
stringclasses
1 value
extension
stringclasses
2 values
total_lines
int64
1
711k
avg_line_length
float64
3.18
138
max_line_length
int64
10
140
alphanum_fraction
float64
0.02
0.93
repo_name
stringlengths
7
69
repo_stars
int64
2
61.6k
repo_forks
int64
12
7.81k
repo_open_issues
int64
0
1.13k
repo_license
stringclasses
10 values
repo_extraction_date
stringclasses
657 values
exact_duplicates_stackv2
bool
1 class
exact_duplicates_stackv1
bool
1 class
exact_duplicates_redpajama
bool
1 class
exact_duplicates_githubcode
bool
2 classes
near_duplicates_stackv2
bool
1 class
near_duplicates_stackv1
bool
1 class
near_duplicates_redpajama
bool
1 class
near_duplicates_githubcode
bool
2 classes
4
freebsd.c
ventoy_Ventoy/VBLADE/vblade-master/freebsd.c
/* * Copyright (c) 2005, Stacey Son <sson (at) verio (dot) net> * All rights reserved. */ // freebsd.c: low level access routines for FreeBSD #include "config.h" #include <sys/types.h> #include <sys/socket.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include <sys/time.h> #include <netinet/in.h> #include <net/ethernet.h> #include <net/bpf.h> #include <net/if.h> #include <net/if_arp.h> #include <net/if_dl.h> #include <net/route.h> #include <sys/ioctl.h> #include <sys/types.h> #include <net/if.h> #include <sys/stat.h> #include <sys/disk.h> #include <sys/select.h> #include <sys/sysctl.h> #include <fcntl.h> #include <errno.h> #include "dat.h" #include "fns.h" #define BPF_DEV "/dev/bpf0" /* Packet buffer for getpkt() */ static uchar *pktbuf = NULL; static int pktbufsz = 0; int dial(char *eth, int bufcnt) { char m; int fd = -1; struct bpf_version bv; u_int v; unsigned bufsize, linktype; char device[sizeof BPF_DEV]; struct ifreq ifr; struct bpf_program *bpf_program = create_bpf_program(shelf, slot); strncpy(device, BPF_DEV, sizeof BPF_DEV); /* find a bpf device we can use, check /dev/bpf[0-9] */ for (m = '0'; m <= '9'; m++) { device[sizeof(BPF_DEV)-2] = m; if ((fd = open(device, O_RDWR)) > 0) break; } if (fd < 0) { perror("open"); return -1; } if (ioctl(fd, BIOCVERSION, &bv) < 0) { perror("BIOCVERSION"); goto bad; } if (bv.bv_major != BPF_MAJOR_VERSION || bv.bv_minor < BPF_MINOR_VERSION) { fprintf(stderr, "kernel bpf filter out of date\n"); goto bad; } /* * Try finding a good size for the buffer; 65536 may be too * big, so keep cutting it in half until we find a size * that works, or run out of sizes to try. * */ for (v = 65536; v != 0; v >>= 1) { (void) ioctl(fd, BIOCSBLEN, (caddr_t)&v); (void)strncpy(ifr.ifr_name, eth, sizeof(ifr.ifr_name)); if (ioctl(fd, BIOCSETIF, (caddr_t)&ifr) >= 0) break; /* that size worked; we're done */ if (errno != ENOBUFS) { fprintf(stderr, "BIOCSETIF: %s: %s\n", eth, strerror(errno)); goto bad; } } if (v == 0) { fprintf(stderr, "BIOCSBLEN: %s: No buffer size worked\n", eth); goto bad; } /* Allocate memory for the packet buffer */ pktbufsz = v; if ((pktbuf = malloc(pktbufsz)) == NULL) { perror("malloc"); goto bad; } /* Don't wait for buffer to be full or timeout */ v = 1; if (ioctl(fd, BIOCIMMEDIATE, &v) < 0) { perror("BIOCIMMEDIATE"); goto bad; } /* Only read incoming packets */ v = 0; if (ioctl(fd, BIOCSSEESENT, &v) < 0) { perror("BIOCSSEESENT"); goto bad; } /* Don't complete ethernet hdr */ v = 1; if (ioctl(fd, BIOCSHDRCMPLT, &v) < 0) { perror("BIOCSHDRCMPLT"); goto bad; } /* Get the data link layer type. */ if (ioctl(fd, BIOCGDLT, (caddr_t)&v) < 0) { perror("BIOCGDLT"); goto bad; } linktype = v; /* Get the filter buf size */ if (ioctl(fd, BIOCGBLEN, (caddr_t)&v) < 0) { perror("BIOCGBLEN"); goto bad; } bufsize = v; if (ioctl(fd, BIOCSETF, (caddr_t)bpf_program) < 0) { perror("BIOSETF"); goto bad; } free_bpf_program(bpf_program); return(fd); bad: free_bpf_program(bpf_program); close(fd); return(-1); } int getea(int s, char *eth, uchar *ea) { int mib[6]; size_t len; char *buf, *next, *end; struct if_msghdr *ifm; struct sockaddr_dl *sdl; mib[0] = CTL_NET; mib[1] = AF_ROUTE; mib[2] = 0; mib[3] = AF_LINK; mib[4] = NET_RT_IFLIST; mib[5] = 0; if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) { return (-1); } if (!(buf = (char *) malloc(len))) { return (-1); } if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) { free(buf); return (-1); } end = buf + len; for (next = buf; next < end; next += ifm->ifm_msglen) { ifm = (struct if_msghdr *)next; if (ifm->ifm_type == RTM_IFINFO) { sdl = (struct sockaddr_dl *)(ifm + 1); if (strncmp(&sdl->sdl_data[0], eth, sdl->sdl_nlen) == 0) { memcpy(ea, LLADDR(sdl), ETHER_ADDR_LEN); break; } } } free(buf); return(0); } #if 0 int getsec(int fd, uchar *place, vlong lba, int nsec) { return pread(fd, place, nsec * 512, lba * 512); } int putsec(int fd, uchar *place, vlong lba, int nsec) { return pwrite(fd, place, nsec * 512, lba * 512); } #endif static int pktn = 0; static uchar *pktbp = NULL; int getpkt(int fd, uchar *buf, int sz) { register struct bpf_hdr *bh; register int pktlen, retlen; if (pktn <= 0) { if ((pktn = read(fd, pktbuf, pktbufsz)) < 0) { perror("read"); exit(1); } pktbp = pktbuf; } bh = (struct bpf_hdr *) pktbp; retlen = (int) bh->bh_caplen; /* This memcpy() is currently needed */ memcpy(buf, (void *)(pktbp + bh->bh_hdrlen), retlen > sz ? sz : retlen); pktlen = bh->bh_hdrlen + bh->bh_caplen; pktbp = pktbp + BPF_WORDALIGN(pktlen); pktn -= (int) BPF_WORDALIGN(pktlen); return retlen; } int putpkt(int fd, uchar *buf, int sz) { return write(fd, buf, sz); } int getmtu(int fd, char *name) { struct ifreq xx; int s, n, p; s = socket(AF_INET, SOCK_RAW, 0); if (s == -1) { perror("Can't get mtu"); return 1500; } xx.ifr_addr.sa_family = AF_INET; snprintf(xx.ifr_name, sizeof xx.ifr_name, "%s", name); n = ioctl(s, SIOCGIFMTU, &xx); if (n == -1) { perror("Can't get mtu"); return 1500; } close(s); // FreeBSD bpf writes are capped at one PAGESIZE'd mbuf. As such we must // limit our sector count. See FreeBSD PR 205164, OpenAoE/vblade #7. p = getpagesize(); if (xx.ifr_mtu > p) { return p; } return xx.ifr_mtu; } vlong getsize(int fd) { off_t media_size; vlong size; struct stat s; int n; // Try getting disklabel from block dev if ((n = ioctl(fd, DIOCGMEDIASIZE, &media_size)) != -1) { size = media_size; } else { // must not be a block special dev if (fstat(fd, &s) == -1) { perror("getsize"); exit(1); } size = s.st_size; } printf("ioctl returned %d\n", n); printf("%lld bytes\n", size); return size; }
5,924
C
.c
262
20.248092
73
0.637888
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
true
5
ata.c
ventoy_Ventoy/VBLADE/vblade-master/ata.c
// ata.c: ATA simulator for vblade #include "config.h" #include <string.h> #include <stdio.h> #include <sys/types.h> #include "dat.h" #include "fns.h" enum { // err bits UNC = 1<<6, MC = 1<<5, IDNF = 1<<4, MCR = 1<<3, ABRT = 1<<2, NM = 1<<1, // status bits BSY = 1<<7, DRDY = 1<<6, DF = 1<<5, DRQ = 1<<3, ERR = 1<<0, }; static ushort ident[256]; static void setfld(ushort *a, int idx, int len, char *str) // set field in ident { uchar *p; p = (uchar *)(a+idx); while (len > 0) { if (*str == 0) p[1] = ' '; else p[1] = *str++; if (*str == 0) p[0] = ' '; else p[0] = *str++; p += 2; len -= 2; } } static void setlba28(ushort *ident, vlong lba) { uchar *cp; cp = (uchar *) &ident[60]; *cp++ = lba; *cp++ = lba >>= 8; *cp++ = lba >>= 8; *cp++ = (lba >>= 8) & 0xf; } static void setlba48(ushort *ident, vlong lba) { uchar *cp; cp = (uchar *) &ident[100]; *cp++ = lba; *cp++ = lba >>= 8; *cp++ = lba >>= 8; *cp++ = lba >>= 8; *cp++ = lba >>= 8; *cp++ = lba >>= 8; } static void setushort(ushort *a, int i, ushort n) { uchar *p; p = (uchar *)(a+i); *p++ = n & 0xff; *p++ = n >> 8; } void atainit(void) { char buf[64]; setushort(ident, 47, 0x8000); setushort(ident, 49, 0x0200); setushort(ident, 50, 0x4000); setushort(ident, 83, 0x5400); setushort(ident, 84, 0x4000); setushort(ident, 86, 0x1400); setushort(ident, 87, 0x4000); setushort(ident, 93, 0x400b); setfld(ident, 27, 40, "Coraid EtherDrive vblade"); sprintf(buf, "V%d", VBLADE_VERSION); setfld(ident, 23, 8, buf); setfld(ident, 10, 20, serial); } /* The ATA spec is weird in that you specify the device size as number * of sectors and then address the sectors with an offset. That means * with LBA 28 you shouldn't see an LBA of all ones. Still, we don't * check for that. */ int atacmd(Ataregs *p, uchar *dp, int ndp, int payload) // do the ata cmd { vlong lba; ushort *ip; int n; enum { MAXLBA28SIZE = 0x0fffffff }; extern int maxscnt; p->status = 0; switch (p->cmd) { default: p->status = DRDY | ERR; p->err = ABRT; return 0; case 0xe7: // flush cache return 0; case 0xec: // identify device if (p->sectors != 1 || ndp < 512) return -1; memmove(dp, ident, 512); ip = (ushort *)dp; if (size & ~MAXLBA28SIZE) setlba28(ip, MAXLBA28SIZE); else setlba28(ip, size); setlba48(ip, size); p->err = 0; p->status = DRDY; p->sectors = 0; return 0; case 0xe5: // check power mode p->err = 0; p->sectors = 0xff; // the device is active or idle p->status = DRDY; return 0; case 0x20: // read sectors case 0x30: // write sectors lba = p->lba & MAXLBA28SIZE; break; case 0x24: // read sectors ext case 0x34: // write sectors ext lba = p->lba & 0x0000ffffffffffffLL; // full 48 break; } // we ought not be here unless we are a read/write if (p->sectors > maxscnt || p->sectors*512 > ndp) return -1; if (lba + p->sectors > size) { p->err = IDNF; p->status = DRDY | ERR; p->lba = lba; return 0; } if (p->cmd == 0x20 || p->cmd == 0x24) n = getsec(bfd, dp, lba+offset, p->sectors); else { // packet should be big enough to contain the data if (payload < 512 * p->sectors) return -1; n = putsec(bfd, dp, lba+offset, p->sectors); } n /= 512; if (n != p->sectors) { p->err = ABRT; p->status = ERR; } else p->err = 0; p->status |= DRDY; p->lba += n; p->sectors -= n; return 0; }
3,425
C
.c
165
18.509091
70
0.608333
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
6
aoe.c
ventoy_Ventoy/VBLADE/vblade-master/aoe.c
// aoe.c: the ATA over Ethernet virtual EtherDrive (R) blade #define _GNU_SOURCE #include "config.h" #include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <netinet/in.h> #include "dat.h" #include "fns.h" enum { Nmasks= 32, Nsrr= 256, Alen= 6, }; uchar masks[Nmasks*Alen]; int nmasks; uchar srr[Nsrr*Alen]; int nsrr; char config[Nconfig]; int nconfig = 0; int maxscnt = 2; char *ifname; int bufcnt = Bufcount; #ifndef O_BINARY #define O_BINARY 0 #endif typedef unsigned long long u64_t; typedef unsigned int u32_t; #pragma pack(4) typedef struct ventoy_img_chunk { u32_t img_start_sector; // sector size: 2KB u32_t img_end_sector; // included u64_t disk_start_sector; // in disk_sector_size u64_t disk_end_sector; // included }ventoy_img_chunk; typedef struct ventoy_disk_map { u64_t img_start_sector; u64_t img_end_sector; u64_t disk_start_sector; u64_t disk_end_sector; }ventoy_disk_map; #pragma pack() static int verbose = 0; static u64_t g_iso_file_size = 0; static int g_img_map_num = 0; static ventoy_disk_map *g_img_map = NULL; static ventoy_disk_map * vtoydm_get_img_map_data(const char *img_map_file, int *plen) { int i; int len; int rc = 1; u64_t sector_num; FILE *fp = NULL; ventoy_img_chunk *chunk = NULL; ventoy_disk_map *map = NULL; fp = fopen(img_map_file, "rb"); if (NULL == fp) { fprintf(stderr, "Failed to open file %s\n", img_map_file); return NULL; } fseek(fp, 0, SEEK_END); len = (int)ftell(fp); fseek(fp, 0, SEEK_SET); chunk = (ventoy_img_chunk *)malloc(len); if (NULL == chunk) { fprintf(stderr, "Failed to malloc memory len:%d\n", len); goto end; } if (fread(chunk, 1, len, fp) != len) { fprintf(stderr, "Failed to read file\n"); goto end; } if (len % sizeof(ventoy_img_chunk)) { fprintf(stderr, "image map file size %d is not aligned with %d\n", len, (int)sizeof(ventoy_img_chunk)); goto end; } map = (ventoy_disk_map *)malloc((len / sizeof(ventoy_img_chunk)) * sizeof(ventoy_disk_map)); if (NULL == map) { fprintf(stderr, "Failed to malloc memory\n"); goto end; } for (i = 0; i < len / sizeof(ventoy_img_chunk); i++) { sector_num = chunk[i].img_end_sector - chunk[i].img_start_sector + 1; g_iso_file_size += sector_num * 2048; map[i].img_start_sector = chunk[i].img_start_sector << 2; map[i].img_end_sector = (chunk[i].img_end_sector << 2) + 3; map[i].disk_start_sector = chunk[i].disk_start_sector; map[i].disk_end_sector = chunk[i].disk_end_sector; } rc = 0; end: fclose(fp); if (chunk) { free(chunk); chunk = NULL; } *plen = len; return map; } static void parse_img_chunk(const char *img_map_file) { int len; g_img_map = vtoydm_get_img_map_data(img_map_file, &len); if (g_img_map) { g_img_map_num = len / sizeof(ventoy_img_chunk); } } static u64_t get_disk_sector(u64_t lba) { int i; ventoy_disk_map *cur = g_img_map; for (i = 0; i < g_img_map_num; i++, cur++) { if (lba >= cur->img_start_sector && lba <= cur->img_end_sector) { return (lba - cur->img_start_sector) + cur->disk_start_sector; } } return 0; } int getsec(int fd, uchar *place, vlong lba, int nsec) { int i; int count = 0; u64_t last_sector; u64_t sector; count = 1; last_sector = get_disk_sector((u64_t)lba); for (i = 1; i < nsec; i++) { sector = get_disk_sector((u64_t)(lba + i)); if (sector == (last_sector + count)) { count++; } else { lseek(fd, last_sector * 512, SEEK_SET); read(fd, place, count * 512); last_sector = sector; count = 1; } } lseek(fd, last_sector * 512, SEEK_SET); read(fd, place, count * 512); return nsec * 512; } // read only int putsec(int fd, uchar *place, vlong lba, int nsec) { return nsec * 512; } void aoead(int fd) // advertise the virtual blade { uchar buf[2000]; Conf *p; int i; p = (Conf *)buf; memset(p, 0, sizeof *p); memset(p->h.dst, 0xff, 6); memmove(p->h.src, mac, 6); p->h.type = htons(0x88a2); p->h.flags = Resp; p->h.maj = htons(shelf); p->h.min = slot; p->h.cmd = Config; p->bufcnt = htons(bufcnt); p->scnt = maxscnt = (getmtu(sfd, ifname) - sizeof (Ata)) / 512; p->firmware = htons(FWV); p->vercmd = 0x10 | Qread; memcpy(p->data, config, nconfig); p->len = htons(nconfig); if (nmasks == 0) if (putpkt(fd, buf, sizeof *p - sizeof p->data + nconfig) == -1) { perror("putpkt aoe id"); return; } for (i=0; i<nmasks; i++) { memcpy(p->h.dst, &masks[i*Alen], Alen); if (putpkt(fd, buf, sizeof *p - sizeof p->data + nconfig) == -1) perror("putpkt aoe id"); } } int isbcast(uchar *ea) { uchar *b = (uchar *)"\377\377\377\377\377\377"; return memcmp(ea, b, 6) == 0; } long long getlba(uchar *p) { vlong v; int i; v = 0; for (i = 0; i < 6; i++) v |= (vlong)(*p++) << i * 8; return v; } int aoeata(Ata *p, int pktlen) // do ATA reqeust { Ataregs r; int len = 60; int n; r.lba = getlba(p->lba); r.sectors = p->sectors; r.feature = p->err; r.cmd = p->cmd; if (r.cmd != 0xec) if (!rrok(p->h.src)) { p->h.flags |= Error; p->h.error = Res; return len; } if (atacmd(&r, (uchar *)(p+1), maxscnt*512, pktlen - sizeof(*p)) < 0) { p->h.flags |= Error; p->h.error = BadArg; return len; } if (!(p->aflag & Write)) if ((n = p->sectors)) { n -= r.sectors; len = sizeof (Ata) + (n*512); } p->sectors = r.sectors; p->err = r.err; p->cmd = r.status; return len; } #define QCMD(x) ((x)->vercmd & 0xf) // yes, this makes unnecessary copies. int confcmd(Conf *p, int payload) // process conf request { int len; len = ntohs(p->len); if (QCMD(p) != Qread) if (len > Nconfig || len > payload) return 0; // if you can't play nice ... switch (QCMD(p)) { case Qtest: if (len != nconfig) return 0; // fall thru case Qprefix: if (len > nconfig) return 0; if (memcmp(config, p->data, len)) return 0; // fall thru case Qread: break; case Qset: if (nconfig) if (nconfig != len || memcmp(config, p->data, len)) { p->h.flags |= Error; p->h.error = ConfigErr; break; } // fall thru case Qfset: nconfig = len; memcpy(config, p->data, nconfig); break; default: p->h.flags |= Error; p->h.error = BadArg; } memmove(p->data, config, nconfig); p->len = htons(nconfig); p->bufcnt = htons(bufcnt); p->scnt = maxscnt = (getmtu(sfd, ifname) - sizeof (Ata)) / 512; p->firmware = htons(FWV); p->vercmd = 0x10 | QCMD(p); // aoe v.1 return nconfig + sizeof *p - sizeof p->data; } static int aoesrr(Aoesrr *sh, int len) { uchar *m, *e; int n; e = (uchar *) sh + len; m = (uchar *) sh + Nsrrhdr; switch (sh->rcmd) { default: e: sh->h.error = BadArg; sh->h.flags |= Error; break; case 1: // set if (!rrok(sh->h.src)) { sh->h.error = Res; sh->h.flags |= Error; break; } case 2: // force set n = sh->nmacs * 6; if (e < m + n) goto e; nsrr = sh->nmacs; memmove(srr, m, n); case 0: // read break; } sh->nmacs = nsrr; n = nsrr * 6; memmove(m, srr, n); return Nsrrhdr + n; } static int addmask(uchar *ea) { uchar *p, *e; p = masks; e = p + nmasks; for (; p<e; p += 6) if (!memcmp(p, ea, 6)) return 2; if (nmasks >= Nmasks) return 0; memmove(p, ea, 6); nmasks++; return 1; } static void rmmask(uchar *ea) { uchar *p, *e; p = masks; e = p + nmasks; for (; p<e; p+=6) if (!memcmp(p, ea, 6)) { memmove(p, p+6, e-p-6); nmasks--; return; } } static int aoemask(Aoemask *mh, int len) { Mdir *md, *mdi, *mde; int i, n; n = 0; md = mdi = (Mdir *) ((uchar *)mh + Nmaskhdr); switch (mh->cmd) { case Medit: mde = md + mh->nmacs; for (; md<mde; md++) { switch (md->cmd) { case MDdel: rmmask(md->mac); continue; case MDadd: if (addmask(md->mac)) continue; mh->merror = MEfull; mh->nmacs = md - mdi; goto e; case MDnop: continue; default: mh->merror = MEbaddir; mh->nmacs = md - mdi; goto e; } } // success. fall thru to return list case Mread: md = mdi; for (i=0; i<nmasks; i++) { md->res = md->cmd = 0; memmove(md->mac, &masks[i*6], 6); md++; } mh->merror = 0; mh->nmacs = nmasks; n = sizeof *md * nmasks; break; default: mh->h.flags |= Error; mh->h.error = BadArg; } e: return n + Nmaskhdr; } void doaoe(Aoehdr *p, int n) { int len; switch (p->cmd) { case ATAcmd: if (n < Natahdr) return; len = aoeata((Ata*)p, n); break; case Config: if (n < Ncfghdr) return; len = confcmd((Conf *)p, n); break; case Mask: if (n < Nmaskhdr) return; len = aoemask((Aoemask *)p, n); break; case Resrel: if (n < Nsrrhdr) return; len = aoesrr((Aoesrr *)p, n); break; default: p->error = BadCmd; p->flags |= Error; len = n; break; } if (len <= 0) return; memmove(p->dst, p->src, 6); memmove(p->src, mac, 6); p->maj = htons(shelf); p->min = slot; p->flags |= Resp; if (putpkt(sfd, (uchar *) p, len) == -1) { perror("write to network"); exit(1); } } void aoe(void) { Aoehdr *p; uchar *buf; int n, sh; long pagesz; enum { bufsz = 1<<16, }; if ((pagesz = sysconf(_SC_PAGESIZE)) < 0) { perror("sysconf"); exit(1); } if ((buf = malloc(bufsz + pagesz)) == NULL) { perror("malloc"); exit(1); } n = (size_t) buf + sizeof(Ata); if (n & (pagesz - 1)) buf += pagesz - (n & (pagesz - 1)); aoead(sfd); for (;;) { n = getpkt(sfd, buf, bufsz); if (n < 0) { perror("read network"); exit(1); } if (n < sizeof(Aoehdr)) continue; p = (Aoehdr *) buf; if (ntohs(p->type) != 0x88a2) continue; if (p->flags & Resp) continue; sh = ntohs(p->maj); if (sh != shelf && sh != (ushort)~0) continue; if (p->min != slot && p->min != (uchar)~0) continue; if (nmasks && !maskok(p->src)) continue; doaoe(p, n); } } void usage(void) { fprintf(stderr, "usage: %s [-b bufcnt] [-o offset] [-l length] [-d ] [-s] [-r] [ -m mac[,mac...] ] shelf slot netif filename\n", progname); exit(1); } /* parseether from plan 9 */ int parseether(uchar *to, char *from) { char nip[4]; char *p; int i; p = from; for(i = 0; i < 6; i++){ if(*p == 0) return -1; nip[0] = *p++; if(*p == 0) return -1; nip[1] = *p++; nip[2] = 0; to[i] = strtoul(nip, 0, 16); if(*p == ':') p++; } return 0; } void setmask(char *ml) { char *p; int n; for (; ml; ml=p) { p = strchr(ml, ','); if (p) *p++ = '\0'; n = parseether(&masks[nmasks*Alen], ml); if (n < 0) fprintf(stderr, "ignoring mask %s, parseether failure\n", ml); else nmasks++; } } int maskok(uchar *ea) { int i, ok = 0; for (i=0; !ok && i<nmasks; i++) ok = memcmp(ea, &masks[i*Alen], Alen) == 0; return ok; } int rrok(uchar *ea) { int i, ok = 0; if (nsrr == 0) return 1; for (i=0; !ok && i<nsrr; i++) ok = memcmp(ea, &srr[i*Alen], Alen) == 0; return ok; } void setserial(int sh, int sl) { char h[32]; h[0] = 0; gethostname(h, sizeof h); snprintf(serial, Nserial, "%d.%d:%.*s", sh, sl, (int) sizeof h, h); } int main(int argc, char **argv) { int ch, omode = 0, readonly = 0; vlong length = 0; char *end; char filepath[300] = {0}; /* Avoid to be killed by systemd */ if (access("/etc/initrd-release", F_OK) >= 0) { argv[0][0] = '@'; } bufcnt = Bufcount; offset = 0; setbuf(stdin, NULL); progname = *argv; while ((ch = getopt(argc, argv, "b:dsrm:f:tv::o:l:")) != -1) { switch (ch) { case 'b': bufcnt = atoi(optarg); break; case 'd': #ifdef O_DIRECT omode |= O_DIRECT; #endif break; case 's': omode |= O_SYNC; break; case 'r': readonly = 1; break; case 'm': setmask(optarg); break; case 't': return 0; case 'v': verbose = 1; break; case 'f': strncpy(filepath, optarg, sizeof(filepath) - 1); break; case 'o': offset = strtoll(optarg, &end, 0); if (end == optarg || offset < 0) usage(); break; case 'l': length = strtoll(optarg, &end, 0); if (end == optarg || length < 1) usage(); break; case '?': default: usage(); } } argc -= optind; argv += optind; if (argc != 4 || bufcnt <= 0) usage(); omode |= readonly ? O_RDONLY : O_RDWR; parse_img_chunk(filepath); bfd = open(argv[3], omode); if (bfd == -1) { perror("open"); exit(1); } shelf = atoi(argv[0]); slot = atoi(argv[1]); setserial(shelf, slot); size = g_iso_file_size; //getsize(bfd); size /= 512; if (size <= offset) { if (offset) fprintf(stderr, "Offset %lld too large for %lld-sector export\n", offset, size); else fputs("0-sector file size is too small\n", stderr); exit(1); } size -= offset; if (length) { if (length > size) { fprintf(stderr, "Length %llu too big - exceeds size of file!\n", offset); exit(1); } size = length; } ifname = argv[2]; sfd = dial(ifname, bufcnt); if (sfd < 0) return 1; getea(sfd, ifname, mac); if (verbose) { printf("pid %ld: e%d.%d, %lld sectors %s\n", (long) getpid(), shelf, slot, size, readonly ? "O_RDONLY" : "O_RDWR"); } fflush(stdout); atainit(); aoe(); return 0; }
13,783
C
.c
664
17.192771
130
0.573569
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
7
bpf.c
ventoy_Ventoy/VBLADE/vblade-master/bpf.c
// bpf.c: bpf packet filter for linux/freebsd #include "config.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include "dat.h" #include "fns.h" struct bpf_insn { ushort code; uchar jt; uchar jf; u_int32_t k; }; struct bpf_program { uint bf_len; struct bpf_insn *bf_insns; }; /* instruction classes */ #define BPF_CLASS(code) ((code) & 0x07) #define BPF_LD 0x00 #define BPF_LDX 0x01 #define BPF_ST 0x02 #define BPF_STX 0x03 #define BPF_ALU 0x04 #define BPF_JMP 0x05 #define BPF_RET 0x06 #define BPF_MISC 0x07 /* ld/ldx fields */ #define BPF_SIZE(code) ((code) & 0x18) #define BPF_W 0x00 #define BPF_H 0x08 #define BPF_B 0x10 #define BPF_MODE(code) ((code) & 0xe0) #define BPF_IMM 0x00 #define BPF_ABS 0x20 #define BPF_IND 0x40 #define BPF_MEM 0x60 #define BPF_LEN 0x80 #define BPF_MSH 0xa0 /* alu/jmp fields */ #define BPF_OP(code) ((code) & 0xf0) #define BPF_ADD 0x00 #define BPF_SUB 0x10 #define BPF_MUL 0x20 #define BPF_DIV 0x30 #define BPF_OR 0x40 #define BPF_AND 0x50 #define BPF_LSH 0x60 #define BPF_RSH 0x70 #define BPF_NEG 0x80 #define BPF_JA 0x00 #define BPF_JEQ 0x10 #define BPF_JGT 0x20 #define BPF_JGE 0x30 #define BPF_JSET 0x40 #define BPF_SRC(code) ((code) & 0x08) #define BPF_K 0x00 #define BPF_X 0x08 /* ret - BPF_K and BPF_X also apply */ #define BPF_RVAL(code) ((code) & 0x18) #define BPF_A 0x10 /* misc */ #define BPF_MISCOP(code) ((code) & 0xf8) #define BPF_TAX 0x00 #define BPF_TXA 0x80 /* macros for insn array initializers */ #define BPF_STMT(code, k) { (ushort)(code), 0, 0, k } #define BPF_JUMP(code, k, jt, jf) { (ushort)(code), jt, jf, k } void * create_bpf_program(int shelf, int slot) { struct bpf_program *bpf_program; struct bpf_insn insns[] = { /* CHECKTYPE: Load the type into register */ BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 12), /* Does it match AoE Type (0x88a2)? No, goto INVALID */ BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x88a2, 0, 10), /* Load the flags into register */ BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 14), /* Check to see if the Resp flag is set */ BPF_STMT(BPF_ALU+BPF_AND+BPF_K, Resp), /* Yes, goto INVALID */ BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0, 0, 7), /* CHECKSHELF: Load the shelf number into register */ BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 16), /* Does it match shelf number? Yes, goto CHECKSLOT */ BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, shelf, 1, 0), /* Does it match broadcast? No, goto INVALID */ BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0xffff, 0, 4), /* CHECKSLOT: Load the slot number into register */ BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 18), /* Does it match shelf number? Yes, goto VALID */ BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, slot, 1, 0), /* Does it match broadcast? No, goto INVALID */ BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0xff, 0, 1), /* VALID: return -1 (allow the packet to be read) */ BPF_STMT(BPF_RET+BPF_K, -1), /* INVALID: return 0 (ignore the packet) */ BPF_STMT(BPF_RET+BPF_K, 0), }; if ((bpf_program = malloc(sizeof(struct bpf_program))) == NULL || (bpf_program->bf_insns = malloc(sizeof(insns))) == NULL) { perror("malloc"); exit(1); } bpf_program->bf_len = sizeof(insns)/sizeof(struct bpf_insn); memcpy(bpf_program->bf_insns, insns, sizeof(insns)); return (void *)bpf_program; } void free_bpf_program(void *bpf_program) { free(((struct bpf_program *) bpf_program)->bf_insns); free(bpf_program); }
3,417
C
.c
116
27.698276
66
0.679331
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
8
linux.c
ventoy_Ventoy/VBLADE/vblade-master/linux.c
// linux.c: low level access routines for Linux #define _GNU_SOURCE #include "config.h" #include <sys/socket.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include <sys/time.h> #include <features.h> /* for the glibc version number */ #if __GLIBC__ >= 2 && __GLIBC_MINOR >= 1 #include <netpacket/packet.h> #include <net/ethernet.h> /* the L2 protocols */ #else #include <asm/types.h> #include <linux/if_packet.h> #include <linux/if_ether.h> /* The L2 protocols */ #endif #include <fcntl.h> #include <sys/ioctl.h> #include <sys/types.h> #include <net/if.h> #include <netinet/in.h> #include <linux/fs.h> #include <sys/stat.h> #include "dat.h" #include "fns.h" int getindx(int, char *); int getea(int, char *, uchar *); int dial(char *eth, int bufcnt) // get us a raw connection to an interface { int i, n, s; struct sockaddr_ll sa; enum { aoe_type = 0x88a2 }; memset(&sa, 0, sizeof sa); s = socket(PF_PACKET, SOCK_RAW, htons(aoe_type)); if (s == -1) { perror("got bad socket"); return -1; } i = getindx(s, eth); if (i < 0) { perror(eth); return -1; } sa.sll_family = AF_PACKET; sa.sll_protocol = htons(0x88a2); sa.sll_ifindex = i; n = bind(s, (struct sockaddr *)&sa, sizeof sa); if (n == -1) { perror("bind funky"); return -1; } struct bpf_program { ulong bf_len; void *bf_insns; } *bpf_program = create_bpf_program(shelf, slot); setsockopt(s, SOL_SOCKET, SO_ATTACH_FILTER, bpf_program, sizeof(*bpf_program)); free_bpf_program(bpf_program); n = bufcnt * getmtu(s, eth); if (setsockopt(s, SOL_SOCKET, SO_SNDBUF, &n, sizeof(n)) < 0) perror("setsockopt SOL_SOCKET, SO_SNDBUF"); if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, &n, sizeof(n)) < 0) perror("setsockopt SOL_SOCKET, SO_RCVBUF"); return s; } int getindx(int s, char *name) // return the index of device 'name' { struct ifreq xx; int n; snprintf(xx.ifr_name, sizeof xx.ifr_name, "%s", name); n = ioctl(s, SIOCGIFINDEX, &xx); if (n == -1) return -1; return xx.ifr_ifindex; } int getea(int s, char *name, uchar *ea) { struct ifreq xx; int n; snprintf(xx.ifr_name, sizeof xx.ifr_name, "%s", name); n = ioctl(s, SIOCGIFHWADDR, &xx); if (n == -1) { perror("Can't get hw addr"); return 0; } memmove(ea, xx.ifr_hwaddr.sa_data, 6); return 1; } int getmtu(int s, char *name) { struct ifreq xx; int n; snprintf(xx.ifr_name, sizeof xx.ifr_name, "%s", name); n = ioctl(s, SIOCGIFMTU, &xx); if (n == -1) { perror("Can't get mtu"); return 1500; } return xx.ifr_mtu; } #if 0 int getsec(int fd, uchar *place, vlong lba, int nsec) { return pread(fd, place, nsec * 512, lba * 512); } int putsec(int fd, uchar *place, vlong lba, int nsec) { return pwrite(fd, place, nsec * 512, lba * 512); } #endif int getpkt(int fd, uchar *buf, int sz) { return read(fd, buf, sz); } int putpkt(int fd, uchar *buf, int sz) { return write(fd, buf, sz); } vlong getsize(int fd) { vlong size; struct stat s; int n; n = ioctl(fd, BLKGETSIZE64, &size); if (n == -1) { // must not be a block special n = fstat(fd, &s); if (n == -1) { perror("getsize"); exit(1); } size = s.st_size; } return size; }
3,179
C
.c
144
20.180556
80
0.661467
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
true
12
u64.c
ventoy_Ventoy/VBLADE/vblade-master/config/u64.c
#include <stdio.h> int main(void) { u64 n; printf("%d\n", (int) n+2); return 0; }
86
C
.c
7
10.714286
27
0.615385
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
16
VDiskRawData.c
ventoy_Ventoy/EDK2/edk2_mod/edk2-edk2-stable201911/MdeModulePkg/Application/VDiskChain/VDiskRawData.c
#include <Uefi.h> int vdisk_get_vdisk_raw(UINT8 **buf, UINT32 *size) { *buf = NULL; *size = 0; return 0; }
106
C
.c
2
52.5
88
0.647619
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
170
vtoy_fuse_iso.c
ventoy_Ventoy/FUSEISO/vtoy_fuse_iso.c
/****************************************************************************** * vtoy_fuse_iso.c * * Copyright (c) 2020, longpanda <[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see <http://www.gnu.org/licenses/>. * */ #define FUSE_USE_VERSION 26 #include <fuse.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <errno.h> #include <fcntl.h> typedef unsigned int uint32_t; typedef struct dmtable_entry { uint32_t isoSector; uint32_t sectorNum; unsigned long long diskSector; }dmtable_entry; #define MAX_ENTRY_NUM (1024 * 1024 / sizeof(dmtable_entry)) static int verbose = 0; #define debug(fmt, ...) if(verbose) printf(fmt, ##__VA_ARGS__) static int g_disk_fd = -1; static uint64_t g_iso_file_size; static char g_mnt_point[512]; static char g_iso_file_name[512]; static dmtable_entry *g_disk_entry_list = NULL; static int g_disk_entry_num = 0; static int ventoy_iso_getattr(const char *path, struct stat *statinfo) { int ret = -ENOENT; if (path && statinfo) { memset(statinfo, 0, sizeof(struct stat)); if (path[0] == '/' && path[1] == 0) { statinfo->st_mode = S_IFDIR | 0755; statinfo->st_nlink = 2; ret = 0; } else if (strcmp(path, g_iso_file_name) == 0) { statinfo->st_mode = S_IFREG | 0444; statinfo->st_nlink = 1; statinfo->st_size = g_iso_file_size; ret = 0; } } return ret; } static int ventoy_iso_readdir ( const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *file ) { (void)offset; (void)file; if (path[0] != '/' || path[1] != 0) { return -ENOENT; } filler(buf, ".", NULL, 0); filler(buf, "..", NULL, 0); filler(buf, g_iso_file_name + 1, NULL, 0); return 0; } static int ventoy_iso_open(const char *path, struct fuse_file_info *file) { if (strcmp(path, g_iso_file_name) != 0) { return -ENOENT; } if ((file->flags & 3) != O_RDONLY) { return -EACCES; } return 0; } static int ventoy_read_iso_sector(uint32_t sector, uint32_t num, char *buf) { uint32_t i = 0; uint32_t leftSec = 0; uint32_t readSec = 0; off_t offset = 0; dmtable_entry *entry = NULL; for (i = 0; i < g_disk_entry_num && num > 0; i++) { entry = g_disk_entry_list + i; if (sector >= entry->isoSector && sector < entry->isoSector + entry->sectorNum) { offset = (entry->diskSector + (sector - entry->isoSector)) * 512; leftSec = entry->sectorNum - (sector - entry->isoSector); readSec = (leftSec > num) ? num : leftSec; pread(g_disk_fd, buf, readSec * 512, offset); sector += readSec; buf += readSec * 512; num -= readSec; } } return 0; } static int ventoy_iso_read ( const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *file ) { uint32_t mod = 0; uint32_t align = 0; uint32_t sector = 0; uint32_t number = 0; size_t leftsize = 0; char secbuf[512]; (void)file; if(strcmp(path, g_iso_file_name) != 0) { return -ENOENT; } if (offset >= g_iso_file_size) { return 0; } if (offset + size > g_iso_file_size) { size = g_iso_file_size - offset; } leftsize = size; sector = offset / 512; mod = offset % 512; if (mod > 0) { align = 512 - mod; ventoy_read_iso_sector(sector, 1, secbuf); if (leftsize > align) { memcpy(buf, secbuf + mod, align); buf += align; offset += align; sector++; leftsize -= align; } else { memcpy(buf, secbuf + mod, leftsize); return size; } } number = leftsize / 512; ventoy_read_iso_sector(sector, number, buf); buf += number * 512; mod = leftsize % 512; if (mod > 0) { ventoy_read_iso_sector(sector + number, 1, secbuf); memcpy(buf, secbuf, mod); } return size; } static struct fuse_operations ventoy_op = { .getattr = ventoy_iso_getattr, .readdir = ventoy_iso_readdir, .open = ventoy_iso_open, .read = ventoy_iso_read, }; static int ventoy_parse_dmtable(const char *filename) { FILE *fp = NULL; char diskname[128] = {0}; char line[256] = {0}; dmtable_entry *entry= g_disk_entry_list; fp = fopen(filename, "r"); if (NULL == fp) { printf("Failed to open file %s\n", filename); return 1; } /* read untill the last line */ while (fgets(line, sizeof(line), fp) && g_disk_entry_num < MAX_ENTRY_NUM) { sscanf(line, "%u %u linear %s %llu", &entry->isoSector, &entry->sectorNum, diskname, &entry->diskSector); g_iso_file_size += (uint64_t)entry->sectorNum * 512ULL; g_disk_entry_num++; entry++; } fclose(fp); if (g_disk_entry_num >= MAX_ENTRY_NUM) { fprintf(stderr, "ISO file has too many fragments ( more than %u )\n", MAX_ENTRY_NUM); return 1; } debug("iso file size: %llu disk name %s\n", g_iso_file_size, diskname); g_disk_fd = open(diskname, O_RDONLY); if (g_disk_fd < 0) { debug("Failed to open %s\n", diskname); return 1; } return 0; } int main(int argc, char **argv) { int rc; int ch; char filename[512] = {0}; /* Avoid to be killed by systemd */ if (access("/etc/initrd-release", F_OK) >= 0) { argv[0][0] = '@'; } g_iso_file_name[0] = '/'; while ((ch = getopt(argc, argv, "f:s:m:v::t::")) != -1) { if (ch == 'f') { strncpy(filename, optarg, sizeof(filename) - 1); } else if (ch == 'm') { strncpy(g_mnt_point, optarg, sizeof(g_mnt_point) - 1); } else if (ch == 's') { strncpy(g_iso_file_name + 1, optarg, sizeof(g_iso_file_name) - 2); } else if (ch == 'v') { verbose = 1; } else if (ch == 't') // for test { return 0; } } if (filename[0] == 0) { fprintf(stderr, "Must input dmsetup table file with -f\n"); return 1; } if (g_mnt_point[0] == 0) { fprintf(stderr, "Must input mount point with -m\n"); return 1; } if (g_iso_file_name[1] == 0) { strncpy(g_iso_file_name + 1, "ventoy.iso", sizeof(g_iso_file_name) - 2); } debug("ventoy fuse iso: %s %s %s\n", filename, g_iso_file_name, g_mnt_point); g_disk_entry_list = malloc(MAX_ENTRY_NUM * sizeof(dmtable_entry)); if (NULL == g_disk_entry_list) { return 1; } rc = ventoy_parse_dmtable(filename); if (rc) { free(g_disk_entry_list); return rc; } argv[1] = g_mnt_point; argv[2] = NULL; rc = fuse_main(2, argv, &ventoy_op, NULL); close(g_disk_fd); free(g_disk_entry_list); return rc; }
7,887
C
.c
289
21.176471
93
0.555955
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
175
process_fragments.h
ventoy_Ventoy/SQUASHFS/squashfs-tools-4.4/squashfs-tools/process_fragments.h
#ifndef PROCESS_FRAGMENTS_H #define PROCESS_FRAGMENTS_H /* * Create a squashfs filesystem. This is a highly compressed read only * filesystem. * * Copyright (c) 2014 * Phillip Lougher <[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2, * or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * process_fragments.h */ #define DUP_HASH(a) (a & 0xffff) extern void *frag_thrd(void *); #endif
1,016
C
.c
28
34.428571
71
0.758621
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
176
zstd_wrapper.c
ventoy_Ventoy/SQUASHFS/squashfs-tools-4.4/squashfs-tools/zstd_wrapper.c
/* * Copyright (c) 2017 * Phillip Lougher <[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2, * or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * zstd_wrapper.c * * Support for ZSTD compression http://zstd.net */ #include <stdio.h> #include <string.h> #include <stdlib.h> #include <zstd.h> #include <zstd_errors.h> #include "squashfs_fs.h" #include "zstd_wrapper.h" #include "compressor.h" static int compression_level = ZSTD_DEFAULT_COMPRESSION_LEVEL; /* * This function is called by the options parsing code in mksquashfs.c * to parse any -X compressor option. * * This function returns: * >=0 (number of additional args parsed) on success * -1 if the option was unrecognised, or * -2 if the option was recognised, but otherwise bad in * some way (e.g. invalid parameter) * * Note: this function sets internal compressor state, but does not * pass back the results of the parsing other than success/failure. * The zstd_dump_options() function is called later to get the options in * a format suitable for writing to the filesystem. */ static int zstd_options(char *argv[], int argc) { return 1; } /* * This function is called by mksquashfs to dump the parsed * compressor options in a format suitable for writing to the * compressor options field in the filesystem (stored immediately * after the superblock). * * This function returns a pointer to the compression options structure * to be stored (and the size), or NULL if there are no compression * options. */ static void *zstd_dump_options(int block_size, int *size) { return NULL; } /* * This function is a helper specifically for the append mode of * mksquashfs. Its purpose is to set the internal compressor state * to the stored compressor options in the passed compressor options * structure. * * In effect this function sets up the compressor options * to the same state they were when the filesystem was originally * generated, this is to ensure on appending, the compressor uses * the same compression options that were used to generate the * original filesystem. * * Note, even if there are no compressor options, this function is still * called with an empty compressor structure (size == 0), to explicitly * set the default options, this is to ensure any user supplied * -X options on the appending mksquashfs command line are over-ridden. * * This function returns 0 on sucessful extraction of options, and -1 on error. */ static int zstd_extract_options(int block_size, void *buffer, int size) { struct zstd_comp_opts *comp_opts = buffer; if (size == 0) { /* Set default values */ compression_level = ZSTD_DEFAULT_COMPRESSION_LEVEL; return 0; } /* we expect a comp_opts structure of sufficient size to be present */ if (size < sizeof(*comp_opts)) goto failed; SQUASHFS_INSWAP_COMP_OPTS(comp_opts); if (comp_opts->compression_level < 1) { fprintf(stderr, "zstd: bad compression level in compression " "options structure\n"); goto failed; } compression_level = comp_opts->compression_level; return 0; failed: fprintf(stderr, "zstd: error reading stored compressor options from " "filesystem!\n"); return -1; } static void zstd_display_options(void *buffer, int size) { struct zstd_comp_opts *comp_opts = buffer; /* we expect a comp_opts structure of sufficient size to be present */ if (size < sizeof(*comp_opts)) goto failed; SQUASHFS_INSWAP_COMP_OPTS(comp_opts); if (comp_opts->compression_level < 1) { fprintf(stderr, "zstd: bad compression level in compression " "options structure\n"); goto failed; } printf("\tcompression-level %d\n", comp_opts->compression_level); return; failed: fprintf(stderr, "zstd: error reading stored compressor options from " "filesystem!\n"); } /* * This function is called by mksquashfs to initialise the * compressor, before compress() is called. * * This function returns 0 on success, and -1 on error. */ static int zstd_init(void **strm, int block_size, int datablock) { return 0; } static int zstd_compress(void *strm, void *dest, void *src, int size, int block_size, int *error) { (void)strm; (void)dest; (void)src; (void)size; (void)block_size; (void)error; return 0; } static int zstd_uncompress(void *dest, void *src, int size, int outsize, int *error) { const size_t res = ZSTD_decompress(dest, outsize, src, size); if (ZSTD_isError(res)) { fprintf(stderr, "\t%d %d\n", outsize, size); *error = (int)ZSTD_getErrorCode(res); return -1; } return (int)res; } static void zstd_usage(void) { fprintf(stderr, "\t -Xcompression-level <compression-level>\n"); } struct compressor zstd_comp_ops = { .init = zstd_init, .compress = zstd_compress, .uncompress = zstd_uncompress, .options = zstd_options, .dump_options = zstd_dump_options, .extract_options = zstd_extract_options, .display_options = zstd_display_options, .usage = zstd_usage, .id = ZSTD_COMPRESSION, .name = "zstd", .supported = 1 };
5,411
C
.c
170
29.647059
79
0.741174
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
183
unsquash-123.c
ventoy_Ventoy/SQUASHFS/squashfs-tools-4.4/squashfs-tools/unsquash-123.c
/* * Unsquash a squashfs filesystem. This is a highly compressed read only * filesystem. * * Copyright (c) 2019 * Phillip Lougher <[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2, * or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * unsquash-123.c * * Helper functions used by unsquash-1, unsquash-2 and unsquash-3. */ #include "unsquashfs.h" #include "squashfs_compat.h" int read_ids(int ids, long long start, long long end, unsigned int **id_table) { /* Note on overflow limits: * Size of ids is 2^8 * Max length is 2^8*4 or 1024 */ int res; int length = ids * sizeof(unsigned int); /* * The size of the index table (length bytes) should match the * table start and end points */ if(length != (end - start)) { ERROR("read_ids: Bad inode count in super block\n"); return FALSE; } TRACE("read_ids: no_ids %d\n", ids); *id_table = malloc(length); if(*id_table == NULL) { ERROR("read_ids: failed to allocate uid/gid table\n"); return FALSE; } if(swap) { unsigned int *sid_table = malloc(length); if(sid_table == NULL) { ERROR("read_ids: failed to allocate uid/gid table\n"); return FALSE; } res = read_fs_bytes(fd, start, length, sid_table); if(res == FALSE) { ERROR("read_ids: failed to read uid/gid table" "\n"); free(sid_table); return FALSE; } SQUASHFS_SWAP_INTS_3((*id_table), sid_table, ids); free(sid_table); } else { res = read_fs_bytes(fd, start, length, *id_table); if(res == FALSE) { ERROR("read_ids: failed to read uid/gid table" "\n"); return FALSE; } } return TRUE; }
2,208
C
.c
74
27.243243
78
0.698824
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
true
184
lzma_wrapper.c
ventoy_Ventoy/SQUASHFS/squashfs-tools-4.4/squashfs-tools/lzma_wrapper.c
/* * Copyright (c) 2009, 2010, 2013 * Phillip Lougher <[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2, * or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * lzma_wrapper.c * * Support for LZMA1 compression using LZMA SDK (4.65 used in * development, other versions may work) http://www.7-zip.org/sdk.html */ #include <LzmaLib.h> #include "squashfs_fs.h" #include "compressor.h" #define LZMA_HEADER_SIZE (LZMA_PROPS_SIZE + 8) static int lzma_compress(void *strm, void *dest, void *src, int size, int block_size, int *error) { return 0; } static int lzma_uncompress(void *dest, void *src, int size, int outsize, int *error) { unsigned char *s = src; size_t outlen, inlen = size - LZMA_HEADER_SIZE; int res; outlen = s[LZMA_PROPS_SIZE] | (s[LZMA_PROPS_SIZE + 1] << 8) | (s[LZMA_PROPS_SIZE + 2] << 16) | (s[LZMA_PROPS_SIZE + 3] << 24); if(outlen > outsize) { *error = 0; return -1; } res = LzmaUncompress(dest, &outlen, src + LZMA_HEADER_SIZE, &inlen, src, LZMA_PROPS_SIZE); if(res == SZ_OK) return outlen; else { *error = res; return -1; } } struct compressor lzma_comp_ops = { .init = NULL, .compress = lzma_compress, .uncompress = lzma_uncompress, .options = NULL, .usage = NULL, .id = LZMA_COMPRESSION, .name = "lzma", .supported = 1 };
1,922
C
.c
65
27.4
85
0.710255
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
185
fnmatch_compat.h
ventoy_Ventoy/SQUASHFS/squashfs-tools-4.4/squashfs-tools/fnmatch_compat.h
#ifndef FNMATCH_COMPAT #define FNMATCH_COMPAT /* * Squashfs * * Copyright (c) 2015 * Phillip Lougher <[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2, * or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * fnmatch_compat.h */ #include <fnmatch.h> #ifndef FNM_EXTMATCH #define FNM_EXTMATCH 0 #endif #endif
936
C
.c
29
30.448276
71
0.764381
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
188
gzip_wrapper.c
ventoy_Ventoy/SQUASHFS/squashfs-tools-4.4/squashfs-tools/gzip_wrapper.c
/* * Copyright (c) 2009, 2010, 2013, 2014 * Phillip Lougher <[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2, * or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * gzip_wrapper.c * * Support for ZLIB compression http://www.zlib.net */ #include <stdio.h> #include <string.h> #include <stdlib.h> #include <zlib.h> #include "squashfs_fs.h" #include "gzip_wrapper.h" #include "compressor.h" static struct strategy strategy[] = { { "default", Z_DEFAULT_STRATEGY, 0 }, { "filtered", Z_FILTERED, 0 }, { "huffman_only", Z_HUFFMAN_ONLY, 0 }, { "run_length_encoded", Z_RLE, 0 }, { "fixed", Z_FIXED, 0 }, { NULL, 0, 0 } }; static int strategy_count = 0; /* default compression level */ static int compression_level = GZIP_DEFAULT_COMPRESSION_LEVEL; /* default window size */ static int window_size = GZIP_DEFAULT_WINDOW_SIZE; /* * This function is called by the options parsing code in mksquashfs.c * to parse any -X compressor option. * * This function returns: * >=0 (number of additional args parsed) on success * -1 if the option was unrecognised, or * -2 if the option was recognised, but otherwise bad in * some way (e.g. invalid parameter) * * Note: this function sets internal compressor state, but does not * pass back the results of the parsing other than success/failure. * The gzip_dump_options() function is called later to get the options in * a format suitable for writing to the filesystem. */ static int gzip_options(char *argv[], int argc) { if(strcmp(argv[0], "-Xcompression-level") == 0) { if(argc < 2) { fprintf(stderr, "gzip: -Xcompression-level missing " "compression level\n"); fprintf(stderr, "gzip: -Xcompression-level it " "should be 1 >= n <= 9\n"); goto failed; } compression_level = atoi(argv[1]); if(compression_level < 1 || compression_level > 9) { fprintf(stderr, "gzip: -Xcompression-level invalid, it " "should be 1 >= n <= 9\n"); goto failed; } return 1; } else if(strcmp(argv[0], "-Xwindow-size") == 0) { if(argc < 2) { fprintf(stderr, "gzip: -Xwindow-size missing window " " size\n"); fprintf(stderr, "gzip: -Xwindow-size <window-size>\n"); goto failed; } window_size = atoi(argv[1]); if(window_size < 8 || window_size > 15) { fprintf(stderr, "gzip: -Xwindow-size invalid, it " "should be 8 >= n <= 15\n"); goto failed; } return 1; } else if(strcmp(argv[0], "-Xstrategy") == 0) { char *name; int i; if(argc < 2) { fprintf(stderr, "gzip: -Xstrategy missing " "strategies\n"); goto failed; } name = argv[1]; while(name[0] != '\0') { for(i = 0; strategy[i].name; i++) { int n = strlen(strategy[i].name); if((strncmp(name, strategy[i].name, n) == 0) && (name[n] == '\0' || name[n] == ',')) { if(strategy[i].selected == 0) { strategy[i].selected = 1; strategy_count++; } name += name[n] == ',' ? n + 1 : n; break; } } if(strategy[i].name == NULL) { fprintf(stderr, "gzip: -Xstrategy unrecognised " "strategy\n"); goto failed; } } return 1; } return -1; failed: return -2; } /* * This function is called after all options have been parsed. * It is used to do post-processing on the compressor options using * values that were not expected to be known at option parse time. * * This function returns 0 on successful post processing, or * -1 on error */ static int gzip_options_post(int block_size) { if(strategy_count == 1 && strategy[0].selected) { strategy_count = 0; strategy[0].selected = 0; } return 0; } /* * This function is called by mksquashfs to dump the parsed * compressor options in a format suitable for writing to the * compressor options field in the filesystem (stored immediately * after the superblock). * * This function returns a pointer to the compression options structure * to be stored (and the size), or NULL if there are no compression * options * */ static void *gzip_dump_options(int block_size, int *size) { static struct gzip_comp_opts comp_opts; int i, strategies = 0; /* * If default compression options of: * compression-level: 8 and * window-size: 15 and * strategy_count == 0 then * don't store a compression options structure (this is compatible * with the legacy implementation of GZIP for Squashfs) */ if(compression_level == GZIP_DEFAULT_COMPRESSION_LEVEL && window_size == GZIP_DEFAULT_WINDOW_SIZE && strategy_count == 0) return NULL; for(i = 0; strategy[i].name; i++) strategies |= strategy[i].selected << i; comp_opts.compression_level = compression_level; comp_opts.window_size = window_size; comp_opts.strategy = strategies; SQUASHFS_INSWAP_COMP_OPTS(&comp_opts); *size = sizeof(comp_opts); return &comp_opts; } /* * This function is a helper specifically for the append mode of * mksquashfs. Its purpose is to set the internal compressor state * to the stored compressor options in the passed compressor options * structure. * * In effect this function sets up the compressor options * to the same state they were when the filesystem was originally * generated, this is to ensure on appending, the compressor uses * the same compression options that were used to generate the * original filesystem. * * Note, even if there are no compressor options, this function is still * called with an empty compressor structure (size == 0), to explicitly * set the default options, this is to ensure any user supplied * -X options on the appending mksquashfs command line are over-ridden * * This function returns 0 on sucessful extraction of options, and * -1 on error */ static int gzip_extract_options(int block_size, void *buffer, int size) { struct gzip_comp_opts *comp_opts = buffer; int i; if(size == 0) { /* Set default values */ compression_level = GZIP_DEFAULT_COMPRESSION_LEVEL; window_size = GZIP_DEFAULT_WINDOW_SIZE; strategy_count = 0; return 0; } /* we expect a comp_opts structure of sufficient size to be present */ if(size < sizeof(*comp_opts)) goto failed; SQUASHFS_INSWAP_COMP_OPTS(comp_opts); /* Check comp_opts structure for correctness */ if(comp_opts->compression_level < 1 || comp_opts->compression_level > 9) { fprintf(stderr, "gzip: bad compression level in " "compression options structure\n"); goto failed; } compression_level = comp_opts->compression_level; if(comp_opts->window_size < 8 || comp_opts->window_size > 15) { fprintf(stderr, "gzip: bad window size in " "compression options structure\n"); goto failed; } window_size = comp_opts->window_size; strategy_count = 0; for(i = 0; strategy[i].name; i++) { if((comp_opts->strategy >> i) & 1) { strategy[i].selected = 1; strategy_count ++; } else strategy[i].selected = 0; } return 0; failed: fprintf(stderr, "gzip: error reading stored compressor options from " "filesystem!\n"); return -1; } static void gzip_display_options(void *buffer, int size) { struct gzip_comp_opts *comp_opts = buffer; int i, printed; /* we expect a comp_opts structure of sufficient size to be present */ if(size < sizeof(*comp_opts)) goto failed; SQUASHFS_INSWAP_COMP_OPTS(comp_opts); /* Check comp_opts structure for correctness */ if(comp_opts->compression_level < 1 || comp_opts->compression_level > 9) { fprintf(stderr, "gzip: bad compression level in " "compression options structure\n"); goto failed; } printf("\tcompression-level %d\n", comp_opts->compression_level); if(comp_opts->window_size < 8 || comp_opts->window_size > 15) { fprintf(stderr, "gzip: bad window size in " "compression options structure\n"); goto failed; } printf("\twindow-size %d\n", comp_opts->window_size); for(i = 0, printed = 0; strategy[i].name; i++) { if((comp_opts->strategy >> i) & 1) { if(printed) printf(", "); else printf("\tStrategies selected: "); printf("%s", strategy[i].name); printed = 1; } } if(!printed) printf("\tStrategies selected: default\n"); else printf("\n"); return; failed: fprintf(stderr, "gzip: error reading stored compressor options from " "filesystem!\n"); } /* * This function is called by mksquashfs to initialise the * compressor, before compress() is called. * * This function returns 0 on success, and * -1 on error */ static int gzip_init(void **strm, int block_size, int datablock) { int i, j, res; struct gzip_stream *stream; if(!datablock || !strategy_count) { stream = malloc(sizeof(*stream) + sizeof(struct gzip_strategy)); if(stream == NULL) goto failed; stream->strategies = 1; stream->strategy[0].strategy = Z_DEFAULT_STRATEGY; } else { stream = malloc(sizeof(*stream) + sizeof(struct gzip_strategy) * strategy_count); if(stream == NULL) goto failed; memset(stream->strategy, 0, sizeof(struct gzip_strategy) * strategy_count); stream->strategies = strategy_count; for(i = 0, j = 0; strategy[i].name; i++) { if(!strategy[i].selected) continue; stream->strategy[j].strategy = strategy[i].strategy; if(j) { stream->strategy[j].buffer = malloc(block_size); if(stream->strategy[j].buffer == NULL) goto failed2; } j++; } } stream->stream.zalloc = Z_NULL; stream->stream.zfree = Z_NULL; stream->stream.opaque = 0; res = deflateInit2(&stream->stream, compression_level, Z_DEFLATED, window_size, 8, stream->strategy[0].strategy); if(res != Z_OK) goto failed2; *strm = stream; return 0; failed2: for(i = 1; i < stream->strategies; i++) free(stream->strategy[i].buffer); free(stream); failed: return -1; } static int gzip_compress(void *strm, void *d, void *s, int size, int block_size, int *error) { int i, res; struct gzip_stream *stream = strm; struct gzip_strategy *selected = NULL; stream->strategy[0].buffer = d; for(i = 0; i < stream->strategies; i++) { struct gzip_strategy *strategy = &stream->strategy[i]; res = deflateReset(&stream->stream); if(res != Z_OK) goto failed; stream->stream.next_in = s; stream->stream.avail_in = size; stream->stream.next_out = strategy->buffer; stream->stream.avail_out = block_size; if(stream->strategies > 1) { res = deflateParams(&stream->stream, compression_level, strategy->strategy); if(res != Z_OK) goto failed; } res = deflate(&stream->stream, Z_FINISH); strategy->length = stream->stream.total_out; if(res == Z_STREAM_END) { if(!selected || selected->length > strategy->length) selected = strategy; } else if(res != Z_OK) goto failed; } if(!selected) /* * Output buffer overflow. Return out of buffer space */ return 0; if(selected->buffer != d) memcpy(d, selected->buffer, selected->length); return (int) selected->length; failed: /* * All other errors return failure, with the compressor * specific error code in *error */ *error = res; return -1; } static int gzip_uncompress(void *d, void *s, int size, int outsize, int *error) { int res; unsigned long bytes = outsize; res = uncompress(d, &bytes, s, size); if(res == Z_OK) return (int) bytes; else { *error = res; return -1; } } static void gzip_usage() { fprintf(stderr, "\t -Xcompression-level <compression-level>\n"); fprintf(stderr, "\t\t<compression-level> should be 1 .. 9 (default " "%d)\n", GZIP_DEFAULT_COMPRESSION_LEVEL); fprintf(stderr, "\t -Xwindow-size <window-size>\n"); fprintf(stderr, "\t\t<window-size> should be 8 .. 15 (default " "%d)\n", GZIP_DEFAULT_WINDOW_SIZE); fprintf(stderr, "\t -Xstrategy strategy1,strategy2,...,strategyN\n"); fprintf(stderr, "\t\tCompress using strategy1,strategy2,...,strategyN" " in turn\n"); fprintf(stderr, "\t\tand choose the best compression.\n"); fprintf(stderr, "\t\tAvailable strategies: default, filtered, " "huffman_only,\n\t\trun_length_encoded and fixed\n"); } struct compressor gzip_comp_ops = { .init = gzip_init, .compress = gzip_compress, .uncompress = gzip_uncompress, .options = gzip_options, .options_post = gzip_options_post, .dump_options = gzip_dump_options, .extract_options = gzip_extract_options, .display_options = gzip_display_options, .usage = gzip_usage, .id = ZLIB_COMPRESSION, .name = "gzip", .supported = 1 };
12,898
C
.c
421
27.855107
80
0.69461
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
189
read_xattrs.c
ventoy_Ventoy/SQUASHFS/squashfs-tools-4.4/squashfs-tools/read_xattrs.c
/* * Read a squashfs filesystem. This is a highly compressed read only * filesystem. * * Copyright (c) 2010, 2012, 2013, 2019 * Phillip Lougher <[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2, * or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * read_xattrs.c */ /* * Common xattr read code shared between mksquashfs and unsquashfs */ #define TRUE 1 #define FALSE 0 #include <stdio.h> #include <string.h> #ifndef linux #define __BYTE_ORDER BYTE_ORDER #define __BIG_ENDIAN BIG_ENDIAN #define __LITTLE_ENDIAN LITTLE_ENDIAN #else #include <endian.h> #endif #include "squashfs_fs.h" #include "squashfs_swap.h" #include "xattr.h" #include "error.h" #include <stdlib.h> extern int read_fs_bytes(int, long long, int, void *); extern int read_block(int, long long, long long *, int, void *); static struct hash_entry { long long start; unsigned int offset; struct hash_entry *next; } *hash_table[65536]; static struct squashfs_xattr_id *xattr_ids; static void *xattrs = NULL; static long long xattr_table_start; /* * Prefix lookup table, storing mapping to/from prefix string and prefix id */ struct prefix prefix_table[] = { { "user.", SQUASHFS_XATTR_USER }, { "trusted.", SQUASHFS_XATTR_TRUSTED }, { "security.", SQUASHFS_XATTR_SECURITY }, { "", -1 } }; /* * store mapping from location of compressed block in fs -> * location of uncompressed block in memory */ static void save_xattr_block(long long start, int offset) { struct hash_entry *hash_entry = malloc(sizeof(*hash_entry)); int hash = start & 0xffff; TRACE("save_xattr_block: start %lld, offset %d\n", start, offset); if(hash_entry == NULL) MEM_ERROR(); hash_entry->start = start; hash_entry->offset = offset; hash_entry->next = hash_table[hash]; hash_table[hash] = hash_entry; } /* * map from location of compressed block in fs -> * location of uncompressed block in memory */ static int get_xattr_block(long long start) { int hash = start & 0xffff; struct hash_entry *hash_entry = hash_table[hash]; for(; hash_entry; hash_entry = hash_entry->next) if(hash_entry->start == start) break; TRACE("get_xattr_block: start %lld, offset %d\n", start, hash_entry ? hash_entry->offset : -1); return hash_entry ? hash_entry->offset : -1; } /* * construct the xattr_list entry from the fs xattr, including * mapping name and prefix into a full name */ static int read_xattr_entry(struct xattr_list *xattr, struct squashfs_xattr_entry *entry, void *name) { int i, len, type = entry->type & XATTR_PREFIX_MASK; for(i = 0; prefix_table[i].type != -1; i++) if(prefix_table[i].type == type) break; if(prefix_table[i].type == -1) { ERROR("read_xattr_entry: Unrecognised xattr type %d\n", type); return 0; } len = strlen(prefix_table[i].prefix); xattr->full_name = malloc(len + entry->size + 1); if(xattr->full_name == NULL) MEM_ERROR(); memcpy(xattr->full_name, prefix_table[i].prefix, len); memcpy(xattr->full_name + len, name, entry->size); xattr->full_name[len + entry->size] = '\0'; xattr->name = xattr->full_name + len; xattr->size = entry->size; xattr->type = type; return 1; } /* * Read and decompress the xattr id table and the xattr metadata. * This is cached in memory for later use by get_xattr() */ int read_xattrs_from_disk(int fd, struct squashfs_super_block *sBlk, int flag, long long *table_start) { /* * Note on overflow limits: * Size of ids (id_table.xattr_ids) is 2^32 (unsigned int) * Max size of bytes is 2^32*16 or 2^36 * Max indexes is (2^32*16)/8K or 2^23 * Max index_bytes is ((2^32*16)/8K)*8 or 2^26 or 64M */ int res, i, indexes, index_bytes; unsigned int ids; long long bytes; long long *index, start, end; struct squashfs_xattr_table id_table; TRACE("read_xattrs_from_disk\n"); if(sBlk->xattr_id_table_start == SQUASHFS_INVALID_BLK) return SQUASHFS_INVALID_BLK; /* * Read xattr id table, containing start of xattr metadata and the * number of xattrs in the file system */ res = read_fs_bytes(fd, sBlk->xattr_id_table_start, sizeof(id_table), &id_table); if(res == 0) return 0; SQUASHFS_INSWAP_XATTR_TABLE(&id_table); /* * Compute index table values */ ids = id_table.xattr_ids; xattr_table_start = id_table.xattr_table_start; index_bytes = SQUASHFS_XATTR_BLOCK_BYTES((long long) ids); indexes = SQUASHFS_XATTR_BLOCKS((long long) ids); /* * The size of the index table (index_bytes) should match the * table start and end points */ if(index_bytes != (sBlk->bytes_used - (sBlk->xattr_id_table_start + sizeof(id_table)))) { ERROR("read_xattrs_from_disk: Bad xattr_ids count in super block\n"); return 0; } /* * id_table.xattr_table_start stores the start of the compressed xattr * metadata blocks. This by definition is also the end of the previous * filesystem table - the id lookup table. */ if(table_start != NULL) *table_start = id_table.xattr_table_start; /* * If flag is set then return once we've read the above * table_start. That value is necessary for sanity checking, * but we don't actually want to extract the xattrs, and so * stop here. */ if(flag) return id_table.xattr_ids; /* * Allocate and read the index to the xattr id table metadata * blocks */ index = malloc(index_bytes); if(index == NULL) MEM_ERROR(); res = read_fs_bytes(fd, sBlk->xattr_id_table_start + sizeof(id_table), index_bytes, index); if(res ==0) goto failed1; SQUASHFS_INSWAP_LONG_LONGS(index, indexes); /* * Allocate enough space for the uncompressed xattr id table, and * read and decompress it */ bytes = SQUASHFS_XATTR_BYTES((long long) ids); xattr_ids = malloc(bytes); if(xattr_ids == NULL) MEM_ERROR(); for(i = 0; i < indexes; i++) { int expected = (i + 1) != indexes ? SQUASHFS_METADATA_SIZE : bytes & (SQUASHFS_METADATA_SIZE - 1); int length = read_block(fd, index[i], NULL, expected, ((unsigned char *) xattr_ids) + ((long long) i * SQUASHFS_METADATA_SIZE)); TRACE("Read xattr id table block %d, from 0x%llx, length " "%d\n", i, index[i], length); if(length == 0) { ERROR("Failed to read xattr id table block %d, " "from 0x%llx, length %d\n", i, index[i], length); goto failed2; } } /* * Read and decompress the xattr metadata * * Note the first xattr id table metadata block is immediately after * the last xattr metadata block, so we can use index[0] to work out * the end of the xattr metadata */ start = xattr_table_start; end = index[0]; for(i = 0; start < end; i++) { int length; xattrs = realloc(xattrs, (i + 1) * SQUASHFS_METADATA_SIZE); if(xattrs == NULL) MEM_ERROR(); /* store mapping from location of compressed block in fs -> * location of uncompressed block in memory */ save_xattr_block(start, i * SQUASHFS_METADATA_SIZE); length = read_block(fd, start, &start, 0, ((unsigned char *) xattrs) + (i * SQUASHFS_METADATA_SIZE)); TRACE("Read xattr block %d, length %d\n", i, length); if(length == 0) { ERROR("Failed to read xattr block %d\n", i); goto failed3; } /* * If this is not the last metadata block in the xattr metadata * then it should be SQUASHFS_METADATA_SIZE in size. * Note, we can't use expected in read_block() above for this * because we don't know if this is the last block until * after reading. */ if(start != end && length != SQUASHFS_METADATA_SIZE) { ERROR("Xattr block %d should be %d bytes in length, " "it is %d bytes\n", i, SQUASHFS_METADATA_SIZE, length); goto failed3; } } /* swap if necessary the xattr id entries */ for(i = 0; i < ids; i++) SQUASHFS_INSWAP_XATTR_ID(&xattr_ids[i]); free(index); return ids; failed3: free(xattrs); failed2: free(xattr_ids); failed1: free(index); return 0; } void free_xattr(struct xattr_list *xattr_list, int count) { int i; for(i = 0; i < count; i++) free(xattr_list[i].full_name); free(xattr_list); } /* * Construct and return the list of xattr name:value pairs for the passed xattr * id * * There are two users for get_xattr(), Mksquashfs uses it to read the * xattrs from the filesystem on appending, and Unsquashfs uses it * to retrieve the xattrs for writing to disk. * * Unfortunately, the two users disagree on what to do with unknown * xattr prefixes, Mksquashfs wants to treat this as fatal otherwise * this will cause xattrs to be be lost on appending. Unsquashfs * on the otherhand wants to retrieve the xattrs which are known and * to ignore the rest, this allows Unsquashfs to cope more gracefully * with future versions which may have unknown xattrs, as long as the * general xattr structure is adhered to, Unsquashfs should be able * to safely ignore unknown xattrs, and to write the ones it knows about, * this is better than completely refusing to retrieve all the xattrs. * * So return an error flag if any unrecognised types were found. */ struct xattr_list *get_xattr(int i, unsigned int *count, int *failed) { long long start; struct xattr_list *xattr_list = NULL; unsigned int offset; void *xptr; int j, n, res = 1; TRACE("get_xattr\n"); if(xattr_ids[i].count == 0) { ERROR("get_xattr: xattr count unexpectedly 0 - corrupt fs?\n"); *failed = TRUE; *count = 0; return NULL; } else *failed = FALSE; start = SQUASHFS_XATTR_BLK(xattr_ids[i].xattr) + xattr_table_start; offset = SQUASHFS_XATTR_OFFSET(xattr_ids[i].xattr); xptr = xattrs + get_xattr_block(start) + offset; TRACE("get_xattr: xattr_id %d, count %d, start %lld, offset %d\n", i, xattr_ids[i].count, start, offset); for(j = 0, n = 0; n < xattr_ids[i].count; n++) { struct squashfs_xattr_entry entry; struct squashfs_xattr_val val; if(res != 0) { xattr_list = realloc(xattr_list, (j + 1) * sizeof(struct xattr_list)); if(xattr_list == NULL) MEM_ERROR(); } SQUASHFS_SWAP_XATTR_ENTRY(xptr, &entry); xptr += sizeof(entry); res = read_xattr_entry(&xattr_list[j], &entry, xptr); if(res == 0) { /* unknown type, skip, and set error flag */ xptr += entry.size; SQUASHFS_SWAP_XATTR_VAL(xptr, &val); xptr += sizeof(val) + val.vsize; *failed = TRUE; continue; } xptr += entry.size; TRACE("get_xattr: xattr %d, type %d, size %d, name %s\n", j, entry.type, entry.size, xattr_list[j].full_name); if(entry.type & SQUASHFS_XATTR_VALUE_OOL) { long long xattr; void *ool_xptr; xptr += sizeof(val); SQUASHFS_SWAP_LONG_LONGS(xptr, &xattr, 1); xptr += sizeof(xattr); start = SQUASHFS_XATTR_BLK(xattr) + xattr_table_start; offset = SQUASHFS_XATTR_OFFSET(xattr); ool_xptr = xattrs + get_xattr_block(start) + offset; SQUASHFS_SWAP_XATTR_VAL(ool_xptr, &val); xattr_list[j].value = ool_xptr + sizeof(val); } else { SQUASHFS_SWAP_XATTR_VAL(xptr, &val); xattr_list[j].value = xptr + sizeof(val); xptr += sizeof(val) + val.vsize; } TRACE("get_xattr: xattr %d, vsize %d\n", j, val.vsize); xattr_list[j++].vsize = val.vsize; } *count = j; return xattr_list; }
11,638
C
.c
358
29.868715
102
0.697162
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
true
194
lzo_wrapper.c
ventoy_Ventoy/SQUASHFS/squashfs-tools-4.4/squashfs-tools/lzo_wrapper.c
/* * Copyright (c) 2013, 2014 * Phillip Lougher <[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2, * or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * lzo_wrapper.c * * Support for LZO compression http://www.oberhumer.com/opensource/lzo */ #include <stdio.h> #include <string.h> #include <stdlib.h> #include <lzo/lzoconf.h> #include <lzo/lzo1x.h> #include "squashfs_fs.h" #include "lzo_wrapper.h" #include "compressor.h" static struct lzo_algorithm lzo[] = { { "lzo1x_1", LZO1X_1_MEM_COMPRESS, lzo1x_1_compress }, { "lzo1x_1_11", LZO1X_1_11_MEM_COMPRESS, lzo1x_1_11_compress }, { "lzo1x_1_12", LZO1X_1_12_MEM_COMPRESS, lzo1x_1_12_compress }, { "lzo1x_1_15", LZO1X_1_15_MEM_COMPRESS, lzo1x_1_15_compress }, { "lzo1x_999", LZO1X_999_MEM_COMPRESS, lzo1x_999_wrapper }, { NULL, 0, NULL } }; /* default LZO compression algorithm and compression level */ static int algorithm = SQUASHFS_LZO1X_999; static int compression_level = SQUASHFS_LZO1X_999_COMP_DEFAULT; /* user specified compression level */ static int user_comp_level = -1; /* * This function is called by the options parsing code in mksquashfs.c * to parse any -X compressor option. * * This function returns: * >=0 (number of additional args parsed) on success * -1 if the option was unrecognised, or * -2 if the option was recognised, but otherwise bad in * some way (e.g. invalid parameter) * * Note: this function sets internal compressor state, but does not * pass back the results of the parsing other than success/failure. * The lzo_dump_options() function is called later to get the options in * a format suitable for writing to the filesystem. */ static int lzo_options(char *argv[], int argc) { (void)argv; (void)argc; return 1; } /* * This function is called after all options have been parsed. * It is used to do post-processing on the compressor options using * values that were not expected to be known at option parse time. * * In this case the LZO algorithm may not be known until after the * compression level has been set (-Xalgorithm used after -Xcompression-level) * * This function returns 0 on successful post processing, or * -1 on error */ static int lzo_options_post(int block_size) { /* * Use of compression level only makes sense for * LZO1X_999 algorithm */ if(user_comp_level != -1) { if(algorithm != SQUASHFS_LZO1X_999) { fprintf(stderr, "lzo: -Xcompression-level not " "supported by selected %s algorithm\n", lzo[algorithm].name); fprintf(stderr, "lzo: -Xcompression-level is only " "applicable for the lzo1x_999 algorithm\n"); goto failed; } compression_level = user_comp_level; } return 0; failed: return -1; } /* * This function is called by mksquashfs to dump the parsed * compressor options in a format suitable for writing to the * compressor options field in the filesystem (stored immediately * after the superblock). * * This function returns a pointer to the compression options structure * to be stored (and the size), or NULL if there are no compression * options * */ static void *lzo_dump_options(int block_size, int *size) { static struct lzo_comp_opts comp_opts; /* * If default compression options of SQUASHFS_LZO1X_999 and * compression level of SQUASHFS_LZO1X_999_COMP_DEFAULT then * don't store a compression options structure (this is compatible * with the legacy implementation of LZO for Squashfs) */ if(algorithm == SQUASHFS_LZO1X_999 && compression_level == SQUASHFS_LZO1X_999_COMP_DEFAULT) return NULL; comp_opts.algorithm = algorithm; comp_opts.compression_level = algorithm == SQUASHFS_LZO1X_999 ? compression_level : 0; SQUASHFS_INSWAP_COMP_OPTS(&comp_opts); *size = sizeof(comp_opts); return &comp_opts; } /* * This function is a helper specifically for the append mode of * mksquashfs. Its purpose is to set the internal compressor state * to the stored compressor options in the passed compressor options * structure. * * In effect this function sets up the compressor options * to the same state they were when the filesystem was originally * generated, this is to ensure on appending, the compressor uses * the same compression options that were used to generate the * original filesystem. * * Note, even if there are no compressor options, this function is still * called with an empty compressor structure (size == 0), to explicitly * set the default options, this is to ensure any user supplied * -X options on the appending mksquashfs command line are over-ridden * * This function returns 0 on sucessful extraction of options, and * -1 on error */ static int lzo_extract_options(int block_size, void *buffer, int size) { struct lzo_comp_opts *comp_opts = buffer; if(size == 0) { /* Set default values */ algorithm = SQUASHFS_LZO1X_999; compression_level = SQUASHFS_LZO1X_999_COMP_DEFAULT; return 0; } /* we expect a comp_opts structure of sufficient size to be present */ if(size < sizeof(*comp_opts)) goto failed; SQUASHFS_INSWAP_COMP_OPTS(comp_opts); /* Check comp_opts structure for correctness */ switch(comp_opts->algorithm) { case SQUASHFS_LZO1X_1: case SQUASHFS_LZO1X_1_11: case SQUASHFS_LZO1X_1_12: case SQUASHFS_LZO1X_1_15: if(comp_opts->compression_level != 0) { fprintf(stderr, "lzo: bad compression level in " "compression options structure\n"); goto failed; } break; case SQUASHFS_LZO1X_999: if(comp_opts->compression_level < 1 || comp_opts->compression_level > 9) { fprintf(stderr, "lzo: bad compression level in " "compression options structure\n"); goto failed; } compression_level = comp_opts->compression_level; break; default: fprintf(stderr, "lzo: bad algorithm in compression options " "structure\n"); goto failed; } algorithm = comp_opts->algorithm; return 0; failed: fprintf(stderr, "lzo: error reading stored compressor options from " "filesystem!\n"); return -1; } static void lzo_display_options(void *buffer, int size) { struct lzo_comp_opts *comp_opts = buffer; /* we expect a comp_opts structure of sufficient size to be present */ if(size < sizeof(*comp_opts)) goto failed; SQUASHFS_INSWAP_COMP_OPTS(comp_opts); /* Check comp_opts structure for correctness */ switch(comp_opts->algorithm) { case SQUASHFS_LZO1X_1: case SQUASHFS_LZO1X_1_11: case SQUASHFS_LZO1X_1_12: case SQUASHFS_LZO1X_1_15: printf("\talgorithm %s\n", lzo[comp_opts->algorithm].name); break; case SQUASHFS_LZO1X_999: if(comp_opts->compression_level < 1 || comp_opts->compression_level > 9) { fprintf(stderr, "lzo: bad compression level in " "compression options structure\n"); goto failed; } printf("\talgorithm %s\n", lzo[comp_opts->algorithm].name); printf("\tcompression level %d\n", comp_opts->compression_level); break; default: fprintf(stderr, "lzo: bad algorithm in compression options " "structure\n"); goto failed; } return; failed: fprintf(stderr, "lzo: error reading stored compressor options from " "filesystem!\n"); } /* * This function is called by mksquashfs to initialise the * compressor, before compress() is called. * * This function returns 0 on success, and * -1 on error */ static int squashfs_lzo_init(void **strm, int block_size, int datablock) { struct lzo_stream *stream; stream = *strm = malloc(sizeof(struct lzo_stream)); if(stream == NULL) goto failed; stream->workspace = malloc(lzo[algorithm].size); if(stream->workspace == NULL) goto failed2; stream->buffer = malloc(LZO_MAX_EXPANSION(block_size)); if(stream->buffer != NULL) return 0; free(stream->workspace); failed2: free(stream); failed: return -1; } static int lzo_compress(void *strm, void *dest, void *src, int size, int block_size, int *error) { return 0; } static int lzo_uncompress(void *dest, void *src, int size, int outsize, int *error) { int res; lzo_uint outlen = outsize; res = lzo1x_decompress_safe(src, size, dest, &outlen, NULL); if(res != LZO_E_OK) { *error = res; return -1; } return outlen; } static void lzo_usage() { int i; fprintf(stderr, "\t -Xalgorithm <algorithm>\n"); fprintf(stderr, "\t\tWhere <algorithm> is one of:\n"); for(i = 0; lzo[i].name; i++) fprintf(stderr, "\t\t\t%s%s\n", lzo[i].name, i == SQUASHFS_LZO1X_999 ? " (default)" : ""); fprintf(stderr, "\t -Xcompression-level <compression-level>\n"); fprintf(stderr, "\t\t<compression-level> should be 1 .. 9 (default " "%d)\n", SQUASHFS_LZO1X_999_COMP_DEFAULT); fprintf(stderr, "\t\tOnly applies to lzo1x_999 algorithm\n"); } /* * Helper function for lzo1x_999 compression algorithm. * All other lzo1x_xxx compressors do not take a compression level, * so we need to wrap lzo1x_999 to pass the compression level which * is applicable to it */ int lzo1x_999_wrapper(const lzo_bytep src, lzo_uint src_len, lzo_bytep dst, lzo_uintp compsize, lzo_voidp workspace) { return lzo1x_999_compress_level(src, src_len, dst, compsize, workspace, NULL, 0, 0, compression_level); } struct compressor lzo_comp_ops = { .init = squashfs_lzo_init, .compress = lzo_compress, .uncompress = lzo_uncompress, .options = lzo_options, .options_post = lzo_options_post, .dump_options = lzo_dump_options, .extract_options = lzo_extract_options, .display_options = lzo_display_options, .usage = lzo_usage, .id = LZO_COMPRESSION, .name = "lzo", .supported = 1 };
10,072
C
.c
309
30.220065
78
0.732763
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
true
197
lz4_wrapper.c
ventoy_Ventoy/SQUASHFS/squashfs-tools-4.4/squashfs-tools/lz4_wrapper.c
/* * Copyright (c) 2013, 2019 * Phillip Lougher <[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2, * or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * lz4_wrapper.c * * Support for LZ4 compression http://fastcompression.blogspot.com/p/lz4.html */ #include <stdio.h> #include <string.h> #include <stdlib.h> #include <lz4.h> #include <lz4hc.h> #include "squashfs_fs.h" #include "lz4_wrapper.h" #include "compressor.h" /* LZ4 1.7.0 introduced new functions, and since r131, * the older functions produce deprecated warnings. * * There are still too many distros using older versions * to switch to the newer functions, but, the deprecated * functions may completely disappear. This is a mess. * * Support both by checking the library version and * using shadow definitions */ /* Earlier (but > 1.7.0) versions don't define this */ #ifndef LZ4HC_CLEVEL_MAX #define LZ4HC_CLEVEL_MAX 12 #endif #if LZ4_VERSION_NUMBER >= 10700 #define COMPRESS(src, dest, size, max) LZ4_compress_default(src, dest, size, max) #define COMPRESS_HC(src, dest, size, max) LZ4_compress_HC(src, dest, size, max, LZ4HC_CLEVEL_MAX) #else #define COMPRESS(src, dest, size, max) LZ4_compress_limitedOutput(src, dest, size, max) #define COMPRESS_HC(src, dest, size, max) LZ4_compressHC_limitedOutput(src, dest, size, max) #endif static int hc = 0; /* * This function is called by the options parsing code in mksquashfs.c * to parse any -X compressor option. * * This function returns: * >=0 (number of additional args parsed) on success * -1 if the option was unrecognised, or * -2 if the option was recognised, but otherwise bad in * some way (e.g. invalid parameter) * * Note: this function sets internal compressor state, but does not * pass back the results of the parsing other than success/failure. * The lz4_dump_options() function is called later to get the options in * a format suitable for writing to the filesystem. */ static int lz4_options(char *argv[], int argc) { if(strcmp(argv[0], "-Xhc") == 0) { hc = 1; return 0; } return -1; } /* * This function is called by mksquashfs to dump the parsed * compressor options in a format suitable for writing to the * compressor options field in the filesystem (stored immediately * after the superblock). * * This function returns a pointer to the compression options structure * to be stored (and the size), or NULL if there are no compression * options * * Currently LZ4 always returns a comp_opts structure, with * the version indicating LZ4_LEGACY stream fomat. This is to * easily accomodate changes in the kernel code to different * stream formats */ static void *lz4_dump_options(int block_size, int *size) { static struct lz4_comp_opts comp_opts; comp_opts.version = LZ4_LEGACY; comp_opts.flags = hc ? LZ4_HC : 0; SQUASHFS_INSWAP_COMP_OPTS(&comp_opts); *size = sizeof(comp_opts); return &comp_opts; } /* * This function is a helper specifically for the append mode of * mksquashfs. Its purpose is to set the internal compressor state * to the stored compressor options in the passed compressor options * structure. * * In effect this function sets up the compressor options * to the same state they were when the filesystem was originally * generated, this is to ensure on appending, the compressor uses * the same compression options that were used to generate the * original filesystem. * * Note, even if there are no compressor options, this function is still * called with an empty compressor structure (size == 0), to explicitly * set the default options, this is to ensure any user supplied * -X options on the appending mksquashfs command line are over-ridden * * This function returns 0 on sucessful extraction of options, and * -1 on error */ static int lz4_extract_options(int block_size, void *buffer, int size) { struct lz4_comp_opts *comp_opts = buffer; /* we expect a comp_opts structure to be present */ if(size < sizeof(*comp_opts)) goto failed; SQUASHFS_INSWAP_COMP_OPTS(comp_opts); /* we expect the stream format to be LZ4_LEGACY */ if(comp_opts->version != LZ4_LEGACY) { fprintf(stderr, "lz4: unknown LZ4 version\n"); goto failed; } /* * Check compression flags, currently only LZ4_HC ("high compression") * can be set. */ if(comp_opts->flags == LZ4_HC) hc = 1; else if(comp_opts->flags != 0) { fprintf(stderr, "lz4: unknown LZ4 flags\n"); goto failed; } return 0; failed: fprintf(stderr, "lz4: error reading stored compressor options from " "filesystem!\n"); return -1; } /* * This function is a helper specifically for unsquashfs. * Its purpose is to check that the compression options are * understood by this version of LZ4. * * This is important for LZ4 because the format understood by the * Linux kernel may change from the already obsolete legacy format * currently supported. * * If this does happen, then this version of LZ4 will not be able to decode * the newer format. So we need to check for this. * * This function returns 0 on sucessful checking of options, and * -1 on error */ static int lz4_check_options(int block_size, void *buffer, int size) { struct lz4_comp_opts *comp_opts = buffer; /* we expect a comp_opts structure to be present */ if(size < sizeof(*comp_opts)) goto failed; SQUASHFS_INSWAP_COMP_OPTS(comp_opts); /* we expect the stream format to be LZ4_LEGACY */ if(comp_opts->version != LZ4_LEGACY) { fprintf(stderr, "lz4: unknown LZ4 version\n"); goto failed; } return 0; failed: fprintf(stderr, "lz4: error reading stored compressor options from " "filesystem!\n"); return -1; } static void lz4_display_options(void *buffer, int size) { struct lz4_comp_opts *comp_opts = buffer; /* check passed comp opts struct is of the correct length */ if(size < sizeof(*comp_opts)) goto failed; SQUASHFS_INSWAP_COMP_OPTS(comp_opts); /* we expect the stream format to be LZ4_LEGACY */ if(comp_opts->version != LZ4_LEGACY) { fprintf(stderr, "lz4: unknown LZ4 version\n"); goto failed; } /* * Check compression flags, currently only LZ4_HC ("high compression") * can be set. */ if(comp_opts->flags & ~LZ4_FLAGS_MASK) { fprintf(stderr, "lz4: unknown LZ4 flags\n"); goto failed; } if(comp_opts->flags & LZ4_HC) printf("\tHigh Compression option specified (-Xhc)\n"); return; failed: fprintf(stderr, "lz4: error reading stored compressor options from " "filesystem!\n"); } static int lz4_compress(void *strm, void *dest, void *src, int size, int block_size, int *error) { return 0; } static int lz4_uncompress(void *dest, void *src, int size, int outsize, int *error) { int res = LZ4_decompress_safe(src, dest, size, outsize); if(res < 0) { *error = res; return -1; } return res; } static void lz4_usage() { fprintf(stderr, "\t -Xhc\n"); fprintf(stderr, "\t\tCompress using LZ4 High Compression\n"); } struct compressor lz4_comp_ops = { .compress = lz4_compress, .uncompress = lz4_uncompress, .options = lz4_options, .dump_options = lz4_dump_options, .extract_options = lz4_extract_options, .check_options = lz4_check_options, .display_options = lz4_display_options, .usage = lz4_usage, .id = LZ4_COMPRESSION, .name = "lz4", .supported = 1 };
7,894
C
.c
240
30.804167
98
0.737119
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
true
201
unsquash-34.c
ventoy_Ventoy/SQUASHFS/squashfs-tools-4.4/squashfs-tools/unsquash-34.c
/* * Unsquash a squashfs filesystem. This is a highly compressed read only * filesystem. * * Copyright (c) 2019 * Phillip Lougher <[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2, * or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * unsquash-34.c * * Helper functions used by unsquash-3 and unsquash-4. */ #include "unsquashfs.h" long long *alloc_index_table(int indexes) { static long long *alloc_table = NULL; static int alloc_size = 0; int length = indexes * sizeof(long long); if(alloc_size < length || length == 0) { long long *table = realloc(alloc_table, length); if(table == NULL && length !=0) EXIT_UNSQUASH("alloc_index_table: failed to allocate " "index table\n"); alloc_table = table; alloc_size = length; } return alloc_table; }
1,403
C
.c
41
31.97561
73
0.735988
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
208
read_file.c
ventoy_Ventoy/SQUASHFS/squashfs-tools-4.4/squashfs-tools/read_file.c
/* * Create a squashfs filesystem. This is a highly compressed read only * filesystem. * * Copyright (c) 2012 * Phillip Lougher <[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2, * or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * read_file.c */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <errno.h> #include "error.h" #define TRUE 1 #define FALSE 0 #define MAX_LINE 16384 /* * Read file, passing each line to parse_line() for * parsing. * * Lines can be split across multiple lines using "\". * * Blank lines and comment lines indicated by # are supported. */ int read_file(char *filename, char *type, int (parse_line)(char *)) { FILE *fd; char *def, *err, *line = NULL; int res, size = 0; fd = fopen(filename, "r"); if(fd == NULL) { ERROR("Could not open %s device file \"%s\" because %s\n", type, filename, strerror(errno)); return FALSE; } while(1) { int total = 0; while(1) { int len; if(total + (MAX_LINE + 1) > size) { line = realloc(line, size += (MAX_LINE + 1)); if(line == NULL) MEM_ERROR(); } err = fgets(line + total, MAX_LINE + 1, fd); if(err == NULL) break; len = strlen(line + total); total += len; if(len == MAX_LINE && line[total - 1] != '\n') { /* line too large */ ERROR("Line too long when reading " "%s file \"%s\", larger than " "%d bytes\n", type, filename, MAX_LINE); goto failed; } /* * Remove '\n' terminator if it exists (the last line * in the file may not be '\n' terminated) */ if(len && line[total - 1] == '\n') { line[-- total] = '\0'; len --; } /* * If no line continuation then jump out to * process line. Note, we have to be careful to * check for "\\" (backslashed backslash) and to * ensure we don't look at the previous line */ if(len == 0 || line[total - 1] != '\\' || (len >= 2 && strcmp(line + total - 2, "\\\\") == 0)) break; else total --; } if(err == NULL) { if(ferror(fd)) { ERROR("Reading %s file \"%s\" failed " "because %s\n", type, filename, strerror(errno)); goto failed; } /* * At EOF, normally we'll be finished, but, have to * check for special case where we had "\" line * continuation and then hit EOF immediately afterwards */ if(total == 0) break; else line[total] = '\0'; } /* Skip any leading whitespace */ for(def = line; isspace(*def); def ++); /* if line is now empty after skipping characters, skip it */ if(*def == '\0') continue; /* if comment line, skip */ if(*def == '#') continue; res = parse_line(def); if(res == FALSE) goto failed; } fclose(fd); free(line); return TRUE; failed: fclose(fd); free(line); return FALSE; }
3,459
C
.c
129
23.364341
71
0.631006
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
true
256
huffman.c
ventoy_Ventoy/wimboot/wimboot-2.7.3/src/huffman.c
/* * Copyright (C) 2014 Michael Brown <[email protected]>. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ /** * @file * * Huffman alphabets * */ #include <stdint.h> #include <string.h> #include <stdio.h> #include <assert.h> #include "wimboot.h" #include "huffman.h" /** * Transcribe binary value (for debugging) * * @v value Value * @v bits Length of value (in bits) * @ret string Transcribed value */ static const char * huffman_bin ( unsigned long value, unsigned int bits ) { static char buf[ ( 8 * sizeof ( value ) ) + 1 /* NUL */ ]; char *out = buf; /* Sanity check */ assert ( bits < sizeof ( buf ) ); /* Transcribe value */ while ( bits-- ) *(out++) = ( ( value & ( 1 << bits ) ) ? '1' : '0' ); *out = '\0'; return buf; } /** * Dump Huffman alphabet (for debugging) * * @v alphabet Huffman alphabet */ static void __attribute__ (( unused )) huffman_dump_alphabet ( struct huffman_alphabet *alphabet ) { struct huffman_symbols *sym; unsigned int bits; unsigned int huf; unsigned int i; /* Dump symbol table for each utilised length */ for ( bits = 1 ; bits <= ( sizeof ( alphabet->huf ) / sizeof ( alphabet->huf[0] ) ) ; bits++ ) { sym = &alphabet->huf[ bits - 1 ]; if ( sym->freq == 0 ) continue; huf = ( sym->start >> sym->shift ); DBG ( "Huffman length %d start \"%s\" freq %d:", bits, huffman_bin ( huf, sym->bits ), sym->freq ); for ( i = 0 ; i < sym->freq ; i++ ) { DBG ( " %03x", sym->raw[ huf + i ] ); } DBG ( "\n" ); } /* Dump quick lookup table */ DBG ( "Huffman quick lookup:" ); for ( i = 0 ; i < ( sizeof ( alphabet->lookup ) / sizeof ( alphabet->lookup[0] ) ) ; i++ ) { DBG ( " %d", ( alphabet->lookup[i] + 1 ) ); } DBG ( "\n" ); } /** * Construct Huffman alphabet * * @v alphabet Huffman alphabet * @v lengths Symbol length table * @v count Number of symbols * @ret rc Return status code */ int huffman_alphabet ( struct huffman_alphabet *alphabet, uint8_t *lengths, unsigned int count ) { struct huffman_symbols *sym; unsigned int huf; unsigned int cum_freq; unsigned int bits; unsigned int raw; unsigned int adjustment; unsigned int prefix; int empty; int complete; /* Clear symbol table */ memset ( alphabet->huf, 0, sizeof ( alphabet->huf ) ); /* Count number of symbols with each Huffman-coded length */ empty = 1; for ( raw = 0 ; raw < count ; raw++ ) { bits = lengths[raw]; if ( bits ) { alphabet->huf[ bits - 1 ].freq++; empty = 0; } } /* In the degenerate case of having no symbols (i.e. an unused * alphabet), generate a trivial alphabet with exactly two * single-bit codes. This allows callers to avoid having to * check for this special case. */ if ( empty ) alphabet->huf[0].freq = 2; /* Populate Huffman-coded symbol table */ huf = 0; cum_freq = 0; for ( bits = 1 ; bits <= ( sizeof ( alphabet->huf ) / sizeof ( alphabet->huf[0] ) ) ; bits++ ) { sym = &alphabet->huf[ bits - 1 ]; sym->bits = bits; sym->shift = ( HUFFMAN_BITS - bits ); sym->start = ( huf << sym->shift ); sym->raw = &alphabet->raw[cum_freq]; huf += sym->freq; if ( huf > ( 1U << bits ) ) { DBG ( "Huffman alphabet has too many symbols with " "lengths <=%d\n", bits ); return -1; } huf <<= 1; cum_freq += sym->freq; } complete = ( huf == ( 1U << bits ) ); /* Populate raw symbol table */ for ( raw = 0 ; raw < count ; raw++ ) { bits = lengths[raw]; if ( bits ) { sym = &alphabet->huf[ bits - 1 ]; *(sym->raw++) = raw; } } /* Adjust Huffman-coded symbol table raw pointers and populate * quick lookup table. */ for ( bits = 1 ; bits <= ( sizeof ( alphabet->huf ) / sizeof ( alphabet->huf[0] ) ) ; bits++ ) { sym = &alphabet->huf[ bits - 1 ]; /* Adjust raw pointer */ sym->raw -= sym->freq; /* Reset to first symbol */ adjustment = ( sym->start >> sym->shift ); sym->raw -= adjustment; /* Adjust for quick indexing */ /* Populate quick lookup table */ for ( prefix = ( sym->start >> HUFFMAN_QL_SHIFT ) ; prefix < ( 1 << HUFFMAN_QL_BITS ) ; prefix++ ) { alphabet->lookup[prefix] = ( bits - 1 ); } } /* Check that there are no invalid codes */ if ( ! complete ) { DBG ( "Huffman alphabet is incomplete\n" ); return -1; } return 0; } /** * Get Huffman symbol set * * @v alphabet Huffman alphabet * @v huf Raw input value (normalised to HUFFMAN_BITS bits) * @ret sym Huffman symbol set */ struct huffman_symbols * huffman_sym ( struct huffman_alphabet *alphabet, unsigned int huf ) { struct huffman_symbols *sym; unsigned int lookup_index; /* Find symbol set for this length */ lookup_index = ( huf >> HUFFMAN_QL_SHIFT ); sym = &alphabet->huf[ alphabet->lookup[ lookup_index ] ]; while ( huf < sym->start ) sym--; return sym; }
5,519
C
.c
187
26.839572
76
0.63484
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
258
pause.c
ventoy_Ventoy/wimboot/wimboot-2.7.3/src/pause.c
/* * Copyright (C) 2014 Michael Brown <[email protected]>. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ /** * @file * * Diagnostic pause * */ #include <stdio.h> #include "wimboot.h" #include "cmdline.h" #include "pause.h" /** * Pause before booting * */ void pause ( void ) { /* Wait for keypress, prompting unless inhibited */ if ( cmdline_pause_quiet ) { getchar(); } else { printf ( "Press any key to continue booting..." ); getchar(); printf ( "\n" ); } }
1,174
C
.c
42
25.97619
70
0.719858
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
259
peloader.c
ventoy_Ventoy/wimboot/wimboot-2.7.3/src/peloader.c
/* * Copyright (C) 2012 Michael Brown <[email protected]>. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ /** * @file * * PE image loader * */ #include <stdint.h> #include <stddef.h> #include <stdio.h> #include <string.h> #include "wimboot.h" #include "peloader.h" /** * Load PE image into memory * * @v data PE image * @v len Length of PE image * @v pe Loaded PE structure to fill in * @ret rc Return status code */ int load_pe ( const void *data, size_t len, struct loaded_pe *pe ) { const struct mz_header *mzhdr; size_t pehdr_offset; const struct pe_header *pehdr; size_t opthdr_offset; const struct pe_optional_header *opthdr; size_t section_offset; const struct coff_section *section; char name[ sizeof ( section->name ) + 1 /* NUL */ ]; unsigned int i; void *section_base; size_t filesz; size_t memsz; void *end; void *raw_base; DBG2 ( "Loading PE executable...\n" ); /* Parse PE header */ mzhdr = data; if ( mzhdr->magic != MZ_HEADER_MAGIC ) { DBG ( "Bad MZ magic %04x\n", mzhdr->magic ); return -1; } pehdr_offset = mzhdr->lfanew; if ( pehdr_offset > len ) { DBG ( "PE header outside file\n" ); return -1; } pehdr = ( data + pehdr_offset ); if ( pehdr->magic != PE_HEADER_MAGIC ) { DBG ( "Bad PE magic %08x\n", pehdr->magic ); return -1; } opthdr_offset = ( pehdr_offset + sizeof ( *pehdr ) ); opthdr = ( data + opthdr_offset ); pe->base = ( ( void * ) ( intptr_t ) ( opthdr->base ) ); section_offset = ( opthdr_offset + pehdr->coff.opthdr_len ); section = ( data + section_offset ); /* Load header into memory */ DBG2 ( "...headers to %p+%#x\n", pe->base, opthdr->header_len ); memcpy ( pe->base, data, opthdr->header_len ); end = ( pe->base + opthdr->header_len ); /* Load each section into memory */ for ( i = 0 ; i < pehdr->coff.num_sections ; i++, section++ ) { memset ( name, 0, sizeof ( name ) ); memcpy ( name, section->name, sizeof ( section->name ) ); section_base = ( pe->base + section->virtual ); filesz = section->raw_len; memsz = section->misc.virtual_len; DBG2 ( "...from %#05x to %p+%#zx/%#zx (%s)\n", section->raw, section_base, filesz, memsz, name ); memset ( section_base, 0, memsz ); memcpy ( section_base, ( data + section->raw ), filesz ); if ( end < ( section_base + memsz ) ) end = ( section_base + memsz ); } pe->len = ( ( ( end - pe->base ) + opthdr->section_align - 1 ) & ~( opthdr->section_align - 1 ) ); /* Load copy of raw image into memory immediately after loaded * sections. This seems to be used for verification of X.509 * signatures. */ raw_base = ( pe->base + pe->len ); memcpy ( raw_base, data, len ); pe->len += len; DBG2 ( "...raw copy to %p+%#zx\n", raw_base, len ); /* Extract entry point */ pe->entry = ( pe->base + opthdr->entry ); DBG2 ( "...entry point %p\n", pe->entry ); return 0; }
3,557
C
.c
108
30.638889
70
0.657459
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
261
xca.c
ventoy_Ventoy/wimboot/wimboot-2.7.3/src/xca.c
/* * Copyright (C) 2012 Michael Brown <[email protected]>. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ /** * @file * * Xpress Compression Algorithm (MS-XCA) decompression * */ #include <stdint.h> #include <stddef.h> #include <string.h> #include <stdio.h> #include "wimboot.h" #include "huffman.h" #include "xca.h" /** * Decompress XCA-compressed data * * @v data Compressed data * @v len Length of compressed data * @v buf Decompression buffer, or NULL * @ret out_len Length of decompressed data, or negative error */ ssize_t xca_decompress ( const void *data, size_t len, void *buf ) { const void *src = data; const void *end = ( uint8_t * ) src + len; uint8_t *out = buf; size_t out_len = 0; size_t out_len_threshold = 0; const struct xca_huf_len *lengths; struct xca xca; uint32_t accum = 0; int extra_bits = 0; unsigned int huf; struct huffman_symbols *sym; unsigned int raw; unsigned int match_len; unsigned int match_offset_bits; unsigned int match_offset; const uint8_t *copy; int rc; /* Process data stream */ while ( src < end ) { /* (Re)initialise decompressor if applicable */ if ( out_len >= out_len_threshold ) { /* Construct symbol lengths */ lengths = src; src = ( uint8_t * ) src + sizeof ( *lengths ); if ( src > end ) { DBG ( "XCA too short to hold Huffman lengths table.\n"); return -1; } for ( raw = 0 ; raw < XCA_CODES ; raw++ ) xca.lengths[raw] = xca_huf_len ( lengths, raw ); /* Construct Huffman alphabet */ if ( ( rc = huffman_alphabet ( &xca.alphabet, xca.lengths, XCA_CODES ) ) != 0 ) return rc; /* Initialise state */ accum = XCA_GET16 ( src ); accum <<= 16; accum |= XCA_GET16 ( src ); extra_bits = 16; /* Determine next threshold */ out_len_threshold = ( out_len + XCA_BLOCK_SIZE ); } /* Determine symbol */ huf = ( accum >> ( 32 - HUFFMAN_BITS ) ); sym = huffman_sym ( &xca.alphabet, huf ); raw = huffman_raw ( sym, huf ); accum <<= huffman_len ( sym ); extra_bits -= huffman_len ( sym ); if ( extra_bits < 0 ) { accum |= ( XCA_GET16 ( src ) << ( -extra_bits ) ); extra_bits += 16; } /* Process symbol */ if ( raw < XCA_END_MARKER ) { /* Literal symbol - add to output stream */ if ( buf ) *(out++) = raw; out_len++; } else if ( ( raw == XCA_END_MARKER ) && ( (uint8_t *) src >= ( ( uint8_t * ) end - 1 ) ) ) { /* End marker symbol */ return out_len; } else { /* LZ77 match symbol */ raw -= XCA_END_MARKER; match_offset_bits = ( raw >> 4 ); match_len = ( raw & 0x0f ); if ( match_len == 0x0f ) { match_len = XCA_GET8 ( src ); if ( match_len == 0xff ) { match_len = XCA_GET16 ( src ); } else { match_len += 0x0f; } } match_len += 3; if ( match_offset_bits ) { match_offset = ( ( accum >> ( 32 - match_offset_bits )) + ( 1 << match_offset_bits ) ); } else { match_offset = 1; } accum <<= match_offset_bits; extra_bits -= match_offset_bits; if ( extra_bits < 0 ) { accum |= ( XCA_GET16 ( src ) << (-extra_bits) ); extra_bits += 16; } /* Copy data */ out_len += match_len; if ( buf ) { copy = ( out - match_offset ); while ( match_len-- ) *(out++) = *(copy++); } } } return out_len; }
4,030
C
.c
141
25.170213
70
0.618187
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
true
262
wchar.h
ventoy_Ventoy/wimboot/wimboot-2.7.3/src/wchar.h
#ifndef _WCHAR_H #define _WCHAR_H /* * Copyright (C) 2012 Michael Brown <[email protected]>. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ /** * @file * * Wide characters * */ #include <stdint.h> typedef void mbstate_t; /** * Convert wide character to multibyte sequence * * @v buf Buffer * @v wc Wide character * @v ps Shift state * @ret len Number of characters written * * This is a stub implementation, sufficient to handle basic ASCII * characters. */ static inline size_t wcrtomb ( char *buf, wchar_t wc, mbstate_t *ps __attribute__ (( unused )) ) { *buf = wc; return 1; } extern int wcscasecmp ( const wchar_t *str1, const wchar_t *str2 ); extern size_t wcslen ( const wchar_t *str ); extern wchar_t * wcschr ( const wchar_t *str, wchar_t c ); extern char *strchr(const char *str, char c); #endif /* _WCHAR_H */
1,546
C
.c
49
29.510204
70
0.721477
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
true
264
efipath.c
ventoy_Ventoy/wimboot/wimboot-2.7.3/src/efipath.c
/* * Copyright (C) 2014 Michael Brown <[email protected]>. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ /** * @file * * EFI device paths * */ #include "wimboot.h" #include "efi.h" #include "efipath.h" /** * Find end of device path * * @v path Path to device * @ret path_end End of device path */ EFI_DEVICE_PATH_PROTOCOL * efi_devpath_end ( EFI_DEVICE_PATH_PROTOCOL *path ) { while ( path->Type != END_DEVICE_PATH_TYPE ) { path = ( ( ( void * ) path ) + /* There's this amazing new-fangled thing known as * a UINT16, but who wants to use one of those? */ ( ( path->Length[1] << 8 ) | path->Length[0] ) ); } return path; }
1,345
C
.c
42
29.857143
79
0.704388
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
265
wim.c
ventoy_Ventoy/wimboot/wimboot-2.7.3/src/wim.c
/* * Copyright (C) 2014 Michael Brown <[email protected]>. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ /** * @file * * WIM images * */ #include <stddef.h> #include <stdio.h> #include <string.h> #include <wchar.h> #include <assert.h> #include "wimboot.h" #include "vdisk.h" #include "lzx.h" #include "xca.h" #include "wim.h" /** WIM chunk buffer */ static struct wim_chunk_buffer wim_chunk_buffer; /** * Get WIM header * * @v file Virtual file * @v header WIM header to fill in * @ret rc Return status code */ int wim_header ( struct vdisk_file *file, struct wim_header *header ) { /* Sanity check */ if ( sizeof ( *header ) > file->len ) { DBG ( "WIM file too short (%#zx bytes)\n", file->len ); return -1; } /* Read WIM header */ file->read ( file, header, 0, sizeof ( *header ) ); return 0; } /** * Get compressed chunk offset * * @v file Virtual file * @v resource Resource * @v chunk Chunk number * @v offset Offset to fill in * @ret rc Return status code */ static int wim_chunk_offset ( struct vdisk_file *file, struct wim_resource_header *resource, unsigned int chunk, size_t *offset ) { size_t zlen = ( resource->zlen__flags & WIM_RESHDR_ZLEN_MASK ); unsigned int chunks; size_t offset_offset; size_t offset_len; size_t chunks_len; union { uint32_t offset_32; uint64_t offset_64; } u; /* Special case: zero-length files have no chunks */ if ( ! resource->len ) { *offset = 0; return 0; } /* Calculate chunk parameters */ chunks = ( ( resource->len + WIM_CHUNK_LEN - 1 ) / WIM_CHUNK_LEN ); offset_len = ( ( resource->len > 0xffffffffULL ) ? sizeof ( u.offset_64 ) : sizeof ( u.offset_32 ) ); chunks_len = ( ( chunks - 1 ) * offset_len ); /* Sanity check */ if ( chunks_len > zlen ) { DBG ( "Resource too short for %d chunks\n", chunks ); return -1; } /* Special case: chunk 0 has no offset field */ if ( ! chunk ) { *offset = chunks_len; return 0; } /* Treat out-of-range chunks as being at the end of the * resource, to allow for length calculation on the final * chunk. */ if ( chunk >= chunks ) { *offset = zlen; return 0; } /* Otherwise, read the chunk offset */ offset_offset = ( ( chunk - 1 ) * offset_len ); file->read ( file, &u, ( resource->offset + offset_offset ), offset_len ); *offset = ( chunks_len + ( ( offset_len == sizeof ( u.offset_64 ) ) ? u.offset_64 : u.offset_32 ) ); if ( *offset > zlen ) { DBG ( "Chunk %d offset lies outside resource\n", chunk ); return -1; } return 0; } /** * Read chunk from a compressed resource * * @v file Virtual file * @v header WIM header * @v resource Resource * @v chunk Chunk number * @v buf Chunk buffer * @ret rc Return status code */ static int wim_chunk ( struct vdisk_file *file, struct wim_header *header, struct wim_resource_header *resource, unsigned int chunk, struct wim_chunk_buffer *buf ) { ssize_t ( * decompress ) ( const void *data, size_t len, void *buf ); unsigned int chunks; size_t offset; size_t next_offset; size_t len; size_t expected_out_len; ssize_t out_len; int rc; /* Get chunk compressed data offset and length */ if ( ( rc = wim_chunk_offset ( file, resource, chunk, &offset ) ) != 0 ) return rc; if ( ( rc = wim_chunk_offset ( file, resource, ( chunk + 1 ), &next_offset ) ) != 0 ) return rc; len = ( next_offset - offset ); /* Calculate uncompressed length */ assert ( resource->len > 0 ); chunks = ( ( resource->len + WIM_CHUNK_LEN - 1 ) / WIM_CHUNK_LEN ); expected_out_len = WIM_CHUNK_LEN; if ( chunk >= ( chunks - 1 ) ) expected_out_len -= ( -resource->len & ( WIM_CHUNK_LEN - 1 ) ); /* Read possibly-compressed data */ if ( len == expected_out_len ) { /* Chunk did not compress; read raw data */ file->read ( file, buf->data, ( resource->offset + offset ), len ); } else { uint8_t zbuf[len]; /* Read compressed data into a temporary buffer */ file->read ( file, zbuf, ( resource->offset + offset ), len ); /* Identify decompressor */ if ( header->flags & WIM_HDR_LZX ) { decompress = lzx_decompress; } else if (header->flags & WIM_HDR_XPRESS) { decompress = xca_decompress; } else { DBG ( "Can't handle unknown compression scheme %#08x " "for %#llx chunk %d at [%#llx+%#llx)\n", header->flags, resource->offset, chunk, ( resource->offset + offset ), ( resource->offset + offset + len ) ); return -1; } /* Decompress data */ out_len = decompress ( zbuf, len, NULL ); if ( out_len < 0 ) return out_len; if ( ( ( size_t ) out_len ) != expected_out_len ) { DBG ( "Unexpected output length %#lx (expected %#zx)\n", out_len, expected_out_len ); return -1; } decompress ( zbuf, len, buf->data ); } return 0; } /** * Read from a (possibly compressed) resource * * @v file Virtual file * @v header WIM header * @v resource Resource * @v data Data buffer * @v offset Starting offset * @v len Length * @ret rc Return status code */ int wim_read ( struct vdisk_file *file, struct wim_header *header, struct wim_resource_header *resource, void *data, size_t offset, size_t len ) { static struct vdisk_file *cached_file; static size_t cached_resource_offset; static unsigned int cached_chunk; size_t zlen = ( resource->zlen__flags & WIM_RESHDR_ZLEN_MASK ); unsigned int chunk; size_t skip_len; size_t frag_len; int rc; /* Sanity checks */ if ( ( offset + len ) > resource->len ) { DBG ( "Resource too short (%#llx bytes)\n", resource->len ); return -1; } if ( ( resource->offset + zlen ) > file->len ) { DBG ( "Resource exceeds length of file\n" ); return -1; } /* If resource is uncompressed, just read the raw data */ if ( ! ( resource->zlen__flags & ( WIM_RESHDR_COMPRESSED | WIM_RESHDR_PACKED_STREAMS ) ) ) { file->read ( file, data, ( resource->offset + offset ), len ); return 0; } /* Read from each chunk overlapping the target region */ while ( len ) { /* Calculate chunk number */ chunk = ( offset / WIM_CHUNK_LEN ); /* Read chunk, if not already cached */ if ( ( file != cached_file ) || ( resource->offset != cached_resource_offset ) || ( chunk != cached_chunk ) ) { /* Read chunk */ if ( ( rc = wim_chunk ( file, header, resource, chunk, &wim_chunk_buffer ) ) != 0 ) return rc; /* Update cache */ cached_file = file; cached_resource_offset = resource->offset; cached_chunk = chunk; } /* Copy fragment from this chunk */ skip_len = ( offset % WIM_CHUNK_LEN ); frag_len = ( WIM_CHUNK_LEN - skip_len ); if ( frag_len > len ) frag_len = len; memcpy ( data, ( wim_chunk_buffer.data + skip_len ), frag_len ); /* Move to next chunk */ data += frag_len; offset += frag_len; len -= frag_len; } return 0; } /** * Get number of images * * @v file Virtual file * @v header WIM header * @v count Count of images to fill in * @ret rc Return status code */ int wim_count ( struct vdisk_file *file, struct wim_header *header, unsigned int *count ) { struct wim_lookup_entry entry; size_t offset; int rc; /* Count metadata entries */ for ( offset = 0 ; ( offset + sizeof ( entry ) ) <= header->lookup.len ; offset += sizeof ( entry ) ) { /* Read entry */ if ( ( rc = wim_read ( file, header, &header->lookup, &entry, offset, sizeof ( entry ) ) ) != 0 ) return rc; /* Check for metadata entries */ if ( entry.resource.zlen__flags & WIM_RESHDR_METADATA ) { (*count)++; DBG2 ( "...found image %d metadata at +%#zx\n", *count, offset ); } } return 0; } /** * Get WIM image metadata * * @v file Virtual file * @v header WIM header * @v index Image index, or 0 to use boot image * @v meta Metadata to fill in * @ret rc Return status code */ int wim_metadata ( struct vdisk_file *file, struct wim_header *header, unsigned int index, struct wim_resource_header *meta ) { struct wim_lookup_entry entry; size_t offset; unsigned int found = 0; int rc; /* If no image index is specified, just use the boot metadata */ if ( index == 0 ) { memcpy ( meta, &header->boot, sizeof ( *meta ) ); return 0; } /* Look for metadata entry */ for ( offset = 0 ; ( offset + sizeof ( entry ) ) <= header->lookup.len ; offset += sizeof ( entry ) ) { /* Read entry */ if ( ( rc = wim_read ( file, header, &header->lookup, &entry, offset, sizeof ( entry ) ) ) != 0 ) return rc; /* Look for our target entry */ if ( entry.resource.zlen__flags & WIM_RESHDR_METADATA ) { found++; DBG2 ( "...found image %d metadata at +%#zx\n", found, offset ); if ( found == index ) { memcpy ( meta, &entry.resource, sizeof ( *meta ) ); return 0; } } } /* Fail if index was not found */ DBG ( "Cannot find WIM image index %d in %s\n", index, file->name ); return -1; } /** * Get directory entry * * @v file Virtual file * @v header WIM header * @v meta Metadata * @v name Name * @v offset Directory offset (will be updated) * @v direntry Directory entry to fill in * @ret rc Return status code */ static int wim_direntry ( struct vdisk_file *file, struct wim_header *header, struct wim_resource_header *meta, const wchar_t *name, size_t *offset, struct wim_directory_entry *direntry ) { wchar_t name_buf[ wcslen ( name ) + 1 /* NUL */ ]; int rc; /* Search directory */ for ( ; ; *offset += direntry->len ) { /* Read length field */ if ( ( rc = wim_read ( file, header, meta, direntry, *offset, sizeof ( direntry->len ) ) ) != 0 ) return rc; /* Check for end of this directory */ if ( ! direntry->len ) { DBG ( "...directory entry \"%ls\" not found\n", name ); return -1; } /* Read fixed-length portion of directory entry */ if ( ( rc = wim_read ( file, header, meta, direntry, *offset, sizeof ( *direntry ) ) ) != 0 ) return rc; /* Check name length */ if ( direntry->name_len > sizeof ( name_buf ) ) continue; /* Read name */ if ( ( rc = wim_read ( file, header, meta, &name_buf, ( *offset + sizeof ( *direntry ) ), sizeof ( name_buf ) ) ) != 0 ) return rc; /* Check name */ if ( wcscasecmp ( name, name_buf ) != 0 ) continue; DBG2 ( "...found entry \"%ls\"\n", name ); return 0; } } /** * Get directory entry for a path * * @v file Virtual file * @v header WIM header * @v meta Metadata * @v path Path to file/directory * @v offset Directory entry offset to fill in * @v direntry Directory entry to fill in * @ret rc Return status code */ int wim_path ( struct vdisk_file *file, struct wim_header *header, struct wim_resource_header *meta, const wchar_t *path, size_t *offset, struct wim_directory_entry *direntry ) { wchar_t path_copy[ wcslen ( path ) + 1 /* WNUL */ ]; struct wim_security_header security; wchar_t *name; wchar_t *next; int rc; /* Read security data header */ if ( ( rc = wim_read ( file, header, meta, &security, 0, sizeof ( security ) ) ) != 0 ) return rc; /* Get root directory offset */ if (security.len > 0) direntry->subdir = ( ( security.len + sizeof ( uint64_t ) - 1 ) & ~( sizeof ( uint64_t ) - 1 ) ); else direntry->subdir = security.len + 8; /* Find directory entry */ name = memcpy ( path_copy, path, sizeof ( path_copy ) ); do { next = wcschr ( name, L'\\' ); if ( next ) *next = L'\0'; *offset = direntry->subdir; if ( ( rc = wim_direntry ( file, header, meta, name, offset, direntry ) ) != 0 ) return rc; name = ( next + 1 ); } while ( next ); return 0; } /** * Get file resource * * @v file Virtual file * @v header WIM header * @v meta Metadata * @v path Path to file * @v resource File resource to fill in * @ret rc Return status code */ int wim_file ( struct vdisk_file *file, struct wim_header *header, struct wim_resource_header *meta, const wchar_t *path, struct wim_resource_header *resource ) { struct wim_directory_entry direntry; struct wim_lookup_entry entry; size_t offset; int rc; /* Find directory entry */ if ( ( rc = wim_path ( file, header, meta, path, &offset, &direntry ) ) != 0 ) return rc; /* File matching file entry */ for ( offset = 0 ; ( offset + sizeof ( entry ) ) <= header->lookup.len ; offset += sizeof ( entry ) ) { /* Read entry */ if ( ( rc = wim_read ( file, header, &header->lookup, &entry, offset, sizeof ( entry ) ) ) != 0 ) return rc; /* Look for our target entry */ if ( memcmp ( &entry.hash, &direntry.hash, sizeof ( entry.hash ) ) == 0 ) { DBG ( "...found file \"%ls\"\n", path ); memcpy ( resource, &entry.resource, sizeof ( *resource ) ); return 0; } } DBG ( "Cannot find file %ls\n", path ); return -1; } /** * Get length of a directory * * @v file Virtual file * @v header WIM header * @v meta Metadata * @v offset Directory offset * @v len Directory length to fill in (excluding terminator) * @ret rc Return status code */ int wim_dir_len ( struct vdisk_file *file, struct wim_header *header, struct wim_resource_header *meta, size_t offset, size_t *len ) { struct wim_directory_entry direntry; int rc; /* Search directory */ for ( *len = 0 ; ; *len += direntry.len ) { /* Read length field */ if ( ( rc = wim_read ( file, header, meta, &direntry, ( offset + *len ), sizeof ( direntry.len ) ) ) != 0 ) return rc; /* Check for end of this directory */ if ( ! direntry.len ) return 0; } }
14,420
C
.c
479
26.818372
102
0.627929
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
false
false
false
false
true
267
die.c
ventoy_Ventoy/wimboot/wimboot-2.7.3/src/die.c
/* * Copyright (C) 2014 Michael Brown <[email protected]>. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ /** * @file * * Fatal errors * */ #include <stdarg.h> #include <stdio.h> #include "wimboot.h" #include "efi.h" /** * Handle fatal errors * * @v fmt Error message format string * @v ... Arguments */ void die ( const char *fmt, ... ) { EFI_BOOT_SERVICES *bs; EFI_RUNTIME_SERVICES *rs; va_list args; /* Print message */ va_start ( args, fmt ); vprintf ( fmt, args ); va_end ( args ); /* Reboot or exit as applicable */ if ( efi_systab ) { /* Exit */ bs = efi_systab->BootServices; bs->Exit ( efi_image_handle, EFI_LOAD_ERROR, 0, NULL ); printf ( "Failed to exit\n" ); rs = efi_systab->RuntimeServices; rs->ResetSystem ( EfiResetWarm, 0, 0, NULL ); printf ( "Failed to reboot\n" ); } else { /* Wait for keypress */ printf ( "Press a key to reboot..." ); getchar(); printf ( "\n" ); /* Reboot system */ reboot(); } /* Should be impossible to reach this */ __builtin_unreachable(); }
1,731
C
.c
62
25.693548
70
0.689572
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
268
cookie.c
ventoy_Ventoy/wimboot/wimboot-2.7.3/src/cookie.c
/* * Copyright (C) 2021 Michael Brown <[email protected]>. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ /** * @file * * Stack cookie * */ #include "wimboot.h" /** Stack cookie */ unsigned long __stack_chk_guard; /** * Construct stack cookie value * */ static __attribute__ (( noinline )) unsigned long make_cookie ( void ) { union { struct { uint32_t eax; uint32_t edx; } __attribute__ (( packed )); unsigned long tsc; } u; unsigned long cookie; /* We have no viable source of entropy. Use the CPU timestamp * counter, which will have at least some minimal randomness * in the low bits by the time we are invoked. */ __asm__ ( "rdtsc" : "=a" ( u.eax ), "=d" ( u.edx ) ); cookie = u.tsc; /* Ensure that the value contains a NUL byte, to act as a * runaway string terminator. Construct the NUL using a shift * rather than a mask, to avoid losing valuable entropy in the * lower-order bits. */ cookie <<= 8; return cookie; } /** * Initialise stack cookie * * This function must not itself use stack guard */ void init_cookie ( void ) { /* Set stack cookie value * * This function must not itself use stack protection, since * the change in the stack guard value would trigger a false * positive. * * There is unfortunately no way to annotate a function to * exclude the use of stack protection. We must therefore * rely on correctly anticipating the compiler's decision on * the use of stack protection. */ __stack_chk_guard = make_cookie(); } /** * Abort on stack check failure * */ void __stack_chk_fail ( void ) { /* Abort program */ die ( "Stack check failed\n" ); }
2,346
C
.c
81
26.703704
72
0.708962
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
271
cpio.c
ventoy_Ventoy/wimboot/wimboot-2.7.3/src/cpio.c
/* * Copyright (C) 2012 Michael Brown <[email protected]>. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ /** * @file * * CPIO archives * */ #include <stdint.h> #include <stddef.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "wimboot.h" #include "cpio.h" /** * Align CPIO length to nearest dword * * @v len Length * @ret len Aligned length */ static size_t cpio_align ( size_t len ) { return ( ( len + 0x03 ) & ~0x03 ); } /** * Parse CPIO field value * * @v field ASCII field * @ret value Field value */ static unsigned long cpio_value ( const char *field ) { char buf[9]; memcpy ( buf, field, ( sizeof ( buf ) - 1 ) ); buf[ sizeof ( buf ) - 1 ] = '\0'; return strtoul ( buf, NULL, 16 ); } /** * Extract files from CPIO archive * * @v data CPIO archive * @v len Maximum length of CPIO archive * @v file File handler * @ret rc Return status code */ int cpio_extract ( void *data, size_t len, int ( * file ) ( const char *name, void *data, size_t len ) ) { const struct cpio_header *cpio; const uint32_t *pad; const char *file_name; void *file_data; size_t file_name_len; size_t file_len; size_t cpio_len; int rc; while ( 1 ) { /* Skip over any padding */ while ( len >= sizeof ( *pad ) ) { pad = data; if ( *pad ) break; data += sizeof ( *pad ); len -= sizeof ( *pad ); } /* Stop if we have reached the end of the archive */ if ( ! len ) return 0; /* Sanity check */ if ( len < sizeof ( *cpio ) ) { DBG ( "Truncated CPIO header\n" ); return -1; } cpio = data; /* Check magic */ if ( memcmp ( cpio->c_magic, CPIO_MAGIC, sizeof ( cpio->c_magic ) ) != 0 ) { DBG ( "Bad CPIO magic\n" ); return -1; } /* Extract file parameters */ file_name = ( ( void * ) ( cpio + 1 ) ); file_name_len = cpio_value ( cpio->c_namesize ); file_data = ( data + cpio_align ( sizeof ( *cpio ) + file_name_len ) ); file_len = cpio_value ( cpio->c_filesize ); cpio_len = ( file_data + file_len - data ); if ( cpio_len < len ) cpio_len = cpio_align ( cpio_len ); if ( cpio_len > len ) { DBG ( "Truncated CPIO file\n" ); return -1; } /* If we reach the trailer, we're done */ if ( strcmp ( file_name, CPIO_TRAILER ) == 0 ) return 0; /* Process file */ if ( ( rc = file ( file_name, file_data, file_len ) ) != 0 ) return rc; /* Move to next file */ data += cpio_len; len -= cpio_len; } }
3,160
C
.c
119
23.865546
70
0.634501
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
272
wimpatch.h
ventoy_Ventoy/wimboot/wimboot-2.7.3/src/wimpatch.h
#ifndef _WIMPATCH_H #define _WIMPATCH_H /* * Copyright (C) 2014 Michael Brown <[email protected]>. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ /** * @file * * WIM dynamic patching * */ #include <stdint.h> struct vdisk_file; extern void patch_wim ( struct vdisk_file *file, void *data, size_t offset, size_t len ); #endif /* _WIMPATCH_H */
1,044
C
.c
31
31.677419
75
0.7428
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
274
efiblock.h
ventoy_Ventoy/wimboot/wimboot-2.7.3/src/efiblock.h
#ifndef _EFIBLOCK_H #define _EFIBLOCK_H /* * Copyright (C) 2014 Michael Brown <[email protected]>. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ /** * @file * * EFI block device * */ #include "efi.h" #include "efi/Protocol/BlockIo.h" #include "efi/Protocol/DevicePath.h" extern void efi_install ( EFI_HANDLE *vdisk, EFI_HANDLE *vpartition ); extern EFI_DEVICE_PATH_PROTOCOL *bootmgfw_path; #endif /* _EFIBLOCK_H */
1,115
C
.c
32
32.96875
70
0.751161
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
276
vsprintf.c
ventoy_Ventoy/wimboot/wimboot-2.7.3/src/vsprintf.c
/* * Quick and dirty wrapper around iPXE's unmodified vsprintf.c * */ #include <stdint.h> #include <string.h> #include "wimboot.h" #define FILE_LICENCE(x) #include "ipxe/vsprintf.c"
188
C
.c
9
19.222222
62
0.744318
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
277
coverity-model.c
ventoy_Ventoy/wimboot/wimboot-2.7.3/src/coverity-model.c
/* * Coverity modelling file * */ typedef unsigned short wchar_t; typedef void mbstate_t; /* Inhibit use of built-in models for functions where Coverity's * assumptions about the modelled function are incorrect for wimboot. */ int getchar ( void ) { } size_t wcrtomb ( char *buf, wchar_t wc, mbstate_t *ps ) { }
319
C
.c
13
23
69
0.740132
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
278
int13.c
ventoy_Ventoy/wimboot/wimboot-2.7.3/src/int13.c
/* * Copyright (C) 2012 Michael Brown <[email protected]>. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ /** * @file * * INT 13 emulation * */ #include <string.h> #include <stdio.h> #include "wimboot.h" #include "int13.h" #include "vdisk.h" /** Emulated drive number */ static int vdisk_drive; /** * Initialise emulation * * @ret drive Emulated drive number */ int initialise_int13 ( void ) { /* Determine drive number */ vdisk_drive = ( 0x80 | INT13_DRIVE_COUNT++ ); DBG ( "Emulating drive %#02x\n", vdisk_drive ); return vdisk_drive; } /** * INT 13, 08 - Get drive parameters * * @ret ch Low bits of maximum cylinder number * @ret cl (bits 7:6) High bits of maximum cylinder number * @ret cl (bits 5:0) Maximum sector number * @ret dh Maximum head number * @ret dl Number of drives * @ret ah Status code */ static void int13_get_parameters ( struct bootapp_callback_params *params ) { unsigned int max_cylinder = ( VDISK_CYLINDERS - 1 ); unsigned int max_head = ( VDISK_HEADS - 1 ); unsigned int max_sector = ( VDISK_SECTORS_PER_TRACK - 0 /* sic */ ); unsigned int num_drives; unsigned int min_num_drives; /* Calculate number of drives to report */ num_drives = INT13_DRIVE_COUNT; min_num_drives = ( ( vdisk_drive & 0x7f ) + 1 ); if ( num_drives < min_num_drives ) num_drives = min_num_drives; /* Fill in drive parameters */ params->ch = ( max_cylinder & 0xff ); params->cl = ( ( ( max_cylinder >> 8 ) << 6 ) | max_sector ); params->dh = max_head; params->dl = num_drives; DBG2 ( "Get parameters: C/H/S = %d/%d/%d, drives = %d\n", ( max_cylinder + 1 ), ( max_head + 1 ), max_sector, num_drives ); /* Success */ params->ah = 0; } /** * INT 13, 15 - Get disk type * * @ret cx:dx Sector count * @ret ah Type code */ static void int13_get_disk_type ( struct bootapp_callback_params *params ) { uint32_t sector_count = VDISK_COUNT; uint8_t drive_type = INT13_DISK_TYPE_HDD; /* Fill in disk type */ params->cx = ( sector_count >> 16 ); params->dx = ( sector_count & 0xffff ); params->ah = drive_type; DBG2 ( "Get disk type: sectors = %#08x, type = %d\n", sector_count, drive_type ); } /** * INT 13, 41 - Extensions installation check * * @v bx 0x55aa * @ret bx 0xaa55 * @ret cx Extensions API support bitmap * @ret ah API version */ static void int13_extension_check ( struct bootapp_callback_params *params ) { /* Fill in extension information */ params->bx = 0xaa55; params->cx = INT13_EXTENSION_LINEAR; params->ah = INT13_EXTENSION_VER_1_X; DBG2 ( "Extensions installation check\n" ); } /** * INT 13, 48 - Get extended parameters * * @v ds:si Drive parameter table * @ret ah Status code */ static void int13_get_extended_parameters ( struct bootapp_callback_params *params ) { struct int13_disk_parameters *disk_params; /* Fill in extended parameters */ disk_params = REAL_PTR ( params->ds, params->si ); memset ( disk_params, 0, sizeof ( *disk_params ) ); disk_params->bufsize = sizeof ( *disk_params ); disk_params->flags = INT13_FL_DMA_TRANSPARENT; disk_params->cylinders = VDISK_CYLINDERS; disk_params->heads = VDISK_HEADS; disk_params->sectors_per_track = VDISK_SECTORS_PER_TRACK; disk_params->sectors = VDISK_COUNT; disk_params->sector_size = VDISK_SECTOR_SIZE; DBG2 ( "Get extended parameters: C/H/S = %d/%d/%d, sectors = %#08llx " "(%d bytes)\n", disk_params->cylinders, disk_params->heads, disk_params->sectors_per_track, disk_params->sectors, disk_params->sector_size ); /* Success */ params->ah = 0; } /** * INT 13, 42 - Extended read * * @v ds:si Disk address packet * @ret ah Status code */ static void int13_extended_read ( struct bootapp_callback_params *params ) { struct int13_disk_address *disk_address; void *data; /* Read from emulated disk */ disk_address = REAL_PTR ( params->ds, params->si ); data = REAL_PTR ( disk_address->buffer.segment, disk_address->buffer.offset ); vdisk_read ( disk_address->lba, disk_address->count, data ); /* Success */ params->ah = 0; } /** * Emulate INT 13 drive * * @v params Parameters */ void emulate_int13 ( struct bootapp_callback_params *params ) { int command = params->ah; int drive = params->dl; int min_num_drives; unsigned long eflags; if ( drive == vdisk_drive ) { /* Emulated drive - handle internally */ /* Populate eflags with a sensible starting value */ __asm__ ( "pushf\n\t" "pop %0\n\t" : "=r" ( eflags ) ); params->eflags = ( eflags & ~CF ); /* Handle command */ switch ( command ) { case INT13_GET_PARAMETERS: int13_get_parameters ( params ); break; case INT13_GET_DISK_TYPE: int13_get_disk_type ( params ); break; case INT13_EXTENSION_CHECK: int13_extension_check ( params ); break; case INT13_GET_EXTENDED_PARAMETERS: int13_get_extended_parameters ( params ); break; case INT13_EXTENDED_READ: int13_extended_read ( params ); break; default: DBG ( "Unrecognised INT 13,%02x\n", command ); params->eflags |= CF; break; } } else { /* Pass through command to underlying INT 13 */ call_interrupt ( params ); /* Modify drive count, if applicable */ if ( command == INT13_GET_PARAMETERS ) { min_num_drives = ( ( vdisk_drive & 0x7f ) + 1 ); if ( params->dl < min_num_drives ) params->dl = min_num_drives; } } }
6,058
C
.c
197
28.263959
78
0.681639
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
280
efiguid.c
ventoy_Ventoy/wimboot/wimboot-2.7.3/src/efiguid.c
/* * Copyright (C) 2014 Michael Brown <[email protected]>. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ /** * @file * * EFI GUIDs * */ #include "wimboot.h" #include "efi.h" #include "efi/Protocol/BlockIo.h" #include "efi/Protocol/DevicePath.h" #include "efi/Protocol/GraphicsOutput.h" #include "efi/Protocol/LoadedImage.h" #include "efi/Protocol/SimpleFileSystem.h" /** Block I/O protocol GUID */ EFI_GUID efi_block_io_protocol_guid = EFI_BLOCK_IO_PROTOCOL_GUID; /** Device path protocol GUID */ EFI_GUID efi_device_path_protocol_guid = EFI_DEVICE_PATH_PROTOCOL_GUID; /** Graphics output protocol GUID */ EFI_GUID efi_graphics_output_protocol_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; /** Loaded image protocol GUID */ EFI_GUID efi_loaded_image_protocol_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID; /** Simple file system protocol GUID */ EFI_GUID efi_simple_file_system_protocol_guid = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID;
1,626
C
.c
46
33.608696
70
0.762238
ventoy/Ventoy
61,575
4,002
755
GPL-3.0
9/7/2024, 9:40:14 AM (Europe/Amsterdam)
false
false
false
true
false
false
false
true
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
22