Include ext4.h in C program - c

I'm trying to create a little program that can read the ext4 filesystem, and for that i need to use all the structures that are defined in the ext4.h file.
Problem is, that this file includes a set of kernel headers such as
#include <linux/blkdev.h>
#include <linux/magic.h>
#include <linux/jbd2.h>
#include <linux/quota.h>
#include <linux/rwsem.h>
#include <linux/rbtree.h>
#include <linux/seqlock.h>
#include <linux/mutex.h>
#include <linux/timer.h>
#include <linux/version.h>
... and more
I've installed the kernel headers using:
$ apt search linux-headers-$(uname -r)
So now i have them in /usr/src/linux-headers-5.4.../include and i try to compile my program with -I /path/to/kernel-headers but now it seems that there're headers included in those headers that it can't find such as asm/current.h which in my filesystem is asm-generic/current.h
Do someone that ever did something like this can help me?

I suggest you take a look at e2fsprogs. This is the user-space toolset for manipulating ext2/3/4 filesystems, and it contains a userspace implementation of the filesystem you can adapt.

Related

What is the necessary header file for prvGetInterruptControllerInstance() function in FreeRTOS?

I am trying to link the interrupt of the fpga to FreeRTOS in zedboard. When I write the code:
InterruptController = (XScuGic *)prvGetInterruptControllerInstance();
I get an error from Xilinx SDK said:
undefined reference to `prvGetInterruptControllerInstance'
May I know what is the necessary include header file to use that function? I tried to search online and I have the same header file included:
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "task.h"
#include "queue.h"
#include "timers.h"
#include "semphr.h"
/* Xilinx includes. */
#include "xil_printf.h"
#include "xparameters.h"
#include <xil_io.h>
#include "xscugic.h"
#include <stdio.h>
Thank you!
1- Your IDE may help you find the header file : right click on the function name, then click on go to the definition, once you get the header file eg file.h you should include it.
2-Your # includeassume that the header files freeRTOS.h... are in the same folder but possibly they are in other folders,
I said that because freeRTOSConfig.his a configuration file that should not be in the same folder as the kernel include filestask.h,...,(at least in the demo project) so make sure that you use the good local /global path to your headers
3- The order of include is not good i guess, the best approach is to go from global to local, stdio.h for example should be at the top of the includes

Linking the PCL library with ROS

i had installed ROS and PCL in ubuntu...
The import in my code are:
#include <pcl/io/pcd_io.h>
#include <pcl/point_cloud.h>
#include <pcl/correspondence.h>
#include <pcl/features/normal_3d_omp.h>
#include <pcl/features/shot_omp.h>
#include <pcl/features/board.h>
#include <pcl/keypoints/uniform_sampling.h>
#include <pcl/recognition/cg/hough_3d.h>
#include <pcl/recognition/cg/geometric_consistency.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/kdtree/kdtree_flann.h>
#include <pcl/kdtree/impl/kdtree_flann.hpp>
#include <pcl/common/transforms.h>
#include <pcl/console/parse.h>
When i compile the program with this CMakeLists:
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(correspondence_grouping)
find_package(PCL 1.3 REQUIRED COMPONENTS common io)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable(correspondence_grouping correspondence_grouping.cpp)
target_link_libraries(correspondence_grouping ${PCL_COMMON_LIBRARIES}${PCL_IO_LIBRARIES})
appears this error:
In file included from /opt/ros/fuerte/include/pcl-1.5/pcl/io/pcd_io.h:43:0,
from /home/user/Desktop/PCL/Grouping/correspondence_grouping.cpp:1:
/opt/ros/fuerte/include/pcl-1.5/pcl/point_cloud.h:46:29: fatal error: std_msgs/Header.h: No such file or directory
I'm new in Linux and ROS+PCL (i'm using them for an university project..) and i can't understand which is the problem.
P.S. Similary error appear with other cpp files with PCL.
I don't know how to do to fix it...
Thanks
I think you will be better off using the ROS build system, which is either rosbuild or catkin depending on the version of ROS you are using. catkin is AFAIK a set of CMake macros that pull in ROS dependencies etc.
See:
http://wiki.ros.org/pcl/Tutorials
You should use the rosbuild environment to create a package (See: [Creating a ros package]) and then put this into your CMakelist.txt to use PCL:
...
find_package(PCL 1.3 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
...
The dependencie to std_msgs is handled by the manifest.xml (automatically generate with the package) with the following standard dependecies:
<package>
...
<depend package="std_msgs"/>
<depend package="rospy"/>
<depend package="roscpp"/>
...
</package>

Do I need to include system header file in the source if another header file already includes it?

For example, in the header file example.h, I wrote:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
And in the source file example.c, I wrote:
#include "example.h`
Do I still need to explicitly wrote these lines if I need functions of these libararies?
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
Thanks!
No.
Keep in mind that includes works like some kind of text substitution, as it's done by the preprocessor.
When you write, on some file:
#include "someheader.h"
It's just like that line will be replaced with the actual content of the header file.
No, you don't.
Include will, as it's named, include the whole content of your header file in your .c file.
If you are using linux, try cpp example.c or gcc -E example.c to see what #include does. You will run the c-preprocessor on your file, which is the program that interpret all # started instructions before the copilation

