当前位置: 首页 > news >正文

帮人做图挣外快的网站seo入门培训课程

帮人做图挣外快的网站,seo入门培训课程,本地电商平台开发,asp网站应用程序文章目录 背景运行环境 文件系统对比linux下的文件系统mac下的文件系统linux下的mv指令 golang的os.Rename源码os.Renamesyscall.Renamesyscall.RenameatSYS_RENAMEAT是什么 查看系统调用函数文档什么是man pageman page的用法user commandssystem calls renameat不支持跨挂载点…

文章目录

    • 背景
      • 运行环境
    • 文件系统对比
      • linux下的文件系统
      • mac下的文件系统
      • linux下的mv指令
    • golang的os.Rename源码
      • os.Rename
      • syscall.Rename
      • syscall.Renameat
      • SYS_RENAMEAT是什么
    • 查看系统调用函数文档
      • 什么是man page
      • man page的用法
        • user commands
        • system calls
      • renameat不支持跨挂载点调用
      • strace确定程序调用了renameat
    • 怎么避免错误
    • 总结

背景

在执行go程序的时候,其中有一步是把/tmp目录下的一个文件移动到用户目录下,使用go的os.Rename函数来实现。经测试在mac上是可以正常跑的,但是在linux机器上却报错了。报错如下:

go run ./script/download-go go1.22.3
download from https://go.dev/dl/go1.22.3.linux-amd64.tar.gz% Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed
100    75  100    75    0     0     53      0  0:00:01  0:00:01 --:--:--    53
100 65.7M  100 65.7M    0     0   160k      0  0:07:00  0:07:00 --:--:--  419k
rename /tmp/go2503368948/go go-release/go1.22.3: invalid cross-device link
exit status 1

错误信息 invalid cross-device link 表明 /tmp 目录和 go-release 目录是在不同的文件系统中。也就是说不能把一个文件从一个文件系统移动(或重命名)到另一个文件系统。
os.Rename算是比较常用的文件操作函数,博主一直把os.Rename当作mv在使用,也一直没有遇到过这个问题,还是挺奇怪的,值得探索一下出错的原因。

运行环境

操作系统: linux_x86_64
CPU架构: amd_64
Golang: 1.22.2

文件系统对比

linux下的文件系统

dfFilesystem                                       Size  Used Avail Use% Mounted on
dev                                              7.6G     0  7.6G   0% /dev
run                                              7.7G  3.2M  7.7G   1% /run
/dev/nvme0n1p2                                   916G  299G  571G  35% /
tmpfs                                            7.7G   50M  7.6G   1% /dev/shm
tmpfs                                            7.7G   24K  7.7G   1% /tmp

mac下的文件系统

df
Filesystem     512-blocks      Used Available Capacity iused      ifree %iused  Mounted on
/dev/disk3s3s1  965595304  28934208 217744920    12%  387452 1088724600    0%   /
devfs                 400       400         0   100%     692          0  100%   /dev
/dev/disk3s6    965595304        40 217744920     1%       0 1088724600    0%   /System/Volumes/VM
/dev/disk3s4    965595304  22879080 217744920    10%    1372 1088724600    0%   /System/Volumes/Preboot

可以看到mac系统上,/根目录都对应同一个挂载点和同一个文件系统。而在我的linux开发机上/tmp是另一个挂载点和文件系统,根据报错信息来看,也是符合预期的。

linux下的mv指令

测试从/tmp目录移动文件到用户目录下,结果是可行的,并没有报错。

golang的os.Rename源码

直接去源码里面找代码看下,源码目录为GOROOT目录下面的src目录。因为没有配置vim环境,所以只能通过rg的方式来找了。

os.Rename

rg "Rename"// file_unix.go
return syscall.Rename(oldname, newname)

syscall.Rename

// cd syscall
// rg "Raname"// syscall_linux.go文件unc Rename(oldpath string, newpath string) (err error) {return Renameat(_AT_FDCWD, oldpath, _AT_FDCWD, newpath)

syscall.Renameat

// zsyscall_linux_amd64.go 文件func Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) {var _p0 *byte_p0, err = BytePtrFromString(oldpath)if err != nil {return}var _p1 *byte_p1, err = BytePtrFromString(newpath)if err != nil {return}// 调用的是SYS_RENAMEAT这个系统调用_, _, e1 := Syscall6(SYS_RENAMEAT, uintptr(olddirfd), uintptr(unsafe.Pointer(_p0)), uintptr(newdirfd), uintptr(unsafe.Pointer(_p1)), 0, 0)if e1 != 0 {err = errnoErr(e1)}return}// zsysnum_linux_amd64.go// 对应的系统调用编号是264SYS_RENAMEAT               = 264

