uefi 下面没有单独的rename, 只有mv

一句话总结,同一个文件系统里面,改文件info 就行了。见代码中汉字注释部分

/**function to take a list of files to move and a destination location and dothe verification and moving of those files to that location.  This functionwill report any errors to the user and continue to move the rest of the files.@param[in] FileList           A LIST_ENTRY* based list of files to move@param[out] Resp              pointer to response from question.  Pass back on looped calling@param[in] DestParameter      the originally specified destination location@retval SHELL_SUCCESS             the files were all moved.@retval SHELL_INVALID_PARAMETER   a parameter was invalid@retval SHELL_SECURITY_VIOLATION  a security violation ocurred@retval SHELL_WRITE_PROTECTED     the destination was write protected@retval SHELL_OUT_OF_RESOURCES    a memory allocation failed
**/
SHELL_STATUS
ValidateAndMoveFiles(IN EFI_SHELL_FILE_INFO        *FileList,OUT VOID                      **Resp,IN CONST CHAR16               *DestParameter)
{EFI_STATUS                Status;CHAR16                    *HiiOutput;CHAR16                    *HiiResultOk;CHAR16                    *DestPath;CHAR16                    *FullDestPath;CONST CHAR16              *Cwd;CHAR16                    *FullCwd;SHELL_STATUS              ShellStatus;EFI_SHELL_FILE_INFO       *Node;VOID                      *Response;UINT64                    Attr;CHAR16                    *CleanFilePathStr;ASSERT(FileList != NULL);ASSERT(DestParameter  != NULL);DestPath          = NULL;FullDestPath      = NULL;Cwd               = ShellGetCurrentDir(NULL);Response          = *Resp;Attr              = 0;CleanFilePathStr  = NULL;FullCwd           = NULL;if (Cwd != NULL) {
    FullCwd = AllocateZeroPool(StrSize(Cwd) + sizeof(CHAR16));  
给 FullCwd 分配内存if (FullCwd == NULL) {return SHELL_OUT_OF_RESOURCES;} else {StrCpyS(FullCwd, StrSize(Cwd)/sizeof(CHAR16)+1, Cwd);StrCatS(FullCwd, StrSize(Cwd)/sizeof(CHAR16)+1, L"\\");}} 此时, FullCwd 类似这个样子 F.S.0.:.\Status = ShellLevel2StripQuotes (DestParameter, &CleanFilePathStr);if (EFI_ERROR (Status)) {SHELL_FREE_NON_NULL(FullCwd);if (Status == EFI_OUT_OF_RESOURCES) {return SHELL_OUT_OF_RESOURCES;} else {return SHELL_INVALID_PARAMETER;}}ASSERT (CleanFilePathStr != NULL);//// Get and validate the destination location//
获得并且验证目标位置ShellStatus = GetDestinationLocation(CleanFilePathStr, &DestPath, FullCwd, (BOOLEAN)(FileList->Link.ForwardLink == FileList->Link.BackLink), &Attr);FreePool (CleanFilePathStr);if (ShellStatus != SHELL_SUCCESS) {SHELL_FREE_NON_NULL (FullCwd);return (ShellStatus);}DestPath = PathCleanUpDirectories(DestPath);
 目标path 取值类似这个样子: F.S.0.:.\.a...t.x.tif (DestPath == NULL) {FreePool (FullCwd);return (SHELL_OUT_OF_RESOURCES);}HiiOutput   = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_MV_OUTPUT), NULL);HiiResultOk = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_GEN_RES_OK), NULL);if (HiiOutput == NULL || HiiResultOk == NULL) {SHELL_FREE_NON_NULL(DestPath);SHELL_FREE_NON_NULL(HiiOutput);SHELL_FREE_NON_NULL(HiiResultOk);SHELL_FREE_NON_NULL(FullCwd);return (SHELL_OUT_OF_RESOURCES);}//// Go through the list of files and directories to move...//for (Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&FileList->Link);  !IsNull(&FileList->Link, &Node->Link);  Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&FileList->Link, &Node->Link)){if (ShellGetExecutionBreakFlag()) {break;}//// These should never be NULL//ASSERT(Node->FileName != NULL);ASSERT(Node->FullName != NULL);ASSERT(Node->Info     != NULL);//// skip the directory traversing stuff...//if (StrCmp(Node->FileName, L".") == 0 || StrCmp(Node->FileName, L"..") == 0) {continue;}SHELL_FREE_NON_NULL(FullDestPath);FullDestPath = NULL;if (ShellIsDirectory(DestPath)==EFI_SUCCESS) {CreateFullDestPath((CONST CHAR16 **)&DestPath, &FullDestPath, Node->FileName);}//// Validate that the move is valid//if (!IsValidMove(Node->FullName, FullCwd, FullDestPath!=NULL? FullDestPath:DestPath, Node->Info->Attribute, Attr, Node->Status)) {ShellStatus = SHELL_INVALID_PARAMETER;continue;}ShellPrintEx(-1, -1, HiiOutput, Node->FullName, FullDestPath!=NULL? FullDestPath:DestPath);//// See if destination exists//if (!EFI_ERROR(ShellFileExists(FullDestPath!=NULL? FullDestPath:DestPath))) {if (Response == NULL) {ShellPromptForResponseHii(ShellPromptResponseTypeYesNoAllCancel, STRING_TOKEN (STR_GEN_DEST_EXIST_OVR), gShellLevel2HiiHandle, &Response);}switch (*(SHELL_PROMPT_RESPONSE*)Response) {case ShellPromptResponseNo:FreePool(Response);Response = NULL;continue;case ShellPromptResponseCancel:*Resp = Response;//// indicate to stop everything//SHELL_FREE_NON_NULL(FullCwd);return (SHELL_ABORTED);case ShellPromptResponseAll:*Resp = Response;break;case ShellPromptResponseYes:FreePool(Response);Response = NULL;break;default:FreePool(Response);SHELL_FREE_NON_NULL(FullCwd);return SHELL_ABORTED;}Status = ShellDeleteFileByName(FullDestPath!=NULL? FullDestPath:DestPath);}if (IsBetweenFileSystem(Node->FullName, FullCwd, DestPath)) {while (FullDestPath == NULL && DestPath != NULL && DestPath[0] != CHAR_NULL && DestPath[StrLen(DestPath) - 1] == L'\\') {DestPath[StrLen(DestPath) - 1] = CHAR_NULL;}Status = MoveBetweenFileSystems(Node, FullDestPath!=NULL? FullDestPath:DestPath, &Response);} else {