C - adding base64 methods to my file

I found these libraries: http://svn.opendnssec.org/trunk/OpenDNSSEC/common/ for encoding in c. I want used them but I am not sure how can I add them.
If I add #include "b64_ntop.c" I have problem with #include <config.h> in b64_ntop.c (no such file or directory). How can I add these modules?
My makefile:
CC=gcc
CFLAGS=-std=gnu99 -Wall -pedantic
all: rdtclient
rdtclient: b64_ntop.o rdtclient.o
$(CC) $(CFLAGS) b64_ntop.o rdtclient.o -o rdtclient
Thanks for help
For that particular file, you can remove every header except <stdlib.h> (needed for abort()), but you would add <stdint.h> to get uint8_t.
#include <config.h> // Remove
#include <sys/types.h> // Remove
#include <sys/param.h> // Remove
#include <sys/socket.h> // Remove
#include <netinet/in.h> // Remove
#include <arpa/inet.h> // Remove
#include <ctype.h> // Remove
#include <stdio.h> // Remove
#include <stdlib.h> // Keep
#include <string.h> // Remove
#include <stdint.h> // Add
There's no need for the others that I can see, and GCC agrees with me when I tested it.
I'm not sure which header introduced uint8_t; most likely, it was <sys/types.h>, but the C standard says <stdint.h> does that (or <inttypes.h> does it).
You should also have a header which declares the function, and that header should be included in this file to ensure that the function declaration and definition agree, and the header should be included in each source file that uses the function. Obviously, that's one more #include line in the source file.
In general, if a file uses <config.h> (or, more usually, "config.h"), then you need to use the configuration tool (usually autoconf or automake) or the configure script that is generated by the tools to create the config.h header. In this file, there was no conditional code affected by the configuration header, so it could be removed.
Once you've cleaned up the header list, you can treat the file as you would any other source file in your project. It would be best to compile it as a separate object file (no special options needed) which is added to the build. That's what your makefile seems to be doing perfectly well. Occasionally, it is sensible or necessary to include a source file (as opposed to header file) in another source file. The number of times that is sensible is strictly limited, though.
You should not #include a C file. Instead #include compat.h and specify the path to the header file in the CFLAGS using the -I option thus:
CFLAGS=-std=gnu99 -Wall -pedantic -Ipath/to/header

Compile C program with visual studio

I am required to explain what the program located in the following links does:
main.c
csapp.c
csapp.h
I compile the following code in linux as:
............................................................
(note all three files have to be in the same working directory for compilation to work. )
that command is: gcc main.c csapp.c
when I execute that command I get the executable: a.out and I get no compilation errors!
That executable file can be downloaded from here (I don't think you need that file plus I will not execute that file if I where you).
Anyways I think that if I could debug the program I will be able to understand better what is going on. As a result I have created a C++ console empty console project in visual studio. I will like to include the same files in there and be able to compile it. I have never used c++ before and I don't really understand where to place header files. This is what I have done hoping to be able to compile the program:
The program will not compile if I place the files like that.
I have also tried placing all the files in the same directory just like on the linux virtual machine:
that does not compile either.
How will I be able to compile that program with visual studio?
If you look at csapp.h you'll notice it tries to include these headers:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <setjmp.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <errno.h>
#include <math.h>
#include <pthread.h>
#include <semaphore.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
Some of these are std C headers, but others are specific to POSIX/Linux/UNIX style operating systems (pthread.h for example). You won't be able to use these libraries on Windows or in Visual Studio unless you're doing something unusual like compiling against Cygwin libraries.
If you want to get an understanding of what the program is doing, there's a number of things you could do. First off, just read through the code and look up the functions it calls in the man pages which document those functions (If you have gcc, I guess you also have man?) second, yes you could print to console to figure stuff out. You could also use a debugger like gdb to step through the program, it's not as intuitive as VS debugger but it works...

Resources