Skip to content

Commit ad2ddb6

Browse files
authored
Merge pull request #74 from Mu2e/eflumerf/ChownDevFile
Label device file with current user
2 parents 1c22235 + 7538fdb commit ad2ddb6

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

mu2e_driver/mu2e_fs.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ struct cdev mu2e_cdev;
4141

4242
static int mu2e_dtc_count[MU2E_MAX_NUM_DTCS] = {0};
4343
static kuid_t mu2e_dtc_owner[MU2E_MAX_NUM_DTCS] = {{0}};
44+
static kuid_t root_uid = {{0}};
4445
static DEFINE_SPINLOCK(mu2e_fs_spinlock);
4546

4647
int mu2e_fs_up()
@@ -98,7 +99,11 @@ int mu2e_open(struct inode *inode, struct file *filp)
9899
}
99100

100101
if (mu2e_dtc_count[dtc] == 0)
102+
{
101103
mu2e_dtc_owner[dtc] = current_uid(); /* grab it */
104+
inode->i_uid = current_uid();
105+
mark_inode_dirty(inode);
106+
}
102107

103108
mu2e_dtc_count[dtc]++;
104109
spin_unlock(&mu2e_fs_spinlock);
@@ -111,6 +116,11 @@ int mu2e_release(struct inode *inode, struct file *filp)
111116
int dtc = iminor(inode);
112117
spin_lock(&mu2e_fs_spinlock);
113118
mu2e_dtc_count[dtc]--;
119+
if (mu2e_dtc_count[dtc] == 0)
120+
{
121+
inode->i_uid = root_uid;
122+
mark_inode_dirty(inode);
123+
}
114124
spin_unlock(&mu2e_fs_spinlock);
115125
return 0;
116126
}

0 commit comments

Comments
 (0)