Changeset 43083ee in freewrt
- Timestamp:
- Jul 24, 2006, 11:41:20 AM (19 years ago)
- Branches:
- freewrt_1_0, freewrt_2_0
- Children:
- 84a01658
- Parents:
- 846f220
- Location:
- package/configfs
- Files:
-
- 2 edited
-
Makefile (modified) (1 diff)
-
src/configfs.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
package/configfs/Makefile
r846f220 r43083ee 24 24 $(MAKE) -C $(WRKBUILD) \ 25 25 $(TARGET_CONFIGURE_OPTS) \ 26 CFLAGS="- I$(STAGING_DIR)/usr/include" \26 CFLAGS="-D_FILE_OFFSET_BITS=64 -I$(STAGING_DIR)/usr/include" \ 27 27 LDFLAGS="-L$(STAGING_DIR)/usr/lib" 28 28 touch $@ -
package/configfs/src/configfs.c
r846f220 r43083ee 1 int main() { 2 printf("hello world\n"); 3 return 0; 1 /* 2 * configfs.c - wrapper for nvram over fuse filesystem 3 * 4 * Copyright (C) 2006 Joerg Seitter <js@freewrt.org> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 2 9 * of the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 * 20 */ 21 22 23 #include <fuse.h> 24 #include <stdio.h> 25 #include <string.h> 26 #include <errno.h> 27 #include <fcntl.h> 28 29 // needed for nvram 30 #include <typedefs.h> 31 #include <bcmnvram.h> 32 33 static char *name, *value, buf[NVRAM_SPACE]; 34 35 static int nvram_getattr(const char *path, struct stat *stbuf) 36 { 37 int res = 0; 38 39 memset(stbuf, 0, sizeof(struct stat)); 40 if(strcmp(path, "/") == 0) { 41 stbuf->st_mode = S_IFDIR | 0755; 42 stbuf->st_nlink = 2; 43 } 44 // here we have to check if the name exists 45 else if(1) { 46 stbuf->st_mode = S_IFREG | 0444; 47 stbuf->st_nlink = 1; 48 // here we get the size, lets fix it to 42, sad but true ;) 49 stbuf->st_size = 42; 50 } 51 else 52 res = -ENOENT; 53 54 return res; 4 55 } 56 57 static int nvram_readdir(const char *path, void *buf, fuse_fill_dir_t filler, 58 off_t offset, struct fuse_file_info *fi) 59 { 60 (void) offset; 61 (void) fi; 62 63 //here we get the list of all nvram vars 64 nvram_getall(buf,sizeof(buf)); 65 // iterate over one enty 66 // for (name = buf; *name; name += strlen(name) + 1) 67 // PUts_trim_cr(name); 68 // size = sizeof(struct nvram_header) + (int) name - (int) buf; 69 // fprintf(stderr, "size: %d bytes (%d left)\n", size, NVRAM_SPACE - size); 70 71 72 if(strcmp(path, "/") != 0) 73 return -ENOENT; 74 75 filler(buf, ".", NULL, 0); 76 filler(buf, "..", NULL, 0); 77 // here we have to put the list of files 78 filler(buf, "test_file" + 1, NULL, 0); 79 80 return 0; 81 } 82 83 static int nvram_open(const char *path, struct fuse_file_info *fi) 84 { 85 //here we have to check if the file exists 86 if(strcmp(path, "filename") != 0) 87 return -ENOENT; 88 89 if((fi->flags & 3) != O_RDONLY) 90 return -EACCES; 91 92 return 0; 93 } 94 95 static int nvram_read(const char *path, char *buf, size_t size, off_t offset, 96 struct fuse_file_info *fi) 97 { 98 size_t len; 99 (void) fi; 100 //here we check if the file exists 101 if(strcmp(path, "filename") != 0) 102 return -ENOENT; 103 104 // here we put the value of the variable 105 len = strlen("this is the value"); 106 if (offset < len) { 107 if (offset + size > len) 108 size = len - offset; 109 //here we copy the content 110 memcpy(buf, "this is the value" + offset, size); 111 } else 112 size = 0; 113 114 return size; 115 } 116 117 // no write is implemented yet 118 static struct fuse_operations nvram_oper = { 119 .getattr = nvram_getattr, 120 .readdir = nvram_readdir, 121 .open = nvram_open, 122 .read = nvram_read, 123 }; 124 125 int main(int argc, char *argv[]) 126 { 127 return fuse_main(argc, argv, &nvram_oper); 128 }
Note:
See TracChangeset
for help on using the changeset viewer.
