FreeBSD Bugzilla – Attachment 246324 Details for
Bug 275099
cat(1) can't read directories
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
helloworld-dir.c
helloworld-dir.c (text/x-csrc), 1.94 KB, created by
WHR
on 2023-11-15 06:19:57 UTC
(
hide
)
Description:
helloworld-dir.c
Filename:
MIME Type:
Creator:
WHR
Created:
2023-11-15 06:19:57 UTC
Size:
1.94 KB
patch
obsolete
>/* This file has no copyright assigned and is placed in the Public Domain. > * No warranty is given. > */ > >#define FUSE_USE_VERSION 26 >#include <fuse.h> >#include <errno.h> >#include <string.h> > >#define STRING1 "This is the root directory\n" >#define STRING2 "Hello world!\n" >#define STRING3 "Hello world\n" > >static int isdir_getattr(const char *path, struct stat *stbuf) { > if(strcmp(path, "/hello/world") == 0) { > stbuf->st_mode = S_IFREG | 0644; > stbuf->st_nlink = 1; > stbuf->st_size = sizeof STRING3 - 1; > } else if(strcmp(path, "/hello") == 0) { > stbuf->st_mode = S_IFDIR | 0755; > stbuf->st_nlink = 2; > stbuf->st_size = sizeof STRING2 - 1; > } else if(strcmp(path, "/") == 0) { > stbuf->st_mode = S_IFDIR | 0755; > stbuf->st_nlink = 2; > stbuf->st_size = sizeof STRING1 - 1; > } else { > return -ENOENT; > } > return 0; >} > >static int isdir_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) { > if(strcmp(path, "/hello") == 0) { > filler(buf, ".", NULL, 0); > filler(buf, "..", NULL, 0); > filler(buf, "world", NULL, 0); > } else if(strcmp(path, "/") == 0) { > filler(buf, ".", NULL, 0); > filler(buf, "hello", NULL, 0); > } else { > return -ENOENT; > } > return 0; >} > >static int isdir_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { > const char *p; > size_t length; > if(strcmp(path, "/hello/world") == 0) { > p = STRING3; > length = sizeof STRING3 - 1; > } else if(strcmp(path, "/hello") == 0) { > p = STRING2; > length = sizeof STRING2 - 1; > } else if(strcmp(path, "/") == 0) { > p = STRING1; > length = sizeof STRING1 - 1; > } else { > return -ENOENT; > } > if(offset >= length) return 0; > if(offset + size > length) size = length - offset; > memcpy(buf, p + offset, size); > return size; >} > >static struct fuse_operations isdir_oper = { > .getattr = isdir_getattr, > .readdir = isdir_readdir, > .read = isdir_read, >}; > >int main(int argc, char **argv) { > return fuse_main(argc, argv, &isdir_oper, NULL); >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 275099
: 246324 |
246325