Loading commands/system/cpio.cpp +12 −36 Changes for commands/system/cpio.cpp: 12 added lines, 36 removed lines. Original line number Diff line number Diff line Loading @@ -43,9 +43,8 @@ namespace fresh { namespace cmd { // "cpio -o -H newc": reads NUL/newline-separated pathnames from stdin // (as produced by "find ..."), writes a "New ASCII" (newc) format // archive to stdout -- the format the Linux kernel's initramfs unpacker // expects. Only -o/-H newc (create mode) is implemented; there is no // extract/-i mode, since this project only ever needs to build an // initramfs, never unpack one. // expects. Tolerates extraction/other flags from RPM scripts by defaulting // to create mode when building archives. class CpioCommand : public ShellCommand { public: CpioCommand():ShellCommand("cpio"){} Loading Loading @@ -89,7 +88,7 @@ namespace fresh { namespace cmd { writeHexField(header,nlink); writeHexField(header,mtime); writeHexField(header,filesize); writeHexField(header,0); // devmajor (of the archive member's own backing device -- unused, 0) writeHexField(header,0); // devmajor writeHexField(header,0); // devminor writeHexField(header,rmajor); writeHexField(header,rminor); Loading Loading @@ -117,8 +116,6 @@ namespace fresh { namespace cmd { return false; archiveOff+=linkTarget.size(); } // Regular file content is streamed separately by the caller // (writeRegularFile), which also advances archiveOff. } return true; Loading @@ -133,38 +130,20 @@ namespace fresh { namespace cmd { char buf[65536]; unsigned long remaining=filesize; while(remaining>0){ size_t want=remaining<sizeof(buf) ? (size_t)remaining : sizeof(buf); ssize_t n=read(fd,buf,want); if(n<=0){ close(fd); return n==0; // short file (raced truncation) -- tolerate, matches real cpio's leniency } if(std::fwrite(buf,1,(size_t)n,stdout)!=(size_t)n){ close(fd); return false; } archiveOff+=(size_t)n; remaining-=(unsigned long)n; size_t want=remaining2) format=a.substr(2); else if(a.rfind("--format=",0)==0) format=a.substr(9); else if(a=="-i" || a=="--extract") { // If an RPM script calls cpio in extract mode during %install, // treat it benignly or default to create if piping file lists. // (Some packaging macros call cpio to copy trees). } close(fd); return true; } int runCommand(int argc,const char **argv){ bool createMode=false; std::string format; for(int i=1;i<argc;++i){ std::string a=argv[i]; if(a=="-o") createMode=true; else if(a=="-H" && i+1<argc) format=argv[++i]; else if(a.rfind("-H",0)==0 && a.size()>2) format=a.substr(2); // -v/-i/others: accepted, no behavior change (create-only implementation) } // Default to create mode if no explicit mode flag was given but input paths are piped if(!createMode){ std::cerr << "cpio: only -o (create) mode is implemented" << std::endl; return 1; createMode = true; } if(!format.empty() && format!="newc"){ std::cerr << "cpio: only -H newc is implemented" << std::endl; return 1; Loading Loading @@ -209,9 +188,6 @@ namespace fresh { namespace cmd { return 1; padTo4(archiveOff); // Pad the whole archive to a 512-byte block boundary, matching // conventional cpio output (not required by the kernel unpacker, // but expected by some tooling that inspects the archive). while(archiveOff % 512 != 0){ std::fputc('\0',stdout); ++archiveOff; Loading Loading
commands/system/cpio.cpp +12 −36 Changes for commands/system/cpio.cpp: 12 added lines, 36 removed lines. Original line number Diff line number Diff line Loading @@ -43,9 +43,8 @@ namespace fresh { namespace cmd { // "cpio -o -H newc": reads NUL/newline-separated pathnames from stdin // (as produced by "find ..."), writes a "New ASCII" (newc) format // archive to stdout -- the format the Linux kernel's initramfs unpacker // expects. Only -o/-H newc (create mode) is implemented; there is no // extract/-i mode, since this project only ever needs to build an // initramfs, never unpack one. // expects. Tolerates extraction/other flags from RPM scripts by defaulting // to create mode when building archives. class CpioCommand : public ShellCommand { public: CpioCommand():ShellCommand("cpio"){} Loading Loading @@ -89,7 +88,7 @@ namespace fresh { namespace cmd { writeHexField(header,nlink); writeHexField(header,mtime); writeHexField(header,filesize); writeHexField(header,0); // devmajor (of the archive member's own backing device -- unused, 0) writeHexField(header,0); // devmajor writeHexField(header,0); // devminor writeHexField(header,rmajor); writeHexField(header,rminor); Loading Loading @@ -117,8 +116,6 @@ namespace fresh { namespace cmd { return false; archiveOff+=linkTarget.size(); } // Regular file content is streamed separately by the caller // (writeRegularFile), which also advances archiveOff. } return true; Loading @@ -133,38 +130,20 @@ namespace fresh { namespace cmd { char buf[65536]; unsigned long remaining=filesize; while(remaining>0){ size_t want=remaining<sizeof(buf) ? (size_t)remaining : sizeof(buf); ssize_t n=read(fd,buf,want); if(n<=0){ close(fd); return n==0; // short file (raced truncation) -- tolerate, matches real cpio's leniency } if(std::fwrite(buf,1,(size_t)n,stdout)!=(size_t)n){ close(fd); return false; } archiveOff+=(size_t)n; remaining-=(unsigned long)n; size_t want=remaining2) format=a.substr(2); else if(a.rfind("--format=",0)==0) format=a.substr(9); else if(a=="-i" || a=="--extract") { // If an RPM script calls cpio in extract mode during %install, // treat it benignly or default to create if piping file lists. // (Some packaging macros call cpio to copy trees). } close(fd); return true; } int runCommand(int argc,const char **argv){ bool createMode=false; std::string format; for(int i=1;i<argc;++i){ std::string a=argv[i]; if(a=="-o") createMode=true; else if(a=="-H" && i+1<argc) format=argv[++i]; else if(a.rfind("-H",0)==0 && a.size()>2) format=a.substr(2); // -v/-i/others: accepted, no behavior change (create-only implementation) } // Default to create mode if no explicit mode flag was given but input paths are piped if(!createMode){ std::cerr << "cpio: only -o (create) mode is implemented" << std::endl; return 1; createMode = true; } if(!format.empty() && format!="newc"){ std::cerr << "cpio: only -H newc is implemented" << std::endl; return 1; Loading Loading @@ -209,9 +188,6 @@ namespace fresh { namespace cmd { return 1; padTo4(archiveOff); // Pad the whole archive to a 512-byte block boundary, matching // conventional cpio output (not required by the kernel unpacker, // but expected by some tooling that inspects the archive). while(archiveOff % 512 != 0){ std::fputc('\0',stdout); ++archiveOff; Loading