-
Notifications
You must be signed in to change notification settings - Fork 1
/
bmap_raw.c
70 lines (60 loc) · 1.49 KB
/
bmap_raw.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* Operating System Lab
* Lab4 (File System in Userspace)
* Copyright (C) 2017 Juhyung Son <[email protected]>
* First Writing: 30/12/2016
*
* bmap_raw.c :
* - bitmap related operatios.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*/
#include <fuse.h>
#include <ulockmgr.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <dirent.h>
#include <errno.h>
#include <sys/time.h>
#include <sys/file.h>
#include "include/lab4_fs_types.h"
/* ibitmap set bit function */
s32 lab4_set_bit(u32 nr,void * addr)
{
s32 mask, retval;
u8 *ADDR = (u8 *) addr;
ADDR += nr >> 3;
mask = 1 << (nr & 0x07);
retval = mask & *ADDR;
*ADDR |= mask;
return retval;
}
s32 lab4_clear_bit(u32 nr, void * addr)
{
s32 mask, retval;
u8 *ADDR = (u8 *) addr;
ADDR += nr >> 3;
mask = 1 << (nr & 0x07);
retval = mask & *ADDR;
*ADDR &= ~mask;
return retval;
}
s32 lab4_test_bit(u32 nr, const void * addr)
{
s32 mask;
const u8 *ADDR = (const u8 *) addr;
ADDR += nr >> 3;
mask = 1 << (nr & 0x07);
return (mask & *ADDR);
}