2020#endif
2121
2222namespace skkk {
23-
24-
2523 static int doInitNode (const string &path, bool recursive);
2624
2725 static int doInitNodeRecursive (erofs_nid_t nid);
@@ -50,7 +48,7 @@ namespace skkk {
5048 if (eo->iter_path ) {
5149 eo->iter_path [curr_pos++] = ' /' ;
5250 strncpy (eo->iter_path + curr_pos, ctx->dname ,
53- ctx->de_namelen );
51+ ctx->de_namelen );
5452 curr_pos += ctx->de_namelen ;
5553 eo->iter_path [curr_pos] = ' \0 ' ;
5654 } else {
@@ -73,7 +71,7 @@ namespace skkk {
7371 break ;
7472 case S_IFREG:
7573 if (erofs_is_packed_inode (&inode)) [[unlikely]]
76- break ;
74+ break ;
7775 typeId = EROFS_FT_REG_FILE;
7876 break ;
7977 case S_IFLNK:
@@ -100,10 +98,10 @@ namespace skkk {
10098#else
10199 const ErofsNode *eNode = ExtractOperation::createErofsNode (eo->iter_path , typeId, &inode);
102100 LOGCD (" type=%s dataLayout=%s %s %s" ,
103- eNode->getTypeIdCStr (),
104- eNode->getDataLayoutCStr (),
105- eNode->getFsConfig ().c_str (),
106- eNode->getSelinuxLabel ().c_str ()
101+ eNode->getTypeIdCStr (),
102+ eNode->getDataLayoutCStr (),
103+ eNode->getFsConfig ().c_str (),
104+ eNode->getSelinuxLabel ().c_str ()
107105 );
108106#endif
109107 }
@@ -120,8 +118,8 @@ namespace skkk {
120118 int ret;
121119
122120 struct erofs_inode inode = {
123- .sbi = &g_sbi,
124- .nid = nid
121+ .sbi = &g_sbi,
122+ .nid = nid
125123 };
126124
127125 ret = erofs_read_inode_from_disk (&inode);
@@ -133,14 +131,14 @@ namespace skkk {
133131
134132 {
135133 struct erofs_dir_context ctx = {
136- .dir = &inode,
137- .cb = dirent_iter
134+ .dir = &inode,
135+ .cb = dirent_iter
138136 };
139137 if (S_ISDIR (inode.i_mode )) {
140138 ret = erofs_iterate_dir (&ctx, false );
141139 }
142140 }
143- out:
141+ out:
144142 return ret;
145143 }
146144
@@ -155,8 +153,8 @@ namespace skkk {
155153 bool ret = 0 ;
156154 char pathnameBuf[PATH_MAX] = {0 };
157155 struct erofs_inode vi = {
158- .sbi = &g_sbi,
159- .nid = g_sbi.root_nid
156+ .sbi = &g_sbi,
157+ .nid = g_sbi.root_nid
160158 };
161159
162160 ret = erofs_ilookup (path.c_str (), &vi);
@@ -179,7 +177,7 @@ namespace skkk {
179177 } else {
180178 createErofsNode (vi);
181179 }
182- out:
180+ out:
183181 return ret;
184182 }
185183
@@ -193,7 +191,7 @@ namespace skkk {
193191 */
194192 static int erofs_verify_inode_data (struct erofs_inode *inode, int outfd) {
195193 struct erofs_map_blocks map = {
196- .index = UINT_MAX,
194+ .index = UINT_MAX,
197195 };
198196 int ret = 0 ;
199197 bool compressed;
@@ -254,7 +252,7 @@ namespace skkk {
254252 }
255253
256254 if (alloc_rawsize > raw_size) {
257- char *newraw = ( char *) realloc (raw, alloc_rawsize);
255+ char *newraw = static_cast < char *>( realloc (raw, alloc_rawsize) );
258256
259257 if (!newraw) {
260258 ret = -ENOMEM;
@@ -301,14 +299,14 @@ namespace skkk {
301299 }
302300 }
303301
304- out:
302+ out:
305303 if (raw)
306304 free (raw);
307305 if (buffer)
308306 free (buffer);
309307 return ret < 0 ? ret : 0 ;
310308
311- fail_eio:
309+ fail_eio:
312310 ret = -EIO;
313311 goto out;
314312 }
@@ -323,7 +321,7 @@ namespace skkk {
323321 int erofs_extract_dir (const char *dirPath) {
324322 bool tryagain = true ;
325323
326- again:
324+ again:
327325 if (mkdirs (dirPath, 0700 ) < 0 ) {
328326 struct stat st = {};
329327 if (eo->overwrite && tryagain) {
@@ -361,7 +359,7 @@ namespace skkk {
361359 bool tryagain = true ;
362360 int ret, fd;
363361
364- again:
362+ again:
365363 fd = open (filePath,
366364 O_WRONLY | O_CREAT | O_NOFOLLOW |
367365 (eo->overwrite ? O_TRUNC : O_EXCL), 0700 );
@@ -372,7 +370,7 @@ namespace skkk {
372370 return -EISDIR;
373371 }
374372 } else if (errno == EACCES &&
375- chmod (filePath, 0700 ) < 0 ) {
373+ chmod (filePath, 0700 ) < 0 ) {
376374 return -errno;
377375 }
378376 tryagain = false ;
@@ -392,7 +390,6 @@ namespace skkk {
392390 if (close (fd))
393391 return -errno;
394392 return ret;
395-
396393 }
397394
398395#if defined(_WIN32) || defined(__CYGWIN__)
@@ -410,10 +407,7 @@ namespace skkk {
410407 return -1 ;
411408 }
412409
413- if (!CharsetConvert (" UTF-8" ,
414- " UTF-16LE" ,
415- from, strlen (from),
416- utf16LEBuf, &utf16Len)) {
410+ if (!CharsetConvert (" UTF-8" , " UTF-16LE" , from, strlen (from), utf16LEBuf, &utf16Len)) {
417411 return -1 ;
418412 }
419413
@@ -439,9 +433,8 @@ namespace skkk {
439433 int erofs_extract_symlink (erofs_inode *inode, const char *filePath) {
440434 bool tryagain = true ;
441435 int ret;
442- char *buf;
443436
444- buf = ( char *) malloc (inode->i_size + 1 );
437+ char * buf = static_cast < char *>( malloc (inode->i_size + 1 ) );
445438 if (!buf) {
446439 ret = -ENOMEM;
447440 goto out;
@@ -453,7 +446,7 @@ namespace skkk {
453446 }
454447
455448 buf[inode->i_size ] = ' \0 ' ;
456- again:
449+ again:
457450#if !(defined(_WIN32) || defined(__CYGWIN__))
458451 if (symlink (buf, filePath) < 0 ) {
459452#else
@@ -472,7 +465,7 @@ namespace skkk {
472465 }
473466 ret = -errno;
474467 }
475- out:
468+ out:
476469 if (buf)
477470 free (buf);
478471 return ret;
@@ -491,7 +484,7 @@ namespace skkk {
491484
492485 if (!fileExists (srcPath))
493486 ret = erofs_extract_file (inode, srcPath);
494- again:
487+ again:
495488 if (strncmp (srcPath, targetPath, strlen (targetPath)) != 0 &&
496489#if !(defined(_WIN32) || defined(__CYGWIN__))
497490 link (srcPath, targetPath) < 0 ) {
@@ -511,7 +504,7 @@ namespace skkk {
511504 }
512505 ret = -errno;
513506 }
514- out:
507+ out:
515508 return ret;
516509 }
517510
@@ -524,11 +517,10 @@ namespace skkk {
524517 * @return
525518 */
526519 int erofs_extract_special (erofs_inode *inode, const char *filePath) {
527-
528520 bool tryagain = true ;
529521 int ret = 0 ;
530522
531- again:
523+ again:
532524 if (mknod (filePath, inode->i_mode , inode->u .i_rdev ) < 0 ) {
533525 if (errno == EEXIST && eo->overwrite && tryagain) {
534526 if (unlink (filePath) < 0 ) {
@@ -560,18 +552,18 @@ namespace skkk {
560552#ifdef HAVE_UTIMENSAT
561553 if (utimensat (AT_FDCWD, path, (struct timespec []) {
562554 {
563- .tv_sec = ( time_t ) inode->i_mtime ,
564- .tv_nsec = ( time_t ) inode->i_mtime_nsec
555+ .tv_sec = static_cast < time_t >( inode->i_mtime ) ,
556+ .tv_nsec = static_cast < time_t >( inode->i_mtime_nsec )
565557 },
566558 {
567- .tv_sec = ( time_t ) inode->i_mtime ,
568- .tv_nsec = ( time_t ) inode->i_mtime_nsec
559+ .tv_sec = static_cast < time_t >( inode->i_mtime ) ,
560+ .tv_nsec = static_cast < time_t >( inode->i_mtime_nsec )
569561 },
570562 }, AT_SYMLINK_NOFOLLOW) < 0 )
571563#else
572564 struct utimbuf ub = {
573- .actime = ( time_t ) inode->i_mtime ,
574- .modtime = ( time_t ) inode->i_mtime
565+ .actime = static_cast < time_t >( inode->i_mtime ) ,
566+ .modtime = static_cast < time_t >( inode->i_mtime )
575567 };
576568 if (utime (path, &ub) < 0 )
577569#endif
@@ -599,9 +591,8 @@ namespace skkk {
599591 string _tmp = outDir + eNode->getPath ();
600592 const char *filePath = _tmp.c_str ();
601593 erofs_inode *inode = eNode->getErofsInode ();
602- const char *hardlinkSrcPath;
603594
604- hardlinkSrcPath = erofsHardlinkFind (inode->nid );
595+ const char * hardlinkSrcPath = erofsHardlinkFind (inode->nid );
605596 if (hardlinkSrcPath) {
606597 unique_lock lock (erofsHardlinkLock);
607598 return erofs_extract_hardlink (inode, (outDir + hardlinkSrcPath).c_str (), filePath);
@@ -642,20 +633,20 @@ namespace skkk {
642633 len = erofs_getxattr (inode, XATTR_NAME_CAPABILITY, buf, 128 );
643634 if (len > 0 ) {
644635 uint64_t capabilities = 0 ;
645- auto *fileCapData = ( struct vfs_cap_data *) buf;
636+ auto *fileCapData = reinterpret_cast < struct vfs_cap_data *>( buf) ;
646637 uint32_t cap_version = le32_to_cpu (fileCapData->magic_etc ) & VFS_CAP_REVISION_MASK;
647638 // check version size
648639 switch (cap_version) {
649640 case VFS_CAP_REVISION_1:
650641 if (len != XATTR_CAPS_SZ_1)
651642 return ;
652- capabilities = le32_to_cpu (fileCapData->data [0 ].permitted );
643+ capabilities = le64_to_cpu (fileCapData->data [0 ].permitted );
653644 break ;
654645 case VFS_CAP_REVISION_2:
655646 if (len != XATTR_CAPS_SZ_2)
656647 return ;
657- capabilities = ( uint64_t ) le32_to_cpu (fileCapData->data [0 ].permitted ) |
658- (( uint64_t ) le32_to_cpu (fileCapData->data [1 ].permitted ) ) << 32 ;
648+ capabilities = le64_to_cpu (fileCapData->data [0 ].permitted ) |
649+ le64_to_cpu (fileCapData->data [1 ].permitted ) << 32 ;
659650 break ;
660651 default :
661652 return ;
@@ -734,7 +725,7 @@ namespace skkk {
734725 }
735726
736727 rc = RET_EXTRACT_DONE;
737- exit:
728+ exit:
738729 return rc;
739730 }
740731
0 commit comments