more projects
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,286 @@
|
||||
// !$*UTF8*$!
|
||||
{
|
||||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 56;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
262DA11F2AB8CBA20099710A /* jiffies.c in Sources */ = {isa = PBXBuildFile; fileRef = 262DA11E2AB8CBA20099710A /* jiffies.c */; };
|
||||
262DA1212AB8CBBB0099710A /* seconds.c in Sources */ = {isa = PBXBuildFile; fileRef = 262DA1202AB8CBBB0099710A /* seconds.c */; };
|
||||
262DA1242AB93B540099710A /* filecopy.c in Sources */ = {isa = PBXBuildFile; fileRef = 262DA1232AB93B540099710A /* filecopy.c */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXCopyFilesBuildPhase section */
|
||||
262DA1122AB8AFB50099710A /* CopyFiles */ = {
|
||||
isa = PBXCopyFilesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
dstPath = /usr/share/man/man1/;
|
||||
dstSubfolderSpec = 0;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 1;
|
||||
};
|
||||
/* End PBXCopyFilesBuildPhase section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
262DA1142AB8AFB50099710A /* Homework 1 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "Homework 1"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
262DA11E2AB8CBA20099710A /* jiffies.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = jiffies.c; sourceTree = "<group>"; };
|
||||
262DA1202AB8CBBB0099710A /* seconds.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = seconds.c; sourceTree = "<group>"; };
|
||||
262DA1232AB93B540099710A /* filecopy.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = filecopy.c; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
262DA1112AB8AFB50099710A /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
262DA10B2AB8AFB50099710A = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
262DA1162AB8AFB50099710A /* Homework 1 */,
|
||||
262DA1152AB8AFB50099710A /* Products */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
262DA1152AB8AFB50099710A /* Products */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
262DA1142AB8AFB50099710A /* Homework 1 */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
262DA1162AB8AFB50099710A /* Homework 1 */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
262DA11E2AB8CBA20099710A /* jiffies.c */,
|
||||
262DA1202AB8CBBB0099710A /* seconds.c */,
|
||||
262DA1232AB93B540099710A /* filecopy.c */,
|
||||
);
|
||||
path = "Homework 1";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
262DA1132AB8AFB50099710A /* Homework 1 */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 262DA11B2AB8AFB50099710A /* Build configuration list for PBXNativeTarget "Homework 1" */;
|
||||
buildPhases = (
|
||||
262DA1102AB8AFB50099710A /* Sources */,
|
||||
262DA1112AB8AFB50099710A /* Frameworks */,
|
||||
262DA1122AB8AFB50099710A /* CopyFiles */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
);
|
||||
name = "Homework 1";
|
||||
productName = "Homework 1";
|
||||
productReference = 262DA1142AB8AFB50099710A /* Homework 1 */;
|
||||
productType = "com.apple.product-type.tool";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
|
||||
/* Begin PBXProject section */
|
||||
262DA10C2AB8AFB50099710A /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
BuildIndependentTargetsInParallel = 1;
|
||||
LastUpgradeCheck = 1430;
|
||||
TargetAttributes = {
|
||||
262DA1132AB8AFB50099710A = {
|
||||
CreatedOnToolsVersion = 14.3.1;
|
||||
};
|
||||
};
|
||||
};
|
||||
buildConfigurationList = 262DA10F2AB8AFB50099710A /* Build configuration list for PBXProject "Homework 1" */;
|
||||
compatibilityVersion = "Xcode 14.0";
|
||||
developmentRegion = en;
|
||||
hasScannedForEncodings = 0;
|
||||
knownRegions = (
|
||||
en,
|
||||
Base,
|
||||
);
|
||||
mainGroup = 262DA10B2AB8AFB50099710A;
|
||||
productRefGroup = 262DA1152AB8AFB50099710A /* Products */;
|
||||
projectDirPath = "";
|
||||
projectRoot = "";
|
||||
targets = (
|
||||
262DA1132AB8AFB50099710A /* Homework 1 */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
262DA1102AB8AFB50099710A /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
262DA11F2AB8CBA20099710A /* jiffies.c in Sources */,
|
||||
262DA1212AB8CBBB0099710A /* seconds.c in Sources */,
|
||||
262DA1242AB93B540099710A /* filecopy.c in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
262DA1192AB8AFB50099710A /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
CLANG_ANALYZER_NONNULL = YES;
|
||||
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_ENABLE_OBJC_WEAK = YES;
|
||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_COMMA = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
|
||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
ENABLE_TESTABILITY = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu11;
|
||||
GCC_DYNAMIC_NO_PIC = NO;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = (
|
||||
"DEBUG=1",
|
||||
"$(inherited)",
|
||||
);
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 13.3;
|
||||
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
|
||||
MTL_FAST_MATH = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = macosx;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
262DA11A2AB8AFB50099710A /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
CLANG_ANALYZER_NONNULL = YES;
|
||||
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_ENABLE_OBJC_WEAK = YES;
|
||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_COMMA = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
|
||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
ENABLE_NS_ASSERTIONS = NO;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu11;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 13.3;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
MTL_FAST_MATH = YES;
|
||||
SDKROOT = macosx;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
262DA11C2AB8AFB50099710A /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
262DA11D2AB8AFB50099710A /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
262DA10F2AB8AFB50099710A /* Build configuration list for PBXProject "Homework 1" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
262DA1192AB8AFB50099710A /* Debug */,
|
||||
262DA11A2AB8AFB50099710A /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
262DA11B2AB8AFB50099710A /* Build configuration list for PBXNativeTarget "Homework 1" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
262DA11C2AB8AFB50099710A /* Debug */,
|
||||
262DA11D2AB8AFB50099710A /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
rootObject = 262DA10C2AB8AFB50099710A /* Project object */;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Workspace
|
||||
version = "1.0">
|
||||
<FileRef
|
||||
location = "self:">
|
||||
</FileRef>
|
||||
</Workspace>
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>IDEDidComputeMac32BitWarning</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
BIN
Binary file not shown.
+14
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>SchemeUserState</key>
|
||||
<dict>
|
||||
<key>Homework 1.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>0</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
Binary file not shown.
@@ -0,0 +1,38 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define BUFFER_SIZE 4096
|
||||
|
||||
int main() {
|
||||
char sourceFileName[256];
|
||||
char destinationFileName[256];
|
||||
int sourceFile, destinationFile;
|
||||
ssize_t bytes_read, bytes_written;
|
||||
char buffer[BUFFER_SIZE];
|
||||
|
||||
printf("Enter the source file name: ");
|
||||
scanf("%255s", sourceFileName);
|
||||
printf("Enter the destination file name: ");
|
||||
scanf("%255s", destinationFileName);
|
||||
|
||||
sourceFile = open(sourceFileName, O_RDONLY);
|
||||
|
||||
destinationFile = open(destinationFileName, O_WRONLY | O_CREAT | O_EXCL, 0666);
|
||||
|
||||
|
||||
// Copy data from source to destination
|
||||
while ((bytes_read = read(sourceFile, buffer, BUFFER_SIZE)) > 0) {
|
||||
bytes_written = write(destinationFile, buffer, bytes_read);
|
||||
}
|
||||
|
||||
// Close files
|
||||
close(sourceFile);
|
||||
close(destinationFile);
|
||||
|
||||
printf("File copied successfully!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
/**
|
||||
* hello.c
|
||||
*
|
||||
* Kernel module that communicates with /proc file system.
|
||||
*
|
||||
* The makefile must be modified to compile this program.
|
||||
* Change the line "simple.o" to "hello.o"
|
||||
*
|
||||
* Operating System Concepts - 10th Edition
|
||||
* Copyright John Wiley & Sons - 2018
|
||||
*/
|
||||
|
||||
#include <linux/init.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/proc_fs.h>
|
||||
#include <linux/uaccess.h>
|
||||
|
||||
#define BUFFER_SIZE 128
|
||||
|
||||
#define PROC_NAME "jiffies"
|
||||
#define MESSAGE "Hello World\n"
|
||||
|
||||
/**
|
||||
* Function prototypes
|
||||
*/
|
||||
ssize_t proc_read(struct file *file, char *buf, size_t count, loff_t *pos);
|
||||
|
||||
static struct file_operations proc_ops = {
|
||||
.owner = THIS_MODULE,
|
||||
.read = proc_read,
|
||||
};
|
||||
|
||||
static long start_jiffies;
|
||||
|
||||
/* This function is called when the module is loaded. */
|
||||
int proc_init(void)
|
||||
{
|
||||
start_jiffies = jiffies;
|
||||
// creates the /proc/hello entry
|
||||
// the following function call is a wrapper for
|
||||
// proc_create_data() passing NULL as the last argument
|
||||
proc_create(PROC_NAME, 0, NULL, &proc_ops);
|
||||
|
||||
printk(KERN_INFO "/proc/%s created\n", PROC_NAME);
|
||||
printk(KERN_INFO "Jiffies: %lu\n", jiffies);
|
||||
printk(KERN_INFO "HZ: %lu\n", HZ);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* This function is called when the module is removed. */
|
||||
void proc_exit(void) {
|
||||
|
||||
// removes the /proc/hello entry
|
||||
remove_proc_entry(PROC_NAME, NULL);
|
||||
|
||||
printk( KERN_INFO "/proc/%s removed\n", PROC_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is called each time the /proc/hello is read.
|
||||
*
|
||||
* This function is called repeatedly until it returns 0, so
|
||||
* there must be logic that ensures it ultimately returns 0
|
||||
* once it has collected the data that is to go into the
|
||||
* corresponding /proc file.
|
||||
*
|
||||
* params:
|
||||
*
|
||||
* file:
|
||||
* buf: buffer in user space
|
||||
* count:
|
||||
* pos:
|
||||
*/
|
||||
ssize_t proc_read(struct file *file, char __user *usr_buf, size_t count, loff_t *pos)
|
||||
{
|
||||
int rv = 0;
|
||||
char buffer[BUFFER_SIZE];
|
||||
static int completed = 0;
|
||||
|
||||
|
||||
if (completed) {
|
||||
completed = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
completed = 1;
|
||||
|
||||
rv = sprintf(buffer, "Jiffies: %lu\n\n", jiffies);
|
||||
|
||||
// copies the contents of buffer to userspace usr_buf
|
||||
copy_to_user(usr_buf, buffer, rv);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
/* Macros for registering module entry and exit points. */
|
||||
module_init( proc_init );
|
||||
module_exit( proc_exit );
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_DESCRIPTION("Hello Module");
|
||||
MODULE_AUTHOR("SGG");
|
||||
@@ -0,0 +1,106 @@
|
||||
/**
|
||||
* seconds.c
|
||||
*
|
||||
* Kernel module that communicates with /proc file system.
|
||||
*
|
||||
* The makefile must be modified to compile this program.
|
||||
* Change the line "simple.o" to "hello.o"
|
||||
*
|
||||
* Operating System Concepts - 10th Edition
|
||||
* Copyright John Wiley & Sons - 2018
|
||||
*/
|
||||
|
||||
#include <linux/init.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/proc_fs.h>
|
||||
#include <linux/uaccess.h>
|
||||
|
||||
#define BUFFER_SIZE 128
|
||||
|
||||
#define PROC_NAME "seconds"
|
||||
#define MESSAGE "Hello World\n"
|
||||
|
||||
/**
|
||||
* Function prototypes
|
||||
*/
|
||||
ssize_t proc_read(struct file *file, char *buf, size_t count, loff_t *pos);
|
||||
|
||||
static struct file_operations proc_ops = {
|
||||
.owner = THIS_MODULE,
|
||||
.read = proc_read,
|
||||
};
|
||||
|
||||
static long start_jiffies;
|
||||
|
||||
/* This function is called when the module is loaded. */
|
||||
int proc_init(void)
|
||||
{
|
||||
start_jiffies = jiffies;
|
||||
// creates the /proc/hello entry
|
||||
// the following function call is a wrapper for
|
||||
// proc_create_data() passing NULL as the last argument
|
||||
proc_create(PROC_NAME, 0, NULL, &proc_ops);
|
||||
|
||||
printk(KERN_INFO "/proc/%s created\n", PROC_NAME);
|
||||
printk(KERN_INFO "Jiffies: %lu\n", jiffies);
|
||||
printk(KERN_INFO "HZ: %lu\n", HZ);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* This function is called when the module is removed. */
|
||||
void proc_exit(void) {
|
||||
|
||||
// removes the /proc/hello entry
|
||||
remove_proc_entry(PROC_NAME, NULL);
|
||||
|
||||
printk( KERN_INFO "/proc/%s removed\n", PROC_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is called each time the /proc/hello is read.
|
||||
*
|
||||
* This function is called repeatedly until it returns 0, so
|
||||
* there must be logic that ensures it ultimately returns 0
|
||||
* once it has collected the data that is to go into the
|
||||
* corresponding /proc file.
|
||||
*
|
||||
* params:
|
||||
*
|
||||
* file:
|
||||
* buf: buffer in user space
|
||||
* count:
|
||||
* pos:
|
||||
*/
|
||||
ssize_t proc_read(struct file *file, char __user *usr_buf, size_t count, loff_t *pos)
|
||||
{
|
||||
int rv = 0;
|
||||
char buffer[BUFFER_SIZE];
|
||||
static int completed = 0;
|
||||
|
||||
long seconds = (jiffies - start_jiffies) / HZ;
|
||||
|
||||
if (completed) {
|
||||
completed = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
completed = 1;
|
||||
|
||||
rv = sprintf(buffer, "Seconds Elapsed: %lu\n\n", seconds);
|
||||
|
||||
// copies the contents of buffer to userspace usr_buf
|
||||
copy_to_user(usr_buf, buffer, rv);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
/* Macros for registering module entry and exit points. */
|
||||
module_init( proc_init );
|
||||
module_exit( proc_exit );
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_DESCRIPTION("Hello Module");
|
||||
MODULE_AUTHOR("SGG");
|
||||
Reference in New Issue
Block a user