重点就在这里,其实现在同名文件 mv.c Status = MoveWithinFileSystems(Node, DestPath, &Response);//// Display error status//if (EFI_ERROR(Status)) {ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, L"mv", Status);}}//// Check our result//if (EFI_ERROR(Status)) {ShellStatus = SHELL_INVALID_PARAMETER;if (Status == EFI_SECURITY_VIOLATION) {ShellStatus = SHELL_SECURITY_VIOLATION;} else if (Status == EFI_WRITE_PROTECTED) {ShellStatus = SHELL_WRITE_PROTECTED;} else if (Status == EFI_OUT_OF_RESOURCES) {ShellStatus = SHELL_OUT_OF_RESOURCES;} else if (Status == EFI_DEVICE_ERROR) {ShellStatus = SHELL_DEVICE_ERROR;} else if (Status == EFI_ACCESS_DENIED) {ShellStatus = SHELL_ACCESS_DENIED;}} else {ShellPrintEx(-1, -1, L"%s", HiiResultOk);}} // main for loopSHELL_FREE_NON_NULL(FullDestPath);SHELL_FREE_NON_NULL(DestPath);SHELL_FREE_NON_NULL(HiiOutput);SHELL_FREE_NON_NULL(HiiResultOk);SHELL_FREE_NON_NULL(FullCwd);return (ShellStatus);
}
/**Function to do a move within a file system.@param[in] Node               A pointer to the file to be removed.@param[in] DestPath           A pointer to the destination file path.@param[out] Resp              A pointer to response from question.  Pass back on looped calling.@retval SHELL_SUCCESS           The source file was moved to the destination.@retval SHELL_OUT_OF_RESOURCES  A memory allocation failed.
**/
EFI_STATUS
MoveWithinFileSystems(IN EFI_SHELL_FILE_INFO  *Node,IN CHAR16               *DestPath,OUT VOID                **Resp)
{EFI_FILE_INFO             *NewFileInfo;CHAR16                    *TempLocation;UINTN                     NewSize;UINTN                     Length;EFI_STATUS                Status;//// Chop off map info from DestPath//if ((TempLocation = StrStr(DestPath, L":")) != NULL) {CopyMem(DestPath, TempLocation+1, StrSize(TempLocation+1));}//// construct the new file info block//NewSize = StrSize(DestPath);NewSize += StrSize(Node->FileName) + SIZE_OF_EFI_FILE_INFO + sizeof(CHAR16);NewFileInfo = AllocateZeroPool(NewSize);if (NewFileInfo == NULL) {ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellLevel2HiiHandle);Status = EFI_OUT_OF_RESOURCES;} else {CopyMem(NewFileInfo, Node->Info, SIZE_OF_EFI_FILE_INFO);if (DestPath[0] != L'\\') {StrCpyS(NewFileInfo->FileName, (NewSize - SIZE_OF_EFI_FILE_INFO) / sizeof(CHAR16), L"\\");StrCatS(NewFileInfo->FileName, (NewSize - SIZE_OF_EFI_FILE_INFO) / sizeof(CHAR16), DestPath);} else {StrCpyS(NewFileInfo->FileName, (NewSize - SIZE_OF_EFI_FILE_INFO) / sizeof(CHAR16), DestPath);
这句话给文件赋予了新的名字。
    }Length = StrLen(NewFileInfo->FileName);if (Length > 0) {Length--;}if (NewFileInfo->FileName[Length] == L'\\') {if (Node->FileName[0] == L'\\') {//// Don't allow for double slashes. Eliminate one of them.//NewFileInfo->FileName[Length] = CHAR_NULL;}StrCatS(NewFileInfo->FileName, (NewSize - SIZE_OF_EFI_FILE_INFO) / sizeof(CHAR16), Node->FileName);}NewFileInfo->Size = SIZE_OF_EFI_FILE_INFO + StrSize(NewFileInfo->FileName);//// Perform the move operation//Status = ShellSetFileInfo(Node->Handle, NewFileInfo);//// Free the info object we used...//FreePool(NewFileInfo);}return (Status);
}

ps:

FileFunctionMap  所有函数实现在UefiFileHandleLib.c

uefi mv a.txt b.txt 是如何做到的? 即同一个文件系统内如何实现重命名相关推荐

  1. linux 移动重命名 mv 命令简介

    1.mv命令的语法格式 SYNOPSISmv [OPTION]... [-T] SOURCE DESTmv [OPTION]... SOURCE... DIRECTORYmv [OPTION]... ...

  2. Ubuntu下批量重命名图片并将路径写入txt文件

    一.批量重命名图片 在图片所在的文件夹中,创建rename.txt文件,在文件中写入如下内容,并根据注释要求按需更改图片数量和格式: > #!/bin/bash > i=130;#文件夹里 ...

  3. python的txt、csv、ini、xml、excel文件相关操作

    python的txt.csv.ini.xml.excel文件相关操作 函数,一个用于专门实现某个功能的代码块(可重用) 内置函数 len.bin.oct.hex 等 自定义函数 # 定义了一个函数,功 ...

  4. shell,给你一个目录,里面有很多文件,把他们改成 1.txt 2.txt 3.txt ....以此类推、盗墓者是个丑奴儿

    //盗墓者是个丑奴儿,原 //博主个人网站 :https://daomu.kaige123.com //打完一波小广告,进入正题 #!/bin/sh #1.txt,2.txt,3.txt....申请修 ...

  5. 生成Yolox检测负样本-对应空文件夹txt、批量文件重命名、批量转化三通道去除小图

    1.生成Yolox检测负样本-对应空文件夹txt import os.path import cv2 from tqdm import tqdmpath = r"G:\pachong\fuy ...

  6. 自己建文件111 txt python_这可能是最详细的Python文件操作

    删除 # ==================删除================== # 只能删除文件,若为目录则报错 # 若文件正在使用,Windows下会直接报错,Linux下会在目录表中删除记 ...

  7. Prn.txt Con.txt(文件命名的问题)

    Prn.txt Con.txt较特殊,一般的文本操作时,不要用这些文件名. Prn表示打印端口,con表示串口.

  8. 用两个文件a.txt;b.txt.使用linux命令,复制,a.txt文档倒数第十行的记录to b.txt文档

    用两个文件a.txt;b.txt.使用linux命令,复制,a.txt文档倒数第十行的记录to b.txt文档 tail -n 10 a.txt | head -n 1 >> b.txt

  9. python读取多个文件夹下所有txt_Python实现合并同一个文件夹下所有txt文件的方法示例...

    本文实例讲述了Python实现合并同一个文件夹下所有txt文件的方法.分享给大家供大家参考,具体如下: 一.需求分析 合并一个文件夹下所有txt文件 二.合并效果 三.python实现代码 # -*- ...

  10. python合并文件夹下的文件_Python实现合并同一个文件夹下所有txt文件的方法示例...

    本文实例讲述了Python实现合并同一个文件夹下所有txt文件的方法.分享给大家供大家参考,具体如下: 一.需求分析 合并一个文件夹下所有txt文件 二.合并效果 三.python实现代码 # -*- ...

最新文章

  1. python程序员搞笑段子_程序员才能看得懂的段子,内含表情包,吃饭的时候别点!...
  2. 任务调度框架Quartz基本介绍
  3. 【Log4j日志输出】控制台输出、输出到文件:简单使用示例
  4. mysql 列合并_mysql 列转行,合并字段的方法(必看)
  5. pythonpy文件打包成exe软件
  6. 【文献阅读】Self-Normalizing Neural Networks
  7. Python 连接开放航空交通数据,轻松构建航班跟踪应用!
  8. Windows Azure 社区新闻综述(#78 版)
  9. Linux 学习记录
  10. 小心Java中封装类的值比较
  11. 微信开发者工具下载、安装、配置HBuilder运行微信小程序教程(官网)
  12. 米思齐MT1637简单显示字符串和时间
  13. Anaconda Clean命令
  14. html半圆形,【实例】CSS3画一个半圆的方法
  15. Python 透视表
  16. 泛型---上界通配符和下界通配符
  17. kubevirt 存储 网络 监控
  18. Centos7 合理分配 swap空间
  19. 亿美软通一键登录升级:扩大适用范围、更高安全保障
  20. 阿里的敏捷组织和中台策略有何不同?

热门文章

  1. HttpClient 连接无法释放问题
  2. 十六进制、八进制、二进制与十进制的关系
  3. vant 时间选择的用法
  4. jsonp实战——换一换功能实现和时间戳的使用
  5. 函授c语言题库,函授C语言程序设计自学复习题..doc
  6. 磺酸钙的全球与中国市场2022-2028年:技术、参与者、趋势、市场规模及占有率研究报告
  7. A16z:需要监管的应是 Web3 应用,而非协议
  8. 如何利用网络来提升公司业绩?
  9. 教师计算机水平比赛评分表,信息化教学设计比赛评分标准.doc
  10. 真菜鸡的保研之路(从未设想之路)