PageSourceSearch

https://photonlibos.github.io/cn/assets/js/eb5b3750.39a509ec.js

js photonlibos.github.io collected 2026-10-03 09:46:54 UTC 7,617 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkphoton_website=self.webpackChunkphoton_website||[]).push([[6306],{2561:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>f,contentTitle:()=>a,default:()=>u,frontMatter:()=>r,metadata:()=>s,toc:()=>l});var i=n(8168),o=(n(6540),n(5680));const r={sidebar_position:5,toc_max_heading_level:4},a="\u6587\u4ef6\u7cfb\u7edf\u548cIO",s={unversionedId:"api/filesystem-and-io",id:"api/filesystem-and-io",title:"\u6587\u4ef6\u7cfb\u7edf\u548cIO",description:"Photon \u5bf9 file \u548c fs \u6709 POSIX \u517c\u5bb9\u7684\u5c01\u88c5\u3002\u5f53\u7136\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u662f\u5426\u4f7f\u7528\u8fd9\u5957\u5c01\u88c5\u3002",source:"@site/i18n/cn/docusaurus-plugin-content-docs/current/api/filesystem-and-io.md",sourceDirName:"api",slug:"/api/filesystem-and-io",permalink:"/cn/docs/api/filesystem-and-io",draft:!1,editUrl:"https://github.com/alibaba/PhotonLibOS/edit/main/doc/docs/api/filesystem-and-io.md",tags:[],version:"current",sidebarPosition:5,frontMatter:{sidebar_position:5,toc_max_heading_level:4},sidebar:"docSidebar",previous:{title:"\u9501\u548c\u540c\u6b65\u539f\u8bed",permalink:"/cn/docs/api/lock-and-synchronization"},next:{title:"\u7f51\u7edc",permalink:"/cn/docs/api/network"}},f={},l=[{value:"Namespace",id:"namespace",level:4},{value:"1. \u4f7f\u7528\u5c01\u88c5",id:"1-\u4f7f\u7528\u5c01\u88c5",level:3},{value:"localfs",id:"localfs",level:4},{value:"fusefs",id:"fusefs",level:4},{value:"cachefs",id:"cachefs",level:4},{value:"2. \u4f7f\u7528\u88f8API",id:"2-\u4f7f\u7528\u88f8api",level:3},{value:"aio",id:"aio",level:4},{value:"io_uring",id:"io_uring",level:4}],c={toc:l},p="wrapper";function u({components:e,...t}){return(0,o.yg)(p,(0,i.A)({},c,t,{components:e,mdxType:"MDXLayout"}),(0,o.yg)("h1",{id:"\u6587\u4ef6\u7cfb\u7edf\u548cio"},"\u6587\u4ef6\u7cfb\u7edf\u548cIO"),(0,o.yg)("p",null,"Photon \u5bf9 file \u548c fs \u6709 POSIX \u517c\u5bb9\u7684\u5c01\u88c5\u3002\u5f53\u7136\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u662f\u5426\u4f7f\u7528\u8fd9\u5957\u5c01\u88c5\u3002"),(0,o.yg)("h4",{id:"namespace"},"Namespace"),(0,o.yg)("p",null,(0,o.yg)("inlineCode",{parentName:"p"},"photon::fs::")),(0,o.yg)("h3",{id:"1-\u4f7f\u7528\u5c01\u88c5"},"1. \u4f7f\u7528\u5c01\u88c5"),(0,o.yg)("h4",{id:"localfs"},"localfs"),(0,o.yg)("p",null,(0,o.yg)("inlineCode",{parentName:"p"},"<photon/fs/localfs.h>")),(0,o.yg)("pre",null,(0,o.yg)("code",{parentName:"pre",className:"language-cpp"},'auto fs = photon::fs::new_localfs_adaptor(".", photon::fs::ioengine_psync);\nif (!fs) {\n    LOG_ERRNO_RETURN(0, -1, "failed to create fs");\n}\nDEFER(delete fs);\n\nauto file = fs->open("test-file", O_WRONLY | O_CREAT | O_TRUNC, 0644);\nif (!file) {\n    LOG_ERRNO_RETURN(0, -1, "failed to open file");\n}\nDEFER(delete file);\n\nssize_t n_written = file->write(buf, 4096);\n')),(0,o.yg)("h4",{id:"fusefs"},"fusefs"),(0,o.yg)("h4",{id:"cachefs"},"cachefs"),(0,o.yg)("p",null,"\u5f85\u8865\u5145..."),(0,o.yg)("h3",{id:"2-\u4f7f\u7528\u88f8api"},"2. \u4f7f\u7528\u88f8API"),(0,o.yg)("h4",{id:"aio"},"aio"),(0,o.yg)("p",null,(0,o.yg)("inlineCode",{parentName:"p"},"<photon/io/aio-wrapper.h>")),(0,o.yg)("p",null,"\u652f\u6301 libaio \u548c posixaio."),(0,o.yg)("pre",null,(0,o.yg)("code",{parentName:"pre",className:"language-cpp"},"// fd \u5fc5\u987b\u7528 O_DIRECT \u6253\u5f00, \u5e76\u4e14\u5185\u5b58\u5fc5\u987b\u5bf9\u9f50\nssize_t libaio_pread(int fd, void *buf, size_t count, off_t offset);\nssize_t libaio_preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset);\nssize_t libaio_pwrite(int fd, const void *buf, size_t count, off_t offset);\nssize_t libaio_pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset);\nstatic int libaio_fsync(int fd) { return 0; }\n\nssize_t posixaio_pread(int fd, void *buf, size_t count, off_t offset);\nssize_t posixaio_pwrite(int fd, const void *buf, size_t count, off_t offset);\nint posixaio_fsync(int fd);\nint posixaio_fdatasync(int fd);\n")),(0,o.yg)("h4",{id:"io_uring"},"io_uring"),(0,o.yg)("p",null,(0,o.yg)("inlineCode",{parentName:"p"},"<photon/io/iouring-wrapper.h>")),(0,o.yg)("pre",null,(0,o.yg)("code",{parentName:"pre",className:"language-cpp"},"ssize_t iouring_pread(int fd, void* buf, size_t count, off_t offset, uint64_t timeout);\nssize_t iouring_pwrite(int fd, const void* buf, size_t count, off_t offset, uint64_t timeout);\nssize_t iouring_preadv(int fd, const iovec* iov, int iovcnt, off_t offset, uint64_t timeout);\nssize_t iouring_pwritev(int fd, const iovec* iov, int iovcnt, off_t offset, uint64_t timeout);\nssize_t iouring_send(int fd, const void* buf, size_t len, int flags, uint64_t timeout);\nssize_t iouring_recv(int fd, void* buf, size_t len, int flags, uint64_t timeout);\nssize_t iouring_sendmsg(int fd, const msghdr* msg, int flags, uint64_t timeout);\nssize_t iouring_recvmsg(int fd, msghdr* msg, int flags, uint64_t timeout);\nint iouring_connect(int fd, const sockaddr* addr, socklen_t addrlen, uint64_t timeout);\nint iouring_accept(int fd, sockaddr* addr, socklen_t* addrlen, uint64_t timeout);\nint iouring_fsync(int fd);\nint iouring_fdatasync(int fd);\nint iouring_open(const char* path, int flags, mode_t mode);\nint iouring_mkdir(const char* path, mode_t mode);\nint iouring_close(int fd);\n")),(0,o.yg)("admonition",{type:"note"},(0,o.yg)("p",{parentName:"admonition"},"io_uring \u7684\u4e8b\u4ef6\u5f15\u64ce\u5fc5\u987b\u5728 ",(0,o.yg)("a",{parentName:"p",href:"./env#init"},"Env")," \u73af\u5883\u91cc\u6b63\u786e\u521d\u59cb\u5316")))}u.isMDXComponent=!0},5680:(e,t,n)=>{n.d(t,{xA:()=>c,yg:()=>_});var i=n(6540);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function a(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};
1t%2?r(Object(n),!0).forEach((function(t){o(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function s(e,t){if(null==e)return{};var n,i,o=function(e,t){if(null==e)return{};var n,i,o={},r=Object.keys(e);for(i=0;i<r.length;i++)n=r[i],t.indexOf(n)>=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(i=0;i<r.length;i++)n=r[i],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var f=i.createContext({}),l=function(e){var t=i.useContext(f),n=t;return e&&(n="function"==typeof e?e(t):a(a({},t),e)),n},c=function(e){var t=l(e.components);return i.createElement(f.Provider,{value:t},e.children)},p="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return i.createElement(i.Fragment,{},t)}},d=i.forwardRef((function(e,t){var n=e.components,o=e.mdxType,r=e.originalType,f=e.parentName,c=s(e,["components","mdxType","originalType","parentName"]),p=l(n),d=o,_=p["".concat(f,".").concat(d)]||p[d]||u[d]||r;return n?i.createElement(_,a(a({ref:t},c),{},{components:n})):i.createElement(_,a({ref:t},c))}));function _(e,t){var n=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var r=n.length,a=new Array(r);a[0]=d;var s={};for(var f in t)hasOwnProperty.call(t,f)&&(s[f]=t[f]);s.originalType=e,s[p]="string"==typeof e?e:o,a[1]=s;for(var l=2;l<r;l++)a[l]=n[l];return i.createElement.apply(null,a)}return i.createElement.apply(null,n)}d.displayName="MDXCreateElement"}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.