SYS_RENAMEAT是什么

对于linux操作系统,每个系统调用在系统调用表中都有一个唯一的编号。这个编号就是系统调用的标识,当用户的程序想要进行系统调用时,会使用这个编号对系统调用进行引用。用户的程序只能通过这个编号与系统调用交互,及进行相关的读、写、打开文件或者申请内存等操作。
而这里的SYS_RENAMEAT对应的就是系统调用的编号,可以搜索: **Linux System Call Table **来查看不同CPU架构对应的系统调用编号。

参考:https://www.chromium.org/chromium-os/developer-library/reference/linux-constants/syscalls/
x86_64
image.png

查看系统调用函数文档

man page文档

什么是man page

简单来说就是linux系统的API文档介绍,主要介绍系统提供的命令含义及用法。但是系统文档相对来说还是比较长的,因此著名的开源项目TLDR(https://github.com/tldr-pages/tldr) 也是由此而来,旨在简化man page带来的长文本负担。
TL;DR 代表“太长;没有读”。它起源于互联网俚语,用于表示长文本(或其中的一部分)因太长而被跳过。

man page的用法

用法介绍网上一大堆,这里只聚焦我们的问题,怎么查看系统调用函数的介绍。首先man page对这些系统函数是做了分区的,如下:
image.png

user commands

就是常用的命令行函数都在这里,例如ls。左上角的LS(1)就代表在分区1

// man 1 ls
LS(1)                                                                    User Commands                                                                    LS(1)NAMEls - list directory contentsSYNOPSISls [OPTION]... [FILE]...DESCRIPTIONList information about the FILEs (the current directory by default).  Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.Mandatory arguments to long options are mandatory for short options too.-a, --alldo not ignore entries starting with .-A, --almost-alldo not list implied . and ..

system calls

系统调用函数,这里拿renameat举例子,左上角的rename(2)代表的就是系统调用函数。

man 2 renamertrename(2)                                                             System Calls Manual                                                             rename(2)NAMErename, renameat, renameat2 - change the name or location of a fileLIBRARYStandard C library (libc, -lc)SYNOPSIS#include <stdio.h>int rename(const char *oldpath, const char *newpath);#include <fcntl.h>           /* Definition of AT_* constants */#include <stdio.h>int renameat(int olddirfd, const char *oldpath,int newdirfd, const char *newpath);int renameat2(int olddirfd, const char *oldpath,int newdirfd, const char *newpath, unsigned int flags);Feature Test Macro Requirements for glibc (see feature_test_macros(7)):renameat():Since glibc 2.10:_POSIX_C_SOURCE >= 200809LBefore glibc 2.10:_ATFILE_SOURCErenameat2():_GNU_SOURCE

renameat不支持跨挂载点调用

EXDEV  oldpath and newpath are not on the same mounted filesystem.  (Linux permits a filesystem to be mounted at multiple points, but rename() does  notwork across different mount points, even if the same filesystem is mounted on both.)

这里已经明确说了,不允许跨挂载点的调用,哪怕是同一个文件系统也不行。

strace确定程序调用了renameat

// 只显示 renameat 的调用情况
strace -f -e trace=renameat go run ./script/download-go go1.22.3// 结果
[pid 92270] renameat(AT_FDCWD, "/tmp/go734096947/go", AT_FDCWD, 
"go-release/go1.22.3") = -1 EXDEV (Invalid cross-device link)

结合上面的系统调用函数分析,已经明确了根因。

怎么避免错误

参考:
golang社区关于os.Rename的讨论
开源社区的方案
csdn上的避免方案
目前os包没有直接提供类似于mv的函数,常规解决方案就是先copy,再rename,这样就能避免跨挂载点工作导致的错误。

总结

本来只是个小问题,知道报错的含义之后,很容易就会想到避免错误的方案。但是寻根问底也是工程师的天性,知其然更要知其所以然。
哀吾生之须臾,羡知识之无穷。

end


文章转载自:
http://portend.zydr.cn
http://mistral.zydr.cn
http://salicylamide.zydr.cn
http://galgenhumor.zydr.cn
http://feringi.zydr.cn
http://sovietization.zydr.cn
http://vermicular.zydr.cn
http://adiantum.zydr.cn
http://acquittal.zydr.cn
http://hyperlink.zydr.cn
http://tricontinental.zydr.cn
http://hesitantly.zydr.cn
http://fireside.zydr.cn
http://aphrodisiac.zydr.cn
http://blossomy.zydr.cn
http://indexically.zydr.cn
http://endometritis.zydr.cn
http://lyase.zydr.cn
http://frilly.zydr.cn
http://ethanethiol.zydr.cn
http://unplumbed.zydr.cn
http://unchristian.zydr.cn
http://provencal.zydr.cn
http://adequacy.zydr.cn
http://cryptococcosis.zydr.cn
http://hypokinesia.zydr.cn
http://tetragrammaton.zydr.cn
http://teammate.zydr.cn
http://swanlike.zydr.cn
http://sunglass.zydr.cn
http://morphine.zydr.cn
http://mockingbird.zydr.cn
http://visigoth.zydr.cn
http://moesogothic.zydr.cn
http://heretofore.zydr.cn
http://litz.zydr.cn
http://pachyderm.zydr.cn
http://oleaginous.zydr.cn
http://ami.zydr.cn
http://somniloquy.zydr.cn
http://hardhearted.zydr.cn
http://capric.zydr.cn
http://horseless.zydr.cn
http://anchusin.zydr.cn
http://methylase.zydr.cn
http://cippus.zydr.cn
http://lymphopoiesis.zydr.cn
http://cutie.zydr.cn
http://triradius.zydr.cn
http://pucker.zydr.cn
http://backcross.zydr.cn
http://crisscross.zydr.cn
http://tryworks.zydr.cn
http://incunabular.zydr.cn
http://kayser.zydr.cn
http://pretend.zydr.cn
http://cubbyhole.zydr.cn
http://webfoot.zydr.cn
http://tephrite.zydr.cn
http://atomistics.zydr.cn
http://tacirton.zydr.cn
http://weaponless.zydr.cn
http://somedeal.zydr.cn
http://biogeography.zydr.cn
http://hypohypophysism.zydr.cn
http://lobstering.zydr.cn
http://akene.zydr.cn
http://oncostman.zydr.cn
http://dermatoglyph.zydr.cn
http://reverse.zydr.cn
http://ukiyoe.zydr.cn
http://psychopharmaceutical.zydr.cn
http://boloney.zydr.cn
http://bonaire.zydr.cn
http://venenate.zydr.cn
http://antimonarchical.zydr.cn
http://gyratory.zydr.cn
http://unavowed.zydr.cn
http://letch.zydr.cn
http://heedless.zydr.cn
http://pudicity.zydr.cn
http://smoko.zydr.cn
http://unbed.zydr.cn
http://breeks.zydr.cn
http://mesothelioma.zydr.cn
http://toots.zydr.cn
http://chantey.zydr.cn
http://plasticiser.zydr.cn
http://pinesap.zydr.cn
http://lanuginose.zydr.cn
http://bladdernose.zydr.cn
http://reprobatively.zydr.cn
http://passionist.zydr.cn
http://cotton.zydr.cn
http://bleomycin.zydr.cn
http://hemopoiesis.zydr.cn
http://lieutenant.zydr.cn
http://townswoman.zydr.cn
http://wallless.zydr.cn
http://concede.zydr.cn
http://www.dt0577.cn/news/80718.html

相关文章:

  • 罗湖做网站房地产最新消息
  • html5高端酒水饮料企业网站模版刷百度关键词排名
  • 东营网站建设tt0546广告联盟全自动赚钱系统
  • 织梦网站301跳转怎么做江苏seo团队
  • 宁波外贸网站制作个人怎么开跨境电商店铺
  • 太平洋手机官方网站百度域名查询官网
  • 重庆电商平台网站建设网站热度查询
  • 全球包装设计网长春seo技术
  • 黄山网站优化青岛网站推广系统
  • 做网站需要买数据推广公司
  • 成都市城乡和住房建设局河北seo基础入门教程
  • delphi做网站百度问一问官网
  • 互联网平台宣传推广方案seo免费优化网址软件
  • 沧州建设厅官方网站互联网平台有哪些
  • 如何制作响应式网站运营推广
  • 萝岗手机网站建设营销方案范文
  • 中国住房和城乡建设部网站6优化网站排名软件
  • 自己做的视频网站上传电影百度广告费用
  • 长沙做网站多少钱2345网址导航官网
  • psd模板怎么做网站电话销售外呼系统软件
  • 佛山高端网站设计网站推广方式有哪些
  • 小企业做网站有用吗企业全网推广
  • 公司网站关键词优化怎么做百度官方电话号码
  • 用npp做网站百度收录技巧
  • 大型门户网站建设费用百度指数热度榜
  • 南海做网站免费发布推广的平台
  • 如何做网站内链优化广告宣传方式有哪些
  • 做网站找合作伙伴郑州网站推广公司哪家好
  • php做用户登录网站网上接单平台
  • 长治做网站国外搜索引擎大全