Skip to content

Commit

Permalink
now dentry->d_inode size is equal to amount of bytes of protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
beraldoleal committed Feb 17, 2013
1 parent 30638d0 commit ed65bf3
Showing 2 changed files with 21 additions and 15 deletions.
10 changes: 4 additions & 6 deletions inode.c
Original file line number Diff line number Diff line change
@@ -70,8 +70,8 @@ extern void netsfs_inc_inode_size(struct inode *inode, loff_t inc)
inc);

spin_lock(&inode->i_lock);
oldsize = i_size_read(inode);
newsize = oldsize + inc;
oldsize = i_size_read(inode);
newsize = oldsize + inc;
i_size_write(inode, newsize);
spin_unlock(&inode->i_lock);
}
@@ -241,9 +241,7 @@ extern int netsfs_create_by_name(const char *name, mode_t mode, struct dentry *p

*dentry = NULL;

/* TODO: Check the necessity of a lock here.
* mutex_lock(&parent->d_inode->i_mutex);
*/
mutex_lock(&parent->d_inode->i_mutex);
*dentry = lookup_one_len(name, parent, strlen(name));
if (!IS_ERR(*dentry)) {
switch (mode & S_IFMT) {
@@ -265,7 +263,7 @@ extern int netsfs_create_by_name(const char *name, mode_t mode, struct dentry *p
} else
error = PTR_ERR(*dentry);

/* mutex_unlock(&parent->d_inode->i_mutex); */
mutex_unlock(&parent->d_inode->i_mutex);
printk("%s:%s:%d - End.\n",
THIS_MODULE->name,
__FUNCTION__,
26 changes: 17 additions & 9 deletions proto.c
Original file line number Diff line number Diff line change
@@ -22,34 +22,40 @@

struct netsfs_skb_info {
struct work_struct my_work;
int x;
char mac_name[8];
char network_name[6];
int len;
};

static void netsfs_go(struct work_struct *work)
{
struct netsfs_skb_info *netsfsinfo;
struct dentry *mac_dentry, *network_dentry;

netsfsinfo = container_of(work, struct netsfs_skb_info, my_work);

printk("Worker: netsfsinfo.x = %d\n", netsfsinfo->x);
printk("Worker: %s %s %d\n", netsfsinfo->mac_name, netsfsinfo->network_name, netsfsinfo->len);

netsfs_create_by_name(netsfsinfo->mac_name, S_IFDIR, NULL, &mac_dentry, NULL);
if (mac_dentry)
netsfs_create_by_name(netsfsinfo->network_name, S_IFDIR, mac_dentry, &network_dentry, NULL);

netsfs_inc_inode_size(mac_dentry->d_inode, netsfsinfo->len);
netsfs_inc_inode_size(network_dentry->d_inode, netsfsinfo->len);
kfree( (void *) work);
}

int netsfs_packet_handler(struct sk_buff *skb, struct net_device *dev, struct packet_type *pkt,
struct net_device *dev2)
{
int len, err;
struct dentry *de_mac;
struct dentry *de_network;
struct dentry *de_transport;

struct netsfs_skb_info *netsfsinfo;

char mac_name[8], network_name[6];

len = skb->len;

/* IEEE 802.3 Ethernet magic. */
if (len > ETH_DATA_LEN) {
printk(KERN_INFO "%s:len > ETH_DATA_LEN!\n", THIS_MODULE->name);
err = -ENOMEM;
goto free;
}
@@ -84,7 +90,9 @@ int netsfs_packet_handler(struct sk_buff *skb, struct net_device *dev, struct pa
goto free;
}

netsfsinfo->x = 10;
netsfsinfo->len = len;
strncpy(netsfsinfo->mac_name, mac_name, strlen(mac_name));
strncpy(netsfsinfo->network_name, network_name, strlen(mac_name));
INIT_WORK(&netsfsinfo->my_work, netsfs_go);
schedule_work(&netsfsinfo->my_work);

0 comments on commit ed65bf3

Please sign in to comment.