problem in adding an extra entry in a dir:fuse imlementation


 
Thread Tools Search this Thread
Operating Systems Linux problem in adding an extra entry in a dir:fuse imlementation
# 1  
Old 01-24-2008
problem in adding an extra entry in a dir:fuse imlementation

Well the problem comes when i try to add an extra file into the existing filesystem mounted at some mountpoint containing a single file hello.
suppose i add a file say "TANVIR"(c it on d line next to line no:49) ,
it gives me abnormal results......
like 1)d file can't be opened
2)no file exists....

help me out if ne 1 has used fuse......Smilie




00001 /*
00002 FUSE: Filesystem in Userspace
00003 Copyright (C) 2001-2005 Miklos Szeredi <miklos@szeredi.hu>
00004
00005 This program can be distributed under the terms of the GNU GPL.
00006 See the file COPYING.
00007 */
00008
00009 #include <fuse.h>
00010 #include <stdio.h>
00011 #include <string.h>
00012 #include <errno.h>
00013 #include <fcntl.h>
00014
00015 static const char *hello_str = "Hello World!\n";
00016 static const char *hello_path = "/hello";
00017
00018 static int hello_getattr(const char *path, struct stat *stbuf)
00019 {
00020 int res = 0;
00021
00022 memset(stbuf, 0, sizeof(struct stat));
00023 if(strcmp(path, "/") == 0) {
00024 stbuf->st_mode = S_IFDIR | 0755;
00025 stbuf->st_nlink = 2;
00026 }
00027 else if(strcmp(path, hello_path) == 0) {
00028 stbuf->st_mode = S_IFREG | 0444;
00029 stbuf->st_nlink = 1;
00030 stbuf->st_size = strlen(hello_str);
00031 }
0032 else if(strcmp(path,"TANVIR")==0){
stbuf->st_mode = S_IFREG | 0444;
stbuf->st_nlink = 1;
stbuf->st_size = 10;

{
else

00033 res = -ENOENT;
00034
00035 return res;
00036 }
00037
00038 static int hello_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
00039 off_t offset, struct fuse_file_info *fi)
00040 {
00041 (void) offset;
00042 (void) fi;
00043
00044 if(strcmp(path, "/") != 0)
00045 return -ENOENT;
00046
00047 filler(buf, ".", NULL, 0);
00048 filler(buf, "..", NULL, 0);
00049 filler(buf, hello_path + 1, NULL, 0);
**** filler(buf,"TANVIR",NULL,0);//when i add dis statement
00050
00051 return 0;
00052 }
00053
00054 static int hello_open(const char *path, struct fuse_file_info *fi)
00055 {
00056 /* if(strcmp(path, hello_path) != 0)
00057 return -ENOENT;
00058
00059 if((fi->flags & 3) != O_RDONLY)
00060 return -EACCES;*/
00061
00062 return 0;
00063 }
00064
00065 static int hello_read(const char *path, char *buf, size_t size, off_t offset,
00066 struct fuse_file_info *fi)
00067 {
00068 size_t len;
00069 (void) fi;
00070 if(strcmp(path, hello_path) != 0)
00071 return -ENOENT;
00072
00073 len = strlen(hello_str);
00074 if (offset < len) {
00075 if (offset + size > len)
00076 size = len - offset;
00077 memcpy(buf, hello_str + offset, size);
00078 } else
00079 size = 0;
00080
00081 return size;
00082 }
00083
00084 static struct fuse_operations hello_oper = {
00085 .getattr = hello_getattr,
00086 .readdir = hello_readdir,
00087 .open = hello_open,
00088 .read = hello_read,
00089 };
00090
00091 int main(int argc, char *argv[])
00092 {
00093 return fuse_main(argc, argv, &hello_oper);
00094 }
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Adding an extra date column in UNIX file

Hi All, I have a file with only one column of data (without delimiter). For Ex: cat temp.txt 22055 21088 93840 30990 50990 50950 I want to insert an additional column with current date as value. So, i have used below command but didn't get the result as excepted. Could onyone over... (5 Replies)
Discussion started by: Suresh
5 Replies

2. UNIX for Dummies Questions & Answers

Sendmail with cat adding extra spaces in email body

when I try to read a file and send email using cat and sendmail: The email received having additional spaces.(Between the letters of words in the text) My code: export MAILTO="sa@y.com" export SUBJECT="mydomain PREPROD MONITOR AT ${DATE}" export... (5 Replies)
Discussion started by: visitsany
5 Replies

3. Shell Programming and Scripting

Need help in column comparison & adding extra line to files

Hi, I wanted to check whether the x,y,z coordinates of two files are equal or not. At times, when one file is converted to another suitable file extension , there are some chances that the data mismatch would happen during the conversion. In order to avoid the data misfit, i would like to... (6 Replies)
Discussion started by: b@l@ji
6 Replies

4. Shell Programming and Scripting

Bash shell adding extra single quotes

AIX 6.1 bash shell #!/bin/bash -x STATEMENT="cvs commit -m \"This is\" ../PBP/EIR.ENTRY" echo $STATEMENT exit 0 This is the output + STATEMENT='cvs commit -m "This is" ../PBP/EIR.ENTRY' + echo cvs commit -m '"This' 'is"' ../PBP/EIR.ENTRY cvs commit -m "This is" ../PBP/EIR.ENTRY + exit... (26 Replies)
Discussion started by: hpodhrad
26 Replies

5. Shell Programming and Scripting

Adding Extra Commas to a CSV file

Trying in this forum. Not sure if it is permitted.... but in need of help. Please find the requirements in the below link. https://www.unix.com/unix-dummies-questions-answers/191503-add-extra-commas-csv-file-2.html#post302665179 Thanks in Advance. (1 Reply)
Discussion started by: chillblue
1 Replies

6. Shell Programming and Scripting

Adding extra word from file1 to file2

I need to add a word from file1 to file2 accordinggly... file1 contains name of servers and file2 version of server I need that information in a single file so that the format is server_name : version I been trying but havent been able to figure out how to search for a file using sed... ... (14 Replies)
Discussion started by: eponcedeleonc
14 Replies

7. Solaris

Adding Extra Hard Disk

Hi Solaris users - I have an Ultra10 SPARC machine, with IIe processor. To prepare for the Solaris10 admin exam PartII I need to set up the metadb/mirroring in my machine, but do not know how to do this properly. I need this to practice the mirroring tasks. If anyone could help it would be... (3 Replies)
Discussion started by: patcom
3 Replies

8. Shell Programming and Scripting

sort file adding extra character

HI all i have this script : #!/bin/bash sort /usr/tmp/"REPORT"$1 -o \ /usr/tmp/"SREPORT"$1 -k 1,7 -S 150 end of script now i'm doing this command : ls -lsgt *REPORT* 4 -rw-r--r-- 300 Sep 16 REPORT54784 4 -rw-r--r-- 301 Sep 16 SREPORT54784 as you can see the sorted file... (5 Replies)
Discussion started by: naamas03
5 Replies

9. UNIX and Linux Applications

CPIO Problem, copy to the root dir / instead of current dir

HI all, I got a CPIO archive that contains a unix filesystem that I try to extract, but it extract to the root dir / unstead of current dir, and happily it detects my file are newer otherwise it would have overwrited my system's file! I tried all these commands cpio -i --make-directories <... (2 Replies)
Discussion started by: nekkro-kvlt
2 Replies

10. IP Networking

Adding an extra route to the ip routing table

In my college dorm, there is a file sharing network in the entire building. Problem is, there is only a manual for windows with the settings on how to connect... :mad: They say that you have to give the following command in cmd in windows: route add 172.16.71.0 mask 255.255.255.0... (2 Replies)
Discussion started by: Japie89
2 Replies
Login or Register to Ask a Question

Featured Tech Videos